Jump to content
  • Advertisement
Sign in to follow this  
3TATUK2

Stencil buffer issues

This topic is 1677 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

so i "sort of" figured out my issue with the stencil... http://i.imgur.com/v4abqYA.png
 
the yellow is the stencil rendering of a sphere, so only the pixels it hit are processed by fragment shader
 
The problem is where rendering multiple spheres close to eachother... the stencil setup is slightly incorrect and part of it gets 
 
Any idea what i might need?
 
This is the current setup:
 
        glDepthFunc( GL_LESS );
        glStencilMask( 0xFF );

        glCullFace( GL_FRONT );
        glStencilFunc( GL_ALWAYS, 1, 0xFF );
        glStencilOp( GL_KEEP, GL_REPLACE, GL_KEEP );
        
        renderSpheres();

        glCullFace( GL_BACK );
        glStencilFunc( GL_EQUAL, 1, 0xFF );
        glStencilOp( GL_KEEP, GL_ZERO, GL_REPLACE );

        renderSpheres();
Edited by 3TATUK2

Share this post


Link to post
Share on other sites
Advertisement

I fixed it by doing it like this:

        glDepthFunc( GL_LESS );
        glStencilMask( 0xFF );

        glCullFace( GL_FRONT );
        glStencilFunc( GL_ALWAYS, 1, 0xFF );
        glStencilOp( GL_KEEP, GL_REPLACE, GL_KEEP );
        
        renderSpheres();

        glCullFace( GL_BACK );
        glStencilFunc( GL_EQUAL, 1, 0xFF );
        glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );

        renderSpheres();

And then before the third pass which renders the color onto the stencil: glStencilFunc( GL_EQUAL, 2, 0xFF );

 

But, does anyone know how to do this with one pass using glStencelOpSeparate()? I'm having some trouble with figuring that out

Share this post


Link to post
Share on other sites

Got it

glDisable( GL_CULL_FACE );
glStencilOpSeparate( GL_BACK, GL_ZERO, GL_INCR, GL_ZERO );
glStencilOpSeparate( GL_FRONT, GL_ZERO, GL_ZERO, GL_INCR );
render();
glEnable( GL_CULL_FACE );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!