Jump to content
  • Advertisement
Sign in to follow this  
george7378

Reflections without changing the view matrix

This topic is 2027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

 

 

Share this post


Link to post
Share on other sites
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:

Edited by unbird

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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 ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!