@plastic-software/three 0.181.3 → 0.182.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 (253) hide show
  1. package/README.md +3 -4
  2. package/build/three.cjs +1192 -522
  3. package/build/three.core.js +345 -219
  4. package/build/three.core.min.js +1 -1
  5. package/build/three.module.js +864 -328
  6. package/build/three.module.min.js +1 -1
  7. package/build/three.tsl.js +15 -3
  8. package/build/three.tsl.min.js +1 -1
  9. package/build/three.webgpu.js +3660 -1545
  10. package/build/three.webgpu.min.js +1 -1
  11. package/build/three.webgpu.nodes.js +3659 -1544
  12. package/build/three.webgpu.nodes.min.js +1 -1
  13. package/examples/jsm/controls/MapControls.js +55 -1
  14. package/examples/jsm/controls/OrbitControls.js +6 -6
  15. package/examples/jsm/controls/TrackballControls.js +6 -6
  16. package/examples/jsm/csm/CSM.js +2 -1
  17. package/examples/jsm/environments/RoomEnvironment.js +2 -0
  18. package/examples/jsm/geometries/DecalGeometry.js +1 -1
  19. package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
  20. package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
  21. package/examples/jsm/inspector/Inspector.js +53 -9
  22. package/examples/jsm/inspector/RendererInspector.js +12 -2
  23. package/examples/jsm/inspector/tabs/Console.js +2 -2
  24. package/examples/jsm/inspector/tabs/Parameters.js +2 -2
  25. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  26. package/examples/jsm/inspector/tabs/Viewer.js +4 -4
  27. package/examples/jsm/inspector/ui/Profiler.js +1836 -31
  28. package/examples/jsm/inspector/ui/Style.js +948 -13
  29. package/examples/jsm/inspector/ui/Tab.js +188 -1
  30. package/examples/jsm/inspector/ui/Values.js +17 -1
  31. package/examples/jsm/loaders/3DMLoader.js +5 -4
  32. package/examples/jsm/loaders/DRACOLoader.js +5 -5
  33. package/examples/jsm/loaders/FBXLoader.js +0 -2
  34. package/examples/jsm/loaders/HDRLoader.js +0 -1
  35. package/examples/jsm/loaders/KTX2Loader.js +16 -0
  36. package/examples/jsm/loaders/LDrawLoader.js +2 -3
  37. package/examples/jsm/loaders/PCDLoader.js +1 -0
  38. package/examples/jsm/loaders/SVGLoader.js +1 -1
  39. package/examples/jsm/loaders/TDSLoader.js +0 -2
  40. package/examples/jsm/loaders/TGALoader.js +0 -2
  41. package/examples/jsm/loaders/UltraHDRLoader.js +110 -137
  42. package/examples/jsm/loaders/VOXLoader.js +660 -117
  43. package/examples/jsm/loaders/VRMLLoader.js +2 -2
  44. package/examples/jsm/loaders/usd/USDCParser.js +1 -1
  45. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  46. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -1
  47. package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
  48. package/examples/jsm/math/Octree.js +131 -1
  49. package/examples/jsm/misc/Volume.js +0 -1
  50. package/examples/jsm/misc/VolumeSlice.js +0 -1
  51. package/examples/jsm/objects/SkyMesh.js +13 -3
  52. package/examples/jsm/physics/AmmoPhysics.js +12 -7
  53. package/examples/jsm/physics/JoltPhysics.js +3 -1
  54. package/examples/jsm/physics/RapierPhysics.js +3 -1
  55. package/examples/jsm/postprocessing/OutputPass.js +9 -0
  56. package/examples/jsm/postprocessing/RenderPass.js +10 -0
  57. package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
  58. package/examples/jsm/renderers/Projector.js +268 -30
  59. package/examples/jsm/renderers/SVGRenderer.js +191 -58
  60. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
  61. package/examples/jsm/transpiler/AST.js +44 -0
  62. package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
  63. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
  64. package/examples/jsm/transpiler/TSLEncoder.js +46 -3
  65. package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
  66. package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
  67. package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -0
  68. package/examples/jsm/tsl/display/BloomNode.js +11 -1
  69. package/examples/jsm/tsl/display/GTAONode.js +3 -2
  70. package/examples/jsm/tsl/display/PixelationPassNode.js +2 -1
  71. package/examples/jsm/tsl/display/SSGINode.js +7 -19
  72. package/examples/jsm/tsl/display/SSRNode.js +1 -1
  73. package/examples/jsm/tsl/display/SSSNode.js +4 -2
  74. package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
  75. package/examples/jsm/tsl/display/TRAANode.js +265 -114
  76. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  77. package/examples/jsm/utils/ShadowMapViewer.js +24 -10
  78. package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
  79. package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
  80. package/package.json +14 -12
  81. package/src/Three.Core.js +1 -0
  82. package/src/Three.TSL.js +14 -2
  83. package/src/animation/AnimationUtils.js +1 -12
  84. package/src/animation/KeyframeTrack.js +1 -1
  85. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  86. package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
  87. package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
  88. package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
  89. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  90. package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
  91. package/src/constants.js +61 -5
  92. package/src/core/BufferGeometry.js +14 -2
  93. package/src/core/Raycaster.js +2 -2
  94. package/src/extras/PMREMGenerator.js +3 -10
  95. package/src/extras/TextureUtils.js +5 -1
  96. package/src/geometries/ExtrudeGeometry.js +2 -2
  97. package/src/geometries/PolyhedronGeometry.js +1 -1
  98. package/src/helpers/PointLightHelper.js +1 -1
  99. package/src/lights/DirectionalLight.js +13 -0
  100. package/src/lights/HemisphereLight.js +10 -0
  101. package/src/lights/Light.js +1 -11
  102. package/src/lights/LightProbe.js +0 -15
  103. package/src/lights/LightShadow.js +0 -3
  104. package/src/lights/PointLight.js +15 -0
  105. package/src/lights/PointLightShadow.js +0 -86
  106. package/src/lights/SpotLight.js +22 -1
  107. package/src/loaders/MaterialLoader.js +2 -1
  108. package/src/loaders/ObjectLoader.js +3 -1
  109. package/src/loaders/nodes/NodeLoader.js +2 -2
  110. package/src/materials/Material.js +2 -0
  111. package/src/materials/ShaderMaterial.js +20 -1
  112. package/src/materials/nodes/Line2NodeMaterial.js +2 -2
  113. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -2
  114. package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
  115. package/src/materials/nodes/NodeMaterial.js +59 -3
  116. package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
  117. package/src/math/Matrix4.js +40 -40
  118. package/src/math/Sphere.js +1 -1
  119. package/src/math/Vector3.js +0 -2
  120. package/src/nodes/TSL.js +4 -1
  121. package/src/nodes/accessors/BatchNode.js +10 -10
  122. package/src/nodes/accessors/BufferAttributeNode.js +98 -12
  123. package/src/nodes/accessors/BufferNode.js +29 -2
  124. package/src/nodes/accessors/ClippingNode.js +4 -4
  125. package/src/nodes/accessors/CubeTextureNode.js +20 -1
  126. package/src/nodes/accessors/InstanceNode.js +69 -29
  127. package/src/nodes/accessors/MaterialNode.js +9 -1
  128. package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
  129. package/src/nodes/accessors/ModelNode.js +1 -1
  130. package/src/nodes/accessors/Normal.js +2 -2
  131. package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
  132. package/src/nodes/accessors/ReferenceNode.js +4 -4
  133. package/src/nodes/accessors/RendererReferenceNode.js +1 -2
  134. package/src/nodes/accessors/SkinningNode.js +15 -2
  135. package/src/nodes/accessors/StorageBufferNode.js +4 -2
  136. package/src/nodes/accessors/Tangent.js +1 -11
  137. package/src/nodes/accessors/Texture3DNode.js +26 -1
  138. package/src/nodes/accessors/UniformArrayNode.js +2 -2
  139. package/src/nodes/accessors/UserDataNode.js +1 -2
  140. package/src/nodes/accessors/VertexColorNode.js +1 -2
  141. package/src/nodes/code/FunctionNode.js +1 -2
  142. package/src/nodes/core/ArrayNode.js +20 -1
  143. package/src/nodes/core/AssignNode.js +2 -2
  144. package/src/nodes/core/AttributeNode.js +2 -2
  145. package/src/nodes/core/ContextNode.js +103 -4
  146. package/src/nodes/core/NodeBuilder.js +56 -14
  147. package/src/nodes/core/NodeFrame.js +12 -4
  148. package/src/nodes/core/NodeUtils.js +5 -5
  149. package/src/nodes/core/ParameterNode.js +1 -2
  150. package/src/nodes/core/PropertyNode.js +19 -3
  151. package/src/nodes/core/StackNode.js +56 -8
  152. package/src/nodes/core/StructNode.js +1 -2
  153. package/src/nodes/core/StructTypeNode.js +11 -17
  154. package/src/nodes/core/UniformNode.js +19 -4
  155. package/src/nodes/core/VarNode.js +46 -21
  156. package/src/nodes/display/NormalMapNode.js +37 -2
  157. package/src/nodes/display/PassNode.js +77 -7
  158. package/src/nodes/display/ScreenNode.js +1 -0
  159. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
  160. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  161. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  162. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
  163. package/src/nodes/functions/PhysicalLightingModel.js +102 -43
  164. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
  165. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  166. package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -3
  167. package/src/nodes/lighting/AnalyticLightNode.js +53 -0
  168. package/src/nodes/lighting/LightsNode.js +2 -2
  169. package/src/nodes/lighting/PointShadowNode.js +141 -140
  170. package/src/nodes/lighting/ShadowFilterNode.js +53 -37
  171. package/src/nodes/lighting/ShadowNode.js +53 -19
  172. package/src/nodes/math/BitcountNode.js +433 -0
  173. package/src/nodes/math/PackFloatNode.js +98 -0
  174. package/src/nodes/math/UnpackFloatNode.js +96 -0
  175. package/src/nodes/pmrem/PMREMNode.js +1 -1
  176. package/src/nodes/tsl/TSLCore.js +4 -4
  177. package/src/nodes/utils/ArrayElementNode.js +13 -0
  178. package/src/nodes/utils/EventNode.js +1 -2
  179. package/src/nodes/utils/Packing.js +13 -1
  180. package/src/nodes/utils/PostProcessingUtils.js +33 -1
  181. package/src/nodes/utils/ReflectorNode.js +1 -1
  182. package/src/nodes/utils/SampleNode.js +1 -1
  183. package/src/nodes/utils/UVUtils.js +26 -0
  184. package/src/objects/BatchedMesh.js +5 -2
  185. package/src/objects/Line.js +1 -1
  186. package/src/objects/Mesh.js +1 -1
  187. package/src/objects/Points.js +1 -1
  188. package/src/objects/Skeleton.js +9 -0
  189. package/src/renderers/WebGLRenderer.js +145 -33
  190. package/src/renderers/common/Backend.js +8 -0
  191. package/src/renderers/common/Background.js +19 -9
  192. package/src/renderers/common/Binding.js +11 -0
  193. package/src/renderers/common/Bindings.js +7 -7
  194. package/src/renderers/common/Buffer.js +40 -0
  195. package/src/renderers/common/ChainMap.js +30 -6
  196. package/src/renderers/common/Geometries.js +12 -0
  197. package/src/renderers/common/RenderContexts.js +8 -1
  198. package/src/renderers/common/RenderObject.js +14 -1
  199. package/src/renderers/common/Renderer.js +53 -35
  200. package/src/renderers/common/Textures.js +1 -1
  201. package/src/renderers/common/UniformsGroup.js +1 -0
  202. package/src/renderers/common/XRManager.js +1 -0
  203. package/src/renderers/common/extras/PMREMGenerator.js +2 -8
  204. package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
  205. package/src/renderers/shaders/DFGLUTData.js +19 -34
  206. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
  207. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  208. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +90 -51
  209. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +194 -186
  210. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  211. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  212. package/src/renderers/shaders/ShaderChunk.js +3 -3
  213. package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
  214. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  215. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -1
  216. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  217. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
  218. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  219. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  220. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +0 -1
  221. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  222. package/src/renderers/shaders/ShaderLib.js +3 -3
  223. package/src/renderers/webgl/WebGLCapabilities.js +3 -4
  224. package/src/renderers/webgl/WebGLLights.js +18 -1
  225. package/src/renderers/webgl/WebGLOutput.js +267 -0
  226. package/src/renderers/webgl/WebGLProgram.js +43 -107
  227. package/src/renderers/webgl/WebGLPrograms.js +35 -45
  228. package/src/renderers/webgl/WebGLShadowMap.js +188 -25
  229. package/src/renderers/webgl/WebGLState.js +20 -20
  230. package/src/renderers/webgl/WebGLTextures.js +89 -28
  231. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  232. package/src/renderers/webgl/WebGLUtils.js +6 -2
  233. package/src/renderers/webgl-fallback/WebGLBackend.js +79 -13
  234. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +59 -7
  235. package/src/renderers/webgl-fallback/utils/WebGLState.js +18 -3
  236. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
  237. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
  238. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
  239. package/src/renderers/webgpu/WebGPUBackend.js +61 -4
  240. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  241. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +65 -23
  242. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
  243. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +354 -186
  244. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
  245. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +20 -7
  246. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +40 -17
  247. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
  248. package/src/renderers/webgpu/utils/WebGPUUtils.js +7 -5
  249. package/src/textures/CubeDepthTexture.js +76 -0
  250. package/src/textures/Source.js +1 -1
  251. package/src/textures/Texture.js +1 -1
  252. package/src/utils.js +13 -1
  253. package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
@@ -0,0 +1,433 @@
1
+ import { float, Fn, If, nodeProxyIntent, uint, int, uvec2, uvec3, uvec4, ivec2, ivec3, ivec4 } from '../tsl/TSLCore.js';
2
+ import { bitcast, floatBitsToUint } from './BitcastNode.js';
3
+ import MathNode, { negate } from './MathNode.js';
4
+
5
+ const registeredBitcountFunctions = {};
6
+
7
+ /**
8
+ * This node represents an operation that counts the bits of a piece of shader data.
9
+ *
10
+ * @augments MathNode
11
+ */
12
+ class BitcountNode extends MathNode {
13
+
14
+ static get type() {
15
+
16
+ return 'BitcountNode';
17
+
18
+ }
19
+
20
+ /**
21
+ * Constructs a new math node.
22
+ *
23
+ * @param {'countTrailingZeros'|'countLeadingZeros'|'countOneBits'} method - The method name.
24
+ * @param {Node} aNode - The first input.
25
+ */
26
+ constructor( method, aNode ) {
27
+
28
+ super( method, aNode );
29
+
30
+ /**
31
+ * This flag can be used for type testing.
32
+ *
33
+ * @type {boolean}
34
+ * @readonly
35
+ * @default true
36
+ */
37
+ this.isBitcountNode = true;
38
+
39
+ }
40
+
41
+ /**
42
+ * Casts the input value of the function to an integer if necessary.
43
+ *
44
+ * @private
45
+ * @param {Node<uint>|Node<int>} inputNode - The input value.
46
+ * @param {Node<uint>} outputNode - The output value.
47
+ * @param {string} elementType - The type of the input value.
48
+ */
49
+ _resolveElementType( inputNode, outputNode, elementType ) {
50
+
51
+ if ( elementType === 'int' ) {
52
+
53
+ outputNode.assign( bitcast( inputNode, 'uint' ) );
54
+
55
+ } else {
56
+
57
+ outputNode.assign( inputNode );
58
+
59
+ }
60
+
61
+ }
62
+
63
+ _returnDataNode( inputType ) {
64
+
65
+ switch ( inputType ) {
66
+
67
+ case 'uint': {
68
+
69
+ return uint;
70
+
71
+ }
72
+
73
+ case 'int': {
74
+
75
+ return int;
76
+
77
+ }
78
+
79
+ case 'uvec2': {
80
+
81
+ return uvec2;
82
+
83
+ }
84
+
85
+ case 'uvec3': {
86
+
87
+ return uvec3;
88
+
89
+ }
90
+
91
+ case 'uvec4': {
92
+
93
+ return uvec4;
94
+
95
+ }
96
+
97
+ case 'ivec2': {
98
+
99
+ return ivec2;
100
+
101
+ }
102
+
103
+ case 'ivec3': {
104
+
105
+ return ivec3;
106
+
107
+ }
108
+
109
+ case 'ivec4': {
110
+
111
+ return ivec4;
112
+
113
+ }
114
+
115
+ }
116
+
117
+ }
118
+
119
+ /**
120
+ * Creates and registers a reusable GLSL function that emulates the behavior of countTrailingZeros.
121
+ *
122
+ * @private
123
+ * @param {string} method - The name of the function to create.
124
+ * @param {string} elementType - The type of the input value.
125
+ * @returns {Function} - The generated function
126
+ */
127
+ _createTrailingZerosBaseLayout( method, elementType ) {
128
+
129
+ const outputConvertNode = this._returnDataNode( elementType );
130
+
131
+ const fnDef = Fn( ( [ value ] ) => {
132
+
133
+ const v = uint( 0.0 );
134
+
135
+ this._resolveElementType( value, v, elementType );
136
+
137
+ const f = float( v.bitAnd( negate( v ) ) );
138
+ const uintBits = floatBitsToUint( f );
139
+
140
+ const numTrailingZeros = ( uintBits.shiftRight( 23 ) ).sub( 127 );
141
+
142
+ return outputConvertNode( numTrailingZeros );
143
+
144
+ } ).setLayout( {
145
+ name: method,
146
+ type: elementType,
147
+ inputs: [
148
+ { name: 'value', type: elementType }
149
+ ]
150
+ } );
151
+
152
+ return fnDef;
153
+
154
+ }
155
+
156
+ /**
157
+ * Creates and registers a reusable GLSL function that emulates the behavior of countLeadingZeros.
158
+ *
159
+ * @private
160
+ * @param {string} method - The name of the function to create.
161
+ * @param {string} elementType - The type of the input value.
162
+ * @returns {Function} - The generated function
163
+ */
164
+ _createLeadingZerosBaseLayout( method, elementType ) {
165
+
166
+ const outputConvertNode = this._returnDataNode( elementType );
167
+
168
+ const fnDef = Fn( ( [ value ] ) => {
169
+
170
+ If( value.equal( uint( 0 ) ), () => {
171
+
172
+ return uint( 32 );
173
+
174
+ } );
175
+
176
+ const v = uint( 0 );
177
+ const n = uint( 0 );
178
+ this._resolveElementType( value, v, elementType );
179
+
180
+ If( v.shiftRight( 16 ).equal( 0 ), () => {
181
+
182
+ n.addAssign( 16 );
183
+ v.shiftLeftAssign( 16 );
184
+
185
+ } );
186
+
187
+ If( v.shiftRight( 24 ).equal( 0 ), () => {
188
+
189
+ n.addAssign( 8 );
190
+ v.shiftLeftAssign( 8 );
191
+
192
+ } );
193
+
194
+ If( v.shiftRight( 28 ).equal( 0 ), () => {
195
+
196
+ n.addAssign( 4 );
197
+ v.shiftLeftAssign( 4 );
198
+
199
+ } );
200
+
201
+ If( v.shiftRight( 30 ).equal( 0 ), () => {
202
+
203
+ n.addAssign( 2 );
204
+ v.shiftLeftAssign( 2 );
205
+
206
+ } );
207
+
208
+ If( v.shiftRight( 31 ).equal( 0 ), () => {
209
+
210
+ n.addAssign( 1 );
211
+
212
+ } );
213
+
214
+ return outputConvertNode( n );
215
+
216
+ } ).setLayout( {
217
+ name: method,
218
+ type: elementType,
219
+ inputs: [
220
+ { name: 'value', type: elementType }
221
+ ]
222
+ } );
223
+
224
+ return fnDef;
225
+
226
+ }
227
+
228
+ /**
229
+ * Creates and registers a reusable GLSL function that emulates the behavior of countOneBits.
230
+ *
231
+ * @private
232
+ * @param {string} method - The name of the function to create.
233
+ * @param {string} elementType - The type of the input value.
234
+ * @returns {Function} - The generated function
235
+ */
236
+ _createOneBitsBaseLayout( method, elementType ) {
237
+
238
+ const outputConvertNode = this._returnDataNode( elementType );
239
+
240
+ const fnDef = Fn( ( [ value ] ) => {
241
+
242
+ const v = uint( 0.0 );
243
+
244
+ this._resolveElementType( value, v, elementType );
245
+
246
+ v.assign( v.sub( v.shiftRight( uint( 1 ) ).bitAnd( uint( 0x55555555 ) ) ) );
247
+ v.assign( v.bitAnd( uint( 0x33333333 ) ).add( v.shiftRight( uint( 2 ) ).bitAnd( uint( 0x33333333 ) ) ) );
248
+
249
+ const numBits = v.add( v.shiftRight( uint( 4 ) ) ).bitAnd( uint( 0xF0F0F0F ) ).mul( uint( 0x1010101 ) ).shiftRight( uint( 24 ) );
250
+
251
+ return outputConvertNode( numBits );
252
+
253
+ } ).setLayout( {
254
+ name: method,
255
+ type: elementType,
256
+ inputs: [
257
+ { name: 'value', type: elementType }
258
+ ]
259
+ } );
260
+
261
+ return fnDef;
262
+
263
+ }
264
+
265
+ /**
266
+ * Creates and registers a reusable GLSL function that emulates the behavior of the specified bitcount function.
267
+ * including considerations for component-wise bitcounts on vector type inputs.
268
+ *
269
+ * @private
270
+ * @param {string} method - The name of the function to create.
271
+ * @param {string} inputType - The type of the input value.
272
+ * @param {number} typeLength - The vec length of the input value.
273
+ * @param {Function} baseFn - The base function that operates on an individual component of the vector.
274
+ * @returns {Function} - The alias function for the specified bitcount method.
275
+ */
276
+ _createMainLayout( method, inputType, typeLength, baseFn ) {
277
+
278
+ const outputConvertNode = this._returnDataNode( inputType );
279
+
280
+ const fnDef = Fn( ( [ value ] ) => {
281
+
282
+ if ( typeLength === 1 ) {
283
+
284
+ return outputConvertNode( baseFn( value ) );
285
+
286
+ } else {
287
+
288
+ const vec = outputConvertNode( 0 );
289
+
290
+ const components = [ 'x', 'y', 'z', 'w' ];
291
+ for ( let i = 0; i < typeLength; i ++ ) {
292
+
293
+ const component = components[ i ];
294
+
295
+ vec[ component ].assign( baseFn( value[ component ] ) );
296
+
297
+ }
298
+
299
+ return vec;
300
+
301
+ }
302
+
303
+ } ).setLayout( {
304
+ name: method,
305
+ type: inputType,
306
+ inputs: [
307
+ { name: 'value', type: inputType }
308
+ ]
309
+ } );
310
+
311
+ return fnDef;
312
+
313
+ }
314
+
315
+ setup( builder ) {
316
+
317
+ const { method, aNode } = this;
318
+
319
+ const { renderer } = builder;
320
+
321
+ if ( renderer.backend.isWebGPUBackend ) {
322
+
323
+ // use built-in WGSL functions for WebGPU
324
+
325
+ return super.setup( builder );
326
+
327
+ }
328
+
329
+ const inputType = this.getInputType( builder );
330
+ const elementType = builder.getElementType( inputType );
331
+
332
+ const typeLength = builder.getTypeLength( inputType );
333
+
334
+ const baseMethod = `${method}_base_${elementType}`;
335
+ const newMethod = `${method}_${inputType}`;
336
+
337
+ let baseFn = registeredBitcountFunctions[ baseMethod ];
338
+
339
+ if ( baseFn === undefined ) {
340
+
341
+ switch ( method ) {
342
+
343
+ case BitcountNode.COUNT_LEADING_ZEROS: {
344
+
345
+ baseFn = this._createLeadingZerosBaseLayout( baseMethod, elementType );
346
+ break;
347
+
348
+ }
349
+
350
+ case BitcountNode.COUNT_TRAILING_ZEROS: {
351
+
352
+ baseFn = this._createTrailingZerosBaseLayout( baseMethod, elementType );
353
+ break;
354
+
355
+ }
356
+
357
+ case BitcountNode.COUNT_ONE_BITS: {
358
+
359
+ baseFn = this._createOneBitsBaseLayout( baseMethod, elementType );
360
+ break;
361
+
362
+ }
363
+
364
+ }
365
+
366
+ registeredBitcountFunctions[ baseMethod ] = baseFn;
367
+
368
+ }
369
+
370
+ let fn = registeredBitcountFunctions[ newMethod ];
371
+
372
+ if ( fn === undefined ) {
373
+
374
+ fn = this._createMainLayout( newMethod, inputType, typeLength, baseFn );
375
+ registeredBitcountFunctions[ newMethod ] = fn;
376
+
377
+ }
378
+
379
+ const output = Fn( () => {
380
+
381
+ return fn(
382
+ aNode,
383
+ );
384
+
385
+ } );
386
+
387
+ return output();
388
+
389
+ }
390
+
391
+ }
392
+
393
+ export default BitcountNode;
394
+
395
+ BitcountNode.COUNT_TRAILING_ZEROS = 'countTrailingZeros';
396
+ BitcountNode.COUNT_LEADING_ZEROS = 'countLeadingZeros';
397
+ BitcountNode.COUNT_ONE_BITS = 'countOneBits';
398
+
399
+ /**
400
+ * Finds the number of consecutive 0 bits from the least significant bit of the input value,
401
+ * which is also the index of the least significant bit of the input value.
402
+ *
403
+ * Can only be used with {@link WebGPURenderer} and a WebGPU backend.
404
+ *
405
+ * @tsl
406
+ * @function
407
+ * @param {Node | number} x - The input value.
408
+ * @returns {Node}
409
+ */
410
+ export const countTrailingZeros = /*@__PURE__*/ nodeProxyIntent( BitcountNode, BitcountNode.COUNT_TRAILING_ZEROS ).setParameterLength( 1 );
411
+
412
+ /**
413
+ * Finds the number of consecutive 0 bits starting from the most significant bit of the input value.
414
+ *
415
+ * Can only be used with {@link WebGPURenderer} and a WebGPU backend.
416
+ *
417
+ * @tsl
418
+ * @function
419
+ * @param {Node | number} x - The input value.
420
+ * @returns {Node}
421
+ */
422
+ export const countLeadingZeros = /*@__PURE__*/ nodeProxyIntent( BitcountNode, BitcountNode.COUNT_LEADING_ZEROS ).setParameterLength( 1 );
423
+
424
+ /**
425
+ * Finds the number of '1' bits set in the input value
426
+ *
427
+ * Can only be used with {@link WebGPURenderer} and a WebGPU backend.
428
+ *
429
+ * @tsl
430
+ * @function
431
+ * @returns {Node}
432
+ */
433
+ export const countOneBits = /*@__PURE__*/ nodeProxyIntent( BitcountNode, BitcountNode.COUNT_ONE_BITS ).setParameterLength( 1 );
@@ -0,0 +1,98 @@
1
+ import TempNode from '../core/TempNode.js';
2
+ import { nodeProxyIntent } from '../tsl/TSLCore.js';
3
+
4
+ /**
5
+ * This node represents an operation that packs floating-point values of a vector into an unsigned 32-bit integer
6
+ *
7
+ * @augments TempNode
8
+ */
9
+ class PackFloatNode extends TempNode {
10
+
11
+ static get type() {
12
+
13
+ return 'PackFloatNode';
14
+
15
+ }
16
+
17
+ /**
18
+ *
19
+ * @param {'snorm' | 'unorm' | 'float16'} encoding - The numeric encoding that describes how the float values are mapped to the integer range.
20
+ * @param {Node} vectorNode - The vector node to be packed
21
+ */
22
+ constructor( encoding, vectorNode ) {
23
+
24
+ super();
25
+
26
+ /**
27
+ * The vector to be packed.
28
+ *
29
+ * @type {Node}
30
+ */
31
+ this.vectorNode = vectorNode;
32
+
33
+ /**
34
+ * The numeric encoding.
35
+ *
36
+ * @type {string}
37
+ */
38
+ this.encoding = encoding;
39
+
40
+ /**
41
+ * This flag can be used for type testing.
42
+ *
43
+ * @type {boolean}
44
+ * @readonly
45
+ * @default true
46
+ */
47
+ this.isPackFloatNode = true;
48
+
49
+ }
50
+
51
+ getNodeType() {
52
+
53
+ return 'uint';
54
+
55
+ }
56
+
57
+ generate( builder ) {
58
+
59
+ const inputType = this.vectorNode.getNodeType( builder );
60
+ return `${ builder.getFloatPackingMethod( this.encoding ) }(${ this.vectorNode.build( builder, inputType )})`;
61
+
62
+ }
63
+
64
+ }
65
+
66
+ export default PackFloatNode;
67
+
68
+ /**
69
+ * Converts each component of the normalized float to 16-bit integer values. The results are packed into a single unsigned integer.
70
+ * round(clamp(c, -1, +1) * 32767.0)
71
+ *
72
+ * @tsl
73
+ * @function
74
+ * @param {Node<vec2>} value - The 2-component vector to be packed
75
+ * @returns {Node}
76
+ */
77
+ export const packSnorm2x16 = /*@__PURE__*/ nodeProxyIntent( PackFloatNode, 'snorm' ).setParameterLength( 1 );
78
+
79
+ /**
80
+ * Converts each component of the normalized float to 16-bit integer values. The results are packed into a single unsigned integer.
81
+ * round(clamp(c, 0, +1) * 65535.0)
82
+ *
83
+ * @tsl
84
+ * @function
85
+ * @param {Node<vec2>} value - The 2-component vector to be packed
86
+ * @returns {Node}
87
+ */
88
+ export const packUnorm2x16 = /*@__PURE__*/ nodeProxyIntent( PackFloatNode, 'unorm' ).setParameterLength( 1 );
89
+
90
+ /**
91
+ * Converts each component of the vec2 to 16-bit floating-point values. The results are packed into a single unsigned integer.
92
+ *
93
+ * @tsl
94
+ * @function
95
+ * @param {Node<vec2>} value - The 2-component vector to be packed
96
+ * @returns {Node}
97
+ */
98
+ export const packHalf2x16 = /*@__PURE__*/ nodeProxyIntent( PackFloatNode, 'float16' ).setParameterLength( 1 );
@@ -0,0 +1,96 @@
1
+ import TempNode from '../core/TempNode.js';
2
+ import { nodeProxyIntent } from '../tsl/TSLCore.js';
3
+
4
+ /**
5
+ * This node represents an operation that unpacks values from a 32-bit unsigned integer, reinterpreting the results as a floating-point vector
6
+ *
7
+ * @augments TempNode
8
+ */
9
+ class UnpackFloatNode extends TempNode {
10
+
11
+ static get type() {
12
+
13
+ return 'UnpackFloatNode';
14
+
15
+ }
16
+
17
+ /**
18
+ *
19
+ * @param {'snorm' | 'unorm' | 'float16'} encoding - The numeric encoding that describes how the integer values are mapped to the float range
20
+ * @param {Node} uintNode - The uint node to be unpacked
21
+ */
22
+ constructor( encoding, uintNode ) {
23
+
24
+ super();
25
+
26
+ /**
27
+ * The unsigned integer to be unpacked.
28
+ *
29
+ * @type {Node}
30
+ */
31
+ this.uintNode = uintNode;
32
+
33
+ /**
34
+ * The numeric encoding.
35
+ *
36
+ * @type {string}
37
+ */
38
+ this.encoding = encoding;
39
+
40
+ /**
41
+ * This flag can be used for type testing.
42
+ *
43
+ * @type {boolean}
44
+ * @readonly
45
+ * @default true
46
+ */
47
+ this.isUnpackFloatNode = true;
48
+
49
+ }
50
+
51
+ getNodeType() {
52
+
53
+ return 'vec2';
54
+
55
+ }
56
+
57
+ generate( builder ) {
58
+
59
+ const inputType = this.uintNode.getNodeType( builder );
60
+ return `${ builder.getFloatUnpackingMethod( this.encoding ) }(${ this.uintNode.build( builder, inputType )})`;
61
+
62
+ }
63
+
64
+ }
65
+
66
+ export default UnpackFloatNode;
67
+
68
+ /**
69
+ * Unpacks a 32-bit unsigned integer into two 16-bit values, interpreted as normalized signed integers. Returns a vec2 with both values.
70
+ *
71
+ * @tsl
72
+ * @function
73
+ * @param {Node<uint>} value - The unsigned integer to be unpacked
74
+ * @returns {Node}
75
+ */
76
+ export const unpackSnorm2x16 = /*@__PURE__*/ nodeProxyIntent( UnpackFloatNode, 'snorm' ).setParameterLength( 1 );
77
+
78
+ /**
79
+ * Unpacks a 32-bit unsigned integer into two 16-bit values, interpreted as normalized unsigned integers. Returns a vec2 with both values.
80
+ *
81
+ * @tsl
82
+ * @function
83
+ * @param {Node<uint>} value - The unsigned integer to be unpacked
84
+ * @returns {Node}
85
+ */
86
+ export const unpackUnorm2x16 = /*@__PURE__*/ nodeProxyIntent( UnpackFloatNode, 'unorm' ).setParameterLength( 1 );
87
+
88
+ /**
89
+ * Unpacks a 32-bit unsigned integer into two 16-bit values, interpreted as 16-bit floating-point numbers. Returns a vec2 with both values.
90
+ *
91
+ * @tsl
92
+ * @function
93
+ * @param {Node<uint>} value - The unsigned integer to be unpacked
94
+ * @returns {Node}
95
+ */
96
+ export const unpackHalf2x16 = /*@__PURE__*/ nodeProxyIntent( UnpackFloatNode, 'float16' ).setParameterLength( 1 );
@@ -308,7 +308,7 @@ class PMREMNode extends TempNode {
308
308
 
309
309
  if ( uvNode === null && builder.context.getUV ) {
310
310
 
311
- uvNode = builder.context.getUV( this );
311
+ uvNode = builder.context.getUV( this, builder );
312
312
 
313
313
  }
314
314
 
@@ -441,7 +441,7 @@ const ShaderNodeProxy = function ( NodeClass, scope = null, factor = null, setti
441
441
 
442
442
  const ShaderNodeImmutable = function ( NodeClass, ...params ) {
443
443
 
444
- return nodeObject( new NodeClass( ...nodeArray( params ) ) );
444
+ return new NodeClass( ...nodeArray( params ) );
445
445
 
446
446
  };
447
447
 
@@ -873,7 +873,7 @@ const ConvertType = function ( type, cacheMap = null ) {
873
873
 
874
874
  error( `TSL: Invalid parameter for the type "${ type }".` );
875
875
 
876
- return nodeObject( new ConstNode( 0, type ) );
876
+ return new ConstNode( 0, type );
877
877
 
878
878
  }
879
879
 
@@ -1171,8 +1171,8 @@ export const mat2 = new ConvertType( 'mat2' );
1171
1171
  export const mat3 = new ConvertType( 'mat3' );
1172
1172
  export const mat4 = new ConvertType( 'mat4' );
1173
1173
 
1174
- export const string = ( value = '' ) => nodeObject( new ConstNode( value, 'string' ) );
1175
- export const arrayBuffer = ( value ) => nodeObject( new ConstNode( value, 'ArrayBuffer' ) );
1174
+ export const string = ( value = '' ) => new ConstNode( value, 'string' );
1175
+ export const arrayBuffer = ( value ) => new ConstNode( value, 'ArrayBuffer' );
1176
1176
 
1177
1177
  addMethodChaining( 'toColor', color );
1178
1178
  addMethodChaining( 'toFloat', float );
@@ -61,6 +61,19 @@ class ArrayElementNode extends Node { // @TODO: If extending from TempNode it br
61
61
 
62
62
  }
63
63
 
64
+ /**
65
+ * This method is overwritten since the member type is inferred from the array-like node.
66
+ *
67
+ * @param {NodeBuilder} builder - The current node builder.
68
+ * @param {string} name - The member name.
69
+ * @return {string} The member type.
70
+ */
71
+ getMemberType( builder, name ) {
72
+
73
+ return this.node.getMemberType( builder, name );
74
+
75
+ }
76
+
64
77
  generate( builder ) {
65
78
 
66
79
  const indexType = this.indexNode.getNodeType( builder );
@@ -1,6 +1,5 @@
1
1
  import Node from '../core/Node.js';
2
2
  import { NodeUpdateType } from '../core/constants.js';
3
- import { nodeObject } from '../tsl/TSLCore.js';
4
3
 
5
4
  /**
6
5
  * EventNode is a node that executes a callback during specific update phases.
@@ -76,7 +75,7 @@ export default EventNode;
76
75
  * @param {Function} callback - The callback function.
77
76
  * @returns {EventNode}
78
77
  */
79
- const createEvent = ( type, callback ) => nodeObject( new EventNode( type, callback ) ).toStack();
78
+ const createEvent = ( type, callback ) => new EventNode( type, callback ).toStack();
80
79
 
81
80
  /**
82
81
  * Creates an event that triggers a function every time an object (Mesh|Sprite) is rendered.