@plastic-software/three 0.175.14 → 0.178.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/build/three.cjs +7746 -6791
- package/build/three.core.js +7371 -6576
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +189 -29
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +19 -11
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +4989 -2235
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +5082 -2469
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +0 -1
- package/examples/jsm/animation/AnimationClipCreator.js +1 -0
- package/examples/jsm/animation/CCDIKSolver.js +6 -3
- package/examples/jsm/capabilities/WebGL.js +1 -27
- package/examples/jsm/capabilities/WebGPU.js +1 -0
- package/examples/jsm/controls/ArcballControls.js +15 -4
- package/examples/jsm/controls/DragControls.js +1 -0
- package/examples/jsm/controls/FirstPersonControls.js +1 -0
- package/examples/jsm/controls/FlyControls.js +1 -0
- package/examples/jsm/controls/MapControls.js +1 -0
- package/examples/jsm/controls/OrbitControls.js +1 -0
- package/examples/jsm/controls/PointerLockControls.js +5 -3
- package/examples/jsm/controls/TrackballControls.js +1 -0
- package/examples/jsm/controls/TransformControls.js +62 -14
- package/examples/jsm/csm/CSM.js +2 -0
- package/examples/jsm/csm/CSMFrustum.js +2 -0
- package/examples/jsm/csm/CSMHelper.js +1 -0
- package/examples/jsm/csm/CSMShader.js +4 -1
- package/examples/jsm/csm/CSMShadowNode.js +18 -4
- package/examples/jsm/curves/CurveExtras.js +14 -0
- package/examples/jsm/curves/NURBSCurve.js +1 -0
- package/examples/jsm/curves/NURBSSurface.js +2 -0
- package/examples/jsm/curves/NURBSUtils.js +4 -1
- package/examples/jsm/curves/NURBSVolume.js +2 -0
- package/examples/jsm/effects/AnaglyphEffect.js +2 -0
- package/examples/jsm/effects/AsciiEffect.js +2 -0
- package/examples/jsm/effects/OutlineEffect.js +2 -0
- package/examples/jsm/effects/ParallaxBarrierEffect.js +2 -0
- package/examples/jsm/effects/StereoEffect.js +2 -0
- package/examples/jsm/environments/DebugEnvironment.js +1 -0
- package/examples/jsm/environments/RoomEnvironment.js +49 -35
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +2 -0
- package/examples/jsm/exporters/GLTFExporter.js +7 -4
- package/examples/jsm/exporters/KTX2Exporter.js +2 -0
- package/examples/jsm/exporters/OBJExporter.js +3 -1
- package/examples/jsm/exporters/PLYExporter.js +4 -2
- package/examples/jsm/exporters/STLExporter.js +2 -0
- package/examples/jsm/exporters/USDZExporter.js +12 -10
- package/examples/jsm/geometries/BoxLineGeometry.js +1 -0
- package/examples/jsm/geometries/ConvexGeometry.js +1 -0
- package/examples/jsm/geometries/DecalGeometry.js +1 -0
- package/examples/jsm/geometries/ParametricFunctions.js +4 -1
- package/examples/jsm/geometries/ParametricGeometry.js +1 -0
- package/examples/jsm/geometries/RoundedBoxGeometry.js +2 -1
- package/examples/jsm/geometries/TeapotGeometry.js +1 -0
- package/examples/jsm/geometries/TextGeometry.js +1 -0
- package/examples/jsm/helpers/LightProbeHelper.js +1 -0
- package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -0
- package/examples/jsm/helpers/OctreeHelper.js +1 -0
- package/examples/jsm/helpers/PositionalAudioHelper.js +1 -0
- package/examples/jsm/helpers/RapierHelper.js +59 -0
- package/examples/jsm/helpers/RectAreaLightHelper.js +1 -0
- package/examples/jsm/helpers/TextureHelper.js +1 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +5 -4
- package/examples/jsm/helpers/VertexNormalsHelper.js +1 -0
- package/examples/jsm/helpers/VertexTangentsHelper.js +1 -0
- package/examples/jsm/helpers/ViewHelper.js +1 -0
- package/examples/jsm/interactive/HTMLMesh.js +7 -0
- package/examples/jsm/interactive/InteractiveGroup.js +1 -0
- package/examples/jsm/interactive/SelectionBox.js +2 -0
- package/examples/jsm/interactive/SelectionHelper.js +2 -0
- package/examples/jsm/lighting/TiledLighting.js +1 -0
- package/examples/jsm/lights/LightProbeGenerator.js +1 -0
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -0
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +1 -0
- package/examples/jsm/lines/Line2.js +1 -0
- package/examples/jsm/lines/LineGeometry.js +1 -0
- package/examples/jsm/lines/LineMaterial.js +4 -4
- package/examples/jsm/lines/LineSegments2.js +1 -0
- package/examples/jsm/lines/LineSegmentsGeometry.js +1 -0
- package/examples/jsm/lines/Wireframe.js +1 -0
- package/examples/jsm/lines/WireframeGeometry2.js +1 -0
- package/examples/jsm/lines/webgpu/Line2.js +1 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +3 -1
- package/examples/jsm/lines/webgpu/Wireframe.js +1 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +1 -0
- package/examples/jsm/loaders/AMFLoader.js +1 -0
- package/examples/jsm/loaders/BVHLoader.js +1 -0
- package/examples/jsm/loaders/ColladaLoader.js +6 -5
- package/examples/jsm/loaders/DDSLoader.js +1 -0
- package/examples/jsm/loaders/DRACOLoader.js +2 -1
- package/examples/jsm/loaders/EXRLoader.js +1 -0
- package/examples/jsm/loaders/FBXLoader.js +25 -23
- package/examples/jsm/loaders/FontLoader.js +1 -0
- package/examples/jsm/loaders/GCodeLoader.js +1 -0
- package/examples/jsm/loaders/GLTFLoader.js +10 -82
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +1 -0
- package/examples/jsm/loaders/IESLoader.js +1 -0
- package/examples/jsm/loaders/KMZLoader.js +1 -0
- package/examples/jsm/loaders/KTX2Loader.js +67 -26
- package/examples/jsm/loaders/KTXLoader.js +1 -0
- package/examples/jsm/loaders/LDrawLoader.js +55 -3
- package/examples/jsm/loaders/LUT3dlLoader.js +1 -0
- package/examples/jsm/loaders/LUTCubeLoader.js +1 -0
- package/examples/jsm/loaders/LUTImageLoader.js +1 -0
- package/examples/jsm/loaders/LWOLoader.js +1 -13
- package/examples/jsm/loaders/LottieLoader.js +15 -0
- package/examples/jsm/loaders/MD2Loader.js +1 -0
- package/examples/jsm/loaders/MDDLoader.js +1 -0
- package/examples/jsm/loaders/MTLLoader.js +4 -3
- package/examples/jsm/loaders/MaterialXLoader.js +1 -0
- package/examples/jsm/loaders/NRRDLoader.js +1 -0
- package/examples/jsm/loaders/OBJLoader.js +1 -0
- package/examples/jsm/loaders/PCDLoader.js +122 -19
- package/examples/jsm/loaders/PDBLoader.js +1 -0
- package/examples/jsm/loaders/PLYLoader.js +1 -0
- package/examples/jsm/loaders/PVRLoader.js +1 -0
- package/examples/jsm/loaders/RGBELoader.js +1 -0
- package/examples/jsm/loaders/RGBMLoader.js +1 -0
- package/examples/jsm/loaders/STLLoader.js +1 -0
- package/examples/jsm/loaders/SVGLoader.js +1 -0
- package/examples/jsm/loaders/TDSLoader.js +1 -0
- package/examples/jsm/loaders/TGALoader.js +1 -0
- package/examples/jsm/loaders/TIFFLoader.js +1 -0
- package/examples/jsm/loaders/TTFLoader.js +1 -0
- package/examples/jsm/loaders/USDZLoader.js +1 -0
- package/examples/jsm/loaders/UltraHDRLoader.js +1 -0
- package/examples/jsm/loaders/VOXLoader.js +1 -0
- package/examples/jsm/loaders/VRMLLoader.js +3 -2
- package/examples/jsm/loaders/VTKLoader.js +1 -0
- package/examples/jsm/loaders/XYZLoader.js +1 -0
- package/examples/jsm/loaders/lwo/IFFParser.js +74 -74
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +1 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -0
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +1 -0
- package/examples/jsm/math/Capsule.js +2 -0
- package/examples/jsm/math/ColorConverter.js +1 -0
- package/examples/jsm/math/ConvexHull.js +2 -0
- package/examples/jsm/math/ImprovedNoise.js +19 -14
- package/examples/jsm/math/Lut.js +2 -0
- package/examples/jsm/math/MeshSurfaceSampler.js +2 -0
- package/examples/jsm/math/OBB.js +2 -0
- package/examples/jsm/math/Octree.js +20 -1
- package/examples/jsm/math/SimplexNoise.js +2 -0
- package/examples/jsm/misc/ConvexObjectBreaker.js +3 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
- package/examples/jsm/misc/Gyroscope.js +1 -0
- package/examples/jsm/misc/MD2Character.js +2 -0
- package/examples/jsm/misc/MD2CharacterComplex.js +5 -3
- package/examples/jsm/misc/MorphAnimMesh.js +1 -0
- package/examples/jsm/misc/MorphBlendMesh.js +1 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +2 -0
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +2 -0
- package/examples/jsm/misc/RollerCoaster.js +5 -0
- package/examples/jsm/misc/Timer.js +2 -0
- package/examples/jsm/misc/TubePainter.js +1 -0
- package/examples/jsm/misc/Volume.js +2 -0
- package/examples/jsm/misc/VolumeSlice.js +1 -0
- package/examples/jsm/modifiers/CurveModifier.js +3 -0
- package/examples/jsm/modifiers/CurveModifierGPU.js +2 -0
- package/examples/jsm/modifiers/EdgeSplitModifier.js +2 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +2 -0
- package/examples/jsm/modifiers/TessellateModifier.js +2 -0
- package/examples/jsm/objects/GroundedSkybox.js +1 -0
- package/examples/jsm/objects/Lensflare.js +3 -0
- package/examples/jsm/objects/LensflareMesh.js +1 -0
- package/examples/jsm/objects/MarchingCubes.js +2 -0
- package/examples/jsm/objects/Reflector.js +1 -0
- package/examples/jsm/objects/ReflectorForSSRPass.js +1 -0
- package/examples/jsm/objects/Refractor.js +1 -0
- package/examples/jsm/objects/ShadowMesh.js +1 -0
- package/examples/jsm/objects/Sky.js +2 -1
- package/examples/jsm/objects/SkyMesh.js +20 -17
- package/examples/jsm/objects/Water.js +1 -0
- package/examples/jsm/objects/Water2.js +1 -0
- package/examples/jsm/objects/Water2Mesh.js +3 -1
- package/examples/jsm/objects/WaterMesh.js +2 -1
- package/examples/jsm/physics/AmmoPhysics.js +1 -0
- package/examples/jsm/physics/JoltPhysics.js +1 -0
- package/examples/jsm/physics/RapierPhysics.js +139 -12
- package/examples/jsm/postprocessing/AfterimagePass.js +20 -2
- package/examples/jsm/postprocessing/BloomPass.js +2 -1
- package/examples/jsm/postprocessing/BokehPass.js +2 -1
- package/examples/jsm/postprocessing/ClearPass.js +1 -0
- package/examples/jsm/postprocessing/CubeTexturePass.js +1 -0
- package/examples/jsm/postprocessing/DotScreenPass.js +1 -0
- package/examples/jsm/postprocessing/EffectComposer.js +4 -2
- package/examples/jsm/postprocessing/FXAAPass.js +40 -0
- package/examples/jsm/postprocessing/FilmPass.js +1 -0
- package/examples/jsm/postprocessing/GTAOPass.js +4 -3
- package/examples/jsm/postprocessing/GlitchPass.js +2 -1
- package/examples/jsm/postprocessing/HalftonePass.js +2 -1
- package/examples/jsm/postprocessing/LUTPass.js +1 -0
- package/examples/jsm/postprocessing/MaskPass.js +1 -0
- package/examples/jsm/postprocessing/OutlinePass.js +5 -2
- package/examples/jsm/postprocessing/OutputPass.js +1 -0
- package/examples/jsm/postprocessing/Pass.js +3 -1
- package/examples/jsm/postprocessing/RenderPass.js +1 -0
- package/examples/jsm/postprocessing/RenderPixelatedPass.js +2 -1
- package/examples/jsm/postprocessing/RenderTransitionPass.js +4 -3
- package/examples/jsm/postprocessing/SAOPass.js +3 -2
- package/examples/jsm/postprocessing/SMAAPass.js +3 -2
- package/examples/jsm/postprocessing/SSAARenderPass.js +2 -1
- package/examples/jsm/postprocessing/SSAOPass.js +2 -1
- package/examples/jsm/postprocessing/SSRPass.js +4 -3
- package/examples/jsm/postprocessing/SavePass.js +2 -1
- package/examples/jsm/postprocessing/ShaderPass.js +1 -0
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -0
- package/examples/jsm/postprocessing/TexturePass.js +1 -0
- package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -1
- package/examples/jsm/renderers/CSS2DRenderer.js +3 -0
- package/examples/jsm/renderers/CSS3DRenderer.js +4 -0
- package/examples/jsm/renderers/Projector.js +2 -0
- package/examples/jsm/renderers/SVGRenderer.js +3 -0
- package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +4 -1
- package/examples/jsm/shaders/AfterimageShader.js +4 -1
- package/examples/jsm/shaders/BasicShader.js +4 -1
- package/examples/jsm/shaders/BleachBypassShader.js +4 -1
- package/examples/jsm/shaders/BlendShader.js +4 -1
- package/examples/jsm/shaders/BokehShader.js +4 -1
- package/examples/jsm/shaders/BokehShader2.js +4 -1
- package/examples/jsm/shaders/BrightnessContrastShader.js +4 -1
- package/examples/jsm/shaders/ColorCorrectionShader.js +4 -1
- package/examples/jsm/shaders/ColorifyShader.js +4 -1
- package/examples/jsm/shaders/ConvolutionShader.js +4 -1
- package/examples/jsm/shaders/CopyShader.js +4 -1
- package/examples/jsm/shaders/DOFMipMapShader.js +4 -1
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +4 -1
- package/examples/jsm/shaders/DigitalGlitch.js +4 -1
- package/examples/jsm/shaders/DotScreenShader.js +4 -1
- package/examples/jsm/shaders/ExposureShader.js +4 -1
- package/examples/jsm/shaders/FXAAShader.js +4 -1
- package/examples/jsm/shaders/FilmShader.js +4 -1
- package/examples/jsm/shaders/FocusShader.js +4 -1
- package/examples/jsm/shaders/FreiChenShader.js +4 -1
- package/examples/jsm/shaders/GTAOShader.js +4 -1
- package/examples/jsm/shaders/GammaCorrectionShader.js +4 -1
- package/examples/jsm/shaders/GodRaysShader.js +4 -1
- package/examples/jsm/shaders/HalftoneShader.js +4 -1
- package/examples/jsm/shaders/HorizontalBlurShader.js +4 -1
- package/examples/jsm/shaders/HorizontalTiltShiftShader.js +4 -1
- package/examples/jsm/shaders/HueSaturationShader.js +4 -1
- package/examples/jsm/shaders/KaleidoShader.js +4 -1
- package/examples/jsm/shaders/LuminosityHighPassShader.js +4 -1
- package/examples/jsm/shaders/LuminosityShader.js +4 -1
- package/examples/jsm/shaders/MirrorShader.js +4 -1
- package/examples/jsm/shaders/NormalMapShader.js +4 -1
- package/examples/jsm/shaders/OutputShader.js +4 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +4 -1
- package/examples/jsm/shaders/RGBShiftShader.js +4 -1
- package/examples/jsm/shaders/SAOShader.js +4 -1
- package/examples/jsm/shaders/SMAAShader.js +1 -0
- package/examples/jsm/shaders/SSAOShader.js +4 -1
- package/examples/jsm/shaders/SSRShader.js +1 -0
- package/examples/jsm/shaders/SepiaShader.js +4 -1
- package/examples/jsm/shaders/SobelOperatorShader.js +4 -1
- package/examples/jsm/shaders/SubsurfaceScatteringShader.js +4 -1
- package/examples/jsm/shaders/TechnicolorShader.js +4 -1
- package/examples/jsm/shaders/ToonShader.js +2 -1
- package/examples/jsm/shaders/TriangleBlurShader.js +4 -1
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +4 -1
- package/examples/jsm/shaders/VelocityShader.js +4 -1
- package/examples/jsm/shaders/VerticalBlurShader.js +4 -1
- package/examples/jsm/shaders/VerticalTiltShiftShader.js +4 -1
- package/examples/jsm/shaders/VignetteShader.js +4 -1
- package/examples/jsm/shaders/VolumeShader.js +5 -2
- package/examples/jsm/shaders/WaterRefractionShader.js +4 -1
- package/examples/jsm/textures/FlakesTexture.js +2 -0
- package/examples/jsm/transpiler/AST.js +381 -30
- package/examples/jsm/transpiler/GLSLDecoder.js +226 -87
- package/examples/jsm/transpiler/Linker.js +327 -0
- package/examples/jsm/transpiler/TSLEncoder.js +234 -85
- package/examples/jsm/transpiler/Transpiler.js +19 -1
- package/examples/jsm/transpiler/TranspilerUtils.js +29 -0
- package/examples/jsm/transpiler/WGSLEncoder.js +788 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +2 -3
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +1 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +5 -4
- package/examples/jsm/tsl/display/BloomNode.js +1 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +206 -0
- package/examples/jsm/tsl/display/DenoiseNode.js +33 -33
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +1 -0
- package/examples/jsm/tsl/display/DotScreenNode.js +1 -0
- package/examples/jsm/tsl/display/FXAANode.js +3 -2
- package/examples/jsm/tsl/display/FilmNode.js +1 -0
- package/examples/jsm/tsl/display/GTAONode.js +1 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +4 -29
- package/examples/jsm/tsl/display/LensflareNode.js +1 -0
- package/examples/jsm/tsl/display/Lut3DNode.js +1 -0
- package/examples/jsm/tsl/display/OutlineNode.js +1 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +1 -0
- package/examples/jsm/tsl/display/PixelationPassNode.js +1 -0
- package/examples/jsm/tsl/display/RGBShiftNode.js +1 -0
- package/examples/jsm/tsl/display/SMAANode.js +9 -8
- package/examples/jsm/tsl/display/SSAAPassNode.js +5 -4
- package/examples/jsm/tsl/display/SSRNode.js +1 -0
- package/examples/jsm/tsl/display/SobelOperatorNode.js +1 -0
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +1 -0
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -0
- package/examples/jsm/tsl/display/TRAAPassNode.js +5 -4
- package/examples/jsm/tsl/display/TransitionNode.js +1 -0
- package/examples/jsm/tsl/display/hashBlur.js +28 -6
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +4 -3
- package/examples/jsm/tsl/math/Bayer.js +4 -1
- 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 +6 -3
- package/examples/jsm/utils/BufferGeometryUtils.js +4 -1
- package/examples/jsm/utils/CameraUtils.js +4 -1
- package/examples/jsm/utils/GeometryCompressionUtils.js +4 -1
- package/examples/jsm/utils/GeometryUtils.js +4 -1
- package/examples/jsm/utils/LDrawUtils.js +2 -0
- package/examples/jsm/utils/SceneOptimizer.js +2 -0
- package/examples/jsm/utils/SceneUtils.js +4 -1
- package/examples/jsm/utils/ShadowMapViewer.js +2 -0
- package/examples/jsm/utils/ShadowMapViewerGPU.js +2 -0
- package/examples/jsm/utils/SkeletonUtils.js +4 -1
- package/examples/jsm/utils/SortUtils.js +4 -1
- package/examples/jsm/utils/UVsDebug.js +4 -1
- package/examples/jsm/utils/WebGLTextureUtils.js +4 -1
- package/examples/jsm/utils/WebGPUTextureUtils.js +4 -1
- package/examples/jsm/utils/WorkerPool.js +2 -0
- package/examples/jsm/webxr/ARButton.js +1 -0
- package/examples/jsm/webxr/OculusHandModel.js +1 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +1 -0
- package/examples/jsm/webxr/Text2D.js +4 -1
- package/examples/jsm/webxr/VRButton.js +1 -0
- package/examples/jsm/webxr/XRButton.js +1 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +2 -0
- package/examples/jsm/webxr/XREstimatedLight.js +1 -0
- package/examples/jsm/webxr/XRHandMeshModel.js +2 -0
- package/examples/jsm/webxr/XRHandModelFactory.js +2 -0
- package/examples/jsm/webxr/XRHandPrimitiveModel.js +2 -0
- package/examples/jsm/webxr/XRPlanes.js +1 -0
- package/package.json +6 -4
- package/src/Three.Core.js +1 -1
- package/src/Three.TSL.js +18 -10
- package/src/Three.WebGPU.Nodes.js +1 -0
- package/src/Three.WebGPU.js +3 -0
- package/src/audio/AudioListener.js +13 -10
- package/src/cameras/ArrayCamera.js +9 -1
- package/src/constants.js +47 -20
- package/src/core/BufferAttribute.js +3 -3
- package/src/core/BufferGeometry.js +2 -5
- package/src/core/Clock.js +2 -8
- package/src/core/GLBufferAttribute.js +13 -1
- package/src/core/Object3D.js +23 -22
- package/src/core/RenderTarget.js +65 -21
- package/src/core/RenderTarget3D.js +1 -0
- package/src/extras/TextureUtils.js +1 -5
- package/src/extras/core/Curve.js +1 -1
- package/src/extras/core/Path.js +22 -22
- package/src/geometries/CapsuleGeometry.js +167 -17
- package/src/geometries/ExtrudeGeometry.js +39 -29
- package/src/helpers/ArrowHelper.js +2 -2
- package/src/helpers/SkeletonHelper.js +1 -1
- package/src/lights/LightShadow.js +14 -0
- package/src/lights/SpotLightShadow.js +9 -1
- package/src/lights/webgpu/ProjectorLight.js +46 -0
- package/src/loaders/BufferGeometryLoader.js +1 -10
- package/src/loaders/FileLoader.js +2 -2
- package/src/loaders/ImageBitmapLoader.js +25 -9
- package/src/loaders/ImageLoader.js +55 -8
- package/src/loaders/ObjectLoader.js +44 -16
- package/src/loaders/nodes/NodeObjectLoader.js +2 -2
- package/src/materials/Material.js +1 -7
- package/src/materials/nodes/MeshBasicNodeMaterial.js +4 -3
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +1 -1
- package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -1
- package/src/materials/nodes/MeshSSSNodeMaterial.js +2 -2
- package/src/materials/nodes/NodeMaterial.js +105 -19
- package/src/materials/nodes/manager/NodeMaterialObserver.js +20 -2
- package/src/math/Box3.js +28 -0
- package/src/math/Color.js +7 -7
- package/src/math/ColorManagement.js +22 -3
- package/src/math/Frustum.js +6 -1
- package/src/math/FrustumArray.js +253 -0
- package/src/math/Quaternion.js +1 -1
- package/src/math/Ray.js +2 -0
- package/src/math/Sphere.js +28 -0
- package/src/nodes/Nodes.js +2 -3
- package/src/nodes/TSL.js +5 -3
- package/src/nodes/accessors/AccessorsUtils.js +7 -8
- package/src/nodes/accessors/Bitangent.js +54 -26
- package/src/nodes/accessors/Camera.js +31 -4
- package/src/nodes/accessors/CubeTextureNode.js +50 -2
- package/src/nodes/accessors/InstanceNode.js +5 -4
- package/src/nodes/accessors/Lights.js +2 -2
- package/src/nodes/accessors/MaterialNode.js +4 -0
- package/src/nodes/accessors/ModelNode.js +1 -1
- package/src/nodes/accessors/Normal.js +102 -16
- package/src/nodes/accessors/Object3DNode.js +7 -8
- package/src/nodes/accessors/Position.js +14 -4
- package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
- package/src/nodes/accessors/ReferenceNode.js +1 -1
- package/src/nodes/accessors/ReflectVector.js +3 -3
- package/src/nodes/accessors/SkinningNode.js +3 -2
- package/src/nodes/accessors/StorageBufferNode.js +25 -0
- package/src/nodes/accessors/StorageTextureNode.js +14 -3
- package/src/nodes/accessors/Tangent.js +25 -17
- package/src/nodes/accessors/TangentUtils.js +46 -0
- package/src/nodes/accessors/TextureBicubic.js +21 -3
- package/src/nodes/accessors/TextureNode.js +59 -8
- package/src/nodes/accessors/UniformArrayNode.js +0 -16
- package/src/nodes/accessors/VelocityNode.js +1 -0
- package/src/nodes/accessors/VertexColorNode.js +4 -4
- package/src/nodes/code/CodeNode.js +8 -11
- package/src/nodes/core/AssignNode.js +27 -5
- package/src/nodes/core/AttributeNode.js +2 -2
- package/src/nodes/core/ContextNode.js +7 -3
- package/src/nodes/core/Node.js +69 -20
- package/src/nodes/core/NodeBuilder.js +248 -29
- package/src/nodes/core/NodeUtils.js +42 -0
- package/src/nodes/core/NodeVarying.js +19 -1
- package/src/nodes/core/PropertyNode.js +8 -12
- package/src/nodes/core/StackNode.js +129 -26
- package/src/nodes/core/StructTypeNode.js +26 -4
- package/src/nodes/core/SubBuildNode.js +89 -0
- package/src/nodes/core/VarNode.js +11 -2
- package/src/nodes/core/VaryingNode.js +45 -24
- package/src/nodes/display/BlendModes.js +42 -1
- package/src/nodes/display/ColorSpaceNode.js +4 -27
- package/src/nodes/display/FrontFacingNode.js +34 -2
- package/src/nodes/display/NormalMapNode.js +19 -50
- package/src/nodes/display/PassNode.js +18 -19
- package/src/nodes/display/ScreenNode.js +0 -26
- package/src/nodes/functions/BSDF/BRDF_GGX.js +2 -6
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +4 -4
- package/src/nodes/functions/PhongLightingModel.js +3 -3
- package/src/nodes/functions/PhysicalLightingModel.js +14 -14
- package/src/nodes/functions/ShadowMaskModel.js +5 -1
- package/src/nodes/functions/material/getGeometryRoughness.js +2 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +1 -1
- package/src/nodes/gpgpu/AtomicFunctionNode.js +28 -10
- package/src/nodes/gpgpu/BarrierNode.js +3 -3
- package/src/nodes/gpgpu/ComputeNode.js +1 -1
- package/src/nodes/lighting/AnalyticLightNode.js +7 -13
- package/src/nodes/lighting/EnvironmentNode.js +5 -5
- package/src/nodes/lighting/HemisphereLightNode.js +2 -2
- package/src/nodes/lighting/IESSpotLightNode.js +2 -1
- package/src/nodes/lighting/LightsNode.js +29 -11
- package/src/nodes/lighting/ProjectorLightNode.js +78 -0
- package/src/nodes/lighting/ShadowBaseNode.js +1 -12
- package/src/nodes/lighting/ShadowFilterNode.js +274 -0
- package/src/nodes/lighting/ShadowNode.js +174 -242
- package/src/nodes/lighting/SpotLightNode.js +44 -7
- package/src/nodes/materialx/lib/mx_noise.js +1 -1
- package/src/nodes/math/ConditionalNode.js +0 -19
- package/src/nodes/math/MathNode.js +68 -21
- package/src/nodes/math/OperatorNode.js +108 -98
- package/src/nodes/shapes/Shapes.js +5 -4
- package/src/nodes/tsl/TSLBase.js +1 -0
- package/src/nodes/tsl/TSLCore.js +160 -65
- package/src/nodes/utils/DebugNode.js +15 -3
- package/src/nodes/utils/Discard.js +2 -2
- package/src/nodes/utils/EquirectUV.js +27 -0
- package/src/nodes/utils/LoopNode.js +64 -34
- package/src/nodes/utils/MatcapUV.js +22 -0
- package/src/nodes/utils/RTTNode.js +13 -5
- package/src/nodes/utils/ReflectorNode.js +77 -7
- package/src/nodes/utils/SampleNode.js +81 -0
- package/src/nodes/utils/TriplanarTextures.js +65 -0
- package/src/objects/BatchedMesh.js +16 -4
- package/src/objects/Mesh.js +9 -0
- package/src/objects/Skeleton.js +1 -1
- package/src/objects/Sprite.js +9 -0
- package/src/renderers/WebGL3DRenderTarget.js +1 -0
- package/src/renderers/WebGLArrayRenderTarget.js +1 -0
- package/src/renderers/WebGLCubeRenderTarget.js +2 -4
- package/src/renderers/WebGLRenderer.js +25 -11
- package/src/renderers/common/Animation.js +2 -2
- package/src/renderers/common/Background.js +13 -2
- package/src/renderers/common/CubeRenderTarget.js +1 -1
- package/src/renderers/common/RenderList.js +0 -4
- package/src/renderers/common/RenderObject.js +80 -4
- package/src/renderers/common/Renderer.js +116 -8
- package/src/renderers/common/Storage3DTexture.js +79 -0
- package/src/renderers/common/StorageArrayTexture.js +63 -0
- package/src/renderers/common/Textures.js +15 -21
- package/src/renderers/common/TimestampQueryPool.js +1 -0
- package/src/renderers/common/Uniform.js +1 -1
- package/src/renderers/common/UniformsGroup.js +14 -18
- package/src/renderers/common/XRManager.js +157 -27
- package/src/renderers/common/XRRenderTarget.js +21 -4
- package/src/renderers/common/extras/PMREMGenerator.js +30 -23
- package/src/renderers/common/nodes/Nodes.js +13 -3
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
- package/src/renderers/webgl/WebGLAttributes.js +4 -0
- package/src/renderers/webgl/WebGLPrograms.js +4 -2
- package/src/renderers/webgl/WebGLShadowMap.js +3 -2
- package/src/renderers/webgl/WebGLState.js +4 -4
- package/src/renderers/webgl/WebGLTextures.js +144 -4
- package/src/renderers/webgl/WebGLUtils.js +1 -3
- package/src/renderers/webgl-fallback/WebGLBackend.js +244 -87
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +73 -7
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +4 -0
- package/src/renderers/webgl-fallback/utils/WebGLConstants.js +1 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +4 -4
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +44 -29
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +22 -21
- package/src/renderers/webgpu/WebGPUBackend.js +451 -128
- package/src/renderers/webgpu/WebGPURenderer.js +7 -0
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +4 -1
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +4 -1
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +86 -33
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +3 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +9 -1
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +28 -5
- package/src/renderers/webgpu/utils/WebGPUConstants.js +8 -2
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +38 -8
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +45 -50
- package/src/renderers/webxr/WebXRController.js +1 -1
- package/src/renderers/webxr/WebXRManager.js +2 -1
- package/src/textures/DepthTexture.js +6 -10
- package/src/textures/Source.js +22 -0
- package/src/textures/Texture.js +118 -1
- package/src/textures/VideoTexture.js +1 -1
- package/examples/jsm/effects/PeppersGhostEffect.js +0 -172
- package/src/core/RenderTargetArray.js +0 -40
- package/src/nodes/utils/EquirectUVNode.js +0 -65
- package/src/nodes/utils/MatcapUVNode.js +0 -49
- package/src/nodes/utils/TriplanarTexturesNode.js +0 -148
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
import { REVISION } from 'three/webgpu';
|
|
2
|
+
|
|
3
|
+
import { VariableDeclaration, Accessor } from './AST.js';
|
|
4
|
+
import { isExpression } from './TranspilerUtils.js';
|
|
5
|
+
|
|
6
|
+
// Note: This is a simplified list. A complete implementation would need more mappings.
|
|
7
|
+
const typeMap = {
|
|
8
|
+
'float': 'f32',
|
|
9
|
+
'int': 'i32',
|
|
10
|
+
'uint': 'u32',
|
|
11
|
+
'bool': 'bool',
|
|
12
|
+
'vec2': 'vec2f',
|
|
13
|
+
'ivec2': 'vec2i',
|
|
14
|
+
'uvec2': 'vec2u',
|
|
15
|
+
'bvec2': 'vec2b',
|
|
16
|
+
'vec3': 'vec3f',
|
|
17
|
+
'ivec3': 'vec3i',
|
|
18
|
+
'uvec3': 'vec3u',
|
|
19
|
+
'bvec3': 'vec3b',
|
|
20
|
+
'vec4': 'vec4f',
|
|
21
|
+
'ivec4': 'vec4i',
|
|
22
|
+
'uvec4': 'vec4u',
|
|
23
|
+
'bvec4': 'vec4b',
|
|
24
|
+
'mat3': 'mat3x3<f32>',
|
|
25
|
+
'mat4': 'mat4x4<f32>',
|
|
26
|
+
'texture': 'texture_2d<f32>',
|
|
27
|
+
'textureCube': 'texture_cube<f32>',
|
|
28
|
+
'texture3D': 'texture_3d<f32>',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// GLSL to WGSL built-in function mapping
|
|
32
|
+
const wgslLib = {
|
|
33
|
+
'abs': 'abs',
|
|
34
|
+
'acos': 'acos',
|
|
35
|
+
'asin': 'asin',
|
|
36
|
+
'atan': 'atan',
|
|
37
|
+
'atan2': 'atan2',
|
|
38
|
+
'ceil': 'ceil',
|
|
39
|
+
'clamp': 'clamp',
|
|
40
|
+
'cos': 'cos',
|
|
41
|
+
'cross': 'cross',
|
|
42
|
+
'degrees': 'degrees',
|
|
43
|
+
'distance': 'distance',
|
|
44
|
+
'dot': 'dot',
|
|
45
|
+
'exp': 'exp',
|
|
46
|
+
'exp2': 'exp2',
|
|
47
|
+
'faceforward': 'faceForward',
|
|
48
|
+
'floor': 'floor',
|
|
49
|
+
'fract': 'fract',
|
|
50
|
+
'inverse': 'inverse',
|
|
51
|
+
'inversesqrt': 'inverseSqrt',
|
|
52
|
+
'length': 'length',
|
|
53
|
+
'log': 'log',
|
|
54
|
+
'log2': 'log2',
|
|
55
|
+
'max': 'max',
|
|
56
|
+
'min': 'min',
|
|
57
|
+
'mix': 'mix',
|
|
58
|
+
'normalize': 'normalize',
|
|
59
|
+
'pow': 'pow',
|
|
60
|
+
'radians': 'radians',
|
|
61
|
+
'reflect': 'reflect',
|
|
62
|
+
'refract': 'refract',
|
|
63
|
+
'round': 'round',
|
|
64
|
+
'sign': 'sign',
|
|
65
|
+
'sin': 'sin',
|
|
66
|
+
'smoothstep': 'smoothstep',
|
|
67
|
+
'sqrt': 'sqrt',
|
|
68
|
+
'step': 'step',
|
|
69
|
+
'tan': 'tan',
|
|
70
|
+
'transpose': 'transpose',
|
|
71
|
+
'trunc': 'trunc',
|
|
72
|
+
'dFdx': 'dpdx',
|
|
73
|
+
'dFdy': 'dpdy',
|
|
74
|
+
'fwidth': 'fwidth',
|
|
75
|
+
// Texture functions are handled separately
|
|
76
|
+
'texture': 'textureSample',
|
|
77
|
+
'texture2D': 'textureSample',
|
|
78
|
+
'texture3D': 'textureSample',
|
|
79
|
+
'textureCube': 'textureSample',
|
|
80
|
+
'textureLod': 'textureSampleLevel',
|
|
81
|
+
'texelFetch': 'textureLoad',
|
|
82
|
+
'textureGrad': 'textureSampleGrad',
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
class WGSLEncoder {
|
|
86
|
+
|
|
87
|
+
constructor() {
|
|
88
|
+
|
|
89
|
+
this.tab = '';
|
|
90
|
+
this.functions = new Map();
|
|
91
|
+
this.uniforms = [];
|
|
92
|
+
this.varyings = [];
|
|
93
|
+
this.structs = new Map();
|
|
94
|
+
this.polyfills = new Map();
|
|
95
|
+
|
|
96
|
+
// Assume a single group for simplicity
|
|
97
|
+
this.groupIndex = 0;
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getWgslType( type ) {
|
|
102
|
+
|
|
103
|
+
return typeMap[ type ] || type;
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
emitExpression( node ) {
|
|
108
|
+
|
|
109
|
+
if ( ! node ) return '';
|
|
110
|
+
|
|
111
|
+
let code;
|
|
112
|
+
|
|
113
|
+
if ( node.isAccessor ) {
|
|
114
|
+
|
|
115
|
+
// Check if this accessor is part of a uniform struct
|
|
116
|
+
const uniform = this.uniforms.find( u => u.name === node.property );
|
|
117
|
+
|
|
118
|
+
if ( uniform && ! uniform.type.includes( 'texture' ) ) {
|
|
119
|
+
|
|
120
|
+
return `uniforms.${node.property}`;
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
code = node.property;
|
|
125
|
+
|
|
126
|
+
} else if ( node.isNumber ) {
|
|
127
|
+
|
|
128
|
+
code = node.value;
|
|
129
|
+
|
|
130
|
+
// WGSL requires floating point numbers to have a decimal
|
|
131
|
+
if ( node.type === 'float' && ! code.includes( '.' ) ) {
|
|
132
|
+
|
|
133
|
+
code += '.0';
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} else if ( node.isOperator ) {
|
|
138
|
+
|
|
139
|
+
const left = this.emitExpression( node.left );
|
|
140
|
+
const right = this.emitExpression( node.right );
|
|
141
|
+
|
|
142
|
+
code = `${ left } ${ node.type } ${ right }`;
|
|
143
|
+
|
|
144
|
+
if ( node.parent.isAssignment !== true && node.parent.isOperator ) {
|
|
145
|
+
|
|
146
|
+
code = `( ${ code } )`;
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
} else if ( node.isFunctionCall ) {
|
|
151
|
+
|
|
152
|
+
const fnName = wgslLib[ node.name ] || node.name;
|
|
153
|
+
|
|
154
|
+
if ( fnName === 'mod' ) {
|
|
155
|
+
|
|
156
|
+
const snippets = node.params.map( p => this.emitExpression( p ) );
|
|
157
|
+
const types = node.params.map( p => p.getType() );
|
|
158
|
+
|
|
159
|
+
const modFnName = 'mod_' + types.join( '_' );
|
|
160
|
+
|
|
161
|
+
if ( this.polyfills.has( modFnName ) === false ) {
|
|
162
|
+
|
|
163
|
+
this.polyfills.set( modFnName, `fn ${ modFnName }( x: ${ this.getWgslType( types[ 0 ] ) }, y: ${ this.getWgslType( types[ 1 ] ) } ) -> ${ this.getWgslType( types[ 0 ] ) } {
|
|
164
|
+
|
|
165
|
+
return x - y * floor( x / y );
|
|
166
|
+
|
|
167
|
+
}` );
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
code = `${ modFnName }( ${ snippets.join( ', ' ) } )`;
|
|
172
|
+
|
|
173
|
+
} else if ( fnName.startsWith( 'texture' ) ) {
|
|
174
|
+
|
|
175
|
+
// Handle texture functions separately due to sampler handling
|
|
176
|
+
|
|
177
|
+
code = this.emitTextureAccess( node );
|
|
178
|
+
|
|
179
|
+
} else {
|
|
180
|
+
|
|
181
|
+
const params = node.params.map( p => this.emitExpression( p ) );
|
|
182
|
+
|
|
183
|
+
if ( typeMap[ fnName ] ) {
|
|
184
|
+
|
|
185
|
+
// Handle type constructors like vec3(...)
|
|
186
|
+
|
|
187
|
+
code = this.getWgslType( fnName );
|
|
188
|
+
|
|
189
|
+
} else {
|
|
190
|
+
|
|
191
|
+
code = fnName;
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if ( params.length > 0 ) {
|
|
196
|
+
|
|
197
|
+
code += '( ' + params.join( ', ' ) + ' )';
|
|
198
|
+
|
|
199
|
+
} else {
|
|
200
|
+
|
|
201
|
+
code += '()';
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
} else if ( node.isReturn ) {
|
|
208
|
+
|
|
209
|
+
code = 'return';
|
|
210
|
+
|
|
211
|
+
if ( node.value ) {
|
|
212
|
+
|
|
213
|
+
code += ' ' + this.emitExpression( node.value );
|
|
214
|
+
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
} else if ( node.isDiscard ) {
|
|
218
|
+
|
|
219
|
+
code = 'discard';
|
|
220
|
+
|
|
221
|
+
} else if ( node.isBreak ) {
|
|
222
|
+
|
|
223
|
+
if ( node.parent.isSwitchCase !== true ) {
|
|
224
|
+
|
|
225
|
+
code = 'break';
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
} else if ( node.isContinue ) {
|
|
230
|
+
|
|
231
|
+
code = 'continue';
|
|
232
|
+
|
|
233
|
+
} else if ( node.isAccessorElements ) {
|
|
234
|
+
|
|
235
|
+
code = this.emitExpression( node.object );
|
|
236
|
+
|
|
237
|
+
for ( const element of node.elements ) {
|
|
238
|
+
|
|
239
|
+
const value = this.emitExpression( element.value );
|
|
240
|
+
|
|
241
|
+
if ( element.isStaticElement ) {
|
|
242
|
+
|
|
243
|
+
code += '.' + value;
|
|
244
|
+
|
|
245
|
+
} else if ( element.isDynamicElement ) {
|
|
246
|
+
|
|
247
|
+
code += `[${value}]`;
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
} else if ( node.isFor ) {
|
|
254
|
+
|
|
255
|
+
code = this.emitFor( node );
|
|
256
|
+
|
|
257
|
+
} else if ( node.isWhile ) {
|
|
258
|
+
|
|
259
|
+
code = this.emitWhile( node );
|
|
260
|
+
|
|
261
|
+
} else if ( node.isSwitch ) {
|
|
262
|
+
|
|
263
|
+
code = this.emitSwitch( node );
|
|
264
|
+
|
|
265
|
+
} else if ( node.isVariableDeclaration ) {
|
|
266
|
+
|
|
267
|
+
code = this.emitVariables( node );
|
|
268
|
+
|
|
269
|
+
} else if ( node.isUniform ) {
|
|
270
|
+
|
|
271
|
+
this.uniforms.push( node );
|
|
272
|
+
return ''; // Defer emission to the header
|
|
273
|
+
|
|
274
|
+
} else if ( node.isVarying ) {
|
|
275
|
+
|
|
276
|
+
this.varyings.push( node );
|
|
277
|
+
return ''; // Defer emission to the header
|
|
278
|
+
|
|
279
|
+
} else if ( node.isTernary ) {
|
|
280
|
+
|
|
281
|
+
const cond = this.emitExpression( node.cond );
|
|
282
|
+
const left = this.emitExpression( node.left );
|
|
283
|
+
const right = this.emitExpression( node.right );
|
|
284
|
+
|
|
285
|
+
// WGSL's equivalent to the ternary operator is select(false_val, true_val, condition)
|
|
286
|
+
code = `select( ${ right }, ${ left }, ${ cond } )`;
|
|
287
|
+
|
|
288
|
+
} else if ( node.isConditional ) {
|
|
289
|
+
|
|
290
|
+
code = this.emitConditional( node );
|
|
291
|
+
|
|
292
|
+
} else if ( node.isUnary ) {
|
|
293
|
+
|
|
294
|
+
const expr = this.emitExpression( node.expression );
|
|
295
|
+
|
|
296
|
+
if ( node.type === '++' || node.type === '--' ) {
|
|
297
|
+
|
|
298
|
+
const op = node.type === '++' ? '+' : '-';
|
|
299
|
+
|
|
300
|
+
code = `${ expr } = ${ expr } ${ op } 1`;
|
|
301
|
+
|
|
302
|
+
} else {
|
|
303
|
+
|
|
304
|
+
code = `${ node.type }${ expr }`;
|
|
305
|
+
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
} else {
|
|
309
|
+
|
|
310
|
+
console.warn( 'Unknown node type in WGSL Encoder:', node );
|
|
311
|
+
|
|
312
|
+
code = `/* unknown node: ${ node.constructor.name } */`;
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return code;
|
|
317
|
+
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
emitTextureAccess( node ) {
|
|
321
|
+
|
|
322
|
+
const wgslFn = wgslLib[ node.name ];
|
|
323
|
+
const textureName = this.emitExpression( node.params[ 0 ] );
|
|
324
|
+
const uv = this.emitExpression( node.params[ 1 ] );
|
|
325
|
+
|
|
326
|
+
// WGSL requires explicit samplers. We assume a naming convention.
|
|
327
|
+
const samplerName = `${textureName}_sampler`;
|
|
328
|
+
|
|
329
|
+
let code;
|
|
330
|
+
|
|
331
|
+
switch ( node.name ) {
|
|
332
|
+
|
|
333
|
+
case 'texture':
|
|
334
|
+
case 'texture2D':
|
|
335
|
+
case 'texture3D':
|
|
336
|
+
case 'textureCube':
|
|
337
|
+
// format: textureSample(texture, sampler, coords, [offset])
|
|
338
|
+
code = `${wgslFn}(${textureName}, ${samplerName}, ${uv}`;
|
|
339
|
+
// Handle optional bias parameter (note: WGSL uses textureSampleBias)
|
|
340
|
+
if ( node.params.length === 3 ) {
|
|
341
|
+
|
|
342
|
+
const bias = this.emitExpression( node.params[ 2 ] );
|
|
343
|
+
code = `textureSampleBias(${textureName}, ${samplerName}, ${uv}, ${bias})`;
|
|
344
|
+
|
|
345
|
+
} else {
|
|
346
|
+
|
|
347
|
+
code += ')';
|
|
348
|
+
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
break;
|
|
352
|
+
|
|
353
|
+
case 'textureLod':
|
|
354
|
+
// format: textureSampleLevel(texture, sampler, coords, level)
|
|
355
|
+
const lod = this.emitExpression( node.params[ 2 ] );
|
|
356
|
+
code = `${wgslFn}(${textureName}, ${samplerName}, ${uv}, ${lod})`;
|
|
357
|
+
break;
|
|
358
|
+
|
|
359
|
+
case 'textureGrad':
|
|
360
|
+
// format: textureSampleGrad(texture, sampler, coords, ddx, ddy)
|
|
361
|
+
const ddx = this.emitExpression( node.params[ 2 ] );
|
|
362
|
+
const ddy = this.emitExpression( node.params[ 3 ] );
|
|
363
|
+
code = `${wgslFn}(${textureName}, ${samplerName}, ${uv}, ${ddx}, ${ddy})`;
|
|
364
|
+
break;
|
|
365
|
+
|
|
366
|
+
case 'texelFetch':
|
|
367
|
+
// format: textureLoad(texture, coords, [level])
|
|
368
|
+
const coords = this.emitExpression( node.params[ 1 ] ); // should be ivec
|
|
369
|
+
const lodFetch = node.params.length > 2 ? this.emitExpression( node.params[ 2 ] ) : '0';
|
|
370
|
+
code = `${wgslFn}(${textureName}, ${coords}, ${lodFetch})`;
|
|
371
|
+
break;
|
|
372
|
+
|
|
373
|
+
default:
|
|
374
|
+
code = `/* unsupported texture op: ${node.name} */`;
|
|
375
|
+
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return code;
|
|
379
|
+
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
emitBody( body ) {
|
|
383
|
+
|
|
384
|
+
let code = '';
|
|
385
|
+
this.tab += '\t';
|
|
386
|
+
|
|
387
|
+
for ( const statement of body ) {
|
|
388
|
+
|
|
389
|
+
code += this.emitExtraLine( statement, body );
|
|
390
|
+
|
|
391
|
+
if ( statement.isComment ) {
|
|
392
|
+
|
|
393
|
+
code += this.emitComment( statement, body );
|
|
394
|
+
continue;
|
|
395
|
+
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
const statementCode = this.emitExpression( statement );
|
|
399
|
+
|
|
400
|
+
if ( statementCode ) {
|
|
401
|
+
|
|
402
|
+
code += this.tab + statementCode;
|
|
403
|
+
|
|
404
|
+
if ( ! statementCode.endsWith( '}' ) && ! statementCode.endsWith( '{' ) ) {
|
|
405
|
+
|
|
406
|
+
code += ';';
|
|
407
|
+
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
code += '\n';
|
|
411
|
+
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
this.tab = this.tab.slice( 0, - 1 );
|
|
417
|
+
return code.slice( 0, - 1 ); // remove the last extra line
|
|
418
|
+
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
emitConditional( node ) {
|
|
422
|
+
|
|
423
|
+
const condStr = this.emitExpression( node.cond );
|
|
424
|
+
const bodyStr = this.emitBody( node.body );
|
|
425
|
+
|
|
426
|
+
let ifStr = `if ( ${ condStr } ) {\n\n${ bodyStr }\n\n${ this.tab }}`;
|
|
427
|
+
|
|
428
|
+
let current = node;
|
|
429
|
+
|
|
430
|
+
while ( current.elseConditional ) {
|
|
431
|
+
|
|
432
|
+
current = current.elseConditional;
|
|
433
|
+
const elseBodyStr = this.emitBody( current.body );
|
|
434
|
+
|
|
435
|
+
if ( current.cond ) { // This is an 'else if'
|
|
436
|
+
|
|
437
|
+
const elseCondStr = this.emitExpression( current.cond );
|
|
438
|
+
|
|
439
|
+
ifStr += ` else if ( ${ elseCondStr } ) {\n\n${ elseBodyStr }\n\n${ this.tab }}`;
|
|
440
|
+
|
|
441
|
+
} else { // This is an 'else'
|
|
442
|
+
|
|
443
|
+
ifStr += ` else {\n\n${ elseBodyStr }\n\n${ this.tab }}`;
|
|
444
|
+
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return ifStr;
|
|
450
|
+
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
emitFor( node ) {
|
|
454
|
+
|
|
455
|
+
const init = this.emitExpression( node.initialization );
|
|
456
|
+
const cond = this.emitExpression( node.condition );
|
|
457
|
+
const after = this.emitExpression( node.afterthought );
|
|
458
|
+
const body = this.emitBody( node.body );
|
|
459
|
+
|
|
460
|
+
return `for ( ${ init }; ${ cond }; ${ after } ) {\n\n${ body }\n\n${ this.tab }}`;
|
|
461
|
+
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
emitWhile( node ) {
|
|
465
|
+
|
|
466
|
+
const cond = this.emitExpression( node.condition );
|
|
467
|
+
const body = this.emitBody( node.body );
|
|
468
|
+
|
|
469
|
+
return `while ( ${ cond } ) {\n\n${ body }\n\n${ this.tab }}`;
|
|
470
|
+
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
emitSwitch( node ) {
|
|
474
|
+
|
|
475
|
+
const discriminant = this.emitExpression( node.discriminant );
|
|
476
|
+
|
|
477
|
+
let switchStr = `switch ( ${ discriminant } ) {\n\n`;
|
|
478
|
+
|
|
479
|
+
this.tab += '\t';
|
|
480
|
+
|
|
481
|
+
for ( const switchCase of node.cases ) {
|
|
482
|
+
|
|
483
|
+
const body = this.emitBody( switchCase.body );
|
|
484
|
+
|
|
485
|
+
if ( switchCase.isDefault ) {
|
|
486
|
+
|
|
487
|
+
switchStr += `${ this.tab }default: {\n\n${ body }\n\n${ this.tab }}\n\n`;
|
|
488
|
+
|
|
489
|
+
} else {
|
|
490
|
+
|
|
491
|
+
const cases = switchCase.conditions.map( c => this.emitExpression( c ) ).join( ', ' );
|
|
492
|
+
|
|
493
|
+
switchStr += `${ this.tab }case ${ cases }: {\n\n${ body }\n\n${ this.tab }}\n\n`;
|
|
494
|
+
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
this.tab = this.tab.slice( 0, - 1 );
|
|
500
|
+
|
|
501
|
+
switchStr += `${this.tab}}`;
|
|
502
|
+
|
|
503
|
+
return switchStr;
|
|
504
|
+
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
emitVariables( node ) {
|
|
508
|
+
|
|
509
|
+
const declarations = [];
|
|
510
|
+
|
|
511
|
+
let current = node;
|
|
512
|
+
|
|
513
|
+
while ( current ) {
|
|
514
|
+
|
|
515
|
+
const type = this.getWgslType( current.type );
|
|
516
|
+
|
|
517
|
+
let valueStr = '';
|
|
518
|
+
|
|
519
|
+
if ( current.value ) {
|
|
520
|
+
|
|
521
|
+
valueStr = ` = ${this.emitExpression( current.value )}`;
|
|
522
|
+
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// The AST linker tracks if a variable is ever reassigned.
|
|
526
|
+
// If so, use 'var'; otherwise, use 'let'.
|
|
527
|
+
|
|
528
|
+
let keyword;
|
|
529
|
+
|
|
530
|
+
if ( current.linker ) {
|
|
531
|
+
|
|
532
|
+
if ( current.linker.assignments.length > 0 ) {
|
|
533
|
+
|
|
534
|
+
keyword = 'var'; // Reassigned variable
|
|
535
|
+
|
|
536
|
+
} else {
|
|
537
|
+
|
|
538
|
+
if ( current.value && current.value.isNumericExpression ) {
|
|
539
|
+
|
|
540
|
+
keyword = 'const'; // Immutable numeric expression
|
|
541
|
+
|
|
542
|
+
} else {
|
|
543
|
+
|
|
544
|
+
keyword = 'let'; // Immutable variable
|
|
545
|
+
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
declarations.push( `${ keyword } ${ current.name }: ${ type }${ valueStr }` );
|
|
553
|
+
|
|
554
|
+
current = current.next;
|
|
555
|
+
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// In WGSL, multiple declarations in one line are not supported, so join with semicolons.
|
|
559
|
+
return declarations.join( ';\n' + this.tab );
|
|
560
|
+
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
emitFunction( node ) {
|
|
564
|
+
|
|
565
|
+
const name = node.name;
|
|
566
|
+
const returnType = this.getWgslType( node.type );
|
|
567
|
+
|
|
568
|
+
const params = [];
|
|
569
|
+
// We will prepend to a copy of the body, not the original AST node.
|
|
570
|
+
const body = [ ...node.body ];
|
|
571
|
+
|
|
572
|
+
for ( const param of node.params ) {
|
|
573
|
+
|
|
574
|
+
const paramName = param.name;
|
|
575
|
+
let paramType = this.getWgslType( param.type );
|
|
576
|
+
|
|
577
|
+
// Handle 'inout' and 'out' qualifiers using pointers. They are already mutable.
|
|
578
|
+
if ( param.qualifier === 'inout' || param.qualifier === 'out' ) {
|
|
579
|
+
|
|
580
|
+
paramType = `ptr<function, ${paramType}>`;
|
|
581
|
+
params.push( `${paramName}: ${paramType}` );
|
|
582
|
+
continue;
|
|
583
|
+
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// If the parameter is reassigned within the function, we need to
|
|
587
|
+
// create a local, mutable variable that shadows the parameter's name.
|
|
588
|
+
if ( param.linker && param.linker.assignments.length > 0 ) {
|
|
589
|
+
|
|
590
|
+
// 1. Rename the incoming parameter to avoid name collision.
|
|
591
|
+
const immutableParamName = `${paramName}_in`;
|
|
592
|
+
params.push( `${immutableParamName}: ${paramType}` );
|
|
593
|
+
|
|
594
|
+
// 2. Create a new Accessor node for the renamed immutable parameter.
|
|
595
|
+
const immutableAccessor = new Accessor( immutableParamName );
|
|
596
|
+
immutableAccessor.isAccessor = true;
|
|
597
|
+
immutableAccessor.property = immutableParamName;
|
|
598
|
+
|
|
599
|
+
// 3. Create a new VariableDeclaration node for the mutable local variable.
|
|
600
|
+
// This new variable will have the original parameter's name.
|
|
601
|
+
const mutableVar = new VariableDeclaration( param.type, param.name, immutableAccessor );
|
|
602
|
+
|
|
603
|
+
// 4. Mark this new variable as mutable so `emitVariables` uses `var`.
|
|
604
|
+
mutableVar.linker = { assignments: [ true ] };
|
|
605
|
+
|
|
606
|
+
// 5. Prepend this new declaration to the function's body.
|
|
607
|
+
body.unshift( mutableVar );
|
|
608
|
+
|
|
609
|
+
} else {
|
|
610
|
+
|
|
611
|
+
// This parameter is not reassigned, so treat it as a normal immutable parameter.
|
|
612
|
+
params.push( `${paramName}: ${paramType}` );
|
|
613
|
+
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
const paramsStr = params.length > 0 ? ' ' + params.join( ', ' ) + ' ' : '';
|
|
619
|
+
const returnStr = ( returnType && returnType !== 'void' ) ? ` -> ${returnType}` : '';
|
|
620
|
+
|
|
621
|
+
// Emit the function body, which now includes our injected variable declarations.
|
|
622
|
+
const bodyStr = this.emitBody( body );
|
|
623
|
+
|
|
624
|
+
return `fn ${name}(${paramsStr})${returnStr} {\n\n${bodyStr}\n\n${this.tab}}`;
|
|
625
|
+
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
emitComment( statement, body ) {
|
|
629
|
+
|
|
630
|
+
const index = body.indexOf( statement );
|
|
631
|
+
const previous = body[ index - 1 ];
|
|
632
|
+
const next = body[ index + 1 ];
|
|
633
|
+
|
|
634
|
+
let output = '';
|
|
635
|
+
|
|
636
|
+
if ( previous && isExpression( previous ) ) {
|
|
637
|
+
|
|
638
|
+
output += '\n';
|
|
639
|
+
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
output += this.tab + statement.comment.replace( /\n/g, '\n' + this.tab ) + '\n';
|
|
643
|
+
|
|
644
|
+
if ( next && isExpression( next ) ) {
|
|
645
|
+
|
|
646
|
+
output += '\n';
|
|
647
|
+
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
return output;
|
|
651
|
+
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
emitExtraLine( statement, body ) {
|
|
655
|
+
|
|
656
|
+
const index = body.indexOf( statement );
|
|
657
|
+
const previous = body[ index - 1 ];
|
|
658
|
+
|
|
659
|
+
if ( previous === undefined ) return '';
|
|
660
|
+
|
|
661
|
+
if ( statement.isReturn ) return '\n';
|
|
662
|
+
|
|
663
|
+
const lastExp = isExpression( previous );
|
|
664
|
+
const currExp = isExpression( statement );
|
|
665
|
+
|
|
666
|
+
if ( lastExp !== currExp || ( ! lastExp && ! currExp ) ) return '\n';
|
|
667
|
+
|
|
668
|
+
return '';
|
|
669
|
+
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
emit( ast ) {
|
|
673
|
+
|
|
674
|
+
const header = '// Three.js Transpiler r' + REVISION + '\n\n';
|
|
675
|
+
|
|
676
|
+
let globals = '';
|
|
677
|
+
let functions = '';
|
|
678
|
+
let dependencies = '';
|
|
679
|
+
|
|
680
|
+
// 1. Pre-process to find all global declarations
|
|
681
|
+
for ( const statement of ast.body ) {
|
|
682
|
+
|
|
683
|
+
if ( statement.isFunctionDeclaration ) {
|
|
684
|
+
|
|
685
|
+
this.functions.set( statement.name, statement );
|
|
686
|
+
|
|
687
|
+
} else if ( statement.isUniform ) {
|
|
688
|
+
|
|
689
|
+
this.uniforms.push( statement );
|
|
690
|
+
|
|
691
|
+
} else if ( statement.isVarying ) {
|
|
692
|
+
|
|
693
|
+
this.varyings.push( statement );
|
|
694
|
+
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// 2. Build resource bindings (uniforms, textures, samplers)
|
|
700
|
+
if ( this.uniforms.length > 0 ) {
|
|
701
|
+
|
|
702
|
+
let bindingIndex = 0;
|
|
703
|
+
const uniformStructMembers = [];
|
|
704
|
+
const textureGlobals = [];
|
|
705
|
+
|
|
706
|
+
for ( const uniform of this.uniforms ) {
|
|
707
|
+
|
|
708
|
+
// Textures are declared as separate global variables, not in the UBO
|
|
709
|
+
if ( uniform.type.includes( 'texture' ) ) {
|
|
710
|
+
|
|
711
|
+
textureGlobals.push( `@group(${this.groupIndex}) @binding(${bindingIndex ++}) var ${uniform.name}: ${this.getWgslType( uniform.type )};` );
|
|
712
|
+
textureGlobals.push( `@group(${this.groupIndex}) @binding(${bindingIndex ++}) var ${uniform.name}_sampler: sampler;` );
|
|
713
|
+
|
|
714
|
+
} else {
|
|
715
|
+
|
|
716
|
+
uniformStructMembers.push( `\t${uniform.name}: ${this.getWgslType( uniform.type )},` );
|
|
717
|
+
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// Create a UBO struct if there are any non-texture uniforms
|
|
723
|
+
if ( uniformStructMembers.length > 0 ) {
|
|
724
|
+
|
|
725
|
+
globals += 'struct Uniforms {\n';
|
|
726
|
+
globals += uniformStructMembers.join( '\n' );
|
|
727
|
+
globals += '\n};\n';
|
|
728
|
+
globals += `@group(${this.groupIndex}) @binding(${bindingIndex ++}) var<uniform> uniforms: Uniforms;\n\n`;
|
|
729
|
+
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// Add the texture and sampler globals
|
|
733
|
+
globals += textureGlobals.join( '\n' ) + '\n\n';
|
|
734
|
+
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// 3. Build varying structs for stage I/O
|
|
738
|
+
// This is a simplification; a full implementation would need to know the shader stage.
|
|
739
|
+
if ( this.varyings.length > 0 ) {
|
|
740
|
+
|
|
741
|
+
globals += 'struct Varyings {\n';
|
|
742
|
+
let location = 0;
|
|
743
|
+
for ( const varying of this.varyings ) {
|
|
744
|
+
|
|
745
|
+
globals += `\t@location(${location ++}) ${varying.name}: ${this.getWgslType( varying.type )},\n`;
|
|
746
|
+
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
globals += '};\n\n';
|
|
750
|
+
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// 4. Emit all functions and other global statements
|
|
754
|
+
for ( const statement of ast.body ) {
|
|
755
|
+
|
|
756
|
+
functions += this.emitExtraLine( statement, ast.body );
|
|
757
|
+
|
|
758
|
+
if ( statement.isFunctionDeclaration ) {
|
|
759
|
+
|
|
760
|
+
functions += this.emitFunction( statement ) + '\n';
|
|
761
|
+
|
|
762
|
+
} else if ( statement.isComment ) {
|
|
763
|
+
|
|
764
|
+
functions += this.emitComment( statement, ast.body );
|
|
765
|
+
|
|
766
|
+
} else if ( ! statement.isUniform && ! statement.isVarying ) {
|
|
767
|
+
|
|
768
|
+
// Handle other top-level statements like 'const'
|
|
769
|
+
functions += this.emitExpression( statement ) + ';\n';
|
|
770
|
+
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// 4. Build dependencies
|
|
776
|
+
for ( const value of this.polyfills.values() ) {
|
|
777
|
+
|
|
778
|
+
dependencies = `${ value }\n\n`;
|
|
779
|
+
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
return header + dependencies + globals + functions.trimEnd() + '\n';
|
|
783
|
+
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
export default WGSLEncoder;
|