22using System . Runtime . InteropServices ;
33using UnityEngine . Rendering . UnifiedRayTracing ;
44using Unity . Collections ;
5+ using UnityEngine . Rendering . Sampling ;
56
67namespace UnityEngine . Rendering
78{
@@ -46,6 +47,7 @@ class DefaultRenderingLayer : RenderingLayerBaker
4647 static readonly int _ProbePositions = Shader . PropertyToID ( "_ProbePositions" ) ;
4748 static readonly int _LayerMasks = Shader . PropertyToID ( "_LayerMasks" ) ;
4849 static readonly int _RenderingLayerMasks = Shader . PropertyToID ( "_RenderingLayerMasks" ) ;
50+ static readonly int _SobolBuffer = Shader . PropertyToID ( "_SobolMatricesBuffer" ) ;
4951
5052 int batchIndex , batchCount ;
5153 Vector4 regionMasks ;
@@ -63,6 +65,7 @@ class DefaultRenderingLayer : RenderingLayerBaker
6365 AccelStructAdapter m_AccelerationStructure ;
6466 GraphicsBuffer scratchBuffer ;
6567 GraphicsBuffer probePositionsBuffer ;
68+ GraphicsBuffer sobolBuffer ;
6669
6770 public override ulong currentStep => ( ulong ) batchIndex ;
6871 public override ulong stepCount => ( ulong ) batchCount ;
@@ -92,12 +95,16 @@ public override void Initialize(ProbeVolumeBakingSet bakingSet, NativeArray<Vect
9295 layerMaskBuffer = new GraphicsBuffer ( GraphicsBuffer . Target . Structured , batchSize , Marshal . SizeOf < uint > ( ) ) ;
9396 scratchBuffer = RayTracingHelper . CreateScratchBufferForBuildAndDispatch ( m_AccelerationStructure . GetAccelerationStructure ( ) , s_TracingContext . shaderRL , ( uint ) batchSize , 1 , 1 ) ;
9497
98+ int sobolBufferSize = ( int ) ( SobolData . SobolDims * SobolData . SobolSize ) ;
99+ sobolBuffer = new GraphicsBuffer ( GraphicsBuffer . Target . Structured , sobolBufferSize , Marshal . SizeOf < uint > ( ) ) ;
100+ sobolBuffer . SetData ( SobolData . SobolMatrices ) ;
101+
95102 cmd = new CommandBuffer ( ) ;
96103 m_AccelerationStructure . Build ( cmd , ref scratchBuffer ) ;
97104 Graphics . ExecuteCommandBuffer ( cmd ) ;
98105 cmd . Clear ( ) ;
99106 }
100-
107+
101108 static AccelStructAdapter BuildAccelerationStructure ( )
102109 {
103110 var accelStruct = s_TracingContext . CreateAccelerationStructure ( ) ;
@@ -115,6 +122,7 @@ static AccelStructAdapter BuildAccelerationStructure()
115122 var matIndices = new uint [ subMeshCount ] ;
116123 Array . Fill ( matIndices , renderer . component . renderingLayerMask ) ; // repurpose the material id as we don't need it here
117124 var perSubMeshMask = new uint [ subMeshCount ] ;
125+
118126 Array . Fill ( perSubMeshMask , GetInstanceMask ( renderer . component . shadowCastingMode ) ) ;
119127 accelStruct . AddInstance ( renderer . component . GetInstanceID ( ) , renderer . component , perSubMeshMask , matIndices ) ;
120128 }
@@ -145,6 +153,7 @@ public override bool Step()
145153 shader . SetVectorParam ( cmd , _RenderingLayerMasks , regionMasks ) ;
146154 shader . SetBufferParam ( cmd , _ProbePositions , probePositionsBuffer ) ;
147155 shader . SetBufferParam ( cmd , _LayerMasks , layerMaskBuffer ) ;
156+ shader . SetBufferParam ( cmd , _SobolBuffer , sobolBuffer ) ;
148157
149158 shader . Dispatch ( cmd , scratchBuffer , ( uint ) batchSize , 1 , 1 ) ;
150159 batchIndex ++ ;
@@ -176,6 +185,7 @@ public override void Dispose()
176185 scratchBuffer ? . Dispose ( ) ;
177186 probePositionsBuffer . Dispose ( ) ;
178187 m_AccelerationStructure . Dispose ( ) ;
188+ sobolBuffer ? . Dispose ( ) ;
179189
180190 layerMaskBuffer . Dispose ( ) ;
181191 layerMask . Dispose ( ) ;
0 commit comments