Change in depthTest behavior breaks stencil buffer opertations
See original GitHub issueIn versions 0.107.0+, the behavior of the depthTest flag on a Material seems to have changed in a way that breaks operations on the stencil buffer.
To Reproduce
Steps to reproduce the behavior:
- Go to https://jsfiddle.net/50cysg9x/
- Change three@0.106.2 on line 28 to three@0.107.0 (or any higher version, including current; 0.127.0)
- See that the stencil shadow no longer renders correctly.
Code
The line in question is 171: changing this line to tintMaterial.depthTest = true
changes the output but it is not correct. As far as I can tell, the stencil buffer operations, buffer.setFunc (gl.ALWAYS, 0, 0xff)
etc, are executed whether tintMaterial.depthTest
is true
or false
. They just don’t contribute to the output in r0.107.0+.
Live example
Expected behavior
All stencil buffer operations should be executed.
Screenshots
Please see live example above
Platform:
- Device: [Desktop]
- OS: [Windows, macOS]
- Browser: [Chrome, Firefox]
- Three.js version: [r0.107.0+]
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Stencil Test - OpenGL Wiki
The Stencil Test is a per-sample operation performed after the Fragment Shader. The fragment's stencil value is tested against the value in ...
Read more >Stencil testing - LearnOpenGL
Stencil buffer operations allow us to set the stencil buffer at specific values wherever we're rendering fragments. By changing the content of the...
Read more >Stencil Buffer Overlapping - Unity Forum
The idea here is to get that impossible goal of drawing both the boxes and the mask “first” by splitting up the boxes...
Read more >Depth buffering - Vulkan Tutorial
Every time the rasterizer produces a fragment, the depth test will check if the new fragment is closer than the previous one. If...
Read more >Improving Shadows and Reflections via the Stencil Buffer
Stenciling is an extra per-pixel test and set of update operations that are closely coupled with the depth test. In addition to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you look at the changelog the addition of stencil parameters is listed as the third item in the r107 changes.
You haven’t set all the stencil options correctly for the effect you’re trying to render. If you add the following options for
tintMaterial
you get a stenciled shadow effect:Also note that because this is a render order-dependent effect you’ll want to set
tintMaterial.renderOrder
to a higher number to ensure the tint material renders last.The only guideline about contribution in general is:
https://github.com/mrdoob/three.js/blob/dev/.github/CONTRIBUTING.md
Clarifying things is of course welcome!
The exposed buffers in
WebGLState
are in some sense a protected part of the API. E.g. theMaskPass
class works with it. However, as far as I know it was never intended that users work directly with this API. At least withWebGPURenderer
such low level access will not be possible.