super-three 0.155.0 → 0.156.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 (108) hide show
  1. package/build/three.cjs +107 -125
  2. package/build/three.js +107 -125
  3. package/build/three.min.js +1 -1
  4. package/build/three.module.js +104 -126
  5. package/build/three.module.min.js +1 -1
  6. package/examples/jsm/controls/OrbitControls.js +13 -5
  7. package/examples/jsm/csm/CSMShader.js +35 -1
  8. package/examples/jsm/libs/tween.module.js +790 -735
  9. package/examples/jsm/libs/utif.module.js +1644 -1558
  10. package/examples/jsm/loaders/DDSLoader.js +46 -3
  11. package/examples/jsm/loaders/EXRLoader.js +4 -4
  12. package/examples/jsm/loaders/FBXLoader.js +2 -0
  13. package/examples/jsm/loaders/GLTFLoader.js +17 -7
  14. package/examples/jsm/loaders/KTX2Loader.js +126 -77
  15. package/examples/jsm/loaders/LogLuvLoader.js +2 -2
  16. package/examples/jsm/loaders/MMDLoader.js +10 -7
  17. package/examples/jsm/loaders/RGBELoader.js +48 -66
  18. package/examples/jsm/loaders/STLLoader.js +7 -0
  19. package/examples/jsm/nodes/Nodes.js +3 -0
  20. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +28 -2
  21. package/examples/jsm/nodes/accessors/CubeTextureNode.js +18 -3
  22. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +2 -4
  23. package/examples/jsm/nodes/accessors/LineMaterialNode.js +31 -0
  24. package/examples/jsm/nodes/accessors/MaterialNode.js +55 -33
  25. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +3 -0
  26. package/examples/jsm/nodes/accessors/Object3DNode.js +2 -2
  27. package/examples/jsm/nodes/accessors/TextureNode.js +6 -2
  28. package/examples/jsm/nodes/accessors/TextureStoreNode.js +29 -0
  29. package/examples/jsm/nodes/core/AttributeNode.js +2 -2
  30. package/examples/jsm/nodes/core/Node.js +17 -1
  31. package/examples/jsm/nodes/core/NodeBuilder.js +94 -12
  32. package/examples/jsm/nodes/core/NodeUniform.js +1 -1
  33. package/examples/jsm/nodes/core/OutputStructNode.js +58 -0
  34. package/examples/jsm/nodes/core/PropertyNode.js +2 -0
  35. package/examples/jsm/nodes/core/StackNode.js +4 -4
  36. package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
  37. package/examples/jsm/nodes/display/ViewportNode.js +19 -5
  38. package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
  39. package/examples/jsm/nodes/materials/Materials.js +1 -0
  40. package/examples/jsm/nodes/materials/NodeMaterial.js +12 -3
  41. package/examples/jsm/nodes/math/HashNode.js +35 -0
  42. package/examples/jsm/nodes/shadernode/ShaderNode.js +4 -0
  43. package/examples/jsm/nodes/utils/SplitNode.js +1 -1
  44. package/examples/jsm/postprocessing/FilmPass.js +3 -5
  45. package/examples/jsm/postprocessing/RenderPass.js +30 -12
  46. package/examples/jsm/postprocessing/SAOPass.js +23 -98
  47. package/examples/jsm/postprocessing/SSAOPass.js +10 -30
  48. package/examples/jsm/renderers/common/Backend.js +11 -8
  49. package/examples/jsm/renderers/common/Binding.js +6 -0
  50. package/examples/jsm/renderers/common/Bindings.js +5 -4
  51. package/examples/jsm/renderers/common/Pipelines.js +2 -2
  52. package/examples/jsm/renderers/common/RenderContexts.js +26 -1
  53. package/examples/jsm/renderers/common/RenderList.js +12 -4
  54. package/examples/jsm/renderers/common/RenderObject.js +6 -2
  55. package/examples/jsm/renderers/common/Renderer.js +12 -3
  56. package/examples/jsm/renderers/common/SampledTexture.js +2 -1
  57. package/examples/jsm/renderers/common/Sampler.js +1 -1
  58. package/examples/jsm/renderers/common/StorageBuffer.js +1 -1
  59. package/examples/jsm/renderers/common/Textures.js +155 -15
  60. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +2 -2
  61. package/examples/jsm/renderers/common/nodes/NodeSampler.js +1 -1
  62. package/examples/jsm/renderers/common/nodes/Nodes.js +43 -9
  63. package/examples/jsm/renderers/webgl/WebGLBackend.js +607 -0
  64. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +118 -17
  65. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +84 -0
  66. package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +26 -0
  67. package/examples/jsm/renderers/webgl/utils/WebGLState.js +529 -0
  68. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +199 -0
  69. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +242 -0
  70. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +340 -0
  71. package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +1 -1
  72. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +279 -40
  73. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +18 -2
  74. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +89 -59
  75. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -2
  76. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +15 -2
  77. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +34 -9
  78. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +26 -135
  79. package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +6 -5
  80. package/examples/jsm/shaders/FilmShader.js +11 -54
  81. package/examples/jsm/shaders/SAOShader.js +0 -13
  82. package/examples/jsm/shaders/SSAOShader.js +33 -26
  83. package/package.json +1 -1
  84. package/src/Three.js +1 -0
  85. package/src/audio/Audio.js +6 -0
  86. package/src/constants.js +4 -1
  87. package/src/core/Object3D.js +1 -14
  88. package/src/core/UniformsGroup.js +2 -2
  89. package/src/loaders/DataTextureLoader.js +0 -2
  90. package/src/materials/Material.js +2 -2
  91. package/src/math/Vector2.js +2 -2
  92. package/src/math/Vector3.js +3 -3
  93. package/src/math/Vector4.js +4 -4
  94. package/src/objects/Line.js +1 -1
  95. package/src/objects/Mesh.js +1 -1
  96. package/src/objects/Points.js +1 -1
  97. package/src/renderers/WebGLRenderer.js +21 -49
  98. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +11 -1
  99. package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
  100. package/src/renderers/webgl/WebGLBackground.js +5 -14
  101. package/src/renderers/webgl/WebGLProgram.js +2 -0
  102. package/src/renderers/webgl/WebGLPrograms.js +5 -1
  103. package/src/renderers/webgl/WebGLTextures.js +4 -4
  104. package/src/renderers/webgl/WebGLUtils.js +27 -20
  105. package/src/textures/Texture.js +2 -2
  106. package/src/utils.js +9 -1
  107. /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +0 -0
  108. /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodes.js +0 -0
@@ -2,7 +2,7 @@ import { EventDispatcher } from '../core/EventDispatcher.js';
2
2
  import { FrontSide, NormalBlending, LessEqualDepth, AddEquation, OneMinusSrcAlphaFactor, SrcAlphaFactor, AlwaysStencilFunc, KeepStencilOp } from '../constants.js';
3
3
  import * as MathUtils from '../math/MathUtils.js';
4
4
 
5
- let materialId = 0;
5
+ let _materialId = 0;
6
6
 
7
7
  class Material extends EventDispatcher {
8
8
 
@@ -12,7 +12,7 @@ class Material extends EventDispatcher {
12
12
 
13
13
  this.isMaterial = true;
14
14
 
15
- Object.defineProperty( this, 'id', { value: materialId ++ } );
15
+ Object.defineProperty( this, 'id', { value: _materialId ++ } );
16
16
 
17
17
  this.uuid = MathUtils.generateUUID();
18
18
 
@@ -293,8 +293,8 @@ class Vector2 {
293
293
 
294
294
  roundToZero() {
295
295
 
296
- this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
297
- this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
296
+ this.x = Math.trunc( this.x );
297
+ this.y = Math.trunc( this.y );
298
298
 
299
299
  return this;
300
300
 
@@ -397,9 +397,9 @@ class Vector3 {
397
397
 
398
398
  roundToZero() {
399
399
 
400
- this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
401
- this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
402
- this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
400
+ this.x = Math.trunc( this.x );
401
+ this.y = Math.trunc( this.y );
402
+ this.z = Math.trunc( this.z );
403
403
 
404
404
  return this;
405
405
 
@@ -502,10 +502,10 @@ class Vector4 {
502
502
 
503
503
  roundToZero() {
504
504
 
505
- this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
506
- this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
507
- this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
508
- this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
505
+ this.x = Math.trunc( this.x );
506
+ this.y = Math.trunc( this.y );
507
+ this.z = Math.trunc( this.z );
508
+ this.w = Math.trunc( this.w );
509
509
 
510
510
  return this;
511
511
 
@@ -34,7 +34,7 @@ class Line extends Object3D {
34
34
 
35
35
  super.copy( source, recursive );
36
36
 
37
- this.material = source.material;
37
+ this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
38
38
  this.geometry = source.geometry;
39
39
 
40
40
  return this;
@@ -65,7 +65,7 @@ class Mesh extends Object3D {
65
65
 
66
66
  }
67
67
 
68
- this.material = source.material;
68
+ this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
69
69
  this.geometry = source.geometry;
70
70
 
71
71
  return this;
@@ -32,7 +32,7 @@ class Points extends Object3D {
32
32
 
33
33
  super.copy( source, recursive );
34
34
 
35
- this.material = source.material;
35
+ this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
36
36
  this.geometry = source.geometry;
37
37
 
38
38
  return this;
@@ -59,15 +59,7 @@ import { WebVRManager } from './webvr/WebVRManager.js';
59
59
  import { WebXRManager } from './webxr/WebXRManager.js';
60
60
  import { WebGLMaterials } from './webgl/WebGLMaterials.js';
61
61
  import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
62
- import { createElementNS } from '../utils.js';
63
-
64
- function createCanvasElement() {
65
-
66
- const canvas = createElementNS( 'canvas' );
67
- canvas.style.display = 'block';
68
- return canvas;
69
-
70
- }
62
+ import { createCanvasElement } from '../utils.js';
71
63
 
72
64
  class WebGLRenderer {
73
65
 
@@ -1799,48 +1791,28 @@ class WebGLRenderer {
1799
1791
 
1800
1792
  if ( refreshProgram || _currentCamera !== camera ) {
1801
1793
 
1802
- p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
1803
-
1804
- if ( capabilities.logarithmicDepthBuffer ) {
1805
-
1806
- p_uniforms.setValue( _gl, 'logDepthBufFC',
1807
- 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
1808
-
1809
- }
1794
+ // common camera uniforms
1810
1795
 
1811
- if ( _currentCamera !== camera ) {
1796
+ p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
1797
+ p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
1812
1798
 
1813
- _currentCamera = camera;
1799
+ const uCamPos = p_uniforms.map.cameraPosition;
1814
1800
 
1815
- // lighting uniforms depend on the camera so enforce an update
1816
- // now, in case this material supports lights - or later, when
1817
- // the next material that does gets activated:
1801
+ if ( uCamPos !== undefined ) {
1818
1802
 
1819
- refreshMaterial = true; // set to true on material change
1820
- refreshLights = true; // remains set until update done
1803
+ uCamPos.setValue( _gl, _vector3.setFromMatrixPosition( camera.matrixWorld ) );
1821
1804
 
1822
1805
  }
1823
1806
 
1824
- // load material specific uniforms
1825
- // (shader material also gets them for the sake of genericity)
1826
-
1827
- if ( material.isShaderMaterial ||
1828
- material.isMeshPhongMaterial ||
1829
- material.isMeshToonMaterial ||
1830
- material.isMeshStandardMaterial ||
1831
- material.envMap ) {
1832
-
1833
- const uCamPos = p_uniforms.map.cameraPosition;
1834
-
1835
- if ( uCamPos !== undefined ) {
1836
-
1837
- uCamPos.setValue( _gl,
1838
- _vector3.setFromMatrixPosition( camera.matrixWorld ) );
1807
+ if ( capabilities.logarithmicDepthBuffer ) {
1839
1808
 
1840
- }
1809
+ p_uniforms.setValue( _gl, 'logDepthBufFC',
1810
+ 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
1841
1811
 
1842
1812
  }
1843
1813
 
1814
+ // consider moving isOrthographic to UniformLib and WebGLMaterials, see https://github.com/mrdoob/three.js/pull/26467#issuecomment-1645185067
1815
+
1844
1816
  if ( material.isMeshPhongMaterial ||
1845
1817
  material.isMeshToonMaterial ||
1846
1818
  material.isMeshLambertMaterial ||
@@ -1852,16 +1824,16 @@ class WebGLRenderer {
1852
1824
 
1853
1825
  }
1854
1826
 
1855
- if ( material.isMeshPhongMaterial ||
1856
- material.isMeshToonMaterial ||
1857
- material.isMeshLambertMaterial ||
1858
- material.isMeshBasicMaterial ||
1859
- material.isMeshStandardMaterial ||
1860
- material.isShaderMaterial ||
1861
- material.isShadowMaterial ||
1862
- object.isSkinnedMesh ) {
1827
+ if ( _currentCamera !== camera ) {
1863
1828
 
1864
- p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
1829
+ _currentCamera = camera;
1830
+
1831
+ // lighting uniforms depend on the camera so enforce an update
1832
+ // now, in case this material supports lights - or later, when
1833
+ // the next material that does gets activated:
1834
+
1835
+ refreshMaterial = true; // set to true on material change
1836
+ refreshLights = true; // remains set until update done
1865
1837
 
1866
1838
  }
1867
1839
 
@@ -1,7 +1,17 @@
1
1
  export default /* glsl */`
2
2
  #ifdef USE_MAP
3
3
 
4
- diffuseColor *= texture2D( map, vMapUv );
4
+ vec4 sampledDiffuseColor = texture2D( map, vMapUv );
5
+
6
+ #ifdef DECODE_VIDEO_TEXTURE
7
+
8
+ // use inline sRGB decode until browsers properly support SRGB8_APLHA8 with video textures
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
+
12
+ #endif
13
+
14
+ diffuseColor *= sampledDiffuseColor;
5
15
 
6
16
  #endif
7
17
  `;
@@ -21,6 +21,14 @@ void main() {
21
21
 
22
22
  vec4 texColor = texture2D( t2D, vUv );
23
23
 
24
+ #ifdef DECODE_VIDEO_TEXTURE
25
+
26
+ // use inline sRGB decode until browsers properly support SRGB8_APLHA8 with video textures
27
+
28
+ texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
29
+
30
+ #endif
31
+
24
32
  texColor.rgb *= backgroundIntensity;
25
33
 
26
34
  gl_FragColor = texColor;
@@ -44,24 +44,15 @@ function WebGLBackground( renderer, cubemaps, cubeuvmaps, state, objects, alpha,
44
44
 
45
45
  }
46
46
 
47
- const xr = renderer.xr;
48
- const environmentBlendMode = xr.getEnvironmentBlendMode();
47
+ const environmentBlendMode = renderer.xr.getEnvironmentBlendMode();
49
48
 
50
- switch ( environmentBlendMode ) {
49
+ if ( environmentBlendMode === 'additive' ) {
51
50
 
52
- case 'opaque':
53
- forceClear = true;
54
- break;
51
+ state.buffers.color.setClear( 0, 0, 0, 1, premultipliedAlpha );
55
52
 
56
- case 'additive':
57
- state.buffers.color.setClear( 0, 0, 0, 1, premultipliedAlpha );
58
- forceClear = true;
59
- break;
53
+ } else if ( environmentBlendMode === 'alpha-blend' ) {
60
54
 
61
- case 'alpha-blend':
62
- state.buffers.color.setClear( 0, 0, 0, 0, premultipliedAlpha );
63
- forceClear = true;
64
- break;
55
+ state.buffers.color.setClear( 0, 0, 0, 0, premultipliedAlpha );
65
56
 
66
57
  }
67
58
 
@@ -765,6 +765,8 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
765
765
 
766
766
  parameters.useLegacyLights ? '#define LEGACY_LIGHTS' : '',
767
767
 
768
+ parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
769
+
768
770
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
769
771
  ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
770
772
 
@@ -1,4 +1,4 @@
1
- import { BackSide, DoubleSide, CubeUVReflectionMapping, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping, NormalBlending, LinearSRGBColorSpace } from '../../constants.js';
1
+ import { BackSide, DoubleSide, CubeUVReflectionMapping, ObjectSpaceNormalMap, TangentSpaceNormalMap, NoToneMapping, NormalBlending, LinearSRGBColorSpace, SRGBColorSpace } 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';
@@ -335,6 +335,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
335
335
  toneMapping: toneMapping,
336
336
  useLegacyLights: renderer._useLegacyLights,
337
337
 
338
+ decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( material.map.colorSpace === SRGBColorSpace ),
339
+
338
340
  premultipliedAlpha: material.premultipliedAlpha,
339
341
 
340
342
  doubleSided: material.side === DoubleSide,
@@ -536,6 +538,8 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
536
538
  _programLayers.enable( 17 );
537
539
  if ( parameters.pointsUvs )
538
540
  _programLayers.enable( 18 );
541
+ if ( parameters.decodeVideoTexture )
542
+ _programLayers.enable( 19 );
539
543
 
540
544
  array.push( _programLayers.mask );
541
545
 
@@ -1,4 +1,4 @@
1
- import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, UnsignedByteType, _SRGBAFormat, NoColorSpace, LinearSRGBColorSpace, SRGBColorSpace, NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare } from '../../constants.js';
1
+ import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, UnsignedByteType, _SRGBAFormat, NoColorSpace, LinearSRGBColorSpace, SRGBColorSpace, NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, DisplayP3ColorSpace } from '../../constants.js';
2
2
  import * as MathUtils from '../../math/MathUtils.js';
3
3
  import { ImageUtils } from '../../extras/ImageUtils.js';
4
4
  import { createElementNS } from '../../utils.js';
@@ -748,7 +748,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
748
748
  glFormat = utils.convert( texture.format, texture.colorSpace );
749
749
 
750
750
  let glType = utils.convert( texture.type ),
751
- glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
751
+ glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture );
752
752
 
753
753
  setTextureParameters( textureType, texture, supportsMips );
754
754
 
@@ -2027,13 +2027,13 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
2027
2027
  const format = texture.format;
2028
2028
  const type = texture.type;
2029
2029
 
2030
- if ( texture.isCompressedTexture === true || texture.format === _SRGBAFormat ) return image;
2030
+ if ( texture.isCompressedTexture === true || texture.isVideoTexture === true || texture.format === _SRGBAFormat ) return image;
2031
2031
 
2032
2032
  if ( colorSpace !== LinearSRGBColorSpace && colorSpace !== NoColorSpace ) {
2033
2033
 
2034
2034
  // sRGB
2035
2035
 
2036
- if ( colorSpace === SRGBColorSpace ) {
2036
+ if ( colorSpace === SRGBColorSpace || colorSpace === DisplayP3ColorSpace ) {
2037
2037
 
2038
2038
  if ( isWebGL2 === false ) {
2039
2039
 
@@ -1,4 +1,7 @@
1
- import { RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RedFormat, RGBAFormat, AlphaFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, RGBA_BPTC_Format, _SRGBAFormat, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, SRGBColorSpace, NoColorSpace } from '../../constants.js';
1
+ import { RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RedFormat, RGBAFormat, AlphaFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, RGBA_BPTC_Format, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, _SRGBAFormat, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, SRGBColorSpace, NoColorSpace, DisplayP3ColorSpace } from '../../constants.js';
2
+
3
+ const LinearTransferFunction = 0;
4
+ const SRGBTransferFunction = 1;
2
5
 
3
6
  function WebGLUtils( gl, extensions, capabilities ) {
4
7
 
@@ -8,6 +11,8 @@ function WebGLUtils( gl, extensions, capabilities ) {
8
11
 
9
12
  let extension;
10
13
 
14
+ const transferFunction = ( colorSpace === SRGBColorSpace || colorSpace === DisplayP3ColorSpace ) ? SRGBTransferFunction : LinearTransferFunction;
15
+
11
16
  if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
12
17
  if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
13
18
  if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
@@ -74,7 +79,7 @@ function WebGLUtils( gl, extensions, capabilities ) {
74
79
 
75
80
  if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
76
81
 
77
- if ( colorSpace === SRGBColorSpace ) {
82
+ if ( transferFunction === SRGBTransferFunction ) {
78
83
 
79
84
  extension = extensions.get( 'WEBGL_compressed_texture_s3tc_srgb' );
80
85
 
@@ -159,8 +164,8 @@ function WebGLUtils( gl, extensions, capabilities ) {
159
164
 
160
165
  if ( extension !== null ) {
161
166
 
162
- if ( p === RGB_ETC2_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
163
- if ( p === RGBA_ETC2_EAC_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC;
167
+ if ( p === RGB_ETC2_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
168
+ if ( p === RGBA_ETC2_EAC_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC;
164
169
 
165
170
  } else {
166
171
 
@@ -182,20 +187,20 @@ function WebGLUtils( gl, extensions, capabilities ) {
182
187
 
183
188
  if ( extension !== null ) {
184
189
 
185
- if ( p === RGBA_ASTC_4x4_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR;
186
- if ( p === RGBA_ASTC_5x4_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR;
187
- if ( p === RGBA_ASTC_5x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR;
188
- if ( p === RGBA_ASTC_6x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR;
189
- if ( p === RGBA_ASTC_6x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR;
190
- if ( p === RGBA_ASTC_8x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR;
191
- if ( p === RGBA_ASTC_8x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR;
192
- if ( p === RGBA_ASTC_8x8_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR;
193
- if ( p === RGBA_ASTC_10x5_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR;
194
- if ( p === RGBA_ASTC_10x6_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR;
195
- if ( p === RGBA_ASTC_10x8_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR;
196
- if ( p === RGBA_ASTC_10x10_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR;
197
- if ( p === RGBA_ASTC_12x10_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR;
198
- if ( p === RGBA_ASTC_12x12_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR;
190
+ if ( p === RGBA_ASTC_4x4_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR;
191
+ if ( p === RGBA_ASTC_5x4_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR;
192
+ if ( p === RGBA_ASTC_5x5_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR;
193
+ if ( p === RGBA_ASTC_6x5_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR;
194
+ if ( p === RGBA_ASTC_6x6_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR;
195
+ if ( p === RGBA_ASTC_8x5_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR;
196
+ if ( p === RGBA_ASTC_8x6_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR;
197
+ if ( p === RGBA_ASTC_8x8_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR;
198
+ if ( p === RGBA_ASTC_10x5_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR;
199
+ if ( p === RGBA_ASTC_10x6_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR;
200
+ if ( p === RGBA_ASTC_10x8_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR;
201
+ if ( p === RGBA_ASTC_10x10_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR;
202
+ if ( p === RGBA_ASTC_12x10_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR;
203
+ if ( p === RGBA_ASTC_12x12_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR;
199
204
 
200
205
  } else {
201
206
 
@@ -207,13 +212,15 @@ function WebGLUtils( gl, extensions, capabilities ) {
207
212
 
208
213
  // BPTC
209
214
 
210
- if ( p === RGBA_BPTC_Format ) {
215
+ if ( p === RGBA_BPTC_Format || p === RGB_BPTC_SIGNED_Format || p === RGB_BPTC_UNSIGNED_Format ) {
211
216
 
212
217
  extension = extensions.get( 'EXT_texture_compression_bptc' );
213
218
 
214
219
  if ( extension !== null ) {
215
220
 
216
- if ( p === RGBA_BPTC_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT;
221
+ if ( p === RGBA_BPTC_Format ) return ( transferFunction === SRGBTransferFunction ) ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT;
222
+ if ( p === RGB_BPTC_SIGNED_Format ) return extension.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;
223
+ if ( p === RGB_BPTC_UNSIGNED_Format ) return extension.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT;
217
224
 
218
225
  } else {
219
226
 
@@ -19,7 +19,7 @@ import { Matrix3 } from '../math/Matrix3.js';
19
19
  import { Source } from './Source.js';
20
20
  import { warnOnce } from '../utils.js';
21
21
 
22
- let textureId = 0;
22
+ let _textureId = 0;
23
23
 
24
24
  class Texture extends EventDispatcher {
25
25
 
@@ -29,7 +29,7 @@ class Texture extends EventDispatcher {
29
29
 
30
30
  this.isTexture = true;
31
31
 
32
- Object.defineProperty( this, 'id', { value: textureId ++ } );
32
+ Object.defineProperty( this, 'id', { value: _textureId ++ } );
33
33
 
34
34
  this.uuid = MathUtils.generateUUID();
35
35
 
package/src/utils.js CHANGED
@@ -68,6 +68,14 @@ function createElementNS( name ) {
68
68
 
69
69
  }
70
70
 
71
+ function createCanvasElement() {
72
+
73
+ const canvas = createElementNS( 'canvas' );
74
+ canvas.style.display = 'block';
75
+ return canvas;
76
+
77
+ }
78
+
71
79
  const _cache = {};
72
80
 
73
81
  function warnOnce( message ) {
@@ -80,4 +88,4 @@ function warnOnce( message ) {
80
88
 
81
89
  }
82
90
 
83
- export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, warnOnce };
91
+ export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, createCanvasElement, warnOnce };