Sign in to follow this  

HLSL and pixel coordinates

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, does somebody know how to get the coordinate of a pixel in a pixel shader with HLSL (like gl_FragCoord in GLSL)? thanks

Share this post


Link to post
Share on other sites
Thank you for your answer but I haven't managed to make it works like that.
First, I must confess that I do Cg but HLSL and Cg are very close.
Here is my answer:

float4 main(in float4 color : COLOR,
in float4 fragpos : WPOS)
{
}


fragpos has the good coordinates.

I don't know if it works with HLSL (I'm curious to know) but if you want to use a texture interpolator, you will need to compute the complete projection in the vertex shader not only transform the vertex by modelviewproj.

bye.

Share this post


Link to post
Share on other sites
With SM3 you can use the VPOS register for the pixel shader and it will be filled with the screen position of the pixel.

Older shader models do not have this and you'll have to pass it in from the vertex shader as mentioned above.

Share this post


Link to post
Share on other sites

This topic is 4516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this