three-gpu-pathtracer 0.0.13 → 0.0.14

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 (78) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +981 -961
  3. package/build/index.module.js +6965 -6508
  4. package/build/index.module.js.map +1 -1
  5. package/build/index.umd.cjs +6959 -6505
  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/index.js +36 -40
  14. package/src/materials/MaterialBase.js +56 -56
  15. package/src/materials/{GraphMaterial.js → debug/GraphMaterial.js} +243 -243
  16. package/src/materials/{AlphaDisplayMaterial.js → fullscreen/AlphaDisplayMaterial.js} +48 -48
  17. package/src/materials/{BlendMaterial.js → fullscreen/BlendMaterial.js} +67 -67
  18. package/src/materials/{DenoiseMaterial.js → fullscreen/DenoiseMaterial.js} +142 -142
  19. package/src/materials/{LambertPathTracingMaterial.js → pathtracing/LambertPathTracingMaterial.js} +296 -285
  20. package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +635 -0
  21. package/src/materials/pathtracing/glsl/attenuateHit.glsl.js +179 -0
  22. package/src/materials/pathtracing/glsl/cameraUtils.glsl.js +81 -0
  23. package/src/materials/pathtracing/glsl/getSurfaceRecord.glsl.js +317 -0
  24. package/src/materials/pathtracing/glsl/traceScene.glsl.js +54 -0
  25. package/src/materials/{AmbientOcclusionMaterial.js → surface/AmbientOcclusionMaterial.js} +207 -199
  26. package/src/materials/surface/FogVolumeMaterial.js +23 -0
  27. package/src/objects/EquirectCamera.js +13 -13
  28. package/src/objects/PhysicalCamera.js +28 -28
  29. package/src/objects/PhysicalSpotLight.js +14 -14
  30. package/src/objects/ShapedAreaLight.js +12 -12
  31. package/src/shader/bsdf/bsdfSampling.glsl.js +490 -0
  32. package/src/shader/bsdf/fog.glsl.js +23 -0
  33. package/src/shader/bsdf/ggx.glsl.js +102 -0
  34. package/src/shader/bsdf/iridescence.glsl.js +135 -0
  35. package/src/shader/bsdf/sheen.glsl.js +98 -0
  36. package/src/shader/{shaderLayerTexelFetchFunctions.js → common/arraySamplerTexelFetch.glsl.js} +25 -25
  37. package/src/shader/common/bvhAnyHit.glsl.js +76 -0
  38. package/src/shader/common/fresnel.glsl.js +98 -0
  39. package/src/shader/common/intersectShapes.glsl.js +62 -0
  40. package/src/shader/common/math.glsl.js +81 -0
  41. package/src/shader/common/utils.glsl.js +116 -0
  42. package/src/shader/{shaderRandFunctions.js → rand/pcg.glsl.js} +57 -57
  43. package/src/shader/{shaderSobolSampling.js → rand/sobol.glsl.js} +256 -256
  44. package/src/shader/sampling/equirectSampling.glsl.js +62 -0
  45. package/src/shader/sampling/lightSampling.glsl.js +223 -0
  46. package/src/shader/sampling/shapeSampling.glsl.js +86 -0
  47. package/src/shader/structs/cameraStruct.glsl.js +13 -0
  48. package/src/shader/structs/equirectStruct.glsl.js +14 -0
  49. package/src/shader/structs/fogMaterialBvh.glsl.js +62 -0
  50. package/src/shader/structs/lightsStruct.glsl.js +78 -0
  51. package/src/shader/{shaderStructs.js → structs/materialStruct.glsl.js} +207 -327
  52. package/src/textures/GradientEquirectTexture.js +35 -35
  53. package/src/textures/ProceduralEquirectTexture.js +75 -75
  54. package/src/uniforms/AttributesTextureArray.js +35 -35
  55. package/src/uniforms/EquirectHdrInfoUniform.js +277 -273
  56. package/src/uniforms/FloatAttributeTextureArray.js +169 -169
  57. package/src/uniforms/IESProfilesTexture.js +100 -100
  58. package/src/uniforms/LightsInfoUniformStruct.js +212 -212
  59. package/src/uniforms/MaterialsTexture.js +503 -426
  60. package/src/uniforms/PhysicalCameraUniform.js +36 -36
  61. package/src/uniforms/RenderTarget2DArray.js +97 -97
  62. package/src/uniforms/utils.js +30 -30
  63. package/src/utils/BlurredEnvMapGenerator.js +116 -116
  64. package/src/utils/GeometryPreparationUtils.js +214 -214
  65. package/src/utils/IESLoader.js +325 -325
  66. package/src/utils/SobolNumberMapGenerator.js +80 -80
  67. package/src/utils/UVUnwrapper.js +101 -101
  68. package/src/utils/macroify.js +9 -0
  69. package/src/workers/PathTracingSceneWorker.js +42 -42
  70. package/src/materials/PhysicalPathTracingMaterial.js +0 -1013
  71. package/src/shader/shaderBvhAnyHit.js +0 -76
  72. package/src/shader/shaderEnvMapSampling.js +0 -58
  73. package/src/shader/shaderGGXFunctions.js +0 -100
  74. package/src/shader/shaderIridescenceFunctions.js +0 -135
  75. package/src/shader/shaderLightSampling.js +0 -229
  76. package/src/shader/shaderMaterialSampling.js +0 -510
  77. package/src/shader/shaderSheenFunctions.js +0 -98
  78. package/src/shader/shaderUtils.js +0 -377
@@ -1,212 +1,212 @@
1
- import { DataTexture, RGBAFormat, ClampToEdgeWrapping, FloatType, Vector3, Quaternion, Matrix4 } from 'three';
2
-
3
- const LIGHT_PIXELS = 6;
4
- const RECT_AREA_LIGHT = 0;
5
- const CIRC_AREA_LIGHT = 1;
6
- const SPOT_LIGHT = 2;
7
- const DIR_LIGHT = 3;
8
- const POINT_LIGHT = 4;
9
- export class LightsInfoUniformStruct {
10
-
11
- constructor() {
12
-
13
- const tex = new DataTexture( new Float32Array( 4 ), 1, 1 );
14
- tex.format = RGBAFormat;
15
- tex.type = FloatType;
16
- tex.wrapS = ClampToEdgeWrapping;
17
- tex.wrapT = ClampToEdgeWrapping;
18
- tex.generateMipmaps = false;
19
-
20
- this.tex = tex;
21
- this.count = 0;
22
-
23
- }
24
-
25
- updateFrom( lights, iesTextures = [] ) {
26
-
27
- const tex = this.tex;
28
- const pixelCount = Math.max( lights.length * LIGHT_PIXELS, 1 );
29
- const dimension = Math.ceil( Math.sqrt( pixelCount ) );
30
-
31
- if ( tex.image.width !== dimension ) {
32
-
33
- tex.dispose();
34
-
35
- tex.image.data = new Float32Array( dimension * dimension * 4 );
36
- tex.image.width = dimension;
37
- tex.image.height = dimension;
38
-
39
- }
40
-
41
- const floatArray = tex.image.data;
42
-
43
- const u = new Vector3();
44
- const v = new Vector3();
45
- const m = new Matrix4();
46
- const worldQuaternion = new Quaternion();
47
- const eye = new Vector3();
48
- const target = new Vector3();
49
- const up = new Vector3();
50
-
51
- for ( let i = 0, l = lights.length; i < l; i ++ ) {
52
-
53
- const l = lights[ i ];
54
-
55
- const baseIndex = i * LIGHT_PIXELS * 4;
56
- let index = 0;
57
-
58
- // sample 1
59
- // position
60
- l.getWorldPosition( v );
61
- floatArray[ baseIndex + ( index ++ ) ] = v.x;
62
- floatArray[ baseIndex + ( index ++ ) ] = v.y;
63
- floatArray[ baseIndex + ( index ++ ) ] = v.z;
64
-
65
- // type
66
- let type = RECT_AREA_LIGHT;
67
- if ( l.isRectAreaLight && l.isCircular ) {
68
-
69
- type = CIRC_AREA_LIGHT;
70
-
71
- } else if ( l.isSpotLight ) {
72
-
73
- type = SPOT_LIGHT;
74
-
75
- } else if ( l.isDirectionalLight ) {
76
-
77
- type = DIR_LIGHT;
78
-
79
- } else if ( l.isPointLight ) {
80
-
81
- type = POINT_LIGHT;
82
-
83
- }
84
-
85
- floatArray[ baseIndex + ( index ++ ) ] = type;
86
-
87
- // sample 2
88
- // color
89
- floatArray[ baseIndex + ( index ++ ) ] = l.color.r;
90
- floatArray[ baseIndex + ( index ++ ) ] = l.color.g;
91
- floatArray[ baseIndex + ( index ++ ) ] = l.color.b;
92
-
93
- // intensity
94
- floatArray[ baseIndex + ( index ++ ) ] = l.intensity;
95
-
96
- l.getWorldQuaternion( worldQuaternion );
97
-
98
- if ( l.isRectAreaLight ) {
99
-
100
- // sample 3
101
- // u vector
102
- u.set( l.width, 0, 0 ).applyQuaternion( worldQuaternion );
103
-
104
- floatArray[ baseIndex + ( index ++ ) ] = u.x;
105
- floatArray[ baseIndex + ( index ++ ) ] = u.y;
106
- floatArray[ baseIndex + ( index ++ ) ] = u.z;
107
- index ++;
108
-
109
- // sample 4
110
- // v vector
111
- v.set( 0, l.height, 0 ).applyQuaternion( worldQuaternion );
112
-
113
- floatArray[ baseIndex + ( index ++ ) ] = v.x;
114
- floatArray[ baseIndex + ( index ++ ) ] = v.y;
115
- floatArray[ baseIndex + ( index ++ ) ] = v.z;
116
-
117
- // area
118
- floatArray[ baseIndex + ( index ++ ) ] = u.cross( v ).length() * ( l.isCircular ? ( Math.PI / 4.0 ) : 1.0 );
119
-
120
- } else if ( l.isSpotLight ) {
121
-
122
- const radius = l.radius;
123
- eye.setFromMatrixPosition( l.matrixWorld );
124
- target.setFromMatrixPosition( l.target.matrixWorld );
125
- m.lookAt( eye, target, up );
126
- worldQuaternion.setFromRotationMatrix( m );
127
-
128
- // sample 3
129
- // u vector
130
- u.set( 1, 0, 0 ).applyQuaternion( worldQuaternion );
131
-
132
- floatArray[ baseIndex + ( index ++ ) ] = u.x;
133
- floatArray[ baseIndex + ( index ++ ) ] = u.y;
134
- floatArray[ baseIndex + ( index ++ ) ] = u.z;
135
- index ++;
136
-
137
- // sample 4
138
- // v vector
139
- v.set( 0, 1, 0 ).applyQuaternion( worldQuaternion );
140
-
141
- floatArray[ baseIndex + ( index ++ ) ] = v.x;
142
- floatArray[ baseIndex + ( index ++ ) ] = v.y;
143
- floatArray[ baseIndex + ( index ++ ) ] = v.z;
144
-
145
- // area
146
- floatArray[ baseIndex + ( index ++ ) ] = Math.PI * radius * radius;
147
-
148
- // sample 5
149
- // radius
150
- floatArray[ baseIndex + ( index ++ ) ] = radius;
151
-
152
- // near
153
- floatArray[ baseIndex + ( index ++ ) ] = l.shadow.camera.near;
154
-
155
- // decay
156
- floatArray[ baseIndex + ( index ++ ) ] = l.decay;
157
-
158
- // distance
159
- floatArray[ baseIndex + ( index ++ ) ] = l.distance;
160
-
161
- // sample 6
162
- // coneCos
163
- floatArray[ baseIndex + ( index ++ ) ] = Math.cos( l.angle );
164
-
165
- // penumbraCos
166
- floatArray[ baseIndex + ( index ++ ) ] = Math.cos( l.angle * ( 1 - l.penumbra ) );
167
-
168
- // iesProfile
169
- floatArray[ baseIndex + ( index ++ ) ] = iesTextures.indexOf( l.iesTexture );
170
-
171
- } else if ( l.isPointLight ) {
172
-
173
- const worldPosition = u.setFromMatrixPosition( l.matrixWorld );
174
-
175
- // sample 3
176
- // u vector
177
- floatArray[ baseIndex + ( index ++ ) ] = worldPosition.x;
178
- floatArray[ baseIndex + ( index ++ ) ] = worldPosition.y;
179
- floatArray[ baseIndex + ( index ++ ) ] = worldPosition.z;
180
- index ++;
181
-
182
- // sample 4
183
- index += 4;
184
-
185
- // sample 5
186
- index += 2;
187
-
188
- floatArray[ baseIndex + ( index ++ ) ] = l.decay;
189
- floatArray[ baseIndex + ( index ++ ) ] = l.distance;
190
-
191
- } else if ( l.isDirectionalLight ) {
192
-
193
- const worldPosition = u.setFromMatrixPosition( l.matrixWorld );
194
- const targetPosition = v.setFromMatrixPosition( l.target.matrixWorld );
195
- target.subVectors( worldPosition, targetPosition ).normalize();
196
-
197
- // sample 3
198
- // u vector
199
- floatArray[ baseIndex + ( index ++ ) ] = target.x;
200
- floatArray[ baseIndex + ( index ++ ) ] = target.y;
201
- floatArray[ baseIndex + ( index ++ ) ] = target.z;
202
-
203
- }
204
-
205
- }
206
-
207
- tex.needsUpdate = true;
208
- this.count = lights.length;
209
-
210
- }
211
-
212
- }
1
+ import { DataTexture, RGBAFormat, ClampToEdgeWrapping, FloatType, Vector3, Quaternion, Matrix4 } from 'three';
2
+
3
+ const LIGHT_PIXELS = 6;
4
+ const RECT_AREA_LIGHT = 0;
5
+ const CIRC_AREA_LIGHT = 1;
6
+ const SPOT_LIGHT = 2;
7
+ const DIR_LIGHT = 3;
8
+ const POINT_LIGHT = 4;
9
+ export class LightsInfoUniformStruct {
10
+
11
+ constructor() {
12
+
13
+ const tex = new DataTexture( new Float32Array( 4 ), 1, 1 );
14
+ tex.format = RGBAFormat;
15
+ tex.type = FloatType;
16
+ tex.wrapS = ClampToEdgeWrapping;
17
+ tex.wrapT = ClampToEdgeWrapping;
18
+ tex.generateMipmaps = false;
19
+
20
+ this.tex = tex;
21
+ this.count = 0;
22
+
23
+ }
24
+
25
+ updateFrom( lights, iesTextures = [] ) {
26
+
27
+ const tex = this.tex;
28
+ const pixelCount = Math.max( lights.length * LIGHT_PIXELS, 1 );
29
+ const dimension = Math.ceil( Math.sqrt( pixelCount ) );
30
+
31
+ if ( tex.image.width !== dimension ) {
32
+
33
+ tex.dispose();
34
+
35
+ tex.image.data = new Float32Array( dimension * dimension * 4 );
36
+ tex.image.width = dimension;
37
+ tex.image.height = dimension;
38
+
39
+ }
40
+
41
+ const floatArray = tex.image.data;
42
+
43
+ const u = new Vector3();
44
+ const v = new Vector3();
45
+ const m = new Matrix4();
46
+ const worldQuaternion = new Quaternion();
47
+ const eye = new Vector3();
48
+ const target = new Vector3();
49
+ const up = new Vector3();
50
+
51
+ for ( let i = 0, l = lights.length; i < l; i ++ ) {
52
+
53
+ const l = lights[ i ];
54
+
55
+ const baseIndex = i * LIGHT_PIXELS * 4;
56
+ let index = 0;
57
+
58
+ // sample 1
59
+ // position
60
+ l.getWorldPosition( v );
61
+ floatArray[ baseIndex + ( index ++ ) ] = v.x;
62
+ floatArray[ baseIndex + ( index ++ ) ] = v.y;
63
+ floatArray[ baseIndex + ( index ++ ) ] = v.z;
64
+
65
+ // type
66
+ let type = RECT_AREA_LIGHT;
67
+ if ( l.isRectAreaLight && l.isCircular ) {
68
+
69
+ type = CIRC_AREA_LIGHT;
70
+
71
+ } else if ( l.isSpotLight ) {
72
+
73
+ type = SPOT_LIGHT;
74
+
75
+ } else if ( l.isDirectionalLight ) {
76
+
77
+ type = DIR_LIGHT;
78
+
79
+ } else if ( l.isPointLight ) {
80
+
81
+ type = POINT_LIGHT;
82
+
83
+ }
84
+
85
+ floatArray[ baseIndex + ( index ++ ) ] = type;
86
+
87
+ // sample 2
88
+ // color
89
+ floatArray[ baseIndex + ( index ++ ) ] = l.color.r;
90
+ floatArray[ baseIndex + ( index ++ ) ] = l.color.g;
91
+ floatArray[ baseIndex + ( index ++ ) ] = l.color.b;
92
+
93
+ // intensity
94
+ floatArray[ baseIndex + ( index ++ ) ] = l.intensity;
95
+
96
+ l.getWorldQuaternion( worldQuaternion );
97
+
98
+ if ( l.isRectAreaLight ) {
99
+
100
+ // sample 3
101
+ // u vector
102
+ u.set( l.width, 0, 0 ).applyQuaternion( worldQuaternion );
103
+
104
+ floatArray[ baseIndex + ( index ++ ) ] = u.x;
105
+ floatArray[ baseIndex + ( index ++ ) ] = u.y;
106
+ floatArray[ baseIndex + ( index ++ ) ] = u.z;
107
+ index ++;
108
+
109
+ // sample 4
110
+ // v vector
111
+ v.set( 0, l.height, 0 ).applyQuaternion( worldQuaternion );
112
+
113
+ floatArray[ baseIndex + ( index ++ ) ] = v.x;
114
+ floatArray[ baseIndex + ( index ++ ) ] = v.y;
115
+ floatArray[ baseIndex + ( index ++ ) ] = v.z;
116
+
117
+ // area
118
+ floatArray[ baseIndex + ( index ++ ) ] = u.cross( v ).length() * ( l.isCircular ? ( Math.PI / 4.0 ) : 1.0 );
119
+
120
+ } else if ( l.isSpotLight ) {
121
+
122
+ const radius = l.radius;
123
+ eye.setFromMatrixPosition( l.matrixWorld );
124
+ target.setFromMatrixPosition( l.target.matrixWorld );
125
+ m.lookAt( eye, target, up );
126
+ worldQuaternion.setFromRotationMatrix( m );
127
+
128
+ // sample 3
129
+ // u vector
130
+ u.set( 1, 0, 0 ).applyQuaternion( worldQuaternion );
131
+
132
+ floatArray[ baseIndex + ( index ++ ) ] = u.x;
133
+ floatArray[ baseIndex + ( index ++ ) ] = u.y;
134
+ floatArray[ baseIndex + ( index ++ ) ] = u.z;
135
+ index ++;
136
+
137
+ // sample 4
138
+ // v vector
139
+ v.set( 0, 1, 0 ).applyQuaternion( worldQuaternion );
140
+
141
+ floatArray[ baseIndex + ( index ++ ) ] = v.x;
142
+ floatArray[ baseIndex + ( index ++ ) ] = v.y;
143
+ floatArray[ baseIndex + ( index ++ ) ] = v.z;
144
+
145
+ // area
146
+ floatArray[ baseIndex + ( index ++ ) ] = Math.PI * radius * radius;
147
+
148
+ // sample 5
149
+ // radius
150
+ floatArray[ baseIndex + ( index ++ ) ] = radius;
151
+
152
+ // near
153
+ floatArray[ baseIndex + ( index ++ ) ] = l.shadow.camera.near;
154
+
155
+ // decay
156
+ floatArray[ baseIndex + ( index ++ ) ] = l.decay;
157
+
158
+ // distance
159
+ floatArray[ baseIndex + ( index ++ ) ] = l.distance;
160
+
161
+ // sample 6
162
+ // coneCos
163
+ floatArray[ baseIndex + ( index ++ ) ] = Math.cos( l.angle );
164
+
165
+ // penumbraCos
166
+ floatArray[ baseIndex + ( index ++ ) ] = Math.cos( l.angle * ( 1 - l.penumbra ) );
167
+
168
+ // iesProfile
169
+ floatArray[ baseIndex + ( index ++ ) ] = iesTextures.indexOf( l.iesTexture );
170
+
171
+ } else if ( l.isPointLight ) {
172
+
173
+ const worldPosition = u.setFromMatrixPosition( l.matrixWorld );
174
+
175
+ // sample 3
176
+ // u vector
177
+ floatArray[ baseIndex + ( index ++ ) ] = worldPosition.x;
178
+ floatArray[ baseIndex + ( index ++ ) ] = worldPosition.y;
179
+ floatArray[ baseIndex + ( index ++ ) ] = worldPosition.z;
180
+ index ++;
181
+
182
+ // sample 4
183
+ index += 4;
184
+
185
+ // sample 5
186
+ index += 2;
187
+
188
+ floatArray[ baseIndex + ( index ++ ) ] = l.decay;
189
+ floatArray[ baseIndex + ( index ++ ) ] = l.distance;
190
+
191
+ } else if ( l.isDirectionalLight ) {
192
+
193
+ const worldPosition = u.setFromMatrixPosition( l.matrixWorld );
194
+ const targetPosition = v.setFromMatrixPosition( l.target.matrixWorld );
195
+ target.subVectors( worldPosition, targetPosition ).normalize();
196
+
197
+ // sample 3
198
+ // u vector
199
+ floatArray[ baseIndex + ( index ++ ) ] = target.x;
200
+ floatArray[ baseIndex + ( index ++ ) ] = target.y;
201
+ floatArray[ baseIndex + ( index ++ ) ] = target.z;
202
+
203
+ }
204
+
205
+ }
206
+
207
+ tex.needsUpdate = true;
208
+ this.count = lights.length;
209
+
210
+ }
211
+
212
+ }