Skip to content

Commit 0368320

Browse files
adrien-de-tocquevilleEvergreen
authored andcommitted
[APV] Bunch of bugfixes
Improve warnings with incorrect setups: - detect when the active scene is not part of any baking set - detect when loaded scenes are part of different baking sets Fix sampling debug mode on URP with render graph due to invalid RG pass setup Fix baking buttons on adjustment volume and probe volumes that could be clicked when baking is in progress ![image](https://media.github.cds.internal.unity3d.com/user/2154/files/f464c4db-6379-4d2c-bc93-b4d105fcdf81) Fix brick placement when using probe offset and max possible probe spacing (reported on arctic demo) Fix cloning of baking sets when opening a new scene in 'Single Scene' mode Fix holes when voxelizing terrains | before | after | | -- | -- | | ![image](https://media.github.cds.internal.unity3d.com/user/2154/files/e970157b-24f3-4f9a-b7be-1db589eead08) | ![image](https://media.github.cds.internal.unity3d.com/user/2154/files/4da5d861-2f64-4348-bac2-0c501e945236) |
1 parent fcf3034 commit 0368320

File tree

12 files changed

+75
-27
lines changed

12 files changed

+75
-27
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,11 @@ static void DrawBakingHelpers(SerializedProbeAdjustmentVolume p, Editor owner)
274274
if (owner.targets.Length == 1)
275275
{
276276
EditorGUILayout.Space();
277-
using (new EditorGUI.DisabledScope(bakingSet == null))
277+
using (new EditorGUI.DisabledScope(Lightmapping.isRunning || bakingSet == null))
278278
{
279-
if (GUILayout.Button(Styles.s_PreviewLighting))
280-
AdaptiveProbeVolumes.BakeAdjustmentVolume(bakingSet, ptv);
279+
using (new EditorGUI.DisabledScope(AdaptiveProbeVolumes.isRunning))
280+
if (GUILayout.Button(Styles.s_PreviewLighting))
281+
AdaptiveProbeVolumes.BakeAdjustmentVolume(bakingSet, ptv);
281282

282283
ProbeVolumeLightingTab.BakeAPVButton();
283284
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ public void Dispose()
172172
static readonly int _NeedDilating = Shader.PropertyToID("_NeedDilating");
173173
static readonly int _DilationParameters = Shader.PropertyToID("_DilationParameters");
174174
static readonly int _OutputProbes = Shader.PropertyToID("_OutputProbes");
175+
176+
// We need to keep the original list of cells that were actually baked to feed it to the dilation process.
177+
// This is because during partial bake we only want to dilate those cells.
178+
static Dictionary<int, BakingCell> m_CellsToDilate = new Dictionary<int, BakingCell>();
179+
static Dictionary<Vector3Int, int> m_CellPosToIndex = new Dictionary<Vector3Int, int>();
180+
181+
// Free up dilation related data
182+
static internal void FinalizeDilation()
183+
{
184+
m_CellPosToIndex.Clear();
185+
m_CellsToDilate.Clear();
186+
}
175187

176188
// Can definitively be optimized later on.
177189
// Also note that all the bookkeeping of all the reference volumes will likely need to change when we move to

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ public override bool Step()
118118
}
119119

120120
// Fixup lighting for probes part of bricks with different subdivision levels
121-
FixSeams(s_BakeData.positionRemap, positions, irradiance, validity);
121+
// When baking reflection probes, we want to skip this step
122+
if (m_BakingBatch != null)
123+
{
124+
FixSeams(s_BakeData.positionRemap, positions, irradiance, validity);
125+
}
122126

123127
return true;
124128
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,7 @@ public void Dispose()
649649
static APVRTContext s_TracingContext;
650650
static BakeData s_BakeData;
651651

652-
static Dictionary<Vector3Int, int> m_CellPosToIndex = new Dictionary<Vector3Int, int>();
653652
static Dictionary<int, BakingCell> m_BakedCells = new Dictionary<int, BakingCell>();
654-
// We need to keep the original list of cells that were actually baked to feed it to the dilation process.
655-
// This is because during partial bake we only want to dilate those cells.
656-
static Dictionary<int, BakingCell> m_CellsToDilate = new Dictionary<int, BakingCell>();
657653

658654
internal static HashSet<string> partialBakeSceneList = null;
659655
internal static bool isBakingSceneSubset => partialBakeSceneList != null;
@@ -779,11 +775,18 @@ static bool SetBakingContext(List<ProbeVolumePerSceneData> perSceneData)
779775
return true;
780776
}
781777

782-
static void EnsurePerSceneDataInOpenScenes()
778+
static bool EnsurePerSceneDataInOpenScenes()
783779
{
784780
var prv = ProbeReferenceVolume.instance;
785781
var activeScene = SceneManager.GetActiveScene();
786782

783+
prv.TryGetBakingSetForLoadedScene(activeScene, out var activeSet);
784+
if (activeSet == null && ProbeVolumeBakingSet.SceneHasProbeVolumes(ProbeReferenceVolume.GetSceneGUID(activeScene)))
785+
{
786+
Debug.LogError($"Active scene at {activeScene.path} is not part of any baking set.");
787+
return false;
788+
}
789+
787790
// We assume that all the per scene data for all the scenes in the set have been set with the scene been saved at least once. However we also update the scenes that are currently loaded anyway for security.
788791
// and to have a new trigger to update the bounds we have.
789792
int openedScenesCount = SceneManager.sceneCount;
@@ -794,12 +797,12 @@ static void EnsurePerSceneDataInOpenScenes()
794797
continue;
795798

796799
ProbeVolumeBakingSet.OnSceneSaving(scene); // We need to perform the same actions we do when the scene is saved.
797-
prv.TryGetBakingSetForLoadedScene(activeScene, out var activeSet); // Must be done after OnSceneSaved because it can put the set in the default baking set if needed.
798800
prv.TryGetBakingSetForLoadedScene(scene, out var sceneBakingSet);
799801

800802
if (sceneBakingSet != null && sceneBakingSet != activeSet && ProbeVolumeBakingSet.SceneHasProbeVolumes(ProbeReferenceVolume.GetSceneGUID(scene)))
801803
{
802804
Debug.LogError($"Scene at {scene.path} is loaded and has probe volumes, but not part of the same baking set as the active scene. This will result in an error. Please make sure all loaded scenes are part of the same baking sets.");
805+
return false;
803806
}
804807
}
805808

@@ -811,6 +814,8 @@ static void EnsurePerSceneDataInOpenScenes()
811814
if (!ProbeVolumeBakingSet.SceneHasProbeVolumes(perSceneData.sceneGUID))
812815
CoreUtils.Destroy(perSceneData.gameObject);
813816
}
817+
818+
return true;
814819
}
815820

816821
static void CachePVHashes(List<ProbeVolume> probeVolumes)
@@ -878,8 +883,8 @@ enum BakingStep
878883
VirtualOffset,
879884
LaunchThread,
880885
SkyOcclusion,
881-
Integration,
882886
RenderingLayerMask,
887+
Integration,
883888
FinalizeCells,
884889

885890
Last = FinalizeCells + 1
@@ -940,7 +945,10 @@ static bool InitializeBake()
940945
if (!isFreezingPlacement)
941946
{
942947
using (new BakingSetupProfiling(BakingSetupProfiling.Stages.EnsurePerSceneDataInOpenScenes))
943-
EnsurePerSceneDataInOpenScenes();
948+
{
949+
if (!EnsurePerSceneDataInOpenScenes())
950+
return false;
951+
}
944952
}
945953

946954
if (ProbeReferenceVolume.instance.perSceneDataList.Count == 0) return false;
@@ -1391,6 +1399,9 @@ static void ApplyPostBakeOperations()
13911399
probeVolume.OnBakeCompleted();
13921400
foreach (var adjustment in s_AdjustmentVolumes)
13931401
adjustment.volume.cachedHashCode = adjustment.volume.GetHashCode();
1402+
1403+
// We allocate data even if dilation is off, that should be changed
1404+
FinalizeDilation();
13941405
}
13951406

13961407

@@ -1435,7 +1446,7 @@ public static bool BakeAsync()
14351446
}
14361447

14371448
/// <summary>
1438-
/// Returns true when the bake job is running, false otherwise (Read Only).
1449+
/// Returns true when the async baking of adaptive probe volumes only is running, false otherwise (Read Only).
14391450
/// </summary>
14401451
public static bool isRunning => s_AsyncBakeTaskID != -1;
14411452

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public static Brick[] SubdivideCell(Vector3Int cellPosition, Bounds cellBounds,
247247
{
248248
float brickSize = ProbeReferenceVolume.instance.BrickSize(brick.subdivisionLevel);
249249
Bounds brickBounds = new Bounds();
250-
brickBounds.min = (Vector3)brick.position * ProbeReferenceVolume.instance.MinBrickSize();
250+
brickBounds.min = subdivisionCtx.profile.probeOffset + (Vector3)brick.position * ProbeReferenceVolume.instance.MinBrickSize();
251251
brickBounds.max = brickBounds.min + new Vector3(brickSize, brickSize, brickSize);
252252

253253
// If any volume that overlaps this brick wants this subdiv level, we keep it

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void Drawer_VolumeContent(SerializedProbeVolume serialized, Editor owner)
157157
}
158158

159159
EditorGUILayout.Space();
160-
using (new EditorGUI.DisabledScope(bakingSet == null))
160+
using (new EditorGUI.DisabledScope(Lightmapping.isRunning || bakingSet == null))
161161
{
162162
ProbeVolumeLightingTab.BakeAPVButton();
163163
}

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/VoxelizeScene.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ TerrainVertexToFragment TerrainVert(uint vertexID : SV_VERTEXID, uint instanceID
152152
float4 vertex = GetQuadVertexPosition(vertexID % 4);
153153
uint2 heightmapLoadPosition = quadPos + vertex.xy;
154154

155+
float scale = _TerrainSize.xz / _TerrainHeightmapResolution;
156+
vertex.xy = heightmapLoadPosition * scale;
157+
155158
// flip quad to xz axis (default terrain orientation without rotation)
156159
vertex = float4(vertex.x, 0, vertex.y, 1);
157160

158-
// Offset quad to create the plane terrain
159-
vertex.xz += (float2(quadPos) / float(_TerrainHeightmapResolution)) * _TerrainSize.xz;
160-
161161
uint2 id = (quadPos / _TerrainSize.xz) * _TerrainHeightmapResolution;
162162
float height = UnpackHeightmap(_TerrainHeightmapTexture.Load(uint3(heightmapLoadPosition, 0)));
163163
vertex.y += height * _TerrainSize.y * 2;

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,27 @@ public bool RemoveScenario(string name)
171171

172172
internal ProbeVolumeBakingSet Clone()
173173
{
174-
var newSet = Instantiate(this);
175-
newSet.m_SceneGUIDs.Clear();
176-
newSet.m_SceneBakeData.Clear();
174+
var newSet = CreateInstance<ProbeVolumeBakingSet>();
175+
176+
// We don't want to clone everything in the set
177+
// Especially don't copy reference to baked data !
178+
newSet.probeOffset = probeOffset;
179+
newSet.simplificationLevels = simplificationLevels;
180+
newSet.minDistanceBetweenProbes = minDistanceBetweenProbes;
181+
newSet.renderersLayerMask = renderersLayerMask;
182+
newSet.minRendererVolumeSize = minRendererVolumeSize;
183+
newSet.skyOcclusion = skyOcclusion;
184+
newSet.skyOcclusionBakingSamples = skyOcclusionBakingSamples;
185+
newSet.skyOcclusionBakingBounces = skyOcclusionBakingBounces;
186+
newSet.skyOcclusionAverageAlbedo = skyOcclusionAverageAlbedo;
187+
newSet.skyOcclusionBackFaceCulling = skyOcclusionBackFaceCulling;
188+
newSet.skyOcclusionShadingDirection = skyOcclusionShadingDirection;
189+
newSet.useRenderingLayers = useRenderingLayers;
190+
newSet.renderingLayerMasks = renderingLayerMasks != null ? (ProbeLayerMask[])renderingLayerMasks.Clone() : null;
191+
newSet.useRenderingLayers = useRenderingLayers;
192+
newSet.useRenderingLayers = useRenderingLayers;
193+
newSet.useRenderingLayers = useRenderingLayers;
194+
newSet.useRenderingLayers = useRenderingLayers;
177195
return newSet;
178196
}
179197

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolumeConstantRuntimeResources.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static Vector3[] GenerateSkyDirections()
8989
#endregion
9090

9191
#region AntiLeak Buffer generator
92-
#if UNITY_EDITOR
92+
#if UNITY_EDITOR
9393
static uint3 GetSampleOffset(uint i)
9494
{
9595
return new uint3(i, i >> 1, i >> 2) & 1;
@@ -252,7 +252,7 @@ static uint ComputeAntiLeakData(uint validityMask)
252252
return mask;
253253
}
254254

255-
[UnityEditor.MenuItem("Edit/Rendering/Global Illumination/Generate AntiLeak Buffer")]
255+
//[UnityEditor.MenuItem("Edit/Rendering/Global Illumination/Generate AntiLeak Buffer")]
256256
static uint[] BuildAntiLeakDataArray()
257257
{
258258
uint[] antileak = new uint[256];

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ void WriteApvPositionNormalDebugBuffer(RenderGraph renderGraph, GraphicsBuffer r
14461446
{
14471447
using (var builder = renderGraph.AddRenderPass<WriteApvData>("APV Debug Sampling", out var passData, ProfilingSampler.Get(HDProfileId.APVSamplingDebug)))
14481448
{
1449-
passData.resultBuffer = renderGraph.ImportBuffer(resultBuffer);
1449+
passData.resultBuffer = builder.WriteBuffer(renderGraph.ImportBuffer(resultBuffer));
14501450
passData.clickCoordinates = clickCoordinates;
14511451
passData.depthBuffer = builder.ReadTexture(depthBuffer);
14521452
passData.normalBuffer = builder.ReadTexture(normalBuffer);

0 commit comments

Comments
 (0)