@needle-tools/three 0.169.20 → 0.183.2-canary.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 (1051) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -6
  3. package/build/three.cjs +54178 -56709
  4. package/build/three.core.js +59506 -0
  5. package/build/three.core.min.js +6 -0
  6. package/build/three.module.js +11645 -73012
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +648 -0
  9. package/build/three.tsl.min.js +6 -0
  10. package/build/three.webgpu.js +53905 -51657
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +53884 -51814
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
  15. package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
  16. package/examples/jsm/Addons.js +5 -15
  17. package/examples/jsm/animation/AnimationClipCreator.js +58 -6
  18. package/examples/jsm/animation/CCDIKSolver.js +152 -45
  19. package/examples/jsm/capabilities/WebGL.js +28 -29
  20. package/examples/jsm/capabilities/WebGPU.js +19 -17
  21. package/examples/jsm/controls/ArcballControls.js +474 -178
  22. package/examples/jsm/controls/DragControls.js +100 -58
  23. package/examples/jsm/controls/FirstPersonControls.js +116 -6
  24. package/examples/jsm/controls/FlyControls.js +50 -2
  25. package/examples/jsm/controls/MapControls.js +96 -8
  26. package/examples/jsm/controls/OrbitControls.js +496 -57
  27. package/examples/jsm/controls/PointerLockControls.js +115 -22
  28. package/examples/jsm/controls/TrackballControls.js +166 -14
  29. package/examples/jsm/controls/TransformControls.js +336 -26
  30. package/examples/jsm/csm/CSM.js +232 -18
  31. package/examples/jsm/csm/CSMFrustum.js +61 -4
  32. package/examples/jsm/csm/CSMHelper.js +50 -0
  33. package/examples/jsm/csm/CSMShader.js +13 -1
  34. package/examples/jsm/csm/CSMShadowNode.js +599 -0
  35. package/examples/jsm/curves/CurveExtras.js +303 -31
  36. package/examples/jsm/curves/NURBSCurve.js +91 -16
  37. package/examples/jsm/curves/NURBSSurface.js +52 -6
  38. package/examples/jsm/curves/NURBSUtils.js +102 -112
  39. package/examples/jsm/curves/NURBSVolume.js +24 -4
  40. package/examples/jsm/effects/AnaglyphEffect.js +134 -7
  41. package/examples/jsm/effects/AsciiEffect.js +69 -22
  42. package/examples/jsm/effects/OutlineEffect.js +61 -111
  43. package/examples/jsm/effects/ParallaxBarrierEffect.js +30 -0
  44. package/examples/jsm/effects/StereoEffect.js +31 -0
  45. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  46. package/examples/jsm/environments/DebugEnvironment.js +50 -0
  47. package/examples/jsm/environments/RoomEnvironment.js +83 -42
  48. package/examples/jsm/exporters/DRACOExporter.js +56 -14
  49. package/examples/jsm/exporters/EXRExporter.js +40 -9
  50. package/examples/jsm/exporters/GLTFExporter.js +502 -169
  51. package/examples/jsm/exporters/OBJExporter.js +21 -1
  52. package/examples/jsm/exporters/PLYExporter.js +44 -12
  53. package/examples/jsm/exporters/STLExporter.js +27 -5
  54. package/examples/jsm/exporters/USDZExporter.js +781 -291
  55. package/examples/jsm/geometries/BoxLineGeometry.js +23 -0
  56. package/examples/jsm/geometries/ConvexGeometry.js +19 -0
  57. package/examples/jsm/geometries/DecalGeometry.js +91 -30
  58. package/examples/jsm/geometries/ParametricFunctions.js +100 -0
  59. package/examples/jsm/geometries/ParametricGeometry.js +38 -5
  60. package/examples/jsm/geometries/RoundedBoxGeometry.js +68 -7
  61. package/examples/jsm/geometries/TeapotGeometry.js +23 -38
  62. package/examples/jsm/geometries/TextGeometry.js +48 -29
  63. package/examples/jsm/gpgpu/BitonicSort.js +715 -0
  64. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  65. package/examples/jsm/helpers/LightProbeHelper.js +36 -0
  66. package/examples/jsm/helpers/LightProbeHelperGPU.js +38 -1
  67. package/examples/jsm/helpers/OctreeHelper.js +36 -0
  68. package/examples/jsm/helpers/PositionalAudioHelper.js +60 -0
  69. package/examples/jsm/helpers/RapierHelper.js +59 -0
  70. package/examples/jsm/helpers/RectAreaLightHelper.js +36 -3
  71. package/examples/jsm/helpers/TextureHelper.js +28 -0
  72. package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
  73. package/examples/jsm/helpers/VertexNormalsHelper.js +61 -2
  74. package/examples/jsm/helpers/VertexTangentsHelper.js +47 -2
  75. package/examples/jsm/helpers/ViewHelper.js +181 -9
  76. package/examples/jsm/inspector/Inspector.js +487 -0
  77. package/examples/jsm/inspector/RendererInspector.js +425 -0
  78. package/examples/jsm/inspector/tabs/Console.js +238 -0
  79. package/examples/jsm/inspector/tabs/Parameters.js +348 -0
  80. package/examples/jsm/inspector/tabs/Performance.js +268 -0
  81. package/examples/jsm/inspector/tabs/Viewer.js +166 -0
  82. package/examples/jsm/inspector/ui/Graph.js +95 -0
  83. package/examples/jsm/inspector/ui/Item.js +170 -0
  84. package/examples/jsm/inspector/ui/List.js +75 -0
  85. package/examples/jsm/inspector/ui/Profiler.js +1975 -0
  86. package/examples/jsm/inspector/ui/Style.js +1613 -0
  87. package/examples/jsm/inspector/ui/Tab.js +233 -0
  88. package/examples/jsm/inspector/ui/Values.js +439 -0
  89. package/examples/jsm/inspector/ui/utils.js +56 -0
  90. package/examples/jsm/interactive/HTMLMesh.js +43 -12
  91. package/examples/jsm/interactive/InteractiveGroup.js +170 -52
  92. package/examples/jsm/interactive/SelectionBox.js +106 -9
  93. package/examples/jsm/interactive/SelectionHelper.js +76 -30
  94. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  95. package/examples/jsm/libs/meshopt_decoder.module.js +76 -58
  96. package/examples/jsm/libs/motion-controllers.module.js +1 -1
  97. package/examples/jsm/lighting/TiledLighting.js +42 -0
  98. package/examples/jsm/lights/LightProbeGenerator.js +44 -7
  99. package/examples/jsm/lights/RectAreaLightTexturesLib.js +50 -14
  100. package/examples/jsm/lights/RectAreaLightUniformsLib.js +16 -0
  101. package/examples/jsm/lines/Line2.js +41 -4
  102. package/examples/jsm/lines/LineGeometry.js +80 -2
  103. package/examples/jsm/lines/LineMaterial.js +105 -5
  104. package/examples/jsm/lines/LineSegments2.js +54 -4
  105. package/examples/jsm/lines/LineSegmentsGeometry.js +65 -8
  106. package/examples/jsm/lines/Wireframe.js +41 -4
  107. package/examples/jsm/lines/WireframeGeometry2.js +27 -2
  108. package/examples/jsm/lines/webgpu/Line2.js +28 -2
  109. package/examples/jsm/lines/webgpu/LineSegments2.js +59 -24
  110. package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
  111. package/examples/jsm/loaders/3DMLoader.js +78 -6
  112. package/examples/jsm/loaders/3MFLoader.js +148 -7
  113. package/examples/jsm/loaders/AMFLoader.js +34 -14
  114. package/examples/jsm/loaders/BVHLoader.js +59 -12
  115. package/examples/jsm/loaders/ColladaLoader.js +61 -4027
  116. package/examples/jsm/loaders/DDSLoader.js +68 -1
  117. package/examples/jsm/loaders/DRACOLoader.js +146 -22
  118. package/examples/jsm/loaders/EXRLoader.js +255 -34
  119. package/examples/jsm/loaders/FBXLoader.js +80 -42
  120. package/examples/jsm/loaders/FontLoader.js +83 -6
  121. package/examples/jsm/loaders/GCodeLoader.js +71 -14
  122. package/examples/jsm/loaders/GLTFLoader.js +381 -263
  123. package/examples/jsm/loaders/HDRCubeTextureLoader.js +52 -3
  124. package/examples/jsm/loaders/HDRLoader.js +485 -0
  125. package/examples/jsm/loaders/IESLoader.js +42 -0
  126. package/examples/jsm/loaders/KMZLoader.js +39 -6
  127. package/examples/jsm/loaders/KTX2Loader.js +124 -48
  128. package/examples/jsm/loaders/KTXLoader.js +31 -10
  129. package/examples/jsm/loaders/LDrawLoader.js +192 -145
  130. package/examples/jsm/loaders/LUT3dlLoader.js +47 -10
  131. package/examples/jsm/loaders/LUTCubeLoader.js +46 -9
  132. package/examples/jsm/loaders/LUTImageLoader.js +79 -38
  133. package/examples/jsm/loaders/LWOLoader.js +54 -59
  134. package/examples/jsm/loaders/LottieLoader.js +54 -1
  135. package/examples/jsm/loaders/MD2Loader.js +37 -1
  136. package/examples/jsm/loaders/MDDLoader.js +57 -12
  137. package/examples/jsm/loaders/MTLLoader.js +60 -35
  138. package/examples/jsm/loaders/MaterialXLoader.js +268 -34
  139. package/examples/jsm/loaders/NRRDLoader.js +40 -8
  140. package/examples/jsm/loaders/OBJLoader.js +51 -2
  141. package/examples/jsm/loaders/PCDLoader.js +173 -21
  142. package/examples/jsm/loaders/PDBLoader.js +41 -2
  143. package/examples/jsm/loaders/PLYLoader.js +70 -39
  144. package/examples/jsm/loaders/PVRLoader.js +25 -6
  145. package/examples/jsm/loaders/RGBELoader.js +6 -438
  146. package/examples/jsm/loaders/STLLoader.js +48 -38
  147. package/examples/jsm/loaders/SVGLoader.js +119 -25
  148. package/examples/jsm/loaders/TDSLoader.js +92 -74
  149. package/examples/jsm/loaders/TGALoader.js +23 -2
  150. package/examples/jsm/loaders/TIFFLoader.js +23 -0
  151. package/examples/jsm/loaders/TTFLoader.js +50 -3
  152. package/examples/jsm/loaders/USDLoader.js +279 -0
  153. package/examples/jsm/loaders/USDZLoader.js +4 -858
  154. package/examples/jsm/loaders/UltraHDRLoader.js +338 -166
  155. package/examples/jsm/loaders/VOXLoader.js +688 -87
  156. package/examples/jsm/loaders/VRMLLoader.js +121 -12
  157. package/examples/jsm/loaders/VTKLoader.js +77 -25
  158. package/examples/jsm/loaders/XYZLoader.js +36 -0
  159. package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
  160. package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
  161. package/examples/jsm/loaders/lwo/IFFParser.js +77 -77
  162. package/examples/jsm/loaders/usd/USDAParser.js +822 -0
  163. package/examples/jsm/loaders/usd/USDCParser.js +1852 -0
  164. package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
  165. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
  166. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
  167. package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
  168. package/examples/jsm/math/Capsule.js +91 -14
  169. package/examples/jsm/math/ColorConverter.js +22 -0
  170. package/examples/jsm/math/ColorSpaces.js +74 -2
  171. package/examples/jsm/math/ConvexHull.js +517 -93
  172. package/examples/jsm/math/ImprovedNoise.js +32 -15
  173. package/examples/jsm/math/Lut.js +113 -0
  174. package/examples/jsm/math/MeshSurfaceSampler.js +78 -13
  175. package/examples/jsm/math/OBB.js +141 -29
  176. package/examples/jsm/math/Octree.js +283 -7
  177. package/examples/jsm/math/SimplexNoise.js +68 -42
  178. package/examples/jsm/misc/ConvexObjectBreaker.js +45 -25
  179. package/examples/jsm/misc/GPUComputationRenderer.js +96 -20
  180. package/examples/jsm/misc/Gyroscope.js +12 -0
  181. package/examples/jsm/misc/MD2Character.js +117 -2
  182. package/examples/jsm/misc/MD2CharacterComplex.js +175 -11
  183. package/examples/jsm/misc/MorphAnimMesh.js +44 -0
  184. package/examples/jsm/misc/MorphBlendMesh.js +103 -0
  185. package/examples/jsm/misc/ProgressiveLightMap.js +100 -54
  186. package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
  187. package/examples/jsm/misc/RollerCoaster.js +57 -0
  188. package/examples/jsm/misc/TubePainter.js +437 -40
  189. package/examples/jsm/misc/Volume.js +123 -76
  190. package/examples/jsm/misc/VolumeSlice.js +95 -49
  191. package/examples/jsm/modifiers/CurveModifier.js +66 -38
  192. package/examples/jsm/modifiers/CurveModifierGPU.js +42 -19
  193. package/examples/jsm/modifiers/EdgeSplitModifier.js +20 -0
  194. package/examples/jsm/modifiers/SimplifyModifier.js +24 -10
  195. package/examples/jsm/modifiers/TessellateModifier.js +35 -2
  196. package/examples/jsm/objects/GroundedSkybox.js +25 -6
  197. package/examples/jsm/objects/Lensflare.js +94 -2
  198. package/examples/jsm/objects/LensflareMesh.js +64 -10
  199. package/examples/jsm/objects/MarchingCubes.js +90 -5
  200. package/examples/jsm/objects/Reflector.js +76 -2
  201. package/examples/jsm/objects/ReflectorForSSRPass.js +41 -0
  202. package/examples/jsm/objects/Refractor.js +62 -0
  203. package/examples/jsm/objects/ShadowMesh.js +54 -4
  204. package/examples/jsm/objects/Sky.js +106 -16
  205. package/examples/jsm/objects/SkyMesh.js +211 -38
  206. package/examples/jsm/objects/Water.js +49 -8
  207. package/examples/jsm/objects/Water2.js +49 -7
  208. package/examples/jsm/objects/Water2Mesh.js +50 -9
  209. package/examples/jsm/objects/WaterMesh.js +136 -43
  210. package/examples/jsm/physics/AmmoPhysics.js +60 -7
  211. package/examples/jsm/physics/JoltPhysics.js +65 -12
  212. package/examples/jsm/physics/RapierPhysics.js +217 -21
  213. package/examples/jsm/postprocessing/AfterimagePass.js +110 -29
  214. package/examples/jsm/postprocessing/BloomPass.js +128 -26
  215. package/examples/jsm/postprocessing/BokehPass.js +99 -22
  216. package/examples/jsm/postprocessing/ClearPass.js +54 -3
  217. package/examples/jsm/postprocessing/CubeTexturePass.js +82 -21
  218. package/examples/jsm/postprocessing/DotScreenPass.js +59 -10
  219. package/examples/jsm/postprocessing/EffectComposer.js +140 -6
  220. package/examples/jsm/postprocessing/FXAAPass.js +40 -0
  221. package/examples/jsm/postprocessing/FilmPass.js +54 -5
  222. package/examples/jsm/postprocessing/GTAOPass.js +202 -57
  223. package/examples/jsm/postprocessing/GlitchPass.js +86 -34
  224. package/examples/jsm/postprocessing/HalftonePass.js +65 -10
  225. package/examples/jsm/postprocessing/LUTPass.js +38 -8
  226. package/examples/jsm/postprocessing/MaskPass.js +91 -0
  227. package/examples/jsm/postprocessing/OutlinePass.js +272 -135
  228. package/examples/jsm/postprocessing/OutputPass.js +65 -14
  229. package/examples/jsm/postprocessing/Pass.js +100 -4
  230. package/examples/jsm/postprocessing/RenderPass.js +94 -0
  231. package/examples/jsm/postprocessing/RenderPixelatedPass.js +124 -45
  232. package/examples/jsm/postprocessing/RenderTransitionPass.js +120 -21
  233. package/examples/jsm/postprocessing/SAOPass.js +128 -55
  234. package/examples/jsm/postprocessing/SMAAPass.js +106 -75
  235. package/examples/jsm/postprocessing/SSAARenderPass.js +118 -35
  236. package/examples/jsm/postprocessing/SSAOPass.js +173 -60
  237. package/examples/jsm/postprocessing/SSRPass.js +268 -53
  238. package/examples/jsm/postprocessing/SavePass.js +69 -16
  239. package/examples/jsm/postprocessing/ShaderPass.js +65 -7
  240. package/examples/jsm/postprocessing/TAARenderPass.js +79 -24
  241. package/examples/jsm/postprocessing/TexturePass.js +72 -8
  242. package/examples/jsm/postprocessing/UnrealBloomPass.js +168 -59
  243. package/examples/jsm/renderers/CSS2DRenderer.js +98 -5
  244. package/examples/jsm/renderers/CSS3DRenderer.js +111 -7
  245. package/examples/jsm/renderers/Projector.js +288 -32
  246. package/examples/jsm/renderers/SVGRenderer.js +323 -61
  247. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +3 -1
  248. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
  249. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +5 -1
  250. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +12 -5
  251. package/examples/jsm/shaders/AfterimageShader.js +8 -3
  252. package/examples/jsm/shaders/BasicShader.js +8 -1
  253. package/examples/jsm/shaders/BleachBypassShader.js +10 -3
  254. package/examples/jsm/shaders/BlendShader.js +8 -1
  255. package/examples/jsm/shaders/BokehShader.js +9 -3
  256. package/examples/jsm/shaders/BokehShader2.js +11 -4
  257. package/examples/jsm/shaders/BrightnessContrastShader.js +10 -4
  258. package/examples/jsm/shaders/ColorCorrectionShader.js +8 -1
  259. package/examples/jsm/shaders/ColorifyShader.js +8 -1
  260. package/examples/jsm/shaders/ConvolutionShader.js +9 -38
  261. package/examples/jsm/shaders/CopyShader.js +8 -1
  262. package/examples/jsm/shaders/DOFMipMapShader.js +10 -3
  263. package/examples/jsm/shaders/DepthLimitedBlurShader.js +10 -1
  264. package/examples/jsm/shaders/DigitalGlitch.js +10 -7
  265. package/examples/jsm/shaders/DotScreenShader.js +8 -3
  266. package/examples/jsm/shaders/ExposureShader.js +8 -1
  267. package/examples/jsm/shaders/FXAAShader.js +233 -221
  268. package/examples/jsm/shaders/FilmShader.js +13 -0
  269. package/examples/jsm/shaders/FocusShader.js +8 -3
  270. package/examples/jsm/shaders/FreiChenShader.js +10 -3
  271. package/examples/jsm/shaders/GTAOShader.js +55 -45
  272. package/examples/jsm/shaders/GammaCorrectionShader.js +11 -2
  273. package/examples/jsm/shaders/HalftoneShader.js +24 -4
  274. package/examples/jsm/shaders/HorizontalBlurShader.js +12 -3
  275. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +9 -2
  276. package/examples/jsm/shaders/HueSaturationShader.js +10 -3
  277. package/examples/jsm/shaders/KaleidoShader.js +11 -4
  278. package/examples/jsm/shaders/LuminosityHighPassShader.js +8 -4
  279. package/examples/jsm/shaders/LuminosityShader.js +8 -2
  280. package/examples/jsm/shaders/MirrorShader.js +10 -4
  281. package/examples/jsm/shaders/NormalMapShader.js +7 -2
  282. package/examples/jsm/shaders/OutputShader.js +19 -1
  283. package/examples/jsm/shaders/PoissonDenoiseShader.js +30 -17
  284. package/examples/jsm/shaders/RGBShiftShader.js +8 -1
  285. package/examples/jsm/shaders/SAOShader.js +27 -5
  286. package/examples/jsm/shaders/SMAAShader.js +24 -1
  287. package/examples/jsm/shaders/SSAOShader.js +37 -6
  288. package/examples/jsm/shaders/SSRShader.js +32 -6
  289. package/examples/jsm/shaders/SepiaShader.js +8 -3
  290. package/examples/jsm/shaders/SobelOperatorShader.js +9 -3
  291. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +13 -8
  292. package/examples/jsm/shaders/TechnicolorShader.js +10 -4
  293. package/examples/jsm/shaders/ToonShader.js +29 -6
  294. package/examples/jsm/shaders/TriangleBlurShader.js +9 -4
  295. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +19 -6
  296. package/examples/jsm/shaders/VelocityShader.js +8 -1
  297. package/examples/jsm/shaders/VerticalBlurShader.js +9 -2
  298. package/examples/jsm/shaders/VerticalTiltShiftShader.js +8 -1
  299. package/examples/jsm/shaders/VignetteShader.js +8 -3
  300. package/examples/jsm/shaders/VolumeShader.js +11 -2
  301. package/examples/jsm/shaders/WaterRefractionShader.js +11 -0
  302. package/examples/jsm/textures/FlakesTexture.js +14 -0
  303. package/examples/jsm/transpiler/AST.js +436 -31
  304. package/examples/jsm/transpiler/GLSLDecoder.js +380 -135
  305. package/examples/jsm/transpiler/Linker.js +327 -0
  306. package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -1
  307. package/examples/jsm/transpiler/TSLEncoder.js +363 -97
  308. package/examples/jsm/transpiler/Transpiler.js +50 -1
  309. package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
  310. package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
  311. package/examples/jsm/tsl/display/AfterImageNode.js +244 -0
  312. package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
  313. package/examples/jsm/tsl/display/AnamorphicNode.js +282 -0
  314. package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
  315. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +11 -4
  316. package/examples/jsm/tsl/display/BloomNode.js +534 -0
  317. package/examples/jsm/tsl/display/CRT.js +150 -0
  318. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +207 -0
  319. package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
  320. package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
  321. package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
  322. package/examples/jsm/tsl/display/FXAANode.js +365 -0
  323. package/examples/jsm/tsl/display/FilmNode.js +101 -0
  324. package/examples/jsm/tsl/display/GTAONode.js +571 -0
  325. package/examples/jsm/tsl/display/GaussianBlurNode.js +389 -0
  326. package/examples/jsm/tsl/display/GodraysNode.js +624 -0
  327. package/examples/jsm/tsl/display/LensflareNode.js +279 -0
  328. package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
  329. package/examples/jsm/tsl/display/MotionBlur.js +33 -0
  330. package/examples/jsm/tsl/display/OutlineNode.js +762 -0
  331. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
  332. package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
  333. package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
  334. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  335. package/examples/jsm/tsl/display/SMAANode.js +768 -0
  336. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +120 -49
  337. package/examples/jsm/tsl/display/SSGINode.js +642 -0
  338. package/examples/jsm/tsl/display/SSRNode.js +656 -0
  339. package/examples/jsm/tsl/display/SSSNode.js +490 -0
  340. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +9 -2
  341. package/examples/jsm/tsl/display/Shape.js +29 -0
  342. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +61 -19
  343. package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
  344. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +48 -12
  345. package/examples/jsm/tsl/display/TRAANode.js +726 -0
  346. package/examples/jsm/tsl/display/TransitionNode.js +141 -0
  347. package/examples/jsm/tsl/display/boxBlur.js +65 -0
  348. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  349. package/examples/jsm/tsl/display/hashBlur.js +54 -0
  350. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  351. package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
  352. package/examples/jsm/tsl/math/Bayer.js +73 -0
  353. package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
  354. package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
  355. package/examples/jsm/tsl/utils/Raymarching.js +70 -0
  356. package/examples/jsm/utils/BufferGeometryUtils.js +91 -29
  357. package/examples/jsm/utils/CameraUtils.js +15 -6
  358. package/examples/jsm/utils/GeometryCompressionUtils.js +23 -30
  359. package/examples/jsm/utils/GeometryUtils.js +32 -27
  360. package/examples/jsm/utils/LDrawUtils.js +14 -5
  361. package/examples/jsm/utils/SceneOptimizer.js +458 -0
  362. package/examples/jsm/utils/SceneUtils.js +53 -3
  363. package/examples/jsm/utils/ShadowMapViewer.js +72 -33
  364. package/examples/jsm/utils/ShadowMapViewerGPU.js +61 -29
  365. package/examples/jsm/utils/SkeletonUtils.js +48 -0
  366. package/examples/jsm/utils/SortUtils.js +17 -5
  367. package/examples/jsm/utils/UVsDebug.js +12 -4
  368. package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +16 -0
  369. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +20 -2
  370. package/examples/jsm/utils/WorkerPool.js +67 -2
  371. package/examples/jsm/webxr/ARButton.js +19 -0
  372. package/examples/jsm/webxr/OculusHandModel.js +84 -0
  373. package/examples/jsm/webxr/OculusHandPointerModel.js +148 -22
  374. package/examples/jsm/webxr/Text2D.js +20 -6
  375. package/examples/jsm/webxr/VRButton.js +31 -0
  376. package/examples/jsm/webxr/XRButton.js +23 -0
  377. package/examples/jsm/webxr/XRControllerModelFactory.js +94 -3
  378. package/examples/jsm/webxr/XREstimatedLight.js +35 -4
  379. package/examples/jsm/webxr/XRHandMeshModel.js +37 -0
  380. package/examples/jsm/webxr/XRHandModelFactory.js +96 -6
  381. package/examples/jsm/webxr/XRHandPrimitiveModel.js +44 -0
  382. package/examples/jsm/webxr/XRPlanes.js +18 -0
  383. package/package.json +29 -34
  384. package/src/Three.Core.js +198 -0
  385. package/src/Three.Legacy.js +0 -21
  386. package/src/Three.TSL.js +641 -0
  387. package/src/Three.WebGPU.Nodes.js +14 -186
  388. package/src/Three.WebGPU.js +16 -186
  389. package/src/Three.js +2 -197
  390. package/src/animation/AnimationAction.js +263 -31
  391. package/src/animation/AnimationClip.js +162 -7
  392. package/src/animation/AnimationMixer.js +99 -15
  393. package/src/animation/AnimationObjectGroup.js +45 -21
  394. package/src/animation/AnimationUtils.js +163 -24
  395. package/src/animation/KeyframeTrack.js +191 -17
  396. package/src/animation/PropertyBinding.js +91 -16
  397. package/src/animation/PropertyMixer.js +72 -5
  398. package/src/animation/tracks/BooleanKeyframeTrack.js +33 -6
  399. package/src/animation/tracks/ColorKeyframeTrack.js +26 -5
  400. package/src/animation/tracks/NumberKeyframeTrack.js +26 -2
  401. package/src/animation/tracks/QuaternionKeyframeTrack.js +30 -1
  402. package/src/animation/tracks/StringKeyframeTrack.js +33 -2
  403. package/src/animation/tracks/VectorKeyframeTrack.js +26 -2
  404. package/src/audio/Audio.js +386 -8
  405. package/src/audio/AudioAnalyser.js +58 -1
  406. package/src/audio/AudioContext.js +15 -0
  407. package/src/audio/AudioListener.js +94 -13
  408. package/src/audio/PositionalAudio.js +107 -0
  409. package/src/cameras/ArrayCamera.js +37 -0
  410. package/src/cameras/Camera.js +61 -0
  411. package/src/cameras/CubeCamera.js +86 -0
  412. package/src/cameras/OrthographicCamera.js +110 -1
  413. package/src/cameras/PerspectiveCamera.js +174 -35
  414. package/src/cameras/StereoCamera.js +48 -2
  415. package/src/constants.js +1546 -11
  416. package/src/core/BufferAttribute.js +417 -3
  417. package/src/core/BufferGeometry.js +407 -22
  418. package/src/core/Clock.js +69 -8
  419. package/src/core/EventDispatcher.js +52 -8
  420. package/src/core/GLBufferAttribute.js +113 -2
  421. package/src/core/InstancedBufferAttribute.js +29 -0
  422. package/src/core/InstancedBufferGeometry.js +20 -0
  423. package/src/core/InstancedInterleavedBuffer.js +26 -0
  424. package/src/core/InterleavedBuffer.js +141 -7
  425. package/src/core/InterleavedBufferAttribute.js +200 -2
  426. package/src/core/Layers.js +71 -10
  427. package/src/core/Object3D.js +673 -26
  428. package/src/core/Raycaster.js +136 -2
  429. package/src/core/RenderTarget.js +256 -27
  430. package/src/core/RenderTarget3D.js +48 -0
  431. package/src/core/Timer.js +184 -0
  432. package/src/core/Uniform.js +29 -0
  433. package/src/core/UniformsGroup.js +84 -2
  434. package/src/extras/Controls.js +89 -1
  435. package/src/extras/DataUtils.js +50 -9
  436. package/src/extras/Earcut.js +18 -779
  437. package/src/extras/ImageUtils.js +22 -14
  438. package/src/extras/PMREMGenerator.js +316 -67
  439. package/src/extras/ShapeUtils.js +24 -2
  440. package/src/extras/TextureUtils.js +101 -15
  441. package/src/extras/core/Curve.js +156 -55
  442. package/src/extras/core/CurvePath.js +63 -22
  443. package/src/extras/core/Interpolations.js +34 -2
  444. package/src/extras/core/Path.js +134 -1
  445. package/src/extras/core/Shape.js +66 -3
  446. package/src/extras/core/ShapePath.js +80 -4
  447. package/src/extras/curves/ArcCurve.js +22 -0
  448. package/src/extras/curves/CatmullRomCurve3.js +89 -18
  449. package/src/extras/curves/CubicBezierCurve.js +67 -0
  450. package/src/extras/curves/CubicBezierCurve3.js +50 -0
  451. package/src/extras/curves/EllipseCurve.js +102 -0
  452. package/src/extras/curves/LineCurve.js +36 -0
  453. package/src/extras/curves/LineCurve3.js +36 -0
  454. package/src/extras/curves/QuadraticBezierCurve.js +59 -0
  455. package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
  456. package/src/extras/curves/SplineCurve.js +48 -0
  457. package/src/extras/lib/earcut.js +685 -0
  458. package/src/geometries/BoxGeometry.js +39 -0
  459. package/src/geometries/CapsuleGeometry.js +196 -11
  460. package/src/geometries/CircleGeometry.js +41 -0
  461. package/src/geometries/ConeGeometry.js +39 -0
  462. package/src/geometries/CylinderGeometry.js +42 -2
  463. package/src/geometries/DodecahedronGeometry.js +33 -0
  464. package/src/geometries/EdgesGeometry.js +30 -2
  465. package/src/geometries/ExtrudeGeometry.js +148 -52
  466. package/src/geometries/IcosahedronGeometry.js +33 -0
  467. package/src/geometries/LatheGeometry.js +44 -3
  468. package/src/geometries/OctahedronGeometry.js +33 -0
  469. package/src/geometries/PlaneGeometry.js +35 -0
  470. package/src/geometries/PolyhedronGeometry.js +30 -1
  471. package/src/geometries/RingGeometry.js +37 -0
  472. package/src/geometries/ShapeGeometry.js +38 -0
  473. package/src/geometries/SphereGeometry.js +38 -0
  474. package/src/geometries/TetrahedronGeometry.js +33 -0
  475. package/src/geometries/TorusGeometry.js +44 -3
  476. package/src/geometries/TorusKnotGeometry.js +39 -0
  477. package/src/geometries/TubeGeometry.js +50 -0
  478. package/src/geometries/WireframeGeometry.js +32 -0
  479. package/src/helpers/ArrowHelper.js +62 -5
  480. package/src/helpers/AxesHelper.js +28 -0
  481. package/src/helpers/Box3Helper.js +28 -0
  482. package/src/helpers/BoxHelper.js +43 -7
  483. package/src/helpers/CameraHelper.js +103 -27
  484. package/src/helpers/DirectionalLightHelper.js +55 -0
  485. package/src/helpers/GridHelper.js +26 -0
  486. package/src/helpers/HemisphereLightHelper.js +42 -0
  487. package/src/helpers/PlaneHelper.js +33 -0
  488. package/src/helpers/PointLightHelper.js +43 -24
  489. package/src/helpers/PolarGridHelper.js +30 -0
  490. package/src/helpers/SkeletonHelper.js +73 -7
  491. package/src/helpers/SpotLightHelper.js +43 -0
  492. package/src/lights/AmbientLight.js +25 -0
  493. package/src/lights/DirectionalLight.js +70 -0
  494. package/src/lights/DirectionalLightShadow.js +15 -0
  495. package/src/lights/HemisphereLight.js +42 -0
  496. package/src/lights/Light.js +37 -11
  497. package/src/lights/LightProbe.js +37 -9
  498. package/src/lights/LightShadow.js +202 -7
  499. package/src/lights/PointLight.js +74 -0
  500. package/src/lights/PointLightShadow.js +15 -80
  501. package/src/lights/RectAreaLight.js +59 -0
  502. package/src/lights/SpotLight.js +124 -1
  503. package/src/lights/SpotLightShadow.js +33 -3
  504. package/src/lights/webgpu/IESSpotLight.js +22 -0
  505. package/src/lights/webgpu/ProjectorLight.js +46 -0
  506. package/src/loaders/AnimationLoader.js +34 -2
  507. package/src/loaders/AudioLoader.js +34 -2
  508. package/src/loaders/BufferGeometryLoader.js +38 -13
  509. package/src/loaders/Cache.js +75 -2
  510. package/src/loaders/CompressedTextureLoader.js +36 -3
  511. package/src/loaders/CubeTextureLoader.js +45 -0
  512. package/src/loaders/DataTextureLoader.js +45 -4
  513. package/src/loaders/FileLoader.js +85 -5
  514. package/src/loaders/ImageBitmapLoader.js +113 -11
  515. package/src/loaders/ImageLoader.js +85 -8
  516. package/src/loaders/Loader.js +144 -0
  517. package/src/loaders/LoaderUtils.js +18 -36
  518. package/src/loaders/LoadingManager.js +187 -0
  519. package/src/loaders/MaterialLoader.js +62 -3
  520. package/src/loaders/ObjectLoader.js +131 -31
  521. package/src/loaders/TextureLoader.js +33 -0
  522. package/src/loaders/nodes/NodeLoader.js +68 -4
  523. package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
  524. package/src/loaders/nodes/NodeObjectLoader.js +61 -0
  525. package/src/materials/LineBasicMaterial.js +74 -1
  526. package/src/materials/LineDashedMaterial.js +52 -1
  527. package/src/materials/Material.js +502 -8
  528. package/src/materials/MeshBasicMaterial.js +168 -2
  529. package/src/materials/MeshDepthMaterial.js +94 -0
  530. package/src/materials/MeshDistanceMaterial.js +76 -0
  531. package/src/materials/MeshLambertMaterial.js +283 -0
  532. package/src/materials/MeshMatcapMaterial.js +164 -0
  533. package/src/materials/MeshNormalMaterial.js +114 -0
  534. package/src/materials/MeshPhongMaterial.js +298 -0
  535. package/src/materials/MeshPhysicalMaterial.js +296 -4
  536. package/src/materials/MeshStandardMaterial.js +300 -2
  537. package/src/materials/MeshToonMaterial.js +219 -0
  538. package/src/materials/PointsMaterial.js +89 -0
  539. package/src/materials/RawShaderMaterial.js +25 -0
  540. package/src/materials/ShaderMaterial.js +234 -6
  541. package/src/materials/ShadowMaterial.js +54 -0
  542. package/src/materials/SpriteMaterial.js +82 -0
  543. package/src/materials/nodes/Line2NodeMaterial.js +158 -53
  544. package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
  545. package/src/materials/nodes/LineDashedNodeMaterial.js +81 -6
  546. package/src/materials/nodes/MeshBasicNodeMaterial.js +59 -2
  547. package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
  548. package/src/materials/nodes/MeshMatcapNodeMaterial.js +23 -3
  549. package/src/materials/nodes/MeshNormalNodeMaterial.js +27 -4
  550. package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
  551. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +276 -3
  552. package/src/materials/nodes/MeshSSSNodeMaterial.js +98 -10
  553. package/src/materials/nodes/MeshStandardNodeMaterial.js +83 -4
  554. package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
  555. package/src/materials/nodes/NodeMaterial.js +789 -74
  556. package/src/materials/nodes/NodeMaterials.js +0 -1
  557. package/src/materials/nodes/PointsNodeMaterial.js +180 -11
  558. package/src/materials/nodes/ShadowNodeMaterial.js +38 -0
  559. package/src/materials/nodes/SpriteNodeMaterial.js +86 -23
  560. package/src/materials/nodes/VolumeNodeMaterial.js +57 -84
  561. package/src/materials/nodes/manager/NodeMaterialObserver.js +329 -12
  562. package/src/math/Box2.js +177 -0
  563. package/src/math/Box3.js +271 -0
  564. package/src/math/Color.js +355 -11
  565. package/src/math/ColorManagement.js +158 -92
  566. package/src/math/Cylindrical.js +65 -6
  567. package/src/math/Euler.js +139 -5
  568. package/src/math/Frustum.js +108 -9
  569. package/src/math/FrustumArray.js +258 -0
  570. package/src/math/Interpolant.js +87 -8
  571. package/src/math/Line3.js +221 -2
  572. package/src/math/MathUtils.js +408 -20
  573. package/src/math/Matrix2.js +70 -0
  574. package/src/math/Matrix3.js +229 -4
  575. package/src/math/Matrix4.js +489 -94
  576. package/src/math/Plane.js +164 -2
  577. package/src/math/Quaternion.js +322 -90
  578. package/src/math/Ray.js +162 -0
  579. package/src/math/Sphere.js +175 -0
  580. package/src/math/Spherical.js +73 -11
  581. package/src/math/SphericalHarmonics3.js +112 -14
  582. package/src/math/Triangle.js +206 -2
  583. package/src/math/Vector2.js +396 -10
  584. package/src/math/Vector3.js +550 -15
  585. package/src/math/Vector4.js +415 -9
  586. package/src/math/interpolants/BezierInterpolant.js +108 -0
  587. package/src/math/interpolants/CubicInterpolant.js +10 -1
  588. package/src/math/interpolants/DiscreteInterpolant.js +10 -2
  589. package/src/math/interpolants/LinearInterpolant.js +13 -0
  590. package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
  591. package/src/nodes/Nodes.js +91 -88
  592. package/src/nodes/TSL.js +32 -38
  593. package/src/nodes/accessors/AccessorsUtils.js +37 -9
  594. package/src/nodes/accessors/Arrays.js +68 -0
  595. package/src/nodes/accessors/BatchNode.js +49 -14
  596. package/src/nodes/accessors/Bitangent.js +82 -13
  597. package/src/nodes/accessors/BufferAttributeNode.js +269 -8
  598. package/src/nodes/accessors/BufferNode.js +91 -2
  599. package/src/nodes/accessors/BuiltinNode.js +63 -0
  600. package/src/nodes/accessors/Camera.js +400 -10
  601. package/src/nodes/accessors/ClippingNode.js +149 -45
  602. package/src/nodes/accessors/CubeTextureNode.js +137 -7
  603. package/src/nodes/accessors/InstanceNode.js +245 -40
  604. package/src/nodes/accessors/InstancedMeshNode.js +50 -0
  605. package/src/nodes/accessors/Lights.js +88 -0
  606. package/src/nodes/accessors/MaterialNode.js +355 -13
  607. package/src/nodes/accessors/MaterialProperties.js +57 -1
  608. package/src/nodes/accessors/MaterialReferenceNode.js +52 -14
  609. package/src/nodes/accessors/ModelNode.js +117 -5
  610. package/src/nodes/accessors/ModelViewProjectionNode.js +10 -39
  611. package/src/nodes/accessors/MorphNode.js +73 -26
  612. package/src/nodes/accessors/Normal.js +174 -19
  613. package/src/nodes/accessors/Object3DNode.js +146 -12
  614. package/src/nodes/accessors/PointUVNode.js +25 -0
  615. package/src/nodes/accessors/Position.js +119 -7
  616. package/src/nodes/accessors/ReferenceBaseNode.js +190 -4
  617. package/src/nodes/accessors/ReferenceNode.js +223 -8
  618. package/src/nodes/accessors/ReflectVector.js +29 -3
  619. package/src/nodes/accessors/RendererReferenceNode.js +45 -2
  620. package/src/nodes/accessors/SceneProperties.js +53 -0
  621. package/src/nodes/accessors/SkinningNode.js +180 -43
  622. package/src/nodes/accessors/StorageBufferNode.js +278 -26
  623. package/src/nodes/accessors/StorageTextureNode.js +205 -12
  624. package/src/nodes/accessors/Tangent.js +48 -10
  625. package/src/nodes/accessors/TangentUtils.js +46 -0
  626. package/src/nodes/accessors/Texture3DNode.js +104 -11
  627. package/src/nodes/accessors/TextureBicubic.js +31 -4
  628. package/src/nodes/accessors/TextureNode.js +564 -52
  629. package/src/nodes/accessors/TextureSizeNode.js +42 -1
  630. package/src/nodes/accessors/UV.js +9 -1
  631. package/src/nodes/accessors/UniformArrayNode.js +226 -34
  632. package/src/nodes/accessors/UserDataNode.js +46 -2
  633. package/src/nodes/accessors/VelocityNode.js +93 -3
  634. package/src/nodes/accessors/VertexColorNode.js +39 -4
  635. package/src/nodes/code/CodeNode.js +101 -8
  636. package/src/nodes/code/ExpressionNode.js +29 -2
  637. package/src/nodes/code/FunctionCallNode.js +98 -10
  638. package/src/nodes/code/FunctionNode.js +69 -2
  639. package/src/nodes/core/ArrayNode.js +174 -0
  640. package/src/nodes/core/AssignNode.js +80 -9
  641. package/src/nodes/core/AttributeNode.js +47 -4
  642. package/src/nodes/core/BypassNode.js +47 -3
  643. package/src/nodes/core/ConstNode.js +32 -0
  644. package/src/nodes/core/ContextNode.js +220 -14
  645. package/src/nodes/core/IndexNode.js +72 -7
  646. package/src/nodes/core/InputNode.js +50 -1
  647. package/src/nodes/core/InspectorNode.js +128 -0
  648. package/src/nodes/core/IsolateNode.js +133 -0
  649. package/src/nodes/core/LightingModel.js +65 -5
  650. package/src/nodes/core/MRTNode.js +113 -2
  651. package/src/nodes/core/Node.js +595 -36
  652. package/src/nodes/core/NodeAttribute.js +38 -0
  653. package/src/nodes/core/NodeBuilder.js +1840 -121
  654. package/src/nodes/core/NodeCache.js +41 -2
  655. package/src/nodes/core/NodeCode.js +31 -0
  656. package/src/nodes/core/NodeError.js +28 -0
  657. package/src/nodes/core/NodeFrame.js +153 -24
  658. package/src/nodes/core/NodeFunction.js +48 -1
  659. package/src/nodes/core/NodeFunctionInput.js +44 -0
  660. package/src/nodes/core/NodeParser.js +13 -1
  661. package/src/nodes/core/NodeUniform.js +53 -1
  662. package/src/nodes/core/NodeUtils.js +201 -51
  663. package/src/nodes/core/NodeVar.js +47 -1
  664. package/src/nodes/core/NodeVarying.js +47 -1
  665. package/src/nodes/core/OutputStructNode.js +54 -12
  666. package/src/nodes/core/ParameterNode.js +60 -2
  667. package/src/nodes/core/PropertyNode.js +286 -7
  668. package/src/nodes/core/StackNode.js +337 -20
  669. package/src/nodes/core/StackTrace.js +139 -0
  670. package/src/nodes/core/StructNode.js +134 -0
  671. package/src/nodes/core/StructType.js +13 -0
  672. package/src/nodes/core/StructTypeNode.js +126 -6
  673. package/src/nodes/core/SubBuildNode.js +89 -0
  674. package/src/nodes/core/TempNode.js +31 -5
  675. package/src/nodes/core/UniformGroupNode.js +85 -7
  676. package/src/nodes/core/UniformNode.js +163 -16
  677. package/src/nodes/core/VarNode.js +317 -10
  678. package/src/nodes/core/VaryingNode.js +115 -13
  679. package/src/nodes/core/constants.js +40 -0
  680. package/src/nodes/display/BlendModes.js +171 -0
  681. package/src/nodes/display/BumpMapNode.js +38 -2
  682. package/src/nodes/display/ColorAdjustment.js +118 -6
  683. package/src/nodes/display/ColorSpaceFunctions.js +22 -6
  684. package/src/nodes/display/ColorSpaceNode.js +97 -47
  685. package/src/nodes/display/FrontFacingNode.js +64 -7
  686. package/src/nodes/display/NormalMapNode.js +101 -54
  687. package/src/nodes/display/PassNode.js +690 -33
  688. package/src/nodes/display/RenderOutputNode.js +94 -4
  689. package/src/nodes/display/ScreenNode.js +138 -27
  690. package/src/nodes/display/ToneMappingFunctions.js +62 -10
  691. package/src/nodes/display/ToneMappingNode.js +88 -8
  692. package/src/nodes/display/ToonOutlinePassNode.js +84 -4
  693. package/src/nodes/display/ViewportDepthNode.js +227 -10
  694. package/src/nodes/display/ViewportDepthTextureNode.js +39 -5
  695. package/src/nodes/display/ViewportSharedTextureNode.js +35 -1
  696. package/src/nodes/display/ViewportTextureNode.js +171 -7
  697. package/src/nodes/fog/Fog.js +97 -0
  698. package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
  699. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
  700. package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
  701. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  702. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  703. package/src/nodes/functions/BSDF/LTC.js +45 -1
  704. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
  705. package/src/nodes/functions/BasicLightingModel.js +28 -6
  706. package/src/nodes/functions/PhongLightingModel.js +36 -6
  707. package/src/nodes/functions/PhysicalLightingModel.js +336 -91
  708. package/src/nodes/functions/ShadowMaskModel.js +30 -3
  709. package/src/nodes/functions/ToonLightingModel.js +21 -2
  710. package/src/nodes/functions/VolumetricLightingModel.js +183 -0
  711. package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
  712. package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
  713. package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
  714. package/src/nodes/geometry/RangeNode.js +97 -8
  715. package/src/nodes/gpgpu/AtomicFunctionNode.js +198 -23
  716. package/src/nodes/gpgpu/BarrierNode.js +52 -3
  717. package/src/nodes/gpgpu/ComputeBuiltinNode.js +135 -6
  718. package/src/nodes/gpgpu/ComputeNode.js +212 -16
  719. package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
  720. package/src/nodes/gpgpu/WorkgroupInfoNode.js +143 -9
  721. package/src/nodes/lighting/AONode.js +18 -0
  722. package/src/nodes/lighting/AmbientLightNode.js +10 -0
  723. package/src/nodes/lighting/AnalyticLightNode.js +186 -399
  724. package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
  725. package/src/nodes/lighting/BasicLightMapNode.js +17 -0
  726. package/src/nodes/lighting/DirectionalLightNode.js +12 -11
  727. package/src/nodes/lighting/EnvironmentNode.js +59 -19
  728. package/src/nodes/lighting/HemisphereLightNode.js +33 -2
  729. package/src/nodes/lighting/IESSpotLightNode.js +13 -1
  730. package/src/nodes/lighting/IrradianceNode.js +17 -0
  731. package/src/nodes/lighting/LightProbeNode.js +20 -0
  732. package/src/nodes/lighting/LightUtils.js +11 -3
  733. package/src/nodes/lighting/LightingContextNode.js +52 -4
  734. package/src/nodes/lighting/LightingNode.js +15 -6
  735. package/src/nodes/lighting/LightsNode.js +238 -35
  736. package/src/nodes/lighting/PointLightNode.js +60 -25
  737. package/src/nodes/lighting/PointShadowNode.js +325 -0
  738. package/src/nodes/lighting/ProjectorLightNode.js +91 -0
  739. package/src/nodes/lighting/RectAreaLightNode.js +50 -14
  740. package/src/nodes/lighting/ShadowBaseNode.js +81 -0
  741. package/src/nodes/lighting/ShadowFilterNode.js +264 -0
  742. package/src/nodes/lighting/ShadowNode.js +867 -0
  743. package/src/nodes/lighting/SpotLightNode.js +99 -18
  744. package/src/nodes/materialx/MaterialXNodes.js +131 -2
  745. package/src/nodes/materialx/lib/mx_noise.js +166 -2
  746. package/src/nodes/math/BitcastNode.js +156 -0
  747. package/src/nodes/math/BitcountNode.js +433 -0
  748. package/src/nodes/math/ConditionalNode.js +110 -21
  749. package/src/nodes/math/Hash.js +8 -0
  750. package/src/nodes/math/MathNode.js +820 -97
  751. package/src/nodes/math/MathUtils.js +47 -1
  752. package/src/nodes/math/OperatorNode.js +517 -84
  753. package/src/nodes/math/PackFloatNode.js +98 -0
  754. package/src/nodes/math/TriNoise3D.js +17 -7
  755. package/src/nodes/math/UnpackFloatNode.js +96 -0
  756. package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
  757. package/src/nodes/parsers/GLSLNodeParser.js +11 -0
  758. package/src/nodes/pmrem/PMREMNode.js +180 -23
  759. package/src/nodes/pmrem/PMREMUtils.js +114 -5
  760. package/src/nodes/procedural/Checker.js +8 -0
  761. package/src/nodes/shapes/Shapes.js +33 -0
  762. package/src/nodes/tsl/TSLBase.js +10 -4
  763. package/src/nodes/tsl/TSLCore.js +732 -160
  764. package/src/nodes/utils/ArrayElementNode.js +55 -4
  765. package/src/nodes/utils/ConvertNode.js +31 -0
  766. package/src/nodes/utils/CubeMapNode.js +79 -2
  767. package/src/nodes/utils/DebugNode.js +83 -0
  768. package/src/nodes/utils/Discard.js +18 -2
  769. package/src/nodes/utils/EquirectUV.js +27 -0
  770. package/src/nodes/utils/EventNode.js +118 -0
  771. package/src/nodes/utils/FlipNode.js +38 -0
  772. package/src/nodes/utils/FunctionOverloadingNode.js +91 -22
  773. package/src/nodes/utils/JoinNode.js +57 -4
  774. package/src/nodes/utils/LoopNode.js +193 -55
  775. package/src/nodes/utils/MatcapUV.js +22 -0
  776. package/src/nodes/utils/MaxMipLevelNode.js +49 -1
  777. package/src/nodes/utils/MemberNode.js +120 -0
  778. package/src/nodes/utils/Oscillators.js +41 -0
  779. package/src/nodes/utils/Packing.js +30 -1
  780. package/src/nodes/utils/PostProcessingUtils.js +154 -0
  781. package/src/nodes/utils/RTTNode.js +165 -9
  782. package/src/nodes/utils/ReflectorNode.js +407 -21
  783. package/src/nodes/utils/RemapNode.js +81 -2
  784. package/src/nodes/utils/RotateNode.js +41 -1
  785. package/src/nodes/utils/SampleNode.js +91 -0
  786. package/src/nodes/utils/SetNode.js +44 -1
  787. package/src/nodes/utils/SplitNode.js +66 -3
  788. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  789. package/src/nodes/utils/SpriteUtils.js +16 -0
  790. package/src/nodes/utils/StorageArrayElementNode.js +56 -3
  791. package/src/nodes/utils/Timer.js +26 -0
  792. package/src/nodes/utils/TriplanarTextures.js +65 -0
  793. package/src/nodes/utils/UVUtils.js +48 -0
  794. package/src/nodes/utils/ViewportUtils.js +12 -0
  795. package/src/objects/BatchedMesh.js +798 -309
  796. package/src/objects/Bone.js +24 -0
  797. package/src/objects/ClippingGroup.js +68 -0
  798. package/src/objects/Group.js +24 -0
  799. package/src/objects/InstancedMesh.js +131 -2
  800. package/src/objects/LOD.js +99 -5
  801. package/src/objects/Line.js +90 -7
  802. package/src/objects/LineLoop.js +20 -0
  803. package/src/objects/LineSegments.js +20 -1
  804. package/src/objects/Mesh.js +84 -0
  805. package/src/objects/Points.js +60 -0
  806. package/src/objects/Skeleton.js +120 -5
  807. package/src/objects/SkinnedMesh.js +102 -6
  808. package/src/objects/Sprite.js +65 -1
  809. package/src/renderers/WebGL3DRenderTarget.js +26 -0
  810. package/src/renderers/WebGLArrayRenderTarget.js +26 -0
  811. package/src/renderers/WebGLCubeRenderTarget.js +41 -5
  812. package/src/renderers/WebGLRenderTarget.js +19 -0
  813. package/src/renderers/WebGLRenderer.js +1016 -278
  814. package/src/renderers/common/Animation.js +123 -14
  815. package/src/renderers/common/Attributes.js +41 -1
  816. package/src/renderers/common/Backend.js +623 -44
  817. package/src/renderers/common/Background.js +99 -16
  818. package/src/renderers/common/BindGroup.js +37 -2
  819. package/src/renderers/common/Binding.js +46 -0
  820. package/src/renderers/common/Bindings.js +211 -20
  821. package/src/renderers/common/BlendMode.js +143 -0
  822. package/src/renderers/common/Buffer.js +89 -0
  823. package/src/renderers/common/BufferUtils.js +25 -0
  824. package/src/renderers/common/BundleGroup.js +57 -0
  825. package/src/renderers/common/CanvasTarget.js +341 -0
  826. package/src/renderers/common/ChainMap.js +73 -10
  827. package/src/renderers/common/ClippingContext.js +172 -87
  828. package/src/renderers/common/Color4.js +40 -0
  829. package/src/renderers/common/ComputePipeline.js +24 -0
  830. package/src/renderers/common/Constants.js +2 -1
  831. package/src/renderers/common/CubeRenderTarget.js +77 -7
  832. package/src/renderers/common/DataMap.js +37 -1
  833. package/src/renderers/common/Geometries.js +163 -14
  834. package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
  835. package/src/renderers/common/Info.js +81 -36
  836. package/src/renderers/common/InspectorBase.js +146 -0
  837. package/src/renderers/common/Lighting.js +57 -0
  838. package/src/renderers/common/Pipeline.js +22 -0
  839. package/src/renderers/common/Pipelines.js +150 -7
  840. package/src/renderers/common/PostProcessing.js +22 -84
  841. package/src/renderers/common/ProgrammableStage.js +60 -2
  842. package/src/renderers/common/QuadMesh.js +63 -6
  843. package/src/renderers/common/RenderBundle.js +14 -8
  844. package/src/renderers/common/RenderBundles.js +40 -10
  845. package/src/renderers/common/RenderContext.js +219 -4
  846. package/src/renderers/common/RenderContexts.js +54 -17
  847. package/src/renderers/common/RenderList.js +233 -24
  848. package/src/renderers/common/RenderLists.js +46 -6
  849. package/src/renderers/common/RenderObject.js +548 -46
  850. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  851. package/src/renderers/common/RenderObjects.js +133 -15
  852. package/src/renderers/common/RenderPipeline.js +216 -6
  853. package/src/renderers/common/Renderer.js +2155 -332
  854. package/src/renderers/common/RendererUtils.js +200 -0
  855. package/src/renderers/common/SampledTexture.js +99 -39
  856. package/src/renderers/common/Sampler.js +148 -1
  857. package/src/renderers/common/Storage3DTexture.js +100 -0
  858. package/src/renderers/common/StorageArrayTexture.js +84 -0
  859. package/src/renderers/common/StorageBuffer.js +38 -2
  860. package/src/renderers/common/StorageBufferAttribute.js +31 -2
  861. package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
  862. package/src/renderers/common/StorageTexture.js +65 -0
  863. package/src/renderers/common/Textures.js +273 -57
  864. package/src/renderers/common/TimestampQueryPool.js +163 -0
  865. package/src/renderers/common/Uniform.js +233 -3
  866. package/src/renderers/common/UniformBuffer.js +19 -0
  867. package/src/renderers/common/UniformsGroup.js +235 -26
  868. package/src/renderers/common/XRManager.js +1677 -0
  869. package/src/renderers/common/XRRenderTarget.js +91 -0
  870. package/src/renderers/common/extras/PMREMGenerator.js +371 -108
  871. package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
  872. package/src/renderers/common/nodes/NodeLibrary.js +95 -17
  873. package/src/renderers/common/nodes/NodeManager.js +852 -0
  874. package/src/renderers/common/nodes/NodeSampledTexture.js +84 -8
  875. package/src/renderers/common/nodes/NodeSampler.js +41 -1
  876. package/src/renderers/common/nodes/NodeStorageBuffer.js +48 -3
  877. package/src/renderers/common/nodes/NodeUniform.js +285 -2
  878. package/src/renderers/common/nodes/NodeUniformBuffer.js +81 -0
  879. package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
  880. package/src/renderers/shaders/DFGLUTData.js +49 -0
  881. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
  882. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
  883. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
  884. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
  885. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
  886. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  887. package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -12
  888. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  889. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -1
  890. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
  891. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +1 -1
  892. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
  893. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
  894. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
  895. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  896. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +154 -59
  897. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
  898. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  899. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
  900. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
  901. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  902. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
  903. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +1 -1
  904. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +230 -181
  905. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  906. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  907. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
  908. package/src/renderers/shaders/ShaderChunk.js +3 -3
  909. package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
  910. package/src/renderers/shaders/ShaderLib/depth.glsl.js +14 -2
  911. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  912. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
  913. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  914. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
  915. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  916. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  917. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
  918. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  919. package/src/renderers/shaders/ShaderLib.js +7 -5
  920. package/src/renderers/shaders/UniformsLib.js +2 -7
  921. package/src/renderers/shaders/UniformsUtils.js +21 -2
  922. package/src/renderers/webgl/WebGLAttributes.js +4 -0
  923. package/src/renderers/webgl/WebGLBackground.js +30 -5
  924. package/src/renderers/webgl/WebGLBindingStates.js +99 -27
  925. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  926. package/src/renderers/webgl/WebGLCapabilities.js +7 -14
  927. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  928. package/src/renderers/webgl/WebGLExtensions.js +2 -25
  929. package/src/renderers/webgl/WebGLGeometries.js +10 -35
  930. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  931. package/src/renderers/webgl/WebGLInfo.js +3 -1
  932. package/src/renderers/webgl/WebGLLights.js +18 -1
  933. package/src/renderers/webgl/WebGLMaterials.js +12 -0
  934. package/src/renderers/webgl/WebGLObjects.js +3 -1
  935. package/src/renderers/webgl/WebGLOutput.js +267 -0
  936. package/src/renderers/webgl/WebGLProgram.js +87 -148
  937. package/src/renderers/webgl/WebGLPrograms.js +53 -51
  938. package/src/renderers/webgl/WebGLRenderLists.js +15 -0
  939. package/src/renderers/webgl/WebGLShadowMap.js +204 -28
  940. package/src/renderers/webgl/WebGLState.js +88 -56
  941. package/src/renderers/webgl/WebGLTextures.js +293 -59
  942. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  943. package/src/renderers/webgl/WebGLUniformsGroups.js +5 -3
  944. package/src/renderers/webgl/WebGLUtils.js +7 -5
  945. package/src/renderers/webgl-fallback/WebGLBackend.js +1416 -293
  946. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
  947. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +785 -92
  948. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +62 -1
  949. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  950. package/src/renderers/webgl-fallback/utils/WebGLConstants.js +3 -3
  951. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  952. package/src/renderers/webgl-fallback/utils/WebGLState.js +584 -20
  953. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +468 -80
  954. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
  955. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +72 -24
  956. package/src/renderers/webgpu/WebGPUBackend.js +1517 -428
  957. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +31 -4
  958. package/src/renderers/webgpu/WebGPURenderer.js +55 -4
  959. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +23 -16
  960. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +37 -42
  961. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +1335 -241
  962. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +32 -4
  963. package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
  964. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +144 -20
  965. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +460 -116
  966. package/src/renderers/webgpu/utils/WebGPUConstants.js +17 -4
  967. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +283 -69
  968. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +225 -178
  969. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +583 -191
  970. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
  971. package/src/renderers/webgpu/utils/WebGPUUtils.js +150 -28
  972. package/src/renderers/webxr/WebXRController.js +87 -2
  973. package/src/renderers/webxr/WebXRDepthSensing.js +52 -7
  974. package/src/renderers/webxr/WebXRManager.js +275 -15
  975. package/src/scenes/Fog.js +60 -0
  976. package/src/scenes/FogExp2.js +51 -0
  977. package/src/scenes/Scene.js +88 -0
  978. package/src/textures/CanvasTexture.js +28 -0
  979. package/src/textures/CompressedArrayTexture.js +57 -0
  980. package/src/textures/CompressedCubeTexture.js +29 -0
  981. package/src/textures/CompressedTexture.js +64 -6
  982. package/src/textures/CubeDepthTexture.js +76 -0
  983. package/src/textures/CubeTexture.js +52 -4
  984. package/src/textures/Data3DTexture.js +79 -2
  985. package/src/textures/DataArrayTexture.js +93 -0
  986. package/src/textures/DataTexture.js +65 -0
  987. package/src/textures/DepthTexture.js +59 -11
  988. package/src/textures/ExternalTexture.js +56 -0
  989. package/src/textures/FramebufferTexture.js +62 -0
  990. package/src/textures/Source.js +106 -4
  991. package/src/textures/Texture.js +488 -6
  992. package/src/textures/VideoFrameTexture.js +72 -0
  993. package/src/textures/VideoTexture.js +78 -6
  994. package/src/utils.js +322 -3
  995. package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
  996. package/examples/jsm/animation/MMDPhysics.js +0 -1406
  997. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  998. package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
  999. package/examples/jsm/exporters/MMDExporter.js +0 -217
  1000. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
  1001. package/examples/jsm/geometries/ParametricGeometries.js +0 -254
  1002. package/examples/jsm/libs/mmdparser.module.js +0 -11530
  1003. package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +0 -729
  1004. package/examples/jsm/loaders/MMDLoader.js +0 -2295
  1005. package/examples/jsm/loaders/RGBMLoader.js +0 -1081
  1006. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -432
  1007. package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -144
  1008. package/examples/jsm/misc/Timer.js +0 -128
  1009. package/examples/jsm/objects/InstancedPoints.js +0 -21
  1010. package/examples/jsm/shaders/GodRaysShader.js +0 -321
  1011. package/examples/jsm/shaders/MMDToonShader.js +0 -134
  1012. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
  1013. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
  1014. package/src/nodes/accessors/SceneNode.js +0 -55
  1015. package/src/nodes/code/ScriptableNode.js +0 -505
  1016. package/src/nodes/code/ScriptableValueNode.js +0 -170
  1017. package/src/nodes/core/CacheNode.js +0 -50
  1018. package/src/nodes/core/UniformGroup.js +0 -13
  1019. package/src/nodes/display/AfterImageNode.js +0 -158
  1020. package/src/nodes/display/AnaglyphPassNode.js +0 -67
  1021. package/src/nodes/display/AnamorphicNode.js +0 -151
  1022. package/src/nodes/display/BlendMode.js +0 -54
  1023. package/src/nodes/display/BloomNode.js +0 -341
  1024. package/src/nodes/display/DenoiseNode.js +0 -204
  1025. package/src/nodes/display/DepthOfFieldNode.js +0 -124
  1026. package/src/nodes/display/DotScreenNode.js +0 -66
  1027. package/src/nodes/display/FXAANode.js +0 -332
  1028. package/src/nodes/display/FilmNode.js +0 -56
  1029. package/src/nodes/display/GTAONode.js +0 -331
  1030. package/src/nodes/display/GaussianBlurNode.js +0 -213
  1031. package/src/nodes/display/Lut3DNode.js +0 -57
  1032. package/src/nodes/display/MotionBlur.js +0 -25
  1033. package/src/nodes/display/ParallaxBarrierPassNode.js +0 -58
  1034. package/src/nodes/display/PixelationPassNode.js +0 -213
  1035. package/src/nodes/display/PosterizeNode.js +0 -33
  1036. package/src/nodes/display/RGBShiftNode.js +0 -53
  1037. package/src/nodes/display/StereoCompositePassNode.js +0 -110
  1038. package/src/nodes/display/TransitionNode.js +0 -80
  1039. package/src/nodes/fog/FogExp2Node.js +0 -35
  1040. package/src/nodes/fog/FogNode.js +0 -50
  1041. package/src/nodes/fog/FogRangeNode.js +0 -36
  1042. package/src/nodes/functions/BSDF/DFGApprox.js +0 -30
  1043. package/src/nodes/utils/EquirectUVNode.js +0 -36
  1044. package/src/nodes/utils/MatcapUVNode.js +0 -33
  1045. package/src/nodes/utils/OscNode.js +0 -85
  1046. package/src/nodes/utils/SpriteSheetUVNode.js +0 -45
  1047. package/src/nodes/utils/TimerNode.js +0 -97
  1048. package/src/nodes/utils/TriplanarTexturesNode.js +0 -64
  1049. package/src/renderers/common/nodes/Nodes.js +0 -534
  1050. package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
  1051. package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -136
@@ -17,9 +17,7 @@ import {
17
17
  UnsignedInt248Type,
18
18
  UnsignedShort4444Type,
19
19
  UnsignedShort5551Type,
20
- WebGLCoordinateSystem,
21
- DisplayP3ColorSpace,
22
- LinearDisplayP3ColorSpace
20
+ WebGLCoordinateSystem
23
21
  } from '../constants.js';
24
22
  import { Color } from '../math/Color.js';
25
23
  import { Frustum } from '../math/Frustum.js';
@@ -33,14 +31,14 @@ import { WebGLBindingStates } from './webgl/WebGLBindingStates.js';
33
31
  import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer.js';
34
32
  import { WebGLCapabilities } from './webgl/WebGLCapabilities.js';
35
33
  import { WebGLClipping } from './webgl/WebGLClipping.js';
36
- import { WebGLCubeMaps } from './webgl/WebGLCubeMaps.js';
37
- import { WebGLCubeUVMaps } from './webgl/WebGLCubeUVMaps.js';
34
+ import { WebGLEnvironments } from './webgl/WebGLEnvironments.js';
38
35
  import { WebGLExtensions } from './webgl/WebGLExtensions.js';
39
36
  import { WebGLGeometries } from './webgl/WebGLGeometries.js';
40
37
  import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer.js';
41
38
  import { WebGLInfo } from './webgl/WebGLInfo.js';
42
39
  import { WebGLMorphtargets } from './webgl/WebGLMorphtargets.js';
43
40
  import { WebGLObjects } from './webgl/WebGLObjects.js';
41
+ import { WebGLOutput } from './webgl/WebGLOutput.js';
44
42
  import { WebGLPrograms } from './webgl/WebGLPrograms.js';
45
43
  import { WebGLProperties } from './webgl/WebGLProperties.js';
46
44
  import { WebGLRenderLists } from './webgl/WebGLRenderLists.js';
@@ -54,11 +52,22 @@ import { WebGLUtils } from './webgl/WebGLUtils.js';
54
52
  import { WebXRManager } from './webxr/WebXRManager.js';
55
53
  import { WebGLMaterials } from './webgl/WebGLMaterials.js';
56
54
  import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
57
- import { createCanvasElement, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce } from '../utils.js';
55
+ import { createCanvasElement, probeAsync, warnOnce, error, warn, log } from '../utils.js';
58
56
  import { ColorManagement } from '../math/ColorManagement.js';
57
+ import { getDFGLUT } from './shaders/DFGLUTData.js';
59
58
 
59
+ /**
60
+ * This renderer uses WebGL 2 to display scenes.
61
+ *
62
+ * WebGL 1 is not supported since `r163`.
63
+ */
60
64
  class WebGLRenderer {
61
65
 
66
+ /**
67
+ * Constructs a new WebGL renderer.
68
+ *
69
+ * @param {WebGLRenderer~Options} [parameters] - The configuration parameter.
70
+ */
62
71
  constructor( parameters = {} ) {
63
72
 
64
73
  const {
@@ -72,8 +81,17 @@ class WebGLRenderer {
72
81
  preserveDrawingBuffer = false,
73
82
  powerPreference = 'default',
74
83
  failIfMajorPerformanceCaveat = false,
84
+ reversedDepthBuffer = false,
85
+ outputBufferType = UnsignedByteType,
75
86
  } = parameters;
76
87
 
88
+ /**
89
+ * This flag can be used for type testing.
90
+ *
91
+ * @type {boolean}
92
+ * @readonly
93
+ * @default true
94
+ */
77
95
  this.isWebGLRenderer = true;
78
96
 
79
97
  let _alpha;
@@ -94,6 +112,23 @@ class WebGLRenderer {
94
112
 
95
113
  }
96
114
 
115
+ const _outputBufferType = outputBufferType;
116
+
117
+ const INTEGER_FORMATS = new Set( [
118
+ RGBAIntegerFormat,
119
+ RGIntegerFormat,
120
+ RedIntegerFormat
121
+ ] );
122
+
123
+ const UNSIGNED_TYPES = new Set( [
124
+ UnsignedByteType,
125
+ UnsignedIntType,
126
+ UnsignedShortType,
127
+ UnsignedInt248Type,
128
+ UnsignedShort4444Type,
129
+ UnsignedShort5551Type
130
+ ] );
131
+
97
132
  const uintClearColor = new Uint32Array( 4 );
98
133
  const intClearColor = new Int32Array( 4 );
99
134
 
@@ -106,15 +141,42 @@ class WebGLRenderer {
106
141
  const renderListStack = [];
107
142
  const renderStateStack = [];
108
143
 
144
+ // internal render target for non-UnsignedByteType color buffer
145
+
146
+ let output = null;
147
+
109
148
  // public properties
110
149
 
150
+ /**
151
+ * A canvas where the renderer draws its output. This is automatically created by the renderer
152
+ * in the constructor (if not provided already); you just need to add it to your page like so:
153
+ * ```js
154
+ * document.body.appendChild( renderer.domElement );
155
+ * ```
156
+ *
157
+ * @type {HTMLCanvasElement|OffscreenCanvas}
158
+ */
111
159
  this.domElement = canvas;
112
160
 
113
- // Debug configuration container
161
+ /**
162
+ * A object with debug configuration settings.
163
+ *
164
+ * - `checkShaderErrors`: If it is `true`, defines whether material shader programs are
165
+ * checked for errors during compilation and linkage process. It may be useful to disable
166
+ * this check in production for performance gain. It is strongly recommended to keep these
167
+ * checks enabled during development. If the shader does not compile and link, it will not
168
+ * work and associated material will not render.
169
+ * - `onShaderError(gl, program, glVertexShader,glFragmentShader)`: A callback function that
170
+ * can be used for custom error reporting. The callback receives the WebGL context, an instance
171
+ * of WebGLProgram as well two instances of WebGLShader representing the vertex and fragment shader.
172
+ * Assigning a custom function disables the default error reporting.
173
+ *
174
+ * @type {Object}
175
+ */
114
176
  this.debug = {
115
177
 
116
178
  /**
117
- * Enables error checking and reporting when shader programs are being compiled
179
+ * Enables error checking and reporting when shader programs are being compiled.
118
180
  * @type {boolean}
119
181
  */
120
182
  checkShaderErrors: true,
@@ -127,29 +189,105 @@ class WebGLRenderer {
127
189
 
128
190
  // clearing
129
191
 
192
+ /**
193
+ * Whether the renderer should automatically clear its output before rendering a frame or not.
194
+ *
195
+ * @type {boolean}
196
+ * @default true
197
+ */
130
198
  this.autoClear = true;
199
+
200
+ /**
201
+ * If {@link WebGLRenderer#autoClear} set to `true`, whether the renderer should clear
202
+ * the color buffer or not.
203
+ *
204
+ * @type {boolean}
205
+ * @default true
206
+ */
131
207
  this.autoClearColor = true;
208
+
209
+ /**
210
+ * If {@link WebGLRenderer#autoClear} set to `true`, whether the renderer should clear
211
+ * the depth buffer or not.
212
+ *
213
+ * @type {boolean}
214
+ * @default true
215
+ */
132
216
  this.autoClearDepth = true;
217
+
218
+ /**
219
+ * If {@link WebGLRenderer#autoClear} set to `true`, whether the renderer should clear
220
+ * the stencil buffer or not.
221
+ *
222
+ * @type {boolean}
223
+ * @default true
224
+ */
133
225
  this.autoClearStencil = true;
134
226
 
135
227
  // scene graph
136
228
 
229
+ /**
230
+ * Whether the renderer should sort objects or not.
231
+ *
232
+ * Note: Sorting is used to attempt to properly render objects that have some
233
+ * degree of transparency. By definition, sorting objects may not work in all
234
+ * cases. Depending on the needs of application, it may be necessary to turn
235
+ * off sorting and use other methods to deal with transparency rendering e.g.
236
+ * manually determining each object's rendering order.
237
+ *
238
+ * @type {boolean}
239
+ * @default true
240
+ */
137
241
  this.sortObjects = true;
138
242
 
139
243
  // user-defined clipping
140
244
 
245
+ /**
246
+ * User-defined clipping planes specified in world space. These planes apply globally.
247
+ * Points in space whose dot product with the plane is negative are cut away.
248
+ *
249
+ * @type {Array<Plane>}
250
+ */
141
251
  this.clippingPlanes = [];
142
- this.localClippingEnabled = false;
143
-
144
- // physically based shading
145
252
 
146
- this._outputColorSpace = SRGBColorSpace;
253
+ /**
254
+ * Whether the renderer respects object-level clipping planes or not.
255
+ *
256
+ * @type {boolean}
257
+ * @default false
258
+ */
259
+ this.localClippingEnabled = false;
147
260
 
148
261
  // tone mapping
149
262
 
263
+ /**
264
+ * The tone mapping technique of the renderer.
265
+ *
266
+ * @type {(NoToneMapping|LinearToneMapping|ReinhardToneMapping|CineonToneMapping|ACESFilmicToneMapping|CustomToneMapping|AgXToneMapping|NeutralToneMapping)}
267
+ * @default NoToneMapping
268
+ */
150
269
  this.toneMapping = NoToneMapping;
270
+
271
+ /**
272
+ * Exposure level of tone mapping.
273
+ *
274
+ * @type {number}
275
+ * @default 1
276
+ */
151
277
  this.toneMappingExposure = 1.0;
152
278
 
279
+ // transmission
280
+
281
+ /**
282
+ * The normalized resolution scale for the transmission render target, measured in percentage
283
+ * of viewport dimensions. Lowering this value can result in significant performance improvements
284
+ * when using {@link MeshPhysicalMaterial#transmission}.
285
+ *
286
+ * @type {number}
287
+ * @default 1
288
+ */
289
+ this.transmissionResolutionScale = 1.0;
290
+
153
291
  // internal properties
154
292
 
155
293
  const _this = this;
@@ -158,6 +296,8 @@ class WebGLRenderer {
158
296
 
159
297
  // internal state cache
160
298
 
299
+ this._outputColorSpace = SRGBColorSpace;
300
+
161
301
  let _currentActiveCubeFace = 0;
162
302
  let _currentActiveMipmapLevel = 0;
163
303
  let _currentRenderTarget = null;
@@ -196,7 +336,6 @@ class WebGLRenderer {
196
336
 
197
337
  // camera matrices cache
198
338
 
199
- const _currentProjectionMatrix = new Matrix4();
200
339
  const _projScreenMatrix = new Matrix4();
201
340
 
202
341
  const _vector3 = new Vector3();
@@ -266,15 +405,15 @@ class WebGLRenderer {
266
405
 
267
406
  }
268
407
 
269
- } catch ( error ) {
408
+ } catch ( e ) {
270
409
 
271
- console.error( 'THREE.WebGLRenderer: ' + error.message );
272
- throw error;
410
+ error( 'WebGLRenderer: ' + e.message );
411
+ throw e;
273
412
 
274
413
  }
275
414
 
276
415
  let extensions, capabilities, state, info;
277
- let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects;
416
+ let properties, textures, environments, attributes, geometries, objects;
278
417
  let programCache, materials, renderLists, renderStates, clipping, shadowMap;
279
418
 
280
419
  let background, morphtargets, bufferRenderer, indexedBufferRenderer;
@@ -290,26 +429,29 @@ class WebGLRenderer {
290
429
 
291
430
  capabilities = new WebGLCapabilities( _gl, extensions, parameters, utils );
292
431
 
293
- state = new WebGLState( _gl );
432
+ state = new WebGLState( _gl, extensions );
433
+
434
+ if ( capabilities.reversedDepthBuffer && reversedDepthBuffer ) {
435
+
436
+ state.buffers.depth.setReversed( true );
294
437
 
295
- if ( capabilities.reverseDepthBuffer ) state.buffers.depth.setReversed( true );
438
+ }
296
439
 
297
440
  info = new WebGLInfo( _gl );
298
441
  properties = new WebGLProperties();
299
442
  textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
300
- cubemaps = new WebGLCubeMaps( _this );
301
- cubeuvmaps = new WebGLCubeUVMaps( _this );
443
+ environments = new WebGLEnvironments( _this );
302
444
  attributes = new WebGLAttributes( _gl );
303
445
  bindingStates = new WebGLBindingStates( _gl, attributes );
304
446
  geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
305
- objects = new WebGLObjects( _gl, geometries, attributes, info );
447
+ objects = new WebGLObjects( _gl, geometries, attributes, bindingStates, info );
306
448
  morphtargets = new WebGLMorphtargets( _gl, capabilities, textures );
307
449
  clipping = new WebGLClipping( properties );
308
- programCache = new WebGLPrograms( _this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping );
450
+ programCache = new WebGLPrograms( _this, environments, extensions, capabilities, bindingStates, clipping );
309
451
  materials = new WebGLMaterials( _this, properties );
310
452
  renderLists = new WebGLRenderLists();
311
453
  renderStates = new WebGLRenderStates( extensions );
312
- background = new WebGLBackground( _this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha );
454
+ background = new WebGLBackground( _this, environments, state, objects, _alpha, premultipliedAlpha );
313
455
  shadowMap = new WebGLShadowMap( _this, objects, capabilities );
314
456
  uniformsGroups = new WebGLUniformsGroups( _gl, info, capabilities, state );
315
457
 
@@ -318,38 +460,129 @@ class WebGLRenderer {
318
460
 
319
461
  info.programs = programCache.programs;
320
462
 
463
+ /**
464
+ * Holds details about the capabilities of the current rendering context.
465
+ *
466
+ * @name WebGLRenderer#capabilities
467
+ * @type {WebGLRenderer~Capabilities}
468
+ */
321
469
  _this.capabilities = capabilities;
470
+
471
+ /**
472
+ * Provides methods for retrieving and testing WebGL extensions.
473
+ *
474
+ * - `get(extensionName:string)`: Used to check whether a WebGL extension is supported
475
+ * and return the extension object if available.
476
+ * - `has(extensionName:string)`: returns `true` if the extension is supported.
477
+ *
478
+ * @name WebGLRenderer#extensions
479
+ * @type {Object}
480
+ */
322
481
  _this.extensions = extensions;
482
+
483
+ /**
484
+ * Used to track properties of other objects like native WebGL objects.
485
+ *
486
+ * @name WebGLRenderer#properties
487
+ * @type {Object}
488
+ */
323
489
  _this.properties = properties;
490
+
491
+ /**
492
+ * Manages the render lists of the renderer.
493
+ *
494
+ * @name WebGLRenderer#renderLists
495
+ * @type {Object}
496
+ */
324
497
  _this.renderLists = renderLists;
498
+
499
+
500
+
501
+ /**
502
+ * Interface for managing shadows.
503
+ *
504
+ * @name WebGLRenderer#shadowMap
505
+ * @type {WebGLRenderer~ShadowMap}
506
+ */
325
507
  _this.shadowMap = shadowMap;
508
+
509
+ /**
510
+ * Interface for managing the WebGL state.
511
+ *
512
+ * @name WebGLRenderer#state
513
+ * @type {Object}
514
+ */
326
515
  _this.state = state;
516
+
517
+ /**
518
+ * Holds a series of statistical information about the GPU memory
519
+ * and the rendering process. Useful for debugging and monitoring.
520
+ *
521
+ * By default these data are reset at each render call but when having
522
+ * multiple render passes per frame (e.g. when using post processing) it can
523
+ * be preferred to reset with a custom pattern. First, set `autoReset` to
524
+ * `false`.
525
+ * ```js
526
+ * renderer.info.autoReset = false;
527
+ * ```
528
+ * Call `reset()` whenever you have finished to render a single frame.
529
+ * ```js
530
+ * renderer.info.reset();
531
+ * ```
532
+ *
533
+ * @name WebGLRenderer#info
534
+ * @type {WebGLRenderer~Info}
535
+ */
327
536
  _this.info = info;
328
537
 
329
538
  }
330
539
 
331
540
  initGLContext();
332
541
 
542
+ // initialize internal render target for non-UnsignedByteType color buffer
543
+
544
+ if ( _outputBufferType !== UnsignedByteType ) {
545
+
546
+ output = new WebGLOutput( _outputBufferType, canvas.width, canvas.height, depth, stencil );
547
+
548
+ }
549
+
333
550
  // xr
334
551
 
335
552
  const xr = new WebXRManager( _this, _gl );
336
553
 
554
+ /**
555
+ * A reference to the XR manager.
556
+ *
557
+ * @type {WebXRManager}
558
+ */
337
559
  this.xr = xr;
338
560
 
339
- // API
340
-
561
+ /**
562
+ * Returns the rendering context.
563
+ *
564
+ * @return {WebGL2RenderingContext} The rendering context.
565
+ */
341
566
  this.getContext = function () {
342
567
 
343
568
  return _gl;
344
569
 
345
570
  };
346
571
 
572
+ /**
573
+ * Returns the rendering context attributes.
574
+ *
575
+ * @return {WebGLContextAttributes} The rendering context attributes.
576
+ */
347
577
  this.getContextAttributes = function () {
348
578
 
349
579
  return _gl.getContextAttributes();
350
580
 
351
581
  };
352
582
 
583
+ /**
584
+ * Simulates a loss of the WebGL context. This requires support for the `WEBGL_lose_context` extension.
585
+ */
353
586
  this.forceContextLoss = function () {
354
587
 
355
588
  const extension = extensions.get( 'WEBGL_lose_context' );
@@ -357,6 +590,9 @@ class WebGLRenderer {
357
590
 
358
591
  };
359
592
 
593
+ /**
594
+ * Simulates a restore of the WebGL context. This requires support for the `WEBGL_lose_context` extension.
595
+ */
360
596
  this.forceContextRestore = function () {
361
597
 
362
598
  const extension = extensions.get( 'WEBGL_lose_context' );
@@ -364,12 +600,22 @@ class WebGLRenderer {
364
600
 
365
601
  };
366
602
 
603
+ /**
604
+ * Returns the pixel ratio.
605
+ *
606
+ * @return {number} The pixel ratio.
607
+ */
367
608
  this.getPixelRatio = function () {
368
609
 
369
610
  return _pixelRatio;
370
611
 
371
612
  };
372
613
 
614
+ /**
615
+ * Sets the given pixel ratio and resizes the canvas if necessary.
616
+ *
617
+ * @param {number} value - The pixel ratio.
618
+ */
373
619
  this.setPixelRatio = function ( value ) {
374
620
 
375
621
  if ( value === undefined ) return;
@@ -380,17 +626,32 @@ class WebGLRenderer {
380
626
 
381
627
  };
382
628
 
629
+ /**
630
+ * Returns the renderer's size in logical pixels. This method does not honor the pixel ratio.
631
+ *
632
+ * @param {Vector2} target - The method writes the result in this target object.
633
+ * @return {Vector2} The renderer's size in logical pixels.
634
+ */
383
635
  this.getSize = function ( target ) {
384
636
 
385
637
  return target.set( _width, _height );
386
638
 
387
639
  };
388
640
 
641
+ /**
642
+ * Resizes the output canvas to (width, height) with device pixel ratio taken
643
+ * into account, and also sets the viewport to fit that size, starting in (0,
644
+ * 0). Setting `updateStyle` to false prevents any style changes to the output canvas.
645
+ *
646
+ * @param {number} width - The width in logical pixels.
647
+ * @param {number} height - The height in logical pixels.
648
+ * @param {boolean} [updateStyle=true] - Whether to update the `style` attribute of the canvas or not.
649
+ */
389
650
  this.setSize = function ( width, height, updateStyle = true ) {
390
651
 
391
652
  if ( xr.isPresenting ) {
392
653
 
393
- console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
654
+ warn( 'WebGLRenderer: Can\'t change size while VR device is presenting.' );
394
655
  return;
395
656
 
396
657
  }
@@ -408,16 +669,41 @@ class WebGLRenderer {
408
669
 
409
670
  }
410
671
 
672
+ if ( output !== null ) {
673
+
674
+ output.setSize( canvas.width, canvas.height );
675
+
676
+ }
677
+
411
678
  this.setViewport( 0, 0, width, height );
412
679
 
413
680
  };
414
681
 
682
+ /**
683
+ * Returns the drawing buffer size in physical pixels. This method honors the pixel ratio.
684
+ *
685
+ * @param {Vector2} target - The method writes the result in this target object.
686
+ * @return {Vector2} The drawing buffer size.
687
+ */
415
688
  this.getDrawingBufferSize = function ( target ) {
416
689
 
417
690
  return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
418
691
 
419
692
  };
420
693
 
694
+ /**
695
+ * This method allows to define the drawing buffer size by specifying
696
+ * width, height and pixel ratio all at once. The size of the drawing
697
+ * buffer is computed with this formula:
698
+ * ```js
699
+ * size.x = width * pixelRatio;
700
+ * size.y = height * pixelRatio;
701
+ * ```
702
+ *
703
+ * @param {number} width - The width in logical pixels.
704
+ * @param {number} height - The height in logical pixels.
705
+ * @param {number} pixelRatio - The pixel ratio.
706
+ */
421
707
  this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
422
708
 
423
709
  _width = width;
@@ -432,18 +718,72 @@ class WebGLRenderer {
432
718
 
433
719
  };
434
720
 
721
+ /**
722
+ * Sets the post-processing effects to be applied after rendering.
723
+ *
724
+ * @param {Array} effects - An array of post-processing effects.
725
+ */
726
+ this.setEffects = function ( effects ) {
727
+
728
+ if ( _outputBufferType === UnsignedByteType ) {
729
+
730
+ console.error( 'THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.' );
731
+ return;
732
+
733
+ }
734
+
735
+ if ( effects ) {
736
+
737
+ for ( let i = 0; i < effects.length; i ++ ) {
738
+
739
+ if ( effects[ i ].isOutputPass === true ) {
740
+
741
+ console.warn( 'THREE.WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.' );
742
+ break;
743
+
744
+ }
745
+
746
+ }
747
+
748
+ }
749
+
750
+ output.setEffects( effects || [] );
751
+
752
+ };
753
+
754
+ /**
755
+ * Returns the current viewport definition.
756
+ *
757
+ * @param {Vector2} target - The method writes the result in this target object.
758
+ * @return {Vector2} The current viewport definition.
759
+ */
435
760
  this.getCurrentViewport = function ( target ) {
436
761
 
437
762
  return target.copy( _currentViewport );
438
763
 
439
764
  };
440
765
 
766
+ /**
767
+ * Returns the viewport definition.
768
+ *
769
+ * @param {Vector4} target - The method writes the result in this target object.
770
+ * @return {Vector4} The viewport definition.
771
+ */
441
772
  this.getViewport = function ( target ) {
442
773
 
443
774
  return target.copy( _viewport );
444
775
 
445
776
  };
446
777
 
778
+ /**
779
+ * Sets the viewport to render from `(x, y)` to `(x + width, y + height)`.
780
+ *
781
+ * @param {number | Vector4} x - The horizontal coordinate for the lower left corner of the viewport origin in logical pixel unit.
782
+ * Or alternatively a four-component vector specifying all the parameters of the viewport.
783
+ * @param {number} y - The vertical coordinate for the lower left corner of the viewport origin in logical pixel unit.
784
+ * @param {number} width - The width of the viewport in logical pixel unit.
785
+ * @param {number} height - The height of the viewport in logical pixel unit.
786
+ */
447
787
  this.setViewport = function ( x, y, width, height ) {
448
788
 
449
789
  if ( x.isVector4 ) {
@@ -460,12 +800,27 @@ class WebGLRenderer {
460
800
 
461
801
  };
462
802
 
803
+ /**
804
+ * Returns the scissor region.
805
+ *
806
+ * @param {Vector4} target - The method writes the result in this target object.
807
+ * @return {Vector4} The scissor region.
808
+ */
463
809
  this.getScissor = function ( target ) {
464
810
 
465
811
  return target.copy( _scissor );
466
812
 
467
813
  };
468
814
 
815
+ /**
816
+ * Sets the scissor region to render from `(x, y)` to `(x + width, y + height)`.
817
+ *
818
+ * @param {number | Vector4} x - The horizontal coordinate for the lower left corner of the scissor region origin in logical pixel unit.
819
+ * Or alternatively a four-component vector specifying all the parameters of the scissor region.
820
+ * @param {number} y - The vertical coordinate for the lower left corner of the scissor region origin in logical pixel unit.
821
+ * @param {number} width - The width of the scissor region in logical pixel unit.
822
+ * @param {number} height - The height of the scissor region in logical pixel unit.
823
+ */
469
824
  this.setScissor = function ( x, y, width, height ) {
470
825
 
471
826
  if ( x.isVector4 ) {
@@ -482,24 +837,48 @@ class WebGLRenderer {
482
837
 
483
838
  };
484
839
 
840
+ /**
841
+ * Returns `true` if the scissor test is enabled.
842
+ *
843
+ * @return {boolean} Whether the scissor test is enabled or not.
844
+ */
485
845
  this.getScissorTest = function () {
486
846
 
487
847
  return _scissorTest;
488
848
 
489
849
  };
490
850
 
851
+ /**
852
+ * Enable or disable the scissor test. When this is enabled, only the pixels
853
+ * within the defined scissor area will be affected by further renderer
854
+ * actions.
855
+ *
856
+ * @param {boolean} boolean - Whether the scissor test is enabled or not.
857
+ */
491
858
  this.setScissorTest = function ( boolean ) {
492
859
 
493
860
  state.setScissorTest( _scissorTest = boolean );
494
861
 
495
862
  };
496
863
 
864
+ /**
865
+ * Sets a custom opaque sort function for the render lists. Pass `null`
866
+ * to use the default `painterSortStable` function.
867
+ *
868
+ * @param {?Function} method - The opaque sort function.
869
+ */
497
870
  this.setOpaqueSort = function ( method ) {
498
871
 
499
872
  _opaqueSort = method;
500
873
 
501
874
  };
502
875
 
876
+ /**
877
+ * Sets a custom transparent sort function for the render lists. Pass `null`
878
+ * to use the default `reversePainterSortStable` function.
879
+ *
880
+ * @param {?Function} method - The opaque sort function.
881
+ */
503
882
  this.setTransparentSort = function ( method ) {
504
883
 
505
884
  _transparentSort = method;
@@ -508,30 +887,60 @@ class WebGLRenderer {
508
887
 
509
888
  // Clearing
510
889
 
890
+ /**
891
+ * Returns the clear color.
892
+ *
893
+ * @param {Color} target - The method writes the result in this target object.
894
+ * @return {Color} The clear color.
895
+ */
511
896
  this.getClearColor = function ( target ) {
512
897
 
513
898
  return target.copy( background.getClearColor() );
514
899
 
515
900
  };
516
901
 
902
+ /**
903
+ * Sets the clear color and alpha.
904
+ *
905
+ * @param {Color} color - The clear color.
906
+ * @param {number} [alpha=1] - The clear alpha.
907
+ */
517
908
  this.setClearColor = function () {
518
909
 
519
- background.setClearColor.apply( background, arguments );
910
+ background.setClearColor( ...arguments );
520
911
 
521
912
  };
522
913
 
914
+ /**
915
+ * Returns the clear alpha. Ranges within `[0,1]`.
916
+ *
917
+ * @return {number} The clear alpha.
918
+ */
523
919
  this.getClearAlpha = function () {
524
920
 
525
921
  return background.getClearAlpha();
526
922
 
527
923
  };
528
924
 
925
+ /**
926
+ * Sets the clear alpha.
927
+ *
928
+ * @param {number} alpha - The clear alpha.
929
+ */
529
930
  this.setClearAlpha = function () {
530
931
 
531
- background.setClearAlpha.apply( background, arguments );
932
+ background.setClearAlpha( ...arguments );
532
933
 
533
934
  };
534
935
 
936
+ /**
937
+ * Tells the renderer to clear its color, depth or stencil drawing buffer(s).
938
+ * This method initializes the buffers to the current clear color values.
939
+ *
940
+ * @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
941
+ * @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
942
+ * @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
943
+ */
535
944
  this.clear = function ( color = true, depth = true, stencil = true ) {
536
945
 
537
946
  let bits = 0;
@@ -543,9 +952,7 @@ class WebGLRenderer {
543
952
  if ( _currentRenderTarget !== null ) {
544
953
 
545
954
  const targetFormat = _currentRenderTarget.texture.format;
546
- isIntegerFormat = targetFormat === RGBAIntegerFormat ||
547
- targetFormat === RGIntegerFormat ||
548
- targetFormat === RedIntegerFormat;
955
+ isIntegerFormat = INTEGER_FORMATS.has( targetFormat );
549
956
 
550
957
  }
551
958
 
@@ -554,12 +961,7 @@ class WebGLRenderer {
554
961
  if ( isIntegerFormat ) {
555
962
 
556
963
  const targetType = _currentRenderTarget.texture.type;
557
- const isUnsignedType = targetType === UnsignedByteType ||
558
- targetType === UnsignedIntType ||
559
- targetType === UnsignedShortType ||
560
- targetType === UnsignedInt248Type ||
561
- targetType === UnsignedShort4444Type ||
562
- targetType === UnsignedShort5551Type;
964
+ const isUnsignedType = UNSIGNED_TYPES.has( targetType );
563
965
 
564
966
  const clearColor = background.getClearColor();
565
967
  const a = background.getClearAlpha();
@@ -596,7 +998,6 @@ class WebGLRenderer {
596
998
  if ( depth ) {
597
999
 
598
1000
  bits |= _gl.DEPTH_BUFFER_BIT;
599
- _gl.clearDepth( this.capabilities.reverseDepthBuffer ? 0 : 1 );
600
1001
 
601
1002
  }
602
1003
 
@@ -607,41 +1008,56 @@ class WebGLRenderer {
607
1008
 
608
1009
  }
609
1010
 
610
- _gl.clear( bits );
1011
+ if ( bits !== 0 ) {
1012
+
1013
+ _gl.clear( bits );
1014
+
1015
+ }
611
1016
 
612
1017
  };
613
1018
 
1019
+ /**
1020
+ * Clears the color buffer. Equivalent to calling `renderer.clear( true, false, false )`.
1021
+ */
614
1022
  this.clearColor = function () {
615
1023
 
616
1024
  this.clear( true, false, false );
617
1025
 
618
1026
  };
619
1027
 
1028
+ /**
1029
+ * Clears the depth buffer. Equivalent to calling `renderer.clear( false, true, false )`.
1030
+ */
620
1031
  this.clearDepth = function () {
621
1032
 
622
1033
  this.clear( false, true, false );
623
1034
 
624
1035
  };
625
1036
 
1037
+ /**
1038
+ * Clears the stencil buffer. Equivalent to calling `renderer.clear( false, false, true )`.
1039
+ */
626
1040
  this.clearStencil = function () {
627
1041
 
628
1042
  this.clear( false, false, true );
629
1043
 
630
1044
  };
631
1045
 
632
- //
633
-
1046
+ /**
1047
+ * Frees the GPU-related resources allocated by this instance. Call this
1048
+ * method whenever this instance is no longer used in your app.
1049
+ */
634
1050
  this.dispose = function () {
635
1051
 
636
1052
  canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
637
1053
  canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
638
1054
  canvas.removeEventListener( 'webglcontextcreationerror', onContextCreationError, false );
639
1055
 
1056
+ background.dispose();
640
1057
  renderLists.dispose();
641
1058
  renderStates.dispose();
642
1059
  properties.dispose();
643
- cubemaps.dispose();
644
- cubeuvmaps.dispose();
1060
+ environments.dispose();
645
1061
  objects.dispose();
646
1062
  bindingStates.dispose();
647
1063
  uniformsGroups.dispose();
@@ -662,7 +1078,7 @@ class WebGLRenderer {
662
1078
 
663
1079
  event.preventDefault();
664
1080
 
665
- console.log( 'THREE.WebGLRenderer: Context Lost.' );
1081
+ log( 'WebGLRenderer: Context Lost.' );
666
1082
 
667
1083
  _isContextLost = true;
668
1084
 
@@ -670,7 +1086,7 @@ class WebGLRenderer {
670
1086
 
671
1087
  function onContextRestore( /* event */ ) {
672
1088
 
673
- console.log( 'THREE.WebGLRenderer: Context Restored.' );
1089
+ log( 'WebGLRenderer: Context Restored.' );
674
1090
 
675
1091
  _isContextLost = false;
676
1092
 
@@ -692,7 +1108,7 @@ class WebGLRenderer {
692
1108
 
693
1109
  function onContextCreationError( event ) {
694
1110
 
695
- console.error( 'THREE.WebGLRenderer: A WebGL context could not be created. Reason: ', event.statusMessage );
1111
+ error( 'WebGLRenderer: A WebGL context could not be created. Reason: ', event.statusMessage );
696
1112
 
697
1113
  }
698
1114
 
@@ -864,6 +1280,8 @@ class WebGLRenderer {
864
1280
 
865
1281
  if ( object._multiDrawInstances !== null ) {
866
1282
 
1283
+ // @deprecated, r174
1284
+ warnOnce( 'WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.' );
867
1285
  renderer.renderMultiDrawInstances( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances );
868
1286
 
869
1287
  } else {
@@ -933,6 +1351,18 @@ class WebGLRenderer {
933
1351
 
934
1352
  }
935
1353
 
1354
+ /**
1355
+ * Compiles all materials in the scene with the camera. This is useful to precompile shaders
1356
+ * before the first rendering. If you want to add a 3D object to an existing scene, use the third
1357
+ * optional parameter for applying the target scene.
1358
+ *
1359
+ * Note that the (target) scene's lighting and environment must be configured before calling this method.
1360
+ *
1361
+ * @param {Object3D} scene - The scene or another type of 3D object to precompile.
1362
+ * @param {Camera} camera - The camera.
1363
+ * @param {?Scene} [targetScene=null] - The target scene.
1364
+ * @return {Set<Material>} The precompiled materials.
1365
+ */
936
1366
  this.compile = function ( scene, camera, targetScene = null ) {
937
1367
 
938
1368
  if ( targetScene === null ) targetScene = scene;
@@ -1020,8 +1450,7 @@ class WebGLRenderer {
1020
1450
 
1021
1451
  } );
1022
1452
 
1023
- renderStateStack.pop();
1024
- currentRenderState = null;
1453
+ currentRenderState = renderStateStack.pop();
1025
1454
 
1026
1455
  return materials;
1027
1456
 
@@ -1029,6 +1458,18 @@ class WebGLRenderer {
1029
1458
 
1030
1459
  // compileAsync
1031
1460
 
1461
+ /**
1462
+ * Asynchronous version of {@link WebGLRenderer#compile}.
1463
+ *
1464
+ * This method makes use of the `KHR_parallel_shader_compile` WebGL extension. Hence,
1465
+ * it is recommended to use this version of `compile()` whenever possible.
1466
+ *
1467
+ * @async
1468
+ * @param {Object3D} scene - The scene or another type of 3D object to precompile.
1469
+ * @param {Camera} camera - The camera.
1470
+ * @param {?Scene} [targetScene=null] - The target scene.
1471
+ * @return {Promise} A Promise that resolves when the given scene can be rendered without unnecessary stalling due to shader compilation.
1472
+ */
1032
1473
  this.compileAsync = function ( scene, camera, targetScene = null ) {
1033
1474
 
1034
1475
  const materials = this.compile( scene, camera, targetScene );
@@ -1116,6 +1557,13 @@ class WebGLRenderer {
1116
1557
 
1117
1558
  if ( typeof self !== 'undefined' ) animation.setContext( self );
1118
1559
 
1560
+ /**
1561
+ * Applications are advised to always define the animation loop
1562
+ * with this method and not manually with `requestAnimationFrame()`
1563
+ * for best compatibility.
1564
+ *
1565
+ * @param {?onAnimationCallback} callback - The application's animation loop.
1566
+ */
1119
1567
  this.setAnimationLoop = function ( callback ) {
1120
1568
 
1121
1569
  onAnimationFrameCallback = callback;
@@ -1130,17 +1578,37 @@ class WebGLRenderer {
1130
1578
 
1131
1579
  // Rendering
1132
1580
 
1581
+ /**
1582
+ * Renders the given scene (or other type of 3D object) using the given camera.
1583
+ *
1584
+ * The render is done to a previously specified render target set by calling {@link WebGLRenderer#setRenderTarget}
1585
+ * or to the canvas as usual.
1586
+ *
1587
+ * By default render buffers are cleared before rendering but you can prevent
1588
+ * this by setting the property `autoClear` to `false`. If you want to prevent
1589
+ * only certain buffers being cleared you can `autoClearColor`, `autoClearDepth`
1590
+ * or `autoClearStencil` to `false`. To force a clear, use {@link WebGLRenderer#clear}.
1591
+ *
1592
+ * @param {Object3D} scene - The scene to render.
1593
+ * @param {Camera} camera - The camera.
1594
+ */
1133
1595
  this.render = function ( scene, camera ) {
1134
1596
 
1135
1597
  if ( camera !== undefined && camera.isCamera !== true ) {
1136
1598
 
1137
- console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
1599
+ error( 'WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
1138
1600
  return;
1139
1601
 
1140
1602
  }
1141
1603
 
1142
1604
  if ( _isContextLost === true ) return;
1143
1605
 
1606
+ // use internal render target for HalfFloatType color buffer (only when tone mapping is enabled)
1607
+
1608
+ const isXRPresenting = xr.enabled === true && xr.isPresenting === true;
1609
+
1610
+ const useOutput = output !== null && ( _currentRenderTarget === null || isXRPresenting ) && output.begin( _this, _currentRenderTarget );
1611
+
1144
1612
  // update scene graph
1145
1613
 
1146
1614
  if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
@@ -1149,7 +1617,7 @@ class WebGLRenderer {
1149
1617
 
1150
1618
  if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
1151
1619
 
1152
- if ( xr.enabled === true && xr.isPresenting === true ) {
1620
+ if ( xr.enabled === true && xr.isPresenting === true && ( output === null || output.isCompositing() === false ) ) {
1153
1621
 
1154
1622
  if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );
1155
1623
 
@@ -1166,7 +1634,7 @@ class WebGLRenderer {
1166
1634
  renderStateStack.push( currentRenderState );
1167
1635
 
1168
1636
  _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
1169
- _frustum.setFromProjectionMatrix( _projScreenMatrix );
1637
+ _frustum.setFromProjectionMatrix( _projScreenMatrix, WebGLCoordinateSystem, camera.reversedDepth );
1170
1638
 
1171
1639
  _localClippingEnabled = this.localClippingEnabled;
1172
1640
  _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled );
@@ -1221,52 +1689,58 @@ class WebGLRenderer {
1221
1689
 
1222
1690
  if ( this.info.autoReset === true ) this.info.reset();
1223
1691
 
1224
- // render scene
1692
+ // render scene (skip if first effect is a render pass - it will render the scene itself)
1225
1693
 
1226
- const opaqueObjects = currentRenderList.opaque;
1227
- const transmissiveObjects = currentRenderList.transmissive;
1694
+ const skipSceneRender = useOutput && output.hasRenderPass();
1228
1695
 
1229
- currentRenderState.setupLights();
1696
+ if ( skipSceneRender === false ) {
1230
1697
 
1231
- if ( camera.isArrayCamera ) {
1698
+ const opaqueObjects = currentRenderList.opaque;
1699
+ const transmissiveObjects = currentRenderList.transmissive;
1232
1700
 
1233
- const cameras = camera.cameras;
1701
+ currentRenderState.setupLights();
1234
1702
 
1235
- if ( transmissiveObjects.length > 0 ) {
1703
+ if ( camera.isArrayCamera ) {
1236
1704
 
1237
- for ( let i = 0, l = cameras.length; i < l; i ++ ) {
1705
+ const cameras = camera.cameras;
1238
1706
 
1239
- const camera2 = cameras[ i ];
1707
+ if ( transmissiveObjects.length > 0 ) {
1708
+
1709
+ for ( let i = 0, l = cameras.length; i < l; i ++ ) {
1710
+
1711
+ const camera2 = cameras[ i ];
1240
1712
 
1241
- renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera2 );
1713
+ renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera2 );
1714
+
1715
+ }
1242
1716
 
1243
1717
  }
1244
1718
 
1245
- }
1719
+ if ( _renderBackground ) background.render( scene );
1246
1720
 
1247
- if ( _renderBackground ) background.render( scene );
1721
+ for ( let i = 0, l = cameras.length; i < l; i ++ ) {
1248
1722
 
1249
- for ( let i = 0, l = cameras.length; i < l; i ++ ) {
1723
+ const camera2 = cameras[ i ];
1250
1724
 
1251
- const camera2 = cameras[ i ];
1725
+ renderScene( currentRenderList, scene, camera2, camera2.viewport );
1252
1726
 
1253
- renderScene( currentRenderList, scene, camera2, camera2.viewport );
1727
+ }
1254
1728
 
1255
- }
1729
+ } else {
1256
1730
 
1257
- } else {
1731
+ if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );
1258
1732
 
1259
- if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );
1733
+ if ( _renderBackground ) background.render( scene );
1260
1734
 
1261
- if ( _renderBackground ) background.render( scene );
1735
+ renderScene( currentRenderList, scene, camera );
1262
1736
 
1263
- renderScene( currentRenderList, scene, camera );
1737
+ }
1264
1738
 
1265
1739
  }
1266
1740
 
1267
1741
  //
1268
1742
 
1269
- if ( _currentRenderTarget !== null ) {
1743
+ if ( _currentRenderTarget !== null && _currentActiveMipmapLevel === 0 ) {
1270
1744
 
1271
1745
  // resolve multisample renderbuffers to a single-sample texture if necessary
1272
1746
 
@@ -1278,6 +1752,14 @@ class WebGLRenderer {
1278
1752
 
1279
1753
  }
1280
1754
 
1755
+ // copy from internal render target to canvas using fullscreen quad
1756
+
1757
+ if ( useOutput ) {
1758
+
1759
+ output.end( _this );
1760
+
1761
+ }
1762
+
1281
1763
  //
1282
1764
 
1283
1765
  if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
@@ -1432,9 +1914,7 @@ class WebGLRenderer {
1432
1914
 
1433
1915
  function renderScene( currentRenderList, scene, camera, viewport ) {
1434
1916
 
1435
- const opaqueObjects = currentRenderList.opaque;
1436
- const transmissiveObjects = currentRenderList.transmissive;
1437
- const transparentObjects = currentRenderList.transparent;
1917
+ const { opaque: opaqueObjects, transmissive: transmissiveObjects, transparent: transparentObjects } = currentRenderList;
1438
1918
 
1439
1919
  currentRenderState.setupLightsView( camera );
1440
1920
 
@@ -1468,11 +1948,13 @@ class WebGLRenderer {
1468
1948
 
1469
1949
  if ( currentRenderState.state.transmissionRenderTarget[ camera.id ] === undefined ) {
1470
1950
 
1951
+ const hasHalfFloatSupport = extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' );
1952
+
1471
1953
  currentRenderState.state.transmissionRenderTarget[ camera.id ] = new WebGLRenderTarget( 1, 1, {
1472
1954
  generateMipmaps: true,
1473
- type: ( extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' ) ) ? HalfFloatType : UnsignedByteType,
1955
+ type: hasHalfFloatSupport ? HalfFloatType : UnsignedByteType,
1474
1956
  minFilter: LinearMipmapLinearFilter,
1475
- samples: 4,
1957
+ samples: Math.max( 4, capabilities.samples ), // to avoid feedback loops, the transmission render target requires a resolve, see #26177
1476
1958
  stencilBuffer: stencil,
1477
1959
  resolveDepthBuffer: false,
1478
1960
  resolveStencilBuffer: false,
@@ -1494,11 +1976,14 @@ class WebGLRenderer {
1494
1976
  const transmissionRenderTarget = currentRenderState.state.transmissionRenderTarget[ camera.id ];
1495
1977
 
1496
1978
  const activeViewport = camera.viewport || _currentViewport;
1497
- transmissionRenderTarget.setSize( activeViewport.z, activeViewport.w );
1979
+ transmissionRenderTarget.setSize( activeViewport.z * _this.transmissionResolutionScale, activeViewport.w * _this.transmissionResolutionScale );
1498
1980
 
1499
1981
  //
1500
1982
 
1501
1983
  const currentRenderTarget = _this.getRenderTarget();
1984
+ const currentActiveCubeFace = _this.getActiveCubeFace();
1985
+ const currentActiveMipmapLevel = _this.getActiveMipmapLevel();
1986
+
1502
1987
  _this.setRenderTarget( transmissionRenderTarget );
1503
1988
 
1504
1989
  _this.getClearColor( _currentClearColor );
@@ -1536,10 +2021,7 @@ class WebGLRenderer {
1536
2021
 
1537
2022
  const renderItem = transmissiveObjects[ i ];
1538
2023
 
1539
- const object = renderItem.object;
1540
- const geometry = renderItem.geometry;
1541
- const material = renderItem.material;
1542
- const group = renderItem.group;
2024
+ const { object, geometry, material, group } = renderItem;
1543
2025
 
1544
2026
  if ( material.side === DoubleSide && object.layers.test( camera.layers ) ) {
1545
2027
 
@@ -1568,7 +2050,7 @@ class WebGLRenderer {
1568
2050
 
1569
2051
  }
1570
2052
 
1571
- _this.setRenderTarget( currentRenderTarget );
2053
+ _this.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
1572
2054
 
1573
2055
  _this.setClearColor( _currentClearColor, _currentClearAlpha );
1574
2056
 
@@ -1586,10 +2068,14 @@ class WebGLRenderer {
1586
2068
 
1587
2069
  const renderItem = renderList[ i ];
1588
2070
 
1589
- const object = renderItem.object;
1590
- const geometry = renderItem.geometry;
1591
- const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
1592
- const group = renderItem.group;
2071
+ const { object, geometry, group } = renderItem;
2072
+ let material = renderItem.material;
2073
+
2074
+ if ( material.allowOverride === true && overrideMaterial !== null ) {
2075
+
2076
+ material = overrideMaterial;
2077
+
2078
+ }
1593
2079
 
1594
2080
  if ( object.layers.test( camera.layers ) ) {
1595
2081
 
@@ -1650,9 +2136,11 @@ class WebGLRenderer {
1650
2136
 
1651
2137
  // always update environment and fog - changing these trigger an getProgram call, but it's possible that the program doesn't change
1652
2138
 
1653
- materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
2139
+ materialProperties.environment = ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) ? scene.environment : null;
1654
2140
  materialProperties.fog = scene.fog;
1655
- materialProperties.envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || materialProperties.environment );
2141
+
2142
+ const usePMREM = material.isMeshStandardMaterial || ( material.isMeshLambertMaterial && ! material.envMap ) || ( material.isMeshPhongMaterial && ! material.envMap );
2143
+ materialProperties.envMap = environments.get( material.envMap || materialProperties.environment, usePMREM );
1656
2144
  materialProperties.envMapRotation = ( materialProperties.environment !== null && material.envMap === null ) ? scene.environmentRotation : material.envMapRotation;
1657
2145
 
1658
2146
  if ( programs === undefined ) {
@@ -1727,12 +2215,9 @@ class WebGLRenderer {
1727
2215
  uniforms.pointLightShadows.value = lights.state.pointShadow;
1728
2216
  uniforms.hemisphereLights.value = lights.state.hemi;
1729
2217
 
1730
- uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
1731
2218
  uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
1732
- uniforms.spotShadowMap.value = lights.state.spotShadowMap;
1733
2219
  uniforms.spotLightMatrix.value = lights.state.spotLightMatrix;
1734
2220
  uniforms.spotLightMap.value = lights.state.spotLightMap;
1735
- uniforms.pointShadowMap.value = lights.state.pointShadowMap;
1736
2221
  uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
1737
2222
  // TODO (abelnation): add area lights shadow info to uniforms
1738
2223
 
@@ -1788,9 +2273,10 @@ class WebGLRenderer {
1788
2273
  textures.resetTextureUnits();
1789
2274
 
1790
2275
  const fog = scene.fog;
1791
- const environment = material.isMeshStandardMaterial ? scene.environment : null;
2276
+ const environment = ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) ? scene.environment : null;
1792
2277
  const colorSpace = ( _currentRenderTarget === null ) ? _this.outputColorSpace : ( _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace );
1793
- const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
2278
+ const usePMREM = material.isMeshStandardMaterial || ( material.isMeshLambertMaterial && ! material.envMap ) || ( material.isMeshPhongMaterial && ! material.envMap );
2279
+ const envMap = environments.get( material.envMap || environment, usePMREM );
1794
2280
  const vertexAlphas = material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4;
1795
2281
  const vertexTangents = !! geometry.attributes.tangent && ( !! material.normalMap || material.anisotropy > 0 );
1796
2282
  const morphTargets = !! geometry.morphAttributes.position;
@@ -1983,21 +2469,17 @@ class WebGLRenderer {
1983
2469
 
1984
2470
  // common camera uniforms
1985
2471
 
1986
- if ( capabilities.reverseDepthBuffer ) {
2472
+ const reversedDepthBuffer = state.buffers.depth.getReversed();
1987
2473
 
1988
- _currentProjectionMatrix.copy( camera.projectionMatrix );
2474
+ if ( reversedDepthBuffer && camera.reversedDepth !== true ) {
1989
2475
 
1990
- toNormalizedProjectionMatrix( _currentProjectionMatrix );
1991
- toReversedProjectionMatrix( _currentProjectionMatrix );
1992
-
1993
- p_uniforms.setValue( _gl, 'projectionMatrix', _currentProjectionMatrix );
1994
-
1995
- } else {
1996
-
1997
- p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
2476
+ camera._reversedDepth = true;
2477
+ camera.updateProjectionMatrix();
1998
2478
 
1999
2479
  }
2000
2480
 
2481
+ p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
2482
+
2001
2483
  p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
2002
2484
 
2003
2485
  const uCamPos = p_uniforms.map.cameraPosition;
@@ -2043,6 +2525,30 @@ class WebGLRenderer {
2043
2525
 
2044
2526
  }
2045
2527
 
2528
+ // Pre-allocate texture units for shadow samplers before setting data textures
2529
+ if ( materialProperties.needsLights ) {
2530
+
2531
+ // Set shadow map uniforms first to ensure they get the first texture units
2532
+ if ( lights.state.directionalShadowMap.length > 0 ) {
2533
+
2534
+ p_uniforms.setValue( _gl, 'directionalShadowMap', lights.state.directionalShadowMap, textures );
2535
+
2536
+ }
2537
+
2538
+ if ( lights.state.spotShadowMap.length > 0 ) {
2539
+
2540
+ p_uniforms.setValue( _gl, 'spotShadowMap', lights.state.spotShadowMap, textures );
2541
+
2542
+ }
2543
+
2544
+ if ( lights.state.pointShadowMap.length > 0 ) {
2545
+
2546
+ p_uniforms.setValue( _gl, 'pointShadowMap', lights.state.pointShadowMap, textures );
2547
+
2548
+ }
2549
+
2550
+ }
2551
+
2046
2552
  // skinning and morph target uniforms must be set even if material didn't change
2047
2553
  // auto-setting of texture unit for bone and morph texture must go before other textures
2048
2554
  // otherwise textures used for skinning and morphing can take over texture units reserved for other material textures
@@ -2096,19 +2602,16 @@ class WebGLRenderer {
2096
2602
 
2097
2603
  }
2098
2604
 
2099
- // https://github.com/mrdoob/three.js/pull/24467#issuecomment-1209031512
2605
+ if ( ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) && material.envMap === null && scene.environment !== null ) {
2100
2606
 
2101
- if ( material.isMeshGouraudMaterial && material.envMap !== null ) {
2102
-
2103
- m_uniforms.envMap.value = envMap;
2104
-
2105
- m_uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? - 1 : 1;
2607
+ m_uniforms.envMapIntensity.value = scene.environmentIntensity;
2106
2608
 
2107
2609
  }
2108
2610
 
2109
- if ( material.isMeshStandardMaterial && material.envMap === null && scene.environment !== null ) {
2611
+ // Set DFG LUT for physically-based materials
2612
+ if ( m_uniforms.dfgLUT !== undefined ) {
2110
2613
 
2111
- m_uniforms.envMapIntensity.value = scene.environmentIntensity;
2614
+ m_uniforms.dfgLUT.value = getDFGLUT();
2112
2615
 
2113
2616
  }
2114
2617
 
@@ -2211,18 +2714,34 @@ class WebGLRenderer {
2211
2714
 
2212
2715
  }
2213
2716
 
2717
+ /**
2718
+ * Returns the active cube face.
2719
+ *
2720
+ * @return {number} The active cube face.
2721
+ */
2214
2722
  this.getActiveCubeFace = function () {
2215
2723
 
2216
2724
  return _currentActiveCubeFace;
2217
2725
 
2218
2726
  };
2219
2727
 
2728
+ /**
2729
+ * Returns the active mipmap level.
2730
+ *
2731
+ * @return {number} The active mipmap level.
2732
+ */
2220
2733
  this.getActiveMipmapLevel = function () {
2221
2734
 
2222
2735
  return _currentActiveMipmapLevel;
2223
2736
 
2224
2737
  };
2225
2738
 
2739
+ /**
2740
+ * Returns the active render target.
2741
+ *
2742
+ * @return {?WebGLRenderTarget} The active render target. Returns `null` if no render target
2743
+ * is currently set.
2744
+ */
2226
2745
  this.getRenderTarget = function () {
2227
2746
 
2228
2747
  return _currentRenderTarget;
@@ -2231,26 +2750,21 @@ class WebGLRenderer {
2231
2750
 
2232
2751
  this.setRenderTargetTextures = function ( renderTarget, colorTexture, depthTexture ) {
2233
2752
 
2234
- properties.get( renderTarget.texture ).__webglTexture = colorTexture;
2235
- properties.get( renderTarget.depthTexture ).__webglTexture = depthTexture;
2236
-
2237
2753
  const renderTargetProperties = properties.get( renderTarget );
2238
- renderTargetProperties.__hasExternalTextures = true;
2239
2754
 
2240
- renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === undefined;
2241
-
2242
- if ( ! renderTargetProperties.__autoAllocateDepthBuffer ) {
2755
+ renderTargetProperties.__autoAllocateDepthBuffer = renderTarget.resolveDepthBuffer === false;
2756
+ if ( renderTargetProperties.__autoAllocateDepthBuffer === false ) {
2243
2757
 
2244
2758
  // The multisample_render_to_texture extension doesn't work properly if there
2245
2759
  // are midframe flushes and an external depth buffer. Disable use of the extension.
2246
- if ( extensions.has( 'WEBGL_multisampled_render_to_texture' ) === true ) {
2760
+ renderTargetProperties.__useRenderToTexture = false;
2247
2761
 
2248
- console.warn( 'THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided' );
2249
- renderTargetProperties.__useRenderToTexture = false;
2762
+ }
2250
2763
 
2251
- }
2764
+ properties.get( renderTarget.texture ).__webglTexture = colorTexture;
2765
+ properties.get( renderTarget.depthTexture ).__webglTexture = renderTargetProperties.__autoAllocateDepthBuffer ? undefined : depthTexture;
2252
2766
 
2253
- }
2767
+ renderTargetProperties.__hasExternalTextures = true;
2254
2768
 
2255
2769
  };
2256
2770
 
@@ -2262,13 +2776,23 @@ class WebGLRenderer {
2262
2776
 
2263
2777
  };
2264
2778
 
2779
+ const _scratchFrameBuffer = _gl.createFramebuffer();
2780
+
2781
+ /**
2782
+ * Sets the active rendertarget.
2783
+ *
2784
+ * @param {?WebGLRenderTarget} renderTarget - The render target to set. When `null` is given,
2785
+ * the canvas is set as the active render target instead.
2786
+ * @param {number} [activeCubeFace=0] - The active cube face when using a cube render target.
2787
+ * Indicates the z layer to render in to when using 3D or array render targets.
2788
+ * @param {number} [activeMipmapLevel=0] - The active mipmap level.
2789
+ */
2265
2790
  this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
2266
2791
 
2267
2792
  _currentRenderTarget = renderTarget;
2268
2793
  _currentActiveCubeFace = activeCubeFace;
2269
2794
  _currentActiveMipmapLevel = activeMipmapLevel;
2270
2795
 
2271
- let useDefaultFramebuffer = true;
2272
2796
  let framebuffer = null;
2273
2797
  let isCube = false;
2274
2798
  let isRenderTarget3D = false;
@@ -2279,9 +2803,21 @@ class WebGLRenderer {
2279
2803
 
2280
2804
  if ( renderTargetProperties.__useDefaultFramebuffer !== undefined ) {
2281
2805
 
2282
- // We need to make sure to rebind the framebuffer.
2283
- state.bindFramebuffer( _gl.FRAMEBUFFER, null );
2284
- useDefaultFramebuffer = false;
2806
+ // Externally-managed framebuffer (e.g. XR)
2807
+ // Bind to the stored framebuffer (may be null for default, or a WebGLFramebuffer)
2808
+ state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
2809
+
2810
+ _currentViewport.copy( renderTarget.viewport );
2811
+ _currentScissor.copy( renderTarget.scissor );
2812
+ _currentScissorTest = renderTarget.scissorTest;
2813
+
2814
+ state.viewport( _currentViewport );
2815
+ state.scissor( _currentScissor );
2816
+ state.setScissorTest( _currentScissorTest );
2817
+
2818
+ _currentMaterialId = - 1;
2819
+
2820
+ return;
2285
2821
 
2286
2822
  } else if ( renderTargetProperties.__webglFramebuffer === undefined ) {
2287
2823
 
@@ -2370,9 +2906,17 @@ class WebGLRenderer {
2370
2906
 
2371
2907
  }
2372
2908
 
2909
+ // Use a scratch frame buffer if rendering to a mip level to avoid depth buffers
2910
+ // being bound that are different sizes.
2911
+ if ( activeMipmapLevel !== 0 ) {
2912
+
2913
+ framebuffer = _scratchFrameBuffer;
2914
+
2915
+ }
2916
+
2373
2917
  const framebufferBound = state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2374
2918
 
2375
- if ( framebufferBound && useDefaultFramebuffer ) {
2919
+ if ( framebufferBound ) {
2376
2920
 
2377
2921
  state.drawBuffers( renderTarget, framebuffer );
2378
2922
 
@@ -2389,9 +2933,22 @@ class WebGLRenderer {
2389
2933
 
2390
2934
  } else if ( isRenderTarget3D ) {
2391
2935
 
2936
+ const layer = activeCubeFace;
2937
+
2938
+ for ( let i = 0; i < renderTarget.textures.length; i ++ ) {
2939
+
2940
+ const textureProperties = properties.get( renderTarget.textures[ i ] );
2941
+
2942
+ _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, textureProperties.__webglTexture, activeMipmapLevel, layer );
2943
+
2944
+ }
2945
+
2946
+ } else if ( renderTarget !== null && activeMipmapLevel !== 0 ) {
2947
+
2948
+ // Only bind the frame buffer if we are using a scratch frame buffer to render to a mipmap.
2949
+ // If we rebind the texture when using a multi sample buffer then an error about inconsistent samples will be thrown.
2392
2950
  const textureProperties = properties.get( renderTarget.texture );
2393
- const layer = activeCubeFace || 0;
2394
- _gl.framebufferTextureLayer( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel || 0, layer );
2951
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, textureProperties.__webglTexture, activeMipmapLevel );
2395
2952
 
2396
2953
  }
2397
2954
 
@@ -2399,11 +2956,23 @@ class WebGLRenderer {
2399
2956
 
2400
2957
  };
2401
2958
 
2402
- this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
2959
+ /**
2960
+ * Reads the pixel data from the given render target into the given buffer.
2961
+ *
2962
+ * @param {WebGLRenderTarget} renderTarget - The render target to read from.
2963
+ * @param {number} x - The `x` coordinate of the copy region's origin.
2964
+ * @param {number} y - The `y` coordinate of the copy region's origin.
2965
+ * @param {number} width - The width of the copy region.
2966
+ * @param {number} height - The height of the copy region.
2967
+ * @param {TypedArray} buffer - The result buffer.
2968
+ * @param {number} [activeCubeFaceIndex] - The active cube face index.
2969
+ * @param {number} [textureIndex=0] - The texture index of an MRT render target.
2970
+ */
2971
+ this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex, textureIndex = 0 ) {
2403
2972
 
2404
2973
  if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
2405
2974
 
2406
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
2975
+ error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
2407
2976
  return;
2408
2977
 
2409
2978
  }
@@ -2422,20 +2991,24 @@ class WebGLRenderer {
2422
2991
 
2423
2992
  try {
2424
2993
 
2425
- const texture = renderTarget.texture;
2994
+ const texture = renderTarget.textures[ textureIndex ];
2426
2995
  const textureFormat = texture.format;
2427
2996
  const textureType = texture.type;
2428
2997
 
2998
+ // when using MRT, select the correct color buffer for the subsequent read command
2999
+
3000
+ if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
3001
+
2429
3002
  if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
2430
3003
 
2431
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
3004
+ error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
2432
3005
  return;
2433
3006
 
2434
3007
  }
2435
3008
 
2436
3009
  if ( ! capabilities.textureTypeReadable( textureType ) ) {
2437
3010
 
2438
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
3011
+ error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
2439
3012
  return;
2440
3013
 
2441
3014
  }
@@ -2461,7 +3034,23 @@ class WebGLRenderer {
2461
3034
 
2462
3035
  };
2463
3036
 
2464
- this.readRenderTargetPixelsAsync = async function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
3037
+ /**
3038
+ * Asynchronous, non-blocking version of {@link WebGLRenderer#readRenderTargetPixels}.
3039
+ *
3040
+ * It is recommended to use this version of `readRenderTargetPixels()` whenever possible.
3041
+ *
3042
+ * @async
3043
+ * @param {WebGLRenderTarget} renderTarget - The render target to read from.
3044
+ * @param {number} x - The `x` coordinate of the copy region's origin.
3045
+ * @param {number} y - The `y` coordinate of the copy region's origin.
3046
+ * @param {number} width - The width of the copy region.
3047
+ * @param {number} height - The height of the copy region.
3048
+ * @param {TypedArray} buffer - The result buffer.
3049
+ * @param {number} [activeCubeFaceIndex] - The active cube face index.
3050
+ * @param {number} [textureIndex=0] - The texture index of an MRT render target.
3051
+ * @return {Promise<TypedArray>} A Promise that resolves when the read has been finished. The resolve provides the read data as a typed array.
3052
+ */
3053
+ this.readRenderTargetPixelsAsync = async function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex, textureIndex = 0 ) {
2465
3054
 
2466
3055
  if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
2467
3056
 
@@ -2478,31 +3067,37 @@ class WebGLRenderer {
2478
3067
 
2479
3068
  if ( framebuffer ) {
2480
3069
 
2481
- const texture = renderTarget.texture;
2482
- const textureFormat = texture.format;
2483
- const textureType = texture.type;
3070
+ // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
3071
+ if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
2484
3072
 
2485
- if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
3073
+ // set the active frame buffer to the one we want to read
3074
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
2486
3075
 
2487
- throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
3076
+ const texture = renderTarget.textures[ textureIndex ];
3077
+ const textureFormat = texture.format;
3078
+ const textureType = texture.type;
2488
3079
 
2489
- }
3080
+ // when using MRT, select the correct color buffer for the subsequent read command
2490
3081
 
2491
- if ( ! capabilities.textureTypeReadable( textureType ) ) {
3082
+ if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
2492
3083
 
2493
- throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
2494
3084
 
2495
- }
3085
+ if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
2496
3086
 
2497
- // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
2498
- if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
3087
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
2499
3088
 
2500
- // set the active frame buffer to the one we want to read
2501
- state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
3089
+ }
3090
+
3091
+ if ( ! capabilities.textureTypeReadable( textureType ) ) {
3092
+
3093
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
3094
+
3095
+ }
2502
3096
 
2503
3097
  const glBuffer = _gl.createBuffer();
2504
3098
  _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
2505
3099
  _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
3100
+
2506
3101
  _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
2507
3102
 
2508
3103
  // reset the frame buffer to the currently set buffer before waiting
@@ -2534,19 +3129,15 @@ class WebGLRenderer {
2534
3129
 
2535
3130
  };
2536
3131
 
3132
+ /**
3133
+ * Copies pixels from the current bound framebuffer into the given texture.
3134
+ *
3135
+ * @param {FramebufferTexture} texture - The texture.
3136
+ * @param {?Vector2} [position=null] - The start position of the copy operation.
3137
+ * @param {number} [level=0] - The mip level. The default represents the base mip.
3138
+ */
2537
3139
  this.copyFramebufferToTexture = function ( texture, position = null, level = 0 ) {
2538
3140
 
2539
- // support previous signature with position first
2540
- if ( texture.isTexture !== true ) {
2541
-
2542
- // @deprecated, r165
2543
- warnOnce( 'WebGLRenderer: copyFramebufferToTexture function signature has changed.' );
2544
-
2545
- position = arguments[ 0 ] || null;
2546
- texture = arguments[ 1 ];
2547
-
2548
- }
2549
-
2550
3141
  const levelScale = Math.pow( 2, - level );
2551
3142
  const width = Math.floor( texture.image.width * levelScale );
2552
3143
  const height = Math.floor( texture.image.height * levelScale );
@@ -2562,37 +3153,59 @@ class WebGLRenderer {
2562
3153
 
2563
3154
  };
2564
3155
 
2565
- this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
2566
-
2567
- // support previous signature with dstPosition first
2568
- if ( srcTexture.isTexture !== true ) {
2569
-
2570
- // @deprecated, r165
2571
- warnOnce( 'WebGLRenderer: copyTextureToTexture function signature has changed.' );
2572
-
2573
- dstPosition = arguments[ 0 ] || null;
2574
- srcTexture = arguments[ 1 ];
2575
- dstTexture = arguments[ 2 ];
2576
- level = arguments[ 3 ] || 0;
2577
- srcRegion = null;
2578
-
2579
- }
2580
-
2581
- let width, height, minX, minY;
2582
- let dstX, dstY;
3156
+ const _srcFramebuffer = _gl.createFramebuffer();
3157
+ const _dstFramebuffer = _gl.createFramebuffer();
3158
+
3159
+ /**
3160
+ * Copies data of the given source texture into a destination texture.
3161
+ *
3162
+ * When using render target textures as `srcTexture` and `dstTexture`, you must make sure both render targets are initialized
3163
+ * {@link WebGLRenderer#initRenderTarget}.
3164
+ *
3165
+ * @param {Texture} srcTexture - The source texture.
3166
+ * @param {Texture} dstTexture - The destination texture.
3167
+ * @param {?(Box2|Box3)} [srcRegion=null] - A bounding box which describes the source region. Can be two or three-dimensional.
3168
+ * @param {?(Vector2|Vector3)} [dstPosition=null] - A vector that represents the origin of the destination region. Can be two or three-dimensional.
3169
+ * @param {number} [srcLevel=0] - The source mipmap level to copy.
3170
+ * @param {?number} [dstLevel=0] - The destination mipmap level.
3171
+ */
3172
+ this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0 ) {
3173
+
3174
+ // gather the necessary dimensions to copy
3175
+ let width, height, depth, minX, minY, minZ;
3176
+ let dstX, dstY, dstZ;
3177
+ const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ dstLevel ] : srcTexture.image;
2583
3178
  if ( srcRegion !== null ) {
2584
3179
 
2585
3180
  width = srcRegion.max.x - srcRegion.min.x;
2586
3181
  height = srcRegion.max.y - srcRegion.min.y;
3182
+ depth = srcRegion.isBox3 ? srcRegion.max.z - srcRegion.min.z : 1;
2587
3183
  minX = srcRegion.min.x;
2588
3184
  minY = srcRegion.min.y;
3185
+ minZ = srcRegion.isBox3 ? srcRegion.min.z : 0;
2589
3186
 
2590
3187
  } else {
2591
3188
 
2592
- width = srcTexture.image.width;
2593
- height = srcTexture.image.height;
3189
+ const levelScale = Math.pow( 2, - srcLevel );
3190
+ width = Math.floor( image.width * levelScale );
3191
+ height = Math.floor( image.height * levelScale );
3192
+ if ( srcTexture.isDataArrayTexture ) {
3193
+
3194
+ depth = image.depth;
3195
+
3196
+ } else if ( srcTexture.isData3DTexture ) {
3197
+
3198
+ depth = Math.floor( image.depth * levelScale );
3199
+
3200
+ } else {
3201
+
3202
+ depth = 1;
3203
+
3204
+ }
3205
+
2594
3206
  minX = 0;
2595
3207
  minY = 0;
3208
+ minZ = 0;
2596
3209
 
2597
3210
  }
2598
3211
 
@@ -2600,177 +3213,179 @@ class WebGLRenderer {
2600
3213
 
2601
3214
  dstX = dstPosition.x;
2602
3215
  dstY = dstPosition.y;
3216
+ dstZ = dstPosition.z;
2603
3217
 
2604
3218
  } else {
2605
3219
 
2606
3220
  dstX = 0;
2607
3221
  dstY = 0;
3222
+ dstZ = 0;
2608
3223
 
2609
3224
  }
2610
3225
 
3226
+ // Set up the destination target
2611
3227
  const glFormat = utils.convert( dstTexture.format );
2612
3228
  const glType = utils.convert( dstTexture.type );
3229
+ let glTarget;
3230
+
3231
+ if ( dstTexture.isData3DTexture ) {
2613
3232
 
2614
- textures.setTexture2D( dstTexture, 0 );
3233
+ textures.setTexture3D( dstTexture, 0 );
3234
+ glTarget = _gl.TEXTURE_3D;
3235
+
3236
+ } else if ( dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture ) {
3237
+
3238
+ textures.setTexture2DArray( dstTexture, 0 );
3239
+ glTarget = _gl.TEXTURE_2D_ARRAY;
3240
+
3241
+ } else {
3242
+
3243
+ textures.setTexture2D( dstTexture, 0 );
3244
+ glTarget = _gl.TEXTURE_2D;
3245
+
3246
+ }
2615
3247
 
2616
- // As another texture upload may have changed pixelStorei
2617
- // parameters, make sure they are correct for the dstTexture
2618
3248
  _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
2619
3249
  _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
2620
3250
  _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
2621
3251
 
3252
+ // used for copying data from cpu
2622
3253
  const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
2623
3254
  const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
2624
3255
  const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
2625
3256
  const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
2626
3257
  const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
2627
3258
 
2628
- const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
2629
-
2630
3259
  _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
2631
3260
  _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
2632
3261
  _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
2633
3262
  _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
3263
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
2634
3264
 
2635
- if ( srcTexture.isDataTexture ) {
3265
+ // set up the src texture
3266
+ const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture;
3267
+ const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture;
3268
+ if ( srcTexture.isDepthTexture ) {
2636
3269
 
2637
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data );
3270
+ const srcTextureProperties = properties.get( srcTexture );
3271
+ const dstTextureProperties = properties.get( dstTexture );
3272
+ const srcRenderTargetProperties = properties.get( srcTextureProperties.__renderTarget );
3273
+ const dstRenderTargetProperties = properties.get( dstTextureProperties.__renderTarget );
3274
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, srcRenderTargetProperties.__webglFramebuffer );
3275
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, dstRenderTargetProperties.__webglFramebuffer );
2638
3276
 
2639
- } else {
3277
+ for ( let i = 0; i < depth; i ++ ) {
2640
3278
 
2641
- if ( srcTexture.isCompressedTexture ) {
3279
+ // if the source or destination are a 3d target then a layer needs to be bound
3280
+ if ( isSrc3D ) {
2642
3281
 
2643
- _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data );
3282
+ _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( srcTexture ).__webglTexture, srcLevel, minZ + i );
3283
+ _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( dstTexture ).__webglTexture, dstLevel, dstZ + i );
2644
3284
 
2645
- } else {
3285
+ }
2646
3286
 
2647
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image );
3287
+ _gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, _gl.DEPTH_BUFFER_BIT, _gl.NEAREST );
2648
3288
 
2649
3289
  }
2650
3290
 
2651
- }
3291
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );
3292
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null );
2652
3293
 
2653
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
2654
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
2655
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
2656
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
2657
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
3294
+ } else if ( srcLevel !== 0 || srcTexture.isRenderTargetTexture || properties.has( srcTexture ) ) {
2658
3295
 
2659
- // Generate mipmaps only when copying level 0
2660
- if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D );
3296
+ // get the appropriate frame buffers
3297
+ const srcTextureProperties = properties.get( srcTexture );
3298
+ const dstTextureProperties = properties.get( dstTexture );
2661
3299
 
2662
- state.unbindTexture();
3300
+ // bind the frame buffer targets
3301
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, _srcFramebuffer );
3302
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, _dstFramebuffer );
2663
3303
 
2664
- };
3304
+ for ( let i = 0; i < depth; i ++ ) {
2665
3305
 
2666
- this.copyTextureToTexture3D = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
3306
+ // assign the correct layers and mip maps to the frame buffers
3307
+ if ( isSrc3D ) {
2667
3308
 
2668
- // support previous signature with source box first
2669
- if ( srcTexture.isTexture !== true ) {
3309
+ _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, srcTextureProperties.__webglTexture, srcLevel, minZ + i );
2670
3310
 
2671
- // @deprecated, r165
2672
- warnOnce( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' );
3311
+ } else {
2673
3312
 
2674
- srcRegion = arguments[ 0 ] || null;
2675
- dstPosition = arguments[ 1 ] || null;
2676
- srcTexture = arguments[ 2 ];
2677
- dstTexture = arguments[ 3 ];
2678
- level = arguments[ 4 ] || 0;
3313
+ _gl.framebufferTexture2D( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, srcTextureProperties.__webglTexture, srcLevel );
2679
3314
 
2680
- }
3315
+ }
2681
3316
 
2682
- let width, height, depth, minX, minY, minZ;
2683
- let dstX, dstY, dstZ;
2684
- const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
2685
- if ( srcRegion !== null ) {
3317
+ if ( isDst3D ) {
2686
3318
 
2687
- width = srcRegion.max.x - srcRegion.min.x;
2688
- height = srcRegion.max.y - srcRegion.min.y;
2689
- depth = srcRegion.max.z - srcRegion.min.z;
2690
- minX = srcRegion.min.x;
2691
- minY = srcRegion.min.y;
2692
- minZ = srcRegion.min.z;
3319
+ _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, dstTextureProperties.__webglTexture, dstLevel, dstZ + i );
2693
3320
 
2694
- } else {
3321
+ } else {
2695
3322
 
2696
- width = image.width;
2697
- height = image.height;
2698
- depth = image.depth;
2699
- minX = 0;
2700
- minY = 0;
2701
- minZ = 0;
3323
+ _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, dstTextureProperties.__webglTexture, dstLevel );
2702
3324
 
2703
- }
3325
+ }
2704
3326
 
2705
- if ( dstPosition !== null ) {
3327
+ // copy the data using the fastest function that can achieve the copy
3328
+ if ( srcLevel !== 0 ) {
2706
3329
 
2707
- dstX = dstPosition.x;
2708
- dstY = dstPosition.y;
2709
- dstZ = dstPosition.z;
3330
+ _gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, _gl.COLOR_BUFFER_BIT, _gl.NEAREST );
2710
3331
 
2711
- } else {
3332
+ } else if ( isDst3D ) {
2712
3333
 
2713
- dstX = 0;
2714
- dstY = 0;
2715
- dstZ = 0;
3334
+ _gl.copyTexSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ + i, minX, minY, width, height );
2716
3335
 
2717
- }
3336
+ } else {
2718
3337
 
2719
- const glFormat = utils.convert( dstTexture.format );
2720
- const glType = utils.convert( dstTexture.type );
2721
- let glTarget;
3338
+ _gl.copyTexSubImage2D( glTarget, dstLevel, dstX, dstY, minX, minY, width, height );
2722
3339
 
2723
- if ( dstTexture.isData3DTexture ) {
2724
-
2725
- textures.setTexture3D( dstTexture, 0 );
2726
- glTarget = _gl.TEXTURE_3D;
3340
+ }
2727
3341
 
2728
- } else if ( dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture ) {
3342
+ }
2729
3343
 
2730
- textures.setTexture2DArray( dstTexture, 0 );
2731
- glTarget = _gl.TEXTURE_2D_ARRAY;
3344
+ // unbind read, draw buffers
3345
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );
3346
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null );
2732
3347
 
2733
3348
  } else {
2734
3349
 
2735
- console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.' );
2736
- return;
3350
+ if ( isDst3D ) {
2737
3351
 
2738
- }
3352
+ // copy data into the 3d texture
3353
+ if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
2739
3354
 
2740
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
2741
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
2742
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
3355
+ _gl.texSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
2743
3356
 
2744
- const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
2745
- const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
2746
- const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
2747
- const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
2748
- const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
3357
+ } else if ( dstTexture.isCompressedArrayTexture ) {
2749
3358
 
2750
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
2751
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
2752
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
2753
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
2754
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
3359
+ _gl.compressedTexSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
2755
3360
 
2756
- if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
3361
+ } else {
2757
3362
 
2758
- _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
3363
+ _gl.texSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
2759
3364
 
2760
- } else {
3365
+ }
2761
3366
 
2762
- if ( dstTexture.isCompressedArrayTexture ) {
3367
+ } else {
2763
3368
 
2764
- _gl.compressedTexSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
3369
+ // copy data into the 2d texture
3370
+ if ( srcTexture.isDataTexture ) {
2765
3371
 
2766
- } else {
3372
+ _gl.texSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image.data );
2767
3373
 
2768
- _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
3374
+ } else if ( srcTexture.isCompressedTexture ) {
3375
+
3376
+ _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, image.width, image.height, glFormat, image.data );
3377
+
3378
+ } else {
3379
+
3380
+ _gl.texSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image );
3381
+
3382
+ }
2769
3383
 
2770
3384
  }
2771
3385
 
2772
3386
  }
2773
3387
 
3388
+ // reset values
2774
3389
  _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
2775
3390
  _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
2776
3391
  _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
@@ -2778,12 +3393,23 @@ class WebGLRenderer {
2778
3393
  _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
2779
3394
 
2780
3395
  // Generate mipmaps only when copying level 0
2781
- if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget );
3396
+ if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
3397
+
3398
+ _gl.generateMipmap( glTarget );
3399
+
3400
+ }
2782
3401
 
2783
3402
  state.unbindTexture();
2784
3403
 
2785
3404
  };
2786
3405
 
3406
+ /**
3407
+ * Initializes the given WebGLRenderTarget memory. Useful for initializing a render target so data
3408
+ * can be copied into it using {@link WebGLRenderer#copyTextureToTexture} before it has been
3409
+ * rendered to.
3410
+ *
3411
+ * @param {WebGLRenderTarget} target - The render target.
3412
+ */
2787
3413
  this.initRenderTarget = function ( target ) {
2788
3414
 
2789
3415
  if ( properties.get( target ).__webglFramebuffer === undefined ) {
@@ -2794,6 +3420,12 @@ class WebGLRenderer {
2794
3420
 
2795
3421
  };
2796
3422
 
3423
+ /**
3424
+ * Initializes the given texture. Useful for preloading a texture rather than waiting until first
3425
+ * render (which can cause noticeable lags due to decode and GPU upload overhead).
3426
+ *
3427
+ * @param {Texture} texture - The texture.
3428
+ */
2797
3429
  this.initTexture = function ( texture ) {
2798
3430
 
2799
3431
  if ( texture.isCubeTexture ) {
@@ -2818,6 +3450,11 @@ class WebGLRenderer {
2818
3450
 
2819
3451
  };
2820
3452
 
3453
+ /**
3454
+ * Can be used to reset the internal WebGL state. This method is mostly
3455
+ * relevant for applications which share a single WebGL context across
3456
+ * multiple WebGL libraries.
3457
+ */
2821
3458
  this.resetState = function () {
2822
3459
 
2823
3460
  _currentActiveCubeFace = 0;
@@ -2837,12 +3474,27 @@ class WebGLRenderer {
2837
3474
 
2838
3475
  }
2839
3476
 
3477
+ /**
3478
+ * Defines the coordinate system of the renderer.
3479
+ *
3480
+ * In `WebGLRenderer`, the value is always `WebGLCoordinateSystem`.
3481
+ *
3482
+ * @type {WebGLCoordinateSystem|WebGPUCoordinateSystem}
3483
+ * @default WebGLCoordinateSystem
3484
+ * @readonly
3485
+ */
2840
3486
  get coordinateSystem() {
2841
3487
 
2842
3488
  return WebGLCoordinateSystem;
2843
3489
 
2844
3490
  }
2845
3491
 
3492
+ /**
3493
+ * Defines the output color space of the renderer.
3494
+ *
3495
+ * @type {SRGBColorSpace|LinearSRGBColorSpace}
3496
+ * @default SRGBColorSpace
3497
+ */
2846
3498
  get outputColorSpace() {
2847
3499
 
2848
3500
  return this._outputColorSpace;
@@ -2854,12 +3506,98 @@ class WebGLRenderer {
2854
3506
  this._outputColorSpace = colorSpace;
2855
3507
 
2856
3508
  const gl = this.getContext();
2857
- gl.drawingBufferColorSpace = colorSpace === DisplayP3ColorSpace ? 'display-p3' : 'srgb';
2858
- gl.unpackColorSpace = ColorManagement.workingColorSpace === LinearDisplayP3ColorSpace ? 'display-p3' : 'srgb';
3509
+ gl.drawingBufferColorSpace = ColorManagement._getDrawingBufferColorSpace( colorSpace );
3510
+ gl.unpackColorSpace = ColorManagement._getUnpackColorSpace();
2859
3511
 
2860
3512
  }
2861
3513
 
2862
3514
  }
2863
3515
 
3516
+ // JSDoc
3517
+
3518
+ /**
3519
+ * WebGLRenderer options.
3520
+ *
3521
+ * @typedef {Object} WebGLRenderer~Options
3522
+ * @property {HTMLCanvasElement|OffscreenCanvas} [canvas=null] - A canvas element where the renderer draws its output. If not passed in here, a new canvas element will be created by the renderer.
3523
+ * @property {WebGL2RenderingContext} [context=null] - Can be used to attach an existing rendering context to this renderer.
3524
+ * @property {('highp'|'mediump'|'lowp')} [precision='highp'] - The default shader precision. Uses `highp` if supported by the device.
3525
+ * @property {boolean} [alpha=false] - Controls the default clear alpha value. When set to`true`, the value is `0`. Otherwise it's `1`.
3526
+ * @property {boolean} [premultipliedAlpha=true] Whether the renderer will assume colors have premultiplied alpha or not.
3527
+ * @property {boolean} [antialias=false] Whether to use the default MSAA or not.
3528
+ * @property {boolean} [stencil=false] Whether the drawing buffer has a stencil buffer of at least 8 bits or not.
3529
+ * @property {boolean} [preserveDrawingBuffer=false] Whether to preserve the buffer until manually cleared or overwritten.
3530
+ * @property {('default'|'low-power'|'high-performance')} [powerPreference='default'] Provides a hint to the user agent indicating what configuration of GPU is suitable for this WebGL context.
3531
+ * @property {boolean} [failIfMajorPerformanceCaveat=false] Whether the renderer creation will fail upon low performance is detected.
3532
+ * @property {boolean} [depth=true] Whether the drawing buffer has a depth buffer of at least 16 bits.
3533
+ * @property {boolean} [logarithmicDepthBuffer=false] Whether to use a logarithmic depth buffer. It may be necessary to use this if dealing with huge differences in scale in a single scene.
3534
+ * Note that this setting uses `gl_FragDepth` if available which disables the Early Fragment Test optimization and can cause a decrease in performance.
3535
+ * @property {boolean} [reversedDepthBuffer=false] Whether to use a reverse depth buffer. Requires the `EXT_clip_control` extension.
3536
+ * This is a more faster and accurate version than logarithmic depth buffer.
3537
+ * @property {number} [outputBufferType=UnsignedByteType] Defines the type of the output buffer. Use `HalfFloatType` for HDR rendering with tone mapping and post-processing support.
3538
+ **/
3539
+
3540
+ /**
3541
+ * WebGLRenderer Capabilities.
3542
+ *
3543
+ * @typedef {Object} WebGLRenderer~Capabilities
3544
+ * @property {Function} getMaxAnisotropy - Returns the maximum available anisotropy.
3545
+ * @property {Function} getMaxPrecision - Returns the maximum available precision for vertex and fragment shaders.
3546
+ * @property {boolean} logarithmicDepthBuffer - `true` if `logarithmicDepthBuffer` was set to `true` in the constructor.
3547
+ * @property {number} maxAttributes - The number of shader attributes that can be used by the vertex shader.
3548
+ * @property {number} maxCubemapSize - Maximum height * width of cube map textures that a shader can use.
3549
+ * @property {number} maxFragmentUniforms - The number of uniforms that can be used by a fragment shader.
3550
+ * @property {number} maxSamples - Maximum number of samples in context of Multisample anti-aliasing (MSAA).
3551
+ * @property {number} maxTextures - The maximum number of textures that can be used by a shader.
3552
+ * @property {number} maxTextureSize - Maximum height * width of a texture that a shader use.
3553
+ * @property {number} maxVaryings - The number of varying vectors that can used by shaders.
3554
+ * @property {number} maxVertexTextures - The number of textures that can be used in a vertex shader.
3555
+ * @property {number} maxVertexUniforms - The maximum number of uniforms that can be used in a vertex shader.
3556
+ * @property {string} precision - The shader precision currently being used by the renderer.
3557
+ * @property {boolean} reversedDepthBuffer - `true` if `reversedDepthBuffer` was set to `true` in the constructor
3558
+ * and the rendering context supports `EXT_clip_control`.
3559
+ **/
3560
+
3561
+ /**
3562
+ * WebGLRenderer Info Memory
3563
+ *
3564
+ * @typedef {Object} WebGLRenderer~InfoMemory
3565
+ * @property {number} geometries - The number of active geometries.
3566
+ * @property {number} textures - The number of active textures.
3567
+ **/
3568
+
3569
+ /**
3570
+ * WebGLRenderer Info Render
3571
+ *
3572
+ * @typedef {Object} WebGLRenderer~InfoRender
3573
+ * @property {number} frame - The frame ID.
3574
+ * @property {number} calls - The number of draw calls per frame.
3575
+ * @property {number} triangles - The number of rendered triangles primitives per frame.
3576
+ * @property {number} points - The number of rendered points primitives per frame.
3577
+ * @property {number} lines - The number of rendered lines primitives per frame.
3578
+ **/
3579
+
3580
+ /**
3581
+ * WebGLRenderer Info
3582
+ *
3583
+ * @typedef {Object} WebGLRenderer~Info
3584
+ * @property {boolean} [autoReset=true] - Whether to automatically reset the info by the renderer or not.
3585
+ * @property {WebGLRenderer~InfoMemory} memory - Information about allocated objects.
3586
+ * @property {WebGLRenderer~InfoRender} render - Information about rendered objects.
3587
+ * @property {?Array<WebGLProgram>} programs - An array `WebGLProgram`s used for rendering.
3588
+ * @property {Function} reset - Resets the info object for the next frame.
3589
+ **/
3590
+
3591
+ /**
3592
+ * WebGLRenderer Shadow Map.
3593
+ *
3594
+ * @typedef {Object} WebGLRenderer~ShadowMap
3595
+ * @property {boolean} [enabled=false] - If set to `true`, use shadow maps in the scene.
3596
+ * @property {boolean} [autoUpdate=true] - Enables automatic updates to the shadows in the scene.
3597
+ * If you do not require dynamic lighting / shadows, you may set this to `false`.
3598
+ * @property {boolean} [needsUpdate=false] - When set to `true`, shadow maps in the scene
3599
+ * will be updated in the next `render` call.
3600
+ * @property {(BasicShadowMap|PCFShadowMap|VSMShadowMap)} [type=PCFShadowMap] - Defines the shadow map type.
3601
+ **/
2864
3602
 
2865
3603
  export { WebGLRenderer };