Skip to content

Commit 17c1d46

Browse files
authored
Merge pull request #8041 from Unity-Technologies/internal/master
Internal/master
2 parents f184df7 + 202243c commit 17c1d46

File tree

842 files changed

+263899
-111562
lines changed

Some content is hidden

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

842 files changed

+263899
-111562
lines changed
5.87 KB
Loading
5.98 KB
Loading

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal static class Styles
3535

3636
internal static readonly GUIContent s_Mode = new GUIContent("Mode", "Choose which type of adjustment to apply to probes covered by this volume.");
3737
internal static readonly GUIContent s_DilationThreshold = new GUIContent("Dilation Validity Threshold", "Override the Dilation Validity Threshold for probes covered by this Probe Adjustment Volume. Higher values increase the chance of probes being considered invalid.");
38+
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.");
3839
internal static readonly GUIContent s_VODirection = new GUIContent("Direction", "Rotate the axis along which probes will be pushed when applying Virtual Offset.");
3940
internal static readonly GUIContent s_VODistance = new GUIContent("Distance", "Determines how far probes are pushed in the direction of the Virtual Offset.");
4041
internal static readonly GUIContent s_PreviewLighting = new GUIContent("Preview Probe Adjustments", "Quickly preview the effect of adjustments on probes covered by this volume.");
@@ -175,6 +176,7 @@ public static void DrawAdjustmentContent(SerializedProbeAdjustmentVolume seriali
175176
else if (serialized.mode.intValue == (int)ProbeAdjustmentVolume.Mode.OverrideVirtualOffsetSettings)
176177
{
177178
EditorGUI.BeginDisabledGroup(!useVirtualOffset);
179+
EditorGUILayout.PropertyField(serialized.virtualOffsetThreshold, Styles.virtualOffsetThreshold);
178180
EditorGUILayout.PropertyField(serialized.geometryBias);
179181
EditorGUILayout.PropertyField(serialized.rayOriginBias);
180182
EditorGUI.EndDisabledGroup();

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct ProbeData
2323
public float tMax;
2424
public float geometryBias;
2525
public int probeIndex;
26-
internal float _;
26+
public float validityThreshold;
2727
};
2828

2929
int batchPosIdx;
@@ -35,6 +35,7 @@ struct ProbeData
3535
float scaleForSearchDist;
3636
float rayOriginBias;
3737
float geometryBias;
38+
float validityThreshold;
3839

3940
// Output buffer
4041
public Vector3[] offsets;
@@ -57,6 +58,7 @@ public void Initialize(ProbeVolumeBakingSet bakingSet, NativeList<Vector3> probe
5758
scaleForSearchDist = voSettings.searchMultiplier;
5859
rayOriginBias = voSettings.rayOriginBias;
5960
geometryBias = voSettings.outOfGeoOffset;
61+
validityThreshold = voSettings.validityThreshold;
6062

6163
offsets = new Vector3[probePositions.Length];
6264
cellToVolumes = GetTouchupsPerCell(out bool hasAppliers);
@@ -137,7 +139,6 @@ public bool RunVirtualOffsetStep()
137139
if (currentStep >= stepCount)
138140
return true;
139141

140-
float cellSize = m_ProfileInfo.cellSizeInMeters;
141142
float minBrickSize = m_ProfileInfo.minBrickSize;
142143

143144
// Prepare batch
@@ -149,15 +150,14 @@ public bool RunVirtualOffsetStep()
149150
var searchDistance = (brickSize * minBrickSize) / ProbeBrickPool.kBrickCellCount;
150151
var distanceSearch = scaleForSearchDist * searchDistance;
151152

152-
int cellIndex = PosToIndex(Vector3Int.FloorToInt(positions[batchPosIdx] / cellSize));
153+
int cellIndex = PosToIndex(m_ProfileInfo.PositionToCell(positions[batchPosIdx]));
153154
if (cellToVolumes.TryGetValue(cellIndex, out var volumes))
154155
{
155156
bool adjusted = false;
156157
foreach (var (touchup, obb, center, offset) in volumes.appliers)
157158
{
158159
if (touchup.ContainsPoint(obb, center, positions[batchPosIdx]))
159160
{
160-
positions[batchPosIdx] += offset;
161161
offsets[batchPosIdx] = offset;
162162
adjusted = true;
163163
break;
@@ -173,6 +173,7 @@ public bool RunVirtualOffsetStep()
173173
{
174174
rayOriginBias = touchup.rayOriginBias;
175175
geometryBias = touchup.geometryBias;
176+
validityThreshold = 1.0f - touchup.virtualOffsetThreshold;
176177
break;
177178
}
178179
}
@@ -184,6 +185,7 @@ public bool RunVirtualOffsetStep()
184185
originBias = rayOriginBias,
185186
tMax = distanceSearch,
186187
geometryBias = geometryBias,
188+
validityThreshold = validityThreshold,
187189
probeIndex = batchPosIdx,
188190
};
189191
}
@@ -240,7 +242,7 @@ static internal void RecomputeVOForDebugOnly()
240242
return;
241243

242244
globalBounds = prv.globalBounds;
243-
CellCountInDirections(out minCellPosition, out maxCellPosition, prv.MaxBrickSize());
245+
CellCountInDirections(out minCellPosition, out maxCellPosition, prv.MaxBrickSize(), prv.ProbeOffset());
244246
cellCount = maxCellPosition + Vector3Int.one - minCellPosition;
245247

246248
m_BakingBatch = new BakingBatch(cellCount);
@@ -343,9 +345,7 @@ struct TouchupsPerCell
343345

344346
static Dictionary<int, TouchupsPerCell> GetTouchupsPerCell(out bool hasAppliers)
345347
{
346-
float cellSize = m_ProfileInfo.cellSizeInMeters;
347348
hasAppliers = false;
348-
349349
var adjustmentVolumes = s_AdjustmentVolumes != null ? s_AdjustmentVolumes : GetAdjustementVolumes();
350350

351351
Dictionary<int, TouchupsPerCell> cellToVolumes = new();
@@ -358,8 +358,8 @@ static Dictionary<int, TouchupsPerCell> GetTouchupsPerCell(out bool hasAppliers)
358358

359359
hasAppliers |= mode == ProbeAdjustmentVolume.Mode.ApplyVirtualOffset;
360360

361-
Vector3Int min = Vector3Int.FloorToInt(adjustment.aabb.min / cellSize);
362-
Vector3Int max = Vector3Int.FloorToInt(adjustment.aabb.max / cellSize);
361+
Vector3Int min = m_ProfileInfo.PositionToCell(adjustment.aabb.min);
362+
Vector3Int max = m_ProfileInfo.PositionToCell(adjustment.aabb.max);
363363

364364
for (int x = min.x; x <= max.x; x++)
365365
{
@@ -386,17 +386,15 @@ static Dictionary<int, TouchupsPerCell> GetTouchupsPerCell(out bool hasAppliers)
386386

387387
static Vector3[] DoApplyVirtualOffsetsFromAdjustmentVolumes(NativeList<Vector3> positions, Vector3[] offsets, Dictionary<int, TouchupsPerCell> cellToVolumes)
388388
{
389-
float cellSize = m_ProfileInfo.cellSizeInMeters;
390389
for (int i = 0; i < positions.Length; i++)
391390
{
392-
int cellIndex = PosToIndex(Vector3Int.FloorToInt(positions[i] / cellSize));
391+
int cellIndex = PosToIndex(m_ProfileInfo.PositionToCell(positions[i]));
393392
if (cellToVolumes.TryGetValue(cellIndex, out var volumes))
394393
{
395394
foreach (var (touchup, obb, center, offset) in volumes.appliers)
396395
{
397396
if (touchup.ContainsPoint(obb, center, positions[i]))
398397
{
399-
positions[i] += offset;
400398
offsets[i] = offset;
401399
break;
402400
}

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ class BakingBatch
234234
// Utilities to compute unique probe position hash
235235
Vector3Int maxBrickCount;
236236
float inverseScale;
237+
Vector3 offset;
237238

238239
public Dictionary<(int, int), float> customDilationThresh = new Dictionary<(int, int), float>();
239240
public Dictionary<Vector3, Bounds> forceInvalidatedProbesAndTouchupVols = new Dictionary<Vector3, Bounds>();
@@ -255,11 +256,12 @@ public BakingBatch(Vector3Int cellCount)
255256
{
256257
maxBrickCount = cellCount * ProbeReferenceVolume.CellSize(ProbeReferenceVolume.instance.GetMaxSubdivision());
257258
inverseScale = ProbeBrickPool.kBrickCellCount / ProbeReferenceVolume.instance.MinBrickSize();
259+
offset = ProbeReferenceVolume.instance.ProbeOffset();
258260
}
259261

260262
public int GetProbePositionHash(Vector3 position)
261263
{
262-
var brickPosition = Vector3Int.RoundToInt(position * inverseScale);
264+
var brickPosition = Vector3Int.RoundToInt((position - offset) * inverseScale); // Inverse of op in ConvertBricksToPositions()
263265
return brickPosition.x + brickPosition.y * maxBrickCount.x + brickPosition.z * maxBrickCount.x * maxBrickCount.y;
264266
}
265267

@@ -270,11 +272,14 @@ class ProbeVolumeProfileInfo
270272
{
271273
public int simplificationLevels;
272274
public float minDistanceBetweenProbes;
275+
public Vector3 probeOffset;
273276

274277
public int maxSubdivision => ProbeVolumeBakingSet.GetMaxSubdivision(simplificationLevels);
275278
public float minBrickSize => ProbeVolumeBakingSet.GetMinBrickSize(minDistanceBetweenProbes);
276279
public int cellSizeInBricks => ProbeVolumeBakingSet.GetCellSizeInBricks(simplificationLevels);
277280
public float cellSizeInMeters => (float)cellSizeInBricks * minBrickSize;
281+
282+
public Vector3Int PositionToCell(Vector3 position) => Vector3Int.FloorToInt((position - probeOffset) / cellSizeInMeters);
278283
}
279284

280285
/// <summary>
@@ -712,6 +717,7 @@ static ProbeVolumeProfileInfo GetProfileInfoFromBakingSet(ProbeVolumeBakingSet s
712717
var result = new ProbeVolumeProfileInfo();
713718
result.minDistanceBetweenProbes = set.minDistanceBetweenProbes;
714719
result.simplificationLevels = set.simplificationLevels;
720+
result.probeOffset = set.probeOffset;
715721
return result;
716722
}
717723

@@ -756,7 +762,7 @@ static bool InitializeBake()
756762
}
757763

758764
// Get min/max
759-
CellCountInDirections(out minCellPosition, out maxCellPosition, m_ProfileInfo.cellSizeInMeters);
765+
CellCountInDirections(out minCellPosition, out maxCellPosition, m_ProfileInfo.cellSizeInMeters, m_ProfileInfo.probeOffset);
760766
cellCount = maxCellPosition + Vector3Int.one - minCellPosition;
761767

762768
ProbeReferenceVolume.instance.EnsureCurrentBakingSet(m_BakingSet);
@@ -789,14 +795,13 @@ static void OnBakeStarted()
789795
}
790796
}
791797

792-
static void CellCountInDirections(out Vector3Int minCellPositionXYZ, out Vector3Int maxCellPositionXYZ, float cellSizeInMeters)
798+
static void CellCountInDirections(out Vector3Int minCellPositionXYZ, out Vector3Int maxCellPositionXYZ, float cellSizeInMeters, Vector3 worldOffset)
793799
{
794800
minCellPositionXYZ = Vector3Int.zero;
795801
maxCellPositionXYZ = Vector3Int.zero;
796802

797-
Vector3 center = Vector3.zero;
798-
var centeredMin = globalBounds.min - center;
799-
var centeredMax = globalBounds.max - center;
803+
var centeredMin = globalBounds.min - worldOffset;
804+
var centeredMax = globalBounds.max - worldOffset;
800805

801806
minCellPositionXYZ.x = Mathf.FloorToInt(centeredMin.x / cellSizeInMeters);
802807
minCellPositionXYZ.y = Mathf.FloorToInt(centeredMin.y / cellSizeInMeters);
@@ -1209,7 +1214,7 @@ static void ApplyPostBakeOperations(NativeArray<SphericalHarmonicsL2> sh, Native
12091214

12101215
// Make sure all pending operations are done (needs to be after the Clear to unload all previous scenes)
12111216
probeRefVolume.PerformPendingOperations();
1212-
probeRefVolume.SetMinBrickAndMaxSubdiv(m_ProfileInfo.minBrickSize, m_ProfileInfo.maxSubdivision);
1217+
probeRefVolume.SetSubdivisionDimensions(m_ProfileInfo.minBrickSize, m_ProfileInfo.maxSubdivision, m_ProfileInfo.probeOffset);
12131218

12141219
// Use the globalBounds we just computed, as the one in probeRefVolume doesn't include scenes that have never been baked
12151220
probeRefVolume.globalBounds = globalBounds;
@@ -1702,6 +1707,7 @@ unsafe static void WriteBakingCells(BakingCell[] bakingCells)
17021707
m_BakingSet.cellDescs = new SerializedDictionary<int, CellDesc>();
17031708
m_BakingSet.bakedMinDistanceBetweenProbes = m_ProfileInfo.minDistanceBetweenProbes;
17041709
m_BakingSet.bakedSimplificationLevels = m_ProfileInfo.simplificationLevels;
1710+
m_BakingSet.bakedProbeOffset = m_ProfileInfo.probeOffset;
17051711
m_BakingSet.bakedSkyOcclusion = m_BakingSet.skyOcclusion;
17061712
m_BakingSet.bakedSkyShadingDirection = m_BakingSet.bakedSkyOcclusion && m_BakingSet.skyOcclusionShadingDirection;
17071713

@@ -2133,7 +2139,8 @@ static NativeList<Vector3> RunPlacement(Span<BakeJob> jobs)
21332139
// Overwrite loaded settings with data from profile. Note that the m_BakingSet.profile is already patched up if isFreezingPlacement
21342140
float prevBrickSize = ProbeReferenceVolume.instance.MinBrickSize();
21352141
int prevMaxSubdiv = ProbeReferenceVolume.instance.GetMaxSubdivision();
2136-
ProbeReferenceVolume.instance.SetMinBrickAndMaxSubdiv(m_ProfileInfo.minBrickSize, m_ProfileInfo.maxSubdivision);
2142+
Vector3 prevOffset = ProbeReferenceVolume.instance.ProbeOffset();
2143+
ProbeReferenceVolume.instance.SetSubdivisionDimensions(m_ProfileInfo.minBrickSize, m_ProfileInfo.maxSubdivision, m_ProfileInfo.probeOffset);
21372144

21382145
// All probes need to be baked only once for the whole batch and not once per cell
21392146
// The reason is that the baker is not deterministic so the same probe position baked in two different cells may have different values causing seams artefacts.
@@ -2150,7 +2157,7 @@ static NativeList<Vector3> RunPlacement(Span<BakeJob> jobs)
21502157
positions = ApplySubdivisionResults(result, jobs);
21512158

21522159
// Restore loaded asset settings
2153-
ProbeReferenceVolume.instance.SetMinBrickAndMaxSubdiv(prevBrickSize, prevMaxSubdiv);
2160+
ProbeReferenceVolume.instance.SetSubdivisionDimensions(prevBrickSize, prevMaxSubdiv, prevOffset);
21542161

21552162
return positions;
21562163
}
@@ -2271,6 +2278,7 @@ static void ModifyProfileFromLoadedData(ProbeVolumeBakingSet bakingSet)
22712278
{
22722279
m_ProfileInfo.simplificationLevels = bakingSet.bakedSimplificationLevels;
22732280
m_ProfileInfo.minDistanceBetweenProbes = bakingSet.bakedMinDistanceBetweenProbes;
2281+
m_ProfileInfo.probeOffset = bakingSet.bakedProbeOffset;
22742282
globalBounds = bakingSet.globalBounds;
22752283
}
22762284

@@ -2279,6 +2287,7 @@ internal static void ConvertBricksToPositions(Brick[] bricks, out Vector3[] outP
22792287
{
22802288
int posIdx = 0;
22812289
float scale = ProbeReferenceVolume.instance.MinBrickSize() / ProbeBrickPool.kBrickCellCount;
2290+
Vector3 offset = ProbeReferenceVolume.instance.ProbeOffset();
22822291

22832292
outProbePositions = new Vector3[bricks.Length * ProbeBrickPool.kBrickProbeCountTotal];
22842293
outBrickSubdiv = new int[bricks.Length * ProbeBrickPool.kBrickProbeCountTotal];
@@ -2296,7 +2305,7 @@ internal static void ConvertBricksToPositions(Brick[] bricks, out Vector3[] outP
22962305
{
22972306
var probeOffset = brickOffset + new Vector3Int(x, y, z) * brickSize;
22982307

2299-
outProbePositions[posIdx] = (Vector3)probeOffset * scale;
2308+
outProbePositions[posIdx] = offset + (Vector3)probeOffset * scale;
23002309
outBrickSubdiv[posIdx] = b.subdivisionLevel;
23012310

23022311
posIdx++;

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ static void SubdivideSubCell(Bounds cellAABB, ProbeSubdivisionContext subdivisio
331331
}
332332

333333
float minBrickSize = subdivisionCtx.profile.minBrickSize;
334+
var cellOffset = subdivisionCtx.profile.probeOffset;
334335

335336
var cmd = CommandBufferPool.Get($"Subdivide (Sub)Cell {cellAABB.center}");
336337

@@ -356,7 +357,8 @@ static void SubdivideSubCell(Bounds cellAABB, ProbeSubdivisionContext subdivisio
356357
VoxelizeProbeVolumeData(cmd, cellAABB, probeVolumes, ctx);
357358

358359
// Find the maximum subdivision level we can have in this cell (avoid extra work if not needed)
359-
int startSubdivisionLevel = Mathf.Max(0, ctx.maxSubdivisionLevelInSubCell - GetMaxSubdivision(ctx, probeVolumes.Max(p => p.component.GetMaxSubdivMultiplier())));
360+
int globalMaxSubdiv = ProbeVolumeBakingSet.GetMaxSubdivision(ctx.maxSubdivisionLevel);
361+
int startSubdivisionLevel = Mathf.Max(0, ctx.maxSubdivisionLevelInSubCell - GetMaxSubdivision(ctx, probeVolumes.Max(p => p.component.GetMaxSubdivMultiplier(globalMaxSubdiv))));
360362
for (int subdivisionLevel = startSubdivisionLevel; subdivisionLevel <= ctx.maxSubdivisionLevelInSubCell; subdivisionLevel++)
361363
{
362364
// Add the bricks from the probe volume min subdivision level:
@@ -372,7 +374,7 @@ static void SubdivideSubCell(Bounds cellAABB, ProbeSubdivisionContext subdivisio
372374
}
373375

374376
// Generate the list of bricks on the GPU
375-
SubdivideFromDistanceField(cmd, cellAABB, ctx, probeSubdivisionData, bricksBuffer, brickCountPerAxis, subdivisionLevel, minBrickSize);
377+
SubdivideFromDistanceField(cmd, cellAABB, ctx, probeSubdivisionData, bricksBuffer, brickCountPerAxis, subdivisionLevel, minBrickSize, cellOffset);
376378

377379
cmd.CopyCounterValue(bricksBuffer, brickCountReadbackBuffer, 0);
378380
// Capture locally the subdivision level to use it inside the lambda
@@ -585,8 +587,9 @@ static void VoxelizeProbeVolumeData(CommandBuffer cmd, Bounds cellAABB,
585587
// Prepare list of GPU probe volumes
586588
foreach (var kp in probeVolumes)
587589
{
588-
int minSubdiv = GetMaxSubdivision(ctx, kp.component.GetMinSubdivMultiplier());
589-
int maxSubdiv = GetMaxSubdivision(ctx, kp.component.GetMaxSubdivMultiplier());
590+
int globalMaxSubdiv = ProbeVolumeBakingSet.GetMaxSubdivision(ctx.maxSubdivisionLevel);
591+
int minSubdiv = GetMaxSubdivision(ctx, kp.component.GetMinSubdivMultiplier(globalMaxSubdiv));
592+
int maxSubdiv = GetMaxSubdivision(ctx, kp.component.GetMaxSubdivMultiplier(globalMaxSubdiv));
590593

591594
// Constrain the probe volume AABB inside the cell
592595
var pvAABB = kp.bounds;
@@ -630,13 +633,13 @@ static void VoxelizeProbeVolumeData(CommandBuffer cmd, Bounds cellAABB,
630633

631634
static void SubdivideFromDistanceField(
632635
CommandBuffer cmd, Bounds volume, GPUSubdivisionContext ctx, RenderTexture probeVolumeData,
633-
ComputeBuffer buffer, int brickCount, int subdivisionLevel, float minBrickSize)
636+
ComputeBuffer buffer, int brickCount, int subdivisionLevel, float minBrickSize, Vector3 cellOffset)
634637
{
635638
using (new ProfilingScope(cmd, new ProfilingSampler($"Subdivide Bricks at level {Mathf.Log(brickCount, 3)}")))
636639
{
637640
// We convert the world space volume position (of a corner) in bricks.
638641
// This is necessary to have correct brick position (the position calculated in the compute shader needs to be in number of bricks from the reference volume (origin)).
639-
Vector3 volumeBrickPosition = (volume.center - volume.extents) / minBrickSize;
642+
Vector3 volumeBrickPosition = (volume.center - volume.extents - cellOffset) / minBrickSize;
640643
cmd.SetComputeVectorParam(subdivideSceneCS, _VolumeOffsetInBricks, volumeBrickPosition);
641644
cmd.SetComputeBufferParam(subdivideSceneCS, s_SubdivideKernel, _Bricks, buffer);
642645
cmd.SetComputeVectorParam(subdivideSceneCS, _MaxBrickSize, Vector3.one * brickCount);

0 commit comments

Comments
 (0)