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.
Files changed (76) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1004 -981
  3. package/build/index.module.js +7413 -6902
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +7446 -6933
  6. package/build/index.umd.cjs.map +1 -1
  7. package/package.json +73 -73
  8. package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
  9. package/src/core/MaterialReducer.js +256 -256
  10. package/src/core/PathTracingRenderer.js +346 -346
  11. package/src/core/PathTracingSceneGenerator.js +69 -69
  12. package/src/core/QuiltPathTracingRenderer.js +223 -223
  13. package/src/detectors/CompatibilityDetector.js +38 -0
  14. package/src/detectors/MaterialCompileDetector.js +50 -0
  15. package/src/detectors/PrecisionDetector.js +85 -0
  16. package/src/detectors/PrecisionMaterial.js +160 -0
  17. package/src/index.js +40 -36
  18. package/src/materials/MaterialBase.js +56 -56
  19. package/src/materials/debug/GraphMaterial.js +243 -243
  20. package/src/materials/fullscreen/AlphaDisplayMaterial.js +50 -48
  21. package/src/materials/fullscreen/BlendMaterial.js +67 -67
  22. package/src/materials/fullscreen/DenoiseMaterial.js +142 -142
  23. package/src/materials/fullscreen/GradientMapMaterial.js +82 -0
  24. package/src/materials/pathtracing/LambertPathTracingMaterial.js +296 -296
  25. package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +118 -196
  26. package/src/materials/pathtracing/glsl/attenuateHit.glsl.js +177 -179
  27. package/src/materials/pathtracing/glsl/cameraUtils.glsl.js +84 -81
  28. package/src/materials/pathtracing/glsl/directLightContribution.glsl.js +93 -0
  29. package/src/materials/pathtracing/glsl/getSurfaceRecord.glsl.js +323 -317
  30. package/src/materials/pathtracing/glsl/renderStructs.glsl.js +50 -0
  31. package/src/materials/pathtracing/glsl/traceScene.glsl.js +52 -54
  32. package/src/materials/surface/AmbientOcclusionMaterial.js +207 -207
  33. package/src/materials/surface/FogVolumeMaterial.js +23 -23
  34. package/src/objects/EquirectCamera.js +13 -13
  35. package/src/objects/PhysicalCamera.js +42 -28
  36. package/src/objects/PhysicalSpotLight.js +25 -14
  37. package/src/objects/ShapedAreaLight.js +22 -12
  38. package/src/shader/bsdf/bsdfSampling.glsl.js +499 -490
  39. package/src/shader/bsdf/fog.glsl.js +22 -23
  40. package/src/shader/bsdf/ggx.glsl.js +102 -102
  41. package/src/shader/bsdf/iridescence.glsl.js +135 -135
  42. package/src/shader/bsdf/sheen.glsl.js +98 -98
  43. package/src/shader/common/arraySamplerTexelFetch.glsl.js +25 -25
  44. package/src/shader/common/bvhAnyHit.glsl.js +76 -76
  45. package/src/shader/common/fresnel.glsl.js +98 -98
  46. package/src/shader/common/intersectShapes.glsl.js +62 -62
  47. package/src/shader/common/math.glsl.js +81 -81
  48. package/src/shader/common/utils.glsl.js +116 -116
  49. package/src/shader/rand/pcg.glsl.js +57 -57
  50. package/src/shader/rand/sobol.glsl.js +256 -256
  51. package/src/shader/sampling/equirectSampling.glsl.js +62 -62
  52. package/src/shader/sampling/lightSampling.glsl.js +223 -223
  53. package/src/shader/sampling/shapeSampling.glsl.js +86 -86
  54. package/src/shader/structs/cameraStruct.glsl.js +13 -13
  55. package/src/shader/structs/equirectStruct.glsl.js +13 -14
  56. package/src/shader/structs/fogMaterialBvh.glsl.js +62 -62
  57. package/src/shader/structs/lightsStruct.glsl.js +78 -78
  58. package/src/shader/structs/materialStruct.glsl.js +207 -207
  59. package/src/textures/GradientEquirectTexture.js +35 -35
  60. package/src/textures/ProceduralEquirectTexture.js +75 -75
  61. package/src/uniforms/AttributesTextureArray.js +35 -35
  62. package/src/uniforms/EquirectHdrInfoUniform.js +269 -277
  63. package/src/uniforms/FloatAttributeTextureArray.js +169 -169
  64. package/src/uniforms/IESProfilesTexture.js +100 -100
  65. package/src/uniforms/LightsInfoUniformStruct.js +212 -212
  66. package/src/uniforms/MaterialsTexture.js +503 -503
  67. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  68. package/src/uniforms/RenderTarget2DArray.js +97 -97
  69. package/src/uniforms/utils.js +30 -30
  70. package/src/utils/BlurredEnvMapGenerator.js +116 -116
  71. package/src/utils/GeometryPreparationUtils.js +214 -214
  72. package/src/utils/IESLoader.js +325 -325
  73. package/src/utils/SobolNumberMapGenerator.js +80 -80
  74. package/src/utils/UVUnwrapper.js +101 -101
  75. package/src/utils/macroify.js +9 -9
  76. package/src/workers/PathTracingSceneWorker.js +42 -42
@@ -1,67 +1,67 @@
1
- import { NoBlending } from 'three';
2
- import { MaterialBase } from '../MaterialBase.js';
3
-
4
- export class BlendMaterial extends MaterialBase {
5
-
6
- constructor( parameters ) {
7
-
8
- super( {
9
-
10
- blending: NoBlending,
11
-
12
- uniforms: {
13
-
14
- target1: { value: null },
15
- target2: { value: null },
16
- opacity: { value: 1.0 },
17
-
18
- },
19
-
20
- vertexShader: /* glsl */`
21
-
22
- varying vec2 vUv;
23
-
24
- void main() {
25
-
26
- vUv = uv;
27
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
28
-
29
- }`,
30
-
31
- fragmentShader: /* glsl */`
32
-
33
- uniform float opacity;
34
-
35
- uniform sampler2D target1;
36
- uniform sampler2D target2;
37
-
38
- varying vec2 vUv;
39
-
40
- void main() {
41
-
42
- vec4 color1 = texture2D( target1, vUv );
43
- vec4 color2 = texture2D( target2, vUv );
44
-
45
- float invOpacity = 1.0 - opacity;
46
- float totalAlpha = color1.a * invOpacity + color2.a * opacity;
47
-
48
- if ( color1.a != 0.0 || color2.a != 0.0 ) {
49
-
50
- gl_FragColor.rgb = color1.rgb * ( invOpacity * color1.a / totalAlpha ) + color2.rgb * ( opacity * color2.a / totalAlpha );
51
- gl_FragColor.a = totalAlpha;
52
-
53
- } else {
54
-
55
- gl_FragColor = vec4( 0.0 );
56
-
57
- }
58
-
59
- }`
60
-
61
- } );
62
-
63
- this.setValues( parameters );
64
-
65
- }
66
-
67
- }
1
+ import { NoBlending } from 'three';
2
+ import { MaterialBase } from '../MaterialBase.js';
3
+
4
+ export class BlendMaterial extends MaterialBase {
5
+
6
+ constructor( parameters ) {
7
+
8
+ super( {
9
+
10
+ blending: NoBlending,
11
+
12
+ uniforms: {
13
+
14
+ target1: { value: null },
15
+ target2: { value: null },
16
+ opacity: { value: 1.0 },
17
+
18
+ },
19
+
20
+ vertexShader: /* glsl */`
21
+
22
+ varying vec2 vUv;
23
+
24
+ void main() {
25
+
26
+ vUv = uv;
27
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
28
+
29
+ }`,
30
+
31
+ fragmentShader: /* glsl */`
32
+
33
+ uniform float opacity;
34
+
35
+ uniform sampler2D target1;
36
+ uniform sampler2D target2;
37
+
38
+ varying vec2 vUv;
39
+
40
+ void main() {
41
+
42
+ vec4 color1 = texture2D( target1, vUv );
43
+ vec4 color2 = texture2D( target2, vUv );
44
+
45
+ float invOpacity = 1.0 - opacity;
46
+ float totalAlpha = color1.a * invOpacity + color2.a * opacity;
47
+
48
+ if ( color1.a != 0.0 || color2.a != 0.0 ) {
49
+
50
+ gl_FragColor.rgb = color1.rgb * ( invOpacity * color1.a / totalAlpha ) + color2.rgb * ( opacity * color2.a / totalAlpha );
51
+ gl_FragColor.a = totalAlpha;
52
+
53
+ } else {
54
+
55
+ gl_FragColor = vec4( 0.0 );
56
+
57
+ }
58
+
59
+ }`
60
+
61
+ } );
62
+
63
+ this.setValues( parameters );
64
+
65
+ }
66
+
67
+ }
@@ -1,142 +1,142 @@
1
- import { NoBlending } from 'three';
2
- import { MaterialBase } from '../MaterialBase.js';
3
-
4
- export class DenoiseMaterial extends MaterialBase {
5
-
6
- constructor( parameters ) {
7
-
8
- super( {
9
-
10
- blending: NoBlending,
11
-
12
- transparent: false,
13
-
14
- depthWrite: false,
15
-
16
- depthTest: false,
17
-
18
- defines: {
19
-
20
- USE_SLIDER: 0,
21
-
22
- },
23
-
24
- uniforms: {
25
-
26
- sigma: { value: 5.0 },
27
- threshold: { value: 0.03 },
28
- kSigma: { value: 1.0 },
29
-
30
- map: { value: null },
31
-
32
- },
33
-
34
- vertexShader: /* glsl */`
35
-
36
- varying vec2 vUv;
37
-
38
- void main() {
39
-
40
- vUv = uv;
41
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
42
-
43
- }
44
-
45
- `,
46
-
47
- fragmentShader: /* glsl */`
48
-
49
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
- // Copyright (c) 2018-2019 Michele Morrone
51
- // All rights reserved.
52
- //
53
- // https://michelemorrone.eu - https://BrutPitt.com
54
- //
55
- // me@michelemorrone.eu - brutpitt@gmail.com
56
- // twitter: @BrutPitt - github: BrutPitt
57
- //
58
- // https://github.com/BrutPitt/glslSmartDeNoise/
59
- //
60
- // This software is distributed under the terms of the BSD 2-Clause license
61
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62
-
63
- uniform sampler2D map;
64
-
65
- uniform float sigma;
66
- uniform float threshold;
67
- uniform float kSigma;
68
-
69
- varying vec2 vUv;
70
-
71
- #define INV_SQRT_OF_2PI 0.39894228040143267793994605993439
72
- #define INV_PI 0.31830988618379067153776752674503
73
-
74
- // Parameters:
75
- // sampler2D tex - sampler image / texture
76
- // vec2 uv - actual fragment coord
77
- // float sigma > 0 - sigma Standard Deviation
78
- // float kSigma >= 0 - sigma coefficient
79
- // kSigma * sigma --> radius of the circular kernel
80
- // float threshold - edge sharpening threshold
81
- vec4 smartDeNoise( sampler2D tex, vec2 uv, float sigma, float kSigma, float threshold ) {
82
-
83
- float radius = round( kSigma * sigma );
84
- float radQ = radius * radius;
85
-
86
- float invSigmaQx2 = 0.5 / ( sigma * sigma );
87
- float invSigmaQx2PI = INV_PI * invSigmaQx2;
88
-
89
- float invThresholdSqx2 = 0.5 / ( threshold * threshold );
90
- float invThresholdSqrt2PI = INV_SQRT_OF_2PI / threshold;
91
-
92
- vec4 centrPx = texture2D( tex, uv );
93
- centrPx.rgb *= centrPx.a;
94
-
95
- float zBuff = 0.0;
96
- vec4 aBuff = vec4( 0.0 );
97
- vec2 size = vec2( textureSize( tex, 0 ) );
98
-
99
- vec2 d;
100
- for ( d.x = - radius; d.x <= radius; d.x ++ ) {
101
-
102
- float pt = sqrt( radQ - d.x * d.x );
103
-
104
- for ( d.y = - pt; d.y <= pt; d.y ++ ) {
105
-
106
- float blurFactor = exp( - dot( d, d ) * invSigmaQx2 ) * invSigmaQx2PI;
107
-
108
- vec4 walkPx = texture2D( tex, uv + d / size );
109
- walkPx.rgb *= walkPx.a;
110
-
111
- vec4 dC = walkPx - centrPx;
112
- float deltaFactor = exp( - dot( dC.rgba, dC.rgba ) * invThresholdSqx2 ) * invThresholdSqrt2PI * blurFactor;
113
-
114
- zBuff += deltaFactor;
115
- aBuff += deltaFactor * walkPx;
116
-
117
- }
118
-
119
- }
120
-
121
- return aBuff / zBuff;
122
-
123
- }
124
-
125
- void main() {
126
-
127
- gl_FragColor = smartDeNoise( map, vec2( vUv.x, vUv.y ), sigma, kSigma, threshold );
128
- #include <tonemapping_fragment>
129
- #include <encodings_fragment>
130
- #include <premultiplied_alpha_fragment>
131
-
132
- }
133
-
134
- `
135
-
136
- } );
137
-
138
- this.setValues( parameters );
139
-
140
- }
141
-
142
- }
1
+ import { NoBlending } from 'three';
2
+ import { MaterialBase } from '../MaterialBase.js';
3
+
4
+ export class DenoiseMaterial extends MaterialBase {
5
+
6
+ constructor( parameters ) {
7
+
8
+ super( {
9
+
10
+ blending: NoBlending,
11
+
12
+ transparent: false,
13
+
14
+ depthWrite: false,
15
+
16
+ depthTest: false,
17
+
18
+ defines: {
19
+
20
+ USE_SLIDER: 0,
21
+
22
+ },
23
+
24
+ uniforms: {
25
+
26
+ sigma: { value: 5.0 },
27
+ threshold: { value: 0.03 },
28
+ kSigma: { value: 1.0 },
29
+
30
+ map: { value: null },
31
+
32
+ },
33
+
34
+ vertexShader: /* glsl */`
35
+
36
+ varying vec2 vUv;
37
+
38
+ void main() {
39
+
40
+ vUv = uv;
41
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
42
+
43
+ }
44
+
45
+ `,
46
+
47
+ fragmentShader: /* glsl */`
48
+
49
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
+ // Copyright (c) 2018-2019 Michele Morrone
51
+ // All rights reserved.
52
+ //
53
+ // https://michelemorrone.eu - https://BrutPitt.com
54
+ //
55
+ // me@michelemorrone.eu - brutpitt@gmail.com
56
+ // twitter: @BrutPitt - github: BrutPitt
57
+ //
58
+ // https://github.com/BrutPitt/glslSmartDeNoise/
59
+ //
60
+ // This software is distributed under the terms of the BSD 2-Clause license
61
+ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62
+
63
+ uniform sampler2D map;
64
+
65
+ uniform float sigma;
66
+ uniform float threshold;
67
+ uniform float kSigma;
68
+
69
+ varying vec2 vUv;
70
+
71
+ #define INV_SQRT_OF_2PI 0.39894228040143267793994605993439
72
+ #define INV_PI 0.31830988618379067153776752674503
73
+
74
+ // Parameters:
75
+ // sampler2D tex - sampler image / texture
76
+ // vec2 uv - actual fragment coord
77
+ // float sigma > 0 - sigma Standard Deviation
78
+ // float kSigma >= 0 - sigma coefficient
79
+ // kSigma * sigma --> radius of the circular kernel
80
+ // float threshold - edge sharpening threshold
81
+ vec4 smartDeNoise( sampler2D tex, vec2 uv, float sigma, float kSigma, float threshold ) {
82
+
83
+ float radius = round( kSigma * sigma );
84
+ float radQ = radius * radius;
85
+
86
+ float invSigmaQx2 = 0.5 / ( sigma * sigma );
87
+ float invSigmaQx2PI = INV_PI * invSigmaQx2;
88
+
89
+ float invThresholdSqx2 = 0.5 / ( threshold * threshold );
90
+ float invThresholdSqrt2PI = INV_SQRT_OF_2PI / threshold;
91
+
92
+ vec4 centrPx = texture2D( tex, uv );
93
+ centrPx.rgb *= centrPx.a;
94
+
95
+ float zBuff = 0.0;
96
+ vec4 aBuff = vec4( 0.0 );
97
+ vec2 size = vec2( textureSize( tex, 0 ) );
98
+
99
+ vec2 d;
100
+ for ( d.x = - radius; d.x <= radius; d.x ++ ) {
101
+
102
+ float pt = sqrt( radQ - d.x * d.x );
103
+
104
+ for ( d.y = - pt; d.y <= pt; d.y ++ ) {
105
+
106
+ float blurFactor = exp( - dot( d, d ) * invSigmaQx2 ) * invSigmaQx2PI;
107
+
108
+ vec4 walkPx = texture2D( tex, uv + d / size );
109
+ walkPx.rgb *= walkPx.a;
110
+
111
+ vec4 dC = walkPx - centrPx;
112
+ float deltaFactor = exp( - dot( dC.rgba, dC.rgba ) * invThresholdSqx2 ) * invThresholdSqrt2PI * blurFactor;
113
+
114
+ zBuff += deltaFactor;
115
+ aBuff += deltaFactor * walkPx;
116
+
117
+ }
118
+
119
+ }
120
+
121
+ return aBuff / zBuff;
122
+
123
+ }
124
+
125
+ void main() {
126
+
127
+ gl_FragColor = smartDeNoise( map, vec2( vUv.x, vUv.y ), sigma, kSigma, threshold );
128
+ #include <tonemapping_fragment>
129
+ #include <encodings_fragment>
130
+ #include <premultiplied_alpha_fragment>
131
+
132
+ }
133
+
134
+ `
135
+
136
+ } );
137
+
138
+ this.setValues( parameters );
139
+
140
+ }
141
+
142
+ }
@@ -0,0 +1,82 @@
1
+ import { Color, NoBlending } from 'three';
2
+ import { MaterialBase } from '../MaterialBase.js';
3
+
4
+ export class GradientMapMaterial extends MaterialBase {
5
+
6
+ constructor( parameters ) {
7
+
8
+ super( {
9
+
10
+ defines: {
11
+
12
+ FEATURE_BIN: 0,
13
+
14
+ },
15
+
16
+ uniforms: {
17
+
18
+ map: { value: null },
19
+
20
+ minColor: { value: new Color( 0 ) },
21
+ minValue: { value: 0 },
22
+
23
+ maxColor: { value: new Color( 0xffffff ) },
24
+ maxValue: { value: 10 },
25
+
26
+ field: { value: 0 },
27
+ power: { value: 1 },
28
+
29
+ },
30
+
31
+ blending: NoBlending,
32
+
33
+ vertexShader: /* glsl */`
34
+
35
+ varying vec2 vUv;
36
+
37
+ void main() {
38
+
39
+ vUv = uv;
40
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
41
+
42
+ }`,
43
+
44
+ fragmentShader: /* glsl */`
45
+
46
+ uniform sampler2D map;
47
+ uniform vec3 minColor;
48
+ uniform float minValue;
49
+ uniform vec3 maxColor;
50
+ uniform float maxValue;
51
+ uniform int field;
52
+ uniform float power;
53
+
54
+ varying vec2 vUv;
55
+
56
+ void main() {
57
+
58
+ float value = texture( map, vUv )[ field ];
59
+
60
+ #if FEATURE_BIN
61
+
62
+ value = ceil( value );
63
+
64
+ #endif
65
+
66
+ float t = smoothstep( minValue, maxValue, value );
67
+ t = pow( t, power );
68
+
69
+ gl_FragColor.rgb = vec3( mix( minColor, maxColor, t ) );
70
+ gl_FragColor.a = 1.0;
71
+
72
+ #include <encodings_fragment>
73
+
74
+ }`,
75
+
76
+ } );
77
+
78
+ this.setValues( parameters );
79
+
80
+ }
81
+
82
+ }