@plastic-software/three 0.167.3 → 0.174.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/build/three.cjs +36277 -24023
- package/build/three.core.js +48830 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +10175 -46743
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +550 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +44348 -50670
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +70301 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +3 -15
- package/examples/jsm/animation/AnimationClipCreator.js +1 -1
- package/examples/jsm/animation/CCDIKSolver.js +61 -11
- package/examples/jsm/capabilities/WebGL.js +27 -21
- package/examples/jsm/capabilities/WebGPU.js +1 -10
- package/examples/jsm/controls/ArcballControls.js +262 -231
- package/examples/jsm/controls/DragControls.js +1 -1
- package/examples/jsm/controls/FirstPersonControls.js +175 -163
- package/examples/jsm/controls/FlyControls.js +194 -188
- package/examples/jsm/controls/OrbitControls.js +801 -777
- package/examples/jsm/controls/PointerLockControls.js +26 -20
- package/examples/jsm/controls/TrackballControls.js +469 -448
- package/examples/jsm/controls/TransformControls.js +119 -68
- package/examples/jsm/csm/CSM.js +2 -2
- package/examples/jsm/csm/CSMFrustum.js +7 -4
- package/examples/jsm/csm/CSMHelper.js +2 -0
- package/examples/jsm/csm/CSMShadowNode.js +442 -0
- package/examples/jsm/curves/NURBSCurve.js +33 -2
- package/examples/jsm/curves/NURBSUtils.js +3 -0
- package/examples/jsm/effects/AnaglyphEffect.js +6 -13
- package/examples/jsm/effects/OutlineEffect.js +1 -1
- package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
- package/examples/jsm/effects/StereoEffect.js +6 -1
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/GLTFExporter.js +181 -109
- package/examples/jsm/exporters/KTX2Exporter.js +54 -23
- package/examples/jsm/exporters/OBJExporter.js +5 -1
- package/examples/jsm/exporters/PLYExporter.js +11 -9
- package/examples/jsm/exporters/USDZExporter.js +50 -11
- package/examples/jsm/geometries/DecalGeometry.js +73 -21
- package/examples/jsm/geometries/TextGeometry.js +1 -12
- package/examples/jsm/helpers/LightProbeHelper.js +43 -44
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +185 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
- package/examples/jsm/interactive/HTMLMesh.js +1 -0
- package/examples/jsm/interactive/InteractiveGroup.js +108 -51
- package/examples/jsm/interactive/SelectionHelper.js +3 -1
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lighting/TiledLighting.js +18 -0
- package/examples/jsm/lights/LightProbeGenerator.js +26 -12
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
- package/examples/jsm/lines/LineGeometry.js +25 -0
- package/examples/jsm/lines/LineMaterial.js +0 -1
- package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
- package/examples/jsm/lines/webgpu/Line2.js +2 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +16 -21
- package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +104 -2
- package/examples/jsm/loaders/BVHLoader.js +1 -1
- package/examples/jsm/loaders/ColladaLoader.js +15 -12
- package/examples/jsm/loaders/DDSLoader.js +42 -0
- package/examples/jsm/loaders/DRACOLoader.js +3 -1
- package/examples/jsm/loaders/FBXLoader.js +71 -22
- package/examples/jsm/loaders/GCodeLoader.js +4 -2
- package/examples/jsm/loaders/GLTFLoader.js +29 -14
- package/examples/jsm/loaders/KTX2Loader.js +160 -58
- package/examples/jsm/loaders/KTXLoader.js +4 -4
- package/examples/jsm/loaders/LDrawLoader.js +22 -136
- package/examples/jsm/loaders/LottieLoader.js +2 -1
- package/examples/jsm/loaders/MTLLoader.js +27 -7
- package/examples/jsm/loaders/MaterialXLoader.js +40 -14
- package/examples/jsm/loaders/NRRDLoader.js +1 -1
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +14 -13
- package/examples/jsm/loaders/PDBLoader.js +3 -2
- package/examples/jsm/loaders/PLYLoader.js +15 -12
- package/examples/jsm/loaders/PVRLoader.js +1 -1
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/SVGLoader.js +2 -2
- package/examples/jsm/loaders/TDSLoader.js +17 -18
- package/examples/jsm/loaders/VRMLLoader.js +17 -17
- package/examples/jsm/loaders/VTKLoader.js +4 -3
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/math/ColorSpaces.js +76 -0
- package/examples/jsm/math/ConvexHull.js +1 -1
- package/examples/jsm/math/OBB.js +17 -0
- package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
- package/examples/jsm/misc/ProgressiveLightMap.js +54 -41
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +294 -0
- package/examples/jsm/misc/Timer.js +27 -12
- package/examples/jsm/misc/Volume.js +28 -18
- package/examples/jsm/misc/VolumeSlice.js +19 -16
- package/examples/jsm/modifiers/CurveModifier.js +10 -8
- package/examples/jsm/modifiers/CurveModifierGPU.js +235 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
- package/examples/jsm/objects/GroundedSkybox.js +4 -4
- package/examples/jsm/objects/LensflareMesh.js +324 -0
- package/examples/jsm/objects/Reflector.js +5 -2
- package/examples/jsm/objects/Sky.js +2 -2
- package/examples/jsm/objects/SkyMesh.js +14 -14
- package/examples/jsm/objects/Water2.js +1 -1
- package/examples/jsm/objects/Water2Mesh.js +11 -9
- package/examples/jsm/objects/WaterMesh.js +38 -33
- package/examples/jsm/physics/JoltPhysics.js +8 -8
- package/examples/jsm/physics/RapierPhysics.js +5 -5
- package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
- package/examples/jsm/postprocessing/BloomPass.js +2 -2
- package/examples/jsm/postprocessing/EffectComposer.js +1 -2
- package/examples/jsm/postprocessing/OutlinePass.js +37 -51
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/postprocessing/SAOPass.js +1 -2
- package/examples/jsm/postprocessing/SMAAPass.js +1 -3
- package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
- package/examples/jsm/postprocessing/SSAOPass.js +2 -4
- package/examples/jsm/postprocessing/SSRPass.js +8 -4
- package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
- package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
- package/examples/jsm/renderers/SVGRenderer.js +6 -4
- package/examples/jsm/shaders/BokehShader2.js +1 -1
- package/examples/jsm/shaders/FXAAShader.js +225 -224
- package/examples/jsm/shaders/GodRaysShader.js +3 -3
- package/examples/jsm/shaders/OutputShader.js +6 -2
- package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
- package/examples/jsm/transpiler/AST.js +12 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +77 -31
- package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -3
- package/examples/jsm/transpiler/TSLEncoder.js +96 -21
- package/examples/jsm/tsl/display/AfterImageNode.js +243 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +106 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +257 -0
- package/{src/nodes/display/BleachBypassNode.js → examples/jsm/tsl/display/BleachBypass.js} +11 -6
- package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +252 -67
- package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
- package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +92 -14
- package/examples/jsm/tsl/display/DotScreenNode.js +103 -0
- package/examples/jsm/tsl/display/FXAANode.js +364 -0
- package/examples/jsm/tsl/display/FilmNode.js +100 -0
- package/examples/jsm/tsl/display/GTAONode.js +521 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +393 -0
- package/examples/jsm/tsl/display/LensflareNode.js +278 -0
- package/examples/jsm/tsl/display/Lut3DNode.js +108 -0
- package/examples/jsm/tsl/display/MotionBlur.js +33 -0
- package/examples/jsm/tsl/display/OutlineNode.js +750 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +88 -0
- package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +160 -28
- package/examples/jsm/tsl/display/RGBShiftNode.js +95 -0
- package/examples/jsm/tsl/display/SMAANode.js +767 -0
- package/examples/jsm/tsl/display/SSAAPassNode.js +357 -0
- package/examples/jsm/tsl/display/SSRNode.js +538 -0
- package/examples/jsm/tsl/display/Sepia.js +24 -0
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +66 -20
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +184 -0
- package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
- package/examples/jsm/tsl/display/TRAAPassNode.js +451 -0
- package/examples/jsm/tsl/display/TransitionNode.js +140 -0
- package/examples/jsm/tsl/display/hashBlur.js +34 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +395 -0
- package/examples/jsm/tsl/math/Bayer.js +18 -0
- package/examples/jsm/tsl/utils/Raymarching.js +65 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +2 -2
- package/examples/jsm/utils/CameraUtils.js +4 -1
- package/examples/jsm/utils/GeometryCompressionUtils.js +38 -123
- package/examples/jsm/utils/GeometryUtils.js +22 -19
- package/examples/jsm/utils/SceneOptimizer.js +410 -0
- package/examples/jsm/utils/SceneUtils.js +2 -2
- package/examples/jsm/utils/ShadowMapViewer.js +3 -8
- package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
- package/examples/jsm/utils/SkeletonUtils.js +84 -66
- package/examples/jsm/utils/UVsDebug.js +1 -1
- package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +1 -0
- package/examples/jsm/utils/WebGPUTextureUtils.js +64 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
- package/examples/jsm/webxr/Text2D.js +6 -6
- package/examples/jsm/webxr/XRControllerModelFactory.js +7 -2
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +14 -9
- package/src/Three.Core.js +182 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +543 -0
- package/src/Three.WebGPU.Nodes.js +23 -0
- package/src/Three.WebGPU.js +13 -184
- package/src/Three.js +1 -176
- package/src/animation/AnimationClip.js +2 -2
- package/src/animation/AnimationObjectGroup.js +2 -2
- package/src/animation/AnimationUtils.js +1 -1
- package/src/animation/PropertyBinding.js +2 -2
- package/src/audio/Audio.js +379 -2
- package/src/audio/AudioAnalyser.js +58 -1
- package/src/audio/AudioContext.js +15 -0
- package/src/audio/AudioListener.js +76 -0
- package/src/audio/PositionalAudio.js +107 -0
- package/src/cameras/ArrayCamera.js +29 -0
- package/src/cameras/Camera.js +47 -0
- package/src/cameras/CubeCamera.js +66 -0
- package/src/cameras/OrthographicCamera.js +109 -0
- package/src/cameras/PerspectiveCamera.js +173 -34
- package/src/cameras/StereoCamera.js +48 -2
- package/src/constants.js +6 -6
- package/src/core/BufferAttribute.js +4 -9
- package/src/core/BufferGeometry.js +48 -8
- package/src/core/Clock.js +1 -1
- package/src/core/EventDispatcher.js +52 -8
- package/src/core/InterleavedBuffer.js +4 -13
- package/src/core/Object3D.js +573 -3
- package/src/core/RenderTarget.js +22 -4
- package/src/core/RenderTarget3D.js +22 -0
- package/src/core/RenderTargetArray.js +22 -0
- package/src/extras/Controls.js +104 -0
- package/src/extras/DataUtils.js +48 -8
- package/src/extras/Earcut.js +18 -7
- package/src/extras/ImageUtils.js +18 -11
- package/src/extras/PMREMGenerator.js +40 -9
- package/src/extras/ShapeUtils.js +24 -2
- package/src/extras/TextureUtils.js +96 -10
- package/src/extras/core/Curve.js +153 -53
- package/src/extras/core/CurvePath.js +63 -22
- package/src/extras/core/Interpolations.js +29 -3
- package/src/extras/core/Path.js +134 -1
- package/src/extras/core/Shape.js +66 -3
- package/src/extras/core/ShapePath.js +76 -0
- 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/geometries/BoxGeometry.js +38 -0
- package/src/geometries/CapsuleGeometry.js +34 -0
- package/src/geometries/CircleGeometry.js +40 -0
- package/src/geometries/ConeGeometry.js +38 -0
- package/src/geometries/CylinderGeometry.js +50 -4
- package/src/geometries/DodecahedronGeometry.js +32 -0
- package/src/geometries/EdgesGeometry.js +30 -2
- package/src/geometries/ExtrudeGeometry.js +52 -0
- package/src/geometries/IcosahedronGeometry.js +32 -0
- package/src/geometries/LatheGeometry.js +43 -3
- package/src/geometries/OctahedronGeometry.js +32 -0
- package/src/geometries/PlaneGeometry.js +34 -0
- package/src/geometries/PolyhedronGeometry.js +29 -0
- package/src/geometries/RingGeometry.js +36 -0
- package/src/geometries/ShapeGeometry.js +37 -0
- package/src/geometries/SphereGeometry.js +37 -0
- package/src/geometries/TetrahedronGeometry.js +32 -0
- package/src/geometries/TorusGeometry.js +35 -0
- package/src/geometries/TorusKnotGeometry.js +38 -0
- package/src/geometries/TubeGeometry.js +49 -0
- package/src/geometries/WireframeGeometry.js +32 -0
- package/src/helpers/ArrowHelper.js +60 -3
- 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 +61 -18
- package/src/helpers/DirectionalLightHelper.js +52 -0
- package/src/helpers/GridHelper.js +26 -0
- package/src/helpers/HemisphereLightHelper.js +39 -0
- package/src/helpers/PlaneHelper.js +33 -0
- package/src/helpers/PointLightHelper.js +43 -0
- package/src/helpers/PolarGridHelper.js +30 -0
- package/src/helpers/SkeletonHelper.js +39 -2
- package/src/helpers/SpotLightHelper.js +40 -0
- package/src/lights/AmbientLight.js +25 -0
- package/src/lights/DirectionalLight.js +57 -0
- package/src/lights/DirectionalLightShadow.js +15 -0
- package/src/lights/HemisphereLight.js +32 -0
- package/src/lights/Light.js +36 -0
- package/src/lights/LightProbe.js +43 -0
- package/src/lights/LightShadow.js +159 -0
- package/src/lights/PointLight.js +59 -0
- package/src/lights/PointLightShadow.js +21 -0
- package/src/lights/RectAreaLight.js +59 -0
- package/src/lights/SpotLight.js +102 -0
- package/src/lights/SpotLightShadow.js +24 -2
- package/src/lights/webgpu/IESSpotLight.js +21 -0
- package/src/loaders/Loader.js +132 -0
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/nodes/NodeLoader.js +189 -0
- package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
- package/src/loaders/nodes/NodeObjectLoader.js +151 -0
- package/src/materials/LineDashedMaterial.js +0 -1
- package/src/materials/Material.js +469 -7
- package/src/materials/MeshPhongMaterial.js +1 -1
- package/src/materials/MeshPhysicalMaterial.js +2 -2
- package/src/materials/MeshStandardMaterial.js +2 -2
- package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +192 -82
- package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
- package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
- package/src/materials/nodes/MeshBasicNodeMaterial.js +133 -0
- package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
- package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
- package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +517 -0
- package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
- package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
- package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
- package/src/materials/nodes/NodeMaterial.js +1180 -0
- package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -2
- package/src/materials/nodes/PointsNodeMaterial.js +153 -0
- package/src/materials/nodes/ShadowNodeMaterial.js +67 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +198 -0
- package/src/materials/nodes/VolumeNodeMaterial.js +72 -0
- package/src/materials/nodes/manager/NodeMaterialObserver.js +509 -0
- package/src/math/Box2.js +177 -0
- package/src/math/Box3.js +243 -0
- package/src/math/Color.js +343 -0
- package/src/math/ColorManagement.js +143 -102
- package/src/math/Cylindrical.js +65 -6
- package/src/math/Euler.js +137 -4
- package/src/math/Frustum.js +83 -0
- package/src/math/Interpolant.js +87 -8
- package/src/math/Line3.js +96 -2
- package/src/math/MathUtils.js +182 -19
- package/src/math/Matrix2.js +70 -0
- package/src/math/Matrix3.js +229 -4
- package/src/math/Matrix4.js +368 -3
- package/src/math/Plane.js +164 -2
- package/src/math/Quaternion.js +265 -9
- package/src/math/Ray.js +160 -0
- package/src/math/Sphere.js +147 -0
- package/src/math/Spherical.js +73 -11
- package/src/math/SphericalHarmonics3.js +112 -14
- package/src/math/Triangle.js +230 -2
- package/src/math/Vector2.js +396 -10
- package/src/math/Vector3.js +550 -13
- package/src/math/Vector4.js +415 -9
- 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 +84 -166
- package/src/nodes/TSL.js +167 -0
- package/src/nodes/accessors/AccessorsUtils.js +39 -10
- package/src/nodes/accessors/Arrays.js +68 -0
- package/src/nodes/accessors/BatchNode.js +93 -26
- package/src/nodes/accessors/Bitangent.js +54 -0
- package/src/nodes/accessors/BufferAttributeNode.js +189 -11
- package/src/nodes/accessors/BufferNode.js +70 -5
- package/src/nodes/accessors/BuiltinNode.js +63 -0
- package/src/nodes/accessors/Camera.js +129 -0
- package/src/nodes/accessors/ClippingNode.js +152 -43
- package/src/nodes/accessors/CubeTextureNode.js +76 -13
- package/src/nodes/accessors/InstanceNode.js +118 -35
- package/src/nodes/accessors/InstancedMeshNode.js +50 -0
- package/src/nodes/accessors/Lights.js +129 -0
- package/src/nodes/accessors/MaterialNode.js +394 -58
- package/src/nodes/accessors/MaterialProperties.js +57 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +60 -18
- package/src/nodes/accessors/ModelNode.js +159 -12
- package/src/nodes/accessors/ModelViewProjectionNode.js +10 -36
- package/src/nodes/accessors/MorphNode.js +60 -13
- package/src/nodes/accessors/Normal.js +156 -0
- package/src/nodes/accessors/Object3DNode.js +154 -35
- package/src/nodes/accessors/PointUVNode.js +35 -6
- package/src/nodes/accessors/Position.js +64 -0
- package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
- package/src/nodes/accessors/ReferenceNode.js +243 -6
- package/src/nodes/accessors/ReflectVector.js +36 -0
- package/src/nodes/accessors/RendererReferenceNode.js +57 -7
- package/src/nodes/accessors/SceneNode.js +98 -6
- package/src/nodes/accessors/SkinningNode.js +214 -21
- package/src/nodes/accessors/StorageBufferNode.js +288 -28
- package/src/nodes/accessors/StorageTextureNode.js +139 -12
- package/src/nodes/accessors/Tangent.js +62 -0
- package/src/nodes/accessors/Texture3DNode.js +98 -12
- package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +14 -34
- package/src/nodes/accessors/TextureNode.js +347 -34
- package/src/nodes/accessors/TextureSizeNode.js +51 -9
- package/src/nodes/accessors/UV.js +11 -0
- package/src/nodes/accessors/UniformArrayNode.js +241 -32
- package/src/nodes/accessors/UserDataNode.js +55 -7
- package/src/nodes/accessors/VelocityNode.js +223 -0
- package/src/nodes/accessors/VertexColorNode.js +45 -6
- package/src/nodes/code/CodeNode.js +108 -8
- package/src/nodes/code/ExpressionNode.js +38 -7
- package/src/nodes/code/FunctionCallNode.js +62 -11
- package/src/nodes/code/FunctionNode.js +54 -24
- package/src/nodes/code/ScriptableNode.js +241 -17
- package/src/nodes/code/ScriptableValueNode.js +93 -8
- package/src/nodes/core/ArrayNode.js +142 -0
- package/src/nodes/core/AssignNode.js +60 -12
- package/src/nodes/core/AttributeNode.js +55 -22
- package/src/nodes/core/BypassNode.js +59 -11
- package/src/nodes/core/CacheNode.js +64 -10
- package/src/nodes/core/ConstNode.js +38 -3
- package/src/nodes/core/ContextNode.js +87 -12
- package/src/nodes/core/IndexNode.js +102 -10
- package/src/nodes/core/InputNode.js +55 -3
- package/src/nodes/core/LightingModel.js +65 -5
- package/src/nodes/core/MRTNode.js +81 -7
- package/src/nodes/core/Node.js +368 -50
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +1317 -83
- package/src/nodes/core/NodeCache.js +41 -2
- package/src/nodes/core/NodeCode.js +31 -0
- package/src/nodes/core/NodeFrame.js +123 -2
- package/src/nodes/core/NodeFunction.js +46 -0
- package/src/nodes/core/NodeFunctionInput.js +44 -0
- package/src/nodes/core/NodeParser.js +11 -0
- package/src/nodes/core/NodeUniform.js +52 -0
- package/src/nodes/core/NodeUtils.js +226 -6
- package/src/nodes/core/NodeVar.js +47 -1
- package/src/nodes/core/NodeVarying.js +28 -0
- package/src/nodes/core/OutputStructNode.js +61 -17
- package/src/nodes/core/ParameterNode.js +34 -4
- package/src/nodes/core/PropertyNode.js +296 -32
- package/src/nodes/core/StackNode.js +108 -8
- package/src/nodes/core/StructNode.js +120 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +116 -9
- package/src/nodes/core/TempNode.js +37 -7
- package/src/nodes/core/UniformGroupNode.js +98 -17
- package/src/nodes/core/UniformNode.js +72 -4
- package/src/nodes/core/VarNode.js +170 -13
- package/src/nodes/core/VaryingNode.js +109 -8
- package/src/nodes/core/constants.js +40 -0
- package/src/nodes/display/BlendModes.js +193 -0
- package/src/nodes/display/BumpMapNode.js +47 -10
- package/src/nodes/display/ColorAdjustment.js +141 -0
- package/src/nodes/display/ColorSpaceFunctions.js +54 -0
- package/src/nodes/display/ColorSpaceNode.js +147 -68
- package/src/nodes/display/FrontFacingNode.js +39 -6
- package/src/nodes/display/NormalMapNode.js +55 -13
- package/src/nodes/display/PassNode.js +420 -19
- package/src/nodes/display/PosterizeNode.js +40 -7
- package/src/nodes/display/RenderOutputNode.js +81 -13
- package/src/nodes/display/ScreenNode.js +286 -0
- package/src/nodes/display/ToneMappingFunctions.js +242 -0
- package/src/nodes/display/ToneMappingNode.js +68 -175
- package/src/nodes/display/ToonOutlinePassNode.js +183 -0
- package/src/nodes/display/ViewportDepthNode.js +210 -36
- package/src/nodes/display/ViewportDepthTextureNode.js +32 -9
- package/src/nodes/display/ViewportSharedTextureNode.js +32 -9
- package/src/nodes/display/ViewportTextureNode.js +68 -11
- package/src/nodes/fog/Fog.js +113 -0
- package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
- package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
- package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +50 -6
- package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/functions/BasicLightingModel.js +27 -6
- package/src/nodes/functions/PhongLightingModel.js +38 -8
- package/src/nodes/functions/PhysicalLightingModel.js +215 -51
- package/src/nodes/functions/ShadowMaskModel.js +24 -1
- package/src/nodes/functions/ToonLightingModel.js +24 -5
- 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/functions/material/getRoughness.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +62 -7
- package/src/nodes/gpgpu/AtomicFunctionNode.js +280 -0
- package/src/nodes/gpgpu/BarrierNode.js +89 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
- package/src/nodes/gpgpu/ComputeNode.js +124 -9
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +208 -0
- package/src/nodes/lighting/AONode.js +24 -3
- package/src/nodes/lighting/AmbientLightNode.js +16 -8
- package/src/nodes/lighting/AnalyticLightNode.js +151 -231
- package/src/nodes/lighting/BasicEnvironmentNode.js +25 -3
- package/src/nodes/lighting/BasicLightMapNode.js +25 -5
- package/src/nodes/lighting/DirectionalLightNode.js +19 -20
- package/src/nodes/lighting/EnvironmentNode.js +34 -17
- package/src/nodes/lighting/HemisphereLightNode.js +42 -11
- package/src/nodes/lighting/IESSpotLightNode.js +18 -9
- package/src/nodes/lighting/IrradianceNode.js +23 -3
- package/src/nodes/lighting/LightProbeNode.js +29 -36
- package/src/nodes/lighting/LightUtils.js +12 -4
- package/src/nodes/lighting/LightingContextNode.js +70 -21
- package/src/nodes/lighting/LightingNode.js +22 -9
- package/src/nodes/lighting/LightsNode.js +309 -86
- package/src/nodes/lighting/PointLightNode.js +66 -32
- package/src/nodes/lighting/PointShadowNode.js +306 -0
- package/src/nodes/lighting/RectAreaLightNode.js +61 -25
- package/src/nodes/lighting/ShadowBaseNode.js +92 -0
- package/src/nodes/lighting/ShadowNode.js +812 -0
- package/src/nodes/lighting/SpotLightNode.js +73 -31
- package/src/nodes/materialx/MaterialXNodes.js +2 -2
- package/src/nodes/materialx/lib/mx_hsv.js +27 -22
- package/src/nodes/materialx/lib/mx_noise.js +70 -70
- package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
- package/src/nodes/math/ConditionalNode.js +230 -0
- package/src/nodes/math/Hash.js +21 -0
- package/src/nodes/math/MathNode.js +812 -131
- package/src/nodes/math/MathUtils.js +47 -8
- package/src/nodes/math/OperatorNode.js +410 -66
- package/src/nodes/math/TriNoise3D.js +32 -32
- package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
- package/src/nodes/parsers/GLSLNodeParser.js +11 -0
- package/src/nodes/pmrem/PMREMNode.js +188 -28
- package/src/nodes/pmrem/PMREMUtils.js +24 -24
- package/src/nodes/procedural/Checker.js +22 -0
- package/src/nodes/shapes/Shapes.js +32 -0
- package/src/nodes/tsl/TSLBase.js +31 -0
- package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +114 -98
- package/src/nodes/utils/ArrayElementNode.js +45 -5
- package/src/nodes/utils/ConvertNode.js +39 -4
- package/src/nodes/utils/CubeMapNode.js +88 -8
- package/src/nodes/utils/Discard.js +24 -0
- package/src/nodes/utils/EquirectUVNode.js +39 -7
- package/src/nodes/utils/FlipNode.js +106 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +61 -6
- package/src/nodes/utils/JoinNode.js +31 -3
- package/src/nodes/utils/LoopNode.js +95 -9
- package/src/nodes/utils/MatcapUVNode.js +27 -8
- package/src/nodes/utils/MaxMipLevelNode.js +57 -6
- package/src/nodes/utils/MemberNode.js +68 -0
- package/src/nodes/utils/Oscillators.js +41 -0
- package/src/nodes/utils/Packing.js +21 -0
- package/src/nodes/utils/PostProcessingUtils.js +95 -0
- package/src/nodes/utils/RTTNode.js +141 -9
- package/src/nodes/utils/ReflectorNode.js +295 -21
- package/src/nodes/utils/RemapNode.js +93 -10
- package/src/nodes/utils/RotateNode.js +48 -13
- package/src/nodes/utils/SetNode.js +50 -4
- package/src/nodes/utils/SplitNode.js +62 -6
- package/src/nodes/utils/SpriteSheetUVNode.js +56 -7
- package/src/nodes/utils/SpriteUtils.js +21 -5
- package/src/nodes/utils/StorageArrayElementNode.js +64 -12
- package/src/nodes/utils/Timer.js +73 -0
- package/src/nodes/utils/TriplanarTexturesNode.js +96 -10
- package/src/nodes/utils/UVUtils.js +27 -9
- package/src/nodes/utils/ViewportUtils.js +16 -4
- package/src/objects/BatchedMesh.js +808 -281
- 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 +120 -2
- package/src/objects/LOD.js +120 -5
- package/src/objects/Line.js +89 -6
- package/src/objects/LineLoop.js +20 -0
- package/src/objects/LineSegments.js +18 -0
- package/src/objects/Mesh.js +82 -23
- package/src/objects/Points.js +62 -0
- package/src/objects/Skeleton.js +107 -2
- package/src/objects/SkinnedMesh.js +99 -5
- package/src/objects/Sprite.js +54 -0
- package/src/renderers/WebGLRenderer.js +274 -157
- package/src/renderers/common/Animation.js +109 -12
- package/src/renderers/common/Attributes.js +40 -0
- package/src/renderers/common/Backend.js +504 -44
- package/src/renderers/common/Background.js +67 -9
- package/src/renderers/common/BindGroup.js +45 -1
- package/src/renderers/common/Binding.js +35 -0
- package/src/renderers/common/Bindings.js +136 -19
- package/src/renderers/common/Buffer.js +49 -0
- package/src/renderers/common/BufferUtils.js +25 -0
- package/src/renderers/common/BundleGroup.js +83 -0
- package/src/renderers/common/ChainMap.js +45 -6
- package/src/renderers/common/ClippingContext.js +175 -80
- 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 +22 -3
- package/src/renderers/common/DataMap.js +37 -1
- package/src/renderers/common/Geometries.js +111 -14
- package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
- package/src/renderers/common/Info.js +78 -35
- package/src/renderers/common/Lighting.js +73 -0
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +148 -5
- package/src/renderers/common/PostProcessing.js +112 -11
- package/src/renderers/common/ProgrammableStage.js +60 -2
- package/src/renderers/common/QuadMesh.js +56 -5
- package/src/renderers/common/RenderBundle.js +14 -8
- package/src/renderers/common/RenderBundles.js +39 -10
- package/src/renderers/common/RenderContext.js +205 -7
- package/src/renderers/common/RenderContexts.js +59 -6
- package/src/renderers/common/RenderList.js +230 -21
- package/src/renderers/common/RenderLists.js +45 -6
- package/src/renderers/common/RenderObject.js +552 -41
- package/src/renderers/common/RenderObjects.js +118 -9
- package/src/renderers/common/RenderPipeline.js +24 -0
- package/src/renderers/common/Renderer.js +1537 -239
- package/src/renderers/common/RendererUtils.js +191 -0
- package/src/renderers/common/SampledTexture.js +132 -3
- package/src/renderers/common/Sampler.js +30 -0
- package/src/renderers/common/StorageBuffer.js +24 -0
- package/src/renderers/common/StorageBufferAttribute.js +31 -2
- package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
- package/src/renderers/common/StorageTexture.js +38 -0
- package/src/renderers/common/Textures.js +142 -32
- package/src/renderers/common/TimestampQueryPool.js +98 -0
- package/src/renderers/common/Uniform.js +225 -3
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +157 -6
- package/src/renderers/common/XRManager.js +1185 -0
- package/src/renderers/common/XRRenderTarget.js +74 -0
- package/src/renderers/common/extras/PMREMGenerator.js +211 -53
- package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
- package/src/renderers/common/nodes/NodeLibrary.js +194 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +92 -4
- package/src/renderers/common/nodes/NodeSampler.js +28 -0
- package/src/renderers/common/nodes/NodeStorageBuffer.js +37 -3
- package/src/renderers/common/nodes/NodeUniform.js +285 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
- package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
- package/src/renderers/common/nodes/Nodes.js +390 -70
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderLib/points.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/webgl/WebGLAttributes.js +45 -14
- package/src/renderers/webgl/WebGLBackground.js +24 -1
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +2 -0
- package/src/renderers/webgl/WebGLGeometries.js +0 -28
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLProgram.js +27 -29
- package/src/renderers/webgl/WebGLPrograms.js +24 -16
- package/src/renderers/webgl/WebGLState.js +68 -11
- package/src/renderers/webgl/WebGLTextures.js +49 -10
- package/src/renderers/webgl-fallback/WebGLBackend.js +1055 -238
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +425 -48
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +64 -1
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +419 -14
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +281 -59
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +367 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
- package/src/renderers/webgpu/WebGPUBackend.js +816 -236
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +78 -0
- package/src/renderers/webgpu/WebGPURenderer.js +45 -6
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +63 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +97 -0
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +954 -147
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +29 -4
- package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +147 -31
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +213 -31
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +146 -28
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +161 -7
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +333 -50
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +131 -3
- package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
- package/src/renderers/webxr/WebXRManager.js +54 -32
- package/src/scenes/Fog.js +60 -0
- package/src/scenes/FogExp2.js +51 -0
- package/src/scenes/Scene.js +87 -0
- package/src/textures/Data3DTexture.js +2 -2
- package/src/textures/DepthTexture.js +2 -0
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +368 -5
- package/src/textures/VideoFrameTexture.js +35 -0
- package/src/utils.js +33 -1
- 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/controls/Controls.js +0 -32
- package/examples/jsm/exporters/MMDExporter.js +0 -217
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/LogLuvLoader.js +0 -606
- package/examples/jsm/loaders/MMDLoader.js +0 -2295
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/objects/InstancedPoints.js +0 -21
- package/examples/jsm/shaders/MMDToonShader.js +0 -134
- package/examples/jsm/utils/GPUStatsPanel.js +0 -95
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/nodes/accessors/BitangentNode.js +0 -13
- package/src/nodes/accessors/CameraNode.js +0 -19
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -21
- package/src/nodes/accessors/NormalNode.js +0 -14
- package/src/nodes/accessors/PositionNode.js +0 -10
- package/src/nodes/accessors/ReflectVectorNode.js +0 -10
- package/src/nodes/accessors/TangentNode.js +0 -23
- package/src/nodes/accessors/UVNode.js +0 -3
- package/src/nodes/core/NodeKeywords.js +0 -80
- package/src/nodes/core/UniformGroup.js +0 -13
- package/src/nodes/display/AfterImageNode.js +0 -152
- package/src/nodes/display/AnamorphicNode.js +0 -145
- package/src/nodes/display/BlendModeNode.js +0 -128
- package/src/nodes/display/ColorAdjustmentNode.js +0 -104
- package/src/nodes/display/DenoiseNode.js +0 -198
- package/src/nodes/display/DotScreenNode.js +0 -75
- package/src/nodes/display/FXAANode.js +0 -327
- package/src/nodes/display/FilmNode.js +0 -52
- package/src/nodes/display/GTAONode.js +0 -324
- package/src/nodes/display/GaussianBlurNode.js +0 -207
- package/src/nodes/display/Lut3DNode.js +0 -53
- package/src/nodes/display/RGBShiftNode.js +0 -49
- package/src/nodes/display/SepiaNode.js +0 -18
- package/src/nodes/display/TransitionNode.js +0 -76
- package/src/nodes/display/ViewportNode.js +0 -137
- package/src/nodes/fog/FogExp2Node.js +0 -34
- package/src/nodes/fog/FogNode.js +0 -48
- package/src/nodes/fog/FogRangeNode.js +0 -35
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/nodes/loaders/NodeLoader.js +0 -110
- package/src/nodes/loaders/NodeMaterialLoader.js +0 -60
- package/src/nodes/loaders/NodeObjectLoader.js +0 -71
- package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
- package/src/nodes/materials/LineBasicNodeMaterial.js +0 -28
- package/src/nodes/materials/LineDashedNodeMaterial.js +0 -55
- package/src/nodes/materials/MeshBasicNodeMaterial.js +0 -73
- package/src/nodes/materials/MeshLambertNodeMaterial.js +0 -43
- package/src/nodes/materials/MeshMatcapNodeMaterial.js +0 -53
- package/src/nodes/materials/MeshNormalNodeMaterial.js +0 -40
- package/src/nodes/materials/MeshPhongNodeMaterial.js +0 -74
- package/src/nodes/materials/MeshPhysicalNodeMaterial.js +0 -244
- package/src/nodes/materials/MeshSSSNodeMaterial.js +0 -84
- package/src/nodes/materials/MeshStandardNodeMaterial.js +0 -104
- package/src/nodes/materials/MeshToonNodeMaterial.js +0 -34
- package/src/nodes/materials/NodeMaterial.js +0 -680
- package/src/nodes/materials/PointsNodeMaterial.js +0 -39
- package/src/nodes/materials/ShadowNodeMaterial.js +0 -34
- package/src/nodes/materials/SpriteNodeMaterial.js +0 -90
- package/src/nodes/materials/VolumeNodeMaterial.js +0 -106
- package/src/nodes/math/CondNode.js +0 -139
- package/src/nodes/math/HashNode.js +0 -34
- package/src/nodes/procedural/CheckerNode.js +0 -42
- package/src/nodes/utils/DiscardNode.js +0 -28
- package/src/nodes/utils/OscNode.js +0 -81
- package/src/nodes/utils/PackingNode.js +0 -55
- package/src/nodes/utils/TimerNode.js +0 -94
|
@@ -11,12 +11,27 @@ import { NodeBuilder, CodeNode } from '../../../nodes/Nodes.js';
|
|
|
11
11
|
import { getFormat } from '../utils/WebGPUTextureUtils.js';
|
|
12
12
|
|
|
13
13
|
import WGSLNodeParser from './WGSLNodeParser.js';
|
|
14
|
-
import {
|
|
14
|
+
import { NodeAccess } from '../../../nodes/core/constants.js';
|
|
15
15
|
|
|
16
|
-
import
|
|
16
|
+
import VarNode from '../../../nodes/core/VarNode.js';
|
|
17
|
+
import ExpressionNode from '../../../nodes/code/ExpressionNode.js';
|
|
18
|
+
|
|
19
|
+
import { NoColorSpace, FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter } from '../../../constants.js';
|
|
17
20
|
|
|
18
21
|
// GPUShaderStage is not defined in browsers not supporting WebGPU
|
|
19
|
-
const GPUShaderStage = self.GPUShaderStage;
|
|
22
|
+
const GPUShaderStage = ( typeof self !== 'undefined' ) ? self.GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 };
|
|
23
|
+
|
|
24
|
+
const accessNames = {
|
|
25
|
+
[ NodeAccess.READ_ONLY ]: 'read',
|
|
26
|
+
[ NodeAccess.WRITE_ONLY ]: 'write',
|
|
27
|
+
[ NodeAccess.READ_WRITE ]: 'read_write'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const wrapNames = {
|
|
31
|
+
[ RepeatWrapping ]: 'repeat',
|
|
32
|
+
[ ClampToEdgeWrapping ]: 'clamp',
|
|
33
|
+
[ MirroredRepeatWrapping ]: 'mirror'
|
|
34
|
+
};
|
|
20
35
|
|
|
21
36
|
const gpuShaderStageLib = {
|
|
22
37
|
'vertex': GPUShaderStage ? GPUShaderStage.VERTEX : 1,
|
|
@@ -57,21 +72,12 @@ const wgslTypeLib = {
|
|
|
57
72
|
bvec4: 'vec4<bool>',
|
|
58
73
|
|
|
59
74
|
mat2: 'mat2x2<f32>',
|
|
60
|
-
imat2: 'mat2x2<i32>',
|
|
61
|
-
umat2: 'mat2x2<u32>',
|
|
62
|
-
bmat2: 'mat2x2<bool>',
|
|
63
|
-
|
|
64
75
|
mat3: 'mat3x3<f32>',
|
|
65
|
-
|
|
66
|
-
umat3: 'mat3x3<u32>',
|
|
67
|
-
bmat3: 'mat3x3<bool>',
|
|
68
|
-
|
|
69
|
-
mat4: 'mat4x4<f32>',
|
|
70
|
-
imat4: 'mat4x4<i32>',
|
|
71
|
-
umat4: 'mat4x4<u32>',
|
|
72
|
-
bmat4: 'mat4x4<bool>'
|
|
76
|
+
mat4: 'mat4x4<f32>'
|
|
73
77
|
};
|
|
74
78
|
|
|
79
|
+
const wgslCodeCache = {};
|
|
80
|
+
|
|
75
81
|
const wgslPolyfill = {
|
|
76
82
|
tsl_xor: new CodeNode( 'fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }' ),
|
|
77
83
|
mod_float: new CodeNode( 'fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }' ),
|
|
@@ -82,19 +88,13 @@ const wgslPolyfill = {
|
|
|
82
88
|
equals_bvec2: new CodeNode( 'fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }' ),
|
|
83
89
|
equals_bvec3: new CodeNode( 'fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }' ),
|
|
84
90
|
equals_bvec4: new CodeNode( 'fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }' ),
|
|
85
|
-
|
|
86
|
-
fn
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
repeatWrapping_float: new CodeNode( 'fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }' ),
|
|
92
|
+
mirrorWrapping_float: new CodeNode( 'fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }' ),
|
|
93
|
+
clampWrapping_float: new CodeNode( 'fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }' ),
|
|
94
|
+
biquadraticTexture: new CodeNode( /* wgsl */`
|
|
95
|
+
fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {
|
|
89
96
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
` ),
|
|
94
|
-
biquadraticTexture: new CodeNode( `
|
|
95
|
-
fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {
|
|
96
|
-
|
|
97
|
-
let res = vec2f( textureDimensions( map, level ) );
|
|
97
|
+
let res = vec2f( iRes );
|
|
98
98
|
|
|
99
99
|
let uvScaled = coord * res;
|
|
100
100
|
let uvWrapping = ( ( uvScaled % res ) + res ) % res;
|
|
@@ -105,10 +105,10 @@ fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -
|
|
|
105
105
|
let iuv = floor( uv );
|
|
106
106
|
let f = fract( uv );
|
|
107
107
|
|
|
108
|
-
let rg1 = textureLoad( map,
|
|
109
|
-
let rg2 = textureLoad( map,
|
|
110
|
-
let rg3 = textureLoad( map,
|
|
111
|
-
let rg4 = textureLoad( map,
|
|
108
|
+
let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );
|
|
109
|
+
let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );
|
|
110
|
+
let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );
|
|
111
|
+
let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );
|
|
112
112
|
|
|
113
113
|
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
114
114
|
|
|
@@ -133,7 +133,7 @@ const wgslMethods = {
|
|
|
133
133
|
|
|
134
134
|
// WebGPU issue: does not support pow() with negative base on Windows
|
|
135
135
|
|
|
136
|
-
if ( /Windows/g.test( navigator.userAgent ) ) {
|
|
136
|
+
if ( typeof navigator !== 'undefined' && /Windows/g.test( navigator.userAgent ) ) {
|
|
137
137
|
|
|
138
138
|
wgslPolyfill.pow_float = new CodeNode( 'fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }' );
|
|
139
139
|
wgslPolyfill.pow_vec2 = new CodeNode( 'fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }', [ wgslPolyfill.pow_float ] );
|
|
@@ -149,26 +149,91 @@ if ( /Windows/g.test( navigator.userAgent ) ) {
|
|
|
149
149
|
|
|
150
150
|
//
|
|
151
151
|
|
|
152
|
+
let diagnostics = '';
|
|
153
|
+
|
|
154
|
+
if ( ( typeof navigator !== 'undefined' && /Firefox|Deno/g.test( navigator.userAgent ) ) !== true ) {
|
|
155
|
+
|
|
156
|
+
diagnostics += 'diagnostic( off, derivative_uniformity );\n';
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* A node builder targeting WGSL.
|
|
162
|
+
*
|
|
163
|
+
* This module generates WGSL shader code from node materials and also
|
|
164
|
+
* generates the respective bindings and vertex buffer definitions. These
|
|
165
|
+
* data are later used by the renderer to create render and compute pipelines
|
|
166
|
+
* for render objects.
|
|
167
|
+
*
|
|
168
|
+
* @augments NodeBuilder
|
|
169
|
+
*/
|
|
152
170
|
class WGSLNodeBuilder extends NodeBuilder {
|
|
153
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Constructs a new WGSL node builder renderer.
|
|
174
|
+
*
|
|
175
|
+
* @param {Object3D} object - The 3D object.
|
|
176
|
+
* @param {Renderer} renderer - The renderer.
|
|
177
|
+
*/
|
|
154
178
|
constructor( object, renderer ) {
|
|
155
179
|
|
|
156
180
|
super( object, renderer, new WGSLNodeParser() );
|
|
157
181
|
|
|
182
|
+
/**
|
|
183
|
+
* A dictionary that holds for each shader stage ('vertex', 'fragment', 'compute')
|
|
184
|
+
* another dictionary which manages UBOs per group ('render','frame','object').
|
|
185
|
+
*
|
|
186
|
+
* @type {Object<string,Object<string,NodeUniformsGroup>>}
|
|
187
|
+
*/
|
|
158
188
|
this.uniformGroups = {};
|
|
159
189
|
|
|
190
|
+
/**
|
|
191
|
+
* A dictionary that holds for each shader stage a Map of builtins.
|
|
192
|
+
*
|
|
193
|
+
* @type {Object<string,Map<string,Object>>}
|
|
194
|
+
*/
|
|
160
195
|
this.builtins = {};
|
|
161
196
|
|
|
197
|
+
/**
|
|
198
|
+
* A dictionary that holds for each shader stage a Set of directives.
|
|
199
|
+
*
|
|
200
|
+
* @type {Object<string,Set<string>>}
|
|
201
|
+
*/
|
|
162
202
|
this.directives = {};
|
|
163
203
|
|
|
204
|
+
/**
|
|
205
|
+
* A map for managing scope arrays. Only relevant for when using
|
|
206
|
+
* {@link WorkgroupInfoNode} in context of compute shaders.
|
|
207
|
+
*
|
|
208
|
+
* @type {Map<string,Object>}
|
|
209
|
+
*/
|
|
210
|
+
this.scopedArrays = new Map();
|
|
211
|
+
|
|
164
212
|
}
|
|
165
213
|
|
|
166
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Checks if the given texture requires a manual conversion to the working color space.
|
|
216
|
+
*
|
|
217
|
+
* @param {Texture} texture - The texture to check.
|
|
218
|
+
* @return {boolean} Whether the given texture requires a conversion to working color space or not.
|
|
219
|
+
*/
|
|
220
|
+
needsToWorkingColorSpace( texture ) {
|
|
167
221
|
|
|
168
222
|
return texture.isVideoTexture === true && texture.colorSpace !== NoColorSpace;
|
|
169
223
|
|
|
170
224
|
}
|
|
171
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Generates the WGSL snippet for sampled textures.
|
|
228
|
+
*
|
|
229
|
+
* @private
|
|
230
|
+
* @param {Texture} texture - The texture.
|
|
231
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
232
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
233
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
234
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
235
|
+
* @return {string} The WGSL snippet.
|
|
236
|
+
*/
|
|
172
237
|
_generateTextureSample( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
173
238
|
|
|
174
239
|
if ( shaderStage === 'fragment' ) {
|
|
@@ -189,12 +254,21 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
189
254
|
|
|
190
255
|
} else {
|
|
191
256
|
|
|
192
|
-
return this.generateTextureLod( texture, textureProperty, uvSnippet, '0' );
|
|
257
|
+
return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, '0' );
|
|
193
258
|
|
|
194
259
|
}
|
|
195
260
|
|
|
196
261
|
}
|
|
197
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Generates the WGSL snippet when sampling video textures.
|
|
265
|
+
*
|
|
266
|
+
* @private
|
|
267
|
+
* @param {string} textureProperty - The name of the video texture uniform in the shader.
|
|
268
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
269
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
270
|
+
* @return {string} The WGSL snippet.
|
|
271
|
+
*/
|
|
198
272
|
_generateVideoSample( textureProperty, uvSnippet, shaderStage = this.shaderStage ) {
|
|
199
273
|
|
|
200
274
|
if ( shaderStage === 'fragment' ) {
|
|
@@ -209,9 +283,21 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
209
283
|
|
|
210
284
|
}
|
|
211
285
|
|
|
286
|
+
/**
|
|
287
|
+
* Generates the WGSL snippet when sampling textures with explicit mip level.
|
|
288
|
+
*
|
|
289
|
+
* @private
|
|
290
|
+
* @param {Texture} texture - The texture.
|
|
291
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
292
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
293
|
+
* @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
294
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
295
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
296
|
+
* @return {string} The WGSL snippet.
|
|
297
|
+
*/
|
|
212
298
|
_generateTextureSampleLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
213
299
|
|
|
214
|
-
if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false ) {
|
|
300
|
+
if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( texture ) === false ) {
|
|
215
301
|
|
|
216
302
|
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
|
|
217
303
|
|
|
@@ -221,56 +307,301 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
221
307
|
|
|
222
308
|
} else {
|
|
223
309
|
|
|
224
|
-
return this.generateTextureLod( texture, textureProperty, uvSnippet, levelSnippet );
|
|
310
|
+
return this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet );
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Generates a wrap function used in context of textures.
|
|
318
|
+
*
|
|
319
|
+
* @param {Texture} texture - The texture to generate the function for.
|
|
320
|
+
* @return {string} The name of the generated function.
|
|
321
|
+
*/
|
|
322
|
+
generateWrapFunction( texture ) {
|
|
323
|
+
|
|
324
|
+
const functionName = `tsl_coord_${ wrapNames[ texture.wrapS ] }S_${ wrapNames[ texture.wrapT ] }_${texture.isData3DTexture ? '3d' : '2d'}T`;
|
|
325
|
+
|
|
326
|
+
let nodeCode = wgslCodeCache[ functionName ];
|
|
327
|
+
|
|
328
|
+
if ( nodeCode === undefined ) {
|
|
329
|
+
|
|
330
|
+
const includes = [];
|
|
331
|
+
|
|
332
|
+
// For 3D textures, use vec3f; for texture arrays, keep vec2f since array index is separate
|
|
333
|
+
const coordType = texture.isData3DTexture ? 'vec3f' : 'vec2f';
|
|
334
|
+
let code = `fn ${functionName}( coord : ${coordType} ) -> ${coordType} {\n\n\treturn ${coordType}(\n`;
|
|
335
|
+
|
|
336
|
+
const addWrapSnippet = ( wrap, axis ) => {
|
|
337
|
+
|
|
338
|
+
if ( wrap === RepeatWrapping ) {
|
|
339
|
+
|
|
340
|
+
includes.push( wgslPolyfill.repeatWrapping_float );
|
|
341
|
+
|
|
342
|
+
code += `\t\ttsl_repeatWrapping_float( coord.${ axis } )`;
|
|
343
|
+
|
|
344
|
+
} else if ( wrap === ClampToEdgeWrapping ) {
|
|
345
|
+
|
|
346
|
+
includes.push( wgslPolyfill.clampWrapping_float );
|
|
347
|
+
|
|
348
|
+
code += `\t\ttsl_clampWrapping_float( coord.${ axis } )`;
|
|
349
|
+
|
|
350
|
+
} else if ( wrap === MirroredRepeatWrapping ) {
|
|
351
|
+
|
|
352
|
+
includes.push( wgslPolyfill.mirrorWrapping_float );
|
|
353
|
+
|
|
354
|
+
code += `\t\ttsl_mirrorWrapping_float( coord.${ axis } )`;
|
|
355
|
+
|
|
356
|
+
} else {
|
|
357
|
+
|
|
358
|
+
code += `\t\tcoord.${ axis }`;
|
|
359
|
+
|
|
360
|
+
console.warn( `WebGPURenderer: Unsupported texture wrap type "${ wrap }" for vertex shader.` );
|
|
361
|
+
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
addWrapSnippet( texture.wrapS, 'x' );
|
|
367
|
+
|
|
368
|
+
code += ',\n';
|
|
369
|
+
|
|
370
|
+
addWrapSnippet( texture.wrapT, 'y' );
|
|
371
|
+
|
|
372
|
+
if ( texture.isData3DTexture ) {
|
|
373
|
+
|
|
374
|
+
code += ',\n';
|
|
375
|
+
addWrapSnippet( texture.wrapR, 'z' );
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
code += '\n\t);\n\n}\n';
|
|
380
|
+
|
|
381
|
+
wgslCodeCache[ functionName ] = nodeCode = new CodeNode( code, includes );
|
|
382
|
+
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
nodeCode.build( this );
|
|
386
|
+
|
|
387
|
+
return functionName;
|
|
388
|
+
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Generates the array declaration string.
|
|
393
|
+
*
|
|
394
|
+
* @param {string} type - The type.
|
|
395
|
+
* @param {?number} [count] - The count.
|
|
396
|
+
* @return {string} The generated value as a shader string.
|
|
397
|
+
*/
|
|
398
|
+
generateArrayDeclaration( type, count ) {
|
|
399
|
+
|
|
400
|
+
return `array< ${ this.getType( type ) }, ${ count } >`;
|
|
401
|
+
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Generates a WGSL variable that holds the texture dimension of the given texture.
|
|
406
|
+
* It also returns information about the the number of layers (elements) of an arrayed
|
|
407
|
+
* texture as well as the cube face count of cube textures.
|
|
408
|
+
*
|
|
409
|
+
* @param {Texture} texture - The texture to generate the function for.
|
|
410
|
+
* @param {string} textureProperty - The name of the video texture uniform in the shader.
|
|
411
|
+
* @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
412
|
+
* @return {string} The name of the dimension variable.
|
|
413
|
+
*/
|
|
414
|
+
generateTextureDimension( texture, textureProperty, levelSnippet ) {
|
|
415
|
+
|
|
416
|
+
const textureData = this.getDataFromNode( texture, this.shaderStage, this.globalCache );
|
|
417
|
+
|
|
418
|
+
if ( textureData.dimensionsSnippet === undefined ) textureData.dimensionsSnippet = {};
|
|
419
|
+
|
|
420
|
+
let textureDimensionNode = textureData.dimensionsSnippet[ levelSnippet ];
|
|
421
|
+
|
|
422
|
+
if ( textureData.dimensionsSnippet[ levelSnippet ] === undefined ) {
|
|
423
|
+
|
|
424
|
+
let textureDimensionsParams;
|
|
425
|
+
let dimensionType;
|
|
426
|
+
|
|
427
|
+
const { primarySamples } = this.renderer.backend.utils.getTextureSampleData( texture );
|
|
428
|
+
const isMultisampled = primarySamples > 1;
|
|
429
|
+
|
|
430
|
+
if ( texture.isData3DTexture ) {
|
|
431
|
+
|
|
432
|
+
dimensionType = 'vec3<u32>';
|
|
433
|
+
|
|
434
|
+
} else {
|
|
435
|
+
|
|
436
|
+
// Regular 2D textures, depth textures, etc.
|
|
437
|
+
dimensionType = 'vec2<u32>';
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Build parameters string based on texture type and multisampling
|
|
442
|
+
if ( isMultisampled || texture.isVideoTexture || texture.isStorageTexture ) {
|
|
443
|
+
|
|
444
|
+
textureDimensionsParams = textureProperty;
|
|
445
|
+
|
|
446
|
+
} else {
|
|
447
|
+
|
|
448
|
+
textureDimensionsParams = `${textureProperty}${levelSnippet ? `, u32( ${ levelSnippet } )` : ''}`;
|
|
449
|
+
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
textureDimensionNode = new VarNode( new ExpressionNode( `textureDimensions( ${ textureDimensionsParams } )`, dimensionType ) );
|
|
453
|
+
|
|
454
|
+
textureData.dimensionsSnippet[ levelSnippet ] = textureDimensionNode;
|
|
455
|
+
|
|
456
|
+
if ( texture.isDataArrayTexture || texture.isData3DTexture ) {
|
|
457
|
+
|
|
458
|
+
textureData.arrayLayerCount = new VarNode(
|
|
459
|
+
new ExpressionNode(
|
|
460
|
+
`textureNumLayers(${textureProperty})`,
|
|
461
|
+
'u32'
|
|
462
|
+
)
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// For cube textures, we know it's always 6 faces
|
|
468
|
+
if ( texture.isTextureCube ) {
|
|
469
|
+
|
|
470
|
+
textureData.cubeFaceCount = new VarNode(
|
|
471
|
+
new ExpressionNode( '6u', 'u32' )
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
}
|
|
225
475
|
|
|
226
476
|
}
|
|
227
477
|
|
|
478
|
+
return textureDimensionNode.build( this );
|
|
479
|
+
|
|
228
480
|
}
|
|
229
481
|
|
|
230
|
-
|
|
482
|
+
/**
|
|
483
|
+
* Generates the WGSL snippet for a manual filtered texture.
|
|
484
|
+
*
|
|
485
|
+
* @param {Texture} texture - The texture.
|
|
486
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
487
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
488
|
+
* @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
489
|
+
* @return {string} The WGSL snippet.
|
|
490
|
+
*/
|
|
491
|
+
generateFilteredTexture( texture, textureProperty, uvSnippet, levelSnippet = '0u' ) {
|
|
231
492
|
|
|
232
493
|
this._include( 'biquadraticTexture' );
|
|
233
494
|
|
|
234
|
-
|
|
495
|
+
const wrapFunction = this.generateWrapFunction( texture );
|
|
496
|
+
const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
|
|
497
|
+
|
|
498
|
+
return `tsl_biquadraticTexture( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ levelSnippet } ) )`;
|
|
235
499
|
|
|
236
500
|
}
|
|
237
501
|
|
|
238
|
-
|
|
502
|
+
/**
|
|
503
|
+
* Generates the WGSL snippet for a texture lookup with explicit level-of-detail.
|
|
504
|
+
* Since it's a lookup, no sampling or filtering is applied.
|
|
505
|
+
*
|
|
506
|
+
* @param {Texture} texture - The texture.
|
|
507
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
508
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
509
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
510
|
+
* @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
511
|
+
* @return {string} The WGSL snippet.
|
|
512
|
+
*/
|
|
513
|
+
generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, levelSnippet = '0u' ) {
|
|
239
514
|
|
|
240
|
-
this.
|
|
515
|
+
const wrapFunction = this.generateWrapFunction( texture );
|
|
516
|
+
const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
|
|
241
517
|
|
|
242
|
-
const
|
|
518
|
+
const vecType = texture.isData3DTexture ? 'vec3' : 'vec2';
|
|
519
|
+
const coordSnippet = `${vecType}<u32>(${wrapFunction}(${uvSnippet}) * ${vecType}<f32>(${textureDimension}))`;
|
|
243
520
|
|
|
244
|
-
return
|
|
521
|
+
return this.generateTextureLoad( texture, textureProperty, coordSnippet, depthSnippet, levelSnippet );
|
|
245
522
|
|
|
246
523
|
}
|
|
247
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Generates the WGSL snippet that reads a single texel from a texture without sampling or filtering.
|
|
527
|
+
*
|
|
528
|
+
* @param {Texture} texture - The texture.
|
|
529
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
530
|
+
* @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
531
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
532
|
+
* @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
533
|
+
* @return {string} The WGSL snippet.
|
|
534
|
+
*/
|
|
248
535
|
generateTextureLoad( texture, textureProperty, uvIndexSnippet, depthSnippet, levelSnippet = '0u' ) {
|
|
249
536
|
|
|
250
|
-
if (
|
|
537
|
+
if ( texture.isVideoTexture === true || texture.isStorageTexture === true ) {
|
|
538
|
+
|
|
539
|
+
return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`;
|
|
540
|
+
|
|
541
|
+
} else if ( depthSnippet ) {
|
|
251
542
|
|
|
252
|
-
return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
|
|
543
|
+
return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet }, u32( ${ levelSnippet } ) )`;
|
|
253
544
|
|
|
254
545
|
} else {
|
|
255
546
|
|
|
256
|
-
return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ levelSnippet } )`;
|
|
547
|
+
return `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, u32( ${ levelSnippet } ) )`;
|
|
257
548
|
|
|
258
549
|
}
|
|
259
550
|
|
|
260
551
|
}
|
|
261
552
|
|
|
553
|
+
/**
|
|
554
|
+
* Generates the WGSL snippet that writes a single texel to a texture.
|
|
555
|
+
*
|
|
556
|
+
* @param {Texture} texture - The texture.
|
|
557
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
558
|
+
* @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
559
|
+
* @param {string} valueSnippet - A WGSL snippet that represent the new texel value.
|
|
560
|
+
* @return {string} The WGSL snippet.
|
|
561
|
+
*/
|
|
262
562
|
generateTextureStore( texture, textureProperty, uvIndexSnippet, valueSnippet ) {
|
|
263
563
|
|
|
264
564
|
return `textureStore( ${ textureProperty }, ${ uvIndexSnippet }, ${ valueSnippet } )`;
|
|
265
565
|
|
|
266
566
|
}
|
|
267
567
|
|
|
568
|
+
/**
|
|
569
|
+
* Returns `true` if the sampled values of the given texture should be compared against a reference value.
|
|
570
|
+
*
|
|
571
|
+
* @param {Texture} texture - The texture.
|
|
572
|
+
* @return {boolean} Whether the sampled values of the given texture should be compared against a reference value or not.
|
|
573
|
+
*/
|
|
574
|
+
isSampleCompare( texture ) {
|
|
575
|
+
|
|
576
|
+
return texture.isDepthTexture === true && texture.compareFunction !== null;
|
|
577
|
+
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Returns `true` if the given texture is unfilterable.
|
|
582
|
+
*
|
|
583
|
+
* @param {Texture} texture - The texture.
|
|
584
|
+
* @return {boolean} Whether the given texture is unfilterable or not.
|
|
585
|
+
*/
|
|
268
586
|
isUnfilterable( texture ) {
|
|
269
587
|
|
|
270
|
-
return this.getComponentTypeFromTexture( texture ) !== 'float' ||
|
|
588
|
+
return this.getComponentTypeFromTexture( texture ) !== 'float' ||
|
|
589
|
+
( ! this.isAvailable( 'float32Filterable' ) && texture.isDataTexture === true && texture.type === FloatType ) ||
|
|
590
|
+
( this.isSampleCompare( texture ) === false && texture.minFilter === NearestFilter && texture.magFilter === NearestFilter ) ||
|
|
591
|
+
this.renderer.backend.utils.getTextureSampleData( texture ).primarySamples > 1;
|
|
271
592
|
|
|
272
593
|
}
|
|
273
594
|
|
|
595
|
+
/**
|
|
596
|
+
* Generates the WGSL snippet for sampling/loading the given texture.
|
|
597
|
+
*
|
|
598
|
+
* @param {Texture} texture - The texture.
|
|
599
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
600
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
601
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
602
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
603
|
+
* @return {string} The WGSL snippet.
|
|
604
|
+
*/
|
|
274
605
|
generateTexture( texture, textureProperty, uvSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
275
606
|
|
|
276
607
|
let snippet = null;
|
|
@@ -281,7 +612,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
281
612
|
|
|
282
613
|
} else if ( this.isUnfilterable( texture ) ) {
|
|
283
614
|
|
|
284
|
-
snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, '0',
|
|
615
|
+
snippet = this.generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, '0', shaderStage );
|
|
285
616
|
|
|
286
617
|
} else {
|
|
287
618
|
|
|
@@ -293,6 +624,17 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
293
624
|
|
|
294
625
|
}
|
|
295
626
|
|
|
627
|
+
/**
|
|
628
|
+
* Generates the WGSL snippet for sampling/loading the given texture using explicit gradients.
|
|
629
|
+
*
|
|
630
|
+
* @param {Texture} texture - The texture.
|
|
631
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
632
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
633
|
+
* @param {Array<string>} gradSnippet - An array holding both gradient WGSL snippets.
|
|
634
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
635
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
636
|
+
* @return {string} The WGSL snippet.
|
|
637
|
+
*/
|
|
296
638
|
generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
297
639
|
|
|
298
640
|
if ( shaderStage === 'fragment' ) {
|
|
@@ -308,6 +650,18 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
308
650
|
|
|
309
651
|
}
|
|
310
652
|
|
|
653
|
+
/**
|
|
654
|
+
* Generates the WGSL snippet for sampling a depth texture and comparing the sampled depth values
|
|
655
|
+
* against a reference value.
|
|
656
|
+
*
|
|
657
|
+
* @param {Texture} texture - The texture.
|
|
658
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
659
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
660
|
+
* @param {string} compareSnippet - A WGSL snippet that represents the reference value.
|
|
661
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
662
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
663
|
+
* @return {string} The WGSL snippet.
|
|
664
|
+
*/
|
|
311
665
|
generateTextureCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
312
666
|
|
|
313
667
|
if ( shaderStage === 'fragment' ) {
|
|
@@ -322,6 +676,17 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
322
676
|
|
|
323
677
|
}
|
|
324
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Generates the WGSL snippet when sampling textures with explicit mip level.
|
|
681
|
+
*
|
|
682
|
+
* @param {Texture} texture - The texture.
|
|
683
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
684
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
685
|
+
* @param {string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
686
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
687
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
688
|
+
* @return {string} The WGSL snippet.
|
|
689
|
+
*/
|
|
325
690
|
generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
326
691
|
|
|
327
692
|
let snippet = null;
|
|
@@ -340,6 +705,17 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
340
705
|
|
|
341
706
|
}
|
|
342
707
|
|
|
708
|
+
/**
|
|
709
|
+
* Generates the WGSL snippet when sampling textures with a bias to the mip level.
|
|
710
|
+
*
|
|
711
|
+
* @param {Texture} texture - The texture.
|
|
712
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
713
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
714
|
+
* @param {string} biasSnippet - A WGSL snippet that represents the bias to apply to the mip level before sampling.
|
|
715
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
716
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
717
|
+
* @return {string} The WGSL snippet.
|
|
718
|
+
*/
|
|
343
719
|
generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet, shaderStage = this.shaderStage ) {
|
|
344
720
|
|
|
345
721
|
if ( shaderStage === 'fragment' ) {
|
|
@@ -354,6 +730,13 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
354
730
|
|
|
355
731
|
}
|
|
356
732
|
|
|
733
|
+
/**
|
|
734
|
+
* Returns a WGSL snippet that represents the property name of the given node.
|
|
735
|
+
*
|
|
736
|
+
* @param {Node} node - The node.
|
|
737
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
738
|
+
* @return {string} The property name.
|
|
739
|
+
*/
|
|
357
740
|
getPropertyName( node, shaderStage = this.shaderStage ) {
|
|
358
741
|
|
|
359
742
|
if ( node.isNodeVarying === true && node.needsInterpolation === true ) {
|
|
@@ -373,9 +756,15 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
373
756
|
|
|
374
757
|
return name;
|
|
375
758
|
|
|
376
|
-
} else if ( type === 'buffer' || type === 'storageBuffer' ) {
|
|
759
|
+
} else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
|
|
760
|
+
|
|
761
|
+
if ( this.isCustomStruct( node ) ) {
|
|
762
|
+
|
|
763
|
+
return name;
|
|
764
|
+
|
|
765
|
+
}
|
|
377
766
|
|
|
378
|
-
return
|
|
767
|
+
return name + '.value';
|
|
379
768
|
|
|
380
769
|
} else {
|
|
381
770
|
|
|
@@ -389,18 +778,23 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
389
778
|
|
|
390
779
|
}
|
|
391
780
|
|
|
781
|
+
/**
|
|
782
|
+
* Returns the output struct name.
|
|
783
|
+
*
|
|
784
|
+
* @return {string} The name of the output struct.
|
|
785
|
+
*/
|
|
392
786
|
getOutputStructName() {
|
|
393
787
|
|
|
394
788
|
return 'output';
|
|
395
789
|
|
|
396
790
|
}
|
|
397
791
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
792
|
+
/**
|
|
793
|
+
* Returns the native shader operator name for a given generic name.
|
|
794
|
+
*
|
|
795
|
+
* @param {string} op - The operator name to resolve.
|
|
796
|
+
* @return {?string} The resolved operator name.
|
|
797
|
+
*/
|
|
404
798
|
getFunctionOperator( op ) {
|
|
405
799
|
|
|
406
800
|
const fnOp = wgslFnOpLib[ op ];
|
|
@@ -417,49 +811,48 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
417
811
|
|
|
418
812
|
}
|
|
419
813
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
return 'read';
|
|
429
|
-
|
|
430
|
-
case GPUStorageTextureAccess.WriteOnly:
|
|
431
|
-
|
|
432
|
-
return 'write';
|
|
433
|
-
|
|
434
|
-
default:
|
|
435
|
-
|
|
436
|
-
return 'read_write';
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
} else {
|
|
441
|
-
|
|
442
|
-
switch ( node.access ) {
|
|
443
|
-
|
|
444
|
-
case GPUBufferBindingType.Storage:
|
|
814
|
+
/**
|
|
815
|
+
* Returns the node access for the given node and shader stage.
|
|
816
|
+
*
|
|
817
|
+
* @param {StorageTextureNode|StorageBufferNode} node - The storage node.
|
|
818
|
+
* @param {string} shaderStage - The shader stage.
|
|
819
|
+
* @return {string} The node access.
|
|
820
|
+
*/
|
|
821
|
+
getNodeAccess( node, shaderStage ) {
|
|
445
822
|
|
|
446
|
-
|
|
823
|
+
if ( shaderStage !== 'compute' )
|
|
824
|
+
return NodeAccess.READ_ONLY;
|
|
447
825
|
|
|
826
|
+
return node.access;
|
|
448
827
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
return 'read';
|
|
452
|
-
|
|
453
|
-
default:
|
|
828
|
+
}
|
|
454
829
|
|
|
455
|
-
|
|
830
|
+
/**
|
|
831
|
+
* Returns A WGSL snippet representing the storage access.
|
|
832
|
+
*
|
|
833
|
+
* @param {StorageTextureNode|StorageBufferNode} node - The storage node.
|
|
834
|
+
* @param {string} shaderStage - The shader stage.
|
|
835
|
+
* @return {string} The WGSL snippet representing the storage access.
|
|
836
|
+
*/
|
|
837
|
+
getStorageAccess( node, shaderStage ) {
|
|
456
838
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
839
|
+
return accessNames[ this.getNodeAccess( node, shaderStage ) ];
|
|
460
840
|
|
|
461
841
|
}
|
|
462
842
|
|
|
843
|
+
/**
|
|
844
|
+
* This method is one of the more important ones since it's responsible
|
|
845
|
+
* for generating a matching binding instance for the given uniform node.
|
|
846
|
+
*
|
|
847
|
+
* These bindings are later used in the renderer to create bind groups
|
|
848
|
+
* and layouts.
|
|
849
|
+
*
|
|
850
|
+
* @param {UniformNode} node - The uniform node.
|
|
851
|
+
* @param {string} type - The node data type.
|
|
852
|
+
* @param {string} shaderStage - The shader stage.
|
|
853
|
+
* @param {?string} [name=null] - An optional uniform name.
|
|
854
|
+
* @return {NodeUniform} The node uniform object.
|
|
855
|
+
*/
|
|
463
856
|
getUniformFromNode( node, type, shaderStage, name = null ) {
|
|
464
857
|
|
|
465
858
|
const uniformNode = super.getUniformFromNode( node, type, shaderStage, name );
|
|
@@ -478,26 +871,28 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
478
871
|
|
|
479
872
|
let texture = null;
|
|
480
873
|
|
|
874
|
+
const access = this.getNodeAccess( node, shaderStage );
|
|
875
|
+
|
|
481
876
|
if ( type === 'texture' || type === 'storageTexture' ) {
|
|
482
877
|
|
|
483
|
-
texture = new NodeSampledTexture( uniformNode.name, uniformNode.node, group,
|
|
878
|
+
texture = new NodeSampledTexture( uniformNode.name, uniformNode.node, group, access );
|
|
484
879
|
|
|
485
880
|
} else if ( type === 'cubeTexture' ) {
|
|
486
881
|
|
|
487
|
-
texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group,
|
|
882
|
+
texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group, access );
|
|
488
883
|
|
|
489
884
|
} else if ( type === 'texture3D' ) {
|
|
490
885
|
|
|
491
|
-
texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group,
|
|
886
|
+
texture = new NodeSampledTexture3D( uniformNode.name, uniformNode.node, group, access );
|
|
492
887
|
|
|
493
888
|
}
|
|
494
889
|
|
|
495
890
|
texture.store = node.isStorageTextureNode === true;
|
|
496
891
|
texture.setVisibility( gpuShaderStageLib[ shaderStage ] );
|
|
497
892
|
|
|
498
|
-
if ( shaderStage === 'fragment' && this.isUnfilterable( node.value ) === false && texture.store === false ) {
|
|
893
|
+
if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( node.value ) === false && texture.store === false ) {
|
|
499
894
|
|
|
500
|
-
const sampler = new NodeSampler( `${uniformNode.name}_sampler`, uniformNode.node, group );
|
|
895
|
+
const sampler = new NodeSampler( `${ uniformNode.name }_sampler`, uniformNode.node, group );
|
|
501
896
|
sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
|
|
502
897
|
|
|
503
898
|
bindings.push( sampler, texture );
|
|
@@ -512,9 +907,10 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
512
907
|
|
|
513
908
|
}
|
|
514
909
|
|
|
515
|
-
} else if ( type === 'buffer' || type === 'storageBuffer' ) {
|
|
910
|
+
} else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
|
|
911
|
+
|
|
912
|
+
const bufferClass = type === 'buffer' ? NodeUniformBuffer : NodeStorageBuffer;
|
|
516
913
|
|
|
517
|
-
const bufferClass = type === 'storageBuffer' ? NodeStorageBuffer : NodeUniformBuffer;
|
|
518
914
|
const buffer = new bufferClass( node, group );
|
|
519
915
|
buffer.setVisibility( gpuShaderStageLib[ shaderStage ] );
|
|
520
916
|
|
|
@@ -522,6 +918,8 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
522
918
|
|
|
523
919
|
uniformGPU = buffer;
|
|
524
920
|
|
|
921
|
+
uniformNode.name = name ? name : 'NodeBuffer_' + uniformNode.id;
|
|
922
|
+
|
|
525
923
|
} else {
|
|
526
924
|
|
|
527
925
|
const uniformsStage = this.uniformGroups[ shaderStage ] || ( this.uniformGroups[ shaderStage ] = {} );
|
|
@@ -553,6 +951,17 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
553
951
|
|
|
554
952
|
}
|
|
555
953
|
|
|
954
|
+
/**
|
|
955
|
+
* This method should be used whenever builtins are required in nodes.
|
|
956
|
+
* The internal builtins data structure will make sure builtins are
|
|
957
|
+
* defined in the WGSL source.
|
|
958
|
+
*
|
|
959
|
+
* @param {string} name - The builtin name.
|
|
960
|
+
* @param {string} property - The property name.
|
|
961
|
+
* @param {string} type - The node data type.
|
|
962
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
963
|
+
* @return {string} The property name.
|
|
964
|
+
*/
|
|
556
965
|
getBuiltin( name, property, type, shaderStage = this.shaderStage ) {
|
|
557
966
|
|
|
558
967
|
const map = this.builtins[ shaderStage ] || ( this.builtins[ shaderStage ] = new Map() );
|
|
@@ -571,6 +980,24 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
571
980
|
|
|
572
981
|
}
|
|
573
982
|
|
|
983
|
+
/**
|
|
984
|
+
* Returns `true` if the given builtin is defined in the given shader stage.
|
|
985
|
+
*
|
|
986
|
+
* @param {string} name - The builtin name.
|
|
987
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage this code snippet is generated for.
|
|
988
|
+
* @return {boolean} Whether the given builtin is defined in the given shader stage or not.
|
|
989
|
+
*/
|
|
990
|
+
hasBuiltin( name, shaderStage = this.shaderStage ) {
|
|
991
|
+
|
|
992
|
+
return ( this.builtins[ shaderStage ] !== undefined && this.builtins[ shaderStage ].has( name ) );
|
|
993
|
+
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Returns the vertex index builtin.
|
|
998
|
+
*
|
|
999
|
+
* @return {string} The vertex index.
|
|
1000
|
+
*/
|
|
574
1001
|
getVertexIndex() {
|
|
575
1002
|
|
|
576
1003
|
if ( this.shaderStage === 'vertex' ) {
|
|
@@ -583,6 +1010,12 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
583
1010
|
|
|
584
1011
|
}
|
|
585
1012
|
|
|
1013
|
+
/**
|
|
1014
|
+
* Builds the given shader node.
|
|
1015
|
+
*
|
|
1016
|
+
* @param {ShaderNodeInternal} shaderNode - The shader node.
|
|
1017
|
+
* @return {string} The WGSL function code.
|
|
1018
|
+
*/
|
|
586
1019
|
buildFunctionCode( shaderNode ) {
|
|
587
1020
|
|
|
588
1021
|
const layout = shaderNode.layout;
|
|
@@ -598,12 +1031,18 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
598
1031
|
|
|
599
1032
|
//
|
|
600
1033
|
|
|
601
|
-
|
|
1034
|
+
let code = `fn ${ layout.name }( ${ parameters.join( ', ' ) } ) -> ${ this.getType( layout.type ) } {
|
|
602
1035
|
${ flowData.vars }
|
|
603
1036
|
${ flowData.code }
|
|
604
|
-
|
|
1037
|
+
`;
|
|
1038
|
+
|
|
1039
|
+
if ( flowData.result ) {
|
|
605
1040
|
|
|
606
|
-
}`;
|
|
1041
|
+
code += `\treturn ${ flowData.result };\n`;
|
|
1042
|
+
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
code += '\n}\n';
|
|
607
1046
|
|
|
608
1047
|
//
|
|
609
1048
|
|
|
@@ -611,6 +1050,11 @@ ${ flowData.code }
|
|
|
611
1050
|
|
|
612
1051
|
}
|
|
613
1052
|
|
|
1053
|
+
/**
|
|
1054
|
+
* Returns the instance index builtin.
|
|
1055
|
+
*
|
|
1056
|
+
* @return {string} The instance index.
|
|
1057
|
+
*/
|
|
614
1058
|
getInstanceIndex() {
|
|
615
1059
|
|
|
616
1060
|
if ( this.shaderStage === 'vertex' ) {
|
|
@@ -623,6 +1067,22 @@ ${ flowData.code }
|
|
|
623
1067
|
|
|
624
1068
|
}
|
|
625
1069
|
|
|
1070
|
+
/**
|
|
1071
|
+
* Returns the invocation local index builtin.
|
|
1072
|
+
*
|
|
1073
|
+
* @return {string} The invocation local index.
|
|
1074
|
+
*/
|
|
1075
|
+
getInvocationLocalIndex() {
|
|
1076
|
+
|
|
1077
|
+
return this.getBuiltin( 'local_invocation_index', 'invocationLocalIndex', 'u32', 'attribute' );
|
|
1078
|
+
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Returns the subgroup size builtin.
|
|
1083
|
+
*
|
|
1084
|
+
* @return {string} The subgroup size.
|
|
1085
|
+
*/
|
|
626
1086
|
getSubgroupSize() {
|
|
627
1087
|
|
|
628
1088
|
this.enableSubGroups();
|
|
@@ -631,44 +1091,104 @@ ${ flowData.code }
|
|
|
631
1091
|
|
|
632
1092
|
}
|
|
633
1093
|
|
|
1094
|
+
/**
|
|
1095
|
+
* Returns the invocation subgroup index builtin.
|
|
1096
|
+
*
|
|
1097
|
+
* @return {string} The invocation subgroup index.
|
|
1098
|
+
*/
|
|
1099
|
+
getInvocationSubgroupIndex() {
|
|
1100
|
+
|
|
1101
|
+
this.enableSubGroups();
|
|
1102
|
+
|
|
1103
|
+
return this.getBuiltin( 'subgroup_invocation_id', 'invocationSubgroupIndex', 'u32', 'attribute' );
|
|
1104
|
+
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Returns the subgroup index builtin.
|
|
1109
|
+
*
|
|
1110
|
+
* @return {string} The subgroup index.
|
|
1111
|
+
*/
|
|
634
1112
|
getSubgroupIndex() {
|
|
635
1113
|
|
|
636
1114
|
this.enableSubGroups();
|
|
637
1115
|
|
|
638
|
-
return this.getBuiltin( '
|
|
1116
|
+
return this.getBuiltin( 'subgroup_id', 'subgroupIndex', 'u32', 'attribute' );
|
|
639
1117
|
|
|
640
1118
|
}
|
|
641
1119
|
|
|
1120
|
+
/**
|
|
1121
|
+
* Overwritten as a NOP since this method is intended for the WebGL 2 backend.
|
|
1122
|
+
*
|
|
1123
|
+
* @return {null} Null.
|
|
1124
|
+
*/
|
|
642
1125
|
getDrawIndex() {
|
|
643
1126
|
|
|
644
1127
|
return null;
|
|
645
1128
|
|
|
646
1129
|
}
|
|
647
1130
|
|
|
1131
|
+
/**
|
|
1132
|
+
* Returns the front facing builtin.
|
|
1133
|
+
*
|
|
1134
|
+
* @return {string} The front facing builtin.
|
|
1135
|
+
*/
|
|
648
1136
|
getFrontFacing() {
|
|
649
1137
|
|
|
650
1138
|
return this.getBuiltin( 'front_facing', 'isFront', 'bool' );
|
|
651
1139
|
|
|
652
1140
|
}
|
|
653
1141
|
|
|
1142
|
+
/**
|
|
1143
|
+
* Returns the frag coord builtin.
|
|
1144
|
+
*
|
|
1145
|
+
* @return {string} The frag coord builtin.
|
|
1146
|
+
*/
|
|
654
1147
|
getFragCoord() {
|
|
655
1148
|
|
|
656
|
-
return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.
|
|
1149
|
+
return this.getBuiltin( 'position', 'fragCoord', 'vec4<f32>' ) + '.xy';
|
|
657
1150
|
|
|
658
1151
|
}
|
|
659
1152
|
|
|
1153
|
+
/**
|
|
1154
|
+
* Returns the frag depth builtin.
|
|
1155
|
+
*
|
|
1156
|
+
* @return {string} The frag depth builtin.
|
|
1157
|
+
*/
|
|
660
1158
|
getFragDepth() {
|
|
661
1159
|
|
|
662
1160
|
return 'output.' + this.getBuiltin( 'frag_depth', 'depth', 'f32', 'output' );
|
|
663
1161
|
|
|
664
1162
|
}
|
|
665
1163
|
|
|
1164
|
+
/**
|
|
1165
|
+
* Returns the clip distances builtin.
|
|
1166
|
+
*
|
|
1167
|
+
* @return {string} The clip distances builtin.
|
|
1168
|
+
*/
|
|
1169
|
+
getClipDistance() {
|
|
1170
|
+
|
|
1171
|
+
return 'varyings.hw_clip_distances';
|
|
1172
|
+
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* Whether to flip texture data along its vertical axis or not.
|
|
1177
|
+
*
|
|
1178
|
+
* @return {boolean} Returns always `false` in context of WGSL.
|
|
1179
|
+
*/
|
|
666
1180
|
isFlipY() {
|
|
667
1181
|
|
|
668
1182
|
return false;
|
|
669
1183
|
|
|
670
1184
|
}
|
|
671
1185
|
|
|
1186
|
+
/**
|
|
1187
|
+
* Enables the given directive for the given shader stage.
|
|
1188
|
+
*
|
|
1189
|
+
* @param {string} name - The directive name.
|
|
1190
|
+
* @param {string} [shaderStage=this.shaderStage] - The shader stage to enable the directive for.
|
|
1191
|
+
*/
|
|
672
1192
|
enableDirective( name, shaderStage = this.shaderStage ) {
|
|
673
1193
|
|
|
674
1194
|
const stage = this.directives[ shaderStage ] || ( this.directives[ shaderStage ] = new Set() );
|
|
@@ -676,6 +1196,12 @@ ${ flowData.code }
|
|
|
676
1196
|
|
|
677
1197
|
}
|
|
678
1198
|
|
|
1199
|
+
/**
|
|
1200
|
+
* Returns the directives of the given shader stage as a WGSL string.
|
|
1201
|
+
*
|
|
1202
|
+
* @param {string} shaderStage - The shader stage.
|
|
1203
|
+
* @return {string} A WGSL snippet that enables the directives of the given stage.
|
|
1204
|
+
*/
|
|
679
1205
|
getDirectives( shaderStage ) {
|
|
680
1206
|
|
|
681
1207
|
const snippets = [];
|
|
@@ -695,36 +1221,69 @@ ${ flowData.code }
|
|
|
695
1221
|
|
|
696
1222
|
}
|
|
697
1223
|
|
|
1224
|
+
/**
|
|
1225
|
+
* Enables the 'subgroups' directive.
|
|
1226
|
+
*/
|
|
698
1227
|
enableSubGroups() {
|
|
699
1228
|
|
|
700
1229
|
this.enableDirective( 'subgroups' );
|
|
701
1230
|
|
|
702
1231
|
}
|
|
703
1232
|
|
|
1233
|
+
/**
|
|
1234
|
+
* Enables the 'subgroups-f16' directive.
|
|
1235
|
+
*/
|
|
704
1236
|
enableSubgroupsF16() {
|
|
705
1237
|
|
|
706
1238
|
this.enableDirective( 'subgroups-f16' );
|
|
707
1239
|
|
|
708
1240
|
}
|
|
709
1241
|
|
|
1242
|
+
/**
|
|
1243
|
+
* Enables the 'clip_distances' directive.
|
|
1244
|
+
*/
|
|
710
1245
|
enableClipDistances() {
|
|
711
1246
|
|
|
712
1247
|
this.enableDirective( 'clip_distances' );
|
|
713
1248
|
|
|
714
1249
|
}
|
|
715
1250
|
|
|
1251
|
+
/**
|
|
1252
|
+
* Enables the 'f16' directive.
|
|
1253
|
+
*/
|
|
716
1254
|
enableShaderF16() {
|
|
717
1255
|
|
|
718
1256
|
this.enableDirective( 'f16' );
|
|
719
1257
|
|
|
720
1258
|
}
|
|
721
1259
|
|
|
1260
|
+
/**
|
|
1261
|
+
* Enables the 'dual_source_blending' directive.
|
|
1262
|
+
*/
|
|
722
1263
|
enableDualSourceBlending() {
|
|
723
1264
|
|
|
724
1265
|
this.enableDirective( 'dual_source_blending' );
|
|
725
1266
|
|
|
726
1267
|
}
|
|
727
1268
|
|
|
1269
|
+
/**
|
|
1270
|
+
* Enables hardware clipping.
|
|
1271
|
+
*
|
|
1272
|
+
* @param {string} planeCount - The clipping plane count.
|
|
1273
|
+
*/
|
|
1274
|
+
enableHardwareClipping( planeCount ) {
|
|
1275
|
+
|
|
1276
|
+
this.enableClipDistances();
|
|
1277
|
+
this.getBuiltin( 'clip_distances', 'hw_clip_distances', `array<f32, ${ planeCount } >`, 'vertex' );
|
|
1278
|
+
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Returns the builtins of the given shader stage as a WGSL string.
|
|
1283
|
+
*
|
|
1284
|
+
* @param {string} shaderStage - The shader stage.
|
|
1285
|
+
* @return {string} A WGSL snippet that represents the builtins of the given stage.
|
|
1286
|
+
*/
|
|
728
1287
|
getBuiltins( shaderStage ) {
|
|
729
1288
|
|
|
730
1289
|
const snippets = [];
|
|
@@ -744,17 +1303,87 @@ ${ flowData.code }
|
|
|
744
1303
|
|
|
745
1304
|
}
|
|
746
1305
|
|
|
1306
|
+
/**
|
|
1307
|
+
* This method should be used when a new scoped buffer is used in context of
|
|
1308
|
+
* compute shaders. It adds the array to the internal data structure which is
|
|
1309
|
+
* later used to generate the respective WGSL.
|
|
1310
|
+
*
|
|
1311
|
+
* @param {string} name - The array name.
|
|
1312
|
+
* @param {string} scope - The scope.
|
|
1313
|
+
* @param {string} bufferType - The buffer type.
|
|
1314
|
+
* @param {string} bufferCount - The buffer count.
|
|
1315
|
+
* @return {string} The array name.
|
|
1316
|
+
*/
|
|
1317
|
+
getScopedArray( name, scope, bufferType, bufferCount ) {
|
|
1318
|
+
|
|
1319
|
+
if ( this.scopedArrays.has( name ) === false ) {
|
|
1320
|
+
|
|
1321
|
+
this.scopedArrays.set( name, {
|
|
1322
|
+
name,
|
|
1323
|
+
scope,
|
|
1324
|
+
bufferType,
|
|
1325
|
+
bufferCount
|
|
1326
|
+
} );
|
|
1327
|
+
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
return name;
|
|
1331
|
+
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
/**
|
|
1335
|
+
* Returns the scoped arrays of the given shader stage as a WGSL string.
|
|
1336
|
+
*
|
|
1337
|
+
* @param {string} shaderStage - The shader stage.
|
|
1338
|
+
* @return {string|undefined} The WGSL snippet that defines the scoped arrays.
|
|
1339
|
+
* Returns `undefined` when used in the vertex or fragment stage.
|
|
1340
|
+
*/
|
|
1341
|
+
getScopedArrays( shaderStage ) {
|
|
1342
|
+
|
|
1343
|
+
if ( shaderStage !== 'compute' ) {
|
|
1344
|
+
|
|
1345
|
+
return;
|
|
1346
|
+
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
const snippets = [];
|
|
1350
|
+
|
|
1351
|
+
for ( const { name, scope, bufferType, bufferCount } of this.scopedArrays.values() ) {
|
|
1352
|
+
|
|
1353
|
+
const type = this.getType( bufferType );
|
|
1354
|
+
|
|
1355
|
+
snippets.push( `var<${scope}> ${name}: array< ${type}, ${bufferCount} >;` );
|
|
1356
|
+
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
return snippets.join( '\n' );
|
|
1360
|
+
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* Returns the shader attributes of the given shader stage as a WGSL string.
|
|
1365
|
+
*
|
|
1366
|
+
* @param {string} shaderStage - The shader stage.
|
|
1367
|
+
* @return {string} The WGSL snippet that defines the shader attributes.
|
|
1368
|
+
*/
|
|
747
1369
|
getAttributes( shaderStage ) {
|
|
748
1370
|
|
|
749
1371
|
const snippets = [];
|
|
750
1372
|
|
|
751
1373
|
if ( shaderStage === 'compute' ) {
|
|
752
1374
|
|
|
753
|
-
this.getBuiltin( 'global_invocation_id', '
|
|
1375
|
+
this.getBuiltin( 'global_invocation_id', 'globalId', 'vec3<u32>', 'attribute' );
|
|
754
1376
|
this.getBuiltin( 'workgroup_id', 'workgroupId', 'vec3<u32>', 'attribute' );
|
|
755
1377
|
this.getBuiltin( 'local_invocation_id', 'localId', 'vec3<u32>', 'attribute' );
|
|
756
1378
|
this.getBuiltin( 'num_workgroups', 'numWorkgroups', 'vec3<u32>', 'attribute' );
|
|
757
1379
|
|
|
1380
|
+
if ( this.renderer.hasFeature( 'subgroups' ) ) {
|
|
1381
|
+
|
|
1382
|
+
this.enableDirective( 'subgroups', shaderStage );
|
|
1383
|
+
this.getBuiltin( 'subgroup_size', 'subgroupSize', 'u32', 'attribute' );
|
|
1384
|
+
|
|
1385
|
+
}
|
|
1386
|
+
|
|
758
1387
|
}
|
|
759
1388
|
|
|
760
1389
|
if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
|
|
@@ -781,57 +1410,108 @@ ${ flowData.code }
|
|
|
781
1410
|
|
|
782
1411
|
}
|
|
783
1412
|
|
|
1413
|
+
/**
|
|
1414
|
+
* Returns the members of the given struct type node as a WGSL string.
|
|
1415
|
+
*
|
|
1416
|
+
* @param {StructTypeNode} struct - The struct type node.
|
|
1417
|
+
* @return {string} The WGSL snippet that defines the struct members.
|
|
1418
|
+
*/
|
|
784
1419
|
getStructMembers( struct ) {
|
|
785
1420
|
|
|
786
1421
|
const snippets = [];
|
|
787
|
-
const members = struct.getMemberTypes();
|
|
788
1422
|
|
|
789
|
-
for (
|
|
1423
|
+
for ( const member of struct.members ) {
|
|
790
1424
|
|
|
791
|
-
const
|
|
792
|
-
|
|
1425
|
+
const prefix = struct.output ? '@location( ' + member.index + ' ) ' : '';
|
|
1426
|
+
|
|
1427
|
+
let type = this.getType( member.type );
|
|
1428
|
+
|
|
1429
|
+
if ( member.atomic ) {
|
|
1430
|
+
|
|
1431
|
+
type = 'atomic< ' + type + ' >';
|
|
1432
|
+
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
snippets.push( `\t${ prefix + member.name } : ${ type }` );
|
|
793
1436
|
|
|
794
1437
|
}
|
|
795
1438
|
|
|
796
|
-
|
|
1439
|
+
if ( struct.output ) {
|
|
797
1440
|
|
|
798
|
-
|
|
1441
|
+
snippets.push( `\t${ this.getBuiltins( 'output' ) }` );
|
|
1442
|
+
|
|
1443
|
+
}
|
|
799
1444
|
|
|
800
1445
|
return snippets.join( ',\n' );
|
|
801
1446
|
|
|
802
1447
|
}
|
|
803
1448
|
|
|
1449
|
+
/**
|
|
1450
|
+
* Returns the structs of the given shader stage as a WGSL string.
|
|
1451
|
+
*
|
|
1452
|
+
* @param {string} shaderStage - The shader stage.
|
|
1453
|
+
* @return {string} The WGSL snippet that defines the structs.
|
|
1454
|
+
*/
|
|
804
1455
|
getStructs( shaderStage ) {
|
|
805
1456
|
|
|
806
|
-
|
|
1457
|
+
let result = '';
|
|
1458
|
+
|
|
807
1459
|
const structs = this.structs[ shaderStage ];
|
|
808
1460
|
|
|
809
|
-
|
|
1461
|
+
if ( structs.length > 0 ) {
|
|
810
1462
|
|
|
811
|
-
const
|
|
812
|
-
const name = struct.name;
|
|
1463
|
+
const snippets = [];
|
|
813
1464
|
|
|
814
|
-
|
|
815
|
-
snippet += this.getStructMembers( struct );
|
|
816
|
-
snippet += '\n}';
|
|
1465
|
+
for ( const struct of structs ) {
|
|
817
1466
|
|
|
1467
|
+
let snippet = `struct ${ struct.name } {\n`;
|
|
1468
|
+
snippet += this.getStructMembers( struct );
|
|
1469
|
+
snippet += '\n};';
|
|
818
1470
|
|
|
819
|
-
|
|
1471
|
+
snippets.push( snippet );
|
|
820
1472
|
|
|
821
|
-
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
result = '\n' + snippets.join( '\n\n' ) + '\n';
|
|
822
1476
|
|
|
823
1477
|
}
|
|
824
1478
|
|
|
825
|
-
return
|
|
1479
|
+
return result;
|
|
826
1480
|
|
|
827
1481
|
}
|
|
828
1482
|
|
|
829
|
-
|
|
1483
|
+
/**
|
|
1484
|
+
* Returns a WGSL string representing a variable.
|
|
1485
|
+
*
|
|
1486
|
+
* @param {string} type - The variable's type.
|
|
1487
|
+
* @param {string} name - The variable's name.
|
|
1488
|
+
* @param {?number} [count=null] - The array length.
|
|
1489
|
+
* @return {string} The WGSL snippet that defines a variable.
|
|
1490
|
+
*/
|
|
1491
|
+
getVar( type, name, count = null ) {
|
|
1492
|
+
|
|
1493
|
+
let snippet = `var ${ name } : `;
|
|
1494
|
+
|
|
1495
|
+
if ( count !== null ) {
|
|
1496
|
+
|
|
1497
|
+
snippet += this.generateArrayDeclaration( type, count );
|
|
1498
|
+
|
|
1499
|
+
} else {
|
|
1500
|
+
|
|
1501
|
+
snippet += this.getType( type );
|
|
1502
|
+
|
|
1503
|
+
}
|
|
830
1504
|
|
|
831
|
-
return
|
|
1505
|
+
return snippet;
|
|
832
1506
|
|
|
833
1507
|
}
|
|
834
1508
|
|
|
1509
|
+
/**
|
|
1510
|
+
* Returns the variables of the given shader stage as a WGSL string.
|
|
1511
|
+
*
|
|
1512
|
+
* @param {string} shaderStage - The shader stage.
|
|
1513
|
+
* @return {string} The WGSL snippet that defines the variables.
|
|
1514
|
+
*/
|
|
835
1515
|
getVars( shaderStage ) {
|
|
836
1516
|
|
|
837
1517
|
const snippets = [];
|
|
@@ -841,7 +1521,7 @@ ${ flowData.code }
|
|
|
841
1521
|
|
|
842
1522
|
for ( const variable of vars ) {
|
|
843
1523
|
|
|
844
|
-
snippets.push( `\t${ this.getVar( variable.type, variable.name ) };` );
|
|
1524
|
+
snippets.push( `\t${ this.getVar( variable.type, variable.name, variable.count ) };` );
|
|
845
1525
|
|
|
846
1526
|
}
|
|
847
1527
|
|
|
@@ -851,6 +1531,12 @@ ${ flowData.code }
|
|
|
851
1531
|
|
|
852
1532
|
}
|
|
853
1533
|
|
|
1534
|
+
/**
|
|
1535
|
+
* Returns the varyings of the given shader stage as a WGSL string.
|
|
1536
|
+
*
|
|
1537
|
+
* @param {string} shaderStage - The shader stage.
|
|
1538
|
+
* @return {string} The WGSL snippet that defines the varyings.
|
|
1539
|
+
*/
|
|
854
1540
|
getVaryings( shaderStage ) {
|
|
855
1541
|
|
|
856
1542
|
const snippets = [];
|
|
@@ -903,6 +1589,18 @@ ${ flowData.code }
|
|
|
903
1589
|
|
|
904
1590
|
}
|
|
905
1591
|
|
|
1592
|
+
isCustomStruct( nodeUniform ) {
|
|
1593
|
+
|
|
1594
|
+
return nodeUniform.value.isStorageBufferAttribute && nodeUniform.node.structTypeNode !== null;
|
|
1595
|
+
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
/**
|
|
1599
|
+
* Returns the uniforms of the given shader stage as a WGSL string.
|
|
1600
|
+
*
|
|
1601
|
+
* @param {string} shaderStage - The shader stage.
|
|
1602
|
+
* @return {string} The WGSL snippet that defines the uniforms.
|
|
1603
|
+
*/
|
|
906
1604
|
getUniforms( shaderStage ) {
|
|
907
1605
|
|
|
908
1606
|
const uniforms = this.uniforms[ shaderStage ];
|
|
@@ -914,16 +1612,16 @@ ${ flowData.code }
|
|
|
914
1612
|
|
|
915
1613
|
for ( const uniform of uniforms ) {
|
|
916
1614
|
|
|
917
|
-
const
|
|
918
|
-
const uniformIndexes = this.bindingsIndexes[
|
|
1615
|
+
const groupName = uniform.groupNode.name;
|
|
1616
|
+
const uniformIndexes = this.bindingsIndexes[ groupName ];
|
|
919
1617
|
|
|
920
1618
|
if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
|
|
921
1619
|
|
|
922
1620
|
const texture = uniform.node.value;
|
|
923
1621
|
|
|
924
|
-
if ( shaderStage === 'fragment' && this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true ) {
|
|
1622
|
+
if ( ( shaderStage === 'fragment' || shaderStage === 'compute' ) && this.isUnfilterable( texture ) === false && uniform.node.isStorageTextureNode !== true ) {
|
|
925
1623
|
|
|
926
|
-
if (
|
|
1624
|
+
if ( this.isSampleCompare( texture ) ) {
|
|
927
1625
|
|
|
928
1626
|
bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler_comparison;` );
|
|
929
1627
|
|
|
@@ -939,7 +1637,9 @@ ${ flowData.code }
|
|
|
939
1637
|
|
|
940
1638
|
let multisampled = '';
|
|
941
1639
|
|
|
942
|
-
|
|
1640
|
+
const { primarySamples } = this.renderer.backend.utils.getTextureSampleData( texture );
|
|
1641
|
+
|
|
1642
|
+
if ( primarySamples > 1 ) {
|
|
943
1643
|
|
|
944
1644
|
multisampled = '_multisampled';
|
|
945
1645
|
|
|
@@ -949,7 +1649,7 @@ ${ flowData.code }
|
|
|
949
1649
|
|
|
950
1650
|
textureType = 'texture_cube<f32>';
|
|
951
1651
|
|
|
952
|
-
} else if ( texture.isDataArrayTexture === true ) {
|
|
1652
|
+
} else if ( texture.isDataArrayTexture === true || texture.isCompressedArrayTexture === true ) {
|
|
953
1653
|
|
|
954
1654
|
textureType = 'texture_2d_array<f32>';
|
|
955
1655
|
|
|
@@ -968,7 +1668,7 @@ ${ flowData.code }
|
|
|
968
1668
|
} else if ( uniform.node.isStorageTextureNode === true ) {
|
|
969
1669
|
|
|
970
1670
|
const format = getFormat( texture );
|
|
971
|
-
const access = this.getStorageAccess( uniform.node );
|
|
1671
|
+
const access = this.getStorageAccess( uniform.node, shaderStage );
|
|
972
1672
|
|
|
973
1673
|
textureType = `texture_storage_2d<${ format }, ${ access }>`;
|
|
974
1674
|
|
|
@@ -976,23 +1676,32 @@ ${ flowData.code }
|
|
|
976
1676
|
|
|
977
1677
|
const componentPrefix = this.getComponentTypeFromTexture( texture ).charAt( 0 );
|
|
978
1678
|
|
|
979
|
-
textureType = `texture${multisampled}_2d<${ componentPrefix }32>`;
|
|
1679
|
+
textureType = `texture${ multisampled }_2d<${ componentPrefix }32>`;
|
|
980
1680
|
|
|
981
1681
|
}
|
|
982
1682
|
|
|
983
1683
|
bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name } : ${ textureType };` );
|
|
984
1684
|
|
|
985
|
-
} else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' ) {
|
|
1685
|
+
} else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' || uniform.type === 'indirectStorageBuffer' ) {
|
|
986
1686
|
|
|
987
1687
|
const bufferNode = uniform.node;
|
|
988
|
-
const bufferType = this.getType( bufferNode.
|
|
1688
|
+
const bufferType = this.getType( bufferNode.getNodeType( this ) );
|
|
989
1689
|
const bufferCount = bufferNode.bufferCount;
|
|
1690
|
+
const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : '';
|
|
1691
|
+
const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode, shaderStage ) }` : 'uniform';
|
|
990
1692
|
|
|
991
|
-
|
|
992
|
-
const bufferSnippet = `\t${ uniform.name } : array< ${ bufferType }${ bufferCountSnippet } >\n`;
|
|
993
|
-
const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform';
|
|
1693
|
+
if ( this.isCustomStruct( uniform ) ) {
|
|
994
1694
|
|
|
995
|
-
|
|
1695
|
+
bufferSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var<${ bufferAccessMode }> ${ uniform.name } : ${ bufferType };` );
|
|
1696
|
+
|
|
1697
|
+
} else {
|
|
1698
|
+
|
|
1699
|
+
const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${ bufferType }>` : `${ bufferType }`;
|
|
1700
|
+
const bufferSnippet = `\tvalue : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >`;
|
|
1701
|
+
|
|
1702
|
+
bufferSnippets.push( this._getWGSLStructBinding( uniform.name, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) );
|
|
1703
|
+
|
|
1704
|
+
}
|
|
996
1705
|
|
|
997
1706
|
} else {
|
|
998
1707
|
|
|
@@ -1027,12 +1736,19 @@ ${ flowData.code }
|
|
|
1027
1736
|
|
|
1028
1737
|
}
|
|
1029
1738
|
|
|
1739
|
+
/**
|
|
1740
|
+
* Controls the code build of the shader stages.
|
|
1741
|
+
*/
|
|
1030
1742
|
buildCode() {
|
|
1031
1743
|
|
|
1032
1744
|
const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
|
|
1033
1745
|
|
|
1746
|
+
this.sortBindingGroups();
|
|
1747
|
+
|
|
1034
1748
|
for ( const shaderStage in shadersData ) {
|
|
1035
1749
|
|
|
1750
|
+
this.shaderStage = shaderStage;
|
|
1751
|
+
|
|
1036
1752
|
const stageData = shadersData[ shaderStage ];
|
|
1037
1753
|
stageData.uniforms = this.getUniforms( shaderStage );
|
|
1038
1754
|
stageData.attributes = this.getAttributes( shaderStage );
|
|
@@ -1041,6 +1757,7 @@ ${ flowData.code }
|
|
|
1041
1757
|
stageData.vars = this.getVars( shaderStage );
|
|
1042
1758
|
stageData.codes = this.getCodes( shaderStage );
|
|
1043
1759
|
stageData.directives = this.getDirectives( shaderStage );
|
|
1760
|
+
stageData.scopedArrays = this.getScopedArrays( shaderStage );
|
|
1044
1761
|
|
|
1045
1762
|
//
|
|
1046
1763
|
|
|
@@ -1062,7 +1779,7 @@ ${ flowData.code }
|
|
|
1062
1779
|
|
|
1063
1780
|
if ( flow.length > 0 ) flow += '\n';
|
|
1064
1781
|
|
|
1065
|
-
flow += `\t// flow -> ${ slotName }\n
|
|
1782
|
+
flow += `\t// flow -> ${ slotName }\n`;
|
|
1066
1783
|
|
|
1067
1784
|
}
|
|
1068
1785
|
|
|
@@ -1080,7 +1797,8 @@ ${ flowData.code }
|
|
|
1080
1797
|
|
|
1081
1798
|
if ( isOutputStruct ) {
|
|
1082
1799
|
|
|
1083
|
-
stageData.returnType = outputNode.
|
|
1800
|
+
stageData.returnType = outputNode.getNodeType( this );
|
|
1801
|
+
stageData.structs += 'var<private> output : ' + stageData.returnType + ';';
|
|
1084
1802
|
|
|
1085
1803
|
flow += `return ${ flowSlotData.result };`;
|
|
1086
1804
|
|
|
@@ -1094,7 +1812,7 @@ ${ flowData.code }
|
|
|
1094
1812
|
|
|
1095
1813
|
stageData.returnType = 'OutputStruct';
|
|
1096
1814
|
stageData.structs += this._getWGSLStruct( 'OutputStruct', structSnippet );
|
|
1097
|
-
stageData.structs += '\nvar<private> output : OutputStruct
|
|
1815
|
+
stageData.structs += '\nvar<private> output : OutputStruct;';
|
|
1098
1816
|
|
|
1099
1817
|
flow += `output.color = ${ flowSlotData.result };\n\n\treturn output;`;
|
|
1100
1818
|
|
|
@@ -1108,9 +1826,10 @@ ${ flowData.code }
|
|
|
1108
1826
|
|
|
1109
1827
|
stageData.flow = flow;
|
|
1110
1828
|
|
|
1111
|
-
|
|
1112
1829
|
}
|
|
1113
1830
|
|
|
1831
|
+
this.shaderStage = null;
|
|
1832
|
+
|
|
1114
1833
|
if ( this.material !== null ) {
|
|
1115
1834
|
|
|
1116
1835
|
this.vertexShader = this._getWGSLVertexCode( shadersData.vertex );
|
|
@@ -1124,6 +1843,13 @@ ${ flowData.code }
|
|
|
1124
1843
|
|
|
1125
1844
|
}
|
|
1126
1845
|
|
|
1846
|
+
/**
|
|
1847
|
+
* Returns the native shader method name for a given generic name.
|
|
1848
|
+
*
|
|
1849
|
+
* @param {string} method - The method name to resolve.
|
|
1850
|
+
* @param {?string} [output=null] - An optional output.
|
|
1851
|
+
* @return {string} The resolved WGSL method name.
|
|
1852
|
+
*/
|
|
1127
1853
|
getMethod( method, output = null ) {
|
|
1128
1854
|
|
|
1129
1855
|
let wgslMethod;
|
|
@@ -1144,12 +1870,24 @@ ${ flowData.code }
|
|
|
1144
1870
|
|
|
1145
1871
|
}
|
|
1146
1872
|
|
|
1873
|
+
/**
|
|
1874
|
+
* Returns the WGSL type of the given node data type.
|
|
1875
|
+
*
|
|
1876
|
+
* @param {string} type - The node data type.
|
|
1877
|
+
* @return {string} The WGSL type.
|
|
1878
|
+
*/
|
|
1147
1879
|
getType( type ) {
|
|
1148
1880
|
|
|
1149
1881
|
return wgslTypeLib[ type ] || type;
|
|
1150
1882
|
|
|
1151
1883
|
}
|
|
1152
1884
|
|
|
1885
|
+
/**
|
|
1886
|
+
* Whether the requested feature is available or not.
|
|
1887
|
+
*
|
|
1888
|
+
* @param {string} name - The requested feature.
|
|
1889
|
+
* @return {boolean} Whether the requested feature is supported or not.
|
|
1890
|
+
*/
|
|
1153
1891
|
isAvailable( name ) {
|
|
1154
1892
|
|
|
1155
1893
|
let result = supports[ name ];
|
|
@@ -1160,6 +1898,10 @@ ${ flowData.code }
|
|
|
1160
1898
|
|
|
1161
1899
|
result = this.renderer.hasFeature( 'float32-filterable' );
|
|
1162
1900
|
|
|
1901
|
+
} else if ( name === 'clipDistance' ) {
|
|
1902
|
+
|
|
1903
|
+
result = this.renderer.hasFeature( 'clip-distances' );
|
|
1904
|
+
|
|
1163
1905
|
}
|
|
1164
1906
|
|
|
1165
1907
|
supports[ name ] = result;
|
|
@@ -1170,6 +1912,13 @@ ${ flowData.code }
|
|
|
1170
1912
|
|
|
1171
1913
|
}
|
|
1172
1914
|
|
|
1915
|
+
/**
|
|
1916
|
+
* Returns the native shader method name for a given generic name.
|
|
1917
|
+
*
|
|
1918
|
+
* @private
|
|
1919
|
+
* @param {string} method - The method name to resolve.
|
|
1920
|
+
* @return {string} The resolved WGSL method name.
|
|
1921
|
+
*/
|
|
1173
1922
|
_getWGSLMethod( method ) {
|
|
1174
1923
|
|
|
1175
1924
|
if ( wgslPolyfill[ method ] !== undefined ) {
|
|
@@ -1182,6 +1931,14 @@ ${ flowData.code }
|
|
|
1182
1931
|
|
|
1183
1932
|
}
|
|
1184
1933
|
|
|
1934
|
+
/**
|
|
1935
|
+
* Includes the given method name into the current
|
|
1936
|
+
* function node.
|
|
1937
|
+
*
|
|
1938
|
+
* @private
|
|
1939
|
+
* @param {string} name - The method name to include.
|
|
1940
|
+
* @return {CodeNode} The respective code node.
|
|
1941
|
+
*/
|
|
1185
1942
|
_include( name ) {
|
|
1186
1943
|
|
|
1187
1944
|
const codeNode = wgslPolyfill[ name ];
|
|
@@ -1197,12 +1954,22 @@ ${ flowData.code }
|
|
|
1197
1954
|
|
|
1198
1955
|
}
|
|
1199
1956
|
|
|
1957
|
+
/**
|
|
1958
|
+
* Returns a WGSL vertex shader based on the given shader data.
|
|
1959
|
+
*
|
|
1960
|
+
* @private
|
|
1961
|
+
* @param {Object} shaderData - The shader data.
|
|
1962
|
+
* @return {string} The vertex shader.
|
|
1963
|
+
*/
|
|
1200
1964
|
_getWGSLVertexCode( shaderData ) {
|
|
1201
1965
|
|
|
1202
1966
|
return `${ this.getSignature() }
|
|
1203
1967
|
// directives
|
|
1204
1968
|
${shaderData.directives}
|
|
1205
1969
|
|
|
1970
|
+
// structs
|
|
1971
|
+
${shaderData.structs}
|
|
1972
|
+
|
|
1206
1973
|
// uniforms
|
|
1207
1974
|
${shaderData.uniforms}
|
|
1208
1975
|
|
|
@@ -1229,18 +1996,25 @@ fn main( ${shaderData.attributes} ) -> VaryingsStruct {
|
|
|
1229
1996
|
|
|
1230
1997
|
}
|
|
1231
1998
|
|
|
1999
|
+
/**
|
|
2000
|
+
* Returns a WGSL fragment shader based on the given shader data.
|
|
2001
|
+
*
|
|
2002
|
+
* @private
|
|
2003
|
+
* @param {Object} shaderData - The shader data.
|
|
2004
|
+
* @return {string} The vertex shader.
|
|
2005
|
+
*/
|
|
1232
2006
|
_getWGSLFragmentCode( shaderData ) {
|
|
1233
2007
|
|
|
1234
2008
|
return `${ this.getSignature() }
|
|
2009
|
+
// global
|
|
2010
|
+
${ diagnostics }
|
|
1235
2011
|
|
|
1236
|
-
|
|
2012
|
+
// structs
|
|
2013
|
+
${shaderData.structs}
|
|
1237
2014
|
|
|
1238
2015
|
// uniforms
|
|
1239
2016
|
${shaderData.uniforms}
|
|
1240
2017
|
|
|
1241
|
-
// structs
|
|
1242
|
-
${shaderData.structs}
|
|
1243
|
-
|
|
1244
2018
|
// codes
|
|
1245
2019
|
${shaderData.codes}
|
|
1246
2020
|
|
|
@@ -1258,6 +2032,14 @@ fn main( ${shaderData.varyings} ) -> ${shaderData.returnType} {
|
|
|
1258
2032
|
|
|
1259
2033
|
}
|
|
1260
2034
|
|
|
2035
|
+
/**
|
|
2036
|
+
* Returns a WGSL compute shader based on the given shader data.
|
|
2037
|
+
*
|
|
2038
|
+
* @private
|
|
2039
|
+
* @param {Object} shaderData - The shader data.
|
|
2040
|
+
* @param {string} workgroupSize - The workgroup size.
|
|
2041
|
+
* @return {string} The vertex shader.
|
|
2042
|
+
*/
|
|
1261
2043
|
_getWGSLComputeCode( shaderData, workgroupSize ) {
|
|
1262
2044
|
|
|
1263
2045
|
return `${ this.getSignature() }
|
|
@@ -1267,6 +2049,12 @@ ${shaderData.directives}
|
|
|
1267
2049
|
// system
|
|
1268
2050
|
var<private> instanceIndex : u32;
|
|
1269
2051
|
|
|
2052
|
+
// locals
|
|
2053
|
+
${shaderData.scopedArrays}
|
|
2054
|
+
|
|
2055
|
+
// structs
|
|
2056
|
+
${shaderData.structs}
|
|
2057
|
+
|
|
1270
2058
|
// uniforms
|
|
1271
2059
|
${shaderData.uniforms}
|
|
1272
2060
|
|
|
@@ -1277,7 +2065,7 @@ ${shaderData.codes}
|
|
|
1277
2065
|
fn main( ${shaderData.attributes} ) {
|
|
1278
2066
|
|
|
1279
2067
|
// system
|
|
1280
|
-
instanceIndex =
|
|
2068
|
+
instanceIndex = globalId.x + globalId.y * numWorkgroups.x * u32(${workgroupSize}) + globalId.z * numWorkgroups.x * numWorkgroups.y * u32(${workgroupSize});
|
|
1281
2069
|
|
|
1282
2070
|
// vars
|
|
1283
2071
|
${shaderData.vars}
|
|
@@ -1290,6 +2078,14 @@ fn main( ${shaderData.attributes} ) {
|
|
|
1290
2078
|
|
|
1291
2079
|
}
|
|
1292
2080
|
|
|
2081
|
+
/**
|
|
2082
|
+
* Returns a WGSL struct based on the given name and variables.
|
|
2083
|
+
*
|
|
2084
|
+
* @private
|
|
2085
|
+
* @param {string} name - The struct name.
|
|
2086
|
+
* @param {string} vars - The struct variables.
|
|
2087
|
+
* @return {string} The WGSL snippet representing a struct.
|
|
2088
|
+
*/
|
|
1293
2089
|
_getWGSLStruct( name, vars ) {
|
|
1294
2090
|
|
|
1295
2091
|
return `
|
|
@@ -1299,14 +2095,25 @@ ${vars}
|
|
|
1299
2095
|
|
|
1300
2096
|
}
|
|
1301
2097
|
|
|
2098
|
+
/**
|
|
2099
|
+
* Returns a WGSL struct binding.
|
|
2100
|
+
*
|
|
2101
|
+
* @private
|
|
2102
|
+
* @param {string} name - The struct name.
|
|
2103
|
+
* @param {string} vars - The struct variables.
|
|
2104
|
+
* @param {string} access - The access.
|
|
2105
|
+
* @param {number} [binding=0] - The binding index.
|
|
2106
|
+
* @param {number} [group=0] - The group index.
|
|
2107
|
+
* @return {string} The WGSL snippet representing a struct binding.
|
|
2108
|
+
*/
|
|
1302
2109
|
_getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) {
|
|
1303
2110
|
|
|
1304
2111
|
const structName = name + 'Struct';
|
|
1305
2112
|
const structSnippet = this._getWGSLStruct( structName, vars );
|
|
1306
2113
|
|
|
1307
2114
|
return `${structSnippet}
|
|
1308
|
-
@binding( ${binding} ) @group( ${group} )
|
|
1309
|
-
var<${access}> ${name} : ${structName};`;
|
|
2115
|
+
@binding( ${ binding } ) @group( ${ group } )
|
|
2116
|
+
var<${access}> ${ name } : ${ structName };`;
|
|
1310
2117
|
|
|
1311
2118
|
}
|
|
1312
2119
|
|