Sign in to follow this  
ZeroEffect

Projective Texturing (and tex2Dproj)

Recommended Posts

ZeroEffect    136
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
SimmerD    1210
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

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