projective texture in vertex shader

Started by
1 comment, last by oinf 18 years, 11 months ago
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.
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).
Really thinks for your reply.
It was helpfull, i've solved my problem.

This topic is closed to new replies.

Advertisement