super-three 0.164.0 → 0.165.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 (124) hide show
  1. package/README.md +3 -3
  2. package/build/three.cjs +664 -217
  3. package/build/three.module.js +664 -217
  4. package/build/three.module.min.js +1 -1
  5. package/examples/jsm/controls/TransformControls.js +1 -1
  6. package/examples/jsm/environments/RoomEnvironment.js +1 -5
  7. package/examples/jsm/exporters/GLTFExporter.js +1 -1
  8. package/examples/jsm/exporters/USDZExporter.js +6 -4
  9. package/examples/jsm/helpers/ViewHelper.js +32 -67
  10. package/examples/jsm/libs/tween.module.js +75 -64
  11. package/examples/jsm/lines/LineMaterial.js +1 -15
  12. package/examples/jsm/lines/LineSegments2.js +15 -0
  13. package/examples/jsm/lines/Wireframe.js +16 -1
  14. package/examples/jsm/loaders/DRACOLoader.js +1 -1
  15. package/examples/jsm/loaders/FBXLoader.js +24 -13
  16. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  17. package/examples/jsm/loaders/LDrawLoader.js +3 -2
  18. package/examples/jsm/loaders/MMDLoader.js +31 -12
  19. package/examples/jsm/modifiers/CurveModifier.js +11 -9
  20. package/examples/jsm/nodes/Nodes.js +12 -11
  21. package/examples/jsm/nodes/accessors/BitangentNode.js +7 -83
  22. package/examples/jsm/nodes/accessors/BufferNode.js +6 -0
  23. package/examples/jsm/nodes/accessors/CameraNode.js +12 -119
  24. package/examples/jsm/nodes/accessors/MaterialNode.js +2 -0
  25. package/examples/jsm/nodes/accessors/ModelNode.js +3 -0
  26. package/examples/jsm/nodes/accessors/NormalNode.js +9 -101
  27. package/examples/jsm/nodes/accessors/PositionNode.js +6 -100
  28. package/examples/jsm/nodes/accessors/ReferenceNode.js +6 -0
  29. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +2 -31
  30. package/examples/jsm/nodes/accessors/{TextureStoreNode.js → StorageTextureNode.js} +19 -6
  31. package/examples/jsm/nodes/accessors/TangentNode.js +11 -97
  32. package/examples/jsm/nodes/accessors/Texture3DNode.js +100 -0
  33. package/examples/jsm/nodes/accessors/UVNode.js +2 -46
  34. package/examples/jsm/nodes/core/AttributeNode.js +15 -3
  35. package/examples/jsm/nodes/core/ContextNode.js +6 -0
  36. package/examples/jsm/nodes/core/Node.js +15 -2
  37. package/examples/jsm/nodes/core/NodeBuilder.js +20 -9
  38. package/examples/jsm/nodes/core/NodeKeywords.js +1 -1
  39. package/examples/jsm/nodes/core/OutputStructNode.js +1 -5
  40. package/examples/jsm/nodes/core/PropertyNode.js +1 -0
  41. package/examples/jsm/nodes/core/VaryingNode.js +40 -9
  42. package/examples/jsm/nodes/display/AfterImageNode.js +14 -2
  43. package/examples/jsm/nodes/display/PassNode.js +3 -1
  44. package/examples/jsm/nodes/display/ViewportNode.js +1 -1
  45. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +61 -17
  46. package/examples/jsm/nodes/functions/ToonLightingModel.js +49 -0
  47. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +2 -1
  48. package/examples/jsm/nodes/lighting/LightsNode.js +17 -0
  49. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +1 -1
  50. package/examples/jsm/nodes/materials/Materials.js +3 -0
  51. package/examples/jsm/nodes/materials/MeshMatcapNodeMaterial.js +52 -0
  52. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +21 -4
  53. package/examples/jsm/nodes/materials/MeshToonNodeMaterial.js +34 -0
  54. package/examples/jsm/nodes/materials/NodeMaterial.js +13 -5
  55. package/examples/jsm/nodes/materials/VolumeNodeMaterial.js +106 -0
  56. package/examples/jsm/nodes/math/HashNode.js +2 -2
  57. package/examples/jsm/nodes/shadernode/ShaderNode.js +55 -33
  58. package/examples/jsm/nodes/utils/ArrayElementNode.js +1 -1
  59. package/examples/jsm/nodes/utils/MatcapUVNode.js +1 -1
  60. package/examples/jsm/nodes/utils/TimerNode.js +1 -1
  61. package/examples/jsm/objects/Lensflare.js +2 -2
  62. package/examples/jsm/postprocessing/RenderPass.js +1 -1
  63. package/examples/jsm/renderers/CSS2DRenderer.js +25 -5
  64. package/examples/jsm/renderers/CSS3DRenderer.js +24 -3
  65. package/examples/jsm/renderers/common/Attributes.js +2 -0
  66. package/examples/jsm/renderers/common/Bindings.js +17 -0
  67. package/examples/jsm/renderers/common/ChainMap.js +18 -48
  68. package/examples/jsm/renderers/common/ClippingContext.js +4 -4
  69. package/examples/jsm/renderers/common/Pipelines.js +2 -2
  70. package/examples/jsm/renderers/common/RenderBundle.js +18 -0
  71. package/examples/jsm/renderers/common/RenderBundles.js +38 -0
  72. package/examples/jsm/renderers/common/RenderList.js +9 -0
  73. package/examples/jsm/renderers/common/RenderObject.js +6 -0
  74. package/examples/jsm/renderers/common/Renderer.js +139 -11
  75. package/examples/jsm/renderers/common/Uniform.js +1 -1
  76. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +18 -4
  77. package/examples/jsm/renderers/common/nodes/NodeSampler.js +6 -0
  78. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +17 -5
  79. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +93 -6
  80. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +50 -4
  81. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +69 -11
  82. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +10 -1
  83. package/examples/jsm/renderers/webgpu/utils/WebGPUConstants.js +6 -0
  84. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +62 -19
  85. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +62 -3
  86. package/examples/jsm/utils/BufferGeometryUtils.js +18 -16
  87. package/examples/jsm/utils/GPUStatsPanel.js +2 -0
  88. package/examples/jsm/utils/SortUtils.js +8 -5
  89. package/package.json +3 -2
  90. package/src/animation/tracks/BooleanKeyframeTrack.js +10 -1
  91. package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -2
  92. package/src/animation/tracks/StringKeyframeTrack.js +10 -1
  93. package/src/constants.js +1 -1
  94. package/src/core/Object3D.js +2 -0
  95. package/src/core/Raycaster.js +6 -2
  96. package/src/loaders/FileLoader.js +4 -0
  97. package/src/loaders/LoaderUtils.js +3 -1
  98. package/src/loaders/ObjectLoader.js +1 -0
  99. package/src/objects/BatchedMesh.js +91 -1
  100. package/src/renderers/WebGLRenderer.js +288 -57
  101. package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +15 -0
  102. package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -1
  103. package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +9 -1
  104. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +8 -22
  105. package/src/renderers/shaders/ShaderChunk/morphcolor_vertex.glsl.js +1 -1
  106. package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +1 -1
  107. package/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl.js +3 -14
  108. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +10 -31
  109. package/src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl.js +3 -23
  110. package/src/renderers/webgl/WebGLBackground.js +6 -0
  111. package/src/renderers/webgl/WebGLExtensions.js +3 -1
  112. package/src/renderers/webgl/WebGLLights.js +9 -12
  113. package/src/renderers/webgl/WebGLMaterials.js +1 -5
  114. package/src/renderers/webgl/WebGLMorphtargets.js +1 -2
  115. package/src/renderers/webgl/WebGLProgram.js +2 -31
  116. package/src/renderers/webgl/WebGLPrograms.js +14 -14
  117. package/src/renderers/webgl/WebGLRenderStates.js +2 -2
  118. package/src/renderers/webgl/WebGLTextures.js +139 -70
  119. package/src/renderers/webxr/WebXRDepthSensing.js +3 -3
  120. package/src/renderers/webxr/WebXRManager.js +6 -2
  121. package/src/textures/CompressedArrayTexture.js +14 -0
  122. package/src/textures/DataArrayTexture.js +14 -0
  123. package/src/textures/DepthTexture.js +1 -3
  124. package/src/utils.js +30 -1
@@ -3,7 +3,7 @@
3
3
  * Copyright 2010-2024 Three.js Authors
4
4
  * SPDX-License-Identifier: MIT
5
5
  */
6
- const REVISION = '164';
6
+ const REVISION = '165';
7
7
 
8
8
  const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
9
9
  const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
@@ -1560,6 +1560,35 @@ function warnOnce( message ) {
1560
1560
 
1561
1561
  }
1562
1562
 
1563
+ function probeAsync( gl, sync, interval ) {
1564
+
1565
+ return new Promise( function ( resolve, reject ) {
1566
+
1567
+ function probe() {
1568
+
1569
+ switch ( gl.clientWaitSync( sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0 ) ) {
1570
+
1571
+ case gl.WAIT_FAILED:
1572
+ reject();
1573
+ break;
1574
+
1575
+ case gl.TIMEOUT_EXPIRED:
1576
+ setTimeout( probe, interval );
1577
+ break;
1578
+
1579
+ default:
1580
+ resolve();
1581
+
1582
+ }
1583
+
1584
+ }
1585
+
1586
+ setTimeout( probe, interval );
1587
+
1588
+ } );
1589
+
1590
+ }
1591
+
1563
1592
  /**
1564
1593
  * Matrices converting P3 <-> Rec. 709 primaries, without gamut mapping
1565
1594
  * or clipping. Based on W3C specifications for sRGB and Display P3,
@@ -3077,6 +3106,20 @@ class DataArrayTexture extends Texture {
3077
3106
  this.flipY = false;
3078
3107
  this.unpackAlignment = 1;
3079
3108
 
3109
+ this.layerUpdates = new Set();
3110
+
3111
+ }
3112
+
3113
+ addLayerUpdate( layerIndex ) {
3114
+
3115
+ this.layerUpdates.add( layerIndex );
3116
+
3117
+ }
3118
+
3119
+ clearLayerUpdates() {
3120
+
3121
+ this.layerUpdates.clear();
3122
+
3080
3123
  }
3081
3124
 
3082
3125
  }
@@ -7846,6 +7889,8 @@ class Object3D extends EventDispatcher {
7846
7889
 
7847
7890
  object.matricesTexture = this._matricesTexture.toJSON( meta );
7848
7891
 
7892
+ if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );
7893
+
7849
7894
  if ( this.boundingSphere !== null ) {
7850
7895
 
7851
7896
  object.boundingSphere = {
@@ -13758,7 +13803,7 @@ var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D(
13758
13803
 
13759
13804
  var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
13760
13805
 
13761
- var batching_pars_vertex = "#ifdef USE_BATCHING\n\tattribute float batchId;\n\tuniform highp sampler2D batchingTexture;\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#endif";
13806
+ var batching_pars_vertex = "#ifdef USE_BATCHING\n\tattribute float batchId;\n\tuniform highp sampler2D batchingTexture;\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#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";
13762
13807
 
13763
13808
  var batching_vertex = "#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( batchId );\n#endif";
13764
13809
 
@@ -13784,9 +13829,9 @@ var color_fragment = "#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\
13784
13829
 
13785
13830
  var color_pars_fragment = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif";
13786
13831
 
13787
- var color_pars_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
13832
+ 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";
13788
13833
 
13789
- var color_vertex = "#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_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";
13834
+ 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( batchId );\n\tvColor.xyz *= batchingColor.xyz;\n#endif";
13790
13835
 
13791
13836
  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}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat luminance( const in vec3 rgb ) {\n\tconst vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 );\n\treturn dot( weights, rgb );\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";
13792
13837
 
@@ -13832,7 +13877,7 @@ var lights_lambert_fragment = "LambertMaterial material;\nmaterial.diffuseColor
13832
13877
 
13833
13878
  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";
13834
13879
 
13835
- 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\t#if defined ( LEGACY_LIGHTS )\n\t\tif ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\t\treturn pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t\t}\n\t\treturn 1.0;\n\t#else\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tif ( cutoffDistance > 0.0 ) {\n\t\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\t}\n\t\treturn distanceFalloff;\n\t#endif\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";
13880
+ 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";
13836
13881
 
13837
13882
  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, roughness * 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";
13838
13883
 
@@ -13874,15 +13919,15 @@ var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_META
13874
13919
 
13875
13920
  var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
13876
13921
 
13877
- var morphinstance_vertex = "#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[MORPHTARGETS_COUNT];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif";
13922
+ var morphinstance_vertex = "#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif";
13878
13923
 
13879
- var morphcolor_vertex = "#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif";
13924
+ var morphcolor_vertex = "#if defined( USE_MORPHCOLORS )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif";
13880
13925
 
13881
- var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\t\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\t\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\t\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n\t#endif\n#endif";
13926
+ var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif";
13882
13927
 
13883
- var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t#endif\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\t#ifndef USE_INSTANCING_MORPH\n\t\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t\t#endif\n\t\tuniform sampler2DArray morphTargetsTexture;\n\t\tuniform ivec2 morphTargetsTextureSize;\n\t\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t\t}\n\t#else\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\tuniform float morphTargetInfluences[ 8 ];\n\t\t#else\n\t\t\tuniform float morphTargetInfluences[ 4 ];\n\t\t#endif\n\t#endif\n#endif";
13928
+ var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif";
13884
13929
 
13885
- var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\t\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\t\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\t\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t\t#endif\n\t#endif\n#endif";
13930
+ var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif";
13886
13931
 
13887
13932
  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;";
13888
13933
 
@@ -14807,6 +14852,12 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
14807
14852
 
14808
14853
  if ( renderer.autoClear || forceClear ) {
14809
14854
 
14855
+ // buffers might not be writable which is required to ensure a correct clear
14856
+
14857
+ state.buffers.depth.setTest( true );
14858
+ state.buffers.depth.setMask( true );
14859
+ state.buffers.color.setMask( true );
14860
+
14810
14861
  renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
14811
14862
 
14812
14863
  }
@@ -17320,7 +17371,7 @@ function WebGLExtensions( gl ) {
17320
17371
 
17321
17372
  if ( extension === null ) {
17322
17373
 
17323
- console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
17374
+ warnOnce( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
17324
17375
 
17325
17376
  }
17326
17377
 
@@ -17730,8 +17781,7 @@ function WebGLMorphtargets( gl, capabilities, textures ) {
17730
17781
 
17731
17782
  const objectInfluences = object.morphTargetInfluences;
17732
17783
 
17733
- // instead of using attributes, the WebGL 2 code path encodes morph targets
17734
- // into an array of data textures. Each layer represents a single morph target.
17784
+ // the following encodes morph targets into an array of data textures. Each layer represents a single morph target.
17735
17785
 
17736
17786
  const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;
17737
17787
  const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0;
@@ -18072,9 +18122,7 @@ function WebGLObjects( gl, geometries, attributes, info ) {
18072
18122
 
18073
18123
  class DepthTexture extends Texture {
18074
18124
 
18075
- constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
18076
-
18077
- format = format !== undefined ? format : DepthFormat;
18125
+ constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat ) {
18078
18126
 
18079
18127
  if ( format !== DepthFormat && format !== DepthStencilFormat ) {
18080
18128
 
@@ -19804,6 +19852,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
19804
19852
 
19805
19853
  parameters.extensionClipCullDistance ? '#define USE_CLIP_DISTANCE' : '',
19806
19854
  parameters.batching ? '#define USE_BATCHING' : '',
19855
+ parameters.batchingColor ? '#define USE_BATCHING_COLOR' : '',
19807
19856
  parameters.instancing ? '#define USE_INSTANCING' : '',
19808
19857
  parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',
19809
19858
  parameters.instancingMorph ? '#define USE_INSTANCING_MORPH' : '',
@@ -19900,7 +19949,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
19900
19949
  parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
19901
19950
  parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
19902
19951
  ( parameters.morphColors ) ? '#define USE_MORPHCOLORS' : '',
19903
- ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_TEXTURE' : '',
19904
19952
  ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_TEXTURE_STRIDE ' + parameters.morphTextureStride : '',
19905
19953
  ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_COUNT ' + parameters.morphTargetsCount : '',
19906
19954
  parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
@@ -19913,8 +19961,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
19913
19961
 
19914
19962
  parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
19915
19963
 
19916
- parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
19917
-
19918
19964
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
19919
19965
 
19920
19966
  'uniform mat4 modelMatrix;',
@@ -19981,31 +20027,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
19981
20027
 
19982
20028
  '#endif',
19983
20029
 
19984
- '#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )',
19985
-
19986
- ' attribute vec3 morphTarget0;',
19987
- ' attribute vec3 morphTarget1;',
19988
- ' attribute vec3 morphTarget2;',
19989
- ' attribute vec3 morphTarget3;',
19990
-
19991
- ' #ifdef USE_MORPHNORMALS',
19992
-
19993
- ' attribute vec3 morphNormal0;',
19994
- ' attribute vec3 morphNormal1;',
19995
- ' attribute vec3 morphNormal2;',
19996
- ' attribute vec3 morphNormal3;',
19997
-
19998
- ' #else',
19999
-
20000
- ' attribute vec3 morphTarget4;',
20001
- ' attribute vec3 morphTarget5;',
20002
- ' attribute vec3 morphTarget6;',
20003
- ' attribute vec3 morphTarget7;',
20004
-
20005
- ' #endif',
20006
-
20007
- '#endif',
20008
-
20009
20030
  '#ifdef USE_SKINNING',
20010
20031
 
20011
20032
  ' attribute vec4 skinIndex;',
@@ -20081,7 +20102,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
20081
20102
  parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',
20082
20103
 
20083
20104
  parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '',
20084
- parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
20105
+ parameters.vertexColors || parameters.instancingColor || parameters.batchingColor ? '#define USE_COLOR' : '',
20085
20106
  parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',
20086
20107
  parameters.vertexUv1s ? '#define USE_UV1' : '',
20087
20108
  parameters.vertexUv2s ? '#define USE_UV2' : '',
@@ -20103,8 +20124,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
20103
20124
 
20104
20125
  parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
20105
20126
 
20106
- parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
20107
-
20108
20127
  parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
20109
20128
 
20110
20129
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
@@ -20727,6 +20746,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
20727
20746
  precision: precision,
20728
20747
 
20729
20748
  batching: IS_BATCHEDMESH,
20749
+ batchingColor: IS_BATCHEDMESH && object._colorsTexture !== null,
20730
20750
  instancing: IS_INSTANCEDMESH,
20731
20751
  instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null,
20732
20752
  instancingMorph: IS_INSTANCEDMESH && object.morphTexture !== null,
@@ -20872,7 +20892,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
20872
20892
  shadowMapType: renderer.shadowMap.type,
20873
20893
 
20874
20894
  toneMapping: toneMapping,
20875
- useLegacyLights: renderer._useLegacyLights,
20876
20895
 
20877
20896
  decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ),
20878
20897
 
@@ -21046,6 +21065,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
21046
21065
  _programLayers.enable( 19 );
21047
21066
  if ( parameters.dispersion )
21048
21067
  _programLayers.enable( 20 );
21068
+ if ( parameters.batchingColor )
21069
+ _programLayers.enable( 21 );
21049
21070
 
21050
21071
  array.push( _programLayers.mask );
21051
21072
  _programLayers.disableAll();
@@ -21070,30 +21091,28 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
21070
21091
  _programLayers.enable( 8 );
21071
21092
  if ( parameters.shadowMapEnabled )
21072
21093
  _programLayers.enable( 9 );
21073
- if ( parameters.useLegacyLights )
21074
- _programLayers.enable( 10 );
21075
21094
  if ( parameters.doubleSided )
21076
- _programLayers.enable( 11 );
21095
+ _programLayers.enable( 10 );
21077
21096
  if ( parameters.flipSided )
21078
- _programLayers.enable( 12 );
21097
+ _programLayers.enable( 11 );
21079
21098
  if ( parameters.useDepthPacking )
21080
- _programLayers.enable( 13 );
21099
+ _programLayers.enable( 12 );
21081
21100
  if ( parameters.dithering )
21082
- _programLayers.enable( 14 );
21101
+ _programLayers.enable( 13 );
21083
21102
  if ( parameters.transmission )
21084
- _programLayers.enable( 15 );
21103
+ _programLayers.enable( 14 );
21085
21104
  if ( parameters.sheen )
21086
- _programLayers.enable( 16 );
21105
+ _programLayers.enable( 15 );
21087
21106
  if ( parameters.opaque )
21088
- _programLayers.enable( 17 );
21107
+ _programLayers.enable( 16 );
21089
21108
  if ( parameters.pointsUvs )
21090
- _programLayers.enable( 18 );
21109
+ _programLayers.enable( 17 );
21091
21110
  if ( parameters.decodeVideoTexture )
21092
- _programLayers.enable( 19 );
21111
+ _programLayers.enable( 18 );
21093
21112
  if ( parameters.alphaToCoverage )
21094
- _programLayers.enable( 20 );
21113
+ _programLayers.enable( 19 );
21095
21114
  if ( parameters.numMultiviewViews )
21096
- _programLayers.enable( 21 );
21115
+ _programLayers.enable( 20 );
21097
21116
 
21098
21117
  array.push( _programLayers.mask );
21099
21118
 
@@ -21675,7 +21694,7 @@ function WebGLLights( extensions ) {
21675
21694
  const matrix4 = new Matrix4();
21676
21695
  const matrix42 = new Matrix4();
21677
21696
 
21678
- function setup( lights, useLegacyLights ) {
21697
+ function setup( lights ) {
21679
21698
 
21680
21699
  let r = 0, g = 0, b = 0;
21681
21700
 
@@ -21698,9 +21717,6 @@ function WebGLLights( extensions ) {
21698
21717
  // ordering : [shadow casting + map texturing, map texturing, shadow casting, none ]
21699
21718
  lights.sort( shadowCastingAndTexturingLightsFirst );
21700
21719
 
21701
- // artist-friendly light intensity scaling factor
21702
- const scaleFactor = ( useLegacyLights === true ) ? Math.PI : 1;
21703
-
21704
21720
  for ( let i = 0, l = lights.length; i < l; i ++ ) {
21705
21721
 
21706
21722
  const light = lights[ i ];
@@ -21713,9 +21729,9 @@ function WebGLLights( extensions ) {
21713
21729
 
21714
21730
  if ( light.isAmbientLight ) {
21715
21731
 
21716
- r += color.r * intensity * scaleFactor;
21717
- g += color.g * intensity * scaleFactor;
21718
- b += color.b * intensity * scaleFactor;
21732
+ r += color.r * intensity;
21733
+ g += color.g * intensity;
21734
+ b += color.b * intensity;
21719
21735
 
21720
21736
  } else if ( light.isLightProbe ) {
21721
21737
 
@@ -21731,7 +21747,7 @@ function WebGLLights( extensions ) {
21731
21747
 
21732
21748
  const uniforms = cache.get( light );
21733
21749
 
21734
- uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
21750
+ uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
21735
21751
 
21736
21752
  if ( light.castShadow ) {
21737
21753
 
@@ -21762,7 +21778,7 @@ function WebGLLights( extensions ) {
21762
21778
 
21763
21779
  uniforms.position.setFromMatrixPosition( light.matrixWorld );
21764
21780
 
21765
- uniforms.color.copy( color ).multiplyScalar( intensity * scaleFactor );
21781
+ uniforms.color.copy( color ).multiplyScalar( intensity );
21766
21782
  uniforms.distance = distance;
21767
21783
 
21768
21784
  uniforms.coneCos = Math.cos( light.angle );
@@ -21823,7 +21839,7 @@ function WebGLLights( extensions ) {
21823
21839
 
21824
21840
  const uniforms = cache.get( light );
21825
21841
 
21826
- uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
21842
+ uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
21827
21843
  uniforms.distance = light.distance;
21828
21844
  uniforms.decay = light.decay;
21829
21845
 
@@ -21856,8 +21872,8 @@ function WebGLLights( extensions ) {
21856
21872
 
21857
21873
  const uniforms = cache.get( light );
21858
21874
 
21859
- uniforms.skyColor.copy( light.color ).multiplyScalar( intensity * scaleFactor );
21860
- uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity * scaleFactor );
21875
+ uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
21876
+ uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
21861
21877
 
21862
21878
  state.hemi[ hemiLength ] = uniforms;
21863
21879
 
@@ -22058,9 +22074,9 @@ function WebGLRenderState( extensions ) {
22058
22074
 
22059
22075
  }
22060
22076
 
22061
- function setupLights( useLegacyLights ) {
22077
+ function setupLights() {
22062
22078
 
22063
- lights.setup( lightsArray, useLegacyLights );
22079
+ lights.setup( lightsArray );
22064
22080
 
22065
22081
  }
22066
22082
 
@@ -24107,6 +24123,48 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24107
24123
 
24108
24124
  }
24109
24125
 
24126
+ function getInternalDepthFormat( useStencil, depthType ) {
24127
+
24128
+ let glInternalFormat;
24129
+ if ( useStencil ) {
24130
+
24131
+ if ( depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type ) {
24132
+
24133
+ glInternalFormat = _gl.DEPTH24_STENCIL8;
24134
+
24135
+ } else if ( depthType === FloatType ) {
24136
+
24137
+ glInternalFormat = _gl.DEPTH32F_STENCIL8;
24138
+
24139
+ } else if ( depthType === UnsignedShortType ) {
24140
+
24141
+ glInternalFormat = _gl.DEPTH24_STENCIL8;
24142
+ console.warn( 'DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.' );
24143
+
24144
+ }
24145
+
24146
+ } else {
24147
+
24148
+ if ( depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type ) {
24149
+
24150
+ glInternalFormat = _gl.DEPTH_COMPONENT24;
24151
+
24152
+ } else if ( depthType === FloatType ) {
24153
+
24154
+ glInternalFormat = _gl.DEPTH_COMPONENT32F;
24155
+
24156
+ } else if ( depthType === UnsignedShortType ) {
24157
+
24158
+ glInternalFormat = _gl.DEPTH_COMPONENT16;
24159
+
24160
+ }
24161
+
24162
+ }
24163
+
24164
+ return glInternalFormat;
24165
+
24166
+ }
24167
+
24110
24168
  function getMipLevels( texture, image ) {
24111
24169
 
24112
24170
  if ( textureNeedsGenerateMipmaps( texture ) === true || ( texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) ) {
@@ -24661,23 +24719,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24661
24719
 
24662
24720
  if ( texture.isDepthTexture ) {
24663
24721
 
24664
- // populate depth texture with dummy data
24665
-
24666
- glInternalFormat = _gl.DEPTH_COMPONENT16;
24667
-
24668
- if ( texture.type === FloatType ) {
24669
-
24670
- glInternalFormat = _gl.DEPTH_COMPONENT32F;
24671
-
24672
- } else if ( texture.type === UnsignedIntType ) {
24673
-
24674
- glInternalFormat = _gl.DEPTH_COMPONENT24;
24675
-
24676
- } else if ( texture.type === UnsignedInt248Type ) {
24677
-
24678
- glInternalFormat = _gl.DEPTH24_STENCIL8;
24679
-
24680
- }
24722
+ glInternalFormat = getInternalDepthFormat( texture.format === DepthStencilFormat, texture.type );
24681
24723
 
24682
24724
  //
24683
24725
 
@@ -24777,7 +24819,22 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24777
24819
 
24778
24820
  if ( dataReady ) {
24779
24821
 
24780
- state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );
24822
+ if ( texture.layerUpdates.size > 0 ) {
24823
+
24824
+ for ( const layerIndex of texture.layerUpdates ) {
24825
+
24826
+ const layerSize = mipmap.width * mipmap.height;
24827
+ state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, mipmap.data.slice( layerSize * layerIndex, layerSize * ( layerIndex + 1 ) ), 0, 0 );
24828
+
24829
+ }
24830
+
24831
+ texture.clearLayerUpdates();
24832
+
24833
+ } else {
24834
+
24835
+ state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );
24836
+
24837
+ }
24781
24838
 
24782
24839
  }
24783
24840
 
@@ -24883,7 +24940,72 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24883
24940
 
24884
24941
  if ( dataReady ) {
24885
24942
 
24886
- state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );
24943
+ if ( texture.layerUpdates.size > 0 ) {
24944
+
24945
+ // When type is GL_UNSIGNED_BYTE, each of these bytes is
24946
+ // interpreted as one color component, depending on format. When
24947
+ // type is one of GL_UNSIGNED_SHORT_5_6_5,
24948
+ // GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_5_5_5_1, each
24949
+ // unsigned value is interpreted as containing all the components
24950
+ // for a single pixel, with the color components arranged
24951
+ // according to format.
24952
+ //
24953
+ // See https://registry.khronos.org/OpenGL-Refpages/es1.1/xhtml/glTexImage2D.xml
24954
+ let texelSize;
24955
+ switch ( glType ) {
24956
+
24957
+ case _gl.UNSIGNED_BYTE:
24958
+ switch ( glFormat ) {
24959
+
24960
+ case _gl.ALPHA:
24961
+ texelSize = 1;
24962
+ break;
24963
+ case _gl.LUMINANCE:
24964
+ texelSize = 1;
24965
+ break;
24966
+ case _gl.LUMINANCE_ALPHA:
24967
+ texelSize = 2;
24968
+ break;
24969
+ case _gl.RGB:
24970
+ texelSize = 3;
24971
+ break;
24972
+ case _gl.RGBA:
24973
+ texelSize = 4;
24974
+ break;
24975
+
24976
+ default:
24977
+ throw new Error( `Unknown texel size for format ${glFormat}.` );
24978
+
24979
+ }
24980
+
24981
+ break;
24982
+
24983
+ case _gl.UNSIGNED_SHORT_4_4_4_4:
24984
+ case _gl.UNSIGNED_SHORT_5_5_5_1:
24985
+ case _gl.UNSIGNED_SHORT_5_6_5:
24986
+ texelSize = 1;
24987
+ break;
24988
+
24989
+ default:
24990
+ throw new Error( `Unknown texel size for type ${glType}.` );
24991
+
24992
+ }
24993
+
24994
+ const layerSize = image.width * image.height * texelSize;
24995
+
24996
+ for ( const layerIndex of texture.layerUpdates ) {
24997
+
24998
+ state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, layerIndex, image.width, image.height, 1, glFormat, glType, image.data.slice( layerSize * layerIndex, layerSize * ( layerIndex + 1 ) ) );
24999
+
25000
+ }
25001
+
25002
+ texture.clearLayerUpdates();
25003
+
25004
+ } else {
25005
+
25006
+ state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );
25007
+
25008
+ }
24887
25009
 
24888
25010
  }
24889
25011
 
@@ -25327,7 +25449,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25327
25449
 
25328
25450
  }
25329
25451
 
25330
-
25331
25452
  // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
25332
25453
  function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
25333
25454
 
@@ -25387,66 +25508,30 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25387
25508
 
25388
25509
  } else if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
25389
25510
 
25390
- let glInternalFormat = _gl.DEPTH_COMPONENT24;
25391
-
25392
- if ( isMultisample || useMultisampledRTT( renderTarget ) ) {
25393
-
25394
- const depthTexture = renderTarget.depthTexture;
25395
-
25396
- if ( depthTexture && depthTexture.isDepthTexture ) {
25397
-
25398
- if ( depthTexture.type === FloatType ) {
25399
-
25400
- glInternalFormat = _gl.DEPTH_COMPONENT32F;
25401
-
25402
- } else if ( depthTexture.type === UnsignedIntType ) {
25403
-
25404
- glInternalFormat = _gl.DEPTH_COMPONENT24;
25405
-
25406
- }
25407
-
25408
- }
25409
-
25410
- const samples = getRenderTargetSamples( renderTarget );
25411
-
25412
- if ( useMultisampledRTT( renderTarget ) ) {
25413
-
25414
- multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
25415
-
25416
- } else {
25417
-
25418
- _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
25419
-
25420
- }
25421
-
25422
- } else {
25423
-
25424
- _gl.renderbufferStorage( _gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height );
25425
-
25426
- }
25427
-
25428
- _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
25429
-
25430
- } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
25511
+ // retrieve the depth attachment types
25512
+ const depthTexture = renderTarget.depthTexture;
25513
+ const depthType = depthTexture && depthTexture.isDepthTexture ? depthTexture.type : null;
25514
+ const glInternalFormat = getInternalDepthFormat( renderTarget.stencilBuffer, depthType );
25515
+ const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
25431
25516
 
25517
+ // set up the attachment
25432
25518
  const samples = getRenderTargetSamples( renderTarget );
25519
+ const isUseMultisampledRTT = useMultisampledRTT( renderTarget );
25520
+ if ( isUseMultisampledRTT ) {
25433
25521
 
25434
- if ( isMultisample && useMultisampledRTT( renderTarget ) === false ) {
25522
+ multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
25435
25523
 
25436
- _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height );
25524
+ } else if ( isMultisample ) {
25437
25525
 
25438
- } else if ( useMultisampledRTT( renderTarget ) ) {
25439
-
25440
- multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height );
25526
+ _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
25441
25527
 
25442
25528
  } else {
25443
25529
 
25444
- _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
25530
+ _gl.renderbufferStorage( _gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height );
25445
25531
 
25446
25532
  }
25447
25533
 
25448
-
25449
- _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
25534
+ _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer );
25450
25535
 
25451
25536
  } else {
25452
25537
 
@@ -27357,7 +27442,7 @@ class WebXRDepthSensing {
27357
27442
 
27358
27443
  }
27359
27444
 
27360
- render( renderer, cameraXR ) {
27445
+ getMesh( cameraXR ) {
27361
27446
 
27362
27447
  if ( this.texture !== null ) {
27363
27448
 
@@ -27378,10 +27463,10 @@ class WebXRDepthSensing {
27378
27463
 
27379
27464
  }
27380
27465
 
27381
- renderer.render( this.mesh, cameraXR );
27382
-
27383
27466
  }
27384
27467
 
27468
+ return this.mesh;
27469
+
27385
27470
  }
27386
27471
 
27387
27472
  reset() {
@@ -28105,6 +28190,12 @@ class WebXRManager extends EventDispatcher {
28105
28190
 
28106
28191
  };
28107
28192
 
28193
+ this.getDepthSensingMesh = function () {
28194
+
28195
+ return depthSensing.getMesh( cameraXR );
28196
+
28197
+ };
28198
+
28108
28199
  // Animation Loop
28109
28200
 
28110
28201
  let onAnimationFrameCallback = null;
@@ -28230,8 +28321,6 @@ class WebXRManager extends EventDispatcher {
28230
28321
 
28231
28322
  }
28232
28323
 
28233
- depthSensing.render( renderer, cameraXR );
28234
-
28235
28324
  if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
28236
28325
 
28237
28326
  if ( frame.detectedPlanes ) {
@@ -28506,11 +28595,7 @@ function WebGLMaterials( renderer, properties ) {
28506
28595
  if ( material.lightMap ) {
28507
28596
 
28508
28597
  uniforms.lightMap.value = material.lightMap;
28509
-
28510
- // artist-friendly light intensity scaling factor
28511
- const scaleFactor = ( renderer._useLegacyLights === true ) ? Math.PI : 1;
28512
-
28513
- uniforms.lightMapIntensity.value = material.lightMapIntensity * scaleFactor;
28598
+ uniforms.lightMapIntensity.value = material.lightMapIntensity;
28514
28599
 
28515
28600
  refreshTransformUniform( material.lightMap, uniforms.lightMapTransform );
28516
28601
 
@@ -29328,10 +29413,6 @@ class WebGLRenderer {
29328
29413
 
29329
29414
  this._outputColorSpace = SRGBColorSpace;
29330
29415
 
29331
- // physical lights
29332
-
29333
- this._useLegacyLights = false;
29334
-
29335
29416
  // tone mapping
29336
29417
 
29337
29418
  this.toneMapping = NoToneMapping;
@@ -29389,6 +29470,8 @@ class WebGLRenderer {
29389
29470
 
29390
29471
  const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
29391
29472
 
29473
+ let _renderBackground = false;
29474
+
29392
29475
  function getTargetPixelRatio() {
29393
29476
 
29394
29477
  return _currentRenderTarget === null ? _pixelRatio : 1;
@@ -30138,7 +30221,7 @@ class WebGLRenderer {
30138
30221
 
30139
30222
  }
30140
30223
 
30141
- currentRenderState.setupLights( _this._useLegacyLights );
30224
+ currentRenderState.setupLights();
30142
30225
 
30143
30226
  // Only initialize materials in the new scene, not the targetScene.
30144
30227
 
@@ -30328,6 +30411,18 @@ class WebGLRenderer {
30328
30411
 
30329
30412
  renderListStack.push( currentRenderList );
30330
30413
 
30414
+ if ( xr.enabled === true && xr.isPresenting === true ) {
30415
+
30416
+ const depthSensingMesh = _this.xr.getDepthSensingMesh();
30417
+
30418
+ if ( depthSensingMesh !== null ) {
30419
+
30420
+ projectObject( depthSensingMesh, camera, - Infinity, _this.sortObjects );
30421
+
30422
+ }
30423
+
30424
+ }
30425
+
30331
30426
  projectObject( scene, camera, 0, _this.sortObjects );
30332
30427
 
30333
30428
  currentRenderList.finish();
@@ -30338,8 +30433,8 @@ class WebGLRenderer {
30338
30433
 
30339
30434
  }
30340
30435
 
30341
- const renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
30342
- if ( renderBackground ) {
30436
+ _renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
30437
+ if ( _renderBackground ) {
30343
30438
 
30344
30439
  background.addToRenderList( currentRenderList, scene );
30345
30440
 
@@ -30366,7 +30461,7 @@ class WebGLRenderer {
30366
30461
  const opaqueObjects = currentRenderList.opaque;
30367
30462
  const transmissiveObjects = currentRenderList.transmissive;
30368
30463
 
30369
- currentRenderState.setupLights( _this._useLegacyLights );
30464
+ currentRenderState.setupLights();
30370
30465
 
30371
30466
  if ( camera.isArrayCamera ) {
30372
30467
 
@@ -30384,7 +30479,7 @@ class WebGLRenderer {
30384
30479
 
30385
30480
  }
30386
30481
 
30387
- if ( renderBackground ) background.render( scene );
30482
+ if ( _renderBackground ) background.render( scene );
30388
30483
 
30389
30484
  if ( xr.enabled && xr.isMultiview ) {
30390
30485
 
@@ -30408,7 +30503,7 @@ class WebGLRenderer {
30408
30503
 
30409
30504
  if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );
30410
30505
 
30411
- if ( renderBackground ) background.render( scene );
30506
+ if ( _renderBackground ) background.render( scene );
30412
30507
 
30413
30508
  renderScene( currentRenderList, scene, camera );
30414
30509
 
@@ -30632,7 +30727,8 @@ class WebGLRenderer {
30632
30727
  samples: 4,
30633
30728
  stencilBuffer: stencil,
30634
30729
  resolveDepthBuffer: false,
30635
- resolveStencilBuffer: false
30730
+ resolveStencilBuffer: false,
30731
+ colorSpace: ColorManagement.workingColorSpace,
30636
30732
  } );
30637
30733
 
30638
30734
  // debug
@@ -30661,7 +30757,15 @@ class WebGLRenderer {
30661
30757
  _currentClearAlpha = _this.getClearAlpha();
30662
30758
  if ( _currentClearAlpha < 1 ) _this.setClearColor( 0xffffff, 0.5 );
30663
30759
 
30664
- _this.clear();
30760
+ if ( _renderBackground ) {
30761
+
30762
+ background.render( scene );
30763
+
30764
+ } else {
30765
+
30766
+ _this.clear();
30767
+
30768
+ }
30665
30769
 
30666
30770
  // Turn off the features which can affect the frag color for opaque objects pass.
30667
30771
  // Otherwise they are applied twice in opaque objects pass and transmission objects pass.
@@ -30918,6 +31022,7 @@ class WebGLRenderer {
30918
31022
 
30919
31023
  materialProperties.outputColorSpace = parameters.outputColorSpace;
30920
31024
  materialProperties.batching = parameters.batching;
31025
+ materialProperties.batchingColor = parameters.batchingColor;
30921
31026
  materialProperties.instancing = parameters.instancing;
30922
31027
  materialProperties.instancingColor = parameters.instancingColor;
30923
31028
  materialProperties.instancingMorph = parameters.instancingMorph;
@@ -31010,6 +31115,14 @@ class WebGLRenderer {
31010
31115
 
31011
31116
  needsProgramChange = true;
31012
31117
 
31118
+ } else if ( object.isBatchedMesh && materialProperties.batchingColor === true && object.colorTexture === null ) {
31119
+
31120
+ needsProgramChange = true;
31121
+
31122
+ } else if ( object.isBatchedMesh && materialProperties.batchingColor === false && object.colorTexture !== null ) {
31123
+
31124
+ needsProgramChange = true;
31125
+
31013
31126
  } else if ( object.isInstancedMesh && materialProperties.instancing === false ) {
31014
31127
 
31015
31128
  needsProgramChange = true;
@@ -31215,6 +31328,13 @@ class WebGLRenderer {
31215
31328
  p_uniforms.setOptional( _gl, object, 'batchingTexture' );
31216
31329
  p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures );
31217
31330
 
31331
+ p_uniforms.setOptional( _gl, object, 'batchingColorTexture' );
31332
+ if ( object._colorsTexture !== null ) {
31333
+
31334
+ p_uniforms.setValue( _gl, 'batchingColorTexture', object._colorsTexture, textures );
31335
+
31336
+ }
31337
+
31218
31338
  }
31219
31339
 
31220
31340
  const morphAttributes = geometry.morphAttributes;
@@ -31610,24 +31730,159 @@ class WebGLRenderer {
31610
31730
 
31611
31731
  };
31612
31732
 
31613
- this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
31733
+ this.readRenderTargetPixelsAsync = async function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
31734
+
31735
+ if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
31736
+
31737
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
31738
+
31739
+ }
31740
+
31741
+ let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
31742
+ if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
31743
+
31744
+ framebuffer = framebuffer[ activeCubeFaceIndex ];
31745
+
31746
+ }
31747
+
31748
+ if ( framebuffer ) {
31749
+
31750
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
31751
+
31752
+ try {
31753
+
31754
+ const texture = renderTarget.texture;
31755
+ const textureFormat = texture.format;
31756
+ const textureType = texture.type;
31757
+
31758
+ if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
31759
+
31760
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
31761
+
31762
+ }
31763
+
31764
+ if ( ! capabilities.textureTypeReadable( textureType ) ) {
31765
+
31766
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
31767
+
31768
+ }
31769
+
31770
+ // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
31771
+ if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
31772
+
31773
+ const glBuffer = _gl.createBuffer();
31774
+ _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
31775
+ _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
31776
+ _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
31777
+ _gl.flush();
31778
+
31779
+ // check if the commands have finished every 8 ms
31780
+ const sync = _gl.fenceSync( _gl.SYNC_GPU_COMMANDS_COMPLETE, 0 );
31781
+ await probeAsync( _gl, sync, 4 );
31782
+
31783
+ try {
31784
+
31785
+ _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
31786
+ _gl.getBufferSubData( _gl.PIXEL_PACK_BUFFER, 0, buffer );
31787
+
31788
+ } finally {
31789
+
31790
+ _gl.deleteBuffer( glBuffer );
31791
+ _gl.deleteSync( sync );
31792
+
31793
+ }
31794
+
31795
+ return buffer;
31796
+
31797
+ }
31798
+
31799
+ } finally {
31800
+
31801
+ // restore framebuffer of current render target if necessary
31802
+
31803
+ const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
31804
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
31805
+
31806
+ }
31807
+
31808
+ }
31809
+
31810
+ };
31811
+
31812
+ this.copyFramebufferToTexture = function ( texture, position = null, level = 0 ) {
31813
+
31814
+ // support previous signature with position first
31815
+ if ( texture.isTexture !== true ) {
31816
+
31817
+ // @deprecated, r165
31818
+ console.warn( 'WebGLRenderer: copyFramebufferToTexture function signature has changed.' );
31819
+
31820
+ position = arguments[ 0 ] || null;
31821
+ texture = arguments[ 1 ];
31822
+
31823
+ }
31614
31824
 
31615
31825
  const levelScale = Math.pow( 2, - level );
31616
31826
  const width = Math.floor( texture.image.width * levelScale );
31617
31827
  const height = Math.floor( texture.image.height * levelScale );
31618
31828
 
31829
+ const x = position !== null ? position.x : 0;
31830
+ const y = position !== null ? position.y : 0;
31831
+
31619
31832
  textures.setTexture2D( texture, 0 );
31620
31833
 
31621
- _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height );
31834
+ _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, x, y, width, height );
31622
31835
 
31623
31836
  state.unbindTexture();
31624
31837
 
31625
31838
  };
31626
31839
 
31627
- this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) {
31840
+ this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
31841
+
31842
+ // support previous signature with dstPosition first
31843
+ if ( srcTexture.isTexture !== true ) {
31844
+
31845
+ // @deprecated, r165
31846
+ console.warn( 'WebGLRenderer: copyTextureToTexture function signature has changed.' );
31847
+
31848
+ dstPosition = arguments[ 0 ] || null;
31849
+ srcTexture = arguments[ 1 ];
31850
+ dstTexture = arguments[ 2 ];
31851
+ level = arguments[ 3 ] || 0;
31852
+ srcRegion = null;
31853
+
31854
+ }
31855
+
31856
+ let width, height, minX, minY;
31857
+ let dstX, dstY;
31858
+ if ( srcRegion !== null ) {
31859
+
31860
+ width = srcRegion.max.x - srcRegion.min.x;
31861
+ height = srcRegion.max.y - srcRegion.min.y;
31862
+ minX = srcRegion.min.x;
31863
+ minY = srcRegion.min.y;
31864
+
31865
+ } else {
31866
+
31867
+ width = srcTexture.image.width;
31868
+ height = srcTexture.image.height;
31869
+ minX = 0;
31870
+ minY = 0;
31871
+
31872
+ }
31873
+
31874
+ if ( dstPosition !== null ) {
31875
+
31876
+ dstX = dstPosition.x;
31877
+ dstY = dstPosition.y;
31878
+
31879
+ } else {
31880
+
31881
+ dstX = 0;
31882
+ dstY = 0;
31883
+
31884
+ }
31628
31885
 
31629
- const width = srcTexture.image.width;
31630
- const height = srcTexture.image.height;
31631
31886
  const glFormat = utils.convert( dstTexture.format );
31632
31887
  const glType = utils.convert( dstTexture.type );
31633
31888
 
@@ -31639,24 +31894,43 @@ class WebGLRenderer {
31639
31894
  _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
31640
31895
  _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
31641
31896
 
31897
+ const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
31898
+ const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
31899
+ const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
31900
+ const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
31901
+ const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
31902
+
31903
+ const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
31904
+
31905
+ _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
31906
+ _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
31907
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
31908
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
31909
+
31642
31910
  if ( srcTexture.isDataTexture ) {
31643
31911
 
31644
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
31912
+ _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data );
31645
31913
 
31646
31914
  } else {
31647
31915
 
31648
31916
  if ( srcTexture.isCompressedTexture ) {
31649
31917
 
31650
- _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
31918
+ _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data );
31651
31919
 
31652
31920
  } else {
31653
31921
 
31654
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );
31922
+ _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, glFormat, glType, image );
31655
31923
 
31656
31924
  }
31657
31925
 
31658
31926
  }
31659
31927
 
31928
+ _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
31929
+ _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
31930
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
31931
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
31932
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
31933
+
31660
31934
  // Generate mipmaps only when copying level 0
31661
31935
  if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D );
31662
31936
 
@@ -31664,11 +31938,59 @@ class WebGLRenderer {
31664
31938
 
31665
31939
  };
31666
31940
 
31667
- this.copyTextureToTexture3D = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) {
31941
+ this.copyTextureToTexture3D = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
31942
+
31943
+ // support previous signature with source box first
31944
+ if ( srcTexture.isTexture !== true ) {
31945
+
31946
+ // @deprecated, r165
31947
+ console.warn( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' );
31948
+
31949
+ srcRegion = arguments[ 0 ] || null;
31950
+ dstPosition = arguments[ 1 ] || null;
31951
+ srcTexture = arguments[ 2 ];
31952
+ dstTexture = arguments[ 3 ];
31953
+ level = arguments[ 4 ] || 0;
31954
+
31955
+ }
31956
+
31957
+ let width, height, depth, minX, minY, minZ;
31958
+ let dstX, dstY, dstZ;
31959
+ const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
31960
+ if ( srcRegion !== null ) {
31961
+
31962
+ width = srcRegion.max.x - srcRegion.min.x;
31963
+ height = srcRegion.max.y - srcRegion.min.y;
31964
+ depth = srcRegion.max.z - srcRegion.min.z;
31965
+ minX = srcRegion.min.x;
31966
+ minY = srcRegion.min.y;
31967
+ minZ = srcRegion.min.z;
31968
+
31969
+ } else {
31970
+
31971
+ width = image.width;
31972
+ height = image.height;
31973
+ depth = image.depth;
31974
+ minX = 0;
31975
+ minY = 0;
31976
+ minZ = 0;
31977
+
31978
+ }
31979
+
31980
+ if ( dstPosition !== null ) {
31981
+
31982
+ dstX = dstPosition.x;
31983
+ dstY = dstPosition.y;
31984
+ dstZ = dstPosition.z;
31985
+
31986
+ } else {
31987
+
31988
+ dstX = 0;
31989
+ dstY = 0;
31990
+ dstZ = 0;
31991
+
31992
+ }
31668
31993
 
31669
- const width = sourceBox.max.x - sourceBox.min.x;
31670
- const height = sourceBox.max.y - sourceBox.min.y;
31671
- const depth = sourceBox.max.z - sourceBox.min.z;
31672
31994
  const glFormat = utils.convert( dstTexture.format );
31673
31995
  const glType = utils.convert( dstTexture.type );
31674
31996
  let glTarget;
@@ -31694,43 +32016,41 @@ class WebGLRenderer {
31694
32016
  _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
31695
32017
  _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
31696
32018
 
31697
- const unpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
31698
- const unpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
31699
- const unpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
31700
- const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
31701
- const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
31702
-
31703
- const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
32019
+ const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
32020
+ const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
32021
+ const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
32022
+ const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
32023
+ const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
31704
32024
 
31705
32025
  _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
31706
32026
  _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
31707
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, sourceBox.min.x );
31708
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y );
31709
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z );
32027
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
32028
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
32029
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
31710
32030
 
31711
32031
  if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
31712
32032
 
31713
- _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data );
32033
+ _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
31714
32034
 
31715
32035
  } else {
31716
32036
 
31717
32037
  if ( dstTexture.isCompressedArrayTexture ) {
31718
32038
 
31719
- _gl.compressedTexSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data );
32039
+ _gl.compressedTexSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
31720
32040
 
31721
32041
  } else {
31722
32042
 
31723
- _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image );
32043
+ _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
31724
32044
 
31725
32045
  }
31726
32046
 
31727
32047
  }
31728
32048
 
31729
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen );
31730
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight );
31731
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, unpackSkipPixels );
31732
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, unpackSkipRows );
31733
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, unpackSkipImages );
32049
+ _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
32050
+ _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
32051
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
32052
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
32053
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
31734
32054
 
31735
32055
  // Generate mipmaps only when copying level 0
31736
32056
  if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget );
@@ -31739,6 +32059,16 @@ class WebGLRenderer {
31739
32059
 
31740
32060
  };
31741
32061
 
32062
+ this.initRenderTarget = function ( target ) {
32063
+
32064
+ if ( properties.get( target ).__webglFramebuffer === undefined ) {
32065
+
32066
+ textures.setupRenderTarget( target );
32067
+
32068
+ }
32069
+
32070
+ };
32071
+
31742
32072
  this.initTexture = function ( texture ) {
31743
32073
 
31744
32074
  if ( texture.isCubeTexture ) {
@@ -31804,20 +32134,6 @@ class WebGLRenderer {
31804
32134
 
31805
32135
  }
31806
32136
 
31807
- get useLegacyLights() { // @deprecated, r155
31808
-
31809
- console.warn( 'THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.' );
31810
- return this._useLegacyLights;
31811
-
31812
- }
31813
-
31814
- set useLegacyLights( value ) { // @deprecated, r155
31815
-
31816
- console.warn( 'THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.' );
31817
- this._useLegacyLights = value;
31818
-
31819
- }
31820
-
31821
32137
  }
31822
32138
 
31823
32139
  class FogExp2 {
@@ -33806,11 +34122,14 @@ const ID_ATTR_NAME = 'batchId';
33806
34122
  const _matrix$1 = /*@__PURE__*/ new Matrix4();
33807
34123
  const _invMatrixWorld = /*@__PURE__*/ new Matrix4();
33808
34124
  const _identityMatrix = /*@__PURE__*/ new Matrix4();
34125
+ const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
33809
34126
  const _projScreenMatrix$2 = /*@__PURE__*/ new Matrix4();
33810
34127
  const _frustum = /*@__PURE__*/ new Frustum();
33811
34128
  const _box$1 = /*@__PURE__*/ new Box3();
33812
34129
  const _sphere$2 = /*@__PURE__*/ new Sphere();
33813
34130
  const _vector$5 = /*@__PURE__*/ new Vector3();
34131
+ const _forward = /*@__PURE__*/ new Vector3();
34132
+ const _temp = /*@__PURE__*/ new Vector3();
33814
34133
  const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
33815
34134
  const _mesh = /*@__PURE__*/ new Mesh();
33816
34135
  const _batchIntersects = [];
@@ -33895,6 +34214,9 @@ class BatchedMesh extends Mesh {
33895
34214
 
33896
34215
  this._initMatricesTexture();
33897
34216
 
34217
+ // Local color per geometry by using data texture
34218
+ this._colorsTexture = null;
34219
+
33898
34220
  }
33899
34221
 
33900
34222
  _initMatricesTexture() {
@@ -33917,6 +34239,20 @@ class BatchedMesh extends Mesh {
33917
34239
 
33918
34240
  }
33919
34241
 
34242
+ _initColorsTexture() {
34243
+
34244
+ let size = Math.sqrt( this._maxGeometryCount );
34245
+ size = Math.ceil( size );
34246
+
34247
+ // 4 floats per RGBA pixel initialized to white
34248
+ const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
34249
+ const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
34250
+ colorsTexture.colorSpace = ColorManagement.workingColorSpace;
34251
+
34252
+ this._colorsTexture = colorsTexture;
34253
+
34254
+ }
34255
+
33920
34256
  _initializeGeometry( reference ) {
33921
34257
 
33922
34258
  const geometry = this.geometry;
@@ -34150,6 +34486,7 @@ class BatchedMesh extends Mesh {
34150
34486
  const active = this._active;
34151
34487
  const matricesTexture = this._matricesTexture;
34152
34488
  const matricesArray = this._matricesTexture.image.data;
34489
+ const colorsTexture = this._colorsTexture;
34153
34490
 
34154
34491
  // push new visibility states
34155
34492
  visibility.push( true );
@@ -34163,6 +34500,14 @@ class BatchedMesh extends Mesh {
34163
34500
  _identityMatrix.toArray( matricesArray, geometryId * 16 );
34164
34501
  matricesTexture.needsUpdate = true;
34165
34502
 
34503
+ // initialize the color to white
34504
+ if ( colorsTexture !== null ) {
34505
+
34506
+ _whiteColor.toArray( colorsTexture.image.data, geometryId * 4 );
34507
+ colorsTexture.needsUpdate = true;
34508
+
34509
+ }
34510
+
34166
34511
  // add the reserved range and draw range objects
34167
34512
  reservedRanges.push( reservedRange );
34168
34513
  drawRanges.push( {
@@ -34481,6 +34826,49 @@ class BatchedMesh extends Mesh {
34481
34826
 
34482
34827
  }
34483
34828
 
34829
+ setColorAt( geometryId, color ) {
34830
+
34831
+ if ( this._colorsTexture === null ) {
34832
+
34833
+ this._initColorsTexture();
34834
+
34835
+ }
34836
+
34837
+ // @TODO: Map geometryId to index of the arrays because
34838
+ // optimize() can make geometryId mismatch the index
34839
+
34840
+ const active = this._active;
34841
+ const colorsTexture = this._colorsTexture;
34842
+ const colorsArray = this._colorsTexture.image.data;
34843
+ const geometryCount = this._geometryCount;
34844
+ if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
34845
+
34846
+ return this;
34847
+
34848
+ }
34849
+
34850
+ color.toArray( colorsArray, geometryId * 4 );
34851
+ colorsTexture.needsUpdate = true;
34852
+
34853
+ return this;
34854
+
34855
+ }
34856
+
34857
+ getColorAt( geometryId, color ) {
34858
+
34859
+ const active = this._active;
34860
+ const colorsArray = this._colorsTexture.image.data;
34861
+ const geometryCount = this._geometryCount;
34862
+ if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
34863
+
34864
+ return null;
34865
+
34866
+ }
34867
+
34868
+ return color.fromArray( colorsArray, geometryId * 4 );
34869
+
34870
+ }
34871
+
34484
34872
  setVisibleAt( geometryId, value ) {
34485
34873
 
34486
34874
  const visibility = this._visibility;
@@ -34621,6 +35009,13 @@ class BatchedMesh extends Mesh {
34621
35009
  this._matricesTexture = source._matricesTexture.clone();
34622
35010
  this._matricesTexture.image.data = this._matricesTexture.image.slice();
34623
35011
 
35012
+ if ( this._colorsTexture !== null ) {
35013
+
35014
+ this._colorsTexture = source._colorsTexture.clone();
35015
+ this._colorsTexture.image.data = this._colorsTexture.image.slice();
35016
+
35017
+ }
35018
+
34624
35019
  return this;
34625
35020
 
34626
35021
  }
@@ -34632,6 +35027,14 @@ class BatchedMesh extends Mesh {
34632
35027
 
34633
35028
  this._matricesTexture.dispose();
34634
35029
  this._matricesTexture = null;
35030
+
35031
+ if ( this._colorsTexture !== null ) {
35032
+
35033
+ this._colorsTexture.dispose();
35034
+ this._colorsTexture = null;
35035
+
35036
+ }
35037
+
34635
35038
  return this;
34636
35039
 
34637
35040
  }
@@ -34677,6 +35080,7 @@ class BatchedMesh extends Mesh {
34677
35080
  // get the camera position in the local frame
34678
35081
  _invMatrixWorld.copy( this.matrixWorld ).invert();
34679
35082
  _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _invMatrixWorld );
35083
+ _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _invMatrixWorld );
34680
35084
 
34681
35085
  for ( let i = 0, l = visibility.length; i < l; i ++ ) {
34682
35086
 
@@ -34697,7 +35101,7 @@ class BatchedMesh extends Mesh {
34697
35101
  if ( ! culled ) {
34698
35102
 
34699
35103
  // get the distance from camera used for sorting
34700
- const z = _vector$5.distanceTo( _sphere$2.center );
35104
+ const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
34701
35105
  _renderList.push( drawRanges[ i ], z );
34702
35106
 
34703
35107
  }
@@ -35427,6 +35831,20 @@ class CompressedArrayTexture extends CompressedTexture {
35427
35831
  this.image.depth = depth;
35428
35832
  this.wrapR = ClampToEdgeWrapping;
35429
35833
 
35834
+ this.layerUpdates = new Set();
35835
+
35836
+ }
35837
+
35838
+ addLayerUpdates( layerIndex ) {
35839
+
35840
+ this.layerUpdates.add( layerIndex );
35841
+
35842
+ }
35843
+
35844
+ clearLayerUpdates() {
35845
+
35846
+ this.layerUpdates.clear();
35847
+
35430
35848
  }
35431
35849
 
35432
35850
  }
@@ -43591,7 +44009,16 @@ KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
43591
44009
  /**
43592
44010
  * A Track of Boolean keyframe values.
43593
44011
  */
43594
- class BooleanKeyframeTrack extends KeyframeTrack {}
44012
+ class BooleanKeyframeTrack extends KeyframeTrack {
44013
+
44014
+ // No interpolation parameter because only InterpolateDiscrete is valid.
44015
+ constructor( name, times, values ) {
44016
+
44017
+ super( name, times, values );
44018
+
44019
+ }
44020
+
44021
+ }
43595
44022
 
43596
44023
  BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
43597
44024
  BooleanKeyframeTrack.prototype.ValueBufferType = Array;
@@ -43662,13 +44089,22 @@ class QuaternionKeyframeTrack extends KeyframeTrack {
43662
44089
 
43663
44090
  QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
43664
44091
  // ValueBufferType is inherited
43665
- QuaternionKeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
44092
+ // DefaultInterpolation is inherited;
43666
44093
  QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
43667
44094
 
43668
44095
  /**
43669
44096
  * A Track that interpolates Strings
43670
44097
  */
43671
- class StringKeyframeTrack extends KeyframeTrack {}
44098
+ class StringKeyframeTrack extends KeyframeTrack {
44099
+
44100
+ // No interpolation parameter because only InterpolateDiscrete is valid.
44101
+ constructor( name, times, values ) {
44102
+
44103
+ super( name, times, values );
44104
+
44105
+ }
44106
+
44107
+ }
43672
44108
 
43673
44109
  StringKeyframeTrack.prototype.ValueTypeName = 'string';
43674
44110
  StringKeyframeTrack.prototype.ValueBufferType = Array;
@@ -44541,6 +44977,10 @@ class FileLoader extends Loader {
44541
44977
 
44542
44978
  }
44543
44979
 
44980
+ }, ( e ) => {
44981
+
44982
+ controller.error( e );
44983
+
44544
44984
  } );
44545
44985
 
44546
44986
  }
@@ -46376,7 +46816,9 @@ class MaterialLoader extends Loader {
46376
46816
 
46377
46817
  class LoaderUtils {
46378
46818
 
46379
- static decodeText( array ) {
46819
+ static decodeText( array ) { // @deprecated, r165
46820
+
46821
+ console.warn( 'THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.' );
46380
46822
 
46381
46823
  if ( typeof TextDecoder !== 'undefined' ) {
46382
46824
 
@@ -47587,6 +48029,7 @@ class ObjectLoader extends Loader {
47587
48029
  object._geometryCount = data.geometryCount;
47588
48030
 
47589
48031
  object._matricesTexture = getTexture( data.matricesTexture.uuid );
48032
+ if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );
47590
48033
 
47591
48034
  break;
47592
48035
 
@@ -52049,13 +52492,17 @@ function ascSort( a, b ) {
52049
52492
 
52050
52493
  function intersect( object, raycaster, intersects, recursive ) {
52051
52494
 
52495
+ let propagate = true;
52496
+
52052
52497
  if ( object.layers.test( raycaster.layers ) ) {
52053
52498
 
52054
- object.raycast( raycaster, intersects );
52499
+ const result = object.raycast( raycaster, intersects );
52500
+
52501
+ if ( result === false ) propagate = false;
52055
52502
 
52056
52503
  }
52057
52504
 
52058
- if ( recursive === true ) {
52505
+ if ( propagate === true && recursive === true ) {
52059
52506
 
52060
52507
  const children = object.children;
52061
52508