super-three 0.167.0 → 0.169.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 (387) hide show
  1. package/build/three.cjs +532 -173
  2. package/build/three.module.js +532 -174
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +18173 -14266
  5. package/build/three.webgpu.min.js +1 -1
  6. package/build/three.webgpu.nodes.js +79941 -0
  7. package/build/three.webgpu.nodes.min.js +6 -0
  8. package/examples/jsm/Addons.js +0 -4
  9. package/examples/jsm/animation/AnimationClipCreator.js +1 -1
  10. package/examples/jsm/capabilities/WebGL.js +27 -21
  11. package/examples/jsm/controls/ArcballControls.js +174 -158
  12. package/examples/jsm/controls/DragControls.js +260 -132
  13. package/examples/jsm/controls/FirstPersonControls.js +175 -163
  14. package/examples/jsm/controls/FlyControls.js +194 -188
  15. package/examples/jsm/controls/OrbitControls.js +777 -786
  16. package/examples/jsm/controls/PointerLockControls.js +24 -15
  17. package/examples/jsm/controls/TrackballControls.js +469 -448
  18. package/examples/jsm/controls/TransformControls.js +97 -62
  19. package/examples/jsm/effects/AnaglyphEffect.js +6 -13
  20. package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
  21. package/examples/jsm/effects/StereoEffect.js +6 -1
  22. package/examples/jsm/environments/RoomEnvironment.js +1 -1
  23. package/examples/jsm/exporters/DRACOExporter.js +4 -2
  24. package/examples/jsm/exporters/EXRExporter.js +19 -11
  25. package/examples/jsm/exporters/GLTFExporter.js +6 -1
  26. package/examples/jsm/exporters/KTX2Exporter.js +21 -13
  27. package/examples/jsm/exporters/OBJExporter.js +5 -1
  28. package/examples/jsm/exporters/PLYExporter.js +9 -7
  29. package/examples/jsm/exporters/USDZExporter.js +29 -8
  30. package/examples/jsm/geometries/DecalGeometry.js +4 -1
  31. package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
  32. package/examples/jsm/helpers/LightProbeHelper.js +43 -44
  33. package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
  34. package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
  35. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  36. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  37. package/examples/jsm/lights/LightProbeGenerator.js +24 -10
  38. package/examples/jsm/loaders/ColladaLoader.js +9 -6
  39. package/examples/jsm/loaders/DRACOLoader.js +3 -1
  40. package/examples/jsm/loaders/FBXLoader.js +30 -20
  41. package/examples/jsm/loaders/GLTFLoader.js +5 -10
  42. package/examples/jsm/loaders/KTX2Loader.js +27 -12
  43. package/examples/jsm/loaders/MTLLoader.js +4 -3
  44. package/examples/jsm/loaders/MaterialXLoader.js +40 -14
  45. package/examples/jsm/loaders/OBJLoader.js +5 -3
  46. package/examples/jsm/loaders/PCDLoader.js +14 -13
  47. package/examples/jsm/loaders/PDBLoader.js +3 -2
  48. package/examples/jsm/loaders/PLYLoader.js +8 -5
  49. package/examples/jsm/loaders/STLLoader.js +3 -2
  50. package/examples/jsm/loaders/VRMLLoader.js +10 -10
  51. package/examples/jsm/loaders/VTKLoader.js +4 -3
  52. package/examples/jsm/loaders/XYZLoader.js +3 -2
  53. package/examples/jsm/misc/Timer.js +1 -1
  54. package/examples/jsm/modifiers/CurveModifierGPU.js +233 -0
  55. package/examples/jsm/objects/LensflareMesh.js +322 -0
  56. package/examples/jsm/objects/SkyMesh.js +187 -0
  57. package/examples/jsm/objects/Water2Mesh.js +158 -0
  58. package/examples/jsm/objects/WaterMesh.js +101 -0
  59. package/examples/jsm/physics/JoltPhysics.js +1 -1
  60. package/examples/jsm/physics/RapierPhysics.js +21 -1
  61. package/examples/jsm/postprocessing/OutlinePass.js +31 -46
  62. package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
  63. package/examples/jsm/shaders/BleachBypassShader.js +1 -2
  64. package/examples/jsm/shaders/OutputShader.js +1 -1
  65. package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
  66. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
  67. package/examples/jsm/transpiler/TSLEncoder.js +8 -8
  68. package/examples/jsm/utils/GeometryCompressionUtils.js +37 -122
  69. package/examples/jsm/utils/ShadowMapViewer.js +3 -8
  70. package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
  71. package/examples/jsm/utils/SkeletonUtils.js +84 -66
  72. package/examples/jsm/utils/TextureUtils.js +2 -1
  73. package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
  74. package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
  75. package/package.json +3 -2
  76. package/src/Three.WebGPU.Nodes.js +200 -0
  77. package/src/Three.WebGPU.js +7 -0
  78. package/src/Three.js +1 -0
  79. package/src/audio/Audio.js +2 -2
  80. package/src/constants.js +1 -1
  81. package/src/core/BufferAttribute.js +0 -9
  82. package/src/core/Clock.js +1 -1
  83. package/src/core/InterleavedBuffer.js +0 -9
  84. package/src/extras/Controls.js +32 -0
  85. package/src/geometries/CylinderGeometry.js +11 -4
  86. package/src/loaders/MaterialLoader.js +7 -1
  87. package/src/loaders/ObjectLoader.js +3 -3
  88. package/src/{nodes/loaders → loaders/nodes}/NodeLoader.js +25 -5
  89. package/src/{nodes/loaders → loaders/nodes}/NodeMaterialLoader.js +21 -18
  90. package/src/{nodes/loaders → loaders/nodes}/NodeObjectLoader.js +19 -0
  91. package/src/materials/Material.js +4 -7
  92. package/src/materials/nodes/InstancedPointsNodeMaterial.js +156 -0
  93. package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +56 -59
  94. package/src/{nodes/materials → materials/nodes}/LineBasicNodeMaterial.js +8 -5
  95. package/src/{nodes/materials → materials/nodes}/LineDashedNodeMaterial.js +12 -10
  96. package/src/{nodes/materials → materials/nodes}/MeshBasicNodeMaterial.js +16 -12
  97. package/src/{nodes/materials → materials/nodes}/MeshLambertNodeMaterial.js +10 -6
  98. package/src/{nodes/materials → materials/nodes}/MeshMatcapNodeMaterial.js +13 -9
  99. package/src/{nodes/materials → materials/nodes}/MeshNormalNodeMaterial.js +13 -9
  100. package/src/{nodes/materials → materials/nodes}/MeshPhongNodeMaterial.js +14 -9
  101. package/src/{nodes/materials → materials/nodes}/MeshPhysicalNodeMaterial.js +22 -18
  102. package/src/{nodes/materials → materials/nodes}/MeshSSSNodeMaterial.js +10 -7
  103. package/src/{nodes/materials → materials/nodes}/MeshStandardNodeMaterial.js +22 -12
  104. package/src/{nodes/materials → materials/nodes}/MeshToonNodeMaterial.js +9 -5
  105. package/src/{nodes/materials → materials/nodes}/NodeMaterial.js +71 -115
  106. package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -1
  107. package/src/{nodes/materials → materials/nodes}/PointsNodeMaterial.js +8 -5
  108. package/src/{nodes/materials → materials/nodes}/ShadowNodeMaterial.js +9 -5
  109. package/src/{nodes/materials → materials/nodes}/SpriteNodeMaterial.js +47 -14
  110. package/src/{nodes/materials → materials/nodes}/VolumeNodeMaterial.js +24 -22
  111. package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
  112. package/src/math/Triangle.js +24 -0
  113. package/src/nodes/Nodes.js +103 -159
  114. package/src/nodes/TSL.js +179 -0
  115. package/src/nodes/accessors/AccessorsUtils.js +8 -8
  116. package/src/nodes/accessors/BatchNode.js +53 -21
  117. package/src/nodes/accessors/{BitangentNode.js → Bitangent.js} +9 -9
  118. package/src/nodes/accessors/BufferAttributeNode.js +8 -5
  119. package/src/nodes/accessors/BufferNode.js +7 -4
  120. package/src/nodes/accessors/Camera.js +13 -0
  121. package/src/nodes/accessors/ClippingNode.js +19 -13
  122. package/src/nodes/accessors/CubeTextureNode.js +9 -8
  123. package/src/nodes/accessors/InstanceNode.js +19 -15
  124. package/src/nodes/accessors/InstancedPointsMaterialNode.js +8 -5
  125. package/src/nodes/accessors/Lights.js +51 -0
  126. package/src/nodes/accessors/MaterialNode.js +56 -55
  127. package/src/nodes/accessors/MaterialProperties.js +3 -0
  128. package/src/nodes/accessors/MaterialReferenceNode.js +9 -4
  129. package/src/nodes/accessors/ModelNode.js +47 -12
  130. package/src/nodes/accessors/ModelViewProjectionNode.js +12 -9
  131. package/src/nodes/accessors/MorphNode.js +17 -13
  132. package/src/nodes/accessors/Normal.js +88 -0
  133. package/src/nodes/accessors/Object3DNode.js +17 -33
  134. package/src/nodes/accessors/PointUVNode.js +9 -5
  135. package/src/nodes/accessors/Position.js +10 -0
  136. package/src/nodes/accessors/ReferenceBaseNode.js +171 -0
  137. package/src/nodes/accessors/ReferenceNode.js +50 -7
  138. package/src/nodes/accessors/ReflectVector.js +10 -0
  139. package/src/nodes/accessors/RendererReferenceNode.js +12 -6
  140. package/src/nodes/accessors/SceneNode.js +9 -6
  141. package/src/nodes/accessors/SkinningNode.js +88 -21
  142. package/src/nodes/accessors/StorageBufferNode.js +22 -5
  143. package/src/nodes/accessors/StorageTextureNode.js +9 -6
  144. package/src/nodes/accessors/Tangent.js +22 -0
  145. package/src/nodes/accessors/Texture3DNode.js +16 -13
  146. package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +3 -32
  147. package/src/nodes/accessors/TextureNode.js +29 -23
  148. package/src/nodes/accessors/TextureSizeNode.js +10 -9
  149. package/src/nodes/accessors/{UniformsNode.js → UniformArrayNode.js} +26 -14
  150. package/src/nodes/accessors/UserDataNode.js +10 -7
  151. package/src/nodes/accessors/VelocityNode.js +134 -0
  152. package/src/nodes/accessors/VertexColorNode.js +7 -4
  153. package/src/nodes/code/CodeNode.js +9 -5
  154. package/src/nodes/code/ExpressionNode.js +10 -6
  155. package/src/nodes/code/FunctionCallNode.js +8 -5
  156. package/src/nodes/code/FunctionNode.js +8 -23
  157. package/src/nodes/code/ScriptableNode.js +13 -10
  158. package/src/nodes/code/ScriptableValueNode.js +9 -7
  159. package/src/nodes/core/AssignNode.js +12 -9
  160. package/src/nodes/core/AttributeNode.js +12 -21
  161. package/src/nodes/core/BypassNode.js +11 -7
  162. package/src/nodes/core/CacheNode.js +10 -6
  163. package/src/nodes/core/ConstNode.js +6 -3
  164. package/src/nodes/core/ContextNode.js +21 -11
  165. package/src/nodes/core/IndexNode.js +35 -8
  166. package/src/nodes/core/InputNode.js +7 -3
  167. package/src/nodes/core/MRTNode.js +16 -7
  168. package/src/nodes/core/Node.js +19 -40
  169. package/src/nodes/core/NodeBuilder.js +117 -38
  170. package/src/nodes/core/NodeUtils.js +49 -6
  171. package/src/nodes/core/OutputStructNode.js +10 -6
  172. package/src/nodes/core/ParameterNode.js +7 -4
  173. package/src/nodes/core/PropertyNode.js +36 -32
  174. package/src/nodes/core/StackNode.js +31 -11
  175. package/src/nodes/core/StructTypeNode.js +7 -3
  176. package/src/nodes/core/TempNode.js +8 -4
  177. package/src/nodes/core/UniformGroupNode.js +14 -11
  178. package/src/nodes/core/UniformNode.js +7 -4
  179. package/src/nodes/core/VarNode.js +12 -8
  180. package/src/nodes/core/VaryingNode.js +10 -6
  181. package/src/nodes/display/AfterImageNode.js +15 -9
  182. package/src/nodes/display/AnaglyphPassNode.js +67 -0
  183. package/src/nodes/display/AnamorphicNode.js +17 -11
  184. package/src/nodes/display/BleachBypass.js +26 -0
  185. package/src/nodes/display/BlendMode.js +54 -0
  186. package/src/nodes/display/BloomNode.js +27 -19
  187. package/src/nodes/display/BumpMapNode.js +13 -12
  188. package/src/nodes/display/ColorAdjustment.js +46 -0
  189. package/src/nodes/display/ColorSpaceFunctions.js +38 -0
  190. package/src/nodes/display/ColorSpaceNode.js +67 -61
  191. package/src/nodes/display/DenoiseNode.js +23 -17
  192. package/src/nodes/display/DepthOfFieldNode.js +12 -7
  193. package/src/nodes/display/DotScreenNode.js +13 -22
  194. package/src/nodes/display/FXAANode.js +21 -16
  195. package/src/nodes/display/FilmNode.js +11 -7
  196. package/src/nodes/display/FrontFacingNode.js +10 -6
  197. package/src/nodes/display/GTAONode.js +22 -15
  198. package/src/nodes/display/GaussianBlurNode.js +14 -8
  199. package/src/nodes/display/Lut3DNode.js +10 -6
  200. package/src/nodes/display/MotionBlur.js +25 -0
  201. package/src/nodes/display/NormalMapNode.js +13 -13
  202. package/src/nodes/display/ParallaxBarrierPassNode.js +58 -0
  203. package/src/nodes/display/PassNode.js +95 -8
  204. package/src/nodes/display/PixelationPassNode.js +20 -8
  205. package/src/nodes/display/PosterizeNode.js +8 -7
  206. package/src/nodes/display/RGBShiftNode.js +11 -7
  207. package/src/nodes/display/RenderOutputNode.js +15 -11
  208. package/src/nodes/display/SSAAPassNode.js +287 -0
  209. package/src/nodes/display/ScreenNode.js +181 -0
  210. package/src/nodes/display/Sepia.js +17 -0
  211. package/src/nodes/display/SobelOperatorNode.js +13 -8
  212. package/src/nodes/display/StereoCompositePassNode.js +110 -0
  213. package/src/nodes/display/StereoPassNode.js +83 -0
  214. package/src/nodes/display/ToneMappingFunctions.js +190 -0
  215. package/src/nodes/display/ToneMappingNode.js +15 -175
  216. package/src/nodes/display/ToonOutlinePassNode.js +111 -0
  217. package/src/nodes/display/TransitionNode.js +12 -8
  218. package/src/nodes/display/ViewportDepthNode.js +34 -29
  219. package/src/nodes/display/ViewportDepthTextureNode.js +10 -9
  220. package/src/nodes/display/ViewportSharedTextureNode.js +10 -9
  221. package/src/nodes/display/ViewportTextureNode.js +11 -11
  222. package/src/nodes/fog/FogExp2Node.js +8 -7
  223. package/src/nodes/fog/FogNode.js +10 -8
  224. package/src/nodes/fog/FogRangeNode.js +8 -7
  225. package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
  226. package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  227. package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
  228. package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
  229. package/src/nodes/functions/BSDF/D_GGX.js +2 -2
  230. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
  231. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  232. package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
  233. package/src/nodes/functions/BSDF/LTC.js +6 -6
  234. package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
  235. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
  236. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  237. package/src/nodes/functions/BasicLightingModel.js +1 -1
  238. package/src/nodes/functions/PhongLightingModel.js +5 -5
  239. package/src/nodes/functions/PhysicalLightingModel.js +34 -33
  240. package/src/nodes/functions/ShadowMaskModel.js +1 -1
  241. package/src/nodes/functions/ToonLightingModel.js +3 -3
  242. package/src/nodes/functions/material/getGeometryRoughness.js +4 -4
  243. package/src/nodes/functions/material/getRoughness.js +2 -2
  244. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  245. package/src/nodes/geometry/RangeNode.js +9 -5
  246. package/src/nodes/gpgpu/AtomicFunctionNode.js +99 -0
  247. package/src/nodes/gpgpu/BarrierNode.js +40 -0
  248. package/src/nodes/gpgpu/ComputeBuiltinNode.js +98 -0
  249. package/src/nodes/gpgpu/ComputeNode.js +10 -6
  250. package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
  251. package/src/nodes/lighting/AONode.js +6 -3
  252. package/src/nodes/lighting/AmbientLightNode.js +6 -8
  253. package/src/nodes/lighting/AnalyticLightNode.js +225 -36
  254. package/src/nodes/lighting/BasicEnvironmentNode.js +8 -4
  255. package/src/nodes/lighting/BasicLightMapNode.js +7 -4
  256. package/src/nodes/lighting/DirectionalLightNode.js +7 -9
  257. package/src/nodes/lighting/EnvironmentNode.js +23 -19
  258. package/src/nodes/lighting/HemisphereLightNode.js +11 -11
  259. package/src/nodes/lighting/IESSpotLightNode.js +7 -9
  260. package/src/nodes/lighting/IrradianceNode.js +6 -3
  261. package/src/nodes/lighting/LightProbeNode.js +53 -0
  262. package/src/nodes/lighting/LightUtils.js +3 -3
  263. package/src/nodes/lighting/LightingContextNode.js +19 -18
  264. package/src/nodes/lighting/LightingNode.js +7 -3
  265. package/src/nodes/lighting/LightsNode.js +112 -75
  266. package/src/nodes/lighting/PointLightNode.js +12 -13
  267. package/src/nodes/lighting/RectAreaLightNode.js +11 -11
  268. package/src/nodes/lighting/SpotLightNode.js +14 -16
  269. package/src/nodes/materialx/MaterialXNodes.js +2 -2
  270. package/src/nodes/materialx/lib/mx_hsv.js +36 -31
  271. package/src/nodes/materialx/lib/mx_noise.js +96 -96
  272. package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
  273. package/src/nodes/math/{CondNode.js → ConditionalNode.js} +38 -10
  274. package/src/nodes/math/Hash.js +13 -0
  275. package/src/nodes/math/MathNode.js +127 -124
  276. package/src/nodes/math/MathUtils.js +0 -7
  277. package/src/nodes/math/OperatorNode.js +97 -52
  278. package/src/nodes/math/TriNoise3D.js +19 -29
  279. package/src/nodes/pmrem/PMREMNode.js +61 -15
  280. package/src/nodes/pmrem/PMREMUtils.js +46 -46
  281. package/src/nodes/procedural/Checker.js +14 -0
  282. package/src/nodes/tsl/TSLBase.js +30 -0
  283. package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +105 -97
  284. package/src/nodes/utils/ArrayElementNode.js +8 -4
  285. package/src/nodes/utils/ConvertNode.js +7 -3
  286. package/src/nodes/utils/CubeMapNode.js +160 -0
  287. package/src/nodes/utils/Discard.js +8 -0
  288. package/src/nodes/utils/EquirectUVNode.js +9 -6
  289. package/src/nodes/utils/FlipNode.js +68 -0
  290. package/src/nodes/utils/FunctionOverloadingNode.js +9 -5
  291. package/src/nodes/utils/JoinNode.js +6 -3
  292. package/src/nodes/utils/LoopNode.js +16 -6
  293. package/src/nodes/utils/MatcapUVNode.js +10 -7
  294. package/src/nodes/utils/MaxMipLevelNode.js +8 -5
  295. package/src/nodes/utils/OscNode.js +12 -8
  296. package/src/nodes/utils/Packing.js +4 -0
  297. package/src/nodes/utils/RTTNode.js +11 -8
  298. package/src/nodes/utils/ReflectorNode.js +12 -4
  299. package/src/nodes/utils/RemapNode.js +12 -8
  300. package/src/nodes/utils/RotateNode.js +8 -13
  301. package/src/nodes/utils/SetNode.js +7 -4
  302. package/src/nodes/utils/SplitNode.js +7 -3
  303. package/src/nodes/utils/SpriteSheetUVNode.js +10 -6
  304. package/src/nodes/utils/SpriteUtils.js +47 -0
  305. package/src/nodes/utils/StorageArrayElementNode.js +11 -12
  306. package/src/nodes/utils/TimerNode.js +8 -5
  307. package/src/nodes/utils/TriplanarTexturesNode.js +11 -9
  308. package/src/nodes/utils/UVUtils.js +19 -0
  309. package/src/nodes/utils/ViewportUtils.js +14 -0
  310. package/src/objects/BatchedMesh.js +78 -13
  311. package/src/objects/LOD.js +21 -0
  312. package/src/objects/Line.js +1 -0
  313. package/src/objects/Mesh.js +7 -23
  314. package/src/objects/Points.js +2 -0
  315. package/src/renderers/WebGLRenderer.js +88 -41
  316. package/src/renderers/common/Backend.js +2 -2
  317. package/src/renderers/common/Background.js +3 -1
  318. package/src/renderers/common/BindGroup.js +3 -1
  319. package/src/renderers/common/Bindings.js +13 -15
  320. package/src/renderers/common/BundleGroup.js +26 -0
  321. package/src/renderers/common/ClippingContext.js +15 -5
  322. package/src/renderers/common/CubeRenderTarget.js +9 -3
  323. package/src/renderers/common/PostProcessing.js +4 -1
  324. package/src/renderers/common/QuadMesh.js +2 -0
  325. package/src/renderers/common/RenderContext.js +23 -0
  326. package/src/renderers/common/RenderList.js +1 -1
  327. package/src/renderers/common/RenderObject.js +117 -6
  328. package/src/renderers/common/RenderObjects.js +8 -1
  329. package/src/renderers/common/Renderer.js +128 -94
  330. package/src/renderers/common/SampledTexture.js +12 -3
  331. package/src/renderers/common/Textures.js +8 -12
  332. package/src/renderers/common/extras/PMREMGenerator.js +19 -22
  333. package/src/renderers/common/nodes/NodeBuilderState.js +4 -4
  334. package/src/renderers/common/nodes/NodeLibrary.js +118 -0
  335. package/src/renderers/common/nodes/NodeSampledTexture.js +2 -2
  336. package/src/renderers/common/nodes/Nodes.js +65 -19
  337. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
  338. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
  339. package/src/renderers/webgl/WebGLAttributes.js +45 -14
  340. package/src/renderers/webgl/WebGLCapabilities.js +9 -0
  341. package/src/renderers/webgl/WebGLProgram.js +3 -1
  342. package/src/renderers/webgl/WebGLPrograms.js +21 -17
  343. package/src/renderers/webgl/WebGLProperties.js +7 -0
  344. package/src/renderers/webgl/WebGLState.js +21 -0
  345. package/src/renderers/webgl/WebGLTextures.js +83 -4
  346. package/src/renderers/webgl-fallback/WebGLBackend.js +135 -110
  347. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +60 -12
  348. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +6 -0
  349. package/src/renderers/webgl-fallback/utils/WebGLState.js +20 -2
  350. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +89 -37
  351. package/src/renderers/webgpu/WebGPUBackend.js +112 -86
  352. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
  353. package/src/renderers/webgpu/WebGPURenderer.js +9 -6
  354. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
  355. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +105 -0
  356. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +189 -73
  357. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -16
  358. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +45 -21
  359. package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -1
  360. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +7 -16
  361. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +62 -5
  362. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +43 -26
  363. package/src/renderers/webgpu/utils/WebGPUUtils.js +19 -2
  364. package/src/renderers/webxr/WebXRManager.js +32 -25
  365. package/src/utils.js +33 -1
  366. package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
  367. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  368. package/examples/jsm/loaders/TiltLoader.js +0 -520
  369. package/examples/jsm/utils/GPUStatsPanel.js +0 -95
  370. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  371. package/src/nodes/accessors/CameraNode.js +0 -19
  372. package/src/nodes/accessors/NormalNode.js +0 -14
  373. package/src/nodes/accessors/PositionNode.js +0 -10
  374. package/src/nodes/accessors/ReflectVectorNode.js +0 -10
  375. package/src/nodes/accessors/TangentNode.js +0 -23
  376. package/src/nodes/core/NodeKeywords.js +0 -80
  377. package/src/nodes/display/BlendModeNode.js +0 -128
  378. package/src/nodes/display/ColorAdjustmentNode.js +0 -104
  379. package/src/nodes/display/ViewportNode.js +0 -137
  380. package/src/nodes/lighting/LightNode.js +0 -57
  381. package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
  382. package/src/nodes/math/HashNode.js +0 -34
  383. package/src/nodes/procedural/CheckerNode.js +0 -42
  384. package/src/nodes/utils/DiscardNode.js +0 -28
  385. package/src/nodes/utils/PackingNode.js +0 -55
  386. package/src/nodes/utils/RotateUVNode.js +0 -35
  387. /package/src/nodes/accessors/{UVNode.js → UV.js} +0 -0
@@ -0,0 +1,105 @@
1
+ import NodeLibrary from '../../common/nodes/NodeLibrary.js';
2
+
3
+ // Materials
4
+ import { MeshPhongMaterial } from '../../../materials/MeshPhongMaterial.js';
5
+ import MeshPhongNodeMaterial from '../../../materials/nodes/MeshPhongNodeMaterial.js';
6
+ import { MeshStandardMaterial } from '../../../materials/MeshStandardMaterial.js';
7
+ import MeshStandardNodeMaterial from '../../../materials/nodes/MeshStandardNodeMaterial.js';
8
+ import { MeshPhysicalMaterial } from '../../../materials/MeshPhysicalMaterial.js';
9
+ import MeshPhysicalNodeMaterial from '../../../materials/nodes/MeshPhysicalNodeMaterial.js';
10
+ import { MeshToonMaterial } from '../../../materials/MeshToonMaterial.js';
11
+ import MeshToonNodeMaterial from '../../../materials/nodes/MeshToonNodeMaterial.js';
12
+ import { MeshBasicMaterial } from '../../../materials/MeshBasicMaterial.js';
13
+ import MeshBasicNodeMaterial from '../../../materials/nodes/MeshBasicNodeMaterial.js';
14
+ import { MeshLambertMaterial } from '../../../materials/MeshLambertMaterial.js';
15
+ import MeshLambertNodeMaterial from '../../../materials/nodes/MeshLambertNodeMaterial.js';
16
+ import { MeshNormalMaterial } from '../../../materials/MeshNormalMaterial.js';
17
+ import MeshNormalNodeMaterial from '../../../materials/nodes/MeshNormalNodeMaterial.js';
18
+ import { MeshMatcapMaterial } from '../../../materials/MeshMatcapMaterial.js';
19
+ import MeshMatcapNodeMaterial from '../../../materials/nodes/MeshMatcapNodeMaterial.js';
20
+ import { LineBasicMaterial } from '../../../materials/LineBasicMaterial.js';
21
+ import LineBasicNodeMaterial from '../../../materials/nodes/LineBasicNodeMaterial.js';
22
+ import { LineDashedMaterial } from '../../../materials/LineDashedMaterial.js';
23
+ import LineDashedNodeMaterial from '../../../materials/nodes/LineDashedNodeMaterial.js';
24
+ import { PointsMaterial } from '../../../materials/PointsMaterial.js';
25
+ import PointsNodeMaterial from '../../../materials/nodes/PointsNodeMaterial.js';
26
+ import { SpriteMaterial } from '../../../materials/SpriteMaterial.js';
27
+ import SpriteNodeMaterial from '../../../materials/nodes/SpriteNodeMaterial.js';
28
+ import { ShadowMaterial } from '../../../materials/ShadowMaterial.js';
29
+ import ShadowNodeMaterial from '../../../materials/nodes/ShadowNodeMaterial.js';
30
+ //import { MeshDepthMaterial } from '../../../materials/MeshDepthMaterial.js';
31
+ //import MeshDepthNodeMaterial from '../../../materials/nodes/MeshDepthNodeMaterial.js';
32
+ //import { MeshDistanceMaterial } from '../../../materials/MeshDistanceMaterial.js';
33
+ //import MeshDistanceNodeMaterial from '../../../materials/nodes/MeshDistanceNodeMaterial.js';
34
+
35
+ // Lights
36
+ import { PointLight } from '../../../lights/PointLight.js';
37
+ import { PointLightNode } from '../../../nodes/Nodes.js';
38
+ import { DirectionalLight } from '../../../lights/DirectionalLight.js';
39
+ import { DirectionalLightNode } from '../../../nodes/Nodes.js';
40
+ import { RectAreaLight } from '../../../lights/RectAreaLight.js';
41
+ import { RectAreaLightNode } from '../../../nodes/Nodes.js';
42
+ import { SpotLight } from '../../../lights/SpotLight.js';
43
+ import { SpotLightNode } from '../../../nodes/Nodes.js';
44
+ import { AmbientLight } from '../../../lights/AmbientLight.js';
45
+ import { AmbientLightNode } from '../../../nodes/Nodes.js';
46
+ import { HemisphereLight } from '../../../lights/HemisphereLight.js';
47
+ import { HemisphereLightNode } from '../../../nodes/Nodes.js';
48
+ import { LightProbe } from '../../../lights/LightProbe.js';
49
+ import { LightProbeNode } from '../../../nodes/Nodes.js';
50
+ import IESSpotLight from '../../../lights/webgpu/IESSpotLight.js';
51
+ import { IESSpotLightNode } from '../../../nodes/Nodes.js';
52
+
53
+ // Tone Mapping
54
+ import { LinearToneMapping, ReinhardToneMapping, CineonToneMapping, ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping } from '../../../constants.js';
55
+ import { linearToneMapping, reinhardToneMapping, cineonToneMapping, acesFilmicToneMapping, agxToneMapping, neutralToneMapping } from '../../../nodes/display/ToneMappingFunctions.js';
56
+
57
+ // Color Space
58
+ import { LinearSRGBColorSpace, SRGBColorSpace } from '../../../constants.js';
59
+ import { linearSRGBTosRGB, sRGBToLinearSRGB } from '../../../nodes/display/ColorSpaceFunctions.js';
60
+ import { getColorSpaceMethod } from '../../../nodes/display/ColorSpaceNode.js';
61
+
62
+ class StandardNodeLibrary extends NodeLibrary {
63
+
64
+ constructor() {
65
+
66
+ super();
67
+
68
+ this.addMaterial( MeshPhongNodeMaterial, MeshPhongMaterial );
69
+ this.addMaterial( MeshStandardNodeMaterial, MeshStandardMaterial );
70
+ this.addMaterial( MeshPhysicalNodeMaterial, MeshPhysicalMaterial );
71
+ this.addMaterial( MeshToonNodeMaterial, MeshToonMaterial );
72
+ this.addMaterial( MeshBasicNodeMaterial, MeshBasicMaterial );
73
+ this.addMaterial( MeshLambertNodeMaterial, MeshLambertMaterial );
74
+ this.addMaterial( MeshNormalNodeMaterial, MeshNormalMaterial );
75
+ this.addMaterial( MeshMatcapNodeMaterial, MeshMatcapMaterial );
76
+ this.addMaterial( LineBasicNodeMaterial, LineBasicMaterial );
77
+ this.addMaterial( LineDashedNodeMaterial, LineDashedMaterial );
78
+ this.addMaterial( PointsNodeMaterial, PointsMaterial );
79
+ this.addMaterial( SpriteNodeMaterial, SpriteMaterial );
80
+ this.addMaterial( ShadowNodeMaterial, ShadowMaterial );
81
+
82
+ this.addLight( PointLightNode, PointLight );
83
+ this.addLight( DirectionalLightNode, DirectionalLight );
84
+ this.addLight( RectAreaLightNode, RectAreaLight );
85
+ this.addLight( SpotLightNode, SpotLight );
86
+ this.addLight( AmbientLightNode, AmbientLight );
87
+ this.addLight( HemisphereLightNode, HemisphereLight );
88
+ this.addLight( LightProbeNode, LightProbe );
89
+ this.addLight( IESSpotLightNode, IESSpotLight );
90
+
91
+ this.addToneMapping( linearToneMapping, LinearToneMapping );
92
+ this.addToneMapping( reinhardToneMapping, ReinhardToneMapping );
93
+ this.addToneMapping( cineonToneMapping, CineonToneMapping );
94
+ this.addToneMapping( acesFilmicToneMapping, ACESFilmicToneMapping );
95
+ this.addToneMapping( agxToneMapping, AgXToneMapping );
96
+ this.addToneMapping( neutralToneMapping, NeutralToneMapping );
97
+
98
+ this.addColorSpace( linearSRGBTosRGB, getColorSpaceMethod( LinearSRGBColorSpace, SRGBColorSpace ) );
99
+ this.addColorSpace( sRGBToLinearSRGB, getColorSpaceMethod( SRGBColorSpace, LinearSRGBColorSpace ) );
100
+
101
+ }
102
+
103
+ }
104
+
105
+ export default StandardNodeLibrary;
@@ -31,7 +31,7 @@ const supports = {
31
31
  };
32
32
 
33
33
  const wgslFnOpLib = {
34
- '^^': 'threejs_xor'
34
+ '^^': 'tsl_xor'
35
35
  };
36
36
 
37
37
  const wgslTypeLib = {
@@ -72,55 +72,18 @@ const wgslTypeLib = {
72
72
  bmat4: 'mat4x4<bool>'
73
73
  };
74
74
 
75
- const wgslMethods = {
76
- dFdx: 'dpdx',
77
- dFdy: '- dpdy',
78
- mod_float: 'threejs_mod_float',
79
- mod_vec2: 'threejs_mod_vec2',
80
- mod_vec3: 'threejs_mod_vec3',
81
- mod_vec4: 'threejs_mod_vec4',
82
- equals_bool: 'threejs_equals_bool',
83
- equals_bvec2: 'threejs_equals_bvec2',
84
- equals_bvec3: 'threejs_equals_bvec3',
85
- equals_bvec4: 'threejs_equals_bvec4',
86
- lessThanEqual: 'threejs_lessThanEqual',
87
- greaterThan: 'threejs_greaterThan',
88
- inversesqrt: 'inverseSqrt',
89
- bitcast: 'bitcast<f32>'
90
- };
91
-
92
75
  const wgslPolyfill = {
93
- threejs_xor: new CodeNode( `
94
- fn threejs_xor( a : bool, b : bool ) -> bool {
95
-
96
- return ( a || b ) && !( a && b );
97
-
98
- }
99
- ` ),
100
- lessThanEqual: new CodeNode( `
101
- fn threejs_lessThanEqual( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
102
-
103
- return vec3<bool>( a.x <= b.x, a.y <= b.y, a.z <= b.z );
104
-
105
- }
106
- ` ),
107
- greaterThan: new CodeNode( `
108
- fn threejs_greaterThan( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
109
-
110
- return vec3<bool>( a.x > b.x, a.y > b.y, a.z > b.z );
111
-
112
- }
113
- ` ),
114
- mod_float: new CodeNode( 'fn threejs_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }' ),
115
- mod_vec2: new CodeNode( 'fn threejs_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }' ),
116
- mod_vec3: new CodeNode( 'fn threejs_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }' ),
117
- mod_vec4: new CodeNode( 'fn threejs_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }' ),
118
- equals_bool: new CodeNode( 'fn threejs_equals_bool( a : bool, b : bool ) -> bool { return a == b; }' ),
119
- equals_bvec2: new CodeNode( 'fn threejs_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }' ),
120
- equals_bvec3: new CodeNode( 'fn threejs_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }' ),
121
- equals_bvec4: new CodeNode( 'fn threejs_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }' ),
76
+ tsl_xor: new CodeNode( 'fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }' ),
77
+ mod_float: new CodeNode( 'fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }' ),
78
+ mod_vec2: new CodeNode( 'fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }' ),
79
+ mod_vec3: new CodeNode( 'fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }' ),
80
+ mod_vec4: new CodeNode( 'fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }' ),
81
+ equals_bool: new CodeNode( 'fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }' ),
82
+ equals_bvec2: new CodeNode( 'fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }' ),
83
+ equals_bvec3: new CodeNode( 'fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }' ),
84
+ equals_bvec4: new CodeNode( 'fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }' ),
122
85
  repeatWrapping: new CodeNode( `
123
- fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
86
+ fn tsl_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
124
87
 
125
88
  let uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );
126
89
 
@@ -129,9 +92,10 @@ fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32>
129
92
  }
130
93
  ` ),
131
94
  biquadraticTexture: new CodeNode( `
132
- fn threejs_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {
95
+ fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {
133
96
 
134
- let res = vec2f( textureDimensions( map, level ) );
97
+ let iRes = vec2i( textureDimensions( map, level ) );
98
+ let res = vec2f( iRes );
135
99
 
136
100
  let uvScaled = coord * res;
137
101
  let uvWrapping = ( ( uvScaled % res ) + res ) % res;
@@ -142,10 +106,10 @@ fn threejs_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32
142
106
  let iuv = floor( uv );
143
107
  let f = fract( uv );
144
108
 
145
- let rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ), level );
146
- let rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ), level );
147
- let rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ), level );
148
- let rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ), level );
109
+ let rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );
110
+ let rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );
111
+ let rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );
112
+ let rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );
149
113
 
150
114
  return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
151
115
 
@@ -153,6 +117,49 @@ fn threejs_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32
153
117
  ` )
154
118
  };
155
119
 
120
+ const wgslMethods = {
121
+ dFdx: 'dpdx',
122
+ dFdy: '- dpdy',
123
+ mod_float: 'tsl_mod_float',
124
+ mod_vec2: 'tsl_mod_vec2',
125
+ mod_vec3: 'tsl_mod_vec3',
126
+ mod_vec4: 'tsl_mod_vec4',
127
+ equals_bool: 'tsl_equals_bool',
128
+ equals_bvec2: 'tsl_equals_bvec2',
129
+ equals_bvec3: 'tsl_equals_bvec3',
130
+ equals_bvec4: 'tsl_equals_bvec4',
131
+ inversesqrt: 'inverseSqrt',
132
+ bitcast: 'bitcast<f32>'
133
+ };
134
+
135
+ // WebGPU issue: does not support pow() with negative base on Windows
136
+
137
+ if ( /Windows/g.test( navigator.userAgent ) ) {
138
+
139
+ wgslPolyfill.pow_float = new CodeNode( 'fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }' );
140
+ wgslPolyfill.pow_vec2 = new CodeNode( 'fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }', [ wgslPolyfill.pow_float ] );
141
+ wgslPolyfill.pow_vec3 = new CodeNode( 'fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }', [ wgslPolyfill.pow_float ] );
142
+ wgslPolyfill.pow_vec4 = new CodeNode( 'fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }', [ wgslPolyfill.pow_float ] );
143
+
144
+ wgslMethods.pow_float = 'tsl_pow_float';
145
+ wgslMethods.pow_vec2 = 'tsl_pow_vec2';
146
+ wgslMethods.pow_vec3 = 'tsl_pow_vec3';
147
+ wgslMethods.pow_vec4 = 'tsl_pow_vec4';
148
+
149
+ }
150
+
151
+ //
152
+
153
+ let diagnostics = '';
154
+
155
+ if ( /Firefox/g.test( navigator.userAgent ) !== true ) {
156
+
157
+ diagnostics += 'diagnostic( off, derivative_uniformity );\n';
158
+
159
+ }
160
+
161
+ //
162
+
156
163
  class WGSLNodeBuilder extends NodeBuilder {
157
164
 
158
165
  constructor( object, renderer ) {
@@ -165,9 +172,11 @@ class WGSLNodeBuilder extends NodeBuilder {
165
172
 
166
173
  this.directives = {};
167
174
 
175
+ this.scopedArrays = new Map();
176
+
168
177
  }
169
178
 
170
- needsColorSpaceToLinear( texture ) {
179
+ needsToWorkingColorSpace( texture ) {
171
180
 
172
181
  return texture.isVideoTexture === true && texture.colorSpace !== NoColorSpace;
173
182
 
@@ -235,7 +244,7 @@ class WGSLNodeBuilder extends NodeBuilder {
235
244
 
236
245
  this._include( 'biquadraticTexture' );
237
246
 
238
- return `threejs_biquadraticTexture( ${ textureProperty }, ${ uvSnippet }, i32( ${ levelSnippet } ) )`;
247
+ return `tsl_biquadraticTexture( ${ textureProperty }, ${ uvSnippet }, i32( ${ levelSnippet } ) )`;
239
248
 
240
249
  }
241
250
 
@@ -245,7 +254,7 @@ class WGSLNodeBuilder extends NodeBuilder {
245
254
 
246
255
  const dimension = texture.isMultisampleRenderTargetTexture === true ? `textureDimensions( ${ textureProperty } )` : `textureDimensions( ${ textureProperty }, 0 )`;
247
256
 
248
- return `textureLoad( ${ textureProperty }, threejs_repeatWrapping( ${ uvSnippet }, ${ dimension } ), i32( ${ levelSnippet } ) )`;
257
+ return `textureLoad( ${ textureProperty }, tsl_repeatWrapping( ${ uvSnippet }, ${ dimension } ), i32( ${ levelSnippet } ) )`;
249
258
 
250
259
  }
251
260
 
@@ -271,7 +280,7 @@ class WGSLNodeBuilder extends NodeBuilder {
271
280
 
272
281
  isUnfilterable( texture ) {
273
282
 
274
- return this.getComponentTypeFromTexture( texture ) !== 'float' || ( texture.isDataTexture === true && texture.type === FloatType ) || texture.isMultisampleRenderTargetTexture === true;
283
+ return this.getComponentTypeFromTexture( texture ) !== 'float' || ( ! this.isAvailable( 'float32Filterable' ) && texture.isDataTexture === true && texture.type === FloatType ) || texture.isMultisampleRenderTargetTexture === true;
275
284
 
276
285
  }
277
286
 
@@ -575,6 +584,12 @@ class WGSLNodeBuilder extends NodeBuilder {
575
584
 
576
585
  }
577
586
 
587
+ hasBuiltin( name, shaderStage = this.shaderStage ) {
588
+
589
+ return ( this.builtins[ shaderStage ] !== undefined && this.builtins[ shaderStage ].has( name ) );
590
+
591
+ }
592
+
578
593
  getVertexIndex() {
579
594
 
580
595
  if ( this.shaderStage === 'vertex' ) {
@@ -602,12 +617,18 @@ class WGSLNodeBuilder extends NodeBuilder {
602
617
 
603
618
  //
604
619
 
605
- const code = `fn ${ layout.name }( ${ parameters.join( ', ' ) } ) -> ${ this.getType( layout.type ) } {
620
+ let code = `fn ${ layout.name }( ${ parameters.join( ', ' ) } ) -> ${ this.getType( layout.type ) } {
606
621
  ${ flowData.vars }
607
622
  ${ flowData.code }
608
- return ${ flowData.result };
623
+ `;
624
+
625
+ if ( flowData.result ) {
626
+
627
+ code += `\treturn ${ flowData.result };\n`;
628
+
629
+ }
609
630
 
610
- }`;
631
+ code += '\n}\n';
611
632
 
612
633
  //
613
634
 
@@ -627,6 +648,36 @@ ${ flowData.code }
627
648
 
628
649
  }
629
650
 
651
+ getInvocationLocalIndex() {
652
+
653
+ return this.getBuiltin( 'local_invocation_index', 'invocationLocalIndex', 'u32', 'attribute' );
654
+
655
+ }
656
+
657
+ getSubgroupSize() {
658
+
659
+ this.enableSubGroups();
660
+
661
+ return this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' );
662
+
663
+ }
664
+
665
+ getInvocationSubgroupIndex() {
666
+
667
+ this.enableSubGroups();
668
+
669
+ return this.getBuiltin( 'subgroup_invocation_id', 'invocationSubgroupIndex', 'u32', 'attribute' );
670
+
671
+ }
672
+
673
+ getSubgroupIndex() {
674
+
675
+ this.enableSubGroups();
676
+
677
+ return this.getBuiltin( 'subgroup_id', 'subgroupIndex', 'u32', 'attribute' );
678
+
679
+ }
680
+
630
681
  getDrawIndex() {
631
682
 
632
683
  return null;
@@ -641,7 +692,7 @@ ${ flowData.code }
641
692
 
642
693
  getFragCoord() {
643
694
 
644
- return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xyz';
695
+ return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xy';
645
696
 
646
697
  }
647
698
 
@@ -659,8 +710,8 @@ ${ flowData.code }
659
710
 
660
711
  enableDirective( name, shaderStage = this.shaderStage ) {
661
712
 
662
- const stage = this.directives[ shaderStage ] || ( this.directives[ shaderStage ] = [] );
663
- stage.push( name );
713
+ const stage = this.directives[ shaderStage ] || ( this.directives[ shaderStage ] = new Set() );
714
+ stage.add( name );
664
715
 
665
716
  }
666
717
 
@@ -673,7 +724,7 @@ ${ flowData.code }
673
724
 
674
725
  for ( const directive of directives ) {
675
726
 
676
- snippets.push( `enable ${directive}` );
727
+ snippets.push( `enable ${directive};` );
677
728
 
678
729
  }
679
730
 
@@ -683,6 +734,18 @@ ${ flowData.code }
683
734
 
684
735
  }
685
736
 
737
+ enableSubGroups() {
738
+
739
+ this.enableDirective( 'subgroups' );
740
+
741
+ }
742
+
743
+ enableSubgroupsF16() {
744
+
745
+ this.enableDirective( 'subgroups-f16' );
746
+
747
+ }
748
+
686
749
  enableClipDistances() {
687
750
 
688
751
  this.enableDirective( 'clip_distances' );
@@ -720,6 +783,45 @@ ${ flowData.code }
720
783
 
721
784
  }
722
785
 
786
+ getScopedArray( name, scope, bufferType, bufferCount ) {
787
+
788
+ if ( this.scopedArrays.has( name ) === false ) {
789
+
790
+ this.scopedArrays.set( name, {
791
+ name,
792
+ scope,
793
+ bufferType,
794
+ bufferCount
795
+ } );
796
+
797
+ }
798
+
799
+ return name;
800
+
801
+ }
802
+
803
+ getScopedArrays( shaderStage ) {
804
+
805
+ if ( shaderStage !== 'compute' ) {
806
+
807
+ return;
808
+
809
+ }
810
+
811
+ const snippets = [];
812
+
813
+ for ( const { name, scope, bufferType, bufferCount } of this.scopedArrays.values() ) {
814
+
815
+ const type = this.getType( bufferType );
816
+
817
+ snippets.push( `var<${scope}> ${name}: array< ${type}, ${bufferCount} >;` );
818
+
819
+ }
820
+
821
+ return snippets.join( '\n' );
822
+
823
+ }
824
+
723
825
  getAttributes( shaderStage ) {
724
826
 
725
827
  const snippets = [];
@@ -731,6 +833,13 @@ ${ flowData.code }
731
833
  this.getBuiltin( 'local_invocation_id', 'localId', 'vec3<u32>', 'attribute' );
732
834
  this.getBuiltin( 'num_workgroups', 'numWorkgroups', 'vec3<u32>', 'attribute' );
733
835
 
836
+ if ( this.renderer.hasFeature( 'subgroups' ) ) {
837
+
838
+ this.enableDirective( 'subgroups', shaderStage );
839
+ this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' );
840
+
841
+ }
842
+
734
843
  }
735
844
 
736
845
  if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
@@ -771,7 +880,7 @@ ${ flowData.code }
771
880
 
772
881
  const builtins = this.getBuiltins( 'output' );
773
882
 
774
- if ( builtins ) snippets.push( builtins );
883
+ if ( builtins ) snippets.push( '\t' + builtins );
775
884
 
776
885
  return snippets.join( ',\n' );
777
886
 
@@ -890,8 +999,8 @@ ${ flowData.code }
890
999
 
891
1000
  for ( const uniform of uniforms ) {
892
1001
 
893
- const groundName = uniform.groupNode.name;
894
- const uniformIndexes = this.bindingsIndexes[ groundName ];
1002
+ const groupName = uniform.groupNode.name;
1003
+ const uniformIndexes = this.bindingsIndexes[ groupName ];
895
1004
 
896
1005
  if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
897
1006
 
@@ -925,7 +1034,7 @@ ${ flowData.code }
925
1034
 
926
1035
  textureType = 'texture_cube<f32>';
927
1036
 
928
- } else if ( texture.isDataArrayTexture === true ) {
1037
+ } else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
929
1038
 
930
1039
  textureType = 'texture_2d_array<f32>';
931
1040
 
@@ -965,7 +1074,8 @@ ${ flowData.code }
965
1074
  const bufferCount = bufferNode.bufferCount;
966
1075
 
967
1076
  const bufferCountSnippet = bufferCount > 0 ? ', ' + bufferCount : '';
968
- const bufferSnippet = `\t${ uniform.name } : array< ${ bufferType }${ bufferCountSnippet } >\n`;
1077
+ const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`;
1078
+ const bufferSnippet = `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`;
969
1079
  const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform';
970
1080
 
971
1081
  bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) );
@@ -1007,6 +1117,8 @@ ${ flowData.code }
1007
1117
 
1008
1118
  const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
1009
1119
 
1120
+ this.sortBindingGroups();
1121
+
1010
1122
  for ( const shaderStage in shadersData ) {
1011
1123
 
1012
1124
  const stageData = shadersData[ shaderStage ];
@@ -1017,6 +1129,7 @@ ${ flowData.code }
1017
1129
  stageData.vars = this.getVars( shaderStage );
1018
1130
  stageData.codes = this.getCodes( shaderStage );
1019
1131
  stageData.directives = this.getDirectives( shaderStage );
1132
+ stageData.scopedArrays = this.getScopedArrays( shaderStage );
1020
1133
 
1021
1134
  //
1022
1135
 
@@ -1177,7 +1290,7 @@ ${ flowData.code }
1177
1290
 
1178
1291
  return `${ this.getSignature() }
1179
1292
  // directives
1180
- ${shaderData.directives};
1293
+ ${shaderData.directives}
1181
1294
 
1182
1295
  // uniforms
1183
1296
  ${shaderData.uniforms}
@@ -1208,8 +1321,8 @@ fn main( ${shaderData.attributes} ) -> VaryingsStruct {
1208
1321
  _getWGSLFragmentCode( shaderData ) {
1209
1322
 
1210
1323
  return `${ this.getSignature() }
1211
-
1212
- diagnostic( off, derivative_uniformity );
1324
+ // global
1325
+ ${ diagnostics }
1213
1326
 
1214
1327
  // uniforms
1215
1328
  ${shaderData.uniforms}
@@ -1243,6 +1356,9 @@ ${shaderData.directives}
1243
1356
  // system
1244
1357
  var<private> instanceIndex : u32;
1245
1358
 
1359
+ // locals
1360
+ ${shaderData.scopedArrays}
1361
+
1246
1362
  // uniforms
1247
1363
  ${shaderData.uniforms}
1248
1364
 
@@ -224,22 +224,12 @@ class WebGPUAttributeUtils {
224
224
  const bufferGPU = data.buffer;
225
225
  const size = bufferGPU.size;
226
226
 
227
- let readBufferGPU = data.readBuffer;
228
- let needsUnmap = true;
227
+ const readBufferGPU = device.createBuffer( {
228
+ label: attribute.name,
229
+ size,
230
+ usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
231
+ } );
229
232
 
230
- if ( readBufferGPU === undefined ) {
231
-
232
- readBufferGPU = device.createBuffer( {
233
- label: attribute.name,
234
- size,
235
- usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
236
- } );
237
-
238
- needsUnmap = false;
239
-
240
- data.readBuffer = readBufferGPU;
241
-
242
- }
243
233
 
244
234
  const cmdEncoder = device.createCommandEncoder( {} );
245
235
 
@@ -251,7 +241,7 @@ class WebGPUAttributeUtils {
251
241
  size
252
242
  );
253
243
 
254
- if ( needsUnmap ) readBufferGPU.unmap();
244
+ readBufferGPU.unmap();
255
245
 
256
246
  const gpuCommands = cmdEncoder.finish();
257
247
  device.queue.submit( [ gpuCommands ] );