Skip to main content
gamedev.net
🔒 Locked

Plane reflection problems

Started by Thraddash May 6, 2004 at 8:27 AM 2 replies 600+ views
Original Post
Thraddash
Thraddash
I'm currently trying to get reflections working in my water by mirroring my geometry about the water plane and rendering to a 2D texture. No problems so far. The problem comes when I try and use this reflection texture: specifically determining the texture coordinates I need to get it to map right. From my readings of MSDN it appears I need to use D3DTSS_TCI_CAMERASPACEPOSITION, so I set up my texture stage like this:
device->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION);
device->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3 | D3DTTFF_PROJECTED );  
My problem comes in supplying the matrix to transform the camera space position of the vertex. I've tried all kinds of wacky combinations of view and projection matrices, as well as scaling and translation matrices to compensate for the fact that post projection x and y coordinates are in the range [-1,1]. No matter what I do the reflection texture ends up behaving horribly. Any help or pointers would be greatly appreciated. [edited by - Thraddash on May 6, 2004 9:27:44 AM]
S1CA
S1CA
Are you using cubemaps?

If not, change to count2 and move all the stuff that you''d put in the 4th column (or row depending on how you look at your matrices) into the 3rd column - i.e. for texture transforms of 2d coordinates the translation part of the texture transform needs to be where the Z row would normally be.


Simon O''Connor
Game Programmer &
Microsoft DirectX MVP
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Thraddash
Thraddash
No, I'm not using a cube map, just a single 2D texture.

I tried your suggestion, thanks: but the mapping still isn't right. I don't think using COUNT2 is right though, as I still need to take into account the Z coordinate when projecting the reflected textures onto the plane.

Let me explain my thinking here - in case I have some fundamental misunderstanding: To get the reflection right, the texcoords of the corners of my reflective plane should address their 'location' within the reflection texture. To do this, I need to take the 3D cameraspace vertex generated by TCI_CAMERASPACEPOSITION, and multiply it by the projection matrix. So now my texcoord has x and y values in the range [-1, 1]. So to scale them into proper texcoords, I translate by one unit in x and y, and then scale by 0.5.

So I've been loading my texture matrix as
mat = scale * translate * projection  
but this seems to be getting me nowhere. Obviously I'm missing something here.

[edited by - Thraddash on May 6, 2004 10:19:52 PM]
Thraddash
Thraddash
A bump because I''m still stumped.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.