0
votes

I'm currently working on a reflection of my OpenGL scene (basically consisting of a skycube and a small white cube inside of that). The reflection should happen in the xz-plane (with y=0). I've managed to render that into a FBO but currently there is some issue with the view or prespective matrix. The reflection is either as seen from the wrong view position, or it just inverts what is seen on the screen.

What I need, however, is a real mirror-like reflection. In most tutorials they say that you should just scale(1,-1,1) the view-matrix or use gl_scalef(1,-1,1) but none of this works for me - the effects are described above.

Below are two screenshots of the best I currently get, using the following code immediately before rendering the (to be mirrored) scene:

view = m_camera*mat4::scale(1,-1,1);
projection = m_cameraPerspective;

Corresponding original scene: Original scene

Reflected scene: Reflected scene

Note, how this is actually the reflected scene (e.g., the clouds from the top are visible instead of the water from the bottom - as in the original rendering) but the positions are somehow not correct, e.g., the white cube is not at the same position on screen, e.g., different distance to window border).

Please ignore the wrong colors. That's because I quick hacked a function that writes the pixel values into a tga file (from the rendered texture). When actually enabling rendering the texture on my mirror plane (which is currently disabled in both render steps), the colors are correct.

What's wrong with my reflection matrix?

1
It's hard to see if the screenshot is wrong. But it can be correct. The camera probably looks a bit downwards. So it is ok for the cube to change its distance to the window border. The code looks good, so the result should be correct. - Nico Schertler
Yea, I just managed to print it correctly on the mirror-plane and saw that the mirroring works as expected. I will close this as soon as the minimum waiting time for closing is over. - pedjjj

1 Answers

1
votes

As stated in the comment, this is actually correct.