@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
@@ -78,7 +78,7 @@ class SceneNode extends Node {
78
78
 
79
79
  } else if ( scope === SceneNode.BACKGROUND_ROTATION ) {
80
80
 
81
- output = uniform( 'mat4' ).label( 'backgroundRotation' ).setGroup( renderGroup ).onRenderUpdate( () => {
81
+ output = uniform( 'mat4' ).setName( 'backgroundRotation' ).setGroup( renderGroup ).onRenderUpdate( () => {
82
82
 
83
83
  const background = scene.background;
84
84
 
@@ -186,7 +186,7 @@ class StorageTextureNode extends TextureNode {
186
186
  const { uvNode, storeNode, depthNode } = properties;
187
187
 
188
188
  const textureProperty = super.generate( builder, 'property' );
189
- const uvSnippet = uvNode.build( builder, 'uvec2' );
189
+ const uvSnippet = uvNode.build( builder, this.value.is3DTexture === true ? 'uvec3' : 'uvec2' );
190
190
  const storeSnippet = storeNode.build( builder, 'vec4' );
191
191
  const depthSnippet = depthNode ? depthNode.build( builder, 'int' ) : null;
192
192
 
@@ -157,6 +157,19 @@ class Texture3DNode extends TextureNode {
157
157
 
158
158
  }
159
159
 
160
+ /**
161
+ * Generates the offset code snippet.
162
+ *
163
+ * @param {NodeBuilder} builder - The current node builder.
164
+ * @param {Node} offsetNode - The offset node to generate code for.
165
+ * @return {string} The generated code snippet.
166
+ */
167
+ generateOffset( builder, offsetNode ) {
168
+
169
+ return offsetNode.build( builder, 'ivec3' );
170
+
171
+ }
172
+
160
173
  /**
161
174
  * TODO.
162
175
  *
@@ -95,6 +95,15 @@ class TextureNode extends UniformNode {
95
95
  */
96
96
  this.gradNode = null;
97
97
 
98
+ /**
99
+ * Represents the optional texel offset applied to the unnormalized texture
100
+ * coordinate before sampling the texture.
101
+ *
102
+ * @type {?Node<ivec2|ivec3>}
103
+ * @default null
104
+ */
105
+ this.offsetNode = null;
106
+
98
107
  /**
99
108
  * Whether texture values should be sampled or fetched.
100
109
  *
@@ -364,6 +373,7 @@ class TextureNode extends UniformNode {
364
373
  properties.compareNode = this.compareNode;
365
374
  properties.gradNode = this.gradNode;
366
375
  properties.depthNode = this.depthNode;
376
+ properties.offsetNode = this.offsetNode;
367
377
 
368
378
  }
369
379
 
@@ -380,6 +390,19 @@ class TextureNode extends UniformNode {
380
390
 
381
391
  }
382
392
 
393
+ /**
394
+ * Generates the offset code snippet.
395
+ *
396
+ * @param {NodeBuilder} builder - The current node builder.
397
+ * @param {Node} offsetNode - The offset node to generate code for.
398
+ * @return {string} The generated code snippet.
399
+ */
400
+ generateOffset( builder, offsetNode ) {
401
+
402
+ return offsetNode.build( builder, 'ivec2' );
403
+
404
+ }
405
+
383
406
  /**
384
407
  * Generates the snippet for the texture sampling.
385
408
  *
@@ -391,9 +414,10 @@ class TextureNode extends UniformNode {
391
414
  * @param {?string} depthSnippet - The depth snippet.
392
415
  * @param {?string} compareSnippet - The compare snippet.
393
416
  * @param {?Array<string>} gradSnippet - The grad snippet.
417
+ * @param {?string} offsetSnippet - The offset snippet.
394
418
  * @return {string} The generated code snippet.
395
419
  */
396
- generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet ) {
420
+ generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet, offsetSnippet ) {
397
421
 
398
422
  const texture = this.value;
399
423
 
@@ -401,27 +425,27 @@ class TextureNode extends UniformNode {
401
425
 
402
426
  if ( levelSnippet ) {
403
427
 
404
- snippet = builder.generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet );
428
+ snippet = builder.generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, offsetSnippet );
405
429
 
406
430
  } else if ( biasSnippet ) {
407
431
 
408
- snippet = builder.generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet );
432
+ snippet = builder.generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet, offsetSnippet );
409
433
 
410
434
  } else if ( gradSnippet ) {
411
435
 
412
- snippet = builder.generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet );
436
+ snippet = builder.generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, offsetSnippet );
413
437
 
414
438
  } else if ( compareSnippet ) {
415
439
 
416
- snippet = builder.generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet );
440
+ snippet = builder.generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, offsetSnippet );
417
441
 
418
442
  } else if ( this.sampler === false ) {
419
443
 
420
- snippet = builder.generateTextureLoad( texture, textureProperty, uvSnippet, depthSnippet );
444
+ snippet = builder.generateTextureLoad( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet );
421
445
 
422
446
  } else {
423
447
 
424
- snippet = builder.generateTexture( texture, textureProperty, uvSnippet, depthSnippet );
448
+ snippet = builder.generateTexture( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet );
425
449
 
426
450
  }
427
451
 
@@ -459,7 +483,7 @@ class TextureNode extends UniformNode {
459
483
 
460
484
  if ( propertyName === undefined ) {
461
485
 
462
- const { uvNode, levelNode, biasNode, compareNode, depthNode, gradNode } = properties;
486
+ const { uvNode, levelNode, biasNode, compareNode, depthNode, gradNode, offsetNode } = properties;
463
487
 
464
488
  const uvSnippet = this.generateUV( builder, uvNode );
465
489
  const levelSnippet = levelNode ? levelNode.build( builder, 'float' ) : null;
@@ -467,12 +491,13 @@ class TextureNode extends UniformNode {
467
491
  const depthSnippet = depthNode ? depthNode.build( builder, 'int' ) : null;
468
492
  const compareSnippet = compareNode ? compareNode.build( builder, 'float' ) : null;
469
493
  const gradSnippet = gradNode ? [ gradNode[ 0 ].build( builder, 'vec2' ), gradNode[ 1 ].build( builder, 'vec2' ) ] : null;
494
+ const offsetSnippet = offsetNode ? this.generateOffset( builder, offsetNode ) : null;
470
495
 
471
496
  const nodeVar = builder.getVarFromNode( this );
472
497
 
473
498
  propertyName = builder.getPropertyName( nodeVar );
474
499
 
475
- const snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet );
500
+ const snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet, offsetSnippet );
476
501
 
477
502
  builder.addLineFlowCode( `${propertyName} = ${snippet}`, this );
478
503
 
@@ -548,12 +573,24 @@ class TextureNode extends UniformNode {
548
573
 
549
574
  const textureNode = this.clone();
550
575
  textureNode.uvNode = nodeObject( uvNode );
551
- textureNode.referenceNode = this.getSelf();
576
+ textureNode.referenceNode = this.getBase();
552
577
 
553
578
  return nodeObject( textureNode );
554
579
 
555
580
  }
556
581
 
582
+ /**
583
+ * TSL function for creating a texture node that fetches/loads texels without interpolation.
584
+ *
585
+ * @param {Node<uvec2>} uvNode - The uv node.
586
+ * @returns {TextureNode} A texture node representing the texture load.
587
+ */
588
+ load( uvNode ) {
589
+
590
+ return this.sample( uvNode ).setSampler( false );
591
+
592
+ }
593
+
557
594
  /**
558
595
  * Samples a blurred version of the texture by defining an internal bias.
559
596
  *
@@ -564,7 +601,7 @@ class TextureNode extends UniformNode {
564
601
 
565
602
  const textureNode = this.clone();
566
603
  textureNode.biasNode = nodeObject( amountNode ).mul( maxMipLevel( textureNode ) );
567
- textureNode.referenceNode = this.getSelf();
604
+ textureNode.referenceNode = this.getBase();
568
605
 
569
606
  const map = textureNode.value;
570
607
 
@@ -590,7 +627,7 @@ class TextureNode extends UniformNode {
590
627
 
591
628
  const textureNode = this.clone();
592
629
  textureNode.levelNode = nodeObject( levelNode );
593
- textureNode.referenceNode = this.getSelf();
630
+ textureNode.referenceNode = this.getBase();
594
631
 
595
632
  return nodeObject( textureNode );
596
633
 
@@ -618,12 +655,22 @@ class TextureNode extends UniformNode {
618
655
 
619
656
  const textureNode = this.clone();
620
657
  textureNode.biasNode = nodeObject( biasNode );
621
- textureNode.referenceNode = this.getSelf();
658
+ textureNode.referenceNode = this.getBase();
622
659
 
623
660
  return nodeObject( textureNode );
624
661
 
625
662
  }
626
663
 
664
+ /**
665
+ * Returns the base texture of this node.
666
+ * @return {TextureNode} The base texture node.
667
+ */
668
+ getBase() {
669
+
670
+ return this.referenceNode ? this.referenceNode.getBase() : this;
671
+
672
+ }
673
+
627
674
  /**
628
675
  * Samples the texture by executing a compare operation.
629
676
  *
@@ -634,7 +681,7 @@ class TextureNode extends UniformNode {
634
681
 
635
682
  const textureNode = this.clone();
636
683
  textureNode.compareNode = nodeObject( compareNode );
637
- textureNode.referenceNode = this.getSelf();
684
+ textureNode.referenceNode = this.getBase();
638
685
 
639
686
  return nodeObject( textureNode );
640
687
 
@@ -651,7 +698,7 @@ class TextureNode extends UniformNode {
651
698
 
652
699
  const textureNode = this.clone();
653
700
  textureNode.gradNode = [ nodeObject( gradNodeX ), nodeObject( gradNodeY ) ];
654
- textureNode.referenceNode = this.getSelf();
701
+ textureNode.referenceNode = this.getBase();
655
702
 
656
703
  return nodeObject( textureNode );
657
704
 
@@ -667,7 +714,23 @@ class TextureNode extends UniformNode {
667
714
 
668
715
  const textureNode = this.clone();
669
716
  textureNode.depthNode = nodeObject( depthNode );
670
- textureNode.referenceNode = this.getSelf();
717
+ textureNode.referenceNode = this.getBase();
718
+
719
+ return nodeObject( textureNode );
720
+
721
+ }
722
+
723
+ /**
724
+ * Samples the texture by defining an offset node.
725
+ *
726
+ * @param {Node<ivec2>} offsetNode - The offset node.
727
+ * @return {TextureNode} A texture node representing the texture sample.
728
+ */
729
+ offset( offsetNode ) {
730
+
731
+ const textureNode = this.clone();
732
+ textureNode.offsetNode = nodeObject( offsetNode );
733
+ textureNode.referenceNode = this.getBase();
671
734
 
672
735
  return nodeObject( textureNode );
673
736
 
@@ -727,6 +790,7 @@ class TextureNode extends UniformNode {
727
790
  newNode.depthNode = this.depthNode;
728
791
  newNode.compareNode = this.compareNode;
729
792
  newNode.gradNode = this.gradNode;
793
+ newNode.offsetNode = this.offsetNode;
730
794
 
731
795
  return newNode;
732
796
 
@@ -754,7 +818,7 @@ const textureBase = /*@__PURE__*/ nodeProxy( TextureNode ).setParameterLength( 1
754
818
  *
755
819
  * @tsl
756
820
  * @function
757
- * @param {?Texture|TextureNode} [value=EmptyTexture] - The texture.
821
+ * @param {?(Texture|TextureNode)} [value=EmptyTexture] - The texture.
758
822
  * @param {?Node<vec2|vec3>} [uvNode=null] - The uv node.
759
823
  * @param {?Node<int>} [levelNode=null] - The level node.
760
824
  * @param {?Node<float>} [biasNode=null] - The bias node.
@@ -767,7 +831,7 @@ export const texture = ( value = EmptyTexture, uvNode = null, levelNode = null,
767
831
  if ( value && value.isTextureNode === true ) {
768
832
 
769
833
  textureNode = nodeObject( value.clone() );
770
- textureNode.referenceNode = value.getSelf(); // Ensure the reference is set to the original node
834
+ textureNode.referenceNode = value.getBase(); // Ensure the reference is set to the original node
771
835
 
772
836
  if ( uvNode !== null ) textureNode.uvNode = nodeObject( uvNode );
773
837
  if ( levelNode !== null ) textureNode.levelNode = nodeObject( levelNode );
@@ -798,7 +862,7 @@ export const uniformTexture = ( value = EmptyTexture ) => texture( value );
798
862
  *
799
863
  * @tsl
800
864
  * @function
801
- * @param {?Texture|TextureNode} [value=EmptyTexture] - The texture.
865
+ * @param {?(Texture|TextureNode)} [value=EmptyTexture] - The texture.
802
866
  * @param {?Node<vec2|vec3>} [uvNode=null] - The uv node.
803
867
  * @param {?Node<int>} [levelNode=null] - The level node.
804
868
  * @param {?Node<float>} [biasNode=null] - The bias node.
@@ -69,12 +69,31 @@ class FunctionCallNode extends TempNode {
69
69
 
70
70
  }
71
71
 
72
+ /**
73
+ * Returns the type of this function call node.
74
+ *
75
+ * @param {NodeBuilder} builder - The current node builder.
76
+ * @returns {string} The type of this node.
77
+ */
72
78
  getNodeType( builder ) {
73
79
 
74
80
  return this.functionNode.getNodeType( builder );
75
81
 
76
82
  }
77
83
 
84
+ /**
85
+ * Returns the function node of this function call node.
86
+ *
87
+ * @param {NodeBuilder} builder - The current node builder.
88
+ * @param {string} [name] - The name of the member.
89
+ * @returns {string} The type of the member.
90
+ */
91
+ getMemberType( builder, name ) {
92
+
93
+ return this.functionNode.getMemberType( builder, name );
94
+
95
+ }
96
+
78
97
  generate( builder ) {
79
98
 
80
99
  const params = [];
@@ -48,12 +48,35 @@ class FunctionNode extends CodeNode {
48
48
 
49
49
  }
50
50
 
51
+ /**
52
+ * Returns the type of this function node.
53
+ *
54
+ * @param {NodeBuilder} builder - The current node builder.
55
+ * @return {string} The type.
56
+ */
51
57
  getNodeType( builder ) {
52
58
 
53
59
  return this.getNodeFunction( builder ).type;
54
60
 
55
61
  }
56
62
 
63
+ /**
64
+ * Returns the type of a member of this function node.
65
+ *
66
+ * @param {NodeBuilder} builder - The current node builder.
67
+ * @param {string} name - The name of the member.
68
+ * @return {string} The type of the member.
69
+ */
70
+ getMemberType( builder, name ) {
71
+
72
+ const type = this.getNodeType( builder );
73
+
74
+ const structType = builder.getStructTypeNode( type );
75
+
76
+ return structType.getMemberType( builder, name );
77
+
78
+ }
79
+
57
80
  /**
58
81
  * Returns the inputs of this function node.
59
82
  *
@@ -58,6 +58,18 @@ class ArrayNode extends TempNode {
58
58
 
59
59
  }
60
60
 
61
+ /**
62
+ * Returns the number of elements in the node array.
63
+ *
64
+ * @param {NodeBuilder} builder - The current node builder.
65
+ * @return {number} The number of elements in the node array.
66
+ */
67
+ getArrayCount( /*builder*/ ) {
68
+
69
+ return this.count;
70
+
71
+ }
72
+
61
73
  /**
62
74
  * Returns the node's type.
63
75
  *
@@ -97,6 +97,11 @@ class AssignNode extends TempNode {
97
97
 
98
98
  const { targetNode, sourceNode } = this;
99
99
 
100
+ const scope = targetNode.getScope();
101
+
102
+ const targetProperties = builder.getNodeProperties( scope );
103
+ targetProperties.assign = true;
104
+
100
105
  const properties = builder.getNodeProperties( this );
101
106
  properties.sourceNode = sourceNode;
102
107
  properties.targetNode = targetNode.context( { assign: true } );
@@ -109,11 +114,10 @@ class AssignNode extends TempNode {
109
114
 
110
115
  const needsSplitAssign = this.needsSplitAssign( builder );
111
116
 
117
+ const target = targetNode.build( builder );
112
118
  const targetType = targetNode.getNodeType( builder );
113
119
 
114
- const target = targetNode.build( builder );
115
120
  const source = sourceNode.build( builder, targetType );
116
-
117
121
  const sourceType = sourceNode.getNodeType( builder );
118
122
 
119
123
  const nodeData = builder.getDataFromNode( this );
@@ -78,6 +78,19 @@ class ContextNode extends Node {
78
78
 
79
79
  }
80
80
 
81
+ /**
82
+ * This method is overwritten to ensure it returns the member type of {@link ContextNode#node}.
83
+ *
84
+ * @param {NodeBuilder} builder - The current node builder.
85
+ * @param {string} name - The member name.
86
+ * @returns {string} The member type.
87
+ */
88
+ getMemberType( builder, name ) {
89
+
90
+ return this.node.getMemberType( builder, name );
91
+
92
+ }
93
+
81
94
  analyze( builder ) {
82
95
 
83
96
  const previousContext = builder.getContext();
@@ -131,16 +144,46 @@ export default ContextNode;
131
144
  */
132
145
  export const context = /*@__PURE__*/ nodeProxy( ContextNode ).setParameterLength( 1, 2 );
133
146
 
147
+ /**
148
+ * TSL function for defining a uniformFlow context value for a given node.
149
+ *
150
+ * @tsl
151
+ * @function
152
+ * @param {Node} node - The node whose dependencies should all execute within a uniform control-flow path.
153
+ * @returns {ContextNode}
154
+ */
155
+ export const uniformFlow = ( node ) => context( node, { uniformFlow: true } );
156
+
157
+ /**
158
+ * TSL function for defining a name for the context value for a given node.
159
+ *
160
+ * @tsl
161
+ * @function
162
+ * @param {Node} node - The node whose context should be modified.
163
+ * @param {string} name - The name to set.
164
+ * @returns {ContextNode}
165
+ */
166
+ export const setName = ( node, name ) => context( node, { nodeName: name } );
167
+
134
168
  /**
135
169
  * TSL function for defining a label context value for a given node.
136
170
  *
137
171
  * @tsl
138
172
  * @function
173
+ * @deprecated
139
174
  * @param {Node} node - The node whose context should be modified.
140
175
  * @param {string} name - The name/label to set.
141
176
  * @returns {ContextNode}
142
177
  */
143
- export const label = ( node, name ) => context( node, { label: name } );
178
+ export function label( node, name ) {
179
+
180
+ console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
181
+
182
+ return setName( node, name );
183
+
184
+ }
144
185
 
145
186
  addMethodChaining( 'context', context );
146
187
  addMethodChaining( 'label', label );
188
+ addMethodChaining( 'uniformFlow', uniformFlow );
189
+ addMethodChaining( 'setName', setName );
@@ -172,7 +172,7 @@ class Node extends EventDispatcher {
172
172
  onUpdate( callback, updateType ) {
173
173
 
174
174
  this.updateType = updateType;
175
- this.update = callback.bind( this.getSelf() );
175
+ this.update = callback.bind( this );
176
176
 
177
177
  return this;
178
178
 
@@ -225,26 +225,12 @@ class Node extends EventDispatcher {
225
225
  */
226
226
  onReference( callback ) {
227
227
 
228
- this.updateReference = callback.bind( this.getSelf() );
228
+ this.updateReference = callback.bind( this );
229
229
 
230
230
  return this;
231
231
 
232
232
  }
233
233
 
234
- /**
235
- * The `this` reference might point to a Proxy so this method can be used
236
- * to get the reference to the actual node instance.
237
- *
238
- * @return {Node} A reference to the node.
239
- */
240
- getSelf() {
241
-
242
- // Returns non-node object.
243
-
244
- return this.self || this;
245
-
246
- }
247
-
248
234
  /**
249
235
  * Nodes might refer to other objects like materials. This method allows to dynamically update the reference
250
236
  * to such objects based on a given state (e.g. the current node frame or builder).
@@ -480,10 +466,22 @@ class Node extends EventDispatcher {
480
466
 
481
467
  }
482
468
 
469
+ /**
470
+ * Returns the number of elements in the node array.
471
+ *
472
+ * @param {NodeBuilder} builder - The current node builder.
473
+ * @return {?number} The number of elements in the node array.
474
+ */
475
+ getArrayCount( /*builder*/ ) {
476
+
477
+ return null;
478
+
479
+ }
480
+
483
481
  /**
484
482
  * Represents the setup stage which is the first step of the build process, see {@link Node#build} method.
485
- * This method is often overwritten in derived modules to prepare the node which is used as the output/result.
486
- * The output node must be returned in the `return` statement.
483
+ * This method is often overwritten in derived modules to prepare the node which is used as a node's output/result.
484
+ * If an output node is prepared, then it must be returned in the `return` statement of the derived module's setup function.
487
485
  *
488
486
  * @param {NodeBuilder} builder - The current node builder.
489
487
  * @return {?Node} The output node.
@@ -551,7 +549,7 @@ class Node extends EventDispatcher {
551
549
  * This state builds the output node and returns the resulting shader string.
552
550
  *
553
551
  * @param {NodeBuilder} builder - The current node builder.
554
- * @param {?string} output - Can be used to define the output type.
552
+ * @param {?string} [output] - Can be used to define the output type.
555
553
  * @return {?string} The generated shader string.
556
554
  */
557
555
  generate( builder, output ) {
@@ -615,8 +613,8 @@ class Node extends EventDispatcher {
615
613
  * - **generate**: Generates the shader code for the node. Returns the generated shader string.
616
614
  *
617
615
  * @param {NodeBuilder} builder - The current node builder.
618
- * @param {string|Node|null} [output=null] - Can be used to define the output type.
619
- * @return {Node|string|null} The result of the build process, depending on the build stage.
616
+ * @param {?(string|Node)} [output=null] - Can be used to define the output type.
617
+ * @return {?(Node|string)} The result of the build process, depending on the build stage.
620
618
  */
621
619
  build( builder, output = null ) {
622
620
 
@@ -753,6 +751,16 @@ class Node extends EventDispatcher {
753
751
 
754
752
  }
755
753
 
754
+ if ( result === '' && output !== null && output !== 'void' && output !== 'OutputType' ) {
755
+
756
+ // if no snippet is generated, return a default value
757
+
758
+ console.error( `THREE.TSL: Invalid generated code, expected a "${ output }".` );
759
+
760
+ result = builder.generateConst( output );
761
+
762
+ }
763
+
756
764
  }
757
765
 
758
766
  builder.removeChain( this );
@@ -765,7 +773,7 @@ class Node extends EventDispatcher {
765
773
  /**
766
774
  * Returns the child nodes as a JSON object.
767
775
  *
768
- * @return {Array<Object>} An iterable list of serialized child objects as JSON.
776
+ * @return {Generator<Object>} An iterable list of serialized child objects as JSON.
769
777
  */
770
778
  getSerializeChildren() {
771
779