super-three 0.181.0 → 0.184.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (539) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -4
  3. package/build/three.cjs +13152 -11354
  4. package/build/three.core.js +12319 -11539
  5. package/build/three.core.min.js +2 -2
  6. package/build/three.module.js +1808 -781
  7. package/build/three.module.min.js +2 -2
  8. package/build/three.tsl.js +27 -13
  9. package/build/three.tsl.min.js +2 -2
  10. package/build/three.webgpu.js +10523 -6263
  11. package/build/three.webgpu.min.js +2 -2
  12. package/build/three.webgpu.nodes.js +10484 -6262
  13. package/build/three.webgpu.nodes.min.js +2 -2
  14. package/examples/jsm/Addons.js +11 -3
  15. package/examples/jsm/animation/CCDIKSolver.js +7 -3
  16. package/examples/jsm/controls/ArcballControls.js +7 -4
  17. package/examples/jsm/controls/DragControls.js +2 -2
  18. package/examples/jsm/controls/FirstPersonControls.js +58 -54
  19. package/examples/jsm/controls/FlyControls.js +4 -0
  20. package/examples/jsm/controls/MapControls.js +55 -1
  21. package/examples/jsm/controls/OrbitControls.js +111 -8
  22. package/examples/jsm/controls/TrackballControls.js +8 -8
  23. package/examples/jsm/controls/TransformControls.js +34 -2
  24. package/examples/jsm/csm/CSM.js +2 -1
  25. package/examples/jsm/csm/CSMShadowNode.js +6 -2
  26. package/examples/jsm/effects/AnaglyphEffect.js +102 -7
  27. package/examples/jsm/environments/ColorEnvironment.js +59 -0
  28. package/examples/jsm/environments/RoomEnvironment.js +3 -0
  29. package/examples/jsm/exporters/EXRExporter.js +1 -1
  30. package/examples/jsm/exporters/GLTFExporter.js +152 -9
  31. package/examples/jsm/exporters/USDZExporter.js +22 -3
  32. package/examples/jsm/geometries/DecalGeometry.js +1 -1
  33. package/examples/jsm/geometries/TextGeometry.js +18 -0
  34. package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
  35. package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
  36. package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
  37. package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
  38. package/examples/jsm/helpers/ViewHelper.js +67 -8
  39. package/examples/jsm/inspector/Extension.js +13 -0
  40. package/examples/jsm/inspector/Inspector.js +203 -88
  41. package/examples/jsm/inspector/RendererInspector.js +14 -4
  42. package/examples/jsm/inspector/extensions/extensions.json +6 -0
  43. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
  44. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
  45. package/examples/jsm/inspector/tabs/Console.js +41 -7
  46. package/examples/jsm/inspector/tabs/Memory.js +128 -0
  47. package/examples/jsm/inspector/tabs/Parameters.js +51 -3
  48. package/examples/jsm/inspector/tabs/Performance.js +4 -4
  49. package/examples/jsm/inspector/tabs/Settings.js +264 -0
  50. package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
  51. package/examples/jsm/inspector/tabs/Viewer.js +107 -5
  52. package/examples/jsm/inspector/ui/Graph.js +2 -2
  53. package/examples/jsm/inspector/ui/List.js +1 -1
  54. package/examples/jsm/inspector/ui/Profiler.js +1936 -34
  55. package/examples/jsm/inspector/ui/Style.js +1044 -31
  56. package/examples/jsm/inspector/ui/Tab.js +222 -3
  57. package/examples/jsm/inspector/ui/Values.js +55 -2
  58. package/examples/jsm/inspector/ui/utils.js +13 -0
  59. package/examples/jsm/interaction/InteractionManager.js +226 -0
  60. package/examples/jsm/libs/meshopt_decoder.module.js +9 -8
  61. package/examples/jsm/lighting/DynamicLighting.js +82 -0
  62. package/examples/jsm/lighting/LightProbeGrid.js +651 -0
  63. package/examples/jsm/lines/LineMaterial.js +7 -1
  64. package/examples/jsm/loaders/3DMLoader.js +5 -4
  65. package/examples/jsm/loaders/3MFLoader.js +2 -2
  66. package/examples/jsm/loaders/AMFLoader.js +2 -2
  67. package/examples/jsm/loaders/ColladaLoader.js +24 -4026
  68. package/examples/jsm/loaders/DRACOLoader.js +5 -5
  69. package/examples/jsm/loaders/EXRLoader.js +687 -48
  70. package/examples/jsm/loaders/FBXLoader.js +235 -37
  71. package/examples/jsm/loaders/GCodeLoader.js +34 -8
  72. package/examples/jsm/loaders/GLTFLoader.js +146 -178
  73. package/examples/jsm/loaders/HDRLoader.js +1 -2
  74. package/examples/jsm/loaders/KMZLoader.js +5 -5
  75. package/examples/jsm/loaders/KTX2Loader.js +27 -5
  76. package/examples/jsm/loaders/LDrawLoader.js +41 -50
  77. package/examples/jsm/loaders/LWOLoader.js +7 -39
  78. package/examples/jsm/loaders/NRRDLoader.js +2 -2
  79. package/examples/jsm/loaders/PCDLoader.js +4 -2
  80. package/examples/jsm/loaders/SVGLoader.js +2 -2
  81. package/examples/jsm/loaders/TDSLoader.js +0 -2
  82. package/examples/jsm/loaders/TGALoader.js +0 -2
  83. package/examples/jsm/loaders/USDLoader.js +100 -40
  84. package/examples/jsm/loaders/UltraHDRLoader.js +285 -160
  85. package/examples/jsm/loaders/VOXLoader.js +660 -117
  86. package/examples/jsm/loaders/VRMLLoader.js +79 -2
  87. package/examples/jsm/loaders/VTKLoader.js +42 -25
  88. package/examples/jsm/loaders/collada/ColladaComposer.js +3044 -0
  89. package/examples/jsm/loaders/collada/ColladaParser.js +1977 -0
  90. package/examples/jsm/loaders/usd/USDAParser.js +450 -363
  91. package/examples/jsm/loaders/usd/USDCParser.js +1867 -6
  92. package/examples/jsm/loaders/usd/USDComposer.js +4594 -0
  93. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
  94. package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
  95. package/examples/jsm/math/Octree.js +131 -1
  96. package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
  97. package/examples/jsm/misc/RollerCoaster.js +42 -4
  98. package/examples/jsm/misc/Volume.js +0 -1
  99. package/examples/jsm/misc/VolumeSlice.js +0 -1
  100. package/examples/jsm/modifiers/TessellateModifier.js +1 -1
  101. package/examples/jsm/objects/LensflareMesh.js +1 -1
  102. package/examples/jsm/objects/Reflector.js +73 -25
  103. package/examples/jsm/objects/Sky.js +90 -6
  104. package/examples/jsm/objects/SkyMesh.js +150 -16
  105. package/examples/jsm/objects/Water.js +4 -3
  106. package/examples/jsm/objects/Water2.js +5 -3
  107. package/examples/jsm/objects/WaterMesh.js +5 -7
  108. package/examples/jsm/physics/AmmoPhysics.js +12 -7
  109. package/examples/jsm/physics/JoltPhysics.js +10 -6
  110. package/examples/jsm/physics/RapierPhysics.js +9 -5
  111. package/examples/jsm/postprocessing/EffectComposer.js +7 -5
  112. package/examples/jsm/postprocessing/OutputPass.js +9 -0
  113. package/examples/jsm/postprocessing/RenderPass.js +10 -0
  114. package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
  115. package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
  116. package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
  117. package/examples/jsm/renderers/Projector.js +246 -28
  118. package/examples/jsm/renderers/SVGRenderer.js +174 -60
  119. package/examples/jsm/shaders/GTAOShader.js +19 -6
  120. package/examples/jsm/shaders/HalftoneShader.js +12 -1
  121. package/examples/jsm/shaders/PoissonDenoiseShader.js +6 -2
  122. package/examples/jsm/shaders/SAOShader.js +17 -4
  123. package/examples/jsm/shaders/SSAOShader.js +11 -1
  124. package/examples/jsm/shaders/SSRShader.js +6 -5
  125. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
  126. package/examples/jsm/shaders/VignetteShader.js +1 -1
  127. package/examples/jsm/transpiler/AST.js +44 -0
  128. package/examples/jsm/transpiler/GLSLDecoder.js +63 -6
  129. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
  130. package/examples/jsm/transpiler/TSLEncoder.js +46 -3
  131. package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
  132. package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
  133. package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
  134. package/examples/jsm/tsl/display/AfterImageNode.js +11 -1
  135. package/examples/jsm/tsl/display/AnaglyphPassNode.js +458 -16
  136. package/examples/jsm/tsl/display/AnamorphicNode.js +12 -1
  137. package/examples/jsm/tsl/display/BilateralBlurNode.js +374 -0
  138. package/examples/jsm/tsl/display/BloomNode.js +16 -6
  139. package/examples/jsm/tsl/display/CRT.js +150 -0
  140. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
  141. package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
  142. package/examples/jsm/tsl/display/DepthOfFieldNode.js +1 -1
  143. package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
  144. package/examples/jsm/tsl/display/FSR1Node.js +477 -0
  145. package/examples/jsm/tsl/display/FXAANode.js +2 -2
  146. package/examples/jsm/tsl/display/GTAONode.js +6 -4
  147. package/examples/jsm/tsl/display/GaussianBlurNode.js +21 -2
  148. package/examples/jsm/tsl/display/GodraysNode.js +615 -0
  149. package/examples/jsm/tsl/display/LensflareNode.js +1 -1
  150. package/examples/jsm/tsl/display/Lut3DNode.js +1 -1
  151. package/examples/jsm/tsl/display/OutlineNode.js +69 -19
  152. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
  153. package/examples/jsm/tsl/display/PixelationPassNode.js +7 -6
  154. package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
  155. package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
  156. package/examples/jsm/tsl/display/SMAANode.js +2 -2
  157. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  158. package/examples/jsm/tsl/display/SSGINode.js +8 -24
  159. package/examples/jsm/tsl/display/SSRNode.js +8 -8
  160. package/examples/jsm/tsl/display/SSSNode.js +6 -4
  161. package/examples/jsm/tsl/display/Shape.js +29 -0
  162. package/examples/jsm/tsl/display/SharpenNode.js +283 -0
  163. package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
  164. package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
  165. package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
  166. package/examples/jsm/tsl/display/TAAUNode.js +835 -0
  167. package/examples/jsm/tsl/display/TRAANode.js +315 -126
  168. package/examples/jsm/tsl/display/TransitionNode.js +1 -1
  169. package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
  170. package/examples/jsm/tsl/display/radialBlur.js +68 -0
  171. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
  172. package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
  173. package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
  174. package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
  175. package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
  176. package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
  177. package/examples/jsm/tsl/math/Bayer.js +53 -3
  178. package/examples/jsm/utils/BufferGeometryUtils.js +2 -3
  179. package/examples/jsm/utils/ColorUtils.js +76 -0
  180. package/examples/jsm/utils/LDrawUtils.js +1 -1
  181. package/examples/jsm/utils/ShadowMapViewer.js +24 -10
  182. package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
  183. package/examples/jsm/utils/SkeletonUtils.js +14 -8
  184. package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
  185. package/examples/jsm/webxr/XRHandMeshModel.js +36 -10
  186. package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
  187. package/package.json +24 -30
  188. package/src/Three.Core.js +3 -1
  189. package/src/Three.TSL.js +25 -11
  190. package/src/Three.WebGPU.Nodes.js +5 -0
  191. package/src/Three.WebGPU.js +9 -0
  192. package/src/Three.js +1 -0
  193. package/src/animation/AnimationAction.js +12 -2
  194. package/src/animation/AnimationClip.js +1 -1
  195. package/src/animation/AnimationMixer.js +6 -0
  196. package/src/animation/AnimationUtils.js +1 -12
  197. package/src/animation/KeyframeTrack.js +47 -8
  198. package/src/animation/PropertyMixer.js +4 -4
  199. package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
  200. package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
  201. package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
  202. package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
  203. package/src/animation/tracks/StringKeyframeTrack.js +1 -1
  204. package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
  205. package/src/audio/Audio.js +1 -1
  206. package/src/audio/AudioContext.js +2 -2
  207. package/src/audio/AudioListener.js +5 -3
  208. package/src/cameras/Camera.js +32 -2
  209. package/src/cameras/CubeCamera.js +20 -0
  210. package/src/constants.js +90 -5
  211. package/src/core/BufferAttribute.js +13 -1
  212. package/src/core/BufferGeometry.js +14 -2
  213. package/src/core/Clock.js +7 -0
  214. package/src/core/Object3D.js +52 -4
  215. package/src/core/Raycaster.js +2 -2
  216. package/src/core/RenderTarget.js +4 -4
  217. package/src/extras/PMREMGenerator.js +7 -18
  218. package/src/extras/TextureUtils.js +5 -1
  219. package/src/extras/curves/CatmullRomCurve3.js +3 -2
  220. package/src/geometries/ExtrudeGeometry.js +2 -2
  221. package/src/geometries/PolyhedronGeometry.js +1 -1
  222. package/src/geometries/TorusGeometry.js +8 -3
  223. package/src/helpers/CameraHelper.js +3 -0
  224. package/src/helpers/DirectionalLightHelper.js +4 -1
  225. package/src/helpers/HemisphereLightHelper.js +3 -0
  226. package/src/helpers/PointLightHelper.js +1 -25
  227. package/src/helpers/SpotLightHelper.js +3 -0
  228. package/src/lights/DirectionalLight.js +13 -0
  229. package/src/lights/HemisphereLight.js +10 -0
  230. package/src/lights/Light.js +1 -11
  231. package/src/lights/LightProbe.js +0 -15
  232. package/src/lights/LightShadow.js +15 -6
  233. package/src/lights/PointLight.js +15 -0
  234. package/src/lights/PointLightShadow.js +0 -86
  235. package/src/lights/SpotLight.js +22 -1
  236. package/src/lights/webgpu/IESSpotLight.js +2 -1
  237. package/src/loaders/AudioLoader.js +11 -1
  238. package/src/loaders/Cache.js +28 -0
  239. package/src/loaders/DataTextureLoader.js +6 -4
  240. package/src/loaders/FileLoader.js +2 -3
  241. package/src/loaders/ImageBitmapLoader.js +12 -9
  242. package/src/loaders/Loader.js +6 -0
  243. package/src/loaders/MaterialLoader.js +3 -2
  244. package/src/loaders/ObjectLoader.js +46 -6
  245. package/src/loaders/nodes/NodeLoader.js +2 -2
  246. package/src/loaders/nodes/NodeObjectLoader.js +18 -0
  247. package/src/materials/Material.js +2 -0
  248. package/src/materials/MeshLambertMaterial.js +9 -0
  249. package/src/materials/MeshPhongMaterial.js +9 -0
  250. package/src/materials/MeshToonMaterial.js +1 -1
  251. package/src/materials/ShaderMaterial.js +20 -1
  252. package/src/materials/nodes/Line2NodeMaterial.js +34 -7
  253. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +5 -2
  254. package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
  255. package/src/materials/nodes/NodeMaterial.js +45 -25
  256. package/src/materials/nodes/manager/NodeMaterialObserver.js +191 -86
  257. package/src/math/Line3.js +6 -5
  258. package/src/math/MathUtils.js +10 -10
  259. package/src/math/Matrix2.js +13 -9
  260. package/src/math/Matrix3.js +13 -9
  261. package/src/math/Matrix4.js +87 -74
  262. package/src/math/Plane.js +4 -3
  263. package/src/math/Quaternion.js +3 -29
  264. package/src/math/Sphere.js +1 -1
  265. package/src/math/Triangle.js +1 -1
  266. package/src/math/Vector2.js +11 -7
  267. package/src/math/Vector3.js +15 -13
  268. package/src/math/Vector4.js +13 -9
  269. package/src/math/interpolants/BezierInterpolant.js +108 -0
  270. package/src/nodes/Nodes.js +86 -68
  271. package/src/nodes/TSL.js +7 -7
  272. package/src/nodes/accessors/Arrays.js +1 -1
  273. package/src/nodes/accessors/BatchNode.js +10 -10
  274. package/src/nodes/accessors/Bitangent.js +5 -5
  275. package/src/nodes/accessors/BufferAttributeNode.js +107 -15
  276. package/src/nodes/accessors/BufferNode.js +29 -2
  277. package/src/nodes/accessors/Camera.js +149 -28
  278. package/src/nodes/accessors/ClippingNode.js +4 -4
  279. package/src/nodes/accessors/CubeTextureNode.js +27 -2
  280. package/src/nodes/accessors/InstanceNode.js +148 -43
  281. package/src/nodes/accessors/MaterialNode.js +9 -1
  282. package/src/nodes/accessors/MaterialProperties.js +2 -5
  283. package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
  284. package/src/nodes/accessors/ModelNode.js +1 -1
  285. package/src/nodes/accessors/Normal.js +11 -11
  286. package/src/nodes/accessors/Object3DNode.js +1 -1
  287. package/src/nodes/accessors/Position.js +34 -2
  288. package/src/nodes/accessors/ReferenceBaseNode.js +6 -6
  289. package/src/nodes/accessors/ReferenceNode.js +8 -8
  290. package/src/nodes/accessors/RendererReferenceNode.js +1 -2
  291. package/src/nodes/accessors/SceneProperties.js +47 -0
  292. package/src/nodes/accessors/SkinningNode.js +27 -26
  293. package/src/nodes/accessors/StorageBufferNode.js +14 -25
  294. package/src/nodes/accessors/StorageTextureNode.js +40 -9
  295. package/src/nodes/accessors/Tangent.js +4 -14
  296. package/src/nodes/accessors/Texture3DNode.js +32 -35
  297. package/src/nodes/accessors/TextureNode.js +67 -23
  298. package/src/nodes/accessors/UniformArrayNode.js +6 -4
  299. package/src/nodes/accessors/UserDataNode.js +1 -2
  300. package/src/nodes/accessors/VertexColorNode.js +1 -2
  301. package/src/nodes/code/FunctionCallNode.js +1 -1
  302. package/src/nodes/code/FunctionNode.js +2 -3
  303. package/src/nodes/core/ArrayNode.js +21 -2
  304. package/src/nodes/core/AssignNode.js +3 -3
  305. package/src/nodes/core/AttributeNode.js +3 -3
  306. package/src/nodes/core/BypassNode.js +1 -1
  307. package/src/nodes/core/ContextNode.js +104 -5
  308. package/src/nodes/core/IndexNode.js +2 -1
  309. package/src/nodes/core/InputNode.js +1 -1
  310. package/src/nodes/core/InspectorNode.js +1 -1
  311. package/src/nodes/core/IsolateNode.js +1 -1
  312. package/src/nodes/core/MRTNode.js +48 -2
  313. package/src/nodes/core/Node.js +112 -15
  314. package/src/nodes/core/NodeBuilder.js +284 -66
  315. package/src/nodes/core/NodeError.js +28 -0
  316. package/src/nodes/core/NodeFrame.js +12 -4
  317. package/src/nodes/core/NodeUtils.js +11 -9
  318. package/src/nodes/core/OutputStructNode.js +12 -10
  319. package/src/nodes/core/ParameterNode.js +4 -4
  320. package/src/nodes/core/PropertyNode.js +19 -3
  321. package/src/nodes/core/StackNode.js +66 -17
  322. package/src/nodes/core/StackTrace.js +139 -0
  323. package/src/nodes/core/StructNode.js +17 -3
  324. package/src/nodes/core/StructTypeNode.js +12 -18
  325. package/src/nodes/core/SubBuildNode.js +2 -2
  326. package/src/nodes/core/UniformGroupNode.js +36 -6
  327. package/src/nodes/core/UniformNode.js +21 -5
  328. package/src/nodes/core/VarNode.js +48 -23
  329. package/src/nodes/core/VaryingNode.js +2 -19
  330. package/src/nodes/display/BlendModes.js +0 -64
  331. package/src/nodes/display/ColorAdjustment.js +17 -0
  332. package/src/nodes/display/ColorSpaceNode.js +3 -3
  333. package/src/nodes/display/NormalMapNode.js +39 -4
  334. package/src/nodes/display/PassNode.js +125 -16
  335. package/src/nodes/display/RenderOutputNode.js +7 -7
  336. package/src/nodes/display/ScreenNode.js +4 -2
  337. package/src/nodes/display/ToneMappingNode.js +1 -1
  338. package/src/nodes/display/ToonOutlinePassNode.js +2 -2
  339. package/src/nodes/display/ViewportDepthNode.js +52 -4
  340. package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
  341. package/src/nodes/display/ViewportTextureNode.js +39 -11
  342. package/src/nodes/fog/Fog.js +18 -35
  343. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
  344. package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
  345. package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
  346. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  347. package/src/nodes/functions/PhysicalLightingModel.js +126 -45
  348. package/src/nodes/geometry/RangeNode.js +5 -3
  349. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  350. package/src/nodes/gpgpu/BarrierNode.js +9 -0
  351. package/src/nodes/gpgpu/ComputeBuiltinNode.js +2 -3
  352. package/src/nodes/gpgpu/ComputeNode.js +74 -48
  353. package/src/nodes/gpgpu/SubgroupFunctionNode.js +2 -2
  354. package/src/nodes/gpgpu/WorkgroupInfoNode.js +4 -4
  355. package/src/nodes/lighting/AnalyticLightNode.js +53 -0
  356. package/src/nodes/lighting/EnvironmentNode.js +28 -3
  357. package/src/nodes/lighting/LightsNode.js +7 -28
  358. package/src/nodes/lighting/PointShadowNode.js +162 -149
  359. package/src/nodes/lighting/ShadowFilterNode.js +53 -65
  360. package/src/nodes/lighting/ShadowNode.js +120 -42
  361. package/src/nodes/math/BitcastNode.js +1 -1
  362. package/src/nodes/math/BitcountNode.js +433 -0
  363. package/src/nodes/math/ConditionalNode.js +3 -3
  364. package/src/nodes/math/MathNode.js +76 -41
  365. package/src/nodes/math/OperatorNode.js +3 -2
  366. package/src/nodes/math/PackFloatNode.js +98 -0
  367. package/src/nodes/math/UnpackFloatNode.js +96 -0
  368. package/src/nodes/pmrem/PMREMNode.js +1 -1
  369. package/src/nodes/pmrem/PMREMUtils.js +9 -15
  370. package/src/nodes/tsl/TSLBase.js +1 -1
  371. package/src/nodes/tsl/TSLCore.js +38 -17
  372. package/src/nodes/utils/ArrayElementNode.js +14 -1
  373. package/src/nodes/utils/ConvertNode.js +1 -1
  374. package/src/nodes/utils/DebugNode.js +12 -12
  375. package/src/nodes/utils/EventNode.js +31 -2
  376. package/src/nodes/utils/FlipNode.js +1 -1
  377. package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
  378. package/src/nodes/utils/JoinNode.js +3 -3
  379. package/src/nodes/utils/LoopNode.js +1 -1
  380. package/src/nodes/utils/MemberNode.js +2 -2
  381. package/src/nodes/utils/Packing.js +13 -1
  382. package/src/nodes/utils/PostProcessingUtils.js +33 -1
  383. package/src/nodes/utils/RTTNode.js +1 -1
  384. package/src/nodes/utils/ReflectorNode.js +3 -4
  385. package/src/nodes/utils/Remap.js +48 -0
  386. package/src/nodes/utils/RotateNode.js +1 -1
  387. package/src/nodes/utils/SampleNode.js +1 -1
  388. package/src/nodes/utils/SetNode.js +1 -1
  389. package/src/nodes/utils/SplitNode.js +1 -1
  390. package/src/nodes/utils/SpriteSheetUV.js +35 -0
  391. package/src/nodes/utils/UVUtils.js +28 -0
  392. package/src/objects/BatchedMesh.js +44 -16
  393. package/src/objects/InstancedMesh.js +30 -3
  394. package/src/objects/Line.js +1 -1
  395. package/src/objects/Mesh.js +1 -1
  396. package/src/objects/Points.js +1 -1
  397. package/src/objects/Skeleton.js +9 -0
  398. package/src/objects/SkinnedMesh.js +26 -9
  399. package/src/renderers/WebGLRenderer.js +329 -145
  400. package/src/renderers/common/Animation.js +3 -3
  401. package/src/renderers/common/Attributes.js +15 -1
  402. package/src/renderers/common/Backend.js +29 -8
  403. package/src/renderers/common/Background.js +26 -13
  404. package/src/renderers/common/BindGroup.js +1 -16
  405. package/src/renderers/common/Binding.js +11 -0
  406. package/src/renderers/common/Bindings.js +29 -14
  407. package/src/renderers/common/BlendMode.js +143 -0
  408. package/src/renderers/common/Buffer.js +40 -0
  409. package/src/renderers/common/BundleGroup.js +1 -1
  410. package/src/renderers/common/ChainMap.js +30 -6
  411. package/src/renderers/common/ComputePipeline.js +1 -1
  412. package/src/renderers/common/CubeRenderTarget.js +51 -7
  413. package/src/renderers/common/Geometries.js +29 -3
  414. package/src/renderers/common/Info.js +333 -4
  415. package/src/renderers/common/InspectorBase.js +6 -1
  416. package/src/renderers/common/Lighting.js +5 -21
  417. package/src/renderers/common/Pipelines.js +40 -7
  418. package/src/renderers/common/PostProcessing.js +8 -206
  419. package/src/renderers/common/ReadbackBuffer.js +78 -0
  420. package/src/renderers/common/RenderBundle.js +3 -1
  421. package/src/renderers/common/RenderBundles.js +7 -3
  422. package/src/renderers/common/RenderContext.js +16 -0
  423. package/src/renderers/common/RenderContexts.js +33 -49
  424. package/src/renderers/common/RenderLists.js +2 -1
  425. package/src/renderers/common/RenderObject.js +17 -5
  426. package/src/renderers/common/RenderObjectPipeline.js +40 -0
  427. package/src/renderers/common/RenderObjects.js +21 -5
  428. package/src/renderers/common/RenderPipeline.js +232 -17
  429. package/src/renderers/common/Renderer.js +481 -117
  430. package/src/renderers/common/Sampler.js +4 -4
  431. package/src/renderers/common/StorageBuffer.js +13 -1
  432. package/src/renderers/common/Textures.js +89 -4
  433. package/src/renderers/common/TimestampQueryPool.js +5 -3
  434. package/src/renderers/common/Uniform.js +8 -0
  435. package/src/renderers/common/UniformsGroup.js +62 -1
  436. package/src/renderers/common/XRManager.js +37 -29
  437. package/src/renderers/common/extras/PMREMGenerator.js +25 -23
  438. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  439. package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +242 -99
  440. package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
  441. package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
  442. package/src/renderers/shaders/DFGLUTData.js +19 -34
  443. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
  444. package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
  445. package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
  446. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
  447. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
  448. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
  449. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +8 -12
  450. package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
  451. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +13 -2
  452. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
  453. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
  454. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +2 -0
  455. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
  456. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +112 -53
  457. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
  458. package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
  459. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
  460. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +225 -186
  461. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
  462. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
  463. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  464. package/src/renderers/shaders/ShaderChunk.js +5 -3
  465. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
  466. package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
  467. package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
  468. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
  469. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
  470. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
  471. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
  472. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
  473. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
  474. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
  475. package/src/renderers/shaders/ShaderLib.js +7 -6
  476. package/src/renderers/shaders/UniformsLib.js +7 -5
  477. package/src/renderers/shaders/UniformsUtils.js +27 -5
  478. package/src/renderers/webgl/WebGLAnimation.js +2 -1
  479. package/src/renderers/webgl/WebGLBackground.js +15 -15
  480. package/src/renderers/webgl/WebGLBindingStates.js +99 -27
  481. package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
  482. package/src/renderers/webgl/WebGLCapabilities.js +9 -4
  483. package/src/renderers/webgl/WebGLEnvironments.js +228 -0
  484. package/src/renderers/webgl/WebGLGeometries.js +10 -7
  485. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
  486. package/src/renderers/webgl/WebGLLights.js +18 -1
  487. package/src/renderers/webgl/WebGLMaterials.js +24 -13
  488. package/src/renderers/webgl/WebGLObjects.js +3 -1
  489. package/src/renderers/webgl/WebGLOutput.js +270 -0
  490. package/src/renderers/webgl/WebGLProgram.js +49 -109
  491. package/src/renderers/webgl/WebGLPrograms.js +63 -51
  492. package/src/renderers/webgl/WebGLRenderLists.js +15 -0
  493. package/src/renderers/webgl/WebGLRenderStates.js +13 -2
  494. package/src/renderers/webgl/WebGLShadowMap.js +188 -24
  495. package/src/renderers/webgl/WebGLState.js +75 -37
  496. package/src/renderers/webgl/WebGLTextures.js +215 -54
  497. package/src/renderers/webgl/WebGLUniforms.js +40 -3
  498. package/src/renderers/webgl/WebGLUniformsGroups.js +19 -0
  499. package/src/renderers/webgl/WebGLUtils.js +6 -2
  500. package/src/renderers/webgl-fallback/WebGLBackend.js +253 -82
  501. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
  502. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +173 -74
  503. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
  504. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
  505. package/src/renderers/webgl-fallback/utils/WebGLState.js +223 -6
  506. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +68 -53
  507. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +10 -10
  508. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
  509. package/src/renderers/webgpu/WebGPUBackend.js +260 -140
  510. package/src/renderers/webgpu/WebGPURenderer.js +2 -1
  511. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +366 -90
  512. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +107 -34
  513. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +357 -200
  514. package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
  515. package/src/renderers/webgpu/utils/WebGPUConstants.js +10 -0
  516. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +61 -23
  517. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +152 -200
  518. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +156 -59
  519. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
  520. package/src/renderers/webgpu/utils/WebGPUUtils.js +33 -11
  521. package/src/renderers/webxr/WebXRController.js +12 -0
  522. package/src/renderers/webxr/WebXRManager.js +4 -2
  523. package/src/textures/CubeDepthTexture.js +76 -0
  524. package/src/textures/HTMLTexture.js +74 -0
  525. package/src/textures/Source.js +2 -2
  526. package/src/textures/Texture.js +16 -5
  527. package/src/utils.js +280 -3
  528. package/examples/jsm/materials/MeshGouraudMaterial.js +0 -434
  529. package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
  530. package/examples/jsm/shaders/GodRaysShader.js +0 -333
  531. package/src/nodes/accessors/SceneNode.js +0 -145
  532. package/src/nodes/code/ScriptableNode.js +0 -726
  533. package/src/nodes/code/ScriptableValueNode.js +0 -253
  534. package/src/nodes/display/PosterizeNode.js +0 -65
  535. package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
  536. package/src/nodes/utils/RemapNode.js +0 -125
  537. package/src/nodes/utils/SpriteSheetUVNode.js +0 -90
  538. package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
  539. package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2010-2025 Three.js Authors
3
+ * Copyright 2010-2026 Three.js Authors
4
4
  * SPDX-License-Identifier: MIT
5
5
  */
6
- import { Color, Matrix3, Vector2, mergeUniforms, Vector3, CubeUVReflectionMapping, Mesh, BoxGeometry, ShaderMaterial, cloneUniforms, BackSide, ColorManagement, SRGBTransfer, PlaneGeometry, FrontSide, getUnlitUniformColorSpace, Euler, Matrix4, IntType, warn, RGBAFormat, HalfFloatType, UnsignedByteType, FloatType, Plane, EquirectangularReflectionMapping, EquirectangularRefractionMapping, WebGLCubeRenderTarget, CubeReflectionMapping, CubeRefractionMapping, BufferGeometry, PerspectiveCamera, NoToneMapping, MeshBasicMaterial, error, BufferAttribute, WebGLRenderTarget, NoBlending, OrthographicCamera, LinearFilter, LinearSRGBColorSpace, warnOnce, arrayNeedsUint32, Uint32BufferAttribute, Uint16BufferAttribute, Vector4, DataArrayTexture, LessEqualCompare, Texture, DepthTexture, Data3DTexture, CubeTexture, GLSL3, CustomToneMapping, NeutralToneMapping, AgXToneMapping, ACESFilmicToneMapping, CineonToneMapping, ReinhardToneMapping, LinearToneMapping, PCFShadowMap, PCFSoftShadowMap, VSMShadowMap, LinearTransfer, AddOperation, MixOperation, MultiplyOperation, ObjectSpaceNormalMap, TangentSpaceNormalMap, NormalBlending, DoubleSide, UniformsUtils, Layers, Frustum, MeshDepthMaterial, RGBADepthPacking, MeshDistanceMaterial, NearestFilter, LessEqualDepth, AddEquation, SubtractEquation, ReverseSubtractEquation, ZeroFactor, OneFactor, SrcColorFactor, SrcAlphaFactor, SrcAlphaSaturateFactor, DstColorFactor, DstAlphaFactor, OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor, ConstantColorFactor, OneMinusConstantColorFactor, ConstantAlphaFactor, OneMinusConstantAlphaFactor, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, CullFaceNone, CullFaceBack, CullFaceFront, NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessDepth, AlwaysDepth, NeverDepth, MinEquation, MaxEquation, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapNearestFilter, LinearMipmapLinearFilter, NeverCompare, AlwaysCompare, LessCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, NoColorSpace, DepthStencilFormat, getByteLength, DepthFormat, UnsignedIntType, UnsignedInt248Type, UnsignedShortType, createElementNS, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedInt5999Type, UnsignedInt101111Type, ByteType, ShortType, AlphaFormat, RGBFormat, RedFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, ExternalTexture, EventDispatcher, ArrayCamera, WebXRController, RAD2DEG, DataTexture, createCanvasElement, SRGBColorSpace, REVISION, log, WebGLCoordinateSystem, probeAsync } from './three.core.js';
7
- export { AdditiveAnimationBlendMode, AlwaysStencilFunc, AmbientLight, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrowHelper, AttachedBindMode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BasicDepthPacking, BasicShadowMap, BatchedMesh, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxHelper, BufferGeometryLoader, Cache, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CircleGeometry, Clock, ColorKeyframeTrack, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ConeGeometry, Controls, CubeCamera, CubeTextureLoader, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceFrontBack, Curve, CurvePath, CylinderGeometry, Cylindrical, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EllipseCurve, EqualStencilFunc, ExtrudeGeometry, FileLoader, Float16BufferAttribute, Float32BufferAttribute, Fog, FogExp2, FramebufferTexture, FrustumArray, GLBufferAttribute, GLSL1, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HemisphereLight, HemisphereLightHelper, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InterpolationSamplingMode, InterpolationSamplingType, InvertStencilOp, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LineSegments, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, Loader, LoaderUtils, LoadingManager, LoopOnce, LoopPingPong, LoopRepeat, MOUSE, Material, MaterialLoader, MathUtils, Matrix2, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NeverStencilFunc, NormalAnimationBlendMode, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, OctahedronGeometry, Path, PlaneHelper, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RGBDepthPacking, RGBIntegerFormat, RGDepthPacking, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RenderTarget, RenderTarget3D, ReplaceStencilOp, RingGeometry, Scene, ShadowMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, Skeleton, SkeletonHelper, SkinnedMesh, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, TOUCH, TetrahedronGeometry, TextureLoader, TextureUtils, Timer, TimestampQuery, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry, UVMapping, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsGroup, VectorKeyframeTrack, VideoFrameTexture, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGPUCoordinateSystem, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, ZeroStencilOp, getConsoleFunction, setConsoleFunction } from './three.core.js';
6
+ import { Matrix3, Vector2, Color, Vector3, mergeUniforms, CubeUVReflectionMapping, Mesh, BoxGeometry, ShaderMaterial, BackSide, cloneUniforms, Matrix4, ColorManagement, SRGBTransfer, PlaneGeometry, FrontSide, getUnlitUniformColorSpace, IntType, warn, HalfFloatType, UnsignedByteType, FloatType, RGBAFormat, Plane, CubeReflectionMapping, CubeRefractionMapping, BufferGeometry, OrthographicCamera, PerspectiveCamera, NoToneMapping, MeshBasicMaterial, error, NoBlending, WebGLRenderTarget, BufferAttribute, LinearSRGBColorSpace, LinearFilter, CubeTexture, LinearMipmapLinearFilter, CubeCamera, EquirectangularReflectionMapping, EquirectangularRefractionMapping, warnOnce, Uint32BufferAttribute, Uint16BufferAttribute, DataArrayTexture, Vector4, DepthTexture, Float32BufferAttribute, RawShaderMaterial, CustomToneMapping, NeutralToneMapping, AgXToneMapping, ACESFilmicToneMapping, CineonToneMapping, ReinhardToneMapping, LinearToneMapping, Data3DTexture, GreaterEqualCompare, LessEqualCompare, Texture, GLSL3, VSMShadowMap, PCFShadowMap, AddOperation, MixOperation, MultiplyOperation, LinearTransfer, UniformsUtils, DoubleSide, NormalBlending, TangentSpaceNormalMap, ObjectSpaceNormalMap, Layers, RGFormat, RG11_EAC_Format, RED_GREEN_RGTC2_Format, MeshDepthMaterial, MeshDistanceMaterial, PCFSoftShadowMap, DepthFormat, NearestFilter, CubeDepthTexture, UnsignedIntType, Frustum, LessEqualDepth, ReverseSubtractEquation, SubtractEquation, AddEquation, OneMinusConstantAlphaFactor, ConstantAlphaFactor, OneMinusConstantColorFactor, ConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, DstAlphaFactor, DstColorFactor, SrcAlphaSaturateFactor, SrcAlphaFactor, SrcColorFactor, OneFactor, ZeroFactor, NotEqualDepth, GreaterDepth, GreaterEqualDepth, EqualDepth, LessDepth, AlwaysDepth, NeverDepth, CullFaceNone, CullFaceBack, CullFaceFront, CustomBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, ReversedDepthFuncs, MinEquation, MaxEquation, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, LinearMipmapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NotEqualCompare, GreaterCompare, EqualCompare, LessCompare, AlwaysCompare, NeverCompare, NoColorSpace, DepthStencilFormat, getByteLength, UnsignedInt248Type, UnsignedShortType, createElementNS, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedInt5999Type, UnsignedInt101111Type, ByteType, ShortType, AlphaFormat, RGBFormat, RedFormat, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat, RGB_S3TC_DXT1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGB_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_PVRTC_2BPPV1_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, R11_EAC_Format, SIGNED_R11_EAC_Format, SIGNED_RG11_EAC_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, SIGNED_RED_GREEN_RGTC2_Format, ExternalTexture, EventDispatcher, ArrayCamera, WebXRController, RAD2DEG, DataTexture, createCanvasElement, SRGBColorSpace, REVISION, log, WebGLCoordinateSystem, probeAsync } from './three.core.js';
7
+ export { AdditiveAnimationBlendMode, AlwaysStencilFunc, AmbientLight, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrowHelper, AttachedBindMode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BasicDepthPacking, BasicShadowMap, BatchedMesh, BezierInterpolant, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxHelper, BufferGeometryLoader, Cache, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CircleGeometry, Clock, ColorKeyframeTrack, Compatibility, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ConeGeometry, Controls, CubeTextureLoader, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceFrontBack, Curve, CurvePath, CylinderGeometry, Cylindrical, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EllipseCurve, EqualStencilFunc, Euler, ExtrudeGeometry, FileLoader, Float16BufferAttribute, Fog, FogExp2, FramebufferTexture, FrustumArray, GLBufferAttribute, GLSL1, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HTMLTexture, HemisphereLight, HemisphereLightHelper, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateBezier, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InterpolationSamplingMode, InterpolationSamplingType, InvertStencilOp, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LineSegments, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, Loader, LoaderUtils, LoadingManager, LoopOnce, LoopPingPong, LoopRepeat, MOUSE, Material, MaterialBlending, MaterialLoader, MathUtils, Matrix2, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NeverStencilFunc, NoNormalPacking, NormalAnimationBlendMode, NormalGAPacking, NormalRGPacking, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, OctahedronGeometry, Path, PlaneHelper, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RGBADepthPacking, RGBDepthPacking, RGBIntegerFormat, RGDepthPacking, Ray, Raycaster, RectAreaLight, RenderTarget, RenderTarget3D, ReplaceStencilOp, RingGeometry, Scene, ShadowMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, Skeleton, SkeletonHelper, SkinnedMesh, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, TOUCH, TetrahedronGeometry, TextureLoader, TextureUtils, Timer, TimestampQuery, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry, UVMapping, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsGroup, VectorKeyframeTrack, VideoFrameTexture, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGPUCoordinateSystem, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroSlopeEnding, ZeroStencilOp, getConsoleFunction, setConsoleFunction } from './three.core.js';
8
8
 
9
9
  function WebGLAnimation() {
10
10
 
@@ -27,6 +27,7 @@ function WebGLAnimation() {
27
27
 
28
28
  if ( isAnimating === true ) return;
29
29
  if ( animationLoop === null ) return;
30
+ if ( context === null ) return;
30
31
 
31
32
  requestId = context.requestAnimationFrame( onAnimationFrame );
32
33
 
@@ -36,7 +37,7 @@ function WebGLAnimation() {
36
37
 
37
38
  stop: function () {
38
39
 
39
- context.cancelAnimationFrame( requestId );
40
+ if ( context !== null ) context.cancelAnimationFrame( requestId );
40
41
 
41
42
  isAnimating = false;
42
43
 
@@ -309,7 +310,7 @@ var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D(
309
310
 
310
311
  var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
311
312
 
312
- var batching_pars_vertex = "#ifdef USE_BATCHING\n\t#if ! defined( GL_ANGLE_multi_draw )\n\t#define gl_DrawID _gl_DrawID\n\tuniform int _gl_DrawID;\n\t#endif\n\tuniform highp sampler2D batchingTexture;\n\tuniform highp usampler2D batchingIdTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n\tfloat getIndirectIndex( const in int i ) {\n\t\tint size = textureSize( batchingIdTexture, 0 ).x;\n\t\tint x = i % size;\n\t\tint y = i / size;\n\t\treturn float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\n\t}\n#endif\n#ifdef USE_BATCHING_COLOR\n\tuniform sampler2D batchingColorTexture;\n\tvec3 getBatchingColor( const in float i ) {\n\t\tint size = textureSize( batchingColorTexture, 0 ).x;\n\t\tint j = int( i );\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;\n\t}\n#endif";
313
+ var batching_pars_vertex = "#ifdef USE_BATCHING\n\t#if ! defined( GL_ANGLE_multi_draw )\n\t#define gl_DrawID _gl_DrawID\n\tuniform int _gl_DrawID;\n\t#endif\n\tuniform highp sampler2D batchingTexture;\n\tuniform highp usampler2D batchingIdTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n\tfloat getIndirectIndex( const in int i ) {\n\t\tint size = textureSize( batchingIdTexture, 0 ).x;\n\t\tint x = i % size;\n\t\tint y = i / size;\n\t\treturn float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\n\t}\n#endif\n#ifdef USE_BATCHING_COLOR\n\tuniform sampler2D batchingColorTexture;\n\tvec4 getBatchingColor( const in float i ) {\n\t\tint size = textureSize( batchingColorTexture, 0 ).x;\n\t\tint j = int( i );\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 );\n\t}\n#endif";
313
314
 
314
315
  var batching_vertex = "#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );\n#endif";
315
316
 
@@ -331,13 +332,13 @@ var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 v
331
332
 
332
333
  var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
333
334
 
334
- var color_fragment = "#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif";
335
+ var color_fragment = "#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#endif";
335
336
 
336
- var color_pars_fragment = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif";
337
+ var color_pars_fragment = "#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#endif";
337
338
 
338
- var color_pars_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec3 vColor;\n#endif";
339
+ var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec4 vColor;\n#endif";
339
340
 
340
- var color_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );\n\tvColor.xyz *= batchingColor.xyz;\n#endif";
341
+ var color_vertex = "#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec4( 1.0 );\n#endif\n#ifdef USE_COLOR_ALPHA\n\tvColor *= color;\n#elif defined( USE_COLOR )\n\tvColor.rgb *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.rgb *= instanceColor.rgb;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) );\n#endif";
341
342
 
342
343
  var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated";
343
344
 
@@ -357,9 +358,9 @@ var colorspace_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
357
358
 
358
359
  var colorspace_pars_fragment = "vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}";
359
360
 
360
- var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
361
+ var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * reflectVec );\n\t\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t\t#endif\n\t#endif\n#endif";
361
362
 
362
- var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n#endif";
363
+ var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n#endif";
363
364
 
364
365
  var envmap_pars_fragment = "#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";
365
366
 
@@ -383,7 +384,7 @@ var lights_lambert_fragment = "LambertMaterial material;\nmaterial.diffuseColor
383
384
 
384
385
  var lights_lambert_pars_fragment = "varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert";
385
386
 
386
- var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif";
387
+ var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif\n#include <lightprobes_pars_fragment>";
387
388
 
388
389
  var envmap_physical_pars_fragment = "#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n#endif";
389
390
 
@@ -395,15 +396,17 @@ var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor
395
396
 
396
397
  var lights_phong_pars_fragment = "varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong";
397
398
 
398
- var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif";
399
+ var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.metalness = metalnessFactor;\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor;\n\tmaterial.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = vec3( 0.04 );\n\tmaterial.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.0001, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif";
399
400
 
400
- var lights_physical_pars_fragment = "uniform sampler2D dfgLUT;\nstruct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\tfloat v = 0.5 / ( gv + gl );\n\t\treturn saturate(v);\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColor;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transpose( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 uv = vec2( roughness, dotNV );\n\treturn texture2D( dfgLUT, uv ).rg;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nvec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 singleScatter = BRDF_GGX( lightDir, viewDir, normal, material );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 dfgV = DFGApprox( vec3(0.0, 0.0, 1.0), vec3(sqrt(1.0 - dotNV * dotNV), 0.0, dotNV), material.roughness );\n\tvec2 dfgL = DFGApprox( vec3(0.0, 0.0, 1.0), vec3(sqrt(1.0 - dotNL * dotNL), 0.0, dotNL), material.roughness );\n\tvec3 FssEss_V = material.specularColor * dfgV.x + material.specularF90 * dfgV.y;\n\tvec3 FssEss_L = material.specularColor * dfgL.x + material.specularF90 * dfgL.y;\n\tfloat Ess_V = dfgV.x + dfgV.y;\n\tfloat Ess_L = dfgL.x + dfgL.y;\n\tfloat Ems_V = 1.0 - Ess_V;\n\tfloat Ems_L = 1.0 - Ess_L;\n\tvec3 Favg = material.specularColor + ( 1.0 - material.specularColor ) * 0.047619;\n\tvec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg * Favg + EPSILON );\n\tfloat compensationFactor = Ems_V * Ems_L;\n\tvec3 multiScatter = Fms * compensationFactor;\n\treturn singleScatter + multiScatter;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX_Multiscatter( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\t#endif\n\tvec3 totalScattering = singleScattering + multiScattering;\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
401
+ var lights_physical_pars_fragment = "uniform sampler2D dfgLUT;\nstruct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tvec3 diffuseContribution;\n\tvec3 specularColor;\n\tvec3 specularColorBlended;\n\tfloat roughness;\n\tfloat metalness;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t\tvec3 iridescenceFresnelDielectric;\n\t\tvec3 iridescenceFresnelMetallic;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\treturn 0.5 / max( gv + gl, EPSILON );\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColorBlended;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transpose( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat rInv = 1.0 / ( roughness + 0.1 );\n\tfloat a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv;\n\tfloat b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv;\n\tfloat DG = exp( a * dotNV + b );\n\treturn saturate( DG );\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nvec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 singleScatter = BRDF_GGX( lightDir, viewDir, normal, material );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 dfgV = texture2D( dfgLUT, vec2( material.roughness, dotNV ) ).rg;\n\tvec2 dfgL = texture2D( dfgLUT, vec2( material.roughness, dotNL ) ).rg;\n\tvec3 FssEss_V = material.specularColorBlended * dfgV.x + material.specularF90 * dfgV.y;\n\tvec3 FssEss_L = material.specularColorBlended * dfgL.x + material.specularF90 * dfgL.y;\n\tfloat Ess_V = dfgV.x + dfgV.y;\n\tfloat Ess_L = dfgL.x + dfgL.y;\n\tfloat Ems_V = 1.0 - Ess_V;\n\tfloat Ems_L = 1.0 - Ess_L;\n\tvec3 Favg = material.specularColorBlended + ( 1.0 - material.specularColorBlended ) * 0.047619;\n\tvec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg + EPSILON );\n\tfloat compensationFactor = Ems_V * Ems_L;\n\tvec3 multiScatter = Fms * compensationFactor;\n\treturn singleScatter + multiScatter;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t\t#ifdef USE_CLEARCOAT\n\t\t\tvec3 Ncc = geometryClearcoatNormal;\n\t\t\tvec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness );\n\t\t\tvec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat );\n\t\t\tvec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat );\n\t\t\tmat3 mInvClearcoat = mat3(\n\t\t\t\tvec3( t1Clearcoat.x, 0, t1Clearcoat.y ),\n\t\t\t\tvec3( 0, 1, 0 ),\n\t\t\t\tvec3( t1Clearcoat.z, 0, t1Clearcoat.w )\n\t\t\t);\n\t\t\tvec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y;\n\t\t\tclearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords );\n\t\t#endif\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n \n \t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n \n \t\tfloat sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n \t\tfloat sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness );\n \n \t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL );\n \n \t\tirradiance *= sheenEnergyComp;\n \n \t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX_Multiscatter( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseContribution );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution );\n\t#ifdef USE_SHEEN\n\t\tfloat sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;\n\t\tdiffuse *= sheenEnergyComp;\n\t#endif\n\treflectedLight.indirectDiffuse += diffuse;\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ) * RECIPROCAL_PI;\n \t#endif\n\tvec3 singleScatteringDielectric = vec3( 0.0 );\n\tvec3 multiScatteringDielectric = vec3( 0.0 );\n\tvec3 singleScatteringMetallic = vec3( 0.0 );\n\tvec3 multiScatteringMetallic = vec3( 0.0 );\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnelDielectric, material.roughness, singleScatteringDielectric, multiScatteringDielectric );\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceFresnelMetallic, material.roughness, singleScatteringMetallic, multiScatteringMetallic );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScatteringDielectric, multiScatteringDielectric );\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.diffuseColor, material.specularF90, material.roughness, singleScatteringMetallic, multiScatteringMetallic );\n\t#endif\n\tvec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness );\n\tvec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness );\n\tvec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;\n\tvec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tvec3 indirectSpecular = radiance * singleScattering;\n\tindirectSpecular += multiScattering * cosineWeightedIrradiance;\n\tvec3 indirectDiffuse = diffuse * cosineWeightedIrradiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t\tfloat sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;\n\t\tindirectSpecular *= sheenEnergyComp;\n\t\tindirectDiffuse *= sheenEnergyComp;\n\t#endif\n\treflectedLight.indirectSpecular += indirectSpecular;\n\treflectedLight.indirectDiffuse += indirectDiffuse;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";
401
402
 
402
- var lights_fragment_begin = "\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
403
+ var lights_fragment_begin = "\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor );\n\t\tmaterial.iridescenceFresnel = mix( material.iridescenceFresnelDielectric, material.iridescenceFresnelMetallic, material.metalness );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#ifdef USE_LIGHT_PROBES_GRID\n\t\tvec3 probeWorldPos = ( ( vec4( geometryPosition, 1.0 ) - viewMatrix[ 3 ] ) * viewMatrix ).xyz;\n\t\tvec3 probeWorldNormal = inverseTransformDirection( geometryNormal, viewMatrix );\n\t\tirradiance += getLightProbeGridIrradiance( probeWorldPos, probeWorldNormal );\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";
403
404
 
404
- var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif";
405
+ var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\t#if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG )\n\t\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t\t#endif\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif";
405
406
 
406
- var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif";
407
+ var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n\t#if defined( LAMBERT ) || defined( PHONG )\n\t\tirradiance += iblIrradiance;\n\t#endif\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif";
408
+
409
+ var lightprobes_pars_fragment = "#ifdef USE_LIGHT_PROBES_GRID\nuniform highp sampler3D probesSH;\nuniform vec3 probesMin;\nuniform vec3 probesMax;\nuniform vec3 probesResolution;\nvec3 getLightProbeGridIrradiance( vec3 worldPos, vec3 worldNormal ) {\n\tvec3 res = probesResolution;\n\tvec3 gridRange = probesMax - probesMin;\n\tvec3 resMinusOne = res - 1.0;\n\tvec3 probeSpacing = gridRange / resMinusOne;\n\tvec3 samplePos = worldPos + worldNormal * probeSpacing * 0.5;\n\tvec3 uvw = clamp( ( samplePos - probesMin ) / gridRange, 0.0, 1.0 );\n\tuvw = uvw * resMinusOne / res + 0.5 / res;\n\tfloat nz = res.z;\n\tfloat paddedSlices = nz + 2.0;\n\tfloat atlasDepth = 7.0 * paddedSlices;\n\tfloat uvZBase = uvw.z * nz + 1.0;\n\tvec4 s0 = texture( probesSH, vec3( uvw.xy, ( uvZBase ) / atlasDepth ) );\n\tvec4 s1 = texture( probesSH, vec3( uvw.xy, ( uvZBase + paddedSlices ) / atlasDepth ) );\n\tvec4 s2 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 2.0 * paddedSlices ) / atlasDepth ) );\n\tvec4 s3 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 3.0 * paddedSlices ) / atlasDepth ) );\n\tvec4 s4 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 4.0 * paddedSlices ) / atlasDepth ) );\n\tvec4 s5 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 5.0 * paddedSlices ) / atlasDepth ) );\n\tvec4 s6 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 6.0 * paddedSlices ) / atlasDepth ) );\n\tvec3 c0 = s0.xyz;\n\tvec3 c1 = vec3( s0.w, s1.xy );\n\tvec3 c2 = vec3( s1.zw, s2.x );\n\tvec3 c3 = s2.yzw;\n\tvec3 c4 = s3.xyz;\n\tvec3 c5 = vec3( s3.w, s4.xy );\n\tvec3 c6 = vec3( s4.zw, s5.x );\n\tvec3 c7 = s5.yzw;\n\tvec3 c8 = s6.xyz;\n\tfloat x = worldNormal.x, y = worldNormal.y, z = worldNormal.z;\n\tvec3 result = c0 * 0.886227;\n\tresult += c1 * 2.0 * 0.511664 * y;\n\tresult += c2 * 2.0 * 0.511664 * z;\n\tresult += c3 * 2.0 * 0.511664 * x;\n\tresult += c4 * 2.0 * 0.429043 * x * y;\n\tresult += c5 * 2.0 * 0.429043 * y * z;\n\tresult += c6 * ( 0.743125 * z * z - 0.247708 );\n\tresult += c7 * 2.0 * 0.429043 * x * z;\n\tresult += c8 * 0.429043 * ( x * x - y * y );\n\treturn max( result, vec3( 0.0 ) );\n}\n#endif";
407
410
 
408
411
  var logdepthbuf_fragment = "#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";
409
412
 
@@ -437,7 +440,7 @@ var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetB
437
440
 
438
441
  var normal_fragment_begin = "float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;";
439
442
 
440
- var normal_fragment_maps = "#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";
443
+ var normal_fragment_maps = "#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#if defined( USE_PACKED_NORMALMAP )\n\t\tmapN = vec3( mapN.xy, sqrt( saturate( 1.0 - dot( mapN.xy, mapN.xy ) ) ) );\n\t#endif\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif";
441
444
 
442
445
  var normal_pars_fragment = "#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif";
443
446
 
@@ -457,7 +460,7 @@ var iridescence_pars_fragment = "#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D
457
460
 
458
461
  var opaque_fragment = "#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );";
459
462
 
460
- var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn depth * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * depth - far );\n}";
463
+ var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\n\t\treturn depth * ( far - near ) - far;\n\t#else\n\t\treturn depth * ( near - far ) - near;\n\t#endif\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\t\n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\treturn ( near * far ) / ( ( near - far ) * depth - near );\n\t#else\n\t\treturn ( near * far ) / ( ( far - near ) * depth - far );\n\t#endif\n}";
461
464
 
462
465
  var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
463
466
 
@@ -471,13 +474,13 @@ var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUG
471
474
 
472
475
  var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
473
476
 
474
- var shadowmap_pars_fragment = "#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\tfloat depth = unpackRGBAToDepth( texture2D( depths, uv ) );\n\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\treturn step( depth, compare );\n\t\t#else\n\t\t\treturn step( compare, depth );\n\t\t#endif\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow( sampler2D shadow, vec2 uv, float compare ) {\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\tfloat hard_shadow = step( distribution.x, compare );\n\t\t#else\n\t\t\tfloat hard_shadow = step( compare, distribution.x );\n\t\t#endif\n\t\tif ( hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\t\n\t\tfloat lightToPositionLength = length( lightToPosition );\n\t\tif ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t\t) * ( 1.0 / 9.0 );\n\t\t\t#else\n\t\t\t\tshadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n#endif";
477
+ var shadowmap_pars_fragment = "#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\t#else\n\t\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tuniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\t#elif defined( SHADOWMAP_TYPE_BASIC )\n\t\t\tuniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\t#endif\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\tfloat interleavedGradientNoise( vec2 position ) {\n\t\t\treturn fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) );\n\t\t}\n\t\tvec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) {\n\t\t\tconst float goldenAngle = 2.399963229728653;\n\t\t\tfloat r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) );\n\t\t\tfloat theta = float( sampleIndex ) * goldenAngle + phi;\n\t\t\treturn vec2( cos( theta ), sin( theta ) ) * r;\n\t\t}\n\t#endif\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\tfloat getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\tshadowCoord.z += shadowBias;\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\t\tfloat radius = shadowRadius * texelSize.x;\n\t\t\t\tfloat phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) +\n\t\t\t\t\ttexture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) )\n\t\t\t\t) * 0.2;\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tvec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg;\n\t\t\t\tfloat mean = distribution.x;\n\t\t\t\tfloat variance = distribution.y * distribution.y;\n\t\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\t\tfloat hard_shadow = step( mean, shadowCoord.z );\n\t\t\t\t#else\n\t\t\t\t\tfloat hard_shadow = step( shadowCoord.z, mean );\n\t\t\t\t#endif\n\t\t\t\t\n\t\t\t\tif ( hard_shadow == 1.0 ) {\n\t\t\t\t\tshadow = 1.0;\n\t\t\t\t} else {\n\t\t\t\t\tvariance = max( variance, 0.0000001 );\n\t\t\t\t\tfloat d = shadowCoord.z - mean;\n\t\t\t\t\tfloat p_max = variance / ( variance + d * d );\n\t\t\t\t\tp_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 );\n\t\t\t\t\tshadow = max( hard_shadow, p_max );\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#else\n\t\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\t\tfloat shadow = 1.0;\n\t\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tshadowCoord.z -= shadowBias;\n\t\t\t#else\n\t\t\t\tshadowCoord.z += shadowBias;\n\t\t\t#endif\n\t\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\t\tif ( frustumTest ) {\n\t\t\t\tfloat depth = texture2D( shadowMap, shadowCoord.xy ).r;\n\t\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\t\tshadow = step( depth, shadowCoord.z );\n\t\t\t\t#else\n\t\t\t\t\tshadow = step( shadowCoord.z, depth );\n\t\t\t\t#endif\n\t\t\t}\n\t\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t\t}\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#if defined( SHADOWMAP_TYPE_PCF )\n\tfloat getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\tvec3 absVec = abs( lightToPosition );\n\t\tfloat viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );\n\t\tif ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tfloat dp = ( shadowCameraNear * ( shadowCameraFar - viewSpaceZ ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\t\tdp -= shadowBias;\n\t\t\t#else\n\t\t\t\tfloat dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\t\tdp += shadowBias;\n\t\t\t#endif\n\t\t\tfloat texelSize = shadowRadius / shadowMapSize.x;\n\t\t\tvec3 absDir = abs( bd3D );\n\t\t\tvec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );\n\t\t\ttangent = normalize( cross( bd3D, tangent ) );\n\t\t\tvec3 bitangent = cross( bd3D, tangent );\n\t\t\tfloat phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;\n\t\t\tvec2 sample0 = vogelDiskSample( 0, 5, phi );\n\t\t\tvec2 sample1 = vogelDiskSample( 1, 5, phi );\n\t\t\tvec2 sample2 = vogelDiskSample( 2, 5, phi );\n\t\t\tvec2 sample3 = vogelDiskSample( 3, 5, phi );\n\t\t\tvec2 sample4 = vogelDiskSample( 4, 5, phi );\n\t\t\tshadow = (\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample0.x + bitangent * sample0.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample1.x + bitangent * sample1.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample2.x + bitangent * sample2.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample3.x + bitangent * sample3.y ) * texelSize, dp ) ) +\n\t\t\t\ttexture( shadowMap, vec4( bd3D + ( tangent * sample4.x + bitangent * sample4.y ) * texelSize, dp ) )\n\t\t\t) * 0.2;\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\t#elif defined( SHADOWMAP_TYPE_BASIC )\n\tfloat getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tvec3 absVec = abs( lightToPosition );\n\t\tfloat viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );\n\t\tif ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );\n\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tfloat depth = textureCube( shadowMap, bd3D ).r;\n\t\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\t\tdepth = 1.0 - depth;\n\t\t\t#endif\n\t\t\tshadow = step( dp, depth );\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\t#endif\n\t#endif\n#endif";
475
478
 
476
479
  var shadowmap_pars_vertex = "#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";
477
480
 
478
- var shadowmap_vertex = "#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif";
481
+ var shadowmap_vertex = "#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\t#ifdef HAS_NORMAL\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t#else\n\t\tvec3 shadowWorldNormal = vec3( 0.0 );\n\t#endif\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif";
479
482
 
480
- var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";
483
+ var shadowmask_pars_fragment = "float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";
481
484
 
482
485
  var skinbase_vertex = "#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";
483
486
 
@@ -495,7 +498,7 @@ var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = to
495
498
 
496
499
  var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }";
497
500
 
498
- var transmission_fragment = "#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif";
501
+ var transmission_fragment = "#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif";
499
502
 
500
503
  var transmission_pars_fragment = "#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t#else\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif";
501
504
 
@@ -513,7 +516,7 @@ const fragment$h = "uniform sampler2D t2D;\nuniform float backgroundIntensity;\n
513
516
 
514
517
  const vertex$g = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
515
518
 
516
- const fragment$g = "#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}";
519
+ const fragment$g = "#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vWorldDirection );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}";
517
520
 
518
521
  const vertex$f = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";
519
522
 
@@ -525,7 +528,7 @@ const fragment$e = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\
525
528
 
526
529
  const vertex$d = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";
527
530
 
528
- const fragment$d = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";
531
+ const fragment$d = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = vec4( dist, 0.0, 0.0, 1.0 );\n}";
529
532
 
530
533
  const vertex$c = "varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";
531
534
 
@@ -541,7 +544,7 @@ const fragment$a = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_
541
544
 
542
545
  const vertex$9 = "#define LAMBERT\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
543
546
 
544
- const fragment$9 = "#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_lambert_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_lambert_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
547
+ const fragment$9 = "#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_lambert_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_lambert_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
545
548
 
546
549
  const vertex$8 = "#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";
547
550
 
@@ -549,19 +552,19 @@ const fragment$8 = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity
549
552
 
550
553
  const vertex$7 = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";
551
554
 
552
- const fragment$7 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}";
555
+ const fragment$7 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}";
553
556
 
554
557
  const vertex$6 = "#define PHONG\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
555
558
 
556
- const fragment$6 = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
559
+ const fragment$6 = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
557
560
 
558
561
  const vertex$5 = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}";
559
562
 
560
- const fragment$5 = "#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
563
+ const fragment$5 = "#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n \n\t\toutgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;\n \n \t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
561
564
 
562
565
  const vertex$4 = "#define TOON\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
563
566
 
564
- const fragment$4 = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
567
+ const fragment$4 = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";
565
568
 
566
569
  const vertex$3 = "uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";
567
570
 
@@ -569,7 +572,7 @@ const fragment$3 = "uniform vec3 diffuse;\nuniform float opacity;\n#include <com
569
572
 
570
573
  const vertex$2 = "#include <common>\n#include <batching_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";
571
574
 
572
- const fragment$2 = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <logdepthbuf_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n}";
575
+ const fragment$2 = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <logdepthbuf_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";
573
576
 
574
577
  const vertex$1 = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
575
578
 
@@ -632,6 +635,7 @@ const ShaderChunk = {
632
635
  lights_fragment_begin: lights_fragment_begin,
633
636
  lights_fragment_maps: lights_fragment_maps,
634
637
  lights_fragment_end: lights_fragment_end,
638
+ lightprobes_pars_fragment: lightprobes_pars_fragment,
635
639
  logdepthbuf_fragment: logdepthbuf_fragment,
636
640
  logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
637
641
  logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
@@ -692,8 +696,8 @@ const ShaderChunk = {
692
696
  cube_frag: fragment$f,
693
697
  depth_vert: vertex$e,
694
698
  depth_frag: fragment$e,
695
- distanceRGBA_vert: vertex$d,
696
- distanceRGBA_frag: fragment$d,
699
+ distance_vert: vertex$d,
700
+ distance_frag: fragment$d,
697
701
  equirect_vert: vertex$c,
698
702
  equirect_frag: fragment$c,
699
703
  linedashed_vert: vertex$b,
@@ -749,7 +753,6 @@ const UniformsLib = {
749
753
 
750
754
  envMap: { value: null },
751
755
  envMapRotation: { value: /*@__PURE__*/ new Matrix3() },
752
- flipEnvMap: { value: -1 },
753
756
  reflectivity: { value: 1.0 }, // basic, lambert, phong
754
757
  ior: { value: 1.5 }, // physical
755
758
  refractionRatio: { value: 0.98 }, // basic, lambert, phong
@@ -853,7 +856,6 @@ const UniformsLib = {
853
856
  shadowMapSize: {}
854
857
  } },
855
858
 
856
- directionalShadowMap: { value: [] },
857
859
  directionalShadowMatrix: { value: [] },
858
860
 
859
861
  spotLights: { value: [], properties: {
@@ -875,7 +877,6 @@ const UniformsLib = {
875
877
  } },
876
878
 
877
879
  spotLightMap: { value: [] },
878
- spotShadowMap: { value: [] },
879
880
  spotLightMatrix: { value: [] },
880
881
 
881
882
  pointLights: { value: [], properties: {
@@ -895,7 +896,6 @@ const UniformsLib = {
895
896
  shadowCameraFar: {}
896
897
  } },
897
898
 
898
- pointShadowMap: { value: [] },
899
899
  pointShadowMatrix: { value: [] },
900
900
 
901
901
  hemisphereLights: { value: [], properties: {
@@ -913,7 +913,12 @@ const UniformsLib = {
913
913
  } },
914
914
 
915
915
  ltc_1: { value: null },
916
- ltc_2: { value: null }
916
+ ltc_2: { value: null },
917
+
918
+ probesSH: { value: null },
919
+ probesMin: { value: /*@__PURE__*/ new Vector3() },
920
+ probesMax: { value: /*@__PURE__*/ new Vector3() },
921
+ probesResolution: { value: /*@__PURE__*/ new Vector3() }
917
922
 
918
923
  },
919
924
 
@@ -980,7 +985,8 @@ const ShaderLib = {
980
985
  UniformsLib.fog,
981
986
  UniformsLib.lights,
982
987
  {
983
- emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) }
988
+ emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) },
989
+ envMapIntensity: { value: 1 }
984
990
  }
985
991
  ] ),
986
992
 
@@ -1006,7 +1012,8 @@ const ShaderLib = {
1006
1012
  {
1007
1013
  emissive: { value: /*@__PURE__*/ new Color( 0x000000 ) },
1008
1014
  specular: { value: /*@__PURE__*/ new Color( 0x111111 ) },
1009
- shininess: { value: 30 }
1015
+ shininess: { value: 30 },
1016
+ envMapIntensity: { value: 1 }
1010
1017
  }
1011
1018
  ] ),
1012
1019
 
@@ -1171,7 +1178,6 @@ const ShaderLib = {
1171
1178
 
1172
1179
  uniforms: {
1173
1180
  envMap: { value: null },
1174
- flipEnvMap: { value: -1 },
1175
1181
  backgroundBlurriness: { value: 0 },
1176
1182
  backgroundIntensity: { value: 1 },
1177
1183
  backgroundRotation: { value: /*@__PURE__*/ new Matrix3() }
@@ -1206,7 +1212,7 @@ const ShaderLib = {
1206
1212
 
1207
1213
  },
1208
1214
 
1209
- distanceRGBA: {
1215
+ distance: {
1210
1216
 
1211
1217
  uniforms: /*@__PURE__*/ mergeUniforms( [
1212
1218
  UniformsLib.common,
@@ -1218,8 +1224,8 @@ const ShaderLib = {
1218
1224
  }
1219
1225
  ] ),
1220
1226
 
1221
- vertexShader: ShaderChunk.distanceRGBA_vert,
1222
- fragmentShader: ShaderChunk.distanceRGBA_frag
1227
+ vertexShader: ShaderChunk.distance_vert,
1228
+ fragmentShader: ShaderChunk.distance_frag
1223
1229
 
1224
1230
  },
1225
1231
 
@@ -1299,10 +1305,12 @@ ShaderLib.physical = {
1299
1305
  };
1300
1306
 
1301
1307
  const _rgb = { r: 0, b: 0, g: 0 };
1302
- const _e1$1 = /*@__PURE__*/ new Euler();
1303
1308
  const _m1$1 = /*@__PURE__*/ new Matrix4();
1309
+ const _m$1 = /*@__PURE__*/ new Matrix3();
1304
1310
 
1305
- function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha, premultipliedAlpha ) {
1311
+ _m$1.set( -1, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 );
1312
+
1313
+ function WebGLBackground( renderer, environments, state, objects, alpha, premultipliedAlpha ) {
1306
1314
 
1307
1315
  const clearColor = new Color( 0x000000 );
1308
1316
  let clearAlpha = alpha === true ? 0 : 1;
@@ -1321,7 +1329,7 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
1321
1329
  if ( background && background.isTexture ) {
1322
1330
 
1323
1331
  const usePMREM = scene.backgroundBlurriness > 0; // use PMREM if the user wants to blur the background
1324
- background = ( usePMREM ? cubeuvmaps : cubemaps ).get( background );
1332
+ background = environments.get( background, usePMREM );
1325
1333
 
1326
1334
  }
1327
1335
 
@@ -1418,24 +1426,22 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
1418
1426
 
1419
1427
  }
1420
1428
 
1421
- _e1$1.copy( scene.backgroundRotation );
1422
1429
 
1423
- // accommodate left-handed frame
1424
- _e1$1.x *= -1; _e1$1.y *= -1; _e1$1.z *= -1;
1430
+ boxMesh.material.uniforms.envMap.value = background;
1431
+ boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness;
1432
+ boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;
1433
+
1434
+
1435
+ // note: since the matrix is orthonormal, we can use the more-efficient transpose() in lieu of invert()
1436
+ boxMesh.material.uniforms.backgroundRotation.value.setFromMatrix4( _m1$1.makeRotationFromEuler( scene.backgroundRotation ) ).transpose();
1425
1437
 
1426
1438
  if ( background.isCubeTexture && background.isRenderTargetTexture === false ) {
1427
1439
 
1428
- // environment maps which are not cube render targets or PMREMs follow a different convention
1429
- _e1$1.y *= -1;
1430
- _e1$1.z *= -1;
1440
+ boxMesh.material.uniforms.backgroundRotation.value.premultiply( _m$1 );
1431
1441
 
1432
1442
  }
1433
1443
 
1434
- boxMesh.material.uniforms.envMap.value = background;
1435
- boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background.isRenderTargetTexture === false ) ? -1 : 1;
1436
- boxMesh.material.uniforms.backgroundBlurriness.value = scene.backgroundBlurriness;
1437
- boxMesh.material.uniforms.backgroundIntensity.value = scene.backgroundIntensity;
1438
- boxMesh.material.uniforms.backgroundRotation.value.setFromMatrix4( _m1$1.makeRotationFromEuler( _e1$1 ) );
1444
+
1439
1445
  boxMesh.material.toneMapped = ColorManagement.getTransfer( background.colorSpace ) !== SRGBTransfer;
1440
1446
 
1441
1447
  if ( currentBackground !== background ||
@@ -1601,7 +1607,7 @@ function WebGLBindingStates( gl, attributes ) {
1601
1607
 
1602
1608
  let updateBuffers = false;
1603
1609
 
1604
- const state = getBindingState( geometry, program, material );
1610
+ const state = getBindingState( object, geometry, program, material );
1605
1611
 
1606
1612
  if ( currentState !== state ) {
1607
1613
 
@@ -1654,16 +1660,28 @@ function WebGLBindingStates( gl, attributes ) {
1654
1660
 
1655
1661
  }
1656
1662
 
1657
- function getBindingState( geometry, program, material ) {
1663
+ function getBindingState( object, geometry, program, material ) {
1658
1664
 
1659
1665
  const wireframe = ( material.wireframe === true );
1660
1666
 
1661
- let programMap = bindingStates[ geometry.id ];
1667
+ let objectMap = bindingStates[ geometry.id ];
1668
+
1669
+ if ( objectMap === undefined ) {
1670
+
1671
+ objectMap = {};
1672
+ bindingStates[ geometry.id ] = objectMap;
1673
+
1674
+ }
1675
+
1676
+ // Each InstancedMesh requires unique binding states because it contains instanced attributes.
1677
+ const objectId = ( object.isInstancedMesh === true ) ? object.id : 0;
1678
+
1679
+ let programMap = objectMap[ objectId ];
1662
1680
 
1663
1681
  if ( programMap === undefined ) {
1664
1682
 
1665
1683
  programMap = {};
1666
- bindingStates[ geometry.id ] = programMap;
1684
+ objectMap[ objectId ] = programMap;
1667
1685
 
1668
1686
  }
1669
1687
 
@@ -2064,21 +2082,27 @@ function WebGLBindingStates( gl, attributes ) {
2064
2082
 
2065
2083
  for ( const geometryId in bindingStates ) {
2066
2084
 
2067
- const programMap = bindingStates[ geometryId ];
2085
+ const objectMap = bindingStates[ geometryId ];
2068
2086
 
2069
- for ( const programId in programMap ) {
2087
+ for ( const objectId in objectMap ) {
2070
2088
 
2071
- const stateMap = programMap[ programId ];
2089
+ const programMap = objectMap[ objectId ];
2072
2090
 
2073
- for ( const wireframe in stateMap ) {
2091
+ for ( const programId in programMap ) {
2074
2092
 
2075
- deleteVertexArrayObject( stateMap[ wireframe ].object );
2093
+ const stateMap = programMap[ programId ];
2076
2094
 
2077
- delete stateMap[ wireframe ];
2095
+ for ( const wireframe in stateMap ) {
2078
2096
 
2079
- }
2097
+ deleteVertexArrayObject( stateMap[ wireframe ].object );
2080
2098
 
2081
- delete programMap[ programId ];
2099
+ delete stateMap[ wireframe ];
2100
+
2101
+ }
2102
+
2103
+ delete programMap[ programId ];
2104
+
2105
+ }
2082
2106
 
2083
2107
  }
2084
2108
 
@@ -2092,21 +2116,27 @@ function WebGLBindingStates( gl, attributes ) {
2092
2116
 
2093
2117
  if ( bindingStates[ geometry.id ] === undefined ) return;
2094
2118
 
2095
- const programMap = bindingStates[ geometry.id ];
2119
+ const objectMap = bindingStates[ geometry.id ];
2096
2120
 
2097
- for ( const programId in programMap ) {
2121
+ for ( const objectId in objectMap ) {
2098
2122
 
2099
- const stateMap = programMap[ programId ];
2123
+ const programMap = objectMap[ objectId ];
2124
+
2125
+ for ( const programId in programMap ) {
2100
2126
 
2101
- for ( const wireframe in stateMap ) {
2127
+ const stateMap = programMap[ programId ];
2102
2128
 
2103
- deleteVertexArrayObject( stateMap[ wireframe ].object );
2129
+ for ( const wireframe in stateMap ) {
2104
2130
 
2105
- delete stateMap[ wireframe ];
2131
+ deleteVertexArrayObject( stateMap[ wireframe ].object );
2106
2132
 
2107
- }
2133
+ delete stateMap[ wireframe ];
2134
+
2135
+ }
2136
+
2137
+ delete programMap[ programId ];
2108
2138
 
2109
- delete programMap[ programId ];
2139
+ }
2110
2140
 
2111
2141
  }
2112
2142
 
@@ -2118,26 +2148,73 @@ function WebGLBindingStates( gl, attributes ) {
2118
2148
 
2119
2149
  for ( const geometryId in bindingStates ) {
2120
2150
 
2121
- const programMap = bindingStates[ geometryId ];
2151
+ const objectMap = bindingStates[ geometryId ];
2152
+
2153
+ for ( const objectId in objectMap ) {
2154
+
2155
+ const programMap = objectMap[ objectId ];
2156
+
2157
+ if ( programMap[ program.id ] === undefined ) continue;
2158
+
2159
+ const stateMap = programMap[ program.id ];
2160
+
2161
+ for ( const wireframe in stateMap ) {
2162
+
2163
+ deleteVertexArrayObject( stateMap[ wireframe ].object );
2164
+
2165
+ delete stateMap[ wireframe ];
2166
+
2167
+ }
2168
+
2169
+ delete programMap[ program.id ];
2170
+
2171
+ }
2172
+
2173
+ }
2174
+
2175
+ }
2176
+
2177
+ function releaseStatesOfObject( object ) {
2178
+
2179
+ for ( const geometryId in bindingStates ) {
2180
+
2181
+ const objectMap = bindingStates[ geometryId ];
2182
+
2183
+ const objectId = ( object.isInstancedMesh === true ) ? object.id : 0;
2184
+
2185
+ const programMap = objectMap[ objectId ];
2186
+
2187
+ if ( programMap === undefined ) continue;
2122
2188
 
2123
- if ( programMap[ program.id ] === undefined ) continue;
2189
+ for ( const programId in programMap ) {
2190
+
2191
+ const stateMap = programMap[ programId ];
2192
+
2193
+ for ( const wireframe in stateMap ) {
2124
2194
 
2125
- const stateMap = programMap[ program.id ];
2195
+ deleteVertexArrayObject( stateMap[ wireframe ].object );
2126
2196
 
2127
- for ( const wireframe in stateMap ) {
2197
+ delete stateMap[ wireframe ];
2128
2198
 
2129
- deleteVertexArrayObject( stateMap[ wireframe ].object );
2199
+ }
2130
2200
 
2131
- delete stateMap[ wireframe ];
2201
+ delete programMap[ programId ];
2132
2202
 
2133
2203
  }
2134
2204
 
2135
- delete programMap[ program.id ];
2205
+ delete objectMap[ objectId ];
2206
+
2207
+ if ( Object.keys( objectMap ).length === 0 ) {
2208
+
2209
+ delete bindingStates[ geometryId ];
2210
+
2211
+ }
2136
2212
 
2137
2213
  }
2138
2214
 
2139
2215
  }
2140
2216
 
2217
+
2141
2218
  function reset() {
2142
2219
 
2143
2220
  resetDefaultState();
@@ -2167,6 +2244,7 @@ function WebGLBindingStates( gl, attributes ) {
2167
2244
  resetDefaultState: resetDefaultState,
2168
2245
  dispose: dispose,
2169
2246
  releaseStatesOfGeometry: releaseStatesOfGeometry,
2247
+ releaseStatesOfObject: releaseStatesOfObject,
2170
2248
  releaseStatesOfProgram: releaseStatesOfProgram,
2171
2249
 
2172
2250
  initAttributes: initAttributes,
@@ -2223,44 +2301,12 @@ function WebGLBufferRenderer( gl, extensions, info ) {
2223
2301
 
2224
2302
  }
2225
2303
 
2226
- function renderMultiDrawInstances( starts, counts, drawCount, primcount ) {
2227
-
2228
- if ( drawCount === 0 ) return;
2229
-
2230
- const extension = extensions.get( 'WEBGL_multi_draw' );
2231
-
2232
- if ( extension === null ) {
2233
-
2234
- for ( let i = 0; i < starts.length; i ++ ) {
2235
-
2236
- renderInstances( starts[ i ], counts[ i ], primcount[ i ] );
2237
-
2238
- }
2239
-
2240
- } else {
2241
-
2242
- extension.multiDrawArraysInstancedWEBGL( mode, starts, 0, counts, 0, primcount, 0, drawCount );
2243
-
2244
- let elementCount = 0;
2245
- for ( let i = 0; i < drawCount; i ++ ) {
2246
-
2247
- elementCount += counts[ i ] * primcount[ i ];
2248
-
2249
- }
2250
-
2251
- info.update( elementCount, mode, 1 );
2252
-
2253
- }
2254
-
2255
- }
2256
-
2257
2304
  //
2258
2305
 
2259
2306
  this.setMode = setMode;
2260
2307
  this.render = render;
2261
2308
  this.renderInstances = renderInstances;
2262
2309
  this.renderMultiDraw = renderMultiDraw;
2263
- this.renderMultiDrawInstances = renderMultiDrawInstances;
2264
2310
 
2265
2311
  }
2266
2312
 
@@ -2358,6 +2404,12 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
2358
2404
  const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
2359
2405
  const reversedDepthBuffer = parameters.reversedDepthBuffer === true && extensions.has( 'EXT_clip_control' );
2360
2406
 
2407
+ if ( parameters.reversedDepthBuffer === true && reversedDepthBuffer === false ) {
2408
+
2409
+ warn( 'WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.' );
2410
+
2411
+ }
2412
+
2361
2413
  const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
2362
2414
  const maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
2363
2415
  const maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
@@ -2368,9 +2420,8 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
2368
2420
  const maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
2369
2421
  const maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
2370
2422
 
2371
- const vertexTextures = maxVertexTextures > 0;
2372
-
2373
2423
  const maxSamples = gl.getParameter( gl.MAX_SAMPLES );
2424
+ const samples = gl.getParameter( gl.SAMPLES );
2374
2425
 
2375
2426
  return {
2376
2427
 
@@ -2396,9 +2447,9 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
2396
2447
  maxVaryings: maxVaryings,
2397
2448
  maxFragmentUniforms: maxFragmentUniforms,
2398
2449
 
2399
- vertexTextures: vertexTextures,
2450
+ maxSamples: maxSamples,
2400
2451
 
2401
- maxSamples: maxSamples
2452
+ samples: samples
2402
2453
 
2403
2454
  };
2404
2455
 
@@ -2570,101 +2621,6 @@ function WebGLClipping( properties ) {
2570
2621
 
2571
2622
  }
2572
2623
 
2573
- function WebGLCubeMaps( renderer ) {
2574
-
2575
- let cubemaps = new WeakMap();
2576
-
2577
- function mapTextureMapping( texture, mapping ) {
2578
-
2579
- if ( mapping === EquirectangularReflectionMapping ) {
2580
-
2581
- texture.mapping = CubeReflectionMapping;
2582
-
2583
- } else if ( mapping === EquirectangularRefractionMapping ) {
2584
-
2585
- texture.mapping = CubeRefractionMapping;
2586
-
2587
- }
2588
-
2589
- return texture;
2590
-
2591
- }
2592
-
2593
- function get( texture ) {
2594
-
2595
- if ( texture && texture.isTexture ) {
2596
-
2597
- const mapping = texture.mapping;
2598
-
2599
- if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) {
2600
-
2601
- if ( cubemaps.has( texture ) ) {
2602
-
2603
- const cubemap = cubemaps.get( texture ).texture;
2604
- return mapTextureMapping( cubemap, texture.mapping );
2605
-
2606
- } else {
2607
-
2608
- const image = texture.image;
2609
-
2610
- if ( image && image.height > 0 ) {
2611
-
2612
- const renderTarget = new WebGLCubeRenderTarget( image.height );
2613
- renderTarget.fromEquirectangularTexture( renderer, texture );
2614
- cubemaps.set( texture, renderTarget );
2615
-
2616
- texture.addEventListener( 'dispose', onTextureDispose );
2617
-
2618
- return mapTextureMapping( renderTarget.texture, texture.mapping );
2619
-
2620
- } else {
2621
-
2622
- // image not yet ready. try the conversion next frame
2623
-
2624
- return null;
2625
-
2626
- }
2627
-
2628
- }
2629
-
2630
- }
2631
-
2632
- }
2633
-
2634
- return texture;
2635
-
2636
- }
2637
-
2638
- function onTextureDispose( event ) {
2639
-
2640
- const texture = event.target;
2641
-
2642
- texture.removeEventListener( 'dispose', onTextureDispose );
2643
-
2644
- const cubemap = cubemaps.get( texture );
2645
-
2646
- if ( cubemap !== undefined ) {
2647
-
2648
- cubemaps.delete( texture );
2649
- cubemap.dispose();
2650
-
2651
- }
2652
-
2653
- }
2654
-
2655
- function dispose() {
2656
-
2657
- cubemaps = new WeakMap();
2658
-
2659
- }
2660
-
2661
- return {
2662
- get: get,
2663
- dispose: dispose
2664
- };
2665
-
2666
- }
2667
-
2668
2624
  const LOD_MIN = 4;
2669
2625
 
2670
2626
  // The standard deviations (radians) associated with the extra mips.
@@ -2744,7 +2700,7 @@ class PMREMGenerator {
2744
2700
  * @param {number} [far=100] - The far plane distance.
2745
2701
  * @param {Object} [options={}] - The configuration options.
2746
2702
  * @param {number} [options.size=256] - The texture size of the PMREM.
2747
- * @param {Vector3} [options.renderTarget=origin] - The position of the internal cube camera that renders the scene.
2703
+ * @param {Vector3} [options.position=origin] - The position of the internal cube camera that renders the scene.
2748
2704
  * @return {WebGLRenderTarget} The resulting PMREM.
2749
2705
  */
2750
2706
  fromScene( scene, sigma = 0, near = 0.1, far = 100, options = {} ) {
@@ -2955,6 +2911,7 @@ class PMREMGenerator {
2955
2911
  ( { lodMeshes: this._lodMeshes, sizeLods: this._sizeLods, sigmas: this._sigmas } = _createPlanes( _lodMax ) );
2956
2912
 
2957
2913
  this._blurMaterial = _getBlurShader( _lodMax, width, height );
2914
+ this._ggxMaterial = _getGGXShader( _lodMax, width, height );
2958
2915
 
2959
2916
  }
2960
2917
 
@@ -3160,14 +3117,6 @@ class PMREMGenerator {
3160
3117
  const renderer = this._renderer;
3161
3118
  const pingPongRenderTarget = this._pingPongRenderTarget;
3162
3119
 
3163
- if ( this._ggxMaterial === null ) {
3164
-
3165
- const width = 3 * Math.max( this._cubeSize, 16 );
3166
- const height = 4 * this._cubeSize;
3167
- this._ggxMaterial = _getGGXShader( this._lodMax, width, height );
3168
-
3169
- }
3170
-
3171
3120
  const ggxMaterial = this._ggxMaterial;
3172
3121
  const ggxMesh = this._lodMeshes[ lodOut ];
3173
3122
  ggxMesh.material = ggxMaterial;
@@ -3180,7 +3129,7 @@ class PMREMGenerator {
3180
3129
  const incrementalRoughness = Math.sqrt( targetRoughness * targetRoughness - sourceRoughness * sourceRoughness );
3181
3130
 
3182
3131
  // Apply blur strength mapping for better quality across the roughness range
3183
- const blurStrength = 0.05 + targetRoughness * 0.95;
3132
+ const blurStrength = 0.0 + targetRoughness * 1.25;
3184
3133
  const adjustedRoughness = incrementalRoughness * blurStrength;
3185
3134
 
3186
3135
  // Calculate viewport position based on output LOD level
@@ -3493,24 +3442,20 @@ function _getGGXShader( lodMax, width, height ) {
3493
3442
  vec3 importanceSampleGGX_VNDF(vec2 Xi, vec3 V, float roughness) {
3494
3443
  float alpha = roughness * roughness;
3495
3444
 
3496
- // Section 3.2: Transform view direction to hemisphere configuration
3497
- vec3 Vh = normalize(vec3(alpha * V.x, alpha * V.y, V.z));
3498
-
3499
3445
  // Section 4.1: Orthonormal basis
3500
- float lensq = Vh.x * Vh.x + Vh.y * Vh.y;
3501
- vec3 T1 = lensq > 0.0 ? vec3(-Vh.y, Vh.x, 0.0) / sqrt(lensq) : vec3(1.0, 0.0, 0.0);
3502
- vec3 T2 = cross(Vh, T1);
3446
+ vec3 T1 = vec3(1.0, 0.0, 0.0);
3447
+ vec3 T2 = cross(V, T1);
3503
3448
 
3504
3449
  // Section 4.2: Parameterization of projected area
3505
3450
  float r = sqrt(Xi.x);
3506
3451
  float phi = 2.0 * PI * Xi.y;
3507
3452
  float t1 = r * cos(phi);
3508
3453
  float t2 = r * sin(phi);
3509
- float s = 0.5 * (1.0 + Vh.z);
3454
+ float s = 0.5 * (1.0 + V.z);
3510
3455
  t2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2;
3511
3456
 
3512
3457
  // Section 4.3: Reprojection onto hemisphere
3513
- vec3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * Vh;
3458
+ vec3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * V;
3514
3459
 
3515
3460
  // Section 3.4: Transform back to ellipsoid configuration
3516
3461
  return normalize(vec3(alpha * Nh.x, alpha * Nh.y, max(0.0, Nh.z)));
@@ -3816,72 +3761,304 @@ function _getCommonVertexShader() {
3816
3761
 
3817
3762
  }
3818
3763
 
3819
- function WebGLCubeUVMaps( renderer ) {
3764
+ /**
3765
+ * A cube render target used in context of {@link WebGLRenderer}.
3766
+ *
3767
+ * @augments WebGLRenderTarget
3768
+ */
3769
+ class WebGLCubeRenderTarget extends WebGLRenderTarget {
3820
3770
 
3821
- let cubeUVmaps = new WeakMap();
3771
+ /**
3772
+ * Constructs a new cube render target.
3773
+ *
3774
+ * @param {number} [size=1] - The size of the render target.
3775
+ * @param {RenderTarget~Options} [options] - The configuration object.
3776
+ */
3777
+ constructor( size = 1, options = {} ) {
3822
3778
 
3823
- let pmremGenerator = null;
3779
+ super( size, size, options );
3824
3780
 
3825
- function get( texture ) {
3781
+ /**
3782
+ * This flag can be used for type testing.
3783
+ *
3784
+ * @type {boolean}
3785
+ * @readonly
3786
+ * @default true
3787
+ */
3788
+ this.isWebGLCubeRenderTarget = true;
3826
3789
 
3827
- if ( texture && texture.isTexture ) {
3790
+ const image = { width: size, height: size, depth: 1 };
3791
+ const images = [ image, image, image, image, image, image ];
3828
3792
 
3829
- const mapping = texture.mapping;
3793
+ /**
3794
+ * Overwritten with a different texture type.
3795
+ *
3796
+ * @type {DataArrayTexture}
3797
+ */
3798
+ this.texture = new CubeTexture( images );
3799
+ this._setTextureOptions( options );
3830
3800
 
3831
- const isEquirectMap = ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping );
3832
- const isCubeMap = ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping );
3801
+ // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
3802
+ // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
3803
+ // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
3833
3804
 
3834
- // equirect/cube map to cubeUV conversion
3805
+ // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
3806
+ // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture
3807
+ // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).
3835
3808
 
3836
- if ( isEquirectMap || isCubeMap ) {
3809
+ this.texture.isRenderTargetTexture = true;
3837
3810
 
3838
- let renderTarget = cubeUVmaps.get( texture );
3811
+ }
3839
3812
 
3840
- const currentPMREMVersion = renderTarget !== undefined ? renderTarget.texture.pmremVersion : 0;
3813
+ /**
3814
+ * Converts the given equirectangular texture to a cube map.
3815
+ *
3816
+ * @param {WebGLRenderer} renderer - The renderer.
3817
+ * @param {Texture} texture - The equirectangular texture.
3818
+ * @return {WebGLCubeRenderTarget} A reference to this cube render target.
3819
+ */
3820
+ fromEquirectangularTexture( renderer, texture ) {
3841
3821
 
3842
- if ( texture.isRenderTargetTexture && texture.pmremVersion !== currentPMREMVersion ) {
3822
+ this.texture.type = texture.type;
3823
+ this.texture.colorSpace = texture.colorSpace;
3843
3824
 
3844
- if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
3825
+ this.texture.generateMipmaps = texture.generateMipmaps;
3826
+ this.texture.minFilter = texture.minFilter;
3827
+ this.texture.magFilter = texture.magFilter;
3845
3828
 
3846
- renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture, renderTarget ) : pmremGenerator.fromCubemap( texture, renderTarget );
3847
- renderTarget.texture.pmremVersion = texture.pmremVersion;
3829
+ const shader = {
3848
3830
 
3849
- cubeUVmaps.set( texture, renderTarget );
3831
+ uniforms: {
3832
+ tEquirect: { value: null },
3833
+ },
3850
3834
 
3851
- return renderTarget.texture;
3835
+ vertexShader: /* glsl */`
3852
3836
 
3853
- } else {
3837
+ varying vec3 vWorldDirection;
3854
3838
 
3855
- if ( renderTarget !== undefined ) {
3839
+ vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
3856
3840
 
3857
- return renderTarget.texture;
3841
+ return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
3858
3842
 
3859
- } else {
3843
+ }
3860
3844
 
3861
- const image = texture.image;
3845
+ void main() {
3862
3846
 
3863
- if ( ( isEquirectMap && image && image.height > 0 ) || ( isCubeMap && image && isCubeTextureComplete( image ) ) ) {
3847
+ vWorldDirection = transformDirection( position, modelMatrix );
3864
3848
 
3865
- if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
3849
+ #include <begin_vertex>
3850
+ #include <project_vertex>
3866
3851
 
3867
- renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );
3868
- renderTarget.texture.pmremVersion = texture.pmremVersion;
3852
+ }
3853
+ `,
3869
3854
 
3870
- cubeUVmaps.set( texture, renderTarget );
3855
+ fragmentShader: /* glsl */`
3871
3856
 
3872
- texture.addEventListener( 'dispose', onTextureDispose );
3857
+ uniform sampler2D tEquirect;
3873
3858
 
3874
- return renderTarget.texture;
3859
+ varying vec3 vWorldDirection;
3875
3860
 
3876
- } else {
3861
+ #include <common>
3877
3862
 
3878
- // image not yet ready. try the conversion next frame
3863
+ void main() {
3879
3864
 
3880
- return null;
3865
+ vec3 direction = normalize( vWorldDirection );
3881
3866
 
3882
- }
3867
+ vec2 sampleUV = equirectUv( direction );
3883
3868
 
3884
- }
3869
+ gl_FragColor = texture2D( tEquirect, sampleUV );
3870
+
3871
+ }
3872
+ `
3873
+ };
3874
+
3875
+ const geometry = new BoxGeometry( 5, 5, 5 );
3876
+
3877
+ const material = new ShaderMaterial( {
3878
+
3879
+ name: 'CubemapFromEquirect',
3880
+
3881
+ uniforms: cloneUniforms( shader.uniforms ),
3882
+ vertexShader: shader.vertexShader,
3883
+ fragmentShader: shader.fragmentShader,
3884
+ side: BackSide,
3885
+ blending: NoBlending
3886
+
3887
+ } );
3888
+
3889
+ material.uniforms.tEquirect.value = texture;
3890
+
3891
+ const mesh = new Mesh( geometry, material );
3892
+
3893
+ const currentMinFilter = texture.minFilter;
3894
+
3895
+ // Avoid blurred poles
3896
+ if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
3897
+
3898
+ const camera = new CubeCamera( 1, 10, this );
3899
+ camera.update( renderer, mesh );
3900
+
3901
+ texture.minFilter = currentMinFilter;
3902
+
3903
+ mesh.geometry.dispose();
3904
+ mesh.material.dispose();
3905
+
3906
+ return this;
3907
+
3908
+ }
3909
+
3910
+ /**
3911
+ * Clears this cube render target.
3912
+ *
3913
+ * @param {WebGLRenderer} renderer - The renderer.
3914
+ * @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
3915
+ * @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
3916
+ * @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
3917
+ */
3918
+ clear( renderer, color = true, depth = true, stencil = true ) {
3919
+
3920
+ const currentRenderTarget = renderer.getRenderTarget();
3921
+
3922
+ for ( let i = 0; i < 6; i ++ ) {
3923
+
3924
+ renderer.setRenderTarget( this, i );
3925
+
3926
+ renderer.clear( color, depth, stencil );
3927
+
3928
+ }
3929
+
3930
+ renderer.setRenderTarget( currentRenderTarget );
3931
+
3932
+ }
3933
+
3934
+ }
3935
+
3936
+ function WebGLEnvironments( renderer ) {
3937
+
3938
+ let cubeMaps = new WeakMap();
3939
+ let pmremMaps = new WeakMap();
3940
+
3941
+ let pmremGenerator = null;
3942
+
3943
+ function get( texture, usePMREM = false ) {
3944
+
3945
+ if ( texture === null || texture === undefined ) return null;
3946
+
3947
+ if ( usePMREM ) {
3948
+
3949
+ return getPMREM( texture );
3950
+
3951
+ }
3952
+
3953
+ return getCube( texture );
3954
+
3955
+ }
3956
+
3957
+ function getCube( texture ) {
3958
+
3959
+ if ( texture && texture.isTexture ) {
3960
+
3961
+ const mapping = texture.mapping;
3962
+
3963
+ if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) {
3964
+
3965
+ if ( cubeMaps.has( texture ) ) {
3966
+
3967
+ const cubemap = cubeMaps.get( texture ).texture;
3968
+ return mapTextureMapping( cubemap, texture.mapping );
3969
+
3970
+ } else {
3971
+
3972
+ const image = texture.image;
3973
+
3974
+ if ( image && image.height > 0 ) {
3975
+
3976
+ const renderTarget = new WebGLCubeRenderTarget( image.height );
3977
+ renderTarget.fromEquirectangularTexture( renderer, texture );
3978
+ cubeMaps.set( texture, renderTarget );
3979
+
3980
+ texture.addEventListener( 'dispose', onCubemapDispose );
3981
+
3982
+ return mapTextureMapping( renderTarget.texture, texture.mapping );
3983
+
3984
+ } else {
3985
+
3986
+ // image not yet ready. try the conversion next frame
3987
+
3988
+ return null;
3989
+
3990
+ }
3991
+
3992
+ }
3993
+
3994
+ }
3995
+
3996
+ }
3997
+
3998
+ return texture;
3999
+
4000
+ }
4001
+
4002
+ function getPMREM( texture ) {
4003
+
4004
+ if ( texture && texture.isTexture ) {
4005
+
4006
+ const mapping = texture.mapping;
4007
+
4008
+ const isEquirectMap = ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping );
4009
+ const isCubeMap = ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping );
4010
+
4011
+ // equirect/cube map to cubeUV conversion
4012
+
4013
+ if ( isEquirectMap || isCubeMap ) {
4014
+
4015
+ let renderTarget = pmremMaps.get( texture );
4016
+
4017
+ const currentPMREMVersion = renderTarget !== undefined ? renderTarget.texture.pmremVersion : 0;
4018
+
4019
+ if ( texture.isRenderTargetTexture && texture.pmremVersion !== currentPMREMVersion ) {
4020
+
4021
+ if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
4022
+
4023
+ renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture, renderTarget ) : pmremGenerator.fromCubemap( texture, renderTarget );
4024
+ renderTarget.texture.pmremVersion = texture.pmremVersion;
4025
+
4026
+ pmremMaps.set( texture, renderTarget );
4027
+
4028
+ return renderTarget.texture;
4029
+
4030
+ } else {
4031
+
4032
+ if ( renderTarget !== undefined ) {
4033
+
4034
+ return renderTarget.texture;
4035
+
4036
+ } else {
4037
+
4038
+ const image = texture.image;
4039
+
4040
+ if ( ( isEquirectMap && image && image.height > 0 ) || ( isCubeMap && image && isCubeTextureComplete( image ) ) ) {
4041
+
4042
+ if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
4043
+
4044
+ renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );
4045
+ renderTarget.texture.pmremVersion = texture.pmremVersion;
4046
+
4047
+ pmremMaps.set( texture, renderTarget );
4048
+
4049
+ texture.addEventListener( 'dispose', onPMREMDispose );
4050
+
4051
+ return renderTarget.texture;
4052
+
4053
+ } else {
4054
+
4055
+ // image not yet ready. try the conversion next frame
4056
+
4057
+ return null;
4058
+
4059
+ }
4060
+
4061
+ }
3885
4062
 
3886
4063
  }
3887
4064
 
@@ -3893,6 +4070,22 @@ function WebGLCubeUVMaps( renderer ) {
3893
4070
 
3894
4071
  }
3895
4072
 
4073
+ function mapTextureMapping( texture, mapping ) {
4074
+
4075
+ if ( mapping === EquirectangularReflectionMapping ) {
4076
+
4077
+ texture.mapping = CubeReflectionMapping;
4078
+
4079
+ } else if ( mapping === EquirectangularRefractionMapping ) {
4080
+
4081
+ texture.mapping = CubeRefractionMapping;
4082
+
4083
+ }
4084
+
4085
+ return texture;
4086
+
4087
+ }
4088
+
3896
4089
  function isCubeTextureComplete( image ) {
3897
4090
 
3898
4091
  let count = 0;
@@ -3906,21 +4099,37 @@ function WebGLCubeUVMaps( renderer ) {
3906
4099
 
3907
4100
  return count === length;
3908
4101
 
4102
+ }
4103
+
4104
+ function onCubemapDispose( event ) {
4105
+
4106
+ const texture = event.target;
4107
+
4108
+ texture.removeEventListener( 'dispose', onCubemapDispose );
4109
+
4110
+ const cubemap = cubeMaps.get( texture );
4111
+
4112
+ if ( cubemap !== undefined ) {
4113
+
4114
+ cubeMaps.delete( texture );
4115
+ cubemap.dispose();
4116
+
4117
+ }
3909
4118
 
3910
4119
  }
3911
4120
 
3912
- function onTextureDispose( event ) {
4121
+ function onPMREMDispose( event ) {
3913
4122
 
3914
4123
  const texture = event.target;
3915
4124
 
3916
- texture.removeEventListener( 'dispose', onTextureDispose );
4125
+ texture.removeEventListener( 'dispose', onPMREMDispose );
3917
4126
 
3918
- const cubemapUV = cubeUVmaps.get( texture );
4127
+ const pmrem = pmremMaps.get( texture );
3919
4128
 
3920
- if ( cubemapUV !== undefined ) {
4129
+ if ( pmrem !== undefined ) {
3921
4130
 
3922
- cubeUVmaps.delete( texture );
3923
- cubemapUV.dispose();
4131
+ pmremMaps.delete( texture );
4132
+ pmrem.dispose();
3924
4133
 
3925
4134
  }
3926
4135
 
@@ -3928,7 +4137,8 @@ function WebGLCubeUVMaps( renderer ) {
3928
4137
 
3929
4138
  function dispose() {
3930
4139
 
3931
- cubeUVmaps = new WeakMap();
4140
+ cubeMaps = new WeakMap();
4141
+ pmremMaps = new WeakMap();
3932
4142
 
3933
4143
  if ( pmremGenerator !== null ) {
3934
4144
 
@@ -4087,6 +4297,12 @@ function WebGLGeometries( gl, attributes, info, bindingStates ) {
4087
4297
  const geometryPosition = geometry.attributes.position;
4088
4298
  let version = 0;
4089
4299
 
4300
+ if ( geometryPosition === undefined ) {
4301
+
4302
+ return;
4303
+
4304
+ }
4305
+
4090
4306
  if ( geometryIndex !== null ) {
4091
4307
 
4092
4308
  const array = geometryIndex.array;
@@ -4102,7 +4318,7 @@ function WebGLGeometries( gl, attributes, info, bindingStates ) {
4102
4318
 
4103
4319
  }
4104
4320
 
4105
- } else if ( geometryPosition !== undefined ) {
4321
+ } else {
4106
4322
 
4107
4323
  const array = geometryPosition.array;
4108
4324
  version = geometryPosition.version;
@@ -4117,13 +4333,11 @@ function WebGLGeometries( gl, attributes, info, bindingStates ) {
4117
4333
 
4118
4334
  }
4119
4335
 
4120
- } else {
4121
-
4122
- return;
4123
-
4124
4336
  }
4125
4337
 
4126
- const attribute = new ( arrayNeedsUint32( indices ) ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
4338
+ // check whether a 32 bit or 16 bit buffer is required to store the indices
4339
+ // account for PRIMITIVE_RESTART_FIXED_INDEX, #24565
4340
+ const attribute = new ( geometryPosition.count >= 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
4127
4341
  attribute.version = version;
4128
4342
 
4129
4343
  // Updating index buffer in VAO now. See WebGLBindingStates
@@ -4237,37 +4451,6 @@ function WebGLIndexedBufferRenderer( gl, extensions, info ) {
4237
4451
 
4238
4452
  }
4239
4453
 
4240
- function renderMultiDrawInstances( starts, counts, drawCount, primcount ) {
4241
-
4242
- if ( drawCount === 0 ) return;
4243
-
4244
- const extension = extensions.get( 'WEBGL_multi_draw' );
4245
-
4246
- if ( extension === null ) {
4247
-
4248
- for ( let i = 0; i < starts.length; i ++ ) {
4249
-
4250
- renderInstances( starts[ i ] / bytesPerElement, counts[ i ], primcount[ i ] );
4251
-
4252
- }
4253
-
4254
- } else {
4255
-
4256
- extension.multiDrawElementsInstancedWEBGL( mode, counts, 0, type, starts, 0, primcount, 0, drawCount );
4257
-
4258
- let elementCount = 0;
4259
- for ( let i = 0; i < drawCount; i ++ ) {
4260
-
4261
- elementCount += counts[ i ] * primcount[ i ];
4262
-
4263
- }
4264
-
4265
- info.update( elementCount, mode, 1 );
4266
-
4267
- }
4268
-
4269
- }
4270
-
4271
4454
  //
4272
4455
 
4273
4456
  this.setMode = setMode;
@@ -4275,7 +4458,6 @@ function WebGLIndexedBufferRenderer( gl, extensions, info ) {
4275
4458
  this.render = render;
4276
4459
  this.renderInstances = renderInstances;
4277
4460
  this.renderMultiDraw = renderMultiDraw;
4278
- this.renderMultiDrawInstances = renderMultiDrawInstances;
4279
4461
 
4280
4462
  }
4281
4463
 
@@ -4606,7 +4788,7 @@ class WebGLMultiview {
4606
4788
 
4607
4789
  }
4608
4790
 
4609
- function WebGLObjects( gl, geometries, attributes, info ) {
4791
+ function WebGLObjects( gl, geometries, attributes, bindingStates, info ) {
4610
4792
 
4611
4793
  let updateMap = new WeakMap();
4612
4794
 
@@ -4681,6 +4863,8 @@ function WebGLObjects( gl, geometries, attributes, info ) {
4681
4863
 
4682
4864
  instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose );
4683
4865
 
4866
+ bindingStates.releaseStatesOfObject( instancedMesh );
4867
+
4684
4868
  attributes.remove( instancedMesh.instanceMatrix );
4685
4869
 
4686
4870
  if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor );
@@ -4696,6 +4880,254 @@ function WebGLObjects( gl, geometries, attributes, info ) {
4696
4880
 
4697
4881
  }
4698
4882
 
4883
+ const toneMappingMap = {
4884
+ [ LinearToneMapping ]: 'LINEAR_TONE_MAPPING',
4885
+ [ ReinhardToneMapping ]: 'REINHARD_TONE_MAPPING',
4886
+ [ CineonToneMapping ]: 'CINEON_TONE_MAPPING',
4887
+ [ ACESFilmicToneMapping ]: 'ACES_FILMIC_TONE_MAPPING',
4888
+ [ AgXToneMapping ]: 'AGX_TONE_MAPPING',
4889
+ [ NeutralToneMapping ]: 'NEUTRAL_TONE_MAPPING',
4890
+ [ CustomToneMapping ]: 'CUSTOM_TONE_MAPPING'
4891
+ };
4892
+
4893
+ function WebGLOutput( type, width, height, depth, stencil ) {
4894
+
4895
+ // render targets for scene and post-processing
4896
+ const targetA = new WebGLRenderTarget( width, height, {
4897
+ type: type,
4898
+ depthBuffer: depth,
4899
+ stencilBuffer: stencil,
4900
+ depthTexture: depth ? new DepthTexture( width, height ) : undefined
4901
+ } );
4902
+
4903
+ const targetB = new WebGLRenderTarget( width, height, {
4904
+ type: HalfFloatType,
4905
+ depthBuffer: false,
4906
+ stencilBuffer: false
4907
+ } );
4908
+
4909
+ // create fullscreen triangle geometry
4910
+ const geometry = new BufferGeometry();
4911
+ geometry.setAttribute( 'position', new Float32BufferAttribute( [ -1, 3, 0, -1, -1, 0, 3, -1, 0 ], 3 ) );
4912
+ geometry.setAttribute( 'uv', new Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) );
4913
+
4914
+ // create output material with tone mapping support
4915
+ const material = new RawShaderMaterial( {
4916
+ uniforms: {
4917
+ tDiffuse: { value: null }
4918
+ },
4919
+ vertexShader: /* glsl */`
4920
+ precision highp float;
4921
+
4922
+ uniform mat4 modelViewMatrix;
4923
+ uniform mat4 projectionMatrix;
4924
+
4925
+ attribute vec3 position;
4926
+ attribute vec2 uv;
4927
+
4928
+ varying vec2 vUv;
4929
+
4930
+ void main() {
4931
+ vUv = uv;
4932
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
4933
+ }`,
4934
+ fragmentShader: /* glsl */`
4935
+ precision highp float;
4936
+
4937
+ uniform sampler2D tDiffuse;
4938
+
4939
+ varying vec2 vUv;
4940
+
4941
+ #include <tonemapping_pars_fragment>
4942
+ #include <colorspace_pars_fragment>
4943
+
4944
+ void main() {
4945
+ gl_FragColor = texture2D( tDiffuse, vUv );
4946
+
4947
+ #ifdef LINEAR_TONE_MAPPING
4948
+ gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
4949
+ #elif defined( REINHARD_TONE_MAPPING )
4950
+ gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
4951
+ #elif defined( CINEON_TONE_MAPPING )
4952
+ gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
4953
+ #elif defined( ACES_FILMIC_TONE_MAPPING )
4954
+ gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
4955
+ #elif defined( AGX_TONE_MAPPING )
4956
+ gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
4957
+ #elif defined( NEUTRAL_TONE_MAPPING )
4958
+ gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
4959
+ #elif defined( CUSTOM_TONE_MAPPING )
4960
+ gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
4961
+ #endif
4962
+
4963
+ #ifdef SRGB_TRANSFER
4964
+ gl_FragColor = sRGBTransferOETF( gl_FragColor );
4965
+ #endif
4966
+ }`,
4967
+ depthTest: false,
4968
+ depthWrite: false
4969
+ } );
4970
+
4971
+ const mesh = new Mesh( geometry, material );
4972
+ const camera = new OrthographicCamera( -1, 1, 1, -1, 0, 1 );
4973
+
4974
+ let _outputColorSpace = null;
4975
+ let _outputToneMapping = null;
4976
+ let _isCompositing = false;
4977
+ let _savedToneMapping;
4978
+ let _savedRenderTarget = null;
4979
+ let _effects = [];
4980
+ let _hasRenderPass = false;
4981
+
4982
+ this.setSize = function ( width, height ) {
4983
+
4984
+ targetA.setSize( width, height );
4985
+ targetB.setSize( width, height );
4986
+
4987
+ for ( let i = 0; i < _effects.length; i ++ ) {
4988
+
4989
+ const effect = _effects[ i ];
4990
+ if ( effect.setSize ) effect.setSize( width, height );
4991
+
4992
+ }
4993
+
4994
+ };
4995
+
4996
+ this.setEffects = function ( effects ) {
4997
+
4998
+ _effects = effects;
4999
+ _hasRenderPass = _effects.length > 0 && _effects[ 0 ].isRenderPass === true;
5000
+
5001
+ const width = targetA.width;
5002
+ const height = targetA.height;
5003
+
5004
+ for ( let i = 0; i < _effects.length; i ++ ) {
5005
+
5006
+ const effect = _effects[ i ];
5007
+ if ( effect.setSize ) effect.setSize( width, height );
5008
+
5009
+ }
5010
+
5011
+ };
5012
+
5013
+ this.begin = function ( renderer, renderTarget ) {
5014
+
5015
+ // Don't begin during compositing phase (post-processing effects call render())
5016
+ if ( _isCompositing ) return false;
5017
+
5018
+ if ( renderer.toneMapping === NoToneMapping && _effects.length === 0 ) return false;
5019
+
5020
+ _savedRenderTarget = renderTarget;
5021
+
5022
+ // resize internal buffers to match render target (e.g. XR resolution)
5023
+ if ( renderTarget !== null ) {
5024
+
5025
+ const width = renderTarget.width;
5026
+ const height = renderTarget.height;
5027
+
5028
+ if ( targetA.width !== width || targetA.height !== height ) {
5029
+
5030
+ this.setSize( width, height );
5031
+
5032
+ }
5033
+
5034
+ }
5035
+
5036
+ // if first effect is a RenderPass, it will set its own render target
5037
+ if ( _hasRenderPass === false ) {
5038
+
5039
+ renderer.setRenderTarget( targetA );
5040
+
5041
+ }
5042
+
5043
+ // disable tone mapping during render - it will be applied in end()
5044
+ _savedToneMapping = renderer.toneMapping;
5045
+ renderer.toneMapping = NoToneMapping;
5046
+
5047
+ return true;
5048
+
5049
+ };
5050
+
5051
+ this.hasRenderPass = function () {
5052
+
5053
+ return _hasRenderPass;
5054
+
5055
+ };
5056
+
5057
+ this.end = function ( renderer, deltaTime ) {
5058
+
5059
+ // restore tone mapping
5060
+ renderer.toneMapping = _savedToneMapping;
5061
+
5062
+ _isCompositing = true;
5063
+
5064
+ // run post-processing effects
5065
+ let readBuffer = targetA;
5066
+ let writeBuffer = targetB;
5067
+
5068
+ for ( let i = 0; i < _effects.length; i ++ ) {
5069
+
5070
+ const effect = _effects[ i ];
5071
+
5072
+ if ( effect.enabled === false ) continue;
5073
+
5074
+ effect.render( renderer, writeBuffer, readBuffer, deltaTime );
5075
+
5076
+ if ( effect.needsSwap !== false ) {
5077
+
5078
+ const temp = readBuffer;
5079
+ readBuffer = writeBuffer;
5080
+ writeBuffer = temp;
5081
+
5082
+ }
5083
+
5084
+ }
5085
+
5086
+ // update output material defines if settings changed
5087
+ if ( _outputColorSpace !== renderer.outputColorSpace || _outputToneMapping !== renderer.toneMapping ) {
5088
+
5089
+ _outputColorSpace = renderer.outputColorSpace;
5090
+ _outputToneMapping = renderer.toneMapping;
5091
+
5092
+ material.defines = {};
5093
+
5094
+ if ( ColorManagement.getTransfer( _outputColorSpace ) === SRGBTransfer ) material.defines.SRGB_TRANSFER = '';
5095
+
5096
+ const toneMapping = toneMappingMap[ _outputToneMapping ];
5097
+ if ( toneMapping ) material.defines[ toneMapping ] = '';
5098
+
5099
+ material.needsUpdate = true;
5100
+
5101
+ }
5102
+
5103
+ // final output to canvas (or XR render target)
5104
+ material.uniforms.tDiffuse.value = readBuffer.texture;
5105
+ renderer.setRenderTarget( _savedRenderTarget );
5106
+ renderer.render( mesh, camera );
5107
+
5108
+ _savedRenderTarget = null;
5109
+ _isCompositing = false;
5110
+
5111
+ };
5112
+
5113
+ this.isCompositing = function () {
5114
+
5115
+ return _isCompositing;
5116
+
5117
+ };
5118
+
5119
+ this.dispose = function () {
5120
+
5121
+ if ( targetA.depthTexture ) targetA.depthTexture.dispose();
5122
+ targetA.dispose();
5123
+ targetB.dispose();
5124
+ geometry.dispose();
5125
+ material.dispose();
5126
+
5127
+ };
5128
+
5129
+ }
5130
+
4699
5131
  /**
4700
5132
  * Uniforms of a program.
4701
5133
  * Those form a tree structure with a special top-level container for the root,
@@ -5264,7 +5696,7 @@ function setValueT1( gl, v, textures ) {
5264
5696
 
5265
5697
  if ( this.type === gl.SAMPLER_2D_SHADOW ) {
5266
5698
 
5267
- emptyShadowTexture.compareFunction = LessEqualCompare; // #28670
5699
+ emptyShadowTexture.compareFunction = textures.isReversedDepthBuffer() ? GreaterEqualCompare : LessEqualCompare;
5268
5700
  emptyTexture2D = emptyShadowTexture;
5269
5701
 
5270
5702
  } else {
@@ -5514,9 +5946,21 @@ function setValueT1Array( gl, v, textures ) {
5514
5946
 
5515
5947
  }
5516
5948
 
5949
+ let emptyTexture2D;
5950
+
5951
+ if ( this.type === gl.SAMPLER_2D_SHADOW ) {
5952
+
5953
+ emptyTexture2D = emptyShadowTexture;
5954
+
5955
+ } else {
5956
+
5957
+ emptyTexture2D = emptyTexture;
5958
+
5959
+ }
5960
+
5517
5961
  for ( let i = 0; i !== n; ++ i ) {
5518
5962
 
5519
- textures.setTexture2D( v[ i ] || emptyTexture, units[ i ] );
5963
+ textures.setTexture2D( v[ i ] || emptyTexture2D, units[ i ] );
5520
5964
 
5521
5965
  }
5522
5966
 
@@ -5802,6 +6246,31 @@ class WebGLUniforms {
5802
6246
 
5803
6247
  }
5804
6248
 
6249
+ // Sort uniforms to prioritize shadow samplers first (for optimal texture unit allocation)
6250
+
6251
+ const shadowSamplers = [];
6252
+ const otherUniforms = [];
6253
+
6254
+ for ( const u of this.seq ) {
6255
+
6256
+ if ( u.type === gl.SAMPLER_2D_SHADOW || u.type === gl.SAMPLER_CUBE_SHADOW || u.type === gl.SAMPLER_2D_ARRAY_SHADOW ) {
6257
+
6258
+ shadowSamplers.push( u );
6259
+
6260
+ } else {
6261
+
6262
+ otherUniforms.push( u );
6263
+
6264
+ }
6265
+
6266
+ }
6267
+
6268
+ if ( shadowSamplers.length > 0 ) {
6269
+
6270
+ this.seq = shadowSamplers.concat( otherUniforms );
6271
+
6272
+ }
6273
+
5805
6274
  }
5806
6275
 
5807
6276
  setValue( gl, name, value, textures ) {
@@ -5956,43 +6425,24 @@ function getTexelEncodingFunction( functionName, colorSpace ) {
5956
6425
 
5957
6426
  }
5958
6427
 
5959
- function getToneMappingFunction( functionName, toneMapping ) {
5960
-
5961
- let toneMappingName;
5962
-
5963
- switch ( toneMapping ) {
5964
-
5965
- case LinearToneMapping:
5966
- toneMappingName = 'Linear';
5967
- break;
5968
-
5969
- case ReinhardToneMapping:
5970
- toneMappingName = 'Reinhard';
5971
- break;
5972
-
5973
- case CineonToneMapping:
5974
- toneMappingName = 'Cineon';
5975
- break;
5976
-
5977
- case ACESFilmicToneMapping:
5978
- toneMappingName = 'ACESFilmic';
5979
- break;
6428
+ const toneMappingFunctions = {
6429
+ [ LinearToneMapping ]: 'Linear',
6430
+ [ ReinhardToneMapping ]: 'Reinhard',
6431
+ [ CineonToneMapping ]: 'Cineon',
6432
+ [ ACESFilmicToneMapping ]: 'ACESFilmic',
6433
+ [ AgXToneMapping ]: 'AgX',
6434
+ [ NeutralToneMapping ]: 'Neutral',
6435
+ [ CustomToneMapping ]: 'Custom'
6436
+ };
5980
6437
 
5981
- case AgXToneMapping:
5982
- toneMappingName = 'AgX';
5983
- break;
6438
+ function getToneMappingFunction( functionName, toneMapping ) {
5984
6439
 
5985
- case NeutralToneMapping:
5986
- toneMappingName = 'Neutral';
5987
- break;
6440
+ const toneMappingName = toneMappingFunctions[ toneMapping ];
5988
6441
 
5989
- case CustomToneMapping:
5990
- toneMappingName = 'Custom';
5991
- break;
6442
+ if ( toneMappingName === undefined ) {
5992
6443
 
5993
- default:
5994
- warn( 'WebGLProgram: Unsupported toneMapping:', toneMapping );
5995
- toneMappingName = 'Linear';
6444
+ warn( 'WebGLProgram: Unsupported toneMapping:', toneMapping );
6445
+ return 'vec3 ' + functionName + '( vec3 color ) { return LinearToneMapping( color ); }';
5996
6446
 
5997
6447
  }
5998
6448
 
@@ -6220,99 +6670,54 @@ function generatePrecision( parameters ) {
6220
6670
 
6221
6671
  }
6222
6672
 
6223
- function generateShadowMapTypeDefine( parameters ) {
6224
-
6225
- let shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
6226
-
6227
- if ( parameters.shadowMapType === PCFShadowMap ) {
6228
-
6229
- shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
6230
-
6231
- } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
6232
-
6233
- shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
6234
-
6235
- } else if ( parameters.shadowMapType === VSMShadowMap ) {
6236
-
6237
- shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
6673
+ const shadowMapTypeDefines = {
6674
+ [ PCFShadowMap ]: 'SHADOWMAP_TYPE_PCF',
6675
+ [ VSMShadowMap ]: 'SHADOWMAP_TYPE_VSM'
6676
+ };
6238
6677
 
6239
- }
6678
+ function generateShadowMapTypeDefine( parameters ) {
6240
6679
 
6241
- return shadowMapTypeDefine;
6680
+ return shadowMapTypeDefines[ parameters.shadowMapType ] || 'SHADOWMAP_TYPE_BASIC';
6242
6681
 
6243
6682
  }
6244
6683
 
6245
- function generateEnvMapTypeDefine( parameters ) {
6246
-
6247
- let envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
6248
-
6249
- if ( parameters.envMap ) {
6250
-
6251
- switch ( parameters.envMapMode ) {
6252
-
6253
- case CubeReflectionMapping:
6254
- case CubeRefractionMapping:
6255
- envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
6256
- break;
6257
-
6258
- case CubeUVReflectionMapping:
6259
- envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
6260
- break;
6684
+ const envMapTypeDefines = {
6685
+ [ CubeReflectionMapping ]: 'ENVMAP_TYPE_CUBE',
6686
+ [ CubeRefractionMapping ]: 'ENVMAP_TYPE_CUBE',
6687
+ [ CubeUVReflectionMapping ]: 'ENVMAP_TYPE_CUBE_UV'
6688
+ };
6261
6689
 
6262
- }
6690
+ function generateEnvMapTypeDefine( parameters ) {
6263
6691
 
6264
- }
6692
+ if ( parameters.envMap === false ) return 'ENVMAP_TYPE_CUBE';
6265
6693
 
6266
- return envMapTypeDefine;
6694
+ return envMapTypeDefines[ parameters.envMapMode ] || 'ENVMAP_TYPE_CUBE';
6267
6695
 
6268
6696
  }
6269
6697
 
6270
- function generateEnvMapModeDefine( parameters ) {
6271
-
6272
- let envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
6273
-
6274
- if ( parameters.envMap ) {
6275
-
6276
- switch ( parameters.envMapMode ) {
6277
-
6278
- case CubeRefractionMapping:
6279
-
6280
- envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
6281
- break;
6698
+ const envMapModeDefines = {
6699
+ [ CubeRefractionMapping ]: 'ENVMAP_MODE_REFRACTION'
6700
+ };
6282
6701
 
6283
- }
6702
+ function generateEnvMapModeDefine( parameters ) {
6284
6703
 
6285
- }
6704
+ if ( parameters.envMap === false ) return 'ENVMAP_MODE_REFLECTION';
6286
6705
 
6287
- return envMapModeDefine;
6706
+ return envMapModeDefines[ parameters.envMapMode ] || 'ENVMAP_MODE_REFLECTION';
6288
6707
 
6289
6708
  }
6290
6709
 
6291
- function generateEnvMapBlendingDefine( parameters ) {
6292
-
6293
- let envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
6294
-
6295
- if ( parameters.envMap ) {
6296
-
6297
- switch ( parameters.combine ) {
6298
-
6299
- case MultiplyOperation:
6300
- envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
6301
- break;
6302
-
6303
- case MixOperation:
6304
- envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
6305
- break;
6306
-
6307
- case AddOperation:
6308
- envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
6309
- break;
6710
+ const envMapBlendingDefines = {
6711
+ [ MultiplyOperation ]: 'ENVMAP_BLENDING_MULTIPLY',
6712
+ [ MixOperation ]: 'ENVMAP_BLENDING_MIX',
6713
+ [ AddOperation ]: 'ENVMAP_BLENDING_ADD'
6714
+ };
6310
6715
 
6311
- }
6716
+ function generateEnvMapBlendingDefine( parameters ) {
6312
6717
 
6313
- }
6718
+ if ( parameters.envMap === false ) return 'ENVMAP_BLENDING_NONE';
6314
6719
 
6315
- return envMapBlendingDefine;
6720
+ return envMapBlendingDefines[ parameters.combine ] || 'ENVMAP_BLENDING_NONE';
6316
6721
 
6317
6722
  }
6318
6723
 
@@ -6488,6 +6893,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
6488
6893
  //
6489
6894
 
6490
6895
  parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '',
6896
+ parameters.vertexNormals ? '#define HAS_NORMAL' : '',
6491
6897
  parameters.vertexColors ? '#define USE_COLOR' : '',
6492
6898
  parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',
6493
6899
  parameters.vertexUv1s ? '#define USE_UV1' : '',
@@ -6621,6 +7027,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
6621
7027
  parameters.normalMap ? '#define USE_NORMALMAP' : '',
6622
7028
  parameters.normalMapObjectSpace ? '#define USE_NORMALMAP_OBJECTSPACE' : '',
6623
7029
  parameters.normalMapTangentSpace ? '#define USE_NORMALMAP_TANGENTSPACE' : '',
7030
+ parameters.packedNormalMap ? '#define USE_PACKED_NORMALMAP' : '',
6624
7031
  parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
6625
7032
 
6626
7033
  parameters.anisotropy ? '#define USE_ANISOTROPY' : '',
@@ -6657,8 +7064,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
6657
7064
  parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',
6658
7065
 
6659
7066
  parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '',
6660
- parameters.vertexColors || parameters.instancingColor || parameters.batchingColor ? '#define USE_COLOR' : '',
6661
- parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',
7067
+ parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
7068
+ parameters.vertexAlphas || parameters.batchingColor ? '#define USE_COLOR_ALPHA' : '',
6662
7069
  parameters.vertexUv1s ? '#define USE_UV1' : '',
6663
7070
  parameters.vertexUv2s ? '#define USE_UV2' : '',
6664
7071
  parameters.vertexUv3s ? '#define USE_UV3' : '',
@@ -6679,6 +7086,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
6679
7086
 
6680
7087
  parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
6681
7088
 
7089
+ parameters.numLightProbeGrids > 0 ? '#define USE_LIGHT_PROBES_GRID' : '',
7090
+
6682
7091
  parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
6683
7092
  parameters.decodeVideoTextureEmissive ? '#define DECODE_VIDEO_TEXTURE_EMISSIVE' : '',
6684
7093
 
@@ -7120,21 +7529,27 @@ class WebGLShaderStage {
7120
7529
 
7121
7530
  }
7122
7531
 
7123
- function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping ) {
7532
+ function isPackedRGFormat( format ) {
7533
+
7534
+ return format === RGFormat || format === RG11_EAC_Format || format === RED_GREEN_RGTC2_Format;
7535
+
7536
+ }
7537
+
7538
+ function WebGLPrograms( renderer, environments, extensions, capabilities, bindingStates, clipping ) {
7124
7539
 
7125
7540
  const _programLayers = new Layers();
7126
7541
  const _customShaders = new WebGLShaderCache();
7127
7542
  const _activeChannels = new Set();
7128
7543
  const programs = [];
7544
+ const programsMap = new Map();
7129
7545
 
7130
7546
  const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
7131
- const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures;
7132
7547
 
7133
7548
  let precision = capabilities.precision;
7134
7549
 
7135
7550
  const shaderIDs = {
7136
7551
  MeshDepthMaterial: 'depth',
7137
- MeshDistanceMaterial: 'distanceRGBA',
7552
+ MeshDistanceMaterial: 'distance',
7138
7553
  MeshNormalMaterial: 'normal',
7139
7554
  MeshBasicMaterial: 'basic',
7140
7555
  MeshLambertMaterial: 'lambert',
@@ -7160,13 +7575,14 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7160
7575
 
7161
7576
  }
7162
7577
 
7163
- function getParameters( material, lights, shadows, scene, object ) {
7578
+ function getParameters( material, lights, shadows, scene, object, lightProbeGrids ) {
7164
7579
 
7165
7580
  const fog = scene.fog;
7166
7581
  const geometry = object.geometry;
7167
- const environment = material.isMeshStandardMaterial ? scene.environment : null;
7582
+ const environment = ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) ? scene.environment : null;
7168
7583
 
7169
- const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
7584
+ const usePMREM = material.isMeshStandardMaterial || ( material.isMeshLambertMaterial && ! material.envMap ) || ( material.isMeshPhongMaterial && ! material.envMap );
7585
+ const envMap = environments.get( material.envMap || environment, usePMREM );
7170
7586
  const envMapCubeUVHeight = ( !! envMap ) && ( envMap.mapping === CubeUVReflectionMapping ) ? envMap.image.height : null;
7171
7587
 
7172
7588
  const shaderID = shaderIDs[ material.type ];
@@ -7314,9 +7730,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7314
7730
  instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null,
7315
7731
  instancingMorph: IS_INSTANCEDMESH && object.morphTexture !== null,
7316
7732
 
7317
- supportsVertexTextures: SUPPORTS_VERTEX_TEXTURES,
7318
7733
  numMultiviewViews: numMultiviewViews,
7319
- outputColorSpace: ( currentRenderTarget === null ) ? renderer.outputColorSpace : ( currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace ),
7734
+ outputColorSpace: ( currentRenderTarget === null ) ? renderer.outputColorSpace : ( currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : ColorManagement.workingColorSpace ),
7320
7735
  alphaToCoverage: !! material.alphaToCoverage,
7321
7736
 
7322
7737
  map: HAS_MAP,
@@ -7328,11 +7743,12 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7328
7743
  lightMap: HAS_LIGHTMAP,
7329
7744
  bumpMap: HAS_BUMPMAP,
7330
7745
  normalMap: HAS_NORMALMAP,
7331
- displacementMap: SUPPORTS_VERTEX_TEXTURES && HAS_DISPLACEMENTMAP,
7746
+ displacementMap: HAS_DISPLACEMENTMAP,
7332
7747
  emissiveMap: HAS_EMISSIVEMAP,
7333
7748
 
7334
7749
  normalMapObjectSpace: HAS_NORMALMAP && material.normalMapType === ObjectSpaceNormalMap,
7335
7750
  normalMapTangentSpace: HAS_NORMALMAP && material.normalMapType === TangentSpaceNormalMap,
7751
+ packedNormalMap: HAS_NORMALMAP && material.normalMapType === TangentSpaceNormalMap && isPackedRGFormat( material.normalMap.format ),
7336
7752
 
7337
7753
  metalnessMap: HAS_METALNESSMAP,
7338
7754
  roughnessMap: HAS_ROUGHNESSMAP,
@@ -7410,6 +7826,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7410
7826
  //
7411
7827
 
7412
7828
  vertexTangents: !! geometry.attributes.tangent && ( HAS_NORMALMAP || HAS_ANISOTROPY ),
7829
+ vertexNormals: !! geometry.attributes.normal,
7413
7830
  vertexColors: material.vertexColors,
7414
7831
  vertexAlphas: material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4,
7415
7832
 
@@ -7419,7 +7836,12 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7419
7836
  useFog: material.fog === true,
7420
7837
  fogExp2: ( !! fog && fog.isFogExp2 ),
7421
7838
 
7422
- flatShading: ( material.flatShading === true && material.wireframe === false ),
7839
+ flatShading: material.wireframe === false && (
7840
+ material.flatShading === true ||
7841
+ ( geometry.attributes.normal === undefined && HAS_NORMALMAP === false &&
7842
+ ( material.isMeshLambertMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isMeshPhysicalMaterial )
7843
+ )
7844
+ ),
7423
7845
 
7424
7846
  sizeAttenuation: material.sizeAttenuation === true,
7425
7847
  logarithmicDepthBuffer: logarithmicDepthBuffer,
@@ -7447,6 +7869,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7447
7869
 
7448
7870
  numLightProbes: lights.numLightProbes,
7449
7871
 
7872
+ numLightProbeGrids: lightProbeGrids.length,
7873
+
7450
7874
  numClippingPlanes: clipping.numPlanes,
7451
7875
  numClipIntersection: clipping.numIntersection,
7452
7876
 
@@ -7588,52 +8012,54 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7588
8012
 
7589
8013
  _programLayers.disableAll();
7590
8014
 
7591
- if ( parameters.supportsVertexTextures )
7592
- _programLayers.enable( 0 );
7593
8015
  if ( parameters.instancing )
7594
- _programLayers.enable( 1 );
8016
+ _programLayers.enable( 0 );
7595
8017
  if ( parameters.instancingColor )
7596
- _programLayers.enable( 2 );
8018
+ _programLayers.enable( 1 );
7597
8019
  if ( parameters.instancingMorph )
7598
- _programLayers.enable( 3 );
8020
+ _programLayers.enable( 2 );
7599
8021
  if ( parameters.matcap )
7600
- _programLayers.enable( 4 );
8022
+ _programLayers.enable( 3 );
7601
8023
  if ( parameters.envMap )
7602
- _programLayers.enable( 5 );
8024
+ _programLayers.enable( 4 );
7603
8025
  if ( parameters.normalMapObjectSpace )
7604
- _programLayers.enable( 6 );
8026
+ _programLayers.enable( 5 );
7605
8027
  if ( parameters.normalMapTangentSpace )
7606
- _programLayers.enable( 7 );
8028
+ _programLayers.enable( 6 );
7607
8029
  if ( parameters.clearcoat )
7608
- _programLayers.enable( 8 );
8030
+ _programLayers.enable( 7 );
7609
8031
  if ( parameters.iridescence )
7610
- _programLayers.enable( 9 );
8032
+ _programLayers.enable( 8 );
7611
8033
  if ( parameters.alphaTest )
7612
- _programLayers.enable( 10 );
8034
+ _programLayers.enable( 9 );
7613
8035
  if ( parameters.vertexColors )
7614
- _programLayers.enable( 11 );
8036
+ _programLayers.enable( 10 );
7615
8037
  if ( parameters.vertexAlphas )
7616
- _programLayers.enable( 12 );
8038
+ _programLayers.enable( 11 );
7617
8039
  if ( parameters.vertexUv1s )
7618
- _programLayers.enable( 13 );
8040
+ _programLayers.enable( 12 );
7619
8041
  if ( parameters.vertexUv2s )
7620
- _programLayers.enable( 14 );
8042
+ _programLayers.enable( 13 );
7621
8043
  if ( parameters.vertexUv3s )
7622
- _programLayers.enable( 15 );
8044
+ _programLayers.enable( 14 );
7623
8045
  if ( parameters.vertexTangents )
7624
- _programLayers.enable( 16 );
8046
+ _programLayers.enable( 15 );
7625
8047
  if ( parameters.anisotropy )
7626
- _programLayers.enable( 17 );
8048
+ _programLayers.enable( 16 );
7627
8049
  if ( parameters.alphaHash )
7628
- _programLayers.enable( 18 );
8050
+ _programLayers.enable( 17 );
7629
8051
  if ( parameters.batching )
7630
- _programLayers.enable( 19 );
8052
+ _programLayers.enable( 18 );
7631
8053
  if ( parameters.dispersion )
7632
- _programLayers.enable( 20 );
8054
+ _programLayers.enable( 19 );
7633
8055
  if ( parameters.batchingColor )
7634
- _programLayers.enable( 21 );
8056
+ _programLayers.enable( 20 );
7635
8057
  if ( parameters.gradientMap )
8058
+ _programLayers.enable( 21 );
8059
+ if ( parameters.packedNormalMap )
7636
8060
  _programLayers.enable( 22 );
8061
+ if ( parameters.vertexNormals )
8062
+ _programLayers.enable( 23 );
7637
8063
 
7638
8064
  array.push( _programLayers.mask );
7639
8065
  _programLayers.disableAll();
@@ -7682,8 +8108,10 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7682
8108
  _programLayers.enable( 20 );
7683
8109
  if ( parameters.alphaToCoverage )
7684
8110
  _programLayers.enable( 21 );
7685
- if ( parameters.numMultiviewViews )
8111
+ if ( parameters.numLightProbeGrids > 0 )
7686
8112
  _programLayers.enable( 22 );
8113
+ if ( parameters.numMultiviewViews )
8114
+ _programLayers.enable( 23 );
7687
8115
 
7688
8116
  array.push( _programLayers.mask );
7689
8117
 
@@ -7711,29 +8139,19 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7711
8139
 
7712
8140
  function acquireProgram( parameters, cacheKey ) {
7713
8141
 
7714
- let program;
7715
-
7716
- // Check if code has been already compiled
7717
- for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
7718
-
7719
- const preexistingProgram = programs[ p ];
7720
-
7721
- if ( preexistingProgram.cacheKey === cacheKey ) {
7722
-
7723
- program = preexistingProgram;
7724
- ++ program.usedTimes;
7725
-
7726
- break;
8142
+ let program = programsMap.get( cacheKey );
7727
8143
 
7728
- }
8144
+ if ( program !== undefined ) {
7729
8145
 
7730
- }
8146
+ ++ program.usedTimes;
7731
8147
 
7732
- if ( program === undefined ) {
8148
+ } else {
7733
8149
 
7734
8150
  program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
7735
8151
  programs.push( program );
7736
8152
 
8153
+ programsMap.set( cacheKey, program );
8154
+
7737
8155
  }
7738
8156
 
7739
8157
  return program;
@@ -7749,6 +8167,9 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
7749
8167
  programs[ i ] = programs[ programs.length - 1 ];
7750
8168
  programs.pop();
7751
8169
 
8170
+ // Remove from map
8171
+ programsMap.delete( program.cacheKey );
8172
+
7752
8173
  // Free WebGL resources
7753
8174
  program.destroy();
7754
8175
 
@@ -7849,6 +8270,10 @@ function painterSortStable( a, b ) {
7849
8270
 
7850
8271
  return a.material.id - b.material.id;
7851
8272
 
8273
+ } else if ( a.materialVariant !== b.materialVariant ) {
8274
+
8275
+ return a.materialVariant - b.materialVariant;
8276
+
7852
8277
  } else if ( a.z !== b.z ) {
7853
8278
 
7854
8279
  return a.z - b.z;
@@ -7903,6 +8328,15 @@ function WebGLRenderList() {
7903
8328
 
7904
8329
  }
7905
8330
 
8331
+ function materialVariant( object ) {
8332
+
8333
+ let variant = 0;
8334
+ if ( object.isInstancedMesh ) variant += 2;
8335
+ if ( object.isSkinnedMesh ) variant += 1;
8336
+ return variant;
8337
+
8338
+ }
8339
+
7906
8340
  function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
7907
8341
 
7908
8342
  let renderItem = renderItems[ renderItemsIndex ];
@@ -7914,6 +8348,7 @@ function WebGLRenderList() {
7914
8348
  object: object,
7915
8349
  geometry: geometry,
7916
8350
  material: material,
8351
+ materialVariant: materialVariant( object ),
7917
8352
  groupOrder: groupOrder,
7918
8353
  renderOrder: object.renderOrder,
7919
8354
  z: z,
@@ -7928,6 +8363,7 @@ function WebGLRenderList() {
7928
8363
  renderItem.object = object;
7929
8364
  renderItem.geometry = geometry;
7930
8365
  renderItem.material = material;
8366
+ renderItem.materialVariant = materialVariant( object );
7931
8367
  renderItem.groupOrder = groupOrder;
7932
8368
  renderItem.renderOrder = object.renderOrder;
7933
8369
  renderItem.z = z;
@@ -8306,7 +8742,23 @@ function WebGLLights( extensions ) {
8306
8742
  const intensity = light.intensity;
8307
8743
  const distance = light.distance;
8308
8744
 
8309
- const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
8745
+ let shadowMap = null;
8746
+
8747
+ if ( light.shadow && light.shadow.map ) {
8748
+
8749
+ if ( light.shadow.map.texture.format === RGFormat ) {
8750
+
8751
+ // VSM uses color texture with blurred mean/std_dev
8752
+ shadowMap = light.shadow.map.texture;
8753
+
8754
+ } else {
8755
+
8756
+ // Other types use depth texture
8757
+ shadowMap = light.shadow.map.depthTexture || light.shadow.map.texture;
8758
+
8759
+ }
8760
+
8761
+ }
8310
8762
 
8311
8763
  if ( light.isAmbientLight ) {
8312
8764
 
@@ -8636,6 +9088,7 @@ function WebGLRenderState( extensions ) {
8636
9088
 
8637
9089
  const lightsArray = [];
8638
9090
  const shadowsArray = [];
9091
+ const lightProbeGridArray = [];
8639
9092
 
8640
9093
  function init( camera ) {
8641
9094
 
@@ -8643,6 +9096,7 @@ function WebGLRenderState( extensions ) {
8643
9096
 
8644
9097
  lightsArray.length = 0;
8645
9098
  shadowsArray.length = 0;
9099
+ lightProbeGridArray.length = 0;
8646
9100
 
8647
9101
  }
8648
9102
 
@@ -8658,6 +9112,12 @@ function WebGLRenderState( extensions ) {
8658
9112
 
8659
9113
  }
8660
9114
 
9115
+ function pushLightProbeGrid( volume ) {
9116
+
9117
+ lightProbeGridArray.push( volume );
9118
+
9119
+ }
9120
+
8661
9121
  function setupLights() {
8662
9122
 
8663
9123
  lights.setup( lightsArray );
@@ -8673,12 +9133,14 @@ function WebGLRenderState( extensions ) {
8673
9133
  const state = {
8674
9134
  lightsArray: lightsArray,
8675
9135
  shadowsArray: shadowsArray,
9136
+ lightProbeGridArray: lightProbeGridArray,
8676
9137
 
8677
9138
  camera: null,
8678
9139
 
8679
9140
  lights: lights,
8680
9141
 
8681
- transmissionRenderTarget: {}
9142
+ transmissionRenderTarget: {},
9143
+ textureUnits: 0
8682
9144
  };
8683
9145
 
8684
9146
  return {
@@ -8688,7 +9150,8 @@ function WebGLRenderState( extensions ) {
8688
9150
  setupLightsView: setupLightsView,
8689
9151
 
8690
9152
  pushLight: pushLight,
8691
- pushShadow: pushShadow
9153
+ pushShadow: pushShadow,
9154
+ pushLightProbeGrid: pushLightProbeGrid
8692
9155
  };
8693
9156
 
8694
9157
  }
@@ -8741,7 +9204,21 @@ function WebGLRenderStates( extensions ) {
8741
9204
 
8742
9205
  const vertex = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
8743
9206
 
8744
- const fragment = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";
9207
+ const fragment = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );\n\tgl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );\n}";
9208
+
9209
+ const _cubeDirections = [
9210
+ /*@__PURE__*/ new Vector3( 1, 0, 0 ), /*@__PURE__*/ new Vector3( -1, 0, 0 ), /*@__PURE__*/ new Vector3( 0, 1, 0 ),
9211
+ /*@__PURE__*/ new Vector3( 0, -1, 0 ), /*@__PURE__*/ new Vector3( 0, 0, 1 ), /*@__PURE__*/ new Vector3( 0, 0, -1 )
9212
+ ];
9213
+
9214
+ const _cubeUps = [
9215
+ /*@__PURE__*/ new Vector3( 0, -1, 0 ), /*@__PURE__*/ new Vector3( 0, -1, 0 ), /*@__PURE__*/ new Vector3( 0, 0, 1 ),
9216
+ /*@__PURE__*/ new Vector3( 0, 0, -1 ), /*@__PURE__*/ new Vector3( 0, -1, 0 ), /*@__PURE__*/ new Vector3( 0, -1, 0 )
9217
+ ];
9218
+
9219
+ const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
9220
+ const _lightPositionWorld = /*@__PURE__*/ new Vector3();
9221
+ const _lookTarget = /*@__PURE__*/ new Vector3();
8745
9222
 
8746
9223
  function WebGLShadowMap( renderer, objects, capabilities ) {
8747
9224
 
@@ -8752,7 +9229,7 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
8752
9229
 
8753
9230
  _viewport = new Vector4(),
8754
9231
 
8755
- _depthMaterial = new MeshDepthMaterial( { depthPacking: RGBADepthPacking } ),
9232
+ _depthMaterial = new MeshDepthMaterial(),
8756
9233
  _distanceMaterial = new MeshDistanceMaterial(),
8757
9234
 
8758
9235
  _materialCache = {},
@@ -8807,6 +9284,13 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
8807
9284
 
8808
9285
  if ( lights.length === 0 ) return;
8809
9286
 
9287
+ if ( this.type === PCFSoftShadowMap ) {
9288
+
9289
+ warn( 'WebGLShadowMap: PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead.' );
9290
+ this.type = PCFShadowMap;
9291
+
9292
+ }
9293
+
8810
9294
  const currentRenderTarget = renderer.getRenderTarget();
8811
9295
  const activeCubeFace = renderer.getActiveCubeFace();
8812
9296
  const activeMipmapLevel = renderer.getActiveMipmapLevel();
@@ -8831,8 +9315,31 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
8831
9315
 
8832
9316
  // check for shadow map type changes
8833
9317
 
8834
- const toVSM = ( _previousType !== VSMShadowMap && this.type === VSMShadowMap );
8835
- const fromVSM = ( _previousType === VSMShadowMap && this.type !== VSMShadowMap );
9318
+ const typeChanged = _previousType !== this.type;
9319
+
9320
+ // When shadow map type changes, materials need recompilation because sampler types change
9321
+ // (sampler2DShadow for PCF vs sampler2D for Basic)
9322
+ if ( typeChanged ) {
9323
+
9324
+ scene.traverse( function ( object ) {
9325
+
9326
+ if ( object.material ) {
9327
+
9328
+ if ( Array.isArray( object.material ) ) {
9329
+
9330
+ object.material.forEach( mat => mat.needsUpdate = true );
9331
+
9332
+ } else {
9333
+
9334
+ object.material.needsUpdate = true;
9335
+
9336
+ }
9337
+
9338
+ }
9339
+
9340
+ } );
9341
+
9342
+ }
8836
9343
 
8837
9344
  // render depth map
8838
9345
 
@@ -8878,42 +9385,154 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
8878
9385
 
8879
9386
  }
8880
9387
 
8881
- if ( shadow.map === null || toVSM === true || fromVSM === true ) {
9388
+ const reversedDepthBuffer = renderer.state.buffers.depth.getReversed();
9389
+ shadow.camera._reversedDepth = reversedDepthBuffer;
8882
9390
 
8883
- const pars = ( this.type !== VSMShadowMap ) ? { minFilter: NearestFilter, magFilter: NearestFilter } : {};
9391
+ if ( shadow.map === null || typeChanged === true ) {
8884
9392
 
8885
9393
  if ( shadow.map !== null ) {
8886
9394
 
9395
+ if ( shadow.map.depthTexture !== null ) {
9396
+
9397
+ shadow.map.depthTexture.dispose();
9398
+ shadow.map.depthTexture = null;
9399
+
9400
+ }
9401
+
8887
9402
  shadow.map.dispose();
8888
9403
 
8889
9404
  }
8890
9405
 
8891
- shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
8892
- shadow.map.texture.name = light.name + '.shadowMap';
9406
+ if ( this.type === VSMShadowMap ) {
9407
+
9408
+ if ( light.isPointLight ) {
9409
+
9410
+ warn( 'WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.' );
9411
+ continue;
9412
+
9413
+ }
9414
+
9415
+ shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, {
9416
+ format: RGFormat,
9417
+ type: HalfFloatType,
9418
+ minFilter: LinearFilter,
9419
+ magFilter: LinearFilter,
9420
+ generateMipmaps: false
9421
+ } );
9422
+ shadow.map.texture.name = light.name + '.shadowMap';
9423
+
9424
+ // Native depth texture for VSM - depth is captured here, then blurred into the color texture
9425
+ shadow.map.depthTexture = new DepthTexture( _shadowMapSize.x, _shadowMapSize.y, FloatType );
9426
+ shadow.map.depthTexture.name = light.name + '.shadowMapDepth';
9427
+ shadow.map.depthTexture.format = DepthFormat;
9428
+ shadow.map.depthTexture.compareFunction = null; // For regular sampling (not shadow comparison)
9429
+ shadow.map.depthTexture.minFilter = NearestFilter;
9430
+ shadow.map.depthTexture.magFilter = NearestFilter;
9431
+
9432
+ } else {
9433
+
9434
+ if ( light.isPointLight ) {
9435
+
9436
+ shadow.map = new WebGLCubeRenderTarget( _shadowMapSize.x );
9437
+ shadow.map.depthTexture = new CubeDepthTexture( _shadowMapSize.x, UnsignedIntType );
9438
+
9439
+ } else {
9440
+
9441
+ shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y );
9442
+ shadow.map.depthTexture = new DepthTexture( _shadowMapSize.x, _shadowMapSize.y, UnsignedIntType );
9443
+
9444
+ }
9445
+
9446
+ shadow.map.depthTexture.name = light.name + '.shadowMap';
9447
+ shadow.map.depthTexture.format = DepthFormat;
9448
+
9449
+ if ( this.type === PCFShadowMap ) {
9450
+
9451
+ shadow.map.depthTexture.compareFunction = reversedDepthBuffer ? GreaterEqualCompare : LessEqualCompare;
9452
+ shadow.map.depthTexture.minFilter = LinearFilter;
9453
+ shadow.map.depthTexture.magFilter = LinearFilter;
9454
+
9455
+ } else {
9456
+
9457
+ shadow.map.depthTexture.compareFunction = null;
9458
+ shadow.map.depthTexture.minFilter = NearestFilter;
9459
+ shadow.map.depthTexture.magFilter = NearestFilter;
9460
+
9461
+ }
9462
+
9463
+ }
8893
9464
 
8894
9465
  shadow.camera.updateProjectionMatrix();
8895
9466
 
8896
9467
  }
8897
9468
 
8898
- renderer.setRenderTarget( shadow.map );
8899
- renderer.clear();
9469
+ // For cube render targets (PointLights), render all 6 faces. Otherwise, render once.
9470
+ const faceCount = shadow.map.isWebGLCubeRenderTarget ? 6 : 1;
8900
9471
 
8901
- const viewportCount = shadow.getViewportCount();
9472
+ for ( let face = 0; face < faceCount; face ++ ) {
8902
9473
 
8903
- for ( let vp = 0; vp < viewportCount; vp ++ ) {
9474
+ // For cube render targets, render to each face separately
9475
+ if ( shadow.map.isWebGLCubeRenderTarget ) {
8904
9476
 
8905
- const viewport = shadow.getViewport( vp );
9477
+ renderer.setRenderTarget( shadow.map, face );
9478
+ renderer.clear();
8906
9479
 
8907
- _viewport.set(
8908
- _viewportSize.x * viewport.x,
8909
- _viewportSize.y * viewport.y,
8910
- _viewportSize.x * viewport.z,
8911
- _viewportSize.y * viewport.w
8912
- );
9480
+ } else {
9481
+
9482
+ // For 2D render targets, use viewports
9483
+ if ( face === 0 ) {
9484
+
9485
+ renderer.setRenderTarget( shadow.map );
9486
+ renderer.clear();
9487
+
9488
+ }
9489
+
9490
+ const viewport = shadow.getViewport( face );
9491
+
9492
+ _viewport.set(
9493
+ _viewportSize.x * viewport.x,
9494
+ _viewportSize.y * viewport.y,
9495
+ _viewportSize.x * viewport.z,
9496
+ _viewportSize.y * viewport.w
9497
+ );
9498
+
9499
+ _state.viewport( _viewport );
9500
+
9501
+ }
9502
+
9503
+ if ( light.isPointLight ) {
9504
+
9505
+ const camera = shadow.camera;
9506
+ const shadowMatrix = shadow.matrix;
9507
+
9508
+ const far = light.distance || camera.far;
9509
+
9510
+ if ( far !== camera.far ) {
9511
+
9512
+ camera.far = far;
9513
+ camera.updateProjectionMatrix();
9514
+
9515
+ }
9516
+
9517
+ _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
9518
+ camera.position.copy( _lightPositionWorld );
9519
+
9520
+ _lookTarget.copy( camera.position );
9521
+ _lookTarget.add( _cubeDirections[ face ] );
9522
+ camera.up.copy( _cubeUps[ face ] );
9523
+ camera.lookAt( _lookTarget );
9524
+ camera.updateMatrixWorld();
9525
+
9526
+ shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
9527
+
9528
+ _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
9529
+ shadow._frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );
8913
9530
 
8914
- _state.viewport( _viewport );
9531
+ } else {
9532
+
9533
+ shadow.updateMatrices( light );
8915
9534
 
8916
- shadow.updateMatrices( light, vp );
9535
+ }
8917
9536
 
8918
9537
  _frustum = shadow.getFrustum();
8919
9538
 
@@ -8957,13 +9576,16 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
8957
9576
 
8958
9577
  if ( shadow.mapPass === null ) {
8959
9578
 
8960
- shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y );
9579
+ shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, {
9580
+ format: RGFormat,
9581
+ type: HalfFloatType
9582
+ } );
8961
9583
 
8962
9584
  }
8963
9585
 
8964
- // vertical pass
9586
+ // vertical pass - read from native depth texture
8965
9587
 
8966
- shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
9588
+ shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.depthTexture;
8967
9589
  shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
8968
9590
  shadowMaterialVertical.uniforms.radius.value = shadow.radius;
8969
9591
  renderer.setRenderTarget( shadow.mapPass );
@@ -9162,18 +9784,6 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
9162
9784
 
9163
9785
  }
9164
9786
 
9165
- const reversedFuncs = {
9166
- [ NeverDepth ]: AlwaysDepth,
9167
- [ LessDepth ]: GreaterDepth,
9168
- [ EqualDepth ]: NotEqualDepth,
9169
- [ LessEqualDepth ]: GreaterEqualDepth,
9170
-
9171
- [ AlwaysDepth ]: NeverDepth,
9172
- [ GreaterDepth ]: LessDepth,
9173
- [ NotEqualDepth ]: EqualDepth,
9174
- [ GreaterEqualDepth ]: LessEqualDepth,
9175
- };
9176
-
9177
9787
  function WebGLState( gl, extensions ) {
9178
9788
 
9179
9789
  function ColorBuffer() {
@@ -9305,7 +9915,7 @@ function WebGLState( gl, extensions ) {
9305
9915
 
9306
9916
  setFunc: function ( depthFunc ) {
9307
9917
 
9308
- if ( currentReversed ) depthFunc = reversedFuncs[ depthFunc ];
9918
+ if ( currentReversed ) depthFunc = ReversedDepthFuncs[ depthFunc ];
9309
9919
 
9310
9920
  if ( currentDepthFunc !== depthFunc ) {
9311
9921
 
@@ -9373,6 +9983,8 @@ function WebGLState( gl, extensions ) {
9373
9983
 
9374
9984
  if ( currentDepthClear !== depth ) {
9375
9985
 
9986
+ currentDepthClear = depth;
9987
+
9376
9988
  if ( currentReversed ) {
9377
9989
 
9378
9990
  depth = 1 - depth;
@@ -9380,7 +9992,6 @@ function WebGLState( gl, extensions ) {
9380
9992
  }
9381
9993
 
9382
9994
  gl.clearDepth( depth );
9383
- currentDepthClear = depth;
9384
9995
 
9385
9996
  }
9386
9997
 
@@ -9523,6 +10134,7 @@ function WebGLState( gl, extensions ) {
9523
10134
  const uboProgramMap = new WeakMap();
9524
10135
 
9525
10136
  let enabledCapabilities = {};
10137
+ let parameters = {};
9526
10138
 
9527
10139
  let currentBoundFramebuffers = {};
9528
10140
  let currentDrawbuffers = new WeakMap();
@@ -10034,11 +10646,17 @@ function WebGLState( gl, extensions ) {
10034
10646
 
10035
10647
  if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
10036
10648
 
10037
- gl.polygonOffset( factor, units );
10038
-
10039
10649
  currentPolygonOffsetFactor = factor;
10040
10650
  currentPolygonOffsetUnits = units;
10041
10651
 
10652
+ if ( depthBuffer.getReversed() ) {
10653
+
10654
+ factor = - factor;
10655
+
10656
+ }
10657
+
10658
+ gl.polygonOffset( factor, units );
10659
+
10042
10660
  }
10043
10661
 
10044
10662
  } else {
@@ -10142,9 +10760,9 @@ function WebGLState( gl, extensions ) {
10142
10760
 
10143
10761
  gl.compressedTexImage2D( ...arguments );
10144
10762
 
10145
- } catch ( error ) {
10763
+ } catch ( e ) {
10146
10764
 
10147
- error( 'WebGLState:', error );
10765
+ error( 'WebGLState:', e );
10148
10766
 
10149
10767
  }
10150
10768
 
@@ -10156,9 +10774,9 @@ function WebGLState( gl, extensions ) {
10156
10774
 
10157
10775
  gl.compressedTexImage3D( ...arguments );
10158
10776
 
10159
- } catch ( error ) {
10777
+ } catch ( e ) {
10160
10778
 
10161
- error( 'WebGLState:', error );
10779
+ error( 'WebGLState:', e );
10162
10780
 
10163
10781
  }
10164
10782
 
@@ -10170,9 +10788,9 @@ function WebGLState( gl, extensions ) {
10170
10788
 
10171
10789
  gl.texSubImage2D( ...arguments );
10172
10790
 
10173
- } catch ( error ) {
10791
+ } catch ( e ) {
10174
10792
 
10175
- error( 'WebGLState:', error );
10793
+ error( 'WebGLState:', e );
10176
10794
 
10177
10795
  }
10178
10796
 
@@ -10184,9 +10802,9 @@ function WebGLState( gl, extensions ) {
10184
10802
 
10185
10803
  gl.texSubImage3D( ...arguments );
10186
10804
 
10187
- } catch ( error ) {
10805
+ } catch ( e ) {
10188
10806
 
10189
- error( 'WebGLState:', error );
10807
+ error( 'WebGLState:', e );
10190
10808
 
10191
10809
  }
10192
10810
 
@@ -10198,9 +10816,9 @@ function WebGLState( gl, extensions ) {
10198
10816
 
10199
10817
  gl.compressedTexSubImage2D( ...arguments );
10200
10818
 
10201
- } catch ( error ) {
10819
+ } catch ( e ) {
10202
10820
 
10203
- error( 'WebGLState:', error );
10821
+ error( 'WebGLState:', e );
10204
10822
 
10205
10823
  }
10206
10824
 
@@ -10212,9 +10830,9 @@ function WebGLState( gl, extensions ) {
10212
10830
 
10213
10831
  gl.compressedTexSubImage3D( ...arguments );
10214
10832
 
10215
- } catch ( error ) {
10833
+ } catch ( e ) {
10216
10834
 
10217
- error( 'WebGLState:', error );
10835
+ error( 'WebGLState:', e );
10218
10836
 
10219
10837
  }
10220
10838
 
@@ -10226,9 +10844,9 @@ function WebGLState( gl, extensions ) {
10226
10844
 
10227
10845
  gl.texStorage2D( ...arguments );
10228
10846
 
10229
- } catch ( error ) {
10847
+ } catch ( e ) {
10230
10848
 
10231
- error( 'WebGLState:', error );
10849
+ error( 'WebGLState:', e );
10232
10850
 
10233
10851
  }
10234
10852
 
@@ -10240,9 +10858,9 @@ function WebGLState( gl, extensions ) {
10240
10858
 
10241
10859
  gl.texStorage3D( ...arguments );
10242
10860
 
10243
- } catch ( error ) {
10861
+ } catch ( e ) {
10244
10862
 
10245
- error( 'WebGLState:', error );
10863
+ error( 'WebGLState:', e );
10246
10864
 
10247
10865
  }
10248
10866
 
@@ -10254,9 +10872,9 @@ function WebGLState( gl, extensions ) {
10254
10872
 
10255
10873
  gl.texImage2D( ...arguments );
10256
10874
 
10257
- } catch ( error ) {
10875
+ } catch ( e ) {
10258
10876
 
10259
- error( 'WebGLState:', error );
10877
+ error( 'WebGLState:', e );
10260
10878
 
10261
10879
  }
10262
10880
 
@@ -10268,9 +10886,34 @@ function WebGLState( gl, extensions ) {
10268
10886
 
10269
10887
  gl.texImage3D( ...arguments );
10270
10888
 
10271
- } catch ( error ) {
10889
+ } catch ( e ) {
10890
+
10891
+ error( 'WebGLState:', e );
10892
+
10893
+ }
10894
+
10895
+ }
10896
+
10897
+ function getParameter( name ) {
10898
+
10899
+ if ( parameters[ name ] !== undefined ) {
10900
+
10901
+ return parameters[ name ];
10902
+
10903
+ } else {
10904
+
10905
+ return gl.getParameter( name );
10906
+
10907
+ }
10908
+
10909
+ }
10910
+
10911
+ function pixelStorei( name, value ) {
10912
+
10913
+ if ( parameters[ name ] !== value ) {
10272
10914
 
10273
- error( 'WebGLState:', error );
10915
+ gl.pixelStorei( name, value );
10916
+ parameters[ name ] = value;
10274
10917
 
10275
10918
  }
10276
10919
 
@@ -10392,9 +11035,24 @@ function WebGLState( gl, extensions ) {
10392
11035
  gl.scissor( 0, 0, gl.canvas.width, gl.canvas.height );
10393
11036
  gl.viewport( 0, 0, gl.canvas.width, gl.canvas.height );
10394
11037
 
11038
+ gl.pixelStorei( gl.PACK_ALIGNMENT, 4 );
11039
+ gl.pixelStorei( gl.UNPACK_ALIGNMENT, 4 );
11040
+ gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, false );
11041
+ gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false );
11042
+ gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL );
11043
+ gl.pixelStorei( gl.PACK_ROW_LENGTH, 0 );
11044
+ gl.pixelStorei( gl.PACK_SKIP_PIXELS, 0 );
11045
+ gl.pixelStorei( gl.PACK_SKIP_ROWS, 0 );
11046
+ gl.pixelStorei( gl.UNPACK_ROW_LENGTH, 0 );
11047
+ gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, 0 );
11048
+ gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, 0 );
11049
+ gl.pixelStorei( gl.UNPACK_SKIP_ROWS, 0 );
11050
+ gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, 0 );
11051
+
10395
11052
  // reset internals
10396
11053
 
10397
11054
  enabledCapabilities = {};
11055
+ parameters = {};
10398
11056
 
10399
11057
  currentTextureSlot = null;
10400
11058
  currentBoundTextures = {};
@@ -10468,6 +11126,8 @@ function WebGLState( gl, extensions ) {
10468
11126
  compressedTexImage3D: compressedTexImage3D,
10469
11127
  texImage2D: texImage2D,
10470
11128
  texImage3D: texImage3D,
11129
+ pixelStorei: pixelStorei,
11130
+ getParameter: getParameter,
10471
11131
 
10472
11132
  updateUBOMapping: updateUBOMapping,
10473
11133
  uniformBlockBinding: uniformBlockBinding,
@@ -10496,6 +11156,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10496
11156
 
10497
11157
  const _imageDimensions = new Vector2();
10498
11158
  const _videoTextures = new WeakMap();
11159
+ const _htmlTextures = new Set();
10499
11160
  let _canvas;
10500
11161
 
10501
11162
  const _sources = new WeakMap(); // maps WebglTexture objects to instances of Source
@@ -10512,9 +11173,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10512
11173
  try {
10513
11174
 
10514
11175
  useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
10515
- // eslint-disable-next-line compat/compat
10516
11176
  && ( new OffscreenCanvas( 1, 1 ).getContext( '2d' ) ) !== null;
10517
11177
 
11178
+
10518
11179
  } catch ( err ) {
10519
11180
 
10520
11181
  // Ignore any errors
@@ -10526,7 +11187,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10526
11187
  // Use OffscreenCanvas when available. Specially needed in web workers
10527
11188
 
10528
11189
  return useOffscreenCanvas ?
10529
- // eslint-disable-next-line compat/compat
10530
11190
  new OffscreenCanvas( width, height ) : createElementNS( 'canvas' );
10531
11191
 
10532
11192
  }
@@ -10614,7 +11274,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10614
11274
 
10615
11275
  }
10616
11276
 
10617
- function getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
11277
+ function getInternalFormat( internalFormatName, glFormat, glType, normalized, colorSpace, forceLinearTransfer = false ) {
10618
11278
 
10619
11279
  if ( internalFormatName !== null ) {
10620
11280
 
@@ -10624,6 +11284,20 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10624
11284
 
10625
11285
  }
10626
11286
 
11287
+ let ext_texture_norm16;
11288
+
11289
+ if ( normalized ) {
11290
+
11291
+ ext_texture_norm16 = extensions.get( 'EXT_texture_norm16' );
11292
+
11293
+ if ( ! ext_texture_norm16 ) {
11294
+
11295
+ warn( 'WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension' );
11296
+
11297
+ }
11298
+
11299
+ }
11300
+
10627
11301
  let internalFormat = glFormat;
10628
11302
 
10629
11303
  if ( glFormat === _gl.RED ) {
@@ -10631,6 +11305,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10631
11305
  if ( glType === _gl.FLOAT ) internalFormat = _gl.R32F;
10632
11306
  if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.R16F;
10633
11307
  if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.R8;
11308
+ if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_EXT;
11309
+ if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_SNORM_EXT;
10634
11310
 
10635
11311
  }
10636
11312
 
@@ -10650,6 +11326,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10650
11326
  if ( glType === _gl.FLOAT ) internalFormat = _gl.RG32F;
10651
11327
  if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RG16F;
10652
11328
  if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RG8;
11329
+ if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_EXT;
11330
+ if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_SNORM_EXT;
10653
11331
 
10654
11332
  }
10655
11333
 
@@ -10688,6 +11366,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10688
11366
 
10689
11367
  if ( glFormat === _gl.RGB ) {
10690
11368
 
11369
+ if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_EXT;
11370
+ if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_SNORM_EXT;
10691
11371
  if ( glType === _gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = _gl.RGB9_E5;
10692
11372
  if ( glType === _gl.UNSIGNED_INT_10F_11F_11F_REV ) internalFormat = _gl.R11F_G11F_B10F;
10693
11373
 
@@ -10700,6 +11380,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10700
11380
  if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;
10701
11381
  if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;
10702
11382
  if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
11383
+ if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_EXT;
11384
+ if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_SNORM_EXT;
10703
11385
  if ( glType === _gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = _gl.RGBA4;
10704
11386
  if ( glType === _gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = _gl.RGB5_A1;
10705
11387
 
@@ -10801,6 +11483,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10801
11483
 
10802
11484
  }
10803
11485
 
11486
+ if ( texture.isHTMLTexture ) {
11487
+
11488
+ _htmlTextures.delete( texture );
11489
+
11490
+ }
11491
+
10804
11492
  }
10805
11493
 
10806
11494
  function onRenderTargetDispose( event ) {
@@ -10957,6 +11645,18 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
10957
11645
 
10958
11646
  }
10959
11647
 
11648
+ function getTextureUnits() {
11649
+
11650
+ return textureUnits;
11651
+
11652
+ }
11653
+
11654
+ function setTextureUnits( value ) {
11655
+
11656
+ textureUnits = value;
11657
+
11658
+ }
11659
+
10960
11660
  function allocateTextureUnit() {
10961
11661
 
10962
11662
  const textureUnit = textureUnits;
@@ -11074,7 +11774,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11074
11774
 
11075
11775
  const textureProperties = properties.get( texture );
11076
11776
 
11077
- if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
11777
+ if ( texture.isCubeDepthTexture !== true && texture.version > 0 && textureProperties.__version !== texture.version ) {
11078
11778
 
11079
11779
  uploadCubeTexture( textureProperties, texture, slot );
11080
11780
  return;
@@ -11311,11 +12011,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11311
12011
  // Trim the array to only contain the merged ranges.
11312
12012
  updateRanges.length = mergeIndex + 1;
11313
12013
 
11314
- const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
11315
- const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
11316
- const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
12014
+ const currentUnpackRowLen = state.getParameter( _gl.UNPACK_ROW_LENGTH );
12015
+ const currentUnpackSkipPixels = state.getParameter( _gl.UNPACK_SKIP_PIXELS );
12016
+ const currentUnpackSkipRows = state.getParameter( _gl.UNPACK_SKIP_ROWS );
11317
12017
 
11318
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
12018
+ state.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
11319
12019
 
11320
12020
  for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {
11321
12021
 
@@ -11331,8 +12031,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11331
12031
  const width = pixelCount;
11332
12032
  const height = 1;
11333
12033
 
11334
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, x );
11335
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, y );
12034
+ state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, x );
12035
+ state.pixelStorei( _gl.UNPACK_SKIP_ROWS, y );
11336
12036
 
11337
12037
  state.texSubImage2D( _gl.TEXTURE_2D, 0, x, y, width, height, glFormat, glType, image.data );
11338
12038
 
@@ -11340,11 +12040,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11340
12040
 
11341
12041
  texture.clearUpdateRanges();
11342
12042
 
11343
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
11344
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
11345
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
12043
+ state.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
12044
+ state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
12045
+ state.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
11346
12046
 
11347
12047
  }
12048
+
11348
12049
  }
11349
12050
 
11350
12051
  function setDeferTextureUploads( deferFlag ) {
@@ -11402,14 +12103,21 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11402
12103
 
11403
12104
  state.activeTexture( _gl.TEXTURE0 + slot );
11404
12105
 
11405
- const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );
11406
- const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );
11407
- const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;
12106
+ const isImageBitmap = ( typeof ImageBitmap !== 'undefined' && texture.image instanceof ImageBitmap );
12107
+
12108
+ if ( isImageBitmap === false ) {
11408
12109
 
11409
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
11410
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
11411
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
11412
- _gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
12110
+ const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );
12111
+ const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );
12112
+ const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;
12113
+
12114
+ state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
12115
+ state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
12116
+ state.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
12117
+
12118
+ }
12119
+
12120
+ state.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
11413
12121
 
11414
12122
  let image = resizeImage( texture.image, false, capabilities.maxTextureSize );
11415
12123
  image = verifyColorSpace( texture, image );
@@ -11417,7 +12125,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11417
12125
  const glFormat = utils.convert( texture.format, texture.colorSpace );
11418
12126
 
11419
12127
  const glType = utils.convert( texture.type );
11420
- let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
12128
+ let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, texture.isVideoTexture );
11421
12129
 
11422
12130
  setTextureParameters( textureType, texture );
11423
12131
 
@@ -11734,6 +12442,59 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11734
12442
 
11735
12443
  }
11736
12444
 
12445
+ } else if ( texture.isHTMLTexture ) {
12446
+
12447
+ if ( 'texElementImage2D' in _gl ) {
12448
+
12449
+ const canvas = _gl.canvas;
12450
+
12451
+ // Ensure the canvas supports HTML-in-Canvas and the element is a child.
12452
+ if ( ! canvas.hasAttribute( 'layoutsubtree' ) ) {
12453
+
12454
+ canvas.setAttribute( 'layoutsubtree', 'true' );
12455
+
12456
+ }
12457
+
12458
+ if ( image.parentNode !== canvas ) {
12459
+
12460
+ canvas.appendChild( image );
12461
+
12462
+ // Register and set up a shared paint callback for all HTMLTextures.
12463
+ _htmlTextures.add( texture );
12464
+
12465
+ canvas.onpaint = ( event ) => {
12466
+
12467
+ const changed = event.changedElements;
12468
+
12469
+ for ( const t of _htmlTextures ) {
12470
+
12471
+ if ( changed.includes( t.image ) ) {
12472
+
12473
+ t.needsUpdate = true;
12474
+
12475
+ }
12476
+
12477
+ }
12478
+
12479
+ };
12480
+
12481
+ canvas.requestPaint();
12482
+ return;
12483
+
12484
+ }
12485
+
12486
+ const level = 0;
12487
+ const internalFormat = _gl.RGBA;
12488
+ const srcFormat = _gl.RGBA;
12489
+ const srcType = _gl.UNSIGNED_BYTE;
12490
+
12491
+ _gl.texElementImage2D( _gl.TEXTURE_2D, level, internalFormat, srcFormat, srcType, image );
12492
+ _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.LINEAR );
12493
+ _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
12494
+ _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
12495
+
12496
+ }
12497
+
11737
12498
  } else {
11738
12499
 
11739
12500
  // regular Texture (image, video, canvas)
@@ -11838,10 +12599,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11838
12599
  const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );
11839
12600
  const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;
11840
12601
 
11841
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
11842
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
11843
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
11844
- _gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
12602
+ state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
12603
+ state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
12604
+ state.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
12605
+ state.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
11845
12606
 
11846
12607
  const isCompressed = ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture );
11847
12608
  const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
@@ -11867,7 +12628,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11867
12628
  const image = cubeImage[ 0 ],
11868
12629
  glFormat = utils.convert( texture.format, texture.colorSpace ),
11869
12630
  glType = utils.convert( texture.type ),
11870
- glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
12631
+ glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );
11871
12632
 
11872
12633
  const useTexStorage = ( texture.isVideoTexture !== true );
11873
12634
  const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
@@ -12063,7 +12824,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12063
12824
 
12064
12825
  const glFormat = utils.convert( texture.format, texture.colorSpace );
12065
12826
  const glType = utils.convert( texture.type );
12066
- const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
12827
+ const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );
12067
12828
  const renderTargetProperties = properties.get( renderTarget );
12068
12829
  const textureProperties = properties.get( texture );
12069
12830
 
@@ -12125,7 +12886,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12125
12886
  }
12126
12887
 
12127
12888
  // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
12128
- function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
12889
+ function setupRenderBufferStorage( renderbuffer, renderTarget, useMultisample ) {
12129
12890
 
12130
12891
  _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
12131
12892
 
@@ -12190,15 +12951,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12190
12951
  const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
12191
12952
 
12192
12953
  // set up the attachment
12193
- const samples = getRenderTargetSamples( renderTarget );
12194
- const isUseMultisampledRTT = useMultisampledRTT( renderTarget );
12195
- if ( isUseMultisampledRTT ) {
12954
+ if ( useMultisampledRTT( renderTarget ) ) {
12196
12955
 
12197
- multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
12956
+ multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, getRenderTargetSamples( renderTarget ), glInternalFormat, renderTarget.width, renderTarget.height );
12198
12957
 
12199
- } else if ( isMultisample ) {
12958
+ } else if ( useMultisample ) {
12200
12959
 
12201
- _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
12960
+ _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, getRenderTargetSamples( renderTarget ), glInternalFormat, renderTarget.width, renderTarget.height );
12202
12961
 
12203
12962
  } else {
12204
12963
 
@@ -12218,16 +12977,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12218
12977
 
12219
12978
  const glFormat = utils.convert( texture.format, texture.colorSpace );
12220
12979
  const glType = utils.convert( texture.type );
12221
- const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
12222
- const samples = getRenderTargetSamples( renderTarget );
12980
+ const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );
12223
12981
 
12224
- if ( isMultisample && useMultisampledRTT( renderTarget ) === false ) {
12982
+ if ( useMultisampledRTT( renderTarget ) ) {
12225
12983
 
12226
- _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
12984
+ multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, getRenderTargetSamples( renderTarget ), glInternalFormat, renderTarget.width, renderTarget.height );
12227
12985
 
12228
- } else if ( useMultisampledRTT( renderTarget ) ) {
12986
+ } else if ( useMultisample ) {
12229
12987
 
12230
- multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
12988
+ _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, getRenderTargetSamples( renderTarget ), glInternalFormat, renderTarget.width, renderTarget.height );
12231
12989
 
12232
12990
  } else {
12233
12991
 
@@ -12244,10 +13002,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12244
13002
  }
12245
13003
 
12246
13004
  // Setup resources for a Depth Texture for a FBO (needs an extension)
12247
- function setupDepthTexture( framebuffer, renderTarget ) {
13005
+ function setupDepthTexture( framebuffer, renderTarget, cubeFace ) {
12248
13006
 
12249
- const isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
12250
- if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
13007
+ const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
12251
13008
 
12252
13009
  state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
12253
13010
 
@@ -12271,7 +13028,49 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12271
13028
 
12272
13029
  }
12273
13030
 
12274
- if ( renderTarget.depthTexture.image.depth != 1 ) {
13031
+ if ( isCube ) {
13032
+
13033
+ // For cube depth textures, initialize and bind without uploading image data
13034
+ if ( textureProperties.__webglInit === undefined ) {
13035
+
13036
+ textureProperties.__webglInit = true;
13037
+ renderTarget.depthTexture.addEventListener( 'dispose', onTextureDispose );
13038
+
13039
+ }
13040
+
13041
+ // Only create and allocate storage once
13042
+ if ( textureProperties.__webglTexture === undefined ) {
13043
+
13044
+ textureProperties.__webglTexture = _gl.createTexture();
13045
+
13046
+ state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
13047
+ setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.depthTexture );
13048
+
13049
+ // Allocate storage for all 6 faces with correct depth texture format
13050
+ const glFormat = utils.convert( renderTarget.depthTexture.format );
13051
+ const glType = utils.convert( renderTarget.depthTexture.type );
13052
+
13053
+ // Use proper internal format for depth textures
13054
+ let glInternalFormat;
13055
+ if ( renderTarget.depthTexture.format === DepthFormat ) {
13056
+
13057
+ glInternalFormat = _gl.DEPTH_COMPONENT24;
13058
+
13059
+ } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
13060
+
13061
+ glInternalFormat = _gl.DEPTH24_STENCIL8;
13062
+
13063
+ }
13064
+
13065
+ for ( let i = 0; i < 6; i ++ ) {
13066
+
13067
+ _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
13068
+
13069
+ }
13070
+
13071
+ }
13072
+
13073
+ } else if ( renderTarget.depthTexture.image.depth != 1 ) {
12275
13074
 
12276
13075
  setTexture2DArray( renderTarget.depthTexture, 0 );
12277
13076
 
@@ -12321,15 +13120,18 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12321
13120
 
12322
13121
  } else {
12323
13122
 
13123
+ const glTextureType = isCube ? _gl.TEXTURE_CUBE_MAP_POSITIVE_X + cubeFace : _gl.TEXTURE_2D;
13124
+ const glAttachmentType = renderTarget.depthTexture.format === DepthStencilFormat ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
13125
+
12324
13126
  if ( renderTarget.depthTexture.format === DepthFormat ) {
12325
13127
 
12326
13128
  if ( useMultisampledRTT( renderTarget ) ) {
12327
13129
 
12328
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
13130
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, glAttachmentType, glTextureType, webglDepthTexture, 0, samples );
12329
13131
 
12330
13132
  } else {
12331
13133
 
12332
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
13134
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, glAttachmentType, glTextureType, webglDepthTexture, 0 );
12333
13135
 
12334
13136
  }
12335
13137
 
@@ -12337,11 +13139,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12337
13139
 
12338
13140
  if ( useMultisampledRTT( renderTarget ) ) {
12339
13141
 
12340
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples );
13142
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, glAttachmentType, glTextureType, webglDepthTexture, 0, samples );
12341
13143
 
12342
13144
  } else {
12343
13145
 
12344
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0 );
13146
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, glAttachmentType, glTextureType, webglDepthTexture, 0 );
12345
13147
 
12346
13148
  }
12347
13149
 
@@ -12394,17 +13196,28 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12394
13196
 
12395
13197
  if ( renderTarget.depthTexture && ! renderTargetProperties.__autoAllocateDepthBuffer ) {
12396
13198
 
12397
- if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
13199
+ if ( isCube ) {
12398
13200
 
12399
- const mipmaps = renderTarget.texture.mipmaps;
13201
+ // For cube render targets with depth texture, setup each face
13202
+ for ( let i = 0; i < 6; i ++ ) {
12400
13203
 
12401
- if ( mipmaps && mipmaps.length > 0 ) {
13204
+ setupDepthTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, i );
12402
13205
 
12403
- setupDepthTexture( renderTargetProperties.__webglFramebuffer[ 0 ], renderTarget );
13206
+ }
12404
13207
 
12405
13208
  } else {
12406
13209
 
12407
- setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
13210
+ const mipmaps = renderTarget.texture.mipmaps;
13211
+
13212
+ if ( mipmaps && mipmaps.length > 0 ) {
13213
+
13214
+ setupDepthTexture( renderTargetProperties.__webglFramebuffer[ 0 ], renderTarget, 0 );
13215
+
13216
+ } else {
13217
+
13218
+ setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 0 );
13219
+
13220
+ }
12408
13221
 
12409
13222
  }
12410
13223
 
@@ -12597,7 +13410,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12597
13410
 
12598
13411
  const glFormat = utils.convert( texture.format, texture.colorSpace );
12599
13412
  const glType = utils.convert( texture.type );
12600
- const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, renderTarget.isXRRenderTarget === true );
13413
+ const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, renderTarget.isXRRenderTarget === true );
12601
13414
  const samples = getRenderTargetSamples( renderTarget );
12602
13415
  _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
12603
13416
 
@@ -12979,6 +13792,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12979
13792
 
12980
13793
  this.allocateTextureUnit = allocateTextureUnit;
12981
13794
  this.resetTextureUnits = resetTextureUnits;
13795
+ this.getTextureUnits = getTextureUnits;
13796
+ this.setTextureUnits = setTextureUnits;
12982
13797
 
12983
13798
  this.setTexture2D = setTexture2D;
12984
13799
  this.setTexture2DArray = setTexture2DArray;
@@ -12996,6 +13811,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
12996
13811
  this.runDeferredUploads = runDeferredUploads;
12997
13812
  this.setDeferTextureUploads = setDeferTextureUploads;
12998
13813
 
13814
+ this.isReversedDepthBuffer = function () {
13815
+
13816
+ return state.buffers.depth.getReversed();
13817
+
13818
+ };
13819
+
12999
13820
  }
13000
13821
 
13001
13822
  function WebGLUtils( gl, extensions ) {
@@ -13099,7 +13920,7 @@ function WebGLUtils( gl, extensions ) {
13099
13920
 
13100
13921
  // ETC
13101
13922
 
13102
- if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
13923
+ if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format || p === R11_EAC_Format || p === SIGNED_R11_EAC_Format || p === RG11_EAC_Format || p === SIGNED_RG11_EAC_Format ) {
13103
13924
 
13104
13925
  extension = extensions.get( 'WEBGL_compressed_texture_etc' );
13105
13926
 
@@ -13107,6 +13928,10 @@ function WebGLUtils( gl, extensions ) {
13107
13928
 
13108
13929
  if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
13109
13930
  if ( p === RGBA_ETC2_EAC_Format ) return ( transfer === SRGBTransfer ) ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC;
13931
+ if ( p === R11_EAC_Format ) return extension.COMPRESSED_R11_EAC;
13932
+ if ( p === SIGNED_R11_EAC_Format ) return extension.COMPRESSED_SIGNED_R11_EAC;
13933
+ if ( p === RG11_EAC_Format ) return extension.COMPRESSED_RG11_EAC;
13934
+ if ( p === SIGNED_RG11_EAC_Format ) return extension.COMPRESSED_SIGNED_RG11_EAC;
13110
13935
 
13111
13936
  } else {
13112
13937
 
@@ -13404,6 +14229,8 @@ class WebXRManager extends EventDispatcher {
13404
14229
  *
13405
14230
  * @param {WebGLRenderer} renderer - The renderer.
13406
14231
  * @param {WebGL2RenderingContext} gl - The rendering context.
14232
+ * @param {WebGLExtensions} extensions - The WebGL extensions helper.
14233
+ * @param {boolean} useMultiview - Whether to enable OCULUS_multiview when available.
13407
14234
  */
13408
14235
  constructor( renderer, gl, extensions, useMultiview ) {
13409
14236
 
@@ -14188,8 +15015,8 @@ class WebXRManager extends EventDispatcher {
14188
15015
 
14189
15016
  // inherit camera layers and enable eye layers (1 = left, 2 = right)
14190
15017
  cameraXR.layers.mask = camera.layers.mask | 0b110;
14191
- cameraL.layers.mask = cameraXR.layers.mask & 0b011;
14192
- cameraR.layers.mask = cameraXR.layers.mask & 0b101;
15018
+ cameraL.layers.mask = cameraXR.layers.mask & -5;
15019
+ cameraR.layers.mask = cameraXR.layers.mask & -3;
14193
15020
 
14194
15021
  const cameras = cameraXR.cameras;
14195
15022
  var object = poseTarget || camera;
@@ -14540,8 +15367,10 @@ class WebXRManager extends EventDispatcher {
14540
15367
 
14541
15368
  }
14542
15369
 
14543
- const _e1 = /*@__PURE__*/ new Euler();
14544
15370
  const _m1 = /*@__PURE__*/ new Matrix4();
15371
+ const _m = /*@__PURE__*/ new Matrix3();
15372
+
15373
+ _m.set( -1, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0 );
14545
15374
 
14546
15375
  function WebGLMaterials( renderer, properties ) {
14547
15376
 
@@ -14576,7 +15405,11 @@ function WebGLMaterials( renderer, properties ) {
14576
15405
 
14577
15406
  function refreshMaterialUniforms( uniforms, material, pixelRatio, height, transmissionRenderTarget ) {
14578
15407
 
14579
- if ( material.isMeshBasicMaterial ) {
15408
+ if ( material.isNodeMaterial ) {
15409
+
15410
+ material.uniformsNeedUpdate = false;
15411
+
15412
+ } else if ( material.isMeshBasicMaterial ) {
14580
15413
 
14581
15414
  refreshUniformsCommon( uniforms, material );
14582
15415
 
@@ -14584,6 +15417,12 @@ function WebGLMaterials( renderer, properties ) {
14584
15417
 
14585
15418
  refreshUniformsCommon( uniforms, material );
14586
15419
 
15420
+ if ( material.envMap ) {
15421
+
15422
+ uniforms.envMapIntensity.value = material.envMapIntensity;
15423
+
15424
+ }
15425
+
14587
15426
  } else if ( material.isMeshToonMaterial ) {
14588
15427
 
14589
15428
  refreshUniformsCommon( uniforms, material );
@@ -14594,6 +15433,12 @@ function WebGLMaterials( renderer, properties ) {
14594
15433
  refreshUniformsCommon( uniforms, material );
14595
15434
  refreshUniformsPhong( uniforms, material );
14596
15435
 
15436
+ if ( material.envMap ) {
15437
+
15438
+ uniforms.envMapIntensity.value = material.envMapIntensity;
15439
+
15440
+ }
15441
+
14597
15442
  } else if ( material.isMeshStandardMaterial ) {
14598
15443
 
14599
15444
  refreshUniformsCommon( uniforms, material );
@@ -14760,23 +15605,16 @@ function WebGLMaterials( renderer, properties ) {
14760
15605
 
14761
15606
  uniforms.envMap.value = envMap;
14762
15607
 
14763
- _e1.copy( envMapRotation );
15608
+ // note: since the matrix is orthonormal, we can use the more-efficient transpose() in lieu of invert()
15609
+ uniforms.envMapRotation.value.setFromMatrix4( _m1.makeRotationFromEuler( envMapRotation ) ).transpose();
14764
15610
 
14765
- // accommodate left-handed frame
14766
- _e1.x *= -1; _e1.y *= -1; _e1.z *= -1;
14767
15611
 
14768
15612
  if ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) {
14769
15613
 
14770
- // environment maps which are not cube render targets or PMREMs follow a different convention
14771
- _e1.y *= -1;
14772
- _e1.z *= -1;
15614
+ uniforms.envMapRotation.value.premultiply( _m );
14773
15615
 
14774
15616
  }
14775
15617
 
14776
- uniforms.envMapRotation.value.setFromMatrix4( _m1.makeRotationFromEuler( _e1 ) );
14777
-
14778
- uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? -1 : 1;
14779
-
14780
15618
  uniforms.reflectivity.value = material.reflectivity;
14781
15619
  uniforms.ior.value = material.ior;
14782
15620
  uniforms.refractionRatio.value = material.refractionRatio;
@@ -15266,6 +16104,11 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
15266
16104
  uniform.__data[ 10 ] = value.elements[ 8 ];
15267
16105
  uniform.__data[ 11 ] = 0;
15268
16106
 
16107
+ } else if ( ArrayBuffer.isView( value ) ) {
16108
+
16109
+ // copy the buffer data using "set"
16110
+ uniform.__data.set( new value.constructor( value.buffer, value.byteOffset, uniform.__data.length ) );
16111
+
15269
16112
  } else {
15270
16113
 
15271
16114
  value.toArray( uniform.__data, arrayOffset );
@@ -15301,6 +16144,10 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
15301
16144
 
15302
16145
  cache[ indexString ] = value;
15303
16146
 
16147
+ } else if ( ArrayBuffer.isView( value ) ) {
16148
+
16149
+ cache[ indexString ] = value.slice();
16150
+
15304
16151
  } else {
15305
16152
 
15306
16153
  cache[ indexString ] = value.clone();
@@ -15324,6 +16171,11 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
15324
16171
 
15325
16172
  }
15326
16173
 
16174
+ } else if ( ArrayBuffer.isView( value ) ) {
16175
+
16176
+ // always update the array buffers
16177
+ return true;
16178
+
15327
16179
  } else {
15328
16180
 
15329
16181
  if ( cachedObject.equals( value ) === false ) {
@@ -15464,6 +16316,11 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
15464
16316
 
15465
16317
  warn( 'WebGLRenderer: Texture samplers can not be part of an uniforms group.' );
15466
16318
 
16319
+ } else if ( ArrayBuffer.isView( value ) ) {
16320
+
16321
+ info.boundary = 16;
16322
+ info.storage = value.byteLength;
16323
+
15467
16324
  } else {
15468
16325
 
15469
16326
  warn( 'WebGLRenderer: Unsupported uniform value type.', value );
@@ -15517,45 +16374,29 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
15517
16374
 
15518
16375
  /**
15519
16376
  * Precomputed DFG LUT for Image-Based Lighting
15520
- * Resolution: 32x32
16377
+ * Resolution: 16x16
15521
16378
  * Samples: 4096 per texel
15522
16379
  * Format: RG16F (2 half floats per texel: scale, bias)
15523
16380
  */
15524
16381
 
15525
16382
 
15526
16383
  const DATA = new Uint16Array( [
15527
- 0x2cd9, 0x3b64, 0x2d0e, 0x3b43, 0x2e20, 0x3aa7, 0x3061, 0x39fb, 0x325e, 0x397c, 0x3454, 0x3908, 0x357d, 0x3893, 0x3698, 0x381e, 0x379d, 0x375b, 0x3845, 0x3689, 0x38af, 0x35ca, 0x390d, 0x351e, 0x395f, 0x3484, 0x39a8, 0x33f9, 0x39e6, 0x330a, 0x3a1c, 0x3239, 0x3a4b, 0x3183, 0x3a73, 0x30e5, 0x3a95, 0x305b, 0x3ab1, 0x2fc6, 0x3ac9, 0x2ef7, 0x3ade, 0x2e43, 0x3aee, 0x2da7, 0x3afc, 0x2d1f, 0x3b07, 0x2ca9, 0x3b10, 0x2c42, 0x3b17, 0x2bd1, 0x3b1c, 0x2b34, 0x3b1f, 0x2aaa, 0x3b22, 0x2a31, 0x3b23, 0x29c7, 0x3b23, 0x2968,
15528
- 0x32d4, 0x3a4b, 0x32dc, 0x3a45, 0x3308, 0x3a26, 0x3378, 0x39d0, 0x3425, 0x394a, 0x34c9, 0x38be, 0x359c, 0x383e, 0x3688, 0x3796, 0x3778, 0x36c4, 0x382f, 0x3603, 0x3898, 0x3553, 0x38f7, 0x34b3, 0x394b, 0x3424, 0x3994, 0x334c, 0x39d3, 0x326c, 0x3a08, 0x31a9, 0x3a35, 0x30fe, 0x3a5a, 0x306a, 0x3a78, 0x2fd1, 0x3a90, 0x2ef1, 0x3aa2, 0x2e2e, 0x3ab0, 0x2d86, 0x3aba, 0x2cf3, 0x3ac1, 0x2c74, 0x3ac4, 0x2c05, 0x3ac4, 0x2b49, 0x3ac2, 0x2aa1, 0x3abd, 0x2a0c, 0x3ab7, 0x298b, 0x3aaf, 0x2918, 0x3aa6, 0x28b3, 0x3a9b, 0x285a,
15529
- 0x3559, 0x3954, 0x355a, 0x3951, 0x3566, 0x3944, 0x3582, 0x391e, 0x35b6, 0x38d3, 0x360a, 0x386a, 0x3684, 0x37ed, 0x3720, 0x370d, 0x37d3, 0x3641, 0x3847, 0x3588, 0x38a3, 0x34e2, 0x38fa, 0x344d, 0x3948, 0x3391, 0x398d, 0x32a6, 0x39c8, 0x31d6, 0x39fa, 0x3121, 0x3a22, 0x3082, 0x3a43, 0x2ff0, 0x3a5c, 0x2f01, 0x3a6f, 0x2e32, 0x3a7c, 0x2d7e, 0x3a84, 0x2ce2, 0x3a87, 0x2c5b, 0x3a87, 0x2bcc, 0x3a83, 0x2b00, 0x3a7b, 0x2a4e, 0x3a71, 0x29b3, 0x3a66, 0x292c, 0x3a58, 0x28b4, 0x3a4b, 0x284b, 0x3a3d, 0x27dc, 0x3a2e, 0x2739,
15530
- 0x3709, 0x387c, 0x370a, 0x387b, 0x3710, 0x3874, 0x3720, 0x385f, 0x373d, 0x3834, 0x376a, 0x37e1, 0x37ac, 0x3732, 0x3805, 0x3675, 0x383f, 0x35bc, 0x3883, 0x3511, 0x38cb, 0x3476, 0x3912, 0x33d8, 0x3955, 0x32e2, 0x3991, 0x3208, 0x39c6, 0x3149, 0x39f1, 0x30a1, 0x3a15, 0x300f, 0x3a30, 0x2f21, 0x3a44, 0x2e45, 0x3a51, 0x2d87, 0x3a59, 0x2ce2, 0x3a5b, 0x2c53, 0x3a58, 0x2bb0, 0x3a52, 0x2ada, 0x3a49, 0x2a1f, 0x3a40, 0x297d, 0x3a34, 0x28f0, 0x3a25, 0x2874, 0x3a13, 0x2807, 0x3a00, 0x274e, 0x39eb, 0x26a6, 0x39d5, 0x2611,
15531
- 0x3840, 0x3780, 0x3840, 0x377e, 0x3842, 0x3776, 0x3846, 0x375e, 0x384f, 0x372a, 0x385b, 0x36d3, 0x386c, 0x3659, 0x3885, 0x35c7, 0x38a8, 0x352d, 0x38d4, 0x3497, 0x3906, 0x340c, 0x393b, 0x331a, 0x3970, 0x323a, 0x39a0, 0x3172, 0x39cb, 0x30c3, 0x39ef, 0x302a, 0x3a0c, 0x2f4a, 0x3a21, 0x2e63, 0x3a2f, 0x2d9b, 0x3a37, 0x2ced, 0x3a39, 0x2c57, 0x3a37, 0x2baa, 0x3a34, 0x2ac9, 0x3a2c, 0x2a05, 0x3a20, 0x295d, 0x3a11, 0x28ca, 0x39ff, 0x2849, 0x39eb, 0x27b2, 0x39d5, 0x26ed, 0x39be, 0x2640, 0x39a5, 0x25aa, 0x398b, 0x2523,
15532
- 0x38e2, 0x363b, 0x38e2, 0x363b, 0x38e3, 0x3635, 0x38e6, 0x3626, 0x38ea, 0x3606, 0x38f0, 0x35cd, 0x38f8, 0x3579, 0x3903, 0x350e, 0x3915, 0x3495, 0x392d, 0x3418, 0x394c, 0x3340, 0x3970, 0x3261, 0x3995, 0x3197, 0x39b8, 0x30e4, 0x39d8, 0x3046, 0x39f3, 0x2f76, 0x3a08, 0x2e86, 0x3a16, 0x2db5, 0x3a1e, 0x2cff, 0x3a22, 0x2c61, 0x3a24, 0x2bb3, 0x3a20, 0x2ac7, 0x3a17, 0x29fc, 0x3a0a, 0x294c, 0x39fa, 0x28b2, 0x39e7, 0x282e, 0x39d1, 0x2773, 0x39b9, 0x26a9, 0x399f, 0x25fa, 0x3985, 0x255f, 0x3968, 0x24d6, 0x394a, 0x245d,
15533
- 0x396e, 0x3524, 0x396e, 0x3524, 0x396e, 0x3520, 0x396f, 0x3517, 0x3971, 0x3502, 0x3973, 0x34dd, 0x3975, 0x34a5, 0x3978, 0x3458, 0x397e, 0x33f9, 0x3987, 0x3332, 0x3997, 0x326b, 0x39aa, 0x31ac, 0x39c0, 0x30fb, 0x39d7, 0x305c, 0x39eb, 0x2f9e, 0x39fc, 0x2ea7, 0x3a07, 0x2dcf, 0x3a0f, 0x2d13, 0x3a16, 0x2c70, 0x3a17, 0x2bc4, 0x3a14, 0x2ad0, 0x3a0a, 0x29fc, 0x39fd, 0x2945, 0x39ed, 0x28a6, 0x39d9, 0x281d, 0x39c2, 0x274a, 0x39a9, 0x267c, 0x398e, 0x25c7, 0x3971, 0x2528, 0x3952, 0x249e, 0x3931, 0x2425, 0x3910, 0x2374,
15534
- 0x39e5, 0x3436, 0x39e5, 0x3435, 0x39e5, 0x3434, 0x39e5, 0x342e, 0x39e5, 0x3420, 0x39e5, 0x3408, 0x39e3, 0x33c4, 0x39e1, 0x3359, 0x39df, 0x32d3, 0x39de, 0x323a, 0x39e1, 0x319a, 0x39e7, 0x30fb, 0x39f0, 0x3065, 0x39f9, 0x2fb6, 0x3a02, 0x2ec0, 0x3a08, 0x2de6, 0x3a0d, 0x2d26, 0x3a12, 0x2c7e, 0x3a13, 0x2bda, 0x3a0e, 0x2adc, 0x3a05, 0x2a02, 0x39f8, 0x2945, 0x39e7, 0x28a1, 0x39d3, 0x2813, 0x39bc, 0x2730, 0x39a2, 0x265c, 0x3985, 0x25a3, 0x3966, 0x2501, 0x3945, 0x2475, 0x3923, 0x23f3, 0x3901, 0x231c, 0x38dd, 0x225e,
15535
- 0x3a4b, 0x32d6, 0x3a4a, 0x32d6, 0x3a4a, 0x32d4, 0x3a4a, 0x32cc, 0x3a48, 0x32bb, 0x3a47, 0x329d, 0x3a43, 0x326b, 0x3a3d, 0x3222, 0x3a36, 0x31c2, 0x3a2e, 0x314f, 0x3a28, 0x30d2, 0x3a23, 0x3052, 0x3a20, 0x2fab, 0x3a1e, 0x2ec2, 0x3a1b, 0x2def, 0x3a19, 0x2d31, 0x3a1a, 0x2c89, 0x3a18, 0x2beb, 0x3a11, 0x2aea, 0x3a07, 0x2a0a, 0x39fa, 0x2948, 0x39e9, 0x28a1, 0x39d4, 0x280f, 0x39bd, 0x2721, 0x39a2, 0x2647, 0x3985, 0x258b, 0x3964, 0x24e5, 0x3942, 0x2455, 0x391f, 0x23b3, 0x38fb, 0x22d8, 0x38d4, 0x2219, 0x38ad, 0x2172,
15536
- 0x3aa0, 0x3180, 0x3aa0, 0x3180, 0x3aa0, 0x317f, 0x3a9f, 0x317b, 0x3a9d, 0x3170, 0x3a99, 0x315d, 0x3a95, 0x313d, 0x3a8d, 0x310c, 0x3a82, 0x30ca, 0x3a76, 0x3077, 0x3a69, 0x3019, 0x3a5c, 0x2f68, 0x3a4f, 0x2e9e, 0x3a42, 0x2dde, 0x3a37, 0x2d2b, 0x3a30, 0x2c89, 0x3a29, 0x2bef, 0x3a1f, 0x2af0, 0x3a12, 0x2a0f, 0x3a03, 0x294a, 0x39f1, 0x28a0, 0x39dc, 0x280c, 0x39c5, 0x2717, 0x39a9, 0x2638, 0x398b, 0x2578, 0x396a, 0x24d0, 0x3947, 0x243f, 0x3923, 0x2380, 0x38fc, 0x22a4, 0x38d4, 0x21e4, 0x38ac, 0x213c, 0x3883, 0x20a8,
15537
- 0x3ae8, 0x3062, 0x3ae8, 0x3062, 0x3ae7, 0x3061, 0x3ae6, 0x305f, 0x3ae4, 0x305a, 0x3ae0, 0x304f, 0x3ada, 0x303b, 0x3ad1, 0x301b, 0x3ac5, 0x2fdd, 0x3ab6, 0x2f6a, 0x3aa4, 0x2ede, 0x3a91, 0x2e45, 0x3a7c, 0x2da5, 0x3a67, 0x2d0a, 0x3a57, 0x2c77, 0x3a48, 0x2bdc, 0x3a38, 0x2ae5, 0x3a27, 0x2a0a, 0x3a16, 0x2947, 0x3a02, 0x289d, 0x39eb, 0x2808, 0x39d3, 0x270d, 0x39b6, 0x262b, 0x3997, 0x256a, 0x3976, 0x24bf, 0x3952, 0x242b, 0x392d, 0x2358, 0x3904, 0x227a, 0x38db, 0x21b8, 0x38b2, 0x2110, 0x3887, 0x207d, 0x385b, 0x1ff6,
15538
- 0x3b23, 0x2ee8, 0x3b23, 0x2ee8, 0x3b22, 0x2ee8, 0x3b21, 0x2ee7, 0x3b1f, 0x2ee3, 0x3b1a, 0x2ed6, 0x3b14, 0x2ec1, 0x3b0b, 0x2e99, 0x3afe, 0x2e60, 0x3aee, 0x2e12, 0x3ad8, 0x2dad, 0x3ac1, 0x2d3d, 0x3aa5, 0x2cc3, 0x3a8b, 0x2c48, 0x3a76, 0x2ba2, 0x3a60, 0x2ac0, 0x3a49, 0x29f2, 0x3a32, 0x2938, 0x3a1b, 0x2893, 0x3a02, 0x27ff, 0x39e8, 0x26ff, 0x39ca, 0x261e, 0x39aa, 0x255b, 0x3988, 0x24b0, 0x3964, 0x241c, 0x393d, 0x2336, 0x3913, 0x2257, 0x38e9, 0x2195, 0x38be, 0x20eb, 0x3891, 0x2059, 0x3864, 0x1fae, 0x3837, 0x1ecd,
15539
- 0x3b54, 0x2d61, 0x3b54, 0x2d61, 0x3b53, 0x2d61, 0x3b52, 0x2d62, 0x3b4f, 0x2d61, 0x3b4b, 0x2d5c, 0x3b45, 0x2d51, 0x3b3b, 0x2d3d, 0x3b2e, 0x2d1a, 0x3b1d, 0x2ce7, 0x3b06, 0x2ca3, 0x3aeb, 0x2c52, 0x3acb, 0x2bee, 0x3ab0, 0x2b31, 0x3a94, 0x2a74, 0x3a77, 0x29bf, 0x3a5a, 0x2915, 0x3a3f, 0x287a, 0x3a22, 0x27de, 0x3a05, 0x26e4, 0x39e5, 0x2609, 0x39c3, 0x2547, 0x39a0, 0x249f, 0x397b, 0x240c, 0x3953, 0x2314, 0x3928, 0x2238, 0x38fd, 0x2175, 0x38d0, 0x20cb, 0x38a2, 0x2038, 0x3873, 0x1f71, 0x3844, 0x1e90, 0x3815, 0x1dce,
15540
- 0x3b7c, 0x2c22, 0x3b7c, 0x2c22, 0x3b7b, 0x2c23, 0x3b7a, 0x2c25, 0x3b77, 0x2c27, 0x3b73, 0x2c26, 0x3b6d, 0x2c23, 0x3b64, 0x2c1a, 0x3b57, 0x2c07, 0x3b46, 0x2bd1, 0x3b2e, 0x2b79, 0x3b0f, 0x2b07, 0x3aef, 0x2a86, 0x3ad1, 0x29f8, 0x3ab0, 0x2967, 0x3a8e, 0x28d7, 0x3a6d, 0x284e, 0x3a4c, 0x279f, 0x3a2b, 0x26b7, 0x3a08, 0x25e5, 0x39e4, 0x252c, 0x39be, 0x2488, 0x3998, 0x23f0, 0x396f, 0x22f2, 0x3943, 0x2215, 0x3917, 0x2155, 0x38e8, 0x20ae, 0x38b9, 0x201c, 0x3888, 0x1f38, 0x3857, 0x1e5a, 0x3826, 0x1d9a, 0x37eb, 0x1cf0,
15541
- 0x3b9c, 0x2a43, 0x3b9c, 0x2a43, 0x3b9b, 0x2a46, 0x3b9a, 0x2a4a, 0x3b98, 0x2a50, 0x3b93, 0x2a54, 0x3b8e, 0x2a59, 0x3b85, 0x2a56, 0x3b79, 0x2a45, 0x3b67, 0x2a24, 0x3b4f, 0x29ee, 0x3b2f, 0x29a4, 0x3b10, 0x294b, 0x3aef, 0x28e5, 0x3ac9, 0x2877, 0x3aa4, 0x2809, 0x3a7e, 0x2739, 0x3a59, 0x266d, 0x3a34, 0x25af, 0x3a0c, 0x2503, 0x39e4, 0x2468, 0x39bb, 0x23bb, 0x3990, 0x22c6, 0x3963, 0x21f0, 0x3936, 0x2133, 0x3906, 0x208f, 0x38d5, 0x1ffd, 0x38a3, 0x1f04, 0x3870, 0x1e28, 0x383d, 0x1d69, 0x380b, 0x1cc3, 0x37b0, 0x1c32,
15542
- 0x3bb5, 0x28aa, 0x3bb5, 0x28ab, 0x3bb5, 0x28ad, 0x3bb4, 0x28b2, 0x3bb2, 0x28b9, 0x3bae, 0x28c2, 0x3ba8, 0x28ca, 0x3ba0, 0x28d1, 0x3b94, 0x28cd, 0x3b83, 0x28c1, 0x3b6a, 0x28a3, 0x3b4b, 0x2876, 0x3b2d, 0x283d, 0x3b09, 0x27ea, 0x3ae1, 0x274b, 0x3ab9, 0x26a6, 0x3a8f, 0x25fe, 0x3a67, 0x255d, 0x3a3d, 0x24c5, 0x3a11, 0x2439, 0x39e6, 0x2371, 0x39b9, 0x228d, 0x398a, 0x21c1, 0x395a, 0x210b, 0x3929, 0x206c, 0x38f7, 0x1fc1, 0x38c3, 0x1ecb, 0x388f, 0x1df6, 0x385a, 0x1d3a, 0x3825, 0x1c99, 0x37e1, 0x1c08, 0x3779, 0x1b1b,
15543
- 0x3bc9, 0x26d3, 0x3bc9, 0x26d4, 0x3bc9, 0x26d9, 0x3bc8, 0x26e3, 0x3bc6, 0x26ef, 0x3bc2, 0x2705, 0x3bbd, 0x271a, 0x3bb6, 0x2731, 0x3baa, 0x273c, 0x3b9a, 0x273d, 0x3b81, 0x2726, 0x3b65, 0x26f7, 0x3b46, 0x26af, 0x3b20, 0x2650, 0x3af7, 0x25e1, 0x3acd, 0x256a, 0x3aa1, 0x24eb, 0x3a75, 0x246f, 0x3a46, 0x23ee, 0x3a17, 0x230d, 0x39e9, 0x223e, 0x39b7, 0x2183, 0x3985, 0x20d8, 0x3953, 0x2043, 0x391e, 0x1f7a, 0x38e9, 0x1e8d, 0x38b3, 0x1dbf, 0x387c, 0x1d0b, 0x3845, 0x1c6c, 0x380e, 0x1bc4, 0x37b0, 0x1ad2, 0x3745, 0x19fd,
15544
- 0x3bd9, 0x24e4, 0x3bd9, 0x24e5, 0x3bd9, 0x24e8, 0x3bd8, 0x24f2, 0x3bd5, 0x24fe, 0x3bd2, 0x2512, 0x3bce, 0x252b, 0x3bc6, 0x2544, 0x3bbc, 0x255a, 0x3bac, 0x256b, 0x3b93, 0x2569, 0x3b7a, 0x2557, 0x3b5b, 0x252f, 0x3b34, 0x24f7, 0x3b0c, 0x24ad, 0x3adf, 0x2458, 0x3ab1, 0x23f8, 0x3a82, 0x233f, 0x3a4f, 0x2286, 0x3a1e, 0x21d5, 0x39eb, 0x2130, 0x39b6, 0x2098, 0x3982, 0x200e, 0x394b, 0x1f25, 0x3914, 0x1e45, 0x38dc, 0x1d83, 0x38a3, 0x1cd6, 0x386b, 0x1c3d, 0x3831, 0x1b71, 0x37f2, 0x1a87, 0x3782, 0x19bc, 0x3714, 0x1909,
15545
- 0x3be5, 0x22d8, 0x3be5, 0x22d9, 0x3be4, 0x22df, 0x3be4, 0x22ef, 0x3be1, 0x2305, 0x3bde, 0x232a, 0x3bda, 0x2358, 0x3bd4, 0x2392, 0x3bcb, 0x23ca, 0x3bbb, 0x23f4, 0x3ba3, 0x2405, 0x3b8c, 0x2405, 0x3b6c, 0x23ec, 0x3b47, 0x23ae, 0x3b1d, 0x2353, 0x3af0, 0x22e2, 0x3ac0, 0x2261, 0x3a8e, 0x21d9, 0x3a5a, 0x214e, 0x3a26, 0x20c7, 0x39ee, 0x2045, 0x39b7, 0x1f97, 0x397f, 0x1eba, 0x3945, 0x1df0, 0x390b, 0x1d3a, 0x38d0, 0x1c9a, 0x3895, 0x1c0a, 0x385a, 0x1b18, 0x381f, 0x1a39, 0x37c9, 0x1975, 0x3756, 0x18cc, 0x36e6, 0x1836,
15546
- 0x3bed, 0x20a8, 0x3bed, 0x20a9, 0x3bed, 0x20ae, 0x3bed, 0x20bb, 0x3beb, 0x20cf, 0x3be8, 0x20ef, 0x3be4, 0x2119, 0x3bde, 0x214f, 0x3bd6, 0x2189, 0x3bc6, 0x21b8, 0x3bb1, 0x21de, 0x3b9a, 0x21f2, 0x3b7b, 0x21f2, 0x3b57, 0x21d8, 0x3b2d, 0x21a4, 0x3b00, 0x215f, 0x3acf, 0x2108, 0x3a99, 0x20a8, 0x3a64, 0x2043, 0x3a2c, 0x1fba, 0x39f2, 0x1ef3, 0x39b8, 0x1e36, 0x397c, 0x1d86, 0x3940, 0x1ce5, 0x3903, 0x1c52, 0x38c6, 0x1b9e, 0x3888, 0x1ab3, 0x384a, 0x19e4, 0x380e, 0x192b, 0x37a3, 0x188b, 0x372d, 0x17f7, 0x36ba, 0x1701,
15547
- 0x3bf4, 0x1e23, 0x3bf4, 0x1e25, 0x3bf4, 0x1e2d, 0x3bf3, 0x1e41, 0x3bf1, 0x1e64, 0x3bef, 0x1e9c, 0x3beb, 0x1ee1, 0x3be6, 0x1f40, 0x3bde, 0x1fa7, 0x3bce, 0x2001, 0x3bbd, 0x202f, 0x3ba6, 0x204e, 0x3b88, 0x205f, 0x3b64, 0x205b, 0x3b3b, 0x2044, 0x3b0e, 0x201f, 0x3adb, 0x1fcf, 0x3aa6, 0x1f4e, 0x3a6e, 0x1ec1, 0x3a33, 0x1e2b, 0x39f7, 0x1d95, 0x39ba, 0x1d06, 0x397b, 0x1c7d, 0x393c, 0x1bfc, 0x38fc, 0x1b13, 0x38bc, 0x1a40, 0x387c, 0x1983, 0x383c, 0x18da, 0x37fa, 0x1842, 0x377f, 0x177f, 0x3706, 0x1695, 0x3691, 0x15c8,
15548
- 0x3bf8, 0x1bca, 0x3bf8, 0x1bcc, 0x3bf8, 0x1bd8, 0x3bf8, 0x1bf7, 0x3bf6, 0x1c1b, 0x3bf4, 0x1c45, 0x3bf1, 0x1c83, 0x3bec, 0x1cce, 0x3be4, 0x1d21, 0x3bd5, 0x1d78, 0x3bc5, 0x1dd1, 0x3bb0, 0x1e17, 0x3b93, 0x1e4a, 0x3b70, 0x1e5f, 0x3b48, 0x1e57, 0x3b1b, 0x1e35, 0x3ae7, 0x1df6, 0x3ab2, 0x1da4, 0x3a77, 0x1d44, 0x3a3a, 0x1cdb, 0x39fc, 0x1c6e, 0x39bb, 0x1c03, 0x397a, 0x1b35, 0x3938, 0x1a72, 0x38f5, 0x19bb, 0x38b3, 0x1914, 0x3870, 0x187d, 0x382e, 0x17eb, 0x37db, 0x16f9, 0x375c, 0x1621, 0x36e1, 0x1565, 0x3669, 0x14be,
15549
- 0x3bfb, 0x18b9, 0x3bfb, 0x18ba, 0x3bfb, 0x18c3, 0x3bfb, 0x18da, 0x3bf9, 0x190a, 0x3bf7, 0x1948, 0x3bf5, 0x19ac, 0x3bf0, 0x1a20, 0x3be9, 0x1ab3, 0x3bdb, 0x1b49, 0x3bcd, 0x1be6, 0x3bb7, 0x1c34, 0x3b9c, 0x1c6d, 0x3b7a, 0x1c8e, 0x3b54, 0x1c9e, 0x3b26, 0x1c96, 0x3af2, 0x1c75, 0x3abc, 0x1c47, 0x3a80, 0x1c09, 0x3a42, 0x1b85, 0x3a01, 0x1aec, 0x39be, 0x1a50, 0x397a, 0x19b5, 0x3935, 0x1921, 0x38f0, 0x1895, 0x38aa, 0x1814, 0x3866, 0x173a, 0x3821, 0x1665, 0x37be, 0x15a4, 0x373c, 0x14f9, 0x36be, 0x1460, 0x3644, 0x13b3,
15550
- 0x3bfd, 0x156b, 0x3bfd, 0x156c, 0x3bfd, 0x1578, 0x3bfd, 0x1598, 0x3bfc, 0x15dd, 0x3bfa, 0x163c, 0x3bf7, 0x16cb, 0x3bf3, 0x177b, 0x3beb, 0x1833, 0x3be0, 0x18ad, 0x3bd2, 0x192e, 0x3bbd, 0x19a6, 0x3ba4, 0x1a0c, 0x3b83, 0x1a5a, 0x3b5d, 0x1a8c, 0x3b30, 0x1a9b, 0x3afd, 0x1a86, 0x3ac6, 0x1a5c, 0x3a89, 0x1a11, 0x3a49, 0x19b7, 0x3a06, 0x194f, 0x39c1, 0x18e3, 0x397a, 0x1873, 0x3933, 0x1805, 0x38eb, 0x173a, 0x38a3, 0x1676, 0x385c, 0x15bf, 0x3816, 0x1519, 0x37a2, 0x1482, 0x371d, 0x13f7, 0x369c, 0x1306, 0x3620, 0x1231,
15551
- 0x3bff, 0x11cb, 0x3bff, 0x11cd, 0x3bfe, 0x11dd, 0x3bfe, 0x1219, 0x3bfd, 0x126b, 0x3bfb, 0x12e9, 0x3bf9, 0x13c5, 0x3bf5, 0x1460, 0x3bee, 0x150f, 0x3be3, 0x15c9, 0x3bd6, 0x168a, 0x3bc3, 0x174f, 0x3baa, 0x1806, 0x3b8b, 0x184f, 0x3b66, 0x1888, 0x3b39, 0x18a6, 0x3b07, 0x18ad, 0x3acf, 0x189c, 0x3a92, 0x1876, 0x3a50, 0x1840, 0x3a0c, 0x17fd, 0x39c4, 0x176a, 0x397b, 0x16ce, 0x3931, 0x1634, 0x38e6, 0x1599, 0x389c, 0x1508, 0x3852, 0x147f, 0x380a, 0x1401, 0x3788, 0x131c, 0x36ff, 0x124a, 0x367c, 0x1190, 0x35fe, 0x10ea,
15552
- 0x3bff, 0x0daa, 0x3bff, 0x0dad, 0x3bff, 0x0dc0, 0x3bff, 0x0e0e, 0x3bfe, 0x0e87, 0x3bfc, 0x0f14, 0x3bfb, 0x1029, 0x3bf7, 0x10d1, 0x3bf0, 0x11d3, 0x3be6, 0x12c9, 0x3bd9, 0x13fc, 0x3bc7, 0x1499, 0x3bb0, 0x152a, 0x3b92, 0x15ab, 0x3b6e, 0x1615, 0x3b42, 0x165a, 0x3b10, 0x1681, 0x3ad8, 0x1683, 0x3a9a, 0x1665, 0x3a57, 0x1629, 0x3a11, 0x15dd, 0x39c8, 0x1580, 0x397c, 0x1518, 0x3930, 0x14ae, 0x38e3, 0x1441, 0x3896, 0x13b1, 0x384a, 0x12e9, 0x37ff, 0x122f, 0x376f, 0x1182, 0x36e3, 0x10e5, 0x365e, 0x1057, 0x35de, 0x0fac,
15553
- 0x3c00, 0x08ea, 0x3c00, 0x08ed, 0x3c00, 0x0902, 0x3c00, 0x0961, 0x3bff, 0x09f3, 0x3bfd, 0x0abc, 0x3bfb, 0x0c1f, 0x3bf8, 0x0d15, 0x3bf1, 0x0e5b, 0x3be8, 0x0fb4, 0x3bdc, 0x10b0, 0x3bcb, 0x1190, 0x3bb5, 0x126c, 0x3b97, 0x132c, 0x3b74, 0x13de, 0x3b4a, 0x1432, 0x3b18, 0x145e, 0x3ae0, 0x1472, 0x3aa2, 0x146f, 0x3a5f, 0x1456, 0x3a17, 0x142e, 0x39cc, 0x13ee, 0x397e, 0x136b, 0x392f, 0x12e1, 0x38df, 0x124f, 0x3890, 0x11bd, 0x3842, 0x1131, 0x37eb, 0x10ac, 0x3757, 0x102e, 0x36c9, 0x0f76, 0x3640, 0x0ea3, 0x35bf, 0x0de4,
15554
- 0x3c00, 0x039b, 0x3c00, 0x039d, 0x3c00, 0x03b2, 0x3c00, 0x041c, 0x3bff, 0x04be, 0x3bfd, 0x05d6, 0x3bfc, 0x0764, 0x3bf8, 0x08e2, 0x3bf2, 0x0a67, 0x3bea, 0x0c1b, 0x3bde, 0x0d41, 0x3bcd, 0x0e5f, 0x3bb8, 0x0f8c, 0x3b9c, 0x1057, 0x3b7a, 0x10e5, 0x3b51, 0x1155, 0x3b20, 0x11a5, 0x3ae8, 0x11da, 0x3aaa, 0x11ef, 0x3a66, 0x11e5, 0x3a1d, 0x11c1, 0x39d0, 0x1185, 0x3980, 0x113b, 0x392e, 0x10e5, 0x38dc, 0x1087, 0x388b, 0x1028, 0x383b, 0x0f94, 0x37d9, 0x0edb, 0x3741, 0x0e2c, 0x36af, 0x0d89, 0x3625, 0x0cf2, 0x35a1, 0x0c69,
15555
- 0x3c00, 0x0107, 0x3c00, 0x0108, 0x3c00, 0x0110, 0x3c00, 0x0145, 0x3bff, 0x0197, 0x3bfe, 0x0224, 0x3bfc, 0x030c, 0x3bf8, 0x0478, 0x3bf3, 0x062c, 0x3beb, 0x0833, 0x3be0, 0x0979, 0x3bd0, 0x0aeb, 0x3bbc, 0x0c3d, 0x3ba0, 0x0d01, 0x3b80, 0x0dbd, 0x3b57, 0x0e69, 0x3b27, 0x0eeb, 0x3af0, 0x0f53, 0x3ab1, 0x0f8a, 0x3a6c, 0x0f9f, 0x3a22, 0x0f8b, 0x39d4, 0x0f5b, 0x3982, 0x0f0f, 0x392f, 0x0eac, 0x38da, 0x0e3d, 0x3886, 0x0dc9, 0x3834, 0x0d51, 0x37c7, 0x0cd9, 0x372c, 0x0c65, 0x3697, 0x0bef, 0x360a, 0x0b20, 0x3585, 0x0a62,
15556
- 0x3c00, 0x0031, 0x3c00, 0x0031, 0x3c00, 0x0034, 0x3c00, 0x004b, 0x3bff, 0x006f, 0x3bfe, 0x00c9, 0x3bfc, 0x011b, 0x3bf9, 0x0207, 0x3bf4, 0x02d6, 0x3bec, 0x0415, 0x3be1, 0x0587, 0x3bd2, 0x0703, 0x3bbf, 0x087d, 0x3ba5, 0x096a, 0x3b85, 0x0a59, 0x3b5d, 0x0b32, 0x3b2e, 0x0bee, 0x3af7, 0x0c44, 0x3ab8, 0x0c7c, 0x3a73, 0x0c9c, 0x3a28, 0x0ca4, 0x39d8, 0x0c98, 0x3985, 0x0c77, 0x392f, 0x0c4a, 0x38d9, 0x0c10, 0x3882, 0x0ba0, 0x382e, 0x0b14, 0x37b6, 0x0a84, 0x3717, 0x09f5, 0x3680, 0x0969, 0x35f0, 0x08e6, 0x356a, 0x086a,
15557
- 0x3c00, 0x0004, 0x3c00, 0x0004, 0x3c00, 0x0004, 0x3c00, 0x000d, 0x3bff, 0x0021, 0x3bfe, 0x003b, 0x3bfd, 0x0070, 0x3bf9, 0x00c7, 0x3bf4, 0x012e, 0x3bed, 0x01c8, 0x3be3, 0x0274, 0x3bd4, 0x033b, 0x3bc1, 0x043a, 0x3ba8, 0x0534, 0x3b89, 0x0641, 0x3b62, 0x073b, 0x3b34, 0x0815, 0x3afd, 0x087c, 0x3abf, 0x08d0, 0x3a7a, 0x090a, 0x3a2e, 0x092c, 0x39dd, 0x0936, 0x3988, 0x0928, 0x3930, 0x0907, 0x38d7, 0x08d7, 0x387f, 0x089b, 0x3828, 0x0855, 0x37a7, 0x080b, 0x3704, 0x077b, 0x366a, 0x06e1, 0x35d8, 0x0649, 0x3550, 0x05b8,
15558
- 0x3c00, 0x0000, 0x3c00, 0x0000, 0x3c00, 0x0000, 0x3c00, 0x0003, 0x3bff, 0x0012, 0x3bfe, 0x001a, 0x3bfd, 0x0035, 0x3bfa, 0x0050, 0x3bf4, 0x0061, 0x3bed, 0x00a5, 0x3be4, 0x00ee, 0x3bd6, 0x0146, 0x3bc3, 0x01ab, 0x3bab, 0x0211, 0x3b8d, 0x028e, 0x3b67, 0x0303, 0x3b39, 0x0375, 0x3b04, 0x03e2, 0x3ac6, 0x0441, 0x3a80, 0x0492, 0x3a34, 0x04cd, 0x39e1, 0x04f2, 0x398b, 0x0504, 0x3931, 0x0502, 0x38d6, 0x04ec, 0x387c, 0x04c7, 0x3822, 0x0496, 0x3798, 0x045c, 0x36f2, 0x041a, 0x3655, 0x03d5, 0x35c1, 0x038e, 0x3537, 0x0347
16384
+ 0x30b5, 0x3ad1, 0x314c, 0x3a4d, 0x33d2, 0x391c, 0x35ef, 0x3828, 0x37f3, 0x36a6, 0x38d1, 0x3539, 0x3979, 0x3410, 0x39f8, 0x3252, 0x3a53, 0x30f0, 0x3a94, 0x2fc9, 0x3abf, 0x2e35, 0x3ada, 0x2d05, 0x3ae8, 0x2c1f, 0x3aed, 0x2ae0, 0x3aea, 0x29d1, 0x3ae1, 0x28ff,
16385
+ 0x3638, 0x38e4, 0x364a, 0x38ce, 0x3699, 0x385e, 0x374e, 0x372c, 0x3839, 0x35a4, 0x38dc, 0x3462, 0x396e, 0x32c4, 0x39de, 0x3134, 0x3a2b, 0x3003, 0x3a59, 0x2e3a, 0x3a6d, 0x2ce1, 0x3a6e, 0x2bba, 0x3a5f, 0x2a33, 0x3a49, 0x290a, 0x3a2d, 0x2826, 0x3a0a, 0x26e8,
16386
+ 0x3894, 0x36d7, 0x3897, 0x36c9, 0x38a3, 0x3675, 0x38bc, 0x35ac, 0x38ee, 0x349c, 0x393e, 0x3332, 0x3997, 0x3186, 0x39e2, 0x3038, 0x3a13, 0x2e75, 0x3a29, 0x2cf5, 0x3a2d, 0x2bac, 0x3a21, 0x29ff, 0x3a04, 0x28bc, 0x39dc, 0x2790, 0x39ad, 0x261a, 0x3978, 0x24fa,
16387
+ 0x39ac, 0x34a8, 0x39ac, 0x34a3, 0x39ae, 0x3480, 0x39ae, 0x3423, 0x39b1, 0x330e, 0x39c2, 0x31a9, 0x39e0, 0x3063, 0x39fc, 0x2eb5, 0x3a0c, 0x2d1d, 0x3a14, 0x2bcf, 0x3a07, 0x29ff, 0x39e9, 0x28a3, 0x39be, 0x273c, 0x3989, 0x25b3, 0x394a, 0x2488, 0x3907, 0x2345,
16388
+ 0x3a77, 0x3223, 0x3a76, 0x321f, 0x3a73, 0x3204, 0x3a6a, 0x31b3, 0x3a58, 0x3114, 0x3a45, 0x303b, 0x3a34, 0x2eb6, 0x3a26, 0x2d31, 0x3a1e, 0x2bef, 0x3a0b, 0x2a0d, 0x39ec, 0x28a1, 0x39c0, 0x271b, 0x3987, 0x2580, 0x3944, 0x2449, 0x38fa, 0x22bd, 0x38ac, 0x2155,
16389
+ 0x3b07, 0x2fca, 0x3b06, 0x2fca, 0x3b00, 0x2fb8, 0x3af4, 0x2f7c, 0x3adb, 0x2eea, 0x3ab4, 0x2e00, 0x3a85, 0x2cec, 0x3a5e, 0x2bc5, 0x3a36, 0x2a00, 0x3a0d, 0x2899, 0x39dc, 0x2707, 0x39a0, 0x2562, 0x395a, 0x2424, 0x390b, 0x2268, 0x38b7, 0x20fd, 0x385f, 0x1fd1,
16390
+ 0x3b69, 0x2cb9, 0x3b68, 0x2cbb, 0x3b62, 0x2cbb, 0x3b56, 0x2cae, 0x3b3b, 0x2c78, 0x3b0d, 0x2c0a, 0x3acf, 0x2ae3, 0x3a92, 0x2998, 0x3a54, 0x2867, 0x3a17, 0x26d0, 0x39d3, 0x253c, 0x3989, 0x2402, 0x3935, 0x2226, 0x38dc, 0x20bd, 0x387d, 0x1f54, 0x381d, 0x1db3,
16391
+ 0x3ba9, 0x296b, 0x3ba8, 0x296f, 0x3ba3, 0x297b, 0x3b98, 0x2987, 0x3b7f, 0x2976, 0x3b4e, 0x2927, 0x3b0e, 0x2895, 0x3ac2, 0x27b7, 0x3a73, 0x263b, 0x3a23, 0x24e7, 0x39d0, 0x239b, 0x3976, 0x21d9, 0x3917, 0x207e, 0x38b2, 0x1ee7, 0x384b, 0x1d53, 0x37c7, 0x1c1e,
16392
+ 0x3bd2, 0x25cb, 0x3bd1, 0x25d3, 0x3bcd, 0x25f0, 0x3bc2, 0x261f, 0x3bad, 0x2645, 0x3b7d, 0x262d, 0x3b3e, 0x25c4, 0x3aec, 0x250f, 0x3a93, 0x243a, 0x3a32, 0x22ce, 0x39d0, 0x215b, 0x3969, 0x202a, 0x38fe, 0x1e6e, 0x388f, 0x1cf1, 0x381f, 0x1b9b, 0x3762, 0x19dd,
16393
+ 0x3be9, 0x21ab, 0x3be9, 0x21b7, 0x3be5, 0x21e5, 0x3bdd, 0x2241, 0x3bc9, 0x22a7, 0x3ba0, 0x22ec, 0x3b62, 0x22cd, 0x3b0f, 0x2247, 0x3aae, 0x2175, 0x3a44, 0x2088, 0x39d4, 0x1f49, 0x3960, 0x1dbe, 0x38e9, 0x1c77, 0x3870, 0x1ae8, 0x37f1, 0x1953, 0x3708, 0x181b,
16394
+ 0x3bf6, 0x1cea, 0x3bf6, 0x1cfb, 0x3bf3, 0x1d38, 0x3bec, 0x1dbd, 0x3bda, 0x1e7c, 0x3bb7, 0x1f25, 0x3b7d, 0x1f79, 0x3b2c, 0x1f4c, 0x3ac6, 0x1ea6, 0x3a55, 0x1dbb, 0x39da, 0x1cbd, 0x395a, 0x1b9d, 0x38d8, 0x1a00, 0x3855, 0x18ac, 0x37ab, 0x173c, 0x36b7, 0x1598,
16395
+ 0x3bfc, 0x1736, 0x3bfc, 0x1759, 0x3bf9, 0x17e7, 0x3bf4, 0x1896, 0x3be4, 0x1997, 0x3bc6, 0x1aa8, 0x3b91, 0x1b84, 0x3b43, 0x1bd2, 0x3ade, 0x1b8a, 0x3a65, 0x1acd, 0x39e2, 0x19d3, 0x3957, 0x18cd, 0x38ca, 0x17b3, 0x383e, 0x1613, 0x376d, 0x14bf, 0x366f, 0x135e,
16396
+ 0x3bff, 0x101b, 0x3bff, 0x1039, 0x3bfc, 0x10c8, 0x3bf9, 0x1226, 0x3bea, 0x1428, 0x3bcf, 0x1584, 0x3b9f, 0x16c5, 0x3b54, 0x179a, 0x3af0, 0x17ce, 0x3a76, 0x1771, 0x39ea, 0x16a4, 0x3956, 0x15a7, 0x38bf, 0x14a7, 0x3829, 0x1379, 0x3735, 0x11ea, 0x362d, 0x10a1,
16397
+ 0x3c00, 0x061b, 0x3c00, 0x066a, 0x3bfe, 0x081c, 0x3bfa, 0x0a4c, 0x3bed, 0x0d16, 0x3bd5, 0x0fb3, 0x3ba9, 0x114d, 0x3b63, 0x127c, 0x3b01, 0x132f, 0x3a85, 0x1344, 0x39f4, 0x12d2, 0x3957, 0x120d, 0x38b5, 0x1122, 0x3817, 0x103c, 0x3703, 0x0ed3, 0x35f0, 0x0d6d,
16398
+ 0x3c00, 0x007a, 0x3c00, 0x0089, 0x3bfe, 0x011d, 0x3bfb, 0x027c, 0x3bf0, 0x04fa, 0x3bda, 0x0881, 0x3bb1, 0x0acd, 0x3b6f, 0x0c97, 0x3b10, 0x0d7b, 0x3a93, 0x0df1, 0x39fe, 0x0def, 0x3959, 0x0d8a, 0x38af, 0x0ce9, 0x3808, 0x0c31, 0x36d5, 0x0af0, 0x35b9, 0x09a3,
16399
+ 0x3c00, 0x0000, 0x3c00, 0x0001, 0x3bff, 0x0015, 0x3bfb, 0x0059, 0x3bf2, 0x00fd, 0x3bdd, 0x01df, 0x3bb7, 0x031c, 0x3b79, 0x047c, 0x3b1d, 0x05d4, 0x3aa0, 0x06d5, 0x3a08, 0x075a, 0x395d, 0x075e, 0x38aa, 0x06f7, 0x37f4, 0x0648, 0x36ac, 0x0576, 0x3586, 0x049f
15559
16400
  ] );
15560
16401
 
15561
16402
  let lut = null;
@@ -15564,7 +16405,8 @@ function getDFGLUT() {
15564
16405
 
15565
16406
  if ( lut === null ) {
15566
16407
 
15567
- lut = new DataTexture( DATA, 32, 32, RGFormat, HalfFloatType );
16408
+ lut = new DataTexture( DATA, 16, 16, RGFormat, HalfFloatType );
16409
+ lut.name = 'DFG_LUT';
15568
16410
  lut.minFilter = LinearFilter;
15569
16411
  lut.magFilter = LinearFilter;
15570
16412
  lut.wrapS = ClampToEdgeWrapping;
@@ -15604,6 +16446,7 @@ class WebGLRenderer {
15604
16446
  powerPreference = 'default',
15605
16447
  failIfMajorPerformanceCaveat = false,
15606
16448
  reversedDepthBuffer = false,
16449
+ outputBufferType = UnsignedByteType,
15607
16450
  multiviewStereo = false,
15608
16451
  } = parameters;
15609
16452
 
@@ -15634,6 +16477,8 @@ class WebGLRenderer {
15634
16477
 
15635
16478
  }
15636
16479
 
16480
+ const _outputBufferType = outputBufferType;
16481
+
15637
16482
  const INTEGER_FORMATS = new Set( [
15638
16483
  RGBAIntegerFormat,
15639
16484
  RGIntegerFormat,
@@ -15651,6 +16496,7 @@ class WebGLRenderer {
15651
16496
 
15652
16497
  const uintClearColor = new Uint32Array( 4 );
15653
16498
  const intClearColor = new Int32Array( 4 );
16499
+ const objectPosition = new Vector3();
15654
16500
 
15655
16501
  let currentRenderList = null;
15656
16502
  let currentRenderState = null;
@@ -15661,10 +16507,14 @@ class WebGLRenderer {
15661
16507
  const renderListStack = [];
15662
16508
  const renderStateStack = [];
15663
16509
 
16510
+ // internal render target for non-UnsignedByteType color buffer
16511
+
16512
+ let output = null;
16513
+
15664
16514
  // public properties
15665
16515
 
15666
16516
  /**
15667
- * A canvas where the renderer draws its output.This is automatically created by the renderer
16517
+ * A canvas where the renderer draws its output. This is automatically created by the renderer
15668
16518
  * in the constructor (if not provided already); you just need to add it to your page like so:
15669
16519
  * ```js
15670
16520
  * document.body.appendChild( renderer.domElement );
@@ -15680,7 +16530,7 @@ class WebGLRenderer {
15680
16530
  * - `checkShaderErrors`: If it is `true`, defines whether material shader programs are
15681
16531
  * checked for errors during compilation and linkage process. It may be useful to disable
15682
16532
  * this check in production for performance gain. It is strongly recommended to keep these
15683
- * checks enabled during development. If the shader does not compile and link - it will not
16533
+ * checks enabled during development. If the shader does not compile and link, it will not
15684
16534
  * work and associated material will not render.
15685
16535
  * - `onShaderError(gl, program, glVertexShader,glFragmentShader)`: A callback function that
15686
16536
  * can be used for custom error reporting. The callback receives the WebGL context, an instance
@@ -15809,6 +16659,7 @@ class WebGLRenderer {
15809
16659
  const _this = this;
15810
16660
 
15811
16661
  let _isContextLost = false;
16662
+ let _nodesHandler = null;
15812
16663
 
15813
16664
  // internal state cache
15814
16665
 
@@ -15921,15 +16772,15 @@ class WebGLRenderer {
15921
16772
 
15922
16773
  }
15923
16774
 
15924
- } catch ( error ) {
16775
+ } catch ( e ) {
15925
16776
 
15926
- error( 'WebGLRenderer: ' + error.message );
15927
- throw error;
16777
+ error( 'WebGLRenderer: ' + e.message );
16778
+ throw e;
15928
16779
 
15929
16780
  }
15930
16781
 
15931
16782
  let extensions, capabilities, state, info;
15932
- let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects;
16783
+ let properties, textures, environments, attributes, geometries, objects;
15933
16784
  let programCache, materials, renderLists, renderStates, clipping, shadowMap;
15934
16785
  let multiview;
15935
16786
 
@@ -15957,19 +16808,18 @@ class WebGLRenderer {
15957
16808
  info = new WebGLInfo( _gl );
15958
16809
  properties = new WebGLProperties();
15959
16810
  textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
15960
- cubemaps = new WebGLCubeMaps( _this );
15961
- cubeuvmaps = new WebGLCubeUVMaps( _this );
16811
+ environments = new WebGLEnvironments( _this );
15962
16812
  attributes = new WebGLAttributes( _gl );
15963
16813
  bindingStates = new WebGLBindingStates( _gl, attributes );
15964
16814
  geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
15965
- objects = new WebGLObjects( _gl, geometries, attributes, info );
16815
+ objects = new WebGLObjects( _gl, geometries, attributes, bindingStates, info );
15966
16816
  morphtargets = new WebGLMorphtargets( _gl, capabilities, textures );
15967
16817
  clipping = new WebGLClipping( properties );
15968
- programCache = new WebGLPrograms( _this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping );
16818
+ programCache = new WebGLPrograms( _this, environments, extensions, capabilities, bindingStates, clipping );
15969
16819
  materials = new WebGLMaterials( _this, properties );
15970
16820
  renderLists = new WebGLRenderLists();
15971
16821
  renderStates = new WebGLRenderStates( extensions );
15972
- background = new WebGLBackground( _this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha );
16822
+ background = new WebGLBackground( _this, environments, state, objects, _alpha, premultipliedAlpha );
15973
16823
  multiview = new WebGLMultiview( _this, extensions, _gl );
15974
16824
  shadowMap = new WebGLShadowMap( _this, objects, capabilities );
15975
16825
  uniformsGroups = new WebGLUniformsGroups( _gl, info, capabilities, state );
@@ -16058,6 +16908,14 @@ class WebGLRenderer {
16058
16908
 
16059
16909
  initGLContext();
16060
16910
 
16911
+ // initialize internal render target for non-UnsignedByteType color buffer
16912
+
16913
+ if ( _outputBufferType !== UnsignedByteType ) {
16914
+
16915
+ output = new WebGLOutput( _outputBufferType, canvas.width, canvas.height, depth, stencil );
16916
+
16917
+ }
16918
+
16061
16919
  // xr
16062
16920
 
16063
16921
  const xr = new WebXRManager( _this, _gl, extensions, multiviewStereo );
@@ -16180,6 +17038,12 @@ class WebGLRenderer {
16180
17038
 
16181
17039
  }
16182
17040
 
17041
+ if ( output !== null ) {
17042
+
17043
+ output.setSize( canvas.width, canvas.height );
17044
+
17045
+ }
17046
+
16183
17047
  this.setViewport( 0, 0, width, height );
16184
17048
 
16185
17049
  };
@@ -16223,6 +17087,39 @@ class WebGLRenderer {
16223
17087
 
16224
17088
  };
16225
17089
 
17090
+ /**
17091
+ * Sets the post-processing effects to be applied after rendering.
17092
+ *
17093
+ * @param {Array} effects - An array of post-processing effects.
17094
+ */
17095
+ this.setEffects = function ( effects ) {
17096
+
17097
+ if ( _outputBufferType === UnsignedByteType ) {
17098
+
17099
+ error( 'THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.' );
17100
+ return;
17101
+
17102
+ }
17103
+
17104
+ if ( effects ) {
17105
+
17106
+ for ( let i = 0; i < effects.length; i ++ ) {
17107
+
17108
+ if ( effects[ i ].isOutputPass === true ) {
17109
+
17110
+ warn( 'THREE.WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.' );
17111
+ break;
17112
+
17113
+ }
17114
+
17115
+ }
17116
+
17117
+ }
17118
+
17119
+ output.setEffects( effects || [] );
17120
+
17121
+ };
17122
+
16226
17123
  /**
16227
17124
  * Returns the current viewport definition.
16228
17125
  *
@@ -16470,6 +17367,7 @@ class WebGLRenderer {
16470
17367
  if ( depth ) {
16471
17368
 
16472
17369
  bits |= _gl.DEPTH_BUFFER_BIT;
17370
+ this.state.buffers.depth.setMask( true );
16473
17371
 
16474
17372
  }
16475
17373
 
@@ -16480,7 +17378,11 @@ class WebGLRenderer {
16480
17378
 
16481
17379
  }
16482
17380
 
16483
- _gl.clear( bits );
17381
+ if ( bits !== 0 ) {
17382
+
17383
+ _gl.clear( bits );
17384
+
17385
+ }
16484
17386
 
16485
17387
  };
16486
17388
 
@@ -16511,6 +17413,20 @@ class WebGLRenderer {
16511
17413
 
16512
17414
  };
16513
17415
 
17416
+ /**
17417
+ * Sets a compatibility node builder for rendering node materials with WebGLRenderer.
17418
+ * This enables using TSL (Three.js Shading Language) node materials to prepare
17419
+ * for migration to WebGPURenderer.
17420
+ *
17421
+ * @param {WebGLNodesHandler} nodesHandler - The node builder instance.
17422
+ */
17423
+ this.setNodesHandler = function ( nodesHandler ) {
17424
+
17425
+ nodesHandler.setRenderer( this );
17426
+ _nodesHandler = nodesHandler;
17427
+
17428
+ };
17429
+
16514
17430
  /**
16515
17431
  * Frees the GPU-related resources allocated by this instance. Call this
16516
17432
  * method whenever this instance is no longer used in your app.
@@ -16525,8 +17441,7 @@ class WebGLRenderer {
16525
17441
  renderLists.dispose();
16526
17442
  renderStates.dispose();
16527
17443
  properties.dispose();
16528
- cubemaps.dispose();
16529
- cubeuvmaps.dispose();
17444
+ environments.dispose();
16530
17445
  objects.dispose();
16531
17446
  bindingStates.dispose();
16532
17447
  uniformsGroups.dispose();
@@ -16747,33 +17662,23 @@ class WebGLRenderer {
16747
17662
 
16748
17663
  if ( object.isBatchedMesh ) {
16749
17664
 
16750
- if ( object._multiDrawInstances !== null ) {
16751
-
16752
- // @deprecated, r174
16753
- warnOnce( 'WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.' );
16754
- renderer.renderMultiDrawInstances( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances );
16755
-
16756
- } else {
16757
-
16758
- if ( ! extensions.get( 'WEBGL_multi_draw' ) ) {
16759
-
16760
- const starts = object._multiDrawStarts;
16761
- const counts = object._multiDrawCounts;
16762
- const drawCount = object._multiDrawCount;
16763
- const bytesPerElement = index ? attributes.get( index ).bytesPerElement : 1;
16764
- const uniforms = properties.get( material ).currentProgram.getUniforms();
16765
- for ( let i = 0; i < drawCount; i ++ ) {
17665
+ if ( ! extensions.get( 'WEBGL_multi_draw' ) ) {
16766
17666
 
16767
- uniforms.setValue( _gl, '_gl_DrawID', i );
16768
- renderer.render( starts[ i ] / bytesPerElement, counts[ i ] );
17667
+ const starts = object._multiDrawStarts;
17668
+ const counts = object._multiDrawCounts;
17669
+ const drawCount = object._multiDrawCount;
17670
+ const bytesPerElement = index ? attributes.get( index ).bytesPerElement : 1;
17671
+ const uniforms = properties.get( material ).currentProgram.getUniforms();
17672
+ for ( let i = 0; i < drawCount; i ++ ) {
16769
17673
 
16770
- }
17674
+ uniforms.setValue( _gl, '_gl_DrawID', i );
17675
+ renderer.render( starts[ i ] / bytesPerElement, counts[ i ] );
16771
17676
 
16772
- } else {
17677
+ }
16773
17678
 
16774
- renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount );
17679
+ } else {
16775
17680
 
16776
- }
17681
+ renderer.renderMultiDraw( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount );
16777
17682
 
16778
17683
  }
16779
17684
 
@@ -17072,6 +17977,19 @@ class WebGLRenderer {
17072
17977
 
17073
17978
  if ( _isContextLost === true ) return;
17074
17979
 
17980
+ // update node builder if available
17981
+ if ( _nodesHandler !== null ) {
17982
+
17983
+ _nodesHandler.renderStart( scene, camera );
17984
+
17985
+ }
17986
+
17987
+ // use internal render target for HalfFloatType color buffer (only when tone mapping is enabled)
17988
+
17989
+ const isXRPresenting = xr.enabled === true && xr.isPresenting === true;
17990
+
17991
+ const useOutput = output !== null && ( _currentRenderTarget === null || isXRPresenting ) && output.begin( _this, _currentRenderTarget );
17992
+
17075
17993
  // update scene graph
17076
17994
 
17077
17995
  if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
@@ -17080,7 +17998,7 @@ class WebGLRenderer {
17080
17998
 
17081
17999
  if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
17082
18000
 
17083
- if ( xr.enabled === true && xr.isPresenting === true ) {
18001
+ if ( xr.enabled === true && xr.isPresenting === true && ( output === null || output.isCompositing() === false ) ) {
17084
18002
 
17085
18003
  if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );
17086
18004
 
@@ -17094,6 +18012,7 @@ class WebGLRenderer {
17094
18012
  currentRenderState = renderStates.get( scene, renderStateStack.length );
17095
18013
  currentRenderState.init( camera );
17096
18014
 
18015
+ currentRenderState.state.textureUnits = textures.getTextureUnits();
17097
18016
  renderStateStack.push( currentRenderState );
17098
18017
 
17099
18018
  _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
@@ -17152,56 +18071,62 @@ class WebGLRenderer {
17152
18071
 
17153
18072
  if ( this.info.autoReset === true ) this.info.reset();
17154
18073
 
17155
- // render scene
18074
+ // render scene (skip if first effect is a render pass - it will render the scene itself)
17156
18075
 
17157
- const opaqueObjects = currentRenderList.opaque;
17158
- const transmissiveObjects = currentRenderList.transmissive;
18076
+ const skipSceneRender = useOutput && output.hasRenderPass();
17159
18077
 
17160
- currentRenderState.setupLights();
18078
+ if ( skipSceneRender === false ) {
17161
18079
 
17162
- if ( camera.isArrayCamera ) {
18080
+ const opaqueObjects = currentRenderList.opaque;
18081
+ const transmissiveObjects = currentRenderList.transmissive;
17163
18082
 
17164
- const cameras = camera.cameras;
18083
+ currentRenderState.setupLights();
17165
18084
 
17166
- if ( transmissiveObjects.length > 0 ) {
18085
+ if ( camera.isArrayCamera ) {
17167
18086
 
17168
- for ( let i = 0, l = cameras.length; i < l; i ++ ) {
18087
+ const cameras = camera.cameras;
17169
18088
 
17170
- const camera2 = cameras[ i ];
18089
+ if ( transmissiveObjects.length > 0 ) {
17171
18090
 
17172
- renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera2 );
18091
+ for ( let i = 0, l = cameras.length; i < l; i ++ ) {
18092
+
18093
+ const camera2 = cameras[ i ];
18094
+
18095
+ renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera2 );
18096
+
18097
+ }
17173
18098
 
17174
18099
  }
17175
18100
 
17176
- }
18101
+ if ( _renderBackground ) background.render( scene );
17177
18102
 
17178
- if ( _renderBackground ) background.render( scene );
18103
+ if ( xr.enabled && xr.isMultiview ) {
17179
18104
 
17180
- if ( xr.enabled && xr.isMultiview ) {
18105
+ textures.setDeferTextureUploads( true );
17181
18106
 
17182
- textures.setDeferTextureUploads( true );
18107
+ renderScene( currentRenderList, scene, camera, camera.cameras[ 0 ].viewport );
17183
18108
 
17184
- renderScene( currentRenderList, scene, camera, camera.cameras[ 0 ].viewport );
18109
+ } else {
17185
18110
 
17186
- } else {
18111
+ for ( let i = 0, l = cameras.length; i < l; i ++ ) {
17187
18112
 
17188
- for ( let i = 0, l = cameras.length; i < l; i ++ ) {
18113
+ const camera2 = cameras[ i ];
17189
18114
 
17190
- const camera2 = cameras[ i ];
18115
+ renderScene( currentRenderList, scene, camera2, camera2.viewport );
17191
18116
 
17192
- renderScene( currentRenderList, scene, camera2, camera2.viewport );
18117
+ }
17193
18118
 
17194
18119
  }
17195
18120
 
17196
- }
18121
+ } else {
17197
18122
 
17198
- } else {
18123
+ if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );
17199
18124
 
17200
- if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );
18125
+ if ( _renderBackground ) background.render( scene );
17201
18126
 
17202
- if ( _renderBackground ) background.render( scene );
18127
+ renderScene( currentRenderList, scene, camera );
17203
18128
 
17204
- renderScene( currentRenderList, scene, camera );
18129
+ }
17205
18130
 
17206
18131
  }
17207
18132
 
@@ -17219,12 +18144,18 @@ class WebGLRenderer {
17219
18144
 
17220
18145
  }
17221
18146
 
18147
+ // copy from internal render target to canvas using fullscreen quad
18148
+
18149
+ if ( useOutput ) {
18150
+
18151
+ output.end( _this );
18152
+
18153
+ }
18154
+
17222
18155
  //
17223
18156
 
17224
18157
  if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
17225
18158
 
17226
- textures.runDeferredUploads();
17227
-
17228
18159
  // _gl.finish();
17229
18160
 
17230
18161
  bindingStates.resetDefaultState();
@@ -17237,6 +18168,8 @@ class WebGLRenderer {
17237
18168
 
17238
18169
  currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
17239
18170
 
18171
+ textures.setTextureUnits( currentRenderState.state.textureUnits );
18172
+
17240
18173
  if ( _clippingEnabled === true ) clipping.setGlobalState( _this.clippingPlanes, currentRenderState.state.camera );
17241
18174
 
17242
18175
  } else {
@@ -17257,6 +18190,12 @@ class WebGLRenderer {
17257
18190
 
17258
18191
  }
17259
18192
 
18193
+ if ( _nodesHandler !== null ) {
18194
+
18195
+ _nodesHandler.renderEnd();
18196
+
18197
+ }
18198
+
17260
18199
  };
17261
18200
 
17262
18201
  function projectObject( object, camera, groupOrder, sortObjects ) {
@@ -17275,6 +18214,10 @@ class WebGLRenderer {
17275
18214
 
17276
18215
  if ( object.autoUpdate === true ) object.update( camera );
17277
18216
 
18217
+ } else if ( object.isLightProbeGrid ) {
18218
+
18219
+ currentRenderState.pushLightProbeGrid( object );
18220
+
17278
18221
  } else if ( object.isLight ) {
17279
18222
 
17280
18223
  currentRenderState.pushLight( object );
@@ -17409,11 +18352,13 @@ class WebGLRenderer {
17409
18352
 
17410
18353
  if ( currentRenderState.state.transmissionRenderTarget[ camera.id ] === undefined ) {
17411
18354
 
18355
+ const hasHalfFloatSupport = extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' );
18356
+
17412
18357
  currentRenderState.state.transmissionRenderTarget[ camera.id ] = new WebGLRenderTarget( 1, 1, {
17413
18358
  generateMipmaps: true,
17414
- type: ( extensions.has( 'EXT_color_buffer_half_float' ) || extensions.has( 'EXT_color_buffer_float' ) ) ? HalfFloatType : UnsignedByteType,
18359
+ type: hasHalfFloatSupport ? HalfFloatType : UnsignedByteType,
17415
18360
  minFilter: LinearMipmapLinearFilter,
17416
- samples: 4,
18361
+ samples: Math.max( 4, capabilities.samples ), // to avoid feedback loops, the transmission render target requires a resolve, see #26177
17417
18362
  stencilBuffer: stencil,
17418
18363
  resolveDepthBuffer: false,
17419
18364
  resolveStencilBuffer: false,
@@ -17588,16 +18533,18 @@ class WebGLRenderer {
17588
18533
 
17589
18534
  const lightsStateVersion = lights.state.version;
17590
18535
 
17591
- const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object );
18536
+ const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object, currentRenderState.state.lightProbeGridArray );
17592
18537
  const programCacheKey = programCache.getProgramCacheKey( parameters );
17593
18538
 
17594
18539
  let programs = materialProperties.programs;
17595
18540
 
17596
18541
  // always update environment and fog - changing these trigger an getProgram call, but it's possible that the program doesn't change
17597
18542
 
17598
- materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
18543
+ materialProperties.environment = ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) ? scene.environment : null;
17599
18544
  materialProperties.fog = scene.fog;
17600
- materialProperties.envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || materialProperties.environment );
18545
+
18546
+ const usePMREM = material.isMeshStandardMaterial || ( material.isMeshLambertMaterial && ! material.envMap ) || ( material.isMeshPhongMaterial && ! material.envMap );
18547
+ materialProperties.envMap = environments.get( material.envMap || materialProperties.environment, usePMREM );
17601
18548
  materialProperties.envMapRotation = ( materialProperties.environment !== null && material.envMap === null ) ? scene.environmentRotation : material.envMapRotation;
17602
18549
 
17603
18550
  if ( programs === undefined ) {
@@ -17629,6 +18576,13 @@ class WebGLRenderer {
17629
18576
 
17630
18577
  parameters.uniforms = programCache.getUniforms( material );
17631
18578
 
18579
+ // Use node builder for node materials if available
18580
+ if ( _nodesHandler !== null && material.isNodeMaterial ) {
18581
+
18582
+ _nodesHandler.build( material, object, parameters );
18583
+
18584
+ }
18585
+
17632
18586
  material.onBeforeCompile( parameters, _this );
17633
18587
 
17634
18588
  program = programCache.acquireProgram( parameters, programCacheKey );
@@ -17670,17 +18624,16 @@ class WebGLRenderer {
17670
18624
  uniforms.pointLightShadows.value = lights.state.pointShadow;
17671
18625
  uniforms.hemisphereLights.value = lights.state.hemi;
17672
18626
 
17673
- uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
17674
18627
  uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
17675
- uniforms.spotShadowMap.value = lights.state.spotShadowMap;
17676
18628
  uniforms.spotLightMatrix.value = lights.state.spotLightMatrix;
17677
18629
  uniforms.spotLightMap.value = lights.state.spotLightMap;
17678
- uniforms.pointShadowMap.value = lights.state.pointShadowMap;
17679
18630
  uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
17680
18631
  // TODO (abelnation): add area lights shadow info to uniforms
17681
18632
 
17682
18633
  }
17683
18634
 
18635
+ materialProperties.lightProbeGrid = currentRenderState.state.lightProbeGridArray.length > 0;
18636
+
17684
18637
  materialProperties.currentProgram = program;
17685
18638
  materialProperties.uniformsList = null;
17686
18639
 
@@ -17725,6 +18678,30 @@ class WebGLRenderer {
17725
18678
 
17726
18679
  }
17727
18680
 
18681
+ function findLightProbeGrid( volumes, object ) {
18682
+
18683
+ if ( volumes.length === 0 ) return null;
18684
+
18685
+ if ( volumes.length === 1 ) {
18686
+
18687
+ return volumes[ 0 ].texture !== null ? volumes[ 0 ] : null;
18688
+
18689
+ }
18690
+
18691
+ objectPosition.setFromMatrixPosition( object.matrixWorld );
18692
+
18693
+ for ( let i = 0, l = volumes.length; i < l; i ++ ) {
18694
+
18695
+ const v = volumes[ i ];
18696
+
18697
+ if ( v.texture !== null && v.boundingBox.containsPoint( objectPosition ) ) return v;
18698
+
18699
+ }
18700
+
18701
+ return null;
18702
+
18703
+ }
18704
+
17728
18705
  function setProgram( camera, scene, geometry, material, object ) {
17729
18706
 
17730
18707
  if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
@@ -17732,9 +18709,10 @@ class WebGLRenderer {
17732
18709
  textures.resetTextureUnits();
17733
18710
 
17734
18711
  const fog = scene.fog;
17735
- const environment = material.isMeshStandardMaterial ? scene.environment : null;
17736
- const colorSpace = ( _currentRenderTarget === null ) ? _this.outputColorSpace : ( _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace );
17737
- const envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || environment );
18712
+ const environment = ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) ? scene.environment : null;
18713
+ const colorSpace = ( _currentRenderTarget === null ) ? _this.outputColorSpace : ( _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : ColorManagement.workingColorSpace );
18714
+ const usePMREM = material.isMeshStandardMaterial || ( material.isMeshLambertMaterial && ! material.envMap ) || ( material.isMeshPhongMaterial && ! material.envMap );
18715
+ const envMap = environments.get( material.envMap || environment, usePMREM );
17738
18716
  const vertexAlphas = material.vertexColors === true && !! geometry.attributes.color && geometry.attributes.color.itemSize === 4;
17739
18717
  const vertexTangents = !! geometry.attributes.tangent && ( !! material.normalMap || material.anisotropy > 0 );
17740
18718
  const morphTargets = !! geometry.morphAttributes.position;
@@ -17882,6 +18860,10 @@ class WebGLRenderer {
17882
18860
 
17883
18861
  needsProgramChange = true;
17884
18862
 
18863
+ } else if ( !! materialProperties.lightProbeGrid !== ( currentRenderState.state.lightProbeGridArray.length > 0 ) ) {
18864
+
18865
+ needsProgramChange = true;
18866
+
17885
18867
  } else if ( materialProperties.numMultiviewViews !== numMultiviewViews ) {
17886
18868
 
17887
18869
  needsProgramChange = true;
@@ -17903,6 +18885,14 @@ class WebGLRenderer {
17903
18885
 
17904
18886
  program = getProgram( material, scene, object );
17905
18887
 
18888
+ // notify the node builder that the program has changed so uniforms and update nodes can
18889
+ // be cached and triggered.
18890
+ if ( _nodesHandler && material.isNodeMaterial ) {
18891
+
18892
+ _nodesHandler.onUpdateProgram( material, program, materialProperties );
18893
+
18894
+ }
18895
+
17906
18896
  }
17907
18897
 
17908
18898
  let refreshProgram = false;
@@ -17928,6 +18918,19 @@ class WebGLRenderer {
17928
18918
 
17929
18919
  }
17930
18920
 
18921
+ if ( materialProperties.needsLights ) {
18922
+
18923
+ const objectVolume = findLightProbeGrid( currentRenderState.state.lightProbeGridArray, object );
18924
+
18925
+ if ( materialProperties.lightProbeGrid !== objectVolume ) {
18926
+
18927
+ materialProperties.lightProbeGrid = objectVolume;
18928
+ refreshMaterial = true;
18929
+
18930
+ }
18931
+
18932
+ }
18933
+
17931
18934
  if ( refreshProgram || _currentCamera !== camera ) {
17932
18935
 
17933
18936
  // common camera uniforms
@@ -17954,6 +18957,7 @@ class WebGLRenderer {
17954
18957
 
17955
18958
  }
17956
18959
 
18960
+
17957
18961
  const uCamPos = p_uniforms.map.cameraPosition;
17958
18962
 
17959
18963
  if ( uCamPos !== undefined ) {
@@ -17997,6 +19001,30 @@ class WebGLRenderer {
17997
19001
 
17998
19002
  }
17999
19003
 
19004
+ // Pre-allocate texture units for shadow samplers before setting data textures
19005
+ if ( materialProperties.needsLights ) {
19006
+
19007
+ // Set shadow map uniforms first to ensure they get the first texture units
19008
+ if ( lights.state.directionalShadowMap.length > 0 ) {
19009
+
19010
+ p_uniforms.setValue( _gl, 'directionalShadowMap', lights.state.directionalShadowMap, textures );
19011
+
19012
+ }
19013
+
19014
+ if ( lights.state.spotShadowMap.length > 0 ) {
19015
+
19016
+ p_uniforms.setValue( _gl, 'spotShadowMap', lights.state.spotShadowMap, textures );
19017
+
19018
+ }
19019
+
19020
+ if ( lights.state.pointShadowMap.length > 0 ) {
19021
+
19022
+ p_uniforms.setValue( _gl, 'pointShadowMap', lights.state.pointShadowMap, textures );
19023
+
19024
+ }
19025
+
19026
+ }
19027
+
18000
19028
  // skinning and morph target uniforms must be set even if material didn't change
18001
19029
  // auto-setting of texture unit for bone and morph texture must go before other textures
18002
19030
  // otherwise textures used for skinning and morphing can take over texture units reserved for other material textures
@@ -18050,17 +19078,7 @@ class WebGLRenderer {
18050
19078
 
18051
19079
  }
18052
19080
 
18053
- // https://github.com/mrdoob/three.js/pull/24467#issuecomment-1209031512
18054
-
18055
- if ( material.isMeshGouraudMaterial && material.envMap !== null ) {
18056
-
18057
- m_uniforms.envMap.value = envMap;
18058
-
18059
- m_uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap.isRenderTargetTexture === false ) ? -1 : 1;
18060
-
18061
- }
18062
-
18063
- if ( material.isMeshStandardMaterial && material.envMap === null && scene.environment !== null ) {
19081
+ if ( ( material.isMeshStandardMaterial || material.isMeshLambertMaterial || material.isMeshPhongMaterial ) && material.envMap === null && scene.environment !== null ) {
18064
19082
 
18065
19083
  m_uniforms.envMapIntensity.value = scene.environmentIntensity;
18066
19084
 
@@ -18102,6 +19120,19 @@ class WebGLRenderer {
18102
19120
 
18103
19121
  materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, currentRenderState.state.transmissionRenderTarget[ camera.id ] );
18104
19122
 
19123
+ // light probe volume
19124
+
19125
+ if ( materialProperties.needsLights && materialProperties.lightProbeGrid ) {
19126
+
19127
+ const volume = materialProperties.lightProbeGrid;
19128
+
19129
+ m_uniforms.probesSH.value = volume.texture;
19130
+ m_uniforms.probesMin.value.copy( volume.boundingBox.min );
19131
+ m_uniforms.probesMax.value.copy( volume.boundingBox.max );
19132
+ m_uniforms.probesResolution.value.copy( volume.resolution );
19133
+
19134
+ }
19135
+
18105
19136
  WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );
18106
19137
 
18107
19138
  }
@@ -18136,7 +19167,7 @@ class WebGLRenderer {
18136
19167
 
18137
19168
  // UBOs
18138
19169
 
18139
- if ( material.isShaderMaterial || material.isRawShaderMaterial ) {
19170
+ if ( material.uniformsGroups !== undefined ) {
18140
19171
 
18141
19172
  const groups = material.uniformsGroups;
18142
19173
 
@@ -18246,7 +19277,7 @@ class WebGLRenderer {
18246
19277
  const renderTargetProperties = properties.get( renderTarget );
18247
19278
 
18248
19279
  renderTargetProperties.__autoAllocateDepthBuffer = renderTarget.resolveDepthBuffer === false;
18249
- if ( ! renderTargetProperties.__autoAllocateDepthBuffer ) {
19280
+ if ( renderTargetProperties.__autoAllocateDepthBuffer === false && ( ! _currentRenderTarget || ! _currentRenderTarget.isWebGLMultiviewRenderTarget ) ) {
18250
19281
 
18251
19282
  // The multisample_render_to_texture extension doesn't work properly if there
18252
19283
  // are midframe flushes and an external depth buffer. Disable use of the extension.
@@ -18293,7 +19324,6 @@ class WebGLRenderer {
18293
19324
  _currentActiveCubeFace = activeCubeFace;
18294
19325
  _currentActiveMipmapLevel = activeMipmapLevel;
18295
19326
 
18296
- let useDefaultFramebuffer = true;
18297
19327
  let framebuffer = null;
18298
19328
  let isCube = false;
18299
19329
  let isRenderTarget3D = false;
@@ -18304,9 +19334,21 @@ class WebGLRenderer {
18304
19334
 
18305
19335
  if ( renderTargetProperties.__useDefaultFramebuffer !== undefined ) {
18306
19336
 
18307
- // We need to make sure to rebind the framebuffer.
18308
- state.bindFramebuffer( _gl.FRAMEBUFFER, null );
18309
- useDefaultFramebuffer = false;
19337
+ // Externally-managed framebuffer (e.g. XR)
19338
+ // Bind to the stored framebuffer (may be null for default, or a WebGLFramebuffer)
19339
+ state.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
19340
+
19341
+ _currentViewport.copy( renderTarget.viewport );
19342
+ _currentScissor.copy( renderTarget.scissor );
19343
+ _currentScissorTest = renderTarget.scissorTest;
19344
+
19345
+ state.viewport( _currentViewport );
19346
+ state.scissor( _currentScissor );
19347
+ state.setScissorTest( _currentScissorTest );
19348
+
19349
+ _currentMaterialId = -1;
19350
+
19351
+ return;
18310
19352
 
18311
19353
  } else if ( renderTargetProperties.__webglFramebuffer === undefined ) {
18312
19354
 
@@ -18405,7 +19447,7 @@ class WebGLRenderer {
18405
19447
 
18406
19448
  const framebufferBound = state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
18407
19449
 
18408
- if ( framebufferBound && useDefaultFramebuffer ) {
19450
+ if ( framebufferBound ) {
18409
19451
 
18410
19452
  state.drawBuffers( renderTarget, framebuffer );
18411
19453
 
@@ -18484,6 +19526,10 @@ class WebGLRenderer {
18484
19526
  const textureFormat = texture.format;
18485
19527
  const textureType = texture.type;
18486
19528
 
19529
+ // when using MRT, select the correct color buffer for the subsequent read command
19530
+
19531
+ if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
19532
+
18487
19533
  if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
18488
19534
 
18489
19535
  error( 'WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
@@ -18502,10 +19548,6 @@ class WebGLRenderer {
18502
19548
 
18503
19549
  if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
18504
19550
 
18505
- // when using MRT, select the correct color buffer for the subsequent read command
18506
-
18507
- if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
18508
-
18509
19551
  _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
18510
19552
 
18511
19553
  }
@@ -18566,6 +19608,11 @@ class WebGLRenderer {
18566
19608
  const textureFormat = texture.format;
18567
19609
  const textureType = texture.type;
18568
19610
 
19611
+ // when using MRT, select the correct color buffer for the subsequent read command
19612
+
19613
+ if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
19614
+
19615
+
18569
19616
  if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
18570
19617
 
18571
19618
  throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
@@ -18582,10 +19629,6 @@ class WebGLRenderer {
18582
19629
  _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
18583
19630
  _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
18584
19631
 
18585
- // when using MRT, select the correct color buffer for the subsequent read command
18586
-
18587
- if ( renderTarget.textures.length > 1 ) _gl.readBuffer( _gl.COLOR_ATTACHMENT0 + textureIndex );
18588
-
18589
19632
  _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
18590
19633
 
18591
19634
  // reset the frame buffer to the currently set buffer before waiting
@@ -18655,27 +19698,9 @@ class WebGLRenderer {
18655
19698
  * @param {?(Box2|Box3)} [srcRegion=null] - A bounding box which describes the source region. Can be two or three-dimensional.
18656
19699
  * @param {?(Vector2|Vector3)} [dstPosition=null] - A vector that represents the origin of the destination region. Can be two or three-dimensional.
18657
19700
  * @param {number} [srcLevel=0] - The source mipmap level to copy.
18658
- * @param {?number} [dstLevel=null] - The destination mipmap level.
19701
+ * @param {?number} [dstLevel=0] - The destination mipmap level.
18659
19702
  */
18660
- this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = null ) {
18661
-
18662
- // support the previous signature with just a single dst mipmap level
18663
- if ( dstLevel === null ) {
18664
-
18665
- if ( srcLevel !== 0 ) {
18666
-
18667
- // @deprecated, r171
18668
- warnOnce( 'WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels.' );
18669
- dstLevel = srcLevel;
18670
- srcLevel = 0;
18671
-
18672
- } else {
18673
-
18674
- dstLevel = 0;
18675
-
18676
- }
18677
-
18678
- }
19703
+ this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0 ) {
18679
19704
 
18680
19705
  // gather the necessary dimensions to copy
18681
19706
  let width, height, depth, minX, minY, minZ;
@@ -18751,22 +19776,24 @@ class WebGLRenderer {
18751
19776
 
18752
19777
  }
18753
19778
 
18754
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
18755
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
18756
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
19779
+ state.activeTexture( _gl.TEXTURE0 ); // see #33153
19780
+
19781
+ state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
19782
+ state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
19783
+ state.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
18757
19784
 
18758
19785
  // used for copying data from cpu
18759
- const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
18760
- const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
18761
- const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
18762
- const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
18763
- const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
18764
-
18765
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
18766
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
18767
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
18768
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
18769
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
19786
+ const currentUnpackRowLen = state.getParameter( _gl.UNPACK_ROW_LENGTH );
19787
+ const currentUnpackImageHeight = state.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
19788
+ const currentUnpackSkipPixels = state.getParameter( _gl.UNPACK_SKIP_PIXELS );
19789
+ const currentUnpackSkipRows = state.getParameter( _gl.UNPACK_SKIP_ROWS );
19790
+ const currentUnpackSkipImages = state.getParameter( _gl.UNPACK_SKIP_IMAGES );
19791
+
19792
+ state.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
19793
+ state.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
19794
+ state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
19795
+ state.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
19796
+ state.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
18770
19797
 
18771
19798
  // set up the src texture
18772
19799
  const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture;
@@ -18892,11 +19919,11 @@ class WebGLRenderer {
18892
19919
  }
18893
19920
 
18894
19921
  // reset values
18895
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
18896
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
18897
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
18898
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
18899
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
19922
+ state.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
19923
+ state.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
19924
+ state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
19925
+ state.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
19926
+ state.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
18900
19927
 
18901
19928
  // Generate mipmaps only when copying level 0
18902
19929
  if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
@@ -19019,4 +20046,4 @@ class WebGLRenderer {
19019
20046
 
19020
20047
  }
19021
20048
 
19022
- export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, ArrayCamera, BackSide, BoxGeometry, BufferAttribute, BufferGeometry, ByteType, CineonToneMapping, ClampToEdgeWrapping, Color, ColorManagement, ConstantAlphaFactor, ConstantColorFactor, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, CustomToneMapping, Data3DTexture, DataArrayTexture, DataTexture, DepthFormat, DepthStencilFormat, DepthTexture, DoubleSide, DstAlphaFactor, DstColorFactor, EqualCompare, EqualDepth, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExternalTexture, FloatType, FrontSide, Frustum, GLSL3, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, HalfFloatType, IntType, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NoBlending, NoColorSpace, NoToneMapping, NormalBlending, NotEqualCompare, NotEqualDepth, ObjectSpaceNormalMap, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, PerspectiveCamera, Plane, PlaneGeometry, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBADepthPacking, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RedFormat, RedIntegerFormat, ReinhardToneMapping, RepeatWrapping, ReverseSubtractEquation, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, ShaderChunk, ShaderLib, ShaderMaterial, ShortType, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, SubtractEquation, SubtractiveBlending, TangentSpaceNormalMap, Texture, Uint16BufferAttribute, Uint32BufferAttribute, UniformsLib, UniformsUtils, UnsignedByteType, UnsignedInt101111Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLRenderTarget, WebGLRenderer, WebGLUtils, WebXRController, ZeroFactor, createCanvasElement, error, log, warn, warnOnce };
20049
+ export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, ArrayCamera, BackSide, BoxGeometry, BufferAttribute, BufferGeometry, ByteType, CineonToneMapping, ClampToEdgeWrapping, Color, ColorManagement, ConstantAlphaFactor, ConstantColorFactor, CubeCamera, CubeDepthTexture, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, CustomToneMapping, Data3DTexture, DataArrayTexture, DataTexture, DepthFormat, DepthStencilFormat, DepthTexture, DoubleSide, DstAlphaFactor, DstColorFactor, EqualCompare, EqualDepth, EquirectangularReflectionMapping, EquirectangularRefractionMapping, EventDispatcher, ExternalTexture, Float32BufferAttribute, FloatType, FrontSide, Frustum, GLSL3, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, HalfFloatType, IntType, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NoBlending, NoColorSpace, NoToneMapping, NormalBlending, NotEqualCompare, NotEqualDepth, ObjectSpaceNormalMap, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, PerspectiveCamera, Plane, PlaneGeometry, R11_EAC_Format, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RG11_EAC_Format, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RawShaderMaterial, RedFormat, RedIntegerFormat, ReinhardToneMapping, RepeatWrapping, ReverseSubtractEquation, SIGNED_R11_EAC_Format, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SIGNED_RG11_EAC_Format, SRGBColorSpace, SRGBTransfer, ShaderChunk, ShaderLib, ShaderMaterial, ShortType, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, SubtractEquation, SubtractiveBlending, TangentSpaceNormalMap, Texture, Uint16BufferAttribute, Uint32BufferAttribute, UniformsLib, UniformsUtils, UnsignedByteType, UnsignedInt101111Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLRenderTarget, WebGLRenderer, WebGLUtils, WebXRController, ZeroFactor, createCanvasElement, error, log, warn, warnOnce };