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

Add EXPOSURE built in to spatial shaders #71364

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

clayjohn
Copy link
Member

This allows users to restore light values to pre-prebaked-exposure amounts

Fixes: #69847
Supersedes: #71304

When using Physical Light Units or exposure_multiplier in a CameraAttributes*** resource all light sources are pre-baked by the exposure amounts in the CameraAttributes. This ensures that the screen texture values stay within a manageable range.

A side-effect of this pre-baking is that SCREEN_TEXTURE returns the post-pre-baked exposure amount. I.e. the final brightness after applying exposure from CameraAttributes, but before applying exposure from the tonemapper. If this value is fed back in as an ALBEDO, everything works fine because ALBEDO expects a non exposed color. However, if you feed the SCREEN_TEXTURE result in EMISSION, it appears black because EMISSION is in physical light units, so it expects un-pre-baked exposed values (it will apply the pre-baked exposure internally after the user shader has ended). The end result is that we can either have SCREEN_TEXTURE properly exposed for ALBEDO (including baked exposure) or for EMISSION (including baked exposure).

#71304 falls short as all it does is revert the default so that SCREEN_TEXTURE works for EMISSION, but not for ALBEDO (i.e. it returns the un-pre-baked exposure value).

This PR exposes an EXPOSURE (open to alternative naming suggestions) builtin to spatial shaders that allows us to account for the pre-baked exposure. Simply multiplying EXPOSURE by values that already have the exposure baked in will undo the pre-baked exposure and return the original value. For example, multiplying this by a light's energy will give the original energy before pre-baking the CameraAttributes exposure. Or alternatively, multiplying by the result of SCREEN_TEXTURE will give you what the screen texture pixel would have been if the pre-baking had not been applied.

Tagging as 4.x as there is no rush on this. It is a pain for people using Physical Light units, but this is an addition to the shader API so I would also like more time for this to be tested and discussed, accordingly, I would prefer to merge after 4.0 stable release.

@akien-mga
Copy link
Member

Needs rebase, otherwise should be good to go if nobody has any comment :)

Copy link
Member

@Chaosus Chaosus left a comment

Choose a reason for hiding this comment

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

Seems good except few typos in visual shader.

This allows users to restore light values to pre-pre-exposure amounts
@clayjohn
Copy link
Member Author

Thanks @Chaosus! I pushed a new version with your suggested changes

@Calinou
Copy link
Member

Calinou commented Apr 12, 2023

Could this PR help with #74140 and #75128?

@clayjohn
Copy link
Member Author

Could this PR help with #74140 and #75128?

I don't think so

@Chaosus Chaosus self-requested a review April 13, 2023 04:39
@akien-mga akien-mga merged commit 8b31811 into godotengine:master Apr 13, 2023
@akien-mga
Copy link
Member

Thanks!

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.

SCREEN_TEXTURE is blank when Use Physical Light Units is enabled
4 participants