@@ -73,7 +73,6 @@ public partial class ProbeVolumeDynamicGI
73
73
private ComputeShader _PropagationAxesShader = null ;
74
74
private ComputeShader _PropagationCombineShader = null ;
75
75
76
- private AxisVector4 [ ] _tempAxisLookups ;
77
76
private Vector4 [ ] _sortedAxisLookups ;
78
77
private ProbeVolumeSimulationRequest [ ] _probeVolumeSimulationRequests ;
79
78
@@ -131,7 +130,6 @@ public enum PropagationAxisAmount
131
130
new Vector4 ( 0 , - s_2DDiagonal , - s_2DDiagonal , s_2DDiagonalDist ) ,
132
131
} ;
133
132
134
- _tempAxisLookups = new AxisVector4 [ s_NeighborAxis . Length ] ;
135
133
_sortedAxisLookups = new Vector4 [ s_NeighborAxis . Length * s_NeighborAxis . Length ] ;
136
134
_probeVolumeSimulationRequests = new ProbeVolumeSimulationRequest [ MAX_SIMULATIONS_PER_FRAME ] ;
137
135
}
@@ -252,16 +250,16 @@ internal static void Copy(ref ProbeVolumePayload payloadSrc, ref ProbeVolumePayl
252
250
}
253
251
}
254
252
255
- internal static void SetNeighborDataHit ( ref ProbeVolumePayload payload , Vector3 albedo , Vector3 normal , float distance , float validity , int probeIndex , int axis , int neighborIndex , float maxDensity )
253
+ internal static void SetNeighborDataHit ( ref ProbeVolumePayload payload , Vector3 albedo , Vector3 normal , float distance , float validity , int probeIndex , int axis , int hitIndex , float maxDensity )
256
254
{
257
- ref var neighborData = ref payload . hitNeighborAxis ;
258
- if ( neighborIndex >= neighborData . Length )
255
+ ref var neighborDataHits = ref payload . hitNeighborAxis ;
256
+ if ( hitIndex >= neighborDataHits . Length )
259
257
{
260
258
Debug . Assert ( false , "Probe Volume Neighbor Indexing Code Error" ) ;
261
259
return ;
262
260
}
263
261
264
- neighborData [ neighborIndex ] = new PackedNeighborHit
262
+ neighborDataHits [ hitIndex ] = new PackedNeighborHit
265
263
{
266
264
indexValidity = PackIndexAndValidity ( ( uint ) probeIndex , ( uint ) axis , validity ) ,
267
265
albedoDistance = PackAlbedoAndDistance ( albedo , distance , maxDensity * s_DiagonalDist ) ,
@@ -271,8 +269,9 @@ internal static void SetNeighborDataHit(ref ProbeVolumePayload payload, Vector3
271
269
272
270
private static void SetNeighborData ( ref ProbeVolumePayload payload , float validity , int probeIndex , int axis , uint hitIndexOrMiss )
273
271
{
274
- var axisIndex = probeIndex * s_NeighborAxis . Length + axis ;
275
272
ref var neighborData = ref payload . neighborAxis ;
273
+ var probeCount = neighborData . Length / s_NeighborAxis . Length ;
274
+ var axisIndex = axis * probeCount + probeIndex ;
276
275
if ( axisIndex >= neighborData . Length )
277
276
{
278
277
Debug . Assert ( false , "Probe Volume Neighbor Indexing Code Error" ) ;
@@ -406,9 +405,13 @@ internal void DispatchProbePropagation(CommandBuffer cmd, ProbeVolumeHandle prob
406
405
var previousRadianceCacheInvalid = InitializePropagationBuffers ( probeVolume ) ;
407
406
408
407
DispatchClearPreviousRadianceCache ( cmd , probeVolume , previousRadianceCacheInvalid || giSettings . clear . value || _clearAllActive ) ;
409
- DispatchPropagationHits ( cmd , probeVolume , in giSettings , previousRadianceCacheInvalid ) ;
410
- DispatchPropagationAxes ( cmd , probeVolume , in giSettings , previousRadianceCacheInvalid ) ;
411
- DispatchPropagationCombine ( cmd , probeVolume , in giSettings , in shaderGlobals , probeVolumeAtlasSHRTHandle ) ;
408
+
409
+ using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . ProbeVolumeDynamicGIHits ) ) )
410
+ DispatchPropagationHits ( cmd , probeVolume , in giSettings , previousRadianceCacheInvalid ) ;
411
+ using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . ProbeVolumeDynamicGIAxes ) ) )
412
+ DispatchPropagationAxes ( cmd , probeVolume , in giSettings , previousRadianceCacheInvalid ) ;
413
+ using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . ProbeVolumeDynamicGICombine ) ) )
414
+ DispatchPropagationCombine ( cmd , probeVolume , in giSettings , in shaderGlobals , probeVolumeAtlasSHRTHandle ) ;
412
415
413
416
_stats . Simulated ( probeVolume ) ;
414
417
probeVolume . propagationBuffers . SwapRadianceCaches ( ) ;
@@ -431,18 +434,21 @@ void DispatchClearPreviousRadianceCache(CommandBuffer cmd, ProbeVolumeHandle pro
431
434
{
432
435
if ( previousRadianceCacheInvalid )
433
436
{
434
- var kernel = _PropagationClearRadianceShader . FindKernel ( "ClearPreviousRadianceCache" ) ;
435
- var shader = _PropagationClearRadianceShader ;
436
-
437
- cmd . SetComputeBufferParam ( shader , kernel , "_RadianceCacheAxis0" , probeVolume . propagationBuffers . radianceCacheAxis0 ) ;
438
- cmd . SetComputeBufferParam ( shader , kernel , "_RadianceCacheAxis1" , probeVolume . propagationBuffers . radianceCacheAxis1 ) ;
439
- cmd . SetComputeIntParam ( shader , "_RadianceCacheAxisCount" , probeVolume . propagationBuffers . radianceCacheAxis0 . count ) ;
440
- cmd . SetComputeBufferParam ( shader , kernel , "_HitRadianceCacheAxis" , probeVolume . propagationBuffers . hitRadianceCache ) ;
441
- cmd . SetComputeIntParam ( shader , "_HitRadianceCacheAxisCount" , probeVolume . propagationBuffers . hitRadianceCache . count ) ;
442
-
443
- int numHits = Mathf . Max ( probeVolume . propagationBuffers . radianceCacheAxis0 . count , probeVolume . propagationBuffers . hitRadianceCache . count ) ;
444
- int dispatchX = ( numHits + 63 ) / 64 ;
445
- cmd . DispatchCompute ( shader , kernel , dispatchX , 1 , 1 ) ;
437
+ using ( new ProfilingScope ( cmd , ProfilingSampler . Get ( HDProfileId . ProbeVolumeDynamicGIClear ) ) )
438
+ {
439
+ var kernel = _PropagationClearRadianceShader . FindKernel ( "ClearPreviousRadianceCache" ) ;
440
+ var shader = _PropagationClearRadianceShader ;
441
+
442
+ cmd . SetComputeBufferParam ( shader , kernel , "_RadianceCacheAxis0" , probeVolume . propagationBuffers . radianceCacheAxis0 ) ;
443
+ cmd . SetComputeBufferParam ( shader , kernel , "_RadianceCacheAxis1" , probeVolume . propagationBuffers . radianceCacheAxis1 ) ;
444
+ cmd . SetComputeIntParam ( shader , "_RadianceCacheAxisCount" , probeVolume . propagationBuffers . radianceCacheAxis0 . count ) ;
445
+ cmd . SetComputeBufferParam ( shader , kernel , "_HitRadianceCacheAxis" , probeVolume . propagationBuffers . hitRadianceCache ) ;
446
+ cmd . SetComputeIntParam ( shader , "_HitRadianceCacheAxisCount" , probeVolume . propagationBuffers . hitRadianceCache . count ) ;
447
+
448
+ int numHits = Mathf . Max ( probeVolume . propagationBuffers . radianceCacheAxis0 . count , probeVolume . propagationBuffers . hitRadianceCache . count ) ;
449
+ int dispatchX = ( numHits + 63 ) / 64 ;
450
+ cmd . DispatchCompute ( shader , kernel , dispatchX , 1 , 1 ) ;
451
+ }
446
452
}
447
453
}
448
454
@@ -555,6 +561,7 @@ void DispatchPropagationAxes(CommandBuffer cmd, ProbeVolumeHandle probeVolume, i
555
561
556
562
cmd . SetComputeBufferParam ( shader , kernel , "_ProbeVolumeNeighbors" , probeVolume . propagationBuffers . neighbors ) ;
557
563
cmd . SetComputeIntParam ( shader , "_ProbeVolumeNeighborsCount" , probeVolume . propagationBuffers . neighbors . count ) ;
564
+ cmd . SetComputeIntParam ( shader , "_ProbeVolumeProbeCount" , probeVolume . propagationBuffers . neighbors . count / s_NeighborAxis . Length ) ;
558
565
cmd . SetComputeFloatParam ( shader , "_LeakMultiplier" , giSettings . leakMultiplier . value ) ;
559
566
cmd . SetComputeFloatParam ( shader , "_PropagationContribution" , giSettings . propagationContribution . value ) ;
560
567
cmd . SetComputeFloatParam ( shader , "_PropagationSharpness" , giSettings . propagationSharpness . value ) ;
@@ -568,7 +575,6 @@ void DispatchPropagationAxes(CommandBuffer cmd, ProbeVolumeHandle probeVolume, i
568
575
569
576
cmd . SetComputeBufferParam ( shader , kernel , "_PreviousRadianceCacheAxis" , probeVolume . propagationBuffers . GetReadRadianceCacheAxis ( ) ) ;
570
577
cmd . SetComputeBufferParam ( shader , kernel , "_RadianceCacheAxis" , probeVolume . propagationBuffers . GetWriteRadianceCacheAxis ( ) ) ;
571
- cmd . SetComputeIntParam ( shader , "_RadianceCacheAxisCount" , probeVolume . propagationBuffers . radianceCacheAxis0 . count ) ;
572
578
573
579
PrecomputeAxisCacheLookup ( giSettings . propagationSharpness . value ) ;
574
580
cmd . SetComputeVectorArrayParam ( shader , "_SortedNeighborAxis" , _sortedAxisLookups ) ;
@@ -709,20 +715,18 @@ unsafe void PrecomputeAxisCacheLookup(float sgSharpness)
709
715
for ( int axisIndex = 0 ; axisIndex < s_NeighborAxis . Length ; ++ axisIndex )
710
716
{
711
717
var axis = s_NeighborAxis [ axisIndex ] ;
718
+ var sortedAxisStart = axisIndex * s_NeighborAxis . Length ;
712
719
for ( int neighborIndex = 0 ; neighborIndex < s_NeighborAxis . Length ; ++ neighborIndex )
713
720
{
714
721
var neighborDirection = s_NeighborAxis [ neighborIndex ] ;
715
722
var sgWeight = SGEvaluateFromDirection ( 1 , sgSharpness , neighborDirection , axis ) ;
716
- _tempAxisLookups [ neighborIndex ] = new AxisVector4 ( new Vector4 ( sgWeight , neighborIndex , 0 , 0 ) ) ;
723
+ sgWeight /= neighborDirection . w * neighborDirection . w ;
724
+ _sortedAxisLookups [ sortedAxisStart + neighborIndex ] = new Vector4 ( sgWeight , neighborIndex , 0 , 0 ) ;
717
725
}
718
726
719
- fixed ( AxisVector4 * axisPtr = & _tempAxisLookups [ 0 ] )
720
- {
721
- CoreUnsafeUtils . QuickSort < AxisVector4 > ( _tempAxisLookups . Length , axisPtr ) ;
722
- }
723
- fixed ( Vector4 * sortedAxisPtr = & _sortedAxisLookups [ axisIndex * s_NeighborAxis . Length ] )
727
+ fixed ( Vector4 * sortedAxisPtr = & _sortedAxisLookups [ sortedAxisStart ] )
724
728
{
725
- CoreUnsafeUtils . CopyTo ( _tempAxisLookups , sortedAxisPtr , s_NeighborAxis . Length ) ;
729
+ CoreUnsafeUtils . QuickSort < AxisVector4 > ( s_NeighborAxis . Length , sortedAxisPtr ) ;
726
730
}
727
731
}
728
732
0 commit comments