Jump to content
  • Advertisement
Sign in to follow this  

projective texture in vertex shader

This topic is 4748 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 trying to emulate the fixed function pipline like m_pd3dDevice->SetTextureStageState(TexStage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT4 | D3DTTFF_PROJECTED); in a vertex shader (for a depth shadow map) I use this but it don't work: ;c12 contain matProjLight*matViewLight*matModel*matBias ... m4x4 r0,v0,c12 rcp r0.w, r0.w mul r0.xyz, r0.xyz, r0 mov oT1,r0 ... My code work fine with fixed pipeline.

Share this post


Link to post
Share on other sites
Advertisement
OK, a few things.

First, about your combined matrix. Are you column or row major order ? In both cases, your matrix multiplication order is wrong. If you're column major, then it should be matBias*matProjLight*matViewLight*matModel. If you're row major, then just reverse it to matModel*matViewLight*matProjLight*matBias. In both cases, the order reads like this: first bring the model into world space (matModel), then into eye/lightview space (matViewLight), then apply the projection (matProjLight), and finally remap the coordinates (matBias).

Second point is the way you handle the w coordinate. In projective texturing, you do not have to do the homogeneous divide by hand, in the vertex shader. Actually, the trick is to do that per-pixel, ie. in the pixel shader. All you have to do within the vertex shader is the matrix multiply, and make sure that all 4 components are given to the pixel processing stage.

In the fixed function pipeline, the perpixel divide is enabled using the D3DTTFF_PROJECTED flag. If you're using a pixel shader, then you have to use the correct form of texture lookup (tex2Dproj, TXP, etc, depends on the shader language you use).

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!