@plastic-software/three 0.178.0 → 0.180.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 (245) hide show
  1. package/README.md +1 -1
  2. package/build/three.cjs +950 -230
  3. package/build/three.core.js +754 -138
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +197 -96
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +99 -25
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +4586 -1499
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +4544 -1499
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/Addons.js +2 -3
  14. package/examples/jsm/capabilities/WebGPU.js +1 -1
  15. package/examples/jsm/controls/ArcballControls.js +7 -7
  16. package/examples/jsm/controls/DragControls.js +6 -56
  17. package/examples/jsm/controls/FirstPersonControls.js +2 -2
  18. package/examples/jsm/controls/PointerLockControls.js +0 -8
  19. package/examples/jsm/csm/CSMShadowNode.js +4 -4
  20. package/examples/jsm/environments/RoomEnvironment.js +8 -3
  21. package/examples/jsm/exporters/GLTFExporter.js +30 -22
  22. package/examples/jsm/exporters/KTX2Exporter.js +4 -2
  23. package/examples/jsm/exporters/PLYExporter.js +1 -1
  24. package/examples/jsm/exporters/USDZExporter.js +676 -299
  25. package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
  26. package/examples/jsm/interactive/HTMLMesh.js +5 -3
  27. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  28. package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
  29. package/examples/jsm/lights/LightProbeGenerator.js +14 -3
  30. package/examples/jsm/lines/Line2.js +3 -3
  31. package/examples/jsm/lines/LineGeometry.js +1 -1
  32. package/examples/jsm/lines/LineSegments2.js +2 -2
  33. package/examples/jsm/lines/Wireframe.js +2 -2
  34. package/examples/jsm/lines/WireframeGeometry2.js +1 -1
  35. package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
  36. package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
  37. package/examples/jsm/loaders/ColladaLoader.js +1 -1
  38. package/examples/jsm/loaders/EXRLoader.js +210 -22
  39. package/examples/jsm/loaders/FBXLoader.js +1 -1
  40. package/examples/jsm/loaders/GLTFLoader.js +9 -5
  41. package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
  42. package/examples/jsm/loaders/HDRLoader.js +486 -0
  43. package/examples/jsm/loaders/KTX2Loader.js +112 -32
  44. package/examples/jsm/loaders/MaterialXLoader.js +212 -30
  45. package/examples/jsm/loaders/RGBELoader.js +7 -473
  46. package/examples/jsm/loaders/TTFLoader.js +13 -1
  47. package/examples/jsm/loaders/USDLoader.js +219 -0
  48. package/examples/jsm/loaders/USDZLoader.js +4 -892
  49. package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
  50. package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
  51. package/examples/jsm/loaders/usd/USDAParser.js +741 -0
  52. package/examples/jsm/loaders/usd/USDCParser.js +17 -0
  53. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  54. package/examples/jsm/math/ColorSpaces.js +19 -1
  55. package/examples/jsm/math/ConvexHull.js +2 -2
  56. package/examples/jsm/math/Lut.js +2 -2
  57. package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
  58. package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
  59. package/examples/jsm/misc/Volume.js +1 -1
  60. package/examples/jsm/objects/LensflareMesh.js +3 -3
  61. package/examples/jsm/objects/SkyMesh.js +2 -2
  62. package/examples/jsm/physics/RapierPhysics.js +14 -5
  63. package/examples/jsm/postprocessing/GTAOPass.js +10 -9
  64. package/examples/jsm/postprocessing/OutlinePass.js +17 -17
  65. package/examples/jsm/postprocessing/SSAOPass.js +10 -9
  66. package/examples/jsm/postprocessing/SSRPass.js +37 -8
  67. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
  68. package/examples/jsm/transpiler/GLSLDecoder.js +23 -20
  69. package/examples/jsm/transpiler/TSLEncoder.js +2 -10
  70. package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
  71. package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
  72. package/examples/jsm/tsl/display/BloomNode.js +7 -6
  73. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
  74. package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
  75. package/examples/jsm/tsl/display/GTAONode.js +8 -0
  76. package/examples/jsm/tsl/display/GaussianBlurNode.js +51 -41
  77. package/examples/jsm/tsl/display/OutlineNode.js +2 -2
  78. package/examples/jsm/tsl/display/SSRNode.js +180 -65
  79. package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
  80. package/examples/jsm/tsl/display/boxBlur.js +64 -0
  81. package/examples/jsm/tsl/display/hashBlur.js +15 -18
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
  83. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  84. package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
  85. package/examples/jsm/webxr/OculusHandModel.js +1 -1
  86. package/package.json +1 -1
  87. package/src/Three.Core.js +2 -0
  88. package/src/Three.TSL.js +98 -24
  89. package/src/animation/AnimationClip.js +17 -2
  90. package/src/animation/KeyframeTrack.js +1 -1
  91. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  92. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  93. package/src/cameras/Camera.js +14 -0
  94. package/src/cameras/OrthographicCamera.js +1 -1
  95. package/src/cameras/PerspectiveCamera.js +1 -1
  96. package/src/constants.js +11 -3
  97. package/src/core/BufferGeometry.js +2 -2
  98. package/{examples/jsm/misc → src/core}/Timer.js +4 -42
  99. package/src/extras/PMREMGenerator.js +11 -0
  100. package/src/extras/TextureUtils.js +2 -1
  101. package/src/extras/lib/earcut.js +1 -1
  102. package/src/helpers/CameraHelper.js +41 -11
  103. package/src/helpers/SkeletonHelper.js +35 -6
  104. package/src/lights/LightShadow.js +21 -8
  105. package/src/lights/PointLightShadow.js +1 -1
  106. package/src/lights/webgpu/ProjectorLight.js +1 -1
  107. package/src/loaders/FileLoader.js +25 -2
  108. package/src/loaders/ImageBitmapLoader.js +23 -0
  109. package/src/loaders/Loader.js +14 -0
  110. package/src/loaders/LoadingManager.js +23 -0
  111. package/src/materials/Material.js +12 -0
  112. package/src/materials/MeshBasicMaterial.js +1 -1
  113. package/src/materials/MeshDistanceMaterial.js +1 -1
  114. package/src/materials/nodes/Line2NodeMaterial.js +0 -8
  115. package/src/materials/nodes/NodeMaterial.js +1 -1
  116. package/src/materials/nodes/PointsNodeMaterial.js +86 -28
  117. package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
  118. package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
  119. package/src/math/ColorManagement.js +7 -1
  120. package/src/math/Frustum.js +19 -8
  121. package/src/math/FrustumArray.js +10 -5
  122. package/src/math/Line3.js +129 -2
  123. package/src/math/Matrix4.js +48 -27
  124. package/src/math/Spherical.js +2 -2
  125. package/src/nodes/Nodes.js +4 -0
  126. package/src/nodes/TSL.js +4 -0
  127. package/src/nodes/accessors/BufferNode.js +1 -1
  128. package/src/nodes/accessors/Camera.js +142 -16
  129. package/src/nodes/accessors/ClippingNode.js +6 -5
  130. package/src/nodes/accessors/CubeTextureNode.js +2 -2
  131. package/src/nodes/accessors/InstanceNode.js +3 -1
  132. package/src/nodes/accessors/Normal.js +11 -11
  133. package/src/nodes/accessors/Object3DNode.js +1 -1
  134. package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
  135. package/src/nodes/accessors/ReferenceNode.js +19 -4
  136. package/src/nodes/accessors/SceneNode.js +1 -1
  137. package/src/nodes/accessors/StorageTextureNode.js +1 -1
  138. package/src/nodes/accessors/Texture3DNode.js +13 -0
  139. package/src/nodes/accessors/TextureNode.js +83 -19
  140. package/src/nodes/code/FunctionCallNode.js +19 -0
  141. package/src/nodes/code/FunctionNode.js +23 -0
  142. package/src/nodes/core/ArrayNode.js +12 -0
  143. package/src/nodes/core/AssignNode.js +6 -2
  144. package/src/nodes/core/ContextNode.js +44 -1
  145. package/src/nodes/core/Node.js +30 -22
  146. package/src/nodes/core/NodeBuilder.js +71 -32
  147. package/src/nodes/core/NodeFrame.js +1 -1
  148. package/src/nodes/core/NodeUniform.js +1 -1
  149. package/src/nodes/core/NodeUtils.js +5 -3
  150. package/src/nodes/core/StackNode.js +71 -4
  151. package/src/nodes/core/StructNode.js +5 -5
  152. package/src/nodes/core/StructTypeNode.js +1 -0
  153. package/src/nodes/core/SubBuildNode.js +2 -2
  154. package/src/nodes/core/UniformNode.js +79 -14
  155. package/src/nodes/core/VarNode.js +83 -15
  156. package/src/nodes/display/FrontFacingNode.js +4 -8
  157. package/src/nodes/display/PassNode.js +148 -2
  158. package/src/nodes/display/ScreenNode.js +42 -13
  159. package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
  160. package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
  161. package/src/nodes/display/ViewportTextureNode.js +94 -4
  162. package/src/nodes/functions/PhysicalLightingModel.js +2 -2
  163. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  164. package/src/nodes/gpgpu/ComputeNode.js +67 -23
  165. package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
  166. package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
  167. package/src/nodes/lighting/LightsNode.js +1 -1
  168. package/src/nodes/lighting/ProjectorLightNode.js +19 -6
  169. package/src/nodes/lighting/ShadowFilterNode.js +1 -1
  170. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  171. package/src/nodes/materialx/lib/mx_noise.js +165 -1
  172. package/src/nodes/math/BitcastNode.js +156 -0
  173. package/src/nodes/math/ConditionalNode.js +19 -3
  174. package/src/nodes/math/MathNode.js +72 -60
  175. package/src/nodes/math/OperatorNode.js +26 -25
  176. package/src/nodes/tsl/TSLCore.js +477 -142
  177. package/src/nodes/utils/DebugNode.js +1 -1
  178. package/src/nodes/utils/EventNode.js +83 -0
  179. package/src/nodes/utils/JoinNode.js +3 -1
  180. package/src/nodes/utils/MemberNode.js +58 -7
  181. package/src/nodes/utils/RTTNode.js +10 -1
  182. package/src/nodes/utils/ReflectorNode.js +51 -7
  183. package/src/nodes/utils/SampleNode.js +12 -2
  184. package/src/nodes/utils/SplitNode.js +11 -0
  185. package/src/nodes/utils/Timer.js +0 -47
  186. package/src/objects/BatchedMesh.js +6 -4
  187. package/src/objects/LOD.js +1 -1
  188. package/src/objects/Sprite.js +2 -2
  189. package/src/renderers/WebGLRenderer.js +21 -31
  190. package/src/renderers/common/Attributes.js +1 -1
  191. package/src/renderers/common/Backend.js +19 -1
  192. package/src/renderers/common/Bindings.js +21 -18
  193. package/src/renderers/common/ChainMap.js +1 -1
  194. package/src/renderers/common/Color4.js +2 -2
  195. package/src/renderers/common/DataMap.js +1 -1
  196. package/src/renderers/common/Pipelines.js +1 -1
  197. package/src/renderers/common/PostProcessing.js +60 -5
  198. package/src/renderers/common/RenderContext.js +2 -2
  199. package/src/renderers/common/RenderObject.js +14 -2
  200. package/src/renderers/common/Renderer.js +55 -32
  201. package/src/renderers/common/SampledTexture.js +4 -72
  202. package/src/renderers/common/Sampler.js +91 -0
  203. package/src/renderers/common/Storage3DTexture.js +21 -0
  204. package/src/renderers/common/StorageArrayTexture.js +21 -0
  205. package/src/renderers/common/StorageTexture.js +19 -0
  206. package/src/renderers/common/Textures.js +52 -14
  207. package/src/renderers/common/TimestampQueryPool.js +3 -3
  208. package/src/renderers/common/XRManager.js +51 -17
  209. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  210. package/src/renderers/common/nodes/NodeLibrary.js +5 -5
  211. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
  212. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
  213. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  214. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
  215. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
  216. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +21 -11
  217. package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
  218. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  219. package/src/renderers/webgl/WebGLMaterials.js +6 -6
  220. package/src/renderers/webgl/WebGLProgram.js +24 -18
  221. package/src/renderers/webgl/WebGLPrograms.js +4 -4
  222. package/src/renderers/webgl/WebGLShadowMap.js +11 -1
  223. package/src/renderers/webgl/WebGLTextures.js +20 -7
  224. package/src/renderers/webgl/WebGLUtils.js +3 -2
  225. package/src/renderers/webgl-fallback/WebGLBackend.js +207 -146
  226. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +112 -19
  227. package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
  228. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
  229. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
  230. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
  231. package/src/renderers/webgpu/WebGPUBackend.js +87 -44
  232. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +169 -99
  233. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +35 -31
  234. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
  235. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +10 -19
  236. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +120 -84
  237. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
  238. package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
  239. package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
  240. package/src/renderers/webxr/WebXRManager.js +86 -11
  241. package/src/textures/ExternalTexture.js +56 -0
  242. package/src/textures/FramebufferTexture.js +2 -2
  243. package/src/textures/Source.js +12 -2
  244. package/src/textures/VideoTexture.js +27 -2
  245. package/examples/jsm/loaders/RGBMLoader.js +0 -1148
@@ -1,18 +1,36 @@
1
1
  import SpriteNodeMaterial from './SpriteNodeMaterial.js';
2
- import { viewport } from '../../nodes/display/ScreenNode.js';
2
+ import { viewportSize, screenDPR } from '../../nodes/display/ScreenNode.js';
3
3
  import { positionGeometry, positionLocal, positionView } from '../../nodes/accessors/Position.js';
4
4
  import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
5
5
  import { materialPointSize } from '../../nodes/accessors/MaterialNode.js';
6
6
  import { rotate } from '../../nodes/utils/RotateNode.js';
7
- import { float, vec2, vec3, vec4 } from '../../nodes/tsl/TSLBase.js';
7
+ import { float, uniform, vec2, vec3, vec4 } from '../../nodes/tsl/TSLBase.js';
8
8
 
9
9
  import { PointsMaterial } from '../PointsMaterial.js';
10
+ import { Vector2 } from '../../math/Vector2.js';
10
11
 
11
12
  const _defaultValues = /*@__PURE__*/ new PointsMaterial();
13
+ const _size = /*@__PURE__*/ new Vector2();
12
14
 
13
15
  /**
14
16
  * Node material version of {@link PointsMaterial}.
15
17
  *
18
+ * This material can be used in two ways:
19
+ *
20
+ * - By rendering point primitives with {@link Points}. Since WebGPU only supports point primitives
21
+ * with a pixel size of `1`, it's not possible to define a size.
22
+ *
23
+ * ```js
24
+ * const pointCloud = new THREE.Points( geometry, new THREE.PointsNodeMaterial() );
25
+ * ```
26
+ *
27
+ * - By rendering point primitives with {@link Sprites}. In this case, size is honored,
28
+ * see {@link PointsNodeMaterial#sizeNode}.
29
+ *
30
+ * ```js
31
+ * const instancedPoints = new THREE.Sprite( new THREE.PointsNodeMaterial( { positionNode: instancedBufferAttribute( positionAttribute ) } ) );
32
+ * ```
33
+ *
16
34
  * @augments SpriteNodeMaterial
17
35
  */
18
36
  class PointsNodeMaterial extends SpriteNodeMaterial {
@@ -35,6 +53,11 @@ class PointsNodeMaterial extends SpriteNodeMaterial {
35
53
  /**
36
54
  * This node property provides an additional way to set the point size.
37
55
  *
56
+ * Note that WebGPU only supports point primitives with 1 pixel size. Consequently,
57
+ * this node has no effect when the material is used with {@link Points} and a WebGPU
58
+ * backend. If an application wants to render points with a size larger than 1 pixel,
59
+ * the material should be used with {@link Sprite} and instancing.
60
+ *
38
61
  * @type {?Node<vec2>}
39
62
  * @default null
40
63
  */
@@ -63,68 +86,95 @@ class PointsNodeMaterial extends SpriteNodeMaterial {
63
86
 
64
87
  }
65
88
 
66
- setupVertex( builder ) {
89
+ setupVertexSprite( builder ) {
90
+
91
+ const { material, camera } = builder;
92
+
93
+ const { rotationNode, scaleNode, sizeNode, sizeAttenuation } = this;
67
94
 
68
- const mvp = super.setupVertex( builder );
95
+ let mvp = super.setupVertex( builder );
69
96
 
70
97
  // skip further processing if the material is not a node material
71
98
 
72
- if ( builder.material.isNodeMaterial !== true ) {
99
+ if ( material.isNodeMaterial !== true ) {
73
100
 
74
101
  return mvp;
75
102
 
76
103
  }
77
104
 
78
- // ndc space
105
+ // point size
79
106
 
80
- const { rotationNode, scaleNode, sizeNode } = this;
107
+ let pointSize = sizeNode !== null ? vec2( sizeNode ) : materialPointSize;
81
108
 
82
- const alignedPosition = positionGeometry.xy.toVar();
83
- const aspect = viewport.z.div( viewport.w );
109
+ pointSize = pointSize.mul( screenDPR );
84
110
 
85
- // rotation
111
+ // size attenuation
86
112
 
87
- if ( rotationNode && rotationNode.isNode ) {
113
+ if ( camera.isPerspectiveCamera && sizeAttenuation === true ) {
88
114
 
89
- const rotation = float( rotationNode );
115
+ // follow WebGLRenderer's implementation, and scale by half the canvas height in logical units
90
116
 
91
- alignedPosition.assign( rotate( alignedPosition, rotation ) );
117
+ pointSize = pointSize.mul( scale.div( positionView.z.negate() ) );
92
118
 
93
119
  }
94
120
 
95
- // point size
96
-
97
- let pointSize = sizeNode !== null ? vec2( sizeNode ) : materialPointSize;
121
+ // scale
98
122
 
99
- if ( this.sizeAttenuation === true ) {
123
+ if ( scaleNode && scaleNode.isNode ) {
100
124
 
101
- pointSize = pointSize.mul( pointSize.div( positionView.z.negate() ) );
125
+ pointSize = pointSize.mul( vec2( scaleNode ) );
102
126
 
103
127
  }
104
128
 
105
- // scale
129
+ // compute offset
106
130
 
107
- if ( scaleNode && scaleNode.isNode ) {
131
+ let offset = positionGeometry.xy;
108
132
 
109
- pointSize = pointSize.mul( vec2( scaleNode ) );
133
+ // apply rotation
134
+
135
+ if ( rotationNode && rotationNode.isNode ) {
136
+
137
+ const rotation = float( rotationNode );
138
+
139
+ offset = rotate( offset, rotation );
110
140
 
111
141
  }
112
142
 
113
- alignedPosition.mulAssign( pointSize.mul( 2 ) );
143
+ // account for point size
144
+
145
+ offset = offset.mul( pointSize );
146
+
147
+ // scale by viewport size
114
148
 
115
- alignedPosition.assign( alignedPosition.div( viewport.z ) );
116
- alignedPosition.y.assign( alignedPosition.y.mul( aspect ) );
149
+ offset = offset.div( viewportSize.div( 2 ) );
117
150
 
118
- // back to clip space
119
- alignedPosition.assign( alignedPosition.mul( mvp.w ) );
151
+ // compensate for the perspective divide
120
152
 
121
- //clipPos.xy += offset;
122
- mvp.addAssign( vec4( alignedPosition, 0, 0 ) );
153
+ offset = offset.mul( mvp.w );
154
+
155
+ // add offset
156
+
157
+ mvp = mvp.add( vec4( offset, 0, 0 ) );
123
158
 
124
159
  return mvp;
125
160
 
126
161
  }
127
162
 
163
+ setupVertex( builder ) {
164
+
165
+ if ( builder.object.isPoints ) {
166
+
167
+ return super.setupVertex( builder );
168
+
169
+
170
+ } else {
171
+
172
+ return this.setupVertexSprite( builder );
173
+
174
+ }
175
+
176
+ }
177
+
128
178
  /**
129
179
  * Whether alpha to coverage should be used or not.
130
180
  *
@@ -150,4 +200,12 @@ class PointsNodeMaterial extends SpriteNodeMaterial {
150
200
 
151
201
  }
152
202
 
203
+ const scale = /*@__PURE__*/ uniform( 1 ).onFrameUpdate( function ( { renderer } ) {
204
+
205
+ const size = renderer.getSize( _size ); // logical units
206
+
207
+ this.value = 0.5 * size.y;
208
+
209
+ } );
210
+
153
211
  export default PointsNodeMaterial;
@@ -1,5 +1,4 @@
1
1
  import NodeMaterial from './NodeMaterial.js';
2
- import { cameraProjectionMatrix } from '../../nodes/accessors/Camera.js';
3
2
  import { materialRotation } from '../../nodes/accessors/MaterialNode.js';
4
3
  import { modelViewMatrix, modelWorldMatrix } from '../../nodes/accessors/ModelNode.js';
5
4
  import { positionGeometry } from '../../nodes/accessors/Position.js';
@@ -111,9 +110,7 @@ class SpriteNodeMaterial extends NodeMaterial {
111
110
 
112
111
  const { object, camera } = builder;
113
112
 
114
- const sizeAttenuation = this.sizeAttenuation;
115
-
116
- const { positionNode, rotationNode, scaleNode } = this;
113
+ const { positionNode, rotationNode, scaleNode, sizeAttenuation } = this;
117
114
 
118
115
  const mvPosition = modelViewMatrix.mul( vec3( positionNode || 0 ) );
119
116
 
@@ -125,18 +122,9 @@ class SpriteNodeMaterial extends NodeMaterial {
125
122
 
126
123
  }
127
124
 
128
- if ( sizeAttenuation === false ) {
129
-
130
- if ( camera.isPerspectiveCamera ) {
131
-
132
- scale = scale.mul( mvPosition.z.negate() );
133
-
134
- } else {
135
-
136
- const orthoScale = float( 2.0 ).div( cameraProjectionMatrix.element( 1 ).element( 1 ) );
137
- scale = scale.mul( orthoScale.mul( 2 ) );
125
+ if ( camera.isPerspectiveCamera && sizeAttenuation === false ) {
138
126
 
139
- }
127
+ scale = scale.mul( mvPosition.z.negate() );
140
128
 
141
129
  }
142
130
 
@@ -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<Object>} 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
 
@@ -34,7 +34,7 @@ function createColorManagement() {
34
34
  * - luminanceCoefficients: RGB luminance coefficients
35
35
  *
36
36
  * Optional:
37
- * - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace }
37
+ * - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace, toneMappingMode: 'extended' | 'standard' }
38
38
  * - workingColorSpaceConfig: { unpackColorSpace: ColorSpace }
39
39
  *
40
40
  * Reference:
@@ -103,6 +103,12 @@ function createColorManagement() {
103
103
 
104
104
  },
105
105
 
106
+ getToneMappingMode: function ( colorSpace ) {
107
+
108
+ return this.spaces[ colorSpace ].outputColorSpaceConfig.toneMappingMode || 'standard';
109
+
110
+ },
111
+
106
112
  getLuminanceCoefficients: function ( target, colorSpace = this.workingColorSpace ) {
107
113
 
108
114
  return target.fromArray( this.spaces[ colorSpace ].luminanceCoefficients );
@@ -89,9 +89,10 @@ class Frustum {
89
89
  *
90
90
  * @param {Matrix4} m - The projection matrix.
91
91
  * @param {(WebGLCoordinateSystem|WebGPUCoordinateSystem)} coordinateSystem - The coordinate system.
92
+ * @param {boolean} [reversedDepth=false] - Whether to use a reversed depth.
92
93
  * @return {Frustum} A reference to this frustum.
93
94
  */
94
- setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) {
95
+ setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem, reversedDepth = false ) {
95
96
 
96
97
  const planes = this.planes;
97
98
  const me = m.elements;
@@ -104,19 +105,29 @@ class Frustum {
104
105
  planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
105
106
  planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
106
107
  planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
107
- planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
108
108
 
109
- if ( coordinateSystem === WebGLCoordinateSystem ) {
109
+ if ( reversedDepth ) {
110
110
 
111
- 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
112
113
 
113
- } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
114
+ } else {
114
115
 
115
- planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize();
116
+ planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize(); // far
116
117
 
117
- } 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 ) {
118
123
 
119
- throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
124
+ planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize(); // near
125
+
126
+ } else {
127
+
128
+ throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
129
+
130
+ }
120
131
 
121
132
  }
122
133
 
@@ -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
  *