three-gpu-pathtracer 0.0.11 → 0.0.12

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.
Files changed (53) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +886 -886
  3. package/build/index.module.js +6478 -6470
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +6473 -6465
  6. package/build/index.umd.cjs.map +1 -1
  7. package/package.json +72 -69
  8. package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
  9. package/src/core/MaterialReducer.js +256 -256
  10. package/src/core/PathTracingRenderer.js +275 -275
  11. package/src/core/PathTracingSceneGenerator.js +69 -69
  12. package/src/index.js +39 -39
  13. package/src/materials/AlphaDisplayMaterial.js +48 -48
  14. package/src/materials/AmbientOcclusionMaterial.js +199 -199
  15. package/src/materials/BlendMaterial.js +67 -67
  16. package/src/materials/DenoiseMaterial.js +142 -142
  17. package/src/materials/GraphMaterial.js +243 -243
  18. package/src/materials/LambertPathTracingMaterial.js +285 -285
  19. package/src/materials/MaterialBase.js +56 -56
  20. package/src/materials/PhysicalPathTracingMaterial.js +982 -982
  21. package/src/objects/EquirectCamera.js +13 -13
  22. package/src/objects/PhysicalCamera.js +28 -28
  23. package/src/objects/PhysicalSpotLight.js +14 -14
  24. package/src/objects/ShapedAreaLight.js +12 -12
  25. package/src/shader/shaderBvhAnyHit.js +76 -0
  26. package/src/shader/shaderEnvMapSampling.js +58 -58
  27. package/src/shader/shaderGGXFunctions.js +100 -100
  28. package/src/shader/shaderIridescenceFunctions.js +130 -130
  29. package/src/shader/shaderLayerTexelFetchFunctions.js +25 -25
  30. package/src/shader/shaderLightSampling.js +229 -229
  31. package/src/shader/shaderMaterialSampling.js +506 -498
  32. package/src/shader/shaderRandFunctions.js +57 -57
  33. package/src/shader/shaderSheenFunctions.js +98 -98
  34. package/src/shader/shaderSobolSampling.js +256 -256
  35. package/src/shader/shaderStructs.js +325 -325
  36. package/src/shader/shaderUtils.js +361 -361
  37. package/src/textures/GradientEquirectTexture.js +35 -35
  38. package/src/textures/ProceduralEquirectTexture.js +75 -75
  39. package/src/uniforms/AttributesTextureArray.js +35 -35
  40. package/src/uniforms/EquirectHdrInfoUniform.js +259 -259
  41. package/src/uniforms/FloatAttributeTextureArray.js +169 -169
  42. package/src/uniforms/IESProfilesTexture.js +100 -100
  43. package/src/uniforms/LightsInfoUniformStruct.js +207 -207
  44. package/src/uniforms/MaterialsTexture.js +426 -426
  45. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  46. package/src/uniforms/RenderTarget2DArray.js +97 -97
  47. package/src/uniforms/utils.js +30 -30
  48. package/src/utils/BlurredEnvMapGenerator.js +116 -116
  49. package/src/utils/GeometryPreparationUtils.js +214 -214
  50. package/src/utils/IESLoader.js +325 -325
  51. package/src/utils/SobolNumberMapGenerator.js +80 -80
  52. package/src/utils/UVUnwrapper.js +101 -101
  53. 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 shaderSobolCommon = /* 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 shaderSobolGeneration = /* 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 shaderSobolSampling = /* 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 shaderSobolCommon = /* 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 shaderSobolGeneration = /* 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 shaderSobolSampling = /* 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
+ `;