-
Notifications
You must be signed in to change notification settings - Fork 772
/
ProbePropagationCombine.compute
357 lines (294 loc) · 19 KB
/
ProbePropagationCombine.compute
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#pragma kernel CombinePropagationAxis
#define GROUP_SIZE 64
//#pragma enable_d3d11_debug_symbols
#pragma multi_compile BASIS_SPHERICAL_GAUSSIAN BASIS_SPHERICAL_GAUSSIAN_WINDOWED BASIS_AMBIENT_DICE_SHARP BASIS_AMBIENT_DICE_SOFTER BASIS_AMBIENT_DICE_SUPER_SOFT BASIS_AMBIENT_DICE_ULTRA_SOFT
#pragma multi_compile BASIS_PROPAGATION_OVERRIDE_NONE BASIS_PROPAGATION_OVERRIDE_SPHERICAL_GAUSSIAN BASIS_PROPAGATION_OVERRIDE_AMBIENT_DICE_WRAPPED_SOFTER BASIS_PROPAGATION_OVERRIDE_AMBIENT_DICE_WRAPPED_SUPER_SOFT BASIS_PROPAGATION_OVERRIDE_AMBIENT_DICE_WRAPPED_ULTRA_SOFT
#pragma multi_compile _ RADIANCE_ENCODING_LOGLUV RADIANCE_ENCODING_HALFLUV RADIANCE_ENCODING_R11G11B10
#pragma multi_compile PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L1 PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L2
#pragma multi_compile _ DIRTY_FLAGS_DISABLED
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbeVolumeDynamicGI.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeRotate.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbePropagationGlobals.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbeVolumeSphericalHarmonicsLighting.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/DynamicGI/ProbePropagationBasis.hlsl"
StructuredBuffer<float> _ProbeVolumeAtlasReadSHL01Buffer;
#if defined(PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L2)
StructuredBuffer<float> _ProbeVolumeAtlasReadSHL2Buffer;
#endif
StructuredBuffer<float> _ProbeVolumeAtlasReadValidityBuffer;
RWTexture3D<float4> _ProbeVolumeAtlasWriteTextureSH;
uint _ProbeVolumeAtlasReadBufferCount;
float3 _ProbeVolumeResolution;
float3 _ProbeVolumeAtlasBias;
float4 _ProbeVolumeAtlasResolutionAndSliceCount;
float3 _ProbeVolumeAtlasSHRotateRight;
float3 _ProbeVolumeAtlasSHRotateUp;
float3 _ProbeVolumeAtlasSHRotateForward;
float3 _ProbeVolumeDGIBoundsRight;
float3 _ProbeVolumeDGIBoundsUp;
#ifndef DIRTY_FLAGS_DISABLED
RWStructuredBuffer<int> _ProbeVolumeDirtyFlags;
#endif
StructuredBuffer<RADIANCE> _RadianceCacheAxis;
int _RadianceCacheAxisCount;
float _BakedLightingContribution;
float _DynamicPropagationContribution;
float4 _RayAxis[NEIGHBOR_AXIS_COUNT];
float _Sharpness;
uint3 ComputeWriteIndexFromReadIndex(uint readIndex, float3 resolution)
{
// _ProbeVolumeAtlasReadBuffer[z * resolutionY * resolutionX + y * resolutionX + x]
// TODO: Could implement as floating point operations, which is likely faster.
// Would need to verify precision.
uint x = readIndex % (uint)resolution.x;
uint y = (readIndex / (uint)resolution.x) % (uint)resolution.y;
uint z = readIndex / ((uint)resolution.y * (uint)resolution.x);
uint3 writeIndex = uint3(x, y, z);
writeIndex += (uint3)floor(_ProbeVolumeAtlasBias * _ProbeVolumeAtlasResolutionAndSliceCount.xyz);
return writeIndex;
}
float ReadValidity(uint readIndex)
{
const float occlusion = _ProbeVolumeAtlasReadValidityBuffer[readIndex];
return pow(1.0 - occlusion, 8.0);
}
SHOutgoingRadiosityWithProjectedConstantsPacked ReadBakedSH(uint readIndex)
{
SHOutgoingRadiosityWithProjectedConstantsPacked outgoingRadiosity;
ZERO_INITIALIZE(SHOutgoingRadiosityWithProjectedConstantsPacked, outgoingRadiosity)
const uint SH_STRIDE_L01 = 4 * 3;
const uint SH_STRIDE_L2 = (9 * 3) - SH_STRIDE_L01;
#if defined(PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L0)
outgoingRadiosity.data[0] = float4(
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 0], // shAr.w
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 1], // shAg.w
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 2], // shAb.w
0.0
);
#elif defined(PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L1)
outgoingRadiosity.data[0] = float4(
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 0], // shAr.w
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 1], // shAg.w
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 2], // shAb.w
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 3] // shAr.x
);
outgoingRadiosity.data[1] = float4(
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 4], // shAr.y
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 5], // shAr.z
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 6], // shAg.x
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 7] // shAg.y
);
outgoingRadiosity.data[2] = float4(
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 8], // shAg.z
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 9], // shAb.x
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 10], // shAb.y
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 11] // shAb.z
);
#elif defined(PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L2)
outgoingRadiosity.data[0] = float4(
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 0], // shAr.w
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 1], // shAg.w
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 2], // shAb.w
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 3] // shAr.x
);
outgoingRadiosity.data[1] = float4(
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 4], // shAr.y
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 5], // shAr.z
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 6], // shAg.x
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 7] // shAg.y
);
outgoingRadiosity.data[2] = float4(
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 8], // shAg.z
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 9], // shAb.x
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 10], // shAb.y
_ProbeVolumeAtlasReadSHL01Buffer[readIndex * SH_STRIDE_L01 + 11] // shAb.z
);
outgoingRadiosity.data[3] = float4(
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 0], // shBr.x
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 1], // shBr.y
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 2], // shBr.z
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 3] // shBr.w
);
outgoingRadiosity.data[4] = float4(
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 4], // shBg.x
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 5], // shBg.y
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 6], // shBg.z
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 7] // shBg.w
);
outgoingRadiosity.data[5] = float4(
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 8], // shBb.x
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 9], // shBb.y
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 10], // shBb.z
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 11] // shBb.w
);
outgoingRadiosity.data[6] = float4(
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 12], // shCr.x
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 13], // shCr.y
_ProbeVolumeAtlasReadSHL2Buffer[readIndex * SH_STRIDE_L2 + 14], // shCr.z
0.0
);
#else
#error "Unsupported Probe Volumes atlas encoding";
#endif
return outgoingRadiosity;
}
void WriteFinalSHOutgoingRadiosityWithProjectedConstantsPacked(uint3 writeIndex, SHOutgoingRadiosityWithProjectedConstantsPacked outgoingRadiosityProjectedConstantsPacked, float validity)
{
#if defined(PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L0)
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 0)] = float4(outgoingRadiosityProjectedConstantsPacked.data[0].xyz, validity);
#elif defined(PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L1)
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 0)] = outgoingRadiosityProjectedConstantsPacked.data[0];
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 1)] = outgoingRadiosityProjectedConstantsPacked.data[1];
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 2)] = outgoingRadiosityProjectedConstantsPacked.data[2];
// Validity shouldn't change from the initial state so in the case when it's not packed with other coefficients we can skip writing to that slice.
#elif defined(PROBE_VOLUMES_ENCODING_SPHERICAL_HARMONICS_L2)
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 0)] = outgoingRadiosityProjectedConstantsPacked.data[0];
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 1)] = outgoingRadiosityProjectedConstantsPacked.data[1];
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 2)] = outgoingRadiosityProjectedConstantsPacked.data[2];
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 3)] = outgoingRadiosityProjectedConstantsPacked.data[3];
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 4)] = outgoingRadiosityProjectedConstantsPacked.data[4];
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 5)] = outgoingRadiosityProjectedConstantsPacked.data[5];
_ProbeVolumeAtlasWriteTextureSH[uint3(writeIndex.x, writeIndex.y, writeIndex.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 6)] = float4(outgoingRadiosityProjectedConstantsPacked.data[6].xyz, validity);
#else
#error "Unsupported Probe Volumes atlas encoding";
#endif
}
SHIncomingIrradiance SHIncomingIrradianceComputeFromBasisAxisHit(BasisAxisHit basisAxisHit, float3 radiance)
{
ZHWindow zhWindow = ComputeZHWindowFromBasisAxisHit(basisAxisHit);
SHWindow shWindow = SHWindowComputeFromZHWindow(zhWindow, basisAxisHit.mean);
SHIncomingIrradiance irradiance = SHIncomingIrradianceComputeFromSHWindowAndRadiance(shWindow, radiance);
return irradiance;
}
SHIncomingIrradiance ComputeSHIncomingIrradianceFromRadialBasisFunctionWithSamplePeaks(uint probeIndex)
{
SHIncomingIrradiance incomingIrradiance;
ZERO_INITIALIZE(SHIncomingIrradiance, incomingIrradiance);
uint localIndex = probeIndex;
for (int axis = 0; axis < NEIGHBOR_AXIS_COUNT; ++axis)
{
float3 radiance = DecodeRadiance(_RadianceCacheAxis[localIndex]);
float3 directionOS = _RayAxis[axis].xyz;
const float3x3 probeVolumeLtw = float3x3(_ProbeVolumeDGIBoundsRight, _ProbeVolumeDGIBoundsUp, cross(_ProbeVolumeDGIBoundsRight, _ProbeVolumeDGIBoundsUp));
float3 directionWS = mul(directionOS, probeVolumeLtw);
BasisAxisHit basisAxisHit = ComputeBasisAxisHit(directionOS, _Sharpness);
basisAxisHit.mean = directionWS; // Rotate the basis to world space after constructing it (because the construction can be dependant on the object space direction (i.e: diagonals with less energy)).
SHIncomingIrradianceAccumulate(incomingIrradiance, basisAxisHit.mean, radiance);
localIndex += _ProbeVolumeAtlasReadBufferCount;
}
return incomingIrradiance;
}
SHIncomingIrradiance ComputeSHIncomingIrradianceFromRadialBasisFunctionWithZHFit(uint probeIndex)
{
SHIncomingIrradiance incomingIrradiance;
ZERO_INITIALIZE(SHIncomingIrradiance, incomingIrradiance);
uint localIndex = probeIndex;
for (int axis = 0; axis < NEIGHBOR_AXIS_COUNT; ++axis)
{
float3 radiance = DecodeRadiance(_RadianceCacheAxis[localIndex]);
float3 directionOS = _RayAxis[axis].xyz;
const float3x3 probeVolumeLtw = float3x3(_ProbeVolumeDGIBoundsRight, _ProbeVolumeDGIBoundsUp, cross(_ProbeVolumeDGIBoundsRight, _ProbeVolumeDGIBoundsUp));
float3 directionWS = mul(directionOS, probeVolumeLtw);
BasisAxisHit basisAxisHit = ComputeBasisAxisHit(directionOS, _Sharpness);
basisAxisHit.mean = directionWS; // Rotate the basis to world space after constructing it (because the construction can be dependant on the object space direction (i.e: diagonals with less energy)).
SHIncomingIrradiance incomingIrradianceCurrentLobe = SHIncomingIrradianceComputeFromBasisAxisHit(basisAxisHit, radiance);
SHIncomingIrradianceAccumulateFromSHIncomingIrradiance(incomingIrradiance, incomingIrradianceCurrentLobe);
localIndex += _ProbeVolumeAtlasReadBufferCount;
}
return incomingIrradiance;
}
SHIncomingIrradiance ComputeSHIncomingIrradianceFromRadialBasisFunctionWithMonteCarlo(uint probeIndex)
{
SHIncomingIrradiance incomingIrradiance;
ZERO_INITIALIZE(SHIncomingIrradiance, incomingIrradiance);
const int SAMPLE_COUNT = 8192;
const float SAMPLE_COUNT_INVERSE = 1.0 / float(SAMPLE_COUNT);
float GOLDEN_ANGLE = PI * (3.0 - sqrt(5.0));
float GOLDEN_ANGLE_HALF = GOLDEN_ANGLE * 0.5;
const float SOLID_ANGLE_SPHERE = 4.0 * PI;
for (int sampleIndex = 0; sampleIndex < SAMPLE_COUNT; ++sampleIndex)
{
float3 sampleDirectionWS;
{
float offset = (float)sampleIndex + 0.5;
float theta = offset * GOLDEN_ANGLE + GOLDEN_ANGLE_HALF;
float z = -(offset * SAMPLE_COUNT_INVERSE * 2.0 - 1.0);
float r = sqrt(1.0 - z * z);
sampleDirectionWS = float3(
r * cos(theta),
r * sin(theta),
z
);
}
float differentialArea = SOLID_ANGLE_SPHERE * SAMPLE_COUNT_INVERSE;
float3 sampleIncomingRadiance = 0.0;
uint localIndex = probeIndex;
for (int axis = 0; axis < NEIGHBOR_AXIS_COUNT; ++axis)
{
float3 radiance = DecodeRadiance(_RadianceCacheAxis[localIndex]);
float3 directionOS = _RayAxis[axis].xyz;
const float3x3 probeVolumeLtw = float3x3(_ProbeVolumeDGIBoundsRight, _ProbeVolumeDGIBoundsUp, cross(_ProbeVolumeDGIBoundsRight, _ProbeVolumeDGIBoundsUp));
float3 directionWS = mul(directionOS, probeVolumeLtw);
BasisAxisHit basisAxisHit = ComputeBasisAxisHit(directionOS, _Sharpness);
basisAxisHit.mean = directionWS; // Rotate the basis to world space after constructing it (because the construction can be dependant on the object space direction (i.e: diagonals with less energy)).
sampleIncomingRadiance += radiance * (ComputeBasisAxisHitEvaluateFromDirection(basisAxisHit, sampleDirectionWS) / basisAxisHit.amplitude);
localIndex += _ProbeVolumeAtlasReadBufferCount;
}
SHIncomingIrradianceAccumulate(incomingIrradiance, sampleDirectionWS, sampleIncomingRadiance * differentialArea);
}
return incomingIrradiance;
}
#define SH_FROM_RBF_MODE_MONTE_CARLO (0)
#define SH_FROM_RBF_MODE_SAMPLE_PEAKS (1)
#define SH_FROM_RBF_MODE_ZH_FIT (2)
// When projecting from our radial basis function into L2 spherical harmonics, because our RBF is higher frequency than an L2 SH, converting each lobe to a zonal harmonic first, rotating, and accumulated gives the closest results to our ground truth monte carlo.
// Simply accumulating the RBF lobe peaks as directional light sources gives less accurate, overly contrasty / overly sharp results when compared to our monte carlo ground truth.
#define SH_FROM_RBF_MODE SH_FROM_RBF_MODE_ZH_FIT
SHIncomingIrradiance ProjectPropagationAxisFromFit(uint probeIndex)
{
#if SH_FROM_RBF_MODE == SH_FROM_RBF_MODE_MONTE_CARLO
SHIncomingIrradiance incomingIrradiance = ComputeSHIncomingIrradianceFromRadialBasisFunctionWithMonteCarlo(probeIndex);
#elif SH_FROM_RBF_MODE == SH_FROM_RBF_MODE_SAMPLE_PEAKS
SHIncomingIrradiance incomingIrradiance = ComputeSHIncomingIrradianceFromRadialBasisFunctionWithSamplePeaks(probeIndex);
#elif SH_FROM_RBF_MODE == SH_FROM_RBF_MODE_ZH_FIT
SHIncomingIrradiance incomingIrradiance = ComputeSHIncomingIrradianceFromRadialBasisFunctionWithZHFit(probeIndex);
#endif
return incomingIrradiance;
}
SHIncomingIrradiance ProjectPropagationAxis(uint probeIndex)
{
return ProjectPropagationAxisFromFit(probeIndex);
}
[numthreads(GROUP_SIZE, 1, 1)]
void CombinePropagationAxis(uint3 id : SV_DispatchThreadID)
{
const uint readIndex = id.x;
if (readIndex < _ProbeVolumeAtlasReadBufferCount)
{
#ifndef DIRTY_FLAGS_DISABLED
if (!IsProbeDirty(_ProbeVolumeDirtyFlags, readIndex))
return;
#endif
uint3 writeIndex = ComputeWriteIndexFromReadIndex(readIndex, _ProbeVolumeResolution);
const float validity = ReadValidity(readIndex);
SHOutgoingRadiosityWithProjectedConstantsPacked bakedOutgoingRadiosityProjectedConstantsPacked = ReadBakedSH(readIndex);
SHIncomingIrradiance dynamicIncomingIrradiance = ProjectPropagationAxis(readIndex);
SHOutgoingRadiosity dynamicOutgoingRadiosity = SHOutgoingRadiosityComputeFromIncomingIrradiance(dynamicIncomingIrradiance);
SHOutgoingRadiosityWithProjectedConstants bakedOutgoingRadiosityProjectedConstants = SHOutgoingRadiosityWithProjectedConstantsCompute(bakedOutgoingRadiosityProjectedConstantsPacked);
SHOutgoingRadiosity bakedOutgoingRadiosity = SHOutgoingRadiosityCompute(bakedOutgoingRadiosityProjectedConstants);
const float3x3 probeVolumeAtlasSHRotate = float3x3(_ProbeVolumeAtlasSHRotateRight, _ProbeVolumeAtlasSHRotateUp, _ProbeVolumeAtlasSHRotateForward);
SHOutgoingRadiosityRotate(probeVolumeAtlasSHRotate, bakedOutgoingRadiosity); // rotate baked SH Data into absolute world space before it is combined with dynamic SH data in absolute world space
SHOutgoingRadiosityBlend(bakedOutgoingRadiosity, _BakedLightingContribution, dynamicOutgoingRadiosity, _DynamicPropagationContribution);
#if DERING_LUMINANCE_ONLY
//SHOutgoingRadiosityDeringLuminance(bakedOutgoingRadiosity);
#else
//SHOutgoingRadiosityDering(bakedOutgoingRadiosity);
#endif
bakedOutgoingRadiosityProjectedConstants = SHOutgoingRadiosityWithProjectedConstantsCompute(bakedOutgoingRadiosity);
bakedOutgoingRadiosityProjectedConstantsPacked = SHOutgoingRadiosityWithProjectedConstantsPackedCompute(bakedOutgoingRadiosityProjectedConstants);
WriteFinalSHOutgoingRadiosityWithProjectedConstantsPacked(writeIndex, bakedOutgoingRadiosityProjectedConstantsPacked, validity);
}
}