#Storing multiple numbers in stencil buffer

1 messages · Page 1 of 1 (latest)

chilly quail
#

If it's very long, it might be good to put it in a thread:

#

@worn linden

worn linden
#

Probably best if I put it here but I just suck at english (sry)

#

Ok,
I'm trying to make a shader which highlights intersections of two meshes, I've already got some code that works with convex Meshes by doing something like this:

  1. Pass: Write Value To Stencil where faces are behind object
  2. Pass: Highlight front faces with that Value

My Idea how to solf the issue (in the screenshot) was:

  1. Count faces behind the object (uneven == not "closed")
  2. Do the same thing in front of the object
  3. Check if they close each other (both values are uneven)
#

Just tell me if I should explain it differently

#

And ofcourse also if what I thought of wouldnt even work 😅

chilly quail
#

I think I understand. But what does this have to do with storing multiple numbers in the stencil buffer? Do you want to use the stencil buffer for other things as well?

worn linden
#

I tought I'd need one for the faces in front and one for those behind, is that not the case?

chilly quail
#

You may be right. I'm a bit distracted now to think this through spatially. I haven't used the stencil buffer for this purpose before.

chilly quail
#

@worn linden Just throwing this out here, you can have separate operations for front and back faces in the same pass. So you can increment with front faces and decrement with back faces, for example. I don't know if that helps though.

worn linden
#

Sounds great, thank you!

chilly quail
# worn linden Sounds great, thank you!

Just note that you should define the inc/dec operations for both Pass and ZFail if you have ZWrite On. If you only define it for Pass and have z writing enabled, then the default Keep operation will be used for pixels that get occluded. And a mesh can occlude itself, depending on its internal triangle order.

worn linden
#

Didnt know that, thank you!

grim ridge
#

As side note, similar technique was used for an old runtime shadow rendering technique called "Stencil Shadows". Some documentation about it can help to fully understand how everything works.