diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2021-07-16 03:33:10 +0200 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2022-06-13 14:31:46 +0200 |
commit | 0225c6d31a8808e5d75c4a5e2d6d18bf5fd81dd6 (patch) | |
tree | 8859bab188435263bdf8ef7bcc2cd049cb2ace02 /servers | |
parent | 2f9a074fb4924b1afd0f596c8e7cd897380539c9 (diff) |
Tweak Light3D property hints for greater flexibility
- Specular can now be set above 1.0.
- Blur can be set to 0 to disable shadow blurring entirely, which is useful
on lights that have a non-zero size.
- When shadow blurring is disabled, lights that have a non-zero size will
not use PCSS-like soft shadows, speeding up shadow rendering
considerably.
- Some property hints now allow more precise values.
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/renderer_rd/renderer_scene_render_rd.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index a1c6ff540d..ef959bc3c6 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -3457,7 +3457,9 @@ void RendererSceneRenderRD::_setup_lights(const PagedArray<RID> &p_lights, const // technically this will keep expanding until reaching the sun, but all we care // is expand until we reach the radius of the near plane (there can't be more occluders than that) angular_diameter = Math::tan(Math::deg2rad(angular_diameter)); - if (light_storage->light_has_shadow(base)) { + if (light_storage->light_has_shadow(base) && light_storage->light_get_param(base, RS::LIGHT_PARAM_SHADOW_BLUR) > 0.0) { + // Only enable PCSS-like soft shadows if blurring is enabled. + // Otherwise, performance would decrease with no visual difference. r_directional_light_soft_shadows = true; } } else { @@ -3736,7 +3738,9 @@ void RendererSceneRenderRD::_setup_lights(const PagedArray<RID> &p_lights, const RendererStorageRD::store_transform(proj, light_data.shadow_matrix); - if (size > 0.0) { + if (size > 0.0 && light_data.soft_shadow_scale > 0.0) { + // Only enable PCSS-like soft shadows if blurring is enabled. + // Otherwise, performance would decrease with no visual difference. light_data.soft_shadow_size = size; } else { light_data.soft_shadow_size = 0.0; @@ -3753,7 +3757,9 @@ void RendererSceneRenderRD::_setup_lights(const PagedArray<RID> &p_lights, const CameraMatrix shadow_mtx = bias * li->shadow_transform[0].camera * modelview; RendererStorageRD::store_camera(shadow_mtx, light_data.shadow_matrix); - if (size > 0.0) { + if (size > 0.0 && light_data.soft_shadow_scale > 0.0) { + // Only enable PCSS-like soft shadows if blurring is enabled. + // Otherwise, performance would decrease with no visual difference. CameraMatrix cm = li->shadow_transform[0].camera; float half_np = cm.get_z_near() * Math::tan(Math::deg2rad(spot_angle)); light_data.soft_shadow_size = (size * 0.5 / radius) / (half_np / cm.get_z_near()) * rect.size.width; |