2
2
using System . Runtime . InteropServices ;
3
3
using UnityEngine . Rendering . UnifiedRayTracing ;
4
4
using Unity . Collections ;
5
+ using UnityEngine . Rendering . Sampling ;
5
6
6
7
namespace UnityEngine . Rendering
7
8
{
@@ -46,6 +47,7 @@ class DefaultRenderingLayer : RenderingLayerBaker
46
47
static readonly int _ProbePositions = Shader . PropertyToID ( "_ProbePositions" ) ;
47
48
static readonly int _LayerMasks = Shader . PropertyToID ( "_LayerMasks" ) ;
48
49
static readonly int _RenderingLayerMasks = Shader . PropertyToID ( "_RenderingLayerMasks" ) ;
50
+ static readonly int _SobolBuffer = Shader . PropertyToID ( "_SobolMatricesBuffer" ) ;
49
51
50
52
int batchIndex , batchCount ;
51
53
Vector4 regionMasks ;
@@ -63,6 +65,7 @@ class DefaultRenderingLayer : RenderingLayerBaker
63
65
AccelStructAdapter m_AccelerationStructure ;
64
66
GraphicsBuffer scratchBuffer ;
65
67
GraphicsBuffer probePositionsBuffer ;
68
+ GraphicsBuffer sobolBuffer ;
66
69
67
70
public override ulong currentStep => ( ulong ) batchIndex ;
68
71
public override ulong stepCount => ( ulong ) batchCount ;
@@ -92,12 +95,16 @@ public override void Initialize(ProbeVolumeBakingSet bakingSet, NativeArray<Vect
92
95
layerMaskBuffer = new GraphicsBuffer ( GraphicsBuffer . Target . Structured , batchSize , Marshal . SizeOf < uint > ( ) ) ;
93
96
scratchBuffer = RayTracingHelper . CreateScratchBufferForBuildAndDispatch ( m_AccelerationStructure . GetAccelerationStructure ( ) , s_TracingContext . shaderRL , ( uint ) batchSize , 1 , 1 ) ;
94
97
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
+
95
102
cmd = new CommandBuffer ( ) ;
96
103
m_AccelerationStructure . Build ( cmd , ref scratchBuffer ) ;
97
104
Graphics . ExecuteCommandBuffer ( cmd ) ;
98
105
cmd . Clear ( ) ;
99
106
}
100
-
107
+
101
108
static AccelStructAdapter BuildAccelerationStructure ( )
102
109
{
103
110
var accelStruct = s_TracingContext . CreateAccelerationStructure ( ) ;
@@ -115,6 +122,7 @@ static AccelStructAdapter BuildAccelerationStructure()
115
122
var matIndices = new uint [ subMeshCount ] ;
116
123
Array . Fill ( matIndices , renderer . component . renderingLayerMask ) ; // repurpose the material id as we don't need it here
117
124
var perSubMeshMask = new uint [ subMeshCount ] ;
125
+
118
126
Array . Fill ( perSubMeshMask , GetInstanceMask ( renderer . component . shadowCastingMode ) ) ;
119
127
accelStruct . AddInstance ( renderer . component . GetInstanceID ( ) , renderer . component , perSubMeshMask , matIndices ) ;
120
128
}
@@ -145,6 +153,7 @@ public override bool Step()
145
153
shader . SetVectorParam ( cmd , _RenderingLayerMasks , regionMasks ) ;
146
154
shader . SetBufferParam ( cmd , _ProbePositions , probePositionsBuffer ) ;
147
155
shader . SetBufferParam ( cmd , _LayerMasks , layerMaskBuffer ) ;
156
+ shader . SetBufferParam ( cmd , _SobolBuffer , sobolBuffer ) ;
148
157
149
158
shader . Dispatch ( cmd , scratchBuffer , ( uint ) batchSize , 1 , 1 ) ;
150
159
batchIndex ++ ;
@@ -176,6 +185,7 @@ public override void Dispose()
176
185
scratchBuffer ? . Dispose ( ) ;
177
186
probePositionsBuffer . Dispose ( ) ;
178
187
m_AccelerationStructure . Dispose ( ) ;
188
+ sobolBuffer ? . Dispose ( ) ;
179
189
180
190
layerMaskBuffer . Dispose ( ) ;
181
191
layerMask . Dispose ( ) ;
0 commit comments