Skip to content

Commit aa57d39

Browse files
Register shadows OnDemand to the cached shadow system only when rendered for the first time. (#6825)
* Fix a couple of issues * Changelog * Change how the registering to the sysem works for ondemand * Changelog * Fix wrong warning Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
1 parent cf6499f commit aa57d39

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
8080
- Fixed an issue where sometimes full screen debug would cause render graph errors.
8181
- Fixed a nullref exception when creating a new scene while LightExplorer is open.
8282
- Fixed issue that caused the uber post process to run even if nothing is to be done, leading to different results when disabling every post process manually vs disabling the whole post-processing pipeline.
83+
- Fixed issue that placed an OnDemand shadow in the atlas before it was ever rendered.
8384

8485
## [14.0.0] - 2021-11-17
8586

com.unity.render-pipelines.high-definition/Editor/Lighting/HDLightUI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,8 @@ static void DrawShadowMapContent(SerializedHDLight serialized, Editor owner)
10511051
{
10521052
HDLightEditor editor = owner as HDLightEditor;
10531053
var additionalLightData = editor.GetAdditionalDataForTargetIndex(0);
1054-
if (!HDCachedShadowManager.instance.LightHasBeenPlacedInAtlas(additionalLightData))
1054+
// If the light was registered, but not placed it means it doesn't fit.
1055+
if (additionalLightData.lightIdxForCachedShadows >= 0 && !HDCachedShadowManager.instance.LightHasBeenPlacedInAtlas(additionalLightData))
10551056
{
10561057
string warningMessage = "The shadow for this light doesn't fit the cached shadow atlas and therefore won't be rendered. Please ensure you have enough space in the cached shadow atlas. You can use the light explorer (Window->Rendering->Light Explorer) to see which lights fit and which don't.\nConsult HDRP Shadow documentation for more information about cached shadow management.";
10571058
// Loop backward in "tile" size to check

com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,9 @@ public ShadowUpdateMode shadowUpdateMode
15491549
}
15501550
else if (legacyLight.shadows != LightShadows.None && m_ShadowUpdateMode == ShadowUpdateMode.EveryFrame && value != ShadowUpdateMode.EveryFrame)
15511551
{
1552-
HDShadowManager.cachedShadowManager.RegisterLight(this);
1552+
// If we are OnDemand not rendered on placement, we defer the registering of the light until the rendering is requested.
1553+
if (!(shadowUpdateMode == ShadowUpdateMode.OnDemand && !onDemandShadowRenderOnPlacement))
1554+
HDShadowManager.cachedShadowManager.RegisterLight(this);
15531555
}
15541556

15551557
m_ShadowUpdateMode = value;
@@ -3239,7 +3241,9 @@ internal void RefreshCachedShadow()
32393241

32403242
if (!ShadowIsUpdatedEveryFrame() && legacyLight.shadows != LightShadows.None)
32413243
{
3242-
HDShadowManager.cachedShadowManager.RegisterLight(this);
3244+
// If we are OnDemand not rendered on placement, we defer the registering of the light until the rendering is requested.
3245+
if (!(shadowUpdateMode == ShadowUpdateMode.OnDemand && !onDemandShadowRenderOnPlacement))
3246+
HDShadowManager.cachedShadowManager.RegisterLight(this);
32433247
}
32443248
}
32453249

@@ -3664,9 +3668,11 @@ internal void CreateHDLightRenderEntity(bool autoDestroy = false)
36643668

36653669
void OnEnable()
36663670
{
3667-
if (shadowUpdateMode != ShadowUpdateMode.EveryFrame && legacyLight.shadows != LightShadows.None)
3671+
if (!ShadowIsUpdatedEveryFrame() && legacyLight.shadows != LightShadows.None)
36683672
{
3669-
HDShadowManager.cachedShadowManager.RegisterLight(this);
3673+
// If we are OnDemand not rendered on placement, we defer the registering of the light until the rendering is requested.
3674+
if (!(shadowUpdateMode == ShadowUpdateMode.OnDemand && !onDemandShadowRenderOnPlacement))
3675+
HDShadowManager.cachedShadowManager.RegisterLight(this);
36703676
}
36713677

36723678
SetEmissiveMeshRendererEnabled(true);

com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDCachedShadowAtlas.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ internal void ScheduleShadowUpdate(HDAdditionalLightData lightData)
557557
if (!lightData.isActiveAndEnabled) return;
558558

559559
int lightIdx = lightData.lightIdxForCachedShadows;
560-
Debug.Assert(lightIdx >= 0);
561560

562561
if (!m_PlacedShadows.ContainsKey(lightIdx))
563562
{

0 commit comments

Comments
 (0)