From a79849b351b444d946bfcae18ddf7e50aa6d90af Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 20 Oct 2020 15:08:07 +0200 Subject: [PATCH 1/3] Fade --- .../Editor/Lighting/HDLightUI.Skin.cs | 1 + .../Editor/Lighting/HDLightUI.cs | 1 + .../Editor/Lighting/SerializedHDLight.cs | 2 ++ .../Lighting/Light/HDAdditionalLightData.cs | 18 ++++++++++++++++++ .../Runtime/Lighting/LightLoop/LightLoop.cs | 4 +++- 5 files changed, 25 insertions(+), 1 deletion(-) 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 21a7098c64f..fbe3021c6df 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,7 @@ 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); + 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 ca7c4930573..a3808bbc952 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 098bde0f962..e8d8c7ee997 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); } From 7401e9a7fd3a307bbe6743f5f323b87bebfcc48b Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 20 Oct 2020 16:04:33 +0200 Subject: [PATCH 2/3] changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 0fc25d5c255..c7ad5282f77 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added a new ray tracing only function that samples the specular part of the materials. - Adding missing marker for ray tracing profiling (RaytracingDeferredLighting) - Added the support of eye shader for ray tracing. +- Added a fade distance for light influencing volumetric lighting. ### Fixed - Fixed several issues with physically-based DoF (TAA ghosting of the CoC buffer, smooth layer transitions, etc) From 2b9453ffaacc85980a392246cdbf9b9081244b04 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 20 Oct 2020 17:24:05 +0200 Subject: [PATCH 3/3] Don't display on directional --- .../Editor/Lighting/HDLightUI.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 fbe3021c6df..bd57d488d56 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs @@ -991,7 +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); - EditorGUILayout.PropertyField(serialized.volumetricFadeDistance, s_Styles.volumetricFadeDistance); + HDLightType lightType = serialized.type; + if (lightType != HDLightType.Directional) + { + EditorGUILayout.PropertyField(serialized.volumetricFadeDistance, s_Styles.volumetricFadeDistance); + } } }