super-three 0.136.0 → 0.136.1

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 (125) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.js +1634 -1608
  3. package/build/three.min.js +1 -1
  4. package/build/three.module.js +4630 -4534
  5. package/examples/js/animation/MMDPhysics.js +1 -1
  6. package/examples/js/cameras/CinematicCamera.js +2 -7
  7. package/examples/js/exporters/MMDExporter.js +1 -1
  8. package/examples/js/geometries/ConvexGeometry.js +1 -1
  9. package/examples/js/loaders/BasisTextureLoader.js +1 -0
  10. package/examples/js/loaders/EXRLoader.js +25 -19
  11. package/examples/js/loaders/GLTFLoader.js +2 -2
  12. package/examples/js/loaders/HDRCubeTextureLoader.js +0 -2
  13. package/examples/js/loaders/LDrawLoader.js +1131 -859
  14. package/examples/js/loaders/LUT3dlLoader.js +17 -10
  15. package/examples/js/loaders/LUTCubeLoader.js +3 -4
  16. package/examples/js/loaders/RGBELoader.js +6 -6
  17. package/examples/js/loaders/RGBMLoader.js +1 -1
  18. package/examples/js/loaders/SVGLoader.js +3 -1
  19. package/examples/js/loaders/VRMLLoader.js +9 -21
  20. package/examples/js/math/ConvexHull.js +7 -13
  21. package/examples/js/misc/Volume.js +2 -2
  22. package/examples/js/modifiers/CurveModifier.js +8 -7
  23. package/examples/js/modifiers/EdgeSplitModifier.js +1 -1
  24. package/examples/js/modifiers/SimplifyModifier.js +1 -1
  25. package/examples/js/objects/Reflector.js +1 -13
  26. package/examples/js/objects/ReflectorForSSRPass.js +0 -10
  27. package/examples/js/objects/Refractor.js +1 -13
  28. package/examples/js/objects/Water.js +1 -13
  29. package/examples/js/postprocessing/GlitchPass.js +4 -5
  30. package/examples/js/postprocessing/SMAAPass.js +2 -9
  31. package/examples/js/postprocessing/SSAOPass.js +9 -21
  32. package/examples/js/postprocessing/SavePass.js +1 -5
  33. package/examples/js/shaders/DigitalGlitch.js +3 -3
  34. package/examples/js/shaders/MMDToonShader.js +0 -1
  35. package/examples/js/shaders/SSAOShader.js +1 -1
  36. package/examples/jsm/animation/MMDPhysics.js +1 -1
  37. package/examples/jsm/cameras/CinematicCamera.js +2 -5
  38. package/examples/jsm/{WebGL.js → capabilities/WebGL.js} +2 -2
  39. package/examples/jsm/{renderers/webgpu → capabilities}/WebGPU.js +1 -1
  40. package/examples/jsm/exporters/GLTFExporter.js +8 -24
  41. package/examples/jsm/exporters/MMDExporter.js +1 -1
  42. package/examples/jsm/geometries/ConvexGeometry.js +1 -1
  43. package/examples/jsm/libs/lil-gui.module.min.js +2 -2
  44. package/examples/jsm/loaders/BasisTextureLoader.js +7 -0
  45. package/examples/jsm/loaders/EXRLoader.js +22 -19
  46. package/examples/jsm/loaders/GLTFLoader.js +1 -3
  47. package/examples/jsm/loaders/HDRCubeTextureLoader.js +1 -4
  48. package/examples/jsm/loaders/LDrawLoader.js +1147 -885
  49. package/examples/jsm/loaders/LUT3dlLoader.js +17 -12
  50. package/examples/jsm/loaders/LUTCubeLoader.js +3 -5
  51. package/examples/jsm/loaders/RGBELoader.js +7 -8
  52. package/examples/jsm/loaders/RGBMLoader.js +1 -1
  53. package/examples/jsm/loaders/SVGLoader.js +6 -1
  54. package/examples/jsm/loaders/VRMLLoader.js +9 -22
  55. package/examples/jsm/math/ConvexHull.js +7 -13
  56. package/examples/jsm/misc/Volume.js +2 -2
  57. package/examples/jsm/modifiers/CurveModifier.js +9 -8
  58. package/examples/jsm/modifiers/EdgeSplitModifier.js +1 -1
  59. package/examples/jsm/modifiers/SimplifyModifier.js +1 -1
  60. package/examples/jsm/node-editor/NodeEditor.js +21 -22
  61. package/examples/jsm/nodes/utils/ColorSpaceNode.js +4 -13
  62. package/examples/jsm/objects/Lensflare.js +4 -4
  63. package/examples/jsm/objects/Reflector.js +1 -16
  64. package/examples/jsm/objects/ReflectorForSSRPass.js +0 -12
  65. package/examples/jsm/objects/Refractor.js +1 -16
  66. package/examples/jsm/objects/Water.js +1 -16
  67. package/examples/jsm/postprocessing/GlitchPass.js +7 -6
  68. package/examples/jsm/postprocessing/SMAAPass.js +2 -11
  69. package/examples/jsm/postprocessing/SSAOPass.js +13 -25
  70. package/examples/jsm/postprocessing/SavePass.js +1 -3
  71. package/examples/jsm/renderers/nodes/Nodes.js +2 -0
  72. package/examples/jsm/renderers/nodes/ShaderNode.js +58 -31
  73. package/examples/jsm/renderers/nodes/display/ColorSpaceNode.js +9 -46
  74. package/examples/jsm/renderers/nodes/inputs/TextureNode.js +5 -10
  75. package/examples/jsm/renderers/nodes/math/MathNode.js +2 -1
  76. package/examples/jsm/renderers/webgpu/WebGPUObjects.js +1 -1
  77. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +3 -5
  78. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +1 -2
  79. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +10 -4
  80. package/examples/jsm/shaders/DigitalGlitch.js +3 -3
  81. package/examples/jsm/shaders/MMDToonShader.js +0 -1
  82. package/examples/jsm/shaders/SSAOShader.js +1 -1
  83. package/examples/jsm/utils/LDrawUtils.js +195 -0
  84. package/examples/jsm/webxr/VRButton.js +24 -0
  85. package/examples/jsm/webxr/XREstimatedLight.js +2 -0
  86. package/package.json +4 -1
  87. package/src/animation/AnimationMixer.js +1 -0
  88. package/src/cameras/CubeCamera.js +2 -0
  89. package/src/constants.js +3 -16
  90. package/src/extras/ImageUtils.js +63 -0
  91. package/src/extras/PMREMGenerator.js +32 -82
  92. package/src/loaders/MaterialLoader.js +1 -1
  93. package/src/materials/Material.js +4 -4
  94. package/src/math/Color.js +1 -1
  95. package/src/math/Quaternion.js +1 -1
  96. package/src/renderers/WebGLCubeRenderTarget.js +0 -2
  97. package/src/renderers/WebGLRenderer.js +1 -67
  98. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +0 -2
  99. package/src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl.js +0 -4
  100. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +0 -2
  101. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +1 -1
  102. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +1 -1
  103. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +2 -2
  104. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +10 -3
  105. package/src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl.js +1 -2
  106. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +8 -7
  107. package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -3
  108. package/src/renderers/shaders/ShaderLib/equirect.glsl.js +1 -3
  109. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -1
  110. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +1 -2
  111. package/src/renderers/shaders/ShaderLib.js +2 -2
  112. package/src/renderers/webgl/WebGLCubeMaps.js +0 -4
  113. package/src/renderers/webgl/WebGLCubeUVMaps.js +29 -16
  114. package/src/renderers/webgl/WebGLMorphtargets.js +12 -0
  115. package/src/renderers/webgl/WebGLProgram.js +4 -16
  116. package/src/renderers/webgl/WebGLPrograms.js +8 -47
  117. package/src/renderers/webgl/WebGLState.js +81 -0
  118. package/src/renderers/webgl/WebGLTextures.js +75 -22
  119. package/src/renderers/webgl/WebGLUtils.js +86 -28
  120. package/src/renderers/webxr/WebXRManager.js +3 -3
  121. package/src/textures/Texture.js +2 -1
  122. package/src/textures/VideoTexture.js +1 -3
  123. package/examples/js/WebGL.js +0 -90
  124. package/examples/js/utils/RoughnessMipmapper.js +0 -268
  125. package/examples/jsm/utils/RoughnessMipmapper.js +0 -288
@@ -40,14 +40,10 @@ function WebGLCubeMaps( renderer ) {
40
40
 
41
41
  if ( image && image.height > 0 ) {
42
42
 
43
- const currentRenderTarget = renderer.getRenderTarget();
44
-
45
43
  const renderTarget = new WebGLCubeRenderTarget( image.height / 2 );
46
44
  renderTarget.fromEquirectangularTexture( renderer, texture );
47
45
  cubemaps.set( texture, renderTarget );
48
46
 
49
- renderer.setRenderTarget( currentRenderTarget );
50
-
51
47
  texture.addEventListener( 'dispose', onTextureDispose );
52
48
 
53
49
  return mapTextureMapping( renderTarget.texture, texture.mapping );
@@ -9,45 +9,58 @@ function WebGLCubeUVMaps( renderer ) {
9
9
 
10
10
  function get( texture ) {
11
11
 
12
- if ( texture && texture.isTexture && texture.isRenderTargetTexture === false ) {
12
+ if ( texture && texture.isTexture ) {
13
13
 
14
14
  const mapping = texture.mapping;
15
15
 
16
16
  const isEquirectMap = ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping );
17
17
  const isCubeMap = ( mapping === CubeReflectionMapping || mapping === CubeRefractionMapping );
18
18
 
19
+ // equirect/cube map to cubeUV conversion
20
+
19
21
  if ( isEquirectMap || isCubeMap ) {
20
22
 
21
- // equirect/cube map to cubeUV conversion
23
+ if ( texture.isRenderTargetTexture && texture.needsPMREMUpdate === true ) {
24
+
25
+ texture.needsPMREMUpdate = false;
26
+
27
+ let renderTarget = cubeUVmaps.get( texture );
28
+
29
+ if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
22
30
 
23
- if ( cubeUVmaps.has( texture ) ) {
31
+ renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture, renderTarget ) : pmremGenerator.fromCubemap( texture, renderTarget );
32
+ cubeUVmaps.set( texture, renderTarget );
24
33
 
25
- return cubeUVmaps.get( texture ).texture;
34
+ return renderTarget.texture;
26
35
 
27
36
  } else {
28
37
 
29
- const image = texture.image;
38
+ if ( cubeUVmaps.has( texture ) ) {
30
39
 
31
- if ( ( isEquirectMap && image && image.height > 0 ) || ( isCubeMap && image && isCubeTextureComplete( image ) ) ) {
40
+ return cubeUVmaps.get( texture ).texture;
32
41
 
33
- const currentRenderTarget = renderer.getRenderTarget();
42
+ } else {
34
43
 
35
- if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
44
+ const image = texture.image;
36
45
 
37
- const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );
38
- cubeUVmaps.set( texture, renderTarget );
46
+ if ( ( isEquirectMap && image && image.height > 0 ) || ( isCubeMap && image && isCubeTextureComplete( image ) ) ) {
39
47
 
40
- renderer.setRenderTarget( currentRenderTarget );
48
+ if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );
41
49
 
42
- texture.addEventListener( 'dispose', onTextureDispose );
50
+ const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );
51
+ cubeUVmaps.set( texture, renderTarget );
43
52
 
44
- return renderTarget.texture;
53
+ texture.addEventListener( 'dispose', onTextureDispose );
45
54
 
46
- } else {
55
+ return renderTarget.texture;
56
+
57
+ } else {
58
+
59
+ // image not yet ready. try the conversion next frame
47
60
 
48
- // image not yet ready. try the conversion next frame
61
+ return null;
49
62
 
50
- return null;
63
+ }
51
64
 
52
65
  }
53
66
 
@@ -135,6 +135,18 @@ function WebGLMorphtargets( gl, capabilities, textures ) {
135
135
 
136
136
  morphTextures.set( geometry, entry );
137
137
 
138
+ function disposeTexture() {
139
+
140
+ texture.dispose();
141
+
142
+ morphTextures.delete( geometry );
143
+
144
+ geometry.removeEventListener( 'dispose', disposeTexture );
145
+
146
+ }
147
+
148
+ geometry.addEventListener( 'dispose', disposeTexture );
149
+
138
150
  }
139
151
 
140
152
  //
@@ -1,7 +1,7 @@
1
1
  import { WebGLUniforms } from './WebGLUniforms.js';
2
2
  import { WebGLShader } from './WebGLShader.js';
3
3
  import { ShaderChunk } from '../shaders/ShaderChunk.js';
4
- import { RGBFormat, NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, ACESFilmicToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, sRGBEncoding, LinearEncoding, GLSL3 } from '../../constants.js';
4
+ import { NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFSoftShadowMap, PCFShadowMap, VSMShadowMap, ACESFilmicToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, sRGBEncoding, LinearEncoding, GLSL3 } from '../../constants.js';
5
5
 
6
6
  let programIdCount = 0;
7
7
 
@@ -49,13 +49,6 @@ function getShaderErrors( gl, shader, type ) {
49
49
 
50
50
  }
51
51
 
52
- function getTexelDecodingFunction( functionName, encoding ) {
53
-
54
- const components = getEncodingComponents( encoding );
55
- return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
56
-
57
- }
58
-
59
52
  function getTexelEncodingFunction( functionName, encoding ) {
60
53
 
61
54
  const components = getEncodingComponents( encoding );
@@ -625,6 +618,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
625
618
  parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
626
619
  parameters.thicknessMap ? '#define USE_THICKNESSMAP' : '',
627
620
 
621
+ parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
622
+
628
623
  parameters.vertexTangents ? '#define USE_TANGENT' : '',
629
624
  parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
630
625
  parameters.vertexAlphas ? '#define USE_COLOR_ALPHA' : '',
@@ -659,16 +654,9 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
659
654
  ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
660
655
 
661
656
  parameters.dithering ? '#define DITHERING' : '',
662
- parameters.format === RGBFormat ? '#define OPAQUE' : '',
657
+ parameters.alphaWrite ? '' : '#define OPAQUE',
663
658
 
664
659
  ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
665
- parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
666
- parameters.matcap ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
667
- parameters.envMap ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
668
- parameters.emissiveMap ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
669
- parameters.specularColorMap ? getTexelDecodingFunction( 'specularColorMapTexelToLinear', parameters.specularColorMapEncoding ) : '',
670
- parameters.sheenColorMap ? getTexelDecodingFunction( 'sheenColorMapTexelToLinear', parameters.sheenColorMapEncoding ) : '',
671
- parameters.lightMap ? getTexelDecodingFunction( 'lightMapTexelToLinear', parameters.lightMapEncoding ) : '',
672
660
  getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ),
673
661
 
674
662
  parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',
@@ -1,4 +1,4 @@
1
- import { BackSide, DoubleSide, CubeUVRefractionMapping, CubeUVReflectionMapping, LinearEncoding, sRGBEncoding, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping, RGBAFormat, UnsignedByteType } from '../../constants.js';
1
+ import { BackSide, DoubleSide, CubeUVRefractionMapping, CubeUVReflectionMapping, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping, sRGBEncoding } from '../../constants.js';
2
2
  import { Layers } from '../../core/Layers.js';
3
3
  import { WebGLProgram } from './WebGLProgram.js';
4
4
  import { WebGLShaderCache } from './WebGLShaderCache.js';
@@ -72,35 +72,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
72
72
 
73
73
  }
74
74
 
75
- function getTextureEncodingFromMap( map ) {
76
-
77
- let encoding;
78
-
79
- if ( map && map.isTexture ) {
80
-
81
- encoding = map.encoding;
82
-
83
- } else if ( map && map.isWebGLRenderTarget ) {
84
-
85
- console.warn( 'THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.' );
86
- encoding = map.texture.encoding;
87
-
88
- } else {
89
-
90
- encoding = LinearEncoding;
91
-
92
- }
93
-
94
- if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {
95
-
96
- encoding = LinearEncoding; // disable inline decode for sRGB textures in WebGL 2
97
-
98
- }
99
-
100
- return encoding;
101
-
102
- }
103
-
104
75
  function getParameters( material, lights, shadows, scene, object ) {
105
76
 
106
77
  const fog = scene.fog;
@@ -177,25 +148,22 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
177
148
  instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
178
149
 
179
150
  supportsVertexTextures: vertexTextures,
180
- outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding,
151
+ outputEncoding: ( currentRenderTarget !== null ) ? currentRenderTarget.texture.encoding : renderer.outputEncoding,
181
152
  map: !! material.map,
182
- mapEncoding: getTextureEncodingFromMap( material.map ),
183
153
  matcap: !! material.matcap,
184
- matcapEncoding: getTextureEncodingFromMap( material.matcap ),
185
154
  envMap: !! envMap,
186
155
  envMapMode: envMap && envMap.mapping,
187
- envMapEncoding: getTextureEncodingFromMap( envMap ),
188
156
  envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
189
157
  lightMap: !! material.lightMap,
190
- lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
191
158
  aoMap: !! material.aoMap,
192
159
  emissiveMap: !! material.emissiveMap,
193
- emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ),
194
160
  bumpMap: !! material.bumpMap,
195
161
  normalMap: !! material.normalMap,
196
162
  objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
197
163
  tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
198
164
 
165
+ decodeVideoTexture: !! material.map && ( material.map.isVideoTexture === true ) && ( material.map.encoding === sRGBEncoding ),
166
+
199
167
  clearcoat: useClearcoat,
200
168
  clearcoatMap: useClearcoat && !! material.clearcoatMap,
201
169
  clearcoatRoughnessMap: useClearcoat && !! material.clearcoatRoughnessMap,
@@ -207,16 +175,15 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
207
175
  specularMap: !! material.specularMap,
208
176
  specularIntensityMap: !! material.specularIntensityMap,
209
177
  specularColorMap: !! material.specularColorMap,
210
- specularColorMapEncoding: getTextureEncodingFromMap( material.specularColorMap ),
211
178
 
212
179
  alphaMap: !! material.alphaMap,
213
180
  alphaTest: useAlphaTest,
181
+ alphaWrite: material.alphaWrite || material.transparent,
214
182
 
215
183
  gradientMap: !! material.gradientMap,
216
184
 
217
185
  sheen: material.sheen > 0,
218
186
  sheenColorMap: !! material.sheenColorMap,
219
- sheenColorMapEncoding: getTextureEncodingFromMap( material.sheenColorMap ),
220
187
  sheenRoughnessMap: !! material.sheenRoughnessMap,
221
188
 
222
189
  transmission: material.transmission > 0,
@@ -261,7 +228,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
261
228
  numClippingPlanes: clipping.numPlanes,
262
229
  numClipIntersection: clipping.numIntersection,
263
230
 
264
- format: material.format,
265
231
  dithering: material.dithering,
266
232
 
267
233
  shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
@@ -340,12 +306,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
340
306
 
341
307
  array.push( parameters.precision );
342
308
  array.push( parameters.outputEncoding );
343
- array.push( parameters.mapEncoding );
344
- array.push( parameters.matcapEncoding );
345
309
  array.push( parameters.envMapMode );
346
- array.push( parameters.envMapEncoding );
347
- array.push( parameters.lightMapEncoding );
348
- array.push( parameters.emissiveMapEncoding );
349
310
  array.push( parameters.combine );
350
311
  array.push( parameters.vertexUvs );
351
312
  array.push( parameters.fogExp2 );
@@ -364,9 +325,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
364
325
  array.push( parameters.toneMapping );
365
326
  array.push( parameters.numClippingPlanes );
366
327
  array.push( parameters.numClipIntersection );
367
- array.push( parameters.format );
368
- array.push( parameters.specularColorMapEncoding );
369
- array.push( parameters.sheenColorMapEncoding );
328
+ array.push( parameters.alphaWrite );
370
329
 
371
330
  }
372
331
 
@@ -486,6 +445,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
486
445
  _programLayers.enable( 20 );
487
446
  if ( parameters.sheenRoughnessMap )
488
447
  _programLayers.enable( 21 );
448
+ if ( parameters.decodeVideoTexture )
449
+ _programLayers.enable( 22 );
489
450
 
490
451
  array.push( _programLayers.mask );
491
452
 
@@ -317,6 +317,8 @@ function WebGLState( gl, extensions, capabilities ) {
317
317
  let enabledCapabilities = {};
318
318
 
319
319
  let currentBoundFramebuffers = {};
320
+ let currentDrawbuffers = new WeakMap();
321
+ let defaultDrawbuffers = [];
320
322
 
321
323
  let currentProgram = null;
322
324
 
@@ -461,6 +463,82 @@ function WebGLState( gl, extensions, capabilities ) {
461
463
 
462
464
  }
463
465
 
466
+ function drawBuffers( renderTarget, framebuffer ) {
467
+
468
+ let drawBuffers = defaultDrawbuffers;
469
+
470
+ let needsUpdate = false;
471
+
472
+ if ( renderTarget ) {
473
+
474
+ drawBuffers = currentDrawbuffers.get( framebuffer );
475
+
476
+ if ( drawBuffers === undefined ) {
477
+
478
+ drawBuffers = [];
479
+ currentDrawbuffers.set( framebuffer, drawBuffers );
480
+
481
+ }
482
+
483
+ if ( renderTarget.isWebGLMultipleRenderTargets ) {
484
+
485
+ const textures = renderTarget.texture;
486
+
487
+ if ( drawBuffers.length !== textures.length || drawBuffers[ 0 ] !== gl.COLOR_ATTACHMENT0 ) {
488
+
489
+ for ( let i = 0, il = textures.length; i < il; i ++ ) {
490
+
491
+ drawBuffers[ i ] = gl.COLOR_ATTACHMENT0 + i;
492
+
493
+ }
494
+
495
+ drawBuffers.length = textures.length;
496
+
497
+ needsUpdate = true;
498
+
499
+ }
500
+
501
+ } else {
502
+
503
+ if ( drawBuffers[ 0 ] !== gl.COLOR_ATTACHMENT0 ) {
504
+
505
+ drawBuffers[ 0 ] = gl.COLOR_ATTACHMENT0;
506
+
507
+ needsUpdate = true;
508
+
509
+ }
510
+
511
+ }
512
+
513
+ } else {
514
+
515
+ if ( drawBuffers[ 0 ] !== gl.BACK ) {
516
+
517
+ drawBuffers[ 0 ] = gl.BACK;
518
+
519
+ needsUpdate = true;
520
+
521
+ }
522
+
523
+ }
524
+
525
+ if ( needsUpdate ) {
526
+
527
+ if ( capabilities.isWebGL2 ) {
528
+
529
+ gl.drawBuffers( drawBuffers );
530
+
531
+ } else {
532
+
533
+ extensions.get( 'WEBGL_draw_buffers' ).drawBuffersWEBGL( drawBuffers );
534
+
535
+ }
536
+
537
+ }
538
+
539
+
540
+ }
541
+
464
542
  function useProgram( program ) {
465
543
 
466
544
  if ( currentProgram !== program ) {
@@ -1047,6 +1125,8 @@ function WebGLState( gl, extensions, capabilities ) {
1047
1125
  currentBoundTextures = {};
1048
1126
 
1049
1127
  currentBoundFramebuffers = {};
1128
+ currentDrawbuffers = new WeakMap();
1129
+ defaultDrawbuffers = [];
1050
1130
 
1051
1131
  currentProgram = null;
1052
1132
 
@@ -1089,6 +1169,7 @@ function WebGLState( gl, extensions, capabilities ) {
1089
1169
  disable: disable,
1090
1170
 
1091
1171
  bindFramebuffer: bindFramebuffer,
1172
+ drawBuffers: drawBuffers,
1092
1173
 
1093
1174
  useProgram: useProgram,
1094
1175
 
@@ -1,5 +1,6 @@
1
- import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBFormat, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, sRGBEncoding } from '../../constants.js';
1
+ import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, sRGBEncoding, LinearEncoding, UnsignedByteType, _SRGBAFormat } from '../../constants.js';
2
2
  import * as MathUtils from '../../math/MathUtils.js';
3
+ import { ImageUtils } from '../../extras/ImageUtils.js';
3
4
  import { createElementNS } from '../../utils.js';
4
5
 
5
6
  function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
@@ -130,7 +131,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
130
131
 
131
132
  }
132
133
 
133
- function getInternalFormat( internalFormatName, glFormat, glType, encoding ) {
134
+ function getInternalFormat( internalFormatName, glFormat, glType, encoding, isVideoTexture = false ) {
134
135
 
135
136
  if ( isWebGL2 === false ) return glFormat;
136
137
 
@@ -164,7 +165,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
164
165
 
165
166
  if ( glType === _gl.FLOAT ) internalFormat = _gl.RGBA32F;
166
167
  if ( glType === _gl.HALF_FLOAT ) internalFormat = _gl.RGBA16F;
167
- if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( encoding === sRGBEncoding ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
168
+ if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = ( encoding === sRGBEncoding && isVideoTexture === false ) ? _gl.SRGB8_ALPHA8 : _gl.RGBA8;
168
169
 
169
170
  }
170
171
 
@@ -550,13 +551,14 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
550
551
  _gl.pixelStorei( _gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, _gl.NONE );
551
552
 
552
553
  const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
553
- const image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
554
+ let image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
555
+ image = verifyColorSpace( texture, image );
554
556
 
555
557
  const supportsMips = isPowerOfTwo( image ) || isWebGL2,
556
- glFormat = utils.convert( texture.format );
558
+ glFormat = utils.convert( texture.format, texture.encoding );
557
559
 
558
560
  let glType = utils.convert( texture.type ),
559
- glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
561
+ glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding, texture.isVideoTexture );
560
562
 
561
563
  setTextureParameters( textureType, texture, supportsMips );
562
564
 
@@ -717,7 +719,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
717
719
 
718
720
  mipmap = mipmaps[ i ];
719
721
 
720
- if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
722
+ if ( texture.format !== RGBAFormat ) {
721
723
 
722
724
  if ( glFormat !== null ) {
723
725
 
@@ -900,11 +902,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
900
902
 
901
903
  }
902
904
 
905
+ cubeImage[ i ] = verifyColorSpace( texture, cubeImage[ i ] );
906
+
903
907
  }
904
908
 
905
909
  const image = cubeImage[ 0 ],
906
910
  supportsMips = isPowerOfTwo( image ) || isWebGL2,
907
- glFormat = utils.convert( texture.format ),
911
+ glFormat = utils.convert( texture.format, texture.encoding ),
908
912
  glType = utils.convert( texture.type ),
909
913
  glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
910
914
 
@@ -932,7 +936,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
932
936
 
933
937
  const mipmap = mipmaps[ j ];
934
938
 
935
- if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
939
+ if ( texture.format !== RGBAFormat ) {
936
940
 
937
941
  if ( glFormat !== null ) {
938
942
 
@@ -1069,7 +1073,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1069
1073
  // Setup storage for target texture and bind it to correct framebuffer
1070
1074
  function setupFrameBufferTexture( framebuffer, renderTarget, texture, attachment, textureTarget ) {
1071
1075
 
1072
- const glFormat = utils.convert( texture.format );
1076
+ const glFormat = utils.convert( texture.format, texture.encoding );
1073
1077
  const glType = utils.convert( texture.type );
1074
1078
  const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
1075
1079
  const renderTargetProperties = properties.get( renderTarget );
@@ -1177,7 +1181,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1177
1181
  // Use the first texture for MRT so far
1178
1182
  const texture = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture[ 0 ] : renderTarget.texture;
1179
1183
 
1180
- const glFormat = utils.convert( texture.format );
1184
+ const glFormat = utils.convert( texture.format, texture.encoding );
1181
1185
  const glType = utils.convert( texture.type );
1182
1186
  const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
1183
1187
  const samples = getRenderTargetSamples( renderTarget );
@@ -1351,16 +1355,6 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1351
1355
  const isRenderTarget3D = texture.isDataTexture3D || texture.isDataTexture2DArray;
1352
1356
  const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
1353
1357
 
1354
- // Handles WebGL2 RGBFormat fallback - #18858
1355
-
1356
- if ( isWebGL2 && texture.format === RGBFormat && ( texture.type === FloatType || texture.type === HalfFloatType ) ) {
1357
-
1358
- texture.format = RGBAFormat;
1359
-
1360
- console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' );
1361
-
1362
- }
1363
-
1364
1358
  // Setup framebuffer
1365
1359
 
1366
1360
  if ( isCube ) {
@@ -1412,7 +1406,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1412
1406
 
1413
1407
  _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer );
1414
1408
 
1415
- const glFormat = utils.convert( texture.format );
1409
+ const glFormat = utils.convert( texture.format, texture.encoding );
1416
1410
  const glType = utils.convert( texture.type );
1417
1411
  const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.encoding );
1418
1412
  const samples = getRenderTargetSamples( renderTarget );
@@ -1631,6 +1625,65 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
1631
1625
 
1632
1626
  }
1633
1627
 
1628
+ function verifyColorSpace( texture, image ) {
1629
+
1630
+ const encoding = texture.encoding;
1631
+ const format = texture.format;
1632
+ const type = texture.type;
1633
+
1634
+ if ( texture.isCompressedTexture === true || texture.format === _SRGBAFormat ) return image;
1635
+
1636
+ if ( encoding !== LinearEncoding ) {
1637
+
1638
+ // sRGB
1639
+
1640
+ if ( encoding === sRGBEncoding && texture.isVideoTexture !== true ) {
1641
+
1642
+ if ( isWebGL2 === false ) {
1643
+
1644
+ // in WebGL 1, try to use EXT_sRGB extension and unsized formats
1645
+
1646
+ if ( extensions.has( 'EXT_sRGB' ) === true && format === RGBAFormat ) {
1647
+
1648
+ texture.format = _SRGBAFormat;
1649
+
1650
+ // it's not possible to generate mips in WebGL 1 with this extension
1651
+
1652
+ texture.minFilter = LinearFilter;
1653
+ texture.generateMipmaps = false;
1654
+
1655
+ } else {
1656
+
1657
+ // slow fallback (CPU decode)
1658
+
1659
+ image = ImageUtils.sRGBToLinear( image );
1660
+
1661
+ }
1662
+
1663
+ } else {
1664
+
1665
+ // in WebGL 2 uncompressed textures can only be sRGB encoded if they have the RGBA8 format
1666
+
1667
+ if ( format !== RGBAFormat || type !== UnsignedByteType ) {
1668
+
1669
+ console.warn( 'THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.' );
1670
+
1671
+ }
1672
+
1673
+ }
1674
+
1675
+ } else {
1676
+
1677
+ console.error( 'THREE.WebGLTextures: Unsupported texture encoding:', encoding );
1678
+
1679
+ }
1680
+
1681
+ }
1682
+
1683
+ return image;
1684
+
1685
+ }
1686
+
1634
1687
  // backwards compatibility
1635
1688
 
1636
1689
  let warnedTexture2D = false;