- Home /
Access to svPosition in fragment shader
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 ?
Answer by MaT227 · Jan 01, 2016 at 02:55 PM
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 : ComputeScreenPos
Your answer
Follow this Question
Related Questions
_LightMatrix0 and Directional Light 1 Answer
Where Is UNITY_POSITION(pos) Defined? 1 Answer
2D Water top surface profile 1 Answer
UnityObjectToClipPos is inverted? 0 Answers
Prevent ColorMask obscuring parts of an object's mesh 0 Answers