super-three 0.181.0 → 0.185.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 +3 -4
- package/build/three.cjs +21332 -19201
- package/build/three.core.js +20908 -19853
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +1947 -862
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +37 -16
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +33628 -25197
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +33394 -25000
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/Addons.js +14 -3
- package/examples/jsm/animation/CCDIKSolver.js +7 -3
- package/examples/jsm/controls/ArcballControls.js +13 -6
- package/examples/jsm/controls/DragControls.js +2 -2
- package/examples/jsm/controls/FirstPersonControls.js +127 -86
- package/examples/jsm/controls/FlyControls.js +4 -0
- package/examples/jsm/controls/MapControls.js +55 -1
- package/examples/jsm/controls/OrbitControls.js +111 -8
- package/examples/jsm/controls/TrackballControls.js +8 -8
- package/examples/jsm/controls/TransformControls.js +102 -17
- package/examples/jsm/csm/CSM.js +2 -1
- package/examples/jsm/csm/CSMFrustum.js +31 -6
- package/examples/jsm/csm/CSMShadowNode.js +10 -3
- package/examples/jsm/effects/AnaglyphEffect.js +102 -7
- package/examples/jsm/effects/AsciiEffect.js +14 -1
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/RoomEnvironment.js +3 -0
- package/examples/jsm/exporters/DRACOExporter.js +27 -6
- package/examples/jsm/exporters/EXRExporter.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +266 -21
- package/examples/jsm/exporters/PLYExporter.js +286 -73
- package/examples/jsm/exporters/USDZExporter.js +353 -99
- package/examples/jsm/generators/CityGenerator.js +346 -0
- package/examples/jsm/generators/ForestGenerator.js +347 -0
- package/examples/jsm/generators/TerrainGenerator.js +504 -0
- package/examples/jsm/generators/TreeGenerator.js +377 -0
- package/examples/jsm/generators/city/SidewalkGenerator.js +253 -0
- package/examples/jsm/generators/city/SkyscraperGenerator.js +1357 -0
- package/examples/jsm/geometries/DecalGeometry.js +1 -1
- package/examples/jsm/geometries/LoftGeometry.js +355 -0
- package/examples/jsm/geometries/TextGeometry.js +18 -0
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +221 -0
- package/examples/jsm/helpers/LightProbeHelper.js +5 -4
- package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
- package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
- package/examples/jsm/helpers/ViewHelper.js +83 -14
- package/examples/jsm/inspector/Extension.js +13 -0
- package/examples/jsm/inspector/Inspector.js +244 -91
- package/examples/jsm/inspector/RendererInspector.js +165 -39
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +916 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +281 -0
- package/examples/jsm/inspector/tabs/Console.js +241 -25
- package/examples/jsm/inspector/tabs/Memory.js +136 -0
- package/examples/jsm/inspector/tabs/Parameters.js +115 -7
- package/examples/jsm/inspector/tabs/Performance.js +24 -9
- package/examples/jsm/inspector/tabs/Settings.js +306 -0
- package/examples/jsm/inspector/tabs/Timeline.js +1696 -0
- package/examples/jsm/inspector/tabs/Viewer.js +723 -9
- package/examples/jsm/inspector/ui/Graph.js +162 -25
- package/examples/jsm/inspector/ui/Item.js +92 -13
- package/examples/jsm/inspector/ui/List.js +2 -2
- package/examples/jsm/inspector/ui/Profiler.js +1991 -44
- package/examples/jsm/inspector/ui/Style.js +1943 -543
- package/examples/jsm/inspector/ui/Tab.js +226 -5
- package/examples/jsm/inspector/ui/Values.js +126 -8
- package/examples/jsm/inspector/ui/utils.js +143 -10
- package/examples/jsm/interaction/InteractionManager.js +226 -0
- package/examples/jsm/libs/basis/README.md +0 -1
- package/examples/jsm/libs/demuxer_mp4.js +3 -3
- package/examples/jsm/libs/draco/README.md +0 -1
- package/examples/jsm/libs/meshopt_clusterizer.module.js +421 -0
- package/examples/jsm/libs/meshopt_decoder.module.js +9 -8
- package/examples/jsm/libs/meshopt_simplifier.module.js +627 -0
- package/examples/jsm/libs/mikktspace.module.js +34 -9
- package/examples/jsm/lighting/ClusteredLighting.js +55 -0
- package/examples/jsm/lighting/DynamicLighting.js +82 -0
- package/examples/jsm/lighting/LightProbeGrid.js +681 -0
- package/examples/jsm/lines/LineMaterial.js +45 -16
- package/examples/jsm/lines/LineSegments2.js +8 -0
- package/examples/jsm/lines/webgpu/LineSegments2.js +8 -0
- package/examples/jsm/loaders/3DMLoader.js +6 -5
- package/examples/jsm/loaders/3MFLoader.js +2 -2
- package/examples/jsm/loaders/AMFLoader.js +2 -2
- package/examples/jsm/loaders/ColladaLoader.js +24 -4026
- package/examples/jsm/loaders/DRACOLoader.js +51 -18
- package/examples/jsm/loaders/EXRLoader.js +701 -90
- package/examples/jsm/loaders/FBXLoader.js +235 -37
- package/examples/jsm/loaders/GCodeLoader.js +34 -8
- package/examples/jsm/loaders/GLTFLoader.js +146 -178
- package/examples/jsm/loaders/HDRLoader.js +7 -30
- package/examples/jsm/loaders/KMZLoader.js +5 -5
- package/examples/jsm/loaders/KTX2Loader.js +58 -17
- package/examples/jsm/loaders/LDrawLoader.js +49 -58
- package/examples/jsm/loaders/LUT3dlLoader.js +2 -2
- package/examples/jsm/loaders/LUTCubeLoader.js +2 -2
- package/examples/jsm/loaders/LWOLoader.js +11 -39
- package/examples/jsm/loaders/LottieLoader.js +1 -1
- package/examples/jsm/loaders/MaterialXLoader.js +31 -9
- package/examples/jsm/loaders/NRRDLoader.js +5 -5
- package/examples/jsm/loaders/PCDLoader.js +11 -9
- package/examples/jsm/loaders/PLYLoader.js +218 -55
- package/examples/jsm/loaders/SVGLoader.js +549 -497
- package/examples/jsm/loaders/TDSLoader.js +0 -2
- package/examples/jsm/loaders/TGALoader.js +0 -2
- package/examples/jsm/loaders/TTFLoader.js +1 -1
- package/examples/jsm/loaders/USDLoader.js +127 -43
- package/examples/jsm/loaders/UltraHDRLoader.js +285 -160
- package/examples/jsm/loaders/VOXLoader.js +660 -117
- package/examples/jsm/loaders/VRMLLoader.js +80 -3
- package/examples/jsm/loaders/VTKLoader.js +42 -25
- package/examples/jsm/loaders/collada/ColladaComposer.js +3044 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1977 -0
- package/examples/jsm/loaders/usd/USDAParser.js +504 -344
- package/examples/jsm/loaders/usd/USDCParser.js +1867 -6
- package/examples/jsm/loaders/usd/USDComposer.js +4627 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
- package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
- package/examples/jsm/math/Octree.js +131 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +2 -0
- package/examples/jsm/misc/RollerCoaster.js +42 -4
- package/examples/jsm/misc/TileCreasedNormalsPlugin.js +270 -0
- package/examples/jsm/misc/Volume.js +2 -3
- package/examples/jsm/misc/VolumeSlice.js +0 -1
- package/examples/jsm/modifiers/TessellateModifier.js +1 -1
- package/examples/jsm/objects/GroundedSkybox.js +1 -1
- package/examples/jsm/objects/LensflareMesh.js +1 -1
- package/examples/jsm/objects/Reflector.js +72 -25
- package/examples/jsm/objects/Sky.js +90 -6
- package/examples/jsm/objects/SkyMesh.js +150 -16
- package/examples/jsm/objects/Water.js +4 -3
- package/examples/jsm/objects/Water2.js +5 -3
- package/examples/jsm/objects/Water2Mesh.js +1 -1
- package/examples/jsm/objects/WaterMesh.js +5 -7
- package/examples/jsm/physics/AmmoPhysics.js +27 -15
- package/examples/jsm/physics/JoltPhysics.js +10 -6
- package/examples/jsm/physics/RapierPhysics.js +36 -7
- package/examples/jsm/postprocessing/EffectComposer.js +7 -5
- package/examples/jsm/postprocessing/OutputPass.js +9 -0
- package/examples/jsm/postprocessing/RenderPass.js +10 -0
- package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
- package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
- package/examples/jsm/renderers/Projector.js +246 -28
- package/examples/jsm/renderers/SVGRenderer.js +174 -60
- package/examples/jsm/shaders/GTAOShader.js +19 -6
- package/examples/jsm/shaders/HalftoneShader.js +12 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +6 -2
- package/examples/jsm/shaders/SAOShader.js +17 -4
- package/examples/jsm/shaders/SSAOShader.js +11 -1
- package/examples/jsm/shaders/SSRShader.js +6 -5
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
- package/examples/jsm/shaders/VignetteShader.js +1 -1
- package/examples/jsm/shaders/VolumeShader.js +31 -44
- package/examples/jsm/transpiler/AST.js +44 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +65 -8
- package/examples/jsm/transpiler/Linker.js +1 -1
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
- package/examples/jsm/transpiler/TSLEncoder.js +46 -3
- package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
- package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
- package/examples/jsm/tsl/WebGLNodesHandler.js +605 -0
- package/examples/jsm/tsl/display/AfterImageNode.js +11 -1
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +458 -16
- package/examples/jsm/tsl/display/BilateralBlurNode.js +374 -0
- package/examples/jsm/tsl/display/BloomNode.js +75 -25
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +3 -36
- package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +3 -3
- package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
- package/examples/jsm/tsl/display/FSR1Node.js +477 -0
- package/examples/jsm/tsl/display/FXAANode.js +13 -14
- package/examples/jsm/tsl/display/GTAONode.js +40 -17
- package/examples/jsm/tsl/display/GaussianBlurNode.js +21 -2
- package/examples/jsm/tsl/display/GodraysNode.js +615 -0
- package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +560 -0
- package/examples/jsm/tsl/display/LensflareNode.js +1 -1
- package/examples/jsm/tsl/display/Lut3DNode.js +1 -1
- package/examples/jsm/tsl/display/OutlineNode.js +69 -19
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +9 -8
- package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
- package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +912 -0
- package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
- package/examples/jsm/tsl/display/SMAANode.js +2 -2
- package/examples/jsm/tsl/display/SSAAPassNode.js +15 -27
- package/examples/jsm/tsl/display/SSGINode.js +96 -62
- package/examples/jsm/tsl/display/SSRNode.js +831 -134
- package/examples/jsm/tsl/display/SSSNode.js +8 -6
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/examples/jsm/tsl/display/SharpenNode.js +283 -0
- package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
- package/examples/jsm/tsl/display/TAAUNode.js +835 -0
- package/examples/jsm/tsl/display/TRAANode.js +315 -126
- package/examples/jsm/tsl/display/TemporalReprojectNode.js +1023 -0
- package/examples/jsm/tsl/display/TransitionNode.js +1 -1
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +622 -0
- package/examples/jsm/tsl/lighting/DynamicLightsNode.js +300 -0
- package/examples/jsm/tsl/lighting/data/AmbientLightDataNode.js +61 -0
- package/examples/jsm/tsl/lighting/data/DirectionalLightDataNode.js +111 -0
- package/examples/jsm/tsl/lighting/data/HemisphereLightDataNode.js +99 -0
- package/examples/jsm/tsl/lighting/data/PointLightDataNode.js +134 -0
- package/examples/jsm/tsl/lighting/data/SpotLightDataNode.js +161 -0
- package/examples/jsm/tsl/math/Bayer.js +53 -3
- package/examples/jsm/tsl/math/curlNoise.js +107 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +1 -1
- package/examples/jsm/tsl/shadows/TileShadowNodeHelper.js +3 -3
- package/examples/jsm/tsl/utils/GroundedSkybox.js +62 -0
- package/examples/jsm/tsl/utils/RNoise.js +51 -0
- package/examples/jsm/tsl/utils/SpecularHelpers.js +325 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +128 -62
- package/examples/jsm/utils/ColorUtils.js +76 -0
- package/examples/jsm/utils/GeometryCompressionUtils.js +1 -1
- package/examples/jsm/utils/LDrawUtils.js +1 -1
- package/examples/jsm/utils/SceneOptimizer.js +1 -1
- package/examples/jsm/utils/ShadowMapViewer.js +24 -10
- package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
- package/examples/jsm/utils/SkeletonUtils.js +14 -8
- package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
- package/examples/jsm/webxr/ARButton.js +1 -1
- package/examples/jsm/webxr/WebGLXRFallback.js +89 -0
- package/examples/jsm/webxr/XRControllerModelFactory.js +2 -2
- package/examples/jsm/webxr/XRHandMeshModel.js +36 -10
- package/examples/jsm/webxr/XRHandModelFactory.js +2 -1
- package/package.json +28 -34
- package/src/Three.Core.js +3 -1
- package/src/Three.TSL.js +35 -14
- package/src/Three.WebGPU.Nodes.js +5 -0
- package/src/Three.WebGPU.js +13 -0
- package/src/Three.js +1 -0
- package/src/animation/AnimationAction.js +18 -4
- package/src/animation/AnimationClip.js +0 -139
- package/src/animation/AnimationMixer.js +6 -0
- package/src/animation/AnimationUtils.js +1 -12
- package/src/animation/KeyframeTrack.js +47 -8
- package/src/animation/PropertyBinding.js +2 -2
- package/src/animation/PropertyMixer.js +4 -4
- package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
- package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
- package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
- package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
- package/src/animation/tracks/StringKeyframeTrack.js +1 -1
- package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
- package/src/audio/Audio.js +1 -1
- package/src/audio/AudioContext.js +2 -2
- package/src/audio/AudioListener.js +5 -3
- package/src/cameras/Camera.js +34 -4
- package/src/cameras/CubeCamera.js +20 -0
- package/src/cameras/StereoCamera.js +5 -2
- package/src/constants.js +90 -5
- package/src/core/BufferAttribute.js +13 -1
- package/src/core/BufferGeometry.js +43 -9
- package/src/core/Clock.js +7 -0
- package/src/core/Object3D.js +69 -11
- package/src/core/Raycaster.js +3 -3
- package/src/core/RenderTarget.js +19 -6
- package/src/extras/PMREMGenerator.js +13 -22
- package/src/extras/TextureUtils.js +6 -2
- package/src/extras/core/ShapePath.js +149 -160
- package/src/extras/curves/CatmullRomCurve3.js +3 -2
- package/src/geometries/ExtrudeGeometry.js +2 -2
- package/src/geometries/PolyhedronGeometry.js +1 -1
- package/src/geometries/SphereGeometry.js +8 -3
- package/src/geometries/TorusGeometry.js +8 -3
- package/src/helpers/CameraHelper.js +3 -0
- package/src/helpers/DirectionalLightHelper.js +6 -1
- package/src/helpers/HemisphereLightHelper.js +5 -0
- package/src/helpers/PointLightHelper.js +3 -25
- package/src/helpers/SpotLightHelper.js +4 -1
- package/src/lights/DirectionalLight.js +13 -0
- package/src/lights/HemisphereLight.js +10 -0
- package/src/lights/Light.js +1 -11
- package/src/lights/LightProbe.js +0 -15
- package/src/lights/LightShadow.js +15 -6
- package/src/lights/PointLight.js +15 -0
- package/src/lights/PointLightShadow.js +0 -86
- package/src/lights/SpotLight.js +22 -1
- package/src/lights/webgpu/IESSpotLight.js +2 -1
- package/src/loaders/AudioLoader.js +11 -1
- package/src/loaders/Cache.js +28 -0
- package/src/loaders/DataTextureLoader.js +75 -42
- package/src/loaders/FileLoader.js +2 -3
- package/src/loaders/ImageBitmapLoader.js +12 -9
- package/src/loaders/Loader.js +6 -0
- package/src/loaders/LoadingManager.js +5 -0
- package/src/loaders/MaterialLoader.js +37 -266
- package/src/loaders/ObjectLoader.js +48 -6
- package/src/loaders/nodes/NodeLoader.js +2 -2
- package/src/loaders/nodes/NodeObjectLoader.js +18 -0
- package/src/materials/LineBasicMaterial.js +4 -0
- package/src/materials/Material.js +198 -1
- package/src/materials/MeshBasicMaterial.js +24 -0
- package/src/materials/MeshDepthMaterial.js +10 -0
- package/src/materials/MeshDistanceMaterial.js +10 -0
- package/src/materials/MeshLambertMaterial.js +49 -1
- package/src/materials/MeshMatcapMaterial.js +25 -1
- package/src/materials/MeshNormalMaterial.js +9 -1
- package/src/materials/MeshPhongMaterial.js +49 -1
- package/src/materials/MeshPhysicalMaterial.js +38 -0
- package/src/materials/MeshStandardMaterial.js +42 -1
- package/src/materials/MeshToonMaterial.js +35 -2
- package/src/materials/PointsMaterial.js +7 -0
- package/src/materials/ShaderMaterial.js +106 -1
- package/src/materials/SpriteMaterial.js +7 -0
- package/src/materials/nodes/Line2NodeMaterial.js +380 -297
- package/src/materials/nodes/MeshBasicNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshNormalNodeMaterial.js +2 -2
- package/src/materials/nodes/MeshPhongNodeMaterial.js +0 -9
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -30
- package/src/materials/nodes/MeshSSSNodeMaterial.js +0 -13
- package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -15
- package/src/materials/nodes/NodeMaterial.js +153 -89
- package/src/materials/nodes/SpriteNodeMaterial.js +0 -10
- package/src/materials/nodes/manager/NodeMaterialObserver.js +234 -100
- package/src/math/Box3.js +5 -0
- package/src/math/FrustumArray.js +103 -133
- package/src/math/Interpolant.js +1 -1
- package/src/math/Line3.js +6 -5
- package/src/math/MathUtils.js +12 -12
- package/src/math/Matrix2.js +13 -9
- package/src/math/Matrix3.js +24 -9
- package/src/math/Matrix4.js +112 -74
- package/src/math/Plane.js +4 -3
- package/src/math/Quaternion.js +3 -29
- package/src/math/Sphere.js +1 -1
- package/src/math/Triangle.js +1 -1
- package/src/math/Vector2.js +13 -9
- package/src/math/Vector3.js +17 -15
- package/src/math/Vector4.js +15 -11
- package/src/math/interpolants/BezierInterpolant.js +106 -0
- package/src/nodes/Nodes.js +86 -71
- package/src/nodes/TSL.js +15 -13
- package/src/nodes/accessors/Arrays.js +5 -5
- package/src/nodes/accessors/Batch.js +108 -0
- package/src/nodes/accessors/Bitangent.js +7 -7
- package/src/nodes/accessors/BufferAttributeNode.js +120 -17
- package/src/nodes/accessors/BufferNode.js +29 -2
- package/src/nodes/accessors/Camera.js +149 -28
- package/src/nodes/accessors/ClippingNode.js +5 -5
- package/src/nodes/accessors/CubeTextureNode.js +27 -2
- package/src/nodes/accessors/Instance.js +264 -0
- package/src/nodes/accessors/MaterialNode.js +27 -3
- package/src/nodes/accessors/MaterialProperties.js +6 -8
- package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
- package/src/nodes/accessors/ModelNode.js +1 -1
- package/src/nodes/accessors/{MorphNode.js → Morph.js} +99 -112
- package/src/nodes/accessors/Normal.js +24 -24
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/Position.js +39 -3
- package/src/nodes/accessors/ReferenceBaseNode.js +6 -6
- package/src/nodes/accessors/ReferenceNode.js +9 -8
- package/src/nodes/accessors/ReflectVector.js +3 -3
- package/src/nodes/accessors/RendererReferenceNode.js +1 -2
- package/src/nodes/accessors/SceneProperties.js +47 -0
- package/src/nodes/accessors/Skinning.js +263 -0
- package/src/nodes/accessors/StorageBufferNode.js +16 -27
- package/src/nodes/accessors/StorageTexture3DNode.js +100 -0
- package/src/nodes/accessors/StorageTextureNode.js +74 -11
- package/src/nodes/accessors/Tangent.js +8 -18
- package/src/nodes/accessors/Texture3DNode.js +32 -35
- package/src/nodes/accessors/TextureNode.js +124 -25
- package/src/nodes/accessors/UniformArrayNode.js +6 -4
- package/src/nodes/accessors/UserDataNode.js +1 -2
- package/src/nodes/accessors/VertexColorNode.js +1 -2
- package/src/nodes/code/FunctionCallNode.js +1 -1
- package/src/nodes/code/FunctionNode.js +4 -19
- package/src/nodes/core/ArrayNode.js +21 -2
- package/src/nodes/core/AssignNode.js +3 -3
- package/src/nodes/core/AttributeNode.js +3 -3
- package/src/nodes/core/BypassNode.js +1 -1
- package/src/nodes/core/ContextNode.js +104 -5
- package/src/nodes/core/IndexNode.js +2 -1
- package/src/nodes/core/InputNode.js +1 -1
- package/src/nodes/core/InspectorNode.js +1 -1
- package/src/nodes/core/IsolateNode.js +1 -1
- package/src/nodes/core/MRTNode.js +55 -4
- package/src/nodes/core/Node.js +151 -17
- package/src/nodes/core/NodeBuilder.js +479 -101
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeFrame.js +12 -4
- package/src/nodes/core/NodeUtils.js +20 -18
- package/src/nodes/core/OutputStructNode.js +13 -11
- package/src/nodes/core/OverrideContextNode.js +153 -0
- package/src/nodes/core/ParameterNode.js +4 -4
- package/src/nodes/core/PropertyNode.js +66 -4
- package/src/nodes/core/StackNode.js +91 -20
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +20 -8
- package/src/nodes/core/StructTypeNode.js +17 -23
- package/src/nodes/core/SubBuildNode.js +2 -2
- package/src/nodes/core/UniformGroupNode.js +36 -6
- package/src/nodes/core/UniformNode.js +21 -5
- package/src/nodes/core/VarNode.js +56 -23
- package/src/nodes/core/VaryingNode.js +14 -21
- package/src/nodes/display/BlendModes.js +1 -105
- package/src/nodes/display/BumpMapNode.js +6 -1
- package/src/nodes/display/ColorAdjustment.js +27 -9
- package/src/nodes/display/ColorSpaceNode.js +3 -3
- package/src/nodes/display/FrontFacingNode.js +38 -9
- package/src/nodes/display/NormalMapNode.js +41 -6
- package/src/nodes/display/PassNode.js +157 -56
- package/src/nodes/display/PremultiplyAlphaFunctions.js +39 -0
- package/src/nodes/display/RenderOutputNode.js +19 -10
- package/src/nodes/display/ScreenNode.js +4 -2
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ToonOutlinePassNode.js +2 -2
- package/src/nodes/display/ViewportDepthNode.js +52 -4
- package/src/nodes/display/ViewportDepthTextureNode.js +11 -15
- package/src/nodes/display/ViewportTextureNode.js +39 -11
- package/src/nodes/fog/Fog.js +18 -35
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/functions/PhysicalLightingModel.js +126 -45
- package/src/nodes/functions/VolumetricLightingModel.js +40 -7
- package/src/nodes/geometry/RangeNode.js +5 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/BarrierNode.js +9 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +2 -3
- package/src/nodes/gpgpu/ComputeNode.js +74 -48
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +2 -2
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +5 -5
- package/src/nodes/lighting/AnalyticLightNode.js +53 -0
- package/src/nodes/lighting/EnvironmentNode.js +30 -5
- package/src/nodes/lighting/IESSpotLightNode.js +40 -2
- package/src/nodes/lighting/LightingContextNode.js +10 -2
- package/src/nodes/lighting/LightsNode.js +97 -65
- package/src/nodes/lighting/PointShadowNode.js +166 -148
- package/src/nodes/lighting/ShadowFilterNode.js +74 -117
- package/src/nodes/lighting/ShadowNode.js +149 -51
- package/src/nodes/materialx/lib/mx_noise.js +2 -2
- package/src/nodes/math/BitcastNode.js +1 -1
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/ConditionalNode.js +6 -6
- package/src/nodes/math/MathNode.js +115 -52
- package/src/nodes/math/OperatorNode.js +24 -23
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
- package/src/nodes/pmrem/PMREMNode.js +34 -3
- package/src/nodes/pmrem/PMREMUtils.js +9 -15
- package/src/nodes/tsl/TSLBase.js +1 -1
- package/src/nodes/tsl/TSLCore.js +99 -33
- package/src/nodes/utils/ArrayElementNode.js +14 -1
- package/src/nodes/utils/ConvertNode.js +1 -1
- package/src/nodes/utils/DebugNode.js +12 -12
- package/src/nodes/utils/EquirectUV.js +30 -5
- package/src/nodes/utils/EventNode.js +31 -2
- package/src/nodes/utils/FlipNode.js +1 -1
- package/src/nodes/utils/FunctionOverloadingNode.js +2 -2
- package/src/nodes/utils/JoinNode.js +3 -3
- package/src/nodes/utils/LoopNode.js +1 -1
- package/src/nodes/utils/MemberNode.js +2 -2
- package/src/nodes/utils/Packing.js +48 -5
- package/src/nodes/utils/PostProcessingUtils.js +33 -1
- package/src/nodes/utils/RTTNode.js +41 -25
- package/src/nodes/utils/ReflectorNode.js +4 -4
- package/src/nodes/utils/Remap.js +48 -0
- package/src/nodes/utils/RotateNode.js +1 -1
- package/src/nodes/utils/SampleNode.js +1 -1
- package/src/nodes/utils/SetNode.js +1 -1
- package/src/nodes/utils/SplitNode.js +1 -1
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/StorageArrayElementNode.js +1 -1
- package/src/nodes/utils/UVUtils.js +28 -0
- package/src/objects/BatchedMesh.js +66 -30
- package/src/objects/InstancedMesh.js +19 -3
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/objects/SkinnedMesh.js +26 -9
- package/src/renderers/WebGLRenderer.js +344 -156
- package/src/renderers/common/Animation.js +3 -3
- package/src/renderers/common/Attributes.js +15 -1
- package/src/renderers/common/Backend.js +78 -13
- package/src/renderers/common/Background.js +26 -13
- package/src/renderers/common/BindGroup.js +1 -16
- package/src/renderers/common/Binding.js +11 -0
- package/src/renderers/common/Bindings.js +141 -57
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/Buffer.js +49 -0
- package/src/renderers/common/BundleGroup.js +1 -1
- package/src/renderers/common/ChainMap.js +30 -6
- package/src/renderers/common/ClippingContext.js +10 -2
- package/src/renderers/common/ComputePipeline.js +1 -1
- package/src/renderers/common/CubeRenderTarget.js +51 -7
- package/src/renderers/common/Geometries.js +29 -3
- package/src/renderers/common/Info.js +374 -4
- package/src/renderers/common/InspectorBase.js +6 -1
- package/src/renderers/common/Lighting.js +51 -19
- package/src/renderers/common/Pipelines.js +40 -7
- package/src/renderers/common/PostProcessing.js +8 -206
- package/src/renderers/common/ReadbackBuffer.js +78 -0
- package/src/renderers/common/RenderBundle.js +3 -1
- package/src/renderers/common/RenderBundles.js +7 -3
- package/src/renderers/common/RenderContext.js +16 -0
- package/src/renderers/common/RenderContexts.js +33 -49
- package/src/renderers/common/RenderList.js +41 -4
- package/src/renderers/common/RenderLists.js +2 -1
- package/src/renderers/common/RenderObject.js +88 -16
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +21 -5
- package/src/renderers/common/RenderPipeline.js +232 -17
- package/src/renderers/common/Renderer.js +700 -163
- package/src/renderers/common/Sampler.js +16 -48
- package/src/renderers/common/StorageBuffer.js +13 -1
- package/src/renderers/common/Textures.js +121 -9
- package/src/renderers/common/TimestampQueryPool.js +6 -4
- package/src/renderers/common/Uniform.js +8 -0
- package/src/renderers/common/UniformsGroup.js +84 -1
- package/src/renderers/common/XRManager.js +377 -51
- package/src/renderers/common/extras/PMREMGenerator.js +40 -61
- package/src/renderers/common/nodes/NodeBuilderState.js +10 -2
- package/src/renderers/common/nodes/NodeLibrary.js +4 -4
- package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +298 -106
- package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +65 -0
- package/src/renderers/shaders/DFGLUTData.js +19 -34
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +13 -4
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +0 -6
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +9 -13
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lightprobes_pars_fragment.glsl.js +80 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +13 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +3 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +112 -53
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/normal_fragment_maps.glsl.js +7 -0
- package/src/renderers/shaders/ShaderChunk/normal_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/premultiplied_alpha_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +225 -186
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +12 -2
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk.js +5 -3
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +2 -3
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +7 -6
- package/src/renderers/shaders/UniformsLib.js +7 -5
- package/src/renderers/shaders/UniformsUtils.js +27 -5
- package/src/renderers/webgl/WebGLAnimation.js +2 -1
- package/src/renderers/webgl/WebGLBackground.js +15 -15
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLCapabilities.js +9 -4
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLGeometries.js +10 -7
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +0 -32
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLMaterials.js +24 -13
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLOutput.js +271 -0
- package/src/renderers/webgl/WebGLProgram.js +54 -113
- package/src/renderers/webgl/WebGLPrograms.js +74 -55
- package/src/renderers/webgl/WebGLRenderLists.js +24 -1
- package/src/renderers/webgl/WebGLRenderStates.js +13 -2
- package/src/renderers/webgl/WebGLShaderCache.js +5 -11
- package/src/renderers/webgl/WebGLShadowMap.js +188 -24
- package/src/renderers/webgl/WebGLState.js +75 -37
- package/src/renderers/webgl/WebGLTextures.js +230 -56
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUniformsGroups.js +82 -35
- package/src/renderers/webgl/WebGLUtils.js +6 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +322 -92
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +0 -41
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +295 -66
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +53 -19
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +25 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +223 -6
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +118 -73
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +10 -10
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +9 -3
- package/src/renderers/webgpu/WebGPUBackend.js +733 -302
- package/src/renderers/webgpu/WebGPURenderer.js +2 -1
- package/src/renderers/webgpu/descriptors/GPUBindGroupDescriptor.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUBufferDescriptor.js +57 -0
- package/src/renderers/webgpu/descriptors/GPUCommandEncoderDescriptor.js +30 -0
- package/src/renderers/webgpu/descriptors/GPUComputePassDescriptor.js +38 -0
- package/src/renderers/webgpu/descriptors/GPUComputePipelineDescriptor.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUCopyExternalImageDestInfo.js +47 -0
- package/src/renderers/webgpu/descriptors/GPUCopyExternalImageSourceInfo.js +50 -0
- package/src/renderers/webgpu/descriptors/GPUExtent3D.js +51 -0
- package/src/renderers/webgpu/descriptors/GPUPipelineLayoutDescriptor.js +39 -0
- package/src/renderers/webgpu/descriptors/GPUQuerySetDescriptor.js +47 -0
- package/src/renderers/webgpu/descriptors/GPURenderBundleEncoderDescriptor.js +74 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassColorAttachment.js +72 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassDepthStencilAttachment.js +99 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassDescriptor.js +72 -0
- package/src/renderers/webgpu/descriptors/GPURenderPassTimestampWrites.js +49 -0
- package/src/renderers/webgpu/descriptors/GPURenderPipelineDescriptor.js +130 -0
- package/src/renderers/webgpu/descriptors/GPUSamplerDescriptor.js +119 -0
- package/src/renderers/webgpu/descriptors/GPUShaderModuleDescriptor.js +46 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferInfo.js +57 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyBufferLayout.js +48 -0
- package/src/renderers/webgpu/descriptors/GPUTexelCopyTextureInfo.js +61 -0
- package/src/renderers/webgpu/descriptors/GPUTextureDescriptor.js +99 -0
- package/src/renderers/webgpu/descriptors/GPUTextureViewDescriptor.js +108 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -1
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +526 -93
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +194 -61
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +395 -234
- package/src/renderers/webgpu/utils/WebGPUCapabilities.js +48 -0
- package/src/renderers/webgpu/utils/WebGPUConstants.js +10 -0
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +224 -91
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +228 -213
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +428 -175
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +40 -25
- package/src/renderers/webgpu/utils/WebGPUUtils.js +70 -13
- package/src/renderers/webxr/WebXRController.js +12 -0
- package/src/renderers/webxr/WebXRManager.js +4 -2
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/DepthTexture.js +1 -1
- package/src/textures/ExternalTexture.js +0 -3
- package/src/textures/HTMLTexture.js +74 -0
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +16 -5
- package/src/utils.js +280 -3
- package/examples/fonts/LICENSE +0 -13
- package/examples/fonts/MPLUSRounded1c/MPLUSRounded1c-Regular.typeface.json.zip +0 -0
- package/examples/fonts/MPLUSRounded1c/OFL.txt +0 -91
- package/examples/fonts/README.md +0 -11
- package/examples/fonts/droid/NOTICE +0 -190
- package/examples/fonts/droid/README.txt +0 -18
- package/examples/fonts/droid/droid_sans_bold.typeface.json +0 -1
- package/examples/fonts/droid/droid_sans_mono_regular.typeface.json +0 -1
- package/examples/fonts/droid/droid_sans_regular.typeface.json +0 -1
- package/examples/fonts/droid/droid_serif_bold.typeface.json +0 -1
- package/examples/fonts/droid/droid_serif_regular.typeface.json +0 -1
- package/examples/fonts/gentilis_bold.typeface.json +0 -1
- package/examples/fonts/gentilis_regular.typeface.json +0 -1
- package/examples/fonts/helvetiker_bold.typeface.json +0 -1
- package/examples/fonts/helvetiker_regular.typeface.json +0 -1
- package/examples/fonts/optimer_bold.typeface.json +0 -1
- package/examples/fonts/optimer_regular.typeface.json +0 -1
- package/examples/fonts/ttf/README.md +0 -9
- package/examples/fonts/ttf/kenpixel.ttf +0 -0
- package/examples/jsm/libs/ammo.wasm.js +0 -822
- package/examples/jsm/libs/ammo.wasm.wasm +0 -0
- package/examples/jsm/libs/draco/draco_encoder.js +0 -33
- package/examples/jsm/libs/draco/gltf/draco_encoder.js +0 -33
- package/examples/jsm/libs/lottie_canvas.module.js +0 -14849
- package/examples/jsm/libs/opentype.module.js +0 -14506
- package/examples/jsm/libs/rhino3dm/rhino3dm.js +0 -21
- package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +0 -16
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/lighting/TiledLighting.js +0 -42
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -434
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
- package/examples/jsm/shaders/GodRaysShader.js +0 -333
- package/examples/jsm/tsl/display/AnamorphicNode.js +0 -282
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +0 -442
- package/src/nodes/accessors/BatchNode.js +0 -163
- package/src/nodes/accessors/InstanceNode.js +0 -244
- package/src/nodes/accessors/InstancedMeshNode.js +0 -50
- package/src/nodes/accessors/SceneNode.js +0 -145
- package/src/nodes/accessors/SkinningNode.js +0 -327
- package/src/nodes/code/ScriptableNode.js +0 -726
- package/src/nodes/code/ScriptableValueNode.js +0 -253
- package/src/nodes/display/PosterizeNode.js +0 -65
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
- package/src/nodes/utils/RemapNode.js +0 -125
- package/src/nodes/utils/SpriteSheetUVNode.js +0 -90
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
|
@@ -16,11 +16,10 @@ import { NodeAccess } from '../../../nodes/core/constants.js';
|
|
|
16
16
|
import VarNode from '../../../nodes/core/VarNode.js';
|
|
17
17
|
import ExpressionNode from '../../../nodes/code/ExpressionNode.js';
|
|
18
18
|
|
|
19
|
-
import { FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter } from '../../../constants.js';
|
|
19
|
+
import { FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, Compatibility } from '../../../constants.js';
|
|
20
20
|
import { warn, error } from '../../../utils.js';
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
const GPUShaderStage = ( typeof self !== 'undefined' ) ? self.GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 };
|
|
22
|
+
import { GPUShaderStage } from '../utils/WebGPUConstants.js';
|
|
24
23
|
|
|
25
24
|
const accessNames = {
|
|
26
25
|
[ NodeAccess.READ_ONLY ]: 'read',
|
|
@@ -35,9 +34,9 @@ const wrapNames = {
|
|
|
35
34
|
};
|
|
36
35
|
|
|
37
36
|
const gpuShaderStageLib = {
|
|
38
|
-
'vertex': GPUShaderStage
|
|
39
|
-
'fragment': GPUShaderStage
|
|
40
|
-
'compute': GPUShaderStage
|
|
37
|
+
'vertex': GPUShaderStage.VERTEX,
|
|
38
|
+
'fragment': GPUShaderStage.FRAGMENT,
|
|
39
|
+
'compute': GPUShaderStage.COMPUTE
|
|
41
40
|
};
|
|
42
41
|
|
|
43
42
|
const supports = {
|
|
@@ -92,6 +91,83 @@ const wgslPolyfill = {
|
|
|
92
91
|
repeatWrapping_float: new CodeNode( 'fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }' ),
|
|
93
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 ); }' ),
|
|
94
93
|
clampWrapping_float: new CodeNode( 'fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }' ),
|
|
94
|
+
inverse_mat2: new CodeNode( /* wgsl */`
|
|
95
|
+
fn tsl_inverse_mat2( m : mat2x2<f32> ) -> mat2x2<f32> {
|
|
96
|
+
|
|
97
|
+
let det = m[ 0 ][ 0 ] * m[ 1 ][ 1 ] - m[ 0 ][ 1 ] * m[ 1 ][ 0 ];
|
|
98
|
+
|
|
99
|
+
return mat2x2<f32>(
|
|
100
|
+
m[ 1 ][ 1 ], - m[ 0 ][ 1 ],
|
|
101
|
+
- m[ 1 ][ 0 ], m[ 0 ][ 0 ]
|
|
102
|
+
) * ( 1.0 / det );
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
` ),
|
|
106
|
+
inverse_mat3: new CodeNode( /* wgsl */`
|
|
107
|
+
fn tsl_inverse_mat3( m : mat3x3<f32> ) -> mat3x3<f32> {
|
|
108
|
+
|
|
109
|
+
let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ];
|
|
110
|
+
let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ];
|
|
111
|
+
let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ];
|
|
112
|
+
|
|
113
|
+
let b01 = a22 * a11 - a12 * a21;
|
|
114
|
+
let b11 = - a22 * a10 + a12 * a20;
|
|
115
|
+
let b21 = a21 * a10 - a11 * a20;
|
|
116
|
+
|
|
117
|
+
let det = a00 * b01 + a01 * b11 + a02 * b21;
|
|
118
|
+
|
|
119
|
+
return mat3x3<f32>(
|
|
120
|
+
b01, ( - a22 * a01 + a02 * a21 ), ( a12 * a01 - a02 * a11 ),
|
|
121
|
+
b11, ( a22 * a00 - a02 * a20 ), ( - a12 * a00 + a02 * a10 ),
|
|
122
|
+
b21, ( - a21 * a00 + a01 * a20 ), ( a11 * a00 - a01 * a10 )
|
|
123
|
+
) * ( 1.0 / det );
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
` ),
|
|
127
|
+
inverse_mat4: new CodeNode( /* wgsl */`
|
|
128
|
+
fn tsl_inverse_mat4( m : mat4x4<f32> ) -> mat4x4<f32> {
|
|
129
|
+
|
|
130
|
+
let a00 = m[ 0 ][ 0 ]; let a01 = m[ 0 ][ 1 ]; let a02 = m[ 0 ][ 2 ]; let a03 = m[ 0 ][ 3 ];
|
|
131
|
+
let a10 = m[ 1 ][ 0 ]; let a11 = m[ 1 ][ 1 ]; let a12 = m[ 1 ][ 2 ]; let a13 = m[ 1 ][ 3 ];
|
|
132
|
+
let a20 = m[ 2 ][ 0 ]; let a21 = m[ 2 ][ 1 ]; let a22 = m[ 2 ][ 2 ]; let a23 = m[ 2 ][ 3 ];
|
|
133
|
+
let a30 = m[ 3 ][ 0 ]; let a31 = m[ 3 ][ 1 ]; let a32 = m[ 3 ][ 2 ]; let a33 = m[ 3 ][ 3 ];
|
|
134
|
+
|
|
135
|
+
let b00 = a00 * a11 - a01 * a10;
|
|
136
|
+
let b01 = a00 * a12 - a02 * a10;
|
|
137
|
+
let b02 = a00 * a13 - a03 * a10;
|
|
138
|
+
let b03 = a01 * a12 - a02 * a11;
|
|
139
|
+
let b04 = a01 * a13 - a03 * a11;
|
|
140
|
+
let b05 = a02 * a13 - a03 * a12;
|
|
141
|
+
let b06 = a20 * a31 - a21 * a30;
|
|
142
|
+
let b07 = a20 * a32 - a22 * a30;
|
|
143
|
+
let b08 = a20 * a33 - a23 * a30;
|
|
144
|
+
let b09 = a21 * a32 - a22 * a31;
|
|
145
|
+
let b10 = a21 * a33 - a23 * a31;
|
|
146
|
+
let b11 = a22 * a33 - a23 * a32;
|
|
147
|
+
|
|
148
|
+
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
149
|
+
|
|
150
|
+
return mat4x4<f32>(
|
|
151
|
+
a11 * b11 - a12 * b10 + a13 * b09,
|
|
152
|
+
a02 * b10 - a01 * b11 - a03 * b09,
|
|
153
|
+
a31 * b05 - a32 * b04 + a33 * b03,
|
|
154
|
+
a22 * b04 - a21 * b05 - a23 * b03,
|
|
155
|
+
a12 * b08 - a10 * b11 - a13 * b07,
|
|
156
|
+
a00 * b11 - a02 * b08 + a03 * b07,
|
|
157
|
+
a32 * b02 - a30 * b05 - a33 * b01,
|
|
158
|
+
a20 * b05 - a22 * b02 + a23 * b01,
|
|
159
|
+
a10 * b10 - a11 * b08 + a13 * b06,
|
|
160
|
+
a01 * b08 - a00 * b10 - a03 * b06,
|
|
161
|
+
a30 * b04 - a31 * b02 + a33 * b00,
|
|
162
|
+
a21 * b02 - a20 * b04 - a23 * b00,
|
|
163
|
+
a11 * b07 - a10 * b09 - a12 * b06,
|
|
164
|
+
a00 * b09 - a01 * b07 + a02 * b06,
|
|
165
|
+
a31 * b01 - a30 * b03 - a32 * b00,
|
|
166
|
+
a20 * b03 - a21 * b01 + a22 * b00
|
|
167
|
+
) * ( 1.0 / det );
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
` ),
|
|
95
171
|
biquadraticTexture: new CodeNode( /* wgsl */`
|
|
96
172
|
fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, level : u32 ) -> vec4f {
|
|
97
173
|
|
|
@@ -113,6 +189,29 @@ fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, iRes : vec2u, l
|
|
|
113
189
|
|
|
114
190
|
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
115
191
|
|
|
192
|
+
}
|
|
193
|
+
` ),
|
|
194
|
+
biquadraticTextureArray: new CodeNode( /* wgsl */`
|
|
195
|
+
fn tsl_biquadraticTexture_array( map : texture_2d_array<f32>, coord : vec2f, iRes : vec2u, layer : u32, level : u32 ) -> vec4f {
|
|
196
|
+
|
|
197
|
+
let res = vec2f( iRes );
|
|
198
|
+
|
|
199
|
+
let uvScaled = coord * res;
|
|
200
|
+
let uvWrapping = ( ( uvScaled % res ) + res ) % res;
|
|
201
|
+
|
|
202
|
+
// https://www.shadertoy.com/view/WtyXRy
|
|
203
|
+
|
|
204
|
+
let uv = uvWrapping - 0.5;
|
|
205
|
+
let iuv = floor( uv );
|
|
206
|
+
let f = fract( uv );
|
|
207
|
+
|
|
208
|
+
let rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, layer, level );
|
|
209
|
+
let rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, layer, level );
|
|
210
|
+
let rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, layer, level );
|
|
211
|
+
let rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, layer, level );
|
|
212
|
+
|
|
213
|
+
return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );
|
|
214
|
+
|
|
116
215
|
}
|
|
117
216
|
` )
|
|
118
217
|
};
|
|
@@ -128,8 +227,17 @@ const wgslMethods = {
|
|
|
128
227
|
equals_bvec2: 'tsl_equals_bvec2',
|
|
129
228
|
equals_bvec3: 'tsl_equals_bvec3',
|
|
130
229
|
equals_bvec4: 'tsl_equals_bvec4',
|
|
230
|
+
inverse_mat2: 'tsl_inverse_mat2',
|
|
231
|
+
inverse_mat3: 'tsl_inverse_mat3',
|
|
232
|
+
inverse_mat4: 'tsl_inverse_mat4',
|
|
131
233
|
inversesqrt: 'inverseSqrt',
|
|
132
|
-
bitcast: 'bitcast<f32>'
|
|
234
|
+
bitcast: 'bitcast<f32>',
|
|
235
|
+
floatpack_snorm_2x16: 'pack2x16snorm',
|
|
236
|
+
floatpack_unorm_2x16: 'pack2x16unorm',
|
|
237
|
+
floatpack_float16_2x16: 'pack2x16float',
|
|
238
|
+
floatunpack_snorm_2x16: 'unpack2x16snorm',
|
|
239
|
+
floatunpack_unorm_2x16: 'unpack2x16unorm',
|
|
240
|
+
floatunpack_float16_2x16: 'unpack2x16float'
|
|
133
241
|
};
|
|
134
242
|
|
|
135
243
|
//
|
|
@@ -172,6 +280,14 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
172
280
|
*/
|
|
173
281
|
this.uniformGroups = {};
|
|
174
282
|
|
|
283
|
+
/**
|
|
284
|
+
* A dictionary that holds the assigned binding indices for each uniform group.
|
|
285
|
+
* This ensures the same binding index is used across all shader stages.
|
|
286
|
+
*
|
|
287
|
+
* @type {Object<string,{index: number, id: number}>}
|
|
288
|
+
*/
|
|
289
|
+
this.uniformGroupsBindings = {};
|
|
290
|
+
|
|
175
291
|
/**
|
|
176
292
|
* A dictionary that holds for each shader stage a Map of builtins.
|
|
177
293
|
*
|
|
@@ -194,6 +310,22 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
194
310
|
*/
|
|
195
311
|
this.scopedArrays = new Map();
|
|
196
312
|
|
|
313
|
+
/**
|
|
314
|
+
* A flag that indicates that early returns are allowed.
|
|
315
|
+
*
|
|
316
|
+
* @type {boolean}
|
|
317
|
+
* @default true
|
|
318
|
+
*/
|
|
319
|
+
this.allowEarlyReturns = true;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* A flag that indicates that global variables are allowed.
|
|
323
|
+
*
|
|
324
|
+
* @type {boolean}
|
|
325
|
+
* @default true
|
|
326
|
+
*/
|
|
327
|
+
this.allowGlobalVariables = true;
|
|
328
|
+
|
|
197
329
|
}
|
|
198
330
|
|
|
199
331
|
/**
|
|
@@ -258,17 +390,31 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
258
390
|
|
|
259
391
|
if ( this.isUnfilterable( texture ) === false ) {
|
|
260
392
|
|
|
261
|
-
if (
|
|
393
|
+
if ( depthSnippet ) {
|
|
262
394
|
|
|
263
|
-
|
|
395
|
+
if ( offsetSnippet ) {
|
|
264
396
|
|
|
265
|
-
|
|
397
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
|
|
266
398
|
|
|
267
|
-
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
|
|
402
|
+
|
|
403
|
+
} else {
|
|
404
|
+
|
|
405
|
+
if ( offsetSnippet ) {
|
|
406
|
+
|
|
407
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
|
|
408
|
+
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
|
|
412
|
+
|
|
413
|
+
}
|
|
268
414
|
|
|
269
415
|
} else if ( this.isFilteredTexture( texture ) ) {
|
|
270
416
|
|
|
271
|
-
return this.generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet );
|
|
417
|
+
return this.generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet, depthSnippet );
|
|
272
418
|
|
|
273
419
|
} else {
|
|
274
420
|
|
|
@@ -286,7 +432,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
286
432
|
*/
|
|
287
433
|
generateWrapFunction( texture ) {
|
|
288
434
|
|
|
289
|
-
const functionName = `tsl_coord_${ wrapNames[ texture.wrapS ] }S_${ wrapNames[ texture.wrapT ] }
|
|
435
|
+
const functionName = `tsl_coord_${ wrapNames[ texture.wrapS ] }S_${ wrapNames[ texture.wrapT ] }T_${ texture.is3DTexture || texture.isData3DTexture ? '3d' : '2d' }`;
|
|
290
436
|
|
|
291
437
|
let nodeCode = wgslCodeCache[ functionName ];
|
|
292
438
|
|
|
@@ -295,7 +441,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
295
441
|
const includes = [];
|
|
296
442
|
|
|
297
443
|
// For 3D textures, use vec3f; for texture arrays, keep vec2f since array index is separate
|
|
298
|
-
const coordType = texture.isData3DTexture ? 'vec3f' : 'vec2f';
|
|
444
|
+
const coordType = texture.is3DTexture || texture.isData3DTexture ? 'vec3f' : 'vec2f';
|
|
299
445
|
let code = `fn ${ functionName }( coord : ${ coordType } ) -> ${ coordType } {\n\n\treturn ${ coordType }(\n`;
|
|
300
446
|
|
|
301
447
|
const addWrapSnippet = ( wrap, axis ) => {
|
|
@@ -334,7 +480,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
334
480
|
|
|
335
481
|
addWrapSnippet( texture.wrapT, 'y' );
|
|
336
482
|
|
|
337
|
-
if ( texture.isData3DTexture ) {
|
|
483
|
+
if ( texture.is3DTexture || texture.isData3DTexture ) {
|
|
338
484
|
|
|
339
485
|
code += ',\n';
|
|
340
486
|
addWrapSnippet( texture.wrapR, 'z' );
|
|
@@ -378,7 +524,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
378
524
|
*/
|
|
379
525
|
generateTextureDimension( texture, textureProperty, levelSnippet ) {
|
|
380
526
|
|
|
381
|
-
const textureData = this.getDataFromNode( texture, this.shaderStage, this.
|
|
527
|
+
const textureData = this.getDataFromNode( texture, this.shaderStage, this.cache );
|
|
382
528
|
|
|
383
529
|
if ( textureData.dimensionsSnippet === undefined ) textureData.dimensionsSnippet = {};
|
|
384
530
|
|
|
@@ -392,7 +538,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
392
538
|
const { primarySamples } = this.renderer.backend.utils.getTextureSampleData( texture );
|
|
393
539
|
const isMultisampled = primarySamples > 1;
|
|
394
540
|
|
|
395
|
-
if ( texture.isData3DTexture ) {
|
|
541
|
+
if ( texture.is3DTexture || texture.isData3DTexture ) {
|
|
396
542
|
|
|
397
543
|
dimensionType = 'vec3<u32>';
|
|
398
544
|
|
|
@@ -418,7 +564,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
418
564
|
|
|
419
565
|
textureData.dimensionsSnippet[ levelSnippet ] = textureDimensionNode;
|
|
420
566
|
|
|
421
|
-
if ( texture.isArrayTexture || texture.isDataArrayTexture || texture.isData3DTexture ) {
|
|
567
|
+
if ( texture.isArrayTexture || texture.isDataArrayTexture || texture.is3DTexture || texture.isData3DTexture ) {
|
|
422
568
|
|
|
423
569
|
textureData.arrayLayerCount = new VarNode(
|
|
424
570
|
new ExpressionNode(
|
|
@@ -452,11 +598,10 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
452
598
|
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
453
599
|
* @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
|
|
454
600
|
* @param {string} [levelSnippet='0u'] - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
601
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
455
602
|
* @return {string} The WGSL snippet.
|
|
456
603
|
*/
|
|
457
|
-
generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet = '0u' ) {
|
|
458
|
-
|
|
459
|
-
this._include( 'biquadraticTexture' );
|
|
604
|
+
generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet = '0u', depthSnippet ) {
|
|
460
605
|
|
|
461
606
|
const wrapFunction = this.generateWrapFunction( texture );
|
|
462
607
|
const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
|
|
@@ -467,6 +612,16 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
467
612
|
|
|
468
613
|
}
|
|
469
614
|
|
|
615
|
+
if ( depthSnippet ) {
|
|
616
|
+
|
|
617
|
+
this._include( 'biquadraticTextureArray' );
|
|
618
|
+
|
|
619
|
+
return `tsl_biquadraticTexture_array( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ depthSnippet } ), u32( ${ levelSnippet } ) )`;
|
|
620
|
+
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
this._include( 'biquadraticTexture' );
|
|
624
|
+
|
|
470
625
|
return `tsl_biquadraticTexture( ${ textureProperty }, ${ wrapFunction }( ${ uvSnippet } ), ${ textureDimension }, u32( ${ levelSnippet } ) )`;
|
|
471
626
|
|
|
472
627
|
}
|
|
@@ -485,10 +640,27 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
485
640
|
*/
|
|
486
641
|
generateTextureLod( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet, levelSnippet = '0u' ) {
|
|
487
642
|
|
|
643
|
+
// Cube textures cannot use textureLoad in WGSL, must use textureSampleLevel
|
|
644
|
+
if ( texture.isCubeTexture === true ) {
|
|
645
|
+
|
|
646
|
+
if ( offsetSnippet ) {
|
|
647
|
+
|
|
648
|
+
uvSnippet = `${ uvSnippet } + vec3<f32>(${ offsetSnippet })`;
|
|
649
|
+
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// Depth textures require integer level, regular textures use float
|
|
653
|
+
const levelType = texture.isDepthTexture ? 'u32' : 'f32';
|
|
654
|
+
|
|
655
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelType }( ${ levelSnippet } ) )`;
|
|
656
|
+
|
|
657
|
+
}
|
|
658
|
+
|
|
488
659
|
const wrapFunction = this.generateWrapFunction( texture );
|
|
489
660
|
const textureDimension = this.generateTextureDimension( texture, textureProperty, levelSnippet );
|
|
490
661
|
|
|
491
|
-
const vecType = texture.isData3DTexture ? 'vec3' : 'vec2';
|
|
662
|
+
const vecType = texture.is3DTexture || texture.isData3DTexture ? 'vec3' : 'vec2';
|
|
663
|
+
const textureDimensionMargin = ( vecType === 'vec3' ) ? 'vec3<u32>( 1, 1, 1 )' : 'vec2<u32>( 1, 1 )';
|
|
492
664
|
|
|
493
665
|
if ( offsetSnippet ) {
|
|
494
666
|
|
|
@@ -496,9 +668,47 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
496
668
|
|
|
497
669
|
}
|
|
498
670
|
|
|
499
|
-
const
|
|
671
|
+
const clampMin = `${ vecType }<f32>( 0 )`;
|
|
672
|
+
const clampMax = `${ vecType }<f32>( ${ textureDimension } - ${ textureDimensionMargin } )`;
|
|
673
|
+
|
|
674
|
+
uvSnippet = `${ vecType }<u32>( clamp( floor( ${ wrapFunction }( ${ uvSnippet } ) * ${ vecType }<f32>( ${ textureDimension } ) ), ${ clampMin }, ${ clampMax } ) )`;
|
|
675
|
+
|
|
676
|
+
return this.generateTextureLoad( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, null );
|
|
677
|
+
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Generates the WGSL snippet that reads a single texel from a storage texture.
|
|
682
|
+
*
|
|
683
|
+
* @param {Texture} texture - The texture.
|
|
684
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
685
|
+
* @param {string} uvIndexSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
686
|
+
* @param {?string} levelSnippet - A WGSL snippet that represents the mip level, with level 0 containing a full size version of the texture.
|
|
687
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
688
|
+
* @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
|
|
689
|
+
* @return {string} The WGSL snippet.
|
|
690
|
+
*/
|
|
691
|
+
generateStorageTextureLoad( texture, textureProperty, uvIndexSnippet, levelSnippet, depthSnippet, offsetSnippet ) {
|
|
692
|
+
|
|
693
|
+
if ( offsetSnippet ) {
|
|
694
|
+
|
|
695
|
+
uvIndexSnippet = `${ uvIndexSnippet } + ${ offsetSnippet }`;
|
|
696
|
+
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
let snippet;
|
|
700
|
+
|
|
701
|
+
if ( depthSnippet ) {
|
|
702
|
+
|
|
703
|
+
snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet }, ${ depthSnippet } )`;
|
|
704
|
+
|
|
705
|
+
} else {
|
|
706
|
+
|
|
707
|
+
snippet = `textureLoad( ${ textureProperty }, ${ uvIndexSnippet } )`;
|
|
500
708
|
|
|
501
|
-
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return snippet;
|
|
502
712
|
|
|
503
713
|
}
|
|
504
714
|
|
|
@@ -581,7 +791,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
581
791
|
*/
|
|
582
792
|
isSampleCompare( texture ) {
|
|
583
793
|
|
|
584
|
-
return texture.isDepthTexture === true && texture.compareFunction !== null;
|
|
794
|
+
return texture.isDepthTexture === true && texture.compareFunction !== null && this.renderer.hasCompatibility( Compatibility.TEXTURE_COMPARE );
|
|
585
795
|
|
|
586
796
|
}
|
|
587
797
|
|
|
@@ -594,7 +804,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
594
804
|
isUnfilterable( texture ) {
|
|
595
805
|
|
|
596
806
|
return this.getComponentTypeFromTexture( texture ) !== 'float' ||
|
|
597
|
-
( ! this.isAvailable( 'float32Filterable' ) && texture.
|
|
807
|
+
( ! this.isAvailable( 'float32Filterable' ) && texture.type === FloatType ) ||
|
|
598
808
|
( this.isSampleCompare( texture ) === false && texture.minFilter === NearestFilter && texture.magFilter === NearestFilter ) ||
|
|
599
809
|
this.renderer.backend.utils.getTextureSampleData( texture ).primarySamples > 1;
|
|
600
810
|
|
|
@@ -645,14 +855,27 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
645
855
|
|
|
646
856
|
if ( shaderStage === 'fragment' ) {
|
|
647
857
|
|
|
648
|
-
|
|
649
|
-
|
|
858
|
+
if ( depthSnippet ) {
|
|
859
|
+
|
|
860
|
+
if ( offsetSnippet ) {
|
|
650
861
|
|
|
651
|
-
|
|
862
|
+
return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
|
|
652
863
|
|
|
653
|
-
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
|
|
867
|
+
|
|
868
|
+
} else {
|
|
869
|
+
|
|
870
|
+
if ( offsetSnippet ) {
|
|
871
|
+
|
|
872
|
+
return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] }, ${ offsetSnippet } )`;
|
|
873
|
+
|
|
874
|
+
}
|
|
654
875
|
|
|
655
|
-
|
|
876
|
+
return `textureSampleGrad( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
|
|
877
|
+
|
|
878
|
+
}
|
|
656
879
|
|
|
657
880
|
} else {
|
|
658
881
|
|
|
@@ -707,6 +930,80 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
707
930
|
|
|
708
931
|
}
|
|
709
932
|
|
|
933
|
+
/**
|
|
934
|
+
* Generates the WGSL snippet for gathering four texels from the given texture.
|
|
935
|
+
*
|
|
936
|
+
* @param {Texture} texture - The texture.
|
|
937
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
938
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
939
|
+
* @param {string} gatherSnippet - A WGSL snippet that represents the index of the channel to read.
|
|
940
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
941
|
+
* @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
|
|
942
|
+
* @param {?string} flipYSnippet - A WGSL snippet that represents the y-flip. Only used for WebGL.
|
|
943
|
+
* @return {string} The WGSL snippet.
|
|
944
|
+
*/
|
|
945
|
+
generateTextureGather( texture, textureProperty, uvSnippet, gatherSnippet, depthSnippet, offsetSnippet ) {
|
|
946
|
+
|
|
947
|
+
const componentSnippet = texture.isDepthTexture === true ? '' : `${gatherSnippet}, `;
|
|
948
|
+
|
|
949
|
+
if ( depthSnippet ) {
|
|
950
|
+
|
|
951
|
+
if ( offsetSnippet ) {
|
|
952
|
+
|
|
953
|
+
return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ offsetSnippet } )`;
|
|
954
|
+
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet } )`;
|
|
958
|
+
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
if ( offsetSnippet ) {
|
|
962
|
+
|
|
963
|
+
return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ offsetSnippet } )`;
|
|
964
|
+
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
return `textureGather( ${componentSnippet}${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet })`;
|
|
968
|
+
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Generates the WGSL snippet for performing a depth comparison on four texels in the given depth texture.
|
|
973
|
+
*
|
|
974
|
+
* @param {Texture} texture - The texture.
|
|
975
|
+
* @param {string} textureProperty - The name of the texture uniform in the shader.
|
|
976
|
+
* @param {string} uvSnippet - A WGSL snippet that represents texture coordinates used for sampling.
|
|
977
|
+
* @param {string} compareSnippet - A WGSL snippet that represents the reference value.
|
|
978
|
+
* @param {?string} depthSnippet - A WGSL snippet that represents 0-based texture array index to sample.
|
|
979
|
+
* @param {?string} offsetSnippet - A WGSL snippet that represents the offset that will be applied to the unnormalized texture coordinate before sampling the texture.
|
|
980
|
+
* @param {?string} flipYSnippet - A WGSL snippet that represents the y-flip. Only used for WebGL.
|
|
981
|
+
* @return {string} The WGSL snippet.
|
|
982
|
+
*/
|
|
983
|
+
generateTextureGatherCompare( texture, textureProperty, uvSnippet, compareSnippet, depthSnippet, offsetSnippet ) {
|
|
984
|
+
|
|
985
|
+
if ( depthSnippet ) {
|
|
986
|
+
|
|
987
|
+
if ( offsetSnippet ) {
|
|
988
|
+
|
|
989
|
+
return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
|
|
990
|
+
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ compareSnippet })`;
|
|
994
|
+
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
if ( offsetSnippet ) {
|
|
998
|
+
|
|
999
|
+
return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet }, ${ offsetSnippet } )`;
|
|
1000
|
+
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
return `textureGatherCompare( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ compareSnippet })`;
|
|
1004
|
+
|
|
1005
|
+
}
|
|
1006
|
+
|
|
710
1007
|
/**
|
|
711
1008
|
* Generates the WGSL snippet when sampling textures with explicit mip level.
|
|
712
1009
|
*
|
|
@@ -723,17 +1020,31 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
723
1020
|
|
|
724
1021
|
if ( this.isUnfilterable( texture ) === false ) {
|
|
725
1022
|
|
|
726
|
-
if (
|
|
1023
|
+
if ( depthSnippet ) {
|
|
727
1024
|
|
|
728
|
-
|
|
1025
|
+
if ( offsetSnippet ) {
|
|
729
1026
|
|
|
730
|
-
|
|
1027
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
|
|
1028
|
+
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ levelSnippet } )`;
|
|
1032
|
+
|
|
1033
|
+
} else {
|
|
1034
|
+
|
|
1035
|
+
if ( offsetSnippet ) {
|
|
731
1036
|
|
|
732
|
-
|
|
1037
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet }, ${ offsetSnippet } )`;
|
|
1038
|
+
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
return `textureSampleLevel( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ levelSnippet } )`;
|
|
1042
|
+
|
|
1043
|
+
}
|
|
733
1044
|
|
|
734
1045
|
} else if ( this.isFilteredTexture( texture ) ) {
|
|
735
1046
|
|
|
736
|
-
return this.generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet );
|
|
1047
|
+
return this.generateFilteredTexture( texture, textureProperty, uvSnippet, offsetSnippet, levelSnippet, depthSnippet );
|
|
737
1048
|
|
|
738
1049
|
} else {
|
|
739
1050
|
|
|
@@ -759,13 +1070,27 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
759
1070
|
|
|
760
1071
|
if ( shaderStage === 'fragment' ) {
|
|
761
1072
|
|
|
762
|
-
if (
|
|
1073
|
+
if ( depthSnippet ) {
|
|
763
1074
|
|
|
764
|
-
|
|
1075
|
+
if ( offsetSnippet ) {
|
|
765
1076
|
|
|
766
|
-
|
|
1077
|
+
return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
|
|
767
1078
|
|
|
768
|
-
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ depthSnippet }, ${ biasSnippet } )`;
|
|
1082
|
+
|
|
1083
|
+
} else {
|
|
1084
|
+
|
|
1085
|
+
if ( offsetSnippet ) {
|
|
1086
|
+
|
|
1087
|
+
return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet }, ${ offsetSnippet } )`;
|
|
1088
|
+
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`;
|
|
1092
|
+
|
|
1093
|
+
}
|
|
769
1094
|
|
|
770
1095
|
} else {
|
|
771
1096
|
|
|
@@ -797,7 +1122,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
797
1122
|
const name = node.name;
|
|
798
1123
|
const type = node.type;
|
|
799
1124
|
|
|
800
|
-
if ( type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'texture3D' ) {
|
|
1125
|
+
if ( type === 'texture' || type === 'cubeTexture' || type === 'cubeDepthTexture' || type === 'storageTexture' || type === 'texture3D' ) {
|
|
801
1126
|
|
|
802
1127
|
return name;
|
|
803
1128
|
|
|
@@ -923,7 +1248,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
923
1248
|
|
|
924
1249
|
const bindings = this.getBindGroupArray( groupName, shaderStage );
|
|
925
1250
|
|
|
926
|
-
if ( type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'texture3D' ) {
|
|
1251
|
+
if ( type === 'texture' || type === 'cubeTexture' || type === 'cubeDepthTexture' || type === 'storageTexture' || type === 'texture3D' ) {
|
|
927
1252
|
|
|
928
1253
|
let texture = null;
|
|
929
1254
|
|
|
@@ -941,7 +1266,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
941
1266
|
|
|
942
1267
|
}
|
|
943
1268
|
|
|
944
|
-
} else if ( type === 'cubeTexture' ) {
|
|
1269
|
+
} else if ( type === 'cubeTexture' || type === 'cubeDepthTexture' ) {
|
|
945
1270
|
|
|
946
1271
|
texture = new NodeSampledCubeTexture( uniformNode.name, uniformNode.node, group, access );
|
|
947
1272
|
|
|
@@ -955,7 +1280,11 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
955
1280
|
texture.mipLevel = texture.store ? node.mipLevel : 0;
|
|
956
1281
|
texture.setVisibility( gpuShaderStageLib[ shaderStage ] );
|
|
957
1282
|
|
|
958
|
-
|
|
1283
|
+
// Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
|
|
1284
|
+
// Also textureGather always need sampler.
|
|
1285
|
+
const needsSampler = node.value.isCubeTexture === true || ( this.isUnfilterable( node.value ) === false && texture.store === false ) || node.gatherNode !== null;
|
|
1286
|
+
|
|
1287
|
+
if ( needsSampler ) {
|
|
959
1288
|
|
|
960
1289
|
const sampler = new NodeSampler( `${ uniformNode.name }_sampler`, uniformNode.node, group );
|
|
961
1290
|
sampler.setVisibility( gpuShaderStageLib[ shaderStage ] );
|
|
@@ -974,10 +1303,21 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
974
1303
|
|
|
975
1304
|
} else if ( type === 'buffer' || type === 'storageBuffer' || type === 'indirectStorageBuffer' ) {
|
|
976
1305
|
|
|
977
|
-
const
|
|
1306
|
+
const sharedData = this.getSharedDataFromNode( node );
|
|
1307
|
+
|
|
1308
|
+
let buffer = sharedData.buffer;
|
|
1309
|
+
|
|
1310
|
+
if ( buffer === undefined ) {
|
|
1311
|
+
|
|
1312
|
+
const bufferClass = type === 'buffer' ? NodeUniformBuffer : NodeStorageBuffer;
|
|
1313
|
+
|
|
1314
|
+
buffer = new bufferClass( node, group );
|
|
978
1315
|
|
|
979
|
-
|
|
980
|
-
|
|
1316
|
+
sharedData.buffer = buffer;
|
|
1317
|
+
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
buffer.setVisibility( buffer.getVisibility() | gpuShaderStageLib[ shaderStage ] );
|
|
981
1321
|
|
|
982
1322
|
bindings.push( buffer );
|
|
983
1323
|
|
|
@@ -987,16 +1327,19 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
987
1327
|
|
|
988
1328
|
} else {
|
|
989
1329
|
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
let uniformsGroup = uniformsStage[ groupName ];
|
|
1330
|
+
let uniformsGroup = this.uniformGroups[ groupName ];
|
|
993
1331
|
|
|
994
1332
|
if ( uniformsGroup === undefined ) {
|
|
995
1333
|
|
|
996
1334
|
uniformsGroup = new NodeUniformsGroup( groupName, group );
|
|
997
|
-
uniformsGroup.setVisibility(
|
|
1335
|
+
uniformsGroup.setVisibility( GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT | GPUShaderStage.COMPUTE );
|
|
998
1336
|
|
|
999
|
-
|
|
1337
|
+
this.uniformGroups[ groupName ] = uniformsGroup;
|
|
1338
|
+
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// Add to bindings for this stage if not already present
|
|
1342
|
+
if ( bindings.indexOf( uniformsGroup ) === - 1 ) {
|
|
1000
1343
|
|
|
1001
1344
|
bindings.push( uniformsGroup );
|
|
1002
1345
|
|
|
@@ -1004,7 +1347,15 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
1004
1347
|
|
|
1005
1348
|
uniformGPU = this.getNodeUniform( uniformNode, type );
|
|
1006
1349
|
|
|
1007
|
-
|
|
1350
|
+
// Only add uniform if not already present in the group (check by name to avoid duplicates across stages)
|
|
1351
|
+
const uniformName = uniformGPU.name;
|
|
1352
|
+
const alreadyExists = uniformsGroup.uniforms.some( u => u.name === uniformName );
|
|
1353
|
+
|
|
1354
|
+
if ( ! alreadyExists ) {
|
|
1355
|
+
|
|
1356
|
+
uniformsGroup.addUniform( uniformGPU );
|
|
1357
|
+
|
|
1358
|
+
}
|
|
1008
1359
|
|
|
1009
1360
|
}
|
|
1010
1361
|
|
|
@@ -1553,11 +1904,12 @@ ${ flowData.code }
|
|
|
1553
1904
|
* @param {string} type - The variable's type.
|
|
1554
1905
|
* @param {string} name - The variable's name.
|
|
1555
1906
|
* @param {?number} [count=null] - The array length.
|
|
1907
|
+
* @param {string} [qualifier=''] - The variable's qualifier.
|
|
1556
1908
|
* @return {string} The WGSL snippet that defines a variable.
|
|
1557
1909
|
*/
|
|
1558
|
-
getVar( type, name, count = null ) {
|
|
1910
|
+
getVar( type, name, count = null, qualifier = '' ) {
|
|
1559
1911
|
|
|
1560
|
-
let snippet = `var ${ name } : `;
|
|
1912
|
+
let snippet = `var${ qualifier } ${ name } : `;
|
|
1561
1913
|
|
|
1562
1914
|
if ( count !== null ) {
|
|
1563
1915
|
|
|
@@ -1579,7 +1931,15 @@ ${ flowData.code }
|
|
|
1579
1931
|
* @param {string} shaderStage - The shader stage.
|
|
1580
1932
|
* @return {string} The WGSL snippet that defines the variables.
|
|
1581
1933
|
*/
|
|
1582
|
-
getVars( shaderStage ) {
|
|
1934
|
+
getVars( shaderStage, global = false ) {
|
|
1935
|
+
|
|
1936
|
+
let qualifier = '';
|
|
1937
|
+
|
|
1938
|
+
if ( global ) {
|
|
1939
|
+
|
|
1940
|
+
qualifier = '<private>';
|
|
1941
|
+
|
|
1942
|
+
}
|
|
1583
1943
|
|
|
1584
1944
|
const snippets = [];
|
|
1585
1945
|
const vars = this.vars[ shaderStage ];
|
|
@@ -1588,13 +1948,13 @@ ${ flowData.code }
|
|
|
1588
1948
|
|
|
1589
1949
|
for ( const variable of vars ) {
|
|
1590
1950
|
|
|
1591
|
-
snippets.push(
|
|
1951
|
+
snippets.push( `${ this.getVar( variable.type, variable.name, variable.count, qualifier ) };` );
|
|
1592
1952
|
|
|
1593
1953
|
}
|
|
1594
1954
|
|
|
1595
1955
|
}
|
|
1596
1956
|
|
|
1597
|
-
return `\n${ snippets.join( '\n' ) }\n`;
|
|
1957
|
+
return global ? snippets.join( '\n' ) : `\n\t${ snippets.join( '\n\t' ) }\n`;
|
|
1598
1958
|
|
|
1599
1959
|
}
|
|
1600
1960
|
|
|
@@ -1610,7 +1970,7 @@ ${ flowData.code }
|
|
|
1610
1970
|
|
|
1611
1971
|
if ( shaderStage === 'vertex' ) {
|
|
1612
1972
|
|
|
1613
|
-
this.getBuiltin( 'position', '
|
|
1973
|
+
this.getBuiltin( 'position', 'builtinClipSpace', 'vec4<f32>', 'vertex' );
|
|
1614
1974
|
|
|
1615
1975
|
}
|
|
1616
1976
|
|
|
@@ -1619,13 +1979,15 @@ ${ flowData.code }
|
|
|
1619
1979
|
const varyings = this.varyings;
|
|
1620
1980
|
const vars = this.vars[ shaderStage ];
|
|
1621
1981
|
|
|
1982
|
+
let varyingIndex = 0;
|
|
1983
|
+
|
|
1622
1984
|
for ( let index = 0; index < varyings.length; index ++ ) {
|
|
1623
1985
|
|
|
1624
1986
|
const varying = varyings[ index ];
|
|
1625
1987
|
|
|
1626
1988
|
if ( varying.needsInterpolation ) {
|
|
1627
1989
|
|
|
1628
|
-
let attributesSnippet = `@location( ${
|
|
1990
|
+
let attributesSnippet = `@location( ${ varyingIndex ++ } )`;
|
|
1629
1991
|
|
|
1630
1992
|
if ( varying.interpolationType ) {
|
|
1631
1993
|
|
|
@@ -1637,7 +1999,7 @@ ${ flowData.code }
|
|
|
1637
1999
|
|
|
1638
2000
|
} else if ( /^(int|uint|ivec|uvec)/.test( varying.type ) ) {
|
|
1639
2001
|
|
|
1640
|
-
attributesSnippet +=
|
|
2002
|
+
attributesSnippet += ' @interpolate(flat, either)';
|
|
1641
2003
|
|
|
1642
2004
|
}
|
|
1643
2005
|
|
|
@@ -1686,6 +2048,7 @@ ${ flowData.code }
|
|
|
1686
2048
|
*/
|
|
1687
2049
|
getUniforms( shaderStage ) {
|
|
1688
2050
|
|
|
2051
|
+
const backend = this.renderer.backend;
|
|
1689
2052
|
const uniforms = this.uniforms[ shaderStage ];
|
|
1690
2053
|
|
|
1691
2054
|
const bindingSnippets = [];
|
|
@@ -1698,13 +2061,18 @@ ${ flowData.code }
|
|
|
1698
2061
|
const groupName = uniform.groupNode.name;
|
|
1699
2062
|
const uniformIndexes = this.bindingsIndexes[ groupName ];
|
|
1700
2063
|
|
|
1701
|
-
if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
|
|
2064
|
+
if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' || uniform.type === 'cubeDepthTexture' || uniform.type === 'storageTexture' || uniform.type === 'texture3D' ) {
|
|
2065
|
+
|
|
2066
|
+
const textureNode = uniform.node;
|
|
2067
|
+
const texture = textureNode.value;
|
|
1702
2068
|
|
|
1703
|
-
|
|
2069
|
+
// Cube textures always need samplers (they use textureSampleLevel, not textureLoad)
|
|
2070
|
+
// Also textureGather always need sampler.
|
|
2071
|
+
const needsSampler = texture.isCubeTexture === true || ( this.isUnfilterable( texture ) === false && textureNode.isStorageTextureNode !== true ) || textureNode.gatherNode !== null;
|
|
1704
2072
|
|
|
1705
|
-
if (
|
|
2073
|
+
if ( needsSampler ) {
|
|
1706
2074
|
|
|
1707
|
-
if ( this.isSampleCompare( texture ) ) {
|
|
2075
|
+
if ( this.isSampleCompare( texture ) && textureNode.compareNode !== null ) {
|
|
1708
2076
|
|
|
1709
2077
|
bindingSnippets.push( `@binding( ${ uniformIndexes.binding ++ } ) @group( ${ uniformIndexes.group } ) var ${ uniform.name }_sampler : sampler_comparison;` );
|
|
1710
2078
|
|
|
@@ -1720,7 +2088,7 @@ ${ flowData.code }
|
|
|
1720
2088
|
|
|
1721
2089
|
let multisampled = '';
|
|
1722
2090
|
|
|
1723
|
-
const { primarySamples } =
|
|
2091
|
+
const { primarySamples } = backend.utils.getTextureSampleData( texture );
|
|
1724
2092
|
|
|
1725
2093
|
if ( primarySamples > 1 ) {
|
|
1726
2094
|
|
|
@@ -1728,13 +2096,17 @@ ${ flowData.code }
|
|
|
1728
2096
|
|
|
1729
2097
|
}
|
|
1730
2098
|
|
|
1731
|
-
if ( texture.isCubeTexture === true ) {
|
|
2099
|
+
if ( texture.isCubeTexture === true && texture.isDepthTexture === true ) {
|
|
2100
|
+
|
|
2101
|
+
textureType = 'texture_depth_cube';
|
|
2102
|
+
|
|
2103
|
+
} else if ( texture.isCubeTexture === true ) {
|
|
1732
2104
|
|
|
1733
2105
|
textureType = 'texture_cube<f32>';
|
|
1734
2106
|
|
|
1735
2107
|
} else if ( texture.isDepthTexture === true ) {
|
|
1736
2108
|
|
|
1737
|
-
if (
|
|
2109
|
+
if ( backend.compatibilityMode && texture.compareFunction === null ) {
|
|
1738
2110
|
|
|
1739
2111
|
textureType = `texture${ multisampled }_2d<f32>`;
|
|
1740
2112
|
|
|
@@ -1746,7 +2118,7 @@ ${ flowData.code }
|
|
|
1746
2118
|
|
|
1747
2119
|
} else if ( uniform.node.isStorageTextureNode === true ) {
|
|
1748
2120
|
|
|
1749
|
-
const format = getFormat( texture );
|
|
2121
|
+
const format = getFormat( texture, backend.device );
|
|
1750
2122
|
const access = this.getStorageAccess( uniform.node, shaderStage );
|
|
1751
2123
|
|
|
1752
2124
|
const is3D = uniform.node.value.is3DTexture;
|
|
@@ -1797,16 +2169,51 @@ ${ flowData.code }
|
|
|
1797
2169
|
|
|
1798
2170
|
} else {
|
|
1799
2171
|
|
|
1800
|
-
const vectorType = this.getType( this.getVectorType( uniform.type ) );
|
|
1801
2172
|
const groupName = uniform.groupNode.name;
|
|
1802
2173
|
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
2174
|
+
// Check if this group has already been processed in this shader stage
|
|
2175
|
+
if ( uniformGroups[ groupName ] === undefined ) {
|
|
2176
|
+
|
|
2177
|
+
// Get the shared uniform group that contains uniforms from all stages
|
|
2178
|
+
const sharedUniformGroup = this.uniformGroups[ groupName ];
|
|
2179
|
+
|
|
2180
|
+
if ( sharedUniformGroup !== undefined ) {
|
|
1808
2181
|
|
|
1809
|
-
|
|
2182
|
+
// Generate snippets for ALL uniforms in this shared group
|
|
2183
|
+
const snippets = [];
|
|
2184
|
+
|
|
2185
|
+
for ( const sharedUniform of sharedUniformGroup.uniforms ) {
|
|
2186
|
+
|
|
2187
|
+
const type = sharedUniform.getType();
|
|
2188
|
+
const vectorType = this.getType( this.getVectorType( type ) );
|
|
2189
|
+
snippets.push( `\t${ sharedUniform.name } : ${ vectorType }` );
|
|
2190
|
+
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
// Check if this group already has an assigned binding index (from another shader stage)
|
|
2194
|
+
let groupBinding = this.uniformGroupsBindings[ groupName ];
|
|
2195
|
+
|
|
2196
|
+
if ( groupBinding === undefined ) {
|
|
2197
|
+
|
|
2198
|
+
// First time processing this group - assign a new binding index
|
|
2199
|
+
groupBinding = {
|
|
2200
|
+
index: uniformIndexes.binding ++,
|
|
2201
|
+
id: uniformIndexes.group
|
|
2202
|
+
};
|
|
2203
|
+
|
|
2204
|
+
this.uniformGroupsBindings[ groupName ] = groupBinding;
|
|
2205
|
+
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
uniformGroups[ groupName ] = {
|
|
2209
|
+
index: groupBinding.index,
|
|
2210
|
+
id: groupBinding.id,
|
|
2211
|
+
snippets: snippets
|
|
2212
|
+
};
|
|
2213
|
+
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
}
|
|
1810
2217
|
|
|
1811
2218
|
}
|
|
1812
2219
|
|
|
@@ -1820,9 +2227,7 @@ ${ flowData.code }
|
|
|
1820
2227
|
|
|
1821
2228
|
}
|
|
1822
2229
|
|
|
1823
|
-
|
|
1824
|
-
code += bufferSnippets.join( '\n' );
|
|
1825
|
-
code += structSnippets.join( '\n' );
|
|
2230
|
+
const code = [ ...bindingSnippets, ...bufferSnippets, ...structSnippets ].join( '\n' );
|
|
1826
2231
|
|
|
1827
2232
|
return code;
|
|
1828
2233
|
|
|
@@ -1841,12 +2246,14 @@ ${ flowData.code }
|
|
|
1841
2246
|
|
|
1842
2247
|
this.shaderStage = shaderStage;
|
|
1843
2248
|
|
|
2249
|
+
const allowGlobal = this.allowGlobalVariables;
|
|
2250
|
+
|
|
1844
2251
|
const stageData = shadersData[ shaderStage ];
|
|
1845
2252
|
stageData.uniforms = this.getUniforms( shaderStage );
|
|
1846
2253
|
stageData.attributes = this.getAttributes( shaderStage );
|
|
1847
2254
|
stageData.varyings = this.getVaryings( shaderStage );
|
|
1848
2255
|
stageData.structs = this.getStructs( shaderStage );
|
|
1849
|
-
stageData.vars = this.getVars( shaderStage );
|
|
2256
|
+
stageData.vars = this.getVars( shaderStage, allowGlobal );
|
|
1850
2257
|
stageData.codes = this.getCodes( shaderStage );
|
|
1851
2258
|
stageData.directives = this.getDirectives( shaderStage );
|
|
1852
2259
|
stageData.scopedArrays = this.getScopedArrays( shaderStage );
|
|
@@ -1883,7 +2290,7 @@ ${ flowData.code }
|
|
|
1883
2290
|
|
|
1884
2291
|
if ( shaderStage === 'vertex' ) {
|
|
1885
2292
|
|
|
1886
|
-
flow += `varyings.
|
|
2293
|
+
flow += `varyings.builtinClipSpace = ${ flowSlotData.result };`;
|
|
1887
2294
|
|
|
1888
2295
|
} else if ( shaderStage === 'fragment' ) {
|
|
1889
2296
|
|
|
@@ -1896,7 +2303,7 @@ ${ flowData.code }
|
|
|
1896
2303
|
|
|
1897
2304
|
} else {
|
|
1898
2305
|
|
|
1899
|
-
let structSnippet =
|
|
2306
|
+
let structSnippet = `\t@location( 0 ) color: ${ this.getType( this.getOutputType() ) }`;
|
|
1900
2307
|
|
|
1901
2308
|
const builtins = this.getBuiltins( 'output' );
|
|
1902
2309
|
|
|
@@ -1906,7 +2313,7 @@ ${ flowData.code }
|
|
|
1906
2313
|
stageData.structs += this._getWGSLStruct( 'OutputStruct', structSnippet );
|
|
1907
2314
|
stageData.structs += '\nvar<private> output : OutputStruct;';
|
|
1908
2315
|
|
|
1909
|
-
flow += `output.color = ${ flowSlotData.result };\n\n\treturn output;`;
|
|
2316
|
+
flow += `output.color = ${ this.format( flowSlotData.result, mainNode.getNodeType( this ), this.getOutputType() ) };\n\n\treturn output;`;
|
|
1910
2317
|
|
|
1911
2318
|
}
|
|
1912
2319
|
|
|
@@ -1980,6 +2387,30 @@ ${ flowData.code }
|
|
|
1980
2387
|
|
|
1981
2388
|
}
|
|
1982
2389
|
|
|
2390
|
+
/**
|
|
2391
|
+
* Returns the float packing method name for a given numeric encoding.
|
|
2392
|
+
*
|
|
2393
|
+
* @param {string} encoding - The numeric encoding that describes how the float values are mapped to the integer range.
|
|
2394
|
+
* @returns {string} The resolve WGSL float packing method name.
|
|
2395
|
+
*/
|
|
2396
|
+
getFloatPackingMethod( encoding ) {
|
|
2397
|
+
|
|
2398
|
+
return this.getMethod( `floatpack_${ encoding }_2x16` );
|
|
2399
|
+
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
/**
|
|
2403
|
+
* Returns the float unpacking method name for a given numeric encoding.
|
|
2404
|
+
*
|
|
2405
|
+
* @param {string} encoding - The numeric encoding that describes how the integer values are mapped to the float range.
|
|
2406
|
+
* @returns {string} The resolve WGSL float unpacking method name.
|
|
2407
|
+
*/
|
|
2408
|
+
getFloatUnpackingMethod( encoding ) {
|
|
2409
|
+
|
|
2410
|
+
return this.getMethod( `floatunpack_${ encoding }_2x16` );
|
|
2411
|
+
|
|
2412
|
+
}
|
|
2413
|
+
|
|
1983
2414
|
/**
|
|
1984
2415
|
* Returns the native snippet for a ternary operation.
|
|
1985
2416
|
*
|
|
@@ -1994,7 +2425,6 @@ ${ flowData.code }
|
|
|
1994
2425
|
|
|
1995
2426
|
}
|
|
1996
2427
|
|
|
1997
|
-
|
|
1998
2428
|
/**
|
|
1999
2429
|
* Returns the WGSL type of the given node data type.
|
|
2000
2430
|
*
|
|
@@ -2098,15 +2528,15 @@ ${shaderData.uniforms}
|
|
|
2098
2528
|
${shaderData.varyings}
|
|
2099
2529
|
var<private> varyings : VaryingsStruct;
|
|
2100
2530
|
|
|
2531
|
+
// vars
|
|
2532
|
+
${shaderData.vars}
|
|
2533
|
+
|
|
2101
2534
|
// codes
|
|
2102
2535
|
${shaderData.codes}
|
|
2103
2536
|
|
|
2104
2537
|
@vertex
|
|
2105
2538
|
fn main( ${shaderData.attributes} ) -> VaryingsStruct {
|
|
2106
2539
|
|
|
2107
|
-
// vars
|
|
2108
|
-
${shaderData.vars}
|
|
2109
|
-
|
|
2110
2540
|
// flow
|
|
2111
2541
|
${shaderData.flow}
|
|
2112
2542
|
|
|
@@ -2136,15 +2566,15 @@ ${shaderData.structs}
|
|
|
2136
2566
|
// uniforms
|
|
2137
2567
|
${shaderData.uniforms}
|
|
2138
2568
|
|
|
2569
|
+
// vars
|
|
2570
|
+
${shaderData.vars}
|
|
2571
|
+
|
|
2139
2572
|
// codes
|
|
2140
2573
|
${shaderData.codes}
|
|
2141
2574
|
|
|
2142
2575
|
@fragment
|
|
2143
2576
|
fn main( ${shaderData.varyings} ) -> ${shaderData.returnType} {
|
|
2144
2577
|
|
|
2145
|
-
// vars
|
|
2146
|
-
${shaderData.vars}
|
|
2147
|
-
|
|
2148
2578
|
// flow
|
|
2149
2579
|
${shaderData.flow}
|
|
2150
2580
|
|
|
@@ -2181,20 +2611,23 @@ ${ shaderData.structs }
|
|
|
2181
2611
|
// uniforms
|
|
2182
2612
|
${ shaderData.uniforms }
|
|
2183
2613
|
|
|
2614
|
+
// vars
|
|
2615
|
+
${ this.allowGlobalVariables ? shaderData.vars : '' }
|
|
2616
|
+
|
|
2184
2617
|
// codes
|
|
2185
2618
|
${ shaderData.codes }
|
|
2186
2619
|
|
|
2187
2620
|
@compute @workgroup_size( ${ workgroupSizeX }, ${ workgroupSizeY }, ${ workgroupSizeZ } )
|
|
2188
2621
|
fn main( ${ shaderData.attributes } ) {
|
|
2189
2622
|
|
|
2623
|
+
// local vars
|
|
2624
|
+
${ this.allowGlobalVariables ? '' : shaderData.vars }
|
|
2625
|
+
|
|
2190
2626
|
// system
|
|
2191
2627
|
instanceIndex = globalId.x
|
|
2192
2628
|
+ globalId.y * ( ${ workgroupSizeX } * numWorkgroups.x )
|
|
2193
2629
|
+ globalId.z * ( ${ workgroupSizeX } * numWorkgroups.x ) * ( ${ workgroupSizeY } * numWorkgroups.y );
|
|
2194
2630
|
|
|
2195
|
-
// vars
|
|
2196
|
-
${ shaderData.vars }
|
|
2197
|
-
|
|
2198
2631
|
// flow
|
|
2199
2632
|
${ shaderData.flow }
|
|
2200
2633
|
|