three-gpu-pathtracer 0.0.23 → 0.0.24
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 +6 -4
- package/build/index.module.js +57 -16
- package/build/index.module.js.map +1 -1
- package/build/index.umd.cjs +57 -16
- package/build/index.umd.cjs.map +1 -1
- package/package.json +13 -13
- package/src/core/PathTracingSceneGenerator.js +21 -2
- package/src/core/WebGLPathTracer.js +8 -7
- package/src/core/utils/mergeGeometries.js +14 -1
- package/src/index.d.ts +2 -1
- package/src/materials/pathtracing/PhysicalPathTracingMaterial.js +2 -1
- package/src/materials/pathtracing/glsl/attenuate_hit_function.glsl.js +2 -1
- package/src/materials/pathtracing/glsl/camera_util_functions.glsl.js +1 -1
- package/src/materials/pathtracing/glsl/get_surface_record_function.glsl.js +2 -1
- package/src/materials/surface/AmbientOcclusionMaterial.js +2 -0
- package/src/shader/bvh/inside_fog_volume_function.glsl.js +1 -1
- package/src/shader/structs/material_struct.glsl.js +3 -1
- package/src/uniforms/MaterialsTexture.js +4 -1
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ _More features and capabilities in progress!_
|
|
|
14
14
|
|
|
15
15
|
# Examples
|
|
16
16
|
|
|
17
|
+
[GLB Drag and Drop Viewer](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/viewer.html)
|
|
18
|
+
|
|
17
19
|
**Setup**
|
|
18
20
|
|
|
19
21
|
[Basic glTF Setup Example](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/basic.html)
|
|
@@ -26,7 +28,7 @@ _More features and capabilities in progress!_
|
|
|
26
28
|
|
|
27
29
|
[Lego Models](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/lego.html)
|
|
28
30
|
|
|
29
|
-
[Interior Scene](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/interior.html)
|
|
31
|
+
[Interior Scene w/ Equirect Rendering](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/interior.html)
|
|
30
32
|
|
|
31
33
|
[Depth of Field](https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/depthOfField.html)
|
|
32
34
|
|
|
@@ -107,7 +109,7 @@ import { BlurredEnvMapGenerator } from 'three-gpu-pathtracer';
|
|
|
107
109
|
|
|
108
110
|
// ...
|
|
109
111
|
|
|
110
|
-
const envMap = await new
|
|
112
|
+
const envMap = await new HDRLoader().setDataType( THREE.FloatType ).loadAsync( envMapUrl );
|
|
111
113
|
const generator = new BlurredEnvMapGenerator( renderer );
|
|
112
114
|
const blurredEnvMap = generator.generate( envMap, 0.35 );
|
|
113
115
|
|
|
@@ -133,10 +135,10 @@ bounces = 10 : Number
|
|
|
133
135
|
|
|
134
136
|
Max number of lights bounces to trace.
|
|
135
137
|
|
|
136
|
-
### .
|
|
138
|
+
### .filterGlossyFactor
|
|
137
139
|
|
|
138
140
|
```js
|
|
139
|
-
|
|
141
|
+
filterGlossyFactor = 0 : Number
|
|
140
142
|
```
|
|
141
143
|
|
|
142
144
|
Factor for alleviating bright pixels from rays that hit diffuse surfaces then specular surfaces. Setting this higher alleviates fireflies but will remove some specular caustics.
|
package/build/index.module.js
CHANGED
|
@@ -277,7 +277,20 @@ function mergeGeometries( geometries, options = {}, targetGeometry = new BufferG
|
|
|
277
277
|
const attr = geometry.getAttribute( key );
|
|
278
278
|
if ( ! skip ) {
|
|
279
279
|
|
|
280
|
-
|
|
280
|
+
if ( key === 'color' && targetAttribute.itemSize !== attr.itemSize ) {
|
|
281
|
+
|
|
282
|
+
// make sure the color attribute is aligned with itemSize 3 to 4
|
|
283
|
+
for ( let index = offset, l = attr.count; index < l; index ++ ) {
|
|
284
|
+
|
|
285
|
+
attr.setXYZW( index, targetAttribute.getX( index ), targetAttribute.getY( index ), targetAttribute.getZ( index ), 1.0 );
|
|
286
|
+
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
} else {
|
|
290
|
+
|
|
291
|
+
copyAttributeContents( attr, targetAttribute, offset );
|
|
292
|
+
|
|
293
|
+
}
|
|
281
294
|
|
|
282
295
|
}
|
|
283
296
|
|
|
@@ -1315,6 +1328,7 @@ class PathTracingSceneGenerator {
|
|
|
1315
1328
|
this._bvhWorker = null;
|
|
1316
1329
|
this._pendingGenerate = null;
|
|
1317
1330
|
this._buildAsync = false;
|
|
1331
|
+
this._materialUuids = null;
|
|
1318
1332
|
|
|
1319
1333
|
}
|
|
1320
1334
|
|
|
@@ -1396,12 +1410,29 @@ class PathTracingSceneGenerator {
|
|
|
1396
1410
|
// generate the geometry
|
|
1397
1411
|
const result = staticGeometryGenerator.generate( geometry );
|
|
1398
1412
|
const materials = result.materials;
|
|
1413
|
+
let needsMaterialIndexUpdate = result.changeType !== NO_CHANGE || this._materialUuids === null || this._materialUuids.length !== length;
|
|
1414
|
+
if ( ! needsMaterialIndexUpdate ) {
|
|
1415
|
+
|
|
1416
|
+
for ( let i = 0, length = materials.length; i < length; i ++ ) {
|
|
1417
|
+
|
|
1418
|
+
const material = materials[ i ];
|
|
1419
|
+
if ( material.uuid !== this._materialUuids[ i ] ) {
|
|
1420
|
+
|
|
1421
|
+
needsMaterialIndexUpdate = true;
|
|
1422
|
+
break;
|
|
1423
|
+
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1399
1430
|
const textures = getTextures$1( materials );
|
|
1400
1431
|
const { lights, iesTextures } = getLights$1( objects );
|
|
1401
|
-
|
|
1402
|
-
if ( result.changeType !== NO_CHANGE ) {
|
|
1432
|
+
if ( needsMaterialIndexUpdate ) {
|
|
1403
1433
|
|
|
1404
1434
|
updateMaterialIndexAttribute( geometry, materials, materials );
|
|
1435
|
+
this._materialUuids = materials.map( material => material.uuid );
|
|
1405
1436
|
|
|
1406
1437
|
}
|
|
1407
1438
|
|
|
@@ -1445,6 +1476,7 @@ class PathTracingSceneGenerator {
|
|
|
1445
1476
|
return {
|
|
1446
1477
|
bvhChanged: result.changeType !== NO_CHANGE,
|
|
1447
1478
|
bvh: this.bvh,
|
|
1479
|
+
needsMaterialIndexUpdate,
|
|
1448
1480
|
lights,
|
|
1449
1481
|
iesTextures,
|
|
1450
1482
|
geometry,
|
|
@@ -2872,7 +2904,7 @@ function getLights( scene ) {
|
|
|
2872
2904
|
|
|
2873
2905
|
}
|
|
2874
2906
|
|
|
2875
|
-
const MATERIAL_PIXELS =
|
|
2907
|
+
const MATERIAL_PIXELS = 47;
|
|
2876
2908
|
const MATERIAL_STRIDE = MATERIAL_PIXELS * 4;
|
|
2877
2909
|
|
|
2878
2910
|
class MaterialFeatures {
|
|
@@ -3297,6 +3329,9 @@ class MaterialsTexture extends DataTexture {
|
|
|
3297
3329
|
// specularIntensityMap transform 43
|
|
3298
3330
|
index += writeTextureMatrixToArray( m, 'specularIntensityMap', floatArray, index );
|
|
3299
3331
|
|
|
3332
|
+
// alphaMap transform 45
|
|
3333
|
+
index += writeTextureMatrixToArray( m, 'alphaMap', floatArray, index );
|
|
3334
|
+
|
|
3300
3335
|
}
|
|
3301
3336
|
|
|
3302
3337
|
// check if the contents have changed
|
|
@@ -4376,6 +4411,7 @@ const material_struct = /* glsl */ `
|
|
|
4376
4411
|
mat3 iridescenceThicknessMapTransform;
|
|
4377
4412
|
mat3 specularColorMapTransform;
|
|
4378
4413
|
mat3 specularIntensityMapTransform;
|
|
4414
|
+
mat3 alphaMapTransform;
|
|
4379
4415
|
|
|
4380
4416
|
};
|
|
4381
4417
|
|
|
@@ -4396,7 +4432,7 @@ const material_struct = /* glsl */ `
|
|
|
4396
4432
|
|
|
4397
4433
|
Material readMaterialInfo( sampler2D tex, uint index ) {
|
|
4398
4434
|
|
|
4399
|
-
uint i = index *
|
|
4435
|
+
uint i = index * uint( MATERIAL_PIXELS );
|
|
4400
4436
|
|
|
4401
4437
|
vec4 s0 = texelFetch1D( tex, i + 0u );
|
|
4402
4438
|
vec4 s1 = texelFetch1D( tex, i + 1u );
|
|
@@ -4495,6 +4531,7 @@ const material_struct = /* glsl */ `
|
|
|
4495
4531
|
m.iridescenceThicknessMapTransform = m.iridescenceThicknessMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 24u );
|
|
4496
4532
|
m.specularColorMapTransform = m.specularColorMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 26u );
|
|
4497
4533
|
m.specularIntensityMapTransform = m.specularIntensityMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 28u );
|
|
4534
|
+
m.alphaMapTransform = m.alphaMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 30u );
|
|
4498
4535
|
|
|
4499
4536
|
return m;
|
|
4500
4537
|
|
|
@@ -6261,7 +6298,7 @@ const inside_fog_volume_function = /* glsl */`
|
|
|
6261
6298
|
// returns whether the given material is a fog material or not
|
|
6262
6299
|
bool isMaterialFogVolume( sampler2D materials, uint materialIndex ) {
|
|
6263
6300
|
|
|
6264
|
-
uint i = materialIndex *
|
|
6301
|
+
uint i = materialIndex * uint( MATERIAL_PIXELS );
|
|
6265
6302
|
vec4 s14 = texelFetch1D( materials, i + 14u );
|
|
6266
6303
|
return bool( int( s14.b ) & 4 );
|
|
6267
6304
|
|
|
@@ -6491,7 +6528,8 @@ const attenuate_hit_function = /* glsl */`
|
|
|
6491
6528
|
// alphaMap
|
|
6492
6529
|
if ( material.alphaMap != - 1 ) {
|
|
6493
6530
|
|
|
6494
|
-
|
|
6531
|
+
vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 );
|
|
6532
|
+
albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x;
|
|
6495
6533
|
|
|
6496
6534
|
}
|
|
6497
6535
|
|
|
@@ -6633,7 +6671,7 @@ const camera_util_functions = /* glsl */`
|
|
|
6633
6671
|
vec3 shapeUVW= rand3( 1 );
|
|
6634
6672
|
int blades = physicalCamera.apertureBlades;
|
|
6635
6673
|
float anamorphicRatio = physicalCamera.anamorphicRatio;
|
|
6636
|
-
vec2 apertureSample =
|
|
6674
|
+
vec2 apertureSample = sampleAperture( blades, shapeUVW );
|
|
6637
6675
|
apertureSample *= physicalCamera.bokehSize * 0.5 * 1e-3;
|
|
6638
6676
|
|
|
6639
6677
|
// rotate the aperture shape
|
|
@@ -6803,7 +6841,8 @@ const get_surface_record_function = /* glsl */`
|
|
|
6803
6841
|
// alphaMap
|
|
6804
6842
|
if ( material.alphaMap != - 1 ) {
|
|
6805
6843
|
|
|
6806
|
-
|
|
6844
|
+
vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 );
|
|
6845
|
+
albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x;
|
|
6807
6846
|
|
|
6808
6847
|
}
|
|
6809
6848
|
|
|
@@ -7218,6 +7257,7 @@ class PhysicalPathTracingMaterial extends MaterialBase {
|
|
|
7218
7257
|
ATTR_TANGENT: 1,
|
|
7219
7258
|
ATTR_UV: 2,
|
|
7220
7259
|
ATTR_COLOR: 3,
|
|
7260
|
+
MATERIAL_PIXELS: MATERIAL_PIXELS,
|
|
7221
7261
|
},
|
|
7222
7262
|
|
|
7223
7263
|
uniforms: {
|
|
@@ -8794,7 +8834,7 @@ class WebGLPathTracer {
|
|
|
8794
8834
|
}
|
|
8795
8835
|
|
|
8796
8836
|
// update scene environment
|
|
8797
|
-
material.environmentIntensity = scene.environmentIntensity ?? 1;
|
|
8837
|
+
material.environmentIntensity = scene.environment !== null ? ( scene.environmentIntensity ?? 1 ) : 0;
|
|
8798
8838
|
material.environmentRotation.makeRotationFromEuler( scene.environmentRotation ).invert();
|
|
8799
8839
|
if ( this._previousEnvironment !== scene.environment ) {
|
|
8800
8840
|
|
|
@@ -8814,10 +8854,6 @@ class WebGLPathTracer {
|
|
|
8814
8854
|
|
|
8815
8855
|
}
|
|
8816
8856
|
|
|
8817
|
-
} else {
|
|
8818
|
-
|
|
8819
|
-
material.environmentIntensity = 0;
|
|
8820
|
-
|
|
8821
8857
|
}
|
|
8822
8858
|
|
|
8823
8859
|
}
|
|
@@ -8835,6 +8871,7 @@ class WebGLPathTracer {
|
|
|
8835
8871
|
geometry,
|
|
8836
8872
|
bvh,
|
|
8837
8873
|
bvhChanged,
|
|
8874
|
+
needsMaterialIndexUpdate,
|
|
8838
8875
|
} = results;
|
|
8839
8876
|
|
|
8840
8877
|
this._materials = materials;
|
|
@@ -8852,6 +8889,10 @@ class WebGLPathTracer {
|
|
|
8852
8889
|
geometry.attributes.color,
|
|
8853
8890
|
);
|
|
8854
8891
|
|
|
8892
|
+
}
|
|
8893
|
+
|
|
8894
|
+
if ( needsMaterialIndexUpdate ) {
|
|
8895
|
+
|
|
8855
8896
|
material.materialIndexAttribute.updateFrom( geometry.attributes.materialIndex );
|
|
8856
8897
|
|
|
8857
8898
|
}
|
|
@@ -8982,8 +9023,8 @@ class WebGLPathTracer {
|
|
|
8982
9023
|
|
|
8983
9024
|
dispose() {
|
|
8984
9025
|
|
|
8985
|
-
this.
|
|
8986
|
-
this.
|
|
9026
|
+
this._quad.dispose();
|
|
9027
|
+
this._quad.material.dispose();
|
|
8987
9028
|
this._pathTracer.dispose();
|
|
8988
9029
|
|
|
8989
9030
|
}
|