PDA

View Full Version : Help with planar reflections



Zeno
11-19-2003, 10:45 AM
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?

DarkWIng
11-20-2003, 12:50 AM
There is a demo at http://www.delphi3d.net 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.

Nicolas Lelong
11-20-2003, 07:19 AM
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

Nicolas.

Zeno
11-20-2003, 09:10 AM
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.

Zeno
11-20-2003, 12:37 PM
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 :P