mirror - order of transformations


I want to draw a water surface which reflects the environment. So far, this works fine in most circumstances, but not always (see http://de.geocities.com/westphj2003/refl.html ).

For creating the reflections, the whole scene is drawn upside-down and this is captured to a texture, which is orthogonally mapped on the whole screen after everything else is drawn (blended by destination alpha so that the reflection is only visible where the water is).

For drawing the upside-down stuff, the following things have to be done:

  • glScalef(1.0, -1.0, 1.0) for making it upside-down

  • glTranslatef to move it to the right height (level of the water plane) so that “normal” and “upside-down” world match exactly at the height of the water surface

  • define a clip plane so only the things above (or below in the upside-down world) are drawn

  • viewpoint setup with gluLookAt

But what I am not at all sure about is in which order to do these things?? As it works the way it is at the moment, but as I said, not under all circumstances… In a certain drawing mode (driver perspective in a driving simulation), everything is fine except that the clipping plane seems to move up and down according to the angle of pitch of the car. This is very weird and I don’t know where this effect comes from.


The problem is that you’re just flipping Y. That’s not actually correct; you need to render the scene as if the camera is as far BELOW the ground plane as it is ABOVE the plane normally. In effect, you must render from a mirrored camera position.

Also, when you go to left-handed coordinates like that, you need to change FrontFrace(), as triangle winding will reverse.

I disagree with jwatte. It sounds like you are doing everything right. It is true that you can’t just flip the image of things over, but you aren’t doing that. Jwatte is probably right about backfase culling, though.

Having not used clip planes at all, I can’t be sure, but from the red book it looks like they are defined in object space, so I’d think you would declare the clip plane after you transform your space and before you draw anything.

thanks… indeed I only had to change the order of doing these things and define the clip planee last. So obviously, I was right . Of course backface culling has to be disabled.


i am trying to create plane reflections currently and I am interrested in your approach.
Could you please explain you algorithm steps a bit more clearly. Especially where you orthoganally map the texture only where the water is.
If some source is also available, I would be gratefull.