@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
|
@@ -5,43 +5,38 @@ import NodeVar from './NodeVar.js';
|
|
|
5
5
|
import NodeCode from './NodeCode.js';
|
|
6
6
|
import NodeCache from './NodeCache.js';
|
|
7
7
|
import ParameterNode from './ParameterNode.js';
|
|
8
|
+
import StructType from './StructType.js';
|
|
8
9
|
import FunctionNode from '../code/FunctionNode.js';
|
|
9
10
|
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
11
|
+
import { getDataFromObject, getTypeFromLength, hashString } from './NodeUtils.js';
|
|
10
12
|
import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';
|
|
11
13
|
|
|
12
14
|
import {
|
|
13
15
|
NumberNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
|
|
14
|
-
ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
|
|
16
|
+
ColorNodeUniform, Matrix2NodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
|
|
15
17
|
} from '../../renderers/common/nodes/NodeUniform.js';
|
|
16
18
|
|
|
17
19
|
import { stack } from './StackNode.js';
|
|
18
20
|
import { getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';
|
|
19
21
|
|
|
20
22
|
import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';
|
|
21
|
-
import ChainMap from '../../renderers/common/ChainMap.js';
|
|
22
|
-
|
|
23
|
-
import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js';
|
|
24
23
|
|
|
25
24
|
import BindGroup from '../../renderers/common/BindGroup.js';
|
|
26
25
|
|
|
27
|
-
import { REVISION } from '../../constants.js';
|
|
26
|
+
import { REVISION, IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter, NormalBlending } from '../../constants.js';
|
|
28
27
|
import { RenderTarget } from '../../core/RenderTarget.js';
|
|
29
28
|
import { Color } from '../../math/Color.js';
|
|
30
29
|
import { Vector2 } from '../../math/Vector2.js';
|
|
31
30
|
import { Vector3 } from '../../math/Vector3.js';
|
|
32
31
|
import { Vector4 } from '../../math/Vector4.js';
|
|
33
32
|
import { Float16BufferAttribute } from '../../core/BufferAttribute.js';
|
|
34
|
-
import {
|
|
33
|
+
import { warn, error } from '../../utils.js';
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
let _id = 0;
|
|
37
36
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
[ 4, 'vec4' ],
|
|
42
|
-
[ 9, 'mat3' ],
|
|
43
|
-
[ 16, 'mat4' ]
|
|
44
|
-
] );
|
|
37
|
+
const _bindingGroupsCache = new WeakMap();
|
|
38
|
+
|
|
39
|
+
const sharedNodeData = new WeakMap();
|
|
45
40
|
|
|
46
41
|
const typeFromArray = new Map( [
|
|
47
42
|
[ Int8Array, 'int' ],
|
|
@@ -55,135 +50,524 @@ const typeFromArray = new Map( [
|
|
|
55
50
|
|
|
56
51
|
const toFloat = ( value ) => {
|
|
57
52
|
|
|
58
|
-
|
|
53
|
+
if ( /e/g.test( value ) ) {
|
|
54
|
+
|
|
55
|
+
return String( value ).replace( /\+/g, '' );
|
|
56
|
+
|
|
57
|
+
} else {
|
|
58
|
+
|
|
59
|
+
value = Number( value );
|
|
60
|
+
|
|
61
|
+
return value + ( value % 1 ? '' : '.0' );
|
|
59
62
|
|
|
60
|
-
|
|
63
|
+
}
|
|
61
64
|
|
|
62
65
|
};
|
|
63
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Base class for builders which generate a shader program based
|
|
69
|
+
* on a 3D object and its node material definition.
|
|
70
|
+
*/
|
|
64
71
|
class NodeBuilder {
|
|
65
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Constructs a new node builder.
|
|
75
|
+
*
|
|
76
|
+
* @param {Object3D} object - The 3D object.
|
|
77
|
+
* @param {Renderer} renderer - The current renderer.
|
|
78
|
+
* @param {NodeParser} parser - A reference to a node parser.
|
|
79
|
+
*/
|
|
66
80
|
constructor( object, renderer, parser ) {
|
|
67
81
|
|
|
82
|
+
/**
|
|
83
|
+
* The 3D object.
|
|
84
|
+
*
|
|
85
|
+
* @type {Object3D}
|
|
86
|
+
*/
|
|
68
87
|
this.object = object;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The material of the 3D object.
|
|
91
|
+
*
|
|
92
|
+
* @type {?Material}
|
|
93
|
+
*/
|
|
69
94
|
this.material = ( object && object.material ) || null;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The geometry of the 3D object.
|
|
98
|
+
*
|
|
99
|
+
* @type {?BufferGeometry}
|
|
100
|
+
*/
|
|
70
101
|
this.geometry = ( object && object.geometry ) || null;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The current renderer.
|
|
105
|
+
*
|
|
106
|
+
* @type {Renderer}
|
|
107
|
+
*/
|
|
71
108
|
this.renderer = renderer;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A reference to a node parser.
|
|
112
|
+
*
|
|
113
|
+
* @type {NodeParser}
|
|
114
|
+
*/
|
|
72
115
|
this.parser = parser;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The scene the 3D object belongs to.
|
|
119
|
+
*
|
|
120
|
+
* @type {?Scene}
|
|
121
|
+
* @default null
|
|
122
|
+
*/
|
|
73
123
|
this.scene = null;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The camera the 3D object is rendered with.
|
|
127
|
+
*
|
|
128
|
+
* @type {?Camera}
|
|
129
|
+
* @default null
|
|
130
|
+
*/
|
|
74
131
|
this.camera = null;
|
|
75
132
|
|
|
133
|
+
/**
|
|
134
|
+
* A list of all nodes the builder is processing
|
|
135
|
+
* for this 3D object.
|
|
136
|
+
*
|
|
137
|
+
* @type {Array<Node>}
|
|
138
|
+
*/
|
|
76
139
|
this.nodes = [];
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A list of all nodes the builder is processing in sequential order.
|
|
143
|
+
*
|
|
144
|
+
* This is used to determine the update order of nodes, which is important for
|
|
145
|
+
* {@link NodeUpdateType#UPDATE_BEFORE} and {@link NodeUpdateType#UPDATE_AFTER}.
|
|
146
|
+
*
|
|
147
|
+
* @type {Array<Node>}
|
|
148
|
+
*/
|
|
149
|
+
this.sequentialNodes = [];
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A list of all nodes which {@link Node#update} method should be executed.
|
|
153
|
+
*
|
|
154
|
+
* @type {Array<Node>}
|
|
155
|
+
*/
|
|
77
156
|
this.updateNodes = [];
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A list of all nodes which {@link Node#updateBefore} method should be executed.
|
|
160
|
+
*
|
|
161
|
+
* @type {Array<Node>}
|
|
162
|
+
*/
|
|
78
163
|
this.updateBeforeNodes = [];
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A list of all nodes which {@link Node#updateAfter} method should be executed.
|
|
167
|
+
*
|
|
168
|
+
* @type {Array<Node>}
|
|
169
|
+
*/
|
|
79
170
|
this.updateAfterNodes = [];
|
|
80
|
-
this.hashNodes = {};
|
|
81
171
|
|
|
82
|
-
|
|
172
|
+
/**
|
|
173
|
+
* A dictionary that assigns each node to a unique hash.
|
|
174
|
+
*
|
|
175
|
+
* @type {Object<number,Node>}
|
|
176
|
+
*/
|
|
177
|
+
this.hashNodes = {};
|
|
83
178
|
|
|
179
|
+
/**
|
|
180
|
+
* A reference to a node material observer.
|
|
181
|
+
*
|
|
182
|
+
* @type {?NodeMaterialObserver}
|
|
183
|
+
* @default null
|
|
184
|
+
*/
|
|
185
|
+
this.observer = null;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* A reference to the current lights node.
|
|
189
|
+
*
|
|
190
|
+
* @type {?LightsNode}
|
|
191
|
+
* @default null
|
|
192
|
+
*/
|
|
84
193
|
this.lightsNode = null;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* A reference to the current environment node.
|
|
197
|
+
*
|
|
198
|
+
* @type {?Node}
|
|
199
|
+
* @default null
|
|
200
|
+
*/
|
|
85
201
|
this.environmentNode = null;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* A reference to the current fog node.
|
|
205
|
+
*
|
|
206
|
+
* @type {?Node}
|
|
207
|
+
* @default null
|
|
208
|
+
*/
|
|
86
209
|
this.fogNode = null;
|
|
87
210
|
|
|
211
|
+
/**
|
|
212
|
+
* The current clipping context.
|
|
213
|
+
*
|
|
214
|
+
* @type {?ClippingContext}
|
|
215
|
+
*/
|
|
88
216
|
this.clippingContext = null;
|
|
89
217
|
|
|
218
|
+
/**
|
|
219
|
+
* The generated vertex shader.
|
|
220
|
+
*
|
|
221
|
+
* @type {?string}
|
|
222
|
+
*/
|
|
90
223
|
this.vertexShader = null;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The generated fragment shader.
|
|
227
|
+
*
|
|
228
|
+
* @type {?string}
|
|
229
|
+
*/
|
|
91
230
|
this.fragmentShader = null;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The generated compute shader.
|
|
234
|
+
*
|
|
235
|
+
* @type {?string}
|
|
236
|
+
*/
|
|
92
237
|
this.computeShader = null;
|
|
93
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Nodes used in the primary flow of code generation.
|
|
241
|
+
*
|
|
242
|
+
* @type {Object<string,Array<Node>>}
|
|
243
|
+
*/
|
|
94
244
|
this.flowNodes = { vertex: [], fragment: [], compute: [] };
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Nodes code from `.flowNodes`.
|
|
248
|
+
*
|
|
249
|
+
* @type {Object<string,string>}
|
|
250
|
+
*/
|
|
95
251
|
this.flowCode = { vertex: '', fragment: '', compute: '' };
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* This dictionary holds the node uniforms of the builder.
|
|
255
|
+
* The uniforms are maintained in an array for each shader stage.
|
|
256
|
+
*
|
|
257
|
+
* @type {Object}
|
|
258
|
+
*/
|
|
96
259
|
this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* This dictionary holds the output structs of the builder.
|
|
263
|
+
* The structs are maintained in an array for each shader stage.
|
|
264
|
+
*
|
|
265
|
+
* @type {Object}
|
|
266
|
+
*/
|
|
97
267
|
this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* This dictionary holds the types of the builder.
|
|
271
|
+
*
|
|
272
|
+
* @type {Object}
|
|
273
|
+
*/
|
|
274
|
+
this.types = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* This dictionary holds the bindings for each shader stage.
|
|
278
|
+
*
|
|
279
|
+
* @type {Object}
|
|
280
|
+
*/
|
|
98
281
|
this.bindings = { vertex: {}, fragment: {}, compute: {} };
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* This dictionary maintains the binding indices per bind group.
|
|
285
|
+
*
|
|
286
|
+
* @type {Object}
|
|
287
|
+
*/
|
|
99
288
|
this.bindingsIndexes = {};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Reference to the array of bind groups.
|
|
292
|
+
*
|
|
293
|
+
* @type {?Array<BindGroup>}
|
|
294
|
+
*/
|
|
100
295
|
this.bindGroups = null;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* This array holds the node attributes of this builder
|
|
299
|
+
* created via {@link AttributeNode}.
|
|
300
|
+
*
|
|
301
|
+
* @type {Array<NodeAttribute>}
|
|
302
|
+
*/
|
|
101
303
|
this.attributes = [];
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* This array holds the node attributes of this builder
|
|
307
|
+
* created via {@link BufferAttributeNode}.
|
|
308
|
+
*
|
|
309
|
+
* @type {Array<NodeAttribute>}
|
|
310
|
+
*/
|
|
102
311
|
this.bufferAttributes = [];
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* This array holds the node varyings of this builder.
|
|
315
|
+
*
|
|
316
|
+
* @type {Array<NodeVarying>}
|
|
317
|
+
*/
|
|
103
318
|
this.varyings = [];
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* This dictionary holds the (native) node codes of this builder.
|
|
322
|
+
* The codes are maintained in an array for each shader stage.
|
|
323
|
+
*
|
|
324
|
+
* @type {Object<string,Array<NodeCode>>}
|
|
325
|
+
*/
|
|
104
326
|
this.codes = {};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* This dictionary holds the node variables of this builder.
|
|
330
|
+
* The variables are maintained in an array for each shader stage.
|
|
331
|
+
* This dictionary is also used to count the number of variables
|
|
332
|
+
* according to their type (const, vars).
|
|
333
|
+
*
|
|
334
|
+
* @type {Object<string,Array<NodeVar>|number>}
|
|
335
|
+
*/
|
|
105
336
|
this.vars = {};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* This dictionary holds the declarations for each shader stage.
|
|
340
|
+
*
|
|
341
|
+
* @type {Object}
|
|
342
|
+
*/
|
|
343
|
+
this.declarations = {};
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Current code flow.
|
|
347
|
+
* All code generated in this stack will be stored in `.flow`.
|
|
348
|
+
*
|
|
349
|
+
* @type {{code: string}}
|
|
350
|
+
*/
|
|
106
351
|
this.flow = { code: '' };
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* A chain of nodes.
|
|
355
|
+
* Used to check recursive calls in node-graph.
|
|
356
|
+
*
|
|
357
|
+
* @type {Array<Node>}
|
|
358
|
+
*/
|
|
107
359
|
this.chaining = [];
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* The current stack.
|
|
363
|
+
* This reflects the current process in the code block hierarchy,
|
|
364
|
+
* it is useful to know if the current process is inside a conditional for example.
|
|
365
|
+
*
|
|
366
|
+
* @type {StackNode}
|
|
367
|
+
*/
|
|
108
368
|
this.stack = stack();
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* List of stack nodes.
|
|
372
|
+
* The current stack hierarchy is stored in an array.
|
|
373
|
+
*
|
|
374
|
+
* @type {Array<StackNode>}
|
|
375
|
+
*/
|
|
109
376
|
this.stacks = [];
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* A tab value. Used for shader string generation.
|
|
380
|
+
*
|
|
381
|
+
* @type {string}
|
|
382
|
+
* @default '\t'
|
|
383
|
+
*/
|
|
110
384
|
this.tab = '\t';
|
|
111
385
|
|
|
386
|
+
/**
|
|
387
|
+
* Reference to the current function node.
|
|
388
|
+
*
|
|
389
|
+
* @type {?FunctionNode}
|
|
390
|
+
* @default null
|
|
391
|
+
*/
|
|
112
392
|
this.currentFunctionNode = null;
|
|
113
393
|
|
|
394
|
+
/**
|
|
395
|
+
* The builder's context.
|
|
396
|
+
*
|
|
397
|
+
* @type {Object}
|
|
398
|
+
*/
|
|
114
399
|
this.context = {
|
|
115
400
|
material: this.material
|
|
116
401
|
};
|
|
117
402
|
|
|
403
|
+
/**
|
|
404
|
+
* The builder's cache.
|
|
405
|
+
*
|
|
406
|
+
* @type {NodeCache}
|
|
407
|
+
*/
|
|
118
408
|
this.cache = new NodeCache();
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Since the {@link NodeBuilder#cache} might be temporarily
|
|
412
|
+
* overwritten by other caches, this member retains the reference
|
|
413
|
+
* to the builder's own cache.
|
|
414
|
+
*
|
|
415
|
+
* @type {NodeCache}
|
|
416
|
+
* @default this.cache
|
|
417
|
+
*/
|
|
119
418
|
this.globalCache = this.cache;
|
|
120
419
|
|
|
121
420
|
this.flowsData = new WeakMap();
|
|
122
421
|
|
|
422
|
+
/**
|
|
423
|
+
* The current shader stage.
|
|
424
|
+
*
|
|
425
|
+
* @type {?('vertex'|'fragment'|'compute'|'any')}
|
|
426
|
+
*/
|
|
123
427
|
this.shaderStage = null;
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* The current build stage.
|
|
431
|
+
*
|
|
432
|
+
* @type {?('setup'|'analyze'|'generate')}
|
|
433
|
+
*/
|
|
124
434
|
this.buildStage = null;
|
|
125
435
|
|
|
126
|
-
|
|
436
|
+
/**
|
|
437
|
+
* The sub-build layers.
|
|
438
|
+
*
|
|
439
|
+
* @type {Array<SubBuildNode>}
|
|
440
|
+
* @default []
|
|
441
|
+
*/
|
|
442
|
+
this.subBuildLayers = [];
|
|
127
443
|
|
|
128
|
-
}
|
|
129
444
|
|
|
130
|
-
|
|
445
|
+
/**
|
|
446
|
+
* The active stack nodes.
|
|
447
|
+
*
|
|
448
|
+
* @type {Array<StackNode>}
|
|
449
|
+
*/
|
|
450
|
+
this.activeStacks = [];
|
|
131
451
|
|
|
132
|
-
|
|
452
|
+
/**
|
|
453
|
+
* The current sub-build TSL function(Fn).
|
|
454
|
+
*
|
|
455
|
+
* @type {?string}
|
|
456
|
+
* @default null
|
|
457
|
+
*/
|
|
458
|
+
this.subBuildFn = null;
|
|
133
459
|
|
|
134
|
-
|
|
460
|
+
/**
|
|
461
|
+
* The current TSL function(Fn) call node.
|
|
462
|
+
*
|
|
463
|
+
* @type {?Node}
|
|
464
|
+
* @default null
|
|
465
|
+
*/
|
|
466
|
+
this.fnCall = null;
|
|
135
467
|
|
|
136
|
-
|
|
468
|
+
Object.defineProperty( this, 'id', { value: _id ++ } );
|
|
137
469
|
|
|
138
|
-
|
|
470
|
+
}
|
|
139
471
|
|
|
140
|
-
|
|
472
|
+
/**
|
|
473
|
+
* Whether the material is using flat shading or not.
|
|
474
|
+
*
|
|
475
|
+
* @returns {boolean} Whether the material is using flat shading or not.
|
|
476
|
+
*/
|
|
477
|
+
isFlatShading() {
|
|
141
478
|
|
|
142
|
-
return
|
|
479
|
+
return this.material.flatShading === true || this.geometry.hasAttribute( 'normal' ) === false;
|
|
143
480
|
|
|
144
481
|
}
|
|
145
482
|
|
|
146
|
-
|
|
483
|
+
/**
|
|
484
|
+
* Whether the material is opaque or not.
|
|
485
|
+
*
|
|
486
|
+
* @return {boolean} Whether the material is opaque or not.
|
|
487
|
+
*/
|
|
488
|
+
isOpaque() {
|
|
147
489
|
|
|
148
|
-
|
|
490
|
+
const material = this.material;
|
|
491
|
+
|
|
492
|
+
return material.transparent === false && material.blending === NormalBlending && material.alphaToCoverage === false;
|
|
149
493
|
|
|
150
494
|
}
|
|
151
495
|
|
|
152
|
-
|
|
496
|
+
/**
|
|
497
|
+
* Factory method for creating an instance of {@link RenderTarget} with the given
|
|
498
|
+
* dimensions and options.
|
|
499
|
+
*
|
|
500
|
+
* @param {number} width - The width of the render target.
|
|
501
|
+
* @param {number} height - The height of the render target.
|
|
502
|
+
* @param {Object} options - The options of the render target.
|
|
503
|
+
* @return {RenderTarget} The render target.
|
|
504
|
+
*/
|
|
505
|
+
createRenderTarget( width, height, options ) {
|
|
153
506
|
|
|
154
|
-
return new
|
|
507
|
+
return new RenderTarget( width, height, options );
|
|
155
508
|
|
|
156
509
|
}
|
|
157
510
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
511
|
+
/**
|
|
512
|
+
* Factory method for creating an instance of {@link CubeRenderTarget} with the given
|
|
513
|
+
* dimensions and options.
|
|
514
|
+
*
|
|
515
|
+
* @param {number} size - The size of the cube render target.
|
|
516
|
+
* @param {Object} options - The options of the cube render target.
|
|
517
|
+
* @return {CubeRenderTarget} The cube render target.
|
|
518
|
+
*/
|
|
519
|
+
createCubeRenderTarget( size, options ) {
|
|
161
520
|
|
|
162
|
-
return new
|
|
521
|
+
return new CubeRenderTarget( size, options );
|
|
163
522
|
|
|
164
523
|
}
|
|
165
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Whether the given node is included in the internal array of nodes or not.
|
|
527
|
+
*
|
|
528
|
+
* @param {Node} node - The node to test.
|
|
529
|
+
* @return {boolean} Whether the given node is included in the internal array of nodes or not.
|
|
530
|
+
*/
|
|
166
531
|
includes( node ) {
|
|
167
532
|
|
|
168
533
|
return this.nodes.includes( node );
|
|
169
534
|
|
|
170
535
|
}
|
|
171
536
|
|
|
537
|
+
/**
|
|
538
|
+
* Returns the output struct name which is required by
|
|
539
|
+
* {@link OutputStructNode}.
|
|
540
|
+
*
|
|
541
|
+
* @abstract
|
|
542
|
+
* @return {string} The name of the output struct.
|
|
543
|
+
*/
|
|
544
|
+
getOutputStructName() {}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Returns a bind group for the given group name and binding.
|
|
548
|
+
*
|
|
549
|
+
* @private
|
|
550
|
+
* @param {string} groupName - The group name.
|
|
551
|
+
* @param {Array<NodeUniformsGroup>} bindings - List of bindings.
|
|
552
|
+
* @return {BindGroup} The bind group
|
|
553
|
+
*/
|
|
172
554
|
_getBindGroup( groupName, bindings ) {
|
|
173
555
|
|
|
174
|
-
const
|
|
556
|
+
const groupNode = bindings[ 0 ].groupNode;
|
|
175
557
|
|
|
176
|
-
|
|
558
|
+
let sharedGroup = groupNode.shared;
|
|
177
559
|
|
|
178
|
-
|
|
560
|
+
if ( sharedGroup ) {
|
|
179
561
|
|
|
180
|
-
|
|
562
|
+
for ( let i = 1; i < bindings.length; i ++ ) {
|
|
181
563
|
|
|
182
|
-
|
|
564
|
+
if ( groupNode !== bindings[ i ].groupNode ) {
|
|
183
565
|
|
|
184
|
-
|
|
566
|
+
sharedGroup = false;
|
|
185
567
|
|
|
186
|
-
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
}
|
|
187
571
|
|
|
188
572
|
}
|
|
189
573
|
|
|
@@ -193,19 +577,59 @@ class NodeBuilder {
|
|
|
193
577
|
|
|
194
578
|
if ( sharedGroup ) {
|
|
195
579
|
|
|
196
|
-
|
|
580
|
+
let cacheKeyString = '';
|
|
581
|
+
|
|
582
|
+
for ( const binding of bindings ) {
|
|
583
|
+
|
|
584
|
+
if ( binding.isNodeUniformsGroup ) {
|
|
585
|
+
|
|
586
|
+
binding.uniforms.sort( ( a, b ) => a.nodeUniform.node.id - b.nodeUniform.node.id );
|
|
587
|
+
|
|
588
|
+
for ( const uniform of binding.uniforms ) {
|
|
589
|
+
|
|
590
|
+
cacheKeyString += uniform.nodeUniform.node.id;
|
|
591
|
+
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
} else {
|
|
595
|
+
|
|
596
|
+
cacheKeyString += binding.nodeUniform.id;
|
|
597
|
+
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// TODO: Remove this hack ._currentRenderContext
|
|
603
|
+
|
|
604
|
+
const currentContext = this.renderer._currentRenderContext || this.renderer; // use renderer as fallback until we have a compute context
|
|
605
|
+
|
|
606
|
+
let bindingGroupsCache = _bindingGroupsCache.get( currentContext );
|
|
607
|
+
|
|
608
|
+
if ( bindingGroupsCache === undefined ) {
|
|
609
|
+
|
|
610
|
+
bindingGroupsCache = new Map();
|
|
611
|
+
|
|
612
|
+
_bindingGroupsCache.set( currentContext, bindingGroupsCache );
|
|
613
|
+
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
//
|
|
617
|
+
|
|
618
|
+
const cacheKey = hashString( cacheKeyString );
|
|
619
|
+
|
|
620
|
+
bindGroup = bindingGroupsCache.get( cacheKey );
|
|
197
621
|
|
|
198
622
|
if ( bindGroup === undefined ) {
|
|
199
623
|
|
|
200
|
-
bindGroup = new BindGroup( groupName,
|
|
624
|
+
bindGroup = new BindGroup( groupName, bindings, this.bindingsIndexes[ groupName ].group );
|
|
201
625
|
|
|
202
|
-
|
|
626
|
+
bindingGroupsCache.set( cacheKey, bindGroup );
|
|
203
627
|
|
|
204
628
|
}
|
|
205
629
|
|
|
206
630
|
} else {
|
|
207
631
|
|
|
208
|
-
bindGroup = new BindGroup( groupName,
|
|
632
|
+
bindGroup = new BindGroup( groupName, bindings, this.bindingsIndexes[ groupName ].group );
|
|
209
633
|
|
|
210
634
|
}
|
|
211
635
|
|
|
@@ -213,6 +637,13 @@ class NodeBuilder {
|
|
|
213
637
|
|
|
214
638
|
}
|
|
215
639
|
|
|
640
|
+
/**
|
|
641
|
+
* Returns an array of node uniform groups for the given group name and shader stage.
|
|
642
|
+
*
|
|
643
|
+
* @param {string} groupName - The group name.
|
|
644
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
645
|
+
* @return {Array<NodeUniformsGroup>} The array of node uniform groups.
|
|
646
|
+
*/
|
|
216
647
|
getBindGroupArray( groupName, shaderStage ) {
|
|
217
648
|
|
|
218
649
|
const bindings = this.bindings[ shaderStage ];
|
|
@@ -235,6 +666,11 @@ class NodeBuilder {
|
|
|
235
666
|
|
|
236
667
|
}
|
|
237
668
|
|
|
669
|
+
/**
|
|
670
|
+
* Returns a list bindings of all shader stages separated by groups.
|
|
671
|
+
*
|
|
672
|
+
* @return {Array<BindGroup>} The list of bindings.
|
|
673
|
+
*/
|
|
238
674
|
getBindings() {
|
|
239
675
|
|
|
240
676
|
let bindingsGroups = this.bindGroups;
|
|
@@ -251,7 +687,16 @@ class NodeBuilder {
|
|
|
251
687
|
const uniforms = bindings[ shaderStage ][ groupName ];
|
|
252
688
|
|
|
253
689
|
const groupUniforms = groups[ groupName ] || ( groups[ groupName ] = [] );
|
|
254
|
-
|
|
690
|
+
|
|
691
|
+
for ( const uniform of uniforms ) {
|
|
692
|
+
|
|
693
|
+
if ( groupUniforms.includes( uniform ) === false ) {
|
|
694
|
+
|
|
695
|
+
groupUniforms.push( uniform );
|
|
696
|
+
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
}
|
|
255
700
|
|
|
256
701
|
}
|
|
257
702
|
|
|
@@ -277,6 +722,9 @@ class NodeBuilder {
|
|
|
277
722
|
|
|
278
723
|
}
|
|
279
724
|
|
|
725
|
+
/**
|
|
726
|
+
* Sorts the bind groups and updates {@link NodeBuilder#bindingsIndexes}.
|
|
727
|
+
*/
|
|
280
728
|
sortBindingGroups() {
|
|
281
729
|
|
|
282
730
|
const bindingsGroups = this.getBindings();
|
|
@@ -294,12 +742,24 @@ class NodeBuilder {
|
|
|
294
742
|
|
|
295
743
|
}
|
|
296
744
|
|
|
745
|
+
/**
|
|
746
|
+
* The builder maintains each node in a hash-based dictionary.
|
|
747
|
+
* This method sets the given node (value) with the given hash (key) into this dictionary.
|
|
748
|
+
*
|
|
749
|
+
* @param {Node} node - The node to add.
|
|
750
|
+
* @param {number} hash - The hash of the node.
|
|
751
|
+
*/
|
|
297
752
|
setHashNode( node, hash ) {
|
|
298
753
|
|
|
299
754
|
this.hashNodes[ hash ] = node;
|
|
300
755
|
|
|
301
756
|
}
|
|
302
757
|
|
|
758
|
+
/**
|
|
759
|
+
* Adds a node to this builder.
|
|
760
|
+
*
|
|
761
|
+
* @param {Node} node - The node to add.
|
|
762
|
+
*/
|
|
303
763
|
addNode( node ) {
|
|
304
764
|
|
|
305
765
|
if ( this.nodes.includes( node ) === false ) {
|
|
@@ -312,29 +772,61 @@ class NodeBuilder {
|
|
|
312
772
|
|
|
313
773
|
}
|
|
314
774
|
|
|
775
|
+
/**
|
|
776
|
+
* It is used to add Nodes that will be used as FRAME and RENDER events,
|
|
777
|
+
* and need to follow a certain sequence in the calls to work correctly.
|
|
778
|
+
* This function should be called after 'setup()' in the 'build()' process to ensure that the child nodes are processed first.
|
|
779
|
+
*
|
|
780
|
+
* @param {Node} node - The node to add.
|
|
781
|
+
*/
|
|
782
|
+
addSequentialNode( node ) {
|
|
783
|
+
|
|
784
|
+
const updateBeforeType = node.getUpdateBeforeType();
|
|
785
|
+
const updateAfterType = node.getUpdateAfterType();
|
|
786
|
+
|
|
787
|
+
if ( updateBeforeType !== NodeUpdateType.NONE || updateAfterType !== NodeUpdateType.NONE ) {
|
|
788
|
+
|
|
789
|
+
if ( this.sequentialNodes.includes( node ) === false ) {
|
|
790
|
+
|
|
791
|
+
this.sequentialNodes.push( node );
|
|
792
|
+
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Checks the update types of nodes
|
|
801
|
+
*/
|
|
315
802
|
buildUpdateNodes() {
|
|
316
803
|
|
|
317
804
|
for ( const node of this.nodes ) {
|
|
318
805
|
|
|
319
806
|
const updateType = node.getUpdateType();
|
|
320
|
-
const updateBeforeType = node.getUpdateBeforeType();
|
|
321
|
-
const updateAfterType = node.getUpdateAfterType();
|
|
322
807
|
|
|
323
808
|
if ( updateType !== NodeUpdateType.NONE ) {
|
|
324
809
|
|
|
325
|
-
this.updateNodes.push( node
|
|
810
|
+
this.updateNodes.push( node );
|
|
326
811
|
|
|
327
812
|
}
|
|
328
813
|
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
for ( const node of this.sequentialNodes ) {
|
|
817
|
+
|
|
818
|
+
const updateBeforeType = node.getUpdateBeforeType();
|
|
819
|
+
const updateAfterType = node.getUpdateAfterType();
|
|
820
|
+
|
|
329
821
|
if ( updateBeforeType !== NodeUpdateType.NONE ) {
|
|
330
822
|
|
|
331
|
-
this.updateBeforeNodes.push( node
|
|
823
|
+
this.updateBeforeNodes.push( node );
|
|
332
824
|
|
|
333
825
|
}
|
|
334
826
|
|
|
335
827
|
if ( updateAfterType !== NodeUpdateType.NONE ) {
|
|
336
828
|
|
|
337
|
-
this.updateAfterNodes.push( node
|
|
829
|
+
this.updateAfterNodes.push( node );
|
|
338
830
|
|
|
339
831
|
}
|
|
340
832
|
|
|
@@ -342,12 +834,24 @@ class NodeBuilder {
|
|
|
342
834
|
|
|
343
835
|
}
|
|
344
836
|
|
|
837
|
+
/**
|
|
838
|
+
* A reference the current node which is the
|
|
839
|
+
* last node in the chain of nodes.
|
|
840
|
+
*
|
|
841
|
+
* @type {Node}
|
|
842
|
+
*/
|
|
345
843
|
get currentNode() {
|
|
346
844
|
|
|
347
845
|
return this.chaining[ this.chaining.length - 1 ];
|
|
348
846
|
|
|
349
847
|
}
|
|
350
848
|
|
|
849
|
+
/**
|
|
850
|
+
* Whether the given texture is filtered or not.
|
|
851
|
+
*
|
|
852
|
+
* @param {Texture} texture - The texture to check.
|
|
853
|
+
* @return {boolean} Whether the given texture is filtered or not.
|
|
854
|
+
*/
|
|
351
855
|
isFilteredTexture( texture ) {
|
|
352
856
|
|
|
353
857
|
return ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
|
|
@@ -355,12 +859,29 @@ class NodeBuilder {
|
|
|
355
859
|
|
|
356
860
|
}
|
|
357
861
|
|
|
862
|
+
/**
|
|
863
|
+
* Returns the maximum number of bytes available for uniform buffers.
|
|
864
|
+
*
|
|
865
|
+
* @return {number} The maximum number of bytes available for uniform buffers.
|
|
866
|
+
*/
|
|
867
|
+
getUniformBufferLimit() {
|
|
868
|
+
|
|
869
|
+
return 16384;
|
|
870
|
+
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Adds the given node to the internal node chain.
|
|
875
|
+
* This is used to check recursive calls in node-graph.
|
|
876
|
+
*
|
|
877
|
+
* @param {Node} node - The node to add.
|
|
878
|
+
*/
|
|
358
879
|
addChain( node ) {
|
|
359
880
|
|
|
360
881
|
/*
|
|
361
882
|
if ( this.chaining.indexOf( node ) !== - 1 ) {
|
|
362
883
|
|
|
363
|
-
|
|
884
|
+
warn( 'Recursive node: ', node );
|
|
364
885
|
|
|
365
886
|
}
|
|
366
887
|
*/
|
|
@@ -369,6 +890,11 @@ class NodeBuilder {
|
|
|
369
890
|
|
|
370
891
|
}
|
|
371
892
|
|
|
893
|
+
/**
|
|
894
|
+
* Removes the given node from the internal node chain.
|
|
895
|
+
*
|
|
896
|
+
* @param {Node} node - The node to remove.
|
|
897
|
+
*/
|
|
372
898
|
removeChain( node ) {
|
|
373
899
|
|
|
374
900
|
const lastChain = this.chaining.pop();
|
|
@@ -381,18 +907,56 @@ class NodeBuilder {
|
|
|
381
907
|
|
|
382
908
|
}
|
|
383
909
|
|
|
910
|
+
/**
|
|
911
|
+
* Returns the native shader method name for a given generic name. E.g.
|
|
912
|
+
* the method name `textureDimensions` matches the WGSL name but must be
|
|
913
|
+
* resolved to `textureSize` in GLSL.
|
|
914
|
+
*
|
|
915
|
+
* @abstract
|
|
916
|
+
* @param {string} method - The method name to resolve.
|
|
917
|
+
* @return {string} The resolved method name.
|
|
918
|
+
*/
|
|
384
919
|
getMethod( method ) {
|
|
385
920
|
|
|
386
921
|
return method;
|
|
387
922
|
|
|
388
923
|
}
|
|
389
924
|
|
|
925
|
+
/**
|
|
926
|
+
* Returns the native snippet for a ternary operation. E.g. GLSL would output
|
|
927
|
+
* a ternary op as `cond ? x : y` whereas WGSL would output it as `select(y, x, cond)`
|
|
928
|
+
*
|
|
929
|
+
* @abstract
|
|
930
|
+
* @param {string} condSnippet - The condition determining which expression gets resolved.
|
|
931
|
+
* @param {string} ifSnippet - The expression to resolve to if the condition is true.
|
|
932
|
+
* @param {string} elseSnippet - The expression to resolve to if the condition is false.
|
|
933
|
+
* @return {string} The resolved method name.
|
|
934
|
+
*/
|
|
935
|
+
getTernary( /* condSnippet, ifSnippet, elseSnippet*/ ) {
|
|
936
|
+
|
|
937
|
+
return null;
|
|
938
|
+
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Returns a node for the given hash, see {@link NodeBuilder#setHashNode}.
|
|
943
|
+
*
|
|
944
|
+
* @param {number} hash - The hash of the node.
|
|
945
|
+
* @return {Node} The found node.
|
|
946
|
+
*/
|
|
390
947
|
getNodeFromHash( hash ) {
|
|
391
948
|
|
|
392
949
|
return this.hashNodes[ hash ];
|
|
393
950
|
|
|
394
951
|
}
|
|
395
952
|
|
|
953
|
+
/**
|
|
954
|
+
* Adds the Node to a target flow so that it can generate code in the 'generate' process.
|
|
955
|
+
*
|
|
956
|
+
* @param {('vertex'|'fragment'|'compute')} shaderStage - The shader stage.
|
|
957
|
+
* @param {Node} node - The node to add.
|
|
958
|
+
* @return {Node} The node.
|
|
959
|
+
*/
|
|
396
960
|
addFlow( shaderStage, node ) {
|
|
397
961
|
|
|
398
962
|
this.flowNodes[ shaderStage ].push( node );
|
|
@@ -401,40 +965,94 @@ class NodeBuilder {
|
|
|
401
965
|
|
|
402
966
|
}
|
|
403
967
|
|
|
968
|
+
/**
|
|
969
|
+
* Sets builder's context.
|
|
970
|
+
*
|
|
971
|
+
* @param {Object} context - The context to set.
|
|
972
|
+
*/
|
|
404
973
|
setContext( context ) {
|
|
405
974
|
|
|
406
975
|
this.context = context;
|
|
407
976
|
|
|
408
977
|
}
|
|
409
978
|
|
|
979
|
+
/**
|
|
980
|
+
* Returns the builder's current context.
|
|
981
|
+
*
|
|
982
|
+
* @return {Object} The builder's current context.
|
|
983
|
+
*/
|
|
410
984
|
getContext() {
|
|
411
985
|
|
|
412
986
|
return this.context;
|
|
413
987
|
|
|
414
988
|
}
|
|
415
989
|
|
|
990
|
+
/**
|
|
991
|
+
* Adds context data to the builder's current context.
|
|
992
|
+
*
|
|
993
|
+
* @param {Object} context - The context to add.
|
|
994
|
+
* @return {Object} The previous context.
|
|
995
|
+
*/
|
|
996
|
+
addContext( context ) {
|
|
997
|
+
|
|
998
|
+
const previousContext = this.getContext();
|
|
999
|
+
|
|
1000
|
+
this.setContext( { ...this.context, ...context } );
|
|
1001
|
+
|
|
1002
|
+
return previousContext;
|
|
1003
|
+
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
* Gets a context used in shader construction that can be shared across different materials.
|
|
1008
|
+
* This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
|
|
1009
|
+
*
|
|
1010
|
+
* @return {Object} The builder's current context without material.
|
|
1011
|
+
*/
|
|
416
1012
|
getSharedContext() {
|
|
417
1013
|
|
|
418
1014
|
const context = { ...this.context };
|
|
419
1015
|
|
|
420
1016
|
delete context.material;
|
|
1017
|
+
delete context.getUV;
|
|
1018
|
+
delete context.getOutput;
|
|
1019
|
+
delete context.getTextureLevel;
|
|
1020
|
+
delete context.getAO;
|
|
1021
|
+
delete context.getShadow;
|
|
421
1022
|
|
|
422
|
-
return
|
|
1023
|
+
return context;
|
|
423
1024
|
|
|
424
1025
|
}
|
|
425
1026
|
|
|
1027
|
+
/**
|
|
1028
|
+
* Sets builder's cache.
|
|
1029
|
+
*
|
|
1030
|
+
* @param {NodeCache} cache - The cache to set.
|
|
1031
|
+
*/
|
|
426
1032
|
setCache( cache ) {
|
|
427
1033
|
|
|
428
1034
|
this.cache = cache;
|
|
429
1035
|
|
|
430
1036
|
}
|
|
431
1037
|
|
|
1038
|
+
/**
|
|
1039
|
+
* Returns the builder's current cache.
|
|
1040
|
+
*
|
|
1041
|
+
* @return {NodeCache} The builder's current cache.
|
|
1042
|
+
*/
|
|
432
1043
|
getCache() {
|
|
433
1044
|
|
|
434
1045
|
return this.cache;
|
|
435
1046
|
|
|
436
1047
|
}
|
|
437
1048
|
|
|
1049
|
+
/**
|
|
1050
|
+
* Returns a cache for the given node.
|
|
1051
|
+
*
|
|
1052
|
+
* @param {Node} node - The node.
|
|
1053
|
+
* @param {boolean} [parent=true] - Whether this node refers to a shared parent cache or not.
|
|
1054
|
+
* @return {NodeCache} The cache.
|
|
1055
|
+
*/
|
|
438
1056
|
getCacheFromNode( node, parent = true ) {
|
|
439
1057
|
|
|
440
1058
|
const data = this.getDataFromNode( node );
|
|
@@ -444,48 +1062,100 @@ class NodeBuilder {
|
|
|
444
1062
|
|
|
445
1063
|
}
|
|
446
1064
|
|
|
1065
|
+
/**
|
|
1066
|
+
* Whether the requested feature is available or not.
|
|
1067
|
+
*
|
|
1068
|
+
* @abstract
|
|
1069
|
+
* @param {string} name - The requested feature.
|
|
1070
|
+
* @return {boolean} Whether the requested feature is supported or not.
|
|
1071
|
+
*/
|
|
447
1072
|
isAvailable( /*name*/ ) {
|
|
448
1073
|
|
|
449
1074
|
return false;
|
|
450
1075
|
|
|
451
1076
|
}
|
|
452
1077
|
|
|
1078
|
+
/**
|
|
1079
|
+
* Returns the vertexIndex input variable as a native shader string.
|
|
1080
|
+
*
|
|
1081
|
+
* @abstract
|
|
1082
|
+
* @return {string} The instanceIndex shader string.
|
|
1083
|
+
*/
|
|
453
1084
|
getVertexIndex() {
|
|
454
1085
|
|
|
455
|
-
|
|
1086
|
+
warn( 'Abstract function.' );
|
|
456
1087
|
|
|
457
1088
|
}
|
|
458
1089
|
|
|
1090
|
+
/**
|
|
1091
|
+
* Contextually returns either the vertex stage instance index builtin
|
|
1092
|
+
* or the linearized index of an compute invocation within a grid of workgroups.
|
|
1093
|
+
*
|
|
1094
|
+
* @abstract
|
|
1095
|
+
* @return {string} The instanceIndex shader string.
|
|
1096
|
+
*/
|
|
459
1097
|
getInstanceIndex() {
|
|
460
1098
|
|
|
461
|
-
|
|
1099
|
+
warn( 'Abstract function.' );
|
|
462
1100
|
|
|
463
1101
|
}
|
|
464
1102
|
|
|
1103
|
+
/**
|
|
1104
|
+
* Returns the drawIndex input variable as a native shader string.
|
|
1105
|
+
* Only relevant for WebGL and its `WEBGL_multi_draw` extension.
|
|
1106
|
+
*
|
|
1107
|
+
* @abstract
|
|
1108
|
+
* @return {?string} The drawIndex shader string.
|
|
1109
|
+
*/
|
|
465
1110
|
getDrawIndex() {
|
|
466
1111
|
|
|
467
|
-
|
|
1112
|
+
warn( 'Abstract function.' );
|
|
468
1113
|
|
|
469
1114
|
}
|
|
470
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* Returns the frontFacing input variable as a native shader string.
|
|
1118
|
+
*
|
|
1119
|
+
* @abstract
|
|
1120
|
+
* @return {string} The frontFacing shader string.
|
|
1121
|
+
*/
|
|
471
1122
|
getFrontFacing() {
|
|
472
1123
|
|
|
473
|
-
|
|
1124
|
+
warn( 'Abstract function.' );
|
|
474
1125
|
|
|
475
1126
|
}
|
|
476
1127
|
|
|
1128
|
+
/**
|
|
1129
|
+
* Returns the fragCoord input variable as a native shader string.
|
|
1130
|
+
*
|
|
1131
|
+
* @abstract
|
|
1132
|
+
* @return {string} The fragCoord shader string.
|
|
1133
|
+
*/
|
|
477
1134
|
getFragCoord() {
|
|
478
1135
|
|
|
479
|
-
|
|
1136
|
+
warn( 'Abstract function.' );
|
|
480
1137
|
|
|
481
1138
|
}
|
|
482
1139
|
|
|
1140
|
+
/**
|
|
1141
|
+
* Whether to flip texture data along its vertical axis or not. WebGL needs
|
|
1142
|
+
* this method evaluate to `true`, WebGPU to `false`.
|
|
1143
|
+
*
|
|
1144
|
+
* @abstract
|
|
1145
|
+
* @return {boolean} Whether to flip texture data along its vertical axis or not.
|
|
1146
|
+
*/
|
|
483
1147
|
isFlipY() {
|
|
484
1148
|
|
|
485
1149
|
return false;
|
|
486
1150
|
|
|
487
1151
|
}
|
|
488
1152
|
|
|
1153
|
+
/**
|
|
1154
|
+
* Calling this method increases the usage count for the given node by one.
|
|
1155
|
+
*
|
|
1156
|
+
* @param {Node} node - The node to increase the usage count for.
|
|
1157
|
+
* @return {number} The updated usage count.
|
|
1158
|
+
*/
|
|
489
1159
|
increaseUsage( node ) {
|
|
490
1160
|
|
|
491
1161
|
const nodeData = this.getDataFromNode( node );
|
|
@@ -495,18 +1165,126 @@ class NodeBuilder {
|
|
|
495
1165
|
|
|
496
1166
|
}
|
|
497
1167
|
|
|
1168
|
+
/**
|
|
1169
|
+
* Generates a texture sample shader string for the given texture data.
|
|
1170
|
+
*
|
|
1171
|
+
* @abstract
|
|
1172
|
+
* @param {Texture} texture - The texture.
|
|
1173
|
+
* @param {string} textureProperty - The texture property name.
|
|
1174
|
+
* @param {string} uvSnippet - Snippet defining the texture coordinates.
|
|
1175
|
+
* @return {string} The generated shader string.
|
|
1176
|
+
*/
|
|
498
1177
|
generateTexture( /* texture, textureProperty, uvSnippet */ ) {
|
|
499
1178
|
|
|
500
|
-
|
|
1179
|
+
warn( 'Abstract function.' );
|
|
501
1180
|
|
|
502
1181
|
}
|
|
503
1182
|
|
|
504
|
-
|
|
1183
|
+
/**
|
|
1184
|
+
* Generates a texture LOD shader string for the given texture data.
|
|
1185
|
+
*
|
|
1186
|
+
* @abstract
|
|
1187
|
+
* @param {Texture} texture - The texture.
|
|
1188
|
+
* @param {string} textureProperty - The texture property name.
|
|
1189
|
+
* @param {string} uvSnippet - Snippet defining the texture coordinates.
|
|
1190
|
+
* @param {?string} depthSnippet - Snippet defining the 0-based texture array index to sample.
|
|
1191
|
+
* @param {string} levelSnippet - Snippet defining the mip level.
|
|
1192
|
+
* @return {string} The generated shader string.
|
|
1193
|
+
*/
|
|
1194
|
+
generateTextureLod( /* texture, textureProperty, uvSnippet, depthSnippet, levelSnippet */ ) {
|
|
505
1195
|
|
|
506
|
-
|
|
1196
|
+
warn( 'Abstract function.' );
|
|
507
1197
|
|
|
508
1198
|
}
|
|
509
1199
|
|
|
1200
|
+
/**
|
|
1201
|
+
* Generates the array declaration string.
|
|
1202
|
+
*
|
|
1203
|
+
* @param {string} type - The type.
|
|
1204
|
+
* @param {?number} [count] - The count.
|
|
1205
|
+
* @return {string} The generated value as a shader string.
|
|
1206
|
+
*/
|
|
1207
|
+
generateArrayDeclaration( type, count ) {
|
|
1208
|
+
|
|
1209
|
+
return this.getType( type ) + '[ ' + count + ' ]';
|
|
1210
|
+
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* Generates the array shader string for the given type and value.
|
|
1215
|
+
*
|
|
1216
|
+
* @param {string} type - The type.
|
|
1217
|
+
* @param {?number} [count] - The count.
|
|
1218
|
+
* @param {?Array<Node>} [values=null] - The default values.
|
|
1219
|
+
* @return {string} The generated value as a shader string.
|
|
1220
|
+
*/
|
|
1221
|
+
generateArray( type, count, values = null ) {
|
|
1222
|
+
|
|
1223
|
+
let snippet = this.generateArrayDeclaration( type, count ) + '( ';
|
|
1224
|
+
|
|
1225
|
+
for ( let i = 0; i < count; i ++ ) {
|
|
1226
|
+
|
|
1227
|
+
const value = values ? values[ i ] : null;
|
|
1228
|
+
|
|
1229
|
+
if ( value !== null ) {
|
|
1230
|
+
|
|
1231
|
+
snippet += value.build( this, type );
|
|
1232
|
+
|
|
1233
|
+
} else {
|
|
1234
|
+
|
|
1235
|
+
snippet += this.generateConst( type );
|
|
1236
|
+
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
if ( i < count - 1 ) snippet += ', ';
|
|
1240
|
+
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
snippet += ' )';
|
|
1244
|
+
|
|
1245
|
+
return snippet;
|
|
1246
|
+
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
/**
|
|
1250
|
+
* Generates the struct shader string.
|
|
1251
|
+
*
|
|
1252
|
+
* @param {string} type - The type.
|
|
1253
|
+
* @param {Array<Object>} [membersLayout] - The count.
|
|
1254
|
+
* @param {?Array<Node>} [values=null] - The default values.
|
|
1255
|
+
* @return {string} The generated value as a shader string.
|
|
1256
|
+
*/
|
|
1257
|
+
generateStruct( type, membersLayout, values = null ) {
|
|
1258
|
+
|
|
1259
|
+
const snippets = [];
|
|
1260
|
+
|
|
1261
|
+
for ( const member of membersLayout ) {
|
|
1262
|
+
|
|
1263
|
+
const { name, type } = member;
|
|
1264
|
+
|
|
1265
|
+
if ( values && values[ name ] && values[ name ].isNode ) {
|
|
1266
|
+
|
|
1267
|
+
snippets.push( values[ name ].build( this, type ) );
|
|
1268
|
+
|
|
1269
|
+
} else {
|
|
1270
|
+
|
|
1271
|
+
snippets.push( this.generateConst( type ) );
|
|
1272
|
+
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
return type + '( ' + snippets.join( ', ' ) + ' )';
|
|
1278
|
+
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Generates the shader string for the given type and value.
|
|
1283
|
+
*
|
|
1284
|
+
* @param {string} type - The type.
|
|
1285
|
+
* @param {?any} [value=null] - The value.
|
|
1286
|
+
* @return {string} The generated value as a shader string.
|
|
1287
|
+
*/
|
|
510
1288
|
generateConst( type, value = null ) {
|
|
511
1289
|
|
|
512
1290
|
if ( value === null ) {
|
|
@@ -514,9 +1292,9 @@ class NodeBuilder {
|
|
|
514
1292
|
if ( type === 'float' || type === 'int' || type === 'uint' ) value = 0;
|
|
515
1293
|
else if ( type === 'bool' ) value = false;
|
|
516
1294
|
else if ( type === 'color' ) value = new Color();
|
|
517
|
-
else if ( type === 'vec2' ) value = new Vector2();
|
|
518
|
-
else if ( type === 'vec3' ) value = new Vector3();
|
|
519
|
-
else if ( type === 'vec4' ) value = new Vector4();
|
|
1295
|
+
else if ( type === 'vec2' || type === 'uvec2' || type === 'ivec2' ) value = new Vector2();
|
|
1296
|
+
else if ( type === 'vec3' || type === 'uvec3' || type === 'ivec3' ) value = new Vector3();
|
|
1297
|
+
else if ( type === 'vec4' || type === 'uvec4' || type === 'ivec4' ) value = new Vector4();
|
|
520
1298
|
|
|
521
1299
|
}
|
|
522
1300
|
|
|
@@ -540,11 +1318,11 @@ class NodeBuilder {
|
|
|
540
1318
|
|
|
541
1319
|
return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) } )`;
|
|
542
1320
|
|
|
543
|
-
} else if ( typeLength === 4 ) {
|
|
1321
|
+
} else if ( typeLength === 4 && type !== 'mat2' ) {
|
|
544
1322
|
|
|
545
1323
|
return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) }, ${ generateConst( value.w ) } )`;
|
|
546
1324
|
|
|
547
|
-
} else if ( typeLength
|
|
1325
|
+
} else if ( typeLength >= 4 && value && ( value.isMatrix2 || value.isMatrix3 || value.isMatrix4 ) ) {
|
|
548
1326
|
|
|
549
1327
|
return `${ this.getType( type ) }( ${ value.elements.map( generateConst ).join( ', ' ) } )`;
|
|
550
1328
|
|
|
@@ -558,6 +1336,13 @@ class NodeBuilder {
|
|
|
558
1336
|
|
|
559
1337
|
}
|
|
560
1338
|
|
|
1339
|
+
/**
|
|
1340
|
+
* It might be necessary to convert certain data types to different ones
|
|
1341
|
+
* so this method can be used to hide the conversion.
|
|
1342
|
+
*
|
|
1343
|
+
* @param {string} type - The type.
|
|
1344
|
+
* @return {string} The updated type.
|
|
1345
|
+
*/
|
|
561
1346
|
getType( type ) {
|
|
562
1347
|
|
|
563
1348
|
if ( type === 'color' ) return 'vec3';
|
|
@@ -566,12 +1351,25 @@ class NodeBuilder {
|
|
|
566
1351
|
|
|
567
1352
|
}
|
|
568
1353
|
|
|
1354
|
+
/**
|
|
1355
|
+
* Whether the given attribute name is defined in the geometry or not.
|
|
1356
|
+
*
|
|
1357
|
+
* @param {string} name - The attribute name.
|
|
1358
|
+
* @return {boolean} Whether the given attribute name is defined in the geometry.
|
|
1359
|
+
*/
|
|
569
1360
|
hasGeometryAttribute( name ) {
|
|
570
1361
|
|
|
571
1362
|
return this.geometry && this.geometry.getAttribute( name ) !== undefined;
|
|
572
1363
|
|
|
573
1364
|
}
|
|
574
1365
|
|
|
1366
|
+
/**
|
|
1367
|
+
* Returns a node attribute for the given name and type.
|
|
1368
|
+
*
|
|
1369
|
+
* @param {string} name - The attribute's name.
|
|
1370
|
+
* @param {string} type - The attribute's type.
|
|
1371
|
+
* @return {NodeAttribute} The node attribute.
|
|
1372
|
+
*/
|
|
575
1373
|
getAttribute( name, type ) {
|
|
576
1374
|
|
|
577
1375
|
const attributes = this.attributes;
|
|
@@ -592,42 +1390,82 @@ class NodeBuilder {
|
|
|
592
1390
|
|
|
593
1391
|
const attribute = new NodeAttribute( name, type );
|
|
594
1392
|
|
|
1393
|
+
this.registerDeclaration( attribute );
|
|
1394
|
+
|
|
595
1395
|
attributes.push( attribute );
|
|
596
1396
|
|
|
597
1397
|
return attribute;
|
|
598
1398
|
|
|
599
1399
|
}
|
|
600
1400
|
|
|
1401
|
+
/**
|
|
1402
|
+
* Returns for the given node and shader stage the property name for the shader.
|
|
1403
|
+
*
|
|
1404
|
+
* @param {Node} node - The node.
|
|
1405
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
1406
|
+
* @return {string} The property name.
|
|
1407
|
+
*/
|
|
601
1408
|
getPropertyName( node/*, shaderStage*/ ) {
|
|
602
1409
|
|
|
603
1410
|
return node.name;
|
|
604
1411
|
|
|
605
1412
|
}
|
|
606
1413
|
|
|
1414
|
+
/**
|
|
1415
|
+
* Whether the given type is a vector type or not.
|
|
1416
|
+
*
|
|
1417
|
+
* @param {string} type - The type to check.
|
|
1418
|
+
* @return {boolean} Whether the given type is a vector type or not.
|
|
1419
|
+
*/
|
|
607
1420
|
isVector( type ) {
|
|
608
1421
|
|
|
609
1422
|
return /vec\d/.test( type );
|
|
610
1423
|
|
|
611
1424
|
}
|
|
612
1425
|
|
|
1426
|
+
/**
|
|
1427
|
+
* Whether the given type is a matrix type or not.
|
|
1428
|
+
*
|
|
1429
|
+
* @param {string} type - The type to check.
|
|
1430
|
+
* @return {boolean} Whether the given type is a matrix type or not.
|
|
1431
|
+
*/
|
|
613
1432
|
isMatrix( type ) {
|
|
614
1433
|
|
|
615
1434
|
return /mat\d/.test( type );
|
|
616
1435
|
|
|
617
1436
|
}
|
|
618
1437
|
|
|
1438
|
+
/**
|
|
1439
|
+
* Whether the given type is a reference type or not.
|
|
1440
|
+
*
|
|
1441
|
+
* @param {string} type - The type to check.
|
|
1442
|
+
* @return {boolean} Whether the given type is a reference type or not.
|
|
1443
|
+
*/
|
|
619
1444
|
isReference( type ) {
|
|
620
1445
|
|
|
621
|
-
return type === 'void' || type === 'property' || type === 'sampler' || type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'depthTexture' || type === 'texture3D';
|
|
1446
|
+
return type === 'void' || type === 'property' || type === 'sampler' || type === 'samplerComparison' || type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'depthTexture' || type === 'texture3D';
|
|
622
1447
|
|
|
623
1448
|
}
|
|
624
1449
|
|
|
1450
|
+
/**
|
|
1451
|
+
* Checks if the given texture requires a manual conversion to the working color space.
|
|
1452
|
+
*
|
|
1453
|
+
* @abstract
|
|
1454
|
+
* @param {Texture} texture - The texture to check.
|
|
1455
|
+
* @return {boolean} Whether the given texture requires a conversion to working color space or not.
|
|
1456
|
+
*/
|
|
625
1457
|
needsToWorkingColorSpace( /*texture*/ ) {
|
|
626
1458
|
|
|
627
1459
|
return false;
|
|
628
1460
|
|
|
629
1461
|
}
|
|
630
1462
|
|
|
1463
|
+
/**
|
|
1464
|
+
* Returns the component type of a given texture.
|
|
1465
|
+
*
|
|
1466
|
+
* @param {Texture} texture - The texture.
|
|
1467
|
+
* @return {string} The component type.
|
|
1468
|
+
*/
|
|
631
1469
|
getComponentTypeFromTexture( texture ) {
|
|
632
1470
|
|
|
633
1471
|
const type = texture.type;
|
|
@@ -643,6 +1481,12 @@ class NodeBuilder {
|
|
|
643
1481
|
|
|
644
1482
|
}
|
|
645
1483
|
|
|
1484
|
+
/**
|
|
1485
|
+
* Returns the element type for a given type.
|
|
1486
|
+
*
|
|
1487
|
+
* @param {string} type - The type.
|
|
1488
|
+
* @return {string} The element type.
|
|
1489
|
+
*/
|
|
646
1490
|
getElementType( type ) {
|
|
647
1491
|
|
|
648
1492
|
if ( type === 'mat2' ) return 'vec2';
|
|
@@ -653,6 +1497,12 @@ class NodeBuilder {
|
|
|
653
1497
|
|
|
654
1498
|
}
|
|
655
1499
|
|
|
1500
|
+
/**
|
|
1501
|
+
* Returns the component type for a given type.
|
|
1502
|
+
*
|
|
1503
|
+
* @param {string} type - The type.
|
|
1504
|
+
* @return {string} The component type.
|
|
1505
|
+
*/
|
|
656
1506
|
getComponentType( type ) {
|
|
657
1507
|
|
|
658
1508
|
type = this.getVectorType( type );
|
|
@@ -671,6 +1521,12 @@ class NodeBuilder {
|
|
|
671
1521
|
|
|
672
1522
|
}
|
|
673
1523
|
|
|
1524
|
+
/**
|
|
1525
|
+
* Returns the vector type for a given type.
|
|
1526
|
+
*
|
|
1527
|
+
* @param {string} type - The type.
|
|
1528
|
+
* @return {string} The vector type.
|
|
1529
|
+
*/
|
|
674
1530
|
getVectorType( type ) {
|
|
675
1531
|
|
|
676
1532
|
if ( type === 'color' ) return 'vec3';
|
|
@@ -680,23 +1536,61 @@ class NodeBuilder {
|
|
|
680
1536
|
|
|
681
1537
|
}
|
|
682
1538
|
|
|
1539
|
+
/**
|
|
1540
|
+
* Returns the data type for the given the length and component type.
|
|
1541
|
+
*
|
|
1542
|
+
* @param {number} length - The length.
|
|
1543
|
+
* @param {string} [componentType='float'] - The component type.
|
|
1544
|
+
* @return {string} The type.
|
|
1545
|
+
*/
|
|
683
1546
|
getTypeFromLength( length, componentType = 'float' ) {
|
|
684
1547
|
|
|
685
1548
|
if ( length === 1 ) return componentType;
|
|
686
1549
|
|
|
687
|
-
|
|
1550
|
+
let baseType = getTypeFromLength( length );
|
|
688
1551
|
const prefix = componentType === 'float' ? '' : componentType[ 0 ];
|
|
689
1552
|
|
|
1553
|
+
// fix edge case for mat2x2 being same size as vec4
|
|
1554
|
+
if ( /mat2/.test( componentType ) === true ) {
|
|
1555
|
+
|
|
1556
|
+
baseType = baseType.replace( 'vec', 'mat' );
|
|
1557
|
+
|
|
1558
|
+
}
|
|
1559
|
+
|
|
690
1560
|
return prefix + baseType;
|
|
691
1561
|
|
|
692
1562
|
}
|
|
693
1563
|
|
|
1564
|
+
/**
|
|
1565
|
+
* Returns the type for a given typed array.
|
|
1566
|
+
*
|
|
1567
|
+
* @param {TypedArray} array - The typed array.
|
|
1568
|
+
* @return {string} The type.
|
|
1569
|
+
*/
|
|
694
1570
|
getTypeFromArray( array ) {
|
|
695
1571
|
|
|
696
1572
|
return typeFromArray.get( array.constructor );
|
|
697
1573
|
|
|
698
1574
|
}
|
|
699
1575
|
|
|
1576
|
+
/**
|
|
1577
|
+
* Returns the type is an integer type.
|
|
1578
|
+
*
|
|
1579
|
+
* @param {string} type - The type.
|
|
1580
|
+
* @return {boolean} Whether the type is an integer type or not.
|
|
1581
|
+
*/
|
|
1582
|
+
isInteger( type ) {
|
|
1583
|
+
|
|
1584
|
+
return /int|uint|(i|u)vec/.test( type );
|
|
1585
|
+
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
/**
|
|
1589
|
+
* Returns the type for a given buffer attribute.
|
|
1590
|
+
*
|
|
1591
|
+
* @param {BufferAttribute} attribute - The buffer attribute.
|
|
1592
|
+
* @return {string} The type.
|
|
1593
|
+
*/
|
|
700
1594
|
getTypeFromAttribute( attribute ) {
|
|
701
1595
|
|
|
702
1596
|
let dataAttribute = attribute;
|
|
@@ -719,6 +1613,12 @@ class NodeBuilder {
|
|
|
719
1613
|
|
|
720
1614
|
}
|
|
721
1615
|
|
|
1616
|
+
/**
|
|
1617
|
+
* Returns the length for the given data type.
|
|
1618
|
+
*
|
|
1619
|
+
* @param {string} type - The data type.
|
|
1620
|
+
* @return {number} The length.
|
|
1621
|
+
*/
|
|
722
1622
|
getTypeLength( type ) {
|
|
723
1623
|
|
|
724
1624
|
const vecType = this.getVectorType( type );
|
|
@@ -734,18 +1634,39 @@ class NodeBuilder {
|
|
|
734
1634
|
|
|
735
1635
|
}
|
|
736
1636
|
|
|
1637
|
+
/**
|
|
1638
|
+
* Returns the vector type for a given matrix type.
|
|
1639
|
+
*
|
|
1640
|
+
* @param {string} type - The matrix type.
|
|
1641
|
+
* @return {string} The vector type.
|
|
1642
|
+
*/
|
|
737
1643
|
getVectorFromMatrix( type ) {
|
|
738
1644
|
|
|
739
1645
|
return type.replace( 'mat', 'vec' );
|
|
740
1646
|
|
|
741
1647
|
}
|
|
742
1648
|
|
|
1649
|
+
/**
|
|
1650
|
+
* For a given type this method changes the component type to the
|
|
1651
|
+
* given value. E.g. `vec4` should be changed to the new component type
|
|
1652
|
+
* `uint` which results in `uvec4`.
|
|
1653
|
+
*
|
|
1654
|
+
* @param {string} type - The type.
|
|
1655
|
+
* @param {string} newComponentType - The new component type.
|
|
1656
|
+
* @return {string} The new type.
|
|
1657
|
+
*/
|
|
743
1658
|
changeComponentType( type, newComponentType ) {
|
|
744
1659
|
|
|
745
1660
|
return this.getTypeFromLength( this.getTypeLength( type ), newComponentType );
|
|
746
1661
|
|
|
747
1662
|
}
|
|
748
1663
|
|
|
1664
|
+
/**
|
|
1665
|
+
* Returns the integer type pendant for the given type.
|
|
1666
|
+
*
|
|
1667
|
+
* @param {string} type - The type.
|
|
1668
|
+
* @return {string} The integer type.
|
|
1669
|
+
*/
|
|
749
1670
|
getIntegerType( type ) {
|
|
750
1671
|
|
|
751
1672
|
const componentType = this.getComponentType( type );
|
|
@@ -756,20 +1677,92 @@ class NodeBuilder {
|
|
|
756
1677
|
|
|
757
1678
|
}
|
|
758
1679
|
|
|
1680
|
+
/**
|
|
1681
|
+
* Adds an active stack to the internal stack.
|
|
1682
|
+
*
|
|
1683
|
+
* @param {StackNode} stack - The stack node to add.
|
|
1684
|
+
*/
|
|
1685
|
+
setActiveStack( stack ) {
|
|
1686
|
+
|
|
1687
|
+
this.activeStacks.push( stack );
|
|
1688
|
+
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
/**
|
|
1692
|
+
* Removes the active stack from the internal stack.
|
|
1693
|
+
*
|
|
1694
|
+
* @param {StackNode} stack - The stack node to remove.
|
|
1695
|
+
*/
|
|
1696
|
+
removeActiveStack( stack ) {
|
|
1697
|
+
|
|
1698
|
+
if ( this.activeStacks[ this.activeStacks.length - 1 ] === stack ) {
|
|
1699
|
+
|
|
1700
|
+
this.activeStacks.pop();
|
|
1701
|
+
|
|
1702
|
+
} else {
|
|
1703
|
+
|
|
1704
|
+
throw new Error( 'NodeBuilder: Invalid active stack removal.' );
|
|
1705
|
+
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* Returns the active stack.
|
|
1712
|
+
*
|
|
1713
|
+
* @return {StackNode} The active stack.
|
|
1714
|
+
*/
|
|
1715
|
+
getActiveStack() {
|
|
1716
|
+
|
|
1717
|
+
return this.activeStacks[ this.activeStacks.length - 1 ];
|
|
1718
|
+
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
/**
|
|
1722
|
+
* Returns the base stack.
|
|
1723
|
+
*
|
|
1724
|
+
* @return {StackNode} The base stack.
|
|
1725
|
+
*/
|
|
1726
|
+
getBaseStack() {
|
|
1727
|
+
|
|
1728
|
+
return this.activeStacks[ 0 ];
|
|
1729
|
+
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* Adds a stack node to the internal stack.
|
|
1734
|
+
*
|
|
1735
|
+
* @return {StackNode} The added stack node.
|
|
1736
|
+
*/
|
|
759
1737
|
addStack() {
|
|
760
1738
|
|
|
761
1739
|
this.stack = stack( this.stack );
|
|
762
1740
|
|
|
763
|
-
|
|
1741
|
+
const previousStack = getCurrentStack();
|
|
1742
|
+
|
|
1743
|
+
this.stacks.push( previousStack );
|
|
764
1744
|
setCurrentStack( this.stack );
|
|
765
1745
|
|
|
766
1746
|
return this.stack;
|
|
767
1747
|
|
|
768
1748
|
}
|
|
769
1749
|
|
|
1750
|
+
/**
|
|
1751
|
+
* Removes the last stack node from the internal stack.
|
|
1752
|
+
*
|
|
1753
|
+
* @return {StackNode} The removed stack node.
|
|
1754
|
+
*/
|
|
770
1755
|
removeStack() {
|
|
771
1756
|
|
|
772
1757
|
const lastStack = this.stack;
|
|
1758
|
+
|
|
1759
|
+
for ( const node of lastStack.nodes ) {
|
|
1760
|
+
|
|
1761
|
+
const nodeData = this.getDataFromNode( node );
|
|
1762
|
+
nodeData.stack = lastStack;
|
|
1763
|
+
|
|
1764
|
+
}
|
|
1765
|
+
|
|
773
1766
|
this.stack = lastStack.parent;
|
|
774
1767
|
|
|
775
1768
|
setCurrentStack( this.stacks.pop() );
|
|
@@ -778,6 +1771,15 @@ class NodeBuilder {
|
|
|
778
1771
|
|
|
779
1772
|
}
|
|
780
1773
|
|
|
1774
|
+
/**
|
|
1775
|
+
* The builder maintains (cached) data for each node during the building process. This method
|
|
1776
|
+
* can be used to get these data for a specific shader stage and cache.
|
|
1777
|
+
*
|
|
1778
|
+
* @param {Node} node - The node to get the data for.
|
|
1779
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1780
|
+
* @param {?NodeCache} cache - An optional cache.
|
|
1781
|
+
* @return {Object} The node data.
|
|
1782
|
+
*/
|
|
781
1783
|
getDataFromNode( node, shaderStage = this.shaderStage, cache = null ) {
|
|
782
1784
|
|
|
783
1785
|
cache = cache === null ? ( node.isGlobal( this ) ? this.globalCache : this.cache ) : cache;
|
|
@@ -794,10 +1796,38 @@ class NodeBuilder {
|
|
|
794
1796
|
|
|
795
1797
|
if ( nodeData[ shaderStage ] === undefined ) nodeData[ shaderStage ] = {};
|
|
796
1798
|
|
|
797
|
-
|
|
1799
|
+
//
|
|
1800
|
+
|
|
1801
|
+
let data = nodeData[ shaderStage ];
|
|
1802
|
+
|
|
1803
|
+
const subBuilds = nodeData.any ? nodeData.any.subBuilds : null;
|
|
1804
|
+
const subBuild = this.getClosestSubBuild( subBuilds );
|
|
1805
|
+
|
|
1806
|
+
if ( subBuild ) {
|
|
1807
|
+
|
|
1808
|
+
if ( data.subBuildsCache === undefined ) data.subBuildsCache = {};
|
|
1809
|
+
|
|
1810
|
+
data = data.subBuildsCache[ subBuild ] || ( data.subBuildsCache[ subBuild ] = {} );
|
|
1811
|
+
data.subBuilds = subBuilds;
|
|
1812
|
+
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
return data;
|
|
798
1816
|
|
|
799
1817
|
}
|
|
800
1818
|
|
|
1819
|
+
/**
|
|
1820
|
+
* Returns the properties for the given node and shader stage.
|
|
1821
|
+
*
|
|
1822
|
+
* Properties are typically used within a build stage to reference a node's
|
|
1823
|
+
* child node or nodes manually assigned to the properties in a separate build stage.
|
|
1824
|
+
* A typical usage pattern for defining nodes manually would be assigning dependency nodes
|
|
1825
|
+
* to the current node's properties in the setup stage and building those properties in the generate stage.
|
|
1826
|
+
*
|
|
1827
|
+
* @param {Node} node - The node to get the properties for.
|
|
1828
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage='any'] - The shader stage.
|
|
1829
|
+
* @return {Object} The node properties.
|
|
1830
|
+
*/
|
|
801
1831
|
getNodeProperties( node, shaderStage = 'any' ) {
|
|
802
1832
|
|
|
803
1833
|
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
@@ -806,9 +1836,16 @@ class NodeBuilder {
|
|
|
806
1836
|
|
|
807
1837
|
}
|
|
808
1838
|
|
|
1839
|
+
/**
|
|
1840
|
+
* Returns an instance of {@link NodeAttribute} for the given buffer attribute node.
|
|
1841
|
+
*
|
|
1842
|
+
* @param {BufferAttributeNode} node - The buffer attribute node.
|
|
1843
|
+
* @param {string} type - The node type.
|
|
1844
|
+
* @return {NodeAttribute} The node attribute.
|
|
1845
|
+
*/
|
|
809
1846
|
getBufferAttributeFromNode( node, type ) {
|
|
810
1847
|
|
|
811
|
-
const nodeData = this.getDataFromNode( node );
|
|
1848
|
+
const nodeData = this.getDataFromNode( node, 'vertex' );
|
|
812
1849
|
|
|
813
1850
|
let bufferAttribute = nodeData.bufferAttribute;
|
|
814
1851
|
|
|
@@ -828,25 +1865,79 @@ class NodeBuilder {
|
|
|
828
1865
|
|
|
829
1866
|
}
|
|
830
1867
|
|
|
831
|
-
|
|
1868
|
+
/**
|
|
1869
|
+
* Returns an instance of {@link StructType} for the given struct name and shader stage
|
|
1870
|
+
* or null if not found.
|
|
1871
|
+
*
|
|
1872
|
+
* @param {string} name - The name of the struct.
|
|
1873
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1874
|
+
* @return {?StructType} The struct type or null if not found.
|
|
1875
|
+
*/
|
|
1876
|
+
getStructTypeNode( name, shaderStage = this.shaderStage ) {
|
|
832
1877
|
|
|
833
|
-
|
|
1878
|
+
return this.types[ shaderStage ][ name ] || null;
|
|
1879
|
+
|
|
1880
|
+
}
|
|
834
1881
|
|
|
835
|
-
|
|
1882
|
+
/**
|
|
1883
|
+
* Returns an instance of {@link StructType} for the given output struct node.
|
|
1884
|
+
*
|
|
1885
|
+
* @param {OutputStructNode} node - The output struct node.
|
|
1886
|
+
* @param {Array<Object>} membersLayout - The output struct types.
|
|
1887
|
+
* @param {?string} [name=null] - The name of the struct.
|
|
1888
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1889
|
+
* @return {StructType} The struct type attribute.
|
|
1890
|
+
*/
|
|
1891
|
+
getStructTypeFromNode( node, membersLayout, name = null, shaderStage = this.shaderStage ) {
|
|
1892
|
+
|
|
1893
|
+
const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
|
|
1894
|
+
|
|
1895
|
+
let structType = nodeData.structType;
|
|
1896
|
+
|
|
1897
|
+
if ( structType === undefined ) {
|
|
836
1898
|
|
|
837
1899
|
const index = this.structs.index ++;
|
|
838
1900
|
|
|
839
|
-
|
|
840
|
-
this.structs[ shaderStage ].push( node );
|
|
1901
|
+
if ( name === null ) name = 'StructType' + index;
|
|
841
1902
|
|
|
842
|
-
|
|
1903
|
+
structType = new StructType( name, membersLayout );
|
|
1904
|
+
|
|
1905
|
+
this.structs[ shaderStage ].push( structType );
|
|
1906
|
+
this.types[ shaderStage ][ name ] = node;
|
|
1907
|
+
|
|
1908
|
+
nodeData.structType = structType;
|
|
843
1909
|
|
|
844
1910
|
}
|
|
845
1911
|
|
|
846
|
-
return
|
|
1912
|
+
return structType;
|
|
847
1913
|
|
|
848
1914
|
}
|
|
849
1915
|
|
|
1916
|
+
/**
|
|
1917
|
+
* Returns an instance of {@link StructType} for the given output struct node.
|
|
1918
|
+
*
|
|
1919
|
+
* @param {OutputStructNode} node - The output struct node.
|
|
1920
|
+
* @param {Array<Object>} membersLayout - The output struct types.
|
|
1921
|
+
* @return {StructType} The struct type attribute.
|
|
1922
|
+
*/
|
|
1923
|
+
getOutputStructTypeFromNode( node, membersLayout ) {
|
|
1924
|
+
|
|
1925
|
+
const structType = this.getStructTypeFromNode( node, membersLayout, 'OutputType', 'fragment' );
|
|
1926
|
+
structType.output = true;
|
|
1927
|
+
|
|
1928
|
+
return structType;
|
|
1929
|
+
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
/**
|
|
1933
|
+
* Returns an instance of {@link NodeUniform} for the given uniform node.
|
|
1934
|
+
*
|
|
1935
|
+
* @param {UniformNode} node - The uniform node.
|
|
1936
|
+
* @param {string} type - The uniform type.
|
|
1937
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1938
|
+
* @param {?string} name - The name of the uniform.
|
|
1939
|
+
* @return {NodeUniform} The node uniform.
|
|
1940
|
+
*/
|
|
850
1941
|
getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) {
|
|
851
1942
|
|
|
852
1943
|
if ( name === 'in' ) {
|
|
@@ -869,6 +1960,8 @@ class NodeBuilder {
|
|
|
869
1960
|
|
|
870
1961
|
this.uniforms[ shaderStage ].push( nodeUniform );
|
|
871
1962
|
|
|
1963
|
+
this.registerDeclaration( nodeUniform );
|
|
1964
|
+
|
|
872
1965
|
nodeData.uniform = nodeUniform;
|
|
873
1966
|
|
|
874
1967
|
}
|
|
@@ -877,23 +1970,62 @@ class NodeBuilder {
|
|
|
877
1970
|
|
|
878
1971
|
}
|
|
879
1972
|
|
|
880
|
-
|
|
1973
|
+
/**
|
|
1974
|
+
* Returns an instance of {@link NodeVar} for the given variable node.
|
|
1975
|
+
*
|
|
1976
|
+
* @param {VarNode} node - The variable node.
|
|
1977
|
+
* @param {?string} name - The variable's name.
|
|
1978
|
+
* @param {string} [type=node.getNodeType( this )] - The variable's type.
|
|
1979
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1980
|
+
* @param {boolean} [readOnly=false] - Whether the variable is read-only or not.
|
|
1981
|
+
*
|
|
1982
|
+
* @return {NodeVar} The node variable.
|
|
1983
|
+
*/
|
|
1984
|
+
getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage, readOnly = false ) {
|
|
881
1985
|
|
|
882
1986
|
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
1987
|
+
const subBuildVariable = this.getSubBuildProperty( 'variable', nodeData.subBuilds );
|
|
883
1988
|
|
|
884
|
-
let nodeVar = nodeData
|
|
1989
|
+
let nodeVar = nodeData[ subBuildVariable ];
|
|
885
1990
|
|
|
886
1991
|
if ( nodeVar === undefined ) {
|
|
887
1992
|
|
|
1993
|
+
const idNS = readOnly ? '_const' : '_var';
|
|
1994
|
+
|
|
888
1995
|
const vars = this.vars[ shaderStage ] || ( this.vars[ shaderStage ] = [] );
|
|
1996
|
+
const id = this.vars[ idNS ] || ( this.vars[ idNS ] = 0 );
|
|
889
1997
|
|
|
890
|
-
if ( name === null )
|
|
1998
|
+
if ( name === null ) {
|
|
891
1999
|
|
|
892
|
-
|
|
2000
|
+
name = ( readOnly ? 'nodeConst' : 'nodeVar' ) + id;
|
|
893
2001
|
|
|
894
|
-
|
|
2002
|
+
this.vars[ idNS ] ++;
|
|
895
2003
|
|
|
896
|
-
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
//
|
|
2007
|
+
|
|
2008
|
+
if ( subBuildVariable !== 'variable' ) {
|
|
2009
|
+
|
|
2010
|
+
name = this.getSubBuildProperty( name, nodeData.subBuilds );
|
|
2011
|
+
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
//
|
|
2015
|
+
|
|
2016
|
+
const count = node.getArrayCount( this );
|
|
2017
|
+
|
|
2018
|
+
nodeVar = new NodeVar( name, type, readOnly, count );
|
|
2019
|
+
|
|
2020
|
+
if ( ! readOnly ) {
|
|
2021
|
+
|
|
2022
|
+
vars.push( nodeVar );
|
|
2023
|
+
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
this.registerDeclaration( nodeVar );
|
|
2027
|
+
|
|
2028
|
+
nodeData[ subBuildVariable ] = nodeVar;
|
|
897
2029
|
|
|
898
2030
|
}
|
|
899
2031
|
|
|
@@ -901,11 +2033,69 @@ class NodeBuilder {
|
|
|
901
2033
|
|
|
902
2034
|
}
|
|
903
2035
|
|
|
904
|
-
|
|
2036
|
+
/**
|
|
2037
|
+
* Returns whether a Node or its flow is deterministic, useful for use in `const`.
|
|
2038
|
+
*
|
|
2039
|
+
* @param {Node} node - The varying node.
|
|
2040
|
+
* @return {boolean} Returns true if deterministic.
|
|
2041
|
+
*/
|
|
2042
|
+
isDeterministic( node ) {
|
|
2043
|
+
|
|
2044
|
+
if ( node.isMathNode ) {
|
|
2045
|
+
|
|
2046
|
+
return this.isDeterministic( node.aNode ) &&
|
|
2047
|
+
( node.bNode ? this.isDeterministic( node.bNode ) : true ) &&
|
|
2048
|
+
( node.cNode ? this.isDeterministic( node.cNode ) : true );
|
|
2049
|
+
|
|
2050
|
+
} else if ( node.isOperatorNode ) {
|
|
2051
|
+
|
|
2052
|
+
return this.isDeterministic( node.aNode ) &&
|
|
2053
|
+
( node.bNode ? this.isDeterministic( node.bNode ) : true );
|
|
2054
|
+
|
|
2055
|
+
} else if ( node.isArrayNode ) {
|
|
2056
|
+
|
|
2057
|
+
if ( node.values !== null ) {
|
|
2058
|
+
|
|
2059
|
+
for ( const n of node.values ) {
|
|
2060
|
+
|
|
2061
|
+
if ( ! this.isDeterministic( n ) ) {
|
|
2062
|
+
|
|
2063
|
+
return false;
|
|
2064
|
+
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
return true;
|
|
2072
|
+
|
|
2073
|
+
} else if ( node.isConstNode ) {
|
|
2074
|
+
|
|
2075
|
+
return true;
|
|
2076
|
+
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
return false;
|
|
2080
|
+
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
/**
|
|
2084
|
+
* Returns an instance of {@link NodeVarying} for the given varying node.
|
|
2085
|
+
*
|
|
2086
|
+
* @param {(VaryingNode|PropertyNode)} node - The varying node.
|
|
2087
|
+
* @param {?string} name - The varying's name.
|
|
2088
|
+
* @param {string} [type=node.getNodeType( this )] - The varying's type.
|
|
2089
|
+
* @param {?string} interpolationType - The interpolation type of the varying.
|
|
2090
|
+
* @param {?string} interpolationSampling - The interpolation sampling type of the varying.
|
|
2091
|
+
* @return {NodeVar} The node varying.
|
|
2092
|
+
*/
|
|
2093
|
+
getVaryingFromNode( node, name = null, type = node.getNodeType( this ), interpolationType = null, interpolationSampling = null ) {
|
|
905
2094
|
|
|
906
2095
|
const nodeData = this.getDataFromNode( node, 'any' );
|
|
2096
|
+
const subBuildVarying = this.getSubBuildProperty( 'varying', nodeData.subBuilds );
|
|
907
2097
|
|
|
908
|
-
let nodeVarying = nodeData
|
|
2098
|
+
let nodeVarying = nodeData[ subBuildVarying ];
|
|
909
2099
|
|
|
910
2100
|
if ( nodeVarying === undefined ) {
|
|
911
2101
|
|
|
@@ -914,11 +2104,23 @@ class NodeBuilder {
|
|
|
914
2104
|
|
|
915
2105
|
if ( name === null ) name = 'nodeVarying' + index;
|
|
916
2106
|
|
|
917
|
-
|
|
2107
|
+
//
|
|
2108
|
+
|
|
2109
|
+
if ( subBuildVarying !== 'varying' ) {
|
|
2110
|
+
|
|
2111
|
+
name = this.getSubBuildProperty( name, nodeData.subBuilds );
|
|
2112
|
+
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
//
|
|
2116
|
+
|
|
2117
|
+
nodeVarying = new NodeVarying( name, type, interpolationType, interpolationSampling );
|
|
918
2118
|
|
|
919
2119
|
varyings.push( nodeVarying );
|
|
920
2120
|
|
|
921
|
-
|
|
2121
|
+
this.registerDeclaration( nodeVarying );
|
|
2122
|
+
|
|
2123
|
+
nodeData[ subBuildVarying ] = nodeVarying;
|
|
922
2124
|
|
|
923
2125
|
}
|
|
924
2126
|
|
|
@@ -926,6 +2128,49 @@ class NodeBuilder {
|
|
|
926
2128
|
|
|
927
2129
|
}
|
|
928
2130
|
|
|
2131
|
+
/**
|
|
2132
|
+
* Registers a node declaration in the current shader stage.
|
|
2133
|
+
*
|
|
2134
|
+
* @param {Object} node - The node to be registered.
|
|
2135
|
+
*/
|
|
2136
|
+
registerDeclaration( node ) {
|
|
2137
|
+
|
|
2138
|
+
const shaderStage = this.shaderStage;
|
|
2139
|
+
const declarations = this.declarations[ shaderStage ] || ( this.declarations[ shaderStage ] = {} );
|
|
2140
|
+
|
|
2141
|
+
const property = this.getPropertyName( node );
|
|
2142
|
+
|
|
2143
|
+
let index = 1;
|
|
2144
|
+
let name = property;
|
|
2145
|
+
|
|
2146
|
+
// Automatically renames the property if the name is already in use.
|
|
2147
|
+
|
|
2148
|
+
while ( declarations[ name ] !== undefined ) {
|
|
2149
|
+
|
|
2150
|
+
name = property + '_' + index ++;
|
|
2151
|
+
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
if ( index > 1 ) {
|
|
2155
|
+
|
|
2156
|
+
node.name = name;
|
|
2157
|
+
|
|
2158
|
+
warn( `TSL: Declaration name '${ property }' of '${ node.type }' already in use. Renamed to '${ name }'.` );
|
|
2159
|
+
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
declarations[ name ] = node;
|
|
2163
|
+
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
/**
|
|
2167
|
+
* Returns an instance of {@link NodeCode} for the given code node.
|
|
2168
|
+
*
|
|
2169
|
+
* @param {CodeNode} node - The code node.
|
|
2170
|
+
* @param {string} type - The node type.
|
|
2171
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
2172
|
+
* @return {NodeCode} The node code.
|
|
2173
|
+
*/
|
|
929
2174
|
getCodeFromNode( node, type, shaderStage = this.shaderStage ) {
|
|
930
2175
|
|
|
931
2176
|
const nodeData = this.getDataFromNode( node );
|
|
@@ -949,6 +2194,15 @@ class NodeBuilder {
|
|
|
949
2194
|
|
|
950
2195
|
}
|
|
951
2196
|
|
|
2197
|
+
/**
|
|
2198
|
+
* Adds a code flow based on the code-block hierarchy.
|
|
2199
|
+
|
|
2200
|
+
* This is used so that code-blocks like If,Else create their variables locally if the Node
|
|
2201
|
+
* is only used inside one of these conditionals in the current shader stage.
|
|
2202
|
+
*
|
|
2203
|
+
* @param {Node} node - The node to add.
|
|
2204
|
+
* @param {Node} nodeBlock - Node-based code-block. Usually 'ConditionalNode'.
|
|
2205
|
+
*/
|
|
952
2206
|
addFlowCodeHierarchy( node, nodeBlock ) {
|
|
953
2207
|
|
|
954
2208
|
const { flowCodes, flowCodeBlock } = this.getDataFromNode( node );
|
|
@@ -981,6 +2235,13 @@ class NodeBuilder {
|
|
|
981
2235
|
|
|
982
2236
|
}
|
|
983
2237
|
|
|
2238
|
+
/**
|
|
2239
|
+
* Add a inline-code to the current flow code-block.
|
|
2240
|
+
*
|
|
2241
|
+
* @param {Node} node - The node to add.
|
|
2242
|
+
* @param {string} code - The code to add.
|
|
2243
|
+
* @param {Node} nodeBlock - Current ConditionalNode
|
|
2244
|
+
*/
|
|
984
2245
|
addLineFlowCodeBlock( node, code, nodeBlock ) {
|
|
985
2246
|
|
|
986
2247
|
const nodeData = this.getDataFromNode( node );
|
|
@@ -992,6 +2253,13 @@ class NodeBuilder {
|
|
|
992
2253
|
|
|
993
2254
|
}
|
|
994
2255
|
|
|
2256
|
+
/**
|
|
2257
|
+
* Add a inline-code to the current flow.
|
|
2258
|
+
*
|
|
2259
|
+
* @param {string} code - The code to add.
|
|
2260
|
+
* @param {?Node} [node= null] - Optional Node, can help the system understand if the Node is part of a code-block.
|
|
2261
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
2262
|
+
*/
|
|
995
2263
|
addLineFlowCode( code, node = null ) {
|
|
996
2264
|
|
|
997
2265
|
if ( code === '' ) return this;
|
|
@@ -1016,6 +2284,12 @@ class NodeBuilder {
|
|
|
1016
2284
|
|
|
1017
2285
|
}
|
|
1018
2286
|
|
|
2287
|
+
/**
|
|
2288
|
+
* Adds a code to the current code flow.
|
|
2289
|
+
*
|
|
2290
|
+
* @param {string} code - Shader code.
|
|
2291
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
2292
|
+
*/
|
|
1019
2293
|
addFlowCode( code ) {
|
|
1020
2294
|
|
|
1021
2295
|
this.flow.code += code;
|
|
@@ -1024,6 +2298,12 @@ class NodeBuilder {
|
|
|
1024
2298
|
|
|
1025
2299
|
}
|
|
1026
2300
|
|
|
2301
|
+
/**
|
|
2302
|
+
* Add tab in the code that will be generated so that other snippets respect the current tabulation.
|
|
2303
|
+
* Typically used in codes with If,Else.
|
|
2304
|
+
*
|
|
2305
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
2306
|
+
*/
|
|
1027
2307
|
addFlowTab() {
|
|
1028
2308
|
|
|
1029
2309
|
this.tab += '\t';
|
|
@@ -1032,6 +2312,11 @@ class NodeBuilder {
|
|
|
1032
2312
|
|
|
1033
2313
|
}
|
|
1034
2314
|
|
|
2315
|
+
/**
|
|
2316
|
+
* Removes a tab.
|
|
2317
|
+
*
|
|
2318
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
2319
|
+
*/
|
|
1035
2320
|
removeFlowTab() {
|
|
1036
2321
|
|
|
1037
2322
|
this.tab = this.tab.slice( 0, - 1 );
|
|
@@ -1040,12 +2325,25 @@ class NodeBuilder {
|
|
|
1040
2325
|
|
|
1041
2326
|
}
|
|
1042
2327
|
|
|
2328
|
+
/**
|
|
2329
|
+
* Gets the current flow data based on a Node.
|
|
2330
|
+
*
|
|
2331
|
+
* @param {Node} node - Node that the flow was started.
|
|
2332
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2333
|
+
* @return {Object} The flow data.
|
|
2334
|
+
*/
|
|
1043
2335
|
getFlowData( node/*, shaderStage*/ ) {
|
|
1044
2336
|
|
|
1045
2337
|
return this.flowsData.get( node );
|
|
1046
2338
|
|
|
1047
2339
|
}
|
|
1048
2340
|
|
|
2341
|
+
/**
|
|
2342
|
+
* Executes the node flow based on a root node to generate the final shader code.
|
|
2343
|
+
*
|
|
2344
|
+
* @param {Node} node - The node to execute.
|
|
2345
|
+
* @return {Object} The code flow.
|
|
2346
|
+
*/
|
|
1049
2347
|
flowNode( node ) {
|
|
1050
2348
|
|
|
1051
2349
|
const output = node.getNodeType( this );
|
|
@@ -1058,6 +2356,29 @@ class NodeBuilder {
|
|
|
1058
2356
|
|
|
1059
2357
|
}
|
|
1060
2358
|
|
|
2359
|
+
/**
|
|
2360
|
+
* Includes a node in the current function node.
|
|
2361
|
+
*
|
|
2362
|
+
* @param {Node} node - The node to include.
|
|
2363
|
+
* @returns {void}
|
|
2364
|
+
*/
|
|
2365
|
+
addInclude( node ) {
|
|
2366
|
+
|
|
2367
|
+
if ( this.currentFunctionNode !== null ) {
|
|
2368
|
+
|
|
2369
|
+
this.currentFunctionNode.includes.push( node );
|
|
2370
|
+
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
/**
|
|
2376
|
+
* Returns the native shader operator name for a given generic name.
|
|
2377
|
+
* It is a similar type of method like {@link NodeBuilder#getMethod}.
|
|
2378
|
+
*
|
|
2379
|
+
* @param {ShaderNodeInternal} shaderNode - The shader node to build the function node with.
|
|
2380
|
+
* @return {FunctionNode} The build function node.
|
|
2381
|
+
*/
|
|
1061
2382
|
buildFunctionNode( shaderNode ) {
|
|
1062
2383
|
|
|
1063
2384
|
const fn = new FunctionNode();
|
|
@@ -1074,6 +2395,12 @@ class NodeBuilder {
|
|
|
1074
2395
|
|
|
1075
2396
|
}
|
|
1076
2397
|
|
|
2398
|
+
/**
|
|
2399
|
+
* Generates a code flow based on a TSL function: Fn().
|
|
2400
|
+
*
|
|
2401
|
+
* @param {ShaderNodeInternal} shaderNode - A function code will be generated based on the input.
|
|
2402
|
+
* @return {Object}
|
|
2403
|
+
*/
|
|
1077
2404
|
flowShaderNode( shaderNode ) {
|
|
1078
2405
|
|
|
1079
2406
|
const layout = shaderNode.layout;
|
|
@@ -1112,10 +2439,46 @@ class NodeBuilder {
|
|
|
1112
2439
|
|
|
1113
2440
|
}
|
|
1114
2441
|
|
|
2442
|
+
/**
|
|
2443
|
+
* Executes the node in a specific build stage.
|
|
2444
|
+
*
|
|
2445
|
+
* This function can be used to arbitrarily execute the specified build stage
|
|
2446
|
+
* outside of the standard build process. For instance, if a node's type depends
|
|
2447
|
+
* on properties created by the 'setup' stage, then flowBuildStage(node, 'setup')
|
|
2448
|
+
* can be used to execute the setup build stage and access its generated nodes
|
|
2449
|
+
* before the standard build process begins.
|
|
2450
|
+
*
|
|
2451
|
+
* @param {Node} node - The node to execute.
|
|
2452
|
+
* @param {string} buildStage - The build stage to execute the node in.
|
|
2453
|
+
* @param {?(Node|string)} [output=null] - Expected output type. For example 'vec3'.
|
|
2454
|
+
* @return {?(Node|string)} The result of the node build.
|
|
2455
|
+
*/
|
|
2456
|
+
flowBuildStage( node, buildStage, output = null ) {
|
|
2457
|
+
|
|
2458
|
+
const previousBuildStage = this.getBuildStage();
|
|
2459
|
+
|
|
2460
|
+
this.setBuildStage( buildStage );
|
|
2461
|
+
|
|
2462
|
+
const result = node.build( this, output );
|
|
2463
|
+
|
|
2464
|
+
this.setBuildStage( previousBuildStage );
|
|
2465
|
+
|
|
2466
|
+
return result;
|
|
2467
|
+
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
/**
|
|
2471
|
+
* Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
|
|
2472
|
+
*
|
|
2473
|
+
* @param {Node} node - The node to execute.
|
|
2474
|
+
* @param {?string} output - Expected output type. For example 'vec3'.
|
|
2475
|
+
* @return {Object}
|
|
2476
|
+
*/
|
|
1115
2477
|
flowStagesNode( node, output = null ) {
|
|
1116
2478
|
|
|
1117
2479
|
const previousFlow = this.flow;
|
|
1118
2480
|
const previousVars = this.vars;
|
|
2481
|
+
const previousDeclarations = this.declarations;
|
|
1119
2482
|
const previousCache = this.cache;
|
|
1120
2483
|
const previousBuildStage = this.buildStage;
|
|
1121
2484
|
const previousStack = this.stack;
|
|
@@ -1126,6 +2489,7 @@ class NodeBuilder {
|
|
|
1126
2489
|
|
|
1127
2490
|
this.flow = flow;
|
|
1128
2491
|
this.vars = {};
|
|
2492
|
+
this.declarations = {};
|
|
1129
2493
|
this.cache = new NodeCache();
|
|
1130
2494
|
this.stack = stack();
|
|
1131
2495
|
|
|
@@ -1141,6 +2505,7 @@ class NodeBuilder {
|
|
|
1141
2505
|
|
|
1142
2506
|
this.flow = previousFlow;
|
|
1143
2507
|
this.vars = previousVars;
|
|
2508
|
+
this.declarations = previousDeclarations;
|
|
1144
2509
|
this.cache = previousCache;
|
|
1145
2510
|
this.stack = previousStack;
|
|
1146
2511
|
|
|
@@ -1150,12 +2515,40 @@ class NodeBuilder {
|
|
|
1150
2515
|
|
|
1151
2516
|
}
|
|
1152
2517
|
|
|
1153
|
-
|
|
2518
|
+
/**
|
|
2519
|
+
* Returns the native shader operator name for a given generic name.
|
|
2520
|
+
* It is a similar type of method like {@link NodeBuilder#getMethod}.
|
|
2521
|
+
*
|
|
2522
|
+
* @abstract
|
|
2523
|
+
* @param {string} op - The operator name to resolve.
|
|
2524
|
+
* @return {?string} The resolved operator name.
|
|
2525
|
+
*/
|
|
2526
|
+
getFunctionOperator( /* op */ ) {
|
|
1154
2527
|
|
|
1155
2528
|
return null;
|
|
1156
2529
|
|
|
1157
2530
|
}
|
|
1158
2531
|
|
|
2532
|
+
/**
|
|
2533
|
+
* Builds the given shader node.
|
|
2534
|
+
*
|
|
2535
|
+
* @abstract
|
|
2536
|
+
* @param {ShaderNodeInternal} shaderNode - The shader node.
|
|
2537
|
+
* @return {string} The function code.
|
|
2538
|
+
*/
|
|
2539
|
+
buildFunctionCode( /* shaderNode */ ) {
|
|
2540
|
+
|
|
2541
|
+
warn( 'Abstract function.' );
|
|
2542
|
+
|
|
2543
|
+
}
|
|
2544
|
+
|
|
2545
|
+
/**
|
|
2546
|
+
* Generates a code flow based on a child Node.
|
|
2547
|
+
*
|
|
2548
|
+
* @param {Node} node - The node to execute.
|
|
2549
|
+
* @param {?string} output - Expected output type. For example 'vec3'.
|
|
2550
|
+
* @return {Object} The code flow.
|
|
2551
|
+
*/
|
|
1159
2552
|
flowChildNode( node, output = null ) {
|
|
1160
2553
|
|
|
1161
2554
|
const previousFlow = this.flow;
|
|
@@ -1174,52 +2567,123 @@ class NodeBuilder {
|
|
|
1174
2567
|
|
|
1175
2568
|
}
|
|
1176
2569
|
|
|
2570
|
+
/**
|
|
2571
|
+
* Executes a flow of code in a different stage.
|
|
2572
|
+
*
|
|
2573
|
+
* Some nodes like `varying()` have the ability to compute code in vertex-stage and
|
|
2574
|
+
* return the value in fragment-stage even if it is being executed in an input fragment.
|
|
2575
|
+
*
|
|
2576
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2577
|
+
* @param {Node} node - The node to execute.
|
|
2578
|
+
* @param {?string} output - Expected output type. For example 'vec3'.
|
|
2579
|
+
* @param {?string} propertyName - The property name to assign the result.
|
|
2580
|
+
* @return {?(Object|Node)} The code flow or node.build() result.
|
|
2581
|
+
*/
|
|
1177
2582
|
flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
|
|
1178
2583
|
|
|
2584
|
+
const previousTab = this.tab;
|
|
2585
|
+
const previousCache = this.cache;
|
|
1179
2586
|
const previousShaderStage = this.shaderStage;
|
|
2587
|
+
const previousContext = this.context;
|
|
1180
2588
|
|
|
1181
2589
|
this.setShaderStage( shaderStage );
|
|
1182
2590
|
|
|
1183
|
-
const
|
|
2591
|
+
const context = { ...this.context };
|
|
2592
|
+
delete context.nodeBlock;
|
|
2593
|
+
|
|
2594
|
+
this.cache = this.globalCache;
|
|
2595
|
+
this.tab = '\t';
|
|
2596
|
+
this.context = context;
|
|
1184
2597
|
|
|
1185
|
-
|
|
2598
|
+
let result = null;
|
|
1186
2599
|
|
|
1187
|
-
|
|
2600
|
+
if ( this.buildStage === 'generate' ) {
|
|
1188
2601
|
|
|
1189
|
-
|
|
2602
|
+
const flowData = this.flowChildNode( node, output );
|
|
1190
2603
|
|
|
1191
|
-
|
|
2604
|
+
if ( propertyName !== null ) {
|
|
2605
|
+
|
|
2606
|
+
flowData.code += `${ this.tab + propertyName } = ${ flowData.result };\n`;
|
|
2607
|
+
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
this.flowCode[ shaderStage ] = this.flowCode[ shaderStage ] + flowData.code;
|
|
2611
|
+
|
|
2612
|
+
result = flowData;
|
|
2613
|
+
|
|
2614
|
+
} else {
|
|
2615
|
+
|
|
2616
|
+
result = node.build( this );
|
|
2617
|
+
|
|
2618
|
+
}
|
|
1192
2619
|
|
|
1193
2620
|
this.setShaderStage( previousShaderStage );
|
|
1194
2621
|
|
|
1195
|
-
|
|
2622
|
+
this.cache = previousCache;
|
|
2623
|
+
this.tab = previousTab;
|
|
2624
|
+
this.context = previousContext;
|
|
2625
|
+
|
|
2626
|
+
return result;
|
|
1196
2627
|
|
|
1197
2628
|
}
|
|
1198
2629
|
|
|
2630
|
+
/**
|
|
2631
|
+
* Returns an array holding all node attributes of this node builder.
|
|
2632
|
+
*
|
|
2633
|
+
* @return {Array<NodeAttribute>} The node attributes of this builder.
|
|
2634
|
+
*/
|
|
1199
2635
|
getAttributesArray() {
|
|
1200
2636
|
|
|
1201
2637
|
return this.attributes.concat( this.bufferAttributes );
|
|
1202
2638
|
|
|
1203
2639
|
}
|
|
1204
2640
|
|
|
2641
|
+
/**
|
|
2642
|
+
* Returns the attribute definitions as a shader string for the given shader stage.
|
|
2643
|
+
*
|
|
2644
|
+
* @abstract
|
|
2645
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2646
|
+
* @return {string} The attribute code section.
|
|
2647
|
+
*/
|
|
1205
2648
|
getAttributes( /*shaderStage*/ ) {
|
|
1206
2649
|
|
|
1207
|
-
|
|
2650
|
+
warn( 'Abstract function.' );
|
|
1208
2651
|
|
|
1209
2652
|
}
|
|
1210
2653
|
|
|
2654
|
+
/**
|
|
2655
|
+
* Returns the varying definitions as a shader string for the given shader stage.
|
|
2656
|
+
*
|
|
2657
|
+
* @abstract
|
|
2658
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2659
|
+
* @return {string} The varying code section.
|
|
2660
|
+
*/
|
|
1211
2661
|
getVaryings( /*shaderStage*/ ) {
|
|
1212
2662
|
|
|
1213
|
-
|
|
2663
|
+
warn( 'Abstract function.' );
|
|
1214
2664
|
|
|
1215
2665
|
}
|
|
1216
2666
|
|
|
1217
|
-
|
|
2667
|
+
/**
|
|
2668
|
+
* Returns a single variable definition as a shader string for the given variable type and name.
|
|
2669
|
+
*
|
|
2670
|
+
* @param {string} type - The variable's type.
|
|
2671
|
+
* @param {string} name - The variable's name.
|
|
2672
|
+
* @param {?number} [count=null] - The array length.
|
|
2673
|
+
* @return {string} The shader string.
|
|
2674
|
+
*/
|
|
2675
|
+
getVar( type, name, count = null ) {
|
|
1218
2676
|
|
|
1219
|
-
return `${ this.getType( type ) } ${ name }`;
|
|
2677
|
+
return `${ count !== null ? this.generateArrayDeclaration( type, count ) : this.getType( type ) } ${ name }`;
|
|
1220
2678
|
|
|
1221
2679
|
}
|
|
1222
2680
|
|
|
2681
|
+
/**
|
|
2682
|
+
* Returns the variable definitions as a shader string for the given shader stage.
|
|
2683
|
+
*
|
|
2684
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2685
|
+
* @return {string} The variable code section.
|
|
2686
|
+
*/
|
|
1223
2687
|
getVars( shaderStage ) {
|
|
1224
2688
|
|
|
1225
2689
|
let snippet = '';
|
|
@@ -1240,12 +2704,25 @@ class NodeBuilder {
|
|
|
1240
2704
|
|
|
1241
2705
|
}
|
|
1242
2706
|
|
|
2707
|
+
/**
|
|
2708
|
+
* Returns the uniform definitions as a shader string for the given shader stage.
|
|
2709
|
+
*
|
|
2710
|
+
* @abstract
|
|
2711
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2712
|
+
* @return {string} The uniform code section.
|
|
2713
|
+
*/
|
|
1243
2714
|
getUniforms( /*shaderStage*/ ) {
|
|
1244
2715
|
|
|
1245
|
-
|
|
2716
|
+
warn( 'Abstract function.' );
|
|
1246
2717
|
|
|
1247
2718
|
}
|
|
1248
2719
|
|
|
2720
|
+
/**
|
|
2721
|
+
* Returns the native code definitions as a shader string for the given shader stage.
|
|
2722
|
+
*
|
|
2723
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2724
|
+
* @return {string} The native code section.
|
|
2725
|
+
*/
|
|
1249
2726
|
getCodes( shaderStage ) {
|
|
1250
2727
|
|
|
1251
2728
|
const codes = this.codes[ shaderStage ];
|
|
@@ -1266,53 +2743,227 @@ class NodeBuilder {
|
|
|
1266
2743
|
|
|
1267
2744
|
}
|
|
1268
2745
|
|
|
2746
|
+
/**
|
|
2747
|
+
* Returns the hash of this node builder.
|
|
2748
|
+
*
|
|
2749
|
+
* @return {string} The hash.
|
|
2750
|
+
*/
|
|
1269
2751
|
getHash() {
|
|
1270
2752
|
|
|
1271
2753
|
return this.vertexShader + this.fragmentShader + this.computeShader;
|
|
1272
2754
|
|
|
1273
2755
|
}
|
|
1274
2756
|
|
|
2757
|
+
/**
|
|
2758
|
+
* Sets the current shader stage.
|
|
2759
|
+
*
|
|
2760
|
+
* @param {?('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage to set.
|
|
2761
|
+
*/
|
|
1275
2762
|
setShaderStage( shaderStage ) {
|
|
1276
2763
|
|
|
1277
2764
|
this.shaderStage = shaderStage;
|
|
1278
2765
|
|
|
1279
2766
|
}
|
|
1280
2767
|
|
|
2768
|
+
/**
|
|
2769
|
+
* Returns the current shader stage.
|
|
2770
|
+
*
|
|
2771
|
+
* @return {?('vertex'|'fragment'|'compute'|'any')} The current shader stage.
|
|
2772
|
+
*/
|
|
1281
2773
|
getShaderStage() {
|
|
1282
2774
|
|
|
1283
2775
|
return this.shaderStage;
|
|
1284
2776
|
|
|
1285
2777
|
}
|
|
1286
2778
|
|
|
2779
|
+
/**
|
|
2780
|
+
* Sets the current build stage.
|
|
2781
|
+
*
|
|
2782
|
+
* @param {?('setup'|'analyze'|'generate')} buildStage - The build stage to set.
|
|
2783
|
+
*/
|
|
1287
2784
|
setBuildStage( buildStage ) {
|
|
1288
2785
|
|
|
1289
2786
|
this.buildStage = buildStage;
|
|
1290
2787
|
|
|
1291
2788
|
}
|
|
1292
2789
|
|
|
2790
|
+
/**
|
|
2791
|
+
* Returns the current build stage.
|
|
2792
|
+
*
|
|
2793
|
+
* @return {?('setup'|'analyze'|'generate')} The current build stage.
|
|
2794
|
+
*/
|
|
1293
2795
|
getBuildStage() {
|
|
1294
2796
|
|
|
1295
2797
|
return this.buildStage;
|
|
1296
2798
|
|
|
1297
2799
|
}
|
|
1298
2800
|
|
|
2801
|
+
/**
|
|
2802
|
+
* Controls the code build of the shader stages.
|
|
2803
|
+
*
|
|
2804
|
+
* @abstract
|
|
2805
|
+
*/
|
|
1299
2806
|
buildCode() {
|
|
1300
2807
|
|
|
1301
|
-
|
|
2808
|
+
warn( 'Abstract function.' );
|
|
1302
2809
|
|
|
1303
2810
|
}
|
|
1304
2811
|
|
|
2812
|
+
/**
|
|
2813
|
+
* Returns the current sub-build layer.
|
|
2814
|
+
*
|
|
2815
|
+
* @return {SubBuildNode} The current sub-build layers.
|
|
2816
|
+
*/
|
|
2817
|
+
get subBuild() {
|
|
2818
|
+
|
|
2819
|
+
return this.subBuildLayers[ this.subBuildLayers.length - 1 ] || null;
|
|
2820
|
+
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
/**
|
|
2824
|
+
* Adds a sub-build layer to the node builder.
|
|
2825
|
+
*
|
|
2826
|
+
* @param {SubBuildNode} subBuild - The sub-build layer to add.
|
|
2827
|
+
*/
|
|
2828
|
+
addSubBuild( subBuild ) {
|
|
2829
|
+
|
|
2830
|
+
this.subBuildLayers.push( subBuild );
|
|
2831
|
+
|
|
2832
|
+
}
|
|
2833
|
+
|
|
2834
|
+
/**
|
|
2835
|
+
* Removes the last sub-build layer from the node builder.
|
|
2836
|
+
*
|
|
2837
|
+
* @return {SubBuildNode} The removed sub-build layer.
|
|
2838
|
+
*/
|
|
2839
|
+
removeSubBuild() {
|
|
2840
|
+
|
|
2841
|
+
return this.subBuildLayers.pop();
|
|
2842
|
+
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
/**
|
|
2846
|
+
* Returns the closest sub-build layer for the given data.
|
|
2847
|
+
*
|
|
2848
|
+
* @param {Node|Set<string>|Array<string>} data - The data to get the closest sub-build layer from.
|
|
2849
|
+
* @return {?string} The closest sub-build name or null if none found.
|
|
2850
|
+
*/
|
|
2851
|
+
getClosestSubBuild( data ) {
|
|
2852
|
+
|
|
2853
|
+
let subBuilds;
|
|
2854
|
+
|
|
2855
|
+
if ( data && data.isNode ) {
|
|
2856
|
+
|
|
2857
|
+
if ( data.isShaderCallNodeInternal ) {
|
|
2858
|
+
|
|
2859
|
+
subBuilds = data.shaderNode.subBuilds;
|
|
2860
|
+
|
|
2861
|
+
} else if ( data.isStackNode ) {
|
|
2862
|
+
|
|
2863
|
+
subBuilds = [ data.subBuild ];
|
|
2864
|
+
|
|
2865
|
+
} else {
|
|
2866
|
+
|
|
2867
|
+
subBuilds = this.getDataFromNode( data, 'any' ).subBuilds;
|
|
2868
|
+
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
} else if ( data instanceof Set ) {
|
|
2872
|
+
|
|
2873
|
+
subBuilds = [ ...data ];
|
|
2874
|
+
|
|
2875
|
+
} else {
|
|
2876
|
+
|
|
2877
|
+
subBuilds = data;
|
|
2878
|
+
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
if ( ! subBuilds ) return null;
|
|
2882
|
+
|
|
2883
|
+
const subBuildLayers = this.subBuildLayers;
|
|
2884
|
+
|
|
2885
|
+
for ( let i = subBuilds.length - 1; i >= 0; i -- ) {
|
|
2886
|
+
|
|
2887
|
+
const subBuild = subBuilds[ i ];
|
|
2888
|
+
|
|
2889
|
+
if ( subBuildLayers.includes( subBuild ) ) {
|
|
2890
|
+
|
|
2891
|
+
return subBuild;
|
|
2892
|
+
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
}
|
|
2896
|
+
|
|
2897
|
+
return null;
|
|
2898
|
+
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2901
|
+
|
|
2902
|
+
/**
|
|
2903
|
+
* Returns the output node of a sub-build layer.
|
|
2904
|
+
*
|
|
2905
|
+
* @param {Node} node - The node to get the output from.
|
|
2906
|
+
* @return {string} The output node name.
|
|
2907
|
+
*/
|
|
2908
|
+
getSubBuildOutput( node ) {
|
|
2909
|
+
|
|
2910
|
+
return this.getSubBuildProperty( 'outputNode', node );
|
|
2911
|
+
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
/**
|
|
2915
|
+
* Returns the sub-build property name for the given property and node.
|
|
2916
|
+
*
|
|
2917
|
+
* @param {string} [property=''] - The property name.
|
|
2918
|
+
* @param {?Node} [node=null] - The node to get the sub-build from.
|
|
2919
|
+
* @return {string} The sub-build property name.
|
|
2920
|
+
*/
|
|
2921
|
+
getSubBuildProperty( property = '', node = null ) {
|
|
2922
|
+
|
|
2923
|
+
let subBuild;
|
|
2924
|
+
|
|
2925
|
+
if ( node !== null ) {
|
|
2926
|
+
|
|
2927
|
+
subBuild = this.getClosestSubBuild( node );
|
|
2928
|
+
|
|
2929
|
+
} else {
|
|
2930
|
+
|
|
2931
|
+
subBuild = this.subBuildFn;
|
|
2932
|
+
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
let result;
|
|
2936
|
+
|
|
2937
|
+
if ( subBuild ) {
|
|
2938
|
+
|
|
2939
|
+
result = property ? ( subBuild + '_' + property ) : subBuild;
|
|
2940
|
+
|
|
2941
|
+
} else {
|
|
2942
|
+
|
|
2943
|
+
result = property;
|
|
2944
|
+
|
|
2945
|
+
}
|
|
2946
|
+
|
|
2947
|
+
return result;
|
|
2948
|
+
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
/**
|
|
2952
|
+
* Central build method which controls the build for the given object.
|
|
2953
|
+
*
|
|
2954
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
2955
|
+
*/
|
|
1305
2956
|
build() {
|
|
1306
2957
|
|
|
1307
2958
|
const { object, material, renderer } = this;
|
|
1308
2959
|
|
|
1309
2960
|
if ( material !== null ) {
|
|
1310
2961
|
|
|
1311
|
-
let nodeMaterial = renderer.
|
|
2962
|
+
let nodeMaterial = renderer.library.fromMaterial( material );
|
|
1312
2963
|
|
|
1313
2964
|
if ( nodeMaterial === null ) {
|
|
1314
2965
|
|
|
1315
|
-
|
|
2966
|
+
error( `NodeMaterial: Material "${ material.type }" is not compatible.` );
|
|
1316
2967
|
|
|
1317
2968
|
nodeMaterial = new NodeMaterial();
|
|
1318
2969
|
|
|
@@ -1326,7 +2977,7 @@ class NodeBuilder {
|
|
|
1326
2977
|
|
|
1327
2978
|
}
|
|
1328
2979
|
|
|
1329
|
-
// setup() -> stage 1: create possible new nodes and
|
|
2980
|
+
// setup() -> stage 1: create possible new nodes and/or return an output reference node
|
|
1330
2981
|
// analyze() -> stage 2: analyze nodes to possible optimization and validation
|
|
1331
2982
|
// generate() -> stage 3: generate shader
|
|
1332
2983
|
|
|
@@ -1334,9 +2985,9 @@ class NodeBuilder {
|
|
|
1334
2985
|
|
|
1335
2986
|
this.setBuildStage( buildStage );
|
|
1336
2987
|
|
|
1337
|
-
if ( this.context.
|
|
2988
|
+
if ( this.context.position && this.context.position.isNode ) {
|
|
1338
2989
|
|
|
1339
|
-
this.flowNodeFromShaderStage( 'vertex', this.context.
|
|
2990
|
+
this.flowNodeFromShaderStage( 'vertex', this.context.position );
|
|
1340
2991
|
|
|
1341
2992
|
}
|
|
1342
2993
|
|
|
@@ -1376,26 +3027,73 @@ class NodeBuilder {
|
|
|
1376
3027
|
|
|
1377
3028
|
}
|
|
1378
3029
|
|
|
1379
|
-
|
|
3030
|
+
/**
|
|
3031
|
+
* Returns shared data object for the given node.
|
|
3032
|
+
*
|
|
3033
|
+
* @param {Node} node - The node to get shared data from.
|
|
3034
|
+
* @return {Object} The shared data.
|
|
3035
|
+
*/
|
|
3036
|
+
getSharedDataFromNode( node ) {
|
|
1380
3037
|
|
|
1381
|
-
|
|
1382
|
-
if ( type === 'vec2' || type === 'ivec2' || type === 'uvec2' ) return new Vector2NodeUniform( uniformNode );
|
|
1383
|
-
if ( type === 'vec3' || type === 'ivec3' || type === 'uvec3' ) return new Vector3NodeUniform( uniformNode );
|
|
1384
|
-
if ( type === 'vec4' || type === 'ivec4' || type === 'uvec4' ) return new Vector4NodeUniform( uniformNode );
|
|
1385
|
-
if ( type === 'color' ) return new ColorNodeUniform( uniformNode );
|
|
1386
|
-
if ( type === 'mat3' ) return new Matrix3NodeUniform( uniformNode );
|
|
1387
|
-
if ( type === 'mat4' ) return new Matrix4NodeUniform( uniformNode );
|
|
3038
|
+
let data = sharedNodeData.get( node );
|
|
1388
3039
|
|
|
1389
|
-
|
|
3040
|
+
if ( data === undefined ) {
|
|
3041
|
+
|
|
3042
|
+
data = {};
|
|
3043
|
+
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
return data;
|
|
1390
3047
|
|
|
1391
3048
|
}
|
|
1392
3049
|
|
|
1393
|
-
|
|
3050
|
+
/**
|
|
3051
|
+
* Returns a uniform representation which is later used for UBO generation and rendering.
|
|
3052
|
+
*
|
|
3053
|
+
* @param {NodeUniform} uniformNode - The uniform node.
|
|
3054
|
+
* @param {string} type - The requested type.
|
|
3055
|
+
* @return {Uniform} The uniform.
|
|
3056
|
+
*/
|
|
3057
|
+
getNodeUniform( uniformNode, type ) {
|
|
3058
|
+
|
|
3059
|
+
const nodeData = this.getSharedDataFromNode( uniformNode );
|
|
3060
|
+
|
|
3061
|
+
let node = nodeData.cache;
|
|
3062
|
+
|
|
3063
|
+
if ( node === undefined ) {
|
|
3064
|
+
|
|
3065
|
+
if ( type === 'float' || type === 'int' || type === 'uint' ) node = new NumberNodeUniform( uniformNode );
|
|
3066
|
+
else if ( type === 'vec2' || type === 'ivec2' || type === 'uvec2' ) node = new Vector2NodeUniform( uniformNode );
|
|
3067
|
+
else if ( type === 'vec3' || type === 'ivec3' || type === 'uvec3' ) node = new Vector3NodeUniform( uniformNode );
|
|
3068
|
+
else if ( type === 'vec4' || type === 'ivec4' || type === 'uvec4' ) node = new Vector4NodeUniform( uniformNode );
|
|
3069
|
+
else if ( type === 'color' ) node = new ColorNodeUniform( uniformNode );
|
|
3070
|
+
else if ( type === 'mat2' ) node = new Matrix2NodeUniform( uniformNode );
|
|
3071
|
+
else if ( type === 'mat3' ) node = new Matrix3NodeUniform( uniformNode );
|
|
3072
|
+
else if ( type === 'mat4' ) node = new Matrix4NodeUniform( uniformNode );
|
|
3073
|
+
else {
|
|
1394
3074
|
|
|
1395
|
-
|
|
3075
|
+
throw new Error( `Uniform "${ type }" not implemented.` );
|
|
3076
|
+
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
nodeData.cache = node;
|
|
3080
|
+
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
return node;
|
|
1396
3084
|
|
|
1397
3085
|
}
|
|
1398
3086
|
|
|
3087
|
+
/**
|
|
3088
|
+
* Formats the given shader snippet from a given type into another one. E.g.
|
|
3089
|
+
* this method might be used to convert a simple float string `"1.0"` into a
|
|
3090
|
+
* `vec3` representation: `"vec3<f32>( 1.0 )"`.
|
|
3091
|
+
*
|
|
3092
|
+
* @param {string} snippet - The shader snippet.
|
|
3093
|
+
* @param {string} fromType - The source type.
|
|
3094
|
+
* @param {string} toType - The target type.
|
|
3095
|
+
* @return {string} The updated shader string.
|
|
3096
|
+
*/
|
|
1399
3097
|
format( snippet, fromType, toType ) {
|
|
1400
3098
|
|
|
1401
3099
|
fromType = this.getVectorType( fromType );
|
|
@@ -1412,13 +3110,13 @@ class NodeBuilder {
|
|
|
1412
3110
|
|
|
1413
3111
|
if ( fromTypeLength === 16 && toTypeLength === 9 ) {
|
|
1414
3112
|
|
|
1415
|
-
return `${ this.getType( toType ) }(${ snippet }[0].xyz, ${ snippet }[1].xyz, ${ snippet }[2].xyz)`;
|
|
3113
|
+
return `${ this.getType( toType ) }( ${ snippet }[ 0 ].xyz, ${ snippet }[ 1 ].xyz, ${ snippet }[ 2 ].xyz )`;
|
|
1416
3114
|
|
|
1417
3115
|
}
|
|
1418
3116
|
|
|
1419
3117
|
if ( fromTypeLength === 9 && toTypeLength === 4 ) {
|
|
1420
3118
|
|
|
1421
|
-
return `${ this.getType( toType ) }(${ snippet }[0].xy, ${ snippet }[1].xy)`;
|
|
3119
|
+
return `${ this.getType( toType ) }( ${ snippet }[ 0 ].xy, ${ snippet }[ 1 ].xy )`;
|
|
1422
3120
|
|
|
1423
3121
|
}
|
|
1424
3122
|
|
|
@@ -1447,7 +3145,9 @@ class NodeBuilder {
|
|
|
1447
3145
|
|
|
1448
3146
|
if ( fromTypeLength > toTypeLength ) {
|
|
1449
3147
|
|
|
1450
|
-
|
|
3148
|
+
snippet = toType === 'bool' ? `all( ${ snippet } )` : `${ snippet }.${ 'xyz'.slice( 0, toTypeLength ) }`;
|
|
3149
|
+
|
|
3150
|
+
return this.format( snippet, this.getTypeFromLength( toTypeLength, this.getComponentType( fromType ) ), toType );
|
|
1451
3151
|
|
|
1452
3152
|
}
|
|
1453
3153
|
|
|
@@ -1476,12 +3176,31 @@ class NodeBuilder {
|
|
|
1476
3176
|
|
|
1477
3177
|
}
|
|
1478
3178
|
|
|
3179
|
+
/**
|
|
3180
|
+
* Returns a signature with the engine's current revision.
|
|
3181
|
+
*
|
|
3182
|
+
* @return {string} The signature.
|
|
3183
|
+
*/
|
|
1479
3184
|
getSignature() {
|
|
1480
3185
|
|
|
1481
3186
|
return `// Three.js r${ REVISION } - Node System\n`;
|
|
1482
3187
|
|
|
1483
3188
|
}
|
|
1484
3189
|
|
|
3190
|
+
/**
|
|
3191
|
+
* Returns `true` if data from the previous frame are required. Relevant
|
|
3192
|
+
* when computing motion vectors with {@link VelocityNode}.
|
|
3193
|
+
*
|
|
3194
|
+
* @return {boolean} Whether data from the previous frame are required or not.
|
|
3195
|
+
*/
|
|
3196
|
+
needsPreviousData() {
|
|
3197
|
+
|
|
3198
|
+
const mrt = this.renderer.getMRT();
|
|
3199
|
+
|
|
3200
|
+
return ( mrt && mrt.has( 'velocity' ) ) || getDataFromObject( this.object ).useVelocity === true;
|
|
3201
|
+
|
|
3202
|
+
}
|
|
3203
|
+
|
|
1485
3204
|
}
|
|
1486
3205
|
|
|
1487
3206
|
export default NodeBuilder;
|