super-three 0.177.0 → 0.179.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 (211) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +959 -231
  3. package/build/three.core.js +751 -170
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +210 -64
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +78 -29
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3269 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3093 -1545
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +1 -2
  14. package/examples/jsm/capabilities/WebGL.js +0 -27
  15. package/examples/jsm/capabilities/WebGPU.js +1 -1
  16. package/examples/jsm/controls/ArcballControls.js +1 -1
  17. package/examples/jsm/controls/TransformControls.js +61 -14
  18. package/examples/jsm/csm/CSMShadowNode.js +4 -4
  19. package/examples/jsm/environments/RoomEnvironment.js +8 -3
  20. package/examples/jsm/exporters/USDZExporter.js +676 -299
  21. package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
  22. package/examples/jsm/interactive/HTMLMesh.js +5 -3
  23. package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
  24. package/examples/jsm/lights/LightProbeGenerator.js +14 -3
  25. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  26. package/examples/jsm/loaders/EXRLoader.js +210 -22
  27. package/examples/jsm/loaders/FBXLoader.js +2 -2
  28. package/examples/jsm/loaders/MaterialXLoader.js +212 -30
  29. package/examples/jsm/loaders/TTFLoader.js +13 -1
  30. package/examples/jsm/loaders/USDLoader.js +219 -0
  31. package/examples/jsm/loaders/USDZLoader.js +4 -892
  32. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  33. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  34. package/examples/jsm/objects/LensflareMesh.js +3 -3
  35. package/examples/jsm/objects/SkyMesh.js +2 -2
  36. package/examples/jsm/physics/RapierPhysics.js +95 -16
  37. package/examples/jsm/postprocessing/GTAOPass.js +10 -9
  38. package/examples/jsm/postprocessing/OutlinePass.js +17 -17
  39. package/examples/jsm/postprocessing/SSAOPass.js +10 -9
  40. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
  41. package/examples/jsm/transpiler/AST.js +381 -30
  42. package/examples/jsm/transpiler/GLSLDecoder.js +226 -86
  43. package/examples/jsm/transpiler/Linker.js +327 -0
  44. package/examples/jsm/transpiler/TSLEncoder.js +197 -92
  45. package/examples/jsm/transpiler/Transpiler.js +17 -1
  46. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  47. package/examples/jsm/transpiler/WGSLEncoder.js +788 -0
  48. package/examples/jsm/tsl/display/BloomNode.js +8 -7
  49. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +206 -0
  50. package/examples/jsm/tsl/display/GaussianBlurNode.js +8 -10
  51. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  52. package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
  53. package/examples/jsm/tsl/display/hashBlur.js +3 -3
  54. package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
  55. package/package.json +1 -1
  56. package/src/Three.Core.js +1 -0
  57. package/src/Three.TSL.js +77 -28
  58. package/src/Three.WebGPU.js +2 -0
  59. package/src/animation/KeyframeTrack.js +1 -1
  60. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  61. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  62. package/src/cameras/Camera.js +14 -0
  63. package/src/cameras/OrthographicCamera.js +1 -1
  64. package/src/cameras/PerspectiveCamera.js +1 -1
  65. package/src/constants.js +3 -3
  66. package/src/core/BufferAttribute.js +3 -3
  67. package/src/core/Clock.js +2 -8
  68. package/src/core/GLBufferAttribute.js +13 -1
  69. package/src/core/Object3D.js +1 -1
  70. package/{examples/jsm/misc → src/core}/Timer.js +4 -42
  71. package/src/extras/PMREMGenerator.js +11 -0
  72. package/src/extras/core/Path.js +22 -22
  73. package/src/helpers/CameraHelper.js +41 -11
  74. package/src/helpers/SkeletonHelper.js +35 -6
  75. package/src/lights/LightShadow.js +21 -8
  76. package/src/lights/PointLightShadow.js +1 -1
  77. package/src/loaders/FileLoader.js +27 -4
  78. package/src/loaders/ImageBitmapLoader.js +27 -4
  79. package/src/loaders/ImageLoader.js +55 -8
  80. package/src/loaders/Loader.js +14 -0
  81. package/src/loaders/LoadingManager.js +23 -0
  82. package/src/materials/MeshBasicMaterial.js +1 -1
  83. package/src/materials/nodes/Line2NodeMaterial.js +0 -8
  84. package/src/materials/nodes/MeshBasicNodeMaterial.js +4 -3
  85. package/src/materials/nodes/MeshMatcapNodeMaterial.js +1 -1
  86. package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
  87. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -1
  88. package/src/materials/nodes/MeshSSSNodeMaterial.js +2 -2
  89. package/src/materials/nodes/NodeMaterial.js +28 -5
  90. package/src/materials/nodes/PointsNodeMaterial.js +5 -0
  91. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
  92. package/src/math/Frustum.js +25 -9
  93. package/src/math/FrustumArray.js +10 -5
  94. package/src/math/Line3.js +129 -2
  95. package/src/math/Matrix4.js +48 -27
  96. package/src/math/Quaternion.js +1 -1
  97. package/src/math/Spherical.js +2 -2
  98. package/src/nodes/Nodes.js +2 -3
  99. package/src/nodes/TSL.js +5 -3
  100. package/src/nodes/accessors/AccessorsUtils.js +7 -8
  101. package/src/nodes/accessors/Bitangent.js +31 -25
  102. package/src/nodes/accessors/Camera.js +12 -12
  103. package/src/nodes/accessors/Normal.js +95 -29
  104. package/src/nodes/accessors/Object3DNode.js +1 -1
  105. package/src/nodes/accessors/Position.js +7 -7
  106. package/src/nodes/accessors/ReferenceNode.js +18 -3
  107. package/src/nodes/accessors/ReflectVector.js +3 -3
  108. package/src/nodes/accessors/SceneNode.js +1 -1
  109. package/src/nodes/accessors/StorageTextureNode.js +1 -1
  110. package/src/nodes/accessors/Tangent.js +25 -17
  111. package/src/nodes/accessors/TangentUtils.js +46 -0
  112. package/src/nodes/accessors/TextureBicubic.js +21 -3
  113. package/src/nodes/accessors/TextureNode.js +12 -0
  114. package/src/nodes/accessors/UniformArrayNode.js +0 -16
  115. package/src/nodes/core/ArrayNode.js +12 -0
  116. package/src/nodes/core/AssignNode.js +3 -0
  117. package/src/nodes/core/CacheNode.js +0 -14
  118. package/src/nodes/core/ContextNode.js +20 -1
  119. package/src/nodes/core/Node.js +15 -3
  120. package/src/nodes/core/NodeBuilder.js +228 -92
  121. package/src/nodes/core/NodeUtils.js +4 -1
  122. package/src/nodes/core/StackNode.js +49 -29
  123. package/src/nodes/core/SubBuildNode.js +89 -0
  124. package/src/nodes/core/UniformNode.js +63 -5
  125. package/src/nodes/core/VarNode.js +91 -2
  126. package/src/nodes/core/VaryingNode.js +6 -4
  127. package/src/nodes/display/BlendModes.js +2 -2
  128. package/src/nodes/display/FrontFacingNode.js +34 -2
  129. package/src/nodes/display/NormalMapNode.js +19 -50
  130. package/src/nodes/display/PassNode.js +157 -9
  131. package/src/nodes/display/ScreenNode.js +0 -26
  132. package/src/nodes/display/ViewportTextureNode.js +67 -7
  133. package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
  134. package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
  135. package/src/nodes/functions/PhongLightingModel.js +3 -3
  136. package/src/nodes/functions/PhysicalLightingModel.js +16 -16
  137. package/src/nodes/functions/material/getGeometryRoughness.js +2 -2
  138. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  139. package/src/nodes/gpgpu/ComputeNode.js +67 -23
  140. package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
  141. package/src/nodes/lighting/EnvironmentNode.js +5 -5
  142. package/src/nodes/lighting/LightsNode.js +4 -4
  143. package/src/nodes/lighting/ProjectorLightNode.js +19 -6
  144. package/src/nodes/lighting/ShadowFilterNode.js +1 -1
  145. package/src/nodes/lighting/ShadowNode.js +2 -2
  146. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  147. package/src/nodes/materialx/lib/mx_noise.js +165 -1
  148. package/src/nodes/math/ConditionalNode.js +1 -20
  149. package/src/nodes/math/MathNode.js +90 -55
  150. package/src/nodes/math/OperatorNode.js +22 -39
  151. package/src/nodes/tsl/TSLBase.js +1 -0
  152. package/src/nodes/tsl/TSLCore.js +114 -55
  153. package/src/nodes/utils/DebugNode.js +1 -1
  154. package/src/nodes/utils/EquirectUV.js +27 -0
  155. package/src/nodes/utils/EventNode.js +83 -0
  156. package/src/nodes/utils/LoopNode.js +0 -17
  157. package/src/nodes/utils/MatcapUV.js +22 -0
  158. package/src/nodes/utils/RTTNode.js +22 -5
  159. package/src/nodes/utils/ReflectorNode.js +11 -4
  160. package/src/nodes/utils/SampleNode.js +81 -0
  161. package/src/nodes/utils/TriplanarTextures.js +65 -0
  162. package/src/objects/BatchedMesh.js +4 -2
  163. package/src/renderers/WebGLRenderer.js +26 -24
  164. package/src/renderers/common/Background.js +2 -2
  165. package/src/renderers/common/Bindings.js +19 -18
  166. package/src/renderers/common/Color4.js +2 -2
  167. package/src/renderers/common/CubeRenderTarget.js +1 -1
  168. package/src/renderers/common/PostProcessing.js +60 -5
  169. package/src/renderers/common/RenderObject.js +68 -3
  170. package/src/renderers/common/Renderer.js +19 -16
  171. package/src/renderers/common/SampledTexture.js +3 -71
  172. package/src/renderers/common/Sampler.js +79 -0
  173. package/src/renderers/common/Storage3DTexture.js +100 -0
  174. package/src/renderers/common/StorageArrayTexture.js +84 -0
  175. package/src/renderers/common/StorageTexture.js +19 -0
  176. package/src/renderers/common/Textures.js +19 -3
  177. package/src/renderers/common/XRManager.js +31 -12
  178. package/src/renderers/common/XRRenderTarget.js +21 -4
  179. package/src/renderers/common/extras/PMREMGenerator.js +1 -1
  180. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
  181. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +20 -2
  182. package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
  183. package/src/renderers/webgl/WebGLAttributes.js +4 -0
  184. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  185. package/src/renderers/webgl/WebGLProgram.js +12 -6
  186. package/src/renderers/webgl/WebGLPrograms.js +6 -4
  187. package/src/renderers/webgl/WebGLShadowMap.js +11 -1
  188. package/src/renderers/webgl/WebGLState.js +4 -4
  189. package/src/renderers/webgl/WebGLTextures.js +19 -7
  190. package/src/renderers/webgl-fallback/WebGLBackend.js +103 -72
  191. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +3 -5
  192. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +4 -0
  193. package/src/renderers/webgl-fallback/utils/WebGLState.js +4 -4
  194. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +2 -0
  195. package/src/renderers/webgpu/WebGPUBackend.js +63 -16
  196. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +64 -79
  197. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -0
  198. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -31
  199. package/src/renderers/webgpu/utils/WebGPUConstants.js +7 -1
  200. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +5 -5
  201. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +12 -65
  202. package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
  203. package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
  204. package/src/renderers/webxr/WebXRManager.js +68 -6
  205. package/src/textures/ExternalTexture.js +45 -0
  206. package/src/textures/FramebufferTexture.js +2 -2
  207. package/src/textures/Source.js +11 -1
  208. package/src/textures/VideoTexture.js +30 -2
  209. package/src/nodes/utils/EquirectUVNode.js +0 -65
  210. package/src/nodes/utils/MatcapUVNode.js +0 -49
  211. package/src/nodes/utils/TriplanarTexturesNode.js +0 -148
@@ -3,8 +3,9 @@ import { materialLightMap } from '../../nodes/accessors/MaterialNode.js';
3
3
  import BasicEnvironmentNode from '../../nodes/lighting/BasicEnvironmentNode.js';
4
4
  import BasicLightMapNode from '../../nodes/lighting/BasicLightMapNode.js';
5
5
  import BasicLightingModel from '../../nodes/functions/BasicLightingModel.js';
6
- import { normalView } from '../../nodes/accessors/Normal.js';
6
+ import { normalViewGeometry } from '../../nodes/accessors/Normal.js';
7
7
  import { diffuseColor } from '../../nodes/core/PropertyNode.js';
8
+ import { directionToFaceDirection } from '../../nodes/display/FrontFacingNode.js';
8
9
 
9
10
  import { MeshBasicMaterial } from '../MeshBasicMaterial.js';
10
11
 
@@ -59,13 +60,13 @@ class MeshBasicNodeMaterial extends NodeMaterial {
59
60
 
60
61
  /**
61
62
  * Basic materials are not affected by normal and bump maps so we
62
- * return by default {@link normalView}.
63
+ * return by default {@link normalViewGeometry}.
63
64
  *
64
65
  * @return {Node<vec3>} The normal node.
65
66
  */
66
67
  setupNormal() {
67
68
 
68
- return normalView; // see #28839
69
+ return directionToFaceDirection( normalViewGeometry ); // see #28839
69
70
 
70
71
  }
71
72
 
@@ -3,7 +3,7 @@ import { materialReference } from '../../nodes/accessors/MaterialReferenceNode.j
3
3
  import { diffuseColor } from '../../nodes/core/PropertyNode.js';
4
4
  import { vec3 } from '../../nodes/tsl/TSLBase.js';
5
5
  import { mix } from '../../nodes/math/MathNode.js';
6
- import { matcapUV } from '../../nodes/utils/MatcapUVNode.js';
6
+ import { matcapUV } from '../../nodes/utils/MatcapUV.js';
7
7
 
8
8
  import { MeshMatcapMaterial } from '../MeshMatcapMaterial.js';
9
9
 
@@ -2,7 +2,7 @@ import NodeMaterial from './NodeMaterial.js';
2
2
  import { diffuseColor } from '../../nodes/core/PropertyNode.js';
3
3
  import { directionToColor } from '../../nodes/utils/Packing.js';
4
4
  import { materialOpacity } from '../../nodes/accessors/MaterialNode.js';
5
- import { transformedNormalView } from '../../nodes/accessors/Normal.js';
5
+ import { normalView } from '../../nodes/accessors/Normal.js';
6
6
  import { colorSpaceToWorking } from '../../nodes/display/ColorSpaceNode.js';
7
7
  import { float, vec4 } from '../../nodes/tsl/TSLBase.js';
8
8
  import { SRGBColorSpace } from '../../constants.js';
@@ -58,7 +58,7 @@ class MeshNormalNodeMaterial extends NodeMaterial {
58
58
 
59
59
  // By convention, a normal packed to RGB is in sRGB color space. Convert it to working color space.
60
60
 
61
- diffuseColor.assign( colorSpaceToWorking( vec4( directionToColor( transformedNormalView ), opacityNode ), SRGBColorSpace ) );
61
+ diffuseColor.assign( colorSpaceToWorking( vec4( directionToColor( normalView ), opacityNode ), SRGBColorSpace ) );
62
62
 
63
63
  }
64
64
 
@@ -6,6 +6,7 @@ import { TBNViewMatrix } from '../../nodes/accessors/AccessorsUtils.js';
6
6
  import PhysicalLightingModel from '../../nodes/functions/PhysicalLightingModel.js';
7
7
  import MeshStandardNodeMaterial from './MeshStandardNodeMaterial.js';
8
8
  import { mix, pow2, min } from '../../nodes/math/MathNode.js';
9
+ import { subBuild } from '../../nodes/core/SubBuildNode.js';
9
10
 
10
11
  import { MeshPhysicalMaterial } from '../MeshPhysicalMaterial.js';
11
12
 
@@ -478,7 +479,7 @@ class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial {
478
479
 
479
480
  setup( builder ) {
480
481
 
481
- builder.context.setupClearcoatNormal = () => this.setupClearcoatNormal( builder );
482
+ builder.context.setupClearcoatNormal = () => subBuild( this.setupClearcoatNormal( builder ), 'NORMAL', 'vec3' );
482
483
 
483
484
  super.setup( builder );
484
485
 
@@ -1,6 +1,6 @@
1
1
  import MeshPhysicalNodeMaterial from './MeshPhysicalNodeMaterial.js';
2
2
  import PhysicalLightingModel from '../../nodes/functions/PhysicalLightingModel.js';
3
- import { transformedNormalView } from '../../nodes/accessors/Normal.js';
3
+ import { normalView } from '../../nodes/accessors/Normal.js';
4
4
  import { positionViewDirection } from '../../nodes/accessors/Position.js';
5
5
  import { float, vec3 } from '../../nodes/tsl/TSLBase.js';
6
6
 
@@ -52,7 +52,7 @@ class SSSLightingModel extends PhysicalLightingModel {
52
52
 
53
53
  const { thicknessColorNode, thicknessDistortionNode, thicknessAmbientNode, thicknessAttenuationNode, thicknessPowerNode, thicknessScaleNode } = material;
54
54
 
55
- const scatteringHalf = lightDirection.add( transformedNormalView.mul( thicknessDistortionNode ) ).normalize();
55
+ const scatteringHalf = lightDirection.add( normalView.mul( thicknessDistortionNode ) ).normalize();
56
56
  const scatteringDot = float( positionViewDirection.dot( scatteringHalf.negate() ).saturate().pow( thicknessPowerNode ).mul( thicknessScaleNode ) );
57
57
  const scatteringIllu = vec3( scatteringDot.add( thicknessAmbientNode ).mul( thicknessColorNode ) );
58
58
 
@@ -13,7 +13,7 @@ import { positionLocal, positionView } from '../../nodes/accessors/Position.js';
13
13
  import { skinning } from '../../nodes/accessors/SkinningNode.js';
14
14
  import { morphReference } from '../../nodes/accessors/MorphNode.js';
15
15
  import { mix } from '../../nodes/math/MathNode.js';
16
- import { namespace, float, vec3, vec4, bool } from '../../nodes/tsl/TSLBase.js';
16
+ import { float, vec3, vec4, bool } from '../../nodes/tsl/TSLBase.js';
17
17
  import AONode from '../../nodes/lighting/AONode.js';
18
18
  import { lightingContext } from '../../nodes/lighting/LightingContextNode.js';
19
19
  import IrradianceNode from '../../nodes/lighting/IrradianceNode.js';
@@ -24,6 +24,8 @@ import NodeMaterialObserver from './manager/NodeMaterialObserver.js';
24
24
  import getAlphaHashThreshold from '../../nodes/functions/material/getAlphaHashThreshold.js';
25
25
  import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
26
26
  import { vertexColor } from '../../nodes/accessors/VertexColorNode.js';
27
+ import { premultiplyAlpha } from '../../nodes/display/BlendModes.js';
28
+ import { subBuild } from '../../nodes/core/SubBuildNode.js';
27
29
 
28
30
  /**
29
31
  * Base class for all node materials.
@@ -444,7 +446,7 @@ class NodeMaterial extends Material {
444
446
  */
445
447
  setup( builder ) {
446
448
 
447
- builder.context.setupNormal = () => this.setupNormal( builder );
449
+ builder.context.setupNormal = () => subBuild( this.setupNormal( builder ), 'NORMAL', 'vec3' );
448
450
  builder.context.setupPositionView = () => this.setupPositionView( builder );
449
451
  builder.context.setupModelViewProjection = () => this.setupModelViewProjection( builder );
450
452
 
@@ -455,7 +457,7 @@ class NodeMaterial extends Material {
455
457
 
456
458
  builder.addStack();
457
459
 
458
- const mvp = this.setupVertex( builder );
460
+ const mvp = subBuild( this.setupVertex( builder ), 'VERTEX' );
459
461
 
460
462
  const vertexNode = this.vertexNode || mvp;
461
463
 
@@ -767,7 +769,7 @@ class NodeMaterial extends Material {
767
769
 
768
770
  if ( this.positionNode !== null ) {
769
771
 
770
- positionLocal.assign( namespace( this.positionNode, 'POSITION' ) );
772
+ positionLocal.assign( subBuild( this.positionNode, 'POSITION', 'vec3' ) );
771
773
 
772
774
  }
773
775
 
@@ -1069,7 +1071,7 @@ class NodeMaterial extends Material {
1069
1071
 
1070
1072
  output.assign( outputNode );
1071
1073
 
1072
- outputNode = vec4( fogNode );
1074
+ outputNode = vec4( fogNode.toVar() );
1073
1075
 
1074
1076
  }
1075
1077
 
@@ -1077,6 +1079,19 @@ class NodeMaterial extends Material {
1077
1079
 
1078
1080
  }
1079
1081
 
1082
+ /**
1083
+ * Setups premultiplied alpha.
1084
+ *
1085
+ * @param {NodeBuilder} builder - The current node builder.
1086
+ * @param {Node<vec4>} outputNode - The existing output node.
1087
+ * @return {Node<vec4>} The output node.
1088
+ */
1089
+ setupPremultipliedAlpha( builder, outputNode ) {
1090
+
1091
+ return premultiplyAlpha( outputNode );
1092
+
1093
+ }
1094
+
1080
1095
  /**
1081
1096
  * Setups the output node.
1082
1097
  *
@@ -1094,6 +1109,14 @@ class NodeMaterial extends Material {
1094
1109
 
1095
1110
  }
1096
1111
 
1112
+ // PREMULTIPLIED ALPHA
1113
+
1114
+ if ( this.premultipliedAlpha === true ) {
1115
+
1116
+ outputNode = this.setupPremultipliedAlpha( builder, outputNode );
1117
+
1118
+ }
1119
+
1097
1120
  return outputNode;
1098
1121
 
1099
1122
  }
@@ -35,6 +35,11 @@ class PointsNodeMaterial extends SpriteNodeMaterial {
35
35
  /**
36
36
  * This node property provides an additional way to set the point size.
37
37
  *
38
+ * Note that WebGPU only supports point primitives with 1 pixel size. Consequently,
39
+ * this node has no effect when the material is used with {@link Points} and a WebGPU
40
+ * backend. If an application wants to render points with a size larger than 1 pixel,
41
+ * the material should be used with {@link Sprite} and instancing.
42
+ *
38
43
  * @type {?Node<vec2>}
39
44
  * @default null
40
45
  */
@@ -55,6 +55,16 @@ const refreshUniforms = [
55
55
  'transmissionMap'
56
56
  ];
57
57
 
58
+
59
+ /**
60
+ * A WeakMap to cache lights data for node materials.
61
+ * Cache lights data by render ID to avoid unnecessary recalculations.
62
+ *
63
+ * @private
64
+ * @type {WeakMap<LightsNode,Object>}
65
+ */
66
+ const _lightsCache = new WeakMap();
67
+
58
68
  /**
59
69
  * This class is used by {@link WebGPURenderer} as management component.
60
70
  * It's primary purpose is to determine whether render objects require a
@@ -196,6 +206,8 @@ class NodeMaterialObserver {
196
206
 
197
207
  }
198
208
 
209
+ data.lights = this.getLightsData( renderObject.lightsNode.getLights() );
210
+
199
211
  this.renderObjects.set( renderObject, data );
200
212
 
201
213
  }
@@ -299,9 +311,10 @@ class NodeMaterialObserver {
299
311
  * Returns `true` if the given render object has not changed its state.
300
312
  *
301
313
  * @param {RenderObject} renderObject - The render object.
314
+ * @param {Array<Light>} lightsData - The current material lights.
302
315
  * @return {boolean} Whether the given render object has changed its state or not.
303
316
  */
304
- equals( renderObject ) {
317
+ equals( renderObject, lightsData ) {
305
318
 
306
319
  const { object, material, geometry } = renderObject;
307
320
 
@@ -462,6 +475,22 @@ class NodeMaterialObserver {
462
475
 
463
476
  }
464
477
 
478
+ // lights
479
+
480
+ if ( renderObjectData.lights ) {
481
+
482
+ for ( let i = 0; i < lightsData.length; i ++ ) {
483
+
484
+ if ( renderObjectData.lights[ i ].map !== lightsData[ i ].map ) {
485
+
486
+ return false;
487
+
488
+ }
489
+
490
+ }
491
+
492
+ }
493
+
465
494
  // center
466
495
 
467
496
  if ( renderObjectData.center ) {
@@ -488,6 +517,61 @@ class NodeMaterialObserver {
488
517
 
489
518
  }
490
519
 
520
+ /**
521
+ * Returns the lights data for the given material lights.
522
+ *
523
+ * @param {Array<Light>} materialLights - The material lights.
524
+ * @return {Array<Object>} The lights data for the given material lights.
525
+ */
526
+ getLightsData( materialLights ) {
527
+
528
+ const lights = [];
529
+
530
+ for ( const light of materialLights ) {
531
+
532
+ if ( light.isSpotLight === true && light.map !== null ) {
533
+
534
+ // only add lights that have a map
535
+
536
+ lights.push( { map: light.map.version } );
537
+
538
+ }
539
+
540
+ }
541
+
542
+ return lights;
543
+
544
+ }
545
+
546
+ /**
547
+ * Returns the lights for the given lights node and render ID.
548
+ *
549
+ * @param {LightsNode} lightsNode - The lights node.
550
+ * @param {number} renderId - The render ID.
551
+ * @return {Array} The lights for the given lights node and render ID.
552
+ */
553
+ getLights( lightsNode, renderId ) {
554
+
555
+ if ( _lightsCache.has( lightsNode ) ) {
556
+
557
+ const cached = _lightsCache.get( lightsNode );
558
+
559
+ if ( cached.renderId === renderId ) {
560
+
561
+ return cached.lightsData;
562
+
563
+ }
564
+
565
+ }
566
+
567
+ const lightsData = this.getLightsData( lightsNode.getLights() );
568
+
569
+ _lightsCache.set( lightsNode, { renderId, lightsData } );
570
+
571
+ return lightsData;
572
+
573
+ }
574
+
491
575
  /**
492
576
  * Checks if the given render object requires a refresh.
493
577
  *
@@ -516,7 +600,8 @@ class NodeMaterialObserver {
516
600
  if ( isStatic || isBundle )
517
601
  return false;
518
602
 
519
- const notEqual = this.equals( renderObject ) !== true;
603
+ const lightsData = this.getLights( renderObject.lightsNode, renderId );
604
+ const notEqual = this.equals( renderObject, lightsData ) !== true;
520
605
 
521
606
  return notEqual;
522
607
 
@@ -1,9 +1,11 @@
1
1
  import { WebGLCoordinateSystem, WebGPUCoordinateSystem } from '../constants.js';
2
+ import { Vector2 } from './Vector2.js';
2
3
  import { Vector3 } from './Vector3.js';
3
4
  import { Sphere } from './Sphere.js';
4
5
  import { Plane } from './Plane.js';
5
6
 
6
7
  const _sphere = /*@__PURE__*/ new Sphere();
8
+ const _defaultSpriteCenter = /*@__PURE__*/ new Vector2( 0.5, 0.5 );
7
9
  const _vector = /*@__PURE__*/ new Vector3();
8
10
 
9
11
  /**
@@ -87,9 +89,10 @@ class Frustum {
87
89
  *
88
90
  * @param {Matrix4} m - The projection matrix.
89
91
  * @param {(WebGLCoordinateSystem|WebGPUCoordinateSystem)} coordinateSystem - The coordinate system.
92
+ * @param {boolean} [reversedDepth=false] - Whether to use a reversed depth.
90
93
  * @return {Frustum} A reference to this frustum.
91
94
  */
92
- setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) {
95
+ setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem, reversedDepth = false ) {
93
96
 
94
97
  const planes = this.planes;
95
98
  const me = m.elements;
@@ -102,19 +105,29 @@ class Frustum {
102
105
  planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
103
106
  planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
104
107
  planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
105
- planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
106
108
 
107
- if ( coordinateSystem === WebGLCoordinateSystem ) {
109
+ if ( reversedDepth ) {
108
110
 
109
- planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
111
+ planes[ 4 ].setComponents( me2, me6, me10, me14 ).normalize(); // far
112
+ planes[ 5 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize(); // near
110
113
 
111
- } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
114
+ } else {
112
115
 
113
- planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize();
116
+ planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize(); // far
114
117
 
115
- } else {
118
+ if ( coordinateSystem === WebGLCoordinateSystem ) {
119
+
120
+ planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize(); // near
121
+
122
+ } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
123
+
124
+ planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize(); // near
116
125
 
117
- throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
126
+ } else {
127
+
128
+ throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
129
+
130
+ }
118
131
 
119
132
  }
120
133
 
@@ -161,7 +174,10 @@ class Frustum {
161
174
  intersectsSprite( sprite ) {
162
175
 
163
176
  _sphere.center.set( 0, 0, 0 );
164
- _sphere.radius = 0.7071067811865476;
177
+
178
+ const offset = _defaultSpriteCenter.distanceTo( sprite.center );
179
+
180
+ _sphere.radius = 0.7071067811865476 + offset;
165
181
  _sphere.applyMatrix4( sprite.matrixWorld );
166
182
 
167
183
  return this.intersectsSphere( _sphere );
@@ -54,7 +54,8 @@ class FrustumArray {
54
54
 
55
55
  _frustum.setFromProjectionMatrix(
56
56
  _projScreenMatrix,
57
- this.coordinateSystem
57
+ camera.coordinateSystem,
58
+ camera.reversedDepth
58
59
  );
59
60
 
60
61
  if ( _frustum.intersectsObject( object ) ) {
@@ -96,7 +97,8 @@ class FrustumArray {
96
97
 
97
98
  _frustum.setFromProjectionMatrix(
98
99
  _projScreenMatrix,
99
- this.coordinateSystem
100
+ camera.coordinateSystem,
101
+ camera.reversedDepth
100
102
  );
101
103
 
102
104
  if ( _frustum.intersectsSprite( sprite ) ) {
@@ -138,7 +140,8 @@ class FrustumArray {
138
140
 
139
141
  _frustum.setFromProjectionMatrix(
140
142
  _projScreenMatrix,
141
- this.coordinateSystem
143
+ camera.coordinateSystem,
144
+ camera.reversedDepth
142
145
  );
143
146
 
144
147
  if ( _frustum.intersectsSphere( sphere ) ) {
@@ -180,7 +183,8 @@ class FrustumArray {
180
183
 
181
184
  _frustum.setFromProjectionMatrix(
182
185
  _projScreenMatrix,
183
- this.coordinateSystem
186
+ camera.coordinateSystem,
187
+ camera.reversedDepth
184
188
  );
185
189
 
186
190
  if ( _frustum.intersectsBox( box ) ) {
@@ -222,7 +226,8 @@ class FrustumArray {
222
226
 
223
227
  _frustum.setFromProjectionMatrix(
224
228
  _projScreenMatrix,
225
- this.coordinateSystem
229
+ camera.coordinateSystem,
230
+ camera.reversedDepth
226
231
  );
227
232
 
228
233
  if ( _frustum.containsPoint( point ) ) {
package/src/math/Line3.js CHANGED
@@ -4,6 +4,12 @@ import { clamp } from './MathUtils.js';
4
4
  const _startP = /*@__PURE__*/ new Vector3();
5
5
  const _startEnd = /*@__PURE__*/ new Vector3();
6
6
 
7
+ const _d1 = /*@__PURE__*/ new Vector3();
8
+ const _d2 = /*@__PURE__*/ new Vector3();
9
+ const _r = /*@__PURE__*/ new Vector3();
10
+ const _c1 = /*@__PURE__*/ new Vector3();
11
+ const _c2 = /*@__PURE__*/ new Vector3();
12
+
7
13
  /**
8
14
  * An analytical line segment in 3D space represented by a start and end point.
9
15
  */
@@ -151,11 +157,11 @@ class Line3 {
151
157
  }
152
158
 
153
159
  /**
154
- * Returns the closets point on the line for a given point.
160
+ * Returns the closest point on the line for a given point.
155
161
  *
156
162
  * @param {Vector3} point - The point to compute the closest point on the line for.
157
163
  * @param {boolean} clampToLine - Whether to clamp the result to the range `[0,1]` or not.
158
- * @param {Vector3} target - The target vector that is used to store the method's result.
164
+ * @param {Vector3} target - The target vector that is used to store the method's result.
159
165
  * @return {Vector3} The closest point on the line.
160
166
  */
161
167
  closestPointToPoint( point, clampToLine, target ) {
@@ -166,6 +172,127 @@ class Line3 {
166
172
 
167
173
  }
168
174
 
175
+ /**
176
+ * Returns the closest squared distance between this line segment and the given one.
177
+ *
178
+ * @param {Line3} line - The line segment to compute the closest squared distance to.
179
+ * @param {Vector3} [c1] - The closest point on this line segment.
180
+ * @param {Vector3} [c2] - The closest point on the given line segment.
181
+ * @return {number} The squared distance between this line segment and the given one.
182
+ */
183
+ distanceSqToLine3( line, c1 = _c1, c2 = _c2 ) {
184
+
185
+ // from Real-Time Collision Detection by Christer Ericson, chapter 5.1.9
186
+
187
+ // Computes closest points C1 and C2 of S1(s)=P1+s*(Q1-P1) and
188
+ // S2(t)=P2+t*(Q2-P2), returning s and t. Function result is squared
189
+ // distance between between S1(s) and S2(t)
190
+
191
+ const EPSILON = 1e-8 * 1e-8; // must be squared since we compare squared length
192
+ let s, t;
193
+
194
+ const p1 = this.start;
195
+ const p2 = line.start;
196
+ const q1 = this.end;
197
+ const q2 = line.end;
198
+
199
+ _d1.subVectors( q1, p1 ); // Direction vector of segment S1
200
+ _d2.subVectors( q2, p2 ); // Direction vector of segment S2
201
+ _r.subVectors( p1, p2 );
202
+
203
+ const a = _d1.dot( _d1 ); // Squared length of segment S1, always nonnegative
204
+ const e = _d2.dot( _d2 ); // Squared length of segment S2, always nonnegative
205
+ const f = _d2.dot( _r );
206
+
207
+ // Check if either or both segments degenerate into points
208
+
209
+ if ( a <= EPSILON && e <= EPSILON ) {
210
+
211
+ // Both segments degenerate into points
212
+
213
+ c1.copy( p1 );
214
+ c2.copy( p2 );
215
+
216
+ c1.sub( c2 );
217
+
218
+ return c1.dot( c1 );
219
+
220
+ }
221
+
222
+ if ( a <= EPSILON ) {
223
+
224
+ // First segment degenerates into a point
225
+
226
+ s = 0;
227
+ t = f / e; // s = 0 => t = (b*s + f) / e = f / e
228
+ t = clamp( t, 0, 1 );
229
+
230
+
231
+ } else {
232
+
233
+ const c = _d1.dot( _r );
234
+
235
+ if ( e <= EPSILON ) {
236
+
237
+ // Second segment degenerates into a point
238
+
239
+ t = 0;
240
+ s = clamp( - c / a, 0, 1 ); // t = 0 => s = (b*t - c) / a = -c / a
241
+
242
+ } else {
243
+
244
+ // The general nondegenerate case starts here
245
+
246
+ const b = _d1.dot( _d2 );
247
+ const denom = a * e - b * b; // Always nonnegative
248
+
249
+ // If segments not parallel, compute closest point on L1 to L2 and
250
+ // clamp to segment S1. Else pick arbitrary s (here 0)
251
+
252
+ if ( denom !== 0 ) {
253
+
254
+ s = clamp( ( b * f - c * e ) / denom, 0, 1 );
255
+
256
+ } else {
257
+
258
+ s = 0;
259
+
260
+ }
261
+
262
+ // Compute point on L2 closest to S1(s) using
263
+ // t = Dot((P1 + D1*s) - P2,D2) / Dot(D2,D2) = (b*s + f) / e
264
+
265
+ t = ( b * s + f ) / e;
266
+
267
+ // If t in [0,1] done. Else clamp t, recompute s for the new value
268
+ // of t using s = Dot((P2 + D2*t) - P1,D1) / Dot(D1,D1)= (t*b - c) / a
269
+ // and clamp s to [0, 1]
270
+
271
+ if ( t < 0 ) {
272
+
273
+ t = 0.;
274
+ s = clamp( - c / a, 0, 1 );
275
+
276
+ } else if ( t > 1 ) {
277
+
278
+ t = 1;
279
+ s = clamp( ( b - c ) / a, 0, 1 );
280
+
281
+ }
282
+
283
+ }
284
+
285
+ }
286
+
287
+ c1.copy( p1 ).add( _d1.multiplyScalar( s ) );
288
+ c2.copy( p2 ).add( _d2.multiplyScalar( t ) );
289
+
290
+ c1.sub( c2 );
291
+
292
+ return c1.dot( c1 );
293
+
294
+ }
295
+
169
296
  /**
170
297
  * Applies a 4x4 transformation matrix to this line segment.
171
298
  *