super-three 0.171.0 → 0.172.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/README.md +1 -1
- package/build/three.cjs +157 -49
- package/build/three.core.js +104 -42
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +53 -8
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +10 -5
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +21191 -1008
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +21189 -1008
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +0 -5
- package/examples/jsm/animation/CCDIKSolver.js +3 -2
- package/examples/jsm/controls/ArcballControls.js +28 -19
- 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 +11 -7
- package/examples/jsm/exporters/KTX2Exporter.js +1 -1
- package/examples/jsm/exporters/PLYExporter.js +2 -2
- package/examples/jsm/helpers/TextureHelperGPU.js +15 -5
- package/examples/jsm/helpers/VertexNormalsHelper.js +2 -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 +1 -1
- package/examples/jsm/loaders/GLTFLoader.js +22 -2
- 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 -1
- 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/math/ConvexHull.js +1 -1
- package/examples/jsm/math/OBB.js +17 -0
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +10 -10
- package/examples/jsm/misc/Volume.js +20 -12
- package/examples/jsm/misc/VolumeSlice.js +2 -2
- 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 +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/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/SobelOperatorShader.js +1 -1
- 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 +2 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +9 -4
- 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/PerspectiveCamera.js +18 -2
- package/src/constants.js +1 -1
- 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/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/InstancedPointsNodeMaterial.js +72 -19
- 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 +474 -21
- package/src/materials/nodes/PointsNodeMaterial.js +22 -13
- package/src/materials/nodes/ShadowNodeMaterial.js +29 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +77 -19
- package/src/materials/nodes/VolumeNodeMaterial.js +80 -4
- package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -0
- package/src/nodes/Nodes.js +1 -6
- package/src/nodes/TSL.js +2 -3
- package/src/nodes/accessors/AccessorsUtils.js +27 -0
- package/src/nodes/accessors/Arrays.js +24 -5
- package/src/nodes/accessors/BatchNode.js +39 -3
- 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 +49 -0
- 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/InstancedPointsMaterialNode.js +13 -0
- package/src/nodes/accessors/Lights.js +50 -1
- package/src/nodes/accessors/MaterialNode.js +302 -8
- 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 +59 -3
- package/src/nodes/accessors/Object3DNode.js +102 -1
- package/src/nodes/accessors/PointUVNode.js +26 -0
- package/src/nodes/accessors/Position.js +53 -4
- package/src/nodes/accessors/ReferenceBaseNode.js +188 -0
- package/src/nodes/accessors/ReferenceNode.js +202 -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 +168 -4
- package/src/nodes/accessors/StorageTextureNode.js +118 -0
- package/src/nodes/accessors/Tangent.js +36 -0
- package/src/nodes/accessors/Texture3DNode.js +89 -5
- package/src/nodes/accessors/TextureBicubic.js +12 -2
- package/src/nodes/accessors/TextureNode.js +309 -10
- package/src/nodes/accessors/TextureSizeNode.js +42 -0
- package/src/nodes/accessors/UV.js +10 -1
- package/src/nodes/accessors/UniformArrayNode.js +223 -23
- package/src/nodes/accessors/UserDataNode.js +46 -0
- package/src/nodes/accessors/VelocityNode.js +82 -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/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 +24 -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 +337 -12
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +945 -15
- 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 +141 -0
- package/src/nodes/core/NodeVar.js +30 -0
- package/src/nodes/core/NodeVarying.js +28 -0
- package/src/nodes/core/OutputStructNode.js +33 -2
- package/src/nodes/core/ParameterNode.js +28 -0
- package/src/nodes/core/PropertyNode.js +232 -0
- package/src/nodes/core/StackNode.js +78 -0
- package/src/nodes/core/StructTypeNode.js +39 -1
- package/src/nodes/core/TempNode.js +30 -4
- package/src/nodes/core/UniformGroupNode.js +82 -7
- package/src/nodes/core/UniformNode.js +66 -0
- package/src/nodes/core/VarNode.js +52 -0
- package/src/nodes/core/VaryingNode.js +83 -2
- package/src/nodes/core/constants.js +36 -0
- 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 +298 -7
- package/src/nodes/display/PosterizeNode.js +33 -0
- package/src/nodes/display/RenderOutputNode.js +66 -1
- package/src/nodes/display/ScreenNode.js +87 -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 +93 -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 +157 -1
- package/src/nodes/gpgpu/BarrierNode.js +47 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +126 -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 +240 -34
- package/src/nodes/lighting/SpotLightNode.js +43 -0
- package/src/nodes/math/ConditionalNode.js +70 -3
- package/src/nodes/math/Hash.js +9 -0
- package/src/nodes/math/MathNode.js +614 -11
- package/src/nodes/math/MathUtils.js +45 -1
- package/src/nodes/math/OperatorNode.js +233 -0
- 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 +1 -1
- package/src/nodes/procedural/Checker.js +9 -0
- package/src/nodes/tsl/TSLBase.js +2 -2
- package/src/nodes/utils/ArrayElementNode.js +38 -2
- 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 +74 -1
- package/src/nodes/utils/MatcapUVNode.js +17 -0
- package/src/nodes/utils/MaxMipLevelNode.js +49 -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 +40 -0
- package/src/nodes/utils/Timer.js +19 -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 +1 -2
- package/src/objects/ClippingGroup.js +49 -0
- package/src/renderers/WebGLRenderer.js +23 -4
- package/src/renderers/common/Animation.js +63 -0
- package/src/renderers/common/Attributes.js +36 -0
- package/src/renderers/common/Backend.js +467 -52
- package/src/renderers/common/Background.js +34 -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 +38 -1
- package/src/renderers/common/ClippingContext.js +107 -14
- package/src/renderers/common/Color4.js +36 -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 +98 -0
- package/src/renderers/common/IndirectStorageBufferAttribute.js +25 -2
- package/src/renderers/common/Info.js +87 -0
- package/src/renderers/common/Lighting.js +26 -0
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +148 -5
- package/src/renderers/common/PostProcessing.js +75 -3
- 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 +33 -10
- package/src/renderers/common/RenderContext.js +169 -4
- package/src/renderers/common/RenderContexts.js +42 -2
- package/src/renderers/common/RenderList.js +178 -0
- package/src/renderers/common/RenderLists.js +31 -0
- package/src/renderers/common/RenderObject.js +328 -4
- package/src/renderers/common/RenderObjects.js +101 -7
- package/src/renderers/common/RenderPipeline.js +24 -0
- package/src/renderers/common/Renderer.js +1096 -31
- package/src/renderers/common/RendererUtils.js +193 -0
- package/src/renderers/common/SampledTexture.js +121 -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 +83 -0
- package/src/renderers/common/Uniform.js +188 -2
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +139 -2
- package/src/renderers/common/extras/PMREMGenerator.js +24 -3
- package/src/renderers/common/nodes/NodeBuilderState.js +95 -1
- package/src/renderers/common/nodes/NodeLibrary.js +89 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +91 -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 +189 -0
- 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 +327 -60
- 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-fallback/WebGLBackend.js +547 -29
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +0 -1
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +1 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +1 -1
- package/src/renderers/webgpu/WebGPUBackend.js +480 -49
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +34 -0
- package/src/renderers/webgpu/WebGPURenderer.js +35 -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 +59 -11
- 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 +10 -8
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +9 -1
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +5 -9
- package/src/renderers/webgpu/utils/WebGPUUtils.js +30 -0
- package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
- package/src/renderers/webxr/WebXRManager.js +7 -1
- package/src/textures/Data3DTexture.js +2 -2
- package/src/textures/Texture.js +4 -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/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/MMDLoader.js +0 -2298
- package/examples/jsm/shaders/MMDToonShader.js +0 -134
- 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
|
@@ -27,6 +27,8 @@ import { Vector4 } from '../../math/Vector4.js';
|
|
|
27
27
|
import { RenderTarget } from '../../core/RenderTarget.js';
|
|
28
28
|
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';
|
|
29
29
|
|
|
30
|
+
/** @module Renderer **/
|
|
31
|
+
|
|
30
32
|
const _scene = /*@__PURE__*/ new Scene();
|
|
31
33
|
const _drawingBufferSize = /*@__PURE__*/ new Vector2();
|
|
32
34
|
const _screen = /*@__PURE__*/ new Vector4();
|
|
@@ -34,10 +36,34 @@ const _frustum = /*@__PURE__*/ new Frustum();
|
|
|
34
36
|
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
|
|
35
37
|
const _vector4 = /*@__PURE__*/ new Vector4();
|
|
36
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Base class for renderers.
|
|
41
|
+
*/
|
|
37
42
|
class Renderer {
|
|
38
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Constructs a new renderer.
|
|
46
|
+
*
|
|
47
|
+
* @param {Backend} backend - The backend the renderer is targeting (e.g. WebGPU or WebGL 2).
|
|
48
|
+
* @param {Object} parameters - The configuration parameter.
|
|
49
|
+
* @param {Boolean} [parameters.logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
|
|
50
|
+
* @param {Boolean} [parameters.alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
|
|
51
|
+
* @param {Boolean} [parameters.depth=true] - Whether the default framebuffer should have a depth buffer or not.
|
|
52
|
+
* @param {Boolean} [parameters.stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
|
|
53
|
+
* @param {Boolean} [parameters.antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
|
|
54
|
+
* @param {Number} [parameters.samples=0] - When `antialias` is `true`, `4` samples are used by default. This parameter can set to any other integer value than 0
|
|
55
|
+
* to overwrite the default.
|
|
56
|
+
* @param {Function?} [parameters.getFallback=null] - This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
|
|
57
|
+
*/
|
|
39
58
|
constructor( backend, parameters = {} ) {
|
|
40
59
|
|
|
60
|
+
/**
|
|
61
|
+
* This flag can be used for type testing.
|
|
62
|
+
*
|
|
63
|
+
* @type {Boolean}
|
|
64
|
+
* @readonly
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
41
67
|
this.isRenderer = true;
|
|
42
68
|
|
|
43
69
|
//
|
|
@@ -52,32 +78,142 @@ class Renderer {
|
|
|
52
78
|
getFallback = null
|
|
53
79
|
} = parameters;
|
|
54
80
|
|
|
55
|
-
|
|
81
|
+
/**
|
|
82
|
+
* A reference to the canvas element the renderer is drawing to.
|
|
83
|
+
* This value of this property will automatically be created by
|
|
84
|
+
* the renderer.
|
|
85
|
+
*
|
|
86
|
+
* @type {HTMLCanvasElement|OffscreenCanvas}
|
|
87
|
+
*/
|
|
56
88
|
this.domElement = backend.getDomElement();
|
|
57
89
|
|
|
90
|
+
/**
|
|
91
|
+
* A reference to the current backend.
|
|
92
|
+
*
|
|
93
|
+
* @type {Backend}
|
|
94
|
+
*/
|
|
58
95
|
this.backend = backend;
|
|
59
96
|
|
|
97
|
+
/**
|
|
98
|
+
* The number of MSAA samples.
|
|
99
|
+
*
|
|
100
|
+
* @type {Number}
|
|
101
|
+
* @default 0
|
|
102
|
+
*/
|
|
60
103
|
this.samples = samples || ( antialias === true ) ? 4 : 0;
|
|
61
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Whether the renderer should automatically clear the current rendering target
|
|
107
|
+
* before execute a `render()` call. The target can be the canvas (default framebuffer)
|
|
108
|
+
* or the current bound render target (custom framebuffer).
|
|
109
|
+
*
|
|
110
|
+
* @type {Boolean}
|
|
111
|
+
* @default true
|
|
112
|
+
*/
|
|
62
113
|
this.autoClear = true;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
117
|
+
* should clear the color buffer.
|
|
118
|
+
*
|
|
119
|
+
* @type {Boolean}
|
|
120
|
+
* @default true
|
|
121
|
+
*/
|
|
63
122
|
this.autoClearColor = true;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
126
|
+
* should clear the depth buffer.
|
|
127
|
+
*
|
|
128
|
+
* @type {Boolean}
|
|
129
|
+
* @default true
|
|
130
|
+
*/
|
|
64
131
|
this.autoClearDepth = true;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
135
|
+
* should clear the stencil buffer.
|
|
136
|
+
*
|
|
137
|
+
* @type {Boolean}
|
|
138
|
+
* @default true
|
|
139
|
+
*/
|
|
65
140
|
this.autoClearStencil = true;
|
|
66
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Whether the default framebuffer should be transparent or opaque.
|
|
144
|
+
*
|
|
145
|
+
* @type {Boolean}
|
|
146
|
+
* @default true
|
|
147
|
+
*/
|
|
67
148
|
this.alpha = alpha;
|
|
68
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Whether logarithmic depth buffer is enabled or not.
|
|
152
|
+
*
|
|
153
|
+
* @type {Boolean}
|
|
154
|
+
* @default false
|
|
155
|
+
*/
|
|
69
156
|
this.logarithmicDepthBuffer = logarithmicDepthBuffer;
|
|
70
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Defines the output color space of the renderer.
|
|
160
|
+
*
|
|
161
|
+
* @type {String}
|
|
162
|
+
* @default SRGBColorSpace
|
|
163
|
+
*/
|
|
71
164
|
this.outputColorSpace = SRGBColorSpace;
|
|
72
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Defines the tone mapping of the renderer.
|
|
168
|
+
*
|
|
169
|
+
* @type {Number}
|
|
170
|
+
* @default NoToneMapping
|
|
171
|
+
*/
|
|
73
172
|
this.toneMapping = NoToneMapping;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Defines the tone mapping exposure.
|
|
176
|
+
*
|
|
177
|
+
* @type {Number}
|
|
178
|
+
* @default 1
|
|
179
|
+
*/
|
|
74
180
|
this.toneMappingExposure = 1.0;
|
|
75
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Whether the renderer should sort its render lists or not.
|
|
184
|
+
*
|
|
185
|
+
* Note: Sorting is used to attempt to properly render objects that have some degree of transparency.
|
|
186
|
+
* By definition, sorting objects may not work in all cases. Depending on the needs of application,
|
|
187
|
+
* it may be necessary to turn off sorting and use other methods to deal with transparency rendering
|
|
188
|
+
* e.g. manually determining each object's rendering order.
|
|
189
|
+
*
|
|
190
|
+
* @type {Boolean}
|
|
191
|
+
* @default true
|
|
192
|
+
*/
|
|
76
193
|
this.sortObjects = true;
|
|
77
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Whether the default framebuffer should have a depth buffer or not.
|
|
197
|
+
*
|
|
198
|
+
* @type {Boolean}
|
|
199
|
+
* @default true
|
|
200
|
+
*/
|
|
78
201
|
this.depth = depth;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Whether the default framebuffer should have a stencil buffer or not.
|
|
205
|
+
*
|
|
206
|
+
* @type {Boolean}
|
|
207
|
+
* @default false
|
|
208
|
+
*/
|
|
79
209
|
this.stencil = stencil;
|
|
80
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Holds a series of statistical information about the GPU memory
|
|
213
|
+
* and the rendering process. Useful for debugging and monitoring.
|
|
214
|
+
*
|
|
215
|
+
* @type {Boolean}
|
|
216
|
+
*/
|
|
81
217
|
this.info = new Info();
|
|
82
218
|
|
|
83
219
|
this.nodes = {
|
|
@@ -85,82 +221,449 @@ class Renderer {
|
|
|
85
221
|
modelNormalViewMatrix: null
|
|
86
222
|
};
|
|
87
223
|
|
|
224
|
+
/**
|
|
225
|
+
* The node library defines how certain library objects like materials, lights
|
|
226
|
+
* or tone mapping functions are mapped to node types. This is required since
|
|
227
|
+
* although instances of classes like `MeshBasicMaterial` or `PointLight` can
|
|
228
|
+
* be part of the scene graph, they are internally represented as nodes for
|
|
229
|
+
* further processing.
|
|
230
|
+
*
|
|
231
|
+
* @type {NodeLibrary}
|
|
232
|
+
*/
|
|
88
233
|
this.library = new NodeLibrary();
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* A map-like data structure for managing lights.
|
|
237
|
+
*
|
|
238
|
+
* @type {Lighting}
|
|
239
|
+
*/
|
|
89
240
|
this.lighting = new Lighting();
|
|
90
241
|
|
|
91
242
|
// internals
|
|
92
243
|
|
|
244
|
+
/**
|
|
245
|
+
* This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
|
|
246
|
+
*
|
|
247
|
+
* @private
|
|
248
|
+
* @type {Function}
|
|
249
|
+
*/
|
|
93
250
|
this._getFallback = getFallback;
|
|
94
251
|
|
|
252
|
+
/**
|
|
253
|
+
* The renderer's pixel ration.
|
|
254
|
+
*
|
|
255
|
+
* @private
|
|
256
|
+
* @type {Number}
|
|
257
|
+
* @default 1
|
|
258
|
+
*/
|
|
95
259
|
this._pixelRatio = 1;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* The width of the renderer's default framebuffer in logical pixel unit.
|
|
263
|
+
*
|
|
264
|
+
* @private
|
|
265
|
+
* @type {Number}
|
|
266
|
+
*/
|
|
96
267
|
this._width = this.domElement.width;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The height of the renderer's default framebuffer in logical pixel unit.
|
|
271
|
+
*
|
|
272
|
+
* @private
|
|
273
|
+
* @type {Number}
|
|
274
|
+
*/
|
|
97
275
|
this._height = this.domElement.height;
|
|
98
276
|
|
|
277
|
+
/**
|
|
278
|
+
* The viewport of the renderer in logical pixel unit.
|
|
279
|
+
*
|
|
280
|
+
* @private
|
|
281
|
+
* @type {Vector4}
|
|
282
|
+
*/
|
|
99
283
|
this._viewport = new Vector4( 0, 0, this._width, this._height );
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The scissor rectangle of the renderer in logical pixel unit.
|
|
287
|
+
*
|
|
288
|
+
* @private
|
|
289
|
+
* @type {Vector4}
|
|
290
|
+
*/
|
|
100
291
|
this._scissor = new Vector4( 0, 0, this._width, this._height );
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Whether the scissor test should be enabled or not.
|
|
295
|
+
*
|
|
296
|
+
* @private
|
|
297
|
+
* @type {Vector4}
|
|
298
|
+
*/
|
|
101
299
|
this._scissorTest = false;
|
|
102
300
|
|
|
301
|
+
/**
|
|
302
|
+
* A reference to a renderer module for managing shader attributes.
|
|
303
|
+
*
|
|
304
|
+
* @private
|
|
305
|
+
* @type {Attributes?}
|
|
306
|
+
* @default null
|
|
307
|
+
*/
|
|
103
308
|
this._attributes = null;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* A reference to a renderer module for managing geometries.
|
|
312
|
+
*
|
|
313
|
+
* @private
|
|
314
|
+
* @type {Geometries?}
|
|
315
|
+
* @default null
|
|
316
|
+
*/
|
|
104
317
|
this._geometries = null;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* A reference to a renderer module for managing node related logic.
|
|
321
|
+
*
|
|
322
|
+
* @private
|
|
323
|
+
* @type {Nodes?}
|
|
324
|
+
* @default null
|
|
325
|
+
*/
|
|
105
326
|
this._nodes = null;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A reference to a renderer module for managing the internal animation loop.
|
|
330
|
+
*
|
|
331
|
+
* @private
|
|
332
|
+
* @type {Animation?}
|
|
333
|
+
* @default null
|
|
334
|
+
*/
|
|
106
335
|
this._animation = null;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* A reference to a renderer module for managing shader program bindings.
|
|
339
|
+
*
|
|
340
|
+
* @private
|
|
341
|
+
* @type {Bindings?}
|
|
342
|
+
* @default null
|
|
343
|
+
*/
|
|
107
344
|
this._bindings = null;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* A reference to a renderer module for managing render objects.
|
|
348
|
+
*
|
|
349
|
+
* @private
|
|
350
|
+
* @type {RenderObjects?}
|
|
351
|
+
* @default null
|
|
352
|
+
*/
|
|
108
353
|
this._objects = null;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* A reference to a renderer module for managing render and cmopute pipelines.
|
|
357
|
+
*
|
|
358
|
+
* @private
|
|
359
|
+
* @type {Pipelines?}
|
|
360
|
+
* @default null
|
|
361
|
+
*/
|
|
109
362
|
this._pipelines = null;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* A reference to a renderer module for managing render bundles.
|
|
366
|
+
*
|
|
367
|
+
* @private
|
|
368
|
+
* @type {RenderBundles?}
|
|
369
|
+
* @default null
|
|
370
|
+
*/
|
|
110
371
|
this._bundles = null;
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* A reference to a renderer module for managing render lists.
|
|
375
|
+
*
|
|
376
|
+
* @private
|
|
377
|
+
* @type {RenderLists?}
|
|
378
|
+
* @default null
|
|
379
|
+
*/
|
|
111
380
|
this._renderLists = null;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* A reference to a renderer module for managing render contexts.
|
|
384
|
+
*
|
|
385
|
+
* @private
|
|
386
|
+
* @type {RenderContexts?}
|
|
387
|
+
* @default null
|
|
388
|
+
*/
|
|
112
389
|
this._renderContexts = null;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* A reference to a renderer module for managing textures.
|
|
393
|
+
*
|
|
394
|
+
* @private
|
|
395
|
+
* @type {Textures?}
|
|
396
|
+
* @default null
|
|
397
|
+
*/
|
|
113
398
|
this._textures = null;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* A reference to a renderer module for backgrounds.
|
|
402
|
+
*
|
|
403
|
+
* @private
|
|
404
|
+
* @type {Background?}
|
|
405
|
+
* @default null
|
|
406
|
+
*/
|
|
114
407
|
this._background = null;
|
|
115
408
|
|
|
409
|
+
/**
|
|
410
|
+
* This fullscreen quad is used for internal render passes
|
|
411
|
+
* like the tone mapping and color space output pass.
|
|
412
|
+
*
|
|
413
|
+
* @private
|
|
414
|
+
* @type {QuadMesh}
|
|
415
|
+
*/
|
|
116
416
|
this._quad = new QuadMesh( new NodeMaterial() );
|
|
117
|
-
this._quad.material.
|
|
118
|
-
|
|
417
|
+
this._quad.material.name = 'Renderer_output';
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* A reference to the current render context.
|
|
421
|
+
*
|
|
422
|
+
* @private
|
|
423
|
+
* @type {RenderContext?}
|
|
424
|
+
* @default null
|
|
425
|
+
*/
|
|
119
426
|
this._currentRenderContext = null;
|
|
120
427
|
|
|
428
|
+
/**
|
|
429
|
+
* A custom sort function for the opaque render list.
|
|
430
|
+
*
|
|
431
|
+
* @private
|
|
432
|
+
* @type {Function?}
|
|
433
|
+
* @default null
|
|
434
|
+
*/
|
|
121
435
|
this._opaqueSort = null;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* A custom sort function for the transparent render list.
|
|
439
|
+
*
|
|
440
|
+
* @private
|
|
441
|
+
* @type {Function?}
|
|
442
|
+
* @default null
|
|
443
|
+
*/
|
|
122
444
|
this._transparentSort = null;
|
|
123
445
|
|
|
446
|
+
/**
|
|
447
|
+
* The framebuffer target.
|
|
448
|
+
*
|
|
449
|
+
* @private
|
|
450
|
+
* @type {RenderTarget?}
|
|
451
|
+
* @default null
|
|
452
|
+
*/
|
|
124
453
|
this._frameBufferTarget = null;
|
|
125
454
|
|
|
126
455
|
const alphaClear = this.alpha === true ? 0 : 1;
|
|
127
456
|
|
|
457
|
+
/**
|
|
458
|
+
* The clear color value.
|
|
459
|
+
*
|
|
460
|
+
* @private
|
|
461
|
+
* @type {Color4}
|
|
462
|
+
*/
|
|
128
463
|
this._clearColor = new Color4( 0, 0, 0, alphaClear );
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* The clear depth value.
|
|
467
|
+
*
|
|
468
|
+
* @private
|
|
469
|
+
* @type {Number}
|
|
470
|
+
* @default 1
|
|
471
|
+
*/
|
|
129
472
|
this._clearDepth = 1;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* The clear stencil value.
|
|
476
|
+
*
|
|
477
|
+
* @private
|
|
478
|
+
* @type {Number}
|
|
479
|
+
* @default 0
|
|
480
|
+
*/
|
|
130
481
|
this._clearStencil = 0;
|
|
131
482
|
|
|
483
|
+
/**
|
|
484
|
+
* The current render target.
|
|
485
|
+
*
|
|
486
|
+
* @private
|
|
487
|
+
* @type {RenderTarget?}
|
|
488
|
+
* @default null
|
|
489
|
+
*/
|
|
132
490
|
this._renderTarget = null;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* The active cube face.
|
|
494
|
+
*
|
|
495
|
+
* @private
|
|
496
|
+
* @type {Number}
|
|
497
|
+
* @default 0
|
|
498
|
+
*/
|
|
133
499
|
this._activeCubeFace = 0;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* The active mipmap level.
|
|
503
|
+
*
|
|
504
|
+
* @private
|
|
505
|
+
* @type {Number}
|
|
506
|
+
* @default 0
|
|
507
|
+
*/
|
|
134
508
|
this._activeMipmapLevel = 0;
|
|
135
509
|
|
|
510
|
+
/**
|
|
511
|
+
* The MRT setting.
|
|
512
|
+
*
|
|
513
|
+
* @private
|
|
514
|
+
* @type {MRTNode?}
|
|
515
|
+
* @default null
|
|
516
|
+
*/
|
|
136
517
|
this._mrt = null;
|
|
137
518
|
|
|
519
|
+
/**
|
|
520
|
+
* This function defines how a render object is going
|
|
521
|
+
* to be rendered.
|
|
522
|
+
*
|
|
523
|
+
* @private
|
|
524
|
+
* @type {Function?}
|
|
525
|
+
* @default null
|
|
526
|
+
*/
|
|
138
527
|
this._renderObjectFunction = null;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Used to keep track of the current render object function.
|
|
531
|
+
*
|
|
532
|
+
* @private
|
|
533
|
+
* @type {Function?}
|
|
534
|
+
* @default null
|
|
535
|
+
*/
|
|
139
536
|
this._currentRenderObjectFunction = null;
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Used to keep track of the current render bundle.
|
|
540
|
+
*
|
|
541
|
+
* @private
|
|
542
|
+
* @type {RenderBundle?}
|
|
543
|
+
* @default null
|
|
544
|
+
*/
|
|
140
545
|
this._currentRenderBundle = null;
|
|
141
546
|
|
|
547
|
+
/**
|
|
548
|
+
* Next to `_renderObjectFunction()`, this function provides another hook
|
|
549
|
+
* for influening the render process of a render object. It is meant for internal
|
|
550
|
+
* use and only relevant for `compileAsync()` right now. Instead of using
|
|
551
|
+
* the default logic of `_renderObjectDirect()` which actually draws the render object,
|
|
552
|
+
* a different function might be used which performs no draw but just the node
|
|
553
|
+
* and pipeline updates.
|
|
554
|
+
*
|
|
555
|
+
* @private
|
|
556
|
+
* @type {Function?}
|
|
557
|
+
* @default null
|
|
558
|
+
*/
|
|
142
559
|
this._handleObjectFunction = this._renderObjectDirect;
|
|
143
560
|
|
|
561
|
+
/**
|
|
562
|
+
* Indicates whether the device has been lost or not. In WebGL terms, the device
|
|
563
|
+
* lost is considered as a context lost. When this is set to `true`, rendering
|
|
564
|
+
* isn't possible anymore.
|
|
565
|
+
*
|
|
566
|
+
* @private
|
|
567
|
+
* @type {Boolean}
|
|
568
|
+
* @default false
|
|
569
|
+
*/
|
|
144
570
|
this._isDeviceLost = false;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* A callback function that defines what should happen when a device/context lost occurs.
|
|
574
|
+
*
|
|
575
|
+
* @type {Function}
|
|
576
|
+
*/
|
|
145
577
|
this.onDeviceLost = this._onDeviceLost;
|
|
146
578
|
|
|
579
|
+
/**
|
|
580
|
+
* Whether the renderer has been initialized or not.
|
|
581
|
+
*
|
|
582
|
+
* @private
|
|
583
|
+
* @type {Boolean}
|
|
584
|
+
* @default false
|
|
585
|
+
*/
|
|
147
586
|
this._initialized = false;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* A reference to the promise which initializes the renderer.
|
|
590
|
+
*
|
|
591
|
+
* @private
|
|
592
|
+
* @type {Promise?}
|
|
593
|
+
* @default null
|
|
594
|
+
*/
|
|
148
595
|
this._initPromise = null;
|
|
149
596
|
|
|
597
|
+
/**
|
|
598
|
+
* An array of compilation promises which are used in `compileAsync()`.
|
|
599
|
+
*
|
|
600
|
+
* @private
|
|
601
|
+
* @type {Array<Promise>?}
|
|
602
|
+
* @default null
|
|
603
|
+
*/
|
|
150
604
|
this._compilationPromises = null;
|
|
151
605
|
|
|
606
|
+
/**
|
|
607
|
+
* Whether the renderer should render transparent render objects or not.
|
|
608
|
+
*
|
|
609
|
+
* @type {Boolean}
|
|
610
|
+
* @default true
|
|
611
|
+
*/
|
|
152
612
|
this.transparent = true;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Whether the renderer should render opaque render objects or not.
|
|
616
|
+
*
|
|
617
|
+
* @type {Boolean}
|
|
618
|
+
* @default true
|
|
619
|
+
*/
|
|
153
620
|
this.opaque = true;
|
|
154
621
|
|
|
622
|
+
/**
|
|
623
|
+
* Shadow map configuration
|
|
624
|
+
* @typedef {Object} ShadowMapConfig
|
|
625
|
+
* @property {Boolean} enabled - Whether to globally enable shadows or not.
|
|
626
|
+
* @property {Number} type - The shadow map type.
|
|
627
|
+
*/
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* The renderer's shadow configuration.
|
|
631
|
+
*
|
|
632
|
+
* @type {module:Renderer~ShadowMapConfig}
|
|
633
|
+
*/
|
|
155
634
|
this.shadowMap = {
|
|
156
635
|
enabled: false,
|
|
157
636
|
type: PCFShadowMap
|
|
158
637
|
};
|
|
159
638
|
|
|
639
|
+
/**
|
|
640
|
+
* XR configuration.
|
|
641
|
+
* @typedef {Object} XRConfig
|
|
642
|
+
* @property {Boolean} enabled - Whether to globally enable XR or not.
|
|
643
|
+
*/
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* The renderer's XR configuration.
|
|
647
|
+
*
|
|
648
|
+
* @type {module:Renderer~XRConfig}
|
|
649
|
+
*/
|
|
160
650
|
this.xr = {
|
|
161
651
|
enabled: false
|
|
162
652
|
};
|
|
163
653
|
|
|
654
|
+
/**
|
|
655
|
+
* Debug configuration.
|
|
656
|
+
* @typedef {Object} DebugConfig
|
|
657
|
+
* @property {Boolean} checkShaderErrors - Whether shader errors should be checked or not.
|
|
658
|
+
* @property {Function} onShaderError - A callback function that is executed when a shader error happens. Only supported with WebGL 2 right now.
|
|
659
|
+
* @property {Function} getShaderAsync - Allows the get the raw shader code for the given scene, camerea and 3D object.
|
|
660
|
+
*/
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* The renderer's debug configuration.
|
|
664
|
+
*
|
|
665
|
+
* @type {module:Renderer~DebugConfig}
|
|
666
|
+
*/
|
|
164
667
|
this.debug = {
|
|
165
668
|
checkShaderErrors: true,
|
|
166
669
|
onShaderError: null,
|
|
@@ -184,6 +687,12 @@ class Renderer {
|
|
|
184
687
|
|
|
185
688
|
}
|
|
186
689
|
|
|
690
|
+
/**
|
|
691
|
+
* Initializes the renderer so it is ready for usage.
|
|
692
|
+
*
|
|
693
|
+
* @async
|
|
694
|
+
* @return {Promise} A Promise that resolves when the renderer has been initialized.
|
|
695
|
+
*/
|
|
187
696
|
async init() {
|
|
188
697
|
|
|
189
698
|
if ( this._initialized ) {
|
|
@@ -259,12 +768,35 @@ class Renderer {
|
|
|
259
768
|
|
|
260
769
|
}
|
|
261
770
|
|
|
771
|
+
/**
|
|
772
|
+
* The coordinate system of the renderer. The value of this property
|
|
773
|
+
* depends on the selected backend. Either `THREE.WebGLCoordinateSystem` or
|
|
774
|
+
* `THREE.WebGPUCoordinateSystem`.
|
|
775
|
+
*
|
|
776
|
+
* @readonly
|
|
777
|
+
* @type {Number}
|
|
778
|
+
*/
|
|
262
779
|
get coordinateSystem() {
|
|
263
780
|
|
|
264
781
|
return this.backend.coordinateSystem;
|
|
265
782
|
|
|
266
783
|
}
|
|
267
784
|
|
|
785
|
+
/**
|
|
786
|
+
* Compiles all materials in the given scene. This can be useful to avoid a
|
|
787
|
+
* phenomenon which is called "shader compilation stutter", which occurs when
|
|
788
|
+
* rendering an object with a new shader for the first time.
|
|
789
|
+
*
|
|
790
|
+
* If you want to add a 3D object to an existing scene, use the third optional
|
|
791
|
+
* parameter for applying the target scene. Note that the (target) scene's lighting
|
|
792
|
+
* and environment must be configured before calling this method.
|
|
793
|
+
*
|
|
794
|
+
* @async
|
|
795
|
+
* @param {Object3D} scene - The scene or 3D object to precompile.
|
|
796
|
+
* @param {Camera} camera - The camera that is used to render the scene.
|
|
797
|
+
* @param {Scene} targetScene - If the first argument is a 3D object, this parameter must represent the scene the 3D object is going to be added.
|
|
798
|
+
* @return {Promise} A Promise that resolves when the compile has been finished.
|
|
799
|
+
*/
|
|
268
800
|
async compileAsync( scene, camera, targetScene = null ) {
|
|
269
801
|
|
|
270
802
|
if ( this._isDeviceLost === true ) return;
|
|
@@ -361,10 +893,6 @@ class Renderer {
|
|
|
361
893
|
|
|
362
894
|
//
|
|
363
895
|
|
|
364
|
-
this._nodes.updateScene( sceneRef );
|
|
365
|
-
|
|
366
|
-
//
|
|
367
|
-
|
|
368
896
|
this._background.update( sceneRef, renderList, renderContext );
|
|
369
897
|
|
|
370
898
|
// process render lists
|
|
@@ -393,6 +921,14 @@ class Renderer {
|
|
|
393
921
|
|
|
394
922
|
}
|
|
395
923
|
|
|
924
|
+
/**
|
|
925
|
+
* Renders the scene in an async fashion.
|
|
926
|
+
*
|
|
927
|
+
* @async
|
|
928
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
929
|
+
* @param {Camera} camera - The camera.
|
|
930
|
+
* @return {Promise} A Promise that resolves when the render has been finished.
|
|
931
|
+
*/
|
|
396
932
|
async renderAsync( scene, camera ) {
|
|
397
933
|
|
|
398
934
|
if ( this._initialized === false ) await this.init();
|
|
@@ -403,12 +939,25 @@ class Renderer {
|
|
|
403
939
|
|
|
404
940
|
}
|
|
405
941
|
|
|
942
|
+
/**
|
|
943
|
+
* Can be used to synchronize CPU operations with GPU tasks. So when this method is called,
|
|
944
|
+
* the CPU waits for the GPU to complete its operation (e.g. a compute task).
|
|
945
|
+
*
|
|
946
|
+
* @async
|
|
947
|
+
* @return {Promise} A Promise that resolves when synchronization has been finished.
|
|
948
|
+
*/
|
|
406
949
|
async waitForGPU() {
|
|
407
950
|
|
|
408
951
|
await this.backend.waitForGPU();
|
|
409
952
|
|
|
410
953
|
}
|
|
411
954
|
|
|
955
|
+
/**
|
|
956
|
+
* Sets the given MRT configuration.
|
|
957
|
+
*
|
|
958
|
+
* @param {MRTNode} mrt - The MRT node to set.
|
|
959
|
+
* @return {Renderer} A reference to this renderer.
|
|
960
|
+
*/
|
|
412
961
|
setMRT( mrt ) {
|
|
413
962
|
|
|
414
963
|
this._mrt = mrt;
|
|
@@ -417,12 +966,23 @@ class Renderer {
|
|
|
417
966
|
|
|
418
967
|
}
|
|
419
968
|
|
|
969
|
+
/**
|
|
970
|
+
* Returns the MRT configuration.
|
|
971
|
+
*
|
|
972
|
+
* @return {MRTNode} The MRT configuration.
|
|
973
|
+
*/
|
|
420
974
|
getMRT() {
|
|
421
975
|
|
|
422
976
|
return this._mrt;
|
|
423
977
|
|
|
424
978
|
}
|
|
425
979
|
|
|
980
|
+
/**
|
|
981
|
+
* Default implementation of the device lost callback.
|
|
982
|
+
*
|
|
983
|
+
* @private
|
|
984
|
+
* @param {Object} info - Information about the context lost.
|
|
985
|
+
*/
|
|
426
986
|
_onDeviceLost( info ) {
|
|
427
987
|
|
|
428
988
|
let errorMessage = `THREE.WebGPURenderer: ${info.api} Device Lost:\n\nMessage: ${info.message}`;
|
|
@@ -439,7 +999,14 @@ class Renderer {
|
|
|
439
999
|
|
|
440
1000
|
}
|
|
441
1001
|
|
|
442
|
-
|
|
1002
|
+
/**
|
|
1003
|
+
* Renders the given render bundle.
|
|
1004
|
+
*
|
|
1005
|
+
* @private
|
|
1006
|
+
* @param {Object} bundle - Render bundle data.
|
|
1007
|
+
* @param {Scene} sceneRef - The scene the render bundle belongs to.
|
|
1008
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
1009
|
+
*/
|
|
443
1010
|
_renderBundle( bundle, sceneRef, lightsNode ) {
|
|
444
1011
|
|
|
445
1012
|
const { bundleGroup, camera, renderList } = bundle;
|
|
@@ -511,6 +1078,18 @@ class Renderer {
|
|
|
511
1078
|
|
|
512
1079
|
}
|
|
513
1080
|
|
|
1081
|
+
/**
|
|
1082
|
+
* Renders the scene or 3D object with the given camera. This method can only be called
|
|
1083
|
+
* if the renderer has been initialized.
|
|
1084
|
+
*
|
|
1085
|
+
* The target of the method is the default framebuffer (meaning the canvas)
|
|
1086
|
+
* or alternatively a render target when specified via `setRenderTarget()`.
|
|
1087
|
+
*
|
|
1088
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
1089
|
+
* @param {Camera} camera - The camera to render the scene with.
|
|
1090
|
+
* @return {Promise?} A Promise that resolve when the scene has been rendered.
|
|
1091
|
+
* Only returned when the renderer has not been initialized.
|
|
1092
|
+
*/
|
|
514
1093
|
render( scene, camera ) {
|
|
515
1094
|
|
|
516
1095
|
if ( this._initialized === false ) {
|
|
@@ -525,6 +1104,14 @@ class Renderer {
|
|
|
525
1104
|
|
|
526
1105
|
}
|
|
527
1106
|
|
|
1107
|
+
/**
|
|
1108
|
+
* Returns an internal render target which is used when computing the output tone mapping
|
|
1109
|
+
* and color space conversion. Unlike in `WebGLRenderer`, this is done in a separate render
|
|
1110
|
+
* pass and not inline to achieve more correct results.
|
|
1111
|
+
*
|
|
1112
|
+
* @private
|
|
1113
|
+
* @return {RenderTarget?} The render target. The method returns `null` if no output conversion should be applied.
|
|
1114
|
+
*/
|
|
528
1115
|
_getFrameBufferTarget() {
|
|
529
1116
|
|
|
530
1117
|
const { currentToneMapping, currentColorSpace } = this;
|
|
@@ -572,6 +1159,15 @@ class Renderer {
|
|
|
572
1159
|
|
|
573
1160
|
}
|
|
574
1161
|
|
|
1162
|
+
/**
|
|
1163
|
+
* Renders the scene or 3D object with the given camera.
|
|
1164
|
+
*
|
|
1165
|
+
* @private
|
|
1166
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
1167
|
+
* @param {Camera} camera - The camera to render the scene with.
|
|
1168
|
+
* @param {Boolean} [useFrameBufferTarget=true] - Whether to use a framebuffer target or not.
|
|
1169
|
+
* @return {RenderContext} The current render context.
|
|
1170
|
+
*/
|
|
575
1171
|
_renderScene( scene, camera, useFrameBufferTarget = true ) {
|
|
576
1172
|
|
|
577
1173
|
if ( this._isDeviceLost === true ) return;
|
|
@@ -737,10 +1333,6 @@ class Renderer {
|
|
|
737
1333
|
|
|
738
1334
|
//
|
|
739
1335
|
|
|
740
|
-
this._nodes.updateScene( sceneRef );
|
|
741
|
-
|
|
742
|
-
//
|
|
743
|
-
|
|
744
1336
|
this._background.update( sceneRef, renderList, renderContext );
|
|
745
1337
|
|
|
746
1338
|
//
|
|
@@ -801,24 +1393,48 @@ class Renderer {
|
|
|
801
1393
|
|
|
802
1394
|
}
|
|
803
1395
|
|
|
1396
|
+
/**
|
|
1397
|
+
* Returns the maximum available anisotropy for texture filtering.
|
|
1398
|
+
*
|
|
1399
|
+
* @return {Number} The maximum available anisotropy.
|
|
1400
|
+
*/
|
|
804
1401
|
getMaxAnisotropy() {
|
|
805
1402
|
|
|
806
1403
|
return this.backend.getMaxAnisotropy();
|
|
807
1404
|
|
|
808
1405
|
}
|
|
809
1406
|
|
|
1407
|
+
/**
|
|
1408
|
+
* Returns the active cube face.
|
|
1409
|
+
*
|
|
1410
|
+
* @return {Number} The active cube face.
|
|
1411
|
+
*/
|
|
810
1412
|
getActiveCubeFace() {
|
|
811
1413
|
|
|
812
1414
|
return this._activeCubeFace;
|
|
813
1415
|
|
|
814
1416
|
}
|
|
815
1417
|
|
|
1418
|
+
/**
|
|
1419
|
+
* Returns the active mipmap level.
|
|
1420
|
+
*
|
|
1421
|
+
* @return {Number} The active mipmap level.
|
|
1422
|
+
*/
|
|
816
1423
|
getActiveMipmapLevel() {
|
|
817
1424
|
|
|
818
1425
|
return this._activeMipmapLevel;
|
|
819
1426
|
|
|
820
1427
|
}
|
|
821
1428
|
|
|
1429
|
+
/**
|
|
1430
|
+
* Applications are advised to always define the animation loop
|
|
1431
|
+
* with this method and not manually with `requestAnimationFrame()`
|
|
1432
|
+
* for best compatibility.
|
|
1433
|
+
*
|
|
1434
|
+
* @async
|
|
1435
|
+
* @param {Function} callback - The application's animation loop.
|
|
1436
|
+
* @return {Promise} A Promise that resolves when the set has been exeucted.
|
|
1437
|
+
*/
|
|
822
1438
|
async setAnimationLoop( callback ) {
|
|
823
1439
|
|
|
824
1440
|
if ( this._initialized === false ) await this.init();
|
|
@@ -827,36 +1443,71 @@ class Renderer {
|
|
|
827
1443
|
|
|
828
1444
|
}
|
|
829
1445
|
|
|
1446
|
+
/**
|
|
1447
|
+
* Can be used to transfer buffer data from a storage buffer attribute
|
|
1448
|
+
* from the GPU to the CPU in context of compute shaders.
|
|
1449
|
+
*
|
|
1450
|
+
* @async
|
|
1451
|
+
* @param {StorageBufferAttribute} attribute - The storage buffer attribute.
|
|
1452
|
+
* @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
|
|
1453
|
+
*/
|
|
830
1454
|
async getArrayBufferAsync( attribute ) {
|
|
831
1455
|
|
|
832
1456
|
return await this.backend.getArrayBufferAsync( attribute );
|
|
833
1457
|
|
|
834
1458
|
}
|
|
835
1459
|
|
|
1460
|
+
/**
|
|
1461
|
+
* Returns the rendering context.
|
|
1462
|
+
*
|
|
1463
|
+
* @return {GPUCanvasContext|WebGL2RenderingContext} The rendering context.
|
|
1464
|
+
*/
|
|
836
1465
|
getContext() {
|
|
837
1466
|
|
|
838
1467
|
return this.backend.getContext();
|
|
839
1468
|
|
|
840
1469
|
}
|
|
841
1470
|
|
|
1471
|
+
/**
|
|
1472
|
+
* Returns the pixel ratio.
|
|
1473
|
+
*
|
|
1474
|
+
* @return {Number} The pixel ratio.
|
|
1475
|
+
*/
|
|
842
1476
|
getPixelRatio() {
|
|
843
1477
|
|
|
844
1478
|
return this._pixelRatio;
|
|
845
1479
|
|
|
846
1480
|
}
|
|
847
1481
|
|
|
1482
|
+
/**
|
|
1483
|
+
* Returns the drawing buffer size in physical pixels. This method honors the pixel ratio.
|
|
1484
|
+
*
|
|
1485
|
+
* @param {Vector2} target - The method writes the result in this target object.
|
|
1486
|
+
* @return {Vector2} The drawing buffer size.
|
|
1487
|
+
*/
|
|
848
1488
|
getDrawingBufferSize( target ) {
|
|
849
1489
|
|
|
850
1490
|
return target.set( this._width * this._pixelRatio, this._height * this._pixelRatio ).floor();
|
|
851
1491
|
|
|
852
1492
|
}
|
|
853
1493
|
|
|
1494
|
+
/**
|
|
1495
|
+
* Returns the renderer's size in logical pixels. This method does not honor the pixel ratio.
|
|
1496
|
+
*
|
|
1497
|
+
* @param {Vector2} target - The method writes the result in this target object.
|
|
1498
|
+
* @return {Vector2} The drawing buffer size.
|
|
1499
|
+
*/
|
|
854
1500
|
getSize( target ) {
|
|
855
1501
|
|
|
856
1502
|
return target.set( this._width, this._height );
|
|
857
1503
|
|
|
858
1504
|
}
|
|
859
1505
|
|
|
1506
|
+
/**
|
|
1507
|
+
* Sets the given pixel ration and resizes the canvas if necessary.
|
|
1508
|
+
*
|
|
1509
|
+
* @param {Number} [value=1] - The pixel ratio.
|
|
1510
|
+
*/
|
|
860
1511
|
setPixelRatio( value = 1 ) {
|
|
861
1512
|
|
|
862
1513
|
if ( this._pixelRatio === value ) return;
|
|
@@ -867,6 +1518,19 @@ class Renderer {
|
|
|
867
1518
|
|
|
868
1519
|
}
|
|
869
1520
|
|
|
1521
|
+
/**
|
|
1522
|
+
* This method allows to define the drawing buffer size by specifying
|
|
1523
|
+
* width, height and pixel ratio all at once. The size of the drawing
|
|
1524
|
+
* buffer is computed with this formula:
|
|
1525
|
+
* ````
|
|
1526
|
+
* size.x = width * pixelRatio;
|
|
1527
|
+
* size.y = height * pixelRatio;
|
|
1528
|
+
*```
|
|
1529
|
+
*
|
|
1530
|
+
* @param {Number} width - The width in logical pixels.
|
|
1531
|
+
* @param {Number} height - The height in logical pixels.
|
|
1532
|
+
* @param {Number} pixelRatio - The pixel ratio.
|
|
1533
|
+
*/
|
|
870
1534
|
setDrawingBufferSize( width, height, pixelRatio ) {
|
|
871
1535
|
|
|
872
1536
|
this._width = width;
|
|
@@ -883,6 +1547,13 @@ class Renderer {
|
|
|
883
1547
|
|
|
884
1548
|
}
|
|
885
1549
|
|
|
1550
|
+
/**
|
|
1551
|
+
* Sets the size of the renderer.
|
|
1552
|
+
*
|
|
1553
|
+
* @param {Number} width - The width in logical pixels.
|
|
1554
|
+
* @param {Number} height - The height in logical pixels.
|
|
1555
|
+
* @param {Boolean} [updateStyle=true] - Whether to update the `style` attribute of the canvas or not.
|
|
1556
|
+
*/
|
|
886
1557
|
setSize( width, height, updateStyle = true ) {
|
|
887
1558
|
|
|
888
1559
|
this._width = width;
|
|
@@ -904,18 +1575,36 @@ class Renderer {
|
|
|
904
1575
|
|
|
905
1576
|
}
|
|
906
1577
|
|
|
1578
|
+
/**
|
|
1579
|
+
* Defines a manual sort function for the opaque render list.
|
|
1580
|
+
* Pass `null` to use the default sort.
|
|
1581
|
+
*
|
|
1582
|
+
* @param {Function} method - The sort function.
|
|
1583
|
+
*/
|
|
907
1584
|
setOpaqueSort( method ) {
|
|
908
1585
|
|
|
909
1586
|
this._opaqueSort = method;
|
|
910
1587
|
|
|
911
1588
|
}
|
|
912
1589
|
|
|
1590
|
+
/**
|
|
1591
|
+
* Defines a manual sort function for the transparent render list.
|
|
1592
|
+
* Pass `null` to use the default sort.
|
|
1593
|
+
*
|
|
1594
|
+
* @param {Function} method - The sort function.
|
|
1595
|
+
*/
|
|
913
1596
|
setTransparentSort( method ) {
|
|
914
1597
|
|
|
915
1598
|
this._transparentSort = method;
|
|
916
1599
|
|
|
917
1600
|
}
|
|
918
1601
|
|
|
1602
|
+
/**
|
|
1603
|
+
* Returns the scissor rectangle.
|
|
1604
|
+
*
|
|
1605
|
+
* @param {Vector4} target - The method writes the result in this target object.
|
|
1606
|
+
* @return {Vector4} The scissor rectangle.
|
|
1607
|
+
*/
|
|
919
1608
|
getScissor( target ) {
|
|
920
1609
|
|
|
921
1610
|
const scissor = this._scissor;
|
|
@@ -929,6 +1618,15 @@ class Renderer {
|
|
|
929
1618
|
|
|
930
1619
|
}
|
|
931
1620
|
|
|
1621
|
+
/**
|
|
1622
|
+
* Defines the scissor rectangle.
|
|
1623
|
+
*
|
|
1624
|
+
* @param {Number | Vector4} x - The horizontal coordinate for the lower left corner of the box in logical pixel unit.
|
|
1625
|
+
* Instead of passing four arguments, the method also works with a single four-dimensional vector.
|
|
1626
|
+
* @param {Number} y - The vertical coordinate for the lower left corner of the box in logical pixel unit.
|
|
1627
|
+
* @param {Number} width - The width of the scissor box in logical pixel unit.
|
|
1628
|
+
* @param {Number} height - The height of the scissor box in logical pixel unit.
|
|
1629
|
+
*/
|
|
932
1630
|
setScissor( x, y, width, height ) {
|
|
933
1631
|
|
|
934
1632
|
const scissor = this._scissor;
|
|
@@ -945,12 +1643,22 @@ class Renderer {
|
|
|
945
1643
|
|
|
946
1644
|
}
|
|
947
1645
|
|
|
1646
|
+
/**
|
|
1647
|
+
* Returns the scissor test value.
|
|
1648
|
+
*
|
|
1649
|
+
* @return {Boolean} Whether the scissor test should be enabled or not.
|
|
1650
|
+
*/
|
|
948
1651
|
getScissorTest() {
|
|
949
1652
|
|
|
950
1653
|
return this._scissorTest;
|
|
951
1654
|
|
|
952
1655
|
}
|
|
953
1656
|
|
|
1657
|
+
/**
|
|
1658
|
+
* Defines the scissor test.
|
|
1659
|
+
*
|
|
1660
|
+
* @param {Boolean} boolean - Whether the scissor test should be enabled or not.
|
|
1661
|
+
*/
|
|
954
1662
|
setScissorTest( boolean ) {
|
|
955
1663
|
|
|
956
1664
|
this._scissorTest = boolean;
|
|
@@ -959,12 +1667,28 @@ class Renderer {
|
|
|
959
1667
|
|
|
960
1668
|
}
|
|
961
1669
|
|
|
1670
|
+
/**
|
|
1671
|
+
* Returns the viewport definition.
|
|
1672
|
+
*
|
|
1673
|
+
* @param {Vector4} target - The method writes the result in this target object.
|
|
1674
|
+
* @return {Vector4} The viewport definition.
|
|
1675
|
+
*/
|
|
962
1676
|
getViewport( target ) {
|
|
963
1677
|
|
|
964
1678
|
return target.copy( this._viewport );
|
|
965
1679
|
|
|
966
1680
|
}
|
|
967
1681
|
|
|
1682
|
+
/**
|
|
1683
|
+
* Defines the viewport.
|
|
1684
|
+
*
|
|
1685
|
+
* @param {Number | Vector4} x - The horizontal coordinate for the lower left corner of the viewport origin in logical pixel unit.
|
|
1686
|
+
* @param {Number} y - The vertical coordinate for the lower left corner of the viewport origin in logical pixel unit.
|
|
1687
|
+
* @param {Number} width - The width of the viewport in logical pixel unit.
|
|
1688
|
+
* @param {Number} height - The height of the viewport in logical pixel unit.
|
|
1689
|
+
* @param {Number} minDepth - The minimum depth value of the viewport. WebGPU only.
|
|
1690
|
+
* @param {Number} maxDepth - The maximum depth value of the viewport. WebGPU only.
|
|
1691
|
+
*/
|
|
968
1692
|
setViewport( x, y, width, height, minDepth = 0, maxDepth = 1 ) {
|
|
969
1693
|
|
|
970
1694
|
const viewport = this._viewport;
|
|
@@ -984,12 +1708,24 @@ class Renderer {
|
|
|
984
1708
|
|
|
985
1709
|
}
|
|
986
1710
|
|
|
1711
|
+
/**
|
|
1712
|
+
* Returns the clear color.
|
|
1713
|
+
*
|
|
1714
|
+
* @param {Color} target - The method writes the result in this target object.
|
|
1715
|
+
* @return {Color} The clear color.
|
|
1716
|
+
*/
|
|
987
1717
|
getClearColor( target ) {
|
|
988
1718
|
|
|
989
1719
|
return target.copy( this._clearColor );
|
|
990
1720
|
|
|
991
1721
|
}
|
|
992
1722
|
|
|
1723
|
+
/**
|
|
1724
|
+
* Defines the clear color and optionally the clear alpha.
|
|
1725
|
+
*
|
|
1726
|
+
* @param {Color} color - The clear color.
|
|
1727
|
+
* @param {Number} [alpha=1] - The clear alpha.
|
|
1728
|
+
*/
|
|
993
1729
|
setClearColor( color, alpha = 1 ) {
|
|
994
1730
|
|
|
995
1731
|
this._clearColor.set( color );
|
|
@@ -997,42 +1733,80 @@ class Renderer {
|
|
|
997
1733
|
|
|
998
1734
|
}
|
|
999
1735
|
|
|
1736
|
+
/**
|
|
1737
|
+
* Returns the clear alpha.
|
|
1738
|
+
*
|
|
1739
|
+
* @return {Number} The clear alpha.
|
|
1740
|
+
*/
|
|
1000
1741
|
getClearAlpha() {
|
|
1001
1742
|
|
|
1002
1743
|
return this._clearColor.a;
|
|
1003
1744
|
|
|
1004
1745
|
}
|
|
1005
1746
|
|
|
1747
|
+
/**
|
|
1748
|
+
* Defines the clear alpha.
|
|
1749
|
+
*
|
|
1750
|
+
* @param {Number} alpha - The clear alpha.
|
|
1751
|
+
*/
|
|
1006
1752
|
setClearAlpha( alpha ) {
|
|
1007
1753
|
|
|
1008
1754
|
this._clearColor.a = alpha;
|
|
1009
1755
|
|
|
1010
1756
|
}
|
|
1011
1757
|
|
|
1758
|
+
/**
|
|
1759
|
+
* Returns the clear depth.
|
|
1760
|
+
*
|
|
1761
|
+
* @return {Number} The clear depth.
|
|
1762
|
+
*/
|
|
1012
1763
|
getClearDepth() {
|
|
1013
1764
|
|
|
1014
1765
|
return this._clearDepth;
|
|
1015
1766
|
|
|
1016
1767
|
}
|
|
1017
1768
|
|
|
1769
|
+
/**
|
|
1770
|
+
* Defines the clear depth.
|
|
1771
|
+
*
|
|
1772
|
+
* @param {Number} depth - The clear depth.
|
|
1773
|
+
*/
|
|
1018
1774
|
setClearDepth( depth ) {
|
|
1019
1775
|
|
|
1020
1776
|
this._clearDepth = depth;
|
|
1021
1777
|
|
|
1022
1778
|
}
|
|
1023
1779
|
|
|
1780
|
+
/**
|
|
1781
|
+
* Returns the clear stencil.
|
|
1782
|
+
*
|
|
1783
|
+
* @return {Number} The clear stencil.
|
|
1784
|
+
*/
|
|
1024
1785
|
getClearStencil() {
|
|
1025
1786
|
|
|
1026
1787
|
return this._clearStencil;
|
|
1027
1788
|
|
|
1028
1789
|
}
|
|
1029
1790
|
|
|
1791
|
+
/**
|
|
1792
|
+
* Defines the clear stencil.
|
|
1793
|
+
*
|
|
1794
|
+
* @param {Number} stencil - The clear stencil.
|
|
1795
|
+
*/
|
|
1030
1796
|
setClearStencil( stencil ) {
|
|
1031
1797
|
|
|
1032
1798
|
this._clearStencil = stencil;
|
|
1033
1799
|
|
|
1034
1800
|
}
|
|
1035
1801
|
|
|
1802
|
+
/**
|
|
1803
|
+
* This method performs an occlusion query for the given 3D object.
|
|
1804
|
+
* It returns `true` if the given 3D object is fully occluded by other
|
|
1805
|
+
* 3D objects in the scene.
|
|
1806
|
+
*
|
|
1807
|
+
* @param {Object3D} object - The 3D object to test.
|
|
1808
|
+
* @return {Boolean} Whether the 3D object is fully occluded or not.
|
|
1809
|
+
*/
|
|
1036
1810
|
isOccluded( object ) {
|
|
1037
1811
|
|
|
1038
1812
|
const renderContext = this._currentRenderContext;
|
|
@@ -1041,6 +1815,15 @@ class Renderer {
|
|
|
1041
1815
|
|
|
1042
1816
|
}
|
|
1043
1817
|
|
|
1818
|
+
/**
|
|
1819
|
+
* Performs a manual clear operation. This method ignores `autoClear` properties.
|
|
1820
|
+
*
|
|
1821
|
+
* @param {Boolean} [color=true] - Whether the color buffer should be cleared or not.
|
|
1822
|
+
* @param {Boolean} [depth=true] - Whether the depth buffer should be cleared or not.
|
|
1823
|
+
* @param {Boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
|
|
1824
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1825
|
+
* Only returned when the renderer has not been initialized.
|
|
1826
|
+
*/
|
|
1044
1827
|
clear( color = true, depth = true, stencil = true ) {
|
|
1045
1828
|
|
|
1046
1829
|
if ( this._initialized === false ) {
|
|
@@ -1053,17 +1836,26 @@ class Renderer {
|
|
|
1053
1836
|
|
|
1054
1837
|
const renderTarget = this._renderTarget || this._getFrameBufferTarget();
|
|
1055
1838
|
|
|
1056
|
-
let
|
|
1839
|
+
let renderContext = null;
|
|
1057
1840
|
|
|
1058
1841
|
if ( renderTarget !== null ) {
|
|
1059
1842
|
|
|
1060
1843
|
this._textures.updateRenderTarget( renderTarget );
|
|
1061
1844
|
|
|
1062
|
-
renderTargetData = this._textures.get( renderTarget );
|
|
1845
|
+
const renderTargetData = this._textures.get( renderTarget );
|
|
1846
|
+
|
|
1847
|
+
renderContext = this._renderContexts.get( null, null, renderTarget );
|
|
1848
|
+
renderContext.textures = renderTargetData.textures;
|
|
1849
|
+
renderContext.depthTexture = renderTargetData.depthTexture;
|
|
1850
|
+
renderContext.width = renderTargetData.width;
|
|
1851
|
+
renderContext.height = renderTargetData.height;
|
|
1852
|
+
renderContext.renderTarget = renderTarget;
|
|
1853
|
+
renderContext.depth = renderTarget.depthBuffer;
|
|
1854
|
+
renderContext.stencil = renderTarget.stencilBuffer;
|
|
1063
1855
|
|
|
1064
1856
|
}
|
|
1065
1857
|
|
|
1066
|
-
this.backend.clear( color, depth, stencil,
|
|
1858
|
+
this.backend.clear( color, depth, stencil, renderContext );
|
|
1067
1859
|
|
|
1068
1860
|
if ( renderTarget !== null && this._renderTarget === null ) {
|
|
1069
1861
|
|
|
@@ -1085,24 +1877,51 @@ class Renderer {
|
|
|
1085
1877
|
|
|
1086
1878
|
}
|
|
1087
1879
|
|
|
1880
|
+
/**
|
|
1881
|
+
* Performs a manual clear operation of the color buffer. This method ignores `autoClear` properties.
|
|
1882
|
+
*
|
|
1883
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1884
|
+
* Only returned when the renderer has not been initialized.
|
|
1885
|
+
*/
|
|
1088
1886
|
clearColor() {
|
|
1089
1887
|
|
|
1090
1888
|
return this.clear( true, false, false );
|
|
1091
1889
|
|
|
1092
1890
|
}
|
|
1093
1891
|
|
|
1892
|
+
/**
|
|
1893
|
+
* Performs a manual clear operation of the depth buffer. This method ignores `autoClear` properties.
|
|
1894
|
+
*
|
|
1895
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1896
|
+
* Only returned when the renderer has not been initialized.
|
|
1897
|
+
*/
|
|
1094
1898
|
clearDepth() {
|
|
1095
1899
|
|
|
1096
1900
|
return this.clear( false, true, false );
|
|
1097
1901
|
|
|
1098
1902
|
}
|
|
1099
1903
|
|
|
1904
|
+
/**
|
|
1905
|
+
* Performs a manual clear operation of the stencil buffer. This method ignores `autoClear` properties.
|
|
1906
|
+
*
|
|
1907
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1908
|
+
* Only returned when the renderer has not been initialized.
|
|
1909
|
+
*/
|
|
1100
1910
|
clearStencil() {
|
|
1101
1911
|
|
|
1102
1912
|
return this.clear( false, false, true );
|
|
1103
1913
|
|
|
1104
1914
|
}
|
|
1105
1915
|
|
|
1916
|
+
/**
|
|
1917
|
+
* Async version of {@link module:Renderer~Renderer#clear}.
|
|
1918
|
+
*
|
|
1919
|
+
* @async
|
|
1920
|
+
* @param {Boolean} [color=true] - Whether the color buffer should be cleared or not.
|
|
1921
|
+
* @param {Boolean} [depth=true] - Whether the depth buffer should be cleared or not.
|
|
1922
|
+
* @param {Boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
|
|
1923
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1924
|
+
*/
|
|
1106
1925
|
async clearAsync( color = true, depth = true, stencil = true ) {
|
|
1107
1926
|
|
|
1108
1927
|
if ( this._initialized === false ) await this.init();
|
|
@@ -1111,36 +1930,70 @@ class Renderer {
|
|
|
1111
1930
|
|
|
1112
1931
|
}
|
|
1113
1932
|
|
|
1114
|
-
|
|
1933
|
+
/**
|
|
1934
|
+
* Async version of {@link module:Renderer~Renderer#clearColor}.
|
|
1935
|
+
*
|
|
1936
|
+
* @async
|
|
1937
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1938
|
+
*/
|
|
1939
|
+
async clearColorAsync() {
|
|
1115
1940
|
|
|
1116
|
-
|
|
1941
|
+
this.clearAsync( true, false, false );
|
|
1117
1942
|
|
|
1118
1943
|
}
|
|
1119
1944
|
|
|
1120
|
-
|
|
1945
|
+
/**
|
|
1946
|
+
* Async version of {@link module:Renderer~Renderer#clearDepth}.
|
|
1947
|
+
*
|
|
1948
|
+
* @async
|
|
1949
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1950
|
+
*/
|
|
1951
|
+
async clearDepthAsync() {
|
|
1121
1952
|
|
|
1122
|
-
|
|
1953
|
+
this.clearAsync( false, true, false );
|
|
1123
1954
|
|
|
1124
1955
|
}
|
|
1125
1956
|
|
|
1126
|
-
|
|
1957
|
+
/**
|
|
1958
|
+
* Async version of {@link module:Renderer~Renderer#clearStencil}.
|
|
1959
|
+
*
|
|
1960
|
+
* @async
|
|
1961
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
1962
|
+
*/
|
|
1963
|
+
async clearStencilAsync() {
|
|
1127
1964
|
|
|
1128
|
-
|
|
1965
|
+
this.clearAsync( false, false, true );
|
|
1129
1966
|
|
|
1130
1967
|
}
|
|
1131
1968
|
|
|
1969
|
+
/**
|
|
1970
|
+
* The current output tone mapping of the renderer. When a render target is set,
|
|
1971
|
+
* the output tone mapping is always `NoToneMapping`.
|
|
1972
|
+
*
|
|
1973
|
+
* @type {Number}
|
|
1974
|
+
*/
|
|
1132
1975
|
get currentToneMapping() {
|
|
1133
1976
|
|
|
1134
1977
|
return this._renderTarget !== null ? NoToneMapping : this.toneMapping;
|
|
1135
1978
|
|
|
1136
1979
|
}
|
|
1137
1980
|
|
|
1981
|
+
/**
|
|
1982
|
+
* The current output color space of the renderer. When a render target is set,
|
|
1983
|
+
* the output color space is always `LinearSRGBColorSpace`.
|
|
1984
|
+
*
|
|
1985
|
+
* @type {String}
|
|
1986
|
+
*/
|
|
1138
1987
|
get currentColorSpace() {
|
|
1139
1988
|
|
|
1140
1989
|
return this._renderTarget !== null ? LinearSRGBColorSpace : this.outputColorSpace;
|
|
1141
1990
|
|
|
1142
1991
|
}
|
|
1143
1992
|
|
|
1993
|
+
/**
|
|
1994
|
+
* Frees all internal resources of the renderer. Call this method if the renderer
|
|
1995
|
+
* is no longer in use by your app.
|
|
1996
|
+
*/
|
|
1144
1997
|
dispose() {
|
|
1145
1998
|
|
|
1146
1999
|
this.info.dispose();
|
|
@@ -1160,6 +2013,15 @@ class Renderer {
|
|
|
1160
2013
|
|
|
1161
2014
|
}
|
|
1162
2015
|
|
|
2016
|
+
/**
|
|
2017
|
+
* Sets the given render target. Calling this method means the renderer does not
|
|
2018
|
+
* target the default framebuffer (meaning the canvas) anymore but a custom framebuffer.
|
|
2019
|
+
* Use `null` as the first argument to reset the state.
|
|
2020
|
+
*
|
|
2021
|
+
* @param {RenderTarget?} renderTarget - The render target to set.
|
|
2022
|
+
* @param {Number} [activeCubeFace=0] - The active cube face.
|
|
2023
|
+
* @param {Number} [activeMipmapLevel=0] - The active mipmap level.
|
|
2024
|
+
*/
|
|
1163
2025
|
setRenderTarget( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
|
|
1164
2026
|
|
|
1165
2027
|
this._renderTarget = renderTarget;
|
|
@@ -1168,24 +2030,67 @@ class Renderer {
|
|
|
1168
2030
|
|
|
1169
2031
|
}
|
|
1170
2032
|
|
|
2033
|
+
/**
|
|
2034
|
+
* Returns the current render target.
|
|
2035
|
+
*
|
|
2036
|
+
* @return {RenderTarget?} The render target. Returns `null` if no render target is set.
|
|
2037
|
+
*/
|
|
1171
2038
|
getRenderTarget() {
|
|
1172
2039
|
|
|
1173
2040
|
return this._renderTarget;
|
|
1174
2041
|
|
|
1175
2042
|
}
|
|
1176
2043
|
|
|
2044
|
+
/**
|
|
2045
|
+
* Callback for {@link module:Renderer~Renderer#setRenderObjectFunction}.
|
|
2046
|
+
*
|
|
2047
|
+
* @callback renderObjectFunction
|
|
2048
|
+
* @param {Object3D} object - The 3D object.
|
|
2049
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2050
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2051
|
+
* @param {BufferGeometry} geometry - The object's geometry.
|
|
2052
|
+
* @param {Material} material - The object's material.
|
|
2053
|
+
* @param {Object?} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2054
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2055
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2056
|
+
* @param {String?} [passId=null] - An optional ID for identifying the pass.
|
|
2057
|
+
*/
|
|
2058
|
+
|
|
2059
|
+
/**
|
|
2060
|
+
* Sets the given render object function. Calling this method overwrites the default implementation
|
|
2061
|
+
* which is {@link module:Renderer~Renderer#renderObject}. Defining a custom function can be useful
|
|
2062
|
+
* if you want to modify the way objects are rendered. For example you can define things like "every
|
|
2063
|
+
* object that has material of a certain type should perform a pre-pass with a special overwrite material".
|
|
2064
|
+
* The custom function must always call `renderObject()` in its implementation.
|
|
2065
|
+
*
|
|
2066
|
+
* Use `null` as the first argument to reset the state.
|
|
2067
|
+
*
|
|
2068
|
+
* @param {module:Renderer~renderObjectFunction?} renderObjectFunction - The render object function.
|
|
2069
|
+
*/
|
|
1177
2070
|
setRenderObjectFunction( renderObjectFunction ) {
|
|
1178
2071
|
|
|
1179
2072
|
this._renderObjectFunction = renderObjectFunction;
|
|
1180
2073
|
|
|
1181
2074
|
}
|
|
1182
2075
|
|
|
2076
|
+
/**
|
|
2077
|
+
* Returns the current render object function.
|
|
2078
|
+
*
|
|
2079
|
+
* @return {Function?} The current render object function. Returns `null` if no function is set.
|
|
2080
|
+
*/
|
|
1183
2081
|
getRenderObjectFunction() {
|
|
1184
2082
|
|
|
1185
2083
|
return this._renderObjectFunction;
|
|
1186
2084
|
|
|
1187
2085
|
}
|
|
1188
2086
|
|
|
2087
|
+
/**
|
|
2088
|
+
* Execute a single or an array of compute nodes. This method can only be called
|
|
2089
|
+
* if the renderer has been initialized.
|
|
2090
|
+
*
|
|
2091
|
+
* @param {Node|Array<Node>} computeNodes - The compute node(s).
|
|
2092
|
+
* @return {Promise?} A Promise that resolve when the compute has finished. Only returned when the renderer has not been initialized.
|
|
2093
|
+
*/
|
|
1189
2094
|
compute( computeNodes ) {
|
|
1190
2095
|
|
|
1191
2096
|
if ( this.isDeviceLost === true ) return;
|
|
@@ -1277,6 +2182,13 @@ class Renderer {
|
|
|
1277
2182
|
|
|
1278
2183
|
}
|
|
1279
2184
|
|
|
2185
|
+
/**
|
|
2186
|
+
* Execute a single or an array of compute nodes.
|
|
2187
|
+
*
|
|
2188
|
+
* @async
|
|
2189
|
+
* @param {Node|Array<Node>} computeNodes - The compute node(s).
|
|
2190
|
+
* @return {Promise?} A Promise that resolve when the compute has finished.
|
|
2191
|
+
*/
|
|
1280
2192
|
async computeAsync( computeNodes ) {
|
|
1281
2193
|
|
|
1282
2194
|
if ( this._initialized === false ) await this.init();
|
|
@@ -1287,6 +2199,13 @@ class Renderer {
|
|
|
1287
2199
|
|
|
1288
2200
|
}
|
|
1289
2201
|
|
|
2202
|
+
/**
|
|
2203
|
+
* Checks if the given feature is supported by the selected backend.
|
|
2204
|
+
*
|
|
2205
|
+
* @async
|
|
2206
|
+
* @param {String} name - The feature's name.
|
|
2207
|
+
* @return {Promise<Boolean>} A Promise that resolves with a bool that indicates whether the feature is supported or not.
|
|
2208
|
+
*/
|
|
1290
2209
|
async hasFeatureAsync( name ) {
|
|
1291
2210
|
|
|
1292
2211
|
if ( this._initialized === false ) await this.init();
|
|
@@ -1295,6 +2214,13 @@ class Renderer {
|
|
|
1295
2214
|
|
|
1296
2215
|
}
|
|
1297
2216
|
|
|
2217
|
+
/**
|
|
2218
|
+
* Checks if the given feature is supported by the selected backend. If the
|
|
2219
|
+
* renderer has not been initialized, this method always returns `false`.
|
|
2220
|
+
*
|
|
2221
|
+
* @param {String} name - The feature's name.
|
|
2222
|
+
* @return {Boolean} Whether the feature is supported or not.
|
|
2223
|
+
*/
|
|
1298
2224
|
hasFeature( name ) {
|
|
1299
2225
|
|
|
1300
2226
|
if ( this._initialized === false ) {
|
|
@@ -1309,12 +2235,25 @@ class Renderer {
|
|
|
1309
2235
|
|
|
1310
2236
|
}
|
|
1311
2237
|
|
|
2238
|
+
/**
|
|
2239
|
+
* Returns `true` when the renderer has been initialized.
|
|
2240
|
+
*
|
|
2241
|
+
* @return {Boolean} Whether the renderer has been initialized or not.
|
|
2242
|
+
*/
|
|
1312
2243
|
hasInitialized() {
|
|
1313
2244
|
|
|
1314
2245
|
return this._initialized;
|
|
1315
2246
|
|
|
1316
2247
|
}
|
|
1317
2248
|
|
|
2249
|
+
/**
|
|
2250
|
+
* Initializes the given textures. Useful for preloading a texture rather than waiting until first render
|
|
2251
|
+
* (which can cause noticeable lags due to decode and GPU upload overhead).
|
|
2252
|
+
*
|
|
2253
|
+
* @async
|
|
2254
|
+
* @param {Texture} texture - The texture.
|
|
2255
|
+
* @return {Promise} A Promise that resolves when the texture has been initialized.
|
|
2256
|
+
*/
|
|
1318
2257
|
async initTextureAsync( texture ) {
|
|
1319
2258
|
|
|
1320
2259
|
if ( this._initialized === false ) await this.init();
|
|
@@ -1323,20 +2262,32 @@ class Renderer {
|
|
|
1323
2262
|
|
|
1324
2263
|
}
|
|
1325
2264
|
|
|
2265
|
+
/**
|
|
2266
|
+
* Initializes the given textures. Useful for preloading a texture rather than waiting until first render
|
|
2267
|
+
* (which can cause noticeable lags due to decode and GPU upload overhead).
|
|
2268
|
+
*
|
|
2269
|
+
* This method can only be used if the renderer has been initialized.
|
|
2270
|
+
*
|
|
2271
|
+
* @param {Texture} texture - The texture.
|
|
2272
|
+
*/
|
|
1326
2273
|
initTexture( texture ) {
|
|
1327
2274
|
|
|
1328
2275
|
if ( this._initialized === false ) {
|
|
1329
2276
|
|
|
1330
2277
|
console.warn( 'THREE.Renderer: .initTexture() called before the backend is initialized. Try using .initTextureAsync() instead.' );
|
|
1331
2278
|
|
|
1332
|
-
return false;
|
|
1333
|
-
|
|
1334
2279
|
}
|
|
1335
2280
|
|
|
1336
2281
|
this._textures.updateTexture( texture );
|
|
1337
2282
|
|
|
1338
2283
|
}
|
|
1339
2284
|
|
|
2285
|
+
/**
|
|
2286
|
+
* Copies the current bound framebuffer into the given texture.
|
|
2287
|
+
*
|
|
2288
|
+
* @param {FramebufferTexture} framebufferTexture - The texture.
|
|
2289
|
+
* @param {Vector2|Vector4} rectangle - A two or four dimensional vector that defines the rectangular portion of the framebuffer that should be copied.
|
|
2290
|
+
*/
|
|
1340
2291
|
copyFramebufferToTexture( framebufferTexture, rectangle = null ) {
|
|
1341
2292
|
|
|
1342
2293
|
if ( rectangle !== null ) {
|
|
@@ -1394,6 +2345,15 @@ class Renderer {
|
|
|
1394
2345
|
|
|
1395
2346
|
}
|
|
1396
2347
|
|
|
2348
|
+
/**
|
|
2349
|
+
* Copies data of source texture into a destination texture.
|
|
2350
|
+
*
|
|
2351
|
+
* @param {Texture} srcTexture - The source texture.
|
|
2352
|
+
* @param {Texture} dstTexture - The destination texture.
|
|
2353
|
+
* @param {Box2|Box3} [srcRegion=null] - A bounding box which describes the source region. Can be two or three-dimensional.
|
|
2354
|
+
* @param {Vector2|Vector3} [dstPosition=null] - A vector that represents the origin of the destination region. Can be two or three-dimensional.
|
|
2355
|
+
* @param {Number} level - The mipmap level to copy.
|
|
2356
|
+
*/
|
|
1397
2357
|
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
|
|
1398
2358
|
|
|
1399
2359
|
this._textures.updateTexture( srcTexture );
|
|
@@ -1403,12 +2363,35 @@ class Renderer {
|
|
|
1403
2363
|
|
|
1404
2364
|
}
|
|
1405
2365
|
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
2366
|
+
/**
|
|
2367
|
+
* Reads pixel data from the given render target.
|
|
2368
|
+
*
|
|
2369
|
+
* @async
|
|
2370
|
+
* @param {RenderTarget} renderTarget - The render target to read from.
|
|
2371
|
+
* @param {Number} x - The `x` coordinate of the copy region's origin.
|
|
2372
|
+
* @param {Number} y - The `y` coordinate of the copy region's origin.
|
|
2373
|
+
* @param {Number} width - The width of the copy region.
|
|
2374
|
+
* @param {Number} height - The height of the copy region.
|
|
2375
|
+
* @param {Number} [textureIndex=0] - The texture index of a MRT render target.
|
|
2376
|
+
* @param {Number} [faceIndex=0] - The active cube face index.
|
|
2377
|
+
* @return {Promise<TypedArray>} A Promise that resolves when the read has been finished. The resolve provides the read data as a typed array.
|
|
2378
|
+
*/
|
|
2379
|
+
async readRenderTargetPixelsAsync( renderTarget, x, y, width, height, textureIndex = 0, faceIndex = 0 ) {
|
|
2380
|
+
|
|
2381
|
+
return this.backend.copyTextureToBuffer( renderTarget.textures[ textureIndex ], x, y, width, height, faceIndex );
|
|
2382
|
+
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
/**
|
|
2386
|
+
* Analyzes the given 3D object's hierarchy and builds render lists from the
|
|
2387
|
+
* processed hierarchy.
|
|
2388
|
+
*
|
|
2389
|
+
* @param {Object3D} object - The 3D object to process (usually a scene).
|
|
2390
|
+
* @param {Camera} camera - The camera the object is rendered with.
|
|
2391
|
+
* @param {Number} groupOrder - The group order is derived from the `renderOrder` of groups and is used to group 3D objects within groups.
|
|
2392
|
+
* @param {RenderList} renderList - The current render list.
|
|
2393
|
+
* @param {ClippingContext} clippingContext - The current clipping context.
|
|
2394
|
+
*/
|
|
1412
2395
|
_projectObject( object, camera, groupOrder, renderList, clippingContext ) {
|
|
1413
2396
|
|
|
1414
2397
|
if ( object.visible === false ) return;
|
|
@@ -1530,6 +2513,14 @@ class Renderer {
|
|
|
1530
2513
|
|
|
1531
2514
|
}
|
|
1532
2515
|
|
|
2516
|
+
/**
|
|
2517
|
+
* Renders the given render bundles.
|
|
2518
|
+
*
|
|
2519
|
+
* @private
|
|
2520
|
+
* @param {Array<Object>} bundles - Array with render bundle data.
|
|
2521
|
+
* @param {Scene} sceneRef - The scene the render bundles belong to.
|
|
2522
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2523
|
+
*/
|
|
1533
2524
|
_renderBundles( bundles, sceneRef, lightsNode ) {
|
|
1534
2525
|
|
|
1535
2526
|
for ( const bundle of bundles ) {
|
|
@@ -1540,6 +2531,16 @@ class Renderer {
|
|
|
1540
2531
|
|
|
1541
2532
|
}
|
|
1542
2533
|
|
|
2534
|
+
/**
|
|
2535
|
+
* Renders the transparent objects from the given render lists.
|
|
2536
|
+
*
|
|
2537
|
+
* @private
|
|
2538
|
+
* @param {Array<Object>} renderList - The transparent render list.
|
|
2539
|
+
* @param {Array<Object>} doublePassList - The list of transparent objects which require a double pass (e.g. because of transmission).
|
|
2540
|
+
* @param {Camera} camera - The camera the render list should be rendered with.
|
|
2541
|
+
* @param {Scene} scene - The scene the render list belongs to.
|
|
2542
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2543
|
+
*/
|
|
1543
2544
|
_renderTransparents( renderList, doublePassList, camera, scene, lightsNode ) {
|
|
1544
2545
|
|
|
1545
2546
|
if ( doublePassList.length > 0 ) {
|
|
@@ -1580,6 +2581,16 @@ class Renderer {
|
|
|
1580
2581
|
|
|
1581
2582
|
}
|
|
1582
2583
|
|
|
2584
|
+
/**
|
|
2585
|
+
* Renders the objects from the given render list.
|
|
2586
|
+
*
|
|
2587
|
+
* @private
|
|
2588
|
+
* @param {Array<Object>} renderList - The render list.
|
|
2589
|
+
* @param {Camera} camera - The camera the render list should be rendered with.
|
|
2590
|
+
* @param {Scene} scene - The scene the render list belongs to.
|
|
2591
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2592
|
+
* @param {String?} [passId=null] - An optional ID for identifying the pass.
|
|
2593
|
+
*/
|
|
1583
2594
|
_renderObjects( renderList, camera, scene, lightsNode, passId = null ) {
|
|
1584
2595
|
|
|
1585
2596
|
// process renderable objects
|
|
@@ -1630,6 +2641,20 @@ class Renderer {
|
|
|
1630
2641
|
|
|
1631
2642
|
}
|
|
1632
2643
|
|
|
2644
|
+
/**
|
|
2645
|
+
* This method represents the default render object function that manages the render lifecycle
|
|
2646
|
+
* of the object.
|
|
2647
|
+
*
|
|
2648
|
+
* @param {Object3D} object - The 3D object.
|
|
2649
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2650
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2651
|
+
* @param {BufferGeometry} geometry - The object's geometry.
|
|
2652
|
+
* @param {Material} material - The object's material.
|
|
2653
|
+
* @param {Object?} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2654
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2655
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2656
|
+
* @param {String?} [passId=null] - An optional ID for identifying the pass.
|
|
2657
|
+
*/
|
|
1633
2658
|
renderObject( object, scene, camera, geometry, material, group, lightsNode, clippingContext = null, passId = null ) {
|
|
1634
2659
|
|
|
1635
2660
|
let overridePositionNode;
|
|
@@ -1655,6 +2680,7 @@ class Renderer {
|
|
|
1655
2680
|
|
|
1656
2681
|
overrideMaterial.alphaTest = material.alphaTest;
|
|
1657
2682
|
overrideMaterial.alphaMap = material.alphaMap;
|
|
2683
|
+
overrideMaterial.transparent = material.transparent || material.transmission > 0;
|
|
1658
2684
|
|
|
1659
2685
|
if ( overrideMaterial.isShadowNodeMaterial ) {
|
|
1660
2686
|
|
|
@@ -1724,6 +2750,20 @@ class Renderer {
|
|
|
1724
2750
|
|
|
1725
2751
|
}
|
|
1726
2752
|
|
|
2753
|
+
/**
|
|
2754
|
+
* This method represents the default `_handleObjectFunction` implementation which creates
|
|
2755
|
+
* a render object from the given data and performs the draw command with the selected backend.
|
|
2756
|
+
*
|
|
2757
|
+
* @private
|
|
2758
|
+
* @param {Object3D} object - The 3D object.
|
|
2759
|
+
* @param {Material} material - The object's material.
|
|
2760
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2761
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2762
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2763
|
+
* @param {Object?} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2764
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2765
|
+
* @param {String?} [passId=null] - An optional ID for identifying the pass.
|
|
2766
|
+
*/
|
|
1727
2767
|
_renderObjectDirect( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
|
|
1728
2768
|
|
|
1729
2769
|
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId );
|
|
@@ -1755,7 +2795,7 @@ class Renderer {
|
|
|
1755
2795
|
|
|
1756
2796
|
renderBundleData.renderObjects.push( renderObject );
|
|
1757
2797
|
|
|
1758
|
-
renderObject.bundle = this._currentRenderBundle.
|
|
2798
|
+
renderObject.bundle = this._currentRenderBundle.bundleGroup;
|
|
1759
2799
|
|
|
1760
2800
|
}
|
|
1761
2801
|
|
|
@@ -1765,9 +2805,25 @@ class Renderer {
|
|
|
1765
2805
|
|
|
1766
2806
|
}
|
|
1767
2807
|
|
|
1768
|
-
|
|
2808
|
+
/**
|
|
2809
|
+
* A different implementation for `_handleObjectFunction` which only makes sure the object is ready for rendering.
|
|
2810
|
+
* Used in `compileAsync()`.
|
|
2811
|
+
*
|
|
2812
|
+
* @private
|
|
2813
|
+
* @param {Object3D} object - The 3D object.
|
|
2814
|
+
* @param {Material} material - The object's material.
|
|
2815
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2816
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2817
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2818
|
+
* @param {Object?} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2819
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2820
|
+
* @param {String?} [passId=null] - An optional ID for identifying the pass.
|
|
2821
|
+
*/
|
|
2822
|
+
_createObjectPipeline( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
|
|
1769
2823
|
|
|
1770
2824
|
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId );
|
|
2825
|
+
renderObject.drawRange = object.geometry.drawRange;
|
|
2826
|
+
renderObject.group = group;
|
|
1771
2827
|
|
|
1772
2828
|
//
|
|
1773
2829
|
|
|
@@ -1784,6 +2840,15 @@ class Renderer {
|
|
|
1784
2840
|
|
|
1785
2841
|
}
|
|
1786
2842
|
|
|
2843
|
+
/**
|
|
2844
|
+
* Alias for `compileAsync()`.
|
|
2845
|
+
*
|
|
2846
|
+
* @method
|
|
2847
|
+
* @param {Object3D} scene - The scene or 3D object to precompile.
|
|
2848
|
+
* @param {Camera} camera - The camera that is used to render the scene.
|
|
2849
|
+
* @param {Scene} targetScene - If the first argument is a 3D object, this parameter must represent the scene the 3D object is going to be added.
|
|
2850
|
+
* @return {Promise} A Promise that resolves when the compile has been finished.
|
|
2851
|
+
*/
|
|
1787
2852
|
get compile() {
|
|
1788
2853
|
|
|
1789
2854
|
return this.compileAsync;
|