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
@@ -4,7 +4,7 @@ import {
4
4
 
5
5
  import {
6
6
  CubeTexture, Texture,
7
- NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter, LinearFilter,
7
+ NearestFilter, NearestMipmapNearestFilter, NearestMipmapLinearFilter,
8
8
  RepeatWrapping, MirroredRepeatWrapping,
9
9
  RGB_ETC2_Format, RGBA_ETC2_EAC_Format,
10
10
  RGBAFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBColorSpace, DepthFormat, DepthStencilFormat,
@@ -97,11 +97,13 @@ class WebGPUTextureUtils {
97
97
 
98
98
  }
99
99
 
100
- const { width, height, depth } = this._getSize( texture );
100
+ if ( options.needsMipmaps === undefined ) options.needsMipmaps = false;
101
+ if ( options.levels === undefined ) options.levels = 1;
102
+ if ( options.depth === undefined ) options.depth = 1;
103
+
104
+ const { width, height, depth, levels } = options;
101
105
 
102
- const needsMipmaps = this._needsMipmaps( texture );
103
106
  const dimension = this._getDimension( texture );
104
- const mipLevelCount = this._getMipLevelCount( texture, width, height, needsMipmaps );
105
107
  const format = texture.internalFormat || this._getFormat( texture );
106
108
 
107
109
  const sampleCount = options.sampleCount !== undefined ? options.sampleCount : 1;
@@ -109,6 +111,12 @@ class WebGPUTextureUtils {
109
111
 
110
112
  let usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC;
111
113
 
114
+ if ( options.store === true ) {
115
+
116
+ usage |= GPUTextureUsage.STORAGE_BINDING;
117
+
118
+ }
119
+
112
120
  if ( texture.isCompressedTexture !== true ) {
113
121
 
114
122
  usage |= GPUTextureUsage.RENDER_ATTACHMENT;
@@ -122,7 +130,7 @@ class WebGPUTextureUtils {
122
130
  height: height,
123
131
  depthOrArrayLayers: depth,
124
132
  },
125
- mipLevelCount: mipLevelCount,
133
+ mipLevelCount: levels,
126
134
  sampleCount: primarySampleCount,
127
135
  dimension: dimension,
128
136
  format: format,
@@ -170,7 +178,6 @@ class WebGPUTextureUtils {
170
178
 
171
179
  textureData.initialized = true;
172
180
 
173
- textureData.needsMipmaps = needsMipmaps;
174
181
  textureData.textureDescriptorGPU = textureDescriptorGPU;
175
182
 
176
183
  }
@@ -217,20 +224,20 @@ class WebGPUTextureUtils {
217
224
 
218
225
  }
219
226
 
220
- updateTexture( texture ) {
227
+ updateTexture( texture, options ) {
221
228
 
222
229
  const textureData = this.backend.get( texture );
223
230
 
224
- const { needsMipmaps, textureDescriptorGPU } = textureData;
231
+ const { textureDescriptorGPU } = textureData;
225
232
 
226
- if ( textureDescriptorGPU === undefined ) // unsupported texture format
233
+ if ( texture.isRenderTargetTexture || ( textureDescriptorGPU === undefined /* unsupported texture format */ ) )
227
234
  return;
228
235
 
229
236
  // transfer texture data
230
237
 
231
238
  if ( texture.isDataTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
232
239
 
233
- this._copyBufferToTexture( texture.image, textureData.texture, textureDescriptorGPU, needsMipmaps );
240
+ this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU );
234
241
 
235
242
  } else if ( texture.isCompressedTexture ) {
236
243
 
@@ -238,15 +245,7 @@ class WebGPUTextureUtils {
238
245
 
239
246
  } else if ( texture.isCubeTexture ) {
240
247
 
241
- if ( texture.image.length === 6 ) {
242
-
243
- this._copyCubeMapToTexture( texture.image, texture, textureData.texture, textureDescriptorGPU, needsMipmaps );
244
-
245
- }
246
-
247
- } else if ( texture.isRenderTargetTexture ) {
248
-
249
- if ( needsMipmaps === true ) this._generateMipmaps( textureData.texture, textureDescriptorGPU );
248
+ this._copyCubeMapToTexture( options.images, texture, textureData.texture, textureDescriptorGPU );
250
249
 
251
250
  } else if ( texture.isVideoTexture ) {
252
251
 
@@ -254,13 +253,9 @@ class WebGPUTextureUtils {
254
253
 
255
254
  textureData.externalTexture = video;
256
255
 
257
- } else if ( texture.image !== null ) {
258
-
259
- this._copyImageToTexture( texture.image, texture, textureData.texture, textureDescriptorGPU, needsMipmaps );
260
-
261
256
  } else {
262
257
 
263
- console.warn( 'WebGPUTextureUtils: Unable to update texture.' );
258
+ this._copyImageToTexture( options.image, textureData.texture );
264
259
 
265
260
  }
266
261
 
@@ -336,7 +331,7 @@ class WebGPUTextureUtils {
336
331
  texture.minFilter = NearestFilter;
337
332
  texture.magFilter = NearestFilter;
338
333
 
339
- this.createTexture( texture );
334
+ this.createTexture( texture, { width: 1, height: 1 } );
340
335
 
341
336
  this.defaultTexture = defaultTexture = texture;
342
337
 
@@ -356,7 +351,7 @@ class WebGPUTextureUtils {
356
351
  texture.minFilter = NearestFilter;
357
352
  texture.magFilter = NearestFilter;
358
353
 
359
- this.createTexture( texture );
354
+ this.createTexture( texture, { width: 1, height: 1, depth: 6 } );
360
355
 
361
356
  this.defaultCubeTexture = defaultCubeTexture = texture;
362
357
 
@@ -366,33 +361,7 @@ class WebGPUTextureUtils {
366
361
 
367
362
  }
368
363
 
369
- _copyImageToTexture( image, texture, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth ) {
370
-
371
- if ( this._isHTMLImage( image ) ) {
372
-
373
- this._getImageBitmapFromHTML( image, texture ).then( imageBitmap => {
374
-
375
- this._copyExternalImageToTexture( imageBitmap, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth );
376
-
377
- } );
378
-
379
- } else {
380
-
381
- // assume ImageBitmap
382
-
383
- this._copyExternalImageToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth );
384
-
385
- }
386
-
387
- }
388
-
389
- _isHTMLImage( image ) {
390
-
391
- return ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement );
392
-
393
- }
394
-
395
- _copyCubeMapToTexture( images, texture, textureGPU, textureDescriptorGPU, needsMipmaps ) {
364
+ _copyCubeMapToTexture( images, texture, textureGPU, textureDescriptorGPU ) {
396
365
 
397
366
  for ( let i = 0; i < 6; i ++ ) {
398
367
 
@@ -400,11 +369,11 @@ class WebGPUTextureUtils {
400
369
 
401
370
  if ( image.isDataTexture ) {
402
371
 
403
- this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, needsMipmaps, i );
372
+ this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, i );
404
373
 
405
374
  } else {
406
375
 
407
- this._copyImageToTexture( image, texture, textureGPU, textureDescriptorGPU, needsMipmaps, i );
376
+ this._copyImageToTexture( image, textureGPU, i );
408
377
 
409
378
  }
410
379
 
@@ -412,7 +381,7 @@ class WebGPUTextureUtils {
412
381
 
413
382
  }
414
383
 
415
- _copyExternalImageToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth = 0 ) {
384
+ _copyImageToTexture( image, textureGPU, originDepth = 0 ) {
416
385
 
417
386
  const device = this.backend.device;
418
387
 
@@ -430,8 +399,6 @@ class WebGPUTextureUtils {
430
399
  }
431
400
  );
432
401
 
433
- if ( needsMipmaps ) this._generateMipmaps( textureGPU, textureDescriptorGPU, originDepth );
434
-
435
402
  }
436
403
 
437
404
  _generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0 ) {
@@ -446,21 +413,7 @@ class WebGPUTextureUtils {
446
413
 
447
414
  }
448
415
 
449
- _getImageBitmapFromHTML( image, texture ) {
450
-
451
- const width = image.width;
452
- const height = image.height;
453
-
454
- const options = {};
455
-
456
- options.imageOrientation = ( texture.flipY === true ) ? 'flipY' : 'none';
457
- options.premultiplyAlpha = ( texture.premultiplyAlpha === true ) ? 'premultiply' : 'default';
458
-
459
- return createImageBitmap( image, 0, 0, width, height, options );
460
-
461
- }
462
-
463
- _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, needsMipmaps, originDepth = 0 ) {
416
+ _copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth = 0 ) {
464
417
 
465
418
  // @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
466
419
  // @TODO: Consider to support valid buffer layouts with other formats like RGB
@@ -489,8 +442,6 @@ class WebGPUTextureUtils {
489
442
  depthOrArrayLayers: ( image.depth !== undefined ) ? image.depth : 1
490
443
  } );
491
444
 
492
- if ( needsMipmaps === true ) this._generateMipmaps( textureGPU, textureDescriptorGPU, originDepth );
493
-
494
445
  }
495
446
 
496
447
  _copyCompressedBufferToTexture( mipmaps, textureGPU, textureDescriptorGPU ) {
@@ -600,44 +551,6 @@ class WebGPUTextureUtils {
600
551
 
601
552
  }
602
553
 
603
- _getSize( texture ) {
604
-
605
- const image = texture.image;
606
-
607
- let width, height, depth;
608
-
609
- if ( texture.isCubeTexture ) {
610
-
611
- const faceImage = image.length > 0 ? image[ 0 ].image || image[ 0 ] : null;
612
-
613
- width = faceImage ? faceImage.width : 1;
614
- height = faceImage ? faceImage.height : 1;
615
- depth = 6; // one image for each side of the cube map
616
-
617
- } else if ( image !== null ) {
618
-
619
- width = image.width;
620
- height = image.height;
621
- depth = ( image.depth !== undefined ) ? image.depth : 1;
622
-
623
- } else {
624
-
625
- width = height = depth = 1;
626
-
627
- }
628
-
629
- return { width, height, depth };
630
-
631
- }
632
-
633
- _needsMipmaps( texture ) {
634
-
635
- if ( this._isEnvironmentTexture( texture ) ) return true;
636
-
637
- return ( texture.isCompressedTexture !== true ) /*&& ( texture.generateMipmaps === true )*/ && ( texture.minFilter !== NearestFilter ) && ( texture.minFilter !== LinearFilter );
638
-
639
- }
640
-
641
554
  _getBytesPerTexel( format ) {
642
555
 
643
556
  if ( format === GPUTextureFormat.R8Unorm ) return 1;
@@ -706,28 +619,6 @@ class WebGPUTextureUtils {
706
619
 
707
620
  }
708
621
 
709
- _getMipLevelCount( texture, width, height, needsMipmaps ) {
710
-
711
- let mipLevelCount;
712
-
713
- if ( texture.isCompressedTexture ) {
714
-
715
- mipLevelCount = texture.mipmaps.length;
716
-
717
- } else if ( needsMipmaps ) {
718
-
719
- mipLevelCount = Math.floor( Math.log2( Math.max( width, height ) ) ) + 1;
720
-
721
- } else {
722
-
723
- mipLevelCount = 1; // a texture without mipmaps has a base mip (mipLevel 0)
724
-
725
- }
726
-
727
- return mipLevelCount;
728
-
729
- }
730
-
731
622
  _getFormat( texture ) {
732
623
 
733
624
  const format = texture.format;
@@ -40,9 +40,10 @@ class WebGPUUtils {
40
40
 
41
41
  let format;
42
42
 
43
- if ( renderContext.texture !== null ) {
43
+ if ( renderContext.textures !== null ) {
44
+
45
+ format = this.getTextureFormatGPU( renderContext.textures[ 0 ] );
44
46
 
45
- format = this.getTextureFormatGPU( renderContext.texture );
46
47
 
47
48
  } else {
48
49
 
@@ -56,9 +57,9 @@ class WebGPUUtils {
56
57
 
57
58
  getCurrentColorSpace( renderContext ) {
58
59
 
59
- if ( renderContext.texture !== null ) {
60
+ if ( renderContext.textures !== null ) {
60
61
 
61
- return renderContext.texture.colorSpace;
62
+ return renderContext.textures[ 0 ].colorSpace;
62
63
 
63
64
  }
64
65
 
@@ -77,7 +78,7 @@ class WebGPUUtils {
77
78
 
78
79
  getSampleCount( renderContext ) {
79
80
 
80
- if ( renderContext.texture !== null ) {
81
+ if ( renderContext.textures !== null ) {
81
82
 
82
83
  return renderContext.sampleCount;
83
84
 
@@ -1,23 +1,3 @@
1
- /**
2
- * Film grain & scanlines shader
3
- *
4
- * - ported from HLSL to WebGL / GLSL
5
- * https://web.archive.org/web/20210226214859/http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html
6
- *
7
- * Screen Space Static Postprocessor
8
- *
9
- * Produces an analogue noise overlay similar to a film grain / TV static
10
- *
11
- * Original implementation and noise algorithm
12
- * Pat 'Hawthorne' Shearon
13
- *
14
- * Optimized scanlines + noise version with intensity scaling
15
- * Georg 'Leviathan' Steinrohder
16
- *
17
- * This version is provided under a Creative Commons Attribution 3.0 License
18
- * http://creativecommons.org/licenses/by/3.0/
19
- */
20
-
21
1
  const FilmShader = {
22
2
 
23
3
  name: 'FilmShader',
@@ -26,10 +6,8 @@ const FilmShader = {
26
6
 
27
7
  'tDiffuse': { value: null },
28
8
  'time': { value: 0.0 },
29
- 'nIntensity': { value: 0.5 },
30
- 'sIntensity': { value: 0.05 },
31
- 'sCount': { value: 4096 },
32
- 'grayscale': { value: 1 }
9
+ 'intensity': { value: 0.5 },
10
+ 'grayscale': { value: false }
33
11
 
34
12
  },
35
13
 
@@ -48,19 +26,9 @@ const FilmShader = {
48
26
 
49
27
  #include <common>
50
28
 
51
- // control parameter
52
- uniform float time;
53
-
29
+ uniform float intensity;
54
30
  uniform bool grayscale;
55
-
56
- // noise effect intensity value (0 = no effect, 1 = full effect)
57
- uniform float nIntensity;
58
-
59
- // scanlines effect intensity value (0 = no effect, 1 = full effect)
60
- uniform float sIntensity;
61
-
62
- // scanlines effect count value (0 = no effect, 4096 = full effect)
63
- uniform float sCount;
31
+ uniform float time;
64
32
 
65
33
  uniform sampler2D tDiffuse;
66
34
 
@@ -68,32 +36,21 @@ const FilmShader = {
68
36
 
69
37
  void main() {
70
38
 
71
- // sample the source
72
- vec4 cTextureScreen = texture2D( tDiffuse, vUv );
73
-
74
- // make some noise
75
- float dx = rand( vUv + time );
76
-
77
- // add noise
78
- vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 );
39
+ vec4 base = texture2D( tDiffuse, vUv );
79
40
 
80
- // get us a sine and cosine
81
- vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );
41
+ float noise = rand( vUv + time );
82
42
 
83
- // add scanlines
84
- cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;
43
+ vec3 color = base.rgb + base.rgb * clamp( 0.1 + noise, 0.0, 1.0 );
85
44
 
86
- // interpolate between source and result by intensity
87
- cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );
45
+ color = mix( base.rgb, color, intensity );
88
46
 
89
- // convert to grayscale if desired
90
- if( grayscale ) {
47
+ if ( grayscale ) {
91
48
 
92
- cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );
49
+ color = vec3( luminance( color ) ); // assuming linear-srgb
93
50
 
94
51
  }
95
52
 
96
- gl_FragColor = vec4( cResult, cTextureScreen.a );
53
+ gl_FragColor = vec4( color, base.a );
97
54
 
98
55
  }`,
99
56
 
@@ -11,9 +11,7 @@ const SAOShader = {
11
11
  defines: {
12
12
  'NUM_SAMPLES': 7,
13
13
  'NUM_RINGS': 4,
14
- 'NORMAL_TEXTURE': 0,
15
14
  'DIFFUSE_TEXTURE': 0,
16
- 'DEPTH_PACKING': 1,
17
15
  'PERSPECTIVE_CAMERA': 1
18
16
  },
19
17
  uniforms: {
@@ -56,10 +54,7 @@ const SAOShader = {
56
54
  #endif
57
55
 
58
56
  uniform sampler2D tDepth;
59
-
60
- #if NORMAL_TEXTURE == 1
61
57
  uniform sampler2D tNormal;
62
- #endif
63
58
 
64
59
  uniform float cameraNear;
65
60
  uniform float cameraFar;
@@ -87,11 +82,7 @@ const SAOShader = {
87
82
  }
88
83
 
89
84
  float getDepth( const in vec2 screenPosition ) {
90
- #if DEPTH_PACKING == 1
91
- return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
92
- #else
93
85
  return texture2D( tDepth, screenPosition ).x;
94
- #endif
95
86
  }
96
87
 
97
88
  float getViewZ( const in float depth ) {
@@ -111,11 +102,7 @@ const SAOShader = {
111
102
  }
112
103
 
113
104
  vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {
114
- #if NORMAL_TEXTURE == 1
115
105
  return unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );
116
- #else
117
- return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );
118
- #endif
119
106
  }
120
107
 
121
108
  float scaleDividedByCameraFar;
@@ -19,7 +19,6 @@ const SSAOShader = {
19
19
 
20
20
  uniforms: {
21
21
 
22
- 'tDiffuse': { value: null },
23
22
  'tNormal': { value: null },
24
23
  'tDepth': { value: null },
25
24
  'tNoise': { value: null },
@@ -49,7 +48,6 @@ const SSAOShader = {
49
48
 
50
49
  fragmentShader: /* glsl */`
51
50
 
52
- uniform sampler2D tDiffuse;
53
51
  uniform sampler2D tNormal;
54
52
  uniform sampler2D tDepth;
55
53
  uniform sampler2D tNoise;
@@ -128,47 +126,56 @@ const SSAOShader = {
128
126
  void main() {
129
127
 
130
128
  float depth = getDepth( vUv );
131
- float viewZ = getViewZ( depth );
132
129
 
133
- vec3 viewPosition = getViewPosition( vUv, depth, viewZ );
134
- vec3 viewNormal = getViewNormal( vUv );
130
+ if ( depth == 1.0 ) {
131
+
132
+ gl_FragColor = vec4( 1.0 ); // don't influence background
133
+
134
+ } else {
135
+
136
+ float viewZ = getViewZ( depth );
137
+
138
+ vec3 viewPosition = getViewPosition( vUv, depth, viewZ );
139
+ vec3 viewNormal = getViewNormal( vUv );
135
140
 
136
- vec2 noiseScale = vec2( resolution.x / 4.0, resolution.y / 4.0 );
137
- vec3 random = vec3( texture2D( tNoise, vUv * noiseScale ).r );
141
+ vec2 noiseScale = vec2( resolution.x / 4.0, resolution.y / 4.0 );
142
+ vec3 random = vec3( texture2D( tNoise, vUv * noiseScale ).r );
138
143
 
139
- // compute matrix used to reorient a kernel vector
144
+ // compute matrix used to reorient a kernel vector
140
145
 
141
- vec3 tangent = normalize( random - viewNormal * dot( random, viewNormal ) );
142
- vec3 bitangent = cross( viewNormal, tangent );
143
- mat3 kernelMatrix = mat3( tangent, bitangent, viewNormal );
146
+ vec3 tangent = normalize( random - viewNormal * dot( random, viewNormal ) );
147
+ vec3 bitangent = cross( viewNormal, tangent );
148
+ mat3 kernelMatrix = mat3( tangent, bitangent, viewNormal );
144
149
 
145
- float occlusion = 0.0;
150
+ float occlusion = 0.0;
146
151
 
147
- for ( int i = 0; i < KERNEL_SIZE; i ++ ) {
152
+ for ( int i = 0; i < KERNEL_SIZE; i ++ ) {
148
153
 
149
- vec3 sampleVector = kernelMatrix * kernel[ i ]; // reorient sample vector in view space
150
- vec3 samplePoint = viewPosition + ( sampleVector * kernelRadius ); // calculate sample point
154
+ vec3 sampleVector = kernelMatrix * kernel[ i ]; // reorient sample vector in view space
155
+ vec3 samplePoint = viewPosition + ( sampleVector * kernelRadius ); // calculate sample point
151
156
 
152
- vec4 samplePointNDC = cameraProjectionMatrix * vec4( samplePoint, 1.0 ); // project point and calculate NDC
153
- samplePointNDC /= samplePointNDC.w;
157
+ vec4 samplePointNDC = cameraProjectionMatrix * vec4( samplePoint, 1.0 ); // project point and calculate NDC
158
+ samplePointNDC /= samplePointNDC.w;
154
159
 
155
- vec2 samplePointUv = samplePointNDC.xy * 0.5 + 0.5; // compute uv coordinates
160
+ vec2 samplePointUv = samplePointNDC.xy * 0.5 + 0.5; // compute uv coordinates
156
161
 
157
- float realDepth = getLinearDepth( samplePointUv ); // get linear depth from depth texture
158
- float sampleDepth = viewZToOrthographicDepth( samplePoint.z, cameraNear, cameraFar ); // compute linear depth of the sample view Z value
159
- float delta = sampleDepth - realDepth;
162
+ float realDepth = getLinearDepth( samplePointUv ); // get linear depth from depth texture
163
+ float sampleDepth = viewZToOrthographicDepth( samplePoint.z, cameraNear, cameraFar ); // compute linear depth of the sample view Z value
164
+ float delta = sampleDepth - realDepth;
160
165
 
161
- if ( delta > minDistance && delta < maxDistance ) { // if fragment is before sample point, increase occlusion
166
+ if ( delta > minDistance && delta < maxDistance ) { // if fragment is before sample point, increase occlusion
162
167
 
163
- occlusion += 1.0;
168
+ occlusion += 1.0;
169
+
170
+ }
164
171
 
165
172
  }
166
173
 
167
- }
174
+ occlusion = clamp( occlusion / float( KERNEL_SIZE ), 0.0, 1.0 );
168
175
 
169
- occlusion = clamp( occlusion / float( KERNEL_SIZE ), 0.0, 1.0 );
176
+ gl_FragColor = vec4( vec3( 1.0 - occlusion ), 1.0 );
170
177
 
171
- gl_FragColor = vec4( vec3( 1.0 - occlusion ), 1.0 );
178
+ }
172
179
 
173
180
  }`
174
181
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "super-three",
3
- "version": "0.155.0",
3
+ "version": "0.156.0",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.js",
package/src/Three.js CHANGED
@@ -158,6 +158,7 @@ export { ImageUtils } from './extras/ImageUtils.js';
158
158
  export { ShapeUtils } from './extras/ShapeUtils.js';
159
159
  export { PMREMGenerator } from './extras/PMREMGenerator.js';
160
160
  export { WebGLUtils } from './renderers/webgl/WebGLUtils.js';
161
+ export { createCanvasElement } from './utils.js';
161
162
  export * from './constants.js';
162
163
  export * from './Three.Legacy.js';
163
164
 
@@ -210,6 +210,12 @@ class Audio extends Object3D {
210
210
 
211
211
  disconnect() {
212
212
 
213
+ if ( this._connected === false ) {
214
+
215
+ return;
216
+
217
+ }
218
+
213
219
  if ( this.filters.length > 0 ) {
214
220
 
215
221
  this.source.disconnect( this.filters[ 0 ] );
package/src/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const REVISION = '155';
1
+ export const REVISION = '156';
2
2
 
3
3
  export const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
4
4
  export const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
@@ -122,6 +122,8 @@ export const RGBA_ASTC_10x10_Format = 37819;
122
122
  export const RGBA_ASTC_12x10_Format = 37820;
123
123
  export const RGBA_ASTC_12x12_Format = 37821;
124
124
  export const RGBA_BPTC_Format = 36492;
125
+ export const RGB_BPTC_SIGNED_Format = 36494;
126
+ export const RGB_BPTC_UNSIGNED_Format = 36495;
125
127
  export const RED_RGTC1_Format = 36283;
126
128
  export const SIGNED_RED_RGTC1_Format = 36284;
127
129
  export const RED_GREEN_RGTC2_Format = 36285;
@@ -154,6 +156,7 @@ export const NoColorSpace = '';
154
156
  export const SRGBColorSpace = 'srgb';
155
157
  export const LinearSRGBColorSpace = 'srgb-linear';
156
158
  export const DisplayP3ColorSpace = 'display-p3';
159
+ export const LinearDisplayP3ColorSpace = 'display-p3-linear';
157
160
 
158
161
  export const ZeroStencilOp = 0;
159
162
  export const KeepStencilOp = 7680;
@@ -392,20 +392,7 @@ class Object3D extends EventDispatcher {
392
392
 
393
393
  clear() {
394
394
 
395
- for ( let i = 0; i < this.children.length; i ++ ) {
396
-
397
- const object = this.children[ i ];
398
-
399
- object.parent = null;
400
-
401
- object.dispatchEvent( _removedEvent );
402
-
403
- }
404
-
405
- this.children.length = 0;
406
-
407
- return this;
408
-
395
+ return this.remove( ... this.children );
409
396
 
410
397
  }
411
398
 
@@ -1,7 +1,7 @@
1
1
  import { EventDispatcher } from './EventDispatcher.js';
2
2
  import { StaticDrawUsage } from '../constants.js';
3
3
 
4
- let id = 0;
4
+ let _id = 0;
5
5
 
6
6
  class UniformsGroup extends EventDispatcher {
7
7
 
@@ -11,7 +11,7 @@ class UniformsGroup extends EventDispatcher {
11
11
 
12
12
  this.isUniformsGroup = true;
13
13
 
14
- Object.defineProperty( this, 'id', { value: id ++ } );
14
+ Object.defineProperty( this, 'id', { value: _id ++ } );
15
15
 
16
16
  this.name = '';
17
17
 
@@ -51,8 +51,6 @@ class DataTextureLoader extends Loader {
51
51
 
52
52
  }
53
53
 
54
- if ( ! texData ) return onError(); // TODO: Remove this when all loaders properly throw errors
55
-
56
54
  if ( texData.image !== undefined ) {
57
55
 
58
56
  texture.image = texData.image;