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

ToneMappingEffect affects the background color #678

Closed
MajorMeerkatThe3rd opened this issue Jan 27, 2025 · 5 comments
Closed

ToneMappingEffect affects the background color #678

MajorMeerkatThe3rd opened this issue Jan 27, 2025 · 5 comments
Labels
feature request New feature request

Comments

@MajorMeerkatThe3rd
Copy link

Currently the ToneMappingEffect affects the background color, this can be reproduced on the demo page.

It would be very helpful to have a setting to ignore the background, like for other passes.

@vanruesc
Copy link
Member

vanruesc commented Feb 5, 2025

Hi,

I agree that it would be a useful feature to have, but there are currently no plans to add support for masking to ToneMappingEffect. The reason being transparent objects.

Implementing masking based on min/max depth wouldn't be too difficult. However, transparent objects don't write depth so all transparent fragments rendered on top of the background would no longer be tone mapped. Depth-based masking also causes aliasing artifacts around object edges and it requires additional texture sampling which isn't free.

I haven't tried this, but it might be possible to modify three's skybox shader to output untonemapped/inverse-tonemapped colors (http://www.codersnotes.com/notes/untonemapping/). After applying tone mapping, the final output should then look closer to the original colors.

@vanruesc vanruesc added the feature request New feature request label Feb 5, 2025
@MajorMeerkatThe3rd
Copy link
Author

Hello @vanruesc,

thank you for this very insightful answer! This makes the complexity of the issue much more clear to me.
Once I find some time, I'll try the suggested approach and will report back!

Thank you!

@vanruesc
Copy link
Member

vanruesc commented Feb 9, 2025

Closing this since there are no actionable tasks. Feel free to reopen if there are any techniques/approaches that could be explored to make selective tone mapping work.

@vanruesc vanruesc closed this as completed Feb 9, 2025
@MajorMeerkatThe3rd
Copy link
Author

@vanruesc I found out that it is actually an easy change that can be done to ignore the background. Simply request the depth for the tone mapping effect (EffectAttribute.DEPTH) and in the mainImage function, add this to the end:

if(depth >= 1.0) {
    outputColor = inputColor;
}

It's basically a passthrough for the background. Seems to work very well in my tests.

This could be made an option of course.

@vanruesc
Copy link
Member

It's basically a passthrough for the background.

Yes, that's basically what I described here:

Implementing masking based on min/max depth wouldn't be too difficult. However, transparent objects don't write depth so all transparent fragments rendered on top of the background would no longer be tone mapped.

It's not a general solution to this problem, so I don't think it should be added as an option.

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

No branches or pull requests

2 participants