• Advertisement
Sign in to follow this  

Texture lookup problem

This topic is 2158 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 there,

I am adding random vectors to the world position. How do I transform these into coordinates that can be used in the Texture2D "Load" function to look up the samples depth from the depth shader resource?

I have transformed the new world sample positions by the view, projection matrices and then divided by w. This doesn't seem to have worked.

Thanks

Share this post


Link to post
Share on other sites
Advertisement
After division by W your XY coordinates will be of the range [-1, 1], where (-1, -1) is the bottom left of the screen and (1, 1) is the top right. Load takes integer coordinates of the range [0, NumTexels - 1] so you need to do some conversion. Basically you need to flip y, compress to [0, 1], then multiply by the size of the texture.

float4 screenPos = mul(samplePos, ViewProj);
screenPos.xy /= screenPos.w;
float2 texturePos = screenPos.xy * float2(0.5f, -0.5f) + 0.5f;
texturePos *= TextureSize;
float depth = DepthMap.Load(uint3(texturePos, 0));

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement