three-gpu-pathtracer 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +1004 -981
- package/build/index.module.js +7413 -6902
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +7446 -6933
- package/build/index.umd.cjs.map +1 -1
- package/package.json +73 -73
- package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
- package/src/core/MaterialReducer.js +256 -256
- package/src/core/PathTracingRenderer.js +346 -346
- package/src/core/PathTracingSceneGenerator.js +69 -69
- package/src/core/QuiltPathTracingRenderer.js +223 -223
- package/src/detectors/CompatibilityDetector.js +38 -0
- package/src/detectors/MaterialCompileDetector.js +50 -0
- package/src/detectors/PrecisionDetector.js +85 -0
- package/src/detectors/PrecisionMaterial.js +160 -0
- package/src/index.js +40 -36
- package/src/materials/MaterialBase.js +56 -56
- package/src/materials/debug/GraphMaterial.js +243 -243
- package/src/materials/fullscreen/AlphaDisplayMaterial.js +50 -48
- package/src/materials/fullscreen/BlendMaterial.js +67 -67
- package/src/materials/fullscreen/DenoiseMaterial.js +142 -142
- package/src/materials/fullscreen/GradientMapMaterial.js +82 -0
- package/src/materials/pathtracing/LambertPathTracingMaterial.js +296 -296
- package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +118 -196
- package/src/materials/pathtracing/glsl/attenuateHit.glsl.js +177 -179
- package/src/materials/pathtracing/glsl/cameraUtils.glsl.js +84 -81
- package/src/materials/pathtracing/glsl/directLightContribution.glsl.js +93 -0
- package/src/materials/pathtracing/glsl/getSurfaceRecord.glsl.js +323 -317
- package/src/materials/pathtracing/glsl/renderStructs.glsl.js +50 -0
- package/src/materials/pathtracing/glsl/traceScene.glsl.js +52 -54
- package/src/materials/surface/AmbientOcclusionMaterial.js +207 -207
- package/src/materials/surface/FogVolumeMaterial.js +23 -23
- package/src/objects/EquirectCamera.js +13 -13
- package/src/objects/PhysicalCamera.js +42 -28
- package/src/objects/PhysicalSpotLight.js +25 -14
- package/src/objects/ShapedAreaLight.js +22 -12
- package/src/shader/bsdf/bsdfSampling.glsl.js +499 -490
- package/src/shader/bsdf/fog.glsl.js +22 -23
- package/src/shader/bsdf/ggx.glsl.js +102 -102
- package/src/shader/bsdf/iridescence.glsl.js +135 -135
- package/src/shader/bsdf/sheen.glsl.js +98 -98
- package/src/shader/common/arraySamplerTexelFetch.glsl.js +25 -25
- package/src/shader/common/bvhAnyHit.glsl.js +76 -76
- package/src/shader/common/fresnel.glsl.js +98 -98
- package/src/shader/common/intersectShapes.glsl.js +62 -62
- package/src/shader/common/math.glsl.js +81 -81
- package/src/shader/common/utils.glsl.js +116 -116
- package/src/shader/rand/pcg.glsl.js +57 -57
- package/src/shader/rand/sobol.glsl.js +256 -256
- package/src/shader/sampling/equirectSampling.glsl.js +62 -62
- package/src/shader/sampling/lightSampling.glsl.js +223 -223
- package/src/shader/sampling/shapeSampling.glsl.js +86 -86
- package/src/shader/structs/cameraStruct.glsl.js +13 -13
- package/src/shader/structs/equirectStruct.glsl.js +13 -14
- package/src/shader/structs/fogMaterialBvh.glsl.js +62 -62
- package/src/shader/structs/lightsStruct.glsl.js +78 -78
- package/src/shader/structs/materialStruct.glsl.js +207 -207
- package/src/textures/GradientEquirectTexture.js +35 -35
- package/src/textures/ProceduralEquirectTexture.js +75 -75
- package/src/uniforms/AttributesTextureArray.js +35 -35
- package/src/uniforms/EquirectHdrInfoUniform.js +269 -277
- package/src/uniforms/FloatAttributeTextureArray.js +169 -169
- package/src/uniforms/IESProfilesTexture.js +100 -100
- package/src/uniforms/LightsInfoUniformStruct.js +212 -212
- package/src/uniforms/MaterialsTexture.js +503 -503
- package/src/uniforms/PhysicalCameraUniform.js +36 -36
- package/src/uniforms/RenderTarget2DArray.js +97 -97
- package/src/uniforms/utils.js +30 -30
- package/src/utils/BlurredEnvMapGenerator.js +116 -116
- package/src/utils/GeometryPreparationUtils.js +214 -214
- package/src/utils/IESLoader.js +325 -325
- package/src/utils/SobolNumberMapGenerator.js +80 -80
- package/src/utils/UVUnwrapper.js +101 -101
- package/src/utils/macroify.js +9 -9
- package/src/workers/PathTracingSceneWorker.js +42 -42
|
@@ -1,256 +1,256 @@
|
|
|
1
|
-
// References
|
|
2
|
-
// - https://jcgt.org/published/0009/04/01/
|
|
3
|
-
// - Code from https://www.shadertoy.com/view/WtGyDm
|
|
4
|
-
|
|
5
|
-
// functions to generate multi-dimensions variables of the same functions
|
|
6
|
-
// to support 1, 2, 3, and 4 dimensional sobol sampling.
|
|
7
|
-
function generateSobolFunctionVariants( dim = 1 ) {
|
|
8
|
-
|
|
9
|
-
let type = 'uint';
|
|
10
|
-
if ( dim > 1 ) {
|
|
11
|
-
|
|
12
|
-
type = 'uvec' + dim;
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return /* glsl */`
|
|
17
|
-
${ type } sobolReverseBits( ${ type } x ) {
|
|
18
|
-
|
|
19
|
-
x = ( ( ( x & 0xaaaaaaaau ) >> 1 ) | ( ( x & 0x55555555u ) << 1 ) );
|
|
20
|
-
x = ( ( ( x & 0xccccccccu ) >> 2 ) | ( ( x & 0x33333333u ) << 2 ) );
|
|
21
|
-
x = ( ( ( x & 0xf0f0f0f0u ) >> 4 ) | ( ( x & 0x0f0f0f0fu ) << 4 ) );
|
|
22
|
-
x = ( ( ( x & 0xff00ff00u ) >> 8 ) | ( ( x & 0x00ff00ffu ) << 8 ) );
|
|
23
|
-
return ( ( x >> 16 ) | ( x << 16 ) );
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
${ type } sobolHashCombine( uint seed, ${ type } v ) {
|
|
28
|
-
|
|
29
|
-
return seed ^ ( v + ${ type }( ( seed << 6 ) + ( seed >> 2 ) ) );
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
${ type } sobolLaineKarrasPermutation( ${ type } x, ${ type } seed ) {
|
|
34
|
-
|
|
35
|
-
x += seed;
|
|
36
|
-
x ^= x * 0x6c50b47cu;
|
|
37
|
-
x ^= x * 0xb82f1e52u;
|
|
38
|
-
x ^= x * 0xc7afe638u;
|
|
39
|
-
x ^= x * 0x8d22f6e6u;
|
|
40
|
-
return x;
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
${ type } nestedUniformScrambleBase2( ${ type } x, ${ type } seed ) {
|
|
45
|
-
|
|
46
|
-
x = sobolLaineKarrasPermutation( x, seed );
|
|
47
|
-
x = sobolReverseBits( x );
|
|
48
|
-
return x;
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
`;
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function generateSobolSampleFunctions( dim = 1 ) {
|
|
56
|
-
|
|
57
|
-
let utype = 'uint';
|
|
58
|
-
let vtype = 'float';
|
|
59
|
-
let num = '';
|
|
60
|
-
let components = '.r';
|
|
61
|
-
let combineValues = '1u';
|
|
62
|
-
if ( dim > 1 ) {
|
|
63
|
-
|
|
64
|
-
utype = 'uvec' + dim;
|
|
65
|
-
vtype = 'vec' + dim;
|
|
66
|
-
num = dim + '';
|
|
67
|
-
if ( dim === 2 ) {
|
|
68
|
-
|
|
69
|
-
components = '.rg';
|
|
70
|
-
combineValues = 'uvec2( 1u, 2u )';
|
|
71
|
-
|
|
72
|
-
} else if ( dim === 3 ) {
|
|
73
|
-
|
|
74
|
-
components = '.rgb';
|
|
75
|
-
combineValues = 'uvec3( 1u, 2u, 3u )';
|
|
76
|
-
|
|
77
|
-
} else {
|
|
78
|
-
|
|
79
|
-
components = '';
|
|
80
|
-
combineValues = 'uvec4( 1u, 2u, 3u, 4u )';
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return /* glsl */`
|
|
87
|
-
|
|
88
|
-
${ vtype } sobol${ num }( int effect ) {
|
|
89
|
-
|
|
90
|
-
uint seed = sobolGetSeed( sobolBounceIndex, uint( effect ) );
|
|
91
|
-
uint index = sobolPathIndex;
|
|
92
|
-
|
|
93
|
-
uint shuffle_seed = sobolHashCombine( seed, 0u );
|
|
94
|
-
uint shuffled_index = nestedUniformScrambleBase2( sobolReverseBits( index ), shuffle_seed );
|
|
95
|
-
${ vtype } sobol_pt = sobolGetTexturePoint( shuffled_index )${ components };
|
|
96
|
-
${ utype } result = ${ utype }( sobol_pt * 16777216.0 );
|
|
97
|
-
|
|
98
|
-
${ utype } seed2 = sobolHashCombine( seed, ${ combineValues } );
|
|
99
|
-
result = nestedUniformScrambleBase2( result, seed2 );
|
|
100
|
-
|
|
101
|
-
return SOBOL_FACTOR * ${ vtype }( result >> 8 );
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
`;
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export const sobolCommonGLSL = /* glsl */`
|
|
109
|
-
|
|
110
|
-
// Utils
|
|
111
|
-
const float SOBOL_FACTOR = 1.0 / 16777216.0;
|
|
112
|
-
const uint SOBOL_MAX_POINTS = 256u * 256u;
|
|
113
|
-
|
|
114
|
-
${ generateSobolFunctionVariants( 1 ) }
|
|
115
|
-
${ generateSobolFunctionVariants( 2 ) }
|
|
116
|
-
${ generateSobolFunctionVariants( 3 ) }
|
|
117
|
-
${ generateSobolFunctionVariants( 4 ) }
|
|
118
|
-
|
|
119
|
-
uint sobolHash( uint x ) {
|
|
120
|
-
|
|
121
|
-
// finalizer from murmurhash3
|
|
122
|
-
x ^= x >> 16;
|
|
123
|
-
x *= 0x85ebca6bu;
|
|
124
|
-
x ^= x >> 13;
|
|
125
|
-
x *= 0xc2b2ae35u;
|
|
126
|
-
x ^= x >> 16;
|
|
127
|
-
return x;
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
`;
|
|
132
|
-
|
|
133
|
-
export const sobolGenerationGLSL = /* glsl */`
|
|
134
|
-
|
|
135
|
-
const uint SOBOL_DIRECTIONS_1[ 32 ] = uint[ 32 ](
|
|
136
|
-
0x80000000u, 0xc0000000u, 0xa0000000u, 0xf0000000u,
|
|
137
|
-
0x88000000u, 0xcc000000u, 0xaa000000u, 0xff000000u,
|
|
138
|
-
0x80800000u, 0xc0c00000u, 0xa0a00000u, 0xf0f00000u,
|
|
139
|
-
0x88880000u, 0xcccc0000u, 0xaaaa0000u, 0xffff0000u,
|
|
140
|
-
0x80008000u, 0xc000c000u, 0xa000a000u, 0xf000f000u,
|
|
141
|
-
0x88008800u, 0xcc00cc00u, 0xaa00aa00u, 0xff00ff00u,
|
|
142
|
-
0x80808080u, 0xc0c0c0c0u, 0xa0a0a0a0u, 0xf0f0f0f0u,
|
|
143
|
-
0x88888888u, 0xccccccccu, 0xaaaaaaaau, 0xffffffffu
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const uint SOBOL_DIRECTIONS_2[ 32 ] = uint[ 32 ](
|
|
147
|
-
0x80000000u, 0xc0000000u, 0x60000000u, 0x90000000u,
|
|
148
|
-
0xe8000000u, 0x5c000000u, 0x8e000000u, 0xc5000000u,
|
|
149
|
-
0x68800000u, 0x9cc00000u, 0xee600000u, 0x55900000u,
|
|
150
|
-
0x80680000u, 0xc09c0000u, 0x60ee0000u, 0x90550000u,
|
|
151
|
-
0xe8808000u, 0x5cc0c000u, 0x8e606000u, 0xc5909000u,
|
|
152
|
-
0x6868e800u, 0x9c9c5c00u, 0xeeee8e00u, 0x5555c500u,
|
|
153
|
-
0x8000e880u, 0xc0005cc0u, 0x60008e60u, 0x9000c590u,
|
|
154
|
-
0xe8006868u, 0x5c009c9cu, 0x8e00eeeeu, 0xc5005555u
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
const uint SOBOL_DIRECTIONS_3[ 32 ] = uint[ 32 ](
|
|
158
|
-
0x80000000u, 0xc0000000u, 0x20000000u, 0x50000000u,
|
|
159
|
-
0xf8000000u, 0x74000000u, 0xa2000000u, 0x93000000u,
|
|
160
|
-
0xd8800000u, 0x25400000u, 0x59e00000u, 0xe6d00000u,
|
|
161
|
-
0x78080000u, 0xb40c0000u, 0x82020000u, 0xc3050000u,
|
|
162
|
-
0x208f8000u, 0x51474000u, 0xfbea2000u, 0x75d93000u,
|
|
163
|
-
0xa0858800u, 0x914e5400u, 0xdbe79e00u, 0x25db6d00u,
|
|
164
|
-
0x58800080u, 0xe54000c0u, 0x79e00020u, 0xb6d00050u,
|
|
165
|
-
0x800800f8u, 0xc00c0074u, 0x200200a2u, 0x50050093u
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
const uint SOBOL_DIRECTIONS_4[ 32 ] = uint[ 32 ](
|
|
169
|
-
0x80000000u, 0x40000000u, 0x20000000u, 0xb0000000u,
|
|
170
|
-
0xf8000000u, 0xdc000000u, 0x7a000000u, 0x9d000000u,
|
|
171
|
-
0x5a800000u, 0x2fc00000u, 0xa1600000u, 0xf0b00000u,
|
|
172
|
-
0xda880000u, 0x6fc40000u, 0x81620000u, 0x40bb0000u,
|
|
173
|
-
0x22878000u, 0xb3c9c000u, 0xfb65a000u, 0xddb2d000u,
|
|
174
|
-
0x78022800u, 0x9c0b3c00u, 0x5a0fb600u, 0x2d0ddb00u,
|
|
175
|
-
0xa2878080u, 0xf3c9c040u, 0xdb65a020u, 0x6db2d0b0u,
|
|
176
|
-
0x800228f8u, 0x400b3cdcu, 0x200fb67au, 0xb00ddb9du
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
uint getMaskedSobol( uint index, uint directions[ 32 ] ) {
|
|
180
|
-
|
|
181
|
-
uint X = 0u;
|
|
182
|
-
for ( int bit = 0; bit < 32; bit ++ ) {
|
|
183
|
-
|
|
184
|
-
uint mask = ( index >> bit ) & 1u;
|
|
185
|
-
X ^= mask * directions[ bit ];
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
return X;
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
vec4 generateSobolPoint( uint index ) {
|
|
193
|
-
|
|
194
|
-
if ( index >= SOBOL_MAX_POINTS ) {
|
|
195
|
-
|
|
196
|
-
return vec4( 0.0 );
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// NOTEL this sobol "direction" is also available but we can't write out 5 components
|
|
201
|
-
// uint x = index & 0x00ffffffu;
|
|
202
|
-
uint x = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_1 ) ) & 0x00ffffffu;
|
|
203
|
-
uint y = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_2 ) ) & 0x00ffffffu;
|
|
204
|
-
uint z = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_3 ) ) & 0x00ffffffu;
|
|
205
|
-
uint w = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_4 ) ) & 0x00ffffffu;
|
|
206
|
-
|
|
207
|
-
return vec4( x, y, z, w ) * SOBOL_FACTOR;
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
`;
|
|
212
|
-
|
|
213
|
-
export const sobolSamplingGLSL = /* glsl */`
|
|
214
|
-
|
|
215
|
-
// Seeds
|
|
216
|
-
uniform sampler2D sobolTexture;
|
|
217
|
-
uint sobolPixelIndex;
|
|
218
|
-
uint sobolPathIndex;
|
|
219
|
-
uint sobolBounceIndex;
|
|
220
|
-
|
|
221
|
-
uint sobolGetSeed( uint bounce, uint effect ) {
|
|
222
|
-
|
|
223
|
-
return sobolHash(
|
|
224
|
-
sobolHashCombine(
|
|
225
|
-
sobolHashCombine(
|
|
226
|
-
sobolHash( bounce ),
|
|
227
|
-
sobolPixelIndex
|
|
228
|
-
),
|
|
229
|
-
effect
|
|
230
|
-
)
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
vec4 sobolGetTexturePoint( uint index ) {
|
|
236
|
-
|
|
237
|
-
if ( index >= SOBOL_MAX_POINTS ) {
|
|
238
|
-
|
|
239
|
-
index = index % SOBOL_MAX_POINTS;
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
uvec2 dim = uvec2( textureSize( sobolTexture, 0 ).xy );
|
|
244
|
-
uint y = index / dim.x;
|
|
245
|
-
uint x = index - y * dim.x;
|
|
246
|
-
vec2 uv = vec2( x, y ) / vec2( dim );
|
|
247
|
-
return texture( sobolTexture, uv );
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
${ generateSobolSampleFunctions( 1 ) }
|
|
252
|
-
${ generateSobolSampleFunctions( 2 ) }
|
|
253
|
-
${ generateSobolSampleFunctions( 3 ) }
|
|
254
|
-
${ generateSobolSampleFunctions( 4 ) }
|
|
255
|
-
|
|
256
|
-
`;
|
|
1
|
+
// References
|
|
2
|
+
// - https://jcgt.org/published/0009/04/01/
|
|
3
|
+
// - Code from https://www.shadertoy.com/view/WtGyDm
|
|
4
|
+
|
|
5
|
+
// functions to generate multi-dimensions variables of the same functions
|
|
6
|
+
// to support 1, 2, 3, and 4 dimensional sobol sampling.
|
|
7
|
+
function generateSobolFunctionVariants( dim = 1 ) {
|
|
8
|
+
|
|
9
|
+
let type = 'uint';
|
|
10
|
+
if ( dim > 1 ) {
|
|
11
|
+
|
|
12
|
+
type = 'uvec' + dim;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return /* glsl */`
|
|
17
|
+
${ type } sobolReverseBits( ${ type } x ) {
|
|
18
|
+
|
|
19
|
+
x = ( ( ( x & 0xaaaaaaaau ) >> 1 ) | ( ( x & 0x55555555u ) << 1 ) );
|
|
20
|
+
x = ( ( ( x & 0xccccccccu ) >> 2 ) | ( ( x & 0x33333333u ) << 2 ) );
|
|
21
|
+
x = ( ( ( x & 0xf0f0f0f0u ) >> 4 ) | ( ( x & 0x0f0f0f0fu ) << 4 ) );
|
|
22
|
+
x = ( ( ( x & 0xff00ff00u ) >> 8 ) | ( ( x & 0x00ff00ffu ) << 8 ) );
|
|
23
|
+
return ( ( x >> 16 ) | ( x << 16 ) );
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
${ type } sobolHashCombine( uint seed, ${ type } v ) {
|
|
28
|
+
|
|
29
|
+
return seed ^ ( v + ${ type }( ( seed << 6 ) + ( seed >> 2 ) ) );
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
${ type } sobolLaineKarrasPermutation( ${ type } x, ${ type } seed ) {
|
|
34
|
+
|
|
35
|
+
x += seed;
|
|
36
|
+
x ^= x * 0x6c50b47cu;
|
|
37
|
+
x ^= x * 0xb82f1e52u;
|
|
38
|
+
x ^= x * 0xc7afe638u;
|
|
39
|
+
x ^= x * 0x8d22f6e6u;
|
|
40
|
+
return x;
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
${ type } nestedUniformScrambleBase2( ${ type } x, ${ type } seed ) {
|
|
45
|
+
|
|
46
|
+
x = sobolLaineKarrasPermutation( x, seed );
|
|
47
|
+
x = sobolReverseBits( x );
|
|
48
|
+
return x;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function generateSobolSampleFunctions( dim = 1 ) {
|
|
56
|
+
|
|
57
|
+
let utype = 'uint';
|
|
58
|
+
let vtype = 'float';
|
|
59
|
+
let num = '';
|
|
60
|
+
let components = '.r';
|
|
61
|
+
let combineValues = '1u';
|
|
62
|
+
if ( dim > 1 ) {
|
|
63
|
+
|
|
64
|
+
utype = 'uvec' + dim;
|
|
65
|
+
vtype = 'vec' + dim;
|
|
66
|
+
num = dim + '';
|
|
67
|
+
if ( dim === 2 ) {
|
|
68
|
+
|
|
69
|
+
components = '.rg';
|
|
70
|
+
combineValues = 'uvec2( 1u, 2u )';
|
|
71
|
+
|
|
72
|
+
} else if ( dim === 3 ) {
|
|
73
|
+
|
|
74
|
+
components = '.rgb';
|
|
75
|
+
combineValues = 'uvec3( 1u, 2u, 3u )';
|
|
76
|
+
|
|
77
|
+
} else {
|
|
78
|
+
|
|
79
|
+
components = '';
|
|
80
|
+
combineValues = 'uvec4( 1u, 2u, 3u, 4u )';
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return /* glsl */`
|
|
87
|
+
|
|
88
|
+
${ vtype } sobol${ num }( int effect ) {
|
|
89
|
+
|
|
90
|
+
uint seed = sobolGetSeed( sobolBounceIndex, uint( effect ) );
|
|
91
|
+
uint index = sobolPathIndex;
|
|
92
|
+
|
|
93
|
+
uint shuffle_seed = sobolHashCombine( seed, 0u );
|
|
94
|
+
uint shuffled_index = nestedUniformScrambleBase2( sobolReverseBits( index ), shuffle_seed );
|
|
95
|
+
${ vtype } sobol_pt = sobolGetTexturePoint( shuffled_index )${ components };
|
|
96
|
+
${ utype } result = ${ utype }( sobol_pt * 16777216.0 );
|
|
97
|
+
|
|
98
|
+
${ utype } seed2 = sobolHashCombine( seed, ${ combineValues } );
|
|
99
|
+
result = nestedUniformScrambleBase2( result, seed2 );
|
|
100
|
+
|
|
101
|
+
return SOBOL_FACTOR * ${ vtype }( result >> 8 );
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const sobolCommonGLSL = /* glsl */`
|
|
109
|
+
|
|
110
|
+
// Utils
|
|
111
|
+
const float SOBOL_FACTOR = 1.0 / 16777216.0;
|
|
112
|
+
const uint SOBOL_MAX_POINTS = 256u * 256u;
|
|
113
|
+
|
|
114
|
+
${ generateSobolFunctionVariants( 1 ) }
|
|
115
|
+
${ generateSobolFunctionVariants( 2 ) }
|
|
116
|
+
${ generateSobolFunctionVariants( 3 ) }
|
|
117
|
+
${ generateSobolFunctionVariants( 4 ) }
|
|
118
|
+
|
|
119
|
+
uint sobolHash( uint x ) {
|
|
120
|
+
|
|
121
|
+
// finalizer from murmurhash3
|
|
122
|
+
x ^= x >> 16;
|
|
123
|
+
x *= 0x85ebca6bu;
|
|
124
|
+
x ^= x >> 13;
|
|
125
|
+
x *= 0xc2b2ae35u;
|
|
126
|
+
x ^= x >> 16;
|
|
127
|
+
return x;
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
`;
|
|
132
|
+
|
|
133
|
+
export const sobolGenerationGLSL = /* glsl */`
|
|
134
|
+
|
|
135
|
+
const uint SOBOL_DIRECTIONS_1[ 32 ] = uint[ 32 ](
|
|
136
|
+
0x80000000u, 0xc0000000u, 0xa0000000u, 0xf0000000u,
|
|
137
|
+
0x88000000u, 0xcc000000u, 0xaa000000u, 0xff000000u,
|
|
138
|
+
0x80800000u, 0xc0c00000u, 0xa0a00000u, 0xf0f00000u,
|
|
139
|
+
0x88880000u, 0xcccc0000u, 0xaaaa0000u, 0xffff0000u,
|
|
140
|
+
0x80008000u, 0xc000c000u, 0xa000a000u, 0xf000f000u,
|
|
141
|
+
0x88008800u, 0xcc00cc00u, 0xaa00aa00u, 0xff00ff00u,
|
|
142
|
+
0x80808080u, 0xc0c0c0c0u, 0xa0a0a0a0u, 0xf0f0f0f0u,
|
|
143
|
+
0x88888888u, 0xccccccccu, 0xaaaaaaaau, 0xffffffffu
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const uint SOBOL_DIRECTIONS_2[ 32 ] = uint[ 32 ](
|
|
147
|
+
0x80000000u, 0xc0000000u, 0x60000000u, 0x90000000u,
|
|
148
|
+
0xe8000000u, 0x5c000000u, 0x8e000000u, 0xc5000000u,
|
|
149
|
+
0x68800000u, 0x9cc00000u, 0xee600000u, 0x55900000u,
|
|
150
|
+
0x80680000u, 0xc09c0000u, 0x60ee0000u, 0x90550000u,
|
|
151
|
+
0xe8808000u, 0x5cc0c000u, 0x8e606000u, 0xc5909000u,
|
|
152
|
+
0x6868e800u, 0x9c9c5c00u, 0xeeee8e00u, 0x5555c500u,
|
|
153
|
+
0x8000e880u, 0xc0005cc0u, 0x60008e60u, 0x9000c590u,
|
|
154
|
+
0xe8006868u, 0x5c009c9cu, 0x8e00eeeeu, 0xc5005555u
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const uint SOBOL_DIRECTIONS_3[ 32 ] = uint[ 32 ](
|
|
158
|
+
0x80000000u, 0xc0000000u, 0x20000000u, 0x50000000u,
|
|
159
|
+
0xf8000000u, 0x74000000u, 0xa2000000u, 0x93000000u,
|
|
160
|
+
0xd8800000u, 0x25400000u, 0x59e00000u, 0xe6d00000u,
|
|
161
|
+
0x78080000u, 0xb40c0000u, 0x82020000u, 0xc3050000u,
|
|
162
|
+
0x208f8000u, 0x51474000u, 0xfbea2000u, 0x75d93000u,
|
|
163
|
+
0xa0858800u, 0x914e5400u, 0xdbe79e00u, 0x25db6d00u,
|
|
164
|
+
0x58800080u, 0xe54000c0u, 0x79e00020u, 0xb6d00050u,
|
|
165
|
+
0x800800f8u, 0xc00c0074u, 0x200200a2u, 0x50050093u
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const uint SOBOL_DIRECTIONS_4[ 32 ] = uint[ 32 ](
|
|
169
|
+
0x80000000u, 0x40000000u, 0x20000000u, 0xb0000000u,
|
|
170
|
+
0xf8000000u, 0xdc000000u, 0x7a000000u, 0x9d000000u,
|
|
171
|
+
0x5a800000u, 0x2fc00000u, 0xa1600000u, 0xf0b00000u,
|
|
172
|
+
0xda880000u, 0x6fc40000u, 0x81620000u, 0x40bb0000u,
|
|
173
|
+
0x22878000u, 0xb3c9c000u, 0xfb65a000u, 0xddb2d000u,
|
|
174
|
+
0x78022800u, 0x9c0b3c00u, 0x5a0fb600u, 0x2d0ddb00u,
|
|
175
|
+
0xa2878080u, 0xf3c9c040u, 0xdb65a020u, 0x6db2d0b0u,
|
|
176
|
+
0x800228f8u, 0x400b3cdcu, 0x200fb67au, 0xb00ddb9du
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
uint getMaskedSobol( uint index, uint directions[ 32 ] ) {
|
|
180
|
+
|
|
181
|
+
uint X = 0u;
|
|
182
|
+
for ( int bit = 0; bit < 32; bit ++ ) {
|
|
183
|
+
|
|
184
|
+
uint mask = ( index >> bit ) & 1u;
|
|
185
|
+
X ^= mask * directions[ bit ];
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
return X;
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
vec4 generateSobolPoint( uint index ) {
|
|
193
|
+
|
|
194
|
+
if ( index >= SOBOL_MAX_POINTS ) {
|
|
195
|
+
|
|
196
|
+
return vec4( 0.0 );
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// NOTEL this sobol "direction" is also available but we can't write out 5 components
|
|
201
|
+
// uint x = index & 0x00ffffffu;
|
|
202
|
+
uint x = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_1 ) ) & 0x00ffffffu;
|
|
203
|
+
uint y = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_2 ) ) & 0x00ffffffu;
|
|
204
|
+
uint z = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_3 ) ) & 0x00ffffffu;
|
|
205
|
+
uint w = sobolReverseBits( getMaskedSobol( index, SOBOL_DIRECTIONS_4 ) ) & 0x00ffffffu;
|
|
206
|
+
|
|
207
|
+
return vec4( x, y, z, w ) * SOBOL_FACTOR;
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
`;
|
|
212
|
+
|
|
213
|
+
export const sobolSamplingGLSL = /* glsl */`
|
|
214
|
+
|
|
215
|
+
// Seeds
|
|
216
|
+
uniform sampler2D sobolTexture;
|
|
217
|
+
uint sobolPixelIndex;
|
|
218
|
+
uint sobolPathIndex;
|
|
219
|
+
uint sobolBounceIndex;
|
|
220
|
+
|
|
221
|
+
uint sobolGetSeed( uint bounce, uint effect ) {
|
|
222
|
+
|
|
223
|
+
return sobolHash(
|
|
224
|
+
sobolHashCombine(
|
|
225
|
+
sobolHashCombine(
|
|
226
|
+
sobolHash( bounce ),
|
|
227
|
+
sobolPixelIndex
|
|
228
|
+
),
|
|
229
|
+
effect
|
|
230
|
+
)
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
vec4 sobolGetTexturePoint( uint index ) {
|
|
236
|
+
|
|
237
|
+
if ( index >= SOBOL_MAX_POINTS ) {
|
|
238
|
+
|
|
239
|
+
index = index % SOBOL_MAX_POINTS;
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
uvec2 dim = uvec2( textureSize( sobolTexture, 0 ).xy );
|
|
244
|
+
uint y = index / dim.x;
|
|
245
|
+
uint x = index - y * dim.x;
|
|
246
|
+
vec2 uv = vec2( x, y ) / vec2( dim );
|
|
247
|
+
return texture( sobolTexture, uv );
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
${ generateSobolSampleFunctions( 1 ) }
|
|
252
|
+
${ generateSobolSampleFunctions( 2 ) }
|
|
253
|
+
${ generateSobolSampleFunctions( 3 ) }
|
|
254
|
+
${ generateSobolSampleFunctions( 4 ) }
|
|
255
|
+
|
|
256
|
+
`;
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
export const equirectSamplingGLSL = /* glsl */`
|
|
2
|
-
|
|
3
|
-
// samples the the given environment map in the given direction
|
|
4
|
-
vec3 sampleEquirectColor( sampler2D envMap, vec3 direction ) {
|
|
5
|
-
|
|
6
|
-
return texture2D( envMap, equirectDirectionToUv( direction ) ).rgb;
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// gets the pdf of the given direction to sample
|
|
11
|
-
float equirectDirectionPdf( vec3 direction ) {
|
|
12
|
-
|
|
13
|
-
vec2 uv = equirectDirectionToUv( direction );
|
|
14
|
-
float theta = uv.y * PI;
|
|
15
|
-
float sinTheta = sin( theta );
|
|
16
|
-
if ( sinTheta == 0.0 ) {
|
|
17
|
-
|
|
18
|
-
return 0.0;
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return 1.0 / ( 2.0 * PI * PI * sinTheta );
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// samples the color given env map with CDF and returns the pdf of the direction
|
|
27
|
-
float sampleEquirect( EquirectHdrInfo info, vec3 direction, out vec3 color ) {
|
|
28
|
-
|
|
29
|
-
vec2 uv = equirectDirectionToUv( direction );
|
|
30
|
-
color = texture2D( info.map, uv ).rgb;
|
|
31
|
-
|
|
32
|
-
float totalSum = info.
|
|
33
|
-
float lum = luminance( color );
|
|
34
|
-
ivec2 resolution = textureSize( info.map, 0 );
|
|
35
|
-
float pdf = lum / totalSum;
|
|
36
|
-
|
|
37
|
-
return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// samples a direction of the envmap with color and retrieves pdf
|
|
42
|
-
float sampleEquirectProbability( EquirectHdrInfo info, vec2 r, out vec3 color, out vec3 direction ) {
|
|
43
|
-
|
|
44
|
-
// sample env map cdf
|
|
45
|
-
float v = texture2D( info.marginalWeights, vec2( r.x, 0.0 ) ).x;
|
|
46
|
-
float u = texture2D( info.conditionalWeights, vec2( r.y, v ) ).x;
|
|
47
|
-
vec2 uv = vec2( u, v );
|
|
48
|
-
|
|
49
|
-
vec3 derivedDirection = equirectUvToDirection( uv );
|
|
50
|
-
direction = derivedDirection;
|
|
51
|
-
color = texture2D( info.map, uv ).rgb;
|
|
52
|
-
|
|
53
|
-
float totalSum = info.
|
|
54
|
-
float lum = luminance( color );
|
|
55
|
-
ivec2 resolution = textureSize( info.map, 0 );
|
|
56
|
-
float pdf = lum / totalSum;
|
|
57
|
-
|
|
58
|
-
return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
`;
|
|
1
|
+
export const equirectSamplingGLSL = /* glsl */`
|
|
2
|
+
|
|
3
|
+
// samples the the given environment map in the given direction
|
|
4
|
+
vec3 sampleEquirectColor( sampler2D envMap, vec3 direction ) {
|
|
5
|
+
|
|
6
|
+
return texture2D( envMap, equirectDirectionToUv( direction ) ).rgb;
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// gets the pdf of the given direction to sample
|
|
11
|
+
float equirectDirectionPdf( vec3 direction ) {
|
|
12
|
+
|
|
13
|
+
vec2 uv = equirectDirectionToUv( direction );
|
|
14
|
+
float theta = uv.y * PI;
|
|
15
|
+
float sinTheta = sin( theta );
|
|
16
|
+
if ( sinTheta == 0.0 ) {
|
|
17
|
+
|
|
18
|
+
return 0.0;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return 1.0 / ( 2.0 * PI * PI * sinTheta );
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// samples the color given env map with CDF and returns the pdf of the direction
|
|
27
|
+
float sampleEquirect( EquirectHdrInfo info, vec3 direction, out vec3 color ) {
|
|
28
|
+
|
|
29
|
+
vec2 uv = equirectDirectionToUv( direction );
|
|
30
|
+
color = texture2D( info.map, uv ).rgb;
|
|
31
|
+
|
|
32
|
+
float totalSum = info.totalSum;
|
|
33
|
+
float lum = luminance( color );
|
|
34
|
+
ivec2 resolution = textureSize( info.map, 0 );
|
|
35
|
+
float pdf = lum / totalSum;
|
|
36
|
+
|
|
37
|
+
return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// samples a direction of the envmap with color and retrieves pdf
|
|
42
|
+
float sampleEquirectProbability( EquirectHdrInfo info, vec2 r, out vec3 color, out vec3 direction ) {
|
|
43
|
+
|
|
44
|
+
// sample env map cdf
|
|
45
|
+
float v = texture2D( info.marginalWeights, vec2( r.x, 0.0 ) ).x;
|
|
46
|
+
float u = texture2D( info.conditionalWeights, vec2( r.y, v ) ).x;
|
|
47
|
+
vec2 uv = vec2( u, v );
|
|
48
|
+
|
|
49
|
+
vec3 derivedDirection = equirectUvToDirection( uv );
|
|
50
|
+
direction = derivedDirection;
|
|
51
|
+
color = texture2D( info.map, uv ).rgb;
|
|
52
|
+
|
|
53
|
+
float totalSum = info.totalSum;
|
|
54
|
+
float lum = luminance( color );
|
|
55
|
+
ivec2 resolution = textureSize( info.map, 0 );
|
|
56
|
+
float pdf = lum / totalSum;
|
|
57
|
+
|
|
58
|
+
return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
`;
|