@@ -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
@@ -400,6 +412,8 @@ internal void PreSetup(UniversalRenderingData renderingData, UniversalCameraData
400412 var viewToClips = new Fixed2 < float4x4 > ( cameraData . GetProjectionMatrix ( 0 ) , cameraData . GetProjectionMatrix ( math . min ( 1 , viewCount - 1 ) ) ) ;
401413
402414 m_CullingHandle = ScheduleClusteringJobs (
415+ lightData . mainLightIndex != - 1 ,
416+ lightData . supportsAdditionalLights ,
403417 lightData . visibleLights ,
404418 renderingData . cullResults . visibleReflectionProbes ,
405419 m_ZBins ,
@@ -656,12 +670,13 @@ void SetupAdditionalLightConstants(UnsafeCommandBuffer cmd, ref CullingResults c
656670 int additionalLightsCount = SetupPerObjectLightIndices ( cullResults , lightData ) ;
657671 if ( additionalLightsCount > 0 )
658672 {
673+ int mainLight = lightData . mainLightIndex ;
659674 if ( m_UseStructuredBuffer )
660675 {
661676 NativeArray < ShaderInput . LightData > additionalLightsData = new NativeArray < ShaderInput . LightData > ( additionalLightsCount , Allocator . Temp ) ;
662677 for ( int i = 0 , lightIter = 0 ; i < lights . Length && lightIter < maxAdditionalLightsCount ; ++ i )
663678 {
664- if ( lightData . mainLightIndex != i )
679+ if ( mainLight != i )
665680 {
666681 ShaderInput . LightData data ;
667682 InitializeLightConstants ( lights , i , supportsLightLayers ,
@@ -688,7 +703,7 @@ void SetupAdditionalLightConstants(UnsafeCommandBuffer cmd, ref CullingResults c
688703 {
689704 for ( int i = 0 , lightIter = 0 ; i < lights . Length && lightIter < maxAdditionalLightsCount ; ++ i )
690705 {
691- if ( lightData . mainLightIndex != i )
706+ if ( mainLight != i )
692707 {
693708 InitializeLightConstants (
694709 lights ,
0 commit comments