@gnsx/three 0.185.16 → 0.186.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/build/three.cjs +10 -82600
- package/build/three.core.js +1309 -807
- package/build/three.module.js +439 -338
- package/build/three.tsl.js +74 -44
- package/build/three.webgpu.js +6036 -2184
- package/build/three.webgpu.nodes.js +6020 -2184
- package/examples/jsm/Addons.js +6 -6
- package/examples/jsm/controls/ArcballControls.js +1 -1
- package/examples/jsm/controls/FirstPersonControls.js +44 -20
- package/examples/jsm/controls/OrbitControls.js +9 -0
- package/examples/jsm/controls/TrackballControls.js +109 -4
- package/examples/jsm/csm/CSMShadowNode.js +13 -0
- package/examples/jsm/exporters/GLTFExporter.js +23 -7
- package/examples/jsm/exporters/USDZExporter.js +2 -2
- package/examples/jsm/generators/CityGenerator.js +377 -45
- package/examples/jsm/generators/ForestGenerator.js +12 -12
- package/examples/jsm/generators/TerrainGenerator.js +49 -37
- package/examples/jsm/generators/TreeGenerator.js +70 -76
- package/examples/jsm/generators/city/BenchGenerator.js +127 -0
- package/examples/jsm/generators/city/CarGenerator.js +479 -0
- package/examples/jsm/generators/city/CityGeneratorUtils.js +31 -0
- package/examples/jsm/generators/city/HydrantGenerator.js +106 -0
- package/examples/jsm/generators/city/InstancedMeshGenerator.js +86 -0
- package/examples/jsm/generators/city/PersonGenerator.js +447 -0
- package/examples/jsm/generators/city/SidewalkGenerator.js +33 -38
- package/examples/jsm/generators/city/SkyscraperGenerator.js +448 -48
- package/examples/jsm/generators/city/StreetTreeGenerator.js +231 -0
- package/examples/jsm/generators/city/StreetlightGenerator.js +100 -0
- package/examples/jsm/generators/city/TrafficlightGenerator.js +106 -0
- package/examples/jsm/generators/city/TrashcanGenerator.js +100 -0
- package/examples/jsm/geometries/BoxLineGeometry.js +1 -1
- package/examples/jsm/geometries/ParametricGeometry.js +1 -1
- package/examples/jsm/geometries/RoundedBoxGeometry.js +1 -1
- package/examples/jsm/gpgpu/CountingSort.js +271 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +60 -239
- package/examples/jsm/helpers/LightProbeGridHelperWebGL.js +221 -0
- package/examples/jsm/inspector/Extension.js +94 -0
- package/examples/jsm/inspector/Inspector.js +145 -41
- package/examples/jsm/inspector/RendererInspector.js +100 -52
- package/examples/jsm/inspector/extensions/color-grading/ColorGrading.js +2609 -0
- package/examples/jsm/inspector/extensions/color-grading/ColorWheel.js +352 -0
- package/examples/jsm/inspector/extensions/color-grading/CurveEditor.js +599 -0
- package/examples/jsm/inspector/extensions/color-grading/LUT3DStyle.js +1201 -0
- package/examples/jsm/inspector/extensions/color-grading/LUTMath.js +788 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/BrightnessModule.js +72 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ColorWheelModule.js +112 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ContrastModule.js +82 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/CurvesModule.js +109 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ExposureHueModule.js +110 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ExposureModule.js +73 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/HueModule.js +78 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ImportedCubeModule.js +89 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/Module.js +285 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/OutputModule.js +101 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/RendererModule.js +225 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/SatVibranceModule.js +102 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/SaturationModule.js +76 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/VibranceModule.js +76 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/WhiteBalanceModule.js +86 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +26 -31
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +1 -0
- package/examples/jsm/inspector/tabs/Memory.js +0 -2
- package/examples/jsm/inspector/tabs/Settings.js +4 -0
- package/examples/jsm/inspector/tabs/Timeline.js +223 -171
- package/examples/jsm/inspector/tabs/Viewer.js +515 -21
- package/examples/jsm/inspector/ui/List.js +15 -9
- package/examples/jsm/inspector/ui/Profiler.js +170 -14
- package/examples/jsm/inspector/ui/Style.js +269 -23
- package/examples/jsm/inspector/ui/Tab.js +2 -0
- package/examples/jsm/inspector/ui/Values.js +14 -2
- package/examples/jsm/interactive/HTMLMesh.js +19 -3
- package/examples/jsm/lighting/LightProbeGrid.js +484 -889
- package/examples/jsm/lighting/LightProbeGridUtils.js +107 -0
- package/examples/jsm/lighting/LightProbeGridWebGL.js +841 -0
- package/examples/jsm/lighting/vxgi/VXGIConeTracer.js +194 -0
- package/examples/jsm/lighting/vxgi/VXGINode.js +660 -0
- package/examples/jsm/lighting/vxgi/VXGISceneCollector.js +478 -0
- package/examples/jsm/lighting/vxgi/VXGIVolume.js +1430 -0
- package/examples/jsm/lights/SunLight.js +95 -0
- package/examples/jsm/lights/SunLightNode.js +56 -0
- package/examples/jsm/lights/SunLightShadow.js +319 -0
- package/examples/jsm/lights/SunShadowNode.js +312 -0
- package/examples/jsm/loaders/3DMLoader.js +150 -49
- package/examples/jsm/loaders/3MFLoader.js +202 -1
- package/examples/jsm/loaders/FBXLoader.js +81 -5
- package/examples/jsm/loaders/GLTFGaussianSplatLoaderExtension.js +330 -0
- package/examples/jsm/loaders/GLTFLoader.js +79 -14
- package/examples/jsm/loaders/GaussianSplatPLYLoader.js +386 -0
- package/examples/jsm/loaders/KSPLATLoader.js +463 -0
- package/examples/jsm/loaders/MaterialXLoader.js +111 -1010
- package/examples/jsm/loaders/PCDLoader.js +1 -1
- package/examples/jsm/loaders/SPLATLoader.js +139 -0
- package/examples/jsm/loaders/SPZLoader.js +561 -0
- package/examples/jsm/loaders/materialx/MaterialXArchive.js +108 -0
- package/examples/jsm/loaders/materialx/MaterialXDocument.js +878 -0
- package/examples/jsm/loaders/materialx/MaterialXHextile.js +183 -0
- package/examples/jsm/loaders/materialx/MaterialXInterfaceValidation.js +376 -0
- package/examples/jsm/loaders/materialx/MaterialXLog.js +75 -0
- package/examples/jsm/loaders/materialx/MaterialXNodeInterfaceRegistry.js +4 -0
- package/examples/jsm/loaders/materialx/MaterialXNodeLibrary.js +1021 -0
- package/examples/jsm/loaders/materialx/MaterialXSurfaceMappings.js +661 -0
- package/examples/jsm/loaders/materialx/MaterialXUtils.js +57 -0
- package/examples/jsm/loaders/materialx/compile/MaterialXCompileRegistry.js +997 -0
- package/examples/jsm/loaders/materialx/parse/MaterialXParser.js +28 -0
- package/examples/jsm/loaders/usd/USDAParser.js +15 -2
- package/examples/jsm/loaders/usd/USDCParser.js +1 -4
- package/examples/jsm/loaders/usd/USDComposer.js +80 -42
- package/examples/jsm/materials/WoodNodeMaterial.js +6 -108
- package/examples/jsm/misc/RollerCoaster.js +2 -2
- package/examples/jsm/misc/SculptGL.LICENSE.txt +21 -0
- package/examples/jsm/misc/Sculptor.js +1679 -0
- package/examples/jsm/misc/SculptorMesh.js +1504 -0
- package/examples/jsm/misc/SculptorTools.js +1180 -0
- package/examples/jsm/misc/SculptorUtils.js +345 -0
- package/examples/jsm/misc/TubePainter.js +28 -16
- package/examples/jsm/misc/VolumeSlice.js +24 -24
- package/examples/jsm/modifiers/SimplifyModifier.js +63 -556
- package/examples/jsm/objects/GaussianSplat.js +1039 -0
- package/examples/jsm/objects/Sky.js +66 -45
- package/examples/jsm/objects/SkyMesh.js +70 -51
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/postprocessing/AfterimagePass.js +4 -2
- package/examples/jsm/postprocessing/BloomPass.js +2 -2
- package/examples/jsm/postprocessing/GTAOPass.js +1 -1
- package/examples/jsm/postprocessing/OutlinePass.js +5 -5
- package/examples/jsm/postprocessing/SAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSRPass.js +4 -2
- package/examples/jsm/postprocessing/SavePass.js +1 -1
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +30 -13
- package/examples/jsm/renderers/CSS2DRenderer.js +29 -5
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +4 -1
- package/examples/jsm/shaders/ExposureShader.js +1 -1
- package/examples/jsm/shaders/FilmShader.js +2 -1
- package/examples/jsm/transpiler/AST.js +21 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +498 -8
- package/examples/jsm/transpiler/TSLEncoder.js +82 -10
- package/examples/jsm/transpiler/WGSLEncoder.js +33 -4
- package/examples/jsm/tsl/WebGLNodesHandler.js +29 -39
- package/examples/jsm/tsl/display/AfterImageNode.js +2 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +3 -2
- package/examples/jsm/tsl/display/BilateralBlurNode.js +5 -2
- package/examples/jsm/tsl/display/BloomNode.js +55 -30
- package/examples/jsm/tsl/display/DenoiseNode.js +21 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +24 -6
- package/examples/jsm/tsl/display/DotScreenNode.js +11 -11
- package/examples/jsm/tsl/display/FSR1Node.js +8 -4
- package/examples/jsm/tsl/display/GTAONode.js +199 -86
- package/examples/jsm/tsl/display/GaussianBlurNode.js +65 -52
- package/examples/jsm/tsl/display/GodraysNode.js +5 -2
- package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +2 -2
- package/examples/jsm/tsl/display/LensflareNode.js +5 -2
- package/examples/jsm/tsl/display/OITPassNode.js +352 -0
- package/examples/jsm/tsl/display/OutlineNode.js +2 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +3 -2
- package/examples/jsm/tsl/display/RGBShiftNode.js +9 -9
- package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +7 -4
- package/examples/jsm/tsl/display/RetroPassNode.js +1 -1
- package/examples/jsm/tsl/display/SMAANode.js +22 -61
- package/examples/jsm/tsl/display/SSAAPassNode.js +2 -4
- package/examples/jsm/tsl/display/SSAONode.js +436 -0
- package/examples/jsm/tsl/display/SSGINode.js +5 -2
- package/examples/jsm/tsl/display/SSRNode.js +7 -2
- package/examples/jsm/tsl/display/SSSNode.js +5 -2
- package/examples/jsm/tsl/display/SharpenNode.js +5 -4
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +1 -3
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -3
- package/examples/jsm/tsl/display/TAAUNode.js +22 -125
- package/examples/jsm/tsl/display/TRAANode.js +16 -142
- package/examples/jsm/tsl/display/TemporalReprojectNode.js +21 -15
- package/examples/jsm/tsl/display/depthAwareBlur.js +63 -0
- package/examples/jsm/tsl/display/hashBlur.js +3 -2
- package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +38 -27
- package/examples/jsm/tsl/lighting/LightProbeGridNode.js +136 -0
- package/examples/jsm/tsl/math/voronoiNoise.js +112 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +4 -6
- package/examples/jsm/tsl/utils/Raymarching.js +5 -5
- package/examples/jsm/tsl/utils/SoftParticles.js +60 -0
- package/examples/jsm/tsl/utils/TAAUtils.js +195 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +14 -14
- package/examples/jsm/utils/GaussianSplatUtils.js +229 -0
- package/examples/jsm/utils/WebGLTextureUtils.js +1 -1
- package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
- package/examples/jsm/webxr/WebGLXRFallback.js +2 -16
- package/examples/jsm/webxr/XRControllerModelFactory.js +16 -4
- package/package.json +9 -16
- package/src/Three.Core.js +2 -1
- package/src/Three.TSL.js +73 -43
- package/src/Three.WebGPU.Nodes.js +1 -0
- package/src/Three.WebGPU.js +1 -0
- package/src/animation/AnimationClip.js +15 -2
- package/src/animation/AnimationObjectGroup.js +18 -6
- package/src/animation/AnimationUtils.js +26 -0
- package/src/animation/KeyframeTrack.js +37 -0
- package/src/constants.js +23 -1
- package/src/core/BufferAttribute.js +3 -2
- package/src/core/BufferGeometry.js +1 -1
- package/src/core/InterleavedBuffer.js +5 -1
- package/src/core/Object3D.js +40 -12
- package/src/core/Raycaster.js +4 -0
- package/src/core/RenderTarget.js +99 -9
- package/src/core/RenderTarget3D.js +12 -8
- package/src/extras/Controls.js +0 -8
- package/src/extras/PMREMGenerator.js +99 -205
- package/src/geometries/TorusGeometry.js +1 -1
- package/src/helpers/ArrowHelper.js +2 -0
- package/src/helpers/AxesHelper.js +2 -0
- package/src/helpers/Box3Helper.js +2 -0
- package/src/helpers/BoxHelper.js +2 -0
- package/src/helpers/CameraHelper.js +2 -0
- package/src/helpers/DirectionalLightHelper.js +2 -0
- package/src/helpers/GridHelper.js +2 -0
- package/src/helpers/HemisphereLightHelper.js +2 -0
- package/src/helpers/PlaneHelper.js +2 -0
- package/src/helpers/PointLightHelper.js +2 -0
- package/src/helpers/PolarGridHelper.js +2 -0
- package/src/helpers/SkeletonHelper.js +2 -0
- package/src/helpers/SpotLightHelper.js +2 -0
- package/src/lights/Light.js +0 -10
- package/src/lights/LightShadow.js +43 -12
- package/src/lights/SpotLightShadow.js +18 -0
- package/src/loaders/BufferGeometryLoader.js +5 -0
- package/src/loaders/ImageBitmapLoader.js +3 -1
- package/src/loaders/ObjectLoader.js +8 -5
- package/src/materials/Material.js +80 -57
- package/src/materials/MeshPhysicalMaterial.js +32 -0
- package/src/materials/nodes/Line2NodeMaterial.js +17 -8
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +42 -5
- package/src/materials/nodes/NodeMaterial.js +19 -13
- package/src/materials/nodes/PointsNodeMaterial.js +2 -1
- package/src/materials/nodes/manager/NodeMaterialObserver.js +282 -55
- package/src/math/Frustum.js +9 -0
- package/src/math/FrustumArray.js +1 -1
- package/src/math/MathUtils.js +5 -3
- package/src/math/Matrix4.js +2 -9
- package/src/math/Plane.js +30 -1
- package/src/math/Quaternion.js +0 -10
- package/src/math/Ray.js +95 -45
- package/src/math/Triangle.js +0 -2
- package/src/math/Vector3.js +2 -2
- package/src/math/Vector4.js +0 -4
- package/src/math/interpolants/BezierInterpolant.js +36 -23
- package/src/nodes/Nodes.js +2 -0
- package/src/nodes/TSL.js +11 -3
- package/src/nodes/accessors/Batch.js +85 -13
- package/src/nodes/accessors/BufferAttributeNode.js +1 -1
- package/src/nodes/accessors/BuiltinNode.js +1 -1
- package/src/nodes/accessors/Instance.js +19 -18
- package/src/nodes/accessors/MaterialNode.js +9 -0
- package/src/nodes/accessors/ModelNode.js +85 -9
- package/src/nodes/accessors/ReferenceBaseNode.js +1 -70
- package/src/nodes/accessors/ReferenceElementNode.js +72 -0
- package/src/nodes/accessors/ReferenceNode.js +1 -70
- package/src/nodes/accessors/Skinning.js +124 -12
- package/src/nodes/accessors/StorageTextureNode.js +7 -3
- package/src/nodes/accessors/Texture3DNode.js +1 -1
- package/src/nodes/accessors/TextureNode.js +51 -21
- package/src/nodes/accessors/TextureSizeNode.js +4 -2
- package/src/nodes/accessors/UniformArrayNode.js +30 -5
- package/src/nodes/code/CodeNode.js +1 -1
- package/src/nodes/code/FunctionNode.js +12 -2
- package/src/nodes/core/ArrayNode.js +2 -2
- package/src/nodes/core/ContextNode.js +57 -4
- package/src/nodes/core/IndexNode.js +69 -4
- package/src/nodes/core/InspectorNode.js +2 -2
- package/src/nodes/core/MRTNode.js +44 -2
- package/src/nodes/core/Node.js +6 -3
- package/src/nodes/core/NodeBuilder.js +65 -50
- package/src/nodes/core/NodeFrame.js +11 -3
- package/src/nodes/core/NodeUtils.js +88 -0
- package/src/nodes/core/PropertyNode.js +8 -0
- package/src/nodes/core/StackNode.js +0 -1
- package/src/nodes/core/StructNode.js +4 -3
- package/src/nodes/core/UniformGroupNode.js +3 -2
- package/src/nodes/core/UniformNode.js +26 -12
- package/src/nodes/core/VarNode.js +0 -1
- package/src/nodes/display/BumpMapNode.js +2 -2
- package/src/nodes/display/ColorAdjustment.js +1 -1
- package/src/nodes/display/PassNode.js +76 -15
- package/src/nodes/display/ScreenNode.js +22 -65
- package/src/nodes/fog/Fog.js +4 -4
- package/src/nodes/functions/BSDF/BRDF_GGX.js +6 -6
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +1 -1
- package/src/nodes/functions/BSDF/DFGLUT.js +2 -1
- package/src/nodes/functions/BSDF/LTC.js +1 -1
- package/src/nodes/functions/PhongLightingModel.js +1 -1
- package/src/nodes/functions/PhysicalLightingModel.js +83 -25
- package/src/nodes/functions/ToonLightingModel.js +2 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +3 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +64 -13
- package/src/nodes/gpgpu/BarrierNode.js +13 -4
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +20 -17
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +165 -37
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +44 -6
- package/src/nodes/lighting/EnvironmentNode.js +40 -4
- package/src/nodes/lighting/LightsNode.js +20 -4
- package/src/nodes/lighting/ShadowBaseNode.js +158 -1
- package/src/nodes/lighting/ShadowFilterNode.js +2 -106
- package/src/nodes/lighting/ShadowNode.js +22 -91
- package/src/nodes/materialx/{lib/mx_hsv.js → MaterialXColor.js} +3 -6
- package/src/nodes/materialx/{lib/mx_transform_color.js → MaterialXColorTransform.js} +3 -6
- package/src/nodes/materialx/MaterialXCore.js +37 -0
- package/src/nodes/materialx/MaterialXNodes.js +64 -72
- package/src/nodes/materialx/{lib/mx_noise.js → MaterialXNoise.js} +426 -197
- package/src/nodes/math/BitcountNode.js +24 -4
- package/src/nodes/math/MathNode.js +4 -4
- package/src/nodes/math/MathUtils.js +15 -4
- package/src/nodes/math/OperatorNode.js +2 -2
- package/src/nodes/math/PackFloatNode.js +29 -1
- package/src/nodes/math/Packed4x8IntegerNode.js +433 -0
- package/src/nodes/math/UnpackFloatNode.js +30 -2
- package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
- package/src/nodes/pmrem/PMREMNode.js +1 -1
- package/src/nodes/pmrem/PMREMUtils.js +31 -74
- package/src/nodes/shapes/Shapes.js +1 -1
- package/src/nodes/tsl/TSLCore.js +1 -31
- package/src/nodes/utils/EventNode.js +75 -0
- package/src/nodes/utils/LoopNode.js +54 -13
- package/src/nodes/utils/PostProcessingUtils.js +23 -2
- package/src/nodes/utils/RTTNode.js +97 -32
- package/src/nodes/utils/ReflectorNode.js +8 -4
- package/src/nodes/utils/RotateNode.js +85 -8
- package/src/nodes/utils/SpriteUtils.js +58 -23
- package/src/objects/BatchedMesh.js +6 -0
- package/src/objects/InstancedMesh.js +1 -1
- package/src/objects/LOD.js +1 -1
- package/src/objects/Line.js +12 -0
- package/src/objects/Mesh.js +12 -0
- package/src/objects/Points.js +12 -0
- package/src/objects/Sprite.js +12 -0
- package/src/renderers/WebGLRenderer.js +93 -27
- package/src/renderers/common/Animation.js +12 -2
- package/src/renderers/common/Backend.js +38 -10
- package/src/renderers/common/BindGroup.js +0 -1
- package/src/renderers/common/Bindings.js +50 -4
- package/src/renderers/common/BundleGroup.js +4 -0
- package/src/renderers/common/ClippingContext.js +11 -1
- package/src/renderers/common/Color4.js +9 -0
- package/src/renderers/common/Constants.js +0 -5
- package/src/renderers/common/DirectRenderPipeline.js +233 -0
- package/src/renderers/common/Geometries.js +24 -3
- package/src/renderers/common/Info.js +3 -3
- package/src/renderers/common/InspectorBase.js +37 -8
- package/src/renderers/common/Lighting.js +11 -4
- package/src/renderers/common/Pipelines.js +6 -4
- package/src/renderers/common/QuadMesh.js +16 -2
- package/src/renderers/common/RenderContext.js +8 -0
- package/src/renderers/common/RenderList.js +53 -19
- package/src/renderers/common/RenderLists.js +58 -11
- package/src/renderers/common/RenderObject.js +14 -0
- package/src/renderers/common/RenderObjects.js +14 -9
- package/src/renderers/common/RenderPipeline.js +52 -44
- package/src/renderers/common/Renderer.js +226 -55
- package/src/renderers/common/Storage3DTexture.js +16 -0
- package/src/renderers/common/Textures.js +3 -3
- package/src/renderers/common/XRManager.js +79 -72
- package/src/renderers/common/extras/PMREMGenerator.js +76 -144
- package/src/renderers/common/nodes/NodeManager.js +144 -6
- package/src/renderers/common/nodes/NodeStorageBuffer.js +3 -1
- package/src/renderers/common/nodes/NodeUniformBuffer.js +3 -1
- package/src/renderers/shaders/DFGLUTData.js +2 -1
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +4 -2
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +48 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +53 -4
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +20 -2
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +20 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +61 -57
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +82 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +9 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +8 -1
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +15 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
- package/src/renderers/shaders/ShaderLib.js +1 -0
- package/src/renderers/shaders/UniformsLib.js +16 -0
- package/src/renderers/webgl/WebGLAnimation.js +2 -2
- package/src/renderers/webgl/WebGLCapabilities.js +2 -2
- package/src/renderers/webgl/WebGLLights.js +74 -4
- package/src/renderers/webgl/WebGLMaterials.js +6 -0
- package/src/renderers/webgl/WebGLOutput.js +36 -24
- package/src/renderers/webgl/WebGLProgram.js +3 -0
- package/src/renderers/webgl/WebGLPrograms.js +8 -0
- package/src/renderers/webgl/WebGLRenderLists.js +6 -10
- package/src/renderers/webgl/WebGLShadowMap.js +47 -44
- package/src/renderers/webgl/WebGLTextures.js +7 -7
- package/src/renderers/webgl-fallback/WebGLBackend.js +153 -45
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +83 -29
- package/src/renderers/webgl-fallback/utils/WebGLState.js +163 -17
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +32 -5
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +11 -4
- package/src/renderers/webgpu/WebGPUBackend.js +513 -145
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +99 -20
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -1
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +3 -12
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +24 -14
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +80 -14
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +62 -7
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +9 -3
- package/src/renderers/webgpu/utils/WebGPUUtils.js +16 -4
- package/src/renderers/webxr/WebXRManager.js +25 -2
- package/src/scenes/Scene.js +3 -3
- package/src/textures/CompressedArrayTexture.js +16 -0
- package/src/textures/Data3DTexture.js +16 -0
- package/src/textures/DataArrayTexture.js +16 -0
- package/src/textures/DepthTexture.js +3 -3
- package/src/textures/Texture.js +3 -3
- package/src/textures/{Source.js → TextureSource.js} +39 -8
- package/src/utils.js +6 -79
- package/build/three.core.min.js +0 -6
- package/build/three.module.min.js +0 -6
- package/build/three.tsl.min.js +0 -6
- package/build/three.webgpu.min.js +0 -6
- package/build/three.webgpu.nodes.min.js +0 -6
- package/examples/jsm/libs/ecsy.module.js +0 -1792
- package/examples/jsm/loaders/LottieLoader.js +0 -130
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +0 -52
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RenderTarget, Vector2, NodeMaterial, RendererUtils, QuadMesh, TempNode, NodeUpdateType } from '@gnsx/three/webgpu';
|
|
2
|
-
import { Fn, float, uv, uniform, convertToTexture, vec2, vec4, passTexture, premultiplyAlpha, unpremultiplyAlpha } from '@gnsx/three/tsl';
|
|
1
|
+
import { RenderTarget, Vector2, NodeMaterial, RendererUtils, QuadMesh, TempNode, NodeUpdateType, warnOnce } from '@gnsx/three/webgpu';
|
|
2
|
+
import { Fn, float, uv, uniform, convertToTexture, vec2, vec4, passTexture, premultiplyAlpha, unpremultiplyAlpha, context, texture } from '@gnsx/three/tsl';
|
|
3
3
|
|
|
4
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
5
|
|
|
@@ -62,15 +62,6 @@ class GaussianBlurNode extends TempNode {
|
|
|
62
62
|
*/
|
|
63
63
|
this._invSize = uniform( new Vector2() );
|
|
64
64
|
|
|
65
|
-
/**
|
|
66
|
-
* Gaussian blur is applied in two passes (horizontal, vertical).
|
|
67
|
-
* This node controls the direction of each pass.
|
|
68
|
-
*
|
|
69
|
-
* @private
|
|
70
|
-
* @type {UniformNode<vec2>}
|
|
71
|
-
*/
|
|
72
|
-
this._passDirection = uniform( new Vector2() );
|
|
73
|
-
|
|
74
65
|
/**
|
|
75
66
|
* The render target used for the horizontal pass.
|
|
76
67
|
*
|
|
@@ -104,7 +95,15 @@ class GaussianBlurNode extends TempNode {
|
|
|
104
95
|
* @private
|
|
105
96
|
* @type {?NodeMaterial}
|
|
106
97
|
*/
|
|
107
|
-
this.
|
|
98
|
+
this._hMaterial = null;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The material for the vertical pass.
|
|
102
|
+
*
|
|
103
|
+
* @private
|
|
104
|
+
* @type {?NodeMaterial}
|
|
105
|
+
*/
|
|
106
|
+
this._vMaterial = null;
|
|
108
107
|
|
|
109
108
|
/**
|
|
110
109
|
* The `updateBeforeType` is set to `NodeUpdateType.FRAME` since the node renders
|
|
@@ -173,12 +172,9 @@ class GaussianBlurNode extends TempNode {
|
|
|
173
172
|
|
|
174
173
|
//
|
|
175
174
|
|
|
176
|
-
const
|
|
177
|
-
const map = textureNode.value;
|
|
175
|
+
const map = this.textureNode.value;
|
|
178
176
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
_quadMesh.material = this._material;
|
|
177
|
+
_quadMesh.material = this._hMaterial;
|
|
182
178
|
|
|
183
179
|
this.setSize( map.image.width, map.image.height );
|
|
184
180
|
|
|
@@ -191,25 +187,20 @@ class GaussianBlurNode extends TempNode {
|
|
|
191
187
|
|
|
192
188
|
renderer.setRenderTarget( this._horizontalRT );
|
|
193
189
|
|
|
194
|
-
this._passDirection.value.set( 1, 0 );
|
|
195
|
-
|
|
196
190
|
_quadMesh.name = 'Gaussian Blur [ Horizontal Pass ]';
|
|
197
191
|
_quadMesh.render( renderer );
|
|
198
192
|
|
|
199
193
|
// vertical
|
|
200
194
|
|
|
201
|
-
|
|
202
|
-
renderer.setRenderTarget( this._verticalRT );
|
|
195
|
+
_quadMesh.material = this._vMaterial;
|
|
203
196
|
|
|
204
|
-
|
|
197
|
+
renderer.setRenderTarget( this._verticalRT );
|
|
205
198
|
|
|
206
199
|
_quadMesh.name = 'Gaussian Blur [ Vertical Pass ]';
|
|
207
200
|
_quadMesh.render( renderer );
|
|
208
201
|
|
|
209
202
|
// restore
|
|
210
203
|
|
|
211
|
-
textureNode.value = currentTexture;
|
|
212
|
-
|
|
213
204
|
RendererUtils.restoreRendererState( renderer, _rendererState );
|
|
214
205
|
|
|
215
206
|
}
|
|
@@ -233,36 +224,32 @@ class GaussianBlurNode extends TempNode {
|
|
|
233
224
|
*/
|
|
234
225
|
setup( builder ) {
|
|
235
226
|
|
|
236
|
-
const textureNode = this.textureNode;
|
|
237
|
-
|
|
238
|
-
//
|
|
239
|
-
|
|
240
227
|
const uvNode = uv();
|
|
241
228
|
const directionNode = vec2( this.directionNode || 1 );
|
|
242
229
|
|
|
243
|
-
|
|
230
|
+
const blur = Fn( ( [ textureNode, passDirection ] ) => {
|
|
244
231
|
|
|
245
|
-
|
|
232
|
+
let sampleTexture, output;
|
|
246
233
|
|
|
247
|
-
|
|
234
|
+
if ( this.premultipliedAlpha ) {
|
|
248
235
|
|
|
249
|
-
|
|
250
|
-
output = ( color ) => unpremultiplyAlpha( color );
|
|
236
|
+
// https://lisyarus.github.io/blog/posts/blur-coefficients-generator.html
|
|
251
237
|
|
|
252
|
-
|
|
238
|
+
sampleTexture = ( uv ) => premultiplyAlpha( textureNode.sample( uv ) );
|
|
239
|
+
output = ( color ) => unpremultiplyAlpha( color );
|
|
253
240
|
|
|
254
|
-
|
|
255
|
-
output = ( color ) => color;
|
|
241
|
+
} else {
|
|
256
242
|
|
|
257
|
-
|
|
243
|
+
sampleTexture = ( uv ) => textureNode.sample( uv );
|
|
244
|
+
output = ( color ) => color;
|
|
258
245
|
|
|
259
|
-
|
|
246
|
+
}
|
|
260
247
|
|
|
261
248
|
const kernelSize = 3 + ( 2 * this.sigma );
|
|
262
249
|
const gaussianCoefficients = this._getCoefficients( kernelSize );
|
|
263
250
|
|
|
264
251
|
const invSize = this._invSize;
|
|
265
|
-
const direction = directionNode.mul(
|
|
252
|
+
const direction = directionNode.mul( passDirection );
|
|
266
253
|
|
|
267
254
|
const diffuseSum = vec4( sampleTexture( uvNode ).mul( gaussianCoefficients[ 0 ] ) ).toVar();
|
|
268
255
|
|
|
@@ -286,15 +273,26 @@ class GaussianBlurNode extends TempNode {
|
|
|
286
273
|
|
|
287
274
|
//
|
|
288
275
|
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
276
|
+
const hTextureNode = this.textureNode;
|
|
277
|
+
|
|
278
|
+
this._hMaterial = this._hMaterial || ( new NodeMaterial() );
|
|
279
|
+
this._hMaterial.contextNode = context( builder.getSharedContext() );
|
|
280
|
+
this._hMaterial.fragmentNode = blur( hTextureNode, vec2( 1, 0 ) );
|
|
281
|
+
this._hMaterial.name = 'Gaussian_blur_horizontal';
|
|
282
|
+
this._hMaterial.needsUpdate = true;
|
|
283
|
+
|
|
284
|
+
const vTextureNode = texture( this._horizontalRT.texture, uv() );
|
|
285
|
+
|
|
286
|
+
this._vMaterial = this._vMaterial || new NodeMaterial();
|
|
287
|
+
this._vMaterial.fragmentNode = blur( vTextureNode, vec2( 0, 1 ) );
|
|
288
|
+
this._vMaterial.name = 'Gaussian_blur_vertical';
|
|
289
|
+
this._vMaterial.needsUpdate = true;
|
|
293
290
|
|
|
294
291
|
//
|
|
295
292
|
|
|
296
293
|
const properties = builder.getNodeProperties( this );
|
|
297
|
-
properties.
|
|
294
|
+
properties.hTextureNode = hTextureNode;
|
|
295
|
+
properties.vTextureNode = vTextureNode;
|
|
298
296
|
|
|
299
297
|
//
|
|
300
298
|
|
|
@@ -311,7 +309,17 @@ class GaussianBlurNode extends TempNode {
|
|
|
311
309
|
this._horizontalRT.dispose();
|
|
312
310
|
this._verticalRT.dispose();
|
|
313
311
|
|
|
314
|
-
if ( this.
|
|
312
|
+
if ( this._hMaterial !== null ) {
|
|
313
|
+
|
|
314
|
+
this._hMaterial.dispose();
|
|
315
|
+
this._vMaterial.dispose();
|
|
316
|
+
|
|
317
|
+
this._hMaterial = null;
|
|
318
|
+
this._vMaterial = null;
|
|
319
|
+
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
super.dispose();
|
|
315
323
|
|
|
316
324
|
}
|
|
317
325
|
|
|
@@ -327,13 +335,18 @@ class GaussianBlurNode extends TempNode {
|
|
|
327
335
|
const coefficients = [];
|
|
328
336
|
const sigma = kernelRadius / 3;
|
|
329
337
|
|
|
330
|
-
|
|
338
|
+
let sum = 1;
|
|
339
|
+
coefficients.push( 1 );
|
|
340
|
+
|
|
341
|
+
for ( let i = 1; i < kernelRadius; i ++ ) {
|
|
331
342
|
|
|
332
|
-
|
|
343
|
+
const w = Math.exp( - 0.5 * i * i / ( sigma * sigma ) );
|
|
344
|
+
coefficients.push( w );
|
|
345
|
+
sum += 2 * w;
|
|
333
346
|
|
|
334
347
|
}
|
|
335
348
|
|
|
336
|
-
return coefficients;
|
|
349
|
+
return coefficients.map( c => c / sum );
|
|
337
350
|
|
|
338
351
|
}
|
|
339
352
|
|
|
@@ -346,7 +359,7 @@ class GaussianBlurNode extends TempNode {
|
|
|
346
359
|
*/
|
|
347
360
|
get resolution() {
|
|
348
361
|
|
|
349
|
-
|
|
362
|
+
warnOnce( 'THREE.GaussianBlurNode: The "resolution" property has been renamed to "resolutionScale" and is now of type `number`.' ); // @deprecated r180
|
|
350
363
|
|
|
351
364
|
return new Vector2( this.resolutionScale, this.resolutionScale );
|
|
352
365
|
|
|
@@ -354,7 +367,7 @@ class GaussianBlurNode extends TempNode {
|
|
|
354
367
|
|
|
355
368
|
set resolution( value ) {
|
|
356
369
|
|
|
357
|
-
|
|
370
|
+
warnOnce( 'THREE.GaussianBlurNode: The "resolution" property has been renamed to "resolutionScale" and is now of type `number`.' ); // @deprecated r180
|
|
358
371
|
|
|
359
372
|
this.resolutionScale = value.x;
|
|
360
373
|
|
|
@@ -384,7 +397,7 @@ export const gaussianBlur = ( node, directionNode, sigma, options = {} ) => new
|
|
|
384
397
|
*
|
|
385
398
|
* @tsl
|
|
386
399
|
* @function
|
|
387
|
-
* @deprecated
|
|
400
|
+
* @deprecated since r180. Use `gaussianBlur()` with `premultipliedAlpha: true` option instead.
|
|
388
401
|
* @param {Node<vec4>} node - The node that represents the input of the effect.
|
|
389
402
|
* @param {Node<vec2|float>} directionNode - Defines the direction and radius of the blur.
|
|
390
403
|
* @param {number} sigma - Controls the kernel of the blur filter. Higher values mean a wider blur radius.
|
|
@@ -392,7 +405,7 @@ export const gaussianBlur = ( node, directionNode, sigma, options = {} ) => new
|
|
|
392
405
|
*/
|
|
393
406
|
export function premultipliedGaussianBlur( node, directionNode, sigma ) {
|
|
394
407
|
|
|
395
|
-
|
|
408
|
+
warnOnce( 'THREE.TSL: "premultipliedGaussianBlur()" is deprecated. Use "gaussianBlur()" with "premultipliedAlpha: true" option instead.' ); // @deprecated r180
|
|
396
409
|
|
|
397
410
|
return gaussianBlur( node, directionNode, sigma, { premultipliedAlpha: true } );
|
|
398
411
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Frustum, Matrix4, RenderTarget, Vector2, RendererUtils, QuadMesh, TempNode, NodeMaterial, NodeUpdateType, Vector3, Plane } from '@gnsx/three/webgpu';
|
|
2
|
-
import { cubeTexture, clamp, viewZToPerspectiveDepth, logarithmicDepthToViewZ, float, Loop, max, Fn, passTexture, uv, dot, uniformArray, If, getViewPosition, uniform, vec4, add, interleavedGradientNoise, screenCoordinate, round, mul, uint, mix, exp, vec3, distance, pow, reference, lightPosition, vec2, bool, texture, perspectiveDepthToViewZ, lightShadowMatrix } from '@gnsx/three/tsl';
|
|
2
|
+
import { cubeTexture, clamp, viewZToPerspectiveDepth, logarithmicDepthToViewZ, float, Loop, max, Fn, passTexture, uv, dot, uniformArray, If, getViewPosition, uniform, vec4, add, interleavedGradientNoise, screenCoordinate, round, mul, uint, mix, exp, vec3, distance, pow, reference, lightPosition, vec2, bool, texture, perspectiveDepthToViewZ, lightShadowMatrix, context } from '@gnsx/three/tsl';
|
|
3
3
|
|
|
4
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
5
|
const _size = /*@__PURE__*/ new Vector2();
|
|
@@ -579,7 +579,8 @@ class GodraysNode extends TempNode {
|
|
|
579
579
|
|
|
580
580
|
} );
|
|
581
581
|
|
|
582
|
-
this._material.
|
|
582
|
+
this._material.contextNode = context( builder.getSharedContext() );
|
|
583
|
+
this._material.fragmentNode = godrays();
|
|
583
584
|
this._material.needsUpdate = true;
|
|
584
585
|
|
|
585
586
|
return this._textureNode;
|
|
@@ -592,6 +593,8 @@ class GodraysNode extends TempNode {
|
|
|
592
593
|
*/
|
|
593
594
|
dispose() {
|
|
594
595
|
|
|
596
|
+
super.dispose();
|
|
597
|
+
|
|
595
598
|
this._godraysRenderTarget.dispose();
|
|
596
599
|
|
|
597
600
|
this._material.dispose();
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { If, dot, equirectUV, float, luminance, max, normalize, texture, uniform, vec2, vec4 } from '@gnsx/three/tsl';
|
|
11
|
-
import { ClampToEdgeWrapping, DataTexture, DataUtils, FloatType, HalfFloatType, LinearFilter, RedFormat, RepeatWrapping,
|
|
11
|
+
import { ClampToEdgeWrapping, DataTexture, DataUtils, FloatType, HalfFloatType, LinearFilter, RedFormat, RepeatWrapping, TextureSource, Vector2 } from '@gnsx/three/webgpu';
|
|
12
12
|
import { D_GTR, F_Schlick, GeometryTerm, SmithG, equirectDirPdf, misPowerHeuristic } from '../utils/SpecularHelpers.js';
|
|
13
13
|
|
|
14
14
|
function colorToLuminance( r, g, b ) {
|
|
@@ -45,7 +45,7 @@ function binarySearchFindClosestIndexOf( array, targetValue, offset = 0, count =
|
|
|
45
45
|
function preprocessEnvMap( envMap ) {
|
|
46
46
|
|
|
47
47
|
const map = envMap.clone();
|
|
48
|
-
map.source = new
|
|
48
|
+
map.source = new TextureSource( { ...map.image } );
|
|
49
49
|
const { width, height, data } = map.image;
|
|
50
50
|
|
|
51
51
|
let newData = data;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderTarget, Vector2, TempNode, NodeUpdateType, QuadMesh, RendererUtils, NodeMaterial } from '@gnsx/three/webgpu';
|
|
2
|
-
import { convertToTexture, nodeObject, Fn, passTexture, uv, vec2, vec3, vec4, max, float, sub, int, Loop, fract, pow, distance } from '@gnsx/three/tsl';
|
|
2
|
+
import { convertToTexture, nodeObject, Fn, passTexture, uv, vec2, vec3, vec4, max, float, sub, int, Loop, fract, pow, distance, context } from '@gnsx/three/tsl';
|
|
3
3
|
|
|
4
4
|
const _quadMesh = /*@__PURE__*/ new QuadMesh();
|
|
5
5
|
const _size = /*@__PURE__*/ new Vector2();
|
|
@@ -239,7 +239,8 @@ class LensflareNode extends TempNode {
|
|
|
239
239
|
|
|
240
240
|
} );
|
|
241
241
|
|
|
242
|
-
this._material.
|
|
242
|
+
this._material.contextNode = context( builder.getSharedContext() );
|
|
243
|
+
this._material.fragmentNode = lensflare();
|
|
243
244
|
this._material.needsUpdate = true;
|
|
244
245
|
|
|
245
246
|
return this._textureNode;
|
|
@@ -252,6 +253,8 @@ class LensflareNode extends TempNode {
|
|
|
252
253
|
*/
|
|
253
254
|
dispose() {
|
|
254
255
|
|
|
256
|
+
super.dispose();
|
|
257
|
+
|
|
255
258
|
this._renderTarget.dispose();
|
|
256
259
|
this._material.dispose();
|
|
257
260
|
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { PassNode, RenderTarget, BlendMode, RendererUtils, Vector2, HalfFloatType, UnsignedByteType, RedFormat, CustomBlending, NormalBlending, OneFactor, ZeroFactor, OneMinusSrcColorFactor } from '@gnsx/three/webgpu';
|
|
2
|
+
import { float, mix, mrt, output, positionView, texture, vec4 } from '@gnsx/three/tsl';
|
|
3
|
+
|
|
4
|
+
const _size = /*@__PURE__*/ new Vector2();
|
|
5
|
+
|
|
6
|
+
let _rendererState, _sceneState;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A render pass node that renders the scene with Order-Independent Transparency
|
|
10
|
+
* based on the Weighted Blended OIT technique by McGuire and Bavoil.
|
|
11
|
+
*
|
|
12
|
+
* Transparent objects are rendered in a separate pass into two accumulation
|
|
13
|
+
* targets (a weighted color sum and the pixel's revealage) which are
|
|
14
|
+
* then composited over the rest of the scene. Since the result does not depend
|
|
15
|
+
* on the draw order, artifacts from sorting-based transparency like popping or
|
|
16
|
+
* incorrectly resolved intersecting geometry are avoided.
|
|
17
|
+
*
|
|
18
|
+
* Only transparent materials using `NormalBlending` and no transmission qualify
|
|
19
|
+
* for OIT. All other objects are rendered as usual.
|
|
20
|
+
*
|
|
21
|
+
* MSAA is only supported with the WebGPU backend.
|
|
22
|
+
*
|
|
23
|
+
* MRT configurations assigned via `setMRT()` apply to the default pass only.
|
|
24
|
+
* OIT-qualified objects contribute to the color output but not to custom
|
|
25
|
+
* MRT outputs since a pixel may accumulate multiple transparent surfaces.
|
|
26
|
+
*
|
|
27
|
+
* ```js
|
|
28
|
+
* const renderPipeline = new THREE.RenderPipeline( renderer );
|
|
29
|
+
* renderPipeline.outputNode = oitPass( scene, camera );
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* References:
|
|
33
|
+
* - {@link https://jcgt.org/published/0002/02/09/}
|
|
34
|
+
* - {@link https://casual-effects.blogspot.com/2014/03/weighted-blended-order-independent.html}
|
|
35
|
+
*
|
|
36
|
+
* @augments PassNode
|
|
37
|
+
* @three_import import { oitPass } from 'three/addons/tsl/display/OITPassNode.js';
|
|
38
|
+
*/
|
|
39
|
+
class OITPassNode extends PassNode {
|
|
40
|
+
|
|
41
|
+
static get type() {
|
|
42
|
+
|
|
43
|
+
return 'OITPassNode';
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Constructs a new OIT pass node.
|
|
49
|
+
*
|
|
50
|
+
* @param {Scene} scene - The scene to render.
|
|
51
|
+
* @param {Camera} camera - The camera to render the scene with.
|
|
52
|
+
* @param {Object} [options={}] - Options for the internal render target.
|
|
53
|
+
*/
|
|
54
|
+
constructor( scene, camera, options = {} ) {
|
|
55
|
+
|
|
56
|
+
super( PassNode.COLOR, scene, camera, options );
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* This flag can be used for type testing.
|
|
60
|
+
*
|
|
61
|
+
* @type {boolean}
|
|
62
|
+
* @readonly
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
this.isOITPassNode = true;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The depth-based weight of a transparent fragment, see equations (7) to (9)
|
|
69
|
+
* in the paper. When `null`, equation (9) is used. Must be assigned before
|
|
70
|
+
* the first render.
|
|
71
|
+
*
|
|
72
|
+
* @type {?Node<float>}
|
|
73
|
+
* @default null
|
|
74
|
+
*/
|
|
75
|
+
this.weightNode = null;
|
|
76
|
+
|
|
77
|
+
// the accumulation target shares the depth of the default pass so transparent
|
|
78
|
+
// fragments are depth-tested against the opaque scene (without depth writes)
|
|
79
|
+
|
|
80
|
+
const oitRenderTarget = new RenderTarget( 1, 1, { count: 2 } );
|
|
81
|
+
oitRenderTarget.depthTexture = this.renderTarget.depthTexture;
|
|
82
|
+
|
|
83
|
+
const accumTexture = oitRenderTarget.textures[ 0 ]; // RGBA16
|
|
84
|
+
accumTexture.name = 'accum';
|
|
85
|
+
accumTexture.type = HalfFloatType;
|
|
86
|
+
|
|
87
|
+
const revealageTexture = oitRenderTarget.textures[ 1 ]; // R8
|
|
88
|
+
revealageTexture.name = 'revealage';
|
|
89
|
+
revealageTexture.format = RedFormat;
|
|
90
|
+
revealageTexture.type = UnsignedByteType;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The render target holding the OIT accumulation textures.
|
|
94
|
+
*
|
|
95
|
+
* @private
|
|
96
|
+
* @type {RenderTarget}
|
|
97
|
+
*/
|
|
98
|
+
this._oitRenderTarget = oitRenderTarget;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The MRT configuration for the OIT pass.
|
|
102
|
+
*
|
|
103
|
+
* @private
|
|
104
|
+
* @type {?MRTNode}
|
|
105
|
+
*/
|
|
106
|
+
this._oitMRTNode = null;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The renderer of the current frame.
|
|
110
|
+
*
|
|
111
|
+
* @private
|
|
112
|
+
* @type {?Renderer}
|
|
113
|
+
*/
|
|
114
|
+
this._renderer = null;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Renders opaque objects and transparent objects that do not qualify for OIT.
|
|
118
|
+
*
|
|
119
|
+
* @private
|
|
120
|
+
* @type {Function}
|
|
121
|
+
*/
|
|
122
|
+
this._defaultRenderObjectFunction = ( object, scene, camera, geometry, material, group, lightsNode, clippingContext, passId ) => {
|
|
123
|
+
|
|
124
|
+
if ( isOITCapable( material ) === false ) {
|
|
125
|
+
|
|
126
|
+
this._renderer.renderObject( object, scene, camera, geometry, material, group, lightsNode, clippingContext, passId );
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Renders OIT-qualified objects into the accumulation targets.
|
|
134
|
+
*
|
|
135
|
+
* @private
|
|
136
|
+
* @type {Function}
|
|
137
|
+
*/
|
|
138
|
+
this._oitRenderObjectFunction = ( object, scene, camera, geometry, material, group, lightsNode, clippingContext, passId ) => {
|
|
139
|
+
|
|
140
|
+
if ( isOITCapable( material ) === true ) {
|
|
141
|
+
|
|
142
|
+
const currentDepthWrite = material.depthWrite;
|
|
143
|
+
|
|
144
|
+
material.depthWrite = false;
|
|
145
|
+
|
|
146
|
+
this._renderer.renderObject( object, scene, camera, geometry, material, group, lightsNode, clippingContext, passId );
|
|
147
|
+
|
|
148
|
+
material.depthWrite = currentDepthWrite;
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Returns the MRT configuration for the OIT pass.
|
|
158
|
+
*
|
|
159
|
+
* @private
|
|
160
|
+
* @return {MRTNode} The MRT node.
|
|
161
|
+
*/
|
|
162
|
+
_getMRTNode() {
|
|
163
|
+
|
|
164
|
+
if ( this._oitMRTNode === null ) {
|
|
165
|
+
|
|
166
|
+
const alpha = output.a;
|
|
167
|
+
|
|
168
|
+
let weight = this.weightNode;
|
|
169
|
+
|
|
170
|
+
if ( weight === null ) {
|
|
171
|
+
|
|
172
|
+
// equation (9) from the paper, based on the linear eye-space depth
|
|
173
|
+
|
|
174
|
+
const z = positionView.z.negate();
|
|
175
|
+
|
|
176
|
+
weight = alpha.mul( float( 0.03 ).div( z.div( 200 ).pow( 4 ).add( 1e-5 ) ).clamp( 1e-2, 3e3 ) );
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// since the revealage target is single-channel, the alpha must be blended
|
|
181
|
+
// via its red channel
|
|
182
|
+
|
|
183
|
+
const accumBlending = new BlendMode( CustomBlending );
|
|
184
|
+
accumBlending.blendSrc = OneFactor;
|
|
185
|
+
accumBlending.blendDst = OneFactor;
|
|
186
|
+
|
|
187
|
+
const revealageBlending = new BlendMode( CustomBlending );
|
|
188
|
+
revealageBlending.blendSrc = ZeroFactor;
|
|
189
|
+
revealageBlending.blendDst = OneMinusSrcColorFactor;
|
|
190
|
+
|
|
191
|
+
this._oitMRTNode = mrt( {
|
|
192
|
+
accum: vec4( output.rgb.mul( alpha ), alpha ).mul( weight ),
|
|
193
|
+
revealage: alpha
|
|
194
|
+
} ).setBlendMode( 'accum', accumBlending ).setBlendMode( 'revealage', revealageBlending )
|
|
195
|
+
.setClearColor( 'accum', 0x000000, 0 ).setClearColor( 'revealage', 0xffffff, 1 );
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return this._oitMRTNode;
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
setSize( width, height ) {
|
|
204
|
+
|
|
205
|
+
super.setSize( width, height );
|
|
206
|
+
|
|
207
|
+
this._oitRenderTarget.setSize( this.renderTarget.width, this.renderTarget.height );
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
setup( builder ) {
|
|
212
|
+
|
|
213
|
+
const beautyNode = super.setup( builder );
|
|
214
|
+
|
|
215
|
+
// MSAA
|
|
216
|
+
|
|
217
|
+
if ( builder.renderer.backend.isWebGPUBackend === true ) {
|
|
218
|
+
|
|
219
|
+
// sample counts must match since the depth buffer is shared
|
|
220
|
+
|
|
221
|
+
this._oitRenderTarget.samples = this.renderTarget.samples;
|
|
222
|
+
|
|
223
|
+
} else {
|
|
224
|
+
|
|
225
|
+
// The WebGL backend does not support depth texture sharing with MSAA unless
|
|
226
|
+
// WEBGL_multisampled_render_to_texture is supported (which isn't available on most devices)
|
|
227
|
+
|
|
228
|
+
this.renderTarget.samples = 0;
|
|
229
|
+
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// TSL
|
|
233
|
+
|
|
234
|
+
const accumNode = texture( this._oitRenderTarget.textures[ 0 ] );
|
|
235
|
+
const revealageNode = texture( this._oitRenderTarget.textures[ 1 ] ).r;
|
|
236
|
+
|
|
237
|
+
const accumColor = accumNode.rgb.div( accumNode.a.max( 1e-5 ) );
|
|
238
|
+
|
|
239
|
+
return vec4( mix( accumColor, beautyNode.rgb, revealageNode ), beautyNode.a );
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
updateBefore( frame ) {
|
|
244
|
+
|
|
245
|
+
const { renderer } = frame;
|
|
246
|
+
const { scene, camera } = this;
|
|
247
|
+
|
|
248
|
+
this._renderer = renderer;
|
|
249
|
+
|
|
250
|
+
renderer.getDrawingBufferSize( _size );
|
|
251
|
+
this.setSize( _size.width, _size.height );
|
|
252
|
+
|
|
253
|
+
_rendererState = RendererUtils.saveRendererState( renderer, _rendererState );
|
|
254
|
+
|
|
255
|
+
const currentAutoClearColor = renderer.autoClearColor;
|
|
256
|
+
const currentAutoClearDepth = renderer.autoClearDepth;
|
|
257
|
+
const currentAutoClearStencil = renderer.autoClearStencil;
|
|
258
|
+
const currentTransparent = renderer.transparent;
|
|
259
|
+
const currentOpaque = renderer.opaque;
|
|
260
|
+
const currentMask = camera.layers.mask;
|
|
261
|
+
|
|
262
|
+
this._cameraNear.value = camera.near;
|
|
263
|
+
this._cameraFar.value = camera.far;
|
|
264
|
+
|
|
265
|
+
if ( this._layers !== null ) {
|
|
266
|
+
|
|
267
|
+
camera.layers.mask = this._layers.mask;
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
renderer.autoClear = this.autoClear;
|
|
272
|
+
renderer.autoClearColor = this.autoClearColor;
|
|
273
|
+
renderer.autoClearDepth = this.autoClearDepth;
|
|
274
|
+
renderer.autoClearStencil = this.autoClearStencil;
|
|
275
|
+
|
|
276
|
+
// default pass: opaque objects and transparent objects that do not qualify for OIT
|
|
277
|
+
|
|
278
|
+
renderer.setMRT( this._mrt );
|
|
279
|
+
renderer.setRenderTarget( this.renderTarget );
|
|
280
|
+
renderer.setRenderObjectFunction( this._defaultRenderObjectFunction );
|
|
281
|
+
|
|
282
|
+
renderer.render( scene, camera );
|
|
283
|
+
|
|
284
|
+
// OIT pass: accumulate the weighted colors and the revealage of all OIT-qualified objects
|
|
285
|
+
|
|
286
|
+
_sceneState = RendererUtils.resetSceneState( scene, _sceneState ); // the background must not affect the accumulation targets
|
|
287
|
+
|
|
288
|
+
renderer.setRenderTarget( this._oitRenderTarget );
|
|
289
|
+
renderer.setMRT( this._getMRTNode() );
|
|
290
|
+
renderer.setRenderObjectFunction( this._oitRenderObjectFunction );
|
|
291
|
+
renderer.autoClearDepth = false; // the depth buffer is shared with the default pass
|
|
292
|
+
renderer.opaque = false;
|
|
293
|
+
renderer.transparent = true;
|
|
294
|
+
|
|
295
|
+
renderer.render( scene, camera );
|
|
296
|
+
|
|
297
|
+
// restore
|
|
298
|
+
|
|
299
|
+
RendererUtils.restoreSceneState( scene, _sceneState );
|
|
300
|
+
RendererUtils.restoreRendererState( renderer, _rendererState );
|
|
301
|
+
|
|
302
|
+
renderer.autoClearColor = currentAutoClearColor;
|
|
303
|
+
renderer.autoClearDepth = currentAutoClearDepth;
|
|
304
|
+
renderer.autoClearStencil = currentAutoClearStencil;
|
|
305
|
+
renderer.transparent = currentTransparent;
|
|
306
|
+
renderer.opaque = currentOpaque;
|
|
307
|
+
|
|
308
|
+
camera.layers.mask = currentMask;
|
|
309
|
+
|
|
310
|
+
this._renderer = null;
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
dispose() {
|
|
315
|
+
|
|
316
|
+
super.dispose();
|
|
317
|
+
|
|
318
|
+
this._oitRenderTarget.dispose();
|
|
319
|
+
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Returns `true` if the given material qualifies for OIT.
|
|
326
|
+
*
|
|
327
|
+
* @param {Material} material - The material to check.
|
|
328
|
+
* @return {boolean} Whether the material qualifies for OIT or not.
|
|
329
|
+
*/
|
|
330
|
+
function isOITCapable( material ) {
|
|
331
|
+
|
|
332
|
+
return material.transparent === true && material.blending === NormalBlending &&
|
|
333
|
+
( material.transmission > 0 ) === false &&
|
|
334
|
+
! ( material.transmissionNode && material.transmissionNode.isNode ) &&
|
|
335
|
+
! ( material.backdropNode && material.backdropNode.isNode );
|
|
336
|
+
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
export default OITPassNode;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* TSL function for creating an OIT pass node.
|
|
344
|
+
*
|
|
345
|
+
* @tsl
|
|
346
|
+
* @function
|
|
347
|
+
* @param {Scene} scene - The scene to render.
|
|
348
|
+
* @param {Camera} camera - The camera to render the scene with.
|
|
349
|
+
* @param {Object} [options={}] - Options for the internal render target.
|
|
350
|
+
* @returns {OITPassNode}
|
|
351
|
+
*/
|
|
352
|
+
export const oitPass = ( scene, camera, options ) => new OITPassNode( scene, camera, options );
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeMaterial } from '@gnsx/three/webgpu';
|
|
2
|
-
import { Fn, vec4, uv, If, mod, screenCoordinate } from '@gnsx/three/tsl';
|
|
2
|
+
import { Fn, vec4, uv, If, mod, screenCoordinate, context } from '@gnsx/three/tsl';
|
|
3
3
|
import StereoCompositePassNode from './StereoCompositePassNode.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -66,7 +66,8 @@ class ParallaxBarrierPassNode extends StereoCompositePassNode {
|
|
|
66
66
|
} );
|
|
67
67
|
|
|
68
68
|
const material = this._material || ( this._material = new NodeMaterial() );
|
|
69
|
-
material.
|
|
69
|
+
material.contextNode = context( builder.getSharedContext() );
|
|
70
|
+
material.fragmentNode = parallaxBarrier();
|
|
70
71
|
material.needsUpdate = true;
|
|
71
72
|
|
|
72
73
|
return super.setup( builder );
|