I am trying to access to the svPosition in my fragment program in Unity but I keep having this error.
invalid input semantic 'POSITION': Legal indices are in [1,15] invalid ps_3_0 input semantic 'POSITION'
Here are some information about my whole shader.
struct : float4 pos : SV_POSITION;
vertex : o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
fragment : col.rgb = i.pos.xyz;
Any idea how to access this value ?
According to an answer in the Unity forum here is the explanation.
SV_POSITION in pixel shader is available in DirectX 10 and above. That means
#pragma target 4.0 and above in Unity. The DirectX 9
#pragma target 3.0 version of this semantic is called
VPOS, but I’m not sure if Unity supports it.
You can alternatively compute this value in vertex shader and pass it to pixel shader yourself. There is even a builtin function for that :