Jump to content

  • Log In with Google      Sign In   
  • Create Account


View matrix to reflected view matrix


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 wildboar   Members   -  Reputation: 281

Like
0Likes
Like

Posted 25 October 2011 - 08:53 AM

I am trying to make a simple water shader in OpenGL and I need to get the mirrored view matrix for the reflection map of the water.
I made my camera with lookat and I am a bit stuck.

I am following a tutorial on habib's site and he has code like this:

private Matrix reflectionViewMatrix;    float reflectionCamZCoord = -cameraPosition.Z + 2*waterHeight;    Vector3 reflectionCamPosition = new Vector3(cameraPosition.X, cameraPosition.Y, reflectionCamZCoord);    float reflectionTargetZCoord = -targetPos.Z + 2 * waterHeight;    Vector3 reflectionCamTarget = new Vector3(targetPos.X, targetPos.Y, reflectionTargetZCoord);    Vector3 forwardVector = reflectionCamTarget - reflectionCamPosition;    Vector3 sideVector = Vector3.Transform(new Vector3(1, 0, 0), cameraRotation); Vector3 reflectionCamUp = Vector3.Cross(sideVector, forwardVector);    reflectionViewMatrix = Matrix.CreateLookAt(reflectionCamPosition, reflectionCamTarget, reflectionCamUp);

but I need something like that for OpenGL, the only things I know is the water Y value, the view matrix and the parameters that go into lookat function.
Can someone please help me

Sponsor:

#2 clb   Members   -  Reputation: 1777

Like
0Likes
Like

Posted 25 October 2011 - 09:33 AM

Mirroring an object with respect to a plane is independent of the rendering API that is used. If you know the position and the lookat direction of the original camera, you can construct the position and lookat direction of the virtual camera by mirroring the position point and lookat direction vector independently with respect to the plane, and then use the same LookAt function to generate the world (and hence the view) matrix of the virtual camera.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

#3 Lauris Kaplinski   Members   -  Reputation: 841

Like
1Likes
Like

Posted 26 October 2011 - 06:12 AM

To get mirrored view matrix (for reflection) you should multiply your view matrix (generated with lookAt) with mirror matrix of given plane.

M'camera = Mreflection * Mcamera

You can take a look at Parts 1.1 and 1.2 of my reflection tutorial, the construction of reflection matrix is shown there (or check any other 3D/matrix/vector geometry reference).

If your water level in scene is Y, the water plane is (0, 1, 0, -Y) - assuming Y is upwards direction.
You may also want to add extra mirror transformation (around X or Z axis in your case), to keep the winding (culling) order of polygons intact.
You can also use the same mirror matrix to transform the view and target points (and possibly up vector) for lookAt function.
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

#4 wildboar   Members   -  Reputation: 281

Like
0Likes
Like

Posted 26 October 2011 - 07:46 PM

To get mirrored view matrix (for reflection) you should multiply your view matrix (generated with lookAt) with mirror matrix of given plane.

M'camera = Mreflection * Mcamera

You can take a look at Parts 1.1 and 1.2 of my reflection tutorial, the construction of reflection matrix is shown there (or check any other 3D/matrix/vector geometry reference).

If your water level in scene is Y, the water plane is (0, 1, 0, -Y) - assuming Y is upwards direction.
You may also want to add extra mirror transformation (around X or Z axis in your case), to keep the winding (culling) order of polygons intact.
You can also use the same mirror matrix to transform the view and target points (and possibly up vector) for lookAt function.


Sweet tutorial dude :)
TIme to study it.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS