Read stencil buffer to texture


#1

I have two questions on the stencil buffer. If I understand, the stencil buffer is an array. How to view it for debugging?
I use RenderDoc, however I saw a black screen using an example http://www.panda3d.org/manual/?title=Stencil_Attribute.

The second question: is it possible to write the frame buffer at once in the form of a mask for the stencil? I just want to use a shader to generate a mask.


#2

The stencil buffer is not an array; it is just an 8-bit unsigned integer value. To enable it, add this to Config.prc:

framebuffer-stencil true

Panda3D writes nothing to the stencil buffer by default. You need to apply a StencilAttrib to your geometry in order to write anything to it.

I don’t believe it’s possible to write to the stencil buffer from a fragment shader; it’s a mask that is on or off for an object’s fragments. Though, you can probably use discard; in your shader to avoid writing to the stencil buffer.

I think the buffer viewer should be supporting the debugging of stencil buffers. If this doesn’t work right, we should fix that.


#3

The word framebuffer seems to mislead me. It looks like a bitmask for a collision, only in this case for rendering. I think implement stencil based shader. This should work faster, because, as I understand it, the panda stencil test runs on the processor.


#4

It actually works. The fact is that the values ​​0/255 and 1/255 in color indistinguishable to the eye, which were used in the example.