Skip to content

Conversation

@Oletus
Copy link
Contributor

@Oletus Oletus commented Oct 13, 2023

In case the regular rendering is using stencil based effects, the transmission pass also needs a stencil buffer so that the rendering matches the normal render pass.

This contribution is funded by Higharc

In case the regular rendering is using stencil based effects, the transmission pass also needs a stencil buffer so that the rendering matches the normal render pass.

This contribution is funded by https://higharc.com/
@github-actions
Copy link

github-actions bot commented Oct 13, 2023

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
651.5 kB (161.4 kB) 651.6 kB (161.5 kB) +131 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
444.2 kB (107.4 kB) 444.3 kB (107.4 kB) +135 B

minFilter: LinearMipmapLinearFilter,
samples: ( isWebGL2 ) ? 4 : 0
samples: ( isWebGL2 ) ? 4 : 0,
stencilBuffer: needStencilBuffer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For simplicity reasons, couldn't we just always create the transmission render target with a stencil buffer? I don't think this would cause noticeable overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd always avoid extra memory allocations wherever possible. On a large resolution screen the bytes add up.

Copy link
Collaborator

@Mugen87 Mugen87 Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I'm still a bit unsure about the amount of new code and the checks per frame if we could also fix the issue with just stencilBuffer: true.

Is it possible to quantify how much memory the engine would additionally allocate with enabled stencil buffer and e.g. a 5K framebuffer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stencil uses 1 byte per pixel, so for rendering at 5K resolution that's about 15 megabytes. Whether that's a lot or not depends on perspective, but I think we should avoid this kind of waste. With WebGL it also can't be assumed that the user is focusing on one app at once, but rather it's quite common to have multiple open simultaneously.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With WebGL it also can't be assumed that the user is focusing on one app at once, but rather it's quite common to have multiple open simultaneously.

That's true but only when all applications actually rendering transmissive objects (which is not a common thing I would say). But yes I understand the concerns regarding memory.

@mrdoob What is your preference regarding this issue?

Mugen87
Mugen87 previously approved these changes Oct 13, 2023
@Mugen87 Mugen87 changed the title Support stenciling transmission buffer contents WebGLRenderer: Support stenciling transmission buffer contents. Oct 13, 2023
@Mugen87 Mugen87 added this to the r158 milestone Oct 16, 2023
@Mugen87 Mugen87 dismissed their stale review October 17, 2023 16:08

Needs more feedback.

@mrdoob mrdoob modified the milestones: r158, r159 Oct 27, 2023
@mrdoob mrdoob modified the milestones: r159, r160 Nov 30, 2023
@mrdoob mrdoob modified the milestones: r160, r161 Dec 22, 2023
@mrdoob mrdoob modified the milestones: r161, r162 Jan 31, 2024
@mrdoob mrdoob modified the milestones: r162, r163 Feb 29, 2024
@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 8, 2024

Side note: Stencil for the default drawing buffer is enabled by default (since the stencil WebGL context attribute is true by default). A user reported now a performance degradation when we sync the stencil buffer of the transmission render target with the stencil context attribute, see #27846 (comment).

Let's clarify in #27799 (comment) first if we can set stencil to false by default.

@mrdoob mrdoob modified the milestones: r163, r164 Mar 29, 2024
@mrdoob mrdoob modified the milestones: r164, r165 Apr 25, 2024
@mrdoob mrdoob modified the milestones: r165, r166 May 31, 2024
@mrdoob mrdoob removed this from the r166 milestone Jun 28, 2024
@mrdoob mrdoob modified the milestones: r167, r168 Jul 25, 2024
@mrdoob mrdoob modified the milestones: r168, r169 Aug 30, 2024
@mrdoob mrdoob modified the milestones: r169, r170 Sep 26, 2024
@mrdoob mrdoob modified the milestones: r170, r171 Oct 31, 2024
@mrdoob mrdoob modified the milestones: r171, r172 Nov 29, 2024
@mrdoob mrdoob modified the milestones: r172, r173 Dec 31, 2024
@mrdoob mrdoob modified the milestones: r173, r174 Jan 31, 2025
@mrdoob mrdoob modified the milestones: r174, r175 Feb 27, 2025
@mrdoob mrdoob modified the milestones: r175, r176 Mar 28, 2025
@mrdoob mrdoob modified the milestones: r176, r177 Apr 24, 2025
@mrdoob mrdoob modified the milestones: r177, r178 May 30, 2025
@mrdoob mrdoob modified the milestones: r178, r179 Jun 30, 2025
@mrdoob mrdoob modified the milestones: r179, r180 Aug 1, 2025
@mrdoob mrdoob modified the milestones: r180, r181 Sep 3, 2025
@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 21, 2025

After #27900, #27921 and #28096, this PR is not required anymore.

@Mugen87 Mugen87 closed this Sep 21, 2025
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.

3 participants