Stencil buffer not working in 163

In 162, i render a mesh that writes 1 to the stencil buffer, and then a mesh that renders only if the value is 1. In 163, nothing seems to happen regarding the stencil buffer. I’m not sure if it’s not being written or being read. However, when inspecting with spector i do see that the stencil values are being set.

Write to stencil:

Read from stencil:
image

I just noticed the STENCIL_BITS is 0 and in 162 i get 8

Well, to answer my own question, passing stencil:true into the webgl renderer resolves this. I log 8 bits from STENCIL_BITS.

2 Likes

Yes, with r163 stencil is now false by default for performance reasons. Most applications don’t need a stencil attachment in the default framebuffer so this change saves some memory. It is also noted in the migration guide: Migration Guide · mrdoob/three.js Wiki · GitHub

3 Likes

hi, may i know how you see the stencil state in spector? what is the spector?

But keep in mind that you may not get all the information depending on how you setup your scene. You can also install it and import it into your app and call it programmatically (it’s a bit tricky though).

From there, stencil state should be reported in the draw call information.

1 Like

Also, a word of warning about SpectorJS and similar webGL inspection tools, they can cause weird side effects that look like bugs in your code…

I tend to enable and disable those extensions only when I am directly using them. I have been bitten by them before.
(both with spectorjs and webglinspector)

https://benvanik.github.io/WebGL-Inspector/

1 Like