super-three 0.171.0 → 0.173.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 (455) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/build/three.cjs +594 -427
  4. package/build/three.core.js +515 -81
  5. package/build/three.core.min.js +2 -2
  6. package/build/three.module.js +79 -350
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +20 -7
  9. package/build/three.tsl.min.js +2 -2
  10. package/build/three.webgpu.js +29362 -3427
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +29361 -3427
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/jsm/Addons.js +0 -5
  15. package/examples/jsm/animation/CCDIKSolver.js +9 -7
  16. package/examples/jsm/capabilities/WebGPU.js +1 -1
  17. package/examples/jsm/controls/ArcballControls.js +48 -37
  18. package/examples/jsm/controls/OrbitControls.js +5 -4
  19. package/examples/jsm/csm/CSMShadowNode.js +16 -11
  20. package/examples/jsm/curves/NURBSCurve.js +1 -1
  21. package/examples/jsm/curves/NURBSUtils.js +3 -0
  22. package/examples/jsm/effects/OutlineEffect.js +1 -1
  23. package/examples/jsm/exporters/GLTFExporter.js +34 -29
  24. package/examples/jsm/exporters/KTX2Exporter.js +1 -1
  25. package/examples/jsm/exporters/PLYExporter.js +2 -2
  26. package/examples/jsm/geometries/TextGeometry.js +1 -12
  27. package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
  28. package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
  29. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  30. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  31. package/examples/jsm/lights/LightProbeGenerator.js +3 -3
  32. package/examples/jsm/lines/webgpu/LineSegments2.js +15 -6
  33. package/examples/jsm/loaders/3MFLoader.js +6 -3
  34. package/examples/jsm/loaders/BVHLoader.js +1 -1
  35. package/examples/jsm/loaders/ColladaLoader.js +5 -5
  36. package/examples/jsm/loaders/DDSLoader.js +42 -0
  37. package/examples/jsm/loaders/GCodeLoader.js +4 -2
  38. package/examples/jsm/loaders/GLTFLoader.js +22 -4
  39. package/examples/jsm/loaders/KTX2Loader.js +6 -1
  40. package/examples/jsm/loaders/KTXLoader.js +4 -4
  41. package/examples/jsm/loaders/LDrawLoader.js +1 -1
  42. package/examples/jsm/loaders/LottieLoader.js +1 -1
  43. package/examples/jsm/loaders/MTLLoader.js +1 -0
  44. package/examples/jsm/loaders/NRRDLoader.js +1 -1
  45. package/examples/jsm/loaders/PLYLoader.js +7 -7
  46. package/examples/jsm/loaders/PVRLoader.js +1 -1
  47. package/examples/jsm/loaders/SVGLoader.js +2 -2
  48. package/examples/jsm/loaders/TDSLoader.js +1 -2
  49. package/examples/jsm/loaders/VRMLLoader.js +7 -7
  50. package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
  51. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
  52. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  53. package/examples/jsm/math/ConvexHull.js +1 -1
  54. package/examples/jsm/math/OBB.js +17 -0
  55. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  56. package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
  57. package/examples/jsm/misc/ProgressiveLightMapGPU.js +14 -13
  58. package/examples/jsm/misc/Volume.js +27 -17
  59. package/examples/jsm/misc/VolumeSlice.js +7 -5
  60. package/examples/jsm/modifiers/CurveModifier.js +10 -8
  61. package/examples/jsm/modifiers/CurveModifierGPU.js +9 -7
  62. package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
  63. package/examples/jsm/objects/GroundedSkybox.js +4 -4
  64. package/examples/jsm/objects/Sky.js +2 -2
  65. package/examples/jsm/objects/SkyMesh.js +3 -3
  66. package/examples/jsm/objects/Water2.js +1 -1
  67. package/examples/jsm/objects/Water2Mesh.js +2 -2
  68. package/examples/jsm/objects/WaterMesh.js +29 -24
  69. package/examples/jsm/physics/JoltPhysics.js +7 -7
  70. package/examples/jsm/physics/RapierPhysics.js +4 -4
  71. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  72. package/examples/jsm/postprocessing/EffectComposer.js +1 -2
  73. package/examples/jsm/postprocessing/OutlinePass.js +4 -4
  74. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  75. package/examples/jsm/postprocessing/SAOPass.js +1 -2
  76. package/examples/jsm/postprocessing/SMAAPass.js +1 -3
  77. package/examples/jsm/postprocessing/SSAOPass.js +2 -4
  78. package/examples/jsm/postprocessing/SSRPass.js +2 -4
  79. package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
  80. package/examples/jsm/renderers/SVGRenderer.js +6 -4
  81. package/examples/jsm/shaders/BokehShader2.js +1 -1
  82. package/examples/jsm/shaders/GodRaysShader.js +3 -3
  83. package/examples/jsm/shaders/OutputShader.js +5 -1
  84. package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
  85. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  86. package/examples/jsm/transpiler/TSLEncoder.js +2 -0
  87. package/examples/jsm/tsl/display/AfterImageNode.js +93 -4
  88. package/examples/jsm/tsl/display/AnaglyphPassNode.js +46 -2
  89. package/examples/jsm/tsl/display/AnamorphicNode.js +118 -5
  90. package/examples/jsm/tsl/display/BleachBypass.js +10 -0
  91. package/examples/jsm/tsl/display/BloomNode.js +233 -26
  92. package/examples/jsm/tsl/display/DenoiseNode.js +141 -25
  93. package/examples/jsm/tsl/display/DepthOfFieldNode.js +80 -1
  94. package/examples/jsm/tsl/display/DotScreenNode.js +50 -5
  95. package/examples/jsm/tsl/display/FXAANode.js +52 -3
  96. package/examples/jsm/tsl/display/FilmNode.js +47 -1
  97. package/examples/jsm/tsl/display/GTAONode.js +210 -14
  98. package/examples/jsm/tsl/display/GaussianBlurNode.js +152 -8
  99. package/examples/jsm/tsl/display/LensflareNode.js +131 -13
  100. package/examples/jsm/tsl/display/Lut3DNode.js +55 -1
  101. package/examples/jsm/tsl/display/MotionBlur.js +12 -2
  102. package/examples/jsm/tsl/display/OutlineNode.js +343 -26
  103. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +36 -2
  104. package/examples/jsm/tsl/display/PixelationPassNode.js +142 -9
  105. package/examples/jsm/tsl/display/RGBShiftNode.js +49 -2
  106. package/examples/jsm/tsl/display/SMAANode.js +187 -46
  107. package/examples/jsm/tsl/display/SSAAPassNode.js +110 -25
  108. package/examples/jsm/tsl/display/SSRNode.js +194 -21
  109. package/examples/jsm/tsl/display/Sepia.js +9 -0
  110. package/examples/jsm/tsl/display/SobelOperatorNode.js +54 -4
  111. package/examples/jsm/tsl/display/StereoCompositePassNode.js +79 -3
  112. package/examples/jsm/tsl/display/StereoPassNode.js +41 -3
  113. package/examples/jsm/tsl/display/TRAAPassNode.js +116 -21
  114. package/examples/jsm/tsl/display/TransitionNode.js +71 -6
  115. package/examples/jsm/tsl/display/hashBlur.js +14 -3
  116. package/examples/jsm/tsl/lighting/TiledLightsNode.js +40 -34
  117. package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
  118. package/examples/jsm/utils/CameraUtils.js +4 -1
  119. package/examples/jsm/utils/GeometryUtils.js +22 -19
  120. package/examples/jsm/utils/SceneUtils.js +2 -2
  121. package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
  122. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  123. package/package.json +8 -3
  124. package/src/Three.Core.js +4 -0
  125. package/src/Three.Legacy.js +0 -21
  126. package/src/Three.TSL.js +18 -5
  127. package/src/Three.WebGPU.Nodes.js +2 -2
  128. package/src/Three.WebGPU.js +2 -2
  129. package/src/animation/PropertyBinding.js +2 -2
  130. package/src/cameras/ArrayCamera.js +1 -0
  131. package/src/cameras/PerspectiveCamera.js +18 -2
  132. package/src/constants.js +6 -1
  133. package/src/core/BufferAttribute.js +4 -0
  134. package/src/core/EventDispatcher.js +8 -6
  135. package/src/core/RenderTarget.js +18 -0
  136. package/src/core/RenderTarget3D.js +22 -0
  137. package/src/core/RenderTargetArray.js +22 -0
  138. package/src/extras/Earcut.js +1 -1
  139. package/src/extras/ImageUtils.js +1 -11
  140. package/src/extras/PMREMGenerator.js +20 -0
  141. package/src/extras/TextureUtils.js +6 -0
  142. package/src/helpers/CameraHelper.js +16 -13
  143. package/src/loaders/nodes/NodeLoader.js +59 -0
  144. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  145. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  146. package/src/materials/nodes/Line2NodeMaterial.js +128 -34
  147. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  148. package/src/materials/nodes/LineDashedNodeMaterial.js +78 -5
  149. package/src/materials/nodes/MeshBasicNodeMaterial.js +56 -0
  150. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  151. package/src/materials/nodes/MeshMatcapNodeMaterial.js +22 -2
  152. package/src/materials/nodes/MeshNormalNodeMaterial.js +21 -2
  153. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  154. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +269 -0
  155. package/src/materials/nodes/MeshSSSNodeMaterial.js +97 -6
  156. package/src/materials/nodes/MeshStandardNodeMaterial.js +78 -0
  157. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  158. package/src/materials/nodes/NodeMaterial.js +476 -23
  159. package/src/materials/nodes/NodeMaterials.js +0 -1
  160. package/src/materials/nodes/PointsNodeMaterial.js +121 -10
  161. package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
  162. package/src/materials/nodes/SpriteNodeMaterial.js +78 -20
  163. package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
  164. package/src/materials/nodes/manager/NodeMaterialObserver.js +95 -0
  165. package/src/nodes/Nodes.js +5 -6
  166. package/src/nodes/TSL.js +6 -3
  167. package/src/nodes/accessors/AccessorsUtils.js +27 -0
  168. package/src/nodes/accessors/Arrays.js +47 -6
  169. package/src/nodes/accessors/BatchNode.js +42 -6
  170. package/src/nodes/accessors/Bitangent.js +37 -0
  171. package/src/nodes/accessors/BufferAttributeNode.js +178 -5
  172. package/src/nodes/accessors/BufferNode.js +63 -0
  173. package/src/nodes/accessors/BuiltinNode.js +38 -0
  174. package/src/nodes/accessors/Camera.js +113 -3
  175. package/src/nodes/accessors/ClippingNode.js +71 -2
  176. package/src/nodes/accessors/CubeTextureNode.js +64 -0
  177. package/src/nodes/accessors/InstanceNode.js +85 -2
  178. package/src/nodes/accessors/InstancedMeshNode.js +28 -3
  179. package/src/nodes/accessors/Lights.js +50 -1
  180. package/src/nodes/accessors/MaterialNode.js +306 -12
  181. package/src/nodes/accessors/MaterialProperties.js +7 -0
  182. package/src/nodes/accessors/MaterialReferenceNode.js +53 -13
  183. package/src/nodes/accessors/ModelNode.js +100 -5
  184. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -38
  185. package/src/nodes/accessors/MorphNode.js +48 -4
  186. package/src/nodes/accessors/Normal.js +65 -5
  187. package/src/nodes/accessors/Object3DNode.js +101 -1
  188. package/src/nodes/accessors/PointUVNode.js +26 -0
  189. package/src/nodes/accessors/Position.js +56 -7
  190. package/src/nodes/accessors/ReferenceBaseNode.js +186 -0
  191. package/src/nodes/accessors/ReferenceNode.js +201 -2
  192. package/src/nodes/accessors/ReflectVector.js +24 -0
  193. package/src/nodes/accessors/RendererReferenceNode.js +46 -1
  194. package/src/nodes/accessors/SceneNode.js +54 -0
  195. package/src/nodes/accessors/SkinningNode.js +127 -1
  196. package/src/nodes/accessors/StorageBufferNode.js +209 -8
  197. package/src/nodes/accessors/StorageTextureNode.js +118 -0
  198. package/src/nodes/accessors/Tangent.js +38 -2
  199. package/src/nodes/accessors/Texture3DNode.js +91 -7
  200. package/src/nodes/accessors/TextureBicubic.js +12 -2
  201. package/src/nodes/accessors/TextureNode.js +316 -10
  202. package/src/nodes/accessors/TextureSizeNode.js +42 -0
  203. package/src/nodes/accessors/UV.js +10 -1
  204. package/src/nodes/accessors/UniformArrayNode.js +231 -25
  205. package/src/nodes/accessors/UserDataNode.js +46 -0
  206. package/src/nodes/accessors/VelocityNode.js +80 -0
  207. package/src/nodes/accessors/VertexColorNode.js +39 -2
  208. package/src/nodes/code/CodeNode.js +95 -1
  209. package/src/nodes/code/ExpressionNode.js +28 -0
  210. package/src/nodes/code/FunctionCallNode.js +37 -0
  211. package/src/nodes/code/FunctionNode.js +45 -0
  212. package/src/nodes/code/ScriptableNode.js +223 -1
  213. package/src/nodes/code/ScriptableValueNode.js +85 -1
  214. package/src/nodes/core/ArrayNode.js +125 -0
  215. package/src/nodes/core/AssignNode.js +48 -2
  216. package/src/nodes/core/AttributeNode.js +43 -0
  217. package/src/nodes/core/BypassNode.js +47 -2
  218. package/src/nodes/core/CacheNode.js +53 -2
  219. package/src/nodes/core/ConstNode.js +32 -0
  220. package/src/nodes/core/ContextNode.js +65 -0
  221. package/src/nodes/core/IndexNode.js +68 -7
  222. package/src/nodes/core/InputNode.js +48 -0
  223. package/src/nodes/core/LightingModel.js +60 -0
  224. package/src/nodes/core/MRTNode.js +66 -0
  225. package/src/nodes/core/Node.js +350 -12
  226. package/src/nodes/core/NodeAttribute.js +38 -0
  227. package/src/nodes/core/NodeBuilder.js +1166 -26
  228. package/src/nodes/core/NodeCache.js +41 -2
  229. package/src/nodes/core/NodeCode.js +31 -0
  230. package/src/nodes/core/NodeFrame.js +123 -2
  231. package/src/nodes/core/NodeFunction.js +46 -0
  232. package/src/nodes/core/NodeFunctionInput.js +44 -0
  233. package/src/nodes/core/NodeParser.js +11 -0
  234. package/src/nodes/core/NodeUniform.js +52 -0
  235. package/src/nodes/core/NodeUtils.js +152 -1
  236. package/src/nodes/core/NodeVar.js +47 -1
  237. package/src/nodes/core/NodeVarying.js +28 -0
  238. package/src/nodes/core/OutputStructNode.js +51 -10
  239. package/src/nodes/core/ParameterNode.js +28 -0
  240. package/src/nodes/core/PropertyNode.js +232 -0
  241. package/src/nodes/core/StackNode.js +98 -1
  242. package/src/nodes/core/StructNode.js +121 -0
  243. package/src/nodes/core/StructType.js +13 -0
  244. package/src/nodes/core/StructTypeNode.js +105 -6
  245. package/src/nodes/core/TempNode.js +31 -5
  246. package/src/nodes/core/UniformGroupNode.js +82 -7
  247. package/src/nodes/core/UniformNode.js +66 -0
  248. package/src/nodes/core/VarNode.js +146 -7
  249. package/src/nodes/core/VaryingNode.js +100 -3
  250. package/src/nodes/core/constants.js +36 -0
  251. package/src/nodes/display/BlendModes.js +88 -1
  252. package/src/nodes/display/BumpMapNode.js +37 -0
  253. package/src/nodes/display/ColorAdjustment.js +53 -11
  254. package/src/nodes/display/ColorSpaceFunctions.js +16 -0
  255. package/src/nodes/display/ColorSpaceNode.js +82 -0
  256. package/src/nodes/display/FrontFacingNode.js +29 -0
  257. package/src/nodes/display/NormalMapNode.js +43 -0
  258. package/src/nodes/display/PassNode.js +300 -7
  259. package/src/nodes/display/PosterizeNode.js +33 -0
  260. package/src/nodes/display/RenderOutputNode.js +66 -1
  261. package/src/nodes/display/ScreenNode.js +96 -0
  262. package/src/nodes/display/ToneMappingFunctions.js +58 -10
  263. package/src/nodes/display/ToneMappingNode.js +55 -2
  264. package/src/nodes/display/ToonOutlinePassNode.js +73 -0
  265. package/src/nodes/display/ViewportDepthNode.js +122 -8
  266. package/src/nodes/display/ViewportDepthTextureNode.js +23 -0
  267. package/src/nodes/display/ViewportSharedTextureNode.js +23 -0
  268. package/src/nodes/display/ViewportTextureNode.js +57 -0
  269. package/src/nodes/fog/Fog.js +110 -0
  270. package/src/nodes/functions/BasicLightingModel.js +24 -0
  271. package/src/nodes/functions/PhongLightingModel.js +34 -2
  272. package/src/nodes/functions/PhysicalLightingModel.js +167 -8
  273. package/src/nodes/functions/ShadowMaskModel.js +23 -0
  274. package/src/nodes/functions/ToonLightingModel.js +20 -0
  275. package/src/nodes/functions/material/getAlphaHashThreshold.js +1 -3
  276. package/src/nodes/functions/material/getParallaxCorrectNormal.js +16 -1
  277. package/src/nodes/geometry/RangeNode.js +54 -2
  278. package/src/nodes/gpgpu/AtomicFunctionNode.js +174 -2
  279. package/src/nodes/gpgpu/BarrierNode.js +47 -0
  280. package/src/nodes/gpgpu/ComputeBuiltinNode.js +134 -0
  281. package/src/nodes/gpgpu/ComputeNode.js +106 -2
  282. package/src/nodes/gpgpu/WorkgroupInfoNode.js +115 -6
  283. package/src/nodes/lighting/AONode.js +18 -0
  284. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  285. package/src/nodes/lighting/AnalyticLightNode.js +97 -2
  286. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  287. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  288. package/src/nodes/lighting/DirectionalLightNode.js +10 -0
  289. package/src/nodes/lighting/EnvironmentNode.js +18 -0
  290. package/src/nodes/lighting/HemisphereLightNode.js +31 -0
  291. package/src/nodes/lighting/IESSpotLightNode.js +11 -0
  292. package/src/nodes/lighting/IrradianceNode.js +17 -0
  293. package/src/nodes/lighting/LightProbeNode.js +20 -0
  294. package/src/nodes/lighting/LightUtils.js +12 -0
  295. package/src/nodes/lighting/LightingContextNode.js +48 -0
  296. package/src/nodes/lighting/LightingNode.js +15 -6
  297. package/src/nodes/lighting/LightsNode.js +132 -1
  298. package/src/nodes/lighting/PointLightNode.js +32 -1
  299. package/src/nodes/lighting/PointShadowNode.js +54 -1
  300. package/src/nodes/lighting/RectAreaLightNode.js +44 -6
  301. package/src/nodes/lighting/ShadowBaseNode.js +93 -0
  302. package/src/nodes/lighting/ShadowNode.js +241 -35
  303. package/src/nodes/lighting/SpotLightNode.js +43 -0
  304. package/src/nodes/math/ConditionalNode.js +78 -4
  305. package/src/nodes/math/Hash.js +9 -0
  306. package/src/nodes/math/MathNode.js +627 -11
  307. package/src/nodes/math/MathUtils.js +45 -1
  308. package/src/nodes/math/OperatorNode.js +329 -18
  309. package/src/nodes/math/TriNoise3D.js +18 -7
  310. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  311. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  312. package/src/nodes/pmrem/PMREMNode.js +133 -0
  313. package/src/nodes/pmrem/PMREMUtils.js +2 -2
  314. package/src/nodes/procedural/Checker.js +9 -0
  315. package/src/nodes/shapes/Shapes.js +33 -0
  316. package/src/nodes/tsl/TSLBase.js +3 -2
  317. package/src/nodes/tsl/TSLCore.js +22 -2
  318. package/src/nodes/utils/ArrayElementNode.js +39 -3
  319. package/src/nodes/utils/ConvertNode.js +31 -0
  320. package/src/nodes/utils/CubeMapNode.js +78 -0
  321. package/src/nodes/utils/Discard.js +16 -0
  322. package/src/nodes/utils/EquirectUVNode.js +31 -1
  323. package/src/nodes/utils/FlipNode.js +38 -0
  324. package/src/nodes/utils/FunctionOverloadingNode.js +53 -1
  325. package/src/nodes/utils/JoinNode.js +25 -0
  326. package/src/nodes/utils/LoopNode.js +82 -2
  327. package/src/nodes/utils/MatcapUVNode.js +17 -0
  328. package/src/nodes/utils/MaxMipLevelNode.js +49 -0
  329. package/src/nodes/utils/MemberNode.js +68 -0
  330. package/src/nodes/utils/Oscillators.js +33 -0
  331. package/src/nodes/utils/Packing.js +17 -0
  332. package/src/nodes/utils/PostProcessingUtils.js +28 -23
  333. package/src/nodes/utils/RTTNode.js +123 -2
  334. package/src/nodes/utils/ReflectorNode.js +174 -4
  335. package/src/nodes/utils/RemapNode.js +79 -0
  336. package/src/nodes/utils/RotateNode.js +41 -0
  337. package/src/nodes/utils/SetNode.js +44 -1
  338. package/src/nodes/utils/SplitNode.js +55 -3
  339. package/src/nodes/utils/SpriteSheetUVNode.js +46 -0
  340. package/src/nodes/utils/SpriteUtils.js +17 -0
  341. package/src/nodes/utils/StorageArrayElementNode.js +54 -0
  342. package/src/nodes/utils/Timer.js +40 -0
  343. package/src/nodes/utils/TriplanarTexturesNode.js +84 -0
  344. package/src/nodes/utils/UVUtils.js +20 -0
  345. package/src/nodes/utils/ViewportUtils.js +13 -0
  346. package/src/objects/BatchedMesh.js +2 -3
  347. package/src/objects/ClippingGroup.js +49 -0
  348. package/src/objects/Line.js +6 -6
  349. package/src/renderers/WebGLRenderer.js +30 -4
  350. package/src/renderers/common/Animation.js +85 -0
  351. package/src/renderers/common/Attributes.js +36 -0
  352. package/src/renderers/common/Backend.js +502 -44
  353. package/src/renderers/common/Background.js +48 -1
  354. package/src/renderers/common/BindGroup.js +43 -0
  355. package/src/renderers/common/Binding.js +35 -0
  356. package/src/renderers/common/Bindings.js +93 -1
  357. package/src/renderers/common/Buffer.js +49 -0
  358. package/src/renderers/common/BufferUtils.js +27 -0
  359. package/src/renderers/common/BundleGroup.js +57 -0
  360. package/src/renderers/common/ChainMap.js +45 -6
  361. package/src/renderers/common/ClippingContext.js +108 -15
  362. package/src/renderers/common/Color4.js +40 -0
  363. package/src/renderers/common/ComputePipeline.js +24 -0
  364. package/src/renderers/common/CubeRenderTarget.js +13 -0
  365. package/src/renderers/common/DataMap.js +37 -1
  366. package/src/renderers/common/Geometries.js +91 -14
  367. package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
  368. package/src/renderers/common/Info.js +78 -35
  369. package/src/renderers/common/Lighting.js +34 -6
  370. package/src/renderers/common/Pipeline.js +22 -0
  371. package/src/renderers/common/Pipelines.js +148 -5
  372. package/src/renderers/common/PostProcessing.js +99 -11
  373. package/src/renderers/common/ProgrammableStage.js +60 -2
  374. package/src/renderers/common/QuadMesh.js +54 -5
  375. package/src/renderers/common/RenderBundle.js +14 -8
  376. package/src/renderers/common/RenderBundles.js +39 -10
  377. package/src/renderers/common/RenderContext.js +201 -2
  378. package/src/renderers/common/RenderContexts.js +59 -6
  379. package/src/renderers/common/RenderList.js +178 -0
  380. package/src/renderers/common/RenderLists.js +40 -3
  381. package/src/renderers/common/RenderObject.js +400 -17
  382. package/src/renderers/common/RenderObjects.js +103 -7
  383. package/src/renderers/common/RenderPipeline.js +24 -0
  384. package/src/renderers/common/Renderer.js +1170 -86
  385. package/src/renderers/common/RendererUtils.js +193 -0
  386. package/src/renderers/common/SampledTexture.js +120 -0
  387. package/src/renderers/common/Sampler.js +30 -0
  388. package/src/renderers/common/StorageBuffer.js +24 -0
  389. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  390. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  391. package/src/renderers/common/StorageTexture.js +38 -0
  392. package/src/renderers/common/Textures.js +97 -7
  393. package/src/renderers/common/TimestampQueryPool.js +39 -0
  394. package/src/renderers/common/Uniform.js +225 -3
  395. package/src/renderers/common/UniformBuffer.js +19 -0
  396. package/src/renderers/common/UniformsGroup.js +141 -2
  397. package/src/renderers/common/XRManager.js +1193 -0
  398. package/src/renderers/common/XRRenderTarget.js +74 -0
  399. package/src/renderers/common/extras/PMREMGenerator.js +76 -10
  400. package/src/renderers/common/nodes/NodeBuilderState.js +99 -5
  401. package/src/renderers/common/nodes/NodeLibrary.js +89 -0
  402. package/src/renderers/common/nodes/NodeSampledTexture.js +90 -2
  403. package/src/renderers/common/nodes/NodeSampler.js +28 -0
  404. package/src/renderers/common/nodes/NodeStorageBuffer.js +35 -0
  405. package/src/renderers/common/nodes/NodeUniform.js +243 -2
  406. package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
  407. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  408. package/src/renderers/common/nodes/Nodes.js +352 -78
  409. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  410. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  411. package/src/renderers/webgl/WebGLBackground.js +4 -0
  412. package/src/renderers/webgl-fallback/WebGLBackend.js +819 -116
  413. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -18
  414. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +58 -1
  415. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  416. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  417. package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
  418. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +168 -22
  419. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
  420. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  421. package/src/renderers/webgpu/WebGPUBackend.js +578 -164
  422. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +36 -0
  423. package/src/renderers/webgpu/WebGPURenderer.js +36 -0
  424. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +20 -8
  425. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +21 -8
  426. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +674 -52
  427. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +17 -0
  428. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  429. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +95 -14
  430. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +94 -1
  431. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
  432. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
  433. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +262 -18
  434. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
  435. package/src/renderers/webgpu/utils/WebGPUUtils.js +116 -4
  436. package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
  437. package/src/renderers/webxr/WebXRManager.js +19 -2
  438. package/src/textures/Data3DTexture.js +2 -2
  439. package/src/textures/Texture.js +4 -0
  440. package/src/textures/VideoFrameTexture.js +35 -0
  441. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1209
  442. package/examples/jsm/animation/MMDPhysics.js +0 -1408
  443. package/examples/jsm/exporters/MMDExporter.js +0 -223
  444. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
  445. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  446. package/examples/jsm/loaders/MMDLoader.js +0 -2298
  447. package/examples/jsm/objects/InstancedPoints.js +0 -19
  448. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  449. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
  450. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
  451. package/src/nodes/core/UniformGroup.js +0 -13
  452. package/src/nodes/fog/FogExp2Node.js +0 -35
  453. package/src/nodes/fog/FogNode.js +0 -50
  454. package/src/nodes/fog/FogRangeNode.js +0 -36
  455. package/src/renderers/common/PostProcessingUtils.js +0 -86
@@ -13,19 +13,196 @@ import { WebGLBufferRenderer } from './WebGLBufferRenderer.js';
13
13
 
14
14
  import { warnOnce } from '../../utils.js';
15
15
  import { WebGLCoordinateSystem } from '../../constants.js';
16
-
17
- //
18
-
16
+ import WebGLTimestampQueryPool from './utils/WebGLTimestampQueryPool.js';
17
+
18
+ /**
19
+ * A backend implementation targeting WebGL 2.
20
+ *
21
+ * @private
22
+ * @augments Backend
23
+ */
19
24
  class WebGLBackend extends Backend {
20
25
 
26
+ /**
27
+ * Constructs a new WebGPU backend.
28
+ *
29
+ * @param {Object} parameters - The configuration parameter.
30
+ * @param {Boolean} [parameters.logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
31
+ * @param {Boolean} [parameters.alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
32
+ * @param {Boolean} [parameters.depth=true] - Whether the default framebuffer should have a depth buffer or not.
33
+ * @param {Boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
34
+ * @param {Boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
35
+ * @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default.
36
+ * @param {Boolean} [parameters.forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
37
+ * @param {WebGL2RenderingContext} [parameters.context=undefined] - A WebGL 2 rendering context.
38
+ */
21
39
  constructor( parameters = {} ) {
22
40
 
23
41
  super( parameters );
24
42
 
43
+ /**
44
+ * This flag can be used for type testing.
45
+ *
46
+ * @type {Boolean}
47
+ * @readonly
48
+ * @default true
49
+ */
25
50
  this.isWebGLBackend = true;
26
51
 
52
+ /**
53
+ * A reference to a backend module holding shader attribute-related
54
+ * utility functions.
55
+ *
56
+ * @type {WebGLAttributeUtils?}
57
+ * @default null
58
+ */
59
+ this.attributeUtils = null;
60
+
61
+ /**
62
+ * A reference to a backend module holding extension-related
63
+ * utility functions.
64
+ *
65
+ * @type {WebGLExtensions?}
66
+ * @default null
67
+ */
68
+ this.extensions = null;
69
+
70
+ /**
71
+ * A reference to a backend module holding capability-related
72
+ * utility functions.
73
+ *
74
+ * @type {WebGLCapabilities?}
75
+ * @default null
76
+ */
77
+ this.capabilities = null;
78
+
79
+ /**
80
+ * A reference to a backend module holding texture-related
81
+ * utility functions.
82
+ *
83
+ * @type {WebGLTextureUtils?}
84
+ * @default null
85
+ */
86
+ this.textureUtils = null;
87
+
88
+ /**
89
+ * A reference to a backend module holding renderer-related
90
+ * utility functions.
91
+ *
92
+ * @type {WebGLBufferRenderer?}
93
+ * @default null
94
+ */
95
+ this.bufferRenderer = null;
96
+
97
+ /**
98
+ * A reference to the rendering context.
99
+ *
100
+ * @type {WebGL2RenderingContext?}
101
+ * @default null
102
+ */
103
+ this.gl = null;
104
+
105
+ /**
106
+ * A reference to a backend module holding state-related
107
+ * utility functions.
108
+ *
109
+ * @type {WebGLState?}
110
+ * @default null
111
+ */
112
+ this.state = null;
113
+
114
+ /**
115
+ * A reference to a backend module holding common
116
+ * utility functions.
117
+ *
118
+ * @type {WebGLUtils?}
119
+ * @default null
120
+ */
121
+ this.utils = null;
122
+
123
+ /**
124
+ * Dictionary for caching VAOs.
125
+ *
126
+ * @type {Object<String,WebGLVertexArrayObject>}
127
+ */
128
+ this.vaoCache = {};
129
+
130
+ /**
131
+ * Dictionary for caching transform feedback objects.
132
+ *
133
+ * @type {Object<String,WebGLTransformFeedback>}
134
+ */
135
+ this.transformFeedbackCache = {};
136
+
137
+ /**
138
+ * Controls if `gl.RASTERIZER_DISCARD` should be enabled or not.
139
+ * Only relevant when using compute shaders.
140
+ *
141
+ * @type {Boolean}
142
+ * @default false
143
+ */
144
+ this.discard = false;
145
+
146
+ /**
147
+ * A reference to the `EXT_disjoint_timer_query_webgl2` extension. `null` if the
148
+ * device does not support the extension.
149
+ *
150
+ * @type {EXTDisjointTimerQueryWebGL2?}
151
+ * @default null
152
+ */
153
+ this.disjoint = null;
154
+
155
+ /**
156
+ * A reference to the `KHR_parallel_shader_compile` extension. `null` if the
157
+ * device does not support the extension.
158
+ *
159
+ * @type {KHRParallelShaderCompile?}
160
+ * @default null
161
+ */
162
+ this.parallel = null;
163
+
164
+ /**
165
+ * Whether to track timestamps with a Timestamp Query API or not.
166
+ *
167
+ * @type {Boolean}
168
+ * @default false
169
+ */
170
+ this.trackTimestamp = ( parameters.trackTimestamp === true );
171
+
172
+ /**
173
+ * A reference to the current render context.
174
+ *
175
+ * @private
176
+ * @type {RenderContext}
177
+ * @default null
178
+ */
179
+ this._currentContext = null;
180
+
181
+ /**
182
+ * A unique collection of bindings.
183
+ *
184
+ * @private
185
+ * @type {WeakSet}
186
+ */
187
+ this._knownBindings = new WeakSet();
188
+
189
+ /**
190
+ * The target framebuffer when rendering with
191
+ * the WebXR device API.
192
+ *
193
+ * @private
194
+ * @type {WebGLFramebuffer}
195
+ * @default null
196
+ */
197
+ this._xrFamebuffer = null;
198
+
27
199
  }
28
200
 
201
+ /**
202
+ * Initializes the backend so it is ready for usage.
203
+ *
204
+ * @param {Renderer} renderer - The renderer.
205
+ */
29
206
  init( renderer ) {
30
207
 
31
208
  super.init( renderer );
@@ -34,7 +211,14 @@ class WebGLBackend extends Backend {
34
211
 
35
212
  const parameters = this.parameters;
36
213
 
37
- const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2' );
214
+ const contextAttributes = {
215
+ antialias: false, // MSAA is applied via a custom renderbuffer
216
+ alpha: true, // always true for performance reasons
217
+ depth: false, // depth and stencil are set to false since the engine always renders into a framebuffer target first
218
+ stencil: false
219
+ };
220
+
221
+ const glContext = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgl2', contextAttributes );
38
222
 
39
223
  function onContextLost( event ) {
40
224
 
@@ -66,11 +250,6 @@ class WebGLBackend extends Backend {
66
250
  this.state = new WebGLState( this );
67
251
  this.utils = new WebGLUtils( this );
68
252
 
69
- this.vaoCache = {};
70
- this.transformFeedbackCache = {};
71
- this.discard = false;
72
- this.trackTimestamp = ( parameters.trackTimestamp === true );
73
-
74
253
  this.extensions.get( 'EXT_color_buffer_float' );
75
254
  this.extensions.get( 'WEBGL_clip_cull_distance' );
76
255
  this.extensions.get( 'OES_texture_float_linear' );
@@ -82,83 +261,103 @@ class WebGLBackend extends Backend {
82
261
  this.disjoint = this.extensions.get( 'EXT_disjoint_timer_query_webgl2' );
83
262
  this.parallel = this.extensions.get( 'KHR_parallel_shader_compile' );
84
263
 
85
- this._knownBindings = new WeakSet();
86
-
87
- this._currentContext = null;
88
-
89
264
  }
90
265
 
266
+ /**
267
+ * The coordinate system of the backend.
268
+ *
269
+ * @type {Number}
270
+ * @readonly
271
+ */
91
272
  get coordinateSystem() {
92
273
 
93
274
  return WebGLCoordinateSystem;
94
275
 
95
276
  }
96
277
 
278
+ /**
279
+ * This method performs a readback operation by moving buffer data from
280
+ * a storage buffer attribute from the GPU to the CPU.
281
+ *
282
+ * @async
283
+ * @param {StorageBufferAttribute} attribute - The storage buffer attribute.
284
+ * @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
285
+ */
97
286
  async getArrayBufferAsync( attribute ) {
98
287
 
99
288
  return await this.attributeUtils.getArrayBufferAsync( attribute );
100
289
 
101
290
  }
102
291
 
292
+ /**
293
+ * Can be used to synchronize CPU operations with GPU tasks. So when this method is called,
294
+ * the CPU waits for the GPU to complete its operation (e.g. a compute task).
295
+ *
296
+ * @async
297
+ * @return {Promise} A Promise that resolves when synchronization has been finished.
298
+ */
103
299
  async waitForGPU() {
104
300
 
105
301
  await this.utils._clientWaitAsync();
106
302
 
107
303
  }
108
304
 
109
- initTimestampQuery( renderContext ) {
110
-
111
- if ( ! this.disjoint || ! this.trackTimestamp ) return;
305
+ /**
306
+ * Ensures the backend is XR compatible.
307
+ *
308
+ * @async
309
+ * @return {Promise} A Promise that resolve when the renderer is XR compatible.
310
+ */
311
+ async makeXRCompatible() {
112
312
 
113
- const renderContextData = this.get( renderContext );
114
-
115
- if ( this.queryRunning ) {
116
-
117
- if ( ! renderContextData.queryQueue ) renderContextData.queryQueue = [];
118
- renderContextData.queryQueue.push( renderContext );
119
- return;
120
-
121
- }
313
+ const attributes = this.gl.getContextAttributes();
122
314
 
123
- if ( renderContextData.activeQuery ) {
315
+ if ( attributes.xrCompatible !== true ) {
124
316
 
125
- this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT );
126
- renderContextData.activeQuery = null;
317
+ await this.gl.makeXRCompatible();
127
318
 
128
319
  }
129
320
 
130
- renderContextData.activeQuery = this.gl.createQuery();
131
-
132
- if ( renderContextData.activeQuery !== null ) {
133
-
134
- this.gl.beginQuery( this.disjoint.TIME_ELAPSED_EXT, renderContextData.activeQuery );
135
- this.queryRunning = true;
321
+ }
322
+ /**
323
+ * Sets the XR rendering destination.
324
+ *
325
+ * @param {WebGLFramebuffer} xrFamebuffer - The XR framebuffer.
326
+ */
327
+ setXRTarget( xrFamebuffer ) {
136
328
 
137
- }
329
+ this._xrFamebuffer = xrFamebuffer;
138
330
 
139
331
  }
140
332
 
141
- // timestamp utils
333
+ /**
334
+ * Configures the given XR render target with external textures.
335
+ *
336
+ * This method is only relevant when using the WebXR Layers API.
337
+ *
338
+ * @param {XRRenderTarget} renderTarget - The XR render target.
339
+ * @param {WebGLTexture} colorTexture - A native color texture.
340
+ * @param {WebGLTexture?} [depthTexture=null] - A native depth texture.
341
+ */
342
+ setXRRenderTargetTextures( renderTarget, colorTexture, depthTexture = null ) {
142
343
 
143
- prepareTimestampBuffer( renderContext ) {
344
+ const gl = this.gl;
144
345
 
145
- if ( ! this.disjoint || ! this.trackTimestamp ) return;
346
+ this.set( renderTarget.texture, { textureGPU: colorTexture, glInternalFormat: gl.RGBA8 } ); // see #24698 why RGBA8 and not SRGB8_ALPHA8 is used
146
347
 
147
- const renderContextData = this.get( renderContext );
348
+ if ( depthTexture !== null ) {
148
349
 
149
- if ( renderContextData.activeQuery ) {
350
+ const glInternalFormat = renderTarget.stencilBuffer ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24;
150
351
 
151
- this.gl.endQuery( this.disjoint.TIME_ELAPSED_EXT );
352
+ this.set( renderTarget.depthTexture, { textureGPU: depthTexture, glInternalFormat: glInternalFormat } );
152
353
 
153
- if ( ! renderContextData.gpuQueries ) renderContextData.gpuQueries = [];
154
- renderContextData.gpuQueries.push( { query: renderContextData.activeQuery } );
155
- renderContextData.activeQuery = null;
156
- this.queryRunning = false;
354
+ renderTarget.autoAllocateDepthBuffer = false;
157
355
 
158
- if ( renderContextData.queryQueue && renderContextData.queryQueue.length > 0 ) {
356
+ // The multisample_render_to_texture extension doesn't work properly if there
357
+ // are midframe flushes and an external depth texture.
358
+ if ( this.extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) {
159
359
 
160
- const nextRenderContext = renderContextData.queryQueue.shift();
161
- this.initTimestampQuery( nextRenderContext );
360
+ console.warn( 'THREE.WebGLBackend: Render-to-texture extension was disabled because an external texture was provided' );
162
361
 
163
362
  }
164
363
 
@@ -166,44 +365,75 @@ class WebGLBackend extends Backend {
166
365
 
167
366
  }
168
367
 
169
- async resolveTimestampAsync( renderContext, type = 'render' ) {
368
+ /**
369
+ * Inits a time stamp query for the given render context.
370
+ *
371
+ * @param {RenderContext} renderContext - The render context.
372
+ */
373
+ initTimestampQuery( renderContext ) {
170
374
 
171
375
  if ( ! this.disjoint || ! this.trackTimestamp ) return;
172
376
 
173
- const renderContextData = this.get( renderContext );
377
+ const type = renderContext.isComputeNode ? 'compute' : 'render';
174
378
 
175
- if ( ! renderContextData.gpuQueries ) renderContextData.gpuQueries = [];
379
+ if ( ! this.timestampQueryPool[ type ] ) {
176
380
 
177
- for ( let i = 0; i < renderContextData.gpuQueries.length; i ++ ) {
381
+ // TODO: Variable maxQueries?
382
+ this.timestampQueryPool[ type ] = new WebGLTimestampQueryPool( this.gl, type, 2048 );
178
383
 
179
- const queryInfo = renderContextData.gpuQueries[ i ];
180
- const available = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT_AVAILABLE );
181
- const disjoint = this.gl.getParameter( this.disjoint.GPU_DISJOINT_EXT );
384
+ }
182
385
 
183
- if ( available && ! disjoint ) {
386
+ const timestampQueryPool = this.timestampQueryPool[ type ];
184
387
 
185
- const elapsed = this.gl.getQueryParameter( queryInfo.query, this.gl.QUERY_RESULT );
186
- const duration = Number( elapsed ) / 1000000; // Convert nanoseconds to milliseconds
187
- this.gl.deleteQuery( queryInfo.query );
188
- renderContextData.gpuQueries.splice( i, 1 ); // Remove the processed query
189
- i --;
190
- this.renderer.info.updateTimestamp( type, duration );
388
+ const baseOffset = timestampQueryPool.allocateQueriesForContext( renderContext );
191
389
 
192
- }
390
+ if ( baseOffset !== null ) {
391
+
392
+ timestampQueryPool.beginQuery( renderContext );
193
393
 
194
394
  }
195
395
 
196
396
  }
197
397
 
398
+ // timestamp utils
399
+
400
+ /**
401
+ * Prepares the timestamp buffer.
402
+ *
403
+ * @param {RenderContext} renderContext - The render context.
404
+ */
405
+ prepareTimestampBuffer( renderContext ) {
406
+
407
+ if ( ! this.disjoint || ! this.trackTimestamp ) return;
408
+
409
+ const type = renderContext.isComputeNode ? 'compute' : 'render';
410
+ const timestampQueryPool = this.timestampQueryPool[ type ];
411
+
412
+ timestampQueryPool.endQuery( renderContext );
413
+
414
+ }
415
+
416
+
417
+ /**
418
+ * Returns the backend's rendering context.
419
+ *
420
+ * @return {WebGL2RenderingContext} The rendering context.
421
+ */
198
422
  getContext() {
199
423
 
200
424
  return this.gl;
201
425
 
202
426
  }
203
427
 
428
+ /**
429
+ * This method is executed at the beginning of a render call and prepares
430
+ * the WebGL state for upcoming render calls
431
+ *
432
+ * @param {RenderContext} renderContext - The render context.
433
+ */
204
434
  beginRender( renderContext ) {
205
435
 
206
- const { gl } = this;
436
+ const { state, gl } = this;
207
437
  const renderContextData = this.get( renderContext );
208
438
 
209
439
  //
@@ -226,7 +456,7 @@ class WebGLBackend extends Backend {
226
456
 
227
457
  } else {
228
458
 
229
- gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
459
+ state.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
230
460
 
231
461
  }
232
462
 
@@ -234,7 +464,7 @@ class WebGLBackend extends Backend {
234
464
 
235
465
  const { x, y, width, height } = renderContext.scissorValue;
236
466
 
237
- gl.scissor( x, renderContext.height - height - y, width, height );
467
+ state.scissor( x, renderContext.height - height - y, width, height );
238
468
 
239
469
  }
240
470
 
@@ -256,6 +486,12 @@ class WebGLBackend extends Backend {
256
486
 
257
487
  }
258
488
 
489
+ /**
490
+ * This method is executed at the end of a render call and finalizes work
491
+ * after draw calls.
492
+ *
493
+ * @param {RenderContext} renderContext - The render context.
494
+ */
259
495
  finishRender( renderContext ) {
260
496
 
261
497
  const { gl, state } = this;
@@ -302,7 +538,7 @@ class WebGLBackend extends Backend {
302
538
 
303
539
  const { samples } = renderContext.renderTarget;
304
540
 
305
- if ( samples > 0 ) {
541
+ if ( samples > 0 && this._useMultisampledRTT( renderContext.renderTarget ) === false ) {
306
542
 
307
543
  const fb = renderTargetContextData.framebuffers[ renderContext.getCacheKey() ];
308
544
 
@@ -352,7 +588,7 @@ class WebGLBackend extends Backend {
352
588
 
353
589
  } else {
354
590
 
355
- gl.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
591
+ state.viewport( 0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight );
356
592
 
357
593
  }
358
594
 
@@ -362,6 +598,13 @@ class WebGLBackend extends Backend {
362
598
 
363
599
  }
364
600
 
601
+ /**
602
+ * This method processes the result of occlusion queries and writes it
603
+ * into render context data.
604
+ *
605
+ * @async
606
+ * @param {RenderContext} renderContext - The render context.
607
+ */
365
608
  resolveOccludedAsync( renderContext ) {
366
609
 
367
610
  const renderContextData = this.get( renderContext );
@@ -391,7 +634,7 @@ class WebGLBackend extends Backend {
391
634
 
392
635
  if ( gl.getQueryParameter( query, gl.QUERY_RESULT_AVAILABLE ) ) {
393
636
 
394
- if ( gl.getQueryParameter( query, gl.QUERY_RESULT ) > 0 ) occluded.add( currentOcclusionQueryObjects[ i ] );
637
+ if ( gl.getQueryParameter( query, gl.QUERY_RESULT ) === 0 ) occluded.add( currentOcclusionQueryObjects[ i ] );
395
638
 
396
639
  currentOcclusionQueries[ i ] = null;
397
640
  gl.deleteQuery( query );
@@ -420,6 +663,14 @@ class WebGLBackend extends Backend {
420
663
 
421
664
  }
422
665
 
666
+ /**
667
+ * Returns `true` if the given 3D object is fully occluded by other
668
+ * 3D objects in the scene.
669
+ *
670
+ * @param {RenderContext} renderContext - The render context.
671
+ * @param {Object3D} object - The 3D object to test.
672
+ * @return {Boolean} Whether the 3D object is fully occluded or not.
673
+ */
423
674
  isOccluded( renderContext, object ) {
424
675
 
425
676
  const renderContextData = this.get( renderContext );
@@ -428,31 +679,42 @@ class WebGLBackend extends Backend {
428
679
 
429
680
  }
430
681
 
682
+ /**
683
+ * Updates the viewport with the values from the given render context.
684
+ *
685
+ * @param {RenderContext} renderContext - The render context.
686
+ */
431
687
  updateViewport( renderContext ) {
432
688
 
433
- const gl = this.gl;
689
+ const { state } = this;
434
690
  const { x, y, width, height } = renderContext.viewportValue;
435
691
 
436
- gl.viewport( x, renderContext.height - height - y, width, height );
692
+ state.viewport( x, renderContext.height - height - y, width, height );
437
693
 
438
694
  }
439
695
 
696
+ /**
697
+ * Defines the scissor test.
698
+ *
699
+ * @param {Boolean} boolean - Whether the scissor test should be enabled or not.
700
+ */
440
701
  setScissorTest( boolean ) {
441
702
 
442
- const gl = this.gl;
443
-
444
- if ( boolean ) {
445
-
446
- gl.enable( gl.SCISSOR_TEST );
447
-
448
- } else {
449
-
450
- gl.disable( gl.SCISSOR_TEST );
703
+ const state = this.state;
451
704
 
452
- }
705
+ state.setScissorTest( boolean );
453
706
 
454
707
  }
455
708
 
709
+ /**
710
+ * Performs a clear operation.
711
+ *
712
+ * @param {Boolean} color - Whether the color buffer should be cleared or not.
713
+ * @param {Boolean} depth - Whether the depth buffer should be cleared or not.
714
+ * @param {Boolean} stencil - Whether the stencil buffer should be cleared or not.
715
+ * @param {Object?} [descriptor=null] - The render context of the current set render target.
716
+ * @param {Boolean} [setFrameBuffer=true] - TODO.
717
+ */
456
718
  clear( color, depth, stencil, descriptor = null, setFrameBuffer = true ) {
457
719
 
458
720
  const { gl } = this;
@@ -543,6 +805,12 @@ class WebGLBackend extends Backend {
543
805
 
544
806
  }
545
807
 
808
+ /**
809
+ * This method is executed at the beginning of a compute call and
810
+ * prepares the state for upcoming compute tasks.
811
+ *
812
+ * @param {Node|Array<Node>} computeGroup - The compute node(s).
813
+ */
546
814
  beginCompute( computeGroup ) {
547
815
 
548
816
  const { state, gl } = this;
@@ -552,11 +820,19 @@ class WebGLBackend extends Backend {
552
820
 
553
821
  }
554
822
 
823
+ /**
824
+ * Executes a compute command for the given compute node.
825
+ *
826
+ * @param {Node|Array<Node>} computeGroup - The group of compute nodes of a compute call. Can be a single compute node.
827
+ * @param {Node} computeNode - The compute node.
828
+ * @param {Array<BindGroup>} bindings - The bindings.
829
+ * @param {ComputePipeline} pipeline - The compute pipeline.
830
+ */
555
831
  compute( computeGroup, computeNode, bindings, pipeline ) {
556
832
 
557
833
  const { state, gl } = this;
558
834
 
559
- if ( ! this.discard ) {
835
+ if ( this.discard === false ) {
560
836
 
561
837
  // required here to handle async behaviour of render.compute()
562
838
  gl.enable( gl.RASTERIZER_DISCARD );
@@ -621,6 +897,12 @@ class WebGLBackend extends Backend {
621
897
 
622
898
  }
623
899
 
900
+ /**
901
+ * This method is executed at the end of a compute call and
902
+ * finalizes work after compute tasks.
903
+ *
904
+ * @param {Node|Array<Node>} computeGroup - The compute node(s).
905
+ */
624
906
  finishCompute( computeGroup ) {
625
907
 
626
908
  const gl = this.gl;
@@ -639,6 +921,12 @@ class WebGLBackend extends Backend {
639
921
 
640
922
  }
641
923
 
924
+ /**
925
+ * Executes a draw command for the given render object.
926
+ *
927
+ * @param {RenderObject} renderObject - The render object to draw.
928
+ * @param {Info} info - Holds a series of statistical information about the GPU memory and the rendering process.
929
+ */
642
930
  draw( renderObject/*, info*/ ) {
643
931
 
644
932
  const { object, pipeline, material, context, hardwareClippingPlanes } = renderObject;
@@ -770,43 +1058,125 @@ class WebGLBackend extends Backend {
770
1058
 
771
1059
  }
772
1060
 
773
- if ( object.isBatchedMesh ) {
1061
+ const draw = () => {
1062
+
1063
+ if ( object.isBatchedMesh ) {
774
1064
 
775
- if ( object._multiDrawInstances !== null ) {
1065
+ if ( object._multiDrawInstances !== null ) {
776
1066
 
777
- renderer.renderMultiDrawInstances( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances );
1067
+ renderer.renderMultiDrawInstances( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances );
778
1068
 
779
- } else if ( ! this.hasFeature( 'WEBGL_multi_draw' ) ) {
1069
+ } else if ( ! this.hasFeature( 'WEBGL_multi_draw' ) ) {
1070
+
1071
+ warnOnce( 'THREE.WebGLRenderer: WEBGL_multi_draw not supported.' );
1072
+
1073
+ } else {
780
1074
 
781
- warnOnce( 'THREE.WebGLRenderer: WEBGL_multi_draw not supported.' );
1075
+ renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount );
1076
+
1077
+ }
1078
+
1079
+ } else if ( instanceCount > 1 ) {
1080
+
1081
+ renderer.renderInstances( firstVertex, vertexCount, instanceCount );
782
1082
 
783
1083
  } else {
784
1084
 
785
- renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount );
1085
+ renderer.render( firstVertex, vertexCount );
786
1086
 
787
1087
  }
788
1088
 
789
- } else if ( instanceCount > 1 ) {
1089
+ };
1090
+
1091
+ if ( renderObject.camera.isArrayCamera && renderObject.camera.cameras.length > 0 ) {
1092
+
1093
+ const cameraData = this.get( renderObject.camera );
1094
+ const cameras = renderObject.camera.cameras;
1095
+ const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' ).bindings[ 0 ];
1096
+
1097
+ if ( cameraData.indexesGPU === undefined || cameraData.indexesGPU.length !== cameras.length ) {
1098
+
1099
+ const data = new Uint32Array( [ 0, 0, 0, 0 ] );
1100
+ const indexesGPU = [];
1101
+
1102
+ for ( let i = 0, len = cameras.length; i < len; i ++ ) {
1103
+
1104
+ const bufferGPU = gl.createBuffer();
1105
+
1106
+ data[ 0 ] = i;
1107
+
1108
+ gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
1109
+ gl.bufferData( gl.UNIFORM_BUFFER, data, gl.STATIC_DRAW );
1110
+
1111
+ indexesGPU.push( bufferGPU );
1112
+
1113
+ }
790
1114
 
791
- renderer.renderInstances( firstVertex, vertexCount, instanceCount );
1115
+ cameraData.indexesGPU = indexesGPU; // TODO: Create a global library for this
1116
+
1117
+ }
1118
+
1119
+ const cameraIndexData = this.get( cameraIndex );
1120
+ const pixelRatio = this.renderer.getPixelRatio();
1121
+
1122
+ for ( let i = 0, len = cameras.length; i < len; i ++ ) {
1123
+
1124
+ const subCamera = cameras[ i ];
1125
+
1126
+ if ( object.layers.test( subCamera.layers ) ) {
1127
+
1128
+ const vp = subCamera.viewport;
1129
+
1130
+ const x = vp.x * pixelRatio;
1131
+ const y = vp.y * pixelRatio;
1132
+ const width = vp.width * pixelRatio;
1133
+ const height = vp.height * pixelRatio;
1134
+
1135
+ state.viewport(
1136
+ Math.floor( x ),
1137
+ Math.floor( renderObject.context.height - height - y ),
1138
+ Math.floor( width ),
1139
+ Math.floor( height )
1140
+ );
1141
+
1142
+ state.bindBufferBase( gl.UNIFORM_BUFFER, cameraIndexData.index, cameraData.indexesGPU[ i ] );
1143
+
1144
+ draw();
1145
+
1146
+ }
1147
+
1148
+ }
792
1149
 
793
1150
  } else {
794
1151
 
795
- renderer.render( firstVertex, vertexCount );
1152
+ draw();
796
1153
 
797
1154
  }
1155
+
798
1156
  //
799
1157
 
800
1158
  gl.bindVertexArray( null );
801
1159
 
802
1160
  }
803
1161
 
1162
+ /**
1163
+ * Explain why always null is returned.
1164
+ *
1165
+ * @param {RenderObject} renderObject - The render object.
1166
+ * @return {Boolean} Whether the render pipeline requires an update or not.
1167
+ */
804
1168
  needsRenderUpdate( /*renderObject*/ ) {
805
1169
 
806
1170
  return false;
807
1171
 
808
1172
  }
809
1173
 
1174
+ /**
1175
+ * Explain why no cache key is computed.
1176
+ *
1177
+ * @param {RenderObject} renderObject - The render object.
1178
+ * @return {String} The cache key.
1179
+ */
810
1180
  getRenderCacheKey( /*renderObject*/ ) {
811
1181
 
812
1182
  return '';
@@ -815,53 +1185,109 @@ class WebGLBackend extends Backend {
815
1185
 
816
1186
  // textures
817
1187
 
1188
+ /**
1189
+ * Creates a default texture for the given texture that can be used
1190
+ * as a placeholder until the actual texture is ready for usage.
1191
+ *
1192
+ * @param {Texture} texture - The texture to create a default texture for.
1193
+ */
818
1194
  createDefaultTexture( texture ) {
819
1195
 
820
1196
  this.textureUtils.createDefaultTexture( texture );
821
1197
 
822
1198
  }
823
1199
 
1200
+ /**
1201
+ * Defines a texture on the GPU for the given texture object.
1202
+ *
1203
+ * @param {Texture} texture - The texture.
1204
+ * @param {Object} [options={}] - Optional configuration parameter.
1205
+ */
824
1206
  createTexture( texture, options ) {
825
1207
 
826
1208
  this.textureUtils.createTexture( texture, options );
827
1209
 
828
1210
  }
829
1211
 
1212
+ /**
1213
+ * Uploads the updated texture data to the GPU.
1214
+ *
1215
+ * @param {Texture} texture - The texture.
1216
+ * @param {Object} [options={}] - Optional configuration parameter.
1217
+ */
830
1218
  updateTexture( texture, options ) {
831
1219
 
832
1220
  this.textureUtils.updateTexture( texture, options );
833
1221
 
834
1222
  }
835
1223
 
1224
+ /**
1225
+ * Generates mipmaps for the given texture.
1226
+ *
1227
+ * @param {Texture} texture - The texture.
1228
+ */
836
1229
  generateMipmaps( texture ) {
837
1230
 
838
1231
  this.textureUtils.generateMipmaps( texture );
839
1232
 
840
1233
  }
841
1234
 
842
-
1235
+ /**
1236
+ * Destroys the GPU data for the given texture object.
1237
+ *
1238
+ * @param {Texture} texture - The texture.
1239
+ */
843
1240
  destroyTexture( texture ) {
844
1241
 
845
1242
  this.textureUtils.destroyTexture( texture );
846
1243
 
847
1244
  }
848
1245
 
849
- copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
1246
+ /**
1247
+ * Returns texture data as a typed array.
1248
+ *
1249
+ * @async
1250
+ * @param {Texture} texture - The texture to copy.
1251
+ * @param {Number} x - The x coordinate of the copy origin.
1252
+ * @param {Number} y - The y coordinate of the copy origin.
1253
+ * @param {Number} width - The width of the copy.
1254
+ * @param {Number} height - The height of the copy.
1255
+ * @param {Number} faceIndex - The face index.
1256
+ * @return {Promise<TypedArray>} A Promise that resolves with a typed array when the copy operation has finished.
1257
+ */
1258
+ async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
850
1259
 
851
1260
  return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height, faceIndex );
852
1261
 
853
1262
  }
854
1263
 
1264
+ /**
1265
+ * This method does nothing since WebGL 2 has no concept of samplers.
1266
+ *
1267
+ * @param {Texture} texture - The texture to create the sampler for.
1268
+ */
855
1269
  createSampler( /*texture*/ ) {
856
1270
 
857
1271
  //console.warn( 'Abstract class.' );
858
1272
 
859
1273
  }
860
1274
 
861
- destroySampler() {}
1275
+ /**
1276
+ * This method does nothing since WebGL 2 has no concept of samplers.
1277
+ *
1278
+ * @param {Texture} texture - The texture to destroy the sampler for.
1279
+ */
1280
+ destroySampler( /*texture*/ ) {}
862
1281
 
863
1282
  // node builder
864
1283
 
1284
+ /**
1285
+ * Returns a node builder for the given render object.
1286
+ *
1287
+ * @param {RenderObject} object - The render object.
1288
+ * @param {Renderer} renderer - The renderer.
1289
+ * @return {GLSLNodeBuilder} The node builder.
1290
+ */
865
1291
  createNodeBuilder( object, renderer ) {
866
1292
 
867
1293
  return new GLSLNodeBuilder( object, renderer );
@@ -870,6 +1296,11 @@ class WebGLBackend extends Backend {
870
1296
 
871
1297
  // program
872
1298
 
1299
+ /**
1300
+ * Creates a shader program from the given programmable stage.
1301
+ *
1302
+ * @param {ProgrammableStage} program - The programmable stage.
1303
+ */
873
1304
  createProgram( program ) {
874
1305
 
875
1306
  const gl = this.gl;
@@ -886,12 +1317,23 @@ class WebGLBackend extends Backend {
886
1317
 
887
1318
  }
888
1319
 
889
- destroyProgram( /*program*/ ) {
1320
+ /**
1321
+ * Destroys the shader program of the given programmable stage.
1322
+ *
1323
+ * @param {ProgrammableStage} program - The programmable stage.
1324
+ */
1325
+ destroyProgram( program ) {
890
1326
 
891
- console.warn( 'Abstract class.' );
1327
+ this.delete( program );
892
1328
 
893
1329
  }
894
1330
 
1331
+ /**
1332
+ * Creates a render pipeline for the given render object.
1333
+ *
1334
+ * @param {RenderObject} renderObject - The render object.
1335
+ * @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
1336
+ */
895
1337
  createRenderPipeline( renderObject, promises ) {
896
1338
 
897
1339
  const gl = this.gl;
@@ -950,6 +1392,14 @@ class WebGLBackend extends Backend {
950
1392
 
951
1393
  }
952
1394
 
1395
+ /**
1396
+ * Formats the source code of error messages.
1397
+ *
1398
+ * @private
1399
+ * @param {String} string - The code.
1400
+ * @param {Number} errorLine - The error line.
1401
+ * @return {String} The formatted code.
1402
+ */
953
1403
  _handleSource( string, errorLine ) {
954
1404
 
955
1405
  const lines = string.split( '\n' );
@@ -969,6 +1419,15 @@ class WebGLBackend extends Backend {
969
1419
 
970
1420
  }
971
1421
 
1422
+ /**
1423
+ * Gets the shader compilation errors from the info log.
1424
+ *
1425
+ * @private
1426
+ * @param {WebGL2RenderingContext} gl - The rendering context.
1427
+ * @param {WebGLShader} shader - The WebGL shader object.
1428
+ * @param {String} type - The shader type.
1429
+ * @return {String} The shader errors.
1430
+ */
972
1431
  _getShaderErrors( gl, shader, type ) {
973
1432
 
974
1433
  const status = gl.getShaderParameter( shader, gl.COMPILE_STATUS );
@@ -990,6 +1449,14 @@ class WebGLBackend extends Backend {
990
1449
 
991
1450
  }
992
1451
 
1452
+ /**
1453
+ * Logs shader compilation errors.
1454
+ *
1455
+ * @private
1456
+ * @param {WebGLProgram} programGPU - The WebGL program.
1457
+ * @param {WebGLShader} glFragmentShader - The fragment shader as a native WebGL shader object.
1458
+ * @param {WebGLShader} glVertexShader - The vertex shader as a native WebGL shader object.
1459
+ */
993
1460
  _logProgramError( programGPU, glFragmentShader, glVertexShader ) {
994
1461
 
995
1462
  if ( this.renderer.debug.checkShaderErrors ) {
@@ -1032,6 +1499,13 @@ class WebGLBackend extends Backend {
1032
1499
 
1033
1500
  }
1034
1501
 
1502
+ /**
1503
+ * Completes the shader program setup for the given render object.
1504
+ *
1505
+ * @private
1506
+ * @param {RenderObject} renderObject - The render object.
1507
+ * @param {RenderPipeline} pipeline - The render pipeline.
1508
+ */
1035
1509
  _completeCompile( renderObject, pipeline ) {
1036
1510
 
1037
1511
  const { state, gl } = this;
@@ -1060,6 +1534,12 @@ class WebGLBackend extends Backend {
1060
1534
 
1061
1535
  }
1062
1536
 
1537
+ /**
1538
+ * Creates a compute pipeline for the given compute node.
1539
+ *
1540
+ * @param {ComputePipeline} computePipeline - The compute pipeline.
1541
+ * @param {Array<BindGroup>} bindings - The bindings.
1542
+ */
1063
1543
  createComputePipeline( computePipeline, bindings ) {
1064
1544
 
1065
1545
  const { state, gl } = this;
@@ -1154,7 +1634,15 @@ class WebGLBackend extends Backend {
1154
1634
 
1155
1635
  }
1156
1636
 
1157
- createBindings( bindGroup, bindings ) {
1637
+ /**
1638
+ * Creates bindings from the given bind group definition.
1639
+ *
1640
+ * @param {BindGroup} bindGroup - The bind group.
1641
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
1642
+ * @param {Number} cacheIndex - The cache index.
1643
+ * @param {Number} version - The version.
1644
+ */
1645
+ createBindings( bindGroup, bindings /*, cacheIndex, version*/ ) {
1158
1646
 
1159
1647
  if ( this._knownBindings.has( bindings ) === false ) {
1160
1648
 
@@ -1185,7 +1673,15 @@ class WebGLBackend extends Backend {
1185
1673
 
1186
1674
  }
1187
1675
 
1188
- updateBindings( bindGroup /*, bindings*/ ) {
1676
+ /**
1677
+ * Updates the given bind group definition.
1678
+ *
1679
+ * @param {BindGroup} bindGroup - The bind group.
1680
+ * @param {Array<BindGroup>} bindings - Array of bind groups.
1681
+ * @param {Number} cacheIndex - The cache index.
1682
+ * @param {Number} version - The version.
1683
+ */
1684
+ updateBindings( bindGroup /*, bindings, cacheIndex, version*/ ) {
1189
1685
 
1190
1686
  const { gl } = this;
1191
1687
 
@@ -1225,6 +1721,11 @@ class WebGLBackend extends Backend {
1225
1721
 
1226
1722
  }
1227
1723
 
1724
+ /**
1725
+ * Updates a buffer binding.
1726
+ *
1727
+ * @param {Buffer} binding - The buffer binding to update.
1728
+ */
1228
1729
  updateBinding( binding ) {
1229
1730
 
1230
1731
  const gl = this.gl;
@@ -1244,6 +1745,11 @@ class WebGLBackend extends Backend {
1244
1745
 
1245
1746
  // attributes
1246
1747
 
1748
+ /**
1749
+ * Creates the GPU buffer of an indexed shader attribute.
1750
+ *
1751
+ * @param {BufferAttribute} attribute - The indexed buffer attribute.
1752
+ */
1247
1753
  createIndexAttribute( attribute ) {
1248
1754
 
1249
1755
  const gl = this.gl;
@@ -1252,6 +1758,11 @@ class WebGLBackend extends Backend {
1252
1758
 
1253
1759
  }
1254
1760
 
1761
+ /**
1762
+ * Creates the GPU buffer of a shader attribute.
1763
+ *
1764
+ * @param {BufferAttribute} attribute - The buffer attribute.
1765
+ */
1255
1766
  createAttribute( attribute ) {
1256
1767
 
1257
1768
  if ( this.has( attribute ) ) return;
@@ -1262,6 +1773,11 @@ class WebGLBackend extends Backend {
1262
1773
 
1263
1774
  }
1264
1775
 
1776
+ /**
1777
+ * Creates the GPU buffer of a storage attribute.
1778
+ *
1779
+ * @param {BufferAttribute} attribute - The buffer attribute.
1780
+ */
1265
1781
  createStorageAttribute( attribute ) {
1266
1782
 
1267
1783
  if ( this.has( attribute ) ) return;
@@ -1272,24 +1788,34 @@ class WebGLBackend extends Backend {
1272
1788
 
1273
1789
  }
1274
1790
 
1791
+ /**
1792
+ * Updates the GPU buffer of a shader attribute.
1793
+ *
1794
+ * @param {BufferAttribute} attribute - The buffer attribute to update.
1795
+ */
1275
1796
  updateAttribute( attribute ) {
1276
1797
 
1277
1798
  this.attributeUtils.updateAttribute( attribute );
1278
1799
 
1279
1800
  }
1280
1801
 
1802
+ /**
1803
+ * Destroys the GPU buffer of a shader attribute.
1804
+ *
1805
+ * @param {BufferAttribute} attribute - The buffer attribute to destroy.
1806
+ */
1281
1807
  destroyAttribute( attribute ) {
1282
1808
 
1283
1809
  this.attributeUtils.destroyAttribute( attribute );
1284
1810
 
1285
1811
  }
1286
1812
 
1287
- updateSize() {
1288
-
1289
- //console.warn( 'Abstract class.' );
1290
-
1291
- }
1292
-
1813
+ /**
1814
+ * Checks if the given feature is supported by the backend.
1815
+ *
1816
+ * @param {String} name - The feature's name.
1817
+ * @return {Boolean} Whether the feature is supported or not.
1818
+ */
1293
1819
  hasFeature( name ) {
1294
1820
 
1295
1821
  const keysMatching = Object.keys( GLFeatureName ).filter( key => GLFeatureName[ key ] === name );
@@ -1306,24 +1832,51 @@ class WebGLBackend extends Backend {
1306
1832
 
1307
1833
  }
1308
1834
 
1835
+ /**
1836
+ * Returns the maximum anisotropy texture filtering value.
1837
+ *
1838
+ * @return {Number} The maximum anisotropy texture filtering value.
1839
+ */
1309
1840
  getMaxAnisotropy() {
1310
1841
 
1311
1842
  return this.capabilities.getMaxAnisotropy();
1312
1843
 
1313
1844
  }
1314
1845
 
1315
- copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level ) {
1846
+ /**
1847
+ * Copies data of the given source texture to the given destination texture.
1848
+ *
1849
+ * @param {Texture} srcTexture - The source texture.
1850
+ * @param {Texture} dstTexture - The destination texture.
1851
+ * @param {Vector4?} [srcRegion=null] - The region of the source texture to copy.
1852
+ * @param {(Vector2|Vector3)?} [dstPosition=null] - The destination position of the copy.
1853
+ * @param {Number} [level=0] - The mip level to copy.
1854
+ */
1855
+ copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
1316
1856
 
1317
1857
  this.textureUtils.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level );
1318
1858
 
1319
1859
  }
1320
1860
 
1861
+ /**
1862
+ * Copies the current bound framebuffer to the given texture.
1863
+ *
1864
+ * @param {Texture} texture - The destination texture.
1865
+ * @param {RenderContext} renderContext - The render context.
1866
+ * @param {Vector4} rectangle - A four dimensional vector defining the origin and dimension of the copy.
1867
+ */
1321
1868
  copyFramebufferToTexture( texture, renderContext, rectangle ) {
1322
1869
 
1323
1870
  this.textureUtils.copyFramebufferToTexture( texture, renderContext, rectangle );
1324
1871
 
1325
1872
  }
1326
1873
 
1874
+ /**
1875
+ * Configures the active framebuffer from the given render context.
1876
+ *
1877
+ * @private
1878
+ * @param {RenderContext} descriptor - The render context.
1879
+ */
1327
1880
  _setFramebuffer( descriptor ) {
1328
1881
 
1329
1882
  const { gl, state } = this;
@@ -1337,9 +1890,15 @@ class WebGLBackend extends Backend {
1337
1890
  const { samples, depthBuffer, stencilBuffer } = renderTarget;
1338
1891
 
1339
1892
  const isCube = renderTarget.isWebGLCubeRenderTarget === true;
1893
+ const isRenderTarget3D = renderTarget.isRenderTarget3D === true;
1894
+ const isRenderTargetArray = renderTarget.isRenderTargetArray === true;
1895
+ const isXRRenderTarget = renderTarget.isXRRenderTarget === true;
1896
+ const hasExternalTextures = ( isXRRenderTarget === true && renderTarget.hasExternalTextures === true );
1340
1897
 
1341
1898
  let msaaFb = renderTargetContextData.msaaFrameBuffer;
1342
1899
  let depthRenderbuffer = renderTargetContextData.depthRenderbuffer;
1900
+ const multisampledRTTExt = this.extensions.get( 'WEBGL_multisampled_render_to_texture' );
1901
+ const useMultisampledRTT = this._useMultisampledRTT( renderTarget );
1343
1902
 
1344
1903
  const cacheKey = getCacheKey( descriptor );
1345
1904
 
@@ -1351,6 +1910,10 @@ class WebGLBackend extends Backend {
1351
1910
 
1352
1911
  fb = renderTargetContextData.cubeFramebuffers[ cacheKey ];
1353
1912
 
1913
+ } else if ( isXRRenderTarget && hasExternalTextures === false ) {
1914
+
1915
+ fb = this._xrFamebuffer;
1916
+
1354
1917
  } else {
1355
1918
 
1356
1919
  renderTargetContextData.framebuffers || ( renderTargetContextData.framebuffers = {} );
@@ -1390,7 +1953,25 @@ class WebGLBackend extends Backend {
1390
1953
 
1391
1954
  const attachment = gl.COLOR_ATTACHMENT0 + i;
1392
1955
 
1393
- gl.framebufferTexture2D( gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureData.textureGPU, 0 );
1956
+ if ( isRenderTarget3D || isRenderTargetArray ) {
1957
+
1958
+ const layer = this.renderer._activeCubeFace;
1959
+
1960
+ gl.framebufferTextureLayer( gl.FRAMEBUFFER, attachment, textureData.textureGPU, 0, layer );
1961
+
1962
+ } else {
1963
+
1964
+ if ( useMultisampledRTT ) {
1965
+
1966
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureData.textureGPU, 0, samples );
1967
+
1968
+ } else {
1969
+
1970
+ gl.framebufferTexture2D( gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureData.textureGPU, 0 );
1971
+
1972
+ }
1973
+
1974
+ }
1394
1975
 
1395
1976
  }
1396
1977
 
@@ -1398,20 +1979,88 @@ class WebGLBackend extends Backend {
1398
1979
 
1399
1980
  }
1400
1981
 
1401
- if ( descriptor.depthTexture !== null ) {
1982
+ if ( renderTarget.isXRRenderTarget && renderTarget.autoAllocateDepthBuffer === true ) {
1983
+
1984
+ const renderbuffer = gl.createRenderbuffer();
1985
+ this.textureUtils.setupRenderBufferStorage( renderbuffer, descriptor, 0, useMultisampledRTT );
1986
+ renderTargetContextData.xrDepthRenderbuffer = renderbuffer;
1987
+
1988
+ } else {
1989
+
1990
+ if ( descriptor.depthTexture !== null ) {
1991
+
1992
+ const textureData = this.get( descriptor.depthTexture );
1993
+ const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
1994
+ textureData.renderTarget = descriptor.renderTarget;
1995
+ textureData.cacheKey = cacheKey; // required for copyTextureToTexture()
1996
+
1997
+ if ( useMultisampledRTT ) {
1998
+
1999
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0, samples );
2000
+
2001
+ } else {
2002
+
2003
+ gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );
2004
+
2005
+ }
2006
+
2007
+ }
2008
+
2009
+ }
2010
+
2011
+ } else {
2012
+
2013
+ // rebind external XR textures
2014
+
2015
+ if ( isXRRenderTarget && hasExternalTextures ) {
2016
+
2017
+ state.bindFramebuffer( gl.FRAMEBUFFER, fb );
2018
+
2019
+ // rebind color
2020
+
2021
+ const textureData = this.get( descriptor.textures[ 0 ] );
2022
+
2023
+ if ( useMultisampledRTT ) {
2024
+
2025
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, textureData.textureGPU, 0, samples );
2026
+
2027
+ } else {
2028
+
2029
+ gl.framebufferTexture2D( gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, textureData.textureGPU, 0 );
2030
+
2031
+ }
2032
+
2033
+ // rebind depth
1402
2034
 
1403
- const textureData = this.get( descriptor.depthTexture );
1404
2035
  const depthStyle = stencilBuffer ? gl.DEPTH_STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
1405
- textureData.renderTarget = descriptor.renderTarget;
1406
- textureData.cacheKey = cacheKey; // required for copyTextureToTexture()
1407
2036
 
1408
- gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );
2037
+ if ( renderTarget.autoAllocateDepthBuffer === true ) {
2038
+
2039
+ const renderbuffer = renderTargetContextData.xrDepthRenderbuffer;
2040
+ gl.bindRenderbuffer( gl.RENDERBUFFER, renderbuffer );
2041
+ gl.framebufferRenderbuffer( gl.FRAMEBUFFER, depthStyle, gl.RENDERBUFFER, renderbuffer );
2042
+
2043
+ } else {
2044
+
2045
+ const textureData = this.get( descriptor.depthTexture );
2046
+
2047
+ if ( useMultisampledRTT ) {
2048
+
2049
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0, samples );
2050
+
2051
+ } else {
2052
+
2053
+ gl.framebufferTexture2D( gl.FRAMEBUFFER, depthStyle, gl.TEXTURE_2D, textureData.textureGPU, 0 );
2054
+
2055
+ }
2056
+
2057
+ }
1409
2058
 
1410
2059
  }
1411
2060
 
1412
2061
  }
1413
2062
 
1414
- if ( samples > 0 ) {
2063
+ if ( samples > 0 && useMultisampledRTT === false ) {
1415
2064
 
1416
2065
  if ( msaaFb === undefined ) {
1417
2066
 
@@ -1455,7 +2104,7 @@ class WebGLBackend extends Backend {
1455
2104
  if ( depthRenderbuffer === undefined ) {
1456
2105
 
1457
2106
  depthRenderbuffer = gl.createRenderbuffer();
1458
- this.textureUtils.setupRenderBufferStorage( depthRenderbuffer, descriptor );
2107
+ this.textureUtils.setupRenderBufferStorage( depthRenderbuffer, descriptor, samples );
1459
2108
 
1460
2109
  renderTargetContextData.depthRenderbuffer = depthRenderbuffer;
1461
2110
 
@@ -1482,10 +2131,17 @@ class WebGLBackend extends Backend {
1482
2131
 
1483
2132
  }
1484
2133
 
1485
-
2134
+ /**
2135
+ * Computes the VAO key for the given index and attributes.
2136
+ *
2137
+ * @private
2138
+ * @param {BufferAttribute?} index - The index. `null` for non-indexed geometries.
2139
+ * @param {Array<BufferAttribute>} attributes - An array of buffer attributes.
2140
+ * @return {String} The VAO key.
2141
+ */
1486
2142
  _getVaoKey( index, attributes ) {
1487
2143
 
1488
- let key = [];
2144
+ let key = '';
1489
2145
 
1490
2146
  if ( index !== null ) {
1491
2147
 
@@ -1507,6 +2163,14 @@ class WebGLBackend extends Backend {
1507
2163
 
1508
2164
  }
1509
2165
 
2166
+ /**
2167
+ * Creates a VAO from the index and attributes.
2168
+ *
2169
+ * @private
2170
+ * @param {BufferAttribute?} index - The index. `null` for non-indexed geometries.
2171
+ * @param {Array<BufferAttribute>} attributes - An array of buffer attributes.
2172
+ * @return {Object} The VAO data.
2173
+ */
1510
2174
  _createVao( index, attributes ) {
1511
2175
 
1512
2176
  const { gl } = this;
@@ -1584,6 +2248,13 @@ class WebGLBackend extends Backend {
1584
2248
 
1585
2249
  }
1586
2250
 
2251
+ /**
2252
+ * Creates a transform feedback from the given transform buffers.
2253
+ *
2254
+ * @private
2255
+ * @param {Array<DualAttributeData>} transformBuffers - The transform buffers.
2256
+ * @return {WebGLTransformFeedback} The transform feedback.
2257
+ */
1587
2258
  _getTransformFeedback( transformBuffers ) {
1588
2259
 
1589
2260
  let key = '';
@@ -1624,7 +2295,13 @@ class WebGLBackend extends Backend {
1624
2295
 
1625
2296
  }
1626
2297
 
1627
-
2298
+ /**
2299
+ * Setups the given bindings.
2300
+ *
2301
+ * @private
2302
+ * @param {Array<BindGroup>} bindings - The bindings.
2303
+ * @param {WebGLProgram} programGPU - The WebGL program.
2304
+ */
1628
2305
  _setupBindings( bindings, programGPU ) {
1629
2306
 
1630
2307
  const gl = this.gl;
@@ -1654,6 +2331,12 @@ class WebGLBackend extends Backend {
1654
2331
 
1655
2332
  }
1656
2333
 
2334
+ /**
2335
+ * Binds the given uniforms.
2336
+ *
2337
+ * @private
2338
+ * @param {Array<BindGroup>} bindings - The bindings.
2339
+ */
1657
2340
  _bindUniforms( bindings ) {
1658
2341
 
1659
2342
  const { gl, state } = this;
@@ -1682,8 +2365,28 @@ class WebGLBackend extends Backend {
1682
2365
 
1683
2366
  }
1684
2367
 
2368
+ /**
2369
+ * Returns `true` if the `WEBGL_multisampled_render_to_texture` extension
2370
+ * should be used when MSAA is enabled.
2371
+ *
2372
+ * @private
2373
+ * @param {RenderTarget} renderTarget - The render target that should be multisampled.
2374
+ * @return {Boolean} Whether to use the `WEBGL_multisampled_render_to_texture` extension for MSAA or not.
2375
+ */
2376
+ _useMultisampledRTT( renderTarget ) {
2377
+
2378
+ return renderTarget.samples > 0 && this.extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true && renderTarget.autoAllocateDepthBuffer !== false;
2379
+
2380
+ }
2381
+
2382
+ /**
2383
+ * Frees internal resources.
2384
+ */
1685
2385
  dispose() {
1686
2386
 
2387
+ const extension = this.extensions.get( 'WEBGL_lose_context' );
2388
+ if ( extension ) extension.loseContext();
2389
+
1687
2390
  this.renderer.domElement.removeEventListener( 'webglcontextlost', this._onContextLost );
1688
2391
 
1689
2392
  }