Jump to content
  • Advertisement


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


blending and stencil buffer

This topic is 5265 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!