Skip to content

Commit 5e89f2e

Browse files
Populate new neighbor axis lookups buffer and switch to reading from it.
1 parent c7d2009 commit 5e89f2e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbePropagationAxes.compute

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,14 @@ void PropagateLight(uint3 id : SV_DispatchThreadID)
267267

268268
for(int l=0; l < PROPAGATION_AXIS_AMOUNT; ++l)
269269
{
270-
float4 neighborAxisLookup = _SortedNeighborAxis[neighborAxisIndexOffset + l];
271-
int i = (int)neighborAxisLookup.y;
272-
float sgWeight = neighborAxisLookup.x;
270+
// float4 neighborAxisLookup = _SortedNeighborAxis[neighborAxisIndexOffset + l];
271+
// int i = (int)neighborAxisLookup.y;
272+
// float sgWeight = neighborAxisLookup.x;
273273

274-
/*NeighborAxisLookup neighborAxisLookup = _SortedNeighborAxisLookup[neighborAxisIndexOffset + l];
274+
NeighborAxisLookup neighborAxisLookup = _SortedNeighborAxisLookup[neighborAxisIndexOffset + l];
275275
int i = neighborAxisLookup.index;
276276
float sgWeight = neighborAxisLookup.sgWeight;
277-
float3 neighborDirection = neighborAxisLookup.neighborDirection;*/
278277

279-
float3 neighborDirection = _RayAxis[i].xyz;
280278
uint sampleAxis = i * _ProbeVolumeProbeCount + probeIndex;
281279
NeighborAxis neighbor = _ProbeVolumeNeighbors[sampleAxis];
282280

@@ -313,6 +311,8 @@ void PropagateLight(uint3 id : SV_DispatchThreadID)
313311
#if defined(SAMPLE_NEIGHBORS_DIRECTION_ONLY) || defined(SAMPLE_NEIGHBORS_POSITION_AND_DIRECTION)
314312
else
315313
{
314+
float3 neighborDirection = neighborAxisLookup.neighborDirection;
315+
// float3 neighborDirection = _RayAxis[i].xyz;
316316
float3 neighborWorldDirection = neighborDirection;
317317

318318
#if defined(SAMPLE_NEIGHBORS_POSITION_AND_DIRECTION)

com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbeVolumeDynamicGI.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public partial class ProbeVolumeDynamicGI
7474
private ComputeShader _PropagationCombineShader = null;
7575

7676
private Vector4[] _sortedAxisLookups;
77+
private NeighborAxisLookup[] _sortedAxisLookupsArray;
7778
private ComputeBuffer _sortedNeighborAxisLookups;
7879
private ProbeVolumeSimulationRequest[] _probeVolumeSimulationRequests;
7980

@@ -131,9 +132,9 @@ public enum PropagationAxisAmount
131132
new Vector4( 0, -s_2DDiagonal, -s_2DDiagonal, s_2DDiagonalDist),
132133
};
133134

134-
int sortedNeighborAxisLookupsCount = (s_NeighborAxis.Length * s_NeighborAxis.Length);
135-
_sortedAxisLookups = new Vector4[sortedNeighborAxisLookupsCount];
136-
ProbeVolume.EnsureBuffer<NeighborAxisLookup>(ref _sortedNeighborAxisLookups, sortedNeighborAxisLookupsCount);
135+
_sortedAxisLookups = new Vector4[s_NeighborAxis.Length * s_NeighborAxis.Length];
136+
_sortedAxisLookupsArray = new NeighborAxisLookup[s_NeighborAxis.Length * s_NeighborAxis.Length];
137+
137138
_probeVolumeSimulationRequests = new ProbeVolumeSimulationRequest[MAX_SIMULATIONS_PER_FRAME];
138139
}
139140

@@ -388,6 +389,8 @@ internal void Allocate(RenderPipelineResources resources)
388389
_PropagationAxesShader = resources.shaders.probePropagationAxesCS;
389390
_PropagationCombineShader = resources.shaders.probePropagationCombineCS;
390391

392+
ProbeVolume.EnsureBuffer<NeighborAxisLookup>(ref _sortedNeighborAxisLookups, _sortedAxisLookups.Length);
393+
391394
#if UNITY_EDITOR
392395
_ProbeVolumeDebugNeighbors = resources.shaders.probeVolumeDebugNeighbors;
393396
dummyColor = RTHandles.Alloc(kDummyRTWidth, kDummyRTHeight, dimension: TextureDimension.Tex2D, colorFormat: GraphicsFormat.R8G8B8A8_UNorm, name: "Dummy color");
@@ -400,6 +403,7 @@ internal void Cleanup()
400403
#if UNITY_EDITOR
401404
RTHandles.Release(dummyColor);
402405
#endif
406+
ProbeVolume.CleanupBuffer(_sortedNeighborAxisLookups);
403407
}
404408

405409

@@ -727,14 +731,22 @@ unsafe void PrecomputeAxisCacheLookup(float sgSharpness)
727731
var sgWeight = SGEvaluateFromDirection(1, sgSharpness, neighborDirection, axis);
728732
sgWeight /= neighborDirection.w * neighborDirection.w;
729733
_sortedAxisLookups[sortedAxisStart + neighborIndex] = new Vector4(sgWeight, neighborIndex, 0, 0);
734+
_sortedAxisLookupsArray[sortedAxisStart + neighborIndex] = new NeighborAxisLookup(neighborIndex, sgWeight, neighborDirection);
730735
}
731736

732737
fixed (Vector4* sortedAxisPtr = &_sortedAxisLookups[sortedAxisStart])
733738
{
734739
CoreUnsafeUtils.QuickSort<AxisVector4>(s_NeighborAxis.Length, sortedAxisPtr);
735740
}
741+
742+
fixed (NeighborAxisLookup* sortedAxisPtr = &_sortedAxisLookupsArray[sortedAxisStart])
743+
{
744+
CoreUnsafeUtils.QuickSort<NeighborAxisLookup>(s_NeighborAxis.Length, sortedAxisPtr);
745+
}
736746
}
737747

748+
_sortedNeighborAxisLookups.SetData(_sortedAxisLookupsArray);
749+
738750
_sortedAxisSharpness = sgSharpness;
739751
}
740752
}

0 commit comments

Comments
 (0)