@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
@@ -575,7 +575,7 @@ class PhysicalLightingModel extends LightingModel {
575
575
  * @param {Object} lightData - The light data.
576
576
  * @param {NodeBuilder} builder - The current node builder.
577
577
  */
578
- direct( { lightDirection, lightColor, reflectedLight } ) {
578
+ direct( { lightDirection, lightColor, reflectedLight }, /* builder */ ) {
579
579
 
580
580
  const dotNL = normalView.dot( lightDirection ).clamp();
581
581
  const irradiance = dotNL.mul( lightColor );
@@ -608,7 +608,7 @@ class PhysicalLightingModel extends LightingModel {
608
608
  * @param {Object} input - The input data.
609
609
  * @param {NodeBuilder} builder - The current node builder.
610
610
  */
611
- directRectArea( { lightColor, lightPosition, halfWidth, halfHeight, reflectedLight, ltc_1, ltc_2 } ) {
611
+ directRectArea( { lightColor, lightPosition, halfWidth, halfHeight, reflectedLight, ltc_1, ltc_2 }, /* builder */ ) {
612
612
 
613
613
  const p0 = lightPosition.add( halfWidth ).sub( halfHeight ); // counterclockwise; light shines in local neg z direction
614
614
  const p1 = lightPosition.sub( halfWidth ).sub( halfHeight );
@@ -113,7 +113,7 @@ class AtomicFunctionNode extends Node {
113
113
  }
114
114
 
115
115
  const methodSnippet = `${ builder.getMethod( method, type ) }( ${ params.join( ', ' ) } )`;
116
- const isVoid = parents.length === 1 && parents[ 0 ].isStackNode === true;
116
+ const isVoid = parents ? ( parents.length === 1 && parents[ 0 ].isStackNode === true ) : false;
117
117
 
118
118
  if ( isVoid ) {
119
119
 
@@ -19,10 +19,9 @@ class ComputeNode extends Node {
19
19
  * Constructs a new compute node.
20
20
  *
21
21
  * @param {Node} computeNode - TODO
22
- * @param {number} count - TODO.
23
- * @param {Array<number>} [workgroupSize=[64]] - TODO.
22
+ * @param {Array<number>} workgroupSize - TODO.
24
23
  */
25
- constructor( computeNode, count, workgroupSize = [ 64 ] ) {
24
+ constructor( computeNode, workgroupSize ) {
26
25
 
27
26
  super( 'void' );
28
27
 
@@ -42,18 +41,12 @@ class ComputeNode extends Node {
42
41
  */
43
42
  this.computeNode = computeNode;
44
43
 
45
- /**
46
- * TODO
47
- *
48
- * @type {number}
49
- */
50
- this.count = count;
51
44
 
52
45
  /**
53
46
  * TODO
54
47
  *
55
48
  * @type {Array<number>}
56
- * @default [64]
49
+ * @default [ 64 ]
57
50
  */
58
51
  this.workgroupSize = workgroupSize;
59
52
 
@@ -62,7 +55,7 @@ class ComputeNode extends Node {
62
55
  *
63
56
  * @type {number}
64
57
  */
65
- this.dispatchCount = 0;
58
+ this.count = null;
66
59
 
67
60
  /**
68
61
  * TODO
@@ -95,7 +88,19 @@ class ComputeNode extends Node {
95
88
  */
96
89
  this.onInitFunction = null;
97
90
 
98
- this.updateDispatchCount();
91
+ }
92
+
93
+ setCount( count ) {
94
+
95
+ this.count = count;
96
+
97
+ return this;
98
+
99
+ }
100
+
101
+ getCount() {
102
+
103
+ return this.count;
99
104
 
100
105
  }
101
106
 
@@ -114,7 +119,7 @@ class ComputeNode extends Node {
114
119
  * @param {string} name - The name of the uniform.
115
120
  * @return {ComputeNode} A reference to this node.
116
121
  */
117
- label( name ) {
122
+ setName( name ) {
118
123
 
119
124
  this.name = name;
120
125
 
@@ -123,18 +128,17 @@ class ComputeNode extends Node {
123
128
  }
124
129
 
125
130
  /**
126
- * TODO
131
+ * Sets the {@link ComputeNode#name} property.
132
+ *
133
+ * @deprecated
134
+ * @param {string} name - The name of the uniform.
135
+ * @return {ComputeNode} A reference to this node.
127
136
  */
128
- updateDispatchCount() {
129
-
130
- const { count, workgroupSize } = this;
131
-
132
- let size = workgroupSize[ 0 ];
137
+ label( name ) {
133
138
 
134
- for ( let i = 1; i < workgroupSize.length; i ++ )
135
- size *= workgroupSize[ i ];
139
+ console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
136
140
 
137
- this.dispatchCount = Math.ceil( count / size );
141
+ return this.setName( name );
138
142
 
139
143
  }
140
144
 
@@ -213,6 +217,45 @@ class ComputeNode extends Node {
213
217
 
214
218
  export default ComputeNode;
215
219
 
220
+ /**
221
+ * TSL function for creating a compute kernel node.
222
+ *
223
+ * @tsl
224
+ * @function
225
+ * @param {Node} node - TODO
226
+ * @param {Array<number>} [workgroupSize=[64]] - TODO.
227
+ * @returns {AtomicFunctionNode}
228
+ */
229
+ export const computeKernel = ( node, workgroupSize = [ 64 ] ) => {
230
+
231
+ if ( workgroupSize.length === 0 || workgroupSize.length > 3 ) {
232
+
233
+ console.error( 'THREE.TSL: compute() workgroupSize must have 1, 2, or 3 elements' );
234
+
235
+ }
236
+
237
+ for ( let i = 0; i < workgroupSize.length; i ++ ) {
238
+
239
+ const val = workgroupSize[ i ];
240
+
241
+ if ( typeof val !== 'number' || val <= 0 || ! Number.isInteger( val ) ) {
242
+
243
+ console.error( `THREE.TSL: compute() workgroupSize element at index [ ${ i } ] must be a positive integer` );
244
+
245
+ }
246
+
247
+ }
248
+
249
+ // Implicit fill-up to [ x, y, z ] with 1s, just like WGSL treats @workgroup_size when fewer dimensions are specified
250
+
251
+ while ( workgroupSize.length < 3 ) workgroupSize.push( 1 );
252
+
253
+ //
254
+
255
+ return nodeObject( new ComputeNode( nodeObject( node ), workgroupSize ) );
256
+
257
+ };
258
+
216
259
  /**
217
260
  * TSL function for creating a compute node.
218
261
  *
@@ -223,6 +266,7 @@ export default ComputeNode;
223
266
  * @param {Array<number>} [workgroupSize=[64]] - TODO.
224
267
  * @returns {AtomicFunctionNode}
225
268
  */
226
- export const compute = ( node, count, workgroupSize ) => nodeObject( new ComputeNode( nodeObject( node ), count, workgroupSize ) );
269
+ export const compute = ( node, count, workgroupSize ) => computeKernel( node, workgroupSize ).setCount( count );
227
270
 
228
271
  addMethodChaining( 'compute', compute );
272
+ addMethodChaining( 'computeKernel', computeKernel );
@@ -0,0 +1,430 @@
1
+ import TempNode from '../core/TempNode.js';
2
+ import { nodeProxyIntent } from '../tsl/TSLCore.js';
3
+
4
+
5
+ /**
6
+ * This class represents a set of built in WGSL shader functions that sync
7
+ * synchronously execute an operation across a subgroup, or 'warp', of compute
8
+ * or fragment shader invocations within a workgroup. Typically, these functions
9
+ * will synchronously execute an operation using data from all active invocations
10
+ * within the subgroup, then broadcast that result to all active invocations. In
11
+ * other graphics APIs, subgroup functions are also referred to as wave intrinsics
12
+ * (DirectX/HLSL) or warp intrinsics (CUDA).
13
+ *
14
+ * @augments TempNode
15
+ */
16
+ class SubgroupFunctionNode extends TempNode {
17
+
18
+ static get type() {
19
+
20
+ return 'SubgroupFunctionNode';
21
+
22
+ }
23
+
24
+ /**
25
+ * Constructs a new function node.
26
+ *
27
+ * @param {string} method - The subgroup/wave intrinsic method to construct.
28
+ * @param {Node} [aNode=null] - The method's first argument.
29
+ * @param {Node} [bNode=null] - The method's second argument.
30
+ */
31
+ constructor( method, aNode = null, bNode = null ) {
32
+
33
+ super();
34
+
35
+ /**
36
+ * The subgroup/wave intrinsic method to construct.
37
+ *
38
+ * @type {String}
39
+ */
40
+ this.method = method;
41
+
42
+ /**
43
+ * The method's first argument.
44
+ *
45
+ * @type {Node}
46
+ */
47
+ this.aNode = aNode;
48
+
49
+ /**
50
+ * The method's second argument.
51
+ *
52
+ * @type {Node}
53
+ */
54
+ this.bNode = bNode;
55
+
56
+ }
57
+
58
+ getInputType( builder ) {
59
+
60
+ const aType = this.aNode ? this.aNode.getNodeType( builder ) : null;
61
+ const bType = this.bNode ? this.bNode.getNodeType( builder ) : null;
62
+
63
+ const aLen = builder.isMatrix( aType ) ? 0 : builder.getTypeLength( aType );
64
+ const bLen = builder.isMatrix( bType ) ? 0 : builder.getTypeLength( bType );
65
+
66
+ if ( aLen > bLen ) {
67
+
68
+ return aType;
69
+
70
+ } else {
71
+
72
+ return bType;
73
+
74
+ }
75
+
76
+ }
77
+
78
+ getNodeType( builder ) {
79
+
80
+ const method = this.method;
81
+
82
+ if ( method === SubgroupFunctionNode.SUBGROUP_ELECT ) {
83
+
84
+ return 'bool';
85
+
86
+ } else if ( method === SubgroupFunctionNode.SUBGROUP_BALLOT ) {
87
+
88
+ return 'uvec4';
89
+
90
+ } else {
91
+
92
+ return this.getInputType( builder );
93
+
94
+ }
95
+
96
+ }
97
+
98
+ generate( builder, output ) {
99
+
100
+ const method = this.method;
101
+
102
+ const type = this.getNodeType( builder );
103
+ const inputType = this.getInputType( builder );
104
+
105
+ const a = this.aNode;
106
+ const b = this.bNode;
107
+
108
+ const params = [];
109
+
110
+ if (
111
+ method === SubgroupFunctionNode.SUBGROUP_BROADCAST ||
112
+ method === SubgroupFunctionNode.SUBGROUP_SHUFFLE ||
113
+ method === SubgroupFunctionNode.QUAD_BROADCAST
114
+ ) {
115
+
116
+ const bType = b.getNodeType( builder );
117
+
118
+ params.push(
119
+ a.build( builder, type ),
120
+ b.build( builder, bType === 'float' ? 'int' : type )
121
+ );
122
+
123
+ } else if (
124
+ method === SubgroupFunctionNode.SUBGROUP_SHUFFLE_XOR ||
125
+ method === SubgroupFunctionNode.SUBGROUP_SHUFFLE_DOWN ||
126
+ method === SubgroupFunctionNode.SUBGROUP_SHUFFLE_UP
127
+ ) {
128
+
129
+ params.push(
130
+ a.build( builder, type ),
131
+ b.build( builder, 'uint' )
132
+ );
133
+
134
+ } else {
135
+
136
+ if ( a !== null ) params.push( a.build( builder, inputType ) );
137
+ if ( b !== null ) params.push( b.build( builder, inputType ) );
138
+
139
+ }
140
+
141
+ const paramsString = params.length === 0 ? '()' : `( ${params.join( ', ' )} )`;
142
+
143
+ return builder.format( `${ builder.getMethod( method, type ) }${paramsString}`, type, output );
144
+
145
+
146
+
147
+ }
148
+
149
+ serialize( data ) {
150
+
151
+ super.serialize( data );
152
+
153
+ data.method = this.method;
154
+
155
+ }
156
+
157
+ deserialize( data ) {
158
+
159
+ super.deserialize( data );
160
+
161
+ this.method = data.method;
162
+
163
+ }
164
+
165
+ }
166
+
167
+ // 0 inputs
168
+ SubgroupFunctionNode.SUBGROUP_ELECT = 'subgroupElect';
169
+
170
+ // 1 input
171
+ SubgroupFunctionNode.SUBGROUP_BALLOT = 'subgroupBallot';
172
+ SubgroupFunctionNode.SUBGROUP_ADD = 'subgroupAdd';
173
+ SubgroupFunctionNode.SUBGROUP_INCLUSIVE_ADD = 'subgroupInclusiveAdd';
174
+ SubgroupFunctionNode.SUBGROUP_EXCLUSIVE_AND = 'subgroupExclusiveAdd';
175
+ SubgroupFunctionNode.SUBGROUP_MUL = 'subgroupMul';
176
+ SubgroupFunctionNode.SUBGROUP_INCLUSIVE_MUL = 'subgroupInclusiveMul';
177
+ SubgroupFunctionNode.SUBGROUP_EXCLUSIVE_MUL = 'subgroupExclusiveMul';
178
+ SubgroupFunctionNode.SUBGROUP_AND = 'subgroupAnd';
179
+ SubgroupFunctionNode.SUBGROUP_OR = 'subgroupOr';
180
+ SubgroupFunctionNode.SUBGROUP_XOR = 'subgroupXor';
181
+ SubgroupFunctionNode.SUBGROUP_MIN = 'subgroupMin';
182
+ SubgroupFunctionNode.SUBGROUP_MAX = 'subgroupMax';
183
+ SubgroupFunctionNode.SUBGROUP_ALL = 'subgroupAll';
184
+ SubgroupFunctionNode.SUBGROUP_ANY = 'subgroupAny';
185
+ SubgroupFunctionNode.SUBGROUP_BROADCAST_FIRST = 'subgroupBroadcastFirst';
186
+ SubgroupFunctionNode.QUAD_SWAP_X = 'quadSwapX';
187
+ SubgroupFunctionNode.QUAD_SWAP_Y = 'quadSwapY';
188
+ SubgroupFunctionNode.QUAD_SWAP_DIAGONAL = 'quadSwapDiagonal';
189
+
190
+ // 2 inputs
191
+ SubgroupFunctionNode.SUBGROUP_BROADCAST = 'subgroupBroadcast';
192
+ SubgroupFunctionNode.SUBGROUP_SHUFFLE = 'subgroupShuffle';
193
+ SubgroupFunctionNode.SUBGROUP_SHUFFLE_XOR = 'subgroupShuffleXor';
194
+ SubgroupFunctionNode.SUBGROUP_SHUFFLE_UP = 'subgroupShuffleUp';
195
+ SubgroupFunctionNode.SUBGROUP_SHUFFLE_DOWN = 'subgroupShuffleDown';
196
+ SubgroupFunctionNode.QUAD_BROADCAST = 'quadBroadcast';
197
+
198
+ export default SubgroupFunctionNode;
199
+
200
+
201
+
202
+ /**
203
+ * Returns true if this invocation has the lowest subgroup_invocation_id
204
+ * among active invocations in the subgroup.
205
+ *
206
+ * @method
207
+ * @return {bool} The result of the computation.
208
+ */
209
+ export const subgroupElect = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_ELECT ).setParameterLength( 0 );
210
+
211
+ /**
212
+ * Returns a set of bitfields where the bit corresponding to subgroup_invocation_id
213
+ * is 1 if pred is true for that active invocation and 0 otherwise.
214
+ *
215
+ * @method
216
+ * @param {bool} pred - A boolean that sets the bit corresponding to the invocations subgroup invocation id.
217
+ * @return {vec4<u32>}- A bitfield corresponding to the pred value of each subgroup invocation.
218
+ */
219
+ export const subgroupBallot = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_BALLOT ).setParameterLength( 1 );
220
+
221
+ /**
222
+ * A reduction that adds e among all active invocations and returns that result.
223
+ *
224
+ * @method
225
+ * @param {number} e - The value provided to the reduction by the current invocation.
226
+ * @return {number} The accumulated result of the reduction operation.
227
+ */
228
+ export const subgroupAdd = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_ADD ).setParameterLength( 1 );
229
+
230
+ /**
231
+ * An inclusive scan returning the sum of e for all active invocations with subgroup_invocation_id less than or equal to this invocation.
232
+ *
233
+ * @method
234
+ * @param {number} e - The value provided to the inclusive scan by the current invocation.
235
+ * @return {number} The accumulated result of the inclusive scan operation.
236
+ */
237
+ export const subgroupInclusiveAdd = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_INCLUSIVE_ADD ).setParameterLength( 1 );
238
+
239
+ /**
240
+ * An exclusive scan that returns the sum of e for all active invocations with subgroup_invocation_id less than this invocation.
241
+ *
242
+ * @method
243
+ * @param {number} e - The value provided to the exclusive scan by the current invocation.
244
+ * @return {number} The accumulated result of the exclusive scan operation.
245
+ */
246
+ export const subgroupExclusiveAdd = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_EXCLUSIVE_AND ).setParameterLength( 1 );
247
+
248
+ /**
249
+ * A reduction that multiplies e among all active invocations and returns that result.
250
+ *
251
+ * @method
252
+ * @param {number} e - The value provided to the reduction by the current invocation.
253
+ * @return {number} The accumulated result of the reduction operation.
254
+ */
255
+ export const subgroupMul = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_MUL ).setParameterLength( 1 );
256
+
257
+ /**
258
+ * An inclusive scan returning the product of e for all active invocations with subgroup_invocation_id less than or equal to this invocation.
259
+ *
260
+ * @method
261
+ * @param {number} e - The value provided to the inclusive scan by the current invocation.
262
+ * @return {number} The accumulated result of the inclusive scan operation.
263
+ */
264
+ export const subgroupInclusiveMul = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_INCLUSIVE_MUL ).setParameterLength( 1 );
265
+
266
+ /**
267
+ * An exclusive scan that returns the product of e for all active invocations with subgroup_invocation_id less than this invocation.
268
+ *
269
+ * @method
270
+ * @param {number} e - The value provided to the exclusive scan by the current invocation.
271
+ * @return {number} The accumulated result of the exclusive scan operation.
272
+ */
273
+ export const subgroupExclusiveMul = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_EXCLUSIVE_MUL ).setParameterLength( 1 );
274
+
275
+ /**
276
+ * A reduction that performs a bitwise and of e among all active invocations and returns that result.
277
+ *
278
+ * @method
279
+ * @param {number} e - The value provided to the reduction by the current invocation.
280
+ * @return {number} The result of the reduction operation.
281
+ */
282
+ export const subgroupAnd = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_AND ).setParameterLength( 1 );
283
+
284
+ /**
285
+ * A reduction that performs a bitwise or of e among all active invocations and returns that result.
286
+ *
287
+ * @method
288
+ * @param {number} e - The value provided to the reduction by the current invocation.
289
+ * @return {number} The result of the reduction operation.
290
+ */
291
+ export const subgroupOr = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_OR ).setParameterLength( 1 );
292
+
293
+ /**
294
+ * A reduction that performs a bitwise xor of e among all active invocations and returns that result.
295
+ *
296
+ * @method
297
+ * @param {number} e - The value provided to the reduction by the current invocation.
298
+ * @return {number} The result of the reduction operation.
299
+ */
300
+ export const subgroupXor = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_XOR ).setParameterLength( 1 );
301
+
302
+ /**
303
+ * A reduction that performs a min of e among all active invocations and returns that result.
304
+ *
305
+ * @method
306
+ * @param {number} e - The value provided to the reduction by the current invocation.
307
+ * @return {number} The result of the reduction operation.
308
+ */
309
+ export const subgroupMin = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_MIN ).setParameterLength( 1 );
310
+
311
+ /**
312
+ * A reduction that performs a max of e among all active invocations and returns that result.
313
+ *
314
+ * @method
315
+ * @param {number} e - The value provided to the reduction by the current invocation.
316
+ * @return {number} The result of the reduction operation.
317
+ */
318
+ export const subgroupMax = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_MAX ).setParameterLength( 1 );
319
+
320
+ /**
321
+ * Returns true if e is true for all active invocations in the subgroup.
322
+ *
323
+ * @method
324
+ * @return {bool} The result of the computation.
325
+ */
326
+ export const subgroupAll = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_ALL ).setParameterLength( 0 );
327
+
328
+ /**
329
+ * Returns true if e is true for any active invocation in the subgroup
330
+ *
331
+ * @method
332
+ * @return {bool} The result of the computation.
333
+ */
334
+ export const subgroupAny = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_ANY ).setParameterLength( 0 );
335
+
336
+ /**
337
+ * Broadcasts e from the active invocation with the lowest subgroup_invocation_id in the subgroup to all other active invocations.
338
+ *
339
+ * @method
340
+ * @param {number} e - The value to broadcast from the lowest subgroup invocation.
341
+ * @param {number} id - The subgroup invocation to broadcast from.
342
+ * @return {number} The broadcast value.
343
+ */
344
+ export const subgroupBroadcastFirst = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_BROADCAST_FIRST ).setParameterLength( 2 );
345
+
346
+ /**
347
+ * Swaps e between invocations in the quad in the X direction.
348
+ *
349
+ * @method
350
+ * @param {number} e - The value to swap from the current invocation.
351
+ * @return {number} The value received from the swap operation.
352
+ */
353
+ export const quadSwapX = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.QUAD_SWAP_X ).setParameterLength( 1 );
354
+
355
+ /**
356
+ * Swaps e between invocations in the quad in the Y direction.
357
+ *
358
+ * @method
359
+ * @param {number} e - The value to swap from the current invocation.
360
+ * @return {number} The value received from the swap operation.
361
+ */
362
+ export const quadSwapY = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.QUAD_SWAP_Y ).setParameterLength( 1 );
363
+
364
+ /**
365
+ * Swaps e between invocations in the quad diagonally.
366
+ *
367
+ * @method
368
+ * @param {number} e - The value to swap from the current invocation.
369
+ * @return {number} The value received from the swap operation.
370
+ */
371
+ export const quadSwapDiagonal = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.QUAD_SWAP_DIAGONAL ).setParameterLength( 1 );
372
+
373
+ /**
374
+ * Broadcasts e from the invocation whose subgroup_invocation_id matches id, to all active invocations.
375
+ *
376
+ * @method
377
+ * @param {number} e - The value to broadcast from subgroup invocation 'id'.
378
+ * @param {number} id - The subgroup invocation to broadcast from.
379
+ * @return {number} The broadcast value.
380
+ */
381
+ export const subgroupBroadcast = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_BROADCAST ).setParameterLength( 2 );
382
+
383
+ /**
384
+ * Returns v from the active invocation whose subgroup_invocation_id matches id
385
+ *
386
+ * @method
387
+ * @param {number} v - The value to return from subgroup invocation id^mask.
388
+ * @param {number} id - The subgroup invocation which returns the value v.
389
+ * @return {number} The broadcast value.
390
+ */
391
+ export const subgroupShuffle = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_SHUFFLE ).setParameterLength( 2 );
392
+
393
+ /**
394
+ * Returns v from the active invocation whose subgroup_invocation_id matches subgroup_invocation_id ^ mask.
395
+ *
396
+ * @method
397
+ * @param {number} v - The value to return from subgroup invocation id^mask.
398
+ * @param {number} mask - A bitmask that determines the target invocation via a XOR operation.
399
+ * @return {number} The broadcast value.
400
+ */
401
+ export const subgroupShuffleXor = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_SHUFFLE_XOR ).setParameterLength( 2 );
402
+
403
+ /**
404
+ * Returns v from the active invocation whose subgroup_invocation_id matches subgroup_invocation_id - delta
405
+ *
406
+ * @method
407
+ * @param {number} v - The value to return from subgroup invocation id^mask.
408
+ * @param {number} delta - A value that offsets the current in.
409
+ * @return {number} The broadcast value.
410
+ */
411
+ export const subgroupShuffleUp = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_SHUFFLE_UP ).setParameterLength( 2 );
412
+
413
+ /**
414
+ * Returns v from the active invocation whose subgroup_invocation_id matches subgroup_invocation_id + delta
415
+ *
416
+ * @method
417
+ * @param {number} v - The value to return from subgroup invocation id^mask.
418
+ * @param {number} delta - A value that offsets the current subgroup invocation.
419
+ * @return {number} The broadcast value.
420
+ */
421
+ export const subgroupShuffleDown = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.SUBGROUP_SHUFFLE_DOWN ).setParameterLength( 2 );
422
+
423
+ /**
424
+ * Broadcasts e from the quad invocation with id equal to id.
425
+ *
426
+ * @method
427
+ * @param {number} e - The value to broadcast.
428
+ * @return {number} The broadcast value.
429
+ */
430
+ export const quadBroadcast = /*@__PURE__*/ nodeProxyIntent( SubgroupFunctionNode, SubgroupFunctionNode.QUAD_BROADCAST ).setParameterLength( 1 );
@@ -116,15 +116,23 @@ class WorkgroupInfoNode extends Node {
116
116
  */
117
117
  this.scope = scope;
118
118
 
119
+ /**
120
+ * The name of the workgroup scoped buffer.
121
+ *
122
+ * @type {string}
123
+ * @default ''
124
+ */
125
+ this.name = '';
126
+
119
127
  }
120
128
 
121
129
  /**
122
- * Sets the name/label of this node.
130
+ * Sets the name of this node.
123
131
  *
124
132
  * @param {string} name - The name to set.
125
133
  * @return {WorkgroupInfoNode} A reference to this node.
126
134
  */
127
- label( name ) {
135
+ setName( name ) {
128
136
 
129
137
  this.name = name;
130
138
 
@@ -132,6 +140,21 @@ class WorkgroupInfoNode extends Node {
132
140
 
133
141
  }
134
142
 
143
+ /**
144
+ * Sets the name/label of this node.
145
+ *
146
+ * @deprecated
147
+ * @param {string} name - The name to set.
148
+ * @return {WorkgroupInfoNode} A reference to this node.
149
+ */
150
+ label( name ) {
151
+
152
+ console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
153
+
154
+ return this.setName( name );
155
+
156
+ }
157
+
135
158
  /**
136
159
  * Sets the scope of this node.
137
160
  *
@@ -185,7 +208,9 @@ class WorkgroupInfoNode extends Node {
185
208
 
186
209
  generate( builder ) {
187
210
 
188
- return builder.getScopedArray( this.name || `${this.scope}Array_${this.id}`, this.scope.toLowerCase(), this.bufferType, this.bufferCount );
211
+ const name = ( this.name !== '' ) ? this.name : `${this.scope}Array_${this.id}`;
212
+
213
+ return builder.getScopedArray( name, this.scope.toLowerCase(), this.bufferType, this.bufferCount );
189
214
 
190
215
  }
191
216
 
@@ -159,7 +159,7 @@ class LightsNode extends Node {
159
159
 
160
160
  for ( const lightNode of this._lightNodes ) {
161
161
 
162
- hash.push( lightNode.getSelf().getHash() );
162
+ hash.push( lightNode.getHash() );
163
163
 
164
164
  }
165
165