Stencil buffer issues

Started by
2 comments, last by TheChubu 10 years, 5 months ago
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();
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

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

C will crouch!

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

This topic is closed to new replies.

Advertisement