Skip to content

Commit dc5f1b7

Browse files
committed
Merge pull request #100319 from Flarkk/fix_light_shadow_range
Fix shadows of long range `OmniLight3D` and `SpotLight3D`
2 parents 3e3a013 + 5125adf commit dc5f1b7

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2614,9 +2614,9 @@ void RenderForwardClustered::_render_shadow_pass(RID p_light, RID p_shadow_atlas
26142614
Rect2 atlas_rect_norm = atlas_rect;
26152615
atlas_rect_norm.position /= float(atlas_size);
26162616
atlas_rect_norm.size /= float(atlas_size);
2617-
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), light_projection.get_z_far(), false);
2617+
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), zfar, false);
26182618
atlas_rect_norm.position += Vector2(dual_paraboloid_offset) * atlas_rect_norm.size;
2619-
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), light_projection.get_z_far(), true);
2619+
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), zfar, true);
26202620

26212621
//restore transform so it can be properly used
26222622
light_storage->light_instance_set_shadow_transform(p_light, Projection(), light_storage->light_instance_get_base_transform(p_light), zfar, 0, 0, 0);

servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1382,9 +1382,9 @@ void RenderForwardMobile::_render_shadow_pass(RID p_light, RID p_shadow_atlas, i
13821382
Rect2 atlas_rect_norm = atlas_rect;
13831383
atlas_rect_norm.position /= float(atlas_size);
13841384
atlas_rect_norm.size /= float(atlas_size);
1385-
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), light_projection.get_z_far(), false);
1385+
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), zfar, false);
13861386
atlas_rect_norm.position += Vector2(dual_paraboloid_offset) * atlas_rect_norm.size;
1387-
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), light_projection.get_z_far(), true);
1387+
copy_effects->copy_cubemap_to_dp(render_texture, atlas_fb, atlas_rect_norm, atlas_rect.size, light_projection.get_z_near(), zfar, true);
13881388

13891389
//restore transform so it can be properly used
13901390
light_storage->light_instance_set_shadow_transform(p_light, Projection(), light_storage->light_instance_get_base_transform(p_light), zfar, 0, 0, 0);

servers/rendering/renderer_scene_cull.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2558,8 +2558,9 @@ bool RendererSceneCull::_light_instance_update_shadow(Instance *p_instance, cons
25582558
}
25592559

25602560
real_t radius = RSG::light_storage->light_get_param(p_instance->base, RS::LIGHT_PARAM_RANGE);
2561+
real_t z_near = 0.005f;
25612562
Projection cm;
2562-
cm.set_perspective(90, 1, radius * 0.005f, radius);
2563+
cm.set_perspective(90, 1, z_near, radius);
25632564

25642565
for (int i = 0; i < 6; i++) {
25652566
RENDER_TIMESTAMP("Cull OmniLight3D Shadow Cube, Side " + itos(i));
@@ -2647,9 +2648,10 @@ bool RendererSceneCull::_light_instance_update_shadow(Instance *p_instance, cons
26472648

26482649
real_t radius = RSG::light_storage->light_get_param(p_instance->base, RS::LIGHT_PARAM_RANGE);
26492650
real_t angle = RSG::light_storage->light_get_param(p_instance->base, RS::LIGHT_PARAM_SPOT_ANGLE);
2651+
real_t z_near = 0.005f;
26502652

26512653
Projection cm;
2652-
cm.set_perspective(angle * 2.0, 1.0, 0.005f * radius, radius);
2654+
cm.set_perspective(angle * 2.0, 1.0, z_near, radius);
26532655

26542656
Vector<Plane> planes = cm.get_projection_planes(light_transform);
26552657

0 commit comments

Comments
 (0)