@@ -186,6 +186,8 @@ out float4 viewToViewportScaleBias
186186 /// but also in unit testing.
187187 /// </summary>
188188 internal static JobHandle ScheduleClusteringJobs (
189+ bool hasMainLight ,
190+ bool supportsAdditionalLights ,
189191 NativeArray < VisibleLight > lights ,
190192 NativeArray < VisibleReflectionProbe > probes ,
191193 NativeArray < uint > zBins ,
@@ -207,7 +209,7 @@ internal static JobHandle ScheduleClusteringJobs(
207209 out int wordsPerTile
208210 )
209211 {
210- localLightCount = lights . Length ;
212+ localLightCount = supportsAdditionalLights ? lights . Length : 0 ;
211213 // The lights array first has directional lights, and then local lights. We traverse the list to find the
212214 // index of the first local light.
213215 var firstLocalLightIdx = 0 ;
@@ -217,8 +219,18 @@ out int wordsPerTile
217219 }
218220 localLightCount -= firstLocalLightIdx ;
219221
220- // If there's 1 or more directional lights, one of them must be the main light
221- directionalLightCount = firstLocalLightIdx > 0 ? firstLocalLightIdx - 1 : 0 ;
222+ // If there's 1 or more directional lights, one of them could be the main light
223+ if ( firstLocalLightIdx > 0 )
224+ {
225+
226+ directionalLightCount = firstLocalLightIdx ;
227+ if ( hasMainLight )
228+ directionalLightCount -= 1 ;
229+ }
230+ else
231+ {
232+ directionalLightCount = 0 ;
233+ }
222234
223235 var localLights = lights . GetSubArray ( firstLocalLightIdx , localLightCount ) ;
224236
@@ -404,6 +416,8 @@ internal void PreSetup(UniversalRenderingData renderingData, UniversalCameraData
404416 var viewToClips = new Fixed2 < float4x4 > ( cameraData . GetProjectionMatrix ( 0 ) , cameraData . GetProjectionMatrix ( math . min ( 1 , viewCount - 1 ) ) ) ;
405417
406418 m_CullingHandle = ScheduleClusteringJobs (
419+ lightData . mainLightIndex != - 1 ,
420+ lightData . supportsAdditionalLights ,
407421 lightData . visibleLights ,
408422 renderingData . cullResults . visibleReflectionProbes ,
409423 m_ZBins ,
@@ -649,12 +663,13 @@ void SetupAdditionalLightConstants(UnsafeCommandBuffer cmd, ref CullingResults c
649663 int additionalLightsCount = SetupPerObjectLightIndices ( cullResults , lightData ) ;
650664 if ( additionalLightsCount > 0 )
651665 {
666+ int mainLight = lightData . mainLightIndex ;
652667 if ( m_UseStructuredBuffer )
653668 {
654669 NativeArray < ShaderInput . LightData > additionalLightsData = new NativeArray < ShaderInput . LightData > ( additionalLightsCount , Allocator . Temp ) ;
655670 for ( int i = 0 , lightIter = 0 ; i < lights . Length && lightIter < maxAdditionalLightsCount ; ++ i )
656671 {
657- if ( lightData . mainLightIndex != i )
672+ if ( mainLight != i )
658673 {
659674 ShaderInput . LightData data ;
660675 InitializeLightConstants ( lights , i , supportsLightLayers ,
@@ -681,7 +696,7 @@ void SetupAdditionalLightConstants(UnsafeCommandBuffer cmd, ref CullingResults c
681696 {
682697 for ( int i = 0 , lightIter = 0 ; i < lights . Length && lightIter < maxAdditionalLightsCount ; ++ i )
683698 {
684- if ( lightData . mainLightIndex != i )
699+ if ( mainLight != i )
685700 {
686701 InitializeLightConstants (
687702 lights ,
0 commit comments