Skip to content

Commit 676f90a

Browse files
erickssonEvergreen
authored andcommitted
Revert "[APV] Fix leak reduction mode in complex cases"
1 parent 8bf8bb3 commit 676f90a

24 files changed

+446
-639
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal void FromSphericalHarmonicsShaderConstants(ProbeReferenceVolume.Cell ce
8787
if (cellChunkData.skyShadingDirectionIndices.Length != 0)
8888
{
8989
int id = cellChunkData.skyShadingDirectionIndices[index];
90-
var directions = ProbeVolumeConstantRuntimeResources.GetSkySamplingDirections();
90+
var directions = DynamicSkyPrecomputedDirections.GetPrecomputedDirections();
9191
SO_Direction = id == 255 ? Vector3.zero : directions[id];
9292
}
9393
}
@@ -171,6 +171,7 @@ public void Dispose()
171171
static readonly int _ProbePositionsBuffer = Shader.PropertyToID("_ProbePositionsBuffer");
172172
static readonly int _NeedDilating = Shader.PropertyToID("_NeedDilating");
173173
static readonly int _DilationParameters = Shader.PropertyToID("_DilationParameters");
174+
static readonly int _DilationParameters2 = Shader.PropertyToID("_DilationParameters2");
174175
static readonly int _OutputProbes = Shader.PropertyToID("_OutputProbes");
175176

176177
// Can definitively be optimized later on.
@@ -295,7 +296,8 @@ static void PerformDilation(ProbeReferenceVolume.Cell cell, ProbeVolumeBakingSet
295296
// There's an upper limit on the number of bricks supported inside a single cell
296297
int probeCount = Mathf.Min(cell.data.probePositions.Length, ushort.MaxValue * ProbeBrickPool.kBrickProbeCountTotal);
297298

298-
cmd.SetComputeVectorParam(dilationShader, _DilationParameters, new Vector4(probeCount, settings.dilationValidityThreshold, settings.dilationDistance, settings.squaredDistWeighting ? 1 : 0));
299+
cmd.SetComputeVectorParam(dilationShader, _DilationParameters, new Vector4(probeCount, settings.dilationValidityThreshold, settings.dilationDistance, ProbeReferenceVolume.instance.MinBrickSize()));
300+
cmd.SetComputeVectorParam(dilationShader, _DilationParameters2, new Vector4(settings.squaredDistWeighting ? 1 : 0, bakingSet.skyOcclusion ? 1 : 0, bakingSet.skyOcclusionShadingDirection ? 1 : 0, 0));
299301

300302
var refVolume = ProbeReferenceVolume.instance;
301303
ProbeReferenceVolume.RuntimeResources rr = refVolume.GetRuntimeResources();
@@ -328,11 +330,12 @@ static void PerformDilation(ProbeReferenceVolume.Cell cell, ProbeVolumeBakingSet
328330
parameters.samplingNoise = 0;
329331
parameters.weight = 1f;
330332
parameters.leakReductionMode = APVLeakReductionMode.None;
333+
parameters.minValidNormalWeight = 0.0f;
331334
parameters.frameIndexForNoise = 0;
332335
parameters.reflNormalizationLowerClamp = 0.1f;
333336
parameters.reflNormalizationUpperClamp = 1.0f;
334-
parameters.skyOcclusionIntensity = bakingSet.skyOcclusion ? 1 : 0;
335-
parameters.skyOcclusionShadingDirection = bakingSet.skyOcclusionShadingDirection ? true : false;
337+
parameters.skyOcclusionIntensity = 0.0f;
338+
parameters.skyOcclusionShadingDirection = false;
336339
parameters.regionCount = 1;
337340
parameters.regionLayerMasks = 1;
338341
ProbeReferenceVolume.instance.UpdateConstantBuffer(cmd, parameters);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ static void AnalyzeBrickForIndirectionEntries(ref BakingCell cell)
326326
cell.indirectionEntryInfo[i].positionInBricks = cellPosInBricks + new Vector3Int(x, y, z) * indirectionEntrySizeInBricks;
327327
cell.indirectionEntryInfo[i].hasOnlyBiggerBricks = minSubdiv > entrySubdivLevel && touchedBrick;
328328

329-
prv.ComputeEntryMinMax(ref cell.indirectionEntryInfo[i], cell.bricks);
330-
int brickCount = ProbeReferenceVolume.GetNumberOfBricksAtSubdiv(cell.indirectionEntryInfo[i]);
329+
ProbeBrickIndex.IndirectionEntryUpdateInfo unused = new ProbeBrickIndex.IndirectionEntryUpdateInfo();
330+
int brickCount = ProbeReferenceVolume.instance.GetNumberOfBricksAtSubdiv(cell.indirectionEntryInfo[i], ref unused);
331331

332332
totalIndexChunks += Mathf.CeilToInt((float)brickCount / ProbeBrickIndex.kIndexChunkSize);
333333

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ internal static NativeArray<uint> EncodeShadingDirection(NativeArray<Vector3> di
5555
var cs = GraphicsSettings.GetRenderPipelineSettings<ProbeVolumeBakingResources>().skyOcclusionCS;
5656
int kernel = cs.FindKernel("EncodeShadingDirection");
5757

58-
ProbeVolumeConstantRuntimeResources.Initialize();
58+
DynamicSkyPrecomputedDirections.Initialize();
5959
var precomputedShadingDirections = ProbeReferenceVolume.instance.GetRuntimeResources().SkyPrecomputedDirections;
6060

6161
int probeCount = directions.Length;
@@ -93,7 +93,7 @@ internal static NativeArray<uint> EncodeShadingDirection(NativeArray<Vector3> di
9393

9494
internal static uint EncodeSkyShadingDirection(Vector3 direction)
9595
{
96-
var precomputedDirections = ProbeVolumeConstantRuntimeResources.GetSkySamplingDirections();
96+
var precomputedDirections = DynamicSkyPrecomputedDirections.GetPrecomputedDirections();
9797

9898
uint indexMax = 255;
9999
float bestDot = -10.0f;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static class Styles
8888
// Probe Invalidity section
8989
public static readonly GUIContent resetDilation = new GUIContent("Reset Dilation Settings");
9090
public static readonly GUIContent resetVirtualOffset = new GUIContent("Reset Virtual Offset Settings");
91-
public static readonly GUIContent renderingLayerMasks = new GUIContent("Rendering Layer Masks", "When enabled, geometry in a Rendering Layer will only receive lighting from probes which see Rendering Layers in the same Rendering Layer Mask. This can be used to prevent leaking across boundaries.\nGeometry not belonging to a Rendering Layer Mask will continue to sample all probes. Requires Leak Reduction Mode to be enabled.");
91+
public static readonly GUIContent renderingLayerMasks = new GUIContent("Rendering Layer Masks", "When enabled, geometry in a Rendering Layer will only receive lighting from probes which see Rendering Layers in the same Rendering Layer Mask. This can be used to prevent leaking across boundaries.\nGeometry not belonging to a Rendering Layer Mask will continue to sample all probes.");
9292
public static readonly string maskTooltip = "The Rendering Layers for this mask.";
9393
}
9494

Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeVolumeCellDilation.compute

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ CBUFFER_END
1818
#define _ProbeCount (uint)_DilationParameters.x
1919
#define _ValidityThreshold _DilationParameters.y
2020
#define _SearchRadius _DilationParameters.z
21-
#define _SquaredDistanceWeight (_DilationParameters.w > 0)
21+
#define _MinBrickSizeForDilation _DilationParameters.w
22+
23+
#define _SquaredDistanceWeight (_DilationParameters2.x > 0)
24+
#define _EnableSkyOcclusion (_DilationParameters2.y > 0)
25+
#define _EnableSkyDirection (_DilationParameters2.z > 0)
2226

2327
StructuredBuffer<int> _NeedDilating;
2428
StructuredBuffer<float3> _ProbePositionsBuffer;
@@ -56,17 +60,17 @@ void AddProbeSample(APVResources apvRes, float3 uvw, inout DilatedProbe probe, f
5660
}
5761

5862
// Sky occlusion data
59-
if (_APVSkyOcclusionWeight > 0)
63+
if (_EnableSkyOcclusion)
6064
{
6165
float4 SO_L0L1 = SAMPLE_TEXTURE3D_LOD(apvRes.SkyOcclusionL0L1, s_linear_clamp_sampler, uvw, 0).rgba * weight;
6266

6367
if (SO_L0L1.x >= 0.0001f)
6468
{
6569
probe.SO_L0L1 += SO_L0L1 * weight;
6670

67-
if (_APVSkyDirectionWeight > 0)
71+
if (_EnableSkyDirection)
6872
{
69-
int3 texCoord = uvw * _APVPoolDim - 0.5f; // No interpolation for sky shading indices
73+
int3 texCoord = uvw * _PoolDim - 0.5f; // No interpolation for sky shading indices
7074
uint index = LOAD_TEXTURE3D(apvRes.SkyShadingDirectionIndices, texCoord).x * 255.0;
7175

7276
probe.SO_Direction = index == 255 ? float3(0, 0, 0) : apvRes.SkyPrecomputedDirections[index].rgb * weight;
@@ -99,18 +103,18 @@ void DilateCell(uint3 id : SV_DispatchThreadID)
99103

100104
if (_NeedDilating[probeIdx] > 0)
101105
{
102-
float3 centralPosition = _ProbePositionsBuffer[probeIdx] - _APVWorldOffset;
106+
float3 centralPosition = _ProbePositionsBuffer[probeIdx] - _WorldOffset;
103107
DilatedProbe probe = (DilatedProbe)0;
104108

105109
float3 uvw;
106110
uint subdiv;
107111
float shWeight = 0, soWeight = 0;
108-
float3 uvwDelta = rcp(_APVPoolDim);
112+
float3 uvwDelta = rcp(_PoolDim);
109113

110114
float3 biasedPosWS;
111115
if (TryToGetPoolUVWAndSubdiv(FillAPVResources(), centralPosition, 0, 0, uvw, subdiv, biasedPosWS))
112116
{
113-
float stepSize = _APVMinBrickSize / 3.0f;
117+
float stepSize = _MinBrickSizeForDilation / 3.0f;
114118

115119
// Inflate search radius a bit.
116120
float radius = 1.5f * _SearchRadius;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sealed class ProbeVolumesOptionsEditor : VolumeComponentEditor
1010
SerializedDataParameter m_ScaleBiasMinProbeDistance;
1111
SerializedDataParameter m_SamplingNoise;
1212
SerializedDataParameter m_LeakReductionMode;
13+
SerializedDataParameter m_MinValidDotProdValue;
1314
SerializedDataParameter m_AnimateNoise;
1415
SerializedDataParameter m_OcclusionOnlyNormalization;
1516

@@ -25,6 +26,7 @@ public override void OnEnable()
2526
m_ScaleBiasMinProbeDistance = Unpack(o.Find(x => x.scaleBiasWithMinProbeDistance));
2627
m_SamplingNoise = Unpack(o.Find(x => x.samplingNoise));
2728
m_LeakReductionMode = Unpack(o.Find(x => x.leakReductionMode));
29+
m_MinValidDotProdValue = Unpack(o.Find(x => x.minValidDotProductValue));
2830
m_AnimateNoise = Unpack(o.Find(x => x.animateSamplingNoise));
2931
m_OcclusionOnlyNormalization = Unpack(o.Find(x => x.occlusionOnlyReflectionNormalization));
3032

@@ -42,6 +44,15 @@ public override void OnInspectorGUI()
4244
PropertyField(m_SamplingNoise);
4345
PropertyField(m_AnimateNoise);
4446
PropertyField(m_LeakReductionMode);
47+
if (m_LeakReductionMode.value.intValue == (int)APVLeakReductionMode.ValidityBased)
48+
{
49+
}
50+
else if (m_LeakReductionMode.value.intValue == (int)APVLeakReductionMode.ValidityAndNormalBased)
51+
{
52+
using (new IndentLevelScope())
53+
PropertyField(m_MinValidDotProdValue);
54+
}
55+
4556
PropertyField(m_OcclusionOnlyNormalization);
4657

4758
PropertyField(m_IntensityMultiplier);

Packages/com.unity.render-pipelines.core/Runtime/Debug/ProbeVolumeDebugBase.hlsl

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void DoCull(inout v2f o)
103103
// snappedProbePosition_WS : worldspace position of main probe (a corner of the 8 probes cube)
104104
// samplingPosition_WS : worldspace sampling position after applying 'NormalBias' and 'ViewBias' and 'ValidityAndNormalBased Leak Reduction'
105105
// normalizedOffset : normalized offset between sampling position and snappedProbePosition
106-
void FindSamplingData(float3 posWS, float3 normalWS, uint renderingLayer, out float3 snappedProbePosition_WS, out float3 samplingPositionNoAntiLeak_WS, out float probeDistance, out float3 normalizedOffset, out float validityWeights[8])
106+
void FindSamplingData(float3 posWS, float3 normalWS, uint renderingLayer, out float3 snappedProbePosition_WS, out float3 samplingPosition_WS, out float3 samplingPositionNoAntiLeak_WS, out float probeDistance, out float3 normalizedOffset, out float validityWeights[8])
107107
{
108108
float3 cameraPosition_WS = _WorldSpaceCameraPos;
109109
float3 viewDir_WS = normalize(cameraPosition_WS - posWS);
@@ -115,43 +115,33 @@ void FindSamplingData(float3 posWS, float3 normalWS, uint renderingLayer, out fl
115115
posWS = AddNoiseToSamplingPosition(posWS, posSS, viewDir_WS);
116116
}
117117

118-
posWS -= _APVWorldOffset;
118+
posWS -= _WorldOffset;
119119

120-
// uvw
121120
APVResources apvRes = FillAPVResources();
122121
float3 uvw;
123122
uint subdiv;
124123
float3 biasedPosWS;
125124
bool valid = TryToGetPoolUVWAndSubdiv(apvRes, posWS, normalWS, viewDir_WS, uvw, subdiv, biasedPosWS);
126125

127-
// Validity mask
128-
float3 texCoord = uvw * _APVPoolDim - .5f;
129-
float3 texFrac = frac(texCoord);
130-
uint validityMask = LoadValidityMask(apvRes, renderingLayer, texCoord);
131-
for (uint i = 0; i < 8; i++)
126+
probeDistance = ProbeDistance(subdiv);
127+
snappedProbePosition_WS = GetSnappedProbePosition(biasedPosWS, subdiv);
128+
129+
WarpUVWLeakReduction(apvRes, posWS, normalWS, renderingLayer, subdiv, biasedPosWS, uvw, normalizedOffset, validityWeights);
130+
131+
biasedPosWS += _WorldOffset;
132+
snappedProbePosition_WS += _WorldOffset;
133+
samplingPositionNoAntiLeak_WS = biasedPosWS;
134+
135+
if (_LeakReductionMode != 0)
132136
{
133-
int3 probeCoord = GetSampleOffset(i);
134-
float validityWeight = ((probeCoord.x == 1) ? texFrac.x : 1.0f - texFrac.x) *
135-
((probeCoord.y == 1) ? texFrac.y : 1.0f - texFrac.y) *
136-
((probeCoord.z == 1) ? texFrac.z : 1.0f - texFrac.z);
137-
validityWeights[i] = validityWeight * GetValidityWeight(i, validityMask);
137+
samplingPosition_WS = snappedProbePosition_WS + (normalizedOffset*probeDistance);
138138
}
139-
140-
// Sample position
141-
normalizedOffset = texFrac;
142-
if (_APVLeakReductionMode == APVLEAKREDUCTIONMODE_PERFORMANCE)
139+
else
143140
{
144-
float3 warped = uvw;
145-
WarpUVWLeakReduction(apvRes, renderingLayer, warped);
146-
normalizedOffset += (warped - uvw) * _APVPoolDim;
141+
normalizedOffset = (biasedPosWS - snappedProbePosition_WS) / probeDistance;
142+
samplingPosition_WS = biasedPosWS;
147143
}
148144

149-
// stuff
150-
biasedPosWS += _APVWorldOffset;
151-
samplingPositionNoAntiLeak_WS = biasedPosWS;
152-
153-
probeDistance = ProbeDistance(subdiv);
154-
snappedProbePosition_WS = GetSnappedProbePosition(biasedPosWS, subdiv);
155145
}
156146

157147
// Return probe sampling weight
@@ -303,7 +293,7 @@ float3 CalculateDiffuseLighting(v2f i)
303293
float3 skyShadingDirection = normal;
304294
if (_ShadingMode == DEBUGPROBESHADINGMODE_SKY_DIRECTION)
305295
{
306-
if (_APVSkyDirectionWeight > 0)
296+
if (_EnableSkyOcclusionShadingDirection > 0)
307297
{
308298
float value = 1.0f / GetCurrentExposureMultiplier();
309299

@@ -324,8 +314,8 @@ float3 CalculateDiffuseLighting(v2f i)
324314
}
325315
else
326316
{
327-
float3 skyOcclusion = _DebugEmptyProbeData.xyz;
328-
if (_APVSkyOcclusionWeight > 0)
317+
float skyOcclusion = 0.0f;
318+
if (_SkyOcclusionIntensity > 0)
329319
{
330320
// L0 L1
331321
float4 temp = float4(kSHBasis0, kSHBasis1 * normal.x, kSHBasis1 * normal.y, kSHBasis1 * normal.z);
@@ -334,7 +324,10 @@ float3 CalculateDiffuseLighting(v2f i)
334324

335325
if (_ShadingMode == DEBUGPROBESHADINGMODE_SKY_OCCLUSION_SH)
336326
{
337-
return skyOcclusion / GetCurrentExposureMultiplier();
327+
if(_SkyOcclusionIntensity > 0)
328+
return skyOcclusion / GetCurrentExposureMultiplier();
329+
else
330+
return _DebugEmptyProbeData.xyz / GetCurrentExposureMultiplier();
338331
}
339332
else
340333
{
@@ -362,7 +355,7 @@ float3 CalculateDiffuseLighting(v2f i)
362355

363356
bakeDiffuseLighting += EvalL2(L0, L2_R, L2_G, L2_B, L2_C, normal);
364357
#endif
365-
if (_APVSkyOcclusionWeight > 0)
358+
if (_SkyOcclusionIntensity > 0)
366359
bakeDiffuseLighting += skyOcclusion * EvaluateAmbientProbe(skyShadingDirection);
367360

368361
return bakeDiffuseLighting;

0 commit comments

Comments
 (0)