Skip to content

Commit 1ae844e

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[URP][Unity 6.0] Minor code cleanup of MainLightShadowCasterPass (UUM-85883)
Fixes [UUM-85883](https://jira.unity3d.com/browse/UUM-85883). Also does some minor code cleanup of variables used for main light shadows.
1 parent dbdda9d commit 1ae844e

1 file changed

Lines changed: 40 additions & 54 deletions

File tree

Packages/com.unity.render-pipelines.universal/Runtime/Passes/MainLightShadowCasterPass.cs

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,50 @@ namespace UnityEngine.Rendering.Universal.Internal
1010
/// </summary>
1111
public class MainLightShadowCasterPass : ScriptableRenderPass
1212
{
13-
private static class MainLightShadowConstantBuffer
14-
{
15-
public static int _WorldToShadow;
16-
public static int _ShadowParams;
17-
public static int _CascadeShadowSplitSpheres0;
18-
public static int _CascadeShadowSplitSpheres1;
19-
public static int _CascadeShadowSplitSpheres2;
20-
public static int _CascadeShadowSplitSpheres3;
21-
public static int _CascadeShadowSplitSphereRadii;
22-
public static int _ShadowOffset0;
23-
public static int _ShadowOffset1;
24-
public static int _ShadowmapSize;
25-
}
26-
27-
const int k_MaxCascades = 4;
28-
const int k_ShadowmapBufferBits = 16;
29-
float m_CascadeBorder;
30-
float m_MaxShadowDistanceSq;
31-
int m_ShadowCasterCascadesCount;
32-
33-
int m_MainLightShadowmapID;
13+
// Internal
3414
internal RTHandle m_MainLightShadowmapTexture;
15+
16+
// Private
17+
private int renderTargetWidth;
18+
private int renderTargetHeight;
19+
private int m_ShadowCasterCascadesCount;
20+
private bool m_CreateEmptyShadowmap;
21+
private bool m_EmptyShadowmapNeedsClear = false;
22+
private float m_CascadeBorder;
23+
private float m_MaxShadowDistanceSq;
24+
private PassData m_PassData;
3525
private RTHandle m_EmptyMainLightShadowmapTexture;
26+
private Vector4[] m_CascadeSplitDistances;
27+
private Matrix4x4[] m_MainLightShadowMatrices;
28+
private ProfilingSampler m_ProfilingSetupSampler = new ("Setup Main Shadowmap");
29+
private ShadowSliceData[] m_CascadeSlices;
30+
private RenderTextureDescriptor m_MainLightShadowDescriptor;
31+
32+
// Constants and Statics
3633
private const int k_EmptyShadowMapDimensions = 1;
34+
private const int k_MaxCascades = 4;
35+
private const int k_ShadowmapBufferBits = 16;
3736
private const string k_MainLightShadowMapTextureName = "_MainLightShadowmapTexture";
3837
private const string k_EmptyMainLightShadowMapTextureName = "_EmptyMainLightShadowmapTexture";
39-
private static readonly Vector4 s_EmptyShadowParams = new Vector4(1, 0, 1, 0);
40-
private static readonly Vector4 s_EmptyShadowmapSize = s_EmptyShadowmapSize = new Vector4(k_EmptyShadowMapDimensions, 1f / k_EmptyShadowMapDimensions, k_EmptyShadowMapDimensions, k_EmptyShadowMapDimensions);
38+
private static readonly Vector4 s_EmptyShadowParams = new (1, 0, 1, 0);
39+
private static readonly Vector4 s_EmptyShadowmapSize = new (k_EmptyShadowMapDimensions, 1f / k_EmptyShadowMapDimensions, k_EmptyShadowMapDimensions, k_EmptyShadowMapDimensions);
4140

42-
Matrix4x4[] m_MainLightShadowMatrices;
43-
ShadowSliceData[] m_CascadeSlices;
44-
Vector4[] m_CascadeSplitDistances;
45-
46-
private RenderTextureDescriptor m_MainLightShadowDescriptor;
47-
48-
bool m_CreateEmptyShadowmap;
49-
bool m_EmptyShadowmapNeedsClear = false;
50-
51-
int renderTargetWidth;
52-
int renderTargetHeight;
41+
// Classes
42+
private static class MainLightShadowConstantBuffer
43+
{
44+
public static readonly int _WorldToShadow = Shader.PropertyToID("_MainLightWorldToShadow");
45+
public static readonly int _ShadowParams = Shader.PropertyToID("_MainLightShadowParams");
46+
public static readonly int _CascadeShadowSplitSpheres0 = Shader.PropertyToID("_CascadeShadowSplitSpheres0");
47+
public static readonly int _CascadeShadowSplitSpheres1 = Shader.PropertyToID("_CascadeShadowSplitSpheres1");
48+
public static readonly int _CascadeShadowSplitSpheres2 = Shader.PropertyToID("_CascadeShadowSplitSpheres2");
49+
public static readonly int _CascadeShadowSplitSpheres3 = Shader.PropertyToID("_CascadeShadowSplitSpheres3");
50+
public static readonly int _CascadeShadowSplitSphereRadii = Shader.PropertyToID("_CascadeShadowSplitSphereRadii");
51+
public static readonly int _ShadowOffset0 = Shader.PropertyToID("_MainLightShadowOffset0");
52+
public static readonly int _ShadowOffset1 = Shader.PropertyToID("_MainLightShadowOffset1");
53+
public static readonly int _ShadowmapSize = Shader.PropertyToID("_MainLightShadowmapSize");
54+
public static readonly int _MainLightShadowmapID = Shader.PropertyToID(k_MainLightShadowMapTextureName);
55+
}
5356

54-
ProfilingSampler m_ProfilingSetupSampler = new ProfilingSampler("Setup Main Shadowmap");
55-
private PassData m_PassData;
5657
/// <summary>
5758
/// Creates a new <c>MainLightShadowCasterPass</c> instance.
5859
/// </summary>
@@ -68,18 +69,6 @@ public MainLightShadowCasterPass(RenderPassEvent evt)
6869
m_CascadeSlices = new ShadowSliceData[k_MaxCascades];
6970
m_CascadeSplitDistances = new Vector4[k_MaxCascades];
7071

71-
MainLightShadowConstantBuffer._WorldToShadow = Shader.PropertyToID("_MainLightWorldToShadow");
72-
MainLightShadowConstantBuffer._ShadowParams = Shader.PropertyToID("_MainLightShadowParams");
73-
MainLightShadowConstantBuffer._CascadeShadowSplitSpheres0 = Shader.PropertyToID("_CascadeShadowSplitSpheres0");
74-
MainLightShadowConstantBuffer._CascadeShadowSplitSpheres1 = Shader.PropertyToID("_CascadeShadowSplitSpheres1");
75-
MainLightShadowConstantBuffer._CascadeShadowSplitSpheres2 = Shader.PropertyToID("_CascadeShadowSplitSpheres2");
76-
MainLightShadowConstantBuffer._CascadeShadowSplitSpheres3 = Shader.PropertyToID("_CascadeShadowSplitSpheres3");
77-
MainLightShadowConstantBuffer._CascadeShadowSplitSphereRadii = Shader.PropertyToID("_CascadeShadowSplitSphereRadii");
78-
MainLightShadowConstantBuffer._ShadowOffset0 = Shader.PropertyToID("_MainLightShadowOffset0");
79-
MainLightShadowConstantBuffer._ShadowOffset1 = Shader.PropertyToID("_MainLightShadowOffset1");
80-
MainLightShadowConstantBuffer._ShadowmapSize = Shader.PropertyToID("_MainLightShadowmapSize");
81-
82-
m_MainLightShadowmapID = Shader.PropertyToID(k_MainLightShadowMapTextureName);
8372
m_EmptyShadowmapNeedsClear = true;
8473
}
8574

@@ -248,15 +237,15 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
248237
if (m_CreateEmptyShadowmap)
249238
{
250239
SetEmptyMainLightCascadeShadowmap(CommandBufferHelpers.GetRasterCommandBuffer(universalRenderingData.commandBuffer));
251-
universalRenderingData.commandBuffer.SetGlobalTexture(m_MainLightShadowmapID, m_EmptyMainLightShadowmapTexture.nameID);
240+
universalRenderingData.commandBuffer.SetGlobalTexture(MainLightShadowConstantBuffer._MainLightShadowmapID, m_EmptyMainLightShadowmapTexture.nameID);
252241
return;
253242
}
254243

255244
InitPassData(ref m_PassData, universalRenderingData, cameraData, lightData, shadowData);
256245
InitRendererLists(ref m_PassData, context, default(RenderGraph), false);
257246

258247
RenderMainLightCascadeShadowmap(CommandBufferHelpers.GetRasterCommandBuffer(universalRenderingData.commandBuffer), ref m_PassData, false);
259-
universalRenderingData.commandBuffer.SetGlobalTexture(m_MainLightShadowmapID, m_MainLightShadowmapTexture.nameID);
248+
universalRenderingData.commandBuffer.SetGlobalTexture(MainLightShadowConstantBuffer._MainLightShadowmapID, m_MainLightShadowmapTexture.nameID);
260249
}
261250

262251
void Clear()
@@ -396,7 +385,6 @@ private class PassData
396385
internal MainLightShadowCasterPass pass;
397386

398387
internal TextureHandle shadowmapTexture;
399-
internal int shadowmapID;
400388
internal bool emptyShadowmap;
401389

402390
internal RendererListHandle[] shadowRendererListsHandle = new RendererListHandle[k_MaxCascades];
@@ -413,7 +401,6 @@ private void InitPassData(
413401
passData.pass = this;
414402

415403
passData.emptyShadowmap = m_CreateEmptyShadowmap;
416-
passData.shadowmapID = m_MainLightShadowmapID;
417404
passData.renderingData = renderingData;
418405
passData.cameraData = cameraData;
419406
passData.lightData = lightData;
@@ -430,7 +417,6 @@ void InitEmptyPassData(
430417
passData.pass = this;
431418

432419
passData.emptyShadowmap = m_CreateEmptyShadowmap;
433-
passData.shadowmapID = m_MainLightShadowmapID;
434420
passData.renderingData = renderingData;
435421
passData.cameraData = cameraData;
436422
passData.lightData = lightData;
@@ -488,7 +474,7 @@ internal TextureHandle Render(RenderGraph graph, ContextContainer frameData)
488474
builder.AllowGlobalStateModification(true);
489475

490476
if (shadowTexture.IsValid())
491-
builder.SetGlobalTextureAfterPass(shadowTexture, m_MainLightShadowmapID);
477+
builder.SetGlobalTextureAfterPass(shadowTexture, MainLightShadowConstantBuffer._MainLightShadowmapID);
492478

493479
builder.SetRenderFunc((PassData data, RasterGraphContext context) =>
494480
{

0 commit comments

Comments
 (0)