Jump to content
  • Advertisement
Sign in to follow this  
Vexator

flipping a scene upside-down

This topic is 4165 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

for a water shader i'm working on, i need an upside-down reflection of the current scene. all the meshes and all the lights in this scene have their own view matrix. these are multiplied with the inverse camera view matrix and the projection matrix to get the final vertex position. ok, so to flip the scene, i can either - scale the camera view matrix about 1, -1, 1. the geometry and the lights are flipped correctly, but now the camera's rotation around the y-axis is inverted as well. so if i rotate the camera, the actual scene and its reflection move into opposite corrections. or - scale all the meshes' and lights' matrices about 1, -1, 1. this way everything is fine, but it's too much overhead, because i have to re-scale all the matrices again for the next pass. so, is there a way to invert only one axis of a quaternion - this way i could readjust the camera's orientation.. or are there better ideas how to do it? thanks in advance! [Edited by - Vexator on July 23, 2007 4:41:57 AM]

Share this post


Link to post
Share on other sites
Advertisement
Scale the view matrix by 1,-1,1, and do this each frame instead of trying to rotate the reflected camera.

Share this post


Link to post
Share on other sites
Modifying the camera matrix is the way to go but simply scaling it will produce the wrong result as you noted and it won't be very flexible if your reflection plane changes.

What you can do though is get the camera position and look at vectors (position + front * some distance) and individually mirror them over your reflection plane. You will also need to mirror the direction (not point) of the Up vector over this plane. From the two points and direction you can then easily calculate a new matrix for the reflected camera.

Share this post


Link to post
Share on other sites
mh. how would i extract those vectors from the matrix? and what exactly do you mean by front * some distance? thanks in advance!

Share this post


Link to post
Share on other sites
Quote:
Original post by Vexator
mh. how would i extract those vectors from the matrix? and what exactly do you mean by front * some distance? thanks in advance!

How to extract the look at or front vector from a matrix, not sure...

The other part I meant for how to get a point in space that the camera would be looking at by moving the front vector out by "some distance" from the camera position.

How are you handling the camera, do you have any raw rotation or position data available or just the matrix? It may technically be possible to flip a matrix over a plane but I have no idea how to go about doing that :p

Share this post


Link to post
Share on other sites
i have the translation (a vector), the rotation (a quaternion) and the scaling (another vector). they are combined into a matrix every frame.

Share this post


Link to post
Share on other sites
OK, I looked into it some more, I don't know why I thought just a scale would be enough.

What's needed is a reflection matrix on the stack. Just google for how to make one, the formula is I - 2*N*N, "I" is the identity matrix and where when I say N*N I mean the outer product that will give a 3x3 matrix. If the normal is just (0,1,0), then this comes out the same as using the (1,-1,1) scaling matrix.

Applying the reflection matrix has the same effect as reversing the forward, right and up vectors and making a matrix from them. Each of the first 3 columns of the matrix corresponds to one of the directions.

A translation is also needed, since the reflection matrix only reflects about the origin (like how rotations matrices rotate about the origin). The translation is twice the distance from the origin to the plane of reflection.

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!