Skip to content

Commit 0eb06da

Browse files
Calinouclayjohn
andcommitted
Jitter shadow map dithering pattern across frames when TAA is enabled
This improves shadow quality by reducing the visibility of the noisy pattern caused by dithering. This jittering also applies when FSR2 is enabled, as it provides its own form of temporal antialiasing. Co-authored-by: Clay John <claynjohn@gmail.com>
1 parent 155fcd0 commit 0eb06da

File tree

10 files changed

+54
-47
lines changed

10 files changed

+54
-47
lines changed

servers/rendering/renderer_rd/renderer_scene_render_rd.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ void RendererSceneRenderRD::render_scene(const Ref<RenderSceneBuffers> &p_render
11311131
scene_data.cam_orthogonal = p_camera_data->is_orthogonal;
11321132
scene_data.camera_visible_layers = p_camera_data->visible_layers;
11331133
scene_data.taa_jitter = p_camera_data->taa_jitter;
1134+
scene_data.taa_frame_count = p_camera_data->taa_frame_count;
11341135
scene_data.main_cam_transform = p_camera_data->main_transform;
11351136
scene_data.flip_y = !p_reflection_probe.is_valid();
11361137

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,7 +1886,7 @@ void fragment_shader(in SceneData scene_data) {
18861886
float range_begin = directional_lights.data[i].shadow_range_begin.x;
18871887
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
18881888
vec2 tex_scale = directional_lights.data[i].uv_scale1 * test_radius;
1889-
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1889+
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
18901890
blend_count++;
18911891
}
18921892

@@ -1902,7 +1902,7 @@ void fragment_shader(in SceneData scene_data) {
19021902
float range_begin = directional_lights.data[i].shadow_range_begin.y;
19031903
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
19041904
vec2 tex_scale = directional_lights.data[i].uv_scale2 * test_radius;
1905-
float s = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1905+
float s = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
19061906

19071907
if (blend_count == 0) {
19081908
shadow = s;
@@ -1927,7 +1927,7 @@ void fragment_shader(in SceneData scene_data) {
19271927
float range_begin = directional_lights.data[i].shadow_range_begin.z;
19281928
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
19291929
vec2 tex_scale = directional_lights.data[i].uv_scale3 * test_radius;
1930-
float s = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1930+
float s = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
19311931

19321932
if (blend_count == 0) {
19331933
shadow = s;
@@ -1952,7 +1952,7 @@ void fragment_shader(in SceneData scene_data) {
19521952
float range_begin = directional_lights.data[i].shadow_range_begin.w;
19531953
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
19541954
vec2 tex_scale = directional_lights.data[i].uv_scale4 * test_radius;
1955-
float s = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1955+
float s = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
19561956

19571957
if (blend_count == 0) {
19581958
shadow = s;
@@ -2003,7 +2003,7 @@ void fragment_shader(in SceneData scene_data) {
20032003

20042004
pssm_coord /= pssm_coord.w;
20052005

2006-
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale * (blur_factor + (1.0 - blur_factor) * float(directional_lights.data[i].blend_splits)), pssm_coord);
2006+
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale * (blur_factor + (1.0 - blur_factor) * float(directional_lights.data[i].blend_splits)), pssm_coord, scene_data.taa_frame_count);
20072007

20082008
if (directional_lights.data[i].blend_splits) {
20092009
float pssm_blend;
@@ -2037,7 +2037,7 @@ void fragment_shader(in SceneData scene_data) {
20372037

20382038
pssm_coord /= pssm_coord.w;
20392039

2040-
float shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale * (blur_factor2 + (1.0 - blur_factor2) * float(directional_lights.data[i].blend_splits)), pssm_coord);
2040+
float shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale * (blur_factor2 + (1.0 - blur_factor2) * float(directional_lights.data[i].blend_splits)), pssm_coord, scene_data.taa_frame_count);
20412041
shadow = mix(shadow, shadow2, pssm_blend);
20422042
}
20432043
}
@@ -2220,7 +2220,7 @@ void fragment_shader(in SceneData scene_data) {
22202220
continue; // Statically baked light and object uses lightmap, skip
22212221
}
22222222

2223-
float shadow = light_process_omni_shadow(light_index, vertex, normal);
2223+
float shadow = light_process_omni_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
22242224

22252225
shadow = blur_shadow(shadow);
22262226

@@ -2292,7 +2292,7 @@ void fragment_shader(in SceneData scene_data) {
22922292
continue; // Statically baked light and object uses lightmap, skip
22932293
}
22942294

2295-
float shadow = light_process_spot_shadow(light_index, vertex, normal);
2295+
float shadow = light_process_spot_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
22962296

22972297
shadow = blur_shadow(shadow);
22982298

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,9 +1450,9 @@ void main() {
14501450
float range_begin = directional_lights.data[i].shadow_range_begin.x;
14511451
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
14521452
vec2 tex_scale = directional_lights.data[i].uv_scale1 * test_radius;
1453-
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1453+
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
14541454
} else {
1455-
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord);
1455+
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord, scene_data.taa_frame_count);
14561456
}
14571457
} else if (depth_z < directional_lights.data[i].shadow_split_offsets.y) {
14581458
vec4 v = vec4(vertex, 1.0);
@@ -1467,9 +1467,9 @@ void main() {
14671467
float range_begin = directional_lights.data[i].shadow_range_begin.y;
14681468
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
14691469
vec2 tex_scale = directional_lights.data[i].uv_scale2 * test_radius;
1470-
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1470+
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
14711471
} else {
1472-
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord);
1472+
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord, scene_data.taa_frame_count);
14731473
}
14741474
} else if (depth_z < directional_lights.data[i].shadow_split_offsets.z) {
14751475
vec4 v = vec4(vertex, 1.0);
@@ -1484,9 +1484,9 @@ void main() {
14841484
float range_begin = directional_lights.data[i].shadow_range_begin.z;
14851485
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
14861486
vec2 tex_scale = directional_lights.data[i].uv_scale3 * test_radius;
1487-
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1487+
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
14881488
} else {
1489-
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord);
1489+
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord, scene_data.taa_frame_count);
14901490
}
14911491
} else {
14921492
vec4 v = vec4(vertex, 1.0);
@@ -1501,9 +1501,9 @@ void main() {
15011501
float range_begin = directional_lights.data[i].shadow_range_begin.w;
15021502
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
15031503
vec2 tex_scale = directional_lights.data[i].uv_scale4 * test_radius;
1504-
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1504+
shadow = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
15051505
} else {
1506-
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord);
1506+
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord, scene_data.taa_frame_count);
15071507
}
15081508
}
15091509

@@ -1522,9 +1522,9 @@ void main() {
15221522
float range_begin = directional_lights.data[i].shadow_range_begin.y;
15231523
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
15241524
vec2 tex_scale = directional_lights.data[i].uv_scale2 * test_radius;
1525-
shadow2 = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1525+
shadow2 = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
15261526
} else {
1527-
shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord);
1527+
shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord, scene_data.taa_frame_count);
15281528
}
15291529

15301530
pssm_blend = smoothstep(0.0, directional_lights.data[i].shadow_split_offsets.x, depth_z);
@@ -1539,9 +1539,9 @@ void main() {
15391539
float range_begin = directional_lights.data[i].shadow_range_begin.z;
15401540
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
15411541
vec2 tex_scale = directional_lights.data[i].uv_scale3 * test_radius;
1542-
shadow2 = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1542+
shadow2 = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
15431543
} else {
1544-
shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord);
1544+
shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord, scene_data.taa_frame_count);
15451545
}
15461546

15471547
pssm_blend = smoothstep(directional_lights.data[i].shadow_split_offsets.x, directional_lights.data[i].shadow_split_offsets.y, depth_z);
@@ -1555,9 +1555,9 @@ void main() {
15551555
float range_begin = directional_lights.data[i].shadow_range_begin.w;
15561556
float test_radius = (range_pos - range_begin) * directional_lights.data[i].softshadow_angle;
15571557
vec2 tex_scale = directional_lights.data[i].uv_scale4 * test_radius;
1558-
shadow2 = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale);
1558+
shadow2 = sample_directional_soft_shadow(directional_shadow_atlas, pssm_coord.xyz, tex_scale * directional_lights.data[i].soft_shadow_scale, scene_data.taa_frame_count);
15591559
} else {
1560-
shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord);
1560+
shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale, pssm_coord, scene_data.taa_frame_count);
15611561
}
15621562

15631563
pssm_blend = smoothstep(directional_lights.data[i].shadow_split_offsets.y, directional_lights.data[i].shadow_split_offsets.z, depth_z);
@@ -1627,7 +1627,7 @@ void main() {
16271627

16281628
pssm_coord /= pssm_coord.w;
16291629

1630-
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale * (blur_factor + (1.0 - blur_factor) * float(directional_lights.data[i].blend_splits)), pssm_coord);
1630+
shadow = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale * (blur_factor + (1.0 - blur_factor) * float(directional_lights.data[i].blend_splits)), pssm_coord, scene_data.taa_frame_count);
16311631

16321632
if (directional_lights.data[i].blend_splits) {
16331633
float pssm_blend;
@@ -1661,7 +1661,7 @@ void main() {
16611661

16621662
pssm_coord /= pssm_coord.w;
16631663

1664-
float shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale * (blur_factor2 + (1.0 - blur_factor2) * float(directional_lights.data[i].blend_splits)), pssm_coord);
1664+
float shadow2 = sample_directional_pcf_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size * directional_lights.data[i].soft_shadow_scale * (blur_factor2 + (1.0 - blur_factor2) * float(directional_lights.data[i].blend_splits)), pssm_coord, scene_data.taa_frame_count);
16651665
shadow = mix(shadow, shadow2, pssm_blend);
16661666
}
16671667

@@ -1767,7 +1767,7 @@ void main() {
17671767
break;
17681768
}
17691769

1770-
float shadow = light_process_omni_shadow(light_index, vertex, normal);
1770+
float shadow = light_process_omni_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
17711771

17721772
shadow = blur_shadow(shadow);
17731773

@@ -1812,7 +1812,7 @@ void main() {
18121812
break;
18131813
}
18141814

1815-
float shadow = light_process_spot_shadow(light_index, vertex, normal);
1815+
float shadow = light_process_spot_shadow(light_index, vertex, normal, scene_data.taa_frame_count);
18161816

18171817
shadow = blur_shadow(shadow);
18181818

servers/rendering/renderer_rd/shaders/scene_data_inc.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ struct SceneData {
5252
uint fog_mode;
5353
highp float fog_density;
5454
highp float fog_height;
55-
highp float fog_height_density;
5655

56+
highp float fog_height_density;
5757
highp float fog_depth_curve;
58-
highp float pad;
5958
highp float fog_depth_begin;
59+
highp float taa_frame_count;
6060

6161
mediump vec3 fog_light_color;
6262
highp float fog_depth_end;

0 commit comments

Comments
 (0)