Archived

This topic is now archived and is closed to further replies.

seastley

Projective Texture Mapping/Vertex Shader

Recommended Posts

Hi, I''m trying to implement projected texture mapping via a vertex shader. If I use D3DTSS_TCI_CAMERASPACEPOSITION and a texture projection matrix, the reflection I''m rendering comes out perfect. I want to (as a step in a process) achieve the same result via a vertex shader. I have c5-c8 receiving my cannoical world-view matrix, and c9-c12 receiving the texture projection matrix. The result is close -- everything''s reflected about where it should be. But its distorted. m4x4 r1, v0, c5 ; transform vertex into camera space rcp r2, r1.z ; calculate 1/Z mul r1.xy, r1, r2 ; multiply x and y by Z-reciprical m4x4 oT2.xy, r1, c9 ; transform x and y into texture space I suspect something''s wrong with how I apply the reciprical and the effect on the projection transformation. I''ve tried many different combinations on masking the multiplication result, etc. Any ideas what I''m doing wrong or missing here? Thanks, Shawn

Share this post


Link to post
Share on other sites
In my implemetation i carry out all the matrix calculations in the code rather than in the shader. I then pass a single projection matric to the shader whic is used to transform the vertex position into texture coordinates. Dont know if this helps much but it might make it a bit simpler than trying to do it all in the shader.

Share this post


Link to post
Share on other sites
Hi,

Yes. That''s how I had things set up initially
too. But then I questioned whether the Z-reciprical
application was supposed to come before or after
the texture projection matrix.

Shawn

Share this post


Link to post
Share on other sites
Are you using DirectX cos if you are this is the code i use to set up my matrix. I dont think you even have to deal with the reciprical if you calculate the matrix in the code (i dont anyway and it seems to work fine) you only have to think about that if your coding in the shader. Heres the code anyway.

D3DXMATRIX lightViewProj, lightView, lightProjection;
D3DXMatrixMultiply( &lightViewProj, &lightView, &lightProjection);

// Texture adjustment matrix
D3DXMATRIX matTexAdj(0.5f, 0.0f, 0.0f, 0.0f,
0.0f, -0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f,
0.5f, 0.5f, 1.0f, 1.0f);

D3DXMATRIX matProjShadow;
D3DXMatrixMultiplyTranspose( &matProjShadow, &lightViewProj, &matTexAdj );
pDevice->SetVertexShaderConstantF( 40, (float*)&matProjShadow, 4 );

Hope that helps

Share this post


Link to post
Share on other sites
Sorry just noticed you are using directx due to the D3DTSS_TCI_CAMERASPACEPOSITION call, sorry for the stupid question, if you need any more help just send another post

Share this post


Link to post
Share on other sites