Question by
meteorstorm · May 05, 2018 at 10:30 PM ·
shadersshader programmingnormalization
Frag shader input not in Normalized Device Coordinates?
Hey guys, I was reading some other posts around here that were saying the input to the fragment shader is in NDC space, that the hardware applies the perspective divide by w automatically.
I set up an example to color a plane. And it looks like the frag shader input positions are NOT normalized. (x is in [0,800], y is in [0,600] with my viewport settings). Also, it looks like w is already 1, so I can't divide by it...
Any idea why?
struct v2f
{
float4 vertex : SV_POSITION;
float4 color : COLOR;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// i.vertex not in NDC? / why do I need to do this?
fixed4 norm = normalize(i.vertex);
return fixed4(norm.xy,0,1);
// doesn't work... w seems to be 1
//return fixed4(i.vertex.xyz / i.vertex.w, 1);
}
Comment