X Tutup
Skip to content

Check if sun scatter is enabled when using SKY_MODE_AUTOMATIC#113609

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
Kaleb-Reid:sun-scatter-incremental
Dec 8, 2025
Merged

Check if sun scatter is enabled when using SKY_MODE_AUTOMATIC#113609
Repiteo merged 1 commit intogodotengine:masterfrom
Kaleb-Reid:sun-scatter-incremental

Conversation

@Kaleb-Reid
Copy link
Contributor

@Kaleb-Reid Kaleb-Reid commented Dec 5, 2025

I noticed recently that when transforming a DirectionalLight3D in a particular scene, the performance was terrible. Similar to #107928, shader_data->uses_light does not include the case where lights are used in fog sun scatter. This pr makes SKY_MODE_AUTOMATIC use SKY_MODE_INCREMENTAL instead of SKY_MODE_QUALITY if the user's sky shader does not use LIGHTX_* built-ins but lights are still used for fog.

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.

Why does enabling sun_scatter cause the radiance map to get updated? AFAIK it should only cause the directional light buffer to get updated.

@Kaleb-Reid
Copy link
Contributor Author

@clayjohn

if (light_data_dirty) {
RD::get_singleton()->buffer_update(sky_scene_state.directional_light_buffer, 0, sizeof(SkyDirectionalLightData) * sky_scene_state.max_directional_lights, sky_scene_state.directional_lights);
SkyDirectionalLightData *temp = sky_scene_state.last_frame_directional_lights;
sky_scene_state.last_frame_directional_lights = sky_scene_state.directional_lights;
sky_scene_state.directional_lights = temp;
sky_scene_state.last_frame_directional_light_count = sky_scene_state.ubo.directional_light_count;
if (sky) {
sky->reflection.dirty = true;
}
}
// Update radiance octmap
if (sky->reflection.dirty && (sky->processing_layer >= max_processing_layer || update_single_frame)) {
It looks like the when the directional light buffer is updated, so is the radiance buffer?

@clayjohn
Copy link
Member

clayjohn commented Dec 5, 2025

@clayjohn

if (light_data_dirty) {
RD::get_singleton()->buffer_update(sky_scene_state.directional_light_buffer, 0, sizeof(SkyDirectionalLightData) * sky_scene_state.max_directional_lights, sky_scene_state.directional_lights);
SkyDirectionalLightData *temp = sky_scene_state.last_frame_directional_lights;
sky_scene_state.last_frame_directional_lights = sky_scene_state.directional_lights;
sky_scene_state.directional_lights = temp;
sky_scene_state.last_frame_directional_light_count = sky_scene_state.ubo.directional_light_count;
if (sky) {
sky->reflection.dirty = true;
}
}

// Update radiance octmap
if (sky->reflection.dirty && (sky->processing_layer >= max_processing_layer || update_single_frame)) {

It looks like the when the directional light buffer is updated, so is the radiance buffer?

Thanks, that's right. But the radiance buffer should only be updated if the directional light buffer is updated and the sky shader is using directional lights. So I think the proper solution will be to change when the radiance is set to dirty

I.e. this:

if (sky) { 
	sky->reflection.dirty = true; 
} 

Should look like:

if (sky && sky->uses_lights) { 
	sky->reflection.dirty = true; 
} 

@Kaleb-Reid
Copy link
Contributor Author

@clayjohn If you go up a bit, this code is already dependent on:

if (shader_data->uses_light || (RendererSceneRenderRD::get_singleton()->environment_get_fog_enabled(p_render_data->environment) && RendererSceneRenderRD::get_singleton()->environment_get_fog_sun_scatter(p_render_data->environment) > 0.001)) {
If sun scatter is enabled, lights appear in the sky even if the user's shader does not use any LIGHTX_* built-ins (uses_lights will be false). Is this not the same reason for using SKY_MODE_INCREMENTAL when uses_lights == true?

@clayjohn
Copy link
Member

clayjohn commented Dec 5, 2025

If sun scatter is enabled, lights appear in the sky even if the user's shader does not use any LIGHTX_* built-ins (uses_lights will be false). Is this not the same reason for using SKY_MODE_INCREMENTAL when uses_lights == true?

Good point. I was forgetting that sun_scatter is evaluated in the sky shader. In my mind it was only in the scene shader and fog shader. In that case this is the correct fix!

@akien-mga akien-mga changed the title Check if sun scatter is enabled when using SKY_MODE_AUTOMATIC Check if sun scatter is enabled when using SKY_MODE_AUTOMATIC Dec 8, 2025
@Repiteo Repiteo merged commit db8b25e into godotengine:master Dec 8, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 8, 2025

Thanks!

@Kaleb-Reid Kaleb-Reid deleted the sun-scatter-incremental branch December 8, 2025 22:20
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.

4 participants

X Tutup