-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGLRenderer: Make sure stencil works with transmission. #27799
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
@Oletus Solves the issue for you? |
Syncing stencil of the transmission render target with the default framebuffer seems a step in the right direction. We can discuss in #26959 if a more dynamic solution is still required. |
@mrdoob It has been reported in #27846 (comment) that enabling stencil for transmission has a negative impact on the performance. I still think that syncing the stencil buffer of the transmission render target with the setup of the drawing buffer is right. But that leads me to the question: Why is the Since stencil is a more specific feature, I feel it hasn't to be enabled by default. |
here the version with stencil on: https://lo-th.github.io/phy/index2.html#random Stencil off: https://lo-th.github.io/phy/#random |
I get 25 - 55 with stencil and 26-55 without on a mac Mini with M2 Pro. But I admit a performance degradation is visible. |
26 !? wow mac :) |
This kind of FPS difference should not be the case. An additional stencil buffer can't be the sole reason for this kind of performance degradation. This is almost worth reporting at the browser vendor. What kind of browser and operating system are you using? |
windows 11 / chrome / rtx 4090 / threadripper 32 core :) |
I don't think there was a reason for it. |
@lo-th I've researched a bit more and it seems the following document explains the performance drop on Windows: https://groups.google.com/g/webgl-dev-list/c/iwIYWPPJwoQ?pli=1 tl;dr: D3D does not support resolving depth+stencil on the GPU. Hence, WebGL must do this on the CPU (emulation) which is slow. Since the transmission render target is multisampled, it goes through this process on Windows when |
I think there should be some way of disabling the stencil bit when resolving using |
TBH, I would prefer a solution that doesn't require a new flag. At least not a flag that has to be set by users.
Maybe we can always do this for the transmission render target and nobody will notice 🙈 ? |
Yep, avoiding a flag is good if we can get away with it! I don't think there will be any problems with resolving just the color buffer in case of the transmission render target. But it's a bit harder to say in general what's the most appropriate for user-created multisample render targets. |
I have implemented the discussed approach in Mugen87@707d454 for testing:
@lo-th Do you still see a performance degradation in the first link on Windows? Ideally test 1. and 3. should have equal performance, test 2. should stutter (it's the version before the revert #27885). |
i see no difference on both ? |
Maybe you can apply the patch to your demo and check the performance? Update build files are available here: |
work fine with this build and stencil=true |
@Mugen87 Hey, it looks like stencil buffer bit is still set when resolving MSAA render targets, unless it's a transmission render target? Any chance we could universally disable stencil multisample resolve, or implement a flag controlling that? |
Correct. The following line controls this: three.js/src/renderers/webgl/WebGLTextures.js Lines 1881 to 1883 in c3b2fb0
I'm open for a |
Related #26959.
Description
This PR is an alternative implementation to #26959.
When the default drawing buffer has a stencil buffer, this PR makes sure the transmission render target has one as well. This is achieved by applying the
stencil
context parameter to the internal render target.This PR is more simple but less flexible than #26959 since it does not perform dynamic checks on render targets. The policy is if stencil is required in the transmission pass, is has to be turned on for the default drawing buffer.