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.
Files changed (51) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +886 -815
  3. package/build/index.module.js +6374 -5613
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +6377 -5615
  6. package/build/index.umd.cjs.map +1 -1
  7. package/package.json +69 -68
  8. package/src/core/DynamicPathTracingSceneGenerator.js +119 -119
  9. package/src/core/MaterialReducer.js +256 -256
  10. package/src/core/PathTracingRenderer.js +275 -270
  11. package/src/core/PathTracingSceneGenerator.js +1 -1
  12. package/src/index.js +39 -35
  13. package/src/materials/AlphaDisplayMaterial.js +48 -48
  14. package/src/materials/AmbientOcclusionMaterial.js +199 -197
  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 -970
  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/shaderEnvMapSampling.js +58 -59
  26. package/src/shader/shaderGGXFunctions.js +100 -100
  27. package/src/shader/shaderIridescenceFunctions.js +130 -130
  28. package/src/shader/shaderLayerTexelFetchFunctions.js +25 -0
  29. package/src/shader/shaderLightSampling.js +229 -231
  30. package/src/shader/shaderMaterialSampling.js +498 -542
  31. package/src/shader/shaderRandFunctions.js +57 -0
  32. package/src/shader/shaderSheenFunctions.js +98 -98
  33. package/src/shader/shaderSobolSampling.js +256 -0
  34. package/src/shader/shaderStructs.js +325 -321
  35. package/src/shader/shaderUtils.js +361 -364
  36. package/src/textures/GradientEquirectTexture.js +35 -0
  37. package/src/textures/ProceduralEquirectTexture.js +75 -0
  38. package/src/uniforms/AttributesTextureArray.js +35 -0
  39. package/src/uniforms/EquirectHdrInfoUniform.js +259 -259
  40. package/src/uniforms/FloatAttributeTextureArray.js +169 -0
  41. package/src/uniforms/IESProfilesTexture.js +100 -100
  42. package/src/uniforms/LightsInfoUniformStruct.js +207 -162
  43. package/src/uniforms/MaterialsTexture.js +426 -426
  44. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  45. package/src/uniforms/RenderTarget2DArray.js +97 -93
  46. package/src/uniforms/utils.js +30 -0
  47. package/src/utils/BlurredEnvMapGenerator.js +116 -113
  48. package/src/utils/IESLoader.js +325 -325
  49. package/src/utils/SobolNumberMapGenerator.js +80 -0
  50. package/src/utils/UVUnwrapper.js +101 -101
  51. 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
+ }