Jump to content
  • Advertisement
Sign in to follow this  
Jernej.L

OpenGL More stencil shadow volume problems

This topic is 4174 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 am rendering my stencil shadow volume shadows using stencil buffer, i'm rendering a voxel-like map made of cubes where each cube side has it's own shadow volume, the calculations of volumes are ok: i project them orthogonally and cap front and rear of shadow volumes, but the final result looks something like this: The stencil buffer is 8 bit, when i dump it to raw data and load it as grayscale image, i get this (after stretching histogram): I figured out that somehow the shadow volumes exclude or sum each other, i'm not an expert in math and opengl, but i think my code is right, (based on a codesampler.com demo), here is the code that makes the shadow pass (calls cbproc callback twice to render actual shadoe volumes):
[source=c]
procedure OneSidedStencil(cbproc: rendervolumecallback);
begin
    //Prevents z-fighting.
    glEnable(GL_POLYGON_OFFSET_FILL);
    glPolygonOffset(0.0, 100.0);

    glColorMask( FALSE, FALSE, FALSE, FALSE );

    // Set the appropriate states for creating a stencil for shadowing.
    glEnable( GL_CULL_FACE );
    glEnable( GL_STENCIL_TEST );
    glDepthMask( FALSE );
    glStencilFunc( GL_ALWAYS, 0, 0 );

    // Render the shadow volume and increment the stencil every where a front facing polygon is rendered.
    glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );            
    glCullFace( GL_BACK );
    cbproc; // render front faces

    // Render the shadow volume and decrement the stencil every where a back facing polygon is rendered.
    glStencilOp( GL_KEEP, GL_KEEP, GL_DECR );
    glCullFace( GL_FRONT );
    cbproc; // render back faces

    // When done, set the states back to something more typical.
    glDepthMask( TRUE );
    glDepthFunc( GL_LEQUAL );

    glColorMask( TRUE, TRUE, TRUE, TRUE );
    glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
    glCullFace( GL_BACK );
    glDisable( GL_CULL_FACE );
    glDisable(GL_POLYGON_OFFSET_FILL);
    
    glColorMask( TRUE, TRUE, TRUE, TRUE );

    // Render the shadowed part...
    glStencilFunc( GL_LEQUAL, 1, 1 );
end;

Can somebody please tell me what am i doing wrong here?

Share this post


Link to post
Share on other sites
Advertisement
I think the prob lies here:

// Render the shadowed part...
glStencilFunc( GL_LEQUAL, 1, 1 );

As you already figured out, overlapping shadows sum up.
So you may try GL_GREATER instead:

glStencilFunc( GL_GREATER, 0, 0xff );

Please forgive me if it's wrong. I'm not an opengl expert!

cu,
Chris

Share this post


Link to post
Share on other sites
thanks for the hint, i did some experiments and fixed it using:

glStencilFunc( GL_NOTEQUAL, 0, $FFFFFFFF );

this makes shadows draw perfectly:


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.

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!