From 1806661462b2b11419dd3b286ec80ebc160ae7be Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Mon, 25 Oct 2021 21:57:34 +0200 Subject: [PATCH] Only show relevant properties in the DirectionalLight inspector Some split distance properties are unused depending on the current shadow mode. Also, Blend Splits and Bias Split Scale can only be used if the shadow mode is PSSM 2 Splits or PSSM 4 Splits. --- doc/classes/DirectionalLight.xml | 12 ++++++------ scene/3d/light.cpp | 15 +++++++++++++++ scene/3d/light.h | 1 + 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/doc/classes/DirectionalLight.xml b/doc/classes/DirectionalLight.xml index aa3b7b0748..e292c38611 100644 --- a/doc/classes/DirectionalLight.xml +++ b/doc/classes/DirectionalLight.xml @@ -13,16 +13,16 @@ - Amount of extra bias for shadow splits that are far away. If self-shadowing occurs only on the splits far away, increasing this value can fix them. + Amount of extra bias for shadow splits that are far away. If self-shadowing occurs only on the splits far away, increasing this value can fix them. This is ignored when [member directional_shadow_mode] is [constant SHADOW_ORTHOGONAL]. - If [code]true[/code], shadow detail is sacrificed in exchange for smoother transitions between splits. + If [code]true[/code], shadow detail is sacrificed in exchange for smoother transitions between splits. Enabling shadow blend splitting also has a moderate performance cost. This is ignored when [member directional_shadow_mode] is [constant SHADOW_ORTHOGONAL]. Optimizes shadow rendering for detail versus movement. See [enum ShadowDepthRange]. - The maximum distance for shadow splits. + The maximum distance for shadow splits. Increasing this value will make directional shadows visible from further away, at the cost of lower overall shadow detail and performance (since more objects need to be included in the directional shadow rendering). The light's shadow rendering algorithm. See [enum ShadowMode]. @@ -31,13 +31,13 @@ Can be used to fix special cases of self shadowing when objects are perpendicular to the light. - The distance from camera to shadow split 1. Relative to [member directional_shadow_max_distance]. Only used when [member directional_shadow_mode] is [code]SHADOW_PARALLEL_2_SPLITS[/code] or [code]SHADOW_PARALLEL_4_SPLITS[/code]. + The distance from camera to shadow split 1. Relative to [member directional_shadow_max_distance]. Only used when [member directional_shadow_mode] is [constant SHADOW_PARALLEL_2_SPLITS] or [constant SHADOW_PARALLEL_4_SPLITS]. - The distance from shadow split 1 to split 2. Relative to [member directional_shadow_max_distance]. Only used when [member directional_shadow_mode] is [code]SHADOW_PARALLEL_2_SPLITS[/code] or [code]SHADOW_PARALLEL_4_SPLITS[/code]. + The distance from shadow split 1 to split 2. Relative to [member directional_shadow_max_distance]. Only used when [member directional_shadow_mode] is [constant SHADOW_PARALLEL_2_SPLITS] or [constant SHADOW_PARALLEL_4_SPLITS]. - The distance from shadow split 2 to split 3. Relative to [member directional_shadow_max_distance]. Only used when [member directional_shadow_mode] is [code]SHADOW_PARALLEL_4_SPLITS[/code]. + The distance from shadow split 2 to split 3. Relative to [member directional_shadow_max_distance]. Only used when [member directional_shadow_mode] is [constant SHADOW_PARALLEL_4_SPLITS]. diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 32ba2d7c5a..a20cce74e4 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -331,6 +331,7 @@ Light::~Light() { void DirectionalLight::set_shadow_mode(ShadowMode p_mode) { shadow_mode = p_mode; VS::get_singleton()->light_directional_set_shadow_mode(light, VS::LightDirectionalShadowMode(p_mode)); + property_list_changed_notify(); } DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const { @@ -355,6 +356,20 @@ bool DirectionalLight::is_blend_splits_enabled() const { return blend_splits; } +void DirectionalLight::_validate_property(PropertyInfo &property) const { + if (shadow_mode == SHADOW_ORTHOGONAL && (property.name == "directional_shadow_split_1" || property.name == "directional_shadow_blend_splits" || property.name == "directional_shadow_bias_split_scale")) { + // Split 2, split blending and bias split scale are only used with the PSSM 2 Splits and PSSM 4 Splits shadow modes. + property.usage = PROPERTY_USAGE_NOEDITOR; + } + + if ((shadow_mode == SHADOW_ORTHOGONAL || shadow_mode == SHADOW_PARALLEL_2_SPLITS) && (property.name == "directional_shadow_split_2" || property.name == "directional_shadow_split_3")) { + // Splits 3 and 4 are only used with the PSSM 4 Splits shadow mode. + property.usage = PROPERTY_USAGE_NOEDITOR; + } + + Light::_validate_property(property); +} + void DirectionalLight::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight::set_shadow_mode); ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight::get_shadow_mode); diff --git a/scene/3d/light.h b/scene/3d/light.h index 5561273fff..e854bfb97d 100644 --- a/scene/3d/light.h +++ b/scene/3d/light.h @@ -152,6 +152,7 @@ private: protected: static void _bind_methods(); + virtual void _validate_property(PropertyInfo &property) const; public: void set_shadow_mode(ShadowMode p_mode);