Help with planar reflections

Hi all. This is an embarrasing question for me but I can’t afford to spend too much more time dinking around with it, so I hope someone can help.

I’m trying to get a planar reflection (like a flat mirror) to work using projected texture mapping in a vertex program.

Here is what I am doing now:

  1. Make matrix to reflect about the plane of reflection.
  2. reflected modelview, RM = normal modelview * reflection matrix
  3. Render reflected scene using RM and default camera projection matrix P. I’m pretty sure things work up to here.
  4. Create texgen matrix: TG = S * (P * RM) where S is a scale and translation by 0.5 to center the texture.
  5. Send texgen matrix as 4 GL_EYE_PLANEs using glTexGenfv. Each eye plane is a row from the TG matrix. This is done after camera modelview has been applied but individual object transforms have not.
  6. Use texgen matrix in vertex program on vertices that have been transformed by modelview… i.e. texcoords = TG * (Mv)

What I’m actually seeing on the mirrored surface is several copies of what I think is the correct reflection texture. Like it’s being projected way too small (I have GL_REPEAT as the texture mode right now, which is why I see many copies). Any ideas?

There is a demo at using ARB_VP to do reflection. It might help you find the bug. Even if you don’t know delphi you still get to see the VP.

I can’t help you for your texture placement problem, but, FWIW, I just wanted to point out that for ‘simple’ planar reflections, it may be simpler not to use a texture to store the reflection.

You could render directly your reflected scene in the color/depth buffers - only writing fragments where stencil is set by the reflecting geometry.

just my 0.02€


Thanks DarkWIng, I’ll take a look at it.

Nicolas - the problem with stencil is that you can’t perturb it based on a normal map…I’m going to be needing to do this with some surfaces.

I just figured out the problem. My math wasn’t the problem.

If anyone cares, I was using TEX in a fragment program to look up the texture. For projective textures, the w coordinate is important and I should have been using the TXP instruction :stuck_out_tongue: