Jump to content
  • Advertisement
Sign in to follow this  
ZeroEffect

Projective Texturing (and tex2Dproj)

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

I'm currently trying to better understand the math behind projective texturing wrt vertex & pixel shaders. Currently, since I'm working in DirectX, I must offset the texture so that the texel to pixel mapping is correct (offset by half a pixel in x and y). This involves multiplying vertex position in the light's perpective space by an adjustment matrix: | 0.5f 0.0f 0.0f 0.0f | | 0.0f -0.5f 0.0f 0.0f | | 0.0f 0.0f 0.0f 0.0f | | offsetX offsetY Bias 1.0f | Now, if my math is right, the x, y, z, w coords would be: x' = 0.5x + offsetX * w y' = -0.5y + offsetY * w z' = Bias * w w' = w My first question is: Will w always be equal to 1? Secondly: These coordinates are used as the texture lookup using the tex2Dproj(s, t) instruction. My understanding is that tex2Dproj divides t by t's fourth component before doing the lookup. But if the lookup is 2D then only x' and y' (uv in texture space) are used. What happens to z' (the Bias that I am applying to the projection)? Is there something that I don't understand about the tex2Dproj instruction? Thanks, Chris Z.

Share this post


Link to post
Share on other sites
Advertisement
Positions start with a w of 1, and after the projection matrix ( but before the projective divide by w ), the w contains the viewspace z.

You can verify this by looking to see that the projection matrix's last column is

0
0
1
0

Which picks up the z from the model/view combined matrix before.

Directions can be thought of as points at infinity. They have a w of zero. This keeps the translation part of the matrices from applying to a direction. This is why normals and directional light vectors, if specified with 4 coordinates, have a w of zero.

Your matrix is correct, btw.

z' is not used, unless you are addressing into a cubemap, a volumetric texture, or a depth-stencil shadow buffer.



Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!