@plastic-software/three 0.167.4 → 0.174.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 (747) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +36217 -23964
  4. package/build/three.core.js +48830 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +10175 -46744
  7. package/build/three.module.min.js +2 -3
  8. package/build/three.tsl.js +550 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +44348 -50671
  11. package/build/three.webgpu.min.js +2 -3
  12. package/build/three.webgpu.nodes.js +70301 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/jsm/Addons.js +3 -15
  15. package/examples/jsm/animation/AnimationClipCreator.js +1 -1
  16. package/examples/jsm/animation/CCDIKSolver.js +61 -11
  17. package/examples/jsm/capabilities/WebGL.js +27 -21
  18. package/examples/jsm/capabilities/WebGPU.js +1 -10
  19. package/examples/jsm/controls/ArcballControls.js +262 -231
  20. package/examples/jsm/controls/DragControls.js +1 -1
  21. package/examples/jsm/controls/FirstPersonControls.js +175 -163
  22. package/examples/jsm/controls/FlyControls.js +194 -188
  23. package/examples/jsm/controls/OrbitControls.js +801 -777
  24. package/examples/jsm/controls/PointerLockControls.js +26 -20
  25. package/examples/jsm/controls/TrackballControls.js +469 -448
  26. package/examples/jsm/controls/TransformControls.js +119 -68
  27. package/examples/jsm/csm/CSM.js +2 -2
  28. package/examples/jsm/csm/CSMFrustum.js +7 -4
  29. package/examples/jsm/csm/CSMHelper.js +2 -0
  30. package/examples/jsm/csm/CSMShadowNode.js +442 -0
  31. package/examples/jsm/curves/NURBSCurve.js +33 -2
  32. package/examples/jsm/curves/NURBSUtils.js +3 -0
  33. package/examples/jsm/effects/AnaglyphEffect.js +6 -13
  34. package/examples/jsm/effects/OutlineEffect.js +1 -1
  35. package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
  36. package/examples/jsm/effects/StereoEffect.js +6 -1
  37. package/examples/jsm/exporters/DRACOExporter.js +4 -2
  38. package/examples/jsm/exporters/EXRExporter.js +19 -11
  39. package/examples/jsm/exporters/GLTFExporter.js +181 -109
  40. package/examples/jsm/exporters/KTX2Exporter.js +54 -23
  41. package/examples/jsm/exporters/OBJExporter.js +5 -1
  42. package/examples/jsm/exporters/PLYExporter.js +11 -9
  43. package/examples/jsm/exporters/USDZExporter.js +50 -11
  44. package/examples/jsm/geometries/DecalGeometry.js +73 -21
  45. package/examples/jsm/geometries/TextGeometry.js +1 -12
  46. package/examples/jsm/helpers/LightProbeHelper.js +43 -44
  47. package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
  48. package/examples/jsm/helpers/TextureHelperGPU.js +185 -0
  49. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  50. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  51. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  52. package/examples/jsm/interactive/SelectionHelper.js +3 -1
  53. package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
  54. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  55. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  56. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  57. package/examples/jsm/lighting/TiledLighting.js +18 -0
  58. package/examples/jsm/lights/LightProbeGenerator.js +26 -12
  59. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  60. package/examples/jsm/lines/LineGeometry.js +25 -0
  61. package/examples/jsm/lines/LineMaterial.js +0 -1
  62. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  63. package/examples/jsm/lines/webgpu/Line2.js +2 -1
  64. package/examples/jsm/lines/webgpu/LineSegments2.js +16 -21
  65. package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
  66. package/examples/jsm/loaders/3DMLoader.js +1 -0
  67. package/examples/jsm/loaders/3MFLoader.js +104 -2
  68. package/examples/jsm/loaders/BVHLoader.js +1 -1
  69. package/examples/jsm/loaders/ColladaLoader.js +15 -12
  70. package/examples/jsm/loaders/DDSLoader.js +42 -0
  71. package/examples/jsm/loaders/DRACOLoader.js +3 -1
  72. package/examples/jsm/loaders/FBXLoader.js +71 -22
  73. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  74. package/examples/jsm/loaders/GLTFLoader.js +29 -14
  75. package/examples/jsm/loaders/KTX2Loader.js +160 -58
  76. package/examples/jsm/loaders/KTXLoader.js +4 -4
  77. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  78. package/examples/jsm/loaders/LottieLoader.js +2 -1
  79. package/examples/jsm/loaders/MTLLoader.js +27 -7
  80. package/examples/jsm/loaders/MaterialXLoader.js +40 -14
  81. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  82. package/examples/jsm/loaders/OBJLoader.js +5 -3
  83. package/examples/jsm/loaders/PCDLoader.js +14 -13
  84. package/examples/jsm/loaders/PDBLoader.js +3 -2
  85. package/examples/jsm/loaders/PLYLoader.js +15 -12
  86. package/examples/jsm/loaders/PVRLoader.js +1 -1
  87. package/examples/jsm/loaders/STLLoader.js +3 -2
  88. package/examples/jsm/loaders/SVGLoader.js +2 -2
  89. package/examples/jsm/loaders/TDSLoader.js +17 -18
  90. package/examples/jsm/loaders/VRMLLoader.js +17 -17
  91. package/examples/jsm/loaders/VTKLoader.js +4 -3
  92. package/examples/jsm/loaders/XYZLoader.js +3 -2
  93. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  94. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  95. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  96. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  97. package/examples/jsm/math/ColorSpaces.js +76 -0
  98. package/examples/jsm/math/ConvexHull.js +1 -1
  99. package/examples/jsm/math/OBB.js +17 -0
  100. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  101. package/examples/jsm/misc/ProgressiveLightMap.js +54 -41
  102. package/examples/jsm/misc/ProgressiveLightMapGPU.js +294 -0
  103. package/examples/jsm/misc/Timer.js +27 -12
  104. package/examples/jsm/misc/Volume.js +28 -18
  105. package/examples/jsm/misc/VolumeSlice.js +19 -16
  106. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  107. package/examples/jsm/modifiers/CurveModifierGPU.js +235 -0
  108. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  109. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  110. package/examples/jsm/objects/LensflareMesh.js +324 -0
  111. package/examples/jsm/objects/Reflector.js +5 -2
  112. package/examples/jsm/objects/Sky.js +2 -2
  113. package/examples/jsm/objects/SkyMesh.js +14 -14
  114. package/examples/jsm/objects/Water2.js +1 -1
  115. package/examples/jsm/objects/Water2Mesh.js +11 -9
  116. package/examples/jsm/objects/WaterMesh.js +38 -33
  117. package/examples/jsm/physics/JoltPhysics.js +8 -8
  118. package/examples/jsm/physics/RapierPhysics.js +5 -5
  119. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  120. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  121. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  122. package/examples/jsm/postprocessing/OutlinePass.js +37 -51
  123. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  124. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  125. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  126. package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
  127. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  128. package/examples/jsm/postprocessing/SSRPass.js +8 -4
  129. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  130. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  131. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  132. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  133. package/examples/jsm/shaders/BokehShader2.js +1 -1
  134. package/examples/jsm/shaders/FXAAShader.js +225 -224
  135. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  136. package/examples/jsm/shaders/OutputShader.js +6 -2
  137. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  138. package/examples/jsm/transpiler/AST.js +12 -2
  139. package/examples/jsm/transpiler/GLSLDecoder.js +77 -31
  140. package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -3
  141. package/examples/jsm/transpiler/TSLEncoder.js +96 -21
  142. package/examples/jsm/tsl/display/AfterImageNode.js +243 -0
  143. package/examples/jsm/tsl/display/AnaglyphPassNode.js +106 -0
  144. package/examples/jsm/tsl/display/AnamorphicNode.js +257 -0
  145. package/{src/nodes/display/BleachBypassNode.js → examples/jsm/tsl/display/BleachBypass.js} +11 -6
  146. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +252 -67
  147. package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
  148. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +92 -14
  149. package/examples/jsm/tsl/display/DotScreenNode.js +103 -0
  150. package/examples/jsm/tsl/display/FXAANode.js +364 -0
  151. package/examples/jsm/tsl/display/FilmNode.js +100 -0
  152. package/examples/jsm/tsl/display/GTAONode.js +521 -0
  153. package/examples/jsm/tsl/display/GaussianBlurNode.js +393 -0
  154. package/examples/jsm/tsl/display/LensflareNode.js +278 -0
  155. package/examples/jsm/tsl/display/Lut3DNode.js +108 -0
  156. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  157. package/examples/jsm/tsl/display/OutlineNode.js +750 -0
  158. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +88 -0
  159. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +160 -28
  160. package/examples/jsm/tsl/display/RGBShiftNode.js +95 -0
  161. package/examples/jsm/tsl/display/SMAANode.js +767 -0
  162. package/examples/jsm/tsl/display/SSAAPassNode.js +357 -0
  163. package/examples/jsm/tsl/display/SSRNode.js +538 -0
  164. package/examples/jsm/tsl/display/Sepia.js +24 -0
  165. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +66 -20
  166. package/examples/jsm/tsl/display/StereoCompositePassNode.js +184 -0
  167. package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
  168. package/examples/jsm/tsl/display/TRAAPassNode.js +451 -0
  169. package/examples/jsm/tsl/display/TransitionNode.js +140 -0
  170. package/examples/jsm/tsl/display/hashBlur.js +34 -0
  171. package/examples/jsm/tsl/lighting/TiledLightsNode.js +395 -0
  172. package/examples/jsm/tsl/math/Bayer.js +18 -0
  173. package/examples/jsm/tsl/utils/Raymarching.js +65 -0
  174. package/examples/jsm/utils/BufferGeometryUtils.js +2 -2
  175. package/examples/jsm/utils/CameraUtils.js +4 -1
  176. package/examples/jsm/utils/GeometryCompressionUtils.js +38 -123
  177. package/examples/jsm/utils/GeometryUtils.js +22 -19
  178. package/examples/jsm/utils/SceneOptimizer.js +410 -0
  179. package/examples/jsm/utils/SceneUtils.js +2 -2
  180. package/examples/jsm/utils/ShadowMapViewer.js +3 -8
  181. package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
  182. package/examples/jsm/utils/SkeletonUtils.js +84 -66
  183. package/examples/jsm/utils/UVsDebug.js +1 -1
  184. package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +1 -0
  185. package/examples/jsm/utils/WebGPUTextureUtils.js +64 -0
  186. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  187. package/examples/jsm/webxr/Text2D.js +6 -6
  188. package/examples/jsm/webxr/XRControllerModelFactory.js +7 -2
  189. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  190. package/package.json +14 -9
  191. package/src/Three.Core.js +182 -0
  192. package/src/Three.Legacy.js +0 -21
  193. package/src/Three.TSL.js +543 -0
  194. package/src/Three.WebGPU.Nodes.js +23 -0
  195. package/src/Three.WebGPU.js +13 -184
  196. package/src/Three.js +1 -176
  197. package/src/animation/AnimationClip.js +2 -2
  198. package/src/animation/AnimationObjectGroup.js +2 -2
  199. package/src/animation/AnimationUtils.js +1 -1
  200. package/src/animation/PropertyBinding.js +2 -2
  201. package/src/audio/Audio.js +379 -2
  202. package/src/audio/AudioAnalyser.js +58 -1
  203. package/src/audio/AudioContext.js +15 -0
  204. package/src/audio/AudioListener.js +76 -0
  205. package/src/audio/PositionalAudio.js +107 -0
  206. package/src/cameras/ArrayCamera.js +29 -0
  207. package/src/cameras/Camera.js +47 -0
  208. package/src/cameras/CubeCamera.js +66 -0
  209. package/src/cameras/OrthographicCamera.js +109 -0
  210. package/src/cameras/PerspectiveCamera.js +173 -34
  211. package/src/cameras/StereoCamera.js +48 -2
  212. package/src/constants.js +6 -6
  213. package/src/core/BufferAttribute.js +4 -9
  214. package/src/core/BufferGeometry.js +48 -8
  215. package/src/core/Clock.js +1 -1
  216. package/src/core/EventDispatcher.js +52 -8
  217. package/src/core/InterleavedBuffer.js +4 -13
  218. package/src/core/Object3D.js +573 -3
  219. package/src/core/RenderTarget.js +22 -4
  220. package/src/core/RenderTarget3D.js +22 -0
  221. package/src/core/RenderTargetArray.js +22 -0
  222. package/src/extras/Controls.js +104 -0
  223. package/src/extras/DataUtils.js +48 -8
  224. package/src/extras/Earcut.js +18 -7
  225. package/src/extras/ImageUtils.js +18 -11
  226. package/src/extras/PMREMGenerator.js +40 -9
  227. package/src/extras/ShapeUtils.js +24 -2
  228. package/src/extras/TextureUtils.js +96 -10
  229. package/src/extras/core/Curve.js +153 -53
  230. package/src/extras/core/CurvePath.js +63 -22
  231. package/src/extras/core/Interpolations.js +29 -3
  232. package/src/extras/core/Path.js +134 -1
  233. package/src/extras/core/Shape.js +66 -3
  234. package/src/extras/core/ShapePath.js +76 -0
  235. package/src/extras/curves/ArcCurve.js +22 -0
  236. package/src/extras/curves/CatmullRomCurve3.js +89 -18
  237. package/src/extras/curves/CubicBezierCurve.js +67 -0
  238. package/src/extras/curves/CubicBezierCurve3.js +50 -0
  239. package/src/extras/curves/EllipseCurve.js +102 -0
  240. package/src/extras/curves/LineCurve.js +36 -0
  241. package/src/extras/curves/LineCurve3.js +36 -0
  242. package/src/extras/curves/QuadraticBezierCurve.js +59 -0
  243. package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
  244. package/src/extras/curves/SplineCurve.js +48 -0
  245. package/src/geometries/BoxGeometry.js +38 -0
  246. package/src/geometries/CapsuleGeometry.js +34 -0
  247. package/src/geometries/CircleGeometry.js +40 -0
  248. package/src/geometries/ConeGeometry.js +38 -0
  249. package/src/geometries/CylinderGeometry.js +50 -4
  250. package/src/geometries/DodecahedronGeometry.js +32 -0
  251. package/src/geometries/EdgesGeometry.js +30 -2
  252. package/src/geometries/ExtrudeGeometry.js +52 -0
  253. package/src/geometries/IcosahedronGeometry.js +32 -0
  254. package/src/geometries/LatheGeometry.js +43 -3
  255. package/src/geometries/OctahedronGeometry.js +32 -0
  256. package/src/geometries/PlaneGeometry.js +34 -0
  257. package/src/geometries/PolyhedronGeometry.js +29 -0
  258. package/src/geometries/RingGeometry.js +36 -0
  259. package/src/geometries/ShapeGeometry.js +37 -0
  260. package/src/geometries/SphereGeometry.js +37 -0
  261. package/src/geometries/TetrahedronGeometry.js +32 -0
  262. package/src/geometries/TorusGeometry.js +35 -0
  263. package/src/geometries/TorusKnotGeometry.js +38 -0
  264. package/src/geometries/TubeGeometry.js +49 -0
  265. package/src/geometries/WireframeGeometry.js +32 -0
  266. package/src/helpers/ArrowHelper.js +60 -3
  267. package/src/helpers/AxesHelper.js +28 -0
  268. package/src/helpers/Box3Helper.js +28 -0
  269. package/src/helpers/BoxHelper.js +43 -7
  270. package/src/helpers/CameraHelper.js +61 -18
  271. package/src/helpers/DirectionalLightHelper.js +52 -0
  272. package/src/helpers/GridHelper.js +26 -0
  273. package/src/helpers/HemisphereLightHelper.js +39 -0
  274. package/src/helpers/PlaneHelper.js +33 -0
  275. package/src/helpers/PointLightHelper.js +43 -0
  276. package/src/helpers/PolarGridHelper.js +30 -0
  277. package/src/helpers/SkeletonHelper.js +39 -2
  278. package/src/helpers/SpotLightHelper.js +40 -0
  279. package/src/lights/AmbientLight.js +25 -0
  280. package/src/lights/DirectionalLight.js +57 -0
  281. package/src/lights/DirectionalLightShadow.js +15 -0
  282. package/src/lights/HemisphereLight.js +32 -0
  283. package/src/lights/Light.js +36 -0
  284. package/src/lights/LightProbe.js +43 -0
  285. package/src/lights/LightShadow.js +159 -0
  286. package/src/lights/PointLight.js +59 -0
  287. package/src/lights/PointLightShadow.js +21 -0
  288. package/src/lights/RectAreaLight.js +59 -0
  289. package/src/lights/SpotLight.js +102 -0
  290. package/src/lights/SpotLightShadow.js +24 -2
  291. package/src/lights/webgpu/IESSpotLight.js +21 -0
  292. package/src/loaders/Loader.js +132 -0
  293. package/src/loaders/MaterialLoader.js +7 -1
  294. package/src/loaders/nodes/NodeLoader.js +189 -0
  295. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  296. package/src/loaders/nodes/NodeObjectLoader.js +151 -0
  297. package/src/materials/LineDashedMaterial.js +0 -1
  298. package/src/materials/Material.js +469 -7
  299. package/src/materials/MeshPhongMaterial.js +1 -1
  300. package/src/materials/MeshPhysicalMaterial.js +2 -2
  301. package/src/materials/MeshStandardMaterial.js +2 -2
  302. package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +192 -82
  303. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  304. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  305. package/src/materials/nodes/MeshBasicNodeMaterial.js +133 -0
  306. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  307. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  308. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  309. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  310. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +517 -0
  311. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  312. package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
  313. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  314. package/src/materials/nodes/NodeMaterial.js +1180 -0
  315. package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -2
  316. package/src/materials/nodes/PointsNodeMaterial.js +153 -0
  317. package/src/materials/nodes/ShadowNodeMaterial.js +67 -0
  318. package/src/materials/nodes/SpriteNodeMaterial.js +198 -0
  319. package/src/materials/nodes/VolumeNodeMaterial.js +72 -0
  320. package/src/materials/nodes/manager/NodeMaterialObserver.js +509 -0
  321. package/src/math/Box2.js +177 -0
  322. package/src/math/Box3.js +243 -0
  323. package/src/math/Color.js +343 -0
  324. package/src/math/ColorManagement.js +143 -102
  325. package/src/math/Cylindrical.js +65 -6
  326. package/src/math/Euler.js +137 -4
  327. package/src/math/Frustum.js +83 -0
  328. package/src/math/Interpolant.js +87 -8
  329. package/src/math/Line3.js +96 -2
  330. package/src/math/MathUtils.js +182 -19
  331. package/src/math/Matrix2.js +70 -0
  332. package/src/math/Matrix3.js +229 -4
  333. package/src/math/Matrix4.js +368 -3
  334. package/src/math/Plane.js +164 -2
  335. package/src/math/Quaternion.js +265 -9
  336. package/src/math/Ray.js +160 -0
  337. package/src/math/Sphere.js +147 -0
  338. package/src/math/Spherical.js +73 -11
  339. package/src/math/SphericalHarmonics3.js +112 -14
  340. package/src/math/Triangle.js +230 -2
  341. package/src/math/Vector2.js +396 -10
  342. package/src/math/Vector3.js +550 -13
  343. package/src/math/Vector4.js +415 -9
  344. package/src/math/interpolants/CubicInterpolant.js +10 -1
  345. package/src/math/interpolants/DiscreteInterpolant.js +10 -2
  346. package/src/math/interpolants/LinearInterpolant.js +13 -0
  347. package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
  348. package/src/nodes/Nodes.js +84 -166
  349. package/src/nodes/TSL.js +167 -0
  350. package/src/nodes/accessors/AccessorsUtils.js +39 -10
  351. package/src/nodes/accessors/Arrays.js +68 -0
  352. package/src/nodes/accessors/BatchNode.js +93 -26
  353. package/src/nodes/accessors/Bitangent.js +54 -0
  354. package/src/nodes/accessors/BufferAttributeNode.js +189 -11
  355. package/src/nodes/accessors/BufferNode.js +70 -5
  356. package/src/nodes/accessors/BuiltinNode.js +63 -0
  357. package/src/nodes/accessors/Camera.js +129 -0
  358. package/src/nodes/accessors/ClippingNode.js +152 -43
  359. package/src/nodes/accessors/CubeTextureNode.js +76 -13
  360. package/src/nodes/accessors/InstanceNode.js +118 -35
  361. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  362. package/src/nodes/accessors/Lights.js +129 -0
  363. package/src/nodes/accessors/MaterialNode.js +394 -58
  364. package/src/nodes/accessors/MaterialProperties.js +57 -1
  365. package/src/nodes/accessors/MaterialReferenceNode.js +60 -18
  366. package/src/nodes/accessors/ModelNode.js +159 -12
  367. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -36
  368. package/src/nodes/accessors/MorphNode.js +60 -13
  369. package/src/nodes/accessors/Normal.js +156 -0
  370. package/src/nodes/accessors/Object3DNode.js +154 -35
  371. package/src/nodes/accessors/PointUVNode.js +35 -6
  372. package/src/nodes/accessors/Position.js +64 -0
  373. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  374. package/src/nodes/accessors/ReferenceNode.js +243 -6
  375. package/src/nodes/accessors/ReflectVector.js +36 -0
  376. package/src/nodes/accessors/RendererReferenceNode.js +57 -7
  377. package/src/nodes/accessors/SceneNode.js +98 -6
  378. package/src/nodes/accessors/SkinningNode.js +214 -21
  379. package/src/nodes/accessors/StorageBufferNode.js +288 -28
  380. package/src/nodes/accessors/StorageTextureNode.js +139 -12
  381. package/src/nodes/accessors/Tangent.js +62 -0
  382. package/src/nodes/accessors/Texture3DNode.js +98 -12
  383. package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +14 -34
  384. package/src/nodes/accessors/TextureNode.js +347 -34
  385. package/src/nodes/accessors/TextureSizeNode.js +51 -9
  386. package/src/nodes/accessors/UV.js +11 -0
  387. package/src/nodes/accessors/UniformArrayNode.js +241 -32
  388. package/src/nodes/accessors/UserDataNode.js +55 -7
  389. package/src/nodes/accessors/VelocityNode.js +223 -0
  390. package/src/nodes/accessors/VertexColorNode.js +45 -6
  391. package/src/nodes/code/CodeNode.js +108 -8
  392. package/src/nodes/code/ExpressionNode.js +38 -7
  393. package/src/nodes/code/FunctionCallNode.js +62 -11
  394. package/src/nodes/code/FunctionNode.js +54 -24
  395. package/src/nodes/code/ScriptableNode.js +241 -17
  396. package/src/nodes/code/ScriptableValueNode.js +93 -8
  397. package/src/nodes/core/ArrayNode.js +142 -0
  398. package/src/nodes/core/AssignNode.js +60 -12
  399. package/src/nodes/core/AttributeNode.js +55 -22
  400. package/src/nodes/core/BypassNode.js +59 -11
  401. package/src/nodes/core/CacheNode.js +64 -10
  402. package/src/nodes/core/ConstNode.js +38 -3
  403. package/src/nodes/core/ContextNode.js +87 -12
  404. package/src/nodes/core/IndexNode.js +102 -10
  405. package/src/nodes/core/InputNode.js +55 -3
  406. package/src/nodes/core/LightingModel.js +65 -5
  407. package/src/nodes/core/MRTNode.js +81 -7
  408. package/src/nodes/core/Node.js +368 -50
  409. package/src/nodes/core/NodeAttribute.js +38 -0
  410. package/src/nodes/core/NodeBuilder.js +1317 -83
  411. package/src/nodes/core/NodeCache.js +41 -2
  412. package/src/nodes/core/NodeCode.js +31 -0
  413. package/src/nodes/core/NodeFrame.js +123 -2
  414. package/src/nodes/core/NodeFunction.js +46 -0
  415. package/src/nodes/core/NodeFunctionInput.js +44 -0
  416. package/src/nodes/core/NodeParser.js +11 -0
  417. package/src/nodes/core/NodeUniform.js +52 -0
  418. package/src/nodes/core/NodeUtils.js +226 -6
  419. package/src/nodes/core/NodeVar.js +47 -1
  420. package/src/nodes/core/NodeVarying.js +28 -0
  421. package/src/nodes/core/OutputStructNode.js +61 -17
  422. package/src/nodes/core/ParameterNode.js +34 -4
  423. package/src/nodes/core/PropertyNode.js +296 -32
  424. package/src/nodes/core/StackNode.js +108 -8
  425. package/src/nodes/core/StructNode.js +120 -0
  426. package/src/nodes/core/StructType.js +13 -0
  427. package/src/nodes/core/StructTypeNode.js +116 -9
  428. package/src/nodes/core/TempNode.js +37 -7
  429. package/src/nodes/core/UniformGroupNode.js +98 -17
  430. package/src/nodes/core/UniformNode.js +72 -4
  431. package/src/nodes/core/VarNode.js +170 -13
  432. package/src/nodes/core/VaryingNode.js +109 -8
  433. package/src/nodes/core/constants.js +40 -0
  434. package/src/nodes/display/BlendModes.js +193 -0
  435. package/src/nodes/display/BumpMapNode.js +47 -10
  436. package/src/nodes/display/ColorAdjustment.js +141 -0
  437. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  438. package/src/nodes/display/ColorSpaceNode.js +147 -68
  439. package/src/nodes/display/FrontFacingNode.js +39 -6
  440. package/src/nodes/display/NormalMapNode.js +55 -13
  441. package/src/nodes/display/PassNode.js +420 -19
  442. package/src/nodes/display/PosterizeNode.js +40 -7
  443. package/src/nodes/display/RenderOutputNode.js +81 -13
  444. package/src/nodes/display/ScreenNode.js +286 -0
  445. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  446. package/src/nodes/display/ToneMappingNode.js +68 -175
  447. package/src/nodes/display/ToonOutlinePassNode.js +183 -0
  448. package/src/nodes/display/ViewportDepthNode.js +210 -36
  449. package/src/nodes/display/ViewportDepthTextureNode.js +32 -9
  450. package/src/nodes/display/ViewportSharedTextureNode.js +32 -9
  451. package/src/nodes/display/ViewportTextureNode.js +68 -11
  452. package/src/nodes/fog/Fog.js +113 -0
  453. package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
  454. package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
  455. package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
  456. package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
  457. package/src/nodes/functions/BSDF/D_GGX.js +2 -2
  458. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
  459. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  460. package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
  461. package/src/nodes/functions/BSDF/LTC.js +50 -6
  462. package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
  463. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
  464. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  465. package/src/nodes/functions/BasicLightingModel.js +27 -6
  466. package/src/nodes/functions/PhongLightingModel.js +38 -8
  467. package/src/nodes/functions/PhysicalLightingModel.js +215 -51
  468. package/src/nodes/functions/ShadowMaskModel.js +24 -1
  469. package/src/nodes/functions/ToonLightingModel.js +24 -5
  470. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  471. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  472. package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
  473. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  474. package/src/nodes/functions/material/getRoughness.js +2 -2
  475. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  476. package/src/nodes/geometry/RangeNode.js +62 -7
  477. package/src/nodes/gpgpu/AtomicFunctionNode.js +280 -0
  478. package/src/nodes/gpgpu/BarrierNode.js +89 -0
  479. package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
  480. package/src/nodes/gpgpu/ComputeNode.js +124 -9
  481. package/src/nodes/gpgpu/WorkgroupInfoNode.js +208 -0
  482. package/src/nodes/lighting/AONode.js +24 -3
  483. package/src/nodes/lighting/AmbientLightNode.js +16 -8
  484. package/src/nodes/lighting/AnalyticLightNode.js +151 -231
  485. package/src/nodes/lighting/BasicEnvironmentNode.js +25 -3
  486. package/src/nodes/lighting/BasicLightMapNode.js +25 -5
  487. package/src/nodes/lighting/DirectionalLightNode.js +19 -20
  488. package/src/nodes/lighting/EnvironmentNode.js +34 -17
  489. package/src/nodes/lighting/HemisphereLightNode.js +42 -11
  490. package/src/nodes/lighting/IESSpotLightNode.js +18 -9
  491. package/src/nodes/lighting/IrradianceNode.js +23 -3
  492. package/src/nodes/lighting/LightProbeNode.js +29 -36
  493. package/src/nodes/lighting/LightUtils.js +12 -4
  494. package/src/nodes/lighting/LightingContextNode.js +70 -21
  495. package/src/nodes/lighting/LightingNode.js +22 -9
  496. package/src/nodes/lighting/LightsNode.js +309 -86
  497. package/src/nodes/lighting/PointLightNode.js +66 -32
  498. package/src/nodes/lighting/PointShadowNode.js +306 -0
  499. package/src/nodes/lighting/RectAreaLightNode.js +61 -25
  500. package/src/nodes/lighting/ShadowBaseNode.js +92 -0
  501. package/src/nodes/lighting/ShadowNode.js +812 -0
  502. package/src/nodes/lighting/SpotLightNode.js +73 -31
  503. package/src/nodes/materialx/MaterialXNodes.js +2 -2
  504. package/src/nodes/materialx/lib/mx_hsv.js +27 -22
  505. package/src/nodes/materialx/lib/mx_noise.js +70 -70
  506. package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
  507. package/src/nodes/math/ConditionalNode.js +230 -0
  508. package/src/nodes/math/Hash.js +21 -0
  509. package/src/nodes/math/MathNode.js +812 -131
  510. package/src/nodes/math/MathUtils.js +47 -8
  511. package/src/nodes/math/OperatorNode.js +410 -66
  512. package/src/nodes/math/TriNoise3D.js +32 -32
  513. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  514. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  515. package/src/nodes/pmrem/PMREMNode.js +188 -28
  516. package/src/nodes/pmrem/PMREMUtils.js +24 -24
  517. package/src/nodes/procedural/Checker.js +22 -0
  518. package/src/nodes/shapes/Shapes.js +32 -0
  519. package/src/nodes/tsl/TSLBase.js +31 -0
  520. package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +114 -98
  521. package/src/nodes/utils/ArrayElementNode.js +45 -5
  522. package/src/nodes/utils/ConvertNode.js +39 -4
  523. package/src/nodes/utils/CubeMapNode.js +88 -8
  524. package/src/nodes/utils/Discard.js +24 -0
  525. package/src/nodes/utils/EquirectUVNode.js +39 -7
  526. package/src/nodes/utils/FlipNode.js +106 -0
  527. package/src/nodes/utils/FunctionOverloadingNode.js +61 -6
  528. package/src/nodes/utils/JoinNode.js +31 -3
  529. package/src/nodes/utils/LoopNode.js +95 -9
  530. package/src/nodes/utils/MatcapUVNode.js +27 -8
  531. package/src/nodes/utils/MaxMipLevelNode.js +57 -6
  532. package/src/nodes/utils/MemberNode.js +68 -0
  533. package/src/nodes/utils/Oscillators.js +41 -0
  534. package/src/nodes/utils/Packing.js +21 -0
  535. package/src/nodes/utils/PostProcessingUtils.js +95 -0
  536. package/src/nodes/utils/RTTNode.js +141 -9
  537. package/src/nodes/utils/ReflectorNode.js +295 -21
  538. package/src/nodes/utils/RemapNode.js +93 -10
  539. package/src/nodes/utils/RotateNode.js +48 -13
  540. package/src/nodes/utils/SetNode.js +50 -4
  541. package/src/nodes/utils/SplitNode.js +62 -6
  542. package/src/nodes/utils/SpriteSheetUVNode.js +56 -7
  543. package/src/nodes/utils/SpriteUtils.js +21 -5
  544. package/src/nodes/utils/StorageArrayElementNode.js +64 -12
  545. package/src/nodes/utils/Timer.js +73 -0
  546. package/src/nodes/utils/TriplanarTexturesNode.js +96 -10
  547. package/src/nodes/utils/UVUtils.js +27 -9
  548. package/src/nodes/utils/ViewportUtils.js +16 -4
  549. package/src/objects/BatchedMesh.js +808 -281
  550. package/src/objects/Bone.js +24 -0
  551. package/src/objects/ClippingGroup.js +68 -0
  552. package/src/objects/Group.js +24 -0
  553. package/src/objects/InstancedMesh.js +120 -2
  554. package/src/objects/LOD.js +120 -5
  555. package/src/objects/Line.js +89 -6
  556. package/src/objects/LineLoop.js +20 -0
  557. package/src/objects/LineSegments.js +18 -0
  558. package/src/objects/Mesh.js +82 -23
  559. package/src/objects/Points.js +62 -0
  560. package/src/objects/Skeleton.js +107 -2
  561. package/src/objects/SkinnedMesh.js +99 -5
  562. package/src/objects/Sprite.js +54 -0
  563. package/src/renderers/WebGLRenderer.js +274 -157
  564. package/src/renderers/common/Animation.js +109 -12
  565. package/src/renderers/common/Attributes.js +40 -0
  566. package/src/renderers/common/Backend.js +504 -44
  567. package/src/renderers/common/Background.js +67 -9
  568. package/src/renderers/common/BindGroup.js +45 -1
  569. package/src/renderers/common/Binding.js +35 -0
  570. package/src/renderers/common/Bindings.js +136 -19
  571. package/src/renderers/common/Buffer.js +49 -0
  572. package/src/renderers/common/BufferUtils.js +25 -0
  573. package/src/renderers/common/BundleGroup.js +83 -0
  574. package/src/renderers/common/ChainMap.js +45 -6
  575. package/src/renderers/common/ClippingContext.js +175 -80
  576. package/src/renderers/common/Color4.js +40 -0
  577. package/src/renderers/common/ComputePipeline.js +24 -0
  578. package/src/renderers/common/Constants.js +2 -1
  579. package/src/renderers/common/CubeRenderTarget.js +22 -3
  580. package/src/renderers/common/DataMap.js +37 -1
  581. package/src/renderers/common/Geometries.js +111 -14
  582. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  583. package/src/renderers/common/Info.js +78 -35
  584. package/src/renderers/common/Lighting.js +73 -0
  585. package/src/renderers/common/Pipeline.js +22 -0
  586. package/src/renderers/common/Pipelines.js +148 -5
  587. package/src/renderers/common/PostProcessing.js +112 -11
  588. package/src/renderers/common/ProgrammableStage.js +60 -2
  589. package/src/renderers/common/QuadMesh.js +56 -5
  590. package/src/renderers/common/RenderBundle.js +14 -8
  591. package/src/renderers/common/RenderBundles.js +39 -10
  592. package/src/renderers/common/RenderContext.js +205 -7
  593. package/src/renderers/common/RenderContexts.js +59 -6
  594. package/src/renderers/common/RenderList.js +230 -21
  595. package/src/renderers/common/RenderLists.js +45 -6
  596. package/src/renderers/common/RenderObject.js +552 -41
  597. package/src/renderers/common/RenderObjects.js +118 -9
  598. package/src/renderers/common/RenderPipeline.js +24 -0
  599. package/src/renderers/common/Renderer.js +1537 -239
  600. package/src/renderers/common/RendererUtils.js +191 -0
  601. package/src/renderers/common/SampledTexture.js +132 -3
  602. package/src/renderers/common/Sampler.js +30 -0
  603. package/src/renderers/common/StorageBuffer.js +24 -0
  604. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  605. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  606. package/src/renderers/common/StorageTexture.js +38 -0
  607. package/src/renderers/common/Textures.js +142 -32
  608. package/src/renderers/common/TimestampQueryPool.js +98 -0
  609. package/src/renderers/common/Uniform.js +225 -3
  610. package/src/renderers/common/UniformBuffer.js +19 -0
  611. package/src/renderers/common/UniformsGroup.js +157 -6
  612. package/src/renderers/common/XRManager.js +1185 -0
  613. package/src/renderers/common/XRRenderTarget.js +74 -0
  614. package/src/renderers/common/extras/PMREMGenerator.js +211 -53
  615. package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
  616. package/src/renderers/common/nodes/NodeLibrary.js +194 -0
  617. package/src/renderers/common/nodes/NodeSampledTexture.js +92 -4
  618. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  619. package/src/renderers/common/nodes/NodeStorageBuffer.js +37 -3
  620. package/src/renderers/common/nodes/NodeUniform.js +285 -2
  621. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  622. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  623. package/src/renderers/common/nodes/Nodes.js +390 -70
  624. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  625. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  626. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  627. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  628. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
  629. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  630. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
  631. package/src/renderers/webgl/WebGLAttributes.js +45 -14
  632. package/src/renderers/webgl/WebGLBackground.js +24 -1
  633. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  634. package/src/renderers/webgl/WebGLCapabilities.js +2 -0
  635. package/src/renderers/webgl/WebGLGeometries.js +0 -28
  636. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  637. package/src/renderers/webgl/WebGLProgram.js +27 -29
  638. package/src/renderers/webgl/WebGLPrograms.js +24 -16
  639. package/src/renderers/webgl/WebGLState.js +68 -11
  640. package/src/renderers/webgl/WebGLTextures.js +49 -10
  641. package/src/renderers/webgl-fallback/WebGLBackend.js +1055 -238
  642. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
  643. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +425 -48
  644. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +64 -1
  645. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  646. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  647. package/src/renderers/webgl-fallback/utils/WebGLState.js +419 -14
  648. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +281 -59
  649. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +367 -0
  650. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  651. package/src/renderers/webgpu/WebGPUBackend.js +816 -236
  652. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +78 -0
  653. package/src/renderers/webgpu/WebGPURenderer.js +45 -6
  654. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +63 -0
  655. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +97 -0
  656. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +954 -147
  657. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +29 -4
  658. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  659. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +147 -31
  660. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +213 -31
  661. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +146 -28
  662. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +161 -7
  663. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +333 -50
  664. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
  665. package/src/renderers/webgpu/utils/WebGPUUtils.js +131 -3
  666. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  667. package/src/renderers/webxr/WebXRManager.js +54 -32
  668. package/src/scenes/Fog.js +60 -0
  669. package/src/scenes/FogExp2.js +51 -0
  670. package/src/scenes/Scene.js +87 -0
  671. package/src/textures/Data3DTexture.js +2 -2
  672. package/src/textures/DepthTexture.js +2 -0
  673. package/src/textures/Source.js +2 -2
  674. package/src/textures/Texture.js +368 -5
  675. package/src/textures/VideoFrameTexture.js +35 -0
  676. package/src/utils.js +33 -1
  677. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  678. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  679. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  680. package/examples/jsm/controls/Controls.js +0 -32
  681. package/examples/jsm/exporters/MMDExporter.js +0 -217
  682. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
  683. package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
  684. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  685. package/examples/jsm/loaders/LogLuvLoader.js +0 -606
  686. package/examples/jsm/loaders/MMDLoader.js +0 -2295
  687. package/examples/jsm/loaders/TiltLoader.js +0 -520
  688. package/examples/jsm/objects/InstancedPoints.js +0 -21
  689. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  690. package/examples/jsm/utils/GPUStatsPanel.js +0 -95
  691. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  692. package/src/nodes/accessors/BitangentNode.js +0 -13
  693. package/src/nodes/accessors/CameraNode.js +0 -19
  694. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -21
  695. package/src/nodes/accessors/NormalNode.js +0 -14
  696. package/src/nodes/accessors/PositionNode.js +0 -10
  697. package/src/nodes/accessors/ReflectVectorNode.js +0 -10
  698. package/src/nodes/accessors/TangentNode.js +0 -23
  699. package/src/nodes/accessors/UVNode.js +0 -3
  700. package/src/nodes/core/NodeKeywords.js +0 -80
  701. package/src/nodes/core/UniformGroup.js +0 -13
  702. package/src/nodes/display/AfterImageNode.js +0 -152
  703. package/src/nodes/display/AnamorphicNode.js +0 -145
  704. package/src/nodes/display/BlendModeNode.js +0 -128
  705. package/src/nodes/display/ColorAdjustmentNode.js +0 -104
  706. package/src/nodes/display/DenoiseNode.js +0 -198
  707. package/src/nodes/display/DotScreenNode.js +0 -75
  708. package/src/nodes/display/FXAANode.js +0 -327
  709. package/src/nodes/display/FilmNode.js +0 -52
  710. package/src/nodes/display/GTAONode.js +0 -324
  711. package/src/nodes/display/GaussianBlurNode.js +0 -207
  712. package/src/nodes/display/Lut3DNode.js +0 -53
  713. package/src/nodes/display/RGBShiftNode.js +0 -49
  714. package/src/nodes/display/SepiaNode.js +0 -18
  715. package/src/nodes/display/TransitionNode.js +0 -76
  716. package/src/nodes/display/ViewportNode.js +0 -137
  717. package/src/nodes/fog/FogExp2Node.js +0 -34
  718. package/src/nodes/fog/FogNode.js +0 -48
  719. package/src/nodes/fog/FogRangeNode.js +0 -35
  720. package/src/nodes/lighting/LightNode.js +0 -57
  721. package/src/nodes/loaders/NodeLoader.js +0 -110
  722. package/src/nodes/loaders/NodeMaterialLoader.js +0 -60
  723. package/src/nodes/loaders/NodeObjectLoader.js +0 -71
  724. package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
  725. package/src/nodes/materials/LineBasicNodeMaterial.js +0 -28
  726. package/src/nodes/materials/LineDashedNodeMaterial.js +0 -55
  727. package/src/nodes/materials/MeshBasicNodeMaterial.js +0 -73
  728. package/src/nodes/materials/MeshLambertNodeMaterial.js +0 -43
  729. package/src/nodes/materials/MeshMatcapNodeMaterial.js +0 -53
  730. package/src/nodes/materials/MeshNormalNodeMaterial.js +0 -40
  731. package/src/nodes/materials/MeshPhongNodeMaterial.js +0 -74
  732. package/src/nodes/materials/MeshPhysicalNodeMaterial.js +0 -244
  733. package/src/nodes/materials/MeshSSSNodeMaterial.js +0 -84
  734. package/src/nodes/materials/MeshStandardNodeMaterial.js +0 -104
  735. package/src/nodes/materials/MeshToonNodeMaterial.js +0 -34
  736. package/src/nodes/materials/NodeMaterial.js +0 -680
  737. package/src/nodes/materials/PointsNodeMaterial.js +0 -39
  738. package/src/nodes/materials/ShadowNodeMaterial.js +0 -34
  739. package/src/nodes/materials/SpriteNodeMaterial.js +0 -90
  740. package/src/nodes/materials/VolumeNodeMaterial.js +0 -106
  741. package/src/nodes/math/CondNode.js +0 -139
  742. package/src/nodes/math/HashNode.js +0 -34
  743. package/src/nodes/procedural/CheckerNode.js +0 -42
  744. package/src/nodes/utils/DiscardNode.js +0 -28
  745. package/src/nodes/utils/OscNode.js +0 -81
  746. package/src/nodes/utils/PackingNode.js +0 -55
  747. package/src/nodes/utils/TimerNode.js +0 -94
@@ -11,12 +11,27 @@ import { NodeBuilder, CodeNode } from '../../../nodes/Nodes.js';
11
11
  import { getFormat } from '../utils/WebGPUTextureUtils.js';
12
12
 
13
13
  import WGSLNodeParser from './WGSLNodeParser.js';
14
- import { GPUBufferBindingType, GPUStorageTextureAccess } from '../utils/WebGPUConstants.js';
14
+ import { NodeAccess } from '../../../nodes/core/constants.js';
15
15
 
16
- import { NoColorSpace, FloatType } from '../../../constants.js';
16
+ import VarNode from '../../../nodes/core/VarNode.js';
17
+ import ExpressionNode from '../../../nodes/code/ExpressionNode.js';
18
+
19
+ import { NoColorSpace, FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter } from '../../../constants.js';
17
20
 
18
21
  // GPUShaderStage is not defined in browsers not supporting WebGPU
19
- const GPUShaderStage = self.GPUShaderStage;
22
+ const GPUShaderStage = ( typeof self !== 'undefined' ) ? self.GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 };
23
+
24
+ const accessNames = {
25
+ [ NodeAccess.READ_ONLY ]: 'read',
26
+ [ NodeAccess.WRITE_ONLY ]: 'write',
27
+ [ NodeAccess.READ_WRITE ]: 'read_write'
28
+ };
29
+
30
+ const wrapNames = {
31
+ [ RepeatWrapping ]: 'repeat',
32
+ [ ClampToEdgeWrapping ]: 'clamp',
33
+ [ MirroredRepeatWrapping ]: 'mirror'
34
+ };
20
35
 
21
36
  const gpuShaderStageLib = {
22
37
  'vertex': GPUShaderStage ? GPUShaderStage.VERTEX : 1,
@@ -57,21 +72,12 @@ const wgslTypeLib = {
57
72
  bvec4: 'vec4<bool>',
58
73
 
59
74
  mat2: 'mat2x2<f32>',
60
- imat2: 'mat2x2<i32>',
61
- umat2: 'mat2x2<u32>',
62
- bmat2: 'mat2x2<bool>',
63
-
64
75
  mat3: 'mat3x3<f32>',
65
- imat3: 'mat3x3<i32>',
66
- umat3: 'mat3x3<u32>',
67
- bmat3: 'mat3x3<bool>',
68
-
69
- mat4: 'mat4x4<f32>',
70
- imat4: 'mat4x4<i32>',
71
- umat4: 'mat4x4<u32>',
72
- bmat4: 'mat4x4<bool>'
76
+ mat4: 'mat4x4<f32>'
73
77
  };
74
78
 
79
+ const wgslCodeCache = {};
80
+
75
81
  const wgslPolyfill = {
76
82
  tsl_xor: new CodeNode( 'fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }' ),
77
83
  mod_float: new CodeNode( 'fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }' ),
@@ -82,19 +88,13 @@ const wgslPolyfill = {
82
88
  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
89
  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
90
  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 ); }' ),
85
- repeatWrapping: new CodeNode( `
86
- fn tsl_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
87
-
88
- let uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );
91
+ repeatWrapping_float: new CodeNode( 'fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }' ),
92
+ mirrorWrapping_float: new CodeNode( 'fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }' ),
93
+ clampWrapping_float: new CodeNode( 'fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }' ),
94
+ biquadraticTexture: new CodeNode( /* wgsl */`
95
+ fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {
89
96
 
90
- return ( ( uvScaled % dimension ) + dimension ) % dimension;
91
-
92
- }
93
- ` ),
94
- biquadraticTexture: new CodeNode( `
95
- fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {
96
-
97
- let res = vec2f( textureDimensions( map, level ) );
97
+ let res = vec2f( iRes );
98
98
 
99
99
  let uvScaled = coord * res;
100
100
  let uvWrapping = ( ( uvScaled % res ) + res ) % res;
@@ -105,10 +105,10 @@ fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -
105
105
  let iuv = floor( uv );
106
106
  let f = fract( uv );
107
107
 
108
- let rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ), level );
109
- let rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ), level );
110
- let rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ), level );
111
- let rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ), level );
108
+ let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );
109
+ let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );
110
+ let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );
111
+ let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );
112
112
 
113
113
  return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
114
114
 
@@ -133,7 +133,7 @@ const wgslMethods = {
133
133
 
134
134
  // WebGPU issue: does not support pow() with negative base on Windows
135
135
 
136
- if ( /Windows/g.test( navigator.userAgent ) ) {
136
+ if ( typeof navigator !== 'undefined' && /Windows/g.test( navigator.userAgent ) ) {
137
137
 
138
138
  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 ); }' );
139
139
  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 ] );
@@ -149,26 +149,91 @@ if ( /Windows/g.test( navigator.userAgent ) ) {
149
149
 
150
150
  //
151
151
 
152
+ let diagnostics = '';
153
+
154
+ if ( ( typeof navigator !== 'undefined' && /Firefox|Deno/g.test( navigator.userAgent ) ) !== true ) {
155
+
156
+ diagnostics += 'diagnostic( off, derivative_uniformity );\n';
157
+
158
+ }
159
+
160
+ /**
161
+ * A node builder targeting WGSL.
162
+ *
163
+ * This module generates WGSL shader code from node materials and also
164
+ * generates the respective bindings and vertex buffer definitions. These
165
+ * data are later used by the renderer to create render and compute pipelines
166
+ * for render objects.
167
+ *
168
+ * @augments NodeBuilder
169
+ */
152
170
  class WGSLNodeBuilder extends NodeBuilder {
153
171
 
172
+ /**
173
+ * Constructs a new WGSL node builder renderer.
174
+ *
175
+ * @param {Object3D} object - The 3D object.
176
+ * @param {Renderer} renderer - The renderer.
177
+ */
154
178
  constructor( object, renderer ) {
155
179
 
156
180
  super( object, renderer, new WGSLNodeParser() );
157
181
 
182
+ /**
183
+ * A dictionary that holds for each shader stage ('vertex', 'fragment', 'compute')
184
+ * another dictionary which manages UBOs per group ('render','frame','object').
185
+ *
186
+ * @type {Object<string,Object<string,NodeUniformsGroup>>}
187
+ */
158
188
  this.uniformGroups = {};
159
189
 
190
+ /**
191
+ * A dictionary that holds for each shader stage a Map of builtins.
192
+ *
193
+ * @type {Object<string,Map<string,Object>>}
194
+ */
160
195
  this.builtins = {};
161
196
 
197
+ /**
198
+ * A dictionary that holds for each shader stage a Set of directives.
199
+ *
200
+ * @type {Object<string,Set<string>>}
201
+ */
162
202
  this.directives = {};
163
203
 
204
+ /**
205
+ * A map for managing scope arrays. Only relevant for when using
206
+ * {@link WorkgroupInfoNode} in context of compute shaders.
207
+ *
208
+ * @type {Map<string,Object>}
209
+ */
210
+ this.scopedArrays = new Map();
211
+
164
212
  }
165
213
 
166
- needsColorSpaceToLinear( texture ) {
214
+ /**
215
+ * Checks if the given texture requires a manual conversion to the working color space.
216
+ *
217
+ * @param {Texture} texture - The texture to check.
218
+ * @return {boolean} Whether the given texture requires a conversion to working color space or not.
219
+ */
220
+ needsToWorkingColorSpace( texture ) {
167
221
 
168
222
  return texture.isVideoTexture === true && texture.colorSpace !== NoColorSpace;
169
223
 
170
224
  }
171
225
 
226
+ /**
227
+ * Generates the WGSL snippet for sampled textures.
228
+ *
229
+ * @private
230
+ * @param {Texture} texture - The texture.
231
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
232
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
233
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
234
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
235
+ * @return {string} The WGSL snippet.
236
+ */
172
237
  _generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) {
173
238
 
174
239
  if ( shaderStage === 'fragment' ) {
@@ -189,12 +254,21 @@ class WGSLNodeBuilder extends NodeBuilder {
189
254
 
190
255
  } else {
191
256
 
192
- return this.generateTextureLod( texture, textureProperty, uvSnippet, '0' );
257
+ return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, '0' );
193
258
 
194
259
  }
195
260
 
196
261
  }
197
262
 
263
+ /**
264
+ * Generates the WGSL snippet when sampling video textures.
265
+ *
266
+ * @private
267
+ * @param {string} textureProperty - The name of the video texture uniform in the shader.
268
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
269
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
270
+ * @return {string} The WGSL snippet.
271
+ */
198
272
  _generateVideoSample( textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
199
273
 
200
274
  if ( shaderStage === 'fragment' ) {
@@ -209,9 +283,21 @@ class WGSLNodeBuilder extends NodeBuilder {
209
283
 
210
284
  }
211
285
 
286
+ /**
287
+ * Generates the WGSL snippet when sampling textures with explicit mip level.
288
+ *
289
+ * @private
290
+ * @param {Texture} texture - The texture.
291
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
292
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
293
+ * @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
294
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
295
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
296
+ * @return {string} The WGSL snippet.
297
+ */
212
298
  _generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) {
213
299
 
214
- if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false ) {
300
+ if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( texture ) === false ) {
215
301
 
216
302
  return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
217
303
 
@@ -221,56 +307,301 @@ class WGSLNodeBuilder extends NodeBuilder {
221
307
 
222
308
  } else {
223
309
 
224
- return this.generateTextureLod( texture, textureProperty, uvSnippet, levelSnippet );
310
+ return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet );
311
+
312
+ }
313
+
314
+ }
315
+
316
+ /**
317
+ * Generates a wrap function used in context of textures.
318
+ *
319
+ * @param {Texture} texture - The texture to generate the function for.
320
+ * @return {string} The name of the generated function.
321
+ */
322
+ generateWrapFunction( texture ) {
323
+
324
+ const functionName = `tsl_coord_${ wrapNames[ texture.wrapS ] }S_${ wrapNames[ texture.wrapT ] }_${texture.isData3DTexture ? '3d' : '2d'}T`;
325
+
326
+ let nodeCode = wgslCodeCache[ functionName ];
327
+
328
+ if ( nodeCode === undefined ) {
329
+
330
+ const includes = [];
331
+
332
+ // For 3D textures, use vec3f; for texture arrays, keep vec2f since array index is separate
333
+ const coordType = texture.isData3DTexture ? 'vec3f' : 'vec2f';
334
+ let code = `fn ${functionName}( coord : ${coordType} ) -> ${coordType} {\n\n\treturn ${coordType}(\n`;
335
+
336
+ const addWrapSnippet = ( wrap, axis ) => {
337
+
338
+ if ( wrap === RepeatWrapping ) {
339
+
340
+ includes.push( wgslPolyfill.repeatWrapping_float );
341
+
342
+ code += `\t\ttsl_repeatWrapping_float( coord.${ axis } )`;
343
+
344
+ } else if ( wrap === ClampToEdgeWrapping ) {
345
+
346
+ includes.push( wgslPolyfill.clampWrapping_float );
347
+
348
+ code += `\t\ttsl_clampWrapping_float( coord.${ axis } )`;
349
+
350
+ } else if ( wrap === MirroredRepeatWrapping ) {
351
+
352
+ includes.push( wgslPolyfill.mirrorWrapping_float );
353
+
354
+ code += `\t\ttsl_mirrorWrapping_float( coord.${ axis } )`;
355
+
356
+ } else {
357
+
358
+ code += `\t\tcoord.${ axis }`;
359
+
360
+ console.warn( `WebGPURenderer: Unsupported texture wrap type "${ wrap }" for vertex shader.` );
361
+
362
+ }
363
+
364
+ };
365
+
366
+ addWrapSnippet( texture.wrapS, 'x' );
367
+
368
+ code += ',\n';
369
+
370
+ addWrapSnippet( texture.wrapT, 'y' );
371
+
372
+ if ( texture.isData3DTexture ) {
373
+
374
+ code += ',\n';
375
+ addWrapSnippet( texture.wrapR, 'z' );
376
+
377
+ }
378
+
379
+ code += '\n\t);\n\n}\n';
380
+
381
+ wgslCodeCache[ functionName ] = nodeCode = new CodeNode( code, includes );
382
+
383
+ }
384
+
385
+ nodeCode.build( this );
386
+
387
+ return functionName;
388
+
389
+ }
390
+
391
+ /**
392
+ * Generates the array declaration string.
393
+ *
394
+ * @param {string} type - The type.
395
+ * @param {?number} [count] - The count.
396
+ * @return {string} The generated value as a shader string.
397
+ */
398
+ generateArrayDeclaration( type, count ) {
399
+
400
+ return `array< ${ this.getType( type ) }, ${ count } >`;
401
+
402
+ }
403
+
404
+ /**
405
+ * Generates a WGSL variable that holds the texture dimension of the given texture.
406
+ * It also returns information about the the number of layers (elements) of an arrayed
407
+ * texture as well as the cube face count of cube textures.
408
+ *
409
+ * @param {Texture} texture - The texture to generate the function for.
410
+ * @param {string} textureProperty - The name of the video texture uniform in the shader.
411
+ * @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
412
+ * @return {string} The name of the dimension variable.
413
+ */
414
+ generateTextureDimension( texture, textureProperty, levelSnippet ) {
415
+
416
+ const textureData = this.getDataFromNode( texture, this.shaderStage, this.globalCache );
417
+
418
+ if ( textureData.dimensionsSnippet === undefined ) textureData.dimensionsSnippet = {};
419
+
420
+ let textureDimensionNode = textureData.dimensionsSnippet[ levelSnippet ];
421
+
422
+ if ( textureData.dimensionsSnippet[ levelSnippet ] === undefined ) {
423
+
424
+ let textureDimensionsParams;
425
+ let dimensionType;
426
+
427
+ const { primarySamples } = this.renderer.backend.utils.getTextureSampleData( texture );
428
+ const isMultisampled = primarySamples > 1;
429
+
430
+ if ( texture.isData3DTexture ) {
431
+
432
+ dimensionType = 'vec3<u32>';
433
+
434
+ } else {
435
+
436
+ // Regular 2D textures, depth textures, etc.
437
+ dimensionType = 'vec2<u32>';
438
+
439
+ }
440
+
441
+ // Build parameters string based on texture type and multisampling
442
+ if ( isMultisampled || texture.isVideoTexture || texture.isStorageTexture ) {
443
+
444
+ textureDimensionsParams = textureProperty;
445
+
446
+ } else {
447
+
448
+ textureDimensionsParams = `${textureProperty}${levelSnippet ? `, u32( ${ levelSnippet } )` : ''}`;
449
+
450
+ }
451
+
452
+ textureDimensionNode = new VarNode( new ExpressionNode( `textureDimensions( ${ textureDimensionsParams } )`, dimensionType ) );
453
+
454
+ textureData.dimensionsSnippet[ levelSnippet ] = textureDimensionNode;
455
+
456
+ if ( texture.isDataArrayTexture || texture.isData3DTexture ) {
457
+
458
+ textureData.arrayLayerCount = new VarNode(
459
+ new ExpressionNode(
460
+ `textureNumLayers(${textureProperty})`,
461
+ 'u32'
462
+ )
463
+ );
464
+
465
+ }
466
+
467
+ // For cube textures, we know it's always 6 faces
468
+ if ( texture.isTextureCube ) {
469
+
470
+ textureData.cubeFaceCount = new VarNode(
471
+ new ExpressionNode( '6u', 'u32' )
472
+ );
473
+
474
+ }
225
475
 
226
476
  }
227
477
 
478
+ return textureDimensionNode.build( this );
479
+
228
480
  }
229
481
 
230
- generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet = '0' ) {
482
+ /**
483
+ * Generates the WGSL snippet for a manual filtered texture.
484
+ *
485
+ * @param {Texture} texture - The texture.
486
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
487
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
488
+ * @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
489
+ * @return {string} The WGSL snippet.
490
+ */
491
+ generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet = '0u' ) {
231
492
 
232
493
  this._include( 'biquadraticTexture' );
233
494
 
234
- return `tsl_biquadraticTexture( ${ textureProperty }, ${ uvSnippet }, i32( ${ levelSnippet } ) )`;
495
+ const wrapFunction = this.generateWrapFunction( texture );
496
+ const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
497
+
498
+ return `tsl_biquadraticTexture( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ levelSnippet } ) )`;
235
499
 
236
500
  }
237
501
 
238
- generateTextureLod( texture, textureProperty, uvSnippet, levelSnippet = '0' ) {
502
+ /**
503
+ * Generates the WGSL snippet for a texture lookup with explicit level-of-detail.
504
+ * Since it's a lookup, no sampling or filtering is applied.
505
+ *
506
+ * @param {Texture} texture - The texture.
507
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
508
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
509
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
510
+ * @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
511
+ * @return {string} The WGSL snippet.
512
+ */
513
+ generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet = '0u' ) {
239
514
 
240
- this._include( 'repeatWrapping' );
515
+ const wrapFunction = this.generateWrapFunction( texture );
516
+ const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
241
517
 
242
- const dimension = texture.isMultisampleRenderTargetTexture === true ? `textureDimensions( ${ textureProperty } )` : `textureDimensions( ${ textureProperty }, 0 )`;
518
+ const vecType = texture.isData3DTexture ? 'vec3' : 'vec2';
519
+ const coordSnippet = `${vecType}<u32>(${wrapFunction}(${uvSnippet}) * ${vecType}<f32>(${textureDimension}))`;
243
520
 
244
- return `textureLoad( ${ textureProperty }, tsl_repeatWrapping( ${ uvSnippet }, ${ dimension } ), i32( ${ levelSnippet } ) )`;
521
+ return this.generateTextureLoad( texture, textureProperty, coordSnippet, depthSnippet, levelSnippet );
245
522
 
246
523
  }
247
524
 
525
+ /**
526
+ * Generates the WGSL snippet that reads a single texel from a texture without sampling or filtering.
527
+ *
528
+ * @param {Texture} texture - The texture.
529
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
530
+ * @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
531
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
532
+ * @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
533
+ * @return {string} The WGSL snippet.
534
+ */
248
535
  generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, levelSnippet = '0u' ) {
249
536
 
250
- if ( depthSnippet ) {
537
+ if ( texture.isVideoTexture === true || texture.isStorageTexture === true ) {
538
+
539
+ return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`;
540
+
541
+ } else if ( depthSnippet ) {
251
542
 
252
- return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
543
+ return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
253
544
 
254
545
  } else {
255
546
 
256
- return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ levelSnippet } )`;
547
+ return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, u32( ${ levelSnippet } ) )`;
257
548
 
258
549
  }
259
550
 
260
551
  }
261
552
 
553
+ /**
554
+ * Generates the WGSL snippet that writes a single texel to a texture.
555
+ *
556
+ * @param {Texture} texture - The texture.
557
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
558
+ * @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
559
+ * @param {string} valueSnippet - A WGSL snippet that represent the new texel value.
560
+ * @return {string} The WGSL snippet.
561
+ */
262
562
  generateTextureStore( texture, textureProperty, uvIndexSnippet, valueSnippet ) {
263
563
 
264
564
  return `textureStore( ${ textureProperty }, ${ uvIndexSnippet }, ${ valueSnippet } )`;
265
565
 
266
566
  }
267
567
 
568
+ /**
569
+ * Returns `true` if the sampled values of the given texture should be compared against a reference value.
570
+ *
571
+ * @param {Texture} texture - The texture.
572
+ * @return {boolean} Whether the sampled values of the given texture should be compared against a reference value or not.
573
+ */
574
+ isSampleCompare( texture ) {
575
+
576
+ return texture.isDepthTexture === true && texture.compareFunction !== null;
577
+
578
+ }
579
+
580
+ /**
581
+ * Returns `true` if the given texture is unfilterable.
582
+ *
583
+ * @param {Texture} texture - The texture.
584
+ * @return {boolean} Whether the given texture is unfilterable or not.
585
+ */
268
586
  isUnfilterable( texture ) {
269
587
 
270
- return this.getComponentTypeFromTexture( texture ) !== 'float' || ( texture.isDataTexture === true && texture.type === FloatType ) || texture.isMultisampleRenderTargetTexture === true;
588
+ return this.getComponentTypeFromTexture( texture ) !== 'float' ||
589
+ ( ! this.isAvailable( 'float32Filterable' ) && texture.isDataTexture === true && texture.type === FloatType ) ||
590
+ ( this.isSampleCompare( texture ) === false && texture.minFilter === NearestFilter && texture.magFilter === NearestFilter ) ||
591
+ this.renderer.backend.utils.getTextureSampleData( texture ).primarySamples > 1;
271
592
 
272
593
  }
273
594
 
595
+ /**
596
+ * Generates the WGSL snippet for sampling/loading the given texture.
597
+ *
598
+ * @param {Texture} texture - The texture.
599
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
600
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
601
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
602
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
603
+ * @return {string} The WGSL snippet.
604
+ */
274
605
  generateTexture( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) {
275
606
 
276
607
  let snippet = null;
@@ -281,7 +612,7 @@ class WGSLNodeBuilder extends NodeBuilder {
281
612
 
282
613
  } else if ( this.isUnfilterable( texture ) ) {
283
614
 
284
- snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, '0', depthSnippet, shaderStage );
615
+ snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, '0', shaderStage );
285
616
 
286
617
  } else {
287
618
 
@@ -293,6 +624,17 @@ class WGSLNodeBuilder extends NodeBuilder {
293
624
 
294
625
  }
295
626
 
627
+ /**
628
+ * Generates the WGSL snippet for sampling/loading the given texture using explicit gradients.
629
+ *
630
+ * @param {Texture} texture - The texture.
631
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
632
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
633
+ * @param {Array<string>} gradSnippet - An array holding both gradient WGSL snippets.
634
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
635
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
636
+ * @return {string} The WGSL snippet.
637
+ */
296
638
  generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, shaderStage = this.shaderStage ) {
297
639
 
298
640
  if ( shaderStage === 'fragment' ) {
@@ -308,6 +650,18 @@ class WGSLNodeBuilder extends NodeBuilder {
308
650
 
309
651
  }
310
652
 
653
+ /**
654
+ * Generates the WGSL snippet for sampling a depth texture and comparing the sampled depth values
655
+ * against a reference value.
656
+ *
657
+ * @param {Texture} texture - The texture.
658
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
659
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
660
+ * @param {string} compareSnippet - A WGSL snippet that represents the reference value.
661
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
662
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
663
+ * @return {string} The WGSL snippet.
664
+ */
311
665
  generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) {
312
666
 
313
667
  if ( shaderStage === 'fragment' ) {
@@ -322,6 +676,17 @@ class WGSLNodeBuilder extends NodeBuilder {
322
676
 
323
677
  }
324
678
 
679
+ /**
680
+ * Generates the WGSL snippet when sampling textures with explicit mip level.
681
+ *
682
+ * @param {Texture} texture - The texture.
683
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
684
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
685
+ * @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
686
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
687
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
688
+ * @return {string} The WGSL snippet.
689
+ */
325
690
  generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) {
326
691
 
327
692
  let snippet = null;
@@ -340,6 +705,17 @@ class WGSLNodeBuilder extends NodeBuilder {
340
705
 
341
706
  }
342
707
 
708
+ /**
709
+ * Generates the WGSL snippet when sampling textures with a bias to the mip level.
710
+ *
711
+ * @param {Texture} texture - The texture.
712
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
713
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
714
+ * @param {string} biasSnippet - A WGSL snippet that represents the bias to apply to the mip level before sampling.
715
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
716
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
717
+ * @return {string} The WGSL snippet.
718
+ */
343
719
  generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet, shaderStage = this.shaderStage ) {
344
720
 
345
721
  if ( shaderStage === 'fragment' ) {
@@ -354,6 +730,13 @@ class WGSLNodeBuilder extends NodeBuilder {
354
730
 
355
731
  }
356
732
 
733
+ /**
734
+ * Returns a WGSL snippet that represents the property name of the given node.
735
+ *
736
+ * @param {Node} node - The node.
737
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
738
+ * @return {string} The property name.
739
+ */
357
740
  getPropertyName( node, shaderStage = this.shaderStage ) {
358
741
 
359
742
  if ( node.isNodeVarying === true && node.needsInterpolation === true ) {
@@ -373,9 +756,15 @@ class WGSLNodeBuilder extends NodeBuilder {
373
756
 
374
757
  return name;
375
758
 
376
- } else if ( type === 'buffer' || type === 'storageBuffer' ) {
759
+ } else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
760
+
761
+ if ( this.isCustomStruct( node ) ) {
762
+
763
+ return name;
764
+
765
+ }
377
766
 
378
- return `NodeBuffer_${ node.id }.${name}`;
767
+ return name + '.value';
379
768
 
380
769
  } else {
381
770
 
@@ -389,18 +778,23 @@ class WGSLNodeBuilder extends NodeBuilder {
389
778
 
390
779
  }
391
780
 
781
+ /**
782
+ * Returns the output struct name.
783
+ *
784
+ * @return {string} The name of the output struct.
785
+ */
392
786
  getOutputStructName() {
393
787
 
394
788
  return 'output';
395
789
 
396
790
  }
397
791
 
398
- _getUniformGroupCount( shaderStage ) {
399
-
400
- return Object.keys( this.uniforms[ shaderStage ] ).length;
401
-
402
- }
403
-
792
+ /**
793
+ * Returns the native shader operator name for a given generic name.
794
+ *
795
+ * @param {string} op - The operator name to resolve.
796
+ * @return {?string} The resolved operator name.
797
+ */
404
798
  getFunctionOperator( op ) {
405
799
 
406
800
  const fnOp = wgslFnOpLib[ op ];
@@ -417,49 +811,48 @@ class WGSLNodeBuilder extends NodeBuilder {
417
811
 
418
812
  }
419
813
 
420
- getStorageAccess( node ) {
421
-
422
- if ( node.isStorageTextureNode ) {
423
-
424
- switch ( node.access ) {
425
-
426
- case GPUStorageTextureAccess.ReadOnly:
427
-
428
- return 'read';
429
-
430
- case GPUStorageTextureAccess.WriteOnly:
431
-
432
- return 'write';
433
-
434
- default:
435
-
436
- return 'read_write';
437
-
438
- }
439
-
440
- } else {
441
-
442
- switch ( node.access ) {
443
-
444
- case GPUBufferBindingType.Storage:
814
+ /**
815
+ * Returns the node access for the given node and shader stage.
816
+ *
817
+ * @param {StorageTextureNode|StorageBufferNode} node - The storage node.
818
+ * @param {string} shaderStage - The shader stage.
819
+ * @return {string} The node access.
820
+ */
821
+ getNodeAccess( node, shaderStage ) {
445
822
 
446
- return 'read_write';
823
+ if ( shaderStage !== 'compute' )
824
+ return NodeAccess.READ_ONLY;
447
825
 
826
+ return node.access;
448
827
 
449
- case GPUBufferBindingType.ReadOnlyStorage:
450
-
451
- return 'read';
452
-
453
- default:
828
+ }
454
829
 
455
- return 'write';
830
+ /**
831
+ * Returns A WGSL snippet representing the storage access.
832
+ *
833
+ * @param {StorageTextureNode|StorageBufferNode} node - The storage node.
834
+ * @param {string} shaderStage - The shader stage.
835
+ * @return {string} The WGSL snippet representing the storage access.
836
+ */
837
+ getStorageAccess( node, shaderStage ) {
456
838
 
457
- }
458
-
459
- }
839
+ return accessNames[ this.getNodeAccess( node, shaderStage ) ];
460
840
 
461
841
  }
462
842
 
843
+ /**
844
+ * This method is one of the more important ones since it's responsible
845
+ * for generating a matching binding instance for the given uniform node.
846
+ *
847
+ * These bindings are later used in the renderer to create bind groups
848
+ * and layouts.
849
+ *
850
+ * @param {UniformNode} node - The uniform node.
851
+ * @param {string} type - The node data type.
852
+ * @param {string} shaderStage - The shader stage.
853
+ * @param {?string} [name=null] - An optional uniform name.
854
+ * @return {NodeUniform} The node uniform object.
855
+ */
463
856
  getUniformFromNode( node, type, shaderStage, name = null ) {
464
857
 
465
858
  const uniformNode = super.getUniformFromNode( node, type, shaderStage, name );
@@ -478,26 +871,28 @@ class WGSLNodeBuilder extends NodeBuilder {
478
871
 
479
872
  let texture = null;
480
873
 
874
+ const access = this.getNodeAccess( node, shaderStage );
875
+
481
876
  if ( type === 'texture' || type === 'storageTexture' ) {
482
877
 
483
- texture = new NodeSampledTexture( uniformNode.name, uniformNode.node, group, node.access ? node.access : null );
878
+ texture = new NodeSampledTexture( uniformNode.name, uniformNode.node, group, access );
484
879
 
485
880
  } else if ( type === 'cubeTexture' ) {
486
881
 
487
- texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group, node.access ? node.access : null );
882
+ texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group, access );
488
883
 
489
884
  } else if ( type === 'texture3D' ) {
490
885
 
491
- texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group, node.access ? node.access : null );
886
+ texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group, access );
492
887
 
493
888
  }
494
889
 
495
890
  texture.store = node.isStorageTextureNode === true;
496
891
  texture.setVisibility( gpuShaderStageLib[ shaderStage ] );
497
892
 
498
- if ( shaderStage === 'fragment' && this.isUnfilterable( node.value ) === false && texture.store === false ) {
893
+ if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( node.value ) === false && texture.store === false ) {
499
894
 
500
- const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node, group );
895
+ const sampler = new NodeSampler( `${ uniformNode.name }_sampler`, uniformNode.node, group );
501
896
  sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
502
897
 
503
898
  bindings.push( sampler, texture );
@@ -512,9 +907,10 @@ class WGSLNodeBuilder extends NodeBuilder {
512
907
 
513
908
  }
514
909
 
515
- } else if ( type === 'buffer' || type === 'storageBuffer' ) {
910
+ } else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
911
+
912
+ const bufferClass = type === 'buffer' ? NodeUniformBuffer : NodeStorageBuffer;
516
913
 
517
- const bufferClass = type === 'storageBuffer' ? NodeStorageBuffer : NodeUniformBuffer;
518
914
  const buffer = new bufferClass( node, group );
519
915
  buffer.setVisibility( gpuShaderStageLib[ shaderStage ] );
520
916
 
@@ -522,6 +918,8 @@ class WGSLNodeBuilder extends NodeBuilder {
522
918
 
523
919
  uniformGPU = buffer;
524
920
 
921
+ uniformNode.name = name ? name : 'NodeBuffer_' + uniformNode.id;
922
+
525
923
  } else {
526
924
 
527
925
  const uniformsStage = this.uniformGroups[ shaderStage ] || ( this.uniformGroups[ shaderStage ] = {} );
@@ -553,6 +951,17 @@ class WGSLNodeBuilder extends NodeBuilder {
553
951
 
554
952
  }
555
953
 
954
+ /**
955
+ * This method should be used whenever builtins are required in nodes.
956
+ * The internal builtins data structure will make sure builtins are
957
+ * defined in the WGSL source.
958
+ *
959
+ * @param {string} name - The builtin name.
960
+ * @param {string} property - The property name.
961
+ * @param {string} type - The node data type.
962
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
963
+ * @return {string} The property name.
964
+ */
556
965
  getBuiltin( name, property, type, shaderStage = this.shaderStage ) {
557
966
 
558
967
  const map = this.builtins[ shaderStage ] || ( this.builtins[ shaderStage ] = new Map() );
@@ -571,6 +980,24 @@ class WGSLNodeBuilder extends NodeBuilder {
571
980
 
572
981
  }
573
982
 
983
+ /**
984
+ * Returns `true` if the given builtin is defined in the given shader stage.
985
+ *
986
+ * @param {string} name - The builtin name.
987
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
988
+ * @return {boolean} Whether the given builtin is defined in the given shader stage or not.
989
+ */
990
+ hasBuiltin( name, shaderStage = this.shaderStage ) {
991
+
992
+ return ( this.builtins[ shaderStage ] !== undefined && this.builtins[ shaderStage ].has( name ) );
993
+
994
+ }
995
+
996
+ /**
997
+ * Returns the vertex index builtin.
998
+ *
999
+ * @return {string} The vertex index.
1000
+ */
574
1001
  getVertexIndex() {
575
1002
 
576
1003
  if ( this.shaderStage === 'vertex' ) {
@@ -583,6 +1010,12 @@ class WGSLNodeBuilder extends NodeBuilder {
583
1010
 
584
1011
  }
585
1012
 
1013
+ /**
1014
+ * Builds the given shader node.
1015
+ *
1016
+ * @param {ShaderNodeInternal} shaderNode - The shader node.
1017
+ * @return {string} The WGSL function code.
1018
+ */
586
1019
  buildFunctionCode( shaderNode ) {
587
1020
 
588
1021
  const layout = shaderNode.layout;
@@ -598,12 +1031,18 @@ class WGSLNodeBuilder extends NodeBuilder {
598
1031
 
599
1032
  //
600
1033
 
601
- const code = `fn ${ layout.name }( ${ parameters.join( ', ' ) } ) -> ${ this.getType( layout.type ) } {
1034
+ let code = `fn ${ layout.name }( ${ parameters.join( ', ' ) } ) -> ${ this.getType( layout.type ) } {
602
1035
  ${ flowData.vars }
603
1036
  ${ flowData.code }
604
- return ${ flowData.result };
1037
+ `;
1038
+
1039
+ if ( flowData.result ) {
605
1040
 
606
- }`;
1041
+ code += `\treturn ${ flowData.result };\n`;
1042
+
1043
+ }
1044
+
1045
+ code += '\n}\n';
607
1046
 
608
1047
  //
609
1048
 
@@ -611,6 +1050,11 @@ ${ flowData.code }
611
1050
 
612
1051
  }
613
1052
 
1053
+ /**
1054
+ * Returns the instance index builtin.
1055
+ *
1056
+ * @return {string} The instance index.
1057
+ */
614
1058
  getInstanceIndex() {
615
1059
 
616
1060
  if ( this.shaderStage === 'vertex' ) {
@@ -623,6 +1067,22 @@ ${ flowData.code }
623
1067
 
624
1068
  }
625
1069
 
1070
+ /**
1071
+ * Returns the invocation local index builtin.
1072
+ *
1073
+ * @return {string} The invocation local index.
1074
+ */
1075
+ getInvocationLocalIndex() {
1076
+
1077
+ return this.getBuiltin( 'local_invocation_index', 'invocationLocalIndex', 'u32', 'attribute' );
1078
+
1079
+ }
1080
+
1081
+ /**
1082
+ * Returns the subgroup size builtin.
1083
+ *
1084
+ * @return {string} The subgroup size.
1085
+ */
626
1086
  getSubgroupSize() {
627
1087
 
628
1088
  this.enableSubGroups();
@@ -631,44 +1091,104 @@ ${ flowData.code }
631
1091
 
632
1092
  }
633
1093
 
1094
+ /**
1095
+ * Returns the invocation subgroup index builtin.
1096
+ *
1097
+ * @return {string} The invocation subgroup index.
1098
+ */
1099
+ getInvocationSubgroupIndex() {
1100
+
1101
+ this.enableSubGroups();
1102
+
1103
+ return this.getBuiltin( 'subgroup_invocation_id', 'invocationSubgroupIndex', 'u32', 'attribute' );
1104
+
1105
+ }
1106
+
1107
+ /**
1108
+ * Returns the subgroup index builtin.
1109
+ *
1110
+ * @return {string} The subgroup index.
1111
+ */
634
1112
  getSubgroupIndex() {
635
1113
 
636
1114
  this.enableSubGroups();
637
1115
 
638
- return this.getBuiltin( 'subgroup_invocation_id', 'subgroupIndex', 'u32', 'attribute' );
1116
+ return this.getBuiltin( 'subgroup_id', 'subgroupIndex', 'u32', 'attribute' );
639
1117
 
640
1118
  }
641
1119
 
1120
+ /**
1121
+ * Overwritten as a NOP since this method is intended for the WebGL 2 backend.
1122
+ *
1123
+ * @return {null} Null.
1124
+ */
642
1125
  getDrawIndex() {
643
1126
 
644
1127
  return null;
645
1128
 
646
1129
  }
647
1130
 
1131
+ /**
1132
+ * Returns the front facing builtin.
1133
+ *
1134
+ * @return {string} The front facing builtin.
1135
+ */
648
1136
  getFrontFacing() {
649
1137
 
650
1138
  return this.getBuiltin( 'front_facing', 'isFront', 'bool' );
651
1139
 
652
1140
  }
653
1141
 
1142
+ /**
1143
+ * Returns the frag coord builtin.
1144
+ *
1145
+ * @return {string} The frag coord builtin.
1146
+ */
654
1147
  getFragCoord() {
655
1148
 
656
- return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xyz';
1149
+ return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xy';
657
1150
 
658
1151
  }
659
1152
 
1153
+ /**
1154
+ * Returns the frag depth builtin.
1155
+ *
1156
+ * @return {string} The frag depth builtin.
1157
+ */
660
1158
  getFragDepth() {
661
1159
 
662
1160
  return 'output.' + this.getBuiltin( 'frag_depth', 'depth', 'f32', 'output' );
663
1161
 
664
1162
  }
665
1163
 
1164
+ /**
1165
+ * Returns the clip distances builtin.
1166
+ *
1167
+ * @return {string} The clip distances builtin.
1168
+ */
1169
+ getClipDistance() {
1170
+
1171
+ return 'varyings.hw_clip_distances';
1172
+
1173
+ }
1174
+
1175
+ /**
1176
+ * Whether to flip texture data along its vertical axis or not.
1177
+ *
1178
+ * @return {boolean} Returns always `false` in context of WGSL.
1179
+ */
666
1180
  isFlipY() {
667
1181
 
668
1182
  return false;
669
1183
 
670
1184
  }
671
1185
 
1186
+ /**
1187
+ * Enables the given directive for the given shader stage.
1188
+ *
1189
+ * @param {string} name - The directive name.
1190
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage to enable the directive for.
1191
+ */
672
1192
  enableDirective( name, shaderStage = this.shaderStage ) {
673
1193
 
674
1194
  const stage = this.directives[ shaderStage ] || ( this.directives[ shaderStage ] = new Set() );
@@ -676,6 +1196,12 @@ ${ flowData.code }
676
1196
 
677
1197
  }
678
1198
 
1199
+ /**
1200
+ * Returns the directives of the given shader stage as a WGSL string.
1201
+ *
1202
+ * @param {string} shaderStage - The shader stage.
1203
+ * @return {string} A WGSL snippet that enables the directives of the given stage.
1204
+ */
679
1205
  getDirectives( shaderStage ) {
680
1206
 
681
1207
  const snippets = [];
@@ -695,36 +1221,69 @@ ${ flowData.code }
695
1221
 
696
1222
  }
697
1223
 
1224
+ /**
1225
+ * Enables the 'subgroups' directive.
1226
+ */
698
1227
  enableSubGroups() {
699
1228
 
700
1229
  this.enableDirective( 'subgroups' );
701
1230
 
702
1231
  }
703
1232
 
1233
+ /**
1234
+ * Enables the 'subgroups-f16' directive.
1235
+ */
704
1236
  enableSubgroupsF16() {
705
1237
 
706
1238
  this.enableDirective( 'subgroups-f16' );
707
1239
 
708
1240
  }
709
1241
 
1242
+ /**
1243
+ * Enables the 'clip_distances' directive.
1244
+ */
710
1245
  enableClipDistances() {
711
1246
 
712
1247
  this.enableDirective( 'clip_distances' );
713
1248
 
714
1249
  }
715
1250
 
1251
+ /**
1252
+ * Enables the 'f16' directive.
1253
+ */
716
1254
  enableShaderF16() {
717
1255
 
718
1256
  this.enableDirective( 'f16' );
719
1257
 
720
1258
  }
721
1259
 
1260
+ /**
1261
+ * Enables the 'dual_source_blending' directive.
1262
+ */
722
1263
  enableDualSourceBlending() {
723
1264
 
724
1265
  this.enableDirective( 'dual_source_blending' );
725
1266
 
726
1267
  }
727
1268
 
1269
+ /**
1270
+ * Enables hardware clipping.
1271
+ *
1272
+ * @param {string} planeCount - The clipping plane count.
1273
+ */
1274
+ enableHardwareClipping( planeCount ) {
1275
+
1276
+ this.enableClipDistances();
1277
+ this.getBuiltin( 'clip_distances', 'hw_clip_distances', `array<f32, ${ planeCount } >`, 'vertex' );
1278
+
1279
+ }
1280
+
1281
+ /**
1282
+ * Returns the builtins of the given shader stage as a WGSL string.
1283
+ *
1284
+ * @param {string} shaderStage - The shader stage.
1285
+ * @return {string} A WGSL snippet that represents the builtins of the given stage.
1286
+ */
728
1287
  getBuiltins( shaderStage ) {
729
1288
 
730
1289
  const snippets = [];
@@ -744,17 +1303,87 @@ ${ flowData.code }
744
1303
 
745
1304
  }
746
1305
 
1306
+ /**
1307
+ * This method should be used when a new scoped buffer is used in context of
1308
+ * compute shaders. It adds the array to the internal data structure which is
1309
+ * later used to generate the respective WGSL.
1310
+ *
1311
+ * @param {string} name - The array name.
1312
+ * @param {string} scope - The scope.
1313
+ * @param {string} bufferType - The buffer type.
1314
+ * @param {string} bufferCount - The buffer count.
1315
+ * @return {string} The array name.
1316
+ */
1317
+ getScopedArray( name, scope, bufferType, bufferCount ) {
1318
+
1319
+ if ( this.scopedArrays.has( name ) === false ) {
1320
+
1321
+ this.scopedArrays.set( name, {
1322
+ name,
1323
+ scope,
1324
+ bufferType,
1325
+ bufferCount
1326
+ } );
1327
+
1328
+ }
1329
+
1330
+ return name;
1331
+
1332
+ }
1333
+
1334
+ /**
1335
+ * Returns the scoped arrays of the given shader stage as a WGSL string.
1336
+ *
1337
+ * @param {string} shaderStage - The shader stage.
1338
+ * @return {string|undefined} The WGSL snippet that defines the scoped arrays.
1339
+ * Returns `undefined` when used in the vertex or fragment stage.
1340
+ */
1341
+ getScopedArrays( shaderStage ) {
1342
+
1343
+ if ( shaderStage !== 'compute' ) {
1344
+
1345
+ return;
1346
+
1347
+ }
1348
+
1349
+ const snippets = [];
1350
+
1351
+ for ( const { name, scope, bufferType, bufferCount } of this.scopedArrays.values() ) {
1352
+
1353
+ const type = this.getType( bufferType );
1354
+
1355
+ snippets.push( `var<${scope}> ${name}: array< ${type}, ${bufferCount} >;` );
1356
+
1357
+ }
1358
+
1359
+ return snippets.join( '\n' );
1360
+
1361
+ }
1362
+
1363
+ /**
1364
+ * Returns the shader attributes of the given shader stage as a WGSL string.
1365
+ *
1366
+ * @param {string} shaderStage - The shader stage.
1367
+ * @return {string} The WGSL snippet that defines the shader attributes.
1368
+ */
747
1369
  getAttributes( shaderStage ) {
748
1370
 
749
1371
  const snippets = [];
750
1372
 
751
1373
  if ( shaderStage === 'compute' ) {
752
1374
 
753
- this.getBuiltin( 'global_invocation_id', 'id', 'vec3<u32>', 'attribute' );
1375
+ this.getBuiltin( 'global_invocation_id', 'globalId', 'vec3<u32>', 'attribute' );
754
1376
  this.getBuiltin( 'workgroup_id', 'workgroupId', 'vec3<u32>', 'attribute' );
755
1377
  this.getBuiltin( 'local_invocation_id', 'localId', 'vec3<u32>', 'attribute' );
756
1378
  this.getBuiltin( 'num_workgroups', 'numWorkgroups', 'vec3<u32>', 'attribute' );
757
1379
 
1380
+ if ( this.renderer.hasFeature( 'subgroups' ) ) {
1381
+
1382
+ this.enableDirective( 'subgroups', shaderStage );
1383
+ this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' );
1384
+
1385
+ }
1386
+
758
1387
  }
759
1388
 
760
1389
  if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
@@ -781,57 +1410,108 @@ ${ flowData.code }
781
1410
 
782
1411
  }
783
1412
 
1413
+ /**
1414
+ * Returns the members of the given struct type node as a WGSL string.
1415
+ *
1416
+ * @param {StructTypeNode} struct - The struct type node.
1417
+ * @return {string} The WGSL snippet that defines the struct members.
1418
+ */
784
1419
  getStructMembers( struct ) {
785
1420
 
786
1421
  const snippets = [];
787
- const members = struct.getMemberTypes();
788
1422
 
789
- for ( let i = 0; i < members.length; i ++ ) {
1423
+ for ( const member of struct.members ) {
790
1424
 
791
- const member = members[ i ];
792
- snippets.push( `\t@location( ${i} ) m${i} : ${ member }<f32>` );
1425
+ const prefix = struct.output ? '@location( ' + member.index + ' ) ' : '';
1426
+
1427
+ let type = this.getType( member.type );
1428
+
1429
+ if ( member.atomic ) {
1430
+
1431
+ type = 'atomic< ' + type + ' >';
1432
+
1433
+ }
1434
+
1435
+ snippets.push( `\t${ prefix + member.name } : ${ type }` );
793
1436
 
794
1437
  }
795
1438
 
796
- const builtins = this.getBuiltins( 'output' );
1439
+ if ( struct.output ) {
797
1440
 
798
- if ( builtins ) snippets.push( builtins );
1441
+ snippets.push( `\t${ this.getBuiltins( 'output' ) }` );
1442
+
1443
+ }
799
1444
 
800
1445
  return snippets.join( ',\n' );
801
1446
 
802
1447
  }
803
1448
 
1449
+ /**
1450
+ * Returns the structs of the given shader stage as a WGSL string.
1451
+ *
1452
+ * @param {string} shaderStage - The shader stage.
1453
+ * @return {string} The WGSL snippet that defines the structs.
1454
+ */
804
1455
  getStructs( shaderStage ) {
805
1456
 
806
- const snippets = [];
1457
+ let result = '';
1458
+
807
1459
  const structs = this.structs[ shaderStage ];
808
1460
 
809
- for ( let index = 0, length = structs.length; index < length; index ++ ) {
1461
+ if ( structs.length > 0 ) {
810
1462
 
811
- const struct = structs[ index ];
812
- const name = struct.name;
1463
+ const snippets = [];
813
1464
 
814
- let snippet = `\struct ${ name } {\n`;
815
- snippet += this.getStructMembers( struct );
816
- snippet += '\n}';
1465
+ for ( const struct of structs ) {
817
1466
 
1467
+ let snippet = `struct ${ struct.name } {\n`;
1468
+ snippet += this.getStructMembers( struct );
1469
+ snippet += '\n};';
818
1470
 
819
- snippets.push( snippet );
1471
+ snippets.push( snippet );
820
1472
 
821
- snippets.push( `\nvar<private> output : ${ name };\n\n` );
1473
+ }
1474
+
1475
+ result = '\n' + snippets.join( '\n\n' ) + '\n';
822
1476
 
823
1477
  }
824
1478
 
825
- return snippets.join( '\n\n' );
1479
+ return result;
826
1480
 
827
1481
  }
828
1482
 
829
- getVar( type, name ) {
1483
+ /**
1484
+ * Returns a WGSL string representing a variable.
1485
+ *
1486
+ * @param {string} type - The variable's type.
1487
+ * @param {string} name - The variable's name.
1488
+ * @param {?number} [count=null] - The array length.
1489
+ * @return {string} The WGSL snippet that defines a variable.
1490
+ */
1491
+ getVar( type, name, count = null ) {
1492
+
1493
+ let snippet = `var ${ name } : `;
1494
+
1495
+ if ( count !== null ) {
1496
+
1497
+ snippet += this.generateArrayDeclaration( type, count );
1498
+
1499
+ } else {
1500
+
1501
+ snippet += this.getType( type );
1502
+
1503
+ }
830
1504
 
831
- return `var ${ name } : ${ this.getType( type ) }`;
1505
+ return snippet;
832
1506
 
833
1507
  }
834
1508
 
1509
+ /**
1510
+ * Returns the variables of the given shader stage as a WGSL string.
1511
+ *
1512
+ * @param {string} shaderStage - The shader stage.
1513
+ * @return {string} The WGSL snippet that defines the variables.
1514
+ */
835
1515
  getVars( shaderStage ) {
836
1516
 
837
1517
  const snippets = [];
@@ -841,7 +1521,7 @@ ${ flowData.code }
841
1521
 
842
1522
  for ( const variable of vars ) {
843
1523
 
844
- snippets.push( `\t${ this.getVar( variable.type, variable.name ) };` );
1524
+ snippets.push( `\t${ this.getVar( variable.type, variable.name, variable.count ) };` );
845
1525
 
846
1526
  }
847
1527
 
@@ -851,6 +1531,12 @@ ${ flowData.code }
851
1531
 
852
1532
  }
853
1533
 
1534
+ /**
1535
+ * Returns the varyings of the given shader stage as a WGSL string.
1536
+ *
1537
+ * @param {string} shaderStage - The shader stage.
1538
+ * @return {string} The WGSL snippet that defines the varyings.
1539
+ */
854
1540
  getVaryings( shaderStage ) {
855
1541
 
856
1542
  const snippets = [];
@@ -903,6 +1589,18 @@ ${ flowData.code }
903
1589
 
904
1590
  }
905
1591
 
1592
+ isCustomStruct( nodeUniform ) {
1593
+
1594
+ return nodeUniform.value.isStorageBufferAttribute && nodeUniform.node.structTypeNode !== null;
1595
+
1596
+ }
1597
+
1598
+ /**
1599
+ * Returns the uniforms of the given shader stage as a WGSL string.
1600
+ *
1601
+ * @param {string} shaderStage - The shader stage.
1602
+ * @return {string} The WGSL snippet that defines the uniforms.
1603
+ */
906
1604
  getUniforms( shaderStage ) {
907
1605
 
908
1606
  const uniforms = this.uniforms[ shaderStage ];
@@ -914,16 +1612,16 @@ ${ flowData.code }
914
1612
 
915
1613
  for ( const uniform of uniforms ) {
916
1614
 
917
- const groundName = uniform.groupNode.name;
918
- const uniformIndexes = this.bindingsIndexes[ groundName ];
1615
+ const groupName = uniform.groupNode.name;
1616
+ const uniformIndexes = this.bindingsIndexes[ groupName ];
919
1617
 
920
1618
  if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
921
1619
 
922
1620
  const texture = uniform.node.value;
923
1621
 
924
- if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true ) {
1622
+ if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true ) {
925
1623
 
926
- if ( texture.isDepthTexture === true && texture.compareFunction !== null ) {
1624
+ if ( this.isSampleCompare( texture ) ) {
927
1625
 
928
1626
  bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler_comparison;` );
929
1627
 
@@ -939,7 +1637,9 @@ ${ flowData.code }
939
1637
 
940
1638
  let multisampled = '';
941
1639
 
942
- if ( texture.isMultisampleRenderTargetTexture === true ) {
1640
+ const { primarySamples } = this.renderer.backend.utils.getTextureSampleData( texture );
1641
+
1642
+ if ( primarySamples > 1 ) {
943
1643
 
944
1644
  multisampled = '_multisampled';
945
1645
 
@@ -949,7 +1649,7 @@ ${ flowData.code }
949
1649
 
950
1650
  textureType = 'texture_cube<f32>';
951
1651
 
952
- } else if ( texture.isDataArrayTexture === true ) {
1652
+ } else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
953
1653
 
954
1654
  textureType = 'texture_2d_array<f32>';
955
1655
 
@@ -968,7 +1668,7 @@ ${ flowData.code }
968
1668
  } else if ( uniform.node.isStorageTextureNode === true ) {
969
1669
 
970
1670
  const format = getFormat( texture );
971
- const access = this.getStorageAccess( uniform.node );
1671
+ const access = this.getStorageAccess( uniform.node, shaderStage );
972
1672
 
973
1673
  textureType = `texture_storage_2d<${ format }, ${ access }>`;
974
1674
 
@@ -976,23 +1676,32 @@ ${ flowData.code }
976
1676
 
977
1677
  const componentPrefix = this.getComponentTypeFromTexture( texture ).charAt( 0 );
978
1678
 
979
- textureType = `texture${multisampled}_2d<${ componentPrefix }32>`;
1679
+ textureType = `texture${ multisampled }_2d<${ componentPrefix }32>`;
980
1680
 
981
1681
  }
982
1682
 
983
1683
  bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name } : ${ textureType };` );
984
1684
 
985
- } else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' ) {
1685
+ } else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' || uniform.type === 'indirectStorageBuffer' ) {
986
1686
 
987
1687
  const bufferNode = uniform.node;
988
- const bufferType = this.getType( bufferNode.bufferType );
1688
+ const bufferType = this.getType( bufferNode.getNodeType( this ) );
989
1689
  const bufferCount = bufferNode.bufferCount;
1690
+ const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : '';
1691
+ const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode, shaderStage ) }` : 'uniform';
990
1692
 
991
- const bufferCountSnippet = bufferCount > 0 ? ', ' + bufferCount : '';
992
- const bufferSnippet = `\t${ uniform.name } : array< ${ bufferType }${ bufferCountSnippet } >\n`;
993
- const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform';
1693
+ if ( this.isCustomStruct( uniform ) ) {
994
1694
 
995
- bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) );
1695
+ bufferSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var<${ bufferAccessMode }> ${ uniform.name } : ${ bufferType };` );
1696
+
1697
+ } else {
1698
+
1699
+ const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${ bufferType }>` : `${ bufferType }`;
1700
+ const bufferSnippet = `\tvalue : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >`;
1701
+
1702
+ bufferSnippets.push( this._getWGSLStructBinding( uniform.name, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) );
1703
+
1704
+ }
996
1705
 
997
1706
  } else {
998
1707
 
@@ -1027,12 +1736,19 @@ ${ flowData.code }
1027
1736
 
1028
1737
  }
1029
1738
 
1739
+ /**
1740
+ * Controls the code build of the shader stages.
1741
+ */
1030
1742
  buildCode() {
1031
1743
 
1032
1744
  const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
1033
1745
 
1746
+ this.sortBindingGroups();
1747
+
1034
1748
  for ( const shaderStage in shadersData ) {
1035
1749
 
1750
+ this.shaderStage = shaderStage;
1751
+
1036
1752
  const stageData = shadersData[ shaderStage ];
1037
1753
  stageData.uniforms = this.getUniforms( shaderStage );
1038
1754
  stageData.attributes = this.getAttributes( shaderStage );
@@ -1041,6 +1757,7 @@ ${ flowData.code }
1041
1757
  stageData.vars = this.getVars( shaderStage );
1042
1758
  stageData.codes = this.getCodes( shaderStage );
1043
1759
  stageData.directives = this.getDirectives( shaderStage );
1760
+ stageData.scopedArrays = this.getScopedArrays( shaderStage );
1044
1761
 
1045
1762
  //
1046
1763
 
@@ -1062,7 +1779,7 @@ ${ flowData.code }
1062
1779
 
1063
1780
  if ( flow.length > 0 ) flow += '\n';
1064
1781
 
1065
- flow += `\t// flow -> ${ slotName }\n\t`;
1782
+ flow += `\t// flow -> ${ slotName }\n`;
1066
1783
 
1067
1784
  }
1068
1785
 
@@ -1080,7 +1797,8 @@ ${ flowData.code }
1080
1797
 
1081
1798
  if ( isOutputStruct ) {
1082
1799
 
1083
- stageData.returnType = outputNode.nodeType;
1800
+ stageData.returnType = outputNode.getNodeType( this );
1801
+ stageData.structs += 'var<private> output : ' + stageData.returnType + ';';
1084
1802
 
1085
1803
  flow += `return ${ flowSlotData.result };`;
1086
1804
 
@@ -1094,7 +1812,7 @@ ${ flowData.code }
1094
1812
 
1095
1813
  stageData.returnType = 'OutputStruct';
1096
1814
  stageData.structs += this._getWGSLStruct( 'OutputStruct', structSnippet );
1097
- stageData.structs += '\nvar<private> output : OutputStruct;\n\n';
1815
+ stageData.structs += '\nvar<private> output : OutputStruct;';
1098
1816
 
1099
1817
  flow += `output.color = ${ flowSlotData.result };\n\n\treturn output;`;
1100
1818
 
@@ -1108,9 +1826,10 @@ ${ flowData.code }
1108
1826
 
1109
1827
  stageData.flow = flow;
1110
1828
 
1111
-
1112
1829
  }
1113
1830
 
1831
+ this.shaderStage = null;
1832
+
1114
1833
  if ( this.material !== null ) {
1115
1834
 
1116
1835
  this.vertexShader = this._getWGSLVertexCode( shadersData.vertex );
@@ -1124,6 +1843,13 @@ ${ flowData.code }
1124
1843
 
1125
1844
  }
1126
1845
 
1846
+ /**
1847
+ * Returns the native shader method name for a given generic name.
1848
+ *
1849
+ * @param {string} method - The method name to resolve.
1850
+ * @param {?string} [output=null] - An optional output.
1851
+ * @return {string} The resolved WGSL method name.
1852
+ */
1127
1853
  getMethod( method, output = null ) {
1128
1854
 
1129
1855
  let wgslMethod;
@@ -1144,12 +1870,24 @@ ${ flowData.code }
1144
1870
 
1145
1871
  }
1146
1872
 
1873
+ /**
1874
+ * Returns the WGSL type of the given node data type.
1875
+ *
1876
+ * @param {string} type - The node data type.
1877
+ * @return {string} The WGSL type.
1878
+ */
1147
1879
  getType( type ) {
1148
1880
 
1149
1881
  return wgslTypeLib[ type ] || type;
1150
1882
 
1151
1883
  }
1152
1884
 
1885
+ /**
1886
+ * Whether the requested feature is available or not.
1887
+ *
1888
+ * @param {string} name - The requested feature.
1889
+ * @return {boolean} Whether the requested feature is supported or not.
1890
+ */
1153
1891
  isAvailable( name ) {
1154
1892
 
1155
1893
  let result = supports[ name ];
@@ -1160,6 +1898,10 @@ ${ flowData.code }
1160
1898
 
1161
1899
  result = this.renderer.hasFeature( 'float32-filterable' );
1162
1900
 
1901
+ } else if ( name === 'clipDistance' ) {
1902
+
1903
+ result = this.renderer.hasFeature( 'clip-distances' );
1904
+
1163
1905
  }
1164
1906
 
1165
1907
  supports[ name ] = result;
@@ -1170,6 +1912,13 @@ ${ flowData.code }
1170
1912
 
1171
1913
  }
1172
1914
 
1915
+ /**
1916
+ * Returns the native shader method name for a given generic name.
1917
+ *
1918
+ * @private
1919
+ * @param {string} method - The method name to resolve.
1920
+ * @return {string} The resolved WGSL method name.
1921
+ */
1173
1922
  _getWGSLMethod( method ) {
1174
1923
 
1175
1924
  if ( wgslPolyfill[ method ] !== undefined ) {
@@ -1182,6 +1931,14 @@ ${ flowData.code }
1182
1931
 
1183
1932
  }
1184
1933
 
1934
+ /**
1935
+ * Includes the given method name into the current
1936
+ * function node.
1937
+ *
1938
+ * @private
1939
+ * @param {string} name - The method name to include.
1940
+ * @return {CodeNode} The respective code node.
1941
+ */
1185
1942
  _include( name ) {
1186
1943
 
1187
1944
  const codeNode = wgslPolyfill[ name ];
@@ -1197,12 +1954,22 @@ ${ flowData.code }
1197
1954
 
1198
1955
  }
1199
1956
 
1957
+ /**
1958
+ * Returns a WGSL vertex shader based on the given shader data.
1959
+ *
1960
+ * @private
1961
+ * @param {Object} shaderData - The shader data.
1962
+ * @return {string} The vertex shader.
1963
+ */
1200
1964
  _getWGSLVertexCode( shaderData ) {
1201
1965
 
1202
1966
  return `${ this.getSignature() }
1203
1967
  // directives
1204
1968
  ${shaderData.directives}
1205
1969
 
1970
+ // structs
1971
+ ${shaderData.structs}
1972
+
1206
1973
  // uniforms
1207
1974
  ${shaderData.uniforms}
1208
1975
 
@@ -1229,18 +1996,25 @@ fn main( ${shaderData.attributes} ) -> VaryingsStruct {
1229
1996
 
1230
1997
  }
1231
1998
 
1999
+ /**
2000
+ * Returns a WGSL fragment shader based on the given shader data.
2001
+ *
2002
+ * @private
2003
+ * @param {Object} shaderData - The shader data.
2004
+ * @return {string} The vertex shader.
2005
+ */
1232
2006
  _getWGSLFragmentCode( shaderData ) {
1233
2007
 
1234
2008
  return `${ this.getSignature() }
2009
+ // global
2010
+ ${ diagnostics }
1235
2011
 
1236
- diagnostic( off, derivative_uniformity );
2012
+ // structs
2013
+ ${shaderData.structs}
1237
2014
 
1238
2015
  // uniforms
1239
2016
  ${shaderData.uniforms}
1240
2017
 
1241
- // structs
1242
- ${shaderData.structs}
1243
-
1244
2018
  // codes
1245
2019
  ${shaderData.codes}
1246
2020
 
@@ -1258,6 +2032,14 @@ fn main( ${shaderData.varyings} ) -> ${shaderData.returnType} {
1258
2032
 
1259
2033
  }
1260
2034
 
2035
+ /**
2036
+ * Returns a WGSL compute shader based on the given shader data.
2037
+ *
2038
+ * @private
2039
+ * @param {Object} shaderData - The shader data.
2040
+ * @param {string} workgroupSize - The workgroup size.
2041
+ * @return {string} The vertex shader.
2042
+ */
1261
2043
  _getWGSLComputeCode( shaderData, workgroupSize ) {
1262
2044
 
1263
2045
  return `${ this.getSignature() }
@@ -1267,6 +2049,12 @@ ${shaderData.directives}
1267
2049
  // system
1268
2050
  var<private> instanceIndex : u32;
1269
2051
 
2052
+ // locals
2053
+ ${shaderData.scopedArrays}
2054
+
2055
+ // structs
2056
+ ${shaderData.structs}
2057
+
1270
2058
  // uniforms
1271
2059
  ${shaderData.uniforms}
1272
2060
 
@@ -1277,7 +2065,7 @@ ${shaderData.codes}
1277
2065
  fn main( ${shaderData.attributes} ) {
1278
2066
 
1279
2067
  // system
1280
- instanceIndex = id.x + id.y * numWorkgroups.x * u32(${workgroupSize}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${workgroupSize});
2068
+ instanceIndex = globalId.x + globalId.y * numWorkgroups.x * u32(${workgroupSize}) + globalId.z * numWorkgroups.x * numWorkgroups.y * u32(${workgroupSize});
1281
2069
 
1282
2070
  // vars
1283
2071
  ${shaderData.vars}
@@ -1290,6 +2078,14 @@ fn main( ${shaderData.attributes} ) {
1290
2078
 
1291
2079
  }
1292
2080
 
2081
+ /**
2082
+ * Returns a WGSL struct based on the given name and variables.
2083
+ *
2084
+ * @private
2085
+ * @param {string} name - The struct name.
2086
+ * @param {string} vars - The struct variables.
2087
+ * @return {string} The WGSL snippet representing a struct.
2088
+ */
1293
2089
  _getWGSLStruct( name, vars ) {
1294
2090
 
1295
2091
  return `
@@ -1299,14 +2095,25 @@ ${vars}
1299
2095
 
1300
2096
  }
1301
2097
 
2098
+ /**
2099
+ * Returns a WGSL struct binding.
2100
+ *
2101
+ * @private
2102
+ * @param {string} name - The struct name.
2103
+ * @param {string} vars - The struct variables.
2104
+ * @param {string} access - The access.
2105
+ * @param {number} [binding=0] - The binding index.
2106
+ * @param {number} [group=0] - The group index.
2107
+ * @return {string} The WGSL snippet representing a struct binding.
2108
+ */
1302
2109
  _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) {
1303
2110
 
1304
2111
  const structName = name + 'Struct';
1305
2112
  const structSnippet = this._getWGSLStruct( structName, vars );
1306
2113
 
1307
2114
  return `${structSnippet}
1308
- @binding( ${binding} ) @group( ${group} )
1309
- var<${access}> ${name} : ${structName};`;
2115
+ @binding( ${ binding } ) @group( ${ group } )
2116
+ var<${access}> ${ name } : ${ structName };`;
1310
2117
 
1311
2118
  }
1312
2119