@needle-tools/three 0.169.20-experimental.0 → 0.183.2-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +5 -6
- package/build/three.cjs +54184 -56703
- package/build/three.core.js +59506 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +11645 -73000
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +648 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +53912 -51652
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +53888 -51806
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
- package/examples/fonts/MPLUSRounded1c/OFL.txt +91 -0
- package/examples/jsm/Addons.js +5 -15
- package/examples/jsm/animation/AnimationClipCreator.js +58 -6
- package/examples/jsm/animation/CCDIKSolver.js +152 -45
- package/examples/jsm/capabilities/WebGL.js +28 -29
- package/examples/jsm/capabilities/WebGPU.js +19 -17
- package/examples/jsm/controls/ArcballControls.js +474 -178
- package/examples/jsm/controls/DragControls.js +100 -58
- package/examples/jsm/controls/FirstPersonControls.js +116 -6
- package/examples/jsm/controls/FlyControls.js +50 -2
- package/examples/jsm/controls/MapControls.js +96 -8
- package/examples/jsm/controls/OrbitControls.js +496 -57
- package/examples/jsm/controls/PointerLockControls.js +115 -22
- package/examples/jsm/controls/TrackballControls.js +166 -14
- package/examples/jsm/controls/TransformControls.js +336 -26
- package/examples/jsm/csm/CSM.js +232 -18
- package/examples/jsm/csm/CSMFrustum.js +61 -4
- package/examples/jsm/csm/CSMHelper.js +50 -0
- package/examples/jsm/csm/CSMShader.js +13 -1
- package/examples/jsm/csm/CSMShadowNode.js +599 -0
- package/examples/jsm/curves/CurveExtras.js +303 -31
- package/examples/jsm/curves/NURBSCurve.js +91 -16
- package/examples/jsm/curves/NURBSSurface.js +52 -6
- package/examples/jsm/curves/NURBSUtils.js +102 -112
- package/examples/jsm/curves/NURBSVolume.js +24 -4
- package/examples/jsm/effects/AnaglyphEffect.js +134 -7
- package/examples/jsm/effects/AsciiEffect.js +69 -22
- package/examples/jsm/effects/OutlineEffect.js +61 -111
- package/examples/jsm/effects/ParallaxBarrierEffect.js +30 -0
- package/examples/jsm/effects/StereoEffect.js +31 -0
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/DebugEnvironment.js +50 -0
- package/examples/jsm/environments/RoomEnvironment.js +83 -42
- package/examples/jsm/exporters/DRACOExporter.js +56 -14
- package/examples/jsm/exporters/EXRExporter.js +40 -9
- package/examples/jsm/exporters/GLTFExporter.js +502 -169
- package/examples/jsm/exporters/OBJExporter.js +21 -1
- package/examples/jsm/exporters/PLYExporter.js +44 -12
- package/examples/jsm/exporters/STLExporter.js +27 -5
- package/examples/jsm/exporters/USDZExporter.js +781 -291
- package/examples/jsm/geometries/BoxLineGeometry.js +23 -0
- package/examples/jsm/geometries/ConvexGeometry.js +19 -0
- package/examples/jsm/geometries/DecalGeometry.js +91 -30
- package/examples/jsm/geometries/ParametricFunctions.js +100 -0
- package/examples/jsm/geometries/ParametricGeometry.js +38 -5
- package/examples/jsm/geometries/RoundedBoxGeometry.js +68 -7
- package/examples/jsm/geometries/TeapotGeometry.js +23 -38
- package/examples/jsm/geometries/TextGeometry.js +48 -29
- package/examples/jsm/gpgpu/BitonicSort.js +715 -0
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/LightProbeHelper.js +36 -0
- package/examples/jsm/helpers/LightProbeHelperGPU.js +38 -1
- package/examples/jsm/helpers/OctreeHelper.js +36 -0
- package/examples/jsm/helpers/PositionalAudioHelper.js +60 -0
- package/examples/jsm/helpers/RapierHelper.js +59 -0
- package/examples/jsm/helpers/RectAreaLightHelper.js +36 -3
- package/examples/jsm/helpers/TextureHelper.js +28 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +214 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +61 -2
- package/examples/jsm/helpers/VertexTangentsHelper.js +47 -2
- package/examples/jsm/helpers/ViewHelper.js +181 -9
- package/examples/jsm/inspector/Inspector.js +487 -0
- package/examples/jsm/inspector/RendererInspector.js +425 -0
- package/examples/jsm/inspector/tabs/Console.js +238 -0
- package/examples/jsm/inspector/tabs/Parameters.js +348 -0
- package/examples/jsm/inspector/tabs/Performance.js +268 -0
- package/examples/jsm/inspector/tabs/Viewer.js +166 -0
- package/examples/jsm/inspector/ui/Graph.js +95 -0
- package/examples/jsm/inspector/ui/Item.js +170 -0
- package/examples/jsm/inspector/ui/List.js +75 -0
- package/examples/jsm/inspector/ui/Profiler.js +1975 -0
- package/examples/jsm/inspector/ui/Style.js +1613 -0
- package/examples/jsm/inspector/ui/Tab.js +233 -0
- package/examples/jsm/inspector/ui/Values.js +439 -0
- package/examples/jsm/inspector/ui/utils.js +56 -0
- package/examples/jsm/interactive/HTMLMesh.js +43 -12
- package/examples/jsm/interactive/InteractiveGroup.js +170 -52
- package/examples/jsm/interactive/SelectionBox.js +106 -9
- package/examples/jsm/interactive/SelectionHelper.js +76 -30
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +76 -58
- package/examples/jsm/libs/motion-controllers.module.js +1 -1
- package/examples/jsm/lighting/TiledLighting.js +42 -0
- package/examples/jsm/lights/LightProbeGenerator.js +44 -7
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +50 -14
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +16 -0
- package/examples/jsm/lines/Line2.js +41 -4
- package/examples/jsm/lines/LineGeometry.js +80 -2
- package/examples/jsm/lines/LineMaterial.js +105 -5
- package/examples/jsm/lines/LineSegments2.js +54 -4
- package/examples/jsm/lines/LineSegmentsGeometry.js +65 -8
- package/examples/jsm/lines/Wireframe.js +41 -4
- package/examples/jsm/lines/WireframeGeometry2.js +27 -2
- package/examples/jsm/lines/webgpu/Line2.js +28 -2
- package/examples/jsm/lines/webgpu/LineSegments2.js +59 -24
- package/examples/jsm/lines/webgpu/Wireframe.js +86 -0
- package/examples/jsm/loaders/3DMLoader.js +78 -6
- package/examples/jsm/loaders/3MFLoader.js +148 -7
- package/examples/jsm/loaders/AMFLoader.js +34 -14
- package/examples/jsm/loaders/BVHLoader.js +59 -12
- package/examples/jsm/loaders/ColladaLoader.js +61 -4027
- package/examples/jsm/loaders/DDSLoader.js +68 -1
- package/examples/jsm/loaders/DRACOLoader.js +146 -22
- package/examples/jsm/loaders/EXRLoader.js +255 -34
- package/examples/jsm/loaders/FBXLoader.js +80 -42
- package/examples/jsm/loaders/FontLoader.js +83 -6
- package/examples/jsm/loaders/GCodeLoader.js +71 -14
- package/examples/jsm/loaders/GLTFLoader.js +381 -263
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +52 -3
- package/examples/jsm/loaders/HDRLoader.js +485 -0
- package/examples/jsm/loaders/IESLoader.js +42 -0
- package/examples/jsm/loaders/KMZLoader.js +39 -6
- package/examples/jsm/loaders/KTX2Loader.js +124 -48
- package/examples/jsm/loaders/KTXLoader.js +31 -10
- package/examples/jsm/loaders/LDrawLoader.js +192 -145
- package/examples/jsm/loaders/LUT3dlLoader.js +47 -10
- package/examples/jsm/loaders/LUTCubeLoader.js +46 -9
- package/examples/jsm/loaders/LUTImageLoader.js +79 -38
- package/examples/jsm/loaders/LWOLoader.js +54 -59
- package/examples/jsm/loaders/LottieLoader.js +54 -1
- package/examples/jsm/loaders/MD2Loader.js +37 -1
- package/examples/jsm/loaders/MDDLoader.js +57 -12
- package/examples/jsm/loaders/MTLLoader.js +60 -35
- package/examples/jsm/loaders/MaterialXLoader.js +268 -34
- package/examples/jsm/loaders/NRRDLoader.js +40 -8
- package/examples/jsm/loaders/OBJLoader.js +51 -2
- package/examples/jsm/loaders/PCDLoader.js +173 -21
- package/examples/jsm/loaders/PDBLoader.js +41 -2
- package/examples/jsm/loaders/PLYLoader.js +70 -39
- package/examples/jsm/loaders/PVRLoader.js +25 -6
- package/examples/jsm/loaders/RGBELoader.js +6 -438
- package/examples/jsm/loaders/STLLoader.js +48 -38
- package/examples/jsm/loaders/SVGLoader.js +119 -25
- package/examples/jsm/loaders/TDSLoader.js +92 -74
- package/examples/jsm/loaders/TGALoader.js +23 -2
- package/examples/jsm/loaders/TIFFLoader.js +23 -0
- package/examples/jsm/loaders/TTFLoader.js +50 -3
- package/examples/jsm/loaders/USDLoader.js +279 -0
- package/examples/jsm/loaders/USDZLoader.js +4 -858
- package/examples/jsm/loaders/UltraHDRLoader.js +338 -166
- package/examples/jsm/loaders/VOXLoader.js +688 -87
- package/examples/jsm/loaders/VRMLLoader.js +121 -12
- package/examples/jsm/loaders/VTKLoader.js +77 -25
- package/examples/jsm/loaders/XYZLoader.js +36 -0
- package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
- package/examples/jsm/loaders/lwo/IFFParser.js +77 -77
- package/examples/jsm/loaders/usd/USDAParser.js +822 -0
- package/examples/jsm/loaders/usd/USDCParser.js +1852 -0
- package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +183 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +154 -0
- package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
- package/examples/jsm/math/Capsule.js +91 -14
- package/examples/jsm/math/ColorConverter.js +22 -0
- package/examples/jsm/math/ColorSpaces.js +74 -2
- package/examples/jsm/math/ConvexHull.js +517 -93
- package/examples/jsm/math/ImprovedNoise.js +32 -15
- package/examples/jsm/math/Lut.js +113 -0
- package/examples/jsm/math/MeshSurfaceSampler.js +78 -13
- package/examples/jsm/math/OBB.js +141 -29
- package/examples/jsm/math/Octree.js +283 -7
- package/examples/jsm/math/SimplexNoise.js +68 -42
- package/examples/jsm/misc/ConvexObjectBreaker.js +45 -25
- package/examples/jsm/misc/GPUComputationRenderer.js +96 -20
- package/examples/jsm/misc/Gyroscope.js +12 -0
- package/examples/jsm/misc/MD2Character.js +117 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +175 -11
- package/examples/jsm/misc/MorphAnimMesh.js +44 -0
- package/examples/jsm/misc/MorphBlendMesh.js +103 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +100 -54
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +322 -0
- package/examples/jsm/misc/RollerCoaster.js +57 -0
- package/examples/jsm/misc/TubePainter.js +437 -40
- package/examples/jsm/misc/Volume.js +123 -76
- package/examples/jsm/misc/VolumeSlice.js +95 -49
- package/examples/jsm/modifiers/CurveModifier.js +66 -38
- package/examples/jsm/modifiers/CurveModifierGPU.js +42 -19
- package/examples/jsm/modifiers/EdgeSplitModifier.js +20 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +24 -10
- package/examples/jsm/modifiers/TessellateModifier.js +35 -2
- package/examples/jsm/objects/GroundedSkybox.js +25 -6
- package/examples/jsm/objects/Lensflare.js +94 -2
- package/examples/jsm/objects/LensflareMesh.js +64 -10
- package/examples/jsm/objects/MarchingCubes.js +90 -5
- package/examples/jsm/objects/Reflector.js +76 -2
- package/examples/jsm/objects/ReflectorForSSRPass.js +41 -0
- package/examples/jsm/objects/Refractor.js +62 -0
- package/examples/jsm/objects/ShadowMesh.js +54 -4
- package/examples/jsm/objects/Sky.js +106 -16
- package/examples/jsm/objects/SkyMesh.js +211 -38
- package/examples/jsm/objects/Water.js +49 -8
- package/examples/jsm/objects/Water2.js +49 -7
- package/examples/jsm/objects/Water2Mesh.js +50 -9
- package/examples/jsm/objects/WaterMesh.js +136 -43
- package/examples/jsm/physics/AmmoPhysics.js +60 -7
- package/examples/jsm/physics/JoltPhysics.js +65 -12
- package/examples/jsm/physics/RapierPhysics.js +217 -21
- package/examples/jsm/postprocessing/AfterimagePass.js +110 -29
- package/examples/jsm/postprocessing/BloomPass.js +128 -26
- package/examples/jsm/postprocessing/BokehPass.js +99 -22
- package/examples/jsm/postprocessing/ClearPass.js +54 -3
- package/examples/jsm/postprocessing/CubeTexturePass.js +82 -21
- package/examples/jsm/postprocessing/DotScreenPass.js +59 -10
- package/examples/jsm/postprocessing/EffectComposer.js +140 -6
- package/examples/jsm/postprocessing/FXAAPass.js +40 -0
- package/examples/jsm/postprocessing/FilmPass.js +54 -5
- package/examples/jsm/postprocessing/GTAOPass.js +202 -57
- package/examples/jsm/postprocessing/GlitchPass.js +86 -34
- package/examples/jsm/postprocessing/HalftonePass.js +65 -10
- package/examples/jsm/postprocessing/LUTPass.js +38 -8
- package/examples/jsm/postprocessing/MaskPass.js +91 -0
- package/examples/jsm/postprocessing/OutlinePass.js +272 -135
- package/examples/jsm/postprocessing/OutputPass.js +65 -14
- package/examples/jsm/postprocessing/Pass.js +100 -4
- package/examples/jsm/postprocessing/RenderPass.js +94 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +124 -45
- package/examples/jsm/postprocessing/RenderTransitionPass.js +120 -21
- package/examples/jsm/postprocessing/SAOPass.js +128 -55
- package/examples/jsm/postprocessing/SMAAPass.js +106 -75
- package/examples/jsm/postprocessing/SSAARenderPass.js +118 -35
- package/examples/jsm/postprocessing/SSAOPass.js +173 -60
- package/examples/jsm/postprocessing/SSRPass.js +268 -53
- package/examples/jsm/postprocessing/SavePass.js +69 -16
- package/examples/jsm/postprocessing/ShaderPass.js +65 -7
- package/examples/jsm/postprocessing/TAARenderPass.js +79 -24
- package/examples/jsm/postprocessing/TexturePass.js +72 -8
- package/examples/jsm/postprocessing/UnrealBloomPass.js +168 -59
- package/examples/jsm/renderers/CSS2DRenderer.js +98 -5
- package/examples/jsm/renderers/CSS3DRenderer.js +111 -7
- package/examples/jsm/renderers/Projector.js +288 -32
- package/examples/jsm/renderers/SVGRenderer.js +323 -61
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +3 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +1 -1
- package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +5 -1
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +12 -5
- package/examples/jsm/shaders/AfterimageShader.js +8 -3
- package/examples/jsm/shaders/BasicShader.js +8 -1
- package/examples/jsm/shaders/BleachBypassShader.js +10 -3
- package/examples/jsm/shaders/BlendShader.js +8 -1
- package/examples/jsm/shaders/BokehShader.js +9 -3
- package/examples/jsm/shaders/BokehShader2.js +11 -4
- package/examples/jsm/shaders/BrightnessContrastShader.js +10 -4
- package/examples/jsm/shaders/ColorCorrectionShader.js +8 -1
- package/examples/jsm/shaders/ColorifyShader.js +8 -1
- package/examples/jsm/shaders/ConvolutionShader.js +9 -38
- package/examples/jsm/shaders/CopyShader.js +8 -1
- package/examples/jsm/shaders/DOFMipMapShader.js +10 -3
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +10 -1
- package/examples/jsm/shaders/DigitalGlitch.js +10 -7
- package/examples/jsm/shaders/DotScreenShader.js +8 -3
- package/examples/jsm/shaders/ExposureShader.js +8 -1
- package/examples/jsm/shaders/FXAAShader.js +233 -221
- package/examples/jsm/shaders/FilmShader.js +13 -0
- package/examples/jsm/shaders/FocusShader.js +8 -3
- package/examples/jsm/shaders/FreiChenShader.js +10 -3
- package/examples/jsm/shaders/GTAOShader.js +55 -45
- package/examples/jsm/shaders/GammaCorrectionShader.js +11 -2
- package/examples/jsm/shaders/HalftoneShader.js +24 -4
- package/examples/jsm/shaders/HorizontalBlurShader.js +12 -3
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +9 -2
- package/examples/jsm/shaders/HueSaturationShader.js +10 -3
- package/examples/jsm/shaders/KaleidoShader.js +11 -4
- package/examples/jsm/shaders/LuminosityHighPassShader.js +8 -4
- package/examples/jsm/shaders/LuminosityShader.js +8 -2
- package/examples/jsm/shaders/MirrorShader.js +10 -4
- package/examples/jsm/shaders/NormalMapShader.js +7 -2
- package/examples/jsm/shaders/OutputShader.js +19 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +30 -17
- package/examples/jsm/shaders/RGBShiftShader.js +8 -1
- package/examples/jsm/shaders/SAOShader.js +27 -5
- package/examples/jsm/shaders/SMAAShader.js +24 -1
- package/examples/jsm/shaders/SSAOShader.js +37 -6
- package/examples/jsm/shaders/SSRShader.js +32 -6
- package/examples/jsm/shaders/SepiaShader.js +8 -3
- package/examples/jsm/shaders/SobelOperatorShader.js +9 -3
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +13 -8
- package/examples/jsm/shaders/TechnicolorShader.js +10 -4
- package/examples/jsm/shaders/ToonShader.js +29 -6
- package/examples/jsm/shaders/TriangleBlurShader.js +9 -4
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +19 -6
- package/examples/jsm/shaders/VelocityShader.js +8 -1
- package/examples/jsm/shaders/VerticalBlurShader.js +9 -2
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +8 -1
- package/examples/jsm/shaders/VignetteShader.js +8 -3
- package/examples/jsm/shaders/VolumeShader.js +11 -2
- package/examples/jsm/shaders/WaterRefractionShader.js +11 -0
- package/examples/jsm/textures/FlakesTexture.js +14 -0
- package/examples/jsm/transpiler/AST.js +436 -31
- package/examples/jsm/transpiler/GLSLDecoder.js +380 -135
- package/examples/jsm/transpiler/Linker.js +327 -0
- package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -1
- package/examples/jsm/transpiler/TSLEncoder.js +363 -97
- package/examples/jsm/transpiler/Transpiler.js +50 -1
- package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
- package/examples/jsm/transpiler/WGSLEncoder.js +839 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +244 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +549 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +282 -0
- package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +11 -4
- package/examples/jsm/tsl/display/BloomNode.js +534 -0
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +207 -0
- package/examples/jsm/tsl/display/DenoiseNode.js +334 -0
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +554 -0
- package/examples/jsm/tsl/display/DotScreenNode.js +104 -0
- package/examples/jsm/tsl/display/FXAANode.js +365 -0
- package/examples/jsm/tsl/display/FilmNode.js +101 -0
- package/examples/jsm/tsl/display/GTAONode.js +571 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +389 -0
- package/examples/jsm/tsl/display/GodraysNode.js +624 -0
- package/examples/jsm/tsl/display/LensflareNode.js +279 -0
- package/examples/jsm/tsl/display/Lut3DNode.js +109 -0
- package/examples/jsm/tsl/display/MotionBlur.js +33 -0
- package/examples/jsm/tsl/display/OutlineNode.js +762 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +89 -0
- package/examples/jsm/tsl/display/PixelationPassNode.js +335 -0
- package/examples/jsm/tsl/display/RGBShiftNode.js +96 -0
- package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
- package/examples/jsm/tsl/display/SMAANode.js +768 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +120 -49
- package/examples/jsm/tsl/display/SSGINode.js +642 -0
- package/examples/jsm/tsl/display/SSRNode.js +656 -0
- package/examples/jsm/tsl/display/SSSNode.js +490 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +9 -2
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +61 -19
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +192 -0
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +48 -12
- package/examples/jsm/tsl/display/TRAANode.js +726 -0
- package/examples/jsm/tsl/display/TransitionNode.js +141 -0
- package/examples/jsm/tsl/display/boxBlur.js +65 -0
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/display/hashBlur.js +54 -0
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +442 -0
- package/examples/jsm/tsl/math/Bayer.js +73 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +456 -0
- package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +212 -0
- package/examples/jsm/tsl/utils/Raymarching.js +70 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +91 -29
- package/examples/jsm/utils/CameraUtils.js +15 -6
- package/examples/jsm/utils/GeometryCompressionUtils.js +23 -30
- package/examples/jsm/utils/GeometryUtils.js +32 -27
- package/examples/jsm/utils/LDrawUtils.js +14 -5
- package/examples/jsm/utils/SceneOptimizer.js +458 -0
- package/examples/jsm/utils/SceneUtils.js +53 -3
- package/examples/jsm/utils/ShadowMapViewer.js +72 -33
- package/examples/jsm/utils/ShadowMapViewerGPU.js +61 -29
- package/examples/jsm/utils/SkeletonUtils.js +48 -0
- package/examples/jsm/utils/SortUtils.js +17 -5
- package/examples/jsm/utils/UVsDebug.js +12 -4
- package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +16 -0
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +20 -2
- package/examples/jsm/utils/WorkerPool.js +67 -2
- package/examples/jsm/webxr/ARButton.js +19 -0
- package/examples/jsm/webxr/OculusHandModel.js +84 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +148 -22
- package/examples/jsm/webxr/Text2D.js +20 -6
- package/examples/jsm/webxr/VRButton.js +31 -0
- package/examples/jsm/webxr/XRButton.js +23 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +94 -3
- package/examples/jsm/webxr/XREstimatedLight.js +35 -4
- package/examples/jsm/webxr/XRHandMeshModel.js +37 -0
- package/examples/jsm/webxr/XRHandModelFactory.js +96 -6
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +44 -0
- package/examples/jsm/webxr/XRPlanes.js +18 -0
- package/package.json +29 -37
- package/src/Three.Core.js +198 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +641 -0
- package/src/Three.WebGPU.Nodes.js +14 -186
- package/src/Three.WebGPU.js +16 -186
- package/src/Three.js +2 -197
- package/src/animation/AnimationAction.js +263 -31
- package/src/animation/AnimationClip.js +162 -7
- package/src/animation/AnimationMixer.js +105 -15
- package/src/animation/AnimationObjectGroup.js +45 -21
- package/src/animation/AnimationUtils.js +163 -24
- package/src/animation/KeyframeTrack.js +191 -17
- package/src/animation/PropertyBinding.js +91 -16
- package/src/animation/PropertyMixer.js +72 -5
- package/src/animation/tracks/BooleanKeyframeTrack.js +33 -6
- package/src/animation/tracks/ColorKeyframeTrack.js +26 -5
- package/src/animation/tracks/NumberKeyframeTrack.js +26 -2
- package/src/animation/tracks/QuaternionKeyframeTrack.js +30 -1
- package/src/animation/tracks/StringKeyframeTrack.js +33 -2
- package/src/animation/tracks/VectorKeyframeTrack.js +26 -2
- package/src/audio/Audio.js +386 -8
- package/src/audio/AudioAnalyser.js +58 -1
- package/src/audio/AudioContext.js +15 -0
- package/src/audio/AudioListener.js +94 -13
- package/src/audio/PositionalAudio.js +107 -0
- package/src/cameras/ArrayCamera.js +37 -0
- package/src/cameras/Camera.js +61 -0
- package/src/cameras/CubeCamera.js +86 -0
- package/src/cameras/OrthographicCamera.js +110 -1
- package/src/cameras/PerspectiveCamera.js +174 -35
- package/src/cameras/StereoCamera.js +48 -2
- package/src/constants.js +1546 -11
- package/src/core/BufferAttribute.js +417 -3
- package/src/core/BufferGeometry.js +407 -22
- package/src/core/Clock.js +69 -8
- package/src/core/EventDispatcher.js +52 -8
- package/src/core/GLBufferAttribute.js +113 -2
- package/src/core/InstancedBufferAttribute.js +29 -0
- package/src/core/InstancedBufferGeometry.js +20 -0
- package/src/core/InstancedInterleavedBuffer.js +26 -0
- package/src/core/InterleavedBuffer.js +141 -7
- package/src/core/InterleavedBufferAttribute.js +200 -2
- package/src/core/Layers.js +71 -10
- package/src/core/Object3D.js +673 -26
- package/src/core/Raycaster.js +136 -2
- package/src/core/RenderTarget.js +256 -27
- package/src/core/RenderTarget3D.js +48 -0
- package/src/core/Timer.js +184 -0
- package/src/core/Uniform.js +29 -0
- package/src/core/UniformsGroup.js +84 -2
- package/src/extras/Controls.js +89 -1
- package/src/extras/DataUtils.js +50 -9
- package/src/extras/Earcut.js +18 -779
- package/src/extras/ImageUtils.js +22 -14
- package/src/extras/PMREMGenerator.js +316 -67
- package/src/extras/ShapeUtils.js +24 -2
- package/src/extras/TextureUtils.js +101 -15
- package/src/extras/core/Curve.js +156 -55
- package/src/extras/core/CurvePath.js +63 -22
- package/src/extras/core/Interpolations.js +34 -2
- package/src/extras/core/Path.js +134 -1
- package/src/extras/core/Shape.js +66 -3
- package/src/extras/core/ShapePath.js +80 -4
- package/src/extras/curves/ArcCurve.js +22 -0
- package/src/extras/curves/CatmullRomCurve3.js +89 -18
- package/src/extras/curves/CubicBezierCurve.js +67 -0
- package/src/extras/curves/CubicBezierCurve3.js +50 -0
- package/src/extras/curves/EllipseCurve.js +102 -0
- package/src/extras/curves/LineCurve.js +36 -0
- package/src/extras/curves/LineCurve3.js +36 -0
- package/src/extras/curves/QuadraticBezierCurve.js +59 -0
- package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
- package/src/extras/curves/SplineCurve.js +48 -0
- package/src/extras/lib/earcut.js +685 -0
- package/src/geometries/BoxGeometry.js +39 -0
- package/src/geometries/CapsuleGeometry.js +196 -11
- package/src/geometries/CircleGeometry.js +41 -0
- package/src/geometries/ConeGeometry.js +39 -0
- package/src/geometries/CylinderGeometry.js +42 -2
- package/src/geometries/DodecahedronGeometry.js +33 -0
- package/src/geometries/EdgesGeometry.js +30 -2
- package/src/geometries/ExtrudeGeometry.js +148 -52
- package/src/geometries/IcosahedronGeometry.js +33 -0
- package/src/geometries/LatheGeometry.js +44 -3
- package/src/geometries/OctahedronGeometry.js +33 -0
- package/src/geometries/PlaneGeometry.js +35 -0
- package/src/geometries/PolyhedronGeometry.js +30 -1
- package/src/geometries/RingGeometry.js +37 -0
- package/src/geometries/ShapeGeometry.js +38 -0
- package/src/geometries/SphereGeometry.js +38 -0
- package/src/geometries/TetrahedronGeometry.js +33 -0
- package/src/geometries/TorusGeometry.js +44 -3
- package/src/geometries/TorusKnotGeometry.js +39 -0
- package/src/geometries/TubeGeometry.js +50 -0
- package/src/geometries/WireframeGeometry.js +32 -0
- package/src/helpers/ArrowHelper.js +62 -5
- package/src/helpers/AxesHelper.js +28 -0
- package/src/helpers/Box3Helper.js +28 -0
- package/src/helpers/BoxHelper.js +43 -7
- package/src/helpers/CameraHelper.js +103 -27
- package/src/helpers/DirectionalLightHelper.js +55 -0
- package/src/helpers/GridHelper.js +26 -0
- package/src/helpers/HemisphereLightHelper.js +42 -0
- package/src/helpers/PlaneHelper.js +33 -0
- package/src/helpers/PointLightHelper.js +43 -24
- package/src/helpers/PolarGridHelper.js +30 -0
- package/src/helpers/SkeletonHelper.js +73 -7
- package/src/helpers/SpotLightHelper.js +43 -0
- package/src/lights/AmbientLight.js +25 -0
- package/src/lights/DirectionalLight.js +70 -0
- package/src/lights/DirectionalLightShadow.js +15 -0
- package/src/lights/HemisphereLight.js +42 -0
- package/src/lights/Light.js +37 -11
- package/src/lights/LightProbe.js +37 -9
- package/src/lights/LightShadow.js +202 -7
- package/src/lights/PointLight.js +74 -0
- package/src/lights/PointLightShadow.js +15 -80
- package/src/lights/RectAreaLight.js +59 -0
- package/src/lights/SpotLight.js +124 -1
- package/src/lights/SpotLightShadow.js +33 -3
- package/src/lights/webgpu/IESSpotLight.js +22 -0
- package/src/lights/webgpu/ProjectorLight.js +46 -0
- package/src/loaders/AnimationLoader.js +34 -2
- package/src/loaders/AudioLoader.js +34 -2
- package/src/loaders/BufferGeometryLoader.js +38 -13
- package/src/loaders/Cache.js +75 -2
- package/src/loaders/CompressedTextureLoader.js +36 -3
- package/src/loaders/CubeTextureLoader.js +45 -0
- package/src/loaders/DataTextureLoader.js +45 -4
- package/src/loaders/FileLoader.js +85 -5
- package/src/loaders/ImageBitmapLoader.js +113 -11
- package/src/loaders/ImageLoader.js +85 -8
- package/src/loaders/Loader.js +150 -0
- package/src/loaders/LoaderUtils.js +18 -36
- package/src/loaders/LoadingManager.js +187 -0
- package/src/loaders/MaterialLoader.js +62 -3
- package/src/loaders/ObjectLoader.js +131 -31
- package/src/loaders/TextureLoader.js +33 -0
- package/src/loaders/nodes/NodeLoader.js +68 -4
- package/src/loaders/nodes/NodeMaterialLoader.js +45 -0
- package/src/loaders/nodes/NodeObjectLoader.js +61 -0
- package/src/materials/LineBasicMaterial.js +74 -1
- package/src/materials/LineDashedMaterial.js +52 -1
- package/src/materials/Material.js +502 -8
- package/src/materials/MeshBasicMaterial.js +168 -2
- package/src/materials/MeshDepthMaterial.js +94 -0
- package/src/materials/MeshDistanceMaterial.js +76 -0
- package/src/materials/MeshLambertMaterial.js +283 -0
- package/src/materials/MeshMatcapMaterial.js +164 -0
- package/src/materials/MeshNormalMaterial.js +114 -0
- package/src/materials/MeshPhongMaterial.js +298 -0
- package/src/materials/MeshPhysicalMaterial.js +296 -4
- package/src/materials/MeshStandardMaterial.js +300 -2
- package/src/materials/MeshToonMaterial.js +219 -0
- package/src/materials/PointsMaterial.js +89 -0
- package/src/materials/RawShaderMaterial.js +25 -0
- package/src/materials/ShaderMaterial.js +234 -6
- package/src/materials/ShadowMaterial.js +54 -0
- package/src/materials/SpriteMaterial.js +82 -0
- package/src/materials/nodes/Line2NodeMaterial.js +158 -53
- package/src/materials/nodes/LineBasicNodeMaterial.js +17 -2
- package/src/materials/nodes/LineDashedNodeMaterial.js +81 -6
- package/src/materials/nodes/MeshBasicNodeMaterial.js +59 -2
- package/src/materials/nodes/MeshLambertNodeMaterial.js +35 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +23 -3
- package/src/materials/nodes/MeshNormalNodeMaterial.js +27 -4
- package/src/materials/nodes/MeshPhongNodeMaterial.js +64 -1
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +276 -3
- package/src/materials/nodes/MeshSSSNodeMaterial.js +98 -10
- package/src/materials/nodes/MeshStandardNodeMaterial.js +83 -4
- package/src/materials/nodes/MeshToonNodeMaterial.js +28 -0
- package/src/materials/nodes/NodeMaterial.js +789 -74
- package/src/materials/nodes/NodeMaterials.js +0 -1
- package/src/materials/nodes/PointsNodeMaterial.js +180 -11
- package/src/materials/nodes/ShadowNodeMaterial.js +38 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +86 -23
- package/src/materials/nodes/VolumeNodeMaterial.js +57 -84
- package/src/materials/nodes/manager/NodeMaterialObserver.js +329 -12
- package/src/math/Box2.js +177 -0
- package/src/math/Box3.js +271 -0
- package/src/math/Color.js +355 -11
- package/src/math/ColorManagement.js +158 -92
- package/src/math/Cylindrical.js +65 -6
- package/src/math/Euler.js +139 -5
- package/src/math/Frustum.js +108 -9
- package/src/math/FrustumArray.js +258 -0
- package/src/math/Interpolant.js +87 -8
- package/src/math/Line3.js +221 -2
- package/src/math/MathUtils.js +408 -20
- package/src/math/Matrix2.js +70 -0
- package/src/math/Matrix3.js +229 -4
- package/src/math/Matrix4.js +489 -94
- package/src/math/Plane.js +164 -2
- package/src/math/Quaternion.js +322 -90
- package/src/math/Ray.js +162 -0
- package/src/math/Sphere.js +175 -0
- package/src/math/Spherical.js +73 -11
- package/src/math/SphericalHarmonics3.js +112 -14
- package/src/math/Triangle.js +206 -2
- package/src/math/Vector2.js +396 -10
- package/src/math/Vector3.js +550 -15
- package/src/math/Vector4.js +415 -9
- package/src/math/interpolants/BezierInterpolant.js +108 -0
- package/src/math/interpolants/CubicInterpolant.js +10 -1
- package/src/math/interpolants/DiscreteInterpolant.js +10 -2
- package/src/math/interpolants/LinearInterpolant.js +13 -0
- package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
- package/src/nodes/Nodes.js +91 -88
- package/src/nodes/TSL.js +32 -38
- package/src/nodes/accessors/AccessorsUtils.js +37 -9
- package/src/nodes/accessors/Arrays.js +68 -0
- package/src/nodes/accessors/BatchNode.js +49 -14
- package/src/nodes/accessors/Bitangent.js +82 -13
- package/src/nodes/accessors/BufferAttributeNode.js +269 -8
- package/src/nodes/accessors/BufferNode.js +91 -2
- package/src/nodes/accessors/BuiltinNode.js +63 -0
- package/src/nodes/accessors/Camera.js +400 -10
- package/src/nodes/accessors/ClippingNode.js +149 -45
- package/src/nodes/accessors/CubeTextureNode.js +137 -7
- package/src/nodes/accessors/InstanceNode.js +245 -40
- package/src/nodes/accessors/InstancedMeshNode.js +50 -0
- package/src/nodes/accessors/Lights.js +88 -0
- package/src/nodes/accessors/MaterialNode.js +355 -13
- package/src/nodes/accessors/MaterialProperties.js +57 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +52 -14
- package/src/nodes/accessors/ModelNode.js +117 -5
- package/src/nodes/accessors/ModelViewProjectionNode.js +10 -39
- package/src/nodes/accessors/MorphNode.js +73 -26
- package/src/nodes/accessors/Normal.js +174 -19
- package/src/nodes/accessors/Object3DNode.js +146 -12
- package/src/nodes/accessors/PointUVNode.js +25 -0
- package/src/nodes/accessors/Position.js +119 -7
- package/src/nodes/accessors/ReferenceBaseNode.js +190 -4
- package/src/nodes/accessors/ReferenceNode.js +223 -8
- package/src/nodes/accessors/ReflectVector.js +29 -3
- package/src/nodes/accessors/RendererReferenceNode.js +45 -2
- package/src/nodes/accessors/SceneProperties.js +53 -0
- package/src/nodes/accessors/SkinningNode.js +180 -43
- package/src/nodes/accessors/StorageBufferNode.js +278 -26
- package/src/nodes/accessors/StorageTextureNode.js +205 -12
- package/src/nodes/accessors/Tangent.js +48 -10
- package/src/nodes/accessors/TangentUtils.js +46 -0
- package/src/nodes/accessors/Texture3DNode.js +104 -11
- package/src/nodes/accessors/TextureBicubic.js +31 -4
- package/src/nodes/accessors/TextureNode.js +564 -52
- package/src/nodes/accessors/TextureSizeNode.js +42 -1
- package/src/nodes/accessors/UV.js +9 -1
- package/src/nodes/accessors/UniformArrayNode.js +226 -34
- package/src/nodes/accessors/UserDataNode.js +46 -2
- package/src/nodes/accessors/VelocityNode.js +93 -3
- package/src/nodes/accessors/VertexColorNode.js +39 -4
- package/src/nodes/code/CodeNode.js +101 -8
- package/src/nodes/code/ExpressionNode.js +29 -2
- package/src/nodes/code/FunctionCallNode.js +98 -10
- package/src/nodes/code/FunctionNode.js +69 -2
- package/src/nodes/core/ArrayNode.js +174 -0
- package/src/nodes/core/AssignNode.js +80 -9
- package/src/nodes/core/AttributeNode.js +47 -4
- package/src/nodes/core/BypassNode.js +47 -3
- package/src/nodes/core/ConstNode.js +32 -0
- package/src/nodes/core/ContextNode.js +220 -14
- package/src/nodes/core/IndexNode.js +72 -7
- package/src/nodes/core/InputNode.js +50 -1
- package/src/nodes/core/InspectorNode.js +128 -0
- package/src/nodes/core/IsolateNode.js +133 -0
- package/src/nodes/core/LightingModel.js +65 -5
- package/src/nodes/core/MRTNode.js +113 -2
- package/src/nodes/core/Node.js +595 -36
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +1840 -121
- package/src/nodes/core/NodeCache.js +41 -2
- package/src/nodes/core/NodeCode.js +31 -0
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeFrame.js +153 -24
- package/src/nodes/core/NodeFunction.js +48 -1
- package/src/nodes/core/NodeFunctionInput.js +44 -0
- package/src/nodes/core/NodeParser.js +13 -1
- package/src/nodes/core/NodeUniform.js +53 -1
- package/src/nodes/core/NodeUtils.js +201 -51
- package/src/nodes/core/NodeVar.js +47 -1
- package/src/nodes/core/NodeVarying.js +47 -1
- package/src/nodes/core/OutputStructNode.js +54 -12
- package/src/nodes/core/ParameterNode.js +60 -2
- package/src/nodes/core/PropertyNode.js +286 -7
- package/src/nodes/core/StackNode.js +337 -20
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +134 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +126 -6
- package/src/nodes/core/SubBuildNode.js +89 -0
- package/src/nodes/core/TempNode.js +31 -5
- package/src/nodes/core/UniformGroupNode.js +85 -7
- package/src/nodes/core/UniformNode.js +163 -16
- package/src/nodes/core/VarNode.js +317 -10
- package/src/nodes/core/VaryingNode.js +115 -13
- package/src/nodes/core/constants.js +40 -0
- package/src/nodes/display/BlendModes.js +171 -0
- package/src/nodes/display/BumpMapNode.js +38 -2
- package/src/nodes/display/ColorAdjustment.js +118 -6
- package/src/nodes/display/ColorSpaceFunctions.js +22 -6
- package/src/nodes/display/ColorSpaceNode.js +97 -47
- package/src/nodes/display/FrontFacingNode.js +64 -7
- package/src/nodes/display/NormalMapNode.js +101 -54
- package/src/nodes/display/PassNode.js +690 -33
- package/src/nodes/display/RenderOutputNode.js +94 -4
- package/src/nodes/display/ScreenNode.js +138 -27
- package/src/nodes/display/ToneMappingFunctions.js +62 -10
- package/src/nodes/display/ToneMappingNode.js +88 -8
- package/src/nodes/display/ToonOutlinePassNode.js +84 -4
- package/src/nodes/display/ViewportDepthNode.js +227 -10
- package/src/nodes/display/ViewportDepthTextureNode.js +39 -5
- package/src/nodes/display/ViewportSharedTextureNode.js +35 -1
- package/src/nodes/display/ViewportTextureNode.js +171 -7
- package/src/nodes/fog/Fog.js +97 -0
- package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +52 -0
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +45 -1
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
- package/src/nodes/functions/BasicLightingModel.js +28 -6
- package/src/nodes/functions/PhongLightingModel.js +36 -6
- package/src/nodes/functions/PhysicalLightingModel.js +336 -91
- package/src/nodes/functions/ShadowMaskModel.js +30 -3
- package/src/nodes/functions/ToonLightingModel.js +21 -2
- package/src/nodes/functions/VolumetricLightingModel.js +183 -0
- package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
- package/src/nodes/geometry/RangeNode.js +97 -8
- package/src/nodes/gpgpu/AtomicFunctionNode.js +198 -23
- package/src/nodes/gpgpu/BarrierNode.js +52 -3
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +135 -6
- package/src/nodes/gpgpu/ComputeNode.js +212 -16
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +455 -0
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +143 -9
- package/src/nodes/lighting/AONode.js +18 -0
- package/src/nodes/lighting/AmbientLightNode.js +10 -0
- package/src/nodes/lighting/AnalyticLightNode.js +186 -399
- package/src/nodes/lighting/BasicEnvironmentNode.js +19 -0
- package/src/nodes/lighting/BasicLightMapNode.js +17 -0
- package/src/nodes/lighting/DirectionalLightNode.js +12 -11
- package/src/nodes/lighting/EnvironmentNode.js +59 -19
- package/src/nodes/lighting/HemisphereLightNode.js +33 -2
- package/src/nodes/lighting/IESSpotLightNode.js +13 -1
- package/src/nodes/lighting/IrradianceNode.js +17 -0
- package/src/nodes/lighting/LightProbeNode.js +20 -0
- package/src/nodes/lighting/LightUtils.js +11 -3
- package/src/nodes/lighting/LightingContextNode.js +52 -4
- package/src/nodes/lighting/LightingNode.js +15 -6
- package/src/nodes/lighting/LightsNode.js +238 -35
- package/src/nodes/lighting/PointLightNode.js +60 -25
- package/src/nodes/lighting/PointShadowNode.js +325 -0
- package/src/nodes/lighting/ProjectorLightNode.js +91 -0
- package/src/nodes/lighting/RectAreaLightNode.js +50 -14
- package/src/nodes/lighting/ShadowBaseNode.js +81 -0
- package/src/nodes/lighting/ShadowFilterNode.js +264 -0
- package/src/nodes/lighting/ShadowNode.js +867 -0
- package/src/nodes/lighting/SpotLightNode.js +99 -18
- package/src/nodes/materialx/MaterialXNodes.js +131 -2
- package/src/nodes/materialx/lib/mx_noise.js +166 -2
- package/src/nodes/math/BitcastNode.js +156 -0
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/ConditionalNode.js +110 -21
- package/src/nodes/math/Hash.js +8 -0
- package/src/nodes/math/MathNode.js +820 -97
- package/src/nodes/math/MathUtils.js +47 -1
- package/src/nodes/math/OperatorNode.js +517 -84
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/TriNoise3D.js +17 -7
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
- package/src/nodes/parsers/GLSLNodeParser.js +11 -0
- package/src/nodes/pmrem/PMREMNode.js +180 -23
- package/src/nodes/pmrem/PMREMUtils.js +114 -5
- package/src/nodes/procedural/Checker.js +8 -0
- package/src/nodes/shapes/Shapes.js +33 -0
- package/src/nodes/tsl/TSLBase.js +10 -4
- package/src/nodes/tsl/TSLCore.js +732 -160
- package/src/nodes/utils/ArrayElementNode.js +55 -4
- package/src/nodes/utils/ConvertNode.js +31 -0
- package/src/nodes/utils/CubeMapNode.js +79 -2
- package/src/nodes/utils/DebugNode.js +83 -0
- package/src/nodes/utils/Discard.js +18 -2
- package/src/nodes/utils/EquirectUV.js +27 -0
- package/src/nodes/utils/EventNode.js +118 -0
- package/src/nodes/utils/FlipNode.js +38 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +91 -22
- package/src/nodes/utils/JoinNode.js +57 -4
- package/src/nodes/utils/LoopNode.js +193 -55
- package/src/nodes/utils/MatcapUV.js +22 -0
- package/src/nodes/utils/MaxMipLevelNode.js +49 -1
- package/src/nodes/utils/MemberNode.js +120 -0
- package/src/nodes/utils/Oscillators.js +41 -0
- package/src/nodes/utils/Packing.js +30 -1
- package/src/nodes/utils/PostProcessingUtils.js +154 -0
- package/src/nodes/utils/RTTNode.js +165 -9
- package/src/nodes/utils/ReflectorNode.js +407 -21
- package/src/nodes/utils/RemapNode.js +81 -2
- package/src/nodes/utils/RotateNode.js +41 -1
- package/src/nodes/utils/SampleNode.js +91 -0
- package/src/nodes/utils/SetNode.js +44 -1
- package/src/nodes/utils/SplitNode.js +66 -3
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/SpriteUtils.js +16 -0
- package/src/nodes/utils/StorageArrayElementNode.js +56 -3
- package/src/nodes/utils/Timer.js +26 -0
- package/src/nodes/utils/TriplanarTextures.js +65 -0
- package/src/nodes/utils/UVUtils.js +48 -0
- package/src/nodes/utils/ViewportUtils.js +12 -0
- package/src/objects/BatchedMesh.js +798 -309
- package/src/objects/Bone.js +24 -0
- package/src/objects/ClippingGroup.js +68 -0
- package/src/objects/Group.js +24 -0
- package/src/objects/InstancedMesh.js +131 -2
- package/src/objects/LOD.js +99 -5
- package/src/objects/Line.js +90 -7
- package/src/objects/LineLoop.js +20 -0
- package/src/objects/LineSegments.js +20 -1
- package/src/objects/Mesh.js +84 -0
- package/src/objects/Points.js +60 -0
- package/src/objects/Skeleton.js +120 -5
- package/src/objects/SkinnedMesh.js +102 -6
- package/src/objects/Sprite.js +65 -1
- package/src/renderers/WebGL3DRenderTarget.js +26 -0
- package/src/renderers/WebGLArrayRenderTarget.js +26 -0
- package/src/renderers/WebGLCubeRenderTarget.js +41 -5
- package/src/renderers/WebGLRenderTarget.js +19 -0
- package/src/renderers/WebGLRenderer.js +1016 -278
- package/src/renderers/common/Animation.js +123 -14
- package/src/renderers/common/Attributes.js +41 -1
- package/src/renderers/common/Backend.js +623 -44
- package/src/renderers/common/Background.js +99 -16
- package/src/renderers/common/BindGroup.js +37 -2
- package/src/renderers/common/Binding.js +46 -0
- package/src/renderers/common/Bindings.js +211 -20
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/Buffer.js +89 -0
- package/src/renderers/common/BufferUtils.js +25 -0
- package/src/renderers/common/BundleGroup.js +57 -0
- package/src/renderers/common/CanvasTarget.js +341 -0
- package/src/renderers/common/ChainMap.js +73 -10
- package/src/renderers/common/ClippingContext.js +172 -87
- package/src/renderers/common/Color4.js +40 -0
- package/src/renderers/common/ComputePipeline.js +24 -0
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/CubeRenderTarget.js +77 -7
- package/src/renderers/common/DataMap.js +37 -1
- package/src/renderers/common/Geometries.js +163 -14
- package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
- package/src/renderers/common/Info.js +81 -36
- package/src/renderers/common/InspectorBase.js +146 -0
- package/src/renderers/common/Lighting.js +57 -0
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +150 -7
- package/src/renderers/common/PostProcessing.js +22 -84
- package/src/renderers/common/ProgrammableStage.js +60 -2
- package/src/renderers/common/QuadMesh.js +63 -6
- package/src/renderers/common/RenderBundle.js +14 -8
- package/src/renderers/common/RenderBundles.js +40 -10
- package/src/renderers/common/RenderContext.js +219 -4
- package/src/renderers/common/RenderContexts.js +54 -17
- package/src/renderers/common/RenderList.js +233 -24
- package/src/renderers/common/RenderLists.js +46 -6
- package/src/renderers/common/RenderObject.js +548 -46
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +133 -15
- package/src/renderers/common/RenderPipeline.js +216 -6
- package/src/renderers/common/Renderer.js +2155 -332
- package/src/renderers/common/RendererUtils.js +200 -0
- package/src/renderers/common/SampledTexture.js +99 -39
- package/src/renderers/common/Sampler.js +148 -1
- package/src/renderers/common/Storage3DTexture.js +100 -0
- package/src/renderers/common/StorageArrayTexture.js +84 -0
- package/src/renderers/common/StorageBuffer.js +38 -2
- package/src/renderers/common/StorageBufferAttribute.js +31 -2
- package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
- package/src/renderers/common/StorageTexture.js +65 -0
- package/src/renderers/common/Textures.js +273 -57
- package/src/renderers/common/TimestampQueryPool.js +163 -0
- package/src/renderers/common/Uniform.js +233 -3
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +235 -26
- package/src/renderers/common/XRManager.js +1677 -0
- package/src/renderers/common/XRRenderTarget.js +91 -0
- package/src/renderers/common/extras/PMREMGenerator.js +371 -108
- package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
- package/src/renderers/common/nodes/NodeLibrary.js +95 -17
- package/src/renderers/common/nodes/NodeManager.js +852 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +84 -8
- package/src/renderers/common/nodes/NodeSampler.js +41 -1
- package/src/renderers/common/nodes/NodeStorageBuffer.js +48 -3
- package/src/renderers/common/nodes/NodeUniform.js +285 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +81 -0
- package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
- package/src/renderers/shaders/DFGLUTData.js +49 -0
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -12
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +154 -59
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +230 -181
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderChunk.js +3 -3
- package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +14 -2
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +7 -5
- package/src/renderers/shaders/UniformsLib.js +2 -7
- package/src/renderers/shaders/UniformsUtils.js +21 -2
- package/src/renderers/webgl/WebGLAttributes.js +4 -0
- package/src/renderers/webgl/WebGLBackground.js +30 -5
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +7 -14
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLExtensions.js +2 -25
- package/src/renderers/webgl/WebGLGeometries.js +10 -35
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLInfo.js +3 -1
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLMaterials.js +12 -0
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLOutput.js +267 -0
- package/src/renderers/webgl/WebGLProgram.js +87 -148
- package/src/renderers/webgl/WebGLPrograms.js +53 -51
- package/src/renderers/webgl/WebGLRenderLists.js +15 -0
- package/src/renderers/webgl/WebGLShadowMap.js +204 -28
- package/src/renderers/webgl/WebGLState.js +88 -56
- package/src/renderers/webgl/WebGLTextures.js +293 -59
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUniformsGroups.js +5 -3
- package/src/renderers/webgl/WebGLUtils.js +7 -5
- package/src/renderers/webgl-fallback/WebGLBackend.js +1416 -293
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +785 -92
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +62 -1
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLConstants.js +3 -3
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +584 -20
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +468 -80
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +396 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +72 -24
- package/src/renderers/webgpu/WebGPUBackend.js +1517 -428
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +31 -4
- package/src/renderers/webgpu/WebGPURenderer.js +55 -4
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +23 -16
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +37 -42
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +1335 -241
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +32 -4
- package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +144 -20
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +460 -116
- package/src/renderers/webgpu/utils/WebGPUConstants.js +17 -4
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +283 -69
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +225 -178
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +583 -191
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +310 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +150 -28
- package/src/renderers/webxr/WebXRController.js +87 -2
- package/src/renderers/webxr/WebXRDepthSensing.js +52 -7
- package/src/renderers/webxr/WebXRManager.js +275 -15
- package/src/scenes/Fog.js +60 -0
- package/src/scenes/FogExp2.js +51 -0
- package/src/scenes/Scene.js +88 -0
- package/src/textures/CanvasTexture.js +28 -0
- package/src/textures/CompressedArrayTexture.js +57 -0
- package/src/textures/CompressedCubeTexture.js +29 -0
- package/src/textures/CompressedTexture.js +64 -6
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/CubeTexture.js +52 -4
- package/src/textures/Data3DTexture.js +79 -2
- package/src/textures/DataArrayTexture.js +93 -0
- package/src/textures/DataTexture.js +65 -0
- package/src/textures/DepthTexture.js +59 -11
- package/src/textures/ExternalTexture.js +56 -0
- package/src/textures/FramebufferTexture.js +62 -0
- package/src/textures/Source.js +106 -4
- package/src/textures/Texture.js +488 -6
- package/src/textures/VideoFrameTexture.js +72 -0
- package/src/textures/VideoTexture.js +78 -6
- package/src/utils.js +322 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
- package/examples/jsm/animation/MMDPhysics.js +0 -1406
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/examples/jsm/effects/PeppersGhostEffect.js +0 -153
- package/examples/jsm/exporters/MMDExporter.js +0 -217
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
- package/examples/jsm/geometries/ParametricGeometries.js +0 -254
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +0 -729
- package/examples/jsm/loaders/MMDLoader.js +0 -2295
- package/examples/jsm/loaders/RGBMLoader.js +0 -1081
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -432
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -144
- package/examples/jsm/misc/Timer.js +0 -128
- package/examples/jsm/objects/InstancedPoints.js +0 -21
- package/examples/jsm/shaders/GodRaysShader.js +0 -321
- package/examples/jsm/shaders/MMDToonShader.js +0 -134
- package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -156
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -24
- package/src/nodes/accessors/SceneNode.js +0 -55
- package/src/nodes/code/ScriptableNode.js +0 -505
- package/src/nodes/code/ScriptableValueNode.js +0 -170
- package/src/nodes/core/CacheNode.js +0 -50
- package/src/nodes/core/UniformGroup.js +0 -13
- package/src/nodes/display/AfterImageNode.js +0 -158
- package/src/nodes/display/AnaglyphPassNode.js +0 -67
- package/src/nodes/display/AnamorphicNode.js +0 -151
- package/src/nodes/display/BlendMode.js +0 -54
- package/src/nodes/display/BloomNode.js +0 -341
- package/src/nodes/display/DenoiseNode.js +0 -204
- package/src/nodes/display/DepthOfFieldNode.js +0 -124
- package/src/nodes/display/DotScreenNode.js +0 -66
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/display/FilmNode.js +0 -56
- package/src/nodes/display/GTAONode.js +0 -331
- package/src/nodes/display/GaussianBlurNode.js +0 -213
- package/src/nodes/display/Lut3DNode.js +0 -57
- package/src/nodes/display/MotionBlur.js +0 -25
- package/src/nodes/display/ParallaxBarrierPassNode.js +0 -58
- package/src/nodes/display/PixelationPassNode.js +0 -213
- package/src/nodes/display/PosterizeNode.js +0 -33
- package/src/nodes/display/RGBShiftNode.js +0 -53
- package/src/nodes/display/StereoCompositePassNode.js +0 -110
- package/src/nodes/display/TransitionNode.js +0 -80
- package/src/nodes/fog/FogExp2Node.js +0 -35
- package/src/nodes/fog/FogNode.js +0 -50
- package/src/nodes/fog/FogRangeNode.js +0 -36
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -30
- package/src/nodes/utils/EquirectUVNode.js +0 -36
- package/src/nodes/utils/MatcapUVNode.js +0 -33
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/SpriteSheetUVNode.js +0 -45
- package/src/nodes/utils/TimerNode.js +0 -97
- package/src/nodes/utils/TriplanarTexturesNode.js +0 -64
- package/src/renderers/common/nodes/Nodes.js +0 -534
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -136
|
@@ -9,156 +9,710 @@ import RenderLists from './RenderLists.js';
|
|
|
9
9
|
import RenderContexts from './RenderContexts.js';
|
|
10
10
|
import Textures from './Textures.js';
|
|
11
11
|
import Background from './Background.js';
|
|
12
|
-
import
|
|
12
|
+
import NodeManager from './nodes/NodeManager.js';
|
|
13
13
|
import Color4 from './Color4.js';
|
|
14
14
|
import ClippingContext from './ClippingContext.js';
|
|
15
15
|
import QuadMesh from './QuadMesh.js';
|
|
16
16
|
import RenderBundles from './RenderBundles.js';
|
|
17
17
|
import NodeLibrary from './nodes/NodeLibrary.js';
|
|
18
|
+
import Lighting from './Lighting.js';
|
|
19
|
+
import XRManager from './XRManager.js';
|
|
20
|
+
import InspectorBase from './InspectorBase.js';
|
|
21
|
+
import CanvasTarget from './CanvasTarget.js';
|
|
18
22
|
|
|
19
23
|
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
20
24
|
|
|
21
25
|
import { Scene } from '../../scenes/Scene.js';
|
|
26
|
+
import { ColorManagement } from '../../math/ColorManagement.js';
|
|
22
27
|
import { Frustum } from '../../math/Frustum.js';
|
|
28
|
+
import { FrustumArray } from '../../math/FrustumArray.js';
|
|
23
29
|
import { Matrix4 } from '../../math/Matrix4.js';
|
|
24
30
|
import { Vector2 } from '../../math/Vector2.js';
|
|
25
31
|
import { Vector4 } from '../../math/Vector4.js';
|
|
26
32
|
import { RenderTarget } from '../../core/RenderTarget.js';
|
|
27
|
-
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter,
|
|
33
|
+
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, HalfFloatType, RGBAFormat, PCFShadowMap, VSMShadowMap } from '../../constants.js';
|
|
34
|
+
|
|
35
|
+
import { float, vec3, vec4, Fn } from '../../nodes/tsl/TSLCore.js';
|
|
36
|
+
import { reference } from '../../nodes/accessors/ReferenceNode.js';
|
|
37
|
+
import { highpModelNormalViewMatrix, highpModelViewMatrix } from '../../nodes/accessors/ModelNode.js';
|
|
38
|
+
import { context } from '../../nodes/core/ContextNode.js';
|
|
39
|
+
import { error, warn, warnOnce } from '../../utils.js';
|
|
28
40
|
|
|
29
41
|
const _scene = /*@__PURE__*/ new Scene();
|
|
30
42
|
const _drawingBufferSize = /*@__PURE__*/ new Vector2();
|
|
31
43
|
const _screen = /*@__PURE__*/ new Vector4();
|
|
32
44
|
const _frustum = /*@__PURE__*/ new Frustum();
|
|
45
|
+
const _frustumArray = /*@__PURE__*/ new FrustumArray();
|
|
46
|
+
|
|
33
47
|
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
|
|
34
48
|
const _vector4 = /*@__PURE__*/ new Vector4();
|
|
35
49
|
|
|
50
|
+
const _shadowSide = { [ FrontSide ]: BackSide, [ BackSide ]: FrontSide, [ DoubleSide ]: DoubleSide };
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Base class for renderers.
|
|
54
|
+
*/
|
|
36
55
|
class Renderer {
|
|
37
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Renderer options.
|
|
59
|
+
*
|
|
60
|
+
* @typedef {Object} Renderer~Options
|
|
61
|
+
* @property {boolean} [logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
|
|
62
|
+
* @property {boolean} [reversedDepthBuffer=false] - Whether reversed depth buffer is enabled or not.
|
|
63
|
+
* @property {boolean} [alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
|
|
64
|
+
* @property {boolean} [depth=true] - Whether the default framebuffer should have a depth buffer or not.
|
|
65
|
+
* @property {boolean} [stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
|
|
66
|
+
* @property {boolean} [antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
|
|
67
|
+
* @property {number} [samples=0] - When `antialias` is `true`, `4` samples are used by default. This parameter can set to any other integer value than 0
|
|
68
|
+
* to overwrite the default.
|
|
69
|
+
* @property {?Function} [getFallback=null] - This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
|
|
70
|
+
* @property {number} [outputBufferType=HalfFloatType] - Defines the type of output buffers. The default `HalfFloatType` is recommend for best
|
|
71
|
+
* quality. To save memory and bandwidth, `UnsignedByteType` might be used. This will reduce rendering quality though.
|
|
72
|
+
* @property {boolean} [multiview=false] - If set to `true`, the renderer will use multiview during WebXR rendering if supported.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Constructs a new renderer.
|
|
77
|
+
*
|
|
78
|
+
* @param {Backend} backend - The backend the renderer is targeting (e.g. WebGPU or WebGL 2).
|
|
79
|
+
* @param {Renderer~Options} [parameters] - The configuration parameter.
|
|
80
|
+
|
|
81
|
+
*/
|
|
38
82
|
constructor( backend, parameters = {} ) {
|
|
39
83
|
|
|
84
|
+
/**
|
|
85
|
+
* This flag can be used for type testing.
|
|
86
|
+
*
|
|
87
|
+
* @type {boolean}
|
|
88
|
+
* @readonly
|
|
89
|
+
* @default true
|
|
90
|
+
*/
|
|
40
91
|
this.isRenderer = true;
|
|
41
92
|
|
|
42
93
|
//
|
|
43
94
|
|
|
44
95
|
const {
|
|
45
96
|
logarithmicDepthBuffer = false,
|
|
97
|
+
reversedDepthBuffer = false,
|
|
46
98
|
alpha = true,
|
|
47
99
|
depth = true,
|
|
48
100
|
stencil = false,
|
|
49
101
|
antialias = false,
|
|
50
102
|
samples = 0,
|
|
51
|
-
getFallback = null
|
|
103
|
+
getFallback = null,
|
|
104
|
+
outputBufferType = HalfFloatType,
|
|
105
|
+
multiview = false
|
|
52
106
|
} = parameters;
|
|
53
107
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
108
|
+
/**
|
|
109
|
+
* A reference to the current backend.
|
|
110
|
+
*
|
|
111
|
+
* @type {Backend}
|
|
112
|
+
*/
|
|
57
113
|
this.backend = backend;
|
|
58
114
|
|
|
59
|
-
|
|
60
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Whether the renderer should automatically clear the current rendering target
|
|
117
|
+
* before execute a `render()` call. The target can be the canvas (default framebuffer)
|
|
118
|
+
* or the current bound render target (custom framebuffer).
|
|
119
|
+
*
|
|
120
|
+
* @type {boolean}
|
|
121
|
+
* @default true
|
|
122
|
+
*/
|
|
61
123
|
this.autoClear = true;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
127
|
+
* should clear the color buffer.
|
|
128
|
+
*
|
|
129
|
+
* @type {boolean}
|
|
130
|
+
* @default true
|
|
131
|
+
*/
|
|
62
132
|
this.autoClearColor = true;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
136
|
+
* should clear the depth buffer.
|
|
137
|
+
*
|
|
138
|
+
* @type {boolean}
|
|
139
|
+
* @default true
|
|
140
|
+
*/
|
|
63
141
|
this.autoClearDepth = true;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* When `autoClear` is set to `true`, this property defines whether the renderer
|
|
145
|
+
* should clear the stencil buffer.
|
|
146
|
+
*
|
|
147
|
+
* @type {boolean}
|
|
148
|
+
* @default true
|
|
149
|
+
*/
|
|
64
150
|
this.autoClearStencil = true;
|
|
65
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Whether the default framebuffer should be transparent or opaque.
|
|
154
|
+
*
|
|
155
|
+
* @type {boolean}
|
|
156
|
+
* @default true
|
|
157
|
+
*/
|
|
66
158
|
this.alpha = alpha;
|
|
67
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Whether logarithmic depth buffer is enabled or not.
|
|
162
|
+
*
|
|
163
|
+
* @type {boolean}
|
|
164
|
+
* @default false
|
|
165
|
+
* @readonly
|
|
166
|
+
*/
|
|
68
167
|
this.logarithmicDepthBuffer = logarithmicDepthBuffer;
|
|
69
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Whether reversed depth buffer is enabled or not.
|
|
171
|
+
*
|
|
172
|
+
* @type {boolean}
|
|
173
|
+
* @default false
|
|
174
|
+
* @readonly
|
|
175
|
+
*/
|
|
176
|
+
this.reversedDepthBuffer = reversedDepthBuffer;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Defines the output color space of the renderer.
|
|
180
|
+
*
|
|
181
|
+
* @type {string}
|
|
182
|
+
* @default SRGBColorSpace
|
|
183
|
+
*/
|
|
70
184
|
this.outputColorSpace = SRGBColorSpace;
|
|
71
185
|
|
|
186
|
+
/**
|
|
187
|
+
* Defines the tone mapping of the renderer.
|
|
188
|
+
*
|
|
189
|
+
* @type {number}
|
|
190
|
+
* @default NoToneMapping
|
|
191
|
+
*/
|
|
72
192
|
this.toneMapping = NoToneMapping;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Defines the tone mapping exposure.
|
|
196
|
+
*
|
|
197
|
+
* @type {number}
|
|
198
|
+
* @default 1
|
|
199
|
+
*/
|
|
73
200
|
this.toneMappingExposure = 1.0;
|
|
74
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Whether the renderer should sort its render lists or not.
|
|
204
|
+
*
|
|
205
|
+
* Note: Sorting is used to attempt to properly render objects that have some degree of transparency.
|
|
206
|
+
* By definition, sorting objects may not work in all cases. Depending on the needs of application,
|
|
207
|
+
* it may be necessary to turn off sorting and use other methods to deal with transparency rendering
|
|
208
|
+
* e.g. manually determining each object's rendering order.
|
|
209
|
+
*
|
|
210
|
+
* @type {boolean}
|
|
211
|
+
* @default true
|
|
212
|
+
*/
|
|
75
213
|
this.sortObjects = true;
|
|
76
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Whether the default framebuffer should have a depth buffer or not.
|
|
217
|
+
*
|
|
218
|
+
* @type {boolean}
|
|
219
|
+
* @default true
|
|
220
|
+
*/
|
|
77
221
|
this.depth = depth;
|
|
78
|
-
this.stencil = stencil;
|
|
79
222
|
|
|
80
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Whether the default framebuffer should have a stencil buffer or not.
|
|
225
|
+
*
|
|
226
|
+
* @type {boolean}
|
|
227
|
+
* @default false
|
|
228
|
+
*/
|
|
229
|
+
this.stencil = stencil;
|
|
81
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Holds a series of statistical information about the GPU memory
|
|
233
|
+
* and the rendering process. Useful for debugging and monitoring.
|
|
234
|
+
*
|
|
235
|
+
* @type {Info}
|
|
236
|
+
*/
|
|
82
237
|
this.info = new Info();
|
|
83
238
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
239
|
+
/**
|
|
240
|
+
* A global context node that stores override nodes for specific transformations or calculations.
|
|
241
|
+
* These nodes can be used to replace default behavior in the rendering pipeline.
|
|
242
|
+
*
|
|
243
|
+
* @type {ContextNode}
|
|
244
|
+
* @property {Object} value - The context value object.
|
|
245
|
+
*/
|
|
246
|
+
this.contextNode = context();
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The node library defines how certain library objects like materials, lights
|
|
250
|
+
* or tone mapping functions are mapped to node types. This is required since
|
|
251
|
+
* although instances of classes like `MeshBasicMaterial` or `PointLight` can
|
|
252
|
+
* be part of the scene graph, they are internally represented as nodes for
|
|
253
|
+
* further processing.
|
|
254
|
+
*
|
|
255
|
+
* @type {NodeLibrary}
|
|
256
|
+
*/
|
|
257
|
+
this.library = new NodeLibrary();
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* A map-like data structure for managing lights.
|
|
261
|
+
*
|
|
262
|
+
* @type {Lighting}
|
|
263
|
+
*/
|
|
264
|
+
this.lighting = new Lighting();
|
|
91
265
|
|
|
92
266
|
// internals
|
|
93
267
|
|
|
268
|
+
/**
|
|
269
|
+
* The number of MSAA samples.
|
|
270
|
+
*
|
|
271
|
+
* @private
|
|
272
|
+
* @type {number}
|
|
273
|
+
* @default 0
|
|
274
|
+
*/
|
|
275
|
+
this._samples = samples || ( antialias === true ) ? 4 : 0;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* OnCanvasTargetResize callback function.
|
|
279
|
+
*
|
|
280
|
+
* @private
|
|
281
|
+
* @type {Function}
|
|
282
|
+
*/
|
|
283
|
+
this._onCanvasTargetResize = this._onCanvasTargetResize.bind( this );
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The canvas target for rendering.
|
|
287
|
+
*
|
|
288
|
+
* @private
|
|
289
|
+
* @type {CanvasTarget}
|
|
290
|
+
*/
|
|
291
|
+
this._canvasTarget = new CanvasTarget( backend.getDomElement() );
|
|
292
|
+
this._canvasTarget.addEventListener( 'resize', this._onCanvasTargetResize );
|
|
293
|
+
this._canvasTarget.isDefaultCanvasTarget = true;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* The inspector provides information about the internal renderer state.
|
|
297
|
+
*
|
|
298
|
+
* @private
|
|
299
|
+
* @type {InspectorBase}
|
|
300
|
+
*/
|
|
301
|
+
this._inspector = new InspectorBase();
|
|
302
|
+
this._inspector.setRenderer( this );
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
|
|
306
|
+
*
|
|
307
|
+
* @private
|
|
308
|
+
* @type {?Function}
|
|
309
|
+
*/
|
|
94
310
|
this._getFallback = getFallback;
|
|
95
311
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
312
|
+
/**
|
|
313
|
+
* A reference to a renderer module for managing shader attributes.
|
|
314
|
+
*
|
|
315
|
+
* @private
|
|
316
|
+
* @type {?Attributes}
|
|
317
|
+
* @default null
|
|
318
|
+
*/
|
|
104
319
|
this._attributes = null;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* A reference to a renderer module for managing geometries.
|
|
323
|
+
*
|
|
324
|
+
* @private
|
|
325
|
+
* @type {?Geometries}
|
|
326
|
+
* @default null
|
|
327
|
+
*/
|
|
105
328
|
this._geometries = null;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* A reference to a renderer module for managing node related logic.
|
|
332
|
+
*
|
|
333
|
+
* @private
|
|
334
|
+
* @type {?NodeManager}
|
|
335
|
+
* @default null
|
|
336
|
+
*/
|
|
106
337
|
this._nodes = null;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* A reference to a renderer module for managing the internal animation loop.
|
|
341
|
+
*
|
|
342
|
+
* @private
|
|
343
|
+
* @type {?Animation}
|
|
344
|
+
* @default null
|
|
345
|
+
*/
|
|
107
346
|
this._animation = null;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* A reference to a renderer module for managing shader program bindings.
|
|
350
|
+
*
|
|
351
|
+
* @private
|
|
352
|
+
* @type {?Bindings}
|
|
353
|
+
* @default null
|
|
354
|
+
*/
|
|
108
355
|
this._bindings = null;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* A reference to a renderer module for managing render objects.
|
|
359
|
+
*
|
|
360
|
+
* @private
|
|
361
|
+
* @type {?RenderObjects}
|
|
362
|
+
* @default null
|
|
363
|
+
*/
|
|
109
364
|
this._objects = null;
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* A reference to a renderer module for managing render and compute pipelines.
|
|
368
|
+
*
|
|
369
|
+
* @private
|
|
370
|
+
* @type {?Pipelines}
|
|
371
|
+
* @default null
|
|
372
|
+
*/
|
|
110
373
|
this._pipelines = null;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* A reference to a renderer module for managing render bundles.
|
|
377
|
+
*
|
|
378
|
+
* @private
|
|
379
|
+
* @type {?RenderBundles}
|
|
380
|
+
* @default null
|
|
381
|
+
*/
|
|
111
382
|
this._bundles = null;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* A reference to a renderer module for managing render lists.
|
|
386
|
+
*
|
|
387
|
+
* @private
|
|
388
|
+
* @type {?RenderLists}
|
|
389
|
+
* @default null
|
|
390
|
+
*/
|
|
112
391
|
this._renderLists = null;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* A reference to a renderer module for managing render contexts.
|
|
395
|
+
*
|
|
396
|
+
* @private
|
|
397
|
+
* @type {?RenderContexts}
|
|
398
|
+
* @default null
|
|
399
|
+
*/
|
|
113
400
|
this._renderContexts = null;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* A reference to a renderer module for managing textures.
|
|
404
|
+
*
|
|
405
|
+
* @private
|
|
406
|
+
* @type {?Textures}
|
|
407
|
+
* @default null
|
|
408
|
+
*/
|
|
114
409
|
this._textures = null;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* A reference to a renderer module for backgrounds.
|
|
413
|
+
*
|
|
414
|
+
* @private
|
|
415
|
+
* @type {?Background}
|
|
416
|
+
* @default null
|
|
417
|
+
*/
|
|
115
418
|
this._background = null;
|
|
116
419
|
|
|
420
|
+
/**
|
|
421
|
+
* This fullscreen quad is used for internal render passes
|
|
422
|
+
* like the tone mapping and color space output pass.
|
|
423
|
+
*
|
|
424
|
+
* @private
|
|
425
|
+
* @type {QuadMesh}
|
|
426
|
+
*/
|
|
117
427
|
this._quad = new QuadMesh( new NodeMaterial() );
|
|
118
|
-
this._quad.
|
|
119
|
-
|
|
428
|
+
this._quad.name = 'Output Color Transform';
|
|
429
|
+
this._quad.material.name = 'outputColorTransform';
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* A reference to the current render context.
|
|
433
|
+
*
|
|
434
|
+
* @private
|
|
435
|
+
* @type {?RenderContext}
|
|
436
|
+
* @default null
|
|
437
|
+
*/
|
|
120
438
|
this._currentRenderContext = null;
|
|
121
439
|
|
|
440
|
+
/**
|
|
441
|
+
* A custom sort function for the opaque render list.
|
|
442
|
+
*
|
|
443
|
+
* @private
|
|
444
|
+
* @type {?Function}
|
|
445
|
+
* @default null
|
|
446
|
+
*/
|
|
122
447
|
this._opaqueSort = null;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* A custom sort function for the transparent render list.
|
|
451
|
+
*
|
|
452
|
+
* @private
|
|
453
|
+
* @type {?Function}
|
|
454
|
+
* @default null
|
|
455
|
+
*/
|
|
123
456
|
this._transparentSort = null;
|
|
124
457
|
|
|
458
|
+
/**
|
|
459
|
+
* The framebuffer target.
|
|
460
|
+
*
|
|
461
|
+
* @private
|
|
462
|
+
* @type {?RenderTarget}
|
|
463
|
+
* @default null
|
|
464
|
+
*/
|
|
125
465
|
this._frameBufferTarget = null;
|
|
126
466
|
|
|
127
467
|
const alphaClear = this.alpha === true ? 0 : 1;
|
|
128
468
|
|
|
469
|
+
/**
|
|
470
|
+
* The clear color value.
|
|
471
|
+
*
|
|
472
|
+
* @private
|
|
473
|
+
* @type {Color4}
|
|
474
|
+
*/
|
|
129
475
|
this._clearColor = new Color4( 0, 0, 0, alphaClear );
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* The clear depth value.
|
|
479
|
+
*
|
|
480
|
+
* @private
|
|
481
|
+
* @type {number}
|
|
482
|
+
* @default 1
|
|
483
|
+
*/
|
|
130
484
|
this._clearDepth = 1;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* The clear stencil value.
|
|
488
|
+
*
|
|
489
|
+
* @private
|
|
490
|
+
* @type {number}
|
|
491
|
+
* @default 0
|
|
492
|
+
*/
|
|
131
493
|
this._clearStencil = 0;
|
|
132
494
|
|
|
495
|
+
/**
|
|
496
|
+
* The current render target.
|
|
497
|
+
*
|
|
498
|
+
* @private
|
|
499
|
+
* @type {?RenderTarget}
|
|
500
|
+
* @default null
|
|
501
|
+
*/
|
|
133
502
|
this._renderTarget = null;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* The active cube face.
|
|
506
|
+
*
|
|
507
|
+
* @private
|
|
508
|
+
* @type {number}
|
|
509
|
+
* @default 0
|
|
510
|
+
*/
|
|
134
511
|
this._activeCubeFace = 0;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* The active mipmap level.
|
|
515
|
+
*
|
|
516
|
+
* @private
|
|
517
|
+
* @type {number}
|
|
518
|
+
* @default 0
|
|
519
|
+
*/
|
|
135
520
|
this._activeMipmapLevel = 0;
|
|
136
521
|
|
|
522
|
+
/**
|
|
523
|
+
* The current output render target.
|
|
524
|
+
*
|
|
525
|
+
* @private
|
|
526
|
+
* @type {?RenderTarget}
|
|
527
|
+
* @default null
|
|
528
|
+
*/
|
|
529
|
+
this._outputRenderTarget = null;
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* The MRT setting.
|
|
533
|
+
*
|
|
534
|
+
* @private
|
|
535
|
+
* @type {?MRTNode}
|
|
536
|
+
* @default null
|
|
537
|
+
*/
|
|
137
538
|
this._mrt = null;
|
|
138
539
|
|
|
540
|
+
/**
|
|
541
|
+
* This function defines how a render object is going
|
|
542
|
+
* to be rendered.
|
|
543
|
+
*
|
|
544
|
+
* @private
|
|
545
|
+
* @type {?Function}
|
|
546
|
+
* @default null
|
|
547
|
+
*/
|
|
139
548
|
this._renderObjectFunction = null;
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Used to keep track of the current render object function.
|
|
552
|
+
*
|
|
553
|
+
* @private
|
|
554
|
+
* @type {?Function}
|
|
555
|
+
* @default null
|
|
556
|
+
*/
|
|
140
557
|
this._currentRenderObjectFunction = null;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Used to keep track of the current render bundle.
|
|
561
|
+
*
|
|
562
|
+
* @private
|
|
563
|
+
* @type {?RenderBundle}
|
|
564
|
+
* @default null
|
|
565
|
+
*/
|
|
141
566
|
this._currentRenderBundle = null;
|
|
142
567
|
|
|
568
|
+
/**
|
|
569
|
+
* Next to `_renderObjectFunction()`, this function provides another hook
|
|
570
|
+
* for influencing the render process of a render object. It is meant for internal
|
|
571
|
+
* use and only relevant for `compileAsync()` right now. Instead of using
|
|
572
|
+
* the default logic of `_renderObjectDirect()` which actually draws the render object,
|
|
573
|
+
* a different function might be used which performs no draw but just the node
|
|
574
|
+
* and pipeline updates.
|
|
575
|
+
*
|
|
576
|
+
* @private
|
|
577
|
+
* @type {Function}
|
|
578
|
+
*/
|
|
143
579
|
this._handleObjectFunction = this._renderObjectDirect;
|
|
144
580
|
|
|
581
|
+
/**
|
|
582
|
+
* Indicates whether the device has been lost or not. In WebGL terms, the device
|
|
583
|
+
* lost is considered as a context lost. When this is set to `true`, rendering
|
|
584
|
+
* isn't possible anymore.
|
|
585
|
+
*
|
|
586
|
+
* @private
|
|
587
|
+
* @type {boolean}
|
|
588
|
+
* @default false
|
|
589
|
+
*/
|
|
590
|
+
this._isDeviceLost = false;
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* A callback function that defines what should happen when a device/context lost occurs.
|
|
594
|
+
*
|
|
595
|
+
* @type {Function}
|
|
596
|
+
*/
|
|
597
|
+
this.onDeviceLost = this._onDeviceLost;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Defines the type of output buffers. The default `HalfFloatType` is recommend for
|
|
601
|
+
* best quality. To save memory and bandwidth, `UnsignedByteType` might be used.
|
|
602
|
+
* This will reduce rendering quality though.
|
|
603
|
+
*
|
|
604
|
+
* @private
|
|
605
|
+
* @type {number}
|
|
606
|
+
* @default HalfFloatType
|
|
607
|
+
*/
|
|
608
|
+
this._outputBufferType = outputBufferType;
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* A cache for shadow nodes per material
|
|
612
|
+
*
|
|
613
|
+
* @private
|
|
614
|
+
* @type {WeakMap<Material, Object>}
|
|
615
|
+
*/
|
|
616
|
+
this._cacheShadowNodes = new WeakMap();
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Whether the renderer has been initialized or not.
|
|
620
|
+
*
|
|
621
|
+
* @private
|
|
622
|
+
* @type {boolean}
|
|
623
|
+
* @default false
|
|
624
|
+
*/
|
|
145
625
|
this._initialized = false;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* The call depth of the renderer. Counts the number of
|
|
629
|
+
* nested render calls.
|
|
630
|
+
*
|
|
631
|
+
* @private
|
|
632
|
+
* @type {number}
|
|
633
|
+
* @default - 1
|
|
634
|
+
*/
|
|
635
|
+
this._callDepth = - 1;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* A reference to the promise which initializes the renderer.
|
|
639
|
+
*
|
|
640
|
+
* @private
|
|
641
|
+
* @type {?Promise<this>}
|
|
642
|
+
* @default null
|
|
643
|
+
*/
|
|
146
644
|
this._initPromise = null;
|
|
147
645
|
|
|
646
|
+
/**
|
|
647
|
+
* An array of compilation promises which are used in `compileAsync()`.
|
|
648
|
+
*
|
|
649
|
+
* @private
|
|
650
|
+
* @type {?Array<Promise>}
|
|
651
|
+
* @default null
|
|
652
|
+
*/
|
|
148
653
|
this._compilationPromises = null;
|
|
149
654
|
|
|
655
|
+
/**
|
|
656
|
+
* Whether the renderer should render transparent render objects or not.
|
|
657
|
+
*
|
|
658
|
+
* @type {boolean}
|
|
659
|
+
* @default true
|
|
660
|
+
*/
|
|
150
661
|
this.transparent = true;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Whether the renderer should render opaque render objects or not.
|
|
665
|
+
*
|
|
666
|
+
* @type {boolean}
|
|
667
|
+
* @default true
|
|
668
|
+
*/
|
|
151
669
|
this.opaque = true;
|
|
152
670
|
|
|
671
|
+
/**
|
|
672
|
+
* Shadow map configuration
|
|
673
|
+
* @typedef {Object} ShadowMapConfig
|
|
674
|
+
* @property {boolean} enabled - Whether to globally enable shadows or not.
|
|
675
|
+
* @property {boolean} transmitted - Whether to enable light transmission through non-opaque materials.
|
|
676
|
+
* @property {number} type - The shadow map type.
|
|
677
|
+
*/
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* The renderer's shadow configuration.
|
|
681
|
+
*
|
|
682
|
+
* @type {ShadowMapConfig}
|
|
683
|
+
*/
|
|
153
684
|
this.shadowMap = {
|
|
154
685
|
enabled: false,
|
|
686
|
+
transmitted: false,
|
|
155
687
|
type: PCFShadowMap
|
|
156
688
|
};
|
|
157
689
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
690
|
+
/**
|
|
691
|
+
* XR configuration.
|
|
692
|
+
* @typedef {Object} XRConfig
|
|
693
|
+
* @property {boolean} enabled - Whether to globally enable XR or not.
|
|
694
|
+
*/
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* The renderer's XR manager.
|
|
698
|
+
*
|
|
699
|
+
* @type {XRManager}
|
|
700
|
+
*/
|
|
701
|
+
this.xr = new XRManager( this, multiview );
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Debug configuration.
|
|
705
|
+
* @typedef {Object} DebugConfig
|
|
706
|
+
* @property {boolean} checkShaderErrors - Whether shader errors should be checked or not.
|
|
707
|
+
* @property {?Function} onShaderError - A callback function that is executed when a shader error happens. Only supported with WebGL 2 right now.
|
|
708
|
+
* @property {Function} getShaderAsync - Allows the get the raw shader code for the given scene, camera and 3D object.
|
|
709
|
+
*/
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* The renderer's debug configuration.
|
|
713
|
+
*
|
|
714
|
+
* @type {DebugConfig}
|
|
715
|
+
*/
|
|
162
716
|
this.debug = {
|
|
163
717
|
checkShaderErrors: true,
|
|
164
718
|
onShaderError: null,
|
|
@@ -167,11 +721,11 @@ class Renderer {
|
|
|
167
721
|
await this.compileAsync( scene, camera );
|
|
168
722
|
|
|
169
723
|
const renderList = this._renderLists.get( scene, camera );
|
|
170
|
-
const renderContext = this._renderContexts.get(
|
|
724
|
+
const renderContext = this._renderContexts.get( this._renderTarget, this._mrt );
|
|
171
725
|
|
|
172
726
|
const material = scene.overrideMaterial || object.material;
|
|
173
727
|
|
|
174
|
-
const renderObject = this._objects.get( object, material, scene, camera, renderList.lightsNode, renderContext );
|
|
728
|
+
const renderObject = this._objects.get( object, material, scene, camera, renderList.lightsNode, renderContext, renderContext.clippingContext );
|
|
175
729
|
|
|
176
730
|
const { fragmentShader, vertexShader } = renderObject.getNodeBuilderState();
|
|
177
731
|
|
|
@@ -182,14 +736,14 @@ class Renderer {
|
|
|
182
736
|
|
|
183
737
|
}
|
|
184
738
|
|
|
739
|
+
/**
|
|
740
|
+
* Initializes the renderer so it is ready for usage.
|
|
741
|
+
*
|
|
742
|
+
* @async
|
|
743
|
+
* @return {Promise<this>} A Promise that resolves when the renderer has been initialized.
|
|
744
|
+
*/
|
|
185
745
|
async init() {
|
|
186
746
|
|
|
187
|
-
if ( this._initialized ) {
|
|
188
|
-
|
|
189
|
-
throw new Error( 'Renderer: Backend has already been initialized.' );
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
747
|
if ( this._initPromise !== null ) {
|
|
194
748
|
|
|
195
749
|
return this._initPromise;
|
|
@@ -231,8 +785,8 @@ class Renderer {
|
|
|
231
785
|
|
|
232
786
|
}
|
|
233
787
|
|
|
234
|
-
this._nodes = new
|
|
235
|
-
this._animation = new Animation( this._nodes, this.info );
|
|
788
|
+
this._nodes = new NodeManager( this, backend );
|
|
789
|
+
this._animation = new Animation( this, this._nodes, this.info );
|
|
236
790
|
this._attributes = new Attributes( backend );
|
|
237
791
|
this._background = new Background( this, this._nodes );
|
|
238
792
|
this._geometries = new Geometries( this._attributes, this.info );
|
|
@@ -240,15 +794,22 @@ class Renderer {
|
|
|
240
794
|
this._pipelines = new Pipelines( backend, this._nodes );
|
|
241
795
|
this._bindings = new Bindings( backend, this._nodes, this._textures, this._attributes, this._pipelines, this.info );
|
|
242
796
|
this._objects = new RenderObjects( this, this._nodes, this._geometries, this._pipelines, this._bindings, this.info );
|
|
243
|
-
this._renderLists = new RenderLists();
|
|
797
|
+
this._renderLists = new RenderLists( this.lighting );
|
|
244
798
|
this._bundles = new RenderBundles();
|
|
245
|
-
this._renderContexts = new RenderContexts();
|
|
799
|
+
this._renderContexts = new RenderContexts( this );
|
|
246
800
|
|
|
247
801
|
//
|
|
248
802
|
|
|
803
|
+
this._animation.start();
|
|
249
804
|
this._initialized = true;
|
|
250
805
|
|
|
251
|
-
|
|
806
|
+
//
|
|
807
|
+
|
|
808
|
+
this._inspector.init();
|
|
809
|
+
|
|
810
|
+
//
|
|
811
|
+
|
|
812
|
+
resolve( this );
|
|
252
813
|
|
|
253
814
|
} );
|
|
254
815
|
|
|
@@ -256,14 +817,52 @@ class Renderer {
|
|
|
256
817
|
|
|
257
818
|
}
|
|
258
819
|
|
|
820
|
+
/**
|
|
821
|
+
* A reference to the canvas element the renderer is drawing to.
|
|
822
|
+
* This value of this property will automatically be created by
|
|
823
|
+
* the renderer.
|
|
824
|
+
*
|
|
825
|
+
* @type {HTMLCanvasElement|OffscreenCanvas}
|
|
826
|
+
*/
|
|
827
|
+
get domElement() {
|
|
828
|
+
|
|
829
|
+
return this._canvasTarget.domElement;
|
|
830
|
+
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* The coordinate system of the renderer. The value of this property
|
|
835
|
+
* depends on the selected backend. Either `THREE.WebGLCoordinateSystem` or
|
|
836
|
+
* `THREE.WebGPUCoordinateSystem`.
|
|
837
|
+
*
|
|
838
|
+
* @readonly
|
|
839
|
+
* @type {number}
|
|
840
|
+
*/
|
|
259
841
|
get coordinateSystem() {
|
|
260
842
|
|
|
261
843
|
return this.backend.coordinateSystem;
|
|
262
844
|
|
|
263
845
|
}
|
|
264
846
|
|
|
847
|
+
/**
|
|
848
|
+
* Compiles all materials in the given scene. This can be useful to avoid a
|
|
849
|
+
* phenomenon which is called "shader compilation stutter", which occurs when
|
|
850
|
+
* rendering an object with a new shader for the first time.
|
|
851
|
+
*
|
|
852
|
+
* If you want to add a 3D object to an existing scene, use the third optional
|
|
853
|
+
* parameter for applying the target scene. Note that the (target) scene's lighting
|
|
854
|
+
* and environment must be configured before calling this method.
|
|
855
|
+
*
|
|
856
|
+
* @async
|
|
857
|
+
* @param {Object3D} scene - The scene or 3D object to precompile.
|
|
858
|
+
* @param {Camera} camera - The camera that is used to render the scene.
|
|
859
|
+
* @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.
|
|
860
|
+
* @return {Promise} A Promise that resolves when the compile has been finished.
|
|
861
|
+
*/
|
|
265
862
|
async compileAsync( scene, camera, targetScene = null ) {
|
|
266
863
|
|
|
864
|
+
if ( this._isDeviceLost === true ) return;
|
|
865
|
+
|
|
267
866
|
if ( this._initialized === false ) await this.init();
|
|
268
867
|
|
|
269
868
|
// preserve render tree
|
|
@@ -273,6 +872,7 @@ class Renderer {
|
|
|
273
872
|
const previousRenderId = nodeFrame.renderId;
|
|
274
873
|
const previousRenderContext = this._currentRenderContext;
|
|
275
874
|
const previousRenderObjectFunction = this._currentRenderObjectFunction;
|
|
875
|
+
const previousHandleObjectFunction = this._handleObjectFunction;
|
|
276
876
|
const previousCompilationPromises = this._compilationPromises;
|
|
277
877
|
|
|
278
878
|
//
|
|
@@ -282,7 +882,7 @@ class Renderer {
|
|
|
282
882
|
if ( targetScene === null ) targetScene = scene;
|
|
283
883
|
|
|
284
884
|
const renderTarget = this._renderTarget;
|
|
285
|
-
const renderContext = this._renderContexts.get(
|
|
885
|
+
const renderContext = this._renderContexts.get( renderTarget, this._mrt );
|
|
286
886
|
const activeMipmapLevel = this._activeMipmapLevel;
|
|
287
887
|
|
|
288
888
|
const compilationPromises = [];
|
|
@@ -306,7 +906,7 @@ class Renderer {
|
|
|
306
906
|
renderContext.stencil = this.stencil;
|
|
307
907
|
|
|
308
908
|
if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext();
|
|
309
|
-
renderContext.clippingContext.updateGlobal(
|
|
909
|
+
renderContext.clippingContext.updateGlobal( sceneRef, camera );
|
|
310
910
|
|
|
311
911
|
//
|
|
312
912
|
|
|
@@ -317,7 +917,7 @@ class Renderer {
|
|
|
317
917
|
const renderList = this._renderLists.get( scene, camera );
|
|
318
918
|
renderList.begin();
|
|
319
919
|
|
|
320
|
-
this._projectObject( scene, camera, 0, renderList );
|
|
920
|
+
this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
|
|
321
921
|
|
|
322
922
|
// include lights from target scene
|
|
323
923
|
if ( targetScene !== scene ) {
|
|
@@ -356,20 +956,25 @@ class Renderer {
|
|
|
356
956
|
|
|
357
957
|
//
|
|
358
958
|
|
|
359
|
-
|
|
959
|
+
if ( targetScene !== scene ) {
|
|
960
|
+
|
|
961
|
+
this._background.update( targetScene, renderList, renderContext );
|
|
360
962
|
|
|
361
|
-
|
|
963
|
+
} else {
|
|
362
964
|
|
|
363
|
-
|
|
965
|
+
this._background.update( sceneRef, renderList, renderContext );
|
|
966
|
+
|
|
967
|
+
}
|
|
364
968
|
|
|
365
969
|
// process render lists
|
|
366
970
|
|
|
367
971
|
const opaqueObjects = renderList.opaque;
|
|
368
972
|
const transparentObjects = renderList.transparent;
|
|
973
|
+
const transparentDoublePassObjects = renderList.transparentDoublePass;
|
|
369
974
|
const lightsNode = renderList.lightsNode;
|
|
370
975
|
|
|
371
976
|
if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
|
|
372
|
-
if ( this.transparent === true && transparentObjects.length > 0 ) this.
|
|
977
|
+
if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode );
|
|
373
978
|
|
|
374
979
|
// restore render tree
|
|
375
980
|
|
|
@@ -377,26 +982,121 @@ class Renderer {
|
|
|
377
982
|
|
|
378
983
|
this._currentRenderContext = previousRenderContext;
|
|
379
984
|
this._currentRenderObjectFunction = previousRenderObjectFunction;
|
|
985
|
+
this._handleObjectFunction = previousHandleObjectFunction;
|
|
380
986
|
this._compilationPromises = previousCompilationPromises;
|
|
381
987
|
|
|
382
|
-
this._handleObjectFunction = this._renderObjectDirect;
|
|
383
|
-
|
|
384
988
|
// wait for all promises setup by backends awaiting compilation/linking/pipeline creation to complete
|
|
385
989
|
|
|
386
990
|
await Promise.all( compilationPromises );
|
|
387
991
|
|
|
388
992
|
}
|
|
389
993
|
|
|
994
|
+
/**
|
|
995
|
+
* Renders the scene in an async fashion.
|
|
996
|
+
*
|
|
997
|
+
* @async
|
|
998
|
+
* @deprecated
|
|
999
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
1000
|
+
* @param {Camera} camera - The camera.
|
|
1001
|
+
* @return {Promise} A Promise that resolves when the render has been finished.
|
|
1002
|
+
*/
|
|
390
1003
|
async renderAsync( scene, camera ) {
|
|
391
1004
|
|
|
392
|
-
|
|
1005
|
+
warnOnce( 'Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
|
|
1006
|
+
|
|
1007
|
+
await this.init();
|
|
1008
|
+
|
|
1009
|
+
this.render( scene, camera );
|
|
1010
|
+
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Can be used to synchronize CPU operations with GPU tasks. So when this method is called,
|
|
1015
|
+
* the CPU waits for the GPU to complete its operation (e.g. a compute task).
|
|
1016
|
+
*
|
|
1017
|
+
* @async
|
|
1018
|
+
* @deprecated
|
|
1019
|
+
* @return {Promise} A Promise that resolves when synchronization has been finished.
|
|
1020
|
+
*/
|
|
1021
|
+
async waitForGPU() {
|
|
1022
|
+
|
|
1023
|
+
error( 'Renderer: waitForGPU() has been removed. Read https://github.com/mrdoob/three.js/issues/32012 for more information.' );
|
|
1024
|
+
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
//
|
|
1028
|
+
|
|
1029
|
+
set inspector( value ) {
|
|
1030
|
+
|
|
1031
|
+
if ( this._inspector !== null ) {
|
|
1032
|
+
|
|
1033
|
+
this._inspector.setRenderer( null );
|
|
1034
|
+
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
this._inspector = value;
|
|
1038
|
+
this._inspector.setRenderer( this );
|
|
1039
|
+
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* The inspector instance. The inspector can be any class that extends from `InspectorBase`.
|
|
1044
|
+
*
|
|
1045
|
+
* @type {InspectorBase}
|
|
1046
|
+
*/
|
|
1047
|
+
get inspector() {
|
|
1048
|
+
|
|
1049
|
+
return this._inspector;
|
|
393
1050
|
|
|
394
|
-
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Enables or disables high precision for model-view and normal-view matrices.
|
|
1055
|
+
* When enabled, will use CPU 64-bit precision for higher precision instead of GPU 32-bit for higher performance.
|
|
1056
|
+
*
|
|
1057
|
+
* NOTE: 64-bit precision is not compatible with `InstancedMesh` and `SkinnedMesh`.
|
|
1058
|
+
*
|
|
1059
|
+
* @param {boolean} value - Whether to enable or disable high precision.
|
|
1060
|
+
* @type {boolean}
|
|
1061
|
+
*/
|
|
1062
|
+
set highPrecision( value ) {
|
|
1063
|
+
|
|
1064
|
+
const contextNodeData = this.contextNode.value;
|
|
1065
|
+
|
|
1066
|
+
if ( value === true ) {
|
|
1067
|
+
|
|
1068
|
+
contextNodeData.modelViewMatrix = highpModelViewMatrix;
|
|
1069
|
+
contextNodeData.modelNormalViewMatrix = highpModelNormalViewMatrix;
|
|
1070
|
+
|
|
1071
|
+
} else if ( this.highPrecision ) {
|
|
1072
|
+
|
|
1073
|
+
delete contextNodeData.modelViewMatrix;
|
|
1074
|
+
delete contextNodeData.modelNormalViewMatrix;
|
|
1075
|
+
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Returns whether high precision is enabled or not.
|
|
1082
|
+
*
|
|
1083
|
+
* @return {boolean} Whether high precision is enabled or not.
|
|
1084
|
+
* @type {boolean}
|
|
1085
|
+
*/
|
|
1086
|
+
get highPrecision() {
|
|
395
1087
|
|
|
396
|
-
|
|
1088
|
+
const contextNodeData = this.contextNode.value;
|
|
1089
|
+
|
|
1090
|
+
return contextNodeData.modelViewMatrix === highpModelViewMatrix && contextNodeData.modelNormalViewMatrix === highpModelNormalViewMatrix;
|
|
397
1091
|
|
|
398
1092
|
}
|
|
399
1093
|
|
|
1094
|
+
/**
|
|
1095
|
+
* Sets the given MRT configuration.
|
|
1096
|
+
*
|
|
1097
|
+
* @param {MRTNode} mrt - The MRT node to set.
|
|
1098
|
+
* @return {Renderer} A reference to this renderer.
|
|
1099
|
+
*/
|
|
400
1100
|
setMRT( mrt ) {
|
|
401
1101
|
|
|
402
1102
|
this._mrt = mrt;
|
|
@@ -405,12 +1105,72 @@ class Renderer {
|
|
|
405
1105
|
|
|
406
1106
|
}
|
|
407
1107
|
|
|
1108
|
+
/**
|
|
1109
|
+
* Returns the MRT configuration.
|
|
1110
|
+
*
|
|
1111
|
+
* @return {MRTNode} The MRT configuration.
|
|
1112
|
+
*/
|
|
408
1113
|
getMRT() {
|
|
409
1114
|
|
|
410
1115
|
return this._mrt;
|
|
411
1116
|
|
|
412
1117
|
}
|
|
413
1118
|
|
|
1119
|
+
/**
|
|
1120
|
+
* Returns the output buffer type.
|
|
1121
|
+
*
|
|
1122
|
+
* @return {number} The output buffer type.
|
|
1123
|
+
*/
|
|
1124
|
+
getOutputBufferType() {
|
|
1125
|
+
|
|
1126
|
+
return this._outputBufferType;
|
|
1127
|
+
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
* Returns the output buffer type.
|
|
1132
|
+
*
|
|
1133
|
+
* @deprecated since r182. Use `.getOutputBufferType()` instead.
|
|
1134
|
+
* @return {number} The output buffer type.
|
|
1135
|
+
*/
|
|
1136
|
+
getColorBufferType() { // @deprecated, r182
|
|
1137
|
+
|
|
1138
|
+
warnOnce( 'Renderer: ".getColorBufferType()" has been renamed to ".getOutputBufferType()".' );
|
|
1139
|
+
|
|
1140
|
+
return this.getOutputBufferType();
|
|
1141
|
+
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Default implementation of the device lost callback.
|
|
1146
|
+
*
|
|
1147
|
+
* @private
|
|
1148
|
+
* @param {Object} info - Information about the context lost.
|
|
1149
|
+
*/
|
|
1150
|
+
_onDeviceLost( info ) {
|
|
1151
|
+
|
|
1152
|
+
let errorMessage = `THREE.WebGPURenderer: ${info.api} Device Lost:\n\nMessage: ${info.message}`;
|
|
1153
|
+
|
|
1154
|
+
if ( info.reason ) {
|
|
1155
|
+
|
|
1156
|
+
errorMessage += `\nReason: ${info.reason}`;
|
|
1157
|
+
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
error( errorMessage );
|
|
1161
|
+
|
|
1162
|
+
this._isDeviceLost = true;
|
|
1163
|
+
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Renders the given render bundle.
|
|
1168
|
+
*
|
|
1169
|
+
* @private
|
|
1170
|
+
* @param {Object} bundle - Render bundle data.
|
|
1171
|
+
* @param {Scene} sceneRef - The scene the render bundle belongs to.
|
|
1172
|
+
* @param {LightsNode} lightsNode - The lights node.
|
|
1173
|
+
*/
|
|
414
1174
|
_renderBundle( bundle, sceneRef, lightsNode ) {
|
|
415
1175
|
|
|
416
1176
|
const { bundleGroup, camera, renderList } = bundle;
|
|
@@ -443,9 +1203,14 @@ class Renderer {
|
|
|
443
1203
|
|
|
444
1204
|
this._currentRenderBundle = renderBundle;
|
|
445
1205
|
|
|
446
|
-
const
|
|
1206
|
+
const {
|
|
1207
|
+
transparentDoublePass: transparentDoublePassObjects,
|
|
1208
|
+
transparent: transparentObjects,
|
|
1209
|
+
opaque: opaqueObjects
|
|
1210
|
+
} = renderList;
|
|
447
1211
|
|
|
448
|
-
if ( opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
|
|
1212
|
+
if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
|
|
1213
|
+
if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode );
|
|
449
1214
|
|
|
450
1215
|
this._currentRenderBundle = null;
|
|
451
1216
|
|
|
@@ -482,13 +1247,26 @@ class Renderer {
|
|
|
482
1247
|
|
|
483
1248
|
}
|
|
484
1249
|
|
|
1250
|
+
/**
|
|
1251
|
+
* Renders the scene or 3D object with the given camera. This method can only be called
|
|
1252
|
+
* if the renderer has been initialized. When using `render()` inside an animation loop,
|
|
1253
|
+
* it's guaranteed the renderer will be initialized. The animation loop must be defined
|
|
1254
|
+
* with {@link Renderer#setAnimationLoop} though.
|
|
1255
|
+
*
|
|
1256
|
+
* For all other use cases (like when using on-demand rendering), you must call
|
|
1257
|
+
* {@link Renderer#init} before rendering.
|
|
1258
|
+
*
|
|
1259
|
+
* The target of the method is the default framebuffer (meaning the canvas)
|
|
1260
|
+
* or alternatively a render target when specified via `setRenderTarget()`.
|
|
1261
|
+
*
|
|
1262
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
1263
|
+
* @param {Camera} camera - The camera to render the scene with.
|
|
1264
|
+
*/
|
|
485
1265
|
render( scene, camera ) {
|
|
486
1266
|
|
|
487
1267
|
if ( this._initialized === false ) {
|
|
488
1268
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return this.renderAsync( scene, camera );
|
|
1269
|
+
throw new Error( 'Renderer: .render() called before the backend is initialized. Use "await renderer.init();" before rendering.' );
|
|
492
1270
|
|
|
493
1271
|
}
|
|
494
1272
|
|
|
@@ -496,12 +1274,32 @@ class Renderer {
|
|
|
496
1274
|
|
|
497
1275
|
}
|
|
498
1276
|
|
|
1277
|
+
/**
|
|
1278
|
+
* Returns whether the renderer has been initialized or not.
|
|
1279
|
+
*
|
|
1280
|
+
* @readonly
|
|
1281
|
+
* @return {boolean} Whether the renderer has been initialized or not.
|
|
1282
|
+
*/
|
|
1283
|
+
get initialized() {
|
|
1284
|
+
|
|
1285
|
+
return this._initialized;
|
|
1286
|
+
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/**
|
|
1290
|
+
* Returns an internal render target which is used when computing the output tone mapping
|
|
1291
|
+
* and color space conversion. Unlike in `WebGLRenderer`, this is done in a separate render
|
|
1292
|
+
* pass and not inline to achieve more correct results.
|
|
1293
|
+
*
|
|
1294
|
+
* @private
|
|
1295
|
+
* @return {?RenderTarget} The render target. The method returns `null` if no output conversion should be applied.
|
|
1296
|
+
*/
|
|
499
1297
|
_getFrameBufferTarget() {
|
|
500
1298
|
|
|
501
1299
|
const { currentToneMapping, currentColorSpace } = this;
|
|
502
1300
|
|
|
503
1301
|
const useToneMapping = currentToneMapping !== NoToneMapping;
|
|
504
|
-
const useColorSpace = currentColorSpace !==
|
|
1302
|
+
const useColorSpace = currentColorSpace !== ColorManagement.workingColorSpace;
|
|
505
1303
|
|
|
506
1304
|
if ( useToneMapping === false && useColorSpace === false ) return null;
|
|
507
1305
|
|
|
@@ -515,9 +1313,9 @@ class Renderer {
|
|
|
515
1313
|
frameBufferTarget = new RenderTarget( width, height, {
|
|
516
1314
|
depthBuffer: depth,
|
|
517
1315
|
stencilBuffer: stencil,
|
|
518
|
-
type:
|
|
1316
|
+
type: this._outputBufferType,
|
|
519
1317
|
format: RGBAFormat,
|
|
520
|
-
colorSpace:
|
|
1318
|
+
colorSpace: ColorManagement.workingColorSpace,
|
|
521
1319
|
generateMipmaps: false,
|
|
522
1320
|
minFilter: LinearFilter,
|
|
523
1321
|
magFilter: LinearFilter,
|
|
@@ -530,21 +1328,50 @@ class Renderer {
|
|
|
530
1328
|
|
|
531
1329
|
}
|
|
532
1330
|
|
|
1331
|
+
const outputRenderTarget = this.getOutputRenderTarget();
|
|
1332
|
+
|
|
533
1333
|
frameBufferTarget.depthBuffer = depth;
|
|
534
1334
|
frameBufferTarget.stencilBuffer = stencil;
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
1335
|
+
if ( outputRenderTarget !== null ) {
|
|
1336
|
+
|
|
1337
|
+
frameBufferTarget.setSize( outputRenderTarget.width, outputRenderTarget.height, outputRenderTarget.depth );
|
|
1338
|
+
|
|
1339
|
+
} else {
|
|
1340
|
+
|
|
1341
|
+
frameBufferTarget.setSize( width, height, 1 );
|
|
1342
|
+
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
const canvasTarget = this._canvasTarget;
|
|
1346
|
+
|
|
1347
|
+
frameBufferTarget.viewport.copy( canvasTarget._viewport );
|
|
1348
|
+
frameBufferTarget.scissor.copy( canvasTarget._scissor );
|
|
1349
|
+
frameBufferTarget.viewport.multiplyScalar( canvasTarget._pixelRatio );
|
|
1350
|
+
frameBufferTarget.scissor.multiplyScalar( canvasTarget._pixelRatio );
|
|
1351
|
+
frameBufferTarget.scissorTest = canvasTarget._scissorTest;
|
|
1352
|
+
frameBufferTarget.multiview = outputRenderTarget !== null ? outputRenderTarget.multiview : false;
|
|
1353
|
+
frameBufferTarget.resolveDepthBuffer = outputRenderTarget !== null ? outputRenderTarget.resolveDepthBuffer : true;
|
|
1354
|
+
frameBufferTarget._autoAllocateDepthBuffer = outputRenderTarget !== null ? outputRenderTarget._autoAllocateDepthBuffer : false;
|
|
541
1355
|
|
|
542
1356
|
return frameBufferTarget;
|
|
543
1357
|
|
|
544
1358
|
}
|
|
545
1359
|
|
|
1360
|
+
/**
|
|
1361
|
+
* Renders the scene or 3D object with the given camera.
|
|
1362
|
+
*
|
|
1363
|
+
* @private
|
|
1364
|
+
* @param {Object3D} scene - The scene or 3D object to render.
|
|
1365
|
+
* @param {Camera} camera - The camera to render the scene with.
|
|
1366
|
+
* @param {boolean} [useFrameBufferTarget=true] - Whether to use a framebuffer target or not.
|
|
1367
|
+
* @return {RenderContext} The current render context.
|
|
1368
|
+
*/
|
|
546
1369
|
_renderScene( scene, camera, useFrameBufferTarget = true ) {
|
|
547
1370
|
|
|
1371
|
+
if ( this._isDeviceLost === true ) return;
|
|
1372
|
+
|
|
1373
|
+
//
|
|
1374
|
+
|
|
548
1375
|
const frameBufferTarget = useFrameBufferTarget ? this._getFrameBufferTarget() : null;
|
|
549
1376
|
|
|
550
1377
|
// preserve render tree
|
|
@@ -554,12 +1381,15 @@ class Renderer {
|
|
|
554
1381
|
const previousRenderId = nodeFrame.renderId;
|
|
555
1382
|
const previousRenderContext = this._currentRenderContext;
|
|
556
1383
|
const previousRenderObjectFunction = this._currentRenderObjectFunction;
|
|
1384
|
+
const previousHandleObjectFunction = this._handleObjectFunction;
|
|
557
1385
|
|
|
558
1386
|
//
|
|
559
1387
|
|
|
1388
|
+
this._callDepth ++;
|
|
1389
|
+
|
|
560
1390
|
const sceneRef = ( scene.isScene === true ) ? scene : _scene;
|
|
561
1391
|
|
|
562
|
-
const outputRenderTarget = this._renderTarget;
|
|
1392
|
+
const outputRenderTarget = this._renderTarget || this._outputRenderTarget;
|
|
563
1393
|
|
|
564
1394
|
const activeCubeFace = this._activeCubeFace;
|
|
565
1395
|
const activeMipmapLevel = this._activeMipmapLevel;
|
|
@@ -582,10 +1412,11 @@ class Renderer {
|
|
|
582
1412
|
|
|
583
1413
|
//
|
|
584
1414
|
|
|
585
|
-
const renderContext = this._renderContexts.get(
|
|
1415
|
+
const renderContext = this._renderContexts.get( renderTarget, this._mrt, this._callDepth );
|
|
586
1416
|
|
|
587
1417
|
this._currentRenderContext = renderContext;
|
|
588
1418
|
this._currentRenderObjectFunction = this._renderObjectFunction || this.renderObject;
|
|
1419
|
+
this._handleObjectFunction = this._renderObjectDirect;
|
|
589
1420
|
|
|
590
1421
|
//
|
|
591
1422
|
|
|
@@ -597,13 +1428,78 @@ class Renderer {
|
|
|
597
1428
|
|
|
598
1429
|
//
|
|
599
1430
|
|
|
600
|
-
|
|
1431
|
+
this.backend.updateTimeStampUID( renderContext );
|
|
1432
|
+
|
|
1433
|
+
this.inspector.beginRender( this.backend.getTimestampUID( renderContext ), scene, camera, renderTarget );
|
|
1434
|
+
|
|
1435
|
+
//
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
const xr = this.xr;
|
|
1439
|
+
|
|
1440
|
+
if ( xr.isPresenting === false ) {
|
|
1441
|
+
|
|
1442
|
+
let projectionMatrixNeedsUpdate = false;
|
|
1443
|
+
|
|
1444
|
+
// reversed depth
|
|
1445
|
+
|
|
1446
|
+
if ( this.reversedDepthBuffer === true && camera.reversedDepth !== true ) {
|
|
1447
|
+
|
|
1448
|
+
camera._reversedDepth = true;
|
|
1449
|
+
|
|
1450
|
+
if ( camera.isArrayCamera ) {
|
|
1451
|
+
|
|
1452
|
+
for ( const subCamera of camera.cameras ) {
|
|
1453
|
+
|
|
1454
|
+
subCamera._reversedDepth = true;
|
|
1455
|
+
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
projectionMatrixNeedsUpdate = true;
|
|
1461
|
+
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// WebGPU/WebGL coordinate system
|
|
1465
|
+
|
|
1466
|
+
const coordinateSystem = this.coordinateSystem;
|
|
1467
|
+
|
|
1468
|
+
if ( camera.coordinateSystem !== coordinateSystem ) {
|
|
1469
|
+
|
|
1470
|
+
camera.coordinateSystem = coordinateSystem;
|
|
1471
|
+
|
|
1472
|
+
if ( camera.isArrayCamera ) {
|
|
1473
|
+
|
|
1474
|
+
for ( const subCamera of camera.cameras ) {
|
|
1475
|
+
|
|
1476
|
+
subCamera.coordinateSystem = coordinateSystem;
|
|
1477
|
+
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
projectionMatrixNeedsUpdate = true;
|
|
1483
|
+
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
// camera update
|
|
1487
|
+
|
|
1488
|
+
if ( projectionMatrixNeedsUpdate === true ) {
|
|
1489
|
+
|
|
1490
|
+
camera.updateProjectionMatrix();
|
|
601
1491
|
|
|
602
|
-
|
|
1492
|
+
if ( camera.isArrayCamera ) {
|
|
603
1493
|
|
|
604
|
-
|
|
1494
|
+
for ( const subCamera of camera.cameras ) {
|
|
605
1495
|
|
|
606
|
-
|
|
1496
|
+
subCamera.updateProjectionMatrix();
|
|
1497
|
+
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
}
|
|
607
1503
|
|
|
608
1504
|
}
|
|
609
1505
|
|
|
@@ -613,11 +1509,20 @@ class Renderer {
|
|
|
613
1509
|
|
|
614
1510
|
if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
|
|
615
1511
|
|
|
1512
|
+
if ( xr.enabled === true && xr.isPresenting === true ) {
|
|
1513
|
+
|
|
1514
|
+
if ( xr.cameraAutoUpdate === true ) xr.updateCamera( camera );
|
|
1515
|
+
camera = xr.getCamera(); // use XR camera for rendering
|
|
1516
|
+
|
|
1517
|
+
}
|
|
1518
|
+
|
|
616
1519
|
//
|
|
617
1520
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
let
|
|
1521
|
+
const canvasTarget = this._canvasTarget;
|
|
1522
|
+
|
|
1523
|
+
let viewport = canvasTarget._viewport;
|
|
1524
|
+
let scissor = canvasTarget._scissor;
|
|
1525
|
+
let pixelRatio = canvasTarget._pixelRatio;
|
|
621
1526
|
|
|
622
1527
|
if ( renderTarget !== null ) {
|
|
623
1528
|
|
|
@@ -642,12 +1547,12 @@ class Renderer {
|
|
|
642
1547
|
renderContext.viewport = renderContext.viewportValue.equals( _screen ) === false;
|
|
643
1548
|
|
|
644
1549
|
renderContext.scissorValue.copy( scissor ).multiplyScalar( pixelRatio ).floor();
|
|
645
|
-
renderContext.scissor =
|
|
1550
|
+
renderContext.scissor = canvasTarget._scissorTest && renderContext.scissorValue.equals( _screen ) === false;
|
|
646
1551
|
renderContext.scissorValue.width >>= activeMipmapLevel;
|
|
647
1552
|
renderContext.scissorValue.height >>= activeMipmapLevel;
|
|
648
1553
|
|
|
649
1554
|
if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext();
|
|
650
|
-
renderContext.clippingContext.updateGlobal(
|
|
1555
|
+
renderContext.clippingContext.updateGlobal( sceneRef, camera );
|
|
651
1556
|
|
|
652
1557
|
//
|
|
653
1558
|
|
|
@@ -655,13 +1560,19 @@ class Renderer {
|
|
|
655
1560
|
|
|
656
1561
|
//
|
|
657
1562
|
|
|
658
|
-
|
|
659
|
-
|
|
1563
|
+
const frustum = camera.isArrayCamera ? _frustumArray : _frustum;
|
|
1564
|
+
|
|
1565
|
+
if ( ! camera.isArrayCamera ) {
|
|
1566
|
+
|
|
1567
|
+
_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
|
|
1568
|
+
frustum.setFromProjectionMatrix( _projScreenMatrix, camera.coordinateSystem, camera.reversedDepth );
|
|
1569
|
+
|
|
1570
|
+
}
|
|
660
1571
|
|
|
661
1572
|
const renderList = this._renderLists.get( scene, camera );
|
|
662
1573
|
renderList.begin();
|
|
663
1574
|
|
|
664
|
-
this._projectObject( scene, camera, 0, renderList );
|
|
1575
|
+
this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
|
|
665
1576
|
|
|
666
1577
|
renderList.finish();
|
|
667
1578
|
|
|
@@ -691,8 +1602,8 @@ class Renderer {
|
|
|
691
1602
|
|
|
692
1603
|
renderContext.textures = null;
|
|
693
1604
|
renderContext.depthTexture = null;
|
|
694
|
-
renderContext.width =
|
|
695
|
-
renderContext.height =
|
|
1605
|
+
renderContext.width = _drawingBufferSize.width;
|
|
1606
|
+
renderContext.height = _drawingBufferSize.height;
|
|
696
1607
|
renderContext.depth = this.depth;
|
|
697
1608
|
renderContext.stencil = this.stencil;
|
|
698
1609
|
|
|
@@ -706,7 +1617,19 @@ class Renderer {
|
|
|
706
1617
|
|
|
707
1618
|
//
|
|
708
1619
|
|
|
709
|
-
|
|
1620
|
+
renderContext.scissorValue.max( _vector4.set( 0, 0, 0, 0 ) );
|
|
1621
|
+
|
|
1622
|
+
if ( renderContext.scissorValue.x + renderContext.scissorValue.width > renderContext.width ) {
|
|
1623
|
+
|
|
1624
|
+
renderContext.scissorValue.width = Math.max( renderContext.width - renderContext.scissorValue.x, 0 );
|
|
1625
|
+
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
if ( renderContext.scissorValue.y + renderContext.scissorValue.height > renderContext.height ) {
|
|
1629
|
+
|
|
1630
|
+
renderContext.scissorValue.height = Math.max( renderContext.height - renderContext.scissorValue.y, 0 );
|
|
1631
|
+
|
|
1632
|
+
}
|
|
710
1633
|
|
|
711
1634
|
//
|
|
712
1635
|
|
|
@@ -714,6 +1637,7 @@ class Renderer {
|
|
|
714
1637
|
|
|
715
1638
|
//
|
|
716
1639
|
|
|
1640
|
+
renderContext.camera = camera;
|
|
717
1641
|
this.backend.beginRender( renderContext );
|
|
718
1642
|
|
|
719
1643
|
// process render lists
|
|
@@ -721,13 +1645,14 @@ class Renderer {
|
|
|
721
1645
|
const {
|
|
722
1646
|
bundles,
|
|
723
1647
|
lightsNode,
|
|
1648
|
+
transparentDoublePass: transparentDoublePassObjects,
|
|
724
1649
|
transparent: transparentObjects,
|
|
725
1650
|
opaque: opaqueObjects
|
|
726
1651
|
} = renderList;
|
|
727
1652
|
|
|
728
1653
|
if ( bundles.length > 0 ) this._renderBundles( bundles, sceneRef, lightsNode );
|
|
729
1654
|
if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
|
|
730
|
-
if ( this.transparent === true && transparentObjects.length > 0 ) this.
|
|
1655
|
+
if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode );
|
|
731
1656
|
|
|
732
1657
|
// finish render pass
|
|
733
1658
|
|
|
@@ -739,23 +1664,17 @@ class Renderer {
|
|
|
739
1664
|
|
|
740
1665
|
this._currentRenderContext = previousRenderContext;
|
|
741
1666
|
this._currentRenderObjectFunction = previousRenderObjectFunction;
|
|
1667
|
+
this._handleObjectFunction = previousHandleObjectFunction;
|
|
742
1668
|
|
|
743
1669
|
//
|
|
744
1670
|
|
|
1671
|
+
this._callDepth --;
|
|
1672
|
+
|
|
745
1673
|
if ( frameBufferTarget !== null ) {
|
|
746
1674
|
|
|
747
1675
|
this.setRenderTarget( outputRenderTarget, activeCubeFace, activeMipmapLevel );
|
|
748
1676
|
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
if ( this._nodes.hasOutputChange( renderTarget.texture ) ) {
|
|
752
|
-
|
|
753
|
-
quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture );
|
|
754
|
-
quad.material.needsUpdate = true;
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
this._renderScene( quad, quad.camera, false );
|
|
1677
|
+
this._renderOutput( renderTarget );
|
|
759
1678
|
|
|
760
1679
|
}
|
|
761
1680
|
|
|
@@ -765,28 +1684,100 @@ class Renderer {
|
|
|
765
1684
|
|
|
766
1685
|
//
|
|
767
1686
|
|
|
1687
|
+
this.inspector.finishRender( this.backend.getTimestampUID( renderContext ) );
|
|
1688
|
+
|
|
1689
|
+
//
|
|
1690
|
+
|
|
768
1691
|
return renderContext;
|
|
769
1692
|
|
|
770
1693
|
}
|
|
771
1694
|
|
|
1695
|
+
_setXRLayerSize( width, height ) {
|
|
1696
|
+
|
|
1697
|
+
// TODO: Find a better solution to resize the canvas when in XR.
|
|
1698
|
+
|
|
1699
|
+
this._canvasTarget._width = width;
|
|
1700
|
+
this._canvasTarget._height = height;
|
|
1701
|
+
|
|
1702
|
+
this.setViewport( 0, 0, width, height );
|
|
1703
|
+
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
/**
|
|
1707
|
+
* The output pass performs tone mapping and color space conversion.
|
|
1708
|
+
*
|
|
1709
|
+
* @private
|
|
1710
|
+
* @param {RenderTarget} renderTarget - The current render target.
|
|
1711
|
+
*/
|
|
1712
|
+
_renderOutput( renderTarget ) {
|
|
1713
|
+
|
|
1714
|
+
const quad = this._quad;
|
|
1715
|
+
|
|
1716
|
+
if ( this._nodes.hasOutputChange( renderTarget.texture ) ) {
|
|
1717
|
+
|
|
1718
|
+
quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture );
|
|
1719
|
+
quad.material.needsUpdate = true;
|
|
1720
|
+
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
// a clear operation clears the intermediate renderTarget texture, but should not update the screen canvas.
|
|
1724
|
+
|
|
1725
|
+
const currentAutoClear = this.autoClear;
|
|
1726
|
+
const currentXR = this.xr.enabled;
|
|
1727
|
+
|
|
1728
|
+
this.autoClear = false;
|
|
1729
|
+
this.xr.enabled = false;
|
|
1730
|
+
|
|
1731
|
+
this._renderScene( quad, quad.camera, false );
|
|
1732
|
+
|
|
1733
|
+
this.autoClear = currentAutoClear;
|
|
1734
|
+
this.xr.enabled = currentXR;
|
|
1735
|
+
|
|
1736
|
+
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
/**
|
|
1740
|
+
* Returns the maximum available anisotropy for texture filtering.
|
|
1741
|
+
*
|
|
1742
|
+
* @return {number} The maximum available anisotropy.
|
|
1743
|
+
*/
|
|
772
1744
|
getMaxAnisotropy() {
|
|
773
1745
|
|
|
774
1746
|
return this.backend.getMaxAnisotropy();
|
|
775
1747
|
|
|
776
1748
|
}
|
|
777
1749
|
|
|
1750
|
+
/**
|
|
1751
|
+
* Returns the active cube face.
|
|
1752
|
+
*
|
|
1753
|
+
* @return {number} The active cube face.
|
|
1754
|
+
*/
|
|
778
1755
|
getActiveCubeFace() {
|
|
779
1756
|
|
|
780
1757
|
return this._activeCubeFace;
|
|
781
1758
|
|
|
782
1759
|
}
|
|
783
1760
|
|
|
1761
|
+
/**
|
|
1762
|
+
* Returns the active mipmap level.
|
|
1763
|
+
*
|
|
1764
|
+
* @return {number} The active mipmap level.
|
|
1765
|
+
*/
|
|
784
1766
|
getActiveMipmapLevel() {
|
|
785
1767
|
|
|
786
1768
|
return this._activeMipmapLevel;
|
|
787
1769
|
|
|
788
1770
|
}
|
|
789
1771
|
|
|
1772
|
+
/**
|
|
1773
|
+
* Applications are advised to always define the animation loop
|
|
1774
|
+
* with this method and not manually with `requestAnimationFrame()`
|
|
1775
|
+
* for best compatibility.
|
|
1776
|
+
*
|
|
1777
|
+
* @async
|
|
1778
|
+
* @param {?onAnimationCallback} callback - The application's animation loop.
|
|
1779
|
+
* @return {Promise} A Promise that resolves when the set has been executed.
|
|
1780
|
+
*/
|
|
790
1781
|
async setAnimationLoop( callback ) {
|
|
791
1782
|
|
|
792
1783
|
if ( this._initialized === false ) await this.init();
|
|
@@ -795,210 +1786,330 @@ class Renderer {
|
|
|
795
1786
|
|
|
796
1787
|
}
|
|
797
1788
|
|
|
1789
|
+
/**
|
|
1790
|
+
* Returns the current animation loop callback.
|
|
1791
|
+
*
|
|
1792
|
+
* @return {?Function} The current animation loop callback.
|
|
1793
|
+
*/
|
|
1794
|
+
getAnimationLoop() {
|
|
1795
|
+
|
|
1796
|
+
return this._animation.getAnimationLoop();
|
|
1797
|
+
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
/**
|
|
1801
|
+
* Can be used to transfer buffer data from a storage buffer attribute
|
|
1802
|
+
* from the GPU to the CPU in context of compute shaders.
|
|
1803
|
+
*
|
|
1804
|
+
* @async
|
|
1805
|
+
* @param {StorageBufferAttribute} attribute - The storage buffer attribute.
|
|
1806
|
+
* @return {Promise<ArrayBuffer>} A promise that resolves with the buffer data when the data are ready.
|
|
1807
|
+
*/
|
|
798
1808
|
async getArrayBufferAsync( attribute ) {
|
|
799
1809
|
|
|
800
1810
|
return await this.backend.getArrayBufferAsync( attribute );
|
|
801
1811
|
|
|
802
1812
|
}
|
|
803
1813
|
|
|
1814
|
+
/**
|
|
1815
|
+
* Returns the rendering context.
|
|
1816
|
+
*
|
|
1817
|
+
* @return {GPUCanvasContext|WebGL2RenderingContext} The rendering context.
|
|
1818
|
+
*/
|
|
804
1819
|
getContext() {
|
|
805
1820
|
|
|
806
1821
|
return this.backend.getContext();
|
|
807
1822
|
|
|
808
1823
|
}
|
|
809
1824
|
|
|
1825
|
+
/**
|
|
1826
|
+
* Returns the pixel ratio.
|
|
1827
|
+
*
|
|
1828
|
+
* @return {number} The pixel ratio.
|
|
1829
|
+
*/
|
|
810
1830
|
getPixelRatio() {
|
|
811
1831
|
|
|
812
|
-
return this.
|
|
1832
|
+
return this._canvasTarget.getPixelRatio();
|
|
813
1833
|
|
|
814
1834
|
}
|
|
815
1835
|
|
|
1836
|
+
/**
|
|
1837
|
+
* Returns the drawing buffer size in physical pixels. This method honors the pixel ratio.
|
|
1838
|
+
*
|
|
1839
|
+
* @param {Vector2} target - The method writes the result in this target object.
|
|
1840
|
+
* @return {Vector2} The drawing buffer size.
|
|
1841
|
+
*/
|
|
816
1842
|
getDrawingBufferSize( target ) {
|
|
817
1843
|
|
|
818
|
-
return
|
|
1844
|
+
return this._canvasTarget.getDrawingBufferSize( target );
|
|
819
1845
|
|
|
820
1846
|
}
|
|
821
1847
|
|
|
1848
|
+
/**
|
|
1849
|
+
* Returns the renderer's size in logical pixels. This method does not honor the pixel ratio.
|
|
1850
|
+
*
|
|
1851
|
+
* @param {Vector2} target - The method writes the result in this target object.
|
|
1852
|
+
* @return {Vector2} The renderer's size in logical pixels.
|
|
1853
|
+
*/
|
|
822
1854
|
getSize( target ) {
|
|
823
1855
|
|
|
824
|
-
return
|
|
1856
|
+
return this._canvasTarget.getSize( target );
|
|
825
1857
|
|
|
826
1858
|
}
|
|
827
1859
|
|
|
1860
|
+
/**
|
|
1861
|
+
* Sets the given pixel ratio and resizes the canvas if necessary.
|
|
1862
|
+
*
|
|
1863
|
+
* @param {number} [value=1] - The pixel ratio.
|
|
1864
|
+
*/
|
|
828
1865
|
setPixelRatio( value = 1 ) {
|
|
829
1866
|
|
|
830
|
-
this.
|
|
831
|
-
|
|
832
|
-
this.setSize( this._width, this._height, false );
|
|
1867
|
+
this._canvasTarget.setPixelRatio( value );
|
|
833
1868
|
|
|
834
1869
|
}
|
|
835
1870
|
|
|
1871
|
+
/**
|
|
1872
|
+
* This method allows to define the drawing buffer size by specifying
|
|
1873
|
+
* width, height and pixel ratio all at once. The size of the drawing
|
|
1874
|
+
* buffer is computed with this formula:
|
|
1875
|
+
* ```js
|
|
1876
|
+
* size.x = width * pixelRatio;
|
|
1877
|
+
* size.y = height * pixelRatio;
|
|
1878
|
+
* ```
|
|
1879
|
+
*
|
|
1880
|
+
* @param {number} width - The width in logical pixels.
|
|
1881
|
+
* @param {number} height - The height in logical pixels.
|
|
1882
|
+
* @param {number} pixelRatio - The pixel ratio.
|
|
1883
|
+
*/
|
|
836
1884
|
setDrawingBufferSize( width, height, pixelRatio ) {
|
|
837
1885
|
|
|
838
|
-
|
|
839
|
-
this.
|
|
840
|
-
|
|
841
|
-
this._pixelRatio = pixelRatio;
|
|
842
|
-
|
|
843
|
-
this.domElement.width = Math.floor( width * pixelRatio );
|
|
844
|
-
this.domElement.height = Math.floor( height * pixelRatio );
|
|
1886
|
+
// Renderer can't be resized while presenting in XR.
|
|
1887
|
+
if ( this.xr && this.xr.isPresenting ) return;
|
|
845
1888
|
|
|
846
|
-
this.
|
|
847
|
-
|
|
848
|
-
if ( this._initialized ) this.backend.updateSize();
|
|
1889
|
+
this._canvasTarget.setDrawingBufferSize( width, height, pixelRatio );
|
|
849
1890
|
|
|
850
1891
|
}
|
|
851
1892
|
|
|
1893
|
+
/**
|
|
1894
|
+
* Sets the size of the renderer.
|
|
1895
|
+
*
|
|
1896
|
+
* @param {number} width - The width in logical pixels.
|
|
1897
|
+
* @param {number} height - The height in logical pixels.
|
|
1898
|
+
* @param {boolean} [updateStyle=true] - Whether to update the `style` attribute of the canvas or not.
|
|
1899
|
+
*/
|
|
852
1900
|
setSize( width, height, updateStyle = true ) {
|
|
853
1901
|
|
|
854
|
-
|
|
855
|
-
this.
|
|
856
|
-
|
|
857
|
-
this.domElement.width = Math.floor( width * this._pixelRatio );
|
|
858
|
-
this.domElement.height = Math.floor( height * this._pixelRatio );
|
|
1902
|
+
// Renderer can't be resized while presenting in XR.
|
|
1903
|
+
if ( this.xr && this.xr.isPresenting ) return;
|
|
859
1904
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
this.domElement.style.width = width + 'px';
|
|
863
|
-
this.domElement.style.height = height + 'px';
|
|
864
|
-
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
this.setViewport( 0, 0, width, height );
|
|
868
|
-
|
|
869
|
-
if ( this._initialized ) this.backend.updateSize();
|
|
1905
|
+
this._canvasTarget.setSize( width, height, updateStyle );
|
|
870
1906
|
|
|
871
1907
|
}
|
|
872
1908
|
|
|
1909
|
+
/**
|
|
1910
|
+
* Defines a manual sort function for the opaque render list.
|
|
1911
|
+
* Pass `null` to use the default sort.
|
|
1912
|
+
*
|
|
1913
|
+
* @param {Function} method - The sort function.
|
|
1914
|
+
*/
|
|
873
1915
|
setOpaqueSort( method ) {
|
|
874
1916
|
|
|
875
1917
|
this._opaqueSort = method;
|
|
876
1918
|
|
|
877
1919
|
}
|
|
878
1920
|
|
|
1921
|
+
/**
|
|
1922
|
+
* Defines a manual sort function for the transparent render list.
|
|
1923
|
+
* Pass `null` to use the default sort.
|
|
1924
|
+
*
|
|
1925
|
+
* @param {Function} method - The sort function.
|
|
1926
|
+
*/
|
|
879
1927
|
setTransparentSort( method ) {
|
|
880
1928
|
|
|
881
1929
|
this._transparentSort = method;
|
|
882
1930
|
|
|
883
1931
|
}
|
|
884
1932
|
|
|
1933
|
+
/**
|
|
1934
|
+
* Returns the scissor rectangle.
|
|
1935
|
+
*
|
|
1936
|
+
* @param {Vector4} target - The method writes the result in this target object.
|
|
1937
|
+
* @return {Vector4} The scissor rectangle.
|
|
1938
|
+
*/
|
|
885
1939
|
getScissor( target ) {
|
|
886
1940
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
target.x = scissor.x;
|
|
890
|
-
target.y = scissor.y;
|
|
891
|
-
target.width = scissor.width;
|
|
892
|
-
target.height = scissor.height;
|
|
893
|
-
|
|
894
|
-
return target;
|
|
1941
|
+
return this._canvasTarget.getScissor( target );
|
|
895
1942
|
|
|
896
1943
|
}
|
|
897
1944
|
|
|
1945
|
+
/**
|
|
1946
|
+
* Defines the scissor rectangle.
|
|
1947
|
+
*
|
|
1948
|
+
* @param {number | Vector4} x - The horizontal coordinate for the upper left corner of the box in logical pixel unit.
|
|
1949
|
+
* Instead of passing four arguments, the method also works with a single four-dimensional vector.
|
|
1950
|
+
* @param {number} y - The vertical coordinate for the upper left corner of the box in logical pixel unit.
|
|
1951
|
+
* @param {number} width - The width of the scissor box in logical pixel unit.
|
|
1952
|
+
* @param {number} height - The height of the scissor box in logical pixel unit.
|
|
1953
|
+
*/
|
|
898
1954
|
setScissor( x, y, width, height ) {
|
|
899
1955
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if ( x.isVector4 ) {
|
|
903
|
-
|
|
904
|
-
scissor.copy( x );
|
|
905
|
-
|
|
906
|
-
} else {
|
|
907
|
-
|
|
908
|
-
scissor.set( x, y, width, height );
|
|
909
|
-
|
|
910
|
-
}
|
|
1956
|
+
this._canvasTarget.setScissor( x, y, width, height );
|
|
911
1957
|
|
|
912
1958
|
}
|
|
913
1959
|
|
|
1960
|
+
/**
|
|
1961
|
+
* Returns the scissor test value.
|
|
1962
|
+
*
|
|
1963
|
+
* @return {boolean} Whether the scissor test should be enabled or not.
|
|
1964
|
+
*/
|
|
914
1965
|
getScissorTest() {
|
|
915
1966
|
|
|
916
|
-
return this.
|
|
1967
|
+
return this._canvasTarget.getScissorTest();
|
|
917
1968
|
|
|
918
1969
|
}
|
|
919
1970
|
|
|
1971
|
+
/**
|
|
1972
|
+
* Defines the scissor test.
|
|
1973
|
+
*
|
|
1974
|
+
* @param {boolean} boolean - Whether the scissor test should be enabled or not.
|
|
1975
|
+
*/
|
|
920
1976
|
setScissorTest( boolean ) {
|
|
921
1977
|
|
|
922
|
-
this.
|
|
1978
|
+
this._canvasTarget.setScissorTest( boolean );
|
|
1979
|
+
|
|
1980
|
+
// TODO: Move it to CanvasTarget event listener.
|
|
923
1981
|
|
|
924
1982
|
this.backend.setScissorTest( boolean );
|
|
925
1983
|
|
|
926
1984
|
}
|
|
927
1985
|
|
|
1986
|
+
/**
|
|
1987
|
+
* Returns the viewport definition.
|
|
1988
|
+
*
|
|
1989
|
+
* @param {Vector4} target - The method writes the result in this target object.
|
|
1990
|
+
* @return {Vector4} The viewport definition.
|
|
1991
|
+
*/
|
|
928
1992
|
getViewport( target ) {
|
|
929
1993
|
|
|
930
|
-
return
|
|
1994
|
+
return this._canvasTarget.getViewport( target );
|
|
931
1995
|
|
|
932
1996
|
}
|
|
933
1997
|
|
|
1998
|
+
/**
|
|
1999
|
+
* Defines the viewport.
|
|
2000
|
+
*
|
|
2001
|
+
* @param {number | Vector4} x - The horizontal coordinate for the upper left corner of the viewport origin in logical pixel unit.
|
|
2002
|
+
* @param {number} y - The vertical coordinate for the upper left corner of the viewport origin in logical pixel unit.
|
|
2003
|
+
* @param {number} width - The width of the viewport in logical pixel unit.
|
|
2004
|
+
* @param {number} height - The height of the viewport in logical pixel unit.
|
|
2005
|
+
* @param {number} minDepth - The minimum depth value of the viewport. WebGPU only.
|
|
2006
|
+
* @param {number} maxDepth - The maximum depth value of the viewport. WebGPU only.
|
|
2007
|
+
*/
|
|
934
2008
|
setViewport( x, y, width, height, minDepth = 0, maxDepth = 1 ) {
|
|
935
2009
|
|
|
936
|
-
|
|
2010
|
+
this._canvasTarget.setViewport( x, y, width, height, minDepth, maxDepth );
|
|
937
2011
|
|
|
938
|
-
|
|
2012
|
+
}
|
|
939
2013
|
|
|
940
|
-
|
|
2014
|
+
/**
|
|
2015
|
+
* Returns the clear color.
|
|
2016
|
+
*
|
|
2017
|
+
* @param {Color} target - The method writes the result in this target object.
|
|
2018
|
+
* @return {Color} The clear color.
|
|
2019
|
+
*/
|
|
2020
|
+
getClearColor( target ) {
|
|
941
2021
|
|
|
942
|
-
|
|
2022
|
+
return target.copy( this._clearColor );
|
|
943
2023
|
|
|
944
|
-
|
|
2024
|
+
}
|
|
945
2025
|
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
getClearColor( target ) {
|
|
954
|
-
|
|
955
|
-
return target.copy( this._clearColor );
|
|
956
|
-
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
setClearColor( color, alpha = 1 ) {
|
|
2026
|
+
/**
|
|
2027
|
+
* Defines the clear color and optionally the clear alpha.
|
|
2028
|
+
*
|
|
2029
|
+
* @param {Color} color - The clear color.
|
|
2030
|
+
* @param {number} [alpha=1] - The clear alpha.
|
|
2031
|
+
*/
|
|
2032
|
+
setClearColor( color, alpha = 1 ) {
|
|
960
2033
|
|
|
961
2034
|
this._clearColor.set( color );
|
|
962
2035
|
this._clearColor.a = alpha;
|
|
963
2036
|
|
|
964
2037
|
}
|
|
965
2038
|
|
|
2039
|
+
/**
|
|
2040
|
+
* Returns the clear alpha.
|
|
2041
|
+
*
|
|
2042
|
+
* @return {number} The clear alpha.
|
|
2043
|
+
*/
|
|
966
2044
|
getClearAlpha() {
|
|
967
2045
|
|
|
968
2046
|
return this._clearColor.a;
|
|
969
2047
|
|
|
970
2048
|
}
|
|
971
2049
|
|
|
2050
|
+
/**
|
|
2051
|
+
* Defines the clear alpha.
|
|
2052
|
+
*
|
|
2053
|
+
* @param {number} alpha - The clear alpha.
|
|
2054
|
+
*/
|
|
972
2055
|
setClearAlpha( alpha ) {
|
|
973
2056
|
|
|
974
2057
|
this._clearColor.a = alpha;
|
|
975
2058
|
|
|
976
2059
|
}
|
|
977
2060
|
|
|
2061
|
+
/**
|
|
2062
|
+
* Returns the clear depth.
|
|
2063
|
+
*
|
|
2064
|
+
* @return {number} The clear depth.
|
|
2065
|
+
*/
|
|
978
2066
|
getClearDepth() {
|
|
979
2067
|
|
|
980
|
-
return this._clearDepth;
|
|
2068
|
+
return ( this.reversedDepthBuffer === true ) ? 1 - this._clearDepth : this._clearDepth;
|
|
981
2069
|
|
|
982
2070
|
}
|
|
983
2071
|
|
|
2072
|
+
/**
|
|
2073
|
+
* Defines the clear depth.
|
|
2074
|
+
*
|
|
2075
|
+
* @param {number} depth - The clear depth.
|
|
2076
|
+
*/
|
|
984
2077
|
setClearDepth( depth ) {
|
|
985
2078
|
|
|
986
2079
|
this._clearDepth = depth;
|
|
987
2080
|
|
|
988
2081
|
}
|
|
989
2082
|
|
|
2083
|
+
/**
|
|
2084
|
+
* Returns the clear stencil.
|
|
2085
|
+
*
|
|
2086
|
+
* @return {number} The clear stencil.
|
|
2087
|
+
*/
|
|
990
2088
|
getClearStencil() {
|
|
991
2089
|
|
|
992
2090
|
return this._clearStencil;
|
|
993
2091
|
|
|
994
2092
|
}
|
|
995
2093
|
|
|
2094
|
+
/**
|
|
2095
|
+
* Defines the clear stencil.
|
|
2096
|
+
*
|
|
2097
|
+
* @param {number} stencil - The clear stencil.
|
|
2098
|
+
*/
|
|
996
2099
|
setClearStencil( stencil ) {
|
|
997
2100
|
|
|
998
2101
|
this._clearStencil = stencil;
|
|
999
2102
|
|
|
1000
2103
|
}
|
|
1001
2104
|
|
|
2105
|
+
/**
|
|
2106
|
+
* This method performs an occlusion query for the given 3D object.
|
|
2107
|
+
* It returns `true` if the given 3D object is fully occluded by other
|
|
2108
|
+
* 3D objects in the scene.
|
|
2109
|
+
*
|
|
2110
|
+
* @param {Object3D} object - The 3D object to test.
|
|
2111
|
+
* @return {boolean} Whether the 3D object is fully occluded or not.
|
|
2112
|
+
*/
|
|
1002
2113
|
isOccluded( object ) {
|
|
1003
2114
|
|
|
1004
2115
|
const renderContext = this._currentRenderContext;
|
|
@@ -1007,124 +2118,287 @@ class Renderer {
|
|
|
1007
2118
|
|
|
1008
2119
|
}
|
|
1009
2120
|
|
|
2121
|
+
/**
|
|
2122
|
+
* Performs a manual clear operation. This method ignores `autoClear` properties.
|
|
2123
|
+
*
|
|
2124
|
+
* @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
|
|
2125
|
+
* @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
|
|
2126
|
+
* @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
|
|
2127
|
+
*/
|
|
1010
2128
|
clear( color = true, depth = true, stencil = true ) {
|
|
1011
2129
|
|
|
1012
2130
|
if ( this._initialized === false ) {
|
|
1013
2131
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
return this.clearAsync( color, depth, stencil );
|
|
2132
|
+
throw new Error( 'Renderer: .clear() called before the backend is initialized. Use "await renderer.init();" before before using this method.' );
|
|
1017
2133
|
|
|
1018
2134
|
}
|
|
1019
2135
|
|
|
1020
2136
|
const renderTarget = this._renderTarget || this._getFrameBufferTarget();
|
|
1021
2137
|
|
|
1022
|
-
let
|
|
2138
|
+
let renderContext = null;
|
|
1023
2139
|
|
|
1024
2140
|
if ( renderTarget !== null ) {
|
|
1025
2141
|
|
|
1026
2142
|
this._textures.updateRenderTarget( renderTarget );
|
|
1027
2143
|
|
|
1028
|
-
renderTargetData = this._textures.get( renderTarget );
|
|
2144
|
+
const renderTargetData = this._textures.get( renderTarget );
|
|
2145
|
+
|
|
2146
|
+
renderContext = this._renderContexts.get( renderTarget );
|
|
2147
|
+
renderContext.textures = renderTargetData.textures;
|
|
2148
|
+
renderContext.depthTexture = renderTargetData.depthTexture;
|
|
2149
|
+
renderContext.width = renderTargetData.width;
|
|
2150
|
+
renderContext.height = renderTargetData.height;
|
|
2151
|
+
renderContext.renderTarget = renderTarget;
|
|
2152
|
+
renderContext.depth = renderTarget.depthBuffer;
|
|
2153
|
+
renderContext.stencil = renderTarget.stencilBuffer;
|
|
2154
|
+
// #30329
|
|
2155
|
+
const color = this.backend.getClearColor();
|
|
2156
|
+
renderContext.clearColorValue.r = color.r;
|
|
2157
|
+
renderContext.clearColorValue.g = color.g;
|
|
2158
|
+
renderContext.clearColorValue.b = color.b;
|
|
2159
|
+
renderContext.clearColorValue.a = color.a;
|
|
2160
|
+
renderContext.clearDepthValue = this.getClearDepth();
|
|
2161
|
+
renderContext.clearStencilValue = this.getClearStencil();
|
|
2162
|
+
renderContext.activeCubeFace = this.getActiveCubeFace();
|
|
2163
|
+
renderContext.activeMipmapLevel = this.getActiveMipmapLevel();
|
|
1029
2164
|
|
|
1030
2165
|
}
|
|
1031
2166
|
|
|
1032
|
-
this.backend.clear( color, depth, stencil,
|
|
2167
|
+
this.backend.clear( color, depth, stencil, renderContext );
|
|
1033
2168
|
|
|
1034
2169
|
if ( renderTarget !== null && this._renderTarget === null ) {
|
|
1035
2170
|
|
|
1036
|
-
|
|
1037
|
-
// the clear operation clears the intermediate renderTarget texture, but does not update the screen canvas.
|
|
1038
|
-
|
|
1039
|
-
const quad = this._quad;
|
|
1040
|
-
|
|
1041
|
-
if ( this._nodes.hasOutputChange( renderTarget.texture ) ) {
|
|
1042
|
-
|
|
1043
|
-
quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture );
|
|
1044
|
-
quad.material.needsUpdate = true;
|
|
1045
|
-
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
this._renderScene( quad, quad.camera, false );
|
|
2171
|
+
this._renderOutput( renderTarget );
|
|
1049
2172
|
|
|
1050
2173
|
}
|
|
1051
2174
|
|
|
1052
2175
|
}
|
|
1053
2176
|
|
|
2177
|
+
/**
|
|
2178
|
+
* Performs a manual clear operation of the color buffer. This method ignores `autoClear` properties.
|
|
2179
|
+
*/
|
|
1054
2180
|
clearColor() {
|
|
1055
2181
|
|
|
1056
|
-
|
|
2182
|
+
this.clear( true, false, false );
|
|
1057
2183
|
|
|
1058
2184
|
}
|
|
1059
2185
|
|
|
2186
|
+
/**
|
|
2187
|
+
* Performs a manual clear operation of the depth buffer. This method ignores `autoClear` properties.
|
|
2188
|
+
*/
|
|
1060
2189
|
clearDepth() {
|
|
1061
2190
|
|
|
1062
|
-
|
|
2191
|
+
this.clear( false, true, false );
|
|
1063
2192
|
|
|
1064
2193
|
}
|
|
1065
2194
|
|
|
2195
|
+
/**
|
|
2196
|
+
* Performs a manual clear operation of the stencil buffer. This method ignores `autoClear` properties.
|
|
2197
|
+
*/
|
|
1066
2198
|
clearStencil() {
|
|
1067
2199
|
|
|
1068
|
-
|
|
2200
|
+
this.clear( false, false, true );
|
|
1069
2201
|
|
|
1070
2202
|
}
|
|
1071
2203
|
|
|
2204
|
+
/**
|
|
2205
|
+
* Async version of {@link Renderer#clear}.
|
|
2206
|
+
*
|
|
2207
|
+
* @async
|
|
2208
|
+
* @deprecated
|
|
2209
|
+
* @param {boolean} [color=true] - Whether the color buffer should be cleared or not.
|
|
2210
|
+
* @param {boolean} [depth=true] - Whether the depth buffer should be cleared or not.
|
|
2211
|
+
* @param {boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
|
|
2212
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
2213
|
+
*/
|
|
1072
2214
|
async clearAsync( color = true, depth = true, stencil = true ) {
|
|
1073
2215
|
|
|
1074
|
-
|
|
2216
|
+
warnOnce( 'Renderer: "clearAsync()" has been deprecated. Use "clear()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
|
|
2217
|
+
|
|
2218
|
+
await this.init();
|
|
1075
2219
|
|
|
1076
2220
|
this.clear( color, depth, stencil );
|
|
1077
2221
|
|
|
1078
2222
|
}
|
|
1079
2223
|
|
|
1080
|
-
|
|
2224
|
+
/**
|
|
2225
|
+
* Async version of {@link Renderer#clearColor}.
|
|
2226
|
+
*
|
|
2227
|
+
* @async
|
|
2228
|
+
* @deprecated
|
|
2229
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
2230
|
+
*/
|
|
2231
|
+
async clearColorAsync() {
|
|
2232
|
+
|
|
2233
|
+
warnOnce( 'Renderer: "clearColorAsync()" has been deprecated. Use "clearColor()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
|
|
1081
2234
|
|
|
1082
|
-
|
|
2235
|
+
this.clear( true, false, false );
|
|
1083
2236
|
|
|
1084
2237
|
}
|
|
1085
2238
|
|
|
1086
|
-
|
|
2239
|
+
/**
|
|
2240
|
+
* Async version of {@link Renderer#clearDepth}.
|
|
2241
|
+
*
|
|
2242
|
+
* @async
|
|
2243
|
+
* @deprecated
|
|
2244
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
2245
|
+
*/
|
|
2246
|
+
async clearDepthAsync() {
|
|
1087
2247
|
|
|
1088
|
-
|
|
2248
|
+
warnOnce( 'Renderer: "clearDepthAsync()" has been deprecated. Use "clearDepth()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
|
|
2249
|
+
|
|
2250
|
+
this.clear( false, true, false );
|
|
1089
2251
|
|
|
1090
2252
|
}
|
|
1091
2253
|
|
|
1092
|
-
|
|
2254
|
+
/**
|
|
2255
|
+
* Async version of {@link Renderer#clearStencil}.
|
|
2256
|
+
*
|
|
2257
|
+
* @async
|
|
2258
|
+
* @deprecated
|
|
2259
|
+
* @return {Promise} A Promise that resolves when the clear operation has been executed.
|
|
2260
|
+
*/
|
|
2261
|
+
async clearStencilAsync() {
|
|
2262
|
+
|
|
2263
|
+
warnOnce( 'Renderer: "clearStencilAsync()" has been deprecated. Use "clearStencil()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
|
|
1093
2264
|
|
|
1094
|
-
|
|
2265
|
+
this.clear( false, false, true );
|
|
1095
2266
|
|
|
1096
2267
|
}
|
|
1097
2268
|
|
|
2269
|
+
/**
|
|
2270
|
+
* Returns `true` if a framebuffer target is needed to perform tone mapping or color space conversion.
|
|
2271
|
+
* If this is the case, the renderer allocates an internal render target for that purpose.
|
|
2272
|
+
*
|
|
2273
|
+
*/
|
|
2274
|
+
get needsFrameBufferTarget() {
|
|
2275
|
+
|
|
2276
|
+
const useToneMapping = this.currentToneMapping !== NoToneMapping;
|
|
2277
|
+
const useColorSpace = this.currentColorSpace !== ColorManagement.workingColorSpace;
|
|
2278
|
+
|
|
2279
|
+
return useToneMapping || useColorSpace;
|
|
2280
|
+
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
/**
|
|
2284
|
+
* The number of samples used for multi-sample anti-aliasing (MSAA).
|
|
2285
|
+
*
|
|
2286
|
+
* @type {number}
|
|
2287
|
+
* @default 0
|
|
2288
|
+
*/
|
|
2289
|
+
get samples() {
|
|
2290
|
+
|
|
2291
|
+
return this._samples;
|
|
2292
|
+
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
/**
|
|
2296
|
+
* The current number of samples used for multi-sample anti-aliasing (MSAA).
|
|
2297
|
+
*
|
|
2298
|
+
* When rendering to a custom render target, the number of samples of that render target is used.
|
|
2299
|
+
* If the renderer needs an internal framebuffer target for tone mapping or color space conversion,
|
|
2300
|
+
* the number of samples is set to 0.
|
|
2301
|
+
*
|
|
2302
|
+
* @type {number}
|
|
2303
|
+
*/
|
|
2304
|
+
get currentSamples() {
|
|
2305
|
+
|
|
2306
|
+
let samples = this._samples;
|
|
2307
|
+
|
|
2308
|
+
if ( this._renderTarget !== null ) {
|
|
2309
|
+
|
|
2310
|
+
samples = this._renderTarget.samples;
|
|
2311
|
+
|
|
2312
|
+
} else if ( this.needsFrameBufferTarget ) {
|
|
2313
|
+
|
|
2314
|
+
samples = 0;
|
|
2315
|
+
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
return samples;
|
|
2319
|
+
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
/**
|
|
2323
|
+
* The current tone mapping of the renderer. When not producing screen output,
|
|
2324
|
+
* the tone mapping is always `NoToneMapping`.
|
|
2325
|
+
*
|
|
2326
|
+
* @type {number}
|
|
2327
|
+
*/
|
|
1098
2328
|
get currentToneMapping() {
|
|
1099
2329
|
|
|
1100
|
-
return this.
|
|
2330
|
+
return this.isOutputTarget ? this.toneMapping : NoToneMapping;
|
|
1101
2331
|
|
|
1102
2332
|
}
|
|
1103
2333
|
|
|
2334
|
+
/**
|
|
2335
|
+
* The current color space of the renderer. When not producing screen output,
|
|
2336
|
+
* the color space is always the working color space.
|
|
2337
|
+
*
|
|
2338
|
+
* @type {string}
|
|
2339
|
+
*/
|
|
1104
2340
|
get currentColorSpace() {
|
|
1105
2341
|
|
|
1106
|
-
return this.
|
|
2342
|
+
return this.isOutputTarget ? this.outputColorSpace : ColorManagement.workingColorSpace;
|
|
1107
2343
|
|
|
1108
2344
|
}
|
|
1109
2345
|
|
|
2346
|
+
/**
|
|
2347
|
+
* Returns `true` if the rendering settings are set to screen output.
|
|
2348
|
+
*
|
|
2349
|
+
* @returns {boolean} True if the current render target is the same of output render target or `null`, otherwise false.
|
|
2350
|
+
*/
|
|
2351
|
+
get isOutputTarget() {
|
|
2352
|
+
|
|
2353
|
+
return this._renderTarget === this._outputRenderTarget || this._renderTarget === null;
|
|
2354
|
+
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
/**
|
|
2358
|
+
* Frees all internal resources of the renderer. Call this method if the renderer
|
|
2359
|
+
* is no longer in use by your app.
|
|
2360
|
+
*/
|
|
1110
2361
|
dispose() {
|
|
1111
2362
|
|
|
1112
|
-
this.
|
|
2363
|
+
if ( this._initialized === true ) {
|
|
2364
|
+
|
|
2365
|
+
this.info.dispose();
|
|
2366
|
+
this.backend.dispose();
|
|
2367
|
+
|
|
2368
|
+
this._animation.dispose();
|
|
2369
|
+
this._objects.dispose();
|
|
2370
|
+
this._geometries.dispose();
|
|
2371
|
+
this._pipelines.dispose();
|
|
2372
|
+
this._nodes.dispose();
|
|
2373
|
+
this._bindings.dispose();
|
|
2374
|
+
this._renderLists.dispose();
|
|
2375
|
+
this._renderContexts.dispose();
|
|
2376
|
+
this._textures.dispose();
|
|
1113
2377
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
2378
|
+
if ( this._frameBufferTarget !== null ) this._frameBufferTarget.dispose();
|
|
2379
|
+
|
|
2380
|
+
Object.values( this.backend.timestampQueryPool ).forEach( queryPool => {
|
|
2381
|
+
|
|
2382
|
+
if ( queryPool !== null ) queryPool.dispose();
|
|
2383
|
+
|
|
2384
|
+
} );
|
|
2385
|
+
|
|
2386
|
+
}
|
|
1122
2387
|
|
|
1123
2388
|
this.setRenderTarget( null );
|
|
1124
2389
|
this.setAnimationLoop( null );
|
|
1125
2390
|
|
|
1126
2391
|
}
|
|
1127
2392
|
|
|
2393
|
+
/**
|
|
2394
|
+
* Sets the given render target. Calling this method means the renderer does not
|
|
2395
|
+
* target the default framebuffer (meaning the canvas) anymore but a custom framebuffer.
|
|
2396
|
+
* Use `null` as the first argument to reset the state.
|
|
2397
|
+
*
|
|
2398
|
+
* @param {?RenderTarget} renderTarget - The render target to set.
|
|
2399
|
+
* @param {number} [activeCubeFace=0] - The active cube face.
|
|
2400
|
+
* @param {number} [activeMipmapLevel=0] - The active mipmap level.
|
|
2401
|
+
*/
|
|
1128
2402
|
setRenderTarget( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
|
|
1129
2403
|
|
|
1130
2404
|
this._renderTarget = renderTarget;
|
|
@@ -1133,27 +2407,148 @@ class Renderer {
|
|
|
1133
2407
|
|
|
1134
2408
|
}
|
|
1135
2409
|
|
|
2410
|
+
/**
|
|
2411
|
+
* Returns the current render target.
|
|
2412
|
+
*
|
|
2413
|
+
* @return {?RenderTarget} The render target. Returns `null` if no render target is set.
|
|
2414
|
+
*/
|
|
1136
2415
|
getRenderTarget() {
|
|
1137
2416
|
|
|
1138
2417
|
return this._renderTarget;
|
|
1139
2418
|
|
|
1140
2419
|
}
|
|
1141
2420
|
|
|
2421
|
+
/**
|
|
2422
|
+
* Sets the output render target for the renderer.
|
|
2423
|
+
*
|
|
2424
|
+
* @param {Object} renderTarget - The render target to set as the output target.
|
|
2425
|
+
*/
|
|
2426
|
+
setOutputRenderTarget( renderTarget ) {
|
|
2427
|
+
|
|
2428
|
+
this._outputRenderTarget = renderTarget;
|
|
2429
|
+
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
/**
|
|
2433
|
+
* Returns the current output target.
|
|
2434
|
+
*
|
|
2435
|
+
* @return {?RenderTarget} The current output render target. Returns `null` if no output target is set.
|
|
2436
|
+
*/
|
|
2437
|
+
getOutputRenderTarget() {
|
|
2438
|
+
|
|
2439
|
+
return this._outputRenderTarget;
|
|
2440
|
+
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2443
|
+
/**
|
|
2444
|
+
* Sets the canvas target. The canvas target manages the HTML canvas
|
|
2445
|
+
* or the offscreen canvas the renderer draws into.
|
|
2446
|
+
*
|
|
2447
|
+
* @param {CanvasTarget} canvasTarget - The canvas target.
|
|
2448
|
+
*/
|
|
2449
|
+
setCanvasTarget( canvasTarget ) {
|
|
2450
|
+
|
|
2451
|
+
this._canvasTarget.removeEventListener( 'resize', this._onCanvasTargetResize );
|
|
2452
|
+
|
|
2453
|
+
this._canvasTarget = canvasTarget;
|
|
2454
|
+
this._canvasTarget.addEventListener( 'resize', this._onCanvasTargetResize );
|
|
2455
|
+
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
/**
|
|
2459
|
+
* Returns the current canvas target.
|
|
2460
|
+
*
|
|
2461
|
+
* @return {CanvasTarget} The current canvas target.
|
|
2462
|
+
*/
|
|
2463
|
+
getCanvasTarget() {
|
|
2464
|
+
|
|
2465
|
+
return this._canvasTarget;
|
|
2466
|
+
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
/**
|
|
2470
|
+
* Resets the renderer to the initial state before WebXR started.
|
|
2471
|
+
*
|
|
2472
|
+
* @private
|
|
2473
|
+
*/
|
|
2474
|
+
_resetXRState() {
|
|
2475
|
+
|
|
2476
|
+
this.backend.setXRTarget( null );
|
|
2477
|
+
this.setOutputRenderTarget( null );
|
|
2478
|
+
this.setRenderTarget( null );
|
|
2479
|
+
|
|
2480
|
+
this._frameBufferTarget.dispose();
|
|
2481
|
+
this._frameBufferTarget = null;
|
|
2482
|
+
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
/**
|
|
2486
|
+
* Callback for {@link Renderer#setRenderObjectFunction}.
|
|
2487
|
+
*
|
|
2488
|
+
* @callback renderObjectFunction
|
|
2489
|
+
* @param {Object3D} object - The 3D object.
|
|
2490
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
2491
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
2492
|
+
* @param {BufferGeometry} geometry - The object's geometry.
|
|
2493
|
+
* @param {Material} material - The object's material.
|
|
2494
|
+
* @param {?Object} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
2495
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
2496
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
2497
|
+
* @param {?string} [passId=null] - An optional ID for identifying the pass.
|
|
2498
|
+
*/
|
|
2499
|
+
|
|
2500
|
+
/**
|
|
2501
|
+
* Sets the given render object function. Calling this method overwrites the default implementation
|
|
2502
|
+
* which is {@link Renderer#renderObject}. Defining a custom function can be useful
|
|
2503
|
+
* if you want to modify the way objects are rendered. For example you can define things like "every
|
|
2504
|
+
* object that has material of a certain type should perform a pre-pass with a special overwrite material".
|
|
2505
|
+
* The custom function must always call `renderObject()` in its implementation.
|
|
2506
|
+
*
|
|
2507
|
+
* Use `null` as the first argument to reset the state.
|
|
2508
|
+
*
|
|
2509
|
+
* @param {?renderObjectFunction} renderObjectFunction - The render object function.
|
|
2510
|
+
*/
|
|
1142
2511
|
setRenderObjectFunction( renderObjectFunction ) {
|
|
1143
2512
|
|
|
1144
2513
|
this._renderObjectFunction = renderObjectFunction;
|
|
1145
2514
|
|
|
1146
2515
|
}
|
|
1147
2516
|
|
|
2517
|
+
/**
|
|
2518
|
+
* Returns the current render object function.
|
|
2519
|
+
*
|
|
2520
|
+
* @return {?Function} The current render object function. Returns `null` if no function is set.
|
|
2521
|
+
*/
|
|
1148
2522
|
getRenderObjectFunction() {
|
|
1149
2523
|
|
|
1150
2524
|
return this._renderObjectFunction;
|
|
1151
2525
|
|
|
1152
2526
|
}
|
|
1153
2527
|
|
|
1154
|
-
|
|
2528
|
+
/**
|
|
2529
|
+
* Execute a single or an array of compute nodes. This method can only be called
|
|
2530
|
+
* if the renderer has been initialized.
|
|
2531
|
+
*
|
|
2532
|
+
* @param {Node|Array<Node>} computeNodes - The compute node(s).
|
|
2533
|
+
* @param {number|Array<number>|IndirectStorageBufferAttribute} [dispatchSize=null]
|
|
2534
|
+
* - A single number representing count, or
|
|
2535
|
+
* - An array [x, y, z] representing dispatch size, or
|
|
2536
|
+
* - A IndirectStorageBufferAttribute for indirect dispatch size.
|
|
2537
|
+
* @return {Promise|undefined} A Promise that resolve when the compute has finished. Only returned when the renderer has not been initialized.
|
|
2538
|
+
*/
|
|
2539
|
+
compute( computeNodes, dispatchSize = null ) {
|
|
1155
2540
|
|
|
1156
|
-
if ( this.
|
|
2541
|
+
if ( this._isDeviceLost === true ) return;
|
|
2542
|
+
|
|
2543
|
+
if ( this._initialized === false ) {
|
|
2544
|
+
|
|
2545
|
+
warn( 'Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead.' );
|
|
2546
|
+
|
|
2547
|
+
return this.computeAsync( computeNodes, dispatchSize );
|
|
2548
|
+
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
//
|
|
1157
2552
|
|
|
1158
2553
|
const nodeFrame = this._nodes.nodeFrame;
|
|
1159
2554
|
|
|
@@ -1169,6 +2564,12 @@ class Renderer {
|
|
|
1169
2564
|
|
|
1170
2565
|
//
|
|
1171
2566
|
|
|
2567
|
+
this.backend.updateTimeStampUID( computeNodes );
|
|
2568
|
+
|
|
2569
|
+
this.inspector.beginCompute( this.backend.getTimestampUID( computeNodes ), computeNodes );
|
|
2570
|
+
|
|
2571
|
+
//
|
|
2572
|
+
|
|
1172
2573
|
const backend = this.backend;
|
|
1173
2574
|
const pipelines = this._pipelines;
|
|
1174
2575
|
const bindings = this._bindings;
|
|
@@ -1195,7 +2596,7 @@ class Renderer {
|
|
|
1195
2596
|
computeNode.removeEventListener( 'dispose', dispose );
|
|
1196
2597
|
|
|
1197
2598
|
pipelines.delete( computeNode );
|
|
1198
|
-
bindings.
|
|
2599
|
+
bindings.deleteForCompute( computeNode );
|
|
1199
2600
|
nodes.delete( computeNode );
|
|
1200
2601
|
|
|
1201
2602
|
};
|
|
@@ -1204,7 +2605,13 @@ class Renderer {
|
|
|
1204
2605
|
|
|
1205
2606
|
//
|
|
1206
2607
|
|
|
1207
|
-
|
|
2608
|
+
const onInitFn = computeNode.onInitFunction;
|
|
2609
|
+
|
|
2610
|
+
if ( onInitFn !== null ) {
|
|
2611
|
+
|
|
2612
|
+
onInitFn.call( computeNode, { renderer: this } );
|
|
2613
|
+
|
|
2614
|
+
}
|
|
1208
2615
|
|
|
1209
2616
|
}
|
|
1210
2617
|
|
|
@@ -1214,35 +2621,79 @@ class Renderer {
|
|
|
1214
2621
|
const computeBindings = bindings.getForCompute( computeNode );
|
|
1215
2622
|
const computePipeline = pipelines.getForCompute( computeNode, computeBindings );
|
|
1216
2623
|
|
|
1217
|
-
backend.compute( computeNodes, computeNode, computeBindings, computePipeline );
|
|
2624
|
+
backend.compute( computeNodes, computeNode, computeBindings, computePipeline, dispatchSize );
|
|
1218
2625
|
|
|
1219
2626
|
}
|
|
1220
2627
|
|
|
1221
2628
|
backend.finishCompute( computeNodes );
|
|
1222
2629
|
|
|
1223
|
-
await this.backend.resolveTimestampAsync( computeNodes, 'compute' );
|
|
1224
|
-
|
|
1225
2630
|
//
|
|
1226
2631
|
|
|
1227
2632
|
nodeFrame.renderId = previousRenderId;
|
|
1228
2633
|
|
|
2634
|
+
//
|
|
2635
|
+
|
|
2636
|
+
this.inspector.finishCompute( this.backend.getTimestampUID( computeNodes ) );
|
|
2637
|
+
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
/**
|
|
2641
|
+
* Execute a single or an array of compute nodes.
|
|
2642
|
+
*
|
|
2643
|
+
* @async
|
|
2644
|
+
* @param {Node|Array<Node>} computeNodes - The compute node(s).
|
|
2645
|
+
* @param {number|Array<number>|IndirectStorageBufferAttribute} [dispatchSize=null]
|
|
2646
|
+
* - A single number representing count, or
|
|
2647
|
+
* - An array [x, y, z] representing dispatch size, or
|
|
2648
|
+
* - A IndirectStorageBufferAttribute for indirect dispatch size.
|
|
2649
|
+
* @return {Promise} A Promise that resolve when the compute has finished.
|
|
2650
|
+
*/
|
|
2651
|
+
async computeAsync( computeNodes, dispatchSize = null ) {
|
|
2652
|
+
|
|
2653
|
+
if ( this._initialized === false ) await this.init();
|
|
2654
|
+
|
|
2655
|
+
this.compute( computeNodes, dispatchSize );
|
|
2656
|
+
|
|
1229
2657
|
}
|
|
1230
2658
|
|
|
2659
|
+
/**
|
|
2660
|
+
* Checks if the given feature is supported by the selected backend.
|
|
2661
|
+
*
|
|
2662
|
+
* @async
|
|
2663
|
+
* @deprecated
|
|
2664
|
+
* @param {string} name - The feature's name.
|
|
2665
|
+
* @return {Promise<boolean>} A Promise that resolves with a bool that indicates whether the feature is supported or not.
|
|
2666
|
+
*/
|
|
1231
2667
|
async hasFeatureAsync( name ) {
|
|
1232
2668
|
|
|
2669
|
+
warnOnce( 'Renderer: "hasFeatureAsync()" has been deprecated. Use "hasFeature()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
|
|
2670
|
+
|
|
2671
|
+
await this.init();
|
|
2672
|
+
|
|
2673
|
+
return this.hasFeature( name );
|
|
2674
|
+
|
|
2675
|
+
}
|
|
2676
|
+
|
|
2677
|
+
async resolveTimestampsAsync( type = 'render' ) {
|
|
2678
|
+
|
|
1233
2679
|
if ( this._initialized === false ) await this.init();
|
|
1234
2680
|
|
|
1235
|
-
return this.backend.
|
|
2681
|
+
return this.backend.resolveTimestampsAsync( type );
|
|
1236
2682
|
|
|
1237
2683
|
}
|
|
1238
2684
|
|
|
2685
|
+
/**
|
|
2686
|
+
* Checks if the given feature is supported by the selected backend. If the
|
|
2687
|
+
* renderer has not been initialized, this method always returns `false`.
|
|
2688
|
+
*
|
|
2689
|
+
* @param {string} name - The feature's name.
|
|
2690
|
+
* @return {boolean} Whether the feature is supported or not.
|
|
2691
|
+
*/
|
|
1239
2692
|
hasFeature( name ) {
|
|
1240
2693
|
|
|
1241
2694
|
if ( this._initialized === false ) {
|
|
1242
2695
|
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
return false;
|
|
2696
|
+
throw new Error( 'Renderer: .hasFeature() called before the backend is initialized. Use "await renderer.init();" before before using this method.' );
|
|
1246
2697
|
|
|
1247
2698
|
}
|
|
1248
2699
|
|
|
@@ -1250,35 +2701,204 @@ class Renderer {
|
|
|
1250
2701
|
|
|
1251
2702
|
}
|
|
1252
2703
|
|
|
2704
|
+
/**
|
|
2705
|
+
* Returns `true` when the renderer has been initialized.
|
|
2706
|
+
*
|
|
2707
|
+
* @return {boolean} Whether the renderer has been initialized or not.
|
|
2708
|
+
*/
|
|
2709
|
+
hasInitialized() {
|
|
2710
|
+
|
|
2711
|
+
return this._initialized;
|
|
2712
|
+
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
/**
|
|
2716
|
+
* Initializes the given textures. Useful for preloading a texture rather than waiting until first render
|
|
2717
|
+
* (which can cause noticeable lags due to decode and GPU upload overhead).
|
|
2718
|
+
*
|
|
2719
|
+
* @async
|
|
2720
|
+
* @deprecated
|
|
2721
|
+
* @param {Texture} texture - The texture.
|
|
2722
|
+
* @return {Promise} A Promise that resolves when the texture has been initialized.
|
|
2723
|
+
*/
|
|
2724
|
+
async initTextureAsync( texture ) {
|
|
2725
|
+
|
|
2726
|
+
warnOnce( 'Renderer: "initTextureAsync()" has been deprecated. Use "initTexture()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
|
|
2727
|
+
|
|
2728
|
+
await this.init();
|
|
2729
|
+
|
|
2730
|
+
this.initTexture( texture );
|
|
2731
|
+
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2734
|
+
/**
|
|
2735
|
+
* Initializes the given texture. Useful for preloading a texture rather than waiting until first render
|
|
2736
|
+
* (which can cause noticeable lags due to decode and GPU upload overhead).
|
|
2737
|
+
*
|
|
2738
|
+
* This method can only be used if the renderer has been initialized.
|
|
2739
|
+
*
|
|
2740
|
+
* @param {Texture} texture - The texture.
|
|
2741
|
+
*/
|
|
2742
|
+
initTexture( texture ) {
|
|
2743
|
+
|
|
2744
|
+
if ( this._initialized === false ) {
|
|
2745
|
+
|
|
2746
|
+
throw new Error( 'Renderer: .initTexture() called before the backend is initialized. Use "await renderer.init();" before before using this method.' );
|
|
2747
|
+
|
|
2748
|
+
}
|
|
2749
|
+
|
|
2750
|
+
this._textures.updateTexture( texture );
|
|
2751
|
+
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
/**
|
|
2755
|
+
* Initializes the given render target.
|
|
2756
|
+
*
|
|
2757
|
+
* @param {RenderTarget} renderTarget - The render target to intialize.
|
|
2758
|
+
*/
|
|
2759
|
+
initRenderTarget( renderTarget ) {
|
|
2760
|
+
|
|
2761
|
+
if ( this._initialized === false ) {
|
|
2762
|
+
|
|
2763
|
+
throw new Error( 'Renderer: .initRenderTarget() called before the backend is initialized. Use "await renderer.init();" before before using this method.' );
|
|
2764
|
+
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
this._textures.updateRenderTarget( renderTarget );
|
|
2768
|
+
|
|
2769
|
+
const renderTargetData = this._textures.get( renderTarget );
|
|
2770
|
+
|
|
2771
|
+
const renderContext = this._renderContexts.get( renderTarget );
|
|
2772
|
+
|
|
2773
|
+
renderContext.textures = renderTargetData.textures;
|
|
2774
|
+
renderContext.depthTexture = renderTargetData.depthTexture;
|
|
2775
|
+
renderContext.width = renderTargetData.width;
|
|
2776
|
+
renderContext.height = renderTargetData.height;
|
|
2777
|
+
renderContext.renderTarget = renderTarget;
|
|
2778
|
+
renderContext.depth = renderTarget.depthBuffer;
|
|
2779
|
+
renderContext.stencil = renderTarget.stencilBuffer;
|
|
2780
|
+
|
|
2781
|
+
this.backend.initRenderTarget( renderContext );
|
|
2782
|
+
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2785
|
+
/**
|
|
2786
|
+
* Copies the current bound framebuffer into the given texture.
|
|
2787
|
+
*
|
|
2788
|
+
* @param {FramebufferTexture} framebufferTexture - The texture.
|
|
2789
|
+
* @param {?(Vector2|Vector4)} [rectangle=null] - A two or four dimensional vector that defines the rectangular portion of the framebuffer that should be copied.
|
|
2790
|
+
*/
|
|
1253
2791
|
copyFramebufferToTexture( framebufferTexture, rectangle = null ) {
|
|
1254
2792
|
|
|
1255
|
-
|
|
2793
|
+
if ( rectangle !== null ) {
|
|
2794
|
+
|
|
2795
|
+
if ( rectangle.isVector2 ) {
|
|
2796
|
+
|
|
2797
|
+
rectangle = _vector4.set( rectangle.x, rectangle.y, framebufferTexture.image.width, framebufferTexture.image.height ).floor();
|
|
2798
|
+
|
|
2799
|
+
} else if ( rectangle.isVector4 ) {
|
|
2800
|
+
|
|
2801
|
+
rectangle = _vector4.copy( rectangle ).floor();
|
|
2802
|
+
|
|
2803
|
+
} else {
|
|
2804
|
+
|
|
2805
|
+
error( 'Renderer.copyFramebufferToTexture: Invalid rectangle.' );
|
|
1256
2806
|
|
|
1257
|
-
|
|
2807
|
+
return;
|
|
1258
2808
|
|
|
1259
|
-
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
} else {
|
|
2812
|
+
|
|
2813
|
+
rectangle = _vector4.set( 0, 0, framebufferTexture.image.width, framebufferTexture.image.height );
|
|
2814
|
+
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
//
|
|
2818
|
+
|
|
2819
|
+
let renderContext = this._currentRenderContext;
|
|
2820
|
+
let renderTarget;
|
|
2821
|
+
|
|
2822
|
+
if ( renderContext !== null ) {
|
|
2823
|
+
|
|
2824
|
+
renderTarget = renderContext.renderTarget;
|
|
2825
|
+
|
|
2826
|
+
} else {
|
|
2827
|
+
|
|
2828
|
+
renderTarget = this._renderTarget || this._getFrameBufferTarget();
|
|
2829
|
+
|
|
2830
|
+
if ( renderTarget !== null ) {
|
|
2831
|
+
|
|
2832
|
+
this._textures.updateRenderTarget( renderTarget );
|
|
2833
|
+
|
|
2834
|
+
renderContext = this._textures.get( renderTarget );
|
|
2835
|
+
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
//
|
|
2841
|
+
|
|
2842
|
+
this._textures.updateTexture( framebufferTexture, { renderTarget } );
|
|
1260
2843
|
|
|
1261
2844
|
this.backend.copyFramebufferToTexture( framebufferTexture, renderContext, rectangle );
|
|
1262
2845
|
|
|
2846
|
+
this._inspector.copyFramebufferToTexture( framebufferTexture );
|
|
2847
|
+
|
|
1263
2848
|
}
|
|
1264
2849
|
|
|
1265
|
-
|
|
2850
|
+
/**
|
|
2851
|
+
* Copies data of the given source texture into a destination texture.
|
|
2852
|
+
*
|
|
2853
|
+
* @param {Texture} srcTexture - The source texture.
|
|
2854
|
+
* @param {Texture} dstTexture - The destination texture.
|
|
2855
|
+
* @param {Box2|Box3} [srcRegion=null] - A bounding box which describes the source region. Can be two or three-dimensional.
|
|
2856
|
+
* @param {Vector2|Vector3} [dstPosition=null] - A vector that represents the origin of the destination region. Can be two or three-dimensional.
|
|
2857
|
+
* @param {number} [srcLevel=0] - The source mip level to copy from.
|
|
2858
|
+
* @param {number} [dstLevel=0] - The destination mip level to copy to.
|
|
2859
|
+
*/
|
|
2860
|
+
copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0 ) {
|
|
1266
2861
|
|
|
1267
2862
|
this._textures.updateTexture( srcTexture );
|
|
1268
2863
|
this._textures.updateTexture( dstTexture );
|
|
1269
2864
|
|
|
1270
|
-
this.backend.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition,
|
|
2865
|
+
this.backend.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, srcLevel, dstLevel );
|
|
1271
2866
|
|
|
1272
|
-
|
|
2867
|
+
this._inspector.copyTextureToTexture( srcTexture, dstTexture );
|
|
1273
2868
|
|
|
2869
|
+
}
|
|
1274
2870
|
|
|
1275
|
-
|
|
2871
|
+
/**
|
|
2872
|
+
* Reads pixel data from the given render target.
|
|
2873
|
+
*
|
|
2874
|
+
* @async
|
|
2875
|
+
* @param {RenderTarget} renderTarget - The render target to read from.
|
|
2876
|
+
* @param {number} x - The `x` coordinate of the copy region's origin.
|
|
2877
|
+
* @param {number} y - The `y` coordinate of the copy region's origin.
|
|
2878
|
+
* @param {number} width - The width of the copy region.
|
|
2879
|
+
* @param {number} height - The height of the copy region.
|
|
2880
|
+
* @param {number} [textureIndex=0] - The texture index of a MRT render target.
|
|
2881
|
+
* @param {number} [faceIndex=0] - The active cube face index.
|
|
2882
|
+
* @return {Promise<TypedArray>} A Promise that resolves when the read has been finished. The resolve provides the read data as a typed array.
|
|
2883
|
+
*/
|
|
2884
|
+
async readRenderTargetPixelsAsync( renderTarget, x, y, width, height, textureIndex = 0, faceIndex = 0 ) {
|
|
1276
2885
|
|
|
1277
|
-
return this.backend.copyTextureToBuffer( renderTarget.textures[
|
|
2886
|
+
return this.backend.copyTextureToBuffer( renderTarget.textures[ textureIndex ], x, y, width, height, faceIndex );
|
|
1278
2887
|
|
|
1279
2888
|
}
|
|
1280
2889
|
|
|
1281
|
-
|
|
2890
|
+
/**
|
|
2891
|
+
* Analyzes the given 3D object's hierarchy and builds render lists from the
|
|
2892
|
+
* processed hierarchy.
|
|
2893
|
+
*
|
|
2894
|
+
* @private
|
|
2895
|
+
* @param {Object3D} object - The 3D object to process (usually a scene).
|
|
2896
|
+
* @param {Camera} camera - The camera the object is rendered with.
|
|
2897
|
+
* @param {number} groupOrder - The group order is derived from the `renderOrder` of groups and is used to group 3D objects within groups.
|
|
2898
|
+
* @param {RenderList} renderList - The current render list.
|
|
2899
|
+
* @param {ClippingContext} clippingContext - The current clipping context.
|
|
2900
|
+
*/
|
|
2901
|
+
_projectObject( object, camera, groupOrder, renderList, clippingContext ) {
|
|
1282
2902
|
|
|
1283
2903
|
if ( object.visible === false ) return;
|
|
1284
2904
|
|
|
@@ -1290,6 +2910,8 @@ class Renderer {
|
|
|
1290
2910
|
|
|
1291
2911
|
groupOrder = object.renderOrder;
|
|
1292
2912
|
|
|
2913
|
+
if ( object.isClippingGroup && object.enabled ) clippingContext = clippingContext.getGroupContext( object );
|
|
2914
|
+
|
|
1293
2915
|
} else if ( object.isLOD ) {
|
|
1294
2916
|
|
|
1295
2917
|
if ( object.autoUpdate === true ) object.update( camera );
|
|
@@ -1300,7 +2922,9 @@ class Renderer {
|
|
|
1300
2922
|
|
|
1301
2923
|
} else if ( object.isSprite ) {
|
|
1302
2924
|
|
|
1303
|
-
|
|
2925
|
+
const frustum = camera.isArrayCamera ? _frustumArray : _frustum;
|
|
2926
|
+
|
|
2927
|
+
if ( ! object.frustumCulled || frustum.intersectsSprite( object, camera ) ) {
|
|
1304
2928
|
|
|
1305
2929
|
if ( this.sortObjects === true ) {
|
|
1306
2930
|
|
|
@@ -1312,7 +2936,7 @@ class Renderer {
|
|
|
1312
2936
|
|
|
1313
2937
|
if ( material.visible ) {
|
|
1314
2938
|
|
|
1315
|
-
renderList.push( object, geometry, material, groupOrder, _vector4.z, null );
|
|
2939
|
+
renderList.push( object, geometry, material, groupOrder, _vector4.z, null, clippingContext );
|
|
1316
2940
|
|
|
1317
2941
|
}
|
|
1318
2942
|
|
|
@@ -1320,11 +2944,13 @@ class Renderer {
|
|
|
1320
2944
|
|
|
1321
2945
|
} else if ( object.isLineLoop ) {
|
|
1322
2946
|
|
|
1323
|
-
|
|
2947
|
+
error( 'Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.' );
|
|
1324
2948
|
|
|
1325
2949
|
} else if ( object.isMesh || object.isLine || object.isPoints ) {
|
|
1326
2950
|
|
|
1327
|
-
|
|
2951
|
+
const frustum = camera.isArrayCamera ? _frustumArray : _frustum;
|
|
2952
|
+
|
|
2953
|
+
if ( ! object.frustumCulled || frustum.intersectsObject( object, camera ) ) {
|
|
1328
2954
|
|
|
1329
2955
|
const { geometry, material } = object;
|
|
1330
2956
|
|
|
@@ -1350,7 +2976,7 @@ class Renderer {
|
|
|
1350
2976
|
|
|
1351
2977
|
if ( groupMaterial && groupMaterial.visible ) {
|
|
1352
2978
|
|
|
1353
|
-
renderList.push( object, geometry, groupMaterial, groupOrder, _vector4.z, group );
|
|
2979
|
+
renderList.push( object, geometry, groupMaterial, groupOrder, _vector4.z, group, clippingContext );
|
|
1354
2980
|
|
|
1355
2981
|
}
|
|
1356
2982
|
|
|
@@ -1358,7 +2984,7 @@ class Renderer {
|
|
|
1358
2984
|
|
|
1359
2985
|
} else if ( material.visible ) {
|
|
1360
2986
|
|
|
1361
|
-
renderList.push( object, geometry, material, groupOrder, _vector4.z, null );
|
|
2987
|
+
renderList.push( object, geometry, material, groupOrder, _vector4.z, null, clippingContext );
|
|
1362
2988
|
|
|
1363
2989
|
}
|
|
1364
2990
|
|
|
@@ -1391,12 +3017,20 @@ class Renderer {
|
|
|
1391
3017
|
|
|
1392
3018
|
for ( let i = 0, l = children.length; i < l; i ++ ) {
|
|
1393
3019
|
|
|
1394
|
-
this._projectObject( children[ i ], camera, groupOrder, renderList );
|
|
3020
|
+
this._projectObject( children[ i ], camera, groupOrder, renderList, clippingContext );
|
|
1395
3021
|
|
|
1396
3022
|
}
|
|
1397
3023
|
|
|
1398
3024
|
}
|
|
1399
3025
|
|
|
3026
|
+
/**
|
|
3027
|
+
* Renders the given render bundles.
|
|
3028
|
+
*
|
|
3029
|
+
* @private
|
|
3030
|
+
* @param {Array<Object>} bundles - Array with render bundle data.
|
|
3031
|
+
* @param {Scene} sceneRef - The scene the render bundles belong to.
|
|
3032
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
3033
|
+
*/
|
|
1400
3034
|
_renderBundles( bundles, sceneRef, lightsNode ) {
|
|
1401
3035
|
|
|
1402
3036
|
for ( const bundle of bundles ) {
|
|
@@ -1407,126 +3041,259 @@ class Renderer {
|
|
|
1407
3041
|
|
|
1408
3042
|
}
|
|
1409
3043
|
|
|
1410
|
-
|
|
3044
|
+
/**
|
|
3045
|
+
* Renders the transparent objects from the given render lists.
|
|
3046
|
+
*
|
|
3047
|
+
* @private
|
|
3048
|
+
* @param {Array<Object>} renderList - The transparent render list.
|
|
3049
|
+
* @param {Array<Object>} doublePassList - The list of transparent objects which require a double pass (e.g. because of transmission).
|
|
3050
|
+
* @param {Camera} camera - The camera the render list should be rendered with.
|
|
3051
|
+
* @param {Scene} scene - The scene the render list belongs to.
|
|
3052
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
3053
|
+
*/
|
|
3054
|
+
_renderTransparents( renderList, doublePassList, camera, scene, lightsNode ) {
|
|
1411
3055
|
|
|
1412
|
-
|
|
3056
|
+
if ( doublePassList.length > 0 ) {
|
|
1413
3057
|
|
|
1414
|
-
|
|
3058
|
+
// render back side
|
|
1415
3059
|
|
|
1416
|
-
const
|
|
3060
|
+
for ( const { material } of doublePassList ) {
|
|
1417
3061
|
|
|
1418
|
-
|
|
1419
|
-
// the material from the renderItem object and pass it with its group data to renderObject().
|
|
3062
|
+
material.side = BackSide;
|
|
1420
3063
|
|
|
1421
|
-
|
|
3064
|
+
}
|
|
1422
3065
|
|
|
1423
|
-
|
|
3066
|
+
this._renderObjects( doublePassList, camera, scene, lightsNode, 'backSide' );
|
|
1424
3067
|
|
|
1425
|
-
|
|
3068
|
+
// render front side
|
|
1426
3069
|
|
|
1427
|
-
|
|
3070
|
+
for ( const { material } of doublePassList ) {
|
|
1428
3071
|
|
|
1429
|
-
|
|
3072
|
+
material.side = FrontSide;
|
|
1430
3073
|
|
|
1431
|
-
|
|
3074
|
+
}
|
|
1432
3075
|
|
|
1433
|
-
|
|
1434
|
-
const minDepth = ( vp.minDepth === undefined ) ? 0 : vp.minDepth;
|
|
1435
|
-
const maxDepth = ( vp.maxDepth === undefined ) ? 1 : vp.maxDepth;
|
|
3076
|
+
this._renderObjects( renderList, camera, scene, lightsNode );
|
|
1436
3077
|
|
|
1437
|
-
|
|
1438
|
-
viewportValue.copy( vp ).multiplyScalar( this._pixelRatio ).floor();
|
|
1439
|
-
viewportValue.minDepth = minDepth;
|
|
1440
|
-
viewportValue.maxDepth = maxDepth;
|
|
3078
|
+
// restore
|
|
1441
3079
|
|
|
1442
|
-
|
|
3080
|
+
for ( const { material } of doublePassList ) {
|
|
1443
3081
|
|
|
1444
|
-
|
|
3082
|
+
material.side = DoubleSide;
|
|
1445
3083
|
|
|
1446
|
-
|
|
3084
|
+
}
|
|
1447
3085
|
|
|
1448
|
-
|
|
3086
|
+
} else {
|
|
1449
3087
|
|
|
1450
|
-
|
|
3088
|
+
this._renderObjects( renderList, camera, scene, lightsNode );
|
|
1451
3089
|
|
|
1452
|
-
|
|
3090
|
+
}
|
|
1453
3091
|
|
|
1454
|
-
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
/**
|
|
3095
|
+
* Renders the objects from the given render list.
|
|
3096
|
+
*
|
|
3097
|
+
* @private
|
|
3098
|
+
* @param {Array<Object>} renderList - The render list.
|
|
3099
|
+
* @param {Camera} camera - The camera the render list should be rendered with.
|
|
3100
|
+
* @param {Scene} scene - The scene the render list belongs to.
|
|
3101
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
3102
|
+
* @param {?string} [passId=null] - An optional ID for identifying the pass.
|
|
3103
|
+
*/
|
|
3104
|
+
_renderObjects( renderList, camera, scene, lightsNode, passId = null ) {
|
|
3105
|
+
|
|
3106
|
+
for ( let i = 0, il = renderList.length; i < il; i ++ ) {
|
|
3107
|
+
|
|
3108
|
+
const { object, geometry, material, group, clippingContext } = renderList[ i ];
|
|
3109
|
+
|
|
3110
|
+
this._currentRenderObjectFunction( object, scene, camera, geometry, material, group, lightsNode, clippingContext, passId );
|
|
1455
3111
|
|
|
1456
3112
|
}
|
|
1457
3113
|
|
|
1458
3114
|
}
|
|
1459
3115
|
|
|
1460
|
-
|
|
3116
|
+
/**
|
|
3117
|
+
* Retrieves shadow nodes for the given material. This is used to setup shadow passes.
|
|
3118
|
+
* The result is cached per material and updated when the material's version changes.
|
|
3119
|
+
*
|
|
3120
|
+
* @private
|
|
3121
|
+
* @param {Material} material
|
|
3122
|
+
* @returns {Object} - The shadow nodes for the material.
|
|
3123
|
+
*/
|
|
3124
|
+
_getShadowNodes( material ) {
|
|
1461
3125
|
|
|
1462
|
-
|
|
1463
|
-
let overrideFragmentNode;
|
|
1464
|
-
let overrideDepthNode;
|
|
3126
|
+
const version = material.version;
|
|
1465
3127
|
|
|
1466
|
-
|
|
3128
|
+
let cache = this._cacheShadowNodes.get( material );
|
|
1467
3129
|
|
|
1468
|
-
|
|
3130
|
+
if ( cache === undefined || cache.version !== version ) {
|
|
1469
3131
|
|
|
1470
|
-
|
|
3132
|
+
const hasMap = material.map !== null;
|
|
3133
|
+
const hasColorNode = material.colorNode && material.colorNode.isNode;
|
|
3134
|
+
const hasCastShadowNode = material.castShadowNode && material.castShadowNode.isNode;
|
|
3135
|
+
const hasMaskNode = ( material.maskShadowNode && material.maskShadowNode.isNode ) || ( material.maskNode && material.maskNode.isNode );
|
|
1471
3136
|
|
|
1472
|
-
|
|
3137
|
+
let positionNode = null;
|
|
3138
|
+
let colorNode = null;
|
|
3139
|
+
let depthNode = null;
|
|
1473
3140
|
|
|
1474
|
-
|
|
3141
|
+
if ( hasMap || hasColorNode || hasCastShadowNode || hasMaskNode ) {
|
|
1475
3142
|
|
|
1476
|
-
|
|
3143
|
+
let shadowRGB;
|
|
3144
|
+
let shadowAlpha;
|
|
1477
3145
|
|
|
1478
|
-
|
|
3146
|
+
if ( hasCastShadowNode ) {
|
|
1479
3147
|
|
|
1480
|
-
|
|
1481
|
-
|
|
3148
|
+
shadowRGB = material.castShadowNode.rgb;
|
|
3149
|
+
shadowAlpha = material.castShadowNode.a;
|
|
1482
3150
|
|
|
1483
|
-
|
|
3151
|
+
if ( this.shadowMap.transmitted !== true ) {
|
|
1484
3152
|
|
|
1485
|
-
|
|
3153
|
+
warnOnce( 'Renderer: `shadowMap.transmitted` needs to be set to `true` when using `material.castShadowNode`.' );
|
|
1486
3154
|
|
|
1487
|
-
|
|
3155
|
+
}
|
|
1488
3156
|
|
|
1489
|
-
|
|
3157
|
+
} else {
|
|
1490
3158
|
|
|
1491
|
-
|
|
1492
|
-
|
|
3159
|
+
shadowRGB = vec3( 0 );
|
|
3160
|
+
shadowAlpha = float( 1 );
|
|
1493
3161
|
|
|
1494
3162
|
}
|
|
1495
3163
|
|
|
3164
|
+
if ( hasMap ) {
|
|
1496
3165
|
|
|
1497
|
-
|
|
3166
|
+
shadowAlpha = shadowAlpha.mul( reference( 'map', 'texture', material ).a );
|
|
1498
3167
|
|
|
1499
|
-
|
|
1500
|
-
|
|
3168
|
+
}
|
|
3169
|
+
|
|
3170
|
+
if ( hasColorNode ) {
|
|
3171
|
+
|
|
3172
|
+
shadowAlpha = shadowAlpha.mul( material.colorNode.a );
|
|
1501
3173
|
|
|
1502
3174
|
}
|
|
1503
3175
|
|
|
1504
|
-
|
|
3176
|
+
colorNode = vec4( shadowRGB, shadowAlpha );
|
|
1505
3177
|
|
|
1506
|
-
|
|
3178
|
+
if ( hasMaskNode ) {
|
|
1507
3179
|
|
|
1508
|
-
|
|
3180
|
+
const maskNode = material.maskShadowNode || material.maskNode;
|
|
1509
3181
|
|
|
1510
|
-
|
|
1511
|
-
overrideMaterial.needsUpdate = true;
|
|
3182
|
+
colorNode = Fn( ( [ color ] ) => {
|
|
1512
3183
|
|
|
1513
|
-
|
|
3184
|
+
maskNode.not().discard();
|
|
1514
3185
|
|
|
1515
|
-
|
|
3186
|
+
return color;
|
|
1516
3187
|
|
|
1517
|
-
|
|
3188
|
+
} )( colorNode );
|
|
1518
3189
|
|
|
1519
|
-
|
|
3190
|
+
}
|
|
1520
3191
|
|
|
1521
|
-
|
|
3192
|
+
}
|
|
1522
3193
|
|
|
1523
|
-
|
|
1524
|
-
overrideMaterial.needsUpdate = true;
|
|
3194
|
+
if ( material.depthNode && material.depthNode.isNode ) {
|
|
1525
3195
|
|
|
1526
|
-
|
|
3196
|
+
depthNode = material.depthNode;
|
|
3197
|
+
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
if ( material.castShadowPositionNode && material.castShadowPositionNode.isNode ) {
|
|
3201
|
+
|
|
3202
|
+
positionNode = material.castShadowPositionNode;
|
|
3203
|
+
|
|
3204
|
+
} else if ( material.positionNode && material.positionNode.isNode ) {
|
|
3205
|
+
|
|
3206
|
+
positionNode = material.positionNode;
|
|
3207
|
+
|
|
3208
|
+
}
|
|
3209
|
+
|
|
3210
|
+
cache = {
|
|
3211
|
+
version,
|
|
3212
|
+
colorNode,
|
|
3213
|
+
depthNode,
|
|
3214
|
+
positionNode
|
|
3215
|
+
};
|
|
3216
|
+
|
|
3217
|
+
this._cacheShadowNodes.set( material, cache );
|
|
3218
|
+
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
return cache;
|
|
3222
|
+
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
/**
|
|
3226
|
+
* This method represents the default render object function that manages the render lifecycle
|
|
3227
|
+
* of the object.
|
|
3228
|
+
*
|
|
3229
|
+
* @param {Object3D} object - The 3D object.
|
|
3230
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
3231
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
3232
|
+
* @param {BufferGeometry} geometry - The object's geometry.
|
|
3233
|
+
* @param {Material} material - The object's material.
|
|
3234
|
+
* @param {?Object} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
3235
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
3236
|
+
* @param {?ClippingContext} clippingContext - The clipping context.
|
|
3237
|
+
* @param {?string} [passId=null] - An optional ID for identifying the pass.
|
|
3238
|
+
*/
|
|
3239
|
+
renderObject( object, scene, camera, geometry, material, group, lightsNode, clippingContext = null, passId = null ) {
|
|
3240
|
+
|
|
3241
|
+
let materialOverride = false;
|
|
3242
|
+
let materialColorNode;
|
|
3243
|
+
let materialDepthNode;
|
|
3244
|
+
let materialPositionNode;
|
|
3245
|
+
let materialSide;
|
|
3246
|
+
|
|
3247
|
+
//
|
|
3248
|
+
|
|
3249
|
+
object.onBeforeRender( this, scene, camera, geometry, material, group );
|
|
3250
|
+
|
|
3251
|
+
material.onBeforeRender( this, scene, camera, geometry, material, group );
|
|
3252
|
+
|
|
3253
|
+
//
|
|
3254
|
+
|
|
3255
|
+
if ( material.allowOverride === true && scene.overrideMaterial !== null ) {
|
|
3256
|
+
|
|
3257
|
+
const overrideMaterial = scene.overrideMaterial;
|
|
3258
|
+
|
|
3259
|
+
materialOverride = true;
|
|
3260
|
+
|
|
3261
|
+
// store original nodes
|
|
3262
|
+
materialColorNode = ( overrideMaterial.isNodeMaterial ) ? overrideMaterial.colorNode : null;
|
|
3263
|
+
materialDepthNode = ( overrideMaterial.isNodeMaterial ) ? overrideMaterial.depthNode : null;
|
|
3264
|
+
materialPositionNode = ( overrideMaterial.isNodeMaterial ) ? overrideMaterial.positionNode : null;
|
|
3265
|
+
materialSide = scene.overrideMaterial.side;
|
|
3266
|
+
|
|
3267
|
+
if ( material.positionNode && material.positionNode.isNode ) {
|
|
3268
|
+
|
|
3269
|
+
overrideMaterial.positionNode = material.positionNode;
|
|
3270
|
+
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
overrideMaterial.alphaTest = material.alphaTest;
|
|
3274
|
+
overrideMaterial.alphaMap = material.alphaMap;
|
|
3275
|
+
overrideMaterial.transparent = material.transparent || material.transmission > 0 ||
|
|
3276
|
+
( material.transmissionNode && material.transmissionNode.isNode ) ||
|
|
3277
|
+
( material.backdropNode && material.backdropNode.isNode );
|
|
3278
|
+
|
|
3279
|
+
if ( overrideMaterial.isShadowPassMaterial ) {
|
|
3280
|
+
|
|
3281
|
+
const { colorNode, depthNode, positionNode } = this._getShadowNodes( material );
|
|
3282
|
+
|
|
3283
|
+
if ( this.shadowMap.type === VSMShadowMap ) {
|
|
3284
|
+
|
|
3285
|
+
overrideMaterial.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
|
|
3286
|
+
|
|
3287
|
+
} else {
|
|
3288
|
+
|
|
3289
|
+
overrideMaterial.side = ( material.shadowSide !== null ) ? material.shadowSide : _shadowSide[ material.side ];
|
|
1527
3290
|
|
|
1528
3291
|
}
|
|
1529
3292
|
|
|
3293
|
+
if ( colorNode !== null ) overrideMaterial.colorNode = colorNode;
|
|
3294
|
+
if ( depthNode !== null ) overrideMaterial.depthNode = depthNode;
|
|
3295
|
+
if ( positionNode !== null ) overrideMaterial.positionNode = positionNode;
|
|
3296
|
+
|
|
1530
3297
|
}
|
|
1531
3298
|
|
|
1532
3299
|
material = overrideMaterial;
|
|
@@ -1538,51 +3305,79 @@ class Renderer {
|
|
|
1538
3305
|
if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
|
|
1539
3306
|
|
|
1540
3307
|
material.side = BackSide;
|
|
1541
|
-
this._handleObjectFunction( object, material, scene, camera, lightsNode, group, 'backSide' ); // create backSide pass id
|
|
3308
|
+
this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, 'backSide' ); // create backSide pass id
|
|
1542
3309
|
|
|
1543
3310
|
material.side = FrontSide;
|
|
1544
|
-
this._handleObjectFunction( object, material, scene, camera, lightsNode, group ); // use default pass id
|
|
3311
|
+
this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, passId ); // use default pass id
|
|
1545
3312
|
|
|
1546
3313
|
material.side = DoubleSide;
|
|
1547
3314
|
|
|
1548
3315
|
} else {
|
|
1549
3316
|
|
|
1550
|
-
this._handleObjectFunction( object, material, scene, camera, lightsNode, group );
|
|
3317
|
+
this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, passId );
|
|
1551
3318
|
|
|
1552
3319
|
}
|
|
1553
3320
|
|
|
1554
3321
|
//
|
|
1555
3322
|
|
|
1556
|
-
if (
|
|
3323
|
+
if ( materialOverride ) {
|
|
1557
3324
|
|
|
1558
|
-
scene.overrideMaterial.
|
|
3325
|
+
scene.overrideMaterial.colorNode = materialColorNode;
|
|
3326
|
+
scene.overrideMaterial.depthNode = materialDepthNode;
|
|
3327
|
+
scene.overrideMaterial.positionNode = materialPositionNode;
|
|
3328
|
+
scene.overrideMaterial.side = materialSide;
|
|
1559
3329
|
|
|
1560
3330
|
}
|
|
1561
3331
|
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
scene.overrideMaterial.depthNode = overrideDepthNode;
|
|
1565
|
-
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
if ( overrideFragmentNode !== undefined ) {
|
|
3332
|
+
//
|
|
1569
3333
|
|
|
1570
|
-
|
|
3334
|
+
object.onAfterRender( this, scene, camera, geometry, material, group );
|
|
1571
3335
|
|
|
1572
|
-
|
|
3336
|
+
}
|
|
1573
3337
|
|
|
1574
|
-
|
|
3338
|
+
/**
|
|
3339
|
+
* Checks if the given compatibility is supported by the selected backend. If the
|
|
3340
|
+
* renderer has not been initialized, this method always returns `false`.
|
|
3341
|
+
*
|
|
3342
|
+
* @param {string} name - The compatibility's name.
|
|
3343
|
+
* @return {boolean} Whether the compatibility is supported or not.
|
|
3344
|
+
*/
|
|
3345
|
+
hasCompatibility( name ) {
|
|
1575
3346
|
|
|
1576
|
-
|
|
3347
|
+
return this.backend.hasCompatibility( name );
|
|
1577
3348
|
|
|
1578
3349
|
}
|
|
1579
3350
|
|
|
1580
|
-
|
|
3351
|
+
/**
|
|
3352
|
+
* This method represents the default `_handleObjectFunction` implementation which creates
|
|
3353
|
+
* a render object from the given data and performs the draw command with the selected backend.
|
|
3354
|
+
*
|
|
3355
|
+
* @private
|
|
3356
|
+
* @param {Object3D} object - The 3D object.
|
|
3357
|
+
* @param {Material} material - The object's material.
|
|
3358
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
3359
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
3360
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
3361
|
+
* @param {?{start: number, count: number}} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
3362
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
3363
|
+
* @param {string} [passId] - An optional ID for identifying the pass.
|
|
3364
|
+
*/
|
|
3365
|
+
_renderObjectDirect( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
|
|
1581
3366
|
|
|
1582
|
-
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, passId );
|
|
3367
|
+
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId );
|
|
1583
3368
|
renderObject.drawRange = object.geometry.drawRange;
|
|
1584
3369
|
renderObject.group = group;
|
|
1585
3370
|
|
|
3371
|
+
if ( this._currentRenderBundle !== null ) {
|
|
3372
|
+
|
|
3373
|
+
const renderBundleData = this.backend.get( this._currentRenderBundle );
|
|
3374
|
+
|
|
3375
|
+
renderBundleData.renderObjects.push( renderObject );
|
|
3376
|
+
|
|
3377
|
+
renderObject.bundle = this._currentRenderBundle.bundleGroup;
|
|
3378
|
+
|
|
3379
|
+
}
|
|
3380
|
+
|
|
1586
3381
|
//
|
|
1587
3382
|
|
|
1588
3383
|
const needsRefresh = this._nodes.needsRefresh( renderObject );
|
|
@@ -1602,25 +3397,31 @@ class Renderer {
|
|
|
1602
3397
|
|
|
1603
3398
|
//
|
|
1604
3399
|
|
|
1605
|
-
if ( this._currentRenderBundle !== null ) {
|
|
1606
|
-
|
|
1607
|
-
const renderBundleData = this.backend.get( this._currentRenderBundle );
|
|
1608
|
-
|
|
1609
|
-
renderBundleData.renderObjects.push( renderObject );
|
|
1610
|
-
|
|
1611
|
-
renderObject.bundle = this._currentRenderBundle.scene;
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
3400
|
this.backend.draw( renderObject, this.info );
|
|
1616
3401
|
|
|
1617
3402
|
if ( needsRefresh ) this._nodes.updateAfter( renderObject );
|
|
1618
3403
|
|
|
1619
3404
|
}
|
|
1620
3405
|
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
3406
|
+
/**
|
|
3407
|
+
* A different implementation for `_handleObjectFunction` which only makes sure the object is ready for rendering.
|
|
3408
|
+
* Used in `compileAsync()`.
|
|
3409
|
+
*
|
|
3410
|
+
* @private
|
|
3411
|
+
* @param {Object3D} object - The 3D object.
|
|
3412
|
+
* @param {Material} material - The object's material.
|
|
3413
|
+
* @param {Scene} scene - The scene the 3D object belongs to.
|
|
3414
|
+
* @param {Camera} camera - The camera the object should be rendered with.
|
|
3415
|
+
* @param {LightsNode} lightsNode - The current lights node.
|
|
3416
|
+
* @param {?{start: number, count: number}} group - Only relevant for objects using multiple materials. This represents a group entry from the respective `BufferGeometry`.
|
|
3417
|
+
* @param {ClippingContext} clippingContext - The clipping context.
|
|
3418
|
+
* @param {string} [passId] - An optional ID for identifying the pass.
|
|
3419
|
+
*/
|
|
3420
|
+
_createObjectPipeline( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
|
|
3421
|
+
|
|
3422
|
+
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId );
|
|
3423
|
+
renderObject.drawRange = object.geometry.drawRange;
|
|
3424
|
+
renderObject.group = group;
|
|
1624
3425
|
|
|
1625
3426
|
//
|
|
1626
3427
|
|
|
@@ -1637,12 +3438,26 @@ class Renderer {
|
|
|
1637
3438
|
|
|
1638
3439
|
}
|
|
1639
3440
|
|
|
1640
|
-
|
|
3441
|
+
/**
|
|
3442
|
+
* Callback when the canvas has been resized.
|
|
3443
|
+
*
|
|
3444
|
+
* @private
|
|
3445
|
+
*/
|
|
3446
|
+
_onCanvasTargetResize() {
|
|
1641
3447
|
|
|
1642
|
-
|
|
3448
|
+
if ( this._initialized ) this.backend.updateSize();
|
|
1643
3449
|
|
|
1644
3450
|
}
|
|
1645
3451
|
|
|
3452
|
+
/**
|
|
3453
|
+
* Alias for `compileAsync()`.
|
|
3454
|
+
*
|
|
3455
|
+
* @method
|
|
3456
|
+
* @param {Object3D} scene - The scene or 3D object to precompile.
|
|
3457
|
+
* @param {Camera} camera - The camera that is used to render the scene.
|
|
3458
|
+
* @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.
|
|
3459
|
+
* @return {function(Object3D, Camera, ?Scene): Promise|undefined} A Promise that resolves when the compile has been finished.
|
|
3460
|
+
*/
|
|
1646
3461
|
get compile() {
|
|
1647
3462
|
|
|
1648
3463
|
return this.compileAsync;
|
|
@@ -1651,4 +3466,12 @@ class Renderer {
|
|
|
1651
3466
|
|
|
1652
3467
|
}
|
|
1653
3468
|
|
|
3469
|
+
/**
|
|
3470
|
+
* Animation loop parameter of `renderer.setAnimationLoop()`.
|
|
3471
|
+
*
|
|
3472
|
+
* @callback onAnimationCallback
|
|
3473
|
+
* @param {DOMHighResTimeStamp} time - A timestamp indicating the end time of the previous frame's rendering.
|
|
3474
|
+
* @param {XRFrame} [frame] - A reference to the current XR frame. Only relevant when using XR rendering.
|
|
3475
|
+
*/
|
|
3476
|
+
|
|
1654
3477
|
export default Renderer;
|