Sign in to follow this  
Followers 0
3TATUK2

Stencil buffer issues

3 posts in this topic

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
0

Share this post


Link to post
Share on other sites

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

0

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 );
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0