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
package/build/three.cjs CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const REVISION = '164';
8
+ const REVISION = '165';
9
9
 
10
10
  const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
11
11
  const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
@@ -1562,6 +1562,35 @@ function warnOnce( message ) {
1562
1562
 
1563
1563
  }
1564
1564
 
1565
+ function probeAsync( gl, sync, interval ) {
1566
+
1567
+ return new Promise( function ( resolve, reject ) {
1568
+
1569
+ function probe() {
1570
+
1571
+ switch ( gl.clientWaitSync( sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0 ) ) {
1572
+
1573
+ case gl.WAIT_FAILED:
1574
+ reject();
1575
+ break;
1576
+
1577
+ case gl.TIMEOUT_EXPIRED:
1578
+ setTimeout( probe, interval );
1579
+ break;
1580
+
1581
+ default:
1582
+ resolve();
1583
+
1584
+ }
1585
+
1586
+ }
1587
+
1588
+ setTimeout( probe, interval );
1589
+
1590
+ } );
1591
+
1592
+ }
1593
+
1565
1594
  /**
1566
1595
  * Matrices converting P3 <-> Rec. 709 primaries, without gamut mapping
1567
1596
  * or clipping. Based on W3C specifications for sRGB and Display P3,
@@ -3079,6 +3108,20 @@ class DataArrayTexture extends Texture {
3079
3108
  this.flipY = false;
3080
3109
  this.unpackAlignment = 1;
3081
3110
 
3111
+ this.layerUpdates = new Set();
3112
+
3113
+ }
3114
+
3115
+ addLayerUpdate( layerIndex ) {
3116
+
3117
+ this.layerUpdates.add( layerIndex );
3118
+
3119
+ }
3120
+
3121
+ clearLayerUpdates() {
3122
+
3123
+ this.layerUpdates.clear();
3124
+
3082
3125
  }
3083
3126
 
3084
3127
  }
@@ -7848,6 +7891,8 @@ class Object3D extends EventDispatcher {
7848
7891
 
7849
7892
  object.matricesTexture = this._matricesTexture.toJSON( meta );
7850
7893
 
7894
+ if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );
7895
+
7851
7896
  if ( this.boundingSphere !== null ) {
7852
7897
 
7853
7898
  object.boundingSphere = {
@@ -13760,7 +13805,7 @@ var aomap_fragment = "#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D(
13760
13805
 
13761
13806
  var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
13762
13807
 
13763
- 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";
13808
+ 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";
13764
13809
 
13765
13810
  var batching_vertex = "#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( batchId );\n#endif";
13766
13811
 
@@ -13786,9 +13831,9 @@ var color_fragment = "#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\
13786
13831
 
13787
13832
  var color_pars_fragment = "#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif";
13788
13833
 
13789
- 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";
13834
+ 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";
13790
13835
 
13791
- 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";
13836
+ 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";
13792
13837
 
13793
13838
  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";
13794
13839
 
@@ -13834,7 +13879,7 @@ var lights_lambert_fragment = "LambertMaterial material;\nmaterial.diffuseColor
13834
13879
 
13835
13880
  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";
13836
13881
 
13837
- 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";
13882
+ 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";
13838
13883
 
13839
13884
  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";
13840
13885
 
@@ -13876,15 +13921,15 @@ var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_META
13876
13921
 
13877
13922
  var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
13878
13923
 
13879
- 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";
13924
+ 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";
13880
13925
 
13881
- 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";
13926
+ 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";
13882
13927
 
13883
- 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";
13928
+ 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";
13884
13929
 
13885
- 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";
13930
+ 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";
13886
13931
 
13887
- 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";
13932
+ 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";
13888
13933
 
13889
13934
  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;";
13890
13935
 
@@ -14809,6 +14854,12 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
14809
14854
 
14810
14855
  if ( renderer.autoClear || forceClear ) {
14811
14856
 
14857
+ // buffers might not be writable which is required to ensure a correct clear
14858
+
14859
+ state.buffers.depth.setTest( true );
14860
+ state.buffers.depth.setMask( true );
14861
+ state.buffers.color.setMask( true );
14862
+
14812
14863
  renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
14813
14864
 
14814
14865
  }
@@ -17322,7 +17373,7 @@ function WebGLExtensions( gl ) {
17322
17373
 
17323
17374
  if ( extension === null ) {
17324
17375
 
17325
- console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
17376
+ warnOnce( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
17326
17377
 
17327
17378
  }
17328
17379
 
@@ -17732,8 +17783,7 @@ function WebGLMorphtargets( gl, capabilities, textures ) {
17732
17783
 
17733
17784
  const objectInfluences = object.morphTargetInfluences;
17734
17785
 
17735
- // instead of using attributes, the WebGL 2 code path encodes morph targets
17736
- // into an array of data textures. Each layer represents a single morph target.
17786
+ // the following encodes morph targets into an array of data textures. Each layer represents a single morph target.
17737
17787
 
17738
17788
  const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color;
17739
17789
  const morphTargetsCount = ( morphAttribute !== undefined ) ? morphAttribute.length : 0;
@@ -18074,9 +18124,7 @@ function WebGLObjects( gl, geometries, attributes, info ) {
18074
18124
 
18075
18125
  class DepthTexture extends Texture {
18076
18126
 
18077
- constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
18078
-
18079
- format = format !== undefined ? format : DepthFormat;
18127
+ constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat ) {
18080
18128
 
18081
18129
  if ( format !== DepthFormat && format !== DepthStencilFormat ) {
18082
18130
 
@@ -19806,6 +19854,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
19806
19854
 
19807
19855
  parameters.extensionClipCullDistance ? '#define USE_CLIP_DISTANCE' : '',
19808
19856
  parameters.batching ? '#define USE_BATCHING' : '',
19857
+ parameters.batchingColor ? '#define USE_BATCHING_COLOR' : '',
19809
19858
  parameters.instancing ? '#define USE_INSTANCING' : '',
19810
19859
  parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',
19811
19860
  parameters.instancingMorph ? '#define USE_INSTANCING_MORPH' : '',
@@ -19902,7 +19951,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
19902
19951
  parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
19903
19952
  parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
19904
19953
  ( parameters.morphColors ) ? '#define USE_MORPHCOLORS' : '',
19905
- ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_TEXTURE' : '',
19906
19954
  ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_TEXTURE_STRIDE ' + parameters.morphTextureStride : '',
19907
19955
  ( parameters.morphTargetsCount > 0 ) ? '#define MORPHTARGETS_COUNT ' + parameters.morphTargetsCount : '',
19908
19956
  parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
@@ -19915,8 +19963,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
19915
19963
 
19916
19964
  parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
19917
19965
 
19918
- parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
19919
-
19920
19966
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
19921
19967
 
19922
19968
  'uniform mat4 modelMatrix;',
@@ -19983,31 +20029,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
19983
20029
 
19984
20030
  '#endif',
19985
20031
 
19986
- '#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )',
19987
-
19988
- ' attribute vec3 morphTarget0;',
19989
- ' attribute vec3 morphTarget1;',
19990
- ' attribute vec3 morphTarget2;',
19991
- ' attribute vec3 morphTarget3;',
19992
-
19993
- ' #ifdef USE_MORPHNORMALS',
19994
-
19995
- ' attribute vec3 morphNormal0;',
19996
- ' attribute vec3 morphNormal1;',
19997
- ' attribute vec3 morphNormal2;',
19998
- ' attribute vec3 morphNormal3;',
19999
-
20000
- ' #else',
20001
-
20002
- ' attribute vec3 morphTarget4;',
20003
- ' attribute vec3 morphTarget5;',
20004
- ' attribute vec3 morphTarget6;',
20005
- ' attribute vec3 morphTarget7;',
20006
-
20007
- ' #endif',
20008
-
20009
- '#endif',
20010
-
20011
20032
  '#ifdef USE_SKINNING',
20012
20033
 
20013
20034
  ' attribute vec4 skinIndex;',
@@ -20083,7 +20104,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
20083
20104
  parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',
20084
20105
 
20085
20106
  parameters.vertexTangents && parameters.flatShading === false ? '#define USE_TANGENT' : '',
20086
- parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
20107
+ parameters.vertexColors || parameters.instancingColor || parameters.batchingColor ? '#define USE_COLOR' : '',
20087
20108
  parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',
20088
20109
  parameters.vertexUv1s ? '#define USE_UV1' : '',
20089
20110
  parameters.vertexUv2s ? '#define USE_UV2' : '',
@@ -20105,8 +20126,6 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
20105
20126
 
20106
20127
  parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
20107
20128
 
20108
- parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
20109
-
20110
20129
  parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
20111
20130
 
20112
20131
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
@@ -20729,6 +20748,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
20729
20748
  precision: precision,
20730
20749
 
20731
20750
  batching: IS_BATCHEDMESH,
20751
+ batchingColor: IS_BATCHEDMESH && object._colorsTexture !== null,
20732
20752
  instancing: IS_INSTANCEDMESH,
20733
20753
  instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null,
20734
20754
  instancingMorph: IS_INSTANCEDMESH && object.morphTexture !== null,
@@ -20874,7 +20894,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
20874
20894
  shadowMapType: renderer.shadowMap.type,
20875
20895
 
20876
20896
  toneMapping: toneMapping,
20877
- useLegacyLights: renderer._useLegacyLights,
20878
20897
 
20879
20898
  decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ),
20880
20899
 
@@ -21048,6 +21067,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
21048
21067
  _programLayers.enable( 19 );
21049
21068
  if ( parameters.dispersion )
21050
21069
  _programLayers.enable( 20 );
21070
+ if ( parameters.batchingColor )
21071
+ _programLayers.enable( 21 );
21051
21072
 
21052
21073
  array.push( _programLayers.mask );
21053
21074
  _programLayers.disableAll();
@@ -21072,30 +21093,28 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
21072
21093
  _programLayers.enable( 8 );
21073
21094
  if ( parameters.shadowMapEnabled )
21074
21095
  _programLayers.enable( 9 );
21075
- if ( parameters.useLegacyLights )
21076
- _programLayers.enable( 10 );
21077
21096
  if ( parameters.doubleSided )
21078
- _programLayers.enable( 11 );
21097
+ _programLayers.enable( 10 );
21079
21098
  if ( parameters.flipSided )
21080
- _programLayers.enable( 12 );
21099
+ _programLayers.enable( 11 );
21081
21100
  if ( parameters.useDepthPacking )
21082
- _programLayers.enable( 13 );
21101
+ _programLayers.enable( 12 );
21083
21102
  if ( parameters.dithering )
21084
- _programLayers.enable( 14 );
21103
+ _programLayers.enable( 13 );
21085
21104
  if ( parameters.transmission )
21086
- _programLayers.enable( 15 );
21105
+ _programLayers.enable( 14 );
21087
21106
  if ( parameters.sheen )
21088
- _programLayers.enable( 16 );
21107
+ _programLayers.enable( 15 );
21089
21108
  if ( parameters.opaque )
21090
- _programLayers.enable( 17 );
21109
+ _programLayers.enable( 16 );
21091
21110
  if ( parameters.pointsUvs )
21092
- _programLayers.enable( 18 );
21111
+ _programLayers.enable( 17 );
21093
21112
  if ( parameters.decodeVideoTexture )
21094
- _programLayers.enable( 19 );
21113
+ _programLayers.enable( 18 );
21095
21114
  if ( parameters.alphaToCoverage )
21096
- _programLayers.enable( 20 );
21115
+ _programLayers.enable( 19 );
21097
21116
  if ( parameters.numMultiviewViews )
21098
- _programLayers.enable( 21 );
21117
+ _programLayers.enable( 20 );
21099
21118
 
21100
21119
  array.push( _programLayers.mask );
21101
21120
 
@@ -21677,7 +21696,7 @@ function WebGLLights( extensions ) {
21677
21696
  const matrix4 = new Matrix4();
21678
21697
  const matrix42 = new Matrix4();
21679
21698
 
21680
- function setup( lights, useLegacyLights ) {
21699
+ function setup( lights ) {
21681
21700
 
21682
21701
  let r = 0, g = 0, b = 0;
21683
21702
 
@@ -21700,9 +21719,6 @@ function WebGLLights( extensions ) {
21700
21719
  // ordering : [shadow casting + map texturing, map texturing, shadow casting, none ]
21701
21720
  lights.sort( shadowCastingAndTexturingLightsFirst );
21702
21721
 
21703
- // artist-friendly light intensity scaling factor
21704
- const scaleFactor = ( useLegacyLights === true ) ? Math.PI : 1;
21705
-
21706
21722
  for ( let i = 0, l = lights.length; i < l; i ++ ) {
21707
21723
 
21708
21724
  const light = lights[ i ];
@@ -21715,9 +21731,9 @@ function WebGLLights( extensions ) {
21715
21731
 
21716
21732
  if ( light.isAmbientLight ) {
21717
21733
 
21718
- r += color.r * intensity * scaleFactor;
21719
- g += color.g * intensity * scaleFactor;
21720
- b += color.b * intensity * scaleFactor;
21734
+ r += color.r * intensity;
21735
+ g += color.g * intensity;
21736
+ b += color.b * intensity;
21721
21737
 
21722
21738
  } else if ( light.isLightProbe ) {
21723
21739
 
@@ -21733,7 +21749,7 @@ function WebGLLights( extensions ) {
21733
21749
 
21734
21750
  const uniforms = cache.get( light );
21735
21751
 
21736
- uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
21752
+ uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
21737
21753
 
21738
21754
  if ( light.castShadow ) {
21739
21755
 
@@ -21764,7 +21780,7 @@ function WebGLLights( extensions ) {
21764
21780
 
21765
21781
  uniforms.position.setFromMatrixPosition( light.matrixWorld );
21766
21782
 
21767
- uniforms.color.copy( color ).multiplyScalar( intensity * scaleFactor );
21783
+ uniforms.color.copy( color ).multiplyScalar( intensity );
21768
21784
  uniforms.distance = distance;
21769
21785
 
21770
21786
  uniforms.coneCos = Math.cos( light.angle );
@@ -21825,7 +21841,7 @@ function WebGLLights( extensions ) {
21825
21841
 
21826
21842
  const uniforms = cache.get( light );
21827
21843
 
21828
- uniforms.color.copy( light.color ).multiplyScalar( light.intensity * scaleFactor );
21844
+ uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
21829
21845
  uniforms.distance = light.distance;
21830
21846
  uniforms.decay = light.decay;
21831
21847
 
@@ -21858,8 +21874,8 @@ function WebGLLights( extensions ) {
21858
21874
 
21859
21875
  const uniforms = cache.get( light );
21860
21876
 
21861
- uniforms.skyColor.copy( light.color ).multiplyScalar( intensity * scaleFactor );
21862
- uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity * scaleFactor );
21877
+ uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
21878
+ uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
21863
21879
 
21864
21880
  state.hemi[ hemiLength ] = uniforms;
21865
21881
 
@@ -22060,9 +22076,9 @@ function WebGLRenderState( extensions ) {
22060
22076
 
22061
22077
  }
22062
22078
 
22063
- function setupLights( useLegacyLights ) {
22079
+ function setupLights() {
22064
22080
 
22065
- lights.setup( lightsArray, useLegacyLights );
22081
+ lights.setup( lightsArray );
22066
22082
 
22067
22083
  }
22068
22084
 
@@ -24109,6 +24125,48 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24109
24125
 
24110
24126
  }
24111
24127
 
24128
+ function getInternalDepthFormat( useStencil, depthType ) {
24129
+
24130
+ let glInternalFormat;
24131
+ if ( useStencil ) {
24132
+
24133
+ if ( depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type ) {
24134
+
24135
+ glInternalFormat = _gl.DEPTH24_STENCIL8;
24136
+
24137
+ } else if ( depthType === FloatType ) {
24138
+
24139
+ glInternalFormat = _gl.DEPTH32F_STENCIL8;
24140
+
24141
+ } else if ( depthType === UnsignedShortType ) {
24142
+
24143
+ glInternalFormat = _gl.DEPTH24_STENCIL8;
24144
+ console.warn( 'DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.' );
24145
+
24146
+ }
24147
+
24148
+ } else {
24149
+
24150
+ if ( depthType === null || depthType === UnsignedIntType || depthType === UnsignedInt248Type ) {
24151
+
24152
+ glInternalFormat = _gl.DEPTH_COMPONENT24;
24153
+
24154
+ } else if ( depthType === FloatType ) {
24155
+
24156
+ glInternalFormat = _gl.DEPTH_COMPONENT32F;
24157
+
24158
+ } else if ( depthType === UnsignedShortType ) {
24159
+
24160
+ glInternalFormat = _gl.DEPTH_COMPONENT16;
24161
+
24162
+ }
24163
+
24164
+ }
24165
+
24166
+ return glInternalFormat;
24167
+
24168
+ }
24169
+
24112
24170
  function getMipLevels( texture, image ) {
24113
24171
 
24114
24172
  if ( textureNeedsGenerateMipmaps( texture ) === true || ( texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) ) {
@@ -24663,23 +24721,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24663
24721
 
24664
24722
  if ( texture.isDepthTexture ) {
24665
24723
 
24666
- // populate depth texture with dummy data
24667
-
24668
- glInternalFormat = _gl.DEPTH_COMPONENT16;
24669
-
24670
- if ( texture.type === FloatType ) {
24671
-
24672
- glInternalFormat = _gl.DEPTH_COMPONENT32F;
24673
-
24674
- } else if ( texture.type === UnsignedIntType ) {
24675
-
24676
- glInternalFormat = _gl.DEPTH_COMPONENT24;
24677
-
24678
- } else if ( texture.type === UnsignedInt248Type ) {
24679
-
24680
- glInternalFormat = _gl.DEPTH24_STENCIL8;
24681
-
24682
- }
24724
+ glInternalFormat = getInternalDepthFormat( texture.format === DepthStencilFormat, texture.type );
24683
24725
 
24684
24726
  //
24685
24727
 
@@ -24779,7 +24821,22 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24779
24821
 
24780
24822
  if ( dataReady ) {
24781
24823
 
24782
- state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );
24824
+ if ( texture.layerUpdates.size > 0 ) {
24825
+
24826
+ for ( const layerIndex of texture.layerUpdates ) {
24827
+
24828
+ const layerSize = mipmap.width * mipmap.height;
24829
+ 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 );
24830
+
24831
+ }
24832
+
24833
+ texture.clearLayerUpdates();
24834
+
24835
+ } else {
24836
+
24837
+ state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );
24838
+
24839
+ }
24783
24840
 
24784
24841
  }
24785
24842
 
@@ -24885,7 +24942,72 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24885
24942
 
24886
24943
  if ( dataReady ) {
24887
24944
 
24888
- state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );
24945
+ if ( texture.layerUpdates.size > 0 ) {
24946
+
24947
+ // When type is GL_UNSIGNED_BYTE, each of these bytes is
24948
+ // interpreted as one color component, depending on format. When
24949
+ // type is one of GL_UNSIGNED_SHORT_5_6_5,
24950
+ // GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_5_5_5_1, each
24951
+ // unsigned value is interpreted as containing all the components
24952
+ // for a single pixel, with the color components arranged
24953
+ // according to format.
24954
+ //
24955
+ // See https://registry.khronos.org/OpenGL-Refpages/es1.1/xhtml/glTexImage2D.xml
24956
+ let texelSize;
24957
+ switch ( glType ) {
24958
+
24959
+ case _gl.UNSIGNED_BYTE:
24960
+ switch ( glFormat ) {
24961
+
24962
+ case _gl.ALPHA:
24963
+ texelSize = 1;
24964
+ break;
24965
+ case _gl.LUMINANCE:
24966
+ texelSize = 1;
24967
+ break;
24968
+ case _gl.LUMINANCE_ALPHA:
24969
+ texelSize = 2;
24970
+ break;
24971
+ case _gl.RGB:
24972
+ texelSize = 3;
24973
+ break;
24974
+ case _gl.RGBA:
24975
+ texelSize = 4;
24976
+ break;
24977
+
24978
+ default:
24979
+ throw new Error( `Unknown texel size for format ${glFormat}.` );
24980
+
24981
+ }
24982
+
24983
+ break;
24984
+
24985
+ case _gl.UNSIGNED_SHORT_4_4_4_4:
24986
+ case _gl.UNSIGNED_SHORT_5_5_5_1:
24987
+ case _gl.UNSIGNED_SHORT_5_6_5:
24988
+ texelSize = 1;
24989
+ break;
24990
+
24991
+ default:
24992
+ throw new Error( `Unknown texel size for type ${glType}.` );
24993
+
24994
+ }
24995
+
24996
+ const layerSize = image.width * image.height * texelSize;
24997
+
24998
+ for ( const layerIndex of texture.layerUpdates ) {
24999
+
25000
+ 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 ) ) );
25001
+
25002
+ }
25003
+
25004
+ texture.clearLayerUpdates();
25005
+
25006
+ } else {
25007
+
25008
+ state.texSubImage3D( _gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data );
25009
+
25010
+ }
24889
25011
 
24890
25012
  }
24891
25013
 
@@ -25329,7 +25451,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25329
25451
 
25330
25452
  }
25331
25453
 
25332
-
25333
25454
  // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
25334
25455
  function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
25335
25456
 
@@ -25389,66 +25510,30 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25389
25510
 
25390
25511
  } else if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
25391
25512
 
25392
- let glInternalFormat = _gl.DEPTH_COMPONENT24;
25393
-
25394
- if ( isMultisample || useMultisampledRTT( renderTarget ) ) {
25395
-
25396
- const depthTexture = renderTarget.depthTexture;
25397
-
25398
- if ( depthTexture && depthTexture.isDepthTexture ) {
25399
-
25400
- if ( depthTexture.type === FloatType ) {
25401
-
25402
- glInternalFormat = _gl.DEPTH_COMPONENT32F;
25403
-
25404
- } else if ( depthTexture.type === UnsignedIntType ) {
25405
-
25406
- glInternalFormat = _gl.DEPTH_COMPONENT24;
25407
-
25408
- }
25409
-
25410
- }
25411
-
25412
- const samples = getRenderTargetSamples( renderTarget );
25413
-
25414
- if ( useMultisampledRTT( renderTarget ) ) {
25415
-
25416
- multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
25417
-
25418
- } else {
25419
-
25420
- _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
25421
-
25422
- }
25423
-
25424
- } else {
25425
-
25426
- _gl.renderbufferStorage( _gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height );
25427
-
25428
- }
25429
-
25430
- _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
25431
-
25432
- } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
25513
+ // retrieve the depth attachment types
25514
+ const depthTexture = renderTarget.depthTexture;
25515
+ const depthType = depthTexture && depthTexture.isDepthTexture ? depthTexture.type : null;
25516
+ const glInternalFormat = getInternalDepthFormat( renderTarget.stencilBuffer, depthType );
25517
+ const glAttachmentType = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT;
25433
25518
 
25519
+ // set up the attachment
25434
25520
  const samples = getRenderTargetSamples( renderTarget );
25521
+ const isUseMultisampledRTT = useMultisampledRTT( renderTarget );
25522
+ if ( isUseMultisampledRTT ) {
25435
25523
 
25436
- if ( isMultisample && useMultisampledRTT( renderTarget ) === false ) {
25524
+ multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
25437
25525
 
25438
- _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height );
25526
+ } else if ( isMultisample ) {
25439
25527
 
25440
- } else if ( useMultisampledRTT( renderTarget ) ) {
25441
-
25442
- multisampledRTTExt.renderbufferStorageMultisampleEXT( _gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height );
25528
+ _gl.renderbufferStorageMultisample( _gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height );
25443
25529
 
25444
25530
  } else {
25445
25531
 
25446
- _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
25532
+ _gl.renderbufferStorage( _gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height );
25447
25533
 
25448
25534
  }
25449
25535
 
25450
-
25451
- _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
25536
+ _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, glAttachmentType, _gl.RENDERBUFFER, renderbuffer );
25452
25537
 
25453
25538
  } else {
25454
25539
 
@@ -27359,7 +27444,7 @@ class WebXRDepthSensing {
27359
27444
 
27360
27445
  }
27361
27446
 
27362
- render( renderer, cameraXR ) {
27447
+ getMesh( cameraXR ) {
27363
27448
 
27364
27449
  if ( this.texture !== null ) {
27365
27450
 
@@ -27380,10 +27465,10 @@ class WebXRDepthSensing {
27380
27465
 
27381
27466
  }
27382
27467
 
27383
- renderer.render( this.mesh, cameraXR );
27384
-
27385
27468
  }
27386
27469
 
27470
+ return this.mesh;
27471
+
27387
27472
  }
27388
27473
 
27389
27474
  reset() {
@@ -28107,6 +28192,12 @@ class WebXRManager extends EventDispatcher {
28107
28192
 
28108
28193
  };
28109
28194
 
28195
+ this.getDepthSensingMesh = function () {
28196
+
28197
+ return depthSensing.getMesh( cameraXR );
28198
+
28199
+ };
28200
+
28110
28201
  // Animation Loop
28111
28202
 
28112
28203
  let onAnimationFrameCallback = null;
@@ -28232,8 +28323,6 @@ class WebXRManager extends EventDispatcher {
28232
28323
 
28233
28324
  }
28234
28325
 
28235
- depthSensing.render( renderer, cameraXR );
28236
-
28237
28326
  if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
28238
28327
 
28239
28328
  if ( frame.detectedPlanes ) {
@@ -28508,11 +28597,7 @@ function WebGLMaterials( renderer, properties ) {
28508
28597
  if ( material.lightMap ) {
28509
28598
 
28510
28599
  uniforms.lightMap.value = material.lightMap;
28511
-
28512
- // artist-friendly light intensity scaling factor
28513
- const scaleFactor = ( renderer._useLegacyLights === true ) ? Math.PI : 1;
28514
-
28515
- uniforms.lightMapIntensity.value = material.lightMapIntensity * scaleFactor;
28600
+ uniforms.lightMapIntensity.value = material.lightMapIntensity;
28516
28601
 
28517
28602
  refreshTransformUniform( material.lightMap, uniforms.lightMapTransform );
28518
28603
 
@@ -29330,10 +29415,6 @@ class WebGLRenderer {
29330
29415
 
29331
29416
  this._outputColorSpace = SRGBColorSpace;
29332
29417
 
29333
- // physical lights
29334
-
29335
- this._useLegacyLights = false;
29336
-
29337
29418
  // tone mapping
29338
29419
 
29339
29420
  this.toneMapping = NoToneMapping;
@@ -29391,6 +29472,8 @@ class WebGLRenderer {
29391
29472
 
29392
29473
  const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
29393
29474
 
29475
+ let _renderBackground = false;
29476
+
29394
29477
  function getTargetPixelRatio() {
29395
29478
 
29396
29479
  return _currentRenderTarget === null ? _pixelRatio : 1;
@@ -30140,7 +30223,7 @@ class WebGLRenderer {
30140
30223
 
30141
30224
  }
30142
30225
 
30143
- currentRenderState.setupLights( _this._useLegacyLights );
30226
+ currentRenderState.setupLights();
30144
30227
 
30145
30228
  // Only initialize materials in the new scene, not the targetScene.
30146
30229
 
@@ -30330,6 +30413,18 @@ class WebGLRenderer {
30330
30413
 
30331
30414
  renderListStack.push( currentRenderList );
30332
30415
 
30416
+ if ( xr.enabled === true && xr.isPresenting === true ) {
30417
+
30418
+ const depthSensingMesh = _this.xr.getDepthSensingMesh();
30419
+
30420
+ if ( depthSensingMesh !== null ) {
30421
+
30422
+ projectObject( depthSensingMesh, camera, - Infinity, _this.sortObjects );
30423
+
30424
+ }
30425
+
30426
+ }
30427
+
30333
30428
  projectObject( scene, camera, 0, _this.sortObjects );
30334
30429
 
30335
30430
  currentRenderList.finish();
@@ -30340,8 +30435,8 @@ class WebGLRenderer {
30340
30435
 
30341
30436
  }
30342
30437
 
30343
- const renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
30344
- if ( renderBackground ) {
30438
+ _renderBackground = xr.enabled === false || xr.isPresenting === false || xr.hasDepthSensing() === false;
30439
+ if ( _renderBackground ) {
30345
30440
 
30346
30441
  background.addToRenderList( currentRenderList, scene );
30347
30442
 
@@ -30368,7 +30463,7 @@ class WebGLRenderer {
30368
30463
  const opaqueObjects = currentRenderList.opaque;
30369
30464
  const transmissiveObjects = currentRenderList.transmissive;
30370
30465
 
30371
- currentRenderState.setupLights( _this._useLegacyLights );
30466
+ currentRenderState.setupLights();
30372
30467
 
30373
30468
  if ( camera.isArrayCamera ) {
30374
30469
 
@@ -30386,7 +30481,7 @@ class WebGLRenderer {
30386
30481
 
30387
30482
  }
30388
30483
 
30389
- if ( renderBackground ) background.render( scene );
30484
+ if ( _renderBackground ) background.render( scene );
30390
30485
 
30391
30486
  if ( xr.enabled && xr.isMultiview ) {
30392
30487
 
@@ -30410,7 +30505,7 @@ class WebGLRenderer {
30410
30505
 
30411
30506
  if ( transmissiveObjects.length > 0 ) renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera );
30412
30507
 
30413
- if ( renderBackground ) background.render( scene );
30508
+ if ( _renderBackground ) background.render( scene );
30414
30509
 
30415
30510
  renderScene( currentRenderList, scene, camera );
30416
30511
 
@@ -30634,7 +30729,8 @@ class WebGLRenderer {
30634
30729
  samples: 4,
30635
30730
  stencilBuffer: stencil,
30636
30731
  resolveDepthBuffer: false,
30637
- resolveStencilBuffer: false
30732
+ resolveStencilBuffer: false,
30733
+ colorSpace: ColorManagement.workingColorSpace,
30638
30734
  } );
30639
30735
 
30640
30736
  // debug
@@ -30663,7 +30759,15 @@ class WebGLRenderer {
30663
30759
  _currentClearAlpha = _this.getClearAlpha();
30664
30760
  if ( _currentClearAlpha < 1 ) _this.setClearColor( 0xffffff, 0.5 );
30665
30761
 
30666
- _this.clear();
30762
+ if ( _renderBackground ) {
30763
+
30764
+ background.render( scene );
30765
+
30766
+ } else {
30767
+
30768
+ _this.clear();
30769
+
30770
+ }
30667
30771
 
30668
30772
  // Turn off the features which can affect the frag color for opaque objects pass.
30669
30773
  // Otherwise they are applied twice in opaque objects pass and transmission objects pass.
@@ -30920,6 +31024,7 @@ class WebGLRenderer {
30920
31024
 
30921
31025
  materialProperties.outputColorSpace = parameters.outputColorSpace;
30922
31026
  materialProperties.batching = parameters.batching;
31027
+ materialProperties.batchingColor = parameters.batchingColor;
30923
31028
  materialProperties.instancing = parameters.instancing;
30924
31029
  materialProperties.instancingColor = parameters.instancingColor;
30925
31030
  materialProperties.instancingMorph = parameters.instancingMorph;
@@ -31012,6 +31117,14 @@ class WebGLRenderer {
31012
31117
 
31013
31118
  needsProgramChange = true;
31014
31119
 
31120
+ } else if ( object.isBatchedMesh && materialProperties.batchingColor === true && object.colorTexture === null ) {
31121
+
31122
+ needsProgramChange = true;
31123
+
31124
+ } else if ( object.isBatchedMesh && materialProperties.batchingColor === false && object.colorTexture !== null ) {
31125
+
31126
+ needsProgramChange = true;
31127
+
31015
31128
  } else if ( object.isInstancedMesh && materialProperties.instancing === false ) {
31016
31129
 
31017
31130
  needsProgramChange = true;
@@ -31217,6 +31330,13 @@ class WebGLRenderer {
31217
31330
  p_uniforms.setOptional( _gl, object, 'batchingTexture' );
31218
31331
  p_uniforms.setValue( _gl, 'batchingTexture', object._matricesTexture, textures );
31219
31332
 
31333
+ p_uniforms.setOptional( _gl, object, 'batchingColorTexture' );
31334
+ if ( object._colorsTexture !== null ) {
31335
+
31336
+ p_uniforms.setValue( _gl, 'batchingColorTexture', object._colorsTexture, textures );
31337
+
31338
+ }
31339
+
31220
31340
  }
31221
31341
 
31222
31342
  const morphAttributes = geometry.morphAttributes;
@@ -31612,24 +31732,159 @@ class WebGLRenderer {
31612
31732
 
31613
31733
  };
31614
31734
 
31615
- this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
31735
+ this.readRenderTargetPixelsAsync = async function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
31736
+
31737
+ if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
31738
+
31739
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
31740
+
31741
+ }
31742
+
31743
+ let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
31744
+ if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
31745
+
31746
+ framebuffer = framebuffer[ activeCubeFaceIndex ];
31747
+
31748
+ }
31749
+
31750
+ if ( framebuffer ) {
31751
+
31752
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
31753
+
31754
+ try {
31755
+
31756
+ const texture = renderTarget.texture;
31757
+ const textureFormat = texture.format;
31758
+ const textureType = texture.type;
31759
+
31760
+ if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
31761
+
31762
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
31763
+
31764
+ }
31765
+
31766
+ if ( ! capabilities.textureTypeReadable( textureType ) ) {
31767
+
31768
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
31769
+
31770
+ }
31771
+
31772
+ // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
31773
+ if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
31774
+
31775
+ const glBuffer = _gl.createBuffer();
31776
+ _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
31777
+ _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
31778
+ _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
31779
+ _gl.flush();
31780
+
31781
+ // check if the commands have finished every 8 ms
31782
+ const sync = _gl.fenceSync( _gl.SYNC_GPU_COMMANDS_COMPLETE, 0 );
31783
+ await probeAsync( _gl, sync, 4 );
31784
+
31785
+ try {
31786
+
31787
+ _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
31788
+ _gl.getBufferSubData( _gl.PIXEL_PACK_BUFFER, 0, buffer );
31789
+
31790
+ } finally {
31791
+
31792
+ _gl.deleteBuffer( glBuffer );
31793
+ _gl.deleteSync( sync );
31794
+
31795
+ }
31796
+
31797
+ return buffer;
31798
+
31799
+ }
31800
+
31801
+ } finally {
31802
+
31803
+ // restore framebuffer of current render target if necessary
31804
+
31805
+ const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
31806
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
31807
+
31808
+ }
31809
+
31810
+ }
31811
+
31812
+ };
31813
+
31814
+ this.copyFramebufferToTexture = function ( texture, position = null, level = 0 ) {
31815
+
31816
+ // support previous signature with position first
31817
+ if ( texture.isTexture !== true ) {
31818
+
31819
+ // @deprecated, r165
31820
+ console.warn( 'WebGLRenderer: copyFramebufferToTexture function signature has changed.' );
31821
+
31822
+ position = arguments[ 0 ] || null;
31823
+ texture = arguments[ 1 ];
31824
+
31825
+ }
31616
31826
 
31617
31827
  const levelScale = Math.pow( 2, - level );
31618
31828
  const width = Math.floor( texture.image.width * levelScale );
31619
31829
  const height = Math.floor( texture.image.height * levelScale );
31620
31830
 
31831
+ const x = position !== null ? position.x : 0;
31832
+ const y = position !== null ? position.y : 0;
31833
+
31621
31834
  textures.setTexture2D( texture, 0 );
31622
31835
 
31623
- _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height );
31836
+ _gl.copyTexSubImage2D( _gl.TEXTURE_2D, level, 0, 0, x, y, width, height );
31624
31837
 
31625
31838
  state.unbindTexture();
31626
31839
 
31627
31840
  };
31628
31841
 
31629
- this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) {
31842
+ this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
31843
+
31844
+ // support previous signature with dstPosition first
31845
+ if ( srcTexture.isTexture !== true ) {
31846
+
31847
+ // @deprecated, r165
31848
+ console.warn( 'WebGLRenderer: copyTextureToTexture function signature has changed.' );
31849
+
31850
+ dstPosition = arguments[ 0 ] || null;
31851
+ srcTexture = arguments[ 1 ];
31852
+ dstTexture = arguments[ 2 ];
31853
+ level = arguments[ 3 ] || 0;
31854
+ srcRegion = null;
31855
+
31856
+ }
31857
+
31858
+ let width, height, minX, minY;
31859
+ let dstX, dstY;
31860
+ if ( srcRegion !== null ) {
31861
+
31862
+ width = srcRegion.max.x - srcRegion.min.x;
31863
+ height = srcRegion.max.y - srcRegion.min.y;
31864
+ minX = srcRegion.min.x;
31865
+ minY = srcRegion.min.y;
31866
+
31867
+ } else {
31868
+
31869
+ width = srcTexture.image.width;
31870
+ height = srcTexture.image.height;
31871
+ minX = 0;
31872
+ minY = 0;
31873
+
31874
+ }
31875
+
31876
+ if ( dstPosition !== null ) {
31877
+
31878
+ dstX = dstPosition.x;
31879
+ dstY = dstPosition.y;
31880
+
31881
+ } else {
31882
+
31883
+ dstX = 0;
31884
+ dstY = 0;
31885
+
31886
+ }
31630
31887
 
31631
- const width = srcTexture.image.width;
31632
- const height = srcTexture.image.height;
31633
31888
  const glFormat = utils.convert( dstTexture.format );
31634
31889
  const glType = utils.convert( dstTexture.type );
31635
31890
 
@@ -31641,24 +31896,43 @@ class WebGLRenderer {
31641
31896
  _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
31642
31897
  _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
31643
31898
 
31899
+ const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
31900
+ const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
31901
+ const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
31902
+ const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
31903
+ const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
31904
+
31905
+ const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
31906
+
31907
+ _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
31908
+ _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
31909
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
31910
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
31911
+
31644
31912
  if ( srcTexture.isDataTexture ) {
31645
31913
 
31646
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
31914
+ _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data );
31647
31915
 
31648
31916
  } else {
31649
31917
 
31650
31918
  if ( srcTexture.isCompressedTexture ) {
31651
31919
 
31652
- _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
31920
+ _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data );
31653
31921
 
31654
31922
  } else {
31655
31923
 
31656
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );
31924
+ _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, glFormat, glType, image );
31657
31925
 
31658
31926
  }
31659
31927
 
31660
31928
  }
31661
31929
 
31930
+ _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
31931
+ _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
31932
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
31933
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
31934
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
31935
+
31662
31936
  // Generate mipmaps only when copying level 0
31663
31937
  if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D );
31664
31938
 
@@ -31666,11 +31940,59 @@ class WebGLRenderer {
31666
31940
 
31667
31941
  };
31668
31942
 
31669
- this.copyTextureToTexture3D = function ( sourceBox, position, srcTexture, dstTexture, level = 0 ) {
31943
+ this.copyTextureToTexture3D = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
31944
+
31945
+ // support previous signature with source box first
31946
+ if ( srcTexture.isTexture !== true ) {
31947
+
31948
+ // @deprecated, r165
31949
+ console.warn( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' );
31950
+
31951
+ srcRegion = arguments[ 0 ] || null;
31952
+ dstPosition = arguments[ 1 ] || null;
31953
+ srcTexture = arguments[ 2 ];
31954
+ dstTexture = arguments[ 3 ];
31955
+ level = arguments[ 4 ] || 0;
31956
+
31957
+ }
31958
+
31959
+ let width, height, depth, minX, minY, minZ;
31960
+ let dstX, dstY, dstZ;
31961
+ const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
31962
+ if ( srcRegion !== null ) {
31963
+
31964
+ width = srcRegion.max.x - srcRegion.min.x;
31965
+ height = srcRegion.max.y - srcRegion.min.y;
31966
+ depth = srcRegion.max.z - srcRegion.min.z;
31967
+ minX = srcRegion.min.x;
31968
+ minY = srcRegion.min.y;
31969
+ minZ = srcRegion.min.z;
31970
+
31971
+ } else {
31972
+
31973
+ width = image.width;
31974
+ height = image.height;
31975
+ depth = image.depth;
31976
+ minX = 0;
31977
+ minY = 0;
31978
+ minZ = 0;
31979
+
31980
+ }
31981
+
31982
+ if ( dstPosition !== null ) {
31983
+
31984
+ dstX = dstPosition.x;
31985
+ dstY = dstPosition.y;
31986
+ dstZ = dstPosition.z;
31987
+
31988
+ } else {
31989
+
31990
+ dstX = 0;
31991
+ dstY = 0;
31992
+ dstZ = 0;
31993
+
31994
+ }
31670
31995
 
31671
- const width = sourceBox.max.x - sourceBox.min.x;
31672
- const height = sourceBox.max.y - sourceBox.min.y;
31673
- const depth = sourceBox.max.z - sourceBox.min.z;
31674
31996
  const glFormat = utils.convert( dstTexture.format );
31675
31997
  const glType = utils.convert( dstTexture.type );
31676
31998
  let glTarget;
@@ -31696,43 +32018,41 @@ class WebGLRenderer {
31696
32018
  _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
31697
32019
  _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
31698
32020
 
31699
- const unpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
31700
- const unpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
31701
- const unpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
31702
- const unpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
31703
- const unpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
31704
-
31705
- const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
32021
+ const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
32022
+ const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
32023
+ const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
32024
+ const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
32025
+ const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
31706
32026
 
31707
32027
  _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
31708
32028
  _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
31709
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, sourceBox.min.x );
31710
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y );
31711
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z );
32029
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
32030
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
32031
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
31712
32032
 
31713
32033
  if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
31714
32034
 
31715
- _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data );
32035
+ _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
31716
32036
 
31717
32037
  } else {
31718
32038
 
31719
32039
  if ( dstTexture.isCompressedArrayTexture ) {
31720
32040
 
31721
- _gl.compressedTexSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data );
32041
+ _gl.compressedTexSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
31722
32042
 
31723
32043
  } else {
31724
32044
 
31725
- _gl.texSubImage3D( glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image );
32045
+ _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
31726
32046
 
31727
32047
  }
31728
32048
 
31729
32049
  }
31730
32050
 
31731
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, unpackRowLen );
31732
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight );
31733
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, unpackSkipPixels );
31734
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, unpackSkipRows );
31735
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, unpackSkipImages );
32051
+ _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
32052
+ _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
32053
+ _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
32054
+ _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
32055
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
31736
32056
 
31737
32057
  // Generate mipmaps only when copying level 0
31738
32058
  if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget );
@@ -31741,6 +32061,16 @@ class WebGLRenderer {
31741
32061
 
31742
32062
  };
31743
32063
 
32064
+ this.initRenderTarget = function ( target ) {
32065
+
32066
+ if ( properties.get( target ).__webglFramebuffer === undefined ) {
32067
+
32068
+ textures.setupRenderTarget( target );
32069
+
32070
+ }
32071
+
32072
+ };
32073
+
31744
32074
  this.initTexture = function ( texture ) {
31745
32075
 
31746
32076
  if ( texture.isCubeTexture ) {
@@ -31806,20 +32136,6 @@ class WebGLRenderer {
31806
32136
 
31807
32137
  }
31808
32138
 
31809
- get useLegacyLights() { // @deprecated, r155
31810
-
31811
- 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.' );
31812
- return this._useLegacyLights;
31813
-
31814
- }
31815
-
31816
- set useLegacyLights( value ) { // @deprecated, r155
31817
-
31818
- 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.' );
31819
- this._useLegacyLights = value;
31820
-
31821
- }
31822
-
31823
32139
  }
31824
32140
 
31825
32141
  class FogExp2 {
@@ -33808,11 +34124,14 @@ const ID_ATTR_NAME = 'batchId';
33808
34124
  const _matrix$1 = /*@__PURE__*/ new Matrix4();
33809
34125
  const _invMatrixWorld = /*@__PURE__*/ new Matrix4();
33810
34126
  const _identityMatrix = /*@__PURE__*/ new Matrix4();
34127
+ const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
33811
34128
  const _projScreenMatrix$2 = /*@__PURE__*/ new Matrix4();
33812
34129
  const _frustum = /*@__PURE__*/ new Frustum();
33813
34130
  const _box$1 = /*@__PURE__*/ new Box3();
33814
34131
  const _sphere$2 = /*@__PURE__*/ new Sphere();
33815
34132
  const _vector$5 = /*@__PURE__*/ new Vector3();
34133
+ const _forward = /*@__PURE__*/ new Vector3();
34134
+ const _temp = /*@__PURE__*/ new Vector3();
33816
34135
  const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
33817
34136
  const _mesh = /*@__PURE__*/ new Mesh();
33818
34137
  const _batchIntersects = [];
@@ -33897,6 +34216,9 @@ class BatchedMesh extends Mesh {
33897
34216
 
33898
34217
  this._initMatricesTexture();
33899
34218
 
34219
+ // Local color per geometry by using data texture
34220
+ this._colorsTexture = null;
34221
+
33900
34222
  }
33901
34223
 
33902
34224
  _initMatricesTexture() {
@@ -33919,6 +34241,20 @@ class BatchedMesh extends Mesh {
33919
34241
 
33920
34242
  }
33921
34243
 
34244
+ _initColorsTexture() {
34245
+
34246
+ let size = Math.sqrt( this._maxGeometryCount );
34247
+ size = Math.ceil( size );
34248
+
34249
+ // 4 floats per RGBA pixel initialized to white
34250
+ const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
34251
+ const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
34252
+ colorsTexture.colorSpace = ColorManagement.workingColorSpace;
34253
+
34254
+ this._colorsTexture = colorsTexture;
34255
+
34256
+ }
34257
+
33922
34258
  _initializeGeometry( reference ) {
33923
34259
 
33924
34260
  const geometry = this.geometry;
@@ -34152,6 +34488,7 @@ class BatchedMesh extends Mesh {
34152
34488
  const active = this._active;
34153
34489
  const matricesTexture = this._matricesTexture;
34154
34490
  const matricesArray = this._matricesTexture.image.data;
34491
+ const colorsTexture = this._colorsTexture;
34155
34492
 
34156
34493
  // push new visibility states
34157
34494
  visibility.push( true );
@@ -34165,6 +34502,14 @@ class BatchedMesh extends Mesh {
34165
34502
  _identityMatrix.toArray( matricesArray, geometryId * 16 );
34166
34503
  matricesTexture.needsUpdate = true;
34167
34504
 
34505
+ // initialize the color to white
34506
+ if ( colorsTexture !== null ) {
34507
+
34508
+ _whiteColor.toArray( colorsTexture.image.data, geometryId * 4 );
34509
+ colorsTexture.needsUpdate = true;
34510
+
34511
+ }
34512
+
34168
34513
  // add the reserved range and draw range objects
34169
34514
  reservedRanges.push( reservedRange );
34170
34515
  drawRanges.push( {
@@ -34483,6 +34828,49 @@ class BatchedMesh extends Mesh {
34483
34828
 
34484
34829
  }
34485
34830
 
34831
+ setColorAt( geometryId, color ) {
34832
+
34833
+ if ( this._colorsTexture === null ) {
34834
+
34835
+ this._initColorsTexture();
34836
+
34837
+ }
34838
+
34839
+ // @TODO: Map geometryId to index of the arrays because
34840
+ // optimize() can make geometryId mismatch the index
34841
+
34842
+ const active = this._active;
34843
+ const colorsTexture = this._colorsTexture;
34844
+ const colorsArray = this._colorsTexture.image.data;
34845
+ const geometryCount = this._geometryCount;
34846
+ if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
34847
+
34848
+ return this;
34849
+
34850
+ }
34851
+
34852
+ color.toArray( colorsArray, geometryId * 4 );
34853
+ colorsTexture.needsUpdate = true;
34854
+
34855
+ return this;
34856
+
34857
+ }
34858
+
34859
+ getColorAt( geometryId, color ) {
34860
+
34861
+ const active = this._active;
34862
+ const colorsArray = this._colorsTexture.image.data;
34863
+ const geometryCount = this._geometryCount;
34864
+ if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
34865
+
34866
+ return null;
34867
+
34868
+ }
34869
+
34870
+ return color.fromArray( colorsArray, geometryId * 4 );
34871
+
34872
+ }
34873
+
34486
34874
  setVisibleAt( geometryId, value ) {
34487
34875
 
34488
34876
  const visibility = this._visibility;
@@ -34623,6 +35011,13 @@ class BatchedMesh extends Mesh {
34623
35011
  this._matricesTexture = source._matricesTexture.clone();
34624
35012
  this._matricesTexture.image.data = this._matricesTexture.image.slice();
34625
35013
 
35014
+ if ( this._colorsTexture !== null ) {
35015
+
35016
+ this._colorsTexture = source._colorsTexture.clone();
35017
+ this._colorsTexture.image.data = this._colorsTexture.image.slice();
35018
+
35019
+ }
35020
+
34626
35021
  return this;
34627
35022
 
34628
35023
  }
@@ -34634,6 +35029,14 @@ class BatchedMesh extends Mesh {
34634
35029
 
34635
35030
  this._matricesTexture.dispose();
34636
35031
  this._matricesTexture = null;
35032
+
35033
+ if ( this._colorsTexture !== null ) {
35034
+
35035
+ this._colorsTexture.dispose();
35036
+ this._colorsTexture = null;
35037
+
35038
+ }
35039
+
34637
35040
  return this;
34638
35041
 
34639
35042
  }
@@ -34679,6 +35082,7 @@ class BatchedMesh extends Mesh {
34679
35082
  // get the camera position in the local frame
34680
35083
  _invMatrixWorld.copy( this.matrixWorld ).invert();
34681
35084
  _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _invMatrixWorld );
35085
+ _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _invMatrixWorld );
34682
35086
 
34683
35087
  for ( let i = 0, l = visibility.length; i < l; i ++ ) {
34684
35088
 
@@ -34699,7 +35103,7 @@ class BatchedMesh extends Mesh {
34699
35103
  if ( ! culled ) {
34700
35104
 
34701
35105
  // get the distance from camera used for sorting
34702
- const z = _vector$5.distanceTo( _sphere$2.center );
35106
+ const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
34703
35107
  _renderList.push( drawRanges[ i ], z );
34704
35108
 
34705
35109
  }
@@ -35429,6 +35833,20 @@ class CompressedArrayTexture extends CompressedTexture {
35429
35833
  this.image.depth = depth;
35430
35834
  this.wrapR = ClampToEdgeWrapping;
35431
35835
 
35836
+ this.layerUpdates = new Set();
35837
+
35838
+ }
35839
+
35840
+ addLayerUpdates( layerIndex ) {
35841
+
35842
+ this.layerUpdates.add( layerIndex );
35843
+
35844
+ }
35845
+
35846
+ clearLayerUpdates() {
35847
+
35848
+ this.layerUpdates.clear();
35849
+
35432
35850
  }
35433
35851
 
35434
35852
  }
@@ -43593,7 +44011,16 @@ KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
43593
44011
  /**
43594
44012
  * A Track of Boolean keyframe values.
43595
44013
  */
43596
- class BooleanKeyframeTrack extends KeyframeTrack {}
44014
+ class BooleanKeyframeTrack extends KeyframeTrack {
44015
+
44016
+ // No interpolation parameter because only InterpolateDiscrete is valid.
44017
+ constructor( name, times, values ) {
44018
+
44019
+ super( name, times, values );
44020
+
44021
+ }
44022
+
44023
+ }
43597
44024
 
43598
44025
  BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
43599
44026
  BooleanKeyframeTrack.prototype.ValueBufferType = Array;
@@ -43664,13 +44091,22 @@ class QuaternionKeyframeTrack extends KeyframeTrack {
43664
44091
 
43665
44092
  QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
43666
44093
  // ValueBufferType is inherited
43667
- QuaternionKeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
44094
+ // DefaultInterpolation is inherited;
43668
44095
  QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
43669
44096
 
43670
44097
  /**
43671
44098
  * A Track that interpolates Strings
43672
44099
  */
43673
- class StringKeyframeTrack extends KeyframeTrack {}
44100
+ class StringKeyframeTrack extends KeyframeTrack {
44101
+
44102
+ // No interpolation parameter because only InterpolateDiscrete is valid.
44103
+ constructor( name, times, values ) {
44104
+
44105
+ super( name, times, values );
44106
+
44107
+ }
44108
+
44109
+ }
43674
44110
 
43675
44111
  StringKeyframeTrack.prototype.ValueTypeName = 'string';
43676
44112
  StringKeyframeTrack.prototype.ValueBufferType = Array;
@@ -44543,6 +44979,10 @@ class FileLoader extends Loader {
44543
44979
 
44544
44980
  }
44545
44981
 
44982
+ }, ( e ) => {
44983
+
44984
+ controller.error( e );
44985
+
44546
44986
  } );
44547
44987
 
44548
44988
  }
@@ -46378,7 +46818,9 @@ class MaterialLoader extends Loader {
46378
46818
 
46379
46819
  class LoaderUtils {
46380
46820
 
46381
- static decodeText( array ) {
46821
+ static decodeText( array ) { // @deprecated, r165
46822
+
46823
+ console.warn( 'THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.' );
46382
46824
 
46383
46825
  if ( typeof TextDecoder !== 'undefined' ) {
46384
46826
 
@@ -47589,6 +48031,7 @@ class ObjectLoader extends Loader {
47589
48031
  object._geometryCount = data.geometryCount;
47590
48032
 
47591
48033
  object._matricesTexture = getTexture( data.matricesTexture.uuid );
48034
+ if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );
47592
48035
 
47593
48036
  break;
47594
48037
 
@@ -52051,13 +52494,17 @@ function ascSort( a, b ) {
52051
52494
 
52052
52495
  function intersect( object, raycaster, intersects, recursive ) {
52053
52496
 
52497
+ let propagate = true;
52498
+
52054
52499
  if ( object.layers.test( raycaster.layers ) ) {
52055
52500
 
52056
- object.raycast( raycaster, intersects );
52501
+ const result = object.raycast( raycaster, intersects );
52502
+
52503
+ if ( result === false ) propagate = false;
52057
52504
 
52058
52505
  }
52059
52506
 
52060
- if ( recursive === true ) {
52507
+ if ( propagate === true && recursive === true ) {
52061
52508
 
52062
52509
  const children = object.children;
52063
52510