Skip to main content
GameDev.net gamedev.net
🔒 Locked

Reflection Problem

Started by The Bag Apr 24, 2004 at 6:02 PM 2 replies 950+ views
Original Post
The Bag
The Bag
I''m using lesson 26 from NeHe about using the stencil buffer for reflections. I''m drawing terrain which I wish to reflect in a water plane - this is working fine, except that the entire terrain is being drawn again under the reflective plane. That is, I''ve got two complete copies of my terrain, the one I want and a second upside down below it. Any ideas? static float l0Dir[]= {-1, 10, 1, 0}; double eqr[4]= {0.0f,-1.0f, 0.0f, 0.0f}; // Clear Screen, Depth Buffer & Stencil Buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glPushMatrix(); glLoadIdentity(); glTranslatef(-0.5*TERR_WIDTH, 0, -0.5*TERR_DEPTH); glTranslatef(tX, tY, tD); glRotatef(xrot, 0.0f, 1.0f, 0.0f); glRotatef(yrot, 1.0f, 0.0f, 0.0f); glColorMask(0,0,0,0); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glDisable(GL_DEPTH_TEST); drawWater(pWater); glEnable(GL_DEPTH_TEST); glColorMask(1,1,1,1); glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glEnable(GL_CLIP_PLANE0); glClipPlane(GL_CLIP_PLANE0, eqr); glPushMatrix(); glScalef(1.0f, -1.0f, 1.0f); glLightfv(GL_LIGHT0, GL_POSITION, l0Dir); glCullFace( GL_BACK ); glEnable( GL_CULL_FACE ); terrDraw(pTB, pWater); glPopMatrix(); glDisable( GL_CULL_FACE ); glDisable(GL_CLIP_PLANE0); glDisable(GL_STENCIL_TEST); glLightfv(GL_LIGHT0, GL_POSITION, l0Dir); glEnable(GL_BLEND); glDisable(GL_LIGHTING); glColor4f(1.0f, 1.0f, 1.0f, 0.8f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); drawWater(pWater); glPopMatrix(); glEnable(GL_LIGHTING); glDisable(GL_BLEND); terrDraw(pTB, pWater); glPopMatrix(); glFlush();
666_1337
666_1337
if the water plane equation is -y=0, your waterplane goes through the locale. now if your terrain is normalized to be between y=0 and y=highest_point, if you scale it, it is between y=0 and y=-highest_point, and the terrain then is completely below the plane, and because you scaled it with (1,-1,1) it is upside down.

our new version has many new and good features. sadly, the good nes are not new and the new nes are not good oo
The Bag
The Bag
Shouldn''t it only draw the upside down version/the reflection where the stencil buffer is set though?
The Bag
The Bag
Got it - I hadn''t setup the stencil buffer in the init stage.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.