Add variable rate update for shadow maps atlas based on distance to light

This commit is contained in:
Wojtek Figat
2024-04-08 00:04:57 +02:00
parent 7d92779e99
commit 708fba5136
11 changed files with 328 additions and 151 deletions

View File

@@ -38,6 +38,8 @@ void DirectionalLight::Draw(RenderContext& renderContext)
data.VolumetricScatteringIntensity = VolumetricScatteringIntensity;
data.IndirectLightingIntensity = IndirectLightingIntensity;
data.CastVolumetricShadow = CastVolumetricShadow;
data.ShadowsUpdateRate = ShadowsUpdateRate;
data.ShadowsUpdateRateAtDistance = ShadowsUpdateRateAtDistance;
data.ShadowsMode = ShadowsMode;
data.CascadeCount = CascadeCount;
data.Cascade1Spacing = Cascade1Spacing;

View File

@@ -100,6 +100,8 @@ void LightWithShadow::Serialize(SerializeStream& stream, const void* otherObj)
SERIALIZE(ShadowsDepthBias);
SERIALIZE(ShadowsNormalOffsetScale);
SERIALIZE(ContactShadowsLength);
SERIALIZE(ShadowsUpdateRate);
SERIALIZE(ShadowsUpdateRateAtDistance);
}
void LightWithShadow::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
@@ -116,4 +118,6 @@ void LightWithShadow::Deserialize(DeserializeStream& stream, ISerializeModifier*
DESERIALIZE(ShadowsDepthBias);
DESERIALIZE(ShadowsNormalOffsetScale);
DESERIALIZE(ContactShadowsLength);
DESERIALIZE(ShadowsUpdateRate);
DESERIALIZE(ShadowsUpdateRateAtDistance);
}

View File

@@ -128,6 +128,18 @@ public:
API_FIELD(Attributes="EditorOrder(99), EditorDisplay(\"Shadow\"), Limit(0.0f, 0.1f, 0.001f)")
float ContactShadowsLength = 0.0f;
/// <summary>
/// Frequency of shadow updates. 1 - every frame, 0.5 - every second frame, 0 - on start or change. It's the inverse value of how many frames should happen in-between shadow map updates (eg. inverse of 0.5 is 2 thus shadow will update every 2nd frame).
/// </summary>
API_FIELD(Attributes="EditorOrder(100), EditorDisplay(\"Shadow\", \"Update Rate\"), Limit(0.0f, 1.0f)")
float ShadowsUpdateRate = 1.0f;
/// <summary>
/// Frequency of shadow updates at the maximum distance from the view at which shadows are still rendered. This value is multiplied by ShadowsUpdateRate and allows scaling the update rate in-between the shadow range. For example, if light is near view, it will get normal shadow updates but will reduce this rate when far from view. See ShadowsUpdateRate to learn more.
/// </summary>
API_FIELD(Attributes="EditorOrder(105), EditorDisplay(\"Shadow\", \"Update Rate At Distance\"), Limit(0.0f, 1.0f)")
float ShadowsUpdateRateAtDistance = 0.5f;
/// <summary>
/// Describes how a visual element casts shadows.
/// </summary>

View File

@@ -103,6 +103,8 @@ void PointLight::Draw(RenderContext& renderContext)
data.ShadowsSharpness = ShadowsSharpness;
data.VolumetricScatteringIntensity = VolumetricScatteringIntensity;
data.CastVolumetricShadow = CastVolumetricShadow;
data.ShadowsUpdateRate = ShadowsUpdateRate;
data.ShadowsUpdateRateAtDistance = ShadowsUpdateRateAtDistance;
data.ShadowsMode = ShadowsMode;
data.Radius = radius;
data.FallOffExponent = FallOffExponent;

View File

@@ -153,6 +153,8 @@ void SpotLight::Draw(RenderContext& renderContext)
data.ShadowsSharpness = ShadowsSharpness;
data.VolumetricScatteringIntensity = VolumetricScatteringIntensity;
data.CastVolumetricShadow = CastVolumetricShadow;
data.ShadowsUpdateRate = ShadowsUpdateRate;
data.ShadowsUpdateRateAtDistance = ShadowsUpdateRateAtDistance;
data.ShadowsMode = ShadowsMode;
data.Radius = radius;
data.FallOffExponent = FallOffExponent;