@plastic-software/three 0.183.4 → 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 (277) hide show
  1. package/build/three.cjs +773 -286
  2. package/build/three.core.js +372 -110
  3. package/build/three.core.min.js +1 -1
  4. package/build/three.module.js +426 -180
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +7 -1
  7. package/build/three.tsl.min.js +1 -1
  8. package/build/three.webgpu.js +2979 -1281
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +2942 -1281
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/Addons.js +11 -0
  13. package/examples/jsm/animation/CCDIKSolver.js +5 -1
  14. package/examples/jsm/controls/ArcballControls.js +4 -1
  15. package/examples/jsm/controls/DragControls.js +2 -2
  16. package/examples/jsm/controls/FirstPersonControls.js +58 -54
  17. package/examples/jsm/controls/FlyControls.js +4 -0
  18. package/examples/jsm/controls/OrbitControls.js +2 -2
  19. package/examples/jsm/controls/TrackballControls.js +2 -2
  20. package/examples/jsm/controls/TransformControls.js +34 -2
  21. package/examples/jsm/csm/CSMShadowNode.js +6 -2
  22. package/examples/jsm/exporters/GLTFExporter.js +21 -5
  23. package/examples/jsm/geometries/TextGeometry.js +18 -0
  24. package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
  25. package/examples/jsm/inspector/Extension.js +13 -0
  26. package/examples/jsm/inspector/Inspector.js +169 -114
  27. package/examples/jsm/inspector/RendererInspector.js +2 -2
  28. package/examples/jsm/inspector/extensions/extensions.json +6 -0
  29. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
  30. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
  31. package/examples/jsm/inspector/tabs/Memory.js +128 -0
  32. package/examples/jsm/inspector/tabs/Parameters.js +34 -2
  33. package/examples/jsm/inspector/tabs/Performance.js +2 -2
  34. package/examples/jsm/inspector/tabs/Settings.js +264 -0
  35. package/examples/jsm/inspector/tabs/Timeline.js +1611 -0
  36. package/examples/jsm/inspector/tabs/Viewer.js +105 -3
  37. package/examples/jsm/inspector/ui/Graph.js +2 -2
  38. package/examples/jsm/inspector/ui/List.js +1 -1
  39. package/examples/jsm/inspector/ui/Profiler.js +273 -176
  40. package/examples/jsm/inspector/ui/Style.js +64 -10
  41. package/examples/jsm/inspector/ui/Tab.js +39 -7
  42. package/examples/jsm/inspector/ui/Values.js +39 -2
  43. package/examples/jsm/inspector/ui/utils.js +13 -0
  44. package/examples/jsm/interaction/InteractionManager.js +226 -0
  45. package/examples/jsm/libs/meshopt_decoder.module.js +8 -8
  46. package/examples/jsm/lighting/DynamicLighting.js +82 -0
  47. package/examples/jsm/lighting/LightProbeGrid.js +651 -0
  48. package/examples/jsm/lines/LineMaterial.js +1 -1
  49. package/examples/jsm/loaders/EXRLoader.js +682 -43
  50. package/examples/jsm/loaders/FBXLoader.js +233 -33
  51. package/examples/jsm/loaders/GLTFLoader.js +24 -7
  52. package/examples/jsm/loaders/HDRLoader.js +1 -1
  53. package/examples/jsm/loaders/KTX2Loader.js +8 -2
  54. package/examples/jsm/loaders/LDrawLoader.js +39 -47
  55. package/examples/jsm/loaders/SVGLoader.js +1 -1
  56. package/examples/jsm/loaders/VTKLoader.js +5 -1
  57. package/examples/jsm/loaders/collada/ColladaComposer.js +101 -7
  58. package/examples/jsm/loaders/collada/ColladaParser.js +19 -4
  59. package/examples/jsm/loaders/usd/USDAParser.js +6 -0
  60. package/examples/jsm/loaders/usd/USDCParser.js +26 -0
  61. package/examples/jsm/loaders/usd/USDComposer.js +656 -103
  62. package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
  63. package/examples/jsm/misc/RollerCoaster.js +42 -4
  64. package/examples/jsm/modifiers/TessellateModifier.js +1 -1
  65. package/examples/jsm/objects/Reflector.js +73 -25
  66. package/examples/jsm/objects/Sky.js +14 -2
  67. package/examples/jsm/objects/SkyMesh.js +23 -6
  68. package/examples/jsm/renderers/Projector.js +18 -38
  69. package/examples/jsm/renderers/SVGRenderer.js +6 -25
  70. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  71. package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
  72. package/examples/jsm/tsl/display/AfterImageNode.js +10 -0
  73. package/examples/jsm/tsl/display/AnamorphicNode.js +11 -0
  74. package/examples/jsm/tsl/display/BilateralBlurNode.js +10 -0
  75. package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
  76. package/examples/jsm/tsl/display/FSR1Node.js +477 -0
  77. package/examples/jsm/tsl/display/GTAONode.js +2 -1
  78. package/examples/jsm/tsl/display/GaussianBlurNode.js +10 -0
  79. package/examples/jsm/tsl/display/GodraysNode.js +2 -11
  80. package/examples/jsm/tsl/display/OutlineNode.js +66 -16
  81. package/examples/jsm/tsl/display/SSGINode.js +0 -4
  82. package/examples/jsm/tsl/display/SharpenNode.js +283 -0
  83. package/examples/jsm/tsl/display/TAAUNode.js +835 -0
  84. package/examples/jsm/tsl/display/TRAANode.js +48 -7
  85. package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
  86. package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
  87. package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
  88. package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
  89. package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
  90. package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
  91. package/examples/jsm/tsl/math/Bayer.js +13 -2
  92. package/examples/jsm/utils/BufferGeometryUtils.js +2 -3
  93. package/examples/jsm/utils/ColorUtils.js +76 -0
  94. package/examples/jsm/utils/SkeletonUtils.js +14 -8
  95. package/examples/jsm/webxr/XRHandMeshModel.js +36 -10
  96. package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
  97. package/package.json +4 -4
  98. package/src/Three.Core.js +1 -0
  99. package/src/Three.TSL.js +6 -0
  100. package/src/Three.WebGPU.Nodes.js +3 -0
  101. package/src/Three.WebGPU.js +6 -0
  102. package/src/animation/AnimationAction.js +11 -1
  103. package/src/audio/AudioContext.js +2 -2
  104. package/src/constants.js +1 -1
  105. package/src/core/BufferAttribute.js +13 -1
  106. package/src/core/Clock.js +1 -1
  107. package/src/core/Object3D.js +1 -5
  108. package/src/core/RenderTarget.js +1 -0
  109. package/src/extras/curves/CatmullRomCurve3.js +3 -2
  110. package/src/loaders/AudioLoader.js +11 -1
  111. package/src/loaders/DataTextureLoader.js +6 -4
  112. package/src/loaders/FileLoader.js +1 -2
  113. package/src/loaders/ImageBitmapLoader.js +4 -6
  114. package/src/loaders/MaterialLoader.js +1 -1
  115. package/src/loaders/ObjectLoader.js +25 -4
  116. package/src/loaders/nodes/NodeObjectLoader.js +18 -0
  117. package/src/materials/MeshToonMaterial.js +1 -1
  118. package/src/materials/nodes/Line2NodeMaterial.js +27 -0
  119. package/src/materials/nodes/NodeMaterial.js +0 -27
  120. package/src/materials/nodes/manager/NodeMaterialObserver.js +188 -89
  121. package/src/math/Line3.js +3 -0
  122. package/src/math/Matrix2.js +13 -9
  123. package/src/math/Matrix3.js +13 -9
  124. package/src/math/Matrix4.js +13 -9
  125. package/src/math/Plane.js +4 -3
  126. package/src/math/Triangle.js +1 -1
  127. package/src/math/Vector2.js +11 -7
  128. package/src/math/Vector3.js +12 -8
  129. package/src/math/Vector4.js +13 -9
  130. package/src/nodes/Nodes.js +0 -1
  131. package/src/nodes/TSL.js +1 -1
  132. package/src/nodes/accessors/BufferAttributeNode.js +9 -3
  133. package/src/nodes/accessors/CubeTextureNode.js +7 -1
  134. package/src/nodes/accessors/MaterialProperties.js +2 -5
  135. package/src/nodes/accessors/Object3DNode.js +1 -1
  136. package/src/nodes/accessors/ReferenceBaseNode.js +2 -2
  137. package/src/nodes/accessors/ReferenceNode.js +4 -4
  138. package/src/nodes/accessors/SceneProperties.js +2 -8
  139. package/src/nodes/accessors/StorageBufferNode.js +10 -4
  140. package/src/nodes/accessors/StorageTextureNode.js +4 -9
  141. package/src/nodes/accessors/TextureNode.js +10 -2
  142. package/src/nodes/accessors/UniformArrayNode.js +2 -2
  143. package/src/nodes/code/FunctionCallNode.js +1 -1
  144. package/src/nodes/code/FunctionNode.js +1 -1
  145. package/src/nodes/core/ArrayNode.js +1 -1
  146. package/src/nodes/core/AssignNode.js +1 -1
  147. package/src/nodes/core/AttributeNode.js +1 -1
  148. package/src/nodes/core/BypassNode.js +1 -1
  149. package/src/nodes/core/ContextNode.js +1 -1
  150. package/src/nodes/core/IndexNode.js +2 -1
  151. package/src/nodes/core/InputNode.js +1 -1
  152. package/src/nodes/core/InspectorNode.js +1 -1
  153. package/src/nodes/core/IsolateNode.js +1 -1
  154. package/src/nodes/core/Node.js +83 -12
  155. package/src/nodes/core/NodeBuilder.js +117 -16
  156. package/src/nodes/core/NodeUtils.js +1 -1
  157. package/src/nodes/core/OutputStructNode.js +1 -1
  158. package/src/nodes/core/ParameterNode.js +1 -1
  159. package/src/nodes/core/StackNode.js +1 -1
  160. package/src/nodes/core/StructNode.js +1 -1
  161. package/src/nodes/core/StructTypeNode.js +1 -1
  162. package/src/nodes/core/SubBuildNode.js +1 -1
  163. package/src/nodes/core/UniformGroupNode.js +36 -6
  164. package/src/nodes/core/VarNode.js +1 -1
  165. package/src/nodes/core/VaryingNode.js +1 -1
  166. package/src/nodes/display/NormalMapNode.js +2 -2
  167. package/src/nodes/display/PassNode.js +27 -7
  168. package/src/nodes/display/RenderOutputNode.js +4 -4
  169. package/src/nodes/display/ScreenNode.js +1 -1
  170. package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
  171. package/src/nodes/display/ViewportTextureNode.js +18 -7
  172. package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
  173. package/src/nodes/geometry/RangeNode.js +1 -1
  174. package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
  175. package/src/nodes/gpgpu/BarrierNode.js +9 -0
  176. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
  177. package/src/nodes/gpgpu/ComputeNode.js +69 -44
  178. package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
  179. package/src/nodes/lighting/LightsNode.js +6 -27
  180. package/src/nodes/lighting/ShadowNode.js +24 -2
  181. package/src/nodes/math/BitcastNode.js +1 -1
  182. package/src/nodes/math/ConditionalNode.js +1 -1
  183. package/src/nodes/math/MathNode.js +73 -1
  184. package/src/nodes/math/OperatorNode.js +1 -1
  185. package/src/nodes/math/PackFloatNode.js +1 -1
  186. package/src/nodes/math/UnpackFloatNode.js +1 -1
  187. package/src/nodes/tsl/TSLBase.js +1 -1
  188. package/src/nodes/tsl/TSLCore.js +21 -3
  189. package/src/nodes/utils/ArrayElementNode.js +1 -1
  190. package/src/nodes/utils/ConvertNode.js +1 -1
  191. package/src/nodes/utils/DebugNode.js +1 -1
  192. package/src/nodes/utils/EventNode.js +30 -0
  193. package/src/nodes/utils/FlipNode.js +1 -1
  194. package/src/nodes/utils/FunctionOverloadingNode.js +1 -1
  195. package/src/nodes/utils/JoinNode.js +1 -1
  196. package/src/nodes/utils/MemberNode.js +1 -1
  197. package/src/nodes/utils/Remap.js +48 -0
  198. package/src/nodes/utils/RotateNode.js +1 -1
  199. package/src/nodes/utils/SetNode.js +1 -1
  200. package/src/nodes/utils/SplitNode.js +1 -1
  201. package/src/objects/BatchedMesh.js +17 -2
  202. package/src/objects/InstancedMesh.js +19 -3
  203. package/src/objects/SkinnedMesh.js +26 -9
  204. package/src/renderers/WebGLRenderer.js +147 -48
  205. package/src/renderers/common/Animation.js +3 -3
  206. package/src/renderers/common/Attributes.js +15 -1
  207. package/src/renderers/common/Backend.js +0 -8
  208. package/src/renderers/common/Background.js +2 -2
  209. package/src/renderers/common/BindGroup.js +1 -8
  210. package/src/renderers/common/Bindings.js +2 -2
  211. package/src/renderers/common/ComputePipeline.js +1 -1
  212. package/src/renderers/common/CubeRenderTarget.js +1 -1
  213. package/src/renderers/common/Info.js +333 -4
  214. package/src/renderers/common/InspectorBase.js +6 -1
  215. package/src/renderers/common/Pipelines.js +36 -3
  216. package/src/renderers/common/ReadbackBuffer.js +78 -0
  217. package/src/renderers/common/RenderBundle.js +3 -1
  218. package/src/renderers/common/RenderBundles.js +5 -2
  219. package/src/renderers/common/RenderObject.js +2 -2
  220. package/src/renderers/common/RenderObjects.js +3 -3
  221. package/src/renderers/common/RenderPipeline.js +35 -6
  222. package/src/renderers/common/Renderer.js +232 -53
  223. package/src/renderers/common/Textures.js +72 -3
  224. package/src/renderers/common/UniformsGroup.js +1 -1
  225. package/src/renderers/common/XRManager.js +34 -27
  226. package/src/renderers/common/extras/PMREMGenerator.js +23 -15
  227. package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
  228. package/src/renderers/common/nodes/NodeManager.js +230 -99
  229. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
  230. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
  231. package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
  232. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +8 -0
  233. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +2 -0
  234. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -3
  235. package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
  236. package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
  237. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
  238. package/src/renderers/shaders/ShaderChunk.js +2 -0
  239. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
  240. package/src/renderers/shaders/ShaderLib.js +0 -1
  241. package/src/renderers/shaders/UniformsLib.js +7 -2
  242. package/src/renderers/shaders/UniformsUtils.js +27 -5
  243. package/src/renderers/webgl/WebGLAnimation.js +2 -1
  244. package/src/renderers/webgl/WebGLBackground.js +13 -13
  245. package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
  246. package/src/renderers/webgl/WebGLCapabilities.js +6 -0
  247. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
  248. package/src/renderers/webgl/WebGLMaterials.js +12 -13
  249. package/src/renderers/webgl/WebGLOutput.js +4 -1
  250. package/src/renderers/webgl/WebGLProgram.js +4 -0
  251. package/src/renderers/webgl/WebGLPrograms.js +19 -3
  252. package/src/renderers/webgl/WebGLRenderStates.js +13 -2
  253. package/src/renderers/webgl/WebGLState.js +43 -0
  254. package/src/renderers/webgl/WebGLTextures.js +129 -26
  255. package/src/renderers/webgl/WebGLUniformsGroups.js +19 -0
  256. package/src/renderers/webgl-fallback/WebGLBackend.js +106 -65
  257. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
  258. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +29 -51
  259. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
  260. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
  261. package/src/renderers/webgl-fallback/utils/WebGLState.js +42 -1
  262. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +63 -50
  263. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +1 -1
  264. package/src/renderers/webgpu/WebGPUBackend.js +160 -146
  265. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +55 -33
  266. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +103 -17
  267. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +1 -1
  268. package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
  269. package/src/renderers/webgpu/utils/WebGPUConstants.js +8 -0
  270. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +91 -17
  271. package/src/renderers/webgpu/utils/WebGPUUtils.js +18 -2
  272. package/src/renderers/webxr/WebXRController.js +12 -0
  273. package/src/textures/HTMLTexture.js +74 -0
  274. package/src/textures/Source.js +1 -1
  275. package/src/textures/Texture.js +13 -2
  276. package/src/utils.js +23 -1
  277. package/src/nodes/utils/RemapNode.js +0 -125
@@ -6,6 +6,7 @@ function WebGLRenderState( extensions ) {
6
6
 
7
7
  const lightsArray = [];
8
8
  const shadowsArray = [];
9
+ const lightProbeGridArray = [];
9
10
 
10
11
  function init( camera ) {
11
12
 
@@ -13,6 +14,7 @@ function WebGLRenderState( extensions ) {
13
14
 
14
15
  lightsArray.length = 0;
15
16
  shadowsArray.length = 0;
17
+ lightProbeGridArray.length = 0;
16
18
 
17
19
  }
18
20
 
@@ -28,6 +30,12 @@ function WebGLRenderState( extensions ) {
28
30
 
29
31
  }
30
32
 
33
+ function pushLightProbeGrid( volume ) {
34
+
35
+ lightProbeGridArray.push( volume );
36
+
37
+ }
38
+
31
39
  function setupLights() {
32
40
 
33
41
  lights.setup( lightsArray );
@@ -43,12 +51,14 @@ function WebGLRenderState( extensions ) {
43
51
  const state = {
44
52
  lightsArray: lightsArray,
45
53
  shadowsArray: shadowsArray,
54
+ lightProbeGridArray: lightProbeGridArray,
46
55
 
47
56
  camera: null,
48
57
 
49
58
  lights: lights,
50
59
 
51
- transmissionRenderTarget: {}
60
+ transmissionRenderTarget: {},
61
+ textureUnits: 0
52
62
  };
53
63
 
54
64
  return {
@@ -58,7 +68,8 @@ function WebGLRenderState( extensions ) {
58
68
  setupLightsView: setupLightsView,
59
69
 
60
70
  pushLight: pushLight,
61
- pushShadow: pushShadow
71
+ pushShadow: pushShadow,
72
+ pushLightProbeGrid: pushLightProbeGrid
62
73
  };
63
74
 
64
75
  }
@@ -353,6 +353,7 @@ function WebGLState( gl, extensions ) {
353
353
  const uboProgramMap = new WeakMap();
354
354
 
355
355
  let enabledCapabilities = {};
356
+ let parameters = {};
356
357
 
357
358
  let currentBoundFramebuffers = {};
358
359
  let currentDrawbuffers = new WeakMap();
@@ -1112,6 +1113,31 @@ function WebGLState( gl, extensions ) {
1112
1113
 
1113
1114
  }
1114
1115
 
1116
+ function getParameter( name ) {
1117
+
1118
+ if ( parameters[ name ] !== undefined ) {
1119
+
1120
+ return parameters[ name ];
1121
+
1122
+ } else {
1123
+
1124
+ return gl.getParameter( name );
1125
+
1126
+ }
1127
+
1128
+ }
1129
+
1130
+ function pixelStorei( name, value ) {
1131
+
1132
+ if ( parameters[ name ] !== value ) {
1133
+
1134
+ gl.pixelStorei( name, value );
1135
+ parameters[ name ] = value;
1136
+
1137
+ }
1138
+
1139
+ }
1140
+
1115
1141
  //
1116
1142
 
1117
1143
  function scissor( scissor ) {
@@ -1228,9 +1254,24 @@ function WebGLState( gl, extensions ) {
1228
1254
  gl.scissor( 0, 0, gl.canvas.width, gl.canvas.height );
1229
1255
  gl.viewport( 0, 0, gl.canvas.width, gl.canvas.height );
1230
1256
 
1257
+ gl.pixelStorei( gl.PACK_ALIGNMENT, 4 );
1258
+ gl.pixelStorei( gl.UNPACK_ALIGNMENT, 4 );
1259
+ gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, false );
1260
+ gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false );
1261
+ gl.pixelStorei( gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.BROWSER_DEFAULT_WEBGL );
1262
+ gl.pixelStorei( gl.PACK_ROW_LENGTH, 0 );
1263
+ gl.pixelStorei( gl.PACK_SKIP_PIXELS, 0 );
1264
+ gl.pixelStorei( gl.PACK_SKIP_ROWS, 0 );
1265
+ gl.pixelStorei( gl.UNPACK_ROW_LENGTH, 0 );
1266
+ gl.pixelStorei( gl.UNPACK_IMAGE_HEIGHT, 0 );
1267
+ gl.pixelStorei( gl.UNPACK_SKIP_PIXELS, 0 );
1268
+ gl.pixelStorei( gl.UNPACK_SKIP_ROWS, 0 );
1269
+ gl.pixelStorei( gl.UNPACK_SKIP_IMAGES, 0 );
1270
+
1231
1271
  // reset internals
1232
1272
 
1233
1273
  enabledCapabilities = {};
1274
+ parameters = {};
1234
1275
 
1235
1276
  currentTextureSlot = null;
1236
1277
  currentBoundTextures = {};
@@ -1304,6 +1345,8 @@ function WebGLState( gl, extensions ) {
1304
1345
  compressedTexImage3D: compressedTexImage3D,
1305
1346
  texImage2D: texImage2D,
1306
1347
  texImage3D: texImage3D,
1348
+ pixelStorei: pixelStorei,
1349
+ getParameter: getParameter,
1307
1350
 
1308
1351
  updateUBOMapping: updateUBOMapping,
1309
1352
  uniformBlockBinding: uniformBlockBinding,
@@ -11,6 +11,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
11
11
 
12
12
  const _imageDimensions = new Vector2();
13
13
  const _videoTextures = new WeakMap();
14
+ const _htmlTextures = new Set();
14
15
  let _canvas;
15
16
 
16
17
  const _sources = new WeakMap(); // maps WebglTexture objects to instances of Source
@@ -125,7 +126,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
125
126
 
126
127
  }
127
128
 
128
- function getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
129
+ function getInternalFormat( internalFormatName, glFormat, glType, normalized, colorSpace, forceLinearTransfer = false ) {
129
130
 
130
131
  if ( internalFormatName !== null ) {
131
132
 
@@ -135,6 +136,20 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
135
136
 
136
137
  }
137
138
 
139
+ let ext_texture_norm16;
140
+
141
+ if ( normalized ) {
142
+
143
+ ext_texture_norm16 = extensions.get( 'EXT_texture_norm16' );
144
+
145
+ if ( ! ext_texture_norm16 ) {
146
+
147
+ warn( 'WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension' );
148
+
149
+ }
150
+
151
+ }
152
+
138
153
  let internalFormat = glFormat;
139
154
 
140
155
  if ( glFormat === _gl.RED ) {
@@ -142,6 +157,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
142
157
  if ( glType === _gl.FLOAT ) internalFormat = _gl.R32F;
143
158
  if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.R16F;
144
159
  if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.R8;
160
+ if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_EXT;
161
+ if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.R16_SNORM_EXT;
145
162
 
146
163
  }
147
164
 
@@ -161,6 +178,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
161
178
  if ( glType === _gl.FLOAT ) internalFormat = _gl.RG32F;
162
179
  if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RG16F;
163
180
  if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RG8;
181
+ if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_EXT;
182
+ if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RG16_SNORM_EXT;
164
183
 
165
184
  }
166
185
 
@@ -199,6 +218,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
199
218
 
200
219
  if ( glFormat === _gl.RGB ) {
201
220
 
221
+ if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_EXT;
222
+ if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGB16_SNORM_EXT;
202
223
  if ( glType === _gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = _gl.RGB9_E5;
203
224
  if ( glType === _gl.UNSIGNED_INT_10F_11F_11F_REV ) internalFormat = _gl.R11F_G11F_B10F;
204
225
 
@@ -211,6 +232,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
211
232
  if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;
212
233
  if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;
213
234
  if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( transfer === SRGBTransfer ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
235
+ if ( glType === _gl.UNSIGNED_SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_EXT;
236
+ if ( glType === _gl.SHORT && ext_texture_norm16 ) internalFormat = ext_texture_norm16.RGBA16_SNORM_EXT;
214
237
  if ( glType === _gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = _gl.RGBA4;
215
238
  if ( glType === _gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = _gl.RGB5_A1;
216
239
 
@@ -312,6 +335,12 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
312
335
 
313
336
  }
314
337
 
338
+ if ( texture.isHTMLTexture ) {
339
+
340
+ _htmlTextures.delete( texture );
341
+
342
+ }
343
+
315
344
  }
316
345
 
317
346
  function onRenderTargetDispose( event ) {
@@ -468,6 +497,18 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
468
497
 
469
498
  }
470
499
 
500
+ function getTextureUnits() {
501
+
502
+ return textureUnits;
503
+
504
+ }
505
+
506
+ function setTextureUnits( value ) {
507
+
508
+ textureUnits = value;
509
+
510
+ }
511
+
471
512
  function allocateTextureUnit() {
472
513
 
473
514
  const textureUnit = textureUnits;
@@ -819,11 +860,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
819
860
  // Trim the array to only contain the merged ranges.
820
861
  updateRanges.length = mergeIndex + 1;
821
862
 
822
- const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
823
- const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
824
- const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
863
+ const currentUnpackRowLen = state.getParameter( _gl.UNPACK_ROW_LENGTH );
864
+ const currentUnpackSkipPixels = state.getParameter( _gl.UNPACK_SKIP_PIXELS );
865
+ const currentUnpackSkipRows = state.getParameter( _gl.UNPACK_SKIP_ROWS );
825
866
 
826
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
867
+ state.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
827
868
 
828
869
  for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {
829
870
 
@@ -839,8 +880,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
839
880
  const width = pixelCount;
840
881
  const height = 1;
841
882
 
842
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, x );
843
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, y );
883
+ state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, x );
884
+ state.pixelStorei( _gl.UNPACK_SKIP_ROWS, y );
844
885
 
845
886
  state.texSubImage2D( _gl.TEXTURE_2D, 0, x, y, width, height, glFormat, glType, image.data );
846
887
 
@@ -848,9 +889,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
848
889
 
849
890
  texture.clearUpdateRanges();
850
891
 
851
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
852
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
853
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
892
+ state.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
893
+ state.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
894
+ state.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
854
895
 
855
896
  }
856
897
 
@@ -874,14 +915,21 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
874
915
 
875
916
  state.activeTexture( _gl.TEXTURE0 + slot );
876
917
 
877
- const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );
878
- const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );
879
- const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;
918
+ const isImageBitmap = ( typeof ImageBitmap !== 'undefined' && texture.image instanceof ImageBitmap );
919
+
920
+ if ( isImageBitmap === false ) {
921
+
922
+ const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );
923
+ const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );
924
+ const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;
925
+
926
+ state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
927
+ state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
928
+ state.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
929
+
930
+ }
880
931
 
881
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
882
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
883
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
884
- _gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
932
+ state.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
885
933
 
886
934
  let image = resizeImage( texture.image, false, capabilities.maxTextureSize );
887
935
  image = verifyColorSpace( texture, image );
@@ -889,7 +937,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
889
937
  const glFormat = utils.convert( texture.format, texture.colorSpace );
890
938
 
891
939
  const glType = utils.convert( texture.type );
892
- let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
940
+ let glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, texture.isVideoTexture );
893
941
 
894
942
  setTextureParameters( textureType, texture );
895
943
 
@@ -1206,6 +1254,59 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1206
1254
 
1207
1255
  }
1208
1256
 
1257
+ } else if ( texture.isHTMLTexture ) {
1258
+
1259
+ if ( 'texElementImage2D' in _gl ) {
1260
+
1261
+ const canvas = _gl.canvas;
1262
+
1263
+ // Ensure the canvas supports HTML-in-Canvas and the element is a child.
1264
+ if ( ! canvas.hasAttribute( 'layoutsubtree' ) ) {
1265
+
1266
+ canvas.setAttribute( 'layoutsubtree', 'true' );
1267
+
1268
+ }
1269
+
1270
+ if ( image.parentNode !== canvas ) {
1271
+
1272
+ canvas.appendChild( image );
1273
+
1274
+ // Register and set up a shared paint callback for all HTMLTextures.
1275
+ _htmlTextures.add( texture );
1276
+
1277
+ canvas.onpaint = ( event ) => {
1278
+
1279
+ const changed = event.changedElements;
1280
+
1281
+ for ( const t of _htmlTextures ) {
1282
+
1283
+ if ( changed.includes( t.image ) ) {
1284
+
1285
+ t.needsUpdate = true;
1286
+
1287
+ }
1288
+
1289
+ }
1290
+
1291
+ };
1292
+
1293
+ canvas.requestPaint();
1294
+ return;
1295
+
1296
+ }
1297
+
1298
+ const level = 0;
1299
+ const internalFormat = _gl.RGBA;
1300
+ const srcFormat = _gl.RGBA;
1301
+ const srcType = _gl.UNSIGNED_BYTE;
1302
+
1303
+ _gl.texElementImage2D( _gl.TEXTURE_2D, level, internalFormat, srcFormat, srcType, image );
1304
+ _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_MIN_FILTER, _gl.LINEAR );
1305
+ _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
1306
+ _gl.texParameteri( _gl.TEXTURE_2D, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
1307
+
1308
+ }
1309
+
1209
1310
  } else {
1210
1311
 
1211
1312
  // regular Texture (image, video, canvas)
@@ -1309,10 +1410,10 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1309
1410
  const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries( texture.colorSpace );
1310
1411
  const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL;
1311
1412
 
1312
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
1313
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
1314
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
1315
- _gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
1413
+ state.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
1414
+ state.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
1415
+ state.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
1416
+ state.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion );
1316
1417
 
1317
1418
  const isCompressed = ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture );
1318
1419
  const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
@@ -1338,7 +1439,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1338
1439
  const image = cubeImage[ 0 ],
1339
1440
  glFormat = utils.convert( texture.format, texture.colorSpace ),
1340
1441
  glType = utils.convert( texture.type ),
1341
- glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
1442
+ glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );
1342
1443
 
1343
1444
  const useTexStorage = ( texture.isVideoTexture !== true );
1344
1445
  const allocateMemory = ( sourceProperties.__version === undefined ) || ( forceUpload === true );
@@ -1534,7 +1635,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1534
1635
 
1535
1636
  const glFormat = utils.convert( texture.format, texture.colorSpace );
1536
1637
  const glType = utils.convert( texture.type );
1537
- const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
1638
+ const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );
1538
1639
  const renderTargetProperties = properties.get( renderTarget );
1539
1640
  const textureProperties = properties.get( texture );
1540
1641
 
@@ -1613,7 +1714,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1613
1714
 
1614
1715
  const glFormat = utils.convert( texture.format, texture.colorSpace );
1615
1716
  const glType = utils.convert( texture.type );
1616
- const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
1717
+ const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace );
1617
1718
 
1618
1719
  if ( useMultisampledRTT( renderTarget ) ) {
1619
1720
 
@@ -2003,7 +2104,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
2003
2104
 
2004
2105
  const glFormat = utils.convert( texture.format, texture.colorSpace );
2005
2106
  const glType = utils.convert( texture.type );
2006
- const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, renderTarget.isXRRenderTarget === true );
2107
+ const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.normalized, texture.colorSpace, renderTarget.isXRRenderTarget === true );
2007
2108
  const samples = getRenderTargetSamples( renderTarget );
2008
2109
  _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
2009
2110
 
@@ -2379,6 +2480,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
2379
2480
 
2380
2481
  this.allocateTextureUnit = allocateTextureUnit;
2381
2482
  this.resetTextureUnits = resetTextureUnits;
2483
+ this.getTextureUnits = getTextureUnits;
2484
+ this.setTextureUnits = setTextureUnits;
2382
2485
 
2383
2486
  this.setTexture2D = setTexture2D;
2384
2487
  this.setTexture2DArray = setTexture2DArray;
@@ -141,6 +141,11 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
141
141
  uniform.__data[ 10 ] = value.elements[ 8 ];
142
142
  uniform.__data[ 11 ] = 0;
143
143
 
144
+ } else if ( ArrayBuffer.isView( value ) ) {
145
+
146
+ // copy the buffer data using "set"
147
+ uniform.__data.set( new value.constructor( value.buffer, value.byteOffset, uniform.__data.length ) );
148
+
144
149
  } else {
145
150
 
146
151
  value.toArray( uniform.__data, arrayOffset );
@@ -176,6 +181,10 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
176
181
 
177
182
  cache[ indexString ] = value;
178
183
 
184
+ } else if ( ArrayBuffer.isView( value ) ) {
185
+
186
+ cache[ indexString ] = value.slice();
187
+
179
188
  } else {
180
189
 
181
190
  cache[ indexString ] = value.clone();
@@ -199,6 +208,11 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
199
208
 
200
209
  }
201
210
 
211
+ } else if ( ArrayBuffer.isView( value ) ) {
212
+
213
+ // always update the array buffers
214
+ return true;
215
+
202
216
  } else {
203
217
 
204
218
  if ( cachedObject.equals( value ) === false ) {
@@ -339,6 +353,11 @@ function WebGLUniformsGroups( gl, info, capabilities, state ) {
339
353
 
340
354
  warn( 'WebGLRenderer: Texture samplers can not be part of an uniforms group.' );
341
355
 
356
+ } else if ( ArrayBuffer.isView( value ) ) {
357
+
358
+ info.boundary = 16;
359
+ info.storage = value.byteLength;
360
+
342
361
  } else {
343
362
 
344
363
  warn( 'WebGLRenderer: Unsupported uniform value type.', value );