From 52939b203196c0f07c4199468c3a1308ec4408ee Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Sat, 16 Nov 2024 09:18:02 +0100 Subject: [PATCH 01/24] storageStruct --- src/nodes/TSL.js | 1 + src/nodes/accessors/StorageBufferNode.js | 10 +++ src/nodes/core/StructTypeNode.js | 16 ++++ src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 83 +++++++++++++++++-- 4 files changed, 102 insertions(+), 8 deletions(-) diff --git a/src/nodes/TSL.js b/src/nodes/TSL.js index ded6a8ef5bcc8d..f8a0f9522b1057 100644 --- a/src/nodes/TSL.js +++ b/src/nodes/TSL.js @@ -11,6 +11,7 @@ export * from './core/IndexNode.js'; export * from './core/ParameterNode.js'; export * from './core/PropertyNode.js'; export * from './core/StackNode.js'; +export * from './core/StructTypeNode.js'; export * from './core/UniformGroupNode.js'; export * from './core/UniformNode.js'; export * from './core/VaryingNode.js'; diff --git a/src/nodes/accessors/StorageBufferNode.js b/src/nodes/accessors/StorageBufferNode.js index 8cfe16237d59af..1689ccc738077c 100644 --- a/src/nodes/accessors/StorageBufferNode.js +++ b/src/nodes/accessors/StorageBufferNode.js @@ -22,6 +22,7 @@ class StorageBufferNode extends BufferNode { this.isAtomic = false; this.bufferObject = false; + this.bufferStruct = false; this.bufferCount = bufferCount; this._attribute = null; @@ -84,6 +85,14 @@ class StorageBufferNode extends BufferNode { } + setBufferStruct( value ) { + + this.bufferStruct = value; + + return this; + + } + setAccess( value ) { this.access = value; @@ -166,4 +175,5 @@ export default StorageBufferNode; // Read-Write Storage export const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) ); +export const storageStruct = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferStruct( true ) ); export const storageObject = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferObject( true ) ); diff --git a/src/nodes/core/StructTypeNode.js b/src/nodes/core/StructTypeNode.js index 288ea9535096aa..231ccdf2c91249 100644 --- a/src/nodes/core/StructTypeNode.js +++ b/src/nodes/core/StructTypeNode.js @@ -26,3 +26,19 @@ class StructTypeNode extends Node { } export default StructTypeNode; + +export const struct = ( members ) => { + + return Object.entries( members ).map( ( [ name, value ] ) => { + + if ( typeof value === 'string' ) { + + return { name, type: value, isAtomic: false }; + + } + + return { name, type: value.type, isAtomic: value.atomic || false }; + + } ); + +}; \ No newline at end of file diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index f3b71446153dd0..d11d4384266d31 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -964,6 +964,45 @@ ${ flowData.code } } + getStructType( shaderStage ) { + + const uniforms = this.uniforms[ shaderStage ]; + + const bufferStructMap = new Map(); + + uniforms.forEach( ( uniform ) => { + + const { name, node } = uniform; + const hasBufferStruct = node.bufferStruct === true; + bufferStructMap.set( name, hasBufferStruct ); + + } ); + + return bufferStructMap; + + } + + getBufferStructMembers( members ) { + + const structMembers = members.map( ( { name, type, isAtomic } ) => { + + let finalType = wgslTypeLib[ type ]; + + if ( ! finalType ) { + + console.warn( `Unrecognized type: ${type}` ); + finalType = 'vec4'; + + } + + return `${name}: ${isAtomic ? `atomic<${finalType}>` : finalType}`; + + } ); + + return `\t${structMembers.join( ',\n\t' )}`; + + } + getStructMembers( struct ) { const snippets = []; @@ -1171,12 +1210,14 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; + const structName = uniform.value.name; + const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; - const bufferSnippet = `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; + const bufferSnippet = bufferNode.bufferStruct ? this.getBufferStructMembers( bufferType ) : `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform'; - bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); + bufferSnippets.push( this._getWGSLStructBinding( bufferNode.bufferStruct, isArray, 'NodeBuffer_' + bufferNode.id, structName, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); } else { @@ -1199,7 +1240,7 @@ ${ flowData.code } const group = uniformGroups[ name ]; - structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); + structSnippets.push( this._getWGSLStructBinding( false, false, name, undefined, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); } @@ -1228,9 +1269,20 @@ ${ flowData.code } stageData.codes = this.getCodes( shaderStage ); stageData.directives = this.getDirectives( shaderStage ); stageData.scopedArrays = this.getScopedArrays( shaderStage ); + stageData.bufferStruct = this.getStructType( shaderStage ); // + const reduceFlow = ( flow ) => { + + return flow.replace( /&(\w+)\.(\w+)/g, ( match, bufferName, uniformName ) => + + stageData.bufferStruct.get( uniformName ) === true ? `&${bufferName}` : match + + ); + + }; + let flow = '// code\n\n'; flow += this.flowCode[ shaderStage ]; @@ -1255,6 +1307,8 @@ ${ flowData.code } flow += `${ flowSlotData.code }\n\t`; + flow = reduceFlow( flow ); + if ( node === mainNode && shaderStage !== 'compute' ) { flow += '// result\n\n\t'; @@ -1493,14 +1547,27 @@ ${vars} } - _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) { + _getWGSLStructBinding( isBufferStruct, isArray, name, structName, vars, access, binding = 0, group = 0 ) { + + if ( ! isBufferStruct ) { - const structName = name + 'Struct'; - const structSnippet = this._getWGSLStruct( structName, vars ); + const _structName = name + 'Struct'; + const structSnippet = this._getWGSLStruct( _structName, vars ); - return `${structSnippet} + return `${structSnippet} @binding( ${binding} ) @group( ${group} ) -var<${access}> ${name} : ${structName};`; +var<${access}> ${name} : ${_structName};`; + + } else { + + const structSnippet = this._getWGSLStruct( structName, vars ); + const structAccessor = isArray ? `array<${structName}>` : structName; + + return `${structSnippet} +@binding( ${binding} ) @group( ${group} ) +var<${access}> ${name} : ${structAccessor};`; + + } } From 13461f0e39be11c1e48bd0dc794373a41dafce10 Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Sat, 16 Nov 2024 10:03:20 +0100 Subject: [PATCH 02/24] Update StructTypeNode.js fix lint --- src/nodes/core/StructTypeNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nodes/core/StructTypeNode.js b/src/nodes/core/StructTypeNode.js index 231ccdf2c91249..e309ac38f23589 100644 --- a/src/nodes/core/StructTypeNode.js +++ b/src/nodes/core/StructTypeNode.js @@ -41,4 +41,4 @@ export const struct = ( members ) => { } ); -}; \ No newline at end of file +}; From 0930b480e1290e3dcee6231cf6cf267bba897ae4 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Sun, 17 Nov 2024 19:41:09 +0100 Subject: [PATCH 03/24] Extended functionality to vertex and fragment shaders too --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index d11d4384266d31..3c03de05d112aa 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1343,6 +1343,8 @@ ${ flowData.code } } + flow = reduceFlow( flow ); + } } From eefe48a019e243b9a86ebd288bf02723c5464ea0 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Tue, 19 Nov 2024 03:23:23 +0100 Subject: [PATCH 04/24] improved struct name managment --- build/three.webgpu.js | 261 +++++++++++++++++- build/three.webgpu.min.js | 2 +- build/three.webgpu.nodes.js | 261 +++++++++++++++++- build/three.webgpu.nodes.min.js | 2 +- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 186 +++++++++++-- 5 files changed, 682 insertions(+), 30 deletions(-) diff --git a/build/three.webgpu.js b/build/three.webgpu.js index a1b0490a2a860b..402dab5d779295 100644 --- a/build/three.webgpu.js +++ b/build/three.webgpu.js @@ -16322,6 +16322,22 @@ class StructTypeNode extends Node { } +const struct = ( members ) => { + + return Object.entries( members ).map( ( [ name, value ] ) => { + + if ( typeof value === 'string' ) { + + return { name, type: value, isAtomic: false }; + + } + + return { name, type: value.type, isAtomic: value.atomic || false }; + + } ); + +}; + class OutputStructNode extends Node { static get type() { @@ -17974,6 +17990,7 @@ class StorageBufferNode extends BufferNode { this.isAtomic = false; this.bufferObject = false; + this.bufferStruct = false; this.bufferCount = bufferCount; this._attribute = null; @@ -18036,6 +18053,14 @@ class StorageBufferNode extends BufferNode { } + setBufferStruct( value ) { + + this.bufferStruct = value; + + return this; + + } + setAccess( value ) { this.access = value; @@ -18116,6 +18141,7 @@ class StorageBufferNode extends BufferNode { // Read-Write Storage const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) ); +const storageStruct = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferStruct( true ) ); const storageObject = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferObject( true ) ); class StorageTextureNode extends TextureNode { @@ -38037,6 +38063,88 @@ ${ flowData.code } } + getTypeFromCustomStruct( shaderStage ) { + + const uniforms = this.uniforms[ shaderStage ]; + + const bufferStructMap = new Map(); + + uniforms.forEach( ( uniform ) => { + + const { name, node } = uniform; + const hasBufferStruct = node.bufferStruct === true; + bufferStructMap.set( name, hasBufferStruct ); + + } ); + + return bufferStructMap; + + } + + getMembersFromCustomStruct( members ) { + + const structMembers = members.map( ( { name, type, isAtomic } ) => { + + let finalType = wgslTypeLib[ type ]; + + if ( ! finalType ) { + + console.warn( `Unrecognized type: ${type}` ); + finalType = 'vec4'; + + } + + return `${name}: ${isAtomic ? `atomic<${finalType}>` : finalType}`; + + } ); + + return `\t${structMembers.join( ',\n\t' )}`; + + } + + getCustomStructNameFromShader( source ) { + + const functionRegex = /fn\s+\w+\s*\(([\s\S]*?)\)/g; // filter shader header + const parameterRegex = /(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g; // filter parameters + + const results = []; + + let match; + + while ( ( match = functionRegex.exec( source ) ) !== null ) { + + const parameterString = match[ 1 ]; + + let paramMatch; + + while ( ( paramMatch = parameterRegex.exec( parameterString ) ) !== null ) { + + const [ fullMatch, name, fullType, ptrType, arrayType, directStructName ] = paramMatch; + + const structName = arrayType || directStructName || null; + + const type = ptrType || fullType; + + if (Object.values(wgslTypeLib).includes(structName) || structName === null) { + + continue; + + } + + results.push( { + name, + type, + structName + } ); + + } + + } + + return results; + + } + getStructMembers( struct ) { const snippets = []; @@ -38244,12 +38352,14 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; + + const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; - const bufferSnippet = `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; + const bufferSnippet = bufferNode.bufferStruct ? this.getMembersFromCustomStruct( bufferType ) : `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform'; - bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); + bufferSnippets.push( this._getWGSLStructBinding( bufferNode.bufferStruct, isArray, 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); } else { @@ -38272,7 +38382,7 @@ ${ flowData.code } const group = uniformGroups[ name ]; - structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); + structSnippets.push( this._getWGSLStructBinding( false, false, name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); } @@ -38301,9 +38411,69 @@ ${ flowData.code } stageData.codes = this.getCodes( shaderStage ); stageData.directives = this.getDirectives( shaderStage ); stageData.scopedArrays = this.getScopedArrays( shaderStage ); + stageData.isBufferStruct = this.getTypeFromCustomStruct( shaderStage ); + stageData.customStructNames = this.getCustomStructNameFromShader( stageData.codes ); // + const reduceFlow = ( flow ) => { + + return flow.replace( /&(\w+)\.(\w+)/g, ( match, bufferName, uniformName ) => + + stageData.isBufferStruct.get( uniformName ) === true ? `&${bufferName}` : match + + ); + + }; + + const extractPointerNames = ( source ) => { + + const match = source.match( /\(([^)]+)\)/ ); + if ( ! match ) return []; + + const content = match[ 1 ]; + + return content + .split( /\s*,\s*/ ) + .map( part => part.trim() ) + .filter( part => part.includes( '&' ) ) + .map( part => part.replace( '&', '' ) ) + .filter( part => ! part.includes( '.' ) ); + + }; + + const createStructNameMapping = ( nodeBuffers, structs ) => { + + const resultMap = new Map(); + + for (let i = 0; i < nodeBuffers.length; i++) { + + const bufferName = nodeBuffers[i]; + const struct = structs[i]; + + resultMap.set(bufferName, struct.structName); + + } + + return resultMap; + + }; + + const replaceStructNamesInUniforms = ( shaderCode, map ) => { + + for ( const [ key, value ] of map.entries() ) { + + const regex = new RegExp( `\\b${key}Struct\\b`, 'g' ); + shaderCode = shaderCode.replace( regex, value ); + + } + + return shaderCode; + + }; + + + let pointerNames, structnameMapping; let flow = '// code\n\n'; flow += this.flowCode[ shaderStage ]; @@ -38328,6 +38498,68 @@ ${ flowData.code } flow += `${ flowSlotData.code }\n\t`; + + /* + REVIEW COMMENT remove after review + + before reduceFlow: + compute( &NodeBuffer_554.nodeUniform0, &NodeBuffer_558.nodeUniform1, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); + + after reduceFlow: reduceFlow checks whether there is a storageStruct and if so then the + postfix is ​​removed so that the pointer points to the struct and not to a content in the struct + compute( &NodeBuffer_554, &NodeBuffer_558, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); + + extractPointerNames reads the names of the reduced pointers and stores them in an array + Array(2) + 0: "NodeBuffer_554" + 1: "NodeBuffer_558" + + getCustomStructNameFromShader at the beginning reads the structNames from the shader header + Array(2) + 0: {name: 'drawBuffer', type: 'storage', structName: 'DrawBuffer'} + 1: {name: 'meshletInfo', type: 'storage', structName: 'MeshletInfo'} + + + createStructNameMapping links the automatic generated WGSLNodeBuilder for each struct with the struct name specified by the user. + This is necessary because in wgslFn the user can choose any name in the shader in ptr for structs. + + Map(2) + [[Entries]] + 0: {"NodeBuffer_554" => "DrawBuffer"} + 1: {"NodeBuffer_558" => "MeshletInfo"} + + replaceStructNames then replaces the names in the uniforms in the custom structs that the WGSLNodeBuilder + created with the name chosen by the user. + + before replaceStructNames: + + struct NodeBuffer_554Struct { + vertexCount: u32, + instanceCount: u32, + firstVertex: u32, + firstInstance: u32 + }; + @binding( 0 ) @group( 0 ) + var NodeBuffer_554 : NodeBuffer_554Struct; + + after replaceStructNames: + + struct DrawBuffer { + vertexCount: u32, + instanceCount: u32, + firstVertex: u32, + firstInstance: u32 + }; + @binding( 0 ) @group( 0 ) + var NodeBuffer_554 : DrawBuffer; + */ + + + flow = reduceFlow( flow ); + pointerNames = extractPointerNames(flow); + structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); + stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); + if ( node === mainNode && shaderStage !== 'compute' ) { flow += '// result\n\n\t'; @@ -38362,6 +38594,11 @@ ${ flowData.code } } + flow = reduceFlow( flow ); + pointerNames = extractPointerNames(flow); + structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); + stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); + } } @@ -38566,15 +38803,27 @@ ${vars} } - _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) { + _getWGSLStructBinding( isBufferStruct, isArray, name, vars, access, binding = 0, group = 0 ) { const structName = name + 'Struct'; const structSnippet = this._getWGSLStruct( structName, vars ); - return `${structSnippet} + if ( ! isBufferStruct ) { + + return `${structSnippet} @binding( ${binding} ) @group( ${group} ) var<${access}> ${name} : ${structName};`; + } else { + + const StructName = isArray ? `array<${structName}>` : structName; + + return `${structSnippet} +@binding( ${binding} ) @group( ${group} ) +var<${access}> ${name} : ${StructName};`; + + } + } } @@ -42210,4 +42459,4 @@ class ClippingGroup extends Group { } -export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BRDF_GGX, BRDF_Lambert, BackSide, BasicEnvironmentNode, BatchNode, BoxGeometry, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DFGApprox, D_GGX, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, Discard, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EPSILON, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, F_Schlick, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fn, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, If, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, 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, Loader, Loop, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap$1 as PCFShadowMap, PI, PI2, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, 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_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScreenNode, ScriptableNode, ScriptableNodeResources, ScriptableValueNode, SetNode, ShaderNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, abs, acesFilmicToneMapping, acos, add, addMethodChaining, addNodeElement, agxToneMapping, all, alphaT, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, atomicAdd, atomicAnd, atomicFunc, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, attenuationColor, attenuationDistance, attribute, backgroundBlurriness, backgroundIntensity, backgroundRotation, batch, billboarding, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blendNormal, blur, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, cdl, ceil, checker, cineonToneMapping, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToWorking, colorToDirection, compute, cond, context, convert, convertColorSpace, convertToTexture, cos, createCanvasElement, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, deltaTime, densityFog, depth, depthPass, difference, diffuseColor, directPointLight, directionToColor, dispersion, distance, div, dodge, dot, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getNormalFromDepth, getParallaxCorrectNormal, getRoughness, getScreenPosition, getShIrradianceAt, getTextureIndex, getViewPosition, glsl, glslFn, grayscale, greaterThan, greaterThanEqual, hash, highPrecisionModelNormalViewMatrix, highPrecisionModelViewMatrix, hue, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, invocationLocalIndex, invocationSubgroupIndex, ior, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightPosition, lightTargetDirection, lightTargetPosition, lightViewPosition, lightingContext, lights, linearDepth, linearToneMapping, localId, log, log2, logarithmicDepthToViewZ, loop, luminance, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialAttenuationColor, materialAttenuationDistance, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIOR, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRefractionRatio, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularColor, materialSpecularIntensity, materialSpecularStrength, materialThickness, materialTransmission, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mixElement, mod, modInt, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, neutralToneMapping, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalFlat, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, notEqual, numWorkgroups, objectDirection, objectGroup, objectPosition, objectScale, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionPrevious, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, reinhardToneMapping, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rotate, rotateUV, roughness, round, rtt, sRGBTransferEOTF, sRGBTransferOETF, sampler, saturate, saturation, screen, screenCoordinate, screenSize, screenUV, scriptable, scriptableValue, select, setCurrentStack, shaderStages, shadow, sharedUniformGroup, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, smoothstepElement, specularColor, specularF90, spherizeUV, split, spritesheetUV, sqrt, stack, step, storage, storageBarrier, storageObject, storageTexture, string, sub, subgroupIndex, subgroupSize, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBarrier, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, thickness, threshold, time, timerDelta, timerGlobal, timerLocal, toOutputColorSpace, toWorkingColorSpace, toneMapping, toneMappingExposure, toonOutlinePass, transformDirection, transformNormal, transformNormalToView, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transmission, transpose, tri, tri3, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, uniform, uniformArray, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, velocity, vertexColor, vertexIndex, vibrance, viewZToLogarithmicDepth, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSafeUV, viewportSharedTexture, viewportSize, viewportTexture, viewportTopLeft, viewportUV, wgsl, wgslFn, workgroupArray, workgroupBarrier, workgroupId, workingToColorSpace, xor }; +export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BRDF_GGX, BRDF_Lambert, BackSide, BasicEnvironmentNode, BatchNode, BoxGeometry, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DFGApprox, D_GGX, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, Discard, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EPSILON, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, F_Schlick, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fn, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, If, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, 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, Loader, Loop, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap$1 as PCFShadowMap, PI, PI2, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, 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_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScreenNode, ScriptableNode, ScriptableNodeResources, ScriptableValueNode, SetNode, ShaderNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, abs, acesFilmicToneMapping, acos, add, addMethodChaining, addNodeElement, agxToneMapping, all, alphaT, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, atomicAdd, atomicAnd, atomicFunc, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, attenuationColor, attenuationDistance, attribute, backgroundBlurriness, backgroundIntensity, backgroundRotation, batch, billboarding, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blendNormal, blur, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, cdl, ceil, checker, cineonToneMapping, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToWorking, colorToDirection, compute, cond, context, convert, convertColorSpace, convertToTexture, cos, createCanvasElement, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, deltaTime, densityFog, depth, depthPass, difference, diffuseColor, directPointLight, directionToColor, dispersion, distance, div, dodge, dot, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getNormalFromDepth, getParallaxCorrectNormal, getRoughness, getScreenPosition, getShIrradianceAt, getTextureIndex, getViewPosition, glsl, glslFn, grayscale, greaterThan, greaterThanEqual, hash, highPrecisionModelNormalViewMatrix, highPrecisionModelViewMatrix, hue, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, invocationLocalIndex, invocationSubgroupIndex, ior, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightPosition, lightTargetDirection, lightTargetPosition, lightViewPosition, lightingContext, lights, linearDepth, linearToneMapping, localId, log, log2, logarithmicDepthToViewZ, loop, luminance, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialAttenuationColor, materialAttenuationDistance, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIOR, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRefractionRatio, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularColor, materialSpecularIntensity, materialSpecularStrength, materialThickness, materialTransmission, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mixElement, mod, modInt, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, neutralToneMapping, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalFlat, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, notEqual, numWorkgroups, objectDirection, objectGroup, objectPosition, objectScale, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionPrevious, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, reinhardToneMapping, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rotate, rotateUV, roughness, round, rtt, sRGBTransferEOTF, sRGBTransferOETF, sampler, saturate, saturation, screen, screenCoordinate, screenSize, screenUV, scriptable, scriptableValue, select, setCurrentStack, shaderStages, shadow, sharedUniformGroup, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, smoothstepElement, specularColor, specularF90, spherizeUV, split, spritesheetUV, sqrt, stack, step, storage, storageBarrier, storageObject, storageStruct, storageTexture, string, struct, sub, subgroupIndex, subgroupSize, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBarrier, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, thickness, threshold, time, timerDelta, timerGlobal, timerLocal, toOutputColorSpace, toWorkingColorSpace, toneMapping, toneMappingExposure, toonOutlinePass, transformDirection, transformNormal, transformNormalToView, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transmission, transpose, tri, tri3, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, uniform, uniformArray, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, velocity, vertexColor, vertexIndex, vibrance, viewZToLogarithmicDepth, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSafeUV, viewportSharedTexture, viewportSize, viewportTexture, viewportTopLeft, viewportUV, wgsl, wgslFn, workgroupArray, workgroupBarrier, workgroupId, workingToColorSpace, xor }; diff --git a/build/three.webgpu.min.js b/build/three.webgpu.min.js index 6c1ab1bd4a612b..6e2389d3b73a74 100644 --- a/build/three.webgpu.min.js +++ b/build/three.webgpu.min.js @@ -3,4 +3,4 @@ * Copyright 2010-2024 Three.js Authors * SPDX-License-Identifier: MIT */ -import{Color as e,Vector2 as t,Vector3 as s,Vector4 as r,Matrix3 as i,Matrix4 as n,EventDispatcher as o,MathUtils as a,ColorManagement as u,SRGBTransfer as l,NoToneMapping as d,StaticDrawUsage as c,InterleavedBuffer as h,DynamicDrawUsage as p,InterleavedBufferAttribute as g,NoColorSpace as m,UnsignedIntType as f,IntType as y,WebGLCoordinateSystem as b,BackSide as x,CubeReflectionMapping as T,CubeRefractionMapping as _,WebGPUCoordinateSystem as N,TangentSpaceNormalMap as v,ObjectSpaceNormalMap as S,InstancedInterleavedBuffer as A,InstancedBufferAttribute as R,DataArrayTexture as C,FloatType as E,FramebufferTexture as w,LinearMipmapLinearFilter as M,DepthTexture as B,Material as U,NormalBlending as F,PointsMaterial as P,LineBasicMaterial as I,LineDashedMaterial as L,MeshNormalMaterial as D,WebGLCubeRenderTarget as V,BoxGeometry as O,NoBlending as G,Mesh as k,Scene as z,LinearFilter as $,CubeCamera as H,CubeTexture as W,EquirectangularReflectionMapping as j,EquirectangularRefractionMapping as q,AddOperation as K,MixOperation as X,MultiplyOperation as Y,MeshBasicMaterial as Q,MeshLambertMaterial as Z,MeshPhongMaterial as J,Texture as ee,MeshStandardMaterial as te,MeshPhysicalMaterial as se,MeshToonMaterial as re,MeshMatcapMaterial as ie,SpriteMaterial as ne,ShadowMaterial as oe,Uint32BufferAttribute as ae,Uint16BufferAttribute as ue,DoubleSide as le,DepthStencilFormat as de,DepthFormat as ce,UnsignedInt248Type as he,UnsignedByteType as pe,RenderTarget as ge,Plane as me,Object3D as fe,HalfFloatType as ye,LinearMipMapLinearFilter as be,OrthographicCamera as xe,BufferGeometry as Te,Float32BufferAttribute as _e,UVMapping as Ne,Euler as ve,LinearSRGBColorSpace as Se,LessCompare as Ae,VSMShadowMap as Re,RGFormat as Ce,SphereGeometry as Ee,BufferAttribute as we,CubeUVReflectionMapping as Me,PerspectiveCamera as Be,RGBAFormat as Ue,LinearMipmapNearestFilter as Fe,NearestMipmapLinearFilter as Pe,Float16BufferAttribute as Ie,REVISION as Le,SRGBColorSpace as De,PCFShadowMap as Ve,FrontSide as Oe,Frustum as Ge,DataTexture as ke,RedIntegerFormat as ze,RedFormat as $e,RGIntegerFormat as He,RGBIntegerFormat as We,RGBFormat as je,RGBAIntegerFormat as qe,UnsignedShortType as Ke,ByteType as Xe,ShortType as Ye,createCanvasElement as Qe,AddEquation as Ze,SubtractEquation as Je,ReverseSubtractEquation as et,ZeroFactor as tt,OneFactor as st,SrcColorFactor as rt,SrcAlphaFactor as it,SrcAlphaSaturateFactor as nt,DstColorFactor as ot,DstAlphaFactor as at,OneMinusSrcColorFactor as ut,OneMinusSrcAlphaFactor as lt,OneMinusDstColorFactor as dt,OneMinusDstAlphaFactor as ct,CullFaceNone as ht,CullFaceBack as pt,CullFaceFront as gt,CustomBlending as mt,MultiplyBlending as ft,SubtractiveBlending as yt,AdditiveBlending as bt,NotEqualDepth as xt,GreaterDepth as Tt,GreaterEqualDepth as _t,EqualDepth as Nt,LessEqualDepth as vt,LessDepth as St,AlwaysDepth as At,NeverDepth as Rt,UnsignedShort4444Type as Ct,UnsignedShort5551Type as Et,UnsignedInt5999Type as wt,AlphaFormat as Mt,LuminanceFormat as Bt,LuminanceAlphaFormat as Ut,RGB_S3TC_DXT1_Format as Ft,RGBA_S3TC_DXT1_Format as Pt,RGBA_S3TC_DXT3_Format as It,RGBA_S3TC_DXT5_Format as Lt,RGB_PVRTC_4BPPV1_Format as Dt,RGB_PVRTC_2BPPV1_Format as Vt,RGBA_PVRTC_4BPPV1_Format as Ot,RGBA_PVRTC_2BPPV1_Format as Gt,RGB_ETC1_Format as kt,RGB_ETC2_Format as zt,RGBA_ETC2_EAC_Format as $t,RGBA_ASTC_4x4_Format as Ht,RGBA_ASTC_5x4_Format as Wt,RGBA_ASTC_5x5_Format as jt,RGBA_ASTC_6x5_Format as qt,RGBA_ASTC_6x6_Format as Kt,RGBA_ASTC_8x5_Format as Xt,RGBA_ASTC_8x6_Format as Yt,RGBA_ASTC_8x8_Format as Qt,RGBA_ASTC_10x5_Format as Zt,RGBA_ASTC_10x6_Format as Jt,RGBA_ASTC_10x8_Format as es,RGBA_ASTC_10x10_Format as ts,RGBA_ASTC_12x10_Format as ss,RGBA_ASTC_12x12_Format as rs,RGBA_BPTC_Format as is,RED_RGTC1_Format as ns,SIGNED_RED_RGTC1_Format as os,RED_GREEN_RGTC2_Format as as,SIGNED_RED_GREEN_RGTC2_Format as us,RepeatWrapping as ls,ClampToEdgeWrapping as ds,MirroredRepeatWrapping as cs,NearestFilter as hs,NearestMipmapNearestFilter as ps,NeverCompare as gs,AlwaysCompare as ms,LessEqualCompare as fs,EqualCompare as ys,GreaterEqualCompare as bs,GreaterCompare as xs,NotEqualCompare as Ts,warnOnce as _s,NotEqualStencilFunc as Ns,GreaterStencilFunc as vs,GreaterEqualStencilFunc as Ss,EqualStencilFunc as As,LessEqualStencilFunc as Rs,LessStencilFunc as Cs,AlwaysStencilFunc as Es,NeverStencilFunc as ws,DecrementWrapStencilOp as Ms,IncrementWrapStencilOp as Bs,DecrementStencilOp as Us,IncrementStencilOp as Fs,InvertStencilOp as Ps,ReplaceStencilOp as Is,ZeroStencilOp as Ls,KeepStencilOp as Ds,MaxEquation as Vs,MinEquation as Os,SpotLight as Gs,PointLight as ks,DirectionalLight as zs,RectAreaLight as $s,AmbientLight as Hs,HemisphereLight as Ws,LightProbe as js,LinearToneMapping as qs,ReinhardToneMapping as Ks,CineonToneMapping as Xs,ACESFilmicToneMapping as Ys,AgXToneMapping as Qs,NeutralToneMapping as Zs,Group as Js,Loader as er,FileLoader as tr,MaterialLoader as sr,ObjectLoader as rr}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrayCamera,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BasicShadowMap,BatchedMesh,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,Camera,CameraHelper,CanvasTexture,CapsuleGeometry,CatmullRomCurve3,CircleGeometry,Clock,ColorKeyframeTrack,CompressedArrayTexture,CompressedCubeTexture,CompressedTexture,CompressedTextureLoader,ConeGeometry,ConstantAlphaFactor,ConstantColorFactor,Controls,CubeTextureLoader,CubicBezierCurve,CubicBezierCurve3,CubicInterpolant,CullFaceFrontBack,Curve,CurvePath,CustomToneMapping,CylinderGeometry,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LinearTransfer,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,Matrix2,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,PCFSoftShadowMap,Path,PlaneGeometry,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,Quaternion,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Sphere,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLMultipleRenderTargets,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding}from"./three.core.min.js";const ir=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class nr{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=ir,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:s,material:r}=e;if(t={material:this.getMaterialData(r),geometry:{attributes:this.getAttributesData(s.attributes),indexVersion:s.index?s.index.version:null,drawRange:{start:s.drawRange.start,count:s.drawRange.count}},worldMatrix:e.object.matrixWorld.clone()},e.object.center&&(t.center=e.object.center.clone()),e.object.morphTargetInfluences&&(t.morphTargetInfluences=e.object.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,i=this.getRenderObjectData(e);if(!0!==i.worldMatrix.equals(t.matrixWorld))return i.worldMatrix.copy(t.matrixWorld),!1;const n=i.material;for(const e in n){const t=n[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return n[e]=r,!1}if(n.transmission>0){const{width:t,height:s}=e.context;if(i.bufferWidth!==t||i.bufferHeight!==s)return i.bufferWidth=t,i.bufferHeight=s,!1}const o=i.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return i.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(i.morphTargetInfluences){let e=!1;for(let s=0;s>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:i}of cr(e))s.push(s,or(r.slice(0,-4)),i.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;ee.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of cr(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let r=null;const i=e.getBuildStage();if("setup"===i){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===i)this.analyze(e);else if("generate"===i){if(1===this.generate.length){const s=this.getNodeType(e),i=e.getDataFromNode(this);r=i.snippet,void 0===r?(r=this.generate(e)||"",i.snippet=r):void 0!==i.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:i,childNode:n}of t)void 0!==i?(void 0===s[r]&&(s[r]=Number.isInteger(i)?[]:{}),s[r][i]=n.toJSON(e.meta).uuid):s[r]=n.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const i of e.inputNodes[s])r.push(t[i]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const i in e.inputNodes[s]){const n=e.inputNodes[s][i];r[i]=t[n]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let i=e.nodes[t];function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===i&&(i={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[i.uuid]=i),this.serialize(i),delete i.meta),r){const t=n(e.textures),s=n(e.images),r=n(e.nodes);t.length>0&&(i.textures=t),s.length>0&&(i.images=s),r.length>0&&(i.nodes=r)}return i}}class Rr extends Ar{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,r=this.getNodeType(e),i=s.build(e,r);return e.format(i,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const i=super.build(e,s),n=e.getVarFromNode(this,null,s),o=e.getPropertyName(n);return e.addLineFlowCode(`${o} = ${i}`,this),r.snippet=i,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,s)=>t+e.getTypeLength(s.getNodeType(e))),0))}generate(e,t){const s=this.getNodeType(e),r=this.nodes,i=e.getComponentType(s),n=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==i&&(s=e.format(s,r,i)),n.push(s)}const o=`${e.getType(s)}( ${n.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(vr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,r=e.getTypeLength(s.getNodeType(e));let i=null;if(r>1){let n=null;this.getVectorLength()>=r&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,n);i=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,n,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else i=s.build(e,t);return i}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:r}=this,i=this.getNodeType(e),n=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,n),a=t.build(e,i),u=e.getTypeLength(i),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(hi(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),ci(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>ci(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>ci(new Fr(ci(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),ci(new Br(e,t));if(!0===/^\d+$/.test(t))return ci(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=ci(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;rci(null!==r?Object.assign(e,r):e);return null===t?(...t)=>i(new e(...pi(t))):null!==s?(s=ci(s),(...r)=>i(new e(t,...pi(r),s))):(...s)=>i(new e(t,...pi(s)))},qr=function(e,...t){return ci(new e(...pi(t)))};class Kr extends Ar{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let i=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let n=r.get(t);void 0===n&&(n=ci(e.buildFunctionNode(t)),r.set(t,n)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(n),i=ci(n.call(s))}else{const r=t.jsFunc,n=null!==s?r(s,e):r(e);i=ci(n)}return t.once&&(r.onceOutput=i),i}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return hi(e),ci(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],ei=new Map;for(const e of Yr)ei.set(e,new Ir(e));const ti=new Map;for(const e of Qr)ti.set(e,new Ir(e,"uint"));const si=new Map([...ti].map((e=>new Ir(e.value,"int"))));for(const e of Zr)si.set(e,new Ir(e,"int"));const ri=new Map([...si].map((e=>new Ir(e.value))));for(const e of Jr)ri.set(e,new Ir(e));for(const e of Jr)ri.set(-e,new Ir(-e));const ii={bool:ei,uint:ti,ints:si,float:ri},ni=new Map([...ei,...ri]),oi=(e,t)=>ni.has(e)?ni.get(e):!0===e.isNode?e:new Ir(e,t),ai=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return ci(t.get(s[0]));if(1===s.length){const t=oi(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?ci(t):ci(new Cr(t,e))}const r=s.map((e=>oi(e)));return ci(new wr(r,e))}},ui=e=>"object"==typeof e&&null!==e?e.value:e,li=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function di(e,t){return new Proxy(new Xr(e,t),kr)}const ci=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?ci(oi(e,t)):"shader"===s?fi(e):e}(e,t),hi=(e,t=null)=>new Hr(e,t),pi=(e,t=null)=>new Wr(e,t),gi=(...e)=>new jr(...e),mi=(...e)=>new qr(...e),fi=(e,t)=>{const s=new di(e,t),r=(...e)=>{let t;return hi(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},yi=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),fi(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const bi=e=>{Lr=e},xi=()=>Lr,Ti=(...e)=>Lr.If(...e);function _i(e){return Lr&&Lr.add(e),e}Vr("append",_i);const Ni=new ai("color"),vi=new ai("float",ii.float),Si=new ai("int",ii.ints),Ai=new ai("uint",ii.uint),Ri=new ai("bool",ii.bool),Ci=new ai("vec2"),Ei=new ai("ivec2"),wi=new ai("uvec2"),Mi=new ai("bvec2"),Bi=new ai("vec3"),Ui=new ai("ivec3"),Fi=new ai("uvec3"),Pi=new ai("bvec3"),Ii=new ai("vec4"),Li=new ai("ivec4"),Di=new ai("uvec4"),Vi=new ai("bvec4"),Oi=new ai("mat2"),Gi=new ai("mat3"),ki=new ai("mat4"),zi=(e="")=>ci(new Ir(e,"string")),$i=e=>ci(new Ir(e,"ArrayBuffer"));Vr("toColor",Ni),Vr("toFloat",vi),Vr("toInt",Si),Vr("toUint",Ai),Vr("toBool",Ri),Vr("toVec2",Ci),Vr("toIVec2",Ei),Vr("toUVec2",wi),Vr("toBVec2",Mi),Vr("toVec3",Bi),Vr("toIVec3",Ui),Vr("toUVec3",Fi),Vr("toBVec3",Pi),Vr("toVec4",Ii),Vr("toIVec4",Li),Vr("toUVec4",Di),Vr("toBVec4",Vi),Vr("toMat2",Oi),Vr("toMat3",Gi),Vr("toMat4",ki);const Hi=gi(Rr),Wi=(e,t)=>ci(new Cr(ci(e),t)),ji=(e,t)=>ci(new Br(ci(e),t));Vr("element",Hi),Vr("convert",Wi);class qi extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Ki=e=>new qi(e),Xi=(e,t=0)=>new qi(e,!0,t),Yi=Xi("frame"),Qi=Xi("render"),Zi=Ki("object");class Ji extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Zi}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let i=e.getNodeFromHash(r);void 0===i&&(e.setHashNode(this,r),i=this);const n=i.getInputType(e),o=e.getUniformFromNode(i,n,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const en=(e,t)=>{const s=li(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return ci(new Ji(r,s))};class tn extends Ar{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const sn=(e,t)=>ci(new tn(e,t)),rn=(e,t)=>ci(new tn(e,t,!0)),nn=mi(tn,"vec4","DiffuseColor"),on=mi(tn,"vec3","EmissiveColor"),an=mi(tn,"float","Roughness"),un=mi(tn,"float","Metalness"),ln=mi(tn,"float","Clearcoat"),dn=mi(tn,"float","ClearcoatRoughness"),cn=mi(tn,"vec3","Sheen"),hn=mi(tn,"float","SheenRoughness"),pn=mi(tn,"float","Iridescence"),gn=mi(tn,"float","IridescenceIOR"),mn=mi(tn,"float","IridescenceThickness"),fn=mi(tn,"float","AlphaT"),yn=mi(tn,"float","Anisotropy"),bn=mi(tn,"vec3","AnisotropyT"),xn=mi(tn,"vec3","AnisotropyB"),Tn=mi(tn,"color","SpecularColor"),_n=mi(tn,"float","SpecularF90"),Nn=mi(tn,"float","Shininess"),vn=mi(tn,"vec4","Output"),Sn=mi(tn,"float","dashSize"),An=mi(tn,"float","gapSize"),Rn=mi(tn,"float","pointWidth"),Cn=mi(tn,"float","IOR"),En=mi(tn,"float","Transmission"),wn=mi(tn,"float","Thickness"),Mn=mi(tn,"float","AttenuationDistance"),Bn=mi(tn,"color","AttenuationColor"),Un=mi(tn,"float","Dispersion");class Fn extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,i=this.needsSplitAssign(e),n=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,n),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(i){const r=e.getVarFromNode(this,null,n),i=e.getPropertyName(r);e.addLineFlowCode(`${i} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t{const r=s.type;let i;return i="pointer"===r?"&"+t.build(e):t.build(e,r),i};if(Array.isArray(i))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?pi(t):hi(t[0]),ci(new In(ci(e),t)));Vr("call",Ln);class Dn extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let i=new Dn(e,t,s);for(let t=0;t>"===s||"<<"===s)return e.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(n),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&e.isMatrix(o)?o:e.isMatrix(n)&&e.isVector(o)?e.getVectorFromMatrix(n):e.isVector(n)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(n)?o:n}generate(e,t){const s=this.op,r=this.aNode,i=this.bNode,n=this.getNodeType(e,t);let o=null,a=null;"void"!==n?(o=r.getNodeType(e),a=void 0!==i?i.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=n,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=n):o=a=n;const u=r.build(e,o),l=void 0!==i?i.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} < ${l} )`,n,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} <= ${l} )`,n,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} > ${l} )`,n,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} >= ${l} )`,n,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,n,t):e.format(`( ${u} ${s} ${l} )`,n,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,n,t):e.format(`${u} ${s} ${l}`,n,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vn=gi(Dn,"+"),On=gi(Dn,"-"),Gn=gi(Dn,"*"),kn=gi(Dn,"/"),zn=gi(Dn,"%"),$n=gi(Dn,"=="),Hn=gi(Dn,"!="),Wn=gi(Dn,"<"),jn=gi(Dn,">"),qn=gi(Dn,"<="),Kn=gi(Dn,">="),Xn=gi(Dn,"&&"),Yn=gi(Dn,"||"),Qn=gi(Dn,"!"),Zn=gi(Dn,"^^"),Jn=gi(Dn,"&"),eo=gi(Dn,"~"),to=gi(Dn,"|"),so=gi(Dn,"^"),ro=gi(Dn,"<<"),io=gi(Dn,">>");Vr("add",Vn),Vr("sub",On),Vr("mul",Gn),Vr("div",kn),Vr("modInt",zn),Vr("equal",$n),Vr("notEqual",Hn),Vr("lessThan",Wn),Vr("greaterThan",jn),Vr("lessThanEqual",qn),Vr("greaterThanEqual",Kn),Vr("and",Xn),Vr("or",Yn),Vr("not",Qn),Vr("xor",Zn),Vr("bitAnd",Jn),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",io);const no=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zn(...e));Vr("remainder",no);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return i>n&&i>o?t:n>o?s:o>i?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),i=this.getInputType(e),n=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=n,r=o;e.isMatrix(s.getNodeType(e))?r=Ii(Bi(r),0):s=Ii(Bi(s),0);const i=Gn(s,r).xyz;return Ao(i).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+n.build(e,i)+" )",r,t);if(s===oo.ONE_MINUS)return On(1,n).build(e,t);if(s===oo.RECIPROCAL)return kn(1,n).build(e,t);if(s===oo.DIFFERENCE)return Fo(On(n,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(n.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":i),o.build(e,i)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(n.build(e,i),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":i)):s===oo.REFRACT?l.push(n.build(e,i),o.build(e,i),a.build(e,"float")):s===oo.MIX?l.push(n.build(e,i),o.build(e,i),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":i)):(l.push(n.build(e,i)),null!==o&&l.push(o.build(e,i)),null!==a&&l.push(a.build(e,i))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=vi(1e-6),uo=vi(1e6),lo=vi(Math.PI),co=vi(2*Math.PI),ho=gi(oo,oo.ALL),po=gi(oo,oo.ANY),go=gi(oo,oo.EQUALS),mo=gi(oo,oo.RADIANS),fo=gi(oo,oo.DEGREES),yo=gi(oo,oo.EXP),bo=gi(oo,oo.EXP2),xo=gi(oo,oo.LOG),To=gi(oo,oo.LOG2),_o=gi(oo,oo.SQRT),No=gi(oo,oo.INVERSE_SQRT),vo=gi(oo,oo.FLOOR),So=gi(oo,oo.CEIL),Ao=gi(oo,oo.NORMALIZE),Ro=gi(oo,oo.FRACT),Co=gi(oo,oo.SIN),Eo=gi(oo,oo.COS),wo=gi(oo,oo.TAN),Mo=gi(oo,oo.ASIN),Bo=gi(oo,oo.ACOS),Uo=gi(oo,oo.ATAN),Fo=gi(oo,oo.ABS),Po=gi(oo,oo.SIGN),Io=gi(oo,oo.LENGTH),Lo=gi(oo,oo.NEGATE),Do=gi(oo,oo.ONE_MINUS),Vo=gi(oo,oo.DFDX),Oo=gi(oo,oo.DFDY),Go=gi(oo,oo.ROUND),ko=gi(oo,oo.RECIPROCAL),zo=gi(oo,oo.TRUNC),$o=gi(oo,oo.FWIDTH),Ho=gi(oo,oo.BITCAST),Wo=gi(oo,oo.TRANSPOSE),jo=gi(oo,oo.ATAN2),qo=gi(oo,oo.MIN),Ko=gi(oo,oo.MAX),Xo=gi(oo,oo.MOD),Yo=gi(oo,oo.STEP),Qo=gi(oo,oo.REFLECT),Zo=gi(oo,oo.DISTANCE),Jo=gi(oo,oo.DIFFERENCE),ea=gi(oo,oo.DOT),ta=gi(oo,oo.CROSS),sa=gi(oo,oo.POW),ra=gi(oo,oo.POW,2),ia=gi(oo,oo.POW,3),na=gi(oo,oo.POW,4),oa=gi(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gn(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=gi(oo,oo.MIX),da=(e,t=0,s=1)=>ci(new oo(oo.CLAMP,ci(e),ci(t),ci(s))),ca=e=>da(e),ha=gi(oo,oo.REFRACT),pa=gi(oo,oo.SMOOTHSTEP),ga=gi(oo,oo.FACEFORWARD),ma=fi((([e])=>{const t=ea(e.xy,Ci(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",ia),Vr("pow4",na),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,i=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=i,null!==r&&(e.getDataFromNode(r).parentNodeBlock=i);const n=e.getNodeProperties(this);n.condNode=t,n.ifNode=s.context({nodeBlock:s}),n.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:i,ifNode:n,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?sn(s).build(e):"";r.nodeProperty=u;const l=i.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=n.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=gi(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e,t);return e.setContext(s),r}}const Na=gi(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),i=e.getPropertyName(r),n=t.build(e,r.type);return e.addLineFlowCode(`${i} = ${n}`,this),i}}const Aa=gi(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const r=this.name,i=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,i),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const r=this.getNodeType(e),i=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,i),t.propertyName=i}return e.getPropertyName(s)}}const Ea=gi(Ca);Vr("varying",Ea);const wa=fi((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=fi((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let n=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(n=Ii(wa(n.rgb),n.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(n=Ii(Gi(u._getMatrix(new i,s,r)).mul(n.rgb),n.a)),u.getTransfer(r)===l&&(n=Ii(Ma(n.rgb),n.a)),n):n}}const Pa=e=>ci(new Fa(ci(e),Ba,Ua)),Ia=e=>ci(new Fa(ci(e),Ua,Ba)),La=(e,t)=>ci(new Fa(ci(e),Ba,t)),Da=(e,t)=>ci(new Fa(ci(e),t,Ba)),Va=(e,t,s)=>ci(new Fa(ci(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return ci(new Oa(this,ci(e)))}setNodeType(e){const t=en(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;eci(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const i=e.renderer.library.getToneMappingFunction(s);return null!==i?r=Ii(i(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>ci(new $a(e,ci(t),ci(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),i=this.bufferStride||r,n=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,i),a=new g(o,r,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let i=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,i=r;else{i=Ea(this).build(e,t)}return i}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>ci(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;eci(new Qa(ci(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const i=this.node.build(e,...t);return e.setCache(s),i}}const eu=(e,...t)=>ci(new Ja(ci(e),...t));Vr("cache",eu);class tu extends Ar{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const su=gi(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=vi(0),i=vi(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=i,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:i,doClamp:n}=this;let o=e.sub(t).div(s.sub(t));return!0===n&&(o=o.clamp()),o.mul(i.sub(r)).add(r)}}const iu=gi(ru,null,null,{doClamp:!1}),nu=gi(ru);Vr("remap",iu),Vr("remapClamp",nu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=gi(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>ci(new du(ci(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),i=e.getTypeFromAttribute(r),n=e.getAttribute(t,i);if("vertex"===e.shaderStage)return e.format(n.name,i,s);return Ea(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const gu=(e,t)=>ci(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=gi(fu);class bu extends Ji{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=gi(bu);class Tu extends Ji{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=en(this.value.matrix)),this._matrixUniform.mul(Bi(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&!0===s.flipY||!0===s.isRenderTargetTexture||!0===s.isFramebufferTexture||!0===s.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(Si(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,i,n,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,n):i?e.generateTextureBias(u,t,s,i,n):a?e.generateTextureGrad(u,t,s,a,n):o?e.generateTextureCompare(u,t,s,o,n):!1===this.sampler?e.generateTextureLoad(u,t,s,n):e.generateTexture(u,t,s,n),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const i=super.generate(e,"property");if("sampler"===t)return i+"_sampler";if(e.isReference(t))return i;{const n=e.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,i,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),n.snippet=b,n.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}blur(e){const t=this.clone();return t.biasNode=ci(e).mul(xu(t)),t.referenceNode=this.getSelf(),ci(t)}level(e){const t=this.clone();return t.levelNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}compare(e){const t=this.clone();return t.compareNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}grad(e,t){const s=this.clone();return s.gradNode=[ci(e),ci(t)],s.referenceNode=this.getSelf(),ci(s)}depth(e){const t=this.clone();return t.depthNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=gi(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=en("float").label("cameraNear").setGroup(Qi).onRenderUpdate((({camera:e})=>e.near)),Au=en("float").label("cameraFar").setGroup(Qi).onRenderUpdate((({camera:e})=>e.far)),Ru=en("mat4").label("cameraProjectionMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=en("mat4").label("cameraProjectionMatrixInverse").setGroup(Qi).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=en("mat4").label("cameraViewMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=en("mat4").label("cameraWorldMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=en("mat3").label("cameraNormalMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=en(new s).label("cameraPosition").setGroup(Qi).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new Ji(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,i=this.scope;if(i===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(i===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(i===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(i===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(i===Uu.VIEW_POSITION){const i=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(i.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=gi(Uu,Uu.DIRECTION),Pu=gi(Uu,Uu.WORLD_MATRIX),Iu=gi(Uu,Uu.POSITION),Lu=gi(Uu,Uu.SCALE),Du=gi(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=mi(Vu,Vu.DIRECTION),Gu=mi(Vu,Vu.WORLD_MATRIX),ku=mi(Vu,Vu.POSITION),zu=mi(Vu,Vu.SCALE),$u=mi(Vu,Vu.VIEW_POSITION),Hu=en(new i).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=en(new n).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=fi((e=>(e.context.isHighPrecisionModelViewMatrix=!0,en("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=fi((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return en("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=mi(sl),il=vi(rl).mul(2).sub(1),nl=gu("normal","vec3"),ol=fi((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Bi(0,1,0)):nl),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=fi((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=fi((e=>e.context.setupNormal()),"vec3").once()().mul(il).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=fi((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(il).toVar("transformedClearcoatNormalView"),pl=fi((([e,t=Gu])=>{const s=Gi(t),r=e.div(Bi(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=fi((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=en(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Bi(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Bi(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=gi(Tl);class Nl extends Ji{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const vl=(e,t,s)=>ci(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;sci(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),ci(new Al(e,t)));class El extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return ci(new El(this,ci(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):en(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;eci(new wl(e,t,s)),Bl=(e,t,s,r)=>ci(new wl(e,t,r,s));class Ul extends wl{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>ci(new Ul(e,t,s)),Pl=fi((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ii(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(nl.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=Gi(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xn.cross(tl);return e=e.cross(xn).normalize(),e=la(e,dl,yn.mul(an.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=fi((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:i}=e,n=t.dFdx(),o=t.dFdy(),a=i.dFdx(),u=i.dFdy(),l=s,d=o.cross(l),c=l.cross(n),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=il.mul(g.inverseSqrt());return Vn(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Bi(r.xy.mul(s),r.z));let i=null;if(t===S)i=gl(r);else if(t===v){i=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return i}}const Jl=gi(Zl),ed=fi((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=vi(s((e=>e)));return Ci(vi(s((e=>e.add(e.dFdx())))).sub(r),vi(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=fi((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,i=t.dFdx().normalize(),n=s,o=t.dFdy().normalize().cross(n),a=n.cross(i),u=i.dot(o).mul(il),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=gi(sd),id=new Map;class nd extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=id.get(e);return void 0===s&&(s=Fl(e,t),id.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===nd.COLOR){const e=void 0!==t.color?this.getColor(s):Bi();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===nd.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===nd.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:vi(1);else if(s===nd.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===nd.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===nd.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===nd.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===nd.EMISSIVE){const e=this.getFloat("emissiveIntensity"),i=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?i.mul(this.getTexture(s)):i}else if(s===nd.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===nd.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===nd.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===nd.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===nd.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===nd.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===nd.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Oi($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(Ci(1)).normalize().mul(e.b))}else r=$d;else if(s===nd.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const i=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(i).mul(this.getTexture(s).g).add(i)}else r=e}else if(s===nd.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===nd.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===nd.IOR)r=this.getFloat(s);else if(s===nd.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===nd.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}nd.ALPHA_TEST="alphaTest",nd.COLOR="color",nd.OPACITY="opacity",nd.SHININESS="shininess",nd.SPECULAR="specular",nd.SPECULAR_STRENGTH="specularStrength",nd.SPECULAR_INTENSITY="specularIntensity",nd.SPECULAR_COLOR="specularColor",nd.REFLECTIVITY="reflectivity",nd.ROUGHNESS="roughness",nd.METALNESS="metalness",nd.NORMAL="normal",nd.CLEARCOAT="clearcoat",nd.CLEARCOAT_ROUGHNESS="clearcoatRoughness",nd.CLEARCOAT_NORMAL="clearcoatNormal",nd.EMISSIVE="emissive",nd.ROTATION="rotation",nd.SHEEN="sheen",nd.SHEEN_ROUGHNESS="sheenRoughness",nd.ANISOTROPY="anisotropy",nd.IRIDESCENCE="iridescence",nd.IRIDESCENCE_IOR="iridescenceIOR",nd.IRIDESCENCE_THICKNESS="iridescenceThickness",nd.IOR="ior",nd.TRANSMISSION="transmission",nd.THICKNESS="thickness",nd.ATTENUATION_DISTANCE="attenuationDistance",nd.ATTENUATION_COLOR="attenuationColor",nd.LINE_SCALE="scale",nd.LINE_DASH_SIZE="dashSize",nd.LINE_GAP_SIZE="gapSize",nd.LINE_WIDTH="linewidth",nd.LINE_DASH_OFFSET="dashOffset",nd.POINT_WIDTH="pointWidth",nd.DISPERSION="dispersion",nd.LIGHT_MAP="light",nd.AO_MAP="ao";const od=mi(nd,nd.ALPHA_TEST),ad=mi(nd,nd.COLOR),ud=mi(nd,nd.SHININESS),ld=mi(nd,nd.EMISSIVE),dd=mi(nd,nd.OPACITY),cd=mi(nd,nd.SPECULAR),hd=mi(nd,nd.SPECULAR_INTENSITY),pd=mi(nd,nd.SPECULAR_COLOR),gd=mi(nd,nd.SPECULAR_STRENGTH),md=mi(nd,nd.REFLECTIVITY),fd=mi(nd,nd.ROUGHNESS),yd=mi(nd,nd.METALNESS),bd=mi(nd,nd.NORMAL).context({getUV:null}),xd=mi(nd,nd.CLEARCOAT),Td=mi(nd,nd.CLEARCOAT_ROUGHNESS),_d=mi(nd,nd.CLEARCOAT_NORMAL).context({getUV:null}),Nd=mi(nd,nd.ROTATION),vd=mi(nd,nd.SHEEN),Sd=mi(nd,nd.SHEEN_ROUGHNESS),Ad=mi(nd,nd.ANISOTROPY),Rd=mi(nd,nd.IRIDESCENCE),Cd=mi(nd,nd.IRIDESCENCE_IOR),Ed=mi(nd,nd.IRIDESCENCE_THICKNESS),wd=mi(nd,nd.TRANSMISSION),Md=mi(nd,nd.THICKNESS),Bd=mi(nd,nd.IOR),Ud=mi(nd,nd.ATTENUATION_DISTANCE),Fd=mi(nd,nd.ATTENUATION_COLOR),Pd=mi(nd,nd.LINE_SCALE),Id=mi(nd,nd.LINE_DASH_SIZE),Ld=mi(nd,nd.LINE_GAP_SIZE),Dd=mi(nd,nd.LINE_WIDTH),Vd=mi(nd,nd.LINE_DASH_OFFSET),Od=mi(nd,nd.POINT_WIDTH),Gd=mi(nd,nd.DISPERSION),kd=mi(nd,nd.LIGHT_MAP),zd=mi(nd,nd.AO_MAP),$d=en(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=gi(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,i;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)i=r;else{i=Ea(this).build(e,t)}return i}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=mi(jd,jd.VERTEX),Kd=mi(jd,jd.INSTANCE),Xd=mi(jd,jd.SUBGROUP),Yd=mi(jd,jd.INVOCATION_SUBGROUP),Qd=mi(jd,jd.INVOCATION_LOCAL),Zd=mi(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,i=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=ki(...i)}this.instanceMatrixNode=t}const i=r.instanceColor;if(i&&null===s){const e=new R(i.array,3),t=i.usage===p?Ya:Xa;this.bufferColor=e,s=Bi(t(e,"vec3",3,0)),this.instanceColorNode=s}const n=t.mul(Yu).xyz;if(Yu.assign(n),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&rn("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=gi(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=fi((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=Si(e).modInt(Si(t)),r=Si(e).div(Si(t));return Nu(this.batchMesh._indirectTexture,Ei(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(Si(this.batchingIdNode)),r=this.batchMesh._matricesTexture,i=yu(Nu(r),0),n=vi(s).mul(4).toInt().toVar(),o=n.modInt(i),a=n.div(Si(i)),u=ki(Nu(r,Ei(o,a)),Nu(r,Ei(o.add(1),a)),Nu(r,Ei(o.add(2),a)),Nu(r,Ei(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=fi((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),i=s.div(t);return Nu(l,Ei(r,i)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);rn("vec3","vBatchColor").assign(t)}const d=Gi(u);Yu.assign(u.mul(Yu));const c=ol.div(Bi(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=gi(tc),rc=new WeakMap;class ic extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,i;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),i=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=en(e.bindMatrix,"mat4"),r=en(e.bindMatrixInverse,"mat4"),i=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=i,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:i,bindMatrixInverseNode:n}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=i.mul(t),c=Vn(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return n.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:i,bindMatrixInverseNode:n}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vn(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=n.mul(d).mul(i),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const nc=e=>ci(new ic(e)),oc=e=>ci(new ic(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;eNumber(n)?">=":"<"));const d={start:i,end:n,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const i=r.build(e,"void"),n=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+i);for(let t=0,s=this.params.length-1;tci(new ac(pi(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=fi((({bufferMap:e,influence:t,stride:s,width:r,depth:i,offset:n})=>{const o=Si(qd).mul(s).add(n),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,Ei(u,a)).depth(i).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=en(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,i=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,n=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==n?n.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,i=void 0!==e.morphAttributes.color,n=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==n?n.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===i&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=vi(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,Ei(Si(e).add(1),Si(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:Si(0)})),!0===i&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:Si(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=gi(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Bi().toVar("directDiffuse"),directSpecular:Bi().toVar("directSpecular"),indirectDiffuse:Bi().toVar("indirectDiffuse"),indirectSpecular:Bi().toVar("indirectSpecular")};return{radiance:Bi().toVar("radiance"),irradiance:Bi().toVar("irradiance"),iblIrradiance:Bi().toVar("iblIrradiance"),ambientOcclusion:vi(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Tc=gi(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?en(Nc||(Nc=new t)):e===Sc.VIEWPORT?en(vc||(vc=new r)):Ci(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=mi(Sc,Sc.UV),Rc=mi(Sc,Sc.SIZE),Cc=mi(Sc,Sc.COORDINATE),Ec=mi(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=fi((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=fi((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=fi((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=gi(Lc),Vc=gi(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=gi(Gc);class zc extends Ar{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Xc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.negate().div(t)),i=To(s.div(t));return r.div(i)},Kc=(e,t,s)=>{const r=e.mul(xo(s.div(t)));return vi(Math.E).pow(r).mul(t).negate()},Xc=gi(zc,zc.DEPTH_BASE),Yc=mi(zc,zc.DEPTH),Qc=gi(zc,zc.LINEAR_DEPTH),Zc=Qc(kc());Yc.assign=e=>Xc(e);const Jc=gi(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class eh extends Ar{static get type(){return"ClippingNode"}constructor(e=eh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===eh.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===eh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return fi((()=>{const s=vi().toVar("distanceToPlane"),r=vi().toVar("distanceToGradient"),i=vi(1).toVar("clipOpacity"),n=t.length;if(!this.hardwareClipping&&n>0){const e=Rl(t);uc(n,(({i:t})=>{const n=e.element(t);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),n=vi(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const i=t.element(e);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s).oneMinus())})),i.mulAssign(n.oneMinus())}nn.a.mulAssign(i),nn.a.equal(0).discard()}))()}setupDefault(e,t){return fi((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Ri(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),fi((()=>{const r=Rl(e),i=Jc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();i.element(e).assign(s)}))}))()}}eh.ALPHA_TO_COVERAGE="alphaToCoverage",eh.DEFAULT="default",eh.HARDWARE="hardware";const th=fi((([e])=>Ro(Gn(1e4,Co(Gn(17,e.x).add(Gn(.1,e.y)))).mul(Vn(.1,Fo(Co(Gn(13,e.y).add(e.x)))))))),sh=fi((([e])=>th(Ci(th(e.xy),e.z)))),rh=fi((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=vi(1).div(vi(.05).mul(t)).toVar("pixScale"),r=Ci(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),i=Ci(sh(vo(r.x.mul(e.xyz))),sh(vo(r.y.mul(e.xyz)))).toVar("alpha"),n=Ro(To(s)).toVar("lerpFactor"),o=Vn(Gn(n.oneMinus(),i.x),Gn(n,i.y)).toVar("x"),a=qo(n,n.oneMinus()).toVar("a"),u=Bi(o.mul(o).div(Gn(2,a).mul(On(1,a))),o.sub(Gn(.5,a)).div(On(1,a)),On(1,On(1,o).mul(On(1,o)).div(Gn(2,a).mul(On(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class ih extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new nr(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const i=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const n=this.setupLighting(e);null!==i&&e.stack.add(i);const o=Ii(n,nn.a).max(0);if(r=this.setupOutput(e,o),vn.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ii(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=ci(new eh(eh.ALPHA_TO_COVERAGE)):e.stack.add(ci(new eh))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(ci(new eh(eh.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(el.z,Su,Au):$c(el.z,Su,Au))}null!==r&&Yc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ii(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ii(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=rn("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=rn("vec3","vBatchColor").mul(s)}nn.assign(s);const r=this.opacityNode?vi(this.opacityNode):dd;if(nn.a.assign(nn.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?vi(this.alphaTestNode):od;nn.a.lessThanEqual(e).discard()}!0===this.alphaHash&&nn.a.lessThan(rh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&nn.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Bi(0):nn.rgb}setupNormal(){return this.normalNode?Bi(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let i=this.lightsNode||e.lightsNode;return t.length>0&&(i=e.renderer.lighting.createNode([...i.getLights(),...t])),i}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:i}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(n&&n.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(n,t,s,r)}else null!==s&&(o=Bi(null!==r?la(o,s,r):s));return(i&&!0===i.isNode||t.emissive&&!0===t.emissive.isColor)&&(on.assign(Bi(i||ld)),o=o.add(on)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ii(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:i}of r)s.inputNodes[t]=i.toJSON(e).uuid;function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=i(e.textures),r=i(e.images),n=i(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),n.length>0&&(s.nodes=n)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const nh=new P;class oh extends ih{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(nh),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=fi((()=>{const e=gu("instancePosition").xyz,t=Ii(ju.mul(Ii(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),i=Xu.xy.toVar();return i.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),i.assign(i.div(Ec.z)),i.y.assign(i.y.mul(s)),i.assign(i.mul(r.w)),r.addAssign(Ii(i,0,0)),r}))(),this.fragmentNode=fi((()=>{const r=vi(1).toVar(),i=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=vi(i.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),i).oneMinus())}else i.greaterThan(1).discard();let n;if(this.pointColorNode)n=this.pointColorNode;else if(s){n=gu("instanceColor").mul(ad)}else n=ad;return r.mulAssign(dd),Ii(n,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ah=new I;class uh extends ih{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(ah),this.setValues(e)}}const lh=new L;class dh extends ih{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(lh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?vi(this.offsetNodeNode):Vd,t=this.dashScaleNode?vi(this.dashScaleNode):Pd,s=this.dashSizeNode?vi(this.dashSizeNode):Id,r=this.dashSizeNode?vi(this.dashGapNode):Ld;Sn.assign(s),An.assign(r);const i=Ea(gu("lineDistance").mul(t));(e?i.add(e):i).mod(Sn.add(An)).greaterThan(Sn).discard()}}const ch=new L;class hh extends ih{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ch),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,i=this.worldUnits,n=fi((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ii(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=fi((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ii(ju.mul(Ii(e,1))).toVar("start"),o=Ii(ju.mul(Ii(t,1))).toVar("end");if(r){const e=this.dashScaleNode?vi(this.dashScaleNode):Pd,t=this.offsetNode?vi(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let i=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));i=i.add(t),rn("float","lineDistance").assign(i)}i&&(rn("vec3","worldStart").assign(s.xyz),rn("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);Ti(u,(()=>{Ti(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(n({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(n({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ii().toVar();if(i){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),i=e.cross(t).normalize(),n=e.cross(i),a=rn("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ii(Xu.x.lessThan(0).select(i.mul(u),i.mul(u).negate()),0)),r||(a.addAssign(Ii(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ii(n.mul(u),0)),Ti(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ii(n.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Bi().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=Ci(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),Ti(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ii(e,0,0)))}return g}))();const o=fi((({p1:e,p2:t,p3:s,p4:r})=>{const i=e.sub(s),n=r.sub(s),o=t.sub(e),a=i.dot(n),u=n.dot(o),l=i.dot(o),d=n.dot(n),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return Ci(h,p)}));this.fragmentNode=fi((()=>{const n=mu();if(r){const e=this.dashSizeNode?vi(this.dashSizeNode):Id,t=this.dashSizeNode?vi(this.dashGapNode):Ld;Sn.assign(e),An.assign(t);const s=rn("float","lineDistance");n.y.lessThan(-1).or(n.y.greaterThan(1)).discard(),s.mod(Sn.add(An)).greaterThan(Sn).discard()}const a=vi(1).toVar("alpha");if(i){const s=rn("vec3","worldStart"),i=rn("vec3","worldEnd"),n=rn("vec4","worldPos").xyz.normalize().mul(1e5),u=i.sub(s),l=o({p1:s,p2:i,p3:Bi(0,0,0),p4:n}),d=s.add(u.mul(l.x)),c=n.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1)),s=e.mul(e).add(t.mul(t)),r=vi(s.fwidth()).toVar("dlen");Ti(n.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else Ti(n.y.abs().greaterThan(1),(()=>{const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ii(u,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ph=e=>ci(e).mul(.5).add(.5),gh=e=>ci(e).mul(2).sub(1),mh=new D;class fh extends ih{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(mh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?vi(this.opacityNode):dd;nn.assign(Ii(ph(dl),e))}}class yh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return Ci(t,s)}}const bh=gi(yh);class xh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const i=new O(5,5,5),n=bh(Ju),o=new ih;o.colorNode=_u(t,n,0),o.side=x,o.blending=G;const a=new k(i,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const Th=new WeakMap;class _h extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(Th.has(e)){const t=Th.get(e);vh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new xh(s.height);r.fromEquirectangularTexture(t,e),vh(r.texture,e.mapping),this._cubeTexture=r.texture,Th.set(e,r.texture),e.addEventListener("dispose",Nh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Nh(e){const t=e.target;t.removeEventListener("dispose",Nh);const s=Th.get(t);void 0!==s&&(Th.delete(t),s.dispose())}function vh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const Sh=gi(_h);class Ah extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Sh(this.envNode)}}class Rh extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=vi(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ch{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Eh extends Ch{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,i=e.reflectedLight,n=s.context.irradianceLightMap;i.indirectDiffuse.assign(Ii(0)),n?i.indirectDiffuse.addAssign(n):i.indirectDiffuse.addAssign(Ii(1,1,1,0)),i.indirectDiffuse.mulAssign(r),i.indirectDiffuse.mulAssign(nn.rgb)}finish(e,t,s){const r=s.material,i=e.outgoingLight,n=s.context.environment;if(n)switch(r.combine){case Y:i.rgb.assign(la(i.rgb,i.rgb.mul(n.rgb),gd.mul(md)));break;case X:i.rgb.assign(la(i.rgb,n.rgb,gd.mul(md)));break;case K:i.rgb.addAssign(n.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const wh=new Q;class Mh extends ih{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Rh(kd)),t}setupOutgoingLight(){return nn.rgb}setupLightingModel(){return new Eh}}const Bh=fi((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Uh=fi((e=>e.diffuseColor.mul(1/Math.PI))),Fh=fi((({dotNH:e})=>Nn.mul(vi(.5)).add(1).mul(vi(1/Math.PI)).mul(e.pow(Nn)))),Ph=fi((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),i=Bh({f0:Tn,f90:1,dotVH:r}),n=vi(.25),o=Fh({dotNH:s});return i.mul(n).mul(o)}));class Ih extends Eh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:nn.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Ph({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:nn}))),s.indirectDiffuse.mulAssign(e)}}const Lh=new Z;class Dh extends ih{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih(!1)}}const Vh=new J;class Oh extends ih{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Vh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih}setupVariants(){const e=(this.shininessNode?vi(this.shininessNode):ud).max(1e-4);Nn.assign(e);const t=this.specularNode||cd;Tn.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Gh=fi((e=>{if(!1===e.geometry.hasAttribute("normal"))return vi(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),kh=fi((e=>{const{roughness:t}=e,s=Gh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),zh=fi((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),i=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return kn(.5,i.add(n).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),$h=fi((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:i,dotBL:n,dotNV:o,dotNL:a})=>{const u=a.mul(Bi(e.mul(s),t.mul(r),o).length()),l=o.mul(Bi(e.mul(i),t.mul(n),a).length());return kn(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hh=fi((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Wh=vi(1/Math.PI),jh=fi((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:i})=>{const n=e.mul(t),o=Bi(t.mul(r),e.mul(i),n.mul(s)),a=o.dot(o),u=n.div(a);return Wh.mul(n.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),qh=fi((e=>{const{lightDirection:t,f0:s,f90:r,roughness:i,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=i.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Bh({f0:s,f90:r,dotVH:g});if(ui(o)&&(y=pn.mix(y,n)),ui(a)){const e=bn.dot(t),s=bn.dot(tl),r=bn.dot(d),i=xn.dot(t),n=xn.dot(tl),o=xn.dot(d);m=$h({alphaT:fn,alphaB:l,dotTV:s,dotBV:n,dotTL:e,dotBL:i,dotNV:h,dotNL:c}),f=jh({alphaT:fn,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=zh({alpha:l,dotNL:c,dotNV:h}),f=Hh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),Kh=fi((({roughness:e,dotNV:t})=>{const s=Ii(-1,-.0275,-.572,.022),r=Ii(1,.0425,1.04,-.04),i=e.mul(s).add(r),n=i.x.mul(i.x).min(t.mul(-9.28).exp2()).mul(i.x).add(i.y);return Ci(-1.04,1.04).mul(n).add(i.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xh=fi((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:i}=e,n=Kh({dotNV:t,roughness:i});return s.mul(n.x).add(r.mul(n.y))})),Yh=fi((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),i=r.mul(r),n=r.mul(i,i).clamp(0,.9999);return e.sub(Bi(t).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qh=fi((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=vi(1).div(s),i=t.pow2().oneMinus().max(.0078125);return vi(2).add(r).mul(i.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Zh=fi((({dotNV:e,dotNL:t})=>vi(1).div(vi(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Jh=fi((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),i=dl.dot(t).clamp(),n=Qh({roughness:hn,dotNH:i}),o=Zh({dotNV:r,dotNL:s});return cn.mul(n).mul(o)})),ep=fi((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),i=Ci(s,r.oneMinus().sqrt());return i.assign(i.mul(.984375).add(.0078125)),i})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),tp=fi((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sp=fi((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),i=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),n=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=i.div(n),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),rp=fi((({N:e,V:t,P:s,mInv:r,p0:i,p1:n,p2:o,p3:a})=>{const u=n.sub(i).toVar(),l=a.sub(i).toVar(),d=u.cross(l),c=Bi().toVar();return Ti(d.dot(s.sub(i)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(Gi(u,l,e).transpose()).toVar(),h=d.mul(i.sub(s)).normalize().toVar(),p=d.mul(n.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Bi(0).toVar();f.addAssign(sp({v1:h,v2:p})),f.addAssign(sp({v1:p,v2:g})),f.addAssign(sp({v1:g,v2:m})),f.addAssign(sp({v1:m,v2:h})),c.assign(Bi(tp({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),ip=1/6,np=e=>Gn(ip,Gn(e,Gn(e,e.negate().add(3)).sub(3)).add(1)),op=e=>Gn(ip,Gn(e,Gn(e,Gn(3,e).sub(6))).add(4)),ap=e=>Gn(ip,Gn(e,Gn(e,Gn(-3,e).add(3)).add(3)).add(1)),up=e=>Gn(ip,sa(e,3)),lp=e=>np(e).add(op(e)),dp=e=>ap(e).add(up(e)),cp=e=>Vn(-1,op(e).div(np(e).add(op(e)))),hp=e=>Vn(1,up(e).div(ap(e).add(up(e)))),pp=(e,t,s)=>{const r=e.uvNode,i=Gn(r,t.zw).add(.5),n=vo(i),o=Ro(i),a=lp(o.x),u=dp(o.x),l=cp(o.x),d=hp(o.x),c=cp(o.y),h=hp(o.y),p=Ci(n.x.add(l),n.y.add(c)).sub(.5).mul(t.xy),g=Ci(n.x.add(d),n.y.add(c)).sub(.5).mul(t.xy),m=Ci(n.x.add(l),n.y.add(h)).sub(.5).mul(t.xy),f=Ci(n.x.add(d),n.y.add(h)).sub(.5).mul(t.xy),y=lp(o.y).mul(Vn(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=dp(o.y).mul(Vn(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},gp=fi((([e,t=vi(3)])=>{const s=Ci(e.size(Si(t))),r=Ci(e.size(Si(t.add(1)))),i=kn(1,s),n=kn(1,r),o=pp(e,Ii(i,s),vo(t)),a=pp(e,Ii(n,r),So(t));return Ro(t).mix(o,a)})),mp=fi((([e,t,s,r,i])=>{const n=Bi(ha(t.negate(),Ao(e),kn(1,r))),o=Bi(Io(i[0].xyz),Io(i[1].xyz),Io(i[2].xyz));return Ao(n).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),fp=fi((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),yp=Vc(),bp=Vc(),xp=fi((([e,t,s],{material:r})=>{const i=(r.side==x?yp:bp).uv(e),n=To(Rc.x).mul(fp(t,s));return gp(i,n)})),Tp=fi((([e,t,s])=>(Ti(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Bi(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),_p=fi((([e,t,s,r,i,n,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ii().toVar(),f=Bi().toVar();const i=d.sub(1).mul(g.mul(.025)),n=Bi(d.sub(i),d,d.add(i));uc({start:0,end:3},(({i:i})=>{const d=n.element(i),g=mp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ii(y,1))),x=Ci(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(Ci(x.x,x.y.oneMinus()));const T=xp(x,s,d);m.element(i).assign(T.element(i)),m.a.addAssign(T.a),f.element(i).assign(r.element(i).mul(Tp(Io(g),h,p).element(i)))})),m.a.divAssign(3)}else{const i=mp(e,t,c,d,a),n=o.add(i),g=l.mul(u.mul(Ii(n,1))),y=Ci(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(Ci(y.x,y.y.oneMinus())),m=xp(y,s,d),f=r.mul(Tp(Io(i),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Bi(Xh({dotNV:b,specularColor:i,specularF90:n,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ii(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),Np=Gi(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),vp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Sp=fi((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:i})=>{const n=la(e,t,pa(0,.03,r)),o=e.div(n).pow2().mul(s.pow2().oneMinus()).oneMinus();Ti(o.lessThan(0),(()=>Bi(1)));const a=o.sqrt(),u=vp(n,e),l=Bh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=n.lessThan(e).select(Math.PI,0),h=vi(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Bi(1).add(t).div(Bi(1).sub(t))})(i.clamp(0,.9999)),g=vp(p,n.toVec3()),m=Bh({f0:g,f90:1,dotVH:a}),f=Bi(p.x.lessThan(n).select(Math.PI,0),p.y.lessThan(n).select(Math.PI,0),p.z.lessThan(n).select(Math.PI,0)),y=n.mul(r,a,2),b=Bi(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Bi(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Bi(54856e-17,44201e-17,52481e-17),i=Bi(1681e3,1795300,2208400),n=Bi(43278e5,93046e5,66121e5),o=vi(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(n.mul(2*Math.PI).sqrt()).mul(i.mul(s).add(t).cos()).mul(s.pow2().negate().mul(n).exp());return a=Bi(a.x.add(o),a.y,a.z).div(1.0685e-7),Np.mul(a)})(vi(e).mul(y),vi(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Bi(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Ap=fi((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),i=s.pow2(),n=xa(s.lessThan(.25),vi(-339.2).mul(i).add(vi(161.4).mul(s)).sub(25.9),vi(-8.48).mul(i).add(vi(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),vi(44).mul(i).sub(vi(23.7).mul(s)).add(3.26),vi(1.97).mul(i).sub(vi(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,vi(.1).mul(s).sub(.025)).add(n.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Rp=Bi(.04),Cp=vi(1);class Ep extends Ch{constructor(e=!1,t=!1,s=!1,r=!1,i=!1,n=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=i,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Bi().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Bi().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Bi().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Bi().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Bi().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=Sp({outsideIOR:vi(1),eta2:gn,cosTheta1:e,thinFilmThickness:mn,baseF0:Tn}),this.iridescenceF0=Yh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=_p(r,s,an,nn,Tn,_n,t,Gu,Eu,Ru,Cn,wn,Bn,Mn,this.dispersion?Un:null),e.backdropAlpha=En,nn.a.mulAssign(la(1,e.backdrop.a,En))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),i=Kh({roughness:an,dotNV:r}),n=(this.iridescenceF0?pn.mix(Tn,this.iridescenceF0):Tn).mul(i.x).add(s.mul(i.y)),o=i.x.add(i.y).oneMinus(),a=Tn.add(Tn.oneMinus().mul(.047619)),u=n.mul(a).div(o.mul(a).oneMinus());e.addAssign(n),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Jh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(qh({lightDirection:e,f0:Rp,f90:Cp,roughness:dn,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:nn.rgb}))),s.directSpecular.addAssign(r.mul(qh({lightDirection:e,f0:Tn,f90:1,roughness:an,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:i,ltc_1:n,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=ep({N:c,V:h,roughness:an}),m=n.uv(g).toVar(),f=o.uv(g).toVar(),y=Gi(Bi(m.x,0,m.y),Bi(0,1,0),Bi(m.z,0,m.w)).toVar(),b=Tn.mul(f.x).add(Tn.oneMinus().mul(f.y)).toVar();i.directSpecular.addAssign(e.mul(b).mul(rp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),i.directDiffuse.addAssign(e.mul(nn).mul(rp({N:c,V:h,P:p,mInv:Gi(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Uh({diffuseColor:nn})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(cn,Ap({normal:dl,viewDir:tl,roughness:hn}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Xh({dotNV:e,specularColor:Rp,specularF90:Cp,roughness:dn});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Bi().toVar("singleScattering"),i=Bi().toVar("multiScattering"),n=t.mul(1/Math.PI);this.computeMultiscattering(r,i,_n);const o=r.add(i),a=nn.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(i.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=an.mul(-16).oneMinus().negate().exp2(),i=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(i)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Bh({dotVH:e,f0:Rp,f90:Cp}),r=t.mul(ln.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(ln));t.assign(r)}if(!0===this.sheen){const e=cn.r.max(cn.g).max(cn.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const wp=vi(1),Mp=vi(-2),Bp=vi(.8),Up=vi(-1),Fp=vi(.4),Pp=vi(2),Ip=vi(.305),Lp=vi(3),Dp=vi(.21),Vp=vi(4),Op=vi(4),Gp=vi(16),kp=fi((([e])=>{const t=Bi(Fo(e)).toVar(),s=vi(-1).toVar();return Ti(t.x.greaterThan(t.z),(()=>{Ti(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{Ti(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),zp=fi((([e,t])=>{const s=Ci().toVar();return Ti(t.equal(0),(()=>{s.assign(Ci(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(Ci(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(Ci(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(Ci(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(Ci(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(Ci(e.x,e.y).div(Fo(e.z)))})),Gn(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$p=fi((([e])=>{const t=vi(0).toVar();return Ti(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).ElseIf(e.greaterThanEqual(Fp),(()=>{t.assign(Bp.sub(e).mul(Pp.sub(Up)).div(Bp.sub(Fp)).add(Up))})).ElseIf(e.greaterThanEqual(Ip),(()=>{t.assign(Fp.sub(e).mul(Lp.sub(Pp)).div(Fp.sub(Ip)).add(Pp))})).ElseIf(e.greaterThanEqual(Dp),(()=>{t.assign(Ip.sub(e).mul(Vp.sub(Lp)).div(Ip.sub(Dp)).add(Lp))})).Else((()=>{t.assign(vi(-2).mul(To(Gn(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Hp=fi((([e,t])=>{const s=e.toVar();s.assign(Gn(2,s).sub(1));const r=Bi(s,1).toVar();return Ti(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Wp=fi((([e,t,s,r,i,n])=>{const o=vi(s),a=Bi(t),u=da($p(o),Mp,n),l=Ro(u),d=vo(u),c=Bi(jp(e,a,d,r,i,n)).toVar();return Ti(l.notEqual(0),(()=>{const t=Bi(jp(e,a,d.add(1),r,i,n)).toVar();c.assign(la(c,t,l))})),c})),jp=fi((([e,t,s,r,i,n])=>{const o=vi(s).toVar(),a=Bi(t),u=vi(kp(a)).toVar(),l=vi(Ko(Op.sub(o),0)).toVar();o.assign(Ko(o,Op));const d=vi(bo(o)).toVar(),c=Ci(zp(a,u).mul(d.sub(2)).add(1)).toVar();return Ti(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gn(3,Gp))),c.y.addAssign(Gn(4,bo(n).sub(d))),c.x.mulAssign(r),c.y.mulAssign(i),e.uv(c).grad(Ci(),Ci())})),qp=fi((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:i,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(i.cross(s).mul(Co(r))).add(i.mul(i.dot(s).mul(u.oneMinus())));return jp(e,l,t,n,o,a)})),Kp=fi((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:i,samples:n,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Bi(xa(t,s,ta(s,r))).toVar();Ti(ho(h.equals(Bi(0))),(()=>{h.assign(Bi(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Bi().toVar();return p.addAssign(i.element(Si(0)).mul(qp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:Si(1),end:e},(({i:e})=>{Ti(e.greaterThanEqual(n),(()=>{dc()}));const t=vi(o.mul(vi(e))).toVar();p.addAssign(i.element(e).mul(qp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(i.element(e).mul(qp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ii(p,1)}));let Xp=null;const Yp=new WeakMap;function Qp(e){let t=Yp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r0}(s))return null;t=Xp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Yp.set(e,t)}return t.texture}class Zp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=en(0),this._height=en(0),this._maxMip=en(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Qp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Xp&&(Xp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Bi(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Wp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Jp=gi(Zp),eg=new WeakMap;class tg extends yc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let r=eg.get(e);void 0===r&&(r=Jp(e),eg.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),i=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,n=s.context(sg(an,i)).mul(r),o=s.context(rg(cl)).mul(Math.PI).mul(r),a=eu(n),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(sg(dn,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const sg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},rg=e=>({getUV:()=>e,getTextureLevel:()=>vi(1)}),ig=new te;class ng extends ih{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ig),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new tg(t):null}setupLightingModel(){return new Ep}setupSpecular(){const e=la(Bi(.04),nn.rgb,un);Tn.assign(e),_n.assign(1)}setupVariants(){const e=this.metalnessNode?vi(this.metalnessNode):yd;un.assign(e);let t=this.roughnessNode?vi(this.roughnessNode):fd;t=kh({roughness:t}),an.assign(t),this.setupSpecular(),nn.assign(Ii(nn.rgb.mul(e.oneMinus()),nn.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const og=new se;class ag extends ng{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(og),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?vi(this.iorNode):Bd;Cn.assign(e),Tn.assign(la(qo(ra(Cn.sub(1).div(Cn.add(1))).mul(pd),Bi(1)).mul(hd),nn.rgb,un)),_n.assign(la(hd,1,un))}setupLightingModel(){return new Ep(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?vi(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?vi(this.clearcoatRoughnessNode):Td;ln.assign(e),dn.assign(kh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Bi(this.sheenNode):vd,t=this.sheenRoughnessNode?vi(this.sheenRoughnessNode):Sd;cn.assign(e),hn.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?vi(this.iridescenceNode):Rd,t=this.iridescenceIORNode?vi(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?vi(this.iridescenceThicknessNode):Ed;pn.assign(e),gn.assign(t),mn.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?Ci(this.anisotropyNode):Ad).toVar();yn.assign(e.length()),Ti(yn.equal(0),(()=>{e.assign(Ci(1,0))})).Else((()=>{e.divAssign(Ci(yn)),yn.assign(yn.saturate())})),fn.assign(yn.pow2().mix(an.pow2(),1)),bn.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xn.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?vi(this.transmissionNode):wd,t=this.thicknessNode?vi(this.thicknessNode):Md,s=this.attenuationDistanceNode?vi(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Bi(this.attenuationColorNode):Fd;if(En.assign(e),wn.assign(t),Mn.assign(s),Bn.assign(r),this.useDispersion){const e=this.dispersionNode?vi(this.dispersionNode):Gd;Un.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Bi(this.clearcoatNormalNode):_d}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class ug extends Ep{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i){if(!0===this.useSSS){const r=i.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=vi(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Bi(h.add(a).mul(n));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i)}}class lg extends ag{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=vi(.1),this.thicknessAmbientNode=vi(0),this.thicknessAttenuationNode=vi(.1),this.thicknessPowerNode=vi(2),this.thicknessScaleNode=vi(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ug(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const dg=fi((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),i=Ci(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>i});return Bi(e.r)}{const e=i.fwidth().mul(.5);return la(Bi(.7),Bi(1),pa(vi(.7).sub(e.x),vi(.7).add(e.x),i.x))}}));class cg extends Ch{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i){const n=dg({normal:nl,lightDirection:e,builder:i}).mul(t);s.directDiffuse.addAssign(n.mul(Uh({diffuseColor:nn.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:nn}))),s.indirectDiffuse.mulAssign(e)}}const hg=new re;class pg extends ih{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(hg),this.setValues(e)}setupLightingModel(){return new cg}}class gg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Bi(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return Ci(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const mg=mi(gg),fg=new ie;class yg extends ih{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(fg),this.setValues(e)}setupVariants(e){const t=mg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Bi(la(.2,.8,t.y)),nn.rgb.mulAssign(s.rgb)}}const bg=new P;class xg extends ih{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(bg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Tg extends Er{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Oi(e,r,r.negate(),e).mul(s)}{const e=t,r=ki(Ii(1,0,0,0),Ii(0,Eo(e.x),Co(e.x).negate(),0),Ii(0,Co(e.x),Eo(e.x),0),Ii(0,0,0,1)),i=ki(Ii(Eo(e.y),0,Co(e.y),0),Ii(0,1,0,0),Ii(Co(e.y).negate(),0,Eo(e.y),0),Ii(0,0,0,1)),n=ki(Ii(Eo(e.z),Co(e.z).negate(),0,0),Ii(Co(e.z),Eo(e.z),0,0),Ii(0,0,1,0),Ii(0,0,0,1));return r.mul(i).mul(n).mul(Ii(s,1)).xyz}}}const _g=gi(Tg),Ng=new ne;class vg extends ih{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Ng),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:i,rotationNode:n,scaleNode:o}=this,a=Yu;let u=ju.mul(Bi(i||0)),l=Ci(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=vi(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>ci(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=vi(n||Nd),h=_g(d,c);u=Ii(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Sg extends Ch{constructor(){super(),this.shadowNode=vi(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){nn.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(nn.rgb)}}const Ag=new oe;class Rg extends ih{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ag),this.setValues(e)}setupLightingModel(){return new Sg}}const Cg=fi((({texture:e,uv:t})=>{const s=1e-4,r=Bi().toVar();return Ti(t.x.lessThan(s),(()=>{r.assign(Bi(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Bi(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Bi(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Bi(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Bi(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Bi(0,0,-1))})).Else((()=>{const s=.01,i=e.uv(t.add(Bi(-.01,0,0))).r.sub(e.uv(t.add(Bi(s,0,0))).r),n=e.uv(t.add(Bi(0,-.01,0))).r.sub(e.uv(t.add(Bi(0,s,0))).r),o=e.uv(t.add(Bi(0,0,-.01))).r.sub(e.uv(t.add(Bi(0,0,s))).r);r.assign(Bi(i,n,o))})),r.normalize()}));class Eg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Bi(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Cg({texture:this,uv:e})}}const wg=gi(Eg);class Mg extends ih{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=wg(this.map,null,0),s=fi((({orig:e,dir:t})=>{const s=Bi(-.5),r=Bi(.5),i=t.reciprocal(),n=s.sub(e).mul(i),o=r.sub(e).mul(i),a=qo(n,o),u=Ko(n,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return Ci(l,d)}));this.fragmentNode=fi((()=>{const e=Ea(Bi(Wu.mul(Ii(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),i=Ci(s({orig:e,dir:r})).toVar();i.x.greaterThan(i.y).discard(),i.assign(Ci(Ko(i.x,0),i.y));const n=Bi(e.add(i.x.mul(r))).toVar(),o=Bi(r.abs().reciprocal()).toVar(),a=vi(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ii(Fl("base","color"),0).toVar();return uc({type:"float",start:i.x,end:i.y,update:"+= delta"},(()=>{const e=sn("float","d").assign(t.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:n,finalColor:u}).append():(u.a.assign(1),dc()),n.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ii(u)}))(),super.setup(e)}}class Bg{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ug{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const i of e){const e=i.node&&i.node.attribute?i.node.attribute:t.getAttribute(i.name);if(void 0===e)continue;s.push(e);const n=e.isInterleavedBufferAttribute?e.data:e;r.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:i}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(n.instanceCount=u,!0===e.isBatchedMesh)return n;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=i.start*l,c=(i.start+i.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(n.vertexCount=g,n.firstVertex=d,n)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let i;if(null!==r){const e=typeof r;"number"===e?i=0!==r?"1":"0":"object"===e?(i="{",r.isTexture&&(i+=r.mapping),i+="}"):i=String(r)}else i=String(r);s+=i+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Ig=[];class Lg{constructor(e,t,s,r,i,n){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=i,this.info=n,this.chainMaps={}}get(e,t,s,r,i,n,o,a){const u=this.getChainMap(a);Ig[0]=e,Ig[1]=t,Ig[2]=n,Ig[3]=i;let l=u.get(Ig);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,i,n,o,a),u.set(Ig,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,i,n,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ug)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,i,n,o,a,u,l,d){const c=this.getChainMap(d),h=new Pg(e,t,s,r,i,n,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Dg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Vg=1,Og=2,Gg=3,kg=4,zg=16;class $g extends Dg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Vg?this.backend.createAttribute(e):t===Og?this.backend.createIndexAttribute(e):t===Gg?this.backend.createStorageAttribute(e):t===kg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return i.version=Hg(e),i}class jg extends Dg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,i=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of i)this.attributes.delete(e);const n=this.wireframes.get(t);void 0!==n&&this.attributes.delete(n),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Gg):this.updateAttribute(e,Vg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Og);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,kg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Wg(t),e.set(t,s)):s.version!==Hg(t)&&(this.attributes.delete(s),s=Wg(t),e.set(t,s)),r=s}return r}}class qg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Kg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Xg extends Kg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Yg extends Kg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Qg=0;class Zg{constructor(e,t,s=null,r=null){this.id=Qg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Jg extends Dg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const i=r.pipeline;i&&(i.usedTimes--,i.computeProgram.usedTimes--);const n=this.nodes.getForCompute(e);let o=this.programs.compute.get(n.computeShader);void 0===o&&(i&&0===i.computeProgram.usedTimes&&this._releaseProgram(i.computeProgram),o=new Zg(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(i&&0===i.usedTimes&&this._releasePipeline(i),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const i=r.pipeline;i&&(i.usedTimes--,i.vertexProgram.usedTimes--,i.fragmentProgram.usedTimes--);const n=e.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(i&&0===i.vertexProgram.usedTimes&&this._releaseProgram(i.vertexProgram),o=new Zg(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(i&&0===i.fragmentProgram.usedTimes&&this._releaseProgram(i.fragmentProgram),a=new Zg(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(i&&0===i.usedTimes&&this._releasePipeline(i),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let i=this.caches.get(s);return void 0===i&&(i=new Yg(s,t),this.caches.set(s,i),this.backend.createComputePipeline(i,r)),i}_getRenderPipeline(e,t,s,r,i){r=r||this._getRenderCacheKey(e,t,s);let n=this.caches.get(r);return void 0===n&&(n=new Xg(r,t,s),this.caches.set(r,n),e.pipeline=n,this.backend.createRenderPipeline(e,i)),n}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class em extends Dg{constructor(e,t,s,r,i,n){super(),this.backend=e,this.textures=s,this.pipelines=i,this.attributes=r,this.nodes=t,this.info=n,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,s=e.isIndirectStorageBufferAttribute?kg:Gg;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1,i=!0,n=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(r=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=s.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?i=!1:(n=10*n+u.id,o+=u.version),!0===s.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,r),this.textures.updateTexture(u),r=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t,i?n:0,o)}}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function sm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function rm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class im{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,i,n,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:i,group:n,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=i,a.group=n,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,i,n,o){const a=this.getNextRenderItem(e,t,s,r,i,n,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,i,n,o){const a=this.getNextRenderItem(e,t,s,r,i,n,o);!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||tm),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||sm),this.transparent.length>1&&this.transparent.sort(t||sm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||i[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,i[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=n,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(i.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&i.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&i.generateMipmaps(e)}}else i.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=dm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class hm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class pm extends tn{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const gm=(e,t)=>ci(new pm(e,t));class mm extends Ar{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new di(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new di(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new di(e),this}build(e,...t){const s=xi();bi(this);for(const t of this.nodes)t.build(e,"void");return bi(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const fm=gi(mm);class ym extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class bm extends Ar{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let r=0;r{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),Sm=(e,t)=>sa(Gn(4,e.mul(On(1,e))),t),Am=(e,t)=>e.lessThan(.5)?Sm(e.mul(2),t).div(2):On(1,Sm(Gn(On(1,e),2),t).div(2)),Rm=(e,t,s)=>sa(kn(sa(e,t),Vn(sa(e,t),sa(On(1,e),s))),1/t),Cm=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),Em=fi((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),wm=fi((([e])=>Bi(Em(e.z.add(Em(e.y.mul(1)))),Em(e.z.add(Em(e.x.mul(1)))),Em(e.y.add(Em(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Mm=fi((([e,t,s])=>{const r=Bi(e).toVar(),i=vi(1.4).toVar(),n=vi(0).toVar(),o=Bi(r).toVar();return uc({start:vi(0),end:vi(3),type:"float",condition:"<="},(()=>{const e=Bi(wm(o.mul(2))).toVar();r.addAssign(e.add(s.mul(vi(.1).mul(t)))),o.mulAssign(1.8),i.mulAssign(1.5),r.mulAssign(1.2);const a=vi(Em(r.z.add(Em(r.x.add(Em(r.y)))))).toVar();n.addAssign(a.div(i)),o.addAssign(.14)})),n})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Bm extends Ar{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let r=null,i=-1;for(const s of this.functionNodes){const n=s.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=n.inputs;if(t.length===o.length){let n=0;for(let s=0;si&&(r=s,i=n)}}this._candidateFnCall=s=r(...t)}return s}}const Um=gi(Bm),Fm=e=>(...t)=>Um(e,...t),Pm=en(0).setGroup(Qi).onRenderUpdate((e=>e.time)),Im=en(0).setGroup(Qi).onRenderUpdate((e=>e.deltaTime)),Lm=en(0,"uint").setGroup(Qi).onRenderUpdate((e=>e.frameId)),Dm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Pm.mul(e)),Vm=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Pm.mul(e)),Om=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Im.mul(e)),Gm=(e=Pm)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),km=(e=Pm)=>e.fract().round(),zm=(e=Pm)=>e.add(.5).fract().mul(2).sub(1).abs(),$m=(e=Pm)=>e.fract(),Hm=fi((([e,t,s=Ci(.5)])=>_g(e.sub(s),t).add(s))),Wm=fi((([e,t,s=Ci(.5)])=>{const r=e.sub(s),i=r.dot(r),n=i.mul(i).mul(t);return e.add(r.mul(n))})),jm=fi((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const i=Eu.mul(r);return ui(t)&&(i[0][0]=Gu[0].length(),i[0][1]=0,i[0][2]=0),ui(s)&&(i[1][0]=0,i[1][1]=Gu[1].length(),i[1][2]=0),i[2][0]=0,i[2][1]=0,i[2][2]=1,Ru.mul(i).mul(Yu)})),qm=fi((([e=null])=>{const t=Qc();return Qc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class Km extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=vi(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:i}=s,n=e.mod(r.mul(i)).floor(),o=n.mod(r),a=i.sub(n.add(1).div(r).ceil()),u=s.reciprocal(),l=Ci(o,a);return t.add(l).mul(u)}}const Xm=gi(Km);class Ym extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=vi(1),i=Yu,n=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=i,this.normalNode=n}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:i,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(Bi(1)));const a=i.yz.mul(r),u=i.zx.mul(r),l=i.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vn(p,g,m)}}const Qm=gi(Ym),Zm=(...e)=>Qm(...e),Jm=new me,ef=new s,tf=new s,sf=new s,rf=new n,nf=new s(0,0,-1),of=new r,af=new s,uf=new s,lf=new r,df=new t,cf=new ge,hf=Ac.flipX();cf.depthTexture=new B(1,1);let pf=!1;class gf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||cf.texture,hf),this._reflectorBaseNode=e.reflector||new mf(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=ci(new gf({defaultTexture:cf.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class mf extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:i=!1,bounces:n=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=i,this.bounces=n,this.depth=o,this.updateBeforeType=n?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(df),e.setSize(Math.round(df.width*s),Math.round(df.height*s))}setup(e){return this._updateResolution(cf,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&pf)return;pf=!0;const{scene:t,camera:s,renderer:r,material:i}=e,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(df),this._updateResolution(a,r),tf.setFromMatrixPosition(n.matrixWorld),sf.setFromMatrixPosition(s.matrixWorld),rf.extractRotation(n.matrixWorld),ef.set(0,0,1),ef.applyMatrix4(rf),af.subVectors(tf,sf),af.dot(ef)>0)return;af.reflect(ef).negate(),af.add(tf),rf.extractRotation(s.matrixWorld),nf.set(0,0,-1),nf.applyMatrix4(rf),nf.add(sf),uf.subVectors(tf,nf),uf.reflect(ef).negate(),uf.add(tf),o.coordinateSystem=s.coordinateSystem,o.position.copy(af),o.up.set(0,1,0),o.up.applyMatrix4(rf),o.up.reflect(ef),o.lookAt(uf),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),Jm.setFromNormalAndCoplanarPoint(ef,tf),Jm.applyMatrix4(o.matrixWorldInverse),of.set(Jm.normal.x,Jm.normal.y,Jm.normal.z,Jm.constant);const u=o.projectionMatrix;lf.x=(Math.sign(of.x)+u.elements[8])/u.elements[0],lf.y=(Math.sign(of.y)+u.elements[9])/u.elements[5],lf.z=-1,lf.w=(1+u.elements[10])/u.elements[14],of.multiplyScalar(1/of.dot(lf));u.elements[2]=of.x,u.elements[6]=of.y,u.elements[10]=r.coordinateSystem===N?of.z-0:of.z+1-0,u.elements[14]=of.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),i.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),i.visible=!0,pf=!1}}const ff=e=>ci(new gf(e)),yf=new xe(-1,1,1,-1,0,1);class bf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const xf=new bf;class Tf extends k{constructor(e=null){super(xf,e),this.camera=yf,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,yf)}render(e){e.render(this,yf)}}const _f=new t;class Nf extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const i=new ge(t,s,r);super(i.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=i,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new Tf(new ih),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(_f);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const vf=(e,...t)=>ci(new Nf(ci(e),...t)),Sf=(e,...t)=>e.isTextureNode?e:vf(e,...t),Af=fi((([e,t,s],r)=>{let i;r.renderer.coordinateSystem===N?(e=Ci(e.x,e.y.oneMinus()).mul(2).sub(1),i=Ii(Bi(e,t),1)):i=Ii(Bi(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const n=Ii(s.mul(i));return n.xyz.div(n.w)})),Rf=fi((([e,t])=>{const s=t.mul(Ii(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return Ci(r.x,r.y.oneMinus())})),Cf=fi((([e,t,s])=>{const r=yu(Nu(t)),i=Ei(e.mul(r)).toVar(),n=Nu(t,i).toVar(),o=Nu(t,i.sub(Ei(2,0))).toVar(),a=Nu(t,i.sub(Ei(1,0))).toVar(),u=Nu(t,i.add(Ei(1,0))).toVar(),l=Nu(t,i.add(Ei(2,0))).toVar(),d=Nu(t,i.add(Ei(0,2))).toVar(),c=Nu(t,i.add(Ei(0,1))).toVar(),h=Nu(t,i.sub(Ei(0,1))).toVar(),p=Nu(t,i.sub(Ei(0,2))).toVar(),g=Fo(On(vi(2).mul(a).sub(o),n)).toVar(),m=Fo(On(vi(2).mul(u).sub(l),n)).toVar(),f=Fo(On(vi(2).mul(c).sub(d),n)).toVar(),y=Fo(On(vi(2).mul(h).sub(p),n)).toVar(),b=Af(e,n,s).toVar(),x=g.lessThan(m).select(b.sub(Af(e.sub(Ci(vi(1).div(r.x),0)),a,s)),b.negate().add(Af(e.add(Ci(vi(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Af(e.add(Ci(0,vi(1).div(r.y))),c,s)),b.negate().add(Af(e.sub(Ci(0,vi(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class Ef extends pu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const wf=(...e)=>ci(new Ef(...e));class Mf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Bf=mi(Mf),Uf=new ve,Ff=new n;class Pf extends Ar{static get type(){return"SceneNode"}constructor(e=Pf.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===Pf.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===Pf.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===Pf.BACKGROUND_ROTATION?r=en("mat4").label("backgroundRotation").setGroup(Qi).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Uf.copy(s.backgroundRotation),Uf.x*=-1,Uf.y*=-1,Uf.z*=-1,Ff.makeRotationFromEuler(Uf)):Ff.identity(),Ff})):console.error("THREE.SceneNode: Unknown scope:",t),r}}Pf.BACKGROUND_BLURRINESS="backgroundBlurriness",Pf.BACKGROUND_INTENSITY="backgroundIntensity",Pf.BACKGROUND_ROTATION="backgroundRotation";const If=mi(Pf,Pf.BACKGROUND_BLURRINESS),Lf=mi(Pf,Pf.BACKGROUND_INTENSITY),Df=mi(Pf,Pf.BACKGROUND_ROTATION);class Vf extends Rr{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Of=gi(Vf),Gf="point-list",kf="line-list",zf="line-strip",$f="triangle-list",Hf="triangle-strip",Wf="never",jf="less",qf="equal",Kf="less-equal",Xf="greater",Yf="not-equal",Qf="greater-equal",Zf="always",Jf="store",ey="load",ty="clear",sy="ccw",ry="none",iy="front",ny="back",oy="uint16",ay="uint32",uy={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},ly="clamp-to-edge",dy="repeat",cy="mirror-repeat",hy="linear",py="nearest",gy="zero",my="one",fy="src",yy="one-minus-src",by="src-alpha",xy="one-minus-src-alpha",Ty="dst",_y="one-minus-dst",Ny="dst-alpha",vy="one-minus-dst-alpha",Sy="src-alpha-saturated",Ay="constant",Ry="one-minus-constant",Cy="add",Ey="subtract",wy="reverse-subtract",My="min",By="max",Uy=0,Fy=15,Py="keep",Iy="zero",Ly="replace",Dy="invert",Vy="increment-clamp",Oy="decrement-clamp",Gy="increment-wrap",ky="decrement-wrap",zy="storage",$y="read-only-storage",Hy="write-only",Wy="read-only",jy="float",qy="unfilterable-float",Ky="depth",Xy="sint",Yy="uint",Qy="2d",Zy="3d",Jy="2d",eb="2d-array",tb="cube",sb="3d",rb="all",ib="vertex",nb="instance",ob={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class ab extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=zy,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Of(this,e)}setBufferObject(e){return this.bufferObject=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess($y)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),r=s.build(e);return e.registerTransform(r,t),r}}const ub=(e,t,s)=>ci(new ab(e,t,s)),lb=(e,t,s)=>ci(new ab(e,t,s).setBufferObject(!0));class db extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Hy}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(Wy)}toWriteOnly(){return this.setAccess(Hy)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,i=super.generate(e,"property"),n=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,i,n,o);e.addLineFlowCode(a,this)}}const cb=gi(db),hb=(e,t,s)=>{const r=cb(e,t,s);return null!==s&&r.append(),r};class pb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const gb=(e,t,s)=>ci(new pb(e,t,s)),mb=new WeakMap;class fb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=en(new n),this.previousProjectionMatrix=en(new n).setGroup(Qi),this.previousCameraViewMatrix=en(new n)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=bb(s);this.previousModelWorldMatrix.value.copy(r);const i=yb(t);i.frameId!==e&&(i.frameId=e,void 0===i.previousProjectionMatrix?(i.previousProjectionMatrix=new n,i.previousCameraViewMatrix=new n,i.currentProjectionMatrix=new n,i.currentCameraViewMatrix=new n,i.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(i.previousProjectionMatrix.copy(i.currentProjectionMatrix),i.previousCameraViewMatrix.copy(i.currentCameraViewMatrix)),i.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(i.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(i.previousCameraViewMatrix))}updateAfter({object:e}){bb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:en(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),i=s.xy.div(s.w),n=r.xy.div(r.w);return On(i,n)}}function yb(e){let t=mb.get(e);return void 0===t&&(t={},mb.set(e,t)),t}function bb(e,t=0){const s=yb(e);let r=s[t];return void 0===r&&(s[t]=r=new n),r}const xb=mi(fb),Tb=fi((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),_b=fi((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Nb=fi((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=fi((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Sb=fi((([e,t])=>Ii(e.rgb.mul(t.a.oneMinus()).add(t.rgb.mul(t.a)),e.a))).setLayout({name:"blendNormal",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Ab=fi((([e])=>wb(e.rgb))),Rb=fi((([e,t=vi(1)])=>t.mix(wb(e.rgb),e.rgb))),Cb=fi((([e,t=vi(1)])=>{const s=Vn(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),i=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,i)})),Eb=fi((([e,t=vi(1)])=>{const s=Bi(.57735,.57735,.57735),r=t.cos();return Bi(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),wb=(e,t=Bi(u.getLuminanceCoefficients(new s)))=>ea(e,t),Mb=(e,t)=>la(Bi(0),e,wb(e).sub(t).max(0)),Bb=fi((([e,t=Bi(1),r=Bi(0),i=Bi(1),n=vi(1),o=Bi(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Bi(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(i).toVar();return Ti(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),Ti(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),Ti(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(n))),Ii(l.rgb,e.a)}));class Ub extends Er{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Fb=gi(Ub);let Pb=null;class Ib extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Pb&&(Pb=new w),super(e,t,Pb)}updateReference(){return this}}const Lb=gi(Ib),Db=new t;class Vb extends Tu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class Ob extends Vb{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class Gb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const i=new B;i.isRenderTargetTexture=!0,i.name="depth";const n=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});n.texture.name="output",n.depthTexture=i,this.renderTarget=n,this.updateBeforeType=br.FRAME,this._textures={output:n.texture,depth:i},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=en(0),this._cameraFar=en(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=ci(new Ob(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=ci(new Ob(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,i=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(i,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===Gb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const i=t.getSize(Db);this.setSize(i.width,i.height);const n=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(n),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Gb.COLOR="color",Gb.DEPTH="depth";const kb=(e,t,s)=>ci(new Gb(Gb.COLOR,e,t,s)),zb=(e,t)=>ci(new Vb(e,t)),$b=(e,t)=>ci(new Gb(Gb.DEPTH,e,t));class Hb extends Gb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,i){super(Gb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=i,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,i,n,o,a,u)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){const l=this._getOutlineMaterial(n);t.renderObject(e,s,r,i,l,o,a,u)}t.renderObject(e,s,r,i,n,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new ih;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=vi(1),i=s.mul(Ii(Yu,1)),n=s.mul(Ii(Yu.add(t),1)),o=Ao(i.sub(n));return e.vertexNode=i.add(o.mul(this.thicknessNode).mul(i.w).mul(r)),e.colorNode=Ii(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const Wb=(t,s,r=new e(0,0,0),i=.003,n=1)=>ci(new Hb(t,s,ci(r),ci(i),ci(n))),jb=fi((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),qb=fi((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Kb=fi((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=fi((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Yb=fi((([e,t])=>{const s=Gi(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=Gi(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=Xb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qb=Gi(Bi(1.6605,-.1246,-.0182),Bi(-.5876,1.1329,-.1006),Bi(-.0728,-.0083,1.1187)),Zb=Gi(Bi(.6274,.0691,.0164),Bi(.3293,.9195,.088),Bi(.0433,.0113,.8956)),Jb=fi((([e])=>{const t=Bi(e).toVar(),s=Bi(t.mul(t)).toVar(),r=Bi(s.mul(s)).toVar();return vi(15.5).mul(r.mul(s)).sub(Gn(40.14,r.mul(t))).add(Gn(31.96,r).sub(Gn(6.868,s.mul(t))).add(Gn(.4298,s).add(Gn(.1191,t).sub(.00232))))})),ex=fi((([e,t])=>{const s=Bi(e).toVar(),r=Gi(Bi(.856627153315983,.137318972929847,.11189821299995),Bi(.0951212405381588,.761241990602591,.0767994186031903),Bi(.0482516061458583,.101439036467562,.811302368396859)),i=Gi(Bi(1.1271005818144368,-.1413297634984383,-.14132976349843826),Bi(-.11060664309660323,1.157823702216272,-.11060664309660294),Bi(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=vi(-12.47393),o=vi(4.026069);return s.mulAssign(t),s.assign(Zb.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(da(s,0,1)),s.assign(Jb(s)),s.assign(i.mul(s)),s.assign(sa(Ko(Bi(0),s),Bi(2.2))),s.assign(Qb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),tx=fi((([e,t])=>{const s=vi(.76),r=vi(.15);e=e.mul(t);const i=qo(e.r,qo(e.g,e.b)),n=xa(i.lessThan(.08),i.sub(Gn(6.25,i.mul(i))),.04);e.subAssign(n);const o=Ko(e.r,Ko(e.g,e.b));Ti(o.lessThan(s),(()=>e));const a=On(1,s),u=On(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=On(1,kn(1,r.mul(o.sub(u)).add(1)));return la(e,Bi(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class sx extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const rx=gi(sx),ix=(e,t)=>rx(e,t,"js"),nx=(e,t)=>rx(e,t,"wgsl"),ox=(e,t)=>rx(e,t,"glsl");class ax extends sx{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,i=s.type,n=e.getCodeFromNode(this,i);""!==r&&(n.name=r);const o=e.getPropertyName(n),a=this.getNodeFunction(e).getCode(o);return n.code=a+"\n","property"===t?o:e.format(`${o}()`,i,t)}}const ux=(e,t=[],s="")=>{for(let e=0;er.call(...e);return i.functionNode=r,i},lx=(e,t)=>ux(e,t,"glsl"),dx=(e,t)=>ux(e,t,"wgsl");class cx extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:vi()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const hx=gi(cx);class px extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class gx{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const mx=new px;class fx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new px,this._output=hx(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=hx(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=hx(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new gx(this),t=mx.get("THREE"),s=mx.get("TSL"),r=this.getMethod(this.codeNode),i=[e,this._local,mx,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...i);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const e of n.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:vi()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const yx=gi(fx);class bx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const xx=gi(bx);class Tx extends bx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const _x=gi(Tx);class Nx extends bx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const vx=gi(Nx);let Sx=null,Ax=null;class Rx extends Ar{static get type(){return"RangeNode"}constructor(e=vi(),t=vi()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const i=this.minNode.value,n=this.maxNode.value,o=e.getTypeLength(hr(i)),u=e.getTypeLength(hr(n));Sx=Sx||new r,Ax=Ax||new r,Sx.setScalar(0),Ax.setScalar(0),1===o?Sx.setScalar(i):i.isColor?Sx.set(i.r,i.g,i.b):Sx.set(i.x,i.y,i.z||0,i.w||0),1===u?Ax.setScalar(n):n.isColor?Ax.set(n.r,n.g,n.b):Ax.set(n.x,n.y,n.z||0,n.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;eci(new Ex(e,t)),Mx=wx("numWorkgroups","uvec3"),Bx=wx("workgroupId","uvec3"),Ux=wx("localId","uvec3"),Fx=wx("subgroupSize","uint");const Px=gi(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Ix=()=>Px("workgroup").append(),Lx=()=>Px("storage").append(),Dx=()=>Px("texture").append();class Vx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class Ox extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return ci(new Vx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const Gx=(e,t)=>ci(new Ox("Workgroup",e,t));class kx extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),i=this.pointerNode,n=this.valueNode,o=[];o.push(`&${i.build(e,r)}`),o.push(n.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}kx.ATOMIC_LOAD="atomicLoad",kx.ATOMIC_STORE="atomicStore",kx.ATOMIC_ADD="atomicAdd",kx.ATOMIC_SUB="atomicSub",kx.ATOMIC_MAX="atomicMax",kx.ATOMIC_MIN="atomicMin",kx.ATOMIC_AND="atomicAnd",kx.ATOMIC_OR="atomicOr",kx.ATOMIC_XOR="atomicXor";const zx=gi(kx),$x=(e,t,s,r)=>{const i=zx(e,t,s,r);return i.append(),i},Hx=(e,t,s=null)=>$x(kx.ATOMIC_STORE,e,t,s),Wx=(e,t,s=null)=>$x(kx.ATOMIC_ADD,e,t,s),jx=(e,t,s=null)=>$x(kx.ATOMIC_SUB,e,t,s),qx=(e,t,s=null)=>$x(kx.ATOMIC_MAX,e,t,s),Kx=(e,t,s=null)=>$x(kx.ATOMIC_MIN,e,t,s),Xx=(e,t,s=null)=>$x(kx.ATOMIC_AND,e,t,s),Yx=(e,t,s=null)=>$x(kx.ATOMIC_OR,e,t,s),Qx=(e,t,s=null)=>$x(kx.ATOMIC_XOR,e,t,s);let Zx;function Jx(e){Zx=Zx||new WeakMap;let t=Zx.get(e);return void 0===t&&Zx.set(e,t={}),t}function eT(e){const t=Jx(e);return t.position||(t.position=en(new s).setGroup(Qi).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function tT(e){const t=Jx(e);return t.targetPosition||(t.targetPosition=en(new s).setGroup(Qi).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function sT(e){const t=Jx(e);return t.viewPosition||(t.viewPosition=en(new s).setGroup(Qi).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const rT=e=>Eu.transformDirection(eT(e).sub(tT(e))),iT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},nT=new WeakMap;class oT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Bi().toVar("totalDiffuse"),this.totalSpecularNode=Bi().toVar("totalSpecular"),this.outgoingLightNode=Bi().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),i=e.renderer.library;for(const e of r)if(e.isNode)t.push(ci(e));else{let r=null;if(null!==s&&(r=iT(e.id,s)),null===r){const s=i.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;nT.has(e)?r=nT.get(e):(r=ci(new s(e)),nT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:i,totalDiffuseNode:n,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,i),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Bi(null!==l?l.mix(g,u):u),t.material.transparent=!0),n.assign(g),o.assign(c.add(p)),r.assign(n.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const aT=(e=[])=>ci(new oT).setLights(e),uT=fi((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),lT=fi((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),i=Ml("mapSize","vec2",s).setGroup(Qi),n=Ml("radius","float",s).setGroup(Qi),o=Ci(1).div(i),a=o.x.negate().mul(n),u=o.y.negate().mul(n),l=o.x.mul(n),d=o.y.mul(n),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vn(r(t.xy.add(Ci(a,u)),t.z),r(t.xy.add(Ci(0,u)),t.z),r(t.xy.add(Ci(l,u)),t.z),r(t.xy.add(Ci(c,h)),t.z),r(t.xy.add(Ci(0,h)),t.z),r(t.xy.add(Ci(p,h)),t.z),r(t.xy.add(Ci(a,0)),t.z),r(t.xy.add(Ci(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(Ci(p,0)),t.z),r(t.xy.add(Ci(l,0)),t.z),r(t.xy.add(Ci(c,g)),t.z),r(t.xy.add(Ci(0,g)),t.z),r(t.xy.add(Ci(p,g)),t.z),r(t.xy.add(Ci(a,d)),t.z),r(t.xy.add(Ci(0,d)),t.z),r(t.xy.add(Ci(l,d)),t.z)).mul(1/17)})),dT=fi((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),i=Ml("mapSize","vec2",s).setGroup(Qi),n=Ci(1).div(i),o=n.x,a=n.y,u=t.xy,l=Ro(u.mul(i).add(.5));return u.subAssign(l.mul(n)),Vn(r(u,t.z),r(u.add(Ci(o,0)),t.z),r(u.add(Ci(0,a)),t.z),r(u.add(n),t.z),la(r(u.add(Ci(o.negate(),0)),t.z),r(u.add(Ci(o.mul(2),0)),t.z),l.x),la(r(u.add(Ci(o.negate(),a)),t.z),r(u.add(Ci(o.mul(2),a)),t.z),l.x),la(r(u.add(Ci(0,a.negate())),t.z),r(u.add(Ci(0,a.mul(2))),t.z),l.y),la(r(u.add(Ci(o,a.negate())),t.z),r(u.add(Ci(o,a.mul(2))),t.z),l.y),la(la(r(u.add(Ci(o.negate(),a.negate())),t.z),r(u.add(Ci(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(Ci(o.negate(),a.mul(2))),t.z),r(u.add(Ci(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),cT=fi((({depthTexture:e,shadowCoord:t})=>{const s=vi(1).toVar(),r=_u(e).uv(t.xy).rg,i=Yo(t.z,r.x);return Ti(i.notEqual(vi(1)),(()=>{const e=t.z.sub(r.x),n=Ko(0,r.y.mul(r.y));let o=n.div(n.add(e.mul(e)));o=da(On(o,.3).div(.95-.3)),s.assign(da(Ko(i,o)))})),s})),hT=fi((({samples:e,radius:t,size:s,shadowPass:r})=>{const i=vi(0).toVar(),n=vi(0).toVar(),o=e.lessThanEqual(vi(1)).select(vi(0),vi(2).div(e.sub(1))),a=e.lessThanEqual(vi(1)).select(vi(0),vi(-1));uc({start:Si(0),end:Si(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(vi(e).mul(o)),l=r.uv(Vn(Cc.xy,Ci(0,u).mul(t)).div(s)).x;i.addAssign(l),n.addAssign(l.mul(l))})),i.divAssign(e),n.divAssign(e);const u=_o(n.sub(i.mul(i)));return Ci(i,u)})),pT=fi((({samples:e,radius:t,size:s,shadowPass:r})=>{const i=vi(0).toVar(),n=vi(0).toVar(),o=e.lessThanEqual(vi(1)).select(vi(0),vi(2).div(e.sub(1))),a=e.lessThanEqual(vi(1)).select(vi(0),vi(-1));uc({start:Si(0),end:Si(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(vi(e).mul(o)),l=r.uv(Vn(Cc.xy,Ci(u,0).mul(t)).div(s));i.addAssign(l.x),n.addAssign(Vn(l.y.mul(l.y),l.x.mul(l.x)))})),i.divAssign(e),n.divAssign(e);const u=_o(n.sub(i.mul(i)));return Ci(i,u)})),gT=[uT,lT,dT,cT];let mT=null;const fT=new Tf;class yT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===mT&&(mT=new ih,mT.fragmentNode=Ii(0,0,0,1),mT.isShadowNodeMaterial=!0,mT.name="ShadowMaterial");const r=this.shadow,i=s.shadowMap.type,n=new B(r.mapSize.width,r.mapSize.height);n.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=n,r.camera.updateProjectionMatrix(),i===Re){n.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(n),s=_u(this.vsmShadowMapVertical.texture),i=Ml("blurSamples","float",r).setGroup(Qi),o=Ml("radius","float",r).setGroup(Qi),a=Ml("mapSize","vec2",r).setGroup(Qi);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new ih);u.fragmentNode=hT({samples:i,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new ih),u.fragmentNode=pT({samples:i,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Qi),u=Ml("bias","float",r).setGroup(Qi),l=Ml("normalBias","float",r).setGroup(Qi),d=t.material.shadowPositionNode||Zu;let c,h=en(r.matrix).setGroup(Qi).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=Ml("near","float",r.camera).setGroup(Qi),s=Ml("far","float",r.camera).setGroup(Qi);c=qc(e.negate(),t,s)}h=Bi(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||gT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:i===Re?this.vsmShadowMapHorizontal.texture:n,shadowCoord:h,shadow:r}),vi(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:i,scene:n,camera:o}=e,a=i.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=n.overrideMaterial;n.overrideMaterial=mT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=i.getRenderTarget(),c=i.getRenderObjectFunction();i.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&i.renderObject(e,...t)})),i.setRenderTarget(t),i.render(n,r.camera),i.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(i),i.setRenderTarget(d),n.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),fT.material=this.vsmMaterialVertical,fT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),fT.material=this.vsmMaterialHorizontal,fT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const bT=(e,t)=>ci(new yT(e,t));class xT extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=en(this.color).setGroup(Qi),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?ci(e):bT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const TT=fi((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,i=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(i.mul(t.div(s).pow4().oneMinus().clamp().pow2()),i)})),_T=fi((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},i)=>{const n=i.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=TT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=i.context.reflectedLight;n.direct({lightDirection:a,lightColor:d,reflectedLight:c},i.stack,i)}));class NT extends xT{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=en(0).setGroup(Qi),this.decayExponentNode=en(0).setGroup(Qi)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){_T({color:this.colorNode,lightViewPosition:sT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const vT=fi((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),ST=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Ri(e).toVar();return xa(n,i,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),AT=fi((([e,t])=>{const s=Ri(t).toVar(),r=vi(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),RT=fi((([e])=>{const t=vi(e).toVar();return Si(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),CT=fi((([e,t])=>{const s=vi(e).toVar();return t.assign(RT(s)),s.sub(vi(t))})),ET=Fm([fi((([e,t,s,r,i,n])=>{const o=vi(n).toVar(),a=vi(i).toVar(),u=vi(r).toVar(),l=vi(s).toVar(),d=vi(t).toVar(),c=vi(e).toVar(),h=vi(On(1,a)).toVar();return On(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),fi((([e,t,s,r,i,n])=>{const o=vi(n).toVar(),a=vi(i).toVar(),u=Bi(r).toVar(),l=Bi(s).toVar(),d=Bi(t).toVar(),c=Bi(e).toVar(),h=vi(On(1,a)).toVar();return On(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),wT=Fm([fi((([e,t,s,r,i,n,o,a,u,l,d])=>{const c=vi(d).toVar(),h=vi(l).toVar(),p=vi(u).toVar(),g=vi(a).toVar(),m=vi(o).toVar(),f=vi(n).toVar(),y=vi(i).toVar(),b=vi(r).toVar(),x=vi(s).toVar(),T=vi(t).toVar(),_=vi(e).toVar(),N=vi(On(1,p)).toVar(),v=vi(On(1,h)).toVar();return vi(On(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),fi((([e,t,s,r,i,n,o,a,u,l,d])=>{const c=vi(d).toVar(),h=vi(l).toVar(),p=vi(u).toVar(),g=Bi(a).toVar(),m=Bi(o).toVar(),f=Bi(n).toVar(),y=Bi(i).toVar(),b=Bi(r).toVar(),x=Bi(s).toVar(),T=Bi(t).toVar(),_=Bi(e).toVar(),N=vi(On(1,p)).toVar(),v=vi(On(1,h)).toVar();return vi(On(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),MT=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Ai(e).toVar(),o=Ai(n.bitAnd(Ai(7))).toVar(),a=vi(ST(o.lessThan(Ai(4)),i,r)).toVar(),u=vi(Gn(2,ST(o.lessThan(Ai(4)),r,i))).toVar();return AT(a,Ri(o.bitAnd(Ai(1)))).add(AT(u,Ri(o.bitAnd(Ai(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),BT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=vi(t).toVar(),a=Ai(e).toVar(),u=Ai(a.bitAnd(Ai(15))).toVar(),l=vi(ST(u.lessThan(Ai(8)),o,n)).toVar(),d=vi(ST(u.lessThan(Ai(4)),n,ST(u.equal(Ai(12)).or(u.equal(Ai(14))),o,i))).toVar();return AT(l,Ri(u.bitAnd(Ai(1)))).add(AT(d,Ri(u.bitAnd(Ai(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),UT=Fm([MT,BT]),FT=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Fi(e).toVar();return Bi(UT(n.x,i,r),UT(n.y,i,r),UT(n.z,i,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),PT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=vi(t).toVar(),a=Fi(e).toVar();return Bi(UT(a.x,o,n,i),UT(a.y,o,n,i),UT(a.z,o,n,i))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),IT=Fm([FT,PT]),LT=fi((([e])=>{const t=vi(e).toVar();return Gn(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),DT=fi((([e])=>{const t=vi(e).toVar();return Gn(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),VT=Fm([LT,fi((([e])=>{const t=Bi(e).toVar();return Gn(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),OT=Fm([DT,fi((([e])=>{const t=Bi(e).toVar();return Gn(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),GT=fi((([e,t])=>{const s=Si(t).toVar(),r=Ai(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(Si(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),kT=fi((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(GT(s,Si(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,Si(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,Si(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(GT(s,Si(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,Si(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,Si(4))),t.addAssign(e)})),zT=fi((([e,t,s])=>{const r=Ai(s).toVar(),i=Ai(t).toVar(),n=Ai(e).toVar();return r.bitXorAssign(i),r.subAssign(GT(i,Si(14))),n.bitXorAssign(r),n.subAssign(GT(r,Si(11))),i.bitXorAssign(n),i.subAssign(GT(n,Si(25))),r.bitXorAssign(i),r.subAssign(GT(i,Si(16))),n.bitXorAssign(r),n.subAssign(GT(r,Si(4))),i.bitXorAssign(n),i.subAssign(GT(n,Si(14))),r.bitXorAssign(i),r.subAssign(GT(i,Si(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),$T=fi((([e])=>{const t=Ai(e).toVar();return vi(t).div(vi(Ai(Si(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),HT=fi((([e])=>{const t=vi(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),WT=Fm([fi((([e])=>{const t=Si(e).toVar(),s=Ai(Ai(1)).toVar(),r=Ai(Ai(Si(3735928559)).add(s.shiftLeft(Ai(2))).add(Ai(13))).toVar();return zT(r.add(Ai(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),fi((([e,t])=>{const s=Si(t).toVar(),r=Si(e).toVar(),i=Ai(Ai(2)).toVar(),n=Ai().toVar(),o=Ai().toVar(),a=Ai().toVar();return n.assign(o.assign(a.assign(Ai(Si(3735928559)).add(i.shiftLeft(Ai(2))).add(Ai(13))))),n.addAssign(Ai(r)),o.addAssign(Ai(s)),zT(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),fi((([e,t,s])=>{const r=Si(s).toVar(),i=Si(t).toVar(),n=Si(e).toVar(),o=Ai(Ai(3)).toVar(),a=Ai().toVar(),u=Ai().toVar(),l=Ai().toVar();return a.assign(u.assign(l.assign(Ai(Si(3735928559)).add(o.shiftLeft(Ai(2))).add(Ai(13))))),a.addAssign(Ai(n)),u.addAssign(Ai(i)),l.addAssign(Ai(r)),zT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),fi((([e,t,s,r])=>{const i=Si(r).toVar(),n=Si(s).toVar(),o=Si(t).toVar(),a=Si(e).toVar(),u=Ai(Ai(4)).toVar(),l=Ai().toVar(),d=Ai().toVar(),c=Ai().toVar();return l.assign(d.assign(c.assign(Ai(Si(3735928559)).add(u.shiftLeft(Ai(2))).add(Ai(13))))),l.addAssign(Ai(a)),d.addAssign(Ai(o)),c.addAssign(Ai(n)),kT(l,d,c),l.addAssign(Ai(i)),zT(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),fi((([e,t,s,r,i])=>{const n=Si(i).toVar(),o=Si(r).toVar(),a=Si(s).toVar(),u=Si(t).toVar(),l=Si(e).toVar(),d=Ai(Ai(5)).toVar(),c=Ai().toVar(),h=Ai().toVar(),p=Ai().toVar();return c.assign(h.assign(p.assign(Ai(Si(3735928559)).add(d.shiftLeft(Ai(2))).add(Ai(13))))),c.addAssign(Ai(l)),h.addAssign(Ai(u)),p.addAssign(Ai(a)),kT(c,h,p),c.addAssign(Ai(o)),h.addAssign(Ai(n)),zT(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),jT=Fm([fi((([e,t])=>{const s=Si(t).toVar(),r=Si(e).toVar(),i=Ai(WT(r,s)).toVar(),n=Fi().toVar();return n.x.assign(i.bitAnd(Si(255))),n.y.assign(i.shiftRight(Si(8)).bitAnd(Si(255))),n.z.assign(i.shiftRight(Si(16)).bitAnd(Si(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),fi((([e,t,s])=>{const r=Si(s).toVar(),i=Si(t).toVar(),n=Si(e).toVar(),o=Ai(WT(n,i,r)).toVar(),a=Fi().toVar();return a.x.assign(o.bitAnd(Si(255))),a.y.assign(o.shiftRight(Si(8)).bitAnd(Si(255))),a.z.assign(o.shiftRight(Si(16)).bitAnd(Si(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),qT=Fm([fi((([e])=>{const t=Ci(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=vi(CT(t.x,s)).toVar(),n=vi(CT(t.y,r)).toVar(),o=vi(HT(i)).toVar(),a=vi(HT(n)).toVar(),u=vi(ET(UT(WT(s,r),i,n),UT(WT(s.add(Si(1)),r),i.sub(1),n),UT(WT(s,r.add(Si(1))),i,n.sub(1)),UT(WT(s.add(Si(1)),r.add(Si(1))),i.sub(1),n.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=Si().toVar(),n=vi(CT(t.x,s)).toVar(),o=vi(CT(t.y,r)).toVar(),a=vi(CT(t.z,i)).toVar(),u=vi(HT(n)).toVar(),l=vi(HT(o)).toVar(),d=vi(HT(a)).toVar(),c=vi(wT(UT(WT(s,r,i),n,o,a),UT(WT(s.add(Si(1)),r,i),n.sub(1),o,a),UT(WT(s,r.add(Si(1)),i),n,o.sub(1),a),UT(WT(s.add(Si(1)),r.add(Si(1)),i),n.sub(1),o.sub(1),a),UT(WT(s,r,i.add(Si(1))),n,o,a.sub(1)),UT(WT(s.add(Si(1)),r,i.add(Si(1))),n.sub(1),o,a.sub(1)),UT(WT(s,r.add(Si(1)),i.add(Si(1))),n,o.sub(1),a.sub(1)),UT(WT(s.add(Si(1)),r.add(Si(1)),i.add(Si(1))),n.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),KT=Fm([fi((([e])=>{const t=Ci(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=vi(CT(t.x,s)).toVar(),n=vi(CT(t.y,r)).toVar(),o=vi(HT(i)).toVar(),a=vi(HT(n)).toVar(),u=Bi(ET(IT(jT(s,r),i,n),IT(jT(s.add(Si(1)),r),i.sub(1),n),IT(jT(s,r.add(Si(1))),i,n.sub(1)),IT(jT(s.add(Si(1)),r.add(Si(1))),i.sub(1),n.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=Si().toVar(),n=vi(CT(t.x,s)).toVar(),o=vi(CT(t.y,r)).toVar(),a=vi(CT(t.z,i)).toVar(),u=vi(HT(n)).toVar(),l=vi(HT(o)).toVar(),d=vi(HT(a)).toVar(),c=Bi(wT(IT(jT(s,r,i),n,o,a),IT(jT(s.add(Si(1)),r,i),n.sub(1),o,a),IT(jT(s,r.add(Si(1)),i),n,o.sub(1),a),IT(jT(s.add(Si(1)),r.add(Si(1)),i),n.sub(1),o.sub(1),a),IT(jT(s,r,i.add(Si(1))),n,o,a.sub(1)),IT(jT(s.add(Si(1)),r,i.add(Si(1))),n.sub(1),o,a.sub(1)),IT(jT(s,r.add(Si(1)),i.add(Si(1))),n,o.sub(1),a.sub(1)),IT(jT(s.add(Si(1)),r.add(Si(1)),i.add(Si(1))),n.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),XT=Fm([fi((([e])=>{const t=vi(e).toVar(),s=Si(RT(t)).toVar();return $T(WT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),fi((([e])=>{const t=Ci(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar();return $T(WT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar();return $T(WT(s,r,i))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),fi((([e])=>{const t=Ii(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar(),n=Si(RT(t.w)).toVar();return $T(WT(s,r,i,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),YT=Fm([fi((([e])=>{const t=vi(e).toVar(),s=Si(RT(t)).toVar();return Bi($T(WT(s,Si(0))),$T(WT(s,Si(1))),$T(WT(s,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),fi((([e])=>{const t=Ci(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar();return Bi($T(WT(s,r,Si(0))),$T(WT(s,r,Si(1))),$T(WT(s,r,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar();return Bi($T(WT(s,r,i,Si(0))),$T(WT(s,r,i,Si(1))),$T(WT(s,r,i,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),fi((([e])=>{const t=Ii(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar(),n=Si(RT(t.w)).toVar();return Bi($T(WT(s,r,i,n,Si(0))),$T(WT(s,r,i,n,Si(1))),$T(WT(s,r,i,n,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),QT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=vi(0).toVar(),l=vi(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(qT(a))),l.mulAssign(i),a.mulAssign(n)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),ZT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=Bi(0).toVar(),l=vi(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(KT(a))),l.mulAssign(i),a.mulAssign(n)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),JT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar();return Ci(QT(a,o,n,i),QT(a.add(Bi(Si(19),Si(193),Si(17))),o,n,i))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),e_=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=Bi(ZT(a,o,n,i)).toVar(),l=vi(QT(a.add(Bi(Si(19),Si(193),Si(17))),o,n,i)).toVar();return Ii(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),t_=Fm([fi((([e,t,s,r,i,n,o])=>{const a=Si(o).toVar(),u=vi(n).toVar(),l=Si(i).toVar(),d=Si(r).toVar(),c=Si(s).toVar(),h=Si(t).toVar(),p=Ci(e).toVar(),g=Bi(YT(Ci(h.add(d),c.add(l)))).toVar(),m=Ci(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=Ci(Ci(vi(h),vi(c)).add(m)).toVar(),y=Ci(f.sub(p)).toVar();return Ti(a.equal(Si(2)),(()=>Fo(y.x).add(Fo(y.y)))),Ti(a.equal(Si(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),fi((([e,t,s,r,i,n,o,a,u])=>{const l=Si(u).toVar(),d=vi(a).toVar(),c=Si(o).toVar(),h=Si(n).toVar(),p=Si(i).toVar(),g=Si(r).toVar(),m=Si(s).toVar(),f=Si(t).toVar(),y=Bi(e).toVar(),b=Bi(YT(Bi(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Bi(Bi(vi(f),vi(m),vi(g)).add(b)).toVar(),T=Bi(x.sub(y)).toVar();return Ti(l.equal(Si(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),Ti(l.equal(Si(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),s_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=vi(1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();l.assign(qo(l,s))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),r_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=Ci(1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();Ti(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=Bi(1e6,1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();Ti(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),n_=Fm([s_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=vi(1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();d.assign(qo(d,n))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),o_=Fm([r_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=Ci(1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();Ti(n.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(n)})).ElseIf(n.lessThan(d.y),(()=>{d.y.assign(n)}))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),a_=Fm([i_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=Bi(1e6,1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();Ti(n.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(n)})).ElseIf(n.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(n)})).ElseIf(n.lessThan(d.z),(()=>{d.z.assign(n)}))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=fi((([e])=>{const t=e.y,s=e.z,r=Bi().toVar();return Ti(t.lessThan(1e-4),(()=>{r.assign(Bi(s,s,s))})).Else((()=>{let i=e.x;i=i.sub(vo(i)).mul(6).toVar();const n=Si(zo(i)),o=i.sub(vi(n)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());Ti(n.equal(Si(0)),(()=>{r.assign(Bi(s,l,a))})).ElseIf(n.equal(Si(1)),(()=>{r.assign(Bi(u,s,a))})).ElseIf(n.equal(Si(2)),(()=>{r.assign(Bi(a,s,l))})).ElseIf(n.equal(Si(3)),(()=>{r.assign(Bi(a,u,s))})).ElseIf(n.equal(Si(4)),(()=>{r.assign(Bi(l,a,s))})).Else((()=>{r.assign(Bi(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),l_=fi((([e])=>{const t=Bi(e).toVar(),s=vi(t.x).toVar(),r=vi(t.y).toVar(),i=vi(t.z).toVar(),n=vi(qo(s,qo(r,i))).toVar(),o=vi(Ko(s,Ko(r,i))).toVar(),a=vi(o.sub(n)).toVar(),u=vi().toVar(),l=vi().toVar(),d=vi().toVar();return d.assign(o),Ti(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),Ti(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{Ti(s.greaterThanEqual(o),(()=>{u.assign(r.sub(i).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vn(2,i.sub(s).div(a)))})).Else((()=>{u.assign(Vn(4,s.sub(r).div(a)))})),u.mulAssign(1/6),Ti(u.lessThan(0),(()=>{u.addAssign(1)}))})),Bi(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),d_=fi((([e])=>{const t=Bi(e).toVar(),s=Pi(jn(t,Bi(.04045))).toVar(),r=Bi(t.div(12.92)).toVar(),i=Bi(sa(Ko(t.add(Bi(.055)),Bi(0)).div(1.055),Bi(2.4))).toVar();return la(r,i,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),c_=(e,t)=>{e=vi(e),t=vi(t);const s=Ci(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},h_=(e,t,s,r)=>la(e,t,s[r].clamp()),p_=(e,t,s=mu())=>h_(e,t,s,"x"),g_=(e,t,s=mu())=>h_(e,t,s,"y"),m_=(e,t,s,r,i)=>la(e,t,c_(s,r[i])),f_=(e,t,s,r=mu())=>m_(e,t,s,r,"x"),y_=(e,t,s,r=mu())=>m_(e,t,s,r,"y"),b_=(e=1,t=0,s=mu())=>s.mul(e).add(t),x_=(e,t=1)=>(e=vi(e)).abs().pow(t).mul(e.sign()),T_=(e,t=1,s=.5)=>vi(e).sub(s).mul(t).add(s),__=(e=mu(),t=1,s=0)=>qT(e.convert("vec2|vec3")).mul(t).add(s),N_=(e=mu(),t=1,s=0)=>KT(e.convert("vec2|vec3")).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ii(KT(e),qT(e.add(Ci(19,73)))).mul(t).add(s)},S_=(e=mu(),t=1)=>n_(e.convert("vec2|vec3"),t,Si(1)),A_=(e=mu(),t=1)=>o_(e.convert("vec2|vec3"),t,Si(1)),R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,Si(1)),C_=(e=mu())=>XT(e.convert("vec2|vec3")),E_=(e=mu(),t=3,s=2,r=.5,i=1)=>QT(e,Si(t),s,r).mul(i),w_=(e=mu(),t=3,s=2,r=.5,i=1)=>JT(e,Si(t),s,r).mul(i),M_=(e=mu(),t=3,s=2,r=.5,i=1)=>ZT(e,Si(t),s,r).mul(i),B_=(e=mu(),t=3,s=2,r=.5,i=1)=>e_(e,Si(t),s,r).mul(i),U_=fi((([e,t,s])=>{const r=Ao(e).toVar("nDir"),i=On(vi(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),n=On(vi(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Bi().toVar("rbminmax");o.x=r.x.greaterThan(vi(0)).select(i.x,n.x),o.y=r.y.greaterThan(vi(0)).select(i.y,n.y),o.z=r.z.greaterThan(vi(0)).select(i.z,n.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),F_=fi((([e,t])=>{const s=e.x,r=e.y,i=e.z;let n=t.element(0).mul(.886227);return n=n.add(t.element(1).mul(1.023328).mul(r)),n=n.add(t.element(2).mul(1.023328).mul(i)),n=n.add(t.element(3).mul(1.023328).mul(s)),n=n.add(t.element(4).mul(.858086).mul(s).mul(r)),n=n.add(t.element(5).mul(.858086).mul(r).mul(i)),n=n.add(t.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),n=n.add(t.element(7).mul(.858086).mul(s).mul(i)),n=n.add(t.element(8).mul(.429043).mul(Gn(s,s).sub(Gn(r,r)))),n})),P_=new hm;class I_ extends Dg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,i=this.nodes.getBackgroundNode(e)||e.background;let n=!1;if(null===i)r._clearColor.getRGB(P_,Se),P_.a=r._clearColor.a;else if(!0===i.isColor)i.getRGB(P_,Se),P_.a=1,n=!0;else if(!0===i.isNode){const s=this.get(e),n=i;P_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ii(n).mul(Lf),{getUV:()=>Df.mul(ll),getTextureLevel:()=>If});let t=Wd();t=t.setZ(t.w);const r=new ih;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ii(n).mul(Lf),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",i);if(!0===r.autoClear||!0===n){const e=s.clearColorValue;e.r=P_.r,e.g=P_.g,e.b=P_.b,e.a=P_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let L_=0;class D_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=L_++}}class V_{constructor(e,t,s,r,i,n,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=i,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new D_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class O_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class G_{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class k_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class z_ extends k_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class $_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let H_=0;class W_{constructor(e=null){this.id=H_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class j_{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class q_ extends j_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class K_ extends j_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class X_ extends j_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Y_ extends j_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class Q_ extends j_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends j_{constructor(e,t=new i){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class J_ extends j_{constructor(e,t=new n){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class eN extends q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class tN extends K_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const aN=[.125,.215,.35,.446,.526,.582],uN=20,lN=new xe(-1,1,1,-1,0,1),dN=new Be(90,1),cN=new e;let hN=null,pN=0,gN=0;const mN=(1+Math.sqrt(5))/2,fN=1/mN,yN=[new s(-mN,fN,0),new s(mN,fN,0),new s(-fN,0,mN),new s(fN,0,mN),new s(0,mN,-fN),new s(0,mN,fN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],bN=[3,1,5,0,4,2],xN=Hp(mu(),gu("faceIndex")).normalize(),TN=Bi(xN.x,xN.y.negate(),xN.z);class _N{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(e,t=0,s=.1,r=100){hN=this._renderer.getRenderTarget(),pN=this._renderer.getActiveCubeFace(),gN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const i=this._allocateTargets();return i.depthBuffer=!0,this._sceneToCubeUV(e,s,r,i),t>0&&this._blur(i,0,0,t),this._applyPMREM(i),this._cleanup(i),i}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=AN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=RN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=aN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],i=bN[e];b.set(r,m*g*i),x.set(h,f*g*i);const n=[i,i,i,i,i,i];T.set(n,y*g*i)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),i.push(new k(_,null)),n>4&&n--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:i}}(i)),this._blurMaterial=function(e,t,r){const i=Rl(new Array(uN).fill(0)),n=en(new s(0,1,0)),o=en(0),a=vi(uN),u=en(0),l=en(1),d=_u(null),c=en(0),h=vi(1/t),p=vi(1/r),g=vi(e),m={n:a,latitudinal:u,weights:i,poleAxis:n,outputDirection:TN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=SN("blur");return f.uniforms=m,f.fragmentNode=Kp({...m,latitudinal:u.equal(1)}),f}(i,e,t)}return i}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,lN)}_sceneToCubeUV(e,t,s,r){const i=dN;i.near=t,i.far=s;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(cN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(cN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,i);for(let t=0;t<6;t++){const s=t%3;0===s?(i.up.set(0,n[t],0),i.lookAt(o[t],0,0)):1===s?(i.up.set(0,0,n[t]),i.lookAt(0,o[t],0)):(i.up.set(0,n[t],0),i.lookAt(0,0,o[t]));const u=this._cubeSize;vN(r,s*u,t>2?u:0,u,u),a.render(e,i)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=AN(e)):null===this._equirectMaterial&&(this._equirectMaterial=RN(e));const i=r?this._cubemapMaterial:this._equirectMaterial;i.fragmentNode.value=e;const n=this._lodMeshes[0];n.material=i;const o=this._cubeSize;vN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(n,lN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;tuN&&console.warn(`sigmaRadians, ${i}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,lN)}}function NN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function vN(e,t,s,r,i){e.viewport.set(t,s,r,i),e.scissor.set(t,s,r,i)}function SN(e){const t=new ih;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function AN(e){const t=SN("cubemap");return t.fragmentNode=_l(e,TN),t}function RN(e){const t=SN("equirect");return t.fragmentNode=_u(e,bh(TN),0),t}const CN=new WeakMap,EN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),wN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),MN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class BN{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=fm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new W_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=CN.get(this.renderer);return void 0===e&&(e=new Ug,CN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new xh(e,t)}createPMREMGenerator(){return new _N(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let i,n=!0;for(const e of t)r.push(e),n=n&&!0!==e.groupNode.shared;return n?(i=s.get(r),void 0===i&&(i=new D_(e,r,this.bindingsIndexes[e].group,r),s.set(r,i))):i=new D_(e,r,this.bindingsIndexes[e].group,r),i}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const i=s[e][r];(t[r]||(t[r]=[])).push(...i)}e=[];for(const s in t){const r=t[s],i=this._getBindGroup(s,r);e.push(i)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(n)}u`:"0u";if("bool"===i)return n?"true":"false";if("color"===i)return`${this.getType("vec3")}( ${MN(n.r)}, ${MN(n.g)}, ${MN(n.b)} )`;const o=this.getTypeLength(i),a=this.getComponentType(i),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)} )`;if(3===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)} )`;if(4===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)}, ${u(n.w)} )`;if(o>4&&n&&(n.isMatrix3||n.isMatrix4))return`${this.getType(i)}( ${n.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(i)}()`;throw new Error(`NodeBuilder: Type '${i}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new O_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=EN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return wN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,i=e.normalized;let n;return e instanceof Ie||!0===i||(n=this.getTypeFromArray(s)),this.getTypeFromLength(r,n)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=fm(this.stack),this.stacks.push(xi()||this.stack),bi(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,bi(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(void 0===r){const i=this.uniforms.index++;r=new O_("nodeAttribute"+i,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const i=this.getDataFromNode(e,s,this.globalCache);let n=i.uniform;if(void 0===n){const o=this.uniforms.index++;n=new G_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(n),i.uniform=n}return n}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const i=this.getDataFromNode(e,r);let n=i.variable;if(void 0===n){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),n=new k_(t,s),e.push(n),i.variable=n}return n}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let i=r.varying;if(void 0===i){const e=this.varyings,n=e.length;null===t&&(t="nodeVarying"+n),i=new z_(t,s),e.push(i),r.varying=i}return i}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let i=r.code;if(void 0===i){const e=this.codes[s]||(this.codes[s]=[]),n=e.length;i=new $_("nodeCode"+n,t),e.push(i),r.code=i}return i}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let i=!0,n=t;for(;n;){if(!0===r.get(n)){i=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(i)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),i=r.flowCodes||(r.flowCodes=[]),n=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);i.push(t),n.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new ax,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new pm(e.type,e.name);e.layout=null;const r=e.call(s),i=this.flowStagesNode(r,t.type);return e.layout=t,i}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,i=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new W_,this.stack=fm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=i,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const i=this.shaderStage;this.setShaderStage(e);const n=this.flowChildNode(t,s);return null!==r&&(n.code+=`${this.tab+r} = ${n.result};\n`),this.flowCode[e]=this.flowCode[e]+n.code,this.setShaderStage(i),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new ih),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new eN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new tN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new sN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new rN(e);if("color"===t)return new iN(e);if("mat3"===t)return new nN(e);if("mat4"===t)return new oN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),i=this.getTypeLength(s);return 16===r&&9===i?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===i?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||i>4||0===i?e:r===i?`${this.getType(s)}( ${e} )`:r>i?this.format(`${e}.${"xyz".slice(0,i)}`,this.getTypeFromLength(i,this.getComponentType(t)),s):4===i&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&i>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class UN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class FN{constructor(e,t,s=null,r="",i=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=i}}FN.isNodeFunctionInput=!0;class PN extends xT{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=rT(this.light),i=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:i},e.stack,e)}}const IN=new n,LN=new n;let DN=null;class VN extends xT{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=en(new s).setGroup(Qi),this.halfWidth=en(new s).setGroup(Qi),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;LN.identity(),IN.copy(t.matrixWorld),IN.premultiply(s),LN.extractRotation(IN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(LN),this.halfHeight.value.applyMatrix4(LN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(DN.LTC_FLOAT_1),s=_u(DN.LTC_FLOAT_2)):(t=_u(DN.LTC_HALF_1),s=_u(DN.LTC_HALF_2));const{colorNode:r,light:i}=this,n=e.context.lightingModel,o=sT(i),a=e.context.reflectedLight;n.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){DN=e}}class ON extends xT{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=en(0).setGroup(Qi),this.penumbraCosNode=en(0).setGroup(Qi),this.cutoffDistanceNode=en(0).setGroup(Qi),this.decayExponentNode=en(0).setGroup(Qi)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:i,light:n}=this,o=sT(n).sub(el),a=o.normalize(),u=a.dot(rT(n)),l=this.getSpotAttenuation(u),d=o.length(),c=TT({lightDistance:d,cutoffDistance:r,decayExponent:i}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class GN extends ON{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,Ci(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class kN extends xT{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class zN extends xT{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=eT(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=en(new e).setGroup(Qi)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:r}=this,i=ul.dot(r).mul(.5).add(.5),n=la(s,t,i);e.context.irradiance.addAssign(n)}}class $N extends xT{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=F_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class HN{parseFunction(){console.warn("Abstract function.")}}class WN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}WN.isNodeFunction=!0;const jN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,qN=/[a-z_0-9]+/gi,KN="#pragma main";class XN extends WN{constructor(e){const{type:t,inputs:s,name:r,precision:i,inputsCode:n,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(KN),s=-1!==t?e.slice(t+12):e,r=s.match(jN);if(null!==r&&5===r.length){const i=r[4],n=[];let o=null;for(;null!==(o=qN.exec(i));)n.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Jp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=Sh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Qi),r=Ml("density","float",s).setGroup(Qi);e=vx(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Qi),r=Ml("near","float",s).setGroup(Qi),i=Ml("far","float",s).setGroup(Qi);e=_x(t,r,i)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,i=null){const n=this.nodeFrame;return n.renderer=e,n.scene=t,n.object=s,n.camera=r,n.material=i,n}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return QN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return QN.set(e,s),r}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new UN,this.nodeBuilderCache=new Map}}const JN=new me;class ev{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new i,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let i=0;i{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),i=this._renderContexts.get(e,t,this._renderTarget),n=e.overrideMaterial||s.material,o=this._objects.get(s,n,e,t,r.lightsNode,i,i.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ZN(this,s),this._animation=new Bg(this._nodes,this.info),this._attributes=new $g(s),this._background=new I_(this,this._nodes),this._geometries=new jg(this._attributes,this.info),this._textures=new cm(this,s,this.info),this._pipelines=new Jg(s,this._nodes),this._bindings=new em(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Lg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new nm(this.lighting),this._bundles=new sv,this._renderContexts=new lm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,i=r.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:ov;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new ev),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=i,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:i,renderList:n}=e,o=this._currentRenderContext,a=this._bundles.get(r,i),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=n.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,i,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(uv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(uv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new ev),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),dv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),lv.setFromProjectionMatrix(dv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),i.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,r){const i=this._scissor;e.isVector4?i.copy(e):i.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,i=0,n=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=i,o.maxDepth=n}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let i=null;if(null!==r&&(this._textures.updateRenderTarget(r),i=this._textures.get(r)),this.backend.clear(e,t,s,i),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const r=this.backend,i=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===i.has(t)){const e=()=>{t.removeEventListener("dispose",e),i.delete(t),n.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),n.updateForCompute(t);const s=n.getForCompute(t),a=i.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=cv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=cv.copy(t).floor()}else t=cv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,i=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,i)}readRenderTargetPixelsAsync(e,t,s,r,i,n=0,o=0){return this.backend.copyTextureToBuffer(e.textures[n],t,s,r,i,o)}_projectObject(e,t,s,r,i){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(i=i.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||lv.intersectsSprite(e)){!0===this.sortObjects&&cv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(dv);const{geometry:t,material:n}=e;n.visible&&r.push(e,t,n,s,cv.z,null,i)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||lv.intersectsObject(e))){const{geometry:t,material:n}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),cv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(dv)),Array.isArray(n)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,i,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,i);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,i)}_renderObjects(e,t,s,r,i=null){for(let n=0,o=e.length;n0?r:"";t=`${e.name} {\n\t${s} ${i.name}[${n}];\n};\n`}else{t=`${this.getVectorType(i.type)} ${this.getPropertyName(i,e)};`,n=!0}const o=i.node.precision;if(null!==o&&(t=Cv[o]+" "+t),n){t="\t"+t;const e=i.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let i="";for(const t in r){const s=r[t];i+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return i+=s.join("\n"),i}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Ev[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Ev[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${r.code}\n\t`,e===i&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const n=e[t];n.extensions=this.getExtensions(t),n.uniforms=this.getUniforms(t),n.attributes=this.getAttributes(t),n.varyings=this.getVaryings(t),n.vars=this.getVars(t),n.structs=this.getStructs(t),n.codes=this.getCodes(t),n.transforms=this.getTransforms(t),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const i=super.getUniformFromNode(e,t,s,r),n=this.getDataFromNode(e,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new vv(i.name,i.node,r),u.push(o);else if("cubeTexture"===t)o=new Sv(i.name,i.node,r),u.push(o);else if("texture3D"===t)o=new Av(i.name,i.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,i.name=`buffer${e.id}`;const t=new yv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=e[a];void 0===n&&(n=new Tv(s+"_"+a,r),e[a]=n,u.push(n)),o=this.getNodeUniform(i,t),n.addUniform(o)}n.uniformGPU=o}return i}}let Bv=null,Uv=null,Fv=null;class Pv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Bv=Bv||new t,this.renderer.getDrawingBufferSize(Bv)}getScissor(){return Uv=Uv||new r,this.renderer.getScissor(Uv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Fv=Fv||new hm,e.getClearColor(Fv),Fv.getRGB(Fv,this.renderer.currentColorSpace),Fv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Iv=0;class Lv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Dv{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,i=e.array,n=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,i,n),a.bufferGPU=l,a.bufferType=t,a.version=o.version),i instanceof Float32Array)u=r.FLOAT;else if(i instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(i instanceof Int16Array)u=r.SHORT;else if(i instanceof Uint32Array)u=r.UNSIGNED_INT;else if(i instanceof Int32Array)u=r.INT;else if(i instanceof Int8Array)u=r.BYTE;else if(i instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(i instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+i);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:i.byteLength,bytesPerElement:i.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Iv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,i,n);d=new Lv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,i=e.isInterleavedBufferAttribute?e.data:e,n=t.get(i),o=n.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t{!function i(){const n=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(n===e.WAIT_FAILED)return e.deleteSync(t),void r();n!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(i)}()}))}}let $v,Hv,Wv,jv=!1;class qv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===jv&&(this._init(this.gl),jv=!0)}_init(e){$v={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},Hv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},Wv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,i=!1){const{gl:n,extensions:o}=this;if(null!==e){if(void 0!==n[e])return n[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===n.RED&&(s===n.FLOAT&&(a=n.R32F),s===n.HALF_FLOAT&&(a=n.R16F),s===n.UNSIGNED_BYTE&&(a=n.R8),s===n.UNSIGNED_SHORT&&(a=n.R16),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),t===n.RED_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.R8UI),s===n.UNSIGNED_SHORT&&(a=n.R16UI),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),t===n.RG&&(s===n.FLOAT&&(a=n.RG32F),s===n.HALF_FLOAT&&(a=n.RG16F),s===n.UNSIGNED_BYTE&&(a=n.RG8),s===n.UNSIGNED_SHORT&&(a=n.RG16),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),t===n.RG_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RG8UI),s===n.UNSIGNED_SHORT&&(a=n.RG16UI),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),t===n.RGB&&(s===n.FLOAT&&(a=n.RGB32F),s===n.HALF_FLOAT&&(a=n.RGB16F),s===n.UNSIGNED_BYTE&&(a=n.RGB8),s===n.UNSIGNED_SHORT&&(a=n.RGB16),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I),s===n.UNSIGNED_BYTE&&(a=r===De&&!1===i?n.SRGB8:n.RGB8),s===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),s===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),t===n.RGB_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGB8UI),s===n.UNSIGNED_SHORT&&(a=n.RGB16UI),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I)),t===n.RGBA&&(s===n.FLOAT&&(a=n.RGBA32F),s===n.HALF_FLOAT&&(a=n.RGBA16F),s===n.UNSIGNED_BYTE&&(a=n.RGBA8),s===n.UNSIGNED_SHORT&&(a=n.RGBA16),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I),s===n.UNSIGNED_BYTE&&(a=r===De&&!1===i?n.SRGB8_ALPHA8:n.RGBA8),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),t===n.RGBA_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),s===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I)),t===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),t===n.DEPTH_STENCIL&&s===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:i}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,$v[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,$v[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,$v[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,Hv[t.magFilter]);const n=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&n?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,Hv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,Wv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const n=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,i.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,i=this.getGLTextureType(e);let n=r[i];void 0===n&&(n=t.createTexture(),s.state.bindTexture(i,n),t.texParameteri(i,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(i,t.TEXTURE_MAG_FILTER,t.NEAREST),r[i]=n),s.set(e,{textureGPU:n,glTextureType:i,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:i,width:n,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,i,d,n,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,i,d,n,o,a):e.isVideoTexture||s.texStorage2D(h,i,d,n,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:i,glTextureType:n,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(n,i),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(n,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:i}=t,{textureGPU:n,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===n)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,n),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,i=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;i.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),i.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),i.bindFramebuffer(r.READ_FRAMEBUFFER,s),i.bindTexture(r.TEXTURE_2D,n),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),i.unbindTexture()}else{const e=r.createFramebuffer();i.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,n,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else i.bindTexture(r.TEXTURE_2D,n),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),i.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:i,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;i>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,i,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(i>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,i,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,i,n){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+n:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*i*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,i,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let r=0;return e===s.UNSIGNED_BYTE&&(r=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Kv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Xv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const Yv={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class Qv{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:r,object:i,type:n,info:o,index:a}=this;0!==a?s.drawElements(r,t,n,e):s.drawArrays(r,e,t),o.update(i,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:i,type:n,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(i,t,n,e,s):r.drawArraysInstanced(i,e,t,s),u.update(a,t,i,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:i,object:n,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),i=r.previousContext,n=e.occlusionQueryCount;n>0&&(n>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const i=r.framebuffers[e.getCacheKey()],n=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,i);for(let s=0;s{let o=0;for(let t=0;t0&&e.add(r[t]),s[t]=null,i.deleteQuery(n),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,i,n){return this.textureUtils.copyTextureToBuffer(e,t,s,r,i,n)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Mv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,i="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(i,r),t.compileShader(i),this.set(e,{shaderGPU:i})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:i,vertexProgram:n}=r,o=s.createProgram(),a=this.get(i).shaderGPU,u=this.get(n).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const i=new Promise((t=>{const i=this.parallel,n=()=>{s.getProgramParameter(o,i.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(n)};n()}));t.push(i)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],i=Math.max(t-6,0),n=Math.min(t+6,s.length);for(let e=i;e":" "} ${i}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),i=e.getShaderInfoLog(t).trim();if(r&&""===i)return"";const n=/ERROR: 0:(\d+)/.exec(i);if(n){const r=parseInt(n[1]);return s.toUpperCase()+"\n\n"+i+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return i}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,i=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const n=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+i+"\n"+n+"\n"+o)}else""!==i&&console.warn("THREE.WebGLProgram: Program Info Log:",i)}}_completeCompile(e,t){const{state:s,gl:r}=this,i=this.get(t),{programGPU:n,fragmentShader:o,vertexShader:a}=i;!1===r.getProgramParameter(n,r.LINK_STATUS)&&this._logProgramError(n,o,a),s.useProgram(n);const u=e.getBindings();this._setupBindings(u,n),this.set(t,{programGPU:n})}createComputePipeline(e,t){const{state:s,gl:r}=this,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:n}=e,o=r.createProgram(),a=this.get(i).shaderGPU,u=this.get(n).shaderGPU,l=n.transforms,d=[],c=[];for(let e=0;eYv[t]===e)),s=this.extensions;for(let e=0;e0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const i=[],l=e.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Hf,stripIndexFormat:ay},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Hf,stripIndexFormat:ay},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:i,height:n}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:i,height:n,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),i=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:ty,storeOp:Jf,clearValue:[0,0,0,0]}]});n.setPipeline(e),n.setBindGroup(0,i),n.draw(4,1,0,0),n.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const i=r.layers[s]||this._mipmapCreateBundles(e,t,s),n=this.device.createCommandEncoder({});this._mipmapRunBundles(n,i),this.device.queue.submit([n.finish()]),0!==r.useCount&&(r.layers[s]=i),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),i=r.getBindGroupLayout(0);let n=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:s});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,dS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,cS={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class hS extends WN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:i,blockCode:n,outputType:o}=(e=>{const t=(e=e.trim()).match(lS);if(null!==t&&4===t.length){const s=t[2],r=[];let i=null;for(;null!==(i=dS.exec(s));)r.push({name:i[1],type:i[2]});const n=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class pS extends HN{parseFunction(e){return new hS(e)}}const gS=self.GPUShaderStage,mS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},fS={vertex:gS?gS.VERTEX:1,fragment:gS?gS.FRAGMENT:2,compute:gS?gS.COMPUTE:4},yS={instance:!0,swizzleAssign:!1,storageBuffer:!0},bS={"^^":"tsl_xor"},xS={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},TS={},_S={tsl_xor:new sx("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new sx("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new sx("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new sx("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new sx("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new sx("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new sx("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new sx("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new sx("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new sx("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new sx("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new sx("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new sx("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new sx("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},NS={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(_S.pow_float=new sx("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),_S.pow_vec2=new sx("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[_S.pow_float]),_S.pow_vec3=new sx("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[_S.pow_float]),_S.pow_vec4=new sx("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[_S.pow_float]),NS.pow_float="tsl_pow_float",NS.pow_vec2="tsl_pow_vec2",NS.pow_vec3="tsl_pow_vec3",NS.pow_vec4="tsl_pow_vec4");let vS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(vS+="diagnostic( off, derivative_uniformity );\n");class SS extends BN{constructor(e,t){super(e,t,new pS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,i=this.shaderStage){return"fragment"===i?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,r,i,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${mS[e.wrapS]}S_${mS[e.wrapT]}T`;let s=TS[t];if(void 0===s){const r=[];let i=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const n=(e,t)=>{e===ls?(r.push(_S.repeatWrapping_float),i+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(r.push(_S.clampWrapping_float),i+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(r.push(_S.mirrorWrapping_float),i+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(i+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};n(e.wrapS,"x"),i+=",\n",n(e.wrapT,"y"),i+="\n\t);\n\n}\n",TS[t]=s=new sx(i,r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let i=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(i=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${i} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=i),i}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,i="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${i} )`:`textureLoad( ${t}, ${s}, ${i} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,i=this.shaderStage){let n=null;return n=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,i):this._generateTextureSample(e,t,s,r,i),n}generateTextureGrad(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(e,t,s,r,i,n=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this._generateTextureSampleLevel(e,t,s,r,i,n),o}generateTextureBias(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=bS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case Wy:return"read";case Hy:return"write";default:return"read_write"}else switch(e.access){case zy:return"read_write";case $y:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const i=super.getUniformFromNode(e,t,s,r),n=this.getDataFromNode(e,s,this.globalCache);if(void 0===n.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let n=null;if("texture"===t||"storageTexture"===t?n=new vv(i.name,i.node,o,e.access?e.access:null):"cubeTexture"===t?n=new Sv(i.name,i.node,o,e.access?e.access:null):"texture3D"===t&&(n=new Av(i.name,i.node,o,e.access?e.access:null)),n.store=!0===e.isStorageTextureNode,n.setVisibility(fS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===n.store){const e=new eS(`${i.name}_sampler`,i.node,o);e.setVisibility(fS[s]),u.push(e,n),r=[e,n]}else u.push(n),r=[n]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const i=new("buffer"===t?yv:rS)(e,o);i.setVisibility(fS[s]),u.push(i),r=i}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=e[a];void 0===n&&(n=new Tv(a,o),n.setVisibility(fS[s]),e[a]=n,u.push(n)),r=this.getNodeUniform(i,t),n.addUniform(r)}n.uniformGPU=r}return i}getBuiltin(e,t,s,r=this.shaderStage){const i=this.builtins[r]||(this.builtins[r]=new Map);return!1===i.has(e)&&i.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let i=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(i+=`\treturn ${s.result};\n`),i+="\n}\n",i}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:i}of s.values())t.push(`@builtin( ${e} ) ${r} : ${i}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:i}of this.scopedArrays.values()){const n=this.getType(r);t.push(`var<${s}> ${e}: array< ${n}, ${i} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e output : ${i};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let i=0;i";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array";else if(!0===t.isDepthTexture)r=`texture_depth${n}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d";else if(!0===i.node.isStorageTextureNode){r=`texture_storage_2d<${uS(t)}, ${this.getStorageAccess(i.node)}>`}else{r=`texture${n}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${i.name} : ${r};`)}else if("buffer"===i.type||"storageBuffer"===i.type||"indirectStorageBuffer"===i.type){const e=i.node,t=this.getType(e.bufferType),s=e.bufferCount,n=s>0&&"buffer"===i.type?", "+s:"",a=e.isAtomic?`atomic<${t}>`:`${t}`,u=`\t${i.name} : array< ${a}${n} >\n`,l=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding("NodeBuffer_"+e.id,u,l,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(i.type)),t=i.groupNode.name;(n[t]||(n[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${i.name} : ${e}`)}}for(const e in n){const t=n[e];i.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=i.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t);let r="// code\n\n";r+=this.flowCode[t];const i=this.flowNodes[t],n=i[i.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const e of i){const i=this.getFlowData(e),u=e.name;if(u&&(r.length>0&&(r+="\n"),r+=`\t// flow -> ${u}\n\t`),r+=`${i.code}\n\t`,e===n&&"compute"!==t)if(r+="// result\n\n\t","vertex"===t)r+=`varyings.Vertex = ${i.result};`;else if("fragment"===t)if(a)s.returnType=o.nodeType,r+=`return ${i.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar output : OutputStruct;\n\n",r+=`output.color = ${i.result};\n\n\treturn output;`}}s.flow=r}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return xS[e]||e}isAvailable(e){let t=yS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),yS[e]=t),t}_getWGSLMethod(e){return void 0!==_S[e]&&this._include(e),NS[e]}_include(e){const t=_S[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${vS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r=0,i=0){const n=e+"Struct";return`${this._getWGSLStruct(n,t)}\n@binding( ${r} ) @group( ${i} )\nvar<${s}> ${e} : ${n};`}}class AS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=uy.Depth24PlusStencil8:e.depth&&(t=uy.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?Gf:e.isLineSegments||e.isMesh&&!0===t.wireframe?kf:e.isLine?zf:e.isMesh?$f:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?uy.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const RS=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),CS=new Map([[Ie,["float16"]]]),ES=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class wS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,i=r.get(s);let n=i.buffer;if(void 0===n){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[s]===r&&(a=o.groups[s])),void 0===a&&(a=this.createBindGroup(e,u),s>0&&(o.groups[s]=a,o.versions[s]=r)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,i=t.get(e).buffer;s.queue.writeBuffer(i,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let i=0;const n=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,n=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:i});e.buffer=n}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);n.push({binding:i,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const i=rb;let n;n=t.isSampledCubeTexture?tb:t.isSampledTexture3D?sb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?eb:Jy,o=e[r]=e.texture.createView({aspect:i,dimension:n,mipLevelCount:s})}}n.push({binding:i,resource:o})}i++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:n})}}class BS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:i,pipeline:n}=e,{vertexProgram:o,fragmentProgram:a}=n,u=this.backend,l=u.device,d=u.utils,c=u.get(n),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,i=s.getCurrentDepthStencilFormat(e),n={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:i,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(n)}createComputePipeline(e,t){const s=this.backend,r=s.device,i=s.get(e.computeProgram).module,n=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}n.pipeline=r.createComputePipeline({compute:i,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,i=e.blendSrc,n=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:i,a=null!==e.blendDstAlpha?e.blendDstAlpha:n,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const i=(e,r,i,n)=>{t={srcFactor:e,dstFactor:r,operation:Cy},s={srcFactor:i,dstFactor:n,operation:Cy}};if(e.premultipliedAlpha)switch(r){case F:i(my,xy,my,xy);break;case bt:i(my,my,my,my);break;case yt:i(gy,yy,gy,my);break;case ft:i(gy,fy,gy,by)}else switch(r){case F:i(by,xy,my,xy);break;case bt:i(by,my,by,my);break;case yt:i(gy,yy,gy,my);break;case ft:i(gy,fy,gy,fy)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=gy;break;case st:t=my;break;case rt:t=fy;break;case ut:t=yy;break;case it:t=by;break;case lt:t=xy;break;case ot:t=Ty;break;case dt:t=_y;break;case at:t=Ny;break;case ct:t=vy;break;case nt:t=Sy;break;case 211:t=Ay;break;case 212:t=Ry;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=Wf;break;case Es:t=Zf;break;case Cs:t=jf;break;case Rs:t=Kf;break;case As:t=qf;break;case Ss:t=Qf;break;case vs:t=Xf;break;case Ns:t=Yf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Py;break;case Ls:t=Iy;break;case Is:t=Ly;break;case Ps:t=Dy;break;case Fs:t=Vy;break;case Us:t=Oy;break;case Bs:t=Gy;break;case Ms:t=ky;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Cy;break;case Je:t=Ey;break;case et:t=wy;break;case Os:t=My;break;case Vs:t=By;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},i=this.backend.utils;switch(r.topology=i.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?oy:ay),s.side){case Oe:r.frontFace=sy,r.cullMode=ny;break;case x:r.frontFace=sy,r.cullMode=iy;break;case le:r.frontFace=sy,r.cullMode=ry;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Fy:Uy}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Zf;else{const s=e.depthFunc;switch(s){case Rt:t=Wf;break;case At:t=Zf;break;case St:t=jf;break;case vt:t=Kf;break;case Nt:t=qf;break;case _t:t=Qf;break;case Tt:t=Xf;break;case xt:t=Yf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class US extends Pv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new AS(this),this.attributeUtils=new wS(this),this.bindingUtils=new MS(this),this.pipelineUtils=new BS(this),this.textureUtils=new aS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const i=Object.values(ob),n=[];for(const e of i)r.features.has(e)&&n.push(e);const o={requiredFeatures:n,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const i=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ob.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:i}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const i=e.getCacheKey();let n=r[i];if(void 0===n){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,i=s.createQuerySet({type:"occlusion",count:r,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=i,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),n=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,n),n.occlusionQuerySet=i;const o=n.depthStencilAttachment;if(null!==e.textures){const t=n.colorAttachments;for(let s=0;s0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const r=8*s;let i=this.occludedResolveCache.get(r);void 0===i&&(i=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,i));const n=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,i,0),t.encoder.copyBufferToBuffer(i,0,n,0,r),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,i.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:r,pipeline:i}=e,n=e.getBindings(),o=this.get(r),a=this.get(i).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=n.length;e1?0:s;l.drawIndexed(t[s],r,e[s]/n,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:i,firstVertex:n}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,i,n,0,0);t.update(s,r,i)}else{const{vertexCount:r,instanceCount:i,firstVertex:n}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,i,n,0);t.update(s,r,i)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,i=this.utils,n=i.getSampleCountRenderContext(e.context),o=i.getCurrentColorSpace(e.context),a=i.getCurrentColorFormat(e.context),u=i.getCurrentDepthStencilFormat(e.context),l=i.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===n&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=n,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,i=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,r.getSampleCountRenderContext(i),r.getCurrentColorSpace(i),r.getCurrentColorFormat(i),r.getCurrentDepthStencilFormat(i),r.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,i,n){return this.textureUtils.copyTextureToBuffer(e,t,s,r,i,n)}async initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){this.device.pushErrorScope("out-of-memory");const r=await this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_renderContext_${e.id}`});if(await this.device.popErrorScope())return s.attemptingTimeStampQuerySetFailed||(console.error(`[GPUOutOfMemoryError][renderContext_${e.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.`),s.attemptingTimeStampQuerySetFailed=!0),void(s.timeStampQuerySet=null);const i={querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:i}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;const r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:i,resultBuffer:n,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,i,0),t.copyBufferToBuffer(i,0,n,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:i}=s.currentTimestampQueryBuffers;!0!==i&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),i=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,i),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new SS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,r=null,i=0){let n=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(n=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:i,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:i,origin:{x:n,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let i=null;i=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const n=this.get(e).texture;if(i.format!==n.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",i.format,n.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:i,origin:{x:s.x,y:s.y,z:0}},{texture:n},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new Zv(e)));super(new t(e),e),this.library=new PS,this.isWebGPURenderer=!0}}class LS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const DS=new ih,VS=new Tf(DS);class OS{constructor(e,t=Ii(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,DS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,VS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;VS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),VS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await VS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function GS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function kS(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function zS(e,t,s={}){return(s=GS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var $S=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=zS(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=GS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){kS(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:kS,saveRendererAndSceneState:zS,saveRendererState:GS});class HS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class WS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class jS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class qS extends WS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class KS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const i=new tr(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),vi()):ci(new this.nodes[e])}}class XS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const i=r[e];t[e]=s[i]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class YS extends rr{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new KS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),i=new XS;i.setTextures(t),i.setNodes(r),i.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(t.matrixWorld))return n.worldMatrix.copy(t.matrixWorld),!1;const i=n.material;for(const e in i){const t=i[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return i[e]=r,!1}if(i.transmission>0){const{width:t,height:s}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==s)return n.bufferWidth=t,n.bufferHeight=s,!1}const o=n.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return n.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let s=0;s>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:n}of cr(e))s.push(s,or(r.slice(0,-4)),n.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;ee.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of cr(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let r=null;const n=e.getBuildStage();if("setup"===n){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===n)this.analyze(e);else if("generate"===n){if(1===this.generate.length){const s=this.getNodeType(e),n=e.getDataFromNode(this);r=n.snippet,void 0===r?(r=this.generate(e)||"",n.snippet=r):void 0!==n.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:n,childNode:i}of t)void 0!==n?(void 0===s[r]&&(s[r]=Number.isInteger(n)?[]:{}),s[r][n]=i.toJSON(e.meta).uuid):s[r]=i.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const n of e.inputNodes[s])r.push(t[n]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const n in e.inputNodes[s]){const i=e.inputNodes[s][n];r[n]=t[i]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let n=e.nodes[t];function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===n&&(n={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[n.uuid]=n),this.serialize(n),delete n.meta),r){const t=i(e.textures),s=i(e.images),r=i(e.nodes);t.length>0&&(n.textures=t),s.length>0&&(n.images=s),r.length>0&&(n.nodes=r)}return n}}class Rr extends Ar{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,r=this.getNodeType(e),n=s.build(e,r);return e.format(n,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const n=super.build(e,s),i=e.getVarFromNode(this,null,s),o=e.getPropertyName(i);return e.addLineFlowCode(`${o} = ${n}`,this),r.snippet=n,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,s)=>t+e.getTypeLength(s.getNodeType(e))),0))}generate(e,t){const s=this.getNodeType(e),r=this.nodes,n=e.getComponentType(s),i=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==n&&(s=e.format(s,r,n)),i.push(s)}const o=`${e.getType(s)}( ${i.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(vr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,r=e.getTypeLength(s.getNodeType(e));let n=null;if(r>1){let i=null;this.getVectorLength()>=r&&(i=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,i);n=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,i,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else n=s.build(e,t);return n}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:r}=this,n=this.getNodeType(e),i=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,i),a=t.build(e,n),u=e.getTypeLength(n),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(pn(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),hn(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>hn(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>hn(new Fr(hn(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),hn(new Br(e,t));if(!0===/^\d+$/.test(t))return hn(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=hn(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;rhn(null!==r?Object.assign(e,r):e);return null===t?(...t)=>n(new e(...gn(t))):null!==s?(s=hn(s),(...r)=>n(new e(t,...gn(r),s))):(...s)=>n(new e(t,...gn(s)))},qr=function(e,...t){return hn(new e(...gn(t)))};class Kr extends Ar{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let n=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let i=r.get(t);void 0===i&&(i=hn(e.buildFunctionNode(t)),r.set(t,i)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(i),n=hn(i.call(s))}else{const r=t.jsFunc,i=null!==s?r(s,e):r(e);n=hn(i)}return t.once&&(r.onceOutput=n),n}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return pn(e),hn(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],en=new Map;for(const e of Yr)en.set(e,new Ir(e));const tn=new Map;for(const e of Qr)tn.set(e,new Ir(e,"uint"));const sn=new Map([...tn].map((e=>new Ir(e.value,"int"))));for(const e of Zr)sn.set(e,new Ir(e,"int"));const rn=new Map([...sn].map((e=>new Ir(e.value))));for(const e of Jr)rn.set(e,new Ir(e));for(const e of Jr)rn.set(-e,new Ir(-e));const nn={bool:en,uint:tn,ints:sn,float:rn},on=new Map([...en,...rn]),an=(e,t)=>on.has(e)?on.get(e):!0===e.isNode?e:new Ir(e,t),un=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return hn(t.get(s[0]));if(1===s.length){const t=an(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?hn(t):hn(new Cr(t,e))}const r=s.map((e=>an(e)));return hn(new wr(r,e))}},ln=e=>"object"==typeof e&&null!==e?e.value:e,dn=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function cn(e,t){return new Proxy(new Xr(e,t),kr)}const hn=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?hn(an(e,t)):"shader"===s?yn(e):e}(e,t),pn=(e,t=null)=>new Hr(e,t),gn=(e,t=null)=>new Wr(e,t),mn=(...e)=>new jr(...e),fn=(...e)=>new qr(...e),yn=(e,t)=>{const s=new cn(e,t),r=(...e)=>{let t;return pn(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},bn=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),yn(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const xn=e=>{Lr=e},Tn=()=>Lr,_n=(...e)=>Lr.If(...e);function Nn(e){return Lr&&Lr.add(e),e}Vr("append",Nn);const vn=new un("color"),Sn=new un("float",nn.float),An=new un("int",nn.ints),Rn=new un("uint",nn.uint),Cn=new un("bool",nn.bool),En=new un("vec2"),wn=new un("ivec2"),Mn=new un("uvec2"),Bn=new un("bvec2"),Un=new un("vec3"),Fn=new un("ivec3"),Pn=new un("uvec3"),In=new un("bvec3"),Ln=new un("vec4"),Dn=new un("ivec4"),Vn=new un("uvec4"),On=new un("bvec4"),Gn=new un("mat2"),kn=new un("mat3"),zn=new un("mat4"),$n=(e="")=>hn(new Ir(e,"string")),Hn=e=>hn(new Ir(e,"ArrayBuffer"));Vr("toColor",vn),Vr("toFloat",Sn),Vr("toInt",An),Vr("toUint",Rn),Vr("toBool",Cn),Vr("toVec2",En),Vr("toIVec2",wn),Vr("toUVec2",Mn),Vr("toBVec2",Bn),Vr("toVec3",Un),Vr("toIVec3",Fn),Vr("toUVec3",Pn),Vr("toBVec3",In),Vr("toVec4",Ln),Vr("toIVec4",Dn),Vr("toUVec4",Vn),Vr("toBVec4",On),Vr("toMat2",Gn),Vr("toMat3",kn),Vr("toMat4",zn);const Wn=mn(Rr),jn=(e,t)=>hn(new Cr(hn(e),t)),qn=(e,t)=>hn(new Br(hn(e),t));Vr("element",Wn),Vr("convert",jn);class Kn extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Xn=e=>new Kn(e),Yn=(e,t=0)=>new Kn(e,!0,t),Qn=Yn("frame"),Zn=Yn("render"),Jn=Xn("object");class ei extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Jn}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let n=e.getNodeFromHash(r);void 0===n&&(e.setHashNode(this,r),n=this);const i=n.getInputType(e),o=e.getUniformFromNode(n,i,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const ti=(e,t)=>{const s=dn(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return hn(new ei(r,s))};class si extends Ar{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const ri=(e,t)=>hn(new si(e,t)),ni=(e,t)=>hn(new si(e,t,!0)),ii=fn(si,"vec4","DiffuseColor"),oi=fn(si,"vec3","EmissiveColor"),ai=fn(si,"float","Roughness"),ui=fn(si,"float","Metalness"),li=fn(si,"float","Clearcoat"),di=fn(si,"float","ClearcoatRoughness"),ci=fn(si,"vec3","Sheen"),hi=fn(si,"float","SheenRoughness"),pi=fn(si,"float","Iridescence"),gi=fn(si,"float","IridescenceIOR"),mi=fn(si,"float","IridescenceThickness"),fi=fn(si,"float","AlphaT"),yi=fn(si,"float","Anisotropy"),bi=fn(si,"vec3","AnisotropyT"),xi=fn(si,"vec3","AnisotropyB"),Ti=fn(si,"color","SpecularColor"),_i=fn(si,"float","SpecularF90"),Ni=fn(si,"float","Shininess"),vi=fn(si,"vec4","Output"),Si=fn(si,"float","dashSize"),Ai=fn(si,"float","gapSize"),Ri=fn(si,"float","pointWidth"),Ci=fn(si,"float","IOR"),Ei=fn(si,"float","Transmission"),wi=fn(si,"float","Thickness"),Mi=fn(si,"float","AttenuationDistance"),Bi=fn(si,"color","AttenuationColor"),Ui=fn(si,"float","Dispersion");class Fi extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,n=this.needsSplitAssign(e),i=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,i),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(n){const r=e.getVarFromNode(this,null,i),n=e.getPropertyName(r);e.addLineFlowCode(`${n} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t{const r=s.type;let n;return n="pointer"===r?"&"+t.build(e):t.build(e,r),n};if(Array.isArray(n))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?gn(t):pn(t[0]),hn(new Ii(hn(e),t)));Vr("call",Li);class Di extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let n=new Di(e,t,s);for(let t=0;t>"===s||"<<"===s)return e.getIntegerType(i);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(i),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===i&&e.isMatrix(o)?o:e.isMatrix(i)&&e.isVector(o)?e.getVectorFromMatrix(i):e.isVector(i)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(i)?o:i}generate(e,t){const s=this.op,r=this.aNode,n=this.bNode,i=this.getNodeType(e,t);let o=null,a=null;"void"!==i?(o=r.getNodeType(e),a=void 0!==n?n.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=i,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=i):o=a=i;const u=r.build(e,o),l=void 0!==n?n.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} < ${l} )`,i,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} <= ${l} )`,i,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} > ${l} )`,i,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} >= ${l} )`,i,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`( ${u} ${s} ${l} )`,i,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`${u} ${s} ${l}`,i,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vi=mn(Di,"+"),Oi=mn(Di,"-"),Gi=mn(Di,"*"),ki=mn(Di,"/"),zi=mn(Di,"%"),$i=mn(Di,"=="),Hi=mn(Di,"!="),Wi=mn(Di,"<"),ji=mn(Di,">"),qi=mn(Di,"<="),Ki=mn(Di,">="),Xi=mn(Di,"&&"),Yi=mn(Di,"||"),Qi=mn(Di,"!"),Zi=mn(Di,"^^"),Ji=mn(Di,"&"),eo=mn(Di,"~"),to=mn(Di,"|"),so=mn(Di,"^"),ro=mn(Di,"<<"),no=mn(Di,">>");Vr("add",Vi),Vr("sub",Oi),Vr("mul",Gi),Vr("div",ki),Vr("modInt",zi),Vr("equal",$i),Vr("notEqual",Hi),Vr("lessThan",Wi),Vr("greaterThan",ji),Vr("lessThanEqual",qi),Vr("greaterThanEqual",Ki),Vr("and",Xi),Vr("or",Yi),Vr("not",Qi),Vr("xor",Zi),Vr("bitAnd",Ji),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",no);const io=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zi(...e));Vr("remainder",io);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,n=e.isMatrix(t)?0:e.getTypeLength(t),i=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return n>i&&n>o?t:i>o?s:o>n?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),n=this.getInputType(e),i=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=i,r=o;e.isMatrix(s.getNodeType(e))?r=Ln(Un(r),0):s=Ln(Un(s),0);const n=Gi(s,r).xyz;return Ao(n).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+i.build(e,n)+" )",r,t);if(s===oo.ONE_MINUS)return Oi(1,i).build(e,t);if(s===oo.RECIPROCAL)return ki(1,i).build(e,t);if(s===oo.DIFFERENCE)return Fo(Oi(i,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(i.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(i.build(e,1===e.getTypeLength(i.getNodeType(e))?"float":n),o.build(e,n)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(i.build(e,n),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":n)):s===oo.REFRACT?l.push(i.build(e,n),o.build(e,n),a.build(e,"float")):s===oo.MIX?l.push(i.build(e,n),o.build(e,n),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":n)):(l.push(i.build(e,n)),null!==o&&l.push(o.build(e,n)),null!==a&&l.push(a.build(e,n))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=Sn(1e-6),uo=Sn(1e6),lo=Sn(Math.PI),co=Sn(2*Math.PI),ho=mn(oo,oo.ALL),po=mn(oo,oo.ANY),go=mn(oo,oo.EQUALS),mo=mn(oo,oo.RADIANS),fo=mn(oo,oo.DEGREES),yo=mn(oo,oo.EXP),bo=mn(oo,oo.EXP2),xo=mn(oo,oo.LOG),To=mn(oo,oo.LOG2),_o=mn(oo,oo.SQRT),No=mn(oo,oo.INVERSE_SQRT),vo=mn(oo,oo.FLOOR),So=mn(oo,oo.CEIL),Ao=mn(oo,oo.NORMALIZE),Ro=mn(oo,oo.FRACT),Co=mn(oo,oo.SIN),Eo=mn(oo,oo.COS),wo=mn(oo,oo.TAN),Mo=mn(oo,oo.ASIN),Bo=mn(oo,oo.ACOS),Uo=mn(oo,oo.ATAN),Fo=mn(oo,oo.ABS),Po=mn(oo,oo.SIGN),Io=mn(oo,oo.LENGTH),Lo=mn(oo,oo.NEGATE),Do=mn(oo,oo.ONE_MINUS),Vo=mn(oo,oo.DFDX),Oo=mn(oo,oo.DFDY),Go=mn(oo,oo.ROUND),ko=mn(oo,oo.RECIPROCAL),zo=mn(oo,oo.TRUNC),$o=mn(oo,oo.FWIDTH),Ho=mn(oo,oo.BITCAST),Wo=mn(oo,oo.TRANSPOSE),jo=mn(oo,oo.ATAN2),qo=mn(oo,oo.MIN),Ko=mn(oo,oo.MAX),Xo=mn(oo,oo.MOD),Yo=mn(oo,oo.STEP),Qo=mn(oo,oo.REFLECT),Zo=mn(oo,oo.DISTANCE),Jo=mn(oo,oo.DIFFERENCE),ea=mn(oo,oo.DOT),ta=mn(oo,oo.CROSS),sa=mn(oo,oo.POW),ra=mn(oo,oo.POW,2),na=mn(oo,oo.POW,3),ia=mn(oo,oo.POW,4),oa=mn(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gi(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=mn(oo,oo.MIX),da=(e,t=0,s=1)=>hn(new oo(oo.CLAMP,hn(e),hn(t),hn(s))),ca=e=>da(e),ha=mn(oo,oo.REFRACT),pa=mn(oo,oo.SMOOTHSTEP),ga=mn(oo,oo.FACEFORWARD),ma=yn((([e])=>{const t=ea(e.xy,En(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",na),Vr("pow4",ia),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,n=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=n,null!==r&&(e.getDataFromNode(r).parentNodeBlock=n);const i=e.getNodeProperties(this);i.condNode=t,i.ifNode=s.context({nodeBlock:s}),i.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:n,ifNode:i,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?ri(s).build(e):"";r.nodeProperty=u;const l=n.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=i.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=mn(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e,t);return e.setContext(s),r}}const Na=mn(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),n=e.getPropertyName(r),i=t.build(e,r.type);return e.addLineFlowCode(`${n} = ${i}`,this),n}}const Aa=mn(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const r=this.name,n=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,n),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const r=this.getNodeType(e),n=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,n),t.propertyName=n}return e.getPropertyName(s)}}const Ea=mn(Ca);Vr("varying",Ea);const wa=yn((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=yn((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let i=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(i=Ln(wa(i.rgb),i.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(i=Ln(kn(u._getMatrix(new n,s,r)).mul(i.rgb),i.a)),u.getTransfer(r)===l&&(i=Ln(Ma(i.rgb),i.a)),i):i}}const Pa=e=>hn(new Fa(hn(e),Ba,Ua)),Ia=e=>hn(new Fa(hn(e),Ua,Ba)),La=(e,t)=>hn(new Fa(hn(e),Ba,t)),Da=(e,t)=>hn(new Fa(hn(e),t,Ba)),Va=(e,t,s)=>hn(new Fa(hn(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return hn(new Oa(this,hn(e)))}setNodeType(e){const t=ti(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const n=e.renderer.library.getToneMappingFunction(s);return null!==n?r=Ln(n(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>hn(new $a(e,hn(t),hn(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),n=this.bufferStride||r,i=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,n),a=new g(o,r,i);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let n=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,n=r;else{n=Ea(this).build(e,t)}return n}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>hn(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;ehn(new Qa(hn(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const n=this.node.build(e,...t);return e.setCache(s),n}}const eu=(e,...t)=>hn(new Ja(hn(e),...t));Vr("cache",eu);class tu extends Ar{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const su=mn(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=Sn(0),n=Sn(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=n,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:n,doClamp:i}=this;let o=e.sub(t).div(s.sub(t));return!0===i&&(o=o.clamp()),o.mul(n.sub(r)).add(r)}}const nu=mn(ru,null,null,{doClamp:!1}),iu=mn(ru);Vr("remap",nu),Vr("remapClamp",iu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=mn(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>hn(new du(hn(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),n=e.getTypeFromAttribute(r),i=e.getAttribute(t,n);if("vertex"===e.shaderStage)return e.format(i.name,n,s);return Ea(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const gu=(e,t)=>hn(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=mn(fu);class bu extends ei{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=mn(bu);class Tu extends ei{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=ti(this.value.matrix)),this._matrixUniform.mul(Un(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&!0===s.flipY||!0===s.isRenderTargetTexture||!0===s.isFramebufferTexture||!0===s.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(An(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,n,i,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,i):n?e.generateTextureBias(u,t,s,n,i):a?e.generateTextureGrad(u,t,s,a,i):o?e.generateTextureCompare(u,t,s,o,i):!1===this.sampler?e.generateTextureLoad(u,t,s,i):e.generateTexture(u,t,s,i),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const n=super.generate(e,"property");if("sampler"===t)return n+"_sampler";if(e.isReference(t))return n;{const i=e.getDataFromNode(this);let o=i.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,n,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),i.snippet=b,i.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}blur(e){const t=this.clone();return t.biasNode=hn(e).mul(xu(t)),t.referenceNode=this.getSelf(),hn(t)}level(e){const t=this.clone();return t.levelNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}compare(e){const t=this.clone();return t.compareNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}grad(e,t){const s=this.clone();return s.gradNode=[hn(e),hn(t)],s.referenceNode=this.getSelf(),hn(s)}depth(e){const t=this.clone();return t.depthNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=mn(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=ti("float").label("cameraNear").setGroup(Zn).onRenderUpdate((({camera:e})=>e.near)),Au=ti("float").label("cameraFar").setGroup(Zn).onRenderUpdate((({camera:e})=>e.far)),Ru=ti("mat4").label("cameraProjectionMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=ti("mat4").label("cameraProjectionMatrixInverse").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=ti("mat4").label("cameraViewMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=ti("mat4").label("cameraWorldMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=ti("mat3").label("cameraNormalMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=ti(new s).label("cameraPosition").setGroup(Zn).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new ei(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,n=this.scope;if(n===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(n===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(n===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(n===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(n===Uu.VIEW_POSITION){const n=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(n.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=mn(Uu,Uu.DIRECTION),Pu=mn(Uu,Uu.WORLD_MATRIX),Iu=mn(Uu,Uu.POSITION),Lu=mn(Uu,Uu.SCALE),Du=mn(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=fn(Vu,Vu.DIRECTION),Gu=fn(Vu,Vu.WORLD_MATRIX),ku=fn(Vu,Vu.POSITION),zu=fn(Vu,Vu.SCALE),$u=fn(Vu,Vu.VIEW_POSITION),Hu=ti(new n).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=ti(new i).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=yn((e=>(e.context.isHighPrecisionModelViewMatrix=!0,ti("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=yn((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return ti("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=fn(sl),nl=Sn(rl).mul(2).sub(1),il=gu("normal","vec3"),ol=yn((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Un(0,1,0)):il),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=yn((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=yn((e=>e.context.setupNormal()),"vec3").once()().mul(nl).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=yn((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(nl).toVar("transformedClearcoatNormalView"),pl=yn((([e,t=Gu])=>{const s=kn(t),r=e.div(Un(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=yn((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=ti(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Un(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Un(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=mn(Tl);class Nl extends ei{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const vl=(e,t,s)=>hn(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;shn(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),hn(new Al(e,t)));class El extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return hn(new El(this,hn(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):ti(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new wl(e,t,s)),Bl=(e,t,s,r)=>hn(new wl(e,t,r,s));class Ul extends wl{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>hn(new Ul(e,t,s)),Pl=yn((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ln(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(il.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=kn(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xi.cross(tl);return e=e.cross(xi).normalize(),e=la(e,dl,yi.mul(ai.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=yn((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:n}=e,i=t.dFdx(),o=t.dFdy(),a=n.dFdx(),u=n.dFdy(),l=s,d=o.cross(l),c=l.cross(i),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=nl.mul(g.inverseSqrt());return Vi(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Un(r.xy.mul(s),r.z));let n=null;if(t===S)n=gl(r);else if(t===v){n=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return n}}const Jl=mn(Zl),ed=yn((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=Sn(s((e=>e)));return En(Sn(s((e=>e.add(e.dFdx())))).sub(r),Sn(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=yn((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,n=t.dFdx().normalize(),i=s,o=t.dFdy().normalize().cross(i),a=i.cross(n),u=n.dot(o).mul(nl),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=mn(sd),nd=new Map;class id extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=nd.get(e);return void 0===s&&(s=Fl(e,t),nd.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===id.COLOR){const e=void 0!==t.color?this.getColor(s):Un();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===id.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===id.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:Sn(1);else if(s===id.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===id.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===id.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===id.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===id.EMISSIVE){const e=this.getFloat("emissiveIntensity"),n=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?n.mul(this.getTexture(s)):n}else if(s===id.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===id.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===id.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===id.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===id.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Gn($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(En(1)).normalize().mul(e.b))}else r=$d;else if(s===id.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const n=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(n).mul(this.getTexture(s).g).add(n)}else r=e}else if(s===id.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===id.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===id.IOR)r=this.getFloat(s);else if(s===id.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===id.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}id.ALPHA_TEST="alphaTest",id.COLOR="color",id.OPACITY="opacity",id.SHININESS="shininess",id.SPECULAR="specular",id.SPECULAR_STRENGTH="specularStrength",id.SPECULAR_INTENSITY="specularIntensity",id.SPECULAR_COLOR="specularColor",id.REFLECTIVITY="reflectivity",id.ROUGHNESS="roughness",id.METALNESS="metalness",id.NORMAL="normal",id.CLEARCOAT="clearcoat",id.CLEARCOAT_ROUGHNESS="clearcoatRoughness",id.CLEARCOAT_NORMAL="clearcoatNormal",id.EMISSIVE="emissive",id.ROTATION="rotation",id.SHEEN="sheen",id.SHEEN_ROUGHNESS="sheenRoughness",id.ANISOTROPY="anisotropy",id.IRIDESCENCE="iridescence",id.IRIDESCENCE_IOR="iridescenceIOR",id.IRIDESCENCE_THICKNESS="iridescenceThickness",id.IOR="ior",id.TRANSMISSION="transmission",id.THICKNESS="thickness",id.ATTENUATION_DISTANCE="attenuationDistance",id.ATTENUATION_COLOR="attenuationColor",id.LINE_SCALE="scale",id.LINE_DASH_SIZE="dashSize",id.LINE_GAP_SIZE="gapSize",id.LINE_WIDTH="linewidth",id.LINE_DASH_OFFSET="dashOffset",id.POINT_WIDTH="pointWidth",id.DISPERSION="dispersion",id.LIGHT_MAP="light",id.AO_MAP="ao";const od=fn(id,id.ALPHA_TEST),ad=fn(id,id.COLOR),ud=fn(id,id.SHININESS),ld=fn(id,id.EMISSIVE),dd=fn(id,id.OPACITY),cd=fn(id,id.SPECULAR),hd=fn(id,id.SPECULAR_INTENSITY),pd=fn(id,id.SPECULAR_COLOR),gd=fn(id,id.SPECULAR_STRENGTH),md=fn(id,id.REFLECTIVITY),fd=fn(id,id.ROUGHNESS),yd=fn(id,id.METALNESS),bd=fn(id,id.NORMAL).context({getUV:null}),xd=fn(id,id.CLEARCOAT),Td=fn(id,id.CLEARCOAT_ROUGHNESS),_d=fn(id,id.CLEARCOAT_NORMAL).context({getUV:null}),Nd=fn(id,id.ROTATION),vd=fn(id,id.SHEEN),Sd=fn(id,id.SHEEN_ROUGHNESS),Ad=fn(id,id.ANISOTROPY),Rd=fn(id,id.IRIDESCENCE),Cd=fn(id,id.IRIDESCENCE_IOR),Ed=fn(id,id.IRIDESCENCE_THICKNESS),wd=fn(id,id.TRANSMISSION),Md=fn(id,id.THICKNESS),Bd=fn(id,id.IOR),Ud=fn(id,id.ATTENUATION_DISTANCE),Fd=fn(id,id.ATTENUATION_COLOR),Pd=fn(id,id.LINE_SCALE),Id=fn(id,id.LINE_DASH_SIZE),Ld=fn(id,id.LINE_GAP_SIZE),Dd=fn(id,id.LINE_WIDTH),Vd=fn(id,id.LINE_DASH_OFFSET),Od=fn(id,id.POINT_WIDTH),Gd=fn(id,id.DISPERSION),kd=fn(id,id.LIGHT_MAP),zd=fn(id,id.AO_MAP),$d=ti(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=mn(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,n;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)n=r;else{n=Ea(this).build(e,t)}return n}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=fn(jd,jd.VERTEX),Kd=fn(jd,jd.INSTANCE),Xd=fn(jd,jd.SUBGROUP),Yd=fn(jd,jd.INVOCATION_SUBGROUP),Qd=fn(jd,jd.INVOCATION_LOCAL),Zd=fn(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,n=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=zn(...n)}this.instanceMatrixNode=t}const n=r.instanceColor;if(n&&null===s){const e=new R(n.array,3),t=n.usage===p?Ya:Xa;this.bufferColor=e,s=Un(t(e,"vec3",3,0)),this.instanceColorNode=s}const i=t.mul(Yu).xyz;if(Yu.assign(i),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&ni("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=mn(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=yn((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=An(e).modInt(An(t)),r=An(e).div(An(t));return Nu(this.batchMesh._indirectTexture,wn(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(An(this.batchingIdNode)),r=this.batchMesh._matricesTexture,n=yu(Nu(r),0),i=Sn(s).mul(4).toInt().toVar(),o=i.modInt(n),a=i.div(An(n)),u=zn(Nu(r,wn(o,a)),Nu(r,wn(o.add(1),a)),Nu(r,wn(o.add(2),a)),Nu(r,wn(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=yn((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),n=s.div(t);return Nu(l,wn(r,n)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);ni("vec3","vBatchColor").assign(t)}const d=kn(u);Yu.assign(u.mul(Yu));const c=ol.div(Un(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=mn(tc),rc=new WeakMap;class nc extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,n;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),n=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=ti(e.bindMatrix,"mat4"),r=ti(e.bindMatrixInverse,"mat4"),n=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=n,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=n.mul(t),c=Vi(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return i.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vi(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=i.mul(d).mul(n),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const ic=e=>hn(new nc(e)),oc=e=>hn(new nc(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;eNumber(i)?">=":"<"));const d={start:n,end:i,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const n=r.build(e,"void"),i=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+n);for(let t=0,s=this.params.length-1;thn(new ac(gn(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=yn((({bufferMap:e,influence:t,stride:s,width:r,depth:n,offset:i})=>{const o=An(qd).mul(s).add(i),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,wn(u,a)).depth(n).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=ti(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,n=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,i=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==i?i.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,n=void 0!==e.morphAttributes.color,i=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==i?i.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===n&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=Sn(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,wn(An(e).add(1),An(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(0)})),!0===n&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=mn(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Un().toVar("directDiffuse"),directSpecular:Un().toVar("directSpecular"),indirectDiffuse:Un().toVar("indirectDiffuse"),indirectSpecular:Un().toVar("indirectSpecular")};return{radiance:Un().toVar("radiance"),irradiance:Un().toVar("irradiance"),iblIrradiance:Un().toVar("iblIrradiance"),ambientOcclusion:Sn(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Tc=mn(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?ti(Nc||(Nc=new t)):e===Sc.VIEWPORT?ti(vc||(vc=new r)):En(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=fn(Sc,Sc.UV),Rc=fn(Sc,Sc.SIZE),Cc=fn(Sc,Sc.COORDINATE),Ec=fn(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=yn((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=yn((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=yn((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=mn(Lc),Vc=mn(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=mn(Gc);class zc extends Ar{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Xc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.negate().div(t)),n=To(s.div(t));return r.div(n)},Kc=(e,t,s)=>{const r=e.mul(xo(s.div(t)));return Sn(Math.E).pow(r).mul(t).negate()},Xc=mn(zc,zc.DEPTH_BASE),Yc=fn(zc,zc.DEPTH),Qc=mn(zc,zc.LINEAR_DEPTH),Zc=Qc(kc());Yc.assign=e=>Xc(e);const Jc=mn(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class eh extends Ar{static get type(){return"ClippingNode"}constructor(e=eh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===eh.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===eh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return yn((()=>{const s=Sn().toVar("distanceToPlane"),r=Sn().toVar("distanceToGradient"),n=Sn(1).toVar("clipOpacity"),i=t.length;if(!this.hardwareClipping&&i>0){const e=Rl(t);uc(i,(({i:t})=>{const i=e.element(t);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),i=Sn(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const n=t.element(e);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s).oneMinus())})),n.mulAssign(i.oneMinus())}ii.a.mulAssign(n),ii.a.equal(0).discard()}))()}setupDefault(e,t){return yn((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Cn(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),yn((()=>{const r=Rl(e),n=Jc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();n.element(e).assign(s)}))}))()}}eh.ALPHA_TO_COVERAGE="alphaToCoverage",eh.DEFAULT="default",eh.HARDWARE="hardware";const th=yn((([e])=>Ro(Gi(1e4,Co(Gi(17,e.x).add(Gi(.1,e.y)))).mul(Vi(.1,Fo(Co(Gi(13,e.y).add(e.x)))))))),sh=yn((([e])=>th(En(th(e.xy),e.z)))),rh=yn((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=Sn(1).div(Sn(.05).mul(t)).toVar("pixScale"),r=En(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),n=En(sh(vo(r.x.mul(e.xyz))),sh(vo(r.y.mul(e.xyz)))).toVar("alpha"),i=Ro(To(s)).toVar("lerpFactor"),o=Vi(Gi(i.oneMinus(),n.x),Gi(i,n.y)).toVar("x"),a=qo(i,i.oneMinus()).toVar("a"),u=Un(o.mul(o).div(Gi(2,a).mul(Oi(1,a))),o.sub(Gi(.5,a)).div(Oi(1,a)),Oi(1,Oi(1,o).mul(Oi(1,o)).div(Gi(2,a).mul(Oi(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class nh extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new ir(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const n=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const i=this.setupLighting(e);null!==n&&e.stack.add(n);const o=Ln(i,ii.a).max(0);if(r=this.setupOutput(e,o),vi.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ln(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=hn(new eh(eh.ALPHA_TO_COVERAGE)):e.stack.add(hn(new eh))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(hn(new eh(eh.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(el.z,Su,Au):$c(el.z,Su,Au))}null!==r&&Yc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ln(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ln(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=ni("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=ni("vec3","vBatchColor").mul(s)}ii.assign(s);const r=this.opacityNode?Sn(this.opacityNode):dd;if(ii.a.assign(ii.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?Sn(this.alphaTestNode):od;ii.a.lessThanEqual(e).discard()}!0===this.alphaHash&&ii.a.lessThan(rh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&ii.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Un(0):ii.rgb}setupNormal(){return this.normalNode?Un(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:n}=this,i=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(i&&i.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(i,t,s,r)}else null!==s&&(o=Un(null!==r?la(o,s,r):s));return(n&&!0===n.isNode||t.emissive&&!0===t.emissive.isColor)&&(oi.assign(Un(n||ld)),o=o.add(oi)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ln(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:n}of r)s.inputNodes[t]=n.toJSON(e).uuid;function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=n(e.textures),r=n(e.images),i=n(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),i.length>0&&(s.nodes=i)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const ih=new P;class oh extends nh{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(ih),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=yn((()=>{const e=gu("instancePosition").xyz,t=Ln(ju.mul(Ln(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),n=Xu.xy.toVar();return n.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),n.assign(n.div(Ec.z)),n.y.assign(n.y.mul(s)),n.assign(n.mul(r.w)),r.addAssign(Ln(n,0,0)),r}))(),this.fragmentNode=yn((()=>{const r=Sn(1).toVar(),n=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=Sn(n.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),n).oneMinus())}else n.greaterThan(1).discard();let i;if(this.pointColorNode)i=this.pointColorNode;else if(s){i=gu("instanceColor").mul(ad)}else i=ad;return r.mulAssign(dd),Ln(i,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ah=new I;class uh extends nh{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(ah),this.setValues(e)}}const lh=new L;class dh extends nh{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(lh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?Sn(this.offsetNodeNode):Vd,t=this.dashScaleNode?Sn(this.dashScaleNode):Pd,s=this.dashSizeNode?Sn(this.dashSizeNode):Id,r=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(s),Ai.assign(r);const n=Ea(gu("lineDistance").mul(t));(e?n.add(e):n).mod(Si.add(Ai)).greaterThan(Si).discard()}}const ch=new L;class hh extends nh{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ch),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,n=this.worldUnits,i=yn((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ln(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=yn((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ln(ju.mul(Ln(e,1))).toVar("start"),o=Ln(ju.mul(Ln(t,1))).toVar("end");if(r){const e=this.dashScaleNode?Sn(this.dashScaleNode):Pd,t=this.offsetNode?Sn(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let n=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));n=n.add(t),ni("float","lineDistance").assign(n)}n&&(ni("vec3","worldStart").assign(s.xyz),ni("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);_n(u,(()=>{_n(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(i({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(i({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ln().toVar();if(n){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),n=e.cross(t).normalize(),i=e.cross(n),a=ni("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ln(Xu.x.lessThan(0).select(n.mul(u),n.mul(u).negate()),0)),r||(a.addAssign(Ln(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ln(i.mul(u),0)),_n(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ln(i.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Un().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=En(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),_n(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ln(e,0,0)))}return g}))();const o=yn((({p1:e,p2:t,p3:s,p4:r})=>{const n=e.sub(s),i=r.sub(s),o=t.sub(e),a=n.dot(i),u=i.dot(o),l=n.dot(o),d=i.dot(i),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return En(h,p)}));this.fragmentNode=yn((()=>{const i=mu();if(r){const e=this.dashSizeNode?Sn(this.dashSizeNode):Id,t=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(e),Ai.assign(t);const s=ni("float","lineDistance");i.y.lessThan(-1).or(i.y.greaterThan(1)).discard(),s.mod(Si.add(Ai)).greaterThan(Si).discard()}const a=Sn(1).toVar("alpha");if(n){const s=ni("vec3","worldStart"),n=ni("vec3","worldEnd"),i=ni("vec4","worldPos").xyz.normalize().mul(1e5),u=n.sub(s),l=o({p1:s,p2:n,p3:Un(0,0,0),p4:i}),d=s.add(u.mul(l.x)),c=i.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1)),s=e.mul(e).add(t.mul(t)),r=Sn(s.fwidth()).toVar("dlen");_n(i.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else _n(i.y.abs().greaterThan(1),(()=>{const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ln(u,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ph=e=>hn(e).mul(.5).add(.5),gh=e=>hn(e).mul(2).sub(1),mh=new D;class fh extends nh{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(mh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?Sn(this.opacityNode):dd;ii.assign(Ln(ph(dl),e))}}class yh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return En(t,s)}}const bh=mn(yh);class xh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n=new O(5,5,5),i=bh(Ju),o=new nh;o.colorNode=_u(t,i,0),o.side=x,o.blending=G;const a=new k(n,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const Th=new WeakMap;class _h extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(Th.has(e)){const t=Th.get(e);vh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new xh(s.height);r.fromEquirectangularTexture(t,e),vh(r.texture,e.mapping),this._cubeTexture=r.texture,Th.set(e,r.texture),e.addEventListener("dispose",Nh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Nh(e){const t=e.target;t.removeEventListener("dispose",Nh);const s=Th.get(t);void 0!==s&&(Th.delete(t),s.dispose())}function vh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const Sh=mn(_h);class Ah extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Sh(this.envNode)}}class Rh extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=Sn(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ch{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Eh extends Ch{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,n=e.reflectedLight,i=s.context.irradianceLightMap;n.indirectDiffuse.assign(Ln(0)),i?n.indirectDiffuse.addAssign(i):n.indirectDiffuse.addAssign(Ln(1,1,1,0)),n.indirectDiffuse.mulAssign(r),n.indirectDiffuse.mulAssign(ii.rgb)}finish(e,t,s){const r=s.material,n=e.outgoingLight,i=s.context.environment;if(i)switch(r.combine){case Y:n.rgb.assign(la(n.rgb,n.rgb.mul(i.rgb),gd.mul(md)));break;case X:n.rgb.assign(la(n.rgb,i.rgb,gd.mul(md)));break;case K:n.rgb.addAssign(i.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const wh=new Q;class Mh extends nh{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Rh(kd)),t}setupOutgoingLight(){return ii.rgb}setupLightingModel(){return new Eh}}const Bh=yn((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Uh=yn((e=>e.diffuseColor.mul(1/Math.PI))),Fh=yn((({dotNH:e})=>Ni.mul(Sn(.5)).add(1).mul(Sn(1/Math.PI)).mul(e.pow(Ni)))),Ph=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),n=Bh({f0:Ti,f90:1,dotVH:r}),i=Sn(.25),o=Fh({dotNH:s});return n.mul(i).mul(o)}));class Ih extends Eh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Ph({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const Lh=new Z;class Dh extends nh{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih(!1)}}const Vh=new J;class Oh extends nh{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Vh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih}setupVariants(){const e=(this.shininessNode?Sn(this.shininessNode):ud).max(1e-4);Ni.assign(e);const t=this.specularNode||cd;Ti.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Gh=yn((e=>{if(!1===e.geometry.hasAttribute("normal"))return Sn(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),kh=yn((e=>{const{roughness:t}=e,s=Gh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),zh=yn((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),n=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),i=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return ki(.5,n.add(i).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),$h=yn((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:n,dotBL:i,dotNV:o,dotNL:a})=>{const u=a.mul(Un(e.mul(s),t.mul(r),o).length()),l=o.mul(Un(e.mul(n),t.mul(i),a).length());return ki(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hh=yn((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Wh=Sn(1/Math.PI),jh=yn((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:n})=>{const i=e.mul(t),o=Un(t.mul(r),e.mul(n),i.mul(s)),a=o.dot(o),u=i.div(a);return Wh.mul(i.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),qh=yn((e=>{const{lightDirection:t,f0:s,f90:r,roughness:n,f:i,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=n.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Bh({f0:s,f90:r,dotVH:g});if(ln(o)&&(y=pi.mix(y,i)),ln(a)){const e=bi.dot(t),s=bi.dot(tl),r=bi.dot(d),n=xi.dot(t),i=xi.dot(tl),o=xi.dot(d);m=$h({alphaT:fi,alphaB:l,dotTV:s,dotBV:i,dotTL:e,dotBL:n,dotNV:h,dotNL:c}),f=jh({alphaT:fi,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=zh({alpha:l,dotNL:c,dotNV:h}),f=Hh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),Kh=yn((({roughness:e,dotNV:t})=>{const s=Ln(-1,-.0275,-.572,.022),r=Ln(1,.0425,1.04,-.04),n=e.mul(s).add(r),i=n.x.mul(n.x).min(t.mul(-9.28).exp2()).mul(n.x).add(n.y);return En(-1.04,1.04).mul(i).add(n.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xh=yn((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:n}=e,i=Kh({dotNV:t,roughness:n});return s.mul(i.x).add(r.mul(i.y))})),Yh=yn((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),n=r.mul(r),i=r.mul(n,n).clamp(0,.9999);return e.sub(Un(t).mul(i)).div(i.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qh=yn((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=Sn(1).div(s),n=t.pow2().oneMinus().max(.0078125);return Sn(2).add(r).mul(n.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Zh=yn((({dotNV:e,dotNL:t})=>Sn(1).div(Sn(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Jh=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),n=dl.dot(t).clamp(),i=Qh({roughness:hi,dotNH:n}),o=Zh({dotNV:r,dotNL:s});return ci.mul(i).mul(o)})),ep=yn((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),n=En(s,r.oneMinus().sqrt());return n.assign(n.mul(.984375).add(.0078125)),n})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),tp=yn((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sp=yn((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),n=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),i=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=n.div(i),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),rp=yn((({N:e,V:t,P:s,mInv:r,p0:n,p1:i,p2:o,p3:a})=>{const u=i.sub(n).toVar(),l=a.sub(n).toVar(),d=u.cross(l),c=Un().toVar();return _n(d.dot(s.sub(n)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(kn(u,l,e).transpose()).toVar(),h=d.mul(n.sub(s)).normalize().toVar(),p=d.mul(i.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Un(0).toVar();f.addAssign(sp({v1:h,v2:p})),f.addAssign(sp({v1:p,v2:g})),f.addAssign(sp({v1:g,v2:m})),f.addAssign(sp({v1:m,v2:h})),c.assign(Un(tp({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),np=1/6,ip=e=>Gi(np,Gi(e,Gi(e,e.negate().add(3)).sub(3)).add(1)),op=e=>Gi(np,Gi(e,Gi(e,Gi(3,e).sub(6))).add(4)),ap=e=>Gi(np,Gi(e,Gi(e,Gi(-3,e).add(3)).add(3)).add(1)),up=e=>Gi(np,sa(e,3)),lp=e=>ip(e).add(op(e)),dp=e=>ap(e).add(up(e)),cp=e=>Vi(-1,op(e).div(ip(e).add(op(e)))),hp=e=>Vi(1,up(e).div(ap(e).add(up(e)))),pp=(e,t,s)=>{const r=e.uvNode,n=Gi(r,t.zw).add(.5),i=vo(n),o=Ro(n),a=lp(o.x),u=dp(o.x),l=cp(o.x),d=hp(o.x),c=cp(o.y),h=hp(o.y),p=En(i.x.add(l),i.y.add(c)).sub(.5).mul(t.xy),g=En(i.x.add(d),i.y.add(c)).sub(.5).mul(t.xy),m=En(i.x.add(l),i.y.add(h)).sub(.5).mul(t.xy),f=En(i.x.add(d),i.y.add(h)).sub(.5).mul(t.xy),y=lp(o.y).mul(Vi(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=dp(o.y).mul(Vi(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},gp=yn((([e,t=Sn(3)])=>{const s=En(e.size(An(t))),r=En(e.size(An(t.add(1)))),n=ki(1,s),i=ki(1,r),o=pp(e,Ln(n,s),vo(t)),a=pp(e,Ln(i,r),So(t));return Ro(t).mix(o,a)})),mp=yn((([e,t,s,r,n])=>{const i=Un(ha(t.negate(),Ao(e),ki(1,r))),o=Un(Io(n[0].xyz),Io(n[1].xyz),Io(n[2].xyz));return Ao(i).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),fp=yn((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),yp=Vc(),bp=Vc(),xp=yn((([e,t,s],{material:r})=>{const n=(r.side==x?yp:bp).uv(e),i=To(Rc.x).mul(fp(t,s));return gp(n,i)})),Tp=yn((([e,t,s])=>(_n(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Un(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),_p=yn((([e,t,s,r,n,i,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ln().toVar(),f=Un().toVar();const n=d.sub(1).mul(g.mul(.025)),i=Un(d.sub(n),d,d.add(n));uc({start:0,end:3},(({i:n})=>{const d=i.element(n),g=mp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ln(y,1))),x=En(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(En(x.x,x.y.oneMinus()));const T=xp(x,s,d);m.element(n).assign(T.element(n)),m.a.addAssign(T.a),f.element(n).assign(r.element(n).mul(Tp(Io(g),h,p).element(n)))})),m.a.divAssign(3)}else{const n=mp(e,t,c,d,a),i=o.add(n),g=l.mul(u.mul(Ln(i,1))),y=En(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(En(y.x,y.y.oneMinus())),m=xp(y,s,d),f=r.mul(Tp(Io(n),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Un(Xh({dotNV:b,specularColor:n,specularF90:i,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ln(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),Np=kn(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),vp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Sp=yn((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:n})=>{const i=la(e,t,pa(0,.03,r)),o=e.div(i).pow2().mul(s.pow2().oneMinus()).oneMinus();_n(o.lessThan(0),(()=>Un(1)));const a=o.sqrt(),u=vp(i,e),l=Bh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=i.lessThan(e).select(Math.PI,0),h=Sn(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Un(1).add(t).div(Un(1).sub(t))})(n.clamp(0,.9999)),g=vp(p,i.toVec3()),m=Bh({f0:g,f90:1,dotVH:a}),f=Un(p.x.lessThan(i).select(Math.PI,0),p.y.lessThan(i).select(Math.PI,0),p.z.lessThan(i).select(Math.PI,0)),y=i.mul(r,a,2),b=Un(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Un(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Un(54856e-17,44201e-17,52481e-17),n=Un(1681e3,1795300,2208400),i=Un(43278e5,93046e5,66121e5),o=Sn(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(i.mul(2*Math.PI).sqrt()).mul(n.mul(s).add(t).cos()).mul(s.pow2().negate().mul(i).exp());return a=Un(a.x.add(o),a.y,a.z).div(1.0685e-7),Np.mul(a)})(Sn(e).mul(y),Sn(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Un(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Ap=yn((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),n=s.pow2(),i=xa(s.lessThan(.25),Sn(-339.2).mul(n).add(Sn(161.4).mul(s)).sub(25.9),Sn(-8.48).mul(n).add(Sn(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),Sn(44).mul(n).sub(Sn(23.7).mul(s)).add(3.26),Sn(1.97).mul(n).sub(Sn(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,Sn(.1).mul(s).sub(.025)).add(i.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Rp=Un(.04),Cp=Sn(1);class Ep extends Ch{constructor(e=!1,t=!1,s=!1,r=!1,n=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=n,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Un().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Un().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Un().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Un().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Un().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=Sp({outsideIOR:Sn(1),eta2:gi,cosTheta1:e,thinFilmThickness:mi,baseF0:Ti}),this.iridescenceF0=Yh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=_p(r,s,ai,ii,Ti,_i,t,Gu,Eu,Ru,Ci,wi,Bi,Mi,this.dispersion?Ui:null),e.backdropAlpha=Ei,ii.a.mulAssign(la(1,e.backdrop.a,Ei))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),n=Kh({roughness:ai,dotNV:r}),i=(this.iridescenceF0?pi.mix(Ti,this.iridescenceF0):Ti).mul(n.x).add(s.mul(n.y)),o=n.x.add(n.y).oneMinus(),a=Ti.add(Ti.oneMinus().mul(.047619)),u=i.mul(a).div(o.mul(a).oneMinus());e.addAssign(i),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Jh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(qh({lightDirection:e,f0:Rp,f90:Cp,roughness:di,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),s.directSpecular.addAssign(r.mul(qh({lightDirection:e,f0:Ti,f90:1,roughness:ai,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:n,ltc_1:i,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=ep({N:c,V:h,roughness:ai}),m=i.uv(g).toVar(),f=o.uv(g).toVar(),y=kn(Un(m.x,0,m.y),Un(0,1,0),Un(m.z,0,m.w)).toVar(),b=Ti.mul(f.x).add(Ti.oneMinus().mul(f.y)).toVar();n.directSpecular.addAssign(e.mul(b).mul(rp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),n.directDiffuse.addAssign(e.mul(ii).mul(rp({N:c,V:h,P:p,mInv:kn(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Uh({diffuseColor:ii})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(ci,Ap({normal:dl,viewDir:tl,roughness:hi}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Xh({dotNV:e,specularColor:Rp,specularF90:Cp,roughness:di});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Un().toVar("singleScattering"),n=Un().toVar("multiScattering"),i=t.mul(1/Math.PI);this.computeMultiscattering(r,n,_i);const o=r.add(n),a=ii.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(n.mul(i)),s.indirectDiffuse.addAssign(a.mul(i))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=ai.mul(-16).oneMinus().negate().exp2(),n=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(n)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Bh({dotVH:e,f0:Rp,f90:Cp}),r=t.mul(li.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(li));t.assign(r)}if(!0===this.sheen){const e=ci.r.max(ci.g).max(ci.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const wp=Sn(1),Mp=Sn(-2),Bp=Sn(.8),Up=Sn(-1),Fp=Sn(.4),Pp=Sn(2),Ip=Sn(.305),Lp=Sn(3),Dp=Sn(.21),Vp=Sn(4),Op=Sn(4),Gp=Sn(16),kp=yn((([e])=>{const t=Un(Fo(e)).toVar(),s=Sn(-1).toVar();return _n(t.x.greaterThan(t.z),(()=>{_n(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{_n(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),zp=yn((([e,t])=>{const s=En().toVar();return _n(t.equal(0),(()=>{s.assign(En(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(En(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(En(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(En(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(En(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(En(e.x,e.y).div(Fo(e.z)))})),Gi(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$p=yn((([e])=>{const t=Sn(0).toVar();return _n(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).ElseIf(e.greaterThanEqual(Fp),(()=>{t.assign(Bp.sub(e).mul(Pp.sub(Up)).div(Bp.sub(Fp)).add(Up))})).ElseIf(e.greaterThanEqual(Ip),(()=>{t.assign(Fp.sub(e).mul(Lp.sub(Pp)).div(Fp.sub(Ip)).add(Pp))})).ElseIf(e.greaterThanEqual(Dp),(()=>{t.assign(Ip.sub(e).mul(Vp.sub(Lp)).div(Ip.sub(Dp)).add(Lp))})).Else((()=>{t.assign(Sn(-2).mul(To(Gi(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Hp=yn((([e,t])=>{const s=e.toVar();s.assign(Gi(2,s).sub(1));const r=Un(s,1).toVar();return _n(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Wp=yn((([e,t,s,r,n,i])=>{const o=Sn(s),a=Un(t),u=da($p(o),Mp,i),l=Ro(u),d=vo(u),c=Un(jp(e,a,d,r,n,i)).toVar();return _n(l.notEqual(0),(()=>{const t=Un(jp(e,a,d.add(1),r,n,i)).toVar();c.assign(la(c,t,l))})),c})),jp=yn((([e,t,s,r,n,i])=>{const o=Sn(s).toVar(),a=Un(t),u=Sn(kp(a)).toVar(),l=Sn(Ko(Op.sub(o),0)).toVar();o.assign(Ko(o,Op));const d=Sn(bo(o)).toVar(),c=En(zp(a,u).mul(d.sub(2)).add(1)).toVar();return _n(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gi(3,Gp))),c.y.addAssign(Gi(4,bo(i).sub(d))),c.x.mulAssign(r),c.y.mulAssign(n),e.uv(c).grad(En(),En())})),qp=yn((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:n,CUBEUV_TEXEL_WIDTH:i,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(n.cross(s).mul(Co(r))).add(n.mul(n.dot(s).mul(u.oneMinus())));return jp(e,l,t,i,o,a)})),Kp=yn((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:n,samples:i,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Un(xa(t,s,ta(s,r))).toVar();_n(ho(h.equals(Un(0))),(()=>{h.assign(Un(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Un().toVar();return p.addAssign(n.element(An(0)).mul(qp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:An(1),end:e},(({i:e})=>{_n(e.greaterThanEqual(i),(()=>{dc()}));const t=Sn(o.mul(Sn(e))).toVar();p.addAssign(n.element(e).mul(qp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(n.element(e).mul(qp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ln(p,1)}));let Xp=null;const Yp=new WeakMap;function Qp(e){let t=Yp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r0}(s))return null;t=Xp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Yp.set(e,t)}return t.texture}class Zp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=ti(0),this._height=ti(0),this._maxMip=ti(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Qp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Xp&&(Xp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Un(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Wp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Jp=mn(Zp),eg=new WeakMap;class tg extends yc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let r=eg.get(e);void 0===r&&(r=Jp(e),eg.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),n=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,i=s.context(sg(ai,n)).mul(r),o=s.context(rg(cl)).mul(Math.PI).mul(r),a=eu(i),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(sg(di,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const sg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},rg=e=>({getUV:()=>e,getTextureLevel:()=>Sn(1)}),ng=new te;class ig extends nh{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ng),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new tg(t):null}setupLightingModel(){return new Ep}setupSpecular(){const e=la(Un(.04),ii.rgb,ui);Ti.assign(e),_i.assign(1)}setupVariants(){const e=this.metalnessNode?Sn(this.metalnessNode):yd;ui.assign(e);let t=this.roughnessNode?Sn(this.roughnessNode):fd;t=kh({roughness:t}),ai.assign(t),this.setupSpecular(),ii.assign(Ln(ii.rgb.mul(e.oneMinus()),ii.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const og=new se;class ag extends ig{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(og),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?Sn(this.iorNode):Bd;Ci.assign(e),Ti.assign(la(qo(ra(Ci.sub(1).div(Ci.add(1))).mul(pd),Un(1)).mul(hd),ii.rgb,ui)),_i.assign(la(hd,1,ui))}setupLightingModel(){return new Ep(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?Sn(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?Sn(this.clearcoatRoughnessNode):Td;li.assign(e),di.assign(kh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Un(this.sheenNode):vd,t=this.sheenRoughnessNode?Sn(this.sheenRoughnessNode):Sd;ci.assign(e),hi.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?Sn(this.iridescenceNode):Rd,t=this.iridescenceIORNode?Sn(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?Sn(this.iridescenceThicknessNode):Ed;pi.assign(e),gi.assign(t),mi.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?En(this.anisotropyNode):Ad).toVar();yi.assign(e.length()),_n(yi.equal(0),(()=>{e.assign(En(1,0))})).Else((()=>{e.divAssign(En(yi)),yi.assign(yi.saturate())})),fi.assign(yi.pow2().mix(ai.pow2(),1)),bi.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xi.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?Sn(this.transmissionNode):wd,t=this.thicknessNode?Sn(this.thicknessNode):Md,s=this.attenuationDistanceNode?Sn(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Un(this.attenuationColorNode):Fd;if(Ei.assign(e),wi.assign(t),Mi.assign(s),Bi.assign(r),this.useDispersion){const e=this.dispersionNode?Sn(this.dispersionNode):Gd;Ui.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Un(this.clearcoatNormalNode):_d}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class ug extends Ep{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){if(!0===this.useSSS){const r=n.material,{thicknessColorNode:i,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=Sn(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Un(h.add(a).mul(i));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n)}}class lg extends ag{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=Sn(.1),this.thicknessAmbientNode=Sn(0),this.thicknessAttenuationNode=Sn(.1),this.thicknessPowerNode=Sn(2),this.thicknessScaleNode=Sn(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ug(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const dg=yn((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),n=En(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>n});return Un(e.r)}{const e=n.fwidth().mul(.5);return la(Un(.7),Un(1),pa(Sn(.7).sub(e.x),Sn(.7).add(e.x),n.x))}}));class cg extends Ch{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){const i=dg({normal:il,lightDirection:e,builder:n}).mul(t);s.directDiffuse.addAssign(i.mul(Uh({diffuseColor:ii.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const hg=new re;class pg extends nh{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(hg),this.setValues(e)}setupLightingModel(){return new cg}}class gg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Un(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return En(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const mg=fn(gg),fg=new ne;class yg extends nh{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(fg),this.setValues(e)}setupVariants(e){const t=mg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Un(la(.2,.8,t.y)),ii.rgb.mulAssign(s.rgb)}}const bg=new P;class xg extends nh{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(bg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Tg extends Er{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Gn(e,r,r.negate(),e).mul(s)}{const e=t,r=zn(Ln(1,0,0,0),Ln(0,Eo(e.x),Co(e.x).negate(),0),Ln(0,Co(e.x),Eo(e.x),0),Ln(0,0,0,1)),n=zn(Ln(Eo(e.y),0,Co(e.y),0),Ln(0,1,0,0),Ln(Co(e.y).negate(),0,Eo(e.y),0),Ln(0,0,0,1)),i=zn(Ln(Eo(e.z),Co(e.z).negate(),0,0),Ln(Co(e.z),Eo(e.z),0,0),Ln(0,0,1,0),Ln(0,0,0,1));return r.mul(n).mul(i).mul(Ln(s,1)).xyz}}}const _g=mn(Tg),Ng=new ie;class vg extends nh{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Ng),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:n,rotationNode:i,scaleNode:o}=this,a=Yu;let u=ju.mul(Un(n||0)),l=En(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=Sn(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>hn(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=Sn(i||Nd),h=_g(d,c);u=Ln(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Sg extends Ch{constructor(){super(),this.shadowNode=Sn(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){ii.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(ii.rgb)}}const Ag=new oe;class Rg extends nh{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ag),this.setValues(e)}setupLightingModel(){return new Sg}}const Cg=yn((({texture:e,uv:t})=>{const s=1e-4,r=Un().toVar();return _n(t.x.lessThan(s),(()=>{r.assign(Un(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Un(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Un(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Un(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Un(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Un(0,0,-1))})).Else((()=>{const s=.01,n=e.uv(t.add(Un(-.01,0,0))).r.sub(e.uv(t.add(Un(s,0,0))).r),i=e.uv(t.add(Un(0,-.01,0))).r.sub(e.uv(t.add(Un(0,s,0))).r),o=e.uv(t.add(Un(0,0,-.01))).r.sub(e.uv(t.add(Un(0,0,s))).r);r.assign(Un(n,i,o))})),r.normalize()}));class Eg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Un(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Cg({texture:this,uv:e})}}const wg=mn(Eg);class Mg extends nh{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=wg(this.map,null,0),s=yn((({orig:e,dir:t})=>{const s=Un(-.5),r=Un(.5),n=t.reciprocal(),i=s.sub(e).mul(n),o=r.sub(e).mul(n),a=qo(i,o),u=Ko(i,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return En(l,d)}));this.fragmentNode=yn((()=>{const e=Ea(Un(Wu.mul(Ln(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),n=En(s({orig:e,dir:r})).toVar();n.x.greaterThan(n.y).discard(),n.assign(En(Ko(n.x,0),n.y));const i=Un(e.add(n.x.mul(r))).toVar(),o=Un(r.abs().reciprocal()).toVar(),a=Sn(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ln(Fl("base","color"),0).toVar();return uc({type:"float",start:n.x,end:n.y,update:"+= delta"},(()=>{const e=ri("float","d").assign(t.uv(i.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:i,finalColor:u}).append():(u.a.assign(1),dc()),i.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ln(u)}))(),super.setup(e)}}class Bg{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ug{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const n of e){const e=n.node&&n.node.attribute?n.node.attribute:t.getAttribute(n.name);if(void 0===e)continue;s.push(e);const i=e.isInterleavedBufferAttribute?e.data:e;r.add(i)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:n}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(i.instanceCount=u,!0===e.isBatchedMesh)return i;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=n.start*l,c=(n.start+n.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(i.vertexCount=g,i.firstVertex=d,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let n;if(null!==r){const e=typeof r;"number"===e?n=0!==r?"1":"0":"object"===e?(n="{",r.isTexture&&(n+=r.mapping),n+="}"):n=String(r)}else n=String(r);s+=n+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Ig=[];class Lg{constructor(e,t,s,r,n,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=n,this.info=i,this.chainMaps={}}get(e,t,s,r,n,i,o,a){const u=this.getChainMap(a);Ig[0]=e,Ig[1]=t,Ig[2]=i,Ig[3]=n;let l=u.get(Ig);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,n,i,o,a),u.set(Ig,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,n,i,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ug)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,n,i,o,a,u,l,d){const c=this.getChainMap(d),h=new Pg(e,t,s,r,n,i,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Dg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Vg=1,Og=2,Gg=3,kg=4,zg=16;class $g extends Dg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Vg?this.backend.createAttribute(e):t===Og?this.backend.createIndexAttribute(e):t===Gg?this.backend.createStorageAttribute(e):t===kg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return n.version=Hg(e),n}class jg extends Dg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,n=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of n)this.attributes.delete(e);const i=this.wireframes.get(t);void 0!==i&&this.attributes.delete(i),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Gg):this.updateAttribute(e,Vg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Og);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,kg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Wg(t),e.set(t,s)):s.version!==Hg(t)&&(this.attributes.delete(s),s=Wg(t),e.set(t,s)),r=s}return r}}class qg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Kg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Xg extends Kg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Yg extends Kg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Qg=0;class Zg{constructor(e,t,s=null,r=null){this.id=Qg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Jg extends Dg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let o=this.programs.compute.get(i.computeShader);void 0===o&&(n&&0===n.computeProgram.usedTimes&&this._releaseProgram(n.computeProgram),o=new Zg(i.computeShader,"compute",i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(n&&0===n.usedTimes&&this._releasePipeline(n),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState();let o=this.programs.vertex.get(i.vertexShader);void 0===o&&(n&&0===n.vertexProgram.usedTimes&&this._releaseProgram(n.vertexProgram),o=new Zg(i.vertexShader,"vertex"),this.programs.vertex.set(i.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(i.fragmentShader);void 0===a&&(n&&0===n.fragmentProgram.usedTimes&&this._releaseProgram(n.fragmentProgram),a=new Zg(i.fragmentShader,"fragment"),this.programs.fragment.set(i.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(n&&0===n.usedTimes&&this._releasePipeline(n),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return void 0===n&&(n=new Yg(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,r)),n}_getRenderPipeline(e,t,s,r,n){r=r||this._getRenderCacheKey(e,t,s);let i=this.caches.get(r);return void 0===i&&(i=new Xg(r,t,s),this.caches.set(r,i),e.pipeline=i,this.backend.createRenderPipeline(e,n)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class em extends Dg{constructor(e,t,s,r,n,i){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=r,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,s=e.isIndirectStorageBufferAttribute?kg:Gg;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1,n=!0,i=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(r=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=s.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?n=!1:(i=10*i+u.id,o+=u.version),!0===s.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,r),this.textures.updateTexture(u),r=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t,n?i:0,o)}}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function sm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function rm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class nm{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,n,i,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:n,group:i,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=n,a.group=i,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||tm),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||sm),this.transparent.length>1&&this.transparent.sort(t||sm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||n[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,n[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=i,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&n.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=dm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class hm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class pm extends si{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const gm=(e,t)=>hn(new pm(e,t));class mm extends Ar{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new cn(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new cn(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new cn(e),this}build(e,...t){const s=Tn();xn(this);for(const t of this.nodes)t.build(e,"void");return xn(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const fm=mn(mm);class ym extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}const bm=e=>Object.entries(e).map((([e,t])=>"string"==typeof t?{name:e,type:t,isAtomic:!1}:{name:e,type:t.type,isAtomic:t.atomic||!1}));class xm extends Ar{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let r=0;r{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),Am=(e,t)=>sa(Gi(4,e.mul(Oi(1,e))),t),Rm=(e,t)=>e.lessThan(.5)?Am(e.mul(2),t).div(2):Oi(1,Am(Gi(Oi(1,e),2),t).div(2)),Cm=(e,t,s)=>sa(ki(sa(e,t),Vi(sa(e,t),sa(Oi(1,e),s))),1/t),Em=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),wm=yn((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),Mm=yn((([e])=>Un(wm(e.z.add(wm(e.y.mul(1)))),wm(e.z.add(wm(e.x.mul(1)))),wm(e.y.add(wm(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Bm=yn((([e,t,s])=>{const r=Un(e).toVar(),n=Sn(1.4).toVar(),i=Sn(0).toVar(),o=Un(r).toVar();return uc({start:Sn(0),end:Sn(3),type:"float",condition:"<="},(()=>{const e=Un(Mm(o.mul(2))).toVar();r.addAssign(e.add(s.mul(Sn(.1).mul(t)))),o.mulAssign(1.8),n.mulAssign(1.5),r.mulAssign(1.2);const a=Sn(wm(r.z.add(wm(r.x.add(wm(r.y)))))).toVar();i.addAssign(a.div(n)),o.addAssign(.14)})),i})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Um extends Ar{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let r=null,n=-1;for(const s of this.functionNodes){const i=s.shaderNode.layout;if(null===i)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=i.inputs;if(t.length===o.length){let i=0;for(let s=0;sn&&(r=s,n=i)}}this._candidateFnCall=s=r(...t)}return s}}const Fm=mn(Um),Pm=e=>(...t)=>Fm(e,...t),Im=ti(0).setGroup(Zn).onRenderUpdate((e=>e.time)),Lm=ti(0).setGroup(Zn).onRenderUpdate((e=>e.deltaTime)),Dm=ti(0,"uint").setGroup(Zn).onRenderUpdate((e=>e.frameId)),Vm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Im.mul(e)),Om=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Im.mul(e)),Gm=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Lm.mul(e)),km=(e=Im)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),zm=(e=Im)=>e.fract().round(),$m=(e=Im)=>e.add(.5).fract().mul(2).sub(1).abs(),Hm=(e=Im)=>e.fract(),Wm=yn((([e,t,s=En(.5)])=>_g(e.sub(s),t).add(s))),jm=yn((([e,t,s=En(.5)])=>{const r=e.sub(s),n=r.dot(r),i=n.mul(n).mul(t);return e.add(r.mul(i))})),qm=yn((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const n=Eu.mul(r);return ln(t)&&(n[0][0]=Gu[0].length(),n[0][1]=0,n[0][2]=0),ln(s)&&(n[1][0]=0,n[1][1]=Gu[1].length(),n[1][2]=0),n[2][0]=0,n[2][1]=0,n[2][2]=1,Ru.mul(n).mul(Yu)})),Km=yn((([e=null])=>{const t=Qc();return Qc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class Xm extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=Sn(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:n}=s,i=e.mod(r.mul(n)).floor(),o=i.mod(r),a=n.sub(i.add(1).div(r).ceil()),u=s.reciprocal(),l=En(o,a);return t.add(l).mul(u)}}const Ym=mn(Xm);class Qm extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=Sn(1),n=Yu,i=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=n,this.normalNode=i}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:n,normalNode:i}=this;let o=i.abs().normalize();o=o.div(o.dot(Un(1)));const a=n.yz.mul(r),u=n.zx.mul(r),l=n.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vi(p,g,m)}}const Zm=mn(Qm),Jm=(...e)=>Zm(...e),ef=new me,tf=new s,sf=new s,rf=new s,nf=new i,of=new s(0,0,-1),af=new r,uf=new s,lf=new s,df=new r,cf=new t,hf=new ge,pf=Ac.flipX();hf.depthTexture=new B(1,1);let gf=!1;class mf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||hf.texture,pf),this._reflectorBaseNode=e.reflector||new ff(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=hn(new mf({defaultTexture:hf.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class ff extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:n=!1,bounces:i=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=n,this.bounces=i,this.depth=o,this.updateBeforeType=i?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(cf),e.setSize(Math.round(cf.width*s),Math.round(cf.height*s))}setup(e){return this._updateResolution(hf,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&gf)return;gf=!0;const{scene:t,camera:s,renderer:r,material:n}=e,{target:i}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(cf),this._updateResolution(a,r),sf.setFromMatrixPosition(i.matrixWorld),rf.setFromMatrixPosition(s.matrixWorld),nf.extractRotation(i.matrixWorld),tf.set(0,0,1),tf.applyMatrix4(nf),uf.subVectors(sf,rf),uf.dot(tf)>0)return;uf.reflect(tf).negate(),uf.add(sf),nf.extractRotation(s.matrixWorld),of.set(0,0,-1),of.applyMatrix4(nf),of.add(rf),lf.subVectors(sf,of),lf.reflect(tf).negate(),lf.add(sf),o.coordinateSystem=s.coordinateSystem,o.position.copy(uf),o.up.set(0,1,0),o.up.applyMatrix4(nf),o.up.reflect(tf),o.lookAt(lf),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),ef.setFromNormalAndCoplanarPoint(tf,sf),ef.applyMatrix4(o.matrixWorldInverse),af.set(ef.normal.x,ef.normal.y,ef.normal.z,ef.constant);const u=o.projectionMatrix;df.x=(Math.sign(af.x)+u.elements[8])/u.elements[0],df.y=(Math.sign(af.y)+u.elements[9])/u.elements[5],df.z=-1,df.w=(1+u.elements[10])/u.elements[14],af.multiplyScalar(1/af.dot(df));u.elements[2]=af.x,u.elements[6]=af.y,u.elements[10]=r.coordinateSystem===N?af.z-0:af.z+1-0,u.elements[14]=af.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),n.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),n.visible=!0,gf=!1}}const yf=e=>hn(new mf(e)),bf=new xe(-1,1,1,-1,0,1);class xf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const Tf=new xf;class _f extends k{constructor(e=null){super(Tf,e),this.camera=bf,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,bf)}render(e){e.render(this,bf)}}const Nf=new t;class vf extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const n=new ge(t,s,r);super(n.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=n,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new _f(new nh),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(Nf);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const Sf=(e,...t)=>hn(new vf(hn(e),...t)),Af=(e,...t)=>e.isTextureNode?e:Sf(e,...t),Rf=yn((([e,t,s],r)=>{let n;r.renderer.coordinateSystem===N?(e=En(e.x,e.y.oneMinus()).mul(2).sub(1),n=Ln(Un(e,t),1)):n=Ln(Un(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const i=Ln(s.mul(n));return i.xyz.div(i.w)})),Cf=yn((([e,t])=>{const s=t.mul(Ln(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return En(r.x,r.y.oneMinus())})),Ef=yn((([e,t,s])=>{const r=yu(Nu(t)),n=wn(e.mul(r)).toVar(),i=Nu(t,n).toVar(),o=Nu(t,n.sub(wn(2,0))).toVar(),a=Nu(t,n.sub(wn(1,0))).toVar(),u=Nu(t,n.add(wn(1,0))).toVar(),l=Nu(t,n.add(wn(2,0))).toVar(),d=Nu(t,n.add(wn(0,2))).toVar(),c=Nu(t,n.add(wn(0,1))).toVar(),h=Nu(t,n.sub(wn(0,1))).toVar(),p=Nu(t,n.sub(wn(0,2))).toVar(),g=Fo(Oi(Sn(2).mul(a).sub(o),i)).toVar(),m=Fo(Oi(Sn(2).mul(u).sub(l),i)).toVar(),f=Fo(Oi(Sn(2).mul(c).sub(d),i)).toVar(),y=Fo(Oi(Sn(2).mul(h).sub(p),i)).toVar(),b=Rf(e,i,s).toVar(),x=g.lessThan(m).select(b.sub(Rf(e.sub(En(Sn(1).div(r.x),0)),a,s)),b.negate().add(Rf(e.add(En(Sn(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Rf(e.add(En(0,Sn(1).div(r.y))),c,s)),b.negate().add(Rf(e.sub(En(0,Sn(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class wf extends pu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const Mf=(...e)=>hn(new wf(...e));class Bf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Uf=fn(Bf),Ff=new ve,Pf=new i;class If extends Ar{static get type(){return"SceneNode"}constructor(e=If.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===If.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===If.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===If.BACKGROUND_ROTATION?r=ti("mat4").label("backgroundRotation").setGroup(Zn).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Ff.copy(s.backgroundRotation),Ff.x*=-1,Ff.y*=-1,Ff.z*=-1,Pf.makeRotationFromEuler(Ff)):Pf.identity(),Pf})):console.error("THREE.SceneNode: Unknown scope:",t),r}}If.BACKGROUND_BLURRINESS="backgroundBlurriness",If.BACKGROUND_INTENSITY="backgroundIntensity",If.BACKGROUND_ROTATION="backgroundRotation";const Lf=fn(If,If.BACKGROUND_BLURRINESS),Df=fn(If,If.BACKGROUND_INTENSITY),Vf=fn(If,If.BACKGROUND_ROTATION);class Of extends Rr{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Gf=mn(Of),kf="point-list",zf="line-list",$f="line-strip",Hf="triangle-list",Wf="triangle-strip",jf="never",qf="less",Kf="equal",Xf="less-equal",Yf="greater",Qf="not-equal",Zf="greater-equal",Jf="always",ey="store",ty="load",sy="clear",ry="ccw",ny="none",iy="front",oy="back",ay="uint16",uy="uint32",ly={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},dy="clamp-to-edge",cy="repeat",hy="mirror-repeat",py="linear",gy="nearest",my="zero",fy="one",yy="src",by="one-minus-src",xy="src-alpha",Ty="one-minus-src-alpha",_y="dst",Ny="one-minus-dst",vy="dst-alpha",Sy="one-minus-dst-alpha",Ay="src-alpha-saturated",Ry="constant",Cy="one-minus-constant",Ey="add",wy="subtract",My="reverse-subtract",By="min",Uy="max",Fy=0,Py=15,Iy="keep",Ly="zero",Dy="replace",Vy="invert",Oy="increment-clamp",Gy="decrement-clamp",ky="increment-wrap",zy="decrement-wrap",$y="storage",Hy="read-only-storage",Wy="write-only",jy="read-only",qy="float",Ky="unfilterable-float",Xy="depth",Yy="sint",Qy="uint",Zy="2d",Jy="3d",eb="2d",tb="2d-array",sb="cube",rb="3d",nb="all",ib="vertex",ob="instance",ab={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class ub extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=$y,this.isAtomic=!1,this.bufferObject=!1,this.bufferStruct=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Gf(this,e)}setBufferObject(e){return this.bufferObject=e,this}setBufferStruct(e){return this.bufferStruct=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Hy)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),r=s.build(e);return e.registerTransform(r,t),r}}const lb=(e,t,s)=>hn(new ub(e,t,s)),db=(e,t,s)=>hn(new ub(e,t,s).setBufferStruct(!0)),cb=(e,t,s)=>hn(new ub(e,t,s).setBufferObject(!0));class hb extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Wy}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(jy)}toWriteOnly(){return this.setAccess(Wy)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,n=super.generate(e,"property"),i=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,n,i,o);e.addLineFlowCode(a,this)}}const pb=mn(hb),gb=(e,t,s)=>{const r=pb(e,t,s);return null!==s&&r.append(),r};class mb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const fb=(e,t,s)=>hn(new mb(e,t,s)),yb=new WeakMap;class bb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=ti(new i),this.previousProjectionMatrix=ti(new i).setGroup(Zn),this.previousCameraViewMatrix=ti(new i)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=Tb(s);this.previousModelWorldMatrix.value.copy(r);const n=xb(t);n.frameId!==e&&(n.frameId=e,void 0===n.previousProjectionMatrix?(n.previousProjectionMatrix=new i,n.previousCameraViewMatrix=new i,n.currentProjectionMatrix=new i,n.currentCameraViewMatrix=new i,n.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(n.previousProjectionMatrix.copy(n.currentProjectionMatrix),n.previousCameraViewMatrix.copy(n.currentCameraViewMatrix)),n.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(n.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(n.previousCameraViewMatrix))}updateAfter({object:e}){Tb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:ti(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),n=s.xy.div(s.w),i=r.xy.div(r.w);return Oi(n,i)}}function xb(e){let t=yb.get(e);return void 0===t&&(t={},yb.set(e,t)),t}function Tb(e,t=0){const s=xb(e);let r=s[t];return void 0===r&&(s[t]=r=new i),r}const _b=fn(bb),Nb=yn((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=yn((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Sb=yn((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Ab=yn((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Rb=yn((([e,t])=>Ln(e.rgb.mul(t.a.oneMinus()).add(t.rgb.mul(t.a)),e.a))).setLayout({name:"blendNormal",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Cb=yn((([e])=>Bb(e.rgb))),Eb=yn((([e,t=Sn(1)])=>t.mix(Bb(e.rgb),e.rgb))),wb=yn((([e,t=Sn(1)])=>{const s=Vi(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),n=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,n)})),Mb=yn((([e,t=Sn(1)])=>{const s=Un(.57735,.57735,.57735),r=t.cos();return Un(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),Bb=(e,t=Un(u.getLuminanceCoefficients(new s)))=>ea(e,t),Ub=(e,t)=>la(Un(0),e,Bb(e).sub(t).max(0)),Fb=yn((([e,t=Un(1),r=Un(0),n=Un(1),i=Sn(1),o=Un(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Un(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(n).toVar();return _n(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),_n(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),_n(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(i))),Ln(l.rgb,e.a)}));class Pb extends Er{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Ib=mn(Pb);let Lb=null;class Db extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Lb&&(Lb=new w),super(e,t,Lb)}updateReference(){return this}}const Vb=mn(Db),Ob=new t;class Gb extends Tu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class kb extends Gb{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class zb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const n=new B;n.isRenderTargetTexture=!0,n.name="depth";const i=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});i.texture.name="output",i.depthTexture=n,this.renderTarget=i,this.updateBeforeType=br.FRAME,this._textures={output:i.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=ti(0),this._cameraFar=ti(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=hn(new kb(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=hn(new kb(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(n,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===zb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const n=t.getSize(Ob);this.setSize(n.width,n.height);const i=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(i),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}zb.COLOR="color",zb.DEPTH="depth";const $b=(e,t,s)=>hn(new zb(zb.COLOR,e,t,s)),Hb=(e,t)=>hn(new Gb(e,t)),Wb=(e,t)=>hn(new zb(zb.DEPTH,e,t));class jb extends zb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,n){super(zb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=n,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,n,i,o,a,u)=>{if((i.isMeshToonMaterial||i.isMeshToonNodeMaterial)&&!1===i.wireframe){const l=this._getOutlineMaterial(i);t.renderObject(e,s,r,n,l,o,a,u)}t.renderObject(e,s,r,n,i,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new nh;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=Sn(1),n=s.mul(Ln(Yu,1)),i=s.mul(Ln(Yu.add(t),1)),o=Ao(n.sub(i));return e.vertexNode=n.add(o.mul(this.thicknessNode).mul(n.w).mul(r)),e.colorNode=Ln(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const qb=(t,s,r=new e(0,0,0),n=.003,i=1)=>hn(new jb(t,s,hn(r),hn(n),hn(i))),Kb=yn((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=yn((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Yb=yn((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qb=yn((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Zb=yn((([e,t])=>{const s=kn(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=kn(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=Qb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Jb=kn(Un(1.6605,-.1246,-.0182),Un(-.5876,1.1329,-.1006),Un(-.0728,-.0083,1.1187)),ex=kn(Un(.6274,.0691,.0164),Un(.3293,.9195,.088),Un(.0433,.0113,.8956)),tx=yn((([e])=>{const t=Un(e).toVar(),s=Un(t.mul(t)).toVar(),r=Un(s.mul(s)).toVar();return Sn(15.5).mul(r.mul(s)).sub(Gi(40.14,r.mul(t))).add(Gi(31.96,r).sub(Gi(6.868,s.mul(t))).add(Gi(.4298,s).add(Gi(.1191,t).sub(.00232))))})),sx=yn((([e,t])=>{const s=Un(e).toVar(),r=kn(Un(.856627153315983,.137318972929847,.11189821299995),Un(.0951212405381588,.761241990602591,.0767994186031903),Un(.0482516061458583,.101439036467562,.811302368396859)),n=kn(Un(1.1271005818144368,-.1413297634984383,-.14132976349843826),Un(-.11060664309660323,1.157823702216272,-.11060664309660294),Un(-.016493938717834573,-.016493938717834257,1.2519364065950405)),i=Sn(-12.47393),o=Sn(4.026069);return s.mulAssign(t),s.assign(ex.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(i).div(o.sub(i))),s.assign(da(s,0,1)),s.assign(tx(s)),s.assign(n.mul(s)),s.assign(sa(Ko(Un(0),s),Un(2.2))),s.assign(Jb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),rx=yn((([e,t])=>{const s=Sn(.76),r=Sn(.15);e=e.mul(t);const n=qo(e.r,qo(e.g,e.b)),i=xa(n.lessThan(.08),n.sub(Gi(6.25,n.mul(n))),.04);e.subAssign(i);const o=Ko(e.r,Ko(e.g,e.b));_n(o.lessThan(s),(()=>e));const a=Oi(1,s),u=Oi(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=Oi(1,ki(1,r.mul(o.sub(u)).add(1)));return la(e,Un(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class nx extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const ix=mn(nx),ox=(e,t)=>ix(e,t,"js"),ax=(e,t)=>ix(e,t,"wgsl"),ux=(e,t)=>ix(e,t,"glsl");class lx extends nx{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,n=s.type,i=e.getCodeFromNode(this,n);""!==r&&(i.name=r);const o=e.getPropertyName(i),a=this.getNodeFunction(e).getCode(o);return i.code=a+"\n","property"===t?o:e.format(`${o}()`,n,t)}}const dx=(e,t=[],s="")=>{for(let e=0;er.call(...e);return n.functionNode=r,n},cx=(e,t)=>dx(e,t,"glsl"),hx=(e,t)=>dx(e,t,"wgsl");class px extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:Sn()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const gx=mn(px);class mx extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class fx{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const yx=new mx;class bx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new mx,this._output=gx(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=gx(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=gx(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new fx(this),t=yx.get("THREE"),s=yx.get("TSL"),r=this.getMethod(this.codeNode),n=[e,this._local,yx,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...n);const i=this._object.layout;if(i&&(!1===i.cache&&this._local.clear(),this._output.outputType=i.outputType||null,Array.isArray(i.elements)))for(const e of i.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:Sn()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const xx=mn(bx);class Tx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const _x=mn(Tx);class Nx extends Tx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const vx=mn(Nx);class Sx extends Tx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const Ax=mn(Sx);let Rx=null,Cx=null;class Ex extends Ar{static get type(){return"RangeNode"}constructor(e=Sn(),t=Sn()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const n=this.minNode.value,i=this.maxNode.value,o=e.getTypeLength(hr(n)),u=e.getTypeLength(hr(i));Rx=Rx||new r,Cx=Cx||new r,Rx.setScalar(0),Cx.setScalar(0),1===o?Rx.setScalar(n):n.isColor?Rx.set(n.r,n.g,n.b):Rx.set(n.x,n.y,n.z||0,n.w||0),1===u?Cx.setScalar(i):i.isColor?Cx.set(i.r,i.g,i.b):Cx.set(i.x,i.y,i.z||0,i.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;ehn(new Mx(e,t)),Ux=Bx("numWorkgroups","uvec3"),Fx=Bx("workgroupId","uvec3"),Px=Bx("localId","uvec3"),Ix=Bx("subgroupSize","uint");const Lx=mn(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Dx=()=>Lx("workgroup").append(),Vx=()=>Lx("storage").append(),Ox=()=>Lx("texture").append();class Gx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class kx extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return hn(new Gx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const zx=(e,t)=>hn(new kx("Workgroup",e,t));class $x extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),n=this.pointerNode,i=this.valueNode,o=[];o.push(`&${n.build(e,r)}`),o.push(i.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}$x.ATOMIC_LOAD="atomicLoad",$x.ATOMIC_STORE="atomicStore",$x.ATOMIC_ADD="atomicAdd",$x.ATOMIC_SUB="atomicSub",$x.ATOMIC_MAX="atomicMax",$x.ATOMIC_MIN="atomicMin",$x.ATOMIC_AND="atomicAnd",$x.ATOMIC_OR="atomicOr",$x.ATOMIC_XOR="atomicXor";const Hx=mn($x),Wx=(e,t,s,r)=>{const n=Hx(e,t,s,r);return n.append(),n},jx=(e,t,s=null)=>Wx($x.ATOMIC_STORE,e,t,s),qx=(e,t,s=null)=>Wx($x.ATOMIC_ADD,e,t,s),Kx=(e,t,s=null)=>Wx($x.ATOMIC_SUB,e,t,s),Xx=(e,t,s=null)=>Wx($x.ATOMIC_MAX,e,t,s),Yx=(e,t,s=null)=>Wx($x.ATOMIC_MIN,e,t,s),Qx=(e,t,s=null)=>Wx($x.ATOMIC_AND,e,t,s),Zx=(e,t,s=null)=>Wx($x.ATOMIC_OR,e,t,s),Jx=(e,t,s=null)=>Wx($x.ATOMIC_XOR,e,t,s);let eT;function tT(e){eT=eT||new WeakMap;let t=eT.get(e);return void 0===t&&eT.set(e,t={}),t}function sT(e){const t=tT(e);return t.position||(t.position=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function rT(e){const t=tT(e);return t.targetPosition||(t.targetPosition=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function nT(e){const t=tT(e);return t.viewPosition||(t.viewPosition=ti(new s).setGroup(Zn).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const iT=e=>Eu.transformDirection(sT(e).sub(rT(e))),oT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},aT=new WeakMap;class uT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Un().toVar("totalDiffuse"),this.totalSpecularNode=Un().toVar("totalSpecular"),this.outgoingLightNode=Un().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),n=e.renderer.library;for(const e of r)if(e.isNode)t.push(hn(e));else{let r=null;if(null!==s&&(r=oT(e.id,s)),null===r){const s=n.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;aT.has(e)?r=aT.get(e):(r=hn(new s(e)),aT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:n,totalDiffuseNode:i,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,n),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Un(null!==l?l.mix(g,u):u),t.material.transparent=!0),i.assign(g),o.assign(c.add(p)),r.assign(i.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const lT=(e=[])=>hn(new uT).setLights(e),dT=yn((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),cT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=Ml("radius","float",s).setGroup(Zn),o=En(1).div(n),a=o.x.negate().mul(i),u=o.y.negate().mul(i),l=o.x.mul(i),d=o.y.mul(i),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vi(r(t.xy.add(En(a,u)),t.z),r(t.xy.add(En(0,u)),t.z),r(t.xy.add(En(l,u)),t.z),r(t.xy.add(En(c,h)),t.z),r(t.xy.add(En(0,h)),t.z),r(t.xy.add(En(p,h)),t.z),r(t.xy.add(En(a,0)),t.z),r(t.xy.add(En(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(En(p,0)),t.z),r(t.xy.add(En(l,0)),t.z),r(t.xy.add(En(c,g)),t.z),r(t.xy.add(En(0,g)),t.z),r(t.xy.add(En(p,g)),t.z),r(t.xy.add(En(a,d)),t.z),r(t.xy.add(En(0,d)),t.z),r(t.xy.add(En(l,d)),t.z)).mul(1/17)})),hT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=En(1).div(n),o=i.x,a=i.y,u=t.xy,l=Ro(u.mul(n).add(.5));return u.subAssign(l.mul(i)),Vi(r(u,t.z),r(u.add(En(o,0)),t.z),r(u.add(En(0,a)),t.z),r(u.add(i),t.z),la(r(u.add(En(o.negate(),0)),t.z),r(u.add(En(o.mul(2),0)),t.z),l.x),la(r(u.add(En(o.negate(),a)),t.z),r(u.add(En(o.mul(2),a)),t.z),l.x),la(r(u.add(En(0,a.negate())),t.z),r(u.add(En(0,a.mul(2))),t.z),l.y),la(r(u.add(En(o,a.negate())),t.z),r(u.add(En(o,a.mul(2))),t.z),l.y),la(la(r(u.add(En(o.negate(),a.negate())),t.z),r(u.add(En(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(En(o.negate(),a.mul(2))),t.z),r(u.add(En(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),pT=yn((({depthTexture:e,shadowCoord:t})=>{const s=Sn(1).toVar(),r=_u(e).uv(t.xy).rg,n=Yo(t.z,r.x);return _n(n.notEqual(Sn(1)),(()=>{const e=t.z.sub(r.x),i=Ko(0,r.y.mul(r.y));let o=i.div(i.add(e.mul(e)));o=da(Oi(o,.3).div(.95-.3)),s.assign(da(Ko(n,o)))})),s})),gT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(0,u).mul(t)).div(s)).x;n.addAssign(l),i.addAssign(l.mul(l))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),mT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(u,0).mul(t)).div(s));n.addAssign(l.x),i.addAssign(Vi(l.y.mul(l.y),l.x.mul(l.x)))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),fT=[dT,cT,hT,pT];let yT=null;const bT=new _f;class xT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===yT&&(yT=new nh,yT.fragmentNode=Ln(0,0,0,1),yT.isShadowNodeMaterial=!0,yT.name="ShadowMaterial");const r=this.shadow,n=s.shadowMap.type,i=new B(r.mapSize.width,r.mapSize.height);i.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=i,r.camera.updateProjectionMatrix(),n===Re){i.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(i),s=_u(this.vsmShadowMapVertical.texture),n=Ml("blurSamples","float",r).setGroup(Zn),o=Ml("radius","float",r).setGroup(Zn),a=Ml("mapSize","vec2",r).setGroup(Zn);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new nh);u.fragmentNode=gT({samples:n,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new nh),u.fragmentNode=mT({samples:n,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Zn),u=Ml("bias","float",r).setGroup(Zn),l=Ml("normalBias","float",r).setGroup(Zn),d=t.material.shadowPositionNode||Zu;let c,h=ti(r.matrix).setGroup(Zn).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=Ml("near","float",r.camera).setGroup(Zn),s=Ml("far","float",r.camera).setGroup(Zn);c=qc(e.negate(),t,s)}h=Un(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||fT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:n===Re?this.vsmShadowMapHorizontal.texture:i,shadowCoord:h,shadow:r}),Sn(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:n,scene:i,camera:o}=e,a=n.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=i.overrideMaterial;i.overrideMaterial=yT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=n.getRenderTarget(),c=n.getRenderObjectFunction();n.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&n.renderObject(e,...t)})),n.setRenderTarget(t),n.render(i,r.camera),n.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(n),n.setRenderTarget(d),i.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),bT.material=this.vsmMaterialVertical,bT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),bT.material=this.vsmMaterialHorizontal,bT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const TT=(e,t)=>hn(new xT(e,t));class _T extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=ti(this.color).setGroup(Zn),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?hn(e):TT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const NT=yn((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,n=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(n.mul(t.div(s).pow4().oneMinus().clamp().pow2()),n)})),vT=yn((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},n)=>{const i=n.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=NT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=n.context.reflectedLight;i.direct({lightDirection:a,lightColor:d,reflectedLight:c},n.stack,n)}));class ST extends _T{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){vT({color:this.colorNode,lightViewPosition:nT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const AT=yn((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),RT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Cn(e).toVar();return xa(i,n,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),CT=yn((([e,t])=>{const s=Cn(t).toVar(),r=Sn(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),ET=yn((([e])=>{const t=Sn(e).toVar();return An(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),wT=yn((([e,t])=>{const s=Sn(e).toVar();return t.assign(ET(s)),s.sub(Sn(t))})),MT=Pm([yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Sn(r).toVar(),l=Sn(s).toVar(),d=Sn(t).toVar(),c=Sn(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Un(r).toVar(),l=Un(s).toVar(),d=Un(t).toVar(),c=Un(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),BT=Pm([yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Sn(a).toVar(),m=Sn(o).toVar(),f=Sn(i).toVar(),y=Sn(n).toVar(),b=Sn(r).toVar(),x=Sn(s).toVar(),T=Sn(t).toVar(),_=Sn(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Un(a).toVar(),m=Un(o).toVar(),f=Un(i).toVar(),y=Un(n).toVar(),b=Un(r).toVar(),x=Un(s).toVar(),T=Un(t).toVar(),_=Un(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),UT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Rn(e).toVar(),o=Rn(i.bitAnd(Rn(7))).toVar(),a=Sn(RT(o.lessThan(Rn(4)),n,r)).toVar(),u=Sn(Gi(2,RT(o.lessThan(Rn(4)),r,n))).toVar();return CT(a,Cn(o.bitAnd(Rn(1)))).add(CT(u,Cn(o.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),FT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Rn(e).toVar(),u=Rn(a.bitAnd(Rn(15))).toVar(),l=Sn(RT(u.lessThan(Rn(8)),o,i)).toVar(),d=Sn(RT(u.lessThan(Rn(4)),i,RT(u.equal(Rn(12)).or(u.equal(Rn(14))),o,n))).toVar();return CT(l,Cn(u.bitAnd(Rn(1)))).add(CT(d,Cn(u.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),PT=Pm([UT,FT]),IT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Pn(e).toVar();return Un(PT(i.x,n,r),PT(i.y,n,r),PT(i.z,n,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),LT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Pn(e).toVar();return Un(PT(a.x,o,i,n),PT(a.y,o,i,n),PT(a.z,o,i,n))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),DT=Pm([IT,LT]),VT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),OT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),GT=Pm([VT,yn((([e])=>{const t=Un(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),kT=Pm([OT,yn((([e])=>{const t=Un(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),zT=yn((([e,t])=>{const s=An(t).toVar(),r=Rn(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(An(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),$T=yn((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(zT(s,An(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(zT(e,An(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(zT(t,An(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(zT(s,An(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(zT(e,An(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(zT(t,An(4))),t.addAssign(e)})),HT=yn((([e,t,s])=>{const r=Rn(s).toVar(),n=Rn(t).toVar(),i=Rn(e).toVar();return r.bitXorAssign(n),r.subAssign(zT(n,An(14))),i.bitXorAssign(r),i.subAssign(zT(r,An(11))),n.bitXorAssign(i),n.subAssign(zT(i,An(25))),r.bitXorAssign(n),r.subAssign(zT(n,An(16))),i.bitXorAssign(r),i.subAssign(zT(r,An(4))),n.bitXorAssign(i),n.subAssign(zT(i,An(14))),r.bitXorAssign(n),r.subAssign(zT(n,An(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),WT=yn((([e])=>{const t=Rn(e).toVar();return Sn(t).div(Sn(Rn(An(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),jT=yn((([e])=>{const t=Sn(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),qT=Pm([yn((([e])=>{const t=An(e).toVar(),s=Rn(Rn(1)).toVar(),r=Rn(Rn(An(3735928559)).add(s.shiftLeft(Rn(2))).add(Rn(13))).toVar();return HT(r.add(Rn(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(Rn(2)).toVar(),i=Rn().toVar(),o=Rn().toVar(),a=Rn().toVar();return i.assign(o.assign(a.assign(Rn(An(3735928559)).add(n.shiftLeft(Rn(2))).add(Rn(13))))),i.addAssign(Rn(r)),o.addAssign(Rn(s)),HT(i,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(Rn(3)).toVar(),a=Rn().toVar(),u=Rn().toVar(),l=Rn().toVar();return a.assign(u.assign(l.assign(Rn(An(3735928559)).add(o.shiftLeft(Rn(2))).add(Rn(13))))),a.addAssign(Rn(i)),u.addAssign(Rn(n)),l.addAssign(Rn(r)),HT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),yn((([e,t,s,r])=>{const n=An(r).toVar(),i=An(s).toVar(),o=An(t).toVar(),a=An(e).toVar(),u=Rn(Rn(4)).toVar(),l=Rn().toVar(),d=Rn().toVar(),c=Rn().toVar();return l.assign(d.assign(c.assign(Rn(An(3735928559)).add(u.shiftLeft(Rn(2))).add(Rn(13))))),l.addAssign(Rn(a)),d.addAssign(Rn(o)),c.addAssign(Rn(i)),$T(l,d,c),l.addAssign(Rn(n)),HT(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),yn((([e,t,s,r,n])=>{const i=An(n).toVar(),o=An(r).toVar(),a=An(s).toVar(),u=An(t).toVar(),l=An(e).toVar(),d=Rn(Rn(5)).toVar(),c=Rn().toVar(),h=Rn().toVar(),p=Rn().toVar();return c.assign(h.assign(p.assign(Rn(An(3735928559)).add(d.shiftLeft(Rn(2))).add(Rn(13))))),c.addAssign(Rn(l)),h.addAssign(Rn(u)),p.addAssign(Rn(a)),$T(c,h,p),c.addAssign(Rn(o)),h.addAssign(Rn(i)),HT(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),KT=Pm([yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(qT(r,s)).toVar(),i=Pn().toVar();return i.x.assign(n.bitAnd(An(255))),i.y.assign(n.shiftRight(An(8)).bitAnd(An(255))),i.z.assign(n.shiftRight(An(16)).bitAnd(An(255))),i})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(qT(i,n,r)).toVar(),a=Pn().toVar();return a.x.assign(o.bitAnd(An(255))),a.y.assign(o.shiftRight(An(8)).bitAnd(An(255))),a.z.assign(o.shiftRight(An(16)).bitAnd(An(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),XT=Pm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(wT(t.x,s)).toVar(),i=Sn(wT(t.y,r)).toVar(),o=Sn(jT(n)).toVar(),a=Sn(jT(i)).toVar(),u=Sn(MT(PT(qT(s,r),n,i),PT(qT(s.add(An(1)),r),n.sub(1),i),PT(qT(s,r.add(An(1))),n,i.sub(1)),PT(qT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return GT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(wT(t.x,s)).toVar(),o=Sn(wT(t.y,r)).toVar(),a=Sn(wT(t.z,n)).toVar(),u=Sn(jT(i)).toVar(),l=Sn(jT(o)).toVar(),d=Sn(jT(a)).toVar(),c=Sn(BT(PT(qT(s,r,n),i,o,a),PT(qT(s.add(An(1)),r,n),i.sub(1),o,a),PT(qT(s,r.add(An(1)),n),i,o.sub(1),a),PT(qT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),PT(qT(s,r,n.add(An(1))),i,o,a.sub(1)),PT(qT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),PT(qT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),PT(qT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return kT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),YT=Pm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(wT(t.x,s)).toVar(),i=Sn(wT(t.y,r)).toVar(),o=Sn(jT(n)).toVar(),a=Sn(jT(i)).toVar(),u=Un(MT(DT(KT(s,r),n,i),DT(KT(s.add(An(1)),r),n.sub(1),i),DT(KT(s,r.add(An(1))),n,i.sub(1)),DT(KT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return GT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(wT(t.x,s)).toVar(),o=Sn(wT(t.y,r)).toVar(),a=Sn(wT(t.z,n)).toVar(),u=Sn(jT(i)).toVar(),l=Sn(jT(o)).toVar(),d=Sn(jT(a)).toVar(),c=Un(BT(DT(KT(s,r,n),i,o,a),DT(KT(s.add(An(1)),r,n),i.sub(1),o,a),DT(KT(s,r.add(An(1)),n),i,o.sub(1),a),DT(KT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),DT(KT(s,r,n.add(An(1))),i,o,a.sub(1)),DT(KT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),DT(KT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),DT(KT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return kT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),QT=Pm([yn((([e])=>{const t=Sn(e).toVar(),s=An(ET(t)).toVar();return WT(qT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar();return WT(qT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar();return WT(qT(s,r,n))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar(),i=An(ET(t.w)).toVar();return WT(qT(s,r,n,i))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),ZT=Pm([yn((([e])=>{const t=Sn(e).toVar(),s=An(ET(t)).toVar();return Un(WT(qT(s,An(0))),WT(qT(s,An(1))),WT(qT(s,An(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar();return Un(WT(qT(s,r,An(0))),WT(qT(s,r,An(1))),WT(qT(s,r,An(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar();return Un(WT(qT(s,r,n,An(0))),WT(qT(s,r,n,An(1))),WT(qT(s,r,n,An(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar(),i=An(ET(t.w)).toVar();return Un(WT(qT(s,r,n,i,An(0))),WT(qT(s,r,n,i,An(1))),WT(qT(s,r,n,i,An(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),JT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Sn(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(XT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),e_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(YT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),t_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar();return En(JT(a,o,i,n),JT(a.add(Un(An(19),An(193),An(17))),o,i,n))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),s_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(e_(a,o,i,n)).toVar(),l=Sn(JT(a.add(Un(An(19),An(193),An(17))),o,i,n)).toVar();return Ln(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),r_=Pm([yn((([e,t,s,r,n,i,o])=>{const a=An(o).toVar(),u=Sn(i).toVar(),l=An(n).toVar(),d=An(r).toVar(),c=An(s).toVar(),h=An(t).toVar(),p=En(e).toVar(),g=Un(ZT(En(h.add(d),c.add(l)))).toVar(),m=En(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=En(En(Sn(h),Sn(c)).add(m)).toVar(),y=En(f.sub(p)).toVar();return _n(a.equal(An(2)),(()=>Fo(y.x).add(Fo(y.y)))),_n(a.equal(An(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),yn((([e,t,s,r,n,i,o,a,u])=>{const l=An(u).toVar(),d=Sn(a).toVar(),c=An(o).toVar(),h=An(i).toVar(),p=An(n).toVar(),g=An(r).toVar(),m=An(s).toVar(),f=An(t).toVar(),y=Un(e).toVar(),b=Un(ZT(Un(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Un(Un(Sn(f),Sn(m),Sn(g)).add(b)).toVar(),T=Un(x.sub(y)).toVar();return _n(l.equal(An(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),_n(l.equal(An(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),n_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();l.assign(qo(l,s))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),o_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),a_=Pm([n_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();d.assign(qo(d,i))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=Pm([i_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.y.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),l_=Pm([o_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(i)})).ElseIf(i.lessThan(d.z),(()=>{d.z.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),d_=yn((([e])=>{const t=e.y,s=e.z,r=Un().toVar();return _n(t.lessThan(1e-4),(()=>{r.assign(Un(s,s,s))})).Else((()=>{let n=e.x;n=n.sub(vo(n)).mul(6).toVar();const i=An(zo(n)),o=n.sub(Sn(i)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());_n(i.equal(An(0)),(()=>{r.assign(Un(s,l,a))})).ElseIf(i.equal(An(1)),(()=>{r.assign(Un(u,s,a))})).ElseIf(i.equal(An(2)),(()=>{r.assign(Un(a,s,l))})).ElseIf(i.equal(An(3)),(()=>{r.assign(Un(a,u,s))})).ElseIf(i.equal(An(4)),(()=>{r.assign(Un(l,a,s))})).Else((()=>{r.assign(Un(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),c_=yn((([e])=>{const t=Un(e).toVar(),s=Sn(t.x).toVar(),r=Sn(t.y).toVar(),n=Sn(t.z).toVar(),i=Sn(qo(s,qo(r,n))).toVar(),o=Sn(Ko(s,Ko(r,n))).toVar(),a=Sn(o.sub(i)).toVar(),u=Sn().toVar(),l=Sn().toVar(),d=Sn().toVar();return d.assign(o),_n(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),_n(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{_n(s.greaterThanEqual(o),(()=>{u.assign(r.sub(n).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vi(2,n.sub(s).div(a)))})).Else((()=>{u.assign(Vi(4,s.sub(r).div(a)))})),u.mulAssign(1/6),_n(u.lessThan(0),(()=>{u.addAssign(1)}))})),Un(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),h_=yn((([e])=>{const t=Un(e).toVar(),s=In(ji(t,Un(.04045))).toVar(),r=Un(t.div(12.92)).toVar(),n=Un(sa(Ko(t.add(Un(.055)),Un(0)).div(1.055),Un(2.4))).toVar();return la(r,n,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),p_=(e,t)=>{e=Sn(e),t=Sn(t);const s=En(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},g_=(e,t,s,r)=>la(e,t,s[r].clamp()),m_=(e,t,s=mu())=>g_(e,t,s,"x"),f_=(e,t,s=mu())=>g_(e,t,s,"y"),y_=(e,t,s,r,n)=>la(e,t,p_(s,r[n])),b_=(e,t,s,r=mu())=>y_(e,t,s,r,"x"),x_=(e,t,s,r=mu())=>y_(e,t,s,r,"y"),T_=(e=1,t=0,s=mu())=>s.mul(e).add(t),__=(e,t=1)=>(e=Sn(e)).abs().pow(t).mul(e.sign()),N_=(e,t=1,s=.5)=>Sn(e).sub(s).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>XT(e.convert("vec2|vec3")).mul(t).add(s),S_=(e=mu(),t=1,s=0)=>YT(e.convert("vec2|vec3")).mul(t).add(s),A_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ln(YT(e),XT(e.add(En(19,73)))).mul(t).add(s)},R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,An(1)),C_=(e=mu(),t=1)=>u_(e.convert("vec2|vec3"),t,An(1)),E_=(e=mu(),t=1)=>l_(e.convert("vec2|vec3"),t,An(1)),w_=(e=mu())=>QT(e.convert("vec2|vec3")),M_=(e=mu(),t=3,s=2,r=.5,n=1)=>JT(e,An(t),s,r).mul(n),B_=(e=mu(),t=3,s=2,r=.5,n=1)=>t_(e,An(t),s,r).mul(n),U_=(e=mu(),t=3,s=2,r=.5,n=1)=>e_(e,An(t),s,r).mul(n),F_=(e=mu(),t=3,s=2,r=.5,n=1)=>s_(e,An(t),s,r).mul(n),P_=yn((([e,t,s])=>{const r=Ao(e).toVar("nDir"),n=Oi(Sn(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),i=Oi(Sn(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Un().toVar("rbminmax");o.x=r.x.greaterThan(Sn(0)).select(n.x,i.x),o.y=r.y.greaterThan(Sn(0)).select(n.y,i.y),o.z=r.z.greaterThan(Sn(0)).select(n.z,i.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),I_=yn((([e,t])=>{const s=e.x,r=e.y,n=e.z;let i=t.element(0).mul(.886227);return i=i.add(t.element(1).mul(1.023328).mul(r)),i=i.add(t.element(2).mul(1.023328).mul(n)),i=i.add(t.element(3).mul(1.023328).mul(s)),i=i.add(t.element(4).mul(.858086).mul(s).mul(r)),i=i.add(t.element(5).mul(.858086).mul(r).mul(n)),i=i.add(t.element(6).mul(n.mul(n).mul(.743125).sub(.247708))),i=i.add(t.element(7).mul(.858086).mul(s).mul(n)),i=i.add(t.element(8).mul(.429043).mul(Gi(s,s).sub(Gi(r,r)))),i})),L_=new hm;class D_ extends Dg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,n=this.nodes.getBackgroundNode(e)||e.background;let i=!1;if(null===n)r._clearColor.getRGB(L_,Se),L_.a=r._clearColor.a;else if(!0===n.isColor)n.getRGB(L_,Se),L_.a=1,i=!0;else if(!0===n.isNode){const s=this.get(e),i=n;L_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ln(i).mul(Df),{getUV:()=>Vf.mul(ll),getTextureLevel:()=>Lf});let t=Wd();t=t.setZ(t.w);const r=new nh;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=i.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ln(i).mul(Df),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",n);if(!0===r.autoClear||!0===i){const e=s.clearColorValue;e.r=L_.r,e.g=L_.g,e.b=L_.b,e.a=L_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let V_=0;class O_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=V_++}}class G_{constructor(e,t,s,r,n,i,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=n,this.updateNodes=i,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new O_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class k_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class z_{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class $_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class H_ extends $_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class W_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let j_=0;class q_{constructor(e=null){this.id=j_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class K_{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class X_ extends K_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class Y_ extends K_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class Q_ extends K_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends K_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class J_ extends K_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class eN extends K_{constructor(e,t=new n){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class tN extends K_{constructor(e,t=new i){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class aN extends eN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class uN extends tN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const lN=[.125,.215,.35,.446,.526,.582],dN=20,cN=new xe(-1,1,1,-1,0,1),hN=new Be(90,1),pN=new e;let gN=null,mN=0,fN=0;const yN=(1+Math.sqrt(5))/2,bN=1/yN,xN=[new s(-yN,bN,0),new s(yN,bN,0),new s(-bN,0,yN),new s(bN,0,yN),new s(0,yN,-bN),new s(0,yN,bN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],TN=[3,1,5,0,4,2],_N=Hp(mu(),gu("faceIndex")).normalize(),NN=Un(_N.x,_N.y.negate(),_N.z);class vN{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(e,t=0,s=.1,r=100){gN=this._renderer.getRenderTarget(),mN=this._renderer.getActiveCubeFace(),fN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const n=this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(e,s,r,n),t>0&&this._blur(n,0,0,t),this._applyPMREM(n),this._cleanup(n),n}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=CN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=EN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=lN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],n=TN[e];b.set(r,m*g*n),x.set(h,f*g*n);const i=[n,n,n,n,n,n];T.set(i,y*g*n)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),n.push(new k(_,null)),i>4&&i--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:n}}(n)),this._blurMaterial=function(e,t,r){const n=Rl(new Array(dN).fill(0)),i=ti(new s(0,1,0)),o=ti(0),a=Sn(dN),u=ti(0),l=ti(1),d=_u(null),c=ti(0),h=Sn(1/t),p=Sn(1/r),g=Sn(e),m={n:a,latitudinal:u,weights:n,poleAxis:i,outputDirection:NN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=RN("blur");return f.uniforms=m,f.fragmentNode=Kp({...m,latitudinal:u.equal(1)}),f}(n,e,t)}return n}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,cN)}_sceneToCubeUV(e,t,s,r){const n=hN;n.near=t,n.far=s;const i=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(pN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(pN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,n);for(let t=0;t<6;t++){const s=t%3;0===s?(n.up.set(0,i[t],0),n.lookAt(o[t],0,0)):1===s?(n.up.set(0,0,i[t]),n.lookAt(0,o[t],0)):(n.up.set(0,i[t],0),n.lookAt(0,0,o[t]));const u=this._cubeSize;AN(r,s*u,t>2?u:0,u,u),a.render(e,n)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=CN(e)):null===this._equirectMaterial&&(this._equirectMaterial=EN(e));const n=r?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=n;const o=this._cubeSize;AN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(i,cN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;tdN&&console.warn(`sigmaRadians, ${n}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,cN)}}function SN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function AN(e,t,s,r,n){e.viewport.set(t,s,r,n),e.scissor.set(t,s,r,n)}function RN(e){const t=new nh;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function CN(e){const t=RN("cubemap");return t.fragmentNode=_l(e,NN),t}function EN(e){const t=RN("equirect");return t.fragmentNode=_u(e,bh(NN),0),t}const wN=new WeakMap,MN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),BN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),UN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class FN{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=fm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new q_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=wN.get(this.renderer);return void 0===e&&(e=new Ug,wN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new xh(e,t)}createPMREMGenerator(){return new vN(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let n,i=!0;for(const e of t)r.push(e),i=i&&!0!==e.groupNode.shared;return i?(n=s.get(r),void 0===n&&(n=new O_(e,r,this.bindingsIndexes[e].group,r),s.set(r,n))):n=new O_(e,r,this.bindingsIndexes[e].group,r),n}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const n=s[e][r];(t[r]||(t[r]=[])).push(...n)}e=[];for(const s in t){const r=t[s],n=this._getBindGroup(s,r);e.push(n)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(i)}u`:"0u";if("bool"===n)return i?"true":"false";if("color"===n)return`${this.getType("vec3")}( ${UN(i.r)}, ${UN(i.g)}, ${UN(i.b)} )`;const o=this.getTypeLength(n),a=this.getComponentType(n),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)} )`;if(3===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)} )`;if(4===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)}, ${u(i.w)} )`;if(o>4&&i&&(i.isMatrix3||i.isMatrix4))return`${this.getType(n)}( ${i.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(n)}()`;throw new Error(`NodeBuilder: Type '${n}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new k_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=MN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return BN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,n=e.normalized;let i;return e instanceof Ie||!0===n||(i=this.getTypeFromArray(s)),this.getTypeFromLength(r,i)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=fm(this.stack),this.stacks.push(Tn()||this.stack),xn(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,xn(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(void 0===r){const n=this.uniforms.index++;r=new k_("nodeAttribute"+n,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const n=this.getDataFromNode(e,s,this.globalCache);let i=n.uniform;if(void 0===i){const o=this.uniforms.index++;i=new z_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(i),n.uniform=i}return i}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const n=this.getDataFromNode(e,r);let i=n.variable;if(void 0===i){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),i=new $_(t,s),e.push(i),n.variable=i}return i}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let n=r.varying;if(void 0===n){const e=this.varyings,i=e.length;null===t&&(t="nodeVarying"+i),n=new H_(t,s),e.push(n),r.varying=n}return n}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let n=r.code;if(void 0===n){const e=this.codes[s]||(this.codes[s]=[]),i=e.length;n=new W_("nodeCode"+i,t),e.push(n),r.code=n}return n}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let n=!0,i=t;for(;i;){if(!0===r.get(i)){n=!1;break}i=this.getDataFromNode(i).parentNodeBlock}if(n)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),n=r.flowCodes||(r.flowCodes=[]),i=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);n.push(t),i.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new lx,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new pm(e.type,e.name);e.layout=null;const r=e.call(s),n=this.flowStagesNode(r,t.type);return e.layout=t,n}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,n=this.cache,i=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new q_,this.stack=fm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=n,this.stack=o,this.setBuildStage(i),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const n=this.shaderStage;this.setShaderStage(e);const i=this.flowChildNode(t,s);return null!==r&&(i.code+=`${this.tab+r} = ${i.result};\n`),this.flowCode[e]=this.flowCode[e]+i.code,this.setShaderStage(n),i}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new nh),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new sN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new rN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new nN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new iN(e);if("color"===t)return new oN(e);if("mat3"===t)return new aN(e);if("mat4"===t)return new uN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),n=this.getTypeLength(s);return 16===r&&9===n?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===n?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||n>4||0===n?e:r===n?`${this.getType(s)}( ${e} )`:r>n?this.format(`${e}.${"xyz".slice(0,n)}`,this.getTypeFromLength(n,this.getComponentType(t)),s):4===n&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&n>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class PN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class IN{constructor(e,t,s=null,r="",n=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=n}}IN.isNodeFunctionInput=!0;class LN extends _T{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=iT(this.light),n=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:n},e.stack,e)}}const DN=new i,VN=new i;let ON=null;class GN extends _T{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=ti(new s).setGroup(Zn),this.halfWidth=ti(new s).setGroup(Zn),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;VN.identity(),DN.copy(t.matrixWorld),DN.premultiply(s),VN.extractRotation(DN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(VN),this.halfHeight.value.applyMatrix4(VN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(ON.LTC_FLOAT_1),s=_u(ON.LTC_FLOAT_2)):(t=_u(ON.LTC_HALF_1),s=_u(ON.LTC_HALF_2));const{colorNode:r,light:n}=this,i=e.context.lightingModel,o=nT(n),a=e.context.reflectedLight;i.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){ON=e}}class kN extends _T{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=ti(0).setGroup(Zn),this.penumbraCosNode=ti(0).setGroup(Zn),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:n,light:i}=this,o=nT(i).sub(el),a=o.normalize(),u=a.dot(iT(i)),l=this.getSpotAttenuation(u),d=o.length(),c=NT({lightDistance:d,cutoffDistance:r,decayExponent:n}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class zN extends kN{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,En(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class $N extends _T{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class HN extends _T{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=sT(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=ti(new e).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:r}=this,n=ul.dot(r).mul(.5).add(.5),i=la(s,t,n);e.context.irradiance.addAssign(i)}}class WN extends _T{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=I_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class jN{parseFunction(){console.warn("Abstract function.")}}class qN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}qN.isNodeFunction=!0;const KN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,XN=/[a-z_0-9]+/gi,YN="#pragma main";class QN extends qN{constructor(e){const{type:t,inputs:s,name:r,precision:n,inputsCode:i,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(YN),s=-1!==t?e.slice(t+12):e,r=s.match(KN);if(null!==r&&5===r.length){const n=r[4],i=[];let o=null;for(;null!==(o=XN.exec(n));)i.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Jp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=Sh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Zn),r=Ml("density","float",s).setGroup(Zn);e=Ax(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Zn),r=Ml("near","float",s).setGroup(Zn),n=Ml("far","float",s).setGroup(Zn);e=vx(t,r,n)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,n=null){const i=this.nodeFrame;return i.renderer=e,i.scene=t,i.object=s,i.camera=r,i.material=n,i}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return JN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return JN.set(e,s),r}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new PN,this.nodeBuilderCache=new Map}}const tv=new me;class sv{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new n,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let n=0;n{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),n=this._renderContexts.get(e,t,this._renderTarget),i=e.overrideMaterial||s.material,o=this._objects.get(s,i,e,t,r.lightsNode,n,n.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ev(this,s),this._animation=new Bg(this._nodes,this.info),this._attributes=new $g(s),this._background=new D_(this,this._nodes),this._geometries=new jg(this._attributes,this.info),this._textures=new cm(this,s,this.info),this._pipelines=new Jg(s,this._nodes),this._bindings=new em(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Lg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new im(this.lighting),this._bundles=new nv,this._renderContexts=new lm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,n=r.renderId,i=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:uv;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new sv),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=n,this._currentRenderContext=i,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:n,renderList:i}=e,o=this._currentRenderContext,a=this._bundles.get(r,n),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=i.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,n,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(dv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(dv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new sv),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),hv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),cv.setFromProjectionMatrix(hv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),n.renderId=i,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,r){const n=this._scissor;e.isVector4?n.copy(e):n.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,n=0,i=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=n,o.maxDepth=i}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let n=null;if(null!==r&&(this._textures.updateRenderTarget(r),n=this._textures.get(r)),this.backend.clear(e,t,s,n),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const r=this.backend,n=this._pipelines,i=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===n.has(t)){const e=()=>{t.removeEventListener("dispose",e),n.delete(t),i.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),i.updateForCompute(t);const s=i.getForCompute(t),a=n.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=pv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=pv.copy(t).floor()}else t=pv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,n)}readRenderTargetPixelsAsync(e,t,s,r,n,i=0,o=0){return this.backend.copyTextureToBuffer(e.textures[i],t,s,r,n,o)}_projectObject(e,t,s,r,n){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(n=n.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||cv.intersectsSprite(e)){!0===this.sortObjects&&pv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(hv);const{geometry:t,material:i}=e;i.visible&&r.push(e,t,i,s,pv.z,null,n)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||cv.intersectsObject(e))){const{geometry:t,material:i}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),pv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(hv)),Array.isArray(i)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,n,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,n);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,n)}_renderObjects(e,t,s,r,n=null){for(let i=0,o=e.length;i0?r:"";t=`${e.name} {\n\t${s} ${n.name}[${i}];\n};\n`}else{t=`${this.getVectorType(n.type)} ${this.getPropertyName(n,e)};`,i=!0}const o=n.node.precision;if(null!==o&&(t=wv[o]+" "+t),i){t="\t"+t;const e=n.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let n="";for(const t in r){const s=r[t];n+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return n+=s.join("\n"),n}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Mv[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Mv[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${i}\n\t`),s+=`${r.code}\n\t`,e===n&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const i=e[t];i.extensions=this.getExtensions(t),i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.vars=this.getVars(t),i.structs=this.getStructs(t),i.codes=this.getCodes(t),i.transforms=this.getTransforms(t),i.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);let o=i.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new Av(n.name,n.node,r),u.push(o);else if("cubeTexture"===t)o=new Rv(n.name,n.node,r),u.push(o);else if("texture3D"===t)o=new Cv(n.name,n.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,n.name=`buffer${e.id}`;const t=new xv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Nv(s+"_"+a,r),e[a]=i,u.push(i)),o=this.getNodeUniform(n,t),i.addUniform(o)}i.uniformGPU=o}return n}}let Fv=null,Pv=null,Iv=null;class Lv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Fv=Fv||new t,this.renderer.getDrawingBufferSize(Fv)}getScissor(){return Pv=Pv||new r,this.renderer.getScissor(Pv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Iv=Iv||new hm,e.getClearColor(Iv),Iv.getRGB(Iv,this.renderer.currentColorSpace),Iv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Dv=0;class Vv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Ov{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,n=e.array,i=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,n,i),a.bufferGPU=l,a.bufferType=t,a.version=o.version),n instanceof Float32Array)u=r.FLOAT;else if(n instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(n instanceof Int16Array)u=r.SHORT;else if(n instanceof Uint32Array)u=r.UNSIGNED_INT;else if(n instanceof Int32Array)u=r.INT;else if(n instanceof Int8Array)u=r.BYTE;else if(n instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Dv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,n,i);d=new Vv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,n=e.isInterleavedBufferAttribute?e.data:e,i=t.get(n),o=i.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,i.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t{!function n(){const i=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(i===e.WAIT_FAILED)return e.deleteSync(t),void r();i!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(n)}()}))}}let Wv,jv,qv,Kv=!1;class Xv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===Kv&&(this._init(this.gl),Kv=!0)}_init(e){Wv={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},jv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},qv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,n=!1){const{gl:i,extensions:o}=this;if(null!==e){if(void 0!==i[e])return i[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===i.RED&&(s===i.FLOAT&&(a=i.R32F),s===i.HALF_FLOAT&&(a=i.R16F),s===i.UNSIGNED_BYTE&&(a=i.R8),s===i.UNSIGNED_SHORT&&(a=i.R16),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RED_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.R8UI),s===i.UNSIGNED_SHORT&&(a=i.R16UI),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RG&&(s===i.FLOAT&&(a=i.RG32F),s===i.HALF_FLOAT&&(a=i.RG16F),s===i.UNSIGNED_BYTE&&(a=i.RG8),s===i.UNSIGNED_SHORT&&(a=i.RG16),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RG_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RG8UI),s===i.UNSIGNED_SHORT&&(a=i.RG16UI),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RGB&&(s===i.FLOAT&&(a=i.RGB32F),s===i.HALF_FLOAT&&(a=i.RGB16F),s===i.UNSIGNED_BYTE&&(a=i.RGB8),s===i.UNSIGNED_SHORT&&(a=i.RGB16),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8:i.RGB8),s===i.UNSIGNED_SHORT_5_6_5&&(a=i.RGB565),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGB4),s===i.UNSIGNED_INT_5_9_9_9_REV&&(a=i.RGB9_E5)),t===i.RGB_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGB8UI),s===i.UNSIGNED_SHORT&&(a=i.RGB16UI),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I)),t===i.RGBA&&(s===i.FLOAT&&(a=i.RGBA32F),s===i.HALF_FLOAT&&(a=i.RGBA16F),s===i.UNSIGNED_BYTE&&(a=i.RGBA8),s===i.UNSIGNED_SHORT&&(a=i.RGBA16),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8_ALPHA8:i.RGBA8),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGBA4),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1)),t===i.RGBA_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGBA8UI),s===i.UNSIGNED_SHORT&&(a=i.RGBA16UI),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I)),t===i.DEPTH_COMPONENT&&(s===i.UNSIGNED_INT&&(a=i.DEPTH24_STENCIL8),s===i.FLOAT&&(a=i.DEPTH_COMPONENT32F)),t===i.DEPTH_STENCIL&&s===i.UNSIGNED_INT_24_8&&(a=i.DEPTH24_STENCIL8),a!==i.R16F&&a!==i.R32F&&a!==i.RG16F&&a!==i.RG32F&&a!==i.RGBA16F&&a!==i.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:n}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,Wv[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,Wv[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,Wv[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,jv[t.magFilter]);const i=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&i?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,jv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,qv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const i=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,n.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,n=this.getGLTextureType(e);let i=r[n];void 0===i&&(i=t.createTexture(),s.state.bindTexture(n,i),t.texParameteri(n,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(n,t.TEXTURE_MAG_FILTER,t.NEAREST),r[n]=i),s.set(e,{textureGPU:i,glTextureType:n,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:n,width:i,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,n,d,i,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,n,d,i,o,a):e.isVideoTexture||s.texStorage2D(h,n,d,i,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:n,glTextureType:i,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(i,n),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(i,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:n}=t,{textureGPU:i,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===i)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,i),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,n=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;n.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),n.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),n.bindFramebuffer(r.READ_FRAMEBUFFER,s),n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),n.unbindTexture()}else{const e=r.createFramebuffer();n.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,i,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),n.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:n,depthTexture:i,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;n>0?(i&&i.isDepthTexture&&i.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,n,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(n>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,n,i){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+i:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*n*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,n,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let r=0;return e===s.UNSIGNED_BYTE&&(r=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Yv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Qv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const Zv={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class Jv{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:r,object:n,type:i,info:o,index:a}=this;0!==a?s.drawElements(r,t,i,e):s.drawArrays(r,e,t),o.update(n,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:n,type:i,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(n,t,i,e,s):r.drawArraysInstanced(n,e,t,s),u.update(a,t,n,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:n,object:i,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),n=r.previousContext,i=e.occlusionQueryCount;i>0&&(i>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const n=r.framebuffers[e.getCacheKey()],i=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,n);for(let s=0;s{let o=0;for(let t=0;t0&&e.add(r[t]),s[t]=null,n.deleteQuery(i),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Uv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,n="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(n,r),t.compileShader(n),this.set(e,{shaderGPU:n})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:n,vertexProgram:i}=r,o=s.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const n=new Promise((t=>{const n=this.parallel,i=()=>{s.getProgramParameter(o,n.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(i)};i()}));t.push(n)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],n=Math.max(t-6,0),i=Math.min(t+6,s.length);for(let e=n;e":" "} ${n}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),n=e.getShaderInfoLog(t).trim();if(r&&""===n)return"";const i=/ERROR: 0:(\d+)/.exec(n);if(i){const r=parseInt(i[1]);return s.toUpperCase()+"\n\n"+n+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return n}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,n=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const i=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+n+"\n"+i+"\n"+o)}else""!==n&&console.warn("THREE.WebGLProgram: Program Info Log:",n)}}_completeCompile(e,t){const{state:s,gl:r}=this,n=this.get(t),{programGPU:i,fragmentShader:o,vertexShader:a}=n;!1===r.getProgramParameter(i,r.LINK_STATUS)&&this._logProgramError(i,o,a),s.useProgram(i);const u=e.getBindings();this._setupBindings(u,i),this.set(t,{programGPU:i})}createComputePipeline(e,t){const{state:s,gl:r}=this,n={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(n);const{computeProgram:i}=e,o=r.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU,l=i.transforms,d=[],c=[];for(let e=0;eZv[t]===e)),s=this.extensions;for(let e=0;e0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const n=[],l=e.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Wf,stripIndexFormat:uy},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Wf,stripIndexFormat:uy},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:n,height:i}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:n,height:i,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),n=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),i=c.beginRenderPass({colorAttachments:[{view:s,loadOp:sy,storeOp:ey,clearValue:[0,0,0,0]}]});i.setPipeline(e),i.setBindGroup(0,n),i.draw(4,1,0,0),i.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const n=r.layers[s]||this._mipmapCreateBundles(e,t,s),i=this.device.createCommandEncoder({});this._mipmapRunBundles(i,n),this.device.queue.submit([i.finish()]),0!==r.useCount&&(r.layers[s]=n),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),n=r.getBindGroupLayout(0);let i=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:s});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,hS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,pS={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class gS extends qN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:n,blockCode:i,outputType:o}=(e=>{const t=(e=e.trim()).match(cS);if(null!==t&&4===t.length){const s=t[2],r=[];let n=null;for(;null!==(n=hS.exec(s));)r.push({name:n[1],type:n[2]});const i=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class mS extends jN{parseFunction(e){return new gS(e)}}const fS=self.GPUShaderStage,yS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},bS={vertex:fS?fS.VERTEX:1,fragment:fS?fS.FRAGMENT:2,compute:fS?fS.COMPUTE:4},xS={instance:!0,swizzleAssign:!1,storageBuffer:!0},TS={"^^":"tsl_xor"},_S={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},NS={},vS={tsl_xor:new nx("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new nx("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new nx("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new nx("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new nx("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new nx("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new nx("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new nx("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new nx("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new nx("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new nx("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new nx("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new nx("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new nx("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},SS={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(vS.pow_float=new nx("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),vS.pow_vec2=new nx("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[vS.pow_float]),vS.pow_vec3=new nx("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[vS.pow_float]),vS.pow_vec4=new nx("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[vS.pow_float]),SS.pow_float="tsl_pow_float",SS.pow_vec2="tsl_pow_vec2",SS.pow_vec3="tsl_pow_vec3",SS.pow_vec4="tsl_pow_vec4");let AS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(AS+="diagnostic( off, derivative_uniformity );\n");class RS extends FN{constructor(e,t){super(e,t,new mS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,n=this.shaderStage){return"fragment"===n?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,r,n,i=this.shaderStage){return"fragment"===i&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${yS[e.wrapS]}S_${yS[e.wrapT]}T`;let s=NS[t];if(void 0===s){const r=[];let n=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const i=(e,t)=>{e===ls?(r.push(vS.repeatWrapping_float),n+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(r.push(vS.clampWrapping_float),n+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(r.push(vS.mirrorWrapping_float),n+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(n+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};i(e.wrapS,"x"),n+=",\n",i(e.wrapT,"y"),n+="\n\t);\n\n}\n",NS[t]=s=new nx(n,r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let n=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(n=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${n} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=n),n}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,n="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${n} )`:`textureLoad( ${t}, ${s}, ${n} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,n=this.shaderStage){let i=null;return i=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,n):this._generateTextureSample(e,t,s,r,n),i}generateTextureGrad(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${i} shader.`)}generateTextureCompare(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${i} shader.`)}generateTextureLevel(e,t,s,r,n,i=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this._generateTextureSampleLevel(e,t,s,r,n,i),o}generateTextureBias(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${i} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=TS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case jy:return"read";case Wy:return"write";default:return"read_write"}else switch(e.access){case $y:return"read_write";case Hy:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);if(void 0===i.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let i=null;if("texture"===t||"storageTexture"===t?i=new Av(n.name,n.node,o,e.access?e.access:null):"cubeTexture"===t?i=new Rv(n.name,n.node,o,e.access?e.access:null):"texture3D"===t&&(i=new Cv(n.name,n.node,o,e.access?e.access:null)),i.store=!0===e.isStorageTextureNode,i.setVisibility(bS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===i.store){const e=new sS(`${n.name}_sampler`,n.node,o);e.setVisibility(bS[s]),u.push(e,i),r=[e,i]}else u.push(i),r=[i]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const n=new("buffer"===t?xv:iS)(e,o);n.setVisibility(bS[s]),u.push(n),r=n}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Nv(a,o),i.setVisibility(bS[s]),e[a]=i,u.push(i)),r=this.getNodeUniform(n,t),i.addUniform(r)}i.uniformGPU=r}return n}getBuiltin(e,t,s,r=this.shaderStage){const n=this.builtins[r]||(this.builtins[r]=new Map);return!1===n.has(e)&&n.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let n=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(n+=`\treturn ${s.result};\n`),n+="\n}\n",n}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:n}of s.values())t.push(`@builtin( ${e} ) ${r} : ${n}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:n}of this.scopedArrays.values()){const i=this.getType(r);t.push(`var<${s}> ${e}: array< ${i}, ${n} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e{const{name:t,node:r}=e,n=!0===r.bufferStruct;s.set(t,n)})),s}getMembersFromCustomStruct(e){return`\t${e.map((({name:e,type:t,isAtomic:s})=>{let r=_S[t];return r||(console.warn(`Unrecognized type: ${t}`),r="vec4"),`${e}: ${s?`atomic<${r}>`:r}`})).join(",\n\t")}`}getCustomStructNameFromShader(e){const t=/fn\s+\w+\s*\(([\s\S]*?)\)/g,s=/(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g,r=[];let n;for(;null!==(n=t.exec(e));){const e=n[1];let t;for(;null!==(t=s.exec(e));){const[e,s,n,i,o,a]=t,u=o||a||null,l=i||n;Object.values(_S).includes(u)||null===u||r.push({name:s,type:l,structName:u})}}return r}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;e`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e output : ${n};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let n=0;n";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array";else if(!0===t.isDepthTexture)r=`texture_depth${i}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d";else if(!0===n.node.isStorageTextureNode){r=`texture_storage_2d<${dS(t)}, ${this.getStorageAccess(n.node)}>`}else{r=`texture${i}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name} : ${r};`)}else if("buffer"===n.type||"storageBuffer"===n.type||"indirectStorageBuffer"===n.type){const e=n.node,t=this.getType(e.bufferType),s=e.bufferCount,i=e.value.array.length!==e.value.itemSize,a=s>0&&"buffer"===n.type?", "+s:"",u=e.isAtomic?`atomic<${t}>`:`${t}`,l=e.bufferStruct?this.getMembersFromCustomStruct(t):`\t${n.name} : array< ${u}${a} >\n`,d=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding(e.bufferStruct,i,"NodeBuffer_"+e.id,l,d,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(n.type)),t=n.groupNode.name;(i[t]||(i[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${n.name} : ${e}`)}}for(const e in i){const t=i[e];n.push(this._getWGSLStructBinding(!1,!1,e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=n.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t),s.isBufferStruct=this.getTypeFromCustomStruct(t),s.customStructNames=this.getCustomStructNameFromShader(s.codes);const r=e=>e.replace(/&(\w+)\.(\w+)/g,((e,t,r)=>!0===s.isBufferStruct.get(r)?`&${t}`:e)),n=e=>{const t=e.match(/\(([^)]+)\)/);if(!t)return[];return t[1].split(/\s*,\s*/).map((e=>e.trim())).filter((e=>e.includes("&"))).map((e=>e.replace("&",""))).filter((e=>!e.includes(".")))},i=(e,t)=>{const s=new Map;for(let r=0;r{for(const[s,r]of t.entries()){const t=new RegExp(`\\b${s}Struct\\b`,"g");e=e.replace(t,r)}return e};let a,u,l="// code\n\n";l+=this.flowCode[t];const d=this.flowNodes[t],c=d[d.length-1],h=c.outputNode,p=void 0!==h&&!0===h.isOutputStructNode;for(const e of d){const d=this.getFlowData(e),g=e.name;if(g&&(l.length>0&&(l+="\n"),l+=`\t// flow -> ${g}\n\t`),l+=`${d.code}\n\t`,l=r(l),a=n(l),u=i(a,s.customStructNames),s.uniforms=o(s.uniforms,u),e===c&&"compute"!==t){if(l+="// result\n\n\t","vertex"===t)l+=`varyings.Vertex = ${d.result};`;else if("fragment"===t)if(p)s.returnType=h.nodeType,l+=`return ${d.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar output : OutputStruct;\n\n",l+=`output.color = ${d.result};\n\n\treturn output;`}l=r(l),a=n(l),u=i(a,s.customStructNames),s.uniforms=o(s.uniforms,u)}}s.flow=l}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return _S[e]||e}isAvailable(e){let t=xS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),xS[e]=t),t}_getWGSLMethod(e){return void 0!==vS[e]&&this._include(e),SS[e]}_include(e){const t=vS[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${AS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r,n,i=0,o=0){const a=s+"Struct",u=this._getWGSLStruct(a,r);if(e){return`${u}\n@binding( ${i} ) @group( ${o} )\nvar<${n}> ${s} : ${t?`array<${a}>`:a};`}return`${u}\n@binding( ${i} ) @group( ${o} )\nvar<${n}> ${s} : ${a};`}}class CS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=ly.Depth24PlusStencil8:e.depth&&(t=ly.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?kf:e.isLineSegments||e.isMesh&&!0===t.wireframe?zf:e.isLine?$f:e.isMesh?Hf:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?ly.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const ES=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),wS=new Map([[Ie,["float16"]]]),MS=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class BS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,n=r.get(s);let i=n.buffer;if(void 0===i){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[s]===r&&(a=o.groups[s])),void 0===a&&(a=this.createBindGroup(e,u),s>0&&(o.groups[s]=a,o.versions[s]=r)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,n=t.get(e).buffer;s.queue.writeBuffer(n,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let n=0;const i=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,n=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,i=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:n});e.buffer=i}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);i.push({binding:n,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const n=nb;let i;i=t.isSampledCubeTexture?sb:t.isSampledTexture3D?rb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?tb:eb,o=e[r]=e.texture.createView({aspect:n,dimension:i,mipLevelCount:s})}}i.push({binding:n,resource:o})}n++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:i})}}class FS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:n,pipeline:i}=e,{vertexProgram:o,fragmentProgram:a}=i,u=this.backend,l=u.device,d=u.utils,c=u.get(i),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,n=s.getCurrentDepthStencilFormat(e),i={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:n,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(i)}createComputePipeline(e,t){const s=this.backend,r=s.device,n=s.get(e.computeProgram).module,i=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}i.pipeline=r.createComputePipeline({compute:n,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,n=e.blendSrc,i=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:n,a=null!==e.blendDstAlpha?e.blendDstAlpha:i,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(n),dstFactor:this._getBlendFactor(i),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const n=(e,r,n,i)=>{t={srcFactor:e,dstFactor:r,operation:Ey},s={srcFactor:n,dstFactor:i,operation:Ey}};if(e.premultipliedAlpha)switch(r){case F:n(fy,Ty,fy,Ty);break;case bt:n(fy,fy,fy,fy);break;case yt:n(my,by,my,fy);break;case ft:n(my,yy,my,xy)}else switch(r){case F:n(xy,Ty,fy,Ty);break;case bt:n(xy,fy,xy,fy);break;case yt:n(my,by,my,fy);break;case ft:n(my,yy,my,yy)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=my;break;case st:t=fy;break;case rt:t=yy;break;case ut:t=by;break;case nt:t=xy;break;case lt:t=Ty;break;case ot:t=_y;break;case dt:t=Ny;break;case at:t=vy;break;case ct:t=Sy;break;case it:t=Ay;break;case 211:t=Ry;break;case 212:t=Cy;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=jf;break;case Es:t=Jf;break;case Cs:t=qf;break;case Rs:t=Xf;break;case As:t=Kf;break;case Ss:t=Zf;break;case vs:t=Yf;break;case Ns:t=Qf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Iy;break;case Ls:t=Ly;break;case Is:t=Dy;break;case Ps:t=Vy;break;case Fs:t=Oy;break;case Us:t=Gy;break;case Bs:t=ky;break;case Ms:t=zy;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Ey;break;case Je:t=wy;break;case et:t=My;break;case Os:t=By;break;case Vs:t=Uy;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},n=this.backend.utils;switch(r.topology=n.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?ay:uy),s.side){case Oe:r.frontFace=ry,r.cullMode=oy;break;case x:r.frontFace=ry,r.cullMode=iy;break;case le:r.frontFace=ry,r.cullMode=ny;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Py:Fy}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Jf;else{const s=e.depthFunc;switch(s){case Rt:t=jf;break;case At:t=Jf;break;case St:t=qf;break;case vt:t=Xf;break;case Nt:t=Kf;break;case _t:t=Zf;break;case Tt:t=Yf;break;case xt:t=Qf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class PS extends Lv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new CS(this),this.attributeUtils=new BS(this),this.bindingUtils=new US(this),this.pipelineUtils=new FS(this),this.textureUtils=new lS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const n=Object.values(ab),i=[];for(const e of n)r.features.has(e)&&i.push(e);const o={requiredFeatures:i,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const n=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ab.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:n}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const n=e.getCacheKey();let i=r[n];if(void 0===i){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,n=s.createQuerySet({type:"occlusion",count:r,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=n,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),i=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,i),i.occlusionQuerySet=n;const o=i.depthStencilAttachment;if(null!==e.textures){const t=i.colorAttachments;for(let s=0;s0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const r=8*s;let n=this.occludedResolveCache.get(r);void 0===n&&(n=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,n));const i=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,n,0),t.encoder.copyBufferToBuffer(n,0,i,0,r),t.occlusionQueryBuffer=i,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,n.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:r,pipeline:n}=e,i=e.getBindings(),o=this.get(r),a=this.get(n).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=i.length;e1?0:s;l.drawIndexed(t[s],r,e[s]/i,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,n,i,0,0);t.update(s,r,n)}else{const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,n,i,0);t.update(s,r,n)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,n=this.utils,i=n.getSampleCountRenderContext(e.context),o=n.getCurrentColorSpace(e.context),a=n.getCurrentColorFormat(e.context),u=n.getCurrentDepthStencilFormat(e.context),l=n.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===i&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=i,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,n=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,r.getSampleCountRenderContext(n),r.getCurrentColorSpace(n),r.getCurrentColorFormat(n),r.getCurrentDepthStencilFormat(n),r.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}async initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){this.device.pushErrorScope("out-of-memory");const r=await this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_renderContext_${e.id}`});if(await this.device.popErrorScope())return s.attemptingTimeStampQuerySetFailed||(console.error(`[GPUOutOfMemoryError][renderContext_${e.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.`),s.attemptingTimeStampQuerySetFailed=!0),void(s.timeStampQuerySet=null);const n={querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:n}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;const r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:n,resultBuffer:i,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,n,0),t.copyBufferToBuffer(n,0,i,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:n}=s.currentTimestampQueryBuffers;!0!==n&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),n=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,n),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new RS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,r=null,n=0){let i=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(i=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:n,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:n,origin:{x:i,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let n=null;n=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const i=this.get(e).texture;if(n.format!==i.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,i.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:n,origin:{x:s.x,y:s.y,z:0}},{texture:i},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new eS(e)));super(new t(e),e),this.library=new LS,this.isWebGPURenderer=!0}}class VS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const OS=new nh,GS=new _f(OS);class kS{constructor(e,t=Ln(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,OS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,GS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;GS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),GS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await GS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function zS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function $S(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function HS(e,t,s={}){return(s=zS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var WS=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=HS(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=zS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){$S(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:$S,saveRendererAndSceneState:HS,saveRendererState:zS});class jS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class qS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class KS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class XS extends qS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class YS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const n=new tr(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),Sn()):hn(new this.nodes[e])}}class QS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const n=r[e];t[e]=s[n]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class ZS extends rr{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new YS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),n=new QS;n.setTextures(t),n.setNodes(r),n.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t { + + return Object.entries( members ).map( ( [ name, value ] ) => { + + if ( typeof value === 'string' ) { + + return { name, type: value, isAtomic: false }; + + } + + return { name, type: value.type, isAtomic: value.atomic || false }; + + } ); + +}; + class OutputStructNode extends Node { static get type() { @@ -17974,6 +17990,7 @@ class StorageBufferNode extends BufferNode { this.isAtomic = false; this.bufferObject = false; + this.bufferStruct = false; this.bufferCount = bufferCount; this._attribute = null; @@ -18036,6 +18053,14 @@ class StorageBufferNode extends BufferNode { } + setBufferStruct( value ) { + + this.bufferStruct = value; + + return this; + + } + setAccess( value ) { this.access = value; @@ -18116,6 +18141,7 @@ class StorageBufferNode extends BufferNode { // Read-Write Storage const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) ); +const storageStruct = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferStruct( true ) ); const storageObject = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferObject( true ) ); class StorageTextureNode extends TextureNode { @@ -38037,6 +38063,88 @@ ${ flowData.code } } + getTypeFromCustomStruct( shaderStage ) { + + const uniforms = this.uniforms[ shaderStage ]; + + const bufferStructMap = new Map(); + + uniforms.forEach( ( uniform ) => { + + const { name, node } = uniform; + const hasBufferStruct = node.bufferStruct === true; + bufferStructMap.set( name, hasBufferStruct ); + + } ); + + return bufferStructMap; + + } + + getMembersFromCustomStruct( members ) { + + const structMembers = members.map( ( { name, type, isAtomic } ) => { + + let finalType = wgslTypeLib[ type ]; + + if ( ! finalType ) { + + console.warn( `Unrecognized type: ${type}` ); + finalType = 'vec4'; + + } + + return `${name}: ${isAtomic ? `atomic<${finalType}>` : finalType}`; + + } ); + + return `\t${structMembers.join( ',\n\t' )}`; + + } + + getCustomStructNameFromShader( source ) { + + const functionRegex = /fn\s+\w+\s*\(([\s\S]*?)\)/g; // filter shader header + const parameterRegex = /(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g; // filter parameters + + const results = []; + + let match; + + while ( ( match = functionRegex.exec( source ) ) !== null ) { + + const parameterString = match[ 1 ]; + + let paramMatch; + + while ( ( paramMatch = parameterRegex.exec( parameterString ) ) !== null ) { + + const [ fullMatch, name, fullType, ptrType, arrayType, directStructName ] = paramMatch; + + const structName = arrayType || directStructName || null; + + const type = ptrType || fullType; + + if (Object.values(wgslTypeLib).includes(structName) || structName === null) { + + continue; + + } + + results.push( { + name, + type, + structName + } ); + + } + + } + + return results; + + } + getStructMembers( struct ) { const snippets = []; @@ -38244,12 +38352,14 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; + + const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; - const bufferSnippet = `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; + const bufferSnippet = bufferNode.bufferStruct ? this.getMembersFromCustomStruct( bufferType ) : `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform'; - bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); + bufferSnippets.push( this._getWGSLStructBinding( bufferNode.bufferStruct, isArray, 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); } else { @@ -38272,7 +38382,7 @@ ${ flowData.code } const group = uniformGroups[ name ]; - structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); + structSnippets.push( this._getWGSLStructBinding( false, false, name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); } @@ -38301,9 +38411,69 @@ ${ flowData.code } stageData.codes = this.getCodes( shaderStage ); stageData.directives = this.getDirectives( shaderStage ); stageData.scopedArrays = this.getScopedArrays( shaderStage ); + stageData.isBufferStruct = this.getTypeFromCustomStruct( shaderStage ); + stageData.customStructNames = this.getCustomStructNameFromShader( stageData.codes ); // + const reduceFlow = ( flow ) => { + + return flow.replace( /&(\w+)\.(\w+)/g, ( match, bufferName, uniformName ) => + + stageData.isBufferStruct.get( uniformName ) === true ? `&${bufferName}` : match + + ); + + }; + + const extractPointerNames = ( source ) => { + + const match = source.match( /\(([^)]+)\)/ ); + if ( ! match ) return []; + + const content = match[ 1 ]; + + return content + .split( /\s*,\s*/ ) + .map( part => part.trim() ) + .filter( part => part.includes( '&' ) ) + .map( part => part.replace( '&', '' ) ) + .filter( part => ! part.includes( '.' ) ); + + }; + + const createStructNameMapping = ( nodeBuffers, structs ) => { + + const resultMap = new Map(); + + for (let i = 0; i < nodeBuffers.length; i++) { + + const bufferName = nodeBuffers[i]; + const struct = structs[i]; + + resultMap.set(bufferName, struct.structName); + + } + + return resultMap; + + }; + + const replaceStructNamesInUniforms = ( shaderCode, map ) => { + + for ( const [ key, value ] of map.entries() ) { + + const regex = new RegExp( `\\b${key}Struct\\b`, 'g' ); + shaderCode = shaderCode.replace( regex, value ); + + } + + return shaderCode; + + }; + + + let pointerNames, structnameMapping; let flow = '// code\n\n'; flow += this.flowCode[ shaderStage ]; @@ -38328,6 +38498,68 @@ ${ flowData.code } flow += `${ flowSlotData.code }\n\t`; + + /* + REVIEW COMMENT remove after review + + before reduceFlow: + compute( &NodeBuffer_554.nodeUniform0, &NodeBuffer_558.nodeUniform1, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); + + after reduceFlow: reduceFlow checks whether there is a storageStruct and if so then the + postfix is ​​removed so that the pointer points to the struct and not to a content in the struct + compute( &NodeBuffer_554, &NodeBuffer_558, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); + + extractPointerNames reads the names of the reduced pointers and stores them in an array + Array(2) + 0: "NodeBuffer_554" + 1: "NodeBuffer_558" + + getCustomStructNameFromShader at the beginning reads the structNames from the shader header + Array(2) + 0: {name: 'drawBuffer', type: 'storage', structName: 'DrawBuffer'} + 1: {name: 'meshletInfo', type: 'storage', structName: 'MeshletInfo'} + + + createStructNameMapping links the automatic generated WGSLNodeBuilder for each struct with the struct name specified by the user. + This is necessary because in wgslFn the user can choose any name in the shader in ptr for structs. + + Map(2) + [[Entries]] + 0: {"NodeBuffer_554" => "DrawBuffer"} + 1: {"NodeBuffer_558" => "MeshletInfo"} + + replaceStructNames then replaces the names in the uniforms in the custom structs that the WGSLNodeBuilder + created with the name chosen by the user. + + before replaceStructNames: + + struct NodeBuffer_554Struct { + vertexCount: u32, + instanceCount: u32, + firstVertex: u32, + firstInstance: u32 + }; + @binding( 0 ) @group( 0 ) + var NodeBuffer_554 : NodeBuffer_554Struct; + + after replaceStructNames: + + struct DrawBuffer { + vertexCount: u32, + instanceCount: u32, + firstVertex: u32, + firstInstance: u32 + }; + @binding( 0 ) @group( 0 ) + var NodeBuffer_554 : DrawBuffer; + */ + + + flow = reduceFlow( flow ); + pointerNames = extractPointerNames(flow); + structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); + stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); + if ( node === mainNode && shaderStage !== 'compute' ) { flow += '// result\n\n\t'; @@ -38362,6 +38594,11 @@ ${ flowData.code } } + flow = reduceFlow( flow ); + pointerNames = extractPointerNames(flow); + structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); + stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); + } } @@ -38566,15 +38803,27 @@ ${vars} } - _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) { + _getWGSLStructBinding( isBufferStruct, isArray, name, vars, access, binding = 0, group = 0 ) { const structName = name + 'Struct'; const structSnippet = this._getWGSLStruct( structName, vars ); - return `${structSnippet} + if ( ! isBufferStruct ) { + + return `${structSnippet} @binding( ${binding} ) @group( ${group} ) var<${access}> ${name} : ${structName};`; + } else { + + const StructName = isArray ? `array<${structName}>` : structName; + + return `${structSnippet} +@binding( ${binding} ) @group( ${group} ) +var<${access}> ${name} : ${StructName};`; + + } + } } @@ -42181,4 +42430,4 @@ class ClippingGroup extends Group { } -export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BRDF_GGX, BRDF_Lambert, BackSide, BasicEnvironmentNode, BatchNode, BoxGeometry, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DFGApprox, D_GGX, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, Discard, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EPSILON, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, F_Schlick, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fn, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, If, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, 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, Loader, Loop, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap$1 as PCFShadowMap, PI, PI2, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, 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_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScreenNode, ScriptableNode, ScriptableNodeResources, ScriptableValueNode, SetNode, ShaderNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, abs, acesFilmicToneMapping, acos, add, addMethodChaining, addNodeElement, agxToneMapping, all, alphaT, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, atomicAdd, atomicAnd, atomicFunc, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, attenuationColor, attenuationDistance, attribute, backgroundBlurriness, backgroundIntensity, backgroundRotation, batch, billboarding, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blendNormal, blur, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, cdl, ceil, checker, cineonToneMapping, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToWorking, colorToDirection, compute, cond, context, convert, convertColorSpace, convertToTexture, cos, createCanvasElement, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, deltaTime, densityFog, depth, depthPass, difference, diffuseColor, directPointLight, directionToColor, dispersion, distance, div, dodge, dot, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getNormalFromDepth, getParallaxCorrectNormal, getRoughness, getScreenPosition, getShIrradianceAt, getTextureIndex, getViewPosition, glsl, glslFn, grayscale, greaterThan, greaterThanEqual, hash, highPrecisionModelNormalViewMatrix, highPrecisionModelViewMatrix, hue, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, invocationLocalIndex, invocationSubgroupIndex, ior, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightPosition, lightTargetDirection, lightTargetPosition, lightViewPosition, lightingContext, lights, linearDepth, linearToneMapping, localId, log, log2, logarithmicDepthToViewZ, loop, luminance, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialAttenuationColor, materialAttenuationDistance, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIOR, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRefractionRatio, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularColor, materialSpecularIntensity, materialSpecularStrength, materialThickness, materialTransmission, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mixElement, mod, modInt, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, neutralToneMapping, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalFlat, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, notEqual, numWorkgroups, objectDirection, objectGroup, objectPosition, objectScale, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionPrevious, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, reinhardToneMapping, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rotate, rotateUV, roughness, round, rtt, sRGBTransferEOTF, sRGBTransferOETF, sampler, saturate, saturation, screen, screenCoordinate, screenSize, screenUV, scriptable, scriptableValue, select, setCurrentStack, shaderStages, shadow, sharedUniformGroup, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, smoothstepElement, specularColor, specularF90, spherizeUV, split, spritesheetUV, sqrt, stack, step, storage, storageBarrier, storageObject, storageTexture, string, sub, subgroupIndex, subgroupSize, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBarrier, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, thickness, threshold, time, timerDelta, timerGlobal, timerLocal, toOutputColorSpace, toWorkingColorSpace, toneMapping, toneMappingExposure, toonOutlinePass, transformDirection, transformNormal, transformNormalToView, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transmission, transpose, tri, tri3, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, uniform, uniformArray, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, velocity, vertexColor, vertexIndex, vibrance, viewZToLogarithmicDepth, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSafeUV, viewportSharedTexture, viewportSize, viewportTexture, viewportTopLeft, viewportUV, wgsl, wgslFn, workgroupArray, workgroupBarrier, workgroupId, workingToColorSpace, xor }; +export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BRDF_GGX, BRDF_Lambert, BackSide, BasicEnvironmentNode, BatchNode, BoxGeometry, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DFGApprox, D_GGX, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, Discard, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EPSILON, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, F_Schlick, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fn, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, If, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, 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, Loader, Loop, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap$1 as PCFShadowMap, PI, PI2, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, 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_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScreenNode, ScriptableNode, ScriptableNodeResources, ScriptableValueNode, SetNode, ShaderNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, abs, acesFilmicToneMapping, acos, add, addMethodChaining, addNodeElement, agxToneMapping, all, alphaT, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, atomicAdd, atomicAnd, atomicFunc, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, attenuationColor, attenuationDistance, attribute, backgroundBlurriness, backgroundIntensity, backgroundRotation, batch, billboarding, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blendNormal, blur, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, cdl, ceil, checker, cineonToneMapping, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToWorking, colorToDirection, compute, cond, context, convert, convertColorSpace, convertToTexture, cos, createCanvasElement, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, deltaTime, densityFog, depth, depthPass, difference, diffuseColor, directPointLight, directionToColor, dispersion, distance, div, dodge, dot, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getNormalFromDepth, getParallaxCorrectNormal, getRoughness, getScreenPosition, getShIrradianceAt, getTextureIndex, getViewPosition, glsl, glslFn, grayscale, greaterThan, greaterThanEqual, hash, highPrecisionModelNormalViewMatrix, highPrecisionModelViewMatrix, hue, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, invocationLocalIndex, invocationSubgroupIndex, ior, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightPosition, lightTargetDirection, lightTargetPosition, lightViewPosition, lightingContext, lights, linearDepth, linearToneMapping, localId, log, log2, logarithmicDepthToViewZ, loop, luminance, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialAttenuationColor, materialAttenuationDistance, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIOR, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRefractionRatio, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularColor, materialSpecularIntensity, materialSpecularStrength, materialThickness, materialTransmission, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mixElement, mod, modInt, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, neutralToneMapping, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalFlat, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, notEqual, numWorkgroups, objectDirection, objectGroup, objectPosition, objectScale, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionPrevious, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, reinhardToneMapping, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rotate, rotateUV, roughness, round, rtt, sRGBTransferEOTF, sRGBTransferOETF, sampler, saturate, saturation, screen, screenCoordinate, screenSize, screenUV, scriptable, scriptableValue, select, setCurrentStack, shaderStages, shadow, sharedUniformGroup, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, smoothstepElement, specularColor, specularF90, spherizeUV, split, spritesheetUV, sqrt, stack, step, storage, storageBarrier, storageObject, storageStruct, storageTexture, string, struct, sub, subgroupIndex, subgroupSize, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBarrier, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, thickness, threshold, time, timerDelta, timerGlobal, timerLocal, toOutputColorSpace, toWorkingColorSpace, toneMapping, toneMappingExposure, toonOutlinePass, transformDirection, transformNormal, transformNormalToView, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transmission, transpose, tri, tri3, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, uniform, uniformArray, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, velocity, vertexColor, vertexIndex, vibrance, viewZToLogarithmicDepth, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSafeUV, viewportSharedTexture, viewportSize, viewportTexture, viewportTopLeft, viewportUV, wgsl, wgslFn, workgroupArray, workgroupBarrier, workgroupId, workingToColorSpace, xor }; diff --git a/build/three.webgpu.nodes.min.js b/build/three.webgpu.nodes.min.js index d40803afdd7c2d..7d337c4ec3ed50 100644 --- a/build/three.webgpu.nodes.min.js +++ b/build/three.webgpu.nodes.min.js @@ -3,4 +3,4 @@ * Copyright 2010-2024 Three.js Authors * SPDX-License-Identifier: MIT */ -import{Color as e,Vector2 as t,Vector3 as s,Vector4 as r,Matrix3 as n,Matrix4 as i,EventDispatcher as o,MathUtils as a,ColorManagement as u,SRGBTransfer as l,NoToneMapping as d,StaticDrawUsage as c,InterleavedBuffer as h,DynamicDrawUsage as p,InterleavedBufferAttribute as g,NoColorSpace as m,UnsignedIntType as f,IntType as y,WebGLCoordinateSystem as b,BackSide as x,CubeReflectionMapping as T,CubeRefractionMapping as _,WebGPUCoordinateSystem as N,TangentSpaceNormalMap as v,ObjectSpaceNormalMap as S,InstancedInterleavedBuffer as A,InstancedBufferAttribute as R,DataArrayTexture as C,FloatType as E,FramebufferTexture as w,LinearMipmapLinearFilter as M,DepthTexture as B,Material as U,NormalBlending as F,PointsMaterial as P,LineBasicMaterial as I,LineDashedMaterial as L,MeshNormalMaterial as D,WebGLCubeRenderTarget as V,BoxGeometry as O,NoBlending as G,Mesh as k,Scene as z,LinearFilter as $,CubeCamera as H,CubeTexture as W,EquirectangularReflectionMapping as j,EquirectangularRefractionMapping as q,AddOperation as K,MixOperation as X,MultiplyOperation as Y,MeshBasicMaterial as Q,MeshLambertMaterial as Z,MeshPhongMaterial as J,Texture as ee,MeshStandardMaterial as te,MeshPhysicalMaterial as se,MeshToonMaterial as re,MeshMatcapMaterial as ne,SpriteMaterial as ie,ShadowMaterial as oe,Uint32BufferAttribute as ae,Uint16BufferAttribute as ue,DoubleSide as le,DepthStencilFormat as de,DepthFormat as ce,UnsignedInt248Type as he,UnsignedByteType as pe,RenderTarget as ge,Plane as me,Object3D as fe,HalfFloatType as ye,LinearMipMapLinearFilter as be,OrthographicCamera as xe,BufferGeometry as Te,Float32BufferAttribute as _e,UVMapping as Ne,Euler as ve,LinearSRGBColorSpace as Se,LessCompare as Ae,VSMShadowMap as Re,RGFormat as Ce,SphereGeometry as Ee,BufferAttribute as we,CubeUVReflectionMapping as Me,PerspectiveCamera as Be,RGBAFormat as Ue,LinearMipmapNearestFilter as Fe,NearestMipmapLinearFilter as Pe,Float16BufferAttribute as Ie,REVISION as Le,SRGBColorSpace as De,PCFShadowMap as Ve,FrontSide as Oe,Frustum as Ge,DataTexture as ke,RedIntegerFormat as ze,RedFormat as $e,RGIntegerFormat as He,RGBIntegerFormat as We,RGBFormat as je,RGBAIntegerFormat as qe,UnsignedShortType as Ke,ByteType as Xe,ShortType as Ye,createCanvasElement as Qe,AddEquation as Ze,SubtractEquation as Je,ReverseSubtractEquation as et,ZeroFactor as tt,OneFactor as st,SrcColorFactor as rt,SrcAlphaFactor as nt,SrcAlphaSaturateFactor as it,DstColorFactor as ot,DstAlphaFactor as at,OneMinusSrcColorFactor as ut,OneMinusSrcAlphaFactor as lt,OneMinusDstColorFactor as dt,OneMinusDstAlphaFactor as ct,CullFaceNone as ht,CullFaceBack as pt,CullFaceFront as gt,CustomBlending as mt,MultiplyBlending as ft,SubtractiveBlending as yt,AdditiveBlending as bt,NotEqualDepth as xt,GreaterDepth as Tt,GreaterEqualDepth as _t,EqualDepth as Nt,LessEqualDepth as vt,LessDepth as St,AlwaysDepth as At,NeverDepth as Rt,UnsignedShort4444Type as Ct,UnsignedShort5551Type as Et,UnsignedInt5999Type as wt,AlphaFormat as Mt,LuminanceFormat as Bt,LuminanceAlphaFormat as Ut,RGB_S3TC_DXT1_Format as Ft,RGBA_S3TC_DXT1_Format as Pt,RGBA_S3TC_DXT3_Format as It,RGBA_S3TC_DXT5_Format as Lt,RGB_PVRTC_4BPPV1_Format as Dt,RGB_PVRTC_2BPPV1_Format as Vt,RGBA_PVRTC_4BPPV1_Format as Ot,RGBA_PVRTC_2BPPV1_Format as Gt,RGB_ETC1_Format as kt,RGB_ETC2_Format as zt,RGBA_ETC2_EAC_Format as $t,RGBA_ASTC_4x4_Format as Ht,RGBA_ASTC_5x4_Format as Wt,RGBA_ASTC_5x5_Format as jt,RGBA_ASTC_6x5_Format as qt,RGBA_ASTC_6x6_Format as Kt,RGBA_ASTC_8x5_Format as Xt,RGBA_ASTC_8x6_Format as Yt,RGBA_ASTC_8x8_Format as Qt,RGBA_ASTC_10x5_Format as Zt,RGBA_ASTC_10x6_Format as Jt,RGBA_ASTC_10x8_Format as es,RGBA_ASTC_10x10_Format as ts,RGBA_ASTC_12x10_Format as ss,RGBA_ASTC_12x12_Format as rs,RGBA_BPTC_Format as ns,RED_RGTC1_Format as is,SIGNED_RED_RGTC1_Format as os,RED_GREEN_RGTC2_Format as as,SIGNED_RED_GREEN_RGTC2_Format as us,RepeatWrapping as ls,ClampToEdgeWrapping as ds,MirroredRepeatWrapping as cs,NearestFilter as hs,NearestMipmapNearestFilter as ps,NeverCompare as gs,AlwaysCompare as ms,LessEqualCompare as fs,EqualCompare as ys,GreaterEqualCompare as bs,GreaterCompare as xs,NotEqualCompare as Ts,warnOnce as _s,NotEqualStencilFunc as Ns,GreaterStencilFunc as vs,GreaterEqualStencilFunc as Ss,EqualStencilFunc as As,LessEqualStencilFunc as Rs,LessStencilFunc as Cs,AlwaysStencilFunc as Es,NeverStencilFunc as ws,DecrementWrapStencilOp as Ms,IncrementWrapStencilOp as Bs,DecrementStencilOp as Us,IncrementStencilOp as Fs,InvertStencilOp as Ps,ReplaceStencilOp as Is,ZeroStencilOp as Ls,KeepStencilOp as Ds,MaxEquation as Vs,MinEquation as Os,SpotLight as Gs,PointLight as ks,DirectionalLight as zs,RectAreaLight as $s,AmbientLight as Hs,HemisphereLight as Ws,LightProbe as js,LinearToneMapping as qs,ReinhardToneMapping as Ks,CineonToneMapping as Xs,ACESFilmicToneMapping as Ys,AgXToneMapping as Qs,NeutralToneMapping as Zs,Group as Js,Loader as er,FileLoader as tr,MaterialLoader as sr,ObjectLoader as rr}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrayCamera,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BasicShadowMap,BatchedMesh,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,Camera,CameraHelper,CanvasTexture,CapsuleGeometry,CatmullRomCurve3,CircleGeometry,Clock,ColorKeyframeTrack,CompressedArrayTexture,CompressedCubeTexture,CompressedTexture,CompressedTextureLoader,ConeGeometry,ConstantAlphaFactor,ConstantColorFactor,Controls,CubeTextureLoader,CubicBezierCurve,CubicBezierCurve3,CubicInterpolant,CullFaceFrontBack,Curve,CurvePath,CustomToneMapping,CylinderGeometry,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LinearTransfer,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,Matrix2,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,PCFSoftShadowMap,Path,PlaneGeometry,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,Quaternion,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Sphere,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLMultipleRenderTargets,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding}from"./three.core.min.js";const nr=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class ir{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=nr,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:s,material:r}=e;if(t={material:this.getMaterialData(r),geometry:{attributes:this.getAttributesData(s.attributes),indexVersion:s.index?s.index.version:null,drawRange:{start:s.drawRange.start,count:s.drawRange.count}},worldMatrix:e.object.matrixWorld.clone()},e.object.center&&(t.center=e.object.center.clone()),e.object.morphTargetInfluences&&(t.morphTargetInfluences=e.object.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(t.matrixWorld))return n.worldMatrix.copy(t.matrixWorld),!1;const i=n.material;for(const e in i){const t=i[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return i[e]=r,!1}if(i.transmission>0){const{width:t,height:s}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==s)return n.bufferWidth=t,n.bufferHeight=s,!1}const o=n.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return n.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let s=0;s>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:n}of cr(e))s.push(s,or(r.slice(0,-4)),n.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;ee.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of cr(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let r=null;const n=e.getBuildStage();if("setup"===n){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===n)this.analyze(e);else if("generate"===n){if(1===this.generate.length){const s=this.getNodeType(e),n=e.getDataFromNode(this);r=n.snippet,void 0===r?(r=this.generate(e)||"",n.snippet=r):void 0!==n.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:n,childNode:i}of t)void 0!==n?(void 0===s[r]&&(s[r]=Number.isInteger(n)?[]:{}),s[r][n]=i.toJSON(e.meta).uuid):s[r]=i.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const n of e.inputNodes[s])r.push(t[n]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const n in e.inputNodes[s]){const i=e.inputNodes[s][n];r[n]=t[i]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let n=e.nodes[t];function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===n&&(n={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[n.uuid]=n),this.serialize(n),delete n.meta),r){const t=i(e.textures),s=i(e.images),r=i(e.nodes);t.length>0&&(n.textures=t),s.length>0&&(n.images=s),r.length>0&&(n.nodes=r)}return n}}class Rr extends Ar{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,r=this.getNodeType(e),n=s.build(e,r);return e.format(n,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const n=super.build(e,s),i=e.getVarFromNode(this,null,s),o=e.getPropertyName(i);return e.addLineFlowCode(`${o} = ${n}`,this),r.snippet=n,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,s)=>t+e.getTypeLength(s.getNodeType(e))),0))}generate(e,t){const s=this.getNodeType(e),r=this.nodes,n=e.getComponentType(s),i=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==n&&(s=e.format(s,r,n)),i.push(s)}const o=`${e.getType(s)}( ${i.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(vr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,r=e.getTypeLength(s.getNodeType(e));let n=null;if(r>1){let i=null;this.getVectorLength()>=r&&(i=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,i);n=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,i,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else n=s.build(e,t);return n}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:r}=this,n=this.getNodeType(e),i=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,i),a=t.build(e,n),u=e.getTypeLength(n),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(pn(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),hn(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>hn(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>hn(new Fr(hn(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),hn(new Br(e,t));if(!0===/^\d+$/.test(t))return hn(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=hn(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;rhn(null!==r?Object.assign(e,r):e);return null===t?(...t)=>n(new e(...gn(t))):null!==s?(s=hn(s),(...r)=>n(new e(t,...gn(r),s))):(...s)=>n(new e(t,...gn(s)))},qr=function(e,...t){return hn(new e(...gn(t)))};class Kr extends Ar{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let n=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let i=r.get(t);void 0===i&&(i=hn(e.buildFunctionNode(t)),r.set(t,i)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(i),n=hn(i.call(s))}else{const r=t.jsFunc,i=null!==s?r(s,e):r(e);n=hn(i)}return t.once&&(r.onceOutput=n),n}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return pn(e),hn(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],en=new Map;for(const e of Yr)en.set(e,new Ir(e));const tn=new Map;for(const e of Qr)tn.set(e,new Ir(e,"uint"));const sn=new Map([...tn].map((e=>new Ir(e.value,"int"))));for(const e of Zr)sn.set(e,new Ir(e,"int"));const rn=new Map([...sn].map((e=>new Ir(e.value))));for(const e of Jr)rn.set(e,new Ir(e));for(const e of Jr)rn.set(-e,new Ir(-e));const nn={bool:en,uint:tn,ints:sn,float:rn},on=new Map([...en,...rn]),an=(e,t)=>on.has(e)?on.get(e):!0===e.isNode?e:new Ir(e,t),un=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return hn(t.get(s[0]));if(1===s.length){const t=an(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?hn(t):hn(new Cr(t,e))}const r=s.map((e=>an(e)));return hn(new wr(r,e))}},ln=e=>"object"==typeof e&&null!==e?e.value:e,dn=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function cn(e,t){return new Proxy(new Xr(e,t),kr)}const hn=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?hn(an(e,t)):"shader"===s?yn(e):e}(e,t),pn=(e,t=null)=>new Hr(e,t),gn=(e,t=null)=>new Wr(e,t),mn=(...e)=>new jr(...e),fn=(...e)=>new qr(...e),yn=(e,t)=>{const s=new cn(e,t),r=(...e)=>{let t;return pn(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},bn=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),yn(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const xn=e=>{Lr=e},Tn=()=>Lr,_n=(...e)=>Lr.If(...e);function Nn(e){return Lr&&Lr.add(e),e}Vr("append",Nn);const vn=new un("color"),Sn=new un("float",nn.float),An=new un("int",nn.ints),Rn=new un("uint",nn.uint),Cn=new un("bool",nn.bool),En=new un("vec2"),wn=new un("ivec2"),Mn=new un("uvec2"),Bn=new un("bvec2"),Un=new un("vec3"),Fn=new un("ivec3"),Pn=new un("uvec3"),In=new un("bvec3"),Ln=new un("vec4"),Dn=new un("ivec4"),Vn=new un("uvec4"),On=new un("bvec4"),Gn=new un("mat2"),kn=new un("mat3"),zn=new un("mat4"),$n=(e="")=>hn(new Ir(e,"string")),Hn=e=>hn(new Ir(e,"ArrayBuffer"));Vr("toColor",vn),Vr("toFloat",Sn),Vr("toInt",An),Vr("toUint",Rn),Vr("toBool",Cn),Vr("toVec2",En),Vr("toIVec2",wn),Vr("toUVec2",Mn),Vr("toBVec2",Bn),Vr("toVec3",Un),Vr("toIVec3",Fn),Vr("toUVec3",Pn),Vr("toBVec3",In),Vr("toVec4",Ln),Vr("toIVec4",Dn),Vr("toUVec4",Vn),Vr("toBVec4",On),Vr("toMat2",Gn),Vr("toMat3",kn),Vr("toMat4",zn);const Wn=mn(Rr),jn=(e,t)=>hn(new Cr(hn(e),t)),qn=(e,t)=>hn(new Br(hn(e),t));Vr("element",Wn),Vr("convert",jn);class Kn extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Xn=e=>new Kn(e),Yn=(e,t=0)=>new Kn(e,!0,t),Qn=Yn("frame"),Zn=Yn("render"),Jn=Xn("object");class ei extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Jn}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let n=e.getNodeFromHash(r);void 0===n&&(e.setHashNode(this,r),n=this);const i=n.getInputType(e),o=e.getUniformFromNode(n,i,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const ti=(e,t)=>{const s=dn(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return hn(new ei(r,s))};class si extends Ar{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const ri=(e,t)=>hn(new si(e,t)),ni=(e,t)=>hn(new si(e,t,!0)),ii=fn(si,"vec4","DiffuseColor"),oi=fn(si,"vec3","EmissiveColor"),ai=fn(si,"float","Roughness"),ui=fn(si,"float","Metalness"),li=fn(si,"float","Clearcoat"),di=fn(si,"float","ClearcoatRoughness"),ci=fn(si,"vec3","Sheen"),hi=fn(si,"float","SheenRoughness"),pi=fn(si,"float","Iridescence"),gi=fn(si,"float","IridescenceIOR"),mi=fn(si,"float","IridescenceThickness"),fi=fn(si,"float","AlphaT"),yi=fn(si,"float","Anisotropy"),bi=fn(si,"vec3","AnisotropyT"),xi=fn(si,"vec3","AnisotropyB"),Ti=fn(si,"color","SpecularColor"),_i=fn(si,"float","SpecularF90"),Ni=fn(si,"float","Shininess"),vi=fn(si,"vec4","Output"),Si=fn(si,"float","dashSize"),Ai=fn(si,"float","gapSize"),Ri=fn(si,"float","pointWidth"),Ci=fn(si,"float","IOR"),Ei=fn(si,"float","Transmission"),wi=fn(si,"float","Thickness"),Mi=fn(si,"float","AttenuationDistance"),Bi=fn(si,"color","AttenuationColor"),Ui=fn(si,"float","Dispersion");class Fi extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,n=this.needsSplitAssign(e),i=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,i),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(n){const r=e.getVarFromNode(this,null,i),n=e.getPropertyName(r);e.addLineFlowCode(`${n} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t{const r=s.type;let n;return n="pointer"===r?"&"+t.build(e):t.build(e,r),n};if(Array.isArray(n))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?gn(t):pn(t[0]),hn(new Ii(hn(e),t)));Vr("call",Li);class Di extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let n=new Di(e,t,s);for(let t=0;t>"===s||"<<"===s)return e.getIntegerType(i);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(i),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===i&&e.isMatrix(o)?o:e.isMatrix(i)&&e.isVector(o)?e.getVectorFromMatrix(i):e.isVector(i)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(i)?o:i}generate(e,t){const s=this.op,r=this.aNode,n=this.bNode,i=this.getNodeType(e,t);let o=null,a=null;"void"!==i?(o=r.getNodeType(e),a=void 0!==n?n.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=i,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=i):o=a=i;const u=r.build(e,o),l=void 0!==n?n.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} < ${l} )`,i,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} <= ${l} )`,i,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} > ${l} )`,i,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} >= ${l} )`,i,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`( ${u} ${s} ${l} )`,i,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`${u} ${s} ${l}`,i,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vi=mn(Di,"+"),Oi=mn(Di,"-"),Gi=mn(Di,"*"),ki=mn(Di,"/"),zi=mn(Di,"%"),$i=mn(Di,"=="),Hi=mn(Di,"!="),Wi=mn(Di,"<"),ji=mn(Di,">"),qi=mn(Di,"<="),Ki=mn(Di,">="),Xi=mn(Di,"&&"),Yi=mn(Di,"||"),Qi=mn(Di,"!"),Zi=mn(Di,"^^"),Ji=mn(Di,"&"),eo=mn(Di,"~"),to=mn(Di,"|"),so=mn(Di,"^"),ro=mn(Di,"<<"),no=mn(Di,">>");Vr("add",Vi),Vr("sub",Oi),Vr("mul",Gi),Vr("div",ki),Vr("modInt",zi),Vr("equal",$i),Vr("notEqual",Hi),Vr("lessThan",Wi),Vr("greaterThan",ji),Vr("lessThanEqual",qi),Vr("greaterThanEqual",Ki),Vr("and",Xi),Vr("or",Yi),Vr("not",Qi),Vr("xor",Zi),Vr("bitAnd",Ji),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",no);const io=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zi(...e));Vr("remainder",io);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,n=e.isMatrix(t)?0:e.getTypeLength(t),i=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return n>i&&n>o?t:i>o?s:o>n?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),n=this.getInputType(e),i=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=i,r=o;e.isMatrix(s.getNodeType(e))?r=Ln(Un(r),0):s=Ln(Un(s),0);const n=Gi(s,r).xyz;return Ao(n).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+i.build(e,n)+" )",r,t);if(s===oo.ONE_MINUS)return Oi(1,i).build(e,t);if(s===oo.RECIPROCAL)return ki(1,i).build(e,t);if(s===oo.DIFFERENCE)return Fo(Oi(i,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(i.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(i.build(e,1===e.getTypeLength(i.getNodeType(e))?"float":n),o.build(e,n)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(i.build(e,n),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":n)):s===oo.REFRACT?l.push(i.build(e,n),o.build(e,n),a.build(e,"float")):s===oo.MIX?l.push(i.build(e,n),o.build(e,n),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":n)):(l.push(i.build(e,n)),null!==o&&l.push(o.build(e,n)),null!==a&&l.push(a.build(e,n))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=Sn(1e-6),uo=Sn(1e6),lo=Sn(Math.PI),co=Sn(2*Math.PI),ho=mn(oo,oo.ALL),po=mn(oo,oo.ANY),go=mn(oo,oo.EQUALS),mo=mn(oo,oo.RADIANS),fo=mn(oo,oo.DEGREES),yo=mn(oo,oo.EXP),bo=mn(oo,oo.EXP2),xo=mn(oo,oo.LOG),To=mn(oo,oo.LOG2),_o=mn(oo,oo.SQRT),No=mn(oo,oo.INVERSE_SQRT),vo=mn(oo,oo.FLOOR),So=mn(oo,oo.CEIL),Ao=mn(oo,oo.NORMALIZE),Ro=mn(oo,oo.FRACT),Co=mn(oo,oo.SIN),Eo=mn(oo,oo.COS),wo=mn(oo,oo.TAN),Mo=mn(oo,oo.ASIN),Bo=mn(oo,oo.ACOS),Uo=mn(oo,oo.ATAN),Fo=mn(oo,oo.ABS),Po=mn(oo,oo.SIGN),Io=mn(oo,oo.LENGTH),Lo=mn(oo,oo.NEGATE),Do=mn(oo,oo.ONE_MINUS),Vo=mn(oo,oo.DFDX),Oo=mn(oo,oo.DFDY),Go=mn(oo,oo.ROUND),ko=mn(oo,oo.RECIPROCAL),zo=mn(oo,oo.TRUNC),$o=mn(oo,oo.FWIDTH),Ho=mn(oo,oo.BITCAST),Wo=mn(oo,oo.TRANSPOSE),jo=mn(oo,oo.ATAN2),qo=mn(oo,oo.MIN),Ko=mn(oo,oo.MAX),Xo=mn(oo,oo.MOD),Yo=mn(oo,oo.STEP),Qo=mn(oo,oo.REFLECT),Zo=mn(oo,oo.DISTANCE),Jo=mn(oo,oo.DIFFERENCE),ea=mn(oo,oo.DOT),ta=mn(oo,oo.CROSS),sa=mn(oo,oo.POW),ra=mn(oo,oo.POW,2),na=mn(oo,oo.POW,3),ia=mn(oo,oo.POW,4),oa=mn(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gi(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=mn(oo,oo.MIX),da=(e,t=0,s=1)=>hn(new oo(oo.CLAMP,hn(e),hn(t),hn(s))),ca=e=>da(e),ha=mn(oo,oo.REFRACT),pa=mn(oo,oo.SMOOTHSTEP),ga=mn(oo,oo.FACEFORWARD),ma=yn((([e])=>{const t=ea(e.xy,En(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",na),Vr("pow4",ia),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,n=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=n,null!==r&&(e.getDataFromNode(r).parentNodeBlock=n);const i=e.getNodeProperties(this);i.condNode=t,i.ifNode=s.context({nodeBlock:s}),i.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:n,ifNode:i,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?ri(s).build(e):"";r.nodeProperty=u;const l=n.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=i.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=mn(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e,t);return e.setContext(s),r}}const Na=mn(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),n=e.getPropertyName(r),i=t.build(e,r.type);return e.addLineFlowCode(`${n} = ${i}`,this),n}}const Aa=mn(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const r=this.name,n=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,n),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const r=this.getNodeType(e),n=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,n),t.propertyName=n}return e.getPropertyName(s)}}const Ea=mn(Ca);Vr("varying",Ea);const wa=yn((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=yn((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let i=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(i=Ln(wa(i.rgb),i.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(i=Ln(kn(u._getMatrix(new n,s,r)).mul(i.rgb),i.a)),u.getTransfer(r)===l&&(i=Ln(Ma(i.rgb),i.a)),i):i}}const Pa=e=>hn(new Fa(hn(e),Ba,Ua)),Ia=e=>hn(new Fa(hn(e),Ua,Ba)),La=(e,t)=>hn(new Fa(hn(e),Ba,t)),Da=(e,t)=>hn(new Fa(hn(e),t,Ba)),Va=(e,t,s)=>hn(new Fa(hn(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return hn(new Oa(this,hn(e)))}setNodeType(e){const t=ti(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const n=e.renderer.library.getToneMappingFunction(s);return null!==n?r=Ln(n(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>hn(new $a(e,hn(t),hn(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),n=this.bufferStride||r,i=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,n),a=new g(o,r,i);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let n=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,n=r;else{n=Ea(this).build(e,t)}return n}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>hn(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;ehn(new Qa(hn(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const n=this.node.build(e,...t);return e.setCache(s),n}}const eu=(e,...t)=>hn(new Ja(hn(e),...t));Vr("cache",eu);class tu extends Ar{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const su=mn(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=Sn(0),n=Sn(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=n,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:n,doClamp:i}=this;let o=e.sub(t).div(s.sub(t));return!0===i&&(o=o.clamp()),o.mul(n.sub(r)).add(r)}}const nu=mn(ru,null,null,{doClamp:!1}),iu=mn(ru);Vr("remap",nu),Vr("remapClamp",iu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=mn(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>hn(new du(hn(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),n=e.getTypeFromAttribute(r),i=e.getAttribute(t,n);if("vertex"===e.shaderStage)return e.format(i.name,n,s);return Ea(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const gu=(e,t)=>hn(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=mn(fu);class bu extends ei{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=mn(bu);class Tu extends ei{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=ti(this.value.matrix)),this._matrixUniform.mul(Un(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&!0===s.flipY||!0===s.isRenderTargetTexture||!0===s.isFramebufferTexture||!0===s.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(An(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,n,i,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,i):n?e.generateTextureBias(u,t,s,n,i):a?e.generateTextureGrad(u,t,s,a,i):o?e.generateTextureCompare(u,t,s,o,i):!1===this.sampler?e.generateTextureLoad(u,t,s,i):e.generateTexture(u,t,s,i),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const n=super.generate(e,"property");if("sampler"===t)return n+"_sampler";if(e.isReference(t))return n;{const i=e.getDataFromNode(this);let o=i.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,n,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),i.snippet=b,i.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}blur(e){const t=this.clone();return t.biasNode=hn(e).mul(xu(t)),t.referenceNode=this.getSelf(),hn(t)}level(e){const t=this.clone();return t.levelNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}compare(e){const t=this.clone();return t.compareNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}grad(e,t){const s=this.clone();return s.gradNode=[hn(e),hn(t)],s.referenceNode=this.getSelf(),hn(s)}depth(e){const t=this.clone();return t.depthNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=mn(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=ti("float").label("cameraNear").setGroup(Zn).onRenderUpdate((({camera:e})=>e.near)),Au=ti("float").label("cameraFar").setGroup(Zn).onRenderUpdate((({camera:e})=>e.far)),Ru=ti("mat4").label("cameraProjectionMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=ti("mat4").label("cameraProjectionMatrixInverse").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=ti("mat4").label("cameraViewMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=ti("mat4").label("cameraWorldMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=ti("mat3").label("cameraNormalMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=ti(new s).label("cameraPosition").setGroup(Zn).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new ei(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,n=this.scope;if(n===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(n===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(n===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(n===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(n===Uu.VIEW_POSITION){const n=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(n.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=mn(Uu,Uu.DIRECTION),Pu=mn(Uu,Uu.WORLD_MATRIX),Iu=mn(Uu,Uu.POSITION),Lu=mn(Uu,Uu.SCALE),Du=mn(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=fn(Vu,Vu.DIRECTION),Gu=fn(Vu,Vu.WORLD_MATRIX),ku=fn(Vu,Vu.POSITION),zu=fn(Vu,Vu.SCALE),$u=fn(Vu,Vu.VIEW_POSITION),Hu=ti(new n).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=ti(new i).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=yn((e=>(e.context.isHighPrecisionModelViewMatrix=!0,ti("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=yn((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return ti("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=fn(sl),nl=Sn(rl).mul(2).sub(1),il=gu("normal","vec3"),ol=yn((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Un(0,1,0)):il),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=yn((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=yn((e=>e.context.setupNormal()),"vec3").once()().mul(nl).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=yn((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(nl).toVar("transformedClearcoatNormalView"),pl=yn((([e,t=Gu])=>{const s=kn(t),r=e.div(Un(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=yn((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=ti(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Un(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Un(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=mn(Tl);class Nl extends ei{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const vl=(e,t,s)=>hn(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;shn(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),hn(new Al(e,t)));class El extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return hn(new El(this,hn(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):ti(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new wl(e,t,s)),Bl=(e,t,s,r)=>hn(new wl(e,t,r,s));class Ul extends wl{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>hn(new Ul(e,t,s)),Pl=yn((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ln(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(il.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=kn(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xi.cross(tl);return e=e.cross(xi).normalize(),e=la(e,dl,yi.mul(ai.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=yn((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:n}=e,i=t.dFdx(),o=t.dFdy(),a=n.dFdx(),u=n.dFdy(),l=s,d=o.cross(l),c=l.cross(i),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=nl.mul(g.inverseSqrt());return Vi(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Un(r.xy.mul(s),r.z));let n=null;if(t===S)n=gl(r);else if(t===v){n=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return n}}const Jl=mn(Zl),ed=yn((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=Sn(s((e=>e)));return En(Sn(s((e=>e.add(e.dFdx())))).sub(r),Sn(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=yn((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,n=t.dFdx().normalize(),i=s,o=t.dFdy().normalize().cross(i),a=i.cross(n),u=n.dot(o).mul(nl),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=mn(sd),nd=new Map;class id extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=nd.get(e);return void 0===s&&(s=Fl(e,t),nd.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===id.COLOR){const e=void 0!==t.color?this.getColor(s):Un();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===id.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===id.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:Sn(1);else if(s===id.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===id.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===id.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===id.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===id.EMISSIVE){const e=this.getFloat("emissiveIntensity"),n=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?n.mul(this.getTexture(s)):n}else if(s===id.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===id.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===id.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===id.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===id.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Gn($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(En(1)).normalize().mul(e.b))}else r=$d;else if(s===id.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const n=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(n).mul(this.getTexture(s).g).add(n)}else r=e}else if(s===id.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===id.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===id.IOR)r=this.getFloat(s);else if(s===id.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===id.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}id.ALPHA_TEST="alphaTest",id.COLOR="color",id.OPACITY="opacity",id.SHININESS="shininess",id.SPECULAR="specular",id.SPECULAR_STRENGTH="specularStrength",id.SPECULAR_INTENSITY="specularIntensity",id.SPECULAR_COLOR="specularColor",id.REFLECTIVITY="reflectivity",id.ROUGHNESS="roughness",id.METALNESS="metalness",id.NORMAL="normal",id.CLEARCOAT="clearcoat",id.CLEARCOAT_ROUGHNESS="clearcoatRoughness",id.CLEARCOAT_NORMAL="clearcoatNormal",id.EMISSIVE="emissive",id.ROTATION="rotation",id.SHEEN="sheen",id.SHEEN_ROUGHNESS="sheenRoughness",id.ANISOTROPY="anisotropy",id.IRIDESCENCE="iridescence",id.IRIDESCENCE_IOR="iridescenceIOR",id.IRIDESCENCE_THICKNESS="iridescenceThickness",id.IOR="ior",id.TRANSMISSION="transmission",id.THICKNESS="thickness",id.ATTENUATION_DISTANCE="attenuationDistance",id.ATTENUATION_COLOR="attenuationColor",id.LINE_SCALE="scale",id.LINE_DASH_SIZE="dashSize",id.LINE_GAP_SIZE="gapSize",id.LINE_WIDTH="linewidth",id.LINE_DASH_OFFSET="dashOffset",id.POINT_WIDTH="pointWidth",id.DISPERSION="dispersion",id.LIGHT_MAP="light",id.AO_MAP="ao";const od=fn(id,id.ALPHA_TEST),ad=fn(id,id.COLOR),ud=fn(id,id.SHININESS),ld=fn(id,id.EMISSIVE),dd=fn(id,id.OPACITY),cd=fn(id,id.SPECULAR),hd=fn(id,id.SPECULAR_INTENSITY),pd=fn(id,id.SPECULAR_COLOR),gd=fn(id,id.SPECULAR_STRENGTH),md=fn(id,id.REFLECTIVITY),fd=fn(id,id.ROUGHNESS),yd=fn(id,id.METALNESS),bd=fn(id,id.NORMAL).context({getUV:null}),xd=fn(id,id.CLEARCOAT),Td=fn(id,id.CLEARCOAT_ROUGHNESS),_d=fn(id,id.CLEARCOAT_NORMAL).context({getUV:null}),Nd=fn(id,id.ROTATION),vd=fn(id,id.SHEEN),Sd=fn(id,id.SHEEN_ROUGHNESS),Ad=fn(id,id.ANISOTROPY),Rd=fn(id,id.IRIDESCENCE),Cd=fn(id,id.IRIDESCENCE_IOR),Ed=fn(id,id.IRIDESCENCE_THICKNESS),wd=fn(id,id.TRANSMISSION),Md=fn(id,id.THICKNESS),Bd=fn(id,id.IOR),Ud=fn(id,id.ATTENUATION_DISTANCE),Fd=fn(id,id.ATTENUATION_COLOR),Pd=fn(id,id.LINE_SCALE),Id=fn(id,id.LINE_DASH_SIZE),Ld=fn(id,id.LINE_GAP_SIZE),Dd=fn(id,id.LINE_WIDTH),Vd=fn(id,id.LINE_DASH_OFFSET),Od=fn(id,id.POINT_WIDTH),Gd=fn(id,id.DISPERSION),kd=fn(id,id.LIGHT_MAP),zd=fn(id,id.AO_MAP),$d=ti(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=mn(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,n;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)n=r;else{n=Ea(this).build(e,t)}return n}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=fn(jd,jd.VERTEX),Kd=fn(jd,jd.INSTANCE),Xd=fn(jd,jd.SUBGROUP),Yd=fn(jd,jd.INVOCATION_SUBGROUP),Qd=fn(jd,jd.INVOCATION_LOCAL),Zd=fn(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,n=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=zn(...n)}this.instanceMatrixNode=t}const n=r.instanceColor;if(n&&null===s){const e=new R(n.array,3),t=n.usage===p?Ya:Xa;this.bufferColor=e,s=Un(t(e,"vec3",3,0)),this.instanceColorNode=s}const i=t.mul(Yu).xyz;if(Yu.assign(i),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&ni("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=mn(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=yn((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=An(e).modInt(An(t)),r=An(e).div(An(t));return Nu(this.batchMesh._indirectTexture,wn(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(An(this.batchingIdNode)),r=this.batchMesh._matricesTexture,n=yu(Nu(r),0),i=Sn(s).mul(4).toInt().toVar(),o=i.modInt(n),a=i.div(An(n)),u=zn(Nu(r,wn(o,a)),Nu(r,wn(o.add(1),a)),Nu(r,wn(o.add(2),a)),Nu(r,wn(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=yn((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),n=s.div(t);return Nu(l,wn(r,n)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);ni("vec3","vBatchColor").assign(t)}const d=kn(u);Yu.assign(u.mul(Yu));const c=ol.div(Un(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=mn(tc),rc=new WeakMap;class nc extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,n;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),n=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=ti(e.bindMatrix,"mat4"),r=ti(e.bindMatrixInverse,"mat4"),n=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=n,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=n.mul(t),c=Vi(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return i.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vi(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=i.mul(d).mul(n),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const ic=e=>hn(new nc(e)),oc=e=>hn(new nc(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;eNumber(i)?">=":"<"));const d={start:n,end:i,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const n=r.build(e,"void"),i=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+n);for(let t=0,s=this.params.length-1;thn(new ac(gn(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=yn((({bufferMap:e,influence:t,stride:s,width:r,depth:n,offset:i})=>{const o=An(qd).mul(s).add(i),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,wn(u,a)).depth(n).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=ti(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,n=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,i=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==i?i.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,n=void 0!==e.morphAttributes.color,i=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==i?i.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===n&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=Sn(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,wn(An(e).add(1),An(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(0)})),!0===n&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=mn(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Un().toVar("directDiffuse"),directSpecular:Un().toVar("directSpecular"),indirectDiffuse:Un().toVar("indirectDiffuse"),indirectSpecular:Un().toVar("indirectSpecular")};return{radiance:Un().toVar("radiance"),irradiance:Un().toVar("irradiance"),iblIrradiance:Un().toVar("iblIrradiance"),ambientOcclusion:Sn(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Tc=mn(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?ti(Nc||(Nc=new t)):e===Sc.VIEWPORT?ti(vc||(vc=new r)):En(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=fn(Sc,Sc.UV),Rc=fn(Sc,Sc.SIZE),Cc=fn(Sc,Sc.COORDINATE),Ec=fn(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=yn((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=yn((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=yn((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=mn(Lc),Vc=mn(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=mn(Gc);class zc extends Ar{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Xc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.negate().div(t)),n=To(s.div(t));return r.div(n)},Kc=(e,t,s)=>{const r=e.mul(xo(s.div(t)));return Sn(Math.E).pow(r).mul(t).negate()},Xc=mn(zc,zc.DEPTH_BASE),Yc=fn(zc,zc.DEPTH),Qc=mn(zc,zc.LINEAR_DEPTH),Zc=Qc(kc());Yc.assign=e=>Xc(e);const Jc=mn(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class eh extends Ar{static get type(){return"ClippingNode"}constructor(e=eh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===eh.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===eh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return yn((()=>{const s=Sn().toVar("distanceToPlane"),r=Sn().toVar("distanceToGradient"),n=Sn(1).toVar("clipOpacity"),i=t.length;if(!this.hardwareClipping&&i>0){const e=Rl(t);uc(i,(({i:t})=>{const i=e.element(t);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),i=Sn(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const n=t.element(e);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s).oneMinus())})),n.mulAssign(i.oneMinus())}ii.a.mulAssign(n),ii.a.equal(0).discard()}))()}setupDefault(e,t){return yn((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Cn(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),yn((()=>{const r=Rl(e),n=Jc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();n.element(e).assign(s)}))}))()}}eh.ALPHA_TO_COVERAGE="alphaToCoverage",eh.DEFAULT="default",eh.HARDWARE="hardware";const th=yn((([e])=>Ro(Gi(1e4,Co(Gi(17,e.x).add(Gi(.1,e.y)))).mul(Vi(.1,Fo(Co(Gi(13,e.y).add(e.x)))))))),sh=yn((([e])=>th(En(th(e.xy),e.z)))),rh=yn((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=Sn(1).div(Sn(.05).mul(t)).toVar("pixScale"),r=En(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),n=En(sh(vo(r.x.mul(e.xyz))),sh(vo(r.y.mul(e.xyz)))).toVar("alpha"),i=Ro(To(s)).toVar("lerpFactor"),o=Vi(Gi(i.oneMinus(),n.x),Gi(i,n.y)).toVar("x"),a=qo(i,i.oneMinus()).toVar("a"),u=Un(o.mul(o).div(Gi(2,a).mul(Oi(1,a))),o.sub(Gi(.5,a)).div(Oi(1,a)),Oi(1,Oi(1,o).mul(Oi(1,o)).div(Gi(2,a).mul(Oi(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class nh extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new ir(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const n=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const i=this.setupLighting(e);null!==n&&e.stack.add(n);const o=Ln(i,ii.a).max(0);if(r=this.setupOutput(e,o),vi.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ln(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=hn(new eh(eh.ALPHA_TO_COVERAGE)):e.stack.add(hn(new eh))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(hn(new eh(eh.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(el.z,Su,Au):$c(el.z,Su,Au))}null!==r&&Yc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ln(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ln(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=ni("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=ni("vec3","vBatchColor").mul(s)}ii.assign(s);const r=this.opacityNode?Sn(this.opacityNode):dd;if(ii.a.assign(ii.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?Sn(this.alphaTestNode):od;ii.a.lessThanEqual(e).discard()}!0===this.alphaHash&&ii.a.lessThan(rh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&ii.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Un(0):ii.rgb}setupNormal(){return this.normalNode?Un(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:n}=this,i=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(i&&i.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(i,t,s,r)}else null!==s&&(o=Un(null!==r?la(o,s,r):s));return(n&&!0===n.isNode||t.emissive&&!0===t.emissive.isColor)&&(oi.assign(Un(n||ld)),o=o.add(oi)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ln(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:n}of r)s.inputNodes[t]=n.toJSON(e).uuid;function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=n(e.textures),r=n(e.images),i=n(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),i.length>0&&(s.nodes=i)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const ih=new P;class oh extends nh{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(ih),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=yn((()=>{const e=gu("instancePosition").xyz,t=Ln(ju.mul(Ln(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),n=Xu.xy.toVar();return n.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),n.assign(n.div(Ec.z)),n.y.assign(n.y.mul(s)),n.assign(n.mul(r.w)),r.addAssign(Ln(n,0,0)),r}))(),this.fragmentNode=yn((()=>{const r=Sn(1).toVar(),n=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=Sn(n.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),n).oneMinus())}else n.greaterThan(1).discard();let i;if(this.pointColorNode)i=this.pointColorNode;else if(s){i=gu("instanceColor").mul(ad)}else i=ad;return r.mulAssign(dd),Ln(i,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ah=new I;class uh extends nh{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(ah),this.setValues(e)}}const lh=new L;class dh extends nh{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(lh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?Sn(this.offsetNodeNode):Vd,t=this.dashScaleNode?Sn(this.dashScaleNode):Pd,s=this.dashSizeNode?Sn(this.dashSizeNode):Id,r=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(s),Ai.assign(r);const n=Ea(gu("lineDistance").mul(t));(e?n.add(e):n).mod(Si.add(Ai)).greaterThan(Si).discard()}}const ch=new L;class hh extends nh{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ch),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,n=this.worldUnits,i=yn((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ln(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=yn((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ln(ju.mul(Ln(e,1))).toVar("start"),o=Ln(ju.mul(Ln(t,1))).toVar("end");if(r){const e=this.dashScaleNode?Sn(this.dashScaleNode):Pd,t=this.offsetNode?Sn(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let n=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));n=n.add(t),ni("float","lineDistance").assign(n)}n&&(ni("vec3","worldStart").assign(s.xyz),ni("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);_n(u,(()=>{_n(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(i({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(i({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ln().toVar();if(n){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),n=e.cross(t).normalize(),i=e.cross(n),a=ni("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ln(Xu.x.lessThan(0).select(n.mul(u),n.mul(u).negate()),0)),r||(a.addAssign(Ln(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ln(i.mul(u),0)),_n(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ln(i.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Un().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=En(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),_n(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ln(e,0,0)))}return g}))();const o=yn((({p1:e,p2:t,p3:s,p4:r})=>{const n=e.sub(s),i=r.sub(s),o=t.sub(e),a=n.dot(i),u=i.dot(o),l=n.dot(o),d=i.dot(i),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return En(h,p)}));this.fragmentNode=yn((()=>{const i=mu();if(r){const e=this.dashSizeNode?Sn(this.dashSizeNode):Id,t=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(e),Ai.assign(t);const s=ni("float","lineDistance");i.y.lessThan(-1).or(i.y.greaterThan(1)).discard(),s.mod(Si.add(Ai)).greaterThan(Si).discard()}const a=Sn(1).toVar("alpha");if(n){const s=ni("vec3","worldStart"),n=ni("vec3","worldEnd"),i=ni("vec4","worldPos").xyz.normalize().mul(1e5),u=n.sub(s),l=o({p1:s,p2:n,p3:Un(0,0,0),p4:i}),d=s.add(u.mul(l.x)),c=i.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1)),s=e.mul(e).add(t.mul(t)),r=Sn(s.fwidth()).toVar("dlen");_n(i.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else _n(i.y.abs().greaterThan(1),(()=>{const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ln(u,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ph=e=>hn(e).mul(.5).add(.5),gh=e=>hn(e).mul(2).sub(1),mh=new D;class fh extends nh{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(mh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?Sn(this.opacityNode):dd;ii.assign(Ln(ph(dl),e))}}class yh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return En(t,s)}}const bh=mn(yh);class xh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n=new O(5,5,5),i=bh(Ju),o=new nh;o.colorNode=_u(t,i,0),o.side=x,o.blending=G;const a=new k(n,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const Th=new WeakMap;class _h extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(Th.has(e)){const t=Th.get(e);vh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new xh(s.height);r.fromEquirectangularTexture(t,e),vh(r.texture,e.mapping),this._cubeTexture=r.texture,Th.set(e,r.texture),e.addEventListener("dispose",Nh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Nh(e){const t=e.target;t.removeEventListener("dispose",Nh);const s=Th.get(t);void 0!==s&&(Th.delete(t),s.dispose())}function vh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const Sh=mn(_h);class Ah extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Sh(this.envNode)}}class Rh extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=Sn(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ch{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Eh extends Ch{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,n=e.reflectedLight,i=s.context.irradianceLightMap;n.indirectDiffuse.assign(Ln(0)),i?n.indirectDiffuse.addAssign(i):n.indirectDiffuse.addAssign(Ln(1,1,1,0)),n.indirectDiffuse.mulAssign(r),n.indirectDiffuse.mulAssign(ii.rgb)}finish(e,t,s){const r=s.material,n=e.outgoingLight,i=s.context.environment;if(i)switch(r.combine){case Y:n.rgb.assign(la(n.rgb,n.rgb.mul(i.rgb),gd.mul(md)));break;case X:n.rgb.assign(la(n.rgb,i.rgb,gd.mul(md)));break;case K:n.rgb.addAssign(i.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const wh=new Q;class Mh extends nh{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Rh(kd)),t}setupOutgoingLight(){return ii.rgb}setupLightingModel(){return new Eh}}const Bh=yn((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Uh=yn((e=>e.diffuseColor.mul(1/Math.PI))),Fh=yn((({dotNH:e})=>Ni.mul(Sn(.5)).add(1).mul(Sn(1/Math.PI)).mul(e.pow(Ni)))),Ph=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),n=Bh({f0:Ti,f90:1,dotVH:r}),i=Sn(.25),o=Fh({dotNH:s});return n.mul(i).mul(o)}));class Ih extends Eh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Ph({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const Lh=new Z;class Dh extends nh{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih(!1)}}const Vh=new J;class Oh extends nh{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Vh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih}setupVariants(){const e=(this.shininessNode?Sn(this.shininessNode):ud).max(1e-4);Ni.assign(e);const t=this.specularNode||cd;Ti.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Gh=yn((e=>{if(!1===e.geometry.hasAttribute("normal"))return Sn(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),kh=yn((e=>{const{roughness:t}=e,s=Gh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),zh=yn((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),n=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),i=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return ki(.5,n.add(i).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),$h=yn((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:n,dotBL:i,dotNV:o,dotNL:a})=>{const u=a.mul(Un(e.mul(s),t.mul(r),o).length()),l=o.mul(Un(e.mul(n),t.mul(i),a).length());return ki(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hh=yn((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Wh=Sn(1/Math.PI),jh=yn((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:n})=>{const i=e.mul(t),o=Un(t.mul(r),e.mul(n),i.mul(s)),a=o.dot(o),u=i.div(a);return Wh.mul(i.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),qh=yn((e=>{const{lightDirection:t,f0:s,f90:r,roughness:n,f:i,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=n.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Bh({f0:s,f90:r,dotVH:g});if(ln(o)&&(y=pi.mix(y,i)),ln(a)){const e=bi.dot(t),s=bi.dot(tl),r=bi.dot(d),n=xi.dot(t),i=xi.dot(tl),o=xi.dot(d);m=$h({alphaT:fi,alphaB:l,dotTV:s,dotBV:i,dotTL:e,dotBL:n,dotNV:h,dotNL:c}),f=jh({alphaT:fi,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=zh({alpha:l,dotNL:c,dotNV:h}),f=Hh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),Kh=yn((({roughness:e,dotNV:t})=>{const s=Ln(-1,-.0275,-.572,.022),r=Ln(1,.0425,1.04,-.04),n=e.mul(s).add(r),i=n.x.mul(n.x).min(t.mul(-9.28).exp2()).mul(n.x).add(n.y);return En(-1.04,1.04).mul(i).add(n.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xh=yn((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:n}=e,i=Kh({dotNV:t,roughness:n});return s.mul(i.x).add(r.mul(i.y))})),Yh=yn((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),n=r.mul(r),i=r.mul(n,n).clamp(0,.9999);return e.sub(Un(t).mul(i)).div(i.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qh=yn((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=Sn(1).div(s),n=t.pow2().oneMinus().max(.0078125);return Sn(2).add(r).mul(n.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Zh=yn((({dotNV:e,dotNL:t})=>Sn(1).div(Sn(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Jh=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),n=dl.dot(t).clamp(),i=Qh({roughness:hi,dotNH:n}),o=Zh({dotNV:r,dotNL:s});return ci.mul(i).mul(o)})),ep=yn((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),n=En(s,r.oneMinus().sqrt());return n.assign(n.mul(.984375).add(.0078125)),n})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),tp=yn((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sp=yn((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),n=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),i=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=n.div(i),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),rp=yn((({N:e,V:t,P:s,mInv:r,p0:n,p1:i,p2:o,p3:a})=>{const u=i.sub(n).toVar(),l=a.sub(n).toVar(),d=u.cross(l),c=Un().toVar();return _n(d.dot(s.sub(n)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(kn(u,l,e).transpose()).toVar(),h=d.mul(n.sub(s)).normalize().toVar(),p=d.mul(i.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Un(0).toVar();f.addAssign(sp({v1:h,v2:p})),f.addAssign(sp({v1:p,v2:g})),f.addAssign(sp({v1:g,v2:m})),f.addAssign(sp({v1:m,v2:h})),c.assign(Un(tp({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),np=1/6,ip=e=>Gi(np,Gi(e,Gi(e,e.negate().add(3)).sub(3)).add(1)),op=e=>Gi(np,Gi(e,Gi(e,Gi(3,e).sub(6))).add(4)),ap=e=>Gi(np,Gi(e,Gi(e,Gi(-3,e).add(3)).add(3)).add(1)),up=e=>Gi(np,sa(e,3)),lp=e=>ip(e).add(op(e)),dp=e=>ap(e).add(up(e)),cp=e=>Vi(-1,op(e).div(ip(e).add(op(e)))),hp=e=>Vi(1,up(e).div(ap(e).add(up(e)))),pp=(e,t,s)=>{const r=e.uvNode,n=Gi(r,t.zw).add(.5),i=vo(n),o=Ro(n),a=lp(o.x),u=dp(o.x),l=cp(o.x),d=hp(o.x),c=cp(o.y),h=hp(o.y),p=En(i.x.add(l),i.y.add(c)).sub(.5).mul(t.xy),g=En(i.x.add(d),i.y.add(c)).sub(.5).mul(t.xy),m=En(i.x.add(l),i.y.add(h)).sub(.5).mul(t.xy),f=En(i.x.add(d),i.y.add(h)).sub(.5).mul(t.xy),y=lp(o.y).mul(Vi(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=dp(o.y).mul(Vi(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},gp=yn((([e,t=Sn(3)])=>{const s=En(e.size(An(t))),r=En(e.size(An(t.add(1)))),n=ki(1,s),i=ki(1,r),o=pp(e,Ln(n,s),vo(t)),a=pp(e,Ln(i,r),So(t));return Ro(t).mix(o,a)})),mp=yn((([e,t,s,r,n])=>{const i=Un(ha(t.negate(),Ao(e),ki(1,r))),o=Un(Io(n[0].xyz),Io(n[1].xyz),Io(n[2].xyz));return Ao(i).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),fp=yn((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),yp=Vc(),bp=Vc(),xp=yn((([e,t,s],{material:r})=>{const n=(r.side==x?yp:bp).uv(e),i=To(Rc.x).mul(fp(t,s));return gp(n,i)})),Tp=yn((([e,t,s])=>(_n(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Un(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),_p=yn((([e,t,s,r,n,i,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ln().toVar(),f=Un().toVar();const n=d.sub(1).mul(g.mul(.025)),i=Un(d.sub(n),d,d.add(n));uc({start:0,end:3},(({i:n})=>{const d=i.element(n),g=mp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ln(y,1))),x=En(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(En(x.x,x.y.oneMinus()));const T=xp(x,s,d);m.element(n).assign(T.element(n)),m.a.addAssign(T.a),f.element(n).assign(r.element(n).mul(Tp(Io(g),h,p).element(n)))})),m.a.divAssign(3)}else{const n=mp(e,t,c,d,a),i=o.add(n),g=l.mul(u.mul(Ln(i,1))),y=En(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(En(y.x,y.y.oneMinus())),m=xp(y,s,d),f=r.mul(Tp(Io(n),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Un(Xh({dotNV:b,specularColor:n,specularF90:i,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ln(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),Np=kn(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),vp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Sp=yn((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:n})=>{const i=la(e,t,pa(0,.03,r)),o=e.div(i).pow2().mul(s.pow2().oneMinus()).oneMinus();_n(o.lessThan(0),(()=>Un(1)));const a=o.sqrt(),u=vp(i,e),l=Bh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=i.lessThan(e).select(Math.PI,0),h=Sn(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Un(1).add(t).div(Un(1).sub(t))})(n.clamp(0,.9999)),g=vp(p,i.toVec3()),m=Bh({f0:g,f90:1,dotVH:a}),f=Un(p.x.lessThan(i).select(Math.PI,0),p.y.lessThan(i).select(Math.PI,0),p.z.lessThan(i).select(Math.PI,0)),y=i.mul(r,a,2),b=Un(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Un(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Un(54856e-17,44201e-17,52481e-17),n=Un(1681e3,1795300,2208400),i=Un(43278e5,93046e5,66121e5),o=Sn(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(i.mul(2*Math.PI).sqrt()).mul(n.mul(s).add(t).cos()).mul(s.pow2().negate().mul(i).exp());return a=Un(a.x.add(o),a.y,a.z).div(1.0685e-7),Np.mul(a)})(Sn(e).mul(y),Sn(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Un(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Ap=yn((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),n=s.pow2(),i=xa(s.lessThan(.25),Sn(-339.2).mul(n).add(Sn(161.4).mul(s)).sub(25.9),Sn(-8.48).mul(n).add(Sn(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),Sn(44).mul(n).sub(Sn(23.7).mul(s)).add(3.26),Sn(1.97).mul(n).sub(Sn(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,Sn(.1).mul(s).sub(.025)).add(i.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Rp=Un(.04),Cp=Sn(1);class Ep extends Ch{constructor(e=!1,t=!1,s=!1,r=!1,n=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=n,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Un().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Un().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Un().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Un().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Un().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=Sp({outsideIOR:Sn(1),eta2:gi,cosTheta1:e,thinFilmThickness:mi,baseF0:Ti}),this.iridescenceF0=Yh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=_p(r,s,ai,ii,Ti,_i,t,Gu,Eu,Ru,Ci,wi,Bi,Mi,this.dispersion?Ui:null),e.backdropAlpha=Ei,ii.a.mulAssign(la(1,e.backdrop.a,Ei))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),n=Kh({roughness:ai,dotNV:r}),i=(this.iridescenceF0?pi.mix(Ti,this.iridescenceF0):Ti).mul(n.x).add(s.mul(n.y)),o=n.x.add(n.y).oneMinus(),a=Ti.add(Ti.oneMinus().mul(.047619)),u=i.mul(a).div(o.mul(a).oneMinus());e.addAssign(i),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Jh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(qh({lightDirection:e,f0:Rp,f90:Cp,roughness:di,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),s.directSpecular.addAssign(r.mul(qh({lightDirection:e,f0:Ti,f90:1,roughness:ai,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:n,ltc_1:i,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=ep({N:c,V:h,roughness:ai}),m=i.uv(g).toVar(),f=o.uv(g).toVar(),y=kn(Un(m.x,0,m.y),Un(0,1,0),Un(m.z,0,m.w)).toVar(),b=Ti.mul(f.x).add(Ti.oneMinus().mul(f.y)).toVar();n.directSpecular.addAssign(e.mul(b).mul(rp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),n.directDiffuse.addAssign(e.mul(ii).mul(rp({N:c,V:h,P:p,mInv:kn(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Uh({diffuseColor:ii})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(ci,Ap({normal:dl,viewDir:tl,roughness:hi}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Xh({dotNV:e,specularColor:Rp,specularF90:Cp,roughness:di});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Un().toVar("singleScattering"),n=Un().toVar("multiScattering"),i=t.mul(1/Math.PI);this.computeMultiscattering(r,n,_i);const o=r.add(n),a=ii.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(n.mul(i)),s.indirectDiffuse.addAssign(a.mul(i))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=ai.mul(-16).oneMinus().negate().exp2(),n=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(n)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Bh({dotVH:e,f0:Rp,f90:Cp}),r=t.mul(li.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(li));t.assign(r)}if(!0===this.sheen){const e=ci.r.max(ci.g).max(ci.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const wp=Sn(1),Mp=Sn(-2),Bp=Sn(.8),Up=Sn(-1),Fp=Sn(.4),Pp=Sn(2),Ip=Sn(.305),Lp=Sn(3),Dp=Sn(.21),Vp=Sn(4),Op=Sn(4),Gp=Sn(16),kp=yn((([e])=>{const t=Un(Fo(e)).toVar(),s=Sn(-1).toVar();return _n(t.x.greaterThan(t.z),(()=>{_n(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{_n(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),zp=yn((([e,t])=>{const s=En().toVar();return _n(t.equal(0),(()=>{s.assign(En(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(En(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(En(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(En(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(En(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(En(e.x,e.y).div(Fo(e.z)))})),Gi(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$p=yn((([e])=>{const t=Sn(0).toVar();return _n(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).ElseIf(e.greaterThanEqual(Fp),(()=>{t.assign(Bp.sub(e).mul(Pp.sub(Up)).div(Bp.sub(Fp)).add(Up))})).ElseIf(e.greaterThanEqual(Ip),(()=>{t.assign(Fp.sub(e).mul(Lp.sub(Pp)).div(Fp.sub(Ip)).add(Pp))})).ElseIf(e.greaterThanEqual(Dp),(()=>{t.assign(Ip.sub(e).mul(Vp.sub(Lp)).div(Ip.sub(Dp)).add(Lp))})).Else((()=>{t.assign(Sn(-2).mul(To(Gi(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Hp=yn((([e,t])=>{const s=e.toVar();s.assign(Gi(2,s).sub(1));const r=Un(s,1).toVar();return _n(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Wp=yn((([e,t,s,r,n,i])=>{const o=Sn(s),a=Un(t),u=da($p(o),Mp,i),l=Ro(u),d=vo(u),c=Un(jp(e,a,d,r,n,i)).toVar();return _n(l.notEqual(0),(()=>{const t=Un(jp(e,a,d.add(1),r,n,i)).toVar();c.assign(la(c,t,l))})),c})),jp=yn((([e,t,s,r,n,i])=>{const o=Sn(s).toVar(),a=Un(t),u=Sn(kp(a)).toVar(),l=Sn(Ko(Op.sub(o),0)).toVar();o.assign(Ko(o,Op));const d=Sn(bo(o)).toVar(),c=En(zp(a,u).mul(d.sub(2)).add(1)).toVar();return _n(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gi(3,Gp))),c.y.addAssign(Gi(4,bo(i).sub(d))),c.x.mulAssign(r),c.y.mulAssign(n),e.uv(c).grad(En(),En())})),qp=yn((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:n,CUBEUV_TEXEL_WIDTH:i,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(n.cross(s).mul(Co(r))).add(n.mul(n.dot(s).mul(u.oneMinus())));return jp(e,l,t,i,o,a)})),Kp=yn((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:n,samples:i,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Un(xa(t,s,ta(s,r))).toVar();_n(ho(h.equals(Un(0))),(()=>{h.assign(Un(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Un().toVar();return p.addAssign(n.element(An(0)).mul(qp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:An(1),end:e},(({i:e})=>{_n(e.greaterThanEqual(i),(()=>{dc()}));const t=Sn(o.mul(Sn(e))).toVar();p.addAssign(n.element(e).mul(qp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(n.element(e).mul(qp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ln(p,1)}));let Xp=null;const Yp=new WeakMap;function Qp(e){let t=Yp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r0}(s))return null;t=Xp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Yp.set(e,t)}return t.texture}class Zp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=ti(0),this._height=ti(0),this._maxMip=ti(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Qp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Xp&&(Xp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Un(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Wp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Jp=mn(Zp),eg=new WeakMap;class tg extends yc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let r=eg.get(e);void 0===r&&(r=Jp(e),eg.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),n=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,i=s.context(sg(ai,n)).mul(r),o=s.context(rg(cl)).mul(Math.PI).mul(r),a=eu(i),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(sg(di,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const sg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},rg=e=>({getUV:()=>e,getTextureLevel:()=>Sn(1)}),ng=new te;class ig extends nh{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ng),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new tg(t):null}setupLightingModel(){return new Ep}setupSpecular(){const e=la(Un(.04),ii.rgb,ui);Ti.assign(e),_i.assign(1)}setupVariants(){const e=this.metalnessNode?Sn(this.metalnessNode):yd;ui.assign(e);let t=this.roughnessNode?Sn(this.roughnessNode):fd;t=kh({roughness:t}),ai.assign(t),this.setupSpecular(),ii.assign(Ln(ii.rgb.mul(e.oneMinus()),ii.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const og=new se;class ag extends ig{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(og),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?Sn(this.iorNode):Bd;Ci.assign(e),Ti.assign(la(qo(ra(Ci.sub(1).div(Ci.add(1))).mul(pd),Un(1)).mul(hd),ii.rgb,ui)),_i.assign(la(hd,1,ui))}setupLightingModel(){return new Ep(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?Sn(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?Sn(this.clearcoatRoughnessNode):Td;li.assign(e),di.assign(kh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Un(this.sheenNode):vd,t=this.sheenRoughnessNode?Sn(this.sheenRoughnessNode):Sd;ci.assign(e),hi.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?Sn(this.iridescenceNode):Rd,t=this.iridescenceIORNode?Sn(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?Sn(this.iridescenceThicknessNode):Ed;pi.assign(e),gi.assign(t),mi.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?En(this.anisotropyNode):Ad).toVar();yi.assign(e.length()),_n(yi.equal(0),(()=>{e.assign(En(1,0))})).Else((()=>{e.divAssign(En(yi)),yi.assign(yi.saturate())})),fi.assign(yi.pow2().mix(ai.pow2(),1)),bi.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xi.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?Sn(this.transmissionNode):wd,t=this.thicknessNode?Sn(this.thicknessNode):Md,s=this.attenuationDistanceNode?Sn(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Un(this.attenuationColorNode):Fd;if(Ei.assign(e),wi.assign(t),Mi.assign(s),Bi.assign(r),this.useDispersion){const e=this.dispersionNode?Sn(this.dispersionNode):Gd;Ui.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Un(this.clearcoatNormalNode):_d}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class ug extends Ep{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){if(!0===this.useSSS){const r=n.material,{thicknessColorNode:i,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=Sn(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Un(h.add(a).mul(i));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n)}}class lg extends ag{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=Sn(.1),this.thicknessAmbientNode=Sn(0),this.thicknessAttenuationNode=Sn(.1),this.thicknessPowerNode=Sn(2),this.thicknessScaleNode=Sn(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ug(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const dg=yn((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),n=En(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>n});return Un(e.r)}{const e=n.fwidth().mul(.5);return la(Un(.7),Un(1),pa(Sn(.7).sub(e.x),Sn(.7).add(e.x),n.x))}}));class cg extends Ch{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){const i=dg({normal:il,lightDirection:e,builder:n}).mul(t);s.directDiffuse.addAssign(i.mul(Uh({diffuseColor:ii.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const hg=new re;class pg extends nh{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(hg),this.setValues(e)}setupLightingModel(){return new cg}}class gg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Un(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return En(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const mg=fn(gg),fg=new ne;class yg extends nh{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(fg),this.setValues(e)}setupVariants(e){const t=mg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Un(la(.2,.8,t.y)),ii.rgb.mulAssign(s.rgb)}}const bg=new P;class xg extends nh{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(bg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Tg extends Er{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Gn(e,r,r.negate(),e).mul(s)}{const e=t,r=zn(Ln(1,0,0,0),Ln(0,Eo(e.x),Co(e.x).negate(),0),Ln(0,Co(e.x),Eo(e.x),0),Ln(0,0,0,1)),n=zn(Ln(Eo(e.y),0,Co(e.y),0),Ln(0,1,0,0),Ln(Co(e.y).negate(),0,Eo(e.y),0),Ln(0,0,0,1)),i=zn(Ln(Eo(e.z),Co(e.z).negate(),0,0),Ln(Co(e.z),Eo(e.z),0,0),Ln(0,0,1,0),Ln(0,0,0,1));return r.mul(n).mul(i).mul(Ln(s,1)).xyz}}}const _g=mn(Tg),Ng=new ie;class vg extends nh{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Ng),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:n,rotationNode:i,scaleNode:o}=this,a=Yu;let u=ju.mul(Un(n||0)),l=En(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=Sn(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>hn(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=Sn(i||Nd),h=_g(d,c);u=Ln(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Sg extends Ch{constructor(){super(),this.shadowNode=Sn(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){ii.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(ii.rgb)}}const Ag=new oe;class Rg extends nh{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ag),this.setValues(e)}setupLightingModel(){return new Sg}}const Cg=yn((({texture:e,uv:t})=>{const s=1e-4,r=Un().toVar();return _n(t.x.lessThan(s),(()=>{r.assign(Un(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Un(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Un(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Un(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Un(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Un(0,0,-1))})).Else((()=>{const s=.01,n=e.uv(t.add(Un(-.01,0,0))).r.sub(e.uv(t.add(Un(s,0,0))).r),i=e.uv(t.add(Un(0,-.01,0))).r.sub(e.uv(t.add(Un(0,s,0))).r),o=e.uv(t.add(Un(0,0,-.01))).r.sub(e.uv(t.add(Un(0,0,s))).r);r.assign(Un(n,i,o))})),r.normalize()}));class Eg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Un(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Cg({texture:this,uv:e})}}const wg=mn(Eg);class Mg extends nh{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=wg(this.map,null,0),s=yn((({orig:e,dir:t})=>{const s=Un(-.5),r=Un(.5),n=t.reciprocal(),i=s.sub(e).mul(n),o=r.sub(e).mul(n),a=qo(i,o),u=Ko(i,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return En(l,d)}));this.fragmentNode=yn((()=>{const e=Ea(Un(Wu.mul(Ln(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),n=En(s({orig:e,dir:r})).toVar();n.x.greaterThan(n.y).discard(),n.assign(En(Ko(n.x,0),n.y));const i=Un(e.add(n.x.mul(r))).toVar(),o=Un(r.abs().reciprocal()).toVar(),a=Sn(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ln(Fl("base","color"),0).toVar();return uc({type:"float",start:n.x,end:n.y,update:"+= delta"},(()=>{const e=ri("float","d").assign(t.uv(i.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:i,finalColor:u}).append():(u.a.assign(1),dc()),i.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ln(u)}))(),super.setup(e)}}class Bg{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ug{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const n of e){const e=n.node&&n.node.attribute?n.node.attribute:t.getAttribute(n.name);if(void 0===e)continue;s.push(e);const i=e.isInterleavedBufferAttribute?e.data:e;r.add(i)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:n}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(i.instanceCount=u,!0===e.isBatchedMesh)return i;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=n.start*l,c=(n.start+n.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(i.vertexCount=g,i.firstVertex=d,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let n;if(null!==r){const e=typeof r;"number"===e?n=0!==r?"1":"0":"object"===e?(n="{",r.isTexture&&(n+=r.mapping),n+="}"):n=String(r)}else n=String(r);s+=n+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Ig=[];class Lg{constructor(e,t,s,r,n,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=n,this.info=i,this.chainMaps={}}get(e,t,s,r,n,i,o,a){const u=this.getChainMap(a);Ig[0]=e,Ig[1]=t,Ig[2]=i,Ig[3]=n;let l=u.get(Ig);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,n,i,o,a),u.set(Ig,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,n,i,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ug)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,n,i,o,a,u,l,d){const c=this.getChainMap(d),h=new Pg(e,t,s,r,n,i,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Dg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Vg=1,Og=2,Gg=3,kg=4,zg=16;class $g extends Dg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Vg?this.backend.createAttribute(e):t===Og?this.backend.createIndexAttribute(e):t===Gg?this.backend.createStorageAttribute(e):t===kg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return n.version=Hg(e),n}class jg extends Dg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,n=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of n)this.attributes.delete(e);const i=this.wireframes.get(t);void 0!==i&&this.attributes.delete(i),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Gg):this.updateAttribute(e,Vg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Og);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,kg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Wg(t),e.set(t,s)):s.version!==Hg(t)&&(this.attributes.delete(s),s=Wg(t),e.set(t,s)),r=s}return r}}class qg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Kg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Xg extends Kg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Yg extends Kg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Qg=0;class Zg{constructor(e,t,s=null,r=null){this.id=Qg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Jg extends Dg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let o=this.programs.compute.get(i.computeShader);void 0===o&&(n&&0===n.computeProgram.usedTimes&&this._releaseProgram(n.computeProgram),o=new Zg(i.computeShader,"compute",i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(n&&0===n.usedTimes&&this._releasePipeline(n),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState();let o=this.programs.vertex.get(i.vertexShader);void 0===o&&(n&&0===n.vertexProgram.usedTimes&&this._releaseProgram(n.vertexProgram),o=new Zg(i.vertexShader,"vertex"),this.programs.vertex.set(i.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(i.fragmentShader);void 0===a&&(n&&0===n.fragmentProgram.usedTimes&&this._releaseProgram(n.fragmentProgram),a=new Zg(i.fragmentShader,"fragment"),this.programs.fragment.set(i.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(n&&0===n.usedTimes&&this._releasePipeline(n),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return void 0===n&&(n=new Yg(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,r)),n}_getRenderPipeline(e,t,s,r,n){r=r||this._getRenderCacheKey(e,t,s);let i=this.caches.get(r);return void 0===i&&(i=new Xg(r,t,s),this.caches.set(r,i),e.pipeline=i,this.backend.createRenderPipeline(e,n)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class em extends Dg{constructor(e,t,s,r,n,i){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=r,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,s=e.isIndirectStorageBufferAttribute?kg:Gg;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1,n=!0,i=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(r=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=s.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?n=!1:(i=10*i+u.id,o+=u.version),!0===s.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,r),this.textures.updateTexture(u),r=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t,n?i:0,o)}}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function sm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function rm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class nm{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,n,i,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:n,group:i,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=n,a.group=i,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||tm),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||sm),this.transparent.length>1&&this.transparent.sort(t||sm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||n[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,n[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=i,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&n.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=dm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class hm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class pm extends si{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const gm=(e,t)=>hn(new pm(e,t));class mm extends Ar{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new cn(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new cn(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new cn(e),this}build(e,...t){const s=Tn();xn(this);for(const t of this.nodes)t.build(e,"void");return xn(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const fm=mn(mm);class ym extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class bm extends Ar{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let r=0;r{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),Sm=(e,t)=>sa(Gi(4,e.mul(Oi(1,e))),t),Am=(e,t)=>e.lessThan(.5)?Sm(e.mul(2),t).div(2):Oi(1,Sm(Gi(Oi(1,e),2),t).div(2)),Rm=(e,t,s)=>sa(ki(sa(e,t),Vi(sa(e,t),sa(Oi(1,e),s))),1/t),Cm=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),Em=yn((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),wm=yn((([e])=>Un(Em(e.z.add(Em(e.y.mul(1)))),Em(e.z.add(Em(e.x.mul(1)))),Em(e.y.add(Em(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Mm=yn((([e,t,s])=>{const r=Un(e).toVar(),n=Sn(1.4).toVar(),i=Sn(0).toVar(),o=Un(r).toVar();return uc({start:Sn(0),end:Sn(3),type:"float",condition:"<="},(()=>{const e=Un(wm(o.mul(2))).toVar();r.addAssign(e.add(s.mul(Sn(.1).mul(t)))),o.mulAssign(1.8),n.mulAssign(1.5),r.mulAssign(1.2);const a=Sn(Em(r.z.add(Em(r.x.add(Em(r.y)))))).toVar();i.addAssign(a.div(n)),o.addAssign(.14)})),i})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Bm extends Ar{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let r=null,n=-1;for(const s of this.functionNodes){const i=s.shaderNode.layout;if(null===i)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=i.inputs;if(t.length===o.length){let i=0;for(let s=0;sn&&(r=s,n=i)}}this._candidateFnCall=s=r(...t)}return s}}const Um=mn(Bm),Fm=e=>(...t)=>Um(e,...t),Pm=ti(0).setGroup(Zn).onRenderUpdate((e=>e.time)),Im=ti(0).setGroup(Zn).onRenderUpdate((e=>e.deltaTime)),Lm=ti(0,"uint").setGroup(Zn).onRenderUpdate((e=>e.frameId)),Dm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Pm.mul(e)),Vm=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Pm.mul(e)),Om=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Im.mul(e)),Gm=(e=Pm)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),km=(e=Pm)=>e.fract().round(),zm=(e=Pm)=>e.add(.5).fract().mul(2).sub(1).abs(),$m=(e=Pm)=>e.fract(),Hm=yn((([e,t,s=En(.5)])=>_g(e.sub(s),t).add(s))),Wm=yn((([e,t,s=En(.5)])=>{const r=e.sub(s),n=r.dot(r),i=n.mul(n).mul(t);return e.add(r.mul(i))})),jm=yn((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const n=Eu.mul(r);return ln(t)&&(n[0][0]=Gu[0].length(),n[0][1]=0,n[0][2]=0),ln(s)&&(n[1][0]=0,n[1][1]=Gu[1].length(),n[1][2]=0),n[2][0]=0,n[2][1]=0,n[2][2]=1,Ru.mul(n).mul(Yu)})),qm=yn((([e=null])=>{const t=Qc();return Qc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class Km extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=Sn(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:n}=s,i=e.mod(r.mul(n)).floor(),o=i.mod(r),a=n.sub(i.add(1).div(r).ceil()),u=s.reciprocal(),l=En(o,a);return t.add(l).mul(u)}}const Xm=mn(Km);class Ym extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=Sn(1),n=Yu,i=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=n,this.normalNode=i}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:n,normalNode:i}=this;let o=i.abs().normalize();o=o.div(o.dot(Un(1)));const a=n.yz.mul(r),u=n.zx.mul(r),l=n.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vi(p,g,m)}}const Qm=mn(Ym),Zm=(...e)=>Qm(...e),Jm=new me,ef=new s,tf=new s,sf=new s,rf=new i,nf=new s(0,0,-1),of=new r,af=new s,uf=new s,lf=new r,df=new t,cf=new ge,hf=Ac.flipX();cf.depthTexture=new B(1,1);let pf=!1;class gf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||cf.texture,hf),this._reflectorBaseNode=e.reflector||new mf(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=hn(new gf({defaultTexture:cf.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class mf extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:n=!1,bounces:i=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=n,this.bounces=i,this.depth=o,this.updateBeforeType=i?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(df),e.setSize(Math.round(df.width*s),Math.round(df.height*s))}setup(e){return this._updateResolution(cf,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&pf)return;pf=!0;const{scene:t,camera:s,renderer:r,material:n}=e,{target:i}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(df),this._updateResolution(a,r),tf.setFromMatrixPosition(i.matrixWorld),sf.setFromMatrixPosition(s.matrixWorld),rf.extractRotation(i.matrixWorld),ef.set(0,0,1),ef.applyMatrix4(rf),af.subVectors(tf,sf),af.dot(ef)>0)return;af.reflect(ef).negate(),af.add(tf),rf.extractRotation(s.matrixWorld),nf.set(0,0,-1),nf.applyMatrix4(rf),nf.add(sf),uf.subVectors(tf,nf),uf.reflect(ef).negate(),uf.add(tf),o.coordinateSystem=s.coordinateSystem,o.position.copy(af),o.up.set(0,1,0),o.up.applyMatrix4(rf),o.up.reflect(ef),o.lookAt(uf),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),Jm.setFromNormalAndCoplanarPoint(ef,tf),Jm.applyMatrix4(o.matrixWorldInverse),of.set(Jm.normal.x,Jm.normal.y,Jm.normal.z,Jm.constant);const u=o.projectionMatrix;lf.x=(Math.sign(of.x)+u.elements[8])/u.elements[0],lf.y=(Math.sign(of.y)+u.elements[9])/u.elements[5],lf.z=-1,lf.w=(1+u.elements[10])/u.elements[14],of.multiplyScalar(1/of.dot(lf));u.elements[2]=of.x,u.elements[6]=of.y,u.elements[10]=r.coordinateSystem===N?of.z-0:of.z+1-0,u.elements[14]=of.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),n.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),n.visible=!0,pf=!1}}const ff=e=>hn(new gf(e)),yf=new xe(-1,1,1,-1,0,1);class bf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const xf=new bf;class Tf extends k{constructor(e=null){super(xf,e),this.camera=yf,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,yf)}render(e){e.render(this,yf)}}const _f=new t;class Nf extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const n=new ge(t,s,r);super(n.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=n,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new Tf(new nh),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(_f);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const vf=(e,...t)=>hn(new Nf(hn(e),...t)),Sf=(e,...t)=>e.isTextureNode?e:vf(e,...t),Af=yn((([e,t,s],r)=>{let n;r.renderer.coordinateSystem===N?(e=En(e.x,e.y.oneMinus()).mul(2).sub(1),n=Ln(Un(e,t),1)):n=Ln(Un(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const i=Ln(s.mul(n));return i.xyz.div(i.w)})),Rf=yn((([e,t])=>{const s=t.mul(Ln(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return En(r.x,r.y.oneMinus())})),Cf=yn((([e,t,s])=>{const r=yu(Nu(t)),n=wn(e.mul(r)).toVar(),i=Nu(t,n).toVar(),o=Nu(t,n.sub(wn(2,0))).toVar(),a=Nu(t,n.sub(wn(1,0))).toVar(),u=Nu(t,n.add(wn(1,0))).toVar(),l=Nu(t,n.add(wn(2,0))).toVar(),d=Nu(t,n.add(wn(0,2))).toVar(),c=Nu(t,n.add(wn(0,1))).toVar(),h=Nu(t,n.sub(wn(0,1))).toVar(),p=Nu(t,n.sub(wn(0,2))).toVar(),g=Fo(Oi(Sn(2).mul(a).sub(o),i)).toVar(),m=Fo(Oi(Sn(2).mul(u).sub(l),i)).toVar(),f=Fo(Oi(Sn(2).mul(c).sub(d),i)).toVar(),y=Fo(Oi(Sn(2).mul(h).sub(p),i)).toVar(),b=Af(e,i,s).toVar(),x=g.lessThan(m).select(b.sub(Af(e.sub(En(Sn(1).div(r.x),0)),a,s)),b.negate().add(Af(e.add(En(Sn(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Af(e.add(En(0,Sn(1).div(r.y))),c,s)),b.negate().add(Af(e.sub(En(0,Sn(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class Ef extends pu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const wf=(...e)=>hn(new Ef(...e));class Mf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Bf=fn(Mf),Uf=new ve,Ff=new i;class Pf extends Ar{static get type(){return"SceneNode"}constructor(e=Pf.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===Pf.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===Pf.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===Pf.BACKGROUND_ROTATION?r=ti("mat4").label("backgroundRotation").setGroup(Zn).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Uf.copy(s.backgroundRotation),Uf.x*=-1,Uf.y*=-1,Uf.z*=-1,Ff.makeRotationFromEuler(Uf)):Ff.identity(),Ff})):console.error("THREE.SceneNode: Unknown scope:",t),r}}Pf.BACKGROUND_BLURRINESS="backgroundBlurriness",Pf.BACKGROUND_INTENSITY="backgroundIntensity",Pf.BACKGROUND_ROTATION="backgroundRotation";const If=fn(Pf,Pf.BACKGROUND_BLURRINESS),Lf=fn(Pf,Pf.BACKGROUND_INTENSITY),Df=fn(Pf,Pf.BACKGROUND_ROTATION);class Vf extends Rr{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Of=mn(Vf),Gf="point-list",kf="line-list",zf="line-strip",$f="triangle-list",Hf="triangle-strip",Wf="never",jf="less",qf="equal",Kf="less-equal",Xf="greater",Yf="not-equal",Qf="greater-equal",Zf="always",Jf="store",ey="load",ty="clear",sy="ccw",ry="none",ny="front",iy="back",oy="uint16",ay="uint32",uy={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},ly="clamp-to-edge",dy="repeat",cy="mirror-repeat",hy="linear",py="nearest",gy="zero",my="one",fy="src",yy="one-minus-src",by="src-alpha",xy="one-minus-src-alpha",Ty="dst",_y="one-minus-dst",Ny="dst-alpha",vy="one-minus-dst-alpha",Sy="src-alpha-saturated",Ay="constant",Ry="one-minus-constant",Cy="add",Ey="subtract",wy="reverse-subtract",My="min",By="max",Uy=0,Fy=15,Py="keep",Iy="zero",Ly="replace",Dy="invert",Vy="increment-clamp",Oy="decrement-clamp",Gy="increment-wrap",ky="decrement-wrap",zy="storage",$y="read-only-storage",Hy="write-only",Wy="read-only",jy="float",qy="unfilterable-float",Ky="depth",Xy="sint",Yy="uint",Qy="2d",Zy="3d",Jy="2d",eb="2d-array",tb="cube",sb="3d",rb="all",nb="vertex",ib="instance",ob={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class ab extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=zy,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Of(this,e)}setBufferObject(e){return this.bufferObject=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess($y)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),r=s.build(e);return e.registerTransform(r,t),r}}const ub=(e,t,s)=>hn(new ab(e,t,s)),lb=(e,t,s)=>hn(new ab(e,t,s).setBufferObject(!0));class db extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Hy}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(Wy)}toWriteOnly(){return this.setAccess(Hy)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,n=super.generate(e,"property"),i=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,n,i,o);e.addLineFlowCode(a,this)}}const cb=mn(db),hb=(e,t,s)=>{const r=cb(e,t,s);return null!==s&&r.append(),r};class pb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const gb=(e,t,s)=>hn(new pb(e,t,s)),mb=new WeakMap;class fb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=ti(new i),this.previousProjectionMatrix=ti(new i).setGroup(Zn),this.previousCameraViewMatrix=ti(new i)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=bb(s);this.previousModelWorldMatrix.value.copy(r);const n=yb(t);n.frameId!==e&&(n.frameId=e,void 0===n.previousProjectionMatrix?(n.previousProjectionMatrix=new i,n.previousCameraViewMatrix=new i,n.currentProjectionMatrix=new i,n.currentCameraViewMatrix=new i,n.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(n.previousProjectionMatrix.copy(n.currentProjectionMatrix),n.previousCameraViewMatrix.copy(n.currentCameraViewMatrix)),n.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(n.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(n.previousCameraViewMatrix))}updateAfter({object:e}){bb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:ti(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),n=s.xy.div(s.w),i=r.xy.div(r.w);return Oi(n,i)}}function yb(e){let t=mb.get(e);return void 0===t&&(t={},mb.set(e,t)),t}function bb(e,t=0){const s=yb(e);let r=s[t];return void 0===r&&(s[t]=r=new i),r}const xb=fn(fb),Tb=yn((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),_b=yn((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Nb=yn((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=yn((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Sb=yn((([e,t])=>Ln(e.rgb.mul(t.a.oneMinus()).add(t.rgb.mul(t.a)),e.a))).setLayout({name:"blendNormal",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Ab=yn((([e])=>wb(e.rgb))),Rb=yn((([e,t=Sn(1)])=>t.mix(wb(e.rgb),e.rgb))),Cb=yn((([e,t=Sn(1)])=>{const s=Vi(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),n=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,n)})),Eb=yn((([e,t=Sn(1)])=>{const s=Un(.57735,.57735,.57735),r=t.cos();return Un(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),wb=(e,t=Un(u.getLuminanceCoefficients(new s)))=>ea(e,t),Mb=(e,t)=>la(Un(0),e,wb(e).sub(t).max(0)),Bb=yn((([e,t=Un(1),r=Un(0),n=Un(1),i=Sn(1),o=Un(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Un(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(n).toVar();return _n(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),_n(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),_n(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(i))),Ln(l.rgb,e.a)}));class Ub extends Er{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Fb=mn(Ub);let Pb=null;class Ib extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Pb&&(Pb=new w),super(e,t,Pb)}updateReference(){return this}}const Lb=mn(Ib),Db=new t;class Vb extends Tu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class Ob extends Vb{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class Gb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const n=new B;n.isRenderTargetTexture=!0,n.name="depth";const i=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});i.texture.name="output",i.depthTexture=n,this.renderTarget=i,this.updateBeforeType=br.FRAME,this._textures={output:i.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=ti(0),this._cameraFar=ti(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=hn(new Ob(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=hn(new Ob(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(n,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===Gb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const n=t.getSize(Db);this.setSize(n.width,n.height);const i=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(i),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Gb.COLOR="color",Gb.DEPTH="depth";const kb=(e,t,s)=>hn(new Gb(Gb.COLOR,e,t,s)),zb=(e,t)=>hn(new Vb(e,t)),$b=(e,t)=>hn(new Gb(Gb.DEPTH,e,t));class Hb extends Gb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,n){super(Gb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=n,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,n,i,o,a,u)=>{if((i.isMeshToonMaterial||i.isMeshToonNodeMaterial)&&!1===i.wireframe){const l=this._getOutlineMaterial(i);t.renderObject(e,s,r,n,l,o,a,u)}t.renderObject(e,s,r,n,i,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new nh;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=Sn(1),n=s.mul(Ln(Yu,1)),i=s.mul(Ln(Yu.add(t),1)),o=Ao(n.sub(i));return e.vertexNode=n.add(o.mul(this.thicknessNode).mul(n.w).mul(r)),e.colorNode=Ln(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const Wb=(t,s,r=new e(0,0,0),n=.003,i=1)=>hn(new Hb(t,s,hn(r),hn(n),hn(i))),jb=yn((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),qb=yn((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Kb=yn((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=yn((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Yb=yn((([e,t])=>{const s=kn(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=kn(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=Xb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qb=kn(Un(1.6605,-.1246,-.0182),Un(-.5876,1.1329,-.1006),Un(-.0728,-.0083,1.1187)),Zb=kn(Un(.6274,.0691,.0164),Un(.3293,.9195,.088),Un(.0433,.0113,.8956)),Jb=yn((([e])=>{const t=Un(e).toVar(),s=Un(t.mul(t)).toVar(),r=Un(s.mul(s)).toVar();return Sn(15.5).mul(r.mul(s)).sub(Gi(40.14,r.mul(t))).add(Gi(31.96,r).sub(Gi(6.868,s.mul(t))).add(Gi(.4298,s).add(Gi(.1191,t).sub(.00232))))})),ex=yn((([e,t])=>{const s=Un(e).toVar(),r=kn(Un(.856627153315983,.137318972929847,.11189821299995),Un(.0951212405381588,.761241990602591,.0767994186031903),Un(.0482516061458583,.101439036467562,.811302368396859)),n=kn(Un(1.1271005818144368,-.1413297634984383,-.14132976349843826),Un(-.11060664309660323,1.157823702216272,-.11060664309660294),Un(-.016493938717834573,-.016493938717834257,1.2519364065950405)),i=Sn(-12.47393),o=Sn(4.026069);return s.mulAssign(t),s.assign(Zb.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(i).div(o.sub(i))),s.assign(da(s,0,1)),s.assign(Jb(s)),s.assign(n.mul(s)),s.assign(sa(Ko(Un(0),s),Un(2.2))),s.assign(Qb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),tx=yn((([e,t])=>{const s=Sn(.76),r=Sn(.15);e=e.mul(t);const n=qo(e.r,qo(e.g,e.b)),i=xa(n.lessThan(.08),n.sub(Gi(6.25,n.mul(n))),.04);e.subAssign(i);const o=Ko(e.r,Ko(e.g,e.b));_n(o.lessThan(s),(()=>e));const a=Oi(1,s),u=Oi(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=Oi(1,ki(1,r.mul(o.sub(u)).add(1)));return la(e,Un(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class sx extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const rx=mn(sx),nx=(e,t)=>rx(e,t,"js"),ix=(e,t)=>rx(e,t,"wgsl"),ox=(e,t)=>rx(e,t,"glsl");class ax extends sx{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,n=s.type,i=e.getCodeFromNode(this,n);""!==r&&(i.name=r);const o=e.getPropertyName(i),a=this.getNodeFunction(e).getCode(o);return i.code=a+"\n","property"===t?o:e.format(`${o}()`,n,t)}}const ux=(e,t=[],s="")=>{for(let e=0;er.call(...e);return n.functionNode=r,n},lx=(e,t)=>ux(e,t,"glsl"),dx=(e,t)=>ux(e,t,"wgsl");class cx extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:Sn()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const hx=mn(cx);class px extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class gx{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const mx=new px;class fx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new px,this._output=hx(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=hx(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=hx(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new gx(this),t=mx.get("THREE"),s=mx.get("TSL"),r=this.getMethod(this.codeNode),n=[e,this._local,mx,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...n);const i=this._object.layout;if(i&&(!1===i.cache&&this._local.clear(),this._output.outputType=i.outputType||null,Array.isArray(i.elements)))for(const e of i.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:Sn()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const yx=mn(fx);class bx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const xx=mn(bx);class Tx extends bx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const _x=mn(Tx);class Nx extends bx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const vx=mn(Nx);let Sx=null,Ax=null;class Rx extends Ar{static get type(){return"RangeNode"}constructor(e=Sn(),t=Sn()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const n=this.minNode.value,i=this.maxNode.value,o=e.getTypeLength(hr(n)),u=e.getTypeLength(hr(i));Sx=Sx||new r,Ax=Ax||new r,Sx.setScalar(0),Ax.setScalar(0),1===o?Sx.setScalar(n):n.isColor?Sx.set(n.r,n.g,n.b):Sx.set(n.x,n.y,n.z||0,n.w||0),1===u?Ax.setScalar(i):i.isColor?Ax.set(i.r,i.g,i.b):Ax.set(i.x,i.y,i.z||0,i.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;ehn(new Ex(e,t)),Mx=wx("numWorkgroups","uvec3"),Bx=wx("workgroupId","uvec3"),Ux=wx("localId","uvec3"),Fx=wx("subgroupSize","uint");const Px=mn(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Ix=()=>Px("workgroup").append(),Lx=()=>Px("storage").append(),Dx=()=>Px("texture").append();class Vx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class Ox extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return hn(new Vx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const Gx=(e,t)=>hn(new Ox("Workgroup",e,t));class kx extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),n=this.pointerNode,i=this.valueNode,o=[];o.push(`&${n.build(e,r)}`),o.push(i.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}kx.ATOMIC_LOAD="atomicLoad",kx.ATOMIC_STORE="atomicStore",kx.ATOMIC_ADD="atomicAdd",kx.ATOMIC_SUB="atomicSub",kx.ATOMIC_MAX="atomicMax",kx.ATOMIC_MIN="atomicMin",kx.ATOMIC_AND="atomicAnd",kx.ATOMIC_OR="atomicOr",kx.ATOMIC_XOR="atomicXor";const zx=mn(kx),$x=(e,t,s,r)=>{const n=zx(e,t,s,r);return n.append(),n},Hx=(e,t,s=null)=>$x(kx.ATOMIC_STORE,e,t,s),Wx=(e,t,s=null)=>$x(kx.ATOMIC_ADD,e,t,s),jx=(e,t,s=null)=>$x(kx.ATOMIC_SUB,e,t,s),qx=(e,t,s=null)=>$x(kx.ATOMIC_MAX,e,t,s),Kx=(e,t,s=null)=>$x(kx.ATOMIC_MIN,e,t,s),Xx=(e,t,s=null)=>$x(kx.ATOMIC_AND,e,t,s),Yx=(e,t,s=null)=>$x(kx.ATOMIC_OR,e,t,s),Qx=(e,t,s=null)=>$x(kx.ATOMIC_XOR,e,t,s);let Zx;function Jx(e){Zx=Zx||new WeakMap;let t=Zx.get(e);return void 0===t&&Zx.set(e,t={}),t}function eT(e){const t=Jx(e);return t.position||(t.position=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function tT(e){const t=Jx(e);return t.targetPosition||(t.targetPosition=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function sT(e){const t=Jx(e);return t.viewPosition||(t.viewPosition=ti(new s).setGroup(Zn).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const rT=e=>Eu.transformDirection(eT(e).sub(tT(e))),nT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},iT=new WeakMap;class oT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Un().toVar("totalDiffuse"),this.totalSpecularNode=Un().toVar("totalSpecular"),this.outgoingLightNode=Un().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),n=e.renderer.library;for(const e of r)if(e.isNode)t.push(hn(e));else{let r=null;if(null!==s&&(r=nT(e.id,s)),null===r){const s=n.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;iT.has(e)?r=iT.get(e):(r=hn(new s(e)),iT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:n,totalDiffuseNode:i,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,n),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Un(null!==l?l.mix(g,u):u),t.material.transparent=!0),i.assign(g),o.assign(c.add(p)),r.assign(i.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const aT=(e=[])=>hn(new oT).setLights(e),uT=yn((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),lT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=Ml("radius","float",s).setGroup(Zn),o=En(1).div(n),a=o.x.negate().mul(i),u=o.y.negate().mul(i),l=o.x.mul(i),d=o.y.mul(i),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vi(r(t.xy.add(En(a,u)),t.z),r(t.xy.add(En(0,u)),t.z),r(t.xy.add(En(l,u)),t.z),r(t.xy.add(En(c,h)),t.z),r(t.xy.add(En(0,h)),t.z),r(t.xy.add(En(p,h)),t.z),r(t.xy.add(En(a,0)),t.z),r(t.xy.add(En(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(En(p,0)),t.z),r(t.xy.add(En(l,0)),t.z),r(t.xy.add(En(c,g)),t.z),r(t.xy.add(En(0,g)),t.z),r(t.xy.add(En(p,g)),t.z),r(t.xy.add(En(a,d)),t.z),r(t.xy.add(En(0,d)),t.z),r(t.xy.add(En(l,d)),t.z)).mul(1/17)})),dT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=En(1).div(n),o=i.x,a=i.y,u=t.xy,l=Ro(u.mul(n).add(.5));return u.subAssign(l.mul(i)),Vi(r(u,t.z),r(u.add(En(o,0)),t.z),r(u.add(En(0,a)),t.z),r(u.add(i),t.z),la(r(u.add(En(o.negate(),0)),t.z),r(u.add(En(o.mul(2),0)),t.z),l.x),la(r(u.add(En(o.negate(),a)),t.z),r(u.add(En(o.mul(2),a)),t.z),l.x),la(r(u.add(En(0,a.negate())),t.z),r(u.add(En(0,a.mul(2))),t.z),l.y),la(r(u.add(En(o,a.negate())),t.z),r(u.add(En(o,a.mul(2))),t.z),l.y),la(la(r(u.add(En(o.negate(),a.negate())),t.z),r(u.add(En(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(En(o.negate(),a.mul(2))),t.z),r(u.add(En(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),cT=yn((({depthTexture:e,shadowCoord:t})=>{const s=Sn(1).toVar(),r=_u(e).uv(t.xy).rg,n=Yo(t.z,r.x);return _n(n.notEqual(Sn(1)),(()=>{const e=t.z.sub(r.x),i=Ko(0,r.y.mul(r.y));let o=i.div(i.add(e.mul(e)));o=da(Oi(o,.3).div(.95-.3)),s.assign(da(Ko(n,o)))})),s})),hT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(0,u).mul(t)).div(s)).x;n.addAssign(l),i.addAssign(l.mul(l))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),pT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(u,0).mul(t)).div(s));n.addAssign(l.x),i.addAssign(Vi(l.y.mul(l.y),l.x.mul(l.x)))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),gT=[uT,lT,dT,cT];let mT=null;const fT=new Tf;class yT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===mT&&(mT=new nh,mT.fragmentNode=Ln(0,0,0,1),mT.isShadowNodeMaterial=!0,mT.name="ShadowMaterial");const r=this.shadow,n=s.shadowMap.type,i=new B(r.mapSize.width,r.mapSize.height);i.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=i,r.camera.updateProjectionMatrix(),n===Re){i.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(i),s=_u(this.vsmShadowMapVertical.texture),n=Ml("blurSamples","float",r).setGroup(Zn),o=Ml("radius","float",r).setGroup(Zn),a=Ml("mapSize","vec2",r).setGroup(Zn);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new nh);u.fragmentNode=hT({samples:n,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new nh),u.fragmentNode=pT({samples:n,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Zn),u=Ml("bias","float",r).setGroup(Zn),l=Ml("normalBias","float",r).setGroup(Zn),d=t.material.shadowPositionNode||Zu;let c,h=ti(r.matrix).setGroup(Zn).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=Ml("near","float",r.camera).setGroup(Zn),s=Ml("far","float",r.camera).setGroup(Zn);c=qc(e.negate(),t,s)}h=Un(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||gT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:n===Re?this.vsmShadowMapHorizontal.texture:i,shadowCoord:h,shadow:r}),Sn(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:n,scene:i,camera:o}=e,a=n.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=i.overrideMaterial;i.overrideMaterial=mT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=n.getRenderTarget(),c=n.getRenderObjectFunction();n.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&n.renderObject(e,...t)})),n.setRenderTarget(t),n.render(i,r.camera),n.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(n),n.setRenderTarget(d),i.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),fT.material=this.vsmMaterialVertical,fT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),fT.material=this.vsmMaterialHorizontal,fT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const bT=(e,t)=>hn(new yT(e,t));class xT extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=ti(this.color).setGroup(Zn),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?hn(e):bT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const TT=yn((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,n=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(n.mul(t.div(s).pow4().oneMinus().clamp().pow2()),n)})),_T=yn((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},n)=>{const i=n.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=TT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=n.context.reflectedLight;i.direct({lightDirection:a,lightColor:d,reflectedLight:c},n.stack,n)}));class NT extends xT{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){_T({color:this.colorNode,lightViewPosition:sT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const vT=yn((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),ST=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Cn(e).toVar();return xa(i,n,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),AT=yn((([e,t])=>{const s=Cn(t).toVar(),r=Sn(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),RT=yn((([e])=>{const t=Sn(e).toVar();return An(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),CT=yn((([e,t])=>{const s=Sn(e).toVar();return t.assign(RT(s)),s.sub(Sn(t))})),ET=Fm([yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Sn(r).toVar(),l=Sn(s).toVar(),d=Sn(t).toVar(),c=Sn(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Un(r).toVar(),l=Un(s).toVar(),d=Un(t).toVar(),c=Un(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),wT=Fm([yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Sn(a).toVar(),m=Sn(o).toVar(),f=Sn(i).toVar(),y=Sn(n).toVar(),b=Sn(r).toVar(),x=Sn(s).toVar(),T=Sn(t).toVar(),_=Sn(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Un(a).toVar(),m=Un(o).toVar(),f=Un(i).toVar(),y=Un(n).toVar(),b=Un(r).toVar(),x=Un(s).toVar(),T=Un(t).toVar(),_=Un(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),MT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Rn(e).toVar(),o=Rn(i.bitAnd(Rn(7))).toVar(),a=Sn(ST(o.lessThan(Rn(4)),n,r)).toVar(),u=Sn(Gi(2,ST(o.lessThan(Rn(4)),r,n))).toVar();return AT(a,Cn(o.bitAnd(Rn(1)))).add(AT(u,Cn(o.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),BT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Rn(e).toVar(),u=Rn(a.bitAnd(Rn(15))).toVar(),l=Sn(ST(u.lessThan(Rn(8)),o,i)).toVar(),d=Sn(ST(u.lessThan(Rn(4)),i,ST(u.equal(Rn(12)).or(u.equal(Rn(14))),o,n))).toVar();return AT(l,Cn(u.bitAnd(Rn(1)))).add(AT(d,Cn(u.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),UT=Fm([MT,BT]),FT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Pn(e).toVar();return Un(UT(i.x,n,r),UT(i.y,n,r),UT(i.z,n,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),PT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Pn(e).toVar();return Un(UT(a.x,o,i,n),UT(a.y,o,i,n),UT(a.z,o,i,n))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),IT=Fm([FT,PT]),LT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),DT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),VT=Fm([LT,yn((([e])=>{const t=Un(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),OT=Fm([DT,yn((([e])=>{const t=Un(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),GT=yn((([e,t])=>{const s=An(t).toVar(),r=Rn(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(An(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),kT=yn((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(GT(s,An(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,An(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,An(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(GT(s,An(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,An(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,An(4))),t.addAssign(e)})),zT=yn((([e,t,s])=>{const r=Rn(s).toVar(),n=Rn(t).toVar(),i=Rn(e).toVar();return r.bitXorAssign(n),r.subAssign(GT(n,An(14))),i.bitXorAssign(r),i.subAssign(GT(r,An(11))),n.bitXorAssign(i),n.subAssign(GT(i,An(25))),r.bitXorAssign(n),r.subAssign(GT(n,An(16))),i.bitXorAssign(r),i.subAssign(GT(r,An(4))),n.bitXorAssign(i),n.subAssign(GT(i,An(14))),r.bitXorAssign(n),r.subAssign(GT(n,An(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),$T=yn((([e])=>{const t=Rn(e).toVar();return Sn(t).div(Sn(Rn(An(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),HT=yn((([e])=>{const t=Sn(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),WT=Fm([yn((([e])=>{const t=An(e).toVar(),s=Rn(Rn(1)).toVar(),r=Rn(Rn(An(3735928559)).add(s.shiftLeft(Rn(2))).add(Rn(13))).toVar();return zT(r.add(Rn(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(Rn(2)).toVar(),i=Rn().toVar(),o=Rn().toVar(),a=Rn().toVar();return i.assign(o.assign(a.assign(Rn(An(3735928559)).add(n.shiftLeft(Rn(2))).add(Rn(13))))),i.addAssign(Rn(r)),o.addAssign(Rn(s)),zT(i,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(Rn(3)).toVar(),a=Rn().toVar(),u=Rn().toVar(),l=Rn().toVar();return a.assign(u.assign(l.assign(Rn(An(3735928559)).add(o.shiftLeft(Rn(2))).add(Rn(13))))),a.addAssign(Rn(i)),u.addAssign(Rn(n)),l.addAssign(Rn(r)),zT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),yn((([e,t,s,r])=>{const n=An(r).toVar(),i=An(s).toVar(),o=An(t).toVar(),a=An(e).toVar(),u=Rn(Rn(4)).toVar(),l=Rn().toVar(),d=Rn().toVar(),c=Rn().toVar();return l.assign(d.assign(c.assign(Rn(An(3735928559)).add(u.shiftLeft(Rn(2))).add(Rn(13))))),l.addAssign(Rn(a)),d.addAssign(Rn(o)),c.addAssign(Rn(i)),kT(l,d,c),l.addAssign(Rn(n)),zT(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),yn((([e,t,s,r,n])=>{const i=An(n).toVar(),o=An(r).toVar(),a=An(s).toVar(),u=An(t).toVar(),l=An(e).toVar(),d=Rn(Rn(5)).toVar(),c=Rn().toVar(),h=Rn().toVar(),p=Rn().toVar();return c.assign(h.assign(p.assign(Rn(An(3735928559)).add(d.shiftLeft(Rn(2))).add(Rn(13))))),c.addAssign(Rn(l)),h.addAssign(Rn(u)),p.addAssign(Rn(a)),kT(c,h,p),c.addAssign(Rn(o)),h.addAssign(Rn(i)),zT(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),jT=Fm([yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(WT(r,s)).toVar(),i=Pn().toVar();return i.x.assign(n.bitAnd(An(255))),i.y.assign(n.shiftRight(An(8)).bitAnd(An(255))),i.z.assign(n.shiftRight(An(16)).bitAnd(An(255))),i})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(WT(i,n,r)).toVar(),a=Pn().toVar();return a.x.assign(o.bitAnd(An(255))),a.y.assign(o.shiftRight(An(8)).bitAnd(An(255))),a.z.assign(o.shiftRight(An(16)).bitAnd(An(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),qT=Fm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(CT(t.x,s)).toVar(),i=Sn(CT(t.y,r)).toVar(),o=Sn(HT(n)).toVar(),a=Sn(HT(i)).toVar(),u=Sn(ET(UT(WT(s,r),n,i),UT(WT(s.add(An(1)),r),n.sub(1),i),UT(WT(s,r.add(An(1))),n,i.sub(1)),UT(WT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(CT(t.x,s)).toVar(),o=Sn(CT(t.y,r)).toVar(),a=Sn(CT(t.z,n)).toVar(),u=Sn(HT(i)).toVar(),l=Sn(HT(o)).toVar(),d=Sn(HT(a)).toVar(),c=Sn(wT(UT(WT(s,r,n),i,o,a),UT(WT(s.add(An(1)),r,n),i.sub(1),o,a),UT(WT(s,r.add(An(1)),n),i,o.sub(1),a),UT(WT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),UT(WT(s,r,n.add(An(1))),i,o,a.sub(1)),UT(WT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),UT(WT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),UT(WT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),KT=Fm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(CT(t.x,s)).toVar(),i=Sn(CT(t.y,r)).toVar(),o=Sn(HT(n)).toVar(),a=Sn(HT(i)).toVar(),u=Un(ET(IT(jT(s,r),n,i),IT(jT(s.add(An(1)),r),n.sub(1),i),IT(jT(s,r.add(An(1))),n,i.sub(1)),IT(jT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(CT(t.x,s)).toVar(),o=Sn(CT(t.y,r)).toVar(),a=Sn(CT(t.z,n)).toVar(),u=Sn(HT(i)).toVar(),l=Sn(HT(o)).toVar(),d=Sn(HT(a)).toVar(),c=Un(wT(IT(jT(s,r,n),i,o,a),IT(jT(s.add(An(1)),r,n),i.sub(1),o,a),IT(jT(s,r.add(An(1)),n),i,o.sub(1),a),IT(jT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),IT(jT(s,r,n.add(An(1))),i,o,a.sub(1)),IT(jT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),IT(jT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),IT(jT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),XT=Fm([yn((([e])=>{const t=Sn(e).toVar(),s=An(RT(t)).toVar();return $T(WT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar();return $T(WT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar(),n=An(RT(t.z)).toVar();return $T(WT(s,r,n))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar(),n=An(RT(t.z)).toVar(),i=An(RT(t.w)).toVar();return $T(WT(s,r,n,i))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),YT=Fm([yn((([e])=>{const t=Sn(e).toVar(),s=An(RT(t)).toVar();return Un($T(WT(s,An(0))),$T(WT(s,An(1))),$T(WT(s,An(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar();return Un($T(WT(s,r,An(0))),$T(WT(s,r,An(1))),$T(WT(s,r,An(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar(),n=An(RT(t.z)).toVar();return Un($T(WT(s,r,n,An(0))),$T(WT(s,r,n,An(1))),$T(WT(s,r,n,An(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar(),n=An(RT(t.z)).toVar(),i=An(RT(t.w)).toVar();return Un($T(WT(s,r,n,i,An(0))),$T(WT(s,r,n,i,An(1))),$T(WT(s,r,n,i,An(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),QT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Sn(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(qT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),ZT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(KT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),JT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar();return En(QT(a,o,i,n),QT(a.add(Un(An(19),An(193),An(17))),o,i,n))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),e_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(ZT(a,o,i,n)).toVar(),l=Sn(QT(a.add(Un(An(19),An(193),An(17))),o,i,n)).toVar();return Ln(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),t_=Fm([yn((([e,t,s,r,n,i,o])=>{const a=An(o).toVar(),u=Sn(i).toVar(),l=An(n).toVar(),d=An(r).toVar(),c=An(s).toVar(),h=An(t).toVar(),p=En(e).toVar(),g=Un(YT(En(h.add(d),c.add(l)))).toVar(),m=En(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=En(En(Sn(h),Sn(c)).add(m)).toVar(),y=En(f.sub(p)).toVar();return _n(a.equal(An(2)),(()=>Fo(y.x).add(Fo(y.y)))),_n(a.equal(An(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),yn((([e,t,s,r,n,i,o,a,u])=>{const l=An(u).toVar(),d=Sn(a).toVar(),c=An(o).toVar(),h=An(i).toVar(),p=An(n).toVar(),g=An(r).toVar(),m=An(s).toVar(),f=An(t).toVar(),y=Un(e).toVar(),b=Un(YT(Un(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Un(Un(Sn(f),Sn(m),Sn(g)).add(b)).toVar(),T=Un(x.sub(y)).toVar();return _n(l.equal(An(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),_n(l.equal(An(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),s_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(CT(i.x,o),CT(i.y,a)).toVar(),l=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(t_(u,e,t,o,a,n,r)).toVar();l.assign(qo(l,s))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),r_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(CT(i.x,o),CT(i.y,a)).toVar(),l=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(t_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),n_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(CT(i.x,o),CT(i.y,a)).toVar(),l=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(t_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=Fm([s_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(CT(i.x,o),CT(i.y,a),CT(i.z,u)).toVar(),d=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(t_(l,e,t,s,o,a,u,n,r)).toVar();d.assign(qo(d,i))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),o_=Fm([r_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(CT(i.x,o),CT(i.y,a),CT(i.z,u)).toVar(),d=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(t_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.y.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),a_=Fm([n_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(CT(i.x,o),CT(i.y,a),CT(i.z,u)).toVar(),d=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(t_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(i)})).ElseIf(i.lessThan(d.z),(()=>{d.z.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=yn((([e])=>{const t=e.y,s=e.z,r=Un().toVar();return _n(t.lessThan(1e-4),(()=>{r.assign(Un(s,s,s))})).Else((()=>{let n=e.x;n=n.sub(vo(n)).mul(6).toVar();const i=An(zo(n)),o=n.sub(Sn(i)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());_n(i.equal(An(0)),(()=>{r.assign(Un(s,l,a))})).ElseIf(i.equal(An(1)),(()=>{r.assign(Un(u,s,a))})).ElseIf(i.equal(An(2)),(()=>{r.assign(Un(a,s,l))})).ElseIf(i.equal(An(3)),(()=>{r.assign(Un(a,u,s))})).ElseIf(i.equal(An(4)),(()=>{r.assign(Un(l,a,s))})).Else((()=>{r.assign(Un(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),l_=yn((([e])=>{const t=Un(e).toVar(),s=Sn(t.x).toVar(),r=Sn(t.y).toVar(),n=Sn(t.z).toVar(),i=Sn(qo(s,qo(r,n))).toVar(),o=Sn(Ko(s,Ko(r,n))).toVar(),a=Sn(o.sub(i)).toVar(),u=Sn().toVar(),l=Sn().toVar(),d=Sn().toVar();return d.assign(o),_n(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),_n(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{_n(s.greaterThanEqual(o),(()=>{u.assign(r.sub(n).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vi(2,n.sub(s).div(a)))})).Else((()=>{u.assign(Vi(4,s.sub(r).div(a)))})),u.mulAssign(1/6),_n(u.lessThan(0),(()=>{u.addAssign(1)}))})),Un(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),d_=yn((([e])=>{const t=Un(e).toVar(),s=In(ji(t,Un(.04045))).toVar(),r=Un(t.div(12.92)).toVar(),n=Un(sa(Ko(t.add(Un(.055)),Un(0)).div(1.055),Un(2.4))).toVar();return la(r,n,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),c_=(e,t)=>{e=Sn(e),t=Sn(t);const s=En(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},h_=(e,t,s,r)=>la(e,t,s[r].clamp()),p_=(e,t,s=mu())=>h_(e,t,s,"x"),g_=(e,t,s=mu())=>h_(e,t,s,"y"),m_=(e,t,s,r,n)=>la(e,t,c_(s,r[n])),f_=(e,t,s,r=mu())=>m_(e,t,s,r,"x"),y_=(e,t,s,r=mu())=>m_(e,t,s,r,"y"),b_=(e=1,t=0,s=mu())=>s.mul(e).add(t),x_=(e,t=1)=>(e=Sn(e)).abs().pow(t).mul(e.sign()),T_=(e,t=1,s=.5)=>Sn(e).sub(s).mul(t).add(s),__=(e=mu(),t=1,s=0)=>qT(e.convert("vec2|vec3")).mul(t).add(s),N_=(e=mu(),t=1,s=0)=>KT(e.convert("vec2|vec3")).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ln(KT(e),qT(e.add(En(19,73)))).mul(t).add(s)},S_=(e=mu(),t=1)=>i_(e.convert("vec2|vec3"),t,An(1)),A_=(e=mu(),t=1)=>o_(e.convert("vec2|vec3"),t,An(1)),R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,An(1)),C_=(e=mu())=>XT(e.convert("vec2|vec3")),E_=(e=mu(),t=3,s=2,r=.5,n=1)=>QT(e,An(t),s,r).mul(n),w_=(e=mu(),t=3,s=2,r=.5,n=1)=>JT(e,An(t),s,r).mul(n),M_=(e=mu(),t=3,s=2,r=.5,n=1)=>ZT(e,An(t),s,r).mul(n),B_=(e=mu(),t=3,s=2,r=.5,n=1)=>e_(e,An(t),s,r).mul(n),U_=yn((([e,t,s])=>{const r=Ao(e).toVar("nDir"),n=Oi(Sn(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),i=Oi(Sn(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Un().toVar("rbminmax");o.x=r.x.greaterThan(Sn(0)).select(n.x,i.x),o.y=r.y.greaterThan(Sn(0)).select(n.y,i.y),o.z=r.z.greaterThan(Sn(0)).select(n.z,i.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),F_=yn((([e,t])=>{const s=e.x,r=e.y,n=e.z;let i=t.element(0).mul(.886227);return i=i.add(t.element(1).mul(1.023328).mul(r)),i=i.add(t.element(2).mul(1.023328).mul(n)),i=i.add(t.element(3).mul(1.023328).mul(s)),i=i.add(t.element(4).mul(.858086).mul(s).mul(r)),i=i.add(t.element(5).mul(.858086).mul(r).mul(n)),i=i.add(t.element(6).mul(n.mul(n).mul(.743125).sub(.247708))),i=i.add(t.element(7).mul(.858086).mul(s).mul(n)),i=i.add(t.element(8).mul(.429043).mul(Gi(s,s).sub(Gi(r,r)))),i})),P_=new hm;class I_ extends Dg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,n=this.nodes.getBackgroundNode(e)||e.background;let i=!1;if(null===n)r._clearColor.getRGB(P_,Se),P_.a=r._clearColor.a;else if(!0===n.isColor)n.getRGB(P_,Se),P_.a=1,i=!0;else if(!0===n.isNode){const s=this.get(e),i=n;P_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ln(i).mul(Lf),{getUV:()=>Df.mul(ll),getTextureLevel:()=>If});let t=Wd();t=t.setZ(t.w);const r=new nh;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=i.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ln(i).mul(Lf),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",n);if(!0===r.autoClear||!0===i){const e=s.clearColorValue;e.r=P_.r,e.g=P_.g,e.b=P_.b,e.a=P_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let L_=0;class D_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=L_++}}class V_{constructor(e,t,s,r,n,i,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=n,this.updateNodes=i,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new D_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class O_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class G_{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class k_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class z_ extends k_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class $_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let H_=0;class W_{constructor(e=null){this.id=H_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class j_{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class q_ extends j_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class K_ extends j_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class X_ extends j_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Y_ extends j_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class Q_ extends j_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends j_{constructor(e,t=new n){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class J_ extends j_{constructor(e,t=new i){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class eN extends q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class tN extends K_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const aN=[.125,.215,.35,.446,.526,.582],uN=20,lN=new xe(-1,1,1,-1,0,1),dN=new Be(90,1),cN=new e;let hN=null,pN=0,gN=0;const mN=(1+Math.sqrt(5))/2,fN=1/mN,yN=[new s(-mN,fN,0),new s(mN,fN,0),new s(-fN,0,mN),new s(fN,0,mN),new s(0,mN,-fN),new s(0,mN,fN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],bN=[3,1,5,0,4,2],xN=Hp(mu(),gu("faceIndex")).normalize(),TN=Un(xN.x,xN.y.negate(),xN.z);class _N{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(e,t=0,s=.1,r=100){hN=this._renderer.getRenderTarget(),pN=this._renderer.getActiveCubeFace(),gN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const n=this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(e,s,r,n),t>0&&this._blur(n,0,0,t),this._applyPMREM(n),this._cleanup(n),n}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=AN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=RN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=aN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],n=bN[e];b.set(r,m*g*n),x.set(h,f*g*n);const i=[n,n,n,n,n,n];T.set(i,y*g*n)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),n.push(new k(_,null)),i>4&&i--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:n}}(n)),this._blurMaterial=function(e,t,r){const n=Rl(new Array(uN).fill(0)),i=ti(new s(0,1,0)),o=ti(0),a=Sn(uN),u=ti(0),l=ti(1),d=_u(null),c=ti(0),h=Sn(1/t),p=Sn(1/r),g=Sn(e),m={n:a,latitudinal:u,weights:n,poleAxis:i,outputDirection:TN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=SN("blur");return f.uniforms=m,f.fragmentNode=Kp({...m,latitudinal:u.equal(1)}),f}(n,e,t)}return n}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,lN)}_sceneToCubeUV(e,t,s,r){const n=dN;n.near=t,n.far=s;const i=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(cN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(cN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,n);for(let t=0;t<6;t++){const s=t%3;0===s?(n.up.set(0,i[t],0),n.lookAt(o[t],0,0)):1===s?(n.up.set(0,0,i[t]),n.lookAt(0,o[t],0)):(n.up.set(0,i[t],0),n.lookAt(0,0,o[t]));const u=this._cubeSize;vN(r,s*u,t>2?u:0,u,u),a.render(e,n)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=AN(e)):null===this._equirectMaterial&&(this._equirectMaterial=RN(e));const n=r?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=n;const o=this._cubeSize;vN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(i,lN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;tuN&&console.warn(`sigmaRadians, ${n}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,lN)}}function NN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function vN(e,t,s,r,n){e.viewport.set(t,s,r,n),e.scissor.set(t,s,r,n)}function SN(e){const t=new nh;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function AN(e){const t=SN("cubemap");return t.fragmentNode=_l(e,TN),t}function RN(e){const t=SN("equirect");return t.fragmentNode=_u(e,bh(TN),0),t}const CN=new WeakMap,EN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),wN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),MN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class BN{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=fm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new W_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=CN.get(this.renderer);return void 0===e&&(e=new Ug,CN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new xh(e,t)}createPMREMGenerator(){return new _N(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let n,i=!0;for(const e of t)r.push(e),i=i&&!0!==e.groupNode.shared;return i?(n=s.get(r),void 0===n&&(n=new D_(e,r,this.bindingsIndexes[e].group,r),s.set(r,n))):n=new D_(e,r,this.bindingsIndexes[e].group,r),n}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const n=s[e][r];(t[r]||(t[r]=[])).push(...n)}e=[];for(const s in t){const r=t[s],n=this._getBindGroup(s,r);e.push(n)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(i)}u`:"0u";if("bool"===n)return i?"true":"false";if("color"===n)return`${this.getType("vec3")}( ${MN(i.r)}, ${MN(i.g)}, ${MN(i.b)} )`;const o=this.getTypeLength(n),a=this.getComponentType(n),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)} )`;if(3===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)} )`;if(4===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)}, ${u(i.w)} )`;if(o>4&&i&&(i.isMatrix3||i.isMatrix4))return`${this.getType(n)}( ${i.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(n)}()`;throw new Error(`NodeBuilder: Type '${n}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new O_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=EN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return wN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,n=e.normalized;let i;return e instanceof Ie||!0===n||(i=this.getTypeFromArray(s)),this.getTypeFromLength(r,i)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=fm(this.stack),this.stacks.push(Tn()||this.stack),xn(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,xn(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(void 0===r){const n=this.uniforms.index++;r=new O_("nodeAttribute"+n,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const n=this.getDataFromNode(e,s,this.globalCache);let i=n.uniform;if(void 0===i){const o=this.uniforms.index++;i=new G_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(i),n.uniform=i}return i}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const n=this.getDataFromNode(e,r);let i=n.variable;if(void 0===i){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),i=new k_(t,s),e.push(i),n.variable=i}return i}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let n=r.varying;if(void 0===n){const e=this.varyings,i=e.length;null===t&&(t="nodeVarying"+i),n=new z_(t,s),e.push(n),r.varying=n}return n}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let n=r.code;if(void 0===n){const e=this.codes[s]||(this.codes[s]=[]),i=e.length;n=new $_("nodeCode"+i,t),e.push(n),r.code=n}return n}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let n=!0,i=t;for(;i;){if(!0===r.get(i)){n=!1;break}i=this.getDataFromNode(i).parentNodeBlock}if(n)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),n=r.flowCodes||(r.flowCodes=[]),i=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);n.push(t),i.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new ax,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new pm(e.type,e.name);e.layout=null;const r=e.call(s),n=this.flowStagesNode(r,t.type);return e.layout=t,n}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,n=this.cache,i=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new W_,this.stack=fm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=n,this.stack=o,this.setBuildStage(i),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const n=this.shaderStage;this.setShaderStage(e);const i=this.flowChildNode(t,s);return null!==r&&(i.code+=`${this.tab+r} = ${i.result};\n`),this.flowCode[e]=this.flowCode[e]+i.code,this.setShaderStage(n),i}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new nh),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new eN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new tN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new sN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new rN(e);if("color"===t)return new nN(e);if("mat3"===t)return new iN(e);if("mat4"===t)return new oN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),n=this.getTypeLength(s);return 16===r&&9===n?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===n?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||n>4||0===n?e:r===n?`${this.getType(s)}( ${e} )`:r>n?this.format(`${e}.${"xyz".slice(0,n)}`,this.getTypeFromLength(n,this.getComponentType(t)),s):4===n&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&n>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class UN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class FN{constructor(e,t,s=null,r="",n=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=n}}FN.isNodeFunctionInput=!0;class PN extends xT{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=rT(this.light),n=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:n},e.stack,e)}}const IN=new i,LN=new i;let DN=null;class VN extends xT{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=ti(new s).setGroup(Zn),this.halfWidth=ti(new s).setGroup(Zn),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;LN.identity(),IN.copy(t.matrixWorld),IN.premultiply(s),LN.extractRotation(IN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(LN),this.halfHeight.value.applyMatrix4(LN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(DN.LTC_FLOAT_1),s=_u(DN.LTC_FLOAT_2)):(t=_u(DN.LTC_HALF_1),s=_u(DN.LTC_HALF_2));const{colorNode:r,light:n}=this,i=e.context.lightingModel,o=sT(n),a=e.context.reflectedLight;i.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){DN=e}}class ON extends xT{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=ti(0).setGroup(Zn),this.penumbraCosNode=ti(0).setGroup(Zn),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:n,light:i}=this,o=sT(i).sub(el),a=o.normalize(),u=a.dot(rT(i)),l=this.getSpotAttenuation(u),d=o.length(),c=TT({lightDistance:d,cutoffDistance:r,decayExponent:n}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class GN extends ON{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,En(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class kN extends xT{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class zN extends xT{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=eT(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=ti(new e).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:r}=this,n=ul.dot(r).mul(.5).add(.5),i=la(s,t,n);e.context.irradiance.addAssign(i)}}class $N extends xT{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=F_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class HN{parseFunction(){console.warn("Abstract function.")}}class WN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}WN.isNodeFunction=!0;const jN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,qN=/[a-z_0-9]+/gi,KN="#pragma main";class XN extends WN{constructor(e){const{type:t,inputs:s,name:r,precision:n,inputsCode:i,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(KN),s=-1!==t?e.slice(t+12):e,r=s.match(jN);if(null!==r&&5===r.length){const n=r[4],i=[];let o=null;for(;null!==(o=qN.exec(n));)i.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Jp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=Sh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Zn),r=Ml("density","float",s).setGroup(Zn);e=vx(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Zn),r=Ml("near","float",s).setGroup(Zn),n=Ml("far","float",s).setGroup(Zn);e=_x(t,r,n)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,n=null){const i=this.nodeFrame;return i.renderer=e,i.scene=t,i.object=s,i.camera=r,i.material=n,i}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return QN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return QN.set(e,s),r}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new UN,this.nodeBuilderCache=new Map}}const JN=new me;class ev{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new n,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let n=0;n{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),n=this._renderContexts.get(e,t,this._renderTarget),i=e.overrideMaterial||s.material,o=this._objects.get(s,i,e,t,r.lightsNode,n,n.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ZN(this,s),this._animation=new Bg(this._nodes,this.info),this._attributes=new $g(s),this._background=new I_(this,this._nodes),this._geometries=new jg(this._attributes,this.info),this._textures=new cm(this,s,this.info),this._pipelines=new Jg(s,this._nodes),this._bindings=new em(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Lg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new im(this.lighting),this._bundles=new sv,this._renderContexts=new lm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,n=r.renderId,i=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:ov;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new ev),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=n,this._currentRenderContext=i,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:n,renderList:i}=e,o=this._currentRenderContext,a=this._bundles.get(r,n),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=i.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,n,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(uv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(uv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new ev),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),dv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),lv.setFromProjectionMatrix(dv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),n.renderId=i,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,r){const n=this._scissor;e.isVector4?n.copy(e):n.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,n=0,i=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=n,o.maxDepth=i}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let n=null;if(null!==r&&(this._textures.updateRenderTarget(r),n=this._textures.get(r)),this.backend.clear(e,t,s,n),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const r=this.backend,n=this._pipelines,i=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===n.has(t)){const e=()=>{t.removeEventListener("dispose",e),n.delete(t),i.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),i.updateForCompute(t);const s=i.getForCompute(t),a=n.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=cv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=cv.copy(t).floor()}else t=cv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,n)}readRenderTargetPixelsAsync(e,t,s,r,n,i=0,o=0){return this.backend.copyTextureToBuffer(e.textures[i],t,s,r,n,o)}_projectObject(e,t,s,r,n){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(n=n.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||lv.intersectsSprite(e)){!0===this.sortObjects&&cv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(dv);const{geometry:t,material:i}=e;i.visible&&r.push(e,t,i,s,cv.z,null,n)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||lv.intersectsObject(e))){const{geometry:t,material:i}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),cv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(dv)),Array.isArray(i)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,n,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,n);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,n)}_renderObjects(e,t,s,r,n=null){for(let i=0,o=e.length;i0?r:"";t=`${e.name} {\n\t${s} ${n.name}[${i}];\n};\n`}else{t=`${this.getVectorType(n.type)} ${this.getPropertyName(n,e)};`,i=!0}const o=n.node.precision;if(null!==o&&(t=Cv[o]+" "+t),i){t="\t"+t;const e=n.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let n="";for(const t in r){const s=r[t];n+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return n+=s.join("\n"),n}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Ev[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Ev[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${i}\n\t`),s+=`${r.code}\n\t`,e===n&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const i=e[t];i.extensions=this.getExtensions(t),i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.vars=this.getVars(t),i.structs=this.getStructs(t),i.codes=this.getCodes(t),i.transforms=this.getTransforms(t),i.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);let o=i.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new vv(n.name,n.node,r),u.push(o);else if("cubeTexture"===t)o=new Sv(n.name,n.node,r),u.push(o);else if("texture3D"===t)o=new Av(n.name,n.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,n.name=`buffer${e.id}`;const t=new yv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Tv(s+"_"+a,r),e[a]=i,u.push(i)),o=this.getNodeUniform(n,t),i.addUniform(o)}i.uniformGPU=o}return n}}let Bv=null,Uv=null,Fv=null;class Pv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Bv=Bv||new t,this.renderer.getDrawingBufferSize(Bv)}getScissor(){return Uv=Uv||new r,this.renderer.getScissor(Uv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Fv=Fv||new hm,e.getClearColor(Fv),Fv.getRGB(Fv,this.renderer.currentColorSpace),Fv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Iv=0;class Lv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Dv{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,n=e.array,i=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,n,i),a.bufferGPU=l,a.bufferType=t,a.version=o.version),n instanceof Float32Array)u=r.FLOAT;else if(n instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(n instanceof Int16Array)u=r.SHORT;else if(n instanceof Uint32Array)u=r.UNSIGNED_INT;else if(n instanceof Int32Array)u=r.INT;else if(n instanceof Int8Array)u=r.BYTE;else if(n instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Iv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,n,i);d=new Lv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,n=e.isInterleavedBufferAttribute?e.data:e,i=t.get(n),o=i.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,i.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t{!function n(){const i=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(i===e.WAIT_FAILED)return e.deleteSync(t),void r();i!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(n)}()}))}}let $v,Hv,Wv,jv=!1;class qv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===jv&&(this._init(this.gl),jv=!0)}_init(e){$v={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},Hv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},Wv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,n=!1){const{gl:i,extensions:o}=this;if(null!==e){if(void 0!==i[e])return i[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===i.RED&&(s===i.FLOAT&&(a=i.R32F),s===i.HALF_FLOAT&&(a=i.R16F),s===i.UNSIGNED_BYTE&&(a=i.R8),s===i.UNSIGNED_SHORT&&(a=i.R16),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RED_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.R8UI),s===i.UNSIGNED_SHORT&&(a=i.R16UI),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RG&&(s===i.FLOAT&&(a=i.RG32F),s===i.HALF_FLOAT&&(a=i.RG16F),s===i.UNSIGNED_BYTE&&(a=i.RG8),s===i.UNSIGNED_SHORT&&(a=i.RG16),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RG_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RG8UI),s===i.UNSIGNED_SHORT&&(a=i.RG16UI),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RGB&&(s===i.FLOAT&&(a=i.RGB32F),s===i.HALF_FLOAT&&(a=i.RGB16F),s===i.UNSIGNED_BYTE&&(a=i.RGB8),s===i.UNSIGNED_SHORT&&(a=i.RGB16),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8:i.RGB8),s===i.UNSIGNED_SHORT_5_6_5&&(a=i.RGB565),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGB4),s===i.UNSIGNED_INT_5_9_9_9_REV&&(a=i.RGB9_E5)),t===i.RGB_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGB8UI),s===i.UNSIGNED_SHORT&&(a=i.RGB16UI),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I)),t===i.RGBA&&(s===i.FLOAT&&(a=i.RGBA32F),s===i.HALF_FLOAT&&(a=i.RGBA16F),s===i.UNSIGNED_BYTE&&(a=i.RGBA8),s===i.UNSIGNED_SHORT&&(a=i.RGBA16),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8_ALPHA8:i.RGBA8),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGBA4),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1)),t===i.RGBA_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGBA8UI),s===i.UNSIGNED_SHORT&&(a=i.RGBA16UI),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I)),t===i.DEPTH_COMPONENT&&(s===i.UNSIGNED_INT&&(a=i.DEPTH24_STENCIL8),s===i.FLOAT&&(a=i.DEPTH_COMPONENT32F)),t===i.DEPTH_STENCIL&&s===i.UNSIGNED_INT_24_8&&(a=i.DEPTH24_STENCIL8),a!==i.R16F&&a!==i.R32F&&a!==i.RG16F&&a!==i.RG32F&&a!==i.RGBA16F&&a!==i.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:n}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,$v[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,$v[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,$v[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,Hv[t.magFilter]);const i=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&i?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,Hv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,Wv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const i=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,n.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,n=this.getGLTextureType(e);let i=r[n];void 0===i&&(i=t.createTexture(),s.state.bindTexture(n,i),t.texParameteri(n,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(n,t.TEXTURE_MAG_FILTER,t.NEAREST),r[n]=i),s.set(e,{textureGPU:i,glTextureType:n,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:n,width:i,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,n,d,i,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,n,d,i,o,a):e.isVideoTexture||s.texStorage2D(h,n,d,i,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:n,glTextureType:i,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(i,n),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(i,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:n}=t,{textureGPU:i,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===i)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,i),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,n=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;n.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),n.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),n.bindFramebuffer(r.READ_FRAMEBUFFER,s),n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),n.unbindTexture()}else{const e=r.createFramebuffer();n.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,i,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),n.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:n,depthTexture:i,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;n>0?(i&&i.isDepthTexture&&i.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,n,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(n>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,n,i){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+i:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*n*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,n,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let r=0;return e===s.UNSIGNED_BYTE&&(r=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Kv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Xv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const Yv={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class Qv{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:r,object:n,type:i,info:o,index:a}=this;0!==a?s.drawElements(r,t,i,e):s.drawArrays(r,e,t),o.update(n,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:n,type:i,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(n,t,i,e,s):r.drawArraysInstanced(n,e,t,s),u.update(a,t,n,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:n,object:i,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),n=r.previousContext,i=e.occlusionQueryCount;i>0&&(i>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const n=r.framebuffers[e.getCacheKey()],i=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,n);for(let s=0;s{let o=0;for(let t=0;t0&&e.add(r[t]),s[t]=null,n.deleteQuery(i),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Mv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,n="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(n,r),t.compileShader(n),this.set(e,{shaderGPU:n})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:n,vertexProgram:i}=r,o=s.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const n=new Promise((t=>{const n=this.parallel,i=()=>{s.getProgramParameter(o,n.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(i)};i()}));t.push(n)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],n=Math.max(t-6,0),i=Math.min(t+6,s.length);for(let e=n;e":" "} ${n}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),n=e.getShaderInfoLog(t).trim();if(r&&""===n)return"";const i=/ERROR: 0:(\d+)/.exec(n);if(i){const r=parseInt(i[1]);return s.toUpperCase()+"\n\n"+n+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return n}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,n=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const i=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+n+"\n"+i+"\n"+o)}else""!==n&&console.warn("THREE.WebGLProgram: Program Info Log:",n)}}_completeCompile(e,t){const{state:s,gl:r}=this,n=this.get(t),{programGPU:i,fragmentShader:o,vertexShader:a}=n;!1===r.getProgramParameter(i,r.LINK_STATUS)&&this._logProgramError(i,o,a),s.useProgram(i);const u=e.getBindings();this._setupBindings(u,i),this.set(t,{programGPU:i})}createComputePipeline(e,t){const{state:s,gl:r}=this,n={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(n);const{computeProgram:i}=e,o=r.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU,l=i.transforms,d=[],c=[];for(let e=0;eYv[t]===e)),s=this.extensions;for(let e=0;e0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const n=[],l=e.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Hf,stripIndexFormat:ay},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Hf,stripIndexFormat:ay},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:n,height:i}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:n,height:i,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),n=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),i=c.beginRenderPass({colorAttachments:[{view:s,loadOp:ty,storeOp:Jf,clearValue:[0,0,0,0]}]});i.setPipeline(e),i.setBindGroup(0,n),i.draw(4,1,0,0),i.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const n=r.layers[s]||this._mipmapCreateBundles(e,t,s),i=this.device.createCommandEncoder({});this._mipmapRunBundles(i,n),this.device.queue.submit([i.finish()]),0!==r.useCount&&(r.layers[s]=n),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),n=r.getBindGroupLayout(0);let i=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:s});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,dS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,cS={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class hS extends WN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:n,blockCode:i,outputType:o}=(e=>{const t=(e=e.trim()).match(lS);if(null!==t&&4===t.length){const s=t[2],r=[];let n=null;for(;null!==(n=dS.exec(s));)r.push({name:n[1],type:n[2]});const i=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class pS extends HN{parseFunction(e){return new hS(e)}}const gS=self.GPUShaderStage,mS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},fS={vertex:gS?gS.VERTEX:1,fragment:gS?gS.FRAGMENT:2,compute:gS?gS.COMPUTE:4},yS={instance:!0,swizzleAssign:!1,storageBuffer:!0},bS={"^^":"tsl_xor"},xS={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},TS={},_S={tsl_xor:new sx("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new sx("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new sx("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new sx("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new sx("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new sx("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new sx("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new sx("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new sx("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new sx("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new sx("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new sx("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new sx("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new sx("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},NS={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(_S.pow_float=new sx("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),_S.pow_vec2=new sx("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[_S.pow_float]),_S.pow_vec3=new sx("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[_S.pow_float]),_S.pow_vec4=new sx("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[_S.pow_float]),NS.pow_float="tsl_pow_float",NS.pow_vec2="tsl_pow_vec2",NS.pow_vec3="tsl_pow_vec3",NS.pow_vec4="tsl_pow_vec4");let vS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(vS+="diagnostic( off, derivative_uniformity );\n");class SS extends BN{constructor(e,t){super(e,t,new pS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,n=this.shaderStage){return"fragment"===n?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,r,n,i=this.shaderStage){return"fragment"===i&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${mS[e.wrapS]}S_${mS[e.wrapT]}T`;let s=TS[t];if(void 0===s){const r=[];let n=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const i=(e,t)=>{e===ls?(r.push(_S.repeatWrapping_float),n+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(r.push(_S.clampWrapping_float),n+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(r.push(_S.mirrorWrapping_float),n+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(n+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};i(e.wrapS,"x"),n+=",\n",i(e.wrapT,"y"),n+="\n\t);\n\n}\n",TS[t]=s=new sx(n,r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let n=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(n=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${n} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=n),n}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,n="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${n} )`:`textureLoad( ${t}, ${s}, ${n} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,n=this.shaderStage){let i=null;return i=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,n):this._generateTextureSample(e,t,s,r,n),i}generateTextureGrad(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${i} shader.`)}generateTextureCompare(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${i} shader.`)}generateTextureLevel(e,t,s,r,n,i=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this._generateTextureSampleLevel(e,t,s,r,n,i),o}generateTextureBias(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${i} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=bS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case Wy:return"read";case Hy:return"write";default:return"read_write"}else switch(e.access){case zy:return"read_write";case $y:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);if(void 0===i.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let i=null;if("texture"===t||"storageTexture"===t?i=new vv(n.name,n.node,o,e.access?e.access:null):"cubeTexture"===t?i=new Sv(n.name,n.node,o,e.access?e.access:null):"texture3D"===t&&(i=new Av(n.name,n.node,o,e.access?e.access:null)),i.store=!0===e.isStorageTextureNode,i.setVisibility(fS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===i.store){const e=new eS(`${n.name}_sampler`,n.node,o);e.setVisibility(fS[s]),u.push(e,i),r=[e,i]}else u.push(i),r=[i]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const n=new("buffer"===t?yv:rS)(e,o);n.setVisibility(fS[s]),u.push(n),r=n}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Tv(a,o),i.setVisibility(fS[s]),e[a]=i,u.push(i)),r=this.getNodeUniform(n,t),i.addUniform(r)}i.uniformGPU=r}return n}getBuiltin(e,t,s,r=this.shaderStage){const n=this.builtins[r]||(this.builtins[r]=new Map);return!1===n.has(e)&&n.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let n=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(n+=`\treturn ${s.result};\n`),n+="\n}\n",n}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:n}of s.values())t.push(`@builtin( ${e} ) ${r} : ${n}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:n}of this.scopedArrays.values()){const i=this.getType(r);t.push(`var<${s}> ${e}: array< ${i}, ${n} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e output : ${n};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let n=0;n";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array";else if(!0===t.isDepthTexture)r=`texture_depth${i}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d";else if(!0===n.node.isStorageTextureNode){r=`texture_storage_2d<${uS(t)}, ${this.getStorageAccess(n.node)}>`}else{r=`texture${i}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name} : ${r};`)}else if("buffer"===n.type||"storageBuffer"===n.type||"indirectStorageBuffer"===n.type){const e=n.node,t=this.getType(e.bufferType),s=e.bufferCount,i=s>0&&"buffer"===n.type?", "+s:"",a=e.isAtomic?`atomic<${t}>`:`${t}`,u=`\t${n.name} : array< ${a}${i} >\n`,l=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding("NodeBuffer_"+e.id,u,l,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(n.type)),t=n.groupNode.name;(i[t]||(i[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${n.name} : ${e}`)}}for(const e in i){const t=i[e];n.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=n.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t);let r="// code\n\n";r+=this.flowCode[t];const n=this.flowNodes[t],i=n[n.length-1],o=i.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const e of n){const n=this.getFlowData(e),u=e.name;if(u&&(r.length>0&&(r+="\n"),r+=`\t// flow -> ${u}\n\t`),r+=`${n.code}\n\t`,e===i&&"compute"!==t)if(r+="// result\n\n\t","vertex"===t)r+=`varyings.Vertex = ${n.result};`;else if("fragment"===t)if(a)s.returnType=o.nodeType,r+=`return ${n.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar output : OutputStruct;\n\n",r+=`output.color = ${n.result};\n\n\treturn output;`}}s.flow=r}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return xS[e]||e}isAvailable(e){let t=yS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),yS[e]=t),t}_getWGSLMethod(e){return void 0!==_S[e]&&this._include(e),NS[e]}_include(e){const t=_S[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${vS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r=0,n=0){const i=e+"Struct";return`${this._getWGSLStruct(i,t)}\n@binding( ${r} ) @group( ${n} )\nvar<${s}> ${e} : ${i};`}}class AS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=uy.Depth24PlusStencil8:e.depth&&(t=uy.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?Gf:e.isLineSegments||e.isMesh&&!0===t.wireframe?kf:e.isLine?zf:e.isMesh?$f:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?uy.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const RS=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),CS=new Map([[Ie,["float16"]]]),ES=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class wS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,n=r.get(s);let i=n.buffer;if(void 0===i){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[s]===r&&(a=o.groups[s])),void 0===a&&(a=this.createBindGroup(e,u),s>0&&(o.groups[s]=a,o.versions[s]=r)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,n=t.get(e).buffer;s.queue.writeBuffer(n,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let n=0;const i=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,n=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,i=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:n});e.buffer=i}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);i.push({binding:n,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const n=rb;let i;i=t.isSampledCubeTexture?tb:t.isSampledTexture3D?sb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?eb:Jy,o=e[r]=e.texture.createView({aspect:n,dimension:i,mipLevelCount:s})}}i.push({binding:n,resource:o})}n++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:i})}}class BS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:n,pipeline:i}=e,{vertexProgram:o,fragmentProgram:a}=i,u=this.backend,l=u.device,d=u.utils,c=u.get(i),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,n=s.getCurrentDepthStencilFormat(e),i={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:n,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(i)}createComputePipeline(e,t){const s=this.backend,r=s.device,n=s.get(e.computeProgram).module,i=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}i.pipeline=r.createComputePipeline({compute:n,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,n=e.blendSrc,i=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:n,a=null!==e.blendDstAlpha?e.blendDstAlpha:i,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(n),dstFactor:this._getBlendFactor(i),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const n=(e,r,n,i)=>{t={srcFactor:e,dstFactor:r,operation:Cy},s={srcFactor:n,dstFactor:i,operation:Cy}};if(e.premultipliedAlpha)switch(r){case F:n(my,xy,my,xy);break;case bt:n(my,my,my,my);break;case yt:n(gy,yy,gy,my);break;case ft:n(gy,fy,gy,by)}else switch(r){case F:n(by,xy,my,xy);break;case bt:n(by,my,by,my);break;case yt:n(gy,yy,gy,my);break;case ft:n(gy,fy,gy,fy)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=gy;break;case st:t=my;break;case rt:t=fy;break;case ut:t=yy;break;case nt:t=by;break;case lt:t=xy;break;case ot:t=Ty;break;case dt:t=_y;break;case at:t=Ny;break;case ct:t=vy;break;case it:t=Sy;break;case 211:t=Ay;break;case 212:t=Ry;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=Wf;break;case Es:t=Zf;break;case Cs:t=jf;break;case Rs:t=Kf;break;case As:t=qf;break;case Ss:t=Qf;break;case vs:t=Xf;break;case Ns:t=Yf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Py;break;case Ls:t=Iy;break;case Is:t=Ly;break;case Ps:t=Dy;break;case Fs:t=Vy;break;case Us:t=Oy;break;case Bs:t=Gy;break;case Ms:t=ky;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Cy;break;case Je:t=Ey;break;case et:t=wy;break;case Os:t=My;break;case Vs:t=By;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},n=this.backend.utils;switch(r.topology=n.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?oy:ay),s.side){case Oe:r.frontFace=sy,r.cullMode=iy;break;case x:r.frontFace=sy,r.cullMode=ny;break;case le:r.frontFace=sy,r.cullMode=ry;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Fy:Uy}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Zf;else{const s=e.depthFunc;switch(s){case Rt:t=Wf;break;case At:t=Zf;break;case St:t=jf;break;case vt:t=Kf;break;case Nt:t=qf;break;case _t:t=Qf;break;case Tt:t=Xf;break;case xt:t=Yf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class US extends Pv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new AS(this),this.attributeUtils=new wS(this),this.bindingUtils=new MS(this),this.pipelineUtils=new BS(this),this.textureUtils=new aS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const n=Object.values(ob),i=[];for(const e of n)r.features.has(e)&&i.push(e);const o={requiredFeatures:i,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const n=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ob.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:n}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const n=e.getCacheKey();let i=r[n];if(void 0===i){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,n=s.createQuerySet({type:"occlusion",count:r,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=n,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),i=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,i),i.occlusionQuerySet=n;const o=i.depthStencilAttachment;if(null!==e.textures){const t=i.colorAttachments;for(let s=0;s0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const r=8*s;let n=this.occludedResolveCache.get(r);void 0===n&&(n=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,n));const i=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,n,0),t.encoder.copyBufferToBuffer(n,0,i,0,r),t.occlusionQueryBuffer=i,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,n.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:r,pipeline:n}=e,i=e.getBindings(),o=this.get(r),a=this.get(n).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=i.length;e1?0:s;l.drawIndexed(t[s],r,e[s]/i,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,n,i,0,0);t.update(s,r,n)}else{const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,n,i,0);t.update(s,r,n)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,n=this.utils,i=n.getSampleCountRenderContext(e.context),o=n.getCurrentColorSpace(e.context),a=n.getCurrentColorFormat(e.context),u=n.getCurrentDepthStencilFormat(e.context),l=n.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===i&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=i,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,n=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,r.getSampleCountRenderContext(n),r.getCurrentColorSpace(n),r.getCurrentColorFormat(n),r.getCurrentDepthStencilFormat(n),r.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}async initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){this.device.pushErrorScope("out-of-memory");const r=await this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_renderContext_${e.id}`});if(await this.device.popErrorScope())return s.attemptingTimeStampQuerySetFailed||(console.error(`[GPUOutOfMemoryError][renderContext_${e.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.`),s.attemptingTimeStampQuerySetFailed=!0),void(s.timeStampQuerySet=null);const n={querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:n}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;const r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:n,resultBuffer:i,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,n,0),t.copyBufferToBuffer(n,0,i,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:n}=s.currentTimestampQueryBuffers;!0!==n&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),n=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,n),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new SS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,r=null,n=0){let i=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(i=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:n,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:n,origin:{x:i,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let n=null;n=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const i=this.get(e).texture;if(n.format!==i.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,i.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:n,origin:{x:s.x,y:s.y,z:0}},{texture:i},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new Zv(e)));super(new t(e),e),this.library=new PS,this.isWebGPURenderer=!0}}class LS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const DS=new nh,VS=new Tf(DS);class OS{constructor(e,t=Ln(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,DS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,VS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;VS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),VS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await VS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function GS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function kS(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function zS(e,t,s={}){return(s=GS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var $S=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=zS(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=GS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){kS(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:kS,saveRendererAndSceneState:zS,saveRendererState:GS});class HS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class WS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class jS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class qS extends WS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class KS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const n=new tr(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),Sn()):hn(new this.nodes[e])}}class XS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const n=r[e];t[e]=s[n]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class YS extends rr{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new KS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),n=new XS;n.setTextures(t),n.setNodes(r),n.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(t.matrixWorld))return n.worldMatrix.copy(t.matrixWorld),!1;const i=n.material;for(const e in i){const t=i[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return i[e]=r,!1}if(i.transmission>0){const{width:t,height:s}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==s)return n.bufferWidth=t,n.bufferHeight=s,!1}const o=n.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return n.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let s=0;s>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:n}of cr(e))s.push(s,or(r.slice(0,-4)),n.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;ee.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of cr(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let r=null;const n=e.getBuildStage();if("setup"===n){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===n)this.analyze(e);else if("generate"===n){if(1===this.generate.length){const s=this.getNodeType(e),n=e.getDataFromNode(this);r=n.snippet,void 0===r?(r=this.generate(e)||"",n.snippet=r):void 0!==n.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:n,childNode:i}of t)void 0!==n?(void 0===s[r]&&(s[r]=Number.isInteger(n)?[]:{}),s[r][n]=i.toJSON(e.meta).uuid):s[r]=i.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const n of e.inputNodes[s])r.push(t[n]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const n in e.inputNodes[s]){const i=e.inputNodes[s][n];r[n]=t[i]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let n=e.nodes[t];function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===n&&(n={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[n.uuid]=n),this.serialize(n),delete n.meta),r){const t=i(e.textures),s=i(e.images),r=i(e.nodes);t.length>0&&(n.textures=t),s.length>0&&(n.images=s),r.length>0&&(n.nodes=r)}return n}}class Rr extends Ar{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,r=this.getNodeType(e),n=s.build(e,r);return e.format(n,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const n=super.build(e,s),i=e.getVarFromNode(this,null,s),o=e.getPropertyName(i);return e.addLineFlowCode(`${o} = ${n}`,this),r.snippet=n,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,s)=>t+e.getTypeLength(s.getNodeType(e))),0))}generate(e,t){const s=this.getNodeType(e),r=this.nodes,n=e.getComponentType(s),i=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==n&&(s=e.format(s,r,n)),i.push(s)}const o=`${e.getType(s)}( ${i.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(vr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,r=e.getTypeLength(s.getNodeType(e));let n=null;if(r>1){let i=null;this.getVectorLength()>=r&&(i=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,i);n=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,i,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else n=s.build(e,t);return n}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:r}=this,n=this.getNodeType(e),i=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,i),a=t.build(e,n),u=e.getTypeLength(n),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(pn(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),hn(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>hn(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>hn(new Fr(hn(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),hn(new Br(e,t));if(!0===/^\d+$/.test(t))return hn(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=hn(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;rhn(null!==r?Object.assign(e,r):e);return null===t?(...t)=>n(new e(...gn(t))):null!==s?(s=hn(s),(...r)=>n(new e(t,...gn(r),s))):(...s)=>n(new e(t,...gn(s)))},qr=function(e,...t){return hn(new e(...gn(t)))};class Kr extends Ar{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let n=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let i=r.get(t);void 0===i&&(i=hn(e.buildFunctionNode(t)),r.set(t,i)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(i),n=hn(i.call(s))}else{const r=t.jsFunc,i=null!==s?r(s,e):r(e);n=hn(i)}return t.once&&(r.onceOutput=n),n}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return pn(e),hn(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],en=new Map;for(const e of Yr)en.set(e,new Ir(e));const tn=new Map;for(const e of Qr)tn.set(e,new Ir(e,"uint"));const sn=new Map([...tn].map((e=>new Ir(e.value,"int"))));for(const e of Zr)sn.set(e,new Ir(e,"int"));const rn=new Map([...sn].map((e=>new Ir(e.value))));for(const e of Jr)rn.set(e,new Ir(e));for(const e of Jr)rn.set(-e,new Ir(-e));const nn={bool:en,uint:tn,ints:sn,float:rn},on=new Map([...en,...rn]),an=(e,t)=>on.has(e)?on.get(e):!0===e.isNode?e:new Ir(e,t),un=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return hn(t.get(s[0]));if(1===s.length){const t=an(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?hn(t):hn(new Cr(t,e))}const r=s.map((e=>an(e)));return hn(new wr(r,e))}},ln=e=>"object"==typeof e&&null!==e?e.value:e,dn=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function cn(e,t){return new Proxy(new Xr(e,t),kr)}const hn=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?hn(an(e,t)):"shader"===s?yn(e):e}(e,t),pn=(e,t=null)=>new Hr(e,t),gn=(e,t=null)=>new Wr(e,t),mn=(...e)=>new jr(...e),fn=(...e)=>new qr(...e),yn=(e,t)=>{const s=new cn(e,t),r=(...e)=>{let t;return pn(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},bn=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),yn(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const xn=e=>{Lr=e},Tn=()=>Lr,_n=(...e)=>Lr.If(...e);function Nn(e){return Lr&&Lr.add(e),e}Vr("append",Nn);const vn=new un("color"),Sn=new un("float",nn.float),An=new un("int",nn.ints),Rn=new un("uint",nn.uint),Cn=new un("bool",nn.bool),En=new un("vec2"),wn=new un("ivec2"),Mn=new un("uvec2"),Bn=new un("bvec2"),Un=new un("vec3"),Fn=new un("ivec3"),Pn=new un("uvec3"),In=new un("bvec3"),Ln=new un("vec4"),Dn=new un("ivec4"),Vn=new un("uvec4"),On=new un("bvec4"),Gn=new un("mat2"),kn=new un("mat3"),zn=new un("mat4"),$n=(e="")=>hn(new Ir(e,"string")),Hn=e=>hn(new Ir(e,"ArrayBuffer"));Vr("toColor",vn),Vr("toFloat",Sn),Vr("toInt",An),Vr("toUint",Rn),Vr("toBool",Cn),Vr("toVec2",En),Vr("toIVec2",wn),Vr("toUVec2",Mn),Vr("toBVec2",Bn),Vr("toVec3",Un),Vr("toIVec3",Fn),Vr("toUVec3",Pn),Vr("toBVec3",In),Vr("toVec4",Ln),Vr("toIVec4",Dn),Vr("toUVec4",Vn),Vr("toBVec4",On),Vr("toMat2",Gn),Vr("toMat3",kn),Vr("toMat4",zn);const Wn=mn(Rr),jn=(e,t)=>hn(new Cr(hn(e),t)),qn=(e,t)=>hn(new Br(hn(e),t));Vr("element",Wn),Vr("convert",jn);class Kn extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Xn=e=>new Kn(e),Yn=(e,t=0)=>new Kn(e,!0,t),Qn=Yn("frame"),Zn=Yn("render"),Jn=Xn("object");class ei extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Jn}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let n=e.getNodeFromHash(r);void 0===n&&(e.setHashNode(this,r),n=this);const i=n.getInputType(e),o=e.getUniformFromNode(n,i,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const ti=(e,t)=>{const s=dn(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return hn(new ei(r,s))};class si extends Ar{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const ri=(e,t)=>hn(new si(e,t)),ni=(e,t)=>hn(new si(e,t,!0)),ii=fn(si,"vec4","DiffuseColor"),oi=fn(si,"vec3","EmissiveColor"),ai=fn(si,"float","Roughness"),ui=fn(si,"float","Metalness"),li=fn(si,"float","Clearcoat"),di=fn(si,"float","ClearcoatRoughness"),ci=fn(si,"vec3","Sheen"),hi=fn(si,"float","SheenRoughness"),pi=fn(si,"float","Iridescence"),gi=fn(si,"float","IridescenceIOR"),mi=fn(si,"float","IridescenceThickness"),fi=fn(si,"float","AlphaT"),yi=fn(si,"float","Anisotropy"),bi=fn(si,"vec3","AnisotropyT"),xi=fn(si,"vec3","AnisotropyB"),Ti=fn(si,"color","SpecularColor"),_i=fn(si,"float","SpecularF90"),Ni=fn(si,"float","Shininess"),vi=fn(si,"vec4","Output"),Si=fn(si,"float","dashSize"),Ai=fn(si,"float","gapSize"),Ri=fn(si,"float","pointWidth"),Ci=fn(si,"float","IOR"),Ei=fn(si,"float","Transmission"),wi=fn(si,"float","Thickness"),Mi=fn(si,"float","AttenuationDistance"),Bi=fn(si,"color","AttenuationColor"),Ui=fn(si,"float","Dispersion");class Fi extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,n=this.needsSplitAssign(e),i=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,i),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(n){const r=e.getVarFromNode(this,null,i),n=e.getPropertyName(r);e.addLineFlowCode(`${n} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t{const r=s.type;let n;return n="pointer"===r?"&"+t.build(e):t.build(e,r),n};if(Array.isArray(n))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?gn(t):pn(t[0]),hn(new Ii(hn(e),t)));Vr("call",Li);class Di extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let n=new Di(e,t,s);for(let t=0;t>"===s||"<<"===s)return e.getIntegerType(i);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(i),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===i&&e.isMatrix(o)?o:e.isMatrix(i)&&e.isVector(o)?e.getVectorFromMatrix(i):e.isVector(i)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(i)?o:i}generate(e,t){const s=this.op,r=this.aNode,n=this.bNode,i=this.getNodeType(e,t);let o=null,a=null;"void"!==i?(o=r.getNodeType(e),a=void 0!==n?n.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=i,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=i):o=a=i;const u=r.build(e,o),l=void 0!==n?n.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} < ${l} )`,i,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} <= ${l} )`,i,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} > ${l} )`,i,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} >= ${l} )`,i,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`( ${u} ${s} ${l} )`,i,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`${u} ${s} ${l}`,i,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vi=mn(Di,"+"),Oi=mn(Di,"-"),Gi=mn(Di,"*"),ki=mn(Di,"/"),zi=mn(Di,"%"),$i=mn(Di,"=="),Hi=mn(Di,"!="),Wi=mn(Di,"<"),ji=mn(Di,">"),qi=mn(Di,"<="),Ki=mn(Di,">="),Xi=mn(Di,"&&"),Yi=mn(Di,"||"),Qi=mn(Di,"!"),Zi=mn(Di,"^^"),Ji=mn(Di,"&"),eo=mn(Di,"~"),to=mn(Di,"|"),so=mn(Di,"^"),ro=mn(Di,"<<"),no=mn(Di,">>");Vr("add",Vi),Vr("sub",Oi),Vr("mul",Gi),Vr("div",ki),Vr("modInt",zi),Vr("equal",$i),Vr("notEqual",Hi),Vr("lessThan",Wi),Vr("greaterThan",ji),Vr("lessThanEqual",qi),Vr("greaterThanEqual",Ki),Vr("and",Xi),Vr("or",Yi),Vr("not",Qi),Vr("xor",Zi),Vr("bitAnd",Ji),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",no);const io=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zi(...e));Vr("remainder",io);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,n=e.isMatrix(t)?0:e.getTypeLength(t),i=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return n>i&&n>o?t:i>o?s:o>n?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),n=this.getInputType(e),i=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=i,r=o;e.isMatrix(s.getNodeType(e))?r=Ln(Un(r),0):s=Ln(Un(s),0);const n=Gi(s,r).xyz;return Ao(n).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+i.build(e,n)+" )",r,t);if(s===oo.ONE_MINUS)return Oi(1,i).build(e,t);if(s===oo.RECIPROCAL)return ki(1,i).build(e,t);if(s===oo.DIFFERENCE)return Fo(Oi(i,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(i.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(i.build(e,1===e.getTypeLength(i.getNodeType(e))?"float":n),o.build(e,n)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(i.build(e,n),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":n)):s===oo.REFRACT?l.push(i.build(e,n),o.build(e,n),a.build(e,"float")):s===oo.MIX?l.push(i.build(e,n),o.build(e,n),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":n)):(l.push(i.build(e,n)),null!==o&&l.push(o.build(e,n)),null!==a&&l.push(a.build(e,n))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=Sn(1e-6),uo=Sn(1e6),lo=Sn(Math.PI),co=Sn(2*Math.PI),ho=mn(oo,oo.ALL),po=mn(oo,oo.ANY),go=mn(oo,oo.EQUALS),mo=mn(oo,oo.RADIANS),fo=mn(oo,oo.DEGREES),yo=mn(oo,oo.EXP),bo=mn(oo,oo.EXP2),xo=mn(oo,oo.LOG),To=mn(oo,oo.LOG2),_o=mn(oo,oo.SQRT),No=mn(oo,oo.INVERSE_SQRT),vo=mn(oo,oo.FLOOR),So=mn(oo,oo.CEIL),Ao=mn(oo,oo.NORMALIZE),Ro=mn(oo,oo.FRACT),Co=mn(oo,oo.SIN),Eo=mn(oo,oo.COS),wo=mn(oo,oo.TAN),Mo=mn(oo,oo.ASIN),Bo=mn(oo,oo.ACOS),Uo=mn(oo,oo.ATAN),Fo=mn(oo,oo.ABS),Po=mn(oo,oo.SIGN),Io=mn(oo,oo.LENGTH),Lo=mn(oo,oo.NEGATE),Do=mn(oo,oo.ONE_MINUS),Vo=mn(oo,oo.DFDX),Oo=mn(oo,oo.DFDY),Go=mn(oo,oo.ROUND),ko=mn(oo,oo.RECIPROCAL),zo=mn(oo,oo.TRUNC),$o=mn(oo,oo.FWIDTH),Ho=mn(oo,oo.BITCAST),Wo=mn(oo,oo.TRANSPOSE),jo=mn(oo,oo.ATAN2),qo=mn(oo,oo.MIN),Ko=mn(oo,oo.MAX),Xo=mn(oo,oo.MOD),Yo=mn(oo,oo.STEP),Qo=mn(oo,oo.REFLECT),Zo=mn(oo,oo.DISTANCE),Jo=mn(oo,oo.DIFFERENCE),ea=mn(oo,oo.DOT),ta=mn(oo,oo.CROSS),sa=mn(oo,oo.POW),ra=mn(oo,oo.POW,2),na=mn(oo,oo.POW,3),ia=mn(oo,oo.POW,4),oa=mn(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gi(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=mn(oo,oo.MIX),da=(e,t=0,s=1)=>hn(new oo(oo.CLAMP,hn(e),hn(t),hn(s))),ca=e=>da(e),ha=mn(oo,oo.REFRACT),pa=mn(oo,oo.SMOOTHSTEP),ga=mn(oo,oo.FACEFORWARD),ma=yn((([e])=>{const t=ea(e.xy,En(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",na),Vr("pow4",ia),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,n=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=n,null!==r&&(e.getDataFromNode(r).parentNodeBlock=n);const i=e.getNodeProperties(this);i.condNode=t,i.ifNode=s.context({nodeBlock:s}),i.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:n,ifNode:i,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?ri(s).build(e):"";r.nodeProperty=u;const l=n.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=i.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=mn(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e,t);return e.setContext(s),r}}const Na=mn(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),n=e.getPropertyName(r),i=t.build(e,r.type);return e.addLineFlowCode(`${n} = ${i}`,this),n}}const Aa=mn(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const r=this.name,n=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,n),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const r=this.getNodeType(e),n=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,n),t.propertyName=n}return e.getPropertyName(s)}}const Ea=mn(Ca);Vr("varying",Ea);const wa=yn((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=yn((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let i=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(i=Ln(wa(i.rgb),i.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(i=Ln(kn(u._getMatrix(new n,s,r)).mul(i.rgb),i.a)),u.getTransfer(r)===l&&(i=Ln(Ma(i.rgb),i.a)),i):i}}const Pa=e=>hn(new Fa(hn(e),Ba,Ua)),Ia=e=>hn(new Fa(hn(e),Ua,Ba)),La=(e,t)=>hn(new Fa(hn(e),Ba,t)),Da=(e,t)=>hn(new Fa(hn(e),t,Ba)),Va=(e,t,s)=>hn(new Fa(hn(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return hn(new Oa(this,hn(e)))}setNodeType(e){const t=ti(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const n=e.renderer.library.getToneMappingFunction(s);return null!==n?r=Ln(n(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>hn(new $a(e,hn(t),hn(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),n=this.bufferStride||r,i=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,n),a=new g(o,r,i);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let n=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,n=r;else{n=Ea(this).build(e,t)}return n}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>hn(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;ehn(new Qa(hn(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const n=this.node.build(e,...t);return e.setCache(s),n}}const eu=(e,...t)=>hn(new Ja(hn(e),...t));Vr("cache",eu);class tu extends Ar{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const su=mn(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=Sn(0),n=Sn(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=n,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:n,doClamp:i}=this;let o=e.sub(t).div(s.sub(t));return!0===i&&(o=o.clamp()),o.mul(n.sub(r)).add(r)}}const nu=mn(ru,null,null,{doClamp:!1}),iu=mn(ru);Vr("remap",nu),Vr("remapClamp",iu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=mn(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>hn(new du(hn(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),n=e.getTypeFromAttribute(r),i=e.getAttribute(t,n);if("vertex"===e.shaderStage)return e.format(i.name,n,s);return Ea(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const gu=(e,t)=>hn(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=mn(fu);class bu extends ei{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=mn(bu);class Tu extends ei{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=ti(this.value.matrix)),this._matrixUniform.mul(Un(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&!0===s.flipY||!0===s.isRenderTargetTexture||!0===s.isFramebufferTexture||!0===s.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(An(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,n,i,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,i):n?e.generateTextureBias(u,t,s,n,i):a?e.generateTextureGrad(u,t,s,a,i):o?e.generateTextureCompare(u,t,s,o,i):!1===this.sampler?e.generateTextureLoad(u,t,s,i):e.generateTexture(u,t,s,i),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const n=super.generate(e,"property");if("sampler"===t)return n+"_sampler";if(e.isReference(t))return n;{const i=e.getDataFromNode(this);let o=i.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,n,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),i.snippet=b,i.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}blur(e){const t=this.clone();return t.biasNode=hn(e).mul(xu(t)),t.referenceNode=this.getSelf(),hn(t)}level(e){const t=this.clone();return t.levelNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}compare(e){const t=this.clone();return t.compareNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}grad(e,t){const s=this.clone();return s.gradNode=[hn(e),hn(t)],s.referenceNode=this.getSelf(),hn(s)}depth(e){const t=this.clone();return t.depthNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=mn(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=ti("float").label("cameraNear").setGroup(Zn).onRenderUpdate((({camera:e})=>e.near)),Au=ti("float").label("cameraFar").setGroup(Zn).onRenderUpdate((({camera:e})=>e.far)),Ru=ti("mat4").label("cameraProjectionMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=ti("mat4").label("cameraProjectionMatrixInverse").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=ti("mat4").label("cameraViewMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=ti("mat4").label("cameraWorldMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=ti("mat3").label("cameraNormalMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=ti(new s).label("cameraPosition").setGroup(Zn).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new ei(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,n=this.scope;if(n===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(n===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(n===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(n===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(n===Uu.VIEW_POSITION){const n=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(n.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=mn(Uu,Uu.DIRECTION),Pu=mn(Uu,Uu.WORLD_MATRIX),Iu=mn(Uu,Uu.POSITION),Lu=mn(Uu,Uu.SCALE),Du=mn(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=fn(Vu,Vu.DIRECTION),Gu=fn(Vu,Vu.WORLD_MATRIX),ku=fn(Vu,Vu.POSITION),zu=fn(Vu,Vu.SCALE),$u=fn(Vu,Vu.VIEW_POSITION),Hu=ti(new n).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=ti(new i).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=yn((e=>(e.context.isHighPrecisionModelViewMatrix=!0,ti("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=yn((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return ti("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=fn(sl),nl=Sn(rl).mul(2).sub(1),il=gu("normal","vec3"),ol=yn((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Un(0,1,0)):il),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=yn((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=yn((e=>e.context.setupNormal()),"vec3").once()().mul(nl).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=yn((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(nl).toVar("transformedClearcoatNormalView"),pl=yn((([e,t=Gu])=>{const s=kn(t),r=e.div(Un(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=yn((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=ti(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Un(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Un(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=mn(Tl);class Nl extends ei{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const vl=(e,t,s)=>hn(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;shn(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),hn(new Al(e,t)));class El extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return hn(new El(this,hn(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):ti(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new wl(e,t,s)),Bl=(e,t,s,r)=>hn(new wl(e,t,r,s));class Ul extends wl{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>hn(new Ul(e,t,s)),Pl=yn((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ln(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(il.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=kn(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xi.cross(tl);return e=e.cross(xi).normalize(),e=la(e,dl,yi.mul(ai.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=yn((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:n}=e,i=t.dFdx(),o=t.dFdy(),a=n.dFdx(),u=n.dFdy(),l=s,d=o.cross(l),c=l.cross(i),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=nl.mul(g.inverseSqrt());return Vi(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Un(r.xy.mul(s),r.z));let n=null;if(t===S)n=gl(r);else if(t===v){n=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return n}}const Jl=mn(Zl),ed=yn((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=Sn(s((e=>e)));return En(Sn(s((e=>e.add(e.dFdx())))).sub(r),Sn(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=yn((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,n=t.dFdx().normalize(),i=s,o=t.dFdy().normalize().cross(i),a=i.cross(n),u=n.dot(o).mul(nl),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=mn(sd),nd=new Map;class id extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=nd.get(e);return void 0===s&&(s=Fl(e,t),nd.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===id.COLOR){const e=void 0!==t.color?this.getColor(s):Un();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===id.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===id.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:Sn(1);else if(s===id.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===id.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===id.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===id.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===id.EMISSIVE){const e=this.getFloat("emissiveIntensity"),n=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?n.mul(this.getTexture(s)):n}else if(s===id.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===id.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===id.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===id.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===id.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Gn($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(En(1)).normalize().mul(e.b))}else r=$d;else if(s===id.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const n=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(n).mul(this.getTexture(s).g).add(n)}else r=e}else if(s===id.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===id.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===id.IOR)r=this.getFloat(s);else if(s===id.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===id.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}id.ALPHA_TEST="alphaTest",id.COLOR="color",id.OPACITY="opacity",id.SHININESS="shininess",id.SPECULAR="specular",id.SPECULAR_STRENGTH="specularStrength",id.SPECULAR_INTENSITY="specularIntensity",id.SPECULAR_COLOR="specularColor",id.REFLECTIVITY="reflectivity",id.ROUGHNESS="roughness",id.METALNESS="metalness",id.NORMAL="normal",id.CLEARCOAT="clearcoat",id.CLEARCOAT_ROUGHNESS="clearcoatRoughness",id.CLEARCOAT_NORMAL="clearcoatNormal",id.EMISSIVE="emissive",id.ROTATION="rotation",id.SHEEN="sheen",id.SHEEN_ROUGHNESS="sheenRoughness",id.ANISOTROPY="anisotropy",id.IRIDESCENCE="iridescence",id.IRIDESCENCE_IOR="iridescenceIOR",id.IRIDESCENCE_THICKNESS="iridescenceThickness",id.IOR="ior",id.TRANSMISSION="transmission",id.THICKNESS="thickness",id.ATTENUATION_DISTANCE="attenuationDistance",id.ATTENUATION_COLOR="attenuationColor",id.LINE_SCALE="scale",id.LINE_DASH_SIZE="dashSize",id.LINE_GAP_SIZE="gapSize",id.LINE_WIDTH="linewidth",id.LINE_DASH_OFFSET="dashOffset",id.POINT_WIDTH="pointWidth",id.DISPERSION="dispersion",id.LIGHT_MAP="light",id.AO_MAP="ao";const od=fn(id,id.ALPHA_TEST),ad=fn(id,id.COLOR),ud=fn(id,id.SHININESS),ld=fn(id,id.EMISSIVE),dd=fn(id,id.OPACITY),cd=fn(id,id.SPECULAR),hd=fn(id,id.SPECULAR_INTENSITY),pd=fn(id,id.SPECULAR_COLOR),gd=fn(id,id.SPECULAR_STRENGTH),md=fn(id,id.REFLECTIVITY),fd=fn(id,id.ROUGHNESS),yd=fn(id,id.METALNESS),bd=fn(id,id.NORMAL).context({getUV:null}),xd=fn(id,id.CLEARCOAT),Td=fn(id,id.CLEARCOAT_ROUGHNESS),_d=fn(id,id.CLEARCOAT_NORMAL).context({getUV:null}),Nd=fn(id,id.ROTATION),vd=fn(id,id.SHEEN),Sd=fn(id,id.SHEEN_ROUGHNESS),Ad=fn(id,id.ANISOTROPY),Rd=fn(id,id.IRIDESCENCE),Cd=fn(id,id.IRIDESCENCE_IOR),Ed=fn(id,id.IRIDESCENCE_THICKNESS),wd=fn(id,id.TRANSMISSION),Md=fn(id,id.THICKNESS),Bd=fn(id,id.IOR),Ud=fn(id,id.ATTENUATION_DISTANCE),Fd=fn(id,id.ATTENUATION_COLOR),Pd=fn(id,id.LINE_SCALE),Id=fn(id,id.LINE_DASH_SIZE),Ld=fn(id,id.LINE_GAP_SIZE),Dd=fn(id,id.LINE_WIDTH),Vd=fn(id,id.LINE_DASH_OFFSET),Od=fn(id,id.POINT_WIDTH),Gd=fn(id,id.DISPERSION),kd=fn(id,id.LIGHT_MAP),zd=fn(id,id.AO_MAP),$d=ti(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=mn(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,n;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)n=r;else{n=Ea(this).build(e,t)}return n}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=fn(jd,jd.VERTEX),Kd=fn(jd,jd.INSTANCE),Xd=fn(jd,jd.SUBGROUP),Yd=fn(jd,jd.INVOCATION_SUBGROUP),Qd=fn(jd,jd.INVOCATION_LOCAL),Zd=fn(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,n=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=zn(...n)}this.instanceMatrixNode=t}const n=r.instanceColor;if(n&&null===s){const e=new R(n.array,3),t=n.usage===p?Ya:Xa;this.bufferColor=e,s=Un(t(e,"vec3",3,0)),this.instanceColorNode=s}const i=t.mul(Yu).xyz;if(Yu.assign(i),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&ni("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=mn(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=yn((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=An(e).modInt(An(t)),r=An(e).div(An(t));return Nu(this.batchMesh._indirectTexture,wn(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(An(this.batchingIdNode)),r=this.batchMesh._matricesTexture,n=yu(Nu(r),0),i=Sn(s).mul(4).toInt().toVar(),o=i.modInt(n),a=i.div(An(n)),u=zn(Nu(r,wn(o,a)),Nu(r,wn(o.add(1),a)),Nu(r,wn(o.add(2),a)),Nu(r,wn(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=yn((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),n=s.div(t);return Nu(l,wn(r,n)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);ni("vec3","vBatchColor").assign(t)}const d=kn(u);Yu.assign(u.mul(Yu));const c=ol.div(Un(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=mn(tc),rc=new WeakMap;class nc extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,n;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),n=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=ti(e.bindMatrix,"mat4"),r=ti(e.bindMatrixInverse,"mat4"),n=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=n,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=n.mul(t),c=Vi(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return i.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vi(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=i.mul(d).mul(n),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const ic=e=>hn(new nc(e)),oc=e=>hn(new nc(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;eNumber(i)?">=":"<"));const d={start:n,end:i,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const n=r.build(e,"void"),i=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+n);for(let t=0,s=this.params.length-1;thn(new ac(gn(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=yn((({bufferMap:e,influence:t,stride:s,width:r,depth:n,offset:i})=>{const o=An(qd).mul(s).add(i),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,wn(u,a)).depth(n).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=ti(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,n=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,i=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==i?i.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,n=void 0!==e.morphAttributes.color,i=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==i?i.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===n&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=Sn(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,wn(An(e).add(1),An(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(0)})),!0===n&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=mn(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Un().toVar("directDiffuse"),directSpecular:Un().toVar("directSpecular"),indirectDiffuse:Un().toVar("indirectDiffuse"),indirectSpecular:Un().toVar("indirectSpecular")};return{radiance:Un().toVar("radiance"),irradiance:Un().toVar("irradiance"),iblIrradiance:Un().toVar("iblIrradiance"),ambientOcclusion:Sn(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Tc=mn(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?ti(Nc||(Nc=new t)):e===Sc.VIEWPORT?ti(vc||(vc=new r)):En(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=fn(Sc,Sc.UV),Rc=fn(Sc,Sc.SIZE),Cc=fn(Sc,Sc.COORDINATE),Ec=fn(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=yn((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=yn((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=yn((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=mn(Lc),Vc=mn(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=mn(Gc);class zc extends Ar{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Xc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.negate().div(t)),n=To(s.div(t));return r.div(n)},Kc=(e,t,s)=>{const r=e.mul(xo(s.div(t)));return Sn(Math.E).pow(r).mul(t).negate()},Xc=mn(zc,zc.DEPTH_BASE),Yc=fn(zc,zc.DEPTH),Qc=mn(zc,zc.LINEAR_DEPTH),Zc=Qc(kc());Yc.assign=e=>Xc(e);const Jc=mn(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class eh extends Ar{static get type(){return"ClippingNode"}constructor(e=eh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===eh.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===eh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return yn((()=>{const s=Sn().toVar("distanceToPlane"),r=Sn().toVar("distanceToGradient"),n=Sn(1).toVar("clipOpacity"),i=t.length;if(!this.hardwareClipping&&i>0){const e=Rl(t);uc(i,(({i:t})=>{const i=e.element(t);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),i=Sn(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const n=t.element(e);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s).oneMinus())})),n.mulAssign(i.oneMinus())}ii.a.mulAssign(n),ii.a.equal(0).discard()}))()}setupDefault(e,t){return yn((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Cn(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),yn((()=>{const r=Rl(e),n=Jc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();n.element(e).assign(s)}))}))()}}eh.ALPHA_TO_COVERAGE="alphaToCoverage",eh.DEFAULT="default",eh.HARDWARE="hardware";const th=yn((([e])=>Ro(Gi(1e4,Co(Gi(17,e.x).add(Gi(.1,e.y)))).mul(Vi(.1,Fo(Co(Gi(13,e.y).add(e.x)))))))),sh=yn((([e])=>th(En(th(e.xy),e.z)))),rh=yn((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=Sn(1).div(Sn(.05).mul(t)).toVar("pixScale"),r=En(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),n=En(sh(vo(r.x.mul(e.xyz))),sh(vo(r.y.mul(e.xyz)))).toVar("alpha"),i=Ro(To(s)).toVar("lerpFactor"),o=Vi(Gi(i.oneMinus(),n.x),Gi(i,n.y)).toVar("x"),a=qo(i,i.oneMinus()).toVar("a"),u=Un(o.mul(o).div(Gi(2,a).mul(Oi(1,a))),o.sub(Gi(.5,a)).div(Oi(1,a)),Oi(1,Oi(1,o).mul(Oi(1,o)).div(Gi(2,a).mul(Oi(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class nh extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new ir(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const n=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const i=this.setupLighting(e);null!==n&&e.stack.add(n);const o=Ln(i,ii.a).max(0);if(r=this.setupOutput(e,o),vi.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ln(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=hn(new eh(eh.ALPHA_TO_COVERAGE)):e.stack.add(hn(new eh))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(hn(new eh(eh.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(el.z,Su,Au):$c(el.z,Su,Au))}null!==r&&Yc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ln(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ln(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=ni("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=ni("vec3","vBatchColor").mul(s)}ii.assign(s);const r=this.opacityNode?Sn(this.opacityNode):dd;if(ii.a.assign(ii.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?Sn(this.alphaTestNode):od;ii.a.lessThanEqual(e).discard()}!0===this.alphaHash&&ii.a.lessThan(rh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&ii.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Un(0):ii.rgb}setupNormal(){return this.normalNode?Un(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:n}=this,i=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(i&&i.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(i,t,s,r)}else null!==s&&(o=Un(null!==r?la(o,s,r):s));return(n&&!0===n.isNode||t.emissive&&!0===t.emissive.isColor)&&(oi.assign(Un(n||ld)),o=o.add(oi)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ln(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:n}of r)s.inputNodes[t]=n.toJSON(e).uuid;function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=n(e.textures),r=n(e.images),i=n(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),i.length>0&&(s.nodes=i)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const ih=new P;class oh extends nh{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(ih),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=yn((()=>{const e=gu("instancePosition").xyz,t=Ln(ju.mul(Ln(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),n=Xu.xy.toVar();return n.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),n.assign(n.div(Ec.z)),n.y.assign(n.y.mul(s)),n.assign(n.mul(r.w)),r.addAssign(Ln(n,0,0)),r}))(),this.fragmentNode=yn((()=>{const r=Sn(1).toVar(),n=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=Sn(n.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),n).oneMinus())}else n.greaterThan(1).discard();let i;if(this.pointColorNode)i=this.pointColorNode;else if(s){i=gu("instanceColor").mul(ad)}else i=ad;return r.mulAssign(dd),Ln(i,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ah=new I;class uh extends nh{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(ah),this.setValues(e)}}const lh=new L;class dh extends nh{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(lh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?Sn(this.offsetNodeNode):Vd,t=this.dashScaleNode?Sn(this.dashScaleNode):Pd,s=this.dashSizeNode?Sn(this.dashSizeNode):Id,r=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(s),Ai.assign(r);const n=Ea(gu("lineDistance").mul(t));(e?n.add(e):n).mod(Si.add(Ai)).greaterThan(Si).discard()}}const ch=new L;class hh extends nh{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ch),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,n=this.worldUnits,i=yn((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ln(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=yn((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ln(ju.mul(Ln(e,1))).toVar("start"),o=Ln(ju.mul(Ln(t,1))).toVar("end");if(r){const e=this.dashScaleNode?Sn(this.dashScaleNode):Pd,t=this.offsetNode?Sn(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let n=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));n=n.add(t),ni("float","lineDistance").assign(n)}n&&(ni("vec3","worldStart").assign(s.xyz),ni("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);_n(u,(()=>{_n(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(i({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(i({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ln().toVar();if(n){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),n=e.cross(t).normalize(),i=e.cross(n),a=ni("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ln(Xu.x.lessThan(0).select(n.mul(u),n.mul(u).negate()),0)),r||(a.addAssign(Ln(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ln(i.mul(u),0)),_n(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ln(i.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Un().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=En(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),_n(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ln(e,0,0)))}return g}))();const o=yn((({p1:e,p2:t,p3:s,p4:r})=>{const n=e.sub(s),i=r.sub(s),o=t.sub(e),a=n.dot(i),u=i.dot(o),l=n.dot(o),d=i.dot(i),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return En(h,p)}));this.fragmentNode=yn((()=>{const i=mu();if(r){const e=this.dashSizeNode?Sn(this.dashSizeNode):Id,t=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(e),Ai.assign(t);const s=ni("float","lineDistance");i.y.lessThan(-1).or(i.y.greaterThan(1)).discard(),s.mod(Si.add(Ai)).greaterThan(Si).discard()}const a=Sn(1).toVar("alpha");if(n){const s=ni("vec3","worldStart"),n=ni("vec3","worldEnd"),i=ni("vec4","worldPos").xyz.normalize().mul(1e5),u=n.sub(s),l=o({p1:s,p2:n,p3:Un(0,0,0),p4:i}),d=s.add(u.mul(l.x)),c=i.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1)),s=e.mul(e).add(t.mul(t)),r=Sn(s.fwidth()).toVar("dlen");_n(i.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else _n(i.y.abs().greaterThan(1),(()=>{const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ln(u,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ph=e=>hn(e).mul(.5).add(.5),gh=e=>hn(e).mul(2).sub(1),mh=new D;class fh extends nh{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(mh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?Sn(this.opacityNode):dd;ii.assign(Ln(ph(dl),e))}}class yh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return En(t,s)}}const bh=mn(yh);class xh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n=new O(5,5,5),i=bh(Ju),o=new nh;o.colorNode=_u(t,i,0),o.side=x,o.blending=G;const a=new k(n,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const Th=new WeakMap;class _h extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(Th.has(e)){const t=Th.get(e);vh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new xh(s.height);r.fromEquirectangularTexture(t,e),vh(r.texture,e.mapping),this._cubeTexture=r.texture,Th.set(e,r.texture),e.addEventListener("dispose",Nh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Nh(e){const t=e.target;t.removeEventListener("dispose",Nh);const s=Th.get(t);void 0!==s&&(Th.delete(t),s.dispose())}function vh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const Sh=mn(_h);class Ah extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Sh(this.envNode)}}class Rh extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=Sn(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ch{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Eh extends Ch{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,n=e.reflectedLight,i=s.context.irradianceLightMap;n.indirectDiffuse.assign(Ln(0)),i?n.indirectDiffuse.addAssign(i):n.indirectDiffuse.addAssign(Ln(1,1,1,0)),n.indirectDiffuse.mulAssign(r),n.indirectDiffuse.mulAssign(ii.rgb)}finish(e,t,s){const r=s.material,n=e.outgoingLight,i=s.context.environment;if(i)switch(r.combine){case Y:n.rgb.assign(la(n.rgb,n.rgb.mul(i.rgb),gd.mul(md)));break;case X:n.rgb.assign(la(n.rgb,i.rgb,gd.mul(md)));break;case K:n.rgb.addAssign(i.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const wh=new Q;class Mh extends nh{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Rh(kd)),t}setupOutgoingLight(){return ii.rgb}setupLightingModel(){return new Eh}}const Bh=yn((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Uh=yn((e=>e.diffuseColor.mul(1/Math.PI))),Fh=yn((({dotNH:e})=>Ni.mul(Sn(.5)).add(1).mul(Sn(1/Math.PI)).mul(e.pow(Ni)))),Ph=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),n=Bh({f0:Ti,f90:1,dotVH:r}),i=Sn(.25),o=Fh({dotNH:s});return n.mul(i).mul(o)}));class Ih extends Eh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Ph({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const Lh=new Z;class Dh extends nh{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih(!1)}}const Vh=new J;class Oh extends nh{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Vh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih}setupVariants(){const e=(this.shininessNode?Sn(this.shininessNode):ud).max(1e-4);Ni.assign(e);const t=this.specularNode||cd;Ti.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Gh=yn((e=>{if(!1===e.geometry.hasAttribute("normal"))return Sn(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),kh=yn((e=>{const{roughness:t}=e,s=Gh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),zh=yn((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),n=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),i=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return ki(.5,n.add(i).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),$h=yn((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:n,dotBL:i,dotNV:o,dotNL:a})=>{const u=a.mul(Un(e.mul(s),t.mul(r),o).length()),l=o.mul(Un(e.mul(n),t.mul(i),a).length());return ki(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hh=yn((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Wh=Sn(1/Math.PI),jh=yn((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:n})=>{const i=e.mul(t),o=Un(t.mul(r),e.mul(n),i.mul(s)),a=o.dot(o),u=i.div(a);return Wh.mul(i.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),qh=yn((e=>{const{lightDirection:t,f0:s,f90:r,roughness:n,f:i,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=n.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Bh({f0:s,f90:r,dotVH:g});if(ln(o)&&(y=pi.mix(y,i)),ln(a)){const e=bi.dot(t),s=bi.dot(tl),r=bi.dot(d),n=xi.dot(t),i=xi.dot(tl),o=xi.dot(d);m=$h({alphaT:fi,alphaB:l,dotTV:s,dotBV:i,dotTL:e,dotBL:n,dotNV:h,dotNL:c}),f=jh({alphaT:fi,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=zh({alpha:l,dotNL:c,dotNV:h}),f=Hh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),Kh=yn((({roughness:e,dotNV:t})=>{const s=Ln(-1,-.0275,-.572,.022),r=Ln(1,.0425,1.04,-.04),n=e.mul(s).add(r),i=n.x.mul(n.x).min(t.mul(-9.28).exp2()).mul(n.x).add(n.y);return En(-1.04,1.04).mul(i).add(n.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xh=yn((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:n}=e,i=Kh({dotNV:t,roughness:n});return s.mul(i.x).add(r.mul(i.y))})),Yh=yn((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),n=r.mul(r),i=r.mul(n,n).clamp(0,.9999);return e.sub(Un(t).mul(i)).div(i.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qh=yn((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=Sn(1).div(s),n=t.pow2().oneMinus().max(.0078125);return Sn(2).add(r).mul(n.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Zh=yn((({dotNV:e,dotNL:t})=>Sn(1).div(Sn(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Jh=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),n=dl.dot(t).clamp(),i=Qh({roughness:hi,dotNH:n}),o=Zh({dotNV:r,dotNL:s});return ci.mul(i).mul(o)})),ep=yn((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),n=En(s,r.oneMinus().sqrt());return n.assign(n.mul(.984375).add(.0078125)),n})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),tp=yn((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sp=yn((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),n=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),i=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=n.div(i),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),rp=yn((({N:e,V:t,P:s,mInv:r,p0:n,p1:i,p2:o,p3:a})=>{const u=i.sub(n).toVar(),l=a.sub(n).toVar(),d=u.cross(l),c=Un().toVar();return _n(d.dot(s.sub(n)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(kn(u,l,e).transpose()).toVar(),h=d.mul(n.sub(s)).normalize().toVar(),p=d.mul(i.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Un(0).toVar();f.addAssign(sp({v1:h,v2:p})),f.addAssign(sp({v1:p,v2:g})),f.addAssign(sp({v1:g,v2:m})),f.addAssign(sp({v1:m,v2:h})),c.assign(Un(tp({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),np=1/6,ip=e=>Gi(np,Gi(e,Gi(e,e.negate().add(3)).sub(3)).add(1)),op=e=>Gi(np,Gi(e,Gi(e,Gi(3,e).sub(6))).add(4)),ap=e=>Gi(np,Gi(e,Gi(e,Gi(-3,e).add(3)).add(3)).add(1)),up=e=>Gi(np,sa(e,3)),lp=e=>ip(e).add(op(e)),dp=e=>ap(e).add(up(e)),cp=e=>Vi(-1,op(e).div(ip(e).add(op(e)))),hp=e=>Vi(1,up(e).div(ap(e).add(up(e)))),pp=(e,t,s)=>{const r=e.uvNode,n=Gi(r,t.zw).add(.5),i=vo(n),o=Ro(n),a=lp(o.x),u=dp(o.x),l=cp(o.x),d=hp(o.x),c=cp(o.y),h=hp(o.y),p=En(i.x.add(l),i.y.add(c)).sub(.5).mul(t.xy),g=En(i.x.add(d),i.y.add(c)).sub(.5).mul(t.xy),m=En(i.x.add(l),i.y.add(h)).sub(.5).mul(t.xy),f=En(i.x.add(d),i.y.add(h)).sub(.5).mul(t.xy),y=lp(o.y).mul(Vi(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=dp(o.y).mul(Vi(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},gp=yn((([e,t=Sn(3)])=>{const s=En(e.size(An(t))),r=En(e.size(An(t.add(1)))),n=ki(1,s),i=ki(1,r),o=pp(e,Ln(n,s),vo(t)),a=pp(e,Ln(i,r),So(t));return Ro(t).mix(o,a)})),mp=yn((([e,t,s,r,n])=>{const i=Un(ha(t.negate(),Ao(e),ki(1,r))),o=Un(Io(n[0].xyz),Io(n[1].xyz),Io(n[2].xyz));return Ao(i).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),fp=yn((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),yp=Vc(),bp=Vc(),xp=yn((([e,t,s],{material:r})=>{const n=(r.side==x?yp:bp).uv(e),i=To(Rc.x).mul(fp(t,s));return gp(n,i)})),Tp=yn((([e,t,s])=>(_n(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Un(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),_p=yn((([e,t,s,r,n,i,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ln().toVar(),f=Un().toVar();const n=d.sub(1).mul(g.mul(.025)),i=Un(d.sub(n),d,d.add(n));uc({start:0,end:3},(({i:n})=>{const d=i.element(n),g=mp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ln(y,1))),x=En(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(En(x.x,x.y.oneMinus()));const T=xp(x,s,d);m.element(n).assign(T.element(n)),m.a.addAssign(T.a),f.element(n).assign(r.element(n).mul(Tp(Io(g),h,p).element(n)))})),m.a.divAssign(3)}else{const n=mp(e,t,c,d,a),i=o.add(n),g=l.mul(u.mul(Ln(i,1))),y=En(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(En(y.x,y.y.oneMinus())),m=xp(y,s,d),f=r.mul(Tp(Io(n),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Un(Xh({dotNV:b,specularColor:n,specularF90:i,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ln(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),Np=kn(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),vp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Sp=yn((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:n})=>{const i=la(e,t,pa(0,.03,r)),o=e.div(i).pow2().mul(s.pow2().oneMinus()).oneMinus();_n(o.lessThan(0),(()=>Un(1)));const a=o.sqrt(),u=vp(i,e),l=Bh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=i.lessThan(e).select(Math.PI,0),h=Sn(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Un(1).add(t).div(Un(1).sub(t))})(n.clamp(0,.9999)),g=vp(p,i.toVec3()),m=Bh({f0:g,f90:1,dotVH:a}),f=Un(p.x.lessThan(i).select(Math.PI,0),p.y.lessThan(i).select(Math.PI,0),p.z.lessThan(i).select(Math.PI,0)),y=i.mul(r,a,2),b=Un(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Un(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Un(54856e-17,44201e-17,52481e-17),n=Un(1681e3,1795300,2208400),i=Un(43278e5,93046e5,66121e5),o=Sn(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(i.mul(2*Math.PI).sqrt()).mul(n.mul(s).add(t).cos()).mul(s.pow2().negate().mul(i).exp());return a=Un(a.x.add(o),a.y,a.z).div(1.0685e-7),Np.mul(a)})(Sn(e).mul(y),Sn(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Un(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Ap=yn((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),n=s.pow2(),i=xa(s.lessThan(.25),Sn(-339.2).mul(n).add(Sn(161.4).mul(s)).sub(25.9),Sn(-8.48).mul(n).add(Sn(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),Sn(44).mul(n).sub(Sn(23.7).mul(s)).add(3.26),Sn(1.97).mul(n).sub(Sn(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,Sn(.1).mul(s).sub(.025)).add(i.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Rp=Un(.04),Cp=Sn(1);class Ep extends Ch{constructor(e=!1,t=!1,s=!1,r=!1,n=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=n,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Un().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Un().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Un().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Un().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Un().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=Sp({outsideIOR:Sn(1),eta2:gi,cosTheta1:e,thinFilmThickness:mi,baseF0:Ti}),this.iridescenceF0=Yh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=_p(r,s,ai,ii,Ti,_i,t,Gu,Eu,Ru,Ci,wi,Bi,Mi,this.dispersion?Ui:null),e.backdropAlpha=Ei,ii.a.mulAssign(la(1,e.backdrop.a,Ei))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),n=Kh({roughness:ai,dotNV:r}),i=(this.iridescenceF0?pi.mix(Ti,this.iridescenceF0):Ti).mul(n.x).add(s.mul(n.y)),o=n.x.add(n.y).oneMinus(),a=Ti.add(Ti.oneMinus().mul(.047619)),u=i.mul(a).div(o.mul(a).oneMinus());e.addAssign(i),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Jh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(qh({lightDirection:e,f0:Rp,f90:Cp,roughness:di,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),s.directSpecular.addAssign(r.mul(qh({lightDirection:e,f0:Ti,f90:1,roughness:ai,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:n,ltc_1:i,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=ep({N:c,V:h,roughness:ai}),m=i.uv(g).toVar(),f=o.uv(g).toVar(),y=kn(Un(m.x,0,m.y),Un(0,1,0),Un(m.z,0,m.w)).toVar(),b=Ti.mul(f.x).add(Ti.oneMinus().mul(f.y)).toVar();n.directSpecular.addAssign(e.mul(b).mul(rp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),n.directDiffuse.addAssign(e.mul(ii).mul(rp({N:c,V:h,P:p,mInv:kn(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Uh({diffuseColor:ii})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(ci,Ap({normal:dl,viewDir:tl,roughness:hi}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Xh({dotNV:e,specularColor:Rp,specularF90:Cp,roughness:di});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Un().toVar("singleScattering"),n=Un().toVar("multiScattering"),i=t.mul(1/Math.PI);this.computeMultiscattering(r,n,_i);const o=r.add(n),a=ii.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(n.mul(i)),s.indirectDiffuse.addAssign(a.mul(i))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=ai.mul(-16).oneMinus().negate().exp2(),n=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(n)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Bh({dotVH:e,f0:Rp,f90:Cp}),r=t.mul(li.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(li));t.assign(r)}if(!0===this.sheen){const e=ci.r.max(ci.g).max(ci.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const wp=Sn(1),Mp=Sn(-2),Bp=Sn(.8),Up=Sn(-1),Fp=Sn(.4),Pp=Sn(2),Ip=Sn(.305),Lp=Sn(3),Dp=Sn(.21),Vp=Sn(4),Op=Sn(4),Gp=Sn(16),kp=yn((([e])=>{const t=Un(Fo(e)).toVar(),s=Sn(-1).toVar();return _n(t.x.greaterThan(t.z),(()=>{_n(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{_n(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),zp=yn((([e,t])=>{const s=En().toVar();return _n(t.equal(0),(()=>{s.assign(En(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(En(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(En(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(En(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(En(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(En(e.x,e.y).div(Fo(e.z)))})),Gi(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$p=yn((([e])=>{const t=Sn(0).toVar();return _n(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).ElseIf(e.greaterThanEqual(Fp),(()=>{t.assign(Bp.sub(e).mul(Pp.sub(Up)).div(Bp.sub(Fp)).add(Up))})).ElseIf(e.greaterThanEqual(Ip),(()=>{t.assign(Fp.sub(e).mul(Lp.sub(Pp)).div(Fp.sub(Ip)).add(Pp))})).ElseIf(e.greaterThanEqual(Dp),(()=>{t.assign(Ip.sub(e).mul(Vp.sub(Lp)).div(Ip.sub(Dp)).add(Lp))})).Else((()=>{t.assign(Sn(-2).mul(To(Gi(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Hp=yn((([e,t])=>{const s=e.toVar();s.assign(Gi(2,s).sub(1));const r=Un(s,1).toVar();return _n(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Wp=yn((([e,t,s,r,n,i])=>{const o=Sn(s),a=Un(t),u=da($p(o),Mp,i),l=Ro(u),d=vo(u),c=Un(jp(e,a,d,r,n,i)).toVar();return _n(l.notEqual(0),(()=>{const t=Un(jp(e,a,d.add(1),r,n,i)).toVar();c.assign(la(c,t,l))})),c})),jp=yn((([e,t,s,r,n,i])=>{const o=Sn(s).toVar(),a=Un(t),u=Sn(kp(a)).toVar(),l=Sn(Ko(Op.sub(o),0)).toVar();o.assign(Ko(o,Op));const d=Sn(bo(o)).toVar(),c=En(zp(a,u).mul(d.sub(2)).add(1)).toVar();return _n(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gi(3,Gp))),c.y.addAssign(Gi(4,bo(i).sub(d))),c.x.mulAssign(r),c.y.mulAssign(n),e.uv(c).grad(En(),En())})),qp=yn((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:n,CUBEUV_TEXEL_WIDTH:i,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(n.cross(s).mul(Co(r))).add(n.mul(n.dot(s).mul(u.oneMinus())));return jp(e,l,t,i,o,a)})),Kp=yn((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:n,samples:i,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Un(xa(t,s,ta(s,r))).toVar();_n(ho(h.equals(Un(0))),(()=>{h.assign(Un(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Un().toVar();return p.addAssign(n.element(An(0)).mul(qp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:An(1),end:e},(({i:e})=>{_n(e.greaterThanEqual(i),(()=>{dc()}));const t=Sn(o.mul(Sn(e))).toVar();p.addAssign(n.element(e).mul(qp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(n.element(e).mul(qp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ln(p,1)}));let Xp=null;const Yp=new WeakMap;function Qp(e){let t=Yp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r0}(s))return null;t=Xp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Yp.set(e,t)}return t.texture}class Zp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=ti(0),this._height=ti(0),this._maxMip=ti(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Qp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Xp&&(Xp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Un(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Wp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Jp=mn(Zp),eg=new WeakMap;class tg extends yc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let r=eg.get(e);void 0===r&&(r=Jp(e),eg.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),n=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,i=s.context(sg(ai,n)).mul(r),o=s.context(rg(cl)).mul(Math.PI).mul(r),a=eu(i),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(sg(di,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const sg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},rg=e=>({getUV:()=>e,getTextureLevel:()=>Sn(1)}),ng=new te;class ig extends nh{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ng),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new tg(t):null}setupLightingModel(){return new Ep}setupSpecular(){const e=la(Un(.04),ii.rgb,ui);Ti.assign(e),_i.assign(1)}setupVariants(){const e=this.metalnessNode?Sn(this.metalnessNode):yd;ui.assign(e);let t=this.roughnessNode?Sn(this.roughnessNode):fd;t=kh({roughness:t}),ai.assign(t),this.setupSpecular(),ii.assign(Ln(ii.rgb.mul(e.oneMinus()),ii.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const og=new se;class ag extends ig{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(og),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?Sn(this.iorNode):Bd;Ci.assign(e),Ti.assign(la(qo(ra(Ci.sub(1).div(Ci.add(1))).mul(pd),Un(1)).mul(hd),ii.rgb,ui)),_i.assign(la(hd,1,ui))}setupLightingModel(){return new Ep(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?Sn(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?Sn(this.clearcoatRoughnessNode):Td;li.assign(e),di.assign(kh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Un(this.sheenNode):vd,t=this.sheenRoughnessNode?Sn(this.sheenRoughnessNode):Sd;ci.assign(e),hi.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?Sn(this.iridescenceNode):Rd,t=this.iridescenceIORNode?Sn(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?Sn(this.iridescenceThicknessNode):Ed;pi.assign(e),gi.assign(t),mi.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?En(this.anisotropyNode):Ad).toVar();yi.assign(e.length()),_n(yi.equal(0),(()=>{e.assign(En(1,0))})).Else((()=>{e.divAssign(En(yi)),yi.assign(yi.saturate())})),fi.assign(yi.pow2().mix(ai.pow2(),1)),bi.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xi.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?Sn(this.transmissionNode):wd,t=this.thicknessNode?Sn(this.thicknessNode):Md,s=this.attenuationDistanceNode?Sn(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Un(this.attenuationColorNode):Fd;if(Ei.assign(e),wi.assign(t),Mi.assign(s),Bi.assign(r),this.useDispersion){const e=this.dispersionNode?Sn(this.dispersionNode):Gd;Ui.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Un(this.clearcoatNormalNode):_d}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class ug extends Ep{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){if(!0===this.useSSS){const r=n.material,{thicknessColorNode:i,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=Sn(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Un(h.add(a).mul(i));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n)}}class lg extends ag{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=Sn(.1),this.thicknessAmbientNode=Sn(0),this.thicknessAttenuationNode=Sn(.1),this.thicknessPowerNode=Sn(2),this.thicknessScaleNode=Sn(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ug(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const dg=yn((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),n=En(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>n});return Un(e.r)}{const e=n.fwidth().mul(.5);return la(Un(.7),Un(1),pa(Sn(.7).sub(e.x),Sn(.7).add(e.x),n.x))}}));class cg extends Ch{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){const i=dg({normal:il,lightDirection:e,builder:n}).mul(t);s.directDiffuse.addAssign(i.mul(Uh({diffuseColor:ii.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const hg=new re;class pg extends nh{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(hg),this.setValues(e)}setupLightingModel(){return new cg}}class gg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Un(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return En(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const mg=fn(gg),fg=new ne;class yg extends nh{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(fg),this.setValues(e)}setupVariants(e){const t=mg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Un(la(.2,.8,t.y)),ii.rgb.mulAssign(s.rgb)}}const bg=new P;class xg extends nh{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(bg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Tg extends Er{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Gn(e,r,r.negate(),e).mul(s)}{const e=t,r=zn(Ln(1,0,0,0),Ln(0,Eo(e.x),Co(e.x).negate(),0),Ln(0,Co(e.x),Eo(e.x),0),Ln(0,0,0,1)),n=zn(Ln(Eo(e.y),0,Co(e.y),0),Ln(0,1,0,0),Ln(Co(e.y).negate(),0,Eo(e.y),0),Ln(0,0,0,1)),i=zn(Ln(Eo(e.z),Co(e.z).negate(),0,0),Ln(Co(e.z),Eo(e.z),0,0),Ln(0,0,1,0),Ln(0,0,0,1));return r.mul(n).mul(i).mul(Ln(s,1)).xyz}}}const _g=mn(Tg),Ng=new ie;class vg extends nh{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Ng),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:n,rotationNode:i,scaleNode:o}=this,a=Yu;let u=ju.mul(Un(n||0)),l=En(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=Sn(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>hn(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=Sn(i||Nd),h=_g(d,c);u=Ln(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Sg extends Ch{constructor(){super(),this.shadowNode=Sn(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){ii.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(ii.rgb)}}const Ag=new oe;class Rg extends nh{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ag),this.setValues(e)}setupLightingModel(){return new Sg}}const Cg=yn((({texture:e,uv:t})=>{const s=1e-4,r=Un().toVar();return _n(t.x.lessThan(s),(()=>{r.assign(Un(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Un(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Un(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Un(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Un(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Un(0,0,-1))})).Else((()=>{const s=.01,n=e.uv(t.add(Un(-.01,0,0))).r.sub(e.uv(t.add(Un(s,0,0))).r),i=e.uv(t.add(Un(0,-.01,0))).r.sub(e.uv(t.add(Un(0,s,0))).r),o=e.uv(t.add(Un(0,0,-.01))).r.sub(e.uv(t.add(Un(0,0,s))).r);r.assign(Un(n,i,o))})),r.normalize()}));class Eg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Un(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Cg({texture:this,uv:e})}}const wg=mn(Eg);class Mg extends nh{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=wg(this.map,null,0),s=yn((({orig:e,dir:t})=>{const s=Un(-.5),r=Un(.5),n=t.reciprocal(),i=s.sub(e).mul(n),o=r.sub(e).mul(n),a=qo(i,o),u=Ko(i,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return En(l,d)}));this.fragmentNode=yn((()=>{const e=Ea(Un(Wu.mul(Ln(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),n=En(s({orig:e,dir:r})).toVar();n.x.greaterThan(n.y).discard(),n.assign(En(Ko(n.x,0),n.y));const i=Un(e.add(n.x.mul(r))).toVar(),o=Un(r.abs().reciprocal()).toVar(),a=Sn(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ln(Fl("base","color"),0).toVar();return uc({type:"float",start:n.x,end:n.y,update:"+= delta"},(()=>{const e=ri("float","d").assign(t.uv(i.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:i,finalColor:u}).append():(u.a.assign(1),dc()),i.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ln(u)}))(),super.setup(e)}}class Bg{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ug{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const n of e){const e=n.node&&n.node.attribute?n.node.attribute:t.getAttribute(n.name);if(void 0===e)continue;s.push(e);const i=e.isInterleavedBufferAttribute?e.data:e;r.add(i)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:n}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(i.instanceCount=u,!0===e.isBatchedMesh)return i;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=n.start*l,c=(n.start+n.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(i.vertexCount=g,i.firstVertex=d,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let n;if(null!==r){const e=typeof r;"number"===e?n=0!==r?"1":"0":"object"===e?(n="{",r.isTexture&&(n+=r.mapping),n+="}"):n=String(r)}else n=String(r);s+=n+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Ig=[];class Lg{constructor(e,t,s,r,n,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=n,this.info=i,this.chainMaps={}}get(e,t,s,r,n,i,o,a){const u=this.getChainMap(a);Ig[0]=e,Ig[1]=t,Ig[2]=i,Ig[3]=n;let l=u.get(Ig);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,n,i,o,a),u.set(Ig,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,n,i,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ug)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,n,i,o,a,u,l,d){const c=this.getChainMap(d),h=new Pg(e,t,s,r,n,i,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Dg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Vg=1,Og=2,Gg=3,kg=4,zg=16;class $g extends Dg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Vg?this.backend.createAttribute(e):t===Og?this.backend.createIndexAttribute(e):t===Gg?this.backend.createStorageAttribute(e):t===kg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return n.version=Hg(e),n}class jg extends Dg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,n=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of n)this.attributes.delete(e);const i=this.wireframes.get(t);void 0!==i&&this.attributes.delete(i),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Gg):this.updateAttribute(e,Vg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Og);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,kg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Wg(t),e.set(t,s)):s.version!==Hg(t)&&(this.attributes.delete(s),s=Wg(t),e.set(t,s)),r=s}return r}}class qg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Kg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Xg extends Kg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Yg extends Kg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Qg=0;class Zg{constructor(e,t,s=null,r=null){this.id=Qg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Jg extends Dg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let o=this.programs.compute.get(i.computeShader);void 0===o&&(n&&0===n.computeProgram.usedTimes&&this._releaseProgram(n.computeProgram),o=new Zg(i.computeShader,"compute",i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(n&&0===n.usedTimes&&this._releasePipeline(n),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState();let o=this.programs.vertex.get(i.vertexShader);void 0===o&&(n&&0===n.vertexProgram.usedTimes&&this._releaseProgram(n.vertexProgram),o=new Zg(i.vertexShader,"vertex"),this.programs.vertex.set(i.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(i.fragmentShader);void 0===a&&(n&&0===n.fragmentProgram.usedTimes&&this._releaseProgram(n.fragmentProgram),a=new Zg(i.fragmentShader,"fragment"),this.programs.fragment.set(i.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(n&&0===n.usedTimes&&this._releasePipeline(n),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return void 0===n&&(n=new Yg(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,r)),n}_getRenderPipeline(e,t,s,r,n){r=r||this._getRenderCacheKey(e,t,s);let i=this.caches.get(r);return void 0===i&&(i=new Xg(r,t,s),this.caches.set(r,i),e.pipeline=i,this.backend.createRenderPipeline(e,n)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class em extends Dg{constructor(e,t,s,r,n,i){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=r,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,s=e.isIndirectStorageBufferAttribute?kg:Gg;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1,n=!0,i=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(r=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=s.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?n=!1:(i=10*i+u.id,o+=u.version),!0===s.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,r),this.textures.updateTexture(u),r=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t,n?i:0,o)}}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function sm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function rm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class nm{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,n,i,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:n,group:i,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=n,a.group=i,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||tm),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||sm),this.transparent.length>1&&this.transparent.sort(t||sm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||n[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,n[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=i,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&n.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=dm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class hm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class pm extends si{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const gm=(e,t)=>hn(new pm(e,t));class mm extends Ar{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new cn(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new cn(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new cn(e),this}build(e,...t){const s=Tn();xn(this);for(const t of this.nodes)t.build(e,"void");return xn(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const fm=mn(mm);class ym extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}const bm=e=>Object.entries(e).map((([e,t])=>"string"==typeof t?{name:e,type:t,isAtomic:!1}:{name:e,type:t.type,isAtomic:t.atomic||!1}));class xm extends Ar{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let r=0;r{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),Am=(e,t)=>sa(Gi(4,e.mul(Oi(1,e))),t),Rm=(e,t)=>e.lessThan(.5)?Am(e.mul(2),t).div(2):Oi(1,Am(Gi(Oi(1,e),2),t).div(2)),Cm=(e,t,s)=>sa(ki(sa(e,t),Vi(sa(e,t),sa(Oi(1,e),s))),1/t),Em=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),wm=yn((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),Mm=yn((([e])=>Un(wm(e.z.add(wm(e.y.mul(1)))),wm(e.z.add(wm(e.x.mul(1)))),wm(e.y.add(wm(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Bm=yn((([e,t,s])=>{const r=Un(e).toVar(),n=Sn(1.4).toVar(),i=Sn(0).toVar(),o=Un(r).toVar();return uc({start:Sn(0),end:Sn(3),type:"float",condition:"<="},(()=>{const e=Un(Mm(o.mul(2))).toVar();r.addAssign(e.add(s.mul(Sn(.1).mul(t)))),o.mulAssign(1.8),n.mulAssign(1.5),r.mulAssign(1.2);const a=Sn(wm(r.z.add(wm(r.x.add(wm(r.y)))))).toVar();i.addAssign(a.div(n)),o.addAssign(.14)})),i})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Um extends Ar{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let r=null,n=-1;for(const s of this.functionNodes){const i=s.shaderNode.layout;if(null===i)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=i.inputs;if(t.length===o.length){let i=0;for(let s=0;sn&&(r=s,n=i)}}this._candidateFnCall=s=r(...t)}return s}}const Fm=mn(Um),Pm=e=>(...t)=>Fm(e,...t),Im=ti(0).setGroup(Zn).onRenderUpdate((e=>e.time)),Lm=ti(0).setGroup(Zn).onRenderUpdate((e=>e.deltaTime)),Dm=ti(0,"uint").setGroup(Zn).onRenderUpdate((e=>e.frameId)),Vm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Im.mul(e)),Om=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Im.mul(e)),Gm=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Lm.mul(e)),km=(e=Im)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),zm=(e=Im)=>e.fract().round(),$m=(e=Im)=>e.add(.5).fract().mul(2).sub(1).abs(),Hm=(e=Im)=>e.fract(),Wm=yn((([e,t,s=En(.5)])=>_g(e.sub(s),t).add(s))),jm=yn((([e,t,s=En(.5)])=>{const r=e.sub(s),n=r.dot(r),i=n.mul(n).mul(t);return e.add(r.mul(i))})),qm=yn((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const n=Eu.mul(r);return ln(t)&&(n[0][0]=Gu[0].length(),n[0][1]=0,n[0][2]=0),ln(s)&&(n[1][0]=0,n[1][1]=Gu[1].length(),n[1][2]=0),n[2][0]=0,n[2][1]=0,n[2][2]=1,Ru.mul(n).mul(Yu)})),Km=yn((([e=null])=>{const t=Qc();return Qc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class Xm extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=Sn(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:n}=s,i=e.mod(r.mul(n)).floor(),o=i.mod(r),a=n.sub(i.add(1).div(r).ceil()),u=s.reciprocal(),l=En(o,a);return t.add(l).mul(u)}}const Ym=mn(Xm);class Qm extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=Sn(1),n=Yu,i=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=n,this.normalNode=i}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:n,normalNode:i}=this;let o=i.abs().normalize();o=o.div(o.dot(Un(1)));const a=n.yz.mul(r),u=n.zx.mul(r),l=n.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vi(p,g,m)}}const Zm=mn(Qm),Jm=(...e)=>Zm(...e),ef=new me,tf=new s,sf=new s,rf=new s,nf=new i,of=new s(0,0,-1),af=new r,uf=new s,lf=new s,df=new r,cf=new t,hf=new ge,pf=Ac.flipX();hf.depthTexture=new B(1,1);let gf=!1;class mf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||hf.texture,pf),this._reflectorBaseNode=e.reflector||new ff(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=hn(new mf({defaultTexture:hf.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class ff extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:n=!1,bounces:i=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=n,this.bounces=i,this.depth=o,this.updateBeforeType=i?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(cf),e.setSize(Math.round(cf.width*s),Math.round(cf.height*s))}setup(e){return this._updateResolution(hf,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&gf)return;gf=!0;const{scene:t,camera:s,renderer:r,material:n}=e,{target:i}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(cf),this._updateResolution(a,r),sf.setFromMatrixPosition(i.matrixWorld),rf.setFromMatrixPosition(s.matrixWorld),nf.extractRotation(i.matrixWorld),tf.set(0,0,1),tf.applyMatrix4(nf),uf.subVectors(sf,rf),uf.dot(tf)>0)return;uf.reflect(tf).negate(),uf.add(sf),nf.extractRotation(s.matrixWorld),of.set(0,0,-1),of.applyMatrix4(nf),of.add(rf),lf.subVectors(sf,of),lf.reflect(tf).negate(),lf.add(sf),o.coordinateSystem=s.coordinateSystem,o.position.copy(uf),o.up.set(0,1,0),o.up.applyMatrix4(nf),o.up.reflect(tf),o.lookAt(lf),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),ef.setFromNormalAndCoplanarPoint(tf,sf),ef.applyMatrix4(o.matrixWorldInverse),af.set(ef.normal.x,ef.normal.y,ef.normal.z,ef.constant);const u=o.projectionMatrix;df.x=(Math.sign(af.x)+u.elements[8])/u.elements[0],df.y=(Math.sign(af.y)+u.elements[9])/u.elements[5],df.z=-1,df.w=(1+u.elements[10])/u.elements[14],af.multiplyScalar(1/af.dot(df));u.elements[2]=af.x,u.elements[6]=af.y,u.elements[10]=r.coordinateSystem===N?af.z-0:af.z+1-0,u.elements[14]=af.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),n.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),n.visible=!0,gf=!1}}const yf=e=>hn(new mf(e)),bf=new xe(-1,1,1,-1,0,1);class xf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const Tf=new xf;class _f extends k{constructor(e=null){super(Tf,e),this.camera=bf,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,bf)}render(e){e.render(this,bf)}}const Nf=new t;class vf extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const n=new ge(t,s,r);super(n.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=n,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new _f(new nh),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(Nf);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const Sf=(e,...t)=>hn(new vf(hn(e),...t)),Af=(e,...t)=>e.isTextureNode?e:Sf(e,...t),Rf=yn((([e,t,s],r)=>{let n;r.renderer.coordinateSystem===N?(e=En(e.x,e.y.oneMinus()).mul(2).sub(1),n=Ln(Un(e,t),1)):n=Ln(Un(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const i=Ln(s.mul(n));return i.xyz.div(i.w)})),Cf=yn((([e,t])=>{const s=t.mul(Ln(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return En(r.x,r.y.oneMinus())})),Ef=yn((([e,t,s])=>{const r=yu(Nu(t)),n=wn(e.mul(r)).toVar(),i=Nu(t,n).toVar(),o=Nu(t,n.sub(wn(2,0))).toVar(),a=Nu(t,n.sub(wn(1,0))).toVar(),u=Nu(t,n.add(wn(1,0))).toVar(),l=Nu(t,n.add(wn(2,0))).toVar(),d=Nu(t,n.add(wn(0,2))).toVar(),c=Nu(t,n.add(wn(0,1))).toVar(),h=Nu(t,n.sub(wn(0,1))).toVar(),p=Nu(t,n.sub(wn(0,2))).toVar(),g=Fo(Oi(Sn(2).mul(a).sub(o),i)).toVar(),m=Fo(Oi(Sn(2).mul(u).sub(l),i)).toVar(),f=Fo(Oi(Sn(2).mul(c).sub(d),i)).toVar(),y=Fo(Oi(Sn(2).mul(h).sub(p),i)).toVar(),b=Rf(e,i,s).toVar(),x=g.lessThan(m).select(b.sub(Rf(e.sub(En(Sn(1).div(r.x),0)),a,s)),b.negate().add(Rf(e.add(En(Sn(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Rf(e.add(En(0,Sn(1).div(r.y))),c,s)),b.negate().add(Rf(e.sub(En(0,Sn(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class wf extends pu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const Mf=(...e)=>hn(new wf(...e));class Bf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Uf=fn(Bf),Ff=new ve,Pf=new i;class If extends Ar{static get type(){return"SceneNode"}constructor(e=If.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===If.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===If.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===If.BACKGROUND_ROTATION?r=ti("mat4").label("backgroundRotation").setGroup(Zn).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Ff.copy(s.backgroundRotation),Ff.x*=-1,Ff.y*=-1,Ff.z*=-1,Pf.makeRotationFromEuler(Ff)):Pf.identity(),Pf})):console.error("THREE.SceneNode: Unknown scope:",t),r}}If.BACKGROUND_BLURRINESS="backgroundBlurriness",If.BACKGROUND_INTENSITY="backgroundIntensity",If.BACKGROUND_ROTATION="backgroundRotation";const Lf=fn(If,If.BACKGROUND_BLURRINESS),Df=fn(If,If.BACKGROUND_INTENSITY),Vf=fn(If,If.BACKGROUND_ROTATION);class Of extends Rr{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Gf=mn(Of),kf="point-list",zf="line-list",$f="line-strip",Hf="triangle-list",Wf="triangle-strip",jf="never",qf="less",Kf="equal",Xf="less-equal",Yf="greater",Qf="not-equal",Zf="greater-equal",Jf="always",ey="store",ty="load",sy="clear",ry="ccw",ny="none",iy="front",oy="back",ay="uint16",uy="uint32",ly={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},dy="clamp-to-edge",cy="repeat",hy="mirror-repeat",py="linear",gy="nearest",my="zero",fy="one",yy="src",by="one-minus-src",xy="src-alpha",Ty="one-minus-src-alpha",_y="dst",Ny="one-minus-dst",vy="dst-alpha",Sy="one-minus-dst-alpha",Ay="src-alpha-saturated",Ry="constant",Cy="one-minus-constant",Ey="add",wy="subtract",My="reverse-subtract",By="min",Uy="max",Fy=0,Py=15,Iy="keep",Ly="zero",Dy="replace",Vy="invert",Oy="increment-clamp",Gy="decrement-clamp",ky="increment-wrap",zy="decrement-wrap",$y="storage",Hy="read-only-storage",Wy="write-only",jy="read-only",qy="float",Ky="unfilterable-float",Xy="depth",Yy="sint",Qy="uint",Zy="2d",Jy="3d",eb="2d",tb="2d-array",sb="cube",rb="3d",nb="all",ib="vertex",ob="instance",ab={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class ub extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=$y,this.isAtomic=!1,this.bufferObject=!1,this.bufferStruct=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Gf(this,e)}setBufferObject(e){return this.bufferObject=e,this}setBufferStruct(e){return this.bufferStruct=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Hy)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),r=s.build(e);return e.registerTransform(r,t),r}}const lb=(e,t,s)=>hn(new ub(e,t,s)),db=(e,t,s)=>hn(new ub(e,t,s).setBufferStruct(!0)),cb=(e,t,s)=>hn(new ub(e,t,s).setBufferObject(!0));class hb extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Wy}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(jy)}toWriteOnly(){return this.setAccess(Wy)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,n=super.generate(e,"property"),i=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,n,i,o);e.addLineFlowCode(a,this)}}const pb=mn(hb),gb=(e,t,s)=>{const r=pb(e,t,s);return null!==s&&r.append(),r};class mb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const fb=(e,t,s)=>hn(new mb(e,t,s)),yb=new WeakMap;class bb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=ti(new i),this.previousProjectionMatrix=ti(new i).setGroup(Zn),this.previousCameraViewMatrix=ti(new i)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=Tb(s);this.previousModelWorldMatrix.value.copy(r);const n=xb(t);n.frameId!==e&&(n.frameId=e,void 0===n.previousProjectionMatrix?(n.previousProjectionMatrix=new i,n.previousCameraViewMatrix=new i,n.currentProjectionMatrix=new i,n.currentCameraViewMatrix=new i,n.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(n.previousProjectionMatrix.copy(n.currentProjectionMatrix),n.previousCameraViewMatrix.copy(n.currentCameraViewMatrix)),n.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(n.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(n.previousCameraViewMatrix))}updateAfter({object:e}){Tb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:ti(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),n=s.xy.div(s.w),i=r.xy.div(r.w);return Oi(n,i)}}function xb(e){let t=yb.get(e);return void 0===t&&(t={},yb.set(e,t)),t}function Tb(e,t=0){const s=xb(e);let r=s[t];return void 0===r&&(s[t]=r=new i),r}const _b=fn(bb),Nb=yn((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=yn((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Sb=yn((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Ab=yn((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Rb=yn((([e,t])=>Ln(e.rgb.mul(t.a.oneMinus()).add(t.rgb.mul(t.a)),e.a))).setLayout({name:"blendNormal",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Cb=yn((([e])=>Bb(e.rgb))),Eb=yn((([e,t=Sn(1)])=>t.mix(Bb(e.rgb),e.rgb))),wb=yn((([e,t=Sn(1)])=>{const s=Vi(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),n=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,n)})),Mb=yn((([e,t=Sn(1)])=>{const s=Un(.57735,.57735,.57735),r=t.cos();return Un(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),Bb=(e,t=Un(u.getLuminanceCoefficients(new s)))=>ea(e,t),Ub=(e,t)=>la(Un(0),e,Bb(e).sub(t).max(0)),Fb=yn((([e,t=Un(1),r=Un(0),n=Un(1),i=Sn(1),o=Un(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Un(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(n).toVar();return _n(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),_n(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),_n(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(i))),Ln(l.rgb,e.a)}));class Pb extends Er{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Ib=mn(Pb);let Lb=null;class Db extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Lb&&(Lb=new w),super(e,t,Lb)}updateReference(){return this}}const Vb=mn(Db),Ob=new t;class Gb extends Tu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class kb extends Gb{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class zb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const n=new B;n.isRenderTargetTexture=!0,n.name="depth";const i=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});i.texture.name="output",i.depthTexture=n,this.renderTarget=i,this.updateBeforeType=br.FRAME,this._textures={output:i.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=ti(0),this._cameraFar=ti(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=hn(new kb(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=hn(new kb(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(n,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===zb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const n=t.getSize(Ob);this.setSize(n.width,n.height);const i=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(i),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}zb.COLOR="color",zb.DEPTH="depth";const $b=(e,t,s)=>hn(new zb(zb.COLOR,e,t,s)),Hb=(e,t)=>hn(new Gb(e,t)),Wb=(e,t)=>hn(new zb(zb.DEPTH,e,t));class jb extends zb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,n){super(zb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=n,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,n,i,o,a,u)=>{if((i.isMeshToonMaterial||i.isMeshToonNodeMaterial)&&!1===i.wireframe){const l=this._getOutlineMaterial(i);t.renderObject(e,s,r,n,l,o,a,u)}t.renderObject(e,s,r,n,i,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new nh;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=Sn(1),n=s.mul(Ln(Yu,1)),i=s.mul(Ln(Yu.add(t),1)),o=Ao(n.sub(i));return e.vertexNode=n.add(o.mul(this.thicknessNode).mul(n.w).mul(r)),e.colorNode=Ln(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const qb=(t,s,r=new e(0,0,0),n=.003,i=1)=>hn(new jb(t,s,hn(r),hn(n),hn(i))),Kb=yn((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=yn((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Yb=yn((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qb=yn((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Zb=yn((([e,t])=>{const s=kn(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=kn(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=Qb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Jb=kn(Un(1.6605,-.1246,-.0182),Un(-.5876,1.1329,-.1006),Un(-.0728,-.0083,1.1187)),ex=kn(Un(.6274,.0691,.0164),Un(.3293,.9195,.088),Un(.0433,.0113,.8956)),tx=yn((([e])=>{const t=Un(e).toVar(),s=Un(t.mul(t)).toVar(),r=Un(s.mul(s)).toVar();return Sn(15.5).mul(r.mul(s)).sub(Gi(40.14,r.mul(t))).add(Gi(31.96,r).sub(Gi(6.868,s.mul(t))).add(Gi(.4298,s).add(Gi(.1191,t).sub(.00232))))})),sx=yn((([e,t])=>{const s=Un(e).toVar(),r=kn(Un(.856627153315983,.137318972929847,.11189821299995),Un(.0951212405381588,.761241990602591,.0767994186031903),Un(.0482516061458583,.101439036467562,.811302368396859)),n=kn(Un(1.1271005818144368,-.1413297634984383,-.14132976349843826),Un(-.11060664309660323,1.157823702216272,-.11060664309660294),Un(-.016493938717834573,-.016493938717834257,1.2519364065950405)),i=Sn(-12.47393),o=Sn(4.026069);return s.mulAssign(t),s.assign(ex.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(i).div(o.sub(i))),s.assign(da(s,0,1)),s.assign(tx(s)),s.assign(n.mul(s)),s.assign(sa(Ko(Un(0),s),Un(2.2))),s.assign(Jb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),rx=yn((([e,t])=>{const s=Sn(.76),r=Sn(.15);e=e.mul(t);const n=qo(e.r,qo(e.g,e.b)),i=xa(n.lessThan(.08),n.sub(Gi(6.25,n.mul(n))),.04);e.subAssign(i);const o=Ko(e.r,Ko(e.g,e.b));_n(o.lessThan(s),(()=>e));const a=Oi(1,s),u=Oi(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=Oi(1,ki(1,r.mul(o.sub(u)).add(1)));return la(e,Un(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class nx extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const ix=mn(nx),ox=(e,t)=>ix(e,t,"js"),ax=(e,t)=>ix(e,t,"wgsl"),ux=(e,t)=>ix(e,t,"glsl");class lx extends nx{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,n=s.type,i=e.getCodeFromNode(this,n);""!==r&&(i.name=r);const o=e.getPropertyName(i),a=this.getNodeFunction(e).getCode(o);return i.code=a+"\n","property"===t?o:e.format(`${o}()`,n,t)}}const dx=(e,t=[],s="")=>{for(let e=0;er.call(...e);return n.functionNode=r,n},cx=(e,t)=>dx(e,t,"glsl"),hx=(e,t)=>dx(e,t,"wgsl");class px extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:Sn()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const gx=mn(px);class mx extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class fx{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const yx=new mx;class bx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new mx,this._output=gx(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=gx(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=gx(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new fx(this),t=yx.get("THREE"),s=yx.get("TSL"),r=this.getMethod(this.codeNode),n=[e,this._local,yx,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...n);const i=this._object.layout;if(i&&(!1===i.cache&&this._local.clear(),this._output.outputType=i.outputType||null,Array.isArray(i.elements)))for(const e of i.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:Sn()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const xx=mn(bx);class Tx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const _x=mn(Tx);class Nx extends Tx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const vx=mn(Nx);class Sx extends Tx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const Ax=mn(Sx);let Rx=null,Cx=null;class Ex extends Ar{static get type(){return"RangeNode"}constructor(e=Sn(),t=Sn()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const n=this.minNode.value,i=this.maxNode.value,o=e.getTypeLength(hr(n)),u=e.getTypeLength(hr(i));Rx=Rx||new r,Cx=Cx||new r,Rx.setScalar(0),Cx.setScalar(0),1===o?Rx.setScalar(n):n.isColor?Rx.set(n.r,n.g,n.b):Rx.set(n.x,n.y,n.z||0,n.w||0),1===u?Cx.setScalar(i):i.isColor?Cx.set(i.r,i.g,i.b):Cx.set(i.x,i.y,i.z||0,i.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;ehn(new Mx(e,t)),Ux=Bx("numWorkgroups","uvec3"),Fx=Bx("workgroupId","uvec3"),Px=Bx("localId","uvec3"),Ix=Bx("subgroupSize","uint");const Lx=mn(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Dx=()=>Lx("workgroup").append(),Vx=()=>Lx("storage").append(),Ox=()=>Lx("texture").append();class Gx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class kx extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return hn(new Gx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const zx=(e,t)=>hn(new kx("Workgroup",e,t));class $x extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),n=this.pointerNode,i=this.valueNode,o=[];o.push(`&${n.build(e,r)}`),o.push(i.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}$x.ATOMIC_LOAD="atomicLoad",$x.ATOMIC_STORE="atomicStore",$x.ATOMIC_ADD="atomicAdd",$x.ATOMIC_SUB="atomicSub",$x.ATOMIC_MAX="atomicMax",$x.ATOMIC_MIN="atomicMin",$x.ATOMIC_AND="atomicAnd",$x.ATOMIC_OR="atomicOr",$x.ATOMIC_XOR="atomicXor";const Hx=mn($x),Wx=(e,t,s,r)=>{const n=Hx(e,t,s,r);return n.append(),n},jx=(e,t,s=null)=>Wx($x.ATOMIC_STORE,e,t,s),qx=(e,t,s=null)=>Wx($x.ATOMIC_ADD,e,t,s),Kx=(e,t,s=null)=>Wx($x.ATOMIC_SUB,e,t,s),Xx=(e,t,s=null)=>Wx($x.ATOMIC_MAX,e,t,s),Yx=(e,t,s=null)=>Wx($x.ATOMIC_MIN,e,t,s),Qx=(e,t,s=null)=>Wx($x.ATOMIC_AND,e,t,s),Zx=(e,t,s=null)=>Wx($x.ATOMIC_OR,e,t,s),Jx=(e,t,s=null)=>Wx($x.ATOMIC_XOR,e,t,s);let eT;function tT(e){eT=eT||new WeakMap;let t=eT.get(e);return void 0===t&&eT.set(e,t={}),t}function sT(e){const t=tT(e);return t.position||(t.position=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function rT(e){const t=tT(e);return t.targetPosition||(t.targetPosition=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function nT(e){const t=tT(e);return t.viewPosition||(t.viewPosition=ti(new s).setGroup(Zn).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const iT=e=>Eu.transformDirection(sT(e).sub(rT(e))),oT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},aT=new WeakMap;class uT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Un().toVar("totalDiffuse"),this.totalSpecularNode=Un().toVar("totalSpecular"),this.outgoingLightNode=Un().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),n=e.renderer.library;for(const e of r)if(e.isNode)t.push(hn(e));else{let r=null;if(null!==s&&(r=oT(e.id,s)),null===r){const s=n.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;aT.has(e)?r=aT.get(e):(r=hn(new s(e)),aT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:n,totalDiffuseNode:i,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,n),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Un(null!==l?l.mix(g,u):u),t.material.transparent=!0),i.assign(g),o.assign(c.add(p)),r.assign(i.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const lT=(e=[])=>hn(new uT).setLights(e),dT=yn((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),cT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=Ml("radius","float",s).setGroup(Zn),o=En(1).div(n),a=o.x.negate().mul(i),u=o.y.negate().mul(i),l=o.x.mul(i),d=o.y.mul(i),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vi(r(t.xy.add(En(a,u)),t.z),r(t.xy.add(En(0,u)),t.z),r(t.xy.add(En(l,u)),t.z),r(t.xy.add(En(c,h)),t.z),r(t.xy.add(En(0,h)),t.z),r(t.xy.add(En(p,h)),t.z),r(t.xy.add(En(a,0)),t.z),r(t.xy.add(En(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(En(p,0)),t.z),r(t.xy.add(En(l,0)),t.z),r(t.xy.add(En(c,g)),t.z),r(t.xy.add(En(0,g)),t.z),r(t.xy.add(En(p,g)),t.z),r(t.xy.add(En(a,d)),t.z),r(t.xy.add(En(0,d)),t.z),r(t.xy.add(En(l,d)),t.z)).mul(1/17)})),hT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=En(1).div(n),o=i.x,a=i.y,u=t.xy,l=Ro(u.mul(n).add(.5));return u.subAssign(l.mul(i)),Vi(r(u,t.z),r(u.add(En(o,0)),t.z),r(u.add(En(0,a)),t.z),r(u.add(i),t.z),la(r(u.add(En(o.negate(),0)),t.z),r(u.add(En(o.mul(2),0)),t.z),l.x),la(r(u.add(En(o.negate(),a)),t.z),r(u.add(En(o.mul(2),a)),t.z),l.x),la(r(u.add(En(0,a.negate())),t.z),r(u.add(En(0,a.mul(2))),t.z),l.y),la(r(u.add(En(o,a.negate())),t.z),r(u.add(En(o,a.mul(2))),t.z),l.y),la(la(r(u.add(En(o.negate(),a.negate())),t.z),r(u.add(En(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(En(o.negate(),a.mul(2))),t.z),r(u.add(En(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),pT=yn((({depthTexture:e,shadowCoord:t})=>{const s=Sn(1).toVar(),r=_u(e).uv(t.xy).rg,n=Yo(t.z,r.x);return _n(n.notEqual(Sn(1)),(()=>{const e=t.z.sub(r.x),i=Ko(0,r.y.mul(r.y));let o=i.div(i.add(e.mul(e)));o=da(Oi(o,.3).div(.95-.3)),s.assign(da(Ko(n,o)))})),s})),gT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(0,u).mul(t)).div(s)).x;n.addAssign(l),i.addAssign(l.mul(l))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),mT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(u,0).mul(t)).div(s));n.addAssign(l.x),i.addAssign(Vi(l.y.mul(l.y),l.x.mul(l.x)))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),fT=[dT,cT,hT,pT];let yT=null;const bT=new _f;class xT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===yT&&(yT=new nh,yT.fragmentNode=Ln(0,0,0,1),yT.isShadowNodeMaterial=!0,yT.name="ShadowMaterial");const r=this.shadow,n=s.shadowMap.type,i=new B(r.mapSize.width,r.mapSize.height);i.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=i,r.camera.updateProjectionMatrix(),n===Re){i.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(i),s=_u(this.vsmShadowMapVertical.texture),n=Ml("blurSamples","float",r).setGroup(Zn),o=Ml("radius","float",r).setGroup(Zn),a=Ml("mapSize","vec2",r).setGroup(Zn);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new nh);u.fragmentNode=gT({samples:n,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new nh),u.fragmentNode=mT({samples:n,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Zn),u=Ml("bias","float",r).setGroup(Zn),l=Ml("normalBias","float",r).setGroup(Zn),d=t.material.shadowPositionNode||Zu;let c,h=ti(r.matrix).setGroup(Zn).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=Ml("near","float",r.camera).setGroup(Zn),s=Ml("far","float",r.camera).setGroup(Zn);c=qc(e.negate(),t,s)}h=Un(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||fT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:n===Re?this.vsmShadowMapHorizontal.texture:i,shadowCoord:h,shadow:r}),Sn(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:n,scene:i,camera:o}=e,a=n.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=i.overrideMaterial;i.overrideMaterial=yT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=n.getRenderTarget(),c=n.getRenderObjectFunction();n.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&n.renderObject(e,...t)})),n.setRenderTarget(t),n.render(i,r.camera),n.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(n),n.setRenderTarget(d),i.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),bT.material=this.vsmMaterialVertical,bT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),bT.material=this.vsmMaterialHorizontal,bT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const TT=(e,t)=>hn(new xT(e,t));class _T extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=ti(this.color).setGroup(Zn),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?hn(e):TT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const NT=yn((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,n=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(n.mul(t.div(s).pow4().oneMinus().clamp().pow2()),n)})),vT=yn((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},n)=>{const i=n.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=NT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=n.context.reflectedLight;i.direct({lightDirection:a,lightColor:d,reflectedLight:c},n.stack,n)}));class ST extends _T{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){vT({color:this.colorNode,lightViewPosition:nT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const AT=yn((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),RT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Cn(e).toVar();return xa(i,n,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),CT=yn((([e,t])=>{const s=Cn(t).toVar(),r=Sn(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),ET=yn((([e])=>{const t=Sn(e).toVar();return An(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),wT=yn((([e,t])=>{const s=Sn(e).toVar();return t.assign(ET(s)),s.sub(Sn(t))})),MT=Pm([yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Sn(r).toVar(),l=Sn(s).toVar(),d=Sn(t).toVar(),c=Sn(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Un(r).toVar(),l=Un(s).toVar(),d=Un(t).toVar(),c=Un(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),BT=Pm([yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Sn(a).toVar(),m=Sn(o).toVar(),f=Sn(i).toVar(),y=Sn(n).toVar(),b=Sn(r).toVar(),x=Sn(s).toVar(),T=Sn(t).toVar(),_=Sn(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Un(a).toVar(),m=Un(o).toVar(),f=Un(i).toVar(),y=Un(n).toVar(),b=Un(r).toVar(),x=Un(s).toVar(),T=Un(t).toVar(),_=Un(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),UT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Rn(e).toVar(),o=Rn(i.bitAnd(Rn(7))).toVar(),a=Sn(RT(o.lessThan(Rn(4)),n,r)).toVar(),u=Sn(Gi(2,RT(o.lessThan(Rn(4)),r,n))).toVar();return CT(a,Cn(o.bitAnd(Rn(1)))).add(CT(u,Cn(o.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),FT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Rn(e).toVar(),u=Rn(a.bitAnd(Rn(15))).toVar(),l=Sn(RT(u.lessThan(Rn(8)),o,i)).toVar(),d=Sn(RT(u.lessThan(Rn(4)),i,RT(u.equal(Rn(12)).or(u.equal(Rn(14))),o,n))).toVar();return CT(l,Cn(u.bitAnd(Rn(1)))).add(CT(d,Cn(u.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),PT=Pm([UT,FT]),IT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Pn(e).toVar();return Un(PT(i.x,n,r),PT(i.y,n,r),PT(i.z,n,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),LT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Pn(e).toVar();return Un(PT(a.x,o,i,n),PT(a.y,o,i,n),PT(a.z,o,i,n))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),DT=Pm([IT,LT]),VT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),OT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),GT=Pm([VT,yn((([e])=>{const t=Un(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),kT=Pm([OT,yn((([e])=>{const t=Un(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),zT=yn((([e,t])=>{const s=An(t).toVar(),r=Rn(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(An(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),$T=yn((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(zT(s,An(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(zT(e,An(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(zT(t,An(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(zT(s,An(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(zT(e,An(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(zT(t,An(4))),t.addAssign(e)})),HT=yn((([e,t,s])=>{const r=Rn(s).toVar(),n=Rn(t).toVar(),i=Rn(e).toVar();return r.bitXorAssign(n),r.subAssign(zT(n,An(14))),i.bitXorAssign(r),i.subAssign(zT(r,An(11))),n.bitXorAssign(i),n.subAssign(zT(i,An(25))),r.bitXorAssign(n),r.subAssign(zT(n,An(16))),i.bitXorAssign(r),i.subAssign(zT(r,An(4))),n.bitXorAssign(i),n.subAssign(zT(i,An(14))),r.bitXorAssign(n),r.subAssign(zT(n,An(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),WT=yn((([e])=>{const t=Rn(e).toVar();return Sn(t).div(Sn(Rn(An(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),jT=yn((([e])=>{const t=Sn(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),qT=Pm([yn((([e])=>{const t=An(e).toVar(),s=Rn(Rn(1)).toVar(),r=Rn(Rn(An(3735928559)).add(s.shiftLeft(Rn(2))).add(Rn(13))).toVar();return HT(r.add(Rn(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(Rn(2)).toVar(),i=Rn().toVar(),o=Rn().toVar(),a=Rn().toVar();return i.assign(o.assign(a.assign(Rn(An(3735928559)).add(n.shiftLeft(Rn(2))).add(Rn(13))))),i.addAssign(Rn(r)),o.addAssign(Rn(s)),HT(i,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(Rn(3)).toVar(),a=Rn().toVar(),u=Rn().toVar(),l=Rn().toVar();return a.assign(u.assign(l.assign(Rn(An(3735928559)).add(o.shiftLeft(Rn(2))).add(Rn(13))))),a.addAssign(Rn(i)),u.addAssign(Rn(n)),l.addAssign(Rn(r)),HT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),yn((([e,t,s,r])=>{const n=An(r).toVar(),i=An(s).toVar(),o=An(t).toVar(),a=An(e).toVar(),u=Rn(Rn(4)).toVar(),l=Rn().toVar(),d=Rn().toVar(),c=Rn().toVar();return l.assign(d.assign(c.assign(Rn(An(3735928559)).add(u.shiftLeft(Rn(2))).add(Rn(13))))),l.addAssign(Rn(a)),d.addAssign(Rn(o)),c.addAssign(Rn(i)),$T(l,d,c),l.addAssign(Rn(n)),HT(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),yn((([e,t,s,r,n])=>{const i=An(n).toVar(),o=An(r).toVar(),a=An(s).toVar(),u=An(t).toVar(),l=An(e).toVar(),d=Rn(Rn(5)).toVar(),c=Rn().toVar(),h=Rn().toVar(),p=Rn().toVar();return c.assign(h.assign(p.assign(Rn(An(3735928559)).add(d.shiftLeft(Rn(2))).add(Rn(13))))),c.addAssign(Rn(l)),h.addAssign(Rn(u)),p.addAssign(Rn(a)),$T(c,h,p),c.addAssign(Rn(o)),h.addAssign(Rn(i)),HT(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),KT=Pm([yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(qT(r,s)).toVar(),i=Pn().toVar();return i.x.assign(n.bitAnd(An(255))),i.y.assign(n.shiftRight(An(8)).bitAnd(An(255))),i.z.assign(n.shiftRight(An(16)).bitAnd(An(255))),i})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(qT(i,n,r)).toVar(),a=Pn().toVar();return a.x.assign(o.bitAnd(An(255))),a.y.assign(o.shiftRight(An(8)).bitAnd(An(255))),a.z.assign(o.shiftRight(An(16)).bitAnd(An(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),XT=Pm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(wT(t.x,s)).toVar(),i=Sn(wT(t.y,r)).toVar(),o=Sn(jT(n)).toVar(),a=Sn(jT(i)).toVar(),u=Sn(MT(PT(qT(s,r),n,i),PT(qT(s.add(An(1)),r),n.sub(1),i),PT(qT(s,r.add(An(1))),n,i.sub(1)),PT(qT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return GT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(wT(t.x,s)).toVar(),o=Sn(wT(t.y,r)).toVar(),a=Sn(wT(t.z,n)).toVar(),u=Sn(jT(i)).toVar(),l=Sn(jT(o)).toVar(),d=Sn(jT(a)).toVar(),c=Sn(BT(PT(qT(s,r,n),i,o,a),PT(qT(s.add(An(1)),r,n),i.sub(1),o,a),PT(qT(s,r.add(An(1)),n),i,o.sub(1),a),PT(qT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),PT(qT(s,r,n.add(An(1))),i,o,a.sub(1)),PT(qT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),PT(qT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),PT(qT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return kT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),YT=Pm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(wT(t.x,s)).toVar(),i=Sn(wT(t.y,r)).toVar(),o=Sn(jT(n)).toVar(),a=Sn(jT(i)).toVar(),u=Un(MT(DT(KT(s,r),n,i),DT(KT(s.add(An(1)),r),n.sub(1),i),DT(KT(s,r.add(An(1))),n,i.sub(1)),DT(KT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return GT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(wT(t.x,s)).toVar(),o=Sn(wT(t.y,r)).toVar(),a=Sn(wT(t.z,n)).toVar(),u=Sn(jT(i)).toVar(),l=Sn(jT(o)).toVar(),d=Sn(jT(a)).toVar(),c=Un(BT(DT(KT(s,r,n),i,o,a),DT(KT(s.add(An(1)),r,n),i.sub(1),o,a),DT(KT(s,r.add(An(1)),n),i,o.sub(1),a),DT(KT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),DT(KT(s,r,n.add(An(1))),i,o,a.sub(1)),DT(KT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),DT(KT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),DT(KT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return kT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),QT=Pm([yn((([e])=>{const t=Sn(e).toVar(),s=An(ET(t)).toVar();return WT(qT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar();return WT(qT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar();return WT(qT(s,r,n))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar(),i=An(ET(t.w)).toVar();return WT(qT(s,r,n,i))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),ZT=Pm([yn((([e])=>{const t=Sn(e).toVar(),s=An(ET(t)).toVar();return Un(WT(qT(s,An(0))),WT(qT(s,An(1))),WT(qT(s,An(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar();return Un(WT(qT(s,r,An(0))),WT(qT(s,r,An(1))),WT(qT(s,r,An(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar();return Un(WT(qT(s,r,n,An(0))),WT(qT(s,r,n,An(1))),WT(qT(s,r,n,An(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar(),i=An(ET(t.w)).toVar();return Un(WT(qT(s,r,n,i,An(0))),WT(qT(s,r,n,i,An(1))),WT(qT(s,r,n,i,An(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),JT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Sn(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(XT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),e_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(YT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),t_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar();return En(JT(a,o,i,n),JT(a.add(Un(An(19),An(193),An(17))),o,i,n))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),s_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(e_(a,o,i,n)).toVar(),l=Sn(JT(a.add(Un(An(19),An(193),An(17))),o,i,n)).toVar();return Ln(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),r_=Pm([yn((([e,t,s,r,n,i,o])=>{const a=An(o).toVar(),u=Sn(i).toVar(),l=An(n).toVar(),d=An(r).toVar(),c=An(s).toVar(),h=An(t).toVar(),p=En(e).toVar(),g=Un(ZT(En(h.add(d),c.add(l)))).toVar(),m=En(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=En(En(Sn(h),Sn(c)).add(m)).toVar(),y=En(f.sub(p)).toVar();return _n(a.equal(An(2)),(()=>Fo(y.x).add(Fo(y.y)))),_n(a.equal(An(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),yn((([e,t,s,r,n,i,o,a,u])=>{const l=An(u).toVar(),d=Sn(a).toVar(),c=An(o).toVar(),h=An(i).toVar(),p=An(n).toVar(),g=An(r).toVar(),m=An(s).toVar(),f=An(t).toVar(),y=Un(e).toVar(),b=Un(ZT(Un(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Un(Un(Sn(f),Sn(m),Sn(g)).add(b)).toVar(),T=Un(x.sub(y)).toVar();return _n(l.equal(An(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),_n(l.equal(An(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),n_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();l.assign(qo(l,s))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),o_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),a_=Pm([n_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();d.assign(qo(d,i))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=Pm([i_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.y.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),l_=Pm([o_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(i)})).ElseIf(i.lessThan(d.z),(()=>{d.z.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),d_=yn((([e])=>{const t=e.y,s=e.z,r=Un().toVar();return _n(t.lessThan(1e-4),(()=>{r.assign(Un(s,s,s))})).Else((()=>{let n=e.x;n=n.sub(vo(n)).mul(6).toVar();const i=An(zo(n)),o=n.sub(Sn(i)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());_n(i.equal(An(0)),(()=>{r.assign(Un(s,l,a))})).ElseIf(i.equal(An(1)),(()=>{r.assign(Un(u,s,a))})).ElseIf(i.equal(An(2)),(()=>{r.assign(Un(a,s,l))})).ElseIf(i.equal(An(3)),(()=>{r.assign(Un(a,u,s))})).ElseIf(i.equal(An(4)),(()=>{r.assign(Un(l,a,s))})).Else((()=>{r.assign(Un(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),c_=yn((([e])=>{const t=Un(e).toVar(),s=Sn(t.x).toVar(),r=Sn(t.y).toVar(),n=Sn(t.z).toVar(),i=Sn(qo(s,qo(r,n))).toVar(),o=Sn(Ko(s,Ko(r,n))).toVar(),a=Sn(o.sub(i)).toVar(),u=Sn().toVar(),l=Sn().toVar(),d=Sn().toVar();return d.assign(o),_n(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),_n(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{_n(s.greaterThanEqual(o),(()=>{u.assign(r.sub(n).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vi(2,n.sub(s).div(a)))})).Else((()=>{u.assign(Vi(4,s.sub(r).div(a)))})),u.mulAssign(1/6),_n(u.lessThan(0),(()=>{u.addAssign(1)}))})),Un(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),h_=yn((([e])=>{const t=Un(e).toVar(),s=In(ji(t,Un(.04045))).toVar(),r=Un(t.div(12.92)).toVar(),n=Un(sa(Ko(t.add(Un(.055)),Un(0)).div(1.055),Un(2.4))).toVar();return la(r,n,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),p_=(e,t)=>{e=Sn(e),t=Sn(t);const s=En(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},g_=(e,t,s,r)=>la(e,t,s[r].clamp()),m_=(e,t,s=mu())=>g_(e,t,s,"x"),f_=(e,t,s=mu())=>g_(e,t,s,"y"),y_=(e,t,s,r,n)=>la(e,t,p_(s,r[n])),b_=(e,t,s,r=mu())=>y_(e,t,s,r,"x"),x_=(e,t,s,r=mu())=>y_(e,t,s,r,"y"),T_=(e=1,t=0,s=mu())=>s.mul(e).add(t),__=(e,t=1)=>(e=Sn(e)).abs().pow(t).mul(e.sign()),N_=(e,t=1,s=.5)=>Sn(e).sub(s).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>XT(e.convert("vec2|vec3")).mul(t).add(s),S_=(e=mu(),t=1,s=0)=>YT(e.convert("vec2|vec3")).mul(t).add(s),A_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ln(YT(e),XT(e.add(En(19,73)))).mul(t).add(s)},R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,An(1)),C_=(e=mu(),t=1)=>u_(e.convert("vec2|vec3"),t,An(1)),E_=(e=mu(),t=1)=>l_(e.convert("vec2|vec3"),t,An(1)),w_=(e=mu())=>QT(e.convert("vec2|vec3")),M_=(e=mu(),t=3,s=2,r=.5,n=1)=>JT(e,An(t),s,r).mul(n),B_=(e=mu(),t=3,s=2,r=.5,n=1)=>t_(e,An(t),s,r).mul(n),U_=(e=mu(),t=3,s=2,r=.5,n=1)=>e_(e,An(t),s,r).mul(n),F_=(e=mu(),t=3,s=2,r=.5,n=1)=>s_(e,An(t),s,r).mul(n),P_=yn((([e,t,s])=>{const r=Ao(e).toVar("nDir"),n=Oi(Sn(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),i=Oi(Sn(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Un().toVar("rbminmax");o.x=r.x.greaterThan(Sn(0)).select(n.x,i.x),o.y=r.y.greaterThan(Sn(0)).select(n.y,i.y),o.z=r.z.greaterThan(Sn(0)).select(n.z,i.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),I_=yn((([e,t])=>{const s=e.x,r=e.y,n=e.z;let i=t.element(0).mul(.886227);return i=i.add(t.element(1).mul(1.023328).mul(r)),i=i.add(t.element(2).mul(1.023328).mul(n)),i=i.add(t.element(3).mul(1.023328).mul(s)),i=i.add(t.element(4).mul(.858086).mul(s).mul(r)),i=i.add(t.element(5).mul(.858086).mul(r).mul(n)),i=i.add(t.element(6).mul(n.mul(n).mul(.743125).sub(.247708))),i=i.add(t.element(7).mul(.858086).mul(s).mul(n)),i=i.add(t.element(8).mul(.429043).mul(Gi(s,s).sub(Gi(r,r)))),i})),L_=new hm;class D_ extends Dg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,n=this.nodes.getBackgroundNode(e)||e.background;let i=!1;if(null===n)r._clearColor.getRGB(L_,Se),L_.a=r._clearColor.a;else if(!0===n.isColor)n.getRGB(L_,Se),L_.a=1,i=!0;else if(!0===n.isNode){const s=this.get(e),i=n;L_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ln(i).mul(Df),{getUV:()=>Vf.mul(ll),getTextureLevel:()=>Lf});let t=Wd();t=t.setZ(t.w);const r=new nh;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=i.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ln(i).mul(Df),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",n);if(!0===r.autoClear||!0===i){const e=s.clearColorValue;e.r=L_.r,e.g=L_.g,e.b=L_.b,e.a=L_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let V_=0;class O_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=V_++}}class G_{constructor(e,t,s,r,n,i,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=n,this.updateNodes=i,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new O_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class k_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class z_{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class $_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class H_ extends $_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class W_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let j_=0;class q_{constructor(e=null){this.id=j_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class K_{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class X_ extends K_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class Y_ extends K_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class Q_ extends K_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends K_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class J_ extends K_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class eN extends K_{constructor(e,t=new n){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class tN extends K_{constructor(e,t=new i){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class aN extends eN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class uN extends tN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const lN=[.125,.215,.35,.446,.526,.582],dN=20,cN=new xe(-1,1,1,-1,0,1),hN=new Be(90,1),pN=new e;let gN=null,mN=0,fN=0;const yN=(1+Math.sqrt(5))/2,bN=1/yN,xN=[new s(-yN,bN,0),new s(yN,bN,0),new s(-bN,0,yN),new s(bN,0,yN),new s(0,yN,-bN),new s(0,yN,bN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],TN=[3,1,5,0,4,2],_N=Hp(mu(),gu("faceIndex")).normalize(),NN=Un(_N.x,_N.y.negate(),_N.z);class vN{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(e,t=0,s=.1,r=100){gN=this._renderer.getRenderTarget(),mN=this._renderer.getActiveCubeFace(),fN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const n=this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(e,s,r,n),t>0&&this._blur(n,0,0,t),this._applyPMREM(n),this._cleanup(n),n}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=CN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=EN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=lN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],n=TN[e];b.set(r,m*g*n),x.set(h,f*g*n);const i=[n,n,n,n,n,n];T.set(i,y*g*n)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),n.push(new k(_,null)),i>4&&i--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:n}}(n)),this._blurMaterial=function(e,t,r){const n=Rl(new Array(dN).fill(0)),i=ti(new s(0,1,0)),o=ti(0),a=Sn(dN),u=ti(0),l=ti(1),d=_u(null),c=ti(0),h=Sn(1/t),p=Sn(1/r),g=Sn(e),m={n:a,latitudinal:u,weights:n,poleAxis:i,outputDirection:NN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=RN("blur");return f.uniforms=m,f.fragmentNode=Kp({...m,latitudinal:u.equal(1)}),f}(n,e,t)}return n}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,cN)}_sceneToCubeUV(e,t,s,r){const n=hN;n.near=t,n.far=s;const i=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(pN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(pN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,n);for(let t=0;t<6;t++){const s=t%3;0===s?(n.up.set(0,i[t],0),n.lookAt(o[t],0,0)):1===s?(n.up.set(0,0,i[t]),n.lookAt(0,o[t],0)):(n.up.set(0,i[t],0),n.lookAt(0,0,o[t]));const u=this._cubeSize;AN(r,s*u,t>2?u:0,u,u),a.render(e,n)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=CN(e)):null===this._equirectMaterial&&(this._equirectMaterial=EN(e));const n=r?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=n;const o=this._cubeSize;AN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(i,cN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;tdN&&console.warn(`sigmaRadians, ${n}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,cN)}}function SN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function AN(e,t,s,r,n){e.viewport.set(t,s,r,n),e.scissor.set(t,s,r,n)}function RN(e){const t=new nh;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function CN(e){const t=RN("cubemap");return t.fragmentNode=_l(e,NN),t}function EN(e){const t=RN("equirect");return t.fragmentNode=_u(e,bh(NN),0),t}const wN=new WeakMap,MN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),BN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),UN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class FN{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=fm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new q_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=wN.get(this.renderer);return void 0===e&&(e=new Ug,wN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new xh(e,t)}createPMREMGenerator(){return new vN(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let n,i=!0;for(const e of t)r.push(e),i=i&&!0!==e.groupNode.shared;return i?(n=s.get(r),void 0===n&&(n=new O_(e,r,this.bindingsIndexes[e].group,r),s.set(r,n))):n=new O_(e,r,this.bindingsIndexes[e].group,r),n}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const n=s[e][r];(t[r]||(t[r]=[])).push(...n)}e=[];for(const s in t){const r=t[s],n=this._getBindGroup(s,r);e.push(n)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(i)}u`:"0u";if("bool"===n)return i?"true":"false";if("color"===n)return`${this.getType("vec3")}( ${UN(i.r)}, ${UN(i.g)}, ${UN(i.b)} )`;const o=this.getTypeLength(n),a=this.getComponentType(n),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)} )`;if(3===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)} )`;if(4===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)}, ${u(i.w)} )`;if(o>4&&i&&(i.isMatrix3||i.isMatrix4))return`${this.getType(n)}( ${i.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(n)}()`;throw new Error(`NodeBuilder: Type '${n}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new k_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=MN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return BN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,n=e.normalized;let i;return e instanceof Ie||!0===n||(i=this.getTypeFromArray(s)),this.getTypeFromLength(r,i)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=fm(this.stack),this.stacks.push(Tn()||this.stack),xn(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,xn(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(void 0===r){const n=this.uniforms.index++;r=new k_("nodeAttribute"+n,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const n=this.getDataFromNode(e,s,this.globalCache);let i=n.uniform;if(void 0===i){const o=this.uniforms.index++;i=new z_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(i),n.uniform=i}return i}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const n=this.getDataFromNode(e,r);let i=n.variable;if(void 0===i){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),i=new $_(t,s),e.push(i),n.variable=i}return i}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let n=r.varying;if(void 0===n){const e=this.varyings,i=e.length;null===t&&(t="nodeVarying"+i),n=new H_(t,s),e.push(n),r.varying=n}return n}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let n=r.code;if(void 0===n){const e=this.codes[s]||(this.codes[s]=[]),i=e.length;n=new W_("nodeCode"+i,t),e.push(n),r.code=n}return n}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let n=!0,i=t;for(;i;){if(!0===r.get(i)){n=!1;break}i=this.getDataFromNode(i).parentNodeBlock}if(n)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),n=r.flowCodes||(r.flowCodes=[]),i=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);n.push(t),i.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new lx,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new pm(e.type,e.name);e.layout=null;const r=e.call(s),n=this.flowStagesNode(r,t.type);return e.layout=t,n}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,n=this.cache,i=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new q_,this.stack=fm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=n,this.stack=o,this.setBuildStage(i),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const n=this.shaderStage;this.setShaderStage(e);const i=this.flowChildNode(t,s);return null!==r&&(i.code+=`${this.tab+r} = ${i.result};\n`),this.flowCode[e]=this.flowCode[e]+i.code,this.setShaderStage(n),i}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new nh),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new sN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new rN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new nN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new iN(e);if("color"===t)return new oN(e);if("mat3"===t)return new aN(e);if("mat4"===t)return new uN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),n=this.getTypeLength(s);return 16===r&&9===n?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===n?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||n>4||0===n?e:r===n?`${this.getType(s)}( ${e} )`:r>n?this.format(`${e}.${"xyz".slice(0,n)}`,this.getTypeFromLength(n,this.getComponentType(t)),s):4===n&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&n>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class PN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class IN{constructor(e,t,s=null,r="",n=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=n}}IN.isNodeFunctionInput=!0;class LN extends _T{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=iT(this.light),n=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:n},e.stack,e)}}const DN=new i,VN=new i;let ON=null;class GN extends _T{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=ti(new s).setGroup(Zn),this.halfWidth=ti(new s).setGroup(Zn),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;VN.identity(),DN.copy(t.matrixWorld),DN.premultiply(s),VN.extractRotation(DN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(VN),this.halfHeight.value.applyMatrix4(VN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(ON.LTC_FLOAT_1),s=_u(ON.LTC_FLOAT_2)):(t=_u(ON.LTC_HALF_1),s=_u(ON.LTC_HALF_2));const{colorNode:r,light:n}=this,i=e.context.lightingModel,o=nT(n),a=e.context.reflectedLight;i.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){ON=e}}class kN extends _T{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=ti(0).setGroup(Zn),this.penumbraCosNode=ti(0).setGroup(Zn),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:n,light:i}=this,o=nT(i).sub(el),a=o.normalize(),u=a.dot(iT(i)),l=this.getSpotAttenuation(u),d=o.length(),c=NT({lightDistance:d,cutoffDistance:r,decayExponent:n}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class zN extends kN{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,En(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class $N extends _T{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class HN extends _T{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=sT(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=ti(new e).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:r}=this,n=ul.dot(r).mul(.5).add(.5),i=la(s,t,n);e.context.irradiance.addAssign(i)}}class WN extends _T{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=I_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class jN{parseFunction(){console.warn("Abstract function.")}}class qN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}qN.isNodeFunction=!0;const KN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,XN=/[a-z_0-9]+/gi,YN="#pragma main";class QN extends qN{constructor(e){const{type:t,inputs:s,name:r,precision:n,inputsCode:i,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(YN),s=-1!==t?e.slice(t+12):e,r=s.match(KN);if(null!==r&&5===r.length){const n=r[4],i=[];let o=null;for(;null!==(o=XN.exec(n));)i.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Jp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=Sh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Zn),r=Ml("density","float",s).setGroup(Zn);e=Ax(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Zn),r=Ml("near","float",s).setGroup(Zn),n=Ml("far","float",s).setGroup(Zn);e=vx(t,r,n)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,n=null){const i=this.nodeFrame;return i.renderer=e,i.scene=t,i.object=s,i.camera=r,i.material=n,i}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return JN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return JN.set(e,s),r}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new PN,this.nodeBuilderCache=new Map}}const tv=new me;class sv{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new n,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let n=0;n{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),n=this._renderContexts.get(e,t,this._renderTarget),i=e.overrideMaterial||s.material,o=this._objects.get(s,i,e,t,r.lightsNode,n,n.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ev(this,s),this._animation=new Bg(this._nodes,this.info),this._attributes=new $g(s),this._background=new D_(this,this._nodes),this._geometries=new jg(this._attributes,this.info),this._textures=new cm(this,s,this.info),this._pipelines=new Jg(s,this._nodes),this._bindings=new em(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Lg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new im(this.lighting),this._bundles=new nv,this._renderContexts=new lm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,n=r.renderId,i=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:uv;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new sv),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=n,this._currentRenderContext=i,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:n,renderList:i}=e,o=this._currentRenderContext,a=this._bundles.get(r,n),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=i.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,n,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(dv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(dv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new sv),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),hv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),cv.setFromProjectionMatrix(hv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),n.renderId=i,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,r){const n=this._scissor;e.isVector4?n.copy(e):n.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,n=0,i=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=n,o.maxDepth=i}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let n=null;if(null!==r&&(this._textures.updateRenderTarget(r),n=this._textures.get(r)),this.backend.clear(e,t,s,n),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const r=this.backend,n=this._pipelines,i=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===n.has(t)){const e=()=>{t.removeEventListener("dispose",e),n.delete(t),i.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),i.updateForCompute(t);const s=i.getForCompute(t),a=n.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=pv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=pv.copy(t).floor()}else t=pv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,n)}readRenderTargetPixelsAsync(e,t,s,r,n,i=0,o=0){return this.backend.copyTextureToBuffer(e.textures[i],t,s,r,n,o)}_projectObject(e,t,s,r,n){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(n=n.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||cv.intersectsSprite(e)){!0===this.sortObjects&&pv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(hv);const{geometry:t,material:i}=e;i.visible&&r.push(e,t,i,s,pv.z,null,n)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||cv.intersectsObject(e))){const{geometry:t,material:i}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),pv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(hv)),Array.isArray(i)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,n,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,n);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,n)}_renderObjects(e,t,s,r,n=null){for(let i=0,o=e.length;i0?r:"";t=`${e.name} {\n\t${s} ${n.name}[${i}];\n};\n`}else{t=`${this.getVectorType(n.type)} ${this.getPropertyName(n,e)};`,i=!0}const o=n.node.precision;if(null!==o&&(t=wv[o]+" "+t),i){t="\t"+t;const e=n.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let n="";for(const t in r){const s=r[t];n+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return n+=s.join("\n"),n}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Mv[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Mv[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${i}\n\t`),s+=`${r.code}\n\t`,e===n&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const i=e[t];i.extensions=this.getExtensions(t),i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.vars=this.getVars(t),i.structs=this.getStructs(t),i.codes=this.getCodes(t),i.transforms=this.getTransforms(t),i.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);let o=i.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new Av(n.name,n.node,r),u.push(o);else if("cubeTexture"===t)o=new Rv(n.name,n.node,r),u.push(o);else if("texture3D"===t)o=new Cv(n.name,n.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,n.name=`buffer${e.id}`;const t=new xv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Nv(s+"_"+a,r),e[a]=i,u.push(i)),o=this.getNodeUniform(n,t),i.addUniform(o)}i.uniformGPU=o}return n}}let Fv=null,Pv=null,Iv=null;class Lv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Fv=Fv||new t,this.renderer.getDrawingBufferSize(Fv)}getScissor(){return Pv=Pv||new r,this.renderer.getScissor(Pv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Iv=Iv||new hm,e.getClearColor(Iv),Iv.getRGB(Iv,this.renderer.currentColorSpace),Iv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Dv=0;class Vv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Ov{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,n=e.array,i=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,n,i),a.bufferGPU=l,a.bufferType=t,a.version=o.version),n instanceof Float32Array)u=r.FLOAT;else if(n instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(n instanceof Int16Array)u=r.SHORT;else if(n instanceof Uint32Array)u=r.UNSIGNED_INT;else if(n instanceof Int32Array)u=r.INT;else if(n instanceof Int8Array)u=r.BYTE;else if(n instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Dv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,n,i);d=new Vv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,n=e.isInterleavedBufferAttribute?e.data:e,i=t.get(n),o=i.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,i.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t{!function n(){const i=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(i===e.WAIT_FAILED)return e.deleteSync(t),void r();i!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(n)}()}))}}let Wv,jv,qv,Kv=!1;class Xv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===Kv&&(this._init(this.gl),Kv=!0)}_init(e){Wv={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},jv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},qv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,n=!1){const{gl:i,extensions:o}=this;if(null!==e){if(void 0!==i[e])return i[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===i.RED&&(s===i.FLOAT&&(a=i.R32F),s===i.HALF_FLOAT&&(a=i.R16F),s===i.UNSIGNED_BYTE&&(a=i.R8),s===i.UNSIGNED_SHORT&&(a=i.R16),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RED_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.R8UI),s===i.UNSIGNED_SHORT&&(a=i.R16UI),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RG&&(s===i.FLOAT&&(a=i.RG32F),s===i.HALF_FLOAT&&(a=i.RG16F),s===i.UNSIGNED_BYTE&&(a=i.RG8),s===i.UNSIGNED_SHORT&&(a=i.RG16),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RG_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RG8UI),s===i.UNSIGNED_SHORT&&(a=i.RG16UI),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RGB&&(s===i.FLOAT&&(a=i.RGB32F),s===i.HALF_FLOAT&&(a=i.RGB16F),s===i.UNSIGNED_BYTE&&(a=i.RGB8),s===i.UNSIGNED_SHORT&&(a=i.RGB16),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8:i.RGB8),s===i.UNSIGNED_SHORT_5_6_5&&(a=i.RGB565),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGB4),s===i.UNSIGNED_INT_5_9_9_9_REV&&(a=i.RGB9_E5)),t===i.RGB_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGB8UI),s===i.UNSIGNED_SHORT&&(a=i.RGB16UI),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I)),t===i.RGBA&&(s===i.FLOAT&&(a=i.RGBA32F),s===i.HALF_FLOAT&&(a=i.RGBA16F),s===i.UNSIGNED_BYTE&&(a=i.RGBA8),s===i.UNSIGNED_SHORT&&(a=i.RGBA16),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8_ALPHA8:i.RGBA8),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGBA4),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1)),t===i.RGBA_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGBA8UI),s===i.UNSIGNED_SHORT&&(a=i.RGBA16UI),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I)),t===i.DEPTH_COMPONENT&&(s===i.UNSIGNED_INT&&(a=i.DEPTH24_STENCIL8),s===i.FLOAT&&(a=i.DEPTH_COMPONENT32F)),t===i.DEPTH_STENCIL&&s===i.UNSIGNED_INT_24_8&&(a=i.DEPTH24_STENCIL8),a!==i.R16F&&a!==i.R32F&&a!==i.RG16F&&a!==i.RG32F&&a!==i.RGBA16F&&a!==i.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:n}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,Wv[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,Wv[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,Wv[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,jv[t.magFilter]);const i=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&i?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,jv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,qv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const i=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,n.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,n=this.getGLTextureType(e);let i=r[n];void 0===i&&(i=t.createTexture(),s.state.bindTexture(n,i),t.texParameteri(n,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(n,t.TEXTURE_MAG_FILTER,t.NEAREST),r[n]=i),s.set(e,{textureGPU:i,glTextureType:n,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:n,width:i,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,n,d,i,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,n,d,i,o,a):e.isVideoTexture||s.texStorage2D(h,n,d,i,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:n,glTextureType:i,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(i,n),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(i,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:n}=t,{textureGPU:i,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===i)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,i),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,n=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;n.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),n.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),n.bindFramebuffer(r.READ_FRAMEBUFFER,s),n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),n.unbindTexture()}else{const e=r.createFramebuffer();n.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,i,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),n.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:n,depthTexture:i,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;n>0?(i&&i.isDepthTexture&&i.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,n,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(n>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,n,i){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+i:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*n*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,n,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let r=0;return e===s.UNSIGNED_BYTE&&(r=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Yv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Qv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const Zv={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class Jv{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:r,object:n,type:i,info:o,index:a}=this;0!==a?s.drawElements(r,t,i,e):s.drawArrays(r,e,t),o.update(n,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:n,type:i,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(n,t,i,e,s):r.drawArraysInstanced(n,e,t,s),u.update(a,t,n,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:n,object:i,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),n=r.previousContext,i=e.occlusionQueryCount;i>0&&(i>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const n=r.framebuffers[e.getCacheKey()],i=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,n);for(let s=0;s{let o=0;for(let t=0;t0&&e.add(r[t]),s[t]=null,n.deleteQuery(i),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Uv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,n="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(n,r),t.compileShader(n),this.set(e,{shaderGPU:n})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:n,vertexProgram:i}=r,o=s.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const n=new Promise((t=>{const n=this.parallel,i=()=>{s.getProgramParameter(o,n.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(i)};i()}));t.push(n)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],n=Math.max(t-6,0),i=Math.min(t+6,s.length);for(let e=n;e":" "} ${n}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),n=e.getShaderInfoLog(t).trim();if(r&&""===n)return"";const i=/ERROR: 0:(\d+)/.exec(n);if(i){const r=parseInt(i[1]);return s.toUpperCase()+"\n\n"+n+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return n}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,n=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const i=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+n+"\n"+i+"\n"+o)}else""!==n&&console.warn("THREE.WebGLProgram: Program Info Log:",n)}}_completeCompile(e,t){const{state:s,gl:r}=this,n=this.get(t),{programGPU:i,fragmentShader:o,vertexShader:a}=n;!1===r.getProgramParameter(i,r.LINK_STATUS)&&this._logProgramError(i,o,a),s.useProgram(i);const u=e.getBindings();this._setupBindings(u,i),this.set(t,{programGPU:i})}createComputePipeline(e,t){const{state:s,gl:r}=this,n={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(n);const{computeProgram:i}=e,o=r.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU,l=i.transforms,d=[],c=[];for(let e=0;eZv[t]===e)),s=this.extensions;for(let e=0;e0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const n=[],l=e.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Wf,stripIndexFormat:uy},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Wf,stripIndexFormat:uy},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:n,height:i}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:n,height:i,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),n=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),i=c.beginRenderPass({colorAttachments:[{view:s,loadOp:sy,storeOp:ey,clearValue:[0,0,0,0]}]});i.setPipeline(e),i.setBindGroup(0,n),i.draw(4,1,0,0),i.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const n=r.layers[s]||this._mipmapCreateBundles(e,t,s),i=this.device.createCommandEncoder({});this._mipmapRunBundles(i,n),this.device.queue.submit([i.finish()]),0!==r.useCount&&(r.layers[s]=n),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),n=r.getBindGroupLayout(0);let i=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:s});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,hS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,pS={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class gS extends qN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:n,blockCode:i,outputType:o}=(e=>{const t=(e=e.trim()).match(cS);if(null!==t&&4===t.length){const s=t[2],r=[];let n=null;for(;null!==(n=hS.exec(s));)r.push({name:n[1],type:n[2]});const i=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class mS extends jN{parseFunction(e){return new gS(e)}}const fS=self.GPUShaderStage,yS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},bS={vertex:fS?fS.VERTEX:1,fragment:fS?fS.FRAGMENT:2,compute:fS?fS.COMPUTE:4},xS={instance:!0,swizzleAssign:!1,storageBuffer:!0},TS={"^^":"tsl_xor"},_S={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},NS={},vS={tsl_xor:new nx("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new nx("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new nx("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new nx("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new nx("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new nx("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new nx("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new nx("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new nx("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new nx("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new nx("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new nx("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new nx("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new nx("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},SS={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(vS.pow_float=new nx("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),vS.pow_vec2=new nx("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[vS.pow_float]),vS.pow_vec3=new nx("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[vS.pow_float]),vS.pow_vec4=new nx("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[vS.pow_float]),SS.pow_float="tsl_pow_float",SS.pow_vec2="tsl_pow_vec2",SS.pow_vec3="tsl_pow_vec3",SS.pow_vec4="tsl_pow_vec4");let AS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(AS+="diagnostic( off, derivative_uniformity );\n");class RS extends FN{constructor(e,t){super(e,t,new mS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,n=this.shaderStage){return"fragment"===n?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,r,n,i=this.shaderStage){return"fragment"===i&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${yS[e.wrapS]}S_${yS[e.wrapT]}T`;let s=NS[t];if(void 0===s){const r=[];let n=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const i=(e,t)=>{e===ls?(r.push(vS.repeatWrapping_float),n+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(r.push(vS.clampWrapping_float),n+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(r.push(vS.mirrorWrapping_float),n+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(n+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};i(e.wrapS,"x"),n+=",\n",i(e.wrapT,"y"),n+="\n\t);\n\n}\n",NS[t]=s=new nx(n,r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let n=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(n=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${n} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=n),n}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,n="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${n} )`:`textureLoad( ${t}, ${s}, ${n} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,n=this.shaderStage){let i=null;return i=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,n):this._generateTextureSample(e,t,s,r,n),i}generateTextureGrad(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${i} shader.`)}generateTextureCompare(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${i} shader.`)}generateTextureLevel(e,t,s,r,n,i=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this._generateTextureSampleLevel(e,t,s,r,n,i),o}generateTextureBias(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${i} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=TS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case jy:return"read";case Wy:return"write";default:return"read_write"}else switch(e.access){case $y:return"read_write";case Hy:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);if(void 0===i.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let i=null;if("texture"===t||"storageTexture"===t?i=new Av(n.name,n.node,o,e.access?e.access:null):"cubeTexture"===t?i=new Rv(n.name,n.node,o,e.access?e.access:null):"texture3D"===t&&(i=new Cv(n.name,n.node,o,e.access?e.access:null)),i.store=!0===e.isStorageTextureNode,i.setVisibility(bS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===i.store){const e=new sS(`${n.name}_sampler`,n.node,o);e.setVisibility(bS[s]),u.push(e,i),r=[e,i]}else u.push(i),r=[i]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const n=new("buffer"===t?xv:iS)(e,o);n.setVisibility(bS[s]),u.push(n),r=n}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Nv(a,o),i.setVisibility(bS[s]),e[a]=i,u.push(i)),r=this.getNodeUniform(n,t),i.addUniform(r)}i.uniformGPU=r}return n}getBuiltin(e,t,s,r=this.shaderStage){const n=this.builtins[r]||(this.builtins[r]=new Map);return!1===n.has(e)&&n.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let n=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(n+=`\treturn ${s.result};\n`),n+="\n}\n",n}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:n}of s.values())t.push(`@builtin( ${e} ) ${r} : ${n}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:n}of this.scopedArrays.values()){const i=this.getType(r);t.push(`var<${s}> ${e}: array< ${i}, ${n} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e{const{name:t,node:r}=e,n=!0===r.bufferStruct;s.set(t,n)})),s}getMembersFromCustomStruct(e){return`\t${e.map((({name:e,type:t,isAtomic:s})=>{let r=_S[t];return r||(console.warn(`Unrecognized type: ${t}`),r="vec4"),`${e}: ${s?`atomic<${r}>`:r}`})).join(",\n\t")}`}getCustomStructNameFromShader(e){const t=/fn\s+\w+\s*\(([\s\S]*?)\)/g,s=/(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g,r=[];let n;for(;null!==(n=t.exec(e));){const e=n[1];let t;for(;null!==(t=s.exec(e));){const[e,s,n,i,o,a]=t,u=o||a||null,l=i||n;Object.values(_S).includes(u)||null===u||r.push({name:s,type:l,structName:u})}}return r}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;e`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e output : ${n};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let n=0;n";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array";else if(!0===t.isDepthTexture)r=`texture_depth${i}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d";else if(!0===n.node.isStorageTextureNode){r=`texture_storage_2d<${dS(t)}, ${this.getStorageAccess(n.node)}>`}else{r=`texture${i}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name} : ${r};`)}else if("buffer"===n.type||"storageBuffer"===n.type||"indirectStorageBuffer"===n.type){const e=n.node,t=this.getType(e.bufferType),s=e.bufferCount,i=e.value.array.length!==e.value.itemSize,a=s>0&&"buffer"===n.type?", "+s:"",u=e.isAtomic?`atomic<${t}>`:`${t}`,l=e.bufferStruct?this.getMembersFromCustomStruct(t):`\t${n.name} : array< ${u}${a} >\n`,d=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding(e.bufferStruct,i,"NodeBuffer_"+e.id,l,d,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(n.type)),t=n.groupNode.name;(i[t]||(i[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${n.name} : ${e}`)}}for(const e in i){const t=i[e];n.push(this._getWGSLStructBinding(!1,!1,e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=n.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t),s.isBufferStruct=this.getTypeFromCustomStruct(t),s.customStructNames=this.getCustomStructNameFromShader(s.codes);const r=e=>e.replace(/&(\w+)\.(\w+)/g,((e,t,r)=>!0===s.isBufferStruct.get(r)?`&${t}`:e)),n=e=>{const t=e.match(/\(([^)]+)\)/);if(!t)return[];return t[1].split(/\s*,\s*/).map((e=>e.trim())).filter((e=>e.includes("&"))).map((e=>e.replace("&",""))).filter((e=>!e.includes(".")))},i=(e,t)=>{const s=new Map;for(let r=0;r{for(const[s,r]of t.entries()){const t=new RegExp(`\\b${s}Struct\\b`,"g");e=e.replace(t,r)}return e};let a,u,l="// code\n\n";l+=this.flowCode[t];const d=this.flowNodes[t],c=d[d.length-1],h=c.outputNode,p=void 0!==h&&!0===h.isOutputStructNode;for(const e of d){const d=this.getFlowData(e),g=e.name;if(g&&(l.length>0&&(l+="\n"),l+=`\t// flow -> ${g}\n\t`),l+=`${d.code}\n\t`,l=r(l),a=n(l),u=i(a,s.customStructNames),s.uniforms=o(s.uniforms,u),e===c&&"compute"!==t){if(l+="// result\n\n\t","vertex"===t)l+=`varyings.Vertex = ${d.result};`;else if("fragment"===t)if(p)s.returnType=h.nodeType,l+=`return ${d.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar output : OutputStruct;\n\n",l+=`output.color = ${d.result};\n\n\treturn output;`}l=r(l),a=n(l),u=i(a,s.customStructNames),s.uniforms=o(s.uniforms,u)}}s.flow=l}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return _S[e]||e}isAvailable(e){let t=xS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),xS[e]=t),t}_getWGSLMethod(e){return void 0!==vS[e]&&this._include(e),SS[e]}_include(e){const t=vS[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${AS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r,n,i=0,o=0){const a=s+"Struct",u=this._getWGSLStruct(a,r);if(e){return`${u}\n@binding( ${i} ) @group( ${o} )\nvar<${n}> ${s} : ${t?`array<${a}>`:a};`}return`${u}\n@binding( ${i} ) @group( ${o} )\nvar<${n}> ${s} : ${a};`}}class CS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=ly.Depth24PlusStencil8:e.depth&&(t=ly.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?kf:e.isLineSegments||e.isMesh&&!0===t.wireframe?zf:e.isLine?$f:e.isMesh?Hf:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?ly.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const ES=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),wS=new Map([[Ie,["float16"]]]),MS=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class BS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,n=r.get(s);let i=n.buffer;if(void 0===i){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[s]===r&&(a=o.groups[s])),void 0===a&&(a=this.createBindGroup(e,u),s>0&&(o.groups[s]=a,o.versions[s]=r)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,n=t.get(e).buffer;s.queue.writeBuffer(n,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let n=0;const i=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,n=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,i=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:n});e.buffer=i}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);i.push({binding:n,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const n=nb;let i;i=t.isSampledCubeTexture?sb:t.isSampledTexture3D?rb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?tb:eb,o=e[r]=e.texture.createView({aspect:n,dimension:i,mipLevelCount:s})}}i.push({binding:n,resource:o})}n++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:i})}}class FS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:n,pipeline:i}=e,{vertexProgram:o,fragmentProgram:a}=i,u=this.backend,l=u.device,d=u.utils,c=u.get(i),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,n=s.getCurrentDepthStencilFormat(e),i={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:n,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(i)}createComputePipeline(e,t){const s=this.backend,r=s.device,n=s.get(e.computeProgram).module,i=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}i.pipeline=r.createComputePipeline({compute:n,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,n=e.blendSrc,i=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:n,a=null!==e.blendDstAlpha?e.blendDstAlpha:i,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(n),dstFactor:this._getBlendFactor(i),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const n=(e,r,n,i)=>{t={srcFactor:e,dstFactor:r,operation:Ey},s={srcFactor:n,dstFactor:i,operation:Ey}};if(e.premultipliedAlpha)switch(r){case F:n(fy,Ty,fy,Ty);break;case bt:n(fy,fy,fy,fy);break;case yt:n(my,by,my,fy);break;case ft:n(my,yy,my,xy)}else switch(r){case F:n(xy,Ty,fy,Ty);break;case bt:n(xy,fy,xy,fy);break;case yt:n(my,by,my,fy);break;case ft:n(my,yy,my,yy)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=my;break;case st:t=fy;break;case rt:t=yy;break;case ut:t=by;break;case nt:t=xy;break;case lt:t=Ty;break;case ot:t=_y;break;case dt:t=Ny;break;case at:t=vy;break;case ct:t=Sy;break;case it:t=Ay;break;case 211:t=Ry;break;case 212:t=Cy;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=jf;break;case Es:t=Jf;break;case Cs:t=qf;break;case Rs:t=Xf;break;case As:t=Kf;break;case Ss:t=Zf;break;case vs:t=Yf;break;case Ns:t=Qf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Iy;break;case Ls:t=Ly;break;case Is:t=Dy;break;case Ps:t=Vy;break;case Fs:t=Oy;break;case Us:t=Gy;break;case Bs:t=ky;break;case Ms:t=zy;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Ey;break;case Je:t=wy;break;case et:t=My;break;case Os:t=By;break;case Vs:t=Uy;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},n=this.backend.utils;switch(r.topology=n.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?ay:uy),s.side){case Oe:r.frontFace=ry,r.cullMode=oy;break;case x:r.frontFace=ry,r.cullMode=iy;break;case le:r.frontFace=ry,r.cullMode=ny;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Py:Fy}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Jf;else{const s=e.depthFunc;switch(s){case Rt:t=jf;break;case At:t=Jf;break;case St:t=qf;break;case vt:t=Xf;break;case Nt:t=Kf;break;case _t:t=Zf;break;case Tt:t=Yf;break;case xt:t=Qf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class PS extends Lv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new CS(this),this.attributeUtils=new BS(this),this.bindingUtils=new US(this),this.pipelineUtils=new FS(this),this.textureUtils=new lS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const n=Object.values(ab),i=[];for(const e of n)r.features.has(e)&&i.push(e);const o={requiredFeatures:i,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const n=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ab.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:n}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const n=e.getCacheKey();let i=r[n];if(void 0===i){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,n=s.createQuerySet({type:"occlusion",count:r,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=n,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),i=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,i),i.occlusionQuerySet=n;const o=i.depthStencilAttachment;if(null!==e.textures){const t=i.colorAttachments;for(let s=0;s0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const r=8*s;let n=this.occludedResolveCache.get(r);void 0===n&&(n=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,n));const i=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,n,0),t.encoder.copyBufferToBuffer(n,0,i,0,r),t.occlusionQueryBuffer=i,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,n.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:r,pipeline:n}=e,i=e.getBindings(),o=this.get(r),a=this.get(n).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=i.length;e1?0:s;l.drawIndexed(t[s],r,e[s]/i,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,n,i,0,0);t.update(s,r,n)}else{const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,n,i,0);t.update(s,r,n)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,n=this.utils,i=n.getSampleCountRenderContext(e.context),o=n.getCurrentColorSpace(e.context),a=n.getCurrentColorFormat(e.context),u=n.getCurrentDepthStencilFormat(e.context),l=n.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===i&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=i,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,n=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,r.getSampleCountRenderContext(n),r.getCurrentColorSpace(n),r.getCurrentColorFormat(n),r.getCurrentDepthStencilFormat(n),r.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}async initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){this.device.pushErrorScope("out-of-memory");const r=await this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_renderContext_${e.id}`});if(await this.device.popErrorScope())return s.attemptingTimeStampQuerySetFailed||(console.error(`[GPUOutOfMemoryError][renderContext_${e.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.`),s.attemptingTimeStampQuerySetFailed=!0),void(s.timeStampQuerySet=null);const n={querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:n}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;const r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:n,resultBuffer:i,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,n,0),t.copyBufferToBuffer(n,0,i,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:n}=s.currentTimestampQueryBuffers;!0!==n&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),n=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,n),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new RS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,r=null,n=0){let i=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(i=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:n,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:n,origin:{x:i,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let n=null;n=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const i=this.get(e).texture;if(n.format!==i.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,i.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:n,origin:{x:s.x,y:s.y,z:0}},{texture:i},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new eS(e)));super(new t(e),e),this.library=new LS,this.isWebGPURenderer=!0}}class VS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const OS=new nh,GS=new _f(OS);class kS{constructor(e,t=Ln(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,OS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,GS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;GS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),GS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await GS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function zS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function $S(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function HS(e,t,s={}){return(s=zS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var WS=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=HS(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=zS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){$S(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:$S,saveRendererAndSceneState:HS,saveRendererState:zS});class jS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class qS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class KS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class XS extends qS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class YS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const n=new tr(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),Sn()):hn(new this.nodes[e])}}class QS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const n=r[e];t[e]=s[n]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class ZS extends rr{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new YS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),n=new QS;n.setTextures(t),n.setNodes(r),n.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t { @@ -1003,6 +1003,49 @@ ${ flowData.code } } + getCustomStructNameFromShader( source ) { + + const functionRegex = /fn\s+\w+\s*\(([\s\S]*?)\)/g; // filter shader header + const parameterRegex = /(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g; // filter parameters + + const results = []; + + let match; + + while ( ( match = functionRegex.exec( source ) ) !== null ) { + + const parameterString = match[ 1 ]; + + let paramMatch; + + while ( ( paramMatch = parameterRegex.exec( parameterString ) ) !== null ) { + + const [ fullMatch, name, fullType, ptrType, arrayType, directStructName ] = paramMatch; + + const structName = arrayType || directStructName || null; + + const type = ptrType || fullType; + + if (Object.values(wgslTypeLib).includes(structName) || structName === null) { + + continue; + + } + + results.push( { + name, + type, + structName + } ); + + } + + } + + return results; + + } + getStructMembers( struct ) { const snippets = []; @@ -1210,14 +1253,14 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; - const structName = uniform.value.name; + const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; - const bufferSnippet = bufferNode.bufferStruct ? this.getBufferStructMembers( bufferType ) : `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; + const bufferSnippet = bufferNode.bufferStruct ? this.getMembersFromCustomStruct( bufferType ) : `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform'; - bufferSnippets.push( this._getWGSLStructBinding( bufferNode.bufferStruct, isArray, 'NodeBuffer_' + bufferNode.id, structName, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); + bufferSnippets.push( this._getWGSLStructBinding( bufferNode.bufferStruct, isArray, 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); } else { @@ -1240,7 +1283,7 @@ ${ flowData.code } const group = uniformGroups[ name ]; - structSnippets.push( this._getWGSLStructBinding( false, false, name, undefined, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); + structSnippets.push( this._getWGSLStructBinding( false, false, name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); } @@ -1269,7 +1312,8 @@ ${ flowData.code } stageData.codes = this.getCodes( shaderStage ); stageData.directives = this.getDirectives( shaderStage ); stageData.scopedArrays = this.getScopedArrays( shaderStage ); - stageData.bufferStruct = this.getStructType( shaderStage ); + stageData.isBufferStruct = this.getTypeFromCustomStruct( shaderStage ); + stageData.customStructNames = this.getCustomStructNameFromShader( stageData.codes ); // @@ -1277,12 +1321,60 @@ ${ flowData.code } return flow.replace( /&(\w+)\.(\w+)/g, ( match, bufferName, uniformName ) => - stageData.bufferStruct.get( uniformName ) === true ? `&${bufferName}` : match + stageData.isBufferStruct.get( uniformName ) === true ? `&${bufferName}` : match ); }; + const extractPointerNames = ( source ) => { + + const match = source.match( /\(([^)]+)\)/ ); + if ( ! match ) return []; + + const content = match[ 1 ]; + + return content + .split( /\s*,\s*/ ) + .map( part => part.trim() ) + .filter( part => part.includes( '&' ) ) + .map( part => part.replace( '&', '' ) ) + .filter( part => ! part.includes( '.' ) ); + + }; + + const createStructNameMapping = ( nodeBuffers, structs ) => { + + const resultMap = new Map(); + + for (let i = 0; i < nodeBuffers.length; i++) { + + const bufferName = nodeBuffers[i]; + const struct = structs[i]; + + resultMap.set(bufferName, struct.structName); + + } + + return resultMap; + + }; + + const replaceStructNamesInUniforms = ( shaderCode, map ) => { + + for ( const [ key, value ] of map.entries() ) { + + const regex = new RegExp( `\\b${key}Struct\\b`, 'g' ); + shaderCode = shaderCode.replace( regex, value ); + + } + + return shaderCode; + + }; + + + let pointerNames, structnameMapping; let flow = '// code\n\n'; flow += this.flowCode[ shaderStage ]; @@ -1307,7 +1399,67 @@ ${ flowData.code } flow += `${ flowSlotData.code }\n\t`; + + /* + REVIEW COMMENT remove after review + + before reduceFlow: + compute( &NodeBuffer_554.nodeUniform0, &NodeBuffer_558.nodeUniform1, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); + + after reduceFlow: reduceFlow checks whether there is a storageStruct and if so then the + postfix is ​​removed so that the pointer points to the struct and not to a content in the struct + compute( &NodeBuffer_554, &NodeBuffer_558, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); + + extractPointerNames reads the names of the reduced pointers and stores them in an array + Array(2) + 0: "NodeBuffer_554" + 1: "NodeBuffer_558" + + getCustomStructNameFromShader at the beginning reads the structNames from the shader header + Array(2) + 0: {name: 'drawBuffer', type: 'storage', structName: 'DrawBuffer'} + 1: {name: 'meshletInfo', type: 'storage', structName: 'MeshletInfo'} + + + createStructNameMapping links the automatic generated WGSLNodeBuilder for each struct with the struct name specified by the user. + This is necessary because in wgslFn the user can choose any name in the shader in ptr for structs. + + Map(2) + [[Entries]] + 0: {"NodeBuffer_554" => "DrawBuffer"} + 1: {"NodeBuffer_558" => "MeshletInfo"} + + replaceStructNames then replaces the names in the uniforms in the custom structs that the WGSLNodeBuilder + created with the name chosen by the user. + + before replaceStructNames: + + struct NodeBuffer_554Struct { + vertexCount: u32, + instanceCount: u32, + firstVertex: u32, + firstInstance: u32 + }; + @binding( 0 ) @group( 0 ) + var NodeBuffer_554 : NodeBuffer_554Struct; + + after replaceStructNames: + + struct DrawBuffer { + vertexCount: u32, + instanceCount: u32, + firstVertex: u32, + firstInstance: u32 + }; + @binding( 0 ) @group( 0 ) + var NodeBuffer_554 : DrawBuffer; + */ + + flow = reduceFlow( flow ); + pointerNames = extractPointerNames(flow); + structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); + stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); if ( node === mainNode && shaderStage !== 'compute' ) { @@ -1344,6 +1496,9 @@ ${ flowData.code } } flow = reduceFlow( flow ); + pointerNames = extractPointerNames(flow); + structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); + stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); } @@ -1549,25 +1704,24 @@ ${vars} } - _getWGSLStructBinding( isBufferStruct, isArray, name, structName, vars, access, binding = 0, group = 0 ) { + _getWGSLStructBinding( isBufferStruct, isArray, name, vars, access, binding = 0, group = 0 ) { - if ( ! isBufferStruct ) { + const structName = name + 'Struct'; + const structSnippet = this._getWGSLStruct( structName, vars ); - const _structName = name + 'Struct'; - const structSnippet = this._getWGSLStruct( _structName, vars ); + if ( ! isBufferStruct ) { return `${structSnippet} @binding( ${binding} ) @group( ${group} ) -var<${access}> ${name} : ${_structName};`; +var<${access}> ${name} : ${structName};`; } else { - const structSnippet = this._getWGSLStruct( structName, vars ); - const structAccessor = isArray ? `array<${structName}>` : structName; + const StructName = isArray ? `array<${structName}>` : structName; return `${structSnippet} @binding( ${binding} ) @group( ${group} ) -var<${access}> ${name} : ${structAccessor};`; +var<${access}> ${name} : ${StructName};`; } From d76a0e6f58f9c55ed2768b7920b395dab428b574 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Tue, 19 Nov 2024 03:24:44 +0100 Subject: [PATCH 05/24] improved struct name managment --- build/three.webgpu.js | 261 +------------------------------- build/three.webgpu.min.js | 2 +- build/three.webgpu.nodes.js | 261 +------------------------------- build/three.webgpu.nodes.min.js | 2 +- 4 files changed, 14 insertions(+), 512 deletions(-) diff --git a/build/three.webgpu.js b/build/three.webgpu.js index 402dab5d779295..a1b0490a2a860b 100644 --- a/build/three.webgpu.js +++ b/build/three.webgpu.js @@ -16322,22 +16322,6 @@ class StructTypeNode extends Node { } -const struct = ( members ) => { - - return Object.entries( members ).map( ( [ name, value ] ) => { - - if ( typeof value === 'string' ) { - - return { name, type: value, isAtomic: false }; - - } - - return { name, type: value.type, isAtomic: value.atomic || false }; - - } ); - -}; - class OutputStructNode extends Node { static get type() { @@ -17990,7 +17974,6 @@ class StorageBufferNode extends BufferNode { this.isAtomic = false; this.bufferObject = false; - this.bufferStruct = false; this.bufferCount = bufferCount; this._attribute = null; @@ -18053,14 +18036,6 @@ class StorageBufferNode extends BufferNode { } - setBufferStruct( value ) { - - this.bufferStruct = value; - - return this; - - } - setAccess( value ) { this.access = value; @@ -18141,7 +18116,6 @@ class StorageBufferNode extends BufferNode { // Read-Write Storage const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) ); -const storageStruct = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferStruct( true ) ); const storageObject = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferObject( true ) ); class StorageTextureNode extends TextureNode { @@ -38063,88 +38037,6 @@ ${ flowData.code } } - getTypeFromCustomStruct( shaderStage ) { - - const uniforms = this.uniforms[ shaderStage ]; - - const bufferStructMap = new Map(); - - uniforms.forEach( ( uniform ) => { - - const { name, node } = uniform; - const hasBufferStruct = node.bufferStruct === true; - bufferStructMap.set( name, hasBufferStruct ); - - } ); - - return bufferStructMap; - - } - - getMembersFromCustomStruct( members ) { - - const structMembers = members.map( ( { name, type, isAtomic } ) => { - - let finalType = wgslTypeLib[ type ]; - - if ( ! finalType ) { - - console.warn( `Unrecognized type: ${type}` ); - finalType = 'vec4'; - - } - - return `${name}: ${isAtomic ? `atomic<${finalType}>` : finalType}`; - - } ); - - return `\t${structMembers.join( ',\n\t' )}`; - - } - - getCustomStructNameFromShader( source ) { - - const functionRegex = /fn\s+\w+\s*\(([\s\S]*?)\)/g; // filter shader header - const parameterRegex = /(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g; // filter parameters - - const results = []; - - let match; - - while ( ( match = functionRegex.exec( source ) ) !== null ) { - - const parameterString = match[ 1 ]; - - let paramMatch; - - while ( ( paramMatch = parameterRegex.exec( parameterString ) ) !== null ) { - - const [ fullMatch, name, fullType, ptrType, arrayType, directStructName ] = paramMatch; - - const structName = arrayType || directStructName || null; - - const type = ptrType || fullType; - - if (Object.values(wgslTypeLib).includes(structName) || structName === null) { - - continue; - - } - - results.push( { - name, - type, - structName - } ); - - } - - } - - return results; - - } - getStructMembers( struct ) { const snippets = []; @@ -38352,14 +38244,12 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; - - const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; - const bufferSnippet = bufferNode.bufferStruct ? this.getMembersFromCustomStruct( bufferType ) : `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; + const bufferSnippet = `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform'; - bufferSnippets.push( this._getWGSLStructBinding( bufferNode.bufferStruct, isArray, 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); + bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); } else { @@ -38382,7 +38272,7 @@ ${ flowData.code } const group = uniformGroups[ name ]; - structSnippets.push( this._getWGSLStructBinding( false, false, name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); + structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); } @@ -38411,69 +38301,9 @@ ${ flowData.code } stageData.codes = this.getCodes( shaderStage ); stageData.directives = this.getDirectives( shaderStage ); stageData.scopedArrays = this.getScopedArrays( shaderStage ); - stageData.isBufferStruct = this.getTypeFromCustomStruct( shaderStage ); - stageData.customStructNames = this.getCustomStructNameFromShader( stageData.codes ); // - const reduceFlow = ( flow ) => { - - return flow.replace( /&(\w+)\.(\w+)/g, ( match, bufferName, uniformName ) => - - stageData.isBufferStruct.get( uniformName ) === true ? `&${bufferName}` : match - - ); - - }; - - const extractPointerNames = ( source ) => { - - const match = source.match( /\(([^)]+)\)/ ); - if ( ! match ) return []; - - const content = match[ 1 ]; - - return content - .split( /\s*,\s*/ ) - .map( part => part.trim() ) - .filter( part => part.includes( '&' ) ) - .map( part => part.replace( '&', '' ) ) - .filter( part => ! part.includes( '.' ) ); - - }; - - const createStructNameMapping = ( nodeBuffers, structs ) => { - - const resultMap = new Map(); - - for (let i = 0; i < nodeBuffers.length; i++) { - - const bufferName = nodeBuffers[i]; - const struct = structs[i]; - - resultMap.set(bufferName, struct.structName); - - } - - return resultMap; - - }; - - const replaceStructNamesInUniforms = ( shaderCode, map ) => { - - for ( const [ key, value ] of map.entries() ) { - - const regex = new RegExp( `\\b${key}Struct\\b`, 'g' ); - shaderCode = shaderCode.replace( regex, value ); - - } - - return shaderCode; - - }; - - - let pointerNames, structnameMapping; let flow = '// code\n\n'; flow += this.flowCode[ shaderStage ]; @@ -38498,68 +38328,6 @@ ${ flowData.code } flow += `${ flowSlotData.code }\n\t`; - - /* - REVIEW COMMENT remove after review - - before reduceFlow: - compute( &NodeBuffer_554.nodeUniform0, &NodeBuffer_558.nodeUniform1, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); - - after reduceFlow: reduceFlow checks whether there is a storageStruct and if so then the - postfix is ​​removed so that the pointer points to the struct and not to a content in the struct - compute( &NodeBuffer_554, &NodeBuffer_558, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); - - extractPointerNames reads the names of the reduced pointers and stores them in an array - Array(2) - 0: "NodeBuffer_554" - 1: "NodeBuffer_558" - - getCustomStructNameFromShader at the beginning reads the structNames from the shader header - Array(2) - 0: {name: 'drawBuffer', type: 'storage', structName: 'DrawBuffer'} - 1: {name: 'meshletInfo', type: 'storage', structName: 'MeshletInfo'} - - - createStructNameMapping links the automatic generated WGSLNodeBuilder for each struct with the struct name specified by the user. - This is necessary because in wgslFn the user can choose any name in the shader in ptr for structs. - - Map(2) - [[Entries]] - 0: {"NodeBuffer_554" => "DrawBuffer"} - 1: {"NodeBuffer_558" => "MeshletInfo"} - - replaceStructNames then replaces the names in the uniforms in the custom structs that the WGSLNodeBuilder - created with the name chosen by the user. - - before replaceStructNames: - - struct NodeBuffer_554Struct { - vertexCount: u32, - instanceCount: u32, - firstVertex: u32, - firstInstance: u32 - }; - @binding( 0 ) @group( 0 ) - var NodeBuffer_554 : NodeBuffer_554Struct; - - after replaceStructNames: - - struct DrawBuffer { - vertexCount: u32, - instanceCount: u32, - firstVertex: u32, - firstInstance: u32 - }; - @binding( 0 ) @group( 0 ) - var NodeBuffer_554 : DrawBuffer; - */ - - - flow = reduceFlow( flow ); - pointerNames = extractPointerNames(flow); - structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); - stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); - if ( node === mainNode && shaderStage !== 'compute' ) { flow += '// result\n\n\t'; @@ -38594,11 +38362,6 @@ ${ flowData.code } } - flow = reduceFlow( flow ); - pointerNames = extractPointerNames(flow); - structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); - stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); - } } @@ -38803,27 +38566,15 @@ ${vars} } - _getWGSLStructBinding( isBufferStruct, isArray, name, vars, access, binding = 0, group = 0 ) { + _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) { const structName = name + 'Struct'; const structSnippet = this._getWGSLStruct( structName, vars ); - if ( ! isBufferStruct ) { - - return `${structSnippet} + return `${structSnippet} @binding( ${binding} ) @group( ${group} ) var<${access}> ${name} : ${structName};`; - } else { - - const StructName = isArray ? `array<${structName}>` : structName; - - return `${structSnippet} -@binding( ${binding} ) @group( ${group} ) -var<${access}> ${name} : ${StructName};`; - - } - } } @@ -42459,4 +42210,4 @@ class ClippingGroup extends Group { } -export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BRDF_GGX, BRDF_Lambert, BackSide, BasicEnvironmentNode, BatchNode, BoxGeometry, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DFGApprox, D_GGX, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, Discard, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EPSILON, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, F_Schlick, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fn, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, If, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, 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, Loader, Loop, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap$1 as PCFShadowMap, PI, PI2, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, 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_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScreenNode, ScriptableNode, ScriptableNodeResources, ScriptableValueNode, SetNode, ShaderNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, abs, acesFilmicToneMapping, acos, add, addMethodChaining, addNodeElement, agxToneMapping, all, alphaT, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, atomicAdd, atomicAnd, atomicFunc, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, attenuationColor, attenuationDistance, attribute, backgroundBlurriness, backgroundIntensity, backgroundRotation, batch, billboarding, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blendNormal, blur, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, cdl, ceil, checker, cineonToneMapping, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToWorking, colorToDirection, compute, cond, context, convert, convertColorSpace, convertToTexture, cos, createCanvasElement, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, deltaTime, densityFog, depth, depthPass, difference, diffuseColor, directPointLight, directionToColor, dispersion, distance, div, dodge, dot, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getNormalFromDepth, getParallaxCorrectNormal, getRoughness, getScreenPosition, getShIrradianceAt, getTextureIndex, getViewPosition, glsl, glslFn, grayscale, greaterThan, greaterThanEqual, hash, highPrecisionModelNormalViewMatrix, highPrecisionModelViewMatrix, hue, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, invocationLocalIndex, invocationSubgroupIndex, ior, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightPosition, lightTargetDirection, lightTargetPosition, lightViewPosition, lightingContext, lights, linearDepth, linearToneMapping, localId, log, log2, logarithmicDepthToViewZ, loop, luminance, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialAttenuationColor, materialAttenuationDistance, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIOR, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRefractionRatio, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularColor, materialSpecularIntensity, materialSpecularStrength, materialThickness, materialTransmission, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mixElement, mod, modInt, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, neutralToneMapping, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalFlat, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, notEqual, numWorkgroups, objectDirection, objectGroup, objectPosition, objectScale, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionPrevious, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, reinhardToneMapping, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rotate, rotateUV, roughness, round, rtt, sRGBTransferEOTF, sRGBTransferOETF, sampler, saturate, saturation, screen, screenCoordinate, screenSize, screenUV, scriptable, scriptableValue, select, setCurrentStack, shaderStages, shadow, sharedUniformGroup, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, smoothstepElement, specularColor, specularF90, spherizeUV, split, spritesheetUV, sqrt, stack, step, storage, storageBarrier, storageObject, storageStruct, storageTexture, string, struct, sub, subgroupIndex, subgroupSize, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBarrier, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, thickness, threshold, time, timerDelta, timerGlobal, timerLocal, toOutputColorSpace, toWorkingColorSpace, toneMapping, toneMappingExposure, toonOutlinePass, transformDirection, transformNormal, transformNormalToView, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transmission, transpose, tri, tri3, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, uniform, uniformArray, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, velocity, vertexColor, vertexIndex, vibrance, viewZToLogarithmicDepth, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSafeUV, viewportSharedTexture, viewportSize, viewportTexture, viewportTopLeft, viewportUV, wgsl, wgslFn, workgroupArray, workgroupBarrier, workgroupId, workingToColorSpace, xor }; +export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BRDF_GGX, BRDF_Lambert, BackSide, BasicEnvironmentNode, BatchNode, BoxGeometry, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DFGApprox, D_GGX, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, Discard, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EPSILON, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, F_Schlick, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fn, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, If, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, 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, Loader, Loop, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap$1 as PCFShadowMap, PI, PI2, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, 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_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScreenNode, ScriptableNode, ScriptableNodeResources, ScriptableValueNode, SetNode, ShaderNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, abs, acesFilmicToneMapping, acos, add, addMethodChaining, addNodeElement, agxToneMapping, all, alphaT, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, atomicAdd, atomicAnd, atomicFunc, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, attenuationColor, attenuationDistance, attribute, backgroundBlurriness, backgroundIntensity, backgroundRotation, batch, billboarding, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blendNormal, blur, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, cdl, ceil, checker, cineonToneMapping, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToWorking, colorToDirection, compute, cond, context, convert, convertColorSpace, convertToTexture, cos, createCanvasElement, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, deltaTime, densityFog, depth, depthPass, difference, diffuseColor, directPointLight, directionToColor, dispersion, distance, div, dodge, dot, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getNormalFromDepth, getParallaxCorrectNormal, getRoughness, getScreenPosition, getShIrradianceAt, getTextureIndex, getViewPosition, glsl, glslFn, grayscale, greaterThan, greaterThanEqual, hash, highPrecisionModelNormalViewMatrix, highPrecisionModelViewMatrix, hue, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, invocationLocalIndex, invocationSubgroupIndex, ior, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightPosition, lightTargetDirection, lightTargetPosition, lightViewPosition, lightingContext, lights, linearDepth, linearToneMapping, localId, log, log2, logarithmicDepthToViewZ, loop, luminance, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialAttenuationColor, materialAttenuationDistance, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIOR, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRefractionRatio, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularColor, materialSpecularIntensity, materialSpecularStrength, materialThickness, materialTransmission, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mixElement, mod, modInt, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, neutralToneMapping, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalFlat, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, notEqual, numWorkgroups, objectDirection, objectGroup, objectPosition, objectScale, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionPrevious, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, reinhardToneMapping, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rotate, rotateUV, roughness, round, rtt, sRGBTransferEOTF, sRGBTransferOETF, sampler, saturate, saturation, screen, screenCoordinate, screenSize, screenUV, scriptable, scriptableValue, select, setCurrentStack, shaderStages, shadow, sharedUniformGroup, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, smoothstepElement, specularColor, specularF90, spherizeUV, split, spritesheetUV, sqrt, stack, step, storage, storageBarrier, storageObject, storageTexture, string, sub, subgroupIndex, subgroupSize, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBarrier, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, thickness, threshold, time, timerDelta, timerGlobal, timerLocal, toOutputColorSpace, toWorkingColorSpace, toneMapping, toneMappingExposure, toonOutlinePass, transformDirection, transformNormal, transformNormalToView, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transmission, transpose, tri, tri3, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, uniform, uniformArray, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, velocity, vertexColor, vertexIndex, vibrance, viewZToLogarithmicDepth, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSafeUV, viewportSharedTexture, viewportSize, viewportTexture, viewportTopLeft, viewportUV, wgsl, wgslFn, workgroupArray, workgroupBarrier, workgroupId, workingToColorSpace, xor }; diff --git a/build/three.webgpu.min.js b/build/three.webgpu.min.js index 6e2389d3b73a74..6c1ab1bd4a612b 100644 --- a/build/three.webgpu.min.js +++ b/build/three.webgpu.min.js @@ -3,4 +3,4 @@ * Copyright 2010-2024 Three.js Authors * SPDX-License-Identifier: MIT */ -import{Color as e,Vector2 as t,Vector3 as s,Vector4 as r,Matrix3 as n,Matrix4 as i,EventDispatcher as o,MathUtils as a,ColorManagement as u,SRGBTransfer as l,NoToneMapping as d,StaticDrawUsage as c,InterleavedBuffer as h,DynamicDrawUsage as p,InterleavedBufferAttribute as g,NoColorSpace as m,UnsignedIntType as f,IntType as y,WebGLCoordinateSystem as b,BackSide as x,CubeReflectionMapping as T,CubeRefractionMapping as _,WebGPUCoordinateSystem as N,TangentSpaceNormalMap as v,ObjectSpaceNormalMap as S,InstancedInterleavedBuffer as A,InstancedBufferAttribute as R,DataArrayTexture as C,FloatType as E,FramebufferTexture as w,LinearMipmapLinearFilter as M,DepthTexture as B,Material as U,NormalBlending as F,PointsMaterial as P,LineBasicMaterial as I,LineDashedMaterial as L,MeshNormalMaterial as D,WebGLCubeRenderTarget as V,BoxGeometry as O,NoBlending as G,Mesh as k,Scene as z,LinearFilter as $,CubeCamera as H,CubeTexture as W,EquirectangularReflectionMapping as j,EquirectangularRefractionMapping as q,AddOperation as K,MixOperation as X,MultiplyOperation as Y,MeshBasicMaterial as Q,MeshLambertMaterial as Z,MeshPhongMaterial as J,Texture as ee,MeshStandardMaterial as te,MeshPhysicalMaterial as se,MeshToonMaterial as re,MeshMatcapMaterial as ne,SpriteMaterial as ie,ShadowMaterial as oe,Uint32BufferAttribute as ae,Uint16BufferAttribute as ue,DoubleSide as le,DepthStencilFormat as de,DepthFormat as ce,UnsignedInt248Type as he,UnsignedByteType as pe,RenderTarget as ge,Plane as me,Object3D as fe,HalfFloatType as ye,LinearMipMapLinearFilter as be,OrthographicCamera as xe,BufferGeometry as Te,Float32BufferAttribute as _e,UVMapping as Ne,Euler as ve,LinearSRGBColorSpace as Se,LessCompare as Ae,VSMShadowMap as Re,RGFormat as Ce,SphereGeometry as Ee,BufferAttribute as we,CubeUVReflectionMapping as Me,PerspectiveCamera as Be,RGBAFormat as Ue,LinearMipmapNearestFilter as Fe,NearestMipmapLinearFilter as Pe,Float16BufferAttribute as Ie,REVISION as Le,SRGBColorSpace as De,PCFShadowMap as Ve,FrontSide as Oe,Frustum as Ge,DataTexture as ke,RedIntegerFormat as ze,RedFormat as $e,RGIntegerFormat as He,RGBIntegerFormat as We,RGBFormat as je,RGBAIntegerFormat as qe,UnsignedShortType as Ke,ByteType as Xe,ShortType as Ye,createCanvasElement as Qe,AddEquation as Ze,SubtractEquation as Je,ReverseSubtractEquation as et,ZeroFactor as tt,OneFactor as st,SrcColorFactor as rt,SrcAlphaFactor as nt,SrcAlphaSaturateFactor as it,DstColorFactor as ot,DstAlphaFactor as at,OneMinusSrcColorFactor as ut,OneMinusSrcAlphaFactor as lt,OneMinusDstColorFactor as dt,OneMinusDstAlphaFactor as ct,CullFaceNone as ht,CullFaceBack as pt,CullFaceFront as gt,CustomBlending as mt,MultiplyBlending as ft,SubtractiveBlending as yt,AdditiveBlending as bt,NotEqualDepth as xt,GreaterDepth as Tt,GreaterEqualDepth as _t,EqualDepth as Nt,LessEqualDepth as vt,LessDepth as St,AlwaysDepth as At,NeverDepth as Rt,UnsignedShort4444Type as Ct,UnsignedShort5551Type as Et,UnsignedInt5999Type as wt,AlphaFormat as Mt,LuminanceFormat as Bt,LuminanceAlphaFormat as Ut,RGB_S3TC_DXT1_Format as Ft,RGBA_S3TC_DXT1_Format as Pt,RGBA_S3TC_DXT3_Format as It,RGBA_S3TC_DXT5_Format as Lt,RGB_PVRTC_4BPPV1_Format as Dt,RGB_PVRTC_2BPPV1_Format as Vt,RGBA_PVRTC_4BPPV1_Format as Ot,RGBA_PVRTC_2BPPV1_Format as Gt,RGB_ETC1_Format as kt,RGB_ETC2_Format as zt,RGBA_ETC2_EAC_Format as $t,RGBA_ASTC_4x4_Format as Ht,RGBA_ASTC_5x4_Format as Wt,RGBA_ASTC_5x5_Format as jt,RGBA_ASTC_6x5_Format as qt,RGBA_ASTC_6x6_Format as Kt,RGBA_ASTC_8x5_Format as Xt,RGBA_ASTC_8x6_Format as Yt,RGBA_ASTC_8x8_Format as Qt,RGBA_ASTC_10x5_Format as Zt,RGBA_ASTC_10x6_Format as Jt,RGBA_ASTC_10x8_Format as es,RGBA_ASTC_10x10_Format as ts,RGBA_ASTC_12x10_Format as ss,RGBA_ASTC_12x12_Format as rs,RGBA_BPTC_Format as ns,RED_RGTC1_Format as is,SIGNED_RED_RGTC1_Format as os,RED_GREEN_RGTC2_Format as as,SIGNED_RED_GREEN_RGTC2_Format as us,RepeatWrapping as ls,ClampToEdgeWrapping as ds,MirroredRepeatWrapping as cs,NearestFilter as hs,NearestMipmapNearestFilter as ps,NeverCompare as gs,AlwaysCompare as ms,LessEqualCompare as fs,EqualCompare as ys,GreaterEqualCompare as bs,GreaterCompare as xs,NotEqualCompare as Ts,warnOnce as _s,NotEqualStencilFunc as Ns,GreaterStencilFunc as vs,GreaterEqualStencilFunc as Ss,EqualStencilFunc as As,LessEqualStencilFunc as Rs,LessStencilFunc as Cs,AlwaysStencilFunc as Es,NeverStencilFunc as ws,DecrementWrapStencilOp as Ms,IncrementWrapStencilOp as Bs,DecrementStencilOp as Us,IncrementStencilOp as Fs,InvertStencilOp as Ps,ReplaceStencilOp as Is,ZeroStencilOp as Ls,KeepStencilOp as Ds,MaxEquation as Vs,MinEquation as Os,SpotLight as Gs,PointLight as ks,DirectionalLight as zs,RectAreaLight as $s,AmbientLight as Hs,HemisphereLight as Ws,LightProbe as js,LinearToneMapping as qs,ReinhardToneMapping as Ks,CineonToneMapping as Xs,ACESFilmicToneMapping as Ys,AgXToneMapping as Qs,NeutralToneMapping as Zs,Group as Js,Loader as er,FileLoader as tr,MaterialLoader as sr,ObjectLoader as rr}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrayCamera,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BasicShadowMap,BatchedMesh,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,Camera,CameraHelper,CanvasTexture,CapsuleGeometry,CatmullRomCurve3,CircleGeometry,Clock,ColorKeyframeTrack,CompressedArrayTexture,CompressedCubeTexture,CompressedTexture,CompressedTextureLoader,ConeGeometry,ConstantAlphaFactor,ConstantColorFactor,Controls,CubeTextureLoader,CubicBezierCurve,CubicBezierCurve3,CubicInterpolant,CullFaceFrontBack,Curve,CurvePath,CustomToneMapping,CylinderGeometry,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LinearTransfer,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,Matrix2,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,PCFSoftShadowMap,Path,PlaneGeometry,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,Quaternion,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Sphere,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLMultipleRenderTargets,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding}from"./three.core.min.js";const nr=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class ir{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=nr,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:s,material:r}=e;if(t={material:this.getMaterialData(r),geometry:{attributes:this.getAttributesData(s.attributes),indexVersion:s.index?s.index.version:null,drawRange:{start:s.drawRange.start,count:s.drawRange.count}},worldMatrix:e.object.matrixWorld.clone()},e.object.center&&(t.center=e.object.center.clone()),e.object.morphTargetInfluences&&(t.morphTargetInfluences=e.object.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(t.matrixWorld))return n.worldMatrix.copy(t.matrixWorld),!1;const i=n.material;for(const e in i){const t=i[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return i[e]=r,!1}if(i.transmission>0){const{width:t,height:s}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==s)return n.bufferWidth=t,n.bufferHeight=s,!1}const o=n.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return n.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let s=0;s>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:n}of cr(e))s.push(s,or(r.slice(0,-4)),n.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;ee.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of cr(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let r=null;const n=e.getBuildStage();if("setup"===n){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===n)this.analyze(e);else if("generate"===n){if(1===this.generate.length){const s=this.getNodeType(e),n=e.getDataFromNode(this);r=n.snippet,void 0===r?(r=this.generate(e)||"",n.snippet=r):void 0!==n.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:n,childNode:i}of t)void 0!==n?(void 0===s[r]&&(s[r]=Number.isInteger(n)?[]:{}),s[r][n]=i.toJSON(e.meta).uuid):s[r]=i.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const n of e.inputNodes[s])r.push(t[n]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const n in e.inputNodes[s]){const i=e.inputNodes[s][n];r[n]=t[i]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let n=e.nodes[t];function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===n&&(n={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[n.uuid]=n),this.serialize(n),delete n.meta),r){const t=i(e.textures),s=i(e.images),r=i(e.nodes);t.length>0&&(n.textures=t),s.length>0&&(n.images=s),r.length>0&&(n.nodes=r)}return n}}class Rr extends Ar{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,r=this.getNodeType(e),n=s.build(e,r);return e.format(n,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const n=super.build(e,s),i=e.getVarFromNode(this,null,s),o=e.getPropertyName(i);return e.addLineFlowCode(`${o} = ${n}`,this),r.snippet=n,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,s)=>t+e.getTypeLength(s.getNodeType(e))),0))}generate(e,t){const s=this.getNodeType(e),r=this.nodes,n=e.getComponentType(s),i=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==n&&(s=e.format(s,r,n)),i.push(s)}const o=`${e.getType(s)}( ${i.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(vr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,r=e.getTypeLength(s.getNodeType(e));let n=null;if(r>1){let i=null;this.getVectorLength()>=r&&(i=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,i);n=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,i,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else n=s.build(e,t);return n}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:r}=this,n=this.getNodeType(e),i=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,i),a=t.build(e,n),u=e.getTypeLength(n),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(pn(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),hn(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>hn(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>hn(new Fr(hn(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),hn(new Br(e,t));if(!0===/^\d+$/.test(t))return hn(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=hn(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;rhn(null!==r?Object.assign(e,r):e);return null===t?(...t)=>n(new e(...gn(t))):null!==s?(s=hn(s),(...r)=>n(new e(t,...gn(r),s))):(...s)=>n(new e(t,...gn(s)))},qr=function(e,...t){return hn(new e(...gn(t)))};class Kr extends Ar{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let n=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let i=r.get(t);void 0===i&&(i=hn(e.buildFunctionNode(t)),r.set(t,i)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(i),n=hn(i.call(s))}else{const r=t.jsFunc,i=null!==s?r(s,e):r(e);n=hn(i)}return t.once&&(r.onceOutput=n),n}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return pn(e),hn(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],en=new Map;for(const e of Yr)en.set(e,new Ir(e));const tn=new Map;for(const e of Qr)tn.set(e,new Ir(e,"uint"));const sn=new Map([...tn].map((e=>new Ir(e.value,"int"))));for(const e of Zr)sn.set(e,new Ir(e,"int"));const rn=new Map([...sn].map((e=>new Ir(e.value))));for(const e of Jr)rn.set(e,new Ir(e));for(const e of Jr)rn.set(-e,new Ir(-e));const nn={bool:en,uint:tn,ints:sn,float:rn},on=new Map([...en,...rn]),an=(e,t)=>on.has(e)?on.get(e):!0===e.isNode?e:new Ir(e,t),un=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return hn(t.get(s[0]));if(1===s.length){const t=an(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?hn(t):hn(new Cr(t,e))}const r=s.map((e=>an(e)));return hn(new wr(r,e))}},ln=e=>"object"==typeof e&&null!==e?e.value:e,dn=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function cn(e,t){return new Proxy(new Xr(e,t),kr)}const hn=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?hn(an(e,t)):"shader"===s?yn(e):e}(e,t),pn=(e,t=null)=>new Hr(e,t),gn=(e,t=null)=>new Wr(e,t),mn=(...e)=>new jr(...e),fn=(...e)=>new qr(...e),yn=(e,t)=>{const s=new cn(e,t),r=(...e)=>{let t;return pn(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},bn=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),yn(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const xn=e=>{Lr=e},Tn=()=>Lr,_n=(...e)=>Lr.If(...e);function Nn(e){return Lr&&Lr.add(e),e}Vr("append",Nn);const vn=new un("color"),Sn=new un("float",nn.float),An=new un("int",nn.ints),Rn=new un("uint",nn.uint),Cn=new un("bool",nn.bool),En=new un("vec2"),wn=new un("ivec2"),Mn=new un("uvec2"),Bn=new un("bvec2"),Un=new un("vec3"),Fn=new un("ivec3"),Pn=new un("uvec3"),In=new un("bvec3"),Ln=new un("vec4"),Dn=new un("ivec4"),Vn=new un("uvec4"),On=new un("bvec4"),Gn=new un("mat2"),kn=new un("mat3"),zn=new un("mat4"),$n=(e="")=>hn(new Ir(e,"string")),Hn=e=>hn(new Ir(e,"ArrayBuffer"));Vr("toColor",vn),Vr("toFloat",Sn),Vr("toInt",An),Vr("toUint",Rn),Vr("toBool",Cn),Vr("toVec2",En),Vr("toIVec2",wn),Vr("toUVec2",Mn),Vr("toBVec2",Bn),Vr("toVec3",Un),Vr("toIVec3",Fn),Vr("toUVec3",Pn),Vr("toBVec3",In),Vr("toVec4",Ln),Vr("toIVec4",Dn),Vr("toUVec4",Vn),Vr("toBVec4",On),Vr("toMat2",Gn),Vr("toMat3",kn),Vr("toMat4",zn);const Wn=mn(Rr),jn=(e,t)=>hn(new Cr(hn(e),t)),qn=(e,t)=>hn(new Br(hn(e),t));Vr("element",Wn),Vr("convert",jn);class Kn extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Xn=e=>new Kn(e),Yn=(e,t=0)=>new Kn(e,!0,t),Qn=Yn("frame"),Zn=Yn("render"),Jn=Xn("object");class ei extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Jn}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let n=e.getNodeFromHash(r);void 0===n&&(e.setHashNode(this,r),n=this);const i=n.getInputType(e),o=e.getUniformFromNode(n,i,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const ti=(e,t)=>{const s=dn(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return hn(new ei(r,s))};class si extends Ar{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const ri=(e,t)=>hn(new si(e,t)),ni=(e,t)=>hn(new si(e,t,!0)),ii=fn(si,"vec4","DiffuseColor"),oi=fn(si,"vec3","EmissiveColor"),ai=fn(si,"float","Roughness"),ui=fn(si,"float","Metalness"),li=fn(si,"float","Clearcoat"),di=fn(si,"float","ClearcoatRoughness"),ci=fn(si,"vec3","Sheen"),hi=fn(si,"float","SheenRoughness"),pi=fn(si,"float","Iridescence"),gi=fn(si,"float","IridescenceIOR"),mi=fn(si,"float","IridescenceThickness"),fi=fn(si,"float","AlphaT"),yi=fn(si,"float","Anisotropy"),bi=fn(si,"vec3","AnisotropyT"),xi=fn(si,"vec3","AnisotropyB"),Ti=fn(si,"color","SpecularColor"),_i=fn(si,"float","SpecularF90"),Ni=fn(si,"float","Shininess"),vi=fn(si,"vec4","Output"),Si=fn(si,"float","dashSize"),Ai=fn(si,"float","gapSize"),Ri=fn(si,"float","pointWidth"),Ci=fn(si,"float","IOR"),Ei=fn(si,"float","Transmission"),wi=fn(si,"float","Thickness"),Mi=fn(si,"float","AttenuationDistance"),Bi=fn(si,"color","AttenuationColor"),Ui=fn(si,"float","Dispersion");class Fi extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,n=this.needsSplitAssign(e),i=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,i),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(n){const r=e.getVarFromNode(this,null,i),n=e.getPropertyName(r);e.addLineFlowCode(`${n} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t{const r=s.type;let n;return n="pointer"===r?"&"+t.build(e):t.build(e,r),n};if(Array.isArray(n))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?gn(t):pn(t[0]),hn(new Ii(hn(e),t)));Vr("call",Li);class Di extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let n=new Di(e,t,s);for(let t=0;t>"===s||"<<"===s)return e.getIntegerType(i);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(i),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===i&&e.isMatrix(o)?o:e.isMatrix(i)&&e.isVector(o)?e.getVectorFromMatrix(i):e.isVector(i)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(i)?o:i}generate(e,t){const s=this.op,r=this.aNode,n=this.bNode,i=this.getNodeType(e,t);let o=null,a=null;"void"!==i?(o=r.getNodeType(e),a=void 0!==n?n.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=i,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=i):o=a=i;const u=r.build(e,o),l=void 0!==n?n.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} < ${l} )`,i,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} <= ${l} )`,i,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} > ${l} )`,i,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} >= ${l} )`,i,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`( ${u} ${s} ${l} )`,i,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`${u} ${s} ${l}`,i,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vi=mn(Di,"+"),Oi=mn(Di,"-"),Gi=mn(Di,"*"),ki=mn(Di,"/"),zi=mn(Di,"%"),$i=mn(Di,"=="),Hi=mn(Di,"!="),Wi=mn(Di,"<"),ji=mn(Di,">"),qi=mn(Di,"<="),Ki=mn(Di,">="),Xi=mn(Di,"&&"),Yi=mn(Di,"||"),Qi=mn(Di,"!"),Zi=mn(Di,"^^"),Ji=mn(Di,"&"),eo=mn(Di,"~"),to=mn(Di,"|"),so=mn(Di,"^"),ro=mn(Di,"<<"),no=mn(Di,">>");Vr("add",Vi),Vr("sub",Oi),Vr("mul",Gi),Vr("div",ki),Vr("modInt",zi),Vr("equal",$i),Vr("notEqual",Hi),Vr("lessThan",Wi),Vr("greaterThan",ji),Vr("lessThanEqual",qi),Vr("greaterThanEqual",Ki),Vr("and",Xi),Vr("or",Yi),Vr("not",Qi),Vr("xor",Zi),Vr("bitAnd",Ji),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",no);const io=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zi(...e));Vr("remainder",io);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,n=e.isMatrix(t)?0:e.getTypeLength(t),i=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return n>i&&n>o?t:i>o?s:o>n?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),n=this.getInputType(e),i=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=i,r=o;e.isMatrix(s.getNodeType(e))?r=Ln(Un(r),0):s=Ln(Un(s),0);const n=Gi(s,r).xyz;return Ao(n).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+i.build(e,n)+" )",r,t);if(s===oo.ONE_MINUS)return Oi(1,i).build(e,t);if(s===oo.RECIPROCAL)return ki(1,i).build(e,t);if(s===oo.DIFFERENCE)return Fo(Oi(i,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(i.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(i.build(e,1===e.getTypeLength(i.getNodeType(e))?"float":n),o.build(e,n)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(i.build(e,n),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":n)):s===oo.REFRACT?l.push(i.build(e,n),o.build(e,n),a.build(e,"float")):s===oo.MIX?l.push(i.build(e,n),o.build(e,n),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":n)):(l.push(i.build(e,n)),null!==o&&l.push(o.build(e,n)),null!==a&&l.push(a.build(e,n))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=Sn(1e-6),uo=Sn(1e6),lo=Sn(Math.PI),co=Sn(2*Math.PI),ho=mn(oo,oo.ALL),po=mn(oo,oo.ANY),go=mn(oo,oo.EQUALS),mo=mn(oo,oo.RADIANS),fo=mn(oo,oo.DEGREES),yo=mn(oo,oo.EXP),bo=mn(oo,oo.EXP2),xo=mn(oo,oo.LOG),To=mn(oo,oo.LOG2),_o=mn(oo,oo.SQRT),No=mn(oo,oo.INVERSE_SQRT),vo=mn(oo,oo.FLOOR),So=mn(oo,oo.CEIL),Ao=mn(oo,oo.NORMALIZE),Ro=mn(oo,oo.FRACT),Co=mn(oo,oo.SIN),Eo=mn(oo,oo.COS),wo=mn(oo,oo.TAN),Mo=mn(oo,oo.ASIN),Bo=mn(oo,oo.ACOS),Uo=mn(oo,oo.ATAN),Fo=mn(oo,oo.ABS),Po=mn(oo,oo.SIGN),Io=mn(oo,oo.LENGTH),Lo=mn(oo,oo.NEGATE),Do=mn(oo,oo.ONE_MINUS),Vo=mn(oo,oo.DFDX),Oo=mn(oo,oo.DFDY),Go=mn(oo,oo.ROUND),ko=mn(oo,oo.RECIPROCAL),zo=mn(oo,oo.TRUNC),$o=mn(oo,oo.FWIDTH),Ho=mn(oo,oo.BITCAST),Wo=mn(oo,oo.TRANSPOSE),jo=mn(oo,oo.ATAN2),qo=mn(oo,oo.MIN),Ko=mn(oo,oo.MAX),Xo=mn(oo,oo.MOD),Yo=mn(oo,oo.STEP),Qo=mn(oo,oo.REFLECT),Zo=mn(oo,oo.DISTANCE),Jo=mn(oo,oo.DIFFERENCE),ea=mn(oo,oo.DOT),ta=mn(oo,oo.CROSS),sa=mn(oo,oo.POW),ra=mn(oo,oo.POW,2),na=mn(oo,oo.POW,3),ia=mn(oo,oo.POW,4),oa=mn(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gi(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=mn(oo,oo.MIX),da=(e,t=0,s=1)=>hn(new oo(oo.CLAMP,hn(e),hn(t),hn(s))),ca=e=>da(e),ha=mn(oo,oo.REFRACT),pa=mn(oo,oo.SMOOTHSTEP),ga=mn(oo,oo.FACEFORWARD),ma=yn((([e])=>{const t=ea(e.xy,En(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",na),Vr("pow4",ia),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,n=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=n,null!==r&&(e.getDataFromNode(r).parentNodeBlock=n);const i=e.getNodeProperties(this);i.condNode=t,i.ifNode=s.context({nodeBlock:s}),i.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:n,ifNode:i,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?ri(s).build(e):"";r.nodeProperty=u;const l=n.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=i.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=mn(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e,t);return e.setContext(s),r}}const Na=mn(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),n=e.getPropertyName(r),i=t.build(e,r.type);return e.addLineFlowCode(`${n} = ${i}`,this),n}}const Aa=mn(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const r=this.name,n=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,n),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const r=this.getNodeType(e),n=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,n),t.propertyName=n}return e.getPropertyName(s)}}const Ea=mn(Ca);Vr("varying",Ea);const wa=yn((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=yn((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let i=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(i=Ln(wa(i.rgb),i.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(i=Ln(kn(u._getMatrix(new n,s,r)).mul(i.rgb),i.a)),u.getTransfer(r)===l&&(i=Ln(Ma(i.rgb),i.a)),i):i}}const Pa=e=>hn(new Fa(hn(e),Ba,Ua)),Ia=e=>hn(new Fa(hn(e),Ua,Ba)),La=(e,t)=>hn(new Fa(hn(e),Ba,t)),Da=(e,t)=>hn(new Fa(hn(e),t,Ba)),Va=(e,t,s)=>hn(new Fa(hn(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return hn(new Oa(this,hn(e)))}setNodeType(e){const t=ti(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const n=e.renderer.library.getToneMappingFunction(s);return null!==n?r=Ln(n(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>hn(new $a(e,hn(t),hn(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),n=this.bufferStride||r,i=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,n),a=new g(o,r,i);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let n=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,n=r;else{n=Ea(this).build(e,t)}return n}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>hn(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;ehn(new Qa(hn(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const n=this.node.build(e,...t);return e.setCache(s),n}}const eu=(e,...t)=>hn(new Ja(hn(e),...t));Vr("cache",eu);class tu extends Ar{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const su=mn(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=Sn(0),n=Sn(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=n,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:n,doClamp:i}=this;let o=e.sub(t).div(s.sub(t));return!0===i&&(o=o.clamp()),o.mul(n.sub(r)).add(r)}}const nu=mn(ru,null,null,{doClamp:!1}),iu=mn(ru);Vr("remap",nu),Vr("remapClamp",iu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=mn(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>hn(new du(hn(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),n=e.getTypeFromAttribute(r),i=e.getAttribute(t,n);if("vertex"===e.shaderStage)return e.format(i.name,n,s);return Ea(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const gu=(e,t)=>hn(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=mn(fu);class bu extends ei{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=mn(bu);class Tu extends ei{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=ti(this.value.matrix)),this._matrixUniform.mul(Un(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&!0===s.flipY||!0===s.isRenderTargetTexture||!0===s.isFramebufferTexture||!0===s.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(An(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,n,i,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,i):n?e.generateTextureBias(u,t,s,n,i):a?e.generateTextureGrad(u,t,s,a,i):o?e.generateTextureCompare(u,t,s,o,i):!1===this.sampler?e.generateTextureLoad(u,t,s,i):e.generateTexture(u,t,s,i),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const n=super.generate(e,"property");if("sampler"===t)return n+"_sampler";if(e.isReference(t))return n;{const i=e.getDataFromNode(this);let o=i.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,n,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),i.snippet=b,i.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}blur(e){const t=this.clone();return t.biasNode=hn(e).mul(xu(t)),t.referenceNode=this.getSelf(),hn(t)}level(e){const t=this.clone();return t.levelNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}compare(e){const t=this.clone();return t.compareNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}grad(e,t){const s=this.clone();return s.gradNode=[hn(e),hn(t)],s.referenceNode=this.getSelf(),hn(s)}depth(e){const t=this.clone();return t.depthNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=mn(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=ti("float").label("cameraNear").setGroup(Zn).onRenderUpdate((({camera:e})=>e.near)),Au=ti("float").label("cameraFar").setGroup(Zn).onRenderUpdate((({camera:e})=>e.far)),Ru=ti("mat4").label("cameraProjectionMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=ti("mat4").label("cameraProjectionMatrixInverse").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=ti("mat4").label("cameraViewMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=ti("mat4").label("cameraWorldMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=ti("mat3").label("cameraNormalMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=ti(new s).label("cameraPosition").setGroup(Zn).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new ei(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,n=this.scope;if(n===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(n===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(n===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(n===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(n===Uu.VIEW_POSITION){const n=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(n.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=mn(Uu,Uu.DIRECTION),Pu=mn(Uu,Uu.WORLD_MATRIX),Iu=mn(Uu,Uu.POSITION),Lu=mn(Uu,Uu.SCALE),Du=mn(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=fn(Vu,Vu.DIRECTION),Gu=fn(Vu,Vu.WORLD_MATRIX),ku=fn(Vu,Vu.POSITION),zu=fn(Vu,Vu.SCALE),$u=fn(Vu,Vu.VIEW_POSITION),Hu=ti(new n).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=ti(new i).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=yn((e=>(e.context.isHighPrecisionModelViewMatrix=!0,ti("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=yn((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return ti("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=fn(sl),nl=Sn(rl).mul(2).sub(1),il=gu("normal","vec3"),ol=yn((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Un(0,1,0)):il),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=yn((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=yn((e=>e.context.setupNormal()),"vec3").once()().mul(nl).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=yn((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(nl).toVar("transformedClearcoatNormalView"),pl=yn((([e,t=Gu])=>{const s=kn(t),r=e.div(Un(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=yn((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=ti(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Un(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Un(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=mn(Tl);class Nl extends ei{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const vl=(e,t,s)=>hn(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;shn(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),hn(new Al(e,t)));class El extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return hn(new El(this,hn(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):ti(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new wl(e,t,s)),Bl=(e,t,s,r)=>hn(new wl(e,t,r,s));class Ul extends wl{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>hn(new Ul(e,t,s)),Pl=yn((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ln(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(il.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=kn(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xi.cross(tl);return e=e.cross(xi).normalize(),e=la(e,dl,yi.mul(ai.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=yn((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:n}=e,i=t.dFdx(),o=t.dFdy(),a=n.dFdx(),u=n.dFdy(),l=s,d=o.cross(l),c=l.cross(i),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=nl.mul(g.inverseSqrt());return Vi(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Un(r.xy.mul(s),r.z));let n=null;if(t===S)n=gl(r);else if(t===v){n=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return n}}const Jl=mn(Zl),ed=yn((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=Sn(s((e=>e)));return En(Sn(s((e=>e.add(e.dFdx())))).sub(r),Sn(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=yn((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,n=t.dFdx().normalize(),i=s,o=t.dFdy().normalize().cross(i),a=i.cross(n),u=n.dot(o).mul(nl),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=mn(sd),nd=new Map;class id extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=nd.get(e);return void 0===s&&(s=Fl(e,t),nd.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===id.COLOR){const e=void 0!==t.color?this.getColor(s):Un();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===id.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===id.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:Sn(1);else if(s===id.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===id.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===id.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===id.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===id.EMISSIVE){const e=this.getFloat("emissiveIntensity"),n=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?n.mul(this.getTexture(s)):n}else if(s===id.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===id.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===id.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===id.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===id.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Gn($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(En(1)).normalize().mul(e.b))}else r=$d;else if(s===id.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const n=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(n).mul(this.getTexture(s).g).add(n)}else r=e}else if(s===id.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===id.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===id.IOR)r=this.getFloat(s);else if(s===id.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===id.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}id.ALPHA_TEST="alphaTest",id.COLOR="color",id.OPACITY="opacity",id.SHININESS="shininess",id.SPECULAR="specular",id.SPECULAR_STRENGTH="specularStrength",id.SPECULAR_INTENSITY="specularIntensity",id.SPECULAR_COLOR="specularColor",id.REFLECTIVITY="reflectivity",id.ROUGHNESS="roughness",id.METALNESS="metalness",id.NORMAL="normal",id.CLEARCOAT="clearcoat",id.CLEARCOAT_ROUGHNESS="clearcoatRoughness",id.CLEARCOAT_NORMAL="clearcoatNormal",id.EMISSIVE="emissive",id.ROTATION="rotation",id.SHEEN="sheen",id.SHEEN_ROUGHNESS="sheenRoughness",id.ANISOTROPY="anisotropy",id.IRIDESCENCE="iridescence",id.IRIDESCENCE_IOR="iridescenceIOR",id.IRIDESCENCE_THICKNESS="iridescenceThickness",id.IOR="ior",id.TRANSMISSION="transmission",id.THICKNESS="thickness",id.ATTENUATION_DISTANCE="attenuationDistance",id.ATTENUATION_COLOR="attenuationColor",id.LINE_SCALE="scale",id.LINE_DASH_SIZE="dashSize",id.LINE_GAP_SIZE="gapSize",id.LINE_WIDTH="linewidth",id.LINE_DASH_OFFSET="dashOffset",id.POINT_WIDTH="pointWidth",id.DISPERSION="dispersion",id.LIGHT_MAP="light",id.AO_MAP="ao";const od=fn(id,id.ALPHA_TEST),ad=fn(id,id.COLOR),ud=fn(id,id.SHININESS),ld=fn(id,id.EMISSIVE),dd=fn(id,id.OPACITY),cd=fn(id,id.SPECULAR),hd=fn(id,id.SPECULAR_INTENSITY),pd=fn(id,id.SPECULAR_COLOR),gd=fn(id,id.SPECULAR_STRENGTH),md=fn(id,id.REFLECTIVITY),fd=fn(id,id.ROUGHNESS),yd=fn(id,id.METALNESS),bd=fn(id,id.NORMAL).context({getUV:null}),xd=fn(id,id.CLEARCOAT),Td=fn(id,id.CLEARCOAT_ROUGHNESS),_d=fn(id,id.CLEARCOAT_NORMAL).context({getUV:null}),Nd=fn(id,id.ROTATION),vd=fn(id,id.SHEEN),Sd=fn(id,id.SHEEN_ROUGHNESS),Ad=fn(id,id.ANISOTROPY),Rd=fn(id,id.IRIDESCENCE),Cd=fn(id,id.IRIDESCENCE_IOR),Ed=fn(id,id.IRIDESCENCE_THICKNESS),wd=fn(id,id.TRANSMISSION),Md=fn(id,id.THICKNESS),Bd=fn(id,id.IOR),Ud=fn(id,id.ATTENUATION_DISTANCE),Fd=fn(id,id.ATTENUATION_COLOR),Pd=fn(id,id.LINE_SCALE),Id=fn(id,id.LINE_DASH_SIZE),Ld=fn(id,id.LINE_GAP_SIZE),Dd=fn(id,id.LINE_WIDTH),Vd=fn(id,id.LINE_DASH_OFFSET),Od=fn(id,id.POINT_WIDTH),Gd=fn(id,id.DISPERSION),kd=fn(id,id.LIGHT_MAP),zd=fn(id,id.AO_MAP),$d=ti(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=mn(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,n;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)n=r;else{n=Ea(this).build(e,t)}return n}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=fn(jd,jd.VERTEX),Kd=fn(jd,jd.INSTANCE),Xd=fn(jd,jd.SUBGROUP),Yd=fn(jd,jd.INVOCATION_SUBGROUP),Qd=fn(jd,jd.INVOCATION_LOCAL),Zd=fn(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,n=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=zn(...n)}this.instanceMatrixNode=t}const n=r.instanceColor;if(n&&null===s){const e=new R(n.array,3),t=n.usage===p?Ya:Xa;this.bufferColor=e,s=Un(t(e,"vec3",3,0)),this.instanceColorNode=s}const i=t.mul(Yu).xyz;if(Yu.assign(i),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&ni("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=mn(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=yn((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=An(e).modInt(An(t)),r=An(e).div(An(t));return Nu(this.batchMesh._indirectTexture,wn(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(An(this.batchingIdNode)),r=this.batchMesh._matricesTexture,n=yu(Nu(r),0),i=Sn(s).mul(4).toInt().toVar(),o=i.modInt(n),a=i.div(An(n)),u=zn(Nu(r,wn(o,a)),Nu(r,wn(o.add(1),a)),Nu(r,wn(o.add(2),a)),Nu(r,wn(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=yn((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),n=s.div(t);return Nu(l,wn(r,n)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);ni("vec3","vBatchColor").assign(t)}const d=kn(u);Yu.assign(u.mul(Yu));const c=ol.div(Un(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=mn(tc),rc=new WeakMap;class nc extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,n;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),n=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=ti(e.bindMatrix,"mat4"),r=ti(e.bindMatrixInverse,"mat4"),n=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=n,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=n.mul(t),c=Vi(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return i.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vi(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=i.mul(d).mul(n),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const ic=e=>hn(new nc(e)),oc=e=>hn(new nc(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;eNumber(i)?">=":"<"));const d={start:n,end:i,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const n=r.build(e,"void"),i=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+n);for(let t=0,s=this.params.length-1;thn(new ac(gn(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=yn((({bufferMap:e,influence:t,stride:s,width:r,depth:n,offset:i})=>{const o=An(qd).mul(s).add(i),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,wn(u,a)).depth(n).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=ti(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,n=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,i=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==i?i.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,n=void 0!==e.morphAttributes.color,i=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==i?i.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===n&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=Sn(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,wn(An(e).add(1),An(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(0)})),!0===n&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=mn(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Un().toVar("directDiffuse"),directSpecular:Un().toVar("directSpecular"),indirectDiffuse:Un().toVar("indirectDiffuse"),indirectSpecular:Un().toVar("indirectSpecular")};return{radiance:Un().toVar("radiance"),irradiance:Un().toVar("irradiance"),iblIrradiance:Un().toVar("iblIrradiance"),ambientOcclusion:Sn(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Tc=mn(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?ti(Nc||(Nc=new t)):e===Sc.VIEWPORT?ti(vc||(vc=new r)):En(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=fn(Sc,Sc.UV),Rc=fn(Sc,Sc.SIZE),Cc=fn(Sc,Sc.COORDINATE),Ec=fn(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=yn((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=yn((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=yn((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=mn(Lc),Vc=mn(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=mn(Gc);class zc extends Ar{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Xc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.negate().div(t)),n=To(s.div(t));return r.div(n)},Kc=(e,t,s)=>{const r=e.mul(xo(s.div(t)));return Sn(Math.E).pow(r).mul(t).negate()},Xc=mn(zc,zc.DEPTH_BASE),Yc=fn(zc,zc.DEPTH),Qc=mn(zc,zc.LINEAR_DEPTH),Zc=Qc(kc());Yc.assign=e=>Xc(e);const Jc=mn(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class eh extends Ar{static get type(){return"ClippingNode"}constructor(e=eh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===eh.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===eh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return yn((()=>{const s=Sn().toVar("distanceToPlane"),r=Sn().toVar("distanceToGradient"),n=Sn(1).toVar("clipOpacity"),i=t.length;if(!this.hardwareClipping&&i>0){const e=Rl(t);uc(i,(({i:t})=>{const i=e.element(t);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),i=Sn(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const n=t.element(e);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s).oneMinus())})),n.mulAssign(i.oneMinus())}ii.a.mulAssign(n),ii.a.equal(0).discard()}))()}setupDefault(e,t){return yn((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Cn(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),yn((()=>{const r=Rl(e),n=Jc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();n.element(e).assign(s)}))}))()}}eh.ALPHA_TO_COVERAGE="alphaToCoverage",eh.DEFAULT="default",eh.HARDWARE="hardware";const th=yn((([e])=>Ro(Gi(1e4,Co(Gi(17,e.x).add(Gi(.1,e.y)))).mul(Vi(.1,Fo(Co(Gi(13,e.y).add(e.x)))))))),sh=yn((([e])=>th(En(th(e.xy),e.z)))),rh=yn((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=Sn(1).div(Sn(.05).mul(t)).toVar("pixScale"),r=En(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),n=En(sh(vo(r.x.mul(e.xyz))),sh(vo(r.y.mul(e.xyz)))).toVar("alpha"),i=Ro(To(s)).toVar("lerpFactor"),o=Vi(Gi(i.oneMinus(),n.x),Gi(i,n.y)).toVar("x"),a=qo(i,i.oneMinus()).toVar("a"),u=Un(o.mul(o).div(Gi(2,a).mul(Oi(1,a))),o.sub(Gi(.5,a)).div(Oi(1,a)),Oi(1,Oi(1,o).mul(Oi(1,o)).div(Gi(2,a).mul(Oi(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class nh extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new ir(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const n=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const i=this.setupLighting(e);null!==n&&e.stack.add(n);const o=Ln(i,ii.a).max(0);if(r=this.setupOutput(e,o),vi.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ln(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=hn(new eh(eh.ALPHA_TO_COVERAGE)):e.stack.add(hn(new eh))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(hn(new eh(eh.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(el.z,Su,Au):$c(el.z,Su,Au))}null!==r&&Yc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ln(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ln(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=ni("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=ni("vec3","vBatchColor").mul(s)}ii.assign(s);const r=this.opacityNode?Sn(this.opacityNode):dd;if(ii.a.assign(ii.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?Sn(this.alphaTestNode):od;ii.a.lessThanEqual(e).discard()}!0===this.alphaHash&&ii.a.lessThan(rh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&ii.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Un(0):ii.rgb}setupNormal(){return this.normalNode?Un(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:n}=this,i=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(i&&i.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(i,t,s,r)}else null!==s&&(o=Un(null!==r?la(o,s,r):s));return(n&&!0===n.isNode||t.emissive&&!0===t.emissive.isColor)&&(oi.assign(Un(n||ld)),o=o.add(oi)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ln(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:n}of r)s.inputNodes[t]=n.toJSON(e).uuid;function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=n(e.textures),r=n(e.images),i=n(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),i.length>0&&(s.nodes=i)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const ih=new P;class oh extends nh{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(ih),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=yn((()=>{const e=gu("instancePosition").xyz,t=Ln(ju.mul(Ln(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),n=Xu.xy.toVar();return n.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),n.assign(n.div(Ec.z)),n.y.assign(n.y.mul(s)),n.assign(n.mul(r.w)),r.addAssign(Ln(n,0,0)),r}))(),this.fragmentNode=yn((()=>{const r=Sn(1).toVar(),n=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=Sn(n.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),n).oneMinus())}else n.greaterThan(1).discard();let i;if(this.pointColorNode)i=this.pointColorNode;else if(s){i=gu("instanceColor").mul(ad)}else i=ad;return r.mulAssign(dd),Ln(i,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ah=new I;class uh extends nh{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(ah),this.setValues(e)}}const lh=new L;class dh extends nh{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(lh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?Sn(this.offsetNodeNode):Vd,t=this.dashScaleNode?Sn(this.dashScaleNode):Pd,s=this.dashSizeNode?Sn(this.dashSizeNode):Id,r=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(s),Ai.assign(r);const n=Ea(gu("lineDistance").mul(t));(e?n.add(e):n).mod(Si.add(Ai)).greaterThan(Si).discard()}}const ch=new L;class hh extends nh{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ch),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,n=this.worldUnits,i=yn((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ln(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=yn((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ln(ju.mul(Ln(e,1))).toVar("start"),o=Ln(ju.mul(Ln(t,1))).toVar("end");if(r){const e=this.dashScaleNode?Sn(this.dashScaleNode):Pd,t=this.offsetNode?Sn(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let n=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));n=n.add(t),ni("float","lineDistance").assign(n)}n&&(ni("vec3","worldStart").assign(s.xyz),ni("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);_n(u,(()=>{_n(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(i({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(i({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ln().toVar();if(n){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),n=e.cross(t).normalize(),i=e.cross(n),a=ni("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ln(Xu.x.lessThan(0).select(n.mul(u),n.mul(u).negate()),0)),r||(a.addAssign(Ln(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ln(i.mul(u),0)),_n(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ln(i.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Un().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=En(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),_n(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ln(e,0,0)))}return g}))();const o=yn((({p1:e,p2:t,p3:s,p4:r})=>{const n=e.sub(s),i=r.sub(s),o=t.sub(e),a=n.dot(i),u=i.dot(o),l=n.dot(o),d=i.dot(i),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return En(h,p)}));this.fragmentNode=yn((()=>{const i=mu();if(r){const e=this.dashSizeNode?Sn(this.dashSizeNode):Id,t=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(e),Ai.assign(t);const s=ni("float","lineDistance");i.y.lessThan(-1).or(i.y.greaterThan(1)).discard(),s.mod(Si.add(Ai)).greaterThan(Si).discard()}const a=Sn(1).toVar("alpha");if(n){const s=ni("vec3","worldStart"),n=ni("vec3","worldEnd"),i=ni("vec4","worldPos").xyz.normalize().mul(1e5),u=n.sub(s),l=o({p1:s,p2:n,p3:Un(0,0,0),p4:i}),d=s.add(u.mul(l.x)),c=i.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1)),s=e.mul(e).add(t.mul(t)),r=Sn(s.fwidth()).toVar("dlen");_n(i.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else _n(i.y.abs().greaterThan(1),(()=>{const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ln(u,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ph=e=>hn(e).mul(.5).add(.5),gh=e=>hn(e).mul(2).sub(1),mh=new D;class fh extends nh{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(mh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?Sn(this.opacityNode):dd;ii.assign(Ln(ph(dl),e))}}class yh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return En(t,s)}}const bh=mn(yh);class xh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n=new O(5,5,5),i=bh(Ju),o=new nh;o.colorNode=_u(t,i,0),o.side=x,o.blending=G;const a=new k(n,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const Th=new WeakMap;class _h extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(Th.has(e)){const t=Th.get(e);vh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new xh(s.height);r.fromEquirectangularTexture(t,e),vh(r.texture,e.mapping),this._cubeTexture=r.texture,Th.set(e,r.texture),e.addEventListener("dispose",Nh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Nh(e){const t=e.target;t.removeEventListener("dispose",Nh);const s=Th.get(t);void 0!==s&&(Th.delete(t),s.dispose())}function vh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const Sh=mn(_h);class Ah extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Sh(this.envNode)}}class Rh extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=Sn(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ch{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Eh extends Ch{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,n=e.reflectedLight,i=s.context.irradianceLightMap;n.indirectDiffuse.assign(Ln(0)),i?n.indirectDiffuse.addAssign(i):n.indirectDiffuse.addAssign(Ln(1,1,1,0)),n.indirectDiffuse.mulAssign(r),n.indirectDiffuse.mulAssign(ii.rgb)}finish(e,t,s){const r=s.material,n=e.outgoingLight,i=s.context.environment;if(i)switch(r.combine){case Y:n.rgb.assign(la(n.rgb,n.rgb.mul(i.rgb),gd.mul(md)));break;case X:n.rgb.assign(la(n.rgb,i.rgb,gd.mul(md)));break;case K:n.rgb.addAssign(i.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const wh=new Q;class Mh extends nh{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Rh(kd)),t}setupOutgoingLight(){return ii.rgb}setupLightingModel(){return new Eh}}const Bh=yn((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Uh=yn((e=>e.diffuseColor.mul(1/Math.PI))),Fh=yn((({dotNH:e})=>Ni.mul(Sn(.5)).add(1).mul(Sn(1/Math.PI)).mul(e.pow(Ni)))),Ph=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),n=Bh({f0:Ti,f90:1,dotVH:r}),i=Sn(.25),o=Fh({dotNH:s});return n.mul(i).mul(o)}));class Ih extends Eh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Ph({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const Lh=new Z;class Dh extends nh{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih(!1)}}const Vh=new J;class Oh extends nh{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Vh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih}setupVariants(){const e=(this.shininessNode?Sn(this.shininessNode):ud).max(1e-4);Ni.assign(e);const t=this.specularNode||cd;Ti.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Gh=yn((e=>{if(!1===e.geometry.hasAttribute("normal"))return Sn(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),kh=yn((e=>{const{roughness:t}=e,s=Gh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),zh=yn((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),n=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),i=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return ki(.5,n.add(i).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),$h=yn((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:n,dotBL:i,dotNV:o,dotNL:a})=>{const u=a.mul(Un(e.mul(s),t.mul(r),o).length()),l=o.mul(Un(e.mul(n),t.mul(i),a).length());return ki(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hh=yn((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Wh=Sn(1/Math.PI),jh=yn((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:n})=>{const i=e.mul(t),o=Un(t.mul(r),e.mul(n),i.mul(s)),a=o.dot(o),u=i.div(a);return Wh.mul(i.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),qh=yn((e=>{const{lightDirection:t,f0:s,f90:r,roughness:n,f:i,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=n.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Bh({f0:s,f90:r,dotVH:g});if(ln(o)&&(y=pi.mix(y,i)),ln(a)){const e=bi.dot(t),s=bi.dot(tl),r=bi.dot(d),n=xi.dot(t),i=xi.dot(tl),o=xi.dot(d);m=$h({alphaT:fi,alphaB:l,dotTV:s,dotBV:i,dotTL:e,dotBL:n,dotNV:h,dotNL:c}),f=jh({alphaT:fi,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=zh({alpha:l,dotNL:c,dotNV:h}),f=Hh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),Kh=yn((({roughness:e,dotNV:t})=>{const s=Ln(-1,-.0275,-.572,.022),r=Ln(1,.0425,1.04,-.04),n=e.mul(s).add(r),i=n.x.mul(n.x).min(t.mul(-9.28).exp2()).mul(n.x).add(n.y);return En(-1.04,1.04).mul(i).add(n.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xh=yn((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:n}=e,i=Kh({dotNV:t,roughness:n});return s.mul(i.x).add(r.mul(i.y))})),Yh=yn((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),n=r.mul(r),i=r.mul(n,n).clamp(0,.9999);return e.sub(Un(t).mul(i)).div(i.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qh=yn((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=Sn(1).div(s),n=t.pow2().oneMinus().max(.0078125);return Sn(2).add(r).mul(n.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Zh=yn((({dotNV:e,dotNL:t})=>Sn(1).div(Sn(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Jh=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),n=dl.dot(t).clamp(),i=Qh({roughness:hi,dotNH:n}),o=Zh({dotNV:r,dotNL:s});return ci.mul(i).mul(o)})),ep=yn((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),n=En(s,r.oneMinus().sqrt());return n.assign(n.mul(.984375).add(.0078125)),n})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),tp=yn((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sp=yn((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),n=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),i=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=n.div(i),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),rp=yn((({N:e,V:t,P:s,mInv:r,p0:n,p1:i,p2:o,p3:a})=>{const u=i.sub(n).toVar(),l=a.sub(n).toVar(),d=u.cross(l),c=Un().toVar();return _n(d.dot(s.sub(n)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(kn(u,l,e).transpose()).toVar(),h=d.mul(n.sub(s)).normalize().toVar(),p=d.mul(i.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Un(0).toVar();f.addAssign(sp({v1:h,v2:p})),f.addAssign(sp({v1:p,v2:g})),f.addAssign(sp({v1:g,v2:m})),f.addAssign(sp({v1:m,v2:h})),c.assign(Un(tp({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),np=1/6,ip=e=>Gi(np,Gi(e,Gi(e,e.negate().add(3)).sub(3)).add(1)),op=e=>Gi(np,Gi(e,Gi(e,Gi(3,e).sub(6))).add(4)),ap=e=>Gi(np,Gi(e,Gi(e,Gi(-3,e).add(3)).add(3)).add(1)),up=e=>Gi(np,sa(e,3)),lp=e=>ip(e).add(op(e)),dp=e=>ap(e).add(up(e)),cp=e=>Vi(-1,op(e).div(ip(e).add(op(e)))),hp=e=>Vi(1,up(e).div(ap(e).add(up(e)))),pp=(e,t,s)=>{const r=e.uvNode,n=Gi(r,t.zw).add(.5),i=vo(n),o=Ro(n),a=lp(o.x),u=dp(o.x),l=cp(o.x),d=hp(o.x),c=cp(o.y),h=hp(o.y),p=En(i.x.add(l),i.y.add(c)).sub(.5).mul(t.xy),g=En(i.x.add(d),i.y.add(c)).sub(.5).mul(t.xy),m=En(i.x.add(l),i.y.add(h)).sub(.5).mul(t.xy),f=En(i.x.add(d),i.y.add(h)).sub(.5).mul(t.xy),y=lp(o.y).mul(Vi(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=dp(o.y).mul(Vi(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},gp=yn((([e,t=Sn(3)])=>{const s=En(e.size(An(t))),r=En(e.size(An(t.add(1)))),n=ki(1,s),i=ki(1,r),o=pp(e,Ln(n,s),vo(t)),a=pp(e,Ln(i,r),So(t));return Ro(t).mix(o,a)})),mp=yn((([e,t,s,r,n])=>{const i=Un(ha(t.negate(),Ao(e),ki(1,r))),o=Un(Io(n[0].xyz),Io(n[1].xyz),Io(n[2].xyz));return Ao(i).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),fp=yn((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),yp=Vc(),bp=Vc(),xp=yn((([e,t,s],{material:r})=>{const n=(r.side==x?yp:bp).uv(e),i=To(Rc.x).mul(fp(t,s));return gp(n,i)})),Tp=yn((([e,t,s])=>(_n(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Un(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),_p=yn((([e,t,s,r,n,i,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ln().toVar(),f=Un().toVar();const n=d.sub(1).mul(g.mul(.025)),i=Un(d.sub(n),d,d.add(n));uc({start:0,end:3},(({i:n})=>{const d=i.element(n),g=mp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ln(y,1))),x=En(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(En(x.x,x.y.oneMinus()));const T=xp(x,s,d);m.element(n).assign(T.element(n)),m.a.addAssign(T.a),f.element(n).assign(r.element(n).mul(Tp(Io(g),h,p).element(n)))})),m.a.divAssign(3)}else{const n=mp(e,t,c,d,a),i=o.add(n),g=l.mul(u.mul(Ln(i,1))),y=En(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(En(y.x,y.y.oneMinus())),m=xp(y,s,d),f=r.mul(Tp(Io(n),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Un(Xh({dotNV:b,specularColor:n,specularF90:i,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ln(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),Np=kn(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),vp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Sp=yn((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:n})=>{const i=la(e,t,pa(0,.03,r)),o=e.div(i).pow2().mul(s.pow2().oneMinus()).oneMinus();_n(o.lessThan(0),(()=>Un(1)));const a=o.sqrt(),u=vp(i,e),l=Bh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=i.lessThan(e).select(Math.PI,0),h=Sn(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Un(1).add(t).div(Un(1).sub(t))})(n.clamp(0,.9999)),g=vp(p,i.toVec3()),m=Bh({f0:g,f90:1,dotVH:a}),f=Un(p.x.lessThan(i).select(Math.PI,0),p.y.lessThan(i).select(Math.PI,0),p.z.lessThan(i).select(Math.PI,0)),y=i.mul(r,a,2),b=Un(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Un(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Un(54856e-17,44201e-17,52481e-17),n=Un(1681e3,1795300,2208400),i=Un(43278e5,93046e5,66121e5),o=Sn(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(i.mul(2*Math.PI).sqrt()).mul(n.mul(s).add(t).cos()).mul(s.pow2().negate().mul(i).exp());return a=Un(a.x.add(o),a.y,a.z).div(1.0685e-7),Np.mul(a)})(Sn(e).mul(y),Sn(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Un(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Ap=yn((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),n=s.pow2(),i=xa(s.lessThan(.25),Sn(-339.2).mul(n).add(Sn(161.4).mul(s)).sub(25.9),Sn(-8.48).mul(n).add(Sn(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),Sn(44).mul(n).sub(Sn(23.7).mul(s)).add(3.26),Sn(1.97).mul(n).sub(Sn(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,Sn(.1).mul(s).sub(.025)).add(i.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Rp=Un(.04),Cp=Sn(1);class Ep extends Ch{constructor(e=!1,t=!1,s=!1,r=!1,n=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=n,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Un().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Un().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Un().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Un().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Un().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=Sp({outsideIOR:Sn(1),eta2:gi,cosTheta1:e,thinFilmThickness:mi,baseF0:Ti}),this.iridescenceF0=Yh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=_p(r,s,ai,ii,Ti,_i,t,Gu,Eu,Ru,Ci,wi,Bi,Mi,this.dispersion?Ui:null),e.backdropAlpha=Ei,ii.a.mulAssign(la(1,e.backdrop.a,Ei))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),n=Kh({roughness:ai,dotNV:r}),i=(this.iridescenceF0?pi.mix(Ti,this.iridescenceF0):Ti).mul(n.x).add(s.mul(n.y)),o=n.x.add(n.y).oneMinus(),a=Ti.add(Ti.oneMinus().mul(.047619)),u=i.mul(a).div(o.mul(a).oneMinus());e.addAssign(i),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Jh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(qh({lightDirection:e,f0:Rp,f90:Cp,roughness:di,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),s.directSpecular.addAssign(r.mul(qh({lightDirection:e,f0:Ti,f90:1,roughness:ai,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:n,ltc_1:i,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=ep({N:c,V:h,roughness:ai}),m=i.uv(g).toVar(),f=o.uv(g).toVar(),y=kn(Un(m.x,0,m.y),Un(0,1,0),Un(m.z,0,m.w)).toVar(),b=Ti.mul(f.x).add(Ti.oneMinus().mul(f.y)).toVar();n.directSpecular.addAssign(e.mul(b).mul(rp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),n.directDiffuse.addAssign(e.mul(ii).mul(rp({N:c,V:h,P:p,mInv:kn(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Uh({diffuseColor:ii})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(ci,Ap({normal:dl,viewDir:tl,roughness:hi}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Xh({dotNV:e,specularColor:Rp,specularF90:Cp,roughness:di});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Un().toVar("singleScattering"),n=Un().toVar("multiScattering"),i=t.mul(1/Math.PI);this.computeMultiscattering(r,n,_i);const o=r.add(n),a=ii.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(n.mul(i)),s.indirectDiffuse.addAssign(a.mul(i))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=ai.mul(-16).oneMinus().negate().exp2(),n=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(n)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Bh({dotVH:e,f0:Rp,f90:Cp}),r=t.mul(li.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(li));t.assign(r)}if(!0===this.sheen){const e=ci.r.max(ci.g).max(ci.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const wp=Sn(1),Mp=Sn(-2),Bp=Sn(.8),Up=Sn(-1),Fp=Sn(.4),Pp=Sn(2),Ip=Sn(.305),Lp=Sn(3),Dp=Sn(.21),Vp=Sn(4),Op=Sn(4),Gp=Sn(16),kp=yn((([e])=>{const t=Un(Fo(e)).toVar(),s=Sn(-1).toVar();return _n(t.x.greaterThan(t.z),(()=>{_n(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{_n(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),zp=yn((([e,t])=>{const s=En().toVar();return _n(t.equal(0),(()=>{s.assign(En(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(En(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(En(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(En(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(En(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(En(e.x,e.y).div(Fo(e.z)))})),Gi(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$p=yn((([e])=>{const t=Sn(0).toVar();return _n(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).ElseIf(e.greaterThanEqual(Fp),(()=>{t.assign(Bp.sub(e).mul(Pp.sub(Up)).div(Bp.sub(Fp)).add(Up))})).ElseIf(e.greaterThanEqual(Ip),(()=>{t.assign(Fp.sub(e).mul(Lp.sub(Pp)).div(Fp.sub(Ip)).add(Pp))})).ElseIf(e.greaterThanEqual(Dp),(()=>{t.assign(Ip.sub(e).mul(Vp.sub(Lp)).div(Ip.sub(Dp)).add(Lp))})).Else((()=>{t.assign(Sn(-2).mul(To(Gi(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Hp=yn((([e,t])=>{const s=e.toVar();s.assign(Gi(2,s).sub(1));const r=Un(s,1).toVar();return _n(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Wp=yn((([e,t,s,r,n,i])=>{const o=Sn(s),a=Un(t),u=da($p(o),Mp,i),l=Ro(u),d=vo(u),c=Un(jp(e,a,d,r,n,i)).toVar();return _n(l.notEqual(0),(()=>{const t=Un(jp(e,a,d.add(1),r,n,i)).toVar();c.assign(la(c,t,l))})),c})),jp=yn((([e,t,s,r,n,i])=>{const o=Sn(s).toVar(),a=Un(t),u=Sn(kp(a)).toVar(),l=Sn(Ko(Op.sub(o),0)).toVar();o.assign(Ko(o,Op));const d=Sn(bo(o)).toVar(),c=En(zp(a,u).mul(d.sub(2)).add(1)).toVar();return _n(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gi(3,Gp))),c.y.addAssign(Gi(4,bo(i).sub(d))),c.x.mulAssign(r),c.y.mulAssign(n),e.uv(c).grad(En(),En())})),qp=yn((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:n,CUBEUV_TEXEL_WIDTH:i,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(n.cross(s).mul(Co(r))).add(n.mul(n.dot(s).mul(u.oneMinus())));return jp(e,l,t,i,o,a)})),Kp=yn((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:n,samples:i,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Un(xa(t,s,ta(s,r))).toVar();_n(ho(h.equals(Un(0))),(()=>{h.assign(Un(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Un().toVar();return p.addAssign(n.element(An(0)).mul(qp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:An(1),end:e},(({i:e})=>{_n(e.greaterThanEqual(i),(()=>{dc()}));const t=Sn(o.mul(Sn(e))).toVar();p.addAssign(n.element(e).mul(qp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(n.element(e).mul(qp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ln(p,1)}));let Xp=null;const Yp=new WeakMap;function Qp(e){let t=Yp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r0}(s))return null;t=Xp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Yp.set(e,t)}return t.texture}class Zp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=ti(0),this._height=ti(0),this._maxMip=ti(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Qp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Xp&&(Xp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Un(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Wp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Jp=mn(Zp),eg=new WeakMap;class tg extends yc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let r=eg.get(e);void 0===r&&(r=Jp(e),eg.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),n=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,i=s.context(sg(ai,n)).mul(r),o=s.context(rg(cl)).mul(Math.PI).mul(r),a=eu(i),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(sg(di,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const sg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},rg=e=>({getUV:()=>e,getTextureLevel:()=>Sn(1)}),ng=new te;class ig extends nh{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ng),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new tg(t):null}setupLightingModel(){return new Ep}setupSpecular(){const e=la(Un(.04),ii.rgb,ui);Ti.assign(e),_i.assign(1)}setupVariants(){const e=this.metalnessNode?Sn(this.metalnessNode):yd;ui.assign(e);let t=this.roughnessNode?Sn(this.roughnessNode):fd;t=kh({roughness:t}),ai.assign(t),this.setupSpecular(),ii.assign(Ln(ii.rgb.mul(e.oneMinus()),ii.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const og=new se;class ag extends ig{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(og),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?Sn(this.iorNode):Bd;Ci.assign(e),Ti.assign(la(qo(ra(Ci.sub(1).div(Ci.add(1))).mul(pd),Un(1)).mul(hd),ii.rgb,ui)),_i.assign(la(hd,1,ui))}setupLightingModel(){return new Ep(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?Sn(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?Sn(this.clearcoatRoughnessNode):Td;li.assign(e),di.assign(kh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Un(this.sheenNode):vd,t=this.sheenRoughnessNode?Sn(this.sheenRoughnessNode):Sd;ci.assign(e),hi.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?Sn(this.iridescenceNode):Rd,t=this.iridescenceIORNode?Sn(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?Sn(this.iridescenceThicknessNode):Ed;pi.assign(e),gi.assign(t),mi.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?En(this.anisotropyNode):Ad).toVar();yi.assign(e.length()),_n(yi.equal(0),(()=>{e.assign(En(1,0))})).Else((()=>{e.divAssign(En(yi)),yi.assign(yi.saturate())})),fi.assign(yi.pow2().mix(ai.pow2(),1)),bi.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xi.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?Sn(this.transmissionNode):wd,t=this.thicknessNode?Sn(this.thicknessNode):Md,s=this.attenuationDistanceNode?Sn(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Un(this.attenuationColorNode):Fd;if(Ei.assign(e),wi.assign(t),Mi.assign(s),Bi.assign(r),this.useDispersion){const e=this.dispersionNode?Sn(this.dispersionNode):Gd;Ui.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Un(this.clearcoatNormalNode):_d}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class ug extends Ep{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){if(!0===this.useSSS){const r=n.material,{thicknessColorNode:i,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=Sn(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Un(h.add(a).mul(i));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n)}}class lg extends ag{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=Sn(.1),this.thicknessAmbientNode=Sn(0),this.thicknessAttenuationNode=Sn(.1),this.thicknessPowerNode=Sn(2),this.thicknessScaleNode=Sn(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ug(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const dg=yn((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),n=En(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>n});return Un(e.r)}{const e=n.fwidth().mul(.5);return la(Un(.7),Un(1),pa(Sn(.7).sub(e.x),Sn(.7).add(e.x),n.x))}}));class cg extends Ch{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){const i=dg({normal:il,lightDirection:e,builder:n}).mul(t);s.directDiffuse.addAssign(i.mul(Uh({diffuseColor:ii.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const hg=new re;class pg extends nh{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(hg),this.setValues(e)}setupLightingModel(){return new cg}}class gg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Un(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return En(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const mg=fn(gg),fg=new ne;class yg extends nh{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(fg),this.setValues(e)}setupVariants(e){const t=mg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Un(la(.2,.8,t.y)),ii.rgb.mulAssign(s.rgb)}}const bg=new P;class xg extends nh{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(bg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Tg extends Er{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Gn(e,r,r.negate(),e).mul(s)}{const e=t,r=zn(Ln(1,0,0,0),Ln(0,Eo(e.x),Co(e.x).negate(),0),Ln(0,Co(e.x),Eo(e.x),0),Ln(0,0,0,1)),n=zn(Ln(Eo(e.y),0,Co(e.y),0),Ln(0,1,0,0),Ln(Co(e.y).negate(),0,Eo(e.y),0),Ln(0,0,0,1)),i=zn(Ln(Eo(e.z),Co(e.z).negate(),0,0),Ln(Co(e.z),Eo(e.z),0,0),Ln(0,0,1,0),Ln(0,0,0,1));return r.mul(n).mul(i).mul(Ln(s,1)).xyz}}}const _g=mn(Tg),Ng=new ie;class vg extends nh{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Ng),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:n,rotationNode:i,scaleNode:o}=this,a=Yu;let u=ju.mul(Un(n||0)),l=En(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=Sn(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>hn(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=Sn(i||Nd),h=_g(d,c);u=Ln(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Sg extends Ch{constructor(){super(),this.shadowNode=Sn(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){ii.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(ii.rgb)}}const Ag=new oe;class Rg extends nh{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ag),this.setValues(e)}setupLightingModel(){return new Sg}}const Cg=yn((({texture:e,uv:t})=>{const s=1e-4,r=Un().toVar();return _n(t.x.lessThan(s),(()=>{r.assign(Un(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Un(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Un(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Un(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Un(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Un(0,0,-1))})).Else((()=>{const s=.01,n=e.uv(t.add(Un(-.01,0,0))).r.sub(e.uv(t.add(Un(s,0,0))).r),i=e.uv(t.add(Un(0,-.01,0))).r.sub(e.uv(t.add(Un(0,s,0))).r),o=e.uv(t.add(Un(0,0,-.01))).r.sub(e.uv(t.add(Un(0,0,s))).r);r.assign(Un(n,i,o))})),r.normalize()}));class Eg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Un(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Cg({texture:this,uv:e})}}const wg=mn(Eg);class Mg extends nh{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=wg(this.map,null,0),s=yn((({orig:e,dir:t})=>{const s=Un(-.5),r=Un(.5),n=t.reciprocal(),i=s.sub(e).mul(n),o=r.sub(e).mul(n),a=qo(i,o),u=Ko(i,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return En(l,d)}));this.fragmentNode=yn((()=>{const e=Ea(Un(Wu.mul(Ln(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),n=En(s({orig:e,dir:r})).toVar();n.x.greaterThan(n.y).discard(),n.assign(En(Ko(n.x,0),n.y));const i=Un(e.add(n.x.mul(r))).toVar(),o=Un(r.abs().reciprocal()).toVar(),a=Sn(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ln(Fl("base","color"),0).toVar();return uc({type:"float",start:n.x,end:n.y,update:"+= delta"},(()=>{const e=ri("float","d").assign(t.uv(i.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:i,finalColor:u}).append():(u.a.assign(1),dc()),i.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ln(u)}))(),super.setup(e)}}class Bg{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ug{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const n of e){const e=n.node&&n.node.attribute?n.node.attribute:t.getAttribute(n.name);if(void 0===e)continue;s.push(e);const i=e.isInterleavedBufferAttribute?e.data:e;r.add(i)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:n}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(i.instanceCount=u,!0===e.isBatchedMesh)return i;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=n.start*l,c=(n.start+n.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(i.vertexCount=g,i.firstVertex=d,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let n;if(null!==r){const e=typeof r;"number"===e?n=0!==r?"1":"0":"object"===e?(n="{",r.isTexture&&(n+=r.mapping),n+="}"):n=String(r)}else n=String(r);s+=n+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Ig=[];class Lg{constructor(e,t,s,r,n,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=n,this.info=i,this.chainMaps={}}get(e,t,s,r,n,i,o,a){const u=this.getChainMap(a);Ig[0]=e,Ig[1]=t,Ig[2]=i,Ig[3]=n;let l=u.get(Ig);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,n,i,o,a),u.set(Ig,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,n,i,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ug)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,n,i,o,a,u,l,d){const c=this.getChainMap(d),h=new Pg(e,t,s,r,n,i,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Dg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Vg=1,Og=2,Gg=3,kg=4,zg=16;class $g extends Dg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Vg?this.backend.createAttribute(e):t===Og?this.backend.createIndexAttribute(e):t===Gg?this.backend.createStorageAttribute(e):t===kg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return n.version=Hg(e),n}class jg extends Dg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,n=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of n)this.attributes.delete(e);const i=this.wireframes.get(t);void 0!==i&&this.attributes.delete(i),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Gg):this.updateAttribute(e,Vg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Og);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,kg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Wg(t),e.set(t,s)):s.version!==Hg(t)&&(this.attributes.delete(s),s=Wg(t),e.set(t,s)),r=s}return r}}class qg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Kg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Xg extends Kg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Yg extends Kg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Qg=0;class Zg{constructor(e,t,s=null,r=null){this.id=Qg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Jg extends Dg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let o=this.programs.compute.get(i.computeShader);void 0===o&&(n&&0===n.computeProgram.usedTimes&&this._releaseProgram(n.computeProgram),o=new Zg(i.computeShader,"compute",i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(n&&0===n.usedTimes&&this._releasePipeline(n),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState();let o=this.programs.vertex.get(i.vertexShader);void 0===o&&(n&&0===n.vertexProgram.usedTimes&&this._releaseProgram(n.vertexProgram),o=new Zg(i.vertexShader,"vertex"),this.programs.vertex.set(i.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(i.fragmentShader);void 0===a&&(n&&0===n.fragmentProgram.usedTimes&&this._releaseProgram(n.fragmentProgram),a=new Zg(i.fragmentShader,"fragment"),this.programs.fragment.set(i.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(n&&0===n.usedTimes&&this._releasePipeline(n),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return void 0===n&&(n=new Yg(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,r)),n}_getRenderPipeline(e,t,s,r,n){r=r||this._getRenderCacheKey(e,t,s);let i=this.caches.get(r);return void 0===i&&(i=new Xg(r,t,s),this.caches.set(r,i),e.pipeline=i,this.backend.createRenderPipeline(e,n)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class em extends Dg{constructor(e,t,s,r,n,i){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=r,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,s=e.isIndirectStorageBufferAttribute?kg:Gg;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1,n=!0,i=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(r=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=s.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?n=!1:(i=10*i+u.id,o+=u.version),!0===s.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,r),this.textures.updateTexture(u),r=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t,n?i:0,o)}}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function sm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function rm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class nm{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,n,i,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:n,group:i,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=n,a.group=i,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||tm),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||sm),this.transparent.length>1&&this.transparent.sort(t||sm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||n[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,n[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=i,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&n.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=dm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class hm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class pm extends si{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const gm=(e,t)=>hn(new pm(e,t));class mm extends Ar{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new cn(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new cn(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new cn(e),this}build(e,...t){const s=Tn();xn(this);for(const t of this.nodes)t.build(e,"void");return xn(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const fm=mn(mm);class ym extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}const bm=e=>Object.entries(e).map((([e,t])=>"string"==typeof t?{name:e,type:t,isAtomic:!1}:{name:e,type:t.type,isAtomic:t.atomic||!1}));class xm extends Ar{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let r=0;r{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),Am=(e,t)=>sa(Gi(4,e.mul(Oi(1,e))),t),Rm=(e,t)=>e.lessThan(.5)?Am(e.mul(2),t).div(2):Oi(1,Am(Gi(Oi(1,e),2),t).div(2)),Cm=(e,t,s)=>sa(ki(sa(e,t),Vi(sa(e,t),sa(Oi(1,e),s))),1/t),Em=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),wm=yn((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),Mm=yn((([e])=>Un(wm(e.z.add(wm(e.y.mul(1)))),wm(e.z.add(wm(e.x.mul(1)))),wm(e.y.add(wm(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Bm=yn((([e,t,s])=>{const r=Un(e).toVar(),n=Sn(1.4).toVar(),i=Sn(0).toVar(),o=Un(r).toVar();return uc({start:Sn(0),end:Sn(3),type:"float",condition:"<="},(()=>{const e=Un(Mm(o.mul(2))).toVar();r.addAssign(e.add(s.mul(Sn(.1).mul(t)))),o.mulAssign(1.8),n.mulAssign(1.5),r.mulAssign(1.2);const a=Sn(wm(r.z.add(wm(r.x.add(wm(r.y)))))).toVar();i.addAssign(a.div(n)),o.addAssign(.14)})),i})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Um extends Ar{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let r=null,n=-1;for(const s of this.functionNodes){const i=s.shaderNode.layout;if(null===i)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=i.inputs;if(t.length===o.length){let i=0;for(let s=0;sn&&(r=s,n=i)}}this._candidateFnCall=s=r(...t)}return s}}const Fm=mn(Um),Pm=e=>(...t)=>Fm(e,...t),Im=ti(0).setGroup(Zn).onRenderUpdate((e=>e.time)),Lm=ti(0).setGroup(Zn).onRenderUpdate((e=>e.deltaTime)),Dm=ti(0,"uint").setGroup(Zn).onRenderUpdate((e=>e.frameId)),Vm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Im.mul(e)),Om=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Im.mul(e)),Gm=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Lm.mul(e)),km=(e=Im)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),zm=(e=Im)=>e.fract().round(),$m=(e=Im)=>e.add(.5).fract().mul(2).sub(1).abs(),Hm=(e=Im)=>e.fract(),Wm=yn((([e,t,s=En(.5)])=>_g(e.sub(s),t).add(s))),jm=yn((([e,t,s=En(.5)])=>{const r=e.sub(s),n=r.dot(r),i=n.mul(n).mul(t);return e.add(r.mul(i))})),qm=yn((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const n=Eu.mul(r);return ln(t)&&(n[0][0]=Gu[0].length(),n[0][1]=0,n[0][2]=0),ln(s)&&(n[1][0]=0,n[1][1]=Gu[1].length(),n[1][2]=0),n[2][0]=0,n[2][1]=0,n[2][2]=1,Ru.mul(n).mul(Yu)})),Km=yn((([e=null])=>{const t=Qc();return Qc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class Xm extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=Sn(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:n}=s,i=e.mod(r.mul(n)).floor(),o=i.mod(r),a=n.sub(i.add(1).div(r).ceil()),u=s.reciprocal(),l=En(o,a);return t.add(l).mul(u)}}const Ym=mn(Xm);class Qm extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=Sn(1),n=Yu,i=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=n,this.normalNode=i}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:n,normalNode:i}=this;let o=i.abs().normalize();o=o.div(o.dot(Un(1)));const a=n.yz.mul(r),u=n.zx.mul(r),l=n.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vi(p,g,m)}}const Zm=mn(Qm),Jm=(...e)=>Zm(...e),ef=new me,tf=new s,sf=new s,rf=new s,nf=new i,of=new s(0,0,-1),af=new r,uf=new s,lf=new s,df=new r,cf=new t,hf=new ge,pf=Ac.flipX();hf.depthTexture=new B(1,1);let gf=!1;class mf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||hf.texture,pf),this._reflectorBaseNode=e.reflector||new ff(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=hn(new mf({defaultTexture:hf.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class ff extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:n=!1,bounces:i=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=n,this.bounces=i,this.depth=o,this.updateBeforeType=i?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(cf),e.setSize(Math.round(cf.width*s),Math.round(cf.height*s))}setup(e){return this._updateResolution(hf,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&gf)return;gf=!0;const{scene:t,camera:s,renderer:r,material:n}=e,{target:i}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(cf),this._updateResolution(a,r),sf.setFromMatrixPosition(i.matrixWorld),rf.setFromMatrixPosition(s.matrixWorld),nf.extractRotation(i.matrixWorld),tf.set(0,0,1),tf.applyMatrix4(nf),uf.subVectors(sf,rf),uf.dot(tf)>0)return;uf.reflect(tf).negate(),uf.add(sf),nf.extractRotation(s.matrixWorld),of.set(0,0,-1),of.applyMatrix4(nf),of.add(rf),lf.subVectors(sf,of),lf.reflect(tf).negate(),lf.add(sf),o.coordinateSystem=s.coordinateSystem,o.position.copy(uf),o.up.set(0,1,0),o.up.applyMatrix4(nf),o.up.reflect(tf),o.lookAt(lf),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),ef.setFromNormalAndCoplanarPoint(tf,sf),ef.applyMatrix4(o.matrixWorldInverse),af.set(ef.normal.x,ef.normal.y,ef.normal.z,ef.constant);const u=o.projectionMatrix;df.x=(Math.sign(af.x)+u.elements[8])/u.elements[0],df.y=(Math.sign(af.y)+u.elements[9])/u.elements[5],df.z=-1,df.w=(1+u.elements[10])/u.elements[14],af.multiplyScalar(1/af.dot(df));u.elements[2]=af.x,u.elements[6]=af.y,u.elements[10]=r.coordinateSystem===N?af.z-0:af.z+1-0,u.elements[14]=af.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),n.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),n.visible=!0,gf=!1}}const yf=e=>hn(new mf(e)),bf=new xe(-1,1,1,-1,0,1);class xf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const Tf=new xf;class _f extends k{constructor(e=null){super(Tf,e),this.camera=bf,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,bf)}render(e){e.render(this,bf)}}const Nf=new t;class vf extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const n=new ge(t,s,r);super(n.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=n,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new _f(new nh),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(Nf);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const Sf=(e,...t)=>hn(new vf(hn(e),...t)),Af=(e,...t)=>e.isTextureNode?e:Sf(e,...t),Rf=yn((([e,t,s],r)=>{let n;r.renderer.coordinateSystem===N?(e=En(e.x,e.y.oneMinus()).mul(2).sub(1),n=Ln(Un(e,t),1)):n=Ln(Un(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const i=Ln(s.mul(n));return i.xyz.div(i.w)})),Cf=yn((([e,t])=>{const s=t.mul(Ln(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return En(r.x,r.y.oneMinus())})),Ef=yn((([e,t,s])=>{const r=yu(Nu(t)),n=wn(e.mul(r)).toVar(),i=Nu(t,n).toVar(),o=Nu(t,n.sub(wn(2,0))).toVar(),a=Nu(t,n.sub(wn(1,0))).toVar(),u=Nu(t,n.add(wn(1,0))).toVar(),l=Nu(t,n.add(wn(2,0))).toVar(),d=Nu(t,n.add(wn(0,2))).toVar(),c=Nu(t,n.add(wn(0,1))).toVar(),h=Nu(t,n.sub(wn(0,1))).toVar(),p=Nu(t,n.sub(wn(0,2))).toVar(),g=Fo(Oi(Sn(2).mul(a).sub(o),i)).toVar(),m=Fo(Oi(Sn(2).mul(u).sub(l),i)).toVar(),f=Fo(Oi(Sn(2).mul(c).sub(d),i)).toVar(),y=Fo(Oi(Sn(2).mul(h).sub(p),i)).toVar(),b=Rf(e,i,s).toVar(),x=g.lessThan(m).select(b.sub(Rf(e.sub(En(Sn(1).div(r.x),0)),a,s)),b.negate().add(Rf(e.add(En(Sn(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Rf(e.add(En(0,Sn(1).div(r.y))),c,s)),b.negate().add(Rf(e.sub(En(0,Sn(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class wf extends pu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const Mf=(...e)=>hn(new wf(...e));class Bf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Uf=fn(Bf),Ff=new ve,Pf=new i;class If extends Ar{static get type(){return"SceneNode"}constructor(e=If.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===If.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===If.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===If.BACKGROUND_ROTATION?r=ti("mat4").label("backgroundRotation").setGroup(Zn).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Ff.copy(s.backgroundRotation),Ff.x*=-1,Ff.y*=-1,Ff.z*=-1,Pf.makeRotationFromEuler(Ff)):Pf.identity(),Pf})):console.error("THREE.SceneNode: Unknown scope:",t),r}}If.BACKGROUND_BLURRINESS="backgroundBlurriness",If.BACKGROUND_INTENSITY="backgroundIntensity",If.BACKGROUND_ROTATION="backgroundRotation";const Lf=fn(If,If.BACKGROUND_BLURRINESS),Df=fn(If,If.BACKGROUND_INTENSITY),Vf=fn(If,If.BACKGROUND_ROTATION);class Of extends Rr{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Gf=mn(Of),kf="point-list",zf="line-list",$f="line-strip",Hf="triangle-list",Wf="triangle-strip",jf="never",qf="less",Kf="equal",Xf="less-equal",Yf="greater",Qf="not-equal",Zf="greater-equal",Jf="always",ey="store",ty="load",sy="clear",ry="ccw",ny="none",iy="front",oy="back",ay="uint16",uy="uint32",ly={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},dy="clamp-to-edge",cy="repeat",hy="mirror-repeat",py="linear",gy="nearest",my="zero",fy="one",yy="src",by="one-minus-src",xy="src-alpha",Ty="one-minus-src-alpha",_y="dst",Ny="one-minus-dst",vy="dst-alpha",Sy="one-minus-dst-alpha",Ay="src-alpha-saturated",Ry="constant",Cy="one-minus-constant",Ey="add",wy="subtract",My="reverse-subtract",By="min",Uy="max",Fy=0,Py=15,Iy="keep",Ly="zero",Dy="replace",Vy="invert",Oy="increment-clamp",Gy="decrement-clamp",ky="increment-wrap",zy="decrement-wrap",$y="storage",Hy="read-only-storage",Wy="write-only",jy="read-only",qy="float",Ky="unfilterable-float",Xy="depth",Yy="sint",Qy="uint",Zy="2d",Jy="3d",eb="2d",tb="2d-array",sb="cube",rb="3d",nb="all",ib="vertex",ob="instance",ab={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class ub extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=$y,this.isAtomic=!1,this.bufferObject=!1,this.bufferStruct=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Gf(this,e)}setBufferObject(e){return this.bufferObject=e,this}setBufferStruct(e){return this.bufferStruct=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Hy)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),r=s.build(e);return e.registerTransform(r,t),r}}const lb=(e,t,s)=>hn(new ub(e,t,s)),db=(e,t,s)=>hn(new ub(e,t,s).setBufferStruct(!0)),cb=(e,t,s)=>hn(new ub(e,t,s).setBufferObject(!0));class hb extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Wy}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(jy)}toWriteOnly(){return this.setAccess(Wy)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,n=super.generate(e,"property"),i=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,n,i,o);e.addLineFlowCode(a,this)}}const pb=mn(hb),gb=(e,t,s)=>{const r=pb(e,t,s);return null!==s&&r.append(),r};class mb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const fb=(e,t,s)=>hn(new mb(e,t,s)),yb=new WeakMap;class bb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=ti(new i),this.previousProjectionMatrix=ti(new i).setGroup(Zn),this.previousCameraViewMatrix=ti(new i)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=Tb(s);this.previousModelWorldMatrix.value.copy(r);const n=xb(t);n.frameId!==e&&(n.frameId=e,void 0===n.previousProjectionMatrix?(n.previousProjectionMatrix=new i,n.previousCameraViewMatrix=new i,n.currentProjectionMatrix=new i,n.currentCameraViewMatrix=new i,n.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(n.previousProjectionMatrix.copy(n.currentProjectionMatrix),n.previousCameraViewMatrix.copy(n.currentCameraViewMatrix)),n.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(n.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(n.previousCameraViewMatrix))}updateAfter({object:e}){Tb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:ti(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),n=s.xy.div(s.w),i=r.xy.div(r.w);return Oi(n,i)}}function xb(e){let t=yb.get(e);return void 0===t&&(t={},yb.set(e,t)),t}function Tb(e,t=0){const s=xb(e);let r=s[t];return void 0===r&&(s[t]=r=new i),r}const _b=fn(bb),Nb=yn((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=yn((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Sb=yn((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Ab=yn((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Rb=yn((([e,t])=>Ln(e.rgb.mul(t.a.oneMinus()).add(t.rgb.mul(t.a)),e.a))).setLayout({name:"blendNormal",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Cb=yn((([e])=>Bb(e.rgb))),Eb=yn((([e,t=Sn(1)])=>t.mix(Bb(e.rgb),e.rgb))),wb=yn((([e,t=Sn(1)])=>{const s=Vi(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),n=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,n)})),Mb=yn((([e,t=Sn(1)])=>{const s=Un(.57735,.57735,.57735),r=t.cos();return Un(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),Bb=(e,t=Un(u.getLuminanceCoefficients(new s)))=>ea(e,t),Ub=(e,t)=>la(Un(0),e,Bb(e).sub(t).max(0)),Fb=yn((([e,t=Un(1),r=Un(0),n=Un(1),i=Sn(1),o=Un(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Un(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(n).toVar();return _n(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),_n(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),_n(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(i))),Ln(l.rgb,e.a)}));class Pb extends Er{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Ib=mn(Pb);let Lb=null;class Db extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Lb&&(Lb=new w),super(e,t,Lb)}updateReference(){return this}}const Vb=mn(Db),Ob=new t;class Gb extends Tu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class kb extends Gb{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class zb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const n=new B;n.isRenderTargetTexture=!0,n.name="depth";const i=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});i.texture.name="output",i.depthTexture=n,this.renderTarget=i,this.updateBeforeType=br.FRAME,this._textures={output:i.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=ti(0),this._cameraFar=ti(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=hn(new kb(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=hn(new kb(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(n,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===zb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const n=t.getSize(Ob);this.setSize(n.width,n.height);const i=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(i),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}zb.COLOR="color",zb.DEPTH="depth";const $b=(e,t,s)=>hn(new zb(zb.COLOR,e,t,s)),Hb=(e,t)=>hn(new Gb(e,t)),Wb=(e,t)=>hn(new zb(zb.DEPTH,e,t));class jb extends zb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,n){super(zb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=n,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,n,i,o,a,u)=>{if((i.isMeshToonMaterial||i.isMeshToonNodeMaterial)&&!1===i.wireframe){const l=this._getOutlineMaterial(i);t.renderObject(e,s,r,n,l,o,a,u)}t.renderObject(e,s,r,n,i,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new nh;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=Sn(1),n=s.mul(Ln(Yu,1)),i=s.mul(Ln(Yu.add(t),1)),o=Ao(n.sub(i));return e.vertexNode=n.add(o.mul(this.thicknessNode).mul(n.w).mul(r)),e.colorNode=Ln(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const qb=(t,s,r=new e(0,0,0),n=.003,i=1)=>hn(new jb(t,s,hn(r),hn(n),hn(i))),Kb=yn((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=yn((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Yb=yn((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qb=yn((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Zb=yn((([e,t])=>{const s=kn(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=kn(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=Qb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Jb=kn(Un(1.6605,-.1246,-.0182),Un(-.5876,1.1329,-.1006),Un(-.0728,-.0083,1.1187)),ex=kn(Un(.6274,.0691,.0164),Un(.3293,.9195,.088),Un(.0433,.0113,.8956)),tx=yn((([e])=>{const t=Un(e).toVar(),s=Un(t.mul(t)).toVar(),r=Un(s.mul(s)).toVar();return Sn(15.5).mul(r.mul(s)).sub(Gi(40.14,r.mul(t))).add(Gi(31.96,r).sub(Gi(6.868,s.mul(t))).add(Gi(.4298,s).add(Gi(.1191,t).sub(.00232))))})),sx=yn((([e,t])=>{const s=Un(e).toVar(),r=kn(Un(.856627153315983,.137318972929847,.11189821299995),Un(.0951212405381588,.761241990602591,.0767994186031903),Un(.0482516061458583,.101439036467562,.811302368396859)),n=kn(Un(1.1271005818144368,-.1413297634984383,-.14132976349843826),Un(-.11060664309660323,1.157823702216272,-.11060664309660294),Un(-.016493938717834573,-.016493938717834257,1.2519364065950405)),i=Sn(-12.47393),o=Sn(4.026069);return s.mulAssign(t),s.assign(ex.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(i).div(o.sub(i))),s.assign(da(s,0,1)),s.assign(tx(s)),s.assign(n.mul(s)),s.assign(sa(Ko(Un(0),s),Un(2.2))),s.assign(Jb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),rx=yn((([e,t])=>{const s=Sn(.76),r=Sn(.15);e=e.mul(t);const n=qo(e.r,qo(e.g,e.b)),i=xa(n.lessThan(.08),n.sub(Gi(6.25,n.mul(n))),.04);e.subAssign(i);const o=Ko(e.r,Ko(e.g,e.b));_n(o.lessThan(s),(()=>e));const a=Oi(1,s),u=Oi(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=Oi(1,ki(1,r.mul(o.sub(u)).add(1)));return la(e,Un(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class nx extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const ix=mn(nx),ox=(e,t)=>ix(e,t,"js"),ax=(e,t)=>ix(e,t,"wgsl"),ux=(e,t)=>ix(e,t,"glsl");class lx extends nx{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,n=s.type,i=e.getCodeFromNode(this,n);""!==r&&(i.name=r);const o=e.getPropertyName(i),a=this.getNodeFunction(e).getCode(o);return i.code=a+"\n","property"===t?o:e.format(`${o}()`,n,t)}}const dx=(e,t=[],s="")=>{for(let e=0;er.call(...e);return n.functionNode=r,n},cx=(e,t)=>dx(e,t,"glsl"),hx=(e,t)=>dx(e,t,"wgsl");class px extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:Sn()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const gx=mn(px);class mx extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class fx{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const yx=new mx;class bx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new mx,this._output=gx(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=gx(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=gx(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new fx(this),t=yx.get("THREE"),s=yx.get("TSL"),r=this.getMethod(this.codeNode),n=[e,this._local,yx,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...n);const i=this._object.layout;if(i&&(!1===i.cache&&this._local.clear(),this._output.outputType=i.outputType||null,Array.isArray(i.elements)))for(const e of i.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:Sn()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const xx=mn(bx);class Tx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const _x=mn(Tx);class Nx extends Tx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const vx=mn(Nx);class Sx extends Tx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const Ax=mn(Sx);let Rx=null,Cx=null;class Ex extends Ar{static get type(){return"RangeNode"}constructor(e=Sn(),t=Sn()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const n=this.minNode.value,i=this.maxNode.value,o=e.getTypeLength(hr(n)),u=e.getTypeLength(hr(i));Rx=Rx||new r,Cx=Cx||new r,Rx.setScalar(0),Cx.setScalar(0),1===o?Rx.setScalar(n):n.isColor?Rx.set(n.r,n.g,n.b):Rx.set(n.x,n.y,n.z||0,n.w||0),1===u?Cx.setScalar(i):i.isColor?Cx.set(i.r,i.g,i.b):Cx.set(i.x,i.y,i.z||0,i.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;ehn(new Mx(e,t)),Ux=Bx("numWorkgroups","uvec3"),Fx=Bx("workgroupId","uvec3"),Px=Bx("localId","uvec3"),Ix=Bx("subgroupSize","uint");const Lx=mn(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Dx=()=>Lx("workgroup").append(),Vx=()=>Lx("storage").append(),Ox=()=>Lx("texture").append();class Gx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class kx extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return hn(new Gx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const zx=(e,t)=>hn(new kx("Workgroup",e,t));class $x extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),n=this.pointerNode,i=this.valueNode,o=[];o.push(`&${n.build(e,r)}`),o.push(i.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}$x.ATOMIC_LOAD="atomicLoad",$x.ATOMIC_STORE="atomicStore",$x.ATOMIC_ADD="atomicAdd",$x.ATOMIC_SUB="atomicSub",$x.ATOMIC_MAX="atomicMax",$x.ATOMIC_MIN="atomicMin",$x.ATOMIC_AND="atomicAnd",$x.ATOMIC_OR="atomicOr",$x.ATOMIC_XOR="atomicXor";const Hx=mn($x),Wx=(e,t,s,r)=>{const n=Hx(e,t,s,r);return n.append(),n},jx=(e,t,s=null)=>Wx($x.ATOMIC_STORE,e,t,s),qx=(e,t,s=null)=>Wx($x.ATOMIC_ADD,e,t,s),Kx=(e,t,s=null)=>Wx($x.ATOMIC_SUB,e,t,s),Xx=(e,t,s=null)=>Wx($x.ATOMIC_MAX,e,t,s),Yx=(e,t,s=null)=>Wx($x.ATOMIC_MIN,e,t,s),Qx=(e,t,s=null)=>Wx($x.ATOMIC_AND,e,t,s),Zx=(e,t,s=null)=>Wx($x.ATOMIC_OR,e,t,s),Jx=(e,t,s=null)=>Wx($x.ATOMIC_XOR,e,t,s);let eT;function tT(e){eT=eT||new WeakMap;let t=eT.get(e);return void 0===t&&eT.set(e,t={}),t}function sT(e){const t=tT(e);return t.position||(t.position=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function rT(e){const t=tT(e);return t.targetPosition||(t.targetPosition=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function nT(e){const t=tT(e);return t.viewPosition||(t.viewPosition=ti(new s).setGroup(Zn).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const iT=e=>Eu.transformDirection(sT(e).sub(rT(e))),oT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},aT=new WeakMap;class uT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Un().toVar("totalDiffuse"),this.totalSpecularNode=Un().toVar("totalSpecular"),this.outgoingLightNode=Un().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),n=e.renderer.library;for(const e of r)if(e.isNode)t.push(hn(e));else{let r=null;if(null!==s&&(r=oT(e.id,s)),null===r){const s=n.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;aT.has(e)?r=aT.get(e):(r=hn(new s(e)),aT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:n,totalDiffuseNode:i,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,n),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Un(null!==l?l.mix(g,u):u),t.material.transparent=!0),i.assign(g),o.assign(c.add(p)),r.assign(i.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const lT=(e=[])=>hn(new uT).setLights(e),dT=yn((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),cT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=Ml("radius","float",s).setGroup(Zn),o=En(1).div(n),a=o.x.negate().mul(i),u=o.y.negate().mul(i),l=o.x.mul(i),d=o.y.mul(i),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vi(r(t.xy.add(En(a,u)),t.z),r(t.xy.add(En(0,u)),t.z),r(t.xy.add(En(l,u)),t.z),r(t.xy.add(En(c,h)),t.z),r(t.xy.add(En(0,h)),t.z),r(t.xy.add(En(p,h)),t.z),r(t.xy.add(En(a,0)),t.z),r(t.xy.add(En(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(En(p,0)),t.z),r(t.xy.add(En(l,0)),t.z),r(t.xy.add(En(c,g)),t.z),r(t.xy.add(En(0,g)),t.z),r(t.xy.add(En(p,g)),t.z),r(t.xy.add(En(a,d)),t.z),r(t.xy.add(En(0,d)),t.z),r(t.xy.add(En(l,d)),t.z)).mul(1/17)})),hT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=En(1).div(n),o=i.x,a=i.y,u=t.xy,l=Ro(u.mul(n).add(.5));return u.subAssign(l.mul(i)),Vi(r(u,t.z),r(u.add(En(o,0)),t.z),r(u.add(En(0,a)),t.z),r(u.add(i),t.z),la(r(u.add(En(o.negate(),0)),t.z),r(u.add(En(o.mul(2),0)),t.z),l.x),la(r(u.add(En(o.negate(),a)),t.z),r(u.add(En(o.mul(2),a)),t.z),l.x),la(r(u.add(En(0,a.negate())),t.z),r(u.add(En(0,a.mul(2))),t.z),l.y),la(r(u.add(En(o,a.negate())),t.z),r(u.add(En(o,a.mul(2))),t.z),l.y),la(la(r(u.add(En(o.negate(),a.negate())),t.z),r(u.add(En(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(En(o.negate(),a.mul(2))),t.z),r(u.add(En(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),pT=yn((({depthTexture:e,shadowCoord:t})=>{const s=Sn(1).toVar(),r=_u(e).uv(t.xy).rg,n=Yo(t.z,r.x);return _n(n.notEqual(Sn(1)),(()=>{const e=t.z.sub(r.x),i=Ko(0,r.y.mul(r.y));let o=i.div(i.add(e.mul(e)));o=da(Oi(o,.3).div(.95-.3)),s.assign(da(Ko(n,o)))})),s})),gT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(0,u).mul(t)).div(s)).x;n.addAssign(l),i.addAssign(l.mul(l))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),mT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(u,0).mul(t)).div(s));n.addAssign(l.x),i.addAssign(Vi(l.y.mul(l.y),l.x.mul(l.x)))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),fT=[dT,cT,hT,pT];let yT=null;const bT=new _f;class xT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===yT&&(yT=new nh,yT.fragmentNode=Ln(0,0,0,1),yT.isShadowNodeMaterial=!0,yT.name="ShadowMaterial");const r=this.shadow,n=s.shadowMap.type,i=new B(r.mapSize.width,r.mapSize.height);i.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=i,r.camera.updateProjectionMatrix(),n===Re){i.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(i),s=_u(this.vsmShadowMapVertical.texture),n=Ml("blurSamples","float",r).setGroup(Zn),o=Ml("radius","float",r).setGroup(Zn),a=Ml("mapSize","vec2",r).setGroup(Zn);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new nh);u.fragmentNode=gT({samples:n,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new nh),u.fragmentNode=mT({samples:n,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Zn),u=Ml("bias","float",r).setGroup(Zn),l=Ml("normalBias","float",r).setGroup(Zn),d=t.material.shadowPositionNode||Zu;let c,h=ti(r.matrix).setGroup(Zn).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=Ml("near","float",r.camera).setGroup(Zn),s=Ml("far","float",r.camera).setGroup(Zn);c=qc(e.negate(),t,s)}h=Un(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||fT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:n===Re?this.vsmShadowMapHorizontal.texture:i,shadowCoord:h,shadow:r}),Sn(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:n,scene:i,camera:o}=e,a=n.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=i.overrideMaterial;i.overrideMaterial=yT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=n.getRenderTarget(),c=n.getRenderObjectFunction();n.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&n.renderObject(e,...t)})),n.setRenderTarget(t),n.render(i,r.camera),n.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(n),n.setRenderTarget(d),i.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),bT.material=this.vsmMaterialVertical,bT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),bT.material=this.vsmMaterialHorizontal,bT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const TT=(e,t)=>hn(new xT(e,t));class _T extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=ti(this.color).setGroup(Zn),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?hn(e):TT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const NT=yn((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,n=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(n.mul(t.div(s).pow4().oneMinus().clamp().pow2()),n)})),vT=yn((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},n)=>{const i=n.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=NT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=n.context.reflectedLight;i.direct({lightDirection:a,lightColor:d,reflectedLight:c},n.stack,n)}));class ST extends _T{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){vT({color:this.colorNode,lightViewPosition:nT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const AT=yn((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),RT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Cn(e).toVar();return xa(i,n,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),CT=yn((([e,t])=>{const s=Cn(t).toVar(),r=Sn(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),ET=yn((([e])=>{const t=Sn(e).toVar();return An(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),wT=yn((([e,t])=>{const s=Sn(e).toVar();return t.assign(ET(s)),s.sub(Sn(t))})),MT=Pm([yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Sn(r).toVar(),l=Sn(s).toVar(),d=Sn(t).toVar(),c=Sn(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Un(r).toVar(),l=Un(s).toVar(),d=Un(t).toVar(),c=Un(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),BT=Pm([yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Sn(a).toVar(),m=Sn(o).toVar(),f=Sn(i).toVar(),y=Sn(n).toVar(),b=Sn(r).toVar(),x=Sn(s).toVar(),T=Sn(t).toVar(),_=Sn(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Un(a).toVar(),m=Un(o).toVar(),f=Un(i).toVar(),y=Un(n).toVar(),b=Un(r).toVar(),x=Un(s).toVar(),T=Un(t).toVar(),_=Un(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),UT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Rn(e).toVar(),o=Rn(i.bitAnd(Rn(7))).toVar(),a=Sn(RT(o.lessThan(Rn(4)),n,r)).toVar(),u=Sn(Gi(2,RT(o.lessThan(Rn(4)),r,n))).toVar();return CT(a,Cn(o.bitAnd(Rn(1)))).add(CT(u,Cn(o.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),FT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Rn(e).toVar(),u=Rn(a.bitAnd(Rn(15))).toVar(),l=Sn(RT(u.lessThan(Rn(8)),o,i)).toVar(),d=Sn(RT(u.lessThan(Rn(4)),i,RT(u.equal(Rn(12)).or(u.equal(Rn(14))),o,n))).toVar();return CT(l,Cn(u.bitAnd(Rn(1)))).add(CT(d,Cn(u.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),PT=Pm([UT,FT]),IT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Pn(e).toVar();return Un(PT(i.x,n,r),PT(i.y,n,r),PT(i.z,n,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),LT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Pn(e).toVar();return Un(PT(a.x,o,i,n),PT(a.y,o,i,n),PT(a.z,o,i,n))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),DT=Pm([IT,LT]),VT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),OT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),GT=Pm([VT,yn((([e])=>{const t=Un(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),kT=Pm([OT,yn((([e])=>{const t=Un(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),zT=yn((([e,t])=>{const s=An(t).toVar(),r=Rn(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(An(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),$T=yn((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(zT(s,An(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(zT(e,An(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(zT(t,An(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(zT(s,An(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(zT(e,An(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(zT(t,An(4))),t.addAssign(e)})),HT=yn((([e,t,s])=>{const r=Rn(s).toVar(),n=Rn(t).toVar(),i=Rn(e).toVar();return r.bitXorAssign(n),r.subAssign(zT(n,An(14))),i.bitXorAssign(r),i.subAssign(zT(r,An(11))),n.bitXorAssign(i),n.subAssign(zT(i,An(25))),r.bitXorAssign(n),r.subAssign(zT(n,An(16))),i.bitXorAssign(r),i.subAssign(zT(r,An(4))),n.bitXorAssign(i),n.subAssign(zT(i,An(14))),r.bitXorAssign(n),r.subAssign(zT(n,An(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),WT=yn((([e])=>{const t=Rn(e).toVar();return Sn(t).div(Sn(Rn(An(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),jT=yn((([e])=>{const t=Sn(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),qT=Pm([yn((([e])=>{const t=An(e).toVar(),s=Rn(Rn(1)).toVar(),r=Rn(Rn(An(3735928559)).add(s.shiftLeft(Rn(2))).add(Rn(13))).toVar();return HT(r.add(Rn(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(Rn(2)).toVar(),i=Rn().toVar(),o=Rn().toVar(),a=Rn().toVar();return i.assign(o.assign(a.assign(Rn(An(3735928559)).add(n.shiftLeft(Rn(2))).add(Rn(13))))),i.addAssign(Rn(r)),o.addAssign(Rn(s)),HT(i,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(Rn(3)).toVar(),a=Rn().toVar(),u=Rn().toVar(),l=Rn().toVar();return a.assign(u.assign(l.assign(Rn(An(3735928559)).add(o.shiftLeft(Rn(2))).add(Rn(13))))),a.addAssign(Rn(i)),u.addAssign(Rn(n)),l.addAssign(Rn(r)),HT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),yn((([e,t,s,r])=>{const n=An(r).toVar(),i=An(s).toVar(),o=An(t).toVar(),a=An(e).toVar(),u=Rn(Rn(4)).toVar(),l=Rn().toVar(),d=Rn().toVar(),c=Rn().toVar();return l.assign(d.assign(c.assign(Rn(An(3735928559)).add(u.shiftLeft(Rn(2))).add(Rn(13))))),l.addAssign(Rn(a)),d.addAssign(Rn(o)),c.addAssign(Rn(i)),$T(l,d,c),l.addAssign(Rn(n)),HT(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),yn((([e,t,s,r,n])=>{const i=An(n).toVar(),o=An(r).toVar(),a=An(s).toVar(),u=An(t).toVar(),l=An(e).toVar(),d=Rn(Rn(5)).toVar(),c=Rn().toVar(),h=Rn().toVar(),p=Rn().toVar();return c.assign(h.assign(p.assign(Rn(An(3735928559)).add(d.shiftLeft(Rn(2))).add(Rn(13))))),c.addAssign(Rn(l)),h.addAssign(Rn(u)),p.addAssign(Rn(a)),$T(c,h,p),c.addAssign(Rn(o)),h.addAssign(Rn(i)),HT(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),KT=Pm([yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(qT(r,s)).toVar(),i=Pn().toVar();return i.x.assign(n.bitAnd(An(255))),i.y.assign(n.shiftRight(An(8)).bitAnd(An(255))),i.z.assign(n.shiftRight(An(16)).bitAnd(An(255))),i})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(qT(i,n,r)).toVar(),a=Pn().toVar();return a.x.assign(o.bitAnd(An(255))),a.y.assign(o.shiftRight(An(8)).bitAnd(An(255))),a.z.assign(o.shiftRight(An(16)).bitAnd(An(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),XT=Pm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(wT(t.x,s)).toVar(),i=Sn(wT(t.y,r)).toVar(),o=Sn(jT(n)).toVar(),a=Sn(jT(i)).toVar(),u=Sn(MT(PT(qT(s,r),n,i),PT(qT(s.add(An(1)),r),n.sub(1),i),PT(qT(s,r.add(An(1))),n,i.sub(1)),PT(qT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return GT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(wT(t.x,s)).toVar(),o=Sn(wT(t.y,r)).toVar(),a=Sn(wT(t.z,n)).toVar(),u=Sn(jT(i)).toVar(),l=Sn(jT(o)).toVar(),d=Sn(jT(a)).toVar(),c=Sn(BT(PT(qT(s,r,n),i,o,a),PT(qT(s.add(An(1)),r,n),i.sub(1),o,a),PT(qT(s,r.add(An(1)),n),i,o.sub(1),a),PT(qT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),PT(qT(s,r,n.add(An(1))),i,o,a.sub(1)),PT(qT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),PT(qT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),PT(qT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return kT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),YT=Pm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(wT(t.x,s)).toVar(),i=Sn(wT(t.y,r)).toVar(),o=Sn(jT(n)).toVar(),a=Sn(jT(i)).toVar(),u=Un(MT(DT(KT(s,r),n,i),DT(KT(s.add(An(1)),r),n.sub(1),i),DT(KT(s,r.add(An(1))),n,i.sub(1)),DT(KT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return GT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(wT(t.x,s)).toVar(),o=Sn(wT(t.y,r)).toVar(),a=Sn(wT(t.z,n)).toVar(),u=Sn(jT(i)).toVar(),l=Sn(jT(o)).toVar(),d=Sn(jT(a)).toVar(),c=Un(BT(DT(KT(s,r,n),i,o,a),DT(KT(s.add(An(1)),r,n),i.sub(1),o,a),DT(KT(s,r.add(An(1)),n),i,o.sub(1),a),DT(KT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),DT(KT(s,r,n.add(An(1))),i,o,a.sub(1)),DT(KT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),DT(KT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),DT(KT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return kT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),QT=Pm([yn((([e])=>{const t=Sn(e).toVar(),s=An(ET(t)).toVar();return WT(qT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar();return WT(qT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar();return WT(qT(s,r,n))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar(),i=An(ET(t.w)).toVar();return WT(qT(s,r,n,i))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),ZT=Pm([yn((([e])=>{const t=Sn(e).toVar(),s=An(ET(t)).toVar();return Un(WT(qT(s,An(0))),WT(qT(s,An(1))),WT(qT(s,An(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar();return Un(WT(qT(s,r,An(0))),WT(qT(s,r,An(1))),WT(qT(s,r,An(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar();return Un(WT(qT(s,r,n,An(0))),WT(qT(s,r,n,An(1))),WT(qT(s,r,n,An(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar(),i=An(ET(t.w)).toVar();return Un(WT(qT(s,r,n,i,An(0))),WT(qT(s,r,n,i,An(1))),WT(qT(s,r,n,i,An(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),JT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Sn(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(XT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),e_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(YT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),t_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar();return En(JT(a,o,i,n),JT(a.add(Un(An(19),An(193),An(17))),o,i,n))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),s_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(e_(a,o,i,n)).toVar(),l=Sn(JT(a.add(Un(An(19),An(193),An(17))),o,i,n)).toVar();return Ln(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),r_=Pm([yn((([e,t,s,r,n,i,o])=>{const a=An(o).toVar(),u=Sn(i).toVar(),l=An(n).toVar(),d=An(r).toVar(),c=An(s).toVar(),h=An(t).toVar(),p=En(e).toVar(),g=Un(ZT(En(h.add(d),c.add(l)))).toVar(),m=En(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=En(En(Sn(h),Sn(c)).add(m)).toVar(),y=En(f.sub(p)).toVar();return _n(a.equal(An(2)),(()=>Fo(y.x).add(Fo(y.y)))),_n(a.equal(An(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),yn((([e,t,s,r,n,i,o,a,u])=>{const l=An(u).toVar(),d=Sn(a).toVar(),c=An(o).toVar(),h=An(i).toVar(),p=An(n).toVar(),g=An(r).toVar(),m=An(s).toVar(),f=An(t).toVar(),y=Un(e).toVar(),b=Un(ZT(Un(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Un(Un(Sn(f),Sn(m),Sn(g)).add(b)).toVar(),T=Un(x.sub(y)).toVar();return _n(l.equal(An(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),_n(l.equal(An(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),n_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();l.assign(qo(l,s))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),o_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),a_=Pm([n_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();d.assign(qo(d,i))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=Pm([i_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.y.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),l_=Pm([o_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(i)})).ElseIf(i.lessThan(d.z),(()=>{d.z.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),d_=yn((([e])=>{const t=e.y,s=e.z,r=Un().toVar();return _n(t.lessThan(1e-4),(()=>{r.assign(Un(s,s,s))})).Else((()=>{let n=e.x;n=n.sub(vo(n)).mul(6).toVar();const i=An(zo(n)),o=n.sub(Sn(i)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());_n(i.equal(An(0)),(()=>{r.assign(Un(s,l,a))})).ElseIf(i.equal(An(1)),(()=>{r.assign(Un(u,s,a))})).ElseIf(i.equal(An(2)),(()=>{r.assign(Un(a,s,l))})).ElseIf(i.equal(An(3)),(()=>{r.assign(Un(a,u,s))})).ElseIf(i.equal(An(4)),(()=>{r.assign(Un(l,a,s))})).Else((()=>{r.assign(Un(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),c_=yn((([e])=>{const t=Un(e).toVar(),s=Sn(t.x).toVar(),r=Sn(t.y).toVar(),n=Sn(t.z).toVar(),i=Sn(qo(s,qo(r,n))).toVar(),o=Sn(Ko(s,Ko(r,n))).toVar(),a=Sn(o.sub(i)).toVar(),u=Sn().toVar(),l=Sn().toVar(),d=Sn().toVar();return d.assign(o),_n(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),_n(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{_n(s.greaterThanEqual(o),(()=>{u.assign(r.sub(n).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vi(2,n.sub(s).div(a)))})).Else((()=>{u.assign(Vi(4,s.sub(r).div(a)))})),u.mulAssign(1/6),_n(u.lessThan(0),(()=>{u.addAssign(1)}))})),Un(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),h_=yn((([e])=>{const t=Un(e).toVar(),s=In(ji(t,Un(.04045))).toVar(),r=Un(t.div(12.92)).toVar(),n=Un(sa(Ko(t.add(Un(.055)),Un(0)).div(1.055),Un(2.4))).toVar();return la(r,n,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),p_=(e,t)=>{e=Sn(e),t=Sn(t);const s=En(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},g_=(e,t,s,r)=>la(e,t,s[r].clamp()),m_=(e,t,s=mu())=>g_(e,t,s,"x"),f_=(e,t,s=mu())=>g_(e,t,s,"y"),y_=(e,t,s,r,n)=>la(e,t,p_(s,r[n])),b_=(e,t,s,r=mu())=>y_(e,t,s,r,"x"),x_=(e,t,s,r=mu())=>y_(e,t,s,r,"y"),T_=(e=1,t=0,s=mu())=>s.mul(e).add(t),__=(e,t=1)=>(e=Sn(e)).abs().pow(t).mul(e.sign()),N_=(e,t=1,s=.5)=>Sn(e).sub(s).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>XT(e.convert("vec2|vec3")).mul(t).add(s),S_=(e=mu(),t=1,s=0)=>YT(e.convert("vec2|vec3")).mul(t).add(s),A_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ln(YT(e),XT(e.add(En(19,73)))).mul(t).add(s)},R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,An(1)),C_=(e=mu(),t=1)=>u_(e.convert("vec2|vec3"),t,An(1)),E_=(e=mu(),t=1)=>l_(e.convert("vec2|vec3"),t,An(1)),w_=(e=mu())=>QT(e.convert("vec2|vec3")),M_=(e=mu(),t=3,s=2,r=.5,n=1)=>JT(e,An(t),s,r).mul(n),B_=(e=mu(),t=3,s=2,r=.5,n=1)=>t_(e,An(t),s,r).mul(n),U_=(e=mu(),t=3,s=2,r=.5,n=1)=>e_(e,An(t),s,r).mul(n),F_=(e=mu(),t=3,s=2,r=.5,n=1)=>s_(e,An(t),s,r).mul(n),P_=yn((([e,t,s])=>{const r=Ao(e).toVar("nDir"),n=Oi(Sn(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),i=Oi(Sn(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Un().toVar("rbminmax");o.x=r.x.greaterThan(Sn(0)).select(n.x,i.x),o.y=r.y.greaterThan(Sn(0)).select(n.y,i.y),o.z=r.z.greaterThan(Sn(0)).select(n.z,i.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),I_=yn((([e,t])=>{const s=e.x,r=e.y,n=e.z;let i=t.element(0).mul(.886227);return i=i.add(t.element(1).mul(1.023328).mul(r)),i=i.add(t.element(2).mul(1.023328).mul(n)),i=i.add(t.element(3).mul(1.023328).mul(s)),i=i.add(t.element(4).mul(.858086).mul(s).mul(r)),i=i.add(t.element(5).mul(.858086).mul(r).mul(n)),i=i.add(t.element(6).mul(n.mul(n).mul(.743125).sub(.247708))),i=i.add(t.element(7).mul(.858086).mul(s).mul(n)),i=i.add(t.element(8).mul(.429043).mul(Gi(s,s).sub(Gi(r,r)))),i})),L_=new hm;class D_ extends Dg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,n=this.nodes.getBackgroundNode(e)||e.background;let i=!1;if(null===n)r._clearColor.getRGB(L_,Se),L_.a=r._clearColor.a;else if(!0===n.isColor)n.getRGB(L_,Se),L_.a=1,i=!0;else if(!0===n.isNode){const s=this.get(e),i=n;L_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ln(i).mul(Df),{getUV:()=>Vf.mul(ll),getTextureLevel:()=>Lf});let t=Wd();t=t.setZ(t.w);const r=new nh;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=i.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ln(i).mul(Df),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",n);if(!0===r.autoClear||!0===i){const e=s.clearColorValue;e.r=L_.r,e.g=L_.g,e.b=L_.b,e.a=L_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let V_=0;class O_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=V_++}}class G_{constructor(e,t,s,r,n,i,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=n,this.updateNodes=i,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new O_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class k_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class z_{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class $_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class H_ extends $_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class W_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let j_=0;class q_{constructor(e=null){this.id=j_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class K_{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class X_ extends K_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class Y_ extends K_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class Q_ extends K_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends K_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class J_ extends K_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class eN extends K_{constructor(e,t=new n){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class tN extends K_{constructor(e,t=new i){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class aN extends eN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class uN extends tN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const lN=[.125,.215,.35,.446,.526,.582],dN=20,cN=new xe(-1,1,1,-1,0,1),hN=new Be(90,1),pN=new e;let gN=null,mN=0,fN=0;const yN=(1+Math.sqrt(5))/2,bN=1/yN,xN=[new s(-yN,bN,0),new s(yN,bN,0),new s(-bN,0,yN),new s(bN,0,yN),new s(0,yN,-bN),new s(0,yN,bN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],TN=[3,1,5,0,4,2],_N=Hp(mu(),gu("faceIndex")).normalize(),NN=Un(_N.x,_N.y.negate(),_N.z);class vN{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(e,t=0,s=.1,r=100){gN=this._renderer.getRenderTarget(),mN=this._renderer.getActiveCubeFace(),fN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const n=this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(e,s,r,n),t>0&&this._blur(n,0,0,t),this._applyPMREM(n),this._cleanup(n),n}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=CN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=EN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=lN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],n=TN[e];b.set(r,m*g*n),x.set(h,f*g*n);const i=[n,n,n,n,n,n];T.set(i,y*g*n)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),n.push(new k(_,null)),i>4&&i--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:n}}(n)),this._blurMaterial=function(e,t,r){const n=Rl(new Array(dN).fill(0)),i=ti(new s(0,1,0)),o=ti(0),a=Sn(dN),u=ti(0),l=ti(1),d=_u(null),c=ti(0),h=Sn(1/t),p=Sn(1/r),g=Sn(e),m={n:a,latitudinal:u,weights:n,poleAxis:i,outputDirection:NN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=RN("blur");return f.uniforms=m,f.fragmentNode=Kp({...m,latitudinal:u.equal(1)}),f}(n,e,t)}return n}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,cN)}_sceneToCubeUV(e,t,s,r){const n=hN;n.near=t,n.far=s;const i=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(pN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(pN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,n);for(let t=0;t<6;t++){const s=t%3;0===s?(n.up.set(0,i[t],0),n.lookAt(o[t],0,0)):1===s?(n.up.set(0,0,i[t]),n.lookAt(0,o[t],0)):(n.up.set(0,i[t],0),n.lookAt(0,0,o[t]));const u=this._cubeSize;AN(r,s*u,t>2?u:0,u,u),a.render(e,n)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=CN(e)):null===this._equirectMaterial&&(this._equirectMaterial=EN(e));const n=r?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=n;const o=this._cubeSize;AN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(i,cN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;tdN&&console.warn(`sigmaRadians, ${n}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,cN)}}function SN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function AN(e,t,s,r,n){e.viewport.set(t,s,r,n),e.scissor.set(t,s,r,n)}function RN(e){const t=new nh;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function CN(e){const t=RN("cubemap");return t.fragmentNode=_l(e,NN),t}function EN(e){const t=RN("equirect");return t.fragmentNode=_u(e,bh(NN),0),t}const wN=new WeakMap,MN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),BN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),UN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class FN{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=fm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new q_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=wN.get(this.renderer);return void 0===e&&(e=new Ug,wN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new xh(e,t)}createPMREMGenerator(){return new vN(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let n,i=!0;for(const e of t)r.push(e),i=i&&!0!==e.groupNode.shared;return i?(n=s.get(r),void 0===n&&(n=new O_(e,r,this.bindingsIndexes[e].group,r),s.set(r,n))):n=new O_(e,r,this.bindingsIndexes[e].group,r),n}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const n=s[e][r];(t[r]||(t[r]=[])).push(...n)}e=[];for(const s in t){const r=t[s],n=this._getBindGroup(s,r);e.push(n)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(i)}u`:"0u";if("bool"===n)return i?"true":"false";if("color"===n)return`${this.getType("vec3")}( ${UN(i.r)}, ${UN(i.g)}, ${UN(i.b)} )`;const o=this.getTypeLength(n),a=this.getComponentType(n),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)} )`;if(3===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)} )`;if(4===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)}, ${u(i.w)} )`;if(o>4&&i&&(i.isMatrix3||i.isMatrix4))return`${this.getType(n)}( ${i.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(n)}()`;throw new Error(`NodeBuilder: Type '${n}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new k_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=MN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return BN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,n=e.normalized;let i;return e instanceof Ie||!0===n||(i=this.getTypeFromArray(s)),this.getTypeFromLength(r,i)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=fm(this.stack),this.stacks.push(Tn()||this.stack),xn(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,xn(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(void 0===r){const n=this.uniforms.index++;r=new k_("nodeAttribute"+n,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const n=this.getDataFromNode(e,s,this.globalCache);let i=n.uniform;if(void 0===i){const o=this.uniforms.index++;i=new z_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(i),n.uniform=i}return i}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const n=this.getDataFromNode(e,r);let i=n.variable;if(void 0===i){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),i=new $_(t,s),e.push(i),n.variable=i}return i}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let n=r.varying;if(void 0===n){const e=this.varyings,i=e.length;null===t&&(t="nodeVarying"+i),n=new H_(t,s),e.push(n),r.varying=n}return n}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let n=r.code;if(void 0===n){const e=this.codes[s]||(this.codes[s]=[]),i=e.length;n=new W_("nodeCode"+i,t),e.push(n),r.code=n}return n}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let n=!0,i=t;for(;i;){if(!0===r.get(i)){n=!1;break}i=this.getDataFromNode(i).parentNodeBlock}if(n)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),n=r.flowCodes||(r.flowCodes=[]),i=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);n.push(t),i.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new lx,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new pm(e.type,e.name);e.layout=null;const r=e.call(s),n=this.flowStagesNode(r,t.type);return e.layout=t,n}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,n=this.cache,i=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new q_,this.stack=fm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=n,this.stack=o,this.setBuildStage(i),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const n=this.shaderStage;this.setShaderStage(e);const i=this.flowChildNode(t,s);return null!==r&&(i.code+=`${this.tab+r} = ${i.result};\n`),this.flowCode[e]=this.flowCode[e]+i.code,this.setShaderStage(n),i}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new nh),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new sN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new rN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new nN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new iN(e);if("color"===t)return new oN(e);if("mat3"===t)return new aN(e);if("mat4"===t)return new uN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),n=this.getTypeLength(s);return 16===r&&9===n?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===n?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||n>4||0===n?e:r===n?`${this.getType(s)}( ${e} )`:r>n?this.format(`${e}.${"xyz".slice(0,n)}`,this.getTypeFromLength(n,this.getComponentType(t)),s):4===n&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&n>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class PN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class IN{constructor(e,t,s=null,r="",n=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=n}}IN.isNodeFunctionInput=!0;class LN extends _T{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=iT(this.light),n=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:n},e.stack,e)}}const DN=new i,VN=new i;let ON=null;class GN extends _T{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=ti(new s).setGroup(Zn),this.halfWidth=ti(new s).setGroup(Zn),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;VN.identity(),DN.copy(t.matrixWorld),DN.premultiply(s),VN.extractRotation(DN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(VN),this.halfHeight.value.applyMatrix4(VN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(ON.LTC_FLOAT_1),s=_u(ON.LTC_FLOAT_2)):(t=_u(ON.LTC_HALF_1),s=_u(ON.LTC_HALF_2));const{colorNode:r,light:n}=this,i=e.context.lightingModel,o=nT(n),a=e.context.reflectedLight;i.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){ON=e}}class kN extends _T{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=ti(0).setGroup(Zn),this.penumbraCosNode=ti(0).setGroup(Zn),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:n,light:i}=this,o=nT(i).sub(el),a=o.normalize(),u=a.dot(iT(i)),l=this.getSpotAttenuation(u),d=o.length(),c=NT({lightDistance:d,cutoffDistance:r,decayExponent:n}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class zN extends kN{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,En(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class $N extends _T{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class HN extends _T{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=sT(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=ti(new e).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:r}=this,n=ul.dot(r).mul(.5).add(.5),i=la(s,t,n);e.context.irradiance.addAssign(i)}}class WN extends _T{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=I_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class jN{parseFunction(){console.warn("Abstract function.")}}class qN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}qN.isNodeFunction=!0;const KN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,XN=/[a-z_0-9]+/gi,YN="#pragma main";class QN extends qN{constructor(e){const{type:t,inputs:s,name:r,precision:n,inputsCode:i,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(YN),s=-1!==t?e.slice(t+12):e,r=s.match(KN);if(null!==r&&5===r.length){const n=r[4],i=[];let o=null;for(;null!==(o=XN.exec(n));)i.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Jp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=Sh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Zn),r=Ml("density","float",s).setGroup(Zn);e=Ax(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Zn),r=Ml("near","float",s).setGroup(Zn),n=Ml("far","float",s).setGroup(Zn);e=vx(t,r,n)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,n=null){const i=this.nodeFrame;return i.renderer=e,i.scene=t,i.object=s,i.camera=r,i.material=n,i}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return JN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return JN.set(e,s),r}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new PN,this.nodeBuilderCache=new Map}}const tv=new me;class sv{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new n,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let n=0;n{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),n=this._renderContexts.get(e,t,this._renderTarget),i=e.overrideMaterial||s.material,o=this._objects.get(s,i,e,t,r.lightsNode,n,n.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ev(this,s),this._animation=new Bg(this._nodes,this.info),this._attributes=new $g(s),this._background=new D_(this,this._nodes),this._geometries=new jg(this._attributes,this.info),this._textures=new cm(this,s,this.info),this._pipelines=new Jg(s,this._nodes),this._bindings=new em(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Lg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new im(this.lighting),this._bundles=new nv,this._renderContexts=new lm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,n=r.renderId,i=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:uv;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new sv),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=n,this._currentRenderContext=i,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:n,renderList:i}=e,o=this._currentRenderContext,a=this._bundles.get(r,n),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=i.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,n,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(dv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(dv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new sv),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),hv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),cv.setFromProjectionMatrix(hv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),n.renderId=i,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,r){const n=this._scissor;e.isVector4?n.copy(e):n.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,n=0,i=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=n,o.maxDepth=i}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let n=null;if(null!==r&&(this._textures.updateRenderTarget(r),n=this._textures.get(r)),this.backend.clear(e,t,s,n),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const r=this.backend,n=this._pipelines,i=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===n.has(t)){const e=()=>{t.removeEventListener("dispose",e),n.delete(t),i.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),i.updateForCompute(t);const s=i.getForCompute(t),a=n.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=pv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=pv.copy(t).floor()}else t=pv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,n)}readRenderTargetPixelsAsync(e,t,s,r,n,i=0,o=0){return this.backend.copyTextureToBuffer(e.textures[i],t,s,r,n,o)}_projectObject(e,t,s,r,n){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(n=n.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||cv.intersectsSprite(e)){!0===this.sortObjects&&pv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(hv);const{geometry:t,material:i}=e;i.visible&&r.push(e,t,i,s,pv.z,null,n)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||cv.intersectsObject(e))){const{geometry:t,material:i}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),pv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(hv)),Array.isArray(i)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,n,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,n);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,n)}_renderObjects(e,t,s,r,n=null){for(let i=0,o=e.length;i0?r:"";t=`${e.name} {\n\t${s} ${n.name}[${i}];\n};\n`}else{t=`${this.getVectorType(n.type)} ${this.getPropertyName(n,e)};`,i=!0}const o=n.node.precision;if(null!==o&&(t=wv[o]+" "+t),i){t="\t"+t;const e=n.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let n="";for(const t in r){const s=r[t];n+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return n+=s.join("\n"),n}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Mv[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Mv[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${i}\n\t`),s+=`${r.code}\n\t`,e===n&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const i=e[t];i.extensions=this.getExtensions(t),i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.vars=this.getVars(t),i.structs=this.getStructs(t),i.codes=this.getCodes(t),i.transforms=this.getTransforms(t),i.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);let o=i.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new Av(n.name,n.node,r),u.push(o);else if("cubeTexture"===t)o=new Rv(n.name,n.node,r),u.push(o);else if("texture3D"===t)o=new Cv(n.name,n.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,n.name=`buffer${e.id}`;const t=new xv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Nv(s+"_"+a,r),e[a]=i,u.push(i)),o=this.getNodeUniform(n,t),i.addUniform(o)}i.uniformGPU=o}return n}}let Fv=null,Pv=null,Iv=null;class Lv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Fv=Fv||new t,this.renderer.getDrawingBufferSize(Fv)}getScissor(){return Pv=Pv||new r,this.renderer.getScissor(Pv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Iv=Iv||new hm,e.getClearColor(Iv),Iv.getRGB(Iv,this.renderer.currentColorSpace),Iv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Dv=0;class Vv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Ov{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,n=e.array,i=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,n,i),a.bufferGPU=l,a.bufferType=t,a.version=o.version),n instanceof Float32Array)u=r.FLOAT;else if(n instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(n instanceof Int16Array)u=r.SHORT;else if(n instanceof Uint32Array)u=r.UNSIGNED_INT;else if(n instanceof Int32Array)u=r.INT;else if(n instanceof Int8Array)u=r.BYTE;else if(n instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Dv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,n,i);d=new Vv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,n=e.isInterleavedBufferAttribute?e.data:e,i=t.get(n),o=i.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,i.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t{!function n(){const i=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(i===e.WAIT_FAILED)return e.deleteSync(t),void r();i!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(n)}()}))}}let Wv,jv,qv,Kv=!1;class Xv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===Kv&&(this._init(this.gl),Kv=!0)}_init(e){Wv={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},jv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},qv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,n=!1){const{gl:i,extensions:o}=this;if(null!==e){if(void 0!==i[e])return i[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===i.RED&&(s===i.FLOAT&&(a=i.R32F),s===i.HALF_FLOAT&&(a=i.R16F),s===i.UNSIGNED_BYTE&&(a=i.R8),s===i.UNSIGNED_SHORT&&(a=i.R16),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RED_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.R8UI),s===i.UNSIGNED_SHORT&&(a=i.R16UI),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RG&&(s===i.FLOAT&&(a=i.RG32F),s===i.HALF_FLOAT&&(a=i.RG16F),s===i.UNSIGNED_BYTE&&(a=i.RG8),s===i.UNSIGNED_SHORT&&(a=i.RG16),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RG_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RG8UI),s===i.UNSIGNED_SHORT&&(a=i.RG16UI),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RGB&&(s===i.FLOAT&&(a=i.RGB32F),s===i.HALF_FLOAT&&(a=i.RGB16F),s===i.UNSIGNED_BYTE&&(a=i.RGB8),s===i.UNSIGNED_SHORT&&(a=i.RGB16),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8:i.RGB8),s===i.UNSIGNED_SHORT_5_6_5&&(a=i.RGB565),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGB4),s===i.UNSIGNED_INT_5_9_9_9_REV&&(a=i.RGB9_E5)),t===i.RGB_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGB8UI),s===i.UNSIGNED_SHORT&&(a=i.RGB16UI),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I)),t===i.RGBA&&(s===i.FLOAT&&(a=i.RGBA32F),s===i.HALF_FLOAT&&(a=i.RGBA16F),s===i.UNSIGNED_BYTE&&(a=i.RGBA8),s===i.UNSIGNED_SHORT&&(a=i.RGBA16),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8_ALPHA8:i.RGBA8),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGBA4),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1)),t===i.RGBA_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGBA8UI),s===i.UNSIGNED_SHORT&&(a=i.RGBA16UI),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I)),t===i.DEPTH_COMPONENT&&(s===i.UNSIGNED_INT&&(a=i.DEPTH24_STENCIL8),s===i.FLOAT&&(a=i.DEPTH_COMPONENT32F)),t===i.DEPTH_STENCIL&&s===i.UNSIGNED_INT_24_8&&(a=i.DEPTH24_STENCIL8),a!==i.R16F&&a!==i.R32F&&a!==i.RG16F&&a!==i.RG32F&&a!==i.RGBA16F&&a!==i.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:n}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,Wv[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,Wv[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,Wv[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,jv[t.magFilter]);const i=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&i?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,jv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,qv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const i=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,n.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,n=this.getGLTextureType(e);let i=r[n];void 0===i&&(i=t.createTexture(),s.state.bindTexture(n,i),t.texParameteri(n,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(n,t.TEXTURE_MAG_FILTER,t.NEAREST),r[n]=i),s.set(e,{textureGPU:i,glTextureType:n,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:n,width:i,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,n,d,i,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,n,d,i,o,a):e.isVideoTexture||s.texStorage2D(h,n,d,i,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:n,glTextureType:i,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(i,n),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(i,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:n}=t,{textureGPU:i,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===i)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,i),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,n=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;n.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),n.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),n.bindFramebuffer(r.READ_FRAMEBUFFER,s),n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),n.unbindTexture()}else{const e=r.createFramebuffer();n.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,i,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),n.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:n,depthTexture:i,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;n>0?(i&&i.isDepthTexture&&i.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,n,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(n>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,n,i){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+i:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*n*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,n,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let r=0;return e===s.UNSIGNED_BYTE&&(r=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Yv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Qv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const Zv={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class Jv{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:r,object:n,type:i,info:o,index:a}=this;0!==a?s.drawElements(r,t,i,e):s.drawArrays(r,e,t),o.update(n,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:n,type:i,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(n,t,i,e,s):r.drawArraysInstanced(n,e,t,s),u.update(a,t,n,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:n,object:i,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),n=r.previousContext,i=e.occlusionQueryCount;i>0&&(i>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const n=r.framebuffers[e.getCacheKey()],i=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,n);for(let s=0;s{let o=0;for(let t=0;t0&&e.add(r[t]),s[t]=null,n.deleteQuery(i),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Uv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,n="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(n,r),t.compileShader(n),this.set(e,{shaderGPU:n})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:n,vertexProgram:i}=r,o=s.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const n=new Promise((t=>{const n=this.parallel,i=()=>{s.getProgramParameter(o,n.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(i)};i()}));t.push(n)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],n=Math.max(t-6,0),i=Math.min(t+6,s.length);for(let e=n;e":" "} ${n}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),n=e.getShaderInfoLog(t).trim();if(r&&""===n)return"";const i=/ERROR: 0:(\d+)/.exec(n);if(i){const r=parseInt(i[1]);return s.toUpperCase()+"\n\n"+n+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return n}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,n=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const i=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+n+"\n"+i+"\n"+o)}else""!==n&&console.warn("THREE.WebGLProgram: Program Info Log:",n)}}_completeCompile(e,t){const{state:s,gl:r}=this,n=this.get(t),{programGPU:i,fragmentShader:o,vertexShader:a}=n;!1===r.getProgramParameter(i,r.LINK_STATUS)&&this._logProgramError(i,o,a),s.useProgram(i);const u=e.getBindings();this._setupBindings(u,i),this.set(t,{programGPU:i})}createComputePipeline(e,t){const{state:s,gl:r}=this,n={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(n);const{computeProgram:i}=e,o=r.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU,l=i.transforms,d=[],c=[];for(let e=0;eZv[t]===e)),s=this.extensions;for(let e=0;e0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const n=[],l=e.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Wf,stripIndexFormat:uy},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Wf,stripIndexFormat:uy},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:n,height:i}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:n,height:i,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),n=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),i=c.beginRenderPass({colorAttachments:[{view:s,loadOp:sy,storeOp:ey,clearValue:[0,0,0,0]}]});i.setPipeline(e),i.setBindGroup(0,n),i.draw(4,1,0,0),i.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const n=r.layers[s]||this._mipmapCreateBundles(e,t,s),i=this.device.createCommandEncoder({});this._mipmapRunBundles(i,n),this.device.queue.submit([i.finish()]),0!==r.useCount&&(r.layers[s]=n),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),n=r.getBindGroupLayout(0);let i=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:s});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,hS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,pS={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class gS extends qN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:n,blockCode:i,outputType:o}=(e=>{const t=(e=e.trim()).match(cS);if(null!==t&&4===t.length){const s=t[2],r=[];let n=null;for(;null!==(n=hS.exec(s));)r.push({name:n[1],type:n[2]});const i=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class mS extends jN{parseFunction(e){return new gS(e)}}const fS=self.GPUShaderStage,yS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},bS={vertex:fS?fS.VERTEX:1,fragment:fS?fS.FRAGMENT:2,compute:fS?fS.COMPUTE:4},xS={instance:!0,swizzleAssign:!1,storageBuffer:!0},TS={"^^":"tsl_xor"},_S={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},NS={},vS={tsl_xor:new nx("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new nx("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new nx("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new nx("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new nx("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new nx("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new nx("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new nx("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new nx("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new nx("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new nx("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new nx("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new nx("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new nx("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},SS={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(vS.pow_float=new nx("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),vS.pow_vec2=new nx("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[vS.pow_float]),vS.pow_vec3=new nx("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[vS.pow_float]),vS.pow_vec4=new nx("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[vS.pow_float]),SS.pow_float="tsl_pow_float",SS.pow_vec2="tsl_pow_vec2",SS.pow_vec3="tsl_pow_vec3",SS.pow_vec4="tsl_pow_vec4");let AS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(AS+="diagnostic( off, derivative_uniformity );\n");class RS extends FN{constructor(e,t){super(e,t,new mS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,n=this.shaderStage){return"fragment"===n?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,r,n,i=this.shaderStage){return"fragment"===i&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${yS[e.wrapS]}S_${yS[e.wrapT]}T`;let s=NS[t];if(void 0===s){const r=[];let n=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const i=(e,t)=>{e===ls?(r.push(vS.repeatWrapping_float),n+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(r.push(vS.clampWrapping_float),n+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(r.push(vS.mirrorWrapping_float),n+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(n+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};i(e.wrapS,"x"),n+=",\n",i(e.wrapT,"y"),n+="\n\t);\n\n}\n",NS[t]=s=new nx(n,r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let n=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(n=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${n} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=n),n}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,n="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${n} )`:`textureLoad( ${t}, ${s}, ${n} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,n=this.shaderStage){let i=null;return i=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,n):this._generateTextureSample(e,t,s,r,n),i}generateTextureGrad(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${i} shader.`)}generateTextureCompare(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${i} shader.`)}generateTextureLevel(e,t,s,r,n,i=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this._generateTextureSampleLevel(e,t,s,r,n,i),o}generateTextureBias(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${i} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=TS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case jy:return"read";case Wy:return"write";default:return"read_write"}else switch(e.access){case $y:return"read_write";case Hy:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);if(void 0===i.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let i=null;if("texture"===t||"storageTexture"===t?i=new Av(n.name,n.node,o,e.access?e.access:null):"cubeTexture"===t?i=new Rv(n.name,n.node,o,e.access?e.access:null):"texture3D"===t&&(i=new Cv(n.name,n.node,o,e.access?e.access:null)),i.store=!0===e.isStorageTextureNode,i.setVisibility(bS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===i.store){const e=new sS(`${n.name}_sampler`,n.node,o);e.setVisibility(bS[s]),u.push(e,i),r=[e,i]}else u.push(i),r=[i]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const n=new("buffer"===t?xv:iS)(e,o);n.setVisibility(bS[s]),u.push(n),r=n}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Nv(a,o),i.setVisibility(bS[s]),e[a]=i,u.push(i)),r=this.getNodeUniform(n,t),i.addUniform(r)}i.uniformGPU=r}return n}getBuiltin(e,t,s,r=this.shaderStage){const n=this.builtins[r]||(this.builtins[r]=new Map);return!1===n.has(e)&&n.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let n=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(n+=`\treturn ${s.result};\n`),n+="\n}\n",n}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:n}of s.values())t.push(`@builtin( ${e} ) ${r} : ${n}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:n}of this.scopedArrays.values()){const i=this.getType(r);t.push(`var<${s}> ${e}: array< ${i}, ${n} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e{const{name:t,node:r}=e,n=!0===r.bufferStruct;s.set(t,n)})),s}getMembersFromCustomStruct(e){return`\t${e.map((({name:e,type:t,isAtomic:s})=>{let r=_S[t];return r||(console.warn(`Unrecognized type: ${t}`),r="vec4"),`${e}: ${s?`atomic<${r}>`:r}`})).join(",\n\t")}`}getCustomStructNameFromShader(e){const t=/fn\s+\w+\s*\(([\s\S]*?)\)/g,s=/(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g,r=[];let n;for(;null!==(n=t.exec(e));){const e=n[1];let t;for(;null!==(t=s.exec(e));){const[e,s,n,i,o,a]=t,u=o||a||null,l=i||n;Object.values(_S).includes(u)||null===u||r.push({name:s,type:l,structName:u})}}return r}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;e`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e output : ${n};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let n=0;n";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array";else if(!0===t.isDepthTexture)r=`texture_depth${i}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d";else if(!0===n.node.isStorageTextureNode){r=`texture_storage_2d<${dS(t)}, ${this.getStorageAccess(n.node)}>`}else{r=`texture${i}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name} : ${r};`)}else if("buffer"===n.type||"storageBuffer"===n.type||"indirectStorageBuffer"===n.type){const e=n.node,t=this.getType(e.bufferType),s=e.bufferCount,i=e.value.array.length!==e.value.itemSize,a=s>0&&"buffer"===n.type?", "+s:"",u=e.isAtomic?`atomic<${t}>`:`${t}`,l=e.bufferStruct?this.getMembersFromCustomStruct(t):`\t${n.name} : array< ${u}${a} >\n`,d=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding(e.bufferStruct,i,"NodeBuffer_"+e.id,l,d,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(n.type)),t=n.groupNode.name;(i[t]||(i[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${n.name} : ${e}`)}}for(const e in i){const t=i[e];n.push(this._getWGSLStructBinding(!1,!1,e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=n.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t),s.isBufferStruct=this.getTypeFromCustomStruct(t),s.customStructNames=this.getCustomStructNameFromShader(s.codes);const r=e=>e.replace(/&(\w+)\.(\w+)/g,((e,t,r)=>!0===s.isBufferStruct.get(r)?`&${t}`:e)),n=e=>{const t=e.match(/\(([^)]+)\)/);if(!t)return[];return t[1].split(/\s*,\s*/).map((e=>e.trim())).filter((e=>e.includes("&"))).map((e=>e.replace("&",""))).filter((e=>!e.includes(".")))},i=(e,t)=>{const s=new Map;for(let r=0;r{for(const[s,r]of t.entries()){const t=new RegExp(`\\b${s}Struct\\b`,"g");e=e.replace(t,r)}return e};let a,u,l="// code\n\n";l+=this.flowCode[t];const d=this.flowNodes[t],c=d[d.length-1],h=c.outputNode,p=void 0!==h&&!0===h.isOutputStructNode;for(const e of d){const d=this.getFlowData(e),g=e.name;if(g&&(l.length>0&&(l+="\n"),l+=`\t// flow -> ${g}\n\t`),l+=`${d.code}\n\t`,l=r(l),a=n(l),u=i(a,s.customStructNames),s.uniforms=o(s.uniforms,u),e===c&&"compute"!==t){if(l+="// result\n\n\t","vertex"===t)l+=`varyings.Vertex = ${d.result};`;else if("fragment"===t)if(p)s.returnType=h.nodeType,l+=`return ${d.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar output : OutputStruct;\n\n",l+=`output.color = ${d.result};\n\n\treturn output;`}l=r(l),a=n(l),u=i(a,s.customStructNames),s.uniforms=o(s.uniforms,u)}}s.flow=l}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return _S[e]||e}isAvailable(e){let t=xS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),xS[e]=t),t}_getWGSLMethod(e){return void 0!==vS[e]&&this._include(e),SS[e]}_include(e){const t=vS[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${AS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r,n,i=0,o=0){const a=s+"Struct",u=this._getWGSLStruct(a,r);if(e){return`${u}\n@binding( ${i} ) @group( ${o} )\nvar<${n}> ${s} : ${t?`array<${a}>`:a};`}return`${u}\n@binding( ${i} ) @group( ${o} )\nvar<${n}> ${s} : ${a};`}}class CS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=ly.Depth24PlusStencil8:e.depth&&(t=ly.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?kf:e.isLineSegments||e.isMesh&&!0===t.wireframe?zf:e.isLine?$f:e.isMesh?Hf:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?ly.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const ES=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),wS=new Map([[Ie,["float16"]]]),MS=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class BS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,n=r.get(s);let i=n.buffer;if(void 0===i){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[s]===r&&(a=o.groups[s])),void 0===a&&(a=this.createBindGroup(e,u),s>0&&(o.groups[s]=a,o.versions[s]=r)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,n=t.get(e).buffer;s.queue.writeBuffer(n,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let n=0;const i=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,n=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,i=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:n});e.buffer=i}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);i.push({binding:n,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const n=nb;let i;i=t.isSampledCubeTexture?sb:t.isSampledTexture3D?rb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?tb:eb,o=e[r]=e.texture.createView({aspect:n,dimension:i,mipLevelCount:s})}}i.push({binding:n,resource:o})}n++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:i})}}class FS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:n,pipeline:i}=e,{vertexProgram:o,fragmentProgram:a}=i,u=this.backend,l=u.device,d=u.utils,c=u.get(i),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,n=s.getCurrentDepthStencilFormat(e),i={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:n,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(i)}createComputePipeline(e,t){const s=this.backend,r=s.device,n=s.get(e.computeProgram).module,i=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}i.pipeline=r.createComputePipeline({compute:n,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,n=e.blendSrc,i=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:n,a=null!==e.blendDstAlpha?e.blendDstAlpha:i,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(n),dstFactor:this._getBlendFactor(i),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const n=(e,r,n,i)=>{t={srcFactor:e,dstFactor:r,operation:Ey},s={srcFactor:n,dstFactor:i,operation:Ey}};if(e.premultipliedAlpha)switch(r){case F:n(fy,Ty,fy,Ty);break;case bt:n(fy,fy,fy,fy);break;case yt:n(my,by,my,fy);break;case ft:n(my,yy,my,xy)}else switch(r){case F:n(xy,Ty,fy,Ty);break;case bt:n(xy,fy,xy,fy);break;case yt:n(my,by,my,fy);break;case ft:n(my,yy,my,yy)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=my;break;case st:t=fy;break;case rt:t=yy;break;case ut:t=by;break;case nt:t=xy;break;case lt:t=Ty;break;case ot:t=_y;break;case dt:t=Ny;break;case at:t=vy;break;case ct:t=Sy;break;case it:t=Ay;break;case 211:t=Ry;break;case 212:t=Cy;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=jf;break;case Es:t=Jf;break;case Cs:t=qf;break;case Rs:t=Xf;break;case As:t=Kf;break;case Ss:t=Zf;break;case vs:t=Yf;break;case Ns:t=Qf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Iy;break;case Ls:t=Ly;break;case Is:t=Dy;break;case Ps:t=Vy;break;case Fs:t=Oy;break;case Us:t=Gy;break;case Bs:t=ky;break;case Ms:t=zy;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Ey;break;case Je:t=wy;break;case et:t=My;break;case Os:t=By;break;case Vs:t=Uy;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},n=this.backend.utils;switch(r.topology=n.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?ay:uy),s.side){case Oe:r.frontFace=ry,r.cullMode=oy;break;case x:r.frontFace=ry,r.cullMode=iy;break;case le:r.frontFace=ry,r.cullMode=ny;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Py:Fy}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Jf;else{const s=e.depthFunc;switch(s){case Rt:t=jf;break;case At:t=Jf;break;case St:t=qf;break;case vt:t=Xf;break;case Nt:t=Kf;break;case _t:t=Zf;break;case Tt:t=Yf;break;case xt:t=Qf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class PS extends Lv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new CS(this),this.attributeUtils=new BS(this),this.bindingUtils=new US(this),this.pipelineUtils=new FS(this),this.textureUtils=new lS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const n=Object.values(ab),i=[];for(const e of n)r.features.has(e)&&i.push(e);const o={requiredFeatures:i,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const n=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ab.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:n}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const n=e.getCacheKey();let i=r[n];if(void 0===i){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,n=s.createQuerySet({type:"occlusion",count:r,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=n,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),i=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,i),i.occlusionQuerySet=n;const o=i.depthStencilAttachment;if(null!==e.textures){const t=i.colorAttachments;for(let s=0;s0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const r=8*s;let n=this.occludedResolveCache.get(r);void 0===n&&(n=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,n));const i=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,n,0),t.encoder.copyBufferToBuffer(n,0,i,0,r),t.occlusionQueryBuffer=i,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,n.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:r,pipeline:n}=e,i=e.getBindings(),o=this.get(r),a=this.get(n).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=i.length;e1?0:s;l.drawIndexed(t[s],r,e[s]/i,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,n,i,0,0);t.update(s,r,n)}else{const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,n,i,0);t.update(s,r,n)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,n=this.utils,i=n.getSampleCountRenderContext(e.context),o=n.getCurrentColorSpace(e.context),a=n.getCurrentColorFormat(e.context),u=n.getCurrentDepthStencilFormat(e.context),l=n.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===i&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=i,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,n=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,r.getSampleCountRenderContext(n),r.getCurrentColorSpace(n),r.getCurrentColorFormat(n),r.getCurrentDepthStencilFormat(n),r.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}async initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){this.device.pushErrorScope("out-of-memory");const r=await this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_renderContext_${e.id}`});if(await this.device.popErrorScope())return s.attemptingTimeStampQuerySetFailed||(console.error(`[GPUOutOfMemoryError][renderContext_${e.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.`),s.attemptingTimeStampQuerySetFailed=!0),void(s.timeStampQuerySet=null);const n={querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:n}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;const r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:n,resultBuffer:i,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,n,0),t.copyBufferToBuffer(n,0,i,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:n}=s.currentTimestampQueryBuffers;!0!==n&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),n=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,n),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new RS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,r=null,n=0){let i=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(i=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:n,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:n,origin:{x:i,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let n=null;n=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const i=this.get(e).texture;if(n.format!==i.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,i.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:n,origin:{x:s.x,y:s.y,z:0}},{texture:i},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new eS(e)));super(new t(e),e),this.library=new LS,this.isWebGPURenderer=!0}}class VS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const OS=new nh,GS=new _f(OS);class kS{constructor(e,t=Ln(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,OS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,GS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;GS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),GS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await GS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function zS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function $S(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function HS(e,t,s={}){return(s=zS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var WS=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=HS(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=zS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){$S(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:$S,saveRendererAndSceneState:HS,saveRendererState:zS});class jS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class qS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class KS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class XS extends qS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class YS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const n=new tr(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),Sn()):hn(new this.nodes[e])}}class QS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const n=r[e];t[e]=s[n]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class ZS extends rr{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new YS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),n=new QS;n.setTextures(t),n.setNodes(r),n.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,i=this.getRenderObjectData(e);if(!0!==i.worldMatrix.equals(t.matrixWorld))return i.worldMatrix.copy(t.matrixWorld),!1;const n=i.material;for(const e in n){const t=n[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return n[e]=r,!1}if(n.transmission>0){const{width:t,height:s}=e.context;if(i.bufferWidth!==t||i.bufferHeight!==s)return i.bufferWidth=t,i.bufferHeight=s,!1}const o=i.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return i.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(i.morphTargetInfluences){let e=!1;for(let s=0;s>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:i}of cr(e))s.push(s,or(r.slice(0,-4)),i.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;ee.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of cr(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let r=null;const i=e.getBuildStage();if("setup"===i){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===i)this.analyze(e);else if("generate"===i){if(1===this.generate.length){const s=this.getNodeType(e),i=e.getDataFromNode(this);r=i.snippet,void 0===r?(r=this.generate(e)||"",i.snippet=r):void 0!==i.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:i,childNode:n}of t)void 0!==i?(void 0===s[r]&&(s[r]=Number.isInteger(i)?[]:{}),s[r][i]=n.toJSON(e.meta).uuid):s[r]=n.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const i of e.inputNodes[s])r.push(t[i]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const i in e.inputNodes[s]){const n=e.inputNodes[s][i];r[i]=t[n]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let i=e.nodes[t];function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===i&&(i={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[i.uuid]=i),this.serialize(i),delete i.meta),r){const t=n(e.textures),s=n(e.images),r=n(e.nodes);t.length>0&&(i.textures=t),s.length>0&&(i.images=s),r.length>0&&(i.nodes=r)}return i}}class Rr extends Ar{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,r=this.getNodeType(e),i=s.build(e,r);return e.format(i,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const i=super.build(e,s),n=e.getVarFromNode(this,null,s),o=e.getPropertyName(n);return e.addLineFlowCode(`${o} = ${i}`,this),r.snippet=i,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,s)=>t+e.getTypeLength(s.getNodeType(e))),0))}generate(e,t){const s=this.getNodeType(e),r=this.nodes,i=e.getComponentType(s),n=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==i&&(s=e.format(s,r,i)),n.push(s)}const o=`${e.getType(s)}( ${n.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(vr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,r=e.getTypeLength(s.getNodeType(e));let i=null;if(r>1){let n=null;this.getVectorLength()>=r&&(n=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,n);i=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,n,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else i=s.build(e,t);return i}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:r}=this,i=this.getNodeType(e),n=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,n),a=t.build(e,i),u=e.getTypeLength(i),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(hi(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),ci(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>ci(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>ci(new Fr(ci(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),ci(new Br(e,t));if(!0===/^\d+$/.test(t))return ci(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=ci(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;rci(null!==r?Object.assign(e,r):e);return null===t?(...t)=>i(new e(...pi(t))):null!==s?(s=ci(s),(...r)=>i(new e(t,...pi(r),s))):(...s)=>i(new e(t,...pi(s)))},qr=function(e,...t){return ci(new e(...pi(t)))};class Kr extends Ar{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let i=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let n=r.get(t);void 0===n&&(n=ci(e.buildFunctionNode(t)),r.set(t,n)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(n),i=ci(n.call(s))}else{const r=t.jsFunc,n=null!==s?r(s,e):r(e);i=ci(n)}return t.once&&(r.onceOutput=i),i}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return hi(e),ci(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],ei=new Map;for(const e of Yr)ei.set(e,new Ir(e));const ti=new Map;for(const e of Qr)ti.set(e,new Ir(e,"uint"));const si=new Map([...ti].map((e=>new Ir(e.value,"int"))));for(const e of Zr)si.set(e,new Ir(e,"int"));const ri=new Map([...si].map((e=>new Ir(e.value))));for(const e of Jr)ri.set(e,new Ir(e));for(const e of Jr)ri.set(-e,new Ir(-e));const ii={bool:ei,uint:ti,ints:si,float:ri},ni=new Map([...ei,...ri]),oi=(e,t)=>ni.has(e)?ni.get(e):!0===e.isNode?e:new Ir(e,t),ai=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return ci(t.get(s[0]));if(1===s.length){const t=oi(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?ci(t):ci(new Cr(t,e))}const r=s.map((e=>oi(e)));return ci(new wr(r,e))}},ui=e=>"object"==typeof e&&null!==e?e.value:e,li=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function di(e,t){return new Proxy(new Xr(e,t),kr)}const ci=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?ci(oi(e,t)):"shader"===s?fi(e):e}(e,t),hi=(e,t=null)=>new Hr(e,t),pi=(e,t=null)=>new Wr(e,t),gi=(...e)=>new jr(...e),mi=(...e)=>new qr(...e),fi=(e,t)=>{const s=new di(e,t),r=(...e)=>{let t;return hi(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},yi=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),fi(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const bi=e=>{Lr=e},xi=()=>Lr,Ti=(...e)=>Lr.If(...e);function _i(e){return Lr&&Lr.add(e),e}Vr("append",_i);const Ni=new ai("color"),vi=new ai("float",ii.float),Si=new ai("int",ii.ints),Ai=new ai("uint",ii.uint),Ri=new ai("bool",ii.bool),Ci=new ai("vec2"),Ei=new ai("ivec2"),wi=new ai("uvec2"),Mi=new ai("bvec2"),Bi=new ai("vec3"),Ui=new ai("ivec3"),Fi=new ai("uvec3"),Pi=new ai("bvec3"),Ii=new ai("vec4"),Li=new ai("ivec4"),Di=new ai("uvec4"),Vi=new ai("bvec4"),Oi=new ai("mat2"),Gi=new ai("mat3"),ki=new ai("mat4"),zi=(e="")=>ci(new Ir(e,"string")),$i=e=>ci(new Ir(e,"ArrayBuffer"));Vr("toColor",Ni),Vr("toFloat",vi),Vr("toInt",Si),Vr("toUint",Ai),Vr("toBool",Ri),Vr("toVec2",Ci),Vr("toIVec2",Ei),Vr("toUVec2",wi),Vr("toBVec2",Mi),Vr("toVec3",Bi),Vr("toIVec3",Ui),Vr("toUVec3",Fi),Vr("toBVec3",Pi),Vr("toVec4",Ii),Vr("toIVec4",Li),Vr("toUVec4",Di),Vr("toBVec4",Vi),Vr("toMat2",Oi),Vr("toMat3",Gi),Vr("toMat4",ki);const Hi=gi(Rr),Wi=(e,t)=>ci(new Cr(ci(e),t)),ji=(e,t)=>ci(new Br(ci(e),t));Vr("element",Hi),Vr("convert",Wi);class qi extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Ki=e=>new qi(e),Xi=(e,t=0)=>new qi(e,!0,t),Yi=Xi("frame"),Qi=Xi("render"),Zi=Ki("object");class Ji extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Zi}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let i=e.getNodeFromHash(r);void 0===i&&(e.setHashNode(this,r),i=this);const n=i.getInputType(e),o=e.getUniformFromNode(i,n,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const en=(e,t)=>{const s=li(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return ci(new Ji(r,s))};class tn extends Ar{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const sn=(e,t)=>ci(new tn(e,t)),rn=(e,t)=>ci(new tn(e,t,!0)),nn=mi(tn,"vec4","DiffuseColor"),on=mi(tn,"vec3","EmissiveColor"),an=mi(tn,"float","Roughness"),un=mi(tn,"float","Metalness"),ln=mi(tn,"float","Clearcoat"),dn=mi(tn,"float","ClearcoatRoughness"),cn=mi(tn,"vec3","Sheen"),hn=mi(tn,"float","SheenRoughness"),pn=mi(tn,"float","Iridescence"),gn=mi(tn,"float","IridescenceIOR"),mn=mi(tn,"float","IridescenceThickness"),fn=mi(tn,"float","AlphaT"),yn=mi(tn,"float","Anisotropy"),bn=mi(tn,"vec3","AnisotropyT"),xn=mi(tn,"vec3","AnisotropyB"),Tn=mi(tn,"color","SpecularColor"),_n=mi(tn,"float","SpecularF90"),Nn=mi(tn,"float","Shininess"),vn=mi(tn,"vec4","Output"),Sn=mi(tn,"float","dashSize"),An=mi(tn,"float","gapSize"),Rn=mi(tn,"float","pointWidth"),Cn=mi(tn,"float","IOR"),En=mi(tn,"float","Transmission"),wn=mi(tn,"float","Thickness"),Mn=mi(tn,"float","AttenuationDistance"),Bn=mi(tn,"color","AttenuationColor"),Un=mi(tn,"float","Dispersion");class Fn extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,i=this.needsSplitAssign(e),n=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,n),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(i){const r=e.getVarFromNode(this,null,n),i=e.getPropertyName(r);e.addLineFlowCode(`${i} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t{const r=s.type;let i;return i="pointer"===r?"&"+t.build(e):t.build(e,r),i};if(Array.isArray(i))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?pi(t):hi(t[0]),ci(new In(ci(e),t)));Vr("call",Ln);class Dn extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let i=new Dn(e,t,s);for(let t=0;t>"===s||"<<"===s)return e.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(n),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&e.isMatrix(o)?o:e.isMatrix(n)&&e.isVector(o)?e.getVectorFromMatrix(n):e.isVector(n)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(n)?o:n}generate(e,t){const s=this.op,r=this.aNode,i=this.bNode,n=this.getNodeType(e,t);let o=null,a=null;"void"!==n?(o=r.getNodeType(e),a=void 0!==i?i.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=n,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=n):o=a=n;const u=r.build(e,o),l=void 0!==i?i.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} < ${l} )`,n,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} <= ${l} )`,n,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} > ${l} )`,n,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,n,t):e.format(`( ${u} >= ${l} )`,n,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,n,t):e.format(`( ${u} ${s} ${l} )`,n,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,n,t):e.format(`${u} ${s} ${l}`,n,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vn=gi(Dn,"+"),On=gi(Dn,"-"),Gn=gi(Dn,"*"),kn=gi(Dn,"/"),zn=gi(Dn,"%"),$n=gi(Dn,"=="),Hn=gi(Dn,"!="),Wn=gi(Dn,"<"),jn=gi(Dn,">"),qn=gi(Dn,"<="),Kn=gi(Dn,">="),Xn=gi(Dn,"&&"),Yn=gi(Dn,"||"),Qn=gi(Dn,"!"),Zn=gi(Dn,"^^"),Jn=gi(Dn,"&"),eo=gi(Dn,"~"),to=gi(Dn,"|"),so=gi(Dn,"^"),ro=gi(Dn,"<<"),io=gi(Dn,">>");Vr("add",Vn),Vr("sub",On),Vr("mul",Gn),Vr("div",kn),Vr("modInt",zn),Vr("equal",$n),Vr("notEqual",Hn),Vr("lessThan",Wn),Vr("greaterThan",jn),Vr("lessThanEqual",qn),Vr("greaterThanEqual",Kn),Vr("and",Xn),Vr("or",Yn),Vr("not",Qn),Vr("xor",Zn),Vr("bitAnd",Jn),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",io);const no=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zn(...e));Vr("remainder",no);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,i=e.isMatrix(t)?0:e.getTypeLength(t),n=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return i>n&&i>o?t:n>o?s:o>i?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),i=this.getInputType(e),n=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=n,r=o;e.isMatrix(s.getNodeType(e))?r=Ii(Bi(r),0):s=Ii(Bi(s),0);const i=Gn(s,r).xyz;return Ao(i).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+n.build(e,i)+" )",r,t);if(s===oo.ONE_MINUS)return On(1,n).build(e,t);if(s===oo.RECIPROCAL)return kn(1,n).build(e,t);if(s===oo.DIFFERENCE)return Fo(On(n,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(n.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(n.build(e,1===e.getTypeLength(n.getNodeType(e))?"float":i),o.build(e,i)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(n.build(e,i),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":i)):s===oo.REFRACT?l.push(n.build(e,i),o.build(e,i),a.build(e,"float")):s===oo.MIX?l.push(n.build(e,i),o.build(e,i),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":i)):(l.push(n.build(e,i)),null!==o&&l.push(o.build(e,i)),null!==a&&l.push(a.build(e,i))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=vi(1e-6),uo=vi(1e6),lo=vi(Math.PI),co=vi(2*Math.PI),ho=gi(oo,oo.ALL),po=gi(oo,oo.ANY),go=gi(oo,oo.EQUALS),mo=gi(oo,oo.RADIANS),fo=gi(oo,oo.DEGREES),yo=gi(oo,oo.EXP),bo=gi(oo,oo.EXP2),xo=gi(oo,oo.LOG),To=gi(oo,oo.LOG2),_o=gi(oo,oo.SQRT),No=gi(oo,oo.INVERSE_SQRT),vo=gi(oo,oo.FLOOR),So=gi(oo,oo.CEIL),Ao=gi(oo,oo.NORMALIZE),Ro=gi(oo,oo.FRACT),Co=gi(oo,oo.SIN),Eo=gi(oo,oo.COS),wo=gi(oo,oo.TAN),Mo=gi(oo,oo.ASIN),Bo=gi(oo,oo.ACOS),Uo=gi(oo,oo.ATAN),Fo=gi(oo,oo.ABS),Po=gi(oo,oo.SIGN),Io=gi(oo,oo.LENGTH),Lo=gi(oo,oo.NEGATE),Do=gi(oo,oo.ONE_MINUS),Vo=gi(oo,oo.DFDX),Oo=gi(oo,oo.DFDY),Go=gi(oo,oo.ROUND),ko=gi(oo,oo.RECIPROCAL),zo=gi(oo,oo.TRUNC),$o=gi(oo,oo.FWIDTH),Ho=gi(oo,oo.BITCAST),Wo=gi(oo,oo.TRANSPOSE),jo=gi(oo,oo.ATAN2),qo=gi(oo,oo.MIN),Ko=gi(oo,oo.MAX),Xo=gi(oo,oo.MOD),Yo=gi(oo,oo.STEP),Qo=gi(oo,oo.REFLECT),Zo=gi(oo,oo.DISTANCE),Jo=gi(oo,oo.DIFFERENCE),ea=gi(oo,oo.DOT),ta=gi(oo,oo.CROSS),sa=gi(oo,oo.POW),ra=gi(oo,oo.POW,2),ia=gi(oo,oo.POW,3),na=gi(oo,oo.POW,4),oa=gi(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gn(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=gi(oo,oo.MIX),da=(e,t=0,s=1)=>ci(new oo(oo.CLAMP,ci(e),ci(t),ci(s))),ca=e=>da(e),ha=gi(oo,oo.REFRACT),pa=gi(oo,oo.SMOOTHSTEP),ga=gi(oo,oo.FACEFORWARD),ma=fi((([e])=>{const t=ea(e.xy,Ci(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",ia),Vr("pow4",na),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,i=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=i,null!==r&&(e.getDataFromNode(r).parentNodeBlock=i);const n=e.getNodeProperties(this);n.condNode=t,n.ifNode=s.context({nodeBlock:s}),n.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:i,ifNode:n,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?sn(s).build(e):"";r.nodeProperty=u;const l=i.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=n.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=gi(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e,t);return e.setContext(s),r}}const Na=gi(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),i=e.getPropertyName(r),n=t.build(e,r.type);return e.addLineFlowCode(`${i} = ${n}`,this),i}}const Aa=gi(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const r=this.name,i=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,i),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const r=this.getNodeType(e),i=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,i),t.propertyName=i}return e.getPropertyName(s)}}const Ea=gi(Ca);Vr("varying",Ea);const wa=fi((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=fi((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let n=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(n=Ii(wa(n.rgb),n.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(n=Ii(Gi(u._getMatrix(new i,s,r)).mul(n.rgb),n.a)),u.getTransfer(r)===l&&(n=Ii(Ma(n.rgb),n.a)),n):n}}const Pa=e=>ci(new Fa(ci(e),Ba,Ua)),Ia=e=>ci(new Fa(ci(e),Ua,Ba)),La=(e,t)=>ci(new Fa(ci(e),Ba,t)),Da=(e,t)=>ci(new Fa(ci(e),t,Ba)),Va=(e,t,s)=>ci(new Fa(ci(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return ci(new Oa(this,ci(e)))}setNodeType(e){const t=en(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;eci(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const i=e.renderer.library.getToneMappingFunction(s);return null!==i?r=Ii(i(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>ci(new $a(e,ci(t),ci(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),i=this.bufferStride||r,n=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,i),a=new g(o,r,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let i=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,i=r;else{i=Ea(this).build(e,t)}return i}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>ci(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;eci(new Qa(ci(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const i=this.node.build(e,...t);return e.setCache(s),i}}const eu=(e,...t)=>ci(new Ja(ci(e),...t));Vr("cache",eu);class tu extends Ar{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const su=gi(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=vi(0),i=vi(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=i,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:i,doClamp:n}=this;let o=e.sub(t).div(s.sub(t));return!0===n&&(o=o.clamp()),o.mul(i.sub(r)).add(r)}}const iu=gi(ru,null,null,{doClamp:!1}),nu=gi(ru);Vr("remap",iu),Vr("remapClamp",nu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=gi(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>ci(new du(ci(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),i=e.getTypeFromAttribute(r),n=e.getAttribute(t,i);if("vertex"===e.shaderStage)return e.format(n.name,i,s);return Ea(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const gu=(e,t)=>ci(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=gi(fu);class bu extends Ji{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=gi(bu);class Tu extends Ji{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=en(this.value.matrix)),this._matrixUniform.mul(Bi(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&!0===s.flipY||!0===s.isRenderTargetTexture||!0===s.isFramebufferTexture||!0===s.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(Si(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,i,n,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,n):i?e.generateTextureBias(u,t,s,i,n):a?e.generateTextureGrad(u,t,s,a,n):o?e.generateTextureCompare(u,t,s,o,n):!1===this.sampler?e.generateTextureLoad(u,t,s,n):e.generateTexture(u,t,s,n),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const i=super.generate(e,"property");if("sampler"===t)return i+"_sampler";if(e.isReference(t))return i;{const n=e.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,i,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),n.snippet=b,n.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}blur(e){const t=this.clone();return t.biasNode=ci(e).mul(xu(t)),t.referenceNode=this.getSelf(),ci(t)}level(e){const t=this.clone();return t.levelNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}compare(e){const t=this.clone();return t.compareNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}grad(e,t){const s=this.clone();return s.gradNode=[ci(e),ci(t)],s.referenceNode=this.getSelf(),ci(s)}depth(e){const t=this.clone();return t.depthNode=ci(e),t.referenceNode=this.getSelf(),ci(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=gi(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=en("float").label("cameraNear").setGroup(Qi).onRenderUpdate((({camera:e})=>e.near)),Au=en("float").label("cameraFar").setGroup(Qi).onRenderUpdate((({camera:e})=>e.far)),Ru=en("mat4").label("cameraProjectionMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=en("mat4").label("cameraProjectionMatrixInverse").setGroup(Qi).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=en("mat4").label("cameraViewMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=en("mat4").label("cameraWorldMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=en("mat3").label("cameraNormalMatrix").setGroup(Qi).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=en(new s).label("cameraPosition").setGroup(Qi).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new Ji(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,i=this.scope;if(i===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(i===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(i===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(i===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(i===Uu.VIEW_POSITION){const i=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(i.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=gi(Uu,Uu.DIRECTION),Pu=gi(Uu,Uu.WORLD_MATRIX),Iu=gi(Uu,Uu.POSITION),Lu=gi(Uu,Uu.SCALE),Du=gi(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=mi(Vu,Vu.DIRECTION),Gu=mi(Vu,Vu.WORLD_MATRIX),ku=mi(Vu,Vu.POSITION),zu=mi(Vu,Vu.SCALE),$u=mi(Vu,Vu.VIEW_POSITION),Hu=en(new i).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=en(new n).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=fi((e=>(e.context.isHighPrecisionModelViewMatrix=!0,en("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=fi((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return en("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=mi(sl),il=vi(rl).mul(2).sub(1),nl=gu("normal","vec3"),ol=fi((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Bi(0,1,0)):nl),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=fi((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=fi((e=>e.context.setupNormal()),"vec3").once()().mul(il).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=fi((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(il).toVar("transformedClearcoatNormalView"),pl=fi((([e,t=Gu])=>{const s=Gi(t),r=e.div(Bi(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=fi((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=en(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Bi(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Bi(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=gi(Tl);class Nl extends Ji{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const vl=(e,t,s)=>ci(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;sci(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),ci(new Al(e,t)));class El extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return ci(new El(this,ci(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):en(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;eci(new wl(e,t,s)),Bl=(e,t,s,r)=>ci(new wl(e,t,r,s));class Ul extends wl{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>ci(new Ul(e,t,s)),Pl=fi((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ii(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(nl.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=Gi(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xn.cross(tl);return e=e.cross(xn).normalize(),e=la(e,dl,yn.mul(an.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=fi((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:i}=e,n=t.dFdx(),o=t.dFdy(),a=i.dFdx(),u=i.dFdy(),l=s,d=o.cross(l),c=l.cross(n),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=il.mul(g.inverseSqrt());return Vn(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Bi(r.xy.mul(s),r.z));let i=null;if(t===S)i=gl(r);else if(t===v){i=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return i}}const Jl=gi(Zl),ed=fi((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=vi(s((e=>e)));return Ci(vi(s((e=>e.add(e.dFdx())))).sub(r),vi(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=fi((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,i=t.dFdx().normalize(),n=s,o=t.dFdy().normalize().cross(n),a=n.cross(i),u=i.dot(o).mul(il),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=gi(sd),id=new Map;class nd extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=id.get(e);return void 0===s&&(s=Fl(e,t),id.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===nd.COLOR){const e=void 0!==t.color?this.getColor(s):Bi();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===nd.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===nd.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:vi(1);else if(s===nd.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===nd.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===nd.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===nd.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===nd.EMISSIVE){const e=this.getFloat("emissiveIntensity"),i=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?i.mul(this.getTexture(s)):i}else if(s===nd.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===nd.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===nd.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===nd.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===nd.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===nd.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===nd.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Oi($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(Ci(1)).normalize().mul(e.b))}else r=$d;else if(s===nd.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const i=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(i).mul(this.getTexture(s).g).add(i)}else r=e}else if(s===nd.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===nd.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===nd.IOR)r=this.getFloat(s);else if(s===nd.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===nd.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}nd.ALPHA_TEST="alphaTest",nd.COLOR="color",nd.OPACITY="opacity",nd.SHININESS="shininess",nd.SPECULAR="specular",nd.SPECULAR_STRENGTH="specularStrength",nd.SPECULAR_INTENSITY="specularIntensity",nd.SPECULAR_COLOR="specularColor",nd.REFLECTIVITY="reflectivity",nd.ROUGHNESS="roughness",nd.METALNESS="metalness",nd.NORMAL="normal",nd.CLEARCOAT="clearcoat",nd.CLEARCOAT_ROUGHNESS="clearcoatRoughness",nd.CLEARCOAT_NORMAL="clearcoatNormal",nd.EMISSIVE="emissive",nd.ROTATION="rotation",nd.SHEEN="sheen",nd.SHEEN_ROUGHNESS="sheenRoughness",nd.ANISOTROPY="anisotropy",nd.IRIDESCENCE="iridescence",nd.IRIDESCENCE_IOR="iridescenceIOR",nd.IRIDESCENCE_THICKNESS="iridescenceThickness",nd.IOR="ior",nd.TRANSMISSION="transmission",nd.THICKNESS="thickness",nd.ATTENUATION_DISTANCE="attenuationDistance",nd.ATTENUATION_COLOR="attenuationColor",nd.LINE_SCALE="scale",nd.LINE_DASH_SIZE="dashSize",nd.LINE_GAP_SIZE="gapSize",nd.LINE_WIDTH="linewidth",nd.LINE_DASH_OFFSET="dashOffset",nd.POINT_WIDTH="pointWidth",nd.DISPERSION="dispersion",nd.LIGHT_MAP="light",nd.AO_MAP="ao";const od=mi(nd,nd.ALPHA_TEST),ad=mi(nd,nd.COLOR),ud=mi(nd,nd.SHININESS),ld=mi(nd,nd.EMISSIVE),dd=mi(nd,nd.OPACITY),cd=mi(nd,nd.SPECULAR),hd=mi(nd,nd.SPECULAR_INTENSITY),pd=mi(nd,nd.SPECULAR_COLOR),gd=mi(nd,nd.SPECULAR_STRENGTH),md=mi(nd,nd.REFLECTIVITY),fd=mi(nd,nd.ROUGHNESS),yd=mi(nd,nd.METALNESS),bd=mi(nd,nd.NORMAL).context({getUV:null}),xd=mi(nd,nd.CLEARCOAT),Td=mi(nd,nd.CLEARCOAT_ROUGHNESS),_d=mi(nd,nd.CLEARCOAT_NORMAL).context({getUV:null}),Nd=mi(nd,nd.ROTATION),vd=mi(nd,nd.SHEEN),Sd=mi(nd,nd.SHEEN_ROUGHNESS),Ad=mi(nd,nd.ANISOTROPY),Rd=mi(nd,nd.IRIDESCENCE),Cd=mi(nd,nd.IRIDESCENCE_IOR),Ed=mi(nd,nd.IRIDESCENCE_THICKNESS),wd=mi(nd,nd.TRANSMISSION),Md=mi(nd,nd.THICKNESS),Bd=mi(nd,nd.IOR),Ud=mi(nd,nd.ATTENUATION_DISTANCE),Fd=mi(nd,nd.ATTENUATION_COLOR),Pd=mi(nd,nd.LINE_SCALE),Id=mi(nd,nd.LINE_DASH_SIZE),Ld=mi(nd,nd.LINE_GAP_SIZE),Dd=mi(nd,nd.LINE_WIDTH),Vd=mi(nd,nd.LINE_DASH_OFFSET),Od=mi(nd,nd.POINT_WIDTH),Gd=mi(nd,nd.DISPERSION),kd=mi(nd,nd.LIGHT_MAP),zd=mi(nd,nd.AO_MAP),$d=en(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=gi(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,i;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)i=r;else{i=Ea(this).build(e,t)}return i}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=mi(jd,jd.VERTEX),Kd=mi(jd,jd.INSTANCE),Xd=mi(jd,jd.SUBGROUP),Yd=mi(jd,jd.INVOCATION_SUBGROUP),Qd=mi(jd,jd.INVOCATION_LOCAL),Zd=mi(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,i=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=ki(...i)}this.instanceMatrixNode=t}const i=r.instanceColor;if(i&&null===s){const e=new R(i.array,3),t=i.usage===p?Ya:Xa;this.bufferColor=e,s=Bi(t(e,"vec3",3,0)),this.instanceColorNode=s}const n=t.mul(Yu).xyz;if(Yu.assign(n),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&rn("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=gi(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=fi((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=Si(e).modInt(Si(t)),r=Si(e).div(Si(t));return Nu(this.batchMesh._indirectTexture,Ei(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(Si(this.batchingIdNode)),r=this.batchMesh._matricesTexture,i=yu(Nu(r),0),n=vi(s).mul(4).toInt().toVar(),o=n.modInt(i),a=n.div(Si(i)),u=ki(Nu(r,Ei(o,a)),Nu(r,Ei(o.add(1),a)),Nu(r,Ei(o.add(2),a)),Nu(r,Ei(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=fi((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),i=s.div(t);return Nu(l,Ei(r,i)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);rn("vec3","vBatchColor").assign(t)}const d=Gi(u);Yu.assign(u.mul(Yu));const c=ol.div(Bi(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=gi(tc),rc=new WeakMap;class ic extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,i;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),i=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=en(e.bindMatrix,"mat4"),r=en(e.bindMatrixInverse,"mat4"),i=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=i,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:i,bindMatrixInverseNode:n}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=i.mul(t),c=Vn(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return n.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:i,bindMatrixInverseNode:n}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vn(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=n.mul(d).mul(i),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const nc=e=>ci(new ic(e)),oc=e=>ci(new ic(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;eNumber(n)?">=":"<"));const d={start:i,end:n,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const i=r.build(e,"void"),n=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+i);for(let t=0,s=this.params.length-1;tci(new ac(pi(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=fi((({bufferMap:e,influence:t,stride:s,width:r,depth:i,offset:n})=>{const o=Si(qd).mul(s).add(n),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,Ei(u,a)).depth(i).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=en(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,i=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,n=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==n?n.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,i=void 0!==e.morphAttributes.color,n=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==n?n.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===i&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=vi(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,Ei(Si(e).add(1),Si(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:Si(0)})),!0===i&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:Si(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=gi(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Bi().toVar("directDiffuse"),directSpecular:Bi().toVar("directSpecular"),indirectDiffuse:Bi().toVar("indirectDiffuse"),indirectSpecular:Bi().toVar("indirectSpecular")};return{radiance:Bi().toVar("radiance"),irradiance:Bi().toVar("irradiance"),iblIrradiance:Bi().toVar("iblIrradiance"),ambientOcclusion:vi(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Tc=gi(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?en(Nc||(Nc=new t)):e===Sc.VIEWPORT?en(vc||(vc=new r)):Ci(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=mi(Sc,Sc.UV),Rc=mi(Sc,Sc.SIZE),Cc=mi(Sc,Sc.COORDINATE),Ec=mi(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=fi((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=fi((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=fi((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=gi(Lc),Vc=gi(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=gi(Gc);class zc extends Ar{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Xc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.negate().div(t)),i=To(s.div(t));return r.div(i)},Kc=(e,t,s)=>{const r=e.mul(xo(s.div(t)));return vi(Math.E).pow(r).mul(t).negate()},Xc=gi(zc,zc.DEPTH_BASE),Yc=mi(zc,zc.DEPTH),Qc=gi(zc,zc.LINEAR_DEPTH),Zc=Qc(kc());Yc.assign=e=>Xc(e);const Jc=gi(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class eh extends Ar{static get type(){return"ClippingNode"}constructor(e=eh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===eh.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===eh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return fi((()=>{const s=vi().toVar("distanceToPlane"),r=vi().toVar("distanceToGradient"),i=vi(1).toVar("clipOpacity"),n=t.length;if(!this.hardwareClipping&&n>0){const e=Rl(t);uc(n,(({i:t})=>{const n=e.element(t);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),n=vi(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const i=t.element(e);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s).oneMinus())})),i.mulAssign(n.oneMinus())}nn.a.mulAssign(i),nn.a.equal(0).discard()}))()}setupDefault(e,t){return fi((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Ri(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),fi((()=>{const r=Rl(e),i=Jc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();i.element(e).assign(s)}))}))()}}eh.ALPHA_TO_COVERAGE="alphaToCoverage",eh.DEFAULT="default",eh.HARDWARE="hardware";const th=fi((([e])=>Ro(Gn(1e4,Co(Gn(17,e.x).add(Gn(.1,e.y)))).mul(Vn(.1,Fo(Co(Gn(13,e.y).add(e.x)))))))),sh=fi((([e])=>th(Ci(th(e.xy),e.z)))),rh=fi((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=vi(1).div(vi(.05).mul(t)).toVar("pixScale"),r=Ci(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),i=Ci(sh(vo(r.x.mul(e.xyz))),sh(vo(r.y.mul(e.xyz)))).toVar("alpha"),n=Ro(To(s)).toVar("lerpFactor"),o=Vn(Gn(n.oneMinus(),i.x),Gn(n,i.y)).toVar("x"),a=qo(n,n.oneMinus()).toVar("a"),u=Bi(o.mul(o).div(Gn(2,a).mul(On(1,a))),o.sub(Gn(.5,a)).div(On(1,a)),On(1,On(1,o).mul(On(1,o)).div(Gn(2,a).mul(On(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class ih extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new nr(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const i=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const n=this.setupLighting(e);null!==i&&e.stack.add(i);const o=Ii(n,nn.a).max(0);if(r=this.setupOutput(e,o),vn.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ii(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=ci(new eh(eh.ALPHA_TO_COVERAGE)):e.stack.add(ci(new eh))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(ci(new eh(eh.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(el.z,Su,Au):$c(el.z,Su,Au))}null!==r&&Yc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ii(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ii(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=rn("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=rn("vec3","vBatchColor").mul(s)}nn.assign(s);const r=this.opacityNode?vi(this.opacityNode):dd;if(nn.a.assign(nn.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?vi(this.alphaTestNode):od;nn.a.lessThanEqual(e).discard()}!0===this.alphaHash&&nn.a.lessThan(rh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&nn.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Bi(0):nn.rgb}setupNormal(){return this.normalNode?Bi(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let i=this.lightsNode||e.lightsNode;return t.length>0&&(i=e.renderer.lighting.createNode([...i.getLights(),...t])),i}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:i}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(n&&n.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(n,t,s,r)}else null!==s&&(o=Bi(null!==r?la(o,s,r):s));return(i&&!0===i.isNode||t.emissive&&!0===t.emissive.isColor)&&(on.assign(Bi(i||ld)),o=o.add(on)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ii(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:i}of r)s.inputNodes[t]=i.toJSON(e).uuid;function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=i(e.textures),r=i(e.images),n=i(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),n.length>0&&(s.nodes=n)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const nh=new P;class oh extends ih{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(nh),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=fi((()=>{const e=gu("instancePosition").xyz,t=Ii(ju.mul(Ii(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),i=Xu.xy.toVar();return i.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),i.assign(i.div(Ec.z)),i.y.assign(i.y.mul(s)),i.assign(i.mul(r.w)),r.addAssign(Ii(i,0,0)),r}))(),this.fragmentNode=fi((()=>{const r=vi(1).toVar(),i=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=vi(i.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),i).oneMinus())}else i.greaterThan(1).discard();let n;if(this.pointColorNode)n=this.pointColorNode;else if(s){n=gu("instanceColor").mul(ad)}else n=ad;return r.mulAssign(dd),Ii(n,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ah=new I;class uh extends ih{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(ah),this.setValues(e)}}const lh=new L;class dh extends ih{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(lh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?vi(this.offsetNodeNode):Vd,t=this.dashScaleNode?vi(this.dashScaleNode):Pd,s=this.dashSizeNode?vi(this.dashSizeNode):Id,r=this.dashSizeNode?vi(this.dashGapNode):Ld;Sn.assign(s),An.assign(r);const i=Ea(gu("lineDistance").mul(t));(e?i.add(e):i).mod(Sn.add(An)).greaterThan(Sn).discard()}}const ch=new L;class hh extends ih{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ch),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,i=this.worldUnits,n=fi((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ii(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=fi((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ii(ju.mul(Ii(e,1))).toVar("start"),o=Ii(ju.mul(Ii(t,1))).toVar("end");if(r){const e=this.dashScaleNode?vi(this.dashScaleNode):Pd,t=this.offsetNode?vi(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let i=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));i=i.add(t),rn("float","lineDistance").assign(i)}i&&(rn("vec3","worldStart").assign(s.xyz),rn("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);Ti(u,(()=>{Ti(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(n({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(n({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ii().toVar();if(i){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),i=e.cross(t).normalize(),n=e.cross(i),a=rn("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ii(Xu.x.lessThan(0).select(i.mul(u),i.mul(u).negate()),0)),r||(a.addAssign(Ii(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ii(n.mul(u),0)),Ti(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ii(n.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Bi().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=Ci(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),Ti(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ii(e,0,0)))}return g}))();const o=fi((({p1:e,p2:t,p3:s,p4:r})=>{const i=e.sub(s),n=r.sub(s),o=t.sub(e),a=i.dot(n),u=n.dot(o),l=i.dot(o),d=n.dot(n),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return Ci(h,p)}));this.fragmentNode=fi((()=>{const n=mu();if(r){const e=this.dashSizeNode?vi(this.dashSizeNode):Id,t=this.dashSizeNode?vi(this.dashGapNode):Ld;Sn.assign(e),An.assign(t);const s=rn("float","lineDistance");n.y.lessThan(-1).or(n.y.greaterThan(1)).discard(),s.mod(Sn.add(An)).greaterThan(Sn).discard()}const a=vi(1).toVar("alpha");if(i){const s=rn("vec3","worldStart"),i=rn("vec3","worldEnd"),n=rn("vec4","worldPos").xyz.normalize().mul(1e5),u=i.sub(s),l=o({p1:s,p2:i,p3:Bi(0,0,0),p4:n}),d=s.add(u.mul(l.x)),c=n.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1)),s=e.mul(e).add(t.mul(t)),r=vi(s.fwidth()).toVar("dlen");Ti(n.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else Ti(n.y.abs().greaterThan(1),(()=>{const e=n.x,t=n.y.greaterThan(0).select(n.y.sub(1),n.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ii(u,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ph=e=>ci(e).mul(.5).add(.5),gh=e=>ci(e).mul(2).sub(1),mh=new D;class fh extends ih{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(mh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?vi(this.opacityNode):dd;nn.assign(Ii(ph(dl),e))}}class yh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return Ci(t,s)}}const bh=gi(yh);class xh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const i=new O(5,5,5),n=bh(Ju),o=new ih;o.colorNode=_u(t,n,0),o.side=x,o.blending=G;const a=new k(i,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const Th=new WeakMap;class _h extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(Th.has(e)){const t=Th.get(e);vh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new xh(s.height);r.fromEquirectangularTexture(t,e),vh(r.texture,e.mapping),this._cubeTexture=r.texture,Th.set(e,r.texture),e.addEventListener("dispose",Nh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Nh(e){const t=e.target;t.removeEventListener("dispose",Nh);const s=Th.get(t);void 0!==s&&(Th.delete(t),s.dispose())}function vh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const Sh=gi(_h);class Ah extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Sh(this.envNode)}}class Rh extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=vi(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ch{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Eh extends Ch{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,i=e.reflectedLight,n=s.context.irradianceLightMap;i.indirectDiffuse.assign(Ii(0)),n?i.indirectDiffuse.addAssign(n):i.indirectDiffuse.addAssign(Ii(1,1,1,0)),i.indirectDiffuse.mulAssign(r),i.indirectDiffuse.mulAssign(nn.rgb)}finish(e,t,s){const r=s.material,i=e.outgoingLight,n=s.context.environment;if(n)switch(r.combine){case Y:i.rgb.assign(la(i.rgb,i.rgb.mul(n.rgb),gd.mul(md)));break;case X:i.rgb.assign(la(i.rgb,n.rgb,gd.mul(md)));break;case K:i.rgb.addAssign(n.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const wh=new Q;class Mh extends ih{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Rh(kd)),t}setupOutgoingLight(){return nn.rgb}setupLightingModel(){return new Eh}}const Bh=fi((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Uh=fi((e=>e.diffuseColor.mul(1/Math.PI))),Fh=fi((({dotNH:e})=>Nn.mul(vi(.5)).add(1).mul(vi(1/Math.PI)).mul(e.pow(Nn)))),Ph=fi((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),i=Bh({f0:Tn,f90:1,dotVH:r}),n=vi(.25),o=Fh({dotNH:s});return i.mul(n).mul(o)}));class Ih extends Eh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:nn.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Ph({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:nn}))),s.indirectDiffuse.mulAssign(e)}}const Lh=new Z;class Dh extends ih{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih(!1)}}const Vh=new J;class Oh extends ih{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Vh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih}setupVariants(){const e=(this.shininessNode?vi(this.shininessNode):ud).max(1e-4);Nn.assign(e);const t=this.specularNode||cd;Tn.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Gh=fi((e=>{if(!1===e.geometry.hasAttribute("normal"))return vi(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),kh=fi((e=>{const{roughness:t}=e,s=Gh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),zh=fi((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),i=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return kn(.5,i.add(n).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),$h=fi((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:i,dotBL:n,dotNV:o,dotNL:a})=>{const u=a.mul(Bi(e.mul(s),t.mul(r),o).length()),l=o.mul(Bi(e.mul(i),t.mul(n),a).length());return kn(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hh=fi((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Wh=vi(1/Math.PI),jh=fi((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:i})=>{const n=e.mul(t),o=Bi(t.mul(r),e.mul(i),n.mul(s)),a=o.dot(o),u=n.div(a);return Wh.mul(n.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),qh=fi((e=>{const{lightDirection:t,f0:s,f90:r,roughness:i,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=i.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Bh({f0:s,f90:r,dotVH:g});if(ui(o)&&(y=pn.mix(y,n)),ui(a)){const e=bn.dot(t),s=bn.dot(tl),r=bn.dot(d),i=xn.dot(t),n=xn.dot(tl),o=xn.dot(d);m=$h({alphaT:fn,alphaB:l,dotTV:s,dotBV:n,dotTL:e,dotBL:i,dotNV:h,dotNL:c}),f=jh({alphaT:fn,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=zh({alpha:l,dotNL:c,dotNV:h}),f=Hh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),Kh=fi((({roughness:e,dotNV:t})=>{const s=Ii(-1,-.0275,-.572,.022),r=Ii(1,.0425,1.04,-.04),i=e.mul(s).add(r),n=i.x.mul(i.x).min(t.mul(-9.28).exp2()).mul(i.x).add(i.y);return Ci(-1.04,1.04).mul(n).add(i.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xh=fi((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:i}=e,n=Kh({dotNV:t,roughness:i});return s.mul(n.x).add(r.mul(n.y))})),Yh=fi((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),i=r.mul(r),n=r.mul(i,i).clamp(0,.9999);return e.sub(Bi(t).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qh=fi((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=vi(1).div(s),i=t.pow2().oneMinus().max(.0078125);return vi(2).add(r).mul(i.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Zh=fi((({dotNV:e,dotNL:t})=>vi(1).div(vi(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Jh=fi((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),i=dl.dot(t).clamp(),n=Qh({roughness:hn,dotNH:i}),o=Zh({dotNV:r,dotNL:s});return cn.mul(n).mul(o)})),ep=fi((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),i=Ci(s,r.oneMinus().sqrt());return i.assign(i.mul(.984375).add(.0078125)),i})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),tp=fi((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sp=fi((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),i=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),n=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=i.div(n),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),rp=fi((({N:e,V:t,P:s,mInv:r,p0:i,p1:n,p2:o,p3:a})=>{const u=n.sub(i).toVar(),l=a.sub(i).toVar(),d=u.cross(l),c=Bi().toVar();return Ti(d.dot(s.sub(i)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(Gi(u,l,e).transpose()).toVar(),h=d.mul(i.sub(s)).normalize().toVar(),p=d.mul(n.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Bi(0).toVar();f.addAssign(sp({v1:h,v2:p})),f.addAssign(sp({v1:p,v2:g})),f.addAssign(sp({v1:g,v2:m})),f.addAssign(sp({v1:m,v2:h})),c.assign(Bi(tp({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),ip=1/6,np=e=>Gn(ip,Gn(e,Gn(e,e.negate().add(3)).sub(3)).add(1)),op=e=>Gn(ip,Gn(e,Gn(e,Gn(3,e).sub(6))).add(4)),ap=e=>Gn(ip,Gn(e,Gn(e,Gn(-3,e).add(3)).add(3)).add(1)),up=e=>Gn(ip,sa(e,3)),lp=e=>np(e).add(op(e)),dp=e=>ap(e).add(up(e)),cp=e=>Vn(-1,op(e).div(np(e).add(op(e)))),hp=e=>Vn(1,up(e).div(ap(e).add(up(e)))),pp=(e,t,s)=>{const r=e.uvNode,i=Gn(r,t.zw).add(.5),n=vo(i),o=Ro(i),a=lp(o.x),u=dp(o.x),l=cp(o.x),d=hp(o.x),c=cp(o.y),h=hp(o.y),p=Ci(n.x.add(l),n.y.add(c)).sub(.5).mul(t.xy),g=Ci(n.x.add(d),n.y.add(c)).sub(.5).mul(t.xy),m=Ci(n.x.add(l),n.y.add(h)).sub(.5).mul(t.xy),f=Ci(n.x.add(d),n.y.add(h)).sub(.5).mul(t.xy),y=lp(o.y).mul(Vn(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=dp(o.y).mul(Vn(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},gp=fi((([e,t=vi(3)])=>{const s=Ci(e.size(Si(t))),r=Ci(e.size(Si(t.add(1)))),i=kn(1,s),n=kn(1,r),o=pp(e,Ii(i,s),vo(t)),a=pp(e,Ii(n,r),So(t));return Ro(t).mix(o,a)})),mp=fi((([e,t,s,r,i])=>{const n=Bi(ha(t.negate(),Ao(e),kn(1,r))),o=Bi(Io(i[0].xyz),Io(i[1].xyz),Io(i[2].xyz));return Ao(n).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),fp=fi((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),yp=Vc(),bp=Vc(),xp=fi((([e,t,s],{material:r})=>{const i=(r.side==x?yp:bp).uv(e),n=To(Rc.x).mul(fp(t,s));return gp(i,n)})),Tp=fi((([e,t,s])=>(Ti(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Bi(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),_p=fi((([e,t,s,r,i,n,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ii().toVar(),f=Bi().toVar();const i=d.sub(1).mul(g.mul(.025)),n=Bi(d.sub(i),d,d.add(i));uc({start:0,end:3},(({i:i})=>{const d=n.element(i),g=mp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ii(y,1))),x=Ci(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(Ci(x.x,x.y.oneMinus()));const T=xp(x,s,d);m.element(i).assign(T.element(i)),m.a.addAssign(T.a),f.element(i).assign(r.element(i).mul(Tp(Io(g),h,p).element(i)))})),m.a.divAssign(3)}else{const i=mp(e,t,c,d,a),n=o.add(i),g=l.mul(u.mul(Ii(n,1))),y=Ci(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(Ci(y.x,y.y.oneMinus())),m=xp(y,s,d),f=r.mul(Tp(Io(i),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Bi(Xh({dotNV:b,specularColor:i,specularF90:n,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ii(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),Np=Gi(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),vp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Sp=fi((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:i})=>{const n=la(e,t,pa(0,.03,r)),o=e.div(n).pow2().mul(s.pow2().oneMinus()).oneMinus();Ti(o.lessThan(0),(()=>Bi(1)));const a=o.sqrt(),u=vp(n,e),l=Bh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=n.lessThan(e).select(Math.PI,0),h=vi(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Bi(1).add(t).div(Bi(1).sub(t))})(i.clamp(0,.9999)),g=vp(p,n.toVec3()),m=Bh({f0:g,f90:1,dotVH:a}),f=Bi(p.x.lessThan(n).select(Math.PI,0),p.y.lessThan(n).select(Math.PI,0),p.z.lessThan(n).select(Math.PI,0)),y=n.mul(r,a,2),b=Bi(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Bi(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Bi(54856e-17,44201e-17,52481e-17),i=Bi(1681e3,1795300,2208400),n=Bi(43278e5,93046e5,66121e5),o=vi(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(n.mul(2*Math.PI).sqrt()).mul(i.mul(s).add(t).cos()).mul(s.pow2().negate().mul(n).exp());return a=Bi(a.x.add(o),a.y,a.z).div(1.0685e-7),Np.mul(a)})(vi(e).mul(y),vi(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Bi(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Ap=fi((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),i=s.pow2(),n=xa(s.lessThan(.25),vi(-339.2).mul(i).add(vi(161.4).mul(s)).sub(25.9),vi(-8.48).mul(i).add(vi(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),vi(44).mul(i).sub(vi(23.7).mul(s)).add(3.26),vi(1.97).mul(i).sub(vi(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,vi(.1).mul(s).sub(.025)).add(n.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Rp=Bi(.04),Cp=vi(1);class Ep extends Ch{constructor(e=!1,t=!1,s=!1,r=!1,i=!1,n=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=i,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Bi().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Bi().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Bi().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Bi().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Bi().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=Sp({outsideIOR:vi(1),eta2:gn,cosTheta1:e,thinFilmThickness:mn,baseF0:Tn}),this.iridescenceF0=Yh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=_p(r,s,an,nn,Tn,_n,t,Gu,Eu,Ru,Cn,wn,Bn,Mn,this.dispersion?Un:null),e.backdropAlpha=En,nn.a.mulAssign(la(1,e.backdrop.a,En))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),i=Kh({roughness:an,dotNV:r}),n=(this.iridescenceF0?pn.mix(Tn,this.iridescenceF0):Tn).mul(i.x).add(s.mul(i.y)),o=i.x.add(i.y).oneMinus(),a=Tn.add(Tn.oneMinus().mul(.047619)),u=n.mul(a).div(o.mul(a).oneMinus());e.addAssign(n),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Jh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(qh({lightDirection:e,f0:Rp,f90:Cp,roughness:dn,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:nn.rgb}))),s.directSpecular.addAssign(r.mul(qh({lightDirection:e,f0:Tn,f90:1,roughness:an,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:i,ltc_1:n,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=ep({N:c,V:h,roughness:an}),m=n.uv(g).toVar(),f=o.uv(g).toVar(),y=Gi(Bi(m.x,0,m.y),Bi(0,1,0),Bi(m.z,0,m.w)).toVar(),b=Tn.mul(f.x).add(Tn.oneMinus().mul(f.y)).toVar();i.directSpecular.addAssign(e.mul(b).mul(rp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),i.directDiffuse.addAssign(e.mul(nn).mul(rp({N:c,V:h,P:p,mInv:Gi(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Uh({diffuseColor:nn})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(cn,Ap({normal:dl,viewDir:tl,roughness:hn}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Xh({dotNV:e,specularColor:Rp,specularF90:Cp,roughness:dn});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Bi().toVar("singleScattering"),i=Bi().toVar("multiScattering"),n=t.mul(1/Math.PI);this.computeMultiscattering(r,i,_n);const o=r.add(i),a=nn.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(i.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=an.mul(-16).oneMinus().negate().exp2(),i=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(i)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Bh({dotVH:e,f0:Rp,f90:Cp}),r=t.mul(ln.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(ln));t.assign(r)}if(!0===this.sheen){const e=cn.r.max(cn.g).max(cn.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const wp=vi(1),Mp=vi(-2),Bp=vi(.8),Up=vi(-1),Fp=vi(.4),Pp=vi(2),Ip=vi(.305),Lp=vi(3),Dp=vi(.21),Vp=vi(4),Op=vi(4),Gp=vi(16),kp=fi((([e])=>{const t=Bi(Fo(e)).toVar(),s=vi(-1).toVar();return Ti(t.x.greaterThan(t.z),(()=>{Ti(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{Ti(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),zp=fi((([e,t])=>{const s=Ci().toVar();return Ti(t.equal(0),(()=>{s.assign(Ci(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(Ci(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(Ci(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(Ci(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(Ci(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(Ci(e.x,e.y).div(Fo(e.z)))})),Gn(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$p=fi((([e])=>{const t=vi(0).toVar();return Ti(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).ElseIf(e.greaterThanEqual(Fp),(()=>{t.assign(Bp.sub(e).mul(Pp.sub(Up)).div(Bp.sub(Fp)).add(Up))})).ElseIf(e.greaterThanEqual(Ip),(()=>{t.assign(Fp.sub(e).mul(Lp.sub(Pp)).div(Fp.sub(Ip)).add(Pp))})).ElseIf(e.greaterThanEqual(Dp),(()=>{t.assign(Ip.sub(e).mul(Vp.sub(Lp)).div(Ip.sub(Dp)).add(Lp))})).Else((()=>{t.assign(vi(-2).mul(To(Gn(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Hp=fi((([e,t])=>{const s=e.toVar();s.assign(Gn(2,s).sub(1));const r=Bi(s,1).toVar();return Ti(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Wp=fi((([e,t,s,r,i,n])=>{const o=vi(s),a=Bi(t),u=da($p(o),Mp,n),l=Ro(u),d=vo(u),c=Bi(jp(e,a,d,r,i,n)).toVar();return Ti(l.notEqual(0),(()=>{const t=Bi(jp(e,a,d.add(1),r,i,n)).toVar();c.assign(la(c,t,l))})),c})),jp=fi((([e,t,s,r,i,n])=>{const o=vi(s).toVar(),a=Bi(t),u=vi(kp(a)).toVar(),l=vi(Ko(Op.sub(o),0)).toVar();o.assign(Ko(o,Op));const d=vi(bo(o)).toVar(),c=Ci(zp(a,u).mul(d.sub(2)).add(1)).toVar();return Ti(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gn(3,Gp))),c.y.addAssign(Gn(4,bo(n).sub(d))),c.x.mulAssign(r),c.y.mulAssign(i),e.uv(c).grad(Ci(),Ci())})),qp=fi((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:i,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(i.cross(s).mul(Co(r))).add(i.mul(i.dot(s).mul(u.oneMinus())));return jp(e,l,t,n,o,a)})),Kp=fi((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:i,samples:n,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Bi(xa(t,s,ta(s,r))).toVar();Ti(ho(h.equals(Bi(0))),(()=>{h.assign(Bi(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Bi().toVar();return p.addAssign(i.element(Si(0)).mul(qp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:Si(1),end:e},(({i:e})=>{Ti(e.greaterThanEqual(n),(()=>{dc()}));const t=vi(o.mul(vi(e))).toVar();p.addAssign(i.element(e).mul(qp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(i.element(e).mul(qp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ii(p,1)}));let Xp=null;const Yp=new WeakMap;function Qp(e){let t=Yp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r0}(s))return null;t=Xp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Yp.set(e,t)}return t.texture}class Zp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=en(0),this._height=en(0),this._maxMip=en(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Qp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Xp&&(Xp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Bi(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Wp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Jp=gi(Zp),eg=new WeakMap;class tg extends yc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let r=eg.get(e);void 0===r&&(r=Jp(e),eg.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),i=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,n=s.context(sg(an,i)).mul(r),o=s.context(rg(cl)).mul(Math.PI).mul(r),a=eu(n),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(sg(dn,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const sg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},rg=e=>({getUV:()=>e,getTextureLevel:()=>vi(1)}),ig=new te;class ng extends ih{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ig),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new tg(t):null}setupLightingModel(){return new Ep}setupSpecular(){const e=la(Bi(.04),nn.rgb,un);Tn.assign(e),_n.assign(1)}setupVariants(){const e=this.metalnessNode?vi(this.metalnessNode):yd;un.assign(e);let t=this.roughnessNode?vi(this.roughnessNode):fd;t=kh({roughness:t}),an.assign(t),this.setupSpecular(),nn.assign(Ii(nn.rgb.mul(e.oneMinus()),nn.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const og=new se;class ag extends ng{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(og),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?vi(this.iorNode):Bd;Cn.assign(e),Tn.assign(la(qo(ra(Cn.sub(1).div(Cn.add(1))).mul(pd),Bi(1)).mul(hd),nn.rgb,un)),_n.assign(la(hd,1,un))}setupLightingModel(){return new Ep(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?vi(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?vi(this.clearcoatRoughnessNode):Td;ln.assign(e),dn.assign(kh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Bi(this.sheenNode):vd,t=this.sheenRoughnessNode?vi(this.sheenRoughnessNode):Sd;cn.assign(e),hn.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?vi(this.iridescenceNode):Rd,t=this.iridescenceIORNode?vi(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?vi(this.iridescenceThicknessNode):Ed;pn.assign(e),gn.assign(t),mn.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?Ci(this.anisotropyNode):Ad).toVar();yn.assign(e.length()),Ti(yn.equal(0),(()=>{e.assign(Ci(1,0))})).Else((()=>{e.divAssign(Ci(yn)),yn.assign(yn.saturate())})),fn.assign(yn.pow2().mix(an.pow2(),1)),bn.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xn.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?vi(this.transmissionNode):wd,t=this.thicknessNode?vi(this.thicknessNode):Md,s=this.attenuationDistanceNode?vi(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Bi(this.attenuationColorNode):Fd;if(En.assign(e),wn.assign(t),Mn.assign(s),Bn.assign(r),this.useDispersion){const e=this.dispersionNode?vi(this.dispersionNode):Gd;Un.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Bi(this.clearcoatNormalNode):_d}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class ug extends Ep{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i){if(!0===this.useSSS){const r=i.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=vi(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Bi(h.add(a).mul(n));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i)}}class lg extends ag{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=vi(.1),this.thicknessAmbientNode=vi(0),this.thicknessAttenuationNode=vi(.1),this.thicknessPowerNode=vi(2),this.thicknessScaleNode=vi(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ug(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const dg=fi((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),i=Ci(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>i});return Bi(e.r)}{const e=i.fwidth().mul(.5);return la(Bi(.7),Bi(1),pa(vi(.7).sub(e.x),vi(.7).add(e.x),i.x))}}));class cg extends Ch{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,i){const n=dg({normal:nl,lightDirection:e,builder:i}).mul(t);s.directDiffuse.addAssign(n.mul(Uh({diffuseColor:nn.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:nn}))),s.indirectDiffuse.mulAssign(e)}}const hg=new re;class pg extends ih{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(hg),this.setValues(e)}setupLightingModel(){return new cg}}class gg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Bi(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return Ci(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const mg=mi(gg),fg=new ie;class yg extends ih{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(fg),this.setValues(e)}setupVariants(e){const t=mg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Bi(la(.2,.8,t.y)),nn.rgb.mulAssign(s.rgb)}}const bg=new P;class xg extends ih{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(bg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Tg extends Er{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Oi(e,r,r.negate(),e).mul(s)}{const e=t,r=ki(Ii(1,0,0,0),Ii(0,Eo(e.x),Co(e.x).negate(),0),Ii(0,Co(e.x),Eo(e.x),0),Ii(0,0,0,1)),i=ki(Ii(Eo(e.y),0,Co(e.y),0),Ii(0,1,0,0),Ii(Co(e.y).negate(),0,Eo(e.y),0),Ii(0,0,0,1)),n=ki(Ii(Eo(e.z),Co(e.z).negate(),0,0),Ii(Co(e.z),Eo(e.z),0,0),Ii(0,0,1,0),Ii(0,0,0,1));return r.mul(i).mul(n).mul(Ii(s,1)).xyz}}}const _g=gi(Tg),Ng=new ne;class vg extends ih{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Ng),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:i,rotationNode:n,scaleNode:o}=this,a=Yu;let u=ju.mul(Bi(i||0)),l=Ci(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=vi(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>ci(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=vi(n||Nd),h=_g(d,c);u=Ii(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Sg extends Ch{constructor(){super(),this.shadowNode=vi(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){nn.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(nn.rgb)}}const Ag=new oe;class Rg extends ih{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ag),this.setValues(e)}setupLightingModel(){return new Sg}}const Cg=fi((({texture:e,uv:t})=>{const s=1e-4,r=Bi().toVar();return Ti(t.x.lessThan(s),(()=>{r.assign(Bi(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Bi(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Bi(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Bi(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Bi(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Bi(0,0,-1))})).Else((()=>{const s=.01,i=e.uv(t.add(Bi(-.01,0,0))).r.sub(e.uv(t.add(Bi(s,0,0))).r),n=e.uv(t.add(Bi(0,-.01,0))).r.sub(e.uv(t.add(Bi(0,s,0))).r),o=e.uv(t.add(Bi(0,0,-.01))).r.sub(e.uv(t.add(Bi(0,0,s))).r);r.assign(Bi(i,n,o))})),r.normalize()}));class Eg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Bi(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Cg({texture:this,uv:e})}}const wg=gi(Eg);class Mg extends ih{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=wg(this.map,null,0),s=fi((({orig:e,dir:t})=>{const s=Bi(-.5),r=Bi(.5),i=t.reciprocal(),n=s.sub(e).mul(i),o=r.sub(e).mul(i),a=qo(n,o),u=Ko(n,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return Ci(l,d)}));this.fragmentNode=fi((()=>{const e=Ea(Bi(Wu.mul(Ii(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),i=Ci(s({orig:e,dir:r})).toVar();i.x.greaterThan(i.y).discard(),i.assign(Ci(Ko(i.x,0),i.y));const n=Bi(e.add(i.x.mul(r))).toVar(),o=Bi(r.abs().reciprocal()).toVar(),a=vi(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ii(Fl("base","color"),0).toVar();return uc({type:"float",start:i.x,end:i.y,update:"+= delta"},(()=>{const e=sn("float","d").assign(t.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:n,finalColor:u}).append():(u.a.assign(1),dc()),n.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ii(u)}))(),super.setup(e)}}class Bg{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ug{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const i of e){const e=i.node&&i.node.attribute?i.node.attribute:t.getAttribute(i.name);if(void 0===e)continue;s.push(e);const n=e.isInterleavedBufferAttribute?e.data:e;r.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:i}=this,n=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(n.instanceCount=u,!0===e.isBatchedMesh)return n;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=i.start*l,c=(i.start+i.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(n.vertexCount=g,n.firstVertex=d,n)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let i;if(null!==r){const e=typeof r;"number"===e?i=0!==r?"1":"0":"object"===e?(i="{",r.isTexture&&(i+=r.mapping),i+="}"):i=String(r)}else i=String(r);s+=i+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Ig=[];class Lg{constructor(e,t,s,r,i,n){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=i,this.info=n,this.chainMaps={}}get(e,t,s,r,i,n,o,a){const u=this.getChainMap(a);Ig[0]=e,Ig[1]=t,Ig[2]=n,Ig[3]=i;let l=u.get(Ig);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,i,n,o,a),u.set(Ig,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,i,n,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ug)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,i,n,o,a,u,l,d){const c=this.getChainMap(d),h=new Pg(e,t,s,r,i,n,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Dg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Vg=1,Og=2,Gg=3,kg=4,zg=16;class $g extends Dg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Vg?this.backend.createAttribute(e):t===Og?this.backend.createIndexAttribute(e):t===Gg?this.backend.createStorageAttribute(e):t===kg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return i.version=Hg(e),i}class jg extends Dg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,i=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of i)this.attributes.delete(e);const n=this.wireframes.get(t);void 0!==n&&this.attributes.delete(n),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Gg):this.updateAttribute(e,Vg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Og);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,kg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Wg(t),e.set(t,s)):s.version!==Hg(t)&&(this.attributes.delete(s),s=Wg(t),e.set(t,s)),r=s}return r}}class qg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Kg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Xg extends Kg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Yg extends Kg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Qg=0;class Zg{constructor(e,t,s=null,r=null){this.id=Qg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Jg extends Dg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const i=r.pipeline;i&&(i.usedTimes--,i.computeProgram.usedTimes--);const n=this.nodes.getForCompute(e);let o=this.programs.compute.get(n.computeShader);void 0===o&&(i&&0===i.computeProgram.usedTimes&&this._releaseProgram(i.computeProgram),o=new Zg(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(i&&0===i.usedTimes&&this._releasePipeline(i),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const i=r.pipeline;i&&(i.usedTimes--,i.vertexProgram.usedTimes--,i.fragmentProgram.usedTimes--);const n=e.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(i&&0===i.vertexProgram.usedTimes&&this._releaseProgram(i.vertexProgram),o=new Zg(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(i&&0===i.fragmentProgram.usedTimes&&this._releaseProgram(i.fragmentProgram),a=new Zg(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(i&&0===i.usedTimes&&this._releasePipeline(i),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let i=this.caches.get(s);return void 0===i&&(i=new Yg(s,t),this.caches.set(s,i),this.backend.createComputePipeline(i,r)),i}_getRenderPipeline(e,t,s,r,i){r=r||this._getRenderCacheKey(e,t,s);let n=this.caches.get(r);return void 0===n&&(n=new Xg(r,t,s),this.caches.set(r,n),e.pipeline=n,this.backend.createRenderPipeline(e,i)),n}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class em extends Dg{constructor(e,t,s,r,i,n){super(),this.backend=e,this.textures=s,this.pipelines=i,this.attributes=r,this.nodes=t,this.info=n,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,s=e.isIndirectStorageBufferAttribute?kg:Gg;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1,i=!0,n=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(r=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=s.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?i=!1:(n=10*n+u.id,o+=u.version),!0===s.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,r),this.textures.updateTexture(u),r=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t,i?n:0,o)}}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function sm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function rm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class im{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,i,n,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:i,group:n,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=i,a.group=n,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,i,n,o){const a=this.getNextRenderItem(e,t,s,r,i,n,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,i,n,o){const a=this.getNextRenderItem(e,t,s,r,i,n,o);!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||tm),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||sm),this.transparent.length>1&&this.transparent.sort(t||sm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||i[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,i[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=n,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(i.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&i.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&i.generateMipmaps(e)}}else i.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=dm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class hm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class pm extends tn{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const gm=(e,t)=>ci(new pm(e,t));class mm extends Ar{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new di(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new di(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new di(e),this}build(e,...t){const s=xi();bi(this);for(const t of this.nodes)t.build(e,"void");return bi(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const fm=gi(mm);class ym extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class bm extends Ar{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let r=0;r{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),Sm=(e,t)=>sa(Gn(4,e.mul(On(1,e))),t),Am=(e,t)=>e.lessThan(.5)?Sm(e.mul(2),t).div(2):On(1,Sm(Gn(On(1,e),2),t).div(2)),Rm=(e,t,s)=>sa(kn(sa(e,t),Vn(sa(e,t),sa(On(1,e),s))),1/t),Cm=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),Em=fi((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),wm=fi((([e])=>Bi(Em(e.z.add(Em(e.y.mul(1)))),Em(e.z.add(Em(e.x.mul(1)))),Em(e.y.add(Em(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Mm=fi((([e,t,s])=>{const r=Bi(e).toVar(),i=vi(1.4).toVar(),n=vi(0).toVar(),o=Bi(r).toVar();return uc({start:vi(0),end:vi(3),type:"float",condition:"<="},(()=>{const e=Bi(wm(o.mul(2))).toVar();r.addAssign(e.add(s.mul(vi(.1).mul(t)))),o.mulAssign(1.8),i.mulAssign(1.5),r.mulAssign(1.2);const a=vi(Em(r.z.add(Em(r.x.add(Em(r.y)))))).toVar();n.addAssign(a.div(i)),o.addAssign(.14)})),n})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Bm extends Ar{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let r=null,i=-1;for(const s of this.functionNodes){const n=s.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=n.inputs;if(t.length===o.length){let n=0;for(let s=0;si&&(r=s,i=n)}}this._candidateFnCall=s=r(...t)}return s}}const Um=gi(Bm),Fm=e=>(...t)=>Um(e,...t),Pm=en(0).setGroup(Qi).onRenderUpdate((e=>e.time)),Im=en(0).setGroup(Qi).onRenderUpdate((e=>e.deltaTime)),Lm=en(0,"uint").setGroup(Qi).onRenderUpdate((e=>e.frameId)),Dm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Pm.mul(e)),Vm=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Pm.mul(e)),Om=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Im.mul(e)),Gm=(e=Pm)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),km=(e=Pm)=>e.fract().round(),zm=(e=Pm)=>e.add(.5).fract().mul(2).sub(1).abs(),$m=(e=Pm)=>e.fract(),Hm=fi((([e,t,s=Ci(.5)])=>_g(e.sub(s),t).add(s))),Wm=fi((([e,t,s=Ci(.5)])=>{const r=e.sub(s),i=r.dot(r),n=i.mul(i).mul(t);return e.add(r.mul(n))})),jm=fi((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const i=Eu.mul(r);return ui(t)&&(i[0][0]=Gu[0].length(),i[0][1]=0,i[0][2]=0),ui(s)&&(i[1][0]=0,i[1][1]=Gu[1].length(),i[1][2]=0),i[2][0]=0,i[2][1]=0,i[2][2]=1,Ru.mul(i).mul(Yu)})),qm=fi((([e=null])=>{const t=Qc();return Qc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class Km extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=vi(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:i}=s,n=e.mod(r.mul(i)).floor(),o=n.mod(r),a=i.sub(n.add(1).div(r).ceil()),u=s.reciprocal(),l=Ci(o,a);return t.add(l).mul(u)}}const Xm=gi(Km);class Ym extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=vi(1),i=Yu,n=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=i,this.normalNode=n}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:i,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(Bi(1)));const a=i.yz.mul(r),u=i.zx.mul(r),l=i.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vn(p,g,m)}}const Qm=gi(Ym),Zm=(...e)=>Qm(...e),Jm=new me,ef=new s,tf=new s,sf=new s,rf=new n,nf=new s(0,0,-1),of=new r,af=new s,uf=new s,lf=new r,df=new t,cf=new ge,hf=Ac.flipX();cf.depthTexture=new B(1,1);let pf=!1;class gf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||cf.texture,hf),this._reflectorBaseNode=e.reflector||new mf(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=ci(new gf({defaultTexture:cf.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class mf extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:i=!1,bounces:n=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=i,this.bounces=n,this.depth=o,this.updateBeforeType=n?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(df),e.setSize(Math.round(df.width*s),Math.round(df.height*s))}setup(e){return this._updateResolution(cf,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&pf)return;pf=!0;const{scene:t,camera:s,renderer:r,material:i}=e,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(df),this._updateResolution(a,r),tf.setFromMatrixPosition(n.matrixWorld),sf.setFromMatrixPosition(s.matrixWorld),rf.extractRotation(n.matrixWorld),ef.set(0,0,1),ef.applyMatrix4(rf),af.subVectors(tf,sf),af.dot(ef)>0)return;af.reflect(ef).negate(),af.add(tf),rf.extractRotation(s.matrixWorld),nf.set(0,0,-1),nf.applyMatrix4(rf),nf.add(sf),uf.subVectors(tf,nf),uf.reflect(ef).negate(),uf.add(tf),o.coordinateSystem=s.coordinateSystem,o.position.copy(af),o.up.set(0,1,0),o.up.applyMatrix4(rf),o.up.reflect(ef),o.lookAt(uf),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),Jm.setFromNormalAndCoplanarPoint(ef,tf),Jm.applyMatrix4(o.matrixWorldInverse),of.set(Jm.normal.x,Jm.normal.y,Jm.normal.z,Jm.constant);const u=o.projectionMatrix;lf.x=(Math.sign(of.x)+u.elements[8])/u.elements[0],lf.y=(Math.sign(of.y)+u.elements[9])/u.elements[5],lf.z=-1,lf.w=(1+u.elements[10])/u.elements[14],of.multiplyScalar(1/of.dot(lf));u.elements[2]=of.x,u.elements[6]=of.y,u.elements[10]=r.coordinateSystem===N?of.z-0:of.z+1-0,u.elements[14]=of.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),i.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),i.visible=!0,pf=!1}}const ff=e=>ci(new gf(e)),yf=new xe(-1,1,1,-1,0,1);class bf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const xf=new bf;class Tf extends k{constructor(e=null){super(xf,e),this.camera=yf,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,yf)}render(e){e.render(this,yf)}}const _f=new t;class Nf extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const i=new ge(t,s,r);super(i.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=i,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new Tf(new ih),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(_f);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const vf=(e,...t)=>ci(new Nf(ci(e),...t)),Sf=(e,...t)=>e.isTextureNode?e:vf(e,...t),Af=fi((([e,t,s],r)=>{let i;r.renderer.coordinateSystem===N?(e=Ci(e.x,e.y.oneMinus()).mul(2).sub(1),i=Ii(Bi(e,t),1)):i=Ii(Bi(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const n=Ii(s.mul(i));return n.xyz.div(n.w)})),Rf=fi((([e,t])=>{const s=t.mul(Ii(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return Ci(r.x,r.y.oneMinus())})),Cf=fi((([e,t,s])=>{const r=yu(Nu(t)),i=Ei(e.mul(r)).toVar(),n=Nu(t,i).toVar(),o=Nu(t,i.sub(Ei(2,0))).toVar(),a=Nu(t,i.sub(Ei(1,0))).toVar(),u=Nu(t,i.add(Ei(1,0))).toVar(),l=Nu(t,i.add(Ei(2,0))).toVar(),d=Nu(t,i.add(Ei(0,2))).toVar(),c=Nu(t,i.add(Ei(0,1))).toVar(),h=Nu(t,i.sub(Ei(0,1))).toVar(),p=Nu(t,i.sub(Ei(0,2))).toVar(),g=Fo(On(vi(2).mul(a).sub(o),n)).toVar(),m=Fo(On(vi(2).mul(u).sub(l),n)).toVar(),f=Fo(On(vi(2).mul(c).sub(d),n)).toVar(),y=Fo(On(vi(2).mul(h).sub(p),n)).toVar(),b=Af(e,n,s).toVar(),x=g.lessThan(m).select(b.sub(Af(e.sub(Ci(vi(1).div(r.x),0)),a,s)),b.negate().add(Af(e.add(Ci(vi(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Af(e.add(Ci(0,vi(1).div(r.y))),c,s)),b.negate().add(Af(e.sub(Ci(0,vi(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class Ef extends pu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const wf=(...e)=>ci(new Ef(...e));class Mf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Bf=mi(Mf),Uf=new ve,Ff=new n;class Pf extends Ar{static get type(){return"SceneNode"}constructor(e=Pf.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===Pf.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===Pf.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===Pf.BACKGROUND_ROTATION?r=en("mat4").label("backgroundRotation").setGroup(Qi).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Uf.copy(s.backgroundRotation),Uf.x*=-1,Uf.y*=-1,Uf.z*=-1,Ff.makeRotationFromEuler(Uf)):Ff.identity(),Ff})):console.error("THREE.SceneNode: Unknown scope:",t),r}}Pf.BACKGROUND_BLURRINESS="backgroundBlurriness",Pf.BACKGROUND_INTENSITY="backgroundIntensity",Pf.BACKGROUND_ROTATION="backgroundRotation";const If=mi(Pf,Pf.BACKGROUND_BLURRINESS),Lf=mi(Pf,Pf.BACKGROUND_INTENSITY),Df=mi(Pf,Pf.BACKGROUND_ROTATION);class Vf extends Rr{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Of=gi(Vf),Gf="point-list",kf="line-list",zf="line-strip",$f="triangle-list",Hf="triangle-strip",Wf="never",jf="less",qf="equal",Kf="less-equal",Xf="greater",Yf="not-equal",Qf="greater-equal",Zf="always",Jf="store",ey="load",ty="clear",sy="ccw",ry="none",iy="front",ny="back",oy="uint16",ay="uint32",uy={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},ly="clamp-to-edge",dy="repeat",cy="mirror-repeat",hy="linear",py="nearest",gy="zero",my="one",fy="src",yy="one-minus-src",by="src-alpha",xy="one-minus-src-alpha",Ty="dst",_y="one-minus-dst",Ny="dst-alpha",vy="one-minus-dst-alpha",Sy="src-alpha-saturated",Ay="constant",Ry="one-minus-constant",Cy="add",Ey="subtract",wy="reverse-subtract",My="min",By="max",Uy=0,Fy=15,Py="keep",Iy="zero",Ly="replace",Dy="invert",Vy="increment-clamp",Oy="decrement-clamp",Gy="increment-wrap",ky="decrement-wrap",zy="storage",$y="read-only-storage",Hy="write-only",Wy="read-only",jy="float",qy="unfilterable-float",Ky="depth",Xy="sint",Yy="uint",Qy="2d",Zy="3d",Jy="2d",eb="2d-array",tb="cube",sb="3d",rb="all",ib="vertex",nb="instance",ob={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class ab extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=zy,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Of(this,e)}setBufferObject(e){return this.bufferObject=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess($y)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),r=s.build(e);return e.registerTransform(r,t),r}}const ub=(e,t,s)=>ci(new ab(e,t,s)),lb=(e,t,s)=>ci(new ab(e,t,s).setBufferObject(!0));class db extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Hy}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(Wy)}toWriteOnly(){return this.setAccess(Hy)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,i=super.generate(e,"property"),n=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,i,n,o);e.addLineFlowCode(a,this)}}const cb=gi(db),hb=(e,t,s)=>{const r=cb(e,t,s);return null!==s&&r.append(),r};class pb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const gb=(e,t,s)=>ci(new pb(e,t,s)),mb=new WeakMap;class fb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=en(new n),this.previousProjectionMatrix=en(new n).setGroup(Qi),this.previousCameraViewMatrix=en(new n)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=bb(s);this.previousModelWorldMatrix.value.copy(r);const i=yb(t);i.frameId!==e&&(i.frameId=e,void 0===i.previousProjectionMatrix?(i.previousProjectionMatrix=new n,i.previousCameraViewMatrix=new n,i.currentProjectionMatrix=new n,i.currentCameraViewMatrix=new n,i.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(i.previousProjectionMatrix.copy(i.currentProjectionMatrix),i.previousCameraViewMatrix.copy(i.currentCameraViewMatrix)),i.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),i.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(i.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(i.previousCameraViewMatrix))}updateAfter({object:e}){bb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:en(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),i=s.xy.div(s.w),n=r.xy.div(r.w);return On(i,n)}}function yb(e){let t=mb.get(e);return void 0===t&&(t={},mb.set(e,t)),t}function bb(e,t=0){const s=yb(e);let r=s[t];return void 0===r&&(s[t]=r=new n),r}const xb=mi(fb),Tb=fi((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),_b=fi((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Nb=fi((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=fi((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Sb=fi((([e,t])=>Ii(e.rgb.mul(t.a.oneMinus()).add(t.rgb.mul(t.a)),e.a))).setLayout({name:"blendNormal",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Ab=fi((([e])=>wb(e.rgb))),Rb=fi((([e,t=vi(1)])=>t.mix(wb(e.rgb),e.rgb))),Cb=fi((([e,t=vi(1)])=>{const s=Vn(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),i=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,i)})),Eb=fi((([e,t=vi(1)])=>{const s=Bi(.57735,.57735,.57735),r=t.cos();return Bi(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),wb=(e,t=Bi(u.getLuminanceCoefficients(new s)))=>ea(e,t),Mb=(e,t)=>la(Bi(0),e,wb(e).sub(t).max(0)),Bb=fi((([e,t=Bi(1),r=Bi(0),i=Bi(1),n=vi(1),o=Bi(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Bi(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(i).toVar();return Ti(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),Ti(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),Ti(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(n))),Ii(l.rgb,e.a)}));class Ub extends Er{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Fb=gi(Ub);let Pb=null;class Ib extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Pb&&(Pb=new w),super(e,t,Pb)}updateReference(){return this}}const Lb=gi(Ib),Db=new t;class Vb extends Tu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class Ob extends Vb{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class Gb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const i=new B;i.isRenderTargetTexture=!0,i.name="depth";const n=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});n.texture.name="output",n.depthTexture=i,this.renderTarget=n,this.updateBeforeType=br.FRAME,this._textures={output:n.texture,depth:i},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=en(0),this._cameraFar=en(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=ci(new Ob(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=ci(new Ob(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,i=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(i,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===Gb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const i=t.getSize(Db);this.setSize(i.width,i.height);const n=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(n),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Gb.COLOR="color",Gb.DEPTH="depth";const kb=(e,t,s)=>ci(new Gb(Gb.COLOR,e,t,s)),zb=(e,t)=>ci(new Vb(e,t)),$b=(e,t)=>ci(new Gb(Gb.DEPTH,e,t));class Hb extends Gb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,i){super(Gb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=i,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,i,n,o,a,u)=>{if((n.isMeshToonMaterial||n.isMeshToonNodeMaterial)&&!1===n.wireframe){const l=this._getOutlineMaterial(n);t.renderObject(e,s,r,i,l,o,a,u)}t.renderObject(e,s,r,i,n,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new ih;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=vi(1),i=s.mul(Ii(Yu,1)),n=s.mul(Ii(Yu.add(t),1)),o=Ao(i.sub(n));return e.vertexNode=i.add(o.mul(this.thicknessNode).mul(i.w).mul(r)),e.colorNode=Ii(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const Wb=(t,s,r=new e(0,0,0),i=.003,n=1)=>ci(new Hb(t,s,ci(r),ci(i),ci(n))),jb=fi((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),qb=fi((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Kb=fi((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=fi((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Yb=fi((([e,t])=>{const s=Gi(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=Gi(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=Xb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qb=Gi(Bi(1.6605,-.1246,-.0182),Bi(-.5876,1.1329,-.1006),Bi(-.0728,-.0083,1.1187)),Zb=Gi(Bi(.6274,.0691,.0164),Bi(.3293,.9195,.088),Bi(.0433,.0113,.8956)),Jb=fi((([e])=>{const t=Bi(e).toVar(),s=Bi(t.mul(t)).toVar(),r=Bi(s.mul(s)).toVar();return vi(15.5).mul(r.mul(s)).sub(Gn(40.14,r.mul(t))).add(Gn(31.96,r).sub(Gn(6.868,s.mul(t))).add(Gn(.4298,s).add(Gn(.1191,t).sub(.00232))))})),ex=fi((([e,t])=>{const s=Bi(e).toVar(),r=Gi(Bi(.856627153315983,.137318972929847,.11189821299995),Bi(.0951212405381588,.761241990602591,.0767994186031903),Bi(.0482516061458583,.101439036467562,.811302368396859)),i=Gi(Bi(1.1271005818144368,-.1413297634984383,-.14132976349843826),Bi(-.11060664309660323,1.157823702216272,-.11060664309660294),Bi(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=vi(-12.47393),o=vi(4.026069);return s.mulAssign(t),s.assign(Zb.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(da(s,0,1)),s.assign(Jb(s)),s.assign(i.mul(s)),s.assign(sa(Ko(Bi(0),s),Bi(2.2))),s.assign(Qb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),tx=fi((([e,t])=>{const s=vi(.76),r=vi(.15);e=e.mul(t);const i=qo(e.r,qo(e.g,e.b)),n=xa(i.lessThan(.08),i.sub(Gn(6.25,i.mul(i))),.04);e.subAssign(n);const o=Ko(e.r,Ko(e.g,e.b));Ti(o.lessThan(s),(()=>e));const a=On(1,s),u=On(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=On(1,kn(1,r.mul(o.sub(u)).add(1)));return la(e,Bi(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class sx extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const rx=gi(sx),ix=(e,t)=>rx(e,t,"js"),nx=(e,t)=>rx(e,t,"wgsl"),ox=(e,t)=>rx(e,t,"glsl");class ax extends sx{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,i=s.type,n=e.getCodeFromNode(this,i);""!==r&&(n.name=r);const o=e.getPropertyName(n),a=this.getNodeFunction(e).getCode(o);return n.code=a+"\n","property"===t?o:e.format(`${o}()`,i,t)}}const ux=(e,t=[],s="")=>{for(let e=0;er.call(...e);return i.functionNode=r,i},lx=(e,t)=>ux(e,t,"glsl"),dx=(e,t)=>ux(e,t,"wgsl");class cx extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:vi()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const hx=gi(cx);class px extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class gx{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const mx=new px;class fx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new px,this._output=hx(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=hx(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=hx(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new gx(this),t=mx.get("THREE"),s=mx.get("TSL"),r=this.getMethod(this.codeNode),i=[e,this._local,mx,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...i);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const e of n.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:vi()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const yx=gi(fx);class bx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const xx=gi(bx);class Tx extends bx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const _x=gi(Tx);class Nx extends bx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const vx=gi(Nx);let Sx=null,Ax=null;class Rx extends Ar{static get type(){return"RangeNode"}constructor(e=vi(),t=vi()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const i=this.minNode.value,n=this.maxNode.value,o=e.getTypeLength(hr(i)),u=e.getTypeLength(hr(n));Sx=Sx||new r,Ax=Ax||new r,Sx.setScalar(0),Ax.setScalar(0),1===o?Sx.setScalar(i):i.isColor?Sx.set(i.r,i.g,i.b):Sx.set(i.x,i.y,i.z||0,i.w||0),1===u?Ax.setScalar(n):n.isColor?Ax.set(n.r,n.g,n.b):Ax.set(n.x,n.y,n.z||0,n.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;eci(new Ex(e,t)),Mx=wx("numWorkgroups","uvec3"),Bx=wx("workgroupId","uvec3"),Ux=wx("localId","uvec3"),Fx=wx("subgroupSize","uint");const Px=gi(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Ix=()=>Px("workgroup").append(),Lx=()=>Px("storage").append(),Dx=()=>Px("texture").append();class Vx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class Ox extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return ci(new Vx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const Gx=(e,t)=>ci(new Ox("Workgroup",e,t));class kx extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),i=this.pointerNode,n=this.valueNode,o=[];o.push(`&${i.build(e,r)}`),o.push(n.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}kx.ATOMIC_LOAD="atomicLoad",kx.ATOMIC_STORE="atomicStore",kx.ATOMIC_ADD="atomicAdd",kx.ATOMIC_SUB="atomicSub",kx.ATOMIC_MAX="atomicMax",kx.ATOMIC_MIN="atomicMin",kx.ATOMIC_AND="atomicAnd",kx.ATOMIC_OR="atomicOr",kx.ATOMIC_XOR="atomicXor";const zx=gi(kx),$x=(e,t,s,r)=>{const i=zx(e,t,s,r);return i.append(),i},Hx=(e,t,s=null)=>$x(kx.ATOMIC_STORE,e,t,s),Wx=(e,t,s=null)=>$x(kx.ATOMIC_ADD,e,t,s),jx=(e,t,s=null)=>$x(kx.ATOMIC_SUB,e,t,s),qx=(e,t,s=null)=>$x(kx.ATOMIC_MAX,e,t,s),Kx=(e,t,s=null)=>$x(kx.ATOMIC_MIN,e,t,s),Xx=(e,t,s=null)=>$x(kx.ATOMIC_AND,e,t,s),Yx=(e,t,s=null)=>$x(kx.ATOMIC_OR,e,t,s),Qx=(e,t,s=null)=>$x(kx.ATOMIC_XOR,e,t,s);let Zx;function Jx(e){Zx=Zx||new WeakMap;let t=Zx.get(e);return void 0===t&&Zx.set(e,t={}),t}function eT(e){const t=Jx(e);return t.position||(t.position=en(new s).setGroup(Qi).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function tT(e){const t=Jx(e);return t.targetPosition||(t.targetPosition=en(new s).setGroup(Qi).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function sT(e){const t=Jx(e);return t.viewPosition||(t.viewPosition=en(new s).setGroup(Qi).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const rT=e=>Eu.transformDirection(eT(e).sub(tT(e))),iT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},nT=new WeakMap;class oT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Bi().toVar("totalDiffuse"),this.totalSpecularNode=Bi().toVar("totalSpecular"),this.outgoingLightNode=Bi().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),i=e.renderer.library;for(const e of r)if(e.isNode)t.push(ci(e));else{let r=null;if(null!==s&&(r=iT(e.id,s)),null===r){const s=i.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;nT.has(e)?r=nT.get(e):(r=ci(new s(e)),nT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:i,totalDiffuseNode:n,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,i),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Bi(null!==l?l.mix(g,u):u),t.material.transparent=!0),n.assign(g),o.assign(c.add(p)),r.assign(n.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const aT=(e=[])=>ci(new oT).setLights(e),uT=fi((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),lT=fi((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),i=Ml("mapSize","vec2",s).setGroup(Qi),n=Ml("radius","float",s).setGroup(Qi),o=Ci(1).div(i),a=o.x.negate().mul(n),u=o.y.negate().mul(n),l=o.x.mul(n),d=o.y.mul(n),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vn(r(t.xy.add(Ci(a,u)),t.z),r(t.xy.add(Ci(0,u)),t.z),r(t.xy.add(Ci(l,u)),t.z),r(t.xy.add(Ci(c,h)),t.z),r(t.xy.add(Ci(0,h)),t.z),r(t.xy.add(Ci(p,h)),t.z),r(t.xy.add(Ci(a,0)),t.z),r(t.xy.add(Ci(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(Ci(p,0)),t.z),r(t.xy.add(Ci(l,0)),t.z),r(t.xy.add(Ci(c,g)),t.z),r(t.xy.add(Ci(0,g)),t.z),r(t.xy.add(Ci(p,g)),t.z),r(t.xy.add(Ci(a,d)),t.z),r(t.xy.add(Ci(0,d)),t.z),r(t.xy.add(Ci(l,d)),t.z)).mul(1/17)})),dT=fi((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),i=Ml("mapSize","vec2",s).setGroup(Qi),n=Ci(1).div(i),o=n.x,a=n.y,u=t.xy,l=Ro(u.mul(i).add(.5));return u.subAssign(l.mul(n)),Vn(r(u,t.z),r(u.add(Ci(o,0)),t.z),r(u.add(Ci(0,a)),t.z),r(u.add(n),t.z),la(r(u.add(Ci(o.negate(),0)),t.z),r(u.add(Ci(o.mul(2),0)),t.z),l.x),la(r(u.add(Ci(o.negate(),a)),t.z),r(u.add(Ci(o.mul(2),a)),t.z),l.x),la(r(u.add(Ci(0,a.negate())),t.z),r(u.add(Ci(0,a.mul(2))),t.z),l.y),la(r(u.add(Ci(o,a.negate())),t.z),r(u.add(Ci(o,a.mul(2))),t.z),l.y),la(la(r(u.add(Ci(o.negate(),a.negate())),t.z),r(u.add(Ci(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(Ci(o.negate(),a.mul(2))),t.z),r(u.add(Ci(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),cT=fi((({depthTexture:e,shadowCoord:t})=>{const s=vi(1).toVar(),r=_u(e).uv(t.xy).rg,i=Yo(t.z,r.x);return Ti(i.notEqual(vi(1)),(()=>{const e=t.z.sub(r.x),n=Ko(0,r.y.mul(r.y));let o=n.div(n.add(e.mul(e)));o=da(On(o,.3).div(.95-.3)),s.assign(da(Ko(i,o)))})),s})),hT=fi((({samples:e,radius:t,size:s,shadowPass:r})=>{const i=vi(0).toVar(),n=vi(0).toVar(),o=e.lessThanEqual(vi(1)).select(vi(0),vi(2).div(e.sub(1))),a=e.lessThanEqual(vi(1)).select(vi(0),vi(-1));uc({start:Si(0),end:Si(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(vi(e).mul(o)),l=r.uv(Vn(Cc.xy,Ci(0,u).mul(t)).div(s)).x;i.addAssign(l),n.addAssign(l.mul(l))})),i.divAssign(e),n.divAssign(e);const u=_o(n.sub(i.mul(i)));return Ci(i,u)})),pT=fi((({samples:e,radius:t,size:s,shadowPass:r})=>{const i=vi(0).toVar(),n=vi(0).toVar(),o=e.lessThanEqual(vi(1)).select(vi(0),vi(2).div(e.sub(1))),a=e.lessThanEqual(vi(1)).select(vi(0),vi(-1));uc({start:Si(0),end:Si(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(vi(e).mul(o)),l=r.uv(Vn(Cc.xy,Ci(u,0).mul(t)).div(s));i.addAssign(l.x),n.addAssign(Vn(l.y.mul(l.y),l.x.mul(l.x)))})),i.divAssign(e),n.divAssign(e);const u=_o(n.sub(i.mul(i)));return Ci(i,u)})),gT=[uT,lT,dT,cT];let mT=null;const fT=new Tf;class yT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===mT&&(mT=new ih,mT.fragmentNode=Ii(0,0,0,1),mT.isShadowNodeMaterial=!0,mT.name="ShadowMaterial");const r=this.shadow,i=s.shadowMap.type,n=new B(r.mapSize.width,r.mapSize.height);n.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=n,r.camera.updateProjectionMatrix(),i===Re){n.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(n),s=_u(this.vsmShadowMapVertical.texture),i=Ml("blurSamples","float",r).setGroup(Qi),o=Ml("radius","float",r).setGroup(Qi),a=Ml("mapSize","vec2",r).setGroup(Qi);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new ih);u.fragmentNode=hT({samples:i,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new ih),u.fragmentNode=pT({samples:i,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Qi),u=Ml("bias","float",r).setGroup(Qi),l=Ml("normalBias","float",r).setGroup(Qi),d=t.material.shadowPositionNode||Zu;let c,h=en(r.matrix).setGroup(Qi).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=Ml("near","float",r.camera).setGroup(Qi),s=Ml("far","float",r.camera).setGroup(Qi);c=qc(e.negate(),t,s)}h=Bi(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||gT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:i===Re?this.vsmShadowMapHorizontal.texture:n,shadowCoord:h,shadow:r}),vi(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:i,scene:n,camera:o}=e,a=i.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=n.overrideMaterial;n.overrideMaterial=mT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=i.getRenderTarget(),c=i.getRenderObjectFunction();i.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&i.renderObject(e,...t)})),i.setRenderTarget(t),i.render(n,r.camera),i.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(i),i.setRenderTarget(d),n.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),fT.material=this.vsmMaterialVertical,fT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),fT.material=this.vsmMaterialHorizontal,fT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const bT=(e,t)=>ci(new yT(e,t));class xT extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=en(this.color).setGroup(Qi),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?ci(e):bT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const TT=fi((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,i=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(i.mul(t.div(s).pow4().oneMinus().clamp().pow2()),i)})),_T=fi((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},i)=>{const n=i.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=TT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=i.context.reflectedLight;n.direct({lightDirection:a,lightColor:d,reflectedLight:c},i.stack,i)}));class NT extends xT{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=en(0).setGroup(Qi),this.decayExponentNode=en(0).setGroup(Qi)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){_T({color:this.colorNode,lightViewPosition:sT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const vT=fi((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),ST=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Ri(e).toVar();return xa(n,i,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),AT=fi((([e,t])=>{const s=Ri(t).toVar(),r=vi(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),RT=fi((([e])=>{const t=vi(e).toVar();return Si(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),CT=fi((([e,t])=>{const s=vi(e).toVar();return t.assign(RT(s)),s.sub(vi(t))})),ET=Fm([fi((([e,t,s,r,i,n])=>{const o=vi(n).toVar(),a=vi(i).toVar(),u=vi(r).toVar(),l=vi(s).toVar(),d=vi(t).toVar(),c=vi(e).toVar(),h=vi(On(1,a)).toVar();return On(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),fi((([e,t,s,r,i,n])=>{const o=vi(n).toVar(),a=vi(i).toVar(),u=Bi(r).toVar(),l=Bi(s).toVar(),d=Bi(t).toVar(),c=Bi(e).toVar(),h=vi(On(1,a)).toVar();return On(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),wT=Fm([fi((([e,t,s,r,i,n,o,a,u,l,d])=>{const c=vi(d).toVar(),h=vi(l).toVar(),p=vi(u).toVar(),g=vi(a).toVar(),m=vi(o).toVar(),f=vi(n).toVar(),y=vi(i).toVar(),b=vi(r).toVar(),x=vi(s).toVar(),T=vi(t).toVar(),_=vi(e).toVar(),N=vi(On(1,p)).toVar(),v=vi(On(1,h)).toVar();return vi(On(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),fi((([e,t,s,r,i,n,o,a,u,l,d])=>{const c=vi(d).toVar(),h=vi(l).toVar(),p=vi(u).toVar(),g=Bi(a).toVar(),m=Bi(o).toVar(),f=Bi(n).toVar(),y=Bi(i).toVar(),b=Bi(r).toVar(),x=Bi(s).toVar(),T=Bi(t).toVar(),_=Bi(e).toVar(),N=vi(On(1,p)).toVar(),v=vi(On(1,h)).toVar();return vi(On(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),MT=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Ai(e).toVar(),o=Ai(n.bitAnd(Ai(7))).toVar(),a=vi(ST(o.lessThan(Ai(4)),i,r)).toVar(),u=vi(Gn(2,ST(o.lessThan(Ai(4)),r,i))).toVar();return AT(a,Ri(o.bitAnd(Ai(1)))).add(AT(u,Ri(o.bitAnd(Ai(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),BT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=vi(t).toVar(),a=Ai(e).toVar(),u=Ai(a.bitAnd(Ai(15))).toVar(),l=vi(ST(u.lessThan(Ai(8)),o,n)).toVar(),d=vi(ST(u.lessThan(Ai(4)),n,ST(u.equal(Ai(12)).or(u.equal(Ai(14))),o,i))).toVar();return AT(l,Ri(u.bitAnd(Ai(1)))).add(AT(d,Ri(u.bitAnd(Ai(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),UT=Fm([MT,BT]),FT=fi((([e,t,s])=>{const r=vi(s).toVar(),i=vi(t).toVar(),n=Fi(e).toVar();return Bi(UT(n.x,i,r),UT(n.y,i,r),UT(n.z,i,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),PT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=vi(t).toVar(),a=Fi(e).toVar();return Bi(UT(a.x,o,n,i),UT(a.y,o,n,i),UT(a.z,o,n,i))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),IT=Fm([FT,PT]),LT=fi((([e])=>{const t=vi(e).toVar();return Gn(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),DT=fi((([e])=>{const t=vi(e).toVar();return Gn(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),VT=Fm([LT,fi((([e])=>{const t=Bi(e).toVar();return Gn(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),OT=Fm([DT,fi((([e])=>{const t=Bi(e).toVar();return Gn(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),GT=fi((([e,t])=>{const s=Si(t).toVar(),r=Ai(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(Si(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),kT=fi((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(GT(s,Si(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,Si(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,Si(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(GT(s,Si(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,Si(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,Si(4))),t.addAssign(e)})),zT=fi((([e,t,s])=>{const r=Ai(s).toVar(),i=Ai(t).toVar(),n=Ai(e).toVar();return r.bitXorAssign(i),r.subAssign(GT(i,Si(14))),n.bitXorAssign(r),n.subAssign(GT(r,Si(11))),i.bitXorAssign(n),i.subAssign(GT(n,Si(25))),r.bitXorAssign(i),r.subAssign(GT(i,Si(16))),n.bitXorAssign(r),n.subAssign(GT(r,Si(4))),i.bitXorAssign(n),i.subAssign(GT(n,Si(14))),r.bitXorAssign(i),r.subAssign(GT(i,Si(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),$T=fi((([e])=>{const t=Ai(e).toVar();return vi(t).div(vi(Ai(Si(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),HT=fi((([e])=>{const t=vi(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),WT=Fm([fi((([e])=>{const t=Si(e).toVar(),s=Ai(Ai(1)).toVar(),r=Ai(Ai(Si(3735928559)).add(s.shiftLeft(Ai(2))).add(Ai(13))).toVar();return zT(r.add(Ai(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),fi((([e,t])=>{const s=Si(t).toVar(),r=Si(e).toVar(),i=Ai(Ai(2)).toVar(),n=Ai().toVar(),o=Ai().toVar(),a=Ai().toVar();return n.assign(o.assign(a.assign(Ai(Si(3735928559)).add(i.shiftLeft(Ai(2))).add(Ai(13))))),n.addAssign(Ai(r)),o.addAssign(Ai(s)),zT(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),fi((([e,t,s])=>{const r=Si(s).toVar(),i=Si(t).toVar(),n=Si(e).toVar(),o=Ai(Ai(3)).toVar(),a=Ai().toVar(),u=Ai().toVar(),l=Ai().toVar();return a.assign(u.assign(l.assign(Ai(Si(3735928559)).add(o.shiftLeft(Ai(2))).add(Ai(13))))),a.addAssign(Ai(n)),u.addAssign(Ai(i)),l.addAssign(Ai(r)),zT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),fi((([e,t,s,r])=>{const i=Si(r).toVar(),n=Si(s).toVar(),o=Si(t).toVar(),a=Si(e).toVar(),u=Ai(Ai(4)).toVar(),l=Ai().toVar(),d=Ai().toVar(),c=Ai().toVar();return l.assign(d.assign(c.assign(Ai(Si(3735928559)).add(u.shiftLeft(Ai(2))).add(Ai(13))))),l.addAssign(Ai(a)),d.addAssign(Ai(o)),c.addAssign(Ai(n)),kT(l,d,c),l.addAssign(Ai(i)),zT(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),fi((([e,t,s,r,i])=>{const n=Si(i).toVar(),o=Si(r).toVar(),a=Si(s).toVar(),u=Si(t).toVar(),l=Si(e).toVar(),d=Ai(Ai(5)).toVar(),c=Ai().toVar(),h=Ai().toVar(),p=Ai().toVar();return c.assign(h.assign(p.assign(Ai(Si(3735928559)).add(d.shiftLeft(Ai(2))).add(Ai(13))))),c.addAssign(Ai(l)),h.addAssign(Ai(u)),p.addAssign(Ai(a)),kT(c,h,p),c.addAssign(Ai(o)),h.addAssign(Ai(n)),zT(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),jT=Fm([fi((([e,t])=>{const s=Si(t).toVar(),r=Si(e).toVar(),i=Ai(WT(r,s)).toVar(),n=Fi().toVar();return n.x.assign(i.bitAnd(Si(255))),n.y.assign(i.shiftRight(Si(8)).bitAnd(Si(255))),n.z.assign(i.shiftRight(Si(16)).bitAnd(Si(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),fi((([e,t,s])=>{const r=Si(s).toVar(),i=Si(t).toVar(),n=Si(e).toVar(),o=Ai(WT(n,i,r)).toVar(),a=Fi().toVar();return a.x.assign(o.bitAnd(Si(255))),a.y.assign(o.shiftRight(Si(8)).bitAnd(Si(255))),a.z.assign(o.shiftRight(Si(16)).bitAnd(Si(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),qT=Fm([fi((([e])=>{const t=Ci(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=vi(CT(t.x,s)).toVar(),n=vi(CT(t.y,r)).toVar(),o=vi(HT(i)).toVar(),a=vi(HT(n)).toVar(),u=vi(ET(UT(WT(s,r),i,n),UT(WT(s.add(Si(1)),r),i.sub(1),n),UT(WT(s,r.add(Si(1))),i,n.sub(1)),UT(WT(s.add(Si(1)),r.add(Si(1))),i.sub(1),n.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=Si().toVar(),n=vi(CT(t.x,s)).toVar(),o=vi(CT(t.y,r)).toVar(),a=vi(CT(t.z,i)).toVar(),u=vi(HT(n)).toVar(),l=vi(HT(o)).toVar(),d=vi(HT(a)).toVar(),c=vi(wT(UT(WT(s,r,i),n,o,a),UT(WT(s.add(Si(1)),r,i),n.sub(1),o,a),UT(WT(s,r.add(Si(1)),i),n,o.sub(1),a),UT(WT(s.add(Si(1)),r.add(Si(1)),i),n.sub(1),o.sub(1),a),UT(WT(s,r,i.add(Si(1))),n,o,a.sub(1)),UT(WT(s.add(Si(1)),r,i.add(Si(1))),n.sub(1),o,a.sub(1)),UT(WT(s,r.add(Si(1)),i.add(Si(1))),n,o.sub(1),a.sub(1)),UT(WT(s.add(Si(1)),r.add(Si(1)),i.add(Si(1))),n.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),KT=Fm([fi((([e])=>{const t=Ci(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=vi(CT(t.x,s)).toVar(),n=vi(CT(t.y,r)).toVar(),o=vi(HT(i)).toVar(),a=vi(HT(n)).toVar(),u=Bi(ET(IT(jT(s,r),i,n),IT(jT(s.add(Si(1)),r),i.sub(1),n),IT(jT(s,r.add(Si(1))),i,n.sub(1)),IT(jT(s.add(Si(1)),r.add(Si(1))),i.sub(1),n.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si().toVar(),r=Si().toVar(),i=Si().toVar(),n=vi(CT(t.x,s)).toVar(),o=vi(CT(t.y,r)).toVar(),a=vi(CT(t.z,i)).toVar(),u=vi(HT(n)).toVar(),l=vi(HT(o)).toVar(),d=vi(HT(a)).toVar(),c=Bi(wT(IT(jT(s,r,i),n,o,a),IT(jT(s.add(Si(1)),r,i),n.sub(1),o,a),IT(jT(s,r.add(Si(1)),i),n,o.sub(1),a),IT(jT(s.add(Si(1)),r.add(Si(1)),i),n.sub(1),o.sub(1),a),IT(jT(s,r,i.add(Si(1))),n,o,a.sub(1)),IT(jT(s.add(Si(1)),r,i.add(Si(1))),n.sub(1),o,a.sub(1)),IT(jT(s,r.add(Si(1)),i.add(Si(1))),n,o.sub(1),a.sub(1)),IT(jT(s.add(Si(1)),r.add(Si(1)),i.add(Si(1))),n.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),XT=Fm([fi((([e])=>{const t=vi(e).toVar(),s=Si(RT(t)).toVar();return $T(WT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),fi((([e])=>{const t=Ci(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar();return $T(WT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar();return $T(WT(s,r,i))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),fi((([e])=>{const t=Ii(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar(),n=Si(RT(t.w)).toVar();return $T(WT(s,r,i,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),YT=Fm([fi((([e])=>{const t=vi(e).toVar(),s=Si(RT(t)).toVar();return Bi($T(WT(s,Si(0))),$T(WT(s,Si(1))),$T(WT(s,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),fi((([e])=>{const t=Ci(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar();return Bi($T(WT(s,r,Si(0))),$T(WT(s,r,Si(1))),$T(WT(s,r,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),fi((([e])=>{const t=Bi(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar();return Bi($T(WT(s,r,i,Si(0))),$T(WT(s,r,i,Si(1))),$T(WT(s,r,i,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),fi((([e])=>{const t=Ii(e).toVar(),s=Si(RT(t.x)).toVar(),r=Si(RT(t.y)).toVar(),i=Si(RT(t.z)).toVar(),n=Si(RT(t.w)).toVar();return Bi($T(WT(s,r,i,n,Si(0))),$T(WT(s,r,i,n,Si(1))),$T(WT(s,r,i,n,Si(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),QT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=vi(0).toVar(),l=vi(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(qT(a))),l.mulAssign(i),a.mulAssign(n)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),ZT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=Bi(0).toVar(),l=vi(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(KT(a))),l.mulAssign(i),a.mulAssign(n)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),JT=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar();return Ci(QT(a,o,n,i),QT(a.add(Bi(Si(19),Si(193),Si(17))),o,n,i))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),e_=fi((([e,t,s,r])=>{const i=vi(r).toVar(),n=vi(s).toVar(),o=Si(t).toVar(),a=Bi(e).toVar(),u=Bi(ZT(a,o,n,i)).toVar(),l=vi(QT(a.add(Bi(Si(19),Si(193),Si(17))),o,n,i)).toVar();return Ii(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),t_=Fm([fi((([e,t,s,r,i,n,o])=>{const a=Si(o).toVar(),u=vi(n).toVar(),l=Si(i).toVar(),d=Si(r).toVar(),c=Si(s).toVar(),h=Si(t).toVar(),p=Ci(e).toVar(),g=Bi(YT(Ci(h.add(d),c.add(l)))).toVar(),m=Ci(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=Ci(Ci(vi(h),vi(c)).add(m)).toVar(),y=Ci(f.sub(p)).toVar();return Ti(a.equal(Si(2)),(()=>Fo(y.x).add(Fo(y.y)))),Ti(a.equal(Si(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),fi((([e,t,s,r,i,n,o,a,u])=>{const l=Si(u).toVar(),d=vi(a).toVar(),c=Si(o).toVar(),h=Si(n).toVar(),p=Si(i).toVar(),g=Si(r).toVar(),m=Si(s).toVar(),f=Si(t).toVar(),y=Bi(e).toVar(),b=Bi(YT(Bi(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Bi(Bi(vi(f),vi(m),vi(g)).add(b)).toVar(),T=Bi(x.sub(y)).toVar();return Ti(l.equal(Si(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),Ti(l.equal(Si(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),s_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=vi(1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();l.assign(qo(l,s))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),r_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=Ci(1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();Ti(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Ci(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Ci(CT(n.x,o),CT(n.y,a)).toVar(),l=Bi(1e6,1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{const s=vi(t_(u,e,t,o,a,i,r)).toVar();Ti(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),Ti(r.equal(Si(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),n_=Fm([s_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=vi(1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();d.assign(qo(d,n))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),o_=Fm([r_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=Ci(1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();Ti(n.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(n)})).ElseIf(n.lessThan(d.y),(()=>{d.y.assign(n)}))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),a_=Fm([i_,fi((([e,t,s])=>{const r=Si(s).toVar(),i=vi(t).toVar(),n=Bi(e).toVar(),o=Si().toVar(),a=Si().toVar(),u=Si().toVar(),l=Bi(CT(n.x,o),CT(n.y,a),CT(n.z,u)).toVar(),d=Bi(1e6,1e6,1e6).toVar();return uc({start:-1,end:Si(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:Si(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:Si(1),name:"z",condition:"<="},(({z:s})=>{const n=vi(t_(l,e,t,s,o,a,u,i,r)).toVar();Ti(n.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(n)})).ElseIf(n.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(n)})).ElseIf(n.lessThan(d.z),(()=>{d.z.assign(n)}))}))}))})),Ti(r.equal(Si(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=fi((([e])=>{const t=e.y,s=e.z,r=Bi().toVar();return Ti(t.lessThan(1e-4),(()=>{r.assign(Bi(s,s,s))})).Else((()=>{let i=e.x;i=i.sub(vo(i)).mul(6).toVar();const n=Si(zo(i)),o=i.sub(vi(n)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());Ti(n.equal(Si(0)),(()=>{r.assign(Bi(s,l,a))})).ElseIf(n.equal(Si(1)),(()=>{r.assign(Bi(u,s,a))})).ElseIf(n.equal(Si(2)),(()=>{r.assign(Bi(a,s,l))})).ElseIf(n.equal(Si(3)),(()=>{r.assign(Bi(a,u,s))})).ElseIf(n.equal(Si(4)),(()=>{r.assign(Bi(l,a,s))})).Else((()=>{r.assign(Bi(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),l_=fi((([e])=>{const t=Bi(e).toVar(),s=vi(t.x).toVar(),r=vi(t.y).toVar(),i=vi(t.z).toVar(),n=vi(qo(s,qo(r,i))).toVar(),o=vi(Ko(s,Ko(r,i))).toVar(),a=vi(o.sub(n)).toVar(),u=vi().toVar(),l=vi().toVar(),d=vi().toVar();return d.assign(o),Ti(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),Ti(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{Ti(s.greaterThanEqual(o),(()=>{u.assign(r.sub(i).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vn(2,i.sub(s).div(a)))})).Else((()=>{u.assign(Vn(4,s.sub(r).div(a)))})),u.mulAssign(1/6),Ti(u.lessThan(0),(()=>{u.addAssign(1)}))})),Bi(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),d_=fi((([e])=>{const t=Bi(e).toVar(),s=Pi(jn(t,Bi(.04045))).toVar(),r=Bi(t.div(12.92)).toVar(),i=Bi(sa(Ko(t.add(Bi(.055)),Bi(0)).div(1.055),Bi(2.4))).toVar();return la(r,i,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),c_=(e,t)=>{e=vi(e),t=vi(t);const s=Ci(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},h_=(e,t,s,r)=>la(e,t,s[r].clamp()),p_=(e,t,s=mu())=>h_(e,t,s,"x"),g_=(e,t,s=mu())=>h_(e,t,s,"y"),m_=(e,t,s,r,i)=>la(e,t,c_(s,r[i])),f_=(e,t,s,r=mu())=>m_(e,t,s,r,"x"),y_=(e,t,s,r=mu())=>m_(e,t,s,r,"y"),b_=(e=1,t=0,s=mu())=>s.mul(e).add(t),x_=(e,t=1)=>(e=vi(e)).abs().pow(t).mul(e.sign()),T_=(e,t=1,s=.5)=>vi(e).sub(s).mul(t).add(s),__=(e=mu(),t=1,s=0)=>qT(e.convert("vec2|vec3")).mul(t).add(s),N_=(e=mu(),t=1,s=0)=>KT(e.convert("vec2|vec3")).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ii(KT(e),qT(e.add(Ci(19,73)))).mul(t).add(s)},S_=(e=mu(),t=1)=>n_(e.convert("vec2|vec3"),t,Si(1)),A_=(e=mu(),t=1)=>o_(e.convert("vec2|vec3"),t,Si(1)),R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,Si(1)),C_=(e=mu())=>XT(e.convert("vec2|vec3")),E_=(e=mu(),t=3,s=2,r=.5,i=1)=>QT(e,Si(t),s,r).mul(i),w_=(e=mu(),t=3,s=2,r=.5,i=1)=>JT(e,Si(t),s,r).mul(i),M_=(e=mu(),t=3,s=2,r=.5,i=1)=>ZT(e,Si(t),s,r).mul(i),B_=(e=mu(),t=3,s=2,r=.5,i=1)=>e_(e,Si(t),s,r).mul(i),U_=fi((([e,t,s])=>{const r=Ao(e).toVar("nDir"),i=On(vi(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),n=On(vi(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Bi().toVar("rbminmax");o.x=r.x.greaterThan(vi(0)).select(i.x,n.x),o.y=r.y.greaterThan(vi(0)).select(i.y,n.y),o.z=r.z.greaterThan(vi(0)).select(i.z,n.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),F_=fi((([e,t])=>{const s=e.x,r=e.y,i=e.z;let n=t.element(0).mul(.886227);return n=n.add(t.element(1).mul(1.023328).mul(r)),n=n.add(t.element(2).mul(1.023328).mul(i)),n=n.add(t.element(3).mul(1.023328).mul(s)),n=n.add(t.element(4).mul(.858086).mul(s).mul(r)),n=n.add(t.element(5).mul(.858086).mul(r).mul(i)),n=n.add(t.element(6).mul(i.mul(i).mul(.743125).sub(.247708))),n=n.add(t.element(7).mul(.858086).mul(s).mul(i)),n=n.add(t.element(8).mul(.429043).mul(Gn(s,s).sub(Gn(r,r)))),n})),P_=new hm;class I_ extends Dg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,i=this.nodes.getBackgroundNode(e)||e.background;let n=!1;if(null===i)r._clearColor.getRGB(P_,Se),P_.a=r._clearColor.a;else if(!0===i.isColor)i.getRGB(P_,Se),P_.a=1,n=!0;else if(!0===i.isNode){const s=this.get(e),n=i;P_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ii(n).mul(Lf),{getUV:()=>Df.mul(ll),getTextureLevel:()=>If});let t=Wd();t=t.setZ(t.w);const r=new ih;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ii(n).mul(Lf),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",i);if(!0===r.autoClear||!0===n){const e=s.clearColorValue;e.r=P_.r,e.g=P_.g,e.b=P_.b,e.a=P_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let L_=0;class D_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=L_++}}class V_{constructor(e,t,s,r,i,n,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=i,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new D_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class O_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class G_{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class k_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class z_ extends k_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class $_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let H_=0;class W_{constructor(e=null){this.id=H_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class j_{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class q_ extends j_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class K_ extends j_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class X_ extends j_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Y_ extends j_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class Q_ extends j_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends j_{constructor(e,t=new i){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class J_ extends j_{constructor(e,t=new n){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class eN extends q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class tN extends K_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const aN=[.125,.215,.35,.446,.526,.582],uN=20,lN=new xe(-1,1,1,-1,0,1),dN=new Be(90,1),cN=new e;let hN=null,pN=0,gN=0;const mN=(1+Math.sqrt(5))/2,fN=1/mN,yN=[new s(-mN,fN,0),new s(mN,fN,0),new s(-fN,0,mN),new s(fN,0,mN),new s(0,mN,-fN),new s(0,mN,fN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],bN=[3,1,5,0,4,2],xN=Hp(mu(),gu("faceIndex")).normalize(),TN=Bi(xN.x,xN.y.negate(),xN.z);class _N{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(e,t=0,s=.1,r=100){hN=this._renderer.getRenderTarget(),pN=this._renderer.getActiveCubeFace(),gN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const i=this._allocateTargets();return i.depthBuffer=!0,this._sceneToCubeUV(e,s,r,i),t>0&&this._blur(i,0,0,t),this._applyPMREM(i),this._cleanup(i),i}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=AN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=RN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=aN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],i=bN[e];b.set(r,m*g*i),x.set(h,f*g*i);const n=[i,i,i,i,i,i];T.set(n,y*g*i)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),i.push(new k(_,null)),n>4&&n--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:i}}(i)),this._blurMaterial=function(e,t,r){const i=Rl(new Array(uN).fill(0)),n=en(new s(0,1,0)),o=en(0),a=vi(uN),u=en(0),l=en(1),d=_u(null),c=en(0),h=vi(1/t),p=vi(1/r),g=vi(e),m={n:a,latitudinal:u,weights:i,poleAxis:n,outputDirection:TN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=SN("blur");return f.uniforms=m,f.fragmentNode=Kp({...m,latitudinal:u.equal(1)}),f}(i,e,t)}return i}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,lN)}_sceneToCubeUV(e,t,s,r){const i=dN;i.near=t,i.far=s;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(cN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(cN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,i);for(let t=0;t<6;t++){const s=t%3;0===s?(i.up.set(0,n[t],0),i.lookAt(o[t],0,0)):1===s?(i.up.set(0,0,n[t]),i.lookAt(0,o[t],0)):(i.up.set(0,n[t],0),i.lookAt(0,0,o[t]));const u=this._cubeSize;vN(r,s*u,t>2?u:0,u,u),a.render(e,i)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=AN(e)):null===this._equirectMaterial&&(this._equirectMaterial=RN(e));const i=r?this._cubemapMaterial:this._equirectMaterial;i.fragmentNode.value=e;const n=this._lodMeshes[0];n.material=i;const o=this._cubeSize;vN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(n,lN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;tuN&&console.warn(`sigmaRadians, ${i}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,lN)}}function NN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function vN(e,t,s,r,i){e.viewport.set(t,s,r,i),e.scissor.set(t,s,r,i)}function SN(e){const t=new ih;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function AN(e){const t=SN("cubemap");return t.fragmentNode=_l(e,TN),t}function RN(e){const t=SN("equirect");return t.fragmentNode=_u(e,bh(TN),0),t}const CN=new WeakMap,EN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),wN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),MN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class BN{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=fm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new W_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=CN.get(this.renderer);return void 0===e&&(e=new Ug,CN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new xh(e,t)}createPMREMGenerator(){return new _N(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let i,n=!0;for(const e of t)r.push(e),n=n&&!0!==e.groupNode.shared;return n?(i=s.get(r),void 0===i&&(i=new D_(e,r,this.bindingsIndexes[e].group,r),s.set(r,i))):i=new D_(e,r,this.bindingsIndexes[e].group,r),i}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const i=s[e][r];(t[r]||(t[r]=[])).push(...i)}e=[];for(const s in t){const r=t[s],i=this._getBindGroup(s,r);e.push(i)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(n)}u`:"0u";if("bool"===i)return n?"true":"false";if("color"===i)return`${this.getType("vec3")}( ${MN(n.r)}, ${MN(n.g)}, ${MN(n.b)} )`;const o=this.getTypeLength(i),a=this.getComponentType(i),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)} )`;if(3===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)} )`;if(4===o)return`${this.getType(i)}( ${u(n.x)}, ${u(n.y)}, ${u(n.z)}, ${u(n.w)} )`;if(o>4&&n&&(n.isMatrix3||n.isMatrix4))return`${this.getType(i)}( ${n.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(i)}()`;throw new Error(`NodeBuilder: Type '${i}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new O_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=EN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return wN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,i=e.normalized;let n;return e instanceof Ie||!0===i||(n=this.getTypeFromArray(s)),this.getTypeFromLength(r,n)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=fm(this.stack),this.stacks.push(xi()||this.stack),bi(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,bi(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(void 0===r){const i=this.uniforms.index++;r=new O_("nodeAttribute"+i,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const i=this.getDataFromNode(e,s,this.globalCache);let n=i.uniform;if(void 0===n){const o=this.uniforms.index++;n=new G_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(n),i.uniform=n}return n}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const i=this.getDataFromNode(e,r);let n=i.variable;if(void 0===n){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),n=new k_(t,s),e.push(n),i.variable=n}return n}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let i=r.varying;if(void 0===i){const e=this.varyings,n=e.length;null===t&&(t="nodeVarying"+n),i=new z_(t,s),e.push(i),r.varying=i}return i}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let i=r.code;if(void 0===i){const e=this.codes[s]||(this.codes[s]=[]),n=e.length;i=new $_("nodeCode"+n,t),e.push(i),r.code=i}return i}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let i=!0,n=t;for(;n;){if(!0===r.get(n)){i=!1;break}n=this.getDataFromNode(n).parentNodeBlock}if(i)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),i=r.flowCodes||(r.flowCodes=[]),n=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);i.push(t),n.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new ax,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new pm(e.type,e.name);e.layout=null;const r=e.call(s),i=this.flowStagesNode(r,t.type);return e.layout=t,i}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,i=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new W_,this.stack=fm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=i,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const i=this.shaderStage;this.setShaderStage(e);const n=this.flowChildNode(t,s);return null!==r&&(n.code+=`${this.tab+r} = ${n.result};\n`),this.flowCode[e]=this.flowCode[e]+n.code,this.setShaderStage(i),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new ih),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new eN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new tN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new sN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new rN(e);if("color"===t)return new iN(e);if("mat3"===t)return new nN(e);if("mat4"===t)return new oN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),i=this.getTypeLength(s);return 16===r&&9===i?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===i?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||i>4||0===i?e:r===i?`${this.getType(s)}( ${e} )`:r>i?this.format(`${e}.${"xyz".slice(0,i)}`,this.getTypeFromLength(i,this.getComponentType(t)),s):4===i&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&i>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class UN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class FN{constructor(e,t,s=null,r="",i=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=i}}FN.isNodeFunctionInput=!0;class PN extends xT{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=rT(this.light),i=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:i},e.stack,e)}}const IN=new n,LN=new n;let DN=null;class VN extends xT{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=en(new s).setGroup(Qi),this.halfWidth=en(new s).setGroup(Qi),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;LN.identity(),IN.copy(t.matrixWorld),IN.premultiply(s),LN.extractRotation(IN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(LN),this.halfHeight.value.applyMatrix4(LN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(DN.LTC_FLOAT_1),s=_u(DN.LTC_FLOAT_2)):(t=_u(DN.LTC_HALF_1),s=_u(DN.LTC_HALF_2));const{colorNode:r,light:i}=this,n=e.context.lightingModel,o=sT(i),a=e.context.reflectedLight;n.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){DN=e}}class ON extends xT{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=en(0).setGroup(Qi),this.penumbraCosNode=en(0).setGroup(Qi),this.cutoffDistanceNode=en(0).setGroup(Qi),this.decayExponentNode=en(0).setGroup(Qi)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:i,light:n}=this,o=sT(n).sub(el),a=o.normalize(),u=a.dot(rT(n)),l=this.getSpotAttenuation(u),d=o.length(),c=TT({lightDistance:d,cutoffDistance:r,decayExponent:i}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class GN extends ON{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,Ci(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class kN extends xT{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class zN extends xT{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=eT(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=en(new e).setGroup(Qi)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:r}=this,i=ul.dot(r).mul(.5).add(.5),n=la(s,t,i);e.context.irradiance.addAssign(n)}}class $N extends xT{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=F_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class HN{parseFunction(){console.warn("Abstract function.")}}class WN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}WN.isNodeFunction=!0;const jN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,qN=/[a-z_0-9]+/gi,KN="#pragma main";class XN extends WN{constructor(e){const{type:t,inputs:s,name:r,precision:i,inputsCode:n,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(KN),s=-1!==t?e.slice(t+12):e,r=s.match(jN);if(null!==r&&5===r.length){const i=r[4],n=[];let o=null;for(;null!==(o=qN.exec(i));)n.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Jp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=Sh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Qi),r=Ml("density","float",s).setGroup(Qi);e=vx(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Qi),r=Ml("near","float",s).setGroup(Qi),i=Ml("far","float",s).setGroup(Qi);e=_x(t,r,i)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,i=null){const n=this.nodeFrame;return n.renderer=e,n.scene=t,n.object=s,n.camera=r,n.material=i,n}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return QN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return QN.set(e,s),r}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new UN,this.nodeBuilderCache=new Map}}const JN=new me;class ev{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new i,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let i=0;i{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),i=this._renderContexts.get(e,t,this._renderTarget),n=e.overrideMaterial||s.material,o=this._objects.get(s,n,e,t,r.lightsNode,i,i.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ZN(this,s),this._animation=new Bg(this._nodes,this.info),this._attributes=new $g(s),this._background=new I_(this,this._nodes),this._geometries=new jg(this._attributes,this.info),this._textures=new cm(this,s,this.info),this._pipelines=new Jg(s,this._nodes),this._bindings=new em(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Lg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new nm(this.lighting),this._bundles=new sv,this._renderContexts=new lm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,i=r.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:ov;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new ev),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=i,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:i,renderList:n}=e,o=this._currentRenderContext,a=this._bundles.get(r,i),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=n.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,i,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(uv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(uv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new ev),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),dv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),lv.setFromProjectionMatrix(dv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),i.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,r){const i=this._scissor;e.isVector4?i.copy(e):i.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,i=0,n=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=i,o.maxDepth=n}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let i=null;if(null!==r&&(this._textures.updateRenderTarget(r),i=this._textures.get(r)),this.backend.clear(e,t,s,i),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const r=this.backend,i=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===i.has(t)){const e=()=>{t.removeEventListener("dispose",e),i.delete(t),n.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),n.updateForCompute(t);const s=n.getForCompute(t),a=i.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=cv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=cv.copy(t).floor()}else t=cv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,i=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,i)}readRenderTargetPixelsAsync(e,t,s,r,i,n=0,o=0){return this.backend.copyTextureToBuffer(e.textures[n],t,s,r,i,o)}_projectObject(e,t,s,r,i){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(i=i.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||lv.intersectsSprite(e)){!0===this.sortObjects&&cv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(dv);const{geometry:t,material:n}=e;n.visible&&r.push(e,t,n,s,cv.z,null,i)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||lv.intersectsObject(e))){const{geometry:t,material:n}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),cv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(dv)),Array.isArray(n)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,i,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,i);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,i)}_renderObjects(e,t,s,r,i=null){for(let n=0,o=e.length;n0?r:"";t=`${e.name} {\n\t${s} ${i.name}[${n}];\n};\n`}else{t=`${this.getVectorType(i.type)} ${this.getPropertyName(i,e)};`,n=!0}const o=i.node.precision;if(null!==o&&(t=Cv[o]+" "+t),n){t="\t"+t;const e=i.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let i="";for(const t in r){const s=r[t];i+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return i+=s.join("\n"),i}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Ev[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Ev[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${r.code}\n\t`,e===i&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const n=e[t];n.extensions=this.getExtensions(t),n.uniforms=this.getUniforms(t),n.attributes=this.getAttributes(t),n.varyings=this.getVaryings(t),n.vars=this.getVars(t),n.structs=this.getStructs(t),n.codes=this.getCodes(t),n.transforms=this.getTransforms(t),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const i=super.getUniformFromNode(e,t,s,r),n=this.getDataFromNode(e,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new vv(i.name,i.node,r),u.push(o);else if("cubeTexture"===t)o=new Sv(i.name,i.node,r),u.push(o);else if("texture3D"===t)o=new Av(i.name,i.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,i.name=`buffer${e.id}`;const t=new yv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=e[a];void 0===n&&(n=new Tv(s+"_"+a,r),e[a]=n,u.push(n)),o=this.getNodeUniform(i,t),n.addUniform(o)}n.uniformGPU=o}return i}}let Bv=null,Uv=null,Fv=null;class Pv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Bv=Bv||new t,this.renderer.getDrawingBufferSize(Bv)}getScissor(){return Uv=Uv||new r,this.renderer.getScissor(Uv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Fv=Fv||new hm,e.getClearColor(Fv),Fv.getRGB(Fv,this.renderer.currentColorSpace),Fv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Iv=0;class Lv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Dv{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,i=e.array,n=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,i,n),a.bufferGPU=l,a.bufferType=t,a.version=o.version),i instanceof Float32Array)u=r.FLOAT;else if(i instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(i instanceof Int16Array)u=r.SHORT;else if(i instanceof Uint32Array)u=r.UNSIGNED_INT;else if(i instanceof Int32Array)u=r.INT;else if(i instanceof Int8Array)u=r.BYTE;else if(i instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(i instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+i);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:i.byteLength,bytesPerElement:i.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Iv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,i,n);d=new Lv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,i=e.isInterleavedBufferAttribute?e.data:e,n=t.get(i),o=n.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t{!function i(){const n=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(n===e.WAIT_FAILED)return e.deleteSync(t),void r();n!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(i)}()}))}}let $v,Hv,Wv,jv=!1;class qv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===jv&&(this._init(this.gl),jv=!0)}_init(e){$v={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},Hv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},Wv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,i=!1){const{gl:n,extensions:o}=this;if(null!==e){if(void 0!==n[e])return n[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===n.RED&&(s===n.FLOAT&&(a=n.R32F),s===n.HALF_FLOAT&&(a=n.R16F),s===n.UNSIGNED_BYTE&&(a=n.R8),s===n.UNSIGNED_SHORT&&(a=n.R16),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),t===n.RED_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.R8UI),s===n.UNSIGNED_SHORT&&(a=n.R16UI),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),t===n.RG&&(s===n.FLOAT&&(a=n.RG32F),s===n.HALF_FLOAT&&(a=n.RG16F),s===n.UNSIGNED_BYTE&&(a=n.RG8),s===n.UNSIGNED_SHORT&&(a=n.RG16),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),t===n.RG_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RG8UI),s===n.UNSIGNED_SHORT&&(a=n.RG16UI),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),t===n.RGB&&(s===n.FLOAT&&(a=n.RGB32F),s===n.HALF_FLOAT&&(a=n.RGB16F),s===n.UNSIGNED_BYTE&&(a=n.RGB8),s===n.UNSIGNED_SHORT&&(a=n.RGB16),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I),s===n.UNSIGNED_BYTE&&(a=r===De&&!1===i?n.SRGB8:n.RGB8),s===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),s===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),t===n.RGB_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGB8UI),s===n.UNSIGNED_SHORT&&(a=n.RGB16UI),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I)),t===n.RGBA&&(s===n.FLOAT&&(a=n.RGBA32F),s===n.HALF_FLOAT&&(a=n.RGBA16F),s===n.UNSIGNED_BYTE&&(a=n.RGBA8),s===n.UNSIGNED_SHORT&&(a=n.RGBA16),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I),s===n.UNSIGNED_BYTE&&(a=r===De&&!1===i?n.SRGB8_ALPHA8:n.RGBA8),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),t===n.RGBA_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),s===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I)),t===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),t===n.DEPTH_STENCIL&&s===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:i}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,$v[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,$v[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,$v[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,Hv[t.magFilter]);const n=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&n?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,Hv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,Wv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const n=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,i.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,i=this.getGLTextureType(e);let n=r[i];void 0===n&&(n=t.createTexture(),s.state.bindTexture(i,n),t.texParameteri(i,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(i,t.TEXTURE_MAG_FILTER,t.NEAREST),r[i]=n),s.set(e,{textureGPU:n,glTextureType:i,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:i,width:n,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,i,d,n,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,i,d,n,o,a):e.isVideoTexture||s.texStorage2D(h,i,d,n,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:i,glTextureType:n,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(n,i),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(n,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:i}=t,{textureGPU:n,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===n)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,n),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,i=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;i.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),i.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),i.bindFramebuffer(r.READ_FRAMEBUFFER,s),i.bindTexture(r.TEXTURE_2D,n),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),i.unbindTexture()}else{const e=r.createFramebuffer();i.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,n,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else i.bindTexture(r.TEXTURE_2D,n),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),i.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:i,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;i>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,i,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(i>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,i,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,i,n){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+n:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*i*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,i,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let r=0;return e===s.UNSIGNED_BYTE&&(r=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Kv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Xv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const Yv={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class Qv{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:r,object:i,type:n,info:o,index:a}=this;0!==a?s.drawElements(r,t,n,e):s.drawArrays(r,e,t),o.update(i,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:i,type:n,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(i,t,n,e,s):r.drawArraysInstanced(i,e,t,s),u.update(a,t,i,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:i,object:n,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),i=r.previousContext,n=e.occlusionQueryCount;n>0&&(n>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const i=r.framebuffers[e.getCacheKey()],n=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,i);for(let s=0;s{let o=0;for(let t=0;t0&&e.add(r[t]),s[t]=null,i.deleteQuery(n),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,i,n){return this.textureUtils.copyTextureToBuffer(e,t,s,r,i,n)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Mv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,i="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(i,r),t.compileShader(i),this.set(e,{shaderGPU:i})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:i,vertexProgram:n}=r,o=s.createProgram(),a=this.get(i).shaderGPU,u=this.get(n).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const i=new Promise((t=>{const i=this.parallel,n=()=>{s.getProgramParameter(o,i.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(n)};n()}));t.push(i)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],i=Math.max(t-6,0),n=Math.min(t+6,s.length);for(let e=i;e":" "} ${i}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),i=e.getShaderInfoLog(t).trim();if(r&&""===i)return"";const n=/ERROR: 0:(\d+)/.exec(i);if(n){const r=parseInt(n[1]);return s.toUpperCase()+"\n\n"+i+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return i}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,i=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const n=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+i+"\n"+n+"\n"+o)}else""!==i&&console.warn("THREE.WebGLProgram: Program Info Log:",i)}}_completeCompile(e,t){const{state:s,gl:r}=this,i=this.get(t),{programGPU:n,fragmentShader:o,vertexShader:a}=i;!1===r.getProgramParameter(n,r.LINK_STATUS)&&this._logProgramError(n,o,a),s.useProgram(n);const u=e.getBindings();this._setupBindings(u,n),this.set(t,{programGPU:n})}createComputePipeline(e,t){const{state:s,gl:r}=this,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:n}=e,o=r.createProgram(),a=this.get(i).shaderGPU,u=this.get(n).shaderGPU,l=n.transforms,d=[],c=[];for(let e=0;eYv[t]===e)),s=this.extensions;for(let e=0;e0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const i=[],l=e.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Hf,stripIndexFormat:ay},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Hf,stripIndexFormat:ay},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:i,height:n}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:i,height:n,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),i=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:ty,storeOp:Jf,clearValue:[0,0,0,0]}]});n.setPipeline(e),n.setBindGroup(0,i),n.draw(4,1,0,0),n.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const i=r.layers[s]||this._mipmapCreateBundles(e,t,s),n=this.device.createCommandEncoder({});this._mipmapRunBundles(n,i),this.device.queue.submit([n.finish()]),0!==r.useCount&&(r.layers[s]=i),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),i=r.getBindGroupLayout(0);let n=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:s});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,dS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,cS={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class hS extends WN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:i,blockCode:n,outputType:o}=(e=>{const t=(e=e.trim()).match(lS);if(null!==t&&4===t.length){const s=t[2],r=[];let i=null;for(;null!==(i=dS.exec(s));)r.push({name:i[1],type:i[2]});const n=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class pS extends HN{parseFunction(e){return new hS(e)}}const gS=self.GPUShaderStage,mS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},fS={vertex:gS?gS.VERTEX:1,fragment:gS?gS.FRAGMENT:2,compute:gS?gS.COMPUTE:4},yS={instance:!0,swizzleAssign:!1,storageBuffer:!0},bS={"^^":"tsl_xor"},xS={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},TS={},_S={tsl_xor:new sx("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new sx("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new sx("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new sx("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new sx("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new sx("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new sx("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new sx("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new sx("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new sx("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new sx("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new sx("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new sx("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new sx("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},NS={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(_S.pow_float=new sx("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),_S.pow_vec2=new sx("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[_S.pow_float]),_S.pow_vec3=new sx("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[_S.pow_float]),_S.pow_vec4=new sx("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[_S.pow_float]),NS.pow_float="tsl_pow_float",NS.pow_vec2="tsl_pow_vec2",NS.pow_vec3="tsl_pow_vec3",NS.pow_vec4="tsl_pow_vec4");let vS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(vS+="diagnostic( off, derivative_uniformity );\n");class SS extends BN{constructor(e,t){super(e,t,new pS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,i=this.shaderStage){return"fragment"===i?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,r,i,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${mS[e.wrapS]}S_${mS[e.wrapT]}T`;let s=TS[t];if(void 0===s){const r=[];let i=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const n=(e,t)=>{e===ls?(r.push(_S.repeatWrapping_float),i+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(r.push(_S.clampWrapping_float),i+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(r.push(_S.mirrorWrapping_float),i+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(i+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};n(e.wrapS,"x"),i+=",\n",n(e.wrapT,"y"),i+="\n\t);\n\n}\n",TS[t]=s=new sx(i,r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let i=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(i=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${i} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=i),i}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,i="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${i} )`:`textureLoad( ${t}, ${s}, ${i} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,i=this.shaderStage){let n=null;return n=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,i):this._generateTextureSample(e,t,s,r,i),n}generateTextureGrad(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(e,t,s,r,i,n=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this._generateTextureSampleLevel(e,t,s,r,i,n),o}generateTextureBias(e,t,s,r,i,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=bS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case Wy:return"read";case Hy:return"write";default:return"read_write"}else switch(e.access){case zy:return"read_write";case $y:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const i=super.getUniformFromNode(e,t,s,r),n=this.getDataFromNode(e,s,this.globalCache);if(void 0===n.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let n=null;if("texture"===t||"storageTexture"===t?n=new vv(i.name,i.node,o,e.access?e.access:null):"cubeTexture"===t?n=new Sv(i.name,i.node,o,e.access?e.access:null):"texture3D"===t&&(n=new Av(i.name,i.node,o,e.access?e.access:null)),n.store=!0===e.isStorageTextureNode,n.setVisibility(fS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===n.store){const e=new eS(`${i.name}_sampler`,i.node,o);e.setVisibility(fS[s]),u.push(e,n),r=[e,n]}else u.push(n),r=[n]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const i=new("buffer"===t?yv:rS)(e,o);i.setVisibility(fS[s]),u.push(i),r=i}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=e[a];void 0===n&&(n=new Tv(a,o),n.setVisibility(fS[s]),e[a]=n,u.push(n)),r=this.getNodeUniform(i,t),n.addUniform(r)}n.uniformGPU=r}return i}getBuiltin(e,t,s,r=this.shaderStage){const i=this.builtins[r]||(this.builtins[r]=new Map);return!1===i.has(e)&&i.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let i=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(i+=`\treturn ${s.result};\n`),i+="\n}\n",i}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:i}of s.values())t.push(`@builtin( ${e} ) ${r} : ${i}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:i}of this.scopedArrays.values()){const n=this.getType(r);t.push(`var<${s}> ${e}: array< ${n}, ${i} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e output : ${i};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let i=0;i";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array";else if(!0===t.isDepthTexture)r=`texture_depth${n}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d";else if(!0===i.node.isStorageTextureNode){r=`texture_storage_2d<${uS(t)}, ${this.getStorageAccess(i.node)}>`}else{r=`texture${n}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${i.name} : ${r};`)}else if("buffer"===i.type||"storageBuffer"===i.type||"indirectStorageBuffer"===i.type){const e=i.node,t=this.getType(e.bufferType),s=e.bufferCount,n=s>0&&"buffer"===i.type?", "+s:"",a=e.isAtomic?`atomic<${t}>`:`${t}`,u=`\t${i.name} : array< ${a}${n} >\n`,l=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding("NodeBuffer_"+e.id,u,l,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(i.type)),t=i.groupNode.name;(n[t]||(n[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${i.name} : ${e}`)}}for(const e in n){const t=n[e];i.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=i.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t);let r="// code\n\n";r+=this.flowCode[t];const i=this.flowNodes[t],n=i[i.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const e of i){const i=this.getFlowData(e),u=e.name;if(u&&(r.length>0&&(r+="\n"),r+=`\t// flow -> ${u}\n\t`),r+=`${i.code}\n\t`,e===n&&"compute"!==t)if(r+="// result\n\n\t","vertex"===t)r+=`varyings.Vertex = ${i.result};`;else if("fragment"===t)if(a)s.returnType=o.nodeType,r+=`return ${i.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar output : OutputStruct;\n\n",r+=`output.color = ${i.result};\n\n\treturn output;`}}s.flow=r}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return xS[e]||e}isAvailable(e){let t=yS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),yS[e]=t),t}_getWGSLMethod(e){return void 0!==_S[e]&&this._include(e),NS[e]}_include(e){const t=_S[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${vS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r=0,i=0){const n=e+"Struct";return`${this._getWGSLStruct(n,t)}\n@binding( ${r} ) @group( ${i} )\nvar<${s}> ${e} : ${n};`}}class AS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=uy.Depth24PlusStencil8:e.depth&&(t=uy.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?Gf:e.isLineSegments||e.isMesh&&!0===t.wireframe?kf:e.isLine?zf:e.isMesh?$f:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?uy.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const RS=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),CS=new Map([[Ie,["float16"]]]),ES=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class wS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,i=r.get(s);let n=i.buffer;if(void 0===n){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[s]===r&&(a=o.groups[s])),void 0===a&&(a=this.createBindGroup(e,u),s>0&&(o.groups[s]=a,o.versions[s]=r)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,i=t.get(e).buffer;s.queue.writeBuffer(i,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let i=0;const n=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,n=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:i});e.buffer=n}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}n.push({binding:i,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);n.push({binding:i,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const i=rb;let n;n=t.isSampledCubeTexture?tb:t.isSampledTexture3D?sb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?eb:Jy,o=e[r]=e.texture.createView({aspect:i,dimension:n,mipLevelCount:s})}}n.push({binding:i,resource:o})}i++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:n})}}class BS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:i,pipeline:n}=e,{vertexProgram:o,fragmentProgram:a}=n,u=this.backend,l=u.device,d=u.utils,c=u.get(n),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,i=s.getCurrentDepthStencilFormat(e),n={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:i,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(n)}createComputePipeline(e,t){const s=this.backend,r=s.device,i=s.get(e.computeProgram).module,n=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}n.pipeline=r.createComputePipeline({compute:i,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,i=e.blendSrc,n=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:i,a=null!==e.blendDstAlpha?e.blendDstAlpha:n,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const i=(e,r,i,n)=>{t={srcFactor:e,dstFactor:r,operation:Cy},s={srcFactor:i,dstFactor:n,operation:Cy}};if(e.premultipliedAlpha)switch(r){case F:i(my,xy,my,xy);break;case bt:i(my,my,my,my);break;case yt:i(gy,yy,gy,my);break;case ft:i(gy,fy,gy,by)}else switch(r){case F:i(by,xy,my,xy);break;case bt:i(by,my,by,my);break;case yt:i(gy,yy,gy,my);break;case ft:i(gy,fy,gy,fy)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=gy;break;case st:t=my;break;case rt:t=fy;break;case ut:t=yy;break;case it:t=by;break;case lt:t=xy;break;case ot:t=Ty;break;case dt:t=_y;break;case at:t=Ny;break;case ct:t=vy;break;case nt:t=Sy;break;case 211:t=Ay;break;case 212:t=Ry;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=Wf;break;case Es:t=Zf;break;case Cs:t=jf;break;case Rs:t=Kf;break;case As:t=qf;break;case Ss:t=Qf;break;case vs:t=Xf;break;case Ns:t=Yf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Py;break;case Ls:t=Iy;break;case Is:t=Ly;break;case Ps:t=Dy;break;case Fs:t=Vy;break;case Us:t=Oy;break;case Bs:t=Gy;break;case Ms:t=ky;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Cy;break;case Je:t=Ey;break;case et:t=wy;break;case Os:t=My;break;case Vs:t=By;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},i=this.backend.utils;switch(r.topology=i.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?oy:ay),s.side){case Oe:r.frontFace=sy,r.cullMode=ny;break;case x:r.frontFace=sy,r.cullMode=iy;break;case le:r.frontFace=sy,r.cullMode=ry;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Fy:Uy}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Zf;else{const s=e.depthFunc;switch(s){case Rt:t=Wf;break;case At:t=Zf;break;case St:t=jf;break;case vt:t=Kf;break;case Nt:t=qf;break;case _t:t=Qf;break;case Tt:t=Xf;break;case xt:t=Yf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class US extends Pv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new AS(this),this.attributeUtils=new wS(this),this.bindingUtils=new MS(this),this.pipelineUtils=new BS(this),this.textureUtils=new aS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const i=Object.values(ob),n=[];for(const e of i)r.features.has(e)&&n.push(e);const o={requiredFeatures:n,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const i=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ob.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:i}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const i=e.getCacheKey();let n=r[i];if(void 0===n){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,i=s.createQuerySet({type:"occlusion",count:r,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=i,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),n=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,n),n.occlusionQuerySet=i;const o=n.depthStencilAttachment;if(null!==e.textures){const t=n.colorAttachments;for(let s=0;s0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const r=8*s;let i=this.occludedResolveCache.get(r);void 0===i&&(i=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,i));const n=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,i,0),t.encoder.copyBufferToBuffer(i,0,n,0,r),t.occlusionQueryBuffer=n,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,i.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:r,pipeline:i}=e,n=e.getBindings(),o=this.get(r),a=this.get(i).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=n.length;e1?0:s;l.drawIndexed(t[s],r,e[s]/n,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:i,firstVertex:n}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,i,n,0,0);t.update(s,r,i)}else{const{vertexCount:r,instanceCount:i,firstVertex:n}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,i,n,0);t.update(s,r,i)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,i=this.utils,n=i.getSampleCountRenderContext(e.context),o=i.getCurrentColorSpace(e.context),a=i.getCurrentColorFormat(e.context),u=i.getCurrentDepthStencilFormat(e.context),l=i.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===n&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=n,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,i=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,r.getSampleCountRenderContext(i),r.getCurrentColorSpace(i),r.getCurrentColorFormat(i),r.getCurrentDepthStencilFormat(i),r.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,i,n){return this.textureUtils.copyTextureToBuffer(e,t,s,r,i,n)}async initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){this.device.pushErrorScope("out-of-memory");const r=await this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_renderContext_${e.id}`});if(await this.device.popErrorScope())return s.attemptingTimeStampQuerySetFailed||(console.error(`[GPUOutOfMemoryError][renderContext_${e.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.`),s.attemptingTimeStampQuerySetFailed=!0),void(s.timeStampQuerySet=null);const i={querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:i}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;const r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:i,resultBuffer:n,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,i,0),t.copyBufferToBuffer(i,0,n,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:i}=s.currentTimestampQueryBuffers;!0!==i&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),i=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,i),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new SS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,r=null,i=0){let n=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(n=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:i,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:i,origin:{x:n,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let i=null;i=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const n=this.get(e).texture;if(i.format!==n.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",i.format,n.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:i,origin:{x:s.x,y:s.y,z:0}},{texture:n},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new Zv(e)));super(new t(e),e),this.library=new PS,this.isWebGPURenderer=!0}}class LS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const DS=new ih,VS=new Tf(DS);class OS{constructor(e,t=Ii(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,DS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,VS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;VS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),VS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await VS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function GS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function kS(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function zS(e,t,s={}){return(s=GS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var $S=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=zS(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=GS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){kS(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:kS,saveRendererAndSceneState:zS,saveRendererState:GS});class HS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class WS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class jS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class qS extends WS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class KS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const i=new tr(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),vi()):ci(new this.nodes[e])}}class XS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const i=r[e];t[e]=s[i]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class YS extends rr{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new KS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),i=new XS;i.setTextures(t),i.setNodes(r),i.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t { - - return Object.entries( members ).map( ( [ name, value ] ) => { - - if ( typeof value === 'string' ) { - - return { name, type: value, isAtomic: false }; - - } - - return { name, type: value.type, isAtomic: value.atomic || false }; - - } ); - -}; - class OutputStructNode extends Node { static get type() { @@ -17990,7 +17974,6 @@ class StorageBufferNode extends BufferNode { this.isAtomic = false; this.bufferObject = false; - this.bufferStruct = false; this.bufferCount = bufferCount; this._attribute = null; @@ -18053,14 +18036,6 @@ class StorageBufferNode extends BufferNode { } - setBufferStruct( value ) { - - this.bufferStruct = value; - - return this; - - } - setAccess( value ) { this.access = value; @@ -18141,7 +18116,6 @@ class StorageBufferNode extends BufferNode { // Read-Write Storage const storage = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ) ); -const storageStruct = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferStruct( true ) ); const storageObject = ( value, type, count ) => nodeObject( new StorageBufferNode( value, type, count ).setBufferObject( true ) ); class StorageTextureNode extends TextureNode { @@ -38063,88 +38037,6 @@ ${ flowData.code } } - getTypeFromCustomStruct( shaderStage ) { - - const uniforms = this.uniforms[ shaderStage ]; - - const bufferStructMap = new Map(); - - uniforms.forEach( ( uniform ) => { - - const { name, node } = uniform; - const hasBufferStruct = node.bufferStruct === true; - bufferStructMap.set( name, hasBufferStruct ); - - } ); - - return bufferStructMap; - - } - - getMembersFromCustomStruct( members ) { - - const structMembers = members.map( ( { name, type, isAtomic } ) => { - - let finalType = wgslTypeLib[ type ]; - - if ( ! finalType ) { - - console.warn( `Unrecognized type: ${type}` ); - finalType = 'vec4'; - - } - - return `${name}: ${isAtomic ? `atomic<${finalType}>` : finalType}`; - - } ); - - return `\t${structMembers.join( ',\n\t' )}`; - - } - - getCustomStructNameFromShader( source ) { - - const functionRegex = /fn\s+\w+\s*\(([\s\S]*?)\)/g; // filter shader header - const parameterRegex = /(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g; // filter parameters - - const results = []; - - let match; - - while ( ( match = functionRegex.exec( source ) ) !== null ) { - - const parameterString = match[ 1 ]; - - let paramMatch; - - while ( ( paramMatch = parameterRegex.exec( parameterString ) ) !== null ) { - - const [ fullMatch, name, fullType, ptrType, arrayType, directStructName ] = paramMatch; - - const structName = arrayType || directStructName || null; - - const type = ptrType || fullType; - - if (Object.values(wgslTypeLib).includes(structName) || structName === null) { - - continue; - - } - - results.push( { - name, - type, - structName - } ); - - } - - } - - return results; - - } - getStructMembers( struct ) { const snippets = []; @@ -38352,14 +38244,12 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; - - const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; - const bufferSnippet = bufferNode.bufferStruct ? this.getMembersFromCustomStruct( bufferType ) : `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; + const bufferSnippet = `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; const bufferAccessMode = bufferNode.isStorageBufferNode ? `storage, ${ this.getStorageAccess( bufferNode ) }` : 'uniform'; - bufferSnippets.push( this._getWGSLStructBinding( bufferNode.bufferStruct, isArray, 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); + bufferSnippets.push( this._getWGSLStructBinding( 'NodeBuffer_' + bufferNode.id, bufferSnippet, bufferAccessMode, uniformIndexes.binding ++, uniformIndexes.group ) ); } else { @@ -38382,7 +38272,7 @@ ${ flowData.code } const group = uniformGroups[ name ]; - structSnippets.push( this._getWGSLStructBinding( false, false, name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); + structSnippets.push( this._getWGSLStructBinding( name, group.snippets.join( ',\n' ), 'uniform', group.index, group.id ) ); } @@ -38411,69 +38301,9 @@ ${ flowData.code } stageData.codes = this.getCodes( shaderStage ); stageData.directives = this.getDirectives( shaderStage ); stageData.scopedArrays = this.getScopedArrays( shaderStage ); - stageData.isBufferStruct = this.getTypeFromCustomStruct( shaderStage ); - stageData.customStructNames = this.getCustomStructNameFromShader( stageData.codes ); // - const reduceFlow = ( flow ) => { - - return flow.replace( /&(\w+)\.(\w+)/g, ( match, bufferName, uniformName ) => - - stageData.isBufferStruct.get( uniformName ) === true ? `&${bufferName}` : match - - ); - - }; - - const extractPointerNames = ( source ) => { - - const match = source.match( /\(([^)]+)\)/ ); - if ( ! match ) return []; - - const content = match[ 1 ]; - - return content - .split( /\s*,\s*/ ) - .map( part => part.trim() ) - .filter( part => part.includes( '&' ) ) - .map( part => part.replace( '&', '' ) ) - .filter( part => ! part.includes( '.' ) ); - - }; - - const createStructNameMapping = ( nodeBuffers, structs ) => { - - const resultMap = new Map(); - - for (let i = 0; i < nodeBuffers.length; i++) { - - const bufferName = nodeBuffers[i]; - const struct = structs[i]; - - resultMap.set(bufferName, struct.structName); - - } - - return resultMap; - - }; - - const replaceStructNamesInUniforms = ( shaderCode, map ) => { - - for ( const [ key, value ] of map.entries() ) { - - const regex = new RegExp( `\\b${key}Struct\\b`, 'g' ); - shaderCode = shaderCode.replace( regex, value ); - - } - - return shaderCode; - - }; - - - let pointerNames, structnameMapping; let flow = '// code\n\n'; flow += this.flowCode[ shaderStage ]; @@ -38498,68 +38328,6 @@ ${ flowData.code } flow += `${ flowSlotData.code }\n\t`; - - /* - REVIEW COMMENT remove after review - - before reduceFlow: - compute( &NodeBuffer_554.nodeUniform0, &NodeBuffer_558.nodeUniform1, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); - - after reduceFlow: reduceFlow checks whether there is a storageStruct and if so then the - postfix is ​​removed so that the pointer points to the struct and not to a content in the struct - compute( &NodeBuffer_554, &NodeBuffer_558, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); - - extractPointerNames reads the names of the reduced pointers and stores them in an array - Array(2) - 0: "NodeBuffer_554" - 1: "NodeBuffer_558" - - getCustomStructNameFromShader at the beginning reads the structNames from the shader header - Array(2) - 0: {name: 'drawBuffer', type: 'storage', structName: 'DrawBuffer'} - 1: {name: 'meshletInfo', type: 'storage', structName: 'MeshletInfo'} - - - createStructNameMapping links the automatic generated WGSLNodeBuilder for each struct with the struct name specified by the user. - This is necessary because in wgslFn the user can choose any name in the shader in ptr for structs. - - Map(2) - [[Entries]] - 0: {"NodeBuffer_554" => "DrawBuffer"} - 1: {"NodeBuffer_558" => "MeshletInfo"} - - replaceStructNames then replaces the names in the uniforms in the custom structs that the WGSLNodeBuilder - created with the name chosen by the user. - - before replaceStructNames: - - struct NodeBuffer_554Struct { - vertexCount: u32, - instanceCount: u32, - firstVertex: u32, - firstInstance: u32 - }; - @binding( 0 ) @group( 0 ) - var NodeBuffer_554 : NodeBuffer_554Struct; - - after replaceStructNames: - - struct DrawBuffer { - vertexCount: u32, - instanceCount: u32, - firstVertex: u32, - firstInstance: u32 - }; - @binding( 0 ) @group( 0 ) - var NodeBuffer_554 : DrawBuffer; - */ - - - flow = reduceFlow( flow ); - pointerNames = extractPointerNames(flow); - structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); - stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); - if ( node === mainNode && shaderStage !== 'compute' ) { flow += '// result\n\n\t'; @@ -38594,11 +38362,6 @@ ${ flowData.code } } - flow = reduceFlow( flow ); - pointerNames = extractPointerNames(flow); - structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); - stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); - } } @@ -38803,27 +38566,15 @@ ${vars} } - _getWGSLStructBinding( isBufferStruct, isArray, name, vars, access, binding = 0, group = 0 ) { + _getWGSLStructBinding( name, vars, access, binding = 0, group = 0 ) { const structName = name + 'Struct'; const structSnippet = this._getWGSLStruct( structName, vars ); - if ( ! isBufferStruct ) { - - return `${structSnippet} + return `${structSnippet} @binding( ${binding} ) @group( ${group} ) var<${access}> ${name} : ${structName};`; - } else { - - const StructName = isArray ? `array<${structName}>` : structName; - - return `${structSnippet} -@binding( ${binding} ) @group( ${group} ) -var<${access}> ${name} : ${StructName};`; - - } - } } @@ -42430,4 +42181,4 @@ class ClippingGroup extends Group { } -export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BRDF_GGX, BRDF_Lambert, BackSide, BasicEnvironmentNode, BatchNode, BoxGeometry, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DFGApprox, D_GGX, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, Discard, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EPSILON, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, F_Schlick, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fn, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, If, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, 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, Loader, Loop, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap$1 as PCFShadowMap, PI, PI2, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, 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_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScreenNode, ScriptableNode, ScriptableNodeResources, ScriptableValueNode, SetNode, ShaderNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, abs, acesFilmicToneMapping, acos, add, addMethodChaining, addNodeElement, agxToneMapping, all, alphaT, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, atomicAdd, atomicAnd, atomicFunc, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, attenuationColor, attenuationDistance, attribute, backgroundBlurriness, backgroundIntensity, backgroundRotation, batch, billboarding, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blendNormal, blur, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, cdl, ceil, checker, cineonToneMapping, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToWorking, colorToDirection, compute, cond, context, convert, convertColorSpace, convertToTexture, cos, createCanvasElement, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, deltaTime, densityFog, depth, depthPass, difference, diffuseColor, directPointLight, directionToColor, dispersion, distance, div, dodge, dot, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getNormalFromDepth, getParallaxCorrectNormal, getRoughness, getScreenPosition, getShIrradianceAt, getTextureIndex, getViewPosition, glsl, glslFn, grayscale, greaterThan, greaterThanEqual, hash, highPrecisionModelNormalViewMatrix, highPrecisionModelViewMatrix, hue, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, invocationLocalIndex, invocationSubgroupIndex, ior, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightPosition, lightTargetDirection, lightTargetPosition, lightViewPosition, lightingContext, lights, linearDepth, linearToneMapping, localId, log, log2, logarithmicDepthToViewZ, loop, luminance, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialAttenuationColor, materialAttenuationDistance, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIOR, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRefractionRatio, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularColor, materialSpecularIntensity, materialSpecularStrength, materialThickness, materialTransmission, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mixElement, mod, modInt, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, neutralToneMapping, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalFlat, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, notEqual, numWorkgroups, objectDirection, objectGroup, objectPosition, objectScale, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionPrevious, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, reinhardToneMapping, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rotate, rotateUV, roughness, round, rtt, sRGBTransferEOTF, sRGBTransferOETF, sampler, saturate, saturation, screen, screenCoordinate, screenSize, screenUV, scriptable, scriptableValue, select, setCurrentStack, shaderStages, shadow, sharedUniformGroup, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, smoothstepElement, specularColor, specularF90, spherizeUV, split, spritesheetUV, sqrt, stack, step, storage, storageBarrier, storageObject, storageStruct, storageTexture, string, struct, sub, subgroupIndex, subgroupSize, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBarrier, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, thickness, threshold, time, timerDelta, timerGlobal, timerLocal, toOutputColorSpace, toWorkingColorSpace, toneMapping, toneMappingExposure, toonOutlinePass, transformDirection, transformNormal, transformNormalToView, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transmission, transpose, tri, tri3, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, uniform, uniformArray, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, velocity, vertexColor, vertexIndex, vibrance, viewZToLogarithmicDepth, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSafeUV, viewportSharedTexture, viewportSize, viewportTexture, viewportTopLeft, viewportUV, wgsl, wgslFn, workgroupArray, workgroupBarrier, workgroupId, workingToColorSpace, xor }; +export { ACESFilmicToneMapping, AONode, AddEquation, AddOperation, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AmbientLightNode, AnalyticLightNode, ArrayElementNode, AssignNode, AttributeNode, BRDF_GGX, BRDF_Lambert, BackSide, BasicEnvironmentNode, BatchNode, BoxGeometry, Break, BufferAttribute, BufferAttributeNode, BufferGeometry, BufferNode, BumpMapNode, BundleGroup, BypassNode, ByteType, CacheNode, CineonToneMapping, ClampToEdgeWrapping, ClippingGroup, CodeNode, Color, ColorManagement, ColorSpaceNode, ComputeNode, ConstNode, ContextNode, Continue, ConvertNode, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureNode, CubeUVReflectionMapping, CullFaceBack, CullFaceFront, CullFaceNone, CustomBlending, DFGApprox, D_GGX, DataArrayTexture, DataTexture, DecrementStencilOp, DecrementWrapStencilOp, DepthFormat, DepthStencilFormat, DepthTexture, DirectionalLight, DirectionalLightNode, Discard, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicDrawUsage, EPSILON, EnvironmentNode, EqualCompare, EqualDepth, EqualStencilFunc, EquirectUVNode, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExpressionNode, F_Schlick, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fn, FogExp2Node, FogNode, FogRangeNode, FramebufferTexture, FrontFacingNode, FrontSide, Frustum, FunctionCallNode, FunctionNode, FunctionOverloadingNode, GLSLNodeParser, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, Group, HalfFloatType, HemisphereLight, HemisphereLightNode, IESSpotLight, IESSpotLightNode, INFINITY, If, IncrementStencilOp, IncrementWrapStencilOp, IndexNode, IndirectStorageBufferAttribute, InstanceNode, InstancedBufferAttribute, InstancedInterleavedBuffer, InstancedPointsNodeMaterial, IntType, InterleavedBuffer, InterleavedBufferAttribute, InvertStencilOp, IrradianceNode, 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, Loader, Loop, LoopNode, LuminanceAlphaFormat, LuminanceFormat, MRTNode, MatcapUVNode, Material, MaterialLoader, MaterialNode, MaterialReferenceNode, MathUtils, Matrix3, Matrix4, MaxEquation, MaxMipLevelNode, Mesh, MeshBasicMaterial, MeshBasicNodeMaterial, MeshLambertMaterial, MeshLambertNodeMaterial, MeshMatcapMaterial, MeshMatcapNodeMaterial, MeshNormalMaterial, MeshNormalNodeMaterial, MeshPhongMaterial, MeshPhongNodeMaterial, MeshPhysicalMaterial, MeshPhysicalNodeMaterial, MeshSSSNodeMaterial, MeshStandardMaterial, MeshStandardNodeMaterial, MeshToonMaterial, MeshToonNodeMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, ModelNode, ModelViewProjectionNode, MorphNode, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, Node, NodeAttribute, NodeBuilder, NodeCache, NodeCode, NodeFrame, NodeFunctionInput, NodeLoader, NodeMaterial, NodeMaterialLoader, NodeMaterialObserver, NodeObjectLoader, NodeShaderStage, NodeType, NodeUniform, NodeUpdateType, NodeUtils, NodeVar, NodeVarying, NormalBlending, NormalMapNode, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, Object3D, Object3DNode, ObjectLoader, ObjectSpaceNormalMap, OneFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, OutputStructNode, PCFShadowMap$1 as PCFShadowMap, PI, PI2, PMREMGenerator, PMREMNode, ParameterNode, PassNode, PerspectiveCamera, PhongLightingModel, PhysicalLightingModel, Plane, PointLight, PointLightNode, PointUVNode, PointsMaterial, PointsNodeMaterial, PostProcessing, PostProcessingUtils, PosterizeNode, PropertyNode, QuadMesh, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, 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_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGFormat, RGIntegerFormat, RTTNode, RangeNode, RectAreaLight, RectAreaLightNode, RedFormat, RedIntegerFormat, ReferenceNode, ReflectorNode, ReinhardToneMapping, RemapNode, RenderOutputNode, RenderTarget, RendererReferenceNode, RepeatWrapping, ReplaceStencilOp, Return, ReverseSubtractEquation, RotateNode, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, SceneNode, Schlick_to_F0, ScreenNode, ScriptableNode, ScriptableNodeResources, ScriptableValueNode, SetNode, ShaderNode, ShadowMaterial, ShadowNode, ShadowNodeMaterial, ShortType, SkinningNode, SphereGeometry, SplitNode, SpotLight, SpotLightNode, SpriteMaterial, SpriteNodeMaterial, SpriteSheetUVNode, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StackNode, StaticDrawUsage, StorageArrayElementNode, StorageBufferAttribute, StorageBufferNode, StorageInstancedBufferAttribute, StorageTexture, StorageTextureNode, SubtractEquation, SubtractiveBlending, TBNViewMatrix, TangentSpaceNormalMap, TempNode, Texture, Texture3DNode, TextureNode, TextureSizeNode, ToneMappingNode, ToonOutlinePassNode, TriplanarTexturesNode, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, UniformArrayNode, UniformGroupNode, UniformNode, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, UserDataNode, VSMShadowMap, V_GGX_SmithCorrelated, VarNode, VaryingNode, Vector2, Vector3, Vector4, VertexColorNode, ViewportDepthNode, ViewportDepthTextureNode, ViewportSharedTextureNode, ViewportTextureNode, VolumeNodeMaterial, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGPUCoordinateSystem, WebGPURenderer, ZeroFactor, ZeroStencilOp, abs, acesFilmicToneMapping, acos, add, addMethodChaining, addNodeElement, agxToneMapping, all, alphaT, and, anisotropy, anisotropyB, anisotropyT, any, append, arrayBuffer, asin, assign, atan, atan2, atomicAdd, atomicAnd, atomicFunc, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, attenuationColor, attenuationDistance, attribute, backgroundBlurriness, backgroundIntensity, backgroundRotation, batch, billboarding, bitAnd, bitNot, bitOr, bitXor, bitangentGeometry, bitangentLocal, bitangentView, bitangentWorld, bitcast, blendNormal, blur, bool, buffer, bufferAttribute, bumpMap, burn, bvec2, bvec3, bvec4, bypass, cache, call, cameraFar, cameraNear, cameraNormalMatrix, cameraPosition, cameraProjectionMatrix, cameraProjectionMatrixInverse, cameraViewMatrix, cameraWorldMatrix, cbrt, cdl, ceil, checker, cineonToneMapping, clamp, clearcoat, clearcoatRoughness, code, color, colorSpaceToWorking, colorToDirection, compute, cond, context, convert, convertColorSpace, convertToTexture, cos, createCanvasElement, cross, cubeTexture, dFdx, dFdy, dashSize, defaultBuildStages, defaultShaderStages, defined, degrees, deltaTime, densityFog, depth, depthPass, difference, diffuseColor, directPointLight, directionToColor, dispersion, distance, div, dodge, dot, drawIndex, dynamicBufferAttribute, element, emissive, equal, equals, equirectUV, exp, exp2, expression, faceDirection, faceForward, float, floor, fog, fract, frameGroup, frameId, frontFacing, fwidth, gain, gapSize, getConstNodeType, getCurrentStack, getDirection, getDistanceAttenuation, getGeometryRoughness, getNormalFromDepth, getParallaxCorrectNormal, getRoughness, getScreenPosition, getShIrradianceAt, getTextureIndex, getViewPosition, glsl, glslFn, grayscale, greaterThan, greaterThanEqual, hash, highPrecisionModelNormalViewMatrix, highPrecisionModelViewMatrix, hue, instance, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, inverseSqrt, invocationLocalIndex, invocationSubgroupIndex, ior, iridescence, iridescenceIOR, iridescenceThickness, ivec2, ivec3, ivec4, js, label, length, lengthSq, lessThan, lessThanEqual, lightPosition, lightTargetDirection, lightTargetPosition, lightViewPosition, lightingContext, lights, linearDepth, linearToneMapping, localId, log, log2, logarithmicDepthToViewZ, loop, luminance, mat2, mat3, mat4, matcapUV, materialAOMap, materialAlphaTest, materialAnisotropy, materialAnisotropyVector, materialAttenuationColor, materialAttenuationDistance, materialClearcoat, materialClearcoatNormal, materialClearcoatRoughness, materialColor, materialDispersion, materialEmissive, materialIOR, materialIridescence, materialIridescenceIOR, materialIridescenceThickness, materialLightMap, materialLineDashOffset, materialLineDashSize, materialLineGapSize, materialLineScale, materialLineWidth, materialMetalness, materialNormal, materialOpacity, materialPointWidth, materialReference, materialReflectivity, materialRefractionRatio, materialRotation, materialRoughness, materialSheen, materialSheenRoughness, materialShininess, materialSpecular, materialSpecularColor, materialSpecularIntensity, materialSpecularStrength, materialThickness, materialTransmission, max$1 as max, maxMipLevel, metalness, min$1 as min, mix, mixElement, mod, modInt, modelDirection, modelNormalMatrix, modelPosition, modelScale, modelViewMatrix, modelViewPosition, modelViewProjection, modelWorldMatrix, modelWorldMatrixInverse, morphReference, mrt, mul, mx_aastep, mx_cell_noise_float, mx_contrast, mx_fractal_noise_float, mx_fractal_noise_vec2, mx_fractal_noise_vec3, mx_fractal_noise_vec4, mx_hsvtorgb, mx_noise_float, mx_noise_vec3, mx_noise_vec4, mx_ramplr, mx_ramptb, mx_rgbtohsv, mx_safepower, mx_splitlr, mx_splittb, mx_srgb_texture_to_lin_rec709, mx_transform_uv, mx_worley_noise_float, mx_worley_noise_vec2, mx_worley_noise_vec3, negate, neutralToneMapping, nodeArray, nodeImmutable, nodeObject, nodeObjects, nodeProxy, normalFlat, normalGeometry, normalLocal, normalMap, normalView, normalWorld, normalize, not, notEqual, numWorkgroups, objectDirection, objectGroup, objectPosition, objectScale, objectViewPosition, objectWorldMatrix, oneMinus, or, orthographicDepthToViewZ, oscSawtooth, oscSine, oscSquare, oscTriangle, output, outputStruct, overlay, overloadingFn, parabola, parallaxDirection, parallaxUV, parameter, pass, passTexture, pcurve, perspectiveDepthToViewZ, pmremTexture, pointUV, pointWidth, positionGeometry, positionLocal, positionPrevious, positionView, positionViewDirection, positionWorld, positionWorldDirection, posterize, pow, pow2, pow3, pow4, property, radians, rand, range, rangeFog, reciprocal, reference, referenceBuffer, reflect, reflectVector, reflectView, reflector, refract, refractVector, refractView, reinhardToneMapping, remainder, remap, remapClamp, renderGroup, renderOutput, rendererReference, rotate, rotateUV, roughness, round, rtt, sRGBTransferEOTF, sRGBTransferOETF, sampler, saturate, saturation, screen, screenCoordinate, screenSize, screenUV, scriptable, scriptableValue, select, setCurrentStack, shaderStages, shadow, sharedUniformGroup, sheen, sheenRoughness, shiftLeft, shiftRight, shininess, sign, sin, sinc, skinning, skinningReference, smoothstep, smoothstepElement, specularColor, specularF90, spherizeUV, split, spritesheetUV, sqrt, stack, step, storage, storageBarrier, storageObject, storageTexture, string, sub, subgroupIndex, subgroupSize, tan, tangentGeometry, tangentLocal, tangentView, tangentWorld, temp, texture, texture3D, textureBarrier, textureBicubic, textureCubeUV, textureLoad, textureSize, textureStore, thickness, threshold, time, timerDelta, timerGlobal, timerLocal, toOutputColorSpace, toWorkingColorSpace, toneMapping, toneMappingExposure, toonOutlinePass, transformDirection, transformNormal, transformNormalToView, transformedBentNormalView, transformedBitangentView, transformedBitangentWorld, transformedClearcoatNormalView, transformedNormalView, transformedNormalWorld, transformedTangentView, transformedTangentWorld, transmission, transpose, tri, tri3, triNoise3D, triplanarTexture, triplanarTextures, trunc, tslFn, uint, uniform, uniformArray, uniformGroup, uniforms, userData, uv, uvec2, uvec3, uvec4, varying, varyingProperty, vec2, vec3, vec4, vectorComponents, velocity, vertexColor, vertexIndex, vibrance, viewZToLogarithmicDepth, viewZToOrthographicDepth, viewZToPerspectiveDepth, viewport, viewportBottomLeft, viewportCoordinate, viewportDepthTexture, viewportLinearDepth, viewportMipTexture, viewportResolution, viewportSafeUV, viewportSharedTexture, viewportSize, viewportTexture, viewportTopLeft, viewportUV, wgsl, wgslFn, workgroupArray, workgroupBarrier, workgroupId, workingToColorSpace, xor }; diff --git a/build/three.webgpu.nodes.min.js b/build/three.webgpu.nodes.min.js index 7d337c4ec3ed50..d40803afdd7c2d 100644 --- a/build/three.webgpu.nodes.min.js +++ b/build/three.webgpu.nodes.min.js @@ -3,4 +3,4 @@ * Copyright 2010-2024 Three.js Authors * SPDX-License-Identifier: MIT */ -import{Color as e,Vector2 as t,Vector3 as s,Vector4 as r,Matrix3 as n,Matrix4 as i,EventDispatcher as o,MathUtils as a,ColorManagement as u,SRGBTransfer as l,NoToneMapping as d,StaticDrawUsage as c,InterleavedBuffer as h,DynamicDrawUsage as p,InterleavedBufferAttribute as g,NoColorSpace as m,UnsignedIntType as f,IntType as y,WebGLCoordinateSystem as b,BackSide as x,CubeReflectionMapping as T,CubeRefractionMapping as _,WebGPUCoordinateSystem as N,TangentSpaceNormalMap as v,ObjectSpaceNormalMap as S,InstancedInterleavedBuffer as A,InstancedBufferAttribute as R,DataArrayTexture as C,FloatType as E,FramebufferTexture as w,LinearMipmapLinearFilter as M,DepthTexture as B,Material as U,NormalBlending as F,PointsMaterial as P,LineBasicMaterial as I,LineDashedMaterial as L,MeshNormalMaterial as D,WebGLCubeRenderTarget as V,BoxGeometry as O,NoBlending as G,Mesh as k,Scene as z,LinearFilter as $,CubeCamera as H,CubeTexture as W,EquirectangularReflectionMapping as j,EquirectangularRefractionMapping as q,AddOperation as K,MixOperation as X,MultiplyOperation as Y,MeshBasicMaterial as Q,MeshLambertMaterial as Z,MeshPhongMaterial as J,Texture as ee,MeshStandardMaterial as te,MeshPhysicalMaterial as se,MeshToonMaterial as re,MeshMatcapMaterial as ne,SpriteMaterial as ie,ShadowMaterial as oe,Uint32BufferAttribute as ae,Uint16BufferAttribute as ue,DoubleSide as le,DepthStencilFormat as de,DepthFormat as ce,UnsignedInt248Type as he,UnsignedByteType as pe,RenderTarget as ge,Plane as me,Object3D as fe,HalfFloatType as ye,LinearMipMapLinearFilter as be,OrthographicCamera as xe,BufferGeometry as Te,Float32BufferAttribute as _e,UVMapping as Ne,Euler as ve,LinearSRGBColorSpace as Se,LessCompare as Ae,VSMShadowMap as Re,RGFormat as Ce,SphereGeometry as Ee,BufferAttribute as we,CubeUVReflectionMapping as Me,PerspectiveCamera as Be,RGBAFormat as Ue,LinearMipmapNearestFilter as Fe,NearestMipmapLinearFilter as Pe,Float16BufferAttribute as Ie,REVISION as Le,SRGBColorSpace as De,PCFShadowMap as Ve,FrontSide as Oe,Frustum as Ge,DataTexture as ke,RedIntegerFormat as ze,RedFormat as $e,RGIntegerFormat as He,RGBIntegerFormat as We,RGBFormat as je,RGBAIntegerFormat as qe,UnsignedShortType as Ke,ByteType as Xe,ShortType as Ye,createCanvasElement as Qe,AddEquation as Ze,SubtractEquation as Je,ReverseSubtractEquation as et,ZeroFactor as tt,OneFactor as st,SrcColorFactor as rt,SrcAlphaFactor as nt,SrcAlphaSaturateFactor as it,DstColorFactor as ot,DstAlphaFactor as at,OneMinusSrcColorFactor as ut,OneMinusSrcAlphaFactor as lt,OneMinusDstColorFactor as dt,OneMinusDstAlphaFactor as ct,CullFaceNone as ht,CullFaceBack as pt,CullFaceFront as gt,CustomBlending as mt,MultiplyBlending as ft,SubtractiveBlending as yt,AdditiveBlending as bt,NotEqualDepth as xt,GreaterDepth as Tt,GreaterEqualDepth as _t,EqualDepth as Nt,LessEqualDepth as vt,LessDepth as St,AlwaysDepth as At,NeverDepth as Rt,UnsignedShort4444Type as Ct,UnsignedShort5551Type as Et,UnsignedInt5999Type as wt,AlphaFormat as Mt,LuminanceFormat as Bt,LuminanceAlphaFormat as Ut,RGB_S3TC_DXT1_Format as Ft,RGBA_S3TC_DXT1_Format as Pt,RGBA_S3TC_DXT3_Format as It,RGBA_S3TC_DXT5_Format as Lt,RGB_PVRTC_4BPPV1_Format as Dt,RGB_PVRTC_2BPPV1_Format as Vt,RGBA_PVRTC_4BPPV1_Format as Ot,RGBA_PVRTC_2BPPV1_Format as Gt,RGB_ETC1_Format as kt,RGB_ETC2_Format as zt,RGBA_ETC2_EAC_Format as $t,RGBA_ASTC_4x4_Format as Ht,RGBA_ASTC_5x4_Format as Wt,RGBA_ASTC_5x5_Format as jt,RGBA_ASTC_6x5_Format as qt,RGBA_ASTC_6x6_Format as Kt,RGBA_ASTC_8x5_Format as Xt,RGBA_ASTC_8x6_Format as Yt,RGBA_ASTC_8x8_Format as Qt,RGBA_ASTC_10x5_Format as Zt,RGBA_ASTC_10x6_Format as Jt,RGBA_ASTC_10x8_Format as es,RGBA_ASTC_10x10_Format as ts,RGBA_ASTC_12x10_Format as ss,RGBA_ASTC_12x12_Format as rs,RGBA_BPTC_Format as ns,RED_RGTC1_Format as is,SIGNED_RED_RGTC1_Format as os,RED_GREEN_RGTC2_Format as as,SIGNED_RED_GREEN_RGTC2_Format as us,RepeatWrapping as ls,ClampToEdgeWrapping as ds,MirroredRepeatWrapping as cs,NearestFilter as hs,NearestMipmapNearestFilter as ps,NeverCompare as gs,AlwaysCompare as ms,LessEqualCompare as fs,EqualCompare as ys,GreaterEqualCompare as bs,GreaterCompare as xs,NotEqualCompare as Ts,warnOnce as _s,NotEqualStencilFunc as Ns,GreaterStencilFunc as vs,GreaterEqualStencilFunc as Ss,EqualStencilFunc as As,LessEqualStencilFunc as Rs,LessStencilFunc as Cs,AlwaysStencilFunc as Es,NeverStencilFunc as ws,DecrementWrapStencilOp as Ms,IncrementWrapStencilOp as Bs,DecrementStencilOp as Us,IncrementStencilOp as Fs,InvertStencilOp as Ps,ReplaceStencilOp as Is,ZeroStencilOp as Ls,KeepStencilOp as Ds,MaxEquation as Vs,MinEquation as Os,SpotLight as Gs,PointLight as ks,DirectionalLight as zs,RectAreaLight as $s,AmbientLight as Hs,HemisphereLight as Ws,LightProbe as js,LinearToneMapping as qs,ReinhardToneMapping as Ks,CineonToneMapping as Xs,ACESFilmicToneMapping as Ys,AgXToneMapping as Qs,NeutralToneMapping as Zs,Group as Js,Loader as er,FileLoader as tr,MaterialLoader as sr,ObjectLoader as rr}from"./three.core.min.js";export{AdditiveAnimationBlendMode,AnimationAction,AnimationClip,AnimationLoader,AnimationMixer,AnimationObjectGroup,AnimationUtils,ArcCurve,ArrayCamera,ArrowHelper,AttachedBindMode,Audio,AudioAnalyser,AudioContext,AudioListener,AudioLoader,AxesHelper,BasicDepthPacking,BasicShadowMap,BatchedMesh,Bone,BooleanKeyframeTrack,Box2,Box3,Box3Helper,BoxHelper,BufferGeometryLoader,Cache,Camera,CameraHelper,CanvasTexture,CapsuleGeometry,CatmullRomCurve3,CircleGeometry,Clock,ColorKeyframeTrack,CompressedArrayTexture,CompressedCubeTexture,CompressedTexture,CompressedTextureLoader,ConeGeometry,ConstantAlphaFactor,ConstantColorFactor,Controls,CubeTextureLoader,CubicBezierCurve,CubicBezierCurve3,CubicInterpolant,CullFaceFrontBack,Curve,CurvePath,CustomToneMapping,CylinderGeometry,Cylindrical,Data3DTexture,DataTextureLoader,DataUtils,DefaultLoadingManager,DetachedBindMode,DirectionalLightHelper,DiscreteInterpolant,DodecahedronGeometry,DynamicCopyUsage,DynamicReadUsage,EdgesGeometry,EllipseCurve,ExtrudeGeometry,Fog,FogExp2,GLBufferAttribute,GLSL1,GLSL3,GridHelper,HemisphereLightHelper,IcosahedronGeometry,ImageBitmapLoader,ImageLoader,ImageUtils,InstancedBufferGeometry,InstancedMesh,Int16BufferAttribute,Int32BufferAttribute,Int8BufferAttribute,Interpolant,InterpolateDiscrete,InterpolateLinear,InterpolateSmooth,KeyframeTrack,LOD,LatheGeometry,Layers,Light,Line,Line3,LineCurve,LineCurve3,LineLoop,LineSegments,LinearInterpolant,LinearMipMapNearestFilter,LinearTransfer,LoaderUtils,LoadingManager,LoopOnce,LoopPingPong,LoopRepeat,MOUSE,Matrix2,MeshDepthMaterial,MeshDistanceMaterial,NearestMipMapLinearFilter,NearestMipMapNearestFilter,NormalAnimationBlendMode,NumberKeyframeTrack,OctahedronGeometry,OneMinusConstantAlphaFactor,OneMinusConstantColorFactor,PCFSoftShadowMap,Path,PlaneGeometry,PlaneHelper,PointLightHelper,Points,PolarGridHelper,PolyhedronGeometry,PositionalAudio,PropertyBinding,PropertyMixer,QuadraticBezierCurve,QuadraticBezierCurve3,Quaternion,QuaternionKeyframeTrack,QuaternionLinearInterpolant,RGBADepthPacking,RGBDepthPacking,RGB_BPTC_SIGNED_Format,RGB_BPTC_UNSIGNED_Format,RGDepthPacking,RawShaderMaterial,Ray,Raycaster,RingGeometry,ShaderMaterial,Shape,ShapeGeometry,ShapePath,ShapeUtils,Skeleton,SkeletonHelper,SkinnedMesh,Source,Sphere,Spherical,SphericalHarmonics3,SplineCurve,SpotLightHelper,Sprite,StaticCopyUsage,StaticReadUsage,StereoCamera,StreamCopyUsage,StreamDrawUsage,StreamReadUsage,StringKeyframeTrack,TOUCH,TetrahedronGeometry,TextureLoader,TextureUtils,TorusGeometry,TorusKnotGeometry,Triangle,TriangleFanDrawMode,TriangleStripDrawMode,TrianglesDrawMode,TubeGeometry,Uint8BufferAttribute,Uint8ClampedBufferAttribute,Uniform,UniformsGroup,VectorKeyframeTrack,VideoTexture,WebGL3DRenderTarget,WebGLArrayRenderTarget,WebGLMultipleRenderTargets,WebGLRenderTarget,WireframeGeometry,WrapAroundEnding,ZeroCurvatureEnding,ZeroSlopeEnding}from"./three.core.min.js";const nr=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class ir{constructor(e){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(e),this.hasAnimation=!0===e.object.isSkinnedMesh,this.refreshUniforms=nr,this.renderId=0}firstInitialization(e){return!1===this.renderObjects.has(e)&&(this.getRenderObjectData(e),!0)}getRenderObjectData(e){let t=this.renderObjects.get(e);if(void 0===t){const{geometry:s,material:r}=e;if(t={material:this.getMaterialData(r),geometry:{attributes:this.getAttributesData(s.attributes),indexVersion:s.index?s.index.version:null,drawRange:{start:s.drawRange.start,count:s.drawRange.count}},worldMatrix:e.object.matrixWorld.clone()},e.object.center&&(t.center=e.object.center.clone()),e.object.morphTargetInfluences&&(t.morphTargetInfluences=e.object.morphTargetInfluences.slice()),null!==e.bundle&&(t.version=e.bundle.version),t.material.transmission>0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(t.matrixWorld))return n.worldMatrix.copy(t.matrixWorld),!1;const i=n.material;for(const e in i){const t=i[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return i[e]=r,!1}if(i.transmission>0){const{width:t,height:s}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==s)return n.bufferWidth=t,n.bufferHeight=s,!1}const o=n.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return n.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let s=0;s>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:n}of cr(e))s.push(s,or(r.slice(0,-4)),n.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;ee.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of cr(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let r=null;const n=e.getBuildStage();if("setup"===n){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===n)this.analyze(e);else if("generate"===n){if(1===this.generate.length){const s=this.getNodeType(e),n=e.getDataFromNode(this);r=n.snippet,void 0===r?(r=this.generate(e)||"",n.snippet=r):void 0!==n.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:n,childNode:i}of t)void 0!==n?(void 0===s[r]&&(s[r]=Number.isInteger(n)?[]:{}),s[r][n]=i.toJSON(e.meta).uuid):s[r]=i.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const n of e.inputNodes[s])r.push(t[n]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const n in e.inputNodes[s]){const i=e.inputNodes[s][n];r[n]=t[i]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let n=e.nodes[t];function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===n&&(n={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[n.uuid]=n),this.serialize(n),delete n.meta),r){const t=i(e.textures),s=i(e.images),r=i(e.nodes);t.length>0&&(n.textures=t),s.length>0&&(n.images=s),r.length>0&&(n.nodes=r)}return n}}class Rr extends Ar{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,r=this.getNodeType(e),n=s.build(e,r);return e.format(n,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const n=super.build(e,s),i=e.getVarFromNode(this,null,s),o=e.getPropertyName(i);return e.addLineFlowCode(`${o} = ${n}`,this),r.snippet=n,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,s)=>t+e.getTypeLength(s.getNodeType(e))),0))}generate(e,t){const s=this.getNodeType(e),r=this.nodes,n=e.getComponentType(s),i=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==n&&(s=e.format(s,r,n)),i.push(s)}const o=`${e.getType(s)}( ${i.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(vr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,r=e.getTypeLength(s.getNodeType(e));let n=null;if(r>1){let i=null;this.getVectorLength()>=r&&(i=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,i);n=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,i,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else n=s.build(e,t);return n}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:r}=this,n=this.getNodeType(e),i=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,i),a=t.build(e,n),u=e.getTypeLength(n),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(pn(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),hn(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>hn(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>hn(new Fr(hn(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),hn(new Br(e,t));if(!0===/^\d+$/.test(t))return hn(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=hn(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;rhn(null!==r?Object.assign(e,r):e);return null===t?(...t)=>n(new e(...gn(t))):null!==s?(s=hn(s),(...r)=>n(new e(t,...gn(r),s))):(...s)=>n(new e(t,...gn(s)))},qr=function(e,...t){return hn(new e(...gn(t)))};class Kr extends Ar{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let n=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let i=r.get(t);void 0===i&&(i=hn(e.buildFunctionNode(t)),r.set(t,i)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(i),n=hn(i.call(s))}else{const r=t.jsFunc,i=null!==s?r(s,e):r(e);n=hn(i)}return t.once&&(r.onceOutput=n),n}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return pn(e),hn(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],en=new Map;for(const e of Yr)en.set(e,new Ir(e));const tn=new Map;for(const e of Qr)tn.set(e,new Ir(e,"uint"));const sn=new Map([...tn].map((e=>new Ir(e.value,"int"))));for(const e of Zr)sn.set(e,new Ir(e,"int"));const rn=new Map([...sn].map((e=>new Ir(e.value))));for(const e of Jr)rn.set(e,new Ir(e));for(const e of Jr)rn.set(-e,new Ir(-e));const nn={bool:en,uint:tn,ints:sn,float:rn},on=new Map([...en,...rn]),an=(e,t)=>on.has(e)?on.get(e):!0===e.isNode?e:new Ir(e,t),un=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return hn(t.get(s[0]));if(1===s.length){const t=an(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?hn(t):hn(new Cr(t,e))}const r=s.map((e=>an(e)));return hn(new wr(r,e))}},ln=e=>"object"==typeof e&&null!==e?e.value:e,dn=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function cn(e,t){return new Proxy(new Xr(e,t),kr)}const hn=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?hn(an(e,t)):"shader"===s?yn(e):e}(e,t),pn=(e,t=null)=>new Hr(e,t),gn=(e,t=null)=>new Wr(e,t),mn=(...e)=>new jr(...e),fn=(...e)=>new qr(...e),yn=(e,t)=>{const s=new cn(e,t),r=(...e)=>{let t;return pn(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},bn=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),yn(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const xn=e=>{Lr=e},Tn=()=>Lr,_n=(...e)=>Lr.If(...e);function Nn(e){return Lr&&Lr.add(e),e}Vr("append",Nn);const vn=new un("color"),Sn=new un("float",nn.float),An=new un("int",nn.ints),Rn=new un("uint",nn.uint),Cn=new un("bool",nn.bool),En=new un("vec2"),wn=new un("ivec2"),Mn=new un("uvec2"),Bn=new un("bvec2"),Un=new un("vec3"),Fn=new un("ivec3"),Pn=new un("uvec3"),In=new un("bvec3"),Ln=new un("vec4"),Dn=new un("ivec4"),Vn=new un("uvec4"),On=new un("bvec4"),Gn=new un("mat2"),kn=new un("mat3"),zn=new un("mat4"),$n=(e="")=>hn(new Ir(e,"string")),Hn=e=>hn(new Ir(e,"ArrayBuffer"));Vr("toColor",vn),Vr("toFloat",Sn),Vr("toInt",An),Vr("toUint",Rn),Vr("toBool",Cn),Vr("toVec2",En),Vr("toIVec2",wn),Vr("toUVec2",Mn),Vr("toBVec2",Bn),Vr("toVec3",Un),Vr("toIVec3",Fn),Vr("toUVec3",Pn),Vr("toBVec3",In),Vr("toVec4",Ln),Vr("toIVec4",Dn),Vr("toUVec4",Vn),Vr("toBVec4",On),Vr("toMat2",Gn),Vr("toMat3",kn),Vr("toMat4",zn);const Wn=mn(Rr),jn=(e,t)=>hn(new Cr(hn(e),t)),qn=(e,t)=>hn(new Br(hn(e),t));Vr("element",Wn),Vr("convert",jn);class Kn extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Xn=e=>new Kn(e),Yn=(e,t=0)=>new Kn(e,!0,t),Qn=Yn("frame"),Zn=Yn("render"),Jn=Xn("object");class ei extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Jn}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let n=e.getNodeFromHash(r);void 0===n&&(e.setHashNode(this,r),n=this);const i=n.getInputType(e),o=e.getUniformFromNode(n,i,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const ti=(e,t)=>{const s=dn(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return hn(new ei(r,s))};class si extends Ar{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const ri=(e,t)=>hn(new si(e,t)),ni=(e,t)=>hn(new si(e,t,!0)),ii=fn(si,"vec4","DiffuseColor"),oi=fn(si,"vec3","EmissiveColor"),ai=fn(si,"float","Roughness"),ui=fn(si,"float","Metalness"),li=fn(si,"float","Clearcoat"),di=fn(si,"float","ClearcoatRoughness"),ci=fn(si,"vec3","Sheen"),hi=fn(si,"float","SheenRoughness"),pi=fn(si,"float","Iridescence"),gi=fn(si,"float","IridescenceIOR"),mi=fn(si,"float","IridescenceThickness"),fi=fn(si,"float","AlphaT"),yi=fn(si,"float","Anisotropy"),bi=fn(si,"vec3","AnisotropyT"),xi=fn(si,"vec3","AnisotropyB"),Ti=fn(si,"color","SpecularColor"),_i=fn(si,"float","SpecularF90"),Ni=fn(si,"float","Shininess"),vi=fn(si,"vec4","Output"),Si=fn(si,"float","dashSize"),Ai=fn(si,"float","gapSize"),Ri=fn(si,"float","pointWidth"),Ci=fn(si,"float","IOR"),Ei=fn(si,"float","Transmission"),wi=fn(si,"float","Thickness"),Mi=fn(si,"float","AttenuationDistance"),Bi=fn(si,"color","AttenuationColor"),Ui=fn(si,"float","Dispersion");class Fi extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,n=this.needsSplitAssign(e),i=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,i),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(n){const r=e.getVarFromNode(this,null,i),n=e.getPropertyName(r);e.addLineFlowCode(`${n} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t{const r=s.type;let n;return n="pointer"===r?"&"+t.build(e):t.build(e,r),n};if(Array.isArray(n))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?gn(t):pn(t[0]),hn(new Ii(hn(e),t)));Vr("call",Li);class Di extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let n=new Di(e,t,s);for(let t=0;t>"===s||"<<"===s)return e.getIntegerType(i);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(i),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===i&&e.isMatrix(o)?o:e.isMatrix(i)&&e.isVector(o)?e.getVectorFromMatrix(i):e.isVector(i)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(i)?o:i}generate(e,t){const s=this.op,r=this.aNode,n=this.bNode,i=this.getNodeType(e,t);let o=null,a=null;"void"!==i?(o=r.getNodeType(e),a=void 0!==n?n.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=i,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=i):o=a=i;const u=r.build(e,o),l=void 0!==n?n.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} < ${l} )`,i,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} <= ${l} )`,i,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} > ${l} )`,i,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} >= ${l} )`,i,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`( ${u} ${s} ${l} )`,i,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`${u} ${s} ${l}`,i,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vi=mn(Di,"+"),Oi=mn(Di,"-"),Gi=mn(Di,"*"),ki=mn(Di,"/"),zi=mn(Di,"%"),$i=mn(Di,"=="),Hi=mn(Di,"!="),Wi=mn(Di,"<"),ji=mn(Di,">"),qi=mn(Di,"<="),Ki=mn(Di,">="),Xi=mn(Di,"&&"),Yi=mn(Di,"||"),Qi=mn(Di,"!"),Zi=mn(Di,"^^"),Ji=mn(Di,"&"),eo=mn(Di,"~"),to=mn(Di,"|"),so=mn(Di,"^"),ro=mn(Di,"<<"),no=mn(Di,">>");Vr("add",Vi),Vr("sub",Oi),Vr("mul",Gi),Vr("div",ki),Vr("modInt",zi),Vr("equal",$i),Vr("notEqual",Hi),Vr("lessThan",Wi),Vr("greaterThan",ji),Vr("lessThanEqual",qi),Vr("greaterThanEqual",Ki),Vr("and",Xi),Vr("or",Yi),Vr("not",Qi),Vr("xor",Zi),Vr("bitAnd",Ji),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",no);const io=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zi(...e));Vr("remainder",io);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,n=e.isMatrix(t)?0:e.getTypeLength(t),i=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return n>i&&n>o?t:i>o?s:o>n?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),n=this.getInputType(e),i=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=i,r=o;e.isMatrix(s.getNodeType(e))?r=Ln(Un(r),0):s=Ln(Un(s),0);const n=Gi(s,r).xyz;return Ao(n).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+i.build(e,n)+" )",r,t);if(s===oo.ONE_MINUS)return Oi(1,i).build(e,t);if(s===oo.RECIPROCAL)return ki(1,i).build(e,t);if(s===oo.DIFFERENCE)return Fo(Oi(i,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(i.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(i.build(e,1===e.getTypeLength(i.getNodeType(e))?"float":n),o.build(e,n)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(i.build(e,n),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":n)):s===oo.REFRACT?l.push(i.build(e,n),o.build(e,n),a.build(e,"float")):s===oo.MIX?l.push(i.build(e,n),o.build(e,n),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":n)):(l.push(i.build(e,n)),null!==o&&l.push(o.build(e,n)),null!==a&&l.push(a.build(e,n))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=Sn(1e-6),uo=Sn(1e6),lo=Sn(Math.PI),co=Sn(2*Math.PI),ho=mn(oo,oo.ALL),po=mn(oo,oo.ANY),go=mn(oo,oo.EQUALS),mo=mn(oo,oo.RADIANS),fo=mn(oo,oo.DEGREES),yo=mn(oo,oo.EXP),bo=mn(oo,oo.EXP2),xo=mn(oo,oo.LOG),To=mn(oo,oo.LOG2),_o=mn(oo,oo.SQRT),No=mn(oo,oo.INVERSE_SQRT),vo=mn(oo,oo.FLOOR),So=mn(oo,oo.CEIL),Ao=mn(oo,oo.NORMALIZE),Ro=mn(oo,oo.FRACT),Co=mn(oo,oo.SIN),Eo=mn(oo,oo.COS),wo=mn(oo,oo.TAN),Mo=mn(oo,oo.ASIN),Bo=mn(oo,oo.ACOS),Uo=mn(oo,oo.ATAN),Fo=mn(oo,oo.ABS),Po=mn(oo,oo.SIGN),Io=mn(oo,oo.LENGTH),Lo=mn(oo,oo.NEGATE),Do=mn(oo,oo.ONE_MINUS),Vo=mn(oo,oo.DFDX),Oo=mn(oo,oo.DFDY),Go=mn(oo,oo.ROUND),ko=mn(oo,oo.RECIPROCAL),zo=mn(oo,oo.TRUNC),$o=mn(oo,oo.FWIDTH),Ho=mn(oo,oo.BITCAST),Wo=mn(oo,oo.TRANSPOSE),jo=mn(oo,oo.ATAN2),qo=mn(oo,oo.MIN),Ko=mn(oo,oo.MAX),Xo=mn(oo,oo.MOD),Yo=mn(oo,oo.STEP),Qo=mn(oo,oo.REFLECT),Zo=mn(oo,oo.DISTANCE),Jo=mn(oo,oo.DIFFERENCE),ea=mn(oo,oo.DOT),ta=mn(oo,oo.CROSS),sa=mn(oo,oo.POW),ra=mn(oo,oo.POW,2),na=mn(oo,oo.POW,3),ia=mn(oo,oo.POW,4),oa=mn(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gi(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=mn(oo,oo.MIX),da=(e,t=0,s=1)=>hn(new oo(oo.CLAMP,hn(e),hn(t),hn(s))),ca=e=>da(e),ha=mn(oo,oo.REFRACT),pa=mn(oo,oo.SMOOTHSTEP),ga=mn(oo,oo.FACEFORWARD),ma=yn((([e])=>{const t=ea(e.xy,En(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",na),Vr("pow4",ia),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,n=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=n,null!==r&&(e.getDataFromNode(r).parentNodeBlock=n);const i=e.getNodeProperties(this);i.condNode=t,i.ifNode=s.context({nodeBlock:s}),i.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:n,ifNode:i,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?ri(s).build(e):"";r.nodeProperty=u;const l=n.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=i.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=mn(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e,t);return e.setContext(s),r}}const Na=mn(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),n=e.getPropertyName(r),i=t.build(e,r.type);return e.addLineFlowCode(`${n} = ${i}`,this),n}}const Aa=mn(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const r=this.name,n=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,n),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const r=this.getNodeType(e),n=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,n),t.propertyName=n}return e.getPropertyName(s)}}const Ea=mn(Ca);Vr("varying",Ea);const wa=yn((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=yn((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let i=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(i=Ln(wa(i.rgb),i.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(i=Ln(kn(u._getMatrix(new n,s,r)).mul(i.rgb),i.a)),u.getTransfer(r)===l&&(i=Ln(Ma(i.rgb),i.a)),i):i}}const Pa=e=>hn(new Fa(hn(e),Ba,Ua)),Ia=e=>hn(new Fa(hn(e),Ua,Ba)),La=(e,t)=>hn(new Fa(hn(e),Ba,t)),Da=(e,t)=>hn(new Fa(hn(e),t,Ba)),Va=(e,t,s)=>hn(new Fa(hn(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return hn(new Oa(this,hn(e)))}setNodeType(e){const t=ti(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const n=e.renderer.library.getToneMappingFunction(s);return null!==n?r=Ln(n(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>hn(new $a(e,hn(t),hn(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),n=this.bufferStride||r,i=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,n),a=new g(o,r,i);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let n=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,n=r;else{n=Ea(this).build(e,t)}return n}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>hn(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;ehn(new Qa(hn(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const n=this.node.build(e,...t);return e.setCache(s),n}}const eu=(e,...t)=>hn(new Ja(hn(e),...t));Vr("cache",eu);class tu extends Ar{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const su=mn(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=Sn(0),n=Sn(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=n,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:n,doClamp:i}=this;let o=e.sub(t).div(s.sub(t));return!0===i&&(o=o.clamp()),o.mul(n.sub(r)).add(r)}}const nu=mn(ru,null,null,{doClamp:!1}),iu=mn(ru);Vr("remap",nu),Vr("remapClamp",iu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=mn(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>hn(new du(hn(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),n=e.getTypeFromAttribute(r),i=e.getAttribute(t,n);if("vertex"===e.shaderStage)return e.format(i.name,n,s);return Ea(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const gu=(e,t)=>hn(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=mn(fu);class bu extends ei{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=mn(bu);class Tu extends ei{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=ti(this.value.matrix)),this._matrixUniform.mul(Un(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&!0===s.flipY||!0===s.isRenderTargetTexture||!0===s.isFramebufferTexture||!0===s.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(An(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,n,i,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,i):n?e.generateTextureBias(u,t,s,n,i):a?e.generateTextureGrad(u,t,s,a,i):o?e.generateTextureCompare(u,t,s,o,i):!1===this.sampler?e.generateTextureLoad(u,t,s,i):e.generateTexture(u,t,s,i),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const n=super.generate(e,"property");if("sampler"===t)return n+"_sampler";if(e.isReference(t))return n;{const i=e.getDataFromNode(this);let o=i.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,n,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),i.snippet=b,i.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}blur(e){const t=this.clone();return t.biasNode=hn(e).mul(xu(t)),t.referenceNode=this.getSelf(),hn(t)}level(e){const t=this.clone();return t.levelNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}compare(e){const t=this.clone();return t.compareNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}grad(e,t){const s=this.clone();return s.gradNode=[hn(e),hn(t)],s.referenceNode=this.getSelf(),hn(s)}depth(e){const t=this.clone();return t.depthNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=mn(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=ti("float").label("cameraNear").setGroup(Zn).onRenderUpdate((({camera:e})=>e.near)),Au=ti("float").label("cameraFar").setGroup(Zn).onRenderUpdate((({camera:e})=>e.far)),Ru=ti("mat4").label("cameraProjectionMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=ti("mat4").label("cameraProjectionMatrixInverse").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=ti("mat4").label("cameraViewMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=ti("mat4").label("cameraWorldMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=ti("mat3").label("cameraNormalMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=ti(new s).label("cameraPosition").setGroup(Zn).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new ei(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,n=this.scope;if(n===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(n===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(n===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(n===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(n===Uu.VIEW_POSITION){const n=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(n.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=mn(Uu,Uu.DIRECTION),Pu=mn(Uu,Uu.WORLD_MATRIX),Iu=mn(Uu,Uu.POSITION),Lu=mn(Uu,Uu.SCALE),Du=mn(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=fn(Vu,Vu.DIRECTION),Gu=fn(Vu,Vu.WORLD_MATRIX),ku=fn(Vu,Vu.POSITION),zu=fn(Vu,Vu.SCALE),$u=fn(Vu,Vu.VIEW_POSITION),Hu=ti(new n).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=ti(new i).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=yn((e=>(e.context.isHighPrecisionModelViewMatrix=!0,ti("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=yn((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return ti("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=fn(sl),nl=Sn(rl).mul(2).sub(1),il=gu("normal","vec3"),ol=yn((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Un(0,1,0)):il),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=yn((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=yn((e=>e.context.setupNormal()),"vec3").once()().mul(nl).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=yn((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(nl).toVar("transformedClearcoatNormalView"),pl=yn((([e,t=Gu])=>{const s=kn(t),r=e.div(Un(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=yn((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=ti(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Un(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Un(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=mn(Tl);class Nl extends ei{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const vl=(e,t,s)=>hn(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;shn(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),hn(new Al(e,t)));class El extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return hn(new El(this,hn(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):ti(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new wl(e,t,s)),Bl=(e,t,s,r)=>hn(new wl(e,t,r,s));class Ul extends wl{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>hn(new Ul(e,t,s)),Pl=yn((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ln(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(il.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=kn(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xi.cross(tl);return e=e.cross(xi).normalize(),e=la(e,dl,yi.mul(ai.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=yn((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:n}=e,i=t.dFdx(),o=t.dFdy(),a=n.dFdx(),u=n.dFdy(),l=s,d=o.cross(l),c=l.cross(i),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=nl.mul(g.inverseSqrt());return Vi(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Un(r.xy.mul(s),r.z));let n=null;if(t===S)n=gl(r);else if(t===v){n=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return n}}const Jl=mn(Zl),ed=yn((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=Sn(s((e=>e)));return En(Sn(s((e=>e.add(e.dFdx())))).sub(r),Sn(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=yn((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,n=t.dFdx().normalize(),i=s,o=t.dFdy().normalize().cross(i),a=i.cross(n),u=n.dot(o).mul(nl),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=mn(sd),nd=new Map;class id extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=nd.get(e);return void 0===s&&(s=Fl(e,t),nd.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===id.COLOR){const e=void 0!==t.color?this.getColor(s):Un();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===id.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===id.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:Sn(1);else if(s===id.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===id.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===id.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===id.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===id.EMISSIVE){const e=this.getFloat("emissiveIntensity"),n=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?n.mul(this.getTexture(s)):n}else if(s===id.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===id.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===id.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===id.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===id.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Gn($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(En(1)).normalize().mul(e.b))}else r=$d;else if(s===id.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const n=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(n).mul(this.getTexture(s).g).add(n)}else r=e}else if(s===id.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===id.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===id.IOR)r=this.getFloat(s);else if(s===id.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===id.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}id.ALPHA_TEST="alphaTest",id.COLOR="color",id.OPACITY="opacity",id.SHININESS="shininess",id.SPECULAR="specular",id.SPECULAR_STRENGTH="specularStrength",id.SPECULAR_INTENSITY="specularIntensity",id.SPECULAR_COLOR="specularColor",id.REFLECTIVITY="reflectivity",id.ROUGHNESS="roughness",id.METALNESS="metalness",id.NORMAL="normal",id.CLEARCOAT="clearcoat",id.CLEARCOAT_ROUGHNESS="clearcoatRoughness",id.CLEARCOAT_NORMAL="clearcoatNormal",id.EMISSIVE="emissive",id.ROTATION="rotation",id.SHEEN="sheen",id.SHEEN_ROUGHNESS="sheenRoughness",id.ANISOTROPY="anisotropy",id.IRIDESCENCE="iridescence",id.IRIDESCENCE_IOR="iridescenceIOR",id.IRIDESCENCE_THICKNESS="iridescenceThickness",id.IOR="ior",id.TRANSMISSION="transmission",id.THICKNESS="thickness",id.ATTENUATION_DISTANCE="attenuationDistance",id.ATTENUATION_COLOR="attenuationColor",id.LINE_SCALE="scale",id.LINE_DASH_SIZE="dashSize",id.LINE_GAP_SIZE="gapSize",id.LINE_WIDTH="linewidth",id.LINE_DASH_OFFSET="dashOffset",id.POINT_WIDTH="pointWidth",id.DISPERSION="dispersion",id.LIGHT_MAP="light",id.AO_MAP="ao";const od=fn(id,id.ALPHA_TEST),ad=fn(id,id.COLOR),ud=fn(id,id.SHININESS),ld=fn(id,id.EMISSIVE),dd=fn(id,id.OPACITY),cd=fn(id,id.SPECULAR),hd=fn(id,id.SPECULAR_INTENSITY),pd=fn(id,id.SPECULAR_COLOR),gd=fn(id,id.SPECULAR_STRENGTH),md=fn(id,id.REFLECTIVITY),fd=fn(id,id.ROUGHNESS),yd=fn(id,id.METALNESS),bd=fn(id,id.NORMAL).context({getUV:null}),xd=fn(id,id.CLEARCOAT),Td=fn(id,id.CLEARCOAT_ROUGHNESS),_d=fn(id,id.CLEARCOAT_NORMAL).context({getUV:null}),Nd=fn(id,id.ROTATION),vd=fn(id,id.SHEEN),Sd=fn(id,id.SHEEN_ROUGHNESS),Ad=fn(id,id.ANISOTROPY),Rd=fn(id,id.IRIDESCENCE),Cd=fn(id,id.IRIDESCENCE_IOR),Ed=fn(id,id.IRIDESCENCE_THICKNESS),wd=fn(id,id.TRANSMISSION),Md=fn(id,id.THICKNESS),Bd=fn(id,id.IOR),Ud=fn(id,id.ATTENUATION_DISTANCE),Fd=fn(id,id.ATTENUATION_COLOR),Pd=fn(id,id.LINE_SCALE),Id=fn(id,id.LINE_DASH_SIZE),Ld=fn(id,id.LINE_GAP_SIZE),Dd=fn(id,id.LINE_WIDTH),Vd=fn(id,id.LINE_DASH_OFFSET),Od=fn(id,id.POINT_WIDTH),Gd=fn(id,id.DISPERSION),kd=fn(id,id.LIGHT_MAP),zd=fn(id,id.AO_MAP),$d=ti(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=mn(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,n;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)n=r;else{n=Ea(this).build(e,t)}return n}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=fn(jd,jd.VERTEX),Kd=fn(jd,jd.INSTANCE),Xd=fn(jd,jd.SUBGROUP),Yd=fn(jd,jd.INVOCATION_SUBGROUP),Qd=fn(jd,jd.INVOCATION_LOCAL),Zd=fn(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,n=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=zn(...n)}this.instanceMatrixNode=t}const n=r.instanceColor;if(n&&null===s){const e=new R(n.array,3),t=n.usage===p?Ya:Xa;this.bufferColor=e,s=Un(t(e,"vec3",3,0)),this.instanceColorNode=s}const i=t.mul(Yu).xyz;if(Yu.assign(i),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&ni("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=mn(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=yn((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=An(e).modInt(An(t)),r=An(e).div(An(t));return Nu(this.batchMesh._indirectTexture,wn(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(An(this.batchingIdNode)),r=this.batchMesh._matricesTexture,n=yu(Nu(r),0),i=Sn(s).mul(4).toInt().toVar(),o=i.modInt(n),a=i.div(An(n)),u=zn(Nu(r,wn(o,a)),Nu(r,wn(o.add(1),a)),Nu(r,wn(o.add(2),a)),Nu(r,wn(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=yn((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),n=s.div(t);return Nu(l,wn(r,n)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);ni("vec3","vBatchColor").assign(t)}const d=kn(u);Yu.assign(u.mul(Yu));const c=ol.div(Un(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=mn(tc),rc=new WeakMap;class nc extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,n;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),n=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=ti(e.bindMatrix,"mat4"),r=ti(e.bindMatrixInverse,"mat4"),n=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=n,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=n.mul(t),c=Vi(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return i.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vi(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=i.mul(d).mul(n),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const ic=e=>hn(new nc(e)),oc=e=>hn(new nc(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;eNumber(i)?">=":"<"));const d={start:n,end:i,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const n=r.build(e,"void"),i=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+n);for(let t=0,s=this.params.length-1;thn(new ac(gn(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=yn((({bufferMap:e,influence:t,stride:s,width:r,depth:n,offset:i})=>{const o=An(qd).mul(s).add(i),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,wn(u,a)).depth(n).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=ti(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,n=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,i=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==i?i.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,n=void 0!==e.morphAttributes.color,i=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==i?i.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===n&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=Sn(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,wn(An(e).add(1),An(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(0)})),!0===n&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=mn(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Un().toVar("directDiffuse"),directSpecular:Un().toVar("directSpecular"),indirectDiffuse:Un().toVar("indirectDiffuse"),indirectSpecular:Un().toVar("indirectSpecular")};return{radiance:Un().toVar("radiance"),irradiance:Un().toVar("irradiance"),iblIrradiance:Un().toVar("iblIrradiance"),ambientOcclusion:Sn(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Tc=mn(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?ti(Nc||(Nc=new t)):e===Sc.VIEWPORT?ti(vc||(vc=new r)):En(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=fn(Sc,Sc.UV),Rc=fn(Sc,Sc.SIZE),Cc=fn(Sc,Sc.COORDINATE),Ec=fn(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=yn((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=yn((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=yn((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=mn(Lc),Vc=mn(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=mn(Gc);class zc extends Ar{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Xc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.negate().div(t)),n=To(s.div(t));return r.div(n)},Kc=(e,t,s)=>{const r=e.mul(xo(s.div(t)));return Sn(Math.E).pow(r).mul(t).negate()},Xc=mn(zc,zc.DEPTH_BASE),Yc=fn(zc,zc.DEPTH),Qc=mn(zc,zc.LINEAR_DEPTH),Zc=Qc(kc());Yc.assign=e=>Xc(e);const Jc=mn(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class eh extends Ar{static get type(){return"ClippingNode"}constructor(e=eh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===eh.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===eh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return yn((()=>{const s=Sn().toVar("distanceToPlane"),r=Sn().toVar("distanceToGradient"),n=Sn(1).toVar("clipOpacity"),i=t.length;if(!this.hardwareClipping&&i>0){const e=Rl(t);uc(i,(({i:t})=>{const i=e.element(t);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),i=Sn(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const n=t.element(e);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s).oneMinus())})),n.mulAssign(i.oneMinus())}ii.a.mulAssign(n),ii.a.equal(0).discard()}))()}setupDefault(e,t){return yn((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Cn(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),yn((()=>{const r=Rl(e),n=Jc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();n.element(e).assign(s)}))}))()}}eh.ALPHA_TO_COVERAGE="alphaToCoverage",eh.DEFAULT="default",eh.HARDWARE="hardware";const th=yn((([e])=>Ro(Gi(1e4,Co(Gi(17,e.x).add(Gi(.1,e.y)))).mul(Vi(.1,Fo(Co(Gi(13,e.y).add(e.x)))))))),sh=yn((([e])=>th(En(th(e.xy),e.z)))),rh=yn((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=Sn(1).div(Sn(.05).mul(t)).toVar("pixScale"),r=En(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),n=En(sh(vo(r.x.mul(e.xyz))),sh(vo(r.y.mul(e.xyz)))).toVar("alpha"),i=Ro(To(s)).toVar("lerpFactor"),o=Vi(Gi(i.oneMinus(),n.x),Gi(i,n.y)).toVar("x"),a=qo(i,i.oneMinus()).toVar("a"),u=Un(o.mul(o).div(Gi(2,a).mul(Oi(1,a))),o.sub(Gi(.5,a)).div(Oi(1,a)),Oi(1,Oi(1,o).mul(Oi(1,o)).div(Gi(2,a).mul(Oi(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class nh extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new ir(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const n=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const i=this.setupLighting(e);null!==n&&e.stack.add(n);const o=Ln(i,ii.a).max(0);if(r=this.setupOutput(e,o),vi.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ln(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=hn(new eh(eh.ALPHA_TO_COVERAGE)):e.stack.add(hn(new eh))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(hn(new eh(eh.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(el.z,Su,Au):$c(el.z,Su,Au))}null!==r&&Yc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ln(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ln(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=ni("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=ni("vec3","vBatchColor").mul(s)}ii.assign(s);const r=this.opacityNode?Sn(this.opacityNode):dd;if(ii.a.assign(ii.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?Sn(this.alphaTestNode):od;ii.a.lessThanEqual(e).discard()}!0===this.alphaHash&&ii.a.lessThan(rh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&ii.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Un(0):ii.rgb}setupNormal(){return this.normalNode?Un(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:n}=this,i=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(i&&i.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(i,t,s,r)}else null!==s&&(o=Un(null!==r?la(o,s,r):s));return(n&&!0===n.isNode||t.emissive&&!0===t.emissive.isColor)&&(oi.assign(Un(n||ld)),o=o.add(oi)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ln(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:n}of r)s.inputNodes[t]=n.toJSON(e).uuid;function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=n(e.textures),r=n(e.images),i=n(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),i.length>0&&(s.nodes=i)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const ih=new P;class oh extends nh{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(ih),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=yn((()=>{const e=gu("instancePosition").xyz,t=Ln(ju.mul(Ln(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),n=Xu.xy.toVar();return n.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),n.assign(n.div(Ec.z)),n.y.assign(n.y.mul(s)),n.assign(n.mul(r.w)),r.addAssign(Ln(n,0,0)),r}))(),this.fragmentNode=yn((()=>{const r=Sn(1).toVar(),n=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=Sn(n.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),n).oneMinus())}else n.greaterThan(1).discard();let i;if(this.pointColorNode)i=this.pointColorNode;else if(s){i=gu("instanceColor").mul(ad)}else i=ad;return r.mulAssign(dd),Ln(i,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ah=new I;class uh extends nh{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(ah),this.setValues(e)}}const lh=new L;class dh extends nh{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(lh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?Sn(this.offsetNodeNode):Vd,t=this.dashScaleNode?Sn(this.dashScaleNode):Pd,s=this.dashSizeNode?Sn(this.dashSizeNode):Id,r=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(s),Ai.assign(r);const n=Ea(gu("lineDistance").mul(t));(e?n.add(e):n).mod(Si.add(Ai)).greaterThan(Si).discard()}}const ch=new L;class hh extends nh{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ch),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,n=this.worldUnits,i=yn((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ln(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=yn((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ln(ju.mul(Ln(e,1))).toVar("start"),o=Ln(ju.mul(Ln(t,1))).toVar("end");if(r){const e=this.dashScaleNode?Sn(this.dashScaleNode):Pd,t=this.offsetNode?Sn(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let n=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));n=n.add(t),ni("float","lineDistance").assign(n)}n&&(ni("vec3","worldStart").assign(s.xyz),ni("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);_n(u,(()=>{_n(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(i({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(i({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ln().toVar();if(n){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),n=e.cross(t).normalize(),i=e.cross(n),a=ni("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ln(Xu.x.lessThan(0).select(n.mul(u),n.mul(u).negate()),0)),r||(a.addAssign(Ln(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ln(i.mul(u),0)),_n(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ln(i.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Un().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=En(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),_n(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ln(e,0,0)))}return g}))();const o=yn((({p1:e,p2:t,p3:s,p4:r})=>{const n=e.sub(s),i=r.sub(s),o=t.sub(e),a=n.dot(i),u=i.dot(o),l=n.dot(o),d=i.dot(i),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return En(h,p)}));this.fragmentNode=yn((()=>{const i=mu();if(r){const e=this.dashSizeNode?Sn(this.dashSizeNode):Id,t=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(e),Ai.assign(t);const s=ni("float","lineDistance");i.y.lessThan(-1).or(i.y.greaterThan(1)).discard(),s.mod(Si.add(Ai)).greaterThan(Si).discard()}const a=Sn(1).toVar("alpha");if(n){const s=ni("vec3","worldStart"),n=ni("vec3","worldEnd"),i=ni("vec4","worldPos").xyz.normalize().mul(1e5),u=n.sub(s),l=o({p1:s,p2:n,p3:Un(0,0,0),p4:i}),d=s.add(u.mul(l.x)),c=i.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1)),s=e.mul(e).add(t.mul(t)),r=Sn(s.fwidth()).toVar("dlen");_n(i.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else _n(i.y.abs().greaterThan(1),(()=>{const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ln(u,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ph=e=>hn(e).mul(.5).add(.5),gh=e=>hn(e).mul(2).sub(1),mh=new D;class fh extends nh{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(mh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?Sn(this.opacityNode):dd;ii.assign(Ln(ph(dl),e))}}class yh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return En(t,s)}}const bh=mn(yh);class xh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n=new O(5,5,5),i=bh(Ju),o=new nh;o.colorNode=_u(t,i,0),o.side=x,o.blending=G;const a=new k(n,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const Th=new WeakMap;class _h extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(Th.has(e)){const t=Th.get(e);vh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new xh(s.height);r.fromEquirectangularTexture(t,e),vh(r.texture,e.mapping),this._cubeTexture=r.texture,Th.set(e,r.texture),e.addEventListener("dispose",Nh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Nh(e){const t=e.target;t.removeEventListener("dispose",Nh);const s=Th.get(t);void 0!==s&&(Th.delete(t),s.dispose())}function vh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const Sh=mn(_h);class Ah extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Sh(this.envNode)}}class Rh extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=Sn(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ch{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Eh extends Ch{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,n=e.reflectedLight,i=s.context.irradianceLightMap;n.indirectDiffuse.assign(Ln(0)),i?n.indirectDiffuse.addAssign(i):n.indirectDiffuse.addAssign(Ln(1,1,1,0)),n.indirectDiffuse.mulAssign(r),n.indirectDiffuse.mulAssign(ii.rgb)}finish(e,t,s){const r=s.material,n=e.outgoingLight,i=s.context.environment;if(i)switch(r.combine){case Y:n.rgb.assign(la(n.rgb,n.rgb.mul(i.rgb),gd.mul(md)));break;case X:n.rgb.assign(la(n.rgb,i.rgb,gd.mul(md)));break;case K:n.rgb.addAssign(i.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const wh=new Q;class Mh extends nh{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Rh(kd)),t}setupOutgoingLight(){return ii.rgb}setupLightingModel(){return new Eh}}const Bh=yn((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Uh=yn((e=>e.diffuseColor.mul(1/Math.PI))),Fh=yn((({dotNH:e})=>Ni.mul(Sn(.5)).add(1).mul(Sn(1/Math.PI)).mul(e.pow(Ni)))),Ph=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),n=Bh({f0:Ti,f90:1,dotVH:r}),i=Sn(.25),o=Fh({dotNH:s});return n.mul(i).mul(o)}));class Ih extends Eh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Ph({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const Lh=new Z;class Dh extends nh{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih(!1)}}const Vh=new J;class Oh extends nh{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Vh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih}setupVariants(){const e=(this.shininessNode?Sn(this.shininessNode):ud).max(1e-4);Ni.assign(e);const t=this.specularNode||cd;Ti.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Gh=yn((e=>{if(!1===e.geometry.hasAttribute("normal"))return Sn(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),kh=yn((e=>{const{roughness:t}=e,s=Gh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),zh=yn((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),n=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),i=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return ki(.5,n.add(i).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),$h=yn((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:n,dotBL:i,dotNV:o,dotNL:a})=>{const u=a.mul(Un(e.mul(s),t.mul(r),o).length()),l=o.mul(Un(e.mul(n),t.mul(i),a).length());return ki(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hh=yn((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Wh=Sn(1/Math.PI),jh=yn((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:n})=>{const i=e.mul(t),o=Un(t.mul(r),e.mul(n),i.mul(s)),a=o.dot(o),u=i.div(a);return Wh.mul(i.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),qh=yn((e=>{const{lightDirection:t,f0:s,f90:r,roughness:n,f:i,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=n.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Bh({f0:s,f90:r,dotVH:g});if(ln(o)&&(y=pi.mix(y,i)),ln(a)){const e=bi.dot(t),s=bi.dot(tl),r=bi.dot(d),n=xi.dot(t),i=xi.dot(tl),o=xi.dot(d);m=$h({alphaT:fi,alphaB:l,dotTV:s,dotBV:i,dotTL:e,dotBL:n,dotNV:h,dotNL:c}),f=jh({alphaT:fi,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=zh({alpha:l,dotNL:c,dotNV:h}),f=Hh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),Kh=yn((({roughness:e,dotNV:t})=>{const s=Ln(-1,-.0275,-.572,.022),r=Ln(1,.0425,1.04,-.04),n=e.mul(s).add(r),i=n.x.mul(n.x).min(t.mul(-9.28).exp2()).mul(n.x).add(n.y);return En(-1.04,1.04).mul(i).add(n.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xh=yn((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:n}=e,i=Kh({dotNV:t,roughness:n});return s.mul(i.x).add(r.mul(i.y))})),Yh=yn((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),n=r.mul(r),i=r.mul(n,n).clamp(0,.9999);return e.sub(Un(t).mul(i)).div(i.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qh=yn((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=Sn(1).div(s),n=t.pow2().oneMinus().max(.0078125);return Sn(2).add(r).mul(n.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Zh=yn((({dotNV:e,dotNL:t})=>Sn(1).div(Sn(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Jh=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),n=dl.dot(t).clamp(),i=Qh({roughness:hi,dotNH:n}),o=Zh({dotNV:r,dotNL:s});return ci.mul(i).mul(o)})),ep=yn((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),n=En(s,r.oneMinus().sqrt());return n.assign(n.mul(.984375).add(.0078125)),n})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),tp=yn((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sp=yn((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),n=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),i=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=n.div(i),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),rp=yn((({N:e,V:t,P:s,mInv:r,p0:n,p1:i,p2:o,p3:a})=>{const u=i.sub(n).toVar(),l=a.sub(n).toVar(),d=u.cross(l),c=Un().toVar();return _n(d.dot(s.sub(n)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(kn(u,l,e).transpose()).toVar(),h=d.mul(n.sub(s)).normalize().toVar(),p=d.mul(i.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Un(0).toVar();f.addAssign(sp({v1:h,v2:p})),f.addAssign(sp({v1:p,v2:g})),f.addAssign(sp({v1:g,v2:m})),f.addAssign(sp({v1:m,v2:h})),c.assign(Un(tp({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),np=1/6,ip=e=>Gi(np,Gi(e,Gi(e,e.negate().add(3)).sub(3)).add(1)),op=e=>Gi(np,Gi(e,Gi(e,Gi(3,e).sub(6))).add(4)),ap=e=>Gi(np,Gi(e,Gi(e,Gi(-3,e).add(3)).add(3)).add(1)),up=e=>Gi(np,sa(e,3)),lp=e=>ip(e).add(op(e)),dp=e=>ap(e).add(up(e)),cp=e=>Vi(-1,op(e).div(ip(e).add(op(e)))),hp=e=>Vi(1,up(e).div(ap(e).add(up(e)))),pp=(e,t,s)=>{const r=e.uvNode,n=Gi(r,t.zw).add(.5),i=vo(n),o=Ro(n),a=lp(o.x),u=dp(o.x),l=cp(o.x),d=hp(o.x),c=cp(o.y),h=hp(o.y),p=En(i.x.add(l),i.y.add(c)).sub(.5).mul(t.xy),g=En(i.x.add(d),i.y.add(c)).sub(.5).mul(t.xy),m=En(i.x.add(l),i.y.add(h)).sub(.5).mul(t.xy),f=En(i.x.add(d),i.y.add(h)).sub(.5).mul(t.xy),y=lp(o.y).mul(Vi(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=dp(o.y).mul(Vi(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},gp=yn((([e,t=Sn(3)])=>{const s=En(e.size(An(t))),r=En(e.size(An(t.add(1)))),n=ki(1,s),i=ki(1,r),o=pp(e,Ln(n,s),vo(t)),a=pp(e,Ln(i,r),So(t));return Ro(t).mix(o,a)})),mp=yn((([e,t,s,r,n])=>{const i=Un(ha(t.negate(),Ao(e),ki(1,r))),o=Un(Io(n[0].xyz),Io(n[1].xyz),Io(n[2].xyz));return Ao(i).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),fp=yn((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),yp=Vc(),bp=Vc(),xp=yn((([e,t,s],{material:r})=>{const n=(r.side==x?yp:bp).uv(e),i=To(Rc.x).mul(fp(t,s));return gp(n,i)})),Tp=yn((([e,t,s])=>(_n(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Un(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),_p=yn((([e,t,s,r,n,i,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ln().toVar(),f=Un().toVar();const n=d.sub(1).mul(g.mul(.025)),i=Un(d.sub(n),d,d.add(n));uc({start:0,end:3},(({i:n})=>{const d=i.element(n),g=mp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ln(y,1))),x=En(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(En(x.x,x.y.oneMinus()));const T=xp(x,s,d);m.element(n).assign(T.element(n)),m.a.addAssign(T.a),f.element(n).assign(r.element(n).mul(Tp(Io(g),h,p).element(n)))})),m.a.divAssign(3)}else{const n=mp(e,t,c,d,a),i=o.add(n),g=l.mul(u.mul(Ln(i,1))),y=En(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(En(y.x,y.y.oneMinus())),m=xp(y,s,d),f=r.mul(Tp(Io(n),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Un(Xh({dotNV:b,specularColor:n,specularF90:i,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ln(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),Np=kn(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),vp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Sp=yn((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:n})=>{const i=la(e,t,pa(0,.03,r)),o=e.div(i).pow2().mul(s.pow2().oneMinus()).oneMinus();_n(o.lessThan(0),(()=>Un(1)));const a=o.sqrt(),u=vp(i,e),l=Bh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=i.lessThan(e).select(Math.PI,0),h=Sn(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Un(1).add(t).div(Un(1).sub(t))})(n.clamp(0,.9999)),g=vp(p,i.toVec3()),m=Bh({f0:g,f90:1,dotVH:a}),f=Un(p.x.lessThan(i).select(Math.PI,0),p.y.lessThan(i).select(Math.PI,0),p.z.lessThan(i).select(Math.PI,0)),y=i.mul(r,a,2),b=Un(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Un(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Un(54856e-17,44201e-17,52481e-17),n=Un(1681e3,1795300,2208400),i=Un(43278e5,93046e5,66121e5),o=Sn(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(i.mul(2*Math.PI).sqrt()).mul(n.mul(s).add(t).cos()).mul(s.pow2().negate().mul(i).exp());return a=Un(a.x.add(o),a.y,a.z).div(1.0685e-7),Np.mul(a)})(Sn(e).mul(y),Sn(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Un(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Ap=yn((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),n=s.pow2(),i=xa(s.lessThan(.25),Sn(-339.2).mul(n).add(Sn(161.4).mul(s)).sub(25.9),Sn(-8.48).mul(n).add(Sn(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),Sn(44).mul(n).sub(Sn(23.7).mul(s)).add(3.26),Sn(1.97).mul(n).sub(Sn(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,Sn(.1).mul(s).sub(.025)).add(i.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Rp=Un(.04),Cp=Sn(1);class Ep extends Ch{constructor(e=!1,t=!1,s=!1,r=!1,n=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=n,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Un().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Un().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Un().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Un().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Un().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=Sp({outsideIOR:Sn(1),eta2:gi,cosTheta1:e,thinFilmThickness:mi,baseF0:Ti}),this.iridescenceF0=Yh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=_p(r,s,ai,ii,Ti,_i,t,Gu,Eu,Ru,Ci,wi,Bi,Mi,this.dispersion?Ui:null),e.backdropAlpha=Ei,ii.a.mulAssign(la(1,e.backdrop.a,Ei))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),n=Kh({roughness:ai,dotNV:r}),i=(this.iridescenceF0?pi.mix(Ti,this.iridescenceF0):Ti).mul(n.x).add(s.mul(n.y)),o=n.x.add(n.y).oneMinus(),a=Ti.add(Ti.oneMinus().mul(.047619)),u=i.mul(a).div(o.mul(a).oneMinus());e.addAssign(i),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Jh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(qh({lightDirection:e,f0:Rp,f90:Cp,roughness:di,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),s.directSpecular.addAssign(r.mul(qh({lightDirection:e,f0:Ti,f90:1,roughness:ai,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:n,ltc_1:i,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=ep({N:c,V:h,roughness:ai}),m=i.uv(g).toVar(),f=o.uv(g).toVar(),y=kn(Un(m.x,0,m.y),Un(0,1,0),Un(m.z,0,m.w)).toVar(),b=Ti.mul(f.x).add(Ti.oneMinus().mul(f.y)).toVar();n.directSpecular.addAssign(e.mul(b).mul(rp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),n.directDiffuse.addAssign(e.mul(ii).mul(rp({N:c,V:h,P:p,mInv:kn(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Uh({diffuseColor:ii})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(ci,Ap({normal:dl,viewDir:tl,roughness:hi}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Xh({dotNV:e,specularColor:Rp,specularF90:Cp,roughness:di});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Un().toVar("singleScattering"),n=Un().toVar("multiScattering"),i=t.mul(1/Math.PI);this.computeMultiscattering(r,n,_i);const o=r.add(n),a=ii.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(n.mul(i)),s.indirectDiffuse.addAssign(a.mul(i))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=ai.mul(-16).oneMinus().negate().exp2(),n=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(n)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Bh({dotVH:e,f0:Rp,f90:Cp}),r=t.mul(li.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(li));t.assign(r)}if(!0===this.sheen){const e=ci.r.max(ci.g).max(ci.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const wp=Sn(1),Mp=Sn(-2),Bp=Sn(.8),Up=Sn(-1),Fp=Sn(.4),Pp=Sn(2),Ip=Sn(.305),Lp=Sn(3),Dp=Sn(.21),Vp=Sn(4),Op=Sn(4),Gp=Sn(16),kp=yn((([e])=>{const t=Un(Fo(e)).toVar(),s=Sn(-1).toVar();return _n(t.x.greaterThan(t.z),(()=>{_n(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{_n(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),zp=yn((([e,t])=>{const s=En().toVar();return _n(t.equal(0),(()=>{s.assign(En(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(En(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(En(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(En(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(En(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(En(e.x,e.y).div(Fo(e.z)))})),Gi(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$p=yn((([e])=>{const t=Sn(0).toVar();return _n(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).ElseIf(e.greaterThanEqual(Fp),(()=>{t.assign(Bp.sub(e).mul(Pp.sub(Up)).div(Bp.sub(Fp)).add(Up))})).ElseIf(e.greaterThanEqual(Ip),(()=>{t.assign(Fp.sub(e).mul(Lp.sub(Pp)).div(Fp.sub(Ip)).add(Pp))})).ElseIf(e.greaterThanEqual(Dp),(()=>{t.assign(Ip.sub(e).mul(Vp.sub(Lp)).div(Ip.sub(Dp)).add(Lp))})).Else((()=>{t.assign(Sn(-2).mul(To(Gi(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Hp=yn((([e,t])=>{const s=e.toVar();s.assign(Gi(2,s).sub(1));const r=Un(s,1).toVar();return _n(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Wp=yn((([e,t,s,r,n,i])=>{const o=Sn(s),a=Un(t),u=da($p(o),Mp,i),l=Ro(u),d=vo(u),c=Un(jp(e,a,d,r,n,i)).toVar();return _n(l.notEqual(0),(()=>{const t=Un(jp(e,a,d.add(1),r,n,i)).toVar();c.assign(la(c,t,l))})),c})),jp=yn((([e,t,s,r,n,i])=>{const o=Sn(s).toVar(),a=Un(t),u=Sn(kp(a)).toVar(),l=Sn(Ko(Op.sub(o),0)).toVar();o.assign(Ko(o,Op));const d=Sn(bo(o)).toVar(),c=En(zp(a,u).mul(d.sub(2)).add(1)).toVar();return _n(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gi(3,Gp))),c.y.addAssign(Gi(4,bo(i).sub(d))),c.x.mulAssign(r),c.y.mulAssign(n),e.uv(c).grad(En(),En())})),qp=yn((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:n,CUBEUV_TEXEL_WIDTH:i,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(n.cross(s).mul(Co(r))).add(n.mul(n.dot(s).mul(u.oneMinus())));return jp(e,l,t,i,o,a)})),Kp=yn((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:n,samples:i,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Un(xa(t,s,ta(s,r))).toVar();_n(ho(h.equals(Un(0))),(()=>{h.assign(Un(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Un().toVar();return p.addAssign(n.element(An(0)).mul(qp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:An(1),end:e},(({i:e})=>{_n(e.greaterThanEqual(i),(()=>{dc()}));const t=Sn(o.mul(Sn(e))).toVar();p.addAssign(n.element(e).mul(qp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(n.element(e).mul(qp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ln(p,1)}));let Xp=null;const Yp=new WeakMap;function Qp(e){let t=Yp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r0}(s))return null;t=Xp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Yp.set(e,t)}return t.texture}class Zp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=ti(0),this._height=ti(0),this._maxMip=ti(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Qp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Xp&&(Xp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Un(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Wp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Jp=mn(Zp),eg=new WeakMap;class tg extends yc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let r=eg.get(e);void 0===r&&(r=Jp(e),eg.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),n=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,i=s.context(sg(ai,n)).mul(r),o=s.context(rg(cl)).mul(Math.PI).mul(r),a=eu(i),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(sg(di,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const sg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},rg=e=>({getUV:()=>e,getTextureLevel:()=>Sn(1)}),ng=new te;class ig extends nh{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ng),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new tg(t):null}setupLightingModel(){return new Ep}setupSpecular(){const e=la(Un(.04),ii.rgb,ui);Ti.assign(e),_i.assign(1)}setupVariants(){const e=this.metalnessNode?Sn(this.metalnessNode):yd;ui.assign(e);let t=this.roughnessNode?Sn(this.roughnessNode):fd;t=kh({roughness:t}),ai.assign(t),this.setupSpecular(),ii.assign(Ln(ii.rgb.mul(e.oneMinus()),ii.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const og=new se;class ag extends ig{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(og),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?Sn(this.iorNode):Bd;Ci.assign(e),Ti.assign(la(qo(ra(Ci.sub(1).div(Ci.add(1))).mul(pd),Un(1)).mul(hd),ii.rgb,ui)),_i.assign(la(hd,1,ui))}setupLightingModel(){return new Ep(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?Sn(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?Sn(this.clearcoatRoughnessNode):Td;li.assign(e),di.assign(kh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Un(this.sheenNode):vd,t=this.sheenRoughnessNode?Sn(this.sheenRoughnessNode):Sd;ci.assign(e),hi.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?Sn(this.iridescenceNode):Rd,t=this.iridescenceIORNode?Sn(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?Sn(this.iridescenceThicknessNode):Ed;pi.assign(e),gi.assign(t),mi.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?En(this.anisotropyNode):Ad).toVar();yi.assign(e.length()),_n(yi.equal(0),(()=>{e.assign(En(1,0))})).Else((()=>{e.divAssign(En(yi)),yi.assign(yi.saturate())})),fi.assign(yi.pow2().mix(ai.pow2(),1)),bi.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xi.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?Sn(this.transmissionNode):wd,t=this.thicknessNode?Sn(this.thicknessNode):Md,s=this.attenuationDistanceNode?Sn(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Un(this.attenuationColorNode):Fd;if(Ei.assign(e),wi.assign(t),Mi.assign(s),Bi.assign(r),this.useDispersion){const e=this.dispersionNode?Sn(this.dispersionNode):Gd;Ui.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Un(this.clearcoatNormalNode):_d}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class ug extends Ep{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){if(!0===this.useSSS){const r=n.material,{thicknessColorNode:i,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=Sn(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Un(h.add(a).mul(i));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n)}}class lg extends ag{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=Sn(.1),this.thicknessAmbientNode=Sn(0),this.thicknessAttenuationNode=Sn(.1),this.thicknessPowerNode=Sn(2),this.thicknessScaleNode=Sn(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ug(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const dg=yn((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),n=En(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>n});return Un(e.r)}{const e=n.fwidth().mul(.5);return la(Un(.7),Un(1),pa(Sn(.7).sub(e.x),Sn(.7).add(e.x),n.x))}}));class cg extends Ch{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){const i=dg({normal:il,lightDirection:e,builder:n}).mul(t);s.directDiffuse.addAssign(i.mul(Uh({diffuseColor:ii.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const hg=new re;class pg extends nh{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(hg),this.setValues(e)}setupLightingModel(){return new cg}}class gg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Un(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return En(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const mg=fn(gg),fg=new ne;class yg extends nh{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(fg),this.setValues(e)}setupVariants(e){const t=mg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Un(la(.2,.8,t.y)),ii.rgb.mulAssign(s.rgb)}}const bg=new P;class xg extends nh{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(bg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Tg extends Er{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Gn(e,r,r.negate(),e).mul(s)}{const e=t,r=zn(Ln(1,0,0,0),Ln(0,Eo(e.x),Co(e.x).negate(),0),Ln(0,Co(e.x),Eo(e.x),0),Ln(0,0,0,1)),n=zn(Ln(Eo(e.y),0,Co(e.y),0),Ln(0,1,0,0),Ln(Co(e.y).negate(),0,Eo(e.y),0),Ln(0,0,0,1)),i=zn(Ln(Eo(e.z),Co(e.z).negate(),0,0),Ln(Co(e.z),Eo(e.z),0,0),Ln(0,0,1,0),Ln(0,0,0,1));return r.mul(n).mul(i).mul(Ln(s,1)).xyz}}}const _g=mn(Tg),Ng=new ie;class vg extends nh{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Ng),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:n,rotationNode:i,scaleNode:o}=this,a=Yu;let u=ju.mul(Un(n||0)),l=En(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=Sn(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>hn(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=Sn(i||Nd),h=_g(d,c);u=Ln(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Sg extends Ch{constructor(){super(),this.shadowNode=Sn(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){ii.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(ii.rgb)}}const Ag=new oe;class Rg extends nh{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ag),this.setValues(e)}setupLightingModel(){return new Sg}}const Cg=yn((({texture:e,uv:t})=>{const s=1e-4,r=Un().toVar();return _n(t.x.lessThan(s),(()=>{r.assign(Un(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Un(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Un(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Un(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Un(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Un(0,0,-1))})).Else((()=>{const s=.01,n=e.uv(t.add(Un(-.01,0,0))).r.sub(e.uv(t.add(Un(s,0,0))).r),i=e.uv(t.add(Un(0,-.01,0))).r.sub(e.uv(t.add(Un(0,s,0))).r),o=e.uv(t.add(Un(0,0,-.01))).r.sub(e.uv(t.add(Un(0,0,s))).r);r.assign(Un(n,i,o))})),r.normalize()}));class Eg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Un(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Cg({texture:this,uv:e})}}const wg=mn(Eg);class Mg extends nh{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=wg(this.map,null,0),s=yn((({orig:e,dir:t})=>{const s=Un(-.5),r=Un(.5),n=t.reciprocal(),i=s.sub(e).mul(n),o=r.sub(e).mul(n),a=qo(i,o),u=Ko(i,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return En(l,d)}));this.fragmentNode=yn((()=>{const e=Ea(Un(Wu.mul(Ln(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),n=En(s({orig:e,dir:r})).toVar();n.x.greaterThan(n.y).discard(),n.assign(En(Ko(n.x,0),n.y));const i=Un(e.add(n.x.mul(r))).toVar(),o=Un(r.abs().reciprocal()).toVar(),a=Sn(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ln(Fl("base","color"),0).toVar();return uc({type:"float",start:n.x,end:n.y,update:"+= delta"},(()=>{const e=ri("float","d").assign(t.uv(i.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:i,finalColor:u}).append():(u.a.assign(1),dc()),i.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ln(u)}))(),super.setup(e)}}class Bg{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ug{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const n of e){const e=n.node&&n.node.attribute?n.node.attribute:t.getAttribute(n.name);if(void 0===e)continue;s.push(e);const i=e.isInterleavedBufferAttribute?e.data:e;r.add(i)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:n}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(i.instanceCount=u,!0===e.isBatchedMesh)return i;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=n.start*l,c=(n.start+n.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(i.vertexCount=g,i.firstVertex=d,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let n;if(null!==r){const e=typeof r;"number"===e?n=0!==r?"1":"0":"object"===e?(n="{",r.isTexture&&(n+=r.mapping),n+="}"):n=String(r)}else n=String(r);s+=n+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Ig=[];class Lg{constructor(e,t,s,r,n,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=n,this.info=i,this.chainMaps={}}get(e,t,s,r,n,i,o,a){const u=this.getChainMap(a);Ig[0]=e,Ig[1]=t,Ig[2]=i,Ig[3]=n;let l=u.get(Ig);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,n,i,o,a),u.set(Ig,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,n,i,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ug)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,n,i,o,a,u,l,d){const c=this.getChainMap(d),h=new Pg(e,t,s,r,n,i,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Dg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Vg=1,Og=2,Gg=3,kg=4,zg=16;class $g extends Dg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Vg?this.backend.createAttribute(e):t===Og?this.backend.createIndexAttribute(e):t===Gg?this.backend.createStorageAttribute(e):t===kg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return n.version=Hg(e),n}class jg extends Dg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,n=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of n)this.attributes.delete(e);const i=this.wireframes.get(t);void 0!==i&&this.attributes.delete(i),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Gg):this.updateAttribute(e,Vg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Og);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,kg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Wg(t),e.set(t,s)):s.version!==Hg(t)&&(this.attributes.delete(s),s=Wg(t),e.set(t,s)),r=s}return r}}class qg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Kg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Xg extends Kg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Yg extends Kg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Qg=0;class Zg{constructor(e,t,s=null,r=null){this.id=Qg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Jg extends Dg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let o=this.programs.compute.get(i.computeShader);void 0===o&&(n&&0===n.computeProgram.usedTimes&&this._releaseProgram(n.computeProgram),o=new Zg(i.computeShader,"compute",i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(n&&0===n.usedTimes&&this._releasePipeline(n),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState();let o=this.programs.vertex.get(i.vertexShader);void 0===o&&(n&&0===n.vertexProgram.usedTimes&&this._releaseProgram(n.vertexProgram),o=new Zg(i.vertexShader,"vertex"),this.programs.vertex.set(i.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(i.fragmentShader);void 0===a&&(n&&0===n.fragmentProgram.usedTimes&&this._releaseProgram(n.fragmentProgram),a=new Zg(i.fragmentShader,"fragment"),this.programs.fragment.set(i.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(n&&0===n.usedTimes&&this._releasePipeline(n),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return void 0===n&&(n=new Yg(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,r)),n}_getRenderPipeline(e,t,s,r,n){r=r||this._getRenderCacheKey(e,t,s);let i=this.caches.get(r);return void 0===i&&(i=new Xg(r,t,s),this.caches.set(r,i),e.pipeline=i,this.backend.createRenderPipeline(e,n)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class em extends Dg{constructor(e,t,s,r,n,i){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=r,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,s=e.isIndirectStorageBufferAttribute?kg:Gg;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1,n=!0,i=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(r=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=s.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?n=!1:(i=10*i+u.id,o+=u.version),!0===s.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,r),this.textures.updateTexture(u),r=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t,n?i:0,o)}}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function sm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function rm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class nm{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,n,i,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:n,group:i,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=n,a.group=i,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||tm),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||sm),this.transparent.length>1&&this.transparent.sort(t||sm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||n[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,n[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=i,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&n.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=dm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class hm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class pm extends si{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const gm=(e,t)=>hn(new pm(e,t));class mm extends Ar{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new cn(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new cn(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new cn(e),this}build(e,...t){const s=Tn();xn(this);for(const t of this.nodes)t.build(e,"void");return xn(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const fm=mn(mm);class ym extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}const bm=e=>Object.entries(e).map((([e,t])=>"string"==typeof t?{name:e,type:t,isAtomic:!1}:{name:e,type:t.type,isAtomic:t.atomic||!1}));class xm extends Ar{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let r=0;r{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),Am=(e,t)=>sa(Gi(4,e.mul(Oi(1,e))),t),Rm=(e,t)=>e.lessThan(.5)?Am(e.mul(2),t).div(2):Oi(1,Am(Gi(Oi(1,e),2),t).div(2)),Cm=(e,t,s)=>sa(ki(sa(e,t),Vi(sa(e,t),sa(Oi(1,e),s))),1/t),Em=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),wm=yn((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),Mm=yn((([e])=>Un(wm(e.z.add(wm(e.y.mul(1)))),wm(e.z.add(wm(e.x.mul(1)))),wm(e.y.add(wm(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Bm=yn((([e,t,s])=>{const r=Un(e).toVar(),n=Sn(1.4).toVar(),i=Sn(0).toVar(),o=Un(r).toVar();return uc({start:Sn(0),end:Sn(3),type:"float",condition:"<="},(()=>{const e=Un(Mm(o.mul(2))).toVar();r.addAssign(e.add(s.mul(Sn(.1).mul(t)))),o.mulAssign(1.8),n.mulAssign(1.5),r.mulAssign(1.2);const a=Sn(wm(r.z.add(wm(r.x.add(wm(r.y)))))).toVar();i.addAssign(a.div(n)),o.addAssign(.14)})),i})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Um extends Ar{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let r=null,n=-1;for(const s of this.functionNodes){const i=s.shaderNode.layout;if(null===i)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=i.inputs;if(t.length===o.length){let i=0;for(let s=0;sn&&(r=s,n=i)}}this._candidateFnCall=s=r(...t)}return s}}const Fm=mn(Um),Pm=e=>(...t)=>Fm(e,...t),Im=ti(0).setGroup(Zn).onRenderUpdate((e=>e.time)),Lm=ti(0).setGroup(Zn).onRenderUpdate((e=>e.deltaTime)),Dm=ti(0,"uint").setGroup(Zn).onRenderUpdate((e=>e.frameId)),Vm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Im.mul(e)),Om=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Im.mul(e)),Gm=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Lm.mul(e)),km=(e=Im)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),zm=(e=Im)=>e.fract().round(),$m=(e=Im)=>e.add(.5).fract().mul(2).sub(1).abs(),Hm=(e=Im)=>e.fract(),Wm=yn((([e,t,s=En(.5)])=>_g(e.sub(s),t).add(s))),jm=yn((([e,t,s=En(.5)])=>{const r=e.sub(s),n=r.dot(r),i=n.mul(n).mul(t);return e.add(r.mul(i))})),qm=yn((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const n=Eu.mul(r);return ln(t)&&(n[0][0]=Gu[0].length(),n[0][1]=0,n[0][2]=0),ln(s)&&(n[1][0]=0,n[1][1]=Gu[1].length(),n[1][2]=0),n[2][0]=0,n[2][1]=0,n[2][2]=1,Ru.mul(n).mul(Yu)})),Km=yn((([e=null])=>{const t=Qc();return Qc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class Xm extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=Sn(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:n}=s,i=e.mod(r.mul(n)).floor(),o=i.mod(r),a=n.sub(i.add(1).div(r).ceil()),u=s.reciprocal(),l=En(o,a);return t.add(l).mul(u)}}const Ym=mn(Xm);class Qm extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=Sn(1),n=Yu,i=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=n,this.normalNode=i}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:n,normalNode:i}=this;let o=i.abs().normalize();o=o.div(o.dot(Un(1)));const a=n.yz.mul(r),u=n.zx.mul(r),l=n.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vi(p,g,m)}}const Zm=mn(Qm),Jm=(...e)=>Zm(...e),ef=new me,tf=new s,sf=new s,rf=new s,nf=new i,of=new s(0,0,-1),af=new r,uf=new s,lf=new s,df=new r,cf=new t,hf=new ge,pf=Ac.flipX();hf.depthTexture=new B(1,1);let gf=!1;class mf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||hf.texture,pf),this._reflectorBaseNode=e.reflector||new ff(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=hn(new mf({defaultTexture:hf.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class ff extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:n=!1,bounces:i=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=n,this.bounces=i,this.depth=o,this.updateBeforeType=i?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(cf),e.setSize(Math.round(cf.width*s),Math.round(cf.height*s))}setup(e){return this._updateResolution(hf,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&gf)return;gf=!0;const{scene:t,camera:s,renderer:r,material:n}=e,{target:i}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(cf),this._updateResolution(a,r),sf.setFromMatrixPosition(i.matrixWorld),rf.setFromMatrixPosition(s.matrixWorld),nf.extractRotation(i.matrixWorld),tf.set(0,0,1),tf.applyMatrix4(nf),uf.subVectors(sf,rf),uf.dot(tf)>0)return;uf.reflect(tf).negate(),uf.add(sf),nf.extractRotation(s.matrixWorld),of.set(0,0,-1),of.applyMatrix4(nf),of.add(rf),lf.subVectors(sf,of),lf.reflect(tf).negate(),lf.add(sf),o.coordinateSystem=s.coordinateSystem,o.position.copy(uf),o.up.set(0,1,0),o.up.applyMatrix4(nf),o.up.reflect(tf),o.lookAt(lf),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),ef.setFromNormalAndCoplanarPoint(tf,sf),ef.applyMatrix4(o.matrixWorldInverse),af.set(ef.normal.x,ef.normal.y,ef.normal.z,ef.constant);const u=o.projectionMatrix;df.x=(Math.sign(af.x)+u.elements[8])/u.elements[0],df.y=(Math.sign(af.y)+u.elements[9])/u.elements[5],df.z=-1,df.w=(1+u.elements[10])/u.elements[14],af.multiplyScalar(1/af.dot(df));u.elements[2]=af.x,u.elements[6]=af.y,u.elements[10]=r.coordinateSystem===N?af.z-0:af.z+1-0,u.elements[14]=af.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),n.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),n.visible=!0,gf=!1}}const yf=e=>hn(new mf(e)),bf=new xe(-1,1,1,-1,0,1);class xf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const Tf=new xf;class _f extends k{constructor(e=null){super(Tf,e),this.camera=bf,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,bf)}render(e){e.render(this,bf)}}const Nf=new t;class vf extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const n=new ge(t,s,r);super(n.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=n,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new _f(new nh),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(Nf);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const Sf=(e,...t)=>hn(new vf(hn(e),...t)),Af=(e,...t)=>e.isTextureNode?e:Sf(e,...t),Rf=yn((([e,t,s],r)=>{let n;r.renderer.coordinateSystem===N?(e=En(e.x,e.y.oneMinus()).mul(2).sub(1),n=Ln(Un(e,t),1)):n=Ln(Un(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const i=Ln(s.mul(n));return i.xyz.div(i.w)})),Cf=yn((([e,t])=>{const s=t.mul(Ln(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return En(r.x,r.y.oneMinus())})),Ef=yn((([e,t,s])=>{const r=yu(Nu(t)),n=wn(e.mul(r)).toVar(),i=Nu(t,n).toVar(),o=Nu(t,n.sub(wn(2,0))).toVar(),a=Nu(t,n.sub(wn(1,0))).toVar(),u=Nu(t,n.add(wn(1,0))).toVar(),l=Nu(t,n.add(wn(2,0))).toVar(),d=Nu(t,n.add(wn(0,2))).toVar(),c=Nu(t,n.add(wn(0,1))).toVar(),h=Nu(t,n.sub(wn(0,1))).toVar(),p=Nu(t,n.sub(wn(0,2))).toVar(),g=Fo(Oi(Sn(2).mul(a).sub(o),i)).toVar(),m=Fo(Oi(Sn(2).mul(u).sub(l),i)).toVar(),f=Fo(Oi(Sn(2).mul(c).sub(d),i)).toVar(),y=Fo(Oi(Sn(2).mul(h).sub(p),i)).toVar(),b=Rf(e,i,s).toVar(),x=g.lessThan(m).select(b.sub(Rf(e.sub(En(Sn(1).div(r.x),0)),a,s)),b.negate().add(Rf(e.add(En(Sn(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Rf(e.add(En(0,Sn(1).div(r.y))),c,s)),b.negate().add(Rf(e.sub(En(0,Sn(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class wf extends pu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const Mf=(...e)=>hn(new wf(...e));class Bf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Uf=fn(Bf),Ff=new ve,Pf=new i;class If extends Ar{static get type(){return"SceneNode"}constructor(e=If.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===If.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===If.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===If.BACKGROUND_ROTATION?r=ti("mat4").label("backgroundRotation").setGroup(Zn).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Ff.copy(s.backgroundRotation),Ff.x*=-1,Ff.y*=-1,Ff.z*=-1,Pf.makeRotationFromEuler(Ff)):Pf.identity(),Pf})):console.error("THREE.SceneNode: Unknown scope:",t),r}}If.BACKGROUND_BLURRINESS="backgroundBlurriness",If.BACKGROUND_INTENSITY="backgroundIntensity",If.BACKGROUND_ROTATION="backgroundRotation";const Lf=fn(If,If.BACKGROUND_BLURRINESS),Df=fn(If,If.BACKGROUND_INTENSITY),Vf=fn(If,If.BACKGROUND_ROTATION);class Of extends Rr{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Gf=mn(Of),kf="point-list",zf="line-list",$f="line-strip",Hf="triangle-list",Wf="triangle-strip",jf="never",qf="less",Kf="equal",Xf="less-equal",Yf="greater",Qf="not-equal",Zf="greater-equal",Jf="always",ey="store",ty="load",sy="clear",ry="ccw",ny="none",iy="front",oy="back",ay="uint16",uy="uint32",ly={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},dy="clamp-to-edge",cy="repeat",hy="mirror-repeat",py="linear",gy="nearest",my="zero",fy="one",yy="src",by="one-minus-src",xy="src-alpha",Ty="one-minus-src-alpha",_y="dst",Ny="one-minus-dst",vy="dst-alpha",Sy="one-minus-dst-alpha",Ay="src-alpha-saturated",Ry="constant",Cy="one-minus-constant",Ey="add",wy="subtract",My="reverse-subtract",By="min",Uy="max",Fy=0,Py=15,Iy="keep",Ly="zero",Dy="replace",Vy="invert",Oy="increment-clamp",Gy="decrement-clamp",ky="increment-wrap",zy="decrement-wrap",$y="storage",Hy="read-only-storage",Wy="write-only",jy="read-only",qy="float",Ky="unfilterable-float",Xy="depth",Yy="sint",Qy="uint",Zy="2d",Jy="3d",eb="2d",tb="2d-array",sb="cube",rb="3d",nb="all",ib="vertex",ob="instance",ab={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class ub extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=$y,this.isAtomic=!1,this.bufferObject=!1,this.bufferStruct=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Gf(this,e)}setBufferObject(e){return this.bufferObject=e,this}setBufferStruct(e){return this.bufferStruct=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess(Hy)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),r=s.build(e);return e.registerTransform(r,t),r}}const lb=(e,t,s)=>hn(new ub(e,t,s)),db=(e,t,s)=>hn(new ub(e,t,s).setBufferStruct(!0)),cb=(e,t,s)=>hn(new ub(e,t,s).setBufferObject(!0));class hb extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Wy}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(jy)}toWriteOnly(){return this.setAccess(Wy)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,n=super.generate(e,"property"),i=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,n,i,o);e.addLineFlowCode(a,this)}}const pb=mn(hb),gb=(e,t,s)=>{const r=pb(e,t,s);return null!==s&&r.append(),r};class mb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const fb=(e,t,s)=>hn(new mb(e,t,s)),yb=new WeakMap;class bb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=ti(new i),this.previousProjectionMatrix=ti(new i).setGroup(Zn),this.previousCameraViewMatrix=ti(new i)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=Tb(s);this.previousModelWorldMatrix.value.copy(r);const n=xb(t);n.frameId!==e&&(n.frameId=e,void 0===n.previousProjectionMatrix?(n.previousProjectionMatrix=new i,n.previousCameraViewMatrix=new i,n.currentProjectionMatrix=new i,n.currentCameraViewMatrix=new i,n.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(n.previousProjectionMatrix.copy(n.currentProjectionMatrix),n.previousCameraViewMatrix.copy(n.currentCameraViewMatrix)),n.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(n.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(n.previousCameraViewMatrix))}updateAfter({object:e}){Tb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:ti(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),n=s.xy.div(s.w),i=r.xy.div(r.w);return Oi(n,i)}}function xb(e){let t=yb.get(e);return void 0===t&&(t={},yb.set(e,t)),t}function Tb(e,t=0){const s=xb(e);let r=s[t];return void 0===r&&(s[t]=r=new i),r}const _b=fn(bb),Nb=yn((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=yn((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Sb=yn((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Ab=yn((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Rb=yn((([e,t])=>Ln(e.rgb.mul(t.a.oneMinus()).add(t.rgb.mul(t.a)),e.a))).setLayout({name:"blendNormal",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Cb=yn((([e])=>Bb(e.rgb))),Eb=yn((([e,t=Sn(1)])=>t.mix(Bb(e.rgb),e.rgb))),wb=yn((([e,t=Sn(1)])=>{const s=Vi(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),n=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,n)})),Mb=yn((([e,t=Sn(1)])=>{const s=Un(.57735,.57735,.57735),r=t.cos();return Un(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),Bb=(e,t=Un(u.getLuminanceCoefficients(new s)))=>ea(e,t),Ub=(e,t)=>la(Un(0),e,Bb(e).sub(t).max(0)),Fb=yn((([e,t=Un(1),r=Un(0),n=Un(1),i=Sn(1),o=Un(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Un(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(n).toVar();return _n(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),_n(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),_n(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(i))),Ln(l.rgb,e.a)}));class Pb extends Er{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Ib=mn(Pb);let Lb=null;class Db extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Lb&&(Lb=new w),super(e,t,Lb)}updateReference(){return this}}const Vb=mn(Db),Ob=new t;class Gb extends Tu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class kb extends Gb{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class zb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const n=new B;n.isRenderTargetTexture=!0,n.name="depth";const i=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});i.texture.name="output",i.depthTexture=n,this.renderTarget=i,this.updateBeforeType=br.FRAME,this._textures={output:i.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=ti(0),this._cameraFar=ti(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=hn(new kb(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=hn(new kb(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(n,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===zb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const n=t.getSize(Ob);this.setSize(n.width,n.height);const i=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(i),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}zb.COLOR="color",zb.DEPTH="depth";const $b=(e,t,s)=>hn(new zb(zb.COLOR,e,t,s)),Hb=(e,t)=>hn(new Gb(e,t)),Wb=(e,t)=>hn(new zb(zb.DEPTH,e,t));class jb extends zb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,n){super(zb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=n,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,n,i,o,a,u)=>{if((i.isMeshToonMaterial||i.isMeshToonNodeMaterial)&&!1===i.wireframe){const l=this._getOutlineMaterial(i);t.renderObject(e,s,r,n,l,o,a,u)}t.renderObject(e,s,r,n,i,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new nh;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=Sn(1),n=s.mul(Ln(Yu,1)),i=s.mul(Ln(Yu.add(t),1)),o=Ao(n.sub(i));return e.vertexNode=n.add(o.mul(this.thicknessNode).mul(n.w).mul(r)),e.colorNode=Ln(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const qb=(t,s,r=new e(0,0,0),n=.003,i=1)=>hn(new jb(t,s,hn(r),hn(n),hn(i))),Kb=yn((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=yn((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Yb=yn((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qb=yn((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Zb=yn((([e,t])=>{const s=kn(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=kn(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=Qb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Jb=kn(Un(1.6605,-.1246,-.0182),Un(-.5876,1.1329,-.1006),Un(-.0728,-.0083,1.1187)),ex=kn(Un(.6274,.0691,.0164),Un(.3293,.9195,.088),Un(.0433,.0113,.8956)),tx=yn((([e])=>{const t=Un(e).toVar(),s=Un(t.mul(t)).toVar(),r=Un(s.mul(s)).toVar();return Sn(15.5).mul(r.mul(s)).sub(Gi(40.14,r.mul(t))).add(Gi(31.96,r).sub(Gi(6.868,s.mul(t))).add(Gi(.4298,s).add(Gi(.1191,t).sub(.00232))))})),sx=yn((([e,t])=>{const s=Un(e).toVar(),r=kn(Un(.856627153315983,.137318972929847,.11189821299995),Un(.0951212405381588,.761241990602591,.0767994186031903),Un(.0482516061458583,.101439036467562,.811302368396859)),n=kn(Un(1.1271005818144368,-.1413297634984383,-.14132976349843826),Un(-.11060664309660323,1.157823702216272,-.11060664309660294),Un(-.016493938717834573,-.016493938717834257,1.2519364065950405)),i=Sn(-12.47393),o=Sn(4.026069);return s.mulAssign(t),s.assign(ex.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(i).div(o.sub(i))),s.assign(da(s,0,1)),s.assign(tx(s)),s.assign(n.mul(s)),s.assign(sa(Ko(Un(0),s),Un(2.2))),s.assign(Jb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),rx=yn((([e,t])=>{const s=Sn(.76),r=Sn(.15);e=e.mul(t);const n=qo(e.r,qo(e.g,e.b)),i=xa(n.lessThan(.08),n.sub(Gi(6.25,n.mul(n))),.04);e.subAssign(i);const o=Ko(e.r,Ko(e.g,e.b));_n(o.lessThan(s),(()=>e));const a=Oi(1,s),u=Oi(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=Oi(1,ki(1,r.mul(o.sub(u)).add(1)));return la(e,Un(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class nx extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const ix=mn(nx),ox=(e,t)=>ix(e,t,"js"),ax=(e,t)=>ix(e,t,"wgsl"),ux=(e,t)=>ix(e,t,"glsl");class lx extends nx{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,n=s.type,i=e.getCodeFromNode(this,n);""!==r&&(i.name=r);const o=e.getPropertyName(i),a=this.getNodeFunction(e).getCode(o);return i.code=a+"\n","property"===t?o:e.format(`${o}()`,n,t)}}const dx=(e,t=[],s="")=>{for(let e=0;er.call(...e);return n.functionNode=r,n},cx=(e,t)=>dx(e,t,"glsl"),hx=(e,t)=>dx(e,t,"wgsl");class px extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:Sn()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const gx=mn(px);class mx extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class fx{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const yx=new mx;class bx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new mx,this._output=gx(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=gx(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=gx(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new fx(this),t=yx.get("THREE"),s=yx.get("TSL"),r=this.getMethod(this.codeNode),n=[e,this._local,yx,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...n);const i=this._object.layout;if(i&&(!1===i.cache&&this._local.clear(),this._output.outputType=i.outputType||null,Array.isArray(i.elements)))for(const e of i.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:Sn()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const xx=mn(bx);class Tx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const _x=mn(Tx);class Nx extends Tx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const vx=mn(Nx);class Sx extends Tx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const Ax=mn(Sx);let Rx=null,Cx=null;class Ex extends Ar{static get type(){return"RangeNode"}constructor(e=Sn(),t=Sn()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const n=this.minNode.value,i=this.maxNode.value,o=e.getTypeLength(hr(n)),u=e.getTypeLength(hr(i));Rx=Rx||new r,Cx=Cx||new r,Rx.setScalar(0),Cx.setScalar(0),1===o?Rx.setScalar(n):n.isColor?Rx.set(n.r,n.g,n.b):Rx.set(n.x,n.y,n.z||0,n.w||0),1===u?Cx.setScalar(i):i.isColor?Cx.set(i.r,i.g,i.b):Cx.set(i.x,i.y,i.z||0,i.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;ehn(new Mx(e,t)),Ux=Bx("numWorkgroups","uvec3"),Fx=Bx("workgroupId","uvec3"),Px=Bx("localId","uvec3"),Ix=Bx("subgroupSize","uint");const Lx=mn(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Dx=()=>Lx("workgroup").append(),Vx=()=>Lx("storage").append(),Ox=()=>Lx("texture").append();class Gx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class kx extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return hn(new Gx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const zx=(e,t)=>hn(new kx("Workgroup",e,t));class $x extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),n=this.pointerNode,i=this.valueNode,o=[];o.push(`&${n.build(e,r)}`),o.push(i.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}$x.ATOMIC_LOAD="atomicLoad",$x.ATOMIC_STORE="atomicStore",$x.ATOMIC_ADD="atomicAdd",$x.ATOMIC_SUB="atomicSub",$x.ATOMIC_MAX="atomicMax",$x.ATOMIC_MIN="atomicMin",$x.ATOMIC_AND="atomicAnd",$x.ATOMIC_OR="atomicOr",$x.ATOMIC_XOR="atomicXor";const Hx=mn($x),Wx=(e,t,s,r)=>{const n=Hx(e,t,s,r);return n.append(),n},jx=(e,t,s=null)=>Wx($x.ATOMIC_STORE,e,t,s),qx=(e,t,s=null)=>Wx($x.ATOMIC_ADD,e,t,s),Kx=(e,t,s=null)=>Wx($x.ATOMIC_SUB,e,t,s),Xx=(e,t,s=null)=>Wx($x.ATOMIC_MAX,e,t,s),Yx=(e,t,s=null)=>Wx($x.ATOMIC_MIN,e,t,s),Qx=(e,t,s=null)=>Wx($x.ATOMIC_AND,e,t,s),Zx=(e,t,s=null)=>Wx($x.ATOMIC_OR,e,t,s),Jx=(e,t,s=null)=>Wx($x.ATOMIC_XOR,e,t,s);let eT;function tT(e){eT=eT||new WeakMap;let t=eT.get(e);return void 0===t&&eT.set(e,t={}),t}function sT(e){const t=tT(e);return t.position||(t.position=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function rT(e){const t=tT(e);return t.targetPosition||(t.targetPosition=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function nT(e){const t=tT(e);return t.viewPosition||(t.viewPosition=ti(new s).setGroup(Zn).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const iT=e=>Eu.transformDirection(sT(e).sub(rT(e))),oT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},aT=new WeakMap;class uT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Un().toVar("totalDiffuse"),this.totalSpecularNode=Un().toVar("totalSpecular"),this.outgoingLightNode=Un().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),n=e.renderer.library;for(const e of r)if(e.isNode)t.push(hn(e));else{let r=null;if(null!==s&&(r=oT(e.id,s)),null===r){const s=n.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;aT.has(e)?r=aT.get(e):(r=hn(new s(e)),aT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:n,totalDiffuseNode:i,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,n),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Un(null!==l?l.mix(g,u):u),t.material.transparent=!0),i.assign(g),o.assign(c.add(p)),r.assign(i.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const lT=(e=[])=>hn(new uT).setLights(e),dT=yn((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),cT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=Ml("radius","float",s).setGroup(Zn),o=En(1).div(n),a=o.x.negate().mul(i),u=o.y.negate().mul(i),l=o.x.mul(i),d=o.y.mul(i),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vi(r(t.xy.add(En(a,u)),t.z),r(t.xy.add(En(0,u)),t.z),r(t.xy.add(En(l,u)),t.z),r(t.xy.add(En(c,h)),t.z),r(t.xy.add(En(0,h)),t.z),r(t.xy.add(En(p,h)),t.z),r(t.xy.add(En(a,0)),t.z),r(t.xy.add(En(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(En(p,0)),t.z),r(t.xy.add(En(l,0)),t.z),r(t.xy.add(En(c,g)),t.z),r(t.xy.add(En(0,g)),t.z),r(t.xy.add(En(p,g)),t.z),r(t.xy.add(En(a,d)),t.z),r(t.xy.add(En(0,d)),t.z),r(t.xy.add(En(l,d)),t.z)).mul(1/17)})),hT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=En(1).div(n),o=i.x,a=i.y,u=t.xy,l=Ro(u.mul(n).add(.5));return u.subAssign(l.mul(i)),Vi(r(u,t.z),r(u.add(En(o,0)),t.z),r(u.add(En(0,a)),t.z),r(u.add(i),t.z),la(r(u.add(En(o.negate(),0)),t.z),r(u.add(En(o.mul(2),0)),t.z),l.x),la(r(u.add(En(o.negate(),a)),t.z),r(u.add(En(o.mul(2),a)),t.z),l.x),la(r(u.add(En(0,a.negate())),t.z),r(u.add(En(0,a.mul(2))),t.z),l.y),la(r(u.add(En(o,a.negate())),t.z),r(u.add(En(o,a.mul(2))),t.z),l.y),la(la(r(u.add(En(o.negate(),a.negate())),t.z),r(u.add(En(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(En(o.negate(),a.mul(2))),t.z),r(u.add(En(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),pT=yn((({depthTexture:e,shadowCoord:t})=>{const s=Sn(1).toVar(),r=_u(e).uv(t.xy).rg,n=Yo(t.z,r.x);return _n(n.notEqual(Sn(1)),(()=>{const e=t.z.sub(r.x),i=Ko(0,r.y.mul(r.y));let o=i.div(i.add(e.mul(e)));o=da(Oi(o,.3).div(.95-.3)),s.assign(da(Ko(n,o)))})),s})),gT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(0,u).mul(t)).div(s)).x;n.addAssign(l),i.addAssign(l.mul(l))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),mT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(u,0).mul(t)).div(s));n.addAssign(l.x),i.addAssign(Vi(l.y.mul(l.y),l.x.mul(l.x)))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),fT=[dT,cT,hT,pT];let yT=null;const bT=new _f;class xT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===yT&&(yT=new nh,yT.fragmentNode=Ln(0,0,0,1),yT.isShadowNodeMaterial=!0,yT.name="ShadowMaterial");const r=this.shadow,n=s.shadowMap.type,i=new B(r.mapSize.width,r.mapSize.height);i.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=i,r.camera.updateProjectionMatrix(),n===Re){i.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(i),s=_u(this.vsmShadowMapVertical.texture),n=Ml("blurSamples","float",r).setGroup(Zn),o=Ml("radius","float",r).setGroup(Zn),a=Ml("mapSize","vec2",r).setGroup(Zn);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new nh);u.fragmentNode=gT({samples:n,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new nh),u.fragmentNode=mT({samples:n,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Zn),u=Ml("bias","float",r).setGroup(Zn),l=Ml("normalBias","float",r).setGroup(Zn),d=t.material.shadowPositionNode||Zu;let c,h=ti(r.matrix).setGroup(Zn).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=Ml("near","float",r.camera).setGroup(Zn),s=Ml("far","float",r.camera).setGroup(Zn);c=qc(e.negate(),t,s)}h=Un(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||fT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:n===Re?this.vsmShadowMapHorizontal.texture:i,shadowCoord:h,shadow:r}),Sn(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:n,scene:i,camera:o}=e,a=n.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=i.overrideMaterial;i.overrideMaterial=yT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=n.getRenderTarget(),c=n.getRenderObjectFunction();n.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&n.renderObject(e,...t)})),n.setRenderTarget(t),n.render(i,r.camera),n.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(n),n.setRenderTarget(d),i.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),bT.material=this.vsmMaterialVertical,bT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),bT.material=this.vsmMaterialHorizontal,bT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const TT=(e,t)=>hn(new xT(e,t));class _T extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=ti(this.color).setGroup(Zn),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?hn(e):TT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const NT=yn((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,n=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(n.mul(t.div(s).pow4().oneMinus().clamp().pow2()),n)})),vT=yn((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},n)=>{const i=n.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=NT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=n.context.reflectedLight;i.direct({lightDirection:a,lightColor:d,reflectedLight:c},n.stack,n)}));class ST extends _T{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){vT({color:this.colorNode,lightViewPosition:nT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const AT=yn((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),RT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Cn(e).toVar();return xa(i,n,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),CT=yn((([e,t])=>{const s=Cn(t).toVar(),r=Sn(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),ET=yn((([e])=>{const t=Sn(e).toVar();return An(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),wT=yn((([e,t])=>{const s=Sn(e).toVar();return t.assign(ET(s)),s.sub(Sn(t))})),MT=Pm([yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Sn(r).toVar(),l=Sn(s).toVar(),d=Sn(t).toVar(),c=Sn(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Un(r).toVar(),l=Un(s).toVar(),d=Un(t).toVar(),c=Un(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),BT=Pm([yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Sn(a).toVar(),m=Sn(o).toVar(),f=Sn(i).toVar(),y=Sn(n).toVar(),b=Sn(r).toVar(),x=Sn(s).toVar(),T=Sn(t).toVar(),_=Sn(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Un(a).toVar(),m=Un(o).toVar(),f=Un(i).toVar(),y=Un(n).toVar(),b=Un(r).toVar(),x=Un(s).toVar(),T=Un(t).toVar(),_=Un(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),UT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Rn(e).toVar(),o=Rn(i.bitAnd(Rn(7))).toVar(),a=Sn(RT(o.lessThan(Rn(4)),n,r)).toVar(),u=Sn(Gi(2,RT(o.lessThan(Rn(4)),r,n))).toVar();return CT(a,Cn(o.bitAnd(Rn(1)))).add(CT(u,Cn(o.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),FT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Rn(e).toVar(),u=Rn(a.bitAnd(Rn(15))).toVar(),l=Sn(RT(u.lessThan(Rn(8)),o,i)).toVar(),d=Sn(RT(u.lessThan(Rn(4)),i,RT(u.equal(Rn(12)).or(u.equal(Rn(14))),o,n))).toVar();return CT(l,Cn(u.bitAnd(Rn(1)))).add(CT(d,Cn(u.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),PT=Pm([UT,FT]),IT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Pn(e).toVar();return Un(PT(i.x,n,r),PT(i.y,n,r),PT(i.z,n,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),LT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Pn(e).toVar();return Un(PT(a.x,o,i,n),PT(a.y,o,i,n),PT(a.z,o,i,n))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),DT=Pm([IT,LT]),VT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),OT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),GT=Pm([VT,yn((([e])=>{const t=Un(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),kT=Pm([OT,yn((([e])=>{const t=Un(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),zT=yn((([e,t])=>{const s=An(t).toVar(),r=Rn(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(An(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),$T=yn((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(zT(s,An(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(zT(e,An(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(zT(t,An(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(zT(s,An(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(zT(e,An(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(zT(t,An(4))),t.addAssign(e)})),HT=yn((([e,t,s])=>{const r=Rn(s).toVar(),n=Rn(t).toVar(),i=Rn(e).toVar();return r.bitXorAssign(n),r.subAssign(zT(n,An(14))),i.bitXorAssign(r),i.subAssign(zT(r,An(11))),n.bitXorAssign(i),n.subAssign(zT(i,An(25))),r.bitXorAssign(n),r.subAssign(zT(n,An(16))),i.bitXorAssign(r),i.subAssign(zT(r,An(4))),n.bitXorAssign(i),n.subAssign(zT(i,An(14))),r.bitXorAssign(n),r.subAssign(zT(n,An(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),WT=yn((([e])=>{const t=Rn(e).toVar();return Sn(t).div(Sn(Rn(An(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),jT=yn((([e])=>{const t=Sn(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),qT=Pm([yn((([e])=>{const t=An(e).toVar(),s=Rn(Rn(1)).toVar(),r=Rn(Rn(An(3735928559)).add(s.shiftLeft(Rn(2))).add(Rn(13))).toVar();return HT(r.add(Rn(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(Rn(2)).toVar(),i=Rn().toVar(),o=Rn().toVar(),a=Rn().toVar();return i.assign(o.assign(a.assign(Rn(An(3735928559)).add(n.shiftLeft(Rn(2))).add(Rn(13))))),i.addAssign(Rn(r)),o.addAssign(Rn(s)),HT(i,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(Rn(3)).toVar(),a=Rn().toVar(),u=Rn().toVar(),l=Rn().toVar();return a.assign(u.assign(l.assign(Rn(An(3735928559)).add(o.shiftLeft(Rn(2))).add(Rn(13))))),a.addAssign(Rn(i)),u.addAssign(Rn(n)),l.addAssign(Rn(r)),HT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),yn((([e,t,s,r])=>{const n=An(r).toVar(),i=An(s).toVar(),o=An(t).toVar(),a=An(e).toVar(),u=Rn(Rn(4)).toVar(),l=Rn().toVar(),d=Rn().toVar(),c=Rn().toVar();return l.assign(d.assign(c.assign(Rn(An(3735928559)).add(u.shiftLeft(Rn(2))).add(Rn(13))))),l.addAssign(Rn(a)),d.addAssign(Rn(o)),c.addAssign(Rn(i)),$T(l,d,c),l.addAssign(Rn(n)),HT(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),yn((([e,t,s,r,n])=>{const i=An(n).toVar(),o=An(r).toVar(),a=An(s).toVar(),u=An(t).toVar(),l=An(e).toVar(),d=Rn(Rn(5)).toVar(),c=Rn().toVar(),h=Rn().toVar(),p=Rn().toVar();return c.assign(h.assign(p.assign(Rn(An(3735928559)).add(d.shiftLeft(Rn(2))).add(Rn(13))))),c.addAssign(Rn(l)),h.addAssign(Rn(u)),p.addAssign(Rn(a)),$T(c,h,p),c.addAssign(Rn(o)),h.addAssign(Rn(i)),HT(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),KT=Pm([yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(qT(r,s)).toVar(),i=Pn().toVar();return i.x.assign(n.bitAnd(An(255))),i.y.assign(n.shiftRight(An(8)).bitAnd(An(255))),i.z.assign(n.shiftRight(An(16)).bitAnd(An(255))),i})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(qT(i,n,r)).toVar(),a=Pn().toVar();return a.x.assign(o.bitAnd(An(255))),a.y.assign(o.shiftRight(An(8)).bitAnd(An(255))),a.z.assign(o.shiftRight(An(16)).bitAnd(An(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),XT=Pm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(wT(t.x,s)).toVar(),i=Sn(wT(t.y,r)).toVar(),o=Sn(jT(n)).toVar(),a=Sn(jT(i)).toVar(),u=Sn(MT(PT(qT(s,r),n,i),PT(qT(s.add(An(1)),r),n.sub(1),i),PT(qT(s,r.add(An(1))),n,i.sub(1)),PT(qT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return GT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(wT(t.x,s)).toVar(),o=Sn(wT(t.y,r)).toVar(),a=Sn(wT(t.z,n)).toVar(),u=Sn(jT(i)).toVar(),l=Sn(jT(o)).toVar(),d=Sn(jT(a)).toVar(),c=Sn(BT(PT(qT(s,r,n),i,o,a),PT(qT(s.add(An(1)),r,n),i.sub(1),o,a),PT(qT(s,r.add(An(1)),n),i,o.sub(1),a),PT(qT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),PT(qT(s,r,n.add(An(1))),i,o,a.sub(1)),PT(qT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),PT(qT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),PT(qT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return kT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),YT=Pm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(wT(t.x,s)).toVar(),i=Sn(wT(t.y,r)).toVar(),o=Sn(jT(n)).toVar(),a=Sn(jT(i)).toVar(),u=Un(MT(DT(KT(s,r),n,i),DT(KT(s.add(An(1)),r),n.sub(1),i),DT(KT(s,r.add(An(1))),n,i.sub(1)),DT(KT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return GT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(wT(t.x,s)).toVar(),o=Sn(wT(t.y,r)).toVar(),a=Sn(wT(t.z,n)).toVar(),u=Sn(jT(i)).toVar(),l=Sn(jT(o)).toVar(),d=Sn(jT(a)).toVar(),c=Un(BT(DT(KT(s,r,n),i,o,a),DT(KT(s.add(An(1)),r,n),i.sub(1),o,a),DT(KT(s,r.add(An(1)),n),i,o.sub(1),a),DT(KT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),DT(KT(s,r,n.add(An(1))),i,o,a.sub(1)),DT(KT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),DT(KT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),DT(KT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return kT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),QT=Pm([yn((([e])=>{const t=Sn(e).toVar(),s=An(ET(t)).toVar();return WT(qT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar();return WT(qT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar();return WT(qT(s,r,n))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar(),i=An(ET(t.w)).toVar();return WT(qT(s,r,n,i))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),ZT=Pm([yn((([e])=>{const t=Sn(e).toVar(),s=An(ET(t)).toVar();return Un(WT(qT(s,An(0))),WT(qT(s,An(1))),WT(qT(s,An(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar();return Un(WT(qT(s,r,An(0))),WT(qT(s,r,An(1))),WT(qT(s,r,An(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar();return Un(WT(qT(s,r,n,An(0))),WT(qT(s,r,n,An(1))),WT(qT(s,r,n,An(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(ET(t.x)).toVar(),r=An(ET(t.y)).toVar(),n=An(ET(t.z)).toVar(),i=An(ET(t.w)).toVar();return Un(WT(qT(s,r,n,i,An(0))),WT(qT(s,r,n,i,An(1))),WT(qT(s,r,n,i,An(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),JT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Sn(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(XT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),e_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(YT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),t_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar();return En(JT(a,o,i,n),JT(a.add(Un(An(19),An(193),An(17))),o,i,n))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),s_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(e_(a,o,i,n)).toVar(),l=Sn(JT(a.add(Un(An(19),An(193),An(17))),o,i,n)).toVar();return Ln(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),r_=Pm([yn((([e,t,s,r,n,i,o])=>{const a=An(o).toVar(),u=Sn(i).toVar(),l=An(n).toVar(),d=An(r).toVar(),c=An(s).toVar(),h=An(t).toVar(),p=En(e).toVar(),g=Un(ZT(En(h.add(d),c.add(l)))).toVar(),m=En(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=En(En(Sn(h),Sn(c)).add(m)).toVar(),y=En(f.sub(p)).toVar();return _n(a.equal(An(2)),(()=>Fo(y.x).add(Fo(y.y)))),_n(a.equal(An(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),yn((([e,t,s,r,n,i,o,a,u])=>{const l=An(u).toVar(),d=Sn(a).toVar(),c=An(o).toVar(),h=An(i).toVar(),p=An(n).toVar(),g=An(r).toVar(),m=An(s).toVar(),f=An(t).toVar(),y=Un(e).toVar(),b=Un(ZT(Un(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Un(Un(Sn(f),Sn(m),Sn(g)).add(b)).toVar(),T=Un(x.sub(y)).toVar();return _n(l.equal(An(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),_n(l.equal(An(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),n_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();l.assign(qo(l,s))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),o_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(wT(i.x,o),wT(i.y,a)).toVar(),l=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(r_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),a_=Pm([n_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();d.assign(qo(d,i))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=Pm([i_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.y.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),l_=Pm([o_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(wT(i.x,o),wT(i.y,a),wT(i.z,u)).toVar(),d=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(r_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(i)})).ElseIf(i.lessThan(d.z),(()=>{d.z.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),d_=yn((([e])=>{const t=e.y,s=e.z,r=Un().toVar();return _n(t.lessThan(1e-4),(()=>{r.assign(Un(s,s,s))})).Else((()=>{let n=e.x;n=n.sub(vo(n)).mul(6).toVar();const i=An(zo(n)),o=n.sub(Sn(i)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());_n(i.equal(An(0)),(()=>{r.assign(Un(s,l,a))})).ElseIf(i.equal(An(1)),(()=>{r.assign(Un(u,s,a))})).ElseIf(i.equal(An(2)),(()=>{r.assign(Un(a,s,l))})).ElseIf(i.equal(An(3)),(()=>{r.assign(Un(a,u,s))})).ElseIf(i.equal(An(4)),(()=>{r.assign(Un(l,a,s))})).Else((()=>{r.assign(Un(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),c_=yn((([e])=>{const t=Un(e).toVar(),s=Sn(t.x).toVar(),r=Sn(t.y).toVar(),n=Sn(t.z).toVar(),i=Sn(qo(s,qo(r,n))).toVar(),o=Sn(Ko(s,Ko(r,n))).toVar(),a=Sn(o.sub(i)).toVar(),u=Sn().toVar(),l=Sn().toVar(),d=Sn().toVar();return d.assign(o),_n(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),_n(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{_n(s.greaterThanEqual(o),(()=>{u.assign(r.sub(n).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vi(2,n.sub(s).div(a)))})).Else((()=>{u.assign(Vi(4,s.sub(r).div(a)))})),u.mulAssign(1/6),_n(u.lessThan(0),(()=>{u.addAssign(1)}))})),Un(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),h_=yn((([e])=>{const t=Un(e).toVar(),s=In(ji(t,Un(.04045))).toVar(),r=Un(t.div(12.92)).toVar(),n=Un(sa(Ko(t.add(Un(.055)),Un(0)).div(1.055),Un(2.4))).toVar();return la(r,n,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),p_=(e,t)=>{e=Sn(e),t=Sn(t);const s=En(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},g_=(e,t,s,r)=>la(e,t,s[r].clamp()),m_=(e,t,s=mu())=>g_(e,t,s,"x"),f_=(e,t,s=mu())=>g_(e,t,s,"y"),y_=(e,t,s,r,n)=>la(e,t,p_(s,r[n])),b_=(e,t,s,r=mu())=>y_(e,t,s,r,"x"),x_=(e,t,s,r=mu())=>y_(e,t,s,r,"y"),T_=(e=1,t=0,s=mu())=>s.mul(e).add(t),__=(e,t=1)=>(e=Sn(e)).abs().pow(t).mul(e.sign()),N_=(e,t=1,s=.5)=>Sn(e).sub(s).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>XT(e.convert("vec2|vec3")).mul(t).add(s),S_=(e=mu(),t=1,s=0)=>YT(e.convert("vec2|vec3")).mul(t).add(s),A_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ln(YT(e),XT(e.add(En(19,73)))).mul(t).add(s)},R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,An(1)),C_=(e=mu(),t=1)=>u_(e.convert("vec2|vec3"),t,An(1)),E_=(e=mu(),t=1)=>l_(e.convert("vec2|vec3"),t,An(1)),w_=(e=mu())=>QT(e.convert("vec2|vec3")),M_=(e=mu(),t=3,s=2,r=.5,n=1)=>JT(e,An(t),s,r).mul(n),B_=(e=mu(),t=3,s=2,r=.5,n=1)=>t_(e,An(t),s,r).mul(n),U_=(e=mu(),t=3,s=2,r=.5,n=1)=>e_(e,An(t),s,r).mul(n),F_=(e=mu(),t=3,s=2,r=.5,n=1)=>s_(e,An(t),s,r).mul(n),P_=yn((([e,t,s])=>{const r=Ao(e).toVar("nDir"),n=Oi(Sn(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),i=Oi(Sn(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Un().toVar("rbminmax");o.x=r.x.greaterThan(Sn(0)).select(n.x,i.x),o.y=r.y.greaterThan(Sn(0)).select(n.y,i.y),o.z=r.z.greaterThan(Sn(0)).select(n.z,i.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),I_=yn((([e,t])=>{const s=e.x,r=e.y,n=e.z;let i=t.element(0).mul(.886227);return i=i.add(t.element(1).mul(1.023328).mul(r)),i=i.add(t.element(2).mul(1.023328).mul(n)),i=i.add(t.element(3).mul(1.023328).mul(s)),i=i.add(t.element(4).mul(.858086).mul(s).mul(r)),i=i.add(t.element(5).mul(.858086).mul(r).mul(n)),i=i.add(t.element(6).mul(n.mul(n).mul(.743125).sub(.247708))),i=i.add(t.element(7).mul(.858086).mul(s).mul(n)),i=i.add(t.element(8).mul(.429043).mul(Gi(s,s).sub(Gi(r,r)))),i})),L_=new hm;class D_ extends Dg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,n=this.nodes.getBackgroundNode(e)||e.background;let i=!1;if(null===n)r._clearColor.getRGB(L_,Se),L_.a=r._clearColor.a;else if(!0===n.isColor)n.getRGB(L_,Se),L_.a=1,i=!0;else if(!0===n.isNode){const s=this.get(e),i=n;L_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ln(i).mul(Df),{getUV:()=>Vf.mul(ll),getTextureLevel:()=>Lf});let t=Wd();t=t.setZ(t.w);const r=new nh;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=i.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ln(i).mul(Df),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",n);if(!0===r.autoClear||!0===i){const e=s.clearColorValue;e.r=L_.r,e.g=L_.g,e.b=L_.b,e.a=L_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let V_=0;class O_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=V_++}}class G_{constructor(e,t,s,r,n,i,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=n,this.updateNodes=i,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new O_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class k_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class z_{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class $_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class H_ extends $_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class W_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let j_=0;class q_{constructor(e=null){this.id=j_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class K_{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class X_ extends K_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class Y_ extends K_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class Q_ extends K_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends K_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class J_ extends K_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class eN extends K_{constructor(e,t=new n){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class tN extends K_{constructor(e,t=new i){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class aN extends eN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class uN extends tN{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const lN=[.125,.215,.35,.446,.526,.582],dN=20,cN=new xe(-1,1,1,-1,0,1),hN=new Be(90,1),pN=new e;let gN=null,mN=0,fN=0;const yN=(1+Math.sqrt(5))/2,bN=1/yN,xN=[new s(-yN,bN,0),new s(yN,bN,0),new s(-bN,0,yN),new s(bN,0,yN),new s(0,yN,-bN),new s(0,yN,bN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],TN=[3,1,5,0,4,2],_N=Hp(mu(),gu("faceIndex")).normalize(),NN=Un(_N.x,_N.y.negate(),_N.z);class vN{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(e,t=0,s=.1,r=100){gN=this._renderer.getRenderTarget(),mN=this._renderer.getActiveCubeFace(),fN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const n=this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(e,s,r,n),t>0&&this._blur(n,0,0,t),this._applyPMREM(n),this._cleanup(n),n}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=CN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=EN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=lN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],n=TN[e];b.set(r,m*g*n),x.set(h,f*g*n);const i=[n,n,n,n,n,n];T.set(i,y*g*n)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),n.push(new k(_,null)),i>4&&i--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:n}}(n)),this._blurMaterial=function(e,t,r){const n=Rl(new Array(dN).fill(0)),i=ti(new s(0,1,0)),o=ti(0),a=Sn(dN),u=ti(0),l=ti(1),d=_u(null),c=ti(0),h=Sn(1/t),p=Sn(1/r),g=Sn(e),m={n:a,latitudinal:u,weights:n,poleAxis:i,outputDirection:NN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=RN("blur");return f.uniforms=m,f.fragmentNode=Kp({...m,latitudinal:u.equal(1)}),f}(n,e,t)}return n}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,cN)}_sceneToCubeUV(e,t,s,r){const n=hN;n.near=t,n.far=s;const i=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(pN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(pN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,n);for(let t=0;t<6;t++){const s=t%3;0===s?(n.up.set(0,i[t],0),n.lookAt(o[t],0,0)):1===s?(n.up.set(0,0,i[t]),n.lookAt(0,o[t],0)):(n.up.set(0,i[t],0),n.lookAt(0,0,o[t]));const u=this._cubeSize;AN(r,s*u,t>2?u:0,u,u),a.render(e,n)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=CN(e)):null===this._equirectMaterial&&(this._equirectMaterial=EN(e));const n=r?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=n;const o=this._cubeSize;AN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(i,cN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;tdN&&console.warn(`sigmaRadians, ${n}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,cN)}}function SN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function AN(e,t,s,r,n){e.viewport.set(t,s,r,n),e.scissor.set(t,s,r,n)}function RN(e){const t=new nh;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function CN(e){const t=RN("cubemap");return t.fragmentNode=_l(e,NN),t}function EN(e){const t=RN("equirect");return t.fragmentNode=_u(e,bh(NN),0),t}const wN=new WeakMap,MN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),BN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),UN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class FN{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=fm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new q_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=wN.get(this.renderer);return void 0===e&&(e=new Ug,wN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new xh(e,t)}createPMREMGenerator(){return new vN(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let n,i=!0;for(const e of t)r.push(e),i=i&&!0!==e.groupNode.shared;return i?(n=s.get(r),void 0===n&&(n=new O_(e,r,this.bindingsIndexes[e].group,r),s.set(r,n))):n=new O_(e,r,this.bindingsIndexes[e].group,r),n}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const n=s[e][r];(t[r]||(t[r]=[])).push(...n)}e=[];for(const s in t){const r=t[s],n=this._getBindGroup(s,r);e.push(n)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(i)}u`:"0u";if("bool"===n)return i?"true":"false";if("color"===n)return`${this.getType("vec3")}( ${UN(i.r)}, ${UN(i.g)}, ${UN(i.b)} )`;const o=this.getTypeLength(n),a=this.getComponentType(n),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)} )`;if(3===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)} )`;if(4===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)}, ${u(i.w)} )`;if(o>4&&i&&(i.isMatrix3||i.isMatrix4))return`${this.getType(n)}( ${i.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(n)}()`;throw new Error(`NodeBuilder: Type '${n}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new k_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=MN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return BN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,n=e.normalized;let i;return e instanceof Ie||!0===n||(i=this.getTypeFromArray(s)),this.getTypeFromLength(r,i)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=fm(this.stack),this.stacks.push(Tn()||this.stack),xn(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,xn(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(void 0===r){const n=this.uniforms.index++;r=new k_("nodeAttribute"+n,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const n=this.getDataFromNode(e,s,this.globalCache);let i=n.uniform;if(void 0===i){const o=this.uniforms.index++;i=new z_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(i),n.uniform=i}return i}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const n=this.getDataFromNode(e,r);let i=n.variable;if(void 0===i){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),i=new $_(t,s),e.push(i),n.variable=i}return i}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let n=r.varying;if(void 0===n){const e=this.varyings,i=e.length;null===t&&(t="nodeVarying"+i),n=new H_(t,s),e.push(n),r.varying=n}return n}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let n=r.code;if(void 0===n){const e=this.codes[s]||(this.codes[s]=[]),i=e.length;n=new W_("nodeCode"+i,t),e.push(n),r.code=n}return n}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let n=!0,i=t;for(;i;){if(!0===r.get(i)){n=!1;break}i=this.getDataFromNode(i).parentNodeBlock}if(n)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),n=r.flowCodes||(r.flowCodes=[]),i=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);n.push(t),i.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new lx,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new pm(e.type,e.name);e.layout=null;const r=e.call(s),n=this.flowStagesNode(r,t.type);return e.layout=t,n}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,n=this.cache,i=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new q_,this.stack=fm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=n,this.stack=o,this.setBuildStage(i),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const n=this.shaderStage;this.setShaderStage(e);const i=this.flowChildNode(t,s);return null!==r&&(i.code+=`${this.tab+r} = ${i.result};\n`),this.flowCode[e]=this.flowCode[e]+i.code,this.setShaderStage(n),i}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new nh),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new sN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new rN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new nN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new iN(e);if("color"===t)return new oN(e);if("mat3"===t)return new aN(e);if("mat4"===t)return new uN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),n=this.getTypeLength(s);return 16===r&&9===n?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===n?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||n>4||0===n?e:r===n?`${this.getType(s)}( ${e} )`:r>n?this.format(`${e}.${"xyz".slice(0,n)}`,this.getTypeFromLength(n,this.getComponentType(t)),s):4===n&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&n>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class PN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class IN{constructor(e,t,s=null,r="",n=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=n}}IN.isNodeFunctionInput=!0;class LN extends _T{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=iT(this.light),n=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:n},e.stack,e)}}const DN=new i,VN=new i;let ON=null;class GN extends _T{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=ti(new s).setGroup(Zn),this.halfWidth=ti(new s).setGroup(Zn),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;VN.identity(),DN.copy(t.matrixWorld),DN.premultiply(s),VN.extractRotation(DN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(VN),this.halfHeight.value.applyMatrix4(VN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(ON.LTC_FLOAT_1),s=_u(ON.LTC_FLOAT_2)):(t=_u(ON.LTC_HALF_1),s=_u(ON.LTC_HALF_2));const{colorNode:r,light:n}=this,i=e.context.lightingModel,o=nT(n),a=e.context.reflectedLight;i.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){ON=e}}class kN extends _T{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=ti(0).setGroup(Zn),this.penumbraCosNode=ti(0).setGroup(Zn),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:n,light:i}=this,o=nT(i).sub(el),a=o.normalize(),u=a.dot(iT(i)),l=this.getSpotAttenuation(u),d=o.length(),c=NT({lightDistance:d,cutoffDistance:r,decayExponent:n}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class zN extends kN{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,En(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class $N extends _T{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class HN extends _T{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=sT(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=ti(new e).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:r}=this,n=ul.dot(r).mul(.5).add(.5),i=la(s,t,n);e.context.irradiance.addAssign(i)}}class WN extends _T{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=I_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class jN{parseFunction(){console.warn("Abstract function.")}}class qN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}qN.isNodeFunction=!0;const KN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,XN=/[a-z_0-9]+/gi,YN="#pragma main";class QN extends qN{constructor(e){const{type:t,inputs:s,name:r,precision:n,inputsCode:i,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(YN),s=-1!==t?e.slice(t+12):e,r=s.match(KN);if(null!==r&&5===r.length){const n=r[4],i=[];let o=null;for(;null!==(o=XN.exec(n));)i.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Jp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=Sh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Zn),r=Ml("density","float",s).setGroup(Zn);e=Ax(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Zn),r=Ml("near","float",s).setGroup(Zn),n=Ml("far","float",s).setGroup(Zn);e=vx(t,r,n)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,n=null){const i=this.nodeFrame;return i.renderer=e,i.scene=t,i.object=s,i.camera=r,i.material=n,i}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return JN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return JN.set(e,s),r}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new PN,this.nodeBuilderCache=new Map}}const tv=new me;class sv{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new n,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let n=0;n{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),n=this._renderContexts.get(e,t,this._renderTarget),i=e.overrideMaterial||s.material,o=this._objects.get(s,i,e,t,r.lightsNode,n,n.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ev(this,s),this._animation=new Bg(this._nodes,this.info),this._attributes=new $g(s),this._background=new D_(this,this._nodes),this._geometries=new jg(this._attributes,this.info),this._textures=new cm(this,s,this.info),this._pipelines=new Jg(s,this._nodes),this._bindings=new em(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Lg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new im(this.lighting),this._bundles=new nv,this._renderContexts=new lm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,n=r.renderId,i=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:uv;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new sv),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=n,this._currentRenderContext=i,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:n,renderList:i}=e,o=this._currentRenderContext,a=this._bundles.get(r,n),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=i.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,n,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(dv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(dv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new sv),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),hv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),cv.setFromProjectionMatrix(hv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),n.renderId=i,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,r){const n=this._scissor;e.isVector4?n.copy(e):n.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,n=0,i=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=n,o.maxDepth=i}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let n=null;if(null!==r&&(this._textures.updateRenderTarget(r),n=this._textures.get(r)),this.backend.clear(e,t,s,n),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const r=this.backend,n=this._pipelines,i=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===n.has(t)){const e=()=>{t.removeEventListener("dispose",e),n.delete(t),i.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),i.updateForCompute(t);const s=i.getForCompute(t),a=n.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=pv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=pv.copy(t).floor()}else t=pv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,n)}readRenderTargetPixelsAsync(e,t,s,r,n,i=0,o=0){return this.backend.copyTextureToBuffer(e.textures[i],t,s,r,n,o)}_projectObject(e,t,s,r,n){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(n=n.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||cv.intersectsSprite(e)){!0===this.sortObjects&&pv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(hv);const{geometry:t,material:i}=e;i.visible&&r.push(e,t,i,s,pv.z,null,n)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||cv.intersectsObject(e))){const{geometry:t,material:i}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),pv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(hv)),Array.isArray(i)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,n,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,n);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,n)}_renderObjects(e,t,s,r,n=null){for(let i=0,o=e.length;i0?r:"";t=`${e.name} {\n\t${s} ${n.name}[${i}];\n};\n`}else{t=`${this.getVectorType(n.type)} ${this.getPropertyName(n,e)};`,i=!0}const o=n.node.precision;if(null!==o&&(t=wv[o]+" "+t),i){t="\t"+t;const e=n.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let n="";for(const t in r){const s=r[t];n+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return n+=s.join("\n"),n}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Mv[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Mv[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${i}\n\t`),s+=`${r.code}\n\t`,e===n&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const i=e[t];i.extensions=this.getExtensions(t),i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.vars=this.getVars(t),i.structs=this.getStructs(t),i.codes=this.getCodes(t),i.transforms=this.getTransforms(t),i.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);let o=i.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new Av(n.name,n.node,r),u.push(o);else if("cubeTexture"===t)o=new Rv(n.name,n.node,r),u.push(o);else if("texture3D"===t)o=new Cv(n.name,n.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,n.name=`buffer${e.id}`;const t=new xv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Nv(s+"_"+a,r),e[a]=i,u.push(i)),o=this.getNodeUniform(n,t),i.addUniform(o)}i.uniformGPU=o}return n}}let Fv=null,Pv=null,Iv=null;class Lv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Fv=Fv||new t,this.renderer.getDrawingBufferSize(Fv)}getScissor(){return Pv=Pv||new r,this.renderer.getScissor(Pv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Iv=Iv||new hm,e.getClearColor(Iv),Iv.getRGB(Iv,this.renderer.currentColorSpace),Iv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Dv=0;class Vv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Ov{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,n=e.array,i=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,n,i),a.bufferGPU=l,a.bufferType=t,a.version=o.version),n instanceof Float32Array)u=r.FLOAT;else if(n instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(n instanceof Int16Array)u=r.SHORT;else if(n instanceof Uint32Array)u=r.UNSIGNED_INT;else if(n instanceof Int32Array)u=r.INT;else if(n instanceof Int8Array)u=r.BYTE;else if(n instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Dv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,n,i);d=new Vv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,n=e.isInterleavedBufferAttribute?e.data:e,i=t.get(n),o=i.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,i.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t{!function n(){const i=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(i===e.WAIT_FAILED)return e.deleteSync(t),void r();i!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(n)}()}))}}let Wv,jv,qv,Kv=!1;class Xv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===Kv&&(this._init(this.gl),Kv=!0)}_init(e){Wv={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},jv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},qv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,n=!1){const{gl:i,extensions:o}=this;if(null!==e){if(void 0!==i[e])return i[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===i.RED&&(s===i.FLOAT&&(a=i.R32F),s===i.HALF_FLOAT&&(a=i.R16F),s===i.UNSIGNED_BYTE&&(a=i.R8),s===i.UNSIGNED_SHORT&&(a=i.R16),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RED_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.R8UI),s===i.UNSIGNED_SHORT&&(a=i.R16UI),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RG&&(s===i.FLOAT&&(a=i.RG32F),s===i.HALF_FLOAT&&(a=i.RG16F),s===i.UNSIGNED_BYTE&&(a=i.RG8),s===i.UNSIGNED_SHORT&&(a=i.RG16),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RG_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RG8UI),s===i.UNSIGNED_SHORT&&(a=i.RG16UI),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RGB&&(s===i.FLOAT&&(a=i.RGB32F),s===i.HALF_FLOAT&&(a=i.RGB16F),s===i.UNSIGNED_BYTE&&(a=i.RGB8),s===i.UNSIGNED_SHORT&&(a=i.RGB16),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8:i.RGB8),s===i.UNSIGNED_SHORT_5_6_5&&(a=i.RGB565),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGB4),s===i.UNSIGNED_INT_5_9_9_9_REV&&(a=i.RGB9_E5)),t===i.RGB_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGB8UI),s===i.UNSIGNED_SHORT&&(a=i.RGB16UI),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I)),t===i.RGBA&&(s===i.FLOAT&&(a=i.RGBA32F),s===i.HALF_FLOAT&&(a=i.RGBA16F),s===i.UNSIGNED_BYTE&&(a=i.RGBA8),s===i.UNSIGNED_SHORT&&(a=i.RGBA16),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8_ALPHA8:i.RGBA8),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGBA4),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1)),t===i.RGBA_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGBA8UI),s===i.UNSIGNED_SHORT&&(a=i.RGBA16UI),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I)),t===i.DEPTH_COMPONENT&&(s===i.UNSIGNED_INT&&(a=i.DEPTH24_STENCIL8),s===i.FLOAT&&(a=i.DEPTH_COMPONENT32F)),t===i.DEPTH_STENCIL&&s===i.UNSIGNED_INT_24_8&&(a=i.DEPTH24_STENCIL8),a!==i.R16F&&a!==i.R32F&&a!==i.RG16F&&a!==i.RG32F&&a!==i.RGBA16F&&a!==i.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:n}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,Wv[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,Wv[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,Wv[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,jv[t.magFilter]);const i=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&i?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,jv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,qv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const i=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,n.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,n=this.getGLTextureType(e);let i=r[n];void 0===i&&(i=t.createTexture(),s.state.bindTexture(n,i),t.texParameteri(n,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(n,t.TEXTURE_MAG_FILTER,t.NEAREST),r[n]=i),s.set(e,{textureGPU:i,glTextureType:n,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:n,width:i,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,n,d,i,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,n,d,i,o,a):e.isVideoTexture||s.texStorage2D(h,n,d,i,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:n,glTextureType:i,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(i,n),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(i,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:n}=t,{textureGPU:i,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===i)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,i),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,n=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;n.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),n.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),n.bindFramebuffer(r.READ_FRAMEBUFFER,s),n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),n.unbindTexture()}else{const e=r.createFramebuffer();n.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,i,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),n.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:n,depthTexture:i,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;n>0?(i&&i.isDepthTexture&&i.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,n,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(n>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,n,i){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+i:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*n*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,n,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let r=0;return e===s.UNSIGNED_BYTE&&(r=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Yv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Qv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const Zv={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class Jv{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:r,object:n,type:i,info:o,index:a}=this;0!==a?s.drawElements(r,t,i,e):s.drawArrays(r,e,t),o.update(n,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:n,type:i,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(n,t,i,e,s):r.drawArraysInstanced(n,e,t,s),u.update(a,t,n,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:n,object:i,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),n=r.previousContext,i=e.occlusionQueryCount;i>0&&(i>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const n=r.framebuffers[e.getCacheKey()],i=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,n);for(let s=0;s{let o=0;for(let t=0;t0&&e.add(r[t]),s[t]=null,n.deleteQuery(i),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Uv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,n="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(n,r),t.compileShader(n),this.set(e,{shaderGPU:n})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:n,vertexProgram:i}=r,o=s.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const n=new Promise((t=>{const n=this.parallel,i=()=>{s.getProgramParameter(o,n.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(i)};i()}));t.push(n)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],n=Math.max(t-6,0),i=Math.min(t+6,s.length);for(let e=n;e":" "} ${n}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),n=e.getShaderInfoLog(t).trim();if(r&&""===n)return"";const i=/ERROR: 0:(\d+)/.exec(n);if(i){const r=parseInt(i[1]);return s.toUpperCase()+"\n\n"+n+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return n}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,n=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const i=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+n+"\n"+i+"\n"+o)}else""!==n&&console.warn("THREE.WebGLProgram: Program Info Log:",n)}}_completeCompile(e,t){const{state:s,gl:r}=this,n=this.get(t),{programGPU:i,fragmentShader:o,vertexShader:a}=n;!1===r.getProgramParameter(i,r.LINK_STATUS)&&this._logProgramError(i,o,a),s.useProgram(i);const u=e.getBindings();this._setupBindings(u,i),this.set(t,{programGPU:i})}createComputePipeline(e,t){const{state:s,gl:r}=this,n={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(n);const{computeProgram:i}=e,o=r.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU,l=i.transforms,d=[],c=[];for(let e=0;eZv[t]===e)),s=this.extensions;for(let e=0;e0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const n=[],l=e.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Wf,stripIndexFormat:uy},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Wf,stripIndexFormat:uy},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:n,height:i}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:n,height:i,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),n=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),i=c.beginRenderPass({colorAttachments:[{view:s,loadOp:sy,storeOp:ey,clearValue:[0,0,0,0]}]});i.setPipeline(e),i.setBindGroup(0,n),i.draw(4,1,0,0),i.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const n=r.layers[s]||this._mipmapCreateBundles(e,t,s),i=this.device.createCommandEncoder({});this._mipmapRunBundles(i,n),this.device.queue.submit([i.finish()]),0!==r.useCount&&(r.layers[s]=n),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),n=r.getBindGroupLayout(0);let i=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:eb,baseArrayLayer:s});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,hS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,pS={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class gS extends qN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:n,blockCode:i,outputType:o}=(e=>{const t=(e=e.trim()).match(cS);if(null!==t&&4===t.length){const s=t[2],r=[];let n=null;for(;null!==(n=hS.exec(s));)r.push({name:n[1],type:n[2]});const i=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class mS extends jN{parseFunction(e){return new gS(e)}}const fS=self.GPUShaderStage,yS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},bS={vertex:fS?fS.VERTEX:1,fragment:fS?fS.FRAGMENT:2,compute:fS?fS.COMPUTE:4},xS={instance:!0,swizzleAssign:!1,storageBuffer:!0},TS={"^^":"tsl_xor"},_S={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},NS={},vS={tsl_xor:new nx("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new nx("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new nx("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new nx("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new nx("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new nx("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new nx("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new nx("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new nx("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new nx("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new nx("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new nx("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new nx("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new nx("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},SS={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(vS.pow_float=new nx("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),vS.pow_vec2=new nx("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[vS.pow_float]),vS.pow_vec3=new nx("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[vS.pow_float]),vS.pow_vec4=new nx("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[vS.pow_float]),SS.pow_float="tsl_pow_float",SS.pow_vec2="tsl_pow_vec2",SS.pow_vec3="tsl_pow_vec3",SS.pow_vec4="tsl_pow_vec4");let AS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(AS+="diagnostic( off, derivative_uniformity );\n");class RS extends FN{constructor(e,t){super(e,t,new mS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,n=this.shaderStage){return"fragment"===n?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,r,n,i=this.shaderStage){return"fragment"===i&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${yS[e.wrapS]}S_${yS[e.wrapT]}T`;let s=NS[t];if(void 0===s){const r=[];let n=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const i=(e,t)=>{e===ls?(r.push(vS.repeatWrapping_float),n+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(r.push(vS.clampWrapping_float),n+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(r.push(vS.mirrorWrapping_float),n+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(n+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};i(e.wrapS,"x"),n+=",\n",i(e.wrapT,"y"),n+="\n\t);\n\n}\n",NS[t]=s=new nx(n,r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let n=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(n=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${n} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=n),n}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,n="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${n} )`:`textureLoad( ${t}, ${s}, ${n} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,n=this.shaderStage){let i=null;return i=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,n):this._generateTextureSample(e,t,s,r,n),i}generateTextureGrad(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${i} shader.`)}generateTextureCompare(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${i} shader.`)}generateTextureLevel(e,t,s,r,n,i=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this._generateTextureSampleLevel(e,t,s,r,n,i),o}generateTextureBias(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${i} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=TS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case jy:return"read";case Wy:return"write";default:return"read_write"}else switch(e.access){case $y:return"read_write";case Hy:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);if(void 0===i.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let i=null;if("texture"===t||"storageTexture"===t?i=new Av(n.name,n.node,o,e.access?e.access:null):"cubeTexture"===t?i=new Rv(n.name,n.node,o,e.access?e.access:null):"texture3D"===t&&(i=new Cv(n.name,n.node,o,e.access?e.access:null)),i.store=!0===e.isStorageTextureNode,i.setVisibility(bS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===i.store){const e=new sS(`${n.name}_sampler`,n.node,o);e.setVisibility(bS[s]),u.push(e,i),r=[e,i]}else u.push(i),r=[i]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const n=new("buffer"===t?xv:iS)(e,o);n.setVisibility(bS[s]),u.push(n),r=n}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Nv(a,o),i.setVisibility(bS[s]),e[a]=i,u.push(i)),r=this.getNodeUniform(n,t),i.addUniform(r)}i.uniformGPU=r}return n}getBuiltin(e,t,s,r=this.shaderStage){const n=this.builtins[r]||(this.builtins[r]=new Map);return!1===n.has(e)&&n.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let n=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(n+=`\treturn ${s.result};\n`),n+="\n}\n",n}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:n}of s.values())t.push(`@builtin( ${e} ) ${r} : ${n}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:n}of this.scopedArrays.values()){const i=this.getType(r);t.push(`var<${s}> ${e}: array< ${i}, ${n} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e{const{name:t,node:r}=e,n=!0===r.bufferStruct;s.set(t,n)})),s}getMembersFromCustomStruct(e){return`\t${e.map((({name:e,type:t,isAtomic:s})=>{let r=_S[t];return r||(console.warn(`Unrecognized type: ${t}`),r="vec4"),`${e}: ${s?`atomic<${r}>`:r}`})).join(",\n\t")}`}getCustomStructNameFromShader(e){const t=/fn\s+\w+\s*\(([\s\S]*?)\)/g,s=/(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g,r=[];let n;for(;null!==(n=t.exec(e));){const e=n[1];let t;for(;null!==(t=s.exec(e));){const[e,s,n,i,o,a]=t,u=o||a||null,l=i||n;Object.values(_S).includes(u)||null===u||r.push({name:s,type:l,structName:u})}}return r}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;e`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e output : ${n};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let n=0;n";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array";else if(!0===t.isDepthTexture)r=`texture_depth${i}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d";else if(!0===n.node.isStorageTextureNode){r=`texture_storage_2d<${dS(t)}, ${this.getStorageAccess(n.node)}>`}else{r=`texture${i}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name} : ${r};`)}else if("buffer"===n.type||"storageBuffer"===n.type||"indirectStorageBuffer"===n.type){const e=n.node,t=this.getType(e.bufferType),s=e.bufferCount,i=e.value.array.length!==e.value.itemSize,a=s>0&&"buffer"===n.type?", "+s:"",u=e.isAtomic?`atomic<${t}>`:`${t}`,l=e.bufferStruct?this.getMembersFromCustomStruct(t):`\t${n.name} : array< ${u}${a} >\n`,d=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding(e.bufferStruct,i,"NodeBuffer_"+e.id,l,d,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(n.type)),t=n.groupNode.name;(i[t]||(i[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${n.name} : ${e}`)}}for(const e in i){const t=i[e];n.push(this._getWGSLStructBinding(!1,!1,e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=n.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t),s.isBufferStruct=this.getTypeFromCustomStruct(t),s.customStructNames=this.getCustomStructNameFromShader(s.codes);const r=e=>e.replace(/&(\w+)\.(\w+)/g,((e,t,r)=>!0===s.isBufferStruct.get(r)?`&${t}`:e)),n=e=>{const t=e.match(/\(([^)]+)\)/);if(!t)return[];return t[1].split(/\s*,\s*/).map((e=>e.trim())).filter((e=>e.includes("&"))).map((e=>e.replace("&",""))).filter((e=>!e.includes(".")))},i=(e,t)=>{const s=new Map;for(let r=0;r{for(const[s,r]of t.entries()){const t=new RegExp(`\\b${s}Struct\\b`,"g");e=e.replace(t,r)}return e};let a,u,l="// code\n\n";l+=this.flowCode[t];const d=this.flowNodes[t],c=d[d.length-1],h=c.outputNode,p=void 0!==h&&!0===h.isOutputStructNode;for(const e of d){const d=this.getFlowData(e),g=e.name;if(g&&(l.length>0&&(l+="\n"),l+=`\t// flow -> ${g}\n\t`),l+=`${d.code}\n\t`,l=r(l),a=n(l),u=i(a,s.customStructNames),s.uniforms=o(s.uniforms,u),e===c&&"compute"!==t){if(l+="// result\n\n\t","vertex"===t)l+=`varyings.Vertex = ${d.result};`;else if("fragment"===t)if(p)s.returnType=h.nodeType,l+=`return ${d.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar output : OutputStruct;\n\n",l+=`output.color = ${d.result};\n\n\treturn output;`}l=r(l),a=n(l),u=i(a,s.customStructNames),s.uniforms=o(s.uniforms,u)}}s.flow=l}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return _S[e]||e}isAvailable(e){let t=xS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),xS[e]=t),t}_getWGSLMethod(e){return void 0!==vS[e]&&this._include(e),SS[e]}_include(e){const t=vS[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${AS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r,n,i=0,o=0){const a=s+"Struct",u=this._getWGSLStruct(a,r);if(e){return`${u}\n@binding( ${i} ) @group( ${o} )\nvar<${n}> ${s} : ${t?`array<${a}>`:a};`}return`${u}\n@binding( ${i} ) @group( ${o} )\nvar<${n}> ${s} : ${a};`}}class CS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=ly.Depth24PlusStencil8:e.depth&&(t=ly.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?kf:e.isLineSegments||e.isMesh&&!0===t.wireframe?zf:e.isLine?$f:e.isMesh?Hf:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?ly.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const ES=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),wS=new Map([[Ie,["float16"]]]),MS=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class BS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,n=r.get(s);let i=n.buffer;if(void 0===i){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[s]===r&&(a=o.groups[s])),void 0===a&&(a=this.createBindGroup(e,u),s>0&&(o.groups[s]=a,o.versions[s]=r)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,n=t.get(e).buffer;s.queue.writeBuffer(n,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let n=0;const i=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,n=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,i=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:n});e.buffer=i}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);i.push({binding:n,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const n=nb;let i;i=t.isSampledCubeTexture?sb:t.isSampledTexture3D?rb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?tb:eb,o=e[r]=e.texture.createView({aspect:n,dimension:i,mipLevelCount:s})}}i.push({binding:n,resource:o})}n++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:i})}}class FS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:n,pipeline:i}=e,{vertexProgram:o,fragmentProgram:a}=i,u=this.backend,l=u.device,d=u.utils,c=u.get(i),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,n=s.getCurrentDepthStencilFormat(e),i={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:n,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(i)}createComputePipeline(e,t){const s=this.backend,r=s.device,n=s.get(e.computeProgram).module,i=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}i.pipeline=r.createComputePipeline({compute:n,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,n=e.blendSrc,i=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:n,a=null!==e.blendDstAlpha?e.blendDstAlpha:i,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(n),dstFactor:this._getBlendFactor(i),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const n=(e,r,n,i)=>{t={srcFactor:e,dstFactor:r,operation:Ey},s={srcFactor:n,dstFactor:i,operation:Ey}};if(e.premultipliedAlpha)switch(r){case F:n(fy,Ty,fy,Ty);break;case bt:n(fy,fy,fy,fy);break;case yt:n(my,by,my,fy);break;case ft:n(my,yy,my,xy)}else switch(r){case F:n(xy,Ty,fy,Ty);break;case bt:n(xy,fy,xy,fy);break;case yt:n(my,by,my,fy);break;case ft:n(my,yy,my,yy)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=my;break;case st:t=fy;break;case rt:t=yy;break;case ut:t=by;break;case nt:t=xy;break;case lt:t=Ty;break;case ot:t=_y;break;case dt:t=Ny;break;case at:t=vy;break;case ct:t=Sy;break;case it:t=Ay;break;case 211:t=Ry;break;case 212:t=Cy;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=jf;break;case Es:t=Jf;break;case Cs:t=qf;break;case Rs:t=Xf;break;case As:t=Kf;break;case Ss:t=Zf;break;case vs:t=Yf;break;case Ns:t=Qf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Iy;break;case Ls:t=Ly;break;case Is:t=Dy;break;case Ps:t=Vy;break;case Fs:t=Oy;break;case Us:t=Gy;break;case Bs:t=ky;break;case Ms:t=zy;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Ey;break;case Je:t=wy;break;case et:t=My;break;case Os:t=By;break;case Vs:t=Uy;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},n=this.backend.utils;switch(r.topology=n.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?ay:uy),s.side){case Oe:r.frontFace=ry,r.cullMode=oy;break;case x:r.frontFace=ry,r.cullMode=iy;break;case le:r.frontFace=ry,r.cullMode=ny;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Py:Fy}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Jf;else{const s=e.depthFunc;switch(s){case Rt:t=jf;break;case At:t=Jf;break;case St:t=qf;break;case vt:t=Xf;break;case Nt:t=Kf;break;case _t:t=Zf;break;case Tt:t=Yf;break;case xt:t=Qf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class PS extends Lv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new CS(this),this.attributeUtils=new BS(this),this.bindingUtils=new US(this),this.pipelineUtils=new FS(this),this.textureUtils=new lS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const n=Object.values(ab),i=[];for(const e of n)r.features.has(e)&&i.push(e);const o={requiredFeatures:i,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const n=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ab.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:n}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const n=e.getCacheKey();let i=r[n];if(void 0===i){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,n=s.createQuerySet({type:"occlusion",count:r,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=n,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),i=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,i),i.occlusionQuerySet=n;const o=i.depthStencilAttachment;if(null!==e.textures){const t=i.colorAttachments;for(let s=0;s0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const r=8*s;let n=this.occludedResolveCache.get(r);void 0===n&&(n=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,n));const i=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,n,0),t.encoder.copyBufferToBuffer(n,0,i,0,r),t.occlusionQueryBuffer=i,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,n.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:r,pipeline:n}=e,i=e.getBindings(),o=this.get(r),a=this.get(n).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=i.length;e1?0:s;l.drawIndexed(t[s],r,e[s]/i,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,n,i,0,0);t.update(s,r,n)}else{const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,n,i,0);t.update(s,r,n)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,n=this.utils,i=n.getSampleCountRenderContext(e.context),o=n.getCurrentColorSpace(e.context),a=n.getCurrentColorFormat(e.context),u=n.getCurrentDepthStencilFormat(e.context),l=n.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===i&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=i,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,n=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,r.getSampleCountRenderContext(n),r.getCurrentColorSpace(n),r.getCurrentColorFormat(n),r.getCurrentDepthStencilFormat(n),r.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}async initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){this.device.pushErrorScope("out-of-memory");const r=await this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_renderContext_${e.id}`});if(await this.device.popErrorScope())return s.attemptingTimeStampQuerySetFailed||(console.error(`[GPUOutOfMemoryError][renderContext_${e.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.`),s.attemptingTimeStampQuerySetFailed=!0),void(s.timeStampQuerySet=null);const n={querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:n}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;const r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:n,resultBuffer:i,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,n,0),t.copyBufferToBuffer(n,0,i,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:n}=s.currentTimestampQueryBuffers;!0!==n&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),n=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,n),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new RS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,r=null,n=0){let i=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(i=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:n,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:n,origin:{x:i,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let n=null;n=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const i=this.get(e).texture;if(n.format!==i.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,i.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:n,origin:{x:s.x,y:s.y,z:0}},{texture:i},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new eS(e)));super(new t(e),e),this.library=new LS,this.isWebGPURenderer=!0}}class VS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const OS=new nh,GS=new _f(OS);class kS{constructor(e,t=Ln(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,OS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,GS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;GS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),GS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await GS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function zS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function $S(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function HS(e,t,s={}){return(s=zS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var WS=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=HS(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=zS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){$S(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:$S,saveRendererAndSceneState:HS,saveRendererState:zS});class jS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class qS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class KS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class XS extends qS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class YS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const n=new tr(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),Sn()):hn(new this.nodes[e])}}class QS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const n=r[e];t[e]=s[n]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class ZS extends rr{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new YS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),n=new QS;n.setTextures(t),n.setNodes(r),n.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t0){const{width:s,height:r}=e.context;t.bufferWidth=s,t.bufferHeight=r}this.renderObjects.set(e,t)}return t}getAttributesData(e){const t={};for(const s in e){const r=e[s];t[s]={version:r.version}}return t}containsNode(e){const t=e.material;for(const e in t)if(t[e]&&t[e].isNode)return!0;return null!==e.renderer.nodes.modelViewMatrix||null!==e.renderer.nodes.modelNormalViewMatrix}getMaterialData(e){const t={};for(const s of this.refreshUniforms){const r=e[s];null!=r&&("object"==typeof r&&void 0!==r.clone?!0===r.isTexture?t[s]={id:r.id,version:r.version}:t[s]=r.clone():t[s]=r)}return t}equals(e){const{object:t,material:s,geometry:r}=e,n=this.getRenderObjectData(e);if(!0!==n.worldMatrix.equals(t.matrixWorld))return n.worldMatrix.copy(t.matrixWorld),!1;const i=n.material;for(const e in i){const t=i[e],r=s[e];if(void 0!==t.equals){if(!1===t.equals(r))return t.copy(r),!1}else if(!0===r.isTexture){if(t.id!==r.id||t.version!==r.version)return t.id=r.id,t.version=r.version,!1}else if(t!==r)return i[e]=r,!1}if(i.transmission>0){const{width:t,height:s}=e.context;if(n.bufferWidth!==t||n.bufferHeight!==s)return n.bufferWidth=t,n.bufferHeight=s,!1}const o=n.geometry,a=r.attributes,u=o.attributes,l=Object.keys(u),d=Object.keys(a);if(l.length!==d.length)return n.geometry.attributes=this.getAttributesData(a),!1;for(const e of l){const t=u[e],s=a[e];if(void 0===s)return delete u[e],!1;if(t.version!==s.version)return t.version=s.version,!1}const c=r.index,h=o.indexVersion,p=c?c.version:null;if(h!==p)return o.indexVersion=p,!1;if(o.drawRange.start!==r.drawRange.start||o.drawRange.count!==r.drawRange.count)return o.drawRange.start=r.drawRange.start,o.drawRange.count=r.drawRange.count,!1;if(n.morphTargetInfluences){let e=!1;for(let s=0;s>>16,2246822507),s^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(s^s>>>13,3266489909),4294967296*(2097151&r)+(s>>>0)}const ar=e=>or(e),ur=e=>or(e),lr=(...e)=>or(e);function dr(e,t=!1){const s=[];!0===e.isNode&&(s.push(e.id),e=e.getSelf());for(const{property:r,childNode:n}of cr(e))s.push(s,or(r.slice(0,-4)),n.getCacheKey(t));return or(s)}function*cr(e,t=!1){for(const s in e){if(!0===s.startsWith("_"))continue;const r=e[s];if(!0===Array.isArray(r))for(let e=0;ee.charCodeAt(0))).buffer}var fr=Object.freeze({__proto__:null,arrayBufferToBase64:gr,base64ToArrayBuffer:mr,getCacheKey:dr,getNodeChildren:cr,getValueFromType:pr,getValueType:hr,hash:lr,hashArray:ur,hashString:ar});const yr={VERTEX:"vertex",FRAGMENT:"fragment"},br={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},xr={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Tr=["fragment","vertex"],_r=["setup","analyze","generate"],Nr=[...Tr,"compute"],vr=["x","y","z","w"];let Sr=0;class Ar extends o{static get type(){return"Node"}constructor(e=null){super(),this.nodeType=e,this.updateType=br.NONE,this.updateBeforeType=br.NONE,this.updateAfterType=br.NONE,this.uuid=a.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:Sr++})}set needsUpdate(e){!0===e&&this.version++}get type(){return this.constructor.type}onUpdate(e,t){return this.updateType=t,this.update=e.bind(this.getSelf()),this}onFrameUpdate(e){return this.onUpdate(e,br.FRAME)}onRenderUpdate(e){return this.onUpdate(e,br.RENDER)}onObjectUpdate(e){return this.onUpdate(e,br.OBJECT)}onReference(e){return this.updateReference=e.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:e}of cr(this))yield e}dispose(){this.dispatchEvent({type:"dispose"})}traverse(e){e(this);for(const t of this.getChildren())t.traverse(e)}getCacheKey(e=!1){return!0!==(e=e||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=dr(this,e),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(e){const t=this.getNodeType(e);return e.getElementType(t)}getNodeType(e){const t=e.getNodeProperties(this);return t.outputNode?t.outputNode.getNodeType(e):this.nodeType}getShared(e){const t=this.getHash(e);return e.getNodeFromHash(t)||this}setup(e){const t=e.getNodeProperties(this);let s=0;for(const e of this.getChildren())t["node"+s++]=e;return null}analyze(e){if(1===e.increaseUsage(this)){const t=e.getNodeProperties(this);for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}generate(e,t){const{outputNode:s}=e.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(e,t)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(e,t=null){const s=this.getShared(e);if(this!==s)return s.build(e,t);e.addNode(this),e.addChain(this);let r=null;const n=e.getBuildStage();if("setup"===n){this.updateReference(e);const t=e.getNodeProperties(this);if(!0!==t.initialized){e.stack.nodes.length;t.initialized=!0,t.outputNode=this.setup(e),null!==t.outputNode&&e.stack.nodes.length;for(const s of Object.values(t))s&&!0===s.isNode&&s.build(e)}}else if("analyze"===n)this.analyze(e);else if("generate"===n){if(1===this.generate.length){const s=this.getNodeType(e),n=e.getDataFromNode(this);r=n.snippet,void 0===r?(r=this.generate(e)||"",n.snippet=r):void 0!==n.flowCodes&&void 0!==e.context.nodeBlock&&e.addFlowCodeHierarchy(this,e.context.nodeBlock),r=e.format(r,s,t)}else r=this.generate(e,t)||""}return e.removeChain(this),e.addSequentialNode(this),r}getSerializeChildren(){return cr(this)}serialize(e){const t=this.getSerializeChildren(),s={};for(const{property:r,index:n,childNode:i}of t)void 0!==n?(void 0===s[r]&&(s[r]=Number.isInteger(n)?[]:{}),s[r][n]=i.toJSON(e.meta).uuid):s[r]=i.toJSON(e.meta).uuid;Object.keys(s).length>0&&(e.inputNodes=s)}deserialize(e){if(void 0!==e.inputNodes){const t=e.meta.nodes;for(const s in e.inputNodes)if(Array.isArray(e.inputNodes[s])){const r=[];for(const n of e.inputNodes[s])r.push(t[n]);this[s]=r}else if("object"==typeof e.inputNodes[s]){const r={};for(const n in e.inputNodes[s]){const i=e.inputNodes[s][n];r[n]=t[i]}this[s]=r}else{const r=e.inputNodes[s];this[s]=t[r]}}}toJSON(e){const{uuid:t,type:s}=this,r=void 0===e||"string"==typeof e;r&&(e={textures:{},images:{},nodes:{}});let n=e.nodes[t];function i(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(void 0===n&&(n={uuid:t,type:s,meta:e,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==r&&(e.nodes[n.uuid]=n),this.serialize(n),delete n.meta),r){const t=i(e.textures),s=i(e.images),r=i(e.nodes);t.length>0&&(n.textures=t),s.length>0&&(n.images=s),r.length>0&&(n.nodes=r)}return n}}class Rr extends Ar{static get type(){return"ArrayElementNode"}constructor(e,t){super(),this.node=e,this.indexNode=t,this.isArrayElementNode=!0}getNodeType(e){return this.node.getElementType(e)}generate(e){return`${this.node.build(e)}[ ${this.indexNode.build(e,"uint")} ]`}}class Cr extends Ar{static get type(){return"ConvertNode"}constructor(e,t){super(),this.node=e,this.convertTo=t}getNodeType(e){const t=this.node.getNodeType(e);let s=null;for(const r of this.convertTo.split("|"))null!==s&&e.getTypeLength(t)!==e.getTypeLength(r)||(s=r);return s}serialize(e){super.serialize(e),e.convertTo=this.convertTo}deserialize(e){super.deserialize(e),this.convertTo=e.convertTo}generate(e,t){const s=this.node,r=this.getNodeType(e),n=s.build(e,r);return e.format(n,r,t)}}class Er extends Ar{static get type(){return"TempNode"}constructor(e){super(e),this.isTempNode=!0}hasDependencies(e){return e.getDataFromNode(this).usageCount>1}build(e,t){if("generate"===e.getBuildStage()){const s=e.getVectorType(this.getNodeType(e,t)),r=e.getDataFromNode(this);if(void 0!==r.propertyName)return e.format(r.propertyName,s,t);if("void"!==s&&"void"!==t&&this.hasDependencies(e)){const n=super.build(e,s),i=e.getVarFromNode(this,null,s),o=e.getPropertyName(i);return e.addLineFlowCode(`${o} = ${n}`,this),r.snippet=n,r.propertyName=o,e.format(r.propertyName,s,t)}}return super.build(e,t)}}class wr extends Er{static get type(){return"JoinNode"}constructor(e=[],t=null){super(t),this.nodes=e}getNodeType(e){return null!==this.nodeType?e.getVectorType(this.nodeType):e.getTypeFromLength(this.nodes.reduce(((t,s)=>t+e.getTypeLength(s.getNodeType(e))),0))}generate(e,t){const s=this.getNodeType(e),r=this.nodes,n=e.getComponentType(s),i=[];for(const t of r){let s=t.build(e);const r=e.getComponentType(t.getNodeType(e));r!==n&&(s=e.format(s,r,n)),i.push(s)}const o=`${e.getType(s)}( ${i.join(", ")} )`;return e.format(o,s,t)}}const Mr=vr.join("");class Br extends Ar{static get type(){return"SplitNode"}constructor(e,t="x"){super(),this.node=e,this.components=t,this.isSplitNode=!0}getVectorLength(){let e=this.components.length;for(const t of this.components)e=Math.max(vr.indexOf(t)+1,e);return e}getComponentType(e){return e.getComponentType(this.node.getNodeType(e))}getNodeType(e){return e.getTypeFromLength(this.components.length,this.getComponentType(e))}generate(e,t){const s=this.node,r=e.getTypeLength(s.getNodeType(e));let n=null;if(r>1){let i=null;this.getVectorLength()>=r&&(i=e.getTypeFromLength(this.getVectorLength(),this.getComponentType(e)));const o=s.build(e,i);n=this.components.length===r&&this.components===Mr.slice(0,this.components.length)?e.format(o,i,t):e.format(`${o}.${this.components}`,this.getNodeType(e),t)}else n=s.build(e,t);return n}serialize(e){super.serialize(e),e.components=this.components}deserialize(e){super.deserialize(e),this.components=e.components}}class Ur extends Er{static get type(){return"SetNode"}constructor(e,t,s){super(),this.sourceNode=e,this.components=t,this.targetNode=s}getNodeType(e){return this.sourceNode.getNodeType(e)}generate(e){const{sourceNode:t,components:s,targetNode:r}=this,n=this.getNodeType(e),i=e.getTypeFromLength(s.length,r.getNodeType(e)),o=r.build(e,i),a=t.build(e,n),u=e.getTypeLength(n),l=[];for(let e=0;ee.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Gr=e=>Or(e).split("").sort().join(""),kr={setup(e,t){const s=t.shift();return e(pn(s),...t)},get(e,t,s){if("string"==typeof t&&void 0===e[t]){if(!0!==e.isStackNode&&"assign"===t)return(...e)=>(Lr.assign(s,...e),s);if(Dr.has(t)){const r=Dr.get(t);return e.isStackNode?(...e)=>s.add(r(...e)):(...e)=>r(s,...e)}if("self"===t)return e;if(t.endsWith("Assign")&&Dr.has(t.slice(0,t.length-6))){const r=Dr.get(t.slice(0,t.length-6));return e.isStackNode?(...e)=>s.assign(e[0],r(...e)):(...e)=>s.assign(r(s,...e))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(t))return t=Or(t),hn(new Br(s,t));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(3).toLowerCase()),s=>hn(new Ur(e,t,s));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(t))return t=Gr(t.slice(4).toLowerCase()),()=>hn(new Fr(hn(e),t));if("width"===t||"height"===t||"depth"===t)return"width"===t?t="x":"height"===t?t="y":"depth"===t&&(t="z"),hn(new Br(e,t));if(!0===/^\d+$/.test(t))return hn(new Rr(s,new Ir(Number(t),"uint")))}return Reflect.get(e,t,s)},set:(e,t,s,r)=>"string"!=typeof t||void 0!==e[t]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(t)&&"width"!==t&&"height"!==t&&"depth"!==t&&!0!==/^\d+$/.test(t)?Reflect.set(e,t,s,r):(r[t].assign(s),!0)},zr=new WeakMap,$r=new WeakMap,Hr=function(e,t=null){for(const s in e)e[s]=hn(e[s],t);return e},Wr=function(e,t=null){const s=e.length;for(let r=0;rhn(null!==r?Object.assign(e,r):e);return null===t?(...t)=>n(new e(...gn(t))):null!==s?(s=hn(s),(...r)=>n(new e(t,...gn(r),s))):(...s)=>n(new e(t,...gn(s)))},qr=function(e,...t){return hn(new e(...gn(t)))};class Kr extends Ar{constructor(e,t){super(),this.shaderNode=e,this.inputNodes=t}getNodeType(e){return this.shaderNode.nodeType||this.getOutputNode(e).getNodeType(e)}call(e){const{shaderNode:t,inputNodes:s}=this,r=e.getNodeProperties(t);if(r.onceOutput)return r.onceOutput;let n=null;if(t.layout){let r=$r.get(e.constructor);void 0===r&&(r=new WeakMap,$r.set(e.constructor,r));let i=r.get(t);void 0===i&&(i=hn(e.buildFunctionNode(t)),r.set(t,i)),null!==e.currentFunctionNode&&e.currentFunctionNode.includes.push(i),n=hn(i.call(s))}else{const r=t.jsFunc,i=null!==s?r(s,e):r(e);n=hn(i)}return t.once&&(r.onceOutput=n),n}getOutputNode(e){const t=e.getNodeProperties(this);return null===t.outputNode&&(t.outputNode=this.setupOutput(e)),t.outputNode}setup(e){return this.getOutputNode(e)}setupOutput(e){return e.addStack(),e.stack.outputNode=this.call(e),e.removeStack()}generate(e,t){return this.getOutputNode(e).build(e,t)}}class Xr extends Ar{constructor(e,t){super(t),this.jsFunc=e,this.layout=null,this.global=!0,this.once=!1}setLayout(e){return this.layout=e,this}call(e=null){return pn(e),hn(new Kr(this,e))}setup(){return this.call()}}const Yr=[!1,!0],Qr=[0,1,2,3],Zr=[-1,-2],Jr=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],en=new Map;for(const e of Yr)en.set(e,new Ir(e));const tn=new Map;for(const e of Qr)tn.set(e,new Ir(e,"uint"));const sn=new Map([...tn].map((e=>new Ir(e.value,"int"))));for(const e of Zr)sn.set(e,new Ir(e,"int"));const rn=new Map([...sn].map((e=>new Ir(e.value))));for(const e of Jr)rn.set(e,new Ir(e));for(const e of Jr)rn.set(-e,new Ir(-e));const nn={bool:en,uint:tn,ints:sn,float:rn},on=new Map([...en,...rn]),an=(e,t)=>on.has(e)?on.get(e):!0===e.isNode?e:new Ir(e,t),un=function(e,t=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(e)&&s.every((e=>"object"!=typeof e)))&&(s=[pr(e,...s)]),1===s.length&&null!==t&&t.has(s[0]))return hn(t.get(s[0]));if(1===s.length){const t=an(s[0],e);return(e=>{try{return e.getNodeType()}catch(e){return}})(t)===e?hn(t):hn(new Cr(t,e))}const r=s.map((e=>an(e)));return hn(new wr(r,e))}},ln=e=>"object"==typeof e&&null!==e?e.value:e,dn=e=>null!=e?e.nodeType||e.convertTo||("string"==typeof e?e:null):null;function cn(e,t){return new Proxy(new Xr(e,t),kr)}const hn=(e,t=null)=>function(e,t=null){const s=hr(e);if("node"===s){let t=zr.get(e);return void 0===t&&(t=new Proxy(e,kr),zr.set(e,t),zr.set(t,t)),t}return null===t&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?hn(an(e,t)):"shader"===s?yn(e):e}(e,t),pn=(e,t=null)=>new Hr(e,t),gn=(e,t=null)=>new Wr(e,t),mn=(...e)=>new jr(...e),fn=(...e)=>new qr(...e),yn=(e,t)=>{const s=new cn(e,t),r=(...e)=>{let t;return pn(e),t=e[0]&&e[0].isNode?[...e]:e[0],s.call(t)};return r.shaderNode=s,r.setLayout=e=>(s.setLayout(e),r),r.once=()=>(s.once=!0,r),r},bn=(...e)=>(console.warn("TSL.ShaderNode: tslFn() has been renamed to Fn()."),yn(...e));Vr("toGlobal",(e=>(e.global=!0,e)));const xn=e=>{Lr=e},Tn=()=>Lr,_n=(...e)=>Lr.If(...e);function Nn(e){return Lr&&Lr.add(e),e}Vr("append",Nn);const vn=new un("color"),Sn=new un("float",nn.float),An=new un("int",nn.ints),Rn=new un("uint",nn.uint),Cn=new un("bool",nn.bool),En=new un("vec2"),wn=new un("ivec2"),Mn=new un("uvec2"),Bn=new un("bvec2"),Un=new un("vec3"),Fn=new un("ivec3"),Pn=new un("uvec3"),In=new un("bvec3"),Ln=new un("vec4"),Dn=new un("ivec4"),Vn=new un("uvec4"),On=new un("bvec4"),Gn=new un("mat2"),kn=new un("mat3"),zn=new un("mat4"),$n=(e="")=>hn(new Ir(e,"string")),Hn=e=>hn(new Ir(e,"ArrayBuffer"));Vr("toColor",vn),Vr("toFloat",Sn),Vr("toInt",An),Vr("toUint",Rn),Vr("toBool",Cn),Vr("toVec2",En),Vr("toIVec2",wn),Vr("toUVec2",Mn),Vr("toBVec2",Bn),Vr("toVec3",Un),Vr("toIVec3",Fn),Vr("toUVec3",Pn),Vr("toBVec3",In),Vr("toVec4",Ln),Vr("toIVec4",Dn),Vr("toUVec4",Vn),Vr("toBVec4",On),Vr("toMat2",Gn),Vr("toMat3",kn),Vr("toMat4",zn);const Wn=mn(Rr),jn=(e,t)=>hn(new Cr(hn(e),t)),qn=(e,t)=>hn(new Br(hn(e),t));Vr("element",Wn),Vr("convert",jn);class Kn extends Ar{static get type(){return"UniformGroupNode"}constructor(e,t=!1,s=1){super("string"),this.name=e,this.version=0,this.shared=t,this.order=s,this.isUniformGroup=!0}set needsUpdate(e){!0===e&&this.version++}serialize(e){super.serialize(e),e.name=this.name,e.version=this.version,e.shared=this.shared}deserialize(e){super.deserialize(e),this.name=e.name,this.version=e.version,this.shared=e.shared}}const Xn=e=>new Kn(e),Yn=(e,t=0)=>new Kn(e,!0,t),Qn=Yn("frame"),Zn=Yn("render"),Jn=Xn("object");class ei extends Pr{static get type(){return"UniformNode"}constructor(e,t=null){super(e,t),this.isUniformNode=!0,this.name="",this.groupNode=Jn}label(e){return this.name=e,this}setGroup(e){return this.groupNode=e,this}getGroup(){return this.groupNode}getUniformHash(e){return this.getHash(e)}onUpdate(e,t){const s=this.getSelf();return e=e.bind(s),super.onUpdate((t=>{const r=e(t,s);void 0!==r&&(this.value=r)}),t)}generate(e,t){const s=this.getNodeType(e),r=this.getUniformHash(e);let n=e.getNodeFromHash(r);void 0===n&&(e.setHashNode(this,r),n=this);const i=n.getInputType(e),o=e.getUniformFromNode(n,i,e.shaderStage,this.name||e.context.label),a=e.getPropertyName(o);return void 0!==e.context.label&&delete e.context.label,e.format(a,s,t)}}const ti=(e,t)=>{const s=dn(t||e),r=e&&!0===e.isNode?e.node&&e.node.value||e.value:e;return hn(new ei(r,s))};class si extends Ar{static get type(){return"PropertyNode"}constructor(e,t=null,s=!1){super(e),this.name=t,this.varying=s,this.isPropertyNode=!0}getHash(e){return this.name||super.getHash(e)}isGlobal(){return!0}generate(e){let t;return!0===this.varying?(t=e.getVaryingFromNode(this,this.name),t.needsInterpolation=!0):t=e.getVarFromNode(this,this.name),e.getPropertyName(t)}}const ri=(e,t)=>hn(new si(e,t)),ni=(e,t)=>hn(new si(e,t,!0)),ii=fn(si,"vec4","DiffuseColor"),oi=fn(si,"vec3","EmissiveColor"),ai=fn(si,"float","Roughness"),ui=fn(si,"float","Metalness"),li=fn(si,"float","Clearcoat"),di=fn(si,"float","ClearcoatRoughness"),ci=fn(si,"vec3","Sheen"),hi=fn(si,"float","SheenRoughness"),pi=fn(si,"float","Iridescence"),gi=fn(si,"float","IridescenceIOR"),mi=fn(si,"float","IridescenceThickness"),fi=fn(si,"float","AlphaT"),yi=fn(si,"float","Anisotropy"),bi=fn(si,"vec3","AnisotropyT"),xi=fn(si,"vec3","AnisotropyB"),Ti=fn(si,"color","SpecularColor"),_i=fn(si,"float","SpecularF90"),Ni=fn(si,"float","Shininess"),vi=fn(si,"vec4","Output"),Si=fn(si,"float","dashSize"),Ai=fn(si,"float","gapSize"),Ri=fn(si,"float","pointWidth"),Ci=fn(si,"float","IOR"),Ei=fn(si,"float","Transmission"),wi=fn(si,"float","Thickness"),Mi=fn(si,"float","AttenuationDistance"),Bi=fn(si,"color","AttenuationColor"),Ui=fn(si,"float","Dispersion");class Fi extends Er{static get type(){return"AssignNode"}constructor(e,t){super(),this.targetNode=e,this.sourceNode=t}hasDependencies(){return!1}getNodeType(e,t){return"void"!==t?this.targetNode.getNodeType(e):"void"}needsSplitAssign(e){const{targetNode:t}=this;if(!1===e.isAvailable("swizzleAssign")&&t.isSplitNode&&t.components.length>1){const s=e.getTypeLength(t.node.getNodeType(e));return vr.join("").slice(0,s)!==t.components}return!1}generate(e,t){const{targetNode:s,sourceNode:r}=this,n=this.needsSplitAssign(e),i=s.getNodeType(e),o=s.context({assign:!0}).build(e),a=r.build(e,i),u=r.getNodeType(e),l=e.getDataFromNode(this);let d;if(!0===l.initialized)"void"!==t&&(d=o);else if(n){const r=e.getVarFromNode(this,null,i),n=e.getPropertyName(r);e.addLineFlowCode(`${n} = ${a}`,this);const u=s.node.context({assign:!0}).build(e);for(let t=0;t{const r=s.type;let n;return n="pointer"===r?"&"+t.build(e):t.build(e,r),n};if(Array.isArray(n))for(let e=0;e(t=t.length>1||t[0]&&!0===t[0].isNode?gn(t):pn(t[0]),hn(new Ii(hn(e),t)));Vr("call",Li);class Di extends Er{static get type(){return"OperatorNode"}constructor(e,t,s,...r){if(super(),r.length>0){let n=new Di(e,t,s);for(let t=0;t>"===s||"<<"===s)return e.getIntegerType(i);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=t?e.getTypeLength(t):Math.max(e.getTypeLength(i),e.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===i&&e.isMatrix(o)?o:e.isMatrix(i)&&e.isVector(o)?e.getVectorFromMatrix(i):e.isVector(i)&&e.isMatrix(o)?e.getVectorFromMatrix(o):e.getTypeLength(o)>e.getTypeLength(i)?o:i}generate(e,t){const s=this.op,r=this.aNode,n=this.bNode,i=this.getNodeType(e,t);let o=null,a=null;"void"!==i?(o=r.getNodeType(e),a=void 0!==n?n.getNodeType(e):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?e.isVector(o)?a=o:o!==a&&(o=a="float"):">>"===s||"<<"===s?(o=i,a=e.changeComponentType(a,"uint")):e.isMatrix(o)&&e.isVector(a)?a=e.getVectorFromMatrix(o):o=e.isVector(o)&&e.isMatrix(a)?e.getVectorFromMatrix(a):a=i):o=a=i;const u=r.build(e,o),l=void 0!==n?n.build(e,a):null,d=e.getTypeLength(t),c=e.getFunctionOperator(s);return"void"!==t?"<"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} < ${l} )`,i,t):"<="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("lessThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} <= ${l} )`,i,t):">"===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThan",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} > ${l} )`,i,t):">="===s&&d>1?e.useComparisonMethod?e.format(`${e.getMethod("greaterThanEqual",t)}( ${u}, ${l} )`,i,t):e.format(`( ${u} >= ${l} )`,i,t):"!"===s||"~"===s?e.format(`(${s}${u})`,o,t):c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`( ${u} ${s} ${l} )`,i,t):"void"!==o?c?e.format(`${c}( ${u}, ${l} )`,i,t):e.format(`${u} ${s} ${l}`,i,t):void 0}serialize(e){super.serialize(e),e.op=this.op}deserialize(e){super.deserialize(e),this.op=e.op}}const Vi=mn(Di,"+"),Oi=mn(Di,"-"),Gi=mn(Di,"*"),ki=mn(Di,"/"),zi=mn(Di,"%"),$i=mn(Di,"=="),Hi=mn(Di,"!="),Wi=mn(Di,"<"),ji=mn(Di,">"),qi=mn(Di,"<="),Ki=mn(Di,">="),Xi=mn(Di,"&&"),Yi=mn(Di,"||"),Qi=mn(Di,"!"),Zi=mn(Di,"^^"),Ji=mn(Di,"&"),eo=mn(Di,"~"),to=mn(Di,"|"),so=mn(Di,"^"),ro=mn(Di,"<<"),no=mn(Di,">>");Vr("add",Vi),Vr("sub",Oi),Vr("mul",Gi),Vr("div",ki),Vr("modInt",zi),Vr("equal",$i),Vr("notEqual",Hi),Vr("lessThan",Wi),Vr("greaterThan",ji),Vr("lessThanEqual",qi),Vr("greaterThanEqual",Ki),Vr("and",Xi),Vr("or",Yi),Vr("not",Qi),Vr("xor",Zi),Vr("bitAnd",Ji),Vr("bitNot",eo),Vr("bitOr",to),Vr("bitXor",so),Vr("shiftLeft",ro),Vr("shiftRight",no);const io=(...e)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),zi(...e));Vr("remainder",io);class oo extends Er{static get type(){return"MathNode"}constructor(e,t,s=null,r=null){super(),this.method=e,this.aNode=t,this.bNode=s,this.cNode=r}getInputType(e){const t=this.aNode.getNodeType(e),s=this.bNode?this.bNode.getNodeType(e):null,r=this.cNode?this.cNode.getNodeType(e):null,n=e.isMatrix(t)?0:e.getTypeLength(t),i=e.isMatrix(s)?0:e.getTypeLength(s),o=e.isMatrix(r)?0:e.getTypeLength(r);return n>i&&n>o?t:i>o?s:o>n?r:t}getNodeType(e){const t=this.method;return t===oo.LENGTH||t===oo.DISTANCE||t===oo.DOT?"float":t===oo.CROSS?"vec3":t===oo.ALL?"bool":t===oo.EQUALS?e.changeComponentType(this.aNode.getNodeType(e),"bool"):t===oo.MOD?this.aNode.getNodeType(e):this.getInputType(e)}generate(e,t){const s=this.method,r=this.getNodeType(e),n=this.getInputType(e),i=this.aNode,o=this.bNode,a=this.cNode,u=!0===e.renderer.isWebGLRenderer;if(s===oo.TRANSFORM_DIRECTION){let s=i,r=o;e.isMatrix(s.getNodeType(e))?r=Ln(Un(r),0):s=Ln(Un(s),0);const n=Gi(s,r).xyz;return Ao(n).build(e,t)}if(s===oo.NEGATE)return e.format("( - "+i.build(e,n)+" )",r,t);if(s===oo.ONE_MINUS)return Oi(1,i).build(e,t);if(s===oo.RECIPROCAL)return ki(1,i).build(e,t);if(s===oo.DIFFERENCE)return Fo(Oi(i,o)).build(e,t);{const l=[];return s===oo.CROSS||s===oo.MOD?l.push(i.build(e,r),o.build(e,r)):u&&s===oo.STEP?l.push(i.build(e,1===e.getTypeLength(i.getNodeType(e))?"float":n),o.build(e,n)):u&&(s===oo.MIN||s===oo.MAX)||s===oo.MOD?l.push(i.build(e,n),o.build(e,1===e.getTypeLength(o.getNodeType(e))?"float":n)):s===oo.REFRACT?l.push(i.build(e,n),o.build(e,n),a.build(e,"float")):s===oo.MIX?l.push(i.build(e,n),o.build(e,n),a.build(e,1===e.getTypeLength(a.getNodeType(e))?"float":n)):(l.push(i.build(e,n)),null!==o&&l.push(o.build(e,n)),null!==a&&l.push(a.build(e,n))),e.format(`${e.getMethod(s,r)}( ${l.join(", ")} )`,r,t)}}serialize(e){super.serialize(e),e.method=this.method}deserialize(e){super.deserialize(e),this.method=e.method}}oo.ALL="all",oo.ANY="any",oo.EQUALS="equals",oo.RADIANS="radians",oo.DEGREES="degrees",oo.EXP="exp",oo.EXP2="exp2",oo.LOG="log",oo.LOG2="log2",oo.SQRT="sqrt",oo.INVERSE_SQRT="inversesqrt",oo.FLOOR="floor",oo.CEIL="ceil",oo.NORMALIZE="normalize",oo.FRACT="fract",oo.SIN="sin",oo.COS="cos",oo.TAN="tan",oo.ASIN="asin",oo.ACOS="acos",oo.ATAN="atan",oo.ABS="abs",oo.SIGN="sign",oo.LENGTH="length",oo.NEGATE="negate",oo.ONE_MINUS="oneMinus",oo.DFDX="dFdx",oo.DFDY="dFdy",oo.ROUND="round",oo.RECIPROCAL="reciprocal",oo.TRUNC="trunc",oo.FWIDTH="fwidth",oo.BITCAST="bitcast",oo.TRANSPOSE="transpose",oo.ATAN2="atan2",oo.MIN="min",oo.MAX="max",oo.MOD="mod",oo.STEP="step",oo.REFLECT="reflect",oo.DISTANCE="distance",oo.DIFFERENCE="difference",oo.DOT="dot",oo.CROSS="cross",oo.POW="pow",oo.TRANSFORM_DIRECTION="transformDirection",oo.MIX="mix",oo.CLAMP="clamp",oo.REFRACT="refract",oo.SMOOTHSTEP="smoothstep",oo.FACEFORWARD="faceforward";const ao=Sn(1e-6),uo=Sn(1e6),lo=Sn(Math.PI),co=Sn(2*Math.PI),ho=mn(oo,oo.ALL),po=mn(oo,oo.ANY),go=mn(oo,oo.EQUALS),mo=mn(oo,oo.RADIANS),fo=mn(oo,oo.DEGREES),yo=mn(oo,oo.EXP),bo=mn(oo,oo.EXP2),xo=mn(oo,oo.LOG),To=mn(oo,oo.LOG2),_o=mn(oo,oo.SQRT),No=mn(oo,oo.INVERSE_SQRT),vo=mn(oo,oo.FLOOR),So=mn(oo,oo.CEIL),Ao=mn(oo,oo.NORMALIZE),Ro=mn(oo,oo.FRACT),Co=mn(oo,oo.SIN),Eo=mn(oo,oo.COS),wo=mn(oo,oo.TAN),Mo=mn(oo,oo.ASIN),Bo=mn(oo,oo.ACOS),Uo=mn(oo,oo.ATAN),Fo=mn(oo,oo.ABS),Po=mn(oo,oo.SIGN),Io=mn(oo,oo.LENGTH),Lo=mn(oo,oo.NEGATE),Do=mn(oo,oo.ONE_MINUS),Vo=mn(oo,oo.DFDX),Oo=mn(oo,oo.DFDY),Go=mn(oo,oo.ROUND),ko=mn(oo,oo.RECIPROCAL),zo=mn(oo,oo.TRUNC),$o=mn(oo,oo.FWIDTH),Ho=mn(oo,oo.BITCAST),Wo=mn(oo,oo.TRANSPOSE),jo=mn(oo,oo.ATAN2),qo=mn(oo,oo.MIN),Ko=mn(oo,oo.MAX),Xo=mn(oo,oo.MOD),Yo=mn(oo,oo.STEP),Qo=mn(oo,oo.REFLECT),Zo=mn(oo,oo.DISTANCE),Jo=mn(oo,oo.DIFFERENCE),ea=mn(oo,oo.DOT),ta=mn(oo,oo.CROSS),sa=mn(oo,oo.POW),ra=mn(oo,oo.POW,2),na=mn(oo,oo.POW,3),ia=mn(oo,oo.POW,4),oa=mn(oo,oo.TRANSFORM_DIRECTION),aa=e=>Gi(Po(e),sa(Fo(e),1/3)),ua=e=>ea(e,e),la=mn(oo,oo.MIX),da=(e,t=0,s=1)=>hn(new oo(oo.CLAMP,hn(e),hn(t),hn(s))),ca=e=>da(e),ha=mn(oo,oo.REFRACT),pa=mn(oo,oo.SMOOTHSTEP),ga=mn(oo,oo.FACEFORWARD),ma=yn((([e])=>{const t=ea(e.xy,En(12.9898,78.233)),s=Xo(t,lo);return Ro(Co(s).mul(43758.5453))})),fa=(e,t,s)=>la(t,s,e),ya=(e,t,s)=>pa(t,s,e);Vr("all",ho),Vr("any",po),Vr("equals",go),Vr("radians",mo),Vr("degrees",fo),Vr("exp",yo),Vr("exp2",bo),Vr("log",xo),Vr("log2",To),Vr("sqrt",_o),Vr("inverseSqrt",No),Vr("floor",vo),Vr("ceil",So),Vr("normalize",Ao),Vr("fract",Ro),Vr("sin",Co),Vr("cos",Eo),Vr("tan",wo),Vr("asin",Mo),Vr("acos",Bo),Vr("atan",Uo),Vr("abs",Fo),Vr("sign",Po),Vr("length",Io),Vr("lengthSq",ua),Vr("negate",Lo),Vr("oneMinus",Do),Vr("dFdx",Vo),Vr("dFdy",Oo),Vr("round",Go),Vr("reciprocal",ko),Vr("trunc",zo),Vr("fwidth",$o),Vr("atan2",jo),Vr("min",qo),Vr("max",Ko),Vr("mod",Xo),Vr("step",Yo),Vr("reflect",Qo),Vr("distance",Zo),Vr("dot",ea),Vr("cross",ta),Vr("pow",sa),Vr("pow2",ra),Vr("pow3",na),Vr("pow4",ia),Vr("transformDirection",oa),Vr("mix",fa),Vr("clamp",da),Vr("refract",ha),Vr("smoothstep",ya),Vr("faceForward",ga),Vr("difference",Jo),Vr("saturate",ca),Vr("cbrt",aa),Vr("transpose",Wo),Vr("rand",ma);class ba extends Ar{static get type(){return"ConditionalNode"}constructor(e,t,s=null){super(),this.condNode=e,this.ifNode=t,this.elseNode=s}getNodeType(e){const t=this.ifNode.getNodeType(e);if(null!==this.elseNode){const s=this.elseNode.getNodeType(e);if(e.getTypeLength(s)>e.getTypeLength(t))return s}return t}setup(e){const t=this.condNode.cache(),s=this.ifNode.cache(),r=this.elseNode?this.elseNode.cache():null,n=e.context.nodeBlock;e.getDataFromNode(s).parentNodeBlock=n,null!==r&&(e.getDataFromNode(r).parentNodeBlock=n);const i=e.getNodeProperties(this);i.condNode=t,i.ifNode=s.context({nodeBlock:s}),i.elseNode=r?r.context({nodeBlock:r}):null}generate(e,t){const s=this.getNodeType(e),r=e.getDataFromNode(this);if(void 0!==r.nodeProperty)return r.nodeProperty;const{condNode:n,ifNode:i,elseNode:o}=e.getNodeProperties(this),a="void"!==t,u=a?ri(s).build(e):"";r.nodeProperty=u;const l=n.build(e,"bool");e.addFlowCode(`\n${e.tab}if ( ${l} ) {\n\n`).addFlowTab();let d=i.build(e,s);if(d&&(d=a?u+" = "+d+";":"return "+d+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+d+"\n\n"+e.tab+"}"),null!==o){e.addFlowCode(" else {\n\n").addFlowTab();let t=o.build(e,s);t&&(t=a?u+" = "+t+";":"return "+t+";"),e.removeFlowTab().addFlowCode(e.tab+"\t"+t+"\n\n"+e.tab+"}\n\n")}else e.addFlowCode("\n\n");return e.format(u,s,t)}}const xa=mn(ba);Vr("select",xa);const Ta=(...e)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),xa(...e));Vr("cond",Ta);class _a extends Ar{static get type(){return"ContextNode"}constructor(e,t={}){super(),this.isContextNode=!0,this.node=e,this.value=t}getScope(){return this.node.getScope()}getNodeType(e){return this.node.getNodeType(e)}analyze(e){this.node.build(e)}setup(e){const t=e.getContext();e.setContext({...e.context,...this.value});const s=this.node.build(e);return e.setContext(t),s}generate(e,t){const s=e.getContext();e.setContext({...e.context,...this.value});const r=this.node.build(e,t);return e.setContext(s),r}}const Na=mn(_a),va=(e,t)=>Na(e,{label:t});Vr("context",Na),Vr("label",va);class Sa extends Ar{static get type(){return"VarNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.global=!0,this.isVarNode=!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}generate(e){const{node:t,name:s}=this,r=e.getVarFromNode(this,s,e.getVectorType(this.getNodeType(e))),n=e.getPropertyName(r),i=t.build(e,r.type);return e.addLineFlowCode(`${n} = ${i}`,this),n}}const Aa=mn(Sa);Vr("toVar",((...e)=>Aa(...e).append()));const Ra=e=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Aa(e));Vr("temp",Ra);class Ca extends Ar{static get type(){return"VaryingNode"}constructor(e,t=null){super(),this.node=e,this.name=t,this.isVaryingNode=!0}isGlobal(){return!0}getHash(e){return this.name||super.getHash(e)}getNodeType(e){return this.node.getNodeType(e)}setupVarying(e){const t=e.getNodeProperties(this);let s=t.varying;if(void 0===s){const r=this.name,n=this.getNodeType(e);t.varying=s=e.getVaryingFromNode(this,r,n),t.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===e.shaderStage),s}setup(e){this.setupVarying(e)}analyze(e){return this.setupVarying(e),this.node.analyze(e)}generate(e){const t=e.getNodeProperties(this),s=this.setupVarying(e);if(void 0===t.propertyName){const r=this.getNodeType(e),n=e.getPropertyName(s,yr.VERTEX);e.flowNodeFromShaderStage(yr.VERTEX,this.node,r,n),t.propertyName=n}return e.getPropertyName(s)}}const Ea=mn(Ca);Vr("varying",Ea);const wa=yn((([e])=>{const t=e.mul(.9478672986).add(.0521327014).pow(2.4),s=e.mul(.0773993808),r=e.lessThanEqual(.04045);return la(t,s,r)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ma=yn((([e])=>{const t=e.pow(.41666).mul(1.055).sub(.055),s=e.mul(12.92),r=e.lessThanEqual(.0031308);return la(t,s,r)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Ba="WorkingColorSpace",Ua="OutputColorSpace";class Fa extends Er{static get type(){return"ColorSpaceNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.source=t,this.target=s}resolveColorSpace(e,t){return t===Ba?u.workingColorSpace:t===Ua?e.context.outputColorSpace||e.renderer.outputColorSpace:t}setup(e){const{colorNode:t}=this,s=this.resolveColorSpace(e,this.source),r=this.resolveColorSpace(e,this.target);let i=t;return!1!==u.enabled&&s!==r&&s&&r?(u.getTransfer(s)===l&&(i=Ln(wa(i.rgb),i.a)),u.getPrimaries(s)!==u.getPrimaries(r)&&(i=Ln(kn(u._getMatrix(new n,s,r)).mul(i.rgb),i.a)),u.getTransfer(r)===l&&(i=Ln(Ma(i.rgb),i.a)),i):i}}const Pa=e=>hn(new Fa(hn(e),Ba,Ua)),Ia=e=>hn(new Fa(hn(e),Ua,Ba)),La=(e,t)=>hn(new Fa(hn(e),Ba,t)),Da=(e,t)=>hn(new Fa(hn(e),t,Ba)),Va=(e,t,s)=>hn(new Fa(hn(e),t,s));Vr("toOutputColorSpace",Pa),Vr("toWorkingColorSpace",Ia),Vr("workingToColorSpace",La),Vr("colorSpaceToWorking",Da);let Oa=class extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}};class Ga extends Ar{static get type(){return"ReferenceBaseNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.updateType=br.OBJECT}setGroup(e){return this.group=e,this}element(e){return hn(new Oa(this,hn(e)))}setNodeType(e){const t=ti(null,e).getSelf();null!==this.group&&t.setGroup(this.group),this.node=t}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new ka(e,t,s));class $a extends Er{static get type(){return"ToneMappingNode"}constructor(e,t=Wa,s=null){super("vec3"),this.toneMapping=e,this.exposureNode=t,this.colorNode=s}getCacheKey(){return lr(super.getCacheKey(),this.toneMapping)}setup(e){const t=this.colorNode||e.context.color,s=this.toneMapping;if(s===d)return t;let r=null;const n=e.renderer.library.getToneMappingFunction(s);return null!==n?r=Ln(n(t.rgb,this.exposureNode),t.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),r=t),r}}const Ha=(e,t,s)=>hn(new $a(e,hn(t),hn(s))),Wa=za("toneMappingExposure","float");Vr("toneMapping",((e,t,s)=>Ha(t,s,e)));class ja extends Pr{static get type(){return"BufferAttributeNode"}constructor(e,t=null,s=0,r=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferStride=s,this.bufferOffset=r,this.usage=c,this.instanced=!1,this.attribute=null,this.global=!0,e&&!0===e.isBufferAttribute&&(this.attribute=e,this.usage=e.usage,this.instanced=e.isInstancedBufferAttribute)}getHash(e){if(0===this.bufferStride&&0===this.bufferOffset){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getNodeType(e){return null===this.bufferType&&(this.bufferType=e.getTypeFromAttribute(this.attribute)),this.bufferType}setup(e){if(null!==this.attribute)return;const t=this.getNodeType(e),s=this.value,r=e.getTypeLength(t),n=this.bufferStride||r,i=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new h(s,n),a=new g(o,r,i);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(e){const t=this.getNodeType(e),s=e.getBufferAttributeFromNode(this,t),r=e.getPropertyName(s);let n=null;if("vertex"===e.shaderStage||"compute"===e.shaderStage)this.name=r,n=r;else{n=Ea(this).build(e,t)}return n}getInputType(){return"bufferAttribute"}setUsage(e){return this.usage=e,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=e),this}setInstanced(e){return this.instanced=e,this}}const qa=(e,t,s,r)=>hn(new ja(e,t,s,r)),Ka=(e,t,s,r)=>qa(e,t,s,r).setUsage(p),Xa=(e,t,s,r)=>qa(e,t,s,r).setInstanced(!0),Ya=(e,t,s,r)=>Ka(e,t,s,r).setInstanced(!0);Vr("toAttribute",(e=>qa(e.value)));class Qa extends Ar{static get type(){return"ComputeNode"}constructor(e,t,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=e,this.count=t,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=br.OBJECT,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){!0===e&&this.version++}updateDispatchCount(){const{count:e,workgroupSize:t}=this;let s=t[0];for(let e=1;ehn(new Qa(hn(e),t,s));Vr("compute",Za);class Ja extends Ar{static get type(){return"CacheNode"}constructor(e,t=!0){super(),this.node=e,this.parent=t,this.isCacheNode=!0}getNodeType(e){return this.node.getNodeType(e)}build(e,...t){const s=e.getCache(),r=e.getCacheFromNode(this,this.parent);e.setCache(r);const n=this.node.build(e,...t);return e.setCache(s),n}}const eu=(e,...t)=>hn(new Ja(hn(e),...t));Vr("cache",eu);class tu extends Ar{static get type(){return"BypassNode"}constructor(e,t){super(),this.isBypassNode=!0,this.outputNode=e,this.callNode=t}getNodeType(e){return this.outputNode.getNodeType(e)}generate(e){const t=this.callNode.build(e,"void");return""!==t&&e.addLineFlowCode(t,this),this.outputNode.build(e)}}const su=mn(tu);Vr("bypass",su);class ru extends Ar{static get type(){return"RemapNode"}constructor(e,t,s,r=Sn(0),n=Sn(1)){super(),this.node=e,this.inLowNode=t,this.inHighNode=s,this.outLowNode=r,this.outHighNode=n,this.doClamp=!0}setup(){const{node:e,inLowNode:t,inHighNode:s,outLowNode:r,outHighNode:n,doClamp:i}=this;let o=e.sub(t).div(s.sub(t));return!0===i&&(o=o.clamp()),o.mul(n.sub(r)).add(r)}}const nu=mn(ru,null,null,{doClamp:!1}),iu=mn(ru);Vr("remap",nu),Vr("remapClamp",iu);class ou extends Ar{static get type(){return"ExpressionNode"}constructor(e="",t="void"){super(t),this.snippet=e}generate(e,t){const s=this.getNodeType(e),r=this.snippet;if("void"!==s)return e.format(`( ${r} )`,s,t);e.addLineFlowCode(r,this)}}const au=mn(ou),uu=e=>(e?xa(e,au("discard")):au("discard")).append(),lu=()=>au("return").append();Vr("discard",uu);class du extends Er{static get type(){return"RenderOutputNode"}constructor(e,t,s){super("vec4"),this.colorNode=e,this.toneMapping=t,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:e}){let t=this.colorNode||e.color;const s=(null!==this.toneMapping?this.toneMapping:e.toneMapping)||d,r=(null!==this.outputColorSpace?this.outputColorSpace:e.outputColorSpace)||m;return s!==d&&(t=t.toneMapping(s)),r!==m&&r!==u.workingColorSpace&&(t=t.workingToColorSpace(r)),t}}const cu=(e,t=null,s=null)=>hn(new du(hn(e),t,s));function hu(e){console.warn("THREE.TSLBase: AddNodeElement has been removed in favor of tree-shaking. Trying add",e)}Vr("renderOutput",cu);class pu extends Ar{static get type(){return"AttributeNode"}constructor(e,t=null){super(t),this.global=!0,this._attributeName=e}getHash(e){return this.getAttributeName(e)}getNodeType(e){let t=this.nodeType;if(null===t){const s=this.getAttributeName(e);if(e.hasGeometryAttribute(s)){const r=e.geometry.getAttribute(s);t=e.getTypeFromAttribute(r)}else t="float"}return t}setAttributeName(e){return this._attributeName=e,this}getAttributeName(){return this._attributeName}generate(e){const t=this.getAttributeName(e),s=this.getNodeType(e);if(!0===e.hasGeometryAttribute(t)){const r=e.geometry.getAttribute(t),n=e.getTypeFromAttribute(r),i=e.getAttribute(t,n);if("vertex"===e.shaderStage)return e.format(i.name,n,s);return Ea(this).build(e,s)}return console.warn(`AttributeNode: Vertex attribute "${t}" not found on geometry.`),e.generateConst(s)}serialize(e){super.serialize(e),e.global=this.global,e._attributeName=this._attributeName}deserialize(e){super.deserialize(e),this.global=e.global,this._attributeName=e._attributeName}}const gu=(e,t)=>hn(new pu(e,t)),mu=e=>gu("uv"+(e>0?e:""),"vec2");class fu extends Ar{static get type(){return"TextureSizeNode"}constructor(e,t=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=e,this.levelNode=t}generate(e,t){const s=this.textureNode.build(e,"property"),r=null===this.levelNode?"0":this.levelNode.build(e,"int");return e.format(`${e.getMethod("textureDimensions")}( ${s}, ${r} )`,this.getNodeType(e),t)}}const yu=mn(fu);class bu extends ei{static get type(){return"MaxMipLevelNode"}constructor(e){super(0),this._textureNode=e,this.updateType=br.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const e=this.texture,t=e.images,s=t&&t.length>0?t[0]&&t[0].image||t[0]:e.image;if(s&&void 0!==s.width){const{width:e,height:t}=s;this.value=Math.log2(Math.max(e,t))}}}const xu=mn(bu);class Tu extends ei{static get type(){return"TextureNode"}constructor(e,t=null,s=null,r=null){super(e),this.isTextureNode=!0,this.uvNode=t,this.levelNode=s,this.biasNode=r,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=br.NONE,this.referenceNode=null,this._value=e,this._matrixUniform=null,this.setUpdateMatrix(null===t)}set value(e){this.referenceNode?this.referenceNode.value=e:this._value=e}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===f?"uvec4":this.value.type===y?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return mu(this.value.channel)}updateReference(){return this.value}getTransformedUV(e){return null===this._matrixUniform&&(this._matrixUniform=ti(this.value.matrix)),this._matrixUniform.mul(Un(e,1)).xy}setUpdateMatrix(e){return this.updateMatrix=e,this.updateType=e?br.FRAME:br.NONE,this}setupUV(e,t){const s=this.value;return e.isFlipY()&&(s.image instanceof ImageBitmap&&!0===s.flipY||!0===s.isRenderTargetTexture||!0===s.isFramebufferTexture||!0===s.isDepthTexture)&&(t=this.sampler?t.flipY():t.setY(An(yu(this,this.levelNode).y).sub(t.y).sub(1))),t}setup(e){const t=e.getNodeProperties(this);t.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==e.context.forceUVContext||!e.context.getUV||(s=e.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(e,s);let r=this.levelNode;null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),t.uvNode=s,t.levelNode=r,t.biasNode=this.biasNode,t.compareNode=this.compareNode,t.gradNode=this.gradNode,t.depthNode=this.depthNode}generateUV(e,t){return t.build(e,!0===this.sampler?"vec2":"ivec2")}generateSnippet(e,t,s,r,n,i,o,a){const u=this.value;let l;return l=r?e.generateTextureLevel(u,t,s,r,i):n?e.generateTextureBias(u,t,s,n,i):a?e.generateTextureGrad(u,t,s,a,i):o?e.generateTextureCompare(u,t,s,o,i):!1===this.sampler?e.generateTextureLoad(u,t,s,i):e.generateTexture(u,t,s,i),l}generate(e,t){const s=e.getNodeProperties(this),r=this.value;if(!r||!0!==r.isTexture)throw new Error("TextureNode: Need a three.js texture.");const n=super.generate(e,"property");if("sampler"===t)return n+"_sampler";if(e.isReference(t))return n;{const i=e.getDataFromNode(this);let o=i.propertyName;if(void 0===o){const{uvNode:t,levelNode:r,biasNode:a,compareNode:u,depthNode:l,gradNode:d}=s,c=this.generateUV(e,t),h=r?r.build(e,"float"):null,p=a?a.build(e,"float"):null,g=l?l.build(e,"int"):null,m=u?u.build(e,"float"):null,f=d?[d[0].build(e,"vec2"),d[1].build(e,"vec2")]:null,y=e.getVarFromNode(this);o=e.getPropertyName(y);const b=this.generateSnippet(e,n,c,h,p,g,m,f);e.addLineFlowCode(`${o} = ${b}`,this),i.snippet=b,i.propertyName=o}let a=o;const u=this.getNodeType(e);return e.needsToWorkingColorSpace(r)&&(a=Da(au(a,u),r.colorSpace).setup(e).build(e,u)),e.format(a,u,t)}}setSampler(e){return this.sampler=e,this}getSampler(){return this.sampler}uv(e){const t=this.clone();return t.uvNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}blur(e){const t=this.clone();return t.biasNode=hn(e).mul(xu(t)),t.referenceNode=this.getSelf(),hn(t)}level(e){const t=this.clone();return t.levelNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}size(e){return yu(this,e)}bias(e){const t=this.clone();return t.biasNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}compare(e){const t=this.clone();return t.compareNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}grad(e,t){const s=this.clone();return s.gradNode=[hn(e),hn(t)],s.referenceNode=this.getSelf(),hn(s)}depth(e){const t=this.clone();return t.depthNode=hn(e),t.referenceNode=this.getSelf(),hn(t)}serialize(e){super.serialize(e),e.value=this.value.toJSON(e.meta).uuid,e.sampler=this.sampler,e.updateMatrix=this.updateMatrix,e.updateType=this.updateType}deserialize(e){super.deserialize(e),this.value=e.meta.textures[e.value],this.sampler=e.sampler,this.updateMatrix=e.updateMatrix,this.updateType=e.updateType}update(){const e=this.value,t=this._matrixUniform;null!==t&&(t.value=e.matrix),!0===e.matrixAutoUpdate&&e.updateMatrix()}clone(){const e=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return e.sampler=this.sampler,e}}const _u=mn(Tu),Nu=(...e)=>_u(...e).setSampler(!1),vu=e=>(!0===e.isNode?e:_u(e)).convert("sampler"),Su=ti("float").label("cameraNear").setGroup(Zn).onRenderUpdate((({camera:e})=>e.near)),Au=ti("float").label("cameraFar").setGroup(Zn).onRenderUpdate((({camera:e})=>e.far)),Ru=ti("mat4").label("cameraProjectionMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrix)),Cu=ti("mat4").label("cameraProjectionMatrixInverse").setGroup(Zn).onRenderUpdate((({camera:e})=>e.projectionMatrixInverse)),Eu=ti("mat4").label("cameraViewMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorldInverse)),wu=ti("mat4").label("cameraWorldMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.matrixWorld)),Mu=ti("mat3").label("cameraNormalMatrix").setGroup(Zn).onRenderUpdate((({camera:e})=>e.normalMatrix)),Bu=ti(new s).label("cameraPosition").setGroup(Zn).onRenderUpdate((({camera:e},t)=>t.value.setFromMatrixPosition(e.matrixWorld)));class Uu extends Ar{static get type(){return"Object3DNode"}constructor(e,t=null){super(),this.scope=e,this.object3d=t,this.updateType=br.OBJECT,this._uniformNode=new ei(null)}getNodeType(){const e=this.scope;return e===Uu.WORLD_MATRIX?"mat4":e===Uu.POSITION||e===Uu.VIEW_POSITION||e===Uu.DIRECTION||e===Uu.SCALE?"vec3":void 0}update(e){const t=this.object3d,r=this._uniformNode,n=this.scope;if(n===Uu.WORLD_MATRIX)r.value=t.matrixWorld;else if(n===Uu.POSITION)r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld);else if(n===Uu.SCALE)r.value=r.value||new s,r.value.setFromMatrixScale(t.matrixWorld);else if(n===Uu.DIRECTION)r.value=r.value||new s,t.getWorldDirection(r.value);else if(n===Uu.VIEW_POSITION){const n=e.camera;r.value=r.value||new s,r.value.setFromMatrixPosition(t.matrixWorld),r.value.applyMatrix4(n.matrixWorldInverse)}}generate(e){const t=this.scope;return t===Uu.WORLD_MATRIX?this._uniformNode.nodeType="mat4":t!==Uu.POSITION&&t!==Uu.VIEW_POSITION&&t!==Uu.DIRECTION&&t!==Uu.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(e)}serialize(e){super.serialize(e),e.scope=this.scope}deserialize(e){super.deserialize(e),this.scope=e.scope}}Uu.WORLD_MATRIX="worldMatrix",Uu.POSITION="position",Uu.SCALE="scale",Uu.VIEW_POSITION="viewPosition",Uu.DIRECTION="direction";const Fu=mn(Uu,Uu.DIRECTION),Pu=mn(Uu,Uu.WORLD_MATRIX),Iu=mn(Uu,Uu.POSITION),Lu=mn(Uu,Uu.SCALE),Du=mn(Uu,Uu.VIEW_POSITION);class Vu extends Uu{static get type(){return"ModelNode"}constructor(e){super(e)}update(e){this.object3d=e.object,super.update(e)}}const Ou=fn(Vu,Vu.DIRECTION),Gu=fn(Vu,Vu.WORLD_MATRIX),ku=fn(Vu,Vu.POSITION),zu=fn(Vu,Vu.SCALE),$u=fn(Vu,Vu.VIEW_POSITION),Hu=ti(new n).onObjectUpdate((({object:e},t)=>t.value.getNormalMatrix(e.matrixWorld))),Wu=ti(new i).onObjectUpdate((({object:e},t)=>t.value.copy(e.matrixWorld).invert())),ju=Eu.mul(Gu).toVar("modelViewMatrix"),qu=yn((e=>(e.context.isHighPrecisionModelViewMatrix=!0,ti("mat4").onObjectUpdate((({object:e,camera:t})=>e.modelViewMatrix.multiplyMatrices(t.matrixWorldInverse,e.matrixWorld)))))).once()().toVar("highPrecisionModelViewMatrix"),Ku=yn((e=>{const t=e.context.isHighPrecisionModelViewMatrix;return ti("mat3").onObjectUpdate((({object:e,camera:s})=>(!0!==t&&e.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix))))})).once()().toVar("highPrecisionModelNormalMatrix"),Xu=gu("position","vec3"),Yu=Xu.varying("positionLocal"),Qu=Xu.varying("positionPrevious"),Zu=Gu.mul(Yu).xyz.varying("v_positionWorld"),Ju=Yu.transformDirection(Gu).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),el=ju.mul(Yu).xyz.varying("v_positionView"),tl=el.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class sl extends Ar{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(e){const{renderer:t,material:s}=e;return t.coordinateSystem===b&&s.side===x?"false":e.getFrontFacing()}}const rl=fn(sl),nl=Sn(rl).mul(2).sub(1),il=gu("normal","vec3"),ol=yn((e=>!1===e.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),Un(0,1,0)):il),"vec3").once()().toVar("normalLocal"),al=el.dFdx().cross(el.dFdy()).normalize().toVar("normalFlat"),ul=yn((e=>{let t;return t=!0===e.material.flatShading?al:Ea(gl(ol),"v_normalView").normalize(),t}),"vec3").once()().toVar("normalView"),ll=Ea(ul.transformDirection(Eu),"v_normalWorld").normalize().toVar("normalWorld"),dl=yn((e=>e.context.setupNormal()),"vec3").once()().mul(nl).toVar("transformedNormalView"),cl=dl.transformDirection(Eu).toVar("transformedNormalWorld"),hl=yn((e=>e.context.setupClearcoatNormal()),"vec3").once()().mul(nl).toVar("transformedClearcoatNormalView"),pl=yn((([e,t=Gu])=>{const s=kn(t),r=e.div(Un(s[0].dot(s[0]),s[1].dot(s[1]),s[2].dot(s[2])));return s.mul(r).xyz})),gl=yn((([e],t)=>{const s=t.renderer.nodes.modelNormalViewMatrix;if(null!==s)return s.transformDirection(e);const r=Hu.mul(e);return Eu.transformDirection(r)})),ml=ti(0).onReference((({material:e})=>e)).onRenderUpdate((({material:e})=>e.refractionRatio)),fl=tl.negate().reflect(dl),yl=tl.negate().refract(dl,ml),bl=fl.transformDirection(Eu).toVar("reflectVector"),xl=yl.transformDirection(Eu).toVar("reflectVector");class Tl extends Tu{static get type(){return"CubeTextureNode"}constructor(e,t=null,s=null,r=null){super(e,t,s,r),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const e=this.value;return e.mapping===T?bl:e.mapping===_?xl:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',e.mapping),Un(0,0,0))}setUpdateMatrix(){}setupUV(e,t){const s=this.value;return e.renderer.coordinateSystem!==N&&s.isRenderTargetTexture?t:Un(t.x.negate(),t.yz)}generateUV(e,t){return t.build(e,"vec3")}}const _l=mn(Tl);class Nl extends ei{static get type(){return"BufferNode"}constructor(e,t,s=0){super(e,t),this.isBufferNode=!0,this.bufferType=t,this.bufferCount=s}getElementType(e){return this.getNodeType(e)}getInputType(){return"buffer"}}const vl=(e,t,s)=>hn(new Nl(e,t,s));class Sl extends Rr{static get type(){return"UniformArrayElementNode"}constructor(e,t){super(e,t),this.isArrayBufferElementNode=!0}generate(e){const t=super.generate(e),s=this.getNodeType();return e.format(t,"vec4",s)}}class Al extends Nl{static get type(){return"UniformArrayNode"}constructor(e,t=null){super(null,"vec4"),this.array=e,this.elementType=t,this._elementType=null,this._elementLength=0,this.updateType=br.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:e,value:t}=this,s=this.getElementLength(),r=this.getElementType();if(1===s)for(let s=0;shn(new Al(e,t)),Cl=(e,t)=>(console.warn("TSL.UniformArrayNode: uniforms() has been renamed to uniformArray()."),hn(new Al(e,t)));class El extends Rr{static get type(){return"ReferenceElementNode"}constructor(e,t){super(e,t),this.referenceNode=e,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(e){const t=super.generate(e),s=this.referenceNode.getNodeType(),r=this.getNodeType();return e.format(t,s,r)}}class wl extends Ar{static get type(){return"ReferenceNode"}constructor(e,t,s=null,r=null){super(),this.property=e,this.uniformType=t,this.object=s,this.count=r,this.properties=e.split("."),this.reference=s,this.node=null,this.group=null,this.name=null,this.updateType=br.OBJECT}element(e){return hn(new El(this,hn(e)))}setGroup(e){return this.group=e,this}label(e){return this.name=e,this}setNodeType(e){let t=null;t=null!==this.count?vl(null,e,this.count):Array.isArray(this.getValueFromReference())?Rl(null,e):"texture"===e?_u(null):"cubeTexture"===e?_l(null):ti(null,e),null!==this.group&&t.setGroup(this.group),null!==this.name&&t.label(this.name),this.node=t.getSelf()}getNodeType(e){return null===this.node&&(this.updateReference(e),this.updateValue()),this.node.getNodeType(e)}getValueFromReference(e=this.reference){const{properties:t}=this;let s=e[t[0]];for(let e=1;ehn(new wl(e,t,s)),Bl=(e,t,s,r)=>hn(new wl(e,t,r,s));class Ul extends wl{static get type(){return"MaterialReferenceNode"}constructor(e,t,s=null){super(e,t,s),this.material=s,this.isMaterialReferenceNode=!0}updateReference(e){return this.reference=null!==this.material?this.material:e.material,this.reference}}const Fl=(e,t,s)=>hn(new Ul(e,t,s)),Pl=yn((e=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),gu("tangent","vec4"))))(),Il=Pl.xyz.toVar("tangentLocal"),Ll=ju.mul(Ln(Il,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView"),Dl=Ll.transformDirection(Eu).varying("v_tangentWorld").normalize().toVar("tangentWorld"),Vl=Ll.toVar("transformedTangentView"),Ol=Vl.transformDirection(Eu).normalize().toVar("transformedTangentWorld"),Gl=e=>e.mul(Pl.w).xyz,kl=Ea(Gl(il.cross(Pl)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),zl=Ea(Gl(ol.cross(Il)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),$l=Ea(Gl(ul.cross(Ll)),"v_bitangentView").normalize().toVar("bitangentView"),Hl=Ea(Gl(ll.cross(Dl)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),Wl=Gl(dl.cross(Vl)).normalize().toVar("transformedBitangentView"),jl=Wl.transformDirection(Eu).normalize().toVar("transformedBitangentWorld"),ql=kn(Ll,$l,ul),Kl=tl.mul(ql),Xl=(e,t)=>e.sub(Kl.mul(t)),Yl=(()=>{let e=xi.cross(tl);return e=e.cross(xi).normalize(),e=la(e,dl,yi.mul(ai.oneMinus()).oneMinus().pow2().pow2()).normalize(),e})(),Ql=yn((e=>{const{eye_pos:t,surf_norm:s,mapN:r,uv:n}=e,i=t.dFdx(),o=t.dFdy(),a=n.dFdx(),u=n.dFdy(),l=s,d=o.cross(l),c=l.cross(i),h=d.mul(a.x).add(c.mul(u.x)),p=d.mul(a.y).add(c.mul(u.y)),g=h.dot(h).max(p.dot(p)),m=nl.mul(g.inverseSqrt());return Vi(h.mul(r.x,m),p.mul(r.y,m),l.mul(r.z)).normalize()}));class Zl extends Er{static get type(){return"NormalMapNode"}constructor(e,t=null){super("vec3"),this.node=e,this.scaleNode=t,this.normalMapType=v}setup(e){const{normalMapType:t,scaleNode:s}=this;let r=this.node.mul(2).sub(1);null!==s&&(r=Un(r.xy.mul(s),r.z));let n=null;if(t===S)n=gl(r);else if(t===v){n=!0===e.hasGeometryAttribute("tangent")?ql.mul(r).normalize():Ql({eye_pos:el,surf_norm:ul,mapN:r,uv:mu()})}return n}}const Jl=mn(Zl),ed=yn((({textureNode:e,bumpScale:t})=>{const s=t=>e.cache().context({getUV:e=>t(e.uvNode||mu()),forceUVContext:!0}),r=Sn(s((e=>e)));return En(Sn(s((e=>e.add(e.dFdx())))).sub(r),Sn(s((e=>e.add(e.dFdy())))).sub(r)).mul(t)})),td=yn((e=>{const{surf_pos:t,surf_norm:s,dHdxy:r}=e,n=t.dFdx().normalize(),i=s,o=t.dFdy().normalize().cross(i),a=i.cross(n),u=n.dot(o).mul(nl),l=u.sign().mul(r.x.mul(o).add(r.y.mul(a)));return u.abs().mul(s).sub(l).normalize()}));class sd extends Er{static get type(){return"BumpMapNode"}constructor(e,t=null){super("vec3"),this.textureNode=e,this.scaleNode=t}setup(){const e=null!==this.scaleNode?this.scaleNode:1,t=ed({textureNode:this.textureNode,bumpScale:e});return td({surf_pos:el,surf_norm:ul,dHdxy:t})}}const rd=mn(sd),nd=new Map;class id extends Ar{static get type(){return"MaterialNode"}constructor(e){super(),this.scope=e}getCache(e,t){let s=nd.get(e);return void 0===s&&(s=Fl(e,t),nd.set(e,s)),s}getFloat(e){return this.getCache(e,"float")}getColor(e){return this.getCache(e,"color")}getTexture(e){return this.getCache("map"===e?"map":e+"Map","texture")}setup(e){const t=e.context.material,s=this.scope;let r=null;if(s===id.COLOR){const e=void 0!==t.color?this.getColor(s):Un();r=t.map&&!0===t.map.isTexture?e.mul(this.getTexture("map")):e}else if(s===id.OPACITY){const e=this.getFloat(s);r=t.alphaMap&&!0===t.alphaMap.isTexture?e.mul(this.getTexture("alpha")):e}else if(s===id.SPECULAR_STRENGTH)r=t.specularMap&&!0===t.specularMap.isTexture?this.getTexture("specular").r:Sn(1);else if(s===id.SPECULAR_INTENSITY){const e=this.getFloat(s);r=t.specularMap?e.mul(this.getTexture(s).a):e}else if(s===id.SPECULAR_COLOR){const e=this.getColor(s);r=t.specularColorMap&&!0===t.specularColorMap.isTexture?e.mul(this.getTexture(s).rgb):e}else if(s===id.ROUGHNESS){const e=this.getFloat(s);r=t.roughnessMap&&!0===t.roughnessMap.isTexture?e.mul(this.getTexture(s).g):e}else if(s===id.METALNESS){const e=this.getFloat(s);r=t.metalnessMap&&!0===t.metalnessMap.isTexture?e.mul(this.getTexture(s).b):e}else if(s===id.EMISSIVE){const e=this.getFloat("emissiveIntensity"),n=this.getColor(s).mul(e);r=t.emissiveMap&&!0===t.emissiveMap.isTexture?n.mul(this.getTexture(s)):n}else if(s===id.NORMAL)t.normalMap?(r=Jl(this.getTexture("normal"),this.getCache("normalScale","vec2")),r.normalMapType=t.normalMapType):r=t.bumpMap?rd(this.getTexture("bump").r,this.getFloat("bumpScale")):ul;else if(s===id.CLEARCOAT){const e=this.getFloat(s);r=t.clearcoatMap&&!0===t.clearcoatMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_ROUGHNESS){const e=this.getFloat(s);r=t.clearcoatRoughnessMap&&!0===t.clearcoatRoughnessMap.isTexture?e.mul(this.getTexture(s).r):e}else if(s===id.CLEARCOAT_NORMAL)r=t.clearcoatNormalMap?Jl(this.getTexture(s),this.getCache(s+"Scale","vec2")):ul;else if(s===id.SHEEN){const e=this.getColor("sheenColor").mul(this.getFloat("sheen"));r=t.sheenColorMap&&!0===t.sheenColorMap.isTexture?e.mul(this.getTexture("sheenColor").rgb):e}else if(s===id.SHEEN_ROUGHNESS){const e=this.getFloat(s);r=t.sheenRoughnessMap&&!0===t.sheenRoughnessMap.isTexture?e.mul(this.getTexture(s).a):e,r=r.clamp(.07,1)}else if(s===id.ANISOTROPY)if(t.anisotropyMap&&!0===t.anisotropyMap.isTexture){const e=this.getTexture(s);r=Gn($d.x,$d.y,$d.y.negate(),$d.x).mul(e.rg.mul(2).sub(En(1)).normalize().mul(e.b))}else r=$d;else if(s===id.IRIDESCENCE_THICKNESS){const e=Ml("1","float",t.iridescenceThicknessRange);if(t.iridescenceThicknessMap){const n=Ml("0","float",t.iridescenceThicknessRange);r=e.sub(n).mul(this.getTexture(s).g).add(n)}else r=e}else if(s===id.TRANSMISSION){const e=this.getFloat(s);r=t.transmissionMap?e.mul(this.getTexture(s).r):e}else if(s===id.THICKNESS){const e=this.getFloat(s);r=t.thicknessMap?e.mul(this.getTexture(s).g):e}else if(s===id.IOR)r=this.getFloat(s);else if(s===id.LIGHT_MAP)r=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===id.AO_MAP)r=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const t=this.getNodeType(e);r=this.getCache(s,t)}return r}}id.ALPHA_TEST="alphaTest",id.COLOR="color",id.OPACITY="opacity",id.SHININESS="shininess",id.SPECULAR="specular",id.SPECULAR_STRENGTH="specularStrength",id.SPECULAR_INTENSITY="specularIntensity",id.SPECULAR_COLOR="specularColor",id.REFLECTIVITY="reflectivity",id.ROUGHNESS="roughness",id.METALNESS="metalness",id.NORMAL="normal",id.CLEARCOAT="clearcoat",id.CLEARCOAT_ROUGHNESS="clearcoatRoughness",id.CLEARCOAT_NORMAL="clearcoatNormal",id.EMISSIVE="emissive",id.ROTATION="rotation",id.SHEEN="sheen",id.SHEEN_ROUGHNESS="sheenRoughness",id.ANISOTROPY="anisotropy",id.IRIDESCENCE="iridescence",id.IRIDESCENCE_IOR="iridescenceIOR",id.IRIDESCENCE_THICKNESS="iridescenceThickness",id.IOR="ior",id.TRANSMISSION="transmission",id.THICKNESS="thickness",id.ATTENUATION_DISTANCE="attenuationDistance",id.ATTENUATION_COLOR="attenuationColor",id.LINE_SCALE="scale",id.LINE_DASH_SIZE="dashSize",id.LINE_GAP_SIZE="gapSize",id.LINE_WIDTH="linewidth",id.LINE_DASH_OFFSET="dashOffset",id.POINT_WIDTH="pointWidth",id.DISPERSION="dispersion",id.LIGHT_MAP="light",id.AO_MAP="ao";const od=fn(id,id.ALPHA_TEST),ad=fn(id,id.COLOR),ud=fn(id,id.SHININESS),ld=fn(id,id.EMISSIVE),dd=fn(id,id.OPACITY),cd=fn(id,id.SPECULAR),hd=fn(id,id.SPECULAR_INTENSITY),pd=fn(id,id.SPECULAR_COLOR),gd=fn(id,id.SPECULAR_STRENGTH),md=fn(id,id.REFLECTIVITY),fd=fn(id,id.ROUGHNESS),yd=fn(id,id.METALNESS),bd=fn(id,id.NORMAL).context({getUV:null}),xd=fn(id,id.CLEARCOAT),Td=fn(id,id.CLEARCOAT_ROUGHNESS),_d=fn(id,id.CLEARCOAT_NORMAL).context({getUV:null}),Nd=fn(id,id.ROTATION),vd=fn(id,id.SHEEN),Sd=fn(id,id.SHEEN_ROUGHNESS),Ad=fn(id,id.ANISOTROPY),Rd=fn(id,id.IRIDESCENCE),Cd=fn(id,id.IRIDESCENCE_IOR),Ed=fn(id,id.IRIDESCENCE_THICKNESS),wd=fn(id,id.TRANSMISSION),Md=fn(id,id.THICKNESS),Bd=fn(id,id.IOR),Ud=fn(id,id.ATTENUATION_DISTANCE),Fd=fn(id,id.ATTENUATION_COLOR),Pd=fn(id,id.LINE_SCALE),Id=fn(id,id.LINE_DASH_SIZE),Ld=fn(id,id.LINE_GAP_SIZE),Dd=fn(id,id.LINE_WIDTH),Vd=fn(id,id.LINE_DASH_OFFSET),Od=fn(id,id.POINT_WIDTH),Gd=fn(id,id.DISPERSION),kd=fn(id,id.LIGHT_MAP),zd=fn(id,id.AO_MAP),$d=ti(new t).onReference((function(e){return e.material})).onRenderUpdate((function({material:e}){this.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation))}));class Hd extends Er{static get type(){return"ModelViewProjectionNode"}constructor(e=null){super("vec4"),this.positionNode=e}setup(e){if("fragment"===e.shaderStage)return Ea(e.context.mvp);const t=this.positionNode||Yu,s=e.renderer.nodes.modelViewMatrix||ju;return Ru.mul(s).mul(t)}}const Wd=mn(Hd);class jd extends Ar{static get type(){return"IndexNode"}constructor(e){super("uint"),this.scope=e,this.isInstanceIndexNode=!0}generate(e){const t=this.getNodeType(e),s=this.scope;let r,n;if(s===jd.VERTEX)r=e.getVertexIndex();else if(s===jd.INSTANCE)r=e.getInstanceIndex();else if(s===jd.DRAW)r=e.getDrawIndex();else if(s===jd.INVOCATION_LOCAL)r=e.getInvocationLocalIndex();else if(s===jd.INVOCATION_SUBGROUP)r=e.getInvocationSubgroupIndex();else{if(s!==jd.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+s);r=e.getSubgroupIndex()}if("vertex"===e.shaderStage||"compute"===e.shaderStage)n=r;else{n=Ea(this).build(e,t)}return n}}jd.VERTEX="vertex",jd.INSTANCE="instance",jd.SUBGROUP="subgroup",jd.INVOCATION_LOCAL="invocationLocal",jd.INVOCATION_SUBGROUP="invocationSubgroup",jd.DRAW="draw";const qd=fn(jd,jd.VERTEX),Kd=fn(jd,jd.INSTANCE),Xd=fn(jd,jd.SUBGROUP),Yd=fn(jd,jd.INVOCATION_SUBGROUP),Qd=fn(jd,jd.INVOCATION_LOCAL),Zd=fn(jd,jd.DRAW);class Jd extends Ar{static get type(){return"InstanceNode"}constructor(e){super("void"),this.instanceMesh=e,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=br.FRAME,this.buffer=null,this.bufferColor=null}setup(e){let t=this.instanceMatrixNode,s=this.instanceColorNode;const r=this.instanceMesh;if(null===t){const e=r.instanceMatrix;if(r.count<=1e3)t=vl(e.array,"mat4",Math.max(r.count,1)).element(Kd);else{const s=new A(e.array,16,1);this.buffer=s;const r=e.usage===p?Ya:Xa,n=[r(s,"vec4",16,0),r(s,"vec4",16,4),r(s,"vec4",16,8),r(s,"vec4",16,12)];t=zn(...n)}this.instanceMatrixNode=t}const n=r.instanceColor;if(n&&null===s){const e=new R(n.array,3),t=n.usage===p?Ya:Xa;this.bufferColor=e,s=Un(t(e,"vec3",3,0)),this.instanceColorNode=s}const i=t.mul(Yu).xyz;if(Yu.assign(i),e.hasGeometryAttribute("normal")){const e=pl(ol,t);ol.assign(e)}null!==this.instanceColorNode&&ni("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==p&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==p&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ec=mn(Jd);class tc extends Ar{static get type(){return"BatchNode"}constructor(e){super("void"),this.batchMesh=e,this.batchingIdNode=null}setup(e){null===this.batchingIdNode&&(null===e.getDrawIndex()?this.batchingIdNode=Kd:this.batchingIdNode=Zd);const t=yn((([e])=>{const t=yu(Nu(this.batchMesh._indirectTexture),0),s=An(e).modInt(An(t)),r=An(e).div(An(t));return Nu(this.batchMesh._indirectTexture,wn(s,r)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=t(An(this.batchingIdNode)),r=this.batchMesh._matricesTexture,n=yu(Nu(r),0),i=Sn(s).mul(4).toInt().toVar(),o=i.modInt(n),a=i.div(An(n)),u=zn(Nu(r,wn(o,a)),Nu(r,wn(o.add(1),a)),Nu(r,wn(o.add(2),a)),Nu(r,wn(o.add(3),a))),l=this.batchMesh._colorsTexture;if(null!==l){const e=yn((([e])=>{const t=yu(Nu(l),0).x,s=e,r=s.modInt(t),n=s.div(t);return Nu(l,wn(r,n)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),t=e(s);ni("vec3","vBatchColor").assign(t)}const d=kn(u);Yu.assign(u.mul(Yu));const c=ol.div(Un(d[0].dot(d[0]),d[1].dot(d[1]),d[2].dot(d[2]))),h=d.mul(c).xyz;ol.assign(h),e.hasGeometryAttribute("tangent")&&Il.mulAssign(d)}}const sc=mn(tc),rc=new WeakMap;class nc extends Ar{static get type(){return"SkinningNode"}constructor(e,t=!1){let s,r,n;super("void"),this.skinnedMesh=e,this.useReference=t,this.updateType=br.OBJECT,this.skinIndexNode=gu("skinIndex","uvec4"),this.skinWeightNode=gu("skinWeight","vec4"),t?(s=Ml("bindMatrix","mat4"),r=Ml("bindMatrixInverse","mat4"),n=Bl("skeleton.boneMatrices","mat4",e.skeleton.bones.length)):(s=ti(e.bindMatrix,"mat4"),r=ti(e.bindMatrixInverse,"mat4"),n=vl(e.skeleton.boneMatrices,"mat4",e.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=r,this.boneMatricesNode=n,this.previousBoneMatricesNode=null}getSkinnedPosition(e=this.boneMatricesNode,t=Yu){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w),d=n.mul(t),c=Vi(o.mul(r.x).mul(d),a.mul(r.y).mul(d),u.mul(r.z).mul(d),l.mul(r.w).mul(d));return i.mul(c).xyz}getSkinnedNormal(e=this.boneMatricesNode,t=ol){const{skinIndexNode:s,skinWeightNode:r,bindMatrixNode:n,bindMatrixInverseNode:i}=this,o=e.element(s.x),a=e.element(s.y),u=e.element(s.z),l=e.element(s.w);let d=Vi(r.x.mul(o),r.y.mul(a),r.z.mul(u),r.w.mul(l));return d=i.mul(d).mul(n),d.transformDirection(t).xyz}getPreviousSkinnedPosition(e){const t=e.object;return null===this.previousBoneMatricesNode&&(t.skeleton.previousBoneMatrices=new Float32Array(t.skeleton.boneMatrices),this.previousBoneMatricesNode=Bl("skeleton.previousBoneMatrices","mat4",t.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,Qu)}needsPreviousBoneMatrices(e){const t=e.renderer.getMRT();return t&&t.has("velocity")}setup(e){this.needsPreviousBoneMatrices(e)&&Qu.assign(this.getPreviousSkinnedPosition(e));const t=this.getSkinnedPosition();if(Yu.assign(t),e.hasGeometryAttribute("normal")){const t=this.getSkinnedNormal();ol.assign(t),e.hasGeometryAttribute("tangent")&&Il.assign(t)}}generate(e,t){if("void"!==t)return Yu.build(e,t)}update(e){const t=(this.useReference?e.object:this.skinnedMesh).skeleton;rc.get(t)!==e.frameId&&(rc.set(t,e.frameId),null!==this.previousBoneMatricesNode&&t.previousBoneMatrices.set(t.boneMatrices),t.update())}}const ic=e=>hn(new nc(e)),oc=e=>hn(new nc(e,!0));class ac extends Ar{static get type(){return"LoopNode"}constructor(e=[]){super(),this.params=e}getVarName(e){return String.fromCharCode("i".charCodeAt()+e)}getProperties(e){const t=e.getNodeProperties(this);if(void 0!==t.stackNode)return t;const s={};for(let e=0,t=this.params.length-1;eNumber(i)?">=":"<"));const d={start:n,end:i,condition:u},c=d.start,h=d.end;let p="",g="",m="";l||(l="int"===a||"uint"===a?u.includes("<")?"++":"--":u.includes("<")?"+= 1.":"-= 1."),p+=e.getVar(a,o)+" = "+c,g+=o+" "+u+" "+h,m+=o+" "+l;const f=`for ( ${p}; ${g}; ${m} )`;e.addFlowCode((0===t?"\n":"")+e.tab+f+" {\n\n").addFlowTab()}const n=r.build(e,"void"),i=t.returnsNode?t.returnsNode.build(e):"";e.removeFlowTab().addFlowCode("\n"+e.tab+n);for(let t=0,s=this.params.length-1;thn(new ac(gn(e,"int"))).append(),lc=()=>au("continue").append(),dc=()=>au("break").append(),cc=(...e)=>(console.warn("TSL.LoopNode: loop() has been renamed to Loop()."),uc(...e)),hc=new WeakMap,pc=new r,gc=yn((({bufferMap:e,influence:t,stride:s,width:r,depth:n,offset:i})=>{const o=An(qd).mul(s).add(i),a=o.div(r),u=o.sub(a.mul(r));return Nu(e,wn(u,a)).depth(n).mul(t)}));class mc extends Ar{static get type(){return"MorphNode"}constructor(e){super("void"),this.mesh=e,this.morphBaseInfluence=ti(1),this.updateType=br.OBJECT}setup(e){const{geometry:s}=e,r=void 0!==s.morphAttributes.position,n=s.hasAttribute("normal")&&void 0!==s.morphAttributes.normal,i=s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color,o=void 0!==i?i.length:0,{texture:a,stride:u,size:l}=function(e){const s=void 0!==e.morphAttributes.position,r=void 0!==e.morphAttributes.normal,n=void 0!==e.morphAttributes.color,i=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,o=void 0!==i?i.length:0;let a=hc.get(e);if(void 0===a||a.count!==o){void 0!==a&&a.texture.dispose();const u=e.morphAttributes.position||[],l=e.morphAttributes.normal||[],d=e.morphAttributes.color||[];let c=0;!0===s&&(c=1),!0===r&&(c=2),!0===n&&(c=3);let h=e.attributes.position.count*c,p=1;const g=4096;h>g&&(p=Math.ceil(h/g),h=g);const m=new Float32Array(h*p*4*o),f=new C(m,h,p,o);f.type=E,f.needsUpdate=!0;const y=4*c;for(let x=0;x{const t=Sn(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?t.assign(Nu(this.mesh.morphTexture,wn(An(e).add(1),An(Kd))).r):t.assign(Ml("morphTargetInfluences","float").element(e).toVar()),!0===r&&Yu.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(0)})),!0===n&&ol.addAssign(gc({bufferMap:a,influence:t,stride:u,width:d,depth:e,offset:An(1)}))}))}update(){const e=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?e.value=1:e.value=1-this.mesh.morphTargetInfluences.reduce(((e,t)=>e+t),0)}}const fc=mn(mc);class yc extends Ar{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class bc extends yc{static get type(){return"AONode"}constructor(e=null){super(),this.aoNode=e}setup(e){e.context.ambientOcclusion.mulAssign(this.aoNode)}}class xc extends _a{static get type(){return"LightingContextNode"}constructor(e,t=null,s=null,r=null){super(e),this.lightingModel=t,this.backdropNode=s,this.backdropAlphaNode=r,this._value=null}getContext(){const{backdropNode:e,backdropAlphaNode:t}=this,s={directDiffuse:Un().toVar("directDiffuse"),directSpecular:Un().toVar("directSpecular"),indirectDiffuse:Un().toVar("indirectDiffuse"),indirectSpecular:Un().toVar("indirectSpecular")};return{radiance:Un().toVar("radiance"),irradiance:Un().toVar("irradiance"),iblIrradiance:Un().toVar("iblIrradiance"),ambientOcclusion:Sn(1).toVar("ambientOcclusion"),reflectedLight:s,backdrop:e,backdropAlpha:t}}setup(e){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||e.context.lightingModel,super.setup(e)}}const Tc=mn(xc);class _c extends yc{static get type(){return"IrradianceNode"}constructor(e){super(),this.node=e}setup(e){e.context.irradiance.addAssign(this.node)}}let Nc,vc;class Sc extends Ar{static get type(){return"ScreenNode"}constructor(e){super(),this.scope=e,this.isViewportNode=!0}getNodeType(){return this.scope===Sc.VIEWPORT?"vec4":"vec2"}getUpdateType(){let e=br.NONE;return this.scope!==Sc.SIZE&&this.scope!==Sc.VIEWPORT||(e=br.RENDER),this.updateType=e,e}update({renderer:e}){const t=e.getRenderTarget();this.scope===Sc.VIEWPORT?null!==t?vc.copy(t.viewport):(e.getViewport(vc),vc.multiplyScalar(e.getPixelRatio())):null!==t?(Nc.width=t.width,Nc.height=t.height):e.getDrawingBufferSize(Nc)}setup(){const e=this.scope;let s=null;return s=e===Sc.SIZE?ti(Nc||(Nc=new t)):e===Sc.VIEWPORT?ti(vc||(vc=new r)):En(Cc.div(Rc)),s}generate(e){if(this.scope===Sc.COORDINATE){let t=e.getFragCoord();if(e.isFlipY()){const s=e.getNodeProperties(Rc).outputNode.build(e);t=`${e.getType("vec2")}( ${t}.x, ${s}.y - ${t}.y )`}return t}return super.generate(e)}}Sc.COORDINATE="coordinate",Sc.VIEWPORT="viewport",Sc.SIZE="size",Sc.UV="uv";const Ac=fn(Sc,Sc.UV),Rc=fn(Sc,Sc.SIZE),Cc=fn(Sc,Sc.COORDINATE),Ec=fn(Sc,Sc.VIEWPORT),wc=Ec.zw,Mc=Cc.sub(Ec.xy),Bc=Mc.div(wc),Uc=yn((()=>(console.warn('TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.'),Rc)),"vec2").once()(),Fc=yn((()=>(console.warn('TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.'),Ac)),"vec2").once()(),Pc=yn((()=>(console.warn('TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.'),Ac.flipY())),"vec2").once()(),Ic=new t;class Lc extends Tu{static get type(){return"ViewportTextureNode"}constructor(e=Ac,t=null,s=null){null===s&&((s=new w).minFilter=M),super(s,e,t),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=br.FRAME}updateBefore(e){const t=e.renderer;t.getDrawingBufferSize(Ic);const s=this.value;s.image.width===Ic.width&&s.image.height===Ic.height||(s.image.width=Ic.width,s.image.height=Ic.height,s.needsUpdate=!0);const r=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,t.copyFramebufferToTexture(s),s.generateMipmaps=r}clone(){const e=new this.constructor(this.uvNode,this.levelNode,this.value);return e.generateMipmaps=this.generateMipmaps,e}}const Dc=mn(Lc),Vc=mn(Lc,null,null,{generateMipmaps:!0});let Oc=null;class Gc extends Lc{static get type(){return"ViewportDepthTextureNode"}constructor(e=Ac,t=null){null===Oc&&(Oc=new B),super(e,t,Oc)}}const kc=mn(Gc);class zc extends Ar{static get type(){return"ViewportDepthNode"}constructor(e,t=null){super("float"),this.scope=e,this.valueNode=t,this.isViewportDepthNode=!0}generate(e){const{scope:t}=this;return t===zc.DEPTH_BASE?e.getFragDepth():super.generate(e)}setup({camera:e}){const{scope:t}=this,s=this.valueNode;let r=null;if(t===zc.DEPTH_BASE)null!==s&&(r=Xc().assign(s));else if(t===zc.DEPTH)r=e.isPerspectiveCamera?Wc(el.z,Su,Au):$c(el.z,Su,Au);else if(t===zc.LINEAR_DEPTH)if(null!==s)if(e.isPerspectiveCamera){const e=jc(s,Su,Au);r=$c(e,Su,Au)}else r=s;else r=$c(el.z,Su,Au);return r}}zc.DEPTH_BASE="depthBase",zc.DEPTH="depth",zc.LINEAR_DEPTH="linearDepth";const $c=(e,t,s)=>e.add(t).div(t.sub(s)),Hc=(e,t,s)=>t.sub(s).mul(e).sub(t),Wc=(e,t,s)=>t.add(e).mul(s).div(s.sub(t).mul(e)),jc=(e,t,s)=>t.mul(s).div(s.sub(t).mul(e).sub(s)),qc=(e,t,s)=>{t=t.max(1e-6).toVar();const r=To(e.negate().div(t)),n=To(s.div(t));return r.div(n)},Kc=(e,t,s)=>{const r=e.mul(xo(s.div(t)));return Sn(Math.E).pow(r).mul(t).negate()},Xc=mn(zc,zc.DEPTH_BASE),Yc=fn(zc,zc.DEPTH),Qc=mn(zc,zc.LINEAR_DEPTH),Zc=Qc(kc());Yc.assign=e=>Xc(e);const Jc=mn(class extends Ar{constructor(e){super("float"),this.name=e,this.isBuiltinNode=!0}generate(){return this.name}});class eh extends Ar{static get type(){return"ClippingNode"}constructor(e=eh.DEFAULT){super(),this.scope=e}setup(e){super.setup(e);const t=e.clippingContext,{intersectionPlanes:s,unionPlanes:r}=t;return this.hardwareClipping=e.material.hardwareClipping,this.scope===eh.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(s,r):this.scope===eh.HARDWARE?this.setupHardwareClipping(r,e):this.setupDefault(s,r)}setupAlphaToCoverage(e,t){return yn((()=>{const s=Sn().toVar("distanceToPlane"),r=Sn().toVar("distanceToGradient"),n=Sn(1).toVar("clipOpacity"),i=t.length;if(!this.hardwareClipping&&i>0){const e=Rl(t);uc(i,(({i:t})=>{const i=e.element(t);s.assign(el.dot(i.xyz).negate().add(i.w)),r.assign(s.fwidth().div(2)),n.mulAssign(pa(r.negate(),r,s))}))}const o=e.length;if(o>0){const t=Rl(e),i=Sn(1).toVar("intersectionClipOpacity");uc(o,(({i:e})=>{const n=t.element(e);s.assign(el.dot(n.xyz).negate().add(n.w)),r.assign(s.fwidth().div(2)),i.mulAssign(pa(r.negate(),r,s).oneMinus())})),n.mulAssign(i.oneMinus())}ii.a.mulAssign(n),ii.a.equal(0).discard()}))()}setupDefault(e,t){return yn((()=>{const s=t.length;if(!this.hardwareClipping&&s>0){const e=Rl(t);uc(s,(({i:t})=>{const s=e.element(t);el.dot(s.xyz).greaterThan(s.w).discard()}))}const r=e.length;if(r>0){const t=Rl(e),s=Cn(!0).toVar("clipped");uc(r,(({i:e})=>{const r=t.element(e);s.assign(el.dot(r.xyz).greaterThan(r.w).and(s))})),s.discard()}}))()}setupHardwareClipping(e,t){const s=e.length;return t.enableHardwareClipping(s),yn((()=>{const r=Rl(e),n=Jc(t.getClipDistance());uc(s,(({i:e})=>{const t=r.element(e),s=el.dot(t.xyz).sub(t.w).negate();n.element(e).assign(s)}))}))()}}eh.ALPHA_TO_COVERAGE="alphaToCoverage",eh.DEFAULT="default",eh.HARDWARE="hardware";const th=yn((([e])=>Ro(Gi(1e4,Co(Gi(17,e.x).add(Gi(.1,e.y)))).mul(Vi(.1,Fo(Co(Gi(13,e.y).add(e.x)))))))),sh=yn((([e])=>th(En(th(e.xy),e.z)))),rh=yn((([e])=>{const t=Ko(Io(Vo(e.xyz)),Io(Oo(e.xyz))).toVar("maxDeriv"),s=Sn(1).div(Sn(.05).mul(t)).toVar("pixScale"),r=En(bo(vo(To(s))),bo(So(To(s)))).toVar("pixScales"),n=En(sh(vo(r.x.mul(e.xyz))),sh(vo(r.y.mul(e.xyz)))).toVar("alpha"),i=Ro(To(s)).toVar("lerpFactor"),o=Vi(Gi(i.oneMinus(),n.x),Gi(i,n.y)).toVar("x"),a=qo(i,i.oneMinus()).toVar("a"),u=Un(o.mul(o).div(Gi(2,a).mul(Oi(1,a))),o.sub(Gi(.5,a)).div(Oi(1,a)),Oi(1,Oi(1,o).mul(Oi(1,o)).div(Gi(2,a).mul(Oi(1,a))))).toVar("cases"),l=o.lessThan(a.oneMinus()).select(o.lessThan(a).select(u.x,u.y),u.z);return da(l,1e-6,1)}));class nh extends U{static get type(){return"NodeMaterial"}get type(){return this.constructor.type}set type(e){}constructor(){super(),this.isNodeMaterial=!0,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.hardwareClipping=!1,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.geometryNode=null,this.depthNode=null,this.shadowPositionNode=null,this.receivedShadowNode=null,this.castShadowNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+dr(this)}build(e){this.setup(e)}setupObserver(e){return new ir(e)}setup(e){e.context.setupNormal=()=>this.setupNormal(e);const t=e.renderer,s=t.getRenderTarget();let r;e.addStack(),e.stack.outputNode=this.vertexNode||this.setupPosition(e),null!==this.geometryNode&&(e.stack.outputNode=e.stack.outputNode.bypass(this.geometryNode)),e.addFlow("vertex",e.removeStack()),e.addStack();const n=this.setupClipping(e);if(!0===this.depthWrite&&(null!==s?!0===s.depthBuffer&&this.setupDepth(e):!0===t.depth&&this.setupDepth(e)),null===this.fragmentNode){this.setupDiffuseColor(e),this.setupVariants(e);const i=this.setupLighting(e);null!==n&&e.stack.add(n);const o=Ln(i,ii.a).max(0);if(r=this.setupOutput(e,o),vi.assign(r),null!==this.outputNode&&(r=this.outputNode),null!==s){const e=t.getMRT(),s=this.mrtNode;null!==e?(r=e,null!==s&&(r=e.merge(s))):null!==s&&(r=s)}}else{let t=this.fragmentNode;!0!==t.isOutputStructNode&&(t=Ln(t)),r=this.setupOutput(e,t)}e.stack.outputNode=r,e.addFlow("fragment",e.removeStack()),e.monitor=this.setupObserver(e)}setupClipping(e){if(null===e.clippingContext)return null;const{unionPlanes:t,intersectionPlanes:s}=e.clippingContext;let r=null;if(t.length>0||s.length>0){const t=e.renderer.samples;this.alphaToCoverage&&t>1?r=hn(new eh(eh.ALPHA_TO_COVERAGE)):e.stack.add(hn(new eh))}return r}setupHardwareClipping(e){if(this.hardwareClipping=!1,null===e.clippingContext)return;const t=e.clippingContext.unionPlanes.length;t>0&&t<=8&&e.isAvailable("clipDistance")&&(e.stack.add(hn(new eh(eh.HARDWARE))),this.hardwareClipping=!0)}setupDepth(e){const{renderer:t,camera:s}=e;let r=this.depthNode;if(null===r){const e=t.getMRT();e&&e.has("depth")?r=e.get("depth"):!0===t.logarithmicDepthBuffer&&(r=s.isPerspectiveCamera?qc(el.z,Su,Au):$c(el.z,Su,Au))}null!==r&&Yc.assign(r).append()}setupPosition(e){const{object:t}=e,s=t.geometry;if(e.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&fc(t).append(),!0===t.isSkinnedMesh&&oc(t).append(),this.displacementMap){const e=Fl("displacementMap","texture"),t=Fl("displacementScale","float"),s=Fl("displacementBias","float");Yu.addAssign(ol.normalize().mul(e.x.mul(t).add(s)))}t.isBatchedMesh&&sc(t).append(),t.instanceMatrix&&!0===t.instanceMatrix.isInstancedBufferAttribute&&ec(t).append(),null!==this.positionNode&&Yu.assign(this.positionNode),this.setupHardwareClipping(e);const r=Wd();return e.context.vertex=e.removeStack(),e.context.mvp=r,r}setupDiffuseColor({object:e,geometry:t}){let s=this.colorNode?Ln(this.colorNode):ad;if(!0===this.vertexColors&&t.hasAttribute("color")&&(s=Ln(s.xyz.mul(gu("color","vec3")),s.a)),e.instanceColor){s=ni("vec3","vInstanceColor").mul(s)}if(e.isBatchedMesh&&e._colorsTexture){s=ni("vec3","vBatchColor").mul(s)}ii.assign(s);const r=this.opacityNode?Sn(this.opacityNode):dd;if(ii.a.assign(ii.a.mul(r)),null!==this.alphaTestNode||this.alphaTest>0){const e=null!==this.alphaTestNode?Sn(this.alphaTestNode):od;ii.a.lessThanEqual(e).discard()}!0===this.alphaHash&&ii.a.lessThan(rh(Yu)).discard(),!1===this.transparent&&this.blending===F&&!1===this.alphaToCoverage&&ii.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?Un(0):ii.rgb}setupNormal(){return this.normalNode?Un(this.normalNode):bd}setupEnvironment(){let e=null;return this.envNode?e=this.envNode:this.envMap&&(e=this.envMap.isCubeTexture?Fl("envMap","cubeTexture"):Fl("envMap","texture")),e}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new _c(kd)),t}setupLights(e){const t=[],s=this.setupEnvironment(e);s&&s.isLightingNode&&t.push(s);const r=this.setupLightMap(e);if(r&&r.isLightingNode&&t.push(r),null!==this.aoNode||e.material.aoMap){const e=null!==this.aoNode?this.aoNode:zd;t.push(new bc(e))}let n=this.lightsNode||e.lightsNode;return t.length>0&&(n=e.renderer.lighting.createNode([...n.getLights(),...t])),n}setupLightingModel(){}setupLighting(e){const{material:t}=e,{backdropNode:s,backdropAlphaNode:r,emissiveNode:n}=this,i=!0===this.lights||null!==this.lightsNode?this.setupLights(e):null;let o=this.setupOutgoingLight(e);if(i&&i.getScope().hasLights){const t=this.setupLightingModel(e);o=Tc(i,t,s,r)}else null!==s&&(o=Un(null!==r?la(o,s,r):s));return(n&&!0===n.isNode||t.emissive&&!0===t.emissive.isColor)&&(oi.assign(Un(n||ld)),o=o.add(oi)),o}setupOutput(e,t){if(!0===this.fog){const s=e.fogNode;s&&(t=Ln(s.mix(t.rgb,s.colorNode),t.a))}return t}setDefaultValues(e){for(const t in e){const s=e[t];void 0===this[t]&&(this[t]=s,s&&s.clone&&(this[t]=s.clone()))}const t=Object.getOwnPropertyDescriptors(e.constructor.prototype);for(const e in t)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,e)&&void 0!==t[e].get&&Object.defineProperty(this.constructor.prototype,e,t[e])}toJSON(e){const t=void 0===e||"string"==typeof e;t&&(e={textures:{},images:{},nodes:{}});const s=U.prototype.toJSON.call(this,e),r=cr(this);s.inputNodes={};for(const{property:t,childNode:n}of r)s.inputNodes[t]=n.toJSON(e).uuid;function n(e){const t=[];for(const s in e){const r=e[s];delete r.metadata,t.push(r)}return t}if(t){const t=n(e.textures),r=n(e.images),i=n(e.nodes);t.length>0&&(s.textures=t),r.length>0&&(s.images=r),i.length>0&&(s.nodes=i)}return s}copy(e){return this.lightsNode=e.lightsNode,this.envNode=e.envNode,this.colorNode=e.colorNode,this.normalNode=e.normalNode,this.opacityNode=e.opacityNode,this.backdropNode=e.backdropNode,this.backdropAlphaNode=e.backdropAlphaNode,this.alphaTestNode=e.alphaTestNode,this.positionNode=e.positionNode,this.geometryNode=e.geometryNode,this.depthNode=e.depthNode,this.shadowPositionNode=e.shadowPositionNode,this.receivedShadowNode=e.receivedShadowNode,this.castShadowNode=e.castShadowNode,this.outputNode=e.outputNode,this.mrtNode=e.mrtNode,this.fragmentNode=e.fragmentNode,this.vertexNode=e.vertexNode,super.copy(e)}}const ih=new P;class oh extends nh{static get type(){return"InstancedPointsNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.pointWidthNode=null,this.setDefaultValues(ih),this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor;this.vertexNode=yn((()=>{const e=gu("instancePosition").xyz,t=Ln(ju.mul(Ln(e,1))),s=Ec.z.div(Ec.w),r=Ru.mul(t),n=Xu.xy.toVar();return n.mulAssign(this.pointWidthNode?this.pointWidthNode:Od),n.assign(n.div(Ec.z)),n.y.assign(n.y.mul(s)),n.assign(n.mul(r.w)),r.addAssign(Ln(n,0,0)),r}))(),this.fragmentNode=yn((()=>{const r=Sn(1).toVar(),n=ua(mu().mul(2).sub(1));if(t&&e.samples>1){const e=Sn(n.fwidth()).toVar();r.assign(pa(e.oneMinus(),e.add(1),n).oneMinus())}else n.greaterThan(1).discard();let i;if(this.pointColorNode)i=this.pointColorNode;else if(s){i=gu("instanceColor").mul(ad)}else i=ad;return r.mulAssign(dd),Ln(i,r)}))()}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ah=new I;class uh extends nh{static get type(){return"LineBasicNodeMaterial"}constructor(e){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(ah),this.setValues(e)}}const lh=new L;class dh extends nh{static get type(){return"LineDashedNodeMaterial"}constructor(e){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(lh),this.dashOffset=0,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setupVariants(){const e=this.offsetNode?Sn(this.offsetNodeNode):Vd,t=this.dashScaleNode?Sn(this.dashScaleNode):Pd,s=this.dashSizeNode?Sn(this.dashSizeNode):Id,r=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(s),Ai.assign(r);const n=Ea(gu("lineDistance").mul(t));(e?n.add(e):n).mod(Si.add(Ai)).greaterThan(Si).discard()}}const ch=new L;class hh extends nh{static get type(){return"Line2NodeMaterial"}constructor(e={}){super(),this.lights=!1,this.setDefaultValues(ch),this.useAlphaToCoverage=!0,this.useColor=e.vertexColors,this.useDash=e.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(e)}setup(e){this.setupShaders(e),super.setup(e)}setupShaders({renderer:e}){const t=this.alphaToCoverage,s=this.useColor,r=this.dashed,n=this.worldUnits,i=yn((({start:e,end:t})=>{const s=Ru.element(2).element(2),r=Ru.element(3).element(2).mul(-.5).div(s).sub(e.z).div(t.z.sub(e.z));return Ln(la(e.xyz,t.xyz,r),t.w)})).setLayout({name:"trimSegment",type:"vec4",inputs:[{name:"start",type:"vec4"},{name:"end",type:"vec4"}]});this.vertexNode=yn((()=>{const e=gu("instanceStart"),t=gu("instanceEnd"),s=Ln(ju.mul(Ln(e,1))).toVar("start"),o=Ln(ju.mul(Ln(t,1))).toVar("end");if(r){const e=this.dashScaleNode?Sn(this.dashScaleNode):Pd,t=this.offsetNode?Sn(this.offsetNodeNode):Vd,s=gu("instanceDistanceStart"),r=gu("instanceDistanceEnd");let n=Xu.y.lessThan(.5).select(e.mul(s),e.mul(r));n=n.add(t),ni("float","lineDistance").assign(n)}n&&(ni("vec3","worldStart").assign(s.xyz),ni("vec3","worldEnd").assign(o.xyz));const a=Ec.z.div(Ec.w),u=Ru.element(2).element(3).equal(-1);_n(u,(()=>{_n(s.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(i({start:s,end:o}))})).ElseIf(o.z.lessThan(0).and(s.z.greaterThanEqual(0)),(()=>{s.assign(i({start:o,end:s}))}))}));const l=Ru.mul(s),d=Ru.mul(o),c=l.xyz.div(l.w),h=d.xyz.div(d.w),p=h.xy.sub(c.xy).toVar();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const g=Ln().toVar();if(n){const e=o.xyz.sub(s.xyz).normalize(),t=la(s.xyz,o.xyz,.5).normalize(),n=e.cross(t).normalize(),i=e.cross(n),a=ni("vec4","worldPos");a.assign(Xu.y.lessThan(.5).select(s,o));const u=Dd.mul(.5);a.addAssign(Ln(Xu.x.lessThan(0).select(n.mul(u),n.mul(u).negate()),0)),r||(a.addAssign(Ln(Xu.y.lessThan(.5).select(e.mul(u).negate(),e.mul(u)),0)),a.addAssign(Ln(i.mul(u),0)),_n(Xu.y.greaterThan(1).or(Xu.y.lessThan(0)),(()=>{a.subAssign(Ln(i.mul(2).mul(u),0))}))),g.assign(Ru.mul(a));const l=Un().toVar();l.assign(Xu.y.lessThan(.5).select(c,h)),g.z.assign(l.z.mul(g.w))}else{const e=En(p.y,p.x.negate()).toVar("offset");p.x.assign(p.x.div(a)),e.x.assign(e.x.div(a)),e.assign(Xu.x.lessThan(0).select(e.negate(),e)),_n(Xu.y.lessThan(0),(()=>{e.assign(e.sub(p))})).ElseIf(Xu.y.greaterThan(1),(()=>{e.assign(e.add(p))})),e.assign(e.mul(Dd)),e.assign(e.div(Ec.w)),g.assign(Xu.y.lessThan(.5).select(l,d)),e.assign(e.mul(g.w)),g.assign(g.add(Ln(e,0,0)))}return g}))();const o=yn((({p1:e,p2:t,p3:s,p4:r})=>{const n=e.sub(s),i=r.sub(s),o=t.sub(e),a=n.dot(i),u=i.dot(o),l=n.dot(o),d=i.dot(i),c=o.dot(o).mul(d).sub(u.mul(u)),h=a.mul(u).sub(l.mul(d)).div(c).clamp(),p=a.add(u.mul(h)).div(d).clamp();return En(h,p)}));this.fragmentNode=yn((()=>{const i=mu();if(r){const e=this.dashSizeNode?Sn(this.dashSizeNode):Id,t=this.dashSizeNode?Sn(this.dashGapNode):Ld;Si.assign(e),Ai.assign(t);const s=ni("float","lineDistance");i.y.lessThan(-1).or(i.y.greaterThan(1)).discard(),s.mod(Si.add(Ai)).greaterThan(Si).discard()}const a=Sn(1).toVar("alpha");if(n){const s=ni("vec3","worldStart"),n=ni("vec3","worldEnd"),i=ni("vec4","worldPos").xyz.normalize().mul(1e5),u=n.sub(s),l=o({p1:s,p2:n,p3:Un(0,0,0),p4:i}),d=s.add(u.mul(l.x)),c=i.mul(l.y),h=d.sub(c).length().div(Dd);if(!r)if(t&&e.samples>1){const e=h.fwidth();a.assign(pa(e.negate().add(.5),e.add(.5),h).oneMinus())}else h.greaterThan(.5).discard()}else if(t&&e.samples>1){const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1)),s=e.mul(e).add(t.mul(t)),r=Sn(s.fwidth()).toVar("dlen");_n(i.y.abs().greaterThan(1),(()=>{a.assign(pa(r.oneMinus(),r.add(1),s).oneMinus())}))}else _n(i.y.abs().greaterThan(1),(()=>{const e=i.x,t=i.y.greaterThan(0).select(i.y.sub(1),i.y.add(1));e.mul(e).add(t.mul(t)).greaterThan(1).discard()}));let u;if(this.lineColorNode)u=this.lineColorNode;else if(s){const e=gu("instanceColorStart"),t=gu("instanceColorEnd");u=Xu.y.lessThan(.5).select(e,t).mul(ad)}else u=ad;return Ln(u,a)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(e){this.useWorldUnits!==e&&(this.useWorldUnits=e,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(e){this.useDash!==e&&(this.useDash=e,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(e){this.useAlphaToCoverage!==e&&(this.useAlphaToCoverage=e,this.needsUpdate=!0)}}const ph=e=>hn(e).mul(.5).add(.5),gh=e=>hn(e).mul(2).sub(1),mh=new D;class fh extends nh{static get type(){return"MeshNormalNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(mh),this.setValues(e)}setupDiffuseColor(){const e=this.opacityNode?Sn(this.opacityNode):dd;ii.assign(Ln(ph(dl),e))}}class yh extends Er{static get type(){return"EquirectUVNode"}constructor(e=Ju){super("vec2"),this.dirNode=e}setup(){const e=this.dirNode,t=e.z.atan2(e.x).mul(1/(2*Math.PI)).add(.5),s=e.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return En(t,s)}}const bh=mn(yh);class xh extends V{constructor(e=1,t={}){super(e,t),this.isCubeRenderTarget=!0}fromEquirectangularTexture(e,t){const s=t.minFilter,r=t.generateMipmaps;t.generateMipmaps=!0,this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const n=new O(5,5,5),i=bh(Ju),o=new nh;o.colorNode=_u(t,i,0),o.side=x,o.blending=G;const a=new k(n,o),u=new z;u.add(a),t.minFilter===M&&(t.minFilter=$);const l=new H(1,10,this),d=e.getMRT();return e.setMRT(null),l.update(e,u),e.setMRT(d),t.minFilter=s,t.currentGenerateMipmaps=r,a.geometry.dispose(),a.material.dispose(),this}}const Th=new WeakMap;class _h extends Er{static get type(){return"CubeMapNode"}constructor(e){super("vec3"),this.envNode=e,this._cubeTexture=null,this._cubeTextureNode=_l();const t=new W;t.isRenderTargetTexture=!0,this._defaultTexture=t,this.updateBeforeType=br.RENDER}updateBefore(e){const{renderer:t,material:s}=e,r=this.envNode;if(r.isTextureNode||r.isMaterialReferenceNode){const e=r.isTextureNode?r.value:s[r.property];if(e&&e.isTexture){const s=e.mapping;if(s===j||s===q){if(Th.has(e)){const t=Th.get(e);vh(t,e.mapping),this._cubeTexture=t}else{const s=e.image;if(function(e){return null!=e&&e.height>0}(s)){const r=new xh(s.height);r.fromEquirectangularTexture(t,e),vh(r.texture,e.mapping),this._cubeTexture=r.texture,Th.set(e,r.texture),e.addEventListener("dispose",Nh)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(e){return this.updateBefore(e),this._cubeTextureNode}}function Nh(e){const t=e.target;t.removeEventListener("dispose",Nh);const s=Th.get(t);void 0!==s&&(Th.delete(t),s.dispose())}function vh(e,t){t===j?e.mapping=T:t===q&&(e.mapping=_)}const Sh=mn(_h);class Ah extends yc{static get type(){return"BasicEnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){e.context.environment=Sh(this.envNode)}}class Rh extends yc{static get type(){return"BasicLightMapNode"}constructor(e=null){super(),this.lightMapNode=e}setup(e){const t=Sn(1/Math.PI);e.context.irradianceLightMap=this.lightMapNode.mul(t)}}class Ch{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Eh extends Ch{constructor(){super()}indirect(e,t,s){const r=e.ambientOcclusion,n=e.reflectedLight,i=s.context.irradianceLightMap;n.indirectDiffuse.assign(Ln(0)),i?n.indirectDiffuse.addAssign(i):n.indirectDiffuse.addAssign(Ln(1,1,1,0)),n.indirectDiffuse.mulAssign(r),n.indirectDiffuse.mulAssign(ii.rgb)}finish(e,t,s){const r=s.material,n=e.outgoingLight,i=s.context.environment;if(i)switch(r.combine){case Y:n.rgb.assign(la(n.rgb,n.rgb.mul(i.rgb),gd.mul(md)));break;case X:n.rgb.assign(la(n.rgb,i.rgb,gd.mul(md)));break;case K:n.rgb.addAssign(i.rgb.mul(gd.mul(md)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",r.combine)}}}const wh=new Q;class Mh extends nh{static get type(){return"MeshBasicNodeMaterial"}constructor(e){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(wh),this.setValues(e)}setupNormal(){return ul}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightMap(e){let t=null;return e.material.lightMap&&(t=new Rh(kd)),t}setupOutgoingLight(){return ii.rgb}setupLightingModel(){return new Eh}}const Bh=yn((({f0:e,f90:t,dotVH:s})=>{const r=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return e.mul(r.oneMinus()).add(t.mul(r))})),Uh=yn((e=>e.diffuseColor.mul(1/Math.PI))),Fh=yn((({dotNH:e})=>Ni.mul(Sn(.5)).add(1).mul(Sn(1/Math.PI)).mul(e.pow(Ni)))),Ph=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(t).clamp(),r=tl.dot(t).clamp(),n=Bh({f0:Ti,f90:1,dotVH:r}),i=Sn(.25),o=Fh({dotNH:s});return n.mul(i).mul(o)}));class Ih extends Eh{constructor(e=!0){super(),this.specular=e}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),!0===this.specular&&s.directSpecular.addAssign(r.mul(Ph({lightDirection:e})).mul(gd))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const Lh=new Z;class Dh extends nh{static get type(){return"MeshLambertNodeMaterial"}constructor(e){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Lh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih(!1)}}const Vh=new J;class Oh extends nh{static get type(){return"MeshPhongNodeMaterial"}constructor(e){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Vh),this.setValues(e)}setupEnvironment(e){const t=super.setupEnvironment(e);return t?new Ah(t):null}setupLightingModel(){return new Ih}setupVariants(){const e=(this.shininessNode?Sn(this.shininessNode):ud).max(1e-4);Ni.assign(e);const t=this.specularNode||cd;Ti.assign(t)}copy(e){return this.shininessNode=e.shininessNode,this.specularNode=e.specularNode,super.copy(e)}}const Gh=yn((e=>{if(!1===e.geometry.hasAttribute("normal"))return Sn(0);const t=ul.dFdx().abs().max(ul.dFdy().abs());return t.x.max(t.y).max(t.z)})),kh=yn((e=>{const{roughness:t}=e,s=Gh();let r=t.max(.0525);return r=r.add(s),r=r.min(1),r})),zh=yn((({alpha:e,dotNL:t,dotNV:s})=>{const r=e.pow2(),n=t.mul(r.add(r.oneMinus().mul(s.pow2())).sqrt()),i=s.mul(r.add(r.oneMinus().mul(t.pow2())).sqrt());return ki(.5,n.add(i).max(ao))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),$h=yn((({alphaT:e,alphaB:t,dotTV:s,dotBV:r,dotTL:n,dotBL:i,dotNV:o,dotNL:a})=>{const u=a.mul(Un(e.mul(s),t.mul(r),o).length()),l=o.mul(Un(e.mul(n),t.mul(i),a).length());return ki(.5,u.add(l)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),Hh=yn((({alpha:e,dotNH:t})=>{const s=e.pow2(),r=t.pow2().mul(s.oneMinus()).oneMinus();return s.div(r.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),Wh=Sn(1/Math.PI),jh=yn((({alphaT:e,alphaB:t,dotNH:s,dotTH:r,dotBH:n})=>{const i=e.mul(t),o=Un(t.mul(r),e.mul(n),i.mul(s)),a=o.dot(o),u=i.div(a);return Wh.mul(i.mul(u.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),qh=yn((e=>{const{lightDirection:t,f0:s,f90:r,roughness:n,f:i,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=e,u=e.normalView||dl,l=n.pow2(),d=t.add(tl).normalize(),c=u.dot(t).clamp(),h=u.dot(tl).clamp(),p=u.dot(d).clamp(),g=tl.dot(d).clamp();let m,f,y=Bh({f0:s,f90:r,dotVH:g});if(ln(o)&&(y=pi.mix(y,i)),ln(a)){const e=bi.dot(t),s=bi.dot(tl),r=bi.dot(d),n=xi.dot(t),i=xi.dot(tl),o=xi.dot(d);m=$h({alphaT:fi,alphaB:l,dotTV:s,dotBV:i,dotTL:e,dotBL:n,dotNV:h,dotNL:c}),f=jh({alphaT:fi,alphaB:l,dotNH:p,dotTH:r,dotBH:o})}else m=zh({alpha:l,dotNL:c,dotNV:h}),f=Hh({alpha:l,dotNH:p});return y.mul(m).mul(f)})),Kh=yn((({roughness:e,dotNV:t})=>{const s=Ln(-1,-.0275,-.572,.022),r=Ln(1,.0425,1.04,-.04),n=e.mul(s).add(r),i=n.x.mul(n.x).min(t.mul(-9.28).exp2()).mul(n.x).add(n.y);return En(-1.04,1.04).mul(i).add(n.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Xh=yn((e=>{const{dotNV:t,specularColor:s,specularF90:r,roughness:n}=e,i=Kh({dotNV:t,roughness:n});return s.mul(i.x).add(r.mul(i.y))})),Yh=yn((({f:e,f90:t,dotVH:s})=>{const r=s.oneMinus().saturate(),n=r.mul(r),i=r.mul(n,n).clamp(0,.9999);return e.sub(Un(t).mul(i)).div(i.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),Qh=yn((({roughness:e,dotNH:t})=>{const s=e.pow2(),r=Sn(1).div(s),n=t.pow2().oneMinus().max(.0078125);return Sn(2).add(r).mul(n.pow(r.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),Zh=yn((({dotNV:e,dotNL:t})=>Sn(1).div(Sn(4).mul(t.add(e).sub(t.mul(e)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),Jh=yn((({lightDirection:e})=>{const t=e.add(tl).normalize(),s=dl.dot(e).clamp(),r=dl.dot(tl).clamp(),n=dl.dot(t).clamp(),i=Qh({roughness:hi,dotNH:n}),o=Zh({dotNV:r,dotNL:s});return ci.mul(i).mul(o)})),ep=yn((({N:e,V:t,roughness:s})=>{const r=e.dot(t).saturate(),n=En(s,r.oneMinus().sqrt());return n.assign(n.mul(.984375).add(.0078125)),n})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),tp=yn((({f:e})=>{const t=e.length();return Ko(t.mul(t).add(e.z).div(t.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sp=yn((({v1:e,v2:t})=>{const s=e.dot(t),r=s.abs().toVar(),n=r.mul(.0145206).add(.4965155).mul(r).add(.8543985).toVar(),i=r.add(4.1616724).mul(r).add(3.417594).toVar(),o=n.div(i),a=s.greaterThan(0).select(o,Ko(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return e.cross(t).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),rp=yn((({N:e,V:t,P:s,mInv:r,p0:n,p1:i,p2:o,p3:a})=>{const u=i.sub(n).toVar(),l=a.sub(n).toVar(),d=u.cross(l),c=Un().toVar();return _n(d.dot(s.sub(n)).greaterThanEqual(0),(()=>{const u=t.sub(e.mul(t.dot(e))).normalize(),l=e.cross(u).negate(),d=r.mul(kn(u,l,e).transpose()).toVar(),h=d.mul(n.sub(s)).normalize().toVar(),p=d.mul(i.sub(s)).normalize().toVar(),g=d.mul(o.sub(s)).normalize().toVar(),m=d.mul(a.sub(s)).normalize().toVar(),f=Un(0).toVar();f.addAssign(sp({v1:h,v2:p})),f.addAssign(sp({v1:p,v2:g})),f.addAssign(sp({v1:g,v2:m})),f.addAssign(sp({v1:m,v2:h})),c.assign(Un(tp({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),np=1/6,ip=e=>Gi(np,Gi(e,Gi(e,e.negate().add(3)).sub(3)).add(1)),op=e=>Gi(np,Gi(e,Gi(e,Gi(3,e).sub(6))).add(4)),ap=e=>Gi(np,Gi(e,Gi(e,Gi(-3,e).add(3)).add(3)).add(1)),up=e=>Gi(np,sa(e,3)),lp=e=>ip(e).add(op(e)),dp=e=>ap(e).add(up(e)),cp=e=>Vi(-1,op(e).div(ip(e).add(op(e)))),hp=e=>Vi(1,up(e).div(ap(e).add(up(e)))),pp=(e,t,s)=>{const r=e.uvNode,n=Gi(r,t.zw).add(.5),i=vo(n),o=Ro(n),a=lp(o.x),u=dp(o.x),l=cp(o.x),d=hp(o.x),c=cp(o.y),h=hp(o.y),p=En(i.x.add(l),i.y.add(c)).sub(.5).mul(t.xy),g=En(i.x.add(d),i.y.add(c)).sub(.5).mul(t.xy),m=En(i.x.add(l),i.y.add(h)).sub(.5).mul(t.xy),f=En(i.x.add(d),i.y.add(h)).sub(.5).mul(t.xy),y=lp(o.y).mul(Vi(a.mul(e.uv(p).level(s)),u.mul(e.uv(g).level(s)))),b=dp(o.y).mul(Vi(a.mul(e.uv(m).level(s)),u.mul(e.uv(f).level(s))));return y.add(b)},gp=yn((([e,t=Sn(3)])=>{const s=En(e.size(An(t))),r=En(e.size(An(t.add(1)))),n=ki(1,s),i=ki(1,r),o=pp(e,Ln(n,s),vo(t)),a=pp(e,Ln(i,r),So(t));return Ro(t).mix(o,a)})),mp=yn((([e,t,s,r,n])=>{const i=Un(ha(t.negate(),Ao(e),ki(1,r))),o=Un(Io(n[0].xyz),Io(n[1].xyz),Io(n[2].xyz));return Ao(i).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),fp=yn((([e,t])=>e.mul(da(t.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),yp=Vc(),bp=Vc(),xp=yn((([e,t,s],{material:r})=>{const n=(r.side==x?yp:bp).uv(e),i=To(Rc.x).mul(fp(t,s));return gp(n,i)})),Tp=yn((([e,t,s])=>(_n(s.notEqual(0),(()=>{const r=xo(t).negate().div(s);return yo(r.negate().mul(e))})),Un(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),_p=yn((([e,t,s,r,n,i,o,a,u,l,d,c,h,p,g])=>{let m,f;if(g){m=Ln().toVar(),f=Un().toVar();const n=d.sub(1).mul(g.mul(.025)),i=Un(d.sub(n),d,d.add(n));uc({start:0,end:3},(({i:n})=>{const d=i.element(n),g=mp(e,t,c,d,a),y=o.add(g),b=l.mul(u.mul(Ln(y,1))),x=En(b.xy.div(b.w)).toVar();x.addAssign(1),x.divAssign(2),x.assign(En(x.x,x.y.oneMinus()));const T=xp(x,s,d);m.element(n).assign(T.element(n)),m.a.addAssign(T.a),f.element(n).assign(r.element(n).mul(Tp(Io(g),h,p).element(n)))})),m.a.divAssign(3)}else{const n=mp(e,t,c,d,a),i=o.add(n),g=l.mul(u.mul(Ln(i,1))),y=En(g.xy.div(g.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(En(y.x,y.y.oneMinus())),m=xp(y,s,d),f=r.mul(Tp(Io(n),h,p))}const y=f.rgb.mul(m.rgb),b=e.dot(t).clamp(),x=Un(Xh({dotNV:b,specularColor:n,specularF90:i,roughness:s})),T=f.r.add(f.g,f.b).div(3);return Ln(x.oneMinus().mul(y),m.a.oneMinus().mul(T).oneMinus())})),Np=kn(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),vp=(e,t)=>e.sub(t).div(e.add(t)).pow2(),Sp=yn((({outsideIOR:e,eta2:t,cosTheta1:s,thinFilmThickness:r,baseF0:n})=>{const i=la(e,t,pa(0,.03,r)),o=e.div(i).pow2().mul(s.pow2().oneMinus()).oneMinus();_n(o.lessThan(0),(()=>Un(1)));const a=o.sqrt(),u=vp(i,e),l=Bh({f0:u,f90:1,dotVH:s}),d=l.oneMinus(),c=i.lessThan(e).select(Math.PI,0),h=Sn(Math.PI).sub(c),p=(e=>{const t=e.sqrt();return Un(1).add(t).div(Un(1).sub(t))})(n.clamp(0,.9999)),g=vp(p,i.toVec3()),m=Bh({f0:g,f90:1,dotVH:a}),f=Un(p.x.lessThan(i).select(Math.PI,0),p.y.lessThan(i).select(Math.PI,0),p.z.lessThan(i).select(Math.PI,0)),y=i.mul(r,a,2),b=Un(h).add(f),x=l.mul(m).clamp(1e-5,.9999),T=x.sqrt(),_=d.pow2().mul(m).div(Un(1).sub(x)),N=l.add(_).toVar(),v=_.sub(d).toVar();return uc({start:1,end:2,condition:"<=",name:"m"},(({m:e})=>{v.mulAssign(T);const t=((e,t)=>{const s=e.mul(2*Math.PI*1e-9),r=Un(54856e-17,44201e-17,52481e-17),n=Un(1681e3,1795300,2208400),i=Un(43278e5,93046e5,66121e5),o=Sn(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(t.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=r.mul(i.mul(2*Math.PI).sqrt()).mul(n.mul(s).add(t).cos()).mul(s.pow2().negate().mul(i).exp());return a=Un(a.x.add(o),a.y,a.z).div(1.0685e-7),Np.mul(a)})(Sn(e).mul(y),Sn(e).mul(b)).mul(2);N.addAssign(v.mul(t))})),N.max(Un(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),Ap=yn((({normal:e,viewDir:t,roughness:s})=>{const r=e.dot(t).saturate(),n=s.pow2(),i=xa(s.lessThan(.25),Sn(-339.2).mul(n).add(Sn(161.4).mul(s)).sub(25.9),Sn(-8.48).mul(n).add(Sn(14.3).mul(s)).sub(9.95)),o=xa(s.lessThan(.25),Sn(44).mul(n).sub(Sn(23.7).mul(s)).add(3.26),Sn(1.97).mul(n).sub(Sn(3.27).mul(s)).add(.72));return xa(s.lessThan(.25),0,Sn(.1).mul(s).sub(.025)).add(i.mul(r).add(o).exp()).mul(1/Math.PI).saturate()})),Rp=Un(.04),Cp=Sn(1);class Ep extends Ch{constructor(e=!1,t=!1,s=!1,r=!1,n=!1,i=!1){super(),this.clearcoat=e,this.sheen=t,this.iridescence=s,this.anisotropy=r,this.transmission=n,this.dispersion=i,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(e){if(!0===this.clearcoat&&(this.clearcoatRadiance=Un().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=Un().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=Un().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=Un().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=Un().toVar("sheenSpecularIndirect")),!0===this.iridescence){const e=dl.dot(tl).clamp();this.iridescenceFresnel=Sp({outsideIOR:Sn(1),eta2:gi,cosTheta1:e,thinFilmThickness:mi,baseF0:Ti}),this.iridescenceF0=Yh({f:this.iridescenceFresnel,f90:1,dotVH:e})}if(!0===this.transmission){const t=Zu,s=Bu.sub(Zu).normalize(),r=cl;e.backdrop=_p(r,s,ai,ii,Ti,_i,t,Gu,Eu,Ru,Ci,wi,Bi,Mi,this.dispersion?Ui:null),e.backdropAlpha=Ei,ii.a.mulAssign(la(1,e.backdrop.a,Ei))}}computeMultiscattering(e,t,s){const r=dl.dot(tl).clamp(),n=Kh({roughness:ai,dotNV:r}),i=(this.iridescenceF0?pi.mix(Ti,this.iridescenceF0):Ti).mul(n.x).add(s.mul(n.y)),o=n.x.add(n.y).oneMinus(),a=Ti.add(Ti.oneMinus().mul(.047619)),u=i.mul(a).div(o.mul(a).oneMinus());e.addAssign(i),t.addAssign(u.mul(o))}direct({lightDirection:e,lightColor:t,reflectedLight:s}){const r=dl.dot(e).clamp().mul(t);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(r.mul(Jh({lightDirection:e}))),!0===this.clearcoat){const s=hl.dot(e).clamp().mul(t);this.clearcoatSpecularDirect.addAssign(s.mul(qh({lightDirection:e,f0:Rp,f90:Cp,roughness:di,normalView:hl})))}s.directDiffuse.addAssign(r.mul(Uh({diffuseColor:ii.rgb}))),s.directSpecular.addAssign(r.mul(qh({lightDirection:e,f0:Ti,f90:1,roughness:ai,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:e,lightPosition:t,halfWidth:s,halfHeight:r,reflectedLight:n,ltc_1:i,ltc_2:o}){const a=t.add(s).sub(r),u=t.sub(s).sub(r),l=t.sub(s).add(r),d=t.add(s).add(r),c=dl,h=tl,p=el.toVar(),g=ep({N:c,V:h,roughness:ai}),m=i.uv(g).toVar(),f=o.uv(g).toVar(),y=kn(Un(m.x,0,m.y),Un(0,1,0),Un(m.z,0,m.w)).toVar(),b=Ti.mul(f.x).add(Ti.oneMinus().mul(f.y)).toVar();n.directSpecular.addAssign(e.mul(b).mul(rp({N:c,V:h,P:p,mInv:y,p0:a,p1:u,p2:l,p3:d}))),n.directDiffuse.addAssign(e.mul(ii).mul(rp({N:c,V:h,P:p,mInv:kn(1,0,0,0,1,0,0,0,1),p0:a,p1:u,p2:l,p3:d})))}indirect(e,t,s){this.indirectDiffuse(e,t,s),this.indirectSpecular(e,t,s),this.ambientOcclusion(e,t,s)}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.addAssign(e.mul(Uh({diffuseColor:ii})))}indirectSpecular({radiance:e,iblIrradiance:t,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(t.mul(ci,Ap({normal:dl,viewDir:tl,roughness:hi}))),!0===this.clearcoat){const e=hl.dot(tl).clamp(),t=Xh({dotNV:e,specularColor:Rp,specularF90:Cp,roughness:di});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(t))}const r=Un().toVar("singleScattering"),n=Un().toVar("multiScattering"),i=t.mul(1/Math.PI);this.computeMultiscattering(r,n,_i);const o=r.add(n),a=ii.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(e.mul(r)),s.indirectSpecular.addAssign(n.mul(i)),s.indirectDiffuse.addAssign(a.mul(i))}ambientOcclusion({ambientOcclusion:e,reflectedLight:t}){const s=dl.dot(tl).clamp().add(e),r=ai.mul(-16).oneMinus().negate().exp2(),n=e.sub(s.pow(r).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(e),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(e),t.indirectDiffuse.mulAssign(e),t.indirectSpecular.mulAssign(n)}finish(e){const{outgoingLight:t}=e;if(!0===this.clearcoat){const e=hl.dot(tl).clamp(),s=Bh({dotVH:e,f0:Rp,f90:Cp}),r=t.mul(li.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(li));t.assign(r)}if(!0===this.sheen){const e=ci.r.max(ci.g).max(ci.b).mul(.157).oneMinus(),s=t.mul(e).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);t.assign(s)}}}const wp=Sn(1),Mp=Sn(-2),Bp=Sn(.8),Up=Sn(-1),Fp=Sn(.4),Pp=Sn(2),Ip=Sn(.305),Lp=Sn(3),Dp=Sn(.21),Vp=Sn(4),Op=Sn(4),Gp=Sn(16),kp=yn((([e])=>{const t=Un(Fo(e)).toVar(),s=Sn(-1).toVar();return _n(t.x.greaterThan(t.z),(()=>{_n(t.x.greaterThan(t.y),(()=>{s.assign(xa(e.x.greaterThan(0),0,3))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})).Else((()=>{_n(t.z.greaterThan(t.y),(()=>{s.assign(xa(e.z.greaterThan(0),2,5))})).Else((()=>{s.assign(xa(e.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),zp=yn((([e,t])=>{const s=En().toVar();return _n(t.equal(0),(()=>{s.assign(En(e.z,e.y).div(Fo(e.x)))})).ElseIf(t.equal(1),(()=>{s.assign(En(e.x.negate(),e.z.negate()).div(Fo(e.y)))})).ElseIf(t.equal(2),(()=>{s.assign(En(e.x.negate(),e.y).div(Fo(e.z)))})).ElseIf(t.equal(3),(()=>{s.assign(En(e.z.negate(),e.y).div(Fo(e.x)))})).ElseIf(t.equal(4),(()=>{s.assign(En(e.x.negate(),e.z).div(Fo(e.y)))})).Else((()=>{s.assign(En(e.x,e.y).div(Fo(e.z)))})),Gi(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),$p=yn((([e])=>{const t=Sn(0).toVar();return _n(e.greaterThanEqual(Bp),(()=>{t.assign(wp.sub(e).mul(Up.sub(Mp)).div(wp.sub(Bp)).add(Mp))})).ElseIf(e.greaterThanEqual(Fp),(()=>{t.assign(Bp.sub(e).mul(Pp.sub(Up)).div(Bp.sub(Fp)).add(Up))})).ElseIf(e.greaterThanEqual(Ip),(()=>{t.assign(Fp.sub(e).mul(Lp.sub(Pp)).div(Fp.sub(Ip)).add(Pp))})).ElseIf(e.greaterThanEqual(Dp),(()=>{t.assign(Ip.sub(e).mul(Vp.sub(Lp)).div(Ip.sub(Dp)).add(Lp))})).Else((()=>{t.assign(Sn(-2).mul(To(Gi(1.16,e))))})),t})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),Hp=yn((([e,t])=>{const s=e.toVar();s.assign(Gi(2,s).sub(1));const r=Un(s,1).toVar();return _n(t.equal(0),(()=>{r.assign(r.zyx)})).ElseIf(t.equal(1),(()=>{r.assign(r.xzy),r.xz.mulAssign(-1)})).ElseIf(t.equal(2),(()=>{r.x.mulAssign(-1)})).ElseIf(t.equal(3),(()=>{r.assign(r.zyx),r.xz.mulAssign(-1)})).ElseIf(t.equal(4),(()=>{r.assign(r.xzy),r.xy.mulAssign(-1)})).ElseIf(t.equal(5),(()=>{r.z.mulAssign(-1)})),r})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),Wp=yn((([e,t,s,r,n,i])=>{const o=Sn(s),a=Un(t),u=da($p(o),Mp,i),l=Ro(u),d=vo(u),c=Un(jp(e,a,d,r,n,i)).toVar();return _n(l.notEqual(0),(()=>{const t=Un(jp(e,a,d.add(1),r,n,i)).toVar();c.assign(la(c,t,l))})),c})),jp=yn((([e,t,s,r,n,i])=>{const o=Sn(s).toVar(),a=Un(t),u=Sn(kp(a)).toVar(),l=Sn(Ko(Op.sub(o),0)).toVar();o.assign(Ko(o,Op));const d=Sn(bo(o)).toVar(),c=En(zp(a,u).mul(d.sub(2)).add(1)).toVar();return _n(u.greaterThan(2),(()=>{c.y.addAssign(d),u.subAssign(3)})),c.x.addAssign(u.mul(d)),c.x.addAssign(l.mul(Gi(3,Gp))),c.y.addAssign(Gi(4,bo(i).sub(d))),c.x.mulAssign(r),c.y.mulAssign(n),e.uv(c).grad(En(),En())})),qp=yn((({envMap:e,mipInt:t,outputDirection:s,theta:r,axis:n,CUBEUV_TEXEL_WIDTH:i,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const u=Eo(r),l=s.mul(u).add(n.cross(s).mul(Co(r))).add(n.mul(n.dot(s).mul(u.oneMinus())));return jp(e,l,t,i,o,a)})),Kp=yn((({n:e,latitudinal:t,poleAxis:s,outputDirection:r,weights:n,samples:i,dTheta:o,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})=>{const h=Un(xa(t,s,ta(s,r))).toVar();_n(ho(h.equals(Un(0))),(()=>{h.assign(Un(r.z,0,r.x.negate()))})),h.assign(Ao(h));const p=Un().toVar();return p.addAssign(n.element(An(0)).mul(qp({theta:0,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),uc({start:An(1),end:e},(({i:e})=>{_n(e.greaterThanEqual(i),(()=>{dc()}));const t=Sn(o.mul(Sn(e))).toVar();p.addAssign(n.element(e).mul(qp({theta:t.mul(-1),axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c}))),p.addAssign(n.element(e).mul(qp({theta:t,axis:h,outputDirection:r,mipInt:a,envMap:u,CUBEUV_TEXEL_WIDTH:l,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:c})))})),Ln(p,1)}));let Xp=null;const Yp=new WeakMap;function Qp(e){let t=Yp.get(e);if((void 0!==t?t.pmremVersion:-1)!==e.pmremVersion){const s=e.image;if(e.isCubeTexture){if(!function(e){if(null==e)return!1;let t=0;const s=6;for(let r=0;r0}(s))return null;t=Xp.fromEquirectangular(e,t)}t.pmremVersion=e.pmremVersion,Yp.set(e,t)}return t.texture}class Zp extends Er{static get type(){return"PMREMNode"}constructor(e,t=null,s=null){super("vec3"),this._value=e,this._pmrem=null,this.uvNode=t,this.levelNode=s,this._generator=null;const r=new ee;r.isRenderTargetTexture=!0,this._texture=_u(r),this._width=ti(0),this._height=ti(0),this._maxMip=ti(0),this.updateBeforeType=br.RENDER}set value(e){this._value=e,this._pmrem=null}get value(){return this._value}updateFromTexture(e){const t=function(e){const t=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:s,maxMip:t}}(e.image.height);this._texture.value=e,this._width.value=t.texelWidth,this._height.value=t.texelHeight,this._maxMip.value=t.maxMip}updateBefore(){let e=this._pmrem;const t=e?e.pmremVersion:-1,s=this._value;t!==s.pmremVersion&&(e=!0===s.isPMREMTexture?s:Qp(s),null!==e&&(this._pmrem=e,this.updateFromTexture(e)))}setup(e){null===Xp&&(Xp=e.createPMREMGenerator()),this.updateBefore(e);let t=this.uvNode;null===t&&e.context.getUV&&(t=e.context.getUV(this));const s=this.value;e.renderer.coordinateSystem===b&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(t=Un(t.x.negate(),t.yz));let r=this.levelNode;return null===r&&e.context.getTextureLevel&&(r=e.context.getTextureLevel(this)),Wp(this._texture,t,r,this._width,this._height,this._maxMip)}}const Jp=mn(Zp),eg=new WeakMap;class tg extends yc{static get type(){return"EnvironmentNode"}constructor(e=null){super(),this.envNode=e}setup(e){const{material:t}=e;let s=this.envNode;if(s.isTextureNode||s.isMaterialReferenceNode){const e=s.isTextureNode?s.value:t[s.property];let r=eg.get(e);void 0===r&&(r=Jp(e),eg.set(e,r)),s=r}const r=t.envMap?Ml("envMapIntensity","float",e.material):Ml("environmentIntensity","float",e.scene),n=!0===t.useAnisotropy||t.anisotropy>0?Yl:dl,i=s.context(sg(ai,n)).mul(r),o=s.context(rg(cl)).mul(Math.PI).mul(r),a=eu(i),u=eu(o);e.context.radiance.addAssign(a),e.context.iblIrradiance.addAssign(u);const l=e.context.lightingModel.clearcoatRadiance;if(l){const e=s.context(sg(di,hl)).mul(r),t=eu(e);l.addAssign(t)}}}const sg=(e,t)=>{let s=null;return{getUV:()=>(null===s&&(s=tl.negate().reflect(t),s=e.mul(e).mix(s,t).normalize(),s=s.transformDirection(Eu)),s),getTextureLevel:()=>e}},rg=e=>({getUV:()=>e,getTextureLevel:()=>Sn(1)}),ng=new te;class ig extends nh{static get type(){return"MeshStandardNodeMaterial"}constructor(e){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(ng),this.setValues(e)}setupEnvironment(e){let t=super.setupEnvironment(e);return null===t&&e.environmentNode&&(t=e.environmentNode),t?new tg(t):null}setupLightingModel(){return new Ep}setupSpecular(){const e=la(Un(.04),ii.rgb,ui);Ti.assign(e),_i.assign(1)}setupVariants(){const e=this.metalnessNode?Sn(this.metalnessNode):yd;ui.assign(e);let t=this.roughnessNode?Sn(this.roughnessNode):fd;t=kh({roughness:t}),ai.assign(t),this.setupSpecular(),ii.assign(Ln(ii.rgb.mul(e.oneMinus()),ii.a))}copy(e){return this.emissiveNode=e.emissiveNode,this.metalnessNode=e.metalnessNode,this.roughnessNode=e.roughnessNode,super.copy(e)}}const og=new se;class ag extends ig{static get type(){return"MeshPhysicalNodeMaterial"}constructor(e){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(og),this.setValues(e)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const e=this.iorNode?Sn(this.iorNode):Bd;Ci.assign(e),Ti.assign(la(qo(ra(Ci.sub(1).div(Ci.add(1))).mul(pd),Un(1)).mul(hd),ii.rgb,ui)),_i.assign(la(hd,1,ui))}setupLightingModel(){return new Ep(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(e){if(super.setupVariants(e),this.useClearcoat){const e=this.clearcoatNode?Sn(this.clearcoatNode):xd,t=this.clearcoatRoughnessNode?Sn(this.clearcoatRoughnessNode):Td;li.assign(e),di.assign(kh({roughness:t}))}if(this.useSheen){const e=this.sheenNode?Un(this.sheenNode):vd,t=this.sheenRoughnessNode?Sn(this.sheenRoughnessNode):Sd;ci.assign(e),hi.assign(t)}if(this.useIridescence){const e=this.iridescenceNode?Sn(this.iridescenceNode):Rd,t=this.iridescenceIORNode?Sn(this.iridescenceIORNode):Cd,s=this.iridescenceThicknessNode?Sn(this.iridescenceThicknessNode):Ed;pi.assign(e),gi.assign(t),mi.assign(s)}if(this.useAnisotropy){const e=(this.anisotropyNode?En(this.anisotropyNode):Ad).toVar();yi.assign(e.length()),_n(yi.equal(0),(()=>{e.assign(En(1,0))})).Else((()=>{e.divAssign(En(yi)),yi.assign(yi.saturate())})),fi.assign(yi.pow2().mix(ai.pow2(),1)),bi.assign(ql[0].mul(e.x).add(ql[1].mul(e.y))),xi.assign(ql[1].mul(e.x).sub(ql[0].mul(e.y)))}if(this.useTransmission){const e=this.transmissionNode?Sn(this.transmissionNode):wd,t=this.thicknessNode?Sn(this.thicknessNode):Md,s=this.attenuationDistanceNode?Sn(this.attenuationDistanceNode):Ud,r=this.attenuationColorNode?Un(this.attenuationColorNode):Fd;if(Ei.assign(e),wi.assign(t),Mi.assign(s),Bi.assign(r),this.useDispersion){const e=this.dispersionNode?Sn(this.dispersionNode):Gd;Ui.assign(e)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?Un(this.clearcoatNormalNode):_d}setup(e){e.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(e),super.setup(e)}copy(e){return this.clearcoatNode=e.clearcoatNode,this.clearcoatRoughnessNode=e.clearcoatRoughnessNode,this.clearcoatNormalNode=e.clearcoatNormalNode,this.sheenNode=e.sheenNode,this.sheenRoughnessNode=e.sheenRoughnessNode,this.iridescenceNode=e.iridescenceNode,this.iridescenceIORNode=e.iridescenceIORNode,this.iridescenceThicknessNode=e.iridescenceThicknessNode,this.specularIntensityNode=e.specularIntensityNode,this.specularColorNode=e.specularColorNode,this.transmissionNode=e.transmissionNode,this.thicknessNode=e.thicknessNode,this.attenuationDistanceNode=e.attenuationDistanceNode,this.attenuationColorNode=e.attenuationColorNode,this.dispersionNode=e.dispersionNode,this.anisotropyNode=e.anisotropyNode,super.copy(e)}}class ug extends Ep{constructor(e,t,s,r){super(e,t,s),this.useSSS=r}direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){if(!0===this.useSSS){const r=n.material,{thicknessColorNode:i,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:u,thicknessPowerNode:l,thicknessScaleNode:d}=r,c=e.add(dl.mul(o)).normalize(),h=Sn(tl.dot(c.negate()).saturate().pow(l).mul(d)),p=Un(h.add(a).mul(i));s.directDiffuse.addAssign(p.mul(u.mul(t)))}super.direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n)}}class lg extends ag{static get type(){return"MeshSSSNodeMaterial"}constructor(e){super(e),this.thicknessColorNode=null,this.thicknessDistortionNode=Sn(.1),this.thicknessAmbientNode=Sn(0),this.thicknessAttenuationNode=Sn(.1),this.thicknessPowerNode=Sn(2),this.thicknessScaleNode=Sn(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new ug(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(e){return this.thicknessColorNode=e.thicknessColorNode,this.thicknessDistortionNode=e.thicknessDistortionNode,this.thicknessAmbientNode=e.thicknessAmbientNode,this.thicknessAttenuationNode=e.thicknessAttenuationNode,this.thicknessPowerNode=e.thicknessPowerNode,this.thicknessScaleNode=e.thicknessScaleNode,super.copy(e)}}const dg=yn((({normal:e,lightDirection:t,builder:s})=>{const r=e.dot(t),n=En(r.mul(.5).add(.5),0);if(s.material.gradientMap){const e=Fl("gradientMap","texture").context({getUV:()=>n});return Un(e.r)}{const e=n.fwidth().mul(.5);return la(Un(.7),Un(1),pa(Sn(.7).sub(e.x),Sn(.7).add(e.x),n.x))}}));class cg extends Ch{direct({lightDirection:e,lightColor:t,reflectedLight:s},r,n){const i=dg({normal:il,lightDirection:e,builder:n}).mul(t);s.directDiffuse.addAssign(i.mul(Uh({diffuseColor:ii.rgb})))}indirect({ambientOcclusion:e,irradiance:t,reflectedLight:s}){s.indirectDiffuse.addAssign(t.mul(Uh({diffuseColor:ii}))),s.indirectDiffuse.mulAssign(e)}}const hg=new re;class pg extends nh{static get type(){return"MeshToonNodeMaterial"}constructor(e){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(hg),this.setValues(e)}setupLightingModel(){return new cg}}class gg extends Er{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const e=Un(tl.z,0,tl.x.negate()).normalize(),t=tl.cross(e);return En(e.dot(dl),t.dot(dl)).mul(.495).add(.5)}}const mg=fn(gg),fg=new ne;class yg extends nh{static get type(){return"MeshMatcapNodeMaterial"}constructor(e){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(fg),this.setValues(e)}setupVariants(e){const t=mg;let s;s=e.material.matcap?Fl("matcap","texture").context({getUV:()=>t}):Un(la(.2,.8,t.y)),ii.rgb.mulAssign(s.rgb)}}const bg=new P;class xg extends nh{static get type(){return"PointsNodeMaterial"}constructor(e){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(bg),this.setValues(e)}copy(e){return this.sizeNode=e.sizeNode,super.copy(e)}}class Tg extends Er{static get type(){return"RotateNode"}constructor(e,t){super(),this.positionNode=e,this.rotationNode=t}getNodeType(e){return this.positionNode.getNodeType(e)}setup(e){const{rotationNode:t,positionNode:s}=this;if("vec2"===this.getNodeType(e)){const e=t.cos(),r=t.sin();return Gn(e,r,r.negate(),e).mul(s)}{const e=t,r=zn(Ln(1,0,0,0),Ln(0,Eo(e.x),Co(e.x).negate(),0),Ln(0,Co(e.x),Eo(e.x),0),Ln(0,0,0,1)),n=zn(Ln(Eo(e.y),0,Co(e.y),0),Ln(0,1,0,0),Ln(Co(e.y).negate(),0,Eo(e.y),0),Ln(0,0,0,1)),i=zn(Ln(Eo(e.z),Co(e.z).negate(),0,0),Ln(Co(e.z),Eo(e.z),0,0),Ln(0,0,1,0),Ln(0,0,0,1));return r.mul(n).mul(i).mul(Ln(s,1)).xyz}}}const _g=mn(Tg),Ng=new ie;class vg extends nh{static get type(){return"SpriteNodeMaterial"}constructor(e){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(Ng),this.setValues(e)}setupPosition({object:e,camera:t,context:s}){const r=this.sizeAttenuation,{positionNode:n,rotationNode:i,scaleNode:o}=this,a=Yu;let u=ju.mul(Un(n||0)),l=En(Gu[0].xyz.length(),Gu[1].xyz.length());if(null!==o&&(l=l.mul(o)),!r)if(t.isPerspectiveCamera)l=l.mul(u.z.negate());else{const e=Sn(2).div(Ru.element(1).element(1));l=l.mul(e.mul(2))}let d=a.xy;if(e.center&&!0===e.center.isVector2){const e=((e,t,s)=>hn(new Ga(e,t,s)))("center","vec2");d=d.sub(e.sub(.5))}d=d.mul(l);const c=Sn(i||Nd),h=_g(d,c);u=Ln(u.xy.add(h),u.zw);const p=Ru.mul(u);return s.vertex=a,p}copy(e){return this.positionNode=e.positionNode,this.rotationNode=e.rotationNode,this.scaleNode=e.scaleNode,super.copy(e)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(e){this._useSizeAttenuation!==e&&(this._useSizeAttenuation=e,this.needsUpdate=!0)}}class Sg extends Ch{constructor(){super(),this.shadowNode=Sn(1).toVar("shadowMask")}direct({shadowMask:e}){this.shadowNode.mulAssign(e)}finish(e){ii.a.mulAssign(this.shadowNode.oneMinus()),e.outgoingLight.rgb.assign(ii.rgb)}}const Ag=new oe;class Rg extends nh{static get type(){return"ShadowNodeMaterial"}constructor(e){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Ag),this.setValues(e)}setupLightingModel(){return new Sg}}const Cg=yn((({texture:e,uv:t})=>{const s=1e-4,r=Un().toVar();return _n(t.x.lessThan(s),(()=>{r.assign(Un(1,0,0))})).ElseIf(t.y.lessThan(s),(()=>{r.assign(Un(0,1,0))})).ElseIf(t.z.lessThan(s),(()=>{r.assign(Un(0,0,1))})).ElseIf(t.x.greaterThan(.9999),(()=>{r.assign(Un(-1,0,0))})).ElseIf(t.y.greaterThan(.9999),(()=>{r.assign(Un(0,-1,0))})).ElseIf(t.z.greaterThan(.9999),(()=>{r.assign(Un(0,0,-1))})).Else((()=>{const s=.01,n=e.uv(t.add(Un(-.01,0,0))).r.sub(e.uv(t.add(Un(s,0,0))).r),i=e.uv(t.add(Un(0,-.01,0))).r.sub(e.uv(t.add(Un(0,s,0))).r),o=e.uv(t.add(Un(0,0,-.01))).r.sub(e.uv(t.add(Un(0,0,s))).r);r.assign(Un(n,i,o))})),r.normalize()}));class Eg extends Tu{static get type(){return"Texture3DNode"}constructor(e,t=null,s=null){super(e,t,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return Un(.5,.5,.5)}setUpdateMatrix(){}setupUV(e,t){return t}generateUV(e,t){return t.build(e,"vec3")}normal(e){return Cg({texture:this,uv:e})}}const wg=mn(Eg);class Mg extends nh{static get type(){return"VolumeNodeMaterial"}constructor(e={}){super(),this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(e)}setup(e){const t=wg(this.map,null,0),s=yn((({orig:e,dir:t})=>{const s=Un(-.5),r=Un(.5),n=t.reciprocal(),i=s.sub(e).mul(n),o=r.sub(e).mul(n),a=qo(i,o),u=Ko(i,o),l=Ko(a.x,Ko(a.y,a.z)),d=qo(u.x,qo(u.y,u.z));return En(l,d)}));this.fragmentNode=yn((()=>{const e=Ea(Un(Wu.mul(Ln(Bu,1)))),r=Ea(Xu.sub(e)).normalize(),n=En(s({orig:e,dir:r})).toVar();n.x.greaterThan(n.y).discard(),n.assign(En(Ko(n.x,0),n.y));const i=Un(e.add(n.x.mul(r))).toVar(),o=Un(r.abs().reciprocal()).toVar(),a=Sn(qo(o.x,qo(o.y,o.z))).toVar("delta");a.divAssign(Fl("steps","float"));const u=Ln(Fl("base","color"),0).toVar();return uc({type:"float",start:n.x,end:n.y,update:"+= delta"},(()=>{const e=ri("float","d").assign(t.uv(i.add(.5)).r);null!==this.testNode?this.testNode({map:t,mapValue:e,probe:i,finalColor:u}).append():(u.a.assign(1),dc()),i.addAssign(r.mul(a))})),u.a.equal(0).discard(),Ln(u)}))(),super.setup(e)}}class Bg{constructor(e,t){this.nodes=e,this.info=t,this._context=self,this._animationLoop=null,this._requestId=null}start(){const e=(t,s)=>{this._requestId=this._context.requestAnimationFrame(e),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this._animationLoop&&this._animationLoop(t,s)};e()}stop(){this._context.cancelAnimationFrame(this._requestId),this._requestId=null}setAnimationLoop(e){this._animationLoop=e}setContext(e){this._context=e}dispose(){this.stop()}}class Ug{constructor(){this.weakMap=new WeakMap}get(e){let t=this.weakMap;for(let s=0;s{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(e){this.clippingContext=e}get clippingNeedsUpdate(){return null!==this.clippingContext&&this.clippingContext.cacheKey!==this.clippingContextCacheKey&&(this.clippingContextCacheKey=this.clippingContext.cacheKey,!0)}get hardwareClippingPlanes(){return!0===this.material.hardwareClipping?this.clippingContext.unionClippingCount:0}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}setGeometry(e){this.geometry=e,this.attributes=null}getAttributes(){if(null!==this.attributes)return this.attributes;const e=this.getNodeBuilderState().nodeAttributes,t=this.geometry,s=[],r=new Set;for(const n of e){const e=n.node&&n.node.attribute?n.node.attribute:t.getAttribute(n.name);if(void 0===e)continue;s.push(e);const i=e.isInterleavedBufferAttribute?e.data:e;r.add(i)}return this.attributes=s,this.vertexBuffers=Array.from(r.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:e,material:t,geometry:s,group:r,drawRange:n}=this,i=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),o=this.getIndex(),a=null!==o,u=s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1;if(0===u)return null;if(i.instanceCount=u,!0===e.isBatchedMesh)return i;let l=1;!0!==t.wireframe||e.isPoints||e.isLineSegments||e.isLine||e.isLineLoop||(l=2);let d=n.start*l,c=(n.start+n.count)*l;null!==r&&(d=Math.max(d,r.start*l),c=Math.min(c,(r.start+r.count)*l));const h=s.attributes.position;let p=1/0;a?p=o.count:null!=h&&(p=h.count),d=Math.max(d,0),c=Math.min(c,p);const g=c-d;return g<0||g===1/0?null:(i.vertexCount=g,i.firstVertex=d,i)}getGeometryCacheKey(){const{geometry:e}=this;let t="";for(const s of Object.keys(e.attributes).sort()){const r=e.attributes[s];t+=s+",",r.data&&(t+=r.data.stride+","),r.offset&&(t+=r.offset+","),r.itemSize&&(t+=r.itemSize+","),r.normalized&&(t+="n,")}return e.index&&(t+="index,"),t}getMaterialCacheKey(){const{object:e,material:t}=this;let s=t.customProgramCacheKey();for(const e of function(e){const t=Object.keys(e);let s=Object.getPrototypeOf(e);for(;s;){const e=Object.getOwnPropertyDescriptors(s);for(const s in e)if(void 0!==e[s]){const r=e[s];r&&"function"==typeof r.get&&t.push(s)}s=Object.getPrototypeOf(s)}return t}(t)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(e))continue;const r=t[e];let n;if(null!==r){const e=typeof r;"number"===e?n=0!==r?"1":"0":"object"===e?(n="{",r.isTexture&&(n+=r.mapping),n+="}"):n=String(r)}else n=String(r);s+=n+","}return s+=this.clippingContextCacheKey+",",e.geometry&&(s+=this.getGeometryCacheKey()),e.skeleton&&(s+=e.skeleton.bones.length+","),e.morphTargetInfluences&&(s+=e.morphTargetInfluences.length+","),e.isBatchedMesh&&(s+=e._matricesTexture.uuid+",",null!==e._colorsTexture&&(s+=e._colorsTexture.uuid+",")),e.count>1&&(s+=e.uuid+","),ar(s)}get needsGeometryUpdate(){return this.geometry.id!==this.object.geometry.id}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let e=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(e+=1),e}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const Ig=[];class Lg{constructor(e,t,s,r,n,i){this.renderer=e,this.nodes=t,this.geometries=s,this.pipelines=r,this.bindings=n,this.info=i,this.chainMaps={}}get(e,t,s,r,n,i,o,a){const u=this.getChainMap(a);Ig[0]=e,Ig[1]=t,Ig[2]=i,Ig[3]=n;let l=u.get(Ig);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,e,t,s,r,n,i,o,a),u.set(Ig,l)):(l.updateClipping(o),l.needsGeometryUpdate&&l.setGeometry(e.geometry),(l.version!==t.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(e,t,s,r,n,i,o,a)):l.version=t.version)),l}getChainMap(e="default"){return this.chainMaps[e]||(this.chainMaps[e]=new Ug)}dispose(){this.chainMaps={}}createRenderObject(e,t,s,r,n,i,o,a,u,l,d){const c=this.getChainMap(d),h=new Pg(e,t,s,r,n,i,o,a,u,l);return h.onDispose=()=>{this.pipelines.delete(h),this.bindings.delete(h),this.nodes.delete(h),c.delete(h.getChainArray())},h}}class Dg{constructor(){this.data=new WeakMap}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}delete(e){let t;return this.data.has(e)&&(t=this.data.get(e),this.data.delete(e)),t}has(e){return this.data.has(e)}dispose(){this.data=new WeakMap}}const Vg=1,Og=2,Gg=3,kg=4,zg=16;class $g extends Dg{constructor(e){super(),this.backend=e}delete(e){const t=super.delete(e);return void 0!==t&&this.backend.destroyAttribute(e),t}update(e,t){const s=this.get(e);if(void 0===s.version)t===Vg?this.backend.createAttribute(e):t===Og?this.backend.createIndexAttribute(e):t===Gg?this.backend.createStorageAttribute(e):t===kg&&this.backend.createIndirectStorageAttribute(e),s.version=this._getBufferAttribute(e).version;else{const t=this._getBufferAttribute(e);(s.version=0;--t)if(e[t]>=65535)return!0;return!1}(t)?ae:ue)(t,1);return n.version=Hg(e),n}class jg extends Dg{constructor(e,t){super(),this.attributes=e,this.info=t,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(e){const t=e.geometry;return super.has(t)&&!0===this.get(t).initialized}updateForRender(e){!1===this.has(e)&&this.initGeometry(e),this.updateAttributes(e)}initGeometry(e){const t=e.geometry;this.get(t).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const r=t.index,n=e.getAttributes();null!==r&&this.attributes.delete(r);for(const e of n)this.attributes.delete(e);const i=this.wireframes.get(t);void 0!==i&&this.attributes.delete(i),t.removeEventListener("dispose",s)};t.addEventListener("dispose",s)}updateAttributes(e){const t=e.getAttributes();for(const e of t)e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute?this.updateAttribute(e,Gg):this.updateAttribute(e,Vg);const s=this.getIndex(e);null!==s&&this.updateAttribute(s,Og);const r=e.geometry.indirect;null!==r&&this.updateAttribute(r,kg)}updateAttribute(e,t){const s=this.info.render.calls;e.isInterleavedBufferAttribute?void 0===this.attributeCall.get(e)?(this.attributes.update(e,t),this.attributeCall.set(e,s)):this.attributeCall.get(e.data)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e.data,s),this.attributeCall.set(e,s)):this.attributeCall.get(e)!==s&&(this.attributes.update(e,t),this.attributeCall.set(e,s))}getIndirect(e){return e.geometry.indirect}getIndex(e){const{geometry:t,material:s}=e;let r=t.index;if(!0===s.wireframe){const e=this.wireframes;let s=e.get(t);void 0===s?(s=Wg(t),e.set(t,s)):s.version!==Hg(t)&&(this.attributes.delete(s),s=Wg(t),e.set(t,s)),r=s}return r}}class qg{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(e,t,s){this.render.drawCalls++,e.isMesh||e.isSprite?this.render.triangles+=s*(t/3):e.isPoints?this.render.points+=s*t:e.isLineSegments?this.render.lines+=s*(t/2):e.isLine?this.render.lines+=s*(t-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(e,t){0===this[e].timestampCalls&&(this[e].timestamp=0),this[e].timestamp+=t,this[e].timestampCalls++,this[e].timestampCalls>=this[e].previousFrameCalls&&(this[e].timestampCalls=0)}reset(){const e=this.render.frameCalls;this.render.previousFrameCalls=e;const t=this.compute.frameCalls;this.compute.previousFrameCalls=t,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Kg{constructor(e){this.cacheKey=e,this.usedTimes=0}}class Xg extends Kg{constructor(e,t,s){super(e),this.vertexProgram=t,this.fragmentProgram=s}}class Yg extends Kg{constructor(e,t){super(e),this.computeProgram=t,this.isComputePipeline=!0}}let Qg=0;class Zg{constructor(e,t,s=null,r=null){this.id=Qg++,this.code=e,this.stage=t,this.transforms=s,this.attributes=r,this.usedTimes=0}}class Jg extends Dg{constructor(e,t){super(),this.backend=e,this.nodes=t,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(e,t){const{backend:s}=this,r=this.get(e);if(this._needsComputeUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.computeProgram.usedTimes--);const i=this.nodes.getForCompute(e);let o=this.programs.compute.get(i.computeShader);void 0===o&&(n&&0===n.computeProgram.usedTimes&&this._releaseProgram(n.computeProgram),o=new Zg(i.computeShader,"compute",i.transforms,i.nodeAttributes),this.programs.compute.set(i.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(e,o);let u=this.caches.get(a);void 0===u&&(n&&0===n.usedTimes&&this._releasePipeline(n),u=this._getComputePipeline(e,o,a,t)),u.usedTimes++,o.usedTimes++,r.version=e.version,r.pipeline=u}return r.pipeline}getForRender(e,t=null){const{backend:s}=this,r=this.get(e);if(this._needsRenderUpdate(e)){const n=r.pipeline;n&&(n.usedTimes--,n.vertexProgram.usedTimes--,n.fragmentProgram.usedTimes--);const i=e.getNodeBuilderState();let o=this.programs.vertex.get(i.vertexShader);void 0===o&&(n&&0===n.vertexProgram.usedTimes&&this._releaseProgram(n.vertexProgram),o=new Zg(i.vertexShader,"vertex"),this.programs.vertex.set(i.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(i.fragmentShader);void 0===a&&(n&&0===n.fragmentProgram.usedTimes&&this._releaseProgram(n.fragmentProgram),a=new Zg(i.fragmentShader,"fragment"),this.programs.fragment.set(i.fragmentShader,a),s.createProgram(a));const u=this._getRenderCacheKey(e,o,a);let l=this.caches.get(u);void 0===l?(n&&0===n.usedTimes&&this._releasePipeline(n),l=this._getRenderPipeline(e,o,a,u,t)):e.pipeline=l,l.usedTimes++,o.usedTimes++,a.usedTimes++,r.pipeline=l}return r.pipeline}delete(e){const t=this.get(e).pipeline;return t&&(t.usedTimes--,0===t.usedTimes&&this._releasePipeline(t),t.isComputePipeline?(t.computeProgram.usedTimes--,0===t.computeProgram.usedTimes&&this._releaseProgram(t.computeProgram)):(t.fragmentProgram.usedTimes--,t.vertexProgram.usedTimes--,0===t.vertexProgram.usedTimes&&this._releaseProgram(t.vertexProgram),0===t.fragmentProgram.usedTimes&&this._releaseProgram(t.fragmentProgram))),super.delete(e)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(e){this.getForRender(e)}_getComputePipeline(e,t,s,r){s=s||this._getComputeCacheKey(e,t);let n=this.caches.get(s);return void 0===n&&(n=new Yg(s,t),this.caches.set(s,n),this.backend.createComputePipeline(n,r)),n}_getRenderPipeline(e,t,s,r,n){r=r||this._getRenderCacheKey(e,t,s);let i=this.caches.get(r);return void 0===i&&(i=new Xg(r,t,s),this.caches.set(r,i),e.pipeline=i,this.backend.createRenderPipeline(e,n)),i}_getComputeCacheKey(e,t){return e.id+","+t.id}_getRenderCacheKey(e,t,s){return t.id+","+s.id+","+this.backend.getRenderCacheKey(e)}_releasePipeline(e){this.caches.delete(e.cacheKey)}_releaseProgram(e){const t=e.code,s=e.stage;this.programs[s].delete(t)}_needsComputeUpdate(e){const t=this.get(e);return void 0===t.pipeline||t.version!==e.version}_needsRenderUpdate(e){return void 0===this.get(e).pipeline||this.backend.needsRenderUpdate(e)}}class em extends Dg{constructor(e,t,s,r,n,i){super(),this.backend=e,this.textures=s,this.pipelines=n,this.attributes=r,this.nodes=t,this.info=i,this.pipelines.bindings=this}getForRender(e){const t=e.getBindings();for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}getForCompute(e){const t=this.nodes.getForCompute(e).bindings;for(const e of t){const s=this.get(e);void 0===s.bindGroup&&(this._init(e),this.backend.createBindings(e,t,0),s.bindGroup=e)}return t}updateForCompute(e){this._updateBindings(this.getForCompute(e))}updateForRender(e){this._updateBindings(this.getForRender(e))}_updateBindings(e){for(const t of e)this._update(t,e)}_init(e){for(const t of e.bindings)if(t.isSampledTexture)this.textures.updateTexture(t.texture);else if(t.isStorageBuffer){const e=t.attribute,s=e.isIndirectStorageBufferAttribute?kg:Gg;this.attributes.update(e,s)}}_update(e,t){const{backend:s}=this;let r=!1,n=!0,i=0,o=0;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&s.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=this.textures.get(t.texture);t.needsBindingsUpdate(e.generation)&&(r=!0);const a=t.update(),u=t.texture;a&&this.textures.updateTexture(u);const l=s.get(u);if(void 0!==l.externalTexture||e.isDefaultTexture?n=!1:(i=10*i+u.id,o+=u.version),!0===s.isWebGPUBackend&&void 0===l.texture&&void 0===l.externalTexture&&(console.error("Bindings._update: binding should be available:",t,a,u,t.textureNode.value,r),this.textures.updateTexture(u),r=!0),!0===u.isStorageTexture){const e=this.get(u);!0===t.store?e.needsMipmap=!0:this.textures.needsMipmaps(u)&&!0===e.needsMipmap&&(this.backend.generateMipmaps(u),e.needsMipmap=!1)}}}!0===r&&this.backend.updateBindings(e,t,n?i:0,o)}}function tm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.material.id!==t.material.id?e.material.id-t.material.id:e.z!==t.z?e.z-t.z:e.id-t.id}function sm(e,t){return e.groupOrder!==t.groupOrder?e.groupOrder-t.groupOrder:e.renderOrder!==t.renderOrder?e.renderOrder-t.renderOrder:e.z!==t.z?t.z-e.z:e.id-t.id}function rm(e){return(e.transmission>0||e.transmissionNode)&&e.side===le&&!1===e.forceSinglePass}class nm{constructor(e,t,s){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=e.getNode(t,s),this.lightsArray=[],this.scene=t,this.camera=s,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(e,t,s,r,n,i,o){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:e.id,object:e,geometry:t,material:s,groupOrder:r,renderOrder:e.renderOrder,z:n,group:i,clippingContext:o},this.renderItems[this.renderItemsIndex]=a):(a.id=e.id,a.object=e,a.geometry=t,a.material=s,a.groupOrder=r,a.renderOrder=e.renderOrder,a.z=n,a.group=i,a.clippingContext=o),this.renderItemsIndex++,a}push(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===e.occlusionTest&&this.occlusionQueryCount++,!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(e,t,s,r,n,i,o){const a=this.getNextRenderItem(e,t,s,r,n,i,o);!0===s.transparent||s.transmission>0?(rm(s)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(e){this.bundles.push(e)}pushLight(e){this.lightsArray.push(e)}sort(e,t){this.opaque.length>1&&this.opaque.sort(e||tm),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(t||sm),this.transparent.length>1&&this.transparent.sort(t||sm)}finish(){this.lightsNode.setLights(this.lightsArray);for(let e=this.renderItemsIndex,t=this.renderItems.length;e>t,u=o.height>>t;let l=e.depthTexture||n[t];const d=!0===e.depthBuffer||!0===e.stencilBuffer;let c=!1;void 0===l&&d&&(l=new B,l.format=e.stencilBuffer?de:ce,l.type=e.stencilBuffer?he:f,l.image.width=a,l.image.height=u,n[t]=l),s.width===o.width&&o.height===s.height||(c=!0,l&&(l.needsUpdate=!0,l.image.width=a,l.image.height=u)),s.width=o.width,s.height=o.height,s.textures=i,s.depthTexture=l||null,s.depth=e.depthBuffer,s.stencil=e.stencilBuffer,s.renderTarget=e,s.sampleCount!==r&&(c=!0,l&&(l.needsUpdate=!0),s.sampleCount=r);const h={sampleCount:r};for(let e=0;e{e.removeEventListener("dispose",t);for(let e=0;e0){const r=e.image;if(void 0===r)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===r.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(e.images){const s=[];for(const t of e.images)s.push(t);t.images=s}else t.image=r;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(n.createTexture(e,t),s.isDefaultTexture=!1,s.generation=e.version),!0===e.source.dataReady&&n.updateTexture(e,t),t.needsMipmaps&&0===e.mipmaps.length&&n.generateMipmaps(e)}}else n.createDefaultTexture(e),s.isDefaultTexture=!0,s.generation=e.version}if(!0!==s.initialized){s.initialized=!0,s.generation=e.version,this.info.memory.textures++;const t=()=>{e.removeEventListener("dispose",t),this._destroyTexture(e),this.info.memory.textures--};e.addEventListener("dispose",t)}s.version=e.version}getSize(e,t=dm){let s=e.images?e.images[0]:e.image;return s?(void 0!==s.image&&(s=s.image),t.width=s.width||1,t.height=s.height||1,t.depth=e.isCubeTexture?6:s.depth||1):t.width=t.height=t.depth=1,t}getMipLevels(e,t,s){let r;return r=e.isCompressedTexture?e.mipmaps?e.mipmaps.length:1:Math.floor(Math.log2(Math.max(t,s)))+1,r}needsMipmaps(e){return this.isEnvironmentTexture(e)||!0===e.isCompressedTexture||e.generateMipmaps}isEnvironmentTexture(e){const t=e.mapping;return t===j||t===q||t===T||t===_}_destroyTexture(e){this.backend.destroySampler(e),this.backend.destroyTexture(e),this.delete(e)}}class hm extends e{constructor(e,t,s,r=1){super(e,t,s),this.a=r}set(e,t,s,r=1){return this.a=r,super.set(e,t,s)}copy(e){return void 0!==e.a&&(this.a=e.a),super.copy(e)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}class pm extends si{static get type(){return"ParameterNode"}constructor(e,t=null){super(e,t),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const gm=(e,t)=>hn(new pm(e,t));class mm extends Ar{static get type(){return"StackNode"}constructor(e=null){super(),this.nodes=[],this.outputNode=null,this.parent=e,this._currentCond=null,this.isStackNode=!0}getNodeType(e){return this.outputNode?this.outputNode.getNodeType(e):"void"}add(e){return this.nodes.push(e),this}If(e,t){const s=new cn(t);return this._currentCond=xa(e,s),this.add(this._currentCond)}ElseIf(e,t){const s=new cn(t),r=xa(e,s);return this._currentCond.elseNode=r,this._currentCond=r,this}Else(e){return this._currentCond.elseNode=new cn(e),this}build(e,...t){const s=Tn();xn(this);for(const t of this.nodes)t.build(e,"void");return xn(s),this.outputNode?this.outputNode.build(e,...t):super.build(e,...t)}else(...e){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...e)}elseif(...e){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...e)}}const fm=mn(mm);class ym extends Ar{static get type(){return"StructTypeNode"}constructor(e){super(),this.types=e,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}class bm extends Ar{static get type(){return"OutputStructNode"}constructor(...e){super(),this.members=e,this.isOutputStructNode=!0}setup(e){super.setup(e);const t=this.members,s=[];for(let r=0;r{const t=e.toUint().mul(747796405).add(2891336453),s=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return s.shiftRight(22).bitXor(s).toFloat().mul(1/2**32)})),Sm=(e,t)=>sa(Gi(4,e.mul(Oi(1,e))),t),Am=(e,t)=>e.lessThan(.5)?Sm(e.mul(2),t).div(2):Oi(1,Sm(Gi(Oi(1,e),2),t).div(2)),Rm=(e,t,s)=>sa(ki(sa(e,t),Vi(sa(e,t),sa(Oi(1,e),s))),1/t),Cm=(e,t)=>Co(lo.mul(t.mul(e).sub(1))).div(lo.mul(t.mul(e).sub(1))),Em=yn((([e])=>e.fract().sub(.5).abs())).setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),wm=yn((([e])=>Un(Em(e.z.add(Em(e.y.mul(1)))),Em(e.z.add(Em(e.x.mul(1)))),Em(e.y.add(Em(e.x.mul(1))))))).setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),Mm=yn((([e,t,s])=>{const r=Un(e).toVar(),n=Sn(1.4).toVar(),i=Sn(0).toVar(),o=Un(r).toVar();return uc({start:Sn(0),end:Sn(3),type:"float",condition:"<="},(()=>{const e=Un(wm(o.mul(2))).toVar();r.addAssign(e.add(s.mul(Sn(.1).mul(t)))),o.mulAssign(1.8),n.mulAssign(1.5),r.mulAssign(1.2);const a=Sn(Em(r.z.add(Em(r.x.add(Em(r.y)))))).toVar();i.addAssign(a.div(n)),o.addAssign(.14)})),i})).setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class Bm extends Ar{static get type(){return"FunctionOverloadingNode"}constructor(e=[],...t){super(),this.functionNodes=e,this.parametersNodes=t,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(e){const t=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let r=null,n=-1;for(const s of this.functionNodes){const i=s.shaderNode.layout;if(null===i)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=i.inputs;if(t.length===o.length){let i=0;for(let s=0;sn&&(r=s,n=i)}}this._candidateFnCall=s=r(...t)}return s}}const Um=mn(Bm),Fm=e=>(...t)=>Um(e,...t),Pm=ti(0).setGroup(Zn).onRenderUpdate((e=>e.time)),Im=ti(0).setGroup(Zn).onRenderUpdate((e=>e.deltaTime)),Lm=ti(0,"uint").setGroup(Zn).onRenderUpdate((e=>e.frameId)),Dm=(e=1)=>(console.warn('TSL: timerLocal() is deprecated. Use "time" instead.'),Pm.mul(e)),Vm=(e=1)=>(console.warn('TSL: timerGlobal() is deprecated. Use "time" instead.'),Pm.mul(e)),Om=(e=1)=>(console.warn('TSL: timerDelta() is deprecated. Use "deltaTime" instead.'),Im.mul(e)),Gm=(e=Pm)=>e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5),km=(e=Pm)=>e.fract().round(),zm=(e=Pm)=>e.add(.5).fract().mul(2).sub(1).abs(),$m=(e=Pm)=>e.fract(),Hm=yn((([e,t,s=En(.5)])=>_g(e.sub(s),t).add(s))),Wm=yn((([e,t,s=En(.5)])=>{const r=e.sub(s),n=r.dot(r),i=n.mul(n).mul(t);return e.add(r.mul(i))})),jm=yn((({position:e=null,horizontal:t=!0,vertical:s=!1})=>{let r;null!==e?(r=Gu.toVar(),r[3][0]=e.x,r[3][1]=e.y,r[3][2]=e.z):r=Gu;const n=Eu.mul(r);return ln(t)&&(n[0][0]=Gu[0].length(),n[0][1]=0,n[0][2]=0),ln(s)&&(n[1][0]=0,n[1][1]=Gu[1].length(),n[1][2]=0),n[2][0]=0,n[2][1]=0,n[2][2]=1,Ru.mul(n).mul(Yu)})),qm=yn((([e=null])=>{const t=Qc();return Qc(kc(e)).sub(t).lessThan(0).select(Ac,e)}));class Km extends Ar{static get type(){return"SpriteSheetUVNode"}constructor(e,t=mu(),s=Sn(0)){super("vec2"),this.countNode=e,this.uvNode=t,this.frameNode=s}setup(){const{frameNode:e,uvNode:t,countNode:s}=this,{width:r,height:n}=s,i=e.mod(r.mul(n)).floor(),o=i.mod(r),a=n.sub(i.add(1).div(r).ceil()),u=s.reciprocal(),l=En(o,a);return t.add(l).mul(u)}}const Xm=mn(Km);class Ym extends Ar{static get type(){return"TriplanarTexturesNode"}constructor(e,t=null,s=null,r=Sn(1),n=Yu,i=ol){super("vec4"),this.textureXNode=e,this.textureYNode=t,this.textureZNode=s,this.scaleNode=r,this.positionNode=n,this.normalNode=i}setup(){const{textureXNode:e,textureYNode:t,textureZNode:s,scaleNode:r,positionNode:n,normalNode:i}=this;let o=i.abs().normalize();o=o.div(o.dot(Un(1)));const a=n.yz.mul(r),u=n.zx.mul(r),l=n.xy.mul(r),d=e.value,c=null!==t?t.value:d,h=null!==s?s.value:d,p=_u(d,a).mul(o.x),g=_u(c,u).mul(o.y),m=_u(h,l).mul(o.z);return Vi(p,g,m)}}const Qm=mn(Ym),Zm=(...e)=>Qm(...e),Jm=new me,ef=new s,tf=new s,sf=new s,rf=new i,nf=new s(0,0,-1),of=new r,af=new s,uf=new s,lf=new r,df=new t,cf=new ge,hf=Ac.flipX();cf.depthTexture=new B(1,1);let pf=!1;class gf extends Tu{static get type(){return"ReflectorNode"}constructor(e={}){super(e.defaultTexture||cf.texture,hf),this._reflectorBaseNode=e.reflector||new mf(this,e),this._depthNode=null,this.setUpdateMatrix(!1)}get reflector(){return this._reflectorBaseNode}get target(){return this._reflectorBaseNode.target}getDepthNode(){if(null===this._depthNode){if(!0!==this._reflectorBaseNode.depth)throw new Error("THREE.ReflectorNode: Depth node can only be requested when the reflector is created with { depth: true }. ");this._depthNode=hn(new gf({defaultTexture:cf.depthTexture,reflector:this._reflectorBaseNode}))}return this._depthNode}setup(e){return e.object.isQuadMesh||this._reflectorBaseNode.build(e),super.setup(e)}clone(){const e=new this.constructor(this.reflectorNode);return e._reflectorBaseNode=this._reflectorBaseNode,e}}class mf extends Ar{static get type(){return"ReflectorBaseNode"}constructor(e,t={}){super();const{target:s=new fe,resolution:r=1,generateMipmaps:n=!1,bounces:i=!0,depth:o=!1}=t;this.textureNode=e,this.target=s,this.resolution=r,this.generateMipmaps=n,this.bounces=i,this.depth=o,this.updateBeforeType=i?br.RENDER:br.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(e,t){const s=this.resolution;t.getDrawingBufferSize(df),e.setSize(Math.round(df.width*s),Math.round(df.height*s))}setup(e){return this._updateResolution(cf,e.renderer),super.setup(e)}getVirtualCamera(e){let t=this.virtualCameras.get(e);return void 0===t&&(t=e.clone(),this.virtualCameras.set(e,t)),t}getRenderTarget(e){let t=this.renderTargets.get(e);return void 0===t&&(t=new ge(0,0,{type:ye}),!0===this.generateMipmaps&&(t.texture.minFilter=be,t.texture.generateMipmaps=!0),!0===this.depth&&(t.depthTexture=new B),this.renderTargets.set(e,t)),t}updateBefore(e){if(!1===this.bounces&&pf)return;pf=!0;const{scene:t,camera:s,renderer:r,material:n}=e,{target:i}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(r.getDrawingBufferSize(df),this._updateResolution(a,r),tf.setFromMatrixPosition(i.matrixWorld),sf.setFromMatrixPosition(s.matrixWorld),rf.extractRotation(i.matrixWorld),ef.set(0,0,1),ef.applyMatrix4(rf),af.subVectors(tf,sf),af.dot(ef)>0)return;af.reflect(ef).negate(),af.add(tf),rf.extractRotation(s.matrixWorld),nf.set(0,0,-1),nf.applyMatrix4(rf),nf.add(sf),uf.subVectors(tf,nf),uf.reflect(ef).negate(),uf.add(tf),o.coordinateSystem=s.coordinateSystem,o.position.copy(af),o.up.set(0,1,0),o.up.applyMatrix4(rf),o.up.reflect(ef),o.lookAt(uf),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),Jm.setFromNormalAndCoplanarPoint(ef,tf),Jm.applyMatrix4(o.matrixWorldInverse),of.set(Jm.normal.x,Jm.normal.y,Jm.normal.z,Jm.constant);const u=o.projectionMatrix;lf.x=(Math.sign(of.x)+u.elements[8])/u.elements[0],lf.y=(Math.sign(of.y)+u.elements[9])/u.elements[5],lf.z=-1,lf.w=(1+u.elements[10])/u.elements[14],of.multiplyScalar(1/of.dot(lf));u.elements[2]=of.x,u.elements[6]=of.y,u.elements[10]=r.coordinateSystem===N?of.z-0:of.z+1-0,u.elements[14]=of.w,this.textureNode.value=a.texture,!0===this.depth&&(this.textureNode.getDepthNode().value=a.depthTexture),n.visible=!1;const l=r.getRenderTarget(),d=r.getMRT();r.setMRT(null),r.setRenderTarget(a),r.render(t,o),r.setMRT(d),r.setRenderTarget(l),n.visible=!0,pf=!1}}const ff=e=>hn(new gf(e)),yf=new xe(-1,1,1,-1,0,1);class bf extends Te{constructor(e=!1){super();const t=!1===e?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new _e([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new _e(t,2))}}const xf=new bf;class Tf extends k{constructor(e=null){super(xf,e),this.camera=yf,this.isQuadMesh=!0}renderAsync(e){return e.renderAsync(this,yf)}render(e){e.render(this,yf)}}const _f=new t;class Nf extends Tu{static get type(){return"RTTNode"}constructor(e,t=null,s=null,r={type:ye}){const n=new ge(t,s,r);super(n.texture,mu()),this.node=e,this.width=t,this.height=s,this.renderTarget=n,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new Tf(new nh),this.updateBeforeType=br.RENDER}get autoSize(){return null===this.width}setup(e){return this._rttNode=this.node.context(e.getSharedContext()),this._quadMesh.material.name="RTT",this._quadMesh.material.needsUpdate=!0,super.setup(e)}setSize(e,t){this.width=e,this.height=t;const s=e*this.pixelRatio,r=t*this.pixelRatio;this.renderTarget.setSize(s,r),this.textureNeedsUpdate=!0}setPixelRatio(e){this.pixelRatio=e,this.setSize(this.width,this.height)}updateBefore({renderer:e}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=e.getPixelRatio();const t=e.getSize(_f);this.setSize(t.width,t.height)}this._quadMesh.material.fragmentNode=this._rttNode;const t=e.getRenderTarget();e.setRenderTarget(this.renderTarget),this._quadMesh.render(e),e.setRenderTarget(t)}clone(){const e=new Tu(this.value,this.uvNode,this.levelNode);return e.sampler=this.sampler,e.referenceNode=this,e}}const vf=(e,...t)=>hn(new Nf(hn(e),...t)),Sf=(e,...t)=>e.isTextureNode?e:vf(e,...t),Af=yn((([e,t,s],r)=>{let n;r.renderer.coordinateSystem===N?(e=En(e.x,e.y.oneMinus()).mul(2).sub(1),n=Ln(Un(e,t),1)):n=Ln(Un(e.x,e.y.oneMinus(),t).mul(2).sub(1),1);const i=Ln(s.mul(n));return i.xyz.div(i.w)})),Rf=yn((([e,t])=>{const s=t.mul(Ln(e,1)),r=s.xy.div(s.w).mul(.5).add(.5).toVar();return En(r.x,r.y.oneMinus())})),Cf=yn((([e,t,s])=>{const r=yu(Nu(t)),n=wn(e.mul(r)).toVar(),i=Nu(t,n).toVar(),o=Nu(t,n.sub(wn(2,0))).toVar(),a=Nu(t,n.sub(wn(1,0))).toVar(),u=Nu(t,n.add(wn(1,0))).toVar(),l=Nu(t,n.add(wn(2,0))).toVar(),d=Nu(t,n.add(wn(0,2))).toVar(),c=Nu(t,n.add(wn(0,1))).toVar(),h=Nu(t,n.sub(wn(0,1))).toVar(),p=Nu(t,n.sub(wn(0,2))).toVar(),g=Fo(Oi(Sn(2).mul(a).sub(o),i)).toVar(),m=Fo(Oi(Sn(2).mul(u).sub(l),i)).toVar(),f=Fo(Oi(Sn(2).mul(c).sub(d),i)).toVar(),y=Fo(Oi(Sn(2).mul(h).sub(p),i)).toVar(),b=Af(e,i,s).toVar(),x=g.lessThan(m).select(b.sub(Af(e.sub(En(Sn(1).div(r.x),0)),a,s)),b.negate().add(Af(e.add(En(Sn(1).div(r.x),0)),u,s))),T=f.lessThan(y).select(b.sub(Af(e.add(En(0,Sn(1).div(r.y))),c,s)),b.negate().add(Af(e.sub(En(0,Sn(1).div(r.y))),h,s)));return Ao(ta(x,T))}));class Ef extends pu{static get type(){return"VertexColorNode"}constructor(e=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=e}getAttributeName(){const e=this.index;return"color"+(e>0?e:"")}generate(e){const t=this.getAttributeName(e);let s;return s=!0===e.hasGeometryAttribute(t)?super.generate(e):e.generateConst(this.nodeType,new r(1,1,1,1)),s}serialize(e){super.serialize(e),e.index=this.index}deserialize(e){super.deserialize(e),this.index=e.index}}const wf=(...e)=>hn(new Ef(...e));class Mf extends Ar{static get type(){return"PointUVNode"}constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const Bf=fn(Mf),Uf=new ve,Ff=new i;class Pf extends Ar{static get type(){return"SceneNode"}constructor(e=Pf.BACKGROUND_BLURRINESS,t=null){super(),this.scope=e,this.scene=t}setup(e){const t=this.scope,s=null!==this.scene?this.scene:e.scene;let r;return t===Pf.BACKGROUND_BLURRINESS?r=Ml("backgroundBlurriness","float",s):t===Pf.BACKGROUND_INTENSITY?r=Ml("backgroundIntensity","float",s):t===Pf.BACKGROUND_ROTATION?r=ti("mat4").label("backgroundRotation").setGroup(Zn).onRenderUpdate((()=>{const e=s.background;return null!==e&&e.isTexture&&e.mapping!==Ne?(Uf.copy(s.backgroundRotation),Uf.x*=-1,Uf.y*=-1,Uf.z*=-1,Ff.makeRotationFromEuler(Uf)):Ff.identity(),Ff})):console.error("THREE.SceneNode: Unknown scope:",t),r}}Pf.BACKGROUND_BLURRINESS="backgroundBlurriness",Pf.BACKGROUND_INTENSITY="backgroundIntensity",Pf.BACKGROUND_ROTATION="backgroundRotation";const If=fn(Pf,Pf.BACKGROUND_BLURRINESS),Lf=fn(Pf,Pf.BACKGROUND_INTENSITY),Df=fn(Pf,Pf.BACKGROUND_ROTATION);class Vf extends Rr{static get type(){return"StorageArrayElementNode"}constructor(e,t){super(e,t),this.isStorageArrayElementNode=!0}set storageBufferNode(e){this.node=e}get storageBufferNode(){return this.node}setup(e){return!1===e.isAvailable("storageBuffer")&&!0===this.node.bufferObject&&e.setupPBO(this.node),super.setup(e)}generate(e,t){let s;const r=e.context.assign;if(s=!1===e.isAvailable("storageBuffer")?!0===this.node.bufferObject&&!0!==r?e.generatePBO(this):this.node.build(e):super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}const Of=mn(Vf),Gf="point-list",kf="line-list",zf="line-strip",$f="triangle-list",Hf="triangle-strip",Wf="never",jf="less",qf="equal",Kf="less-equal",Xf="greater",Yf="not-equal",Qf="greater-equal",Zf="always",Jf="store",ey="load",ty="clear",sy="ccw",ry="none",ny="front",iy="back",oy="uint16",ay="uint32",uy={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},ly="clamp-to-edge",dy="repeat",cy="mirror-repeat",hy="linear",py="nearest",gy="zero",my="one",fy="src",yy="one-minus-src",by="src-alpha",xy="one-minus-src-alpha",Ty="dst",_y="one-minus-dst",Ny="dst-alpha",vy="one-minus-dst-alpha",Sy="src-alpha-saturated",Ay="constant",Ry="one-minus-constant",Cy="add",Ey="subtract",wy="reverse-subtract",My="min",By="max",Uy=0,Fy=15,Py="keep",Iy="zero",Ly="replace",Dy="invert",Vy="increment-clamp",Oy="decrement-clamp",Gy="increment-wrap",ky="decrement-wrap",zy="storage",$y="read-only-storage",Hy="write-only",Wy="read-only",jy="float",qy="unfilterable-float",Ky="depth",Xy="sint",Yy="uint",Qy="2d",Zy="3d",Jy="2d",eb="2d-array",tb="cube",sb="3d",rb="all",nb="vertex",ib="instance",ob={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending",Subgroups:"subgroups"};class ab extends Nl{static get type(){return"StorageBufferNode"}constructor(e,t,s=0){super(e,t,s),this.isStorageBufferNode=!0,this.access=zy,this.isAtomic=!1,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==e.isStorageBufferAttribute&&!0!==e.isStorageInstancedBufferAttribute&&(e.isInstancedBufferAttribute?e.isStorageInstancedBufferAttribute=!0:e.isStorageBufferAttribute=!0)}getHash(e){if(0===this.bufferCount){let t=e.globalCache.getData(this.value);return void 0===t&&(t={node:this},e.globalCache.setData(this.value,t)),t.node.uuid}return this.uuid}getInputType(){return this.value.isIndirectStorageBufferAttribute?"indirectStorageBuffer":"storageBuffer"}element(e){return Of(this,e)}setBufferObject(e){return this.bufferObject=e,this}setAccess(e){return this.access=e,this}toReadOnly(){return this.setAccess($y)}setAtomic(e){return this.isAtomic=e,this}toAtomic(){return this.setAtomic(!0)}getAttributeData(){return null===this._attribute&&(this._attribute=qa(this.value),this._varying=Ea(this._attribute)),{attribute:this._attribute,varying:this._varying}}getNodeType(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.getNodeType(e);const{attribute:t}=this.getAttributeData();return t.getNodeType(e)}generate(e){if(e.isAvailable("storageBuffer")||e.isAvailable("indirectStorageBuffer"))return super.generate(e);const{attribute:t,varying:s}=this.getAttributeData(),r=s.build(e);return e.registerTransform(r,t),r}}const ub=(e,t,s)=>hn(new ab(e,t,s)),lb=(e,t,s)=>hn(new ab(e,t,s).setBufferObject(!0));class db extends Tu{static get type(){return"StorageTextureNode"}constructor(e,t,s=null){super(e,t),this.storeNode=s,this.isStorageTextureNode=!0,this.access=Hy}getInputType(){return"storageTexture"}setup(e){super.setup(e);e.getNodeProperties(this).storeNode=this.storeNode}setAccess(e){return this.access=e,this}generate(e,t){let s;return s=null!==this.storeNode?this.generateStore(e):super.generate(e,t),s}toReadOnly(){return this.setAccess(Wy)}toWriteOnly(){return this.setAccess(Hy)}generateStore(e){const t=e.getNodeProperties(this),{uvNode:s,storeNode:r}=t,n=super.generate(e,"property"),i=s.build(e,"uvec2"),o=r.build(e,"vec4"),a=e.generateTextureStore(e,n,i,o);e.addLineFlowCode(a,this)}}const cb=mn(db),hb=(e,t,s)=>{const r=cb(e,t,s);return null!==s&&r.append(),r};class pb extends wl{static get type(){return"UserDataNode"}constructor(e,t,s=null){super(e,t,s),this.userData=s}updateReference(e){return this.reference=null!==this.userData?this.userData:e.object.userData,this.reference}}const gb=(e,t,s)=>hn(new pb(e,t,s)),mb=new WeakMap;class fb extends Er{static get type(){return"VelocityNode"}constructor(){super("vec2"),this.projectionMatrix=null,this.updateType=br.OBJECT,this.updateAfterType=br.OBJECT,this.previousModelWorldMatrix=ti(new i),this.previousProjectionMatrix=ti(new i).setGroup(Zn),this.previousCameraViewMatrix=ti(new i)}setProjectionMatrix(e){this.projectionMatrix=e}update({frameId:e,camera:t,object:s}){const r=bb(s);this.previousModelWorldMatrix.value.copy(r);const n=yb(t);n.frameId!==e&&(n.frameId=e,void 0===n.previousProjectionMatrix?(n.previousProjectionMatrix=new i,n.previousCameraViewMatrix=new i,n.currentProjectionMatrix=new i,n.currentCameraViewMatrix=new i,n.previousProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.previousCameraViewMatrix.copy(t.matrixWorldInverse)):(n.previousProjectionMatrix.copy(n.currentProjectionMatrix),n.previousCameraViewMatrix.copy(n.currentCameraViewMatrix)),n.currentProjectionMatrix.copy(this.projectionMatrix||t.projectionMatrix),n.currentCameraViewMatrix.copy(t.matrixWorldInverse),this.previousProjectionMatrix.value.copy(n.previousProjectionMatrix),this.previousCameraViewMatrix.value.copy(n.previousCameraViewMatrix))}updateAfter({object:e}){bb(e).copy(e.matrixWorld)}setup(){const e=null===this.projectionMatrix?Ru:ti(this.projectionMatrix),t=this.previousCameraViewMatrix.mul(this.previousModelWorldMatrix),s=e.mul(ju).mul(Yu),r=this.previousProjectionMatrix.mul(t).mul(Qu),n=s.xy.div(s.w),i=r.xy.div(r.w);return Oi(n,i)}}function yb(e){let t=mb.get(e);return void 0===t&&(t={},mb.set(e,t)),t}function bb(e,t=0){const s=yb(e);let r=s[t];return void 0===r&&(s[t]=r=new i),r}const xb=fn(fb),Tb=yn((([e,t])=>qo(1,e.oneMinus().div(t)).oneMinus())).setLayout({name:"burnBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),_b=yn((([e,t])=>qo(e.div(t.oneMinus()),1))).setLayout({name:"dodgeBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Nb=yn((([e,t])=>e.oneMinus().mul(t.oneMinus()).oneMinus())).setLayout({name:"screenBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),vb=yn((([e,t])=>la(e.mul(2).mul(t),e.oneMinus().mul(2).mul(t.oneMinus()).oneMinus(),Yo(.5,e)))).setLayout({name:"overlayBlend",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),Sb=yn((([e,t])=>Ln(e.rgb.mul(t.a.oneMinus()).add(t.rgb.mul(t.a)),e.a))).setLayout({name:"blendNormal",type:"vec4",inputs:[{name:"base",type:"vec4"},{name:"blend",type:"vec4"}]}),Ab=yn((([e])=>wb(e.rgb))),Rb=yn((([e,t=Sn(1)])=>t.mix(wb(e.rgb),e.rgb))),Cb=yn((([e,t=Sn(1)])=>{const s=Vi(e.r,e.g,e.b).div(3),r=e.r.max(e.g.max(e.b)),n=r.sub(s).mul(t).mul(-3);return la(e.rgb,r,n)})),Eb=yn((([e,t=Sn(1)])=>{const s=Un(.57735,.57735,.57735),r=t.cos();return Un(e.rgb.mul(r).add(s.cross(e.rgb).mul(t.sin()).add(s.mul(ea(s,e.rgb).mul(r.oneMinus())))))})),wb=(e,t=Un(u.getLuminanceCoefficients(new s)))=>ea(e,t),Mb=(e,t)=>la(Un(0),e,wb(e).sub(t).max(0)),Bb=yn((([e,t=Un(1),r=Un(0),n=Un(1),i=Sn(1),o=Un(u.getLuminanceCoefficients(new s,Se))])=>{const a=e.rgb.dot(Un(o)),l=Ko(e.rgb.mul(t).add(r),0).toVar(),d=l.pow(n).toVar();return _n(l.r.greaterThan(0),(()=>{l.r.assign(d.r)})),_n(l.g.greaterThan(0),(()=>{l.g.assign(d.g)})),_n(l.b.greaterThan(0),(()=>{l.b.assign(d.b)})),l.assign(a.add(l.sub(a).mul(i))),Ln(l.rgb,e.a)}));class Ub extends Er{static get type(){return"PosterizeNode"}constructor(e,t){super(),this.sourceNode=e,this.stepsNode=t}setup(){const{sourceNode:e,stepsNode:t}=this;return e.mul(t).floor().div(t)}}const Fb=mn(Ub);let Pb=null;class Ib extends Lc{static get type(){return"ViewportSharedTextureNode"}constructor(e=Ac,t=null){null===Pb&&(Pb=new w),super(e,t,Pb)}updateReference(){return this}}const Lb=mn(Ib),Db=new t;class Vb extends Tu{static get type(){return"PassTextureNode"}constructor(e,t){super(t),this.passNode=e,this.setUpdateMatrix(!1)}setup(e){return e.object.isQuadMesh&&this.passNode.build(e),super.setup(e)}clone(){return new this.constructor(this.passNode,this.value)}}class Ob extends Vb{static get type(){return"PassMultipleTextureNode"}constructor(e,t,s=!1){super(e,null),this.textureName=t,this.previousTexture=s}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(e){return this.updateTexture(),super.setup(e)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class Gb extends Er{static get type(){return"PassNode"}constructor(e,t,s,r={}){super("vec4"),this.scope=e,this.scene=t,this.camera=s,this.options=r,this._pixelRatio=1,this._width=1,this._height=1;const n=new B;n.isRenderTargetTexture=!0,n.name="depth";const i=new ge(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:ye,...r});i.texture.name="output",i.depthTexture=n,this.renderTarget=i,this.updateBeforeType=br.FRAME,this._textures={output:i.texture,depth:n},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=ti(0),this._cameraFar=ti(0),this._mrt=null,this.isPassNode=!0}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(e){let t=this._textures[e];if(void 0===t){t=this.renderTarget.texture.clone(),t.isRenderTargetTexture=!0,t.name=e,this._textures[e]=t,this.renderTarget.textures.push(t)}return t}getPreviousTexture(e){let t=this._previousTextures[e];return void 0===t&&(t=this.getTexture(e).clone(),t.isRenderTargetTexture=!0,this._previousTextures[e]=t),t}toggleTexture(e){const t=this._previousTextures[e];if(void 0!==t){const s=this._textures[e],r=this.renderTarget.textures.indexOf(s);this.renderTarget.textures[r]=t,this._textures[e]=t,this._previousTextures[e]=s,this._textureNodes[e].updateTexture(),this._previousTextureNodes[e].updateTexture()}}getTextureNode(e="output"){let t=this._textureNodes[e];return void 0===t&&(t=hn(new Ob(this,e)),t.updateTexture(),this._textureNodes[e]=t),t}getPreviousTextureNode(e="output"){let t=this._previousTextureNodes[e];return void 0===t&&(void 0===this._textureNodes[e]&&this.getTextureNode(e),t=hn(new Ob(this,e,!0)),t.updateTexture(),this._previousTextureNodes[e]=t),t}getViewZNode(e="depth"){let t=this._viewZNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar;this._viewZNodes[e]=t=jc(this.getTextureNode(e),s,r)}return t}getLinearDepthNode(e="depth"){let t=this._linearDepthNodes[e];if(void 0===t){const s=this._cameraNear,r=this._cameraFar,n=this.getViewZNode(e);this._linearDepthNodes[e]=t=$c(n,s,r)}return t}setup({renderer:e}){return this.renderTarget.samples=void 0===this.options.samples?e.samples:this.options.samples,!0===e.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===Gb.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(e){const{renderer:t}=e,{scene:s,camera:r}=this;this._pixelRatio=t.getPixelRatio();const n=t.getSize(Db);this.setSize(n.width,n.height);const i=t.getRenderTarget(),o=t.getMRT();this._cameraNear.value=r.near,this._cameraFar.value=r.far;for(const e in this._previousTextures)this.toggleTexture(e);t.setRenderTarget(this.renderTarget),t.setMRT(this._mrt),t.render(s,r),t.setRenderTarget(i),t.setMRT(o)}setSize(e,t){this._width=e,this._height=t;const s=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget.setSize(s,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}Gb.COLOR="color",Gb.DEPTH="depth";const kb=(e,t,s)=>hn(new Gb(Gb.COLOR,e,t,s)),zb=(e,t)=>hn(new Vb(e,t)),$b=(e,t)=>hn(new Gb(Gb.DEPTH,e,t));class Hb extends Gb{static get type(){return"ToonOutlinePassNode"}constructor(e,t,s,r,n){super(Gb.COLOR,e,t),this.colorNode=s,this.thicknessNode=r,this.alphaNode=n,this._materialCache=new WeakMap}updateBefore(e){const{renderer:t}=e,s=t.getRenderObjectFunction();t.setRenderObjectFunction(((e,s,r,n,i,o,a,u)=>{if((i.isMeshToonMaterial||i.isMeshToonNodeMaterial)&&!1===i.wireframe){const l=this._getOutlineMaterial(i);t.renderObject(e,s,r,n,l,o,a,u)}t.renderObject(e,s,r,n,i,o,a,u)})),super.updateBefore(e),t.setRenderObjectFunction(s)}_createMaterial(){const e=new nh;e.isMeshToonOutlineMaterial=!0,e.name="Toon_Outline",e.side=x;const t=ol.negate(),s=Ru.mul(ju),r=Sn(1),n=s.mul(Ln(Yu,1)),i=s.mul(Ln(Yu.add(t),1)),o=Ao(n.sub(i));return e.vertexNode=n.add(o.mul(this.thicknessNode).mul(n.w).mul(r)),e.colorNode=Ln(this.colorNode,this.alphaNode),e}_getOutlineMaterial(e){let t=this._materialCache.get(e);return void 0===t&&(t=this._createMaterial(),this._materialCache.set(e,t)),t}}const Wb=(t,s,r=new e(0,0,0),n=.003,i=1)=>hn(new Hb(t,s,hn(r),hn(n),hn(i))),jb=yn((([e,t])=>e.mul(t).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),qb=yn((([e,t])=>(e=e.mul(t)).div(e.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Kb=yn((([e,t])=>{const s=(e=(e=e.mul(t)).sub(.004).max(0)).mul(e.mul(6.2).add(.5)),r=e.mul(e.mul(6.2).add(1.7)).add(.06);return s.div(r).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Xb=yn((([e])=>{const t=e.mul(e.add(.0245786)).sub(90537e-9),s=e.mul(e.add(.432951).mul(.983729)).add(.238081);return t.div(s)})),Yb=yn((([e,t])=>{const s=kn(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),r=kn(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return e=e.mul(t).div(.6),e=s.mul(e),e=Xb(e),(e=r.mul(e)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),Qb=kn(Un(1.6605,-.1246,-.0182),Un(-.5876,1.1329,-.1006),Un(-.0728,-.0083,1.1187)),Zb=kn(Un(.6274,.0691,.0164),Un(.3293,.9195,.088),Un(.0433,.0113,.8956)),Jb=yn((([e])=>{const t=Un(e).toVar(),s=Un(t.mul(t)).toVar(),r=Un(s.mul(s)).toVar();return Sn(15.5).mul(r.mul(s)).sub(Gi(40.14,r.mul(t))).add(Gi(31.96,r).sub(Gi(6.868,s.mul(t))).add(Gi(.4298,s).add(Gi(.1191,t).sub(.00232))))})),ex=yn((([e,t])=>{const s=Un(e).toVar(),r=kn(Un(.856627153315983,.137318972929847,.11189821299995),Un(.0951212405381588,.761241990602591,.0767994186031903),Un(.0482516061458583,.101439036467562,.811302368396859)),n=kn(Un(1.1271005818144368,-.1413297634984383,-.14132976349843826),Un(-.11060664309660323,1.157823702216272,-.11060664309660294),Un(-.016493938717834573,-.016493938717834257,1.2519364065950405)),i=Sn(-12.47393),o=Sn(4.026069);return s.mulAssign(t),s.assign(Zb.mul(s)),s.assign(r.mul(s)),s.assign(Ko(s,1e-10)),s.assign(To(s)),s.assign(s.sub(i).div(o.sub(i))),s.assign(da(s,0,1)),s.assign(Jb(s)),s.assign(n.mul(s)),s.assign(sa(Ko(Un(0),s),Un(2.2))),s.assign(Qb.mul(s)),s.assign(da(s,0,1)),s})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),tx=yn((([e,t])=>{const s=Sn(.76),r=Sn(.15);e=e.mul(t);const n=qo(e.r,qo(e.g,e.b)),i=xa(n.lessThan(.08),n.sub(Gi(6.25,n.mul(n))),.04);e.subAssign(i);const o=Ko(e.r,Ko(e.g,e.b));_n(o.lessThan(s),(()=>e));const a=Oi(1,s),u=Oi(1,a.mul(a).div(o.add(a.sub(s))));e.mulAssign(u.div(o));const l=Oi(1,ki(1,r.mul(o.sub(u)).add(1)));return la(e,Un(u),l)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class sx extends Ar{static get type(){return"CodeNode"}constructor(e="",t=[],s=""){super("code"),this.isCodeNode=!0,this.code=e,this.language=s,this.includes=t}isGlobal(){return!0}setIncludes(e){return this.includes=e,this}getIncludes(){return this.includes}generate(e){const t=this.getIncludes(e);for(const s of t)s.build(e);const s=e.getCodeFromNode(this,this.getNodeType(e));return s.code=this.code,s.code}serialize(e){super.serialize(e),e.code=this.code,e.language=this.language}deserialize(e){super.deserialize(e),this.code=e.code,this.language=e.language}}const rx=mn(sx),nx=(e,t)=>rx(e,t,"js"),ix=(e,t)=>rx(e,t,"wgsl"),ox=(e,t)=>rx(e,t,"glsl");class ax extends sx{static get type(){return"FunctionNode"}constructor(e="",t=[],s=""){super(e,t,s)}getNodeType(e){return this.getNodeFunction(e).type}getInputs(e){return this.getNodeFunction(e).inputs}getNodeFunction(e){const t=e.getDataFromNode(this);let s=t.nodeFunction;return void 0===s&&(s=e.parser.parseFunction(this.code),t.nodeFunction=s),s}generate(e,t){super.generate(e);const s=this.getNodeFunction(e),r=s.name,n=s.type,i=e.getCodeFromNode(this,n);""!==r&&(i.name=r);const o=e.getPropertyName(i),a=this.getNodeFunction(e).getCode(o);return i.code=a+"\n","property"===t?o:e.format(`${o}()`,n,t)}}const ux=(e,t=[],s="")=>{for(let e=0;er.call(...e);return n.functionNode=r,n},lx=(e,t)=>ux(e,t,"glsl"),dx=(e,t)=>ux(e,t,"wgsl");class cx extends Ar{static get type(){return"ScriptableValueNode"}constructor(e=null){super(),this._value=e,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new o,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(e){this._value!==e&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=e,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const e=this.value;if(e&&null===this._cache&&"URL"===this.inputType&&e.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([e.value]));else if(e&&null!==e.value&&void 0!==e.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof e.value||"Number"===this.inputType&&"number"==typeof e.value||"Vector2"===this.inputType&&e.value.isVector2||"Vector3"===this.inputType&&e.value.isVector3||"Vector4"===this.inputType&&e.value.isVector4||"Color"===this.inputType&&e.value.isColor||"Matrix3"===this.inputType&&e.value.isMatrix3||"Matrix4"===this.inputType&&e.value.isMatrix4))return e.value;return this._cache||e}getNodeType(e){return this.value&&this.value.isNode?this.value.getNodeType(e):"float"}setup(){return this.value&&this.value.isNode?this.value:Sn()}serialize(e){super.serialize(e),null!==this.value?"ArrayBuffer"===this.inputType?e.value=gr(this.value):e.value=this.value?this.value.toJSON(e.meta).uuid:null:e.value=null,e.inputType=this.inputType,e.outputType=this.outputType}deserialize(e){super.deserialize(e);let t=null;null!==e.value&&(t="ArrayBuffer"===e.inputType?mr(e.value):"Texture"===e.inputType?e.meta.textures[e.value]:e.meta.nodes[e.value]||null),this.value=t,this.inputType=e.inputType,this.outputType=e.outputType}}const hx=mn(cx);class px extends Map{get(e,t=null,...s){if(this.has(e))return super.get(e);if(null!==t){const r=t(...s);return this.set(e,r),r}}}class gx{constructor(e){this.scriptableNode=e}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(e){return this.scriptableNode.getInputLayout(e)}get(e){const t=this.parameters[e];return t?t.getValue():null}}const mx=new px;class fx extends Ar{static get type(){return"ScriptableNode"}constructor(e=null,t={}){super(),this.codeNode=e,this.parameters=t,this._local=new px,this._output=hx(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(e,t){return this._local.set(e,t)}getLocal(e){return this._local.get(e)}onRefresh(){this._refresh()}getInputLayout(e){for(const t of this.getLayout())if(t.inputType&&(t.id===e||t.name===e))return t}getOutputLayout(e){for(const t of this.getLayout())if(t.outputType&&(t.id===e||t.name===e))return t}setOutput(e,t){const s=this._outputs;return void 0===s[e]?s[e]=hx(t):s[e].value=t,this}getOutput(e){return this._outputs[e]}getParameter(e){return this.parameters[e]}setParameter(e,t){const s=this.parameters;return t&&t.isScriptableNode?(this.deleteParameter(e),s[e]=t,s[e].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):t&&t.isScriptableValueNode?(this.deleteParameter(e),s[e]=t,s[e].events.addEventListener("refresh",this.onRefresh)):void 0===s[e]?(s[e]=hx(t),s[e].events.addEventListener("refresh",this.onRefresh)):s[e].value=t,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(e){let t=this.parameters[e];return t&&(t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const e of Object.keys(this.parameters))this.deleteParameter(e);return this.needsUpdate=!0,this}call(e,...t){const s=this.getObject()[e];if("function"==typeof s)return s(...t)}async callAsync(e,...t){const s=this.getObject()[e];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...t):s(...t)}getNodeType(e){return this.getDefaultOutputNode().getNodeType(e)}refresh(e=null){null!==e?this.getOutput(e).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const e=new gx(this),t=mx.get("THREE"),s=mx.get("TSL"),r=this.getMethod(this.codeNode),n=[e,this._local,mx,()=>this.refresh(),(e,t)=>this.setOutput(e,t),t,s];this._object=r(...n);const i=this._object.layout;if(i&&(!1===i.cache&&this._local.clear(),this._output.outputType=i.outputType||null,Array.isArray(i.elements)))for(const e of i.elements){const t=e.id||e.name;e.inputType&&(void 0===this.getParameter(t)&&this.setParameter(t,null),this.getParameter(t).inputType=e.inputType),e.outputType&&(void 0===this.getOutput(t)&&this.setOutput(t,null),this.getOutput(t).outputType=e.outputType)}return this._object}deserialize(e){super.deserialize(e);for(const e in this.parameters){let t=this.parameters[e];t.isScriptableNode&&(t=t.getDefaultOutput()),t.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const e=this.getDefaultOutput().value;return e&&e.isNode?e:Sn()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const e=["layout","init","main","dispose"].join(", "),t="\nreturn { ...output, "+e+" };",s="var "+e+"; var output = {};\n"+this.codeNode.code+t;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(e){const t=[ar(this.source),this.getDefaultOutputNode().getCacheKey(e)];for(const s in this.parameters)t.push(this.parameters[s].getCacheKey(e));return ur(t)}set needsUpdate(e){!0===e&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const yx=mn(fx);class bx extends Ar{static get type(){return"FogNode"}constructor(e,t){super("float"),this.isFogNode=!0,this.colorNode=e,this.factorNode=t}getViewZNode(e){let t;const s=e.context.getViewZ;return void 0!==s&&(t=s(this)),(t||el.z).negate()}setup(){return this.factorNode}}const xx=mn(bx);class Tx extends bx{static get type(){return"FogRangeNode"}constructor(e,t,s){super(e),this.isFogRangeNode=!0,this.nearNode=t,this.farNode=s}setup(e){const t=this.getViewZNode(e);return pa(this.nearNode,this.farNode,t)}}const _x=mn(Tx);class Nx extends bx{static get type(){return"FogExp2Node"}constructor(e,t){super(e),this.isFogExp2Node=!0,this.densityNode=t}setup(e){const t=this.getViewZNode(e),s=this.densityNode;return s.mul(s,t,t).negate().exp().oneMinus()}}const vx=mn(Nx);let Sx=null,Ax=null;class Rx extends Ar{static get type(){return"RangeNode"}constructor(e=Sn(),t=Sn()){super(),this.minNode=e,this.maxNode=t}getVectorLength(e){const t=e.getTypeLength(hr(this.minNode.value)),s=e.getTypeLength(hr(this.maxNode.value));return t>s?t:s}getNodeType(e){return e.object.count>1?e.getTypeFromLength(this.getVectorLength(e)):"float"}setup(e){const t=e.object;let s=null;if(t.count>1){const n=this.minNode.value,i=this.maxNode.value,o=e.getTypeLength(hr(n)),u=e.getTypeLength(hr(i));Sx=Sx||new r,Ax=Ax||new r,Sx.setScalar(0),Ax.setScalar(0),1===o?Sx.setScalar(n):n.isColor?Sx.set(n.r,n.g,n.b):Sx.set(n.x,n.y,n.z||0,n.w||0),1===u?Ax.setScalar(i):i.isColor?Ax.set(i.r,i.g,i.b):Ax.set(i.x,i.y,i.z||0,i.w||0);const l=4,d=l*t.count,c=new Float32Array(d);for(let e=0;ehn(new Ex(e,t)),Mx=wx("numWorkgroups","uvec3"),Bx=wx("workgroupId","uvec3"),Ux=wx("localId","uvec3"),Fx=wx("subgroupSize","uint");const Px=mn(class extends Ar{constructor(e){super(),this.scope=e}generate(e){const{scope:t}=this,{renderer:s}=e;!0===s.backend.isWebGLBackend?e.addFlowCode(`\t// ${t}Barrier \n`):e.addLineFlowCode(`${t}Barrier()`,this)}}),Ix=()=>Px("workgroup").append(),Lx=()=>Px("storage").append(),Dx=()=>Px("texture").append();class Vx extends Rr{constructor(e,t){super(e,t),this.isWorkgroupInfoElementNode=!0}generate(e,t){let s;const r=e.context.assign;if(s=super.generate(e),!0!==r){const r=this.getNodeType(e);s=e.format(s,r,t)}return s}}class Ox extends Ar{constructor(e,t,s=0){super(t),this.bufferType=t,this.bufferCount=s,this.isWorkgroupInfoNode=!0,this.scope=e}label(e){return this.name=e,this}getHash(){return this.uuid}setScope(e){return this.scope=e,this}getInputType(){return`${this.scope}Array`}element(e){return hn(new Vx(this,e))}generate(e){return e.getScopedArray(this.name||`${this.scope}Array_${this.id}`,this.scope.toLowerCase(),this.bufferType,this.bufferCount)}}const Gx=(e,t)=>hn(new Ox("Workgroup",e,t));class kx extends Er{static get type(){return"AtomicFunctionNode"}constructor(e,t,s,r=null){super("uint"),this.method=e,this.pointerNode=t,this.valueNode=s,this.storeNode=r}getInputType(e){return this.pointerNode.getNodeType(e)}getNodeType(e){return this.getInputType(e)}generate(e){const t=this.method,s=this.getNodeType(e),r=this.getInputType(e),n=this.pointerNode,i=this.valueNode,o=[];o.push(`&${n.build(e,r)}`),o.push(i.build(e,r));const a=`${e.getMethod(t,s)}( ${o.join(", ")} )`;if(null!==this.storeNode){const t=this.storeNode.build(e,r);e.addLineFlowCode(`${t} = ${a}`,this)}else e.addLineFlowCode(a,this)}}kx.ATOMIC_LOAD="atomicLoad",kx.ATOMIC_STORE="atomicStore",kx.ATOMIC_ADD="atomicAdd",kx.ATOMIC_SUB="atomicSub",kx.ATOMIC_MAX="atomicMax",kx.ATOMIC_MIN="atomicMin",kx.ATOMIC_AND="atomicAnd",kx.ATOMIC_OR="atomicOr",kx.ATOMIC_XOR="atomicXor";const zx=mn(kx),$x=(e,t,s,r)=>{const n=zx(e,t,s,r);return n.append(),n},Hx=(e,t,s=null)=>$x(kx.ATOMIC_STORE,e,t,s),Wx=(e,t,s=null)=>$x(kx.ATOMIC_ADD,e,t,s),jx=(e,t,s=null)=>$x(kx.ATOMIC_SUB,e,t,s),qx=(e,t,s=null)=>$x(kx.ATOMIC_MAX,e,t,s),Kx=(e,t,s=null)=>$x(kx.ATOMIC_MIN,e,t,s),Xx=(e,t,s=null)=>$x(kx.ATOMIC_AND,e,t,s),Yx=(e,t,s=null)=>$x(kx.ATOMIC_OR,e,t,s),Qx=(e,t,s=null)=>$x(kx.ATOMIC_XOR,e,t,s);let Zx;function Jx(e){Zx=Zx||new WeakMap;let t=Zx.get(e);return void 0===t&&Zx.set(e,t={}),t}function eT(e){const t=Jx(e);return t.position||(t.position=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.matrixWorld))))}function tT(e){const t=Jx(e);return t.targetPosition||(t.targetPosition=ti(new s).setGroup(Zn).onRenderUpdate(((t,s)=>s.value.setFromMatrixPosition(e.target.matrixWorld))))}function sT(e){const t=Jx(e);return t.viewPosition||(t.viewPosition=ti(new s).setGroup(Zn).onRenderUpdate((({camera:t},r)=>{r.value=r.value||new s,r.value.setFromMatrixPosition(e.matrixWorld),r.value.applyMatrix4(t.matrixWorldInverse)})))}const rT=e=>Eu.transformDirection(eT(e).sub(tT(e))),nT=(e,t)=>{for(const s of t)if(s.isAnalyticLightNode&&s.light.id===e)return s;return null},iT=new WeakMap;class oT extends Ar{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=Un().toVar("totalDiffuse"),this.totalSpecularNode=Un().toVar("totalSpecular"),this.outgoingLightNode=Un().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(e){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(e);const t=[];for(const e of this._lightNodes)t.push(e.getSelf().getHash());this._lightNodesHash="lights-"+t.join(",")}return this._lightNodesHash}analyze(e){const t=e.getDataFromNode(this);for(const s of t.nodes)s.build(e)}setupLightsNode(e){const t=[],s=this._lightNodes,r=(e=>e.sort(((e,t)=>e.id-t.id)))(this._lights),n=e.renderer.library;for(const e of r)if(e.isNode)t.push(hn(e));else{let r=null;if(null!==s&&(r=nT(e.id,s)),null===r){const s=n.getLightNodeClass(e.constructor);if(null===s){console.warn(`LightsNode.setupNodeLights: Light node not found for ${e.constructor.name}`);continue}let r=null;iT.has(e)?r=iT.get(e):(r=hn(new s(e)),iT.set(e,r)),t.push(r)}}this._lightNodes=t}setupLights(e,t){for(const s of t)s.build(e)}setup(e){null===this._lightNodes&&this.setupLightsNode(e);const t=e.context,s=t.lightingModel;let r=this.outgoingLightNode;if(s){const{_lightNodes:n,totalDiffuseNode:i,totalSpecularNode:o}=this;t.outgoingLight=r;const a=e.addStack();e.getDataFromNode(this).nodes=a.nodes,s.start(t,a,e),this.setupLights(e,n),s.indirect(t,a,e);const{backdrop:u,backdropAlpha:l}=t,{directDiffuse:d,directSpecular:c,indirectDiffuse:h,indirectSpecular:p}=t.reflectedLight;let g=d.add(h);null!==u&&(g=Un(null!==l?l.mix(g,u):u),t.material.transparent=!0),i.assign(g),o.assign(c.add(p)),r.assign(i.add(o)),s.finish(t,a,e),r=r.bypass(e.removeStack())}return r}setLights(e){return this._lights=e,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const aT=(e=[])=>hn(new oT).setLights(e),uT=yn((({depthTexture:e,shadowCoord:t})=>_u(e,t.xy).compare(t.z))),lT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=Ml("radius","float",s).setGroup(Zn),o=En(1).div(n),a=o.x.negate().mul(i),u=o.y.negate().mul(i),l=o.x.mul(i),d=o.y.mul(i),c=a.div(2),h=u.div(2),p=l.div(2),g=d.div(2);return Vi(r(t.xy.add(En(a,u)),t.z),r(t.xy.add(En(0,u)),t.z),r(t.xy.add(En(l,u)),t.z),r(t.xy.add(En(c,h)),t.z),r(t.xy.add(En(0,h)),t.z),r(t.xy.add(En(p,h)),t.z),r(t.xy.add(En(a,0)),t.z),r(t.xy.add(En(c,0)),t.z),r(t.xy,t.z),r(t.xy.add(En(p,0)),t.z),r(t.xy.add(En(l,0)),t.z),r(t.xy.add(En(c,g)),t.z),r(t.xy.add(En(0,g)),t.z),r(t.xy.add(En(p,g)),t.z),r(t.xy.add(En(a,d)),t.z),r(t.xy.add(En(0,d)),t.z),r(t.xy.add(En(l,d)),t.z)).mul(1/17)})),dT=yn((({depthTexture:e,shadowCoord:t,shadow:s})=>{const r=(t,s)=>_u(e,t).compare(s),n=Ml("mapSize","vec2",s).setGroup(Zn),i=En(1).div(n),o=i.x,a=i.y,u=t.xy,l=Ro(u.mul(n).add(.5));return u.subAssign(l.mul(i)),Vi(r(u,t.z),r(u.add(En(o,0)),t.z),r(u.add(En(0,a)),t.z),r(u.add(i),t.z),la(r(u.add(En(o.negate(),0)),t.z),r(u.add(En(o.mul(2),0)),t.z),l.x),la(r(u.add(En(o.negate(),a)),t.z),r(u.add(En(o.mul(2),a)),t.z),l.x),la(r(u.add(En(0,a.negate())),t.z),r(u.add(En(0,a.mul(2))),t.z),l.y),la(r(u.add(En(o,a.negate())),t.z),r(u.add(En(o,a.mul(2))),t.z),l.y),la(la(r(u.add(En(o.negate(),a.negate())),t.z),r(u.add(En(o.mul(2),a.negate())),t.z),l.x),la(r(u.add(En(o.negate(),a.mul(2))),t.z),r(u.add(En(o.mul(2),a.mul(2))),t.z),l.x),l.y)).mul(1/9)})),cT=yn((({depthTexture:e,shadowCoord:t})=>{const s=Sn(1).toVar(),r=_u(e).uv(t.xy).rg,n=Yo(t.z,r.x);return _n(n.notEqual(Sn(1)),(()=>{const e=t.z.sub(r.x),i=Ko(0,r.y.mul(r.y));let o=i.div(i.add(e.mul(e)));o=da(Oi(o,.3).div(.95-.3)),s.assign(da(Ko(n,o)))})),s})),hT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(0,u).mul(t)).div(s)).x;n.addAssign(l),i.addAssign(l.mul(l))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),pT=yn((({samples:e,radius:t,size:s,shadowPass:r})=>{const n=Sn(0).toVar(),i=Sn(0).toVar(),o=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(2).div(e.sub(1))),a=e.lessThanEqual(Sn(1)).select(Sn(0),Sn(-1));uc({start:An(0),end:An(e),type:"int",condition:"<"},(({i:e})=>{const u=a.add(Sn(e).mul(o)),l=r.uv(Vi(Cc.xy,En(u,0).mul(t)).div(s));n.addAssign(l.x),i.addAssign(Vi(l.y.mul(l.y),l.x.mul(l.x)))})),n.divAssign(e),i.divAssign(e);const u=_o(i.sub(n.mul(n)));return En(n,u)})),gT=[uT,lT,dT,cT];let mT=null;const fT=new Tf;class yT extends Ar{static get type(){return"ShadowNode"}constructor(e,t=null){super(),this.light=e,this.shadow=t||e.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=br.RENDER,this._node=null,this.isShadowNode=!0}setupShadow(e){const{object:t,renderer:s}=e;null===mT&&(mT=new nh,mT.fragmentNode=Ln(0,0,0,1),mT.isShadowNodeMaterial=!0,mT.name="ShadowMaterial");const r=this.shadow,n=s.shadowMap.type,i=new B(r.mapSize.width,r.mapSize.height);i.compareFunction=Ae;const o=e.createRenderTarget(r.mapSize.width,r.mapSize.height);if(o.depthTexture=i,r.camera.updateProjectionMatrix(),n===Re){i.compareFunction=null,this.vsmShadowMapVertical=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye}),this.vsmShadowMapHorizontal=e.createRenderTarget(r.mapSize.width,r.mapSize.height,{format:Ce,type:ye});const t=_u(i),s=_u(this.vsmShadowMapVertical.texture),n=Ml("blurSamples","float",r).setGroup(Zn),o=Ml("radius","float",r).setGroup(Zn),a=Ml("mapSize","vec2",r).setGroup(Zn);let u=this.vsmMaterialVertical||(this.vsmMaterialVertical=new nh);u.fragmentNode=hT({samples:n,radius:o,size:a,shadowPass:t}).context(e.getSharedContext()),u.name="VSMVertical",u=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new nh),u.fragmentNode=pT({samples:n,radius:o,size:a,shadowPass:s}).context(e.getSharedContext()),u.name="VSMHorizontal"}const a=Ml("intensity","float",r).setGroup(Zn),u=Ml("bias","float",r).setGroup(Zn),l=Ml("normalBias","float",r).setGroup(Zn),d=t.material.shadowPositionNode||Zu;let c,h=ti(r.matrix).setGroup(Zn).mul(d.add(cl.mul(l)));if(r.camera.isOrthographicCamera||!0!==s.logarithmicDepthBuffer)h=h.xyz.div(h.w),c=h.z,s.coordinateSystem===N&&(c=c.mul(2).sub(1));else{const e=h.w;h=h.xy.div(e);const t=Ml("near","float",r.camera).setGroup(Zn),s=Ml("far","float",r.camera).setGroup(Zn);c=qc(e.negate(),t,s)}h=Un(h.x,h.y.oneMinus(),c.add(u));const p=h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.lessThanEqual(1)),g=r.filterNode||gT[s.shadowMap.type]||null;if(null===g)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=_u(o.texture,h),f=p.select(g({depthTexture:n===Re?this.vsmShadowMapHorizontal.texture:i,shadowCoord:h,shadow:r}),Sn(1)),y=la(1,f.rgb.mix(m,1),a.mul(m.a)).toVar();return this.shadowMap=o,this.shadow.map=o,y}setup(e){if(!1===e.renderer.shadowMap.enabled)return;let t=this._node;return null===t&&(this._node=t=this.setupShadow(e)),e.material.shadowNode&&console.warn('THREE.NodeMaterial: ".shadowNode" is deprecated. Use ".castShadowNode" instead.'),e.material.receivedShadowNode&&(t=e.material.receivedShadowNode(t)),t}updateShadow(e){const{shadowMap:t,light:s,shadow:r}=this,{renderer:n,scene:i,camera:o}=e,a=n.shadowMap.type,u=t.depthTexture.version;this._depthVersionCached=u;const l=i.overrideMaterial;i.overrideMaterial=mT,t.setSize(r.mapSize.width,r.mapSize.height),r.updateMatrices(s),r.camera.layers.mask=o.layers.mask;const d=n.getRenderTarget(),c=n.getRenderObjectFunction();n.setRenderObjectFunction(((e,...t)=>{(!0===e.castShadow||e.receiveShadow&&a===Re)&&n.renderObject(e,...t)})),n.setRenderTarget(t),n.render(i,r.camera),n.setRenderObjectFunction(c),!0!==s.isPointLight&&a===Re&&this.vsmPass(n),n.setRenderTarget(d),i.overrideMaterial=l}vsmPass(e){const{shadow:t}=this;this.vsmShadowMapVertical.setSize(t.mapSize.width,t.mapSize.height),this.vsmShadowMapHorizontal.setSize(t.mapSize.width,t.mapSize.height),e.setRenderTarget(this.vsmShadowMapVertical),fT.material=this.vsmMaterialVertical,fT.render(e),e.setRenderTarget(this.vsmShadowMapHorizontal),fT.material=this.vsmMaterialHorizontal,fT.render(e)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=br.NONE}updateBefore(e){const{shadow:t}=this;(t.needsUpdate||t.autoUpdate)&&(this.updateShadow(e),this.shadowMap.depthTexture.version===this._depthVersionCached&&(t.needsUpdate=!1))}}const bT=(e,t)=>hn(new yT(e,t));class xT extends yc{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=br.FRAME,this.light=t,this.color=new e,this.colorNode=ti(this.color).setGroup(Zn),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return lr(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(e){const{renderer:t}=e;if(!1===t.shadowMap.enabled)return;let s=this.shadowColorNode;if(null===s){const e=this.light.shadow.shadowNode;let t;t=void 0!==e?hn(e):bT(this.light),this.shadowNode=t,this.shadowColorNode=s=this.colorNode.mul(t),this.baseColorNode=this.colorNode}this.colorNode=s}setup(e){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?e.object.receiveShadow&&this.setupShadow(e):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:e}=this;this.color.copy(e.color).multiplyScalar(e.intensity)}}const TT=yn((e=>{const{lightDistance:t,cutoffDistance:s,decayExponent:r}=e,n=t.pow(r).max(.01).reciprocal();return s.greaterThan(0).select(n.mul(t.div(s).pow4().oneMinus().clamp().pow2()),n)})),_T=yn((({color:e,lightViewPosition:t,cutoffDistance:s,decayExponent:r},n)=>{const i=n.context.lightingModel,o=t.sub(el),a=o.normalize(),u=o.length(),l=TT({lightDistance:u,cutoffDistance:s,decayExponent:r}),d=e.mul(l),c=n.context.reflectedLight;i.direct({lightDirection:a,lightColor:d,reflectedLight:c},n.stack,n)}));class NT extends xT{static get type(){return"PointLightNode"}constructor(e=null){super(e),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}setup(){_T({color:this.colorNode,lightViewPosition:sT(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const vT=yn((([e=t()])=>{const t=e.mul(2),s=t.x.floor(),r=t.y.floor();return s.add(r).mod(2).sign()})),ST=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Cn(e).toVar();return xa(i,n,r)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),AT=yn((([e,t])=>{const s=Cn(t).toVar(),r=Sn(e).toVar();return xa(s,r.negate(),r)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),RT=yn((([e])=>{const t=Sn(e).toVar();return An(vo(t))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),CT=yn((([e,t])=>{const s=Sn(e).toVar();return t.assign(RT(s)),s.sub(Sn(t))})),ET=Fm([yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Sn(r).toVar(),l=Sn(s).toVar(),d=Sn(t).toVar(),c=Sn(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),yn((([e,t,s,r,n,i])=>{const o=Sn(i).toVar(),a=Sn(n).toVar(),u=Un(r).toVar(),l=Un(s).toVar(),d=Un(t).toVar(),c=Un(e).toVar(),h=Sn(Oi(1,a)).toVar();return Oi(1,o).mul(c.mul(h).add(d.mul(a))).add(o.mul(l.mul(h).add(u.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),wT=Fm([yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Sn(a).toVar(),m=Sn(o).toVar(),f=Sn(i).toVar(),y=Sn(n).toVar(),b=Sn(r).toVar(),x=Sn(s).toVar(),T=Sn(t).toVar(),_=Sn(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),yn((([e,t,s,r,n,i,o,a,u,l,d])=>{const c=Sn(d).toVar(),h=Sn(l).toVar(),p=Sn(u).toVar(),g=Un(a).toVar(),m=Un(o).toVar(),f=Un(i).toVar(),y=Un(n).toVar(),b=Un(r).toVar(),x=Un(s).toVar(),T=Un(t).toVar(),_=Un(e).toVar(),N=Sn(Oi(1,p)).toVar(),v=Sn(Oi(1,h)).toVar();return Sn(Oi(1,c)).toVar().mul(v.mul(_.mul(N).add(T.mul(p))).add(h.mul(x.mul(N).add(b.mul(p))))).add(c.mul(v.mul(y.mul(N).add(f.mul(p))).add(h.mul(m.mul(N).add(g.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),MT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Rn(e).toVar(),o=Rn(i.bitAnd(Rn(7))).toVar(),a=Sn(ST(o.lessThan(Rn(4)),n,r)).toVar(),u=Sn(Gi(2,ST(o.lessThan(Rn(4)),r,n))).toVar();return AT(a,Cn(o.bitAnd(Rn(1)))).add(AT(u,Cn(o.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),BT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Rn(e).toVar(),u=Rn(a.bitAnd(Rn(15))).toVar(),l=Sn(ST(u.lessThan(Rn(8)),o,i)).toVar(),d=Sn(ST(u.lessThan(Rn(4)),i,ST(u.equal(Rn(12)).or(u.equal(Rn(14))),o,n))).toVar();return AT(l,Cn(u.bitAnd(Rn(1)))).add(AT(d,Cn(u.bitAnd(Rn(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),UT=Fm([MT,BT]),FT=yn((([e,t,s])=>{const r=Sn(s).toVar(),n=Sn(t).toVar(),i=Pn(e).toVar();return Un(UT(i.x,n,r),UT(i.y,n,r),UT(i.z,n,r))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),PT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=Sn(t).toVar(),a=Pn(e).toVar();return Un(UT(a.x,o,i,n),UT(a.y,o,i,n),UT(a.z,o,i,n))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),IT=Fm([FT,PT]),LT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),DT=yn((([e])=>{const t=Sn(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),VT=Fm([LT,yn((([e])=>{const t=Un(e).toVar();return Gi(.6616,t)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),OT=Fm([DT,yn((([e])=>{const t=Un(e).toVar();return Gi(.982,t)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),GT=yn((([e,t])=>{const s=An(t).toVar(),r=Rn(e).toVar();return r.shiftLeft(s).bitOr(r.shiftRight(An(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),kT=yn((([e,t,s])=>{e.subAssign(s),e.bitXorAssign(GT(s,An(4))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,An(6))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,An(8))),t.addAssign(e),e.subAssign(s),e.bitXorAssign(GT(s,An(16))),s.addAssign(t),t.subAssign(e),t.bitXorAssign(GT(e,An(19))),e.addAssign(s),s.subAssign(t),s.bitXorAssign(GT(t,An(4))),t.addAssign(e)})),zT=yn((([e,t,s])=>{const r=Rn(s).toVar(),n=Rn(t).toVar(),i=Rn(e).toVar();return r.bitXorAssign(n),r.subAssign(GT(n,An(14))),i.bitXorAssign(r),i.subAssign(GT(r,An(11))),n.bitXorAssign(i),n.subAssign(GT(i,An(25))),r.bitXorAssign(n),r.subAssign(GT(n,An(16))),i.bitXorAssign(r),i.subAssign(GT(r,An(4))),n.bitXorAssign(i),n.subAssign(GT(i,An(14))),r.bitXorAssign(n),r.subAssign(GT(n,An(24))),r})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),$T=yn((([e])=>{const t=Rn(e).toVar();return Sn(t).div(Sn(Rn(An(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),HT=yn((([e])=>{const t=Sn(e).toVar();return t.mul(t).mul(t).mul(t.mul(t.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),WT=Fm([yn((([e])=>{const t=An(e).toVar(),s=Rn(Rn(1)).toVar(),r=Rn(Rn(An(3735928559)).add(s.shiftLeft(Rn(2))).add(Rn(13))).toVar();return zT(r.add(Rn(t)),r,r)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(Rn(2)).toVar(),i=Rn().toVar(),o=Rn().toVar(),a=Rn().toVar();return i.assign(o.assign(a.assign(Rn(An(3735928559)).add(n.shiftLeft(Rn(2))).add(Rn(13))))),i.addAssign(Rn(r)),o.addAssign(Rn(s)),zT(i,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(Rn(3)).toVar(),a=Rn().toVar(),u=Rn().toVar(),l=Rn().toVar();return a.assign(u.assign(l.assign(Rn(An(3735928559)).add(o.shiftLeft(Rn(2))).add(Rn(13))))),a.addAssign(Rn(i)),u.addAssign(Rn(n)),l.addAssign(Rn(r)),zT(a,u,l)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),yn((([e,t,s,r])=>{const n=An(r).toVar(),i=An(s).toVar(),o=An(t).toVar(),a=An(e).toVar(),u=Rn(Rn(4)).toVar(),l=Rn().toVar(),d=Rn().toVar(),c=Rn().toVar();return l.assign(d.assign(c.assign(Rn(An(3735928559)).add(u.shiftLeft(Rn(2))).add(Rn(13))))),l.addAssign(Rn(a)),d.addAssign(Rn(o)),c.addAssign(Rn(i)),kT(l,d,c),l.addAssign(Rn(n)),zT(l,d,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),yn((([e,t,s,r,n])=>{const i=An(n).toVar(),o=An(r).toVar(),a=An(s).toVar(),u=An(t).toVar(),l=An(e).toVar(),d=Rn(Rn(5)).toVar(),c=Rn().toVar(),h=Rn().toVar(),p=Rn().toVar();return c.assign(h.assign(p.assign(Rn(An(3735928559)).add(d.shiftLeft(Rn(2))).add(Rn(13))))),c.addAssign(Rn(l)),h.addAssign(Rn(u)),p.addAssign(Rn(a)),kT(c,h,p),c.addAssign(Rn(o)),h.addAssign(Rn(i)),zT(c,h,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),jT=Fm([yn((([e,t])=>{const s=An(t).toVar(),r=An(e).toVar(),n=Rn(WT(r,s)).toVar(),i=Pn().toVar();return i.x.assign(n.bitAnd(An(255))),i.y.assign(n.shiftRight(An(8)).bitAnd(An(255))),i.z.assign(n.shiftRight(An(16)).bitAnd(An(255))),i})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),yn((([e,t,s])=>{const r=An(s).toVar(),n=An(t).toVar(),i=An(e).toVar(),o=Rn(WT(i,n,r)).toVar(),a=Pn().toVar();return a.x.assign(o.bitAnd(An(255))),a.y.assign(o.shiftRight(An(8)).bitAnd(An(255))),a.z.assign(o.shiftRight(An(16)).bitAnd(An(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),qT=Fm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(CT(t.x,s)).toVar(),i=Sn(CT(t.y,r)).toVar(),o=Sn(HT(n)).toVar(),a=Sn(HT(i)).toVar(),u=Sn(ET(UT(WT(s,r),n,i),UT(WT(s.add(An(1)),r),n.sub(1),i),UT(WT(s,r.add(An(1))),n,i.sub(1)),UT(WT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(CT(t.x,s)).toVar(),o=Sn(CT(t.y,r)).toVar(),a=Sn(CT(t.z,n)).toVar(),u=Sn(HT(i)).toVar(),l=Sn(HT(o)).toVar(),d=Sn(HT(a)).toVar(),c=Sn(wT(UT(WT(s,r,n),i,o,a),UT(WT(s.add(An(1)),r,n),i.sub(1),o,a),UT(WT(s,r.add(An(1)),n),i,o.sub(1),a),UT(WT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),UT(WT(s,r,n.add(An(1))),i,o,a.sub(1)),UT(WT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),UT(WT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),UT(WT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),KT=Fm([yn((([e])=>{const t=En(e).toVar(),s=An().toVar(),r=An().toVar(),n=Sn(CT(t.x,s)).toVar(),i=Sn(CT(t.y,r)).toVar(),o=Sn(HT(n)).toVar(),a=Sn(HT(i)).toVar(),u=Un(ET(IT(jT(s,r),n,i),IT(jT(s.add(An(1)),r),n.sub(1),i),IT(jT(s,r.add(An(1))),n,i.sub(1)),IT(jT(s.add(An(1)),r.add(An(1))),n.sub(1),i.sub(1)),o,a)).toVar();return VT(u)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An().toVar(),r=An().toVar(),n=An().toVar(),i=Sn(CT(t.x,s)).toVar(),o=Sn(CT(t.y,r)).toVar(),a=Sn(CT(t.z,n)).toVar(),u=Sn(HT(i)).toVar(),l=Sn(HT(o)).toVar(),d=Sn(HT(a)).toVar(),c=Un(wT(IT(jT(s,r,n),i,o,a),IT(jT(s.add(An(1)),r,n),i.sub(1),o,a),IT(jT(s,r.add(An(1)),n),i,o.sub(1),a),IT(jT(s.add(An(1)),r.add(An(1)),n),i.sub(1),o.sub(1),a),IT(jT(s,r,n.add(An(1))),i,o,a.sub(1)),IT(jT(s.add(An(1)),r,n.add(An(1))),i.sub(1),o,a.sub(1)),IT(jT(s,r.add(An(1)),n.add(An(1))),i,o.sub(1),a.sub(1)),IT(jT(s.add(An(1)),r.add(An(1)),n.add(An(1))),i.sub(1),o.sub(1),a.sub(1)),u,l,d)).toVar();return OT(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),XT=Fm([yn((([e])=>{const t=Sn(e).toVar(),s=An(RT(t)).toVar();return $T(WT(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar();return $T(WT(s,r))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar(),n=An(RT(t.z)).toVar();return $T(WT(s,r,n))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar(),n=An(RT(t.z)).toVar(),i=An(RT(t.w)).toVar();return $T(WT(s,r,n,i))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),YT=Fm([yn((([e])=>{const t=Sn(e).toVar(),s=An(RT(t)).toVar();return Un($T(WT(s,An(0))),$T(WT(s,An(1))),$T(WT(s,An(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),yn((([e])=>{const t=En(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar();return Un($T(WT(s,r,An(0))),$T(WT(s,r,An(1))),$T(WT(s,r,An(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),yn((([e])=>{const t=Un(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar(),n=An(RT(t.z)).toVar();return Un($T(WT(s,r,n,An(0))),$T(WT(s,r,n,An(1))),$T(WT(s,r,n,An(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),yn((([e])=>{const t=Ln(e).toVar(),s=An(RT(t.x)).toVar(),r=An(RT(t.y)).toVar(),n=An(RT(t.z)).toVar(),i=An(RT(t.w)).toVar();return Un($T(WT(s,r,n,i,An(0))),$T(WT(s,r,n,i,An(1))),$T(WT(s,r,n,i,An(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),QT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Sn(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(qT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),ZT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(0).toVar(),l=Sn(1).toVar();return uc(o,(()=>{u.addAssign(l.mul(KT(a))),l.mulAssign(n),a.mulAssign(i)})),u})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),JT=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar();return En(QT(a,o,i,n),QT(a.add(Un(An(19),An(193),An(17))),o,i,n))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),e_=yn((([e,t,s,r])=>{const n=Sn(r).toVar(),i=Sn(s).toVar(),o=An(t).toVar(),a=Un(e).toVar(),u=Un(ZT(a,o,i,n)).toVar(),l=Sn(QT(a.add(Un(An(19),An(193),An(17))),o,i,n)).toVar();return Ln(u,l)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),t_=Fm([yn((([e,t,s,r,n,i,o])=>{const a=An(o).toVar(),u=Sn(i).toVar(),l=An(n).toVar(),d=An(r).toVar(),c=An(s).toVar(),h=An(t).toVar(),p=En(e).toVar(),g=Un(YT(En(h.add(d),c.add(l)))).toVar(),m=En(g.x,g.y).toVar();m.subAssign(.5),m.mulAssign(u),m.addAssign(.5);const f=En(En(Sn(h),Sn(c)).add(m)).toVar(),y=En(f.sub(p)).toVar();return _n(a.equal(An(2)),(()=>Fo(y.x).add(Fo(y.y)))),_n(a.equal(An(3)),(()=>Ko(Fo(y.x),Fo(y.y)))),ea(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),yn((([e,t,s,r,n,i,o,a,u])=>{const l=An(u).toVar(),d=Sn(a).toVar(),c=An(o).toVar(),h=An(i).toVar(),p=An(n).toVar(),g=An(r).toVar(),m=An(s).toVar(),f=An(t).toVar(),y=Un(e).toVar(),b=Un(YT(Un(f.add(p),m.add(h),g.add(c)))).toVar();b.subAssign(.5),b.mulAssign(d),b.addAssign(.5);const x=Un(Un(Sn(f),Sn(m),Sn(g)).add(b)).toVar(),T=Un(x.sub(y)).toVar();return _n(l.equal(An(2)),(()=>Fo(T.x).add(Fo(T.y)).add(Fo(T.z)))),_n(l.equal(An(3)),(()=>Ko(Ko(Fo(T.x),Fo(T.y)),Fo(T.z)))),ea(T,T)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),s_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(CT(i.x,o),CT(i.y,a)).toVar(),l=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(t_(u,e,t,o,a,n,r)).toVar();l.assign(qo(l,s))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),r_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(CT(i.x,o),CT(i.y,a)).toVar(),l=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(t_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.y.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),n_=yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=En(e).toVar(),o=An().toVar(),a=An().toVar(),u=En(CT(i.x,o),CT(i.y,a)).toVar(),l=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{const s=Sn(t_(u,e,t,o,a,n,r)).toVar();_n(s.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(s)})).ElseIf(s.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(s)})).ElseIf(s.lessThan(l.z),(()=>{l.z.assign(s)}))}))})),_n(r.equal(An(0)),(()=>{l.assign(_o(l))})),l})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),i_=Fm([s_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(CT(i.x,o),CT(i.y,a),CT(i.z,u)).toVar(),d=Sn(1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(t_(l,e,t,s,o,a,u,n,r)).toVar();d.assign(qo(d,i))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),o_=Fm([r_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(CT(i.x,o),CT(i.y,a),CT(i.z,u)).toVar(),d=En(1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(t_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.y.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),a_=Fm([n_,yn((([e,t,s])=>{const r=An(s).toVar(),n=Sn(t).toVar(),i=Un(e).toVar(),o=An().toVar(),a=An().toVar(),u=An().toVar(),l=Un(CT(i.x,o),CT(i.y,a),CT(i.z,u)).toVar(),d=Un(1e6,1e6,1e6).toVar();return uc({start:-1,end:An(1),name:"x",condition:"<="},(({x:e})=>{uc({start:-1,end:An(1),name:"y",condition:"<="},(({y:t})=>{uc({start:-1,end:An(1),name:"z",condition:"<="},(({z:s})=>{const i=Sn(t_(l,e,t,s,o,a,u,n,r)).toVar();_n(i.lessThan(d.x),(()=>{d.z.assign(d.y),d.y.assign(d.x),d.x.assign(i)})).ElseIf(i.lessThan(d.y),(()=>{d.z.assign(d.y),d.y.assign(i)})).ElseIf(i.lessThan(d.z),(()=>{d.z.assign(i)}))}))}))})),_n(r.equal(An(0)),(()=>{d.assign(_o(d))})),d})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),u_=yn((([e])=>{const t=e.y,s=e.z,r=Un().toVar();return _n(t.lessThan(1e-4),(()=>{r.assign(Un(s,s,s))})).Else((()=>{let n=e.x;n=n.sub(vo(n)).mul(6).toVar();const i=An(zo(n)),o=n.sub(Sn(i)),a=s.mul(t.oneMinus()),u=s.mul(t.mul(o).oneMinus()),l=s.mul(t.mul(o.oneMinus()).oneMinus());_n(i.equal(An(0)),(()=>{r.assign(Un(s,l,a))})).ElseIf(i.equal(An(1)),(()=>{r.assign(Un(u,s,a))})).ElseIf(i.equal(An(2)),(()=>{r.assign(Un(a,s,l))})).ElseIf(i.equal(An(3)),(()=>{r.assign(Un(a,u,s))})).ElseIf(i.equal(An(4)),(()=>{r.assign(Un(l,a,s))})).Else((()=>{r.assign(Un(s,a,u))}))})),r})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),l_=yn((([e])=>{const t=Un(e).toVar(),s=Sn(t.x).toVar(),r=Sn(t.y).toVar(),n=Sn(t.z).toVar(),i=Sn(qo(s,qo(r,n))).toVar(),o=Sn(Ko(s,Ko(r,n))).toVar(),a=Sn(o.sub(i)).toVar(),u=Sn().toVar(),l=Sn().toVar(),d=Sn().toVar();return d.assign(o),_n(o.greaterThan(0),(()=>{l.assign(a.div(o))})).Else((()=>{l.assign(0)})),_n(l.lessThanEqual(0),(()=>{u.assign(0)})).Else((()=>{_n(s.greaterThanEqual(o),(()=>{u.assign(r.sub(n).div(a))})).ElseIf(r.greaterThanEqual(o),(()=>{u.assign(Vi(2,n.sub(s).div(a)))})).Else((()=>{u.assign(Vi(4,s.sub(r).div(a)))})),u.mulAssign(1/6),_n(u.lessThan(0),(()=>{u.addAssign(1)}))})),Un(u,l,d)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),d_=yn((([e])=>{const t=Un(e).toVar(),s=In(ji(t,Un(.04045))).toVar(),r=Un(t.div(12.92)).toVar(),n=Un(sa(Ko(t.add(Un(.055)),Un(0)).div(1.055),Un(2.4))).toVar();return la(r,n,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),c_=(e,t)=>{e=Sn(e),t=Sn(t);const s=En(t.dFdx(),t.dFdy()).length().mul(.7071067811865476);return pa(e.sub(s),e.add(s),t)},h_=(e,t,s,r)=>la(e,t,s[r].clamp()),p_=(e,t,s=mu())=>h_(e,t,s,"x"),g_=(e,t,s=mu())=>h_(e,t,s,"y"),m_=(e,t,s,r,n)=>la(e,t,c_(s,r[n])),f_=(e,t,s,r=mu())=>m_(e,t,s,r,"x"),y_=(e,t,s,r=mu())=>m_(e,t,s,r,"y"),b_=(e=1,t=0,s=mu())=>s.mul(e).add(t),x_=(e,t=1)=>(e=Sn(e)).abs().pow(t).mul(e.sign()),T_=(e,t=1,s=.5)=>Sn(e).sub(s).mul(t).add(s),__=(e=mu(),t=1,s=0)=>qT(e.convert("vec2|vec3")).mul(t).add(s),N_=(e=mu(),t=1,s=0)=>KT(e.convert("vec2|vec3")).mul(t).add(s),v_=(e=mu(),t=1,s=0)=>{e=e.convert("vec2|vec3");return Ln(KT(e),qT(e.add(En(19,73)))).mul(t).add(s)},S_=(e=mu(),t=1)=>i_(e.convert("vec2|vec3"),t,An(1)),A_=(e=mu(),t=1)=>o_(e.convert("vec2|vec3"),t,An(1)),R_=(e=mu(),t=1)=>a_(e.convert("vec2|vec3"),t,An(1)),C_=(e=mu())=>XT(e.convert("vec2|vec3")),E_=(e=mu(),t=3,s=2,r=.5,n=1)=>QT(e,An(t),s,r).mul(n),w_=(e=mu(),t=3,s=2,r=.5,n=1)=>JT(e,An(t),s,r).mul(n),M_=(e=mu(),t=3,s=2,r=.5,n=1)=>ZT(e,An(t),s,r).mul(n),B_=(e=mu(),t=3,s=2,r=.5,n=1)=>e_(e,An(t),s,r).mul(n),U_=yn((([e,t,s])=>{const r=Ao(e).toVar("nDir"),n=Oi(Sn(.5).mul(t.sub(s)),Zu).div(r).toVar("rbmax"),i=Oi(Sn(-.5).mul(t.sub(s)),Zu).div(r).toVar("rbmin"),o=Un().toVar("rbminmax");o.x=r.x.greaterThan(Sn(0)).select(n.x,i.x),o.y=r.y.greaterThan(Sn(0)).select(n.y,i.y),o.z=r.z.greaterThan(Sn(0)).select(n.z,i.z);const a=qo(qo(o.x,o.y),o.z).toVar("correction");return Zu.add(r.mul(a)).toVar("boxIntersection").sub(s)})),F_=yn((([e,t])=>{const s=e.x,r=e.y,n=e.z;let i=t.element(0).mul(.886227);return i=i.add(t.element(1).mul(1.023328).mul(r)),i=i.add(t.element(2).mul(1.023328).mul(n)),i=i.add(t.element(3).mul(1.023328).mul(s)),i=i.add(t.element(4).mul(.858086).mul(s).mul(r)),i=i.add(t.element(5).mul(.858086).mul(r).mul(n)),i=i.add(t.element(6).mul(n.mul(n).mul(.743125).sub(.247708))),i=i.add(t.element(7).mul(.858086).mul(s).mul(n)),i=i.add(t.element(8).mul(.429043).mul(Gi(s,s).sub(Gi(r,r)))),i})),P_=new hm;class I_ extends Dg{constructor(e,t){super(),this.renderer=e,this.nodes=t}update(e,t,s){const r=this.renderer,n=this.nodes.getBackgroundNode(e)||e.background;let i=!1;if(null===n)r._clearColor.getRGB(P_,Se),P_.a=r._clearColor.a;else if(!0===n.isColor)n.getRGB(P_,Se),P_.a=1,i=!0;else if(!0===n.isNode){const s=this.get(e),i=n;P_.copy(r._clearColor);let o=s.backgroundMesh;if(void 0===o){const e=Na(Ln(i).mul(Lf),{getUV:()=>Df.mul(ll),getTextureLevel:()=>If});let t=Wd();t=t.setZ(t.w);const r=new nh;r.name="Background.material",r.side=x,r.depthTest=!1,r.depthWrite=!1,r.fog=!1,r.lights=!1,r.vertexNode=t,r.colorNode=e,s.backgroundMeshNode=e,s.backgroundMesh=o=new k(new Ee(1,32,32),r),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(e,t,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=i.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=Ln(i).mul(Lf),s.backgroundMeshNode.needsUpdate=!0,o.material.needsUpdate=!0,s.backgroundCacheKey=a),t.unshift(o,o.geometry,o.material,0,0,null,null)}else console.error("THREE.Renderer: Unsupported background configuration.",n);if(!0===r.autoClear||!0===i){const e=s.clearColorValue;e.r=P_.r,e.g=P_.g,e.b=P_.b,e.a=P_.a,!0!==r.backend.isWebGLBackend&&!0!==r.alpha||(e.r*=e.a,e.g*=e.a,e.b*=e.a),s.depthClearValue=r._clearDepth,s.stencilClearValue=r._clearStencil,s.clearColor=!0===r.autoClearColor,s.clearDepth=!0===r.autoClearDepth,s.clearStencil=!0===r.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}let L_=0;class D_{constructor(e="",t=[],s=0,r=[]){this.name=e,this.bindings=t,this.index=s,this.bindingsReference=r,this.id=L_++}}class V_{constructor(e,t,s,r,n,i,o,a,u,l=[]){this.vertexShader=e,this.fragmentShader=t,this.computeShader=s,this.transforms=l,this.nodeAttributes=r,this.bindings=n,this.updateNodes=i,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.monitor=u,this.usedTimes=0}createBindings(){const e=[];for(const t of this.bindings){if(!0!==t.bindings[0].groupNode.shared){const s=new D_(t.name,[],t.index,t);e.push(s);for(const e of t.bindings)s.bindings.push(e.clone())}else e.push(t)}return e}}class O_{constructor(e,t,s=null){this.isNodeAttribute=!0,this.name=e,this.type=t,this.node=s}}class G_{constructor(e,t,s){this.isNodeUniform=!0,this.name=e,this.type=t,this.node=s.getSelf()}get value(){return this.node.value}set value(e){this.node.value=e}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class k_{constructor(e,t){this.isNodeVar=!0,this.name=e,this.type=t}}class z_ extends k_{constructor(e,t){super(e,t),this.needsInterpolation=!1,this.isNodeVarying=!0}}class $_{constructor(e,t,s=""){this.name=e,this.type=t,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}let H_=0;class W_{constructor(e=null){this.id=H_++,this.nodesData=new WeakMap,this.parent=e}getData(e){let t=this.nodesData.get(e);return void 0===t&&null!==this.parent&&(t=this.parent.getData(e)),t}setData(e,t){this.nodesData.set(e,t)}}class j_{constructor(e,t){this.name=e,this.value=t,this.boundary=0,this.itemSize=0,this.offset=0}setValue(e){this.value=e}getValue(){return this.value}}class q_ extends j_{constructor(e,t=0){super(e,t),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class K_ extends j_{constructor(e,s=new t){super(e,s),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class X_ extends j_{constructor(e,t=new s){super(e,t),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class Y_ extends j_{constructor(e,t=new r){super(e,t),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class Q_ extends j_{constructor(t,s=new e){super(t,s),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class Z_ extends j_{constructor(e,t=new n){super(e,t),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class J_ extends j_{constructor(e,t=new i){super(e,t),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class eN extends q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class tN extends K_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class sN extends X_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class rN extends Y_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class nN extends Q_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class iN extends Z_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}class oN extends J_{constructor(e){super(e.name,e.value),this.nodeUniform=e}getValue(){return this.nodeUniform.value}}const aN=[.125,.215,.35,.446,.526,.582],uN=20,lN=new xe(-1,1,1,-1,0,1),dN=new Be(90,1),cN=new e;let hN=null,pN=0,gN=0;const mN=(1+Math.sqrt(5))/2,fN=1/mN,yN=[new s(-mN,fN,0),new s(mN,fN,0),new s(-fN,0,mN),new s(fN,0,mN),new s(0,mN,-fN),new s(0,mN,fN),new s(-1,1,-1),new s(1,1,-1),new s(-1,1,1),new s(1,1,1)],bN=[3,1,5,0,4,2],xN=Hp(mu(),gu("faceIndex")).normalize(),TN=Un(xN.x,xN.y.negate(),xN.z);class _N{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(e,t=0,s=.1,r=100){hN=this._renderer.getRenderTarget(),pN=this._renderer.getActiveCubeFace(),gN=this._renderer.getActiveMipmapLevel(),this._setSize(256);const n=this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(e,s,r,n),t>0&&this._blur(n,0,0,t),this._applyPMREM(n),this._cleanup(n),n}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=AN(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=RN(),await this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let e=0;ee-4?u=aN[a-e+4-1]:0===a&&(u=0),r.push(u);const l=1/(o-2),d=-l,c=1+l,h=[d,d,c,d,c,c,d,d,c,c,d,c],p=6,g=6,m=3,f=2,y=1,b=new Float32Array(m*g*p),x=new Float32Array(f*g*p),T=new Float32Array(y*g*p);for(let e=0;e2?0:-1,r=[t,s,0,t+2/3,s,0,t+2/3,s+1,0,t,s,0,t+2/3,s+1,0,t,s+1,0],n=bN[e];b.set(r,m*g*n),x.set(h,f*g*n);const i=[n,n,n,n,n,n];T.set(i,y*g*n)}const _=new Te;_.setAttribute("position",new we(b,m)),_.setAttribute("uv",new we(x,f)),_.setAttribute("faceIndex",new we(T,y)),t.push(_),n.push(new k(_,null)),i>4&&i--}return{lodPlanes:t,sizeLods:s,sigmas:r,lodMeshes:n}}(n)),this._blurMaterial=function(e,t,r){const n=Rl(new Array(uN).fill(0)),i=ti(new s(0,1,0)),o=ti(0),a=Sn(uN),u=ti(0),l=ti(1),d=_u(null),c=ti(0),h=Sn(1/t),p=Sn(1/r),g=Sn(e),m={n:a,latitudinal:u,weights:n,poleAxis:i,outputDirection:TN,dTheta:o,samples:l,envMap:d,mipInt:c,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:p,CUBEUV_MAX_MIP:g},f=SN("blur");return f.uniforms=m,f.fragmentNode=Kp({...m,latitudinal:u.equal(1)}),f}(n,e,t)}return n}async _compileMaterial(e){const t=new k(this._lodPlanes[0],e);await this._renderer.compile(t,lN)}_sceneToCubeUV(e,t,s,r){const n=dN;n.near=t,n.far=s;const i=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,u=a.autoClear;a.getClearColor(cN),a.autoClear=!1;let l=this._backgroundBox;if(null===l){const e=new Q({name:"PMREM.Background",side:x,depthWrite:!1,depthTest:!1});l=new k(new O,e)}let d=!1;const c=e.background;c?c.isColor&&(l.material.color.copy(c),e.background=null,d=!0):(l.material.color.copy(cN),d=!0),a.setRenderTarget(r),a.clear(),d&&a.render(l,n);for(let t=0;t<6;t++){const s=t%3;0===s?(n.up.set(0,i[t],0),n.lookAt(o[t],0,0)):1===s?(n.up.set(0,0,i[t]),n.lookAt(0,o[t],0)):(n.up.set(0,i[t],0),n.lookAt(0,0,o[t]));const u=this._cubeSize;vN(r,s*u,t>2?u:0,u,u),a.render(e,n)}a.autoClear=u,e.background=c}_textureToCubeUV(e,t){const s=this._renderer,r=e.mapping===T||e.mapping===_;r?null===this._cubemapMaterial&&(this._cubemapMaterial=AN(e)):null===this._equirectMaterial&&(this._equirectMaterial=RN(e));const n=r?this._cubemapMaterial:this._equirectMaterial;n.fragmentNode.value=e;const i=this._lodMeshes[0];i.material=n;const o=this._cubeSize;vN(t,0,0,3*o,2*o),s.setRenderTarget(t),s.render(i,lN)}_applyPMREM(e){const t=this._renderer,s=t.autoClear;t.autoClear=!1;const r=this._lodPlanes.length;for(let t=1;tuN&&console.warn(`sigmaRadians, ${n}, is too large and will clip, as it requested ${g} samples when the maximum is set to 20`);const m=[];let f=0;for(let e=0;ey-4?r-y+4:0),4*(this._cubeSize-b),3*b,2*b),a.setRenderTarget(t),a.render(l,lN)}}function NN(e,t,s){const r=new ge(e,t,s);return r.texture.mapping=Me,r.texture.name="PMREM.cubeUv",r.texture.isPMREMTexture=!0,r.scissorTest=!0,r}function vN(e,t,s,r,n){e.viewport.set(t,s,r,n),e.scissor.set(t,s,r,n)}function SN(e){const t=new nh;return t.depthTest=!1,t.depthWrite=!1,t.blending=G,t.name=`PMREM_${e}`,t}function AN(e){const t=SN("cubemap");return t.fragmentNode=_l(e,TN),t}function RN(e){const t=SN("equirect");return t.fragmentNode=_u(e,bh(TN),0),t}const CN=new WeakMap,EN=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),wN=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),MN=e=>/e/g.test(e)?String(e).replace(/\+/g,""):(e=Number(e))+(e%1?"":".0");class BN{constructor(e,t,s){this.object=e,this.material=e&&e.material||null,this.geometry=e&&e.geometry||null,this.renderer=t,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=fm(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new W_,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let e=CN.get(this.renderer);return void 0===e&&(e=new Ug,CN.set(this.renderer,e)),e}createRenderTarget(e,t,s){return new ge(e,t,s)}createCubeRenderTarget(e,t){return new xh(e,t)}createPMREMGenerator(){return new _N(this.renderer)}includes(e){return this.nodes.includes(e)}_getBindGroup(e,t){const s=this.getBindGroupsCache(),r=[];let n,i=!0;for(const e of t)r.push(e),i=i&&!0!==e.groupNode.shared;return i?(n=s.get(r),void 0===n&&(n=new D_(e,r,this.bindingsIndexes[e].group,r),s.set(r,n))):n=new D_(e,r,this.bindingsIndexes[e].group,r),n}getBindGroupArray(e,t){const s=this.bindings[t];let r=s[e];return void 0===r&&(void 0===this.bindingsIndexes[e]&&(this.bindingsIndexes[e]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[e]=r=[]),r}getBindings(){let e=this.bindGroups;if(null===e){const t={},s=this.bindings;for(const e of Nr)for(const r in s[e]){const n=s[e][r];(t[r]||(t[r]=[])).push(...n)}e=[];for(const s in t){const r=t[s],n=this._getBindGroup(s,r);e.push(n)}this.bindGroups=e}return e}sortBindingGroups(){const e=this.getBindings();e.sort(((e,t)=>e.bindings[0].groupNode.order-t.bindings[0].groupNode.order));for(let t=0;t=0?`${Math.round(i)}u`:"0u";if("bool"===n)return i?"true":"false";if("color"===n)return`${this.getType("vec3")}( ${MN(i.r)}, ${MN(i.g)}, ${MN(i.b)} )`;const o=this.getTypeLength(n),a=this.getComponentType(n),u=e=>this.generateConst(a,e);if(2===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)} )`;if(3===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)} )`;if(4===o)return`${this.getType(n)}( ${u(i.x)}, ${u(i.y)}, ${u(i.z)}, ${u(i.w)} )`;if(o>4&&i&&(i.isMatrix3||i.isMatrix4))return`${this.getType(n)}( ${i.elements.map(u).join(", ")} )`;if(o>4)return`${this.getType(n)}()`;throw new Error(`NodeBuilder: Type '${n}' not found in generate constant attempt.`)}getType(e){return"color"===e?"vec3":e}hasGeometryAttribute(e){return this.geometry&&void 0!==this.geometry.getAttribute(e)}getAttribute(e,t){const s=this.attributes;for(const t of s)if(t.name===e)return t;const r=new O_(e,t);return s.push(r),r}getPropertyName(e){return e.name}isVector(e){return/vec\d/.test(e)}isMatrix(e){return/mat\d/.test(e)}isReference(e){return"void"===e||"property"===e||"sampler"===e||"texture"===e||"cubeTexture"===e||"storageTexture"===e||"depthTexture"===e||"texture3D"===e}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(e){const t=e.type;if(e.isDataTexture){if(t===y)return"int";if(t===f)return"uint"}return"float"}getElementType(e){return"mat2"===e?"vec2":"mat3"===e?"vec3":"mat4"===e?"vec4":this.getComponentType(e)}getComponentType(e){if("float"===(e=this.getVectorType(e))||"bool"===e||"int"===e||"uint"===e)return e;const t=/(b|i|u|)(vec|mat)([2-4])/.exec(e);return null===t?null:"b"===t[1]?"bool":"i"===t[1]?"int":"u"===t[1]?"uint":"float"}getVectorType(e){return"color"===e?"vec3":"texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e?"vec4":e}getTypeFromLength(e,t="float"){if(1===e)return t;const s=EN.get(e);return("float"===t?"":t[0])+s}getTypeFromArray(e){return wN.get(e.constructor)}getTypeFromAttribute(e){let t=e;e.isInterleavedBufferAttribute&&(t=e.data);const s=t.array,r=e.itemSize,n=e.normalized;let i;return e instanceof Ie||!0===n||(i=this.getTypeFromArray(s)),this.getTypeFromLength(r,i)}getTypeLength(e){const t=this.getVectorType(e),s=/vec([2-4])/.exec(t);return null!==s?Number(s[1]):"float"===t||"bool"===t||"int"===t||"uint"===t?1:!0===/mat2/.test(e)?4:!0===/mat3/.test(e)?9:!0===/mat4/.test(e)?16:0}getVectorFromMatrix(e){return e.replace("mat","vec")}changeComponentType(e,t){return this.getTypeFromLength(this.getTypeLength(e),t)}getIntegerType(e){const t=this.getComponentType(e);return"int"===t||"uint"===t?e:this.changeComponentType(e,"int")}addStack(){return this.stack=fm(this.stack),this.stacks.push(Tn()||this.stack),xn(this.stack),this.stack}removeStack(){const e=this.stack;return this.stack=e.parent,xn(this.stacks.pop()),e}getDataFromNode(e,t=this.shaderStage,s=null){let r=(s=null===s?e.isGlobal(this)?this.globalCache:this.cache:s).getData(e);return void 0===r&&(r={},s.setData(e,r)),void 0===r[t]&&(r[t]={}),r[t]}getNodeProperties(e,t="any"){const s=this.getDataFromNode(e,t);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(e,t){const s=this.getDataFromNode(e);let r=s.bufferAttribute;if(void 0===r){const n=this.uniforms.index++;r=new O_("nodeAttribute"+n,t,e),this.bufferAttributes.push(r),s.bufferAttribute=r}return r}getStructTypeFromNode(e,t=this.shaderStage){const s=this.getDataFromNode(e,t);if(void 0===s.structType){const r=this.structs.index++;e.name=`StructType${r}`,this.structs[t].push(e),s.structType=e}return e}getUniformFromNode(e,t,s=this.shaderStage,r=null){const n=this.getDataFromNode(e,s,this.globalCache);let i=n.uniform;if(void 0===i){const o=this.uniforms.index++;i=new G_(r||"nodeUniform"+o,t,e),this.uniforms[s].push(i),n.uniform=i}return i}getVarFromNode(e,t=null,s=e.getNodeType(this),r=this.shaderStage){const n=this.getDataFromNode(e,r);let i=n.variable;if(void 0===i){const e=this.vars[r]||(this.vars[r]=[]);null===t&&(t="nodeVar"+e.length),i=new k_(t,s),e.push(i),n.variable=i}return i}getVaryingFromNode(e,t=null,s=e.getNodeType(this)){const r=this.getDataFromNode(e,"any");let n=r.varying;if(void 0===n){const e=this.varyings,i=e.length;null===t&&(t="nodeVarying"+i),n=new z_(t,s),e.push(n),r.varying=n}return n}getCodeFromNode(e,t,s=this.shaderStage){const r=this.getDataFromNode(e);let n=r.code;if(void 0===n){const e=this.codes[s]||(this.codes[s]=[]),i=e.length;n=new $_("nodeCode"+i,t),e.push(n),r.code=n}return n}addFlowCodeHierarchy(e,t){const{flowCodes:s,flowCodeBlock:r}=this.getDataFromNode(e);let n=!0,i=t;for(;i;){if(!0===r.get(i)){n=!1;break}i=this.getDataFromNode(i).parentNodeBlock}if(n)for(const e of s)this.addLineFlowCode(e)}addLineFlowCodeBlock(e,t,s){const r=this.getDataFromNode(e),n=r.flowCodes||(r.flowCodes=[]),i=r.flowCodeBlock||(r.flowCodeBlock=new WeakMap);n.push(t),i.set(s,!0)}addLineFlowCode(e,t=null){return""===e||(null!==t&&this.context.nodeBlock&&this.addLineFlowCodeBlock(t,e,this.context.nodeBlock),e=this.tab+e,/;\s*$/.test(e)||(e+=";\n"),this.flow.code+=e),this}addFlowCode(e){return this.flow.code+=e,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(e){return this.flowsData.get(e)}flowNode(e){const t=e.getNodeType(this),s=this.flowChildNode(e,t);return this.flowsData.set(e,s),s}buildFunctionNode(e){const t=new ax,s=this.currentFunctionNode;return this.currentFunctionNode=t,t.code=this.buildFunctionCode(e),this.currentFunctionNode=s,t}flowShaderNode(e){const t=e.layout,s={[Symbol.iterator](){let e=0;const t=Object.values(this);return{next:()=>({value:t[e],done:e++>=t.length})}}};for(const e of t.inputs)s[e.name]=new pm(e.type,e.name);e.layout=null;const r=e.call(s),n=this.flowStagesNode(r,t.type);return e.layout=t,n}flowStagesNode(e,t=null){const s=this.flow,r=this.vars,n=this.cache,i=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new W_,this.stack=fm();for(const s of _r)this.setBuildStage(s),a.result=e.build(this,t);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=r,this.cache=n,this.stack=o,this.setBuildStage(i),a}getFunctionOperator(){return null}flowChildNode(e,t=null){const s=this.flow,r={code:""};return this.flow=r,r.result=e.build(this,t),this.flow=s,r}flowNodeFromShaderStage(e,t,s=null,r=null){const n=this.shaderStage;this.setShaderStage(e);const i=this.flowChildNode(t,s);return null!==r&&(i.code+=`${this.tab+r} = ${i.result};\n`),this.flowCode[e]=this.flowCode[e]+i.code,this.setShaderStage(n),i}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(e,t){return`${this.getType(e)} ${t}`}getVars(e){let t="";const s=this.vars[e];if(void 0!==s)for(const e of s)t+=`${this.getVar(e.type,e.name)}; `;return t}getUniforms(){console.warn("Abstract function.")}getCodes(e){const t=this.codes[e];let s="";if(void 0!==t)for(const e of t)s+=e.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(e){this.shaderStage=e}getShaderStage(){return this.shaderStage}setBuildStage(e){this.buildStage=e}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:e,material:t,renderer:s}=this;if(null!==t){let e=s.library.fromMaterial(t);null===e&&(console.error(`NodeMaterial: Material "${t.type}" is not compatible.`),e=new nh),e.build(this)}else this.addFlow("compute",e);for(const e of _r){this.setBuildStage(e),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const t of Nr){this.setShaderStage(t);const s=this.flowNodes[t];for(const t of s)"generate"===e?this.flowNode(t):t.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(e,t){if("float"===t||"int"===t||"uint"===t)return new eN(e);if("vec2"===t||"ivec2"===t||"uvec2"===t)return new tN(e);if("vec3"===t||"ivec3"===t||"uvec3"===t)return new sN(e);if("vec4"===t||"ivec4"===t||"uvec4"===t)return new rN(e);if("color"===t)return new nN(e);if("mat3"===t)return new iN(e);if("mat4"===t)return new oN(e);throw new Error(`Uniform "${t}" not declared.`)}createNodeMaterial(e="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${e}() instead.`)}format(e,t,s){if((t=this.getVectorType(t))===(s=this.getVectorType(s))||null===s||this.isReference(s))return e;const r=this.getTypeLength(t),n=this.getTypeLength(s);return 16===r&&9===n?`${this.getType(s)}(${e}[0].xyz, ${e}[1].xyz, ${e}[2].xyz)`:9===r&&4===n?`${this.getType(s)}(${e}[0].xy, ${e}[1].xy)`:r>4||n>4||0===n?e:r===n?`${this.getType(s)}( ${e} )`:r>n?this.format(`${e}.${"xyz".slice(0,n)}`,this.getTypeFromLength(n,this.getComponentType(t)),s):4===n&&r>1?`${this.getType(s)}( ${this.format(e,t,"vec3")}, 1.0 )`:2===r?`${this.getType(s)}( ${this.format(e,t,"vec2")}, 0.0 )`:(1===r&&n>1&&t!==this.getComponentType(s)&&(e=`${this.getType(this.getComponentType(s))}( ${e} )`),`${this.getType(s)}( ${e} )`)}getSignature(){return`// Three.js r${Le} - Node System\n`}}class UN{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(e,t){let s=e.get(t);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},e.set(t,s)),s}updateBeforeNode(e){const t=e.getUpdateBeforeType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.frameId&&!1!==e.updateBefore(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateBeforeMap,s);t.get(s)!==this.renderId&&!1!==e.updateBefore(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateBefore(this)}updateAfterNode(e){const t=e.getUpdateAfterType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.frameId&&!1!==e.updateAfter(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateAfterMap,s);t.get(s)!==this.renderId&&!1!==e.updateAfter(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.updateAfter(this)}updateNode(e){const t=e.getUpdateType(),s=e.updateReference(this);if(t===br.FRAME){const{frameMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.frameId&&!1!==e.update(this)&&t.set(s,this.frameId)}else if(t===br.RENDER){const{renderMap:t}=this._getMaps(this.updateMap,s);t.get(s)!==this.renderId&&!1!==e.update(this)&&t.set(s,this.renderId)}else t===br.OBJECT&&e.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class FN{constructor(e,t,s=null,r="",n=!1){this.type=e,this.name=t,this.count=s,this.qualifier=r,this.isConst=n}}FN.isNodeFunctionInput=!0;class PN extends xT{static get type(){return"DirectionalLightNode"}constructor(e=null){super(e)}setup(e){super.setup(e);const t=e.context.lightingModel,s=this.colorNode,r=rT(this.light),n=e.context.reflectedLight;t.direct({lightDirection:r,lightColor:s,reflectedLight:n},e.stack,e)}}const IN=new i,LN=new i;let DN=null;class VN extends xT{static get type(){return"RectAreaLightNode"}constructor(e=null){super(e),this.halfHeight=ti(new s).setGroup(Zn),this.halfWidth=ti(new s).setGroup(Zn),this.updateType=br.RENDER}update(e){super.update(e);const{light:t}=this,s=e.camera.matrixWorldInverse;LN.identity(),IN.copy(t.matrixWorld),IN.premultiply(s),LN.extractRotation(IN),this.halfWidth.value.set(.5*t.width,0,0),this.halfHeight.value.set(0,.5*t.height,0),this.halfWidth.value.applyMatrix4(LN),this.halfHeight.value.applyMatrix4(LN)}setup(e){let t,s;super.setup(e),e.isAvailable("float32Filterable")?(t=_u(DN.LTC_FLOAT_1),s=_u(DN.LTC_FLOAT_2)):(t=_u(DN.LTC_HALF_1),s=_u(DN.LTC_HALF_2));const{colorNode:r,light:n}=this,i=e.context.lightingModel,o=sT(n),a=e.context.reflectedLight;i.directRectArea({lightColor:r,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:t,ltc_2:s},e.stack,e)}static setLTC(e){DN=e}}class ON extends xT{static get type(){return"SpotLightNode"}constructor(e=null){super(e),this.coneCosNode=ti(0).setGroup(Zn),this.penumbraCosNode=ti(0).setGroup(Zn),this.cutoffDistanceNode=ti(0).setGroup(Zn),this.decayExponentNode=ti(0).setGroup(Zn)}update(e){super.update(e);const{light:t}=this;this.coneCosNode.value=Math.cos(t.angle),this.penumbraCosNode.value=Math.cos(t.angle*(1-t.penumbra)),this.cutoffDistanceNode.value=t.distance,this.decayExponentNode.value=t.decay}getSpotAttenuation(e){const{coneCosNode:t,penumbraCosNode:s}=this;return pa(t,s,e)}setup(e){super.setup(e);const t=e.context.lightingModel,{colorNode:s,cutoffDistanceNode:r,decayExponentNode:n,light:i}=this,o=sT(i).sub(el),a=o.normalize(),u=a.dot(rT(i)),l=this.getSpotAttenuation(u),d=o.length(),c=TT({lightDistance:d,cutoffDistance:r,decayExponent:n}),h=s.mul(l).mul(c),p=e.context.reflectedLight;t.direct({lightDirection:a,lightColor:h,reflectedLight:p},e.stack,e)}}class GN extends ON{static get type(){return"IESSpotLightNode"}getSpotAttenuation(e){const t=this.light.iesMap;let s=null;if(t&&!0===t.isTexture){const r=e.acos().mul(1/Math.PI);s=_u(t,En(r,0),0).r}else s=super.getSpotAttenuation(e);return s}}class kN extends xT{static get type(){return"AmbientLightNode"}constructor(e=null){super(e)}setup({context:e}){e.irradiance.addAssign(this.colorNode)}}class zN extends xT{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=eT(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=ti(new e).setGroup(Zn)}update(e){const{light:t}=this;super.update(e),this.lightPositionNode.object3d=t,this.groundColorNode.value.copy(t.groundColor).multiplyScalar(t.intensity)}setup(e){const{colorNode:t,groundColorNode:s,lightDirectionNode:r}=this,n=ul.dot(r).mul(.5).add(.5),i=la(s,t,n);e.context.irradiance.addAssign(i)}}class $N extends xT{static get type(){return"LightProbeNode"}constructor(e=null){super(e);const t=[];for(let e=0;e<9;e++)t.push(new s);this.lightProbe=Rl(t)}update(e){const{light:t}=this;super.update(e);for(let e=0;e<9;e++)this.lightProbe.array[e].copy(t.sh.coefficients[e]).multiplyScalar(t.intensity)}setup(e){const t=F_(ll,this.lightProbe);e.context.irradiance.addAssign(t)}}class HN{parseFunction(){console.warn("Abstract function.")}}class WN{constructor(e,t,s="",r=""){this.type=e,this.inputs=t,this.name=s,this.precision=r}getCode(){console.warn("Abstract function.")}}WN.isNodeFunction=!0;const jN=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,qN=/[a-z_0-9]+/gi,KN="#pragma main";class XN extends WN{constructor(e){const{type:t,inputs:s,name:r,precision:n,inputsCode:i,blockCode:o,headerCode:a}=(e=>{const t=(e=e.trim()).indexOf(KN),s=-1!==t?e.slice(t+12):e,r=s.match(jN);if(null!==r&&5===r.length){const n=r[4],i=[];let o=null;for(;null!==(o=qN.exec(n));)i.push(o);const a=[];let u=0;for(;u0||e.backgroundBlurriness>0&&0===t.backgroundBlurriness;if(t.background!==s||r){let r=null;if(!0===s.isCubeTexture||s.mapping===j||s.mapping===q||s.mapping===Me)if(e.backgroundBlurriness>0||s.mapping===Me)r=Jp(s);else{let e;e=!0===s.isCubeTexture?_l(s):_u(s),r=Sh(e)}else!0===s.isTexture?r=_u(s,Ac.flipY()).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s);t.backgroundNode=r,t.background=s,t.backgroundBlurriness=e.backgroundBlurriness}}else t.backgroundNode&&(delete t.backgroundNode,delete t.background)}updateFog(e){const t=this.get(e),s=e.fog;if(s){if(t.fog!==s){let e=null;if(s.isFogExp2){const t=Ml("color","color",s).setGroup(Zn),r=Ml("density","float",s).setGroup(Zn);e=vx(t,r)}else if(s.isFog){const t=Ml("color","color",s).setGroup(Zn),r=Ml("near","float",s).setGroup(Zn),n=Ml("far","float",s).setGroup(Zn);e=_x(t,r,n)}else console.error("WebGPUNodes: Unsupported fog configuration.",s);t.fogNode=e,t.fog=s}}else delete t.fogNode,delete t.fog}updateEnvironment(e){const t=this.get(e),s=e.environment;if(s){if(t.environment!==s){let e=null;!0===s.isCubeTexture?e=_l(s):!0===s.isTexture?e=_u(s):console.error("Nodes: Unsupported environment configuration.",s),t.environmentNode=e,t.environment=s}}else t.environmentNode&&(delete t.environmentNode,delete t.environment)}getNodeFrame(e=this.renderer,t=null,s=null,r=null,n=null){const i=this.nodeFrame;return i.renderer=e,i.scene=t,i.object=s,i.camera=r,i.material=n,i}getNodeFrameForRender(e){return this.getNodeFrame(e.renderer,e.scene,e.object,e.camera,e.material)}getOutputCacheKey(){const e=this.renderer;return e.toneMapping+","+e.currentColorSpace}hasOutputChange(e){return QN.get(e)!==this.getOutputCacheKey()}getOutputNode(e){const t=this.renderer,s=this.getOutputCacheKey(),r=_u(e,Ac).renderOutput(t.toneMapping,t.currentColorSpace);return QN.set(e,s),r}updateBefore(e){const t=e.getNodeBuilderState();for(const s of t.updateBeforeNodes)this.getNodeFrameForRender(e).updateBeforeNode(s)}updateAfter(e){const t=e.getNodeBuilderState();for(const s of t.updateAfterNodes)this.getNodeFrameForRender(e).updateAfterNode(s)}updateForCompute(e){const t=this.getNodeFrame(),s=this.getForCompute(e);for(const e of s.updateNodes)t.updateNode(e)}updateForRender(e){const t=this.getNodeFrameForRender(e),s=e.getNodeBuilderState();for(const e of s.updateNodes)t.updateNode(e)}needsRefresh(e){const t=this.getNodeFrameForRender(e);return e.getMonitor().needsRefresh(e,t)}dispose(){super.dispose(),this.nodeFrame=new UN,this.nodeBuilderCache=new Map}}const JN=new me;class ev{constructor(e=null){this.version=0,this.clipIntersection=null,this.cacheKey="",null===e?(this.intersectionPlanes=[],this.unionPlanes=[],this.viewNormalMatrix=new n,this.clippingGroupContexts=new WeakMap,this.shadowPass=!1):(this.viewNormalMatrix=e.viewNormalMatrix,this.clippingGroupContexts=e.clippingGroupContexts,this.shadowPass=e.shadowPass,this.viewMatrix=e.viewMatrix),this.parentVersion=null}projectPlanes(e,t,s){const r=e.length;for(let n=0;n{await this.compileAsync(e,t);const r=this._renderLists.get(e,t),n=this._renderContexts.get(e,t,this._renderTarget),i=e.overrideMaterial||s.material,o=this._objects.get(s,i,e,t,r.lightsNode,n,n.clippingContext),{fragmentShader:a,vertexShader:u}=o.getNodeBuilderState();return{fragmentShader:a,vertexShader:u}}}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(e,t)=>{let s=this.backend;try{await s.init(this)}catch(e){if(null===this._getFallback)return void t(e);try{this.backend=s=this._getFallback(e),await s.init(this)}catch(e){return void t(e)}}this._nodes=new ZN(this,s),this._animation=new Bg(this._nodes,this.info),this._attributes=new $g(s),this._background=new I_(this,this._nodes),this._geometries=new jg(this._attributes,this.info),this._textures=new cm(this,s,this.info),this._pipelines=new Jg(s,this._nodes),this._bindings=new em(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Lg(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new im(this.lighting),this._bundles=new sv,this._renderContexts=new lm,this._animation.start(),this._initialized=!0,e()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(e,t,s=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const r=this._nodes.nodeFrame,n=r.renderId,i=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,u=!0===e.isScene?e:ov;null===s&&(s=e);const l=this._renderTarget,d=this._renderContexts.get(s,t,l),c=this._activeMipmapLevel,h=[];this._currentRenderContext=d,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=h,r.renderId++,r.update(),d.depth=this.depth,d.stencil=this.stencil,d.clippingContext||(d.clippingContext=new ev),d.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,l);const p=this._renderLists.get(e,t);if(p.begin(),this._projectObject(e,t,0,p,d.clippingContext),s!==e&&s.traverseVisible((function(e){e.isLight&&e.layers.test(t.layers)&&p.pushLight(e)})),p.finish(),null!==l){this._textures.updateRenderTarget(l,c);const e=this._textures.get(l);d.textures=e.textures,d.depthTexture=e.depthTexture}else d.textures=null,d.depthTexture=null;this._nodes.updateScene(u),this._background.update(u,p,d);const g=p.opaque,m=p.transparent,f=p.transparentDoublePass,y=p.lightsNode;!0===this.opaque&&g.length>0&&this._renderObjects(g,t,u,y),!0===this.transparent&&m.length>0&&this._renderTransparents(m,f,t,u,y),r.renderId=n,this._currentRenderContext=i,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(h)}async renderAsync(e,t){!1===this._initialized&&await this.init();const s=this._renderScene(e,t);await this.backend.resolveTimestampAsync(s,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(e){return this._mrt=e,this}getMRT(){return this._mrt}_onDeviceLost(e){let t=`THREE.WebGPURenderer: ${e.api} Device Lost:\n\nMessage: ${e.message}`;e.reason&&(t+=`\nReason: ${e.reason}`),console.error(t),this._isDeviceLost=!0}_renderBundle(e,t,s){const{bundleGroup:r,camera:n,renderList:i}=e,o=this._currentRenderContext,a=this._bundles.get(r,n),u=this.backend.get(a);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=r.version!==u.version,d=!1===u.renderContexts.has(o)||l;if(u.renderContexts.add(o),d){this.backend.beginBundle(o),(void 0===u.renderObjects||l)&&(u.renderObjects=[]),this._currentRenderBundle=a;const e=i.opaque;!0===this.opaque&&e.length>0&&this._renderObjects(e,n,t,s),this._currentRenderBundle=null,this.backend.finishBundle(o,a),u.version=r.version}else{const{renderObjects:e}=u;for(let t=0,s=e.length;t>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=b,p.viewportValue.maxDepth=x,p.viewport=!1===p.viewportValue.equals(uv),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(uv),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new ev),p.clippingContext.updateGlobal(u,t),u.onBeforeRender(this,e,t,h),dv.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),lv.setFromProjectionMatrix(dv,g);const T=this._renderLists.get(e,t);if(T.begin(),this._projectObject(e,t,0,T,p.clippingContext),T.finish(),!0===this.sortObjects&&T.sort(this._opaqueSort,this._transparentSort),null!==h){this._textures.updateRenderTarget(h,c);const e=this._textures.get(h);p.textures=e.textures,p.depthTexture=e.depthTexture,p.width=e.width,p.height=e.height,p.renderTarget=h,p.depth=h.depthBuffer,p.stencil=h.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=d,p.activeMipmapLevel=c,p.occlusionQueryCount=T.occlusionQueryCount,this._nodes.updateScene(u),this._background.update(u,T,p),this.backend.beginRender(p);const{bundles:_,lightsNode:N,transparentDoublePass:v,transparent:S,opaque:A}=T;if(_.length>0&&this._renderBundles(_,u,N),!0===this.opaque&&A.length>0&&this._renderObjects(A,t,u,N),!0===this.transparent&&S.length>0&&this._renderTransparents(S,v,t,u,N),this.backend.finishRender(p),n.renderId=i,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==r){this.setRenderTarget(l,d,c);const e=this._quad;this._nodes.hasOutputChange(h.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(h.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}return u.onAfterRender(this,e,t,h),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(e){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(e)}async getArrayBufferAsync(e){return await this.backend.getArrayBufferAsync(e)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(e){return e.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(e){return e.set(this._width,this._height)}setPixelRatio(e=1){this._pixelRatio!==e&&(this._pixelRatio=e,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(e,t,s){this._width=e,this._height=t,this._pixelRatio=s,this.domElement.width=Math.floor(e*s),this.domElement.height=Math.floor(t*s),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setSize(e,t,s=!0){this._width=e,this._height=t,this.domElement.width=Math.floor(e*this._pixelRatio),this.domElement.height=Math.floor(t*this._pixelRatio),!0===s&&(this.domElement.style.width=e+"px",this.domElement.style.height=t+"px"),this.setViewport(0,0,e,t),this._initialized&&this.backend.updateSize()}setOpaqueSort(e){this._opaqueSort=e}setTransparentSort(e){this._transparentSort=e}getScissor(e){const t=this._scissor;return e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height,e}setScissor(e,t,s,r){const n=this._scissor;e.isVector4?n.copy(e):n.set(e,t,s,r)}getScissorTest(){return this._scissorTest}setScissorTest(e){this._scissorTest=e,this.backend.setScissorTest(e)}getViewport(e){return e.copy(this._viewport)}setViewport(e,t,s,r,n=0,i=1){const o=this._viewport;e.isVector4?o.copy(e):o.set(e,t,s,r),o.minDepth=n,o.maxDepth=i}getClearColor(e){return e.copy(this._clearColor)}setClearColor(e,t=1){this._clearColor.set(e),this._clearColor.a=t}getClearAlpha(){return this._clearColor.a}setClearAlpha(e){this._clearColor.a=e}getClearDepth(){return this._clearDepth}setClearDepth(e){this._clearDepth=e}getClearStencil(){return this._clearStencil}setClearStencil(e){this._clearStencil=e}isOccluded(e){const t=this._currentRenderContext;return t&&this.backend.isOccluded(t,e)}clear(e=!0,t=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(e,t,s);const r=this._renderTarget||this._getFrameBufferTarget();let n=null;if(null!==r&&(this._textures.updateRenderTarget(r),n=this._textures.get(r)),this.backend.clear(e,t,s,n),null!==r&&null===this._renderTarget){const e=this._quad;this._nodes.hasOutputChange(r.texture)&&(e.material.fragmentNode=this._nodes.getOutputNode(r.texture),e.material.needsUpdate=!0),this._renderScene(e,e.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(e=!0,t=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(e,t,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?d:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?Se:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(e,t=0,s=0){this._renderTarget=e,this._activeCubeFace=t,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(e){this._renderObjectFunction=e}getRenderObjectFunction(){return this._renderObjectFunction}compute(e){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(e);const t=this._nodes.nodeFrame,s=t.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,t.renderId=this.info.calls;const r=this.backend,n=this._pipelines,i=this._bindings,o=this._nodes,a=Array.isArray(e)?e:[e];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");r.beginCompute(e);for(const t of a){if(!1===n.has(t)){const e=()=>{t.removeEventListener("dispose",e),n.delete(t),i.delete(t),o.delete(t)};t.addEventListener("dispose",e);const s=t.onInitFunction;null!==s&&s.call(t,{renderer:this})}o.updateForCompute(t),i.updateForCompute(t);const s=i.getForCompute(t),a=n.getForCompute(t,s);r.compute(e,t,s,a)}r.finishCompute(e),t.renderId=s}async computeAsync(e){!1===this._initialized&&await this.init(),this.compute(e),await this.backend.resolveTimestampAsync(e,"compute")}async hasFeatureAsync(e){return!1===this._initialized&&await this.init(),this.backend.hasFeature(e)}hasFeature(e){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(e)}copyFramebufferToTexture(e,t=null){if(null!==t)if(t.isVector2)t=cv.set(t.x,t.y,e.image.width,e.image.height).floor();else{if(!t.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");t=cv.copy(t).floor()}else t=cv.set(0,0,e.image.width,e.image.height);let s,r=this._currentRenderContext;null!==r?s=r.renderTarget:(s=this._renderTarget||this._getFrameBufferTarget(),null!==s&&(this._textures.updateRenderTarget(s),r=this._textures.get(s))),this._textures.updateTexture(e,{renderTarget:s}),this.backend.copyFramebufferToTexture(e,r,t)}copyTextureToTexture(e,t,s=null,r=null,n=0){this._textures.updateTexture(e),this._textures.updateTexture(t),this.backend.copyTextureToTexture(e,t,s,r,n)}readRenderTargetPixelsAsync(e,t,s,r,n,i=0,o=0){return this.backend.copyTextureToBuffer(e.textures[i],t,s,r,n,o)}_projectObject(e,t,s,r,n){if(!1===e.visible)return;if(e.layers.test(t.layers))if(e.isGroup)s=e.renderOrder,e.isClippingGroup&&e.enabled&&(n=n.getGroupContext(e));else if(e.isLOD)!0===e.autoUpdate&&e.update(t);else if(e.isLight)r.pushLight(e);else if(e.isSprite){if(!e.frustumCulled||lv.intersectsSprite(e)){!0===this.sortObjects&&cv.setFromMatrixPosition(e.matrixWorld).applyMatrix4(dv);const{geometry:t,material:i}=e;i.visible&&r.push(e,t,i,s,cv.z,null,n)}}else if(e.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||lv.intersectsObject(e))){const{geometry:t,material:i}=e;if(!0===this.sortObjects&&(null===t.boundingSphere&&t.computeBoundingSphere(),cv.copy(t.boundingSphere.center).applyMatrix4(e.matrixWorld).applyMatrix4(dv)),Array.isArray(i)){const o=t.groups;for(let a=0,u=o.length;a0){for(const{material:e}of t)e.side=x;this._renderObjects(t,s,r,n,"backSide");for(const{material:e}of t)e.side=Oe;this._renderObjects(e,s,r,n);for(const{material:e}of t)e.side=le}else this._renderObjects(e,s,r,n)}_renderObjects(e,t,s,r,n=null){for(let i=0,o=e.length;i0?r:"";t=`${e.name} {\n\t${s} ${n.name}[${i}];\n};\n`}else{t=`${this.getVectorType(n.type)} ${this.getPropertyName(n,e)};`,i=!0}const o=n.node.precision;if(null!==o&&(t=Cv[o]+" "+t),i){t="\t"+t;const e=n.groupNode.name;(r[e]||(r[e]=[])).push(t)}else t="uniform "+t,s.push(t)}let n="";for(const t in r){const s=r[t];n+=this._getGLSLUniformStruct(e+"_"+t,s.join("\n"))+"\n"}return n+=s.join("\n"),n}getTypeFromAttribute(e){let t=super.getTypeFromAttribute(e);if(/^[iu]/.test(t)&&e.gpuType!==y){let s=e;e.isInterleavedBufferAttribute&&(s=e.data);const r=s.array;!1==(r instanceof Uint32Array||r instanceof Int32Array)&&(t=t.slice(1))}return t}getAttributes(e){let t="";if("vertex"===e||"compute"===e){const e=this.getAttributesArray();let s=0;for(const r of e)t+=`layout( location = ${s++} ) in ${r.type} ${r.name};\n`}return t}getStructMembers(e){const t=[],s=e.getMemberTypes();for(let e=0;ee*t),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(e,t,s=this.shaderStage){const r=this.extensions[s]||(this.extensions[s]=new Map);!1===r.has(e)&&r.set(e,{name:e,behavior:t})}getExtensions(e){const t=[];if("vertex"===e){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",e)}const s=this.extensions[e];if(void 0!==s)for(const{name:e,behavior:r}of s.values())t.push(`#extension ${e} : ${r}`);return t.join("\n")}getClipDistance(){return"gl_ClipDistance"}isAvailable(e){let t=Ev[e];if(void 0===t){let s;switch(t=!1,e){case"float32Filterable":s="OES_texture_float_linear";break;case"clipDistance":s="WEBGL_clip_cull_distance"}if(void 0!==s){const e=this.renderer.backend.extensions;e.has(s)&&(e.get(s),t=!0)}Ev[e]=t}return t}isFlipY(){return!0}enableHardwareClipping(e){this.enableExtension("GL_ANGLE_clip_cull_distance","require"),this.builtins.vertex.push(`out float gl_ClipDistance[ ${e} ]`)}registerTransform(e,t){this.transforms.push({varyingName:e,attributeNode:t})}getTransforms(){const e=this.transforms;let t="";for(let s=0;s0&&(s+="\n"),s+=`\t// flow -> ${i}\n\t`),s+=`${r.code}\n\t`,e===n&&"compute"!==t&&(s+="// result\n\t","vertex"===t?(s+="gl_Position = ",s+=`${r.result};`):"fragment"===t&&(e.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${r.result};`)))}const i=e[t];i.extensions=this.getExtensions(t),i.uniforms=this.getUniforms(t),i.attributes=this.getAttributes(t),i.varyings=this.getVaryings(t),i.vars=this.getVars(t),i.structs=this.getStructs(t),i.codes=this.getCodes(t),i.transforms=this.getTransforms(t),i.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(e.vertex),this.fragmentShader=this._getGLSLFragmentCode(e.fragment)):this.computeShader=this._getGLSLVertexCode(e.compute)}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);let o=i.uniformGPU;if(void 0===o){const r=e.groupNode,a=r.name,u=this.getBindGroupArray(a,s);if("texture"===t)o=new vv(n.name,n.node,r),u.push(o);else if("cubeTexture"===t)o=new Sv(n.name,n.node,r),u.push(o);else if("texture3D"===t)o=new Av(n.name,n.node,r),u.push(o);else if("buffer"===t){e.name=`NodeBuffer_${e.id}`,n.name=`buffer${e.id}`;const t=new yv(e,r);t.name=e.name,u.push(t),o=t}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Tv(s+"_"+a,r),e[a]=i,u.push(i)),o=this.getNodeUniform(n,t),i.addUniform(o)}i.uniformGPU=o}return n}}let Bv=null,Uv=null,Fv=null;class Pv{constructor(e={}){this.parameters=Object.assign({},e),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(e){this.renderer=e}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(e){const{object:t,geometry:s}=e;return s.isInstancedBufferGeometry?s.instanceCount:t.count>1?t.count:1}getDrawingBufferSize(){return Bv=Bv||new t,this.renderer.getDrawingBufferSize(Bv)}getScissor(){return Uv=Uv||new r,this.renderer.getScissor(Uv)}setScissorTest(){}getClearColor(){const e=this.renderer;return Fv=Fv||new hm,e.getClearColor(Fv),Fv.getRGB(Fv,this.renderer.currentColorSpace),Fv}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:Qe(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${Le} webgpu`),this.domElement=e),e}set(e,t){this.data.set(e,t)}get(e){let t=this.data.get(e);return void 0===t&&(t={},this.data.set(e,t)),t}has(e){return this.data.has(e)}delete(e){this.data.delete(e)}dispose(){}}let Iv=0;class Lv{constructor(e,t){this.buffers=[e.bufferGPU,t],this.type=e.type,this.bufferType=e.bufferType,this.pbo=e.pbo,this.byteLength=e.byteLength,this.bytesPerElement=e.BYTES_PER_ELEMENT,this.version=e.version,this.isInteger=e.isInteger,this.activeBufferIndex=0,this.baseId=e.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class Dv{constructor(e){this.backend=e}createAttribute(e,t){const s=this.backend,{gl:r}=s,n=e.array,i=e.usage||r.STATIC_DRAW,o=e.isInterleavedBufferAttribute?e.data:e,a=s.get(o);let u,l=a.bufferGPU;if(void 0===l&&(l=this._createBuffer(r,t,n,i),a.bufferGPU=l,a.bufferType=t,a.version=o.version),n instanceof Float32Array)u=r.FLOAT;else if(n instanceof Uint16Array)u=e.isFloat16BufferAttribute?r.HALF_FLOAT:r.UNSIGNED_SHORT;else if(n instanceof Int16Array)u=r.SHORT;else if(n instanceof Uint32Array)u=r.UNSIGNED_INT;else if(n instanceof Int32Array)u=r.INT;else if(n instanceof Int8Array)u=r.BYTE;else if(n instanceof Uint8Array)u=r.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+n);u=r.UNSIGNED_BYTE}let d={bufferGPU:l,bufferType:t,type:u,byteLength:n.byteLength,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version,pbo:e.pbo,isInteger:u===r.INT||u===r.UNSIGNED_INT||e.gpuType===y,id:Iv++};if(e.isStorageBufferAttribute||e.isStorageInstancedBufferAttribute){const e=this._createBuffer(r,t,n,i);d=new Lv(d,e)}s.set(e,d)}updateAttribute(e){const t=this.backend,{gl:s}=t,r=e.array,n=e.isInterleavedBufferAttribute?e.data:e,i=t.get(n),o=i.bufferType,a=e.isInterleavedBufferAttribute?e.data.updateRanges:e.updateRanges;if(s.bindBuffer(o,i.bufferGPU),0===a.length)s.bufferSubData(o,0,r);else{for(let e=0,t=a.length;e1?this.enable(r.SAMPLE_ALPHA_TO_COVERAGE):this.disable(r.SAMPLE_ALPHA_TO_COVERAGE),s>0&&this.currentClippingPlanes!==s){const e=12288;for(let t=0;t<8;t++)t{!function n(){const i=e.clientWaitSync(t,e.SYNC_FLUSH_COMMANDS_BIT,0);if(i===e.WAIT_FAILED)return e.deleteSync(t),void r();i!==e.TIMEOUT_EXPIRED?(e.deleteSync(t),s()):requestAnimationFrame(n)}()}))}}let $v,Hv,Wv,jv=!1;class qv{constructor(e){this.backend=e,this.gl=e.gl,this.extensions=e.extensions,this.defaultTextures={},!1===jv&&(this._init(this.gl),jv=!0)}_init(e){$v={[ls]:e.REPEAT,[ds]:e.CLAMP_TO_EDGE,[cs]:e.MIRRORED_REPEAT},Hv={[hs]:e.NEAREST,[ps]:e.NEAREST_MIPMAP_NEAREST,[Pe]:e.NEAREST_MIPMAP_LINEAR,[$]:e.LINEAR,[Fe]:e.LINEAR_MIPMAP_NEAREST,[M]:e.LINEAR_MIPMAP_LINEAR},Wv={[gs]:e.NEVER,[ms]:e.ALWAYS,[Ae]:e.LESS,[fs]:e.LEQUAL,[ys]:e.EQUAL,[bs]:e.GEQUAL,[xs]:e.GREATER,[Ts]:e.NOTEQUAL}}filterFallback(e){const{gl:t}=this;return e===hs||e===ps||e===Pe?t.NEAREST:t.LINEAR}getGLTextureType(e){const{gl:t}=this;let s;return s=!0===e.isCubeTexture?t.TEXTURE_CUBE_MAP:!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:!0===e.isData3DTexture?t.TEXTURE_3D:t.TEXTURE_2D,s}getInternalFormat(e,t,s,r,n=!1){const{gl:i,extensions:o}=this;if(null!==e){if(void 0!==i[e])return i[e];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+e+"'")}let a=t;return t===i.RED&&(s===i.FLOAT&&(a=i.R32F),s===i.HALF_FLOAT&&(a=i.R16F),s===i.UNSIGNED_BYTE&&(a=i.R8),s===i.UNSIGNED_SHORT&&(a=i.R16),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RED_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.R8UI),s===i.UNSIGNED_SHORT&&(a=i.R16UI),s===i.UNSIGNED_INT&&(a=i.R32UI),s===i.BYTE&&(a=i.R8I),s===i.SHORT&&(a=i.R16I),s===i.INT&&(a=i.R32I)),t===i.RG&&(s===i.FLOAT&&(a=i.RG32F),s===i.HALF_FLOAT&&(a=i.RG16F),s===i.UNSIGNED_BYTE&&(a=i.RG8),s===i.UNSIGNED_SHORT&&(a=i.RG16),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RG_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RG8UI),s===i.UNSIGNED_SHORT&&(a=i.RG16UI),s===i.UNSIGNED_INT&&(a=i.RG32UI),s===i.BYTE&&(a=i.RG8I),s===i.SHORT&&(a=i.RG16I),s===i.INT&&(a=i.RG32I)),t===i.RGB&&(s===i.FLOAT&&(a=i.RGB32F),s===i.HALF_FLOAT&&(a=i.RGB16F),s===i.UNSIGNED_BYTE&&(a=i.RGB8),s===i.UNSIGNED_SHORT&&(a=i.RGB16),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8:i.RGB8),s===i.UNSIGNED_SHORT_5_6_5&&(a=i.RGB565),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGB4),s===i.UNSIGNED_INT_5_9_9_9_REV&&(a=i.RGB9_E5)),t===i.RGB_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGB8UI),s===i.UNSIGNED_SHORT&&(a=i.RGB16UI),s===i.UNSIGNED_INT&&(a=i.RGB32UI),s===i.BYTE&&(a=i.RGB8I),s===i.SHORT&&(a=i.RGB16I),s===i.INT&&(a=i.RGB32I)),t===i.RGBA&&(s===i.FLOAT&&(a=i.RGBA32F),s===i.HALF_FLOAT&&(a=i.RGBA16F),s===i.UNSIGNED_BYTE&&(a=i.RGBA8),s===i.UNSIGNED_SHORT&&(a=i.RGBA16),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I),s===i.UNSIGNED_BYTE&&(a=r===De&&!1===n?i.SRGB8_ALPHA8:i.RGBA8),s===i.UNSIGNED_SHORT_4_4_4_4&&(a=i.RGBA4),s===i.UNSIGNED_SHORT_5_5_5_1&&(a=i.RGB5_A1)),t===i.RGBA_INTEGER&&(s===i.UNSIGNED_BYTE&&(a=i.RGBA8UI),s===i.UNSIGNED_SHORT&&(a=i.RGBA16UI),s===i.UNSIGNED_INT&&(a=i.RGBA32UI),s===i.BYTE&&(a=i.RGBA8I),s===i.SHORT&&(a=i.RGBA16I),s===i.INT&&(a=i.RGBA32I)),t===i.DEPTH_COMPONENT&&(s===i.UNSIGNED_INT&&(a=i.DEPTH24_STENCIL8),s===i.FLOAT&&(a=i.DEPTH_COMPONENT32F)),t===i.DEPTH_STENCIL&&s===i.UNSIGNED_INT_24_8&&(a=i.DEPTH24_STENCIL8),a!==i.R16F&&a!==i.R32F&&a!==i.RG16F&&a!==i.RG32F&&a!==i.RGBA16F&&a!==i.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(e,t){const{gl:s,extensions:r,backend:n}=this;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),s.texParameteri(e,s.TEXTURE_WRAP_S,$v[t.wrapS]),s.texParameteri(e,s.TEXTURE_WRAP_T,$v[t.wrapT]),e!==s.TEXTURE_3D&&e!==s.TEXTURE_2D_ARRAY||s.texParameteri(e,s.TEXTURE_WRAP_R,$v[t.wrapR]),s.texParameteri(e,s.TEXTURE_MAG_FILTER,Hv[t.magFilter]);const i=void 0!==t.mipmaps&&t.mipmaps.length>0,o=t.minFilter===$&&i?M:t.minFilter;if(s.texParameteri(e,s.TEXTURE_MIN_FILTER,Hv[o]),t.compareFunction&&(s.texParameteri(e,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(e,s.TEXTURE_COMPARE_FUNC,Wv[t.compareFunction])),!0===r.has("EXT_texture_filter_anisotropic")){if(t.magFilter===hs)return;if(t.minFilter!==Pe&&t.minFilter!==M)return;if(t.type===E&&!1===r.has("OES_texture_float_linear"))return;if(t.anisotropy>1){const i=r.get("EXT_texture_filter_anisotropic");s.texParameterf(e,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(t.anisotropy,n.getMaxAnisotropy()))}}}createDefaultTexture(e){const{gl:t,backend:s,defaultTextures:r}=this,n=this.getGLTextureType(e);let i=r[n];void 0===i&&(i=t.createTexture(),s.state.bindTexture(n,i),t.texParameteri(n,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(n,t.TEXTURE_MAG_FILTER,t.NEAREST),r[n]=i),s.set(e,{textureGPU:i,glTextureType:n,isDefault:!0})}createTexture(e,t){const{gl:s,backend:r}=this,{levels:n,width:i,height:o,depth:a}=t,u=r.utils.convert(e.format,e.colorSpace),l=r.utils.convert(e.type),d=this.getInternalFormat(e.internalFormat,u,l,e.colorSpace,e.isVideoTexture),c=s.createTexture(),h=this.getGLTextureType(e);r.state.bindTexture(h,c),this.setTextureParameters(h,e),e.isDataArrayTexture||e.isCompressedArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,n,d,i,o,a):e.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,n,d,i,o,a):e.isVideoTexture||s.texStorage2D(h,n,d,i,o),r.set(e,{textureGPU:c,glTextureType:h,glFormat:u,glType:l,glInternalFormat:d})}copyBufferToTexture(e,t){const{gl:s,backend:r}=this,{textureGPU:n,glTextureType:i,glFormat:o,glType:a}=r.get(t),{width:u,height:l}=t.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,e),r.state.bindTexture(i,n),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(i,0,0,0,u,l,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),r.state.unbindTexture()}updateTexture(e,t){const{gl:s}=this,{width:r,height:n}=t,{textureGPU:i,glTextureType:o,glFormat:a,glType:u,glInternalFormat:l}=this.backend.get(e);if(e.isRenderTargetTexture||void 0===i)return;const d=e=>e.isDataTexture?e.image.data:"undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap||e instanceof OffscreenCanvas?e:e.data;if(this.backend.state.bindTexture(o,i),this.setTextureParameters(o,e),e.isCompressedTexture){const r=e.mipmaps,n=t.image;for(let t=0;t0,c=t.renderTarget?t.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(d){const s=0!==o||0!==a;let d,h;if(!0===e.isDepthTexture?(d=r.DEPTH_BUFFER_BIT,h=r.DEPTH_ATTACHMENT,t.stencil&&(d|=r.STENCIL_BUFFER_BIT)):(d=r.COLOR_BUFFER_BIT,h=r.COLOR_ATTACHMENT0),s){const e=this.backend.get(t.renderTarget),s=e.framebuffers[t.getCacheKey()],h=e.msaaFrameBuffer;n.bindFramebuffer(r.DRAW_FRAMEBUFFER,s),n.bindFramebuffer(r.READ_FRAMEBUFFER,h);const p=c-a-l;r.blitFramebuffer(o,p,o+u,p+l,o,p,o+u,p+l,d,r.NEAREST),n.bindFramebuffer(r.READ_FRAMEBUFFER,s),n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,p,u,l),n.unbindTexture()}else{const e=r.createFramebuffer();n.bindFramebuffer(r.DRAW_FRAMEBUFFER,e),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,h,r.TEXTURE_2D,i,0),r.blitFramebuffer(0,0,u,l,0,0,u,l,d,r.NEAREST),r.deleteFramebuffer(e)}}else n.bindTexture(r.TEXTURE_2D,i),r.copyTexSubImage2D(r.TEXTURE_2D,0,0,0,o,c-l-a,u,l),n.unbindTexture();e.generateMipmaps&&this.generateMipmaps(e),this.backend._setFramebuffer(t)}setupRenderBufferStorage(e,t){const{gl:s}=this,r=t.renderTarget,{samples:n,depthTexture:i,depthBuffer:o,stencilBuffer:a,width:u,height:l}=r;if(s.bindRenderbuffer(s.RENDERBUFFER,e),o&&!a){let t=s.DEPTH_COMPONENT24;n>0?(i&&i.isDepthTexture&&i.type===s.FLOAT&&(t=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,n,t,u,l)):s.renderbufferStorage(s.RENDERBUFFER,t,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,e)}else o&&a&&(n>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,n,s.DEPTH24_STENCIL8,u,l):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,u,l),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,e))}async copyTextureToBuffer(e,t,s,r,n,i){const{backend:o,gl:a}=this,{textureGPU:u,glFormat:l,glType:d}=this.backend.get(e),c=a.createFramebuffer();a.bindFramebuffer(a.READ_FRAMEBUFFER,c);const h=e.isCubeTexture?a.TEXTURE_CUBE_MAP_POSITIVE_X+i:a.TEXTURE_2D;a.framebufferTexture2D(a.READ_FRAMEBUFFER,a.COLOR_ATTACHMENT0,h,u,0);const p=this._getTypedArrayType(d),g=r*n*this._getBytesPerTexel(d,l),m=a.createBuffer();a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.bufferData(a.PIXEL_PACK_BUFFER,g,a.STREAM_READ),a.readPixels(t,s,r,n,l,d,0),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),await o.utils._clientWaitAsync();const f=new p(g/p.BYTES_PER_ELEMENT);return a.bindBuffer(a.PIXEL_PACK_BUFFER,m),a.getBufferSubData(a.PIXEL_PACK_BUFFER,0,f),a.bindBuffer(a.PIXEL_PACK_BUFFER,null),a.deleteFramebuffer(c),f}_getTypedArrayType(e){const{gl:t}=this;if(e===t.UNSIGNED_BYTE)return Uint8Array;if(e===t.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(e===t.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(e===t.UNSIGNED_SHORT)return Uint16Array;if(e===t.UNSIGNED_INT)return Uint32Array;if(e===t.HALF_FLOAT)return Uint16Array;if(e===t.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${e}`)}_getBytesPerTexel(e,t){const{gl:s}=this;let r=0;return e===s.UNSIGNED_BYTE&&(r=1),e!==s.UNSIGNED_SHORT_4_4_4_4&&e!==s.UNSIGNED_SHORT_5_5_5_1&&e!==s.UNSIGNED_SHORT_5_6_5&&e!==s.UNSIGNED_SHORT&&e!==s.HALF_FLOAT||(r=2),e!==s.UNSIGNED_INT&&e!==s.FLOAT||(r=4),t===s.RGBA?4*r:t===s.RGB?3*r:t===s.ALPHA?r:void 0}}class Kv{constructor(e){this.backend=e,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(e){let t=this.extensions[e];return void 0===t&&(t=this.gl.getExtension(e),this.extensions[e]=t),t}has(e){return this.availableExtensions.includes(e)}}class Xv{constructor(e){this.backend=e,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const e=this.backend.gl,t=this.backend.extensions;if(!0===t.has("EXT_texture_filter_anisotropic")){const s=t.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const Yv={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class Qv{constructor(e){this.gl=e.gl,this.extensions=e.extensions,this.info=e.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(e,t){const{gl:s,mode:r,object:n,type:i,info:o,index:a}=this;0!==a?s.drawElements(r,t,i,e):s.drawArrays(r,e,t),o.update(n,t,r,1)}renderInstances(e,t,s){const{gl:r,mode:n,type:i,index:o,object:a,info:u}=this;0!==s&&(0!==o?r.drawElementsInstanced(n,t,i,e,s):r.drawArraysInstanced(n,e,t,s),u.update(a,t,n,s))}renderMultiDraw(e,t,s){const{extensions:r,mode:n,object:i,info:o}=this;if(0===s)return;const a=r.get("WEBGL_multi_draw");if(null===a)for(let r=0;r0)){const e=t.queryQueue.shift();this.initTimestampQuery(e)}}async resolveTimestampAsync(e,t="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(e);s.gpuQueries||(s.gpuQueries=[]);for(let e=0;e0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(r),s.occlusionQueryObjects=new Array(r),s.occlusionQueryIndex=0)}finishRender(e){const{gl:t,state:s}=this,r=this.get(e),n=r.previousContext,i=e.occlusionQueryCount;i>0&&(i>r.occlusionQueryIndex&&t.endQuery(t.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(e));const o=e.textures;if(null!==o)for(let e=0;e0){const n=r.framebuffers[e.getCacheKey()],i=t.COLOR_BUFFER_BIT,o=r.msaaFrameBuffer,a=e.textures;s.bindFramebuffer(t.READ_FRAMEBUFFER,o),s.bindFramebuffer(t.DRAW_FRAMEBUFFER,n);for(let s=0;s{let o=0;for(let t=0;t0&&e.add(r[t]),s[t]=null,n.deleteQuery(i),o++))}o1?f.renderInstances(x,y,b):f.render(x,y),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}createSampler(){}destroySampler(){}createNodeBuilder(e,t){return new Mv(e,t)}createProgram(e){const t=this.gl,{stage:s,code:r}=e,n="fragment"===s?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER);t.shaderSource(n,r),t.compileShader(n),this.set(e,{shaderGPU:n})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(e,t){const s=this.gl,r=e.pipeline,{fragmentProgram:n,vertexProgram:i}=r,o=s.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,u),s.linkProgram(o),this.set(r,{programGPU:o,fragmentShader:a,vertexShader:u}),null!==t&&this.parallel){const n=new Promise((t=>{const n=this.parallel,i=()=>{s.getProgramParameter(o,n.COMPLETION_STATUS_KHR)?(this._completeCompile(e,r),t()):requestAnimationFrame(i)};i()}));t.push(n)}else this._completeCompile(e,r)}_handleSource(e,t){const s=e.split("\n"),r=[],n=Math.max(t-6,0),i=Math.min(t+6,s.length);for(let e=n;e":" "} ${n}: ${s[e]}`)}return r.join("\n")}_getShaderErrors(e,t,s){const r=e.getShaderParameter(t,e.COMPILE_STATUS),n=e.getShaderInfoLog(t).trim();if(r&&""===n)return"";const i=/ERROR: 0:(\d+)/.exec(n);if(i){const r=parseInt(i[1]);return s.toUpperCase()+"\n\n"+n+"\n\n"+this._handleSource(e.getShaderSource(t),r)}return n}_logProgramError(e,t,s){if(this.renderer.debug.checkShaderErrors){const r=this.gl,n=r.getProgramInfoLog(e).trim();if(!1===r.getProgramParameter(e,r.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(r,e,s,t);else{const i=this._getShaderErrors(r,s,"vertex"),o=this._getShaderErrors(r,t,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(e,r.VALIDATE_STATUS)+"\n\nProgram Info Log: "+n+"\n"+i+"\n"+o)}else""!==n&&console.warn("THREE.WebGLProgram: Program Info Log:",n)}}_completeCompile(e,t){const{state:s,gl:r}=this,n=this.get(t),{programGPU:i,fragmentShader:o,vertexShader:a}=n;!1===r.getProgramParameter(i,r.LINK_STATUS)&&this._logProgramError(i,o,a),s.useProgram(i);const u=e.getBindings();this._setupBindings(u,i),this.set(t,{programGPU:i})}createComputePipeline(e,t){const{state:s,gl:r}=this,n={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(n);const{computeProgram:i}=e,o=r.createProgram(),a=this.get(n).shaderGPU,u=this.get(i).shaderGPU,l=i.transforms,d=[],c=[];for(let e=0;eYv[t]===e)),s=this.extensions;for(let e=0;e0){if(void 0===d){const r=[];d=t.createFramebuffer(),s.bindFramebuffer(t.FRAMEBUFFER,d);const n=[],l=e.textures;for(let s=0;s,\n\t@location( 0 ) vTex : vec2\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2, 4 >(\n\t\tvec2( -1.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 ),\n\t\tvec2( -1.0, -1.0 ),\n\t\tvec2( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2, 4 >(\n\t\tvec2( 0.0, 0.0 ),\n\t\tvec2( 1.0, 0.0 ),\n\t\tvec2( 0.0, 1.0 ),\n\t\tvec2( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=e.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=e.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2 ) -> @location( 0 ) vec4 {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(e){let t=this.transferPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`mipmap-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Hf,stripIndexFormat:ay},layout:"auto"}),this.transferPipelines[e]=t),t}getFlipYPipeline(e){let t=this.flipYPipelines[e];return void 0===t&&(t=this.device.createRenderPipeline({label:`flipY-${e}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:e}]},primitive:{topology:Hf,stripIndexFormat:ay},layout:"auto"}),this.flipYPipelines[e]=t),t}flipY(e,t,s=0){const r=t.format,{width:n,height:i}=t.size,o=this.getTransferPipeline(r),a=this.getFlipYPipeline(r),u=this.device.createTexture({size:{width:n,height:i,depthOrArrayLayers:1},format:r,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),l=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:s}),d=u.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),h=(e,t,s)=>{const r=e.getBindGroupLayout(0),n=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:t}]}),i=c.beginRenderPass({colorAttachments:[{view:s,loadOp:ty,storeOp:Jf,clearValue:[0,0,0,0]}]});i.setPipeline(e),i.setBindGroup(0,n),i.draw(4,1,0,0),i.end()};h(o,l,d),h(a,d,l),this.device.queue.submit([c.finish()]),u.destroy()}generateMipmaps(e,t,s=0){const r=this.get(e);void 0===r.useCount&&(r.useCount=0,r.layers=[]);const n=r.layers[s]||this._mipmapCreateBundles(e,t,s),i=this.device.createCommandEncoder({});this._mipmapRunBundles(i,n),this.device.queue.submit([i.finish()]),0!==r.useCount&&(r.layers[s]=n),r.useCount++}_mipmapCreateBundles(e,t,s){const r=this.getTransferPipeline(t.format),n=r.getBindGroupLayout(0);let i=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:Jy,baseArrayLayer:s});const o=[];for(let a=1;a1&&!e.isMultisampleRenderTargetTexture){const e=Object.assign({},p);e.label=e.label+"-msaa",e.sampleCount=d,r.msaaTexture=s.device.createTexture(e)}r.initialized=!0,r.textureDescriptorGPU=p}destroyTexture(e){const t=this.backend,s=t.get(e);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),t.delete(e)}destroySampler(e){delete this.backend.get(e).sampler}generateMipmaps(e){const t=this.backend.get(e);if(e.isCubeTexture)for(let e=0;e<6;e++)this._generateMipmaps(t.texture,t.textureDescriptorGPU,e);else{const s=e.image.depth||1;for(let e=0;e1;for(let o=0;o]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,dS=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,cS={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2":"vec2","vec2":"ivec2","vec2":"uvec2","vec2":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3":"vec3","vec3":"ivec3","vec3":"uvec3","vec3":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4":"vec4","vec4":"ivec4","vec4":"uvec4","vec4":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2":"mat2",mat2x2f:"mat2","mat3x3":"mat3",mat3x3f:"mat3","mat4x4":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class hS extends WN{constructor(e){const{type:t,inputs:s,name:r,inputsCode:n,blockCode:i,outputType:o}=(e=>{const t=(e=e.trim()).match(lS);if(null!==t&&4===t.length){const s=t[2],r=[];let n=null;for(;null!==(n=dS.exec(s));)r.push({name:n[1],type:n[2]});const i=[];for(let e=0;e "+this.outputType:"";return`fn ${e} ( ${this.inputsCode.trim()} ) ${t}`+this.blockCode}}class pS extends HN{parseFunction(e){return new hS(e)}}const gS=self.GPUShaderStage,mS={[ls]:"repeat",[ds]:"clamp",[cs]:"mirror"},fS={vertex:gS?gS.VERTEX:1,fragment:gS?gS.FRAGMENT:2,compute:gS?gS.COMPUTE:4},yS={instance:!0,swizzleAssign:!1,storageBuffer:!0},bS={"^^":"tsl_xor"},xS={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3",vec2:"vec2",ivec2:"vec2",uvec2:"vec2",bvec2:"vec2",vec3:"vec3",ivec3:"vec3",uvec3:"vec3",bvec3:"vec3",vec4:"vec4",ivec4:"vec4",uvec4:"vec4",bvec4:"vec4",mat2:"mat2x2",mat3:"mat3x3",mat4:"mat4x4"},TS={},_S={tsl_xor:new sx("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new sx("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new sx("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new sx("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new sx("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new sx("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new sx("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2 { return vec2( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new sx("fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3 { return vec3( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new sx("fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4 { return vec4( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping_float:new sx("fn tsl_repeatWrapping_float( coord: f32 ) -> f32 { return fract( coord ); }"),mirrorWrapping_float:new sx("fn tsl_mirrorWrapping_float( coord: f32 ) -> f32 { let mirrored = fract( coord * 0.5 ) * 2.0; return 1.0 - abs( 1.0 - mirrored ); }"),clampWrapping_float:new sx("fn tsl_clampWrapping_float( coord: f32 ) -> f32 { return clamp( coord, 0.0, 1.0 ); }"),repeatWrapping:new sx("\nfn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 {\n\n\tlet uvScaled = vec2( uv * vec2( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new sx("\nfn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, iRes : vec2u, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( iRes );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2u( iuv + vec2( 0.5, 0.5 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2u( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2u( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2u( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},NS={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast"};/Windows/g.test(navigator.userAgent)&&(_S.pow_float=new sx("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),_S.pow_vec2=new sx("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[_S.pow_float]),_S.pow_vec3=new sx("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[_S.pow_float]),_S.pow_vec4=new sx("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[_S.pow_float]),NS.pow_float="tsl_pow_float",NS.pow_vec2="tsl_pow_vec2",NS.pow_vec3="tsl_pow_vec3",NS.pow_vec4="tsl_pow_vec4");let vS="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(vS+="diagnostic( off, derivative_uniformity );\n");class SS extends BN{constructor(e,t){super(e,t,new pS),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(e){return!0===e.isVideoTexture&&e.colorSpace!==m}_generateTextureSample(e,t,s,r,n=this.shaderStage){return"fragment"===n?r?`textureSample( ${t}, ${t}_sampler, ${s}, ${r} )`:`textureSample( ${t}, ${t}_sampler, ${s} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s):this.generateTextureLod(e,t,s,"0")}_generateVideoSample(e,t,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${e}, ${e}_sampler, vec2( ${t}.x, 1.0 - ${t}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(e,t,s,r,n,i=this.shaderStage){return"fragment"===i&&!1===this.isUnfilterable(e)?`textureSampleLevel( ${t}, ${t}_sampler, ${s}, ${r} )`:this.isFilteredTexture(e)?this.generateFilteredTexture(e,t,s,r):this.generateTextureLod(e,t,s,r)}generateWrapFunction(e){const t=`tsl_coord_${mS[e.wrapS]}S_${mS[e.wrapT]}T`;let s=TS[t];if(void 0===s){const r=[];let n=`fn ${t}( coord : vec2f ) -> vec2f {\n\n\treturn vec2f(\n`;const i=(e,t)=>{e===ls?(r.push(_S.repeatWrapping_float),n+=`\t\ttsl_repeatWrapping_float( coord.${t} )`):e===ds?(r.push(_S.clampWrapping_float),n+=`\t\ttsl_clampWrapping_float( coord.${t} )`):e===cs?(r.push(_S.mirrorWrapping_float),n+=`\t\ttsl_mirrorWrapping_float( coord.${t} )`):(n+=`\t\tcoord.${t}`,console.warn(`WebGPURenderer: Unsupported texture wrap type "${e}" for vertex shader.`))};i(e.wrapS,"x"),n+=",\n",i(e.wrapT,"y"),n+="\n\t);\n\n}\n",TS[t]=s=new sx(n,r)}return s.build(this),t}generateTextureDimension(e,t,s){const r=this.getDataFromNode(e,this.shaderStage,this.globalCache);void 0===r.dimensionsSnippet&&(r.dimensionsSnippet={});let n=r.dimensionsSnippet[s];return void 0===r.dimensionsSnippet[s]&&(n=`textureDimension_${e.id}_${s}`,this.addLineFlowCode(`let ${n} = textureDimensions( ${t}, i32( ${s} ) );`),r.dimensionsSnippet[s]=n),n}generateFilteredTexture(e,t,s,r="0"){this._include("biquadraticTexture");return`tsl_biquadraticTexture( ${t}, ${this.generateWrapFunction(e)}( ${s} ), ${this.generateTextureDimension(e,t,r)}, i32( ${r} ) )`}generateTextureLod(e,t,s,r="0"){this._include("repeatWrapping");return`textureLoad( ${t}, tsl_repeatWrapping( ${s}, ${!0===e.isMultisampleRenderTargetTexture?`textureDimensions( ${t} )`:`textureDimensions( ${t}, 0 )`} ), i32( ${r} ) )`}generateTextureLoad(e,t,s,r,n="0u"){return r?`textureLoad( ${t}, ${s}, ${r}, ${n} )`:`textureLoad( ${t}, ${s}, ${n} )`}generateTextureStore(e,t,s,r){return`textureStore( ${t}, ${s}, ${r} )`}isUnfilterable(e){return"float"!==this.getComponentTypeFromTexture(e)||!this.isAvailable("float32Filterable")&&!0===e.isDataTexture&&e.type===E||!0===e.isMultisampleRenderTargetTexture}generateTexture(e,t,s,r,n=this.shaderStage){let i=null;return i=!0===e.isVideoTexture?this._generateVideoSample(t,s,n):this.isUnfilterable(e)?this.generateTextureLod(e,t,s,"0",r,n):this._generateTextureSample(e,t,s,r,n),i}generateTextureGrad(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleGrad( ${t}, ${t}_sampler, ${s}, ${r[0]}, ${r[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${i} shader.`)}generateTextureCompare(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleCompare( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${i} shader.`)}generateTextureLevel(e,t,s,r,n,i=this.shaderStage){let o=null;return o=!0===e.isVideoTexture?this._generateVideoSample(t,s,i):this._generateTextureSampleLevel(e,t,s,r,n,i),o}generateTextureBias(e,t,s,r,n,i=this.shaderStage){if("fragment"===i)return`textureSampleBias( ${t}, ${t}_sampler, ${s}, ${r} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${i} shader.`)}getPropertyName(e,t=this.shaderStage){if(!0===e.isNodeVarying&&!0===e.needsInterpolation){if("vertex"===t)return`varyings.${e.name}`}else if(!0===e.isNodeUniform){const t=e.name,s=e.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?t:"buffer"===s||"storageBuffer"===s||"indirectStorageBuffer"===s?`NodeBuffer_${e.id}.${t}`:e.groupNode.name+"."+t}return super.getPropertyName(e)}getOutputStructName(){return"output"}_getUniformGroupCount(e){return Object.keys(this.uniforms[e]).length}getFunctionOperator(e){const t=bS[e];return void 0!==t?(this._include(t),t):null}getStorageAccess(e){if(e.isStorageTextureNode)switch(e.access){case Wy:return"read";case Hy:return"write";default:return"read_write"}else switch(e.access){case zy:return"read_write";case $y:return"read";default:return"write"}}getUniformFromNode(e,t,s,r=null){const n=super.getUniformFromNode(e,t,s,r),i=this.getDataFromNode(e,s,this.globalCache);if(void 0===i.uniformGPU){let r;const o=e.groupNode,a=o.name,u=this.getBindGroupArray(a,s);if("texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t){let i=null;if("texture"===t||"storageTexture"===t?i=new vv(n.name,n.node,o,e.access?e.access:null):"cubeTexture"===t?i=new Sv(n.name,n.node,o,e.access?e.access:null):"texture3D"===t&&(i=new Av(n.name,n.node,o,e.access?e.access:null)),i.store=!0===e.isStorageTextureNode,i.setVisibility(fS[s]),"fragment"===s&&!1===this.isUnfilterable(e.value)&&!1===i.store){const e=new eS(`${n.name}_sampler`,n.node,o);e.setVisibility(fS[s]),u.push(e,i),r=[e,i]}else u.push(i),r=[i]}else if("buffer"===t||"storageBuffer"===t||"indirectStorageBuffer"===t){const n=new("buffer"===t?yv:rS)(e,o);n.setVisibility(fS[s]),u.push(n),r=n}else{const e=this.uniformGroups[s]||(this.uniformGroups[s]={});let i=e[a];void 0===i&&(i=new Tv(a,o),i.setVisibility(fS[s]),e[a]=i,u.push(i)),r=this.getNodeUniform(n,t),i.addUniform(r)}i.uniformGPU=r}return n}getBuiltin(e,t,s,r=this.shaderStage){const n=this.builtins[r]||(this.builtins[r]=new Map);return!1===n.has(e)&&n.set(e,{name:e,property:t,type:s}),t}hasBuiltin(e,t=this.shaderStage){return void 0!==this.builtins[t]&&this.builtins[t].has(e)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(e){const t=e.layout,s=this.flowShaderNode(e),r=[];for(const e of t.inputs)r.push(e.name+" : "+this.getType(e.type));let n=`fn ${t.name}( ${r.join(", ")} ) -> ${this.getType(t.type)} {\n${s.vars}\n${s.code}\n`;return s.result&&(n+=`\treturn ${s.result};\n`),n+="\n}\n",n}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}getClipDistance(){return"varyings.hw_clip_distances"}isFlipY(){return!1}enableDirective(e,t=this.shaderStage){(this.directives[t]||(this.directives[t]=new Set)).add(e)}getDirectives(e){const t=[],s=this.directives[e];if(void 0!==s)for(const e of s)t.push(`enable ${e};`);return t.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}enableHardwareClipping(e){this.enableClipDistances(),this.getBuiltin("clip_distances","hw_clip_distances",`array`,"vertex")}getBuiltins(e){const t=[],s=this.builtins[e];if(void 0!==s)for(const{name:e,property:r,type:n}of s.values())t.push(`@builtin( ${e} ) ${r} : ${n}`);return t.join(",\n\t")}getScopedArray(e,t,s,r){return!1===this.scopedArrays.has(e)&&this.scopedArrays.set(e,{name:e,scope:t,bufferType:s,bufferCount:r}),e}getScopedArrays(e){if("compute"!==e)return;const t=[];for(const{name:e,scope:s,bufferType:r,bufferCount:n}of this.scopedArrays.values()){const i=this.getType(r);t.push(`var<${s}> ${e}: array< ${i}, ${n} >;`)}return t.join("\n")}getAttributes(e){const t=[];if("compute"===e&&(this.getBuiltin("global_invocation_id","id","vec3","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3","attribute"),this.getBuiltin("local_invocation_id","localId","vec3","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3","attribute"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",e),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===e||"compute"===e){const e=this.getBuiltins("attribute");e&&t.push(e);const s=this.getAttributesArray();for(let e=0,r=s.length;e`)}const r=this.getBuiltins("output");return r&&t.push("\t"+r),t.join(",\n")}getStructs(e){const t=[],s=this.structs[e];for(let e=0,r=s.length;e output : ${n};\n\n`)}return t.join("\n\n")}getVar(e,t){return`var ${t} : ${this.getType(e)}`}getVars(e){const t=[],s=this.vars[e];if(void 0!==s)for(const e of s)t.push(`\t${this.getVar(e.type,e.name)};`);return`\n${t.join("\n")}\n`}getVaryings(e){const t=[];if("vertex"===e&&this.getBuiltin("position","Vertex","vec4","vertex"),"vertex"===e||"fragment"===e){const s=this.varyings,r=this.vars[e];for(let n=0;n";else if(!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture)r="texture_2d_array";else if(!0===t.isDepthTexture)r=`texture_depth${i}_2d`;else if(!0===t.isVideoTexture)r="texture_external";else if(!0===t.isData3DTexture)r="texture_3d";else if(!0===n.node.isStorageTextureNode){r=`texture_storage_2d<${uS(t)}, ${this.getStorageAccess(n.node)}>`}else{r=`texture${i}_2d<${this.getComponentTypeFromTexture(t).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${n.name} : ${r};`)}else if("buffer"===n.type||"storageBuffer"===n.type||"indirectStorageBuffer"===n.type){const e=n.node,t=this.getType(e.bufferType),s=e.bufferCount,i=s>0&&"buffer"===n.type?", "+s:"",a=e.isAtomic?`atomic<${t}>`:`${t}`,u=`\t${n.name} : array< ${a}${i} >\n`,l=e.isStorageBufferNode?`storage, ${this.getStorageAccess(e)}`:"uniform";r.push(this._getWGSLStructBinding("NodeBuffer_"+e.id,u,l,o.binding++,o.group))}else{const e=this.getType(this.getVectorType(n.type)),t=n.groupNode.name;(i[t]||(i[t]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${n.name} : ${e}`)}}for(const e in i){const t=i[e];n.push(this._getWGSLStructBinding(e,t.snippets.join(",\n"),"uniform",t.index,t.id))}let o=s.join("\n");return o+=r.join("\n"),o+=n.join("\n"),o}buildCode(){const e=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const t in e){const s=e[t];s.uniforms=this.getUniforms(t),s.attributes=this.getAttributes(t),s.varyings=this.getVaryings(t),s.structs=this.getStructs(t),s.vars=this.getVars(t),s.codes=this.getCodes(t),s.directives=this.getDirectives(t),s.scopedArrays=this.getScopedArrays(t);let r="// code\n\n";r+=this.flowCode[t];const n=this.flowNodes[t],i=n[n.length-1],o=i.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const e of n){const n=this.getFlowData(e),u=e.name;if(u&&(r.length>0&&(r+="\n"),r+=`\t// flow -> ${u}\n\t`),r+=`${n.code}\n\t`,e===i&&"compute"!==t)if(r+="// result\n\n\t","vertex"===t)r+=`varyings.Vertex = ${n.result};`;else if("fragment"===t)if(a)s.returnType=o.nodeType,r+=`return ${n.result};`;else{let e="\t@location(0) color: vec4";const t=this.getBuiltins("output");t&&(e+=",\n\t"+t),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",e),s.structs+="\nvar output : OutputStruct;\n\n",r+=`output.color = ${n.result};\n\n\treturn output;`}}s.flow=r}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(e.vertex),this.fragmentShader=this._getWGSLFragmentCode(e.fragment)):this.computeShader=this._getWGSLComputeCode(e.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(e,t=null){let s;return null!==t&&(s=this._getWGSLMethod(e+"_"+t)),void 0===s&&(s=this._getWGSLMethod(e)),s||e}getType(e){return xS[e]||e}isAvailable(e){let t=yS[e];return void 0===t&&("float32Filterable"===e?t=this.renderer.hasFeature("float32-filterable"):"clipDistance"===e&&(t=this.renderer.hasFeature("clip-distances")),yS[e]=t),t}_getWGSLMethod(e){return void 0!==_S[e]&&this._include(e),NS[e]}_include(e){const t=_S[e];return t.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(t),t}_getWGSLVertexCode(e){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// uniforms\n${e.uniforms}\n\n// varyings\n${e.varyings}\nvar varyings : VaryingsStruct;\n\n// codes\n${e.codes}\n\n@vertex\nfn main( ${e.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(e){return`${this.getSignature()}\n// global\n${vS}\n\n// uniforms\n${e.uniforms}\n\n// structs\n${e.structs}\n\n// codes\n${e.codes}\n\n@fragment\nfn main( ${e.varyings} ) -> ${e.returnType} {\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLComputeCode(e,t){return`${this.getSignature()}\n// directives\n${e.directives}\n\n// system\nvar instanceIndex : u32;\n\n// locals\n${e.scopedArrays}\n\n// uniforms\n${e.uniforms}\n\n// codes\n${e.codes}\n\n@compute @workgroup_size( ${t} )\nfn main( ${e.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${t}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${t});\n\n\t// vars\n\t${e.vars}\n\n\t// flow\n\t${e.flow}\n\n}\n`}_getWGSLStruct(e,t){return`\nstruct ${e} {\n${t}\n};`}_getWGSLStructBinding(e,t,s,r=0,n=0){const i=e+"Struct";return`${this._getWGSLStruct(i,t)}\n@binding( ${r} ) @group( ${n} )\nvar<${s}> ${e} : ${i};`}}class AS{constructor(e){this.backend=e}getCurrentDepthStencilFormat(e){let t;return null!==e.depthTexture?t=this.getTextureFormatGPU(e.depthTexture):e.depth&&e.stencil?t=uy.Depth24PlusStencil8:e.depth&&(t=uy.Depth24Plus),t}getTextureFormatGPU(e){return this.backend.get(e).format}getCurrentColorFormat(e){let t;return t=null!==e.textures?this.getTextureFormatGPU(e.textures[0]):this.getPreferredCanvasFormat(),t}getCurrentColorSpace(e){return null!==e.textures?e.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(e,t){return e.isPoints?Gf:e.isLineSegments||e.isMesh&&!0===t.wireframe?kf:e.isLine?zf:e.isMesh?$f:void 0}getSampleCount(e){let t=1;return e>1&&(t=Math.pow(2,Math.floor(Math.log2(e))),2===t&&(t=4)),t}getSampleCountRenderContext(e){return null!==e.textures?this.getSampleCount(e.sampleCount):this.getSampleCount(this.backend.renderer.samples)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?uy.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const RS=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),CS=new Map([[Ie,["float16"]]]),ES=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class wS{constructor(e){this.backend=e}createAttribute(e,t){const s=this._getBufferAttribute(e),r=this.backend,n=r.get(s);let i=n.buffer;if(void 0===i){const o=r.device;let a=s.array;if(!1===e.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const e=new Uint32Array(a.length);for(let t=0;t0&&(void 0===o.groups&&(o.groups=[],o.versions=[]),o.versions[s]===r&&(a=o.groups[s])),void 0===a&&(a=this.createBindGroup(e,u),s>0&&(o.groups[s]=a,o.versions[s]=r)),o.group=a,o.layout=u}updateBinding(e){const t=this.backend,s=t.device,r=e.buffer,n=t.get(e).buffer;s.queue.writeBuffer(n,0,r,0)}createBindGroup(e,t){const s=this.backend,r=s.device;let n=0;const i=[];for(const t of e.bindings){if(t.isUniformBuffer){const e=s.get(t);if(void 0===e.buffer){const s=t.byteLength,n=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,i=r.createBuffer({label:"bindingBuffer_"+t.name,size:s,usage:n});e.buffer=i}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isStorageBuffer){const e=s.get(t);if(void 0===e.buffer){const r=t.attribute;e.buffer=s.get(r).buffer}i.push({binding:n,resource:{buffer:e.buffer}})}else if(t.isSampler){const e=s.get(t.texture);i.push({binding:n,resource:e.sampler})}else if(t.isSampledTexture){const e=s.get(t.texture);let o;if(void 0!==e.externalTexture)o=r.importExternalTexture({source:e.externalTexture});else{const s=t.store?1:e.texture.mipLevelCount,r=`view-${e.texture.width}-${e.texture.height}-${s}`;if(o=e[r],void 0===o){const n=rb;let i;i=t.isSampledCubeTexture?tb:t.isSampledTexture3D?sb:t.texture.isDataArrayTexture||t.texture.isCompressedArrayTexture?eb:Jy,o=e[r]=e.texture.createView({aspect:n,dimension:i,mipLevelCount:s})}}i.push({binding:n,resource:o})}n++}return r.createBindGroup({label:"bindGroup_"+e.name,layout:t,entries:i})}}class BS{constructor(e){this.backend=e}_getSampleCount(e){return this.backend.utils.getSampleCountRenderContext(e)}createRenderPipeline(e,t){const{object:s,material:r,geometry:n,pipeline:i}=e,{vertexProgram:o,fragmentProgram:a}=i,u=this.backend,l=u.device,d=u.utils,c=u.get(i),h=[];for(const t of e.getBindings()){const e=u.get(t);h.push(e.layout)}const p=u.attributeUtils.createShaderVertexBuffers(e);let g;!0===r.transparent&&r.blending!==G&&(g=this._getBlending(r));let m={};!0===r.stencilWrite&&(m={compare:this._getStencilCompare(r),failOp:this._getStencilOperation(r.stencilFail),depthFailOp:this._getStencilOperation(r.stencilZFail),passOp:this._getStencilOperation(r.stencilZPass)});const f=this._getColorWriteMask(r),y=[];if(null!==e.context.textures){const t=e.context.textures;for(let e=0;e1},layout:l.createPipelineLayout({bindGroupLayouts:h})},A={},R=e.context.depth,C=e.context.stencil;if(!0!==R&&!0!==C||(!0===R&&(A.format=N,A.depthWriteEnabled=r.depthWrite,A.depthCompare=_),!0===C&&(A.stencilFront=m,A.stencilBack={},A.stencilReadMask=r.stencilFuncMask,A.stencilWriteMask=r.stencilWriteMask),S.depthStencil=A),null===t)c.pipeline=l.createRenderPipeline(S);else{const e=new Promise((e=>{l.createRenderPipelineAsync(S).then((t=>{c.pipeline=t,e()}))}));t.push(e)}}createBundleEncoder(e){const t=this.backend,{utils:s,device:r}=t,n=s.getCurrentDepthStencilFormat(e),i={label:"renderBundleEncoder",colorFormats:[s.getCurrentColorFormat(e)],depthStencilFormat:n,sampleCount:this._getSampleCount(e)};return r.createRenderBundleEncoder(i)}createComputePipeline(e,t){const s=this.backend,r=s.device,n=s.get(e.computeProgram).module,i=s.get(e),o=[];for(const e of t){const t=s.get(e);o.push(t.layout)}i.pipeline=r.createComputePipeline({compute:n,layout:r.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(e){let t,s;const r=e.blending,n=e.blendSrc,i=e.blendDst,o=e.blendEquation;if(r===mt){const r=null!==e.blendSrcAlpha?e.blendSrcAlpha:n,a=null!==e.blendDstAlpha?e.blendDstAlpha:i,u=null!==e.blendEquationAlpha?e.blendEquationAlpha:o;t={srcFactor:this._getBlendFactor(n),dstFactor:this._getBlendFactor(i),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(u)}}else{const n=(e,r,n,i)=>{t={srcFactor:e,dstFactor:r,operation:Cy},s={srcFactor:n,dstFactor:i,operation:Cy}};if(e.premultipliedAlpha)switch(r){case F:n(my,xy,my,xy);break;case bt:n(my,my,my,my);break;case yt:n(gy,yy,gy,my);break;case ft:n(gy,fy,gy,by)}else switch(r){case F:n(by,xy,my,xy);break;case bt:n(by,my,by,my);break;case yt:n(gy,yy,gy,my);break;case ft:n(gy,fy,gy,fy)}}if(void 0!==t&&void 0!==s)return{color:t,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",r)}_getBlendFactor(e){let t;switch(e){case tt:t=gy;break;case st:t=my;break;case rt:t=fy;break;case ut:t=yy;break;case nt:t=by;break;case lt:t=xy;break;case ot:t=Ty;break;case dt:t=_y;break;case at:t=Ny;break;case ct:t=vy;break;case it:t=Sy;break;case 211:t=Ay;break;case 212:t=Ry;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",e)}return t}_getStencilCompare(e){let t;const s=e.stencilFunc;switch(s){case ws:t=Wf;break;case Es:t=Zf;break;case Cs:t=jf;break;case Rs:t=Kf;break;case As:t=qf;break;case Ss:t=Qf;break;case vs:t=Xf;break;case Ns:t=Yf;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return t}_getStencilOperation(e){let t;switch(e){case Ds:t=Py;break;case Ls:t=Iy;break;case Is:t=Ly;break;case Ps:t=Dy;break;case Fs:t=Vy;break;case Us:t=Oy;break;case Bs:t=Gy;break;case Ms:t=ky;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",t)}return t}_getBlendOperation(e){let t;switch(e){case Ze:t=Cy;break;case Je:t=Ey;break;case et:t=wy;break;case Os:t=My;break;case Vs:t=By;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",e)}return t}_getPrimitiveState(e,t,s){const r={},n=this.backend.utils;switch(r.topology=n.getPrimitiveTopology(e,s),null!==t.index&&!0===e.isLine&&!0!==e.isLineSegments&&(r.stripIndexFormat=t.index.array instanceof Uint16Array?oy:ay),s.side){case Oe:r.frontFace=sy,r.cullMode=iy;break;case x:r.frontFace=sy,r.cullMode=ny;break;case le:r.frontFace=sy,r.cullMode=ry;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return r}_getColorWriteMask(e){return!0===e.colorWrite?Fy:Uy}_getDepthCompare(e){let t;if(!1===e.depthTest)t=Zf;else{const s=e.depthFunc;switch(s){case Rt:t=Wf;break;case At:t=Zf;break;case St:t=jf;break;case vt:t=Kf;break;case Nt:t=qf;break;case _t:t=Qf;break;case Tt:t=Xf;break;case xt:t=Yf;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return t}}class US extends Pv{constructor(e={}){super(e),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===e.alpha||e.alpha,this.parameters.requiredLimits=void 0===e.requiredLimits?{}:e.requiredLimits,this.trackTimestamp=!0===e.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new AS(this),this.attributeUtils=new wS(this),this.bindingUtils=new MS(this),this.pipelineUtils=new BS(this),this.textureUtils=new aS(this),this.occludedResolveCache=new Map}async init(e){await super.init(e);const t=this.parameters;let s;if(void 0===t.device){const e={powerPreference:t.powerPreference},r=await navigator.gpu.requestAdapter(e);if(null===r)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const n=Object.values(ob),i=[];for(const e of n)r.features.has(e)&&i.push(e);const o={requiredFeatures:i,requiredLimits:t.requiredLimits};s=await r.requestDevice(o)}else s=t.device;s.lost.then((t=>{const s={api:"WebGPU",message:t.message||"Unknown reason",reason:t.reason||null,originalEvent:t};e.onDeviceLost(s)}));const r=void 0!==t.context?t.context:e.domElement.getContext("webgpu");this.device=s,this.context=r;const n=t.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(ob.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:n}),this.updateSize()}get coordinateSystem(){return N}async getArrayBufferAsync(e){return await this.attributeUtils.getArrayBufferAsync(e)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let e=this.defaultRenderPassdescriptor;if(null===e){const t=this.renderer;e={colorAttachments:[{view:null}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(e.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(t.depth,t.stencil).createView()});const s=e.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=e}const t=e.colorAttachments[0];return this.renderer.samples>0?t.resolveTarget=this.context.getCurrentTexture().createView():t.view=this.context.getCurrentTexture().createView(),e}_getRenderPassDescriptor(e){const t=e.renderTarget,s=this.get(t);let r=s.descriptors;if(void 0===r||s.width!==t.width||s.height!==t.height||s.activeMipmapLevel!==t.activeMipmapLevel||s.samples!==t.samples){r={},s.descriptors=r;const e=()=>{t.removeEventListener("dispose",e),this.delete(t)};t.addEventListener("dispose",e)}const n=e.getCacheKey();let i=r[n];if(void 0===i){const o=e.textures,a=[];for(let t=0;t0&&(t.currentOcclusionQuerySet&&t.currentOcclusionQuerySet.destroy(),t.currentOcclusionQueryBuffer&&t.currentOcclusionQueryBuffer.destroy(),t.currentOcclusionQuerySet=t.occlusionQuerySet,t.currentOcclusionQueryBuffer=t.occlusionQueryBuffer,t.currentOcclusionQueryObjects=t.occlusionQueryObjects,n=s.createQuerySet({type:"occlusion",count:r,label:`occlusionQuerySet_${e.id}`}),t.occlusionQuerySet=n,t.occlusionQueryIndex=0,t.occlusionQueryObjects=new Array(r),t.lastOcclusionObject=null),i=null===e.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(e),this.initTimestampQuery(e,i),i.occlusionQuerySet=n;const o=i.depthStencilAttachment;if(null!==e.textures){const t=i.colorAttachments;for(let s=0;s0&&t.currentPass.executeBundles(t.renderBundles),s>t.occlusionQueryIndex&&t.currentPass.endOcclusionQuery(),t.currentPass.end(),s>0){const r=8*s;let n=this.occludedResolveCache.get(r);void 0===n&&(n=this.device.createBuffer({size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(r,n));const i=this.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});t.encoder.resolveQuerySet(t.occlusionQuerySet,0,s,n,0),t.encoder.copyBufferToBuffer(n,0,i,0,r),t.occlusionQueryBuffer=i,this.resolveOccludedAsync(e)}if(this.prepareTimestampBuffer(e,t.encoder),this.device.queue.submit([t.encoder.finish()]),null!==e.textures){const t=e.textures;for(let e=0;eo?(u.x=Math.min(t.dispatchCount,o),u.y=Math.ceil(t.dispatchCount/o)):u.x=t.dispatchCount,n.dispatchWorkgroups(u.x,u.y,u.z)}finishCompute(e){const t=this.get(e);t.passEncoderGPU.end(),this.prepareTimestampBuffer(e,t.cmdEncoderGPU),this.device.queue.submit([t.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(e,t){const{object:s,context:r,pipeline:n}=e,i=e.getBindings(),o=this.get(r),a=this.get(n).pipeline,u=o.currentSets,l=o.currentPass,d=e.getDrawParameters();if(null===d)return;u.pipeline!==a&&(l.setPipeline(a),u.pipeline=a);const c=u.bindingGroups;for(let e=0,t=i.length;e1?0:s;l.drawIndexed(t[s],r,e[s]/i,0,o)}}else if(!0===p){const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndexedIndirect(e,0)}else l.drawIndexed(r,n,i,0,0);t.update(s,r,n)}else{const{vertexCount:r,instanceCount:n,firstVertex:i}=d,o=e.getIndirect();if(null!==o){const e=this.get(o).buffer;l.drawIndirect(e,0)}else l.draw(r,n,i,0);t.update(s,r,n)}}needsRenderUpdate(e){const t=this.get(e),{object:s,material:r}=e,n=this.utils,i=n.getSampleCountRenderContext(e.context),o=n.getCurrentColorSpace(e.context),a=n.getCurrentColorFormat(e.context),u=n.getCurrentDepthStencilFormat(e.context),l=n.getPrimitiveTopology(s,r);let d=!1;return t.material===r&&t.materialVersion===r.version&&t.transparent===r.transparent&&t.blending===r.blending&&t.premultipliedAlpha===r.premultipliedAlpha&&t.blendSrc===r.blendSrc&&t.blendDst===r.blendDst&&t.blendEquation===r.blendEquation&&t.blendSrcAlpha===r.blendSrcAlpha&&t.blendDstAlpha===r.blendDstAlpha&&t.blendEquationAlpha===r.blendEquationAlpha&&t.colorWrite===r.colorWrite&&t.depthWrite===r.depthWrite&&t.depthTest===r.depthTest&&t.depthFunc===r.depthFunc&&t.stencilWrite===r.stencilWrite&&t.stencilFunc===r.stencilFunc&&t.stencilFail===r.stencilFail&&t.stencilZFail===r.stencilZFail&&t.stencilZPass===r.stencilZPass&&t.stencilFuncMask===r.stencilFuncMask&&t.stencilWriteMask===r.stencilWriteMask&&t.side===r.side&&t.alphaToCoverage===r.alphaToCoverage&&t.sampleCount===i&&t.colorSpace===o&&t.colorFormat===a&&t.depthStencilFormat===u&&t.primitiveTopology===l&&t.clippingContextCacheKey===e.clippingContextCacheKey||(t.material=r,t.materialVersion=r.version,t.transparent=r.transparent,t.blending=r.blending,t.premultipliedAlpha=r.premultipliedAlpha,t.blendSrc=r.blendSrc,t.blendDst=r.blendDst,t.blendEquation=r.blendEquation,t.blendSrcAlpha=r.blendSrcAlpha,t.blendDstAlpha=r.blendDstAlpha,t.blendEquationAlpha=r.blendEquationAlpha,t.colorWrite=r.colorWrite,t.depthWrite=r.depthWrite,t.depthTest=r.depthTest,t.depthFunc=r.depthFunc,t.stencilWrite=r.stencilWrite,t.stencilFunc=r.stencilFunc,t.stencilFail=r.stencilFail,t.stencilZFail=r.stencilZFail,t.stencilZPass=r.stencilZPass,t.stencilFuncMask=r.stencilFuncMask,t.stencilWriteMask=r.stencilWriteMask,t.side=r.side,t.alphaToCoverage=r.alphaToCoverage,t.sampleCount=i,t.colorSpace=o,t.colorFormat=a,t.depthStencilFormat=u,t.primitiveTopology=l,t.clippingContextCacheKey=e.clippingContextCacheKey,d=!0),d}getRenderCacheKey(e){const{object:t,material:s}=e,r=this.utils,n=e.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,r.getSampleCountRenderContext(n),r.getCurrentColorSpace(n),r.getCurrentColorFormat(n),r.getCurrentDepthStencilFormat(n),r.getPrimitiveTopology(t,s),e.getGeometryCacheKey(),e.clippingContextCacheKey].join()}createSampler(e){this.textureUtils.createSampler(e)}destroySampler(e){this.textureUtils.destroySampler(e)}createDefaultTexture(e){this.textureUtils.createDefaultTexture(e)}createTexture(e,t){this.textureUtils.createTexture(e,t)}updateTexture(e,t){this.textureUtils.updateTexture(e,t)}generateMipmaps(e){this.textureUtils.generateMipmaps(e)}destroyTexture(e){this.textureUtils.destroyTexture(e)}copyTextureToBuffer(e,t,s,r,n,i){return this.textureUtils.copyTextureToBuffer(e,t,s,r,n,i)}async initTimestampQuery(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet){this.device.pushErrorScope("out-of-memory");const r=await this.device.createQuerySet({type:"timestamp",count:2,label:`timestamp_renderContext_${e.id}`});if(await this.device.popErrorScope())return s.attemptingTimeStampQuerySetFailed||(console.error(`[GPUOutOfMemoryError][renderContext_${e.id}]:\nFailed to create timestamp query set. This may be because timestamp queries are already running in other tabs.`),s.attemptingTimeStampQuerySetFailed=!0),void(s.timeStampQuerySet=null);const n={querySet:r,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(t,{timestampWrites:n}),s.timeStampQuerySet=r}}prepareTimestampBuffer(e,t){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;const r=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:r,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:n,resultBuffer:i,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(t.resolveQuerySet(s.timeStampQuerySet,0,2,n,0),t.copyBufferToBuffer(n,0,i,0,r))}async resolveTimestampAsync(e,t="render"){if(!this.trackTimestamp)return;const s=this.get(e);if(!s.timeStampQuerySet)return;if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:r,isMappingPending:n}=s.currentTimestampQueryBuffers;!0!==n&&(s.currentTimestampQueryBuffers.isMappingPending=!0,r.mapAsync(GPUMapMode.READ).then((()=>{const e=new BigUint64Array(r.getMappedRange()),n=Number(e[1]-e[0])/1e6;this.renderer.info.updateTimestamp(t,n),r.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(e,t){return new SS(e,t)}createProgram(e){this.get(e).module={module:this.device.createShaderModule({code:e.code,label:e.stage}),entryPoint:"main"}}destroyProgram(e){this.delete(e)}createRenderPipeline(e,t){this.pipelineUtils.createRenderPipeline(e,t)}createComputePipeline(e,t){this.pipelineUtils.createComputePipeline(e,t)}beginBundle(e){const t=this.get(e);t._currentPass=t.currentPass,t._currentSets=t.currentSets,t.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},t.currentPass=this.pipelineUtils.createBundleEncoder(e)}finishBundle(e,t){const s=this.get(e),r=s.currentPass.finish();this.get(t).bundleGPU=r,s.currentSets=s._currentSets,s.currentPass=s._currentPass}addBundle(e,t){this.get(e).renderBundles.push(this.get(t).bundleGPU)}createBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBindings(e,t,s,r){this.bindingUtils.createBindings(e,t,s,r)}updateBinding(e){this.bindingUtils.updateBinding(e)}createIndexAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createIndirectStorageAttribute(e){this.attributeUtils.createAttribute(e,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(e){this.attributeUtils.updateAttribute(e)}destroyAttribute(e){this.attributeUtils.destroyAttribute(e)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(e){return this.device.features.has(e)}copyTextureToTexture(e,t,s=null,r=null,n=0){let i=0,o=0,a=0,u=0,l=0,d=0,c=e.image.width,h=e.image.height;null!==s&&(u=s.x,l=s.y,d=s.z||0,c=s.width,h=s.height),null!==r&&(i=r.x,o=r.y,a=r.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+e.id+"_"+t.id}),g=this.get(e).texture,m=this.get(t).texture;p.copyTextureToTexture({texture:g,mipLevel:n,origin:{x:u,y:l,z:d}},{texture:m,mipLevel:n,origin:{x:i,y:o,z:a}},[c,h,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(e,t,s){const r=this.get(t);let n=null;n=t.renderTarget?e.isDepthTexture?this.get(t.depthTexture).texture:this.get(t.textures[0]).texture:e.isDepthTexture?this.textureUtils.getDepthBuffer(t.depth,t.stencil):this.context.getCurrentTexture();const i=this.get(e).texture;if(n.format!==i.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,i.format);let o;if(r.currentPass?(r.currentPass.end(),o=r.encoder):o=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+e.id}),o.copyTextureToTexture({texture:n,origin:{x:s.x,y:s.y,z:0}},{texture:i},[s.z,s.w]),e.generateMipmaps&&this.textureUtils.generateMipmaps(e),r.currentPass){const{descriptor:e}=r;for(let t=0;t(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new Zv(e)));super(new t(e),e),this.library=new PS,this.isWebGPURenderer=!0}}class LS extends Js{constructor(){super(),this.isBundleGroup=!0,this.type="BundleGroup",this.static=!0,this.version=0}set needsUpdate(e){!0===e&&this.version++}}const DS=new nh,VS=new Tf(DS);class OS{constructor(e,t=Ln(0,0,1,1)){this.renderer=e,this.outputNode=t,this.outputColorTransform=!0,this.needsUpdate=!0,DS.name="PostProcessing"}render(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,VS.render(e),e.toneMapping=t,e.outputColorSpace=s}update(){if(!0===this.needsUpdate){const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;VS.material.fragmentNode=!0===this.outputColorTransform?cu(this.outputNode,t,s):this.outputNode.context({toneMapping:t,outputColorSpace:s}),VS.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const e=this.renderer,t=e.toneMapping,s=e.outputColorSpace;e.toneMapping=d,e.outputColorSpace=Se,await VS.renderAsync(e),e.toneMapping=t,e.outputColorSpace=s}}function GS(t,s={}){return s.toneMapping=t.toneMapping,s.toneMappingExposure=t.toneMappingExposure,s.outputColorSpace=t.outputColorSpace,s.renderTarget=t.getRenderTarget(),s.activeCubeFace=t.getActiveCubeFace(),s.activeMipmapLevel=t.getActiveMipmapLevel(),s.renderObjectFunction=t.getRenderObjectFunction(),s.pixelRatio=t.getPixelRatio(),s.mrt=t.getMRT(),s.clearColor=t.getClearColor(s.clearColor||new e),s.clearAlpha=t.getClearAlpha(),s.autoClear=t.autoClear,s.scissorTest=t.getScissorTest(),s}function kS(e,t){e.toneMapping=t.toneMapping,e.toneMappingExposure=t.toneMappingExposure,e.outputColorSpace=t.outputColorSpace,e.setRenderTarget(t.renderTarget,t.activeCubeFace,t.activeMipmapLevel),e.setRenderObjectFunction(t.renderObjectFunction),e.setPixelRatio(t.pixelRatio),e.setMRT(t.mrt),e.setClearColor(t.clearColor,t.clearAlpha),e.autoClear=t.autoClear,e.setScissorTest(t.scissorTest)}function zS(e,t,s={}){return(s=GS(e,s)).background=t.background,s.backgroundNode=t.backgroundNode,s.overrideMaterial=t.overrideMaterial,s}var $S=Object.freeze({__proto__:null,resetRendererAndSceneState:function(e,t,s){return s=zS(e,t,s),t.background=null,t.backgroundNode=null,t.overrideMaterial=null,s},resetRendererState:function(e,t){return t=GS(e,t),e.setMRT(null),e.setRenderObjectFunction(null),e.setClearColor(0,1),e.autoClear=!0,t},restoreRendererAndSceneState:function(e,t,s){kS(e,s),t.background=s.background,t.backgroundNode=s.backgroundNode,t.overrideMaterial=s.overrideMaterial},restoreRendererState:kS,saveRendererAndSceneState:zS,saveRendererState:GS});class HS extends ee{constructor(e=1,t=1){super(),this.image={width:e,height:t},this.magFilter=$,this.minFilter=$,this.isStorageTexture=!0}}class WS extends we{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageBufferAttribute=!0}}class jS extends R{constructor(e,t,s=Float32Array){!1===ArrayBuffer.isView(e)&&(e=new s(e*t)),super(e,t),this.isStorageInstancedBufferAttribute=!0}}class qS extends WS{constructor(e,t){super(e,t,Uint32Array),this.isIndirectStorageBufferAttribute=!0}}class KS extends er{constructor(e){super(e),this.textures={},this.nodes={}}load(e,t,s,r){const n=new tr(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(e,(s=>{try{t(this.parse(JSON.parse(s)))}catch(t){r?r(t):console.error(t),this.manager.itemError(e)}}),s,r)}parseNodes(e){const t={};if(void 0!==e){for(const s of e){const{uuid:e,type:r}=s;t[e]=this.createNodeFromType(r),t[e].uuid=e}const s={nodes:t,textures:this.textures};for(const r of e){r.meta=s;t[r.uuid].deserialize(r),delete r.meta}}return t}parse(e){const t=this.createNodeFromType(e.type);t.uuid=e.uuid;const s={nodes:this.parseNodes(e.nodes),textures:this.textures};return e.meta=s,t.deserialize(e),delete e.meta,t}setTextures(e){return this.textures=e,this}setNodes(e){return this.nodes=e,this}createNodeFromType(e){return void 0===this.nodes[e]?(console.error("THREE.NodeLoader: Node type not found:",e),Sn()):hn(new this.nodes[e])}}class XS extends sr{constructor(e){super(e),this.nodes={},this.nodeMaterials={}}parse(e){const t=super.parse(e),s=this.nodes,r=e.inputNodes;for(const e in r){const n=r[e];t[e]=s[n]}return t}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}createMaterialFromType(e){const t=this.nodeMaterials[e];return void 0!==t?new t:super.createMaterialFromType(e)}}class YS extends rr{constructor(e){super(e),this.nodes={},this.nodeMaterials={},this._nodesJSON=null}setNodes(e){return this.nodes=e,this}setNodeMaterials(e){return this.nodeMaterials=e,this}parse(e,t){this._nodesJSON=e.nodes;const s=super.parse(e,t);return this._nodesJSON=null,s}parseNodes(e,t){if(void 0!==e){const s=new KS;return s.setNodes(this.nodes),s.setTextures(t),s.parseNodes(e)}return{}}parseMaterials(e,t){const s={};if(void 0!==e){const r=this.parseNodes(this._nodesJSON,t),n=new XS;n.setTextures(t),n.setNodes(r),n.setNodeMaterials(this.nodeMaterials);for(let t=0,r=e.length;t Date: Tue, 19 Nov 2024 03:40:23 +0100 Subject: [PATCH 06/24] Update WGSLNodeBuilder.js fix lint --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 02cb9375db5fac..f1e11bf89a1122 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1020,7 +1020,7 @@ ${ flowData.code } while ( ( paramMatch = parameterRegex.exec( parameterString ) ) !== null ) { - const [ fullMatch, name, fullType, ptrType, arrayType, directStructName ] = paramMatch; + const [ , name, fullType, ptrType, arrayType, directStructName ] = paramMatch; const structName = arrayType || directStructName || null; From 273e5887987ca05ac912544c7036e85360df2b4e Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 03:50:49 +0100 Subject: [PATCH 07/24] Update WGSLNodeBuilder.js fix lint --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index f1e11bf89a1122..a56ac888c6378b 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1026,7 +1026,7 @@ ${ flowData.code } const type = ptrType || fullType; - if (Object.values(wgslTypeLib).includes(structName) || structName === null) { + if ( Object.values( wgslTypeLib ).includes( structName ) || structName === null ) { continue; From 5341a2966dfc502df6e897f38a63e3233f913b15 Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 03:54:32 +0100 Subject: [PATCH 08/24] Update WGSLNodeBuilder.js fix lint --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index a56ac888c6378b..8f5e1122efce43 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1457,9 +1457,9 @@ ${ flowData.code } flow = reduceFlow( flow ); - pointerNames = extractPointerNames(flow); - structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); - stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); + pointerNames = extractPointerNames( flow ); + structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); + stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); if ( node === mainNode && shaderStage !== 'compute' ) { @@ -1496,9 +1496,9 @@ ${ flowData.code } } flow = reduceFlow( flow ); - pointerNames = extractPointerNames(flow); - structnameMapping = createStructNameMapping(pointerNames, stageData.customStructNames); - stageData.uniforms = replaceStructNamesInUniforms(stageData.uniforms, structnameMapping); + pointerNames = extractPointerNames( flow ); + structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); + stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); } From 28fb56dbcb2ab14d07b0aac87e77182981defe1d Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 04:00:56 +0100 Subject: [PATCH 09/24] Update WGSLNodeBuilder.js fix lint --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 8f5e1122efce43..a510e321e7ee0c 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1400,61 +1400,6 @@ ${ flowData.code } flow += `${ flowSlotData.code }\n\t`; - /* - REVIEW COMMENT remove after review - - before reduceFlow: - compute( &NodeBuffer_554.nodeUniform0, &NodeBuffer_558.nodeUniform1, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); - - after reduceFlow: reduceFlow checks whether there is a storageStruct and if so then the - postfix is ​​removed so that the pointer points to the struct and not to a content in the struct - compute( &NodeBuffer_554, &NodeBuffer_558, &NodeBuffer_555.nodeUniform2, &NodeBuffer_556.nodeUniform3, &NodeBuffer_557.nodeUniform4, &NodeBuffer_559.nodeUniform5, instanceIndex, object.nodeUniform6 ); - - extractPointerNames reads the names of the reduced pointers and stores them in an array - Array(2) - 0: "NodeBuffer_554" - 1: "NodeBuffer_558" - - getCustomStructNameFromShader at the beginning reads the structNames from the shader header - Array(2) - 0: {name: 'drawBuffer', type: 'storage', structName: 'DrawBuffer'} - 1: {name: 'meshletInfo', type: 'storage', structName: 'MeshletInfo'} - - - createStructNameMapping links the automatic generated WGSLNodeBuilder for each struct with the struct name specified by the user. - This is necessary because in wgslFn the user can choose any name in the shader in ptr for structs. - - Map(2) - [[Entries]] - 0: {"NodeBuffer_554" => "DrawBuffer"} - 1: {"NodeBuffer_558" => "MeshletInfo"} - - replaceStructNames then replaces the names in the uniforms in the custom structs that the WGSLNodeBuilder - created with the name chosen by the user. - - before replaceStructNames: - - struct NodeBuffer_554Struct { - vertexCount: u32, - instanceCount: u32, - firstVertex: u32, - firstInstance: u32 - }; - @binding( 0 ) @group( 0 ) - var NodeBuffer_554 : NodeBuffer_554Struct; - - after replaceStructNames: - - struct DrawBuffer { - vertexCount: u32, - instanceCount: u32, - firstVertex: u32, - firstInstance: u32 - }; - @binding( 0 ) @group( 0 ) - var NodeBuffer_554 : DrawBuffer; - */ - flow = reduceFlow( flow ); pointerNames = extractPointerNames( flow ); From 7850209a903a5481b92298fa6c173ad4da4190c0 Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 04:03:52 +0100 Subject: [PATCH 10/24] Update WGSLNodeBuilder.js fix lint --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index a510e321e7ee0c..82b884d223ed66 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1349,8 +1349,8 @@ ${ flowData.code } for (let i = 0; i < nodeBuffers.length; i++) { - const bufferName = nodeBuffers[i]; - const struct = structs[i]; + const bufferName = nodeBuffers[ i ]; + const struct = structs[ i ]; resultMap.set(bufferName, struct.structName); From a072a6ef3cb0cce70eebd429acfaacedc3f20e8c Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 04:06:53 +0100 Subject: [PATCH 11/24] Update WGSLNodeBuilder.js fix lint --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 82b884d223ed66..575232285b8804 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1347,12 +1347,12 @@ ${ flowData.code } const resultMap = new Map(); - for (let i = 0; i < nodeBuffers.length; i++) { + for ( let i = 0; i < nodeBuffers.length; i++ ) { const bufferName = nodeBuffers[ i ]; const struct = structs[ i ]; - resultMap.set(bufferName, struct.structName); + resultMap.set( bufferName, struct.structName ); } From 99218beba5126f703fb983840bfaf9c93501437d Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 04:12:28 +0100 Subject: [PATCH 12/24] Update WGSLNodeBuilder.js fix lint --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 575232285b8804..d49585b3216116 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1347,7 +1347,7 @@ ${ flowData.code } const resultMap = new Map(); - for ( let i = 0; i < nodeBuffers.length; i++ ) { + for ( let i = 0; i < nodeBuffers.length; i ++ ) { const bufferName = nodeBuffers[ i ]; const struct = structs[ i ]; From 4d618cb09d9578197b83b107ab644aba80c78359 Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 04:33:35 +0100 Subject: [PATCH 13/24] Update WGSLNodeBuilder.js --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index d49585b3216116..9f6aa30a42706e 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1338,7 +1338,7 @@ ${ flowData.code } .split( /\s*,\s*/ ) .map( part => part.trim() ) .filter( part => part.includes( '&' ) ) - .map( part => part.replace( '&', '' ) ) + .map( part => part.replace( /&/g, '' ) ) .filter( part => ! part.includes( '.' ) ); }; From a5127215c0acd95e8cb4484bb049bf08d8a77726 Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 05:49:52 +0100 Subject: [PATCH 14/24] Update WGSLNodeBuilder.js more elegant _getWGSLStructBinding --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 9f6aa30a42706e..aae053466a0fee 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1652,23 +1652,12 @@ ${vars} _getWGSLStructBinding( isBufferStruct, isArray, name, vars, access, binding = 0, group = 0 ) { const structName = name + 'Struct'; - const structSnippet = this._getWGSLStruct( structName, vars ); + const structSnippet = this._getWGSLStruct(structName, vars); + const structName_ = isBufferStruct ? (isArray ? `array<${structName}>` : structName) : structName; - if ( ! isBufferStruct ) { - - return `${structSnippet} -@binding( ${binding} ) @group( ${group} ) -var<${access}> ${name} : ${structName};`; - - } else { - - const StructName = isArray ? `array<${structName}>` : structName; - - return `${structSnippet} + return `${structSnippet} @binding( ${binding} ) @group( ${group} ) -var<${access}> ${name} : ${StructName};`; - - } +var<${access}> ${name} : ${structName_};`; } From 4882f9edaeb562dfec879b4ecf1ff68d0ebef432 Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 05:50:54 +0100 Subject: [PATCH 15/24] Update WGSLNodeBuilder.js --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index aae053466a0fee..1829f12ecd2b92 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1652,7 +1652,7 @@ ${vars} _getWGSLStructBinding( isBufferStruct, isArray, name, vars, access, binding = 0, group = 0 ) { const structName = name + 'Struct'; - const structSnippet = this._getWGSLStruct(structName, vars); + const structSnippet = this._getWGSLStruct( structName, vars ); const structName_ = isBufferStruct ? (isArray ? `array<${structName}>` : structName) : structName; return `${structSnippet} From 1f646fd2087cdecba3f9cc68c8946aedc58f893e Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Tue, 19 Nov 2024 05:54:23 +0100 Subject: [PATCH 16/24] Update WGSLNodeBuilder.js --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 1829f12ecd2b92..613da7fd1c2ef9 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1653,7 +1653,7 @@ ${vars} const structName = name + 'Struct'; const structSnippet = this._getWGSLStruct( structName, vars ); - const structName_ = isBufferStruct ? (isArray ? `array<${structName}>` : structName) : structName; + const structName_ = isBufferStruct ? ( isArray ? `array<${structName}>` : structName ) : structName; return `${structSnippet} @binding( ${binding} ) @group( ${group} ) From baa6d0c287a7ca35930235b9db289bae1e1d31c4 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Thu, 21 Nov 2024 06:47:34 +0100 Subject: [PATCH 17/24] update getCustomStructNameFromShader --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 613da7fd1c2ef9..5e9a04d17c9aaa 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1005,39 +1005,34 @@ ${ flowData.code } getCustomStructNameFromShader( source ) { - const functionRegex = /fn\s+\w+\s*\(([\s\S]*?)\)/g; // filter shader header - const parameterRegex = /(\w+)\s*:\s*(ptr<\s*([\w]+),\s*(?:array<([\w<>]+)>|(\w+))[^>]*>|[\w<>,]+)/g; // filter parameters + //This declarationRegexp can be adopted as a new standard in a separate PR and would no longer be necessary separately here. + //The difference is that the shader return type is optional + + const declarationRegexp = /^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*(?:->\s*([a-z_0-9]+(?:<[\s\S]+?>)?))?/i; + const parameterRegex = /([a-z_0-9]+)\s*:\s*(ptr<\s*([a-z_0-9]+),\s*(?:array<([a-z_0-9<>]+)>|([a-z_0-9]+))[^>]*>|[a-z_0-9<>,]+)/ig; const results = []; - let match; + source = source.trim(); - while ( ( match = functionRegex.exec( source ) ) !== null ) { + const declaration = source.match( declarationRegexp ); - const parameterString = match[ 1 ]; + if ( declaration !== null && declaration.length === 4 ) { let paramMatch; - while ( ( paramMatch = parameterRegex.exec( parameterString ) ) !== null ) { - - const [ , name, fullType, ptrType, arrayType, directStructName ] = paramMatch; + while ( ( paramMatch = parameterRegex.exec( declaration[ 2 ] ) ) !== null ) { - const structName = arrayType || directStructName || null; + const name = paramMatch[ 1 ]; - const type = ptrType || fullType; + const structName = paramMatch[ 4 ] || paramMatch[ 5 ]; //4 array, 5 single - if ( Object.values( wgslTypeLib ).includes( structName ) || structName === null ) { + if ( structName && ! Object.values( wgslTypeLib ).includes( structName ) ) { - continue; + results.push( { name, structName } ); } - results.push( { - name, - type, - structName - } ); - } } @@ -1253,7 +1248,6 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; - const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; @@ -1339,6 +1333,7 @@ ${ flowData.code } .map( part => part.trim() ) .filter( part => part.includes( '&' ) ) .map( part => part.replace( /&/g, '' ) ) + .map( part => part.replace( /&/g, '' ) ) .filter( part => ! part.includes( '.' ) ); }; @@ -1347,12 +1342,16 @@ ${ flowData.code } const resultMap = new Map(); + for ( let i = 0; i < nodeBuffers.length; i ++ ) { for ( let i = 0; i < nodeBuffers.length; i ++ ) { const bufferName = nodeBuffers[ i ]; const struct = structs[ i ]; + const bufferName = nodeBuffers[ i ]; + const struct = structs[ i ]; resultMap.set( bufferName, struct.structName ); + resultMap.set( bufferName, struct.structName ); } @@ -1405,6 +1404,9 @@ ${ flowData.code } pointerNames = extractPointerNames( flow ); structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); + pointerNames = extractPointerNames( flow ); + structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); + stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); if ( node === mainNode && shaderStage !== 'compute' ) { @@ -1444,6 +1446,9 @@ ${ flowData.code } pointerNames = extractPointerNames( flow ); structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); + pointerNames = extractPointerNames( flow ); + structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); + stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); } @@ -1654,9 +1659,12 @@ ${vars} const structName = name + 'Struct'; const structSnippet = this._getWGSLStruct( structName, vars ); const structName_ = isBufferStruct ? ( isArray ? `array<${structName}>` : structName ) : structName; + const structName_ = isBufferStruct ? ( isArray ? `array<${structName}>` : structName ) : structName; return `${structSnippet} + return `${structSnippet} @binding( ${binding} ) @group( ${group} ) +var<${access}> ${name} : ${structName_};`; var<${access}> ${name} : ${structName_};`; } From 9f9b70d42d2e409dec74254a7ccf814baca8c571 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Thu, 21 Nov 2024 07:09:32 +0100 Subject: [PATCH 18/24] update getCustomStructNameFromShader --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 5e9a04d17c9aaa..0e61953b99ffb6 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1248,6 +1248,7 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; + const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; @@ -1333,7 +1334,6 @@ ${ flowData.code } .map( part => part.trim() ) .filter( part => part.includes( '&' ) ) .map( part => part.replace( /&/g, '' ) ) - .map( part => part.replace( /&/g, '' ) ) .filter( part => ! part.includes( '.' ) ); }; @@ -1342,16 +1342,12 @@ ${ flowData.code } const resultMap = new Map(); - for ( let i = 0; i < nodeBuffers.length; i ++ ) { for ( let i = 0; i < nodeBuffers.length; i ++ ) { const bufferName = nodeBuffers[ i ]; const struct = structs[ i ]; - const bufferName = nodeBuffers[ i ]; - const struct = structs[ i ]; resultMap.set( bufferName, struct.structName ); - resultMap.set( bufferName, struct.structName ); } @@ -1404,9 +1400,6 @@ ${ flowData.code } pointerNames = extractPointerNames( flow ); structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); - pointerNames = extractPointerNames( flow ); - structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); - stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); if ( node === mainNode && shaderStage !== 'compute' ) { @@ -1446,9 +1439,6 @@ ${ flowData.code } pointerNames = extractPointerNames( flow ); structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); - pointerNames = extractPointerNames( flow ); - structnameMapping = createStructNameMapping( pointerNames, stageData.customStructNames ); - stageData.uniforms = replaceStructNamesInUniforms( stageData.uniforms, structnameMapping ); } @@ -1659,16 +1649,13 @@ ${vars} const structName = name + 'Struct'; const structSnippet = this._getWGSLStruct( structName, vars ); const structName_ = isBufferStruct ? ( isArray ? `array<${structName}>` : structName ) : structName; - const structName_ = isBufferStruct ? ( isArray ? `array<${structName}>` : structName ) : structName; return `${structSnippet} - return `${structSnippet} @binding( ${binding} ) @group( ${group} ) -var<${access}> ${name} : ${structName_};`; var<${access}> ${name} : ${structName_};`; } } -export default WGSLNodeBuilder; +export default WGSLNodeBuilder; \ No newline at end of file From d704d92087344e8d1e652b5c503f416bc71d6fa8 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Thu, 21 Nov 2024 07:23:06 +0100 Subject: [PATCH 19/24] update getCustomStructNameFromShader --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 0e61953b99ffb6..a27af08b96c551 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1248,7 +1248,6 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; - const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; @@ -1658,4 +1657,4 @@ var<${access}> ${name} : ${structName_};`; } -export default WGSLNodeBuilder; \ No newline at end of file +export default WGSLNodeBuilder; From 6f5ec078671acb41db7333ebe903f72b1cca1c3d Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Thu, 21 Nov 2024 21:49:46 +0100 Subject: [PATCH 20/24] add isArray input parameter check for their existance --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index a27af08b96c551..c4588381b37f2b 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1248,7 +1248,14 @@ ${ flowData.code } const bufferType = this.getType( bufferNode.bufferType ); const bufferCount = bufferNode.bufferCount; - const isArray = bufferNode.value.array.length !== bufferNode.value.itemSize; + let isArray = false; + + if ( bufferNode.value?.array?.length && bufferNode.value?.itemSize ) { + + isArray = bufferType && bufferNode.value.array.length > bufferNode.value.itemSize; + + } + const bufferCountSnippet = bufferCount > 0 && uniform.type === 'buffer' ? ', ' + bufferCount : ''; const bufferTypeSnippet = bufferNode.isAtomic ? `atomic<${bufferType}>` : `${bufferType}`; const bufferSnippet = bufferNode.bufferStruct ? this.getMembersFromCustomStruct( bufferType ) : `\t${ uniform.name } : array< ${ bufferTypeSnippet }${ bufferCountSnippet } >\n`; From fb96b7e4dd402b9d77695afe4503cf718c198828 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Thu, 21 Nov 2024 22:00:54 +0100 Subject: [PATCH 21/24] add isArray input parameter check for their existance without .? --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index c4588381b37f2b..5da257a01ffdd4 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -1250,7 +1250,7 @@ ${ flowData.code } let isArray = false; - if ( bufferNode.value?.array?.length && bufferNode.value?.itemSize ) { + if ( bufferNode.value && bufferNode.value.array && bufferNode.value.itemSize ) { isArray = bufferType && bufferNode.value.array.length > bufferNode.value.itemSize; From 4861c3ab91eb43243c5ef8a1cd2238b9bec48280 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Fri, 22 Nov 2024 05:19:16 +0100 Subject: [PATCH 22/24] add new example to show usage of struct and storageStruct --- examples/files.json | 1 + .../webgpu_struct_drawIndirect.jpg | Bin 0 -> 53544 bytes examples/webgpu_struct_drawIndirect.html | 267 ++++++++++++++++++ 3 files changed, 268 insertions(+) create mode 100644 examples/screenshots/webgpu_struct_drawIndirect.jpg create mode 100644 examples/webgpu_struct_drawIndirect.html diff --git a/examples/files.json b/examples/files.json index e70614edb858ee..6d22e10bc3b768 100644 --- a/examples/files.json +++ b/examples/files.json @@ -421,6 +421,7 @@ "webgpu_sky", "webgpu_sprites", "webgpu_storage_buffer", + "webgpu_struct_drawIndirect", "webgpu_texturegrad", "webgpu_textures_2d-array", "webgpu_textures_2d-array_compressed", diff --git a/examples/screenshots/webgpu_struct_drawIndirect.jpg b/examples/screenshots/webgpu_struct_drawIndirect.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6328251bd5ffb9ee171943449738d42140eb93b8 GIT binary patch literal 53544 zcmb5UbyOTn_XRq*yL*DWLvVL@celaak`N@gyUXD2PJ+8j@Zb)?9p2n~Kl|hT-dgXh zp6NYRb#_&quI}1X)$hOFe*@6vq-3Q45MX13U<3f(-vC(Ru9l|mmKGnpY~5`>NXsg! zyl+F+%8H8{tEeeU$tp;KO9KFqc@E}4H)vJ>0O;uMswOS=K}T2b1Kc4134jZL1n>aZ zOwHY#MO9Q30RN}mEdszy0Kgp6UtIrZvH$lB6bnl?a{vJ112|j6+}YI~j7`9p+sobg zFPsL(*yc8-7GPWn#*D7u27>XgztYYA!KZ&=>%TE17y__eHPpnxeZvOh57z&K&He|Q z+qeS3WjMiQC@p}FV17uQf3U@0*#9pKbnpPT?Qi?5hsc(Wn(E*)CHO-OkOs&C6agxL z4*)ZO2f!BK0B{E|fzOWM6gPkxIA84l@F)D+Uj^)C2KKTAn1eke08RiP!1Ql_z+cw@ zTn23ajjfv%2m9Yi5XfQx0L;ew`!y8+0G9{=yvDu1Kj*){zZL)hP-_6d56A!dJLLfY zJh$NVxc{b6<^lj{!2m#W|9{iWQUQRLFaQ95+1b?9^zVA0z~7KoRsg_N2>^hi3jknE z0|1En|HKWP_g6lka0vj=0LMyU0su(Q005}1!Q2M_N5A304*!YU|7V$h#qWI;AP#_n zg#7CO8#MTUfro*ChK50egM)=fMnpzNLPSDBLB&KzLB&8tLPEzy$H2nI!NEaB!^6kL z#>d3Q!TyT`0t)N{4TAs!gMf{Kgo6G5+unNt81R56h&U(+3;-ks1QZ6udq21{5CBLh z@J;tuDE=`RSSV;XNCpB>kO-o z(Q;*!=_i*j73vhfZflefbT&w=@Ur@{T%}(s8+{ES#XiL&-|^Kv$@PTn#c z`R@@6CPMRnt)0vKlsEZxyuroZaXHMG1}$%*tx0OnSdCXMS&+Tt{>bXOnQbDn%(|2P zRD;%Knk#@ZP&n(rXMV?vQO$4ezpV+NDUMJx>D>| zGN&BbtXaHCdt(of(tn&@@y;o{NfF4R=cg;v8h zI}@e(efcRH%~zH$={Q%MclD;owQc>xN3-MWNte~WruxqO}h*P z?||azdjZK7xHU(Og9Muakq-U2gH-U%`};#4y;)gcst|w8x?Umci{A=M(lX3(r(smfZ-k|iB0INxNYGL&I#-j zujc4cV%Q}zHeY!B@J}_QZ+u1yZ;fX6O0p-*0iiV&G5PxxLWeq4_NQ9I>(eE0;jy9f z9fl5ehBY+vxKqD<^kVXvH$L zoZm7THFeo~K&VZPKC{CY|)IOJgP+Wggq0Pzlp-kB7 zZ6Lj2CI`2|aZowq?$DRp`?T#=p7%MI2=!yfU-KdO*}XubS;c(Fv8%cF`)_jalRoc4FdAt?=`-+~x#t?|f{pa@b4KGkfV1pW{vhxg zF4M?&U_&8P`OqW7t0t)njc-2UfGm*U>G6r6TJb{2##q$;RCDj@Ah=CTD@1r|RiCS@ zwoGtlF~#Jc3OFv8jQZyeGIiI-ASc4)KUufEa?%{lN5)iAE(GWX2^lvm8#$saEvygT z>XsQcdT}zq9ligY-g+?8=*_c{&^Otq@YKi1X(LR=hnb_wDVO_SF(O@ii`YI5k@X)~ zsK>q3E7WG8&dpqyUQHUgQb`4+{k+R0xipzBA=4(BWT|}wF@my(hnvlPFRxUW z9v3T{5O3Gz>Si=Y1dXSR9sL$Ax%l2@5h`X0 zp*t&oLq@$U;J_|*Lx4L-KbQGsNWasU@Zsbh#rW*xfUBq8X{k&zM^~@e&7x0fW+ZH_ zhF7i%OKys-Ef?iZr>Eu1Km3^4OD$S$-c>bCWLn7Y0G5`*d|~d*mCY0_?i$mB>1Cg* z$E~40wBy#oiOq;gV1OSqHuY|gQKX(YA4=wJ5r0m$upfSQ@6%@1`K0>=@5`uhhAzA4 ziKU1eDEcn}2R2AE1YZ`FbFDDPtmZSMlv9QBgW{pS2CqdLZ-xn!W(_oD$ZqmFdWfB5_03e|VvMt}8X_Chz!P z(Z0E;W40Blxy0s5MeW1BhIWG-7f3QwUVY9OqGLFpgI1-*+Bg@0M0fakUn;b0p-H-r zJJ-`|q_3;@xwg+036v{rUEek_@~w|YMyqNPc-i8u5_FqXBx44 zjnB5dR!|B1A1{^VR+Vkr&-xH7(Atd~-EhAHgq7MrS0OEOEyfizQ@j%_BVJdXE}sp( z|3isVO~iKFBB;|%y(&G&lW)-!a=>>k=%g8VEhw#9WprU>1*#!*J)P}M%XmXv+-c-! z!%lX@fAX&}o;Z@9jQzyv_wXMs0Kq0lw{GEZc0#rlndH*RV{GlQ`p)8^|MJM9Y4=FWdPI{AC8Uf;gaU1EjA1rF5t8kXkI%6eQ)D9lDg_7Di45pq5eWcGRPgb)s0M%`Bn&J7 z3mXFyM+6=2qY5r1J2yE62Us`4gXJUy4CFJSb$nmCS(R}AVuS6>R5!34|5P6|IAnhK zRO{X+ML19GMf!7MIncF)ZqS$q|O#IfBx=Y?(M^}85o_1b%Y8LQ=56Gx`$>pE+0Ty z-;oR^3`q2?9Jz+*^0Tv_KGV(dM^}U=SKg>f4ZKeHaK{!_`*^O6RhvW(3FwZ@Gn-wP z)35f3xew8W&OJOMd~TEdUgxsU`8zp>2MA^2l4v3sG!kVbHk*lK znWDW*$JArd0BvdAkR*xyrT9(4;m8Rlk-k1;$aT5SG?j96&-yY`l?l0zh~d0`ZImZ% zVX^2kfoX;vC^eo_-AzMy4cWYc))75G(yaH=!7)jS3UqO6>K`E_X+(a0y!yE?iuje- zcyhigrNA~}d%6(8y(3Dm^OwUR%sS@54sfe}F*Ku3@kGnksp&jdd2V6QNOI(+DXgen z)JN=t|5!@IU0FF>?U|M`O20*tZPrjb=FMGW!GXR6grNr9aKYlHw(QJ7%=d zg~gE(#4vpK#wFa)ms2cfkoZY$;_@Z)2;o|F_s4daImNS{_s$koc&1q|mj4qg_H-?yDXkX2HdL8XxB(nP& zrIhFkI5W^;ab?fI-aN^nhT4M#b}Rd!&$(#tff3>MvAy{&g~Ce&Adn+%pz5-VX_laQ zG6NA;XTJRwr3?P9E&|9FOl4RIRgNuT7_>;s*E&PDX;{9fFlcuI66*%QwJ>Y$U}Lly z8}u(SefzrG?kFFd{VnGSZk$F-VEJ>2z2ce0N}o(tqMdf1&pBC1LRe0YHIQ+g+TS8b zrrPXraY84>WJ1IVmr(VNo}NY1*CIPsLxy^3vh$2SV^KGn zuLQ63rM+GZ`|Mwipy3aXM=0x|mvo8=PA<=;YHAj?xKeJv%DXJOAzbmAs6CFYypBi) z!9ID}jMS`Kt*ve*W!K-3oJ;xen1Jz0D!5F+vZKm=u=NZ-yrbE{ zGoBP4U#`#U%wa?e_o^enur0oND~c>6H-<~6lfj}zj-5d*tT#(17MU0HYGoT-Bq2(8 z)>!S6!KLHWam={GF4Kl%S7a2yD)oxkm-0z^y3$x*2u8VF!-Q96skesc%Sm%EbDUtR z&Ump}@gnUeGqpXB*L*B<`Ek0<mzAf@C{Nk$qmYMIKFOGRylWyAL;eCHp@rvSL{ssq0D(ug2|1TBX1M^7&{I5Fp-o~&JRaLC%pIoM zYHxipDZJm2eA66xl+M}_@}Dep8(7lr92nsj`1TV-`ik@oqP-kDuI4^YggVu?VIejM zRg^O2#8=rZbQM9jjztL%`ykwEKNr>W+0b!(TRz;~( znfx!WZJ(PtBLDQZ@G;&+K@71XBvMr?x@ly;8-C=gT{%N*@lT3XUV1D;2C5okMXZ#_ zKdgMn$fYdLv}omSGAgE#IqZT5b2$W3tM+V0k~4^WOnmr9Dv9=DmpMTYC0MsjSZ z5vp#nu}LzV*>B?I-Y5(l9}0Fl8-AjWwk6FN>=IM9IGzk+m}WDq7KAn*5upPf@_(tT zilp8Zlrd13xXzg1N*Y`e4QF}8&RG$H6uO?y4@jtgdFo1?q884}!Q|CYAWq*hlu!*7 zw^84Xx49z^2o)XXwtO2!$dCvXxOcg};=nuorBEF^p%T#Fdv6ulsW`pt# z`3W~v@tZr&NZ}mC!({!qH#EZ;%JyC9i*vQ@-3^*K-LWsV2nRs*kbj$s+p zzUACV=}`8o&`ZQk?b$6mb$oFwu1zs6MH@?rakM>!Lk?O}9v%m-+SxN7ryiOu>zVY? z1ijTm)97dSwc32J7*}%?D&I-^DZLe8P;fGpf?|KEkjo?oneTwldx5Y8e3CMk?v_ z@BNuNc3@_d${oY)`l{`%E6*)KNenkr4lWUe?45DNmK;)wTPCexkd4vahiKb$cV=XH zgKV2}G!s;<*w+j}SEpb|R2c^f(@%ZiQ5hc(jD^k+q9D+N^Yo#gGvNuY{T+Tz zaa$IqKjo9nde0)aZi%G6%6W$JIZ047y-wQbUg%rr(TwWK*+Dd(zA3!NCf}xw?pcp8 zq@+j?m!o-n2_9tHc@Z08IJ&g1Le+{Q$ETrPds5Ehogv*RKBYGNrutM$js)dEy~A?@ zi?SLz!;*Q;-agWiv)GWY+3b5gn1F56lx= zCEpRz&t%B6Szy(+@A~K=e9X;Tst54L(GJ|2_Zeh-0BHe#4au#<=gJ@19FSTJPB1?s zpBx{pN=wCHYdz=l;xbfcO6G8K33M%m82Z;DW-88(X}lDdVQFVB_wBn1BS-Ep!p{gW z@Q=h^uEBWd#X0CZ@MNhYoVZ$HW_faU?z**f=zRVG-;BV%Ik{M!Qxa*f2Xu(xP!Ef9 zSd!4~1A>-%z7@B(Jt<*~?%xaz+Vyp^#84*+G`yi+96T^Aszn37F+Av|=l1y_BjJJE zQL_nX0-_X}j1(fID0Gq~lO@MA=iD3oFzwkMU_%DxpM2i|h~>M}UP&(gLTr%_moz_K z3<8G_IrQO!?mlBYeSTYi8n7*W2k%XQ?-$_%r>m!T09gDAV*nr^p`oDRVg8c8U>ywp z2?c=0_=w3S3WKF;icRkFH9r669}0Gnx*2q_txFYH97+x~Ggm5c^`QE{1u=MyRT$za zxKYFQjS=yeM1NZNXPi1fcHMZPDutFu%wv>u}krR=f4j`vK7~;E#5=F2mcFS=S zG-YX@a+oXG7QSAlGZUZ0PBz_|a|b?Tn>Z?gf!sD7f~|GsM;Uoh2A#P{;*W-=*y=IZ zFcu8Rn(d32SB6}nhULPJy$I$d=Hp*1VK_YSy2mk!UqFX;6#o zADr3bXan*NPNlBN--J1wNuhr}BbLq$_|Q7TljXYqXnluHENh5`Hl^&O@x>-9jN?V3 zGfk|HcEP|z{fejz`%rj=!>uWU6bR~@%9Qr;a z&B@JgBLg|#W% zey$`v{nTR4tp+LD>K_8$C~QX1Ppr%Tg&K9G4{%n}Z^eQ`Z-L!p53&VnK>vPaGn*nhDs zq5{Qcz~`4Ns@+Cs#g!bJxh%!WVKNO;QfaLaAH{gM^KJ5btM|}K)LYarX5@C#?eWcM z4@>Eareqn7`MUR9y5YSR@;O&s6^jYa(Wy}(k1eRjxKxQudmU^NNpu%~0-~ekau_Rf zpz(MXc9EKvQ$Ak7T@2B_1N52?A2CA~RW}~kEVC=I{|eBe ziMAhhz6b*)vagf$bYpNA(g)`wOwrmRse642X;0#d5@wslTuF#N;)1(b^Jh9(AaLPW z=+im0k8{EZ%~8+8epv{eytI+uUo#6(OE`oP`w|Zdxce#2$SJ0XHPpg`d5WznR`-dP zx);DXTNq4W3(N`41akKI+Sv{bdx}wSrn~1+2;;kCkBu|7nU!0<1H!}G28%Q0nLISO zwm{Nk$oZjGAZ)emOBChKVCBiiX^nbxkVfDtc>NB8rAJ@(i0&Qmc=IAYH7;8whftTN z+%qogu<%Lc_h24y?*z5|OHJgp^;DlsLb}3E$gY34N_a@QiyZln4Eo^)CL`oVk-S#QN4Jrt-Oanr%SIKrvNwq0*c5Y&_xw_c! zTP|&q42+%g;I9?Ti7&W8HlnzVc!we5C6!5=PjCKJ2sv?CmX6$&l(Fvs(_+0%#s`Vw z3qr5qURi`agV>xpE-GH?avoY7yQntfD{|ni!=q#Q$!ZO)orhaA&Q>3)@Qf7}{p*?D z^H~3NxTOM>J+pst5;2qSYZaDKe&h6~?^$Kp&p$5M$iu6WQb{w9K~lx3s()Hmv-9B( zt1fWqKeG;wc$yvmvUO#d#MI=Zz77#e4A8Uvn9!l6-#rFv$c*^K1RMA2c@~3jg>Y+B z7hH$f{&+hEZ4w@_VVEEsL>9G;e3{x*i&&=Xft)RxLmA~*17~8y-G`;tH_p%vYhUmH z$a)mhNkIT4D3f`HS#lk%Ds&o%sD*~uwF=cp)&sI*2m3uH>U}n?$|Mq7}82wT3 zqxPngTvJgYOxyiW^jvVNNH2c?=k-mvZFC<|5`E)+Aon77=mF^SDCE=J1(C8jfX{KV zm`P;#&h7cG&t_Ae+Ev$+H(GQow_U{Ae>Tg;Bcd#{rP=CcYW=rdDJ@gdrrwdh82S!9 zy>k$+R$aFx9n6H8uSY78*smIcxrTINS_ZNsA6s3i(AjJ)s<)r%XJ>q_XVC>a)ryD~ z9_PVMRG@Dt5y(@H&SOe^v-cXhbDNA8I>43;8MT{`_Mp6^Kb4;v(|}#0-IfM=1(e1f zA=;z3<>nhk1&v$C3FRP_9Uh_~H1=jxoVTyos>Wm>mlAz^Y$l?w^j;Ayj)qO)mOMgi zt-?-TFA{Z!{q4VHX4|}v0uOynf%Os7t5HCb{5B=(L)W(ev(LcBbcrUWYv%Rjn;Hj) z;!m-#(d|8^m3&{W8=YZ3a@`yIe0Qm%|3XkJaC;h7Oqh(_&wJO0IU2CT`c0!k$yaabw%E?7L`mB5|GC+eLrt7IsseQHzh2)N^J0hAV=Frs; zNiRvGye7T&8Hxzcyz2v~jH@s14v(|( zoR`X)lp*krmWqt#N*_$`4sxff zhiMhu-FA`d?m>qp@co$YiJuCHJc6Ex4gW~|OTIrB$Kcjw}M#DE)&R&rbchse;L0ru8`R=j8&4zsT zI{3h@ks8g@HwXSBqd@C*Ld5JETc$K0#OUpEze*&!h*^MHlhd~m|B-$+SxkzVuYVxn2n>NxAc-LzYOO;D%FE3f%M< zj0VFMEIMr^0QGhf-huvVgTU6lrJy^pEgPwMObAGarQDu= z_VY{AM#!8)u>%sZRi;}3ri;#AtKji=y&SuCNRBtOD9$l_tr<7twj-8x;jkd$#Mkh0<_>3ZAXR59MA|vo!?6kGh zBK5&?lhMOw5LNVh+rZ#`2Mketq`|yBKn){Frnk5a&3N8Jxk!Sb?P7V6xEleokOyxY z6RkGmH6&fV5q*O}88pj&y6fw}vnqj%1JTlIT-~4cR|sPC=2hbE$iydFHq&m{bzLAg zugX32;e!zN1I#T)VePis!niXd3u+PlPQOS@8N77zUcQI}>)5p#i5CB?+IVg6OR&`^ zFZ$RPGt4zC_0*G;O6%`oFtDD8e+R+!Y!f&amcqG&d##DVt2FYn=U+!Y{-Cqf!Li%; zlu#YiLQ>Fy5Y|i7j-xsVHOvingqct%ipoh~jg=ur^Qj7UE>7sxgg%{8qyOa4sr0Q~ zt!JoG$)RN(AC)I}YDaAi(HD)ihm2Al<-G-U8|6Dmx>MKEi!$@x} z%4D5zv++i`?pNQrZsg$6X`&3zqR2hbWr!m>=<~(1kg}|g&6aQUihe8?-SL9dr=u>3 znyAFy+F`*C_p80S##2U3C!Yf`n)WO~R_L$3yN>`E7#`AL7x*KFbl9S~_P)n3{B@ot z0T)QutvyUyGhO;MB%=G?;WQv+=5oq1(WOfSCx81x6ox3 z5Yt7lumQd*N(V1}IchC>YL;8II+ig36&?EBl#AzUR+Tc6xCqC*J?+Y~qqg-F=95e1 zpK04o%no37d3*iJmu<;TyTD{wBp7-eSZ?m|lmxjyNJLkJWQ`vK=&c^{8Mjnr6gYbc z^%mWl+NhNL?5xH+J5{)RHSCj(T&=hmsUO$`%@XJ6Um`j;^VRB5aK| zh0DTH^+nQEw`u%bb(C+dy5cI^r89xe^1BH`w@M1rJ%-VGxvowsyAI|)Ii>uhU~Uvx zM}1OX1zMhuG9b5sk*``P2`{!792c8jL3Bx`FAiNC4U3x^mwG5OZPge~l~oT1ZE;X7 z(SK)zO_Um>a;~B%2Qm1VC0_8TyAe$sYp~`BooyniGVMUsLq$T7P!#7eYOR@hI@eFW z#@V4I$(!fAqMI@~_kefEThs=m&@p%8TMqsKM4KCAMjORWE{S2tn z^V~a?ex8!Y&%*Azm_+WT#8dG%ZQh5}deDM~a1CI174yWZ7+^hV(S~wW>TKFU9t)v> zgHJh9WK7oOI;(LP+P}16(Zk*Tw%TNg$;6pthJK>JjtT>v_Tb2kjUr7X&V*o%-Fz*$ zy_SzQQ727`voH93fXejIuiw6is;N~DB0Ly<13MGmbdM~PHruIj63JY-~`dXnvoIaV{9G#_{+GlqdmvA_FG$%l# zI?V&djID!Y>% z7EHw&IB~DL1lT7rK@14}n6M?x*pow9Km^D?&N1Q}h6VV^b{@2-rKP5m+ihNb>`H~D zAv4&;q@$Ur&wayUDM~q=3+eo;^wGU!Cci&;%~Ov zB!<%%i$7e1-{snXfYYhLv-{ve~Qkwi^K0+P=R80?jQnu})#>%NkwJIIo{I<)7c`>ayJIe1G zZen&F9fRT+*NM|f}pPn4vEYe^-53NjL*J9TPyeWsDS&DK_;&yr51 z#`5ZZ3roF=?u8Mv1CfM5ekC`SHbq^HB^9G@GS?QXweyS{4=N1__RbMDnD;JVUr zx^Y{rHmmD(Ti+^0|G~b>M}3e8D5Bcu?ai0rZW`#%brnjeZnAy%5z&yovg?3oUu(oH zM6Oz6t{F3XnHHgh)^igj4_eEF2I>28%*yMwE_7=li?_j&HY}m~a`?A-CLTJ!{=*}9 zcwv@JJ?}RPE1pAoQ}CNU!sE;~ZH;lgu8Q`nGU6R`3uDJPOCPd7rn{3ijP?p_4PKJ0 z$`4@atDKg_({8hU)ZRzc4C`AJDO)CpFr`#kWw7oW%aWxV*>5M_@t`aAB569U6l^S_ z%whicA&&J+PSveo7RvKYD)O0f)M+;!j@??((elgSphi(4b_QgK-l6Lx_n3pMz_5d^ z$F{AaX*dL{iy6*u-~o2l@^&nBNs2}kVwyLjUfUpHg|}PKfckjvFGh-OLU^nSS)3ZZ zItI4rA0UZA!V5aRv^4w5c!eEX+A+es=_iSbIU8rjm>MC1=RNT3p9L}a4seGP!|~2Y zL1SVmJRrQKmyrNemKoyINbyR8wMx$s@he&P<8n)Uh^^2uBMj#^)`Hs!tRiOb+V-4A z<(`IpOT3Pbh^vxrmxl5-2f41ZW&Fd%Qz__j^eEh#1rR4TMrb@2YcrfCSIAh|Jlv4R z$)TB23~zUa2z6r*#LJLqLYhMx^&!$WvVy=%LGQ-6eus=kuRhU=ff2X=NrUYGuToRu zRCKGv;&gVx3bO2I@hJAZdQ4;O9#$+tZNd|6o~@zG&D#kP&lb5!aiP3D+4#S1t!tBEKLkS%4S1~yUY7tYP>EWvvxJQ~ln)94^~hGmY-Z(rO2H_@mD=pV)9)Jj1av(z;5Kj4Ic`OQnwa*$kQlnGt6gLg+mQGsP9r378p1kD_O*qxwslX)mFpL_r5fz^|YvDpHQsEx@q{&eZO< z^C>+Li_CE-qqv2|>r-Dg&P)@pw`f#p2tD6~BS^@b`Df6HWv~B9X0%MAt5qV@NQ<|1 zDCNm1MKAkOGM{hPH<_>^E0ABCfKVjI*)^lGBcqO7#^0YQhV8uVv?rDQry+U*ygUrO zjd|?MK+D8zOr=NFY&Y-K0M~I1fR2D)US&7^pv32bm>7&S?O&Kn`jC-!RC6)^1%+-B ztFAcPVFLPAq>|$ct@$W%vPD*}xA7zya6ds$ty;1TJWU2umIu$`Q2$Y46i0L5{;jO4 z(w1`XSE&`{ZLer1IX_x29<-~L^QiI;2-6rFlM&SnJ7N)dX|T72E3Xq1mJJ_BqH4^` zkSO|zh+huP#MD}K$lAi%7LE?W$&!MAyXg~Ce)uN(G*=OMtH%1({~aJLme461%p3V4 z=JxF=_KD_(OdY(D!VP{e9Rdpco;(s1%s;Q3|Fe;T`4Njvlw9=>3^sTR#q_Vulsfd8 zOAaxWpId5_fA60_{sSXp>&)2Onh&Z?TIb)OSgj+)$S z*<<_b&i#v!Rk5@QBw>hxMSk(aLKgXNo70Pcw$>UzMzT@i$~zFPsMUDu)(U*_WAmvShohC&#Z(n5=CK;_r7cxiP=u^3ZDOKradb6T z%3ADzj}Wa1!JwVZLax5kvzKPuqFd2dEnlE!wGIk+JxY6U``nbC8-0z_9IitK*h3p*%y^+zgT-@kvStZPZ@qLv?TA8{G5Dh$s7LL z;y8mcn7Rn=S-sI3G8^xU8k$lc=!6SxH_lW6{5#2)Ib(ZMY;g#m+bWYb|AlWu2gstE z1ZCgZP5I{4iNcYQeTX#=V5CBb?(a2Rj>E-h8U3B)ZI(ZJ&e}a4ak;Gy-r7^f_J1%@ zFN>F2)rdphW{T!+BNF)f>-l(GRLhop^*~KZ%%J_-ABxNp?IHekZyew5zZ5botY2M%jMl`#J{jlYts4 z(%Ep1K{<4smr4u$KC9~nFc}&lN*q1E=KJXKA8#)2YG^75n%ef1_8q>CCa3S}To>Jx zZMBCdyC1)3Zqvh{=elVl6gvKxv<0SGj%-u|wFp`bj`x363h2BVY=dSvzgN6=z5^C? zhmEzecHY!bX!IA>sNI^!wC+hA1u>&EfBBp%lonE&J02sr!$bdeKQGFC*8gmyVabc|En?#K24gjHXHC z4CP%FC`ST>K^8}#*O1a8hJ{Ecr1B;r(-CPdrDfw*=a&*d^eyt&7-#u$*vmkum zx5M+A1g&1k$Q5Jn+?DlrD$zIR%ezrtKGxkfs1?OYVb4qME{kCI7Y!2sj+b)zLBl&h zK#dZj-ZNPB3Wd3LIIQ<|LfZM{6RhYT;X;&ee#B9lNKCrl`W9bSQqGvL8*;x~aG^|x zWXidnuby>@2cEi-zj|`I>Qgvq#D|+1O2dLWO|mdMyLY;)gB{u&HLh5{sqm6D=_?BM zlHw@`FecIxJMCOcE~NF|?w&B{t4*<#!@7DMtY1{fmb7WhCmx@oc^|yJ5PI*-x=HmO zBM_MHO>ylmW?cjj0PQuaZzU4PKVlo?Gmt;serG?)VMUNFB)2l{t|IYqXfG9!D|C+iN7u_-0XW|v}NNdLmusD+wr1Jhj~ z!y50~jW*opIeznHz>goL`w>S?=Dy+NUt5p6^2Z)35^*-vwe4T$)_9B{JwRyApjbH{ z4_3tG0a=QULplAF49RdQY^a#y#`XwktM49rSpj?+iC6^kF$Ulz5~m5}!B)OD)Zlw< ze5&@$=*HU%9LJ%sA%`7)e>!Y~gVf0kEwpsB_N1b`!y~201Qbe<11^?A`bd1YIhWXEPT&Wo$yPW5VELj5E1}B@Y*NxEF@TO3Iw#;I|IK1Rh`$qvFcX3Vk}N zq_kDjsgglZZGHHSH8fi4WFc!YULjDMTSrCX&Q4!5hwKw+zVNqajfx-Q$P`Eh(g_w? z7YABzaVJu0iK(Kw}QhCrK#B{ZY0Xh?*O~2 z1l+5@*6HIxVc#nsdmHxcup}xSqKUe7tx0q78s7}|HxT6nR1CfED%AOrzD!p+>4jAr zV?`yYW;~}Zc@T6CFOA?=sb$CS&Z`hRd7vA`B8~4jixOr+$#}T7r0U&o{N3|)^sA#- zi>9&73&iS1cSQpC53@2z_?NA_43jr(A$NL%&Un61jN%RfYo(GzPBEIUFDfg|ug}LD zgVrXoOEv0?B{the=mv-oMti1?4hT=`(xhBWKJ9gL5ix?|p+Ywn+cb#kMjpN2LSj6K zRr}>a_XGF4J_yFERMyK<#>U4te+CNynY(Cqb4PuVx4Z%Zughmd zFXGR0FJDxI;su8IK1_`b@wKKi77%bb-($7la^}a;YTNgFq>6n0Fhzp($_0i?~zlqrUoy%UO}B zFN+q(e*`uu-RHK3iE{XIQ*=a_tR(<>y%;FHNkrO&lT_DcmB{ZOc!OY#a8(lJk|AVx z%cxAP$_RbnIg3}{5(J(>C?1=BI9}R z4iIq5M@a9&|MBp)Tyld@>hxzLfEqN-x`??ZmFTfN|l zB9&l;iEz}lL9f!YmESgomwItABNP0d;xe2MN9vn@27B{8GHZQRgQXj-iT0}nvBh}0 zj6I|Y!nw8!JC_ z)--bBJv0&~ewlQ*a$(|HZAGtE306qSU2%CZ%?|am#Q!N}@tz=zJ-@9mD!%sQw+6{O z60%5Z)rF?2yFnca=l(3t4ZGyL&y%>i9_-uP@vYDB87xtOt7m8M?QNA^*O_aQMUV%t zv7Tz&b1X|0GsV;lT^Q-;`+cYAYEqgDcoTZLE!~kd5fH)7h@f5WunWY#6eonj|54QR ziSla&LXCw#C5N6S zg>VNn4Tl9yRX1@AQD>bCe8wSJSWJ#^OWMT0Ux>rB6gTxMHR4_C&HH^t({uNF{F&wx zuTGR^cPWOMHgAze8;y~)lAq>Tc1;$x<`c31@iH#$gVTy|i*kU>ptH-Siqs|gu79~_ zf~Ll??_5E7+C%z9S=9|pdM?>LNPjKeczP&No-utR3W_K0+>RGV(9wG>_Ic-8O(q^d zq9~8#Bgsl6L#BRRMl3fu4&sn3jRBUPYI;gs9tq7%)a zv|erS8pmnp#!|7^S?I}V0pFG9dsX3ynM3c0qA*5Q=`*WqV%eaaG;YI|vBd-7${|z9 zO7G)+j8o2u=q_xJL-~XGrQ>O-;M4^8SYaKXzQVBz=Xk0iq?ACHU`~g>-z8ubHA_IG zG7NVpoRMH&dYtbNGLfpMvL6a&^5nw;6_2%3uvELIB`a019l!)~rg`P->W zVh$EVrqxbYimqPfPB$~AydL?eD4cvG+9jhcY*LDTXA;uH>Cb`IC+Z!D(EaduSdf7> zlzyXh+H1u~@9&AQwSd10rsNBH>67y-qgmXnvUM`octR3NuQ1@Hi zhRJI8<@^Lpp7eKsvC?r%N6NmSny|fa%i_1P_`d9S0MVjcH%OR1kb;4n8Lhhjk6j9< znadmxB`S6n#6VfhO?+fZKVZI66k#7^CWUCn&)M>w{_P!*@r$K%hC{vui&Vg$Ps_6+ zXix;*b#1nSby6_H;m;~|Nj;LrczraY@@Rr&jLcY$__fj)-QtiCchRRBFVLS~n>>#J zzM4hD?Mc&QM{ z@AG1IE3@g*L}~K*Gg?Cm6T|at9rI$ux3r3s^pwwtL#%1!n(PlMKrUQT6|YSnqa8^- zHrFMy=qGaAKWx>pk@;}0^a6&GWtn<8fhF}m_p?zbM;cfwJe3f~Z|PI@*9X$7iD5Cr z6|^(OXM|U2GLFcotX=dgq_9#oWQfsbW;|2Nf-XC+^X-M{##-hiB2WJG_(sTwq-vlfC>3jRRl$<{H*C-cy1&X60D@JeY%KuR#R zcpq`a#EN?Fmvi2iGDkhr-XX`P1DT}jC(X5y#>_s$U8+2QmO%=p=& zGSppMN+?q4vms@8N|5gJ7H4wcs+NXglMVVU5XX+^@zAiPXq1M8A#)TlSkUJ8g>yWx zzh+&+RgLZG^@~Tq(dYa;ze$Iu$Trd!AX|V7)JVwGX<#ux3-Rd--X54vKDA z!7oD+uw2T*e+?I z?@<2_Ro?&|X|ryfWMbR4ZQEwg#I|j_W81cqiESGb8xv2Q`E$Vu1kG&)fKUzP2ZTkWgO15Zg~zs2cMi>CMXL>{`~p7-mJxy^ zX?i0OK$Qx~!0k_KCi`QI=bRgu&>V=Da^gPDT}J=WUDa5zt6CM&@2+TLf-U-{oR{EV zw^g0yY`3h^e?c_hOJo50bc-NyH6%;E55J`-w@VVa;}Bw%9LiH6G?x#476T*U6JL9O zm&TMCqL%HX^_1Ryzjum#xoy$?E`&{r5Q@IfO}!ZHX@f%I^!6KHwLNMglv`qSzz8_53JV zrY|3~QIkxYLOj@}72jilbyNXKa?|p=e^V7lHc;Lukw_0ZNSJ+wvi-(^M`!1${sJw! z^mGMpRcx|!!CqCQ7b+mgVQFTYT*0S;L@A3!gR`CW>S_Jj!4f0<8uwlbH$-SHCwP_RVHW0co;5v-;Y`d}fXzz13P zy(K}dIE*tza> z7ApViPg47{%sa)S@hAV@rN1CLe&H!d7GHaD;$IbgU#jMR$(q3-K|x{uBWgwgM$~(u)SH}@Nn`>(Yd~V-jRf+L~CP~z?%FDULT(>{|2zq|=`?ND0?*CO=!wdnF$BuaUl5Ec>W&IivnF12SdNvV zXqfPQ=Ao`c48wV;3jmVkWEd+|d!Y<&tZ9;>ebY@fR&zldc`PoyMEI($)vhxTv}_78B>y=q7AU=!~Yq%V!z8NU~bqGf1t$s$Jr zALzY3mpnosil$S7;>xYQ7fzyAL^xK=_uJwop#X;~TSiG4hJVKKMV)w0d47L~sP&hF z#g|dk&?(P^sQ8XL|AGJ^f=|B&&qIt6145g(St7gQ$=325tMEaGFnwFxx&AiC{jLw1 zmu?c$d!{B4AkQWrLWLCq>S(-n(Zaqkj73C4q3l#~ZLE?l77{DsBDv(1`9x&Vmp&#^ zpUJ4D#In$Szs=4|`(Y-e01g~%^NKm}-pkV?c@3V)LJHGKcl`@8KI^P_FchvYi|Q?2 zDe|d8m6=eO(7hfwbJnVD?Fg{{5b$^@0=d|%QG5on896FUpbDrlRV)-Z<0~89ARBvjM;X4>(L`qD8ZL-nn58JwxjE=|1V}CwhTj^T>#f%CNRWBI~ z=Qf`f&nBVyJL;r@=}JlX<&v1o6zR}7gXv8cj2!*Z;Dd8VTL<<2g48In$3xfO)sHo7 zinm;!Fp5#^U zQXI2bS8yCzj&hzvrhA@RQ^-AhSiGHJSkI&zzINtqI>b7T3Py(|6G6=zw*Iu3iyr$^ zF619W48OF!S;`$woe(c7$xgh0A2M4&zB8<%k(p-_dqju6K$W?R2k_o z*FuauvWrOT9sue-nCh_3v@uBQdcPNRcO-hY{ZkYoa|Owm?&9^1dde4PQtd4qNrj8J zV4U!t7E53}&LX+M_z+$0Tg>;H6i9B^a5*iuEt(B;SMC-v0czxd&K#KBz=p!pkRK0s z%^B*CD%S6vO8^5V^5{Ih60_&}X#HJ07Q3bPEk81TYB73N zCU*0&m~(nXQeqR3nXcmYUc+v0u?>KaczZc{91rX7V*Rx1&60|o>0dG9rGJ9SB;o=! zOkK23i2WX4HRVb9>prNNluPLl6K*+0?Y3KxE$k^SYkcEM#IEt#2WgLdL~eUtq^`Tg z=PCMpP8cGf?pF#-Gv&j6PB8jI%&%B8< z4^LN{5N(DCn2H%zg~pftMV+=5qb96mh-xT5n$Jm#L)1BzXpt8gx=msX*=7m7B-)_% zkwqWx!qGDe@uzN`e+nZKLKx|+N8%?D?ErEA*gHGERtjRx>O$lG&;>X`hLLn*n9!m> zWAow-nT=Sj8lr#1cG^XaOyo?uEgK`D7EagWCnj!Q;Z6zkg18hPR8Oy~k1`C44_5tF z4)hy>BTMd5%0Br~>^kUU3q(Bonn%18M$(Je?C)Za`gz%6U3s0-?Voc&KD2vdm-bT( zM^CHRRqvGK(fay3R!L#r7pW<7g7%kqS{US%$V^qfO9i@_8}&WQ==_|n3768_0x-ST z-IOT9ee+I;Mmsfz^U754zano1%tUwBz@S@`NfUK$#}pNw%AfNl#|ye!%CBHO16(*L zf1s`f(Jd}eAu#CU7WwI;;HEN?+d=Pt`Y=A)PypbZ+j$=Mh@u>)fTD#4&jrv8y z1_sno7jfy@wl)!YM<%j+{VZKyYYn>9AKYDxj4(xdnke1F@4d3^b1PVQ$Pk3R?2(>IG`=EVQc-MW@5Jpx;)t8fFwS6r0;m1dkJ1IO(%K)%dmcBy-ax z(NOKX-oMlBqc9py#@oWk?$iPq!PEbV^)B(VF~pMl=7mbZ3G`*zcAjzv*6Lr1PDDf5cLwmpkzi?n(^4j zW;p1aq2Aj?L0_6_wo{;e+KG;KXI6BT{oPx+B>9+Ema@-!lFf-MiG5l*l$9AUi+fqI zwH8}qg4co;rug76Vu#+Y-_NZ|?!6;CAR)(ZVwuh5XH@->69-d4`CZ$y&DNk&vw8^2 zK6N`>$3s3)JIiQ)NRvXnXdH!~+!i6Q$xq{&HJ$1RoC%hFA-Nk>uL}y`%PJ1NHk*B-ojZCcAs0 z;Q{gTtoR|pMr{`gbTXrTzqRM>!Xp$lvE#eGT~bce&AkBdK^Z1BcO zGi<6S)40lh>2N9Cy`;pR)G+q$?c0>CwtXzYtK5l-OmAmkGn?y)e$5Ui!>3`aF$I}Y z6sClQ2_W9d{ieZg+Hfg4%Wqm7x7J!Zq?~9F`mL?~M{<5?ele6Izx+u6GC}6{M@RaV zG^X<~+v(?u`}GYHHW`DND1)tkdVkEYcE;2hVI3)v-^oN|in9F$QMB6i9`Ye1cB-W3 zi%KwbrZj8sy|$&57-=LAyIl2^^NefEgz2Fry9MF3-p<3qMKx{hUA#L3#6nWs+_GV& zf-my4Ile8_z~QgVJ)+z9=FJ!NqjA9+yX^_;v=TMkS1Y1=ZZiOcugmAo%1UC4Zf=r2 zO>SAbBR;GV;pIrnw*$>3G%+WTe(9j0l2bc_<>hcn#%QSL(1Gi}ho1=XqV%JrB(&Qu zQfB(8XB$joy!^tOD98#?r1sBf>FTBqqpw>Sysf4;^|-}L^;@|w3j*@$2|Sj6Y~W9< zxA5AY+?Ve~WDjcgawZqCp4uC?T>Qca?#ZZiWhch>qXB1y;^ccMC;ZN#R+pDhcrN4S zfJ3Ti{y}TOLiaoFXRAV2L`g&&?g^*MLV(3{ez32VO@m~rAh>OXs-GuORs=d=j#dnC zZY4vRARe`uBT@?=e!v)*;r{WN(y!TW*S54|P3)(=MxgLsNjccZJh`6`bFbYJ%7v6B z7p;Yd9?X3RUFNu5kcUDNQ*5BdwL)}Nku#Tp4FVf|mkAvUJ;8(5f@Izg%Sn*NUpwWD z^fUjDMfk6w$Xq~wtM*0ePFfDUx;eWlN00XhF1#8lp(T#8zeUUJh9yhei6nf67v8n% zSSddzIingZ|QW_qJ#86v92_Ku&$)El*u>8rjMtIhzqiuI8*MFJrfYR9H%H za`r-*U+|AK82U_^S@g(yp`Mh~?;cJ&oH{>oQyQpKffnPdN0N4=Sg(b`QWHtMb*#@) zvZ7b!wm&r~C(V*Ac(sstR1xl(7pGJYzp>z{%!UW;)ns_qN{Ak_Hc32=Je|{uE`T!3 z1ZyLvmB`GS`1B{NS)S9hPk>MvaI#ZC#phhB@^L(;I`uhyG~?r;+L|4gJ6I?0cTu>` z`7e{>sCP7OmA8Lv7fb9^5&o+5Lu%$}@(2-M=qI?Pw45Dksg~@`u?jzp#<$YlG@yfT zkI-nqHnljAZar@8X$eQI#GK9xc|AJ;U~8{8#Cd73$ibqA9G|WJ(2*oL*=M6O)lPUi zlfND9i@6^6-lem9!ozPWt11CS8ZrZ3ZF6nMXTRJ()z( zY~9*g0w9ZY_Q=TGSTROMJ35}Sw2P^{hd1It zfnZpUX=y6~AVXUJ=|+k$=}jHTxy}?Us-X?%+hMYrEpSS+%)Aw)9r8M)?XyWO9 z_^=09?`@(8!jBn)TS@(S+N$9hNpq+6LyI=KYb!BgMw?79q?=9;>b(+788%O}Z2}y1 zW0MK9I^9OD0MVo`@8P~`wOfm#LsJ4*-r{(@#nL-^EZixZoVsI8CFaWq$rTg68Pn!q zFYUmasDcaUrV8CEo)4<>V0n9~rA`eiBqx=SMqCb^StXuIL&*_XNtt-E{$|5?qm@8m zMkQ3n&6IifbDPfEx^SN^x6+Ngk}Ex`=!>nc(ra6f+a;bU&P+_GTieOvDwSmq zPt|<1*|UW~LTR=P&nrx!tY(SwBl~~O6j-UVP?Co0(HmvMsFH?p_^ictpkVf`qc44F zLS!PP*9aX%*RI=U3e=LNpqE-g#e3g*)b`Y>ycTwEXnxmMuF?C^`Ts0VH0TfQ()EkP zH#g&)+o+?Y01?D5eE19U#vk#lZz-Bxlew=k?PR|YYojU`6U%xL7N^Zrw+U#r7L9-- zFY7g~(_1MszE&c$+vlr^TfX0{!HPYnAc1DsD0WL+4~=u;)4XHPjL*%nAXmAGrZzma zXhS|WoT_B6xId0@sugLuKpKYRm|&ykT}r5xPQI&QzL9qC*l5%bw{>=9r(f?|Svm=m z>8YvVPfQrF6}Ic8m9bmJ4a|~#EpptAM&;zl|lriy%`ZybRX$hwV4YPZtMeBKIldO6}(OI8!?s z%0|r)Mtc-lc(?;KZTT&^JeU(= z+)-pQ<1&{6fE|yRi5TBmd@K#(KcHT7t>#s-8G6)xWk)uVE8FIunA&PjGeh-+}xbG^A?@ULaGWc;8`Zu7m;kr-@ZN;{MIE?a-< z7ag`=*kwA<*t){29!<&aErgUgo~dZmwkWp{d?n95Png*A7vz(&!9F~uyMRn40TZQ7 z80PL;`mQ?aUM8VQ$|+p$m(UN2XCOhlr_DM>+xr=1lDt5*@OCO-aMFogrD_hsiOcu# zu3*;N)5D6MFS>c$C*OuIGZxiu(4QBzRbBVWE1|ys2U#K|q{5-7pZFqrf=Gf*>1qLdz<0>hof8T3)_@cOK^K+hY;_WF zE3OK7Ih!5^&T2)dZ4cF*MB#3sA46nD&!y|g8Fs=`NRw82l$0FjPWRfEHEV%|$5;A@ zQc8bX${ooq8Cs3~3;Tz8jQ1Ihy#ac8Sdp4F0AfGdiZPrDPFfZzSX#px)u=6dM*wd4i1sxS=PCG|U9=^0J zM4XfxcULmBLiEMba9Nv*E$M9-;cVQvn>AJITR7kL3EH(Z8cZ(y-HN9UOx#-;7)e&bF27@tZ{x3k*tPZ}b^W2o4`Qu7dQs=kCa9H#Yq`ED zcrBHeMU#+|(v)<0TUzV?7y{Dou>>x4A~B>btiD?aQmTg|5H@0}ObL}1jqYBqsr-WluN$nZcALz8Ly;`{5 z*L@&iRPt`%Y^tGs=%*MqV9TrKSqgt`rMs$mKR~rm^~kq-wr7kh!CL-S2u9UUJaqY1O!JkHOJ@5rMl8-R{QFQhE_xR?EbfFEn8|P>;3^}fGgQ;zF|@@P#ARl@#lKa z`IEe58e!gsKi`t-UU9BGdf}-fEYc(gltl`~`S|LY=>nGbVwf1fUy7<2Lta$-OwG zIX<}Ml9oeDbM%P9r8}*=;v^4yMB=%c)yk*ZCzO$ro{gWMuUryyBO|^_rV9V~m-W73 zEWBCwwSSlLkm>W0hG=bc=}}FuY|;)3YNg~;dwljUNqyQ_n0>8qJRH>_kLK$g5h=J~ z_&-x+?H|?~gwvyy=|%Y3Tz0+YCl6Ee|C+gRxEuLQ8|hJROaI`MVYN7%?27py^pYxwN0zAZTsG%4B>_Te_h3pdMrtpG^R5!q`JJw59E zDY811T_H5rXJQ*pMrw?Nj5hpK%$`EOl#NZP_P9x~@~ag|`(S?TA1FgE(~+6((@5S! zl`W=9n^+X<<{(6r4H*$dvOQ<6bkirvb}4(JG@~~dq39!|>ExRc37m7V6$HHmo87v- zT>;Fnv*&BB@#1FU2QRO^D8MsPdiV45;II%KT3f~^PhF}h@$i72rb!NRc)l&eT8Cr< z6C&s=_S`U(6pey}io_~&dFkX)HiB$e=rYbZ^`A7hwt}xi2YK*+AP3Rdp5M-nN{mi2 z88L}~4i{-{-U~+if1=+SIi9tTjIFJ01zmxEK^B&L;58+ktEAE4E*8_{8iN$CMl{{ROEs&voPGJDSEf7^e3+IuGRJVS%a6$TdTR@?6zRI+z$nleat{)z;PJfo({v+1s-QfOB#`s?l zB#KuH*%elqb%7Bn(Gkh|nX=h#W8c)7E*MC8_FqhC_H9;nRB<(@Urs8}!63K!)LJ$Z z?msw}{ENiE@Fw{KLG2C~v_9#aI8J%};cKk64?f7g z{RO%FvS4ZPrT}e3qnY4*?XCFa&ig#{`}Uky?Egii(jb4i z3%4rKClaLh44S$8o4d&5K@@|lYk&BvjVo}z%WgRJK)AVSb2Uh^RAh%QBek(Te_jI(PDugU6aZiTL z3Wv$rgz+Du4_GFwr4D;7nV27;kwQVtX2C6LrTzlDrHJ_%t7|fYkqb6-6%p||7(sv; zGw~M$X52bX9;~Wz=2mNwD?;9Tu?^-q-lRLmRmqcv6X>Y1(IS4|RrVmtO&G^?Vc=Fc zL$ac^KX5l&kWfGGzx+7jC_g$0g_>dL4r&=8YruvOLm@vrixq@BPb|#klGhZZ{}5uf zn;7@#wDaZVV{qP8Gy?ENAtuE^S25d?<`G?DVoeNP5HO)vfKf*+W3*&$)A&Y!2Hz$7}$K z0qJ2$xAAgp{6MDzzr0Q{Yn#vZ9W*cwl)BDwnOI>q6l@;!rLgOLJ9)|P43FrU$O1mB zHuvrLuw0BXrgPZfh4RA~$5cSo{zz!difxVV=Yc2U0&An|?sgal5WJsw6z!j+b6xZg zw*gqYi15r0`0XhS@Li9YB5%1l+Gr$7L{RwseV*(@i`3|h>$2kUiXiBJ`UpebuCK|+ z)6p-Ku5qNnq6Y<+uW9YgV2RmG^l~e@P-HnctAiiX4v0?GAQ8Zh^{BLG{777kC0cQO z^_0T*yHQz1qdvtrNJYNBoNEu*e?f*3F&1Czd1{%f%$9~gf71S(4j5zY zla7%hX2dQ*J*juFOucFz@0uJ|Vp=`+g%v|fCsH;w=jnpW0P%cfhv@(cRPo2u z3@RllDTREVz9+<_{OB;|^~H>mftYD6inS~L?sRin|AvSE*R>WA_ds+6cV$VCGM3Ae z7>SHMl0{z8*^!P0kf2ayFqta$s()`?S&>sj(36l}5z~Z>e&?~qE~ZQ%dHH1&{Y`Gm zwZ|zb$`Lf7IRWYb#Y#IUg~ZG=B8zV_wKAx{ijuwfy#a!>cqy%v&=onlDET#&6o)3b z#@{_VNN1lwW}8N-QT~a-&rvZW-=xS;mgWM@p-@?(se5Yjya?lonWS&f;x9=1WkRrZ z5G%7!mNIwya1Rt5vk19SBc+@-74e@#El!4gk>>2TSm)$hWDYt5F-@f|e;gVW)>+iv zvvD7q^c-j8I%w-}_g=~Y&A;Yi?O}1PMcj~9%iLe{jS4an-~FwJ+F2BZXhLpO2==7a ziBS}jo?oWZVNsLbk7misombsZ>0S?=Z^#*dai;C96fgNWM`&OdGoEHynUD)*r&`d12;M z^K7sO-SXvn$GY#VL*p`sa2vo*=N6;hZB!6hl_t{EbHD)x_kKJC=KHQNIbX)l)6}3C zFXxU&*lv-m*P2%T^&eJd0+=o%tfI=qPv5z<0fNzd{P+TX#_!k=*x&5WOrcpT#vgF4 zVojv{0Y>JsKa;Riv(m?!VR;fbehG;0w|e4yQr#yo5~>46k`7XtI3(uaY0x=z zt)u#a$f?rPA+qc(N1_qkddsp!;KxIg+33~BAB;R3m9Y@-G~*9|x^QT0{r*6iDHz-m z*YZ!GN6+UI;BMxt?p{3d>{3#`I{afw!?Z7wqG zxR5(dVVCkTsVArv8BZTH{mmT1VEkqds7%-AaT`@_`LQSMzBwSd3R961OV0e6tIymc3Or_jgc;=8{mlE;euj0t9 zQglgMcO6qxy&zsNiQc#_cVXxsU*@UWe)W|a_1NE;Z6M1R z?j0IO0xqxJ^x>&@X|yzxBARewx)k%t>Qy9|lU55P$I{Jx#Ed8}!aPTP8pWaAuFDdb zsBu&rwpAwCtZp4|c(zSQn$0VPRUR9*zpUZXlv3iCLhZ9SH~F*UgA9*>YKEr_LUg|I zFNh79q9lDxTl4CoMI+jeH+b&8big()IGne3=2F=yP#T2ciKGB9uJrWuj6}J%}(Mzqd$Ke z?B`5xk>#nLOI)B}1;bqQ1Oq zq73`|L_3~8ye2mbG;BmI_j&7rZ3eX%r*cF@kPkiv-AIp~2ulrRM!53$HQLBIVRi^E zj^7ln*_Ez(6_SZ9vNU9!=qg_C))r@@(P-r_>oz(Pz!Zj;ZEH%bn(W{B$q}+^aT#Q5 zCy7=|yl_r>;4$^eq$oVy*7A|ustaxxWi|0&#) z*wYw6(bo}hQafpMZ`rpCDl}S4TaiA5--@h$`IXA^73|KT^(LuwMNN6!52Pk9lW^@} z4wd!cjM<)XJGhojJ!-F(TI6qN^4Tm*1VyMQ36wdwJ9v$uAkytaa1xjSjc0pI4~CX;lqS^pQ>&o()lKsLaEzDX8F-c$HRIA1LS? za##F)K=`eI0)p&+T$4~47U$P)cgncmCFV|Uv!|hD_};@HM@>p^5lzhmog<3Xi|x{P z;xs^gRKSh$jUft}&;No1!&byx5`XT@L6f4-S-%}{h)a3$_x{>H7N|jwNbGUwZ5K5T z55IS;j_XIUoSG2ooC(5fCsxOkEbqZ0pp5`$*ih-%tj?Mk<6RHKK!^*e(AOT>4btiX zDvh3&kPa6D<3Dyy!I3=yJAbmdKYm&${}fjBbWASL+sN+*8D$AGD^_1Jo2N#~trv`U zfc`=2T$ed8nd~2*Ydi5RGvdWQl?b?X52nre^R|dUnMuv~bXwsKFx?chtpm)kwL5c zqbyzdA7m%g8_r39pawt_+;4~NM=*Z6zq`+_u<)?9`s*6vX9Fls6Mal~2F)7M4uFEA@^ z+`SI)WPqgx0a!>VT;;g=WhULA8pFpE@^f`*Wah}cwNTa~GYJuKNGgE8^Q{!!2B(xF zfqY}{S)()brF~?9RD%Z|GKCmiTP-JCu^GOH((|qO@|2-|LtDln>hKX&(XnOQ&LWEG zNCLYPf#r^FFR#z)!UMkutgowaQOK9~NP~>SBR^LFtPr%}NSAw;mqDN{#&6Z4Yberk zbbZ;kCzNxIM$+=UWmg9nGW%TjZ2n7o#o}Aci)iuWZP+q@Og2OUo2}HsWq_gKbwWM- zuT_k2m){Lmpvkm?+=R*O6zRqX45GSL0+f{zkP4Q?@_gVe#1Q_7NTu|HgnW!R^cU4QIP-3AB zoyL%afh~JPC^@!pR$u>`wcmFQ`NH_#A53BexW%tV%eu-Yk$>x$$@j3138#Y?#M<$m ztSCWPY-Z%fD|ikhF;wA9e2k6EAeZDIX^Mt{TFOM(iA*Kr63?#Q)znmnR(E9LQaFPz{c~R~9tXScM@HL( zK2M%xhBS0L6{7?y7LZtjizm35;I2$8pSPfRO=}$Znoi*m8oxdcN3!Gj!z#V|5&<;% zLPEe85;z!YFt=Ik&VgH$!1Uk~-nF3wu-`TMw(^E0F)Fk=#l3H&cJfAe-0V4eo!NrS za-caWUnR}l0g<9Hac7<*2clNS)$mm!r{+Z+_uy#i#) zvOpFTC_w08u^g%&vY`!|`oa$5*e9zifMb97;$Q}p1vT>5W!zKHS|vuG)oncovSCqA z8&D~NC{;fx|3u=}?)`Y3xI780q4vX`1TGShh6(8?QzYbl-LGtg&FLeZr_?a-Dez~x z`kT~sOmtZ*-`gbl04`N;I0mOx-BrMQSSlaOg|1x)(pH8FMTq;{D(B}qJK0nh8R`ee zeGrMBo2*zLAd%5==r%r=w%*mga%cb@&W*Ci zpXYErIAX7woN<}f?Y)fLiv~Sn#U|VPa@$M>PC?-jM^QXMF)eX|n%huWe#|_2n9@2B zS+`ONub(sN510Av31C|rMiCMPY-;_Dt;9)3@T-!PzlMq&#yo16+l9OU6`RN^yE44Y zo$U27$*!6A9``Pr|2Se9HJZ``Zl4QVQUN}uf2m5P+PCxxc}G$WiYA(bBkKNnD7H9p zX+RsQnh}Z_f=?~-1sH#?TM`7*+@pCH17q&|7o^;Qnbh1sc2)aeEa!VMuIXxZa7y3i zs?T=!o~U>SvJK&KzONI@glM5?I;z#bjgaa9axLZ zBGU1wbVYyyga*PVG$Z+7G<4OICgmWF|WUm%EYN(Pn9Qp1d0DO z_Fm9=a@=;_pWzqu5S`KO2H0R|{pbnd4$;ynB1RR(Av9M4=TJ-Jnb6VhLz+AzJaW?| zzY|LOKsXd5$7%-ZwQ@V@fnVKKaxkUkPMxMsiWvk+X@8vURTamP9YXD~m2r=dKS~=d zTt=`xW&9PLTBCAg(GD2qjpdbe0|J>3fzm=4yScOd0vtZT2^UWf>Q0a0)+J7dcS*B@ zOSC8kBoY&_4~t|?TZMXkr?$fhBh0W@B>x_*{7iv&&!LoJX!TE|{rl{3SgiZmYPkyz zL8i?EiqQHqtU4Z-*8(AISmht1GK#tHyO}s^>d96`i3*4Rvh&Zn6|3WBKwsdt;DUNv zfz>s5HR;jn@tRrA{jkvlqyiC0CT8oBuoW&XTf_nlHVGT;O;sdQ0d7~-HlPg<+Ie93 zonzC&+FRO^Cgs3=WOXEro%54YN)z8~cV{&BfRhsfIC-JehG|GEgrN9&=UMF4K}n!C z)vlL&C{=|fURoUYxsbHix^oAeKld;W1!gzBbvPbhzRrq_(3<8SrM`94q>w_oqh}=z zZM?XWQv62)7A5q=5v1@g;fw_h{^zIaFs=Lwl4o+nJER73jY|)*KeM)xeaD2iV8tqt z{s2lF6!P)mQqIUPRD4eAxC3SxvGpZHu zPvO}M%m*m(w`;1S2sfT@Z7DxM%hDFJa}RzS`JXkt3_pm9c@{!mr}G~yx(tKzRynJc zWeyY(fHdahAgP2vkMblFT&_sHk2-db+(29#n`t>xO5M_9I8&4~!VI+v3-cnorSd<| z=zKTNKO;K95W|RQIBmJgb>N0Cj}jE2IX6d!PPFl0`oy7Zr-}x%w=UXO2VqokMteg(5-}2R9+nIo<{)e%k{<<_ucp< zmL|+k>8y*fBL&XX$Lyrw`4=f9EMzXsIL)xE+5rhn zUe$mw49611W!nitFd=p$FvKqubppyLHbP* zAc%rfU~e2FN$mZYAR>@&q?Arjcx3c>>W9h7a2m>ad9u@Rg$x3Hq&87kFydk!U%F%t zszLRa1nVu7#b8f)kb+^htSP1LpN-o0FP*wjdLgreW4R`kBl{oIu&bo=3)vD~`1{Yy!?c2HImEW{(|5;^U6A+TZF_R>F9P_@#mmmSFEc6M;NfW>p!|LG&6gH7BO6ElD7G- z^pk^;FW#~2Qv?SlknnV5Ykw}W+T;DpCmqm`>&+HidgCwo{O`03Pl2DZb@c-N6l@P+f z5Lq|nbw$DV|Agi3=gd0dU0mIh$o=;k?5k(ze>bYG0Q=1UNtF(r-8*t9BayU1@$pY8 z3l1R^L~*Vy{cF?hf9{$BR=KlA+rVn%CFq}2l-k7V`lZwqp^!%b|D;Oj@6$*2Y@v@D zBUN_#PebXj4A;a<Ihzsr{2G5thjK zxa!8Po*nDIhzwQTM8yhJbnv(0|K2irsP5FLij|kVlOjvHlnNBB!WPzI?X+#Z7%3+xL&-777Uq z$p4a4^T>NQ%D4aKrv7zC3G#=iK8g-^>W;^#1}uNlUl1B>49_a$I1I->aM$lkr0b;O2x2H*J9S-PH9M?@X1e;v4WwR}lmEb#TXdWpQh*r%3d|K46` zN>Hlh&u6G1?kGeI`C@ysNTNq!%$jy{e!A#dJnKaBxTL;C#GMxMAl zFMgw_-@&l`F7xyy!CLZPO-RgvQ;!)tjI`Nmq>~KWvS{Xn8v%MZ>ffd`ZXNf)AEDs` zI3_eV$iRxx-Hyq%ljn zUvyx@Zq63)D{?XKvE_c`2zim7-3(j?Vm$V_-nkSS z5bmm@*O*>pkjV#u);`c7nJI7hpiZgIl(;gy<~oa@o>i#9tYJnoe}F2E3_ddipzM#X!-}YxB)2u@v5P0HFvxHuV2A{TJLEj)XiE4&a}qwpB;9Mjc|9H$ z@0d9ieY&ds;WTGrzw`0=F6Cg8wr`yT+YT>u{lx7HmHc>r^0s%bSuC7L)`^#{hJ}aA zT1HCdfm_RqD+R=viStJSQ)b0h|Au{+-(U?de)SFF#tEvyS>OzT8YD)d)kv@2fQ)<6 zfH90$qY2G8d4FIN6j@6_v97qWYjE~}%NWEQul9Afaw&4I0~-#`yPnkn(+V6J|KvAt zP?ZT68e*GSB&VeuX9SgIU?oOpCnsYX-#XPS8G_jhkJYa(84zg!ql`>&LdpCz5d6wa za7-mj$?K8D`c}%cHR^lAjN>6sv_e4;3;!L`+^(!ki;xGl?#B1w(}P1Jx`e7BH=H&Y zQGIG=)p(LAjwlu~GRwky?#%RJ2bXgo3J_xDr_Q$zv!RSmF(Vg->~Tb{F*0#@Q&WUn z+>wscF*g*!){0@&RX$a3J23duO`#hJ_2^5CpN`Jf7^vJziW?D+Da~w+4e8)WDv!<_ zDt~I^n`9u*0>r{rOGLOfq#0)6D>lrEpAEm@)`Rs42*9n*&7PFq(@zVHv@)reOd+FsfeeTH3LSM6{YaiH*ULbL=JwRJwCh z1eeV~3P&9XN>c*A*#*(P!oAOpXgr6fm-hNJ1hzF|eERhE=`lsIGaCH%p<;@SKtI`= z{k&Tg1oboweX<4xR&R)SEAJ}rd3(qiN!@{6_G8v_rQHxRQF;ru&}M?lI2?hjgrr0t z4QVwLmS9#N>AGnZUKvE>j@3Q)wyg&WK!42;ja((eBIQGf9(n5Y`h2kP!?fp=0(OM% z+qeg@rsx525NMk10Tn7~)@DFZ=hQS&FR#DWu`);eD^R%Jmq+< z-9$D{i`N@#2U+(14xnDz(J^#+z*W%Lz&RwPia`&GtgPadDs^AFR%C(?dx@5Chw^O} zR;V(j$G~o^CZr3RWuYes4z>!57}p69IU~$e-6#nZMD;WUW&B%XQ;dHx4;t*Uml%xk zhTQGQ%B=pLnf@X%Gf{6`+UPgZJQ}1bAtFV2%Yob7YN9}*#M@(OkYcQSY}@4i@FY!~ zEy?i1Lq;*i<6p_fNv-i70X1`WDn7zNv^X_<9g`SHsTRtpt z`hGP=vqMunE(-+n+et?)Gkl**AFhVFT7)5(C>4~^2n=Ksn7~>;E4uRZ_ruv*WGO9- zMR}HC3}C{sVXg#7`fEX+6wsOV$Edf7Uu-Si4#o2zIJ6WrU)BVZqSOeCVjwxZBq{-_ z6IlETqo8})7IPq}^8bv9i-i$=)V+DX>?k7Vd z^Yg>n>v6}eWVF4B^;AB+jTOMbQegQs)U(6b8LOwss`l~0qEXg7E&c~p#RDK^D4cXX zu@bVTTxA@!A(di>BAKCW(&gA!x0yphBE!YjoE z7z}sf{r>&cmt4Lpo}d!Kgj)Xx~j?8M*K@5@WSE`Hnti9w(DXZQg&1MPpm$LV*)ZQ1hw0P}zc zMnw`z(+u6P{BTLDT@x%Mq)Znmx-b{59|=%)aY}|=M-d7bOal`$y8X8Ajb9)ewFV zbSK>we>}~8kj7>lzHs>6$1CRYG-N<|Mafsvap(aJ9>HJ&s&8eGD#RI81r{zG6BeqO zX-w|Tl?-TL8Fi$&NYcJpOQEQ18pj&|K*3p_iI|Qis{IyHi!v}>eDX>|M6##Hjc1A@ z0BEiyeff;V>zAi)!63QBM_Vuo$ro8vr?B%#9WgAKj@+_J*hKw)ogNSMz0=14>} zs{?RJGStReeQHsKh{;Gj42Qz-<@^B!Y72)7D?_?2F%Xy=tORQuog#@jPVlf{u0ll; zvBTSt0ny5?3iR1xv@^&DIZTaW3YD(HnTHq}$b@V@k8~D{IOafwlo?#1w`%YYW>5x1 z!mTU{WJf%+prUzLS3<)*vhvL^xOjRUawiqRd`C7 zW?VQk48X=yjfojCz!u!3)u76>;&dAXn}m}dyEVYD{e`1pWt^#m%r_7wgjK?jh~+8V zXI!Fa?S(7#+M%Bu)cYF5?J0rEY>qZUX+^&l-+SW3qXAs>r(WG-lZPJ5Soca?Kff`F zHSf-+oj2*m;{^|d$UV#n>BZu{@{S zH(SStwzT355CqadGlcArj;-LpDDj#dpU%9zWaTh~$}G#5Xd!{hLx=XA`|pz&dIrY782vmg>bKhFTwQ&SExKJ~7ro(w^upKpAo`7A}cgEa6JzFYsZUaL=%i&=@-;>y0?Uw+k4z0B%Vz^}#8oMMXPvF*i1P8Z34Dw1o3*)GQQp_A zcl|et6VdNiXXD2ZDhjV81|4lPGcl>G`VGHYPFpW=5PqrmpBI>gU;zIBw(h;>g$EKp zBfqR4`g0rV=_9)5GvE5<^aSqh`tfLJ4P?S{vo0Z=eDYg`bYf>d^)cRG951M4t)cWK zy7$Q^q<8Z=KkaAqndUwj#UP5cPyx*IFIRy$6$lbV4g@@cx%_>zo>Pc0zG~s{;}hK~ z+vp~#muGTh)2w(ATTvAQ$#8DD@{dR)terYAz-5E3_M-7~^wx}V39*RL*$$y|kpfoB8UAGPwa4Db} zE_Nlfj6w`2*7x7;`{V7)L`y*CC@OW2JQ0;h zK$(yi)xV_*z=-5WVs<=Ai%8`&3-EHYsl-QS7oh%T&flIa6FGIS->mZ&z*V}zy<^8G zzQ8R+h`4N#szWrUfjtIfdV(j4gaE~=7vJ%CsXmga%@Nf42g9vP638<3Bt>WzVCW0e^nq zj!U2`k3{Xw%4^2nW+054Xd>ZMapW9lPR@CLnyi#=585c52ACln5?~B#TA!rTMsPY` z8#k+Qyz7hHQEd90aM6k8i(jMJ;{0&4)JJY6J;v*)!64ulx2x&vlrdtAGz(Y^Ghsmv zW8Q4(iICrl8T-TwB-A2eBa|2lp*O*5VmNTB5UpZ>FI=R<1?k;qsXfc{eVPP>ij1mI z8`4HYT3BPB=hOW@FYbxpy-N&VYWnP%jj%6HU=e#aIzdX{ie8S)3xf3 z&a<*ETgPYn;eypf>;VO?87dx*Ib_o@MAi`~pjAXO#sCzw31JFW<_~KeL~G~`Pl1Bz zNV$0aZ@M9{%}}Cfrw4%w0Yag|qKk};iIL)00|AAKc?M#7$26A=fnaZj^?N$yP&@=K zL%O{YSgsoKS_BI#3bPGY-gwv!E-0sMxqOlPa*D(wky$Y9aFeXg4{$?I-sy36U}peM zbAHe9yliUq_gE`0>1W zoOD8dP3tmtOXBd@1i)ZjlO`dX`(|5Wa7WIep;YS+2itE7PLlE193ZHMfo`hS6b( zoD%itfnzX55i%VPKCk}(USM|Ocjf{8`BbC03-dopf!K3D z_+C4|*ICyGPzH0`(f=3iH8U8%?db{EV3ytV#`0s=> zrI5X|(*c_13;`p@43mby&izy$bH^05R4na z{Qm&o97!b%Z}vQMCsPt9!m}9x>pvV7KmbzYFnrA25jy47vOn%`jgjI5tmg-BCd9zF z*MErk{&+=7IW4d6l}{6;NroBLLpWHt3%$1LX9|SJSFc>5(~jUMnMW+V2)}oCkO_y! zzW)H88Pa~7=WyelkHh_czG#@~@SJ0K&gz_jF;uyA5pXNamKkZRBgxDP6kS>(XF?d; zpkTsr;lMVF1-7p1t6Fgqs#C1fbcnJ;%~Vt{n=zDh0@EasxaMf{QB;&$C|?`VI95so z(r0>GY;g%o&G@Avk`QeiWpc#eF~&~{_1<~|v(!?{7!?u8CWnNE*!Ha zJk@oW(^SPc1`s;U);h-d1CBWO-249gR*9cnN)&tjTw%e%1$mTd@2|0++vkk%u~8~v zCDElYdg4YJ5hA%8hb3{N5I9qgC;?=Nag94W-wOiE28;C}G zA#Sop)B;*45RYo!6|5mp42S?UsUtjcV~7c$)fXltOd=RAotGyl?!ZlFH|BvjCIC|! zF80O6hes%+sm@&BuhZ^vfng9bHRwI@oF+vj9GEV3!*06rK&92de114N!ECQ%o7um| z6e2QZi97QB6X%pB-m!fiz5O?!05))Fu5ZHQUyc!(v+L{c&5Ahs{;*SAUMz@$e<#0# zxx@iShDBq_!1-MsT^vs`AR3m80I6kVqzXH9C}gOG*lOF}O!9FPHr+j0m_f?-#p}N; zT9+l20W3~UMVCSbsEaQ9cf$mQj!s=*u^4`Z?P){hD7i%en0y_WgB3?Ldcqwr0b%QI&xmw|uoxQ!Kkz=!1wJm2tlZ6-nhJ|vVyF+OCPnsdPkZAQxy z!@jJug>bv~_vHrfh*qyEhhN|z?VpbS0PhF>I96~Uzw`N%{L&#sgHz|B^>3N}GDkct zQa|~F^FOcgw;leY|HJ?&5di=K0s;X81OfvA00000009vp05L&PVR3QUEg+7Q808yi+>HKDWLJoh1JNmLZ9Z%mYl0UL;A-9l4cA! zL@NH(`{{?(n9D)7!CyRuM9G<77hZU*Xyz>RXY+~|68``|ieQ`UTHXAc;K>sciYXY4 ziJ=nDtO44zV6zpM0*2TmJAfjuYA5~}mE_w00I2a2<={3WllP2Z0eI|b5_1=?GMm9( zad&#wuh-i+*g(X6X-(Ce);{u^BG2`R&F_CdY=DxADK6o8i8syll+p|Gmih*Qq%W*R z%^=-*KC_cZd$MQK6u@N`>NtuqyaY!E!a_7BVAdf!Cb2{~`j9*aHC<0%zY+av5PXgf(1mI-|q5}#FxEYZU?Gn@k223{>L91G9D*L?g5+i zh`-J{yoQDHn4b9Va1eHY zN_|froMQV*G|2GLnC@rB9H3Z+Y0=DXq2rBUNI?ihD8Ggd#Cyn0Q)rVAmJEqU2HtRa zMC_WPFtC9|>0{CQ&xEHxbYdwk0{YO&+c1=sxRQ!)Im#9*;gxT*ABPB_3t15G;DGd)yu-VjRq z2_U~0;ywdS2@ok~V{nNq_Lm^boKz-G!?G$pFk=B=rMnqGc?+2%h2Vkc-582etW6Hu z(H+OmH8C}ifm>+Qyv+BB4F=L0AcJC9k~E7n+|)#_G?|JJNG2|07{SVjNjZd6P7wUf zM%yO2n0+0`ya&b`w5&|GMz3dhszgAEgsNelmG<$DpmE5XK+v@H_QE!(6p}$0d$4cB zafg;ci6&7I@FBzO18@q+jLOWAyhJgoau`D)Ac)i(sQuu!vKC~CsUmJ;%25}TY#S5( zhqQNCK!UfYk4GAr*%gt8{{X%I{{Y|Qpy&jzU$KA((1z0S3`^-ax}nly%pu=lXL!0m zPK-m!cjX~hn{wk-mpY1rL-3Wym|X$d4+>Uk90k*IK`5mH&!37 zzCg?=+`yE3KS(l|hs-j3SL@bH`c)joMEHYG*EYmPiKlcNSMA|=wb_DAPAB_pWDK(sNfn?Qylto7^P2O?aXoON2VZ_ zH6gy3`=1}jl4A&*t}3O98zJ=t*JbC4Aj_94KeZu`bQwhoj!_n}-n8)Dk5C_E9jOf1 zqk#>Lh_+m*MDg0P>A|%CA2l6&_ks#jjR06JxrXAmc!W`sS)bkeyTW$Y$49;O#Pr?> z6QCO+KjY*&W-$quO~&-MKV4(c2}v0(tWZpa%#(;uxn#QwqozG)VU8)qubI?*>jvgc zF7iawk+6@pQmEy)+s~Isvx}8YPRETgt@=l*c&LsRNmGcTUSx_R7^Wgly}f&nwhkPP z6~B3?lk=2jDDLH*#l%OaIM4%0JFl!IVVG!f3;HewAjgQufdo`0 zh~}~&a2k?JHxkdluT#3n(A1Mbp|UGnKG-=17i=F-6Ej~J)2uym>bG%GXE^AEqdcIp ziSa5=F^0mU-7QUzh4{#z6sUGa^+@w~cs7qHCWEweLRXDoTSP^Nn%OG{M%gWpCP7T5 zoprx@z$pO8fF4D^VedE0bYI>Xo;j}=H7GG+7=IsqoZyRgG}2vK@g4IZLg7K+CKP5M zi;1?0i_`-QBtc1b6wp}S0=+64K0W^c-VWsfr+X*KO?2VXC*(J+d=hI}6Bc1H1>M~D z9$>?+nxuDZYDt)`y|xfk8ycc`_THha0Ch0{gXlZCc!M6L{{VmCNa_4QEd~-nG!6IZ zKUl)nZ3zmAfXm5L-a!N{O+ARF^v0h|Pb4XWlsDaV?|}tGIQ8_5rPke#B5pmW6pX;W zG|Dj(6mWNefe1K+< zYom+QdU1hjs*J@dR;BBpLfKMqJ<{$Y>-!mUQDVJ3O;h2XFtNblzEEead}|S6_q|m; zc`FHutDisfe3gPj6|kFJg2nSi7_xsQt*tct#||0Rgt${qV`R(KYay*aZ_CfF1Or4f zEHMk!y6fD@(h3Q+>PVLPdhvx5g!1!u^^VLCR_bN{0AD`Yst5_@WWR^)o8^8mR=4=B zKyP_%`QzF#4RIZbu9Sz{Ja7e;=3{XLZS8VLWeZb;wDy?u>5|y=)t+pz$b_3{K?jDX zxLzu)8OK9xuuQ~7{xv2~P2@Tr7sT+<=`#3v2w^p8S>&5oo!aq@iR6e@c%J>R!ioCM z=!3@R*9KQ0TYwZwiBB`XWGWP>W=Sai-q9vH-J-m98&DcY! zFiR?3Jo6V6HS}Zg`>ccOkd7 zY5^WC?rbnlu!=rOuVjAM$_df2Qdq3k^v)sYL_7wrBo!j=nxA_*xm=iZ-QX7c zd#K3ZASf#3@@Q6KW;lN>1b!hk9zM=Zs5r!PfXR^y=wzso?ffZ#G6bo~m$nP^KA2;& zIwW46r;hQ+n?VsL;%>3gGB9PxfQIM3CJp_1SS{KJ{2F%|q?rhNMcZEyzXO3V2{BW_ z6~#}L>jP7WBf(8K69yTlq}UJN;&pJS9U z;p8%3W(yEmh8rMx--t582#mzJ_o#6IOZJ|6?z;o z7jST+Q94NlZd#acEK@KLRGmO^bH*TYLZC_HUkgWjh?Vy+n!SEE@sKOXTb1+0Paha8 zwjb|BJ7DQfcUt?$(f+6SjB77!SOMrFW0B*iA2cd znI0}{+b{5-gN7xOeQG|L4n-kEaRh$*WDpV{z$Q{R2F|!BF?V=NzUiVkQ1xpfvLu7I zMMUaIJDxIAGu?)YBin;)xTS3pMC-Ux?hbmF2S#}jWcl1~Jh-8{J6h{~;iphO$?t~3 z7m1g|`SJ7C5wrmQKde?ih&@OQLNMa4_G7^7(mgRjknFFIPuVg~6GW98sw1z7oFZ_O z5=9c#t$4sY2s6NczIm*2HtuasVS3w$%*Pe;KYi;b%E1-S6FgJ-%|J4FpGc$Zd*l=` z2HTkTxuW}ViL4SEiR3n(XXhA10y>5^QK9YPYUI6Tu&0h7IaS|!grrCm)F}`hL;Dzt zai%~6Qx|VHdccV)+k^{k)Co=`m~k(AdUW{X(<4xa6MnpS#zknqjxn5`Na2=e>0UX- zC}1Bb0Qzg^4!QyYw6-RAyU#04%qfDX|l>Nxl=Vz`bQ4tsy?Mk2~t zeNfpp3G3y?iCdGjx2que_lKZaJC(m*Ka41vEq7m!pInF&trKsx%}%{%0tP}=8{;l!nGhXs?#qNU zOzh#MI%CH00tUnn4+vLOJCLktTsM4~J!iU&#bVm1%tY`6NdXaiUhv4n2p*B6#jEQ( z#c0Np-*J89H7|$w#{$3BA#C!EdIRx+I7lyKSzl21))jz;B0&nE6RtHcSqh0IUybcI zNEbWLq-bR`J0n5BZ#+Z*fVt5hEYBLrZV8!1P1CUC{Nn;yqXpX&57SfAkD~zy3noxC zdfal>K{z!eK}0h^@$1p0x)R)cG5+dr5EKs8H@J!U^B539sc;?q>n0t{t?@zY8Y{eu zgSv^00_mNxW)38P86X1VvZe0T#Y%?;C#)y0sjt%-MIjQ2H`C@Ls3>*HM>eeqC~ z0#9^$_lOi8G6GUh_xwUkgJWUdoo`lG%!z5 zA6fcf5TubfTh+7akf#@dRr7Mm_QGD7?@o(4%GD{yeEJ%lWu^FtdjghOfcwGxoEx=teB?*0R6yAf-A$w$wsGVA^*g)`8 zezP9ftk$?A*u+Q=`ge<+TWM>yo@1^nD1s5V_qdz-afpJDiV}A_9zm%YtzcUgWWHy# z@cGs^JXOl1P4(6KWHp$%I|GN9Nc3kaitM&_nRgcaL05r%d=A5+ERa(`p^rdR|LO;73VkASv{D^;vh z1SOmO`ecT&Gf4!{(#b)+YYUk~e5Wy^S}Td`eugit%yb=1!9=2Au?<`QcwFEoXi8||!G=6$mvRzEgdqngEZ?zInJKvT-@;#J+64@Qh}NHkuWgw!Zt$C<<<#ewlv6(n5ax;^NGj*GcHl*8@;t zf$ruxg-vn9o@$rV3md-uu4@azG>boikKCfeBeFU%t%{q0^l0#Jy`b#UtX2uln*N!pPdeVuQt_Hm>QfU>V22&C9 z^grirN?`>4&zuz2D`)tyQ%3=7Juf9_x|Tzr z;cBt#Qs5gBNt7IbcM&mYsAMLmxRW;`-GbY=vBx1}zkup%jX`!OTS#Cp#7A56^;)k0 zDhMlWNOeTf#xR6n`Y~g|Xw(9V$m#?VVX&#@e7!Fb4U`FyLNvCNPrODJ*|i!|PrVN> zt_ETV8I~U&VD~)ZO17x(=T(IeAiY`>8lq#@9HOKoKp=P&g2237r<6YH;wOHdT=SG! zmQdZGM;=QUKX?5-#4ku?-P=8wO& zu+K5Um~|t}Uk(I0IttMhTy>Msm7;kPVNY>36k`!U2sVw(xh(Hf;uaFr+!k5mz58Hj z*n!)?dEEC-HYhAK$iWsQJDBTkIR-XNgV7X4d49NZRDmH|UpBQoM^?xLQL?*#X7P%0 zgU0LgkxI>wL|DCadbrotc(~#|PsS;dBNR-Aikn8JpBVvRBx|^jG92{=RWm!_p8Xw8 z<5*Fc5afJ!_s$aCaQ8oF<2hXtDTG`sF3#YLp5(O!166>65_n#pSc%5W6R7?=I1hb% z;(&ye+-&vn#Ce=vvu9`b`@B|&wa?V=0V#waS;J;XrmAOF2gCrK95cw!J!c;8&Ay?cdl}Ygl z)CAm~a%2Fgnn#qxi%5Cq=X>?V2)EQ;np@f2H@MU*uXeA~Ajuws;I1W(a7I*RK`_GS zYu>6*!*v9|SzxbiWYFvB0%Vd&{qdTCj=+lBE2lsQEXrbd`JrKYkezzL)@cBA!IQdu z1|!VaoRF63pAqBV&O8KxJtHQ&``{7}2q^l)!a_DP-bS(I$MW5QAD^}aCB5kR{{UG% z$tPS61U108k0d!H|CaPkjMi7;(B(xQ$p=wRc?tH9a z9oUKL7E4n?x-%{L!3L{10+S=0BK31A42DOL#d}@BL~EpDqzdRFVaKM;xZM&WC?wkN1DGH#bSsGZ4E8OAKVj&i+LJkec#sb zj2Wrlrc)uLQ`(*)zZlX-`Zat%czDP%0U%g~C9in)h^*tOP}}Xhm@54;5CNx9AE%)i zASmCXKi}T~0>=RRu<@cR2{9cK!|eY6t>wYBPB8qRRxv)t*SGgsTp1t;2ZYo7;f-Re zE*znKKXrx{Vlb-JVQZj9Y)EDanu5Kn5GDj*L<7^lcxop$$11^nH!&aIdGy*Iv0q~k zt>S>}GgH~)b;q^fL?KXA#@XoCGjL0k3Z@34BKee~kBs1%?vi`^IbyG&&;9ERJs=H9 z1%}u=m>wLFp(yE(hF-Pno>1TZ37w~-^lJw|hTy+=teF*5r`Y}U#a3LH5{yDIF&=RA zKwE%Ah`tEt*C<60+?Bl_+3S}lS73l*qGz{U_}71V&G?SQ?W5cNkWWK}3lErA z>5w66Q%P6~~#LT;0FV(*FQ| z=Ft8}|HJ?&5CH)J0RaI400II60s;d8009vpF#thPVR1l#5Rp)!vB4nG;qd?300;pA z00BP`{{SIR&}|hZb3if+l#NxS#sKI3C@Vq2OaMBs&pAOp01N#p?yOROz)F8%KmP!` z;+>rRAsiu+Ejb%j>dAnI&xB*TRV{Nkk_|yB78GAh{sA*S@(D)a^% zh18JcQ5OP&#lByja-}68%6=d72QgO%Q}_XY*SX*ikN4r7T=`aC{2Bx%nLoP_QGcA- z;edbC*}@Nhd*zS@=_(L(FkGUg_avA%{r><5^W*_J5^JuK{Uz<5XPidK3|*lOx2MFI z?%$-MRLs{}#&_TbtiX!_Q4X`i$UPwjZFiM}z!^%7okbm?{Uc^^-*HF71&{Kgt6vAw zN&rW8FXlh*o-=(STm%Fg2sQ`OM{DSy!8+mA!zzv)$Bafmjee}KWwEIW3h|~V&-ecT zfMa_@gVx|us2^YW0&*4r1tA!pOTRpAO<)KSm@0Gy%Ac_mSK8aoAdYX1335Up3(x^* zKKVi=CnR+Mi3EXsttvG~)xv*}}{jtUTfRZs|Eh&e@s1gmudOJSa=5E>+5Ls3dfLG6JF$q;~m zF+nICGV(UPUZ_|*Q(_kaR=^tQ?t&a3HnTvAK>Eq+$xzaDtdxtqqWUw5>FWv%!MJl~ppu6^1Y8pV$eO(hC{CJ4AV8oi-;wqt z)?5lGED>^)XLe3VAS|Mw0<| zLW<%7O6QUInJ9y9GpYm+6#5Md07!~g2wd@M3Zy7O#;6@A1@l;CL^TPs^;@xrhY28# zU;+&^y~6pmg#7?SVkW>Sm?tAS7pax+P)i9&(g!dFOty$7iaIH|AyLH) zt1vL2G!~C-S*D6{0UjxY% zh&m!7KjoVn6*`SrSl4uNod;%;KCCidD52k@@96I%ToLLh1)`7^=dJL{bZ+ zFnDl2a*(l}I;afg`g!tM4M)%^%N!(;MB%&4L5_mXR&zrV3b`Z=#xVZ?)5WS9LWPTc z0Cz#)(dIA=G!syDQkTjxgM)1_lY*l8ub9!e;hL+N^I3WK3BsQd}fdG_3 zpi@s!pK>D9iqRO|3FA?{hR9%1)vgnsErE46;Q+l}jPH$y*OFV1DU|3##kJe6jGtzx zFevg&LcA2>Q9}`EE6pe96et9Z{#n5DA*W@DA^8PBHgqG1OAu?|h3`(!I8n+cLIJVS zCEz}VKA@#YKoX>=5a~OM-$0_o2k=5ibExq03RD3c#)wol#E6Pf51J4F5h=zq5+)P< z-YBWJ)gQQDFtz9Pa`VZJH43@6V+*#~7+KEc1ocu55R07}SSn;QxkEIi=L zUjuPb(29Y7sG*`BKTDqk2?1wnaX2}Cjh+ZT(LoZ|niX{cA|hbFl5{`GLn?TgC4ZEK zCR82>s55~ntnjE~Ab{|x0*Iii`jh8?=yU=dY^ax%eP`sbC8h!?Qn%scX*sK!%StAt z{11W%R`KwfFS4Aw?X|Ew+%zpj`dbF?Wdp5Rhu6Q~ih?a0U=o!{s;>ESq8SWSjueIY zPbC6^lmT#Z7{n)%QpJY=r@=*V+&lq*$blIY`@Q(Dx~$uPJjJE5Xl(V6X7v=Hdp2+b zH_UKKRE?#jT|eok1qK2J08PCalRdPn7||lb15EG5;Jvua)dVzZm$S>r8EU`;04OAN zxX)q0=h9%usDw;BRSz~#ARrST$j^<&2#g?NNgbx#$YQf(EJ=w{2(S~7M=UC(AOT5R z11sP@Vd^*m_5T1BHWDG2q@ezk{{XYXM@X<}7+}=Yc2y)3=&CYuXp#znqm8vIh6#X} z(g_{$ul+fM1Y4jF|Hs z#;3RdoUWmDegn0h$%p}@DD(wZAj?>}4oW7WF2BEgzGTLu&;_``#9btQsWJd`(u05X z<4%@jvMGvuJRz7XL+M%qx&t!p^ChY!fH5!vy@uy;CzOI<%?waZ&3Q2HBq<7SDdqVp ztJn^VmJSb-y8ChDU#&|lh1yV~;e86^f+$GAi3$1-4duWZkZkM3cHma`@FYB8uHg6> z)>*N(oe2@&&jqa3QblK2FNjYUgo>(xHPCUC6hC~{G$PL&00FM3zK}o} z95eu8;$XDd1=-P6T!yG-YIx+{pE@oq>GLDI=dR=Q5$GnMogI9~c-K}c@RENHdSEv6 zx}GIU>H_|;1(CuHF#toa!5~$a6Ch9lu>Q1>@w0yh><`YrbG|-Rc*jgF6?^d6JM`OP z1?Wv|E(&?1zYv8nF+o@O5>zE&P?ZTWoC=xtcu`O*F9}3E6^}fRLfHz60C{~RzWt3F zjEF{1_&XdWd+jHN*I1?oCzL%XJ=n1VAT&v+%IPPmKq$cA*Mc#w1*F2mOQ8gM-0M~Y zpb7+rv|cuBhJXR^;bjJc-}t6Wp)yn-1Ap5801~J!AgQYl=fccVsv|-eeJjL=jI{K^ zs+!5qOV3tQ7)g!xKq7=o2#%P56fOu9Nv!eJ9rdRGg7E%_&o-wawFZ2em@M2@B4R1n z1X09MP*;i3mAZm{5QL63K0A{pxDW^ivypy21yX}BAE27SRxF-ZQbCtcQ7E(cJa`h% zq9}2$h=+5|i8Q>wkw_}nv#3N6(TY}~3)K7hY(ODWuqQpkiAxfAs8?r}2B9Yfm-E`j z2#Qds2K+yQbJ~Iqe1?N|aQp`;Tb zdzgpU+64yzh;c%G1 zr(ME1Wd;KR4?l`+P?|qXWi&(|GYm_rt+(y}02@H~XpPMU6&D07k)!Tq7BH&s3A1#E z1hj+(D$DXu2?dgrC;<5Fey;kBzMv?A83jP3{ycTDZ)!1$5b6B|YzT+|Bvi%edi?LO zfKL-C8&lzqJ|4a7P?aE97Hd@#%#-a&LnhnP4TN*lVH-tBqMWlBMSL-qAPh8}BUI#@ zUQ~?za*#2v{{Ue49c2SFD5!G2e|}8#5!_L0^;^ljr1g$-iXj>}e{TZdst!^KA}X^- zP4IrH%4gCb4%WK9P-Z+*M+i?dQLe+P5kle%P#Typ_?`w3VdyIProffjk4`7h=`W&z8YEY-e3b4E&+u2n1t7Et%ckZ& zOuH&Fh!F-Rne?eyJU+TDm`JVS)p{2!OC_@igvMC=E1CdB5m5=Z*SOeG%? zcp@X&5NXvPMDT(BArpigJihlAnnvixtWvYoDQptRHcDQlF)129L?&Rp50K?ldKOwv z$Ru3g_|TeafreNm@P87GQS=p+_ShJ<57J%P=*}1tnuddeHLt11VGx$CLTEpZl%l(1 zOmK+5clh-1pmjh|NGmXKGWsHjFMv%1sqv7*;!3u zw&e>ykKSZY>p)X8(<2k=ALmQuq*KBS`G*_^KO8MfKD{wp&Rf}0+0tlYGUuu_sxhR z3lDVF{61Cr<>2-rfQI_lmRcXGt8wg96io*@)49D%lt zALK{y@|^(%8u|i80ErsHQQ7FRcaVrN<>5HFPoud7hNT2< zagQ(`#LJAz)OBT@N0t)zR554-Yy!a*gcw5+s372{LA>`_7` z=I4MSTFMatY6E6?vmExfU;tMHafoW(0xapl!N6X&fCyp`jde*+A%ERJEQmcj%zr<{ zMdEeU14Ka+o;*)2DQ$j*7U^4>c#SVRma7J;vhx7|f*03}EqE_#7p>6fjsf(bbLAzL z5duL65k4ys^fNt)blEtSqCji5LrjQ>N(-%3UxTrMAcLobOpm19y;KB(f{Z~@W8%5- ziJ*#Xg9-8Ts+3znKU*;eMAyYX0h&|<7$`tqk@qL8jSwBf0U=plCn*4+2wq@+`tqE? z4K`r_afwa=s0&y0Iyl%0fT2KW6-#jSX+?ql;I<4fbH-W1_~6$97rtJ~qAyAgwal(x zBQ2JyAUS~81Na!~ATdBE%MaWAuQ&i&3`6&W1B5VG^w|)sNP^ik^gwMW7?lQXB|x-S zoApweas-SPj`=qQR8$T$aFo9ocw69dg|qiy>T2{P$ih+7_&a|c z{{RsEZzDJn#XCQt6!Qfre%SqngM*^r2=Q^mgc7DWEqoWA$CY9KI_c1V(5poj`m7WJdvqQ9v-)odBfZ6x4uWbt|9Q;fXF$3;=RF zp_1x^fDlOrYn8>;#qrL*VgZK?r(r$^l02(GX|*MO4Z-u{`9VSoKYGW%XOSbnq(J<% zpWpT7&3K9sjnD!9*L;JOk)lkq@Ux#Y!Q~`}PL{N|3U=h)8hL$@r=@G#p5o$3+ z2A1XX!ixx12mqs7EZ~ma4`IY(_W&Ry6QVd6V46XrBgJIX9zbnfkRgY`eNSrX0)ToP zB=IRU&`BYjz5MU^slcZBkwSq3`u=?cJeT3K>(0Q;1GjvjJ!U(tsl%&bQ5c@2nCB>LXt zHN+x51tyl()&~?In7cgbX4e~P8mje%_2~sLrGap8>Omn7jrd5_Tu{B;9Y2?Y7e)+7 zs6IFAND!L@ipG~;>^U#bD6}!=pZzWW0Q>9f7jJ+S?Ee7S>cFs!!pBlc!qR0TF$h9F z3>C;C(HRrgQZC+5D2M9BkfJ{#g+c>(v9Zy~Ix6Wh7(hNK8afkESfPRbU_|hWSwjm} z)Fbuf(zQrf7evdD-W%qPQI~f|Pw`I~5d@+H!~KB~)AQ=k0y+SeG!T5t2NK0SZAOPr9$8?t$o%P{F&aWSDdTWxHgM5- z>z0WON|uaq!6(9e%t)Y#ZBP%H3$0OLju-&6q3z65fJR`9CFkR9@|933P}#t*=kQN- z`Iy{r+3$m zK>|yzkZ$;&O>Ca7NK3asD+5(ORKJDLYH zdMk@y{@16S>eMh2qE68o4#zx0l$a6t5f5Dr`;*URh^XMfsG&g1T5F$?4~BkwTtW(| z7e>tUjk2WL)G43hl2y>KNa`u4Jjr$%(Q0N0nuYEcp@aa{1}z7m@R7!jY|vQL4xj@S zI!{Kmq6S?32~ z#@(_+$7zp(B!#sG)$RfP2apm5q=V4KKd_+j@%V`pG}9YFSa{9b#UB*BJ22J$JWeQ7 zkTB5cV6K%N{IMybm_~}aVi4N_UsenKNYaqsCphcX1_YF^=!bnMuAiHfW3Y`I5$%IR zZ6Jh%L+~TU0ZO0%QRPP)25*j=DAkiL#Zm(leRv3zNALWePw)JQgovU$R1(#|1IMSY z&K2(kO(YNnAh8QcNeIw|3WvPR;IxCMh(AH~YbZi#97P;Y844aD%mRiIrZLo>l#o?3 z6wP!6AydE&${n!64hQ6uV{fq{%Cqvvrmp!)l0;N`alad%>B2@u3Ockcm5=o6M@q;R z3xbxVK1%xdc)_KuG&-p4QFf3Q|SA}05IVb zG`d6*dEI4~#kT?cK9k5**HS4#3$faKJcuYt!2yc!GrqD+GytFW1AE&(!p^#GCjtfl zhO0Y@uCvfxEhVV$v(lEH26DSJQBiH`J54$laE^;!6JjE$65{L_~xGO6V8+7kn;nT%MQ$aT`(P zknsapKEnb!Yb{n}NJ67jVG5S!F#;n1wSZ>m>iy)%Y>y%huL57cKd)GiTGqG?An>>& zsM~JHJrw9dfV9pz)%ySoQelLn;&=#=h8Pni1J>DC4;8l<5tr$)rBG@Bc5ze_ZXlGU zh38SV^36+6&>$GvK~2T_0}H5iBybEIZA+jaLd`t#yp&DNcoTq7`q3297 zBAokBL?t@`3wiUC{H-oB>XeQSPrsk1h;DM7sQ}`9exbgC@Tvo4L|E;4&sfyTIb}81 z(jQv9WcAskA}R`^`O-L!K@O|+x%_$4SB~&zjY=U!h-HUXHNs7Vb)Z^E)}Rpvbt+Pz z5I!g!4T2pZ03iYIg1n_9uCy($A75d1)bz_1NqrGxSc==4MU!c@?xMUY_E z8f*LO7mJ1`*Z_YAlb}0?rI;xU5GhFC5Z_2a6O^JLg#{edqOCxL1n}_DH7tR;@(Ai? zIq(Z213=tZE)t)hZH9gk(S;3c5Q07`Fo`8tp(~60K91PgpRg_c_I597o-W)Ove-I>YtIyk}1b`wo7f4XxOy9Q&DPYvT6qr0E0;rf)xbDlAC9Nt>B84F7 z)BgYhxlKw6BS9Qqo+X71jlx+nR&bp29{_<9@K2(|;E4H_KJTfk=M)F)q4EkzjlUET z)M=jDrG{VGd@=+c5{8SF2go&^LL+5cV?>u!B-awX(Ap6I!B{pAopa!I(tZRKxJ7H? zlnZFcW-3}SN_lCMl5A(RD%_yYI!Z(vAU;)FtyjjHj?0tkTNyG4K4-DgJ6JdaL_VI5 zF1{emLfnWXDE|P$k_ZCp00a5}58(d*gDvV@B|nfxx;^sb`RcP17LrGi_x|iWo!kNh}_I)IAhbVV^I>Q&Hse)RRlTQLe8QNl? zh}@nA6$ixs0EM1(B&LP>HF|^~2tm{_L1R8w`+xAskO9CNOTw{#za`JWqgz4nBvF6l zRe+mxF;)5rC(i!>!XO1+2dn_OMTT%+%YQ@uCDx!J-KYJ&vc=U?`~LvMO-(qkIzN#F je@`h|P&}~306jmM{{ZoS{{XK40P*dAcmDvN@<0FCsw3dI literal 0 HcmV?d00001 diff --git a/examples/webgpu_struct_drawIndirect.html b/examples/webgpu_struct_drawIndirect.html new file mode 100644 index 00000000000000..9f09c3316b9266 --- /dev/null +++ b/examples/webgpu_struct_drawIndirect.html @@ -0,0 +1,267 @@ + + + + three.js webgpu - gltf loader + + + + + + +
+ three.js webgpu - struct drawIndirect
+
+ + + + + + + From 3ea0f3aac1fa31d4cda9d63cfdf333320da43562 Mon Sep 17 00:00:00 2001 From: Attila Schroeder Date: Fri, 22 Nov 2024 05:30:16 +0100 Subject: [PATCH 23/24] new screenshot --- .../webgpu_struct_drawIndirect.jpg | Bin 53544 -> 3068 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/examples/screenshots/webgpu_struct_drawIndirect.jpg b/examples/screenshots/webgpu_struct_drawIndirect.jpg index 6328251bd5ffb9ee171943449738d42140eb93b8..11d35b11b1bebdec99831c3829a364f511e60b6f 100644 GIT binary patch literal 3068 zcmeHIdrVVj6hHUgURr1i_d==Qe6&z;I^0@@FPxLgYZ#cNJOaLGDep;zQbHDW10UI3 zG;1|eG{onon>ZsQbIZgjlWm#>Cip;93_*};L{Y*_hI)5yaV-&9vVV;yx4plf^POM6 zbMEusCtFcoV9i&=#V6{xF7jA>R8*!;zc@BN zAqH0ikb75}ib@4)fFiTiqK{jsNY7ZJ5IR5%av)(2XpE-PVy#Y>0At!;mjRgoF3jM$ z#$5K|fHXU&)C52%FdS(rwpbAx5YH;N7W23YvCNcj%tm|!ai|41i1-Tc&l<*ed7S6O zBtno`QuI++n+&lcZv@U7flc|AB3u)WYgE}qX5=T+hjBKK*YLP#Wf|_xX?%r}9CK04B_chE-4mMrS_o z&j8n;xqDlh`*xVqMMxF`&^I`4UlR zzy20mc_vPNw0nBYrAZ;1b6@w_C%XTdJuWCH(~ya*K`gS89wVloASqVh3w}zi&ZagP zox~`d1%$(KL{(AVU7a7g(L8th)wZ12(}EWF)z+&1HC#yS%lo1( zWS(^QM?-$&y>8A>?o#xwh;))qV*tr1+SA33zkD?U)(`l-D}vQwdP9l5 z-OwGk7EjXJ@6FRU9TnJnI@q<3=Vt%7IpNz0`Ie5_^EHbrR}U~7w~&AAzVE3C4xCVR zt2jYf|IN^<5>?ssl!n4m+vItP8@AM>uk$(?Yu`C^M~GzxGkog_p}S6kRcb+_GnQ1^ z6zU{H|G$rCfwJE^uGRlimoCMwzSlD7{oR*mwW-Zd11E2)d(d*CX;VbCcG-i*)GdXE zzP{`{O?TG^DNj!sdmn9XPpkaCP<*h;qJQ*Ih;+`A$$79dTjNzP-?i=BsG?$2+n%p9 zVsznpTr)cN`9#&$nC{WJuRJ3=fRn9Y@%=|owENT{SdCJbWCMlTSTZav{%~MAZy#=& zIW0q09y>K5;!t&Szdk1HWO%!Lkxxd(#WYB3co~I+C9orqXm?uQ%b9(aDzV}&WQS@o@QT^=Zq&qs8_<65JTNPPzI7R-`>ezwp l>2E%fMGC?*Ya`0D-tg*4t)jbv9fPV%>tYPjdj2qM{|BZ~rmO$} literal 53544 zcmb5UbyOTn_XRq*yL*DWLvVL@celaak`N@gyUXD2PJ+8j@Zb)?9p2n~Kl|hT-dgXh zp6NYRb#_&quI}1X)$hOFe*@6vq-3Q45MX13U<3f(-vC(Ru9l|mmKGnpY~5`>NXsg! zyl+F+%8H8{tEeeU$tp;KO9KFqc@E}4H)vJ>0O;uMswOS=K}T2b1Kc4134jZL1n>aZ zOwHY#MO9Q30RN}mEdszy0Kgp6UtIrZvH$lB6bnl?a{vJ112|j6+}YI~j7`9p+sobg zFPsL(*yc8-7GPWn#*D7u27>XgztYYA!KZ&=>%TE17y__eHPpnxeZvOh57z&K&He|Q z+qeS3WjMiQC@p}FV17uQf3U@0*#9pKbnpPT?Qi?5hsc(Wn(E*)CHO-OkOs&C6agxL z4*)ZO2f!BK0B{E|fzOWM6gPkxIA84l@F)D+Uj^)C2KKTAn1eke08RiP!1Ql_z+cw@ zTn23ajjfv%2m9Yi5XfQx0L;ew`!y8+0G9{=yvDu1Kj*){zZL)hP-_6d56A!dJLLfY zJh$NVxc{b6<^lj{!2m#W|9{iWQUQRLFaQ95+1b?9^zVA0z~7KoRsg_N2>^hi3jknE z0|1En|HKWP_g6lka0vj=0LMyU0su(Q005}1!Q2M_N5A304*!YU|7V$h#qWI;AP#_n zg#7CO8#MTUfro*ChK50egM)=fMnpzNLPSDBLB&KzLB&8tLPEzy$H2nI!NEaB!^6kL z#>d3Q!TyT`0t)N{4TAs!gMf{Kgo6G5+unNt81R56h&U(+3;-ks1QZ6udq21{5CBLh z@J;tuDE=`RSSV;XNCpB>kO-o z(Q;*!=_i*j73vhfZflefbT&w=@Ur@{T%}(s8+{ES#XiL&-|^Kv$@PTn#c z`R@@6CPMRnt)0vKlsEZxyuroZaXHMG1}$%*tx0OnSdCXMS&+Tt{>bXOnQbDn%(|2P zRD;%Knk#@ZP&n(rXMV?vQO$4ezpV+NDUMJx>D>| zGN&BbtXaHCdt(of(tn&@@y;o{NfF4R=cg;v8h zI}@e(efcRH%~zH$={Q%MclD;owQc>xN3-MWNte~WruxqO}h*P z?||azdjZK7xHU(Og9Muakq-U2gH-U%`};#4y;)gcst|w8x?Umci{A=M(lX3(r(smfZ-k|iB0INxNYGL&I#-j zujc4cV%Q}zHeY!B@J}_QZ+u1yZ;fX6O0p-*0iiV&G5PxxLWeq4_NQ9I>(eE0;jy9f z9fl5ehBY+vxKqD<^kVXvH$L zoZm7THFeo~K&VZPKC{CY|)IOJgP+Wggq0Pzlp-kB7 zZ6Lj2CI`2|aZowq?$DRp`?T#=p7%MI2=!yfU-KdO*}XubS;c(Fv8%cF`)_jalRoc4FdAt?=`-+~x#t?|f{pa@b4KGkfV1pW{vhxg zF4M?&U_&8P`OqW7t0t)njc-2UfGm*U>G6r6TJb{2##q$;RCDj@Ah=CTD@1r|RiCS@ zwoGtlF~#Jc3OFv8jQZyeGIiI-ASc4)KUufEa?%{lN5)iAE(GWX2^lvm8#$saEvygT z>XsQcdT}zq9ligY-g+?8=*_c{&^Otq@YKi1X(LR=hnb_wDVO_SF(O@ii`YI5k@X)~ zsK>q3E7WG8&dpqyUQHUgQb`4+{k+R0xipzBA=4(BWT|}wF@my(hnvlPFRxUW z9v3T{5O3Gz>Si=Y1dXSR9sL$Ax%l2@5h`X0 zp*t&oLq@$U;J_|*Lx4L-KbQGsNWasU@Zsbh#rW*xfUBq8X{k&zM^~@e&7x0fW+ZH_ zhF7i%OKys-Ef?iZr>Eu1Km3^4OD$S$-c>bCWLn7Y0G5`*d|~d*mCY0_?i$mB>1Cg* z$E~40wBy#oiOq;gV1OSqHuY|gQKX(YA4=wJ5r0m$upfSQ@6%@1`K0>=@5`uhhAzA4 ziKU1eDEcn}2R2AE1YZ`FbFDDPtmZSMlv9QBgW{pS2CqdLZ-xn!W(_oD$ZqmFdWfB5_03e|VvMt}8X_Chz!P z(Z0E;W40Blxy0s5MeW1BhIWG-7f3QwUVY9OqGLFpgI1-*+Bg@0M0fakUn;b0p-H-r zJJ-`|q_3;@xwg+036v{rUEek_@~w|YMyqNPc-i8u5_FqXBx44 zjnB5dR!|B1A1{^VR+Vkr&-xH7(Atd~-EhAHgq7MrS0OEOEyfizQ@j%_BVJdXE}sp( z|3isVO~iKFBB;|%y(&G&lW)-!a=>>k=%g8VEhw#9WprU>1*#!*J)P}M%XmXv+-c-! z!%lX@fAX&}o;Z@9jQzyv_wXMs0Kq0lw{GEZc0#rlndH*RV{GlQ`p)8^|MJM9Y4=FWdPI{AC8Uf;gaU1EjA1rF5t8kXkI%6eQ)D9lDg_7Di45pq5eWcGRPgb)s0M%`Bn&J7 z3mXFyM+6=2qY5r1J2yE62Us`4gXJUy4CFJSb$nmCS(R}AVuS6>R5!34|5P6|IAnhK zRO{X+ML19GMf!7MIncF)ZqS$q|O#IfBx=Y?(M^}85o_1b%Y8LQ=56Gx`$>pE+0Ty z-;oR^3`q2?9Jz+*^0Tv_KGV(dM^}U=SKg>f4ZKeHaK{!_`*^O6RhvW(3FwZ@Gn-wP z)35f3xew8W&OJOMd~TEdUgxsU`8zp>2MA^2l4v3sG!kVbHk*lK znWDW*$JArd0BvdAkR*xyrT9(4;m8Rlk-k1;$aT5SG?j96&-yY`l?l0zh~d0`ZImZ% zVX^2kfoX;vC^eo_-AzMy4cWYc))75G(yaH=!7)jS3UqO6>K`E_X+(a0y!yE?iuje- zcyhigrNA~}d%6(8y(3Dm^OwUR%sS@54sfe}F*Ku3@kGnksp&jdd2V6QNOI(+DXgen z)JN=t|5!@IU0FF>?U|M`O20*tZPrjb=FMGW!GXR6grNr9aKYlHw(QJ7%=d zg~gE(#4vpK#wFa)ms2cfkoZY$;_@Z)2;o|F_s4daImNS{_s$koc&1q|mj4qg_H-?yDXkX2HdL8XxB(nP& zrIhFkI5W^;ab?fI-aN^nhT4M#b}Rd!&$(#tff3>MvAy{&g~Ce&Adn+%pz5-VX_laQ zG6NA;XTJRwr3?P9E&|9FOl4RIRgNuT7_>;s*E&PDX;{9fFlcuI66*%QwJ>Y$U}Lly z8}u(SefzrG?kFFd{VnGSZk$F-VEJ>2z2ce0N}o(tqMdf1&pBC1LRe0YHIQ+g+TS8b zrrPXraY84>WJ1IVmr(VNo}NY1*CIPsLxy^3vh$2SV^KGn zuLQ63rM+GZ`|Mwipy3aXM=0x|mvo8=PA<=;YHAj?xKeJv%DXJOAzbmAs6CFYypBi) z!9ID}jMS`Kt*ve*W!K-3oJ;xen1Jz0D!5F+vZKm=u=NZ-yrbE{ zGoBP4U#`#U%wa?e_o^enur0oND~c>6H-<~6lfj}zj-5d*tT#(17MU0HYGoT-Bq2(8 z)>!S6!KLHWam={GF4Kl%S7a2yD)oxkm-0z^y3$x*2u8VF!-Q96skesc%Sm%EbDUtR z&Ump}@gnUeGqpXB*L*B<`Ek0<mzAf@C{Nk$qmYMIKFOGRylWyAL;eCHp@rvSL{ssq0D(ug2|1TBX1M^7&{I5Fp-o~&JRaLC%pIoM zYHxipDZJm2eA66xl+M}_@}Dep8(7lr92nsj`1TV-`ik@oqP-kDuI4^YggVu?VIejM zRg^O2#8=rZbQM9jjztL%`ykwEKNr>W+0b!(TRz;~( znfx!WZJ(PtBLDQZ@G;&+K@71XBvMr?x@ly;8-C=gT{%N*@lT3XUV1D;2C5okMXZ#_ zKdgMn$fYdLv}omSGAgE#IqZT5b2$W3tM+V0k~4^WOnmr9Dv9=DmpMTYC0MsjSZ z5vp#nu}LzV*>B?I-Y5(l9}0Fl8-AjWwk6FN>=IM9IGzk+m}WDq7KAn*5upPf@_(tT zilp8Zlrd13xXzg1N*Y`e4QF}8&RG$H6uO?y4@jtgdFo1?q884}!Q|CYAWq*hlu!*7 zw^84Xx49z^2o)XXwtO2!$dCvXxOcg};=nuorBEF^p%T#Fdv6ulsW`pt# z`3W~v@tZr&NZ}mC!({!qH#EZ;%JyC9i*vQ@-3^*K-LWsV2nRs*kbj$s+p zzUACV=}`8o&`ZQk?b$6mb$oFwu1zs6MH@?rakM>!Lk?O}9v%m-+SxN7ryiOu>zVY? z1ijTm)97dSwc32J7*}%?D&I-^DZLe8P;fGpf?|KEkjo?oneTwldx5Y8e3CMk?v_ z@BNuNc3@_d${oY)`l{`%E6*)KNenkr4lWUe?45DNmK;)wTPCexkd4vahiKb$cV=XH zgKV2}G!s;<*w+j}SEpb|R2c^f(@%ZiQ5hc(jD^k+q9D+N^Yo#gGvNuY{T+Tz zaa$IqKjo9nde0)aZi%G6%6W$JIZ047y-wQbUg%rr(TwWK*+Dd(zA3!NCf}xw?pcp8 zq@+j?m!o-n2_9tHc@Z08IJ&g1Le+{Q$ETrPds5Ehogv*RKBYGNrutM$js)dEy~A?@ zi?SLz!;*Q;-agWiv)GWY+3b5gn1F56lx= zCEpRz&t%B6Szy(+@A~K=e9X;Tst54L(GJ|2_Zeh-0BHe#4au#<=gJ@19FSTJPB1?s zpBx{pN=wCHYdz=l;xbfcO6G8K33M%m82Z;DW-88(X}lDdVQFVB_wBn1BS-Ep!p{gW z@Q=h^uEBWd#X0CZ@MNhYoVZ$HW_faU?z**f=zRVG-;BV%Ik{M!Qxa*f2Xu(xP!Ef9 zSd!4~1A>-%z7@B(Jt<*~?%xaz+Vyp^#84*+G`yi+96T^Aszn37F+Av|=l1y_BjJJE zQL_nX0-_X}j1(fID0Gq~lO@MA=iD3oFzwkMU_%DxpM2i|h~>M}UP&(gLTr%_moz_K z3<8G_IrQO!?mlBYeSTYi8n7*W2k%XQ?-$_%r>m!T09gDAV*nr^p`oDRVg8c8U>ywp z2?c=0_=w3S3WKF;icRkFH9r669}0Gnx*2q_txFYH97+x~Ggm5c^`QE{1u=MyRT$za zxKYFQjS=yeM1NZNXPi1fcHMZPDutFu%wv>u}krR=f4j`vK7~;E#5=F2mcFS=S zG-YX@a+oXG7QSAlGZUZ0PBz_|a|b?Tn>Z?gf!sD7f~|GsM;Uoh2A#P{;*W-=*y=IZ zFcu8Rn(d32SB6}nhULPJy$I$d=Hp*1VK_YSy2mk!UqFX;6#o zADr3bXan*NPNlBN--J1wNuhr}BbLq$_|Q7TljXYqXnluHENh5`Hl^&O@x>-9jN?V3 zGfk|HcEP|z{fejz`%rj=!>uWU6bR~@%9Qr;a z&B@JgBLg|#W% zey$`v{nTR4tp+LD>K_8$C~QX1Ppr%Tg&K9G4{%n}Z^eQ`Z-L!p53&VnK>vPaGn*nhDs zq5{Qcz~`4Ns@+Cs#g!bJxh%!WVKNO;QfaLaAH{gM^KJ5btM|}K)LYarX5@C#?eWcM z4@>Eareqn7`MUR9y5YSR@;O&s6^jYa(Wy}(k1eRjxKxQudmU^NNpu%~0-~ekau_Rf zpz(MXc9EKvQ$Ak7T@2B_1N52?A2CA~RW}~kEVC=I{|eBe ziMAhhz6b*)vagf$bYpNA(g)`wOwrmRse642X;0#d5@wslTuF#N;)1(b^Jh9(AaLPW z=+im0k8{EZ%~8+8epv{eytI+uUo#6(OE`oP`w|Zdxce#2$SJ0XHPpg`d5WznR`-dP zx);DXTNq4W3(N`41akKI+Sv{bdx}wSrn~1+2;;kCkBu|7nU!0<1H!}G28%Q0nLISO zwm{Nk$oZjGAZ)emOBChKVCBiiX^nbxkVfDtc>NB8rAJ@(i0&Qmc=IAYH7;8whftTN z+%qogu<%Lc_h24y?*z5|OHJgp^;DlsLb}3E$gY34N_a@QiyZln4Eo^)CL`oVk-S#QN4Jrt-Oanr%SIKrvNwq0*c5Y&_xw_c! zTP|&q42+%g;I9?Ti7&W8HlnzVc!we5C6!5=PjCKJ2sv?CmX6$&l(Fvs(_+0%#s`Vw z3qr5qURi`agV>xpE-GH?avoY7yQntfD{|ni!=q#Q$!ZO)orhaA&Q>3)@Qf7}{p*?D z^H~3NxTOM>J+pst5;2qSYZaDKe&h6~?^$Kp&p$5M$iu6WQb{w9K~lx3s()Hmv-9B( zt1fWqKeG;wc$yvmvUO#d#MI=Zz77#e4A8Uvn9!l6-#rFv$c*^K1RMA2c@~3jg>Y+B z7hH$f{&+hEZ4w@_VVEEsL>9G;e3{x*i&&=Xft)RxLmA~*17~8y-G`;tH_p%vYhUmH z$a)mhNkIT4D3f`HS#lk%Ds&o%sD*~uwF=cp)&sI*2m3uH>U}n?$|Mq7}82wT3 zqxPngTvJgYOxyiW^jvVNNH2c?=k-mvZFC<|5`E)+Aon77=mF^SDCE=J1(C8jfX{KV zm`P;#&h7cG&t_Ae+Ev$+H(GQow_U{Ae>Tg;Bcd#{rP=CcYW=rdDJ@gdrrwdh82S!9 zy>k$+R$aFx9n6H8uSY78*smIcxrTINS_ZNsA6s3i(AjJ)s<)r%XJ>q_XVC>a)ryD~ z9_PVMRG@Dt5y(@H&SOe^v-cXhbDNA8I>43;8MT{`_Mp6^Kb4;v(|}#0-IfM=1(e1f zA=;z3<>nhk1&v$C3FRP_9Uh_~H1=jxoVTyos>Wm>mlAz^Y$l?w^j;Ayj)qO)mOMgi zt-?-TFA{Z!{q4VHX4|}v0uOynf%Os7t5HCb{5B=(L)W(ev(LcBbcrUWYv%Rjn;Hj) z;!m-#(d|8^m3&{W8=YZ3a@`yIe0Qm%|3XkJaC;h7Oqh(_&wJO0IU2CT`c0!k$yaabw%E?7L`mB5|GC+eLrt7IsseQHzh2)N^J0hAV=Frs; zNiRvGye7T&8Hxzcyz2v~jH@s14v(|( zoR`X)lp*krmWqt#N*_$`4sxff zhiMhu-FA`d?m>qp@co$YiJuCHJc6Ex4gW~|OTIrB$Kcjw}M#DE)&R&rbchse;L0ru8`R=j8&4zsT zI{3h@ks8g@HwXSBqd@C*Ld5JETc$K0#OUpEze*&!h*^MHlhd~m|B-$+SxkzVuYVxn2n>NxAc-LzYOO;D%FE3f%M< zj0VFMEIMr^0QGhf-huvVgTU6lrJy^pEgPwMObAGarQDu= z_VY{AM#!8)u>%sZRi;}3ri;#AtKji=y&SuCNRBtOD9$l_tr<7twj-8x;jkd$#Mkh0<_>3ZAXR59MA|vo!?6kGh zBK5&?lhMOw5LNVh+rZ#`2Mketq`|yBKn){Frnk5a&3N8Jxk!Sb?P7V6xEleokOyxY z6RkGmH6&fV5q*O}88pj&y6fw}vnqj%1JTlIT-~4cR|sPC=2hbE$iydFHq&m{bzLAg zugX32;e!zN1I#T)VePis!niXd3u+PlPQOS@8N77zUcQI}>)5p#i5CB?+IVg6OR&`^ zFZ$RPGt4zC_0*G;O6%`oFtDD8e+R+!Y!f&amcqG&d##DVt2FYn=U+!Y{-Cqf!Li%; zlu#YiLQ>Fy5Y|i7j-xsVHOvingqct%ipoh~jg=ur^Qj7UE>7sxgg%{8qyOa4sr0Q~ zt!JoG$)RN(AC)I}YDaAi(HD)ihm2Al<-G-U8|6Dmx>MKEi!$@x} z%4D5zv++i`?pNQrZsg$6X`&3zqR2hbWr!m>=<~(1kg}|g&6aQUihe8?-SL9dr=u>3 znyAFy+F`*C_p80S##2U3C!Yf`n)WO~R_L$3yN>`E7#`AL7x*KFbl9S~_P)n3{B@ot z0T)QutvyUyGhO;MB%=G?;WQv+=5oq1(WOfSCx81x6ox3 z5Yt7lumQd*N(V1}IchC>YL;8II+ig36&?EBl#AzUR+Tc6xCqC*J?+Y~qqg-F=95e1 zpK04o%no37d3*iJmu<;TyTD{wBp7-eSZ?m|lmxjyNJLkJWQ`vK=&c^{8Mjnr6gYbc z^%mWl+NhNL?5xH+J5{)RHSCj(T&=hmsUO$`%@XJ6Um`j;^VRB5aK| zh0DTH^+nQEw`u%bb(C+dy5cI^r89xe^1BH`w@M1rJ%-VGxvowsyAI|)Ii>uhU~Uvx zM}1OX1zMhuG9b5sk*``P2`{!792c8jL3Bx`FAiNC4U3x^mwG5OZPge~l~oT1ZE;X7 z(SK)zO_Um>a;~B%2Qm1VC0_8TyAe$sYp~`BooyniGVMUsLq$T7P!#7eYOR@hI@eFW z#@V4I$(!fAqMI@~_kefEThs=m&@p%8TMqsKM4KCAMjORWE{S2tn z^V~a?ex8!Y&%*Azm_+WT#8dG%ZQh5}deDM~a1CI174yWZ7+^hV(S~wW>TKFU9t)v> zgHJh9WK7oOI;(LP+P}16(Zk*Tw%TNg$;6pthJK>JjtT>v_Tb2kjUr7X&V*o%-Fz*$ zy_SzQQ727`voH93fXejIuiw6is;N~DB0Ly<13MGmbdM~PHruIj63JY-~`dXnvoIaV{9G#_{+GlqdmvA_FG$%l# zI?V&djID!Y>% z7EHw&IB~DL1lT7rK@14}n6M?x*pow9Km^D?&N1Q}h6VV^b{@2-rKP5m+ihNb>`H~D zAv4&;q@$Ur&wayUDM~q=3+eo;^wGU!Cci&;%~Ov zB!<%%i$7e1-{snXfYYhLv-{ve~Qkwi^K0+P=R80?jQnu})#>%NkwJIIo{I<)7c`>ayJIe1G zZen&F9fRT+*NM|f}pPn4vEYe^-53NjL*J9TPyeWsDS&DK_;&yr51 z#`5ZZ3roF=?u8Mv1CfM5ekC`SHbq^HB^9G@GS?QXweyS{4=N1__RbMDnD;JVUr zx^Y{rHmmD(Ti+^0|G~b>M}3e8D5Bcu?ai0rZW`#%brnjeZnAy%5z&yovg?3oUu(oH zM6Oz6t{F3XnHHgh)^igj4_eEF2I>28%*yMwE_7=li?_j&HY}m~a`?A-CLTJ!{=*}9 zcwv@JJ?}RPE1pAoQ}CNU!sE;~ZH;lgu8Q`nGU6R`3uDJPOCPd7rn{3ijP?p_4PKJ0 z$`4@atDKg_({8hU)ZRzc4C`AJDO)CpFr`#kWw7oW%aWxV*>5M_@t`aAB569U6l^S_ z%whicA&&J+PSveo7RvKYD)O0f)M+;!j@??((elgSphi(4b_QgK-l6Lx_n3pMz_5d^ z$F{AaX*dL{iy6*u-~o2l@^&nBNs2}kVwyLjUfUpHg|}PKfckjvFGh-OLU^nSS)3ZZ zItI4rA0UZA!V5aRv^4w5c!eEX+A+es=_iSbIU8rjm>MC1=RNT3p9L}a4seGP!|~2Y zL1SVmJRrQKmyrNemKoyINbyR8wMx$s@he&P<8n)Uh^^2uBMj#^)`Hs!tRiOb+V-4A z<(`IpOT3Pbh^vxrmxl5-2f41ZW&Fd%Qz__j^eEh#1rR4TMrb@2YcrfCSIAh|Jlv4R z$)TB23~zUa2z6r*#LJLqLYhMx^&!$WvVy=%LGQ-6eus=kuRhU=ff2X=NrUYGuToRu zRCKGv;&gVx3bO2I@hJAZdQ4;O9#$+tZNd|6o~@zG&D#kP&lb5!aiP3D+4#S1t!tBEKLkS%4S1~yUY7tYP>EWvvxJQ~ln)94^~hGmY-Z(rO2H_@mD=pV)9)Jj1av(z;5Kj4Ic`OQnwa*$kQlnGt6gLg+mQGsP9r378p1kD_O*qxwslX)mFpL_r5fz^|YvDpHQsEx@q{&eZO< z^C>+Li_CE-qqv2|>r-Dg&P)@pw`f#p2tD6~BS^@b`Df6HWv~B9X0%MAt5qV@NQ<|1 zDCNm1MKAkOGM{hPH<_>^E0ABCfKVjI*)^lGBcqO7#^0YQhV8uVv?rDQry+U*ygUrO zjd|?MK+D8zOr=NFY&Y-K0M~I1fR2D)US&7^pv32bm>7&S?O&Kn`jC-!RC6)^1%+-B ztFAcPVFLPAq>|$ct@$W%vPD*}xA7zya6ds$ty;1TJWU2umIu$`Q2$Y46i0L5{;jO4 z(w1`XSE&`{ZLer1IX_x29<-~L^QiI;2-6rFlM&SnJ7N)dX|T72E3Xq1mJJ_BqH4^` zkSO|zh+huP#MD}K$lAi%7LE?W$&!MAyXg~Ce)uN(G*=OMtH%1({~aJLme461%p3V4 z=JxF=_KD_(OdY(D!VP{e9Rdpco;(s1%s;Q3|Fe;T`4Njvlw9=>3^sTR#q_Vulsfd8 zOAaxWpId5_fA60_{sSXp>&)2Onh&Z?TIb)OSgj+)$S z*<<_b&i#v!Rk5@QBw>hxMSk(aLKgXNo70Pcw$>UzMzT@i$~zFPsMUDu)(U*_WAmvShohC&#Z(n5=CK;_r7cxiP=u^3ZDOKradb6T z%3ADzj}Wa1!JwVZLax5kvzKPuqFd2dEnlE!wGIk+JxY6U``nbC8-0z_9IitK*h3p*%y^+zgT-@kvStZPZ@qLv?TA8{G5Dh$s7LL z;y8mcn7Rn=S-sI3G8^xU8k$lc=!6SxH_lW6{5#2)Ib(ZMY;g#m+bWYb|AlWu2gstE z1ZCgZP5I{4iNcYQeTX#=V5CBb?(a2Rj>E-h8U3B)ZI(ZJ&e}a4ak;Gy-r7^f_J1%@ zFN>F2)rdphW{T!+BNF)f>-l(GRLhop^*~KZ%%J_-ABxNp?IHekZyew5zZ5botY2M%jMl`#J{jlYts4 z(%Ep1K{<4smr4u$KC9~nFc}&lN*q1E=KJXKA8#)2YG^75n%ef1_8q>CCa3S}To>Jx zZMBCdyC1)3Zqvh{=elVl6gvKxv<0SGj%-u|wFp`bj`x363h2BVY=dSvzgN6=z5^C? zhmEzecHY!bX!IA>sNI^!wC+hA1u>&EfBBp%lonE&J02sr!$bdeKQGFC*8gmyVabc|En?#K24gjHXHC z4CP%FC`ST>K^8}#*O1a8hJ{Ecr1B;r(-CPdrDfw*=a&*d^eyt&7-#u$*vmkum zx5M+A1g&1k$Q5Jn+?DlrD$zIR%ezrtKGxkfs1?OYVb4qME{kCI7Y!2sj+b)zLBl&h zK#dZj-ZNPB3Wd3LIIQ<|LfZM{6RhYT;X;&ee#B9lNKCrl`W9bSQqGvL8*;x~aG^|x zWXidnuby>@2cEi-zj|`I>Qgvq#D|+1O2dLWO|mdMyLY;)gB{u&HLh5{sqm6D=_?BM zlHw@`FecIxJMCOcE~NF|?w&B{t4*<#!@7DMtY1{fmb7WhCmx@oc^|yJ5PI*-x=HmO zBM_MHO>ylmW?cjj0PQuaZzU4PKVlo?Gmt;serG?)VMUNFB)2l{t|IYqXfG9!D|C+iN7u_-0XW|v}NNdLmusD+wr1Jhj~ z!y50~jW*opIeznHz>goL`w>S?=Dy+NUt5p6^2Z)35^*-vwe4T$)_9B{JwRyApjbH{ z4_3tG0a=QULplAF49RdQY^a#y#`XwktM49rSpj?+iC6^kF$Ulz5~m5}!B)OD)Zlw< ze5&@$=*HU%9LJ%sA%`7)e>!Y~gVf0kEwpsB_N1b`!y~201Qbe<11^?A`bd1YIhWXEPT&Wo$yPW5VELj5E1}B@Y*NxEF@TO3Iw#;I|IK1Rh`$qvFcX3Vk}N zq_kDjsgglZZGHHSH8fi4WFc!YULjDMTSrCX&Q4!5hwKw+zVNqajfx-Q$P`Eh(g_w? z7YABzaVJu0iK(Kw}QhCrK#B{ZY0Xh?*O~2 z1l+5@*6HIxVc#nsdmHxcup}xSqKUe7tx0q78s7}|HxT6nR1CfED%AOrzD!p+>4jAr zV?`yYW;~}Zc@T6CFOA?=sb$CS&Z`hRd7vA`B8~4jixOr+$#}T7r0U&o{N3|)^sA#- zi>9&73&iS1cSQpC53@2z_?NA_43jr(A$NL%&Un61jN%RfYo(GzPBEIUFDfg|ug}LD zgVrXoOEv0?B{the=mv-oMti1?4hT=`(xhBWKJ9gL5ix?|p+Ywn+cb#kMjpN2LSj6K zRr}>a_XGF4J_yFERMyK<#>U4te+CNynY(Cqb4PuVx4Z%Zughmd zFXGR0FJDxI;su8IK1_`b@wKKi77%bb-($7la^}a;YTNgFq>6n0Fhzp($_0i?~zlqrUoy%UO}B zFN+q(e*`uu-RHK3iE{XIQ*=a_tR(<>y%;FHNkrO&lT_DcmB{ZOc!OY#a8(lJk|AVx z%cxAP$_RbnIg3}{5(J(>C?1=BI9}R z4iIq5M@a9&|MBp)Tyld@>hxzLfEqN-x`??ZmFTfN|l zB9&l;iEz}lL9f!YmESgomwItABNP0d;xe2MN9vn@27B{8GHZQRgQXj-iT0}nvBh}0 zj6I|Y!nw8!JC_ z)--bBJv0&~ewlQ*a$(|HZAGtE306qSU2%CZ%?|am#Q!N}@tz=zJ-@9mD!%sQw+6{O z60%5Z)rF?2yFnca=l(3t4ZGyL&y%>i9_-uP@vYDB87xtOt7m8M?QNA^*O_aQMUV%t zv7Tz&b1X|0GsV;lT^Q-;`+cYAYEqgDcoTZLE!~kd5fH)7h@f5WunWY#6eonj|54QR ziSla&LXCw#C5N6S zg>VNn4Tl9yRX1@AQD>bCe8wSJSWJ#^OWMT0Ux>rB6gTxMHR4_C&HH^t({uNF{F&wx zuTGR^cPWOMHgAze8;y~)lAq>Tc1;$x<`c31@iH#$gVTy|i*kU>ptH-Siqs|gu79~_ zf~Ll??_5E7+C%z9S=9|pdM?>LNPjKeczP&No-utR3W_K0+>RGV(9wG>_Ic-8O(q^d zq9~8#Bgsl6L#BRRMl3fu4&sn3jRBUPYI;gs9tq7%)a zv|erS8pmnp#!|7^S?I}V0pFG9dsX3ynM3c0qA*5Q=`*WqV%eaaG;YI|vBd-7${|z9 zO7G)+j8o2u=q_xJL-~XGrQ>O-;M4^8SYaKXzQVBz=Xk0iq?ACHU`~g>-z8ubHA_IG zG7NVpoRMH&dYtbNGLfpMvL6a&^5nw;6_2%3uvELIB`a019l!)~rg`P->W zVh$EVrqxbYimqPfPB$~AydL?eD4cvG+9jhcY*LDTXA;uH>Cb`IC+Z!D(EaduSdf7> zlzyXh+H1u~@9&AQwSd10rsNBH>67y-qgmXnvUM`octR3NuQ1@Hi zhRJI8<@^Lpp7eKsvC?r%N6NmSny|fa%i_1P_`d9S0MVjcH%OR1kb;4n8Lhhjk6j9< znadmxB`S6n#6VfhO?+fZKVZI66k#7^CWUCn&)M>w{_P!*@r$K%hC{vui&Vg$Ps_6+ zXix;*b#1nSby6_H;m;~|Nj;LrczraY@@Rr&jLcY$__fj)-QtiCchRRBFVLS~n>>#J zzM4hD?Mc&QM{ z@AG1IE3@g*L}~K*Gg?Cm6T|at9rI$ux3r3s^pwwtL#%1!n(PlMKrUQT6|YSnqa8^- zHrFMy=qGaAKWx>pk@;}0^a6&GWtn<8fhF}m_p?zbM;cfwJe3f~Z|PI@*9X$7iD5Cr z6|^(OXM|U2GLFcotX=dgq_9#oWQfsbW;|2Nf-XC+^X-M{##-hiB2WJG_(sTwq-vlfC>3jRRl$<{H*C-cy1&X60D@JeY%KuR#R zcpq`a#EN?Fmvi2iGDkhr-XX`P1DT}jC(X5y#>_s$U8+2QmO%=p=& zGSppMN+?q4vms@8N|5gJ7H4wcs+NXglMVVU5XX+^@zAiPXq1M8A#)TlSkUJ8g>yWx zzh+&+RgLZG^@~Tq(dYa;ze$Iu$Trd!AX|V7)JVwGX<#ux3-Rd--X54vKDA z!7oD+uw2T*e+?I z?@<2_Ro?&|X|ryfWMbR4ZQEwg#I|j_W81cqiESGb8xv2Q`E$Vu1kG&)fKUzP2ZTkWgO15Zg~zs2cMi>CMXL>{`~p7-mJxy^ zX?i0OK$Qx~!0k_KCi`QI=bRgu&>V=Da^gPDT}J=WUDa5zt6CM&@2+TLf-U-{oR{EV zw^g0yY`3h^e?c_hOJo50bc-NyH6%;E55J`-w@VVa;}Bw%9LiH6G?x#476T*U6JL9O zm&TMCqL%HX^_1Ryzjum#xoy$?E`&{r5Q@IfO}!ZHX@f%I^!6KHwLNMglv`qSzz8_53JV zrY|3~QIkxYLOj@}72jilbyNXKa?|p=e^V7lHc;Lukw_0ZNSJ+wvi-(^M`!1${sJw! z^mGMpRcx|!!CqCQ7b+mgVQFTYT*0S;L@A3!gR`CW>S_Jj!4f0<8uwlbH$-SHCwP_RVHW0co;5v-;Y`d}fXzz13P zy(K}dIE*tza> z7ApViPg47{%sa)S@hAV@rN1CLe&H!d7GHaD;$IbgU#jMR$(q3-K|x{uBWgwgM$~(u)SH}@Nn`>(Yd~V-jRf+L~CP~z?%FDULT(>{|2zq|=`?ND0?*CO=!wdnF$BuaUl5Ec>W&IivnF12SdNvV zXqfPQ=Ao`c48wV;3jmVkWEd+|d!Y<&tZ9;>ebY@fR&zldc`PoyMEI($)vhxTv}_78B>y=q7AU=!~Yq%V!z8NU~bqGf1t$s$Jr zALzY3mpnosil$S7;>xYQ7fzyAL^xK=_uJwop#X;~TSiG4hJVKKMV)w0d47L~sP&hF z#g|dk&?(P^sQ8XL|AGJ^f=|B&&qIt6145g(St7gQ$=325tMEaGFnwFxx&AiC{jLw1 zmu?c$d!{B4AkQWrLWLCq>S(-n(Zaqkj73C4q3l#~ZLE?l77{DsBDv(1`9x&Vmp&#^ zpUJ4D#In$Szs=4|`(Y-e01g~%^NKm}-pkV?c@3V)LJHGKcl`@8KI^P_FchvYi|Q?2 zDe|d8m6=eO(7hfwbJnVD?Fg{{5b$^@0=d|%QG5on896FUpbDrlRV)-Z<0~89ARBvjM;X4>(L`qD8ZL-nn58JwxjE=|1V}CwhTj^T>#f%CNRWBI~ z=Qf`f&nBVyJL;r@=}JlX<&v1o6zR}7gXv8cj2!*Z;Dd8VTL<<2g48In$3xfO)sHo7 zinm;!Fp5#^U zQXI2bS8yCzj&hzvrhA@RQ^-AhSiGHJSkI&zzINtqI>b7T3Py(|6G6=zw*Iu3iyr$^ zF619W48OF!S;`$woe(c7$xgh0A2M4&zB8<%k(p-_dqju6K$W?R2k_o z*FuauvWrOT9sue-nCh_3v@uBQdcPNRcO-hY{ZkYoa|Owm?&9^1dde4PQtd4qNrj8J zV4U!t7E53}&LX+M_z+$0Tg>;H6i9B^a5*iuEt(B;SMC-v0czxd&K#KBz=p!pkRK0s z%^B*CD%S6vO8^5V^5{Ih60_&}X#HJ07Q3bPEk81TYB73N zCU*0&m~(nXQeqR3nXcmYUc+v0u?>KaczZc{91rX7V*Rx1&60|o>0dG9rGJ9SB;o=! zOkK23i2WX4HRVb9>prNNluPLl6K*+0?Y3KxE$k^SYkcEM#IEt#2WgLdL~eUtq^`Tg z=PCMpP8cGf?pF#-Gv&j6PB8jI%&%B8< z4^LN{5N(DCn2H%zg~pftMV+=5qb96mh-xT5n$Jm#L)1BzXpt8gx=msX*=7m7B-)_% zkwqWx!qGDe@uzN`e+nZKLKx|+N8%?D?ErEA*gHGERtjRx>O$lG&;>X`hLLn*n9!m> zWAow-nT=Sj8lr#1cG^XaOyo?uEgK`D7EagWCnj!Q;Z6zkg18hPR8Oy~k1`C44_5tF z4)hy>BTMd5%0Br~>^kUU3q(Bonn%18M$(Je?C)Za`gz%6U3s0-?Voc&KD2vdm-bT( zM^CHRRqvGK(fay3R!L#r7pW<7g7%kqS{US%$V^qfO9i@_8}&WQ==_|n3768_0x-ST z-IOT9ee+I;Mmsfz^U754zano1%tUwBz@S@`NfUK$#}pNw%AfNl#|ye!%CBHO16(*L zf1s`f(Jd}eAu#CU7WwI;;HEN?+d=Pt`Y=A)PypbZ+j$=Mh@u>)fTD#4&jrv8y z1_sno7jfy@wl)!YM<%j+{VZKyYYn>9AKYDxj4(xdnke1F@4d3^b1PVQ$Pk3R?2(>IG`=EVQc-MW@5Jpx;)t8fFwS6r0;m1dkJ1IO(%K)%dmcBy-ax z(NOKX-oMlBqc9py#@oWk?$iPq!PEbV^)B(VF~pMl=7mbZ3G`*zcAjzv*6Lr1PDDf5cLwmpkzi?n(^4j zW;p1aq2Aj?L0_6_wo{;e+KG;KXI6BT{oPx+B>9+Ema@-!lFf-MiG5l*l$9AUi+fqI zwH8}qg4co;rug76Vu#+Y-_NZ|?!6;CAR)(ZVwuh5XH@->69-d4`CZ$y&DNk&vw8^2 zK6N`>$3s3)JIiQ)NRvXnXdH!~+!i6Q$xq{&HJ$1RoC%hFA-Nk>uL}y`%PJ1NHk*B-ojZCcAs0 z;Q{gTtoR|pMr{`gbTXrTzqRM>!Xp$lvE#eGT~bce&AkBdK^Z1BcO zGi<6S)40lh>2N9Cy`;pR)G+q$?c0>CwtXzYtK5l-OmAmkGn?y)e$5Ui!>3`aF$I}Y z6sClQ2_W9d{ieZg+Hfg4%Wqm7x7J!Zq?~9F`mL?~M{<5?ele6Izx+u6GC}6{M@RaV zG^X<~+v(?u`}GYHHW`DND1)tkdVkEYcE;2hVI3)v-^oN|in9F$QMB6i9`Ye1cB-W3 zi%KwbrZj8sy|$&57-=LAyIl2^^NefEgz2Fry9MF3-p<3qMKx{hUA#L3#6nWs+_GV& zf-my4Ile8_z~QgVJ)+z9=FJ!NqjA9+yX^_;v=TMkS1Y1=ZZiOcugmAo%1UC4Zf=r2 zO>SAbBR;GV;pIrnw*$>3G%+WTe(9j0l2bc_<>hcn#%QSL(1Gi}ho1=XqV%JrB(&Qu zQfB(8XB$joy!^tOD98#?r1sBf>FTBqqpw>Sysf4;^|-}L^;@|w3j*@$2|Sj6Y~W9< zxA5AY+?Ve~WDjcgawZqCp4uC?T>Qca?#ZZiWhch>qXB1y;^ccMC;ZN#R+pDhcrN4S zfJ3Ti{y}TOLiaoFXRAV2L`g&&?g^*MLV(3{ez32VO@m~rAh>OXs-GuORs=d=j#dnC zZY4vRARe`uBT@?=e!v)*;r{WN(y!TW*S54|P3)(=MxgLsNjccZJh`6`bFbYJ%7v6B z7p;Yd9?X3RUFNu5kcUDNQ*5BdwL)}Nku#Tp4FVf|mkAvUJ;8(5f@Izg%Sn*NUpwWD z^fUjDMfk6w$Xq~wtM*0ePFfDUx;eWlN00XhF1#8lp(T#8zeUUJh9yhei6nf67v8n% zSSddzIingZ|QW_qJ#86v92_Ku&$)El*u>8rjMtIhzqiuI8*MFJrfYR9H%H za`r-*U+|AK82U_^S@g(yp`Mh~?;cJ&oH{>oQyQpKffnPdN0N4=Sg(b`QWHtMb*#@) zvZ7b!wm&r~C(V*Ac(sstR1xl(7pGJYzp>z{%!UW;)ns_qN{Ak_Hc32=Je|{uE`T!3 z1ZyLvmB`GS`1B{NS)S9hPk>MvaI#ZC#phhB@^L(;I`uhyG~?r;+L|4gJ6I?0cTu>` z`7e{>sCP7OmA8Lv7fb9^5&o+5Lu%$}@(2-M=qI?Pw45Dksg~@`u?jzp#<$YlG@yfT zkI-nqHnljAZar@8X$eQI#GK9xc|AJ;U~8{8#Cd73$ibqA9G|WJ(2*oL*=M6O)lPUi zlfND9i@6^6-lem9!ozPWt11CS8ZrZ3ZF6nMXTRJ()z( zY~9*g0w9ZY_Q=TGSTROMJ35}Sw2P^{hd1It zfnZpUX=y6~AVXUJ=|+k$=}jHTxy}?Us-X?%+hMYrEpSS+%)Aw)9r8M)?XyWO9 z_^=09?`@(8!jBn)TS@(S+N$9hNpq+6LyI=KYb!BgMw?79q?=9;>b(+788%O}Z2}y1 zW0MK9I^9OD0MVo`@8P~`wOfm#LsJ4*-r{(@#nL-^EZixZoVsI8CFaWq$rTg68Pn!q zFYUmasDcaUrV8CEo)4<>V0n9~rA`eiBqx=SMqCb^StXuIL&*_XNtt-E{$|5?qm@8m zMkQ3n&6IifbDPfEx^SN^x6+Ngk}Ex`=!>nc(ra6f+a;bU&P+_GTieOvDwSmq zPt|<1*|UW~LTR=P&nrx!tY(SwBl~~O6j-UVP?Co0(HmvMsFH?p_^ictpkVf`qc44F zLS!PP*9aX%*RI=U3e=LNpqE-g#e3g*)b`Y>ycTwEXnxmMuF?C^`Ts0VH0TfQ()EkP zH#g&)+o+?Y01?D5eE19U#vk#lZz-Bxlew=k?PR|YYojU`6U%xL7N^Zrw+U#r7L9-- zFY7g~(_1MszE&c$+vlr^TfX0{!HPYnAc1DsD0WL+4~=u;)4XHPjL*%nAXmAGrZzma zXhS|WoT_B6xId0@sugLuKpKYRm|&ykT}r5xPQI&QzL9qC*l5%bw{>=9r(f?|Svm=m z>8YvVPfQrF6}Ic8m9bmJ4a|~#EpptAM&;zl|lriy%`ZybRX$hwV4YPZtMeBKIldO6}(OI8!?s z%0|r)Mtc-lc(?;KZTT&^JeU(= z+)-pQ<1&{6fE|yRi5TBmd@K#(KcHT7t>#s-8G6)xWk)uVE8FIunA&PjGeh-+}xbG^A?@ULaGWc;8`Zu7m;kr-@ZN;{MIE?a-< z7ag`=*kwA<*t){29!<&aErgUgo~dZmwkWp{d?n95Png*A7vz(&!9F~uyMRn40TZQ7 z80PL;`mQ?aUM8VQ$|+p$m(UN2XCOhlr_DM>+xr=1lDt5*@OCO-aMFogrD_hsiOcu# zu3*;N)5D6MFS>c$C*OuIGZxiu(4QBzRbBVWE1|ys2U#K|q{5-7pZFqrf=Gf*>1qLdz<0>hof8T3)_@cOK^K+hY;_WF zE3OK7Ih!5^&T2)dZ4cF*MB#3sA46nD&!y|g8Fs=`NRw82l$0FjPWRfEHEV%|$5;A@ zQc8bX${ooq8Cs3~3;Tz8jQ1Ihy#ac8Sdp4F0AfGdiZPrDPFfZzSX#px)u=6dM*wd4i1sxS=PCG|U9=^0J zM4XfxcULmBLiEMba9Nv*E$M9-;cVQvn>AJITR7kL3EH(Z8cZ(y-HN9UOx#-;7)e&bF27@tZ{x3k*tPZ}b^W2o4`Qu7dQs=kCa9H#Yq`ED zcrBHeMU#+|(v)<0TUzV?7y{Dou>>x4A~B>btiD?aQmTg|5H@0}ObL}1jqYBqsr-WluN$nZcALz8Ly;`{5 z*L@&iRPt`%Y^tGs=%*MqV9TrKSqgt`rMs$mKR~rm^~kq-wr7kh!CL-S2u9UUJaqY1O!JkHOJ@5rMl8-R{QFQhE_xR?EbfFEn8|P>;3^}fGgQ;zF|@@P#ARl@#lKa z`IEe58e!gsKi`t-UU9BGdf}-fEYc(gltl`~`S|LY=>nGbVwf1fUy7<2Lta$-OwG zIX<}Ml9oeDbM%P9r8}*=;v^4yMB=%c)yk*ZCzO$ro{gWMuUryyBO|^_rV9V~m-W73 zEWBCwwSSlLkm>W0hG=bc=}}FuY|;)3YNg~;dwljUNqyQ_n0>8qJRH>_kLK$g5h=J~ z_&-x+?H|?~gwvyy=|%Y3Tz0+YCl6Ee|C+gRxEuLQ8|hJROaI`MVYN7%?27py^pYxwN0zAZTsG%4B>_Te_h3pdMrtpG^R5!q`JJw59E zDY811T_H5rXJQ*pMrw?Nj5hpK%$`EOl#NZP_P9x~@~ag|`(S?TA1FgE(~+6((@5S! zl`W=9n^+X<<{(6r4H*$dvOQ<6bkirvb}4(JG@~~dq39!|>ExRc37m7V6$HHmo87v- zT>;Fnv*&BB@#1FU2QRO^D8MsPdiV45;II%KT3f~^PhF}h@$i72rb!NRc)l&eT8Cr< z6C&s=_S`U(6pey}io_~&dFkX)HiB$e=rYbZ^`A7hwt}xi2YK*+AP3Rdp5M-nN{mi2 z88L}~4i{-{-U~+if1=+SIi9tTjIFJ01zmxEK^B&L;58+ktEAE4E*8_{8iN$CMl{{ROEs&voPGJDSEf7^e3+IuGRJVS%a6$TdTR@?6zRI+z$nleat{)z;PJfo({v+1s-QfOB#`s?l zB#KuH*%elqb%7Bn(Gkh|nX=h#W8c)7E*MC8_FqhC_H9;nRB<(@Urs8}!63K!)LJ$Z z?msw}{ENiE@Fw{KLG2C~v_9#aI8J%};cKk64?f7g z{RO%FvS4ZPrT}e3qnY4*?XCFa&ig#{`}Uky?Egii(jb4i z3%4rKClaLh44S$8o4d&5K@@|lYk&BvjVo}z%WgRJK)AVSb2Uh^RAh%QBek(Te_jI(PDugU6aZiTL z3Wv$rgz+Du4_GFwr4D;7nV27;kwQVtX2C6LrTzlDrHJ_%t7|fYkqb6-6%p||7(sv; zGw~M$X52bX9;~Wz=2mNwD?;9Tu?^-q-lRLmRmqcv6X>Y1(IS4|RrVmtO&G^?Vc=Fc zL$ac^KX5l&kWfGGzx+7jC_g$0g_>dL4r&=8YruvOLm@vrixq@BPb|#klGhZZ{}5uf zn;7@#wDaZVV{qP8Gy?ENAtuE^S25d?<`G?DVoeNP5HO)vfKf*+W3*&$)A&Y!2Hz$7}$K z0qJ2$xAAgp{6MDzzr0Q{Yn#vZ9W*cwl)BDwnOI>q6l@;!rLgOLJ9)|P43FrU$O1mB zHuvrLuw0BXrgPZfh4RA~$5cSo{zz!difxVV=Yc2U0&An|?sgal5WJsw6z!j+b6xZg zw*gqYi15r0`0XhS@Li9YB5%1l+Gr$7L{RwseV*(@i`3|h>$2kUiXiBJ`UpebuCK|+ z)6p-Ku5qNnq6Y<+uW9YgV2RmG^l~e@P-HnctAiiX4v0?GAQ8Zh^{BLG{777kC0cQO z^_0T*yHQz1qdvtrNJYNBoNEu*e?f*3F&1Czd1{%f%$9~gf71S(4j5zY zla7%hX2dQ*J*juFOucFz@0uJ|Vp=`+g%v|fCsH;w=jnpW0P%cfhv@(cRPo2u z3@RllDTREVz9+<_{OB;|^~H>mftYD6inS~L?sRin|AvSE*R>WA_ds+6cV$VCGM3Ae z7>SHMl0{z8*^!P0kf2ayFqta$s()`?S&>sj(36l}5z~Z>e&?~qE~ZQ%dHH1&{Y`Gm zwZ|zb$`Lf7IRWYb#Y#IUg~ZG=B8zV_wKAx{ijuwfy#a!>cqy%v&=onlDET#&6o)3b z#@{_VNN1lwW}8N-QT~a-&rvZW-=xS;mgWM@p-@?(se5Yjya?lonWS&f;x9=1WkRrZ z5G%7!mNIwya1Rt5vk19SBc+@-74e@#El!4gk>>2TSm)$hWDYt5F-@f|e;gVW)>+iv zvvD7q^c-j8I%w-}_g=~Y&A;Yi?O}1PMcj~9%iLe{jS4an-~FwJ+F2BZXhLpO2==7a ziBS}jo?oWZVNsLbk7misombsZ>0S?=Z^#*dai;C96fgNWM`&OdGoEHynUD)*r&`d12;M z^K7sO-SXvn$GY#VL*p`sa2vo*=N6;hZB!6hl_t{EbHD)x_kKJC=KHQNIbX)l)6}3C zFXxU&*lv-m*P2%T^&eJd0+=o%tfI=qPv5z<0fNzd{P+TX#_!k=*x&5WOrcpT#vgF4 zVojv{0Y>JsKa;Riv(m?!VR;fbehG;0w|e4yQr#yo5~>46k`7XtI3(uaY0x=z zt)u#a$f?rPA+qc(N1_qkddsp!;KxIg+33~BAB;R3m9Y@-G~*9|x^QT0{r*6iDHz-m z*YZ!GN6+UI;BMxt?p{3d>{3#`I{afw!?Z7wqG zxR5(dVVCkTsVArv8BZTH{mmT1VEkqds7%-AaT`@_`LQSMzBwSd3R961OV0e6tIymc3Or_jgc;=8{mlE;euj0t9 zQglgMcO6qxy&zsNiQc#_cVXxsU*@UWe)W|a_1NE;Z6M1R z?j0IO0xqxJ^x>&@X|yzxBARewx)k%t>Qy9|lU55P$I{Jx#Ed8}!aPTP8pWaAuFDdb zsBu&rwpAwCtZp4|c(zSQn$0VPRUR9*zpUZXlv3iCLhZ9SH~F*UgA9*>YKEr_LUg|I zFNh79q9lDxTl4CoMI+jeH+b&8big()IGne3=2F=yP#T2ciKGB9uJrWuj6}J%}(Mzqd$Ke z?B`5xk>#nLOI)B}1;bqQ1Oq zq73`|L_3~8ye2mbG;BmI_j&7rZ3eX%r*cF@kPkiv-AIp~2ulrRM!53$HQLBIVRi^E zj^7ln*_Ez(6_SZ9vNU9!=qg_C))r@@(P-r_>oz(Pz!Zj;ZEH%bn(W{B$q}+^aT#Q5 zCy7=|yl_r>;4$^eq$oVy*7A|ustaxxWi|0&#) z*wYw6(bo}hQafpMZ`rpCDl}S4TaiA5--@h$`IXA^73|KT^(LuwMNN6!52Pk9lW^@} z4wd!cjM<)XJGhojJ!-F(TI6qN^4Tm*1VyMQ36wdwJ9v$uAkytaa1xjSjc0pI4~CX;lqS^pQ>&o()lKsLaEzDX8F-c$HRIA1LS? za##F)K=`eI0)p&+T$4~47U$P)cgncmCFV|Uv!|hD_};@HM@>p^5lzhmog<3Xi|x{P z;xs^gRKSh$jUft}&;No1!&byx5`XT@L6f4-S-%}{h)a3$_x{>H7N|jwNbGUwZ5K5T z55IS;j_XIUoSG2ooC(5fCsxOkEbqZ0pp5`$*ih-%tj?Mk<6RHKK!^*e(AOT>4btiX zDvh3&kPa6D<3Dyy!I3=yJAbmdKYm&${}fjBbWASL+sN+*8D$AGD^_1Jo2N#~trv`U zfc`=2T$ed8nd~2*Ydi5RGvdWQl?b?X52nre^R|dUnMuv~bXwsKFx?chtpm)kwL5c zqbyzdA7m%g8_r39pawt_+;4~NM=*Z6zq`+_u<)?9`s*6vX9Fls6Mal~2F)7M4uFEA@^ z+`SI)WPqgx0a!>VT;;g=WhULA8pFpE@^f`*Wah}cwNTa~GYJuKNGgE8^Q{!!2B(xF zfqY}{S)()brF~?9RD%Z|GKCmiTP-JCu^GOH((|qO@|2-|LtDln>hKX&(XnOQ&LWEG zNCLYPf#r^FFR#z)!UMkutgowaQOK9~NP~>SBR^LFtPr%}NSAw;mqDN{#&6Z4Yberk zbbZ;kCzNxIM$+=UWmg9nGW%TjZ2n7o#o}Aci)iuWZP+q@Og2OUo2}HsWq_gKbwWM- zuT_k2m){Lmpvkm?+=R*O6zRqX45GSL0+f{zkP4Q?@_gVe#1Q_7NTu|HgnW!R^cU4QIP-3AB zoyL%afh~JPC^@!pR$u>`wcmFQ`NH_#A53BexW%tV%eu-Yk$>x$$@j3138#Y?#M<$m ztSCWPY-Z%fD|ikhF;wA9e2k6EAeZDIX^Mt{TFOM(iA*Kr63?#Q)znmnR(E9LQaFPz{c~R~9tXScM@HL( zK2M%xhBS0L6{7?y7LZtjizm35;I2$8pSPfRO=}$Znoi*m8oxdcN3!Gj!z#V|5&<;% zLPEe85;z!YFt=Ik&VgH$!1Uk~-nF3wu-`TMw(^E0F)Fk=#l3H&cJfAe-0V4eo!NrS za-caWUnR}l0g<9Hac7<*2clNS)$mm!r{+Z+_uy#i#) zvOpFTC_w08u^g%&vY`!|`oa$5*e9zifMb97;$Q}p1vT>5W!zKHS|vuG)oncovSCqA z8&D~NC{;fx|3u=}?)`Y3xI780q4vX`1TGShh6(8?QzYbl-LGtg&FLeZr_?a-Dez~x z`kT~sOmtZ*-`gbl04`N;I0mOx-BrMQSSlaOg|1x)(pH8FMTq;{D(B}qJK0nh8R`ee zeGrMBo2*zLAd%5==r%r=w%*mga%cb@&W*Ci zpXYErIAX7woN<}f?Y)fLiv~Sn#U|VPa@$M>PC?-jM^QXMF)eX|n%huWe#|_2n9@2B zS+`ONub(sN510Av31C|rMiCMPY-;_Dt;9)3@T-!PzlMq&#yo16+l9OU6`RN^yE44Y zo$U27$*!6A9``Pr|2Se9HJZ``Zl4QVQUN}uf2m5P+PCxxc}G$WiYA(bBkKNnD7H9p zX+RsQnh}Z_f=?~-1sH#?TM`7*+@pCH17q&|7o^;Qnbh1sc2)aeEa!VMuIXxZa7y3i zs?T=!o~U>SvJK&KzONI@glM5?I;z#bjgaa9axLZ zBGU1wbVYyyga*PVG$Z+7G<4OICgmWF|WUm%EYN(Pn9Qp1d0DO z_Fm9=a@=;_pWzqu5S`KO2H0R|{pbnd4$;ynB1RR(Av9M4=TJ-Jnb6VhLz+AzJaW?| zzY|LOKsXd5$7%-ZwQ@V@fnVKKaxkUkPMxMsiWvk+X@8vURTamP9YXD~m2r=dKS~=d zTt=`xW&9PLTBCAg(GD2qjpdbe0|J>3fzm=4yScOd0vtZT2^UWf>Q0a0)+J7dcS*B@ zOSC8kBoY&_4~t|?TZMXkr?$fhBh0W@B>x_*{7iv&&!LoJX!TE|{rl{3SgiZmYPkyz zL8i?EiqQHqtU4Z-*8(AISmht1GK#tHyO}s^>d96`i3*4Rvh&Zn6|3WBKwsdt;DUNv zfz>s5HR;jn@tRrA{jkvlqyiC0CT8oBuoW&XTf_nlHVGT;O;sdQ0d7~-HlPg<+Ie93 zonzC&+FRO^Cgs3=WOXEro%54YN)z8~cV{&BfRhsfIC-JehG|GEgrN9&=UMF4K}n!C z)vlL&C{=|fURoUYxsbHix^oAeKld;W1!gzBbvPbhzRrq_(3<8SrM`94q>w_oqh}=z zZM?XWQv62)7A5q=5v1@g;fw_h{^zIaFs=Lwl4o+nJER73jY|)*KeM)xeaD2iV8tqt z{s2lF6!P)mQqIUPRD4eAxC3SxvGpZHu zPvO}M%m*m(w`;1S2sfT@Z7DxM%hDFJa}RzS`JXkt3_pm9c@{!mr}G~yx(tKzRynJc zWeyY(fHdahAgP2vkMblFT&_sHk2-db+(29#n`t>xO5M_9I8&4~!VI+v3-cnorSd<| z=zKTNKO;K95W|RQIBmJgb>N0Cj}jE2IX6d!PPFl0`oy7Zr-}x%w=UXO2VqokMteg(5-}2R9+nIo<{)e%k{<<_ucp< zmL|+k>8y*fBL&XX$Lyrw`4=f9EMzXsIL)xE+5rhn zUe$mw49611W!nitFd=p$FvKqubppyLHbP* zAc%rfU~e2FN$mZYAR>@&q?Arjcx3c>>W9h7a2m>ad9u@Rg$x3Hq&87kFydk!U%F%t zszLRa1nVu7#b8f)kb+^htSP1LpN-o0FP*wjdLgreW4R`kBl{oIu&bo=3)vD~`1{Yy!?c2HImEW{(|5;^U6A+TZF_R>F9P_@#mmmSFEc6M;NfW>p!|LG&6gH7BO6ElD7G- z^pk^;FW#~2Qv?SlknnV5Ykw}W+T;DpCmqm`>&+HidgCwo{O`03Pl2DZb@c-N6l@P+f z5Lq|nbw$DV|Agi3=gd0dU0mIh$o=;k?5k(ze>bYG0Q=1UNtF(r-8*t9BayU1@$pY8 z3l1R^L~*Vy{cF?hf9{$BR=KlA+rVn%CFq}2l-k7V`lZwqp^!%b|D;Oj@6$*2Y@v@D zBUN_#PebXj4A;a<Ihzsr{2G5thjK zxa!8Po*nDIhzwQTM8yhJbnv(0|K2irsP5FLij|kVlOjvHlnNBB!WPzI?X+#Z7%3+xL&-777Uq z$p4a4^T>NQ%D4aKrv7zC3G#=iK8g-^>W;^#1}uNlUl1B>49_a$I1I->aM$lkr0b;O2x2H*J9S-PH9M?@X1e;v4WwR}lmEb#TXdWpQh*r%3d|K46` zN>Hlh&u6G1?kGeI`C@ysNTNq!%$jy{e!A#dJnKaBxTL;C#GMxMAl zFMgw_-@&l`F7xyy!CLZPO-RgvQ;!)tjI`Nmq>~KWvS{Xn8v%MZ>ffd`ZXNf)AEDs` zI3_eV$iRxx-Hyq%ljn zUvyx@Zq63)D{?XKvE_c`2zim7-3(j?Vm$V_-nkSS z5bmm@*O*>pkjV#u);`c7nJI7hpiZgIl(;gy<~oa@o>i#9tYJnoe}F2E3_ddipzM#X!-}YxB)2u@v5P0HFvxHuV2A{TJLEj)XiE4&a}qwpB;9Mjc|9H$ z@0d9ieY&ds;WTGrzw`0=F6Cg8wr`yT+YT>u{lx7HmHc>r^0s%bSuC7L)`^#{hJ}aA zT1HCdfm_RqD+R=viStJSQ)b0h|Au{+-(U?de)SFF#tEvyS>OzT8YD)d)kv@2fQ)<6 zfH90$qY2G8d4FIN6j@6_v97qWYjE~}%NWEQul9Afaw&4I0~-#`yPnkn(+V6J|KvAt zP?ZT68e*GSB&VeuX9SgIU?oOpCnsYX-#XPS8G_jhkJYa(84zg!ql`>&LdpCz5d6wa za7-mj$?K8D`c}%cHR^lAjN>6sv_e4;3;!L`+^(!ki;xGl?#B1w(}P1Jx`e7BH=H&Y zQGIG=)p(LAjwlu~GRwky?#%RJ2bXgo3J_xDr_Q$zv!RSmF(Vg->~Tb{F*0#@Q&WUn z+>wscF*g*!){0@&RX$a3J23duO`#hJ_2^5CpN`Jf7^vJziW?D+Da~w+4e8)WDv!<_ zDt~I^n`9u*0>r{rOGLOfq#0)6D>lrEpAEm@)`Rs42*9n*&7PFq(@zVHv@)reOd+FsfeeTH3LSM6{YaiH*ULbL=JwRJwCh z1eeV~3P&9XN>c*A*#*(P!oAOpXgr6fm-hNJ1hzF|eERhE=`lsIGaCH%p<;@SKtI`= z{k&Tg1oboweX<4xR&R)SEAJ}rd3(qiN!@{6_G8v_rQHxRQF;ru&}M?lI2?hjgrr0t z4QVwLmS9#N>AGnZUKvE>j@3Q)wyg&WK!42;ja((eBIQGf9(n5Y`h2kP!?fp=0(OM% z+qeg@rsx525NMk10Tn7~)@DFZ=hQS&FR#DWu`);eD^R%Jmq+< z-9$D{i`N@#2U+(14xnDz(J^#+z*W%Lz&RwPia`&GtgPadDs^AFR%C(?dx@5Chw^O} zR;V(j$G~o^CZr3RWuYes4z>!57}p69IU~$e-6#nZMD;WUW&B%XQ;dHx4;t*Uml%xk zhTQGQ%B=pLnf@X%Gf{6`+UPgZJQ}1bAtFV2%Yob7YN9}*#M@(OkYcQSY}@4i@FY!~ zEy?i1Lq;*i<6p_fNv-i70X1`WDn7zNv^X_<9g`SHsTRtpt z`hGP=vqMunE(-+n+et?)Gkl**AFhVFT7)5(C>4~^2n=Ksn7~>;E4uRZ_ruv*WGO9- zMR}HC3}C{sVXg#7`fEX+6wsOV$Edf7Uu-Si4#o2zIJ6WrU)BVZqSOeCVjwxZBq{-_ z6IlETqo8})7IPq}^8bv9i-i$=)V+DX>?k7Vd z^Yg>n>v6}eWVF4B^;AB+jTOMbQegQs)U(6b8LOwss`l~0qEXg7E&c~p#RDK^D4cXX zu@bVTTxA@!A(di>BAKCW(&gA!x0yphBE!YjoE z7z}sf{r>&cmt4Lpo}d!Kgj)Xx~j?8M*K@5@WSE`Hnti9w(DXZQg&1MPpm$LV*)ZQ1hw0P}zc zMnw`z(+u6P{BTLDT@x%Mq)Znmx-b{59|=%)aY}|=M-d7bOal`$y8X8Ajb9)ewFV zbSK>we>}~8kj7>lzHs>6$1CRYG-N<|Mafsvap(aJ9>HJ&s&8eGD#RI81r{zG6BeqO zX-w|Tl?-TL8Fi$&NYcJpOQEQ18pj&|K*3p_iI|Qis{IyHi!v}>eDX>|M6##Hjc1A@ z0BEiyeff;V>zAi)!63QBM_Vuo$ro8vr?B%#9WgAKj@+_J*hKw)ogNSMz0=14>} zs{?RJGStReeQHsKh{;Gj42Qz-<@^B!Y72)7D?_?2F%Xy=tORQuog#@jPVlf{u0ll; zvBTSt0ny5?3iR1xv@^&DIZTaW3YD(HnTHq}$b@V@k8~D{IOafwlo?#1w`%YYW>5x1 z!mTU{WJf%+prUzLS3<)*vhvL^xOjRUawiqRd`C7 zW?VQk48X=yjfojCz!u!3)u76>;&dAXn}m}dyEVYD{e`1pWt^#m%r_7wgjK?jh~+8V zXI!Fa?S(7#+M%Bu)cYF5?J0rEY>qZUX+^&l-+SW3qXAs>r(WG-lZPJ5Soca?Kff`F zHSf-+oj2*m;{^|d$UV#n>BZu{@{S zH(SStwzT355CqadGlcArj;-LpDDj#dpU%9zWaTh~$}G#5Xd!{hLx=XA`|pz&dIrY782vmg>bKhFTwQ&SExKJ~7ro(w^upKpAo`7A}cgEa6JzFYsZUaL=%i&=@-;>y0?Uw+k4z0B%Vz^}#8oMMXPvF*i1P8Z34Dw1o3*)GQQp_A zcl|et6VdNiXXD2ZDhjV81|4lPGcl>G`VGHYPFpW=5PqrmpBI>gU;zIBw(h;>g$EKp zBfqR4`g0rV=_9)5GvE5<^aSqh`tfLJ4P?S{vo0Z=eDYg`bYf>d^)cRG951M4t)cWK zy7$Q^q<8Z=KkaAqndUwj#UP5cPyx*IFIRy$6$lbV4g@@cx%_>zo>Pc0zG~s{;}hK~ z+vp~#muGTh)2w(ATTvAQ$#8DD@{dR)terYAz-5E3_M-7~^wx}V39*RL*$$y|kpfoB8UAGPwa4Db} zE_Nlfj6w`2*7x7;`{V7)L`y*CC@OW2JQ0;h zK$(yi)xV_*z=-5WVs<=Ai%8`&3-EHYsl-QS7oh%T&flIa6FGIS->mZ&z*V}zy<^8G zzQ8R+h`4N#szWrUfjtIfdV(j4gaE~=7vJ%CsXmga%@Nf42g9vP638<3Bt>WzVCW0e^nq zj!U2`k3{Xw%4^2nW+054Xd>ZMapW9lPR@CLnyi#=585c52ACln5?~B#TA!rTMsPY` z8#k+Qyz7hHQEd90aM6k8i(jMJ;{0&4)JJY6J;v*)!64ulx2x&vlrdtAGz(Y^Ghsmv zW8Q4(iICrl8T-TwB-A2eBa|2lp*O*5VmNTB5UpZ>FI=R<1?k;qsXfc{eVPP>ij1mI z8`4HYT3BPB=hOW@FYbxpy-N&VYWnP%jj%6HU=e#aIzdX{ie8S)3xf3 z&a<*ETgPYn;eypf>;VO?87dx*Ib_o@MAi`~pjAXO#sCzw31JFW<_~KeL~G~`Pl1Bz zNV$0aZ@M9{%}}Cfrw4%w0Yag|qKk};iIL)00|AAKc?M#7$26A=fnaZj^?N$yP&@=K zL%O{YSgsoKS_BI#3bPGY-gwv!E-0sMxqOlPa*D(wky$Y9aFeXg4{$?I-sy36U}peM zbAHe9yliUq_gE`0>1W zoOD8dP3tmtOXBd@1i)ZjlO`dX`(|5Wa7WIep;YS+2itE7PLlE193ZHMfo`hS6b( zoD%itfnzX55i%VPKCk}(USM|Ocjf{8`BbC03-dopf!K3D z_+C4|*ICyGPzH0`(f=3iH8U8%?db{EV3ytV#`0s=> zrI5X|(*c_13;`p@43mby&izy$bH^05R4na z{Qm&o97!b%Z}vQMCsPt9!m}9x>pvV7KmbzYFnrA25jy47vOn%`jgjI5tmg-BCd9zF z*MErk{&+=7IW4d6l}{6;NroBLLpWHt3%$1LX9|SJSFc>5(~jUMnMW+V2)}oCkO_y! zzW)H88Pa~7=WyelkHh_czG#@~@SJ0K&gz_jF;uyA5pXNamKkZRBgxDP6kS>(XF?d; zpkTsr;lMVF1-7p1t6Fgqs#C1fbcnJ;%~Vt{n=zDh0@EasxaMf{QB;&$C|?`VI95so z(r0>GY;g%o&G@Avk`QeiWpc#eF~&~{_1<~|v(!?{7!?u8CWnNE*!Ha zJk@oW(^SPc1`s;U);h-d1CBWO-249gR*9cnN)&tjTw%e%1$mTd@2|0++vkk%u~8~v zCDElYdg4YJ5hA%8hb3{N5I9qgC;?=Nag94W-wOiE28;C}G zA#Sop)B;*45RYo!6|5mp42S?UsUtjcV~7c$)fXltOd=RAotGyl?!ZlFH|BvjCIC|! zF80O6hes%+sm@&BuhZ^vfng9bHRwI@oF+vj9GEV3!*06rK&92de114N!ECQ%o7um| z6e2QZi97QB6X%pB-m!fiz5O?!05))Fu5ZHQUyc!(v+L{c&5Ahs{;*SAUMz@$e<#0# zxx@iShDBq_!1-MsT^vs`AR3m80I6kVqzXH9C}gOG*lOF}O!9FPHr+j0m_f?-#p}N; zT9+l20W3~UMVCSbsEaQ9cf$mQj!s=*u^4`Z?P){hD7i%en0y_WgB3?Ldcqwr0b%QI&xmw|uoxQ!Kkz=!1wJm2tlZ6-nhJ|vVyF+OCPnsdPkZAQxy z!@jJug>bv~_vHrfh*qyEhhN|z?VpbS0PhF>I96~Uzw`N%{L&#sgHz|B^>3N}GDkct zQa|~F^FOcgw;leY|HJ?&5di=K0s;X81OfvA00000009vp05L&PVR3QUEg+7Q808yi+>HKDWLJoh1JNmLZ9Z%mYl0UL;A-9l4cA! zL@NH(`{{?(n9D)7!CyRuM9G<77hZU*Xyz>RXY+~|68``|ieQ`UTHXAc;K>sciYXY4 ziJ=nDtO44zV6zpM0*2TmJAfjuYA5~}mE_w00I2a2<={3WllP2Z0eI|b5_1=?GMm9( zad&#wuh-i+*g(X6X-(Ce);{u^BG2`R&F_CdY=DxADK6o8i8syll+p|Gmih*Qq%W*R z%^=-*KC_cZd$MQK6u@N`>NtuqyaY!E!a_7BVAdf!Cb2{~`j9*aHC<0%zY+av5PXgf(1mI-|q5}#FxEYZU?Gn@k223{>L91G9D*L?g5+i zh`-J{yoQDHn4b9Va1eHY zN_|froMQV*G|2GLnC@rB9H3Z+Y0=DXq2rBUNI?ihD8Ggd#Cyn0Q)rVAmJEqU2HtRa zMC_WPFtC9|>0{CQ&xEHxbYdwk0{YO&+c1=sxRQ!)Im#9*;gxT*ABPB_3t15G;DGd)yu-VjRq z2_U~0;ywdS2@ok~V{nNq_Lm^boKz-G!?G$pFk=B=rMnqGc?+2%h2Vkc-582etW6Hu z(H+OmH8C}ifm>+Qyv+BB4F=L0AcJC9k~E7n+|)#_G?|JJNG2|07{SVjNjZd6P7wUf zM%yO2n0+0`ya&b`w5&|GMz3dhszgAEgsNelmG<$DpmE5XK+v@H_QE!(6p}$0d$4cB zafg;ci6&7I@FBzO18@q+jLOWAyhJgoau`D)Ac)i(sQuu!vKC~CsUmJ;%25}TY#S5( zhqQNCK!UfYk4GAr*%gt8{{X%I{{Y|Qpy&jzU$KA((1z0S3`^-ax}nly%pu=lXL!0m zPK-m!cjX~hn{wk-mpY1rL-3Wym|X$d4+>Uk90k*IK`5mH&!37 zzCg?=+`yE3KS(l|hs-j3SL@bH`c)joMEHYG*EYmPiKlcNSMA|=wb_DAPAB_pWDK(sNfn?Qylto7^P2O?aXoON2VZ_ zH6gy3`=1}jl4A&*t}3O98zJ=t*JbC4Aj_94KeZu`bQwhoj!_n}-n8)Dk5C_E9jOf1 zqk#>Lh_+m*MDg0P>A|%CA2l6&_ks#jjR06JxrXAmc!W`sS)bkeyTW$Y$49;O#Pr?> z6QCO+KjY*&W-$quO~&-MKV4(c2}v0(tWZpa%#(;uxn#QwqozG)VU8)qubI?*>jvgc zF7iawk+6@pQmEy)+s~Isvx}8YPRETgt@=l*c&LsRNmGcTUSx_R7^Wgly}f&nwhkPP z6~B3?lk=2jDDLH*#l%OaIM4%0JFl!IVVG!f3;HewAjgQufdo`0 zh~}~&a2k?JHxkdluT#3n(A1Mbp|UGnKG-=17i=F-6Ej~J)2uym>bG%GXE^AEqdcIp ziSa5=F^0mU-7QUzh4{#z6sUGa^+@w~cs7qHCWEweLRXDoTSP^Nn%OG{M%gWpCP7T5 zoprx@z$pO8fF4D^VedE0bYI>Xo;j}=H7GG+7=IsqoZyRgG}2vK@g4IZLg7K+CKP5M zi;1?0i_`-QBtc1b6wp}S0=+64K0W^c-VWsfr+X*KO?2VXC*(J+d=hI}6Bc1H1>M~D z9$>?+nxuDZYDt)`y|xfk8ycc`_THha0Ch0{gXlZCc!M6L{{VmCNa_4QEd~-nG!6IZ zKUl)nZ3zmAfXm5L-a!N{O+ARF^v0h|Pb4XWlsDaV?|}tGIQ8_5rPke#B5pmW6pX;W zG|Dj(6mWNefe1K+< zYom+QdU1hjs*J@dR;BBpLfKMqJ<{$Y>-!mUQDVJ3O;h2XFtNblzEEead}|S6_q|m; zc`FHutDisfe3gPj6|kFJg2nSi7_xsQt*tct#||0Rgt${qV`R(KYay*aZ_CfF1Or4f zEHMk!y6fD@(h3Q+>PVLPdhvx5g!1!u^^VLCR_bN{0AD`Yst5_@WWR^)o8^8mR=4=B zKyP_%`QzF#4RIZbu9Sz{Ja7e;=3{XLZS8VLWeZb;wDy?u>5|y=)t+pz$b_3{K?jDX zxLzu)8OK9xuuQ~7{xv2~P2@Tr7sT+<=`#3v2w^p8S>&5oo!aq@iR6e@c%J>R!ioCM z=!3@R*9KQ0TYwZwiBB`XWGWP>W=Sai-q9vH-J-m98&DcY! zFiR?3Jo6V6HS}Zg`>ccOkd7 zY5^WC?rbnlu!=rOuVjAM$_df2Qdq3k^v)sYL_7wrBo!j=nxA_*xm=iZ-QX7c zd#K3ZASf#3@@Q6KW;lN>1b!hk9zM=Zs5r!PfXR^y=wzso?ffZ#G6bo~m$nP^KA2;& zIwW46r;hQ+n?VsL;%>3gGB9PxfQIM3CJp_1SS{KJ{2F%|q?rhNMcZEyzXO3V2{BW_ z6~#}L>jP7WBf(8K69yTlq}UJN;&pJS9U z;p8%3W(yEmh8rMx--t582#mzJ_o#6IOZJ|6?z;o z7jST+Q94NlZd#acEK@KLRGmO^bH*TYLZC_HUkgWjh?Vy+n!SEE@sKOXTb1+0Paha8 zwjb|BJ7DQfcUt?$(f+6SjB77!SOMrFW0B*iA2cd znI0}{+b{5-gN7xOeQG|L4n-kEaRh$*WDpV{z$Q{R2F|!BF?V=NzUiVkQ1xpfvLu7I zMMUaIJDxIAGu?)YBin;)xTS3pMC-Ux?hbmF2S#}jWcl1~Jh-8{J6h{~;iphO$?t~3 z7m1g|`SJ7C5wrmQKde?ih&@OQLNMa4_G7^7(mgRjknFFIPuVg~6GW98sw1z7oFZ_O z5=9c#t$4sY2s6NczIm*2HtuasVS3w$%*Pe;KYi;b%E1-S6FgJ-%|J4FpGc$Zd*l=` z2HTkTxuW}ViL4SEiR3n(XXhA10y>5^QK9YPYUI6Tu&0h7IaS|!grrCm)F}`hL;Dzt zai%~6Qx|VHdccV)+k^{k)Co=`m~k(AdUW{X(<4xa6MnpS#zknqjxn5`Na2=e>0UX- zC}1Bb0Qzg^4!QyYw6-RAyU#04%qfDX|l>Nxl=Vz`bQ4tsy?Mk2~t zeNfpp3G3y?iCdGjx2que_lKZaJC(m*Ka41vEq7m!pInF&trKsx%}%{%0tP}=8{;l!nGhXs?#qNU zOzh#MI%CH00tUnn4+vLOJCLktTsM4~J!iU&#bVm1%tY`6NdXaiUhv4n2p*B6#jEQ( z#c0Np-*J89H7|$w#{$3BA#C!EdIRx+I7lyKSzl21))jz;B0&nE6RtHcSqh0IUybcI zNEbWLq-bR`J0n5BZ#+Z*fVt5hEYBLrZV8!1P1CUC{Nn;yqXpX&57SfAkD~zy3noxC zdfal>K{z!eK}0h^@$1p0x)R)cG5+dr5EKs8H@J!U^B539sc;?q>n0t{t?@zY8Y{eu zgSv^00_mNxW)38P86X1VvZe0T#Y%?;C#)y0sjt%-MIjQ2H`C@Ls3>*HM>eeqC~ z0#9^$_lOi8G6GUh_xwUkgJWUdoo`lG%!z5 zA6fcf5TubfTh+7akf#@dRr7Mm_QGD7?@o(4%GD{yeEJ%lWu^FtdjghOfcwGxoEx=teB?*0R6yAf-A$w$wsGVA^*g)`8 zezP9ftk$?A*u+Q=`ge<+TWM>yo@1^nD1s5V_qdz-afpJDiV}A_9zm%YtzcUgWWHy# z@cGs^JXOl1P4(6KWHp$%I|GN9Nc3kaitM&_nRgcaL05r%d=A5+ERa(`p^rdR|LO;73VkASv{D^;vh z1SOmO`ecT&Gf4!{(#b)+YYUk~e5Wy^S}Td`eugit%yb=1!9=2Au?<`QcwFEoXi8||!G=6$mvRzEgdqngEZ?zInJKvT-@;#J+64@Qh}NHkuWgw!Zt$C<<<#ewlv6(n5ax;^NGj*GcHl*8@;t zf$ruxg-vn9o@$rV3md-uu4@azG>boikKCfeBeFU%t%{q0^l0#Jy`b#UtX2uln*N!pPdeVuQt_Hm>QfU>V22&C9 z^grirN?`>4&zuz2D`)tyQ%3=7Juf9_x|Tzr z;cBt#Qs5gBNt7IbcM&mYsAMLmxRW;`-GbY=vBx1}zkup%jX`!OTS#Cp#7A56^;)k0 zDhMlWNOeTf#xR6n`Y~g|Xw(9V$m#?VVX&#@e7!Fb4U`FyLNvCNPrODJ*|i!|PrVN> zt_ETV8I~U&VD~)ZO17x(=T(IeAiY`>8lq#@9HOKoKp=P&g2237r<6YH;wOHdT=SG! zmQdZGM;=QUKX?5-#4ku?-P=8wO& zu+K5Um~|t}Uk(I0IttMhTy>Msm7;kPVNY>36k`!U2sVw(xh(Hf;uaFr+!k5mz58Hj z*n!)?dEEC-HYhAK$iWsQJDBTkIR-XNgV7X4d49NZRDmH|UpBQoM^?xLQL?*#X7P%0 zgU0LgkxI>wL|DCadbrotc(~#|PsS;dBNR-Aikn8JpBVvRBx|^jG92{=RWm!_p8Xw8 z<5*Fc5afJ!_s$aCaQ8oF<2hXtDTG`sF3#YLp5(O!166>65_n#pSc%5W6R7?=I1hb% z;(&ye+-&vn#Ce=vvu9`b`@B|&wa?V=0V#waS;J;XrmAOF2gCrK95cw!J!c;8&Ay?cdl}Ygl z)CAm~a%2Fgnn#qxi%5Cq=X>?V2)EQ;np@f2H@MU*uXeA~Ajuws;I1W(a7I*RK`_GS zYu>6*!*v9|SzxbiWYFvB0%Vd&{qdTCj=+lBE2lsQEXrbd`JrKYkezzL)@cBA!IQdu z1|!VaoRF63pAqBV&O8KxJtHQ&``{7}2q^l)!a_DP-bS(I$MW5QAD^}aCB5kR{{UG% z$tPS61U108k0d!H|CaPkjMi7;(B(xQ$p=wRc?tH9a z9oUKL7E4n?x-%{L!3L{10+S=0BK31A42DOL#d}@BL~EpDqzdRFVaKM;xZM&WC?wkN1DGH#bSsGZ4E8OAKVj&i+LJkec#sb zj2Wrlrc)uLQ`(*)zZlX-`Zat%czDP%0U%g~C9in)h^*tOP}}Xhm@54;5CNx9AE%)i zASmCXKi}T~0>=RRu<@cR2{9cK!|eY6t>wYBPB8qRRxv)t*SGgsTp1t;2ZYo7;f-Re zE*znKKXrx{Vlb-JVQZj9Y)EDanu5Kn5GDj*L<7^lcxop$$11^nH!&aIdGy*Iv0q~k zt>S>}GgH~)b;q^fL?KXA#@XoCGjL0k3Z@34BKee~kBs1%?vi`^IbyG&&;9ERJs=H9 z1%}u=m>wLFp(yE(hF-Pno>1TZ37w~-^lJw|hTy+=teF*5r`Y}U#a3LH5{yDIF&=RA zKwE%Ah`tEt*C<60+?Bl_+3S}lS73l*qGz{U_}71V&G?SQ?W5cNkWWK}3lErA z>5w66Q%P6~~#LT;0FV(*FQ| z=Ft8}|HJ?&5CH)J0RaI400II60s;d8009vpF#thPVR1l#5Rp)!vB4nG;qd?300;pA z00BP`{{SIR&}|hZb3if+l#NxS#sKI3C@Vq2OaMBs&pAOp01N#p?yOROz)F8%KmP!` z;+>rRAsiu+Ejb%j>dAnI&xB*TRV{Nkk_|yB78GAh{sA*S@(D)a^% zh18JcQ5OP&#lByja-}68%6=d72QgO%Q}_XY*SX*ikN4r7T=`aC{2Bx%nLoP_QGcA- z;edbC*}@Nhd*zS@=_(L(FkGUg_avA%{r><5^W*_J5^JuK{Uz<5XPidK3|*lOx2MFI z?%$-MRLs{}#&_TbtiX!_Q4X`i$UPwjZFiM}z!^%7okbm?{Uc^^-*HF71&{Kgt6vAw zN&rW8FXlh*o-=(STm%Fg2sQ`OM{DSy!8+mA!zzv)$Bafmjee}KWwEIW3h|~V&-ecT zfMa_@gVx|us2^YW0&*4r1tA!pOTRpAO<)KSm@0Gy%Ac_mSK8aoAdYX1335Up3(x^* zKKVi=CnR+Mi3EXsttvG~)xv*}}{jtUTfRZs|Eh&e@s1gmudOJSa=5E>+5Ls3dfLG6JF$q;~m zF+nICGV(UPUZ_|*Q(_kaR=^tQ?t&a3HnTvAK>Eq+$xzaDtdxtqqWUw5>FWv%!MJl~ppu6^1Y8pV$eO(hC{CJ4AV8oi-;wqt z)?5lGED>^)XLe3VAS|Mw0<| zLW<%7O6QUInJ9y9GpYm+6#5Md07!~g2wd@M3Zy7O#;6@A1@l;CL^TPs^;@xrhY28# zU;+&^y~6pmg#7?SVkW>Sm?tAS7pax+P)i9&(g!dFOty$7iaIH|AyLH) zt1vL2G!~C-S*D6{0UjxY% zh&m!7KjoVn6*`SrSl4uNod;%;KCCidD52k@@96I%ToLLh1)`7^=dJL{bZ+ zFnDl2a*(l}I;afg`g!tM4M)%^%N!(;MB%&4L5_mXR&zrV3b`Z=#xVZ?)5WS9LWPTc z0Cz#)(dIA=G!syDQkTjxgM)1_lY*l8ub9!e;hL+N^I3WK3BsQd}fdG_3 zpi@s!pK>D9iqRO|3FA?{hR9%1)vgnsErE46;Q+l}jPH$y*OFV1DU|3##kJe6jGtzx zFevg&LcA2>Q9}`EE6pe96et9Z{#n5DA*W@DA^8PBHgqG1OAu?|h3`(!I8n+cLIJVS zCEz}VKA@#YKoX>=5a~OM-$0_o2k=5ibExq03RD3c#)wol#E6Pf51J4F5h=zq5+)P< z-YBWJ)gQQDFtz9Pa`VZJH43@6V+*#~7+KEc1ocu55R07}SSn;QxkEIi=L zUjuPb(29Y7sG*`BKTDqk2?1wnaX2}Cjh+ZT(LoZ|niX{cA|hbFl5{`GLn?TgC4ZEK zCR82>s55~ntnjE~Ab{|x0*Iii`jh8?=yU=dY^ax%eP`sbC8h!?Qn%scX*sK!%StAt z{11W%R`KwfFS4Aw?X|Ew+%zpj`dbF?Wdp5Rhu6Q~ih?a0U=o!{s;>ESq8SWSjueIY zPbC6^lmT#Z7{n)%QpJY=r@=*V+&lq*$blIY`@Q(Dx~$uPJjJE5Xl(V6X7v=Hdp2+b zH_UKKRE?#jT|eok1qK2J08PCalRdPn7||lb15EG5;Jvua)dVzZm$S>r8EU`;04OAN zxX)q0=h9%usDw;BRSz~#ARrST$j^<&2#g?NNgbx#$YQf(EJ=w{2(S~7M=UC(AOT5R z11sP@Vd^*m_5T1BHWDG2q@ezk{{XYXM@X<}7+}=Yc2y)3=&CYuXp#znqm8vIh6#X} z(g_{$ul+fM1Y4jF|Hs z#;3RdoUWmDegn0h$%p}@DD(wZAj?>}4oW7WF2BEgzGTLu&;_``#9btQsWJd`(u05X z<4%@jvMGvuJRz7XL+M%qx&t!p^ChY!fH5!vy@uy;CzOI<%?waZ&3Q2HBq<7SDdqVp ztJn^VmJSb-y8ChDU#&|lh1yV~;e86^f+$GAi3$1-4duWZkZkM3cHma`@FYB8uHg6> z)>*N(oe2@&&jqa3QblK2FNjYUgo>(xHPCUC6hC~{G$PL&00FM3zK}o} z95eu8;$XDd1=-P6T!yG-YIx+{pE@oq>GLDI=dR=Q5$GnMogI9~c-K}c@RENHdSEv6 zx}GIU>H_|;1(CuHF#toa!5~$a6Ch9lu>Q1>@w0yh><`YrbG|-Rc*jgF6?^d6JM`OP z1?Wv|E(&?1zYv8nF+o@O5>zE&P?ZTWoC=xtcu`O*F9}3E6^}fRLfHz60C{~RzWt3F zjEF{1_&XdWd+jHN*I1?oCzL%XJ=n1VAT&v+%IPPmKq$cA*Mc#w1*F2mOQ8gM-0M~Y zpb7+rv|cuBhJXR^;bjJc-}t6Wp)yn-1Ap5801~J!AgQYl=fccVsv|-eeJjL=jI{K^ zs+!5qOV3tQ7)g!xKq7=o2#%P56fOu9Nv!eJ9rdRGg7E%_&o-wawFZ2em@M2@B4R1n z1X09MP*;i3mAZm{5QL63K0A{pxDW^ivypy21yX}BAE27SRxF-ZQbCtcQ7E(cJa`h% zq9}2$h=+5|i8Q>wkw_}nv#3N6(TY}~3)K7hY(ODWuqQpkiAxfAs8?r}2B9Yfm-E`j z2#Qds2K+yQbJ~Iqe1?N|aQp`;Tb zdzgpU+64yzh;c%G1 zr(ME1Wd;KR4?l`+P?|qXWi&(|GYm_rt+(y}02@H~XpPMU6&D07k)!Tq7BH&s3A1#E z1hj+(D$DXu2?dgrC;<5Fey;kBzMv?A83jP3{ycTDZ)!1$5b6B|YzT+|Bvi%edi?LO zfKL-C8&lzqJ|4a7P?aE97Hd@#%#-a&LnhnP4TN*lVH-tBqMWlBMSL-qAPh8}BUI#@ zUQ~?za*#2v{{Ue49c2SFD5!G2e|}8#5!_L0^;^ljr1g$-iXj>}e{TZdst!^KA}X^- zP4IrH%4gCb4%WK9P-Z+*M+i?dQLe+P5kle%P#Typ_?`w3VdyIProffjk4`7h=`W&z8YEY-e3b4E&+u2n1t7Et%ckZ& zOuH&Fh!F-Rne?eyJU+TDm`JVS)p{2!OC_@igvMC=E1CdB5m5=Z*SOeG%? zcp@X&5NXvPMDT(BArpigJihlAnnvixtWvYoDQptRHcDQlF)129L?&Rp50K?ldKOwv z$Ru3g_|TeafreNm@P87GQS=p+_ShJ<57J%P=*}1tnuddeHLt11VGx$CLTEpZl%l(1 zOmK+5clh-1pmjh|NGmXKGWsHjFMv%1sqv7*;!3u zw&e>ykKSZY>p)X8(<2k=ALmQuq*KBS`G*_^KO8MfKD{wp&Rf}0+0tlYGUuu_sxhR z3lDVF{61Cr<>2-rfQI_lmRcXGt8wg96io*@)49D%lt zALK{y@|^(%8u|i80ErsHQQ7FRcaVrN<>5HFPoud7hNT2< zagQ(`#LJAz)OBT@N0t)zR554-Yy!a*gcw5+s372{LA>`_7` z=I4MSTFMatY6E6?vmExfU;tMHafoW(0xapl!N6X&fCyp`jde*+A%ERJEQmcj%zr<{ zMdEeU14Ka+o;*)2DQ$j*7U^4>c#SVRma7J;vhx7|f*03}EqE_#7p>6fjsf(bbLAzL z5duL65k4ys^fNt)blEtSqCji5LrjQ>N(-%3UxTrMAcLobOpm19y;KB(f{Z~@W8%5- ziJ*#Xg9-8Ts+3znKU*;eMAyYX0h&|<7$`tqk@qL8jSwBf0U=plCn*4+2wq@+`tqE? z4K`r_afwa=s0&y0Iyl%0fT2KW6-#jSX+?ql;I<4fbH-W1_~6$97rtJ~qAyAgwal(x zBQ2JyAUS~81Na!~ATdBE%MaWAuQ&i&3`6&W1B5VG^w|)sNP^ik^gwMW7?lQXB|x-S zoApweas-SPj`=qQR8$T$aFo9ocw69dg|qiy>T2{P$ih+7_&a|c z{{RsEZzDJn#XCQt6!Qfre%SqngM*^r2=Q^mgc7DWEqoWA$CY9KI_c1V(5poj`m7WJdvqQ9v-)odBfZ6x4uWbt|9Q;fXF$3;=RF zp_1x^fDlOrYn8>;#qrL*VgZK?r(r$^l02(GX|*MO4Z-u{`9VSoKYGW%XOSbnq(J<% zpWpT7&3K9sjnD!9*L;JOk)lkq@Ux#Y!Q~`}PL{N|3U=h)8hL$@r=@G#p5o$3+ z2A1XX!ixx12mqs7EZ~ma4`IY(_W&Ry6QVd6V46XrBgJIX9zbnfkRgY`eNSrX0)ToP zB=IRU&`BYjz5MU^slcZBkwSq3`u=?cJeT3K>(0Q;1GjvjJ!U(tsl%&bQ5c@2nCB>LXt zHN+x51tyl()&~?In7cgbX4e~P8mje%_2~sLrGap8>Omn7jrd5_Tu{B;9Y2?Y7e)+7 zs6IFAND!L@ipG~;>^U#bD6}!=pZzWW0Q>9f7jJ+S?Ee7S>cFs!!pBlc!qR0TF$h9F z3>C;C(HRrgQZC+5D2M9BkfJ{#g+c>(v9Zy~Ix6Wh7(hNK8afkESfPRbU_|hWSwjm} z)Fbuf(zQrf7evdD-W%qPQI~f|Pw`I~5d@+H!~KB~)AQ=k0y+SeG!T5t2NK0SZAOPr9$8?t$o%P{F&aWSDdTWxHgM5- z>z0WON|uaq!6(9e%t)Y#ZBP%H3$0OLju-&6q3z65fJR`9CFkR9@|933P}#t*=kQN- z`Iy{r+3$m zK>|yzkZ$;&O>Ca7NK3asD+5(ORKJDLYH zdMk@y{@16S>eMh2qE68o4#zx0l$a6t5f5Dr`;*URh^XMfsG&g1T5F$?4~BkwTtW(| z7e>tUjk2WL)G43hl2y>KNa`u4Jjr$%(Q0N0nuYEcp@aa{1}z7m@R7!jY|vQL4xj@S zI!{Kmq6S?32~ z#@(_+$7zp(B!#sG)$RfP2apm5q=V4KKd_+j@%V`pG}9YFSa{9b#UB*BJ22J$JWeQ7 zkTB5cV6K%N{IMybm_~}aVi4N_UsenKNYaqsCphcX1_YF^=!bnMuAiHfW3Y`I5$%IR zZ6Jh%L+~TU0ZO0%QRPP)25*j=DAkiL#Zm(leRv3zNALWePw)JQgovU$R1(#|1IMSY z&K2(kO(YNnAh8QcNeIw|3WvPR;IxCMh(AH~YbZi#97P;Y844aD%mRiIrZLo>l#o?3 z6wP!6AydE&${n!64hQ6uV{fq{%Cqvvrmp!)l0;N`alad%>B2@u3Ockcm5=o6M@q;R z3xbxVK1%xdc)_KuG&-p4QFf3Q|SA}05IVb zG`d6*dEI4~#kT?cK9k5**HS4#3$faKJcuYt!2yc!GrqD+GytFW1AE&(!p^#GCjtfl zhO0Y@uCvfxEhVV$v(lEH26DSJQBiH`J54$laE^;!6JjE$65{L_~xGO6V8+7kn;nT%MQ$aT`(P zknsapKEnb!Yb{n}NJ67jVG5S!F#;n1wSZ>m>iy)%Y>y%huL57cKd)GiTGqG?An>>& zsM~JHJrw9dfV9pz)%ySoQelLn;&=#=h8Pni1J>DC4;8l<5tr$)rBG@Bc5ze_ZXlGU zh38SV^36+6&>$GvK~2T_0}H5iBybEIZA+jaLd`t#yp&DNcoTq7`q3297 zBAokBL?t@`3wiUC{H-oB>XeQSPrsk1h;DM7sQ}`9exbgC@Tvo4L|E;4&sfyTIb}81 z(jQv9WcAskA}R`^`O-L!K@O|+x%_$4SB~&zjY=U!h-HUXHNs7Vb)Z^E)}Rpvbt+Pz z5I!g!4T2pZ03iYIg1n_9uCy($A75d1)bz_1NqrGxSc==4MU!c@?xMUY_E z8f*LO7mJ1`*Z_YAlb}0?rI;xU5GhFC5Z_2a6O^JLg#{edqOCxL1n}_DH7tR;@(Ai? zIq(Z213=tZE)t)hZH9gk(S;3c5Q07`Fo`8tp(~60K91PgpRg_c_I597o-W)Ove-I>YtIyk}1b`wo7f4XxOy9Q&DPYvT6qr0E0;rf)xbDlAC9Nt>B84F7 z)BgYhxlKw6BS9Qqo+X71jlx+nR&bp29{_<9@K2(|;E4H_KJTfk=M)F)q4EkzjlUET z)M=jDrG{VGd@=+c5{8SF2go&^LL+5cV?>u!B-awX(Ap6I!B{pAopa!I(tZRKxJ7H? zlnZFcW-3}SN_lCMl5A(RD%_yYI!Z(vAU;)FtyjjHj?0tkTNyG4K4-DgJ6JdaL_VI5 zF1{emLfnWXDE|P$k_ZCp00a5}58(d*gDvV@B|nfxx;^sb`RcP17LrGi_x|iWo!kNh}_I)IAhbVV^I>Q&Hse)RRlTQLe8QNl? zh}@nA6$ixs0EM1(B&LP>HF|^~2tm{_L1R8w`+xAskO9CNOTw{#za`JWqgz4nBvF6l zRe+mxF;)5rC(i!>!XO1+2dn_OMTT%+%YQ@uCDx!J-KYJ&vc=U?`~LvMO-(qkIzN#F je@`h|P&}~306jmM{{ZoS{{XK40P*dAcmDvN@<0FCsw3dI From f49feaad5b8580faf6a2403a7e12d82c1aee5d82 Mon Sep 17 00:00:00 2001 From: Spiri0 <69024222+Spiri0@users.noreply.github.com> Date: Fri, 22 Nov 2024 06:14:08 +0100 Subject: [PATCH 24/24] Update webgpu_struct_drawIndirect.html fix lint --- examples/webgpu_struct_drawIndirect.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webgpu_struct_drawIndirect.html b/examples/webgpu_struct_drawIndirect.html index 9f09c3316b9266..b9e19b94d82d13 100644 --- a/examples/webgpu_struct_drawIndirect.html +++ b/examples/webgpu_struct_drawIndirect.html @@ -55,7 +55,7 @@ async function init() { - await renderer.init(); + await renderer.init(); // geometry