# Stencil buffer not working in 163

**URL:** <https://discourse.threejs.org/t/stencil-buffer-not-working-in-163/63752>\
**Category:** Questions\
**Tags:** stencil\
**Created:** [April 6, 2024, 10:43pm UTC](https://discourse.threejs.org/t/stencil-buffer-not-working-in-163/63752 "2024-04-06T22:43:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [April 6, 2024, 10:43pm UTC](https://discourse.threejs.org/t/stencil-buffer-not-working-in-163/63752/1 "2024-04-06T22:43:48Z")

</div>

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:

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/0/2/0243477bc365f0af42752da638b293cc7db7c08a.png)

Read from stencil:  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/7/8/7870dce4038bcc1908c624ff25f677ff00d02b52.png)

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

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [April 6, 2024, 10:49pm UTC](https://discourse.threejs.org/t/stencil-buffer-not-working-in-163/63752/2 "2024-04-06T22:49:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [April 7, 2024, 5:26pm UTC](https://discourse.threejs.org/t/stencil-buffer-not-working-in-163/63752/3 "2024-04-07T17:26:40Z")

</div>

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](https://github.com/mrdoob/three.js/wiki/Migration-Guide#162--r163)

---

<div class="post-metadata">

**Author:** ![zsllj](https://avatars.discourse-cdn.com/v4/letter/z/9de0a6/32.png) [@zsllj](https://discourse.threejs.org/u/zsllj)\
**Post date:** [June 3, 2024, 11:57am UTC](https://discourse.threejs.org/t/stencil-buffer-not-working-in-163/63752/4 "2024-06-03T11:57:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [June 3, 2024, 5:22pm UTC](https://discourse.threejs.org/t/stencil-buffer-not-working-in-163/63752/5 "2024-06-03T17:22:22Z")

</div>

> **[Spector.js demos & documentation](https://spector.babylonjs.com/)**
>
> SpectorJS is an Open source toolking helping to Explore and Troubleshoot your WebGL scenes with ease.

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.

---

<div class="post-metadata">

**Author:** ![manthrax](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/manthrax/32/2596_2.png) [@manthrax](https://discourse.threejs.org/u/manthrax)\
**Post date:** [June 4, 2024, 7:08am UTC](https://discourse.threejs.org/t/stencil-buffer-not-working-in-163/63752/6 "2024-06-04T07:08:33Z")

</div>

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/](https://benvanik.github.io/WebGL-Inspector/)

> **[Spector.js demos & documentation](https://spector.babylonjs.com/)**
>
> SpectorJS is an Open source toolking helping to Explore and Troubleshoot your WebGL scenes with ease.
