@gnsx/three 0.184.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 (1182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +85 -0
  3. package/build/three.cjs +79695 -0
  4. package/build/three.core.js +59732 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +19552 -0
  7. package/build/three.module.min.js +6 -0
  8. package/build/three.tsl.js +654 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +83969 -0
  11. package/build/three.webgpu.min.js +6 -0
  12. package/build/three.webgpu.nodes.js +83702 -0
  13. package/build/three.webgpu.nodes.min.js +6 -0
  14. package/examples/fonts/LICENSE +13 -0
  15. package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
  16. package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
  17. package/examples/fonts/README.md +11 -0
  18. package/examples/fonts/droid/NOTICE +190 -0
  19. package/examples/fonts/droid/README.txt +18 -0
  20. package/examples/fonts/droid/droid_sans_bold.typeface.json +1 -0
  21. package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +1 -0
  22. package/examples/fonts/droid/droid_sans_regular.typeface.json +1 -0
  23. package/examples/fonts/droid/droid_serif_bold.typeface.json +1 -0
  24. package/examples/fonts/droid/droid_serif_regular.typeface.json +1 -0
  25. package/examples/fonts/gentilis_bold.typeface.json +1 -0
  26. package/examples/fonts/gentilis_regular.typeface.json +1 -0
  27. package/examples/fonts/helvetiker_bold.typeface.json +1 -0
  28. package/examples/fonts/helvetiker_regular.typeface.json +1 -0
  29. package/examples/fonts/optimer_bold.typeface.json +1 -0
  30. package/examples/fonts/optimer_regular.typeface.json +1 -0
  31. package/examples/fonts/ttf/README.md +9 -0
  32. package/examples/fonts/ttf/kenpixel.ttf +0 -0
  33. package/examples/jsm/Addons.js +293 -0
  34. package/examples/jsm/animation/AnimationClipCreator.js +168 -0
  35. package/examples/jsm/animation/CCDIKSolver.js +595 -0
  36. package/examples/jsm/capabilities/WebGL.js +113 -0
  37. package/examples/jsm/capabilities/WebGPU.js +59 -0
  38. package/examples/jsm/controls/ArcballControls.js +3539 -0
  39. package/examples/jsm/controls/DragControls.js +452 -0
  40. package/examples/jsm/controls/FirstPersonControls.js +451 -0
  41. package/examples/jsm/controls/FlyControls.js +384 -0
  42. package/examples/jsm/controls/MapControls.js +116 -0
  43. package/examples/jsm/controls/OrbitControls.js +1963 -0
  44. package/examples/jsm/controls/PointerLockControls.js +264 -0
  45. package/examples/jsm/controls/TrackballControls.js +1001 -0
  46. package/examples/jsm/controls/TransformControls.js +1950 -0
  47. package/examples/jsm/csm/CSM.js +598 -0
  48. package/examples/jsm/csm/CSMFrustum.js +209 -0
  49. package/examples/jsm/csm/CSMHelper.js +243 -0
  50. package/examples/jsm/csm/CSMShader.js +307 -0
  51. package/examples/jsm/csm/CSMShadowNode.js +603 -0
  52. package/examples/jsm/curves/CurveExtras.js +694 -0
  53. package/examples/jsm/curves/NURBSCurve.js +155 -0
  54. package/examples/jsm/curves/NURBSSurface.js +98 -0
  55. package/examples/jsm/curves/NURBSUtils.js +532 -0
  56. package/examples/jsm/curves/NURBSVolume.js +82 -0
  57. package/examples/jsm/effects/AnaglyphEffect.js +274 -0
  58. package/examples/jsm/effects/AsciiEffect.js +310 -0
  59. package/examples/jsm/effects/OutlineEffect.js +489 -0
  60. package/examples/jsm/effects/ParallaxBarrierEffect.js +155 -0
  61. package/examples/jsm/effects/StereoEffect.js +91 -0
  62. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  63. package/examples/jsm/environments/DebugEnvironment.js +102 -0
  64. package/examples/jsm/environments/RoomEnvironment.js +185 -0
  65. package/examples/jsm/exporters/DRACOExporter.js +311 -0
  66. package/examples/jsm/exporters/EXRExporter.js +618 -0
  67. package/examples/jsm/exporters/GLTFExporter.js +3738 -0
  68. package/examples/jsm/exporters/KTX2Exporter.js +347 -0
  69. package/examples/jsm/exporters/OBJExporter.js +308 -0
  70. package/examples/jsm/exporters/PLYExporter.js +562 -0
  71. package/examples/jsm/exporters/STLExporter.js +221 -0
  72. package/examples/jsm/exporters/USDZExporter.js +1254 -0
  73. package/examples/jsm/geometries/BoxLineGeometry.js +92 -0
  74. package/examples/jsm/geometries/ConvexGeometry.js +72 -0
  75. package/examples/jsm/geometries/DecalGeometry.js +420 -0
  76. package/examples/jsm/geometries/ParametricFunctions.js +100 -0
  77. package/examples/jsm/geometries/ParametricGeometry.js +172 -0
  78. package/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  79. package/examples/jsm/geometries/TeapotGeometry.js +689 -0
  80. package/examples/jsm/geometries/TextGeometry.js +102 -0
  81. package/examples/jsm/gpgpu/BitonicSort.js +715 -0
  82. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  83. package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
  84. package/examples/jsm/helpers/LightProbeHelper.js +165 -0
  85. package/examples/jsm/helpers/LightProbeHelperGPU.js +102 -0
  86. package/examples/jsm/helpers/OctreeHelper.js +109 -0
  87. package/examples/jsm/helpers/PositionalAudioHelper.js +169 -0
  88. package/examples/jsm/helpers/RapierHelper.js +59 -0
  89. package/examples/jsm/helpers/RectAreaLightHelper.js +118 -0
  90. package/examples/jsm/helpers/TextureHelper.js +265 -0
  91. package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
  92. package/examples/jsm/helpers/VertexNormalsHelper.js +155 -0
  93. package/examples/jsm/helpers/VertexTangentsHelper.js +133 -0
  94. package/examples/jsm/helpers/ViewHelper.js +519 -0
  95. package/examples/jsm/inspector/Extension.js +13 -0
  96. package/examples/jsm/inspector/Inspector.js +542 -0
  97. package/examples/jsm/inspector/RendererInspector.js +425 -0
  98. package/examples/jsm/inspector/extensions/extensions.json +6 -0
  99. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
  100. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
  101. package/examples/jsm/inspector/tabs/Console.js +238 -0
  102. package/examples/jsm/inspector/tabs/Memory.js +128 -0
  103. package/examples/jsm/inspector/tabs/Parameters.js +380 -0
  104. package/examples/jsm/inspector/tabs/Performance.js +268 -0
  105. package/examples/jsm/inspector/tabs/Settings.js +264 -0
  106. package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
  107. package/examples/jsm/inspector/tabs/Viewer.js +268 -0
  108. package/examples/jsm/inspector/ui/Graph.js +95 -0
  109. package/examples/jsm/inspector/ui/Item.js +170 -0
  110. package/examples/jsm/inspector/ui/List.js +75 -0
  111. package/examples/jsm/inspector/ui/Profiler.js +2072 -0
  112. package/examples/jsm/inspector/ui/Style.js +1667 -0
  113. package/examples/jsm/inspector/ui/Tab.js +265 -0
  114. package/examples/jsm/inspector/ui/Values.js +476 -0
  115. package/examples/jsm/inspector/ui/utils.js +69 -0
  116. package/examples/jsm/interaction/InteractionManager.js +226 -0
  117. package/examples/jsm/interactive/HTMLMesh.js +601 -0
  118. package/examples/jsm/interactive/InteractiveGroup.js +224 -0
  119. package/examples/jsm/interactive/SelectionBox.js +324 -0
  120. package/examples/jsm/interactive/SelectionHelper.js +150 -0
  121. package/examples/jsm/libs/ammo.wasm.js +822 -0
  122. package/examples/jsm/libs/ammo.wasm.wasm +0 -0
  123. package/examples/jsm/libs/basis/README.md +46 -0
  124. package/examples/jsm/libs/basis/basis_transcoder.js +19 -0
  125. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  126. package/examples/jsm/libs/chevrotain.module.min.js +141 -0
  127. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  128. package/examples/jsm/libs/draco/README.md +32 -0
  129. package/examples/jsm/libs/draco/draco_decoder.js +34 -0
  130. package/examples/jsm/libs/draco/draco_decoder.wasm +0 -0
  131. package/examples/jsm/libs/draco/draco_encoder.js +33 -0
  132. package/examples/jsm/libs/draco/draco_wasm_wrapper.js +117 -0
  133. package/examples/jsm/libs/draco/gltf/draco_decoder.js +33 -0
  134. package/examples/jsm/libs/draco/gltf/draco_decoder.wasm +0 -0
  135. package/examples/jsm/libs/draco/gltf/draco_encoder.js +33 -0
  136. package/examples/jsm/libs/draco/gltf/draco_wasm_wrapper.js +116 -0
  137. package/examples/jsm/libs/ecsy.module.js +1792 -0
  138. package/examples/jsm/libs/fflate.module.js +2672 -0
  139. package/examples/jsm/libs/ktx-parse.module.js +1 -0
  140. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  141. package/examples/jsm/libs/lottie_canvas.module.js +14849 -0
  142. package/examples/jsm/libs/meshopt_decoder.module.js +196 -0
  143. package/examples/jsm/libs/mikktspace.module.js +128 -0
  144. package/examples/jsm/libs/motion-controllers.module.js +397 -0
  145. package/examples/jsm/libs/opentype.module.js +14506 -0
  146. package/examples/jsm/libs/potpack.module.js +125 -0
  147. package/examples/jsm/libs/rhino3dm/rhino3dm.js +21 -0
  148. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +16 -0
  149. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  150. package/examples/jsm/libs/stats.module.js +167 -0
  151. package/examples/jsm/libs/surfaceNet.js +201 -0
  152. package/examples/jsm/libs/tween.module.js +876 -0
  153. package/examples/jsm/libs/utif.module.js +1665 -0
  154. package/examples/jsm/libs/zstddec.module.js +1 -0
  155. package/examples/jsm/lighting/DynamicLighting.js +82 -0
  156. package/examples/jsm/lighting/LightProbeGrid.js +651 -0
  157. package/examples/jsm/lighting/TiledLighting.js +42 -0
  158. package/examples/jsm/lights/LightProbeGenerator.js +337 -0
  159. package/examples/jsm/lights/RectAreaLightTexturesLib.js +127 -0
  160. package/examples/jsm/lights/RectAreaLightUniformsLib.js +40 -0
  161. package/examples/jsm/lines/Line2.js +56 -0
  162. package/examples/jsm/lines/LineGeometry.js +157 -0
  163. package/examples/jsm/lines/LineMaterial.js +703 -0
  164. package/examples/jsm/lines/LineSegments2.js +426 -0
  165. package/examples/jsm/lines/LineSegmentsGeometry.js +298 -0
  166. package/examples/jsm/lines/Wireframe.js +108 -0
  167. package/examples/jsm/lines/WireframeGeometry2.js +49 -0
  168. package/examples/jsm/lines/webgpu/Line2.js +46 -0
  169. package/examples/jsm/lines/webgpu/LineSegments2.js +411 -0
  170. package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
  171. package/examples/jsm/loaders/3DMLoader.js +1836 -0
  172. package/examples/jsm/loaders/3MFLoader.js +1621 -0
  173. package/examples/jsm/loaders/AMFLoader.js +541 -0
  174. package/examples/jsm/loaders/BVHLoader.js +484 -0
  175. package/examples/jsm/loaders/ColladaLoader.js +153 -0
  176. package/examples/jsm/loaders/DDSLoader.js +385 -0
  177. package/examples/jsm/loaders/DRACOLoader.js +739 -0
  178. package/examples/jsm/loaders/EXRLoader.js +3423 -0
  179. package/examples/jsm/loaders/FBXLoader.js +4580 -0
  180. package/examples/jsm/loaders/FontLoader.js +260 -0
  181. package/examples/jsm/loaders/GCodeLoader.js +318 -0
  182. package/examples/jsm/loaders/GLTFLoader.js +4860 -0
  183. package/examples/jsm/loaders/HDRCubeTextureLoader.js +164 -0
  184. package/examples/jsm/loaders/HDRLoader.js +485 -0
  185. package/examples/jsm/loaders/IESLoader.js +379 -0
  186. package/examples/jsm/loaders/KMZLoader.js +163 -0
  187. package/examples/jsm/loaders/KTX2Loader.js +1257 -0
  188. package/examples/jsm/loaders/KTXLoader.js +197 -0
  189. package/examples/jsm/loaders/LDrawLoader.js +2510 -0
  190. package/examples/jsm/loaders/LUT3dlLoader.js +205 -0
  191. package/examples/jsm/loaders/LUTCubeLoader.js +190 -0
  192. package/examples/jsm/loaders/LUTImageLoader.js +190 -0
  193. package/examples/jsm/loaders/LWOLoader.js +1047 -0
  194. package/examples/jsm/loaders/LottieLoader.js +130 -0
  195. package/examples/jsm/loaders/MD2Loader.js +435 -0
  196. package/examples/jsm/loaders/MDDLoader.js +147 -0
  197. package/examples/jsm/loaders/MTLLoader.js +593 -0
  198. package/examples/jsm/loaders/MaterialXLoader.js +1104 -0
  199. package/examples/jsm/loaders/NRRDLoader.js +718 -0
  200. package/examples/jsm/loaders/OBJLoader.js +955 -0
  201. package/examples/jsm/loaders/PCDLoader.js +620 -0
  202. package/examples/jsm/loaders/PDBLoader.js +272 -0
  203. package/examples/jsm/loaders/PLYLoader.js +805 -0
  204. package/examples/jsm/loaders/PVRLoader.js +270 -0
  205. package/examples/jsm/loaders/RGBELoader.js +18 -0
  206. package/examples/jsm/loaders/STLLoader.js +421 -0
  207. package/examples/jsm/loaders/SVGLoader.js +3267 -0
  208. package/examples/jsm/loaders/TDSLoader.js +1142 -0
  209. package/examples/jsm/loaders/TGALoader.js +538 -0
  210. package/examples/jsm/loaders/TIFFLoader.js +59 -0
  211. package/examples/jsm/loaders/TTFLoader.js +261 -0
  212. package/examples/jsm/loaders/USDLoader.js +279 -0
  213. package/examples/jsm/loaders/USDZLoader.js +16 -0
  214. package/examples/jsm/loaders/UltraHDRLoader.js +755 -0
  215. package/examples/jsm/loaders/VOXLoader.js +919 -0
  216. package/examples/jsm/loaders/VRMLLoader.js +3646 -0
  217. package/examples/jsm/loaders/VTKLoader.js +1293 -0
  218. package/examples/jsm/loaders/XYZLoader.js +143 -0
  219. package/examples/jsm/loaders/collada/ColladaComposer.js +3044 -0
  220. package/examples/jsm/loaders/collada/ColladaParser.js +1977 -0
  221. package/examples/jsm/loaders/lwo/IFFParser.js +1217 -0
  222. package/examples/jsm/loaders/lwo/LWO2Parser.js +414 -0
  223. package/examples/jsm/loaders/lwo/LWO3Parser.js +373 -0
  224. package/examples/jsm/loaders/usd/USDAParser.js +828 -0
  225. package/examples/jsm/loaders/usd/USDCParser.js +1878 -0
  226. package/examples/jsm/loaders/usd/USDComposer.js +4594 -0
  227. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
  228. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
  229. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  230. package/examples/jsm/math/Capsule.js +159 -0
  231. package/examples/jsm/math/ColorConverter.js +58 -0
  232. package/examples/jsm/math/ColorSpaces.js +147 -0
  233. package/examples/jsm/math/ConvexHull.js +1695 -0
  234. package/examples/jsm/math/ImprovedNoise.js +88 -0
  235. package/examples/jsm/math/Lut.js +317 -0
  236. package/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  237. package/examples/jsm/math/OBB.js +535 -0
  238. package/examples/jsm/math/Octree.js +822 -0
  239. package/examples/jsm/math/SimplexNoise.js +470 -0
  240. package/examples/jsm/misc/ConvexObjectBreaker.js +539 -0
  241. package/examples/jsm/misc/GPUComputationRenderer.js +508 -0
  242. package/examples/jsm/misc/Gyroscope.js +78 -0
  243. package/examples/jsm/misc/MD2Character.js +391 -0
  244. package/examples/jsm/misc/MD2CharacterComplex.js +740 -0
  245. package/examples/jsm/misc/MorphAnimMesh.js +119 -0
  246. package/examples/jsm/misc/MorphBlendMesh.js +425 -0
  247. package/examples/jsm/misc/ProgressiveLightMap.js +370 -0
  248. package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
  249. package/examples/jsm/misc/RollerCoaster.js +661 -0
  250. package/examples/jsm/misc/TubePainter.js +599 -0
  251. package/examples/jsm/misc/Volume.js +520 -0
  252. package/examples/jsm/misc/VolumeSlice.js +275 -0
  253. package/examples/jsm/modifiers/CurveModifier.js +374 -0
  254. package/examples/jsm/modifiers/CurveModifierGPU.js +256 -0
  255. package/examples/jsm/modifiers/EdgeSplitModifier.js +299 -0
  256. package/examples/jsm/modifiers/SimplifyModifier.js +632 -0
  257. package/examples/jsm/modifiers/TessellateModifier.js +340 -0
  258. package/examples/jsm/objects/GroundedSkybox.js +69 -0
  259. package/examples/jsm/objects/Lensflare.js +489 -0
  260. package/examples/jsm/objects/LensflareMesh.js +376 -0
  261. package/examples/jsm/objects/MarchingCubes.js +1261 -0
  262. package/examples/jsm/objects/Reflector.js +386 -0
  263. package/examples/jsm/objects/ReflectorForSSRPass.js +393 -0
  264. package/examples/jsm/objects/Refractor.js +389 -0
  265. package/examples/jsm/objects/ShadowMesh.js +130 -0
  266. package/examples/jsm/objects/Sky.js +321 -0
  267. package/examples/jsm/objects/SkyMesh.js +377 -0
  268. package/examples/jsm/objects/Water.js +374 -0
  269. package/examples/jsm/objects/Water2.js +403 -0
  270. package/examples/jsm/objects/Water2Mesh.js +199 -0
  271. package/examples/jsm/objects/WaterMesh.js +194 -0
  272. package/examples/jsm/offscreen/jank.js +45 -0
  273. package/examples/jsm/offscreen/offscreen.js +8 -0
  274. package/examples/jsm/offscreen/scene.js +86 -0
  275. package/examples/jsm/physics/AmmoPhysics.js +359 -0
  276. package/examples/jsm/physics/JoltPhysics.js +334 -0
  277. package/examples/jsm/physics/RapierPhysics.js +436 -0
  278. package/examples/jsm/postprocessing/AfterimagePass.js +185 -0
  279. package/examples/jsm/postprocessing/BloomPass.js +274 -0
  280. package/examples/jsm/postprocessing/BokehPass.js +218 -0
  281. package/examples/jsm/postprocessing/ClearPass.js +97 -0
  282. package/examples/jsm/postprocessing/CubeTexturePass.js +146 -0
  283. package/examples/jsm/postprocessing/DotScreenPass.js +114 -0
  284. package/examples/jsm/postprocessing/EffectComposer.js +365 -0
  285. package/examples/jsm/postprocessing/FXAAPass.js +40 -0
  286. package/examples/jsm/postprocessing/FilmPass.js +113 -0
  287. package/examples/jsm/postprocessing/GTAOPass.js +727 -0
  288. package/examples/jsm/postprocessing/GlitchPass.js +177 -0
  289. package/examples/jsm/postprocessing/HalftonePass.js +134 -0
  290. package/examples/jsm/postprocessing/LUTPass.js +138 -0
  291. package/examples/jsm/postprocessing/MaskPass.js +195 -0
  292. package/examples/jsm/postprocessing/OutlinePass.js +776 -0
  293. package/examples/jsm/postprocessing/OutputPass.js +148 -0
  294. package/examples/jsm/postprocessing/Pass.js +191 -0
  295. package/examples/jsm/postprocessing/RenderPass.js +193 -0
  296. package/examples/jsm/postprocessing/RenderPixelatedPass.js +314 -0
  297. package/examples/jsm/postprocessing/RenderTransitionPass.js +267 -0
  298. package/examples/jsm/postprocessing/SAOPass.js +407 -0
  299. package/examples/jsm/postprocessing/SMAAPass.js +230 -0
  300. package/examples/jsm/postprocessing/SSAARenderPass.js +313 -0
  301. package/examples/jsm/postprocessing/SSAOPass.js +527 -0
  302. package/examples/jsm/postprocessing/SSRPass.js +856 -0
  303. package/examples/jsm/postprocessing/SavePass.js +132 -0
  304. package/examples/jsm/postprocessing/ShaderPass.js +135 -0
  305. package/examples/jsm/postprocessing/TAARenderPass.js +243 -0
  306. package/examples/jsm/postprocessing/TexturePass.js +131 -0
  307. package/examples/jsm/postprocessing/UnrealBloomPass.js +524 -0
  308. package/examples/jsm/renderers/CSS2DRenderer.js +328 -0
  309. package/examples/jsm/renderers/CSS3DRenderer.js +454 -0
  310. package/examples/jsm/renderers/Projector.js +1154 -0
  311. package/examples/jsm/renderers/SVGRenderer.js +799 -0
  312. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +96 -0
  313. package/examples/jsm/shaders/AfterimageShader.js +63 -0
  314. package/examples/jsm/shaders/BasicShader.js +36 -0
  315. package/examples/jsm/shaders/BleachBypassShader.js +68 -0
  316. package/examples/jsm/shaders/BlendShader.js +56 -0
  317. package/examples/jsm/shaders/BokehShader.js +151 -0
  318. package/examples/jsm/shaders/BokehShader2.js +404 -0
  319. package/examples/jsm/shaders/BrightnessContrastShader.js +62 -0
  320. package/examples/jsm/shaders/ColorCorrectionShader.js +59 -0
  321. package/examples/jsm/shaders/ColorifyShader.js +57 -0
  322. package/examples/jsm/shaders/ConvolutionShader.js +74 -0
  323. package/examples/jsm/shaders/CopyShader.js +52 -0
  324. package/examples/jsm/shaders/DOFMipMapShader.js +63 -0
  325. package/examples/jsm/shaders/DepthLimitedBlurShader.js +180 -0
  326. package/examples/jsm/shaders/DigitalGlitch.js +104 -0
  327. package/examples/jsm/shaders/DotScreenShader.js +75 -0
  328. package/examples/jsm/shaders/ExposureShader.js +51 -0
  329. package/examples/jsm/shaders/FXAAShader.js +298 -0
  330. package/examples/jsm/shaders/FilmShader.js +72 -0
  331. package/examples/jsm/shaders/FocusShader.js +94 -0
  332. package/examples/jsm/shaders/FreiChenShader.js +103 -0
  333. package/examples/jsm/shaders/GTAOShader.js +434 -0
  334. package/examples/jsm/shaders/GammaCorrectionShader.js +52 -0
  335. package/examples/jsm/shaders/HalftoneShader.js +332 -0
  336. package/examples/jsm/shaders/HorizontalBlurShader.js +68 -0
  337. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +70 -0
  338. package/examples/jsm/shaders/HueSaturationShader.js +74 -0
  339. package/examples/jsm/shaders/KaleidoShader.js +65 -0
  340. package/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
  341. package/examples/jsm/shaders/LuminosityShader.js +54 -0
  342. package/examples/jsm/shaders/MirrorShader.js +62 -0
  343. package/examples/jsm/shaders/NormalMapShader.js +60 -0
  344. package/examples/jsm/shaders/OutputShader.js +103 -0
  345. package/examples/jsm/shaders/PoissonDenoiseShader.js +239 -0
  346. package/examples/jsm/shaders/RGBShiftShader.js +61 -0
  347. package/examples/jsm/shaders/SAOShader.js +201 -0
  348. package/examples/jsm/shaders/SMAAShader.js +489 -0
  349. package/examples/jsm/shaders/SSAOShader.js +331 -0
  350. package/examples/jsm/shaders/SSRShader.js +396 -0
  351. package/examples/jsm/shaders/SepiaShader.js +57 -0
  352. package/examples/jsm/shaders/SobelOperatorShader.js +98 -0
  353. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +95 -0
  354. package/examples/jsm/shaders/TechnicolorShader.js +51 -0
  355. package/examples/jsm/shaders/ToonShader.js +349 -0
  356. package/examples/jsm/shaders/TriangleBlurShader.js +79 -0
  357. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +60 -0
  358. package/examples/jsm/shaders/VelocityShader.js +137 -0
  359. package/examples/jsm/shaders/VerticalBlurShader.js +66 -0
  360. package/examples/jsm/shaders/VerticalTiltShiftShader.js +70 -0
  361. package/examples/jsm/shaders/VignetteShader.js +56 -0
  362. package/examples/jsm/shaders/VolumeShader.js +298 -0
  363. package/examples/jsm/shaders/WaterRefractionShader.js +106 -0
  364. package/examples/jsm/textures/FlakesTexture.js +54 -0
  365. package/examples/jsm/transpiler/AST.js +675 -0
  366. package/examples/jsm/transpiler/GLSLDecoder.js +1228 -0
  367. package/examples/jsm/transpiler/Linker.js +327 -0
  368. package/examples/jsm/transpiler/ShaderToyDecoder.js +51 -0
  369. package/examples/jsm/transpiler/TSLEncoder.js +983 -0
  370. package/examples/jsm/transpiler/Transpiler.js +67 -0
  371. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  372. package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
  373. package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
  374. package/examples/jsm/tsl/display/AfterImageNode.js +254 -0
  375. package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
  376. package/examples/jsm/tsl/display/AnamorphicNode.js +293 -0
  377. package/examples/jsm/tsl/display/BilateralBlurNode.js +374 -0
  378. package/examples/jsm/tsl/display/BleachBypass.js +33 -0
  379. package/examples/jsm/tsl/display/BloomNode.js +534 -0
  380. package/examples/jsm/tsl/display/CRT.js +150 -0
  381. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +174 -0
  382. package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
  383. package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
  384. package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
  385. package/examples/jsm/tsl/display/FSR1Node.js +477 -0
  386. package/examples/jsm/tsl/display/FXAANode.js +365 -0
  387. package/examples/jsm/tsl/display/FilmNode.js +101 -0
  388. package/examples/jsm/tsl/display/GTAONode.js +572 -0
  389. package/examples/jsm/tsl/display/GaussianBlurNode.js +399 -0
  390. package/examples/jsm/tsl/display/GodraysNode.js +615 -0
  391. package/examples/jsm/tsl/display/LensflareNode.js +279 -0
  392. package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
  393. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  394. package/examples/jsm/tsl/display/OutlineNode.js +812 -0
  395. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
  396. package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
  397. package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
  398. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  399. package/examples/jsm/tsl/display/SMAANode.js +768 -0
  400. package/examples/jsm/tsl/display/SSAAPassNode.js +358 -0
  401. package/examples/jsm/tsl/display/SSGINode.js +638 -0
  402. package/examples/jsm/tsl/display/SSRNode.js +656 -0
  403. package/examples/jsm/tsl/display/SSSNode.js +490 -0
  404. package/examples/jsm/tsl/display/Sepia.js +24 -0
  405. package/examples/jsm/tsl/display/Shape.js +29 -0
  406. package/examples/jsm/tsl/display/SharpenNode.js +283 -0
  407. package/examples/jsm/tsl/display/SobelOperatorNode.js +168 -0
  408. package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
  409. package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
  410. package/examples/jsm/tsl/display/TAAUNode.js +835 -0
  411. package/examples/jsm/tsl/display/TRAANode.js +767 -0
  412. package/examples/jsm/tsl/display/TransitionNode.js +141 -0
  413. package/examples/jsm/tsl/display/boxBlur.js +65 -0
  414. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  415. package/examples/jsm/tsl/display/hashBlur.js +54 -0
  416. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  417. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
  418. package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
  419. package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
  420. package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
  421. package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
  422. package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
  423. package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
  424. package/examples/jsm/tsl/math/Bayer.js +84 -0
  425. package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
  426. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
  427. package/examples/jsm/tsl/utils/Raymarching.js +70 -0
  428. package/examples/jsm/utils/BufferGeometryUtils.js +1434 -0
  429. package/examples/jsm/utils/CameraUtils.js +82 -0
  430. package/examples/jsm/utils/ColorUtils.js +76 -0
  431. package/examples/jsm/utils/GeometryCompressionUtils.js +547 -0
  432. package/examples/jsm/utils/GeometryUtils.js +226 -0
  433. package/examples/jsm/utils/LDrawUtils.js +211 -0
  434. package/examples/jsm/utils/SceneOptimizer.js +458 -0
  435. package/examples/jsm/utils/SceneUtils.js +363 -0
  436. package/examples/jsm/utils/ShadowMapViewer.js +244 -0
  437. package/examples/jsm/utils/ShadowMapViewerGPU.js +233 -0
  438. package/examples/jsm/utils/SkeletonUtils.js +496 -0
  439. package/examples/jsm/utils/SortUtils.js +175 -0
  440. package/examples/jsm/utils/UVsDebug.js +173 -0
  441. package/examples/jsm/utils/WebGLTextureUtils.js +115 -0
  442. package/examples/jsm/utils/WebGPUTextureUtils.js +81 -0
  443. package/examples/jsm/utils/WorkerPool.js +167 -0
  444. package/examples/jsm/webxr/ARButton.js +251 -0
  445. package/examples/jsm/webxr/OculusHandModel.js +194 -0
  446. package/examples/jsm/webxr/OculusHandPointerModel.js +539 -0
  447. package/examples/jsm/webxr/Text2D.js +52 -0
  448. package/examples/jsm/webxr/VRButton.js +264 -0
  449. package/examples/jsm/webxr/XRButton.js +246 -0
  450. package/examples/jsm/webxr/XRControllerModelFactory.js +403 -0
  451. package/examples/jsm/webxr/XREstimatedLight.js +254 -0
  452. package/examples/jsm/webxr/XRHandMeshModel.js +177 -0
  453. package/examples/jsm/webxr/XRHandModelFactory.js +198 -0
  454. package/examples/jsm/webxr/XRHandPrimitiveModel.js +147 -0
  455. package/examples/jsm/webxr/XRPlanes.js +118 -0
  456. package/package.json +123 -0
  457. package/src/Three.Core.js +187 -0
  458. package/src/Three.Legacy.js +0 -0
  459. package/src/Three.TSL.js +647 -0
  460. package/src/Three.WebGPU.Nodes.js +31 -0
  461. package/src/Three.WebGPU.js +37 -0
  462. package/src/Three.js +10 -0
  463. package/src/animation/AnimationAction.js +942 -0
  464. package/src/animation/AnimationClip.js +628 -0
  465. package/src/animation/AnimationMixer.js +860 -0
  466. package/src/animation/AnimationObjectGroup.js +411 -0
  467. package/src/animation/AnimationUtils.js +495 -0
  468. package/src/animation/KeyframeTrack.js +636 -0
  469. package/src/animation/PropertyBinding.js +794 -0
  470. package/src/animation/PropertyMixer.js +385 -0
  471. package/src/animation/tracks/BooleanKeyframeTrack.js +55 -0
  472. package/src/animation/tracks/ColorKeyframeTrack.js +36 -0
  473. package/src/animation/tracks/NumberKeyframeTrack.js +36 -0
  474. package/src/animation/tracks/QuaternionKeyframeTrack.js +51 -0
  475. package/src/animation/tracks/StringKeyframeTrack.js +55 -0
  476. package/src/animation/tracks/VectorKeyframeTrack.js +36 -0
  477. package/src/audio/Audio.js +778 -0
  478. package/src/audio/AudioAnalyser.js +97 -0
  479. package/src/audio/AudioContext.js +40 -0
  480. package/src/audio/AudioListener.js +218 -0
  481. package/src/audio/PositionalAudio.js +253 -0
  482. package/src/cameras/ArrayCamera.js +54 -0
  483. package/src/cameras/Camera.js +160 -0
  484. package/src/cameras/CubeCamera.js +259 -0
  485. package/src/cameras/OrthographicCamera.js +245 -0
  486. package/src/cameras/PerspectiveCamera.js +407 -0
  487. package/src/cameras/StereoCamera.js +146 -0
  488. package/src/constants.js +1760 -0
  489. package/src/core/BufferAttribute.js +1056 -0
  490. package/src/core/BufferGeometry.js +1458 -0
  491. package/src/core/Clock.js +135 -0
  492. package/src/core/EventDispatcher.js +131 -0
  493. package/src/core/GLBufferAttribute.js +171 -0
  494. package/src/core/InstancedBufferAttribute.js +68 -0
  495. package/src/core/InstancedBufferGeometry.js +60 -0
  496. package/src/core/InstancedInterleavedBuffer.js +74 -0
  497. package/src/core/InterleavedBuffer.js +291 -0
  498. package/src/core/InterleavedBufferAttribute.js +549 -0
  499. package/src/core/Layers.js +121 -0
  500. package/src/core/Object3D.js +1667 -0
  501. package/src/core/Raycaster.js +262 -0
  502. package/src/core/RenderTarget.js +392 -0
  503. package/src/core/RenderTarget3D.js +48 -0
  504. package/src/core/Timer.js +184 -0
  505. package/src/core/Uniform.js +46 -0
  506. package/src/core/UniformsGroup.js +180 -0
  507. package/src/extras/Controls.js +120 -0
  508. package/src/extras/DataUtils.js +217 -0
  509. package/src/extras/Earcut.js +28 -0
  510. package/src/extras/ImageUtils.js +137 -0
  511. package/src/extras/PMREMGenerator.js +1167 -0
  512. package/src/extras/ShapeUtils.js +114 -0
  513. package/src/extras/TextureUtils.js +297 -0
  514. package/src/extras/core/Curve.js +517 -0
  515. package/src/extras/core/CurvePath.js +296 -0
  516. package/src/extras/core/Interpolations.js +111 -0
  517. package/src/extras/core/Path.js +329 -0
  518. package/src/extras/core/Shape.js +165 -0
  519. package/src/extras/core/ShapePath.js +367 -0
  520. package/src/extras/curves/ArcCurve.js +39 -0
  521. package/src/extras/curves/CatmullRomCurve3.js +327 -0
  522. package/src/extras/curves/CubicBezierCurve.js +145 -0
  523. package/src/extras/curves/CubicBezierCurve3.js +129 -0
  524. package/src/extras/curves/Curves.js +10 -0
  525. package/src/extras/curves/EllipseCurve.js +258 -0
  526. package/src/extras/curves/LineCurve.js +128 -0
  527. package/src/extras/curves/LineCurve3.js +128 -0
  528. package/src/extras/curves/QuadraticBezierCurve.js +133 -0
  529. package/src/extras/curves/QuadraticBezierCurve3.js +118 -0
  530. package/src/extras/curves/SplineCurve.js +145 -0
  531. package/src/extras/lib/earcut.js +685 -0
  532. package/src/geometries/BoxGeometry.js +219 -0
  533. package/src/geometries/CapsuleGeometry.js +218 -0
  534. package/src/geometries/CircleGeometry.js +142 -0
  535. package/src/geometries/ConeGeometry.js +70 -0
  536. package/src/geometries/CylinderGeometry.js +333 -0
  537. package/src/geometries/DodecahedronGeometry.js +99 -0
  538. package/src/geometries/EdgesGeometry.js +180 -0
  539. package/src/geometries/ExtrudeGeometry.js +910 -0
  540. package/src/geometries/Geometries.js +21 -0
  541. package/src/geometries/IcosahedronGeometry.js +75 -0
  542. package/src/geometries/LatheGeometry.js +230 -0
  543. package/src/geometries/OctahedronGeometry.js +70 -0
  544. package/src/geometries/PlaneGeometry.js +133 -0
  545. package/src/geometries/PolyhedronGeometry.js +348 -0
  546. package/src/geometries/RingGeometry.js +165 -0
  547. package/src/geometries/ShapeGeometry.js +233 -0
  548. package/src/geometries/SphereGeometry.js +175 -0
  549. package/src/geometries/TetrahedronGeometry.js +67 -0
  550. package/src/geometries/TorusGeometry.js +161 -0
  551. package/src/geometries/TorusKnotGeometry.js +206 -0
  552. package/src/geometries/TubeGeometry.js +253 -0
  553. package/src/geometries/WireframeGeometry.js +179 -0
  554. package/src/helpers/ArrowHelper.js +171 -0
  555. package/src/helpers/AxesHelper.js +96 -0
  556. package/src/helpers/Box3Helper.js +83 -0
  557. package/src/helpers/BoxHelper.js +149 -0
  558. package/src/helpers/CameraHelper.js +345 -0
  559. package/src/helpers/DirectionalLightHelper.js +148 -0
  560. package/src/helpers/GridHelper.js +82 -0
  561. package/src/helpers/HemisphereLightHelper.js +130 -0
  562. package/src/helpers/PlaneHelper.js +96 -0
  563. package/src/helpers/PointLightHelper.js +111 -0
  564. package/src/helpers/PolarGridHelper.js +126 -0
  565. package/src/helpers/SkeletonHelper.js +194 -0
  566. package/src/helpers/SpotLightHelper.js +154 -0
  567. package/src/lights/AmbientLight.js +42 -0
  568. package/src/lights/DirectionalLight.js +113 -0
  569. package/src/lights/DirectionalLightShadow.js +31 -0
  570. package/src/lights/HemisphereLight.js +76 -0
  571. package/src/lights/Light.js +85 -0
  572. package/src/lights/LightProbe.js +75 -0
  573. package/src/lights/LightShadow.js +347 -0
  574. package/src/lights/PointLight.js +131 -0
  575. package/src/lights/PointLightShadow.js +31 -0
  576. package/src/lights/RectAreaLight.js +115 -0
  577. package/src/lights/SpotLight.js +194 -0
  578. package/src/lights/SpotLightShadow.js +80 -0
  579. package/src/lights/webgpu/IESSpotLight.js +47 -0
  580. package/src/lights/webgpu/ProjectorLight.js +46 -0
  581. package/src/loaders/AnimationLoader.js +98 -0
  582. package/src/loaders/AudioLoader.js +108 -0
  583. package/src/loaders/BufferGeometryLoader.js +242 -0
  584. package/src/loaders/Cache.js +115 -0
  585. package/src/loaders/CompressedTextureLoader.js +167 -0
  586. package/src/loaders/CubeTextureLoader.js +103 -0
  587. package/src/loaders/DataTextureLoader.js +174 -0
  588. package/src/loaders/FileLoader.js +367 -0
  589. package/src/loaders/ImageBitmapLoader.js +223 -0
  590. package/src/loaders/ImageLoader.js +168 -0
  591. package/src/loaders/Loader.js +222 -0
  592. package/src/loaders/LoaderUtils.js +59 -0
  593. package/src/loaders/LoadingManager.js +329 -0
  594. package/src/loaders/MaterialLoader.js +439 -0
  595. package/src/loaders/ObjectLoader.js +1304 -0
  596. package/src/loaders/TextureLoader.js +74 -0
  597. package/src/loaders/nodes/NodeLoader.js +194 -0
  598. package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
  599. package/src/loaders/nodes/NodeObjectLoader.js +169 -0
  600. package/src/materials/LineBasicMaterial.js +122 -0
  601. package/src/materials/LineDashedMaterial.js +86 -0
  602. package/src/materials/Material.js +1017 -0
  603. package/src/materials/Materials.js +39 -0
  604. package/src/materials/MeshBasicMaterial.js +250 -0
  605. package/src/materials/MeshDepthMaterial.js +148 -0
  606. package/src/materials/MeshDistanceMaterial.js +119 -0
  607. package/src/materials/MeshLambertMaterial.js +402 -0
  608. package/src/materials/MeshMatcapMaterial.js +245 -0
  609. package/src/materials/MeshNormalMaterial.js +175 -0
  610. package/src/materials/MeshPhongMaterial.js +421 -0
  611. package/src/materials/MeshPhysicalMaterial.js +536 -0
  612. package/src/materials/MeshStandardMaterial.js +425 -0
  613. package/src/materials/MeshToonMaterial.js +321 -0
  614. package/src/materials/PointsMaterial.js +139 -0
  615. package/src/materials/RawShaderMaterial.js +42 -0
  616. package/src/materials/ShaderMaterial.js +413 -0
  617. package/src/materials/ShadowMaterial.js +91 -0
  618. package/src/materials/SpriteMaterial.js +136 -0
  619. package/src/materials/nodes/Line2NodeMaterial.js +569 -0
  620. package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
  621. package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
  622. package/src/materials/nodes/MeshBasicNodeMaterial.js +134 -0
  623. package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
  624. package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
  625. package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
  626. package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
  627. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +521 -0
  628. package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
  629. package/src/materials/nodes/MeshStandardNodeMaterial.js +187 -0
  630. package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
  631. package/src/materials/nodes/NodeMaterial.js +1330 -0
  632. package/src/materials/nodes/NodeMaterials.js +21 -0
  633. package/src/materials/nodes/PointsNodeMaterial.js +211 -0
  634. package/src/materials/nodes/ShadowNodeMaterial.js +76 -0
  635. package/src/materials/nodes/SpriteNodeMaterial.js +186 -0
  636. package/src/materials/nodes/VolumeNodeMaterial.js +81 -0
  637. package/src/materials/nodes/manager/NodeMaterialObserver.js +718 -0
  638. package/src/math/Box2.js +381 -0
  639. package/src/math/Box3.js +805 -0
  640. package/src/math/Color.js +967 -0
  641. package/src/math/ColorManagement.js +215 -0
  642. package/src/math/Cylindrical.js +120 -0
  643. package/src/math/Euler.js +449 -0
  644. package/src/math/Frustum.js +285 -0
  645. package/src/math/FrustumArray.js +258 -0
  646. package/src/math/Interpolant.js +320 -0
  647. package/src/math/Line3.js +337 -0
  648. package/src/math/MathUtils.js +751 -0
  649. package/src/math/Matrix2.js +128 -0
  650. package/src/math/Matrix3.js +617 -0
  651. package/src/math/Matrix4.js +1314 -0
  652. package/src/math/Plane.js +368 -0
  653. package/src/math/Quaternion.js +918 -0
  654. package/src/math/Ray.js +655 -0
  655. package/src/math/Sphere.js +420 -0
  656. package/src/math/Spherical.js +147 -0
  657. package/src/math/SphericalHarmonics3.js +341 -0
  658. package/src/math/Triangle.js +539 -0
  659. package/src/math/Vector2.js +870 -0
  660. package/src/math/Vector3.js +1263 -0
  661. package/src/math/Vector4.js +1067 -0
  662. package/src/math/interpolants/BezierInterpolant.js +108 -0
  663. package/src/math/interpolants/CubicInterpolant.js +159 -0
  664. package/src/math/interpolants/DiscreteInterpolant.js +34 -0
  665. package/src/math/interpolants/LinearInterpolant.js +51 -0
  666. package/src/math/interpolants/QuaternionLinearInterpolant.js +48 -0
  667. package/src/nodes/Nodes.js +166 -0
  668. package/src/nodes/TSL.js +173 -0
  669. package/src/nodes/accessors/AccessorsUtils.js +53 -0
  670. package/src/nodes/accessors/Arrays.js +68 -0
  671. package/src/nodes/accessors/BatchNode.js +163 -0
  672. package/src/nodes/accessors/Bitangent.js +82 -0
  673. package/src/nodes/accessors/BufferAttributeNode.js +432 -0
  674. package/src/nodes/accessors/BufferNode.js +128 -0
  675. package/src/nodes/accessors/BuiltinNode.js +63 -0
  676. package/src/nodes/accessors/Camera.js +403 -0
  677. package/src/nodes/accessors/ClippingNode.js +255 -0
  678. package/src/nodes/accessors/CubeTextureNode.js +215 -0
  679. package/src/nodes/accessors/InstanceNode.js +349 -0
  680. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  681. package/src/nodes/accessors/Lights.js +139 -0
  682. package/src/nodes/accessors/MaterialNode.js +783 -0
  683. package/src/nodes/accessors/MaterialProperties.js +56 -0
  684. package/src/nodes/accessors/MaterialReferenceNode.js +84 -0
  685. package/src/nodes/accessors/ModelNode.js +184 -0
  686. package/src/nodes/accessors/ModelViewProjectionNode.js +13 -0
  687. package/src/nodes/accessors/MorphNode.js +310 -0
  688. package/src/nodes/accessors/Normal.js +243 -0
  689. package/src/nodes/accessors/Object3DNode.js +268 -0
  690. package/src/nodes/accessors/PointUVNode.js +55 -0
  691. package/src/nodes/accessors/Position.js +122 -0
  692. package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
  693. package/src/nodes/accessors/ReferenceNode.js +424 -0
  694. package/src/nodes/accessors/ReflectVector.js +36 -0
  695. package/src/nodes/accessors/RendererReferenceNode.js +78 -0
  696. package/src/nodes/accessors/SceneProperties.js +47 -0
  697. package/src/nodes/accessors/SkinningNode.js +328 -0
  698. package/src/nodes/accessors/StorageBufferNode.js +405 -0
  699. package/src/nodes/accessors/StorageTextureNode.js +295 -0
  700. package/src/nodes/accessors/Tangent.js +60 -0
  701. package/src/nodes/accessors/TangentUtils.js +46 -0
  702. package/src/nodes/accessors/Texture3DNode.js +196 -0
  703. package/src/nodes/accessors/TextureBicubic.js +92 -0
  704. package/src/nodes/accessors/TextureNode.js +971 -0
  705. package/src/nodes/accessors/TextureSizeNode.js +77 -0
  706. package/src/nodes/accessors/UV.js +11 -0
  707. package/src/nodes/accessors/UniformArrayNode.js +350 -0
  708. package/src/nodes/accessors/UserDataNode.js +76 -0
  709. package/src/nodes/accessors/VelocityNode.js +224 -0
  710. package/src/nodes/accessors/VertexColorNode.js +109 -0
  711. package/src/nodes/code/CodeNode.js +181 -0
  712. package/src/nodes/code/ExpressionNode.js +68 -0
  713. package/src/nodes/code/FunctionCallNode.js +187 -0
  714. package/src/nodes/code/FunctionNode.js +182 -0
  715. package/src/nodes/core/ArrayNode.js +174 -0
  716. package/src/nodes/core/AssignNode.js +202 -0
  717. package/src/nodes/core/AttributeNode.js +168 -0
  718. package/src/nodes/core/BypassNode.js +93 -0
  719. package/src/nodes/core/ConstNode.js +67 -0
  720. package/src/nodes/core/ContextNode.js +283 -0
  721. package/src/nodes/core/IndexNode.js +165 -0
  722. package/src/nodes/core/InputNode.js +136 -0
  723. package/src/nodes/core/InspectorNode.js +128 -0
  724. package/src/nodes/core/IsolateNode.js +133 -0
  725. package/src/nodes/core/LightingModel.js +77 -0
  726. package/src/nodes/core/MRTNode.js +196 -0
  727. package/src/nodes/core/Node.js +1180 -0
  728. package/src/nodes/core/NodeAttribute.js +53 -0
  729. package/src/nodes/core/NodeBuilder.js +3299 -0
  730. package/src/nodes/core/NodeCache.js +75 -0
  731. package/src/nodes/core/NodeCode.js +46 -0
  732. package/src/nodes/core/NodeError.js +28 -0
  733. package/src/nodes/core/NodeFrame.js +314 -0
  734. package/src/nodes/core/NodeFunction.js +69 -0
  735. package/src/nodes/core/NodeFunctionInput.js +61 -0
  736. package/src/nodes/core/NodeParser.js +23 -0
  737. package/src/nodes/core/NodeUniform.js +91 -0
  738. package/src/nodes/core/NodeUtils.js +408 -0
  739. package/src/nodes/core/NodeVar.js +60 -0
  740. package/src/nodes/core/NodeVarying.js +63 -0
  741. package/src/nodes/core/OutputStructNode.js +105 -0
  742. package/src/nodes/core/ParameterNode.js +94 -0
  743. package/src/nodes/core/PropertyNode.js +367 -0
  744. package/src/nodes/core/StackNode.js +426 -0
  745. package/src/nodes/core/StackTrace.js +139 -0
  746. package/src/nodes/core/StructNode.js +134 -0
  747. package/src/nodes/core/StructType.js +13 -0
  748. package/src/nodes/core/StructTypeNode.js +148 -0
  749. package/src/nodes/core/SubBuildNode.js +89 -0
  750. package/src/nodes/core/TempNode.js +88 -0
  751. package/src/nodes/core/UniformGroupNode.js +167 -0
  752. package/src/nodes/core/UniformNode.js +259 -0
  753. package/src/nodes/core/VarNode.js +367 -0
  754. package/src/nodes/core/VaryingNode.js +210 -0
  755. package/src/nodes/core/constants.js +68 -0
  756. package/src/nodes/display/BlendModes.js +171 -0
  757. package/src/nodes/display/BumpMapNode.js +117 -0
  758. package/src/nodes/display/ColorAdjustment.js +158 -0
  759. package/src/nodes/display/ColorSpaceFunctions.js +54 -0
  760. package/src/nodes/display/ColorSpaceNode.js +164 -0
  761. package/src/nodes/display/FrontFacingNode.js +102 -0
  762. package/src/nodes/display/NormalMapNode.js +153 -0
  763. package/src/nodes/display/PassNode.js +1055 -0
  764. package/src/nodes/display/RenderOutputNode.js +150 -0
  765. package/src/nodes/display/ScreenNode.js +292 -0
  766. package/src/nodes/display/ToneMappingFunctions.js +242 -0
  767. package/src/nodes/display/ToneMappingNode.js +147 -0
  768. package/src/nodes/display/ToonOutlinePassNode.js +191 -0
  769. package/src/nodes/display/ViewportDepthNode.js +342 -0
  770. package/src/nodes/display/ViewportDepthTextureNode.js +63 -0
  771. package/src/nodes/display/ViewportSharedTextureNode.js +73 -0
  772. package/src/nodes/display/ViewportTextureNode.js +256 -0
  773. package/src/nodes/fog/Fog.js +97 -0
  774. package/src/nodes/functions/BSDF/BRDF_GGX.js +55 -0
  775. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
  776. package/src/nodes/functions/BSDF/BRDF_Lambert.js +9 -0
  777. package/src/nodes/functions/BSDF/BRDF_Sheen.js +57 -0
  778. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  779. package/src/nodes/functions/BSDF/D_GGX.js +23 -0
  780. package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  781. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
  782. package/src/nodes/functions/BSDF/F_Schlick.js +16 -0
  783. package/src/nodes/functions/BSDF/LTC.js +175 -0
  784. package/src/nodes/functions/BSDF/Schlick_to_F0.js +21 -0
  785. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +26 -0
  786. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  787. package/src/nodes/functions/BasicLightingModel.js +100 -0
  788. package/src/nodes/functions/PhongLightingModel.js +99 -0
  789. package/src/nodes/functions/PhysicalLightingModel.js +878 -0
  790. package/src/nodes/functions/ShadowMaskModel.js +58 -0
  791. package/src/nodes/functions/ToonLightingModel.js +70 -0
  792. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  793. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  794. package/src/nodes/functions/material/getGeometryRoughness.js +19 -0
  795. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  796. package/src/nodes/functions/material/getRoughness.js +18 -0
  797. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  798. package/src/nodes/geometry/RangeNode.js +210 -0
  799. package/src/nodes/gpgpu/AtomicFunctionNode.js +274 -0
  800. package/src/nodes/gpgpu/BarrierNode.js +98 -0
  801. package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
  802. package/src/nodes/gpgpu/ComputeNode.js +310 -0
  803. package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
  804. package/src/nodes/gpgpu/WorkgroupInfoNode.js +234 -0
  805. package/src/nodes/lighting/AONode.js +45 -0
  806. package/src/nodes/lighting/AmbientLightNode.js +35 -0
  807. package/src/nodes/lighting/AnalyticLightNode.js +309 -0
  808. package/src/nodes/lighting/BasicEnvironmentNode.js +49 -0
  809. package/src/nodes/lighting/BasicLightMapNode.js +49 -0
  810. package/src/nodes/lighting/DirectionalLightNode.js +39 -0
  811. package/src/nodes/lighting/EnvironmentNode.js +178 -0
  812. package/src/nodes/lighting/HemisphereLightNode.js +87 -0
  813. package/src/nodes/lighting/IESSpotLightNode.js +49 -0
  814. package/src/nodes/lighting/IrradianceNode.js +44 -0
  815. package/src/nodes/lighting/LightProbeNode.js +73 -0
  816. package/src/nodes/lighting/LightUtils.js +25 -0
  817. package/src/nodes/lighting/LightingContextNode.js +115 -0
  818. package/src/nodes/lighting/LightingNode.js +36 -0
  819. package/src/nodes/lighting/LightsNode.js +432 -0
  820. package/src/nodes/lighting/PointLightNode.js +102 -0
  821. package/src/nodes/lighting/PointShadowNode.js +325 -0
  822. package/src/nodes/lighting/ProjectorLightNode.js +91 -0
  823. package/src/nodes/lighting/RectAreaLightNode.js +133 -0
  824. package/src/nodes/lighting/ShadowBaseNode.js +81 -0
  825. package/src/nodes/lighting/ShadowFilterNode.js +264 -0
  826. package/src/nodes/lighting/ShadowNode.js +889 -0
  827. package/src/nodes/lighting/SpotLightNode.js +168 -0
  828. package/src/nodes/materialx/DISCLAIMER.md +199 -0
  829. package/src/nodes/materialx/MaterialXNodes.js +197 -0
  830. package/src/nodes/materialx/lib/mx_hsv.js +127 -0
  831. package/src/nodes/materialx/lib/mx_noise.js +1491 -0
  832. package/src/nodes/materialx/lib/mx_transform_color.js +23 -0
  833. package/src/nodes/math/BitcastNode.js +156 -0
  834. package/src/nodes/math/BitcountNode.js +433 -0
  835. package/src/nodes/math/ConditionalNode.js +245 -0
  836. package/src/nodes/math/Hash.js +21 -0
  837. package/src/nodes/math/MathNode.js +1202 -0
  838. package/src/nodes/math/MathUtils.js +54 -0
  839. package/src/nodes/math/OperatorNode.js +752 -0
  840. package/src/nodes/math/PackFloatNode.js +98 -0
  841. package/src/nodes/math/TriNoise3D.js +71 -0
  842. package/src/nodes/math/UnpackFloatNode.js +96 -0
  843. package/src/nodes/parsers/GLSLNodeFunction.js +168 -0
  844. package/src/nodes/parsers/GLSLNodeParser.js +25 -0
  845. package/src/nodes/pmrem/PMREMNode.js +397 -0
  846. package/src/nodes/pmrem/PMREMUtils.js +397 -0
  847. package/src/nodes/procedural/Checker.js +22 -0
  848. package/src/nodes/shapes/Shapes.js +33 -0
  849. package/src/nodes/tsl/TSLBase.js +36 -0
  850. package/src/nodes/tsl/TSLCore.js +1250 -0
  851. package/src/nodes/utils/ArrayElementNode.js +90 -0
  852. package/src/nodes/utils/ConvertNode.js +100 -0
  853. package/src/nodes/utils/CubeMapNode.js +237 -0
  854. package/src/nodes/utils/DebugNode.js +83 -0
  855. package/src/nodes/utils/Discard.js +24 -0
  856. package/src/nodes/utils/EquirectUV.js +27 -0
  857. package/src/nodes/utils/EventNode.js +148 -0
  858. package/src/nodes/utils/FlipNode.js +106 -0
  859. package/src/nodes/utils/FunctionOverloadingNode.js +170 -0
  860. package/src/nodes/utils/JoinNode.js +117 -0
  861. package/src/nodes/utils/LoopNode.js +349 -0
  862. package/src/nodes/utils/MatcapUV.js +22 -0
  863. package/src/nodes/utils/MaxMipLevelNode.js +103 -0
  864. package/src/nodes/utils/MemberNode.js +120 -0
  865. package/src/nodes/utils/Oscillators.js +41 -0
  866. package/src/nodes/utils/Packing.js +33 -0
  867. package/src/nodes/utils/PostProcessingUtils.js +154 -0
  868. package/src/nodes/utils/RTTNode.js +289 -0
  869. package/src/nodes/utils/ReflectorNode.js +629 -0
  870. package/src/nodes/utils/Remap.js +48 -0
  871. package/src/nodes/utils/RotateNode.js +103 -0
  872. package/src/nodes/utils/SampleNode.js +91 -0
  873. package/src/nodes/utils/SetNode.js +108 -0
  874. package/src/nodes/utils/SplitNode.js +179 -0
  875. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  876. package/src/nodes/utils/SpriteUtils.js +63 -0
  877. package/src/nodes/utils/StorageArrayElementNode.js +143 -0
  878. package/src/nodes/utils/Timer.js +26 -0
  879. package/src/nodes/utils/TriplanarTextures.js +65 -0
  880. package/src/nodes/utils/UVUtils.js +67 -0
  881. package/src/nodes/utils/ViewportUtils.js +26 -0
  882. package/src/objects/BatchedMesh.js +1682 -0
  883. package/src/objects/Bone.js +41 -0
  884. package/src/objects/ClippingGroup.js +68 -0
  885. package/src/objects/Group.js +41 -0
  886. package/src/objects/InstancedMesh.js +422 -0
  887. package/src/objects/LOD.js +329 -0
  888. package/src/objects/Line.js +329 -0
  889. package/src/objects/LineLoop.js +37 -0
  890. package/src/objects/LineSegments.js +74 -0
  891. package/src/objects/Mesh.js +496 -0
  892. package/src/objects/Points.js +228 -0
  893. package/src/objects/Skeleton.js +392 -0
  894. package/src/objects/SkinnedMesh.js +370 -0
  895. package/src/objects/Sprite.js +245 -0
  896. package/src/renderers/WebGL3DRenderTarget.js +48 -0
  897. package/src/renderers/WebGLArrayRenderTarget.js +48 -0
  898. package/src/renderers/WebGLCubeRenderTarget.js +182 -0
  899. package/src/renderers/WebGLRenderTarget.js +34 -0
  900. package/src/renderers/WebGLRenderer.js +3699 -0
  901. package/src/renderers/common/Animation.js +159 -0
  902. package/src/renderers/common/Attributes.js +132 -0
  903. package/src/renderers/common/Backend.js +769 -0
  904. package/src/renderers/common/Background.js +225 -0
  905. package/src/renderers/common/BindGroup.js +46 -0
  906. package/src/renderers/common/Binding.js +71 -0
  907. package/src/renderers/common/Bindings.js +394 -0
  908. package/src/renderers/common/BlendMode.js +143 -0
  909. package/src/renderers/common/Buffer.js +127 -0
  910. package/src/renderers/common/BufferUtils.js +58 -0
  911. package/src/renderers/common/BundleGroup.js +83 -0
  912. package/src/renderers/common/CanvasTarget.js +341 -0
  913. package/src/renderers/common/ChainMap.js +122 -0
  914. package/src/renderers/common/ClippingContext.js +262 -0
  915. package/src/renderers/common/Color4.js +77 -0
  916. package/src/renderers/common/ComputePipeline.js +41 -0
  917. package/src/renderers/common/Constants.js +15 -0
  918. package/src/renderers/common/CubeRenderTarget.js +147 -0
  919. package/src/renderers/common/DataMap.js +90 -0
  920. package/src/renderers/common/Geometries.js +396 -0
  921. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  922. package/src/renderers/common/Info.js +501 -0
  923. package/src/renderers/common/InspectorBase.js +151 -0
  924. package/src/renderers/common/Lighting.js +57 -0
  925. package/src/renderers/common/Pipeline.js +35 -0
  926. package/src/renderers/common/Pipelines.js +498 -0
  927. package/src/renderers/common/PostProcessing.js +28 -0
  928. package/src/renderers/common/ProgrammableStage.js +78 -0
  929. package/src/renderers/common/QuadMesh.js +112 -0
  930. package/src/renderers/common/ReadbackBuffer.js +78 -0
  931. package/src/renderers/common/RenderBundle.js +26 -0
  932. package/src/renderers/common/RenderBundles.js +71 -0
  933. package/src/renderers/common/RenderContext.js +281 -0
  934. package/src/renderers/common/RenderContexts.js +100 -0
  935. package/src/renderers/common/RenderList.js +404 -0
  936. package/src/renderers/common/RenderLists.js +78 -0
  937. package/src/renderers/common/RenderObject.js +915 -0
  938. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  939. package/src/renderers/common/RenderObjects.js +218 -0
  940. package/src/renderers/common/RenderPipeline.js +255 -0
  941. package/src/renderers/common/Renderer.js +3654 -0
  942. package/src/renderers/common/RendererUtils.js +200 -0
  943. package/src/renderers/common/SampledTexture.js +152 -0
  944. package/src/renderers/common/Sampler.js +165 -0
  945. package/src/renderers/common/Storage3DTexture.js +100 -0
  946. package/src/renderers/common/StorageArrayTexture.js +84 -0
  947. package/src/renderers/common/StorageBuffer.js +53 -0
  948. package/src/renderers/common/StorageBufferAttribute.js +46 -0
  949. package/src/renderers/common/StorageInstancedBufferAttribute.js +46 -0
  950. package/src/renderers/common/StorageTexture.js +86 -0
  951. package/src/renderers/common/Textures.js +629 -0
  952. package/src/renderers/common/TimestampQueryPool.js +163 -0
  953. package/src/renderers/common/Uniform.js +375 -0
  954. package/src/renderers/common/UniformBuffer.js +34 -0
  955. package/src/renderers/common/UniformsGroup.js +548 -0
  956. package/src/renderers/common/XRManager.js +1684 -0
  957. package/src/renderers/common/XRRenderTarget.js +91 -0
  958. package/src/renderers/common/extras/PMREMGenerator.js +1042 -0
  959. package/src/renderers/common/nodes/NodeBuilderState.js +152 -0
  960. package/src/renderers/common/nodes/NodeLibrary.js +196 -0
  961. package/src/renderers/common/nodes/NodeManager.js +983 -0
  962. package/src/renderers/common/nodes/NodeSampledTexture.js +140 -0
  963. package/src/renderers/common/nodes/NodeSampler.js +62 -0
  964. package/src/renderers/common/nodes/NodeStorageBuffer.js +72 -0
  965. package/src/renderers/common/nodes/NodeUniform.js +418 -0
  966. package/src/renderers/common/nodes/NodeUniformBuffer.js +105 -0
  967. package/src/renderers/common/nodes/NodeUniformsGroup.js +51 -0
  968. package/src/renderers/shaders/DFGLUTData.js +49 -0
  969. package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
  970. package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
  971. package/src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl.js +7 -0
  972. package/src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl.js +7 -0
  973. package/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +16 -0
  974. package/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +5 -0
  975. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +26 -0
  976. package/src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl.js +8 -0
  977. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +49 -0
  978. package/src/renderers/shaders/ShaderChunk/batching_vertex.glsl.js +5 -0
  979. package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +9 -0
  980. package/src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl.js +9 -0
  981. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +33 -0
  982. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +43 -0
  983. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +7 -0
  984. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_maps.glsl.js +10 -0
  985. package/src/renderers/shaders/ShaderChunk/clearcoat_pars_fragment.glsl.js +21 -0
  986. package/src/renderers/shaders/ShaderChunk/clipping_planes_fragment.glsl.js +78 -0
  987. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_fragment.glsl.js +9 -0
  988. package/src/renderers/shaders/ShaderChunk/clipping_planes_pars_vertex.glsl.js +7 -0
  989. package/src/renderers/shaders/ShaderChunk/clipping_planes_vertex.glsl.js +7 -0
  990. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +7 -0
  991. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +7 -0
  992. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +7 -0
  993. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +29 -0
  994. package/src/renderers/shaders/ShaderChunk/colorspace_fragment.glsl.js +3 -0
  995. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +15 -0
  996. package/src/renderers/shaders/ShaderChunk/common.glsl.js +125 -0
  997. package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +186 -0
  998. package/src/renderers/shaders/ShaderChunk/default_fragment.glsl.js +5 -0
  999. package/src/renderers/shaders/ShaderChunk/default_vertex.glsl.js +5 -0
  1000. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +63 -0
  1001. package/src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl.js +9 -0
  1002. package/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl.js +7 -0
  1003. package/src/renderers/shaders/ShaderChunk/dithering_fragment.glsl.js +7 -0
  1004. package/src/renderers/shaders/ShaderChunk/dithering_pars_fragment.glsl.js +20 -0
  1005. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +17 -0
  1006. package/src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl.js +7 -0
  1007. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +14 -0
  1008. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +58 -0
  1009. package/src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl.js +21 -0
  1010. package/src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl.js +22 -0
  1011. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +69 -0
  1012. package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +37 -0
  1013. package/src/renderers/shaders/ShaderChunk/fog_fragment.glsl.js +17 -0
  1014. package/src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl.js +19 -0
  1015. package/src/renderers/shaders/ShaderChunk/fog_pars_vertex.glsl.js +7 -0
  1016. package/src/renderers/shaders/ShaderChunk/fog_vertex.glsl.js +7 -0
  1017. package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +27 -0
  1018. package/src/renderers/shaders/ShaderChunk/iridescence_fragment.glsl.js +120 -0
  1019. package/src/renderers/shaders/ShaderChunk/iridescence_pars_fragment.glsl.js +14 -0
  1020. package/src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl.js +8 -0
  1021. package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
  1022. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +213 -0
  1023. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +19 -0
  1024. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +44 -0
  1025. package/src/renderers/shaders/ShaderChunk/lights_lambert_fragment.glsl.js +5 -0
  1026. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +28 -0
  1027. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +216 -0
  1028. package/src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl.js +7 -0
  1029. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +32 -0
  1030. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +161 -0
  1031. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +656 -0
  1032. package/src/renderers/shaders/ShaderChunk/lights_toon_fragment.glsl.js +4 -0
  1033. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +26 -0
  1034. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +9 -0
  1035. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +9 -0
  1036. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +8 -0
  1037. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +8 -0
  1038. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +17 -0
  1039. package/src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl.js +7 -0
  1040. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +27 -0
  1041. package/src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl.js +27 -0
  1042. package/src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl.js +12 -0
  1043. package/src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl.js +7 -0
  1044. package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +24 -0
  1045. package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
  1046. package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +16 -0
  1047. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +26 -0
  1048. package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +16 -0
  1049. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +76 -0
  1050. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +40 -0
  1051. package/src/renderers/shaders/ShaderChunk/normal_pars_fragment.glsl.js +14 -0
  1052. package/src/renderers/shaders/ShaderChunk/normal_pars_vertex.glsl.js +14 -0
  1053. package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +14 -0
  1054. package/src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl.js +43 -0
  1055. package/src/renderers/shaders/ShaderChunk/opaque_fragment.glsl.js +11 -0
  1056. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +116 -0
  1057. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +7 -0
  1058. package/src/renderers/shaders/ShaderChunk/project_vertex.glsl.js +19 -0
  1059. package/src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl.js +12 -0
  1060. package/src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl.js +7 -0
  1061. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +376 -0
  1062. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +71 -0
  1063. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +78 -0
  1064. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +66 -0
  1065. package/src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl.js +10 -0
  1066. package/src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl.js +25 -0
  1067. package/src/renderers/shaders/ShaderChunk/skinning_vertex.glsl.js +15 -0
  1068. package/src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl.js +20 -0
  1069. package/src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl.js +14 -0
  1070. package/src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl.js +7 -0
  1071. package/src/renderers/shaders/ShaderChunk/tonemapping_fragment.glsl.js +7 -0
  1072. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +200 -0
  1073. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +36 -0
  1074. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +235 -0
  1075. package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +119 -0
  1076. package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +145 -0
  1077. package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +122 -0
  1078. package/src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl.js +21 -0
  1079. package/src/renderers/shaders/ShaderChunk.js +272 -0
  1080. package/src/renderers/shaders/ShaderLib/background.glsl.js +40 -0
  1081. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +62 -0
  1082. package/src/renderers/shaders/ShaderLib/cube.glsl.js +36 -0
  1083. package/src/renderers/shaders/ShaderLib/depth.glsl.js +117 -0
  1084. package/src/renderers/shaders/ShaderLib/distance.glsl.js +77 -0
  1085. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +35 -0
  1086. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +76 -0
  1087. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +116 -0
  1088. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +126 -0
  1089. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +112 -0
  1090. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +86 -0
  1091. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +128 -0
  1092. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +224 -0
  1093. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +118 -0
  1094. package/src/renderers/shaders/ShaderLib/points.glsl.js +87 -0
  1095. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +58 -0
  1096. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +79 -0
  1097. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +51 -0
  1098. package/src/renderers/shaders/ShaderLib.js +362 -0
  1099. package/src/renderers/shaders/UniformsLib.js +234 -0
  1100. package/src/renderers/shaders/UniformsUtils.js +154 -0
  1101. package/src/renderers/webgl/WebGLAnimation.js +54 -0
  1102. package/src/renderers/webgl/WebGLAttributes.js +237 -0
  1103. package/src/renderers/webgl/WebGLBackground.js +303 -0
  1104. package/src/renderers/webgl/WebGLBindingStates.js +666 -0
  1105. package/src/renderers/webgl/WebGLBufferRenderer.js +57 -0
  1106. package/src/renderers/webgl/WebGLCapabilities.js +150 -0
  1107. package/src/renderers/webgl/WebGLClipping.js +171 -0
  1108. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  1109. package/src/renderers/webgl/WebGLExtensions.js +61 -0
  1110. package/src/renderers/webgl/WebGLGeometries.js +186 -0
  1111. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +68 -0
  1112. package/src/renderers/webgl/WebGLInfo.js +73 -0
  1113. package/src/renderers/webgl/WebGLLights.js +584 -0
  1114. package/src/renderers/webgl/WebGLMaterials.js +602 -0
  1115. package/src/renderers/webgl/WebGLMorphtargets.js +168 -0
  1116. package/src/renderers/webgl/WebGLObjects.js +94 -0
  1117. package/src/renderers/webgl/WebGLOutput.js +270 -0
  1118. package/src/renderers/webgl/WebGLProgram.js +1031 -0
  1119. package/src/renderers/webgl/WebGLPrograms.js +679 -0
  1120. package/src/renderers/webgl/WebGLProperties.js +55 -0
  1121. package/src/renderers/webgl/WebGLRenderLists.js +253 -0
  1122. package/src/renderers/webgl/WebGLRenderStates.js +124 -0
  1123. package/src/renderers/webgl/WebGLShader.js +12 -0
  1124. package/src/renderers/webgl/WebGLShaderCache.js +124 -0
  1125. package/src/renderers/webgl/WebGLShadowMap.js +600 -0
  1126. package/src/renderers/webgl/WebGLState.js +1370 -0
  1127. package/src/renderers/webgl/WebGLTextures.js +2506 -0
  1128. package/src/renderers/webgl/WebGLUniforms.js +1203 -0
  1129. package/src/renderers/webgl/WebGLUniformsGroups.js +413 -0
  1130. package/src/renderers/webgl/WebGLUtils.js +217 -0
  1131. package/src/renderers/webgl-fallback/WebGLBackend.js +2783 -0
  1132. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +99 -0
  1133. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +1676 -0
  1134. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +359 -0
  1135. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +89 -0
  1136. package/src/renderers/webgl-fallback/utils/WebGLConstants.js +13 -0
  1137. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +83 -0
  1138. package/src/renderers/webgl-fallback/utils/WebGLState.js +1361 -0
  1139. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +1324 -0
  1140. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
  1141. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +317 -0
  1142. package/src/renderers/webgpu/WebGPUBackend.js +2602 -0
  1143. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +69 -0
  1144. package/src/renderers/webgpu/WebGPURenderer.js +107 -0
  1145. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +66 -0
  1146. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +100 -0
  1147. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +2523 -0
  1148. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +187 -0
  1149. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +25 -0
  1150. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +522 -0
  1151. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +642 -0
  1152. package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
  1153. package/src/renderers/webgpu/utils/WebGPUConstants.js +354 -0
  1154. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +846 -0
  1155. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +389 -0
  1156. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +1673 -0
  1157. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
  1158. package/src/renderers/webgpu/utils/WebGPUUtils.js +269 -0
  1159. package/src/renderers/webxr/WebXRController.js +440 -0
  1160. package/src/renderers/webxr/WebXRDepthSensing.js +155 -0
  1161. package/src/renderers/webxr/WebXRManager.js +1103 -0
  1162. package/src/scenes/Fog.js +98 -0
  1163. package/src/scenes/FogExp2.js +86 -0
  1164. package/src/scenes/Scene.js +165 -0
  1165. package/src/textures/CanvasTexture.js +45 -0
  1166. package/src/textures/CompressedArrayTexture.js +89 -0
  1167. package/src/textures/CompressedCubeTexture.js +48 -0
  1168. package/src/textures/CompressedTexture.js +86 -0
  1169. package/src/textures/CubeDepthTexture.js +76 -0
  1170. package/src/textures/CubeTexture.js +81 -0
  1171. package/src/textures/Data3DTexture.js +112 -0
  1172. package/src/textures/DataArrayTexture.js +134 -0
  1173. package/src/textures/DataTexture.js +87 -0
  1174. package/src/textures/DepthTexture.js +104 -0
  1175. package/src/textures/ExternalTexture.js +56 -0
  1176. package/src/textures/FramebufferTexture.js +85 -0
  1177. package/src/textures/HTMLTexture.js +74 -0
  1178. package/src/textures/Source.js +230 -0
  1179. package/src/textures/Texture.js +812 -0
  1180. package/src/textures/VideoFrameTexture.js +72 -0
  1181. package/src/textures/VideoTexture.js +127 -0
  1182. package/src/utils.js +493 -0
@@ -0,0 +1,2523 @@
1
+ import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js';
2
+
3
+ import NodeSampler from '../../common/nodes/NodeSampler.js';
4
+ import { NodeSampledTexture, NodeSampledCubeTexture, NodeSampledTexture3D } from '../../common/nodes/NodeSampledTexture.js';
5
+
6
+ import NodeUniformBuffer from '../../common/nodes/NodeUniformBuffer.js';
7
+ import NodeStorageBuffer from '../../common/nodes/NodeStorageBuffer.js';
8
+
9
+ import { NodeBuilder, CodeNode } from '../../../nodes/Nodes.js';
10
+
11
+ import { getFormat } from '../utils/WebGPUTextureUtils.js';
12
+
13
+ import WGSLNodeParser from './WGSLNodeParser.js';
14
+ import { NodeAccess } from '../../../nodes/core/constants.js';
15
+
16
+ import VarNode from '../../../nodes/core/VarNode.js';
17
+ import ExpressionNode from '../../../nodes/code/ExpressionNode.js';
18
+
19
+ import { FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, Compatibility } from '../../../constants.js';
20
+ import { warn, error } from '../../../utils.js';
21
+
22
+ import { GPUShaderStage } from '../utils/WebGPUConstants.js';
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
+ };
35
+
36
+ const gpuShaderStageLib = {
37
+ 'vertex': GPUShaderStage.VERTEX,
38
+ 'fragment': GPUShaderStage.FRAGMENT,
39
+ 'compute': GPUShaderStage.COMPUTE
40
+ };
41
+
42
+ const supports = {
43
+ instance: true,
44
+ swizzleAssign: false,
45
+ storageBuffer: true
46
+ };
47
+
48
+ const wgslFnOpLib = {
49
+ '^^': 'tsl_xor'
50
+ };
51
+
52
+ const wgslTypeLib = {
53
+ float: 'f32',
54
+ int: 'i32',
55
+ uint: 'u32',
56
+ bool: 'bool',
57
+ color: 'vec3<f32>',
58
+
59
+ vec2: 'vec2<f32>',
60
+ ivec2: 'vec2<i32>',
61
+ uvec2: 'vec2<u32>',
62
+ bvec2: 'vec2<bool>',
63
+
64
+ vec3: 'vec3<f32>',
65
+ ivec3: 'vec3<i32>',
66
+ uvec3: 'vec3<u32>',
67
+ bvec3: 'vec3<bool>',
68
+
69
+ vec4: 'vec4<f32>',
70
+ ivec4: 'vec4<i32>',
71
+ uvec4: 'vec4<u32>',
72
+ bvec4: 'vec4<bool>',
73
+
74
+ mat2: 'mat2x2<f32>',
75
+ mat3: 'mat3x3<f32>',
76
+ mat4: 'mat4x4<f32>'
77
+ };
78
+
79
+ const wgslCodeCache = {};
80
+
81
+ const wgslPolyfill = {
82
+ tsl_xor: new CodeNode( 'fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }' ),
83
+ mod_float: new CodeNode( 'fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }' ),
84
+ mod_vec2: new CodeNode( 'fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }' ),
85
+ mod_vec3: new CodeNode( 'fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }' ),
86
+ mod_vec4: new CodeNode( 'fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }' ),
87
+ equals_bool: new CodeNode( 'fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }' ),
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 ); }' ),
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 ); }' ),
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 ); }' ),
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 {
96
+
97
+ let res = vec2f( iRes );
98
+
99
+ let uvScaled = coord * res;
100
+ let uvWrapping = ( ( uvScaled % res ) + res ) % res;
101
+
102
+ // https://www.shadertoy.com/view/WtyXRy
103
+
104
+ let uv = uvWrapping - 0.5;
105
+ let iuv = floor( uv );
106
+ let f = fract( uv );
107
+
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
+
113
+ return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
114
+
115
+ }
116
+ ` ),
117
+ biquadraticTextureArray: new CodeNode( /* wgsl */`
118
+ fn tsl_biquadraticTexture_array( map : texture_2d_array<f32>, coord : vec2f, iRes : vec2u, layer : u32, level : u32 ) -> vec4f {
119
+
120
+ let res = vec2f( iRes );
121
+
122
+ let uvScaled = coord * res;
123
+ let uvWrapping = ( ( uvScaled % res ) + res ) % res;
124
+
125
+ // https://www.shadertoy.com/view/WtyXRy
126
+
127
+ let uv = uvWrapping - 0.5;
128
+ let iuv = floor( uv );
129
+ let f = fract( uv );
130
+
131
+ let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, layer, level );
132
+ let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, layer, level );
133
+ let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, layer, level );
134
+ let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, layer, level );
135
+
136
+ return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
137
+
138
+ }
139
+ ` )
140
+ };
141
+
142
+ const wgslMethods = {
143
+ dFdx: 'dpdx',
144
+ dFdy: '- dpdy',
145
+ mod_float: 'tsl_mod_float',
146
+ mod_vec2: 'tsl_mod_vec2',
147
+ mod_vec3: 'tsl_mod_vec3',
148
+ mod_vec4: 'tsl_mod_vec4',
149
+ equals_bool: 'tsl_equals_bool',
150
+ equals_bvec2: 'tsl_equals_bvec2',
151
+ equals_bvec3: 'tsl_equals_bvec3',
152
+ equals_bvec4: 'tsl_equals_bvec4',
153
+ inversesqrt: 'inverseSqrt',
154
+ bitcast: 'bitcast<f32>',
155
+ floatpack_snorm_2x16: 'pack2x16snorm',
156
+ floatpack_unorm_2x16: 'pack2x16unorm',
157
+ floatpack_float16_2x16: 'pack2x16float',
158
+ floatunpack_snorm_2x16: 'unpack2x16snorm',
159
+ floatunpack_unorm_2x16: 'unpack2x16unorm',
160
+ floatunpack_float16_2x16: 'unpack2x16float'
161
+ };
162
+
163
+ //
164
+
165
+ let diagnostics = '';
166
+
167
+ if ( ( typeof navigator !== 'undefined' && /Firefox|Deno/g.test( navigator.userAgent ) ) !== true ) {
168
+
169
+ diagnostics += 'diagnostic( off, derivative_uniformity );\n';
170
+
171
+ }
172
+
173
+ /**
174
+ * A node builder targeting WGSL.
175
+ *
176
+ * This module generates WGSL shader code from node materials and also
177
+ * generates the respective bindings and vertex buffer definitions. These
178
+ * data are later used by the renderer to create render and compute pipelines
179
+ * for render objects.
180
+ *
181
+ * @augments NodeBuilder
182
+ */
183
+ class WGSLNodeBuilder extends NodeBuilder {
184
+
185
+ /**
186
+ * Constructs a new WGSL node builder renderer.
187
+ *
188
+ * @param {Object3D} object - The 3D object.
189
+ * @param {Renderer} renderer - The renderer.
190
+ */
191
+ constructor( object, renderer ) {
192
+
193
+ super( object, renderer, new WGSLNodeParser() );
194
+
195
+ /**
196
+ * A dictionary that holds for each shader stage ('vertex', 'fragment', 'compute')
197
+ * another dictionary which manages UBOs per group ('render','frame','object').
198
+ *
199
+ * @type {Object<string,Object<string,NodeUniformsGroup>>}
200
+ */
201
+ this.uniformGroups = {};
202
+
203
+ /**
204
+ * A dictionary that holds the assigned binding indices for each uniform group.
205
+ * This ensures the same binding index is used across all shader stages.
206
+ *
207
+ * @type {Object<string,{index: number, id: number}>}
208
+ */
209
+ this.uniformGroupsBindings = {};
210
+
211
+ /**
212
+ * A dictionary that holds for each shader stage a Map of builtins.
213
+ *
214
+ * @type {Object<string,Map<string,Object>>}
215
+ */
216
+ this.builtins = {};
217
+
218
+ /**
219
+ * A dictionary that holds for each shader stage a Set of directives.
220
+ *
221
+ * @type {Object<string,Set<string>>}
222
+ */
223
+ this.directives = {};
224
+
225
+ /**
226
+ * A map for managing scope arrays. Only relevant for when using
227
+ * {@link WorkgroupInfoNode} in context of compute shaders.
228
+ *
229
+ * @type {Map<string,Object>}
230
+ */
231
+ this.scopedArrays = new Map();
232
+
233
+ /**
234
+ * A flag that indicates that early returns are allowed.
235
+ *
236
+ * @type {boolean}
237
+ * @default true
238
+ */
239
+ this.allowEarlyReturns = true;
240
+
241
+ /**
242
+ * A flag that indicates that global variables are allowed.
243
+ *
244
+ * @type {boolean}
245
+ * @default true
246
+ */
247
+ this.allowGlobalVariables = true;
248
+
249
+ }
250
+
251
+ /**
252
+ * Generates the WGSL snippet for sampled textures.
253
+ *
254
+ * @private
255
+ * @param {Texture} texture - The texture.
256
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
257
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
258
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
259
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
260
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
261
+ * @return {string} The WGSL snippet.
262
+ */
263
+ _generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
264
+
265
+ if ( shaderStage === 'fragment' ) {
266
+
267
+ if ( depthSnippet ) {
268
+
269
+ if ( offsetSnippet ) {
270
+
271
+ return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
272
+
273
+ }
274
+
275
+ return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
276
+
277
+ } else {
278
+
279
+ if ( offsetSnippet ) {
280
+
281
+ return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
282
+
283
+ }
284
+
285
+ return `textureSample( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet } )`;
286
+
287
+ }
288
+
289
+ } else {
290
+
291
+ return this.generateTextureSampleLevel( texture, textureProperty, uvSnippet, '0', depthSnippet );
292
+
293
+ }
294
+
295
+ }
296
+
297
+ /**
298
+ * Generates the WGSL snippet when sampling textures with explicit mip level.
299
+ *
300
+ * @private
301
+ * @param {Texture} texture - The texture.
302
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
303
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
304
+ * @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
305
+ * @param {string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
306
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
307
+ * @return {string} The WGSL snippet.
308
+ */
309
+ generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
310
+
311
+ if ( this.isUnfilterable( texture ) === false ) {
312
+
313
+ if ( depthSnippet ) {
314
+
315
+ if ( offsetSnippet ) {
316
+
317
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
318
+
319
+ }
320
+
321
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
322
+
323
+ } else {
324
+
325
+ if ( offsetSnippet ) {
326
+
327
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
328
+
329
+ }
330
+
331
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
332
+
333
+ }
334
+
335
+ } else if ( this.isFilteredTexture( texture ) ) {
336
+
337
+ return this.generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet, depthSnippet );
338
+
339
+ } else {
340
+
341
+ return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, levelSnippet );
342
+
343
+ }
344
+
345
+ }
346
+
347
+ /**
348
+ * Generates a wrap function used in context of textures.
349
+ *
350
+ * @param {Texture} texture - The texture to generate the function for.
351
+ * @return {string} The name of the generated function.
352
+ */
353
+ generateWrapFunction( texture ) {
354
+
355
+ const functionName = `tsl_coord_${ wrapNames[ texture.wrapS ] }S_${ wrapNames[ texture.wrapT ] }_${ texture.is3DTexture || texture.isData3DTexture ? '3d' : '2d' }T`;
356
+
357
+ let nodeCode = wgslCodeCache[ functionName ];
358
+
359
+ if ( nodeCode === undefined ) {
360
+
361
+ const includes = [];
362
+
363
+ // For 3D textures, use vec3f; for texture arrays, keep vec2f since array index is separate
364
+ const coordType = texture.is3DTexture || texture.isData3DTexture ? 'vec3f' : 'vec2f';
365
+ let code = `fn ${ functionName }( coord : ${ coordType } ) -> ${ coordType } {\n\n\treturn ${ coordType }(\n`;
366
+
367
+ const addWrapSnippet = ( wrap, axis ) => {
368
+
369
+ if ( wrap === RepeatWrapping ) {
370
+
371
+ includes.push( wgslPolyfill.repeatWrapping_float );
372
+
373
+ code += `\t\ttsl_repeatWrapping_float( coord.${ axis } )`;
374
+
375
+ } else if ( wrap === ClampToEdgeWrapping ) {
376
+
377
+ includes.push( wgslPolyfill.clampWrapping_float );
378
+
379
+ code += `\t\ttsl_clampWrapping_float( coord.${ axis } )`;
380
+
381
+ } else if ( wrap === MirroredRepeatWrapping ) {
382
+
383
+ includes.push( wgslPolyfill.mirrorWrapping_float );
384
+
385
+ code += `\t\ttsl_mirrorWrapping_float( coord.${ axis } )`;
386
+
387
+ } else {
388
+
389
+ code += `\t\tcoord.${ axis }`;
390
+
391
+ warn( `WebGPURenderer: Unsupported texture wrap type "${ wrap }" for vertex shader.` );
392
+
393
+ }
394
+
395
+ };
396
+
397
+ addWrapSnippet( texture.wrapS, 'x' );
398
+
399
+ code += ',\n';
400
+
401
+ addWrapSnippet( texture.wrapT, 'y' );
402
+
403
+ if ( texture.is3DTexture || texture.isData3DTexture ) {
404
+
405
+ code += ',\n';
406
+ addWrapSnippet( texture.wrapR, 'z' );
407
+
408
+ }
409
+
410
+ code += '\n\t);\n\n}\n';
411
+
412
+ wgslCodeCache[ functionName ] = nodeCode = new CodeNode( code, includes );
413
+
414
+ }
415
+
416
+ nodeCode.build( this );
417
+
418
+ return functionName;
419
+
420
+ }
421
+
422
+ /**
423
+ * Generates the array declaration string.
424
+ *
425
+ * @param {string} type - The type.
426
+ * @param {?number} [count] - The count.
427
+ * @return {string} The generated value as a shader string.
428
+ */
429
+ generateArrayDeclaration( type, count ) {
430
+
431
+ return `array< ${ this.getType( type ) }, ${ count } >`;
432
+
433
+ }
434
+
435
+ /**
436
+ * Generates a WGSL variable that holds the texture dimension of the given texture.
437
+ * It also returns information about the number of layers (elements) of an arrayed
438
+ * texture as well as the cube face count of cube textures.
439
+ *
440
+ * @param {Texture} texture - The texture to generate the function for.
441
+ * @param {string} textureProperty - The name of the video texture uniform in the shader.
442
+ * @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
443
+ * @return {string} The name of the dimension variable.
444
+ */
445
+ generateTextureDimension( texture, textureProperty, levelSnippet ) {
446
+
447
+ const textureData = this.getDataFromNode( texture, this.shaderStage, this.cache );
448
+
449
+ if ( textureData.dimensionsSnippet === undefined ) textureData.dimensionsSnippet = {};
450
+
451
+ let textureDimensionNode = textureData.dimensionsSnippet[ levelSnippet ];
452
+
453
+ if ( textureData.dimensionsSnippet[ levelSnippet ] === undefined ) {
454
+
455
+ let textureDimensionsParams;
456
+ let dimensionType;
457
+
458
+ const { primarySamples } = this.renderer.backend.utils.getTextureSampleData( texture );
459
+ const isMultisampled = primarySamples > 1;
460
+
461
+ if ( texture.is3DTexture || texture.isData3DTexture ) {
462
+
463
+ dimensionType = 'vec3<u32>';
464
+
465
+ } else {
466
+
467
+ // Regular 2D textures, depth textures, etc.
468
+ dimensionType = 'vec2<u32>';
469
+
470
+ }
471
+
472
+ // Build parameters string based on texture type and multisampling
473
+ if ( isMultisampled || texture.isStorageTexture ) {
474
+
475
+ textureDimensionsParams = textureProperty;
476
+
477
+ } else {
478
+
479
+ textureDimensionsParams = `${textureProperty}${levelSnippet ? `, u32( ${ levelSnippet } )` : ''}`;
480
+
481
+ }
482
+
483
+ textureDimensionNode = new VarNode( new ExpressionNode( `textureDimensions( ${ textureDimensionsParams } )`, dimensionType ) );
484
+
485
+ textureData.dimensionsSnippet[ levelSnippet ] = textureDimensionNode;
486
+
487
+ if ( texture.isArrayTexture || texture.isDataArrayTexture || texture.is3DTexture || texture.isData3DTexture ) {
488
+
489
+ textureData.arrayLayerCount = new VarNode(
490
+ new ExpressionNode(
491
+ `textureNumLayers(${textureProperty})`,
492
+ 'u32'
493
+ )
494
+ );
495
+
496
+ }
497
+
498
+ // For cube textures, we know it's always 6 faces
499
+ if ( texture.isTextureCube ) {
500
+
501
+ textureData.cubeFaceCount = new VarNode(
502
+ new ExpressionNode( '6u', 'u32' )
503
+ );
504
+
505
+ }
506
+
507
+ }
508
+
509
+ return textureDimensionNode.build( this );
510
+
511
+ }
512
+
513
+ /**
514
+ * Generates the WGSL snippet for a manual filtered texture.
515
+ *
516
+ * @param {Texture} texture - The texture.
517
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
518
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
519
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
520
+ * @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
521
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
522
+ * @return {string} The WGSL snippet.
523
+ */
524
+ generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet = '0u', depthSnippet ) {
525
+
526
+ const wrapFunction = this.generateWrapFunction( texture );
527
+ const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
528
+
529
+ if ( offsetSnippet ) {
530
+
531
+ uvSnippet = `${ uvSnippet } + vec2<f32>(${ offsetSnippet }) / ${ textureDimension }`;
532
+
533
+ }
534
+
535
+ if ( depthSnippet ) {
536
+
537
+ this._include( 'biquadraticTextureArray' );
538
+
539
+ return `tsl_biquadraticTexture_array( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ depthSnippet } ), u32( ${ levelSnippet } ) )`;
540
+
541
+ }
542
+
543
+ this._include( 'biquadraticTexture' );
544
+
545
+ return `tsl_biquadraticTexture( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ levelSnippet } ) )`;
546
+
547
+ }
548
+
549
+ /**
550
+ * Generates the WGSL snippet for a texture lookup with explicit level-of-detail.
551
+ * Since it's a lookup, no sampling or filtering is applied.
552
+ *
553
+ * @param {Texture} texture - The texture.
554
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
555
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
556
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
557
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
558
+ * @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
559
+ * @return {string} The WGSL snippet.
560
+ */
561
+ generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, levelSnippet = '0u' ) {
562
+
563
+ // Cube textures cannot use textureLoad in WGSL, must use textureSampleLevel
564
+ if ( texture.isCubeTexture === true ) {
565
+
566
+ if ( offsetSnippet ) {
567
+
568
+ uvSnippet = `${ uvSnippet } + vec3<f32>(${ offsetSnippet })`;
569
+
570
+ }
571
+
572
+ // Depth textures require integer level, regular textures use float
573
+ const levelType = texture.isDepthTexture ? 'u32' : 'f32';
574
+
575
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelType }( ${ levelSnippet } ) )`;
576
+
577
+ }
578
+
579
+ const wrapFunction = this.generateWrapFunction( texture );
580
+ const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
581
+
582
+ const vecType = texture.is3DTexture || texture.isData3DTexture ? 'vec3' : 'vec2';
583
+ const textureDimensionMargin = ( vecType === 'vec3' ) ? 'vec3<u32>( 1, 1, 1 )' : 'vec2<u32>( 1, 1 )';
584
+
585
+ if ( offsetSnippet ) {
586
+
587
+ uvSnippet = `${ uvSnippet } + ${ vecType }<f32>(${ offsetSnippet }) / ${ vecType }<f32>( ${ textureDimension } )`;
588
+
589
+ }
590
+
591
+ const clampMin = `${ vecType }<f32>( 0 )`;
592
+ const clampMax = `${ vecType }<f32>( ${ textureDimension } - ${ textureDimensionMargin } )`;
593
+
594
+ uvSnippet = `${ vecType }<u32>( clamp( floor( ${ wrapFunction }( ${ uvSnippet } ) * ${ vecType }<f32>( ${ textureDimension } ) ), ${ clampMin }, ${ clampMax } ) )`;
595
+
596
+ return this.generateTextureLoad( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, null );
597
+
598
+ }
599
+
600
+ /**
601
+ * Generates the WGSL snippet that reads a single texel from a storage texture.
602
+ *
603
+ * @param {Texture} texture - The texture.
604
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
605
+ * @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
606
+ * @param {?string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
607
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
608
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
609
+ * @return {string} The WGSL snippet.
610
+ */
611
+ generateStorageTextureLoad( texture, textureProperty, uvIndexSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
612
+
613
+ if ( offsetSnippet ) {
614
+
615
+ uvIndexSnippet = `${ uvIndexSnippet } + ${ offsetSnippet }`;
616
+
617
+ }
618
+
619
+ let snippet;
620
+
621
+ if ( depthSnippet ) {
622
+
623
+ snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet } )`;
624
+
625
+ } else {
626
+
627
+ snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`;
628
+
629
+ }
630
+
631
+ return snippet;
632
+
633
+ }
634
+
635
+ /**
636
+ * Generates the WGSL snippet that reads a single texel from a texture without sampling or filtering.
637
+ *
638
+ * @param {Texture} texture - The texture.
639
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
640
+ * @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
641
+ * @param {?string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
642
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
643
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
644
+ * @return {string} The WGSL snippet.
645
+ */
646
+ generateTextureLoad( texture, textureProperty, uvIndexSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
647
+
648
+ if ( levelSnippet === null ) levelSnippet = '0u';
649
+
650
+ if ( offsetSnippet ) {
651
+
652
+ uvIndexSnippet = `${ uvIndexSnippet } + ${ offsetSnippet }`;
653
+
654
+ }
655
+
656
+ let snippet;
657
+
658
+ if ( depthSnippet ) {
659
+
660
+ snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
661
+
662
+ } else {
663
+
664
+ snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, u32( ${ levelSnippet } ) )`;
665
+
666
+ if ( this.renderer.backend.compatibilityMode && texture.isDepthTexture ) {
667
+
668
+ snippet += '.x';
669
+
670
+ }
671
+
672
+ }
673
+
674
+ return snippet;
675
+
676
+ }
677
+
678
+ /**
679
+ * Generates the WGSL snippet that writes a single texel to a texture.
680
+ *
681
+ * @param {Texture} texture - The texture.
682
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
683
+ * @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
684
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
685
+ * @param {string} valueSnippet - A WGSL snippet that represent the new texel value.
686
+ * @return {string} The WGSL snippet.
687
+ */
688
+ generateTextureStore( texture, textureProperty, uvIndexSnippet, depthSnippet, valueSnippet ) {
689
+
690
+ let snippet;
691
+
692
+ if ( depthSnippet ) {
693
+
694
+ snippet = `textureStore( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, ${ valueSnippet } )`;
695
+
696
+ } else {
697
+
698
+ snippet = `textureStore( ${ textureProperty }, ${ uvIndexSnippet }, ${ valueSnippet } )`;
699
+
700
+ }
701
+
702
+ return snippet;
703
+
704
+ }
705
+
706
+ /**
707
+ * Returns `true` if the sampled values of the given texture should be compared against a reference value.
708
+ *
709
+ * @param {Texture} texture - The texture.
710
+ * @return {boolean} Whether the sampled values of the given texture should be compared against a reference value or not.
711
+ */
712
+ isSampleCompare( texture ) {
713
+
714
+ return texture.isDepthTexture === true && texture.compareFunction !== null && this.renderer.hasCompatibility( Compatibility.TEXTURE_COMPARE );
715
+
716
+ }
717
+
718
+ /**
719
+ * Returns `true` if the given texture is unfilterable.
720
+ *
721
+ * @param {Texture} texture - The texture.
722
+ * @return {boolean} Whether the given texture is unfilterable or not.
723
+ */
724
+ isUnfilterable( texture ) {
725
+
726
+ return this.getComponentTypeFromTexture( texture ) !== 'float' ||
727
+ ( ! this.isAvailable( 'float32Filterable' ) && texture.type === FloatType ) ||
728
+ ( this.isSampleCompare( texture ) === false && texture.minFilter === NearestFilter && texture.magFilter === NearestFilter ) ||
729
+ this.renderer.backend.utils.getTextureSampleData( texture ).primarySamples > 1;
730
+
731
+ }
732
+
733
+ /**
734
+ * Generates the WGSL snippet for sampling/loading the given texture.
735
+ *
736
+ * @param {Texture} texture - The texture.
737
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
738
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
739
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
740
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
741
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
742
+ * @return {string} The WGSL snippet.
743
+ */
744
+ generateTexture( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
745
+
746
+ let snippet = null;
747
+
748
+ if ( this.isUnfilterable( texture ) ) {
749
+
750
+ snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, '0', shaderStage );
751
+
752
+ } else {
753
+
754
+ snippet = this._generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, shaderStage );
755
+
756
+ }
757
+
758
+ return snippet;
759
+
760
+ }
761
+
762
+ /**
763
+ * Generates the WGSL snippet for sampling/loading the given texture using explicit gradients.
764
+ *
765
+ * @param {Texture} texture - The texture.
766
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
767
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
768
+ * @param {Array<string>} gradSnippet - An array holding both gradient WGSL snippets.
769
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
770
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
771
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
772
+ * @return {string} The WGSL snippet.
773
+ */
774
+ generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
775
+
776
+ if ( shaderStage === 'fragment' ) {
777
+
778
+ if ( depthSnippet ) {
779
+
780
+ if ( offsetSnippet ) {
781
+
782
+ return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
783
+
784
+ }
785
+
786
+ return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
787
+
788
+ } else {
789
+
790
+ if ( offsetSnippet ) {
791
+
792
+ return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
793
+
794
+ }
795
+
796
+ return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
797
+
798
+ }
799
+
800
+ } else {
801
+
802
+ error( `WebGPURenderer: THREE.TextureNode.gradient() does not support ${ shaderStage } shader.` );
803
+
804
+ }
805
+
806
+ }
807
+
808
+ /**
809
+ * Generates the WGSL snippet for sampling a depth texture and comparing the sampled depth values
810
+ * against a reference value.
811
+ *
812
+ * @param {Texture} texture - The texture.
813
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
814
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
815
+ * @param {string} compareSnippet - A WGSL snippet that represents the reference value.
816
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
817
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
818
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
819
+ * @return {string} The WGSL snippet.
820
+ */
821
+ generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
822
+
823
+ if ( shaderStage === 'fragment' ) {
824
+
825
+ if ( texture.isDepthTexture === true && texture.isArrayTexture === true ) {
826
+
827
+ if ( offsetSnippet ) {
828
+
829
+ return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
830
+
831
+ }
832
+
833
+ return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet } )`;
834
+
835
+ }
836
+
837
+ if ( offsetSnippet ) {
838
+
839
+ return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
840
+
841
+ }
842
+
843
+ return `textureSampleCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet } )`;
844
+
845
+ } else {
846
+
847
+ error( `WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${ shaderStage } shader.` );
848
+
849
+ }
850
+
851
+ }
852
+
853
+ /**
854
+ * Generates the WGSL snippet when sampling textures with explicit mip level.
855
+ *
856
+ * @param {Texture} texture - The texture.
857
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
858
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
859
+ * @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
860
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
861
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
862
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
863
+ * @return {string} The WGSL snippet.
864
+ */
865
+ generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
866
+
867
+ if ( this.isUnfilterable( texture ) === false ) {
868
+
869
+ if ( depthSnippet ) {
870
+
871
+ if ( offsetSnippet ) {
872
+
873
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
874
+
875
+ }
876
+
877
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
878
+
879
+ } else {
880
+
881
+ if ( offsetSnippet ) {
882
+
883
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
884
+
885
+ }
886
+
887
+ return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
888
+
889
+ }
890
+
891
+ } else if ( this.isFilteredTexture( texture ) ) {
892
+
893
+ return this.generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet, depthSnippet );
894
+
895
+ } else {
896
+
897
+ return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, levelSnippet );
898
+
899
+ }
900
+
901
+ }
902
+
903
+ /**
904
+ * Generates the WGSL snippet when sampling textures with a bias to the mip level.
905
+ *
906
+ * @param {Texture} texture - The texture.
907
+ * @param {string} textureProperty - The name of the texture uniform in the shader.
908
+ * @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
909
+ * @param {string} biasSnippet - A WGSL snippet that represents the bias to apply to the mip level before sampling.
910
+ * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
911
+ * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
912
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
913
+ * @return {string} The WGSL snippet.
914
+ */
915
+ generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet, offsetSnippet, shaderStage = this.shaderStage ) {
916
+
917
+ if ( shaderStage === 'fragment' ) {
918
+
919
+ if ( depthSnippet ) {
920
+
921
+ if ( offsetSnippet ) {
922
+
923
+ return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
924
+
925
+ }
926
+
927
+ return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet } )`;
928
+
929
+ } else {
930
+
931
+ if ( offsetSnippet ) {
932
+
933
+ return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
934
+
935
+ }
936
+
937
+ return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`;
938
+
939
+ }
940
+
941
+ } else {
942
+
943
+ error( `WebGPURenderer: THREE.TextureNode.biasNode does not support ${ shaderStage } shader.` );
944
+
945
+ }
946
+
947
+ }
948
+
949
+ /**
950
+ * Returns a WGSL snippet that represents the property name of the given node.
951
+ *
952
+ * @param {Node} node - The node.
953
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
954
+ * @return {string} The property name.
955
+ */
956
+ getPropertyName( node, shaderStage = this.shaderStage ) {
957
+
958
+ if ( node.isNodeVarying === true && node.needsInterpolation === true ) {
959
+
960
+ if ( shaderStage === 'vertex' ) {
961
+
962
+ return `varyings.${ node.name }`;
963
+
964
+ }
965
+
966
+ } else if ( node.isNodeUniform === true ) {
967
+
968
+ const name = node.name;
969
+ const type = node.type;
970
+
971
+ if ( type === 'texture' || type === 'cubeTexture' || type === 'cubeDepthTexture' || type === 'storageTexture' || type === 'texture3D' ) {
972
+
973
+ return name;
974
+
975
+ } else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
976
+
977
+ if ( this.isCustomStruct( node ) ) {
978
+
979
+ return name;
980
+
981
+ }
982
+
983
+ return name + '.value';
984
+
985
+ } else {
986
+
987
+ return node.groupNode.name + '.' + name;
988
+
989
+ }
990
+
991
+ }
992
+
993
+ return super.getPropertyName( node );
994
+
995
+ }
996
+
997
+ /**
998
+ * Returns the output struct name.
999
+ *
1000
+ * @return {string} The name of the output struct.
1001
+ */
1002
+ getOutputStructName() {
1003
+
1004
+ return 'output';
1005
+
1006
+ }
1007
+
1008
+ /**
1009
+ * Returns the native shader operator name for a given generic name.
1010
+ *
1011
+ * @param {string} op - The operator name to resolve.
1012
+ * @return {?string} The resolved operator name.
1013
+ */
1014
+ getFunctionOperator( op ) {
1015
+
1016
+ const fnOp = wgslFnOpLib[ op ];
1017
+
1018
+ if ( fnOp !== undefined ) {
1019
+
1020
+ this._include( fnOp );
1021
+
1022
+ return fnOp;
1023
+
1024
+ }
1025
+
1026
+ return null;
1027
+
1028
+ }
1029
+
1030
+ /**
1031
+ * Returns the node access for the given node and shader stage.
1032
+ *
1033
+ * @param {StorageTextureNode|StorageBufferNode} node - The storage node.
1034
+ * @param {string} shaderStage - The shader stage.
1035
+ * @return {string} The node access.
1036
+ */
1037
+ getNodeAccess( node, shaderStage ) {
1038
+
1039
+ if ( shaderStage !== 'compute' ) {
1040
+
1041
+ if ( node.isAtomic === true ) {
1042
+
1043
+ warn( 'WebGPURenderer: Atomic operations are only supported in compute shaders.' );
1044
+
1045
+ return NodeAccess.READ_WRITE;
1046
+
1047
+ }
1048
+
1049
+ return NodeAccess.READ_ONLY;
1050
+
1051
+ }
1052
+
1053
+ return node.access;
1054
+
1055
+ }
1056
+
1057
+ /**
1058
+ * Returns A WGSL snippet representing the storage access.
1059
+ *
1060
+ * @param {StorageTextureNode|StorageBufferNode} node - The storage node.
1061
+ * @param {string} shaderStage - The shader stage.
1062
+ * @return {string} The WGSL snippet representing the storage access.
1063
+ */
1064
+ getStorageAccess( node, shaderStage ) {
1065
+
1066
+ return accessNames[ this.getNodeAccess( node, shaderStage ) ];
1067
+
1068
+ }
1069
+
1070
+ /**
1071
+ * This method is one of the more important ones since it's responsible
1072
+ * for generating a matching binding instance for the given uniform node.
1073
+ *
1074
+ * These bindings are later used in the renderer to create bind groups
1075
+ * and layouts.
1076
+ *
1077
+ * @param {UniformNode} node - The uniform node.
1078
+ * @param {string} type - The node data type.
1079
+ * @param {string} shaderStage - The shader stage.
1080
+ * @param {?string} [name=null] - An optional uniform name.
1081
+ * @return {NodeUniform} The node uniform object.
1082
+ */
1083
+ getUniformFromNode( node, type, shaderStage, name = null ) {
1084
+
1085
+ const uniformNode = super.getUniformFromNode( node, type, shaderStage, name );
1086
+ const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
1087
+
1088
+ if ( nodeData.uniformGPU === undefined ) {
1089
+
1090
+ let uniformGPU;
1091
+
1092
+ const group = node.groupNode;
1093
+ const groupName = group.name;
1094
+
1095
+ const bindings = this.getBindGroupArray( groupName, shaderStage );
1096
+
1097
+ if ( type === 'texture' || type === 'cubeTexture' || type === 'cubeDepthTexture' || type === 'storageTexture' || type === 'texture3D' ) {
1098
+
1099
+ let texture = null;
1100
+
1101
+ const access = this.getNodeAccess( node, shaderStage );
1102
+
1103
+ if ( type === 'texture' || type === 'storageTexture' ) {
1104
+
1105
+ if ( node.value.is3DTexture === true ) {
1106
+
1107
+ texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group, access );
1108
+
1109
+ } else {
1110
+
1111
+ texture = new NodeSampledTexture( uniformNode.name, uniformNode.node, group, access );
1112
+
1113
+ }
1114
+
1115
+ } else if ( type === 'cubeTexture' || type === 'cubeDepthTexture' ) {
1116
+
1117
+ texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group, access );
1118
+
1119
+ } else if ( type === 'texture3D' ) {
1120
+
1121
+ texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group, access );
1122
+
1123
+ }
1124
+
1125
+ texture.store = node.isStorageTextureNode === true;
1126
+ texture.mipLevel = texture.store ? node.mipLevel : 0;
1127
+ texture.setVisibility( gpuShaderStageLib[ shaderStage ] );
1128
+
1129
+ // Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
1130
+ const needsSampler = node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false );
1131
+
1132
+ if ( needsSampler ) {
1133
+
1134
+ const sampler = new NodeSampler( `${ uniformNode.name }_sampler`, uniformNode.node, group );
1135
+ sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
1136
+
1137
+ bindings.push( sampler, texture );
1138
+
1139
+ uniformGPU = [ sampler, texture ];
1140
+
1141
+ } else {
1142
+
1143
+ bindings.push( texture );
1144
+
1145
+ uniformGPU = [ texture ];
1146
+
1147
+ }
1148
+
1149
+ } else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
1150
+
1151
+ const sharedData = this.getSharedDataFromNode( node );
1152
+
1153
+ let buffer = sharedData.buffer;
1154
+
1155
+ if ( buffer === undefined ) {
1156
+
1157
+ const bufferClass = type === 'buffer' ? NodeUniformBuffer : NodeStorageBuffer;
1158
+
1159
+ buffer = new bufferClass( node, group );
1160
+
1161
+ sharedData.buffer = buffer;
1162
+
1163
+ }
1164
+
1165
+ buffer.setVisibility( buffer.getVisibility() | gpuShaderStageLib[ shaderStage ] );
1166
+
1167
+ bindings.push( buffer );
1168
+
1169
+ uniformGPU = buffer;
1170
+
1171
+ uniformNode.name = name ? name : 'NodeBuffer_' + uniformNode.id;
1172
+
1173
+ } else {
1174
+
1175
+ let uniformsGroup = this.uniformGroups[ groupName ];
1176
+
1177
+ if ( uniformsGroup === undefined ) {
1178
+
1179
+ uniformsGroup = new NodeUniformsGroup( groupName, group );
1180
+ uniformsGroup.setVisibility( GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE );
1181
+
1182
+ this.uniformGroups[ groupName ] = uniformsGroup;
1183
+
1184
+ }
1185
+
1186
+ // Add to bindings for this stage if not already present
1187
+ if ( bindings.indexOf( uniformsGroup ) === - 1 ) {
1188
+
1189
+ bindings.push( uniformsGroup );
1190
+
1191
+ }
1192
+
1193
+ uniformGPU = this.getNodeUniform( uniformNode, type );
1194
+
1195
+ // Only add uniform if not already present in the group (check by name to avoid duplicates across stages)
1196
+ const uniformName = uniformGPU.name;
1197
+ const alreadyExists = uniformsGroup.uniforms.some( u => u.name === uniformName );
1198
+
1199
+ if ( ! alreadyExists ) {
1200
+
1201
+ uniformsGroup.addUniform( uniformGPU );
1202
+
1203
+ }
1204
+
1205
+ }
1206
+
1207
+ nodeData.uniformGPU = uniformGPU;
1208
+
1209
+ }
1210
+
1211
+ return uniformNode;
1212
+
1213
+ }
1214
+
1215
+ /**
1216
+ * This method should be used whenever builtins are required in nodes.
1217
+ * The internal builtins data structure will make sure builtins are
1218
+ * defined in the WGSL source.
1219
+ *
1220
+ * @param {string} name - The builtin name.
1221
+ * @param {string} property - The property name.
1222
+ * @param {string} type - The node data type.
1223
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
1224
+ * @return {string} The property name.
1225
+ */
1226
+ getBuiltin( name, property, type, shaderStage = this.shaderStage ) {
1227
+
1228
+ const map = this.builtins[ shaderStage ] || ( this.builtins[ shaderStage ] = new Map() );
1229
+
1230
+ if ( map.has( name ) === false ) {
1231
+
1232
+ map.set( name, {
1233
+ name,
1234
+ property,
1235
+ type
1236
+ } );
1237
+
1238
+ }
1239
+
1240
+ return property;
1241
+
1242
+ }
1243
+
1244
+ /**
1245
+ * Returns `true` if the given builtin is defined in the given shader stage.
1246
+ *
1247
+ * @param {string} name - The builtin name.
1248
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
1249
+ * @return {boolean} Whether the given builtin is defined in the given shader stage or not.
1250
+ */
1251
+ hasBuiltin( name, shaderStage = this.shaderStage ) {
1252
+
1253
+ return ( this.builtins[ shaderStage ] !== undefined && this.builtins[ shaderStage ].has( name ) );
1254
+
1255
+ }
1256
+
1257
+ /**
1258
+ * Returns the vertex index builtin.
1259
+ *
1260
+ * @return {string} The vertex index.
1261
+ */
1262
+ getVertexIndex() {
1263
+
1264
+ if ( this.shaderStage === 'vertex' ) {
1265
+
1266
+ return this.getBuiltin( 'vertex_index', 'vertexIndex', 'u32', 'attribute' );
1267
+
1268
+ }
1269
+
1270
+ return 'vertexIndex';
1271
+
1272
+ }
1273
+
1274
+ /**
1275
+ * Builds the given shader node.
1276
+ *
1277
+ * @param {ShaderNodeInternal} shaderNode - The shader node.
1278
+ * @return {string} The WGSL function code.
1279
+ */
1280
+ buildFunctionCode( shaderNode ) {
1281
+
1282
+ const layout = shaderNode.layout;
1283
+ const flowData = this.flowShaderNode( shaderNode );
1284
+
1285
+ const parameters = [];
1286
+
1287
+ for ( const input of layout.inputs ) {
1288
+
1289
+ parameters.push( input.name + ' : ' + this.getType( input.type ) );
1290
+
1291
+ }
1292
+
1293
+ //
1294
+
1295
+ let code = `fn ${ layout.name }( ${ parameters.join( ', ' ) } ) -> ${ this.getType( layout.type ) } {
1296
+ ${ flowData.vars }
1297
+ ${ flowData.code }
1298
+ `;
1299
+
1300
+ if ( flowData.result ) {
1301
+
1302
+ code += `\treturn ${ flowData.result };\n`;
1303
+
1304
+ }
1305
+
1306
+ code += '\n}\n';
1307
+
1308
+ //
1309
+
1310
+ return code;
1311
+
1312
+ }
1313
+
1314
+ /**
1315
+ * Contextually returns either the vertex stage instance index builtin
1316
+ * or the linearized index of an compute invocation within a grid of workgroups.
1317
+ *
1318
+ * @return {string} The instance index.
1319
+ */
1320
+ getInstanceIndex() {
1321
+
1322
+ if ( this.shaderStage === 'vertex' ) {
1323
+
1324
+ return this.getBuiltin( 'instance_index', 'instanceIndex', 'u32', 'attribute' );
1325
+
1326
+ }
1327
+
1328
+ return 'instanceIndex';
1329
+
1330
+ }
1331
+
1332
+
1333
+ /**
1334
+ * Returns a builtin representing the index of a compute invocation within the scope of a workgroup load.
1335
+ *
1336
+ * @return {string} The invocation local index.
1337
+ */
1338
+ getInvocationLocalIndex() {
1339
+
1340
+ return this.getBuiltin( 'local_invocation_index', 'invocationLocalIndex', 'u32', 'attribute' );
1341
+
1342
+ }
1343
+
1344
+ /**
1345
+ * Returns a builtin representing the size of a subgroup within the current shader.
1346
+ *
1347
+ * @return {string} The subgroup size.
1348
+ */
1349
+ getSubgroupSize() {
1350
+
1351
+ this.enableSubGroups();
1352
+
1353
+ return this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' );
1354
+
1355
+ }
1356
+
1357
+ /**
1358
+ * Returns a builtin representing the index of a compute invocation within the scope of a subgroup.
1359
+ *
1360
+ * @return {string} The invocation subgroup index.
1361
+ */
1362
+ getInvocationSubgroupIndex() {
1363
+
1364
+ this.enableSubGroups();
1365
+
1366
+ return this.getBuiltin( 'subgroup_invocation_id', 'invocationSubgroupIndex', 'u32', 'attribute' );
1367
+
1368
+ }
1369
+
1370
+ /**
1371
+ * Returns a builtin representing the index of a compute invocation's subgroup within its workgroup.
1372
+ *
1373
+ * @return {string} The subgroup index.
1374
+ */
1375
+ getSubgroupIndex() {
1376
+
1377
+ this.enableSubGroups();
1378
+
1379
+ return this.getBuiltin( 'subgroup_id', 'subgroupIndex', 'u32', 'attribute' );
1380
+
1381
+ }
1382
+
1383
+ /**
1384
+ * Overwritten as a NOP since this method is intended for the WebGL 2 backend.
1385
+ *
1386
+ * @return {null} Null.
1387
+ */
1388
+ getDrawIndex() {
1389
+
1390
+ return null;
1391
+
1392
+ }
1393
+
1394
+ /**
1395
+ * Returns the front facing builtin.
1396
+ *
1397
+ * @return {string} The front facing builtin.
1398
+ */
1399
+ getFrontFacing() {
1400
+
1401
+ return this.getBuiltin( 'front_facing', 'isFront', 'bool' );
1402
+
1403
+ }
1404
+
1405
+ /**
1406
+ * Returns the frag coord builtin.
1407
+ *
1408
+ * @return {string} The frag coord builtin.
1409
+ */
1410
+ getFragCoord() {
1411
+
1412
+ return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xy';
1413
+
1414
+ }
1415
+
1416
+ /**
1417
+ * Returns the frag depth builtin.
1418
+ *
1419
+ * @return {string} The frag depth builtin.
1420
+ */
1421
+ getFragDepth() {
1422
+
1423
+ return 'output.' + this.getBuiltin( 'frag_depth', 'depth', 'f32', 'output' );
1424
+
1425
+ }
1426
+
1427
+ /**
1428
+ * Returns the clip distances builtin.
1429
+ *
1430
+ * @return {string} The clip distances builtin.
1431
+ */
1432
+ getClipDistance() {
1433
+
1434
+ return 'varyings.hw_clip_distances';
1435
+
1436
+ }
1437
+
1438
+ /**
1439
+ * Whether to flip texture data along its vertical axis or not.
1440
+ *
1441
+ * @return {boolean} Returns always `false` in context of WGSL.
1442
+ */
1443
+ isFlipY() {
1444
+
1445
+ return false;
1446
+
1447
+ }
1448
+
1449
+ /**
1450
+ * Enables the given directive for the given shader stage.
1451
+ *
1452
+ * @param {string} name - The directive name.
1453
+ * @param {string} [shaderStage=this.shaderStage] - The shader stage to enable the directive for.
1454
+ */
1455
+ enableDirective( name, shaderStage = this.shaderStage ) {
1456
+
1457
+ const stage = this.directives[ shaderStage ] || ( this.directives[ shaderStage ] = new Set() );
1458
+ stage.add( name );
1459
+
1460
+ }
1461
+
1462
+ /**
1463
+ * Returns the directives of the given shader stage as a WGSL string.
1464
+ *
1465
+ * @param {string} shaderStage - The shader stage.
1466
+ * @return {string} A WGSL snippet that enables the directives of the given stage.
1467
+ */
1468
+ getDirectives( shaderStage ) {
1469
+
1470
+ const snippets = [];
1471
+ const directives = this.directives[ shaderStage ];
1472
+
1473
+ if ( directives !== undefined ) {
1474
+
1475
+ for ( const directive of directives ) {
1476
+
1477
+ snippets.push( `enable ${directive};` );
1478
+
1479
+ }
1480
+
1481
+ }
1482
+
1483
+ return snippets.join( '\n' );
1484
+
1485
+ }
1486
+
1487
+ /**
1488
+ * Enables the 'subgroups' directive.
1489
+ */
1490
+ enableSubGroups() {
1491
+
1492
+ this.enableDirective( 'subgroups' );
1493
+
1494
+ }
1495
+
1496
+ /**
1497
+ * Enables the 'subgroups-f16' directive.
1498
+ */
1499
+ enableSubgroupsF16() {
1500
+
1501
+ this.enableDirective( 'subgroups-f16' );
1502
+
1503
+ }
1504
+
1505
+ /**
1506
+ * Enables the 'clip_distances' directive.
1507
+ */
1508
+ enableClipDistances() {
1509
+
1510
+ this.enableDirective( 'clip_distances' );
1511
+
1512
+ }
1513
+
1514
+ /**
1515
+ * Enables the 'f16' directive.
1516
+ */
1517
+ enableShaderF16() {
1518
+
1519
+ this.enableDirective( 'f16' );
1520
+
1521
+ }
1522
+
1523
+ /**
1524
+ * Enables the 'dual_source_blending' directive.
1525
+ */
1526
+ enableDualSourceBlending() {
1527
+
1528
+ this.enableDirective( 'dual_source_blending' );
1529
+
1530
+ }
1531
+
1532
+ /**
1533
+ * Enables hardware clipping.
1534
+ *
1535
+ * @param {string} planeCount - The clipping plane count.
1536
+ */
1537
+ enableHardwareClipping( planeCount ) {
1538
+
1539
+ this.enableClipDistances();
1540
+ this.getBuiltin( 'clip_distances', 'hw_clip_distances', `array<f32, ${ planeCount } >`, 'vertex' );
1541
+
1542
+ }
1543
+
1544
+ /**
1545
+ * Returns the builtins of the given shader stage as a WGSL string.
1546
+ *
1547
+ * @param {string} shaderStage - The shader stage.
1548
+ * @return {string} A WGSL snippet that represents the builtins of the given stage.
1549
+ */
1550
+ getBuiltins( shaderStage ) {
1551
+
1552
+ const snippets = [];
1553
+ const builtins = this.builtins[ shaderStage ];
1554
+
1555
+ if ( builtins !== undefined ) {
1556
+
1557
+ for ( const { name, property, type } of builtins.values() ) {
1558
+
1559
+ snippets.push( `@builtin( ${name} ) ${property} : ${type}` );
1560
+
1561
+ }
1562
+
1563
+ }
1564
+
1565
+ return snippets.join( ',\n\t' );
1566
+
1567
+ }
1568
+
1569
+ /**
1570
+ * This method should be used when a new scoped buffer is used in context of
1571
+ * compute shaders. It adds the array to the internal data structure which is
1572
+ * later used to generate the respective WGSL.
1573
+ *
1574
+ * @param {string} name - The array name.
1575
+ * @param {string} scope - The scope.
1576
+ * @param {string} bufferType - The buffer type.
1577
+ * @param {string} bufferCount - The buffer count.
1578
+ * @return {string} The array name.
1579
+ */
1580
+ getScopedArray( name, scope, bufferType, bufferCount ) {
1581
+
1582
+ if ( this.scopedArrays.has( name ) === false ) {
1583
+
1584
+ this.scopedArrays.set( name, {
1585
+ name,
1586
+ scope,
1587
+ bufferType,
1588
+ bufferCount
1589
+ } );
1590
+
1591
+ }
1592
+
1593
+ return name;
1594
+
1595
+ }
1596
+
1597
+ /**
1598
+ * Returns the scoped arrays of the given shader stage as a WGSL string.
1599
+ *
1600
+ * @param {string} shaderStage - The shader stage.
1601
+ * @return {string|undefined} The WGSL snippet that defines the scoped arrays.
1602
+ * Returns `undefined` when used in the vertex or fragment stage.
1603
+ */
1604
+ getScopedArrays( shaderStage ) {
1605
+
1606
+ if ( shaderStage !== 'compute' ) {
1607
+
1608
+ return;
1609
+
1610
+ }
1611
+
1612
+ const snippets = [];
1613
+
1614
+ for ( const { name, scope, bufferType, bufferCount } of this.scopedArrays.values() ) {
1615
+
1616
+ const type = this.getType( bufferType );
1617
+
1618
+ snippets.push( `var<${scope}> ${name}: array< ${type}, ${bufferCount} >;` );
1619
+
1620
+ }
1621
+
1622
+ return snippets.join( '\n' );
1623
+
1624
+ }
1625
+
1626
+ /**
1627
+ * Returns the shader attributes of the given shader stage as a WGSL string.
1628
+ *
1629
+ * @param {string} shaderStage - The shader stage.
1630
+ * @return {string} The WGSL snippet that defines the shader attributes.
1631
+ */
1632
+ getAttributes( shaderStage ) {
1633
+
1634
+ const snippets = [];
1635
+
1636
+ if ( shaderStage === 'compute' ) {
1637
+
1638
+ this.getBuiltin( 'global_invocation_id', 'globalId', 'vec3<u32>', 'attribute' );
1639
+ this.getBuiltin( 'workgroup_id', 'workgroupId', 'vec3<u32>', 'attribute' );
1640
+ this.getBuiltin( 'local_invocation_id', 'localId', 'vec3<u32>', 'attribute' );
1641
+ this.getBuiltin( 'num_workgroups', 'numWorkgroups', 'vec3<u32>', 'attribute' );
1642
+
1643
+ if ( this.renderer.hasFeature( 'subgroups' ) ) {
1644
+
1645
+ this.enableDirective( 'subgroups', shaderStage );
1646
+ this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' );
1647
+
1648
+ }
1649
+
1650
+ }
1651
+
1652
+ if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
1653
+
1654
+ const builtins = this.getBuiltins( 'attribute' );
1655
+
1656
+ if ( builtins ) snippets.push( builtins );
1657
+
1658
+ const attributes = this.getAttributesArray();
1659
+
1660
+ for ( let index = 0, length = attributes.length; index < length; index ++ ) {
1661
+
1662
+ const attribute = attributes[ index ];
1663
+ const name = attribute.name;
1664
+ const type = this.getType( attribute.type );
1665
+
1666
+ snippets.push( `@location( ${index} ) ${ name } : ${ type }` );
1667
+
1668
+ }
1669
+
1670
+ }
1671
+
1672
+ return snippets.join( ',\n\t' );
1673
+
1674
+ }
1675
+
1676
+ /**
1677
+ * Returns the members of the given struct type node as a WGSL string.
1678
+ *
1679
+ * @param {StructTypeNode} struct - The struct type node.
1680
+ * @return {string} The WGSL snippet that defines the struct members.
1681
+ */
1682
+ getStructMembers( struct ) {
1683
+
1684
+ const snippets = [];
1685
+
1686
+ for ( const member of struct.members ) {
1687
+
1688
+ const prefix = struct.output ? '@location( ' + member.index + ' ) ' : '';
1689
+
1690
+ let type = this.getType( member.type );
1691
+
1692
+ if ( member.atomic ) {
1693
+
1694
+ type = 'atomic< ' + type + ' >';
1695
+
1696
+ }
1697
+
1698
+ snippets.push( `\t${ prefix + member.name } : ${ type }` );
1699
+
1700
+ }
1701
+
1702
+ if ( struct.output ) {
1703
+
1704
+ snippets.push( `\t${ this.getBuiltins( 'output' ) }` );
1705
+
1706
+ }
1707
+
1708
+ return snippets.join( ',\n' );
1709
+
1710
+ }
1711
+
1712
+ /**
1713
+ * Returns the structs of the given shader stage as a WGSL string.
1714
+ *
1715
+ * @param {string} shaderStage - The shader stage.
1716
+ * @return {string} The WGSL snippet that defines the structs.
1717
+ */
1718
+ getStructs( shaderStage ) {
1719
+
1720
+ let result = '';
1721
+
1722
+ const structs = this.structs[ shaderStage ];
1723
+
1724
+ if ( structs.length > 0 ) {
1725
+
1726
+ const snippets = [];
1727
+
1728
+ for ( const struct of structs ) {
1729
+
1730
+ let snippet = `struct ${ struct.name } {\n`;
1731
+ snippet += this.getStructMembers( struct );
1732
+ snippet += '\n};';
1733
+
1734
+ snippets.push( snippet );
1735
+
1736
+ }
1737
+
1738
+ result = '\n' + snippets.join( '\n\n' ) + '\n';
1739
+
1740
+ }
1741
+
1742
+ return result;
1743
+
1744
+ }
1745
+
1746
+ /**
1747
+ * Returns a WGSL string representing a variable.
1748
+ *
1749
+ * @param {string} type - The variable's type.
1750
+ * @param {string} name - The variable's name.
1751
+ * @param {?number} [count=null] - The array length.
1752
+ * @param {string} [qualifier=''] - The variable's qualifier.
1753
+ * @return {string} The WGSL snippet that defines a variable.
1754
+ */
1755
+ getVar( type, name, count = null, qualifier = '' ) {
1756
+
1757
+ let snippet = `var${ qualifier } ${ name } : `;
1758
+
1759
+ if ( count !== null ) {
1760
+
1761
+ snippet += this.generateArrayDeclaration( type, count );
1762
+
1763
+ } else {
1764
+
1765
+ snippet += this.getType( type );
1766
+
1767
+ }
1768
+
1769
+ return snippet;
1770
+
1771
+ }
1772
+
1773
+ /**
1774
+ * Returns the variables of the given shader stage as a WGSL string.
1775
+ *
1776
+ * @param {string} shaderStage - The shader stage.
1777
+ * @return {string} The WGSL snippet that defines the variables.
1778
+ */
1779
+ getVars( shaderStage, global = false ) {
1780
+
1781
+ let qualifier = '';
1782
+
1783
+ if ( global ) {
1784
+
1785
+ qualifier = '<private>';
1786
+
1787
+ }
1788
+
1789
+ const snippets = [];
1790
+ const vars = this.vars[ shaderStage ];
1791
+
1792
+ if ( vars !== undefined ) {
1793
+
1794
+ for ( const variable of vars ) {
1795
+
1796
+ snippets.push( `${ this.getVar( variable.type, variable.name, variable.count, qualifier ) };` );
1797
+
1798
+ }
1799
+
1800
+ }
1801
+
1802
+ return global ? snippets.join( '\n' ) : `\n\t${ snippets.join( '\n\t' ) }\n`;
1803
+
1804
+ }
1805
+
1806
+ /**
1807
+ * Returns the varyings of the given shader stage as a WGSL string.
1808
+ *
1809
+ * @param {string} shaderStage - The shader stage.
1810
+ * @return {string} The WGSL snippet that defines the varyings.
1811
+ */
1812
+ getVaryings( shaderStage ) {
1813
+
1814
+ const snippets = [];
1815
+
1816
+ if ( shaderStage === 'vertex' ) {
1817
+
1818
+ this.getBuiltin( 'position', 'builtinClipSpace', 'vec4<f32>', 'vertex' );
1819
+
1820
+ }
1821
+
1822
+ if ( shaderStage === 'vertex' || shaderStage === 'fragment' ) {
1823
+
1824
+ const varyings = this.varyings;
1825
+ const vars = this.vars[ shaderStage ];
1826
+
1827
+ let varyingIndex = 0;
1828
+
1829
+ for ( let index = 0; index < varyings.length; index ++ ) {
1830
+
1831
+ const varying = varyings[ index ];
1832
+
1833
+ if ( varying.needsInterpolation ) {
1834
+
1835
+ let attributesSnippet = `@location( ${ varyingIndex ++ } )`;
1836
+
1837
+ if ( varying.interpolationType ) {
1838
+
1839
+ const samplingSnippet = varying.interpolationSampling !== null ? `, ${ varying.interpolationSampling } )` : ' )';
1840
+
1841
+ attributesSnippet += ` @interpolate( ${ varying.interpolationType }${ samplingSnippet }`;
1842
+
1843
+ // Otherwise, optimize interpolation when sensible
1844
+
1845
+ } else if ( /^(int|uint|ivec|uvec)/.test( varying.type ) ) {
1846
+
1847
+ attributesSnippet += ' @interpolate(flat, either)';
1848
+
1849
+ }
1850
+
1851
+ snippets.push( `${ attributesSnippet } ${ varying.name } : ${ this.getType( varying.type ) }` );
1852
+
1853
+ } else if ( shaderStage === 'vertex' && vars.includes( varying ) === false ) {
1854
+
1855
+ vars.push( varying );
1856
+
1857
+ }
1858
+
1859
+ }
1860
+
1861
+ }
1862
+
1863
+ const builtins = this.getBuiltins( shaderStage );
1864
+
1865
+ if ( builtins ) snippets.push( builtins );
1866
+
1867
+ const code = snippets.join( ',\n\t' );
1868
+
1869
+ return shaderStage === 'vertex' ? this._getWGSLStruct( 'VaryingsStruct', '\t' + code ) : code;
1870
+
1871
+ }
1872
+
1873
+ isCustomStruct( nodeUniform ) {
1874
+
1875
+ const attribute = nodeUniform.value;
1876
+ const bufferNode = nodeUniform.node;
1877
+
1878
+ const isAttributeStructType = ( attribute.isBufferAttribute || attribute.isInstancedBufferAttribute ) && bufferNode.structTypeNode !== null;
1879
+
1880
+ const isStructArray =
1881
+ ( bufferNode.value && bufferNode.value.array ) &&
1882
+ ( typeof bufferNode.value.itemSize === 'number' && bufferNode.value.array.length > bufferNode.value.itemSize );
1883
+
1884
+ return isAttributeStructType && ! isStructArray;
1885
+
1886
+ }
1887
+
1888
+ /**
1889
+ * Returns the uniforms of the given shader stage as a WGSL string.
1890
+ *
1891
+ * @param {string} shaderStage - The shader stage.
1892
+ * @return {string} The WGSL snippet that defines the uniforms.
1893
+ */
1894
+ getUniforms( shaderStage ) {
1895
+
1896
+ const backend = this.renderer.backend;
1897
+ const uniforms = this.uniforms[ shaderStage ];
1898
+
1899
+ const bindingSnippets = [];
1900
+ const bufferSnippets = [];
1901
+ const structSnippets = [];
1902
+ const uniformGroups = {};
1903
+
1904
+ for ( const uniform of uniforms ) {
1905
+
1906
+ const groupName = uniform.groupNode.name;
1907
+ const uniformIndexes = this.bindingsIndexes[ groupName ];
1908
+
1909
+ if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'cubeDepthTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
1910
+
1911
+ const texture = uniform.node.value;
1912
+
1913
+ // Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
1914
+ const needsSampler = texture.isCubeTexture === true || ( this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true );
1915
+
1916
+ if ( needsSampler ) {
1917
+
1918
+ if ( this.isSampleCompare( texture ) ) {
1919
+
1920
+ bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler_comparison;` );
1921
+
1922
+ } else {
1923
+
1924
+ bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler;` );
1925
+
1926
+ }
1927
+
1928
+ }
1929
+
1930
+ let textureType;
1931
+
1932
+ let multisampled = '';
1933
+
1934
+ const { primarySamples } = backend.utils.getTextureSampleData( texture );
1935
+
1936
+ if ( primarySamples > 1 ) {
1937
+
1938
+ multisampled = '_multisampled';
1939
+
1940
+ }
1941
+
1942
+ if ( texture.isCubeTexture === true && texture.isDepthTexture === true ) {
1943
+
1944
+ textureType = 'texture_depth_cube';
1945
+
1946
+ } else if ( texture.isCubeTexture === true ) {
1947
+
1948
+ textureType = 'texture_cube<f32>';
1949
+
1950
+ } else if ( texture.isDepthTexture === true ) {
1951
+
1952
+ if ( backend.compatibilityMode && texture.compareFunction === null ) {
1953
+
1954
+ textureType = `texture${ multisampled }_2d<f32>`;
1955
+
1956
+ } else {
1957
+
1958
+ textureType = `texture_depth${ multisampled }_2d${ texture.isArrayTexture === true ? '_array' : '' }`;
1959
+
1960
+ }
1961
+
1962
+ } else if ( uniform.node.isStorageTextureNode === true ) {
1963
+
1964
+ const format = getFormat( texture, backend.device );
1965
+ const access = this.getStorageAccess( uniform.node, shaderStage );
1966
+
1967
+ const is3D = uniform.node.value.is3DTexture;
1968
+ const isArrayTexture = uniform.node.value.isArrayTexture;
1969
+
1970
+ const dimension = is3D ? '3d' : `2d${ isArrayTexture ? '_array' : '' }`;
1971
+
1972
+ textureType = `texture_storage_${ dimension }<${ format }, ${ access }>`;
1973
+
1974
+ } else if ( texture.isArrayTexture === true || texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
1975
+
1976
+ textureType = 'texture_2d_array<f32>';
1977
+
1978
+ } else if ( texture.is3DTexture === true || texture.isData3DTexture === true ) {
1979
+
1980
+ textureType = 'texture_3d<f32>';
1981
+
1982
+ } else {
1983
+
1984
+ const componentPrefix = this.getComponentTypeFromTexture( texture ).charAt( 0 );
1985
+
1986
+ textureType = `texture${ multisampled }_2d<${ componentPrefix }32>`;
1987
+
1988
+ }
1989
+
1990
+ bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name } : ${ textureType };` );
1991
+
1992
+ } else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' || uniform.type === 'indirectStorageBuffer' ) {
1993
+
1994
+ const bufferNode = uniform.node;
1995
+ const bufferType = this.getType( bufferNode.getNodeType( this ) );
1996
+ const bufferCount = bufferNode.bufferCount;
1997
+ const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : '';
1998
+ const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode, shaderStage ) }` : 'uniform';
1999
+
2000
+ if ( this.isCustomStruct( uniform ) ) {
2001
+
2002
+ bufferSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var<${ bufferAccessMode }> ${ uniform.name } : ${ bufferType };` );
2003
+
2004
+ } else {
2005
+
2006
+ const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${ bufferType }>` : `${ bufferType }`;
2007
+ const bufferSnippet = `\tvalue : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >`;
2008
+
2009
+ bufferSnippets.push( this._getWGSLStructBinding( uniform.name, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) );
2010
+
2011
+ }
2012
+
2013
+ } else {
2014
+
2015
+ const groupName = uniform.groupNode.name;
2016
+
2017
+ // Check if this group has already been processed in this shader stage
2018
+ if ( uniformGroups[ groupName ] === undefined ) {
2019
+
2020
+ // Get the shared uniform group that contains uniforms from all stages
2021
+ const sharedUniformGroup = this.uniformGroups[ groupName ];
2022
+
2023
+ if ( sharedUniformGroup !== undefined ) {
2024
+
2025
+ // Generate snippets for ALL uniforms in this shared group
2026
+ const snippets = [];
2027
+
2028
+ for ( const sharedUniform of sharedUniformGroup.uniforms ) {
2029
+
2030
+ const type = sharedUniform.getType();
2031
+ const vectorType = this.getType( this.getVectorType( type ) );
2032
+ snippets.push( `\t${ sharedUniform.name } : ${ vectorType }` );
2033
+
2034
+ }
2035
+
2036
+ // Check if this group already has an assigned binding index (from another shader stage)
2037
+ let groupBinding = this.uniformGroupsBindings[ groupName ];
2038
+
2039
+ if ( groupBinding === undefined ) {
2040
+
2041
+ // First time processing this group - assign a new binding index
2042
+ groupBinding = {
2043
+ index: uniformIndexes.binding ++,
2044
+ id: uniformIndexes.group
2045
+ };
2046
+
2047
+ this.uniformGroupsBindings[ groupName ] = groupBinding;
2048
+
2049
+ }
2050
+
2051
+ uniformGroups[ groupName ] = {
2052
+ index: groupBinding.index,
2053
+ id: groupBinding.id,
2054
+ snippets: snippets
2055
+ };
2056
+
2057
+ }
2058
+
2059
+ }
2060
+
2061
+ }
2062
+
2063
+ }
2064
+
2065
+ for ( const name in uniformGroups ) {
2066
+
2067
+ const group = uniformGroups[ name ];
2068
+
2069
+ structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) );
2070
+
2071
+ }
2072
+
2073
+ const code = [ ...bindingSnippets, ...bufferSnippets, ...structSnippets ].join( '\n' );
2074
+
2075
+ return code;
2076
+
2077
+ }
2078
+
2079
+ /**
2080
+ * Controls the code build of the shader stages.
2081
+ */
2082
+ buildCode() {
2083
+
2084
+ const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
2085
+
2086
+ this.sortBindingGroups();
2087
+
2088
+ for ( const shaderStage in shadersData ) {
2089
+
2090
+ this.shaderStage = shaderStage;
2091
+
2092
+ const allowGlobal = this.allowGlobalVariables;
2093
+
2094
+ const stageData = shadersData[ shaderStage ];
2095
+ stageData.uniforms = this.getUniforms( shaderStage );
2096
+ stageData.attributes = this.getAttributes( shaderStage );
2097
+ stageData.varyings = this.getVaryings( shaderStage );
2098
+ stageData.structs = this.getStructs( shaderStage );
2099
+ stageData.vars = this.getVars( shaderStage, allowGlobal );
2100
+ stageData.codes = this.getCodes( shaderStage );
2101
+ stageData.directives = this.getDirectives( shaderStage );
2102
+ stageData.scopedArrays = this.getScopedArrays( shaderStage );
2103
+
2104
+ //
2105
+
2106
+ let flow = '// code\n\n';
2107
+ flow += this.flowCode[ shaderStage ];
2108
+
2109
+ const flowNodes = this.flowNodes[ shaderStage ];
2110
+ const mainNode = flowNodes[ flowNodes.length - 1 ];
2111
+
2112
+ const outputNode = mainNode.outputNode;
2113
+ const isOutputStruct = ( outputNode !== undefined && outputNode.isOutputStructNode === true );
2114
+
2115
+ for ( const node of flowNodes ) {
2116
+
2117
+ const flowSlotData = this.getFlowData( node/*, shaderStage*/ );
2118
+ const slotName = node.name;
2119
+
2120
+ if ( slotName ) {
2121
+
2122
+ if ( flow.length > 0 ) flow += '\n';
2123
+
2124
+ flow += `\t// flow -> ${ slotName }\n`;
2125
+
2126
+ }
2127
+
2128
+ flow += `${ flowSlotData.code }\n\t`;
2129
+
2130
+ if ( node === mainNode && shaderStage !== 'compute' ) {
2131
+
2132
+ flow += '// result\n\n\t';
2133
+
2134
+ if ( shaderStage === 'vertex' ) {
2135
+
2136
+ flow += `varyings.builtinClipSpace = ${ flowSlotData.result };`;
2137
+
2138
+ } else if ( shaderStage === 'fragment' ) {
2139
+
2140
+ if ( isOutputStruct ) {
2141
+
2142
+ stageData.returnType = outputNode.getNodeType( this );
2143
+ stageData.structs += 'var<private> output : ' + stageData.returnType + ';';
2144
+
2145
+ flow += `return ${ flowSlotData.result };`;
2146
+
2147
+ } else {
2148
+
2149
+ let structSnippet = '\t@location( 0 ) color: vec4<f32>';
2150
+
2151
+ const builtins = this.getBuiltins( 'output' );
2152
+
2153
+ if ( builtins ) structSnippet += ',\n\t' + builtins;
2154
+
2155
+ stageData.returnType = 'OutputStruct';
2156
+ stageData.structs += this._getWGSLStruct( 'OutputStruct', structSnippet );
2157
+ stageData.structs += '\nvar<private> output : OutputStruct;';
2158
+
2159
+ flow += `output.color = ${ flowSlotData.result };\n\n\treturn output;`;
2160
+
2161
+ }
2162
+
2163
+ }
2164
+
2165
+ }
2166
+
2167
+ }
2168
+
2169
+ stageData.flow = flow;
2170
+
2171
+ }
2172
+
2173
+ this.shaderStage = null;
2174
+
2175
+ if ( this.material !== null ) {
2176
+
2177
+ this.vertexShader = this._getWGSLVertexCode( shadersData.vertex );
2178
+ this.fragmentShader = this._getWGSLFragmentCode( shadersData.fragment );
2179
+
2180
+ } else {
2181
+
2182
+ // Early strictly validated in computeNode
2183
+
2184
+ const workgroupSize = this.object.workgroupSize;
2185
+
2186
+ this.computeShader = this._getWGSLComputeCode( shadersData.compute, workgroupSize );
2187
+
2188
+ }
2189
+
2190
+ }
2191
+
2192
+ /**
2193
+ * Returns the native shader method name for a given generic name.
2194
+ *
2195
+ * @param {string} method - The method name to resolve.
2196
+ * @param {?string} [output=null] - An optional output.
2197
+ * @return {string} The resolved WGSL method name.
2198
+ */
2199
+ getMethod( method, output = null ) {
2200
+
2201
+ let wgslMethod;
2202
+
2203
+ if ( output !== null ) {
2204
+
2205
+ wgslMethod = this._getWGSLMethod( method + '_' + output );
2206
+
2207
+ }
2208
+
2209
+ if ( wgslMethod === undefined ) {
2210
+
2211
+ wgslMethod = this._getWGSLMethod( method );
2212
+
2213
+ }
2214
+
2215
+ return wgslMethod || method;
2216
+
2217
+ }
2218
+
2219
+ /**
2220
+ * Returns the bitcast method name for a given input and outputType.
2221
+ *
2222
+ * @param {string} type - The output type to bitcast to.
2223
+ * @return {string} The resolved WGSL bitcast invocation.
2224
+ */
2225
+ getBitcastMethod( type ) {
2226
+
2227
+ const dataType = this.getType( type );
2228
+
2229
+ return `bitcast<${ dataType }>`;
2230
+
2231
+ }
2232
+
2233
+ /**
2234
+ * Returns the float packing method name for a given numeric encoding.
2235
+ *
2236
+ * @param {string} encoding - The numeric encoding that describes how the float values are mapped to the integer range.
2237
+ * @returns {string} The resolve WGSL float packing method name.
2238
+ */
2239
+ getFloatPackingMethod( encoding ) {
2240
+
2241
+ return this.getMethod( `floatpack_${ encoding }_2x16` );
2242
+
2243
+ }
2244
+
2245
+ /**
2246
+ * Returns the float unpacking method name for a given numeric encoding.
2247
+ *
2248
+ * @param {string} encoding - The numeric encoding that describes how the integer values are mapped to the float range.
2249
+ * @returns {string} The resolve WGSL float unpacking method name.
2250
+ */
2251
+ getFloatUnpackingMethod( encoding ) {
2252
+
2253
+ return this.getMethod( `floatunpack_${ encoding }_2x16` );
2254
+
2255
+ }
2256
+
2257
+ /**
2258
+ * Returns the native snippet for a ternary operation.
2259
+ *
2260
+ * @param {string} condSnippet - The condition determining which expression gets resolved.
2261
+ * @param {string} ifSnippet - The expression to resolve to if the condition is true.
2262
+ * @param {string} elseSnippet - The expression to resolve to if the condition is false.
2263
+ * @return {string} The resolved method name.
2264
+ */
2265
+ getTernary( condSnippet, ifSnippet, elseSnippet ) {
2266
+
2267
+ return `select( ${elseSnippet}, ${ifSnippet}, ${condSnippet} )`;
2268
+
2269
+ }
2270
+
2271
+ /**
2272
+ * Returns the WGSL type of the given node data type.
2273
+ *
2274
+ * @param {string} type - The node data type.
2275
+ * @return {string} The WGSL type.
2276
+ */
2277
+ getType( type ) {
2278
+
2279
+ return wgslTypeLib[ type ] || type;
2280
+
2281
+ }
2282
+
2283
+ /**
2284
+ * Whether the requested feature is available or not.
2285
+ *
2286
+ * @param {string} name - The requested feature.
2287
+ * @return {boolean} Whether the requested feature is supported or not.
2288
+ */
2289
+ isAvailable( name ) {
2290
+
2291
+ let result = supports[ name ];
2292
+
2293
+ if ( result === undefined ) {
2294
+
2295
+ if ( name === 'float32Filterable' ) {
2296
+
2297
+ result = this.renderer.hasFeature( 'float32-filterable' );
2298
+
2299
+ } else if ( name === 'clipDistance' ) {
2300
+
2301
+ result = this.renderer.hasFeature( 'clip-distances' );
2302
+
2303
+ }
2304
+
2305
+ supports[ name ] = result;
2306
+
2307
+ }
2308
+
2309
+ return result;
2310
+
2311
+ }
2312
+
2313
+ /**
2314
+ * Returns the native shader method name for a given generic name.
2315
+ *
2316
+ * @private
2317
+ * @param {string} method - The method name to resolve.
2318
+ * @return {string} The resolved WGSL method name.
2319
+ */
2320
+ _getWGSLMethod( method ) {
2321
+
2322
+ if ( wgslPolyfill[ method ] !== undefined ) {
2323
+
2324
+ this._include( method );
2325
+
2326
+ }
2327
+
2328
+ return wgslMethods[ method ];
2329
+
2330
+ }
2331
+
2332
+ /**
2333
+ * Includes the given method name into the current
2334
+ * function node.
2335
+ *
2336
+ * @private
2337
+ * @param {string} name - The method name to include.
2338
+ * @return {CodeNode} The respective code node.
2339
+ */
2340
+ _include( name ) {
2341
+
2342
+ const codeNode = wgslPolyfill[ name ];
2343
+ codeNode.build( this );
2344
+
2345
+ this.addInclude( codeNode );
2346
+
2347
+ return codeNode;
2348
+
2349
+ }
2350
+
2351
+ /**
2352
+ * Returns a WGSL vertex shader based on the given shader data.
2353
+ *
2354
+ * @private
2355
+ * @param {Object} shaderData - The shader data.
2356
+ * @return {string} The vertex shader.
2357
+ */
2358
+ _getWGSLVertexCode( shaderData ) {
2359
+
2360
+ return `${ this.getSignature() }
2361
+ // directives
2362
+ ${shaderData.directives}
2363
+
2364
+ // structs
2365
+ ${shaderData.structs}
2366
+
2367
+ // uniforms
2368
+ ${shaderData.uniforms}
2369
+
2370
+ // varyings
2371
+ ${shaderData.varyings}
2372
+ var<private> varyings : VaryingsStruct;
2373
+
2374
+ // vars
2375
+ ${shaderData.vars}
2376
+
2377
+ // codes
2378
+ ${shaderData.codes}
2379
+
2380
+ @vertex
2381
+ fn main( ${shaderData.attributes} ) -> VaryingsStruct {
2382
+
2383
+ // flow
2384
+ ${shaderData.flow}
2385
+
2386
+ return varyings;
2387
+
2388
+ }
2389
+ `;
2390
+
2391
+ }
2392
+
2393
+ /**
2394
+ * Returns a WGSL fragment shader based on the given shader data.
2395
+ *
2396
+ * @private
2397
+ * @param {Object} shaderData - The shader data.
2398
+ * @return {string} The vertex shader.
2399
+ */
2400
+ _getWGSLFragmentCode( shaderData ) {
2401
+
2402
+ return `${ this.getSignature() }
2403
+ // global
2404
+ ${ diagnostics }
2405
+
2406
+ // structs
2407
+ ${shaderData.structs}
2408
+
2409
+ // uniforms
2410
+ ${shaderData.uniforms}
2411
+
2412
+ // vars
2413
+ ${shaderData.vars}
2414
+
2415
+ // codes
2416
+ ${shaderData.codes}
2417
+
2418
+ @fragment
2419
+ fn main( ${shaderData.varyings} ) -> ${shaderData.returnType} {
2420
+
2421
+ // flow
2422
+ ${shaderData.flow}
2423
+
2424
+ }
2425
+ `;
2426
+
2427
+ }
2428
+
2429
+ /**
2430
+ * Returns a WGSL compute shader based on the given shader data.
2431
+ *
2432
+ * @private
2433
+ * @param {Object} shaderData - The shader data.
2434
+ * @param {string} workgroupSize - The workgroup size.
2435
+ * @return {string} The vertex shader.
2436
+ */
2437
+ _getWGSLComputeCode( shaderData, workgroupSize ) {
2438
+
2439
+ const [ workgroupSizeX, workgroupSizeY, workgroupSizeZ ] = workgroupSize;
2440
+
2441
+ return `${ this.getSignature() }
2442
+ // directives
2443
+ ${ shaderData.directives }
2444
+
2445
+ // system
2446
+ var<private> instanceIndex : u32;
2447
+
2448
+ // locals
2449
+ ${ shaderData.scopedArrays }
2450
+
2451
+ // structs
2452
+ ${ shaderData.structs }
2453
+
2454
+ // uniforms
2455
+ ${ shaderData.uniforms }
2456
+
2457
+ // vars
2458
+ ${ this.allowGlobalVariables ? shaderData.vars : '' }
2459
+
2460
+ // codes
2461
+ ${ shaderData.codes }
2462
+
2463
+ @compute @workgroup_size( ${ workgroupSizeX }, ${ workgroupSizeY }, ${ workgroupSizeZ } )
2464
+ fn main( ${ shaderData.attributes } ) {
2465
+
2466
+ // local vars
2467
+ ${ this.allowGlobalVariables ? '' : shaderData.vars }
2468
+
2469
+ // system
2470
+ instanceIndex = globalId.x
2471
+ + globalId.y * ( ${ workgroupSizeX } * numWorkgroups.x )
2472
+ + globalId.z * ( ${ workgroupSizeX } * numWorkgroups.x ) * ( ${ workgroupSizeY } * numWorkgroups.y );
2473
+
2474
+ // flow
2475
+ ${ shaderData.flow }
2476
+
2477
+ }
2478
+ `;
2479
+
2480
+ }
2481
+
2482
+ /**
2483
+ * Returns a WGSL struct based on the given name and variables.
2484
+ *
2485
+ * @private
2486
+ * @param {string} name - The struct name.
2487
+ * @param {string} vars - The struct variables.
2488
+ * @return {string} The WGSL snippet representing a struct.
2489
+ */
2490
+ _getWGSLStruct( name, vars ) {
2491
+
2492
+ return `
2493
+ struct ${name} {
2494
+ ${vars}
2495
+ };`;
2496
+
2497
+ }
2498
+
2499
+ /**
2500
+ * Returns a WGSL struct binding.
2501
+ *
2502
+ * @private
2503
+ * @param {string} name - The struct name.
2504
+ * @param {string} vars - The struct variables.
2505
+ * @param {string} access - The access.
2506
+ * @param {number} [binding=0] - The binding index.
2507
+ * @param {number} [group=0] - The group index.
2508
+ * @return {string} The WGSL snippet representing a struct binding.
2509
+ */
2510
+ _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) {
2511
+
2512
+ const structName = name + 'Struct';
2513
+ const structSnippet = this._getWGSLStruct( structName, vars );
2514
+
2515
+ return `${structSnippet}
2516
+ @binding( ${ binding } ) @group( ${ group } )
2517
+ var<${access}> ${ name } : ${ structName };`;
2518
+
2519
+ }
2520
+
2521
+ }
2522
+
2523
+ export default WGSLNodeBuilder;