PDA

View Full Version : Reflections



MACnus
07-12-2005, 03:23 AM
I've modeled a Piano and want to add reflections to it.

Like this image. http://www.music-inspiration.com/piano.jpg

dvm
07-12-2005, 04:00 AM
You mean you want specular highlights? Or other objects reflected in the surface of the piano?
For the first option you need to provide normals along with your vertices and set up the materials and lights properly for the piano. For the second, you need to draw the reflected object twice. Once normally and the 2nd time behind the piano. There's a technique that uses the stencil buffer and blending for this.

MACnus
07-12-2005, 05:30 AM
I'v tried with this code


glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glDisable(GL_DEPTH_TEST );
drawPiano();

glEnable( GL_DEPTH_TEST );
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glStencilFunc(GL_EQUAL, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glEnable(GL_CLIP_PLANE0);
glClipPlane( GL_CLIP_PLANE0, eqr );
glPushMatrix();
glLightfv( GL_LIGHT0, GL_POSITION, lightPos );

glScalef( 1.0f, -1.0f, 1.0f );
drawReflectedObject();
glPopMatrix();
glDisable(GL_CLIP_PLANE0);
glDisable(GL_STENCIL_TEST);

glLightfv( GL_LIGHT0, GL_POSITION, lightPos );
glEnable( GL_BLEND );
glDisable( GL_LIGHTING );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
drawPiano();

glEnable(GL_LIGHTING);
glDisable(GL_BLEND);
drawReflectedObject();But all it does is making the piano look wierd.

dvm
07-12-2005, 07:32 AM
I'm sorry, it's been a while since I've last done this and I'm a bit bored to start looking around this code at the moment. But you could try downloading the code examples from chapter 12 of OpenGL Game Programming (errata page on the site). In that chapter there's an example of the stencil buffer used for reflections. That's where I based my code on as well.

MACnus
07-14-2005, 05:53 AM
How do i perform multipass rendering?

dvm
07-14-2005, 10:27 AM
I think this refers do drawing your objects twice.
Say you have the piano,

DrawPiano();
// do other stuff
DrawPiano();I believe this refers to the fact that you have to redraw your objects. This can be heavy for complex scenes, but I think that most cases are easy, so there's no slowing down when you redraw your scene.
Notice that I write scene at the last sentence. You could have a function DrawScene that draws everything, then change something, and then redraw the whole scene.
It's not as hard as it sounds.