HLSL and pixel coordinates

Started by
2 comments, last by reltham 18 years, 7 months ago
Hi, does somebody know how to get the coordinate of a pixel in a pixel shader with HLSL (like gl_FragCoord in GLSL)? thanks
Advertisement
You'll have to pass the coordinate from the vertex shader through a texture interpolator.

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.
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.

This topic is closed to new replies.

Advertisement