From 02004977ea4c8f56ce8e0b9bd3f2df2b838060d9 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Sat, 15 Aug 2026 09:42:13 +0200 Subject: [PATCH 1/2] Updated builds. --- build/three.webgpu.js | 244 +++++++++++++++++++++--------------- build/three.webgpu.nodes.js | 244 +++++++++++++++++++++--------------- 2 files changed, 292 insertions(+), 196 deletions(-) diff --git a/build/three.webgpu.js b/build/three.webgpu.js index b0c2d40f950ee5..a8335b29cf444e 100644 --- a/build/three.webgpu.js +++ b/build/three.webgpu.js @@ -8804,11 +8804,17 @@ class ContextNode extends Node { analyze( builder ) { - const previousContext = builder.addContext( this.value ); + const usageCount = builder.increaseUsage( this ); + + if ( usageCount === 1 ) { - this.node.build( builder ); + const previousContext = builder.addContext( this.value ); - builder.setContext( previousContext ); + this.node.build( builder, this ); + + builder.setContext( previousContext ); + + } } @@ -8816,10 +8822,12 @@ class ContextNode extends Node { const previousContext = builder.addContext( this.value ); - this.node.build( builder ); + const node = this.node.build( builder ); builder.setContext( previousContext ); + return node; + } generate( builder, output ) { @@ -9836,8 +9844,6 @@ const convertColorSpace = ( node, sourceColorSpace, targetColorSpace ) => new Co addMethodChaining( 'workingToColorSpace', workingToColorSpace ); addMethodChaining( 'colorSpaceToWorking', colorSpaceToWorking ); -// TODO: Avoid duplicated code and use only ReferenceBaseNode or ReferenceNode - /** * This class is only relevant if the referenced property is array-like. * In this case, `ReferenceElementNode` allows to refer to a specific @@ -9845,7 +9851,7 @@ addMethodChaining( 'colorSpaceToWorking', colorSpaceToWorking ); * * @augments ArrayElementNode */ -let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode { +class ReferenceElementNode extends ArrayElementNode { static get type() { @@ -9856,7 +9862,7 @@ let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode /** * Constructs a new reference element node. * - * @param {ReferenceBaseNode} referenceNode - The reference node. + * @param {(ReferenceBaseNode|ReferenceNode)} referenceNode - The reference node. * @param {Node} indexNode - The index node that defines the element access. */ constructor( referenceNode, indexNode ) { @@ -9864,10 +9870,10 @@ let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode super( referenceNode, indexNode ); /** - * Similar to {@link ReferenceBaseNode#reference}, an additional + * Similar to {@link ReferenceNode#reference}, an additional * property references to the current node. * - * @type {?ReferenceBaseNode} + * @type {?(ReferenceBaseNode|ReferenceNode)} * @default null */ this.referenceNode = referenceNode; @@ -9898,14 +9904,16 @@ let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode generate( builder ) { const snippet = super.generate( builder ); - const arrayType = this.referenceNode.getNodeType(); - const elementType = this.getNodeType(); + const arrayType = this.referenceNode.getNodeType( builder ); + const elementType = this.getNodeType( builder ); return builder.format( snippet, arrayType, elementType ); } -}; +} + +// TODO: Avoid duplicated code and use only ReferenceBaseNode or ReferenceNode /** * Base class for nodes which establishes a reference to a property of another object. @@ -10031,7 +10039,7 @@ class ReferenceBaseNode extends Node { */ element( indexNode ) { - return new ReferenceElementNode$1( this, nodeObject( indexNode ) ); + return new ReferenceElementNode( this, nodeObject( indexNode ) ); } @@ -11924,6 +11932,22 @@ class InspectorBase extends EventDispatcher { */ this.currentFrame = null; + /** + * Indicates whether the inspector is running. + * + * @type {boolean} + * @default false + */ + this.isRunning = false; + + /** + * Indicates whether the inspector is enabled. + * + * @type {boolean} + * @default true + */ + this.enabled = true; + } /** @@ -11970,12 +11994,20 @@ class InspectorBase extends EventDispatcher { /** * Called when a frame begins. */ - begin() { } + begin() { + + this.isRunning = true; + + } /** * Called when a frame ends. */ - finish() { } + finish() { + + this.isRunning = false; + + } /** * Inspects a node. @@ -15981,75 +16013,6 @@ const uniformCubeTexture = ( value = EmptyTexture ) => cubeTextureBase( value ); // TODO: Avoid duplicated code and use only ReferenceBaseNode or ReferenceNode -/** - * This class is only relevant if the referenced property is array-like. - * In this case, `ReferenceElementNode` allows to refer to a specific - * element inside the data structure via an index. - * - * @augments ArrayElementNode - */ -class ReferenceElementNode extends ArrayElementNode { - - static get type() { - - return 'ReferenceElementNode'; - - } - - /** - * Constructs a new reference element node. - * - * @param {?ReferenceNode} referenceNode - The reference node. - * @param {Node} indexNode - The index node that defines the element access. - */ - constructor( referenceNode, indexNode ) { - - super( referenceNode, indexNode ); - - /** - * Similar to {@link ReferenceNode#reference}, an additional - * property references to the current node. - * - * @type {?ReferenceNode} - * @default null - */ - this.referenceNode = referenceNode; - - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - this.isReferenceElementNode = true; - - } - - /** - * This method is overwritten since the node type is inferred from - * the uniform type of the reference node. - * - * @return {string} The node type. - */ - generateNodeType() { - - return this.referenceNode.uniformType; - - } - - generate( builder ) { - - const snippet = super.generate( builder ); - const arrayType = this.referenceNode.getNodeType( builder ); - const elementType = this.getNodeType( builder ); - - return builder.format( snippet, arrayType, elementType ); - - } - -} - /** * This type of node establishes a reference to a property of another object. * In this way, the value of the node is automatically linked to the value of @@ -28719,7 +28682,7 @@ class ToonLightingModel extends LightingModel { */ direct( { lightDirection, lightColor, reflectedLight }, builder ) { - const irradiance = getGradientIrradiance( { normal: normalGeometry, lightDirection, builder } ).mul( lightColor ); + const irradiance = getGradientIrradiance( { normal: normalView, lightDirection, builder } ).mul( lightColor ); reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) ); @@ -29826,6 +29789,12 @@ class Animation { this._requestId = this._context.requestAnimationFrame( update ); + if ( this.renderer._inspector.isRunning ) { + + this.renderer._inspector.finish(); + + } + if ( this.info.autoReset === true ) this.info.reset(); this.nodes.nodeFrame.update(); @@ -29834,9 +29803,11 @@ class Animation { this.renderer._inspector.begin(); - if ( this._animationLoop !== null ) this._animationLoop( time, xrFrame ); + if ( this._animationLoop !== null ) { + + this._animationLoop( time, xrFrame ); - this.renderer._inspector.finish(); + } }; @@ -29849,6 +29820,8 @@ class Animation { */ stop() { + if ( this.renderer._inspector.isRunning ) this.renderer._inspector.finish(); + if ( this._context !== null ) this._context.cancelAnimationFrame( this._requestId ); this._requestId = null; @@ -35275,6 +35248,15 @@ class Color4 extends Color { } + *[ Symbol.iterator ]() { + + yield this.r; + yield this.g; + yield this.b; + yield this.a; + + } + } /** @@ -36541,6 +36523,13 @@ class MRTNode extends OutputStructNode { output: _materialBlending }; + /** + * A dictionary storing the clear colors for each output. + * + * @type {Object} + */ + this.clearColors = {}; + /** * This flag can be used for type testing. * @@ -36579,6 +36568,38 @@ class MRTNode extends OutputStructNode { } + /** + * Sets the clear color for the given output name. + * + * @param {string} name - The name of the output. + * @param {number|string|Color} color - The clear color. + * @param {number} [alpha=1] - The clear alpha. + * @return {MRTNode} The current MRT node. + */ + setClearColor( name, color, alpha = 1 ) { + + const clearColor = this.clearColors[ name ] || ( this.clearColors[ name ] = new Color4() ); + + clearColor.set( color ); + clearColor.a = alpha; + + return this; + + } + + /** + * Returns the clear color for the given output name. + * + * @param {string} name - The name of the output. + * @return {?Color4} The clear color. Returns `null` if no clear color is defined + * which means the renderer's default clear policy is applied. + */ + getClearColor( name ) { + + return this.clearColors[ name ] || null; + + } + /** * Returns `true` if the MRT node has an output with the given name. * @@ -36612,10 +36633,12 @@ class MRTNode extends OutputStructNode { merge( mrtNode ) { const outputs = { ...this.outputNodes, ...mrtNode.outputNodes }; - const blendings = { ...this.blendModes, ...mrtNode.blendModes }; + const blendModes = { ...this.blendModes, ...mrtNode.blendModes }; + const clearColors = { ...this.clearColors, ...mrtNode.clearColors }; const mrtTarget = mrt( outputs ); - mrtTarget.blendings = blendings; + mrtTarget.blendModes = blendModes; + mrtTarget.clearColors = clearColors; return mrtTarget; @@ -72180,11 +72203,14 @@ class WebGLTimestampQueryPool extends TimestampQueryPool { if ( ! this.trackTimestamp ) return null; - // Check if we have enough space for a new query pair if ( this.currentQueryIndex + 2 > this.maxQueries ) { - warnOnce( `WebGLTimestampQueryPool [${ this.type }]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${ this.type.toUpperCase() } ).` ); - return null; + this.resolveQueriesAsync(); + + this.currentQueryIndex = 0; + this.queryOffsets.clear(); + this.queryStates.clear(); + this.activeQuery = null; } @@ -72344,6 +72370,8 @@ class WebGLTimestampQueryPool extends TimestampQueryPool { const frames = []; + this.timestamps.clear(); + for ( const [ uid, promise ] of resolvePromises ) { const match = uid.match( /^(.*):f(\d+)$/ ); @@ -72508,6 +72536,8 @@ class WebGLTimestampQueryPool extends TimestampQueryPool { this.queries = []; this.queryStates.clear(); this.queryOffsets.clear(); + this.timestamps.clear(); + this.frames = []; this.lastValue = 0; this.activeQuery = null; @@ -73335,7 +73365,13 @@ class WebGLBackend extends Backend { for ( let i = 0; i < descriptor.textures.length; i ++ ) { - if ( i === 0 ) { + const mrtClearColor = descriptor.mrt ? descriptor.mrt.getClearColor( descriptor.textures[ i ].name ) : null; + + if ( mrtClearColor !== null ) { + + gl.clearBufferfv( gl.COLOR, i, [ mrtClearColor.r, mrtClearColor.g, mrtClearColor.b, mrtClearColor.a ] ); + + } else if ( i === 0 ) { gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] ); @@ -85024,8 +85060,10 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool { if ( this.currentQueryIndex + 2 > this.maxQueries ) { - warnOnce( `WebGPUTimestampQueryPool [${ this.type }]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${ this.type.toUpperCase() } ).` ); - return null; + this.resolveQueriesAsync(); + + this.currentQueryIndex = 0; + this.queryOffsets.clear(); } @@ -85154,6 +85192,8 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool { const frames = []; + this.timestamps.clear(); + for ( const [ uid, baseOffset ] of currentOffsets ) { const match = uid.match( /^(.*):f(\d+)$/ ); @@ -85270,6 +85310,8 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool { } this.queryOffsets.clear(); + this.timestamps.clear(); + this.frames = []; this.pendingResolve = null; } @@ -86394,7 +86436,13 @@ class WebGPUBackend extends Backend { if ( renderContext.clearColor || discardColor || clearExternalColor ) { - if ( i === 0 ) { + const clearColor = renderContext.mrt ? renderContext.mrt.getClearColor( renderContext.textures[ i ].name ) : null; + + if ( clearColor !== null ) { + + colorAttachment.clearValue = clearColor; + + } else if ( i === 0 ) { colorAttachment.clearValue = renderContext.clearColorValue; @@ -90452,4 +90500,4 @@ class ClippingGroup extends Group { } -export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayCamera, ArrayElementNode, ArrayNode, AssignNode, AtomicFunctionNode, AttributeNode, BackSide, Backend, BarrierNode, BasicEnvironmentNode, BasicLightMapNode, BasicNodeLibrary, BasicShadowMap, BitcastNode, BitcountNode, BlendMode, BoxGeometry, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BuiltinNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CanvasTarget, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, ClippingNode, CodeNode, Color, ColorManagement, ColorSpaceNode, Compatibility, ComputeBuiltinNode, ComputeNode, ConditionalNode, ConstNode, ConstantAlphaFactor, ConstantColorFactor, ContextNode, ConvertNode, CubeCamera, CubeDepthTexture, CubeMapNode, CubeReflectionMapping, CubeRefractionMapping, CubeRenderTarget, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, CylinderGeometry, DataArrayTexture, DataTexture, DebugNode, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectRenderPipeline, DirectionalLight, DirectionalLightNode, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, EventDispatcher, EventNode, ExpressionNode, FileLoader, FlipNode, Float16BufferAttribute, Float32BufferAttribute, FloatType, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FrustumArray, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeBuilder, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InputNode, InspectorBase, InspectorNode, InstancedBufferAttribute, InstancedInterleavedBuffer, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, IsolateNode, JoinNode, KeepStencilOp, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, LightProbe, LightProbeNode, Lighting, LightingContextNode, LightingModel, LightingNode, LightsNode, Line2NodeMaterial, LineBasicMaterial, LineBasicNodeMaterial, LineDashedMaterial, LineDashedNodeMaterial, LinearFilter, LinearMipMapLinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoopNode, MRTNode, Material, MaterialBlending, MaterialLoader, MaterialNode, MaterialReferenceNode, MathNode, MathUtils, Matrix2, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, MemberNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoNormalPacking, NoToneMapping, Node, NodeAccess, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeError, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalGAPacking, NormalMapNode, NormalRGPacking, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OperatorNode, OrthographicCamera, OutputStructNode, OverrideContextNode, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, PMREMNode, PackFloatNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PlaneGeometry, PointLight, PointLightNode, PointShadowNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, ProjectorLight, ProjectorLightNode, PropertyNode, QuadMesh, Quaternion, R11_EAC_Format, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RG11_EAC_Format, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGBIntegerFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, ReadbackBuffer, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceBaseNode, ReferenceNode, ReflectorNode, ReinhardToneMapping, RenderObjectRefreshType, RenderOutputNode, RenderPipeline, RenderTarget, Renderer, RendererReferenceNode, RendererUtils, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RotateNode, SIGNED_R11_EAC_Format, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SIGNED_RG11_EAC_Format, SRGBColorSpace, SRGBTransfer, SampleNode, Scene, ScreenNode, SetNode, ShadowBaseNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, Sphere, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StackTrace, StandardNodeLibrary, StaticDrawUsage, Storage3DTexture, StorageArrayElementNode, StorageArrayTexture, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTexture3DNode, StorageTextureNode, StructNode, StructTypeNode, SubBuildNode, SubgroupFunctionNode, SubtractEquation, SubtractiveBlending, TSL, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, TimestampQuery, ToneMappingNode, ToonOutlinePassNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnpackFloatNode, UnsignedByteType, UnsignedInt101111Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, VarNode, VaryingNode, Vector2, Vector3, Vector4, VelocityNode, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WGSLNodeBuilder, WebGLBackend, WebGLCapabilities, WebGLCoordinateSystem, WebGPUBackend, WebGPUCoordinateSystem, WebGPURenderer, WebXRController, WorkgroupInfoNode, ZeroFactor, ZeroStencilOp, createCanvasElement, defaultBuildStages, defaultShaderStages, error, log$1 as log, shaderStages, vectorComponents, warn, warnOnce }; +export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayCamera, ArrayElementNode, ArrayNode, AssignNode, AtomicFunctionNode, AttributeNode, BackSide, Backend, BarrierNode, BasicEnvironmentNode, BasicLightMapNode, BasicNodeLibrary, BasicShadowMap, BitcastNode, BitcountNode, BlendMode, BoxGeometry, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BuiltinNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CanvasTarget, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, ClippingNode, CodeNode, Color, ColorManagement, ColorSpaceNode, Compatibility, ComputeBuiltinNode, ComputeNode, ConditionalNode, ConstNode, ConstantAlphaFactor, ConstantColorFactor, ContextNode, ConvertNode, CubeCamera, CubeDepthTexture, CubeMapNode, CubeReflectionMapping, CubeRefractionMapping, CubeRenderTarget, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, CylinderGeometry, DataArrayTexture, DataTexture, DebugNode, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectRenderPipeline, DirectionalLight, DirectionalLightNode, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, EventDispatcher, EventNode, ExpressionNode, FileLoader, FlipNode, Float16BufferAttribute, Float32BufferAttribute, FloatType, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FrustumArray, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeBuilder, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InputNode, InspectorBase, InspectorNode, InstancedBufferAttribute, InstancedInterleavedBuffer, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, IsolateNode, JoinNode, KeepStencilOp, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, LightProbe, LightProbeNode, Lighting, LightingContextNode, LightingModel, LightingNode, LightsNode, Line2NodeMaterial, LineBasicMaterial, LineBasicNodeMaterial, LineDashedMaterial, LineDashedNodeMaterial, LinearFilter, LinearMipMapLinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoopNode, MRTNode, Material, MaterialBlending, MaterialLoader, MaterialNode, MaterialReferenceNode, MathNode, MathUtils, Matrix2, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, MemberNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoNormalPacking, NoToneMapping, Node, NodeAccess, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeError, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalGAPacking, NormalMapNode, NormalRGPacking, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OperatorNode, OrthographicCamera, OutputStructNode, OverrideContextNode, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, PMREMNode, PackFloatNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PlaneGeometry, PointLight, PointLightNode, PointShadowNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, ProjectorLight, ProjectorLightNode, PropertyNode, QuadMesh, Quaternion, R11_EAC_Format, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RG11_EAC_Format, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGBIntegerFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, ReadbackBuffer, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceBaseNode, ReferenceElementNode, ReferenceNode, ReflectorNode, ReinhardToneMapping, RenderObjectRefreshType, RenderOutputNode, RenderPipeline, RenderTarget, Renderer, RendererReferenceNode, RendererUtils, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RotateNode, SIGNED_R11_EAC_Format, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SIGNED_RG11_EAC_Format, SRGBColorSpace, SRGBTransfer, SampleNode, Scene, ScreenNode, SetNode, ShadowBaseNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, Sphere, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StackTrace, StandardNodeLibrary, StaticDrawUsage, Storage3DTexture, StorageArrayElementNode, StorageArrayTexture, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTexture3DNode, StorageTextureNode, StructNode, StructTypeNode, SubBuildNode, SubgroupFunctionNode, SubtractEquation, SubtractiveBlending, TSL, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, TimestampQuery, ToneMappingNode, ToonOutlinePassNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnpackFloatNode, UnsignedByteType, UnsignedInt101111Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, VarNode, VaryingNode, Vector2, Vector3, Vector4, VelocityNode, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WGSLNodeBuilder, WebGLBackend, WebGLCapabilities, WebGLCoordinateSystem, WebGPUBackend, WebGPUCoordinateSystem, WebGPURenderer, WebXRController, WorkgroupInfoNode, ZeroFactor, ZeroStencilOp, createCanvasElement, defaultBuildStages, defaultShaderStages, error, log$1 as log, shaderStages, vectorComponents, warn, warnOnce }; diff --git a/build/three.webgpu.nodes.js b/build/three.webgpu.nodes.js index d89012f55978f3..78c0512985fda3 100644 --- a/build/three.webgpu.nodes.js +++ b/build/three.webgpu.nodes.js @@ -8804,11 +8804,17 @@ class ContextNode extends Node { analyze( builder ) { - const previousContext = builder.addContext( this.value ); + const usageCount = builder.increaseUsage( this ); + + if ( usageCount === 1 ) { - this.node.build( builder ); + const previousContext = builder.addContext( this.value ); - builder.setContext( previousContext ); + this.node.build( builder, this ); + + builder.setContext( previousContext ); + + } } @@ -8816,10 +8822,12 @@ class ContextNode extends Node { const previousContext = builder.addContext( this.value ); - this.node.build( builder ); + const node = this.node.build( builder ); builder.setContext( previousContext ); + return node; + } generate( builder, output ) { @@ -9836,8 +9844,6 @@ const convertColorSpace = ( node, sourceColorSpace, targetColorSpace ) => new Co addMethodChaining( 'workingToColorSpace', workingToColorSpace ); addMethodChaining( 'colorSpaceToWorking', colorSpaceToWorking ); -// TODO: Avoid duplicated code and use only ReferenceBaseNode or ReferenceNode - /** * This class is only relevant if the referenced property is array-like. * In this case, `ReferenceElementNode` allows to refer to a specific @@ -9845,7 +9851,7 @@ addMethodChaining( 'colorSpaceToWorking', colorSpaceToWorking ); * * @augments ArrayElementNode */ -let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode { +class ReferenceElementNode extends ArrayElementNode { static get type() { @@ -9856,7 +9862,7 @@ let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode /** * Constructs a new reference element node. * - * @param {ReferenceBaseNode} referenceNode - The reference node. + * @param {(ReferenceBaseNode|ReferenceNode)} referenceNode - The reference node. * @param {Node} indexNode - The index node that defines the element access. */ constructor( referenceNode, indexNode ) { @@ -9864,10 +9870,10 @@ let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode super( referenceNode, indexNode ); /** - * Similar to {@link ReferenceBaseNode#reference}, an additional + * Similar to {@link ReferenceNode#reference}, an additional * property references to the current node. * - * @type {?ReferenceBaseNode} + * @type {?(ReferenceBaseNode|ReferenceNode)} * @default null */ this.referenceNode = referenceNode; @@ -9898,14 +9904,16 @@ let ReferenceElementNode$1 = class ReferenceElementNode extends ArrayElementNode generate( builder ) { const snippet = super.generate( builder ); - const arrayType = this.referenceNode.getNodeType(); - const elementType = this.getNodeType(); + const arrayType = this.referenceNode.getNodeType( builder ); + const elementType = this.getNodeType( builder ); return builder.format( snippet, arrayType, elementType ); } -}; +} + +// TODO: Avoid duplicated code and use only ReferenceBaseNode or ReferenceNode /** * Base class for nodes which establishes a reference to a property of another object. @@ -10031,7 +10039,7 @@ class ReferenceBaseNode extends Node { */ element( indexNode ) { - return new ReferenceElementNode$1( this, nodeObject( indexNode ) ); + return new ReferenceElementNode( this, nodeObject( indexNode ) ); } @@ -11924,6 +11932,22 @@ class InspectorBase extends EventDispatcher { */ this.currentFrame = null; + /** + * Indicates whether the inspector is running. + * + * @type {boolean} + * @default false + */ + this.isRunning = false; + + /** + * Indicates whether the inspector is enabled. + * + * @type {boolean} + * @default true + */ + this.enabled = true; + } /** @@ -11970,12 +11994,20 @@ class InspectorBase extends EventDispatcher { /** * Called when a frame begins. */ - begin() { } + begin() { + + this.isRunning = true; + + } /** * Called when a frame ends. */ - finish() { } + finish() { + + this.isRunning = false; + + } /** * Inspects a node. @@ -15981,75 +16013,6 @@ const uniformCubeTexture = ( value = EmptyTexture ) => cubeTextureBase( value ); // TODO: Avoid duplicated code and use only ReferenceBaseNode or ReferenceNode -/** - * This class is only relevant if the referenced property is array-like. - * In this case, `ReferenceElementNode` allows to refer to a specific - * element inside the data structure via an index. - * - * @augments ArrayElementNode - */ -class ReferenceElementNode extends ArrayElementNode { - - static get type() { - - return 'ReferenceElementNode'; - - } - - /** - * Constructs a new reference element node. - * - * @param {?ReferenceNode} referenceNode - The reference node. - * @param {Node} indexNode - The index node that defines the element access. - */ - constructor( referenceNode, indexNode ) { - - super( referenceNode, indexNode ); - - /** - * Similar to {@link ReferenceNode#reference}, an additional - * property references to the current node. - * - * @type {?ReferenceNode} - * @default null - */ - this.referenceNode = referenceNode; - - /** - * This flag can be used for type testing. - * - * @type {boolean} - * @readonly - * @default true - */ - this.isReferenceElementNode = true; - - } - - /** - * This method is overwritten since the node type is inferred from - * the uniform type of the reference node. - * - * @return {string} The node type. - */ - generateNodeType() { - - return this.referenceNode.uniformType; - - } - - generate( builder ) { - - const snippet = super.generate( builder ); - const arrayType = this.referenceNode.getNodeType( builder ); - const elementType = this.getNodeType( builder ); - - return builder.format( snippet, arrayType, elementType ); - - } - -} - /** * This type of node establishes a reference to a property of another object. * In this way, the value of the node is automatically linked to the value of @@ -28719,7 +28682,7 @@ class ToonLightingModel extends LightingModel { */ direct( { lightDirection, lightColor, reflectedLight }, builder ) { - const irradiance = getGradientIrradiance( { normal: normalGeometry, lightDirection, builder } ).mul( lightColor ); + const irradiance = getGradientIrradiance( { normal: normalView, lightDirection, builder } ).mul( lightColor ); reflectedLight.directDiffuse.addAssign( irradiance.mul( BRDF_Lambert( { diffuseColor: diffuseColor.rgb } ) ) ); @@ -29826,6 +29789,12 @@ class Animation { this._requestId = this._context.requestAnimationFrame( update ); + if ( this.renderer._inspector.isRunning ) { + + this.renderer._inspector.finish(); + + } + if ( this.info.autoReset === true ) this.info.reset(); this.nodes.nodeFrame.update(); @@ -29834,9 +29803,11 @@ class Animation { this.renderer._inspector.begin(); - if ( this._animationLoop !== null ) this._animationLoop( time, xrFrame ); + if ( this._animationLoop !== null ) { + + this._animationLoop( time, xrFrame ); - this.renderer._inspector.finish(); + } }; @@ -29849,6 +29820,8 @@ class Animation { */ stop() { + if ( this.renderer._inspector.isRunning ) this.renderer._inspector.finish(); + if ( this._context !== null ) this._context.cancelAnimationFrame( this._requestId ); this._requestId = null; @@ -35275,6 +35248,15 @@ class Color4 extends Color { } + *[ Symbol.iterator ]() { + + yield this.r; + yield this.g; + yield this.b; + yield this.a; + + } + } /** @@ -36541,6 +36523,13 @@ class MRTNode extends OutputStructNode { output: _materialBlending }; + /** + * A dictionary storing the clear colors for each output. + * + * @type {Object} + */ + this.clearColors = {}; + /** * This flag can be used for type testing. * @@ -36579,6 +36568,38 @@ class MRTNode extends OutputStructNode { } + /** + * Sets the clear color for the given output name. + * + * @param {string} name - The name of the output. + * @param {number|string|Color} color - The clear color. + * @param {number} [alpha=1] - The clear alpha. + * @return {MRTNode} The current MRT node. + */ + setClearColor( name, color, alpha = 1 ) { + + const clearColor = this.clearColors[ name ] || ( this.clearColors[ name ] = new Color4() ); + + clearColor.set( color ); + clearColor.a = alpha; + + return this; + + } + + /** + * Returns the clear color for the given output name. + * + * @param {string} name - The name of the output. + * @return {?Color4} The clear color. Returns `null` if no clear color is defined + * which means the renderer's default clear policy is applied. + */ + getClearColor( name ) { + + return this.clearColors[ name ] || null; + + } + /** * Returns `true` if the MRT node has an output with the given name. * @@ -36612,10 +36633,12 @@ class MRTNode extends OutputStructNode { merge( mrtNode ) { const outputs = { ...this.outputNodes, ...mrtNode.outputNodes }; - const blendings = { ...this.blendModes, ...mrtNode.blendModes }; + const blendModes = { ...this.blendModes, ...mrtNode.blendModes }; + const clearColors = { ...this.clearColors, ...mrtNode.clearColors }; const mrtTarget = mrt( outputs ); - mrtTarget.blendings = blendings; + mrtTarget.blendModes = blendModes; + mrtTarget.clearColors = clearColors; return mrtTarget; @@ -72180,11 +72203,14 @@ class WebGLTimestampQueryPool extends TimestampQueryPool { if ( ! this.trackTimestamp ) return null; - // Check if we have enough space for a new query pair if ( this.currentQueryIndex + 2 > this.maxQueries ) { - warnOnce( `WebGLTimestampQueryPool [${ this.type }]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${ this.type.toUpperCase() } ).` ); - return null; + this.resolveQueriesAsync(); + + this.currentQueryIndex = 0; + this.queryOffsets.clear(); + this.queryStates.clear(); + this.activeQuery = null; } @@ -72344,6 +72370,8 @@ class WebGLTimestampQueryPool extends TimestampQueryPool { const frames = []; + this.timestamps.clear(); + for ( const [ uid, promise ] of resolvePromises ) { const match = uid.match( /^(.*):f(\d+)$/ ); @@ -72508,6 +72536,8 @@ class WebGLTimestampQueryPool extends TimestampQueryPool { this.queries = []; this.queryStates.clear(); this.queryOffsets.clear(); + this.timestamps.clear(); + this.frames = []; this.lastValue = 0; this.activeQuery = null; @@ -73335,7 +73365,13 @@ class WebGLBackend extends Backend { for ( let i = 0; i < descriptor.textures.length; i ++ ) { - if ( i === 0 ) { + const mrtClearColor = descriptor.mrt ? descriptor.mrt.getClearColor( descriptor.textures[ i ].name ) : null; + + if ( mrtClearColor !== null ) { + + gl.clearBufferfv( gl.COLOR, i, [ mrtClearColor.r, mrtClearColor.g, mrtClearColor.b, mrtClearColor.a ] ); + + } else if ( i === 0 ) { gl.clearBufferfv( gl.COLOR, i, [ clearColor.r, clearColor.g, clearColor.b, clearColor.a ] ); @@ -85024,8 +85060,10 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool { if ( this.currentQueryIndex + 2 > this.maxQueries ) { - warnOnce( `WebGPUTimestampQueryPool [${ this.type }]: Maximum number of queries exceeded, when using trackTimestamp it is necessary to resolves the queries via renderer.resolveTimestampsAsync( THREE.TimestampQuery.${ this.type.toUpperCase() } ).` ); - return null; + this.resolveQueriesAsync(); + + this.currentQueryIndex = 0; + this.queryOffsets.clear(); } @@ -85154,6 +85192,8 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool { const frames = []; + this.timestamps.clear(); + for ( const [ uid, baseOffset ] of currentOffsets ) { const match = uid.match( /^(.*):f(\d+)$/ ); @@ -85270,6 +85310,8 @@ class WebGPUTimestampQueryPool extends TimestampQueryPool { } this.queryOffsets.clear(); + this.timestamps.clear(); + this.frames = []; this.pendingResolve = null; } @@ -86394,7 +86436,13 @@ class WebGPUBackend extends Backend { if ( renderContext.clearColor || discardColor || clearExternalColor ) { - if ( i === 0 ) { + const clearColor = renderContext.mrt ? renderContext.mrt.getClearColor( renderContext.textures[ i ].name ) : null; + + if ( clearColor !== null ) { + + colorAttachment.clearValue = clearColor; + + } else if ( i === 0 ) { colorAttachment.clearValue = renderContext.clearColorValue; @@ -90170,4 +90218,4 @@ class ClippingGroup extends Group { } -export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayCamera, ArrayElementNode, ArrayNode, AssignNode, AtomicFunctionNode, AttributeNode, BackSide, BarrierNode, BasicEnvironmentNode, BasicLightMapNode, BasicShadowMap, BitcastNode, BitcountNode, BlendMode, BoxGeometry, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BuiltinNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CanvasTarget, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, ClippingNode, CodeNode, Color, ColorManagement, ColorSpaceNode, Compatibility, ComputeBuiltinNode, ComputeNode, ConditionalNode, ConstNode, ConstantAlphaFactor, ConstantColorFactor, ContextNode, ConvertNode, CubeCamera, CubeDepthTexture, CubeMapNode, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, CylinderGeometry, DataArrayTexture, DataTexture, DebugNode, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectRenderPipeline, DirectionalLight, DirectionalLightNode, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, EventDispatcher, EventNode, ExpressionNode, FileLoader, FlipNode, Float16BufferAttribute, Float32BufferAttribute, FloatType, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FrustumArray, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InputNode, InspectorBase, InspectorNode, InstancedBufferAttribute, InstancedInterleavedBuffer, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, IsolateNode, JoinNode, KeepStencilOp, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, LightProbe, LightProbeNode, Lighting, LightingContextNode, LightingModel, LightingNode, LightsNode, Line2NodeMaterial, LineBasicMaterial, LineBasicNodeMaterial, LineDashedMaterial, LineDashedNodeMaterial, LinearFilter, LinearMipMapLinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoopNode, MRTNode, Material, MaterialBlending, MaterialLoader, MaterialNode, MaterialReferenceNode, MathNode, MathUtils, Matrix2, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, MemberNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoNormalPacking, NoToneMapping, Node, NodeAccess, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeError, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalGAPacking, NormalMapNode, NormalRGPacking, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OperatorNode, OrthographicCamera, OutputStructNode, OverrideContextNode, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, PMREMNode, PackFloatNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PlaneGeometry, PointLight, PointLightNode, PointShadowNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, ProjectorLight, ProjectorLightNode, PropertyNode, QuadMesh, Quaternion, R11_EAC_Format, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RG11_EAC_Format, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGBIntegerFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, ReadbackBuffer, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceBaseNode, ReferenceNode, ReflectorNode, ReinhardToneMapping, RenderObjectRefreshType, RenderOutputNode, RenderPipeline, RenderTarget, RendererReferenceNode, RendererUtils, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RotateNode, SIGNED_R11_EAC_Format, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SIGNED_RG11_EAC_Format, SRGBColorSpace, SRGBTransfer, SampleNode, Scene, ScreenNode, SetNode, ShadowBaseNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, Sphere, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StackTrace, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTexture3DNode, StorageTextureNode, StructNode, StructTypeNode, SubBuildNode, SubgroupFunctionNode, SubtractEquation, SubtractiveBlending, TSL, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, TimestampQuery, ToneMappingNode, ToonOutlinePassNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnpackFloatNode, UnsignedByteType, UnsignedInt101111Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, VarNode, VaryingNode, Vector2, Vector3, Vector4, VelocityNode, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLBackend, WebGLCoordinateSystem, WebGPUBackend, WebGPUCoordinateSystem, WebGPURenderer, WebXRController, WorkgroupInfoNode, ZeroFactor, ZeroStencilOp, createCanvasElement, defaultBuildStages, defaultShaderStages, error, log$1 as log, shaderStages, vectorComponents, warn, warnOnce }; +export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayCamera, ArrayElementNode, ArrayNode, AssignNode, AtomicFunctionNode, AttributeNode, BackSide, BarrierNode, BasicEnvironmentNode, BasicLightMapNode, BasicShadowMap, BitcastNode, BitcountNode, BlendMode, BoxGeometry, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BuiltinNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CanvasTarget, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, ClippingNode, CodeNode, Color, ColorManagement, ColorSpaceNode, Compatibility, ComputeBuiltinNode, ComputeNode, ConditionalNode, ConstNode, ConstantAlphaFactor, ConstantColorFactor, ContextNode, ConvertNode, CubeCamera, CubeDepthTexture, CubeMapNode, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, CylinderGeometry, DataArrayTexture, DataTexture, DebugNode, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectRenderPipeline, DirectionalLight, DirectionalLightNode, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, EventDispatcher, EventNode, ExpressionNode, FileLoader, FlipNode, Float16BufferAttribute, Float32BufferAttribute, FloatType, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FrustumArray, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InputNode, InspectorBase, InspectorNode, InstancedBufferAttribute, InstancedInterleavedBuffer, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, IsolateNode, JoinNode, KeepStencilOp, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, LightProbe, LightProbeNode, Lighting, LightingContextNode, LightingModel, LightingNode, LightsNode, Line2NodeMaterial, LineBasicMaterial, LineBasicNodeMaterial, LineDashedMaterial, LineDashedNodeMaterial, LinearFilter, LinearMipMapLinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoopNode, MRTNode, Material, MaterialBlending, MaterialLoader, MaterialNode, MaterialReferenceNode, MathNode, MathUtils, Matrix2, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, MemberNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoNormalPacking, NoToneMapping, Node, NodeAccess, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeError, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalGAPacking, NormalMapNode, NormalRGPacking, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OperatorNode, OrthographicCamera, OutputStructNode, OverrideContextNode, PCFShadowMap, PCFSoftShadowMap, PMREMGenerator, PMREMNode, PackFloatNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PlaneGeometry, PointLight, PointLightNode, PointShadowNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, ProjectorLight, ProjectorLightNode, PropertyNode, QuadMesh, Quaternion, R11_EAC_Format, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RG11_EAC_Format, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBFormat, RGBIntegerFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, ReadbackBuffer, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceBaseNode, ReferenceElementNode, ReferenceNode, ReflectorNode, ReinhardToneMapping, RenderObjectRefreshType, RenderOutputNode, RenderPipeline, RenderTarget, RendererReferenceNode, RendererUtils, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RotateNode, SIGNED_R11_EAC_Format, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SIGNED_RG11_EAC_Format, SRGBColorSpace, SRGBTransfer, SampleNode, Scene, ScreenNode, SetNode, ShadowBaseNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, Sphere, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StackTrace, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTexture3DNode, StorageTextureNode, StructNode, StructTypeNode, SubBuildNode, SubgroupFunctionNode, SubtractEquation, SubtractiveBlending, TSL, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, TimestampQuery, ToneMappingNode, ToonOutlinePassNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnpackFloatNode, UnsignedByteType, UnsignedInt101111Type, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, VarNode, VaryingNode, Vector2, Vector3, Vector4, VelocityNode, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLBackend, WebGLCoordinateSystem, WebGPUBackend, WebGPUCoordinateSystem, WebGPURenderer, WebXRController, WorkgroupInfoNode, ZeroFactor, ZeroStencilOp, createCanvasElement, defaultBuildStages, defaultShaderStages, error, log$1 as log, shaderStages, vectorComponents, warn, warnOnce }; From 9a5e80081f72ef0b3862cdaeafc72595381b4362 Mon Sep 17 00:00:00 2001 From: gqfx <115675424+gqfx@users.noreply.github.com> Date: Sat, 15 Aug 2026 17:30:30 +0800 Subject: [PATCH 2/2] GaussianSplatMesh: Fix sort invalidation for transforms (#34233) Co-authored-by: gaoqiang Co-authored-by: Michael Herzog --- examples/jsm/objects/GaussianSplatMesh.js | 42 +++++++++-------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/examples/jsm/objects/GaussianSplatMesh.js b/examples/jsm/objects/GaussianSplatMesh.js index ab53fc74c4f713..f81363ed5ac55d 100644 --- a/examples/jsm/objects/GaussianSplatMesh.js +++ b/examples/jsm/objects/GaussianSplatMesh.js @@ -47,7 +47,6 @@ import { const BIN_COUNT = 4096; const WORKGROUP_SIZE = 256; const SORT_DIRECTION_THRESHOLD = 0.9995; -const SORT_POSITION_THRESHOLD = 0.0025; const KERNEL_2D_SIZE = 0.3; const MAX_SCREEN_SPACE_SPLAT_SIZE = 1024; const CLIP_XY = 1.4; @@ -55,10 +54,10 @@ const CLIP_XY = 1.4; const _worldCenter = /*@__PURE__*/ new Vector3(); const _viewCenter = /*@__PURE__*/ new Vector3(); const _worldScale = /*@__PURE__*/ new Vector3(); -const _cameraPosition = /*@__PURE__*/ new Vector3(); -const _cameraDirection = /*@__PURE__*/ new Vector3(); +const _sortDirection = /*@__PURE__*/ new Vector3(); const _sortDepthRange = /*@__PURE__*/ new Vector2(); const _worldMatrixInverse = /*@__PURE__*/ new Matrix4(); +const _modelViewMatrix = /*@__PURE__*/ new Matrix4(); /** * A minimal renderer for 3D Gaussian splat geometry. @@ -143,8 +142,7 @@ class GaussianSplatMesh extends Mesh { this._sortMatrix = uniform( new Matrix4() ); this._sortDepthRange = uniform( new Vector2( 0, 1 ) ); this._sortInitialized = false; - this._lastSortPosition = new Vector3( Infinity, Infinity, Infinity ); - this._lastSortDirection = new Vector3( 0, 0, - 1 ); + this._lastSortDirection = new Vector3(); this._localCameraPosition = localCameraPosition; this._sphericalHarmonicsComputeNode = sphericalHarmonicsComputeNode; this._sphericalHarmonicsInitialized = false; @@ -242,7 +240,8 @@ class GaussianSplatMesh extends Mesh { } /** - * Updates the draw order if the camera has moved enough to need a new sort. + * Updates the draw order if the camera or mesh orientation has changed enough + * to need a new sort. * * @param {Renderer} renderer - The renderer. * @param {Camera} camera - The camera used for rendering. @@ -250,7 +249,11 @@ class GaussianSplatMesh extends Mesh { */ updateSort( renderer, camera ) { - if ( this._sortInitialized === false || this._needsSort( camera ) === true ) { + this.updateWorldMatrix( true, false ); + + const needsSort = this._needsSort( camera ); + + if ( this._sortInitialized === false || needsSort === true ) { this._updateSortUniforms( camera ); @@ -267,6 +270,7 @@ class GaussianSplatMesh extends Mesh { } this._sortInitialized = true; + this._lastSortDirection.copy( _sortDirection ); return true; @@ -278,35 +282,23 @@ class GaussianSplatMesh extends Mesh { _needsSort( camera ) { - _cameraPosition.setFromMatrixPosition( camera.matrixWorld ); - - const e = camera.matrixWorld.elements; - _cameraDirection.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize(); + _modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, this.matrixWorld ); - const positionChanged = _cameraPosition.distanceToSquared( this._lastSortPosition ) > SORT_POSITION_THRESHOLD * SORT_POSITION_THRESHOLD; - const directionChanged = _cameraDirection.dot( this._lastSortDirection ) < SORT_DIRECTION_THRESHOLD; + const e = _modelViewMatrix.elements; + _sortDirection.set( e[ 2 ], e[ 6 ], e[ 10 ] ).normalize(); - if ( positionChanged === true || directionChanged === true ) { - - this._lastSortPosition.copy( _cameraPosition ); - this._lastSortDirection.copy( _cameraDirection ); - return true; - - } - - return false; + return _sortDirection.dot( this._lastSortDirection ) < SORT_DIRECTION_THRESHOLD; } _updateSortUniforms( camera ) { - this.updateWorldMatrix( true, false ); - this._sortMatrix.value.multiplyMatrices( camera.matrixWorldInverse, this.matrixWorld ); _worldCenter.copy( this.splatGeometry.boundingSphere.center ).applyMatrix4( this.matrixWorld ); _viewCenter.copy( _worldCenter ).applyMatrix4( camera.matrixWorldInverse ); - this.getWorldScale( _worldScale ); + + _worldScale.setFromMatrixScale( this.matrixWorld ); const radius = this.splatGeometry.boundingSphere.radius * Math.max( _worldScale.x, _worldScale.y, _worldScale.z ); const depth = - _viewCenter.z;