@plastic-software/three 0.180.0 → 0.181.1

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 (357) hide show
  1. package/build/three.cjs +943 -486
  2. package/build/three.core.js +506 -327
  3. package/build/three.core.min.js +1 -1
  4. package/build/three.module.js +435 -163
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +8 -2
  7. package/build/three.tsl.min.js +1 -1
  8. package/build/three.webgpu.js +3753 -1177
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +3752 -1176
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
  13. package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
  14. package/examples/jsm/animation/CCDIKSolver.js +1 -1
  15. package/examples/jsm/controls/ArcballControls.js +1 -1
  16. package/examples/jsm/controls/DragControls.js +1 -1
  17. package/examples/jsm/controls/FirstPersonControls.js +1 -1
  18. package/examples/jsm/controls/FlyControls.js +1 -1
  19. package/examples/jsm/controls/OrbitControls.js +2 -2
  20. package/examples/jsm/controls/PointerLockControls.js +2 -2
  21. package/examples/jsm/controls/TrackballControls.js +1 -1
  22. package/examples/jsm/controls/TransformControls.js +1 -1
  23. package/examples/jsm/effects/AsciiEffect.js +8 -8
  24. package/examples/jsm/exporters/DRACOExporter.js +2 -2
  25. package/examples/jsm/exporters/EXRExporter.js +1 -1
  26. package/examples/jsm/exporters/GLTFExporter.js +3 -3
  27. package/examples/jsm/exporters/USDZExporter.js +9 -2
  28. package/examples/jsm/geometries/DecalGeometry.js +2 -2
  29. package/examples/jsm/geometries/ParametricGeometry.js +1 -1
  30. package/examples/jsm/geometries/TeapotGeometry.js +2 -2
  31. package/examples/jsm/geometries/TextGeometry.js +3 -2
  32. package/examples/jsm/gpgpu/BitonicSort.js +715 -0
  33. package/examples/jsm/helpers/ViewHelper.js +43 -5
  34. package/examples/jsm/inspector/Inspector.js +427 -0
  35. package/examples/jsm/inspector/RendererInspector.js +415 -0
  36. package/examples/jsm/inspector/tabs/Console.js +204 -0
  37. package/examples/jsm/inspector/tabs/Parameters.js +332 -0
  38. package/examples/jsm/inspector/tabs/Performance.js +268 -0
  39. package/examples/jsm/inspector/tabs/Viewer.js +166 -0
  40. package/examples/jsm/inspector/ui/Graph.js +95 -0
  41. package/examples/jsm/inspector/ui/Item.js +170 -0
  42. package/examples/jsm/inspector/ui/List.js +75 -0
  43. package/examples/jsm/inspector/ui/Profiler.js +170 -0
  44. package/examples/jsm/inspector/ui/Style.js +654 -0
  45. package/examples/jsm/inspector/ui/Tab.js +46 -0
  46. package/examples/jsm/inspector/ui/Values.js +423 -0
  47. package/examples/jsm/inspector/ui/utils.js +56 -0
  48. package/examples/jsm/interactive/HTMLMesh.js +6 -10
  49. package/examples/jsm/interactive/InteractiveGroup.js +1 -1
  50. package/examples/jsm/interactive/SelectionBox.js +30 -0
  51. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  52. package/examples/jsm/loaders/3MFLoader.js +1 -1
  53. package/examples/jsm/loaders/ColladaLoader.js +2 -2
  54. package/examples/jsm/loaders/DDSLoader.js +1 -1
  55. package/examples/jsm/loaders/DRACOLoader.js +73 -22
  56. package/examples/jsm/loaders/FBXLoader.js +2 -2
  57. package/examples/jsm/loaders/FontLoader.js +23 -5
  58. package/examples/jsm/loaders/GLTFLoader.js +5 -3
  59. package/examples/jsm/loaders/KTX2Loader.js +28 -21
  60. package/examples/jsm/loaders/KTXLoader.js +2 -2
  61. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  62. package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
  63. package/examples/jsm/loaders/LUTCubeLoader.js +1 -1
  64. package/examples/jsm/loaders/LWOLoader.js +2 -2
  65. package/examples/jsm/loaders/MaterialXLoader.js +22 -5
  66. package/examples/jsm/loaders/OBJLoader.js +1 -1
  67. package/examples/jsm/loaders/PDBLoader.js +1 -1
  68. package/examples/jsm/loaders/SVGLoader.js +2 -2
  69. package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
  70. package/examples/jsm/math/ConvexHull.js +1 -1
  71. package/examples/jsm/math/ImprovedNoise.js +1 -1
  72. package/examples/jsm/math/SimplexNoise.js +1 -1
  73. package/examples/jsm/misc/ProgressiveLightMap.js +9 -3
  74. package/examples/jsm/misc/ProgressiveLightMapGPU.js +7 -1
  75. package/examples/jsm/misc/TubePainter.js +383 -40
  76. package/examples/jsm/modifiers/SimplifyModifier.js +1 -1
  77. package/examples/jsm/objects/ReflectorForSSRPass.js +1 -0
  78. package/examples/jsm/objects/Sky.js +1 -1
  79. package/examples/jsm/objects/SkyMesh.js +1 -1
  80. package/examples/jsm/objects/Water.js +3 -3
  81. package/examples/jsm/objects/WaterMesh.js +6 -6
  82. package/examples/jsm/postprocessing/GlitchPass.js +2 -2
  83. package/examples/jsm/postprocessing/UnrealBloomPass.js +8 -6
  84. package/examples/jsm/renderers/CSS2DRenderer.js +16 -5
  85. package/examples/jsm/renderers/CSS3DRenderer.js +7 -6
  86. package/examples/jsm/renderers/SVGRenderer.js +1 -1
  87. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +1 -1
  88. package/examples/jsm/shaders/AfterimageShader.js +1 -1
  89. package/examples/jsm/shaders/BleachBypassShader.js +1 -1
  90. package/examples/jsm/shaders/BokehShader.js +1 -1
  91. package/examples/jsm/shaders/BokehShader2.js +1 -1
  92. package/examples/jsm/shaders/DotScreenShader.js +1 -1
  93. package/examples/jsm/shaders/FocusShader.js +1 -1
  94. package/examples/jsm/shaders/GTAOShader.js +2 -2
  95. package/examples/jsm/shaders/GodRaysShader.js +1 -1
  96. package/examples/jsm/shaders/KaleidoShader.js +1 -1
  97. package/examples/jsm/shaders/PoissonDenoiseShader.js +2 -2
  98. package/examples/jsm/shaders/SSRShader.js +1 -1
  99. package/examples/jsm/shaders/SepiaShader.js +1 -1
  100. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +1 -1
  101. package/examples/jsm/shaders/TriangleBlurShader.js +1 -1
  102. package/examples/jsm/shaders/VignetteShader.js +1 -1
  103. package/examples/jsm/transpiler/TSLEncoder.js +7 -0
  104. package/examples/jsm/tsl/display/AfterImageNode.js +26 -24
  105. package/examples/jsm/tsl/display/AnamorphicNode.js +2 -1
  106. package/examples/jsm/tsl/display/BloomNode.js +4 -0
  107. package/examples/jsm/tsl/display/DenoiseNode.js +2 -0
  108. package/examples/jsm/tsl/display/DepthOfFieldNode.js +7 -0
  109. package/examples/jsm/tsl/display/GTAONode.js +45 -5
  110. package/examples/jsm/tsl/display/GaussianBlurNode.js +5 -3
  111. package/examples/jsm/tsl/display/OutlineNode.js +11 -0
  112. package/examples/jsm/tsl/display/SSGINode.js +654 -0
  113. package/examples/jsm/tsl/display/SSRNode.js +2 -0
  114. package/examples/jsm/tsl/display/SSSNode.js +488 -0
  115. package/examples/jsm/tsl/display/TRAANode.js +123 -6
  116. package/examples/jsm/tsl/display/boxBlur.js +1 -0
  117. package/examples/jsm/tsl/display/hashBlur.js +1 -0
  118. package/examples/jsm/tsl/lighting/TiledLightsNode.js +21 -1
  119. package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
  120. package/examples/jsm/webxr/XRHandModelFactory.js +2 -6
  121. package/package.json +5 -10
  122. package/src/Three.Core.js +3 -2
  123. package/src/Three.TSL.js +7 -1
  124. package/src/Three.WebGPU.Nodes.js +2 -0
  125. package/src/Three.WebGPU.js +2 -0
  126. package/src/animation/AnimationClip.js +3 -2
  127. package/src/animation/AnimationMixer.js +3 -3
  128. package/src/animation/AnimationObjectGroup.js +2 -1
  129. package/src/animation/KeyframeTrack.js +7 -6
  130. package/src/animation/PropertyBinding.js +12 -11
  131. package/src/audio/Audio.js +10 -9
  132. package/src/audio/PositionalAudio.js +1 -1
  133. package/src/cameras/OrthographicCamera.js +1 -1
  134. package/src/cameras/PerspectiveCamera.js +1 -1
  135. package/src/cameras/StereoCamera.js +2 -2
  136. package/src/constants.js +1 -1
  137. package/src/core/BufferGeometry.js +8 -8
  138. package/src/core/EventDispatcher.js +1 -1
  139. package/src/core/InterleavedBuffer.js +1 -1
  140. package/src/core/InterleavedBufferAttribute.js +3 -2
  141. package/src/core/Object3D.js +3 -2
  142. package/src/core/Raycaster.js +2 -1
  143. package/src/core/RenderTarget.js +10 -1
  144. package/src/extras/Controls.js +5 -4
  145. package/src/extras/DataUtils.js +2 -1
  146. package/src/extras/Earcut.js +6 -0
  147. package/src/extras/ImageUtils.js +2 -2
  148. package/src/extras/PMREMGenerator.js +268 -55
  149. package/src/extras/core/Curve.js +2 -1
  150. package/src/extras/core/Interpolations.js +7 -1
  151. package/src/extras/core/ShapePath.js +4 -4
  152. package/src/extras/lib/earcut.js +7 -7
  153. package/src/geometries/BoxGeometry.js +1 -0
  154. package/src/geometries/CapsuleGeometry.js +1 -0
  155. package/src/geometries/CircleGeometry.js +1 -0
  156. package/src/geometries/ConeGeometry.js +1 -0
  157. package/src/geometries/CylinderGeometry.js +1 -0
  158. package/src/geometries/DodecahedronGeometry.js +1 -0
  159. package/src/geometries/ExtrudeGeometry.js +8 -6
  160. package/src/geometries/IcosahedronGeometry.js +1 -0
  161. package/src/geometries/LatheGeometry.js +1 -0
  162. package/src/geometries/OctahedronGeometry.js +1 -0
  163. package/src/geometries/PlaneGeometry.js +1 -0
  164. package/src/geometries/RingGeometry.js +1 -0
  165. package/src/geometries/ShapeGeometry.js +1 -0
  166. package/src/geometries/SphereGeometry.js +1 -0
  167. package/src/geometries/TetrahedronGeometry.js +1 -0
  168. package/src/geometries/TorusGeometry.js +1 -0
  169. package/src/geometries/TorusKnotGeometry.js +1 -0
  170. package/src/geometries/TubeGeometry.js +1 -0
  171. package/src/helpers/CameraHelper.js +1 -1
  172. package/src/loaders/AnimationLoader.js +2 -1
  173. package/src/loaders/AudioLoader.js +2 -1
  174. package/src/loaders/BufferGeometryLoader.js +2 -2
  175. package/src/loaders/Cache.js +2 -2
  176. package/src/loaders/DataTextureLoader.js +1 -1
  177. package/src/loaders/FileLoader.js +3 -2
  178. package/src/loaders/ImageBitmapLoader.js +5 -4
  179. package/src/loaders/ImageLoader.js +1 -1
  180. package/src/loaders/Loader.js +3 -3
  181. package/src/loaders/LoadingManager.js +25 -3
  182. package/src/loaders/MaterialLoader.js +3 -2
  183. package/src/loaders/ObjectLoader.js +13 -13
  184. package/src/loaders/TextureLoader.js +1 -1
  185. package/src/loaders/nodes/NodeLoader.js +3 -2
  186. package/src/materials/Material.js +4 -3
  187. package/src/materials/MeshBasicMaterial.js +1 -0
  188. package/src/materials/MeshDepthMaterial.js +1 -0
  189. package/src/materials/MeshLambertMaterial.js +2 -1
  190. package/src/materials/MeshMatcapMaterial.js +22 -0
  191. package/src/materials/MeshNormalMaterial.js +1 -0
  192. package/src/materials/MeshPhongMaterial.js +2 -1
  193. package/src/materials/MeshPhysicalMaterial.js +2 -1
  194. package/src/materials/MeshStandardMaterial.js +8 -7
  195. package/src/materials/MeshToonMaterial.js +1 -0
  196. package/src/materials/PointsMaterial.js +1 -1
  197. package/src/materials/ShaderMaterial.js +2 -2
  198. package/src/materials/nodes/Line2NodeMaterial.js +2 -2
  199. package/src/materials/nodes/MeshSSSNodeMaterial.js +1 -1
  200. package/src/materials/nodes/NodeMaterial.js +62 -22
  201. package/src/materials/nodes/manager/NodeMaterialObserver.js +2 -1
  202. package/src/math/Color.js +6 -5
  203. package/src/math/ColorManagement.js +2 -2
  204. package/src/math/Cylindrical.js +1 -1
  205. package/src/math/Euler.js +2 -1
  206. package/src/math/MathUtils.js +13 -11
  207. package/src/math/Matrix2.js +1 -1
  208. package/src/math/Matrix3.js +2 -2
  209. package/src/math/Matrix4.js +7 -7
  210. package/src/math/Plane.js +1 -1
  211. package/src/math/Quaternion.js +68 -66
  212. package/src/math/Spherical.js +1 -1
  213. package/src/nodes/Nodes.js +1 -1
  214. package/src/nodes/TSL.js +1 -1
  215. package/src/nodes/accessors/CubeTextureNode.js +3 -2
  216. package/src/nodes/accessors/InstanceNode.js +22 -4
  217. package/src/nodes/accessors/Lights.js +10 -0
  218. package/src/nodes/accessors/Normal.js +5 -4
  219. package/src/nodes/accessors/Position.js +18 -2
  220. package/src/nodes/accessors/ReferenceNode.js +2 -1
  221. package/src/nodes/accessors/SceneNode.js +2 -1
  222. package/src/nodes/accessors/StorageBufferNode.js +2 -1
  223. package/src/nodes/accessors/StorageTextureNode.js +22 -0
  224. package/src/nodes/accessors/Texture3DNode.js +1 -1
  225. package/src/nodes/accessors/TextureNode.js +61 -27
  226. package/src/nodes/code/FunctionCallNode.js +5 -4
  227. package/src/nodes/core/ArrayNode.js +1 -0
  228. package/src/nodes/core/AttributeNode.js +2 -1
  229. package/src/nodes/core/ContextNode.js +5 -10
  230. package/src/nodes/core/IndexNode.js +2 -2
  231. package/src/nodes/core/InputNode.js +2 -1
  232. package/src/nodes/core/InspectorNode.js +128 -0
  233. package/src/nodes/core/{CacheNode.js → IsolateNode.js} +40 -7
  234. package/src/nodes/core/Node.js +137 -12
  235. package/src/nodes/core/NodeBuilder.js +135 -21
  236. package/src/nodes/core/NodeFrame.js +20 -20
  237. package/src/nodes/core/NodeFunction.js +2 -1
  238. package/src/nodes/core/NodeParser.js +2 -1
  239. package/src/nodes/core/NodeUtils.js +17 -90
  240. package/src/nodes/core/ParameterNode.js +31 -0
  241. package/src/nodes/core/PropertyNode.js +7 -0
  242. package/src/nodes/core/StackNode.js +16 -14
  243. package/src/nodes/core/UniformNode.js +2 -1
  244. package/src/nodes/core/VarNode.js +70 -12
  245. package/src/nodes/core/VaryingNode.js +3 -2
  246. package/src/nodes/display/BlendModes.js +5 -4
  247. package/src/nodes/display/BumpMapNode.js +1 -1
  248. package/src/nodes/display/ColorAdjustment.js +1 -1
  249. package/src/nodes/display/NormalMapNode.js +2 -1
  250. package/src/nodes/display/PassNode.js +51 -10
  251. package/src/nodes/display/RenderOutputNode.js +28 -2
  252. package/src/nodes/display/ScreenNode.js +2 -1
  253. package/src/nodes/display/ToneMappingNode.js +31 -4
  254. package/src/nodes/display/ToonOutlinePassNode.js +8 -0
  255. package/src/nodes/fog/Fog.js +3 -2
  256. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
  257. package/src/nodes/functions/BSDF/DFGApprox.js +60 -19
  258. package/src/nodes/functions/BasicLightingModel.js +2 -1
  259. package/src/nodes/functions/PhysicalLightingModel.js +3 -2
  260. package/src/nodes/functions/VolumetricLightingModel.js +5 -5
  261. package/src/nodes/geometry/RangeNode.js +40 -4
  262. package/src/nodes/gpgpu/ComputeBuiltinNode.js +2 -1
  263. package/src/nodes/gpgpu/ComputeNode.js +17 -5
  264. package/src/nodes/gpgpu/SubgroupFunctionNode.js +25 -0
  265. package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -1
  266. package/src/nodes/lighting/EnvironmentNode.js +6 -6
  267. package/src/nodes/lighting/LightsNode.js +2 -3
  268. package/src/nodes/lighting/PointShadowNode.js +6 -0
  269. package/src/nodes/lighting/ShadowFilterNode.js +2 -0
  270. package/src/nodes/lighting/ShadowNode.js +75 -8
  271. package/src/nodes/math/ConditionalNode.js +6 -5
  272. package/src/nodes/math/MathNode.js +22 -4
  273. package/src/nodes/math/OperatorNode.js +3 -2
  274. package/src/nodes/pmrem/PMREMUtils.js +117 -2
  275. package/src/nodes/shapes/Shapes.js +1 -1
  276. package/src/nodes/tsl/TSLBase.js +5 -2
  277. package/src/nodes/tsl/TSLCore.js +36 -15
  278. package/src/nodes/utils/DebugNode.js +2 -1
  279. package/src/nodes/utils/EventNode.js +36 -0
  280. package/src/nodes/utils/FunctionOverloadingNode.js +37 -19
  281. package/src/nodes/utils/JoinNode.js +3 -2
  282. package/src/nodes/utils/LoopNode.js +20 -24
  283. package/src/nodes/utils/MemberNode.js +2 -1
  284. package/src/nodes/utils/PostProcessingUtils.js +28 -1
  285. package/src/nodes/utils/RTTNode.js +12 -2
  286. package/src/nodes/utils/ReflectorNode.js +10 -3
  287. package/src/objects/Line.js +2 -1
  288. package/src/objects/LineSegments.js +2 -1
  289. package/src/objects/Skeleton.js +3 -2
  290. package/src/objects/SkinnedMesh.js +3 -1
  291. package/src/objects/Sprite.js +2 -1
  292. package/src/renderers/WebGLRenderer.js +48 -32
  293. package/src/renderers/common/Animation.js +13 -1
  294. package/src/renderers/common/Backend.js +93 -30
  295. package/src/renderers/common/Background.js +2 -1
  296. package/src/renderers/common/Bindings.js +56 -2
  297. package/src/renderers/common/CanvasTarget.js +341 -0
  298. package/src/renderers/common/Geometries.js +26 -0
  299. package/src/renderers/common/Info.js +4 -2
  300. package/src/renderers/common/InspectorBase.js +146 -0
  301. package/src/renderers/common/PostProcessing.js +6 -25
  302. package/src/renderers/common/QuadMesh.js +7 -1
  303. package/src/renderers/common/RenderList.js +7 -3
  304. package/src/renderers/common/RenderObject.js +3 -1
  305. package/src/renderers/common/RenderObjects.js +1 -1
  306. package/src/renderers/common/Renderer.js +436 -228
  307. package/src/renderers/common/RendererUtils.js +9 -0
  308. package/src/renderers/common/SampledTexture.js +8 -0
  309. package/src/renderers/common/Sampler.js +37 -11
  310. package/src/renderers/common/StorageTexture.js +9 -1
  311. package/src/renderers/common/Textures.js +89 -35
  312. package/src/renderers/common/TimestampQueryPool.js +63 -1
  313. package/src/renderers/common/UniformsGroup.js +2 -1
  314. package/src/renderers/common/XRManager.js +7 -3
  315. package/src/renderers/common/extras/PMREMGenerator.js +160 -65
  316. package/src/renderers/common/nodes/NodeLibrary.js +4 -2
  317. package/src/renderers/common/nodes/NodeSampler.js +13 -1
  318. package/src/renderers/common/nodes/Nodes.js +38 -16
  319. package/src/renderers/shaders/DFGLUTData.js +64 -0
  320. package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -12
  321. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -1
  322. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +1 -1
  323. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +52 -18
  324. package/src/renderers/shaders/UniformsLib.js +1 -0
  325. package/src/renderers/shaders/UniformsUtils.js +25 -4
  326. package/src/renderers/webgl/WebGLCapabilities.js +2 -1
  327. package/src/renderers/webgl/WebGLExtensions.js +2 -25
  328. package/src/renderers/webgl/WebGLInfo.js +3 -1
  329. package/src/renderers/webgl/WebGLProgram.js +11 -10
  330. package/src/renderers/webgl/WebGLPrograms.js +2 -1
  331. package/src/renderers/webgl/WebGLShadowMap.js +2 -1
  332. package/src/renderers/webgl/WebGLState.js +15 -14
  333. package/src/renderers/webgl/WebGLTextures.js +18 -14
  334. package/src/renderers/webgl/WebGLUniformsGroups.js +5 -3
  335. package/src/renderers/webgl-fallback/WebGLBackend.js +22 -41
  336. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +74 -11
  337. package/src/renderers/webgl-fallback/utils/WebGLConstants.js +2 -3
  338. package/src/renderers/webgl-fallback/utils/WebGLState.js +6 -5
  339. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +117 -16
  340. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +42 -12
  341. package/src/renderers/webgpu/WebGPUBackend.js +134 -108
  342. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +2 -1
  343. package/src/renderers/webgpu/WebGPURenderer.js +3 -2
  344. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +21 -19
  345. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +2 -1
  346. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +5 -3
  347. package/src/renderers/webgpu/utils/WebGPUConstants.js +5 -0
  348. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +44 -16
  349. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +6 -8
  350. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +146 -74
  351. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +29 -6
  352. package/src/renderers/webgpu/utils/WebGPUUtils.js +22 -2
  353. package/src/renderers/webxr/WebXRManager.js +3 -2
  354. package/src/textures/Source.js +2 -1
  355. package/src/textures/Texture.js +3 -2
  356. package/src/textures/VideoTexture.js +2 -0
  357. package/src/utils.js +67 -3
@@ -2,7 +2,7 @@
2
2
  import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js';
3
3
  //*/
4
4
 
5
- import { GPUFeatureName, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
5
+ import { GPUFeatureName, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension, GPUFeatureMap } from './utils/WebGPUConstants.js';
6
6
 
7
7
  import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
8
8
  import Backend from '../common/Backend.js';
@@ -13,10 +13,9 @@ import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
13
13
  import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
14
14
  import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
15
15
 
16
- import { WebGPUCoordinateSystem, TimestampQuery } from '../../constants.js';
16
+ import { WebGPUCoordinateSystem, TimestampQuery, REVISION, HalfFloatType } from '../../constants.js';
17
17
  import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
18
- import { warnOnce } from '../../utils.js';
19
- import { ColorManagement } from '../../math/ColorManagement.js';
18
+ import { warnOnce, error } from '../../utils.js';
20
19
 
21
20
  /**
22
21
  * A backend implementation targeting WebGPU.
@@ -84,22 +83,6 @@ class WebGPUBackend extends Backend {
84
83
  */
85
84
  this.device = null;
86
85
 
87
- /**
88
- * A reference to the context.
89
- *
90
- * @type {?GPUCanvasContext}
91
- * @default null
92
- */
93
- this.context = null;
94
-
95
- /**
96
- * A reference to the color attachment of the default framebuffer.
97
- *
98
- * @type {?GPUTexture}
99
- * @default null
100
- */
101
- this.colorBuffer = null;
102
-
103
86
  /**
104
87
  * A reference to the default render pass descriptor.
105
88
  *
@@ -232,28 +215,63 @@ class WebGPUBackend extends Backend {
232
215
 
233
216
  } );
234
217
 
235
- const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' );
236
-
237
218
  this.device = device;
238
- this.context = context;
239
219
 
240
- const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
220
+ this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );
221
+
222
+ this.updateSize();
223
+
224
+ }
225
+
226
+ /**
227
+ * A reference to the context.
228
+ *
229
+ * @type {?GPUCanvasContext}
230
+ * @default null
231
+ */
232
+ get context() {
233
+
234
+ const canvasTarget = this.renderer.getCanvasTarget();
235
+ const canvasData = this.get( canvasTarget );
236
+
237
+ let context = canvasData.context;
238
+
239
+ if ( context === undefined ) {
240
+
241
+ const parameters = this.parameters;
242
+
243
+ if ( canvasTarget.isDefaultCanvasTarget === true && parameters.context !== undefined ) {
241
244
 
242
- const toneMappingMode = ColorManagement.getToneMappingMode( this.renderer.outputColorSpace );
245
+ context = parameters.context;
246
+
247
+ } else {
248
+
249
+ context = canvasTarget.domElement.getContext( 'webgpu' );
243
250
 
244
- this.context.configure( {
245
- device: this.device,
246
- format: this.utils.getPreferredCanvasFormat(),
247
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
248
- alphaMode: alphaMode,
249
- toneMapping: {
250
- mode: toneMappingMode
251
251
  }
252
- } );
253
252
 
254
- this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );
253
+ // OffscreenCanvas does not have setAttribute, see #22811
254
+ if ( 'setAttribute' in canvasTarget.domElement ) canvasTarget.domElement.setAttribute( 'data-engine', `three.js r${ REVISION } webgpu` );
255
255
 
256
- this.updateSize();
256
+ const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
257
+
258
+ const toneMappingMode = parameters.outputType === HalfFloatType ? 'extended' : 'standard';
259
+
260
+ context.configure( {
261
+ device: this.device,
262
+ format: this.utils.getPreferredCanvasFormat(),
263
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
264
+ alphaMode: alphaMode,
265
+ toneMapping: {
266
+ mode: toneMappingMode
267
+ }
268
+ } );
269
+
270
+ canvasData.context = context;
271
+
272
+ }
273
+
274
+ return context;
257
275
 
258
276
  }
259
277
 
@@ -306,19 +324,22 @@ class WebGPUBackend extends Backend {
306
324
  */
307
325
  _getDefaultRenderPassDescriptor() {
308
326
 
309
- let descriptor = this.defaultRenderPassdescriptor;
327
+ const renderer = this.renderer;
328
+ const canvasTarget = renderer.getCanvasTarget();
329
+ const canvasData = this.get( canvasTarget );
330
+ const samples = renderer.currentSamples;
310
331
 
311
- if ( descriptor === null ) {
332
+ let descriptor = canvasData.descriptor;
312
333
 
313
- const renderer = this.renderer;
334
+ if ( descriptor === undefined || canvasData.samples !== samples ) {
314
335
 
315
336
  descriptor = {
316
337
  colorAttachments: [ {
317
338
  view: null
318
- } ],
339
+ } ]
319
340
  };
320
341
 
321
- if ( this.renderer.depth === true || this.renderer.stencil === true ) {
342
+ if ( renderer.depth === true || renderer.stencil === true ) {
322
343
 
323
344
  descriptor.depthStencilAttachment = {
324
345
  view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
@@ -328,9 +349,9 @@ class WebGPUBackend extends Backend {
328
349
 
329
350
  const colorAttachment = descriptor.colorAttachments[ 0 ];
330
351
 
331
- if ( this.renderer.samples > 0 ) {
352
+ if ( samples > 0 ) {
332
353
 
333
- colorAttachment.view = this.colorBuffer.createView();
354
+ colorAttachment.view = this.textureUtils.getColorBuffer().createView();
334
355
 
335
356
  } else {
336
357
 
@@ -338,13 +359,14 @@ class WebGPUBackend extends Backend {
338
359
 
339
360
  }
340
361
 
341
- this.defaultRenderPassdescriptor = descriptor;
362
+ canvasData.descriptor = descriptor;
363
+ canvasData.samples = samples;
342
364
 
343
365
  }
344
366
 
345
367
  const colorAttachment = descriptor.colorAttachments[ 0 ];
346
368
 
347
- if ( this.renderer.samples > 0 ) {
369
+ if ( samples > 0 ) {
348
370
 
349
371
  colorAttachment.resolveTarget = this.context.getCurrentTexture().createView();
350
372
 
@@ -570,10 +592,6 @@ class WebGPUBackend extends Backend {
570
592
 
571
593
  //
572
594
 
573
- renderContextData.frameCalls = this.renderer.info.render.frameCalls;
574
-
575
- //
576
-
577
595
  const device = this.device;
578
596
  const occlusionQueryCount = renderContext.occlusionQueryCount;
579
597
 
@@ -759,8 +777,7 @@ class WebGPUBackend extends Backend {
759
777
 
760
778
  if ( renderContext.scissor ) {
761
779
 
762
- const { x, y, width, height } = renderContext.scissorValue;
763
- currentPass.setScissorRect( x, y, width, height );
780
+ this.updateScissor( renderContext );
764
781
 
765
782
  }
766
783
 
@@ -1120,6 +1137,20 @@ class WebGPUBackend extends Backend {
1120
1137
 
1121
1138
  }
1122
1139
 
1140
+ /**
1141
+ * Updates the scissor with the values from the given render context.
1142
+ *
1143
+ * @param {RenderContext} renderContext - The render context.
1144
+ */
1145
+ updateScissor( renderContext ) {
1146
+
1147
+ const { currentPass } = this.get( renderContext );
1148
+ const { x, y, width, height } = renderContext.scissorValue;
1149
+
1150
+ currentPass.setScissorRect( x, y, width, height );
1151
+
1152
+ }
1153
+
1123
1154
  /**
1124
1155
  * Returns the clear color and alpha into a single
1125
1156
  * color object.
@@ -1293,10 +1324,6 @@ class WebGPUBackend extends Backend {
1293
1324
 
1294
1325
  //
1295
1326
 
1296
- groupGPU.frameCalls = this.renderer.info.compute.frameCalls;
1297
-
1298
- //
1299
-
1300
1327
  const descriptor = {
1301
1328
  label: 'computeGroup_' + computeGroup.id
1302
1329
  };
@@ -1316,9 +1343,12 @@ class WebGPUBackend extends Backend {
1316
1343
  * @param {Node} computeNode - The compute node.
1317
1344
  * @param {Array<BindGroup>} bindings - The bindings.
1318
1345
  * @param {ComputePipeline} pipeline - The compute pipeline.
1319
- * @param {?(Array<number>|number)} [dispatchSizeOrCount=null] - Array with [ x, y, z ] values for dispatch or a single number for the count.
1346
+ * @param {number|Array<number>|IndirectStorageBufferAttribute} [dispatchSize=null]
1347
+ * - A single number representing count, or
1348
+ * - An array [x, y, z] representing dispatch size, or
1349
+ * - A IndirectStorageBufferAttribute for indirect dispatch size.
1320
1350
  */
1321
- compute( computeGroup, computeNode, bindings, pipeline, dispatchSizeOrCount = null ) {
1351
+ compute( computeGroup, computeNode, bindings, pipeline, dispatchSize = null ) {
1322
1352
 
1323
1353
  const computeNodeData = this.get( computeNode );
1324
1354
  const { passEncoderGPU } = this.get( computeGroup );
@@ -1340,19 +1370,29 @@ class WebGPUBackend extends Backend {
1340
1370
 
1341
1371
  }
1342
1372
 
1343
- let dispatchSize;
1373
+ if ( dispatchSize === null ) {
1374
+
1375
+ dispatchSize = computeNode.count;
1376
+
1377
+ }
1378
+
1379
+ // When the dispatchSize is set with a StorageBuffer from the GPU.
1344
1380
 
1345
- if ( dispatchSizeOrCount === null ) {
1381
+ if ( dispatchSize && typeof dispatchSize === 'object' && dispatchSize.isIndirectStorageBufferAttribute ) {
1346
1382
 
1347
- dispatchSizeOrCount = computeNode.count;
1383
+ const dispatchBuffer = this.get( dispatchSize ).buffer;
1384
+
1385
+ passEncoderGPU.dispatchWorkgroupsIndirect( dispatchBuffer, 0 );
1386
+
1387
+ return;
1348
1388
 
1349
1389
  }
1350
1390
 
1351
- if ( typeof dispatchSizeOrCount === 'number' ) {
1391
+ if ( typeof dispatchSize === 'number' ) {
1352
1392
 
1353
1393
  // If a single number is given, we calculate the dispatch size based on the workgroup size
1354
1394
 
1355
- const count = dispatchSizeOrCount;
1395
+ const count = dispatchSize;
1356
1396
 
1357
1397
  if ( computeNodeData.dispatchSize === undefined || computeNodeData.count !== count ) {
1358
1398
 
@@ -1389,10 +1429,6 @@ class WebGPUBackend extends Backend {
1389
1429
 
1390
1430
  dispatchSize = computeNodeData.dispatchSize;
1391
1431
 
1392
- } else {
1393
-
1394
- dispatchSize = dispatchSizeOrCount;
1395
-
1396
1432
  }
1397
1433
 
1398
1434
  //
@@ -1421,19 +1457,6 @@ class WebGPUBackend extends Backend {
1421
1457
 
1422
1458
  }
1423
1459
 
1424
- /**
1425
- * Can be used to synchronize CPU operations with GPU tasks. So when this method is called,
1426
- * the CPU waits for the GPU to complete its operation (e.g. a compute task).
1427
- *
1428
- * @async
1429
- * @return {Promise} A Promise that resolves when synchronization has been finished.
1430
- */
1431
- async waitForGPU() {
1432
-
1433
- await this.device.queue.onSubmittedWorkDone();
1434
-
1435
- }
1436
-
1437
1460
  // render object
1438
1461
 
1439
1462
  /**
@@ -1447,7 +1470,10 @@ class WebGPUBackend extends Backend {
1447
1470
  const { object, material, context, pipeline } = renderObject;
1448
1471
  const bindings = renderObject.getBindings();
1449
1472
  const renderContextData = this.get( context );
1450
- const pipelineGPU = this.get( pipeline ).pipeline;
1473
+ const pipelineData = this.get( pipeline );
1474
+ const pipelineGPU = pipelineData.pipeline;
1475
+
1476
+ if ( pipelineData.error === true ) return;
1451
1477
 
1452
1478
  const index = renderObject.getIndex();
1453
1479
  const hasIndex = ( index !== null );
@@ -1542,7 +1568,7 @@ class WebGPUBackend extends Backend {
1542
1568
  if ( drawInstances !== null ) {
1543
1569
 
1544
1570
  // @deprecated, r174
1545
- warnOnce( 'THREE.WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.' );
1571
+ warnOnce( 'WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.' );
1546
1572
 
1547
1573
  }
1548
1574
 
@@ -1834,24 +1860,14 @@ class WebGPUBackend extends Backend {
1834
1860
  // textures
1835
1861
 
1836
1862
  /**
1837
- * Creates a GPU sampler for the given texture.
1838
- *
1839
- * @param {Texture} texture - The texture to create the sampler for.
1840
- */
1841
- createSampler( texture ) {
1842
-
1843
- this.textureUtils.createSampler( texture );
1844
-
1845
- }
1846
-
1847
- /**
1848
- * Destroys the GPU sampler for the given texture.
1863
+ * Updates a GPU sampler for the given texture.
1849
1864
  *
1850
- * @param {Texture} texture - The texture to destroy the sampler for.
1865
+ * @param {Texture} texture - The texture to update the sampler for.
1866
+ * @return {string} The current sampler key.
1851
1867
  */
1852
- destroySampler( texture ) {
1868
+ updateSampler( texture ) {
1853
1869
 
1854
- this.textureUtils.destroySampler( texture );
1870
+ return this.textureUtils.updateSampler( texture );
1855
1871
 
1856
1872
  }
1857
1873
 
@@ -1860,10 +1876,11 @@ class WebGPUBackend extends Backend {
1860
1876
  * as a placeholder until the actual texture is ready for usage.
1861
1877
  *
1862
1878
  * @param {Texture} texture - The texture to create a default texture for.
1879
+ * @return {boolean} Whether the sampler has been updated or not.
1863
1880
  */
1864
1881
  createDefaultTexture( texture ) {
1865
1882
 
1866
- this.textureUtils.createDefaultTexture( texture );
1883
+ return this.textureUtils.createDefaultTexture( texture );
1867
1884
 
1868
1885
  }
1869
1886
 
@@ -1906,10 +1923,11 @@ class WebGPUBackend extends Backend {
1906
1923
  * Destroys the GPU data for the given texture object.
1907
1924
  *
1908
1925
  * @param {Texture} texture - The texture.
1926
+ * @param {boolean} [isDefaultTexture=false] - Whether the texture uses a default GPU texture or not.
1909
1927
  */
1910
- destroyTexture( texture ) {
1928
+ destroyTexture( texture, isDefaultTexture = false ) {
1911
1929
 
1912
- this.textureUtils.destroyTexture( texture );
1930
+ this.textureUtils.destroyTexture( texture, isDefaultTexture );
1913
1931
 
1914
1932
  }
1915
1933
 
@@ -1957,7 +1975,7 @@ class WebGPUBackend extends Backend {
1957
1975
  querySet: timestampQueryPool.querySet,
1958
1976
  beginningOfPassWriteIndex: baseOffset,
1959
1977
  endOfPassWriteIndex: baseOffset + 1,
1960
- };
1978
+ };
1961
1979
 
1962
1980
  }
1963
1981
 
@@ -2209,8 +2227,7 @@ class WebGPUBackend extends Backend {
2209
2227
  */
2210
2228
  updateSize() {
2211
2229
 
2212
- this.colorBuffer = this.textureUtils.getColorBuffer();
2213
- this.defaultRenderPassdescriptor = null;
2230
+ this.delete( this.renderer.getCanvasTarget() );
2214
2231
 
2215
2232
  }
2216
2233
 
@@ -2235,6 +2252,8 @@ class WebGPUBackend extends Backend {
2235
2252
  */
2236
2253
  hasFeature( name ) {
2237
2254
 
2255
+ if ( GPUFeatureMap[ name ] !== undefined ) name = GPUFeatureMap[ name ];
2256
+
2238
2257
  return this.device.features.has( name );
2239
2258
 
2240
2259
  }
@@ -2373,7 +2392,7 @@ class WebGPUBackend extends Backend {
2373
2392
 
2374
2393
  if ( sourceGPU.format !== destinationGPU.format ) {
2375
2394
 
2376
- console.error( 'WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.', sourceGPU.format, destinationGPU.format );
2395
+ error( 'WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.', sourceGPU.format, destinationGPU.format );
2377
2396
 
2378
2397
  return;
2379
2398
 
@@ -2407,6 +2426,15 @@ class WebGPUBackend extends Backend {
2407
2426
  ]
2408
2427
  );
2409
2428
 
2429
+ // mipmaps must be genereated with the same encoder otherwise the copied texture data
2430
+ // might be out-of-sync, see #31768
2431
+
2432
+ if ( texture.generateMipmaps ) {
2433
+
2434
+ this.textureUtils.generateMipmaps( texture, encoder );
2435
+
2436
+ }
2437
+
2410
2438
  if ( renderContextData.currentPass ) {
2411
2439
 
2412
2440
  const { descriptor } = renderContextData;
@@ -2431,9 +2459,7 @@ class WebGPUBackend extends Backend {
2431
2459
 
2432
2460
  if ( renderContext.scissor ) {
2433
2461
 
2434
- const { x, y, width, height } = renderContext.scissorValue;
2435
-
2436
- renderContextData.currentPass.setScissorRect( x, y, width, height );
2462
+ this.updateScissor( renderContext );
2437
2463
 
2438
2464
  }
2439
2465
 
@@ -2443,11 +2469,11 @@ class WebGPUBackend extends Backend {
2443
2469
 
2444
2470
  }
2445
2471
 
2446
- if ( texture.generateMipmaps ) {
2472
+ }
2447
2473
 
2448
- this.textureUtils.generateMipmaps( texture );
2474
+ dispose() {
2449
2475
 
2450
- }
2476
+ this.textureUtils.dispose();
2451
2477
 
2452
2478
  }
2453
2479
 
@@ -2,6 +2,7 @@ import Renderer from '../common/Renderer.js';
2
2
  import WebGLBackend from '../webgl-fallback/WebGLBackend.js';
3
3
  import WebGPUBackend from './WebGPUBackend.js';
4
4
  import BasicNodeLibrary from './nodes/BasicNodeLibrary.js';
5
+ import { warn } from '../../utils.js';
5
6
 
6
7
  /**
7
8
  * This alternative version of {@link WebGPURenderer} only supports node materials.
@@ -31,7 +32,7 @@ class WebGPURenderer extends Renderer {
31
32
 
32
33
  parameters.getFallback = () => {
33
34
 
34
- console.warn( 'THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend.' );
35
+ warn( 'WebGPURenderer: WebGPU is not available, running under WebGL2 backend.' );
35
36
 
36
37
  return new WebGLBackend( parameters );
37
38
 
@@ -2,13 +2,14 @@ import Renderer from '../common/Renderer.js';
2
2
  import WebGLBackend from '../webgl-fallback/WebGLBackend.js';
3
3
  import WebGPUBackend from './WebGPUBackend.js';
4
4
  import StandardNodeLibrary from './nodes/StandardNodeLibrary.js';
5
+ import { warn } from '../../utils.js';
5
6
  /*
6
7
  const debugHandler = {
7
8
 
8
9
  get: function ( target, name ) {
9
10
 
10
11
  // Add |update
11
- if ( /^(create|destroy)/.test( name ) ) console.log( 'WebGPUBackend.' + name );
12
+ if ( /^(create|destroy)/.test( name ) ) log( 'WebGPUBackend.' + name );
12
13
 
13
14
  return target[ name ];
14
15
 
@@ -62,7 +63,7 @@ class WebGPURenderer extends Renderer {
62
63
 
63
64
  parameters.getFallback = () => {
64
65
 
65
- console.warn( 'THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend.' );
66
+ warn( 'WebGPURenderer: WebGPU is not available, running under WebGL2 backend.' );
66
67
 
67
68
  return new WebGLBackend( parameters );
68
69
 
@@ -17,6 +17,7 @@ import VarNode from '../../../nodes/core/VarNode.js';
17
17
  import ExpressionNode from '../../../nodes/code/ExpressionNode.js';
18
18
 
19
19
  import { FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter } from '../../../constants.js';
20
+ import { warn, error } from '../../../utils.js';
20
21
 
21
22
  // GPUShaderStage is not defined in browsers not supporting WebGPU
22
23
  const GPUShaderStage = ( typeof self !== 'undefined' ) ? self.GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 };
@@ -321,7 +322,7 @@ class WGSLNodeBuilder extends NodeBuilder {
321
322
 
322
323
  code += `\t\tcoord.${ axis }`;
323
324
 
324
- console.warn( `WebGPURenderer: Unsupported texture wrap type "${ wrap }" for vertex shader.` );
325
+ warn( `WebGPURenderer: Unsupported texture wrap type "${ wrap }" for vertex shader.` );
325
326
 
326
327
  }
327
328
 
@@ -497,7 +498,7 @@ class WGSLNodeBuilder extends NodeBuilder {
497
498
 
498
499
  const coordSnippet = `${ vecType }<u32>( ${ wrapFunction }( ${ uvSnippet } ) * ${ vecType }<f32>( ${ textureDimension } ) )`;
499
500
 
500
- return this.generateTextureLoad( texture, textureProperty, coordSnippet, depthSnippet, null, levelSnippet );
501
+ return this.generateTextureLoad( texture, textureProperty, coordSnippet, levelSnippet, depthSnippet, null );
501
502
 
502
503
  }
503
504
 
@@ -507,14 +508,14 @@ class WGSLNodeBuilder extends NodeBuilder {
507
508
  * @param {Texture} texture - The texture.
508
509
  * @param {string} textureProperty - The name of the texture uniform in the shader.
509
510
  * @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
511
+ * @param {?string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
510
512
  * @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
511
513
  * @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
512
- * @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
513
514
  * @return {string} The WGSL snippet.
514
515
  */
515
- generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, offsetSnippet, levelSnippet = '0u' ) {
516
+ generateTextureLoad( texture, textureProperty, uvIndexSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
516
517
 
517
- let snippet;
518
+ if ( levelSnippet === null ) levelSnippet = '0u';
518
519
 
519
520
  if ( offsetSnippet ) {
520
521
 
@@ -522,6 +523,8 @@ class WGSLNodeBuilder extends NodeBuilder {
522
523
 
523
524
  }
524
525
 
526
+ let snippet;
527
+
525
528
  if ( depthSnippet ) {
526
529
 
527
530
  snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
@@ -653,7 +656,7 @@ class WGSLNodeBuilder extends NodeBuilder {
653
656
 
654
657
  } else {
655
658
 
656
- console.error( `WebGPURenderer: THREE.TextureNode.gradient() does not support ${ shaderStage } shader.` );
659
+ error( `WebGPURenderer: THREE.TextureNode.gradient() does not support ${ shaderStage } shader.` );
657
660
 
658
661
  }
659
662
 
@@ -698,7 +701,7 @@ class WGSLNodeBuilder extends NodeBuilder {
698
701
 
699
702
  } else {
700
703
 
701
- console.error( `WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${ shaderStage } shader.` );
704
+ error( `WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${ shaderStage } shader.` );
702
705
 
703
706
  }
704
707
 
@@ -766,7 +769,7 @@ class WGSLNodeBuilder extends NodeBuilder {
766
769
 
767
770
  } else {
768
771
 
769
- console.error( `WebGPURenderer: THREE.TextureNode.biasNode does not support ${ shaderStage } shader.` );
772
+ error( `WebGPURenderer: THREE.TextureNode.biasNode does not support ${ shaderStage } shader.` );
770
773
 
771
774
  }
772
775
 
@@ -866,7 +869,7 @@ class WGSLNodeBuilder extends NodeBuilder {
866
869
 
867
870
  if ( node.isAtomic === true ) {
868
871
 
869
- console.warn( 'WebGPURenderer: Atomic operations are only supported in compute shaders.' );
872
+ warn( 'WebGPURenderer: Atomic operations are only supported in compute shaders.' );
870
873
 
871
874
  return NodeAccess.READ_WRITE;
872
875
 
@@ -949,6 +952,7 @@ class WGSLNodeBuilder extends NodeBuilder {
949
952
  }
950
953
 
951
954
  texture.store = node.isStorageTextureNode === true;
955
+ texture.mipLevel = texture.store ? node.mipLevel : 0;
952
956
  texture.setVisibility( gpuShaderStageLib[ shaderStage ] );
953
957
 
954
958
  if ( this.isUnfilterable( node.value ) === false && texture.store === false ) {
@@ -1112,7 +1116,8 @@ ${ flowData.code }
1112
1116
  }
1113
1117
 
1114
1118
  /**
1115
- * Returns the instance index builtin.
1119
+ * Contextually returns either the vertex stage instance index builtin
1120
+ * or the linearized index of an compute invocation within a grid of workgroups.
1116
1121
  *
1117
1122
  * @return {string} The instance index.
1118
1123
  */
@@ -1128,8 +1133,9 @@ ${ flowData.code }
1128
1133
 
1129
1134
  }
1130
1135
 
1136
+
1131
1137
  /**
1132
- * Returns the invocation local index builtin.
1138
+ * Returns a builtin representing the index of a compute invocation within the scope of a workgroup load.
1133
1139
  *
1134
1140
  * @return {string} The invocation local index.
1135
1141
  */
@@ -1140,7 +1146,7 @@ ${ flowData.code }
1140
1146
  }
1141
1147
 
1142
1148
  /**
1143
- * Returns the subgroup size builtin.
1149
+ * Returns a builtin representing the size of a subgroup within the current shader.
1144
1150
  *
1145
1151
  * @return {string} The subgroup size.
1146
1152
  */
@@ -1153,7 +1159,7 @@ ${ flowData.code }
1153
1159
  }
1154
1160
 
1155
1161
  /**
1156
- * Returns the invocation subgroup index builtin.
1162
+ * Returns a builtin representing the index of a compute invocation within the scope of a subgroup.
1157
1163
  *
1158
1164
  * @return {string} The invocation subgroup index.
1159
1165
  */
@@ -1166,7 +1172,7 @@ ${ flowData.code }
1166
1172
  }
1167
1173
 
1168
1174
  /**
1169
- * Returns the subgroup index builtin.
1175
+ * Returns a builtin representing the index of a compute invocation's subgroup within its workgroup.
1170
1176
  *
1171
1177
  * @return {string} The subgroup index.
1172
1178
  */
@@ -2063,11 +2069,7 @@ ${ flowData.code }
2063
2069
  const codeNode = wgslPolyfill[ name ];
2064
2070
  codeNode.build( this );
2065
2071
 
2066
- if ( this.currentFunctionNode !== null ) {
2067
-
2068
- this.currentFunctionNode.includes.push( codeNode );
2069
-
2070
- }
2072
+ this.addInclude( codeNode );
2071
2073
 
2072
2074
  return codeNode;
2073
2075
 
@@ -1,6 +1,7 @@
1
1
  import { GPUInputStepMode } from './WebGPUConstants.js';
2
2
 
3
3
  import { Float16BufferAttribute } from '../../../core/BufferAttribute.js';
4
+ import { error } from '../../../utils.js';
4
5
 
5
6
  const typedArraysToVertexFormatPrefix = new Map( [
6
7
  [ Int8Array, [ 'sint8', 'snorm8' ]],
@@ -406,7 +407,7 @@ class WebGPUAttributeUtils {
406
407
 
407
408
  if ( ! format ) {
408
409
 
409
- console.error( 'THREE.WebGPUAttributeUtils: Vertex format not supported yet.' );
410
+ error( 'WebGPUAttributeUtils: Vertex format not supported yet.' );
410
411
 
411
412
  }
412
413