Skip to content

Commit c599e4e

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.2] Fixed disable light settings
1 parent 8135052 commit c599e4e

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/ForwardLights.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,18 +1833,6 @@ static UniversalLightData CreateLightData(ContextContainer frameData, UniversalR
18331833
lightData.maxPerObjectAdditionalLightsCount = 0;
18341834
}
18351835

1836-
if (settings.mainLightRenderingMode == LightRenderingMode.Disabled)
1837-
{
1838-
var mainLightIndex = GetBrightestDirectionalLightIndex(settings, visibleLights);
1839-
if (mainLightIndex != -1)
1840-
{
1841-
// a visible main light was disabled, since it is still in the visible lights array we need to maintain
1842-
// the mainLightIndex otherwise indexing in the lightloop goes wrong
1843-
lightData.additionalLightsCount--;
1844-
lightData.mainLightIndex = mainLightIndex;
1845-
}
1846-
}
1847-
18481836
lightData.supportsAdditionalLights = settings.additionalLightsRenderingMode != LightRenderingMode.Disabled;
18491837
lightData.shadeAdditionalLightsPerVertex = settings.additionalLightsRenderingMode == LightRenderingMode.PerVertex;
18501838
lightData.supportsMixedLighting = settings.supportsMixedLighting;

Packages/com.unity.render-pipelines.universal/Tests/Runtime/LightClusteringTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public void LightClustering_WhenLightVolumeIntersectionWithXZPlaneIsOutsideTheSc
6161
float farPlane = 1000f;
6262

6363
JobHandle handle = ForwardLights.ScheduleClusteringJobs(
64+
false,
65+
true,
6466
lights,
6567
probes,
6668
zBins,

0 commit comments

Comments
 (0)