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

Depth-based fog transparency effect to blend with the page background #26239

Open
Oletus opened this issue Jun 12, 2023 · 0 comments
Open

Depth-based fog transparency effect to blend with the page background #26239

Oletus opened this issue Jun 12, 2023 · 0 comments

Comments

@Oletus
Copy link
Contributor

Oletus commented Jun 12, 2023

Description

A way to seamlessly blend a scene with the page background color can be useful for cases that mix together 3D and other page content. Leaving the background blank is already possible, but in addition to this, it could be good to also have fog-like fading to the page background (whether it's a solid color or something else).

This would also add a way to match the "fog color" with the page background color in case we start applying regular fog before tone mapping. Applying fog before tone mapping which would be more physically correct, but would make it more difficult to match the fog color with the page background. Or in some cases impossible - see #26208 (comment) .

Solution

To support fog-like fading to the page background, we could render a depth pass in addition to the normal color pass, and then set the alpha values of the WebGL default framebuffer according to fog computed from the depth pass.

This could be implemented as an EffectComposer pass without changing any of the core library.

There are fairly significant downsides like the extra performance cost and not having control over blending between the rendered color and the background color, but these might be worthwhile tradeoffs for some use cases.

Alternatives

Simply rendering objects as semi-transparent according to their depth wouldn't work, since we want the scene objects to be blended only with the page background, not with each other.

The use case is probably uncommon enough that it doesn't need to be supported inside the core library.

Additional context

Reference discussion: #26208 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants