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.

Confusing behavior: Stencil Test is disabled unless Stencil Write is true

See original GitHub issue

This is a minor issue, but it forced me to read the three.js source to figure it out so it may be something to fix…

Anyway, enabling/disabling the stencil test for an object is currently the same as disabling or enabling stencilWrite.

The problem with this is that when using stencil it’s very common to have objects that don’t write stencil, they only test against what’s already in the buffer… so I ended up wasting some time trying to figure out why my object with stencilWrite = false was not affected by the stencil func at all.

I think it may make more sense to have a separate stencilTest bool, so that testing can be enabled without writing, or just assume that the test must be on if stencilFunc is not Always.

Again, this is not a big deal - stencilWrite = true doesn’t actually change anything because all Ops default to Keep, so it’s not too bad to use that one.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mrdoobcommented, Jun 20, 2020

@Tomcc Would you like to do a PR with your proposed behaviour?

1reaction
gkjohnsoncommented, Jun 14, 2020

I see it can be confusing. I think exposing the stencilMask field made it a bit less clear how to handle this. At the least I think the docs could be updated.

I suppose it could make sense to follow the same pattern as the dpeth buffer, though.

stencilTest -> enables reading / writing stencil buffer (defaults to false) stencilWrite -> sets the stencil write mask to 0 if false, uses stencilMask if true (defaults to true) stencilMask -> the write mask used when stencilWrite is true.

The difference is that right now depth mask is not exposed. I think generally a write mask for stencil has more utility.

Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Depth test not working correctly with stencil test - Stack Overflow
1 Answer 1 · Enable the depth test · Disable the color buffer and enable the stencil test for setting the stencil mask...
Read more >
Stencil testing - LearnOpenGL
Disable writing to the stencil buffer. ... The default behavior does not update the stencil buffer, so if you want to write to...
Read more >
ShaderLab command: Stencil - Unity - Manual
You can use the Stencil command to do two different things: to configure the stencil test, and to configure what the GPU writes...
Read more >
directx9 - Direct3D9 depth write without depth test
In OpenGL and Direct3D11 depth write is disabled if depth test is disabled. To enable depth write with out depth test in gl...
Read more >
Stencil Test - OpenGL Wiki
The stencil operation uses the result of the stencil test. If stencil testing is disabled, then the stencil test is counted as passing;...
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