question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change in depthTest behavior breaks stencil buffer opertations

See original GitHub issue

In 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:

  1. Go to https://jsfiddle.net/50cysg9x/
  2. Change three@0.106.2 on line 28 to three@0.107.0 (or any higher version, including current; 0.127.0)
  3. 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:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
gkjohnsoncommented, Apr 12, 2021

Something changed between r0.106.2 and r0.107.0 that introduced this issue. I looked through the changelog and the migration guide, but didn’t see anything about the stencil buffer.

If you look at the changelog the addition of stencil parameters is listed as the third item in the r107 changes.

Here is the effect of using Material attributes: https://jsfiddle.net/md86ax1f/1/ … From what I can see, whether I use Material attributes or not, in r0.107.0+ the stencil operations simply don’t contribute to the output.

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:

tintMaterial.stencilWrite = true;
tintMaterial.side = FrontSide;
tintMaterial.stencilFunc = NotEqualStencilFunc;

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.

1reaction
Mugen87commented, Apr 12, 2021

Is there a guide to documentation standards/guidelines?

The only guideline about contribution in general is:

https://github.com/mrdoob/three.js/blob/dev/.github/CONTRIBUTING.md

I’d be happy to do the update.

Clarifying things is of course welcome!

The exposed buffers in WebGLState are in some sense a protected part of the API. E.g. the MaskPass class works with it. However, as far as I know it was never intended that users work directly with this API. At least with WebGPURenderer such low level access will not be possible.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found