Sign in to follow this  

How to get HLSL texture pixel position

This topic is 3628 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

Using pixel shader 2.0 is there any hardware independent way to calculate the source pixel position (eg I'm on line 30) on a texture from with in a pixel shader routine? I’ve written a de-interlacer shader for a video feed it works great except for part of it needs the line number to calculate the if its an interlaced line. This is easily done via Y_line_num = tex0.y * one_over_delta_line The problem is that this works fine on some hardware but doesn’t other hardware (few lines are incorrectly numbered eg. 1 pixel out). On some hardware when the texture is scaled up the lets say 2.5 times where the sampler scales a source line to 3 lines and where the sampler scales a source line to 2 lines is hardware specific and the formula above only works 95% of the time (maybe due to rounding...) (P.S I know you can do this in pixel shader 3.0)

Share this post


Link to post
Share on other sites
You can calculate them from your post-perspective clip-space position, which you have to pass from the vertex shader. You just need to be careful when using this to determine texture coordinates or vice versa, as the texel must be offset by half a pixel.



float2 positionScreen = (IN.positionClip.xy / IN.positionClip.w) * 0.5f + 0.5f;
positionScreen.x = positionScreen.x * viewPort.x;
positionScreen.y = (1.0f - positionScreen.y) * viewPort.y;

Share this post


Link to post
Share on other sites

I may have misunderstood your solution but its not the screen coordinate I need it is the texture coordinate in pixels. For example if I load a texture into memory that is 512x512 I need to know when the shader is processing line 100 of this texture, irrespective of where on the screen the texture is rendered or how much scaling is applied so that it covers the vertices.

Thanks for the reply :-)

Share this post


Link to post
Share on other sites

This topic is 3628 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