Skip to content

Commit

Permalink
[APV] Fix baking when there is no geometry in the scene
Browse files Browse the repository at this point in the history
When forcing the minimal baking possible by ebaling force and having no geometry in the scene, a nullref was generated.
  • Loading branch information
adrien-de-tocqueville authored and Evergreen committed May 23, 2024
1 parent ebfd28f commit 7df3d9e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ internal void Cleanup()

internal static void Initialize()
{
if (!SystemInfo.supportsComputeShaders)
return;

s_DataUploadCS = GraphicsSettings.GetRenderPipelineSettings<ProbeVolumeRuntimeResources>()?.probeVolumeUploadDataCS;
s_DataUploadL2CS = GraphicsSettings.GetRenderPipelineSettings<ProbeVolumeRuntimeResources>()?.probeVolumeUploadDataL2CS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ static internal int MaxSubdivLevelInProbeVolume(Vector3 volumeSize, int maxSubdi
{
float maxSizedDim = Mathf.Max(volumeSize.x, Mathf.Max(volumeSize.y, volumeSize.z));
float maxSideInBricks = maxSizedDim / ProbeReferenceVolume.instance.MinDistanceBetweenProbes();
int subdiv = Mathf.FloorToInt(Mathf.Log(maxSideInBricks, 3));
int subdiv = Mathf.FloorToInt(Mathf.Log(maxSideInBricks, 3)) - 1;

return Mathf.Max(subdiv, maxSubdiv) - 1;
return Mathf.Max(subdiv, maxSubdiv);
}

static void InflateBound(ref Bounds bounds, ProbeVolume pv)
Expand All @@ -446,7 +446,7 @@ static void InflateBound(ref Bounds bounds, ProbeVolume pv)
maxPadding = cellSizeVector - new Vector3(Mathf.Abs(maxPadding.x), Mathf.Abs(maxPadding.y), Mathf.Abs(maxPadding.z));

// Find the size of the brick we can put for every axis given the padding size
int maxSubdiv = ProbeReferenceVolume.instance.GetMaxSubdivision();
int maxSubdiv = ProbeReferenceVolume.instance.GetMaxSubdivision() - 1;
if (pv.overridesSubdivLevels) maxSubdiv = Mathf.Min(pv.highestSubdivLevelOverride, maxSubdiv);

float rightPaddingSubdivLevel = ProbeReferenceVolume.instance.BrickSize(MaxSubdivLevelInProbeVolume(new Vector3(maxPadding.x, originalBounds.size.y, originalBounds.size.z), maxSubdiv));
Expand Down Expand Up @@ -554,7 +554,7 @@ internal SceneBakeData GetSceneBakeData(string sceneGUID)
internal static bool SceneHasProbeVolumes(string sceneGUID)
{
var bakingSet = GetBakingSetForScene(sceneGUID);
return bakingSet.GetSceneBakeData(sceneGUID)?.hasProbeVolume ?? false;
return bakingSet?.GetSceneBakeData(sceneGUID)?.hasProbeVolume ?? false;
}

internal bool DialogNoProbeVolumeInSetShown()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch webgpu
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch webgpu gles3
//#pragma enable_d3d11_debug_symbols

#pragma kernel BlendScenarios
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch webgpu
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch webgpu gles3
//#pragma enable_d3d11_debug_symbols

#include "Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolumeUploadDataCommon.hlsl"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch webgpu
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch webgpu gles3
//#pragma enable_d3d11_debug_symbols

#include "Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeVolumeUploadDataCommon.hlsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void REPROJECT_CLOUDS(uint3 dispatchThreadId : SV_DispatchThreadID,
{
finalColor = previousColor;
finalCloudDepth = previousCloudDepth;
finalSampleCount = validityFactor * previousSampleCount * _CloudHistoryInvalidation;
finalSampleCount = max(1, validityFactor * previousSampleCount * _CloudHistoryInvalidation);
}
}
else if (!validTracing)
Expand Down

0 comments on commit 7df3d9e

Please sign in to comment.