Skip to content

Apply fog before tonemapping and encoding - #26857

Open
mrdoob wants to merge 10 commits into
devfrom
apply-fog-order
Open

mrdoob wants to merge 10 commits into
devfrom
apply-fog-order

Conversation

@mrdoob

@mrdoob mrdoob commented Sep 27, 2023

Copy link
Copy Markdown
Owner

Related issue: #26208

Oletus and others added 6 commits September 25, 2023 15:13
This makes behavior more consistent between rendering to an SRGB texture and rendering to the WebGL default framebuffer. Encoding the color values should always happen after fog has been applied.
@mrdoob mrdoob added this to the r157 milestone Sep 27, 2023
@github-actions

github-actions Bot commented Sep 27, 2023 •

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
649 kB (160.9 kB) 649.6 kB (160.9 kB) +581 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
442.3 kB (107 kB) 442.9 kB (107.1 kB) +581 B

Comment thread src/renderers/webgl/WebGLMaterials.js Outdated
@mrdoob mrdoob modified the milestones: r157, r158 Sep 27, 2023
@mrdoob

mrdoob commented Sep 27, 2023

Copy link
Copy Markdown
Owner Author

So yeah... scene.background should be tonemapped too.

Screenshot 2023-09-27 at 22 24 50

@mrdoob

mrdoob commented Sep 27, 2023

Copy link
Copy Markdown
Owner Author

Refactored WebGLBackground background.isColor code path.

Screenshot 2023-09-27 at 23 02 59

@sunag

sunag commented Sep 27, 2023

Copy link
Copy Markdown
Collaborator

So yeah... scene.background should be tonemapped too.

This would make my life a lot easier, and this solves one of the problems I'm having when porting transmission materials node-based. To work correctly, the process must work in linear color space while rendering objects and only at the output apply tone mapping and output color space.

@donmccurdy

Copy link
Copy Markdown
Collaborator

I agree this is the more correct way to do things! But there will unfortunately be users with problems because they need the background to match something in HTML/CSS. I wish we had some way to apply the inverse of the tone mapping to a color, so users can at least compute a fog or background color that will give them the final background color they want.

Many colors in the sRGB gamut cannot be reached by ACES tone mapping outputs though, so this would also limit your choice of background color. Perhaps AgX will be more flexible there, but I'm not sure.

Or perhaps THREE.Fog could take an alpha value?

@sunag

sunag commented Sep 27, 2023 •

Copy link
Copy Markdown
Collaborator

I like the idea of rendering with alpha and applying it in Fog too, I think it could solve this issue with HTML/CSS? since the transparent background can provide much more possibilities than a single color. This principle could also follow this reasoning #26857 (comment)

@sunag

sunag commented Sep 29, 2023 •

Copy link
Copy Markdown
Collaborator

Some tests using opacity Fog:

image

image

image

@sunag

sunag commented Sep 29, 2023 •

Copy link
Copy Markdown
Collaborator

Considering that many people use gradient backgrounds, this would fit perfectly into any HTML/CSS.

three.js.examples.-.Google.Chrome.2023-09-29.14-28-11.mp4

@LeviPesin

Copy link
Copy Markdown
Contributor

Is this related to #25819?

@Mugen87

Mugen87 commented Oct 18, 2023

Copy link
Copy Markdown
Collaborator

What are the open points in this PR? Do we need add an alpha property to the fog classes?

As mentioned earlier, the status quo is especially confusing when devs use post processing with a scene using fog. As soon as they integrate OutputPass in their pass chain, the scene looks suddenly different compared to the inline tone mapping and color space conversion. Most devs initially think FX is buggy although it actually renders the scene correctly (see #26954 (comment)).

@mrdoob

mrdoob commented Oct 19, 2023

Copy link
Copy Markdown
Owner Author

I'm unable to find the discussion right now... but @elalish was recently dealing with some browsers not doing alpha compositing properly.

That's why I'm not sure about the transparent fog approach.

@donmccurdy

donmccurdy commented Oct 21, 2023 •

Copy link
Copy Markdown
Collaborator

As soon as they integrate OutputPass in their pass chain, the scene looks suddenly different compared to the inline tone mapping and color space conversion.

Perhaps related ... when using post-processing: should fog be part of OutputPass, or another effect pass, rather than inline?

@mrdoob mrdoob modified the milestones: r158, r159 Oct 27, 2023
@mrdoob mrdoob modified the milestones: r159, r160 Nov 30, 2023
@mrdoob mrdoob added this to the r174 milestone 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
@mrdoob mrdoob modified the milestones: r181, r182 Oct 31, 2025
@mrdoob mrdoob modified the milestones: r182, r183 Dec 10, 2025
@mrdoob mrdoob modified the milestones: r183, r184 Feb 18, 2026
@mrdoob mrdoob modified the milestones: r184, r185 Apr 16, 2026
@mrdoob mrdoob modified the milestones: r185, r186 Jun 24, 2026
@mrdoob mrdoob modified the milestones: r186, r187 Sep 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants