super-three 0.171.0 → 0.173.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 +1 -1
- package/build/three.cjs +594 -427
- package/build/three.core.js +515 -81
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +79 -350
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +20 -7
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +29362 -3427
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +29361 -3427
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/Addons.js +0 -5
- package/examples/jsm/animation/CCDIKSolver.js +9 -7
- package/examples/jsm/capabilities/WebGPU.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +48 -37
- package/examples/jsm/controls/OrbitControls.js +5 -4
- package/examples/jsm/csm/CSMShadowNode.js +16 -11
- package/examples/jsm/curves/NURBSCurve.js +1 -1
- package/examples/jsm/curves/NURBSUtils.js +3 -0
- package/examples/jsm/effects/OutlineEffect.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +34 -29
- package/examples/jsm/exporters/KTX2Exporter.js +1 -1
- package/examples/jsm/exporters/PLYExporter.js +2 -2
- package/examples/jsm/geometries/TextGeometry.js +1 -12
- package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
- package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
- package/examples/jsm/interactive/InteractiveGroup.js +108 -51
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/lights/LightProbeGenerator.js +3 -3
- package/examples/jsm/lines/webgpu/LineSegments2.js +15 -6
- package/examples/jsm/loaders/3MFLoader.js +6 -3
- package/examples/jsm/loaders/BVHLoader.js +1 -1
- package/examples/jsm/loaders/ColladaLoader.js +5 -5
- package/examples/jsm/loaders/DDSLoader.js +42 -0
- package/examples/jsm/loaders/GCodeLoader.js +4 -2
- package/examples/jsm/loaders/GLTFLoader.js +22 -4
- package/examples/jsm/loaders/KTX2Loader.js +6 -1
- package/examples/jsm/loaders/KTXLoader.js +4 -4
- package/examples/jsm/loaders/LDrawLoader.js +1 -1
- package/examples/jsm/loaders/LottieLoader.js +1 -1
- package/examples/jsm/loaders/MTLLoader.js +1 -0
- package/examples/jsm/loaders/NRRDLoader.js +1 -1
- package/examples/jsm/loaders/PLYLoader.js +7 -7
- package/examples/jsm/loaders/PVRLoader.js +1 -1
- package/examples/jsm/loaders/SVGLoader.js +2 -2
- package/examples/jsm/loaders/TDSLoader.js +1 -2
- package/examples/jsm/loaders/VRMLLoader.js +7 -7
- package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/math/ConvexHull.js +1 -1
- package/examples/jsm/math/OBB.js +17 -0
- package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
- package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +14 -13
- package/examples/jsm/misc/Volume.js +27 -17
- package/examples/jsm/misc/VolumeSlice.js +7 -5
- package/examples/jsm/modifiers/CurveModifier.js +10 -8
- package/examples/jsm/modifiers/CurveModifierGPU.js +9 -7
- package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
- package/examples/jsm/objects/GroundedSkybox.js +4 -4
- package/examples/jsm/objects/Sky.js +2 -2
- package/examples/jsm/objects/SkyMesh.js +3 -3
- package/examples/jsm/objects/Water2.js +1 -1
- package/examples/jsm/objects/Water2Mesh.js +2 -2
- package/examples/jsm/objects/WaterMesh.js +29 -24
- package/examples/jsm/physics/JoltPhysics.js +7 -7
- package/examples/jsm/physics/RapierPhysics.js +4 -4
- package/examples/jsm/postprocessing/BloomPass.js +2 -2
- package/examples/jsm/postprocessing/EffectComposer.js +1 -2
- package/examples/jsm/postprocessing/OutlinePass.js +4 -4
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/postprocessing/SAOPass.js +1 -2
- package/examples/jsm/postprocessing/SMAAPass.js +1 -3
- package/examples/jsm/postprocessing/SSAOPass.js +2 -4
- package/examples/jsm/postprocessing/SSRPass.js +2 -4
- package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
- package/examples/jsm/renderers/SVGRenderer.js +6 -4
- package/examples/jsm/shaders/BokehShader2.js +1 -1
- package/examples/jsm/shaders/GodRaysShader.js +3 -3
- package/examples/jsm/shaders/OutputShader.js +5 -1
- package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
- package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
- package/examples/jsm/transpiler/TSLEncoder.js +2 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +93 -4
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +46 -2
- package/examples/jsm/tsl/display/AnamorphicNode.js +118 -5
- package/examples/jsm/tsl/display/BleachBypass.js +10 -0
- package/examples/jsm/tsl/display/BloomNode.js +233 -26
- package/examples/jsm/tsl/display/DenoiseNode.js +141 -25
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +80 -1
- package/examples/jsm/tsl/display/DotScreenNode.js +50 -5
- package/examples/jsm/tsl/display/FXAANode.js +52 -3
- package/examples/jsm/tsl/display/FilmNode.js +47 -1
- package/examples/jsm/tsl/display/GTAONode.js +210 -14
- package/examples/jsm/tsl/display/GaussianBlurNode.js +152 -8
- package/examples/jsm/tsl/display/LensflareNode.js +131 -13
- package/examples/jsm/tsl/display/Lut3DNode.js +55 -1
- package/examples/jsm/tsl/display/MotionBlur.js +12 -2
- package/examples/jsm/tsl/display/OutlineNode.js +343 -26
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +36 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +142 -9
- package/examples/jsm/tsl/display/RGBShiftNode.js +49 -2
- package/examples/jsm/tsl/display/SMAANode.js +187 -46
- package/examples/jsm/tsl/display/SSAAPassNode.js +110 -25
- package/examples/jsm/tsl/display/SSRNode.js +194 -21
- package/examples/jsm/tsl/display/Sepia.js +9 -0
- package/examples/jsm/tsl/display/SobelOperatorNode.js +54 -4
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +79 -3
- package/examples/jsm/tsl/display/StereoPassNode.js +41 -3
- package/examples/jsm/tsl/display/TRAAPassNode.js +116 -21
- package/examples/jsm/tsl/display/TransitionNode.js +71 -6
- package/examples/jsm/tsl/display/hashBlur.js +14 -3
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +40 -34
- package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
- package/examples/jsm/utils/CameraUtils.js +4 -1
- package/examples/jsm/utils/GeometryUtils.js +22 -19
- package/examples/jsm/utils/SceneUtils.js +2 -2
- package/examples/jsm/webxr/XRControllerModelFactory.js +6 -1
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +8 -3
- package/src/Three.Core.js +4 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +18 -5
- package/src/Three.WebGPU.Nodes.js +2 -2
- package/src/Three.WebGPU.js +2 -2
- package/src/animation/PropertyBinding.js +2 -2
- package/src/cameras/ArrayCamera.js +1 -0
- package/src/cameras/PerspectiveCamera.js +18 -2
- package/src/constants.js +6 -1
- package/src/core/BufferAttribute.js +4 -0
- package/src/core/EventDispatcher.js +8 -6
- package/src/core/RenderTarget.js +18 -0
- package/src/core/RenderTarget3D.js +22 -0
- package/src/core/RenderTargetArray.js +22 -0
- package/src/extras/Earcut.js +1 -1
- package/src/extras/ImageUtils.js +1 -11
- package/src/extras/PMREMGenerator.js +20 -0
- package/src/extras/TextureUtils.js +6 -0
- package/src/helpers/CameraHelper.js +16 -13
- package/src/loaders/nodes/NodeLoader.js +59 -0
- package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
- package/src/loaders/nodes/NodeObjectLoader.js +61 -0
- package/src/materials/nodes/Line2NodeMaterial.js +128 -34
- package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
- package/src/materials/nodes/LineDashedNodeMaterial.js +78 -5
- package/src/materials/nodes/MeshBasicNodeMaterial.js +56 -0
- package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +22 -2
- package/src/materials/nodes/MeshNormalNodeMaterial.js +21 -2
- package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +269 -0
- package/src/materials/nodes/MeshSSSNodeMaterial.js +97 -6
- package/src/materials/nodes/MeshStandardNodeMaterial.js +78 -0
- package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
- package/src/materials/nodes/NodeMaterial.js +476 -23
- package/src/materials/nodes/NodeMaterials.js +0 -1
- package/src/materials/nodes/PointsNodeMaterial.js +121 -10
- package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +78 -20
- package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
- package/src/materials/nodes/manager/NodeMaterialObserver.js +95 -0
- package/src/nodes/Nodes.js +5 -6
- package/src/nodes/TSL.js +6 -3
- package/src/nodes/accessors/AccessorsUtils.js +27 -0
- package/src/nodes/accessors/Arrays.js +47 -6
- package/src/nodes/accessors/BatchNode.js +42 -6
- package/src/nodes/accessors/Bitangent.js +37 -0
- package/src/nodes/accessors/BufferAttributeNode.js +178 -5
- package/src/nodes/accessors/BufferNode.js +63 -0
- package/src/nodes/accessors/BuiltinNode.js +38 -0
- package/src/nodes/accessors/Camera.js +113 -3
- package/src/nodes/accessors/ClippingNode.js +71 -2
- package/src/nodes/accessors/CubeTextureNode.js +64 -0
- package/src/nodes/accessors/InstanceNode.js +85 -2
- package/src/nodes/accessors/InstancedMeshNode.js +28 -3
- package/src/nodes/accessors/Lights.js +50 -1
- package/src/nodes/accessors/MaterialNode.js +306 -12
- package/src/nodes/accessors/MaterialProperties.js +7 -0
- package/src/nodes/accessors/MaterialReferenceNode.js +53 -13
- package/src/nodes/accessors/ModelNode.js +100 -5
- package/src/nodes/accessors/ModelViewProjectionNode.js +10 -38
- package/src/nodes/accessors/MorphNode.js +48 -4
- package/src/nodes/accessors/Normal.js +65 -5
- package/src/nodes/accessors/Object3DNode.js +101 -1
- package/src/nodes/accessors/PointUVNode.js +26 -0
- package/src/nodes/accessors/Position.js +56 -7
- package/src/nodes/accessors/ReferenceBaseNode.js +186 -0
- package/src/nodes/accessors/ReferenceNode.js +201 -2
- package/src/nodes/accessors/ReflectVector.js +24 -0
- package/src/nodes/accessors/RendererReferenceNode.js +46 -1
- package/src/nodes/accessors/SceneNode.js +54 -0
- package/src/nodes/accessors/SkinningNode.js +127 -1
- package/src/nodes/accessors/StorageBufferNode.js +209 -8
- package/src/nodes/accessors/StorageTextureNode.js +118 -0
- package/src/nodes/accessors/Tangent.js +38 -2
- package/src/nodes/accessors/Texture3DNode.js +91 -7
- package/src/nodes/accessors/TextureBicubic.js +12 -2
- package/src/nodes/accessors/TextureNode.js +316 -10
- package/src/nodes/accessors/TextureSizeNode.js +42 -0
- package/src/nodes/accessors/UV.js +10 -1
- package/src/nodes/accessors/UniformArrayNode.js +231 -25
- package/src/nodes/accessors/UserDataNode.js +46 -0
- package/src/nodes/accessors/VelocityNode.js +80 -0
- package/src/nodes/accessors/VertexColorNode.js +39 -2
- package/src/nodes/code/CodeNode.js +95 -1
- package/src/nodes/code/ExpressionNode.js +28 -0
- package/src/nodes/code/FunctionCallNode.js +37 -0
- package/src/nodes/code/FunctionNode.js +45 -0
- package/src/nodes/code/ScriptableNode.js +223 -1
- package/src/nodes/code/ScriptableValueNode.js +85 -1
- package/src/nodes/core/ArrayNode.js +125 -0
- package/src/nodes/core/AssignNode.js +48 -2
- package/src/nodes/core/AttributeNode.js +43 -0
- package/src/nodes/core/BypassNode.js +47 -2
- package/src/nodes/core/CacheNode.js +53 -2
- package/src/nodes/core/ConstNode.js +32 -0
- package/src/nodes/core/ContextNode.js +65 -0
- package/src/nodes/core/IndexNode.js +68 -7
- package/src/nodes/core/InputNode.js +48 -0
- package/src/nodes/core/LightingModel.js +60 -0
- package/src/nodes/core/MRTNode.js +66 -0
- package/src/nodes/core/Node.js +350 -12
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +1166 -26
- package/src/nodes/core/NodeCache.js +41 -2
- package/src/nodes/core/NodeCode.js +31 -0
- package/src/nodes/core/NodeFrame.js +123 -2
- package/src/nodes/core/NodeFunction.js +46 -0
- package/src/nodes/core/NodeFunctionInput.js +44 -0
- package/src/nodes/core/NodeParser.js +11 -0
- package/src/nodes/core/NodeUniform.js +52 -0
- package/src/nodes/core/NodeUtils.js +152 -1
- package/src/nodes/core/NodeVar.js +47 -1
- package/src/nodes/core/NodeVarying.js +28 -0
- package/src/nodes/core/OutputStructNode.js +51 -10
- package/src/nodes/core/ParameterNode.js +28 -0
- package/src/nodes/core/PropertyNode.js +232 -0
- package/src/nodes/core/StackNode.js +98 -1
- package/src/nodes/core/StructNode.js +121 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +105 -6
- package/src/nodes/core/TempNode.js +31 -5
- package/src/nodes/core/UniformGroupNode.js +82 -7
- package/src/nodes/core/UniformNode.js +66 -0
- package/src/nodes/core/VarNode.js +146 -7
- package/src/nodes/core/VaryingNode.js +100 -3
- package/src/nodes/core/constants.js +36 -0
- package/src/nodes/display/BlendModes.js +88 -1
- package/src/nodes/display/BumpMapNode.js +37 -0
- package/src/nodes/display/ColorAdjustment.js +53 -11
- package/src/nodes/display/ColorSpaceFunctions.js +16 -0
- package/src/nodes/display/ColorSpaceNode.js +82 -0
- package/src/nodes/display/FrontFacingNode.js +29 -0
- package/src/nodes/display/NormalMapNode.js +43 -0
- package/src/nodes/display/PassNode.js +300 -7
- package/src/nodes/display/PosterizeNode.js +33 -0
- package/src/nodes/display/RenderOutputNode.js +66 -1
- package/src/nodes/display/ScreenNode.js +96 -0
- package/src/nodes/display/ToneMappingFunctions.js +58 -10
- package/src/nodes/display/ToneMappingNode.js +55 -2
- package/src/nodes/display/ToonOutlinePassNode.js +73 -0
- package/src/nodes/display/ViewportDepthNode.js +122 -8
- package/src/nodes/display/ViewportDepthTextureNode.js +23 -0
- package/src/nodes/display/ViewportSharedTextureNode.js +23 -0
- package/src/nodes/display/ViewportTextureNode.js +57 -0
- package/src/nodes/fog/Fog.js +110 -0
- package/src/nodes/functions/BasicLightingModel.js +24 -0
- package/src/nodes/functions/PhongLightingModel.js +34 -2
- package/src/nodes/functions/PhysicalLightingModel.js +167 -8
- package/src/nodes/functions/ShadowMaskModel.js +23 -0
- package/src/nodes/functions/ToonLightingModel.js +20 -0
- package/src/nodes/functions/material/getAlphaHashThreshold.js +1 -3
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +16 -1
- package/src/nodes/geometry/RangeNode.js +54 -2
- package/src/nodes/gpgpu/AtomicFunctionNode.js +174 -2
- package/src/nodes/gpgpu/BarrierNode.js +47 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +134 -0
- package/src/nodes/gpgpu/ComputeNode.js +106 -2
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +115 -6
- package/src/nodes/lighting/AONode.js +18 -0
- package/src/nodes/lighting/AmbientLightNode.js +10 -0
- package/src/nodes/lighting/AnalyticLightNode.js +97 -2
- package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
- package/src/nodes/lighting/BasicLightMapNode.js +17 -0
- package/src/nodes/lighting/DirectionalLightNode.js +10 -0
- package/src/nodes/lighting/EnvironmentNode.js +18 -0
- package/src/nodes/lighting/HemisphereLightNode.js +31 -0
- package/src/nodes/lighting/IESSpotLightNode.js +11 -0
- package/src/nodes/lighting/IrradianceNode.js +17 -0
- package/src/nodes/lighting/LightProbeNode.js +20 -0
- package/src/nodes/lighting/LightUtils.js +12 -0
- package/src/nodes/lighting/LightingContextNode.js +48 -0
- package/src/nodes/lighting/LightingNode.js +15 -6
- package/src/nodes/lighting/LightsNode.js +132 -1
- package/src/nodes/lighting/PointLightNode.js +32 -1
- package/src/nodes/lighting/PointShadowNode.js +54 -1
- package/src/nodes/lighting/RectAreaLightNode.js +44 -6
- package/src/nodes/lighting/ShadowBaseNode.js +93 -0
- package/src/nodes/lighting/ShadowNode.js +241 -35
- package/src/nodes/lighting/SpotLightNode.js +43 -0
- package/src/nodes/math/ConditionalNode.js +78 -4
- package/src/nodes/math/Hash.js +9 -0
- package/src/nodes/math/MathNode.js +627 -11
- package/src/nodes/math/MathUtils.js +45 -1
- package/src/nodes/math/OperatorNode.js +329 -18
- package/src/nodes/math/TriNoise3D.js +18 -7
- package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
- package/src/nodes/parsers/GLSLNodeParser.js +11 -0
- package/src/nodes/pmrem/PMREMNode.js +133 -0
- package/src/nodes/pmrem/PMREMUtils.js +2 -2
- package/src/nodes/procedural/Checker.js +9 -0
- package/src/nodes/shapes/Shapes.js +33 -0
- package/src/nodes/tsl/TSLBase.js +3 -2
- package/src/nodes/tsl/TSLCore.js +22 -2
- package/src/nodes/utils/ArrayElementNode.js +39 -3
- package/src/nodes/utils/ConvertNode.js +31 -0
- package/src/nodes/utils/CubeMapNode.js +78 -0
- package/src/nodes/utils/Discard.js +16 -0
- package/src/nodes/utils/EquirectUVNode.js +31 -1
- package/src/nodes/utils/FlipNode.js +38 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +53 -1
- package/src/nodes/utils/JoinNode.js +25 -0
- package/src/nodes/utils/LoopNode.js +82 -2
- package/src/nodes/utils/MatcapUVNode.js +17 -0
- package/src/nodes/utils/MaxMipLevelNode.js +49 -0
- package/src/nodes/utils/MemberNode.js +68 -0
- package/src/nodes/utils/Oscillators.js +33 -0
- package/src/nodes/utils/Packing.js +17 -0
- package/src/nodes/utils/PostProcessingUtils.js +28 -23
- package/src/nodes/utils/RTTNode.js +123 -2
- package/src/nodes/utils/ReflectorNode.js +174 -4
- package/src/nodes/utils/RemapNode.js +79 -0
- package/src/nodes/utils/RotateNode.js +41 -0
- package/src/nodes/utils/SetNode.js +44 -1
- package/src/nodes/utils/SplitNode.js +55 -3
- package/src/nodes/utils/SpriteSheetUVNode.js +46 -0
- package/src/nodes/utils/SpriteUtils.js +17 -0
- package/src/nodes/utils/StorageArrayElementNode.js +54 -0
- package/src/nodes/utils/Timer.js +40 -0
- package/src/nodes/utils/TriplanarTexturesNode.js +84 -0
- package/src/nodes/utils/UVUtils.js +20 -0
- package/src/nodes/utils/ViewportUtils.js +13 -0
- package/src/objects/BatchedMesh.js +2 -3
- package/src/objects/ClippingGroup.js +49 -0
- package/src/objects/Line.js +6 -6
- package/src/renderers/WebGLRenderer.js +30 -4
- package/src/renderers/common/Animation.js +85 -0
- package/src/renderers/common/Attributes.js +36 -0
- package/src/renderers/common/Backend.js +502 -44
- package/src/renderers/common/Background.js +48 -1
- package/src/renderers/common/BindGroup.js +43 -0
- package/src/renderers/common/Binding.js +35 -0
- package/src/renderers/common/Bindings.js +93 -1
- package/src/renderers/common/Buffer.js +49 -0
- package/src/renderers/common/BufferUtils.js +27 -0
- package/src/renderers/common/BundleGroup.js +57 -0
- package/src/renderers/common/ChainMap.js +45 -6
- package/src/renderers/common/ClippingContext.js +108 -15
- package/src/renderers/common/Color4.js +40 -0
- package/src/renderers/common/ComputePipeline.js +24 -0
- package/src/renderers/common/CubeRenderTarget.js +13 -0
- package/src/renderers/common/DataMap.js +37 -1
- package/src/renderers/common/Geometries.js +91 -14
- package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
- package/src/renderers/common/Info.js +78 -35
- package/src/renderers/common/Lighting.js +34 -6
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +148 -5
- package/src/renderers/common/PostProcessing.js +99 -11
- package/src/renderers/common/ProgrammableStage.js +60 -2
- package/src/renderers/common/QuadMesh.js +54 -5
- package/src/renderers/common/RenderBundle.js +14 -8
- package/src/renderers/common/RenderBundles.js +39 -10
- package/src/renderers/common/RenderContext.js +201 -2
- package/src/renderers/common/RenderContexts.js +59 -6
- package/src/renderers/common/RenderList.js +178 -0
- package/src/renderers/common/RenderLists.js +40 -3
- package/src/renderers/common/RenderObject.js +400 -17
- package/src/renderers/common/RenderObjects.js +103 -7
- package/src/renderers/common/RenderPipeline.js +24 -0
- package/src/renderers/common/Renderer.js +1170 -86
- package/src/renderers/common/RendererUtils.js +193 -0
- package/src/renderers/common/SampledTexture.js +120 -0
- package/src/renderers/common/Sampler.js +30 -0
- package/src/renderers/common/StorageBuffer.js +24 -0
- package/src/renderers/common/StorageBufferAttribute.js +31 -2
- package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
- package/src/renderers/common/StorageTexture.js +38 -0
- package/src/renderers/common/Textures.js +97 -7
- package/src/renderers/common/TimestampQueryPool.js +39 -0
- package/src/renderers/common/Uniform.js +225 -3
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +141 -2
- package/src/renderers/common/XRManager.js +1193 -0
- package/src/renderers/common/XRRenderTarget.js +74 -0
- package/src/renderers/common/extras/PMREMGenerator.js +76 -10
- package/src/renderers/common/nodes/NodeBuilderState.js +99 -5
- package/src/renderers/common/nodes/NodeLibrary.js +89 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +90 -2
- package/src/renderers/common/nodes/NodeSampler.js +28 -0
- package/src/renderers/common/nodes/NodeStorageBuffer.js +35 -0
- package/src/renderers/common/nodes/NodeUniform.js +243 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
- package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
- package/src/renderers/common/nodes/Nodes.js +352 -78
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
- package/src/renderers/webgl/WebGLBackground.js +4 -0
- package/src/renderers/webgl-fallback/WebGLBackend.js +819 -116
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -18
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +58 -1
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +168 -22
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
- package/src/renderers/webgpu/WebGPUBackend.js +578 -164
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +36 -0
- package/src/renderers/webgpu/WebGPURenderer.js +36 -0
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +20 -8
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +21 -8
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +674 -52
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +17 -0
- package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +95 -14
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +94 -1
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +262 -18
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +116 -4
- package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
- package/src/renderers/webxr/WebXRManager.js +19 -2
- package/src/textures/Data3DTexture.js +2 -2
- package/src/textures/Texture.js +4 -0
- package/src/textures/VideoFrameTexture.js +35 -0
- package/examples/jsm/animation/MMDAnimationHelper.js +0 -1209
- package/examples/jsm/animation/MMDPhysics.js +0 -1408
- package/examples/jsm/exporters/MMDExporter.js +0 -223
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/MMDLoader.js +0 -2298
- package/examples/jsm/objects/InstancedPoints.js +0 -19
- 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/core/UniformGroup.js +0 -13
- 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/renderers/common/PostProcessingUtils.js +0 -86
|
@@ -2,19 +2,53 @@ import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, Near
|
|
|
2
2
|
|
|
3
3
|
let initialized = false, wrappingToGL, filterToGL, compareToGL;
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* A WebGL 2 backend utility module for managing textures.
|
|
7
|
+
*
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
5
10
|
class WebGLTextureUtils {
|
|
6
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a new utility object.
|
|
14
|
+
*
|
|
15
|
+
* @param {WebGLBackend} backend - The WebGL 2 backend.
|
|
16
|
+
*/
|
|
7
17
|
constructor( backend ) {
|
|
8
18
|
|
|
19
|
+
/**
|
|
20
|
+
* A reference to the WebGL 2 backend.
|
|
21
|
+
*
|
|
22
|
+
* @type {WebGLBackend}
|
|
23
|
+
*/
|
|
9
24
|
this.backend = backend;
|
|
10
25
|
|
|
26
|
+
/**
|
|
27
|
+
* A reference to the rendering context.
|
|
28
|
+
*
|
|
29
|
+
* @type {WebGL2RenderingContext}
|
|
30
|
+
*/
|
|
11
31
|
this.gl = backend.gl;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A reference to a backend module holding extension-related
|
|
35
|
+
* utility functions.
|
|
36
|
+
*
|
|
37
|
+
* @type {WebGLExtensions}
|
|
38
|
+
*/
|
|
12
39
|
this.extensions = backend.extensions;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A dictionary for managing default textures. The key
|
|
43
|
+
* is the binding point (target), the value the WEbGL texture object.
|
|
44
|
+
*
|
|
45
|
+
* @type {Object<GLenum,WebGLTexture>}
|
|
46
|
+
*/
|
|
13
47
|
this.defaultTextures = {};
|
|
14
48
|
|
|
15
49
|
if ( initialized === false ) {
|
|
16
50
|
|
|
17
|
-
this._init(
|
|
51
|
+
this._init();
|
|
18
52
|
|
|
19
53
|
initialized = true;
|
|
20
54
|
|
|
@@ -22,7 +56,14 @@ class WebGLTextureUtils {
|
|
|
22
56
|
|
|
23
57
|
}
|
|
24
58
|
|
|
25
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Inits the state of the utility.
|
|
61
|
+
*
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
_init() {
|
|
65
|
+
|
|
66
|
+
const gl = this.gl;
|
|
26
67
|
|
|
27
68
|
// Store only WebGL constants here.
|
|
28
69
|
|
|
@@ -55,20 +96,12 @@ class WebGLTextureUtils {
|
|
|
55
96
|
|
|
56
97
|
}
|
|
57
98
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return gl.NEAREST;
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return gl.LINEAR;
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Returns the native texture type for the given texture.
|
|
101
|
+
*
|
|
102
|
+
* @param {Texture} texture - The texture.
|
|
103
|
+
* @return {GLenum} The native texture type.
|
|
104
|
+
*/
|
|
72
105
|
getGLTextureType( texture ) {
|
|
73
106
|
|
|
74
107
|
const { gl } = this;
|
|
@@ -98,6 +131,16 @@ class WebGLTextureUtils {
|
|
|
98
131
|
|
|
99
132
|
}
|
|
100
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Returns the native texture type for the given texture.
|
|
136
|
+
*
|
|
137
|
+
* @param {String?} internalFormatName - The internal format name. When `null`, the internal format is derived from the subsequent parameters.
|
|
138
|
+
* @param {GLenum} glFormat - The WebGL format.
|
|
139
|
+
* @param {GLenum} glType - The WebGL type.
|
|
140
|
+
* @param {String} colorSpace - The texture's color space.
|
|
141
|
+
* @param {Boolean} [forceLinearTransfer=false] - Whether to force a linear transfer or not.
|
|
142
|
+
* @return {GLenum} The internal format.
|
|
143
|
+
*/
|
|
101
144
|
getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
|
|
102
145
|
|
|
103
146
|
const { gl, extensions } = this;
|
|
@@ -218,7 +261,8 @@ class WebGLTextureUtils {
|
|
|
218
261
|
|
|
219
262
|
if ( glFormat === gl.DEPTH_COMPONENT ) {
|
|
220
263
|
|
|
221
|
-
if ( glType === gl.
|
|
264
|
+
if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.DEPTH_COMPONENT16;
|
|
265
|
+
if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.DEPTH_COMPONENT24;
|
|
222
266
|
if ( glType === gl.FLOAT ) internalFormat = gl.DEPTH_COMPONENT32F;
|
|
223
267
|
|
|
224
268
|
}
|
|
@@ -241,6 +285,12 @@ class WebGLTextureUtils {
|
|
|
241
285
|
|
|
242
286
|
}
|
|
243
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Sets the texture parameters for the given texture.
|
|
290
|
+
*
|
|
291
|
+
* @param {GLenum} textureType - The texture type.
|
|
292
|
+
* @param {Texture} texture - The texture.
|
|
293
|
+
*/
|
|
244
294
|
setTextureParameters( textureType, texture ) {
|
|
245
295
|
|
|
246
296
|
const { gl, extensions, backend } = this;
|
|
@@ -294,6 +344,12 @@ class WebGLTextureUtils {
|
|
|
294
344
|
|
|
295
345
|
}
|
|
296
346
|
|
|
347
|
+
/**
|
|
348
|
+
* Creates a default texture for the given texture that can be used
|
|
349
|
+
* as a placeholder until the actual texture is ready for usage.
|
|
350
|
+
*
|
|
351
|
+
* @param {Texture} texture - The texture to create a default texture for.
|
|
352
|
+
*/
|
|
297
353
|
createDefaultTexture( texture ) {
|
|
298
354
|
|
|
299
355
|
const { gl, backend, defaultTextures } = this;
|
|
@@ -325,6 +381,13 @@ class WebGLTextureUtils {
|
|
|
325
381
|
|
|
326
382
|
}
|
|
327
383
|
|
|
384
|
+
/**
|
|
385
|
+
* Defines a texture on the GPU for the given texture object.
|
|
386
|
+
*
|
|
387
|
+
* @param {Texture} texture - The texture.
|
|
388
|
+
* @param {Object} [options={}] - Optional configuration parameter.
|
|
389
|
+
* @return {undefined}
|
|
390
|
+
*/
|
|
328
391
|
createTexture( texture, options ) {
|
|
329
392
|
|
|
330
393
|
const { gl, backend } = this;
|
|
@@ -365,6 +428,12 @@ class WebGLTextureUtils {
|
|
|
365
428
|
|
|
366
429
|
}
|
|
367
430
|
|
|
431
|
+
/**
|
|
432
|
+
* Uploads texture buffer data to the GPU memory.
|
|
433
|
+
*
|
|
434
|
+
* @param {WebGLBuffer} buffer - The buffer data.
|
|
435
|
+
* @param {Texture} texture - The texture,
|
|
436
|
+
*/
|
|
368
437
|
copyBufferToTexture( buffer, texture ) {
|
|
369
438
|
|
|
370
439
|
const { gl, backend } = this;
|
|
@@ -400,6 +469,12 @@ class WebGLTextureUtils {
|
|
|
400
469
|
|
|
401
470
|
}
|
|
402
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Uploads the updated texture data to the GPU.
|
|
474
|
+
*
|
|
475
|
+
* @param {Texture} texture - The texture.
|
|
476
|
+
* @param {Object} [options={}] - Optional configuration parameter.
|
|
477
|
+
*/
|
|
403
478
|
updateTexture( texture, options ) {
|
|
404
479
|
|
|
405
480
|
const { gl } = this;
|
|
@@ -520,6 +595,11 @@ class WebGLTextureUtils {
|
|
|
520
595
|
|
|
521
596
|
}
|
|
522
597
|
|
|
598
|
+
/**
|
|
599
|
+
* Generates mipmaps for the given texture.
|
|
600
|
+
*
|
|
601
|
+
* @param {Texture} texture - The texture.
|
|
602
|
+
*/
|
|
523
603
|
generateMipmaps( texture ) {
|
|
524
604
|
|
|
525
605
|
const { gl, backend } = this;
|
|
@@ -530,6 +610,11 @@ class WebGLTextureUtils {
|
|
|
530
610
|
|
|
531
611
|
}
|
|
532
612
|
|
|
613
|
+
/**
|
|
614
|
+
* Deallocates the render buffers of the given render target.
|
|
615
|
+
*
|
|
616
|
+
* @param {RenderTarget} renderTarget - The render target.
|
|
617
|
+
*/
|
|
533
618
|
deallocateRenderBuffers( renderTarget ) {
|
|
534
619
|
|
|
535
620
|
const { gl, backend } = this;
|
|
@@ -590,6 +675,11 @@ class WebGLTextureUtils {
|
|
|
590
675
|
|
|
591
676
|
}
|
|
592
677
|
|
|
678
|
+
/**
|
|
679
|
+
* Destroys the GPU data for the given texture object.
|
|
680
|
+
*
|
|
681
|
+
* @param {Texture} texture - The texture.
|
|
682
|
+
*/
|
|
593
683
|
destroyTexture( texture ) {
|
|
594
684
|
|
|
595
685
|
const { gl, backend } = this;
|
|
@@ -602,6 +692,15 @@ class WebGLTextureUtils {
|
|
|
602
692
|
|
|
603
693
|
}
|
|
604
694
|
|
|
695
|
+
/**
|
|
696
|
+
* Copies data of the given source texture to the given destination texture.
|
|
697
|
+
*
|
|
698
|
+
* @param {Texture} srcTexture - The source texture.
|
|
699
|
+
* @param {Texture} dstTexture - The destination texture.
|
|
700
|
+
* @param {Vector4?} [srcRegion=null] - The region of the source texture to copy.
|
|
701
|
+
* @param {(Vector2|Vector3)?} [dstPosition=null] - The destination position of the copy.
|
|
702
|
+
* @param {Number} [level=0] - The mip level to copy.
|
|
703
|
+
*/
|
|
605
704
|
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
|
|
606
705
|
|
|
607
706
|
const { gl, backend } = this;
|
|
@@ -720,6 +819,13 @@ class WebGLTextureUtils {
|
|
|
720
819
|
|
|
721
820
|
}
|
|
722
821
|
|
|
822
|
+
/**
|
|
823
|
+
* Copies the current bound framebuffer to the given texture.
|
|
824
|
+
*
|
|
825
|
+
* @param {Texture} texture - The destination texture.
|
|
826
|
+
* @param {RenderContext} renderContext - The render context.
|
|
827
|
+
* @param {Vector4} rectangle - A four dimensional vector defining the origin and dimension of the copy.
|
|
828
|
+
*/
|
|
723
829
|
copyFramebufferToTexture( texture, renderContext, rectangle ) {
|
|
724
830
|
|
|
725
831
|
const { gl } = this;
|
|
@@ -731,7 +837,7 @@ class WebGLTextureUtils {
|
|
|
731
837
|
|
|
732
838
|
const requireDrawFrameBuffer = texture.isDepthTexture === true || ( renderContext.renderTarget && renderContext.renderTarget.samples > 0 );
|
|
733
839
|
|
|
734
|
-
const srcHeight = renderContext.renderTarget ? renderContext.renderTarget.height : this.backend.
|
|
840
|
+
const srcHeight = renderContext.renderTarget ? renderContext.renderTarget.height : this.backend.getDrawingBufferSize().y;
|
|
735
841
|
|
|
736
842
|
if ( requireDrawFrameBuffer ) {
|
|
737
843
|
|
|
@@ -807,13 +913,20 @@ class WebGLTextureUtils {
|
|
|
807
913
|
|
|
808
914
|
}
|
|
809
915
|
|
|
810
|
-
|
|
811
|
-
|
|
916
|
+
/**
|
|
917
|
+
* SetupS storage for internal depth/stencil buffers and bind to correct framebuffer.
|
|
918
|
+
*
|
|
919
|
+
* @param {WebGLRenderbuffer} renderbuffer - The render buffer.
|
|
920
|
+
* @param {RenderContext} renderContext - The render context.
|
|
921
|
+
* @param {Number} samples - The MSAA sample count.
|
|
922
|
+
* @param {Boolean} [useMultisampledRTT=false] - Whether to use WEBGL_multisampled_render_to_texture or not.
|
|
923
|
+
*/
|
|
924
|
+
setupRenderBufferStorage( renderbuffer, renderContext, samples, useMultisampledRTT = false ) {
|
|
812
925
|
|
|
813
926
|
const { gl } = this;
|
|
814
927
|
const renderTarget = renderContext.renderTarget;
|
|
815
928
|
|
|
816
|
-
const {
|
|
929
|
+
const { depthTexture, depthBuffer, stencilBuffer, width, height } = renderTarget;
|
|
817
930
|
|
|
818
931
|
gl.bindRenderbuffer( gl.RENDERBUFFER, renderbuffer );
|
|
819
932
|
|
|
@@ -821,7 +934,13 @@ class WebGLTextureUtils {
|
|
|
821
934
|
|
|
822
935
|
let glInternalFormat = gl.DEPTH_COMPONENT24;
|
|
823
936
|
|
|
824
|
-
if (
|
|
937
|
+
if ( useMultisampledRTT === true ) {
|
|
938
|
+
|
|
939
|
+
const multisampledRTTExt = this.extensions.get( 'WEBGL_multisampled_render_to_texture' );
|
|
940
|
+
|
|
941
|
+
multisampledRTTExt.renderbufferStorageMultisampleEXT( gl.RENDERBUFFER, renderTarget.samples, glInternalFormat, width, height );
|
|
942
|
+
|
|
943
|
+
} else if ( samples > 0 ) {
|
|
825
944
|
|
|
826
945
|
if ( depthTexture && depthTexture.isDepthTexture ) {
|
|
827
946
|
|
|
@@ -862,6 +981,18 @@ class WebGLTextureUtils {
|
|
|
862
981
|
|
|
863
982
|
}
|
|
864
983
|
|
|
984
|
+
/**
|
|
985
|
+
* Returns texture data as a typed array.
|
|
986
|
+
*
|
|
987
|
+
* @async
|
|
988
|
+
* @param {Texture} texture - The texture to copy.
|
|
989
|
+
* @param {Number} x - The x coordinate of the copy origin.
|
|
990
|
+
* @param {Number} y - The y coordinate of the copy origin.
|
|
991
|
+
* @param {Number} width - The width of the copy.
|
|
992
|
+
* @param {Number} height - The height of the copy.
|
|
993
|
+
* @param {Number} faceIndex - The face index.
|
|
994
|
+
* @return {Promise<TypedArray>} A Promise that resolves with a typed array when the copy operation has finished.
|
|
995
|
+
*/
|
|
865
996
|
async copyTextureToBuffer( texture, x, y, width, height, faceIndex ) {
|
|
866
997
|
|
|
867
998
|
const { backend, gl } = this;
|
|
@@ -903,6 +1034,13 @@ class WebGLTextureUtils {
|
|
|
903
1034
|
|
|
904
1035
|
}
|
|
905
1036
|
|
|
1037
|
+
/**
|
|
1038
|
+
* Returns the corresponding typed array type for the given WebGL data type.
|
|
1039
|
+
*
|
|
1040
|
+
* @private
|
|
1041
|
+
* @param {GLenum} glType - The WebGL data type.
|
|
1042
|
+
* @return {TypedArray.constructor} The typed array type.
|
|
1043
|
+
*/
|
|
906
1044
|
_getTypedArrayType( glType ) {
|
|
907
1045
|
|
|
908
1046
|
const { gl } = this;
|
|
@@ -922,6 +1060,14 @@ class WebGLTextureUtils {
|
|
|
922
1060
|
|
|
923
1061
|
}
|
|
924
1062
|
|
|
1063
|
+
/**
|
|
1064
|
+
* Returns the bytes-per-texel value for the given WebGL data type and texture format.
|
|
1065
|
+
*
|
|
1066
|
+
* @private
|
|
1067
|
+
* @param {GLenum} glType - The WebGL data type.
|
|
1068
|
+
* @param {GLenum} glFormat - The WebGL texture format.
|
|
1069
|
+
* @return {Number} The bytes-per-texel.
|
|
1070
|
+
*/
|
|
925
1071
|
_getBytesPerTexel( glType, glFormat ) {
|
|
926
1072
|
|
|
927
1073
|
const { gl } = this;
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { warnOnce } from '../../../utils.js';
|
|
2
|
+
import TimestampQueryPool from '../../common/TimestampQueryPool.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Manages a pool of WebGL timestamp queries for performance measurement.
|
|
6
|
+
* Handles creation, execution, and resolution of timer queries using WebGL extensions.
|
|
7
|
+
* @extends TimestampQueryPool
|
|
8
|
+
*/
|
|
9
|
+
class WebGLTimestampQueryPool extends TimestampQueryPool {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new WebGL timestamp query pool.
|
|
13
|
+
* @param {WebGLRenderingContext|WebGL2RenderingContext} gl - The WebGL context.
|
|
14
|
+
* @param {string} type - The type identifier for this query pool.
|
|
15
|
+
* @param {number} [maxQueries=2048] - Maximum number of queries this pool can hold.
|
|
16
|
+
*/
|
|
17
|
+
constructor( gl, type, maxQueries = 2048 ) {
|
|
18
|
+
|
|
19
|
+
super( maxQueries );
|
|
20
|
+
|
|
21
|
+
this.gl = gl;
|
|
22
|
+
this.type = type;
|
|
23
|
+
|
|
24
|
+
// Check for timer query extensions
|
|
25
|
+
this.ext = gl.getExtension( 'EXT_disjoint_timer_query_webgl2' ) ||
|
|
26
|
+
gl.getExtension( 'EXT_disjoint_timer_query' );
|
|
27
|
+
|
|
28
|
+
if ( ! this.ext ) {
|
|
29
|
+
|
|
30
|
+
console.warn( 'EXT_disjoint_timer_query not supported; timestamps will be disabled.' );
|
|
31
|
+
this.trackTimestamp = false;
|
|
32
|
+
return;
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Create query objects
|
|
37
|
+
this.queries = [];
|
|
38
|
+
for ( let i = 0; i < this.maxQueries; i ++ ) {
|
|
39
|
+
|
|
40
|
+
this.queries.push( gl.createQuery() );
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.activeQuery = null;
|
|
45
|
+
this.queryStates = new Map(); // Track state of each query: 'inactive', 'started', 'ended'
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Allocates a pair of queries for a given render context.
|
|
51
|
+
* @param {Object} renderContext - The render context to allocate queries for.
|
|
52
|
+
* @returns {?number} The base offset for the allocated queries, or null if allocation failed.
|
|
53
|
+
*/
|
|
54
|
+
allocateQueriesForContext( renderContext ) {
|
|
55
|
+
|
|
56
|
+
if ( ! this.trackTimestamp ) return null;
|
|
57
|
+
|
|
58
|
+
// Check if we have enough space for a new query pair
|
|
59
|
+
if ( this.currentQueryIndex + 2 > this.maxQueries ) {
|
|
60
|
+
|
|
61
|
+
warnOnce( `WebGPUTimestampQueryPool [${ this.type }]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${ this.type.toUpperCase() } ).` );
|
|
62
|
+
return null;
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const baseOffset = this.currentQueryIndex;
|
|
67
|
+
this.currentQueryIndex += 2;
|
|
68
|
+
|
|
69
|
+
// Initialize query states
|
|
70
|
+
this.queryStates.set( baseOffset, 'inactive' );
|
|
71
|
+
this.queryOffsets.set( renderContext.id, baseOffset );
|
|
72
|
+
|
|
73
|
+
return baseOffset;
|
|
74
|
+
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Begins a timestamp query for the specified render context.
|
|
79
|
+
* @param {Object} renderContext - The render context to begin timing for.
|
|
80
|
+
*/
|
|
81
|
+
beginQuery( renderContext ) {
|
|
82
|
+
|
|
83
|
+
if ( ! this.trackTimestamp || this.isDisposed ) {
|
|
84
|
+
|
|
85
|
+
return;
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const baseOffset = this.queryOffsets.get( renderContext.id );
|
|
90
|
+
if ( baseOffset == null ) {
|
|
91
|
+
|
|
92
|
+
return;
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Don't start a new query if there's an active one
|
|
97
|
+
if ( this.activeQuery !== null ) {
|
|
98
|
+
|
|
99
|
+
return;
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const query = this.queries[ baseOffset ];
|
|
104
|
+
if ( ! query ) {
|
|
105
|
+
|
|
106
|
+
return;
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
|
|
112
|
+
// Only begin if query is inactive
|
|
113
|
+
if ( this.queryStates.get( baseOffset ) === 'inactive' ) {
|
|
114
|
+
|
|
115
|
+
this.gl.beginQuery( this.ext.TIME_ELAPSED_EXT, query );
|
|
116
|
+
this.activeQuery = baseOffset;
|
|
117
|
+
this.queryStates.set( baseOffset, 'started' );
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
} catch ( error ) {
|
|
122
|
+
|
|
123
|
+
console.error( 'Error in beginQuery:', error );
|
|
124
|
+
this.activeQuery = null;
|
|
125
|
+
this.queryStates.set( baseOffset, 'inactive' );
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Ends the active timestamp query for the specified render context.
|
|
133
|
+
* @param {Object} renderContext - The render context to end timing for.
|
|
134
|
+
* @param {string} renderContext.id - Unique identifier for the render context.
|
|
135
|
+
*/
|
|
136
|
+
endQuery( renderContext ) {
|
|
137
|
+
|
|
138
|
+
if ( ! this.trackTimestamp || this.isDisposed ) {
|
|
139
|
+
|
|
140
|
+
return;
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const baseOffset = this.queryOffsets.get( renderContext.id );
|
|
145
|
+
if ( baseOffset == null ) {
|
|
146
|
+
|
|
147
|
+
return;
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Only end if this is the active query
|
|
152
|
+
if ( this.activeQuery !== baseOffset ) {
|
|
153
|
+
|
|
154
|
+
return;
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
|
|
160
|
+
this.gl.endQuery( this.ext.TIME_ELAPSED_EXT );
|
|
161
|
+
this.queryStates.set( baseOffset, 'ended' );
|
|
162
|
+
this.activeQuery = null;
|
|
163
|
+
|
|
164
|
+
} catch ( error ) {
|
|
165
|
+
|
|
166
|
+
console.error( 'Error in endQuery:', error );
|
|
167
|
+
// Reset state on error
|
|
168
|
+
this.queryStates.set( baseOffset, 'inactive' );
|
|
169
|
+
this.activeQuery = null;
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Asynchronously resolves all completed queries and returns the total duration.
|
|
177
|
+
* @returns {Promise<number>} The total duration in milliseconds, or the last valid value if resolution fails.
|
|
178
|
+
*/
|
|
179
|
+
async resolveQueriesAsync() {
|
|
180
|
+
|
|
181
|
+
if ( ! this.trackTimestamp || this.pendingResolve ) {
|
|
182
|
+
|
|
183
|
+
return this.lastValue;
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this.pendingResolve = true;
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
|
|
191
|
+
// Wait for all ended queries to complete
|
|
192
|
+
const resolvePromises = [];
|
|
193
|
+
|
|
194
|
+
for ( const [ baseOffset, state ] of this.queryStates ) {
|
|
195
|
+
|
|
196
|
+
if ( state === 'ended' ) {
|
|
197
|
+
|
|
198
|
+
const query = this.queries[ baseOffset ];
|
|
199
|
+
resolvePromises.push( this.resolveQuery( query ) );
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if ( resolvePromises.length === 0 ) {
|
|
206
|
+
|
|
207
|
+
return this.lastValue;
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const results = await Promise.all( resolvePromises );
|
|
212
|
+
const totalDuration = results.reduce( ( acc, val ) => acc + val, 0 );
|
|
213
|
+
|
|
214
|
+
// Store the last valid result
|
|
215
|
+
this.lastValue = totalDuration;
|
|
216
|
+
|
|
217
|
+
// Reset states
|
|
218
|
+
this.currentQueryIndex = 0;
|
|
219
|
+
this.queryOffsets.clear();
|
|
220
|
+
this.queryStates.clear();
|
|
221
|
+
this.activeQuery = null;
|
|
222
|
+
|
|
223
|
+
return totalDuration;
|
|
224
|
+
|
|
225
|
+
} catch ( error ) {
|
|
226
|
+
|
|
227
|
+
console.error( 'Error resolving queries:', error );
|
|
228
|
+
return this.lastValue;
|
|
229
|
+
|
|
230
|
+
} finally {
|
|
231
|
+
|
|
232
|
+
this.pendingResolve = false;
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Resolves a single query, checking for completion and disjoint operation.
|
|
240
|
+
* @private
|
|
241
|
+
* @param {WebGLQuery} query - The query object to resolve.
|
|
242
|
+
* @returns {Promise<number>} The elapsed time in milliseconds.
|
|
243
|
+
*/
|
|
244
|
+
async resolveQuery( query ) {
|
|
245
|
+
|
|
246
|
+
return new Promise( ( resolve ) => {
|
|
247
|
+
|
|
248
|
+
if ( this.isDisposed ) {
|
|
249
|
+
|
|
250
|
+
resolve( this.lastValue );
|
|
251
|
+
return;
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let timeoutId;
|
|
256
|
+
let isResolved = false;
|
|
257
|
+
|
|
258
|
+
const cleanup = () => {
|
|
259
|
+
|
|
260
|
+
if ( timeoutId ) {
|
|
261
|
+
|
|
262
|
+
clearTimeout( timeoutId );
|
|
263
|
+
timeoutId = null;
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const finalizeResolution = ( value ) => {
|
|
270
|
+
|
|
271
|
+
if ( ! isResolved ) {
|
|
272
|
+
|
|
273
|
+
isResolved = true;
|
|
274
|
+
cleanup();
|
|
275
|
+
resolve( value );
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const checkQuery = () => {
|
|
282
|
+
|
|
283
|
+
if ( this.isDisposed ) {
|
|
284
|
+
|
|
285
|
+
finalizeResolution( this.lastValue );
|
|
286
|
+
return;
|
|
287
|
+
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
try {
|
|
291
|
+
|
|
292
|
+
// Check if the GPU timer was disjoint (i.e., timing was unreliable)
|
|
293
|
+
const disjoint = this.gl.getParameter( this.ext.GPU_DISJOINT_EXT );
|
|
294
|
+
if ( disjoint ) {
|
|
295
|
+
|
|
296
|
+
finalizeResolution( this.lastValue );
|
|
297
|
+
return;
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const available = this.gl.getQueryParameter( query, this.gl.QUERY_RESULT_AVAILABLE );
|
|
302
|
+
if ( ! available ) {
|
|
303
|
+
|
|
304
|
+
timeoutId = setTimeout( checkQuery, 1 );
|
|
305
|
+
return;
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const elapsed = this.gl.getQueryParameter( query, this.gl.QUERY_RESULT );
|
|
310
|
+
resolve( Number( elapsed ) / 1e6 ); // Convert nanoseconds to milliseconds
|
|
311
|
+
|
|
312
|
+
} catch ( error ) {
|
|
313
|
+
|
|
314
|
+
console.error( 'Error checking query:', error );
|
|
315
|
+
resolve( this.lastValue );
|
|
316
|
+
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
checkQuery();
|
|
322
|
+
|
|
323
|
+
} );
|
|
324
|
+
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Releases all resources held by this query pool.
|
|
329
|
+
* This includes deleting all query objects and clearing internal state.
|
|
330
|
+
*/
|
|
331
|
+
dispose() {
|
|
332
|
+
|
|
333
|
+
if ( this.isDisposed ) {
|
|
334
|
+
|
|
335
|
+
return;
|
|
336
|
+
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
this.isDisposed = true;
|
|
340
|
+
|
|
341
|
+
if ( ! this.trackTimestamp ) return;
|
|
342
|
+
|
|
343
|
+
for ( const query of this.queries ) {
|
|
344
|
+
|
|
345
|
+
this.gl.deleteQuery( query );
|
|
346
|
+
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
this.queries = [];
|
|
350
|
+
this.queryStates.clear();
|
|
351
|
+
this.queryOffsets.clear();
|
|
352
|
+
this.lastValue = 0;
|
|
353
|
+
this.activeQuery = null;
|
|
354
|
+
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export default WebGLTimestampQueryPool;
|