@@ -34,7 +34,13 @@ private static class AdditionalShadowsConstantBuffer
34
34
const int k_ShadowmapBufferBits = 16 ;
35
35
private int m_AdditionalLightsShadowmapID ;
36
36
internal RTHandle m_AdditionalLightsShadowmapHandle ;
37
- internal RTHandle m_EmptyAdditionalLightShadowmapTexture ;
37
+
38
+ private bool m_CreateEmptyShadowmap ;
39
+ private bool m_EmptyShadowmapNeedsClear = false ;
40
+ private RTHandle m_EmptyAdditionalLightShadowmapTexture ;
41
+ private const int k_EmptyShadowMapDimensions = 1 ;
42
+ private const string k_EmptyShadowMapName = "_EmptyAdditionalLightShadowmapTexture" ;
43
+ internal static Vector4 [ ] s_EmptyAdditionalLightIndexToShadowParams = null ;
38
44
39
45
float m_MaxShadowDistanceSq ;
40
46
float m_CascadeBorder ;
@@ -49,9 +55,6 @@ private static class AdditionalShadowsConstantBuffer
49
55
Vector4 [ ] m_AdditionalLightIndexToShadowParams = null ; // per-additional-light shadow info passed to the lighting shader (x: shadowStrength, y: softShadows, z: light type, w: perLightFirstShadowSliceIndex)
50
56
Matrix4x4 [ ] m_AdditionalLightShadowSliceIndexTo_WorldShadowMatrix = null ; // per-shadow-slice info passed to the lighting shader
51
57
52
- bool m_CreateEmptyShadowmap ;
53
- bool m_EmptyShadowmapNeedsClear = false ;
54
-
55
58
int renderTargetWidth ;
56
59
int renderTargetHeight ;
57
60
@@ -95,13 +98,17 @@ public AdditionalLightsShadowCasterPass(RenderPassEvent evt)
95
98
m_VisibleLightIndexToAdditionalLightIndex = new int [ maxVisibleLights ] ;
96
99
m_AdditionalLightIndexToShadowParams = new Vector4 [ maxAdditionalLightShadowParams ] ;
97
100
101
+ s_EmptyAdditionalLightIndexToShadowParams = new Vector4 [ maxAdditionalLightShadowParams ] ;
102
+ for ( int i = 0 ; i < s_EmptyAdditionalLightIndexToShadowParams . Length ; i ++ )
103
+ s_EmptyAdditionalLightIndexToShadowParams [ i ] = c_DefaultShadowParams ;
104
+
98
105
if ( ! m_UseStructuredBuffer )
99
106
{
100
107
// Uniform buffers are faster on some platforms, but they have stricter size limitations
101
108
m_AdditionalLightShadowSliceIndexTo_WorldShadowMatrix = new Matrix4x4 [ maxVisibleAdditionalLights ] ;
102
109
}
103
110
104
- m_EmptyAdditionalLightShadowmapTexture = ShadowUtils . AllocShadowRT ( 1 , 1 , k_ShadowmapBufferBits , 1 , 0 , name : "_EmptyAdditionalLightShadowmapTexture" ) ;
111
+ m_EmptyAdditionalLightShadowmapTexture = ShadowUtils . AllocShadowRT ( k_EmptyShadowMapDimensions , k_EmptyShadowMapDimensions , k_ShadowmapBufferBits , 1 , 0 , name : k_EmptyShadowMapName ) ;
105
112
m_EmptyShadowmapNeedsClear = true ;
106
113
}
107
114
@@ -601,7 +608,7 @@ bool SetupForEmptyRendering(bool stripShadowsOffVariants, UniversalShadowData sh
601
608
useNativeRenderPass = false ;
602
609
603
610
// Required for scene view camera(URP renderer not initialized)
604
- if ( ShadowUtils . ShadowRTReAllocateIfNeeded ( ref m_EmptyAdditionalLightShadowmapTexture , 1 , 1 , k_ShadowmapBufferBits , name : "_EmptyAdditionalLightShadowmapTexture" ) )
611
+ if ( ShadowUtils . ShadowRTReAllocateIfNeeded ( ref m_EmptyAdditionalLightShadowmapTexture , k_EmptyShadowMapDimensions , k_EmptyShadowMapDimensions , k_ShadowmapBufferBits , name : k_EmptyShadowMapName ) )
605
612
m_EmptyShadowmapNeedsClear = true ;
606
613
607
614
// initialize _AdditionalShadowParams
@@ -678,17 +685,21 @@ void Clear()
678
685
679
686
void SetEmptyAdditionalShadowmapAtlas ( RasterCommandBuffer cmd )
680
687
{
681
- cmd . SetKeyword ( ShaderGlobalKeywords . AdditionalLightShadows , true ) ;
688
+ cmd . EnableKeyword ( ShaderGlobalKeywords . AdditionalLightShadows ) ;
689
+ SetEmptyAdditionalLightShadowParams ( cmd , m_AdditionalLightIndexToShadowParams ) ;
690
+ }
682
691
692
+ internal static void SetEmptyAdditionalLightShadowParams ( RasterCommandBuffer cmd , Vector4 [ ] lightIndexToShadowParams )
693
+ {
683
694
if ( RenderingUtils . useStructuredBuffer )
684
695
{
685
- var shadowParamsBuffer = ShaderData . instance . GetAdditionalLightShadowParamsStructuredBuffer ( m_AdditionalLightIndexToShadowParams . Length ) ;
686
- shadowParamsBuffer . SetData ( m_AdditionalLightIndexToShadowParams ) ;
696
+ ComputeBuffer shadowParamsBuffer = ShaderData . instance . GetAdditionalLightShadowParamsStructuredBuffer ( lightIndexToShadowParams . Length ) ;
697
+ shadowParamsBuffer . SetData ( lightIndexToShadowParams ) ;
687
698
cmd . SetGlobalBuffer ( m_AdditionalShadowParams_SSBO , shadowParamsBuffer ) ;
688
699
}
689
700
else
690
701
{
691
- cmd . SetGlobalVectorArray ( AdditionalShadowsConstantBuffer . _AdditionalShadowParams , m_AdditionalLightIndexToShadowParams ) ;
702
+ cmd . SetGlobalVectorArray ( AdditionalShadowsConstantBuffer . _AdditionalShadowParams , lightIndexToShadowParams ) ;
692
703
}
693
704
}
694
705
0 commit comments