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.
@@ -279,7 +279,20 @@
279
279
  const attr = geometry.getAttribute( key );
280
280
  if ( ! skip ) {
281
281
 
282
- copyAttributeContents( attr, targetAttribute, offset );
282
+ if ( key === 'color' && targetAttribute.itemSize !== attr.itemSize ) {
283
+
284
+ // make sure the color attribute is aligned with itemSize 3 to 4
285
+ for ( let index = offset, l = attr.count; index < l; index ++ ) {
286
+
287
+ attr.setXYZW( index, targetAttribute.getX( index ), targetAttribute.getY( index ), targetAttribute.getZ( index ), 1.0 );
288
+
289
+ }
290
+
291
+ } else {
292
+
293
+ copyAttributeContents( attr, targetAttribute, offset );
294
+
295
+ }
283
296
 
284
297
  }
285
298
 
@@ -1317,6 +1330,7 @@
1317
1330
  this._bvhWorker = null;
1318
1331
  this._pendingGenerate = null;
1319
1332
  this._buildAsync = false;
1333
+ this._materialUuids = null;
1320
1334
 
1321
1335
  }
1322
1336
 
@@ -1398,12 +1412,29 @@
1398
1412
  // generate the geometry
1399
1413
  const result = staticGeometryGenerator.generate( geometry );
1400
1414
  const materials = result.materials;
1415
+ let needsMaterialIndexUpdate = result.changeType !== NO_CHANGE || this._materialUuids === null || this._materialUuids.length !== length;
1416
+ if ( ! needsMaterialIndexUpdate ) {
1417
+
1418
+ for ( let i = 0, length = materials.length; i < length; i ++ ) {
1419
+
1420
+ const material = materials[ i ];
1421
+ if ( material.uuid !== this._materialUuids[ i ] ) {
1422
+
1423
+ needsMaterialIndexUpdate = true;
1424
+ break;
1425
+
1426
+ }
1427
+
1428
+ }
1429
+
1430
+ }
1431
+
1401
1432
  const textures = getTextures$1( materials );
1402
1433
  const { lights, iesTextures } = getLights$1( objects );
1403
-
1404
- if ( result.changeType !== NO_CHANGE ) {
1434
+ if ( needsMaterialIndexUpdate ) {
1405
1435
 
1406
1436
  updateMaterialIndexAttribute( geometry, materials, materials );
1437
+ this._materialUuids = materials.map( material => material.uuid );
1407
1438
 
1408
1439
  }
1409
1440
 
@@ -1447,6 +1478,7 @@
1447
1478
  return {
1448
1479
  bvhChanged: result.changeType !== NO_CHANGE,
1449
1480
  bvh: this.bvh,
1481
+ needsMaterialIndexUpdate,
1450
1482
  lights,
1451
1483
  iesTextures,
1452
1484
  geometry,
@@ -2874,7 +2906,7 @@
2874
2906
 
2875
2907
  }
2876
2908
 
2877
- const MATERIAL_PIXELS = 45;
2909
+ const MATERIAL_PIXELS = 47;
2878
2910
  const MATERIAL_STRIDE = MATERIAL_PIXELS * 4;
2879
2911
 
2880
2912
  class MaterialFeatures {
@@ -3299,6 +3331,9 @@
3299
3331
  // specularIntensityMap transform 43
3300
3332
  index += writeTextureMatrixToArray( m, 'specularIntensityMap', floatArray, index );
3301
3333
 
3334
+ // alphaMap transform 45
3335
+ index += writeTextureMatrixToArray( m, 'alphaMap', floatArray, index );
3336
+
3302
3337
  }
3303
3338
 
3304
3339
  // check if the contents have changed
@@ -4378,6 +4413,7 @@
4378
4413
  mat3 iridescenceThicknessMapTransform;
4379
4414
  mat3 specularColorMapTransform;
4380
4415
  mat3 specularIntensityMapTransform;
4416
+ mat3 alphaMapTransform;
4381
4417
 
4382
4418
  };
4383
4419
 
@@ -4398,7 +4434,7 @@
4398
4434
 
4399
4435
  Material readMaterialInfo( sampler2D tex, uint index ) {
4400
4436
 
4401
- uint i = index * 45u;
4437
+ uint i = index * uint( MATERIAL_PIXELS );
4402
4438
 
4403
4439
  vec4 s0 = texelFetch1D( tex, i + 0u );
4404
4440
  vec4 s1 = texelFetch1D( tex, i + 1u );
@@ -4497,6 +4533,7 @@
4497
4533
  m.iridescenceThicknessMapTransform = m.iridescenceThicknessMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 24u );
4498
4534
  m.specularColorMapTransform = m.specularColorMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 26u );
4499
4535
  m.specularIntensityMapTransform = m.specularIntensityMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 28u );
4536
+ m.alphaMapTransform = m.alphaMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 30u );
4500
4537
 
4501
4538
  return m;
4502
4539
 
@@ -6263,7 +6300,7 @@
6263
6300
  // returns whether the given material is a fog material or not
6264
6301
  bool isMaterialFogVolume( sampler2D materials, uint materialIndex ) {
6265
6302
 
6266
- uint i = materialIndex * 45u;
6303
+ uint i = materialIndex * uint( MATERIAL_PIXELS );
6267
6304
  vec4 s14 = texelFetch1D( materials, i + 14u );
6268
6305
  return bool( int( s14.b ) & 4 );
6269
6306
 
@@ -6493,7 +6530,8 @@ bool bvhIntersectFogVolumeHit(
6493
6530
  // alphaMap
6494
6531
  if ( material.alphaMap != - 1 ) {
6495
6532
 
6496
- albedo.a *= texture2D( textures, vec3( uv, material.alphaMap ) ).x;
6533
+ vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 );
6534
+ albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x;
6497
6535
 
6498
6536
  }
6499
6537
 
@@ -6635,7 +6673,7 @@ bool bvhIntersectFogVolumeHit(
6635
6673
  vec3 shapeUVW= rand3( 1 );
6636
6674
  int blades = physicalCamera.apertureBlades;
6637
6675
  float anamorphicRatio = physicalCamera.anamorphicRatio;
6638
- vec2 apertureSample = blades == 0 ? sampleCircle( shapeUVW.xy ) : sampleRegularPolygon( blades, shapeUVW );
6676
+ vec2 apertureSample = sampleAperture( blades, shapeUVW );
6639
6677
  apertureSample *= physicalCamera.bokehSize * 0.5 * 1e-3;
6640
6678
 
6641
6679
  // rotate the aperture shape
@@ -6805,7 +6843,8 @@ bool bvhIntersectFogVolumeHit(
6805
6843
  // alphaMap
6806
6844
  if ( material.alphaMap != - 1 ) {
6807
6845
 
6808
- albedo.a *= texture2D( textures, vec3( uv, material.alphaMap ) ).x;
6846
+ vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 );
6847
+ albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x;
6809
6848
 
6810
6849
  }
6811
6850
 
@@ -7220,6 +7259,7 @@ bool bvhIntersectFogVolumeHit(
7220
7259
  ATTR_TANGENT: 1,
7221
7260
  ATTR_UV: 2,
7222
7261
  ATTR_COLOR: 3,
7262
+ MATERIAL_PIXELS: MATERIAL_PIXELS,
7223
7263
  },
7224
7264
 
7225
7265
  uniforms: {
@@ -8796,7 +8836,7 @@ bool bvhIntersectFogVolumeHit(
8796
8836
  }
8797
8837
 
8798
8838
  // update scene environment
8799
- material.environmentIntensity = scene.environmentIntensity ?? 1;
8839
+ material.environmentIntensity = scene.environment !== null ? ( scene.environmentIntensity ?? 1 ) : 0;
8800
8840
  material.environmentRotation.makeRotationFromEuler( scene.environmentRotation ).invert();
8801
8841
  if ( this._previousEnvironment !== scene.environment ) {
8802
8842
 
@@ -8816,10 +8856,6 @@ bool bvhIntersectFogVolumeHit(
8816
8856
 
8817
8857
  }
8818
8858
 
8819
- } else {
8820
-
8821
- material.environmentIntensity = 0;
8822
-
8823
8859
  }
8824
8860
 
8825
8861
  }
@@ -8837,6 +8873,7 @@ bool bvhIntersectFogVolumeHit(
8837
8873
  geometry,
8838
8874
  bvh,
8839
8875
  bvhChanged,
8876
+ needsMaterialIndexUpdate,
8840
8877
  } = results;
8841
8878
 
8842
8879
  this._materials = materials;
@@ -8854,6 +8891,10 @@ bool bvhIntersectFogVolumeHit(
8854
8891
  geometry.attributes.color,
8855
8892
  );
8856
8893
 
8894
+ }
8895
+
8896
+ if ( needsMaterialIndexUpdate ) {
8897
+
8857
8898
  material.materialIndexAttribute.updateFrom( geometry.attributes.materialIndex );
8858
8899
 
8859
8900
  }
@@ -8984,8 +9025,8 @@ bool bvhIntersectFogVolumeHit(
8984
9025
 
8985
9026
  dispose() {
8986
9027
 
8987
- this._renderQuad.dispose();
8988
- this._renderQuad.material.dispose();
9028
+ this._quad.dispose();
9029
+ this._quad.material.dispose();
8989
9030
  this._pathTracer.dispose();
8990
9031
 
8991
9032
  }