three-gpu-pathtracer 0.0.20 → 0.0.21
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.
- package/README.md +111 -464
- package/build/index.module.js +5691 -5312
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +5369 -5003
- package/build/index.umd.cjs.map +1 -1
- package/package.json +12 -6
- package/src/core/PathTracingRenderer.js +59 -46
- package/src/core/PathTracingSceneGenerator.js +245 -10
- package/src/core/WebGLPathTracer.js +472 -0
- package/src/core/utils/BakedGeometry.js +35 -0
- package/src/core/utils/BufferAttributeUtils.js +64 -0
- package/src/{utils → core/utils}/GeometryPreparationUtils.js +35 -35
- package/src/core/utils/MeshDiff.js +102 -0
- package/src/core/utils/StaticGeometryGenerator.js +285 -0
- package/src/core/utils/convertToStaticGeometry.js +344 -0
- package/src/core/utils/mergeGeometries.js +218 -0
- package/src/core/utils/sceneUpdateUtils.js +96 -0
- package/src/index.d.ts +274 -0
- package/src/index.js +4 -20
- package/src/materials/MaterialBase.js +4 -0
- package/src/materials/fullscreen/ClampedInterpolationMaterial.js +112 -0
- package/src/materials/fullscreen/DenoiseMaterial.js +4 -0
- package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +73 -76
- package/src/materials/pathtracing/glsl/{attenuateHit.glsl.js → attenuate_hit_function.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/{cameraUtils.glsl.js → camera_util_functions.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/{directLightContribution.glsl.js → direct_light_contribution_function.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/{getSurfaceRecord.glsl.js → get_surface_record_function.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/index.js +6 -0
- package/src/materials/pathtracing/glsl/{renderStructs.glsl.js → render_structs.glsl.js} +1 -1
- package/src/materials/pathtracing/glsl/{traceScene.glsl.js → trace_scene_function.glsl.js} +1 -3
- package/src/materials/surface/AmbientOcclusionMaterial.js +8 -8
- package/src/objects/PhysicalSpotLight.js +2 -2
- package/src/shader/bsdf/{bsdfSampling.glsl.js → bsdf_functions.glsl.js} +19 -72
- package/src/shader/bsdf/{fog.glsl.js → fog_functions.glsl.js} +1 -1
- package/src/shader/bsdf/{ggx.glsl.js → ggx_functions.glsl.js} +1 -1
- package/src/shader/bsdf/index.js +5 -0
- package/src/shader/bsdf/{iridescence.glsl.js → iridescence_functions.glsl.js} +1 -1
- package/src/shader/bsdf/{sheen.glsl.js → sheen_functions.glsl.js} +1 -1
- package/src/shader/bvh/index.js +2 -0
- package/src/shader/{structs/fogMaterialBvh.glsl.js → bvh/inside_fog_volume_function.glsl.js} +1 -1
- package/src/shader/{common/bvhAnyHit.glsl.js → bvh/ray_any_hit_function.glsl.js} +1 -1
- package/src/shader/common/{fresnel.glsl.js → fresnel_functions.glsl.js} +1 -1
- package/src/shader/common/index.js +5 -0
- package/src/shader/common/{math.glsl.js → math_functions.glsl.js} +1 -1
- package/src/shader/common/{intersectShapes.glsl.js → shape_intersection_functions.glsl.js} +1 -1
- package/src/shader/common/{arraySamplerTexelFetch.glsl.js → texture_sample_functions.glsl.js} +1 -1
- package/src/shader/common/{utils.glsl.js → util_functions.glsl.js} +1 -1
- package/src/shader/rand/index.js +3 -0
- package/src/shader/rand/pcg.glsl.js +1 -1
- package/src/shader/rand/sobol.glsl.js +4 -4
- package/src/shader/rand/{stratifiedTexture.glsl.js → stratified.glsl.js} +7 -2
- package/src/shader/sampling/{equirectSampling.glsl.js → equirect_sampling_functions.glsl.js} +1 -2
- package/src/shader/sampling/index.js +3 -0
- package/src/shader/sampling/{lightSampling.glsl.js → light_sampling_functions.glsl.js} +3 -3
- package/src/shader/sampling/{shapeSampling.glsl.js → shape_sampling_functions.glsl.js} +1 -1
- package/src/shader/structs/{cameraStruct.glsl.js → camera_struct.glsl.js} +1 -1
- package/src/shader/structs/{equirectStruct.glsl.js → equirect_struct.glsl.js} +1 -1
- package/src/shader/structs/index.js +5 -0
- package/src/shader/structs/{lightsStruct.glsl.js → lights_struct.glsl.js} +1 -1
- package/src/shader/structs/{materialStruct.glsl.js → material_struct.glsl.js} +2 -2
- package/src/shader/structs/surface_record_struct.glsl.js +63 -0
- package/src/uniforms/EquirectHdrInfoUniform.js +16 -11
- package/src/uniforms/LightsInfoUniformStruct.js +21 -10
- package/src/uniforms/MaterialsTexture.js +27 -86
- package/src/uniforms/RenderTarget2DArray.js +60 -20
- package/src/utils/BlurredEnvMapGenerator.js +12 -5
- package/src/utils/SobolNumberMapGenerator.js +3 -3
- package/src/utils/bufferToHash.js +22 -0
- package/src/core/DynamicPathTracingSceneGenerator.js +0 -164
- package/src/core/MaterialReducer.js +0 -256
- package/src/materials/pathtracing/LambertPathTracingMaterial.js +0 -297
- package/src/uniforms/IESProfilesTexture.js +0 -100
- package/src/uniforms/utils.js +0 -30
- package/src/utils/IESLoader.js +0 -327
- package/src/workers/PathTracingSceneWorker.js +0 -52
package/src/utils/IESLoader.js
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DataTexture,
|
|
3
|
-
FileLoader,
|
|
4
|
-
HalfFloatType,
|
|
5
|
-
LinearFilter,
|
|
6
|
-
RedFormat,
|
|
7
|
-
MathUtils,
|
|
8
|
-
Loader,
|
|
9
|
-
} from 'three';
|
|
10
|
-
|
|
11
|
-
import { toHalfFloatArray } from './TextureUtils.js';
|
|
12
|
-
|
|
13
|
-
function IESLamp( text ) {
|
|
14
|
-
|
|
15
|
-
const _self = this;
|
|
16
|
-
|
|
17
|
-
const textArray = text.split( '\n' );
|
|
18
|
-
|
|
19
|
-
let lineNumber = 0;
|
|
20
|
-
let line;
|
|
21
|
-
|
|
22
|
-
_self.verAngles = [ ];
|
|
23
|
-
_self.horAngles = [ ];
|
|
24
|
-
|
|
25
|
-
_self.candelaValues = [ ];
|
|
26
|
-
|
|
27
|
-
_self.tiltData = { };
|
|
28
|
-
_self.tiltData.angles = [ ];
|
|
29
|
-
_self.tiltData.mulFactors = [ ];
|
|
30
|
-
|
|
31
|
-
function textToArray( text ) {
|
|
32
|
-
|
|
33
|
-
text = text.trim(); // remove leading or trailing spaces
|
|
34
|
-
text = text.replace( /,/g, ' ' ); // replace commas with spaces
|
|
35
|
-
text = text.replace( /\s\s+/g, ' ' ); // replace white space/tabs etc by single whitespace
|
|
36
|
-
|
|
37
|
-
const array = text.split( ' ' );
|
|
38
|
-
|
|
39
|
-
return array;
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function readArray( count, array ) {
|
|
44
|
-
|
|
45
|
-
while ( true ) {
|
|
46
|
-
|
|
47
|
-
const line = textArray[ lineNumber ++ ];
|
|
48
|
-
const lineData = textToArray( line );
|
|
49
|
-
|
|
50
|
-
for ( let i = 0; i < lineData.length; ++ i ) {
|
|
51
|
-
|
|
52
|
-
array.push( Number( lineData[ i ] ) );
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if ( array.length === count )
|
|
57
|
-
break;
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function readTilt() {
|
|
64
|
-
|
|
65
|
-
let line = textArray[ lineNumber ++ ];
|
|
66
|
-
let lineData = textToArray( line );
|
|
67
|
-
|
|
68
|
-
_self.tiltData.lampToLumGeometry = Number( lineData[ 0 ] );
|
|
69
|
-
|
|
70
|
-
line = textArray[ lineNumber ++ ];
|
|
71
|
-
lineData = textToArray( line );
|
|
72
|
-
|
|
73
|
-
_self.tiltData.numAngles = Number( lineData[ 0 ] );
|
|
74
|
-
|
|
75
|
-
readArray( _self.tiltData.numAngles, _self.tiltData.angles );
|
|
76
|
-
readArray( _self.tiltData.numAngles, _self.tiltData.mulFactors );
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function readLampValues() {
|
|
81
|
-
|
|
82
|
-
const values = [ ];
|
|
83
|
-
readArray( 10, values );
|
|
84
|
-
|
|
85
|
-
_self.count = Number( values[ 0 ] );
|
|
86
|
-
_self.lumens = Number( values[ 1 ] );
|
|
87
|
-
_self.multiplier = Number( values[ 2 ] );
|
|
88
|
-
_self.numVerAngles = Number( values[ 3 ] );
|
|
89
|
-
_self.numHorAngles = Number( values[ 4 ] );
|
|
90
|
-
_self.gonioType = Number( values[ 5 ] );
|
|
91
|
-
_self.units = Number( values[ 6 ] );
|
|
92
|
-
_self.width = Number( values[ 7 ] );
|
|
93
|
-
_self.length = Number( values[ 8 ] );
|
|
94
|
-
_self.height = Number( values[ 9 ] );
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function readLampFactors() {
|
|
99
|
-
|
|
100
|
-
const values = [ ];
|
|
101
|
-
readArray( 3, values );
|
|
102
|
-
|
|
103
|
-
_self.ballFactor = Number( values[ 0 ] );
|
|
104
|
-
_self.blpFactor = Number( values[ 1 ] );
|
|
105
|
-
_self.inputWatts = Number( values[ 2 ] );
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
while ( true ) {
|
|
110
|
-
|
|
111
|
-
line = textArray[ lineNumber ++ ];
|
|
112
|
-
|
|
113
|
-
if ( line.includes( 'TILT' ) ) {
|
|
114
|
-
|
|
115
|
-
break;
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if ( ! line.includes( 'NONE' ) ) {
|
|
122
|
-
|
|
123
|
-
if ( line.includes( 'INCLUDE' ) ) {
|
|
124
|
-
|
|
125
|
-
readTilt();
|
|
126
|
-
|
|
127
|
-
} else {
|
|
128
|
-
|
|
129
|
-
// TODO:: Read tilt data from a file
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
readLampValues();
|
|
136
|
-
|
|
137
|
-
readLampFactors();
|
|
138
|
-
|
|
139
|
-
// Initialize candela value array
|
|
140
|
-
for ( let i = 0; i < _self.numHorAngles; ++ i ) {
|
|
141
|
-
|
|
142
|
-
_self.candelaValues.push( [ ] );
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Parse Angles
|
|
147
|
-
readArray( _self.numVerAngles, _self.verAngles );
|
|
148
|
-
readArray( _self.numHorAngles, _self.horAngles );
|
|
149
|
-
|
|
150
|
-
// Parse Candela values
|
|
151
|
-
for ( let i = 0; i < _self.numHorAngles; ++ i ) {
|
|
152
|
-
|
|
153
|
-
readArray( _self.numVerAngles, _self.candelaValues[ i ] );
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Calculate actual candela values, and normalize.
|
|
158
|
-
for ( let i = 0; i < _self.numHorAngles; ++ i ) {
|
|
159
|
-
|
|
160
|
-
for ( let j = 0; j < _self.numVerAngles; ++ j ) {
|
|
161
|
-
|
|
162
|
-
_self.candelaValues[ i ][ j ] *= _self.candelaValues[ i ][ j ] * _self.multiplier
|
|
163
|
-
* _self.ballFactor * _self.blpFactor;
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
let maxVal = - 1;
|
|
170
|
-
for ( let i = 0; i < _self.numHorAngles; ++ i ) {
|
|
171
|
-
|
|
172
|
-
for ( let j = 0; j < _self.numVerAngles; ++ j ) {
|
|
173
|
-
|
|
174
|
-
const value = _self.candelaValues[ i ][ j ];
|
|
175
|
-
maxVal = maxVal < value ? value : maxVal;
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const bNormalize = true;
|
|
182
|
-
if ( bNormalize && maxVal > 0 ) {
|
|
183
|
-
|
|
184
|
-
for ( let i = 0; i < _self.numHorAngles; ++ i ) {
|
|
185
|
-
|
|
186
|
-
for ( let j = 0; j < _self.numVerAngles; ++ j ) {
|
|
187
|
-
|
|
188
|
-
_self.candelaValues[ i ][ j ] /= maxVal;
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export class IESLoader extends Loader {
|
|
199
|
-
|
|
200
|
-
_getIESValues( iesLamp ) {
|
|
201
|
-
|
|
202
|
-
const width = 360;
|
|
203
|
-
const height = 180;
|
|
204
|
-
const size = width * height;
|
|
205
|
-
|
|
206
|
-
const data = new Float32Array( size );
|
|
207
|
-
|
|
208
|
-
function interpolateCandelaValues( phi, theta ) {
|
|
209
|
-
|
|
210
|
-
let phiIndex = 0, thetaIndex = 0;
|
|
211
|
-
let startTheta = 0, endTheta = 0, startPhi = 0, endPhi = 0;
|
|
212
|
-
|
|
213
|
-
for ( let i = 0; i < iesLamp.numHorAngles - 1; ++ i ) { // numHorAngles = horAngles.length-1 because of extra padding, so this wont cause an out of bounds error
|
|
214
|
-
|
|
215
|
-
if ( theta < iesLamp.horAngles[ i + 1 ] || i == iesLamp.numHorAngles - 2 ) {
|
|
216
|
-
|
|
217
|
-
thetaIndex = i;
|
|
218
|
-
startTheta = iesLamp.horAngles[ i ];
|
|
219
|
-
endTheta = iesLamp.horAngles[ i + 1 ];
|
|
220
|
-
|
|
221
|
-
break;
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
for ( let i = 0; i < iesLamp.numVerAngles - 1; ++ i ) {
|
|
228
|
-
|
|
229
|
-
if ( phi < iesLamp.verAngles[ i + 1 ] || i == iesLamp.numVerAngles - 2 ) {
|
|
230
|
-
|
|
231
|
-
phiIndex = i;
|
|
232
|
-
startPhi = iesLamp.verAngles[ i ];
|
|
233
|
-
endPhi = iesLamp.verAngles[ i + 1 ];
|
|
234
|
-
|
|
235
|
-
break;
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const deltaTheta = endTheta - startTheta;
|
|
242
|
-
const deltaPhi = endPhi - startPhi;
|
|
243
|
-
|
|
244
|
-
if ( deltaPhi === 0 ) // Outside range
|
|
245
|
-
return 0;
|
|
246
|
-
|
|
247
|
-
const t1 = deltaTheta === 0 ? 0 : ( theta - startTheta ) / deltaTheta;
|
|
248
|
-
const t2 = ( phi - startPhi ) / deltaPhi;
|
|
249
|
-
|
|
250
|
-
const nextThetaIndex = deltaTheta === 0 ? thetaIndex : thetaIndex + 1;
|
|
251
|
-
|
|
252
|
-
const v1 = MathUtils.lerp( iesLamp.candelaValues[ thetaIndex ][ phiIndex ], iesLamp.candelaValues[ nextThetaIndex ][ phiIndex ], t1 );
|
|
253
|
-
const v2 = MathUtils.lerp( iesLamp.candelaValues[ thetaIndex ][ phiIndex + 1 ], iesLamp.candelaValues[ nextThetaIndex ][ phiIndex + 1 ], t1 );
|
|
254
|
-
const v = MathUtils.lerp( v1, v2, t2 );
|
|
255
|
-
|
|
256
|
-
return v;
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const startTheta = iesLamp.horAngles[ 0 ], endTheta = iesLamp.horAngles[ iesLamp.numHorAngles - 1 ];
|
|
261
|
-
for ( let i = 0; i < size; ++ i ) {
|
|
262
|
-
|
|
263
|
-
let theta = i % width;
|
|
264
|
-
const phi = Math.floor( i / width );
|
|
265
|
-
|
|
266
|
-
if ( endTheta - startTheta !== 0 && ( theta < startTheta || theta >= endTheta ) ) { // Handle symmetry for hor angles
|
|
267
|
-
|
|
268
|
-
theta %= endTheta * 2;
|
|
269
|
-
if ( theta > endTheta )
|
|
270
|
-
theta = endTheta * 2 - theta;
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
data[ i ] = interpolateCandelaValues( phi, theta );
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return data;
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
load( url, onLoad, onProgress, onError ) {
|
|
283
|
-
|
|
284
|
-
const loader = new FileLoader( this.manager );
|
|
285
|
-
loader.setResponseType( 'text' );
|
|
286
|
-
loader.setCrossOrigin( this.crossOrigin );
|
|
287
|
-
loader.setWithCredentials( this.withCredentials );
|
|
288
|
-
loader.setPath( this.path );
|
|
289
|
-
loader.setRequestHeader( this.requestHeader );
|
|
290
|
-
|
|
291
|
-
const texture = new DataTexture( null, 360, 180, RedFormat, HalfFloatType );
|
|
292
|
-
texture.minFilter = LinearFilter;
|
|
293
|
-
texture.magFilter = LinearFilter;
|
|
294
|
-
|
|
295
|
-
loader.load( url, text => {
|
|
296
|
-
|
|
297
|
-
const iesLamp = new IESLamp( text );
|
|
298
|
-
|
|
299
|
-
texture.image.data = toHalfFloatArray( this._getIESValues( iesLamp ) );
|
|
300
|
-
texture.needsUpdate = true;
|
|
301
|
-
|
|
302
|
-
if ( onLoad !== undefined ) {
|
|
303
|
-
|
|
304
|
-
onLoad( texture );
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
}, onProgress, onError );
|
|
309
|
-
|
|
310
|
-
return texture;
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
parse( text ) {
|
|
315
|
-
|
|
316
|
-
const iesLamp = new IESLamp( text );
|
|
317
|
-
const texture = new DataTexture( null, 360, 180, RedFormat, HalfFloatType );
|
|
318
|
-
texture.minFilter = LinearFilter;
|
|
319
|
-
texture.magFilter = LinearFilter;
|
|
320
|
-
texture.image.data = toHalfFloatArray( this._getIESValues( iesLamp ) );
|
|
321
|
-
texture.needsUpdate = true;
|
|
322
|
-
|
|
323
|
-
return texture;
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { GenerateMeshBVHWorker } from 'three-mesh-bvh/src/workers/GenerateMeshBVHWorker.js';
|
|
2
|
-
import { DynamicPathTracingSceneGenerator } from '../core/DynamicPathTracingSceneGenerator.js';
|
|
3
|
-
|
|
4
|
-
export class PathTracingSceneWorker {
|
|
5
|
-
|
|
6
|
-
constructor() {
|
|
7
|
-
|
|
8
|
-
this.bvhGenerator = new GenerateMeshBVHWorker();
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
generate( scene, options = {} ) {
|
|
13
|
-
|
|
14
|
-
// ensure scene transforms are up to date
|
|
15
|
-
// TODO: remove this?
|
|
16
|
-
if ( Array.isArray( scene ) ) {
|
|
17
|
-
|
|
18
|
-
scene.forEach( s => s.updateMatrixWorld( true ) );
|
|
19
|
-
|
|
20
|
-
} else {
|
|
21
|
-
|
|
22
|
-
scene.updateMatrixWorld( true );
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const { bvhGenerator } = this;
|
|
27
|
-
const sceneGenerator = new DynamicPathTracingSceneGenerator( scene );
|
|
28
|
-
sceneGenerator.prepScene();
|
|
29
|
-
|
|
30
|
-
const { geometry, materials, textures, lights } = sceneGenerator;
|
|
31
|
-
const bvhPromise = bvhGenerator.generate( geometry, options );
|
|
32
|
-
return bvhPromise.then( bvh => {
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
scene,
|
|
36
|
-
materials,
|
|
37
|
-
textures,
|
|
38
|
-
lights,
|
|
39
|
-
bvh,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
} );
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
dispose() {
|
|
47
|
-
|
|
48
|
-
this.bvhGenerator.dispose();
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|