@plastic-software/three 0.181.3 → 0.183.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 +11330 -10017
- package/build/three.core.js +10011 -9493
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +1414 -631
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +21 -13
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +8007 -5427
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +8005 -5426
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/Addons.js +0 -3
- package/examples/jsm/animation/CCDIKSolver.js +2 -2
- package/examples/jsm/controls/ArcballControls.js +3 -3
- package/examples/jsm/controls/MapControls.js +55 -1
- package/examples/jsm/controls/OrbitControls.js +109 -6
- package/examples/jsm/controls/TrackballControls.js +6 -6
- package/examples/jsm/csm/CSM.js +2 -1
- package/examples/jsm/effects/AnaglyphEffect.js +102 -7
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/RoomEnvironment.js +3 -0
- package/examples/jsm/exporters/EXRExporter.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +131 -4
- package/examples/jsm/exporters/USDZExporter.js +22 -3
- package/examples/jsm/geometries/DecalGeometry.js +1 -1
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
- package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
- package/examples/jsm/helpers/ViewHelper.js +67 -8
- package/examples/jsm/inspector/Inspector.js +74 -14
- package/examples/jsm/inspector/RendererInspector.js +12 -2
- package/examples/jsm/inspector/tabs/Console.js +41 -7
- package/examples/jsm/inspector/tabs/Parameters.js +18 -2
- package/examples/jsm/inspector/tabs/Performance.js +2 -2
- package/examples/jsm/inspector/tabs/Viewer.js +4 -4
- package/examples/jsm/inspector/ui/Profiler.js +1836 -31
- package/examples/jsm/inspector/ui/Style.js +973 -14
- package/examples/jsm/inspector/ui/Tab.js +188 -1
- package/examples/jsm/inspector/ui/Values.js +17 -1
- package/examples/jsm/libs/meshopt_decoder.module.js +6 -5
- package/examples/jsm/lines/LineMaterial.js +6 -0
- package/examples/jsm/loaders/3DMLoader.js +5 -4
- 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 +5 -5
- package/examples/jsm/loaders/EXRLoader.js +5 -5
- package/examples/jsm/loaders/FBXLoader.js +2 -4
- package/examples/jsm/loaders/GCodeLoader.js +34 -8
- package/examples/jsm/loaders/GLTFLoader.js +122 -171
- package/examples/jsm/loaders/HDRLoader.js +0 -1
- package/examples/jsm/loaders/KMZLoader.js +5 -5
- package/examples/jsm/loaders/KTX2Loader.js +19 -3
- package/examples/jsm/loaders/LDrawLoader.js +2 -3
- package/examples/jsm/loaders/LWOLoader.js +7 -39
- package/examples/jsm/loaders/NRRDLoader.js +2 -2
- package/examples/jsm/loaders/PCDLoader.js +4 -2
- package/examples/jsm/loaders/SVGLoader.js +1 -1
- package/examples/jsm/loaders/TDSLoader.js +0 -2
- package/examples/jsm/loaders/TGALoader.js +0 -2
- package/examples/jsm/loaders/USDLoader.js +100 -40
- package/examples/jsm/loaders/UltraHDRLoader.js +285 -160
- package/examples/jsm/loaders/VOXLoader.js +660 -117
- package/examples/jsm/loaders/VRMLLoader.js +79 -2
- package/examples/jsm/loaders/VTKLoader.js +37 -24
- package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
- package/examples/jsm/loaders/usd/USDAParser.js +447 -366
- package/examples/jsm/loaders/usd/USDCParser.js +1841 -6
- package/examples/jsm/loaders/usd/USDComposer.js +4041 -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/Volume.js +0 -1
- package/examples/jsm/misc/VolumeSlice.js +0 -1
- package/examples/jsm/objects/LensflareMesh.js +1 -1
- package/examples/jsm/objects/Sky.js +76 -4
- package/examples/jsm/objects/SkyMesh.js +127 -10
- package/examples/jsm/objects/Water.js +4 -3
- package/examples/jsm/objects/Water2.js +5 -3
- package/examples/jsm/objects/WaterMesh.js +5 -7
- package/examples/jsm/physics/AmmoPhysics.js +12 -7
- package/examples/jsm/physics/JoltPhysics.js +10 -6
- package/examples/jsm/physics/RapierPhysics.js +9 -5
- 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 +268 -30
- package/examples/jsm/renderers/SVGRenderer.js +193 -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/transpiler/AST.js +44 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
- 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/display/AfterImageNode.js +1 -1
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +458 -16
- package/examples/jsm/tsl/display/AnamorphicNode.js +1 -1
- package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
- package/examples/jsm/tsl/display/BloomNode.js +16 -6
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +1 -1
- package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
- package/examples/jsm/tsl/display/FXAANode.js +2 -2
- package/examples/jsm/tsl/display/GTAONode.js +5 -4
- package/examples/jsm/tsl/display/GaussianBlurNode.js +11 -2
- package/examples/jsm/tsl/display/GodraysNode.js +624 -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 +3 -3
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +7 -6
- package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
- 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 +2 -2
- package/examples/jsm/tsl/display/SSGINode.js +8 -20
- package/examples/jsm/tsl/display/SSRNode.js +8 -8
- package/examples/jsm/tsl/display/SSSNode.js +6 -4
- package/examples/jsm/tsl/display/Shape.js +29 -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/TRAANode.js +273 -125
- 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/math/Bayer.js +40 -1
- package/examples/jsm/utils/LDrawUtils.js +1 -1
- package/examples/jsm/utils/ShadowMapViewer.js +24 -10
- package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
- package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
- package/package.json +20 -26
- package/src/Three.Core.js +2 -1
- package/src/Three.TSL.js +19 -11
- package/src/Three.WebGPU.Nodes.js +2 -0
- package/src/Three.WebGPU.js +3 -0
- package/src/Three.js +1 -0
- package/src/animation/AnimationAction.js +1 -1
- package/src/animation/AnimationClip.js +1 -1
- package/src/animation/AnimationMixer.js +6 -0
- package/src/animation/AnimationUtils.js +1 -12
- package/src/animation/KeyframeTrack.js +47 -8
- 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/AudioListener.js +5 -3
- package/src/cameras/Camera.js +32 -2
- package/src/cameras/CubeCamera.js +20 -0
- package/src/constants.js +90 -5
- package/src/core/BufferGeometry.js +14 -2
- package/src/core/Clock.js +7 -0
- package/src/core/Object3D.js +56 -4
- package/src/core/Raycaster.js +2 -2
- package/src/core/RenderTarget.js +3 -4
- package/src/extras/PMREMGenerator.js +7 -18
- package/src/extras/TextureUtils.js +5 -1
- package/src/geometries/ExtrudeGeometry.js +2 -2
- package/src/geometries/PolyhedronGeometry.js +1 -1
- package/src/geometries/TorusGeometry.js +8 -3
- package/src/helpers/CameraHelper.js +3 -0
- package/src/helpers/DirectionalLightHelper.js +4 -1
- package/src/helpers/HemisphereLightHelper.js +3 -0
- package/src/helpers/PointLightHelper.js +1 -25
- package/src/helpers/SpotLightHelper.js +3 -0
- 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/Cache.js +28 -0
- package/src/loaders/FileLoader.js +1 -1
- package/src/loaders/ImageBitmapLoader.js +8 -3
- package/src/loaders/Loader.js +6 -0
- package/src/loaders/MaterialLoader.js +2 -1
- package/src/loaders/ObjectLoader.js +21 -2
- package/src/loaders/nodes/NodeLoader.js +2 -2
- package/src/materials/Material.js +2 -0
- package/src/materials/MeshLambertMaterial.js +9 -0
- package/src/materials/MeshPhongMaterial.js +9 -0
- package/src/materials/ShaderMaterial.js +20 -1
- package/src/materials/nodes/Line2NodeMaterial.js +7 -7
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +5 -2
- package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
- package/src/materials/nodes/NodeMaterial.js +72 -25
- package/src/materials/nodes/manager/NodeMaterialObserver.js +10 -4
- package/src/math/Line3.js +3 -5
- package/src/math/MathUtils.js +10 -10
- package/src/math/Matrix4.js +74 -65
- package/src/math/Quaternion.js +3 -29
- package/src/math/Sphere.js +1 -1
- package/src/math/Vector3.js +3 -5
- package/src/math/interpolants/BezierInterpolant.js +108 -0
- package/src/nodes/Nodes.js +87 -68
- package/src/nodes/TSL.js +6 -6
- package/src/nodes/accessors/Arrays.js +1 -1
- package/src/nodes/accessors/BatchNode.js +10 -10
- package/src/nodes/accessors/Bitangent.js +5 -5
- package/src/nodes/accessors/BufferAttributeNode.js +98 -12
- package/src/nodes/accessors/BufferNode.js +29 -2
- package/src/nodes/accessors/Camera.js +149 -28
- package/src/nodes/accessors/ClippingNode.js +4 -4
- package/src/nodes/accessors/CubeTextureNode.js +20 -1
- package/src/nodes/accessors/InstanceNode.js +148 -43
- package/src/nodes/accessors/MaterialNode.js +9 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
- package/src/nodes/accessors/ModelNode.js +1 -1
- package/src/nodes/accessors/Normal.js +11 -11
- package/src/nodes/accessors/Position.js +34 -2
- package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
- package/src/nodes/accessors/ReferenceNode.js +4 -4
- package/src/nodes/accessors/RendererReferenceNode.js +1 -2
- package/src/nodes/accessors/SceneProperties.js +53 -0
- package/src/nodes/accessors/SkinningNode.js +27 -26
- package/src/nodes/accessors/StorageBufferNode.js +4 -21
- package/src/nodes/accessors/StorageTextureNode.js +37 -1
- package/src/nodes/accessors/Tangent.js +4 -14
- package/src/nodes/accessors/Texture3DNode.js +32 -35
- package/src/nodes/accessors/TextureNode.js +58 -22
- package/src/nodes/accessors/UniformArrayNode.js +4 -2
- package/src/nodes/accessors/UserDataNode.js +1 -2
- package/src/nodes/accessors/VertexColorNode.js +1 -2
- package/src/nodes/code/FunctionNode.js +1 -2
- package/src/nodes/core/ArrayNode.js +20 -1
- package/src/nodes/core/AssignNode.js +2 -2
- package/src/nodes/core/AttributeNode.js +2 -2
- package/src/nodes/core/ContextNode.js +103 -4
- package/src/nodes/core/MRTNode.js +48 -2
- package/src/nodes/core/Node.js +29 -3
- package/src/nodes/core/NodeBuilder.js +170 -53
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeFrame.js +12 -4
- package/src/nodes/core/NodeUtils.js +10 -8
- package/src/nodes/core/OutputStructNode.js +12 -10
- package/src/nodes/core/ParameterNode.js +3 -3
- package/src/nodes/core/PropertyNode.js +19 -3
- package/src/nodes/core/StackNode.js +65 -16
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +16 -2
- package/src/nodes/core/StructTypeNode.js +11 -17
- package/src/nodes/core/SubBuildNode.js +1 -1
- package/src/nodes/core/UniformNode.js +21 -5
- package/src/nodes/core/VarNode.js +47 -22
- package/src/nodes/core/VaryingNode.js +1 -18
- package/src/nodes/display/BlendModes.js +0 -64
- package/src/nodes/display/ColorAdjustment.js +17 -0
- package/src/nodes/display/ColorSpaceNode.js +3 -3
- package/src/nodes/display/NormalMapNode.js +39 -4
- package/src/nodes/display/PassNode.js +98 -9
- package/src/nodes/display/RenderOutputNode.js +3 -3
- package/src/nodes/display/ScreenNode.js +3 -1
- 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/ViewportTextureNode.js +21 -4
- 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 +1 -1
- package/src/nodes/functions/PhysicalLightingModel.js +126 -45
- package/src/nodes/geometry/RangeNode.js +4 -2
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
- package/src/nodes/gpgpu/ComputeNode.js +5 -4
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +4 -4
- package/src/nodes/lighting/AnalyticLightNode.js +53 -0
- package/src/nodes/lighting/EnvironmentNode.js +28 -3
- package/src/nodes/lighting/LightsNode.js +2 -2
- package/src/nodes/lighting/PointShadowNode.js +162 -149
- package/src/nodes/lighting/ShadowFilterNode.js +53 -65
- package/src/nodes/lighting/ShadowNode.js +97 -41
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/ConditionalNode.js +2 -2
- package/src/nodes/math/MathNode.js +3 -40
- package/src/nodes/math/OperatorNode.js +2 -1
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/pmrem/PMREMNode.js +1 -1
- package/src/nodes/pmrem/PMREMUtils.js +9 -15
- package/src/nodes/tsl/TSLCore.js +17 -14
- package/src/nodes/utils/ArrayElementNode.js +13 -0
- package/src/nodes/utils/DebugNode.js +11 -11
- package/src/nodes/utils/EventNode.js +1 -2
- package/src/nodes/utils/JoinNode.js +2 -2
- package/src/nodes/utils/LoopNode.js +1 -1
- package/src/nodes/utils/MemberNode.js +1 -1
- package/src/nodes/utils/Packing.js +13 -1
- package/src/nodes/utils/PostProcessingUtils.js +33 -1
- package/src/nodes/utils/RTTNode.js +1 -1
- package/src/nodes/utils/ReflectorNode.js +3 -4
- package/src/nodes/utils/SampleNode.js +1 -1
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/UVUtils.js +28 -0
- package/src/objects/BatchedMesh.js +27 -14
- package/src/objects/InstancedMesh.js +11 -0
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/objects/Skeleton.js +9 -0
- package/src/renderers/WebGLRenderer.js +178 -92
- package/src/renderers/common/Backend.js +29 -0
- package/src/renderers/common/Background.js +24 -11
- package/src/renderers/common/BindGroup.js +1 -9
- package/src/renderers/common/Binding.js +11 -0
- package/src/renderers/common/Bindings.js +27 -12
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/Buffer.js +40 -0
- package/src/renderers/common/BundleGroup.js +1 -1
- package/src/renderers/common/ChainMap.js +30 -6
- package/src/renderers/common/CubeRenderTarget.js +50 -6
- package/src/renderers/common/Geometries.js +29 -3
- package/src/renderers/common/Lighting.js +5 -21
- package/src/renderers/common/Pipelines.js +4 -4
- package/src/renderers/common/PostProcessing.js +8 -206
- package/src/renderers/common/RenderBundles.js +2 -1
- package/src/renderers/common/RenderContext.js +16 -0
- package/src/renderers/common/RenderContexts.js +33 -49
- package/src/renderers/common/RenderLists.js +2 -1
- package/src/renderers/common/RenderObject.js +15 -3
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +18 -2
- package/src/renderers/common/RenderPipeline.js +203 -17
- package/src/renderers/common/Renderer.js +257 -72
- package/src/renderers/common/Sampler.js +4 -4
- package/src/renderers/common/StorageBuffer.js +13 -1
- package/src/renderers/common/Textures.js +17 -1
- package/src/renderers/common/TimestampQueryPool.js +5 -3
- package/src/renderers/common/Uniform.js +8 -0
- package/src/renderers/common/UniformsGroup.js +61 -0
- package/src/renderers/common/XRManager.js +3 -2
- package/src/renderers/common/extras/PMREMGenerator.js +2 -8
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +18 -6
- package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -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/envmap_fragment.glsl.js +7 -11
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +112 -51
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +225 -186
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk.js +3 -3
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +7 -5
- package/src/renderers/shaders/UniformsLib.js +0 -3
- package/src/renderers/webgl/WebGLBackground.js +2 -2
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLCapabilities.js +3 -4
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLGeometries.js +10 -7
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLMaterials.js +12 -0
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLOutput.js +267 -0
- package/src/renderers/webgl/WebGLProgram.js +45 -109
- package/src/renderers/webgl/WebGLPrograms.js +45 -49
- package/src/renderers/webgl/WebGLRenderLists.js +15 -0
- package/src/renderers/webgl/WebGLShadowMap.js +188 -24
- package/src/renderers/webgl/WebGLState.js +32 -37
- package/src/renderers/webgl/WebGLTextures.js +89 -28
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUtils.js +6 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +148 -18
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +156 -35
- package/src/renderers/webgl-fallback/utils/WebGLState.js +181 -5
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
- package/src/renderers/webgpu/WebGPUBackend.js +119 -13
- package/src/renderers/webgpu/WebGPURenderer.js +2 -1
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +322 -68
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +357 -200
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +61 -23
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +152 -200
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +65 -42
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
- package/src/renderers/webgpu/utils/WebGPUUtils.js +17 -11
- package/src/renderers/webxr/WebXRManager.js +2 -2
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/Source.js +1 -1
- package/src/textures/Texture.js +3 -3
- package/src/utils.js +258 -3
- 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/src/nodes/accessors/SceneNode.js +0 -145
- 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/SpriteSheetUVNode.js +0 -90
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HalfFloatType, Vector2, RenderTarget, RendererUtils, QuadMesh, NodeMaterial, TempNode, NodeUpdateType, Matrix4, DepthTexture } from 'three/webgpu';
|
|
2
|
-
import { add, float, If,
|
|
2
|
+
import { add, float, If, Fn, max, texture, uniform, uv, vec2, vec4, luminance, convertToTexture, passTexture, velocity, getViewPosition, viewZToPerspectiveDepth, struct, ivec2, mix } from 'three/tsl';
|
|
3
3
|
|
|
4
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
5
|
const _size = /*@__PURE__*/ new Vector2();
|
|
@@ -77,60 +77,62 @@ class TRAANode extends TempNode {
|
|
|
77
77
|
this.velocityNode = velocityNode;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
*
|
|
80
|
+
* The camera the scene is rendered with.
|
|
81
81
|
*
|
|
82
82
|
* @type {Camera}
|
|
83
83
|
*/
|
|
84
84
|
this.camera = camera;
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
87
|
+
* When the difference between the current and previous depth goes above this threshold,
|
|
88
|
+
* the history is considered invalid.
|
|
88
89
|
*
|
|
89
|
-
* @private
|
|
90
90
|
* @type {number}
|
|
91
|
-
* @default 0
|
|
91
|
+
* @default 0.0005
|
|
92
92
|
*/
|
|
93
|
-
this.
|
|
93
|
+
this.depthThreshold = 0.0005;
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
96
|
+
* The depth difference within the 3×3 neighborhood to consider a pixel as an edge.
|
|
97
97
|
*
|
|
98
|
-
* @
|
|
99
|
-
* @
|
|
98
|
+
* @type {number}
|
|
99
|
+
* @default 0.001
|
|
100
100
|
*/
|
|
101
|
-
this.
|
|
101
|
+
this.edgeDepthDiff = 0.001;
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
|
-
*
|
|
104
|
+
* The history becomes invalid as the pixel length of the velocity approaches this value.
|
|
105
105
|
*
|
|
106
|
-
* @
|
|
107
|
-
* @
|
|
106
|
+
* @type {number}
|
|
107
|
+
* @default 128
|
|
108
108
|
*/
|
|
109
|
-
this.
|
|
109
|
+
this.maxVelocityLength = 128;
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
112
|
+
* Whether to decrease the weight on the current frame when the velocity is more subpixel.
|
|
113
|
+
* This reduces blurriness under motion, but can introduce a square pattern artifact.
|
|
113
114
|
*
|
|
114
|
-
* @
|
|
115
|
-
* @
|
|
115
|
+
* @type {boolean}
|
|
116
|
+
* @default true
|
|
116
117
|
*/
|
|
117
|
-
this.
|
|
118
|
+
this.useSubpixelCorrection = true;
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
|
-
*
|
|
121
|
+
* The jitter index selects the current camera offset value.
|
|
121
122
|
*
|
|
122
123
|
* @private
|
|
123
|
-
* @type {
|
|
124
|
+
* @type {number}
|
|
125
|
+
* @default 0
|
|
124
126
|
*/
|
|
125
|
-
this.
|
|
127
|
+
this._jitterIndex = 0;
|
|
126
128
|
|
|
127
129
|
/**
|
|
128
|
-
* A uniform node holding the
|
|
130
|
+
* A uniform node holding the inverse resolution value.
|
|
129
131
|
*
|
|
130
132
|
* @private
|
|
131
|
-
* @type {UniformNode<
|
|
133
|
+
* @type {UniformNode<vec2>}
|
|
132
134
|
*/
|
|
133
|
-
this.
|
|
135
|
+
this._invSize = uniform( new Vector2() );
|
|
134
136
|
|
|
135
137
|
/**
|
|
136
138
|
* The render target that represents the history of frame data.
|
|
@@ -175,6 +177,54 @@ class TRAANode extends TempNode {
|
|
|
175
177
|
*/
|
|
176
178
|
this._originalProjectionMatrix = new Matrix4();
|
|
177
179
|
|
|
180
|
+
/**
|
|
181
|
+
* A uniform node holding the camera's near and far.
|
|
182
|
+
*
|
|
183
|
+
* @private
|
|
184
|
+
* @type {UniformNode<vec2>}
|
|
185
|
+
*/
|
|
186
|
+
this._cameraNearFar = uniform( new Vector2() );
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A uniform node holding the camera world matrix.
|
|
190
|
+
*
|
|
191
|
+
* @private
|
|
192
|
+
* @type {UniformNode<mat4>}
|
|
193
|
+
*/
|
|
194
|
+
this._cameraWorldMatrix = uniform( new Matrix4() );
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* A uniform node holding the camera world matrix inverse.
|
|
198
|
+
*
|
|
199
|
+
* @private
|
|
200
|
+
* @type {UniformNode<mat4>}
|
|
201
|
+
*/
|
|
202
|
+
this._cameraWorldMatrixInverse = uniform( new Matrix4() );
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* A uniform node holding the camera projection matrix inverse.
|
|
206
|
+
*
|
|
207
|
+
* @private
|
|
208
|
+
* @type {UniformNode<mat4>}
|
|
209
|
+
*/
|
|
210
|
+
this._cameraProjectionMatrixInverse = uniform( new Matrix4() );
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* A uniform node holding the previous frame's view matrix.
|
|
214
|
+
*
|
|
215
|
+
* @private
|
|
216
|
+
* @type {UniformNode<mat4>}
|
|
217
|
+
*/
|
|
218
|
+
this._previousCameraWorldMatrix = uniform( new Matrix4() );
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* A uniform node holding the previous frame's projection matrix inverse.
|
|
222
|
+
*
|
|
223
|
+
* @private
|
|
224
|
+
* @type {UniformNode<mat4>}
|
|
225
|
+
*/
|
|
226
|
+
this._previousCameraProjectionMatrixInverse = uniform( new Matrix4() );
|
|
227
|
+
|
|
178
228
|
/**
|
|
179
229
|
* A texture node for the previous depth buffer.
|
|
180
230
|
*
|
|
@@ -247,13 +297,13 @@ class TRAANode extends TempNode {
|
|
|
247
297
|
|
|
248
298
|
};
|
|
249
299
|
|
|
250
|
-
const jitterOffset =
|
|
300
|
+
const jitterOffset = _haltonOffsets[ this._jitterIndex ];
|
|
251
301
|
|
|
252
302
|
this.camera.setViewOffset(
|
|
253
303
|
|
|
254
304
|
viewOffset.fullWidth, viewOffset.fullHeight,
|
|
255
305
|
|
|
256
|
-
viewOffset.offsetX + jitterOffset[ 0 ]
|
|
306
|
+
viewOffset.offsetX + jitterOffset[ 0 ] - 0.5, viewOffset.offsetY + jitterOffset[ 1 ] - 0.5,
|
|
257
307
|
|
|
258
308
|
viewOffset.width, viewOffset.height
|
|
259
309
|
|
|
@@ -273,7 +323,7 @@ class TRAANode extends TempNode {
|
|
|
273
323
|
// update jitter index
|
|
274
324
|
|
|
275
325
|
this._jitterIndex ++;
|
|
276
|
-
this._jitterIndex = this._jitterIndex % (
|
|
326
|
+
this._jitterIndex = this._jitterIndex % ( _haltonOffsets.length - 1 );
|
|
277
327
|
|
|
278
328
|
}
|
|
279
329
|
|
|
@@ -293,7 +343,9 @@ class TRAANode extends TempNode {
|
|
|
293
343
|
|
|
294
344
|
// update camera matrices uniforms
|
|
295
345
|
|
|
346
|
+
this._cameraNearFar.value.set( this.camera.near, this.camera.far );
|
|
296
347
|
this._cameraWorldMatrix.value.copy( this.camera.matrixWorld );
|
|
348
|
+
this._cameraWorldMatrixInverse.value.copy( this.camera.matrixWorldInverse );
|
|
297
349
|
this._cameraProjectionMatrixInverse.value.copy( this.camera.projectionMatrixInverse );
|
|
298
350
|
|
|
299
351
|
// keep the TRAA in sync with the dimensions of the beauty node
|
|
@@ -324,13 +376,10 @@ class TRAANode extends TempNode {
|
|
|
324
376
|
|
|
325
377
|
if ( needsRestart === true ) {
|
|
326
378
|
|
|
327
|
-
//
|
|
379
|
+
// make sure render targets are initialized after the resize which triggers a dispose()
|
|
328
380
|
|
|
329
|
-
renderer.
|
|
330
|
-
renderer.
|
|
331
|
-
|
|
332
|
-
renderer.setRenderTarget( this._resolveRenderTarget );
|
|
333
|
-
renderer.clear();
|
|
381
|
+
renderer.initRenderTarget( this._historyRenderTarget );
|
|
382
|
+
renderer.initRenderTarget( this._resolveRenderTarget );
|
|
334
383
|
|
|
335
384
|
// make sure to reset the history with the contents of the beauty buffer otherwise subsequent frames after the
|
|
336
385
|
// resize will fade from a darker color to the correct one because the history was cleared with black.
|
|
@@ -382,20 +431,20 @@ class TRAANode extends TempNode {
|
|
|
382
431
|
*/
|
|
383
432
|
setup( builder ) {
|
|
384
433
|
|
|
385
|
-
const
|
|
434
|
+
const renderPipeline = builder.context.renderPipeline;
|
|
386
435
|
|
|
387
|
-
if (
|
|
436
|
+
if ( renderPipeline ) {
|
|
388
437
|
|
|
389
438
|
this._needsPostProcessingSync = true;
|
|
390
439
|
|
|
391
|
-
|
|
440
|
+
renderPipeline.context.onBeforeRenderPipeline = () => {
|
|
392
441
|
|
|
393
442
|
const size = builder.renderer.getDrawingBufferSize( _size );
|
|
394
443
|
this.setViewOffset( size.width, size.height );
|
|
395
444
|
|
|
396
445
|
};
|
|
397
446
|
|
|
398
|
-
|
|
447
|
+
renderPipeline.context.onAfterRenderPipeline = () => {
|
|
399
448
|
|
|
400
449
|
this.clearViewOffset();
|
|
401
450
|
|
|
@@ -403,123 +452,217 @@ class TRAANode extends TempNode {
|
|
|
403
452
|
|
|
404
453
|
}
|
|
405
454
|
|
|
406
|
-
const
|
|
407
|
-
const sampleTexture = this.beautyNode;
|
|
408
|
-
const depthTexture = this.depthNode;
|
|
409
|
-
const velocityTexture = this.velocityNode;
|
|
455
|
+
const currentDepthStruct = struct( {
|
|
410
456
|
|
|
411
|
-
|
|
457
|
+
closestDepth: 'float',
|
|
458
|
+
closestPositionTexel: 'vec2',
|
|
459
|
+
farthestDepth: 'float',
|
|
412
460
|
|
|
413
|
-
|
|
461
|
+
} );
|
|
414
462
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const closestDepth = float( 1 ).toVar();
|
|
418
|
-
const farthestDepth = float( 0 ).toVar();
|
|
419
|
-
const closestDepthPixelPosition = vec2( 0 ).toVar();
|
|
463
|
+
// Samples 3×3 neighborhood pixels and returns the closest and farthest depths.
|
|
464
|
+
const sampleCurrentDepth = Fn( ( [ positionTexel ] ) => {
|
|
420
465
|
|
|
421
|
-
|
|
422
|
-
|
|
466
|
+
const closestDepth = float( 2 ).toVar();
|
|
467
|
+
const closestPositionTexel = vec2( 0 ).toVar();
|
|
468
|
+
const farthestDepth = float( - 1 ).toVar();
|
|
423
469
|
|
|
424
|
-
|
|
470
|
+
for ( let x = - 1; x <= 1; ++ x ) {
|
|
425
471
|
|
|
426
|
-
|
|
472
|
+
for ( let y = - 1; y <= 1; ++ y ) {
|
|
427
473
|
|
|
428
|
-
const
|
|
429
|
-
const
|
|
474
|
+
const neighbor = positionTexel.add( vec2( x, y ) ).toVar();
|
|
475
|
+
const depth = this.depthNode.load( neighbor ).r.toVar();
|
|
430
476
|
|
|
431
|
-
|
|
432
|
-
maxColor.assign( max( maxColor, colorNeighbor ) );
|
|
477
|
+
If( depth.lessThan( closestDepth ), () => {
|
|
433
478
|
|
|
434
|
-
|
|
479
|
+
closestDepth.assign( depth );
|
|
480
|
+
closestPositionTexel.assign( neighbor );
|
|
435
481
|
|
|
436
|
-
|
|
482
|
+
} );
|
|
437
483
|
|
|
438
|
-
If(
|
|
484
|
+
If( depth.greaterThan( farthestDepth ), () => {
|
|
439
485
|
|
|
440
|
-
|
|
441
|
-
closestDepthPixelPosition.assign( uvNeighbor );
|
|
486
|
+
farthestDepth.assign( depth );
|
|
442
487
|
|
|
443
488
|
} );
|
|
444
489
|
|
|
445
|
-
|
|
490
|
+
}
|
|
446
491
|
|
|
447
|
-
|
|
492
|
+
}
|
|
448
493
|
|
|
449
|
-
|
|
494
|
+
return currentDepthStruct( closestDepth, closestPositionTexel, farthestDepth );
|
|
450
495
|
|
|
451
|
-
|
|
496
|
+
} );
|
|
452
497
|
|
|
453
|
-
|
|
498
|
+
// Samples a previous depth and reproject it using the current camera matrices.
|
|
499
|
+
const samplePreviousDepth = ( uv ) => {
|
|
454
500
|
|
|
455
|
-
|
|
501
|
+
const depth = this._previousDepthNode.sample( uv ).r;
|
|
502
|
+
const positionView = getViewPosition( uv, depth, this._previousCameraProjectionMatrixInverse );
|
|
503
|
+
const positionWorld = this._previousCameraWorldMatrix.mul( vec4( positionView, 1 ) ).xyz;
|
|
504
|
+
const viewZ = this._cameraWorldMatrixInverse.mul( vec4( positionWorld, 1 ) ).z;
|
|
505
|
+
return viewZToPerspectiveDepth( viewZ, this._cameraNearFar.x, this._cameraNearFar.y );
|
|
456
506
|
|
|
457
|
-
|
|
507
|
+
};
|
|
458
508
|
|
|
459
|
-
|
|
509
|
+
// Optimized version of AABB clipping.
|
|
510
|
+
// Reference: https://github.com/playdeadgames/temporal
|
|
511
|
+
const clipAABB = Fn( ( [ currentColor, historyColor, minColor, maxColor ] ) => {
|
|
512
|
+
|
|
513
|
+
const pClip = maxColor.rgb.add( minColor.rgb ).mul( 0.5 );
|
|
514
|
+
const eClip = maxColor.rgb.sub( minColor.rgb ).mul( 0.5 ).add( 1e-7 );
|
|
515
|
+
const vClip = historyColor.sub( vec4( pClip, currentColor.a ) );
|
|
516
|
+
const vUnit = vClip.xyz.div( eClip );
|
|
517
|
+
const absUnit = vUnit.abs();
|
|
518
|
+
const maxUnit = max( absUnit.x, absUnit.y, absUnit.z );
|
|
519
|
+
return maxUnit.greaterThan( 1 ).select(
|
|
520
|
+
vec4( pClip, currentColor.a ).add( vClip.div( maxUnit ) ),
|
|
521
|
+
historyColor
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
} ).setLayout( {
|
|
525
|
+
name: 'clipAABB',
|
|
526
|
+
type: 'vec4',
|
|
527
|
+
inputs: [
|
|
528
|
+
{ name: 'currentColor', type: 'vec4' },
|
|
529
|
+
{ name: 'historyColor', type: 'vec4' },
|
|
530
|
+
{ name: 'minColor', type: 'vec4' },
|
|
531
|
+
{ name: 'maxColor', type: 'vec4' }
|
|
532
|
+
]
|
|
533
|
+
} );
|
|
460
534
|
|
|
461
|
-
|
|
462
|
-
|
|
535
|
+
// Performs variance clipping.
|
|
536
|
+
// See: https://developer.download.nvidia.com/gameworks/events/GDC2016/msalvi_temporal_supersampling.pdf
|
|
537
|
+
const varianceClipping = Fn( ( [ positionTexel, currentColor, historyColor, gamma ] ) => {
|
|
463
538
|
|
|
464
|
-
|
|
539
|
+
const offsets = [
|
|
540
|
+
[ - 1, - 1 ],
|
|
541
|
+
[ - 1, 1 ],
|
|
542
|
+
[ 1, - 1 ],
|
|
543
|
+
[ 1, 1 ],
|
|
544
|
+
[ 1, 0 ],
|
|
545
|
+
[ 0, - 1 ],
|
|
546
|
+
[ 0, 1 ],
|
|
547
|
+
[ - 1, 0 ]
|
|
548
|
+
];
|
|
465
549
|
|
|
466
|
-
const
|
|
550
|
+
const moment1 = currentColor.toVar();
|
|
551
|
+
const moment2 = currentColor.pow2().toVar();
|
|
467
552
|
|
|
468
|
-
|
|
553
|
+
for ( const [ x, y ] of offsets ) {
|
|
469
554
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
555
|
+
// Use max() to prevent NaN values from propagating.
|
|
556
|
+
const neighbor = this.beautyNode.offset( ivec2( x, y ) ).load( positionTexel ).max( 0 );
|
|
557
|
+
moment1.addAssign( neighbor );
|
|
558
|
+
moment2.addAssign( neighbor.pow2() );
|
|
473
559
|
|
|
474
|
-
|
|
560
|
+
}
|
|
475
561
|
|
|
476
|
-
const
|
|
477
|
-
const
|
|
478
|
-
const
|
|
479
|
-
const
|
|
562
|
+
const N = float( offsets.length + 1 );
|
|
563
|
+
const mean = moment1.div( N );
|
|
564
|
+
const variance = moment2.div( N ).sub( mean.pow2() ).max( 0 ).sqrt().mul( gamma );
|
|
565
|
+
const minColor = mean.sub( variance );
|
|
566
|
+
const maxColor = mean.add( variance );
|
|
480
567
|
|
|
481
|
-
|
|
568
|
+
return clipAABB( mean.clamp( minColor, maxColor ), historyColor, minColor, maxColor );
|
|
482
569
|
|
|
483
|
-
|
|
484
|
-
worldPositionDifference.assign( min( max( worldPositionDifference.sub( 1.0 ), 0.0 ), 1.0 ) );
|
|
570
|
+
} );
|
|
485
571
|
|
|
486
|
-
|
|
487
|
-
|
|
572
|
+
// Returns the amount of subpixel (expressed within [0, 1]) in the velocity.
|
|
573
|
+
const subpixelCorrection = Fn( ( [ velocityUV, textureSize ] ) => {
|
|
574
|
+
|
|
575
|
+
const velocityTexel = velocityUV.mul( textureSize );
|
|
576
|
+
const phase = velocityTexel.fract().abs();
|
|
577
|
+
const weight = max( phase, phase.oneMinus() );
|
|
578
|
+
return weight.x.mul( weight.y ).oneMinus().div( 0.75 );
|
|
579
|
+
|
|
580
|
+
} ).setLayout( {
|
|
581
|
+
name: 'subpixelCorrection',
|
|
582
|
+
type: 'float',
|
|
583
|
+
inputs: [
|
|
584
|
+
{ name: 'velocityUV', type: 'vec2' },
|
|
585
|
+
{ name: 'textureSize', type: 'ivec2' }
|
|
586
|
+
]
|
|
587
|
+
} );
|
|
488
588
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
motionFactor.assign( min( motionFactor, 1.0 ) );
|
|
589
|
+
// Flicker reduction based on luminance weighing.
|
|
590
|
+
const flickerReduction = Fn( ( [ currentColor, historyColor, currentWeight ] ) => {
|
|
492
591
|
|
|
493
|
-
const
|
|
494
|
-
const
|
|
592
|
+
const historyWeight = currentWeight.oneMinus();
|
|
593
|
+
const compressedCurrent = currentColor.mul( float( 1 ).div( ( max( currentColor.r, currentColor.g, currentColor.b ).add( 1 ) ) ) );
|
|
594
|
+
const compressedHistory = historyColor.mul( float( 1 ).div( ( max( historyColor.r, historyColor.g, historyColor.b ).add( 1 ) ) ) );
|
|
495
595
|
|
|
496
|
-
|
|
497
|
-
|
|
596
|
+
const luminanceCurrent = luminance( compressedCurrent.rgb );
|
|
597
|
+
const luminanceHistory = luminance( compressedHistory.rgb );
|
|
498
598
|
|
|
499
|
-
|
|
500
|
-
|
|
599
|
+
currentWeight.mulAssign( float( 1 ).div( luminanceCurrent.add( 1 ) ) );
|
|
600
|
+
historyWeight.mulAssign( float( 1 ).div( luminanceHistory.add( 1 ) ) );
|
|
501
601
|
|
|
502
|
-
|
|
602
|
+
return add( currentColor.mul( currentWeight ), historyColor.mul( historyWeight ) ).div( max( currentWeight.add( historyWeight ), 0.00001 ) ).toVar();
|
|
503
603
|
|
|
504
|
-
|
|
505
|
-
historyWeight.assign( 0.0 );
|
|
604
|
+
} );
|
|
506
605
|
|
|
507
|
-
|
|
606
|
+
const historyNode = texture( this._historyRenderTarget.texture );
|
|
508
607
|
|
|
509
|
-
|
|
608
|
+
const resolve = Fn( () => {
|
|
510
609
|
|
|
511
|
-
const
|
|
512
|
-
const
|
|
610
|
+
const uvNode = uv();
|
|
611
|
+
const textureSize = this.beautyNode.size(); // Assumes all the buffers share the same size.
|
|
612
|
+
const positionTexel = uvNode.mul( textureSize );
|
|
513
613
|
|
|
514
|
-
|
|
515
|
-
|
|
614
|
+
// sample the closest and farthest depths in the current buffer
|
|
615
|
+
|
|
616
|
+
const currentDepth = sampleCurrentDepth( positionTexel );
|
|
617
|
+
const closestDepth = currentDepth.get( 'closestDepth' );
|
|
618
|
+
const closestPositionTexel = currentDepth.get( 'closestPositionTexel' );
|
|
619
|
+
const farthestDepth = currentDepth.get( 'farthestDepth' );
|
|
620
|
+
|
|
621
|
+
// convert the NDC offset to UV offset
|
|
622
|
+
|
|
623
|
+
const offsetUV = this.velocityNode.load( closestPositionTexel ).xy.mul( vec2( 0.5, - 0.5 ) );
|
|
624
|
+
|
|
625
|
+
// sample the previous depth
|
|
626
|
+
|
|
627
|
+
const historyUV = uvNode.sub( offsetUV );
|
|
628
|
+
const previousDepth = samplePreviousDepth( historyUV );
|
|
629
|
+
|
|
630
|
+
// history is considered valid when the UV is in range and there's no disocclusion except on edges
|
|
631
|
+
|
|
632
|
+
const isValidUV = historyUV.greaterThanEqual( 0 ).all().and( historyUV.lessThanEqual( 1 ).all() );
|
|
633
|
+
const isEdge = farthestDepth.sub( closestDepth ).greaterThan( this.edgeDepthDiff );
|
|
634
|
+
const isDisocclusion = closestDepth.sub( previousDepth ).greaterThan( this.depthThreshold );
|
|
635
|
+
const hasValidHistory = isValidUV.and( isEdge.or( isDisocclusion.not() ) );
|
|
636
|
+
|
|
637
|
+
// sample the current and previous colors
|
|
638
|
+
|
|
639
|
+
const currentColor = this.beautyNode.sample( uvNode );
|
|
640
|
+
const historyColor = historyNode.sample( uvNode.sub( offsetUV ) );
|
|
641
|
+
|
|
642
|
+
// increase the weight towards the current frame under motion
|
|
643
|
+
|
|
644
|
+
const motionFactor = uvNode.sub( historyUV ).mul( textureSize ).length().div( this.maxVelocityLength ).saturate();
|
|
645
|
+
const currentWeight = float( 0.05 ).toVar(); // A minimum weight
|
|
516
646
|
|
|
517
|
-
|
|
518
|
-
historyWeight.mulAssign( float( 1.0 ).div( luminanceHistory.add( 1 ) ) );
|
|
647
|
+
if ( this.useSubpixelCorrection ) {
|
|
519
648
|
|
|
520
|
-
|
|
649
|
+
// Increase the minimum weight towards the current frame when the velocity is more subpixel.
|
|
650
|
+
currentWeight.addAssign( subpixelCorrection( offsetUV, textureSize ).mul( 0.25 ) );
|
|
521
651
|
|
|
522
|
-
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
currentWeight.assign( hasValidHistory.select( currentWeight.add( motionFactor ).saturate(), 1 ) );
|
|
655
|
+
|
|
656
|
+
// Perform neighborhood clipping/clamping. We use variance clipping here.
|
|
657
|
+
|
|
658
|
+
const varianceGamma = mix( 0.5, 1, motionFactor.oneMinus().pow2() ); // Reasonable gamma range is [0.75, 2]
|
|
659
|
+
const clippedHistoryColor = varianceClipping( positionTexel, currentColor, historyColor, varianceGamma );
|
|
660
|
+
|
|
661
|
+
// flicker reduction based on luminance weighing
|
|
662
|
+
|
|
663
|
+
const output = flickerReduction( currentColor, clippedHistoryColor, currentWeight );
|
|
664
|
+
|
|
665
|
+
return output;
|
|
523
666
|
|
|
524
667
|
} );
|
|
525
668
|
|
|
@@ -548,21 +691,26 @@ class TRAANode extends TempNode {
|
|
|
548
691
|
|
|
549
692
|
export default TRAANode;
|
|
550
693
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
694
|
+
function _halton( index, base ) {
|
|
695
|
+
|
|
696
|
+
let fraction = 1;
|
|
697
|
+
let result = 0;
|
|
698
|
+
while ( index > 0 ) {
|
|
699
|
+
|
|
700
|
+
fraction /= base;
|
|
701
|
+
result += fraction * ( index % base );
|
|
702
|
+
index = Math.floor( index / base );
|
|
703
|
+
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
return result;
|
|
707
|
+
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
const _haltonOffsets = /*@__PURE__*/ Array.from(
|
|
711
|
+
{ length: 32 },
|
|
712
|
+
( _, index ) => [ _halton( index + 1, 2 ), _halton( index + 1, 3 ) ]
|
|
713
|
+
);
|
|
566
714
|
|
|
567
715
|
/**
|
|
568
716
|
* TSL function for creating a TRAA node for Temporal Reprojection Anti-Aliasing.
|
|
@@ -575,4 +723,4 @@ const _JitterVectors = [
|
|
|
575
723
|
* @param {Camera} camera - The camera the scene is rendered with.
|
|
576
724
|
* @returns {TRAANode}
|
|
577
725
|
*/
|
|
578
|
-
export const traa = ( beautyNode, depthNode, velocityNode, camera ) =>
|
|
726
|
+
export const traa = ( beautyNode, depthNode, velocityNode, camera ) => new TRAANode( convertToTexture( beautyNode ), depthNode, velocityNode, camera );
|
|
@@ -138,4 +138,4 @@ export default TransitionNode;
|
|
|
138
138
|
* @param {Node<float> | number} useTexture - Whether `mixTextureNode` should influence the transition or not.
|
|
139
139
|
* @returns {TransitionNode}
|
|
140
140
|
*/
|
|
141
|
-
export const transition = ( nodeA, nodeB, mixTextureNode, mixRatio, threshold, useTexture ) =>
|
|
141
|
+
export const transition = ( nodeA, nodeB, mixTextureNode, mixRatio, threshold, useTexture ) => new TransitionNode( convertToTexture( nodeA ), convertToTexture( nodeB ), convertToTexture( mixTextureNode ), nodeObject( mixRatio ), nodeObject( threshold ), nodeObject( useTexture ) );
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { abs, color, float, Fn, Loop, mix, nodeObject, perspectiveDepthToViewZ, reference, textureSize, uv, vec2, vec4, viewZToOrthographicDepth, int, If, array, ivec2 } from 'three/tsl';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Performs a depth-aware blend between a base scene and a secondary effect (like godrays).
|
|
5
|
+
* This function uses a Poisson disk sampling pattern to detect depth discontinuities
|
|
6
|
+
* in the neighborhood of the current pixel. If an edge is detected, it shifts the
|
|
7
|
+
* sampling coordinate for the blend node away from the edge to prevent light leaking/haloing.
|
|
8
|
+
*
|
|
9
|
+
* @param {Node} baseNode - The main scene/beauty pass texture node.
|
|
10
|
+
* @param {Node} blendNode - The effect to be blended (e.g., Godrays, Bloom).
|
|
11
|
+
* @param {Node} depthNode - The scene depth texture node.
|
|
12
|
+
* @param {Camera} camera - The camera used for the scene.
|
|
13
|
+
* @param {Object} [options={}] - Configuration for the blend effect.
|
|
14
|
+
* @param {Node|Color} [options.blendColor=Color(0xff0000)] - The color applied to the blend node.
|
|
15
|
+
* @param {Node<int> | number} [options.edgeRadius=2] - The search radius (in pixels) for detecting depth edges.
|
|
16
|
+
* @param {Node<float> | number} [options.edgeStrength=2] - How far to "push" the UV away from detected edges.
|
|
17
|
+
* @returns {Node<vec4>} The resulting blended color node.
|
|
18
|
+
*/
|
|
19
|
+
export const depthAwareBlend = /*#__PURE__*/ Fn( ( [ baseNode, blendNode, depthNode, camera, options = {} ] ) => {
|
|
20
|
+
|
|
21
|
+
const uvNode = baseNode.uvNode || uv();
|
|
22
|
+
|
|
23
|
+
const cameraNear = reference( 'near', 'float', camera );
|
|
24
|
+
const cameraFar = reference( 'far', 'float', camera );
|
|
25
|
+
|
|
26
|
+
const blendColor = nodeObject( options.blendColor ) || color( 0xffffff );
|
|
27
|
+
const edgeRadius = nodeObject( options.edgeRadius ) || int( 2 );
|
|
28
|
+
const edgeStrength = nodeObject( options.edgeStrength ) || float( 2 );
|
|
29
|
+
|
|
30
|
+
const viewZ = perspectiveDepthToViewZ( depthNode, cameraNear, cameraFar );
|
|
31
|
+
const correctDepth = viewZToOrthographicDepth( viewZ, cameraNear, cameraFar );
|
|
32
|
+
|
|
33
|
+
const pushDir = vec2( 0.0 ).toVar();
|
|
34
|
+
const count = float( 0 ).toVar();
|
|
35
|
+
|
|
36
|
+
const resolution = ivec2( textureSize( baseNode ) ).toConst();
|
|
37
|
+
const pixelStep = vec2( 1 ).div( resolution );
|
|
38
|
+
|
|
39
|
+
const poissonDisk = array( [
|
|
40
|
+
vec2( 0.493393, 0.394269 ),
|
|
41
|
+
vec2( 0.798547, 0.885922 ),
|
|
42
|
+
vec2( 0.259143, 0.650754 ),
|
|
43
|
+
vec2( 0.605322, 0.023588 ),
|
|
44
|
+
vec2( - 0.574681, 0.137452 ),
|
|
45
|
+
vec2( - 0.430397, - 0.638423 ),
|
|
46
|
+
vec2( - 0.849487, - 0.366258 ),
|
|
47
|
+
vec2( 0.170621, - 0.569941 )
|
|
48
|
+
] );
|
|
49
|
+
|
|
50
|
+
Loop( 8, ( { i } ) => {
|
|
51
|
+
|
|
52
|
+
const offset = poissonDisk.element( i ).mul( edgeRadius );
|
|
53
|
+
|
|
54
|
+
const sampleUv = uvNode.add( offset.mul( pixelStep ) );
|
|
55
|
+
const sampleDepth = depthNode.sample( sampleUv );
|
|
56
|
+
|
|
57
|
+
const sampleViewZ = perspectiveDepthToViewZ( sampleDepth, cameraNear, cameraFar );
|
|
58
|
+
const sampleLinearDepth = viewZToOrthographicDepth( sampleViewZ, cameraNear, cameraFar );
|
|
59
|
+
|
|
60
|
+
If( abs( sampleLinearDepth.sub( correctDepth ) ).lessThan( float( 0.05 ).mul( correctDepth ) ), () => {
|
|
61
|
+
|
|
62
|
+
pushDir.addAssign( offset );
|
|
63
|
+
count.addAssign( 1 );
|
|
64
|
+
|
|
65
|
+
} );
|
|
66
|
+
|
|
67
|
+
} );
|
|
68
|
+
|
|
69
|
+
count.assign( count.equal( 0 ).select( 1, count ) );
|
|
70
|
+
|
|
71
|
+
pushDir.divAssign( count ).normalize();
|
|
72
|
+
|
|
73
|
+
const sampleUv = pushDir.length().greaterThan( 0 ).select( uvNode.add( edgeStrength.mul( pushDir.div( resolution ) ) ), uvNode );
|
|
74
|
+
|
|
75
|
+
const bestChoice = blendNode.sample( sampleUv ).r;
|
|
76
|
+
const baseColor = baseNode.sample( uvNode );
|
|
77
|
+
|
|
78
|
+
return vec4( mix( baseColor, vec4( blendColor, 1 ), bestChoice ) );
|
|
79
|
+
|
|
80
|
+
} );
|