Skip to content

Commit 1c9ae84

Browse files
kennytannEvergreen
authored andcommitted
[Port] [6000.4] [UUM-139229][URP 2D] Fix preview camera missing lighting and shadows
1 parent 0ea8b7b commit 1c9ae84

2 files changed

Lines changed: 15 additions & 25 deletions

File tree

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,16 @@ internal void Render(RenderGraph graph, ContextContainer frameData, int batchInd
176176
var layerBatch = frameData.Get<Universal2DRenderingData>().layerBatches[batchIndex];
177177

178178
DebugHandler debugHandler = GetActiveDebugHandler(cameraData);
179-
var isDebugLightingActive = debugHandler?.IsLightingActive ?? true;
179+
var isLightingActive = debugHandler?.IsLightingActive ?? true;
180180

181181
#if UNITY_EDITOR
182182
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
183-
isDebugLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
184-
185-
if (cameraData.camera.cameraType == CameraType.Preview)
186-
isDebugLightingActive = false;
183+
isLightingActive &= UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
187184
#endif
188185

189186
if (!layerBatch.lightStats.useLights ||
190187
isVolumetric && !layerBatch.lightStats.useVolumetricLights ||
191-
!isDebugLightingActive)
188+
!isLightingActive)
192189
return;
193190

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

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static void Execute(RasterGraphContext context, PassData passData)
3131
RendererLighting.SetLightShaderGlobals(cmd, passData.lightBlendStyles, passData.blendStyleIndices);
3232

3333
#if UNITY_EDITOR
34-
if (passData.isLitView)
34+
if (passData.isLightingActive)
3535
#endif
3636
{
3737
if (passData.layerUseLights)
@@ -79,7 +79,7 @@ class PassData
7979
internal bool activeDebugHandler;
8080

8181
#if UNITY_EDITOR
82-
internal bool isLitView; // Required for prefab view and preview camera
82+
internal bool isLightingActive; // Required for prefab view and preview camera
8383
#endif
8484
}
8585

@@ -93,35 +93,28 @@ public void Render(RenderGraph graph, ContextContainer frameData, int batchIndex
9393
Renderer2DData rendererData = frameData.Get<Universal2DRenderingData>().renderingData;
9494
var layerBatch = frameData.Get<Universal2DRenderingData>().layerBatches[batchIndex];
9595

96-
bool isLitView = true;
96+
DebugHandler debugHandler = GetActiveDebugHandler(cameraData);
97+
var isLightingActive = debugHandler?.IsLightingActive ?? true;
9798

9899
#if UNITY_EDITOR
99100
// Early out for prefabs
100101
if (cameraData.isSceneViewCamera && UnityEditor.SceneView.currentDrawingSceneView != null)
101-
isLitView = UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
102-
103-
// Early out for preview camera
104-
if (cameraData.cameraType == CameraType.Preview)
105-
isLitView = false;
106-
107-
DebugHandler debugHandler = GetActiveDebugHandler(cameraData);
108-
if (debugHandler != null)
109-
isLitView = debugHandler.IsLightingActive;
102+
isLightingActive = UnityEditor.SceneView.currentDrawingSceneView.sceneLighting;
110103
#endif
111104

112105
// Preset global light textures for first batch
113106
if (batchIndex == 0)
114107
{
115108
using (var builder = graph.AddRasterRenderPass<SetGlobalPassData>(k_SetLightBlendTexture, out var passData, m_SetLightBlendTextureProfilingSampler))
116109
{
117-
if (layerBatch.lightStats.useLights && isLitView)
110+
if (layerBatch.lightStats.useLights && isLightingActive)
118111
{
119112
passData.lightTextures = universal2DResourceData.lightTextures[batchIndex];
120113
for (var i = 0; i < passData.lightTextures.Length; i++)
121114
builder.UseTexture(passData.lightTextures[i]);
122115
}
123116

124-
SetGlobalLightTextures(graph, builder, frameData, batchIndex, isLitView);
117+
SetGlobalLightTextures(graph, builder, frameData, batchIndex, isLightingActive);
125118

126119
builder.AllowGlobalStateModification(true);
127120

@@ -143,7 +136,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, int batchIndex
143136
passData.isSceneLit = rendererData.lightCullResult.IsSceneLit();
144137
passData.layerUseLights = layerBatch.lightStats.useLights;
145138
#if UNITY_EDITOR
146-
passData.isLitView = isLitView;
139+
passData.isLightingActive = isLightingActive;
147140
#endif
148141

149142
var drawSettings = CreateDrawingSettings(k_ShaderTags, renderingData, cameraData, lightData, SortingCriteria.CommonTransparent);
@@ -168,7 +161,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, int batchIndex
168161
builder.UseRendererList(passData.rendererList);
169162
}
170163

171-
if (passData.layerUseLights && isLitView)
164+
if (passData.layerUseLights && isLightingActive)
172165
{
173166
passData.lightTextures = universal2DResourceData.lightTextures[batchIndex];
174167
for (var i = 0; i < passData.lightTextures.Length; i++)
@@ -189,7 +182,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, int batchIndex
189182
// Post set global light textures for next renderer pass
190183
var nextBatch = batchIndex + 1;
191184
if (nextBatch < universal2DResourceData.lightTextures.Length)
192-
SetGlobalLightTextures(graph, builder, frameData, nextBatch, isLitView);
185+
SetGlobalLightTextures(graph, builder, frameData, nextBatch, isLightingActive);
193186

194187
builder.SetRenderFunc(static (PassData data, RasterGraphContext context) =>
195188
{
@@ -198,13 +191,13 @@ public void Render(RenderGraph graph, ContextContainer frameData, int batchIndex
198191
}
199192
}
200193

201-
void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, ContextContainer frameData, int batchIndex, bool isLitView)
194+
void SetGlobalLightTextures(RenderGraph graph, IRasterRenderGraphBuilder builder, ContextContainer frameData, int batchIndex, bool isLightingActive)
202195
{
203196
Renderer2DData rendererData = frameData.Get<Universal2DRenderingData>().renderingData;
204197
var layerBatch = frameData.Get<Universal2DRenderingData>().layerBatches[batchIndex];
205198
var lightTextures = frameData.Get<Universal2DResourceData>().lightTextures[batchIndex];
206199

207-
if (isLitView)
200+
if (isLightingActive)
208201
{
209202
if (layerBatch.lightStats.useLights)
210203
{

0 commit comments

Comments
 (0)