PDA

View Full Version : Reflections - problems when object behind reflective surface



gjwilson
12-23-2006, 03:24 PM
I used some of the dino.c sample code to draw some reflections and it works pretty well. However, I have noticed that sometimes I get some weird stuff happening when the object to reflect is "behind" the reflective surface.

I compiled and ran the dinoshade example at http://www.opengl.org//resources/code/samples/glut_examples/examples/examples.html. It worked fine. Then I modified the program to allow the dino to draw on the "under" side of the floor. This was easy, I just changed the line the idle routine (about line 667) from
jump = 4.0 * fabs(sin(time)*0.5);
to
jump = 30.0 * sin(time)*0.5;

This allows the dino to pass throught the floor. Once he is about 1/2 way through the floor, his legs are drawn under the floor (as they should be) and his head is reflected in the floor. However the legs also show above the floor and overtop of his head.

This basically recreates the problem of drawing without using the stencil buffer. Only the stencil buffer was used.

What's the bext way to correct this?

Komat
12-24-2006, 07:17 AM
You need to use the user clip plane (glClipPlane) and position it into the reflective plane during rendering of the geometry that represents the reflection (the glScalef(1.0, -1.0, 1.0); one).

gjwilson
12-24-2006, 07:53 AM
Thanks! That was what was needed. The redraw routine needed


GLdouble eqn[4] = {0.0, 1.0, 0.0, 0.0}; /* y < 0 */

and I changed the lines which drew the dino after doing the glScalef (around line 445) to

glClipPlane (GL_CLIP_PLANE0, eqn);
glEnable (GL_CLIP_PLANE0);
/* Draw the reflected dinosaur. */
drawDinosaur();

glDisable (GL_CLIP_PLANE0);Worked first time! How often does that happen? I think I'll have a look at the shadow now and see if I can get that to not show when the dino is below the floor.

Thanks again