Skip to content

Commit

Permalink
Improve performance of shader lighting code in Forward renderers.
Browse files Browse the repository at this point in the history
- Skip sampling shadows if attenuation is very small.
- Skip computing diffuse and specular light if attenuation and shadow are very small.
  • Loading branch information
DarioSamo committed Nov 27, 2024
1 parent bbc5469 commit 0ce4c6d
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2369,11 +2369,7 @@ void fragment_shader(in SceneData scene_data) {
continue; // Statically baked light and object uses lightmap, skip
}

float shadow = light_process_omni_shadow(light_index, vertex, normal, scene_data.taa_frame_count);

shadow = blur_shadow(shadow);

light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha, screen_uv,
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
Expand Down Expand Up @@ -2441,11 +2437,7 @@ void fragment_shader(in SceneData scene_data) {
continue; // Statically baked light and object uses lightmap, skip
}

float shadow = light_process_spot_shadow(light_index, vertex, normal, scene_data.taa_frame_count);

shadow = blur_shadow(shadow);

light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha, screen_uv,
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1622,13 +1622,7 @@ void main() {
uvec2 omni_indices = instances.data[draw_call.instance_index].omni_lights;
for (uint i = 0; i < sc_omni_lights(); i++) {
uint light_index = (i > 3) ? ((omni_indices.y >> ((i - 4) * 8)) & 0xFF) : ((omni_indices.x >> (i * 8)) & 0xFF);

float shadow = light_process_omni_shadow(light_index, vertex, normal, scene_data.taa_frame_count);

shadow = blur_shadow(shadow);

// Fragment lighting
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha, screen_uv,
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
Expand Down Expand Up @@ -1656,12 +1650,7 @@ void main() {
uvec2 spot_indices = instances.data[draw_call.instance_index].spot_lights;
for (uint i = 0; i < sc_spot_lights(); i++) {
uint light_index = (i > 3) ? ((spot_indices.y >> ((i - 4) * 8)) & 0xFF) : ((spot_indices.x >> (i * 8)) & 0xFF);

float shadow = light_process_spot_shadow(light_index, vertex, normal, scene_data.taa_frame_count);

shadow = blur_shadow(shadow);

light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, shadow, albedo, alpha, screen_uv,
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv,
#ifdef LIGHT_BACKLIGHT_USED
backlight,
#endif
Expand Down
Loading

0 comments on commit 0ce4c6d

Please sign in to comment.