Sign in to follow this  
lgcosta

Water reflections

Recommended Posts

Hi, I´ve been trying to create my water using DirectX using render to texture techniques and then projecting the textures onto the water plane. The problem I find is when I'm projecting the texture. I think I´m a bit lost about mapping the projective texture. I´m already rendering to texture. The code i'm using to calculate the mapping matrix: // WHEN RENDERING TO TEXTURE, AFTER SETTING THE VIEWMATRIX // TO THE REFLECTED ONE D3DXMatrixMultiply(&m_pReflectTexMatrix, &matProj, &matView); D3DXMatrixMultiply(&m_pReflectTexMatrix, &remap, &m_pReflectTexMatrix); And when rendering the water surface: // Set texture. device->SetTexture(0, this->m_pReflectTexture); device->SetTransform(D3DTS_TEXTURE0, &m_pReflectTexMatrix); device->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3 | D3DTTFF_PROJECTED); Do i have to calculate the texture vertices coordinates? How many texture coordinates i need? Does the D3DTTFF_COUNT3 param make sense? How to set the texture coordinates? I´ve been searching on google and already readed Yann's article but I can't understand this points. Thanks

Share this post


Link to post
Share on other sites
Ive done it using shaders which i think would really be the best way to do it expecially when it comes to distorting the texture coordinates to give a rippling effect to the reflection and the fact that you`ll have to update the texture coordinates each frame. I think it can be done without them but you`ll have to lock/unlock your vertex buffer each frame which will be quite costly.

For the projective texturing you have to multiply your vertex coordinates by a texture matrix. This is made up by:

texture_matrix = matView * matProjection * remap_matrix;

The remapping matrix is described in Yanns article. For DirectX you need to transpose the one Yann gives as matrices are in a different format in OpenGL.

I then use this as my texture coordinates in my shader. I presume in your case you just use them with the D3DTTFF_PROJECTED flag. Ive not done it that way before so not 100% sure.

Share this post


Link to post
Share on other sites
The point is that the game is target for an academical study wich doesn't allow me to use vertex shaders.

I understand I need to use the D3DTTFF_PROJECTED flag, but do I have to initialize the texture coordinates? By the way, I'm not really shure how my FVF should be.

Thanks!

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