inline float4 UnityPixelSnap (float4 pos)
{
float2 hpc = _ScreenParams.xy * 0.5f;
float2 pixelPos = round ((pos.xy / pos.w) * hpc);
pos.xy = pixelPos / hpc * pos.w;
return pos;
}
What I understand:
- Input is vertex clip space coordinate.
- Output is vertex clip space coordinates which is integer after tranform to screen space.
What I am confused about:
The screen space coordinate to which input vertex is transformed:
float2 pixelPos = (pos.xy / pos.w + 1) * 0.5 * _ScreenParams.xy
So to round screen space coordinate, It should be
float roundedPixelPos = round((pos.xy / pos.w + 1) * 0.5 * _ScreenParams.xy)
But in code it is:
round ((pos.xy / pos.w) * 0.5 * _ScreenParams.xy);
So why?