diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md
index 13064adad00..1683ea9e2d2 100644
--- a/com.unity.render-pipelines.high-definition/CHANGELOG.md
+++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Exposed the API to access HDRP shader pass names.
- Added the status check of default camera frame settings in the DXR wizard.
- Added frame setting for Virtual Texturing.
+- Added a fade distance for light influencing volumetric lighting.
### Fixed
- Fixed a null reference exception when creating a diffusion profile asset.
diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs
index 27b7442decd..2eaf9d4624b 100644
--- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs
+++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.Skin.cs
@@ -103,6 +103,7 @@ sealed class Styles
// Volumetric Additional light data
public readonly GUIContent volumetricEnable = new GUIContent("Enable", "When enabled, this Light uses Volumetrics.");
public readonly GUIContent volumetricDimmer = new GUIContent("Multiplier", "Controls the intensity of the scattered Volumetric lighting.");
+ public readonly GUIContent volumetricFadeDistance = new GUIContent("Fade Distance", "The distance at which light smoothly fades out from contributing to volumetric lighting.");
// Volumetric Additional shadow data
public readonly GUIContent volumetricShadowDimmer = new GUIContent("Shadow Dimmer", "Dims the volumetric shadows this Light casts.");
diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs
index c0480c596bb..c114982ca93 100644
--- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs
+++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs
@@ -991,6 +991,11 @@ static void DrawVolumetric(SerializedHDLight serialized, Editor owner)
{
EditorGUILayout.PropertyField(serialized.volumetricDimmer, s_Styles.volumetricDimmer);
EditorGUILayout.Slider(serialized.volumetricShadowDimmer, 0.0f, 1.0f, s_Styles.volumetricShadowDimmer);
+ HDLightType lightType = serialized.type;
+ if (lightType != HDLightType.Directional)
+ {
+ EditorGUILayout.PropertyField(serialized.volumetricFadeDistance, s_Styles.volumetricFadeDistance);
+ }
}
}
diff --git a/com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs b/com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs
index 0e897c269d5..eb47bf03b96 100644
--- a/com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs
+++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/SerializedHDLight.cs
@@ -27,6 +27,7 @@ internal class SerializedHDLight
public SerializedProperty maxSmoothness;
public SerializedProperty applyRangeAttenuation;
public SerializedProperty volumetricDimmer;
+ public SerializedProperty volumetricFadeDistance;
public SerializedProperty lightUnit;
public SerializedProperty displayAreaLightEmissiveMesh;
public SerializedProperty areaLightEmissiveMeshCastShadow;
@@ -336,6 +337,7 @@ public SerializedHDLight(HDAdditionalLightData[] lightDatas, LightEditor.Setting
spotIESCutoffPercent = o.Find("m_SpotIESCutoffPercent");
lightDimmer = o.Find("m_LightDimmer");
volumetricDimmer = o.Find("m_VolumetricDimmer");
+ volumetricFadeDistance = o.Find("m_VolumetricFadeDistance");
lightUnit = o.Find("m_LightUnit");
displayAreaLightEmissiveMesh = o.Find("m_DisplayAreaLightEmissiveMesh");
fadeDistance = o.Find("m_FadeDistance");
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs
index 17815178e4d..c54c6ec34a7 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs
@@ -304,6 +304,24 @@ public float fadeDistance
}
}
+ // Not used for directional lights.
+ [SerializeField]
+ float m_VolumetricFadeDistance = 10000.0f;
+ ///
+ /// Get/Set the light fade distance for volumetrics.
+ ///
+ public float volumetricFadeDistance
+ {
+ get => m_VolumetricFadeDistance;
+ set
+ {
+ if (m_VolumetricFadeDistance == value)
+ return;
+
+ m_VolumetricFadeDistance = Mathf.Clamp(value, 0, float.MaxValue);
+ }
+ }
+
[SerializeField, FormerlySerializedAs("affectDiffuse")]
bool m_AffectDiffuse = true;
///
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
index a1f28c7516d..395798aa233 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
@@ -259,6 +259,7 @@ internal struct ProcessedLightData
public LightVolumeType lightVolumeType;
public float distanceToCamera;
public float lightDistanceFade;
+ public float volumetricDistanceFade;
public bool isBakedShadowMask;
}
@@ -1548,7 +1549,7 @@ internal void GetLightData(CommandBuffer cmd, HDCamera hdCamera, HDShadowSetting
lightData.lightDimmer = processedData.lightDistanceFade * (additionalLightData.lightDimmer);
lightData.diffuseDimmer = processedData.lightDistanceFade * (additionalLightData.affectDiffuse ? additionalLightData.lightDimmer : 0);
lightData.specularDimmer = processedData.lightDistanceFade * (additionalLightData.affectSpecular ? additionalLightData.lightDimmer * hdCamera.frameSettings.specularGlobalDimmer : 0);
- lightData.volumetricLightDimmer = processedData.lightDistanceFade * (additionalLightData.volumetricDimmer);
+ lightData.volumetricLightDimmer = Mathf.Min(processedData.volumetricDistanceFade, processedData.lightDistanceFade) * (additionalLightData.volumetricDimmer);
lightData.cookieMode = CookieMode.None;
lightData.shadowIndex = -1;
@@ -2278,6 +2279,7 @@ void PreprocessLightData(ref ProcessedLightData processedData, VisibleLight ligh
ref processedData.lightCategory, ref processedData.gpuLightType, ref processedData.lightVolumeType);
processedData.lightDistanceFade = processedData.gpuLightType == GPULightType.Directional ? 1.0f : HDUtils.ComputeLinearDistanceFade(processedData.distanceToCamera, additionalLightData.fadeDistance);
+ processedData.volumetricDistanceFade = processedData.gpuLightType == GPULightType.Directional ? 1.0f : HDUtils.ComputeLinearDistanceFade(processedData.distanceToCamera, additionalLightData.volumetricFadeDistance);
processedData.isBakedShadowMask = IsBakedShadowMaskLight(lightComponent);
}