I wrote the following surface shader. The idea is to increase the Z depth value of vertices, after projection.
Shader "Custom/Highlighted"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert
#pragma vertex vert
struct Input
{
float4 pos: SV_POSITION;
float4 color : COLOR;
};
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o); //
o.pos = mul(UNITY_MATRIX_MVP, v.vertex); // does not work
o.pos.z += 0.001; //
o.color = v.color; //
}
fixed4 _Color;
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = _Color.rgb;
o.Alpha = _Color.a;
}
ENDCG
}
Fallback "Diffuse"
}
The shader compiles, and objects are rendered correctly, however it's like the z depth value is not modified at all (what is inside vert is ineffective).
Here is the equivalent code as a fragment shader (which work perfectly) :
struct vertInput {
float4 pos : POSITION;
float4 color : COLOR0;
float4 uv : TEXCOORD1;
};
struct vertOutput {
float4 pos : SV_POSITION;
fixed4 color : COLOR0;
};
vertOutput vert (vertInput input)
{
vertOutput o;
o.pos = mul(UNITY_MATRIX_MVP, input.pos);
o.pos.z += 0.001;
o.color = input.color;
return o;
}
v.vertex, which is the vertex position that gets used for projection and depth testing? \$\endgroup\$v.vertexis before projection, I would like to modify the properties after projection (at that moment, z property should be what is written to depth buffer) \$\endgroup\$