Skip to content

Commit 023f107

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.4] Fixed disable light settings
1 parent 147a298 commit 023f107

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

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

@@ -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,

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

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

1889-
if (settings.mainLightRenderingMode == LightRenderingMode.Disabled)
1890-
{
1891-
var mainLightIndex = GetBrightestDirectionalLightIndex(settings, visibleLights);
1892-
if (mainLightIndex != -1)
1893-
{
1894-
// a visible main light was disabled, since it is still in the visible lights array we need to maintain
1895-
// the mainLightIndex otherwise indexing in the lightloop goes wrong
1896-
lightData.additionalLightsCount--;
1897-
lightData.mainLightIndex = mainLightIndex;
1898-
}
1899-
}
1900-
19011889
lightData.supportsAdditionalLights = settings.additionalLightsRenderingMode != LightRenderingMode.Disabled;
19021890
lightData.shadeAdditionalLightsPerVertex = settings.additionalLightsRenderingMode == LightRenderingMode.PerVertex;
19031891
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)