Skip to content

Commit a0bd01d

Browse files
kennytannEvergreen
authored andcommitted
[Port] [6000.3] [UUM-139229][URP 2D] Fix preview camera missing lighting and shadows
1 parent 1c8465e commit a0bd01d

3 files changed

Lines changed: 33 additions & 34 deletions

File tree

Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawLight2DPass.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,12 @@ internal void Render(RenderGraph graph, ContextContainer frameData, Renderer2DDa
180180
Universal2DResourceData universal2DResourceData = frameData.Get<Universal2DResourceData>();
181181
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
182182

183-
DebugHandler debugHandler = ScriptableRenderPass.GetActiveDebugHandler(cameraData);
184-
var isDebugLightingActive = debugHandler?.IsLightingActive ?? true;
185-
186-
#if UNITY_EDITOR
187-
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
188-
isDebugLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
189-
190-
if (cameraData.camera.cameraType == CameraType.Preview)
191-
isDebugLightingActive = false;
192-
#endif
183+
// Check for lighting in scene/prefab/preview camera
184+
var isLightingActive = Renderer2D.s_IsLightingActive;
193185

194186
if (!layerBatch.lightStats.useLights ||
195187
isVolumetric && !layerBatch.lightStats.useVolumetricLights ||
196-
!isDebugLightingActive)
188+
!isLightingActive)
197189
return;
198190

199191
// Render single RTs by for apis that don't support MRTs

Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/DrawRenderer2DPass.cs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private static void Execute(RasterGraphContext context, PassData passData)
3939
RendererLighting.SetLightShaderGlobals(cmd, passData.lightBlendStyles, passData.blendStyleIndices);
4040

4141
#if UNITY_EDITOR
42-
if (passData.isLitView)
42+
if (passData.isLightingActive)
4343
#endif
4444
{
4545
if (passData.layerUseLights)
@@ -87,7 +87,7 @@ class PassData
8787
internal bool activeDebugHandler;
8888

8989
#if UNITY_EDITOR
90-
internal bool isLitView; // Required for prefab view and preview camera
90+
internal bool isLightingActive; // Required for prefab view and preview camera
9191
#endif
9292
}
9393

@@ -100,35 +100,23 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
100100
CommonResourceData commonResourceData = frameData.Get<CommonResourceData>();
101101

102102
var layerBatch = layerBatches[batchIndex];
103-
bool isLitView = true;
104103

105-
#if UNITY_EDITOR
106-
// Early out for prefabs
107-
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
108-
isLitView = UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
109-
110-
// Early out for preview camera
111-
if (cameraData.cameraType == CameraType.Preview)
112-
isLitView = false;
113-
114-
DebugHandler debugHandler = GetActiveDebugHandler(cameraData);
115-
if (debugHandler != null)
116-
isLitView = debugHandler.IsLightingActive;
117-
#endif
104+
// Check for lighting in scene/prefab/preview camera
105+
var isLightingActive = Renderer2D.s_IsLightingActive;
118106

119107
// Preset global light textures for first batch
120108
if (batchIndex == 0)
121109
{
122110
using (var builder = graph.AddRasterRenderPass<SetGlobalPassData>(k_SetLightBlendTexture, out var passData, m_SetLightBlendTextureProfilingSampler))
123111
{
124-
if (layerBatch.lightStats.useLights && isLitView)
112+
if (layerBatch.lightStats.useLights && isLightingActive)
125113
{
126114
passData.lightTextures = universal2DResourceData.lightTextures[batchIndex];
127115
for (var i = 0; i < passData.lightTextures.Length; i++)
128116
builder.UseTexture(passData.lightTextures[i]);
129117
}
130118

131-
SetGlobalLightTextures(graph, builder, passData.lightTextures, ref layerBatch, rendererData, isLitView);
119+
SetGlobalLightTextures(graph, builder, passData.lightTextures, ref layerBatch, rendererData, isLightingActive);
132120

133121
builder.AllowGlobalStateModification(true);
134122

@@ -147,7 +135,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
147135
passData.isSceneLit = rendererData.lightCullResult.IsSceneLit();
148136
passData.layerUseLights = layerBatch.lightStats.useLights;
149137
#if UNITY_EDITOR
150-
passData.isLitView = isLitView;
138+
passData.isLightingActive = isLightingActive;
151139
#endif
152140

153141
var drawSettings = CreateDrawingSettings(k_ShaderTags, renderingData, cameraData, lightData, SortingCriteria.CommonTransparent);
@@ -172,7 +160,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
172160
builder.UseRendererList(passData.rendererList);
173161
}
174162

175-
if (passData.layerUseLights && isLitView)
163+
if (passData.layerUseLights && isLightingActive)
176164
{
177165
passData.lightTextures = universal2DResourceData.lightTextures[batchIndex];
178166
for (var i = 0; i < passData.lightTextures.Length; i++)
@@ -193,7 +181,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
193181
// Post set global light textures for next renderer pass
194182
var nextBatch = batchIndex + 1;
195183
if (nextBatch < universal2DResourceData.lightTextures.Length)
196-
SetGlobalLightTextures(graph, builder, universal2DResourceData.lightTextures[nextBatch], ref layerBatches[nextBatch], rendererData, isLitView);
184+
SetGlobalLightTextures(graph, builder, universal2DResourceData.lightTextures[nextBatch], ref layerBatches[nextBatch], rendererData, isLightingActive);
197185

198186
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
199187
{
@@ -202,9 +190,9 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
202190
}
203191
}
204192

205-
void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, TextureHandle[] lightTextures, ref LayerBatch layerBatch, Renderer2DData rendererData, bool isLitView)
193+
void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, TextureHandle[] lightTextures, ref LayerBatch layerBatch, Renderer2DData rendererData, bool isLightingActive)
206194
{
207-
if (isLitView)
195+
if (isLightingActive)
208196
{
209197
if (layerBatch.lightStats.useLights)
210198
{

Packages/com.unity.render-pipelines.universal/Runtime/2D/Rendergraph/Renderer2DRendergraph.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private struct ImportResourceSummary
6969
internal bool m_CreateColorTexture;
7070
internal bool m_CreateDepthTexture;
7171
bool ppcUpscaleRT = false;
72+
static internal bool s_IsLightingActive;
7273

7374
PostProcessPassRenderGraph m_PostProcessPassRenderGraph;
7475
ColorGradingLutPass m_ColorGradingLutPassRenderGraph;
@@ -343,8 +344,10 @@ public override void SetupCullingParameters(ref ScriptableCullingParameters cull
343344
void InitializeLayerBatches()
344345
{
345346
Universal2DResourceData resourceData = frameData.Get<Universal2DResourceData>();
347+
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
346348

347349
m_LayerBatches = LayerUtility.CalculateBatches(m_Renderer2DData, out m_BatchCount);
350+
s_IsLightingActive = IsSceneViewOrPreviewLightingActive(cameraData);
348351

349352
// Initialize textures dependent on batch size
350353
if (resourceData.normalsTexture.Length != m_BatchCount)
@@ -1074,5 +1077,21 @@ internal static bool supportsMRT
10741077
}
10751078

10761079
internal override bool supportsNativeRenderPassRendergraphCompiler => true;
1080+
1081+
static internal bool IsSceneViewOrPreviewLightingActive(UniversalCameraData cameraData)
1082+
{
1083+
DebugHandler debugHandler = ScriptableRenderPass.GetActiveDebugHandler(cameraData);
1084+
var isLightingActive = debugHandler?.IsLightingActive ?? true;
1085+
1086+
#if UNITY_EDITOR
1087+
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
1088+
isLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
1089+
1090+
if (cameraData.isPreviewCamera && cameraData.camera.name == "Preview Scene Camera")
1091+
isLightingActive = false;
1092+
#endif
1093+
1094+
return isLightingActive;
1095+
}
10771096
}
10781097
}

0 commit comments

Comments
 (0)