diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md
index 1bb5b02b5df..686d8accbbd 100644
--- a/com.unity.render-pipelines.high-definition/CHANGELOG.md
+++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md
@@ -113,6 +113,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed screen space shadow when multiple lights cast shadows.
- Fixed issue with accumulation motion blur and depth of field when path tracing is enabled.
- Fixed issue with dynamic resolution and low res transparency sampling garbage outside of the render target.
+- Fixed issue with raytraced shadows being visible alongside shadowmask.
## [14.0.0] - 2021-11-17
diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Ray-Traced-Shadows.md b/com.unity.render-pipelines.high-definition/Documentation~/Ray-Traced-Shadows.md
index 6f514837fb1..ee8781a8cd3 100644
--- a/com.unity.render-pipelines.high-definition/Documentation~/Ray-Traced-Shadows.md
+++ b/com.unity.render-pipelines.high-definition/Documentation~/Ray-Traced-Shadows.md
@@ -31,6 +31,8 @@ Finally, to make HDRP process ray-traced shadows for your Directional, Point, or
2. Also in the Shadow Map foldout, enable Ray-Traced Shadows. For Directional Lights, you need to enable Screen Space Shadows to access this property.
3. To change the behavior of the shadows, edit the properties under Ray-Traced Shadows.
+If a light is has **Shadowmask Mode** set to **Shadowmask**, then ray traced shadows will not be rendered and shadow masks will be used instead.
+
## Directional Light
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 8200bb4fefe..a83cab9ebc3 100644
--- a/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs
+++ b/com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs
@@ -171,6 +171,12 @@ void IDisposable.Dispose()
}
}
+ // !!! This is very weird, but for some reason the change of this field is not registered when changed.
+ // Because it is important to trigger the rebuild of the light entity (for the burst light loop) and it
+ // happens only when a change in editor happens !!!
+ // The issue is likely on the C# trunk side with the GUI Dropdown.
+ static int s_OldLightBakeType = (int)LightmapBakeType.Realtime;
+
static void DrawGeneralContent(SerializedHDLight serialized, Editor owner, bool isPreset = false)
{
EditorGUI.BeginChangeCheck();
@@ -226,10 +232,20 @@ static void DrawGeneralContent(SerializedHDLight serialized, Editor owner, bool
}
EditorGUI.showMixedValue = false;
+ // We need to trigger an update if the bake mode changes
+ var lightBakeType = ((Light)owner.target).lightmapBakeType;
+
// Draw the mode, for Tube and Disc lights, there is only one choice, so we can disable the enum.
using (new EditorGUI.DisabledScope(updatedLightType == HDLightType.Area && (serialized.areaLightShape == AreaLightShape.Tube || serialized.areaLightShape == AreaLightShape.Disc)))
serialized.settings.DrawLightmapping();
+
+ if (s_OldLightBakeType != serialized.settings.lightmapping.intValue)
+ {
+ s_OldLightBakeType = serialized.settings.lightmapping.intValue;
+ GUI.changed = true;
+ }
+
if (updatedLightType == HDLightType.Area)
{
switch (serialized.areaLightShape)
@@ -1153,6 +1169,7 @@ static void DrawShadowMapContent(SerializedHDLight serialized, Editor owner)
if (lightType != HDLightType.Directional)
EditorGUILayout.Slider(serialized.shadowNearPlane, HDShadowUtils.k_MinShadowNearPlane, HDShadowUtils.k_MaxShadowNearPlane, s_Styles.shadowNearPlane);
+ bool fullShadowMask = false;
if (serialized.settings.isMixed)
{
bool enabled = HDRenderPipeline.currentAsset.currentPlatformRenderPipelineSettings.supportShadowMask;
@@ -1166,10 +1183,12 @@ static void DrawShadowMapContent(SerializedHDLight serialized, Editor owner)
EditorGUI.BeginChangeCheck();
ShadowmaskMode shadowmask = serialized.nonLightmappedOnly.boolValue ? ShadowmaskMode.Shadowmask : ShadowmaskMode.DistanceShadowmask;
shadowmask = (ShadowmaskMode)EditorGUI.EnumPopup(nonLightmappedOnlyRect, s_Styles.nonLightmappedOnly, shadowmask);
+ fullShadowMask = shadowmask == ShadowmaskMode.Shadowmask;
+
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObjects(owner.targets, "Light Update Shadowmask Mode");
- serialized.nonLightmappedOnly.boolValue = shadowmask == ShadowmaskMode.Shadowmask;
+ serialized.nonLightmappedOnly.boolValue = fullShadowMask;
foreach (Light target in owner.targets)
target.lightShadowCasterMode = shadowmask == ShadowmaskMode.Shadowmask ? LightShadowCasterMode.NonLightmappedOnly : LightShadowCasterMode.Everything;
}
@@ -1188,28 +1207,31 @@ static void DrawShadowMapContent(SerializedHDLight serialized, Editor owner)
bool isPunctual = lightType == HDLightType.Point || (lightType == HDLightType.Spot && serialized.spotLightShape.GetEnumValue() == SpotLightShape.Cone);
if (isPunctual || (lightType == HDLightType.Area && serialized.areaLightShape == AreaLightShape.Rectangle))
{
- EditorGUILayout.PropertyField(serialized.useRayTracedShadows, s_Styles.useRayTracedShadows);
- if (serialized.useRayTracedShadows.boolValue)
+ using (new EditorGUI.DisabledScope(fullShadowMask))
{
- if (hdrp != null && lightType == HDLightType.Area && serialized.areaLightShape == AreaLightShape.Rectangle
- && (hdrp.currentPlatformRenderPipelineSettings.supportedLitShaderMode != RenderPipelineSettings.SupportedLitShaderMode.DeferredOnly))
- EditorGUILayout.HelpBox("Ray traced area light shadows are approximated for the Lit shader when not in deferred mode.", MessageType.Warning);
+ EditorGUILayout.PropertyField(serialized.useRayTracedShadows, s_Styles.useRayTracedShadows);
+ if (serialized.useRayTracedShadows.boolValue)
+ {
+ if (hdrp != null && lightType == HDLightType.Area && serialized.areaLightShape == AreaLightShape.Rectangle
+ && (hdrp.currentPlatformRenderPipelineSettings.supportedLitShaderMode != RenderPipelineSettings.SupportedLitShaderMode.DeferredOnly))
+ EditorGUILayout.HelpBox("Ray traced area light shadows are approximated for the Lit shader when not in deferred mode.", MessageType.Warning);
- EditorGUI.indentLevel++;
+ EditorGUI.indentLevel++;
- // We only support semi transparent shadows for punctual lights
- if (isPunctual)
- EditorGUILayout.PropertyField(serialized.semiTransparentShadow, s_Styles.semiTransparentShadow);
+ // We only support semi transparent shadows for punctual lights
+ if (isPunctual)
+ EditorGUILayout.PropertyField(serialized.semiTransparentShadow, s_Styles.semiTransparentShadow);
- EditorGUILayout.PropertyField(serialized.numRayTracingSamples, s_Styles.numRayTracingSamples);
- EditorGUILayout.PropertyField(serialized.filterTracedShadow, s_Styles.denoiseTracedShadow);
- EditorGUI.indentLevel++;
- EditorGUILayout.PropertyField(serialized.filterSizeTraced, s_Styles.denoiserRadius);
- // We only support distance based filtering if we have a punctual light source (point or spot)
- if (isPunctual)
- EditorGUILayout.PropertyField(serialized.distanceBasedFiltering, s_Styles.distanceBasedFiltering);
- EditorGUI.indentLevel--;
- EditorGUI.indentLevel--;
+ EditorGUILayout.PropertyField(serialized.numRayTracingSamples, s_Styles.numRayTracingSamples);
+ EditorGUILayout.PropertyField(serialized.filterTracedShadow, s_Styles.denoiseTracedShadow);
+ EditorGUI.indentLevel++;
+ EditorGUILayout.PropertyField(serialized.filterSizeTraced, s_Styles.denoiserRadius);
+ // We only support distance based filtering if we have a punctual light source (point or spot)
+ if (isPunctual)
+ EditorGUILayout.PropertyField(serialized.distanceBasedFiltering, s_Styles.distanceBasedFiltering);
+ EditorGUI.indentLevel--;
+ EditorGUI.indentLevel--;
+ }
}
}
}
@@ -1220,7 +1242,8 @@ static void DrawShadowMapContent(SerializedHDLight serialized, Editor owner)
EditorGUILayout.PropertyField(serialized.useScreenSpaceShadows, s_Styles.useScreenSpaceShadows);
if (HDRenderPipeline.assetSupportsRayTracing)
{
- using (new EditorGUI.DisabledScope(!serialized.useScreenSpaceShadows.boolValue))
+ bool showRayTraced = serialized.useScreenSpaceShadows.boolValue && !fullShadowMask;
+ using (new EditorGUI.DisabledScope(!showRayTraced))
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serialized.useRayTracedShadows, s_Styles.useRayTracedShadows);
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 a5ae5e3dfba..4f7e57d2e15 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
@@ -400,6 +400,10 @@ public bool nonLightmappedOnly
m_NonLightmappedOnly = value;
legacyLight.lightShadowCasterMode = value ? LightShadowCasterMode.NonLightmappedOnly : LightShadowCasterMode.Everything;
+ // We need to update the ray traced shadow flag as we don't want ray traced shadows with shadow mask.
+ if (lightEntity.valid)
+ HDLightRenderDatabase.instance.EditLightDataAsRef(lightEntity).useRayTracedShadows = m_UseRayTracedShadows && !m_NonLightmappedOnly;
+
}
}
@@ -3627,7 +3631,17 @@ internal void UpdateRenderEntity()
lightRenderData.volumetricFadeDistance = m_VolumetricFadeDistance;
lightRenderData.includeForRayTracing = m_IncludeForRayTracing;
lightRenderData.useScreenSpaceShadows = m_UseScreenSpaceShadows;
- lightRenderData.useRayTracedShadows = m_UseRayTracedShadows;
+
+ // If we are pure shadowmask, we disable raytraced shadows.
+#if UNITY_EDITOR
+ if (legacyLight.lightmapBakeType == LightmapBakeType.Mixed)
+#else
+ if (legacyLight.bakingOutput.lightmapBakeType == LightmapBakeType.Mixed)
+#endif
+ lightRenderData.useRayTracedShadows = !m_NonLightmappedOnly && m_UseRayTracedShadows;
+ else
+ lightRenderData.useRayTracedShadows = m_UseRayTracedShadows;
+
lightRenderData.colorShadow = m_ColorShadow;
lightRenderData.lightDimmer = m_LightDimmer;
lightRenderData.volumetricDimmer = m_VolumetricDimmer;