super-three 0.169.1 → 0.170.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 (193) hide show
  1. package/build/three.cjs +974 -562
  2. package/build/three.module.js +975 -559
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +8398 -9842
  5. package/build/three.webgpu.min.js +1 -1
  6. package/build/three.webgpu.nodes.js +8398 -9842
  7. package/build/three.webgpu.nodes.min.js +1 -1
  8. package/examples/jsm/Addons.js +3 -3
  9. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  10. package/examples/jsm/animation/MMDPhysics.js +2 -0
  11. package/examples/jsm/controls/TransformControls.js +22 -6
  12. package/examples/jsm/csm/CSM.js +2 -2
  13. package/examples/jsm/csm/CSMFrustum.js +7 -4
  14. package/examples/jsm/csm/CSMHelper.js +2 -0
  15. package/examples/jsm/csm/CSMShadowNode.js +435 -0
  16. package/examples/jsm/curves/NURBSCurve.js +34 -3
  17. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  18. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  19. package/examples/jsm/exporters/MMDExporter.js +6 -0
  20. package/examples/jsm/exporters/USDZExporter.js +21 -3
  21. package/examples/jsm/geometries/DecalGeometry.js +65 -20
  22. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  23. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  24. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  25. package/examples/jsm/lighting/TiledLighting.js +18 -0
  26. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  27. package/examples/jsm/lines/LineMaterial.js +7 -2
  28. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  29. package/examples/jsm/lines/webgpu/LineSegments2.js +0 -15
  30. package/examples/jsm/lines/webgpu/Wireframe.js +56 -0
  31. package/examples/jsm/loaders/3DMLoader.js +1 -0
  32. package/examples/jsm/loaders/3MFLoader.js +91 -0
  33. package/examples/jsm/loaders/FBXLoader.js +12 -2
  34. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  35. package/examples/jsm/loaders/KTX2Loader.js +140 -49
  36. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  37. package/examples/jsm/loaders/LottieLoader.js +1 -0
  38. package/examples/jsm/loaders/MMDLoader.js +9 -2
  39. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  40. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  41. package/examples/jsm/materials/MeshGouraudMaterial.js +6 -2
  42. package/examples/jsm/math/ColorSpaces.js +76 -0
  43. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  44. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  45. package/examples/jsm/misc/VolumeSlice.js +1 -0
  46. package/examples/jsm/objects/WaterMesh.js +8 -8
  47. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  48. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  49. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  50. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  51. package/examples/jsm/shaders/FXAAShader.js +225 -224
  52. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  53. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +17 -20
  54. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  55. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  56. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  57. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +11 -40
  58. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +18 -41
  59. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +2 -8
  60. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  61. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  62. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +2 -6
  63. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +30 -70
  64. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +74 -36
  65. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  66. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +1 -4
  67. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  68. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  69. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +1 -5
  70. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +3 -15
  71. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +1 -6
  72. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  73. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  74. package/examples/jsm/tsl/display/SSRNode.js +343 -0
  75. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  76. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +3 -11
  77. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  78. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  79. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  80. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +1 -6
  81. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +392 -0
  83. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  84. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  85. package/examples/jsm/webxr/Text2D.js +6 -6
  86. package/package.json +2 -2
  87. package/src/Three.WebGPU.Nodes.js +4 -0
  88. package/src/Three.WebGPU.js +4 -0
  89. package/src/constants.js +1 -6
  90. package/src/core/BufferGeometry.js +44 -6
  91. package/src/geometries/CylinderGeometry.js +2 -2
  92. package/src/materials/LineBasicMaterial.js +6 -2
  93. package/src/materials/LineDashedMaterial.js +6 -2
  94. package/src/materials/Material.js +14 -1
  95. package/src/materials/MeshBasicMaterial.js +6 -2
  96. package/src/materials/MeshDepthMaterial.js +6 -2
  97. package/src/materials/MeshDistanceMaterial.js +6 -2
  98. package/src/materials/MeshLambertMaterial.js +6 -2
  99. package/src/materials/MeshMatcapMaterial.js +6 -2
  100. package/src/materials/MeshNormalMaterial.js +6 -2
  101. package/src/materials/MeshPhongMaterial.js +6 -2
  102. package/src/materials/MeshPhysicalMaterial.js +6 -2
  103. package/src/materials/MeshStandardMaterial.js +6 -2
  104. package/src/materials/MeshToonMaterial.js +6 -2
  105. package/src/materials/PointsMaterial.js +6 -2
  106. package/src/materials/RawShaderMaterial.js +6 -2
  107. package/src/materials/ShaderMaterial.js +6 -2
  108. package/src/materials/ShadowMaterial.js +6 -2
  109. package/src/materials/SpriteMaterial.js +6 -2
  110. package/src/materials/nodes/NodeMaterial.js +31 -9
  111. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  112. package/src/materials/nodes/manager/NodeMaterialObserver.js +111 -2
  113. package/src/math/ColorManagement.js +118 -85
  114. package/src/math/Vector4.js +11 -0
  115. package/src/nodes/Nodes.js +1 -21
  116. package/src/nodes/TSL.js +6 -24
  117. package/src/nodes/accessors/Camera.js +0 -1
  118. package/src/nodes/accessors/SceneNode.js +35 -1
  119. package/src/nodes/accessors/StorageBufferNode.js +32 -10
  120. package/src/nodes/accessors/VelocityNode.js +13 -3
  121. package/src/nodes/code/FunctionCallNode.js +16 -5
  122. package/src/nodes/code/ScriptableNode.js +4 -4
  123. package/src/nodes/core/Node.js +1 -0
  124. package/src/nodes/core/NodeBuilder.js +29 -5
  125. package/src/nodes/core/VarNode.js +15 -3
  126. package/src/nodes/display/ColorAdjustment.js +53 -4
  127. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  128. package/src/nodes/display/ColorSpaceNode.js +27 -39
  129. package/src/nodes/display/PassNode.js +6 -4
  130. package/src/nodes/display/ToneMappingNode.js +1 -1
  131. package/src/nodes/display/ViewportDepthNode.js +33 -1
  132. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  133. package/src/nodes/functions/material/getAlphaHashThreshold.js +64 -0
  134. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  135. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  136. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  137. package/src/nodes/lighting/AnalyticLightNode.js +12 -416
  138. package/src/nodes/lighting/LightsNode.js +24 -12
  139. package/src/nodes/lighting/PointLightNode.js +36 -26
  140. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  141. package/src/nodes/lighting/ShadowNode.js +484 -0
  142. package/src/nodes/utils/LoopNode.js +2 -2
  143. package/src/nodes/utils/Oscillators.js +6 -0
  144. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  145. package/src/nodes/utils/ReflectorNode.js +101 -15
  146. package/src/nodes/utils/Timer.js +29 -0
  147. package/src/objects/BatchedMesh.js +458 -241
  148. package/src/renderers/WebGLRenderer.js +120 -117
  149. package/src/renderers/common/Attributes.js +4 -0
  150. package/src/renderers/common/Backend.js +2 -0
  151. package/src/renderers/common/Background.js +14 -4
  152. package/src/renderers/common/Bindings.js +3 -2
  153. package/src/renderers/common/Constants.js +2 -1
  154. package/src/renderers/common/Geometries.js +20 -0
  155. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  156. package/src/renderers/common/Lighting.js +45 -0
  157. package/src/renderers/common/PostProcessingUtils.js +86 -0
  158. package/src/renderers/common/RenderList.js +39 -11
  159. package/src/renderers/common/RenderLists.js +4 -2
  160. package/src/renderers/common/RenderObject.js +18 -1
  161. package/src/renderers/common/Renderer.js +165 -26
  162. package/src/renderers/common/Textures.js +30 -14
  163. package/src/renderers/common/nodes/NodeLibrary.js +1 -14
  164. package/src/renderers/common/nodes/Nodes.js +2 -2
  165. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  166. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  167. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  168. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  169. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  170. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  171. package/src/renderers/webgl/WebGLProgram.js +24 -28
  172. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  173. package/src/renderers/webgl/WebGLState.js +37 -1
  174. package/src/renderers/webgl/WebGLTextures.js +29 -12
  175. package/src/renderers/webgl-fallback/WebGLBackend.js +98 -31
  176. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  177. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +33 -8
  178. package/src/renderers/webgpu/WebGPUBackend.js +105 -25
  179. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  180. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  181. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  182. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -8
  183. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +10 -20
  184. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  185. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  186. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +24 -6
  187. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  188. package/src/renderers/webxr/WebXRManager.js +4 -4
  189. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  190. package/src/nodes/display/FXAANode.js +0 -332
  191. package/src/nodes/utils/OscNode.js +0 -85
  192. package/src/nodes/utils/TimerNode.js +0 -97
  193. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
@@ -1,33 +1,13 @@
1
1
  export default /* glsl */`
2
2
 
3
- // http://www.russellcottrell.com/photo/matrixCalculator.htm
4
-
5
- // Linear sRGB => XYZ => Linear Display P3
6
- const mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(
7
- vec3( 0.8224621, 0.177538, 0.0 ),
8
- vec3( 0.0331941, 0.9668058, 0.0 ),
9
- vec3( 0.0170827, 0.0723974, 0.9105199 )
10
- );
11
-
12
- // Linear Display P3 => XYZ => Linear sRGB
13
- const mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(
14
- vec3( 1.2249401, - 0.2249404, 0.0 ),
15
- vec3( - 0.0420569, 1.0420571, 0.0 ),
16
- vec3( - 0.0196376, - 0.0786361, 1.0982735 )
17
- );
18
-
19
- vec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {
20
- return vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );
21
- }
22
-
23
- vec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {
24
- return vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );
25
- }
26
-
27
3
  vec4 LinearTransferOETF( in vec4 value ) {
28
4
  return value;
29
5
  }
30
6
 
7
+ vec4 sRGBTransferEOTF( in vec4 value ) {
8
+ return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
9
+ }
10
+
31
11
  vec4 sRGBTransferOETF( in vec4 value ) {
32
12
  return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
33
13
  }
@@ -3,6 +3,14 @@ export default /* glsl */`
3
3
 
4
4
  vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
5
5
 
6
+ #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
7
+
8
+ // use inline sRGB decode until browsers properly support SRGB8_ALPHA8 with video textures (#26516)
9
+
10
+ emissiveColor = sRGBTransferEOTF( emissiveColor );
11
+
12
+ #endif
13
+
6
14
  totalEmissiveRadiance *= emissiveColor.rgb;
7
15
 
8
16
  #endif
@@ -7,8 +7,8 @@ export default /* glsl */`
7
7
 
8
8
  // use inline sRGB decode until browsers properly support SRGB8_ALPHA8 with video textures (#26516)
9
9
 
10
- sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );
11
-
10
+ sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
11
+
12
12
  #endif
13
13
 
14
14
  diffuseColor *= sampledDiffuseColor;
@@ -65,15 +65,11 @@ function WebGLBufferRenderer( gl, extensions, info ) {
65
65
  let elementCount = 0;
66
66
  for ( let i = 0; i < drawCount; i ++ ) {
67
67
 
68
- elementCount += counts[ i ];
68
+ elementCount += counts[ i ] * primcount[ i ];
69
69
 
70
70
  }
71
71
 
72
- for ( let i = 0; i < primcount.length; i ++ ) {
73
-
74
- info.update( elementCount, mode, primcount[ i ] );
75
-
76
- }
72
+ info.update( elementCount, mode, 1 );
77
73
 
78
74
  }
79
75
 
@@ -94,13 +94,6 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
94
94
  const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
95
95
  const reverseDepthBuffer = parameters.reverseDepthBuffer === true && extensions.has( 'EXT_clip_control' );
96
96
 
97
- if ( reverseDepthBuffer === true ) {
98
-
99
- const ext = extensions.get( 'EXT_clip_control' );
100
- ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT );
101
-
102
- }
103
-
104
97
  const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
105
98
  const maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
106
99
  const maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
@@ -75,15 +75,11 @@ function WebGLIndexedBufferRenderer( gl, extensions, info ) {
75
75
  let elementCount = 0;
76
76
  for ( let i = 0; i < drawCount; i ++ ) {
77
77
 
78
- elementCount += counts[ i ];
78
+ elementCount += counts[ i ] * primcount[ i ];
79
79
 
80
80
  }
81
81
 
82
- for ( let i = 0; i < primcount.length; i ++ ) {
83
-
84
- info.update( elementCount, mode, primcount[ i ] );
85
-
86
- }
82
+ info.update( elementCount, mode, 1 );
87
83
 
88
84
  }
89
85
 
@@ -1,9 +1,10 @@
1
1
  import { WebGLUniforms } from './WebGLUniforms.js';
2
2
  import { WebGLShader } from './WebGLShader.js';
3
3
  import { ShaderChunk } from '../shaders/ShaderChunk.js';
4
- import { NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, AgXToneMapping, ACESFilmicToneMapping, NeutralToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, GLSL3, LinearSRGBColorSpace, SRGBColorSpace, LinearDisplayP3ColorSpace, DisplayP3ColorSpace, P3Primaries, Rec709Primaries } from '../../constants.js';
4
+ import { NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, AgXToneMapping, ACESFilmicToneMapping, NeutralToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, GLSL3, LinearTransfer, SRGBTransfer } from '../../constants.js';
5
5
  import { ColorManagement } from '../../math/ColorManagement.js';
6
6
  import { Vector3 } from '../../math/Vector3.js';
7
+ import { Matrix3 } from '../../math/Matrix3.js';
7
8
 
8
9
  // From https://www.khronos.org/registry/webgl/extensions/KHR_parallel_shader_compile/
9
10
  const COMPLETION_STATUS_KHR = 0x91B1;
@@ -29,40 +30,25 @@ function handleSource( string, errorLine ) {
29
30
 
30
31
  }
31
32
 
32
- function getEncodingComponents( colorSpace ) {
33
-
34
- const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );
35
- const encodingPrimaries = ColorManagement.getPrimaries( colorSpace );
36
-
37
- let gamutMapping;
38
-
39
- if ( workingPrimaries === encodingPrimaries ) {
33
+ const _m0 = /*@__PURE__*/ new Matrix3();
40
34
 
41
- gamutMapping = '';
42
-
43
- } else if ( workingPrimaries === P3Primaries && encodingPrimaries === Rec709Primaries ) {
44
-
45
- gamutMapping = 'LinearDisplayP3ToLinearSRGB';
46
-
47
- } else if ( workingPrimaries === Rec709Primaries && encodingPrimaries === P3Primaries ) {
35
+ function getEncodingComponents( colorSpace ) {
48
36
 
49
- gamutMapping = 'LinearSRGBToLinearDisplayP3';
37
+ ColorManagement._getMatrix( _m0, ColorManagement.workingColorSpace, colorSpace );
50
38
 
51
- }
39
+ const encodingMatrix = `mat3( ${ _m0.elements.map( ( v ) => v.toFixed( 4 ) ) } )`;
52
40
 
53
- switch ( colorSpace ) {
41
+ switch ( ColorManagement.getTransfer( colorSpace ) ) {
54
42
 
55
- case LinearSRGBColorSpace:
56
- case LinearDisplayP3ColorSpace:
57
- return [ gamutMapping, 'LinearTransferOETF' ];
43
+ case LinearTransfer:
44
+ return [ encodingMatrix, 'LinearTransferOETF' ];
58
45
 
59
- case SRGBColorSpace:
60
- case DisplayP3ColorSpace:
61
- return [ gamutMapping, 'sRGBTransferOETF' ];
46
+ case SRGBTransfer:
47
+ return [ encodingMatrix, 'sRGBTransferOETF' ];
62
48
 
63
49
  default:
64
- console.warn( 'THREE.WebGLProgram: Unsupported color space:', colorSpace );
65
- return [ gamutMapping, 'LinearTransferOETF' ];
50
+ console.warn( 'THREE.WebGLProgram: Unsupported color space: ', colorSpace );
51
+ return [ encodingMatrix, 'LinearTransferOETF' ];
66
52
 
67
53
  }
68
54
 
@@ -95,7 +81,16 @@ function getShaderErrors( gl, shader, type ) {
95
81
  function getTexelEncodingFunction( functionName, colorSpace ) {
96
82
 
97
83
  const components = getEncodingComponents( colorSpace );
98
- return `vec4 ${functionName}( vec4 value ) { return ${components[ 0 ]}( ${components[ 1 ]}( value ) ); }`;
84
+
85
+ return [
86
+
87
+ `vec4 ${functionName}( vec4 value ) {`,
88
+
89
+ ` return ${components[ 1 ]}( vec4( value.rgb * ${components[ 0 ]}, value.a ) );`,
90
+
91
+ '}',
92
+
93
+ ].join( '\n' );
99
94
 
100
95
  }
101
96
 
@@ -823,6 +818,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
823
818
  parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
824
819
 
825
820
  parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
821
+ parameters.decodeVideoTextureEmissive ? '#define DECODE_VIDEO_TEXTURE_EMISSIVE' : '',
826
822
 
827
823
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
828
824
  parameters.reverseDepthBuffer ? '#define USE_REVERSEDEPTHBUF' : '',
@@ -14,7 +14,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
14
14
  const programs = [];
15
15
 
16
16
  const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
17
- const reverseDepthBuffer = capabilities.reverseDepthBuffer;
18
17
  const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures;
19
18
 
20
19
  let precision = capabilities.precision;
@@ -109,6 +108,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
109
108
  }
110
109
 
111
110
  const currentRenderTarget = renderer.getRenderTarget();
111
+ const reverseDepthBuffer = renderer.state.buffers.depth.getReversed();
112
112
 
113
113
  const numMultiviewViews = currentRenderTarget && currentRenderTarget.isWebGLMultiviewRenderTarget ? currentRenderTarget.numViews : 0;
114
114
 
@@ -344,6 +344,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
344
344
  toneMapping: toneMapping,
345
345
 
346
346
  decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ),
347
+ decodeVideoTextureEmissive: HAS_EMISSIVEMAP && ( material.emissiveMap.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.emissiveMap.colorSpace ) === SRGBTransfer ),
347
348
 
348
349
  premultipliedAlpha: material.premultipliedAlpha,
349
350
 
@@ -561,8 +562,10 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
561
562
  _programLayers.enable( 18 );
562
563
  if ( parameters.decodeVideoTexture )
563
564
  _programLayers.enable( 19 );
564
- if ( parameters.alphaToCoverage )
565
+ if ( parameters.decodeVideoTextureEmissive )
565
566
  _programLayers.enable( 20 );
567
+ if ( parameters.alphaToCoverage )
568
+ _programLayers.enable( 21 );
566
569
  if ( parameters.numMultiviewViews )
567
570
  _programLayers.enable( 21 );
568
571
 
@@ -14,7 +14,7 @@ const reversedFuncs = {
14
14
  [ GreaterEqualDepth ]: LessEqualDepth,
15
15
  };
16
16
 
17
- function WebGLState( gl ) {
17
+ function WebGLState( gl, extensions ) {
18
18
 
19
19
  function ColorBuffer() {
20
20
 
@@ -88,10 +88,36 @@ function WebGLState( gl ) {
88
88
 
89
89
  setReversed: function ( value ) {
90
90
 
91
+ if ( reversed !== value ) {
92
+
93
+ const ext = extensions.get( 'EXT_clip_control' );
94
+
95
+ if ( reversed ) {
96
+
97
+ ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT );
98
+
99
+ } else {
100
+
101
+ ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT );
102
+
103
+ }
104
+
105
+ const oldDepth = currentDepthClear;
106
+ currentDepthClear = null;
107
+ this.setClear( oldDepth );
108
+
109
+ }
110
+
91
111
  reversed = value;
92
112
 
93
113
  },
94
114
 
115
+ getReversed: function () {
116
+
117
+ return reversed;
118
+
119
+ },
120
+
95
121
  setTest: function ( depthTest ) {
96
122
 
97
123
  if ( depthTest ) {
@@ -187,6 +213,12 @@ function WebGLState( gl ) {
187
213
 
188
214
  if ( currentDepthClear !== depth ) {
189
215
 
216
+ if ( reversed ) {
217
+
218
+ depth = 1 - depth;
219
+
220
+ }
221
+
190
222
  gl.clearDepth( depth );
191
223
  currentDepthClear = depth;
192
224
 
@@ -201,6 +233,7 @@ function WebGLState( gl ) {
201
233
  currentDepthMask = null;
202
234
  currentDepthFunc = null;
203
235
  currentDepthClear = null;
236
+ reversed = false;
204
237
 
205
238
  }
206
239
 
@@ -1171,6 +1204,9 @@ function WebGLState( gl ) {
1171
1204
 
1172
1205
  gl.depthMask( true );
1173
1206
  gl.depthFunc( gl.LESS );
1207
+
1208
+ depthBuffer.setReversed( false );
1209
+
1174
1210
  gl.clearDepth( 1 );
1175
1211
 
1176
1212
  gl.stencilMask( 0xffffffff );
@@ -111,7 +111,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
111
111
 
112
112
  function textureNeedsGenerateMipmaps( texture ) {
113
113
 
114
- return texture.generateMipmaps && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
114
+ return texture.generateMipmaps;
115
115
 
116
116
  }
117
117
 
@@ -121,6 +121,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
121
121
 
122
122
  }
123
123
 
124
+ function getTargetType( texture ) {
125
+
126
+ if ( texture.isWebGLCubeRenderTarget ) return _gl.TEXTURE_CUBE_MAP;
127
+ if ( texture.isWebGL3DRenderTarget ) return _gl.TEXTURE_3D;
128
+ if ( texture.isWebGLArrayRenderTarget || texture.isCompressedArrayTexture ) return _gl.TEXTURE_2D_ARRAY;
129
+ return _gl.TEXTURE_2D;
130
+
131
+ }
132
+
124
133
  function getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
125
134
 
126
135
  if ( internalFormatName !== null ) {
@@ -380,6 +389,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
380
389
 
381
390
  renderTarget.depthTexture.dispose();
382
391
 
392
+ properties.remove( renderTarget.depthTexture );
393
+
383
394
  }
384
395
 
385
396
  if ( renderTarget.isWebGLCubeRenderTarget ) {
@@ -929,7 +940,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
929
940
  layerIndex * layerByteLength / mipmap.data.BYTES_PER_ELEMENT,
930
941
  ( layerIndex + 1 ) * layerByteLength / mipmap.data.BYTES_PER_ELEMENT
931
942
  );
932
- state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, layerData, 0, 0 );
943
+ state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, layerData );
933
944
 
934
945
  }
935
946
 
@@ -937,7 +948,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
937
948
 
938
949
  } else {
939
950
 
940
- state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );
951
+ state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data );
941
952
 
942
953
  }
943
954
 
@@ -1453,6 +1464,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1453
1464
  const glType = utils.convert( texture.type );
1454
1465
  const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
1455
1466
  const renderTargetProperties = properties.get( renderTarget );
1467
+ const textureProperties = properties.get( texture );
1468
+
1469
+ textureProperties.__renderTarget = renderTarget;
1456
1470
 
1457
1471
  if ( ! renderTargetProperties.__hasExternalTextures ) {
1458
1472
 
@@ -1483,11 +1497,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1483
1497
 
1484
1498
  if ( multisampled ) {
1485
1499
 
1486
- multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ), 0, renderTarget.numViews );
1500
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, 0, getRenderTargetSamples( renderTarget ), 0, renderTarget.numViews );
1487
1501
 
1488
1502
  } else {
1489
1503
 
1490
- multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( texture ).__webglTexture, 0, 0, renderTarget.numViews );
1504
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, 0, 0, renderTarget.numViews );
1491
1505
 
1492
1506
  }
1493
1507
 
@@ -1495,11 +1509,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1495
1509
 
1496
1510
  if ( multisampled ) {
1497
1511
 
1498
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
1512
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
1499
1513
 
1500
1514
  } else {
1501
1515
 
1502
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, level );
1516
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, level );
1503
1517
 
1504
1518
  }
1505
1519
 
@@ -1642,8 +1656,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1642
1656
 
1643
1657
  }
1644
1658
 
1659
+ const textureProperties = properties.get( renderTarget.depthTexture );
1660
+ textureProperties.__renderTarget = renderTarget;
1661
+
1645
1662
  // upload an empty depth texture with framebuffer size
1646
- if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
1663
+ if ( ! textureProperties.__webglTexture ||
1647
1664
  renderTarget.depthTexture.image.width !== renderTarget.width ||
1648
1665
  renderTarget.depthTexture.image.height !== renderTarget.height ) {
1649
1666
 
@@ -1664,7 +1681,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1664
1681
 
1665
1682
  }
1666
1683
 
1667
- const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
1684
+ const webglDepthTexture = textureProperties.__webglTexture;
1668
1685
  const samples = getRenderTargetSamples( renderTarget );
1669
1686
 
1670
1687
  if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
@@ -2100,11 +2117,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
2100
2117
 
2101
2118
  if ( textureNeedsGenerateMipmaps( texture ) ) {
2102
2119
 
2103
- const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
2120
+ const targetType = getTargetType( renderTarget );
2104
2121
  const webglTexture = properties.get( texture ).__webglTexture;
2105
2122
 
2106
- state.bindTexture( target, webglTexture );
2107
- generateMipmap( target );
2123
+ state.bindTexture( targetType, webglTexture );
2124
+ generateMipmap( targetType );
2108
2125
  state.unbindTexture();
2109
2126
 
2110
2127
  }