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,243 +1,243 @@
1
- import { NoBlending, Color, Vector2, Vector4 } from 'three';
2
- import { MaterialBase } from '../MaterialBase.js';
3
-
4
- export class GraphMaterial extends MaterialBase {
5
-
6
- get graphFunctionSnippet() {
7
-
8
- return this._graphFunctionSnippet;
9
-
10
- }
11
-
12
- set graphFunctionSnippet( v ) {
13
-
14
- this._graphFunctionSnippet = v;
15
-
16
- }
17
-
18
- constructor( parameters ) {
19
-
20
- super( {
21
-
22
- blending: NoBlending,
23
-
24
- transparent: false,
25
-
26
- depthWrite: false,
27
-
28
- depthTest: false,
29
-
30
- defines: {
31
-
32
- USE_SLIDER: 0,
33
-
34
- },
35
-
36
- uniforms: {
37
-
38
- dim: { value: true },
39
- thickness: { value: 1 },
40
- graphCount: { value: 4 },
41
- graphDisplay: { value: new Vector4( 1.0, 1.0, 1.0, 1.0 ) },
42
- overlay: { value: true },
43
- xRange: { value: new Vector2( - 2.0, 2.0 ) },
44
- yRange: { value: new Vector2( - 2.0, 2.0 ) },
45
- colors: { value: [
46
- new Color( 0xe91e63 ).convertSRGBToLinear(),
47
- new Color( 0x4caf50 ).convertSRGBToLinear(),
48
- new Color( 0x03a9f4 ).convertSRGBToLinear(),
49
- new Color( 0xffc107 ).convertSRGBToLinear(),
50
- ] },
51
-
52
- },
53
-
54
- vertexShader: /* glsl */`
55
-
56
- varying vec2 vUv;
57
-
58
- void main() {
59
-
60
- vUv = uv;
61
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
62
-
63
- }
64
-
65
- `,
66
-
67
- fragmentShader: /* glsl */`
68
- varying vec2 vUv;
69
- uniform bool overlay;
70
- uniform bool dim;
71
- uniform bvec4 graphDisplay;
72
- uniform float graphCount;
73
- uniform float thickness;
74
- uniform vec2 xRange;
75
- uniform vec2 yRange;
76
- uniform vec3 colors[ 4 ];
77
-
78
- __FUNCTION_CONTENT__
79
-
80
- float map( float _min, float _max, float v ) {
81
-
82
- float len = _max - _min;
83
- return _min + len * v;
84
-
85
- }
86
-
87
- vec3 getBackground( vec2 point, float steepness ) {
88
-
89
- vec2 pw = fwidth( point );
90
- vec2 halfWidth = pw * 0.5;
91
-
92
- // x, y axes
93
- vec2 distToZero = smoothstep(
94
- - halfWidth * 0.5,
95
- halfWidth * 0.5,
96
- abs( point.xy ) - pw
97
- );
98
-
99
- // 1 unit markers
100
- vec2 temp;
101
- vec2 modAxis = abs( modf( point + vec2( 0.5 ), temp ) ) - 0.5;
102
- vec2 distToAxis = smoothstep(
103
- - halfWidth,
104
- halfWidth,
105
- abs( modAxis.xy ) - pw * 0.5
106
- );
107
-
108
- // if we're at a chart boundary then remove the artifacts
109
- if ( abs( pw.y ) > steepness * 0.5 ) {
110
-
111
- distToZero.y = 1.0;
112
- distToAxis.y = 1.0;
113
-
114
- }
115
-
116
- // mix colors into a background color
117
- float axisIntensity = 1.0 - min( distToZero.x, distToZero.y );
118
- float markerIntensity = 1.0 - min( distToAxis.x, distToAxis.y );
119
-
120
- vec3 markerColor = mix( vec3( 0.005 ), vec3( 0.05 ), markerIntensity );
121
- vec3 backgroundColor = mix( markerColor, vec3( 0.2 ), axisIntensity );
122
- return backgroundColor;
123
-
124
- }
125
-
126
- void main() {
127
-
128
- // from uniforms
129
- float sectionCount = overlay ? 1.0 : graphCount;
130
- float yWidth = abs( yRange.y - yRange.x );
131
-
132
- // separate into sections
133
- float _section;
134
- float sectionY = modf( sectionCount * vUv.y, _section );
135
- int section = int( sectionCount - _section - 1.0 );
136
-
137
- // get the current point
138
- vec2 point = vec2(
139
- map( xRange.x, xRange.y, vUv.x ),
140
- map( yRange.x, yRange.y, sectionY )
141
- );
142
-
143
- // get the results
144
- vec4 result = graphFunction( point.x );
145
- vec4 delta = result - vec4( point.y );
146
- vec4 halfDdf = fwidth( delta ) * 0.5;
147
- if ( fwidth( point.y ) > yWidth * 0.5 ) {
148
-
149
- halfDdf = vec4( 0.0 );
150
-
151
- }
152
-
153
- // graph display intensity
154
- vec4 graph = smoothstep( - halfDdf, halfDdf, abs( delta ) - thickness * halfDdf );
155
-
156
- // initialize the background
157
- gl_FragColor.rgb = getBackground( point, yWidth );
158
- gl_FragColor.a = 1.0;
159
-
160
- if ( dim && ( point.x < 0.0 || point.y < 0.0 ) ) {
161
-
162
- graph = mix(
163
- vec4( 1.0 ),
164
- graph,
165
- 0.05
166
- );
167
-
168
- }
169
-
170
- // color the charts
171
- if ( sectionCount > 1.0 ) {
172
-
173
- if ( graphDisplay[ section ] ) {
174
-
175
- gl_FragColor.rgb = mix(
176
- colors[ section ],
177
- gl_FragColor.rgb,
178
- graph[ section ]
179
- );
180
-
181
- }
182
-
183
- } else {
184
-
185
- for ( int i = 0; i < int( graphCount ); i ++ ) {
186
-
187
- if ( graphDisplay[ i ] ) {
188
-
189
- gl_FragColor.rgb = mix(
190
- colors[ i ],
191
- gl_FragColor.rgb,
192
- graph[ i ]
193
- );
194
-
195
- }
196
-
197
- }
198
-
199
- }
200
-
201
- #include <encodings_fragment>
202
-
203
- }
204
-
205
- `
206
-
207
- } );
208
-
209
-
210
- this._graphFunctionSnippet = /* glsl */`
211
- vec4 graphFunctionSnippet( float x ) {
212
-
213
- return vec4(
214
- sin( x * 3.1415926535 ),
215
- cos( x ),
216
- 0.0,
217
- 0.0
218
- );
219
-
220
- }
221
- `;
222
-
223
- this.setValues( parameters );
224
-
225
- }
226
-
227
- onBeforeCompile( shader ) {
228
-
229
- shader.fragmentShader = shader.fragmentShader.replace(
230
- '__FUNCTION_CONTENT__',
231
- this._graphFunctionSnippet,
232
- );
233
- return shader;
234
-
235
- }
236
-
237
- customProgramCacheKey() {
238
-
239
- return this._graphFunctionSnippet;
240
-
241
- }
242
-
243
- }
1
+ import { NoBlending, Color, Vector2, Vector4 } from 'three';
2
+ import { MaterialBase } from '../MaterialBase.js';
3
+
4
+ export class GraphMaterial extends MaterialBase {
5
+
6
+ get graphFunctionSnippet() {
7
+
8
+ return this._graphFunctionSnippet;
9
+
10
+ }
11
+
12
+ set graphFunctionSnippet( v ) {
13
+
14
+ this._graphFunctionSnippet = v;
15
+
16
+ }
17
+
18
+ constructor( parameters ) {
19
+
20
+ super( {
21
+
22
+ blending: NoBlending,
23
+
24
+ transparent: false,
25
+
26
+ depthWrite: false,
27
+
28
+ depthTest: false,
29
+
30
+ defines: {
31
+
32
+ USE_SLIDER: 0,
33
+
34
+ },
35
+
36
+ uniforms: {
37
+
38
+ dim: { value: true },
39
+ thickness: { value: 1 },
40
+ graphCount: { value: 4 },
41
+ graphDisplay: { value: new Vector4( 1.0, 1.0, 1.0, 1.0 ) },
42
+ overlay: { value: true },
43
+ xRange: { value: new Vector2( - 2.0, 2.0 ) },
44
+ yRange: { value: new Vector2( - 2.0, 2.0 ) },
45
+ colors: { value: [
46
+ new Color( 0xe91e63 ).convertSRGBToLinear(),
47
+ new Color( 0x4caf50 ).convertSRGBToLinear(),
48
+ new Color( 0x03a9f4 ).convertSRGBToLinear(),
49
+ new Color( 0xffc107 ).convertSRGBToLinear(),
50
+ ] },
51
+
52
+ },
53
+
54
+ vertexShader: /* glsl */`
55
+
56
+ varying vec2 vUv;
57
+
58
+ void main() {
59
+
60
+ vUv = uv;
61
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
62
+
63
+ }
64
+
65
+ `,
66
+
67
+ fragmentShader: /* glsl */`
68
+ varying vec2 vUv;
69
+ uniform bool overlay;
70
+ uniform bool dim;
71
+ uniform bvec4 graphDisplay;
72
+ uniform float graphCount;
73
+ uniform float thickness;
74
+ uniform vec2 xRange;
75
+ uniform vec2 yRange;
76
+ uniform vec3 colors[ 4 ];
77
+
78
+ __FUNCTION_CONTENT__
79
+
80
+ float map( float _min, float _max, float v ) {
81
+
82
+ float len = _max - _min;
83
+ return _min + len * v;
84
+
85
+ }
86
+
87
+ vec3 getBackground( vec2 point, float steepness ) {
88
+
89
+ vec2 pw = fwidth( point );
90
+ vec2 halfWidth = pw * 0.5;
91
+
92
+ // x, y axes
93
+ vec2 distToZero = smoothstep(
94
+ - halfWidth * 0.5,
95
+ halfWidth * 0.5,
96
+ abs( point.xy ) - pw
97
+ );
98
+
99
+ // 1 unit markers
100
+ vec2 temp;
101
+ vec2 modAxis = abs( modf( point + vec2( 0.5 ), temp ) ) - 0.5;
102
+ vec2 distToAxis = smoothstep(
103
+ - halfWidth,
104
+ halfWidth,
105
+ abs( modAxis.xy ) - pw * 0.5
106
+ );
107
+
108
+ // if we're at a chart boundary then remove the artifacts
109
+ if ( abs( pw.y ) > steepness * 0.5 ) {
110
+
111
+ distToZero.y = 1.0;
112
+ distToAxis.y = 1.0;
113
+
114
+ }
115
+
116
+ // mix colors into a background color
117
+ float axisIntensity = 1.0 - min( distToZero.x, distToZero.y );
118
+ float markerIntensity = 1.0 - min( distToAxis.x, distToAxis.y );
119
+
120
+ vec3 markerColor = mix( vec3( 0.005 ), vec3( 0.05 ), markerIntensity );
121
+ vec3 backgroundColor = mix( markerColor, vec3( 0.2 ), axisIntensity );
122
+ return backgroundColor;
123
+
124
+ }
125
+
126
+ void main() {
127
+
128
+ // from uniforms
129
+ float sectionCount = overlay ? 1.0 : graphCount;
130
+ float yWidth = abs( yRange.y - yRange.x );
131
+
132
+ // separate into sections
133
+ float _section;
134
+ float sectionY = modf( sectionCount * vUv.y, _section );
135
+ int section = int( sectionCount - _section - 1.0 );
136
+
137
+ // get the current point
138
+ vec2 point = vec2(
139
+ map( xRange.x, xRange.y, vUv.x ),
140
+ map( yRange.x, yRange.y, sectionY )
141
+ );
142
+
143
+ // get the results
144
+ vec4 result = graphFunction( point.x );
145
+ vec4 delta = result - vec4( point.y );
146
+ vec4 halfDdf = fwidth( delta ) * 0.5;
147
+ if ( fwidth( point.y ) > yWidth * 0.5 ) {
148
+
149
+ halfDdf = vec4( 0.0 );
150
+
151
+ }
152
+
153
+ // graph display intensity
154
+ vec4 graph = smoothstep( - halfDdf, halfDdf, abs( delta ) - thickness * halfDdf );
155
+
156
+ // initialize the background
157
+ gl_FragColor.rgb = getBackground( point, yWidth );
158
+ gl_FragColor.a = 1.0;
159
+
160
+ if ( dim && ( point.x < 0.0 || point.y < 0.0 ) ) {
161
+
162
+ graph = mix(
163
+ vec4( 1.0 ),
164
+ graph,
165
+ 0.05
166
+ );
167
+
168
+ }
169
+
170
+ // color the charts
171
+ if ( sectionCount > 1.0 ) {
172
+
173
+ if ( graphDisplay[ section ] ) {
174
+
175
+ gl_FragColor.rgb = mix(
176
+ colors[ section ],
177
+ gl_FragColor.rgb,
178
+ graph[ section ]
179
+ );
180
+
181
+ }
182
+
183
+ } else {
184
+
185
+ for ( int i = 0; i < int( graphCount ); i ++ ) {
186
+
187
+ if ( graphDisplay[ i ] ) {
188
+
189
+ gl_FragColor.rgb = mix(
190
+ colors[ i ],
191
+ gl_FragColor.rgb,
192
+ graph[ i ]
193
+ );
194
+
195
+ }
196
+
197
+ }
198
+
199
+ }
200
+
201
+ #include <encodings_fragment>
202
+
203
+ }
204
+
205
+ `
206
+
207
+ } );
208
+
209
+
210
+ this._graphFunctionSnippet = /* glsl */`
211
+ vec4 graphFunctionSnippet( float x ) {
212
+
213
+ return vec4(
214
+ sin( x * 3.1415926535 ),
215
+ cos( x ),
216
+ 0.0,
217
+ 0.0
218
+ );
219
+
220
+ }
221
+ `;
222
+
223
+ this.setValues( parameters );
224
+
225
+ }
226
+
227
+ onBeforeCompile( shader ) {
228
+
229
+ shader.fragmentShader = shader.fragmentShader.replace(
230
+ '__FUNCTION_CONTENT__',
231
+ this._graphFunctionSnippet,
232
+ );
233
+ return shader;
234
+
235
+ }
236
+
237
+ customProgramCacheKey() {
238
+
239
+ return this._graphFunctionSnippet;
240
+
241
+ }
242
+
243
+ }
@@ -1,48 +1,50 @@
1
- import { NoBlending } from 'three';
2
- import { MaterialBase } from '../MaterialBase.js';
3
-
4
- export class AlphaDisplayMaterial extends MaterialBase {
5
-
6
- constructor( parameters ) {
7
-
8
- super( {
9
-
10
- uniforms: {
11
-
12
- map: { value: null },
13
-
14
- },
15
-
16
- blending: NoBlending,
17
-
18
- vertexShader: /* glsl */`
19
-
20
- varying vec2 vUv;
21
-
22
- void main() {
23
-
24
- vUv = uv;
25
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
26
-
27
- }`,
28
-
29
- fragmentShader: /* glsl */`
30
-
31
- uniform sampler2D map;
32
-
33
- varying vec2 vUv;
34
-
35
- void main() {
36
-
37
- gl_FragColor = vec4( texture( map, vUv ).a );
38
- gl_FragColor.a = 1.0;
39
-
40
- }`
41
-
42
- } );
43
-
44
- this.setValues( parameters );
45
-
46
- }
47
-
48
- }
1
+ import { NoBlending } from 'three';
2
+ import { MaterialBase } from '../MaterialBase.js';
3
+
4
+ export class AlphaDisplayMaterial extends MaterialBase {
5
+
6
+ constructor( parameters ) {
7
+
8
+ super( {
9
+
10
+ uniforms: {
11
+
12
+ map: { value: null },
13
+
14
+ },
15
+
16
+ blending: NoBlending,
17
+
18
+ vertexShader: /* glsl */`
19
+
20
+ varying vec2 vUv;
21
+
22
+ void main() {
23
+
24
+ vUv = uv;
25
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
26
+
27
+ }`,
28
+
29
+ fragmentShader: /* glsl */`
30
+
31
+ uniform sampler2D map;
32
+
33
+ varying vec2 vUv;
34
+
35
+ void main() {
36
+
37
+ gl_FragColor = vec4( texture( map, vUv ).a );
38
+ gl_FragColor.a = 1.0;
39
+
40
+ #include <encodings_fragment>
41
+
42
+ }`
43
+
44
+ } );
45
+
46
+ this.setValues( parameters );
47
+
48
+ }
49
+
50
+ }