three-gpu-pathtracer 0.0.7 → 0.0.9
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 +886 -815
- package/build/index.module.js +6374 -5613
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +6377 -5615
- package/build/index.umd.cjs.map +1 -1
- package/package.json +69 -68
- package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
- package/src/core/MaterialReducer.js +256 -256
- package/src/core/PathTracingRenderer.js +275 -270
- package/src/core/PathTracingSceneGenerator.js +1 -1
- package/src/index.js +39 -35
- package/src/materials/AlphaDisplayMaterial.js +48 -48
- package/src/materials/AmbientOcclusionMaterial.js +199 -197
- package/src/materials/BlendMaterial.js +67 -67
- package/src/materials/DenoiseMaterial.js +142 -142
- package/src/materials/GraphMaterial.js +243 -243
- package/src/materials/LambertPathTracingMaterial.js +285 -285
- package/src/materials/MaterialBase.js +56 -56
- package/src/materials/PhysicalPathTracingMaterial.js +982 -970
- package/src/objects/EquirectCamera.js +13 -13
- package/src/objects/PhysicalCamera.js +28 -28
- package/src/objects/PhysicalSpotLight.js +14 -14
- package/src/objects/ShapedAreaLight.js +12 -12
- package/src/shader/shaderEnvMapSampling.js +58 -59
- package/src/shader/shaderGGXFunctions.js +100 -100
- package/src/shader/shaderIridescenceFunctions.js +130 -130
- package/src/shader/shaderLayerTexelFetchFunctions.js +25 -0
- package/src/shader/shaderLightSampling.js +229 -231
- package/src/shader/shaderMaterialSampling.js +498 -542
- package/src/shader/shaderRandFunctions.js +57 -0
- package/src/shader/shaderSheenFunctions.js +98 -98
- package/src/shader/shaderSobolSampling.js +256 -0
- package/src/shader/shaderStructs.js +325 -321
- package/src/shader/shaderUtils.js +361 -364
- package/src/textures/GradientEquirectTexture.js +35 -0
- package/src/textures/ProceduralEquirectTexture.js +75 -0
- package/src/uniforms/AttributesTextureArray.js +35 -0
- package/src/uniforms/EquirectHdrInfoUniform.js +259 -259
- package/src/uniforms/FloatAttributeTextureArray.js +169 -0
- package/src/uniforms/IESProfilesTexture.js +100 -100
- package/src/uniforms/LightsInfoUniformStruct.js +207 -162
- package/src/uniforms/MaterialsTexture.js +426 -426
- package/src/uniforms/PhysicalCameraUniform.js +36 -36
- package/src/uniforms/RenderTarget2DArray.js +97 -93
- package/src/uniforms/utils.js +30 -0
- package/src/utils/BlurredEnvMapGenerator.js +116 -113
- package/src/utils/IESLoader.js +325 -325
- package/src/utils/SobolNumberMapGenerator.js +80 -0
- package/src/utils/UVUnwrapper.js +101 -101
- package/src/workers/PathTracingSceneWorker.js +42 -42
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const shaderRandFunctions = /* glsl */`
|
|
2
|
+
|
|
3
|
+
// https://www.shadertoy.com/view/wltcRS
|
|
4
|
+
uvec4 WHITE_NOISE_SEED;
|
|
5
|
+
|
|
6
|
+
void rng_initialize( vec2 p, int frame ) {
|
|
7
|
+
|
|
8
|
+
// white noise seed
|
|
9
|
+
WHITE_NOISE_SEED = uvec4( p, uint( frame ), uint( p.x ) + uint( p.y ) );
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// https://www.pcg-random.org/
|
|
14
|
+
void pcg4d( inout uvec4 v ) {
|
|
15
|
+
|
|
16
|
+
v = v * 1664525u + 1013904223u;
|
|
17
|
+
v.x += v.y * v.w;
|
|
18
|
+
v.y += v.z * v.x;
|
|
19
|
+
v.z += v.x * v.y;
|
|
20
|
+
v.w += v.y * v.z;
|
|
21
|
+
v = v ^ ( v >> 16u );
|
|
22
|
+
v.x += v.y*v.w;
|
|
23
|
+
v.y += v.z*v.x;
|
|
24
|
+
v.z += v.x*v.y;
|
|
25
|
+
v.w += v.y*v.z;
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// returns [ 0, 1 ]
|
|
30
|
+
float rand() {
|
|
31
|
+
|
|
32
|
+
pcg4d( WHITE_NOISE_SEED );
|
|
33
|
+
return float( WHITE_NOISE_SEED.x ) / float( 0xffffffffu );
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
vec2 rand2() {
|
|
38
|
+
|
|
39
|
+
pcg4d( WHITE_NOISE_SEED );
|
|
40
|
+
return vec2( WHITE_NOISE_SEED.xy ) / float(0xffffffffu);
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
vec3 rand3() {
|
|
45
|
+
|
|
46
|
+
pcg4d( WHITE_NOISE_SEED );
|
|
47
|
+
return vec3( WHITE_NOISE_SEED.xyz ) / float( 0xffffffffu );
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
vec4 rand4() {
|
|
52
|
+
|
|
53
|
+
pcg4d( WHITE_NOISE_SEED );
|
|
54
|
+
return vec4( WHITE_NOISE_SEED ) / float( 0xffffffffu );
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
`;
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
export const shaderSheenFunctions = /* glsl */`
|
|
2
|
-
|
|
3
|
-
// See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
4
|
-
float velvetD( float cosThetaH, float roughness ) {
|
|
5
|
-
|
|
6
|
-
float alpha = max( roughness, 0.07 );
|
|
7
|
-
alpha = alpha * alpha;
|
|
8
|
-
|
|
9
|
-
float invAlpha = 1.0 / alpha;
|
|
10
|
-
|
|
11
|
-
float sqrCosThetaH = cosThetaH * cosThetaH;
|
|
12
|
-
float sinThetaH = max( 1.0 - sqrCosThetaH, 0.001 );
|
|
13
|
-
|
|
14
|
-
return ( 2.0 + invAlpha ) * pow( sinThetaH, 0.5 * invAlpha ) / ( 2.0 * PI );
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
float velvetParamsInterpolate( int i, float oneMinusAlphaSquared ) {
|
|
19
|
-
|
|
20
|
-
const float p0[5] = float[5]( 25.3245, 3.32435, 0.16801, -1.27393, -4.85967 );
|
|
21
|
-
const float p1[5] = float[5]( 21.5473, 3.82987, 0.19823, -1.97760, -4.32054 );
|
|
22
|
-
|
|
23
|
-
return mix( p1[i], p0[i], oneMinusAlphaSquared );
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
float velvetL( float x, float alpha ) {
|
|
28
|
-
|
|
29
|
-
float oneMinusAlpha = 1.0 - alpha;
|
|
30
|
-
float oneMinusAlphaSquared = oneMinusAlpha * oneMinusAlpha;
|
|
31
|
-
|
|
32
|
-
float a = velvetParamsInterpolate( 0, oneMinusAlphaSquared );
|
|
33
|
-
float b = velvetParamsInterpolate( 1, oneMinusAlphaSquared );
|
|
34
|
-
float c = velvetParamsInterpolate( 2, oneMinusAlphaSquared );
|
|
35
|
-
float d = velvetParamsInterpolate( 3, oneMinusAlphaSquared );
|
|
36
|
-
float e = velvetParamsInterpolate( 4, oneMinusAlphaSquared );
|
|
37
|
-
|
|
38
|
-
return a / ( 1.0 + b * pow( abs( x ), c ) ) + d * x + e;
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// See equation (3) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
43
|
-
float velvetLambda( float cosTheta, float alpha ) {
|
|
44
|
-
|
|
45
|
-
return abs( cosTheta ) < 0.5 ? exp( velvetL( cosTheta, alpha ) ) : exp( 2.0 * velvetL( 0.5, alpha ) - velvetL( 1.0 - cosTheta, alpha ) );
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// See Section 3, Shadowing Term, in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
50
|
-
float velvetG( float cosThetaO, float cosThetaI, float roughness ) {
|
|
51
|
-
|
|
52
|
-
float alpha = max( roughness, 0.07 );
|
|
53
|
-
alpha = alpha * alpha;
|
|
54
|
-
|
|
55
|
-
return 1.0 / ( 1.0 + velvetLambda( cosThetaO, alpha ) + velvetLambda( cosThetaI, alpha ) );
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
float directionalAlbedoSheen( float cosTheta, float alpha ) {
|
|
60
|
-
|
|
61
|
-
cosTheta = saturate( cosTheta );
|
|
62
|
-
|
|
63
|
-
float c = 1.0 - cosTheta;
|
|
64
|
-
float c3 = c * c * c;
|
|
65
|
-
|
|
66
|
-
return 0.65584461 * c3 + 1.0 / ( 4.16526551 + exp( -7.97291361 * sqrt( alpha ) + 6.33516894 ) );
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
float sheenAlbedoScaling( vec3 wo, vec3 wi, SurfaceRec surf ) {
|
|
71
|
-
|
|
72
|
-
float alpha = max( surf.sheenRoughness, 0.07 );
|
|
73
|
-
alpha = alpha * alpha;
|
|
74
|
-
|
|
75
|
-
float maxSheenColor = max( max( surf.sheenColor.r, surf.sheenColor.g ), surf.sheenColor.b );
|
|
76
|
-
|
|
77
|
-
float eWo = directionalAlbedoSheen( saturateCos( wo.z ), alpha );
|
|
78
|
-
float eWi = directionalAlbedoSheen( saturateCos( wi.z ), alpha );
|
|
79
|
-
|
|
80
|
-
return min( 1.0 - maxSheenColor * eWo, 1.0 - maxSheenColor * eWi );
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// See Section 5, Layering, in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
85
|
-
float sheenAlbedoScaling( vec3 wo, SurfaceRec surf ) {
|
|
86
|
-
|
|
87
|
-
float alpha = max( surf.sheenRoughness, 0.07 );
|
|
88
|
-
alpha = alpha * alpha;
|
|
89
|
-
|
|
90
|
-
float maxSheenColor = max( max( surf.sheenColor.r, surf.sheenColor.g ), surf.sheenColor.b );
|
|
91
|
-
|
|
92
|
-
float eWo = directionalAlbedoSheen( saturateCos( wo.z ), alpha );
|
|
93
|
-
|
|
94
|
-
return 1.0 - maxSheenColor * eWo;
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
`;
|
|
1
|
+
export const shaderSheenFunctions = /* glsl */`
|
|
2
|
+
|
|
3
|
+
// See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
4
|
+
float velvetD( float cosThetaH, float roughness ) {
|
|
5
|
+
|
|
6
|
+
float alpha = max( roughness, 0.07 );
|
|
7
|
+
alpha = alpha * alpha;
|
|
8
|
+
|
|
9
|
+
float invAlpha = 1.0 / alpha;
|
|
10
|
+
|
|
11
|
+
float sqrCosThetaH = cosThetaH * cosThetaH;
|
|
12
|
+
float sinThetaH = max( 1.0 - sqrCosThetaH, 0.001 );
|
|
13
|
+
|
|
14
|
+
return ( 2.0 + invAlpha ) * pow( sinThetaH, 0.5 * invAlpha ) / ( 2.0 * PI );
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
float velvetParamsInterpolate( int i, float oneMinusAlphaSquared ) {
|
|
19
|
+
|
|
20
|
+
const float p0[5] = float[5]( 25.3245, 3.32435, 0.16801, -1.27393, -4.85967 );
|
|
21
|
+
const float p1[5] = float[5]( 21.5473, 3.82987, 0.19823, -1.97760, -4.32054 );
|
|
22
|
+
|
|
23
|
+
return mix( p1[i], p0[i], oneMinusAlphaSquared );
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
float velvetL( float x, float alpha ) {
|
|
28
|
+
|
|
29
|
+
float oneMinusAlpha = 1.0 - alpha;
|
|
30
|
+
float oneMinusAlphaSquared = oneMinusAlpha * oneMinusAlpha;
|
|
31
|
+
|
|
32
|
+
float a = velvetParamsInterpolate( 0, oneMinusAlphaSquared );
|
|
33
|
+
float b = velvetParamsInterpolate( 1, oneMinusAlphaSquared );
|
|
34
|
+
float c = velvetParamsInterpolate( 2, oneMinusAlphaSquared );
|
|
35
|
+
float d = velvetParamsInterpolate( 3, oneMinusAlphaSquared );
|
|
36
|
+
float e = velvetParamsInterpolate( 4, oneMinusAlphaSquared );
|
|
37
|
+
|
|
38
|
+
return a / ( 1.0 + b * pow( abs( x ), c ) ) + d * x + e;
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// See equation (3) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
43
|
+
float velvetLambda( float cosTheta, float alpha ) {
|
|
44
|
+
|
|
45
|
+
return abs( cosTheta ) < 0.5 ? exp( velvetL( cosTheta, alpha ) ) : exp( 2.0 * velvetL( 0.5, alpha ) - velvetL( 1.0 - cosTheta, alpha ) );
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// See Section 3, Shadowing Term, in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
50
|
+
float velvetG( float cosThetaO, float cosThetaI, float roughness ) {
|
|
51
|
+
|
|
52
|
+
float alpha = max( roughness, 0.07 );
|
|
53
|
+
alpha = alpha * alpha;
|
|
54
|
+
|
|
55
|
+
return 1.0 / ( 1.0 + velvetLambda( cosThetaO, alpha ) + velvetLambda( cosThetaI, alpha ) );
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
float directionalAlbedoSheen( float cosTheta, float alpha ) {
|
|
60
|
+
|
|
61
|
+
cosTheta = saturate( cosTheta );
|
|
62
|
+
|
|
63
|
+
float c = 1.0 - cosTheta;
|
|
64
|
+
float c3 = c * c * c;
|
|
65
|
+
|
|
66
|
+
return 0.65584461 * c3 + 1.0 / ( 4.16526551 + exp( -7.97291361 * sqrt( alpha ) + 6.33516894 ) );
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
float sheenAlbedoScaling( vec3 wo, vec3 wi, SurfaceRec surf ) {
|
|
71
|
+
|
|
72
|
+
float alpha = max( surf.sheenRoughness, 0.07 );
|
|
73
|
+
alpha = alpha * alpha;
|
|
74
|
+
|
|
75
|
+
float maxSheenColor = max( max( surf.sheenColor.r, surf.sheenColor.g ), surf.sheenColor.b );
|
|
76
|
+
|
|
77
|
+
float eWo = directionalAlbedoSheen( saturateCos( wo.z ), alpha );
|
|
78
|
+
float eWi = directionalAlbedoSheen( saturateCos( wi.z ), alpha );
|
|
79
|
+
|
|
80
|
+
return min( 1.0 - maxSheenColor * eWo, 1.0 - maxSheenColor * eWi );
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// See Section 5, Layering, in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
85
|
+
float sheenAlbedoScaling( vec3 wo, SurfaceRec surf ) {
|
|
86
|
+
|
|
87
|
+
float alpha = max( surf.sheenRoughness, 0.07 );
|
|
88
|
+
alpha = alpha * alpha;
|
|
89
|
+
|
|
90
|
+
float maxSheenColor = max( max( surf.sheenColor.r, surf.sheenColor.g ), surf.sheenColor.b );
|
|
91
|
+
|
|
92
|
+
float eWo = directionalAlbedoSheen( saturateCos( wo.z ), alpha );
|
|
93
|
+
|
|
94
|
+
return 1.0 - maxSheenColor * eWo;
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
`;
|
|
@@ -0,0 +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
|
+
`;
|