Sign in to follow this  

Multiple Stencil Buffers?

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

To better describe the situation please look at the screen shots below. This shot uses a single shadow plane rendered in the stencil buffer on the front wall, but it can also be seen on the back wall because that face is also inside the stencil buffer. This is the correct result, but i disabled the stencil buffer on the back wall which is not the solution. The question is it possible to create different levels or layers of stencils so that each face contains its own individual buffer where I can render the shadow planes clipping them where they should be? The current basic code structure looks something like:
for each face in map

   if face = stencil then

      glEnable GL_STENCIL_TEST
      glStencilFunc GL_ALWAYS, 1, 1
      glStencilOp GL_REPLACE, GL_REPLACE, GL_REPLACE

      glColorMask GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE
      glDepthMask GL_FALSE

   end if

   render face

   if face = stencil then

      glColorMask GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE
      glDepthMask GL_TRUE

      glStencilFunc GL_EQUAL, 1, 1
      glStencilOp GL_KEEP, GL_KEEP, GL_KEEP
      glDisable GL_STENCIL_TEST

   end if

   render face

next

for each plane in map

   glEnable GL_STENCIL_TEST
   glStencilOp GL_KEEP, GL_KEEP, GL_INCR

   render shadow

   glDisable GL_STENCIL_TEST

next

render model
I already looked into Frame Buffer Objects which seemed practical but required rendering to a texture. I would really prefer not go that route or I would have simply used shadow mapping instead.

Share this post


Link to post
Share on other sites
Different machines support different numbers of stencil bits per pixel. Use glGetIntegerv GL_STENCIL_BITS, to see how many bits are available. If multiple stencil bits are available, glStencilMask() and the mask argument to glStencilFunc() can be used to divide up the stencil buffer into a number of different sections. This allows the application to store separate stencil values per pixel within the same stencil buffer.

Share this post


Link to post
Share on other sites

This topic is 3312 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.

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