Skip to content
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: Reset mask before clearing stencil. #26737

Merged
merged 1 commit into from Oct 4, 2023

Conversation

OndrejSpanel
Copy link
Contributor

Description

When the last object rendered before the clear uses stencilWriteMask, which may happen when doing multiple passes with such materials, or when using some render targets, the clear will not clear bits disabled by the mask.

See https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/clear

The scissor box, dithering, and buffer writemasks can affect the clear() method

This PR resets mask before doing the clear

@github-actions
Copy link

github-actions bot commented Sep 12, 2023

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
647.6 kB (160.8 kB) 647.6 kB (160.8 kB) +47 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
440.9 kB (106.9 kB) 440.9 kB (106.9 kB) +47 B

@OndrejSpanel OndrejSpanel marked this pull request as draft September 12, 2023 15:39
@OndrejSpanel OndrejSpanel marked this pull request as ready for review September 12, 2023 16:21
@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 12, 2023

Can you please provide a fiddle that demonstrates the error the PR fixes?

@OndrejSpanel
Copy link
Contributor Author

I can try, but it is not trivial. In my case the error was happening randomly in a large scene where stencil was used for object outlining. Depending on object order the error appeared sometimes (old outlines sticking on the screen).

@OndrejSpanel
Copy link
Contributor Author

OndrejSpanel commented Sep 15, 2023

Here is the issue repro: https://jsfiddle.net/OndrejSpanel/531fa2e8/116/

Steps:

  1. Render cyan sphere, writing 4 to stencil
    image

  2. Render green sphere with a stencil test value == 4, setting the write mask to zero (any other render call would do, just set the write mask so that bit 4 is not cleared later):
    image

  3. Clear the backbuffer---- here the issue happens. The stencil is not cleared.

  4. Render the green sphere again with a stencil test value == 4 on a freshly cleared backbuffer:
    image
    Nothing should appear, as the stencil buffer should be zero after clear. It is however not cleared and the same shape as in step 2 appears.

@Mugen87 Mugen87 added this to the r157 milestone Sep 15, 2023
@Mugen87 Mugen87 changed the title Reset mask before clearing stencil WebGLRenderer: Reset mask before clearing stencil. Sep 15, 2023
@mrdoob mrdoob modified the milestones: r157, r158 Sep 28, 2023
@Mugen87 Mugen87 merged commit a238892 into mrdoob:dev Oct 4, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants