Skip to content

Commit c8df1d8

Browse files
authored
Merge pull request #8065 from Unity-Technologies/internal/master
Internal/master
2 parents 83af90b + cbb944d commit c8df1d8

File tree

444 files changed

+68959
-2183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

444 files changed

+68959
-2183
lines changed

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeAdjustmentVolumeEditor.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ internal static class Styles
3838
internal static readonly GUIContent virtualOffsetThreshold = new GUIContent("Validity Threshold", "Override the Virtual Offset Validity Threshold for probes covered by this Probe Adjustment Volume. Higher values increase the chance of probes being considered invalid.");
3939
internal static readonly GUIContent s_VODirection = new GUIContent("Direction", "Rotate the axis along which probes will be pushed when applying Virtual Offset.");
4040
internal static readonly GUIContent s_VODistance = new GUIContent("Distance", "Determines how far probes are pushed in the direction of the Virtual Offset.");
41+
internal static readonly GUIContent renderingLayerMaskOperation = new GUIContent("Operation", "The operation to combine the Rendering Layer Mask set by this adjustment volume with the Rendering Layer Mask of the probes covered by this volume.");
42+
internal static readonly GUIContent renderingLayerMask = new GUIContent("Rendering Layer Mask", "Sets the Rendering Layer Mask to be combined with the Rendering Layer Mask of the probes covered by this volume.");
4143
internal static readonly GUIContent s_PreviewLighting = new GUIContent("Preview Probe Adjustments", "Quickly preview the effect of adjustments on probes covered by this volume.");
4244

4345
internal static readonly GUIContent skyOcclusionSampleCount = new GUIContent("Sample Count", "Controls the number of samples per probe for sky occlusion baking.");
@@ -248,6 +250,39 @@ public static void DrawAdjustmentContent(SerializedProbeAdjustmentVolume seriali
248250
});
249251
}
250252
}
253+
else if (serialized.mode.intValue == (int)ProbeAdjustmentVolume.Mode.OverrideRenderingLayerMask)
254+
{
255+
if (bakingSet != null && !bakingSet.useRenderingLayers)
256+
{
257+
CoreEditorUtils.DrawFixMeBox("Override Rendering Layer can be used only if Rendering Layers are enabled for the Baking Set.", MessageType.Warning, "Open", () =>
258+
{
259+
ProbeVolumeLightingTab.OpenBakingSet(bakingSet);
260+
});
261+
}
262+
else
263+
{
264+
EditorGUILayout.PropertyField(serialized.renderingLayerMaskOperation, Styles.renderingLayerMaskOperation);
265+
266+
string[] options;
267+
if (bakingSet != null)
268+
{
269+
options = new string[bakingSet.renderingLayerMasks.Length];
270+
for (int i = 0; i < bakingSet.renderingLayerMasks.Length; i++)
271+
options[i] = bakingSet.renderingLayerMasks[i].name;
272+
}
273+
else
274+
{
275+
options = new string[APVDefinitions.probeMaxRegionCount];
276+
for (int i = 0; i < APVDefinitions.probeMaxRegionCount; i++)
277+
options[i] = "Mask " + (i + 1);
278+
}
279+
280+
EditorGUI.BeginChangeCheck();
281+
int newMask = EditorGUILayout.MaskField(Styles.renderingLayerMask, serialized.renderingLayerMask.intValue, options);
282+
if (EditorGUI.EndChangeCheck())
283+
serialized.renderingLayerMask.uintValue = (uint)newMask;
284+
}
285+
}
251286
}
252287

253288
static void DrawBakingHelpers(SerializedProbeAdjustmentVolume p, Editor owner)

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.Dilate.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ static void PerformDilation(ProbeReferenceVolume.Cell cell, ProbeVolumeBakingSet
336336
parameters.reflNormalizationUpperClamp = 1.0f;
337337
parameters.skyOcclusionIntensity = 0.0f;
338338
parameters.skyOcclusionShadingDirection = false;
339+
parameters.regionCount = 1;
340+
parameters.regionLayerMasks = 1;
339341
ProbeReferenceVolume.instance.UpdateConstantBuffer(cmd, parameters);
340342

341343

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.Invalidation.cs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace UnityEngine.Rendering
77
partial class AdaptiveProbeVolumes
88
{
99
// We use this scratch memory as a way of spoofing the texture.
10-
static DynamicArray<float> s_Validity_locData = new DynamicArray<float>();
10+
static DynamicArray<(float, byte)> s_ValidityLayer_locData = new DynamicArray<(float, byte)>();
1111
static DynamicArray<int> s_ProbeIndices = new DynamicArray<int>();
1212

1313
internal static Vector3Int GetSampleOffset(int i)
@@ -17,28 +17,39 @@ internal static Vector3Int GetSampleOffset(int i)
1717

1818
const float k_MinValidityForLeaking = 0.05f;
1919

20-
internal static int PackValidity(float[] validity)
20+
internal static uint PackValidity(float[] validity)
2121
{
22-
int outputByte = 0;
22+
uint outputByte = 0;
2323
for (int i = 0; i < 8; ++i)
2424
{
25-
int val = (validity[i] > k_MinValidityForLeaking) ? 0 : 1;
25+
uint val = (validity[i] > k_MinValidityForLeaking) ? 0u : 1u;
2626
outputByte |= (val << i);
2727
}
2828
return outputByte;
2929
}
3030

31-
static void StoreScratchData(int x, int y, int z, int dataWidth, int dataHeight, float value, int probeIndex)
31+
internal static uint PackLayer(byte[] layers, int layer)
32+
{
33+
uint outputLayer = 0;
34+
for (int i = 0; i < 8; ++i)
35+
{
36+
if ((layers[i] & (byte)(1 << layer)) != 0)
37+
outputLayer |= (1u << i);
38+
}
39+
return outputLayer;
40+
}
41+
42+
static void StoreScratchData(int x, int y, int z, int dataWidth, int dataHeight, float value, byte layer, int probeIndex)
3243
{
3344
int index = x + dataWidth * (y + dataHeight * z);
34-
s_Validity_locData[index] = value;
45+
s_ValidityLayer_locData[index] = (value, layer);
3546
s_ProbeIndices[index] = probeIndex;
3647
}
3748

38-
static float ReadValidity(int x, int y, int z, int dataWidth, int dataHeight)
49+
static (float, byte) ReadValidity(int x, int y, int z, int dataWidth, int dataHeight)
3950
{
4051
int index = x + dataWidth * (y + dataHeight * z);
41-
return s_Validity_locData[index];
52+
return s_ValidityLayer_locData[index];
4253
}
4354

4455
static int ReadProbeIndex(int x, int y, int z, int dataWidth, int dataHeight)
@@ -74,6 +85,7 @@ static void ComputeValidityMasks(in BakingCell cell)
7485
var bricks = cell.bricks;
7586
int chunkSize = ProbeBrickPool.GetChunkSizeInBrickCount();
7687
int brickChunksCount = (bricks.Length + chunkSize - 1) / chunkSize;
88+
int validityLayerCount = cell.layerValidity != null ? cell.validityNeighbourMask.GetLength(0) : 1;
7789

7890
var probeHasEmptySpaceInGrid = new NativeArray<bool>(cell.probePositions.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
7991

@@ -85,7 +97,7 @@ static void ComputeValidityMasks(in BakingCell cell)
8597
int count = ProbeBrickPool.GetChunkSizeInProbeCount();
8698
int bx = 0, by = 0, bz = 0;
8799

88-
s_Validity_locData.Resize(size);
100+
s_ValidityLayer_locData.Resize(size);
89101
s_ProbeIndices.Resize(size);
90102

91103
HashSet<Vector3Int> probesToRestore = new HashSet<Vector3Int>();
@@ -104,11 +116,12 @@ static void ComputeValidityMasks(in BakingCell cell)
104116

105117
if (shidx >= cell.validity.Length)
106118
{
107-
StoreScratchData(ix, iy, iz, locSize.x, locSize.y, 1.0f, shidx);
119+
StoreScratchData(ix, iy, iz, locSize.x, locSize.y, 1.0f, 0, shidx);
108120
}
109121
else
110122
{
111-
StoreScratchData(ix, iy, iz, locSize.x, locSize.y, cell.validity[shidx], shidx);
123+
byte layer = validityLayerCount > 1 ? cell.layerValidity[shidx] : (byte)0xFF;
124+
StoreScratchData(ix, iy, iz, locSize.x, locSize.y, cell.validity[shidx], layer, shidx);
112125

113126
// Check if we need to do some extra check on this probe.
114127
bool hasFreeNeighbourhood = false;
@@ -150,11 +163,11 @@ static void ComputeValidityMasks(in BakingCell cell)
150163
for (int z = 0; z < locSize.z; ++z)
151164
{
152165
int outIdx = ReadProbeIndex(x, y, z, locSize.x, locSize.y);
153-
float probeValidity = ReadValidity(x, y, z, locSize.x, locSize.y);
154166

155167
if (outIdx < cell.validity.Length)
156168
{
157169
float[] validities = new float[8];
170+
byte[] layers = new byte[8];
158171
bool forceAllValid = false;
159172
for (int o = 0; o < 8; ++o)
160173
{
@@ -171,14 +184,20 @@ static void ComputeValidityMasks(in BakingCell cell)
171184
}
172185
}
173186

174-
validities[o] = ReadValidity(samplePos.x, samplePos.y, samplePos.z, locSize.x, locSize.y);
187+
(validities[o], layers[o]) = ReadValidity(samplePos.x, samplePos.y, samplePos.z, locSize.x, locSize.y);
175188
}
176189

177-
byte mask = forceAllValid ? (byte)255 : Convert.ToByte(PackValidity(validities));
178-
float validity = probeValidity;
190+
// Keeping for safety but i think this is useless
191+
(float probeValidity, uint _) = ReadValidity(x, y, z, locSize.x, locSize.y);
192+
cell.validity[outIdx] = probeValidity;
179193

180-
cell.validity[outIdx] = validity;
181-
cell.validityNeighbourMask[outIdx] = mask;
194+
// Pack validity with layer mask
195+
uint mask = forceAllValid ? 255 : PackValidity(validities);
196+
for (int l = 0; l < validityLayerCount; l++)
197+
{
198+
uint layer = validityLayerCount == 1 ? 0xFF : PackLayer(layers, l);
199+
cell.validityNeighbourMask[l, outIdx] = Convert.ToByte(mask & layer);
200+
}
182201
}
183202
}
184203
}

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.LightTransport.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ struct APVRTContext
484484

485485
static IRayTracingShader m_ShaderVO = null;
486486
static IRayTracingShader m_ShaderSO = null;
487+
static IRayTracingShader m_ShaderRL = null;
487488

488489
internal IRayTracingAccelStruct CreateAccelerationStructure()
489490
{
@@ -550,6 +551,25 @@ public IRayTracingShader shaderSO
550551
}
551552
}
552553

554+
public IRayTracingShader shaderRL
555+
{
556+
get
557+
{
558+
if (m_ShaderRL == null)
559+
{
560+
var bakingResources = GraphicsSettings.GetRenderPipelineSettings<ProbeVolumeBakingResources>();
561+
m_ShaderRL = m_Context.CreateRayTracingShader(m_Backend switch
562+
{
563+
RayTracingBackend.Hardware => bakingResources.renderingLayerRT,
564+
RayTracingBackend.Compute => bakingResources.renderingLayerCS,
565+
_ => null
566+
});
567+
}
568+
569+
return m_ShaderRL;
570+
}
571+
}
572+
553573
public void BindSamplingTextures(CommandBuffer cmd)
554574
{
555575
if (m_SamplingResources == null)
@@ -561,6 +581,26 @@ public void BindSamplingTextures(CommandBuffer cmd)
561581
SamplingResources.BindSamplingTextures(cmd, m_SamplingResources);
562582
}
563583

584+
public bool TryGetMeshForAccelerationStructure(Renderer renderer, out Mesh mesh)
585+
{
586+
mesh = null;
587+
if (renderer.isPartOfStaticBatch)
588+
{
589+
Debug.LogError("Static batching is not supported when baking APV.");
590+
return false;
591+
}
592+
593+
mesh = renderer.GetComponent<MeshFilter>().sharedMesh;
594+
if (mesh == null)
595+
return false;
596+
597+
// This would error out later in LoadIndexBuffer in LightTransport package
598+
if ((mesh.indexBufferTarget & GraphicsBuffer.Target.Raw) == 0 && (mesh.GetIndices(0) == null || mesh.GetIndices(0).Length == 0))
599+
return false;
600+
601+
return true;
602+
}
603+
564604
public void Dispose()
565605
{
566606
if (m_Context != null)
@@ -626,13 +666,15 @@ internal static void BakeAdjustmentVolume(ProbeVolumeBakingSet bakingSet, ProbeA
626666
bool savedSkyOcclusion = bakingSet.skyOcclusion;
627667
bool savedSkyDirection = bakingSet.skyOcclusionShadingDirection;
628668
bool savedVirtualOffset = bakingSet.settings.virtualOffsetSettings.useVirtualOffset;
669+
bool savedRenderingLayers = bakingSet.useRenderingLayers;
629670
{
630671
// Patch baking set as we are not gonna use a mix of baked values and new values
631672
bakingSet.simplificationLevels = bakingSet.bakedSimplificationLevels;
632673
bakingSet.minDistanceBetweenProbes = bakingSet.bakedMinDistanceBetweenProbes;
633674
bakingSet.skyOcclusion = bakingSet.bakedSkyOcclusion;
634675
bakingSet.skyOcclusionShadingDirection = bakingSet.bakedSkyShadingDirection;
635676
bakingSet.settings.virtualOffsetSettings.useVirtualOffset = bakingSet.supportOffsetsChunkSize != 0;
677+
bakingSet.useRenderingLayers = bakingSet.bakedMaskCount == 1 ? false : true;
636678

637679
m_BakingSet = bakingSet;
638680
m_BakingBatch = new BakingBatch(cellCount);
@@ -746,19 +788,27 @@ internal static void BakeAdjustmentVolume(ProbeVolumeBakingSet bakingSet, ProbeA
746788
while (!failed && lightingJob.currentStep < lightingJob.stepCount)
747789
failed |= !lightingJob.Step();
748790

791+
// Bake rendering layers
792+
var layerMaskJob = renderingLayerOverride ?? new DefaultRenderingLayer();
793+
layerMaskJob.Initialize(bakingSet, uniquePositions.AsArray());
794+
while (!failed && layerMaskJob.currentStep < layerMaskJob.stepCount)
795+
failed |= !layerMaskJob.Step();
796+
749797
// Upload new data in cells
750798
foreach ((int uniqueProbeIndex, int cellIndex, int i) in bakedProbes)
751799
{
752800
ref var cell = ref bakingCells[cellIndex];
753801
cell.SetBakedData(m_BakingSet, m_BakingBatch, cellVolumes[cellIndex], i, uniqueProbeIndex,
754802
lightingJob.irradiance[uniqueProbeIndex], lightingJob.validity[uniqueProbeIndex],
755-
virtualOffsetJob.offsets, skyOcclusionJob.occlusion, skyOcclusionJob.encodedDirections);
803+
layerMaskJob.renderingLayerMasks, virtualOffsetJob.offsets,
804+
skyOcclusionJob.occlusion, skyOcclusionJob.encodedDirections);
756805
}
757806

758807
skyOcclusionJob.encodedDirections.Dispose();
759808
virtualOffsetJob.Dispose();
760809
skyOcclusionJob.Dispose();
761810
lightingJob.Dispose();
811+
layerMaskJob.Dispose();
762812

763813
if (!failed)
764814
{
@@ -800,6 +850,7 @@ internal static void BakeAdjustmentVolume(ProbeVolumeBakingSet bakingSet, ProbeA
800850
bakingSet.skyOcclusion = savedSkyOcclusion;
801851
bakingSet.skyOcclusionShadingDirection = savedSkyDirection;
802852
bakingSet.settings.virtualOffsetSettings.useVirtualOffset = savedVirtualOffset;
853+
bakingSet.useRenderingLayers = savedRenderingLayers;
803854

804855
m_BakingBatch = null;
805856
m_BakingSet = null;

0 commit comments

Comments
 (0)