flipping a scene upside-down

Started by
6 comments, last by Vorpy 16 years, 8 months ago
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]
Wunderwerk Engine is an OpenGL-based, shader-driven, cross-platform game engine. It is targeted at aspiring game designers who have been kept from realizing their ideas due to lacking programming skills.

blog.wunderwerk-engine.com
Advertisement
Scale the view matrix by 1,-1,1, and do this each frame instead of trying to rotate the reflected camera.
which view matrix? the camera's? doesn't change anything :/
Wunderwerk Engine is an OpenGL-based, shader-driven, cross-platform game engine. It is targeted at aspiring game designers who have been kept from realizing their ideas due to lacking programming skills.

blog.wunderwerk-engine.com
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.

mh. how would i extract those vectors from the matrix? and what exactly do you mean by front * some distance? thanks in advance!
Wunderwerk Engine is an OpenGL-based, shader-driven, cross-platform game engine. It is targeted at aspiring game designers who have been kept from realizing their ideas due to lacking programming skills.

blog.wunderwerk-engine.com
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

i have the translation (a vector), the rotation (a quaternion) and the scaling (another vector). they are combined into a matrix every frame.
Wunderwerk Engine is an OpenGL-based, shader-driven, cross-platform game engine. It is targeted at aspiring game designers who have been kept from realizing their ideas due to lacking programming skills.

blog.wunderwerk-engine.com
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.

This topic is closed to new replies.

Advertisement