three-gpu-pathtracer 0.0.12 → 0.0.13

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 +961 -886
  3. package/build/index.module.js +6850 -6481
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +6845 -6475
  6. package/build/index.umd.cjs.map +1 -1
  7. package/package.json +73 -72
  8. package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
  9. package/src/core/MaterialReducer.js +256 -256
  10. package/src/core/PathTracingRenderer.js +346 -275
  11. package/src/core/PathTracingSceneGenerator.js +69 -69
  12. package/src/core/QuiltPathTracingRenderer.js +223 -0
  13. package/src/index.js +40 -39
  14. package/src/materials/AlphaDisplayMaterial.js +48 -48
  15. package/src/materials/AmbientOcclusionMaterial.js +199 -199
  16. package/src/materials/BlendMaterial.js +67 -67
  17. package/src/materials/DenoiseMaterial.js +142 -142
  18. package/src/materials/GraphMaterial.js +243 -243
  19. package/src/materials/LambertPathTracingMaterial.js +285 -285
  20. package/src/materials/MaterialBase.js +56 -56
  21. package/src/materials/PhysicalPathTracingMaterial.js +1013 -982
  22. package/src/objects/EquirectCamera.js +13 -13
  23. package/src/objects/PhysicalCamera.js +28 -28
  24. package/src/objects/PhysicalSpotLight.js +14 -14
  25. package/src/objects/ShapedAreaLight.js +12 -12
  26. package/src/shader/shaderEnvMapSampling.js +58 -58
  27. package/src/shader/shaderGGXFunctions.js +100 -100
  28. package/src/shader/shaderIridescenceFunctions.js +135 -130
  29. package/src/shader/shaderLayerTexelFetchFunctions.js +25 -25
  30. package/src/shader/shaderLightSampling.js +229 -229
  31. package/src/shader/shaderMaterialSampling.js +510 -506
  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 +327 -325
  36. package/src/shader/shaderUtils.js +377 -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 +273 -259
  41. package/src/uniforms/FloatAttributeTextureArray.js +169 -169
  42. package/src/uniforms/IESProfilesTexture.js +100 -100
  43. package/src/uniforms/LightsInfoUniformStruct.js +212 -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,130 +1,135 @@
1
- export const shaderIridescenceFunctions = /* glsl */`
2
-
3
- // XYZ to sRGB color space
4
- const mat3 XYZ_TO_REC709 = mat3(
5
- 3.2404542, -0.9692660, 0.0556434,
6
- -1.5371385, 1.8760108, -0.2040259,
7
- -0.4985314, 0.0415560, 1.0572252
8
- );
9
-
10
- vec3 fresnel0ToIor( vec3 fresnel0 ) {
11
-
12
- vec3 sqrtF0 = sqrt( fresnel0 );
13
- return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
14
-
15
- }
16
-
17
- // Conversion FO/IOR
18
- vec3 iorToFresnel0( vec3 transmittedIor, float incidentIor ) {
19
-
20
- return square( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
21
-
22
- }
23
-
24
- // ior is a value between 1.0 and 3.0. 1.0 is air interface
25
- float iorToFresnel0( float transmittedIor, float incidentIor ) {
26
-
27
- return square( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ) );
28
-
29
- }
30
-
31
- // Fresnel equations for dielectric/dielectric interfaces. See https://belcour.github.io/blog/research/2017/05/01/brdf-thin-film.html
32
- vec3 evalSensitivity( float OPD, vec3 shift ) {
33
-
34
- float phase = 2.0 * PI * OPD * 1.0e-9;
35
-
36
- vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
37
- vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
38
- vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
39
-
40
- vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - square( phase ) * var );
41
- xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * square( phase ) );
42
- xyz /= 1.0685e-7;
43
-
44
- vec3 srgb = XYZ_TO_REC709 * xyz;
45
- return srgb;
46
-
47
- }
48
-
49
- // See Section 4. Analytic Spectral Integration, A Practical Extension to Microfacet Theory for the Modeling of Varying Iridescence, https://hal.archives-ouvertes.fr/hal-01518344/document
50
- vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
51
-
52
- vec3 I;
53
-
54
- // Force iridescenceIor -> outsideIOR when thinFilmThickness -> 0.0
55
- float iridescenceIor = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
56
-
57
- // Evaluate the cosTheta on the base layer (Snell law)
58
- float sinTheta2Sq = square( outsideIOR / iridescenceIor ) * ( 1.0 - square( cosTheta1 ) );
59
-
60
- // Handle TIR:
61
- float cosTheta2Sq = 1.0 - sinTheta2Sq;
62
- if ( cosTheta2Sq < 0.0 ) {
63
-
64
- return vec3( 1.0 );
65
-
66
- }
67
-
68
- float cosTheta2 = sqrt( cosTheta2Sq );
69
-
70
- // First interface
71
- float R0 = iorToFresnel0( iridescenceIor, outsideIOR );
72
- float R12 = schlickFresnel( cosTheta1, R0 );
73
- float R21 = R12;
74
- float T121 = 1.0 - R12;
75
- float phi12 = 0.0;
76
- if ( iridescenceIor < outsideIOR ) {
77
-
78
- phi12 = PI;
79
-
80
- }
81
- float phi21 = PI - phi12;
82
-
83
- // Second interface
84
- vec3 baseIOR = fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); // guard against 1.0
85
- vec3 R1 = iorToFresnel0( baseIOR, iridescenceIor );
86
- vec3 R23 = schlickFresnel( cosTheta2, R1 );
87
- vec3 phi23 = vec3( 0.0 );
88
- if ( baseIOR[0] < iridescenceIor ) {
89
-
90
- phi23[ 0 ] = PI;
91
-
92
- }
93
- if ( baseIOR[1] < iridescenceIor ) {
94
-
95
- phi23[ 1 ] = PI;
96
-
97
- }
98
- if ( baseIOR[2] < iridescenceIor ) {
99
-
100
- phi23[ 2 ] = PI;
101
-
102
- }
103
-
104
- // Phase shift
105
- float OPD = 2.0 * iridescenceIor * thinFilmThickness * cosTheta2;
106
- vec3 phi = vec3( phi21 ) + phi23;
107
-
108
- // Compound terms
109
- vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
110
- vec3 r123 = sqrt( R123 );
111
- vec3 Rs = square( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
112
-
113
- // Reflectance term for m = 0 (DC term amplitude)
114
- vec3 C0 = R12 + Rs;
115
- I = C0;
116
-
117
- // Reflectance term for m > 0 (pairs of diracs)
118
- vec3 Cm = Rs - T121;
119
- for ( int m = 1; m <= 2; ++ m )
120
- {
121
- Cm *= r123;
122
- vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
123
- I += Cm * Sm;
124
- }
125
-
126
- // Since out of gamut colors might be produced, negative color values are clamped to 0.
127
- return max( I, vec3( 0.0 ) );
128
- }
129
-
130
- `;
1
+ export const shaderIridescenceFunctions = /* glsl */`
2
+
3
+ // XYZ to sRGB color space
4
+ const mat3 XYZ_TO_REC709 = mat3(
5
+ 3.2404542, -0.9692660, 0.0556434,
6
+ -1.5371385, 1.8760108, -0.2040259,
7
+ -0.4985314, 0.0415560, 1.0572252
8
+ );
9
+
10
+ vec3 fresnel0ToIor( vec3 fresnel0 ) {
11
+
12
+ vec3 sqrtF0 = sqrt( fresnel0 );
13
+ return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
14
+
15
+ }
16
+
17
+ // Conversion FO/IOR
18
+ vec3 iorToFresnel0( vec3 transmittedIor, float incidentIor ) {
19
+
20
+ return square( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
21
+
22
+ }
23
+
24
+ // ior is a value between 1.0 and 3.0. 1.0 is air interface
25
+ float iorToFresnel0( float transmittedIor, float incidentIor ) {
26
+
27
+ return square( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ) );
28
+
29
+ }
30
+
31
+ // Fresnel equations for dielectric/dielectric interfaces. See https://belcour.github.io/blog/research/2017/05/01/brdf-thin-film.html
32
+ vec3 evalSensitivity( float OPD, vec3 shift ) {
33
+
34
+ float phase = 2.0 * PI * OPD * 1.0e-9;
35
+
36
+ vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
37
+ vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
38
+ vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
39
+
40
+ vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - square( phase ) * var );
41
+ xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * square( phase ) );
42
+ xyz /= 1.0685e-7;
43
+
44
+ vec3 srgb = XYZ_TO_REC709 * xyz;
45
+ return srgb;
46
+
47
+ }
48
+
49
+ // See Section 4. Analytic Spectral Integration, A Practical Extension to Microfacet Theory for the Modeling of Varying Iridescence, https://hal.archives-ouvertes.fr/hal-01518344/document
50
+ vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
51
+
52
+ vec3 I;
53
+
54
+ // Force iridescenceIor -> outsideIOR when thinFilmThickness -> 0.0
55
+ float iridescenceIor = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
56
+
57
+ // Evaluate the cosTheta on the base layer (Snell law)
58
+ float sinTheta2Sq = square( outsideIOR / iridescenceIor ) * ( 1.0 - square( cosTheta1 ) );
59
+
60
+ // Handle TIR:
61
+ float cosTheta2Sq = 1.0 - sinTheta2Sq;
62
+ if ( cosTheta2Sq < 0.0 ) {
63
+
64
+ return vec3( 1.0 );
65
+
66
+ }
67
+
68
+ float cosTheta2 = sqrt( cosTheta2Sq );
69
+
70
+ // First interface
71
+ float R0 = iorToFresnel0( iridescenceIor, outsideIOR );
72
+ float R12 = schlickFresnel( cosTheta1, R0 );
73
+ float R21 = R12;
74
+ float T121 = 1.0 - R12;
75
+ float phi12 = 0.0;
76
+ if ( iridescenceIor < outsideIOR ) {
77
+
78
+ phi12 = PI;
79
+
80
+ }
81
+
82
+ float phi21 = PI - phi12;
83
+
84
+ // Second interface
85
+ vec3 baseIOR = fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); // guard against 1.0
86
+ vec3 R1 = iorToFresnel0( baseIOR, iridescenceIor );
87
+ vec3 R23 = schlickFresnel( cosTheta2, R1 );
88
+ vec3 phi23 = vec3( 0.0 );
89
+ if ( baseIOR[0] < iridescenceIor ) {
90
+
91
+ phi23[ 0 ] = PI;
92
+
93
+ }
94
+
95
+ if ( baseIOR[1] < iridescenceIor ) {
96
+
97
+ phi23[ 1 ] = PI;
98
+
99
+ }
100
+
101
+ if ( baseIOR[2] < iridescenceIor ) {
102
+
103
+ phi23[ 2 ] = PI;
104
+
105
+ }
106
+
107
+ // Phase shift
108
+ float OPD = 2.0 * iridescenceIor * thinFilmThickness * cosTheta2;
109
+ vec3 phi = vec3( phi21 ) + phi23;
110
+
111
+ // Compound terms
112
+ vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
113
+ vec3 r123 = sqrt( R123 );
114
+ vec3 Rs = square( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
115
+
116
+ // Reflectance term for m = 0 (DC term amplitude)
117
+ vec3 C0 = R12 + Rs;
118
+ I = C0;
119
+
120
+ // Reflectance term for m > 0 (pairs of diracs)
121
+ vec3 Cm = Rs - T121;
122
+ for ( int m = 1; m <= 2; ++ m ) {
123
+
124
+ Cm *= r123;
125
+ vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
126
+ I += Cm * Sm;
127
+
128
+ }
129
+
130
+ // Since out of gamut colors might be produced, negative color values are clamped to 0.
131
+ return max( I, vec3( 0.0 ) );
132
+
133
+ }
134
+
135
+ `;
@@ -1,25 +1,25 @@
1
-
2
- export const shaderLayerTexelFetchFunctions = /*glsl */`
3
-
4
- // add texel fetch functions for texture arrays
5
- vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
6
-
7
- uint width = uint( textureSize( tex, 0 ).x );
8
- uvec2 uv;
9
- uv.x = index % width;
10
- uv.y = index / width;
11
-
12
- return texelFetch( tex, ivec3( uv, layer ), 0 );
13
-
14
- }
15
-
16
- vec4 textureSampleBarycoord( sampler2DArray tex, int layer, vec3 barycoord, uvec3 faceIndices ) {
17
-
18
- return
19
- barycoord.x * texelFetch1D( tex, layer, faceIndices.x ) +
20
- barycoord.y * texelFetch1D( tex, layer, faceIndices.y ) +
21
- barycoord.z * texelFetch1D( tex, layer, faceIndices.z );
22
-
23
- }
24
-
25
- `;
1
+
2
+ export const shaderLayerTexelFetchFunctions = /*glsl */`
3
+
4
+ // add texel fetch functions for texture arrays
5
+ vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
6
+
7
+ uint width = uint( textureSize( tex, 0 ).x );
8
+ uvec2 uv;
9
+ uv.x = index % width;
10
+ uv.y = index / width;
11
+
12
+ return texelFetch( tex, ivec3( uv, layer ), 0 );
13
+
14
+ }
15
+
16
+ vec4 textureSampleBarycoord( sampler2DArray tex, int layer, vec3 barycoord, uvec3 faceIndices ) {
17
+
18
+ return
19
+ barycoord.x * texelFetch1D( tex, layer, faceIndices.x ) +
20
+ barycoord.y * texelFetch1D( tex, layer, faceIndices.y ) +
21
+ barycoord.z * texelFetch1D( tex, layer, faceIndices.z );
22
+
23
+ }
24
+
25
+ `;