@@ -73,7 +73,6 @@ public partial class ProbeVolumeDynamicGI
7373 private ComputeShader _PropagationAxesShader = null ;
7474 private ComputeShader _PropagationCombineShader = null ;
7575
76- private AxisVector4 [ ] _tempAxisLookups ;
7776 private Vector4 [ ] _sortedAxisLookups ;
7877 private ProbeVolumeSimulationRequest [ ] _probeVolumeSimulationRequests ;
7978
@@ -131,7 +130,6 @@ public enum PropagationAxisAmount
131130 new Vector4 ( 0 , - s_2DDiagonal , - s_2DDiagonal , s_2DDiagonalDist ) ,
132131 } ;
133132
134- _tempAxisLookups = new AxisVector4 [ s_NeighborAxis . Length ] ;
135133 _sortedAxisLookups = new Vector4 [ s_NeighborAxis . Length * s_NeighborAxis . Length ] ;
136134 _probeVolumeSimulationRequests = new ProbeVolumeSimulationRequest [ MAX_SIMULATIONS_PER_FRAME ] ;
137135 }
@@ -252,16 +250,16 @@ internal static void Copy(ref ProbeVolumePayload payloadSrc, ref ProbeVolumePayl
252250 }
253251 }
254252
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 )
256254 {
257- ref var neighborData = ref payload . hitNeighborAxis ;
258- if ( neighborIndex >= neighborData . Length )
255+ ref var neighborDataHits = ref payload . hitNeighborAxis ;
256+ if ( hitIndex >= neighborDataHits . Length )
259257 {
260258 Debug . Assert ( false , "Probe Volume Neighbor Indexing Code Error" ) ;
261259 return ;
262260 }
263261
264- neighborData [ neighborIndex ] = new PackedNeighborHit
262+ neighborDataHits [ hitIndex ] = new PackedNeighborHit
265263 {
266264 indexValidity = PackIndexAndValidity ( ( uint ) probeIndex , ( uint ) axis , validity ) ,
267265 albedoDistance = PackAlbedoAndDistance ( albedo , distance , maxDensity * s_DiagonalDist ) ,
@@ -271,8 +269,9 @@ internal static void SetNeighborDataHit(ref ProbeVolumePayload payload, Vector3
271269
272270 private static void SetNeighborData ( ref ProbeVolumePayload payload , float validity , int probeIndex , int axis , uint hitIndexOrMiss )
273271 {
274- var axisIndex = probeIndex * s_NeighborAxis . Length + axis ;
275272 ref var neighborData = ref payload . neighborAxis ;
273+ var probeCount = neighborData . Length / s_NeighborAxis . Length ;
274+ var axisIndex = axis * probeCount + probeIndex ;
276275 if ( axisIndex >= neighborData . Length )
277276 {
278277 Debug . Assert ( false , "Probe Volume Neighbor Indexing Code Error" ) ;
@@ -406,9 +405,13 @@ internal void DispatchProbePropagation(CommandBuffer cmd, ProbeVolumeHandle prob
406405 var previousRadianceCacheInvalid = InitializePropagationBuffers ( probeVolume ) ;
407406
408407 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 ) ;
412415
413416 _stats . Simulated ( probeVolume ) ;
414417 probeVolume . propagationBuffers . SwapRadianceCaches ( ) ;
@@ -431,18 +434,21 @@ void DispatchClearPreviousRadianceCache(CommandBuffer cmd, ProbeVolumeHandle pro
431434 {
432435 if ( previousRadianceCacheInvalid )
433436 {
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+ }
446452 }
447453 }
448454
@@ -555,6 +561,7 @@ void DispatchPropagationAxes(CommandBuffer cmd, ProbeVolumeHandle probeVolume, i
555561
556562 cmd . SetComputeBufferParam ( shader , kernel , "_ProbeVolumeNeighbors" , probeVolume . propagationBuffers . neighbors ) ;
557563 cmd . SetComputeIntParam ( shader , "_ProbeVolumeNeighborsCount" , probeVolume . propagationBuffers . neighbors . count ) ;
564+ cmd . SetComputeIntParam ( shader , "_ProbeVolumeProbeCount" , probeVolume . propagationBuffers . neighbors . count / s_NeighborAxis . Length ) ;
558565 cmd . SetComputeFloatParam ( shader , "_LeakMultiplier" , giSettings . leakMultiplier . value ) ;
559566 cmd . SetComputeFloatParam ( shader , "_PropagationContribution" , giSettings . propagationContribution . value ) ;
560567 cmd . SetComputeFloatParam ( shader , "_PropagationSharpness" , giSettings . propagationSharpness . value ) ;
@@ -568,7 +575,6 @@ void DispatchPropagationAxes(CommandBuffer cmd, ProbeVolumeHandle probeVolume, i
568575
569576 cmd . SetComputeBufferParam ( shader , kernel , "_PreviousRadianceCacheAxis" , probeVolume . propagationBuffers . GetReadRadianceCacheAxis ( ) ) ;
570577 cmd . SetComputeBufferParam ( shader , kernel , "_RadianceCacheAxis" , probeVolume . propagationBuffers . GetWriteRadianceCacheAxis ( ) ) ;
571- cmd . SetComputeIntParam ( shader , "_RadianceCacheAxisCount" , probeVolume . propagationBuffers . radianceCacheAxis0 . count ) ;
572578
573579 PrecomputeAxisCacheLookup ( giSettings . propagationSharpness . value ) ;
574580 cmd . SetComputeVectorArrayParam ( shader , "_SortedNeighborAxis" , _sortedAxisLookups ) ;
@@ -709,20 +715,18 @@ unsafe void PrecomputeAxisCacheLookup(float sgSharpness)
709715 for ( int axisIndex = 0 ; axisIndex < s_NeighborAxis . Length ; ++ axisIndex )
710716 {
711717 var axis = s_NeighborAxis [ axisIndex ] ;
718+ var sortedAxisStart = axisIndex * s_NeighborAxis . Length ;
712719 for ( int neighborIndex = 0 ; neighborIndex < s_NeighborAxis . Length ; ++ neighborIndex )
713720 {
714721 var neighborDirection = s_NeighborAxis [ neighborIndex ] ;
715722 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 ) ;
717725 }
718726
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 ] )
724728 {
725- CoreUnsafeUtils . CopyTo ( _tempAxisLookups , sortedAxisPtr , s_NeighborAxis . Length ) ;
729+ CoreUnsafeUtils . QuickSort < AxisVector4 > ( s_NeighborAxis . Length , sortedAxisPtr ) ;
726730 }
727731 }
728732
0 commit comments