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

Skip rendering sky if viewport is set to transparent background #91642

Merged
merged 1 commit into from
May 14, 2024

Conversation

BastiaanOlij
Copy link
Contributor

In Godot 3, if we set the viewport to have a transparent background we would clear the environment used for that viewport skipping rendering things like the sky.

In Godot 4 we no longer do this as many settings in the environment still apply. However as we render the sky with alpha 0 (at least on Vulkan), the user was blissfully unaware the sky was being rendered and this took up a fair bit of resources.
This is because we're (ab)using the alpha for sub surface scattering.

The compatibility renderer doesn't do this and you do see the sky, which at least informs the user they may wish to reconfigure the background. This is something we may change in the future but we'll do that as a separate thing.

This PR resolves this issue by skipping rendering the sky if our viewport is set to transparent. We do still update the radiance map so you can have the sky contribute to ambient lighting.

Test project:
test-transparent-sky.zip

@BastiaanOlij BastiaanOlij added this to the 4.3 milestone May 7, 2024
@BastiaanOlij BastiaanOlij self-assigned this May 7, 2024
@BastiaanOlij BastiaanOlij marked this pull request as ready for review May 7, 2024 01:51
@BastiaanOlij BastiaanOlij requested a review from a team as a code owner May 7, 2024 01:51
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

We may want to disable updating the radiance maps when the reflection source is not background.

Right now, this will continue to update the radiance maps as long as the background mode is set to sky, even if the reflection mode is set to custom color.

The current logic for updating the radiance maps is:

if (draw_sky || draw_sky_fog_only || environment_get_reflection_source(p_render_data->environment) == RS::ENV_REFLECTION_SOURCE_SKY || environment_get_ambient_source(p_render_data->environment) == RS::ENV_AMBIENT_SOURCE_SKY) {

@BastiaanOlij BastiaanOlij force-pushed the fix_transparent_sky branch from 2976c10 to fec5d57 Compare May 13, 2024 00:50
@BastiaanOlij BastiaanOlij requested a review from clayjohn May 13, 2024 00:50
@BastiaanOlij
Copy link
Contributor Author

@clayjohn I've changed the logic so draw_sky and/or draw_sky_fog_only only are set to true if the background isn't transparent.

The radiance map will thus not be updated when the background is transparent unless:

  • the reflection source is set to background AND the background is set to sky,
  • the reflection source is set to sky,
  • or the ambient source is set to sky.

Hopefully that will give the right level of control.

@BastiaanOlij BastiaanOlij force-pushed the fix_transparent_sky branch from fec5d57 to 6efaaec Compare May 13, 2024 01:04
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@akien-mga akien-mga merged commit c9fdcde into godotengine:master May 14, 2024
16 checks passed
@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.

3 participants