Archived

This topic is now archived and is closed to further replies.

m4ch0dude

blending and stencil buffer

Recommended Posts

I have a terrain engine that renders reflections in water, by drawing the world upside-down under the water surface, and then blending it with the rest of the image. My problem is that the terrain thats under water, but not upside-down, is getting blended with itself when viewed at low angles, and I''m not sure how to fix the problem. Here''s my basic rendering code: if(camera above water){ //setup stencil buffer glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); glDepthMask(GL_FALSE); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); DrawWater(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glPushMatrix(); //draw upside-down world, clip to below water GLdouble clip[4]={0,-1,0,waterheight}; glClipPlane(GL_CLIP_PLANE0,clip); glTranslatef(0.0, waterheight*2, 0.0); glScalef(1.0, -1.0, 1.0); glEnable(GL_CLIP_PLANE0); DrawTerrain(); DrawSky(); glPopMatrix(); //draw underwater terrain glEnable(GL_BLEND); glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); DrawTerrain(); glDisable(GL_CLIP_PLANE0); glDisable(GL_STENCIL_TEST); //draw water glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); DrawWater(); glDepthMask(GL_TRUE); glDisable(GL_BLEND); } //draw regular world DrawTerrain(); DrawSky(); If anyone has any ideas how to fix this, I would appreciate any help.

Share this post


Link to post
Share on other sites