#Storing multiple numbers in stencil buffer
1 messages · Page 1 of 1 (latest)
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:
- Pass: Write Value To Stencil where faces are behind object
- Pass: Highlight front faces with that Value
My Idea how to solf the issue (in the screenshot) was:
- Count faces behind the object (uneven == not "closed")
- Do the same thing in front of the object
- 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 😅
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?
I tought I'd need one for the faces in front and one for those behind, is that not the case?
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.
@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.
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.
Didnt know that, thank you!
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.