@@ -321,10 +321,7 @@ internal void SetupLights(CommandBuffer cmd, UniversalCameraData cameraData, Vec
321
321
out m_stencilVisLights ,
322
322
out m_stencilVisLightOffsets ,
323
323
ref lightData . visibleLights ,
324
- lightData . additionalLightsCount != 0 || lightData . mainLightIndex >= 0 ,
325
- cameraData . camera . worldToCameraMatrix ,
326
- cameraData . camera . orthographic ,
327
- cameraData . camera . nearClipPlane
324
+ lightData . additionalLightsCount != 0 || lightData . mainLightIndex >= 0
328
325
) ;
329
326
330
327
{
@@ -727,10 +724,7 @@ void PrecomputeLights(
727
724
out NativeArray < ushort > stencilVisLights ,
728
725
out NativeArray < ushort > stencilVisLightOffsets ,
729
726
ref NativeArray < VisibleLight > visibleLights ,
730
- bool hasAdditionalLights ,
731
- Matrix4x4 view ,
732
- bool isOrthographic ,
733
- float zNear )
727
+ bool hasAdditionalLights )
734
728
{
735
729
const int lightTypeCount = ( int ) LightType . Tube + 1 ;
736
730
@@ -807,21 +801,26 @@ void RenderStencilLights(RasterCommandBuffer cmd, UniversalLightData lightData,
807
801
using ( new ProfilingScope ( cmd , m_ProfilingSamplerDeferredStencilPass ) )
808
802
{
809
803
NativeArray < VisibleLight > visibleLights = lightData . visibleLights ;
804
+ bool hasLightCookieManager = m_LightCookieManager != null ;
805
+ bool hasAdditionalLightPass = m_AdditionalLightsShadowCasterPass != null ;
810
806
811
807
if ( HasStencilLightsOfType ( LightType . Directional ) )
812
- RenderStencilDirectionalLights ( cmd , stripShadowsOffVariants , lightData , shadowData , visibleLights , lightData . mainLightIndex ) ;
808
+ RenderStencilDirectionalLights ( cmd , stripShadowsOffVariants , lightData , shadowData , visibleLights , hasAdditionalLightPass , hasLightCookieManager , lightData . mainLightIndex ) ;
813
809
814
- if ( HasStencilLightsOfType ( LightType . Point ) )
815
- RenderStencilPointLights ( cmd , stripShadowsOffVariants , lightData , shadowData , visibleLights ) ;
810
+ if ( lightData . supportsAdditionalLights )
811
+ {
812
+ if ( HasStencilLightsOfType ( LightType . Point ) )
813
+ RenderStencilPointLights ( cmd , stripShadowsOffVariants , lightData , shadowData , visibleLights , hasAdditionalLightPass , hasLightCookieManager ) ;
816
814
817
- if ( HasStencilLightsOfType ( LightType . Spot ) )
818
- RenderStencilSpotLights ( cmd , stripShadowsOffVariants , lightData , shadowData , visibleLights ) ;
815
+ if ( HasStencilLightsOfType ( LightType . Spot ) )
816
+ RenderStencilSpotLights ( cmd , stripShadowsOffVariants , lightData , shadowData , visibleLights , hasAdditionalLightPass , hasLightCookieManager ) ;
817
+ }
819
818
}
820
819
821
820
Profiler . EndSample ( ) ;
822
821
}
823
822
824
- void RenderStencilDirectionalLights ( RasterCommandBuffer cmd , bool stripShadowsOffVariants , UniversalLightData lightData , UniversalShadowData shadowData , NativeArray < VisibleLight > visibleLights , int mainLightIndex )
823
+ void RenderStencilDirectionalLights ( RasterCommandBuffer cmd , bool stripShadowsOffVariants , UniversalLightData lightData , UniversalShadowData shadowData , NativeArray < VisibleLight > visibleLights , bool hasAdditionalLightPass , bool hasLightCookieManager , int mainLightIndex )
825
824
{
826
825
if ( m_FullscreenMesh == null )
827
826
m_FullscreenMesh = CreateFullscreenMesh ( ) ;
@@ -830,10 +829,8 @@ void RenderStencilDirectionalLights(RasterCommandBuffer cmd, bool stripShadowsOf
830
829
831
830
// TODO bundle extra directional lights rendering by batches of 8.
832
831
// Also separate shadow caster lights from non-shadow caster.
833
- bool isFirstLight = true ;
834
- bool hasLightCookieManager = m_LightCookieManager != null ;
835
- bool hasAdditionalLightPass = m_AdditionalLightsShadowCasterPass != null ;
836
832
int lastLightCookieIndex = - 1 ;
833
+ bool isFirstLight = true ;
837
834
bool lastLightCookieKeywordState = false ;
838
835
bool lastShadowsKeywordState = false ;
839
836
bool lastSoftShadowsKeywordState = false ;
@@ -891,17 +888,15 @@ void RenderStencilDirectionalLights(RasterCommandBuffer cmd, bool stripShadowsOf
891
888
cmd . SetKeyword ( ShaderGlobalKeywords . _DIRECTIONAL , false ) ;
892
889
}
893
890
894
- void RenderStencilPointLights ( RasterCommandBuffer cmd , bool stripShadowsOffVariants , UniversalLightData lightData , UniversalShadowData shadowData , NativeArray < VisibleLight > visibleLights )
891
+ void RenderStencilPointLights ( RasterCommandBuffer cmd , bool stripShadowsOffVariants , UniversalLightData lightData , UniversalShadowData shadowData , NativeArray < VisibleLight > visibleLights , bool hasAdditionalLightPass , bool hasLightCookieManager )
895
892
{
896
893
if ( m_SphereMesh == null )
897
894
m_SphereMesh = CreateSphereMesh ( ) ;
898
895
899
896
cmd . SetKeyword ( ShaderGlobalKeywords . _POINT , true ) ;
900
897
901
- bool isFirstLight = true ;
902
- bool hasLightCookieManager = m_LightCookieManager != null ;
903
- bool hasAdditionalLightPass = m_AdditionalLightsShadowCasterPass != null ;
904
898
int lastLightCookieIndex = - 1 ;
899
+ bool isFirstLight = true ;
905
900
bool lastLightCookieKeywordState = false ;
906
901
bool lastShadowsKeywordState = false ;
907
902
bool lastSoftShadowsKeywordState = false ;
@@ -933,6 +928,7 @@ void RenderStencilPointLights(RasterCommandBuffer cmd, bool stripShadowsOffVaria
933
928
if ( light . bakingOutput . lightmapBakeType == LightmapBakeType . Mixed )
934
929
lightFlags |= ( int ) LightFlag . SubtractiveMixedLighting ;
935
930
931
+ // Determine whether the light is casting shadows and what the index it should use.
936
932
int shadowLightIndex = hasAdditionalLightPass ? m_AdditionalLightsShadowCasterPass . GetShadowLightIndexFromLightIndex ( visLightIndex ) : - 1 ;
937
933
bool hasDeferredShadows = light && light . shadows != LightShadows . None && shadowLightIndex >= 0 ;
938
934
@@ -962,23 +958,22 @@ void RenderStencilPointLights(RasterCommandBuffer cmd, bool stripShadowsOffVaria
962
958
cmd . SetKeyword ( ShaderGlobalKeywords . _POINT , false ) ;
963
959
}
964
960
965
- void RenderStencilSpotLights ( RasterCommandBuffer cmd , bool stripShadowsOffVariants , UniversalLightData lightData , UniversalShadowData shadowData , NativeArray < VisibleLight > visibleLights )
961
+ void RenderStencilSpotLights ( RasterCommandBuffer cmd , bool stripShadowsOffVariants , UniversalLightData lightData , UniversalShadowData shadowData , NativeArray < VisibleLight > visibleLights , bool hasAdditionalLightPass , bool hasLightCookieManager )
966
962
{
967
963
if ( m_HemisphereMesh == null )
968
964
m_HemisphereMesh = CreateHemisphereMesh ( ) ;
969
965
970
966
cmd . SetKeyword ( ShaderGlobalKeywords . _SPOT , true ) ;
971
967
972
- bool isFirstLight = true ;
973
- bool hasLightCookieManager = m_LightCookieManager != null ;
974
- bool hasAdditionalLightPass = m_AdditionalLightsShadowCasterPass != null ;
975
968
int lastLightCookieIndex = - 1 ;
969
+ bool isFirstLight = true ;
976
970
bool lastLightCookieKeywordState = false ;
977
971
bool lastShadowsKeywordState = false ;
978
972
bool lastSoftShadowsKeywordState = false ;
979
973
for ( int soffset = m_stencilVisLightOffsets [ ( int ) LightType . Spot ] ; soffset < m_stencilVisLights . Length ; ++ soffset )
980
974
{
981
975
ushort visLightIndex = m_stencilVisLights [ soffset ] ;
976
+
982
977
ref VisibleLight vl = ref visibleLights . UnsafeElementAtMutable ( visLightIndex ) ;
983
978
if ( vl . lightType != LightType . Spot )
984
979
break ;
@@ -993,8 +988,7 @@ void RenderStencilSpotLights(RasterCommandBuffer cmd, bool stripShadowsOffVarian
993
988
// The tighter the spot shape, the lesser inflation is needed.
994
989
float guard = Mathf . Lerp ( 1.0f , kStencilShapeGuard , sinAlpha ) ;
995
990
996
- Vector4 lightPos , lightColor , lightAttenuation , lightSpotDir , lightOcclusionChannel ;
997
- UniversalRenderPipeline . InitializeLightConstants_Common ( visibleLights , visLightIndex , out lightPos , out lightColor , out lightAttenuation , out lightSpotDir , out lightOcclusionChannel ) ;
991
+ UniversalRenderPipeline . InitializeLightConstants_Common ( visibleLights , visLightIndex , out Vector4 lightPos , out Vector4 lightColor , out Vector4 lightAttenuation , out Vector4 lightSpotDir , out Vector4 lightOcclusionChannel ) ;
998
992
999
993
if ( lightData . supportsLightLayers )
1000
994
SetRenderingLayersMask ( cmd , light , ShaderConstants . _LightLayerMask ) ;
@@ -1003,6 +997,7 @@ void RenderStencilSpotLights(RasterCommandBuffer cmd, bool stripShadowsOffVarian
1003
997
if ( light . bakingOutput . lightmapBakeType == LightmapBakeType . Mixed )
1004
998
lightFlags |= ( int ) LightFlag . SubtractiveMixedLighting ;
1005
999
1000
+ // Determine whether the light is casting shadows and what the index it should use.
1006
1001
int shadowLightIndex = hasAdditionalLightPass ? m_AdditionalLightsShadowCasterPass . GetShadowLightIndexFromLightIndex ( visLightIndex ) : - 1 ;
1007
1002
bool hasDeferredShadows = light && light . shadows != LightShadows . None && shadowLightIndex >= 0 ;
1008
1003
@@ -1032,7 +1027,6 @@ void RenderStencilSpotLights(RasterCommandBuffer cmd, bool stripShadowsOffVarian
1032
1027
1033
1028
isFirstLight = false ;
1034
1029
}
1035
-
1036
1030
cmd . SetKeyword ( ShaderGlobalKeywords . _SPOT , false ) ;
1037
1031
}
1038
1032
0 commit comments