super-three 0.162.0 → 0.164.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.
- package/build/three.cjs +847 -1226
- package/build/three.module.js +846 -1225
- package/build/three.module.min.js +2 -2
- package/examples/jsm/animation/CCDIKSolver.js +4 -2
- package/examples/jsm/controls/TransformControls.js +3 -3
- package/examples/jsm/exporters/GLTFExporter.js +66 -5
- package/examples/jsm/exporters/USDZExporter.js +22 -1
- package/examples/jsm/geometries/TextGeometry.js +10 -2
- package/examples/jsm/interactive/HTMLMesh.js +7 -9
- package/examples/jsm/libs/draco/README.md +2 -2
- package/examples/jsm/libs/fflate.module.js +694 -496
- package/examples/jsm/lines/LineMaterial.js +0 -2
- package/examples/jsm/loaders/3MFLoader.js +2 -0
- package/examples/jsm/loaders/EXRLoader.js +351 -97
- package/examples/jsm/loaders/FBXLoader.js +1 -1
- package/examples/jsm/loaders/GLTFLoader.js +59 -0
- package/examples/jsm/loaders/KTX2Loader.js +3 -10
- package/examples/jsm/loaders/LUT3dlLoader.js +0 -15
- package/examples/jsm/loaders/LUTCubeLoader.js +0 -14
- package/examples/jsm/loaders/LUTImageLoader.js +0 -14
- package/examples/jsm/loaders/RGBMLoader.js +16 -0
- package/examples/jsm/loaders/VRMLLoader.js +1 -1
- package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
- package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
- package/examples/jsm/math/Octree.js +26 -20
- package/examples/jsm/misc/GPUComputationRenderer.js +0 -6
- package/examples/jsm/nodes/Nodes.js +10 -4
- package/examples/jsm/nodes/accessors/AccessorsUtils.js +16 -1
- package/examples/jsm/nodes/accessors/BatchNode.js +78 -0
- package/examples/jsm/nodes/accessors/ClippingNode.js +3 -2
- package/examples/jsm/nodes/accessors/InstanceNode.js +25 -2
- package/examples/jsm/nodes/accessors/MaterialNode.js +107 -3
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +1 -1
- package/examples/jsm/nodes/accessors/MorphNode.js +13 -3
- package/examples/jsm/nodes/accessors/NormalNode.js +12 -2
- package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
- package/examples/jsm/nodes/accessors/RendererReferenceNode.js +29 -0
- package/examples/jsm/nodes/accessors/StorageBufferNode.js +9 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +51 -10
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +1 -1
- package/examples/jsm/nodes/code/FunctionNode.js +0 -8
- package/examples/jsm/nodes/core/Node.js +63 -4
- package/examples/jsm/nodes/core/NodeBuilder.js +26 -25
- package/examples/jsm/nodes/core/NodeFrame.js +10 -10
- package/examples/jsm/nodes/core/NodeUtils.js +2 -2
- package/examples/jsm/nodes/core/OutputStructNode.js +2 -1
- package/examples/jsm/nodes/core/PropertyNode.js +10 -0
- package/examples/jsm/nodes/core/UniformNode.js +20 -0
- package/examples/jsm/nodes/display/BumpMapNode.js +7 -26
- package/examples/jsm/nodes/display/FrontFacingNode.js +13 -0
- package/examples/jsm/nodes/display/PassNode.js +17 -1
- package/examples/jsm/nodes/display/ToneMappingNode.js +8 -4
- package/examples/jsm/nodes/display/ViewportDepthNode.js +1 -1
- package/examples/jsm/nodes/display/ViewportNode.js +4 -2
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -0
- package/examples/jsm/nodes/display/ViewportTextureNode.js +4 -1
- package/examples/jsm/nodes/fog/FogExp2Node.js +4 -5
- package/examples/jsm/nodes/fog/FogNode.js +13 -3
- package/examples/jsm/nodes/fog/FogRangeNode.js +4 -3
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +26 -7
- package/examples/jsm/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +1 -3
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
- package/examples/jsm/nodes/functions/PhongLightingModel.js +1 -1
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +164 -10
- package/examples/jsm/nodes/functions/ShadowMaskModel.js +31 -0
- package/examples/jsm/nodes/lighting/AnalyticLightNode.js +19 -5
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -1
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -70
- package/examples/jsm/nodes/lighting/IrradianceNode.js +24 -0
- package/examples/jsm/nodes/lighting/LightsNode.js +11 -1
- package/examples/jsm/nodes/lighting/PointLightNode.js +2 -1
- package/examples/jsm/nodes/lighting/SpotLightNode.js +2 -1
- package/examples/jsm/nodes/materials/Line2NodeMaterial.js +10 -6
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -2
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +76 -5
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +11 -4
- package/examples/jsm/nodes/materials/NodeMaterial.js +55 -43
- package/examples/jsm/nodes/materials/ShadowNodeMaterial.js +34 -0
- package/examples/jsm/nodes/pmrem/PMREMNode.js +193 -0
- package/examples/jsm/nodes/pmrem/PMREMUtils.js +288 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +3 -9
- package/examples/jsm/nodes/utils/EquirectUVNode.js +1 -1
- package/examples/jsm/objects/QuadMesh.js +7 -23
- package/examples/jsm/physics/JoltPhysics.js +281 -0
- package/examples/jsm/physics/RapierPhysics.js +4 -4
- package/examples/jsm/postprocessing/GlitchPass.js +0 -3
- package/examples/jsm/postprocessing/LUTPass.js +5 -71
- package/examples/jsm/postprocessing/RenderTransitionPass.js +193 -0
- package/examples/jsm/postprocessing/SAOPass.js +0 -1
- package/examples/jsm/postprocessing/SSAOPass.js +0 -3
- package/examples/jsm/renderers/common/Animation.js +3 -0
- package/examples/jsm/renderers/common/Background.js +8 -8
- package/examples/jsm/renderers/common/ClippingContext.js +1 -1
- package/examples/jsm/renderers/common/Info.js +11 -19
- package/examples/jsm/renderers/common/PostProcessing.js +12 -4
- package/examples/jsm/renderers/common/RenderContext.js +1 -1
- package/examples/jsm/renderers/common/RenderList.js +1 -1
- package/examples/jsm/renderers/common/RenderObject.js +47 -5
- package/examples/jsm/renderers/common/RenderObjects.js +1 -1
- package/examples/jsm/renderers/common/Renderer.js +153 -21
- package/examples/jsm/renderers/common/Textures.js +1 -1
- package/examples/jsm/renderers/common/extras/PMREMGenerator.js +773 -0
- package/examples/jsm/renderers/common/nodes/Nodes.js +34 -63
- package/examples/jsm/renderers/webgl/WebGLBackend.js +146 -36
- package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +145 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +9 -3
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +1 -1
- package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +1 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +64 -7
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +6 -23
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +77 -60
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +21 -4
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +29 -1
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +18 -4
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +92 -18
- package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/utils/GPUStatsPanel.js +10 -45
- package/examples/jsm/utils/SceneUtils.js +60 -1
- package/examples/jsm/utils/TextureUtils.js +1 -1
- package/examples/jsm/webxr/OculusHandModel.js +3 -2
- package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
- package/package.json +1 -1
- package/src/Three.js +0 -1
- package/src/animation/AnimationClip.js +1 -1
- package/src/constants.js +3 -3
- package/src/core/Object3D.js +10 -7
- package/src/core/RenderTarget.js +8 -0
- package/src/extras/PMREMGenerator.js +21 -11
- package/src/loaders/FileLoader.js +1 -1
- package/src/loaders/MaterialLoader.js +1 -0
- package/src/loaders/ObjectLoader.js +2 -0
- package/src/materials/Material.js +2 -0
- package/src/materials/MeshPhysicalMaterial.js +20 -0
- package/src/materials/ShaderMaterial.js +0 -4
- package/src/math/Spherical.js +4 -5
- package/src/objects/BatchedMesh.js +27 -3
- package/src/objects/InstancedMesh.js +10 -0
- package/src/objects/Line.js +66 -43
- package/src/renderers/WebGLRenderer.js +130 -158
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +2 -10
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +2 -16
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +32 -22
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +17 -9
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
- package/src/renderers/shaders/ShaderChunk.js +0 -2
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
- package/src/renderers/shaders/ShaderLib.js +2 -1
- package/src/renderers/shaders/UniformsUtils.js +10 -1
- package/src/renderers/webgl/WebGLAttributes.js +6 -33
- package/src/renderers/webgl/WebGLBackground.js +18 -3
- package/src/renderers/webgl/WebGLBindingStates.js +14 -51
- package/src/renderers/webgl/WebGLBufferRenderer.js +35 -21
- package/src/renderers/webgl/WebGLCapabilities.js +35 -13
- package/src/renderers/webgl/WebGLCubeUVMaps.js +10 -6
- package/src/renderers/webgl/WebGLExtensions.js +4 -19
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +35 -21
- package/src/renderers/webgl/WebGLLights.js +6 -32
- package/src/renderers/webgl/WebGLMaterials.js +8 -3
- package/src/renderers/webgl/WebGLMorphtargets.js +79 -217
- package/src/renderers/webgl/WebGLProgram.js +21 -52
- package/src/renderers/webgl/WebGLPrograms.js +24 -31
- package/src/renderers/webgl/WebGLRenderStates.js +13 -7
- package/src/renderers/webgl/WebGLShadowMap.js +25 -25
- package/src/renderers/webgl/WebGLState.js +15 -59
- package/src/renderers/webgl/WebGLTextures.js +138 -292
- package/src/renderers/webgl/WebGLUniformsGroups.js +1 -1
- package/src/renderers/webgl/WebGLUtils.js +9 -78
- package/src/renderers/webxr/WebXRDepthSensing.js +2 -3
- package/src/renderers/webxr/WebXRManager.js +4 -6
- package/src/scenes/Scene.js +7 -1
- package/src/textures/Texture.js +11 -1
- package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -320
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +0 -26
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -794
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +0 -51
- package/src/renderers/WebGL1Renderer.js +0 -7
- package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
|
@@ -143,6 +143,7 @@ class WebGLTextureUtils {
|
|
|
143
143
|
if ( glType === gl.UNSIGNED_SHORT_5_6_5 ) internalFormat = gl.RGB565;
|
|
144
144
|
if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;
|
|
145
145
|
if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGB4;
|
|
146
|
+
if ( glType === gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = gl.RGB9_E5;
|
|
146
147
|
|
|
147
148
|
}
|
|
148
149
|
|
|
@@ -523,6 +524,48 @@ class WebGLTextureUtils {
|
|
|
523
524
|
|
|
524
525
|
}
|
|
525
526
|
|
|
527
|
+
copyTextureToTexture( position, srcTexture, dstTexture, level = 0 ) {
|
|
528
|
+
|
|
529
|
+
const { gl, backend } = this;
|
|
530
|
+
const { state } = this.backend;
|
|
531
|
+
|
|
532
|
+
const width = srcTexture.image.width;
|
|
533
|
+
const height = srcTexture.image.height;
|
|
534
|
+
const { textureGPU: dstTextureGPU, glTextureType, glType, glFormat } = backend.get( dstTexture );
|
|
535
|
+
|
|
536
|
+
state.bindTexture( glTextureType, dstTextureGPU );
|
|
537
|
+
|
|
538
|
+
// As another texture upload may have changed pixelStorei
|
|
539
|
+
// parameters, make sure they are correct for the dstTexture
|
|
540
|
+
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
|
|
541
|
+
gl.pixelStorei( gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
|
|
542
|
+
gl.pixelStorei( gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
|
|
543
|
+
|
|
544
|
+
if ( srcTexture.isDataTexture ) {
|
|
545
|
+
|
|
546
|
+
gl.texSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
|
|
547
|
+
|
|
548
|
+
} else {
|
|
549
|
+
|
|
550
|
+
if ( srcTexture.isCompressedTexture ) {
|
|
551
|
+
|
|
552
|
+
gl.compressedTexSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
|
|
553
|
+
|
|
554
|
+
} else {
|
|
555
|
+
|
|
556
|
+
gl.texSubImage2D( gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image );
|
|
557
|
+
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// Generate mipmaps only when copying level 0
|
|
563
|
+
if ( level === 0 && dstTexture.generateMipmaps ) gl.generateMipmap( gl.TEXTURE_2D );
|
|
564
|
+
|
|
565
|
+
state.unbindTexture();
|
|
566
|
+
|
|
567
|
+
}
|
|
568
|
+
|
|
526
569
|
copyFramebufferToTexture( texture, renderContext ) {
|
|
527
570
|
|
|
528
571
|
const { gl } = this;
|
|
@@ -533,20 +576,35 @@ class WebGLTextureUtils {
|
|
|
533
576
|
const width = texture.image.width;
|
|
534
577
|
const height = texture.image.height;
|
|
535
578
|
|
|
536
|
-
|
|
579
|
+
const requireDrawFrameBuffer = texture.isDepthTexture === true || ( renderContext.renderTarget && renderContext.renderTarget.samples > 0 );
|
|
580
|
+
|
|
581
|
+
if ( requireDrawFrameBuffer ) {
|
|
537
582
|
|
|
538
|
-
let mask
|
|
583
|
+
let mask;
|
|
584
|
+
let attachment;
|
|
539
585
|
|
|
540
|
-
if (
|
|
586
|
+
if ( texture.isDepthTexture === true ) {
|
|
541
587
|
|
|
542
|
-
mask
|
|
588
|
+
mask = gl.DEPTH_BUFFER_BIT;
|
|
589
|
+
attachment = gl.DEPTH_ATTACHMENT;
|
|
590
|
+
|
|
591
|
+
if ( renderContext.stencil ) {
|
|
592
|
+
|
|
593
|
+
mask |= gl.STENCIL_BUFFER_BIT;
|
|
594
|
+
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
} else {
|
|
598
|
+
|
|
599
|
+
mask = gl.COLOR_BUFFER_BIT;
|
|
600
|
+
attachment = gl.COLOR_ATTACHMENT0;
|
|
543
601
|
|
|
544
602
|
}
|
|
545
603
|
|
|
546
604
|
const fb = gl.createFramebuffer();
|
|
547
605
|
state.bindFramebuffer( gl.DRAW_FRAMEBUFFER, fb );
|
|
548
606
|
|
|
549
|
-
gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER,
|
|
607
|
+
gl.framebufferTexture2D( gl.DRAW_FRAMEBUFFER, attachment, gl.TEXTURE_2D, textureGPU, 0 );
|
|
550
608
|
|
|
551
609
|
gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, gl.NEAREST );
|
|
552
610
|
|
|
@@ -583,7 +641,6 @@ class WebGLTextureUtils {
|
|
|
583
641
|
|
|
584
642
|
if ( samples > 0 ) {
|
|
585
643
|
|
|
586
|
-
|
|
587
644
|
if ( depthTexture && depthTexture.isDepthTexture ) {
|
|
588
645
|
|
|
589
646
|
if ( depthTexture.type === gl.FLOAT ) {
|
|
@@ -649,7 +706,7 @@ class WebGLTextureUtils {
|
|
|
649
706
|
|
|
650
707
|
await backend.utils._clientWaitAsync();
|
|
651
708
|
|
|
652
|
-
const dstBuffer = new typedArrayType(
|
|
709
|
+
const dstBuffer = new typedArrayType( byteLength / typedArrayType.BYTES_PER_ELEMENT );
|
|
653
710
|
|
|
654
711
|
gl.bindBuffer( gl.PIXEL_PACK_BUFFER, buffer );
|
|
655
712
|
gl.getBufferSubData( gl.PIXEL_PACK_BUFFER, 0, dstBuffer );
|
|
@@ -1,4 +1,4 @@
|
|
|
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,
|
|
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, RGBFormat, RGBAFormat, AlphaFormat, RedIntegerFormat, RGFormat, RGIntegerFormat, RGBAIntegerFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, RGBA_BPTC_Format, RED_RGTC1_Format, SIGNED_RED_RGTC1_Format, RED_GREEN_RGTC2_Format, SIGNED_RED_GREEN_RGTC2_Format, SRGBColorSpace, NoColorSpace } from 'three';
|
|
2
2
|
|
|
3
3
|
class WebGLUtils {
|
|
4
4
|
|
|
@@ -20,6 +20,7 @@ class WebGLUtils {
|
|
|
20
20
|
if ( p === UnsignedByteType ) return gl.UNSIGNED_BYTE;
|
|
21
21
|
if ( p === UnsignedShort4444Type ) return gl.UNSIGNED_SHORT_4_4_4_4;
|
|
22
22
|
if ( p === UnsignedShort5551Type ) return gl.UNSIGNED_SHORT_5_5_5_1;
|
|
23
|
+
if ( p === UnsignedInt5999Type ) return gl.UNSIGNED_INT_5_9_9_9_REV;
|
|
23
24
|
|
|
24
25
|
if ( p === ByteType ) return gl.BYTE;
|
|
25
26
|
if ( p === ShortType ) return gl.SHORT;
|
|
@@ -35,7 +36,7 @@ class WebGLUtils {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
if ( p === AlphaFormat ) return gl.ALPHA;
|
|
38
|
-
if ( p ===
|
|
39
|
+
if ( p === RGBFormat ) return gl.RGB;
|
|
39
40
|
if ( p === RGBAFormat ) return gl.RGBA;
|
|
40
41
|
if ( p === LuminanceFormat ) return gl.LUMINANCE;
|
|
41
42
|
if ( p === LuminanceAlphaFormat ) return gl.LUMINANCE_ALPHA;
|
|
@@ -113,33 +114,15 @@ class WebGLUtils {
|
|
|
113
114
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
//
|
|
117
|
+
// ETC
|
|
117
118
|
|
|
118
|
-
if ( p === RGB_ETC1_Format ) {
|
|
119
|
-
|
|
120
|
-
extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
|
|
121
|
-
|
|
122
|
-
if ( extension !== null ) {
|
|
123
|
-
|
|
124
|
-
return extension.COMPRESSED_RGB_ETC1_WEBGL;
|
|
125
|
-
|
|
126
|
-
} else {
|
|
127
|
-
|
|
128
|
-
return null;
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ETC2
|
|
135
|
-
|
|
136
|
-
if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
|
|
119
|
+
if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
|
|
137
120
|
|
|
138
121
|
extension = extensions.get( 'WEBGL_compressed_texture_etc' );
|
|
139
122
|
|
|
140
123
|
if ( extension !== null ) {
|
|
141
124
|
|
|
142
|
-
if ( p === RGB_ETC2_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
|
|
125
|
+
if ( p === RGB_ETC1_Format || p === RGB_ETC2_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2;
|
|
143
126
|
if ( p === RGBA_ETC2_EAC_Format ) return ( colorSpace === SRGBColorSpace ) ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC;
|
|
144
127
|
|
|
145
128
|
} else {
|
|
@@ -14,7 +14,6 @@ import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
|
|
|
14
14
|
import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
|
|
15
15
|
import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
|
|
16
16
|
import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
|
|
17
|
-
import WebGPU from '../../capabilities/WebGPU.js';
|
|
18
17
|
|
|
19
18
|
//
|
|
20
19
|
|
|
@@ -45,7 +44,6 @@ class WebGPUBackend extends Backend {
|
|
|
45
44
|
|
|
46
45
|
this.trackTimestamp = ( parameters.trackTimestamp === true );
|
|
47
46
|
|
|
48
|
-
this.adapter = null;
|
|
49
47
|
this.device = null;
|
|
50
48
|
this.context = null;
|
|
51
49
|
this.colorBuffer = null;
|
|
@@ -68,44 +66,55 @@ class WebGPUBackend extends Backend {
|
|
|
68
66
|
|
|
69
67
|
const parameters = this.parameters;
|
|
70
68
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
// create the device if it is not passed with parameters
|
|
70
|
+
|
|
71
|
+
let device;
|
|
74
72
|
|
|
75
|
-
|
|
73
|
+
if ( parameters.device === undefined ) {
|
|
76
74
|
|
|
77
|
-
|
|
75
|
+
const adapterOptions = {
|
|
76
|
+
powerPreference: parameters.powerPreference
|
|
77
|
+
};
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
const adapter = await navigator.gpu.requestAdapter( adapterOptions );
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
if ( adapter === null ) {
|
|
82
|
+
|
|
83
|
+
throw new Error( 'WebGPUBackend: Unable to create WebGPU adapter.' );
|
|
84
|
+
|
|
85
|
+
}
|
|
82
86
|
|
|
83
|
-
|
|
87
|
+
// feature support
|
|
84
88
|
|
|
85
|
-
|
|
89
|
+
const features = Object.values( GPUFeatureName );
|
|
86
90
|
|
|
87
|
-
|
|
91
|
+
const supportedFeatures = [];
|
|
88
92
|
|
|
89
|
-
|
|
93
|
+
for ( const name of features ) {
|
|
90
94
|
|
|
91
|
-
|
|
95
|
+
if ( adapter.features.has( name ) ) {
|
|
92
96
|
|
|
93
|
-
|
|
97
|
+
supportedFeatures.push( name );
|
|
98
|
+
|
|
99
|
+
}
|
|
94
100
|
|
|
95
101
|
}
|
|
96
102
|
|
|
97
|
-
|
|
103
|
+
const deviceDescriptor = {
|
|
104
|
+
requiredFeatures: supportedFeatures,
|
|
105
|
+
requiredLimits: parameters.requiredLimits
|
|
106
|
+
};
|
|
98
107
|
|
|
99
|
-
|
|
100
|
-
requiredFeatures: supportedFeatures,
|
|
101
|
-
requiredLimits: parameters.requiredLimits
|
|
102
|
-
};
|
|
108
|
+
device = await adapter.requestDevice( deviceDescriptor );
|
|
103
109
|
|
|
104
|
-
|
|
110
|
+
} else {
|
|
111
|
+
|
|
112
|
+
device = parameters.device;
|
|
113
|
+
|
|
114
|
+
}
|
|
105
115
|
|
|
106
116
|
const context = ( parameters.context !== undefined ) ? parameters.context : renderer.domElement.getContext( 'webgpu' );
|
|
107
117
|
|
|
108
|
-
this.adapter = adapter;
|
|
109
118
|
this.device = device;
|
|
110
119
|
this.context = context;
|
|
111
120
|
|
|
@@ -871,7 +880,7 @@ class WebGPUBackend extends Backend {
|
|
|
871
880
|
|
|
872
881
|
// draw
|
|
873
882
|
|
|
874
|
-
const drawRange =
|
|
883
|
+
const drawRange = renderObject.drawRange;
|
|
875
884
|
const firstVertex = drawRange.start;
|
|
876
885
|
|
|
877
886
|
const instanceCount = this.getInstanceCount( renderObject );
|
|
@@ -1049,9 +1058,11 @@ class WebGPUBackend extends Backend {
|
|
|
1049
1058
|
beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
|
|
1050
1059
|
endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
|
|
1051
1060
|
};
|
|
1061
|
+
|
|
1052
1062
|
Object.assign( descriptor, {
|
|
1053
1063
|
timestampWrites,
|
|
1054
1064
|
} );
|
|
1065
|
+
|
|
1055
1066
|
renderContextData.timeStampQuerySet = timeStampQuerySet;
|
|
1056
1067
|
|
|
1057
1068
|
}
|
|
@@ -1084,33 +1095,29 @@ class WebGPUBackend extends Backend {
|
|
|
1084
1095
|
|
|
1085
1096
|
}
|
|
1086
1097
|
|
|
1087
|
-
async resolveTimestampAsync(
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
const renderContextData = this.get( renderContext );
|
|
1092
|
-
|
|
1093
|
-
// handle timestamp query results
|
|
1094
|
-
|
|
1098
|
+
async resolveTimestampAsync(renderContext, type = 'render') {
|
|
1099
|
+
if (!this.hasFeature(GPUFeatureName.TimestampQuery) || !this.trackTimestamp) return;
|
|
1100
|
+
|
|
1101
|
+
const renderContextData = this.get(renderContext);
|
|
1095
1102
|
const { currentTimestampQueryBuffer } = renderContextData;
|
|
1096
|
-
|
|
1097
|
-
if (
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
const times = new BigUint64Array(
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1103
|
+
|
|
1104
|
+
if (currentTimestampQueryBuffer === undefined) return;
|
|
1105
|
+
|
|
1106
|
+
const buffer = currentTimestampQueryBuffer;
|
|
1107
|
+
|
|
1108
|
+
try {
|
|
1109
|
+
await buffer.mapAsync(GPUMapMode.READ);
|
|
1110
|
+
const times = new BigUint64Array(buffer.getMappedRange());
|
|
1111
|
+
const duration = Number(times[1] - times[0]) / 1000000;
|
|
1112
|
+
this.renderer.info.updateTimestamp(type, duration);
|
|
1113
|
+
} catch (error) {
|
|
1114
|
+
console.error(`Error mapping buffer: ${error}`);
|
|
1115
|
+
// Optionally handle the error, e.g., re-queue the buffer or skip it
|
|
1116
|
+
} finally {
|
|
1117
|
+
buffer.unmap();
|
|
1111
1118
|
}
|
|
1112
|
-
|
|
1113
1119
|
}
|
|
1120
|
+
|
|
1114
1121
|
|
|
1115
1122
|
// node builder
|
|
1116
1123
|
|
|
@@ -1222,27 +1229,37 @@ class WebGPUBackend extends Backend {
|
|
|
1222
1229
|
|
|
1223
1230
|
}
|
|
1224
1231
|
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
const adapter = this.adapter || await WebGPU.getStaticAdapter();
|
|
1228
|
-
|
|
1229
|
-
//
|
|
1232
|
+
hasFeature( name ) {
|
|
1230
1233
|
|
|
1231
|
-
return
|
|
1234
|
+
return this.device.features.has( name );
|
|
1232
1235
|
|
|
1233
1236
|
}
|
|
1234
1237
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
if ( ! this.adapter ) {
|
|
1238
|
+
copyTextureToTexture( position, srcTexture, dstTexture, level = 0 ) {
|
|
1238
1239
|
|
|
1239
|
-
|
|
1240
|
+
const encoder = this.device.createCommandEncoder( { label: 'copyTextureToTexture_' + srcTexture.id + '_' + dstTexture.id } );
|
|
1240
1241
|
|
|
1241
|
-
|
|
1242
|
+
const sourceGPU = this.get( srcTexture ).texture;
|
|
1243
|
+
const destinationGPU = this.get( dstTexture ).texture;
|
|
1242
1244
|
|
|
1243
|
-
|
|
1245
|
+
encoder.copyTextureToTexture(
|
|
1246
|
+
{
|
|
1247
|
+
texture: sourceGPU,
|
|
1248
|
+
mipLevel: level,
|
|
1249
|
+
origin: { x: 0, y: 0, z: 0 }
|
|
1250
|
+
},
|
|
1251
|
+
{
|
|
1252
|
+
texture: destinationGPU,
|
|
1253
|
+
mipLevel: level,
|
|
1254
|
+
origin: { x: position.x, y: position.y, z: position.z }
|
|
1255
|
+
},
|
|
1256
|
+
[
|
|
1257
|
+
srcTexture.image.width,
|
|
1258
|
+
srcTexture.image.height
|
|
1259
|
+
]
|
|
1260
|
+
);
|
|
1244
1261
|
|
|
1245
|
-
|
|
1262
|
+
this.device.queue.submit( [ encoder.finish() ] );
|
|
1246
1263
|
|
|
1247
1264
|
}
|
|
1248
1265
|
|
|
@@ -228,7 +228,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
228
228
|
|
|
229
229
|
isUnfilterable( texture ) {
|
|
230
230
|
|
|
231
|
-
return texture.isDataTexture === true && texture.type === FloatType;
|
|
231
|
+
return this.getComponentTypeFromTexture( texture ) !== 'float' || ( texture.isDataTexture === true && texture.type === FloatType );
|
|
232
232
|
|
|
233
233
|
}
|
|
234
234
|
|
|
@@ -254,6 +254,21 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
254
254
|
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
258
|
+
|
|
259
|
+
if ( shaderStage === 'fragment' ) {
|
|
260
|
+
|
|
261
|
+
// TODO handle i32 or u32 --> uvSnippet, array_index: A, ddx, ddy
|
|
262
|
+
return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
|
|
263
|
+
|
|
264
|
+
} else {
|
|
265
|
+
|
|
266
|
+
console.error( `WebGPURenderer: THREE.TextureNode.gradient() does not support ${ shaderStage } shader.` );
|
|
267
|
+
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
257
272
|
generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
258
273
|
|
|
259
274
|
if ( shaderStage === 'fragment' ) {
|
|
@@ -522,7 +537,7 @@ ${ flowData.code }
|
|
|
522
537
|
|
|
523
538
|
getFragCoord() {
|
|
524
539
|
|
|
525
|
-
return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.
|
|
540
|
+
return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xyz';
|
|
526
541
|
|
|
527
542
|
}
|
|
528
543
|
|
|
@@ -759,11 +774,13 @@ ${ flowData.code }
|
|
|
759
774
|
|
|
760
775
|
const format = getFormat( texture );
|
|
761
776
|
|
|
762
|
-
textureType =
|
|
777
|
+
textureType = `texture_storage_2d<${ format }, write>`;
|
|
763
778
|
|
|
764
779
|
} else {
|
|
765
780
|
|
|
766
|
-
|
|
781
|
+
const componentPrefix = this.getComponentTypeFromTexture( texture ).charAt( 0 );
|
|
782
|
+
|
|
783
|
+
textureType = `texture_2d<${ componentPrefix }32>`;
|
|
767
784
|
|
|
768
785
|
}
|
|
769
786
|
|
|
@@ -17,7 +17,9 @@ const typedAttributeToVertexFormatPrefix = new Map( [
|
|
|
17
17
|
|
|
18
18
|
const typeArraysToVertexFormatPrefixForItemSize1 = new Map( [
|
|
19
19
|
[ Int32Array, 'sint32' ],
|
|
20
|
+
[ Int16Array, 'sint32' ], // patch for INT16
|
|
20
21
|
[ Uint32Array, 'uint32' ],
|
|
22
|
+
[ Uint16Array, 'uint32' ], // patch for UINT16
|
|
21
23
|
[ Float32Array, 'float32' ]
|
|
22
24
|
] );
|
|
23
25
|
|
|
@@ -44,9 +46,24 @@ class WebGPUAttributeUtils {
|
|
|
44
46
|
|
|
45
47
|
let array = bufferAttribute.array;
|
|
46
48
|
|
|
49
|
+
// patch for INT16 and UINT16
|
|
50
|
+
if ( attribute.normalized === false && ( array.constructor === Int16Array || array.constructor === Uint16Array ) ) {
|
|
51
|
+
|
|
52
|
+
const tempArray = new Uint32Array( array.length );
|
|
53
|
+
for ( let i = 0; i < array.length; i ++ ) {
|
|
54
|
+
|
|
55
|
+
tempArray[ i ] = array[ i ];
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
array = tempArray;
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
bufferAttribute.array = array;
|
|
64
|
+
|
|
47
65
|
if ( ( bufferAttribute.isStorageBufferAttribute || bufferAttribute.isStorageInstancedBufferAttribute ) && bufferAttribute.itemSize === 3 ) {
|
|
48
66
|
|
|
49
|
-
bufferAttribute.itemSize = 4;
|
|
50
67
|
array = new array.constructor( bufferAttribute.count * 4 );
|
|
51
68
|
|
|
52
69
|
for ( let i = 0; i < bufferAttribute.count; i ++ ) {
|
|
@@ -55,6 +72,10 @@ class WebGPUAttributeUtils {
|
|
|
55
72
|
|
|
56
73
|
}
|
|
57
74
|
|
|
75
|
+
// Update BufferAttribute
|
|
76
|
+
bufferAttribute.itemSize = 4;
|
|
77
|
+
bufferAttribute.array = array;
|
|
78
|
+
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
const size = array.byteLength + ( ( 4 - ( array.byteLength % 4 ) ) % 4 ); // ensure 4 byte alignment, see #20441
|
|
@@ -149,6 +170,13 @@ class WebGPUAttributeUtils {
|
|
|
149
170
|
|
|
150
171
|
}
|
|
151
172
|
|
|
173
|
+
// patch for INT16 and UINT16
|
|
174
|
+
if ( geometryAttribute.normalized === false && ( geometryAttribute.array.constructor === Int16Array || geometryAttribute.array.constructor === Uint16Array ) ) {
|
|
175
|
+
|
|
176
|
+
arrayStride = 4;
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
152
180
|
vertexBufferLayout = {
|
|
153
181
|
arrayStride,
|
|
154
182
|
attributes: [],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
GPUTextureAspect, GPUTextureViewDimension, GPUBufferBindingType, GPUTextureSampleType
|
|
3
3
|
} from './WebGPUConstants.js';
|
|
4
|
-
import { FloatType } from 'three';
|
|
4
|
+
import { FloatType, IntType, UnsignedIntType } from 'three';
|
|
5
5
|
|
|
6
6
|
class WebGPUBindingUtils {
|
|
7
7
|
|
|
@@ -73,11 +73,25 @@ class WebGPUBindingUtils {
|
|
|
73
73
|
|
|
74
74
|
texture.sampleType = GPUTextureSampleType.Depth;
|
|
75
75
|
|
|
76
|
-
} else if ( binding.texture.isDataTexture
|
|
76
|
+
} else if ( binding.texture.isDataTexture ) {
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
const type = binding.texture.type;
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
if ( type === IntType ) {
|
|
81
|
+
|
|
82
|
+
texture.sampleType = GPUTextureSampleType.SInt;
|
|
83
|
+
|
|
84
|
+
} else if ( type === UnsignedIntType ) {
|
|
85
|
+
|
|
86
|
+
texture.sampleType = GPUTextureSampleType.UInt;
|
|
87
|
+
|
|
88
|
+
} else if ( type === FloatType ) {
|
|
89
|
+
|
|
90
|
+
// @TODO: Add support for this soon: backend.hasFeature( 'float32-filterable' )
|
|
91
|
+
|
|
92
|
+
texture.sampleType = GPUTextureSampleType.UnfilterableFloat;
|
|
93
|
+
|
|
94
|
+
}
|
|
81
95
|
|
|
82
96
|
}
|
|
83
97
|
|