@plastic-software/three 0.179.0 → 0.180.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.
- package/build/three.cjs +167 -107
- package/build/three.core.js +112 -20
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +56 -90
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +30 -5
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +2896 -1048
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +2896 -1048
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +7 -7
- package/examples/jsm/controls/DragControls.js +6 -56
- package/examples/jsm/controls/FirstPersonControls.js +2 -2
- package/examples/jsm/controls/PointerLockControls.js +0 -8
- package/examples/jsm/exporters/GLTFExporter.js +30 -22
- package/examples/jsm/exporters/KTX2Exporter.js +4 -2
- package/examples/jsm/exporters/PLYExporter.js +1 -1
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lines/Line2.js +3 -3
- package/examples/jsm/lines/LineGeometry.js +1 -1
- package/examples/jsm/lines/LineSegments2.js +2 -2
- package/examples/jsm/lines/Wireframe.js +2 -2
- package/examples/jsm/lines/WireframeGeometry2.js +1 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
- package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
- package/examples/jsm/loaders/ColladaLoader.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +5 -5
- package/examples/jsm/loaders/GLTFLoader.js +9 -5
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
- package/examples/jsm/loaders/HDRLoader.js +486 -0
- package/examples/jsm/loaders/KTX2Loader.js +112 -32
- package/examples/jsm/loaders/RGBELoader.js +7 -473
- package/examples/jsm/loaders/TTFLoader.js +4 -4
- package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
- package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
- package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
- package/examples/jsm/math/ColorSpaces.js +19 -1
- package/examples/jsm/math/ConvexHull.js +2 -2
- package/examples/jsm/math/Lut.js +2 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
- package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
- package/examples/jsm/misc/Volume.js +1 -1
- package/examples/jsm/postprocessing/OutlinePass.js +1 -1
- package/examples/jsm/postprocessing/SSRPass.js +37 -8
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +22 -19
- package/examples/jsm/transpiler/TSLEncoder.js +2 -10
- package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
- package/examples/jsm/tsl/display/BloomNode.js +3 -3
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
- package/examples/jsm/tsl/display/GTAONode.js +8 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +47 -35
- package/examples/jsm/tsl/display/OutlineNode.js +2 -2
- package/examples/jsm/tsl/display/SSRNode.js +180 -65
- package/examples/jsm/tsl/display/TRAANode.js +1 -1
- package/examples/jsm/tsl/display/boxBlur.js +64 -0
- package/examples/jsm/tsl/display/hashBlur.js +15 -18
- package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
- package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
- package/examples/jsm/webxr/OculusHandModel.js +1 -1
- package/package.json +1 -1
- package/src/Three.Core.js +1 -0
- package/src/Three.TSL.js +29 -4
- package/src/animation/AnimationClip.js +17 -2
- package/src/constants.js +11 -3
- package/src/core/BufferGeometry.js +2 -2
- package/src/extras/TextureUtils.js +2 -1
- package/src/extras/lib/earcut.js +1 -1
- package/src/lights/webgpu/ProjectorLight.js +1 -1
- package/src/materials/Material.js +12 -0
- package/src/materials/MeshDistanceMaterial.js +1 -1
- package/src/materials/nodes/PointsNodeMaterial.js +81 -28
- package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
- package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
- package/src/math/ColorManagement.js +7 -1
- package/src/nodes/Nodes.js +3 -0
- package/src/nodes/TSL.js +3 -0
- package/src/nodes/accessors/BufferNode.js +1 -1
- package/src/nodes/accessors/Camera.js +133 -7
- package/src/nodes/accessors/ClippingNode.js +6 -5
- package/src/nodes/accessors/CubeTextureNode.js +2 -2
- package/src/nodes/accessors/InstanceNode.js +3 -1
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
- package/src/nodes/accessors/ReferenceNode.js +1 -1
- package/src/nodes/accessors/Texture3DNode.js +13 -0
- package/src/nodes/accessors/TextureNode.js +71 -19
- package/src/nodes/code/FunctionCallNode.js +19 -0
- package/src/nodes/code/FunctionNode.js +23 -0
- package/src/nodes/core/AssignNode.js +4 -3
- package/src/nodes/core/ContextNode.js +24 -0
- package/src/nodes/core/Node.js +16 -20
- package/src/nodes/core/NodeBuilder.js +48 -14
- package/src/nodes/core/NodeFrame.js +1 -1
- package/src/nodes/core/NodeUniform.js +1 -1
- package/src/nodes/core/NodeUtils.js +1 -2
- package/src/nodes/core/StackNode.js +29 -4
- package/src/nodes/core/StructNode.js +5 -5
- package/src/nodes/core/StructTypeNode.js +1 -0
- package/src/nodes/core/SubBuildNode.js +2 -2
- package/src/nodes/core/UniformNode.js +16 -9
- package/src/nodes/core/VarNode.js +0 -21
- package/src/nodes/display/FrontFacingNode.js +4 -8
- package/src/nodes/display/PassNode.js +1 -1
- package/src/nodes/display/ScreenNode.js +42 -13
- package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
- package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
- package/src/nodes/display/ViewportTextureNode.js +42 -12
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
- package/src/nodes/lighting/LightsNode.js +1 -1
- package/src/nodes/math/BitcastNode.js +156 -0
- package/src/nodes/math/ConditionalNode.js +18 -2
- package/src/nodes/math/MathNode.js +3 -15
- package/src/nodes/math/OperatorNode.js +4 -3
- package/src/nodes/tsl/TSLCore.js +432 -152
- package/src/nodes/utils/JoinNode.js +3 -1
- package/src/nodes/utils/MemberNode.js +58 -7
- package/src/nodes/utils/RTTNode.js +1 -1
- package/src/nodes/utils/ReflectorNode.js +51 -7
- package/src/nodes/utils/SampleNode.js +12 -2
- package/src/nodes/utils/SplitNode.js +11 -0
- package/src/nodes/utils/Timer.js +0 -47
- package/src/objects/BatchedMesh.js +2 -2
- package/src/objects/LOD.js +1 -1
- package/src/objects/Sprite.js +2 -2
- package/src/renderers/WebGLRenderer.js +1 -10
- package/src/renderers/common/Attributes.js +1 -1
- package/src/renderers/common/Backend.js +19 -1
- package/src/renderers/common/Bindings.js +2 -0
- package/src/renderers/common/ChainMap.js +1 -1
- package/src/renderers/common/DataMap.js +1 -1
- package/src/renderers/common/Pipelines.js +1 -1
- package/src/renderers/common/RenderContext.js +2 -2
- package/src/renderers/common/RenderObject.js +14 -2
- package/src/renderers/common/Renderer.js +39 -19
- package/src/renderers/common/SampledTexture.js +1 -1
- package/src/renderers/common/Sampler.js +25 -13
- package/src/renderers/common/Textures.js +34 -12
- package/src/renderers/common/TimestampQueryPool.js +3 -3
- package/src/renderers/common/XRManager.js +35 -19
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/NodeLibrary.js +5 -5
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +7 -15
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +1 -1
- package/src/renderers/webgl/WebGLProgram.js +4 -4
- package/src/renderers/webgl/WebGLShadowMap.js +1 -1
- package/src/renderers/webgl/WebGLTextures.js +1 -0
- package/src/renderers/webgl/WebGLUtils.js +3 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +186 -135
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +110 -17
- package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
- package/src/renderers/webgpu/WebGPUBackend.js +35 -31
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +124 -34
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +9 -18
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +114 -25
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
- package/src/renderers/webxr/WebXRManager.js +39 -24
- package/src/textures/ExternalTexture.js +15 -4
- package/src/textures/Source.js +1 -1
- package/src/textures/VideoTexture.js +0 -3
- package/examples/jsm/loaders/RGBMLoader.js +0 -1148
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
RGBAFormat, RGBFormat, RedFormat, RGFormat, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, UnsignedByteType, FloatType, HalfFloatType, SRGBTransfer, DepthFormat, DepthStencilFormat,
|
|
14
14
|
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,
|
|
15
15
|
RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_10x10_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, UnsignedIntType, UnsignedShortType, UnsignedInt248Type, UnsignedInt5999Type,
|
|
16
|
-
NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat
|
|
16
|
+
NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare, IntType, RedIntegerFormat, RGIntegerFormat, RGBAIntegerFormat,
|
|
17
|
+
UnsignedInt101111Type, RGBA_BPTC_Format, RGB_ETC1_Format, RGB_S3TC_DXT1_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format
|
|
17
18
|
} from '../../../constants.js';
|
|
18
19
|
import { CubeTexture } from '../../../textures/CubeTexture.js';
|
|
19
20
|
import { DepthTexture } from '../../../textures/DepthTexture.js';
|
|
@@ -186,6 +187,15 @@ class WebGPUTextureUtils {
|
|
|
186
187
|
|
|
187
188
|
}
|
|
188
189
|
|
|
190
|
+
if ( texture.isExternalTexture ) {
|
|
191
|
+
|
|
192
|
+
textureData.texture = texture.sourceTexture;
|
|
193
|
+
textureData.initialized = true;
|
|
194
|
+
|
|
195
|
+
return;
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
|
|
189
199
|
if ( options.needsMipmaps === undefined ) options.needsMipmaps = false;
|
|
190
200
|
if ( options.levels === undefined ) options.levels = 1;
|
|
191
201
|
if ( options.depth === undefined ) options.depth = 1;
|
|
@@ -221,7 +231,7 @@ class WebGPUTextureUtils {
|
|
|
221
231
|
|
|
222
232
|
}
|
|
223
233
|
|
|
224
|
-
if ( texture.isCompressedTexture !== true && texture.isCompressedArrayTexture !== true ) {
|
|
234
|
+
if ( texture.isCompressedTexture !== true && texture.isCompressedArrayTexture !== true && format !== GPUTextureFormat.RGB9E5UFloat ) {
|
|
225
235
|
|
|
226
236
|
usage |= GPUTextureUsage.RENDER_ATTACHMENT;
|
|
227
237
|
|
|
@@ -266,6 +276,7 @@ class WebGPUTextureUtils {
|
|
|
266
276
|
|
|
267
277
|
msaaTextureDescriptorGPU.label = msaaTextureDescriptorGPU.label + '-msaa';
|
|
268
278
|
msaaTextureDescriptorGPU.sampleCount = samples;
|
|
279
|
+
msaaTextureDescriptorGPU.mipLevelCount = 1; // See https://www.w3.org/TR/webgpu/#texture-creation
|
|
269
280
|
|
|
270
281
|
textureData.msaaTexture = backend.device.createTexture( msaaTextureDescriptorGPU );
|
|
271
282
|
|
|
@@ -432,6 +443,7 @@ class WebGPUTextureUtils {
|
|
|
432
443
|
updateTexture( texture, options ) {
|
|
433
444
|
|
|
434
445
|
const textureData = this.backend.get( texture );
|
|
446
|
+
const mipmaps = texture.mipmaps;
|
|
435
447
|
|
|
436
448
|
const { textureDescriptorGPU } = textureData;
|
|
437
449
|
|
|
@@ -442,7 +454,22 @@ class WebGPUTextureUtils {
|
|
|
442
454
|
|
|
443
455
|
if ( texture.isDataTexture ) {
|
|
444
456
|
|
|
445
|
-
|
|
457
|
+
if ( mipmaps.length > 0 ) {
|
|
458
|
+
|
|
459
|
+
for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
460
|
+
|
|
461
|
+
const mipmap = mipmaps[ i ];
|
|
462
|
+
|
|
463
|
+
this._copyBufferToTexture( mipmap, textureData.texture, textureDescriptorGPU, 0, texture.flipY, 0, i );
|
|
464
|
+
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
} else {
|
|
469
|
+
|
|
470
|
+
this._copyBufferToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY );
|
|
471
|
+
|
|
472
|
+
}
|
|
446
473
|
|
|
447
474
|
} else if ( texture.isArrayTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
|
|
448
475
|
|
|
@@ -458,11 +485,26 @@ class WebGPUTextureUtils {
|
|
|
458
485
|
|
|
459
486
|
} else if ( texture.isCubeTexture ) {
|
|
460
487
|
|
|
461
|
-
this._copyCubeMapToTexture(
|
|
488
|
+
this._copyCubeMapToTexture( texture, textureData.texture, textureDescriptorGPU );
|
|
462
489
|
|
|
463
490
|
} else {
|
|
464
491
|
|
|
465
|
-
|
|
492
|
+
if ( mipmaps.length > 0 ) {
|
|
493
|
+
|
|
494
|
+
for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
|
|
495
|
+
|
|
496
|
+
const mipmap = mipmaps[ i ];
|
|
497
|
+
|
|
498
|
+
this._copyImageToTexture( mipmap, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha, i );
|
|
499
|
+
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
} else {
|
|
504
|
+
|
|
505
|
+
this._copyImageToTexture( options.image, textureData.texture, textureDescriptorGPU, 0, texture.flipY, texture.premultiplyAlpha );
|
|
506
|
+
|
|
507
|
+
}
|
|
466
508
|
|
|
467
509
|
}
|
|
468
510
|
|
|
@@ -470,8 +512,6 @@ class WebGPUTextureUtils {
|
|
|
470
512
|
|
|
471
513
|
textureData.version = texture.version;
|
|
472
514
|
|
|
473
|
-
if ( texture.onUpdate ) texture.onUpdate( texture );
|
|
474
|
-
|
|
475
515
|
}
|
|
476
516
|
|
|
477
517
|
/**
|
|
@@ -500,7 +540,7 @@ class WebGPUTextureUtils {
|
|
|
500
540
|
|
|
501
541
|
const readBuffer = device.createBuffer(
|
|
502
542
|
{
|
|
503
|
-
size:
|
|
543
|
+
size: ( ( height - 1 ) * bytesPerRow ) + ( width * bytesPerTexel ), // see https://github.com/mrdoob/three.js/issues/31658#issuecomment-3229442010
|
|
504
544
|
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
505
545
|
}
|
|
506
546
|
);
|
|
@@ -593,27 +633,46 @@ class WebGPUTextureUtils {
|
|
|
593
633
|
* Uploads cube texture image data to the GPU memory.
|
|
594
634
|
*
|
|
595
635
|
* @private
|
|
596
|
-
* @param {
|
|
636
|
+
* @param {CubeTexture} texture - The cube texture.
|
|
597
637
|
* @param {GPUTexture} textureGPU - The GPU texture.
|
|
598
638
|
* @param {Object} textureDescriptorGPU - The GPU texture descriptor.
|
|
599
|
-
* @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
|
|
600
|
-
* @param {boolean} premultiplyAlpha - Whether the texture should have its RGB channels premultiplied by the alpha channel or not.
|
|
601
639
|
*/
|
|
602
|
-
_copyCubeMapToTexture(
|
|
640
|
+
_copyCubeMapToTexture( texture, textureGPU, textureDescriptorGPU ) {
|
|
641
|
+
|
|
642
|
+
const images = texture.images;
|
|
643
|
+
const mipmaps = texture.mipmaps;
|
|
603
644
|
|
|
604
645
|
for ( let i = 0; i < 6; i ++ ) {
|
|
605
646
|
|
|
606
647
|
const image = images[ i ];
|
|
607
648
|
|
|
608
|
-
const flipIndex = flipY === true ? _flipMap[ i ] : i;
|
|
649
|
+
const flipIndex = texture.flipY === true ? _flipMap[ i ] : i;
|
|
609
650
|
|
|
610
651
|
if ( image.isDataTexture ) {
|
|
611
652
|
|
|
612
|
-
this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, flipY );
|
|
653
|
+
this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY );
|
|
613
654
|
|
|
614
655
|
} else {
|
|
615
656
|
|
|
616
|
-
this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, flipY, premultiplyAlpha );
|
|
657
|
+
this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, texture.premultiplyAlpha );
|
|
658
|
+
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
for ( let j = 0; j < mipmaps.length; j ++ ) {
|
|
662
|
+
|
|
663
|
+
const mipmap = mipmaps[ j ];
|
|
664
|
+
const image = mipmap.images[ i ];
|
|
665
|
+
|
|
666
|
+
if ( image.isDataTexture ) {
|
|
667
|
+
|
|
668
|
+
this._copyBufferToTexture( image.image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, 0, j + 1 );
|
|
669
|
+
|
|
670
|
+
} else {
|
|
671
|
+
|
|
672
|
+
this._copyImageToTexture( image, textureGPU, textureDescriptorGPU, flipIndex, texture.flipY, texture.premultiplyAlpha, j + 1 );
|
|
673
|
+
|
|
674
|
+
}
|
|
675
|
+
|
|
617
676
|
|
|
618
677
|
}
|
|
619
678
|
|
|
@@ -631,23 +690,27 @@ class WebGPUTextureUtils {
|
|
|
631
690
|
* @param {number} originDepth - The origin depth.
|
|
632
691
|
* @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
|
|
633
692
|
* @param {boolean} premultiplyAlpha - Whether the texture should have its RGB channels premultiplied by the alpha channel or not.
|
|
693
|
+
* @param {number} [mipLevel=0] - The mip level where the data should be copied to.
|
|
634
694
|
*/
|
|
635
|
-
_copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, premultiplyAlpha ) {
|
|
695
|
+
_copyImageToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, premultiplyAlpha, mipLevel = 0 ) {
|
|
636
696
|
|
|
637
697
|
const device = this.backend.device;
|
|
638
698
|
|
|
699
|
+
const width = ( mipLevel > 0 ) ? image.width : textureDescriptorGPU.size.width;
|
|
700
|
+
const height = ( mipLevel > 0 ) ? image.height : textureDescriptorGPU.size.height;
|
|
701
|
+
|
|
639
702
|
device.queue.copyExternalImageToTexture(
|
|
640
703
|
{
|
|
641
704
|
source: image,
|
|
642
705
|
flipY: flipY
|
|
643
706
|
}, {
|
|
644
707
|
texture: textureGPU,
|
|
645
|
-
mipLevel:
|
|
708
|
+
mipLevel: mipLevel,
|
|
646
709
|
origin: { x: 0, y: 0, z: originDepth },
|
|
647
710
|
premultipliedAlpha: premultiplyAlpha
|
|
648
711
|
}, {
|
|
649
|
-
width:
|
|
650
|
-
height:
|
|
712
|
+
width: width,
|
|
713
|
+
height: height,
|
|
651
714
|
depthOrArrayLayers: 1
|
|
652
715
|
}
|
|
653
716
|
);
|
|
@@ -711,9 +774,10 @@ class WebGPUTextureUtils {
|
|
|
711
774
|
* @param {Object} textureDescriptorGPU - The GPU texture descriptor.
|
|
712
775
|
* @param {number} originDepth - The origin depth.
|
|
713
776
|
* @param {boolean} flipY - Whether to flip texture data along their vertical axis or not.
|
|
714
|
-
* @param {number} [depth=0] -
|
|
777
|
+
* @param {number} [depth=0] - The depth offset when copying array or 3D texture data.
|
|
778
|
+
* @param {number} [mipLevel=0] - The mip level where the data should be copied to.
|
|
715
779
|
*/
|
|
716
|
-
_copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, depth = 0 ) {
|
|
780
|
+
_copyBufferToTexture( image, textureGPU, textureDescriptorGPU, originDepth, flipY, depth = 0, mipLevel = 0 ) {
|
|
717
781
|
|
|
718
782
|
// @TODO: Consider to use GPUCommandEncoder.copyBufferToTexture()
|
|
719
783
|
// @TODO: Consider to support valid buffer layouts with other formats like RGB
|
|
@@ -728,7 +792,7 @@ class WebGPUTextureUtils {
|
|
|
728
792
|
device.queue.writeTexture(
|
|
729
793
|
{
|
|
730
794
|
texture: textureGPU,
|
|
731
|
-
mipLevel:
|
|
795
|
+
mipLevel: mipLevel,
|
|
732
796
|
origin: { x: 0, y: 0, z: originDepth }
|
|
733
797
|
},
|
|
734
798
|
data,
|
|
@@ -976,7 +1040,7 @@ class WebGPUTextureUtils {
|
|
|
976
1040
|
if ( format === GPUTextureFormat.RG8Snorm ) return Int8Array;
|
|
977
1041
|
if ( format === GPUTextureFormat.RGBA8Uint ) return Uint8Array;
|
|
978
1042
|
if ( format === GPUTextureFormat.RGBA8Sint ) return Int8Array;
|
|
979
|
-
if ( format === GPUTextureFormat.RGBA8Unorm ) return Uint8Array;
|
|
1043
|
+
if ( format === GPUTextureFormat.RGBA8Unorm || format === GPUTextureFormat.RGBA8UnormSRGB ) return Uint8Array;
|
|
980
1044
|
if ( format === GPUTextureFormat.RGBA8Snorm ) return Int8Array;
|
|
981
1045
|
|
|
982
1046
|
|
|
@@ -1001,8 +1065,7 @@ class WebGPUTextureUtils {
|
|
|
1001
1065
|
if ( format === GPUTextureFormat.RGBA32Sint ) return Int32Array;
|
|
1002
1066
|
if ( format === GPUTextureFormat.RGBA32Float ) return Float32Array;
|
|
1003
1067
|
|
|
1004
|
-
if ( format === GPUTextureFormat.BGRA8Unorm ) return Uint8Array;
|
|
1005
|
-
if ( format === GPUTextureFormat.BGRA8UnormSRGB ) return Uint8Array;
|
|
1068
|
+
if ( format === GPUTextureFormat.BGRA8Unorm || format === GPUTextureFormat.BGRA8UnormSRGB ) return Uint8Array;
|
|
1006
1069
|
if ( format === GPUTextureFormat.RGB10A2Unorm ) return Uint32Array;
|
|
1007
1070
|
if ( format === GPUTextureFormat.RGB9E5UFloat ) return Uint32Array;
|
|
1008
1071
|
if ( format === GPUTextureFormat.RG11B10UFloat ) return Uint32Array;
|
|
@@ -1062,6 +1125,7 @@ export function getFormat( texture, device = null ) {
|
|
|
1062
1125
|
|
|
1063
1126
|
switch ( format ) {
|
|
1064
1127
|
|
|
1128
|
+
case RGB_S3TC_DXT1_Format:
|
|
1065
1129
|
case RGBA_S3TC_DXT1_Format:
|
|
1066
1130
|
formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC1RGBAUnormSRGB : GPUTextureFormat.BC1RGBAUnorm;
|
|
1067
1131
|
break;
|
|
@@ -1074,7 +1138,28 @@ export function getFormat( texture, device = null ) {
|
|
|
1074
1138
|
formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC3RGBAUnormSRGB : GPUTextureFormat.BC3RGBAUnorm;
|
|
1075
1139
|
break;
|
|
1076
1140
|
|
|
1141
|
+
case RED_RGTC1_Format:
|
|
1142
|
+
formatGPU = GPUTextureFormat.BC4RUnorm;
|
|
1143
|
+
break;
|
|
1144
|
+
|
|
1145
|
+
case SIGNED_RED_RGTC1_Format:
|
|
1146
|
+
formatGPU = GPUTextureFormat.BC4RSnorm;
|
|
1147
|
+
break;
|
|
1148
|
+
|
|
1149
|
+
case RED_GREEN_RGTC2_Format:
|
|
1150
|
+
formatGPU = GPUTextureFormat.BC5RGUnorm;
|
|
1151
|
+
break;
|
|
1152
|
+
|
|
1153
|
+
case SIGNED_RED_GREEN_RGTC2_Format:
|
|
1154
|
+
formatGPU = GPUTextureFormat.BC5RGSnorm;
|
|
1155
|
+
break;
|
|
1156
|
+
|
|
1157
|
+
case RGBA_BPTC_Format:
|
|
1158
|
+
formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.BC7RGBAUnormSRGB : GPUTextureFormat.BC7RGBAUnorm;
|
|
1159
|
+
break;
|
|
1160
|
+
|
|
1077
1161
|
case RGB_ETC2_Format:
|
|
1162
|
+
case RGB_ETC1_Format:
|
|
1078
1163
|
formatGPU = ( transfer === SRGBTransfer ) ? GPUTextureFormat.ETC2RGB8UnormSRGB : GPUTextureFormat.ETC2RGB8Unorm;
|
|
1079
1164
|
break;
|
|
1080
1165
|
|
|
@@ -1201,6 +1286,10 @@ export function getFormat( texture, device = null ) {
|
|
|
1201
1286
|
formatGPU = GPUTextureFormat.RGB9E5UFloat;
|
|
1202
1287
|
break;
|
|
1203
1288
|
|
|
1289
|
+
case UnsignedInt101111Type:
|
|
1290
|
+
formatGPU = GPUTextureFormat.RG11B10UFloat;
|
|
1291
|
+
break;
|
|
1292
|
+
|
|
1204
1293
|
default:
|
|
1205
1294
|
console.error( 'WebGPURenderer: Unsupported texture type with RGBFormat.', type );
|
|
1206
1295
|
|
|
@@ -46,10 +46,10 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool {
|
|
|
46
46
|
/**
|
|
47
47
|
* Allocates a pair of queries for a given render context.
|
|
48
48
|
*
|
|
49
|
-
* @param {
|
|
49
|
+
* @param {string} uid - A unique identifier for the render context.
|
|
50
50
|
* @returns {?number} The base offset for the allocated queries, or null if allocation failed.
|
|
51
51
|
*/
|
|
52
|
-
allocateQueriesForContext(
|
|
52
|
+
allocateQueriesForContext( uid ) {
|
|
53
53
|
|
|
54
54
|
if ( ! this.trackTimestamp || this.isDisposed ) return null;
|
|
55
55
|
|
|
@@ -63,7 +63,7 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool {
|
|
|
63
63
|
const baseOffset = this.currentQueryIndex;
|
|
64
64
|
this.currentQueryIndex += 2;
|
|
65
65
|
|
|
66
|
-
this.queryOffsets.set(
|
|
66
|
+
this.queryOffsets.set( uid, baseOffset );
|
|
67
67
|
return baseOffset;
|
|
68
68
|
|
|
69
69
|
}
|
|
@@ -52,6 +52,8 @@ class WebXRManager extends EventDispatcher {
|
|
|
52
52
|
let glBaseLayer = null;
|
|
53
53
|
let xrFrame = null;
|
|
54
54
|
|
|
55
|
+
const supportsGlBinding = typeof XRWebGLBinding !== 'undefined';
|
|
56
|
+
|
|
55
57
|
const depthSensing = new WebXRDepthSensing();
|
|
56
58
|
const cameraAccessTextures = {};
|
|
57
59
|
const attributes = gl.getContextAttributes();
|
|
@@ -329,6 +331,9 @@ class WebXRManager extends EventDispatcher {
|
|
|
329
331
|
/**
|
|
330
332
|
* Returns the current base layer.
|
|
331
333
|
*
|
|
334
|
+
* This is an `XRProjectionLayer` when the targeted XR device supports the
|
|
335
|
+
* WebXR Layers API, or an `XRWebGLLayer` otherwise.
|
|
336
|
+
*
|
|
332
337
|
* @return {?(XRWebGLLayer|XRProjectionLayer)} The XR base layer.
|
|
333
338
|
*/
|
|
334
339
|
this.getBaseLayer = function () {
|
|
@@ -340,10 +345,19 @@ class WebXRManager extends EventDispatcher {
|
|
|
340
345
|
/**
|
|
341
346
|
* Returns the current XR binding.
|
|
342
347
|
*
|
|
343
|
-
*
|
|
348
|
+
* Creates a new binding if needed and the browser is
|
|
349
|
+
* capable of doing so.
|
|
350
|
+
*
|
|
351
|
+
* @return {?XRWebGLBinding} The XR binding. Returns `null` if one cannot be created.
|
|
344
352
|
*/
|
|
345
353
|
this.getBinding = function () {
|
|
346
354
|
|
|
355
|
+
if ( glBinding === null && supportsGlBinding ) {
|
|
356
|
+
|
|
357
|
+
glBinding = new XRWebGLBinding( session, gl );
|
|
358
|
+
|
|
359
|
+
}
|
|
360
|
+
|
|
347
361
|
return glBinding;
|
|
348
362
|
|
|
349
363
|
};
|
|
@@ -405,17 +419,12 @@ class WebXRManager extends EventDispatcher {
|
|
|
405
419
|
currentPixelRatio = renderer.getPixelRatio();
|
|
406
420
|
renderer.getSize( currentSize );
|
|
407
421
|
|
|
408
|
-
if ( typeof XRWebGLBinding !== 'undefined' ) {
|
|
409
|
-
|
|
410
|
-
glBinding = new XRWebGLBinding( session, gl );
|
|
411
|
-
|
|
412
|
-
}
|
|
413
422
|
|
|
414
423
|
// Check that the browser implements the necessary APIs to use an
|
|
415
424
|
// XRProjectionLayer rather than an XRWebGLLayer
|
|
416
|
-
const
|
|
425
|
+
const supportsLayers = supportsGlBinding && 'createProjectionLayer' in XRWebGLBinding.prototype;
|
|
417
426
|
|
|
418
|
-
if ( !
|
|
427
|
+
if ( ! supportsLayers ) {
|
|
419
428
|
|
|
420
429
|
const layerInit = {
|
|
421
430
|
antialias: attributes.antialias,
|
|
@@ -466,6 +475,8 @@ class WebXRManager extends EventDispatcher {
|
|
|
466
475
|
scaleFactor: framebufferScaleFactor
|
|
467
476
|
};
|
|
468
477
|
|
|
478
|
+
glBinding = this.getBinding();
|
|
479
|
+
|
|
469
480
|
glProjLayer = glBinding.createProjectionLayer( projectionlayerInit );
|
|
470
481
|
|
|
471
482
|
session.updateRenderState( { layers: [ glProjLayer ] } );
|
|
@@ -525,6 +536,8 @@ class WebXRManager extends EventDispatcher {
|
|
|
525
536
|
/**
|
|
526
537
|
* Returns the current depth texture computed via depth sensing.
|
|
527
538
|
*
|
|
539
|
+
* See {@link WebXRDepthSensing#getDepthTexture}.
|
|
540
|
+
*
|
|
528
541
|
* @return {?Texture} The depth texture.
|
|
529
542
|
*/
|
|
530
543
|
this.getDepthTexture = function () {
|
|
@@ -695,7 +708,7 @@ class WebXRManager extends EventDispatcher {
|
|
|
695
708
|
|
|
696
709
|
/**
|
|
697
710
|
* Updates the state of the XR camera. Use this method on app level if you
|
|
698
|
-
* set cameraAutoUpdate` to `false`. The method requires the non-XR
|
|
711
|
+
* set `cameraAutoUpdate` to `false`. The method requires the non-XR
|
|
699
712
|
* camera of the scene as a parameter. The passed in camera's transformation
|
|
700
713
|
* is automatically adjusted to the position of the XR camera when calling
|
|
701
714
|
* this method.
|
|
@@ -872,6 +885,8 @@ class WebXRManager extends EventDispatcher {
|
|
|
872
885
|
/**
|
|
873
886
|
* Returns the depth sensing mesh.
|
|
874
887
|
*
|
|
888
|
+
* See {@link WebXRDepthSensing#getMesh}.
|
|
889
|
+
*
|
|
875
890
|
* @return {Mesh} The depth sensing mesh.
|
|
876
891
|
*/
|
|
877
892
|
this.getDepthSensingMesh = function () {
|
|
@@ -992,7 +1007,9 @@ class WebXRManager extends EventDispatcher {
|
|
|
992
1007
|
enabledFeatures.includes( 'depth-sensing' ) &&
|
|
993
1008
|
session.depthUsage == 'gpu-optimized';
|
|
994
1009
|
|
|
995
|
-
if ( gpuDepthSensingEnabled &&
|
|
1010
|
+
if ( gpuDepthSensingEnabled && supportsGlBinding ) {
|
|
1011
|
+
|
|
1012
|
+
glBinding = scope.getBinding();
|
|
996
1013
|
|
|
997
1014
|
const depthData = glBinding.getDepthInformation( views[ 0 ] );
|
|
998
1015
|
|
|
@@ -1007,32 +1024,30 @@ class WebXRManager extends EventDispatcher {
|
|
|
1007
1024
|
const cameraAccessEnabled = enabledFeatures &&
|
|
1008
1025
|
enabledFeatures.includes( 'camera-access' );
|
|
1009
1026
|
|
|
1010
|
-
if ( cameraAccessEnabled ) {
|
|
1027
|
+
if ( cameraAccessEnabled && supportsGlBinding ) {
|
|
1011
1028
|
|
|
1012
1029
|
renderer.state.unbindTexture();
|
|
1013
1030
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
for ( let i = 0; i < views.length; i ++ ) {
|
|
1031
|
+
glBinding = scope.getBinding();
|
|
1017
1032
|
|
|
1018
|
-
|
|
1033
|
+
for ( let i = 0; i < views.length; i ++ ) {
|
|
1019
1034
|
|
|
1020
|
-
|
|
1035
|
+
const camera = views[ i ].camera;
|
|
1021
1036
|
|
|
1022
|
-
|
|
1037
|
+
if ( camera ) {
|
|
1023
1038
|
|
|
1024
|
-
|
|
1039
|
+
let cameraTex = cameraAccessTextures[ camera ];
|
|
1025
1040
|
|
|
1026
|
-
|
|
1027
|
-
cameraAccessTextures[ camera ] = cameraTex;
|
|
1041
|
+
if ( ! cameraTex ) {
|
|
1028
1042
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
const glTexture = glBinding.getCameraImage( camera );
|
|
1032
|
-
cameraTex.sourceTexture = glTexture;
|
|
1043
|
+
cameraTex = new ExternalTexture();
|
|
1044
|
+
cameraAccessTextures[ camera ] = cameraTex;
|
|
1033
1045
|
|
|
1034
1046
|
}
|
|
1035
1047
|
|
|
1048
|
+
const glTexture = glBinding.getCameraImage( camera );
|
|
1049
|
+
cameraTex.sourceTexture = glTexture;
|
|
1050
|
+
|
|
1036
1051
|
}
|
|
1037
1052
|
|
|
1038
1053
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Texture } from './Texture.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Represents a texture created externally
|
|
4
|
+
* Represents a texture created externally with the same renderer context.
|
|
5
5
|
*
|
|
6
6
|
* This may be a texture from a protected media stream, device camera feed,
|
|
7
7
|
* or other data feeds like a depth sensor.
|
|
8
8
|
*
|
|
9
|
-
* Note that this class is only supported in {@link WebGLRenderer}
|
|
9
|
+
* Note that this class is only supported in {@link WebGLRenderer}, and in
|
|
10
|
+
* the {@link WebGPURenderer} WebGPU backend.
|
|
10
11
|
*
|
|
11
12
|
* @augments Texture
|
|
12
13
|
*/
|
|
@@ -15,7 +16,7 @@ class ExternalTexture extends Texture {
|
|
|
15
16
|
/**
|
|
16
17
|
* Creates a new raw texture.
|
|
17
18
|
*
|
|
18
|
-
* @param {?WebGLTexture} [sourceTexture=null] - The external texture.
|
|
19
|
+
* @param {?(WebGLTexture|GPUTexture)} [sourceTexture=null] - The external texture.
|
|
19
20
|
*/
|
|
20
21
|
constructor( sourceTexture = null ) {
|
|
21
22
|
|
|
@@ -24,7 +25,7 @@ class ExternalTexture extends Texture {
|
|
|
24
25
|
/**
|
|
25
26
|
* The external source texture.
|
|
26
27
|
*
|
|
27
|
-
* @type {?WebGLTexture}
|
|
28
|
+
* @type {?(WebGLTexture|GPUTexture)}
|
|
28
29
|
* @default null
|
|
29
30
|
*/
|
|
30
31
|
this.sourceTexture = sourceTexture;
|
|
@@ -40,6 +41,16 @@ class ExternalTexture extends Texture {
|
|
|
40
41
|
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
copy( source ) {
|
|
45
|
+
|
|
46
|
+
super.copy( source );
|
|
47
|
+
|
|
48
|
+
this.sourceTexture = source.sourceTexture;
|
|
49
|
+
|
|
50
|
+
return this;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
export { ExternalTexture };
|
package/src/textures/Source.js
CHANGED