Reflections without changing the view matrix

Started by
3 comments, last by george7378 10 years, 10 months ago

I'm currently rendering reflections to my water by using projective texturing. To render the reflection map, I am reflecting the camera about the plane of the water and updating the view matrix accordingly. However, I'd prefer to do it while keeping the view matrix constant and not moving the camera about. Is there a way of doing this by reflecting the geometry? Simply multiplying the world matrix by a reflection matrix (calculated using D3DXMatrixReflect) doesn't seem to work. Here's the scene as rendered from the camera's point of view:

[attachment=16090:goodscene.jpg]

...and the associated reflection map created by moving the camera:

[attachment=16091:goodreflect.png]

Finally, here's the reflection map I get when I keep the camera in the same place but use D3DXMatrixReflect to reflect the geometry about the plane of the water:

[attachment=16092:badreflect.png]

To get this, I'm doing: world*reflection*view*projection, and as you can see, it comes out looking quite wrong! Is there something obvious that's going wrong?


Thanks.

Advertisement

A mirroring transformation flips the winding of your triangles. So use a rasterizer state with a different cull mode.

Edit: Looks nice by the way :wink:

Ah, that's got it, thanks! Yes, it's all coming together :) I added a lot of little things such as refraction, reflection, the Fresnel term, and subtle colouring to make it look as realistic as I can.

If you consider your mirroring algorithm a bit, you can see that your second image has already all the information needed for the reflection.

You don't need to flip your projection matrix, nor flip your culling mode (since you don't flip the projection matrix).

Only thing you need to do (at the shader sampling the reflection map) is to flip the y-coordinate (1.0f - tex.y).

Cheers!

Thanks for the reply - yes, it was working OK with the second image, but I just decided it would be nicer to do it by flipping geometry rather than reflecting the camera. That way I can send the WorldViewProjection matrix straight in to the shader (I can just set the reflection matrix to the identity if I don't want reflection for a certain pass). Also, it means that I don't have to calculate new texture coordinates for reflection and refraction - the sampling works the same for both of them. I know the end effect is exactly the same, but hey ;)

This topic is closed to new replies.

Advertisement