Skip to content

Commit a50076a

Browse files
committed
Improve performance of shader lighting code in Forward renderers.
- Skip sampling shadows if attenuation is very small. - Skip computing diffuse and specular light if attenuation and shadow are very small.
1 parent 23100e0 commit a50076a

3 files changed

Lines changed: 211 additions & 269 deletions

File tree

servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,11 +2369,7 @@ void fragment_shader(in SceneData scene_data) {
23692369
continue; // Statically baked light and object uses lightmap, skip
23702370
}
23712371

2372-
float shadow = light_process_omni_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
2373-
2374-
shadow = blur_shadow(shadow);
2375-
2376-
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha, screen_uv,
2372+
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv,
23772373
#ifdef LIGHT_BACKLIGHT_USED
23782374
backlight,
23792375
#endif
@@ -2441,11 +2437,7 @@ void fragment_shader(in SceneData scene_data) {
24412437
continue; // Statically baked light and object uses lightmap, skip
24422438
}
24432439

2444-
float shadow = light_process_spot_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
2445-
2446-
shadow = blur_shadow(shadow);
2447-
2448-
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha, screen_uv,
2440+
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv,
24492441
#ifdef LIGHT_BACKLIGHT_USED
24502442
backlight,
24512443
#endif

servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,13 +1622,7 @@ void main() {
16221622
uvec2 omni_indices = instances.data[draw_call.instance_index].omni_lights;
16231623
for (uint i = 0; i < sc_omni_lights(); i++) {
16241624
uint light_index = (i > 3) ? ((omni_indices.y >> ((i - 4) * 8)) & 0xFF) : ((omni_indices.x >> (i * 8)) & 0xFF);
1625-
1626-
float shadow = light_process_omni_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
1627-
1628-
shadow = blur_shadow(shadow);
1629-
1630-
// Fragment lighting
1631-
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha, screen_uv,
1625+
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv,
16321626
#ifdef LIGHT_BACKLIGHT_USED
16331627
backlight,
16341628
#endif
@@ -1656,12 +1650,7 @@ void main() {
16561650
uvec2 spot_indices = instances.data[draw_call.instance_index].spot_lights;
16571651
for (uint i = 0; i < sc_spot_lights(); i++) {
16581652
uint light_index = (i > 3) ? ((spot_indices.y >> ((i - 4) * 8)) & 0xFF) : ((spot_indices.x >> (i * 8)) & 0xFF);
1659-
1660-
float shadow = light_process_spot_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
1661-
1662-
shadow = blur_shadow(shadow);
1663-
1664-
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha, screen_uv,
1653+
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv,
16651654
#ifdef LIGHT_BACKLIGHT_USED
16661655
backlight,
16671656
#endif

0 commit comments

Comments
 (0)