@needle-tools/three 0.169.20 → 0.183.2-canary.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/LICENSE +1 -1
- package/README.md +5 -6
- package/build/three.cjs +54178 -56709
- package/build/three.core.js +59506 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +11645 -73012
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +648 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +53905 -51657
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +53884 -51814
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
- package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
- package/examples/jsm/Addons.js +5 -15
- package/examples/jsm/animation/AnimationClipCreator.js +58 -6
- package/examples/jsm/animation/CCDIKSolver.js +152 -45
- package/examples/jsm/capabilities/WebGL.js +28 -29
- package/examples/jsm/capabilities/WebGPU.js +19 -17
- package/examples/jsm/controls/ArcballControls.js +474 -178
- package/examples/jsm/controls/DragControls.js +100 -58
- package/examples/jsm/controls/FirstPersonControls.js +116 -6
- package/examples/jsm/controls/FlyControls.js +50 -2
- package/examples/jsm/controls/MapControls.js +96 -8
- package/examples/jsm/controls/OrbitControls.js +496 -57
- package/examples/jsm/controls/PointerLockControls.js +115 -22
- package/examples/jsm/controls/TrackballControls.js +166 -14
- package/examples/jsm/controls/TransformControls.js +336 -26
- package/examples/jsm/csm/CSM.js +232 -18
- package/examples/jsm/csm/CSMFrustum.js +61 -4
- package/examples/jsm/csm/CSMHelper.js +50 -0
- package/examples/jsm/csm/CSMShader.js +13 -1
- package/examples/jsm/csm/CSMShadowNode.js +599 -0
- package/examples/jsm/curves/CurveExtras.js +303 -31
- package/examples/jsm/curves/NURBSCurve.js +91 -16
- package/examples/jsm/curves/NURBSSurface.js +52 -6
- package/examples/jsm/curves/NURBSUtils.js +102 -112
- package/examples/jsm/curves/NURBSVolume.js +24 -4
- package/examples/jsm/effects/AnaglyphEffect.js +134 -7
- package/examples/jsm/effects/AsciiEffect.js +69 -22
- package/examples/jsm/effects/OutlineEffect.js +61 -111
- package/examples/jsm/effects/ParallaxBarrierEffect.js +30 -0
- package/examples/jsm/effects/StereoEffect.js +31 -0
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/DebugEnvironment.js +50 -0
- package/examples/jsm/environments/RoomEnvironment.js +83 -42
- package/examples/jsm/exporters/DRACOExporter.js +56 -14
- package/examples/jsm/exporters/EXRExporter.js +40 -9
- package/examples/jsm/exporters/GLTFExporter.js +502 -169
- package/examples/jsm/exporters/OBJExporter.js +21 -1
- package/examples/jsm/exporters/PLYExporter.js +44 -12
- package/examples/jsm/exporters/STLExporter.js +27 -5
- package/examples/jsm/exporters/USDZExporter.js +781 -291
- package/examples/jsm/geometries/BoxLineGeometry.js +23 -0
- package/examples/jsm/geometries/ConvexGeometry.js +19 -0
- package/examples/jsm/geometries/DecalGeometry.js +91 -30
- package/examples/jsm/geometries/ParametricFunctions.js +100 -0
- package/examples/jsm/geometries/ParametricGeometry.js +38 -5
- package/examples/jsm/geometries/RoundedBoxGeometry.js +68 -7
- package/examples/jsm/geometries/TeapotGeometry.js +23 -38
- package/examples/jsm/geometries/TextGeometry.js +48 -29
- package/examples/jsm/gpgpu/BitonicSort.js +715 -0
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/LightProbeHelper.js +36 -0
- package/examples/jsm/helpers/LightProbeHelperGPU.js +38 -1
- package/examples/jsm/helpers/OctreeHelper.js +36 -0
- package/examples/jsm/helpers/PositionalAudioHelper.js +60 -0
- package/examples/jsm/helpers/RapierHelper.js +59 -0
- package/examples/jsm/helpers/RectAreaLightHelper.js +36 -3
- package/examples/jsm/helpers/TextureHelper.js +28 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +61 -2
- package/examples/jsm/helpers/VertexTangentsHelper.js +47 -2
- package/examples/jsm/helpers/ViewHelper.js +181 -9
- package/examples/jsm/inspector/Inspector.js +487 -0
- package/examples/jsm/inspector/RendererInspector.js +425 -0
- package/examples/jsm/inspector/tabs/Console.js +238 -0
- package/examples/jsm/inspector/tabs/Parameters.js +348 -0
- package/examples/jsm/inspector/tabs/Performance.js +268 -0
- package/examples/jsm/inspector/tabs/Viewer.js +166 -0
- package/examples/jsm/inspector/ui/Graph.js +95 -0
- package/examples/jsm/inspector/ui/Item.js +170 -0
- package/examples/jsm/inspector/ui/List.js +75 -0
- package/examples/jsm/inspector/ui/Profiler.js +1975 -0
- package/examples/jsm/inspector/ui/Style.js +1613 -0
- package/examples/jsm/inspector/ui/Tab.js +233 -0
- package/examples/jsm/inspector/ui/Values.js +439 -0
- package/examples/jsm/inspector/ui/utils.js +56 -0
- package/examples/jsm/interactive/HTMLMesh.js +43 -12
- package/examples/jsm/interactive/InteractiveGroup.js +170 -52
- package/examples/jsm/interactive/SelectionBox.js +106 -9
- package/examples/jsm/interactive/SelectionHelper.js +76 -30
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +76 -58
- package/examples/jsm/libs/motion-controllers.module.js +1 -1
- package/examples/jsm/lighting/TiledLighting.js +42 -0
- package/examples/jsm/lights/LightProbeGenerator.js +44 -7
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +50 -14
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +16 -0
- package/examples/jsm/lines/Line2.js +41 -4
- package/examples/jsm/lines/LineGeometry.js +80 -2
- package/examples/jsm/lines/LineMaterial.js +105 -5
- package/examples/jsm/lines/LineSegments2.js +54 -4
- package/examples/jsm/lines/LineSegmentsGeometry.js +65 -8
- package/examples/jsm/lines/Wireframe.js +41 -4
- package/examples/jsm/lines/WireframeGeometry2.js +27 -2
- package/examples/jsm/lines/webgpu/Line2.js +28 -2
- package/examples/jsm/lines/webgpu/LineSegments2.js +59 -24
- package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
- package/examples/jsm/loaders/3DMLoader.js +78 -6
- package/examples/jsm/loaders/3MFLoader.js +148 -7
- package/examples/jsm/loaders/AMFLoader.js +34 -14
- package/examples/jsm/loaders/BVHLoader.js +59 -12
- package/examples/jsm/loaders/ColladaLoader.js +61 -4027
- package/examples/jsm/loaders/DDSLoader.js +68 -1
- package/examples/jsm/loaders/DRACOLoader.js +146 -22
- package/examples/jsm/loaders/EXRLoader.js +255 -34
- package/examples/jsm/loaders/FBXLoader.js +80 -42
- package/examples/jsm/loaders/FontLoader.js +83 -6
- package/examples/jsm/loaders/GCodeLoader.js +71 -14
- package/examples/jsm/loaders/GLTFLoader.js +381 -263
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +52 -3
- package/examples/jsm/loaders/HDRLoader.js +485 -0
- package/examples/jsm/loaders/IESLoader.js +42 -0
- package/examples/jsm/loaders/KMZLoader.js +39 -6
- package/examples/jsm/loaders/KTX2Loader.js +124 -48
- package/examples/jsm/loaders/KTXLoader.js +31 -10
- package/examples/jsm/loaders/LDrawLoader.js +192 -145
- package/examples/jsm/loaders/LUT3dlLoader.js +47 -10
- package/examples/jsm/loaders/LUTCubeLoader.js +46 -9
- package/examples/jsm/loaders/LUTImageLoader.js +79 -38
- package/examples/jsm/loaders/LWOLoader.js +54 -59
- package/examples/jsm/loaders/LottieLoader.js +54 -1
- package/examples/jsm/loaders/MD2Loader.js +37 -1
- package/examples/jsm/loaders/MDDLoader.js +57 -12
- package/examples/jsm/loaders/MTLLoader.js +60 -35
- package/examples/jsm/loaders/MaterialXLoader.js +268 -34
- package/examples/jsm/loaders/NRRDLoader.js +40 -8
- package/examples/jsm/loaders/OBJLoader.js +51 -2
- package/examples/jsm/loaders/PCDLoader.js +173 -21
- package/examples/jsm/loaders/PDBLoader.js +41 -2
- package/examples/jsm/loaders/PLYLoader.js +70 -39
- package/examples/jsm/loaders/PVRLoader.js +25 -6
- package/examples/jsm/loaders/RGBELoader.js +6 -438
- package/examples/jsm/loaders/STLLoader.js +48 -38
- package/examples/jsm/loaders/SVGLoader.js +119 -25
- package/examples/jsm/loaders/TDSLoader.js +92 -74
- package/examples/jsm/loaders/TGALoader.js +23 -2
- package/examples/jsm/loaders/TIFFLoader.js +23 -0
- package/examples/jsm/loaders/TTFLoader.js +50 -3
- package/examples/jsm/loaders/USDLoader.js +279 -0
- package/examples/jsm/loaders/USDZLoader.js +4 -858
- package/examples/jsm/loaders/UltraHDRLoader.js +338 -166
- package/examples/jsm/loaders/VOXLoader.js +688 -87
- package/examples/jsm/loaders/VRMLLoader.js +121 -12
- package/examples/jsm/loaders/VTKLoader.js +77 -25
- package/examples/jsm/loaders/XYZLoader.js +36 -0
- package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
- package/examples/jsm/loaders/lwo/IFFParser.js +77 -77
- package/examples/jsm/loaders/usd/USDAParser.js +822 -0
- package/examples/jsm/loaders/usd/USDCParser.js +1852 -0
- package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
- package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
- package/examples/jsm/math/Capsule.js +91 -14
- package/examples/jsm/math/ColorConverter.js +22 -0
- package/examples/jsm/math/ColorSpaces.js +74 -2
- package/examples/jsm/math/ConvexHull.js +517 -93
- package/examples/jsm/math/ImprovedNoise.js +32 -15
- package/examples/jsm/math/Lut.js +113 -0
- package/examples/jsm/math/MeshSurfaceSampler.js +78 -13
- package/examples/jsm/math/OBB.js +141 -29
- package/examples/jsm/math/Octree.js +283 -7
- package/examples/jsm/math/SimplexNoise.js +68 -42
- package/examples/jsm/misc/ConvexObjectBreaker.js +45 -25
- package/examples/jsm/misc/GPUComputationRenderer.js +96 -20
- package/examples/jsm/misc/Gyroscope.js +12 -0
- package/examples/jsm/misc/MD2Character.js +117 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +175 -11
- package/examples/jsm/misc/MorphAnimMesh.js +44 -0
- package/examples/jsm/misc/MorphBlendMesh.js +103 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +100 -54
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
- package/examples/jsm/misc/RollerCoaster.js +57 -0
- package/examples/jsm/misc/TubePainter.js +437 -40
- package/examples/jsm/misc/Volume.js +123 -76
- package/examples/jsm/misc/VolumeSlice.js +95 -49
- package/examples/jsm/modifiers/CurveModifier.js +66 -38
- package/examples/jsm/modifiers/CurveModifierGPU.js +42 -19
- package/examples/jsm/modifiers/EdgeSplitModifier.js +20 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +24 -10
- package/examples/jsm/modifiers/TessellateModifier.js +35 -2
- package/examples/jsm/objects/GroundedSkybox.js +25 -6
- package/examples/jsm/objects/Lensflare.js +94 -2
- package/examples/jsm/objects/LensflareMesh.js +64 -10
- package/examples/jsm/objects/MarchingCubes.js +90 -5
- package/examples/jsm/objects/Reflector.js +76 -2
- package/examples/jsm/objects/ReflectorForSSRPass.js +41 -0
- package/examples/jsm/objects/Refractor.js +62 -0
- package/examples/jsm/objects/ShadowMesh.js +54 -4
- package/examples/jsm/objects/Sky.js +106 -16
- package/examples/jsm/objects/SkyMesh.js +211 -38
- package/examples/jsm/objects/Water.js +49 -8
- package/examples/jsm/objects/Water2.js +49 -7
- package/examples/jsm/objects/Water2Mesh.js +50 -9
- package/examples/jsm/objects/WaterMesh.js +136 -43
- package/examples/jsm/physics/AmmoPhysics.js +60 -7
- package/examples/jsm/physics/JoltPhysics.js +65 -12
- package/examples/jsm/physics/RapierPhysics.js +217 -21
- package/examples/jsm/postprocessing/AfterimagePass.js +110 -29
- package/examples/jsm/postprocessing/BloomPass.js +128 -26
- package/examples/jsm/postprocessing/BokehPass.js +99 -22
- package/examples/jsm/postprocessing/ClearPass.js +54 -3
- package/examples/jsm/postprocessing/CubeTexturePass.js +82 -21
- package/examples/jsm/postprocessing/DotScreenPass.js +59 -10
- package/examples/jsm/postprocessing/EffectComposer.js +140 -6
- package/examples/jsm/postprocessing/FXAAPass.js +40 -0
- package/examples/jsm/postprocessing/FilmPass.js +54 -5
- package/examples/jsm/postprocessing/GTAOPass.js +202 -57
- package/examples/jsm/postprocessing/GlitchPass.js +86 -34
- package/examples/jsm/postprocessing/HalftonePass.js +65 -10
- package/examples/jsm/postprocessing/LUTPass.js +38 -8
- package/examples/jsm/postprocessing/MaskPass.js +91 -0
- package/examples/jsm/postprocessing/OutlinePass.js +272 -135
- package/examples/jsm/postprocessing/OutputPass.js +65 -14
- package/examples/jsm/postprocessing/Pass.js +100 -4
- package/examples/jsm/postprocessing/RenderPass.js +94 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +124 -45
- package/examples/jsm/postprocessing/RenderTransitionPass.js +120 -21
- package/examples/jsm/postprocessing/SAOPass.js +128 -55
- package/examples/jsm/postprocessing/SMAAPass.js +106 -75
- package/examples/jsm/postprocessing/SSAARenderPass.js +118 -35
- package/examples/jsm/postprocessing/SSAOPass.js +173 -60
- package/examples/jsm/postprocessing/SSRPass.js +268 -53
- package/examples/jsm/postprocessing/SavePass.js +69 -16
- package/examples/jsm/postprocessing/ShaderPass.js +65 -7
- package/examples/jsm/postprocessing/TAARenderPass.js +79 -24
- package/examples/jsm/postprocessing/TexturePass.js +72 -8
- package/examples/jsm/postprocessing/UnrealBloomPass.js +168 -59
- package/examples/jsm/renderers/CSS2DRenderer.js +98 -5
- package/examples/jsm/renderers/CSS3DRenderer.js +111 -7
- package/examples/jsm/renderers/Projector.js +288 -32
- package/examples/jsm/renderers/SVGRenderer.js +323 -61
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +3 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +5 -1
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +12 -5
- package/examples/jsm/shaders/AfterimageShader.js +8 -3
- package/examples/jsm/shaders/BasicShader.js +8 -1
- package/examples/jsm/shaders/BleachBypassShader.js +10 -3
- package/examples/jsm/shaders/BlendShader.js +8 -1
- package/examples/jsm/shaders/BokehShader.js +9 -3
- package/examples/jsm/shaders/BokehShader2.js +11 -4
- package/examples/jsm/shaders/BrightnessContrastShader.js +10 -4
- package/examples/jsm/shaders/ColorCorrectionShader.js +8 -1
- package/examples/jsm/shaders/ColorifyShader.js +8 -1
- package/examples/jsm/shaders/ConvolutionShader.js +9 -38
- package/examples/jsm/shaders/CopyShader.js +8 -1
- package/examples/jsm/shaders/DOFMipMapShader.js +10 -3
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +10 -1
- package/examples/jsm/shaders/DigitalGlitch.js +10 -7
- package/examples/jsm/shaders/DotScreenShader.js +8 -3
- package/examples/jsm/shaders/ExposureShader.js +8 -1
- package/examples/jsm/shaders/FXAAShader.js +233 -221
- package/examples/jsm/shaders/FilmShader.js +13 -0
- package/examples/jsm/shaders/FocusShader.js +8 -3
- package/examples/jsm/shaders/FreiChenShader.js +10 -3
- package/examples/jsm/shaders/GTAOShader.js +55 -45
- package/examples/jsm/shaders/GammaCorrectionShader.js +11 -2
- package/examples/jsm/shaders/HalftoneShader.js +24 -4
- package/examples/jsm/shaders/HorizontalBlurShader.js +12 -3
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +9 -2
- package/examples/jsm/shaders/HueSaturationShader.js +10 -3
- package/examples/jsm/shaders/KaleidoShader.js +11 -4
- package/examples/jsm/shaders/LuminosityHighPassShader.js +8 -4
- package/examples/jsm/shaders/LuminosityShader.js +8 -2
- package/examples/jsm/shaders/MirrorShader.js +10 -4
- package/examples/jsm/shaders/NormalMapShader.js +7 -2
- package/examples/jsm/shaders/OutputShader.js +19 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +30 -17
- package/examples/jsm/shaders/RGBShiftShader.js +8 -1
- package/examples/jsm/shaders/SAOShader.js +27 -5
- package/examples/jsm/shaders/SMAAShader.js +24 -1
- package/examples/jsm/shaders/SSAOShader.js +37 -6
- package/examples/jsm/shaders/SSRShader.js +32 -6
- package/examples/jsm/shaders/SepiaShader.js +8 -3
- package/examples/jsm/shaders/SobelOperatorShader.js +9 -3
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +13 -8
- package/examples/jsm/shaders/TechnicolorShader.js +10 -4
- package/examples/jsm/shaders/ToonShader.js +29 -6
- package/examples/jsm/shaders/TriangleBlurShader.js +9 -4
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +19 -6
- package/examples/jsm/shaders/VelocityShader.js +8 -1
- package/examples/jsm/shaders/VerticalBlurShader.js +9 -2
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +8 -1
- package/examples/jsm/shaders/VignetteShader.js +8 -3
- package/examples/jsm/shaders/VolumeShader.js +11 -2
- package/examples/jsm/shaders/WaterRefractionShader.js +11 -0
- package/examples/jsm/textures/FlakesTexture.js +14 -0
- package/examples/jsm/transpiler/AST.js +436 -31
- package/examples/jsm/transpiler/GLSLDecoder.js +380 -135
- package/examples/jsm/transpiler/Linker.js +327 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -1
- package/examples/jsm/transpiler/TSLEncoder.js +363 -97
- package/examples/jsm/transpiler/Transpiler.js +50 -1
- package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
- package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +244 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +282 -0
- package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +11 -4
- package/examples/jsm/tsl/display/BloomNode.js +534 -0
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +207 -0
- package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
- package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
- package/examples/jsm/tsl/display/FXAANode.js +365 -0
- package/examples/jsm/tsl/display/FilmNode.js +101 -0
- package/examples/jsm/tsl/display/GTAONode.js +571 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +389 -0
- package/examples/jsm/tsl/display/GodraysNode.js +624 -0
- package/examples/jsm/tsl/display/LensflareNode.js +279 -0
- package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
- package/examples/jsm/tsl/display/MotionBlur.js +33 -0
- package/examples/jsm/tsl/display/OutlineNode.js +762 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
- package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
- package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
- package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
- package/examples/jsm/tsl/display/SMAANode.js +768 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +120 -49
- package/examples/jsm/tsl/display/SSGINode.js +642 -0
- package/examples/jsm/tsl/display/SSRNode.js +656 -0
- package/examples/jsm/tsl/display/SSSNode.js +490 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +9 -2
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +61 -19
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +48 -12
- package/examples/jsm/tsl/display/TRAANode.js +726 -0
- package/examples/jsm/tsl/display/TransitionNode.js +141 -0
- package/examples/jsm/tsl/display/boxBlur.js +65 -0
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/display/hashBlur.js +54 -0
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
- package/examples/jsm/tsl/math/Bayer.js +73 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
- package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
- package/examples/jsm/tsl/utils/Raymarching.js +70 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +91 -29
- package/examples/jsm/utils/CameraUtils.js +15 -6
- package/examples/jsm/utils/GeometryCompressionUtils.js +23 -30
- package/examples/jsm/utils/GeometryUtils.js +32 -27
- package/examples/jsm/utils/LDrawUtils.js +14 -5
- package/examples/jsm/utils/SceneOptimizer.js +458 -0
- package/examples/jsm/utils/SceneUtils.js +53 -3
- package/examples/jsm/utils/ShadowMapViewer.js +72 -33
- package/examples/jsm/utils/ShadowMapViewerGPU.js +61 -29
- package/examples/jsm/utils/SkeletonUtils.js +48 -0
- package/examples/jsm/utils/SortUtils.js +17 -5
- package/examples/jsm/utils/UVsDebug.js +12 -4
- package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +16 -0
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +20 -2
- package/examples/jsm/utils/WorkerPool.js +67 -2
- package/examples/jsm/webxr/ARButton.js +19 -0
- package/examples/jsm/webxr/OculusHandModel.js +84 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +148 -22
- package/examples/jsm/webxr/Text2D.js +20 -6
- package/examples/jsm/webxr/VRButton.js +31 -0
- package/examples/jsm/webxr/XRButton.js +23 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +94 -3
- package/examples/jsm/webxr/XREstimatedLight.js +35 -4
- package/examples/jsm/webxr/XRHandMeshModel.js +37 -0
- package/examples/jsm/webxr/XRHandModelFactory.js +96 -6
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +44 -0
- package/examples/jsm/webxr/XRPlanes.js +18 -0
- package/package.json +29 -34
- package/src/Three.Core.js +198 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +641 -0
- package/src/Three.WebGPU.Nodes.js +14 -186
- package/src/Three.WebGPU.js +16 -186
- package/src/Three.js +2 -197
- package/src/animation/AnimationAction.js +263 -31
- package/src/animation/AnimationClip.js +162 -7
- package/src/animation/AnimationMixer.js +99 -15
- package/src/animation/AnimationObjectGroup.js +45 -21
- package/src/animation/AnimationUtils.js +163 -24
- package/src/animation/KeyframeTrack.js +191 -17
- package/src/animation/PropertyBinding.js +91 -16
- package/src/animation/PropertyMixer.js +72 -5
- package/src/animation/tracks/BooleanKeyframeTrack.js +33 -6
- package/src/animation/tracks/ColorKeyframeTrack.js +26 -5
- package/src/animation/tracks/NumberKeyframeTrack.js +26 -2
- package/src/animation/tracks/QuaternionKeyframeTrack.js +30 -1
- package/src/animation/tracks/StringKeyframeTrack.js +33 -2
- package/src/animation/tracks/VectorKeyframeTrack.js +26 -2
- package/src/audio/Audio.js +386 -8
- package/src/audio/AudioAnalyser.js +58 -1
- package/src/audio/AudioContext.js +15 -0
- package/src/audio/AudioListener.js +94 -13
- package/src/audio/PositionalAudio.js +107 -0
- package/src/cameras/ArrayCamera.js +37 -0
- package/src/cameras/Camera.js +61 -0
- package/src/cameras/CubeCamera.js +86 -0
- package/src/cameras/OrthographicCamera.js +110 -1
- package/src/cameras/PerspectiveCamera.js +174 -35
- package/src/cameras/StereoCamera.js +48 -2
- package/src/constants.js +1546 -11
- package/src/core/BufferAttribute.js +417 -3
- package/src/core/BufferGeometry.js +407 -22
- package/src/core/Clock.js +69 -8
- package/src/core/EventDispatcher.js +52 -8
- package/src/core/GLBufferAttribute.js +113 -2
- package/src/core/InstancedBufferAttribute.js +29 -0
- package/src/core/InstancedBufferGeometry.js +20 -0
- package/src/core/InstancedInterleavedBuffer.js +26 -0
- package/src/core/InterleavedBuffer.js +141 -7
- package/src/core/InterleavedBufferAttribute.js +200 -2
- package/src/core/Layers.js +71 -10
- package/src/core/Object3D.js +673 -26
- package/src/core/Raycaster.js +136 -2
- package/src/core/RenderTarget.js +256 -27
- package/src/core/RenderTarget3D.js +48 -0
- package/src/core/Timer.js +184 -0
- package/src/core/Uniform.js +29 -0
- package/src/core/UniformsGroup.js +84 -2
- package/src/extras/Controls.js +89 -1
- package/src/extras/DataUtils.js +50 -9
- package/src/extras/Earcut.js +18 -779
- package/src/extras/ImageUtils.js +22 -14
- package/src/extras/PMREMGenerator.js +316 -67
- package/src/extras/ShapeUtils.js +24 -2
- package/src/extras/TextureUtils.js +101 -15
- package/src/extras/core/Curve.js +156 -55
- package/src/extras/core/CurvePath.js +63 -22
- package/src/extras/core/Interpolations.js +34 -2
- package/src/extras/core/Path.js +134 -1
- package/src/extras/core/Shape.js +66 -3
- package/src/extras/core/ShapePath.js +80 -4
- package/src/extras/curves/ArcCurve.js +22 -0
- package/src/extras/curves/CatmullRomCurve3.js +89 -18
- package/src/extras/curves/CubicBezierCurve.js +67 -0
- package/src/extras/curves/CubicBezierCurve3.js +50 -0
- package/src/extras/curves/EllipseCurve.js +102 -0
- package/src/extras/curves/LineCurve.js +36 -0
- package/src/extras/curves/LineCurve3.js +36 -0
- package/src/extras/curves/QuadraticBezierCurve.js +59 -0
- package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
- package/src/extras/curves/SplineCurve.js +48 -0
- package/src/extras/lib/earcut.js +685 -0
- package/src/geometries/BoxGeometry.js +39 -0
- package/src/geometries/CapsuleGeometry.js +196 -11
- package/src/geometries/CircleGeometry.js +41 -0
- package/src/geometries/ConeGeometry.js +39 -0
- package/src/geometries/CylinderGeometry.js +42 -2
- package/src/geometries/DodecahedronGeometry.js +33 -0
- package/src/geometries/EdgesGeometry.js +30 -2
- package/src/geometries/ExtrudeGeometry.js +148 -52
- package/src/geometries/IcosahedronGeometry.js +33 -0
- package/src/geometries/LatheGeometry.js +44 -3
- package/src/geometries/OctahedronGeometry.js +33 -0
- package/src/geometries/PlaneGeometry.js +35 -0
- package/src/geometries/PolyhedronGeometry.js +30 -1
- package/src/geometries/RingGeometry.js +37 -0
- package/src/geometries/ShapeGeometry.js +38 -0
- package/src/geometries/SphereGeometry.js +38 -0
- package/src/geometries/TetrahedronGeometry.js +33 -0
- package/src/geometries/TorusGeometry.js +44 -3
- package/src/geometries/TorusKnotGeometry.js +39 -0
- package/src/geometries/TubeGeometry.js +50 -0
- package/src/geometries/WireframeGeometry.js +32 -0
- package/src/helpers/ArrowHelper.js +62 -5
- package/src/helpers/AxesHelper.js +28 -0
- package/src/helpers/Box3Helper.js +28 -0
- package/src/helpers/BoxHelper.js +43 -7
- package/src/helpers/CameraHelper.js +103 -27
- package/src/helpers/DirectionalLightHelper.js +55 -0
- package/src/helpers/GridHelper.js +26 -0
- package/src/helpers/HemisphereLightHelper.js +42 -0
- package/src/helpers/PlaneHelper.js +33 -0
- package/src/helpers/PointLightHelper.js +43 -24
- package/src/helpers/PolarGridHelper.js +30 -0
- package/src/helpers/SkeletonHelper.js +73 -7
- package/src/helpers/SpotLightHelper.js +43 -0
- package/src/lights/AmbientLight.js +25 -0
- package/src/lights/DirectionalLight.js +70 -0
- package/src/lights/DirectionalLightShadow.js +15 -0
- package/src/lights/HemisphereLight.js +42 -0
- package/src/lights/Light.js +37 -11
- package/src/lights/LightProbe.js +37 -9
- package/src/lights/LightShadow.js +202 -7
- package/src/lights/PointLight.js +74 -0
- package/src/lights/PointLightShadow.js +15 -80
- package/src/lights/RectAreaLight.js +59 -0
- package/src/lights/SpotLight.js +124 -1
- package/src/lights/SpotLightShadow.js +33 -3
- package/src/lights/webgpu/IESSpotLight.js +22 -0
- package/src/lights/webgpu/ProjectorLight.js +46 -0
- package/src/loaders/AnimationLoader.js +34 -2
- package/src/loaders/AudioLoader.js +34 -2
- package/src/loaders/BufferGeometryLoader.js +38 -13
- package/src/loaders/Cache.js +75 -2
- package/src/loaders/CompressedTextureLoader.js +36 -3
- package/src/loaders/CubeTextureLoader.js +45 -0
- package/src/loaders/DataTextureLoader.js +45 -4
- package/src/loaders/FileLoader.js +85 -5
- package/src/loaders/ImageBitmapLoader.js +113 -11
- package/src/loaders/ImageLoader.js +85 -8
- package/src/loaders/Loader.js +144 -0
- package/src/loaders/LoaderUtils.js +18 -36
- package/src/loaders/LoadingManager.js +187 -0
- package/src/loaders/MaterialLoader.js +62 -3
- package/src/loaders/ObjectLoader.js +131 -31
- package/src/loaders/TextureLoader.js +33 -0
- package/src/loaders/nodes/NodeLoader.js +68 -4
- package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
- package/src/loaders/nodes/NodeObjectLoader.js +61 -0
- package/src/materials/LineBasicMaterial.js +74 -1
- package/src/materials/LineDashedMaterial.js +52 -1
- package/src/materials/Material.js +502 -8
- package/src/materials/MeshBasicMaterial.js +168 -2
- package/src/materials/MeshDepthMaterial.js +94 -0
- package/src/materials/MeshDistanceMaterial.js +76 -0
- package/src/materials/MeshLambertMaterial.js +283 -0
- package/src/materials/MeshMatcapMaterial.js +164 -0
- package/src/materials/MeshNormalMaterial.js +114 -0
- package/src/materials/MeshPhongMaterial.js +298 -0
- package/src/materials/MeshPhysicalMaterial.js +296 -4
- package/src/materials/MeshStandardMaterial.js +300 -2
- package/src/materials/MeshToonMaterial.js +219 -0
- package/src/materials/PointsMaterial.js +89 -0
- package/src/materials/RawShaderMaterial.js +25 -0
- package/src/materials/ShaderMaterial.js +234 -6
- package/src/materials/ShadowMaterial.js +54 -0
- package/src/materials/SpriteMaterial.js +82 -0
- package/src/materials/nodes/Line2NodeMaterial.js +158 -53
- package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
- package/src/materials/nodes/LineDashedNodeMaterial.js +81 -6
- package/src/materials/nodes/MeshBasicNodeMaterial.js +59 -2
- package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +23 -3
- package/src/materials/nodes/MeshNormalNodeMaterial.js +27 -4
- package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +276 -3
- package/src/materials/nodes/MeshSSSNodeMaterial.js +98 -10
- package/src/materials/nodes/MeshStandardNodeMaterial.js +83 -4
- package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
- package/src/materials/nodes/NodeMaterial.js +789 -74
- package/src/materials/nodes/NodeMaterials.js +0 -1
- package/src/materials/nodes/PointsNodeMaterial.js +180 -11
- package/src/materials/nodes/ShadowNodeMaterial.js +38 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +86 -23
- package/src/materials/nodes/VolumeNodeMaterial.js +57 -84
- package/src/materials/nodes/manager/NodeMaterialObserver.js +329 -12
- package/src/math/Box2.js +177 -0
- package/src/math/Box3.js +271 -0
- package/src/math/Color.js +355 -11
- package/src/math/ColorManagement.js +158 -92
- package/src/math/Cylindrical.js +65 -6
- package/src/math/Euler.js +139 -5
- package/src/math/Frustum.js +108 -9
- package/src/math/FrustumArray.js +258 -0
- package/src/math/Interpolant.js +87 -8
- package/src/math/Line3.js +221 -2
- package/src/math/MathUtils.js +408 -20
- package/src/math/Matrix2.js +70 -0
- package/src/math/Matrix3.js +229 -4
- package/src/math/Matrix4.js +489 -94
- package/src/math/Plane.js +164 -2
- package/src/math/Quaternion.js +322 -90
- package/src/math/Ray.js +162 -0
- package/src/math/Sphere.js +175 -0
- package/src/math/Spherical.js +73 -11
- package/src/math/SphericalHarmonics3.js +112 -14
- package/src/math/Triangle.js +206 -2
- package/src/math/Vector2.js +396 -10
- package/src/math/Vector3.js +550 -15
- package/src/math/Vector4.js +415 -9
- package/src/math/interpolants/BezierInterpolant.js +108 -0
- package/src/math/interpolants/CubicInterpolant.js +10 -1
- package/src/math/interpolants/DiscreteInterpolant.js +10 -2
- package/src/math/interpolants/LinearInterpolant.js +13 -0
- package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
- package/src/nodes/Nodes.js +91 -88
- package/src/nodes/TSL.js +32 -38
- package/src/nodes/accessors/AccessorsUtils.js +37 -9
- package/src/nodes/accessors/Arrays.js +68 -0
- package/src/nodes/accessors/BatchNode.js +49 -14
- package/src/nodes/accessors/Bitangent.js +82 -13
- package/src/nodes/accessors/BufferAttributeNode.js +269 -8
- package/src/nodes/accessors/BufferNode.js +91 -2
- package/src/nodes/accessors/BuiltinNode.js +63 -0
- package/src/nodes/accessors/Camera.js +400 -10
- package/src/nodes/accessors/ClippingNode.js +149 -45
- package/src/nodes/accessors/CubeTextureNode.js +137 -7
- package/src/nodes/accessors/InstanceNode.js +245 -40
- package/src/nodes/accessors/InstancedMeshNode.js +50 -0
- package/src/nodes/accessors/Lights.js +88 -0
- package/src/nodes/accessors/MaterialNode.js +355 -13
- package/src/nodes/accessors/MaterialProperties.js +57 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +52 -14
- package/src/nodes/accessors/ModelNode.js +117 -5
- package/src/nodes/accessors/ModelViewProjectionNode.js +10 -39
- package/src/nodes/accessors/MorphNode.js +73 -26
- package/src/nodes/accessors/Normal.js +174 -19
- package/src/nodes/accessors/Object3DNode.js +146 -12
- package/src/nodes/accessors/PointUVNode.js +25 -0
- package/src/nodes/accessors/Position.js +119 -7
- package/src/nodes/accessors/ReferenceBaseNode.js +190 -4
- package/src/nodes/accessors/ReferenceNode.js +223 -8
- package/src/nodes/accessors/ReflectVector.js +29 -3
- package/src/nodes/accessors/RendererReferenceNode.js +45 -2
- package/src/nodes/accessors/SceneProperties.js +53 -0
- package/src/nodes/accessors/SkinningNode.js +180 -43
- package/src/nodes/accessors/StorageBufferNode.js +278 -26
- package/src/nodes/accessors/StorageTextureNode.js +205 -12
- package/src/nodes/accessors/Tangent.js +48 -10
- package/src/nodes/accessors/TangentUtils.js +46 -0
- package/src/nodes/accessors/Texture3DNode.js +104 -11
- package/src/nodes/accessors/TextureBicubic.js +31 -4
- package/src/nodes/accessors/TextureNode.js +564 -52
- package/src/nodes/accessors/TextureSizeNode.js +42 -1
- package/src/nodes/accessors/UV.js +9 -1
- package/src/nodes/accessors/UniformArrayNode.js +226 -34
- package/src/nodes/accessors/UserDataNode.js +46 -2
- package/src/nodes/accessors/VelocityNode.js +93 -3
- package/src/nodes/accessors/VertexColorNode.js +39 -4
- package/src/nodes/code/CodeNode.js +101 -8
- package/src/nodes/code/ExpressionNode.js +29 -2
- package/src/nodes/code/FunctionCallNode.js +98 -10
- package/src/nodes/code/FunctionNode.js +69 -2
- package/src/nodes/core/ArrayNode.js +174 -0
- package/src/nodes/core/AssignNode.js +80 -9
- package/src/nodes/core/AttributeNode.js +47 -4
- package/src/nodes/core/BypassNode.js +47 -3
- package/src/nodes/core/ConstNode.js +32 -0
- package/src/nodes/core/ContextNode.js +220 -14
- package/src/nodes/core/IndexNode.js +72 -7
- package/src/nodes/core/InputNode.js +50 -1
- package/src/nodes/core/InspectorNode.js +128 -0
- package/src/nodes/core/IsolateNode.js +133 -0
- package/src/nodes/core/LightingModel.js +65 -5
- package/src/nodes/core/MRTNode.js +113 -2
- package/src/nodes/core/Node.js +595 -36
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +1840 -121
- package/src/nodes/core/NodeCache.js +41 -2
- package/src/nodes/core/NodeCode.js +31 -0
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeFrame.js +153 -24
- package/src/nodes/core/NodeFunction.js +48 -1
- package/src/nodes/core/NodeFunctionInput.js +44 -0
- package/src/nodes/core/NodeParser.js +13 -1
- package/src/nodes/core/NodeUniform.js +53 -1
- package/src/nodes/core/NodeUtils.js +201 -51
- package/src/nodes/core/NodeVar.js +47 -1
- package/src/nodes/core/NodeVarying.js +47 -1
- package/src/nodes/core/OutputStructNode.js +54 -12
- package/src/nodes/core/ParameterNode.js +60 -2
- package/src/nodes/core/PropertyNode.js +286 -7
- package/src/nodes/core/StackNode.js +337 -20
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +134 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +126 -6
- package/src/nodes/core/SubBuildNode.js +89 -0
- package/src/nodes/core/TempNode.js +31 -5
- package/src/nodes/core/UniformGroupNode.js +85 -7
- package/src/nodes/core/UniformNode.js +163 -16
- package/src/nodes/core/VarNode.js +317 -10
- package/src/nodes/core/VaryingNode.js +115 -13
- package/src/nodes/core/constants.js +40 -0
- package/src/nodes/display/BlendModes.js +171 -0
- package/src/nodes/display/BumpMapNode.js +38 -2
- package/src/nodes/display/ColorAdjustment.js +118 -6
- package/src/nodes/display/ColorSpaceFunctions.js +22 -6
- package/src/nodes/display/ColorSpaceNode.js +97 -47
- package/src/nodes/display/FrontFacingNode.js +64 -7
- package/src/nodes/display/NormalMapNode.js +101 -54
- package/src/nodes/display/PassNode.js +690 -33
- package/src/nodes/display/RenderOutputNode.js +94 -4
- package/src/nodes/display/ScreenNode.js +138 -27
- package/src/nodes/display/ToneMappingFunctions.js +62 -10
- package/src/nodes/display/ToneMappingNode.js +88 -8
- package/src/nodes/display/ToonOutlinePassNode.js +84 -4
- package/src/nodes/display/ViewportDepthNode.js +227 -10
- package/src/nodes/display/ViewportDepthTextureNode.js +39 -5
- package/src/nodes/display/ViewportSharedTextureNode.js +35 -1
- package/src/nodes/display/ViewportTextureNode.js +171 -7
- package/src/nodes/fog/Fog.js +97 -0
- package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +45 -1
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
- package/src/nodes/functions/BasicLightingModel.js +28 -6
- package/src/nodes/functions/PhongLightingModel.js +36 -6
- package/src/nodes/functions/PhysicalLightingModel.js +336 -91
- package/src/nodes/functions/ShadowMaskModel.js +30 -3
- package/src/nodes/functions/ToonLightingModel.js +21 -2
- package/src/nodes/functions/VolumetricLightingModel.js +183 -0
- package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
- package/src/nodes/geometry/RangeNode.js +97 -8
- package/src/nodes/gpgpu/AtomicFunctionNode.js +198 -23
- package/src/nodes/gpgpu/BarrierNode.js +52 -3
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +135 -6
- package/src/nodes/gpgpu/ComputeNode.js +212 -16
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +143 -9
- package/src/nodes/lighting/AONode.js +18 -0
- package/src/nodes/lighting/AmbientLightNode.js +10 -0
- package/src/nodes/lighting/AnalyticLightNode.js +186 -399
- package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
- package/src/nodes/lighting/BasicLightMapNode.js +17 -0
- package/src/nodes/lighting/DirectionalLightNode.js +12 -11
- package/src/nodes/lighting/EnvironmentNode.js +59 -19
- package/src/nodes/lighting/HemisphereLightNode.js +33 -2
- package/src/nodes/lighting/IESSpotLightNode.js +13 -1
- package/src/nodes/lighting/IrradianceNode.js +17 -0
- package/src/nodes/lighting/LightProbeNode.js +20 -0
- package/src/nodes/lighting/LightUtils.js +11 -3
- package/src/nodes/lighting/LightingContextNode.js +52 -4
- package/src/nodes/lighting/LightingNode.js +15 -6
- package/src/nodes/lighting/LightsNode.js +238 -35
- package/src/nodes/lighting/PointLightNode.js +60 -25
- package/src/nodes/lighting/PointShadowNode.js +325 -0
- package/src/nodes/lighting/ProjectorLightNode.js +91 -0
- package/src/nodes/lighting/RectAreaLightNode.js +50 -14
- package/src/nodes/lighting/ShadowBaseNode.js +81 -0
- package/src/nodes/lighting/ShadowFilterNode.js +264 -0
- package/src/nodes/lighting/ShadowNode.js +867 -0
- package/src/nodes/lighting/SpotLightNode.js +99 -18
- package/src/nodes/materialx/MaterialXNodes.js +131 -2
- package/src/nodes/materialx/lib/mx_noise.js +166 -2
- package/src/nodes/math/BitcastNode.js +156 -0
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/ConditionalNode.js +110 -21
- package/src/nodes/math/Hash.js +8 -0
- package/src/nodes/math/MathNode.js +820 -97
- package/src/nodes/math/MathUtils.js +47 -1
- package/src/nodes/math/OperatorNode.js +517 -84
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/TriNoise3D.js +17 -7
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
- package/src/nodes/parsers/GLSLNodeParser.js +11 -0
- package/src/nodes/pmrem/PMREMNode.js +180 -23
- package/src/nodes/pmrem/PMREMUtils.js +114 -5
- package/src/nodes/procedural/Checker.js +8 -0
- package/src/nodes/shapes/Shapes.js +33 -0
- package/src/nodes/tsl/TSLBase.js +10 -4
- package/src/nodes/tsl/TSLCore.js +732 -160
- package/src/nodes/utils/ArrayElementNode.js +55 -4
- package/src/nodes/utils/ConvertNode.js +31 -0
- package/src/nodes/utils/CubeMapNode.js +79 -2
- package/src/nodes/utils/DebugNode.js +83 -0
- package/src/nodes/utils/Discard.js +18 -2
- package/src/nodes/utils/EquirectUV.js +27 -0
- package/src/nodes/utils/EventNode.js +118 -0
- package/src/nodes/utils/FlipNode.js +38 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +91 -22
- package/src/nodes/utils/JoinNode.js +57 -4
- package/src/nodes/utils/LoopNode.js +193 -55
- package/src/nodes/utils/MatcapUV.js +22 -0
- package/src/nodes/utils/MaxMipLevelNode.js +49 -1
- package/src/nodes/utils/MemberNode.js +120 -0
- package/src/nodes/utils/Oscillators.js +41 -0
- package/src/nodes/utils/Packing.js +30 -1
- package/src/nodes/utils/PostProcessingUtils.js +154 -0
- package/src/nodes/utils/RTTNode.js +165 -9
- package/src/nodes/utils/ReflectorNode.js +407 -21
- package/src/nodes/utils/RemapNode.js +81 -2
- package/src/nodes/utils/RotateNode.js +41 -1
- package/src/nodes/utils/SampleNode.js +91 -0
- package/src/nodes/utils/SetNode.js +44 -1
- package/src/nodes/utils/SplitNode.js +66 -3
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/SpriteUtils.js +16 -0
- package/src/nodes/utils/StorageArrayElementNode.js +56 -3
- package/src/nodes/utils/Timer.js +26 -0
- package/src/nodes/utils/TriplanarTextures.js +65 -0
- package/src/nodes/utils/UVUtils.js +48 -0
- package/src/nodes/utils/ViewportUtils.js +12 -0
- package/src/objects/BatchedMesh.js +798 -309
- package/src/objects/Bone.js +24 -0
- package/src/objects/ClippingGroup.js +68 -0
- package/src/objects/Group.js +24 -0
- package/src/objects/InstancedMesh.js +131 -2
- package/src/objects/LOD.js +99 -5
- package/src/objects/Line.js +90 -7
- package/src/objects/LineLoop.js +20 -0
- package/src/objects/LineSegments.js +20 -1
- package/src/objects/Mesh.js +84 -0
- package/src/objects/Points.js +60 -0
- package/src/objects/Skeleton.js +120 -5
- package/src/objects/SkinnedMesh.js +102 -6
- package/src/objects/Sprite.js +65 -1
- package/src/renderers/WebGL3DRenderTarget.js +26 -0
- package/src/renderers/WebGLArrayRenderTarget.js +26 -0
- package/src/renderers/WebGLCubeRenderTarget.js +41 -5
- package/src/renderers/WebGLRenderTarget.js +19 -0
- package/src/renderers/WebGLRenderer.js +1016 -278
- package/src/renderers/common/Animation.js +123 -14
- package/src/renderers/common/Attributes.js +41 -1
- package/src/renderers/common/Backend.js +623 -44
- package/src/renderers/common/Background.js +99 -16
- package/src/renderers/common/BindGroup.js +37 -2
- package/src/renderers/common/Binding.js +46 -0
- package/src/renderers/common/Bindings.js +211 -20
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/Buffer.js +89 -0
- package/src/renderers/common/BufferUtils.js +25 -0
- package/src/renderers/common/BundleGroup.js +57 -0
- package/src/renderers/common/CanvasTarget.js +341 -0
- package/src/renderers/common/ChainMap.js +73 -10
- package/src/renderers/common/ClippingContext.js +172 -87
- package/src/renderers/common/Color4.js +40 -0
- package/src/renderers/common/ComputePipeline.js +24 -0
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/CubeRenderTarget.js +77 -7
- package/src/renderers/common/DataMap.js +37 -1
- package/src/renderers/common/Geometries.js +163 -14
- package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
- package/src/renderers/common/Info.js +81 -36
- package/src/renderers/common/InspectorBase.js +146 -0
- package/src/renderers/common/Lighting.js +57 -0
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +150 -7
- package/src/renderers/common/PostProcessing.js +22 -84
- package/src/renderers/common/ProgrammableStage.js +60 -2
- package/src/renderers/common/QuadMesh.js +63 -6
- package/src/renderers/common/RenderBundle.js +14 -8
- package/src/renderers/common/RenderBundles.js +40 -10
- package/src/renderers/common/RenderContext.js +219 -4
- package/src/renderers/common/RenderContexts.js +54 -17
- package/src/renderers/common/RenderList.js +233 -24
- package/src/renderers/common/RenderLists.js +46 -6
- package/src/renderers/common/RenderObject.js +548 -46
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +133 -15
- package/src/renderers/common/RenderPipeline.js +216 -6
- package/src/renderers/common/Renderer.js +2155 -332
- package/src/renderers/common/RendererUtils.js +200 -0
- package/src/renderers/common/SampledTexture.js +99 -39
- package/src/renderers/common/Sampler.js +148 -1
- package/src/renderers/common/Storage3DTexture.js +100 -0
- package/src/renderers/common/StorageArrayTexture.js +84 -0
- package/src/renderers/common/StorageBuffer.js +38 -2
- package/src/renderers/common/StorageBufferAttribute.js +31 -2
- package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
- package/src/renderers/common/StorageTexture.js +65 -0
- package/src/renderers/common/Textures.js +273 -57
- package/src/renderers/common/TimestampQueryPool.js +163 -0
- package/src/renderers/common/Uniform.js +233 -3
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +235 -26
- package/src/renderers/common/XRManager.js +1677 -0
- package/src/renderers/common/XRRenderTarget.js +91 -0
- package/src/renderers/common/extras/PMREMGenerator.js +371 -108
- package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
- package/src/renderers/common/nodes/NodeLibrary.js +95 -17
- package/src/renderers/common/nodes/NodeManager.js +852 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +84 -8
- package/src/renderers/common/nodes/NodeSampler.js +41 -1
- package/src/renderers/common/nodes/NodeStorageBuffer.js +48 -3
- package/src/renderers/common/nodes/NodeUniform.js +285 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +81 -0
- package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
- package/src/renderers/shaders/DFGLUTData.js +49 -0
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -12
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +154 -59
- 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/map_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +230 -181
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk.js +3 -3
- package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +14 -2
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +7 -5
- package/src/renderers/shaders/UniformsLib.js +2 -7
- package/src/renderers/shaders/UniformsUtils.js +21 -2
- package/src/renderers/webgl/WebGLAttributes.js +4 -0
- package/src/renderers/webgl/WebGLBackground.js +30 -5
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +7 -14
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLExtensions.js +2 -25
- package/src/renderers/webgl/WebGLGeometries.js +10 -35
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLInfo.js +3 -1
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLMaterials.js +12 -0
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLOutput.js +267 -0
- package/src/renderers/webgl/WebGLProgram.js +87 -148
- package/src/renderers/webgl/WebGLPrograms.js +53 -51
- package/src/renderers/webgl/WebGLRenderLists.js +15 -0
- package/src/renderers/webgl/WebGLShadowMap.js +204 -28
- package/src/renderers/webgl/WebGLState.js +88 -56
- package/src/renderers/webgl/WebGLTextures.js +293 -59
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUniformsGroups.js +5 -3
- package/src/renderers/webgl/WebGLUtils.js +7 -5
- package/src/renderers/webgl-fallback/WebGLBackend.js +1416 -293
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +785 -92
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +62 -1
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLConstants.js +3 -3
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +584 -20
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +468 -80
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +72 -24
- package/src/renderers/webgpu/WebGPUBackend.js +1517 -428
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +31 -4
- package/src/renderers/webgpu/WebGPURenderer.js +55 -4
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +23 -16
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +37 -42
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +1335 -241
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +32 -4
- package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +144 -20
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +460 -116
- package/src/renderers/webgpu/utils/WebGPUConstants.js +17 -4
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +283 -69
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +225 -178
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +583 -191
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +150 -28
- package/src/renderers/webxr/WebXRController.js +87 -2
- package/src/renderers/webxr/WebXRDepthSensing.js +52 -7
- package/src/renderers/webxr/WebXRManager.js +275 -15
- package/src/scenes/Fog.js +60 -0
- package/src/scenes/FogExp2.js +51 -0
- package/src/scenes/Scene.js +88 -0
- package/src/textures/CanvasTexture.js +28 -0
- package/src/textures/CompressedArrayTexture.js +57 -0
- package/src/textures/CompressedCubeTexture.js +29 -0
- package/src/textures/CompressedTexture.js +64 -6
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/CubeTexture.js +52 -4
- package/src/textures/Data3DTexture.js +79 -2
- package/src/textures/DataArrayTexture.js +93 -0
- package/src/textures/DataTexture.js +65 -0
- package/src/textures/DepthTexture.js +59 -11
- package/src/textures/ExternalTexture.js +56 -0
- package/src/textures/FramebufferTexture.js +62 -0
- package/src/textures/Source.js +106 -4
- package/src/textures/Texture.js +488 -6
- package/src/textures/VideoFrameTexture.js +72 -0
- package/src/textures/VideoTexture.js +78 -6
- package/src/utils.js +322 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
- package/examples/jsm/animation/MMDPhysics.js +0 -1406
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
- package/examples/jsm/exporters/MMDExporter.js +0 -217
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
- package/examples/jsm/geometries/ParametricGeometries.js +0 -254
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +0 -729
- package/examples/jsm/loaders/MMDLoader.js +0 -2295
- package/examples/jsm/loaders/RGBMLoader.js +0 -1081
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -432
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -144
- package/examples/jsm/misc/Timer.js +0 -128
- package/examples/jsm/objects/InstancedPoints.js +0 -21
- package/examples/jsm/shaders/GodRaysShader.js +0 -321
- package/examples/jsm/shaders/MMDToonShader.js +0 -134
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
- package/src/nodes/accessors/SceneNode.js +0 -55
- package/src/nodes/code/ScriptableNode.js +0 -505
- package/src/nodes/code/ScriptableValueNode.js +0 -170
- package/src/nodes/core/CacheNode.js +0 -50
- package/src/nodes/core/UniformGroup.js +0 -13
- package/src/nodes/display/AfterImageNode.js +0 -158
- package/src/nodes/display/AnaglyphPassNode.js +0 -67
- package/src/nodes/display/AnamorphicNode.js +0 -151
- package/src/nodes/display/BlendMode.js +0 -54
- package/src/nodes/display/BloomNode.js +0 -341
- package/src/nodes/display/DenoiseNode.js +0 -204
- package/src/nodes/display/DepthOfFieldNode.js +0 -124
- package/src/nodes/display/DotScreenNode.js +0 -66
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/display/FilmNode.js +0 -56
- package/src/nodes/display/GTAONode.js +0 -331
- package/src/nodes/display/GaussianBlurNode.js +0 -213
- package/src/nodes/display/Lut3DNode.js +0 -57
- package/src/nodes/display/MotionBlur.js +0 -25
- package/src/nodes/display/ParallaxBarrierPassNode.js +0 -58
- package/src/nodes/display/PixelationPassNode.js +0 -213
- package/src/nodes/display/PosterizeNode.js +0 -33
- package/src/nodes/display/RGBShiftNode.js +0 -53
- package/src/nodes/display/StereoCompositePassNode.js +0 -110
- package/src/nodes/display/TransitionNode.js +0 -80
- package/src/nodes/fog/FogExp2Node.js +0 -35
- package/src/nodes/fog/FogNode.js +0 -50
- package/src/nodes/fog/FogRangeNode.js +0 -36
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -30
- package/src/nodes/utils/EquirectUVNode.js +0 -36
- package/src/nodes/utils/MatcapUVNode.js +0 -33
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/SpriteSheetUVNode.js +0 -45
- package/src/nodes/utils/TimerNode.js +0 -97
- package/src/nodes/utils/TriplanarTexturesNode.js +0 -64
- package/src/renderers/common/nodes/Nodes.js +0 -534
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -136
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js';
|
|
3
3
|
//*/
|
|
4
4
|
|
|
5
|
-
import { GPUFeatureName, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
|
|
5
|
+
import { GPUFeatureName, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension, GPUFeatureMap } from './utils/WebGPUConstants.js';
|
|
6
6
|
|
|
7
7
|
import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
|
|
8
8
|
import Backend from '../common/Backend.js';
|
|
@@ -13,16 +13,53 @@ import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
|
|
|
13
13
|
import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
|
|
14
14
|
import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
|
|
15
15
|
|
|
16
|
-
import { WebGPUCoordinateSystem } from '../../constants.js';
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
import { WebGPUCoordinateSystem, TimestampQuery, REVISION, HalfFloatType, Compatibility } from '../../constants.js';
|
|
17
|
+
import WebGPUTimestampQueryPool from './utils/WebGPUTimestampQueryPool.js';
|
|
18
|
+
import { warnOnce, error } from '../../utils.js';
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* A backend implementation targeting WebGPU.
|
|
22
|
+
*
|
|
23
|
+
* @private
|
|
24
|
+
* @augments Backend
|
|
25
|
+
*/
|
|
20
26
|
class WebGPUBackend extends Backend {
|
|
21
27
|
|
|
28
|
+
/**
|
|
29
|
+
* WebGPUBackend options.
|
|
30
|
+
*
|
|
31
|
+
* @typedef {Object} WebGPUBackend~Options
|
|
32
|
+
* @property {boolean} [logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
|
|
33
|
+
* @property {boolean} [reversedDepthBuffer=false] - Whether reversed depth buffer is enabled or not.
|
|
34
|
+
* @property {boolean} [alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
|
|
35
|
+
* @property {boolean} [depth=true] - Whether the default framebuffer should have a depth buffer or not.
|
|
36
|
+
* @property {boolean} [stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
|
|
37
|
+
* @property {boolean} [antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
|
|
38
|
+
* @property {number} [samples=0] - When `antialias` is `true`, `4` samples are used by default. Set this parameter to any other integer value than 0 to overwrite the default.
|
|
39
|
+
* @property {boolean} [forceWebGL=false] - If set to `true`, the renderer uses a WebGL 2 backend no matter if WebGPU is supported or not.
|
|
40
|
+
* @property {boolean} [trackTimestamp=false] - Whether to track timestamps with a Timestamp Query API or not.
|
|
41
|
+
* @property {string} [powerPreference=undefined] - The power preference.
|
|
42
|
+
* @property {Object} [requiredLimits=undefined] - Specifies the limits that are required by the device request. The request will fail if the adapter cannot provide these limits.
|
|
43
|
+
* @property {GPUDevice} [device=undefined] - If there is an existing GPU device on app level, it can be passed to the renderer as a parameter.
|
|
44
|
+
* @property {number} [outputType=undefined] - Texture type for output to canvas. By default, device's preferred format is used; other formats may incur overhead.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Constructs a new WebGPU backend.
|
|
49
|
+
*
|
|
50
|
+
* @param {WebGPUBackend~Options} [parameters] - The configuration parameter.
|
|
51
|
+
*/
|
|
22
52
|
constructor( parameters = {} ) {
|
|
23
53
|
|
|
24
54
|
super( parameters );
|
|
25
55
|
|
|
56
|
+
/**
|
|
57
|
+
* This flag can be used for type testing.
|
|
58
|
+
*
|
|
59
|
+
* @type {boolean}
|
|
60
|
+
* @readonly
|
|
61
|
+
* @default true
|
|
62
|
+
*/
|
|
26
63
|
this.isWebGPUBackend = true;
|
|
27
64
|
|
|
28
65
|
// some parameters require default values other than "undefined"
|
|
@@ -30,22 +67,100 @@ class WebGPUBackend extends Backend {
|
|
|
30
67
|
|
|
31
68
|
this.parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits;
|
|
32
69
|
|
|
33
|
-
|
|
34
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Indicates whether the backend is in WebGPU compatibility mode or not.
|
|
72
|
+
* The backend must be initialized before the property can be evaluated.
|
|
73
|
+
*
|
|
74
|
+
* @type {?boolean}
|
|
75
|
+
* @readonly
|
|
76
|
+
* @default null
|
|
77
|
+
*/
|
|
78
|
+
this.compatibilityMode = null;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A reference to the device.
|
|
82
|
+
*
|
|
83
|
+
* @type {?GPUDevice}
|
|
84
|
+
* @default null
|
|
85
|
+
*/
|
|
35
86
|
this.device = null;
|
|
36
|
-
|
|
37
|
-
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A reference to the default render pass descriptor.
|
|
90
|
+
*
|
|
91
|
+
* @type {?Object}
|
|
92
|
+
* @default null
|
|
93
|
+
*/
|
|
38
94
|
this.defaultRenderPassdescriptor = null;
|
|
39
95
|
|
|
96
|
+
/**
|
|
97
|
+
* A reference to a backend module holding common utility functions.
|
|
98
|
+
*
|
|
99
|
+
* @type {WebGPUUtils}
|
|
100
|
+
*/
|
|
40
101
|
this.utils = new WebGPUUtils( this );
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A reference to a backend module holding shader attribute-related
|
|
105
|
+
* utility functions.
|
|
106
|
+
*
|
|
107
|
+
* @type {WebGPUAttributeUtils}
|
|
108
|
+
*/
|
|
41
109
|
this.attributeUtils = new WebGPUAttributeUtils( this );
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A reference to a backend module holding shader binding-related
|
|
113
|
+
* utility functions.
|
|
114
|
+
*
|
|
115
|
+
* @type {WebGPUBindingUtils}
|
|
116
|
+
*/
|
|
42
117
|
this.bindingUtils = new WebGPUBindingUtils( this );
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A reference to a backend module holding shader pipeline-related
|
|
121
|
+
* utility functions.
|
|
122
|
+
*
|
|
123
|
+
* @type {WebGPUPipelineUtils}
|
|
124
|
+
*/
|
|
43
125
|
this.pipelineUtils = new WebGPUPipelineUtils( this );
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A reference to a backend module holding shader texture-related
|
|
129
|
+
* utility functions.
|
|
130
|
+
*
|
|
131
|
+
* @type {WebGPUTextureUtils}
|
|
132
|
+
*/
|
|
44
133
|
this.textureUtils = new WebGPUTextureUtils( this );
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A map that manages the resolve buffers for occlusion queries.
|
|
137
|
+
*
|
|
138
|
+
* @type {Map<number,GPUBuffer>}
|
|
139
|
+
*/
|
|
45
140
|
this.occludedResolveCache = new Map();
|
|
46
141
|
|
|
142
|
+
// compatibility checks
|
|
143
|
+
|
|
144
|
+
const compatibilityTextureCompare = typeof navigator === 'undefined' ? true : /Android/.test( navigator.userAgent ) === false;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A map of compatibility checks.
|
|
148
|
+
*
|
|
149
|
+
* @type {Object}
|
|
150
|
+
*/
|
|
151
|
+
this._compatibility = {
|
|
152
|
+
[ Compatibility.TEXTURE_COMPARE ]: compatibilityTextureCompare
|
|
153
|
+
};
|
|
154
|
+
|
|
47
155
|
}
|
|
48
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Initializes the backend so it is ready for usage.
|
|
159
|
+
*
|
|
160
|
+
* @async
|
|
161
|
+
* @param {Renderer} renderer - The renderer.
|
|
162
|
+
* @return {Promise} A Promise that resolves when the backend has been initialized.
|
|
163
|
+
*/
|
|
49
164
|
async init( renderer ) {
|
|
50
165
|
|
|
51
166
|
await super.init( renderer );
|
|
@@ -61,10 +176,11 @@ class WebGPUBackend extends Backend {
|
|
|
61
176
|
if ( parameters.device === undefined ) {
|
|
62
177
|
|
|
63
178
|
const adapterOptions = {
|
|
64
|
-
powerPreference: parameters.powerPreference
|
|
179
|
+
powerPreference: parameters.powerPreference,
|
|
180
|
+
featureLevel: 'compatibility'
|
|
65
181
|
};
|
|
66
182
|
|
|
67
|
-
const adapter = await navigator.gpu.requestAdapter( adapterOptions );
|
|
183
|
+
const adapter = ( typeof navigator !== 'undefined' ) ? await navigator.gpu.requestAdapter( adapterOptions ) : null;
|
|
68
184
|
|
|
69
185
|
if ( adapter === null ) {
|
|
70
186
|
|
|
@@ -101,66 +217,166 @@ class WebGPUBackend extends Backend {
|
|
|
101
217
|
|
|
102
218
|
}
|
|
103
219
|
|
|
104
|
-
|
|
220
|
+
this.compatibilityMode = ! device.features.has( 'core-features-and-limits' );
|
|
105
221
|
|
|
106
|
-
this.
|
|
107
|
-
this.context = context;
|
|
222
|
+
if ( this.compatibilityMode ) {
|
|
108
223
|
|
|
109
|
-
|
|
224
|
+
renderer._samples = 0;
|
|
110
225
|
|
|
111
|
-
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
device.lost.then( ( info ) => {
|
|
229
|
+
|
|
230
|
+
if ( info.reason === 'destroyed' ) return;
|
|
231
|
+
|
|
232
|
+
const deviceLossInfo = {
|
|
233
|
+
api: 'WebGPU',
|
|
234
|
+
message: info.message || 'Unknown reason',
|
|
235
|
+
reason: info.reason || null,
|
|
236
|
+
originalEvent: info
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
renderer.onDeviceLost( deviceLossInfo );
|
|
112
240
|
|
|
113
|
-
this.context.configure( {
|
|
114
|
-
device: this.device,
|
|
115
|
-
format: this.utils.getPreferredCanvasFormat(),
|
|
116
|
-
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
|
|
117
|
-
alphaMode: alphaMode
|
|
118
241
|
} );
|
|
119
242
|
|
|
243
|
+
this.device = device;
|
|
244
|
+
|
|
245
|
+
this.trackTimestamp = this.trackTimestamp && this.hasFeature( GPUFeatureName.TimestampQuery );
|
|
246
|
+
|
|
120
247
|
this.updateSize();
|
|
121
248
|
|
|
122
249
|
}
|
|
123
250
|
|
|
251
|
+
/**
|
|
252
|
+
* A reference to the context.
|
|
253
|
+
*
|
|
254
|
+
* @type {?GPUCanvasContext}
|
|
255
|
+
* @default null
|
|
256
|
+
*/
|
|
257
|
+
get context() {
|
|
258
|
+
|
|
259
|
+
const canvasTarget = this.renderer.getCanvasTarget();
|
|
260
|
+
const canvasData = this.get( canvasTarget );
|
|
261
|
+
|
|
262
|
+
let context = canvasData.context;
|
|
263
|
+
|
|
264
|
+
if ( context === undefined ) {
|
|
265
|
+
|
|
266
|
+
const parameters = this.parameters;
|
|
267
|
+
|
|
268
|
+
if ( canvasTarget.isDefaultCanvasTarget === true && parameters.context !== undefined ) {
|
|
269
|
+
|
|
270
|
+
context = parameters.context;
|
|
271
|
+
|
|
272
|
+
} else {
|
|
273
|
+
|
|
274
|
+
context = canvasTarget.domElement.getContext( 'webgpu' );
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// OffscreenCanvas does not have setAttribute, see #22811
|
|
279
|
+
if ( 'setAttribute' in canvasTarget.domElement ) canvasTarget.domElement.setAttribute( 'data-engine', `three.js r${ REVISION } webgpu` );
|
|
280
|
+
|
|
281
|
+
const alphaMode = parameters.alpha ? 'premultiplied' : 'opaque';
|
|
282
|
+
|
|
283
|
+
const toneMappingMode = parameters.outputType === HalfFloatType ? 'extended' : 'standard';
|
|
284
|
+
|
|
285
|
+
context.configure( {
|
|
286
|
+
device: this.device,
|
|
287
|
+
format: this.utils.getPreferredCanvasFormat(),
|
|
288
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
|
|
289
|
+
alphaMode: alphaMode,
|
|
290
|
+
toneMapping: {
|
|
291
|
+
mode: toneMappingMode
|
|
292
|
+
}
|
|
293
|
+
} );
|
|
294
|
+
|
|
295
|
+
canvasData.context = context;
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return context;
|
|
300
|
+
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* The coordinate system of the backend.
|
|
305
|
+
*
|
|
306
|
+
* @type {number}
|
|
307
|
+
* @readonly
|
|
308
|
+
*/
|
|
124
309
|
get coordinateSystem() {
|
|
125
310
|
|
|
126
311
|
return WebGPUCoordinateSystem;
|
|
127
312
|
|
|
128
313
|
}
|
|
129
314
|
|
|
315
|
+
/**
|
|
316
|
+
* This method performs a readback operation by moving buffer data from
|
|
317
|
+
* a storage buffer attribute from the GPU to the CPU.
|
|
318
|
+
*
|
|
319
|
+
* @async
|
|
320
|
+
* @param {StorageBufferAttribute} attribute - The storage buffer attribute.
|
|
321
|
+
* @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
|
|
322
|
+
*/
|
|
130
323
|
async getArrayBufferAsync( attribute ) {
|
|
131
324
|
|
|
132
325
|
return await this.attributeUtils.getArrayBufferAsync( attribute );
|
|
133
326
|
|
|
134
327
|
}
|
|
135
328
|
|
|
329
|
+
/**
|
|
330
|
+
* Returns the backend's rendering context.
|
|
331
|
+
*
|
|
332
|
+
* @return {GPUCanvasContext} The rendering context.
|
|
333
|
+
*/
|
|
136
334
|
getContext() {
|
|
137
335
|
|
|
138
336
|
return this.context;
|
|
139
337
|
|
|
140
338
|
}
|
|
141
339
|
|
|
340
|
+
/**
|
|
341
|
+
* Returns the default render pass descriptor.
|
|
342
|
+
*
|
|
343
|
+
* In WebGPU, the default framebuffer must be configured
|
|
344
|
+
* like custom framebuffers so the backend needs a render
|
|
345
|
+
* pass descriptor even when rendering directly to screen.
|
|
346
|
+
*
|
|
347
|
+
* @private
|
|
348
|
+
* @return {Object} The render pass descriptor.
|
|
349
|
+
*/
|
|
142
350
|
_getDefaultRenderPassDescriptor() {
|
|
143
351
|
|
|
144
|
-
|
|
352
|
+
const renderer = this.renderer;
|
|
353
|
+
const canvasTarget = renderer.getCanvasTarget();
|
|
354
|
+
const canvasData = this.get( canvasTarget );
|
|
355
|
+
const samples = renderer.currentSamples;
|
|
145
356
|
|
|
146
|
-
|
|
357
|
+
let descriptor = canvasData.descriptor;
|
|
147
358
|
|
|
148
|
-
|
|
359
|
+
if ( descriptor === undefined || canvasData.samples !== samples ) {
|
|
149
360
|
|
|
150
361
|
descriptor = {
|
|
151
362
|
colorAttachments: [ {
|
|
152
363
|
view: null
|
|
153
|
-
} ]
|
|
154
|
-
depthStencilAttachment: {
|
|
155
|
-
view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
|
|
156
|
-
}
|
|
364
|
+
} ]
|
|
157
365
|
};
|
|
158
366
|
|
|
367
|
+
if ( renderer.depth === true || renderer.stencil === true ) {
|
|
368
|
+
|
|
369
|
+
descriptor.depthStencilAttachment = {
|
|
370
|
+
view: this.textureUtils.getDepthBuffer( renderer.depth, renderer.stencil ).createView()
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
}
|
|
374
|
+
|
|
159
375
|
const colorAttachment = descriptor.colorAttachments[ 0 ];
|
|
160
376
|
|
|
161
|
-
if (
|
|
377
|
+
if ( samples > 0 ) {
|
|
162
378
|
|
|
163
|
-
colorAttachment.view = this.
|
|
379
|
+
colorAttachment.view = this.textureUtils.getColorBuffer().createView();
|
|
164
380
|
|
|
165
381
|
} else {
|
|
166
382
|
|
|
@@ -168,13 +384,14 @@ class WebGPUBackend extends Backend {
|
|
|
168
384
|
|
|
169
385
|
}
|
|
170
386
|
|
|
171
|
-
|
|
387
|
+
canvasData.descriptor = descriptor;
|
|
388
|
+
canvasData.samples = samples;
|
|
172
389
|
|
|
173
390
|
}
|
|
174
391
|
|
|
175
392
|
const colorAttachment = descriptor.colorAttachments[ 0 ];
|
|
176
393
|
|
|
177
|
-
if (
|
|
394
|
+
if ( samples > 0 ) {
|
|
178
395
|
|
|
179
396
|
colorAttachment.resolveTarget = this.context.getCurrentTexture().createView();
|
|
180
397
|
|
|
@@ -188,7 +405,29 @@ class WebGPUBackend extends Backend {
|
|
|
188
405
|
|
|
189
406
|
}
|
|
190
407
|
|
|
191
|
-
|
|
408
|
+
/**
|
|
409
|
+
* Internal to determine if the current render target is a render target array with depth 2D array texture.
|
|
410
|
+
*
|
|
411
|
+
* @param {RenderContext} renderContext - The render context.
|
|
412
|
+
* @return {boolean} Whether the render target is a render target array with depth 2D array texture.
|
|
413
|
+
*
|
|
414
|
+
* @private
|
|
415
|
+
*/
|
|
416
|
+
_isRenderCameraDepthArray( renderContext ) {
|
|
417
|
+
|
|
418
|
+
return renderContext.depthTexture && renderContext.depthTexture.image.depth > 1 && renderContext.camera.isArrayCamera;
|
|
419
|
+
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Returns the render pass descriptor for the given render context.
|
|
424
|
+
*
|
|
425
|
+
* @private
|
|
426
|
+
* @param {RenderContext} renderContext - The render context.
|
|
427
|
+
* @param {Object} colorAttachmentsConfig - Configuration object for the color attachments.
|
|
428
|
+
* @return {Object} The render pass descriptor.
|
|
429
|
+
*/
|
|
430
|
+
_getRenderPassDescriptor( renderContext, colorAttachmentsConfig = {} ) {
|
|
192
431
|
|
|
193
432
|
const renderTarget = renderContext.renderTarget;
|
|
194
433
|
const renderTargetData = this.get( renderTarget );
|
|
@@ -198,7 +437,6 @@ class WebGPUBackend extends Backend {
|
|
|
198
437
|
if ( descriptors === undefined ||
|
|
199
438
|
renderTargetData.width !== renderTarget.width ||
|
|
200
439
|
renderTargetData.height !== renderTarget.height ||
|
|
201
|
-
renderTargetData.activeMipmapLevel !== renderTarget.activeMipmapLevel ||
|
|
202
440
|
renderTargetData.samples !== renderTarget.samples
|
|
203
441
|
) {
|
|
204
442
|
|
|
@@ -206,80 +444,160 @@ class WebGPUBackend extends Backend {
|
|
|
206
444
|
|
|
207
445
|
renderTargetData.descriptors = descriptors;
|
|
208
446
|
|
|
209
|
-
// dispose
|
|
210
|
-
|
|
211
|
-
const onDispose = () => {
|
|
212
|
-
|
|
213
|
-
renderTarget.removeEventListener( 'dispose', onDispose );
|
|
214
|
-
|
|
215
|
-
this.delete( renderTarget );
|
|
216
|
-
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
renderTarget.addEventListener( 'dispose', onDispose );
|
|
220
|
-
|
|
221
447
|
}
|
|
222
448
|
|
|
223
449
|
const cacheKey = renderContext.getCacheKey();
|
|
450
|
+
let descriptorBase = descriptors[ cacheKey ];
|
|
224
451
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if ( descriptor === undefined ) {
|
|
452
|
+
if ( descriptorBase === undefined ) {
|
|
228
453
|
|
|
229
454
|
const textures = renderContext.textures;
|
|
230
|
-
const
|
|
455
|
+
const textureViews = [];
|
|
456
|
+
|
|
457
|
+
let sliceIndex;
|
|
458
|
+
|
|
459
|
+
const isRenderCameraDepthArray = this._isRenderCameraDepthArray( renderContext );
|
|
231
460
|
|
|
232
461
|
for ( let i = 0; i < textures.length; i ++ ) {
|
|
233
462
|
|
|
234
463
|
const textureData = this.get( textures[ i ] );
|
|
235
464
|
|
|
236
|
-
const
|
|
465
|
+
const viewDescriptor = {
|
|
466
|
+
label: `colorAttachment_${ i }`,
|
|
237
467
|
baseMipLevel: renderContext.activeMipmapLevel,
|
|
238
468
|
mipLevelCount: 1,
|
|
239
469
|
baseArrayLayer: renderContext.activeCubeFace,
|
|
470
|
+
arrayLayerCount: 1,
|
|
240
471
|
dimension: GPUTextureViewDimension.TwoD
|
|
241
|
-
}
|
|
472
|
+
};
|
|
242
473
|
|
|
243
|
-
|
|
474
|
+
if ( renderTarget.isRenderTarget3D ) {
|
|
244
475
|
|
|
245
|
-
|
|
476
|
+
sliceIndex = renderContext.activeCubeFace;
|
|
246
477
|
|
|
247
|
-
|
|
248
|
-
|
|
478
|
+
viewDescriptor.baseArrayLayer = 0;
|
|
479
|
+
viewDescriptor.dimension = GPUTextureViewDimension.ThreeD;
|
|
480
|
+
viewDescriptor.depthOrArrayLayers = textures[ i ].image.depth;
|
|
249
481
|
|
|
250
|
-
} else {
|
|
482
|
+
} else if ( renderTarget.isRenderTarget && textures[ i ].image.depth > 1 ) {
|
|
483
|
+
|
|
484
|
+
if ( isRenderCameraDepthArray === true ) {
|
|
485
|
+
|
|
486
|
+
const cameras = renderContext.camera.cameras;
|
|
487
|
+
for ( let layer = 0; layer < cameras.length; layer ++ ) {
|
|
488
|
+
|
|
489
|
+
const layerViewDescriptor = {
|
|
490
|
+
...viewDescriptor,
|
|
491
|
+
baseArrayLayer: layer,
|
|
492
|
+
arrayLayerCount: 1,
|
|
493
|
+
dimension: GPUTextureViewDimension.TwoD
|
|
494
|
+
};
|
|
495
|
+
const textureView = textureData.texture.createView( layerViewDescriptor );
|
|
496
|
+
textureViews.push( {
|
|
497
|
+
view: textureView,
|
|
498
|
+
resolveTarget: undefined,
|
|
499
|
+
depthSlice: undefined
|
|
500
|
+
} );
|
|
251
501
|
|
|
252
|
-
|
|
253
|
-
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
} else {
|
|
505
|
+
|
|
506
|
+
viewDescriptor.dimension = GPUTextureViewDimension.TwoDArray;
|
|
507
|
+
viewDescriptor.depthOrArrayLayers = textures[ i ].image.depth;
|
|
508
|
+
|
|
509
|
+
}
|
|
254
510
|
|
|
255
511
|
}
|
|
256
512
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
513
|
+
if ( isRenderCameraDepthArray !== true ) {
|
|
514
|
+
|
|
515
|
+
const textureView = textureData.texture.createView( viewDescriptor );
|
|
516
|
+
|
|
517
|
+
let view, resolveTarget;
|
|
518
|
+
|
|
519
|
+
if ( textureData.msaaTexture !== undefined ) {
|
|
520
|
+
|
|
521
|
+
view = textureData.msaaTexture.createView();
|
|
522
|
+
resolveTarget = textureView;
|
|
523
|
+
|
|
524
|
+
} else {
|
|
525
|
+
|
|
526
|
+
view = textureView;
|
|
527
|
+
resolveTarget = undefined;
|
|
528
|
+
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
textureViews.push( {
|
|
532
|
+
view,
|
|
533
|
+
resolveTarget,
|
|
534
|
+
depthSlice: sliceIndex
|
|
535
|
+
} );
|
|
536
|
+
|
|
537
|
+
}
|
|
263
538
|
|
|
264
539
|
}
|
|
265
540
|
|
|
266
|
-
|
|
541
|
+
descriptorBase = { textureViews };
|
|
267
542
|
|
|
268
|
-
|
|
269
|
-
view: depthTextureData.texture.createView()
|
|
270
|
-
};
|
|
543
|
+
if ( renderContext.depth ) {
|
|
271
544
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
545
|
+
const depthTextureData = this.get( renderContext.depthTexture );
|
|
546
|
+
const options = {};
|
|
547
|
+
if ( renderContext.depthTexture.isArrayTexture || renderContext.depthTexture.isCubeTexture ) {
|
|
548
|
+
|
|
549
|
+
options.dimension = GPUTextureViewDimension.TwoD;
|
|
550
|
+
options.arrayLayerCount = 1;
|
|
551
|
+
options.baseArrayLayer = renderContext.activeCubeFace;
|
|
552
|
+
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
descriptorBase.depthStencilView = depthTextureData.texture.createView( options );
|
|
276
556
|
|
|
277
|
-
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
descriptors[ cacheKey ] = descriptorBase;
|
|
278
560
|
|
|
279
561
|
renderTargetData.width = renderTarget.width;
|
|
280
562
|
renderTargetData.height = renderTarget.height;
|
|
281
563
|
renderTargetData.samples = renderTarget.samples;
|
|
282
|
-
renderTargetData.activeMipmapLevel =
|
|
564
|
+
renderTargetData.activeMipmapLevel = renderContext.activeMipmapLevel;
|
|
565
|
+
renderTargetData.activeCubeFace = renderContext.activeCubeFace;
|
|
566
|
+
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const descriptor = {
|
|
570
|
+
colorAttachments: []
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
// Apply dynamic properties to cached views
|
|
574
|
+
for ( let i = 0; i < descriptorBase.textureViews.length; i ++ ) {
|
|
575
|
+
|
|
576
|
+
const viewInfo = descriptorBase.textureViews[ i ];
|
|
577
|
+
|
|
578
|
+
let clearValue = { r: 0, g: 0, b: 0, a: 1 };
|
|
579
|
+
if ( i === 0 && colorAttachmentsConfig.clearValue ) {
|
|
580
|
+
|
|
581
|
+
clearValue = colorAttachmentsConfig.clearValue;
|
|
582
|
+
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
descriptor.colorAttachments.push( {
|
|
586
|
+
view: viewInfo.view,
|
|
587
|
+
depthSlice: viewInfo.depthSlice,
|
|
588
|
+
resolveTarget: viewInfo.resolveTarget,
|
|
589
|
+
loadOp: colorAttachmentsConfig.loadOp || GPULoadOp.Load,
|
|
590
|
+
storeOp: colorAttachmentsConfig.storeOp || GPUStoreOp.Store,
|
|
591
|
+
clearValue: clearValue
|
|
592
|
+
} );
|
|
593
|
+
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
if ( descriptorBase.depthStencilView ) {
|
|
597
|
+
|
|
598
|
+
descriptor.depthStencilAttachment = {
|
|
599
|
+
view: descriptorBase.depthStencilView
|
|
600
|
+
};
|
|
283
601
|
|
|
284
602
|
}
|
|
285
603
|
|
|
@@ -287,10 +605,18 @@ class WebGPUBackend extends Backend {
|
|
|
287
605
|
|
|
288
606
|
}
|
|
289
607
|
|
|
608
|
+
/**
|
|
609
|
+
* This method is executed at the beginning of a render call and prepares
|
|
610
|
+
* the WebGPU state for upcoming render calls
|
|
611
|
+
*
|
|
612
|
+
* @param {RenderContext} renderContext - The render context.
|
|
613
|
+
*/
|
|
290
614
|
beginRender( renderContext ) {
|
|
291
615
|
|
|
292
616
|
const renderContextData = this.get( renderContext );
|
|
293
617
|
|
|
618
|
+
//
|
|
619
|
+
|
|
294
620
|
const device = this.device;
|
|
295
621
|
const occlusionQueryCount = renderContext.occlusionQueryCount;
|
|
296
622
|
|
|
@@ -309,7 +635,7 @@ class WebGPUBackend extends Backend {
|
|
|
309
635
|
|
|
310
636
|
//
|
|
311
637
|
|
|
312
|
-
occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount } );
|
|
638
|
+
occlusionQuerySet = device.createQuerySet( { type: 'occlusion', count: occlusionQueryCount, label: `occlusionQuerySet_${ renderContext.id }` } );
|
|
313
639
|
|
|
314
640
|
renderContextData.occlusionQuerySet = occlusionQuerySet;
|
|
315
641
|
renderContextData.occlusionQueryIndex = 0;
|
|
@@ -327,11 +653,11 @@ class WebGPUBackend extends Backend {
|
|
|
327
653
|
|
|
328
654
|
} else {
|
|
329
655
|
|
|
330
|
-
descriptor = this._getRenderPassDescriptor( renderContext );
|
|
656
|
+
descriptor = this._getRenderPassDescriptor( renderContext, { loadOp: GPULoadOp.Load } );
|
|
331
657
|
|
|
332
658
|
}
|
|
333
659
|
|
|
334
|
-
this.initTimestampQuery( renderContext, descriptor );
|
|
660
|
+
this.initTimestampQuery( TimestampQuery.RENDER, this.getTimestampUID( renderContext ), descriptor );
|
|
335
661
|
|
|
336
662
|
descriptor.occlusionQuerySet = occlusionQuerySet;
|
|
337
663
|
|
|
@@ -349,15 +675,15 @@ class WebGPUBackend extends Backend {
|
|
|
349
675
|
|
|
350
676
|
colorAttachment.clearValue = i === 0 ? renderContext.clearColorValue : { r: 0, g: 0, b: 0, a: 1 };
|
|
351
677
|
colorAttachment.loadOp = GPULoadOp.Clear;
|
|
352
|
-
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
353
678
|
|
|
354
679
|
} else {
|
|
355
680
|
|
|
356
681
|
colorAttachment.loadOp = GPULoadOp.Load;
|
|
357
|
-
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
358
682
|
|
|
359
683
|
}
|
|
360
684
|
|
|
685
|
+
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
686
|
+
|
|
361
687
|
}
|
|
362
688
|
|
|
363
689
|
} else {
|
|
@@ -368,15 +694,15 @@ class WebGPUBackend extends Backend {
|
|
|
368
694
|
|
|
369
695
|
colorAttachment.clearValue = renderContext.clearColorValue;
|
|
370
696
|
colorAttachment.loadOp = GPULoadOp.Clear;
|
|
371
|
-
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
372
697
|
|
|
373
698
|
} else {
|
|
374
699
|
|
|
375
700
|
colorAttachment.loadOp = GPULoadOp.Load;
|
|
376
|
-
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
377
701
|
|
|
378
702
|
}
|
|
379
703
|
|
|
704
|
+
colorAttachment.storeOp = GPUStoreOp.Store;
|
|
705
|
+
|
|
380
706
|
}
|
|
381
707
|
|
|
382
708
|
//
|
|
@@ -387,65 +713,245 @@ class WebGPUBackend extends Backend {
|
|
|
387
713
|
|
|
388
714
|
depthStencilAttachment.depthClearValue = renderContext.clearDepthValue;
|
|
389
715
|
depthStencilAttachment.depthLoadOp = GPULoadOp.Clear;
|
|
390
|
-
depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
|
|
391
716
|
|
|
392
717
|
} else {
|
|
393
718
|
|
|
394
719
|
depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
|
|
395
|
-
depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
|
|
396
720
|
|
|
397
721
|
}
|
|
398
722
|
|
|
723
|
+
depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
|
|
724
|
+
|
|
399
725
|
}
|
|
400
726
|
|
|
401
727
|
if ( renderContext.stencil ) {
|
|
402
728
|
|
|
403
|
-
|
|
729
|
+
if ( renderContext.clearStencil ) {
|
|
404
730
|
|
|
405
731
|
depthStencilAttachment.stencilClearValue = renderContext.clearStencilValue;
|
|
406
732
|
depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear;
|
|
407
|
-
depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
|
|
408
733
|
|
|
409
734
|
} else {
|
|
410
735
|
|
|
411
736
|
depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
412
|
-
depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
|
|
413
737
|
|
|
414
738
|
}
|
|
415
739
|
|
|
740
|
+
depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
|
|
741
|
+
|
|
416
742
|
}
|
|
417
743
|
|
|
418
744
|
//
|
|
419
745
|
|
|
420
746
|
const encoder = device.createCommandEncoder( { label: 'renderContext_' + renderContext.id } );
|
|
421
|
-
|
|
747
|
+
|
|
748
|
+
// shadow arrays - prepare bundle encoders for each camera in an array camera
|
|
749
|
+
|
|
750
|
+
if ( this._isRenderCameraDepthArray( renderContext ) === true ) {
|
|
751
|
+
|
|
752
|
+
const cameras = renderContext.camera.cameras;
|
|
753
|
+
|
|
754
|
+
if ( ! renderContextData.layerDescriptors || renderContextData.layerDescriptors.length !== cameras.length ) {
|
|
755
|
+
|
|
756
|
+
this._createDepthLayerDescriptors( renderContext, renderContextData, descriptor, cameras );
|
|
757
|
+
|
|
758
|
+
} else {
|
|
759
|
+
|
|
760
|
+
this._updateDepthLayerDescriptors( renderContext, renderContextData, cameras );
|
|
761
|
+
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// Create bundle encoders for each layer
|
|
765
|
+
renderContextData.bundleEncoders = [];
|
|
766
|
+
renderContextData.bundleSets = [];
|
|
767
|
+
|
|
768
|
+
// Create separate bundle encoders for each camera in the array
|
|
769
|
+
for ( let i = 0; i < cameras.length; i ++ ) {
|
|
770
|
+
|
|
771
|
+
const bundleEncoder = this.pipelineUtils.createBundleEncoder(
|
|
772
|
+
renderContext,
|
|
773
|
+
'renderBundleArrayCamera_' + i
|
|
774
|
+
);
|
|
775
|
+
|
|
776
|
+
// Initialize state tracking for this bundle
|
|
777
|
+
const bundleSets = {
|
|
778
|
+
attributes: {},
|
|
779
|
+
bindingGroups: [],
|
|
780
|
+
pipeline: null,
|
|
781
|
+
index: null
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
renderContextData.bundleEncoders.push( bundleEncoder );
|
|
785
|
+
renderContextData.bundleSets.push( bundleSets );
|
|
786
|
+
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// We'll complete the bundles in finishRender
|
|
790
|
+
renderContextData.currentPass = null;
|
|
791
|
+
|
|
792
|
+
} else {
|
|
793
|
+
|
|
794
|
+
const currentPass = encoder.beginRenderPass( descriptor );
|
|
795
|
+
renderContextData.currentPass = currentPass;
|
|
796
|
+
|
|
797
|
+
if ( renderContext.viewport ) {
|
|
798
|
+
|
|
799
|
+
this.updateViewport( renderContext );
|
|
800
|
+
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
if ( renderContext.scissor ) {
|
|
804
|
+
|
|
805
|
+
this.updateScissor( renderContext );
|
|
806
|
+
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
}
|
|
422
810
|
|
|
423
811
|
//
|
|
424
812
|
|
|
425
813
|
renderContextData.descriptor = descriptor;
|
|
426
814
|
renderContextData.encoder = encoder;
|
|
427
|
-
renderContextData.currentPass = currentPass;
|
|
428
815
|
renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
|
|
429
816
|
renderContextData.renderBundles = [];
|
|
430
817
|
|
|
431
|
-
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* This method creates layer descriptors for each camera in an array camera
|
|
822
|
+
* to prepare for rendering to a depth array texture.
|
|
823
|
+
*
|
|
824
|
+
* @param {RenderContext} renderContext - The render context.
|
|
825
|
+
* @param {Object} renderContextData - The render context data.
|
|
826
|
+
* @param {Object} descriptor - The render pass descriptor.
|
|
827
|
+
* @param {ArrayCamera} cameras - The array camera.
|
|
828
|
+
*
|
|
829
|
+
* @private
|
|
830
|
+
*/
|
|
831
|
+
_createDepthLayerDescriptors( renderContext, renderContextData, descriptor, cameras ) {
|
|
832
|
+
|
|
833
|
+
const depthStencilAttachment = descriptor.depthStencilAttachment;
|
|
834
|
+
renderContextData.layerDescriptors = [];
|
|
835
|
+
|
|
836
|
+
const depthTextureData = this.get( renderContext.depthTexture );
|
|
837
|
+
if ( ! depthTextureData.viewCache ) {
|
|
838
|
+
|
|
839
|
+
depthTextureData.viewCache = [];
|
|
840
|
+
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
for ( let i = 0; i < cameras.length; i ++ ) {
|
|
844
|
+
|
|
845
|
+
const layerDescriptor = {
|
|
846
|
+
...descriptor,
|
|
847
|
+
colorAttachments: [ {
|
|
848
|
+
...descriptor.colorAttachments[ 0 ],
|
|
849
|
+
view: descriptor.colorAttachments[ i ].view
|
|
850
|
+
} ]
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
if ( descriptor.depthStencilAttachment ) {
|
|
854
|
+
|
|
855
|
+
const layerIndex = i;
|
|
856
|
+
|
|
857
|
+
if ( ! depthTextureData.viewCache[ layerIndex ] ) {
|
|
858
|
+
|
|
859
|
+
depthTextureData.viewCache[ layerIndex ] = depthTextureData.texture.createView( {
|
|
860
|
+
dimension: GPUTextureViewDimension.TwoD,
|
|
861
|
+
baseArrayLayer: i,
|
|
862
|
+
arrayLayerCount: 1
|
|
863
|
+
} );
|
|
432
864
|
|
|
433
|
-
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
layerDescriptor.depthStencilAttachment = {
|
|
868
|
+
view: depthTextureData.viewCache[ layerIndex ],
|
|
869
|
+
depthLoadOp: depthStencilAttachment.depthLoadOp || GPULoadOp.Clear,
|
|
870
|
+
depthStoreOp: depthStencilAttachment.depthStoreOp || GPUStoreOp.Store,
|
|
871
|
+
depthClearValue: depthStencilAttachment.depthClearValue || 1.0
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
if ( renderContext.stencil ) {
|
|
875
|
+
|
|
876
|
+
layerDescriptor.depthStencilAttachment.stencilLoadOp = depthStencilAttachment.stencilLoadOp;
|
|
877
|
+
layerDescriptor.depthStencilAttachment.stencilStoreOp = depthStencilAttachment.stencilStoreOp;
|
|
878
|
+
layerDescriptor.depthStencilAttachment.stencilClearValue = depthStencilAttachment.stencilClearValue;
|
|
879
|
+
|
|
880
|
+
}
|
|
434
881
|
|
|
435
|
-
|
|
882
|
+
} else {
|
|
883
|
+
|
|
884
|
+
layerDescriptor.depthStencilAttachment = { ...depthStencilAttachment };
|
|
885
|
+
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
renderContextData.layerDescriptors.push( layerDescriptor );
|
|
436
889
|
|
|
437
890
|
}
|
|
438
891
|
|
|
439
|
-
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* This method updates the layer descriptors for each camera in an array camera
|
|
896
|
+
* to prepare for rendering to a depth array texture.
|
|
897
|
+
*
|
|
898
|
+
* @param {RenderContext} renderContext - The render context.
|
|
899
|
+
* @param {Object} renderContextData - The render context data.
|
|
900
|
+
* @param {ArrayCamera} cameras - The array camera.
|
|
901
|
+
*
|
|
902
|
+
*/
|
|
903
|
+
_updateDepthLayerDescriptors( renderContext, renderContextData, cameras ) {
|
|
904
|
+
|
|
905
|
+
for ( let i = 0; i < cameras.length; i ++ ) {
|
|
906
|
+
|
|
907
|
+
const layerDescriptor = renderContextData.layerDescriptors[ i ];
|
|
908
|
+
|
|
909
|
+
if ( layerDescriptor.depthStencilAttachment ) {
|
|
910
|
+
|
|
911
|
+
const depthAttachment = layerDescriptor.depthStencilAttachment;
|
|
912
|
+
|
|
913
|
+
if ( renderContext.depth ) {
|
|
914
|
+
|
|
915
|
+
if ( renderContext.clearDepth ) {
|
|
916
|
+
|
|
917
|
+
depthAttachment.depthClearValue = renderContext.clearDepthValue;
|
|
918
|
+
depthAttachment.depthLoadOp = GPULoadOp.Clear;
|
|
919
|
+
|
|
920
|
+
} else {
|
|
921
|
+
|
|
922
|
+
depthAttachment.depthLoadOp = GPULoadOp.Load;
|
|
923
|
+
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
if ( renderContext.stencil ) {
|
|
929
|
+
|
|
930
|
+
if ( renderContext.clearStencil ) {
|
|
931
|
+
|
|
932
|
+
depthAttachment.stencilClearValue = renderContext.clearStencilValue;
|
|
933
|
+
depthAttachment.stencilLoadOp = GPULoadOp.Clear;
|
|
934
|
+
|
|
935
|
+
} else {
|
|
936
|
+
|
|
937
|
+
depthAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
440
938
|
|
|
441
|
-
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
}
|
|
442
942
|
|
|
443
|
-
|
|
943
|
+
}
|
|
444
944
|
|
|
445
945
|
}
|
|
446
946
|
|
|
447
947
|
}
|
|
448
948
|
|
|
949
|
+
/**
|
|
950
|
+
* This method is executed at the end of a render call and finalizes work
|
|
951
|
+
* after draw calls.
|
|
952
|
+
*
|
|
953
|
+
* @param {RenderContext} renderContext - The render context.
|
|
954
|
+
*/
|
|
449
955
|
finishRender( renderContext ) {
|
|
450
956
|
|
|
451
957
|
const renderContextData = this.get( renderContext );
|
|
@@ -463,7 +969,55 @@ class WebGPUBackend extends Backend {
|
|
|
463
969
|
|
|
464
970
|
}
|
|
465
971
|
|
|
466
|
-
|
|
972
|
+
// shadow arrays - Execute bundles for each layer
|
|
973
|
+
|
|
974
|
+
const encoder = renderContextData.encoder;
|
|
975
|
+
|
|
976
|
+
if ( this._isRenderCameraDepthArray( renderContext ) === true ) {
|
|
977
|
+
|
|
978
|
+
const bundles = [];
|
|
979
|
+
|
|
980
|
+
for ( let i = 0; i < renderContextData.bundleEncoders.length; i ++ ) {
|
|
981
|
+
|
|
982
|
+
const bundleEncoder = renderContextData.bundleEncoders[ i ];
|
|
983
|
+
bundles.push( bundleEncoder.finish() );
|
|
984
|
+
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
for ( let i = 0; i < renderContextData.layerDescriptors.length; i ++ ) {
|
|
988
|
+
|
|
989
|
+
if ( i < bundles.length ) {
|
|
990
|
+
|
|
991
|
+
const layerDescriptor = renderContextData.layerDescriptors[ i ];
|
|
992
|
+
const renderPass = encoder.beginRenderPass( layerDescriptor );
|
|
993
|
+
|
|
994
|
+
if ( renderContext.viewport ) {
|
|
995
|
+
|
|
996
|
+
const { x, y, width, height, minDepth, maxDepth } = renderContext.viewportValue;
|
|
997
|
+
renderPass.setViewport( x, y, width, height, minDepth, maxDepth );
|
|
998
|
+
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
if ( renderContext.scissor ) {
|
|
1002
|
+
|
|
1003
|
+
const { x, y, width, height } = renderContext.scissorValue;
|
|
1004
|
+
renderPass.setScissorRect( x, y, width, height );
|
|
1005
|
+
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
renderPass.executeBundles( [ bundles[ i ] ] );
|
|
1009
|
+
|
|
1010
|
+
renderPass.end();
|
|
1011
|
+
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
} else if ( renderContextData.currentPass ) {
|
|
1017
|
+
|
|
1018
|
+
renderContextData.currentPass.end();
|
|
1019
|
+
|
|
1020
|
+
}
|
|
467
1021
|
|
|
468
1022
|
if ( occlusionQueryCount > 0 ) {
|
|
469
1023
|
|
|
@@ -507,8 +1061,6 @@ class WebGPUBackend extends Backend {
|
|
|
507
1061
|
|
|
508
1062
|
}
|
|
509
1063
|
|
|
510
|
-
this.prepareTimestampBuffer( renderContext, renderContextData.encoder );
|
|
511
|
-
|
|
512
1064
|
this.device.queue.submit( [ renderContextData.encoder.finish() ] );
|
|
513
1065
|
|
|
514
1066
|
|
|
@@ -534,6 +1086,14 @@ class WebGPUBackend extends Backend {
|
|
|
534
1086
|
|
|
535
1087
|
}
|
|
536
1088
|
|
|
1089
|
+
/**
|
|
1090
|
+
* Returns `true` if the given 3D object is fully occluded by other
|
|
1091
|
+
* 3D objects in the scene.
|
|
1092
|
+
*
|
|
1093
|
+
* @param {RenderContext} renderContext - The render context.
|
|
1094
|
+
* @param {Object3D} object - The 3D object to test.
|
|
1095
|
+
* @return {boolean} Whether the 3D object is fully occluded or not.
|
|
1096
|
+
*/
|
|
537
1097
|
isOccluded( renderContext, object ) {
|
|
538
1098
|
|
|
539
1099
|
const renderContextData = this.get( renderContext );
|
|
@@ -542,6 +1102,14 @@ class WebGPUBackend extends Backend {
|
|
|
542
1102
|
|
|
543
1103
|
}
|
|
544
1104
|
|
|
1105
|
+
/**
|
|
1106
|
+
* This method processes the result of occlusion queries and writes it
|
|
1107
|
+
* into render context data.
|
|
1108
|
+
*
|
|
1109
|
+
* @async
|
|
1110
|
+
* @param {RenderContext} renderContext - The render context.
|
|
1111
|
+
* @return {Promise} A Promise that resolves when the occlusion query results have been processed.
|
|
1112
|
+
*/
|
|
545
1113
|
async resolveOccludedAsync( renderContext ) {
|
|
546
1114
|
|
|
547
1115
|
const renderContextData = this.get( renderContext );
|
|
@@ -564,7 +1132,7 @@ class WebGPUBackend extends Backend {
|
|
|
564
1132
|
|
|
565
1133
|
for ( let i = 0; i < currentOcclusionQueryObjects.length; i ++ ) {
|
|
566
1134
|
|
|
567
|
-
if ( results[ i ]
|
|
1135
|
+
if ( results[ i ] === BigInt( 0 ) ) {
|
|
568
1136
|
|
|
569
1137
|
occluded.add( currentOcclusionQueryObjects[ i ] );
|
|
570
1138
|
|
|
@@ -580,6 +1148,11 @@ class WebGPUBackend extends Backend {
|
|
|
580
1148
|
|
|
581
1149
|
}
|
|
582
1150
|
|
|
1151
|
+
/**
|
|
1152
|
+
* Updates the viewport with the values from the given render context.
|
|
1153
|
+
*
|
|
1154
|
+
* @param {RenderContext} renderContext - The render context.
|
|
1155
|
+
*/
|
|
583
1156
|
updateViewport( renderContext ) {
|
|
584
1157
|
|
|
585
1158
|
const { currentPass } = this.get( renderContext );
|
|
@@ -589,13 +1162,58 @@ class WebGPUBackend extends Backend {
|
|
|
589
1162
|
|
|
590
1163
|
}
|
|
591
1164
|
|
|
592
|
-
|
|
1165
|
+
/**
|
|
1166
|
+
* Updates the scissor with the values from the given render context.
|
|
1167
|
+
*
|
|
1168
|
+
* @param {RenderContext} renderContext - The render context.
|
|
1169
|
+
*/
|
|
1170
|
+
updateScissor( renderContext ) {
|
|
1171
|
+
|
|
1172
|
+
const { currentPass } = this.get( renderContext );
|
|
1173
|
+
const { x, y, width, height } = renderContext.scissorValue;
|
|
1174
|
+
|
|
1175
|
+
currentPass.setScissorRect( x, y, width, height );
|
|
1176
|
+
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* Returns the clear color and alpha into a single
|
|
1181
|
+
* color object.
|
|
1182
|
+
*
|
|
1183
|
+
* @return {Color4} The clear color.
|
|
1184
|
+
*/
|
|
1185
|
+
getClearColor() {
|
|
1186
|
+
|
|
1187
|
+
const clearColor = super.getClearColor();
|
|
1188
|
+
|
|
1189
|
+
// only premultiply alpha when alphaMode is "premultiplied"
|
|
1190
|
+
|
|
1191
|
+
if ( this.renderer.alpha === true ) {
|
|
1192
|
+
|
|
1193
|
+
clearColor.r *= clearColor.a;
|
|
1194
|
+
clearColor.g *= clearColor.a;
|
|
1195
|
+
clearColor.b *= clearColor.a;
|
|
1196
|
+
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
return clearColor;
|
|
1200
|
+
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* Performs a clear operation.
|
|
1205
|
+
*
|
|
1206
|
+
* @param {boolean} color - Whether the color buffer should be cleared or not.
|
|
1207
|
+
* @param {boolean} depth - Whether the depth buffer should be cleared or not.
|
|
1208
|
+
* @param {boolean} stencil - Whether the stencil buffer should be cleared or not.
|
|
1209
|
+
* @param {?RenderContext} [renderTargetContext=null] - The render context of the current set render target.
|
|
1210
|
+
*/
|
|
1211
|
+
clear( color, depth, stencil, renderTargetContext = null ) {
|
|
593
1212
|
|
|
594
1213
|
const device = this.device;
|
|
595
1214
|
const renderer = this.renderer;
|
|
596
1215
|
|
|
597
1216
|
let colorAttachments = [];
|
|
598
|
-
|
|
599
1217
|
let depthStencilAttachment;
|
|
600
1218
|
let clearValue;
|
|
601
1219
|
|
|
@@ -605,24 +1223,11 @@ class WebGPUBackend extends Backend {
|
|
|
605
1223
|
if ( color ) {
|
|
606
1224
|
|
|
607
1225
|
const clearColor = this.getClearColor();
|
|
608
|
-
|
|
609
|
-
if ( this.renderer.alpha === true ) {
|
|
610
|
-
|
|
611
|
-
// premultiply alpha
|
|
612
|
-
|
|
613
|
-
const a = clearColor.a;
|
|
614
|
-
|
|
615
|
-
clearValue = { r: clearColor.r * a, g: clearColor.g * a, b: clearColor.b * a, a: a };
|
|
616
|
-
|
|
617
|
-
} else {
|
|
618
|
-
|
|
619
|
-
clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };
|
|
620
|
-
|
|
621
|
-
}
|
|
1226
|
+
clearValue = { r: clearColor.r, g: clearColor.g, b: clearColor.b, a: clearColor.a };
|
|
622
1227
|
|
|
623
1228
|
}
|
|
624
1229
|
|
|
625
|
-
if (
|
|
1230
|
+
if ( renderTargetContext === null ) {
|
|
626
1231
|
|
|
627
1232
|
supportsDepth = renderer.depth;
|
|
628
1233
|
supportsStencil = renderer.stencil;
|
|
@@ -649,330 +1254,550 @@ class WebGPUBackend extends Backend {
|
|
|
649
1254
|
|
|
650
1255
|
} else {
|
|
651
1256
|
|
|
652
|
-
supportsDepth =
|
|
653
|
-
supportsStencil =
|
|
1257
|
+
supportsDepth = renderTargetContext.depth;
|
|
1258
|
+
supportsStencil = renderTargetContext.stencil;
|
|
654
1259
|
|
|
655
|
-
|
|
1260
|
+
const clearConfig = {
|
|
1261
|
+
loadOp: color ? GPULoadOp.Clear : GPULoadOp.Load,
|
|
1262
|
+
clearValue: color ? clearValue : undefined
|
|
1263
|
+
};
|
|
656
1264
|
|
|
657
|
-
|
|
1265
|
+
if ( supportsDepth ) {
|
|
658
1266
|
|
|
659
|
-
|
|
660
|
-
|
|
1267
|
+
clearConfig.depthLoadOp = depth ? GPULoadOp.Clear : GPULoadOp.Load;
|
|
1268
|
+
clearConfig.depthClearValue = depth ? renderer.getClearDepth() : undefined;
|
|
1269
|
+
clearConfig.depthStoreOp = GPUStoreOp.Store;
|
|
661
1270
|
|
|
662
|
-
|
|
1271
|
+
}
|
|
663
1272
|
|
|
664
|
-
|
|
1273
|
+
if ( supportsStencil ) {
|
|
665
1274
|
|
|
666
|
-
|
|
667
|
-
|
|
1275
|
+
clearConfig.stencilLoadOp = stencil ? GPULoadOp.Clear : GPULoadOp.Load;
|
|
1276
|
+
clearConfig.stencilClearValue = stencil ? renderer.getClearStencil() : undefined;
|
|
1277
|
+
clearConfig.stencilStoreOp = GPUStoreOp.Store;
|
|
668
1278
|
|
|
669
|
-
|
|
1279
|
+
}
|
|
670
1280
|
|
|
671
|
-
|
|
672
|
-
resolveTarget = undefined;
|
|
1281
|
+
const descriptor = this._getRenderPassDescriptor( renderTargetContext, clearConfig );
|
|
673
1282
|
|
|
674
|
-
|
|
1283
|
+
colorAttachments = descriptor.colorAttachments;
|
|
1284
|
+
depthStencilAttachment = descriptor.depthStencilAttachment;
|
|
675
1285
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
if ( supportsDepth && depthStencilAttachment ) {
|
|
1289
|
+
|
|
1290
|
+
if ( depth ) {
|
|
1291
|
+
|
|
1292
|
+
depthStencilAttachment.depthLoadOp = GPULoadOp.Clear;
|
|
1293
|
+
depthStencilAttachment.depthClearValue = renderer.getClearDepth();
|
|
1294
|
+
depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
|
|
1295
|
+
|
|
1296
|
+
} else {
|
|
1297
|
+
|
|
1298
|
+
depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
|
|
1299
|
+
depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
|
|
1300
|
+
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
//
|
|
1306
|
+
|
|
1307
|
+
if ( supportsStencil && depthStencilAttachment ) {
|
|
1308
|
+
|
|
1309
|
+
if ( stencil ) {
|
|
1310
|
+
|
|
1311
|
+
depthStencilAttachment.stencilLoadOp = GPULoadOp.Clear;
|
|
1312
|
+
depthStencilAttachment.stencilClearValue = renderer.getClearStencil();
|
|
1313
|
+
depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
|
|
1314
|
+
|
|
1315
|
+
} else {
|
|
1316
|
+
|
|
1317
|
+
depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
1318
|
+
depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
|
|
1319
|
+
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
//
|
|
1325
|
+
|
|
1326
|
+
const encoder = device.createCommandEncoder( { label: 'clear' } );
|
|
1327
|
+
const currentPass = encoder.beginRenderPass( {
|
|
1328
|
+
colorAttachments,
|
|
1329
|
+
depthStencilAttachment
|
|
1330
|
+
} );
|
|
1331
|
+
|
|
1332
|
+
currentPass.end();
|
|
1333
|
+
|
|
1334
|
+
device.queue.submit( [ encoder.finish() ] );
|
|
1335
|
+
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
// compute
|
|
1339
|
+
|
|
1340
|
+
/**
|
|
1341
|
+
* This method is executed at the beginning of a compute call and
|
|
1342
|
+
* prepares the state for upcoming compute tasks.
|
|
1343
|
+
*
|
|
1344
|
+
* @param {Node|Array<Node>} computeGroup - The compute node(s).
|
|
1345
|
+
*/
|
|
1346
|
+
beginCompute( computeGroup ) {
|
|
1347
|
+
|
|
1348
|
+
const groupGPU = this.get( computeGroup );
|
|
1349
|
+
|
|
1350
|
+
//
|
|
1351
|
+
|
|
1352
|
+
const descriptor = {
|
|
1353
|
+
label: 'computeGroup_' + computeGroup.id
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
this.initTimestampQuery( TimestampQuery.COMPUTE, this.getTimestampUID( computeGroup ), descriptor );
|
|
1357
|
+
|
|
1358
|
+
groupGPU.cmdEncoderGPU = this.device.createCommandEncoder( { label: 'computeGroup_' + computeGroup.id } );
|
|
1359
|
+
|
|
1360
|
+
groupGPU.passEncoderGPU = groupGPU.cmdEncoderGPU.beginComputePass( descriptor );
|
|
1361
|
+
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
/**
|
|
1365
|
+
* Executes a compute command for the given compute node.
|
|
1366
|
+
*
|
|
1367
|
+
* @param {Node|Array<Node>} computeGroup - The group of compute nodes of a compute call. Can be a single compute node.
|
|
1368
|
+
* @param {Node} computeNode - The compute node.
|
|
1369
|
+
* @param {Array<BindGroup>} bindings - The bindings.
|
|
1370
|
+
* @param {ComputePipeline} pipeline - The compute pipeline.
|
|
1371
|
+
* @param {number|Array<number>|IndirectStorageBufferAttribute} [dispatchSize=null]
|
|
1372
|
+
* - A single number representing count, or
|
|
1373
|
+
* - An array [x, y, z] representing dispatch size, or
|
|
1374
|
+
* - A IndirectStorageBufferAttribute for indirect dispatch size.
|
|
1375
|
+
*/
|
|
1376
|
+
compute( computeGroup, computeNode, bindings, pipeline, dispatchSize = null ) {
|
|
1377
|
+
|
|
1378
|
+
const computeNodeData = this.get( computeNode );
|
|
1379
|
+
const { passEncoderGPU } = this.get( computeGroup );
|
|
1380
|
+
|
|
1381
|
+
// pipeline
|
|
1382
|
+
|
|
1383
|
+
const pipelineGPU = this.get( pipeline ).pipeline;
|
|
1384
|
+
|
|
1385
|
+
this.pipelineUtils.setPipeline( passEncoderGPU, pipelineGPU );
|
|
1386
|
+
|
|
1387
|
+
// bind groups
|
|
1388
|
+
|
|
1389
|
+
for ( let i = 0, l = bindings.length; i < l; i ++ ) {
|
|
1390
|
+
|
|
1391
|
+
const bindGroup = bindings[ i ];
|
|
1392
|
+
const bindingsData = this.get( bindGroup );
|
|
1393
|
+
|
|
1394
|
+
passEncoderGPU.setBindGroup( i, bindingsData.group );
|
|
1395
|
+
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
if ( dispatchSize === null ) {
|
|
1399
|
+
|
|
1400
|
+
dispatchSize = computeNode.count;
|
|
1401
|
+
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
// When the dispatchSize is set with a StorageBuffer from the GPU.
|
|
1405
|
+
|
|
1406
|
+
if ( dispatchSize && typeof dispatchSize === 'object' && dispatchSize.isIndirectStorageBufferAttribute ) {
|
|
1407
|
+
|
|
1408
|
+
const dispatchBuffer = this.get( dispatchSize ).buffer;
|
|
1409
|
+
|
|
1410
|
+
passEncoderGPU.dispatchWorkgroupsIndirect( dispatchBuffer, 0 );
|
|
1411
|
+
|
|
1412
|
+
return;
|
|
1413
|
+
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
if ( typeof dispatchSize === 'number' ) {
|
|
1417
|
+
|
|
1418
|
+
// If a single number is given, we calculate the dispatch size based on the workgroup size
|
|
1419
|
+
|
|
1420
|
+
const count = dispatchSize;
|
|
1421
|
+
|
|
1422
|
+
if ( computeNodeData.dispatchSize === undefined || computeNodeData.count !== count ) {
|
|
1423
|
+
|
|
1424
|
+
// cache dispatch size to avoid recalculating it every time
|
|
1425
|
+
|
|
1426
|
+
computeNodeData.dispatchSize = [ 0, 1, 1 ];
|
|
1427
|
+
computeNodeData.count = count;
|
|
1428
|
+
|
|
1429
|
+
const workgroupSize = computeNode.workgroupSize;
|
|
1430
|
+
|
|
1431
|
+
let size = workgroupSize[ 0 ];
|
|
1432
|
+
|
|
1433
|
+
for ( let i = 1; i < workgroupSize.length; i ++ )
|
|
1434
|
+
size *= workgroupSize[ i ];
|
|
1435
|
+
|
|
1436
|
+
const dispatchCount = Math.ceil( count / size );
|
|
1437
|
+
|
|
1438
|
+
//
|
|
1439
|
+
|
|
1440
|
+
const maxComputeWorkgroupsPerDimension = this.device.limits.maxComputeWorkgroupsPerDimension;
|
|
1441
|
+
|
|
1442
|
+
dispatchSize = [ dispatchCount, 1, 1 ];
|
|
1443
|
+
|
|
1444
|
+
if ( dispatchCount > maxComputeWorkgroupsPerDimension ) {
|
|
1445
|
+
|
|
1446
|
+
dispatchSize[ 0 ] = Math.min( dispatchCount, maxComputeWorkgroupsPerDimension );
|
|
1447
|
+
dispatchSize[ 1 ] = Math.ceil( dispatchCount / maxComputeWorkgroupsPerDimension );
|
|
683
1448
|
|
|
684
1449
|
}
|
|
685
1450
|
|
|
686
|
-
|
|
1451
|
+
computeNodeData.dispatchSize = dispatchSize;
|
|
1452
|
+
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
dispatchSize = computeNodeData.dispatchSize;
|
|
1456
|
+
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
//
|
|
1460
|
+
|
|
1461
|
+
passEncoderGPU.dispatchWorkgroups(
|
|
1462
|
+
dispatchSize[ 0 ],
|
|
1463
|
+
dispatchSize[ 1 ] || 1,
|
|
1464
|
+
dispatchSize[ 2 ] || 1
|
|
1465
|
+
);
|
|
1466
|
+
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* This method is executed at the end of a compute call and
|
|
1471
|
+
* finalizes work after compute tasks.
|
|
1472
|
+
*
|
|
1473
|
+
* @param {Node|Array<Node>} computeGroup - The compute node(s).
|
|
1474
|
+
*/
|
|
1475
|
+
finishCompute( computeGroup ) {
|
|
1476
|
+
|
|
1477
|
+
const groupData = this.get( computeGroup );
|
|
1478
|
+
|
|
1479
|
+
groupData.passEncoderGPU.end();
|
|
1480
|
+
|
|
1481
|
+
this.device.queue.submit( [ groupData.cmdEncoderGPU.finish() ] );
|
|
1482
|
+
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
// render object
|
|
1486
|
+
|
|
1487
|
+
/**
|
|
1488
|
+
* Executes a draw command for the given render object.
|
|
1489
|
+
*
|
|
1490
|
+
* @param {RenderObject} renderObject - The render object to draw.
|
|
1491
|
+
* @param {Info} info - Holds a series of statistical information about the GPU memory and the rendering process.
|
|
1492
|
+
*/
|
|
1493
|
+
draw( renderObject, info ) {
|
|
1494
|
+
|
|
1495
|
+
const { object, material, context, pipeline } = renderObject;
|
|
1496
|
+
const bindings = renderObject.getBindings();
|
|
1497
|
+
const renderContextData = this.get( context );
|
|
1498
|
+
const pipelineData = this.get( pipeline );
|
|
1499
|
+
const pipelineGPU = pipelineData.pipeline;
|
|
687
1500
|
|
|
688
|
-
|
|
1501
|
+
if ( pipelineData.error === true ) return;
|
|
689
1502
|
|
|
690
|
-
|
|
1503
|
+
const index = renderObject.getIndex();
|
|
1504
|
+
const hasIndex = ( index !== null );
|
|
691
1505
|
|
|
692
|
-
depthStencilAttachment = {
|
|
693
|
-
view: depthTextureData.texture.createView()
|
|
694
|
-
};
|
|
695
1506
|
|
|
696
|
-
|
|
1507
|
+
const drawParams = renderObject.getDrawParameters();
|
|
1508
|
+
if ( drawParams === null ) return;
|
|
697
1509
|
|
|
698
|
-
|
|
1510
|
+
// pipeline
|
|
699
1511
|
|
|
700
|
-
|
|
1512
|
+
const setPipelineAndBindings = ( passEncoderGPU, currentSets ) => {
|
|
701
1513
|
|
|
702
|
-
|
|
1514
|
+
// pipeline
|
|
1515
|
+
this.pipelineUtils.setPipeline( passEncoderGPU, pipelineGPU );
|
|
1516
|
+
currentSets.pipeline = pipelineGPU;
|
|
703
1517
|
|
|
704
|
-
|
|
1518
|
+
// bind groups
|
|
1519
|
+
const currentBindingGroups = currentSets.bindingGroups;
|
|
1520
|
+
for ( let i = 0, l = bindings.length; i < l; i ++ ) {
|
|
705
1521
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
1522
|
+
const bindGroup = bindings[ i ];
|
|
1523
|
+
const bindingsData = this.get( bindGroup );
|
|
1524
|
+
if ( currentBindingGroups[ bindGroup.index ] !== bindGroup.id ) {
|
|
709
1525
|
|
|
710
|
-
|
|
1526
|
+
passEncoderGPU.setBindGroup( bindGroup.index, bindingsData.group );
|
|
1527
|
+
currentBindingGroups[ bindGroup.index ] = bindGroup.id;
|
|
711
1528
|
|
|
712
|
-
|
|
713
|
-
depthStencilAttachment.depthStoreOp = GPUStoreOp.Store;
|
|
1529
|
+
}
|
|
714
1530
|
|
|
715
1531
|
}
|
|
716
1532
|
|
|
717
|
-
|
|
1533
|
+
// attributes
|
|
718
1534
|
|
|
719
|
-
|
|
1535
|
+
// index
|
|
720
1536
|
|
|
721
|
-
|
|
1537
|
+
if ( hasIndex === true ) {
|
|
722
1538
|
|
|
723
|
-
|
|
1539
|
+
if ( currentSets.index !== index ) {
|
|
724
1540
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
depthStencilAttachment.stencilStoreOp = GPUStoreOp.Store;
|
|
1541
|
+
const buffer = this.get( index ).buffer;
|
|
1542
|
+
const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
|
|
728
1543
|
|
|
729
|
-
|
|
1544
|
+
passEncoderGPU.setIndexBuffer( buffer, indexFormat );
|
|
730
1545
|
|
|
731
|
-
|
|
732
|
-
|
|
1546
|
+
currentSets.index = index;
|
|
1547
|
+
|
|
1548
|
+
}
|
|
733
1549
|
|
|
734
1550
|
}
|
|
1551
|
+
// vertex buffers
|
|
735
1552
|
|
|
736
|
-
|
|
1553
|
+
const vertexBuffers = renderObject.getVertexBuffers();
|
|
737
1554
|
|
|
738
|
-
|
|
1555
|
+
for ( let i = 0, l = vertexBuffers.length; i < l; i ++ ) {
|
|
739
1556
|
|
|
740
|
-
|
|
741
|
-
const currentPass = encoder.beginRenderPass( {
|
|
742
|
-
colorAttachments,
|
|
743
|
-
depthStencilAttachment
|
|
744
|
-
} );
|
|
1557
|
+
const vertexBuffer = vertexBuffers[ i ];
|
|
745
1558
|
|
|
746
|
-
|
|
1559
|
+
if ( currentSets.attributes[ i ] !== vertexBuffer ) {
|
|
747
1560
|
|
|
748
|
-
|
|
1561
|
+
const buffer = this.get( vertexBuffer ).buffer;
|
|
1562
|
+
passEncoderGPU.setVertexBuffer( i, buffer );
|
|
749
1563
|
|
|
750
|
-
|
|
1564
|
+
currentSets.attributes[ i ] = vertexBuffer;
|
|
751
1565
|
|
|
752
|
-
|
|
1566
|
+
}
|
|
753
1567
|
|
|
754
|
-
|
|
1568
|
+
}
|
|
1569
|
+
// stencil
|
|
755
1570
|
|
|
756
|
-
|
|
1571
|
+
if ( context.stencil === true && material.stencilWrite === true && renderContextData.currentStencilRef !== material.stencilRef ) {
|
|
757
1572
|
|
|
1573
|
+
passEncoderGPU.setStencilReference( material.stencilRef );
|
|
1574
|
+
renderContextData.currentStencilRef = material.stencilRef;
|
|
758
1575
|
|
|
759
|
-
|
|
1576
|
+
}
|
|
760
1577
|
|
|
761
|
-
this.initTimestampQuery( computeGroup, descriptor );
|
|
762
1578
|
|
|
763
|
-
|
|
1579
|
+
};
|
|
764
1580
|
|
|
765
|
-
|
|
1581
|
+
// Define draw function
|
|
1582
|
+
const draw = ( passEncoderGPU, currentSets ) => {
|
|
766
1583
|
|
|
767
|
-
|
|
1584
|
+
setPipelineAndBindings( passEncoderGPU, currentSets );
|
|
768
1585
|
|
|
769
|
-
|
|
1586
|
+
if ( object.isBatchedMesh === true ) {
|
|
770
1587
|
|
|
771
|
-
|
|
1588
|
+
const starts = object._multiDrawStarts;
|
|
1589
|
+
const counts = object._multiDrawCounts;
|
|
1590
|
+
const drawCount = object._multiDrawCount;
|
|
1591
|
+
const drawInstances = object._multiDrawInstances;
|
|
772
1592
|
|
|
773
|
-
|
|
1593
|
+
if ( drawInstances !== null ) {
|
|
774
1594
|
|
|
775
|
-
|
|
776
|
-
|
|
1595
|
+
// @deprecated, r174
|
|
1596
|
+
warnOnce( 'WebGPUBackend: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.' );
|
|
777
1597
|
|
|
778
|
-
|
|
1598
|
+
}
|
|
779
1599
|
|
|
780
|
-
|
|
1600
|
+
let bytesPerElement = ( hasIndex === true ) ? index.array.BYTES_PER_ELEMENT : 1;
|
|
781
1601
|
|
|
782
|
-
|
|
783
|
-
const bindingsData = this.get( bindGroup );
|
|
1602
|
+
if ( material.wireframe ) {
|
|
784
1603
|
|
|
785
|
-
|
|
1604
|
+
bytesPerElement = object.geometry.attributes.position.count > 65535 ? 4 : 2;
|
|
786
1605
|
|
|
787
|
-
|
|
1606
|
+
}
|
|
788
1607
|
|
|
789
|
-
|
|
1608
|
+
for ( let i = 0; i < drawCount; i ++ ) {
|
|
790
1609
|
|
|
791
|
-
|
|
1610
|
+
const count = drawInstances ? drawInstances[ i ] : 1;
|
|
1611
|
+
const firstInstance = count > 1 ? 0 : i;
|
|
792
1612
|
|
|
793
|
-
|
|
1613
|
+
if ( hasIndex === true ) {
|
|
794
1614
|
|
|
795
|
-
|
|
1615
|
+
passEncoderGPU.drawIndexed( counts[ i ], count, starts[ i ] / bytesPerElement, 0, firstInstance );
|
|
796
1616
|
|
|
797
|
-
|
|
1617
|
+
} else {
|
|
798
1618
|
|
|
799
|
-
|
|
800
|
-
dispatchSize.y = Math.ceil( computeNode.dispatchCount / maxComputeWorkgroupsPerDimension );
|
|
1619
|
+
passEncoderGPU.draw( counts[ i ], count, starts[ i ], firstInstance );
|
|
801
1620
|
|
|
802
|
-
|
|
1621
|
+
}
|
|
803
1622
|
|
|
804
|
-
|
|
1623
|
+
info.update( object, counts[ i ], count );
|
|
805
1624
|
|
|
806
|
-
|
|
1625
|
+
}
|
|
807
1626
|
|
|
808
|
-
|
|
809
|
-
dispatchSize.x,
|
|
810
|
-
dispatchSize.y,
|
|
811
|
-
dispatchSize.z
|
|
812
|
-
);
|
|
1627
|
+
} else if ( hasIndex === true ) {
|
|
813
1628
|
|
|
814
|
-
|
|
1629
|
+
const { vertexCount: indexCount, instanceCount, firstVertex: firstIndex } = drawParams;
|
|
815
1630
|
|
|
816
|
-
|
|
1631
|
+
const indirect = renderObject.getIndirect();
|
|
817
1632
|
|
|
818
|
-
|
|
1633
|
+
if ( indirect !== null ) {
|
|
819
1634
|
|
|
820
|
-
|
|
1635
|
+
const buffer = this.get( indirect ).buffer;
|
|
1636
|
+
const indirectOffset = renderObject.getIndirectOffset();
|
|
1637
|
+
const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
|
|
821
1638
|
|
|
822
|
-
|
|
1639
|
+
for ( let i = 0; i < indirectOffsets.length; i ++ ) {
|
|
823
1640
|
|
|
824
|
-
|
|
1641
|
+
passEncoderGPU.drawIndexedIndirect( buffer, indirectOffsets[ i ] );
|
|
825
1642
|
|
|
826
|
-
|
|
1643
|
+
}
|
|
827
1644
|
|
|
828
|
-
|
|
1645
|
+
} else {
|
|
829
1646
|
|
|
830
|
-
|
|
1647
|
+
passEncoderGPU.drawIndexed( indexCount, instanceCount, firstIndex, 0, 0 );
|
|
831
1648
|
|
|
832
|
-
|
|
833
|
-
const bindings = renderObject.getBindings();
|
|
834
|
-
const renderContextData = this.get( context );
|
|
835
|
-
const pipelineGPU = this.get( pipeline ).pipeline;
|
|
836
|
-
const currentSets = renderContextData.currentSets;
|
|
837
|
-
const passEncoderGPU = renderContextData.currentPass;
|
|
1649
|
+
}
|
|
838
1650
|
|
|
839
|
-
|
|
1651
|
+
info.update( object, indexCount, instanceCount );
|
|
840
1652
|
|
|
841
|
-
|
|
1653
|
+
} else {
|
|
842
1654
|
|
|
843
|
-
|
|
1655
|
+
const { vertexCount, instanceCount, firstVertex } = drawParams;
|
|
844
1656
|
|
|
845
|
-
|
|
1657
|
+
const indirect = renderObject.getIndirect();
|
|
846
1658
|
|
|
847
|
-
|
|
1659
|
+
if ( indirect !== null ) {
|
|
848
1660
|
|
|
849
|
-
|
|
1661
|
+
const buffer = this.get( indirect ).buffer;
|
|
1662
|
+
const indirectOffset = renderObject.getIndirectOffset();
|
|
1663
|
+
const indirectOffsets = Array.isArray( indirectOffset ) ? indirectOffset : [ indirectOffset ];
|
|
850
1664
|
|
|
851
|
-
|
|
1665
|
+
for ( let i = 0; i < indirectOffsets.length; i ++ ) {
|
|
852
1666
|
|
|
853
|
-
|
|
1667
|
+
passEncoderGPU.drawIndirect( buffer, indirectOffsets[ i ] );
|
|
1668
|
+
|
|
1669
|
+
}
|
|
854
1670
|
|
|
855
|
-
const currentBindingGroups = currentSets.bindingGroups;
|
|
856
1671
|
|
|
857
|
-
|
|
1672
|
+
} else {
|
|
858
1673
|
|
|
859
|
-
|
|
860
|
-
const bindingsData = this.get( bindGroup );
|
|
1674
|
+
passEncoderGPU.draw( vertexCount, instanceCount, firstVertex, 0 );
|
|
861
1675
|
|
|
862
|
-
|
|
1676
|
+
}
|
|
863
1677
|
|
|
864
|
-
|
|
865
|
-
currentBindingGroups[ bindGroup.index ] = bindGroup.id;
|
|
1678
|
+
info.update( object, vertexCount, instanceCount );
|
|
866
1679
|
|
|
867
1680
|
}
|
|
868
1681
|
|
|
869
|
-
}
|
|
1682
|
+
};
|
|
870
1683
|
|
|
871
|
-
|
|
1684
|
+
if ( renderObject.camera.isArrayCamera && renderObject.camera.cameras.length > 0 ) {
|
|
872
1685
|
|
|
873
|
-
|
|
1686
|
+
const cameraData = this.get( renderObject.camera );
|
|
1687
|
+
const cameras = renderObject.camera.cameras;
|
|
1688
|
+
const cameraIndex = renderObject.getBindingGroup( 'cameraIndex' );
|
|
874
1689
|
|
|
875
|
-
|
|
1690
|
+
if ( cameraData.indexesGPU === undefined || cameraData.indexesGPU.length !== cameras.length ) {
|
|
876
1691
|
|
|
877
|
-
|
|
1692
|
+
const bindingsData = this.get( cameraIndex );
|
|
1693
|
+
const indexesGPU = [];
|
|
878
1694
|
|
|
879
|
-
|
|
1695
|
+
const data = new Uint32Array( [ 0, 0, 0, 0 ] );
|
|
880
1696
|
|
|
881
|
-
|
|
1697
|
+
for ( let i = 0, len = cameras.length; i < len; i ++ ) {
|
|
882
1698
|
|
|
883
|
-
|
|
884
|
-
const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
|
|
1699
|
+
data[ 0 ] = i;
|
|
885
1700
|
|
|
886
|
-
|
|
1701
|
+
const { layoutGPU } = bindingsData.layout;
|
|
887
1702
|
|
|
888
|
-
|
|
1703
|
+
const bindGroupIndex = this.bindingUtils.createBindGroupIndex( data, layoutGPU );
|
|
889
1704
|
|
|
890
|
-
|
|
1705
|
+
indexesGPU.push( bindGroupIndex );
|
|
891
1706
|
|
|
892
|
-
|
|
1707
|
+
}
|
|
893
1708
|
|
|
894
|
-
|
|
1709
|
+
cameraData.indexesGPU = indexesGPU; // TODO: Create a global library for this
|
|
895
1710
|
|
|
896
|
-
|
|
1711
|
+
}
|
|
897
1712
|
|
|
898
|
-
|
|
1713
|
+
const pixelRatio = this.renderer.getPixelRatio();
|
|
899
1714
|
|
|
900
|
-
|
|
1715
|
+
for ( let i = 0, len = cameras.length; i < len; i ++ ) {
|
|
901
1716
|
|
|
902
|
-
|
|
1717
|
+
const subCamera = cameras[ i ];
|
|
903
1718
|
|
|
904
|
-
|
|
905
|
-
passEncoderGPU.setVertexBuffer( i, buffer );
|
|
1719
|
+
if ( object.layers.test( subCamera.layers ) ) {
|
|
906
1720
|
|
|
907
|
-
|
|
1721
|
+
const vp = subCamera.viewport;
|
|
908
1722
|
|
|
909
|
-
}
|
|
910
1723
|
|
|
911
|
-
}
|
|
912
1724
|
|
|
913
|
-
|
|
1725
|
+
let pass = renderContextData.currentPass;
|
|
1726
|
+
let sets = renderContextData.currentSets;
|
|
1727
|
+
if ( renderContextData.bundleEncoders ) {
|
|
914
1728
|
|
|
915
|
-
|
|
1729
|
+
const bundleEncoder = renderContextData.bundleEncoders[ i ];
|
|
1730
|
+
const bundleSets = renderContextData.bundleSets[ i ];
|
|
1731
|
+
pass = bundleEncoder;
|
|
1732
|
+
sets = bundleSets;
|
|
916
1733
|
|
|
917
|
-
|
|
1734
|
+
}
|
|
918
1735
|
|
|
919
|
-
if ( lastObject !== object ) {
|
|
920
1736
|
|
|
921
|
-
if ( lastObject !== null && lastObject.occlusionTest === true ) {
|
|
922
1737
|
|
|
923
|
-
|
|
924
|
-
renderContextData.occlusionQueryIndex ++;
|
|
1738
|
+
if ( vp ) {
|
|
925
1739
|
|
|
926
|
-
|
|
1740
|
+
pass.setViewport(
|
|
1741
|
+
Math.floor( vp.x * pixelRatio ),
|
|
1742
|
+
Math.floor( vp.y * pixelRatio ),
|
|
1743
|
+
Math.floor( vp.width * pixelRatio ),
|
|
1744
|
+
Math.floor( vp.height * pixelRatio ),
|
|
1745
|
+
context.viewportValue.minDepth,
|
|
1746
|
+
context.viewportValue.maxDepth
|
|
1747
|
+
);
|
|
927
1748
|
|
|
928
|
-
|
|
1749
|
+
}
|
|
929
1750
|
|
|
930
|
-
passEncoderGPU.beginOcclusionQuery( renderContextData.occlusionQueryIndex );
|
|
931
|
-
renderContextData.occlusionQueryObjects[ renderContextData.occlusionQueryIndex ] = object;
|
|
932
1751
|
|
|
933
|
-
|
|
1752
|
+
// Set camera index binding for this layer
|
|
1753
|
+
if ( cameraIndex && cameraData.indexesGPU ) {
|
|
934
1754
|
|
|
935
|
-
|
|
1755
|
+
pass.setBindGroup( cameraIndex.index, cameraData.indexesGPU[ i ] );
|
|
1756
|
+
sets.bindingGroups[ cameraIndex.index ] = cameraIndex.id;
|
|
936
1757
|
|
|
937
|
-
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
draw( pass, sets );
|
|
938
1761
|
|
|
939
|
-
}
|
|
940
1762
|
|
|
941
|
-
|
|
1763
|
+
}
|
|
942
1764
|
|
|
943
|
-
|
|
1765
|
+
}
|
|
944
1766
|
|
|
945
|
-
|
|
946
|
-
const counts = object._multiDrawCounts;
|
|
947
|
-
const drawCount = object._multiDrawCount;
|
|
948
|
-
const drawInstances = object._multiDrawInstances;
|
|
1767
|
+
} else {
|
|
949
1768
|
|
|
950
|
-
|
|
1769
|
+
// Regular single camera rendering
|
|
1770
|
+
if ( renderContextData.currentPass ) {
|
|
951
1771
|
|
|
952
|
-
|
|
1772
|
+
// Handle occlusion queries
|
|
1773
|
+
if ( renderContextData.occlusionQuerySet !== undefined ) {
|
|
953
1774
|
|
|
954
|
-
|
|
955
|
-
|
|
1775
|
+
const lastObject = renderContextData.lastOcclusionObject;
|
|
1776
|
+
if ( lastObject !== object ) {
|
|
956
1777
|
|
|
957
|
-
|
|
1778
|
+
if ( lastObject !== null && lastObject.occlusionTest === true ) {
|
|
958
1779
|
|
|
959
|
-
|
|
1780
|
+
renderContextData.currentPass.endOcclusionQuery();
|
|
1781
|
+
renderContextData.occlusionQueryIndex ++;
|
|
960
1782
|
|
|
961
|
-
|
|
1783
|
+
}
|
|
962
1784
|
|
|
963
|
-
|
|
1785
|
+
if ( object.occlusionTest === true ) {
|
|
964
1786
|
|
|
965
|
-
|
|
1787
|
+
renderContextData.currentPass.beginOcclusionQuery( renderContextData.occlusionQueryIndex );
|
|
1788
|
+
renderContextData.occlusionQueryObjects[ renderContextData.occlusionQueryIndex ] = object;
|
|
966
1789
|
|
|
967
|
-
|
|
1790
|
+
}
|
|
968
1791
|
|
|
969
|
-
|
|
1792
|
+
renderContextData.lastOcclusionObject = object;
|
|
1793
|
+
|
|
1794
|
+
}
|
|
970
1795
|
|
|
971
|
-
|
|
1796
|
+
}
|
|
972
1797
|
|
|
973
|
-
|
|
1798
|
+
draw( renderContextData.currentPass, renderContextData.currentSets );
|
|
974
1799
|
|
|
975
|
-
|
|
1800
|
+
}
|
|
976
1801
|
|
|
977
1802
|
}
|
|
978
1803
|
|
|
@@ -980,6 +1805,12 @@ class WebGPUBackend extends Backend {
|
|
|
980
1805
|
|
|
981
1806
|
// cache key
|
|
982
1807
|
|
|
1808
|
+
/**
|
|
1809
|
+
* Returns `true` if the render pipeline requires an update.
|
|
1810
|
+
*
|
|
1811
|
+
* @param {RenderObject} renderObject - The render object.
|
|
1812
|
+
* @return {boolean} Whether the render pipeline requires an update or not.
|
|
1813
|
+
*/
|
|
983
1814
|
needsRenderUpdate( renderObject ) {
|
|
984
1815
|
|
|
985
1816
|
const data = this.get( renderObject );
|
|
@@ -1008,7 +1839,7 @@ class WebGPUBackend extends Backend {
|
|
|
1008
1839
|
data.sampleCount !== sampleCount || data.colorSpace !== colorSpace ||
|
|
1009
1840
|
data.colorFormat !== colorFormat || data.depthStencilFormat !== depthStencilFormat ||
|
|
1010
1841
|
data.primitiveTopology !== primitiveTopology ||
|
|
1011
|
-
data.clippingContextCacheKey !== renderObject.
|
|
1842
|
+
data.clippingContextCacheKey !== renderObject.clippingContextCacheKey
|
|
1012
1843
|
) {
|
|
1013
1844
|
|
|
1014
1845
|
data.material = material; data.materialVersion = material.version;
|
|
@@ -1026,7 +1857,7 @@ class WebGPUBackend extends Backend {
|
|
|
1026
1857
|
data.colorFormat = colorFormat;
|
|
1027
1858
|
data.depthStencilFormat = depthStencilFormat;
|
|
1028
1859
|
data.primitiveTopology = primitiveTopology;
|
|
1029
|
-
data.clippingContextCacheKey = renderObject.
|
|
1860
|
+
data.clippingContextCacheKey = renderObject.clippingContextCacheKey;
|
|
1030
1861
|
|
|
1031
1862
|
needsUpdate = true;
|
|
1032
1863
|
|
|
@@ -1036,6 +1867,12 @@ class WebGPUBackend extends Backend {
|
|
|
1036
1867
|
|
|
1037
1868
|
}
|
|
1038
1869
|
|
|
1870
|
+
/**
|
|
1871
|
+
* Returns a cache key that is used to identify render pipelines.
|
|
1872
|
+
*
|
|
1873
|
+
* @param {RenderObject} renderObject - The render object.
|
|
1874
|
+
* @return {string} The cache key.
|
|
1875
|
+
*/
|
|
1039
1876
|
getRenderCacheKey( renderObject ) {
|
|
1040
1877
|
|
|
1041
1878
|
const { object, material } = renderObject;
|
|
@@ -1043,6 +1880,11 @@ class WebGPUBackend extends Backend {
|
|
|
1043
1880
|
const utils = this.utils;
|
|
1044
1881
|
const renderContext = renderObject.context;
|
|
1045
1882
|
|
|
1883
|
+
// meshes with negative scale have a different frontFace render pipeline
|
|
1884
|
+
// descriptor value so the following must be honored in the cache key
|
|
1885
|
+
|
|
1886
|
+
const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
|
|
1887
|
+
|
|
1046
1888
|
return [
|
|
1047
1889
|
material.transparent, material.blending, material.premultipliedAlpha,
|
|
1048
1890
|
material.blendSrc, material.blendDst, material.blendEquation,
|
|
@@ -1053,163 +1895,148 @@ class WebGPUBackend extends Backend {
|
|
|
1053
1895
|
material.stencilFail, material.stencilZFail, material.stencilZPass,
|
|
1054
1896
|
material.stencilFuncMask, material.stencilWriteMask,
|
|
1055
1897
|
material.side,
|
|
1898
|
+
frontFaceCW,
|
|
1056
1899
|
utils.getSampleCountRenderContext( renderContext ),
|
|
1057
1900
|
utils.getCurrentColorSpace( renderContext ), utils.getCurrentColorFormat( renderContext ), utils.getCurrentDepthStencilFormat( renderContext ),
|
|
1058
1901
|
utils.getPrimitiveTopology( object, material ),
|
|
1059
|
-
renderObject.
|
|
1902
|
+
renderObject.getGeometryCacheKey(),
|
|
1903
|
+
renderObject.clippingContextCacheKey
|
|
1060
1904
|
].join();
|
|
1061
1905
|
|
|
1062
1906
|
}
|
|
1063
1907
|
|
|
1064
1908
|
// textures
|
|
1065
1909
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1910
|
+
/**
|
|
1911
|
+
* Updates a GPU sampler for the given texture.
|
|
1912
|
+
*
|
|
1913
|
+
* @param {Texture} texture - The texture to update the sampler for.
|
|
1914
|
+
* @return {string} The current sampler key.
|
|
1915
|
+
*/
|
|
1916
|
+
updateSampler( texture ) {
|
|
1069
1917
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
destroySampler( texture ) {
|
|
1073
|
-
|
|
1074
|
-
this.textureUtils.destroySampler( texture );
|
|
1918
|
+
return this.textureUtils.updateSampler( texture );
|
|
1075
1919
|
|
|
1076
1920
|
}
|
|
1077
1921
|
|
|
1922
|
+
/**
|
|
1923
|
+
* Creates a default texture for the given texture that can be used
|
|
1924
|
+
* as a placeholder until the actual texture is ready for usage.
|
|
1925
|
+
*
|
|
1926
|
+
* @param {Texture} texture - The texture to create a default texture for.
|
|
1927
|
+
* @return {boolean} Whether the sampler has been updated or not.
|
|
1928
|
+
*/
|
|
1078
1929
|
createDefaultTexture( texture ) {
|
|
1079
1930
|
|
|
1080
|
-
this.textureUtils.createDefaultTexture( texture );
|
|
1931
|
+
return this.textureUtils.createDefaultTexture( texture );
|
|
1081
1932
|
|
|
1082
1933
|
}
|
|
1083
1934
|
|
|
1935
|
+
/**
|
|
1936
|
+
* Defines a texture on the GPU for the given texture object.
|
|
1937
|
+
*
|
|
1938
|
+
* @param {Texture} texture - The texture.
|
|
1939
|
+
* @param {Object} [options={}] - Optional configuration parameter.
|
|
1940
|
+
*/
|
|
1084
1941
|
createTexture( texture, options ) {
|
|
1085
1942
|
|
|
1086
1943
|
this.textureUtils.createTexture( texture, options );
|
|
1087
1944
|
|
|
1088
1945
|
}
|
|
1089
1946
|
|
|
1947
|
+
/**
|
|
1948
|
+
* Uploads the updated texture data to the GPU.
|
|
1949
|
+
*
|
|
1950
|
+
* @param {Texture} texture - The texture.
|
|
1951
|
+
* @param {Object} [options={}] - Optional configuration parameter.
|
|
1952
|
+
*/
|
|
1090
1953
|
updateTexture( texture, options ) {
|
|
1091
1954
|
|
|
1092
1955
|
this.textureUtils.updateTexture( texture, options );
|
|
1093
1956
|
|
|
1094
1957
|
}
|
|
1095
1958
|
|
|
1959
|
+
/**
|
|
1960
|
+
* Generates mipmaps for the given texture.
|
|
1961
|
+
*
|
|
1962
|
+
* @param {Texture} texture - The texture.
|
|
1963
|
+
*/
|
|
1096
1964
|
generateMipmaps( texture ) {
|
|
1097
1965
|
|
|
1098
1966
|
this.textureUtils.generateMipmaps( texture );
|
|
1099
1967
|
|
|
1100
1968
|
}
|
|
1101
1969
|
|
|
1102
|
-
|
|
1970
|
+
/**
|
|
1971
|
+
* Destroys the GPU data for the given texture object.
|
|
1972
|
+
*
|
|
1973
|
+
* @param {Texture} texture - The texture.
|
|
1974
|
+
* @param {boolean} [isDefaultTexture=false] - Whether the texture uses a default GPU texture or not.
|
|
1975
|
+
*/
|
|
1976
|
+
destroyTexture( texture, isDefaultTexture = false ) {
|
|
1103
1977
|
|
|
1104
|
-
this.textureUtils.destroyTexture( texture );
|
|
1978
|
+
this.textureUtils.destroyTexture( texture, isDefaultTexture );
|
|
1105
1979
|
|
|
1106
1980
|
}
|
|
1107
1981
|
|
|
1108
|
-
|
|
1982
|
+
/**
|
|
1983
|
+
* Returns texture data as a typed array.
|
|
1984
|
+
*
|
|
1985
|
+
* @async
|
|
1986
|
+
* @param {Texture} texture - The texture to copy.
|
|
1987
|
+
* @param {number} x - The x coordinate of the copy origin.
|
|
1988
|
+
* @param {number} y - The y coordinate of the copy origin.
|
|
1989
|
+
* @param {number} width - The width of the copy.
|
|
1990
|
+
* @param {number} height - The height of the copy.
|
|
1991
|
+
* @param {number} faceIndex - The face index.
|
|
1992
|
+
* @return {Promise<TypedArray>} A Promise that resolves with a typed array when the copy operation has finished.
|
|
1993
|
+
*/
|
|
1994
|
+
async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
|
|
1109
1995
|
|
|
1110
1996
|
return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height, faceIndex );
|
|
1111
1997
|
|
|
1112
1998
|
}
|
|
1113
1999
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
// Create a GPUQuerySet which holds 2 timestamp query results: one for the
|
|
1124
|
-
// beginning and one for the end of compute pass execution.
|
|
1125
|
-
const timeStampQuerySet = this.device.createQuerySet( { type: 'timestamp', count: 2 } );
|
|
1126
|
-
|
|
1127
|
-
const timestampWrites = {
|
|
1128
|
-
querySet: timeStampQuerySet,
|
|
1129
|
-
beginningOfPassWriteIndex: 0, // Write timestamp in index 0 when pass begins.
|
|
1130
|
-
endOfPassWriteIndex: 1, // Write timestamp in index 1 when pass ends.
|
|
1131
|
-
};
|
|
1132
|
-
|
|
1133
|
-
Object.assign( descriptor, {
|
|
1134
|
-
timestampWrites,
|
|
1135
|
-
} );
|
|
1136
|
-
|
|
1137
|
-
renderContextData.timeStampQuerySet = timeStampQuerySet;
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// timestamp utils
|
|
1144
|
-
|
|
1145
|
-
prepareTimestampBuffer( renderContext, encoder ) {
|
|
2000
|
+
/**
|
|
2001
|
+
* Inits a time stamp query for the given render context.
|
|
2002
|
+
*
|
|
2003
|
+
* @param {string} type - The type of the timestamp query (e.g. 'render', 'compute').
|
|
2004
|
+
* @param {number} uid - Unique id for the context (e.g. render context id).
|
|
2005
|
+
* @param {Object} descriptor - The query descriptor.
|
|
2006
|
+
*/
|
|
2007
|
+
initTimestampQuery( type, uid, descriptor ) {
|
|
1146
2008
|
|
|
1147
2009
|
if ( ! this.trackTimestamp ) return;
|
|
1148
2010
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
const size = 2 * BigInt64Array.BYTES_PER_ELEMENT;
|
|
2011
|
+
if ( ! this.timestampQueryPool[ type ] ) {
|
|
1153
2012
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
renderContextData.currentTimestampQueryBuffers = {
|
|
1157
|
-
resolveBuffer: this.device.createBuffer( {
|
|
1158
|
-
label: 'timestamp resolve buffer',
|
|
1159
|
-
size: size,
|
|
1160
|
-
usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC,
|
|
1161
|
-
} ),
|
|
1162
|
-
resultBuffer: this.device.createBuffer( {
|
|
1163
|
-
label: 'timestamp result buffer',
|
|
1164
|
-
size: size,
|
|
1165
|
-
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
|
|
1166
|
-
} ),
|
|
1167
|
-
isMappingPending: false,
|
|
1168
|
-
};
|
|
2013
|
+
// TODO: Variable maxQueries?
|
|
2014
|
+
this.timestampQueryPool[ type ] = new WebGPUTimestampQueryPool( this.device, type, 2048 );
|
|
1169
2015
|
|
|
1170
2016
|
}
|
|
1171
2017
|
|
|
1172
|
-
const
|
|
2018
|
+
const timestampQueryPool = this.timestampQueryPool[ type ];
|
|
1173
2019
|
|
|
1174
|
-
|
|
2020
|
+
const baseOffset = timestampQueryPool.allocateQueriesForContext( uid );
|
|
1175
2021
|
|
|
1176
|
-
|
|
1177
|
-
|
|
2022
|
+
descriptor.timestampWrites = {
|
|
2023
|
+
querySet: timestampQueryPool.querySet,
|
|
2024
|
+
beginningOfPassWriteIndex: baseOffset,
|
|
2025
|
+
endOfPassWriteIndex: baseOffset + 1,
|
|
2026
|
+
};
|
|
1178
2027
|
|
|
1179
2028
|
}
|
|
1180
2029
|
|
|
1181
|
-
async resolveTimestampAsync( renderContext, type = 'render' ) {
|
|
1182
|
-
|
|
1183
|
-
if ( ! this.trackTimestamp ) return;
|
|
1184
|
-
|
|
1185
|
-
const renderContextData = this.get( renderContext );
|
|
1186
|
-
|
|
1187
|
-
if ( renderContextData.currentTimestampQueryBuffers === undefined ) return;
|
|
1188
|
-
|
|
1189
|
-
const { resultBuffer, isMappingPending } = renderContextData.currentTimestampQueryBuffers;
|
|
1190
|
-
|
|
1191
|
-
if ( isMappingPending === true ) return;
|
|
1192
|
-
|
|
1193
|
-
renderContextData.currentTimestampQueryBuffers.isMappingPending = true;
|
|
1194
|
-
|
|
1195
|
-
resultBuffer.mapAsync( GPUMapMode.READ ).then( () => {
|
|
1196
|
-
|
|
1197
|
-
const times = new BigUint64Array( resultBuffer.getMappedRange() );
|
|
1198
|
-
const duration = Number( times[ 1 ] - times[ 0 ] ) / 1000000;
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
this.renderer.info.updateTimestamp( type, duration );
|
|
1202
|
-
|
|
1203
|
-
resultBuffer.unmap();
|
|
1204
|
-
|
|
1205
|
-
renderContextData.currentTimestampQueryBuffers.isMappingPending = false;
|
|
1206
|
-
|
|
1207
|
-
} );
|
|
1208
|
-
|
|
1209
|
-
}
|
|
1210
2030
|
|
|
1211
2031
|
// node builder
|
|
1212
2032
|
|
|
2033
|
+
/**
|
|
2034
|
+
* Returns a node builder for the given render object.
|
|
2035
|
+
*
|
|
2036
|
+
* @param {RenderObject} object - The render object.
|
|
2037
|
+
* @param {Renderer} renderer - The renderer.
|
|
2038
|
+
* @return {WGSLNodeBuilder} The node builder.
|
|
2039
|
+
*/
|
|
1213
2040
|
createNodeBuilder( object, renderer ) {
|
|
1214
2041
|
|
|
1215
2042
|
return new WGSLNodeBuilder( object, renderer );
|
|
@@ -1218,17 +2045,27 @@ class WebGPUBackend extends Backend {
|
|
|
1218
2045
|
|
|
1219
2046
|
// program
|
|
1220
2047
|
|
|
2048
|
+
/**
|
|
2049
|
+
* Creates a shader program from the given programmable stage.
|
|
2050
|
+
*
|
|
2051
|
+
* @param {ProgrammableStage} program - The programmable stage.
|
|
2052
|
+
*/
|
|
1221
2053
|
createProgram( program ) {
|
|
1222
2054
|
|
|
1223
2055
|
const programGPU = this.get( program );
|
|
1224
2056
|
|
|
1225
2057
|
programGPU.module = {
|
|
1226
|
-
module: this.device.createShaderModule( { code: program.code, label: program.stage } ),
|
|
2058
|
+
module: this.device.createShaderModule( { code: program.code, label: program.stage + ( program.name !== '' ? `_${ program.name }` : '' ) } ),
|
|
1227
2059
|
entryPoint: 'main'
|
|
1228
2060
|
};
|
|
1229
2061
|
|
|
1230
2062
|
}
|
|
1231
2063
|
|
|
2064
|
+
/**
|
|
2065
|
+
* Destroys the shader program of the given programmable stage.
|
|
2066
|
+
*
|
|
2067
|
+
* @param {ProgrammableStage} program - The programmable stage.
|
|
2068
|
+
*/
|
|
1232
2069
|
destroyProgram( program ) {
|
|
1233
2070
|
|
|
1234
2071
|
this.delete( program );
|
|
@@ -1237,18 +2074,35 @@ class WebGPUBackend extends Backend {
|
|
|
1237
2074
|
|
|
1238
2075
|
// pipelines
|
|
1239
2076
|
|
|
2077
|
+
/**
|
|
2078
|
+
* Creates a render pipeline for the given render object.
|
|
2079
|
+
*
|
|
2080
|
+
* @param {RenderObject} renderObject - The render object.
|
|
2081
|
+
* @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
|
|
2082
|
+
*/
|
|
1240
2083
|
createRenderPipeline( renderObject, promises ) {
|
|
1241
2084
|
|
|
1242
2085
|
this.pipelineUtils.createRenderPipeline( renderObject, promises );
|
|
1243
2086
|
|
|
1244
2087
|
}
|
|
1245
2088
|
|
|
2089
|
+
/**
|
|
2090
|
+
* Creates a compute pipeline for the given compute node.
|
|
2091
|
+
*
|
|
2092
|
+
* @param {ComputePipeline} computePipeline - The compute pipeline.
|
|
2093
|
+
* @param {Array<BindGroup>} bindings - The bindings.
|
|
2094
|
+
*/
|
|
1246
2095
|
createComputePipeline( computePipeline, bindings ) {
|
|
1247
2096
|
|
|
1248
2097
|
this.pipelineUtils.createComputePipeline( computePipeline, bindings );
|
|
1249
2098
|
|
|
1250
2099
|
}
|
|
1251
2100
|
|
|
2101
|
+
/**
|
|
2102
|
+
* Prepares the state for encoding render bundles.
|
|
2103
|
+
*
|
|
2104
|
+
* @param {RenderContext} renderContext - The render context.
|
|
2105
|
+
*/
|
|
1252
2106
|
beginBundle( renderContext ) {
|
|
1253
2107
|
|
|
1254
2108
|
const renderContextData = this.get( renderContext );
|
|
@@ -1261,6 +2115,12 @@ class WebGPUBackend extends Backend {
|
|
|
1261
2115
|
|
|
1262
2116
|
}
|
|
1263
2117
|
|
|
2118
|
+
/**
|
|
2119
|
+
* After processing render bundles this method finalizes related work.
|
|
2120
|
+
*
|
|
2121
|
+
* @param {RenderContext} renderContext - The render context.
|
|
2122
|
+
* @param {RenderBundle} bundle - The render bundle.
|
|
2123
|
+
*/
|
|
1264
2124
|
finishBundle( renderContext, bundle ) {
|
|
1265
2125
|
|
|
1266
2126
|
const renderContextData = this.get( renderContext );
|
|
@@ -1277,6 +2137,12 @@ class WebGPUBackend extends Backend {
|
|
|
1277
2137
|
|
|
1278
2138
|
}
|
|
1279
2139
|
|
|
2140
|
+
/**
|
|
2141
|
+
* Adds a render bundle to the render context data.
|
|
2142
|
+
*
|
|
2143
|
+
* @param {RenderContext} renderContext - The render context.
|
|
2144
|
+
* @param {RenderBundle} bundle - The render bundle to add.
|
|
2145
|
+
*/
|
|
1280
2146
|
addBundle( renderContext, bundle ) {
|
|
1281
2147
|
|
|
1282
2148
|
const renderContextData = this.get( renderContext );
|
|
@@ -1287,50 +2153,126 @@ class WebGPUBackend extends Backend {
|
|
|
1287
2153
|
|
|
1288
2154
|
// bindings
|
|
1289
2155
|
|
|
1290
|
-
|
|
2156
|
+
/**
|
|
2157
|
+
* Creates bindings from the given bind group definition.
|
|
2158
|
+
*
|
|
2159
|
+
* @param {BindGroup} bindGroup - The bind group.
|
|
2160
|
+
* @param {Array<BindGroup>} bindings - Array of bind groups.
|
|
2161
|
+
* @param {number} cacheIndex - The cache index.
|
|
2162
|
+
* @param {number} version - The version.
|
|
2163
|
+
*/
|
|
2164
|
+
createBindings( bindGroup, bindings, cacheIndex, version ) {
|
|
1291
2165
|
|
|
1292
|
-
this.bindingUtils.createBindings( bindGroup );
|
|
2166
|
+
this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version );
|
|
1293
2167
|
|
|
1294
2168
|
}
|
|
1295
2169
|
|
|
1296
|
-
|
|
2170
|
+
/**
|
|
2171
|
+
* Updates the given bind group definition.
|
|
2172
|
+
*
|
|
2173
|
+
* @param {BindGroup} bindGroup - The bind group.
|
|
2174
|
+
* @param {Array<BindGroup>} bindings - Array of bind groups.
|
|
2175
|
+
* @param {number} cacheIndex - The cache index.
|
|
2176
|
+
* @param {number} version - The version.
|
|
2177
|
+
*/
|
|
2178
|
+
updateBindings( bindGroup, bindings, cacheIndex, version ) {
|
|
1297
2179
|
|
|
1298
|
-
this.bindingUtils.createBindings( bindGroup );
|
|
2180
|
+
this.bindingUtils.createBindings( bindGroup, bindings, cacheIndex, version );
|
|
1299
2181
|
|
|
1300
2182
|
}
|
|
1301
2183
|
|
|
2184
|
+
/**
|
|
2185
|
+
* Updates a buffer binding.
|
|
2186
|
+
*
|
|
2187
|
+
* @param {Buffer} binding - The buffer binding to update.
|
|
2188
|
+
*/
|
|
1302
2189
|
updateBinding( binding ) {
|
|
1303
2190
|
|
|
1304
2191
|
this.bindingUtils.updateBinding( binding );
|
|
1305
2192
|
|
|
1306
2193
|
}
|
|
1307
2194
|
|
|
2195
|
+
/**
|
|
2196
|
+
* Delete data associated with the current bind group.
|
|
2197
|
+
*
|
|
2198
|
+
* @param {BindGroup} bindGroup - The bind group.
|
|
2199
|
+
*/
|
|
2200
|
+
deleteBindGroupData( bindGroup ) {
|
|
2201
|
+
|
|
2202
|
+
this.bindingUtils.deleteBindGroupData( bindGroup );
|
|
2203
|
+
|
|
2204
|
+
}
|
|
2205
|
+
|
|
1308
2206
|
// attributes
|
|
1309
2207
|
|
|
2208
|
+
/**
|
|
2209
|
+
* Creates the buffer of an indexed shader attribute.
|
|
2210
|
+
*
|
|
2211
|
+
* @param {BufferAttribute} attribute - The indexed buffer attribute.
|
|
2212
|
+
*/
|
|
1310
2213
|
createIndexAttribute( attribute ) {
|
|
1311
2214
|
|
|
1312
|
-
|
|
2215
|
+
let usage = GPUBufferUsage.INDEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST;
|
|
2216
|
+
|
|
2217
|
+
if ( attribute.isStorageBufferAttribute || attribute.isStorageInstancedBufferAttribute ) {
|
|
2218
|
+
|
|
2219
|
+
usage |= GPUBufferUsage.STORAGE;
|
|
2220
|
+
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
this.attributeUtils.createAttribute( attribute, usage );
|
|
1313
2224
|
|
|
1314
2225
|
}
|
|
1315
2226
|
|
|
2227
|
+
/**
|
|
2228
|
+
* Creates the GPU buffer of a shader attribute.
|
|
2229
|
+
*
|
|
2230
|
+
* @param {BufferAttribute} attribute - The buffer attribute.
|
|
2231
|
+
*/
|
|
1316
2232
|
createAttribute( attribute ) {
|
|
1317
2233
|
|
|
1318
2234
|
this.attributeUtils.createAttribute( attribute, GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
|
|
1319
2235
|
|
|
1320
2236
|
}
|
|
1321
2237
|
|
|
2238
|
+
/**
|
|
2239
|
+
* Creates the GPU buffer of a storage attribute.
|
|
2240
|
+
*
|
|
2241
|
+
* @param {BufferAttribute} attribute - The buffer attribute.
|
|
2242
|
+
*/
|
|
1322
2243
|
createStorageAttribute( attribute ) {
|
|
1323
2244
|
|
|
1324
2245
|
this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
|
|
1325
2246
|
|
|
1326
2247
|
}
|
|
1327
2248
|
|
|
2249
|
+
/**
|
|
2250
|
+
* Creates the GPU buffer of an indirect storage attribute.
|
|
2251
|
+
*
|
|
2252
|
+
* @param {BufferAttribute} attribute - The buffer attribute.
|
|
2253
|
+
*/
|
|
2254
|
+
createIndirectStorageAttribute( attribute ) {
|
|
2255
|
+
|
|
2256
|
+
this.attributeUtils.createAttribute( attribute, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST );
|
|
2257
|
+
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
/**
|
|
2261
|
+
* Updates the GPU buffer of a shader attribute.
|
|
2262
|
+
*
|
|
2263
|
+
* @param {BufferAttribute} attribute - The buffer attribute to update.
|
|
2264
|
+
*/
|
|
1328
2265
|
updateAttribute( attribute ) {
|
|
1329
2266
|
|
|
1330
2267
|
this.attributeUtils.updateAttribute( attribute );
|
|
1331
2268
|
|
|
1332
2269
|
}
|
|
1333
2270
|
|
|
2271
|
+
/**
|
|
2272
|
+
* Destroys the GPU buffer of a shader attribute.
|
|
2273
|
+
*
|
|
2274
|
+
* @param {BufferAttribute} attribute - The buffer attribute to destroy.
|
|
2275
|
+
*/
|
|
1334
2276
|
destroyAttribute( attribute ) {
|
|
1335
2277
|
|
|
1336
2278
|
this.attributeUtils.destroyAttribute( attribute );
|
|
@@ -1339,55 +2281,97 @@ class WebGPUBackend extends Backend {
|
|
|
1339
2281
|
|
|
1340
2282
|
// canvas
|
|
1341
2283
|
|
|
2284
|
+
/**
|
|
2285
|
+
* Triggers an update of the default render pass descriptor.
|
|
2286
|
+
*/
|
|
1342
2287
|
updateSize() {
|
|
1343
2288
|
|
|
1344
|
-
this.
|
|
1345
|
-
this.defaultRenderPassdescriptor = null;
|
|
2289
|
+
this.delete( this.renderer.getCanvasTarget() );
|
|
1346
2290
|
|
|
1347
2291
|
}
|
|
1348
2292
|
|
|
1349
2293
|
// utils public
|
|
1350
2294
|
|
|
2295
|
+
/**
|
|
2296
|
+
* Returns the maximum anisotropy texture filtering value.
|
|
2297
|
+
*
|
|
2298
|
+
* @return {number} The maximum anisotropy texture filtering value.
|
|
2299
|
+
*/
|
|
1351
2300
|
getMaxAnisotropy() {
|
|
1352
2301
|
|
|
1353
2302
|
return 16;
|
|
1354
2303
|
|
|
1355
2304
|
}
|
|
1356
2305
|
|
|
2306
|
+
/**
|
|
2307
|
+
* Checks if the given feature is supported by the backend.
|
|
2308
|
+
*
|
|
2309
|
+
* @param {string} name - The feature's name.
|
|
2310
|
+
* @return {boolean} Whether the feature is supported or not.
|
|
2311
|
+
*/
|
|
1357
2312
|
hasFeature( name ) {
|
|
1358
2313
|
|
|
2314
|
+
if ( GPUFeatureMap[ name ] !== undefined ) name = GPUFeatureMap[ name ];
|
|
2315
|
+
|
|
1359
2316
|
return this.device.features.has( name );
|
|
1360
2317
|
|
|
1361
2318
|
}
|
|
1362
2319
|
|
|
1363
|
-
|
|
2320
|
+
/**
|
|
2321
|
+
* Copies data of the given source texture to the given destination texture.
|
|
2322
|
+
*
|
|
2323
|
+
* @param {Texture} srcTexture - The source texture.
|
|
2324
|
+
* @param {Texture} dstTexture - The destination texture.
|
|
2325
|
+
* @param {?(Box3|Box2)} [srcRegion=null] - The region of the source texture to copy.
|
|
2326
|
+
* @param {?(Vector2|Vector3)} [dstPosition=null] - The destination position of the copy.
|
|
2327
|
+
* @param {number} [srcLevel=0] - The mipmap level to copy.
|
|
2328
|
+
* @param {number} [dstLevel=0] - The destination mip level to copy to.
|
|
2329
|
+
*/
|
|
2330
|
+
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0 ) {
|
|
1364
2331
|
|
|
1365
2332
|
let dstX = 0;
|
|
1366
2333
|
let dstY = 0;
|
|
1367
|
-
let
|
|
2334
|
+
let dstZ = 0;
|
|
1368
2335
|
|
|
1369
2336
|
let srcX = 0;
|
|
1370
2337
|
let srcY = 0;
|
|
1371
|
-
let
|
|
2338
|
+
let srcZ = 0;
|
|
1372
2339
|
|
|
1373
2340
|
let srcWidth = srcTexture.image.width;
|
|
1374
2341
|
let srcHeight = srcTexture.image.height;
|
|
2342
|
+
let srcDepth = 1;
|
|
2343
|
+
|
|
1375
2344
|
|
|
1376
2345
|
if ( srcRegion !== null ) {
|
|
1377
2346
|
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
2347
|
+
if ( srcRegion.isBox3 === true ) {
|
|
2348
|
+
|
|
2349
|
+
srcX = srcRegion.min.x;
|
|
2350
|
+
srcY = srcRegion.min.y;
|
|
2351
|
+
srcZ = srcRegion.min.z;
|
|
2352
|
+
srcWidth = srcRegion.max.x - srcRegion.min.x;
|
|
2353
|
+
srcHeight = srcRegion.max.y - srcRegion.min.y;
|
|
2354
|
+
srcDepth = srcRegion.max.z - srcRegion.min.z;
|
|
2355
|
+
|
|
2356
|
+
} else {
|
|
2357
|
+
|
|
2358
|
+
// Assume it's a Box2
|
|
2359
|
+
srcX = srcRegion.min.x;
|
|
2360
|
+
srcY = srcRegion.min.y;
|
|
2361
|
+
srcWidth = srcRegion.max.x - srcRegion.min.x;
|
|
2362
|
+
srcHeight = srcRegion.max.y - srcRegion.min.y;
|
|
2363
|
+
srcDepth = 1;
|
|
2364
|
+
|
|
2365
|
+
}
|
|
1383
2366
|
|
|
1384
2367
|
}
|
|
1385
2368
|
|
|
2369
|
+
|
|
1386
2370
|
if ( dstPosition !== null ) {
|
|
1387
2371
|
|
|
1388
2372
|
dstX = dstPosition.x;
|
|
1389
2373
|
dstY = dstPosition.y;
|
|
1390
|
-
|
|
2374
|
+
dstZ = dstPosition.z || 0;
|
|
1391
2375
|
|
|
1392
2376
|
}
|
|
1393
2377
|
|
|
@@ -1399,31 +2383,42 @@ class WebGPUBackend extends Backend {
|
|
|
1399
2383
|
encoder.copyTextureToTexture(
|
|
1400
2384
|
{
|
|
1401
2385
|
texture: sourceGPU,
|
|
1402
|
-
mipLevel:
|
|
1403
|
-
origin: { x: srcX, y: srcY, z:
|
|
2386
|
+
mipLevel: srcLevel,
|
|
2387
|
+
origin: { x: srcX, y: srcY, z: srcZ }
|
|
1404
2388
|
},
|
|
1405
2389
|
{
|
|
1406
2390
|
texture: destinationGPU,
|
|
1407
|
-
mipLevel:
|
|
1408
|
-
origin: { x: dstX, y: dstY, z:
|
|
2391
|
+
mipLevel: dstLevel,
|
|
2392
|
+
origin: { x: dstX, y: dstY, z: dstZ }
|
|
1409
2393
|
},
|
|
1410
2394
|
[
|
|
1411
2395
|
srcWidth,
|
|
1412
2396
|
srcHeight,
|
|
1413
|
-
|
|
2397
|
+
srcDepth
|
|
1414
2398
|
]
|
|
1415
2399
|
);
|
|
1416
2400
|
|
|
1417
2401
|
this.device.queue.submit( [ encoder.finish() ] );
|
|
1418
2402
|
|
|
2403
|
+
if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
|
|
2404
|
+
|
|
2405
|
+
this.textureUtils.generateMipmaps( dstTexture );
|
|
2406
|
+
|
|
2407
|
+
}
|
|
2408
|
+
|
|
1419
2409
|
}
|
|
1420
2410
|
|
|
2411
|
+
/**
|
|
2412
|
+
* Copies the current bound framebuffer to the given texture.
|
|
2413
|
+
*
|
|
2414
|
+
* @param {Texture} texture - The destination texture.
|
|
2415
|
+
* @param {RenderContext} renderContext - The render context.
|
|
2416
|
+
* @param {Vector4} rectangle - A four dimensional vector defining the origin and dimension of the copy.
|
|
2417
|
+
*/
|
|
1421
2418
|
copyFramebufferToTexture( texture, renderContext, rectangle ) {
|
|
1422
2419
|
|
|
1423
2420
|
const renderContextData = this.get( renderContext );
|
|
1424
2421
|
|
|
1425
|
-
const { encoder, descriptor } = renderContextData;
|
|
1426
|
-
|
|
1427
2422
|
let sourceGPU = null;
|
|
1428
2423
|
|
|
1429
2424
|
if ( renderContext.renderTarget ) {
|
|
@@ -1456,18 +2451,30 @@ class WebGPUBackend extends Backend {
|
|
|
1456
2451
|
|
|
1457
2452
|
if ( sourceGPU.format !== destinationGPU.format ) {
|
|
1458
2453
|
|
|
1459
|
-
|
|
2454
|
+
error( 'WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.', sourceGPU.format, destinationGPU.format );
|
|
1460
2455
|
|
|
1461
2456
|
return;
|
|
1462
2457
|
|
|
1463
2458
|
}
|
|
1464
2459
|
|
|
1465
|
-
|
|
2460
|
+
let encoder;
|
|
2461
|
+
|
|
2462
|
+
if ( renderContextData.currentPass ) {
|
|
2463
|
+
|
|
2464
|
+
renderContextData.currentPass.end();
|
|
2465
|
+
|
|
2466
|
+
encoder = renderContextData.encoder;
|
|
2467
|
+
|
|
2468
|
+
} else {
|
|
2469
|
+
|
|
2470
|
+
encoder = this.device.createCommandEncoder( { label: 'copyFramebufferToTexture_' + texture.id } );
|
|
2471
|
+
|
|
2472
|
+
}
|
|
1466
2473
|
|
|
1467
2474
|
encoder.copyTextureToTexture(
|
|
1468
2475
|
{
|
|
1469
2476
|
texture: sourceGPU,
|
|
1470
|
-
origin:
|
|
2477
|
+
origin: [ rectangle.x, rectangle.y, 0 ],
|
|
1471
2478
|
},
|
|
1472
2479
|
{
|
|
1473
2480
|
texture: destinationGPU
|
|
@@ -1478,19 +2485,101 @@ class WebGPUBackend extends Backend {
|
|
|
1478
2485
|
]
|
|
1479
2486
|
);
|
|
1480
2487
|
|
|
1481
|
-
|
|
2488
|
+
// mipmaps must be genereated with the same encoder otherwise the copied texture data
|
|
2489
|
+
// might be out-of-sync, see #31768
|
|
1482
2490
|
|
|
1483
|
-
|
|
2491
|
+
if ( texture.generateMipmaps ) {
|
|
1484
2492
|
|
|
1485
|
-
|
|
2493
|
+
this.textureUtils.generateMipmaps( texture, encoder );
|
|
1486
2494
|
|
|
1487
2495
|
}
|
|
1488
2496
|
|
|
1489
|
-
if (
|
|
1490
|
-
if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
2497
|
+
if ( renderContextData.currentPass ) {
|
|
1491
2498
|
|
|
1492
|
-
|
|
1493
|
-
|
|
2499
|
+
const { descriptor } = renderContextData;
|
|
2500
|
+
|
|
2501
|
+
for ( let i = 0; i < descriptor.colorAttachments.length; i ++ ) {
|
|
2502
|
+
|
|
2503
|
+
descriptor.colorAttachments[ i ].loadOp = GPULoadOp.Load;
|
|
2504
|
+
|
|
2505
|
+
}
|
|
2506
|
+
|
|
2507
|
+
if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
|
|
2508
|
+
if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
2509
|
+
|
|
2510
|
+
renderContextData.currentPass = encoder.beginRenderPass( descriptor );
|
|
2511
|
+
renderContextData.currentSets = { attributes: {}, bindingGroups: [], pipeline: null, index: null };
|
|
2512
|
+
|
|
2513
|
+
if ( renderContext.viewport ) {
|
|
2514
|
+
|
|
2515
|
+
this.updateViewport( renderContext );
|
|
2516
|
+
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
if ( renderContext.scissor ) {
|
|
2520
|
+
|
|
2521
|
+
this.updateScissor( renderContext );
|
|
2522
|
+
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
} else {
|
|
2526
|
+
|
|
2527
|
+
this.device.queue.submit( [ encoder.finish() ] );
|
|
2528
|
+
|
|
2529
|
+
}
|
|
2530
|
+
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
/**
|
|
2534
|
+
* Checks if the given compatibility is supported by the backend.
|
|
2535
|
+
*
|
|
2536
|
+
* @param {string} name - The compatibility name.
|
|
2537
|
+
* @return {boolean} Whether the compatibility is supported or not.
|
|
2538
|
+
*/
|
|
2539
|
+
hasCompatibility( name ) {
|
|
2540
|
+
|
|
2541
|
+
if ( this._compatibility[ Compatibility.TEXTURE_COMPARE ] !== undefined ) {
|
|
2542
|
+
|
|
2543
|
+
return this._compatibility[ Compatibility.TEXTURE_COMPARE ];
|
|
2544
|
+
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
return super.hasCompatibility( name );
|
|
2548
|
+
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
dispose() {
|
|
2552
|
+
|
|
2553
|
+
this.bindingUtils.dispose();
|
|
2554
|
+
this.textureUtils.dispose();
|
|
2555
|
+
|
|
2556
|
+
if ( this.occludedResolveCache ) {
|
|
2557
|
+
|
|
2558
|
+
for ( const buffer of this.occludedResolveCache.values() ) {
|
|
2559
|
+
|
|
2560
|
+
buffer.destroy();
|
|
2561
|
+
|
|
2562
|
+
}
|
|
2563
|
+
|
|
2564
|
+
this.occludedResolveCache.clear();
|
|
2565
|
+
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
if ( this.timestampQueryPool ) {
|
|
2569
|
+
|
|
2570
|
+
for ( const queryPool of Object.values( this.timestampQueryPool ) ) {
|
|
2571
|
+
|
|
2572
|
+
if ( queryPool !== null ) queryPool.dispose();
|
|
2573
|
+
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
if ( this.parameters.device === undefined && this.device !== null ) {
|
|
2579
|
+
|
|
2580
|
+
this.device.destroy();
|
|
2581
|
+
|
|
2582
|
+
}
|
|
1494
2583
|
|
|
1495
2584
|
}
|
|
1496
2585
|
|