super-three 0.163.0 → 0.164.0

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 (114) hide show
  1. package/build/three.cjs +473 -245
  2. package/build/three.module.js +473 -245
  3. package/build/three.module.min.js +2 -2
  4. package/examples/jsm/animation/CCDIKSolver.js +4 -2
  5. package/examples/jsm/exporters/GLTFExporter.js +45 -1
  6. package/examples/jsm/exporters/USDZExporter.js +7 -1
  7. package/examples/jsm/libs/draco/README.md +2 -2
  8. package/examples/jsm/loaders/EXRLoader.js +283 -99
  9. package/examples/jsm/loaders/GLTFLoader.js +53 -0
  10. package/examples/jsm/loaders/KTX2Loader.js +3 -6
  11. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  12. package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
  13. package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
  14. package/examples/jsm/math/Octree.js +26 -20
  15. package/examples/jsm/nodes/Nodes.js +4 -3
  16. package/examples/jsm/nodes/accessors/AccessorsUtils.js +16 -1
  17. package/examples/jsm/nodes/accessors/ClippingNode.js +3 -2
  18. package/examples/jsm/nodes/accessors/MaterialNode.js +107 -3
  19. package/examples/jsm/nodes/accessors/StorageBufferNode.js +9 -0
  20. package/examples/jsm/nodes/accessors/TextureNode.js +21 -3
  21. package/examples/jsm/nodes/accessors/TextureSizeNode.js +1 -1
  22. package/examples/jsm/nodes/code/FunctionNode.js +0 -8
  23. package/examples/jsm/nodes/core/Node.js +8 -0
  24. package/examples/jsm/nodes/core/NodeBuilder.js +5 -9
  25. package/examples/jsm/nodes/core/OutputStructNode.js +2 -1
  26. package/examples/jsm/nodes/core/PropertyNode.js +10 -0
  27. package/examples/jsm/nodes/display/BumpMapNode.js +7 -26
  28. package/examples/jsm/nodes/display/FrontFacingNode.js +13 -0
  29. package/examples/jsm/nodes/display/ViewportDepthNode.js +1 -1
  30. package/examples/jsm/nodes/display/ViewportNode.js +4 -2
  31. package/examples/jsm/nodes/display/ViewportTextureNode.js +4 -1
  32. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +26 -7
  33. package/examples/jsm/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  34. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +1 -3
  35. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  36. package/examples/jsm/nodes/functions/PhongLightingModel.js +1 -1
  37. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +164 -10
  38. package/examples/jsm/nodes/functions/ShadowMaskModel.js +31 -0
  39. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +18 -4
  40. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -1
  41. package/examples/jsm/nodes/lighting/EnvironmentNode.js +11 -2
  42. package/examples/jsm/nodes/lighting/IrradianceNode.js +24 -0
  43. package/examples/jsm/nodes/lighting/LightsNode.js +11 -1
  44. package/examples/jsm/nodes/lighting/PointLightNode.js +2 -1
  45. package/examples/jsm/nodes/lighting/SpotLightNode.js +2 -1
  46. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +10 -6
  47. package/examples/jsm/nodes/materials/Materials.js +1 -0
  48. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -2
  49. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
  50. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +76 -5
  51. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +11 -4
  52. package/examples/jsm/nodes/materials/NodeMaterial.js +31 -41
  53. package/examples/jsm/nodes/materials/ShadowNodeMaterial.js +34 -0
  54. package/examples/jsm/nodes/pmrem/PMREMUtils.js +1 -1
  55. package/examples/jsm/nodes/shadernode/ShaderNode.js +2 -8
  56. package/examples/jsm/physics/JoltPhysics.js +281 -0
  57. package/examples/jsm/postprocessing/RenderTransitionPass.js +193 -0
  58. package/examples/jsm/renderers/common/Background.js +3 -3
  59. package/examples/jsm/renderers/common/ClippingContext.js +1 -1
  60. package/examples/jsm/renderers/common/RenderList.js +1 -1
  61. package/examples/jsm/renderers/common/RenderObject.js +43 -1
  62. package/examples/jsm/renderers/common/Renderer.js +129 -14
  63. package/examples/jsm/renderers/common/Textures.js +1 -1
  64. package/examples/jsm/renderers/common/extras/PMREMGenerator.js +13 -17
  65. package/examples/jsm/renderers/common/nodes/Nodes.js +31 -47
  66. package/examples/jsm/renderers/webgl/WebGLBackend.js +7 -21
  67. package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +5 -1
  68. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +6 -0
  69. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +21 -7
  70. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +3 -21
  71. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +33 -45
  72. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +16 -1
  73. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -1
  74. package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
  75. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  76. package/examples/jsm/utils/SceneUtils.js +60 -1
  77. package/examples/jsm/webxr/OculusHandModel.js +3 -2
  78. package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
  79. package/package.json +1 -1
  80. package/src/constants.js +1 -1
  81. package/src/core/RenderTarget.js +8 -0
  82. package/src/extras/PMREMGenerator.js +12 -11
  83. package/src/loaders/FileLoader.js +1 -1
  84. package/src/loaders/MaterialLoader.js +1 -0
  85. package/src/materials/Material.js +2 -0
  86. package/src/materials/MeshPhysicalMaterial.js +20 -0
  87. package/src/objects/BatchedMesh.js +23 -0
  88. package/src/objects/Line.js +66 -43
  89. package/src/renderers/WebGLRenderer.js +92 -61
  90. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
  91. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
  92. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +17 -9
  93. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  94. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
  95. package/src/renderers/shaders/ShaderChunk.js +0 -2
  96. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
  97. package/src/renderers/shaders/ShaderLib.js +1 -0
  98. package/src/renderers/webgl/WebGLBackground.js +18 -3
  99. package/src/renderers/webgl/WebGLBufferRenderer.js +36 -0
  100. package/src/renderers/webgl/WebGLCapabilities.js +33 -1
  101. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +36 -0
  102. package/src/renderers/webgl/WebGLMaterials.js +6 -0
  103. package/src/renderers/webgl/WebGLProgram.js +3 -5
  104. package/src/renderers/webgl/WebGLPrograms.js +5 -0
  105. package/src/renderers/webgl/WebGLRenderStates.js +6 -2
  106. package/src/renderers/webgl/WebGLShadowMap.js +25 -25
  107. package/src/renderers/webgl/WebGLTextures.js +68 -60
  108. package/src/renderers/webgl/WebGLUtils.js +3 -21
  109. package/src/renderers/webxr/WebXRManager.js +2 -4
  110. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -318
  111. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +0 -26
  112. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -792
  113. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +0 -51
  114. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
@@ -85,6 +85,12 @@ class GLTFLoader extends Loader {
85
85
 
86
86
  } );
87
87
 
88
+ this.register( function ( parser ) {
89
+
90
+ return new GLTFMaterialsDispersionExtension( parser );
91
+
92
+ } );
93
+
88
94
  this.register( function ( parser ) {
89
95
 
90
96
  return new GLTFTextureBasisUExtension( parser );
@@ -491,6 +497,7 @@ const EXTENSIONS = {
491
497
  KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
492
498
  KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
493
499
  KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
500
+ KHR_MATERIALS_DISPERSION: 'KHR_materials_dispersion',
494
501
  KHR_MATERIALS_IOR: 'KHR_materials_ior',
495
502
  KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
496
503
  KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
@@ -824,6 +831,52 @@ class GLTFMaterialsClearcoatExtension {
824
831
 
825
832
  }
826
833
 
834
+ /**
835
+ * Materials dispersion Extension
836
+ *
837
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_dispersion
838
+ */
839
+ class GLTFMaterialsDispersionExtension {
840
+
841
+ constructor( parser ) {
842
+
843
+ this.parser = parser;
844
+ this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION;
845
+
846
+ }
847
+
848
+ getMaterialType( materialIndex ) {
849
+
850
+ const parser = this.parser;
851
+ const materialDef = parser.json.materials[ materialIndex ];
852
+
853
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
854
+
855
+ return MeshPhysicalMaterial;
856
+
857
+ }
858
+
859
+ extendMaterialParams( materialIndex, materialParams ) {
860
+
861
+ const parser = this.parser;
862
+ const materialDef = parser.json.materials[ materialIndex ];
863
+
864
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
865
+
866
+ return Promise.resolve();
867
+
868
+ }
869
+
870
+ const extension = materialDef.extensions[ this.name ];
871
+
872
+ materialParams.dispersion = extension.dispersion !== undefined ? extension.dispersion : 0;
873
+
874
+ return Promise.resolve();
875
+
876
+ }
877
+
878
+ }
879
+
827
880
  /**
828
881
  * Iridescence Materials Extension
829
882
  *
@@ -31,13 +31,13 @@ import {
31
31
  RGB_ETC1_Format,
32
32
  RGB_ETC2_Format,
33
33
  RGB_PVRTC_4BPPV1_Format,
34
- RGB_S3TC_DXT1_Format,
35
34
  RGBA_ASTC_4x4_Format,
36
35
  RGBA_ASTC_6x6_Format,
37
36
  RGBA_BPTC_Format,
38
37
  RGBA_ETC2_EAC_Format,
39
38
  RGBA_PVRTC_4BPPV1_Format,
40
39
  RGBA_S3TC_DXT5_Format,
40
+ RGBA_S3TC_DXT1_Format,
41
41
  RGBAFormat,
42
42
  RGFormat,
43
43
  SRGBColorSpace,
@@ -160,9 +160,6 @@ class KTX2Loader extends Loader {
160
160
  || renderer.extensions.has( 'WEBKIT_WEBGL_compressed_texture_pvrtc' )
161
161
  };
162
162
 
163
- // https://github.com/mrdoob/three.js/pull/22928
164
- this.workerConfig.etc1Supported = false;
165
-
166
163
  }
167
164
 
168
165
  return this;
@@ -387,7 +384,7 @@ KTX2Loader.EngineFormat = {
387
384
  RGB_ETC1_Format: RGB_ETC1_Format,
388
385
  RGB_ETC2_Format: RGB_ETC2_Format,
389
386
  RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
390
- RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format,
387
+ RGBA_S3TC_DXT1_Format: RGBA_S3TC_DXT1_Format,
391
388
  };
392
389
 
393
390
 
@@ -603,7 +600,7 @@ KTX2Loader.BasisWorker = function () {
603
600
  if: 'dxtSupported',
604
601
  basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
605
602
  transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
606
- engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
603
+ engineFormat: [ EngineFormat.RGBA_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
607
604
  priorityETC1S: 4,
608
605
  priorityUASTC: 5,
609
606
  needsPowerOfTwo: false,
@@ -800,7 +800,7 @@ class VRMLLoader extends Loader {
800
800
  break;
801
801
 
802
802
  case 'rotation':
803
- const axis = new Vector3( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
803
+ const axis = new Vector3( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] ).normalize();
804
804
  const angle = fieldValues[ 3 ];
805
805
  object.quaternion.setFromAxisAngle( axis, angle );
806
806
  break;
@@ -651,10 +651,13 @@ class IFFParser {
651
651
  // LAYR: number[U2], flags[U2], pivot[VEC12], name[S0], parent[U2]
652
652
  parseLayer( length ) {
653
653
 
654
+ var number = this.reader.getUint16();
655
+ var flags = this.reader.getUint16(); // If the least significant bit of flags is set, the layer is hidden.
656
+ var pivot = this.reader.getFloat32Array( 3 ); // Note: this seems to be superflous, as the geometry is translated when pivot is present
654
657
  var layer = {
655
- number: this.reader.getUint16(),
656
- flags: this.reader.getUint16(), // If the least significant bit of flags is set, the layer is hidden.
657
- pivot: this.reader.getFloat32Array( 3 ), // Note: this seems to be superflous, as the geometry is translated when pivot is present
658
+ number: number,
659
+ flags: flags, // If the least significant bit of flags is set, the layer is hidden.
660
+ pivot: [ - pivot[ 0 ], pivot[ 1 ], pivot[ 2 ] ], // Note: this seems to be superflous, as the geometry is translated when pivot is present
658
661
  name: this.reader.getString(),
659
662
  };
660
663
 
@@ -676,8 +679,8 @@ class IFFParser {
676
679
  this.currentPoints = [];
677
680
  for ( var i = 0; i < length / 4; i += 3 ) {
678
681
 
679
- // z -> -z to match three.js right handed coords
680
- this.currentPoints.push( this.reader.getFloat32(), this.reader.getFloat32(), - this.reader.getFloat32() );
682
+ // x -> -x to match three.js right handed coords
683
+ this.currentPoints.push( - this.reader.getFloat32(), this.reader.getFloat32(), this.reader.getFloat32() );
681
684
 
682
685
  }
683
686
 
@@ -270,7 +270,13 @@ const GouraudShader = {
270
270
 
271
271
  #endif
272
272
 
273
- #include <lightmap_fragment>
273
+ #ifdef USE_LIGHTMAP
274
+
275
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
276
+ vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
277
+ reflectedLight.indirectDiffuse += lightMapIrradiance;
278
+
279
+ #endif
274
280
 
275
281
  reflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );
276
282
 
@@ -4,7 +4,8 @@ import {
4
4
  Plane,
5
5
  Sphere,
6
6
  Triangle,
7
- Vector3
7
+ Vector3,
8
+ Layers
8
9
  } from 'three';
9
10
  import { Capsule } from '../math/Capsule.js';
10
11
 
@@ -89,6 +90,7 @@ class Octree {
89
90
 
90
91
  this.subTrees = [];
91
92
  this.triangles = [];
93
+ this.layers = new Layers();
92
94
 
93
95
  }
94
96
 
@@ -478,38 +480,42 @@ class Octree {
478
480
 
479
481
  if ( obj.isMesh === true ) {
480
482
 
481
- let geometry, isTemp = false;
483
+ if ( this.layers.test( obj.layers ) ) {
482
484
 
483
- if ( obj.geometry.index !== null ) {
485
+ let geometry, isTemp = false;
484
486
 
485
- isTemp = true;
486
- geometry = obj.geometry.toNonIndexed();
487
+ if ( obj.geometry.index !== null ) {
487
488
 
488
- } else {
489
+ isTemp = true;
490
+ geometry = obj.geometry.toNonIndexed();
489
491
 
490
- geometry = obj.geometry;
492
+ } else {
491
493
 
492
- }
494
+ geometry = obj.geometry;
493
495
 
494
- const positionAttribute = geometry.getAttribute( 'position' );
496
+ }
495
497
 
496
- for ( let i = 0; i < positionAttribute.count; i += 3 ) {
498
+ const positionAttribute = geometry.getAttribute( 'position' );
497
499
 
498
- const v1 = new Vector3().fromBufferAttribute( positionAttribute, i );
499
- const v2 = new Vector3().fromBufferAttribute( positionAttribute, i + 1 );
500
- const v3 = new Vector3().fromBufferAttribute( positionAttribute, i + 2 );
500
+ for ( let i = 0; i < positionAttribute.count; i += 3 ) {
501
501
 
502
- v1.applyMatrix4( obj.matrixWorld );
503
- v2.applyMatrix4( obj.matrixWorld );
504
- v3.applyMatrix4( obj.matrixWorld );
502
+ const v1 = new Vector3().fromBufferAttribute( positionAttribute, i );
503
+ const v2 = new Vector3().fromBufferAttribute( positionAttribute, i + 1 );
504
+ const v3 = new Vector3().fromBufferAttribute( positionAttribute, i + 2 );
505
505
 
506
- this.addTriangle( new Triangle( v1, v2, v3 ) );
506
+ v1.applyMatrix4( obj.matrixWorld );
507
+ v2.applyMatrix4( obj.matrixWorld );
508
+ v3.applyMatrix4( obj.matrixWorld );
507
509
 
508
- }
510
+ this.addTriangle( new Triangle( v1, v2, v3 ) );
511
+
512
+ }
513
+
514
+ if ( isTemp ) {
509
515
 
510
- if ( isTemp ) {
516
+ geometry.dispose();
511
517
 
512
- geometry.dispose();
518
+ }
513
519
 
514
520
  }
515
521
 
@@ -26,7 +26,7 @@ export { default as NodeUniform } from './core/NodeUniform.js';
26
26
  export { default as NodeVar } from './core/NodeVar.js';
27
27
  export { default as NodeVarying } from './core/NodeVarying.js';
28
28
  export { default as ParameterNode, parameter } from './core/ParameterNode.js';
29
- export { default as PropertyNode, property, varyingProperty, output, diffuseColor, roughness, metalness, clearcoat, clearcoatRoughness, sheen, sheenRoughness, iridescence, iridescenceIOR, iridescenceThickness, specularColor, shininess, dashSize, gapSize, pointWidth } from './core/PropertyNode.js';
29
+ export { default as PropertyNode, property, varyingProperty, output, diffuseColor, roughness, metalness, clearcoat, clearcoatRoughness, sheen, sheenRoughness, iridescence, iridescenceIOR, iridescenceThickness, specularColor, shininess, dashSize, gapSize, pointWidth, alphaT, anisotropy, anisotropyB, anisotropyT } from './core/PropertyNode.js';
30
30
  export { default as StackNode, stack } from './core/StackNode.js';
31
31
  export { default as TempNode } from './core/TempNode.js';
32
32
  export { default as UniformGroupNode, uniformGroup, objectGroup, renderGroup, frameGroup } from './core/UniformGroupNode.js';
@@ -75,7 +75,7 @@ export { default as ReflectorNode, reflector } from './utils/ReflectorNode.js';
75
75
  export * from './shadernode/ShaderNode.js';
76
76
 
77
77
  // accessors
78
- export { TBNViewMatrix, parallaxDirection, parallaxUV } from './accessors/AccessorsUtils.js';
78
+ export { TBNViewMatrix, parallaxDirection, parallaxUV, transformedBentNormalView } from './accessors/AccessorsUtils.js';
79
79
  export { default as UniformsNode, uniforms } from './accessors/UniformsNode.js';
80
80
  export { default as BitangentNode, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, transformedBitangentView, transformedBitangentWorld } from './accessors/BitangentNode.js';
81
81
  export { default as BufferAttributeNode, bufferAttribute, dynamicBufferAttribute, instancedBufferAttribute, instancedDynamicBufferAttribute } from './accessors/BufferAttributeNode.js';
@@ -85,7 +85,7 @@ export { default as VertexColorNode, vertexColor } from './accessors/VertexColor
85
85
  export { default as CubeTextureNode, cubeTexture } from './accessors/CubeTextureNode.js';
86
86
  export { default as InstanceNode, instance } from './accessors/InstanceNode.js';
87
87
  export { default as BatchNode, batch } from './accessors/BatchNode.js';
88
- export { default as MaterialNode, materialAlphaTest, materialColor, materialShininess, materialEmissive, materialOpacity, materialSpecularColor, materialSpecularStrength, materialReflectivity, materialRoughness, materialMetalness, materialNormal, materialClearcoat, materialClearcoatRoughness, materialClearcoatNormal, materialRotation, materialSheen, materialSheenRoughness, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineWidth, materialLineDashOffset, materialPointWidth } from './accessors/MaterialNode.js';
88
+ export { default as MaterialNode, materialAlphaTest, materialColor, materialShininess, materialEmissive, materialOpacity, materialSpecular, materialSpecularStrength, materialReflectivity, materialRoughness, materialMetalness, materialNormal, materialClearcoat, materialClearcoatRoughness, materialClearcoatNormal, materialRotation, materialSheen, materialSheenRoughness, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineWidth, materialLineDashOffset, materialPointWidth, materialAnisotropy, materialAnisotropyVector } from './accessors/MaterialNode.js';
89
89
  export { default as MaterialReferenceNode, materialReference } from './accessors/MaterialReferenceNode.js';
90
90
  export { default as RendererReferenceNode, rendererReference } from './accessors/RendererReferenceNode.js';
91
91
  export { default as MorphNode, morphReference } from './accessors/MorphNode.js';
@@ -158,6 +158,7 @@ export { default as LightingNode /* @TODO: lighting (abstract), light */ } from
158
158
  export { default as LightingContextNode, lightingContext } from './lighting/LightingContextNode.js';
159
159
  export { default as HemisphereLightNode } from './lighting/HemisphereLightNode.js';
160
160
  export { default as EnvironmentNode } from './lighting/EnvironmentNode.js';
161
+ export { default as IrradianceNode } from './lighting/IrradianceNode.js';
161
162
  export { default as AONode } from './lighting/AONode.js';
162
163
  export { default as AnalyticLightNode } from './lighting/AnalyticLightNode.js';
163
164
 
@@ -1,10 +1,25 @@
1
1
  import { bitangentView } from './BitangentNode.js';
2
- import { normalView } from './NormalNode.js';
2
+ import { normalView, transformedNormalView } from './NormalNode.js';
3
3
  import { tangentView } from './TangentNode.js';
4
4
  import { mat3 } from '../shadernode/ShaderNode.js';
5
+ import { mix } from '../math/MathNode.js';
6
+ import { anisotropy, anisotropyB, roughness } from '../core/PropertyNode.js';
5
7
  import { positionViewDirection } from './PositionNode.js';
6
8
 
7
9
  export const TBNViewMatrix = mat3( tangentView, bitangentView, normalView );
8
10
 
9
11
  export const parallaxDirection = positionViewDirection.mul( TBNViewMatrix )/*.normalize()*/;
10
12
  export const parallaxUV = ( uv, scale ) => uv.sub( parallaxDirection.mul( scale ) );
13
+
14
+ export const transformedBentNormalView = ( () => {
15
+
16
+ // https://google.github.io/filament/Filament.md.html#lighting/imagebasedlights/anisotropy
17
+
18
+ let bentNormal = anisotropyB.cross( positionViewDirection );
19
+ bentNormal = bentNormal.cross( anisotropyB ).normalize();
20
+ bentNormal = mix( bentNormal, transformedNormalView, anisotropy.mul( roughness.oneMinus() ).oneMinus().pow2().pow2() ).normalize();
21
+
22
+ return bentNormal;
23
+
24
+
25
+ } )();
@@ -5,7 +5,7 @@ import { positionView } from './PositionNode.js';
5
5
  import { diffuseColor, property } from '../core/PropertyNode.js';
6
6
  import { tslFn } from '../shadernode/ShaderNode.js';
7
7
  import { loop } from '../utils/LoopNode.js';
8
- import { smoothstep } from '../math/MathNode.js';
8
+ import { smoothstep } from '../math/MathNode.js';
9
9
  import { uniforms } from './UniformsNode.js';
10
10
 
11
11
  class ClippingNode extends Node {
@@ -78,7 +78,7 @@ class ClippingNode extends Node {
78
78
 
79
79
  plane = clippingPlanes.element( i );
80
80
 
81
- distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) );
81
+ distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) );
82
82
  distanceGradient.assign( distanceToPlane.fwidth().div( 2.0 ) );
83
83
 
84
84
  unionClipOpacity.mulAssign( smoothstep( distanceGradient.negate(), distanceGradient, distanceToPlane ).oneMinus() );
@@ -126,6 +126,7 @@ class ClippingNode extends Node {
126
126
  } );
127
127
 
128
128
  clipped.discard();
129
+
129
130
  }
130
131
 
131
132
  } )();
@@ -2,7 +2,9 @@ import Node, { addNodeClass } from '../core/Node.js';
2
2
  import { reference } from './ReferenceNode.js';
3
3
  import { materialReference } from './MaterialReferenceNode.js';
4
4
  import { normalView } from './NormalNode.js';
5
- import { nodeImmutable, float } from '../shadernode/ShaderNode.js';
5
+ import { nodeImmutable, float, vec2, mat2 } from '../shadernode/ShaderNode.js';
6
+ import { uniform } from '../core/UniformNode.js';
7
+ import { Vector2 } from 'three';
6
8
 
7
9
  const _propertyCache = new Map();
8
10
 
@@ -89,7 +91,7 @@ class MaterialNode extends Node {
89
91
 
90
92
  if ( material.specularMap && material.specularMap.isTexture === true ) {
91
93
 
92
- node = this.getTexture( scope ).r;
94
+ node = this.getTexture( 'specular' ).r;
93
95
 
94
96
  } else {
95
97
 
@@ -97,6 +99,34 @@ class MaterialNode extends Node {
97
99
 
98
100
  }
99
101
 
102
+ } else if ( scope === MaterialNode.SPECULAR_INTENSITY ) {
103
+
104
+ const specularIntensity = this.getFloat( scope );
105
+
106
+ if ( material.specularMap ) {
107
+
108
+ node = specularIntensity.mul( this.getTexture( scope ).a );
109
+
110
+ } else {
111
+
112
+ node = specularIntensity;
113
+
114
+ }
115
+
116
+ } else if ( scope === MaterialNode.SPECULAR_COLOR ) {
117
+
118
+ const specularColorNode = this.getColor( scope );
119
+
120
+ if ( material.specularColorMap && material.specularColorMap.isTexture === true ) {
121
+
122
+ node = specularColorNode.mul( this.getTexture( scope ).rgb );
123
+
124
+ } else {
125
+
126
+ node = specularColorNode;
127
+
128
+ }
129
+
100
130
  } else if ( scope === MaterialNode.ROUGHNESS ) { // TODO: cleanup similar branches
101
131
 
102
132
  const roughnessNode = this.getFloat( scope );
@@ -225,6 +255,21 @@ class MaterialNode extends Node {
225
255
 
226
256
  node = node.clamp( 0.07, 1.0 );
227
257
 
258
+ } else if ( scope === MaterialNode.ANISOTROPY ) {
259
+
260
+ if ( material.anisotropyMap && material.anisotropyMap.isTexture === true ) {
261
+
262
+ const anisotropyPolar = this.getTexture( scope );
263
+ const anisotropyMat = mat2( materialAnisotropyVector.x, materialAnisotropyVector.y, materialAnisotropyVector.y.negate(), materialAnisotropyVector.x );
264
+
265
+ node = anisotropyMat.mul( anisotropyPolar.rg.mul( 2.0 ).sub( vec2( 1.0 ) ).normalize().mul( anisotropyPolar.b ) );
266
+
267
+ } else {
268
+
269
+ node = materialAnisotropyVector;
270
+
271
+ }
272
+
228
273
  } else if ( scope === MaterialNode.IRIDESCENCE_THICKNESS ) {
229
274
 
230
275
  const iridescenceThicknessMaximum = reference( '1', 'float', material.iridescenceThicknessRange );
@@ -241,6 +286,38 @@ class MaterialNode extends Node {
241
286
 
242
287
  }
243
288
 
289
+ } else if ( scope === MaterialNode.TRANSMISSION ) {
290
+
291
+ const transmissionNode = this.getFloat( scope );
292
+
293
+ if ( material.transmissionMap ) {
294
+
295
+ node = transmissionNode.mul( this.getTexture( scope ).r );
296
+
297
+ } else {
298
+
299
+ node = transmissionNode;
300
+
301
+ }
302
+
303
+ } else if ( scope === MaterialNode.THICKNESS ) {
304
+
305
+ const thicknessNode = this.getFloat( scope );
306
+
307
+ if ( material.thicknessMap ) {
308
+
309
+ node = thicknessNode.mul( this.getTexture( scope ).g );
310
+
311
+ } else {
312
+
313
+ node = thicknessNode;
314
+
315
+ }
316
+
317
+ } else if ( scope === MaterialNode.IOR ) {
318
+
319
+ node = this.getFloat( scope );
320
+
244
321
  } else {
245
322
 
246
323
  const outputType = this.getNodeType( builder );
@@ -259,8 +336,10 @@ MaterialNode.ALPHA_TEST = 'alphaTest';
259
336
  MaterialNode.COLOR = 'color';
260
337
  MaterialNode.OPACITY = 'opacity';
261
338
  MaterialNode.SHININESS = 'shininess';
262
- MaterialNode.SPECULAR_COLOR = 'specular';
339
+ MaterialNode.SPECULAR = 'specular';
263
340
  MaterialNode.SPECULAR_STRENGTH = 'specularStrength';
341
+ MaterialNode.SPECULAR_INTENSITY = 'specularIntensity';
342
+ MaterialNode.SPECULAR_COLOR = 'specularColor';
264
343
  MaterialNode.REFLECTIVITY = 'reflectivity';
265
344
  MaterialNode.ROUGHNESS = 'roughness';
266
345
  MaterialNode.METALNESS = 'metalness';
@@ -272,9 +351,15 @@ MaterialNode.EMISSIVE = 'emissive';
272
351
  MaterialNode.ROTATION = 'rotation';
273
352
  MaterialNode.SHEEN = 'sheen';
274
353
  MaterialNode.SHEEN_ROUGHNESS = 'sheenRoughness';
354
+ MaterialNode.ANISOTROPY = 'anisotropy';
275
355
  MaterialNode.IRIDESCENCE = 'iridescence';
276
356
  MaterialNode.IRIDESCENCE_IOR = 'iridescenceIOR';
277
357
  MaterialNode.IRIDESCENCE_THICKNESS = 'iridescenceThickness';
358
+ MaterialNode.IOR = 'ior';
359
+ MaterialNode.TRANSMISSION = 'transmission';
360
+ MaterialNode.THICKNESS = 'thickness';
361
+ MaterialNode.ATTENUATION_DISTANCE = 'attenuationDistance';
362
+ MaterialNode.ATTENUATION_COLOR = 'attenuationColor';
278
363
  MaterialNode.LINE_SCALE = 'scale';
279
364
  MaterialNode.LINE_DASH_SIZE = 'dashSize';
280
365
  MaterialNode.LINE_GAP_SIZE = 'gapSize';
@@ -289,7 +374,11 @@ export const materialColor = nodeImmutable( MaterialNode, MaterialNode.COLOR );
289
374
  export const materialShininess = nodeImmutable( MaterialNode, MaterialNode.SHININESS );
290
375
  export const materialEmissive = nodeImmutable( MaterialNode, MaterialNode.EMISSIVE );
291
376
  export const materialOpacity = nodeImmutable( MaterialNode, MaterialNode.OPACITY );
377
+ export const materialSpecular = nodeImmutable( MaterialNode, MaterialNode.SPECULAR );
378
+
379
+ export const materialSpecularIntensity = nodeImmutable( MaterialNode, MaterialNode.SPECULAR_INTENSITY );
292
380
  export const materialSpecularColor = nodeImmutable( MaterialNode, MaterialNode.SPECULAR_COLOR );
381
+
293
382
  export const materialSpecularStrength = nodeImmutable( MaterialNode, MaterialNode.SPECULAR_STRENGTH );
294
383
  export const materialReflectivity = nodeImmutable( MaterialNode, MaterialNode.REFLECTIVITY );
295
384
  export const materialRoughness = nodeImmutable( MaterialNode, MaterialNode.ROUGHNESS );
@@ -301,14 +390,29 @@ export const materialClearcoatNormal = nodeImmutable( MaterialNode, MaterialNode
301
390
  export const materialRotation = nodeImmutable( MaterialNode, MaterialNode.ROTATION );
302
391
  export const materialSheen = nodeImmutable( MaterialNode, MaterialNode.SHEEN );
303
392
  export const materialSheenRoughness = nodeImmutable( MaterialNode, MaterialNode.SHEEN_ROUGHNESS );
393
+ export const materialAnisotropy = nodeImmutable( MaterialNode, MaterialNode.ANISOTROPY );
304
394
  export const materialIridescence = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE );
305
395
  export const materialIridescenceIOR = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_IOR );
306
396
  export const materialIridescenceThickness = nodeImmutable( MaterialNode, MaterialNode.IRIDESCENCE_THICKNESS );
397
+ export const materialTransmission = nodeImmutable( MaterialNode, MaterialNode.TRANSMISSION );
398
+ export const materialThickness = nodeImmutable( MaterialNode, MaterialNode.THICKNESS );
399
+ export const materialIOR = nodeImmutable( MaterialNode, MaterialNode.IOR );
400
+ export const materialAttenuationDistance = nodeImmutable( MaterialNode, MaterialNode.ATTENUATION_DISTANCE );
401
+ export const materialAttenuationColor = nodeImmutable( MaterialNode, MaterialNode.ATTENUATION_COLOR );
307
402
  export const materialLineScale = nodeImmutable( MaterialNode, MaterialNode.LINE_SCALE );
308
403
  export const materialLineDashSize = nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_SIZE );
309
404
  export const materialLineGapSize = nodeImmutable( MaterialNode, MaterialNode.LINE_GAP_SIZE );
310
405
  export const materialLineWidth = nodeImmutable( MaterialNode, MaterialNode.LINE_WIDTH );
311
406
  export const materialLineDashOffset = nodeImmutable( MaterialNode, MaterialNode.LINE_DASH_OFFSET );
312
407
  export const materialPointWidth = nodeImmutable( MaterialNode, MaterialNode.POINT_WIDTH );
408
+ export const materialAnisotropyVector = uniform( new Vector2() ).onReference( function ( frame ) {
409
+
410
+ return frame.material;
411
+
412
+ } ).onRenderUpdate( function ( { material } ) {
413
+
414
+ this.value.set( material.anisotropy * Math.cos( material.anisotropyRotation ), material.anisotropy * Math.sin( material.anisotropyRotation ) );
415
+
416
+ } );
313
417
 
314
418
  addNodeClass( 'MaterialNode', MaterialNode );
@@ -18,6 +18,15 @@ class StorageBufferNode extends BufferNode {
18
18
  this._attribute = null;
19
19
  this._varying = null;
20
20
 
21
+ if ( value.isStorageBufferAttribute !== true && value.isStorageInstancedBufferAttribute !== true ) {
22
+
23
+ // TOOD: Improve it, possibly adding a new property to the BufferAttribute to identify it as a storage buffer read-only attribute in Renderer
24
+
25
+ if ( value.isInstancedBufferAttribute ) value.isStorageInstancedBufferAttribute = true;
26
+ else value.isStorageBufferAttribute = true;
27
+
28
+ }
29
+
21
30
  }
22
31
 
23
32
  getInputType( /*builder*/ ) {
@@ -20,6 +20,7 @@ class TextureNode extends UniformNode {
20
20
  this.levelNode = levelNode;
21
21
  this.compareNode = null;
22
22
  this.depthNode = null;
23
+ this.gradNode = null;
23
24
 
24
25
  this.sampler = true;
25
26
  this.updateMatrix = false;
@@ -155,6 +156,7 @@ class TextureNode extends UniformNode {
155
156
  properties.uvNode = uvNode;
156
157
  properties.levelNode = levelNode;
157
158
  properties.compareNode = this.compareNode;
159
+ properties.gradNode = this.gradNode;
158
160
  properties.depthNode = this.depthNode;
159
161
 
160
162
  }
@@ -165,7 +167,7 @@ class TextureNode extends UniformNode {
165
167
 
166
168
  }
167
169
 
168
- generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, depthSnippet, compareSnippet ) {
170
+ generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, depthSnippet, compareSnippet, gradSnippet ) {
169
171
 
170
172
  const texture = this.value;
171
173
 
@@ -175,6 +177,10 @@ class TextureNode extends UniformNode {
175
177
 
176
178
  snippet = builder.generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet );
177
179
 
180
+ } else if ( gradSnippet ) {
181
+
182
+ snippet = builder.generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet );
183
+
178
184
  } else if ( compareSnippet ) {
179
185
 
180
186
  snippet = builder.generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet );
@@ -223,18 +229,19 @@ class TextureNode extends UniformNode {
223
229
 
224
230
  if ( propertyName === undefined ) {
225
231
 
226
- const { uvNode, levelNode, compareNode, depthNode } = properties;
232
+ const { uvNode, levelNode, compareNode, depthNode, gradNode } = properties;
227
233
 
228
234
  const uvSnippet = this.generateUV( builder, uvNode );
229
235
  const levelSnippet = levelNode ? levelNode.build( builder, 'float' ) : null;
230
236
  const depthSnippet = depthNode ? depthNode.build( builder, 'int' ) : null;
231
237
  const compareSnippet = compareNode ? compareNode.build( builder, 'float' ) : null;
238
+ const gradSnippet = gradNode ? [ gradNode[ 0 ].build( builder, 'vec2' ), gradNode[ 1 ].build( builder, 'vec2' ) ] : null;
232
239
 
233
240
  const nodeVar = builder.getVarFromNode( this );
234
241
 
235
242
  propertyName = builder.getPropertyName( nodeVar );
236
243
 
237
- const snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, depthSnippet, compareSnippet );
244
+ const snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, depthSnippet, compareSnippet, gradSnippet );
238
245
 
239
246
  builder.addLineFlowCode( `${propertyName} = ${snippet}` );
240
247
 
@@ -324,6 +331,17 @@ class TextureNode extends UniformNode {
324
331
 
325
332
  }
326
333
 
334
+ grad( gradNodeX, gradNodeY ) {
335
+
336
+ const textureNode = this.clone();
337
+ textureNode.gradNode = [ nodeObject( gradNodeX ), nodeObject( gradNodeY ) ];
338
+
339
+ textureNode.referenceNode = this;
340
+
341
+ return nodeObject( textureNode );
342
+
343
+ }
344
+
327
345
  depth( depthNode ) {
328
346
 
329
347
  const textureNode = this.clone();
@@ -20,7 +20,7 @@ class TextureSizeNode extends Node {
20
20
  const textureProperty = this.textureNode.build( builder, 'property' );
21
21
  const levelNode = this.levelNode.build( builder, 'int' );
22
22
 
23
- return builder.format( `${builder.getMethod( 'textureDimensions' )}( ${textureProperty}, ${levelNode} )`, this.getNodeType( builder ), output );
23
+ return builder.format( `${ builder.getMethod( 'textureDimensions' ) }( ${ textureProperty }, ${ levelNode } )`, this.getNodeType( builder ), output );
24
24
 
25
25
  }
26
26
 
@@ -127,12 +127,4 @@ const nativeFn = ( code, includes = [], language = '' ) => {
127
127
  export const glslFn = ( code, includes ) => nativeFn( code, includes, 'glsl' );
128
128
  export const wgslFn = ( code, includes ) => nativeFn( code, includes, 'wgsl' );
129
129
 
130
- export const func = ( code, includes ) => { // @deprecated, r154
131
-
132
- console.warn( 'TSL: func() is deprecated. Use nativeFn(), wgslFn() or glslFn() instead.' );
133
-
134
- return nodeObject( new FunctionNode( code, includes ) );
135
-
136
- };
137
-
138
130
  addNodeClass( 'FunctionNode', FunctionNode );
@@ -74,6 +74,14 @@ class Node extends EventDispatcher {
74
74
 
75
75
  }
76
76
 
77
+ onReference( callback ) {
78
+
79
+ this.updateReference = callback.bind( this.getSelf() );
80
+
81
+ return this;
82
+
83
+ }
84
+
77
85
  getSelf() {
78
86
 
79
87
  // Returns non-node object.