{"ast":null,"code":"import { NodeMaterialBlock } from \"../nodeMaterialBlock.js\";\nimport { NodeMaterialBlockConnectionPointTypes } from \"../Enums/nodeMaterialBlockConnectionPointTypes.js\";\nimport { NodeMaterialBlockTargets } from \"../Enums/nodeMaterialBlockTargets.js\";\nimport { RegisterClass } from \"../../../Misc/typeStore.js\";\n/**\n * block used to Generate a Voronoi Noise Pattern\n */\nexport class VoronoiNoiseBlock extends NodeMaterialBlock {\n /**\n * Creates a new VoronoiNoiseBlock\n * @param name defines the block name\n */\n constructor(name) {\n super(name, NodeMaterialBlockTargets.Neutral);\n this.registerInput(\"seed\", NodeMaterialBlockConnectionPointTypes.Vector2);\n this.registerInput(\"offset\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerInput(\"density\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"output\", NodeMaterialBlockConnectionPointTypes.Float);\n this.registerOutput(\"cells\", NodeMaterialBlockConnectionPointTypes.Float);\n }\n /**\n * Gets the current class name\n * @returns the class name\n */\n getClassName() {\n return \"VoronoiNoiseBlock\";\n }\n /**\n * Gets the seed input component\n */\n get seed() {\n return this._inputs[0];\n }\n /**\n * Gets the offset input component\n */\n get offset() {\n return this._inputs[1];\n }\n /**\n * Gets the density input component\n */\n get density() {\n return this._inputs[2];\n }\n /**\n * Gets the output component\n */\n get output() {\n return this._outputs[0];\n }\n /**\n * Gets the output component\n */\n get cells() {\n return this._outputs[1];\n }\n _buildBlock(state) {\n super._buildBlock(state);\n if (!this.seed.isConnected) {\n return;\n }\n // Adapted from https://www.shadertoy.com/view/MslGD8\n let functionString = `vec2 voronoiRandom(vec2 p){\n p = vec2(dot(p,vec2(127.1,311.7)),dot(p,vec2(269.5,183.3)));\n return fract(sin(p)*18.5453);\n }\n `;\n if (state.shaderLanguage === 1 /* ShaderLanguage.WGSL */) {\n functionString = state._babylonSLtoWGSL(functionString);\n }\n state._emitFunction(\"voronoiRandom\", functionString, \"// Voronoi random generator\");\n functionString = `void voronoi(vec2 seed, float offset, float density, out float outValue, out float cells){\n vec2 n = floor(seed * density);\n vec2 f = fract(seed * density);\n vec3 m = vec3( 8.0 );\n for( int j=-1; j<=1; j++ ){\n for( int i=-1; i<=1; i++ ){\n vec2 g = vec2( float(i), float(j) );\n vec2 o = voronoiRandom( n + g);\n vec2 r = g - f + (0.5+0.5*sin(offset+6.2831*o));\n float d = dot( r, r );\n if( d