Get pixel's location

Started by
1 comment, last by Hodgman 7 years, 6 months ago

Hey,

Just want to check with you guys:

IIRC, any vertex after applying projection matrix, should report it pixel location at x, and y component right?

so if you have the simplest pixel shader like the following, each of your rasterized pixel should report its screen location in it's x, and y component:


float4 main( float4 f4ProjPos : SV_POSITION ) : SV_Target
{
    return f4ProjPos;
}

I have this simple case setup (I render a unit length cube), and after I run it with visual studio graphics debug, I found out there are decent number of pixel whose value is not pixel location (1-8 offset).

I am super confused with this result, so I am here hoping you guys could tell me what I have missed? Is the interpolation modifier I have to specifically set? or there are any fundamental HW stuff prohibit this?

Thanks

Advertisement
Sorry for the accidental down vote. Thumb slipped and can't seem to undo it. Reply and I will up vote to compensate.

IIRC, any vertex after applying projection matrix, should report it pixel location at x, and y component right?

No, the projection matrix takes you to 4 dimensional pre-projective-divide NDC space, where xy>-w and xy<w. After dividing xy by w (which the GPU does for you during rasterization) you get -1<xy<1.

HOWEVER, yes, in the pixel shader, the SV_POSITION semantic implements a bit of magic and applies this divide by w and also applies the viewport matrix, resulting in xy pixel coordinates.

This topic is closed to new replies.

Advertisement