Jump to content
  • Advertisement
Sign in to follow this  
gamebasic

Multiple Stencil Buffers?

This topic is 3620 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
Advertisement
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
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!