@paper-design/shaders 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/shader-mount.ts", "../src/shaders/grain-clouds.ts", "../src/shaders/mesh-gradient.ts", "../src/shaders/smoke-ring.ts", "../src/shaders/neuro-noise.ts", "../src/shaders/dots-orbit.ts", "../src/shaders/stepped-simplex-noise.ts", "../src/get-shader-color-from-string.ts"],
4
- "sourcesContent": ["export class ShaderMount {\n private canvas: HTMLCanvasElement;\n private gl: WebGLRenderingContext;\n private program: WebGLProgram | null = null;\n private uniformLocations: Record<string, WebGLUniformLocation | null> = {};\n /** The fragment shader that we are using */\n private fragmentShader: string;\n /** Stores the RAF for the render loop */\n private rafId: number | null = null;\n /** Time of the last rendered frame */\n private lastFrameTime = 0;\n /** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */\n private totalAnimationTime = 0;\n /** The current speed that we progress through animation time (multiplies by delta time every update). Allows negatives to play in reverse. If set to 0, rAF will stop entirely so static shaders have no recurring performance costs */\n private speed = 1;\n /** Uniforms that are provided by the user for the specific shader being mounted (not including uniforms that this Mount adds, like time and resolution) */\n private providedUniforms: Record<string, number | number[]>;\n /** Just a sanity check to make sure frames don't run after we're disposed */\n private hasBeenDisposed = false;\n /** If the resolution of the canvas has changed since the last render */\n private resolutionChanged = true;\n\n constructor(\n canvas: HTMLCanvasElement,\n fragmentShader: string,\n uniforms: Record<string, number | number[]> = {},\n webGlContextAttributes?: WebGLContextAttributes,\n speed = 1\n ) {\n this.canvas = canvas;\n this.fragmentShader = fragmentShader;\n this.providedUniforms = uniforms;\n\n const gl = canvas.getContext('webgl', webGlContextAttributes);\n if (!gl) {\n throw new Error('WebGL not supported');\n }\n this.gl = gl;\n\n this.initWebGL();\n this.setupResizeObserver();\n\n // Set the animation speed after everything is ready to go\n this.setSpeed(speed);\n\n // Mark canvas as paper shader mount\n this.canvas.setAttribute('data-paper-shaders', 'true');\n }\n\n private initWebGL = () => {\n const program = createProgram(this.gl, vertexShaderSource, this.fragmentShader);\n if (!program) return;\n this.program = program;\n\n this.setupPositionAttribute();\n this.setupUniforms();\n };\n\n private setupPositionAttribute = () => {\n const positionAttributeLocation = this.gl.getAttribLocation(this.program!, 'a_position');\n const positionBuffer = this.gl.createBuffer();\n this.gl.bindBuffer(this.gl.ARRAY_BUFFER, positionBuffer);\n const positions = [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1];\n this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(positions), this.gl.STATIC_DRAW);\n this.gl.enableVertexAttribArray(positionAttributeLocation);\n this.gl.vertexAttribPointer(positionAttributeLocation, 2, this.gl.FLOAT, false, 0, 0);\n };\n\n private setupUniforms = () => {\n this.uniformLocations = {\n u_time: this.gl.getUniformLocation(this.program!, 'u_time'),\n u_resolution: this.gl.getUniformLocation(this.program!, 'u_resolution'),\n ...Object.fromEntries(\n Object.keys(this.providedUniforms).map((key) => [key, this.gl.getUniformLocation(this.program!, key)])\n ),\n };\n };\n\n private resizeObserver: ResizeObserver | null = null;\n private setupResizeObserver = () => {\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n this.resizeObserver.observe(this.canvas);\n this.handleResize();\n };\n\n private handleResize = () => {\n const pxRatio = Math.min(2, window.devicePixelRatio);\n const newWidth = this.canvas.clientWidth * pxRatio;\n const newHeight = this.canvas.clientHeight * pxRatio;\n if (this.canvas.width !== newWidth || this.canvas.height !== newHeight) {\n this.canvas.width = newWidth;\n this.canvas.height = newHeight;\n this.resolutionChanged = true;\n this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);\n this.render(performance.now());\n }\n };\n\n private render = (currentTime: number) => {\n if (this.hasBeenDisposed) return;\n\n // Calculate the delta time\n const dt = currentTime - this.lastFrameTime;\n this.lastFrameTime = currentTime;\n // Increase the total animation time by dt * animationSpeed\n if (this.speed !== 0) {\n this.totalAnimationTime += dt * this.speed;\n }\n\n // Update uniforms\n this.gl.useProgram(this.program);\n\n // Update the time uniform\n this.gl.uniform1f(this.uniformLocations.u_time!, this.totalAnimationTime * 0.001);\n\n // If the resolution has changed, we need to update the uniform\n if (this.resolutionChanged) {\n this.gl.uniform2f(this.uniformLocations.u_resolution!, this.gl.canvas.width, this.gl.canvas.height);\n this.resolutionChanged = false;\n }\n\n this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);\n\n // Loop if we're animating\n if (this.speed !== 0) {\n this.requestRender();\n } else {\n this.rafId = null;\n }\n };\n\n private requestRender = () => {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n }\n this.rafId = requestAnimationFrame(this.render);\n };\n\n private updateProvidedUniforms = () => {\n this.gl.useProgram(this.program);\n Object.entries(this.providedUniforms).forEach(([key, value]) => {\n const location = this.uniformLocations[key];\n if (location) {\n if (Array.isArray(value)) {\n switch (value.length) {\n case 2:\n this.gl.uniform2fv(location, value);\n break;\n case 3:\n this.gl.uniform3fv(location, value);\n break;\n case 4:\n this.gl.uniform4fv(location, value);\n break;\n default:\n if (value.length === 9) {\n this.gl.uniformMatrix3fv(location, false, value);\n } else if (value.length === 16) {\n this.gl.uniformMatrix4fv(location, false, value);\n } else {\n console.warn(`Unsupported uniform array length: ${value.length}`);\n }\n }\n } else if (typeof value === 'number') {\n this.gl.uniform1f(location, value);\n } else if (typeof value === 'boolean') {\n this.gl.uniform1i(location, value ? 1 : 0);\n } else {\n console.warn(`Unsupported uniform type for ${key}: ${typeof value}`);\n }\n }\n });\n };\n\n /** Set an animation speed (or 0 to stop animation) */\n public setSpeed = (newSpeed: number = 1): void => {\n // Set the new animation speed\n this.speed = newSpeed;\n\n if (this.rafId === null && newSpeed !== 0) {\n // Moving from 0 to animating, kick off a new rAF loop\n this.lastFrameTime = performance.now();\n this.rafId = requestAnimationFrame(this.render);\n }\n\n if (this.rafId !== null && newSpeed === 0) {\n // Moving from animating to not animating, cancel the rAF loop\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n };\n\n /** Update the uniforms that are provided by the outside shader */\n public setUniforms = (newUniforms: Record<string, number | number[]>): void => {\n this.providedUniforms = { ...this.providedUniforms, ...newUniforms };\n\n // If we need to allow users to add uniforms after the shader has been created, we can do that here\n // But right now we're expecting the uniform list to be predictable and static\n // this.setupUniforms();\n\n this.updateProvidedUniforms();\n this.render(performance.now());\n };\n\n /** Dispose of the shader mount, cleaning up all of the WebGL resources */\n public dispose = (): void => {\n // Immediately mark as disposed to prevent future renders from leaking in\n this.hasBeenDisposed = true;\n\n // Cancel the rAF loop\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n\n if (this.gl && this.program) {\n this.gl.deleteProgram(this.program);\n this.program = null;\n\n // Reset the WebGL context\n this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);\n this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, null);\n this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, null);\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null);\n\n // Clear any errors\n this.gl.getError();\n }\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n }\n\n this.uniformLocations = {};\n };\n}\n\n/** Vertex shader for the shader mount */\nconst vertexShaderSource = `\n attribute vec4 a_position;\n void main() {\n gl_Position = a_position;\n }\n`;\n\nfunction createShader(gl: WebGLRenderingContext, type: number, source: string): WebGLShader | null {\n const shader = gl.createShader(type);\n if (!shader) return null;\n\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n console.error('An error occurred compiling the shaders: ' + gl.getShaderInfoLog(shader));\n gl.deleteShader(shader);\n return null;\n }\n\n return shader;\n}\n\nfunction createProgram(\n gl: WebGLRenderingContext,\n vertexShaderSource: string,\n fragmentShaderSource: string\n): WebGLProgram | null {\n const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexShaderSource);\n const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);\n\n if (!vertexShader || !fragmentShader) return null;\n\n const program = gl.createProgram();\n if (!program) return null;\n\n gl.attachShader(program, vertexShader);\n gl.attachShader(program, fragmentShader);\n gl.linkProgram(program);\n\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n console.error('Unable to initialize the shader program: ' + gl.getProgramInfoLog(program));\n gl.deleteProgram(program);\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n return null;\n }\n\n // Clean up shaders after successful linking\n gl.detachShader(program, vertexShader);\n gl.detachShader(program, fragmentShader);\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n\n return program;\n}\n", "export type GrainCloudsUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_scale: number;\n u_grainAmount: number;\n};\n\n/**\n * Renders a grainy texture over top of blobby animated clouds\n * This is an example shader that we're using to bootstrap the project\n * Generated by Claude 3.5 Sonnet\n *\n * Uniforms include:\n * u_color1: The first color of the clouds\n * u_color2: The second color of the clouds\n * u_scale: The scale of the noise\n * u_grainAmount: The amount of grain on the texture\n */\nexport const grainCloudsFragmentShader = `\n precision highp float;\n uniform vec2 u_resolution;\n uniform float u_time;\n\n uniform vec4 u_color1;\n uniform vec4 u_color2;\n uniform float u_scale;\n uniform float u_grainAmount;\n\n // Simplex 2D noise\n vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n void main() {\n vec2 st = gl_FragCoord.xy / u_resolution.xy;\n\n // Calculate the aspect ratio of the shader\n float shaderAspect = u_resolution.x / u_resolution.y;\n\n // Define the aspect ratio of your content (e.g., 1.0 for square)\n float contentAspect = 1.0;\n\n // Adjust st to maintain content aspect ratio\n if (shaderAspect > contentAspect) {\n float scale = shaderAspect / contentAspect;\n st.x = (st.x - 0.5) * scale + 0.5;\n } else {\n float scale = contentAspect / shaderAspect;\n st.y = (st.y - 0.5) * scale + 0.5;\n }\n\n // Create blobby texture\n float n = snoise(st * u_scale + u_time);\n n += 0.5 * snoise(st * u_scale * 2.0 - u_time * 0.5);\n n += 0.25 * snoise(st * u_scale * 4.0 + u_time * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec4 color = mix(u_color1, u_color2, n);\n\n // Add grain\n float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);\n color += (grain - 0.5) * u_grainAmount;\n\n gl_FragColor = color;\n }\n`;\n", "export type MeshGradientUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n};\n\n/**\n * Mesh Gradient, based on https://www.shadertoy.com/view/wdyczG\n * Renders a mesh gradient with a rotating noise pattern\n * and several layers of fractal noise\n *\n * Uniforms include:\n * u_color1: The first color of the mesh gradient\n * u_color2: The second color of the mesh gradient\n * u_color3: The third color of the mesh gradient\n * u_color4: The fourth color of the mesh gradient\n */\n\nexport const meshGradientFragmentShader = `\n// Mesh Gradient: https://www.shadertoy.com/view/wdyczG\n#define S(a,b,t) smoothstep(a,b,t)\n\nprecision highp float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec2 u_resolution;\nuniform float u_time;\n\nmat2 Rot(float a)\n{\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\n}\n\n\nvec2 hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nfloat noise( in vec2 p )\n{\n vec2 i = floor( p );\n vec2 f = fract( p );\n\n\tvec2 u = f*f*(3.0-2.0*f);\n\n float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),\n mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);\n\treturn 0.5 + 0.5*n;\n}\n\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n vec2 tuv = uv;\n tuv -= .5;\n\n // rotate with Noise\n float degree = noise(vec2(u_time, tuv.x * tuv.y));\n\n tuv.y *= 1./ratio;\n tuv *= Rot(radians((degree-.5)*720.+180.));\n\ttuv.y *= ratio;\n\n\n // Wave warp with sin\n float frequency = 5.;\n float amplitude = 30.;\n float speed = u_time * 2.;\n tuv.x += sin(tuv.y*frequency+speed)/amplitude;\n \ttuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n // draw the image\n vec4 layer1 = mix(u_color1, u_color2, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n vec4 layer2 = mix(u_color3, u_color4, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n\n vec4 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));\n gl_FragColor = finalComp;\n}\n`;\n", "export type SmokeRingUniforms = {\n u_colorBack: [number, number, number, number];\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_scale: number;\n u_thickness: number;\n};\n\n/**\n * Smoke Ring, based on https://codepen.io/ksenia-k/full/zYyqRWE\n * Renders a fractional Brownian motion (fBm) noise over the\n * polar coordinates masked with ring shape\n *\n * Uniforms include:\n * u_colorBack: The back color of the scene\n * u_color1: Main color of the ring\n * u_color2: The third color of the mesh gradient\n * u_color4: The fourth color of the mesh gradient\n * u_scale: The scale of the noise\n * u_thickness: The thickness of the ring\n */\n\nexport const smokeRingFragmentShader = `\n\n precision highp float;\n\n uniform vec4 u_colorBack;\n uniform vec4 u_color1;\n uniform vec4 u_color2;\n uniform float u_scale;\n uniform float u_thickness;\n uniform vec2 u_resolution;\n uniform float u_time;\n\n #define TWO_PI 6.28318530718\n #define PI 3.14159265358979323846\n\n float rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n }\n float noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n }\n float fbm(vec2 n) {\n float total = 0.0, amplitude = .4;\n for (int i = 0; i < 12; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.6;\n }\n return total;\n }\n\n float get_ring_shape(vec2 uv, float innerRadius, float outerRadius) {\n float distance = length(uv);\n float line_width = outerRadius - innerRadius;\n float ringValue = smoothstep(innerRadius, innerRadius + .8 * line_width, distance);\n ringValue -= smoothstep(outerRadius, outerRadius + 1.2 * line_width, distance);\n return clamp(ringValue, 0., 1.);\n }\n\n void main() {\n\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n uv -= .5;\n uv *= 2.;\n uv.x *= ratio;\n\n float t = u_time;\n\n float atg = atan(uv.y, uv.x);\n float angle = (atg + PI) / TWO_PI;\n\n vec2 polar_uv = vec2(atg, .1 * t - (.5 * length(uv)) + 1. / pow(length(uv), .5));\n polar_uv *= u_scale;\n\n float noise_left = fbm(polar_uv + .05 * t);\n polar_uv.x = mod(polar_uv.x, u_scale * TWO_PI);\n float noise_right = fbm(polar_uv + .05 * t);\n float noise = mix(noise_right, noise_left, smoothstep(-.2, .2, uv.x));\n\n float center_shape = 1. - pow(smoothstep(2., .0, length(uv)), 50.);\n\n float radius = .4 - .25 * u_thickness;\n float thickness = u_thickness;\n thickness = pow(thickness, 2.);\n\n float ring_shape = get_ring_shape(uv * (.5 + .6 * noise), radius - .2 * thickness, radius + .5 * thickness);\n ring_shape = clamp(ring_shape, 0., 1.);\n \n float ring_shape_outer = 1. - pow(ring_shape, 7.);\n ring_shape_outer *= ring_shape;\n \n float ring_shape_inner = ring_shape - ring_shape_outer;\n ring_shape_inner *= ring_shape;\n\n ring_shape_outer *= u_color2.a;\n ring_shape_inner *= u_color1.a;\n\n float background = 1. - ring_shape;\n background *= u_colorBack.a;\n \n vec3 color = u_color2.rgb * ring_shape_outer;\n color += u_color1.rgb * ring_shape_inner;\n color += u_colorBack.rgb * background;\n \n float opacity = ring_shape_outer;\n opacity += ring_shape_inner;\n opacity += background;\n \n gl_FragColor = vec4(color, opacity);\n }\n`;\n", "export type NeuroNoiseUniforms = {\n u_colorFront: [number, number, number, number];\n u_colorBack: [number, number, number, number];\n u_scale: number;\n u_brightness: number;\n};\n\n/**\n * Neuro Noise Pattern;\n * The original artwork: https://codepen.io/ksenia-k/full/vYwgrWv by Ksenia Kondrashova\n * Renders a fractal-like structure made of several layers of since-arches\n *\n * Uniforms include:\n * u_colorFront: The front color of pattern\n * u_colorBack: The back color of pattern\n * u_brightness: The power/brightness of pattern lines\n * u_scale: The scale applied to coordinates\n */\n\nexport const neuroNoiseFragmentShader = `\nprecision mediump float;\n\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_scale;\nuniform float u_brightness;\n\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat neuro_shape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n vec3 color = vec3(0.);\n\n float noise = neuro_shape(uv, t);\n\n noise = u_brightness * pow(noise, 3.);\n noise += pow(noise, 12.);\n noise = max(.0, noise - .5);\n\n gl_FragColor = mix(u_colorBack, u_colorFront, noise);\n}\n`;\n", "export type DotsOrbitUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n u_scale: number;\n u_dotSize: number;\n u_dotSizeRange: number;\n u_spreading: number;\n};\n\n/**\n * Dots Pattern with dots moving around their grid position\n * The artwork by Ksenia Kondrashova\n * Renders a dot pattern with dots placed in the center of each cell of animated Voronoi diagram\n *\n * Uniforms include:\n * u_color1: The first dots color\n * u_color2: The second dots color\n * u_color3: The third dots color\n * u_color4: The fourth dots color\n * u_scale: The scale applied to pattern\n * u_dotSize: The base dot radius (relative to cell size)\n * u_dotSizeRange: Dot radius to vary between the cells\n * u_spreading: How far dots are moving around the straight grid\n */\n\nexport const dotsOrbitFragmentShader = `\nprecision mediump float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform float u_dotSize;\nuniform float u_dotSizeRange;\nuniform float u_scale;\nuniform float u_spreading;\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nvec2 random2(vec2 p) {\n return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);\n}\n\nvec3 get_voronoi_shape(vec2 _uv, float time) {\n vec2 i_uv = floor(_uv);\n vec2 f_uv = fract(_uv);\n\n float min_dist = 1.;\n vec2 cell_randomizer = vec2(0.);\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 tile_offset = vec2(float(x), float(y));\n vec2 rand = random2(i_uv + tile_offset);\n vec2 cell_center = .5 + u_spreading * sin(time + PI * 2. * rand);\n float dist = length(tile_offset + cell_center - f_uv);\n if (dist < min_dist) {\n min_dist = dist;\n cell_randomizer = rand;\n }\n min_dist = min(min_dist, dist);\n }\n }\n\n return vec3(min_dist, cell_randomizer);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n\n vec3 voronoi = get_voronoi_shape(uv, t);\n float radius = u_dotSize - u_dotSizeRange * voronoi[2];\n\n float radius_smoother = .001 + .001 * (u_scale - 1.);\n float shape = 1. - smoothstep(radius, radius + radius_smoother, voronoi[0]);\n\n float color_randomizer = voronoi[1];\n vec4 color =\n u_color1 * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +\n u_color2 * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +\n u_color3 * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +\n u_color4 * step(0.75, color_randomizer) * step(color_randomizer, 1.0);\n\n gl_FragColor = color * shape;\n}\n`;\n", "export type SteppedSimplexNoiseUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n u_color5: [number, number, number, number];\n u_scale: number;\n u_steps_number: number;\n};\n\n/**\n * Stepped Simplex Noise by Ksenia Kondrashova\n * Calculates a combination of 2 simplex noises with result rendered as a stepped gradient\n *\n * Uniforms include:\n * u_color1: The first color\n * u_color2: The second color\n * u_color3: The third color\n * u_color4: The fourth color\n * u_color5: The fifth color\n * u_scale: The scale applied to coordinates\n * u_steps_number: The number of colors to show as a stepped gradient\n */\n\nexport const steppedSimplexNoiseFragmentShader = `\nprecision highp float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec4 u_color5;\nuniform float u_scale;\nuniform float u_steps_number;\n\nuniform float u_time;\nuniform vec2 u_resolution;\n\n\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\nfloat snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),\n dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n}\n\nfloat get_noise(vec2 uv, float t) {\n float noise = .5 * snoise(uv - vec2(0., .3 * t));\n noise += .5 * snoise(2. * uv + vec2(0., .32 * t));\n\n return noise;\n}\n\nvec4 getColor(int index) {\n if (index == 0) return u_color1;\n if (index == 1) return u_color2;\n if (index == 2) return u_color3;\n if (index == 3) return u_color4;\n if (index == 4) return u_color5;\n return u_color1;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n\n float noise = .5 + .5 * get_noise(uv, t);\n noise = floor(noise * u_steps_number) / u_steps_number;\n\n vec4 col = u_color1;\n for (int i = 0; i < 5; i++) {\n vec4 next_col = getColor(i + 1);\n col = mix(col, next_col, smoothstep((float(i) + .5) / 5., (float(i) + 2.) / 5., noise));\n }\n gl_FragColor = col;\n}\n`;\n", "/** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGBA array */\nexport function getShaderColorFromString(\n colorString: string | [number, number, number] | [number, number, number, number] | undefined,\n fallback: string | [number, number, number] | [number, number, number, number] = [0, 0, 0, 1]\n): [number, number, number, number] {\n // If the color string is already an array of 3 or 4 numbers, return it (with alpha=1 if needed)\n if (Array.isArray(colorString)) {\n if (colorString.length === 4) return colorString as [number, number, number, number];\n if (colorString.length === 3) return [...colorString, 1];\n return getShaderColorFromString(fallback);\n }\n\n // If the color string is not a string, return the fallback\n if (typeof colorString !== 'string') {\n return getShaderColorFromString(fallback);\n }\n\n let r: number,\n g: number,\n b: number,\n a = 1;\n if (colorString.startsWith('#')) {\n [r, g, b, a] = hexToRgba(colorString);\n } else if (colorString.startsWith('rgb')) {\n [r, g, b, a] = parseRgba(colorString);\n } else if (colorString.startsWith('hsl')) {\n [r, g, b, a] = hslaToRgba(parseHsla(colorString));\n } else {\n console.error('Unsupported color format', colorString);\n return getShaderColorFromString(fallback);\n }\n\n return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];\n}\n\n/** Convert hex to RGBA (0 to 1 range) */\nfunction hexToRgba(hex: string): [number, number, number, number] {\n // Remove # if present\n hex = hex.replace(/^#/, '');\n\n // Expand three-letter hex to six-letter\n if (hex.length === 3) {\n hex = hex\n .split('')\n .map((char) => char + char)\n .join('');\n }\n // Expand six-letter hex to eight-letter (add full opacity if no alpha)\n if (hex.length === 6) {\n hex = hex + 'ff';\n }\n\n // Parse the components\n const r = parseInt(hex.slice(0, 2), 16) / 255;\n const g = parseInt(hex.slice(2, 4), 16) / 255;\n const b = parseInt(hex.slice(4, 6), 16) / 255;\n const a = parseInt(hex.slice(6, 8), 16) / 255;\n\n return [r, g, b, a];\n}\n\n/** Parse RGBA string to RGBA (0 to 1 range) */\nfunction parseRgba(rgba: string): [number, number, number, number] {\n // Match both rgb and rgba patterns\n const match = rgba.match(/^rgba?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*([0-9.]+))?\\s*\\)$/i);\n if (!match) return [0, 0, 0, 1];\n\n return [\n parseInt(match[1] ?? '0') / 255,\n parseInt(match[2] ?? '0') / 255,\n parseInt(match[3] ?? '0') / 255,\n match[4] === undefined ? 1 : parseFloat(match[4]),\n ];\n}\n\n/** Parse HSLA string */\nfunction parseHsla(hsla: string): [number, number, number, number] {\n const match = hsla.match(/^hsla?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)%\\s*,\\s*(\\d+)%\\s*(?:,\\s*([0-9.]+))?\\s*\\)$/i);\n if (!match) return [0, 0, 0, 1];\n\n return [\n parseInt(match[1] ?? '0'),\n parseInt(match[2] ?? '0'),\n parseInt(match[3] ?? '0'),\n match[4] === undefined ? 1 : parseFloat(match[4]),\n ];\n}\n\n/** Convert HSLA to RGBA (0 to 1 range) */\nfunction hslaToRgba(hsla: [number, number, number, number]): [number, number, number, number] {\n const [h, s, l, a] = hsla;\n const hDecimal = h / 360;\n const sDecimal = s / 100;\n const lDecimal = l / 100;\n let r, g, b;\n\n if (s === 0) {\n r = g = b = lDecimal; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n\n const q = lDecimal < 0.5 ? lDecimal * (1 + sDecimal) : lDecimal + sDecimal - lDecimal * sDecimal;\n const p = 2 * lDecimal - q;\n r = hue2rgb(p, q, hDecimal + 1 / 3);\n g = hue2rgb(p, q, hDecimal);\n b = hue2rgb(p, q, hDecimal - 1 / 3);\n }\n\n return [r, g, b, a];\n}\n\nexport const clamp = (n: number, min: number, max: number): number => Math.min(Math.max(n, min), max);\n"],
5
- "mappings": ";AAAO,IAAMA,EAAN,KAAkB,CACf,OACA,GACA,QAA+B,KAC/B,iBAAgE,CAAC,EAEjE,eAEA,MAAuB,KAEvB,cAAgB,EAEhB,mBAAqB,EAErB,MAAQ,EAER,iBAEA,gBAAkB,GAElB,kBAAoB,GAE5B,YACEC,EACAC,EACAC,EAA8C,CAAC,EAC/CC,EACAC,EAAQ,EACR,CACA,KAAK,OAASJ,EACd,KAAK,eAAiBC,EACtB,KAAK,iBAAmBC,EAExB,IAAMG,EAAKL,EAAO,WAAW,QAASG,CAAsB,EAC5D,GAAI,CAACE,EACH,MAAM,IAAI,MAAM,qBAAqB,EAEvC,KAAK,GAAKA,EAEV,KAAK,UAAU,EACf,KAAK,oBAAoB,EAGzB,KAAK,SAASD,CAAK,EAGnB,KAAK,OAAO,aAAa,qBAAs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,GAAcD,EAClBC,EAAI,kBAAcF,GAAKC,EAAID,IAAM,kBAAQE,GAAK,EAC3CF,GAGHC,EAAIH,EAAW,GAAMA,GAAY,EAAID,GAAYC,EAAWD,EAAWC,EAAWD,EAClFG,EAAI,EAAIF,EAAWG,EACzBtB,EAAIoB,EAAQC,EAAGC,EAAGL,EAAW,EAAI,CAAC,EAClChB,EAAImB,EAAQC,EAAGC,EAAGL,CAAQ,EAC1Bf,EAAIkB,EAAQC,EAAGC,EAAGL,EAAW,EAAI,CAAC,CACpC,CAEA,MAAO,CAACjB,EAAGC,EAAGC,EAAGC,CAAC,CACpB,CAEO,IAAMK,EAAQ,CAACgB,EAAWC,EAAaC,IAAwB,KAAK,IAAI,KAAK,IAAIF,EAAGC,CAAG,EAAGC,CAAG",
6
- "names": ["ShaderMount", "canvas", "fragmentShader", "uniforms", "webGlContextAttributes", "speed", "gl", "program", "createProgram", "vertexShaderSource", "positionAttributeLocation", "positionBuffer", "positions", "key", "pxRatio", "newWidth", "newHeight", "currentTime", "dt", "value", "location", "newSpeed", "newUniforms", "createShader", "type", "source", "shader", "fragmentShaderSource", "vertexShader", "grainCloudsFragmentShader", "meshGradientFragmentShader", "smokeRingFragmentShader", "neuroNoiseFragmentShader", "dotsOrbitFragmentShader", "steppedSimplexNoiseFragmentShader", "getShaderColorFromString", "colorString", "fallback", "r", "g", "b", "a", "hexToRgba", "parseRgba", "hslaToRgba", "parseHsla", "clamp", "hex", "char", "rgba", "match", "hsla", "h", "s", "l", "hDecimal", "sDecimal", "lDecimal", "hue2rgb", "p", "q", "t", "n", "min", "max"]
3
+ "sources": ["../src/shader-mount.ts", "../src/shaders/grain-clouds.ts", "../src/shaders/mesh-gradient.ts", "../src/shaders/smoke-ring.ts", "../src/shaders/neuro-noise.ts", "../src/shaders/dots-orbit.ts", "../src/shaders/dots-grid.ts", "../src/shaders/stepped-simplex-noise.ts", "../src/shaders/metaballs.ts", "../src/shaders/perlin-noise.ts", "../src/shaders/voronoi.ts", "../src/shaders/waves.ts", "../src/get-shader-color-from-string.ts"],
4
+ "sourcesContent": ["export class ShaderMount {\n private canvas: HTMLCanvasElement;\n private gl: WebGLRenderingContext;\n private program: WebGLProgram | null = null;\n private uniformLocations: Record<string, WebGLUniformLocation | null> = {};\n /** The fragment shader that we are using */\n private fragmentShader: string;\n /** Stores the RAF for the render loop */\n private rafId: number | null = null;\n /** Time of the last rendered frame */\n private lastFrameTime = 0;\n /** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */\n private totalAnimationTime = 0;\n /** The current speed that we progress through animation time (multiplies by delta time every update). Allows negatives to play in reverse. If set to 0, rAF will stop entirely so static shaders have no recurring performance costs */\n private speed = 1;\n /** Uniforms that are provided by the user for the specific shader being mounted (not including uniforms that this Mount adds, like time and resolution) */\n private providedUniforms: Record<string, number | number[]>;\n /** Just a sanity check to make sure frames don't run after we're disposed */\n private hasBeenDisposed = false;\n /** If the resolution of the canvas has changed since the last render */\n private resolutionChanged = true;\n\n constructor(\n canvas: HTMLCanvasElement,\n fragmentShader: string,\n uniforms: Record<string, number | number[]> = {},\n webGlContextAttributes?: WebGLContextAttributes,\n /** The speed of the animation, or 0 to stop it. Supports negative values to play in reverse. */\n speed = 1,\n /** Pass a seed to offset the starting u_time value and give deterministic results*/\n seed = 0\n ) {\n this.canvas = canvas;\n this.fragmentShader = fragmentShader;\n this.providedUniforms = uniforms;\n // Base our starting animation time on the provided seed value\n this.totalAnimationTime = seed;\n\n const gl = canvas.getContext('webgl2', webGlContextAttributes);\n if (!gl) {\n throw new Error('WebGL not supported');\n }\n this.gl = gl;\n\n this.initWebGL();\n this.setupResizeObserver();\n\n // Set the animation speed after everything is ready to go\n this.setSpeed(speed);\n\n // Mark canvas as paper shader mount\n this.canvas.setAttribute('data-paper-shaders', 'true');\n }\n\n private initWebGL = () => {\n const program = createProgram(this.gl, vertexShaderSource, this.fragmentShader);\n if (!program) return;\n this.program = program;\n\n this.setupPositionAttribute();\n this.setupUniforms();\n };\n\n private setupPositionAttribute = () => {\n const positionAttributeLocation = this.gl.getAttribLocation(this.program!, 'a_position');\n const positionBuffer = this.gl.createBuffer();\n this.gl.bindBuffer(this.gl.ARRAY_BUFFER, positionBuffer);\n const positions = [-1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1];\n this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array(positions), this.gl.STATIC_DRAW);\n this.gl.enableVertexAttribArray(positionAttributeLocation);\n this.gl.vertexAttribPointer(positionAttributeLocation, 2, this.gl.FLOAT, false, 0, 0);\n };\n\n private setupUniforms = () => {\n this.uniformLocations = {\n u_time: this.gl.getUniformLocation(this.program!, 'u_time'),\n u_pixelRatio: this.gl.getUniformLocation(this.program!, 'u_pixelRatio'),\n u_resolution: this.gl.getUniformLocation(this.program!, 'u_resolution'),\n ...Object.fromEntries(\n Object.keys(this.providedUniforms).map((key) => [key, this.gl.getUniformLocation(this.program!, key)])\n ),\n };\n };\n\n private resizeObserver: ResizeObserver | null = null;\n private setupResizeObserver = () => {\n this.resizeObserver = new ResizeObserver(() => this.handleResize());\n this.resizeObserver.observe(this.canvas);\n this.handleResize();\n };\n\n private handleResize = () => {\n const pixelRatio = window.devicePixelRatio;\n const newWidth = this.canvas.clientWidth * pixelRatio;\n const newHeight = this.canvas.clientHeight * pixelRatio;\n if (this.canvas.width !== newWidth || this.canvas.height !== newHeight) {\n this.canvas.width = newWidth;\n this.canvas.height = newHeight;\n this.resolutionChanged = true;\n this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);\n this.render(performance.now()); // this is necessary to avoid flashes while resizing (the next scheduled render will set uniforms)\n }\n };\n\n private render = (currentTime: number) => {\n if (this.hasBeenDisposed) return;\n\n // Calculate the delta time\n const dt = currentTime - this.lastFrameTime;\n this.lastFrameTime = currentTime;\n // Increase the total animation time by dt * animationSpeed\n if (this.speed !== 0) {\n this.totalAnimationTime += dt * this.speed;\n }\n\n // Clear the canvas\n this.gl.clear(this.gl.COLOR_BUFFER_BIT);\n\n // Update uniforms\n this.gl.useProgram(this.program);\n\n // Update the time uniform\n this.gl.uniform1f(this.uniformLocations.u_time!, this.totalAnimationTime * 0.001);\n\n // If the resolution has changed, we need to update the uniform\n if (this.resolutionChanged) {\n this.gl.uniform2f(this.uniformLocations.u_resolution!, this.gl.canvas.width, this.gl.canvas.height);\n this.gl.uniform1f(this.uniformLocations.u_pixelRatio!, window.devicePixelRatio);\n this.resolutionChanged = false;\n }\n\n this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);\n\n // Loop if we're animating\n if (this.speed !== 0) {\n this.requestRender();\n } else {\n this.rafId = null;\n }\n };\n\n private requestRender = () => {\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n }\n this.rafId = requestAnimationFrame(this.render);\n };\n\n private updateProvidedUniforms = () => {\n this.gl.useProgram(this.program);\n Object.entries(this.providedUniforms).forEach(([key, value]) => {\n const location = this.uniformLocations[key];\n if (location) {\n if (Array.isArray(value)) {\n switch (value.length) {\n case 2:\n this.gl.uniform2fv(location, value);\n break;\n case 3:\n this.gl.uniform3fv(location, value);\n break;\n case 4:\n this.gl.uniform4fv(location, value);\n break;\n default:\n if (value.length === 9) {\n this.gl.uniformMatrix3fv(location, false, value);\n } else if (value.length === 16) {\n this.gl.uniformMatrix4fv(location, false, value);\n } else {\n console.warn(`Unsupported uniform array length: ${value.length}`);\n }\n }\n } else if (typeof value === 'number') {\n this.gl.uniform1f(location, value);\n } else if (typeof value === 'boolean') {\n this.gl.uniform1i(location, value ? 1 : 0);\n } else {\n console.warn(`Unsupported uniform type for ${key}: ${typeof value}`);\n }\n }\n });\n };\n\n /** Set a seed to get a deterministic result */\n public setSeed = (newSeed: number): void => {\n const oneFrameAt120Fps = 1000 / 120;\n this.totalAnimationTime = newSeed * oneFrameAt120Fps;\n this.lastFrameTime = performance.now();\n this.render(performance.now());\n };\n\n /** Set an animation speed (or 0 to stop animation) */\n public setSpeed = (newSpeed: number = 1): void => {\n // Set the new animation speed\n this.speed = newSpeed;\n\n if (this.rafId === null && newSpeed !== 0) {\n // Moving from 0 to animating, kick off a new rAF loop\n this.lastFrameTime = performance.now();\n this.rafId = requestAnimationFrame(this.render);\n }\n\n if (this.rafId !== null && newSpeed === 0) {\n // Moving from animating to not animating, cancel the rAF loop\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n };\n\n /** Update the uniforms that are provided by the outside shader */\n public setUniforms = (newUniforms: Record<string, number | number[]>): void => {\n this.providedUniforms = { ...this.providedUniforms, ...newUniforms };\n\n // If we need to allow users to add uniforms after the shader has been created, we can do that here\n // But right now we're expecting the uniform list to be predictable and static\n // this.setupUniforms();\n\n this.updateProvidedUniforms();\n this.render(performance.now());\n };\n\n /** Dispose of the shader mount, cleaning up all of the WebGL resources */\n public dispose = (): void => {\n // Immediately mark as disposed to prevent future renders from leaking in\n this.hasBeenDisposed = true;\n\n // Cancel the rAF loop\n if (this.rafId !== null) {\n cancelAnimationFrame(this.rafId);\n this.rafId = null;\n }\n\n if (this.gl && this.program) {\n this.gl.deleteProgram(this.program);\n this.program = null;\n\n // Reset the WebGL context\n this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null);\n this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, null);\n this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, null);\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null);\n\n // Clear any errors\n this.gl.getError();\n }\n\n if (this.resizeObserver) {\n this.resizeObserver.disconnect();\n this.resizeObserver = null;\n }\n\n this.uniformLocations = {};\n };\n}\n\n/** Vertex shader for the shader mount */\nconst vertexShaderSource = `#version 300 es\nlayout(location = 0) in vec4 a_position;\n\nvoid main() {\n gl_Position = a_position;\n}\n`;\n\nfunction createShader(gl: WebGLRenderingContext, type: number, source: string): WebGLShader | null {\n const shader = gl.createShader(type);\n if (!shader) return null;\n\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n console.error('An error occurred compiling the shaders: ' + gl.getShaderInfoLog(shader));\n gl.deleteShader(shader);\n return null;\n }\n\n return shader;\n}\n\nfunction createProgram(\n gl: WebGLRenderingContext,\n vertexShaderSource: string,\n fragmentShaderSource: string\n): WebGLProgram | null {\n const vertexShader = createShader(gl, gl.VERTEX_SHADER, vertexShaderSource);\n const fragmentShader = createShader(gl, gl.FRAGMENT_SHADER, fragmentShaderSource);\n\n if (!vertexShader || !fragmentShader) return null;\n\n const program = gl.createProgram();\n if (!program) return null;\n\n gl.attachShader(program, vertexShader);\n gl.attachShader(program, fragmentShader);\n gl.linkProgram(program);\n\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n console.error('Unable to initialize the shader program: ' + gl.getProgramInfoLog(program));\n gl.deleteProgram(program);\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n return null;\n }\n\n // Clean up shaders after successful linking\n gl.detachShader(program, vertexShader);\n gl.detachShader(program, fragmentShader);\n gl.deleteShader(vertexShader);\n gl.deleteShader(fragmentShader);\n\n return program;\n}\n", "export type GrainCloudsUniforms = {\n u_scale: number;\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_grainAmount: number;\n};\n\n/**\n * Renders a grainy texture over top of blobby animated clouds\n * This is an example shader that we're using to bootstrap the project\n * Generated by Claude 3.5 Sonnet\n *\n * Uniforms include:\n * u_scale - the scale applied to user space\n * u_color1 - the first mixed color\n * u_color2 - the second mixed color\n * u_grainAmount - the power of overlapping grain texture\n */\n\nexport const grainCloudsFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_time;\n\nuniform float u_scale;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform float u_grainAmount;\n\nout vec4 fragColor;\n\n// Simplex 2D noise\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\n\nfloat snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),\n dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n}\n\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\nfloat fbm(vec2 n) {\n float total = 0.0, amplitude = .2;\n for (int i = 0; i < 6; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.6;\n }\n return total;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n float scale = .5 * u_scale + 1e-4;\n uv *= (.0004 * (1. - step(1. - scale, 1.) / scale));\n uv *= u_resolution;\n uv /= u_pixelRatio;\n uv += .5;\n\n // Create blobby texture\n float n = snoise(uv + u_time);\n n += 0.5 * snoise(uv * 2.0 - u_time * 0.5);\n n += 0.25 * snoise(uv * 4.0 + u_time * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec3 color = mix(u_color1.rgb, u_color2.rgb, n);\n float opacity = mix(u_color1.a, u_color2.a, n);\n\n // Add grain\n float grain = fbm(uv * 1000.);\n color.rgb += (grain - 0.5) * u_grainAmount;\n\n fragColor = vec4(color * opacity, opacity);\n}\n`;\n", "export type MeshGradientUniforms = {\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n};\n\n/**\n * Mesh Gradient, based on https://www.shadertoy.com/view/wdyczG\n * Renders a mesh gradient with a rotating noise pattern\n * and several layers of fractal noise\n *\n * Uniforms include:\n * u_color1: The first color of the mesh gradient\n * u_color2: The second color of the mesh gradient\n * u_color3: The third color of the mesh gradient\n * u_color4: The fourth color of the mesh gradient\n */\n\nexport const meshGradientFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\nuniform float u_time;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\n\nout vec4 fragColor;\n\n#define S(a,b,t) smoothstep(a,b,t)\n\nmat2 Rot(float a) {\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\n}\n\nvec2 hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nfloat noise( in vec2 p ) {\n vec2 i = floor( p );\n vec2 f = fract( p );\n vec2 u = f*f*(3.0-2.0*f);\n\n float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),\n mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);\n return 0.5 + 0.5*n;\n}\n\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n \n uv /= u_pixelRatio;\n \n vec2 tuv = uv;\n tuv -= .5;\n\n // rotate with Noise\n float degree = noise(vec2(u_time, tuv.x * tuv.y));\n\n tuv.y *= 1./ratio;\n tuv *= Rot(radians((degree-.5)*720.+180.));\n tuv.y *= ratio;\n\n\n // Wave warp with sin\n float frequency = 5.;\n float amplitude = 30.;\n float speed = u_time * 2.;\n tuv.x += sin(tuv.y*frequency+speed)/amplitude;\n tuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n float proportion_1 = S(-.3, .2, (tuv*Rot(radians(-5.))).x);\n vec3 layer1_color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, proportion_1);\n float layer1_opacity = mix(u_color1.a, u_color2.a, proportion_1);\n vec3 layer2_color = mix(u_color3.rgb * u_color3.a, u_color4.rgb * u_color4.a, proportion_1);\n float layer2_opacity = mix(u_color3.a, u_color4.a, proportion_1);\n\n float proportion_2 = S(.5, -.3, tuv.y);\n vec3 color = mix(layer1_color, layer2_color, proportion_2);\n float opacity = mix(layer1_opacity, layer2_opacity, proportion_2);\n \n fragColor = vec4(color, opacity);\n}\n`;\n", "export type SmokeRingUniforms = {\n u_scale: number;\n u_colorBack: [number, number, number, number];\n u_colorInner: [number, number, number, number];\n u_colorOuter: [number, number, number, number];\n u_noiseScale: number;\n u_thickness: number;\n};\n\n/**\n * Smoke Ring by Ksenia Kondrashova\n * Renders a fractional Brownian motion (fBm) noise over the\n * polar coordinates masked with ring shape\n *\n * Uniforms include:\n * u_scale - the scale applied to user space: with scale = 1 the ring fits the screen height\n * u_colorBack - the background color of the scene\n * u_colorInner - the inner color of the ring gradient\n * u_colorOuter - the outer color of the ring gradient\n * u_noiseScale - the resolution of noise texture\n * u_thickness - the thickness of the ring\n */\n\nexport const smokeRingFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorInner;\nuniform vec4 u_colorOuter;\nuniform float u_noiseScale;\nuniform float u_thickness;\n\nout vec4 fragColor;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nfloat random(in vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n}\nfloat noise(in vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = random(i);\n float b = random(i + vec2(1.0, 0.0));\n float c = random(i + vec2(0.0, 1.0));\n float d = random(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;\n}\nfloat fbm(in vec2 n) {\n float total = 0.0, amplitude = .4;\n for (int i = 0; i < 12; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.6;\n }\n return total;\n}\n\nfloat get_ring_shape(vec2 uv, float innerRadius, float outerRadius) {\n float distance = length(uv);\n float line_width = outerRadius - innerRadius;\n float ringValue = smoothstep(innerRadius, innerRadius + .8 * line_width, distance);\n ringValue -= smoothstep(outerRadius, outerRadius + 1.2 * line_width, distance);\n return clamp(ringValue, 0., 1.);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n uv -= .5;\n uv /= u_pixelRatio;\n float scale = .5 * u_scale + 1e-4;\n uv *= (1. - step(1. - scale, 1.) / scale);\n uv *= 3.;\n uv.x *= ratio;\n\n float t = u_time;\n\n float atg = atan(uv.y, uv.x);\n float angle = (atg + PI) / TWO_PI;\n\n vec2 polar_uv = vec2(atg, .1 * t - (.5 * length(uv)) + 1. / pow(length(uv), .5));\n polar_uv *= u_noiseScale;\n\n float noise_left = fbm(polar_uv + .05 * t);\n polar_uv.x = mod(polar_uv.x, u_noiseScale * TWO_PI);\n float noise_right = fbm(polar_uv + .05 * t);\n float noise = mix(noise_right, noise_left, smoothstep(-.2, .2, uv.x));\n\n float center_shape = 1. - pow(smoothstep(2., .0, length(uv)), 50.);\n\n float radius = .4 - .25 * u_thickness;\n float thickness = u_thickness;\n thickness = pow(thickness, 2.);\n\n float ring_shape = get_ring_shape(uv * (.5 + .6 * noise), radius - .2 * thickness, radius + .5 * thickness);\n\n float ring_shape_outer = 1. - pow(ring_shape, 7.);\n ring_shape_outer *= ring_shape;\n\n float ring_shape_inner = ring_shape - ring_shape_outer;\n ring_shape_inner *= ring_shape;\n\n float background = u_colorBack.a;\n\n float opacity = ring_shape_outer * u_colorOuter.a;\n opacity += ring_shape_inner * u_colorInner.a;\n opacity += background * (1. - ring_shape_inner * u_colorInner.a - ring_shape_outer * u_colorOuter.a);\n\n vec3 color = u_colorBack.rgb * (1. - ring_shape) * background;\n color += u_colorOuter.rgb * ring_shape_outer * u_colorOuter.a;\n color += u_colorInner.rgb * ring_shape_inner * u_colorInner.a;\n\n color += u_colorBack.rgb * ring_shape_inner * (1. - u_colorInner.a) * background;\n color += u_colorBack.rgb * ring_shape_outer * (1. - u_colorOuter.a) * background;\n\n fragColor = vec4(color, opacity);\n}\n`;\n", "export type NeuroNoiseUniforms = {\n u_scale: number;\n u_colorFront: [number, number, number, number];\n u_colorBack: [number, number, number, number];\n u_brightness: number;\n};\n\n/**\n * Neuro Noise Pattern\n * The original artwork: https://codepen.io/ksenia-k/full/vYwgrWv by Ksenia Kondrashova\n * Renders a fractal-like structure made of several layers of since-arches\n *\n * Uniforms include:\n * u_scale - the scale applied to user space\n * u_colorFront - the front color of pattern\n * u_colorBack - the back color of pattern\n * u_brightness - the power (brightness) of pattern lines\n */\n\nexport const neuroNoiseFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_brightness;\n\nout vec4 fragColor;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat neuro_shape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n float scale = .5 * u_scale + 1e-4;\n uv *= (.001 * (1. - step(1. - scale, 1.) / scale));\n uv *= u_resolution;\n uv /= u_pixelRatio;\n uv += .5;\n\n float t = u_time;\n\n float noise = neuro_shape(uv, t);\n\n noise = u_brightness * pow(noise, 3.);\n noise += pow(noise, 12.);\n noise = max(.0, noise - .5);\n\n vec3 color = mix(u_colorBack.rgb * u_colorBack.a, u_colorFront.rgb * u_colorFront.a, noise);\n float opacity = mix(u_colorBack.a, u_colorFront.a, noise);\n\n fragColor = vec4(color, opacity);\n}\n`;\n", "export type DotsOrbitUniforms = {\n u_scale: number;\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n u_dotSize: number;\n u_dotSizeRange: number;\n u_spreading: number;\n};\n\n/**\n * Dots Pattern with dots moving around their grid position\n * The artwork by Ksenia Kondrashova\n * Renders a dot pattern with dots placed in the center of each cell of animated Voronoi diagram\n *\n * Uniforms include:\n * u_scale - the scale applied to user space\n * u_color1 - the first dots color\n * u_color2 - the second dots color\n * u_color3 - the third dots color\n * u_color4 - the fourth dots color\n * u_dotSize (0 .. 1) - the base dot radius (relative to cell size)\n * u_dotSizeRange (0 .. 1) - the dot radius to vary between the cells\n * u_spreading (0 .. 1) - the distance each dot can move around the regular grid\n */\n\nexport const dotsOrbitFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform float u_dotSize;\nuniform float u_dotSizeRange;\nuniform float u_spreading;\n\nout vec4 fragColor;\n\n#define TWO_PI 6.28318530718\n\nfloat random(in vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n}\nvec2 random2(vec2 p) {\n return vec2(random(p), random(200. * p));\n}\n\nvec3 get_voronoi_shape(vec2 _uv, float time) {\n vec2 i_uv = floor(_uv);\n vec2 f_uv = fract(_uv);\n\n float min_dist = 1.;\n vec2 cell_randomizer = vec2(0.);\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 tile_offset = vec2(float(x), float(y));\n vec2 rand = random2(i_uv + tile_offset);\n vec2 cell_center = .5 + 1e-4 + .25 * clamp(u_spreading, 0., 1.) * sin(time + TWO_PI * rand);\n float dist = length(tile_offset + cell_center - f_uv);\n if (dist < min_dist) {\n min_dist = dist;\n cell_randomizer = rand;\n }\n min_dist = min(min_dist, dist);\n }\n }\n\n return vec3(min_dist, cell_randomizer);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n float scale = .5 * u_scale + 1e-4;\n uv *= (.02 * (1. - step(1. - scale, 1.) / scale));\n uv *= u_resolution;\n uv /= u_pixelRatio;\n uv += .5;\n\n float t = u_time;\n\n vec3 voronoi = get_voronoi_shape(uv, t) + 1e-4;\n\n float radius = .25 * clamp(u_dotSize, 0., 1.) - .5 * clamp(u_dotSizeRange, 0., 1.) * voronoi[2];\n float dist = voronoi[0];\n float edge_width = fwidth(dist);\n float shape = smoothstep(radius + edge_width, radius - edge_width, dist);\n\n float color_randomizer = voronoi[1];\n\n float opacity =\n u_color1.a * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +\n u_color2.a * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +\n u_color3.a * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +\n u_color4.a * step(0.75, color_randomizer) * step(color_randomizer, 1.0);\n\n opacity *= shape;\n\n vec3 color =\n u_color1.rgb * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +\n u_color2.rgb * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +\n u_color3.rgb * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +\n u_color4.rgb * step(0.75, color_randomizer) * step(color_randomizer, 1.0);\n\n fragColor = vec4(color * opacity, opacity);\n}\n`;\n", "/** Possible values for the shape uniform */\nexport const DotsGridShapes = {\n Circle: 0,\n Diamond: 1,\n Square: 2,\n Triangle: 3,\n} as const;\nexport type DotsGridShape = (typeof DotsGridShapes)[keyof typeof DotsGridShapes];\n\nexport type DotsGridUniforms = {\n u_colorBack: [number, number, number, number];\n u_colorFill: [number, number, number, number];\n u_colorStroke: [number, number, number, number];\n u_dotSize: number;\n u_gridSpacingX: number;\n u_gridSpacingY: number;\n u_strokeWidth: number;\n u_sizeRange: number;\n u_opacityRange: number;\n u_shape: DotsGridShape;\n};\n\n/**\n * Dot Grid Pattern\n * (the size parameters are set in pixels)\n *\n * Uniforms include:\n * u_colorBack - the background color\n * u_colorFill - the dots fill color\n * u_colorStroke - the dots stroke color\n * u_dotSize (px) - the base dot radius\n * u_strokeWidth (px) - the stroke (to be subtracted from u_dotSize)\n * u_gridSpacingX (px) - horizontal grid spacing\n * u_gridSpacingY (px) - xertical grid spacing\n * u_sizeRange (0 .. 1) - variety of dot size\n * u_opacityRange(0 .. 1) - variety of dot opacity to be applied equally to fill and stroke\n * u_shape - shape code (0 - circle, 1 - diamond, 2 - square, 3 - triangle)\n */\n\nexport const dotsGridFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorFill;\nuniform vec4 u_colorStroke;\nuniform float u_dotSize;\nuniform float u_gridSpacingX;\nuniform float u_gridSpacingY;\nuniform float u_strokeWidth;\nuniform float u_sizeRange;\nuniform float u_opacityRange;\nuniform float u_shape;\n\nout vec4 fragColor;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nfloat hash(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n}\n\nvec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\nfloat polygon(vec2 p, float N, float rot) {\n float a = atan(p.x, p.y) + rot;\n float r = TWO_PI / float(N);\n\n return cos(floor(.5 + a/r) * r - a) * length(p);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy;\n uv.y = u_resolution.y - uv.y;\n\n uv /= u_pixelRatio;\n\n vec2 grid = fract(uv / vec2(u_gridSpacingX, u_gridSpacingY)) + 1e-4;\n vec2 grid_idx = floor(uv / vec2(u_gridSpacingX, u_gridSpacingY));\n float size_randomizer = .5 + .5 * snoise(2. * vec2(grid_idx.x * 100., grid_idx.y));\n float opacity_randomizer = .5 + .5 * snoise(2. * vec2(grid_idx.y, grid_idx.x));\n\n vec2 center = vec2(0.5) - 1e-3;\n vec2 p = (grid - center) * vec2(u_gridSpacingX, u_gridSpacingY);\n\n float base_size = u_dotSize * (1. - size_randomizer * clamp(u_sizeRange, 0., 1.));\n float stroke_width = u_strokeWidth;\n\n float dist;\n if (u_shape < 0.5) {\n // Circle\n dist = length(p);\n } else if (u_shape < 1.5) {\n // Diamond\n dist = polygon(1.5 * p, 4., .25 * PI);\n } else if (u_shape < 2.5) {\n // Square\n dist = polygon(1.5 * p, 4., 1e-3);\n } else {\n // Triangle\n p = p * 2. - 1.;\n p.y -= .75 * base_size;\n stroke_width *= 2.;\n dist = polygon(p, 3., 1e-3);\n }\n\n float edge_width = fwidth(dist);\n float shape_outer = smoothstep(base_size + edge_width, base_size - edge_width, dist);\n float shape_inner = smoothstep(base_size - u_strokeWidth + edge_width, base_size - u_strokeWidth - edge_width, dist);\n float stroke = clamp(shape_outer - shape_inner, 0., 1.);\n\n float dot_opacity = max(0., 1. - opacity_randomizer * clamp(u_opacityRange, 0., 1.));\n\n vec3 color = u_colorBack.rgb * u_colorBack.a;\n color = mix(color, u_colorFill.rgb, u_colorFill.a * dot_opacity * shape_inner);\n color = mix(color, u_colorStroke.rgb, u_colorStroke.a * dot_opacity * stroke);\n\n float opacity = u_colorBack.a;\n opacity += u_colorFill.a * shape_inner * dot_opacity;\n opacity += u_colorStroke.a * stroke * dot_opacity;\n\n fragColor = vec4(color, opacity);\n}\n`;\n", "export type SteppedSimplexNoiseUniforms = {\n u_scale: number;\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_color4: [number, number, number, number];\n u_color5: [number, number, number, number];\n u_steps_number: number;\n};\n\n/**\n * Stepped Simplex Noise by Ksenia Kondrashova\n * Calculates a combination of 2 simplex noises with result rendered as\n * an X-stepped 5-colored gradient\n *\n * Uniforms include:\n * u_scale - the scale applied to user space\n * u_color1 - the first gradient color\n * u_color2 - the second gradient color\n * u_color3 - the third gradient color\n * u_color4 - the fourth gradient color\n * u_color5 - the fifth gradient color\n * u_steps_number - the number of solid colors to show as a stepped gradient\n */\n\nexport const steppedSimplexNoiseFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec4 u_color5;\nuniform float u_steps_number;\n\nout vec4 fragColor;\n\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\nfloat snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),\n dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n}\n\nfloat get_noise(vec2 uv, float t) {\n float noise = .5 * snoise(uv - vec2(0., .3 * t));\n noise += .5 * snoise(2. * uv + vec2(0., .32 * t));\n\n return noise;\n}\n\nvec4 getColor(int index) {\n if (index == 0) return u_color1;\n if (index == 1) return u_color2;\n if (index == 2) return u_color3;\n if (index == 3) return u_color4;\n if (index == 4) return u_color5;\n return u_color1;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n float scale = .5 * u_scale + 1e-4;\n uv *= (.0008 * (1. - step(1. - scale, 1.) / scale));\n uv *= u_resolution;\n uv /= u_pixelRatio;\n uv += .5;\n\n float t = u_time;\n\n float noise = .5 + .5 * get_noise(uv, t);\n noise = floor(noise * u_steps_number) / u_steps_number;\n\n vec3 color = u_color1.rgb * u_color1.a;\n float opacity = u_color1.a;\n for (int i = 0; i < 5; i++) {\n vec4 next_c = getColor(i + 1);\n float proportion = smoothstep((float(i) + .5) / 5., (float(i) + 2.) / 5., noise);\n color = mix(color, next_c.rgb * next_c.a, proportion);\n opacity = mix(opacity, next_c.a, proportion);\n }\n fragColor = vec4(color, opacity);\n}\n`;\n", "export type MetaballsUniforms = {\n u_scale: number;\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_color3: [number, number, number, number];\n u_ballSize: number;\n u_visibilityRange: number;\n};\n\n/**\n * Metaballs (circular shapes with gooey effect applied)\n * The artwork by Ksenia Kondrashova\n *\n * Uniforms include:\n * u_scale - the scale applied to user space\n * (with scale = 1 metaballs fit the screen height)\n * u_color1 - the mataballs gradient color #1\n * u_color2 - the mataballs gradient color #2\n * u_color3 - the mataballs gradient color #3\n * u_ballSize (0 .. 1) - the size coefficient applied to each ball\n * u_visibilityRange (0 .. 1) - to show 2 to 15 balls\n */\n\nexport const metaballsFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform float u_ballSize;\nuniform float u_visibilityRange;\n\n#define TWO_PI 6.28318530718\n\nout vec4 fragColor;\n\nfloat hash(float x) {\n return fract(sin(x) * 43758.5453123);\n}\nfloat lerp(float a, float b, float t) {\n return a + t * (b - a);\n}\nfloat noise(float x) {\n float i = floor(x);\n float f = fract(x);\n float u = f * f * (3.0 - 2.0 * f); // Smoothstep function for interpolation\n return lerp(hash(i), hash(i + 1.0), u);\n}\n\nfloat get_ball_shape(vec2 uv, vec2 c, float p) {\n float s = .5 * length(uv - c);\n s = 1. - clamp(s, 0., 1.);\n s = pow(s, p);\n return s;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n uv -= .5;\n uv /= u_pixelRatio;\n float scale = .5 * u_scale + 1e-4;\n uv *= (18. * (1. - step(1. - scale, 1.) / scale));\n uv += .5;\n uv.x *= ratio;\n\n float t = u_time;\n\n vec3 total_color = vec3(0.);\n float total_shape = 0.;\n\n const int max_balls_number = 15;\n for (int i = 0; i < max_balls_number; i++) {\n vec2 pos = vec2(.5) + 1e-4;\n float idx_fract = float(i) / float(max_balls_number);\n float angle = TWO_PI * idx_fract;\n\n float speed = 1. - .2 * idx_fract;\n float noiseX = noise(angle * 10. + float(i) + t * speed);\n float noiseY = noise(angle * 20. + float(i) - t * speed);\n\n pos += 7. * (vec2(noiseX, noiseY) - .5);\n\n vec4 ball_color;\n if (i % 3 == 0) {\n ball_color = u_color1;\n } else if (i % 3 == 1) {\n ball_color = u_color2;\n } else {\n ball_color = u_color3;\n }\n\n float shape = get_ball_shape(uv, pos, 6. - 4. * u_ballSize) * ball_color.a;\n\n shape *= smoothstep((float(i) - 1.) / float(max_balls_number), idx_fract, u_visibilityRange);\n\n total_color += ball_color.rgb * shape;\n total_shape += shape;\n }\n\n total_color /= max(total_shape, 1e-4);\n\n float edge_width = fwidth(total_shape);\n float final_shape = smoothstep(.4, .4 + edge_width, total_shape);\n\n vec3 color = total_color * final_shape;\n float opacity = final_shape;\n\n if (opacity < .01) {\n discard;\n }\n\n fragColor = vec4(color, opacity);\n}\n`;\n", "export type PerlinNoiseUniforms = {\n u_scale: number;\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_proportion: number;\n u_contour: number;\n u_octaveCount: number;\n u_persistence: number;\n u_lacunarity: number;\n};\n\n/**\n * 3d Perlin noise with exposed parameters\n * Based on https://www.shadertoy.com/view/NlSGDz\n *\n * Uniforms include:\n * u_scale - the scale applied to user space\n * u_color1 - the first mixed color\n * u_color2 - the second mixed color\n * u_proportion (0 .. 1) - the proportion between u_color1 and u_color2;\n * u_contour - the sharpness of the transition between u_color1 and u_color2 in the noise output\n * u_octaveCount - the number of octaves for Perlin noise;\n * higher values increase the complexity of the noise\n * u_persistence (0 .. 1) - the amplitude of each successive octave of the noise;\n * lower values make higher octaves less pronounced\n * u_lacunarity - the frequency of each successive octave of the noise;\n * higher values increase the detail\n */\n\nexport const perlinNoiseFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform float u_proportion;\nuniform float u_contour;\nuniform float u_octaveCount;\nuniform float u_persistence;\nuniform float u_lacunarity;\n\nout vec4 fragColor;\n\n#define TWO_PI 6.28318530718\n\nuint hash(uint x, uint seed) {\n const uint m = 0x5bd1e995U;\n uint hash = seed;\n // process input\n uint k = x;\n k *= m;\n k ^= k >> 24;\n k *= m;\n hash *= m;\n hash ^= k;\n // some final mixing\n hash ^= hash >> 13;\n hash *= m;\n hash ^= hash >> 15;\n return hash;\n}\n\nuint hash(uvec3 x, uint seed){\n const uint m = 0x5bd1e995U;\n uint hash = seed;\n // process first vector element\n uint k = x.x; \n k *= m;\n k ^= k >> 24;\n k *= m;\n hash *= m;\n hash ^= k;\n // process second vector element\n k = x.y; \n k *= m;\n k ^= k >> 24;\n k *= m;\n hash *= m;\n hash ^= k;\n // process third vector element\n k = x.z; \n k *= m;\n k ^= k >> 24;\n k *= m;\n hash *= m;\n hash ^= k;\n // some final mixing\n hash ^= hash >> 13;\n hash *= m;\n hash ^= hash >> 15;\n return hash;\n}\n\n\nvec3 gradientdy(uint hash) {\n switch (int(hash) & 15) { // look at the last four bits to pick a gradient dy\n case 0:\n return vec3(1, 1, 0);\n case 1:\n return vec3(-1, 1, 0);\n case 2:\n return vec3(1, -1, 0);\n case 3:\n return vec3(-1, -1, 0);\n case 4:\n return vec3(1, 0, 1);\n case 5:\n return vec3(-1, 0, 1);\n case 6:\n return vec3(1, 0, -1);\n case 7:\n return vec3(-1, 0, -1);\n case 8:\n return vec3(0, 1, 1);\n case 9:\n return vec3(0, -1, 1);\n case 10:\n return vec3(0, 1, -1);\n case 11:\n return vec3(0, -1, -1);\n case 12:\n return vec3(1, 1, 0);\n case 13:\n return vec3(-1, 1, 0);\n case 14:\n return vec3(0, -1, 1);\n case 15:\n return vec3(0, -1, -1);\n }\n}\n\nfloat interpolate(float value1, float value2, float value3, float value4, float value5, float value6, float value7, float value8, vec3 t) {\n return mix(\n mix(mix(value1, value2, t.x), mix(value3, value4, t.x), t.y),\n mix(mix(value5, value6, t.x), mix(value7, value8, t.x), t.y),\n t.z\n );\n}\n\nvec3 fade(vec3 t) {\n return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);\n}\n\nfloat perlinNoise(vec3 position, uint seed) {\n position += 1e+4;\n vec3 floorPosition = floor(position);\n vec3 fractPosition = fract(position);\n uvec3 cellCoordinates = uvec3(floorPosition);\n float value1 = dot(gradientdy(hash(cellCoordinates, seed)), fractPosition);\n float value2 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 0, 0)), seed)), fractPosition - vec3(1, 0, 0));\n float value3 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 1, 0)), seed)), fractPosition - vec3(0, 1, 0));\n float value4 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 1, 0)), seed)), fractPosition - vec3(1, 1, 0));\n float value5 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 0, 1)), seed)), fractPosition - vec3(0, 0, 1));\n float value6 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 0, 1)), seed)), fractPosition - vec3(1, 0, 1));\n float value7 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 1, 1)), seed)), fractPosition - vec3(0, 1, 1));\n float value8 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 1, 1)), seed)), fractPosition - vec3(1, 1, 1));\n return interpolate(value1, value2, value3, value4, value5, value6, value7, value8, fade(fractPosition));\n}\n\nfloat p_noise(vec3 position, int octaveCount, float persistence, float lacunarity) {\n float value = 0.0;\n float amplitude = 1.0;\n float currentFrequency = 10.;\n uint currentSeed = uint(0);\n for (int i = 0; i < octaveCount; i++) {\n currentSeed = hash(currentSeed, 0x0U);\n value += perlinNoise(position * currentFrequency, currentSeed) * amplitude;\n amplitude *= persistence;\n currentFrequency *= lacunarity;\n }\n return value;\n}\n\nfloat get_max_amp(float persistence, float octaveCount) {\n persistence *= .999;\n return (1. - pow(persistence, octaveCount)) / (1. - persistence);\n}\n\nvoid main() {\n\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float t = .2 * u_time;\n\n uv -= .5;\n uv *= (.004 * u_scale * u_resolution);\n uv /= u_pixelRatio;\n uv += .5;\n \n vec3 p = vec3(uv, t);\n \n float oct_count = max(0., floor(u_octaveCount));\n float persistence = clamp(u_persistence, 0., 1.);\n float noise = p_noise(p, int(oct_count), persistence, u_lacunarity);\n \n float max_amp = get_max_amp(persistence, oct_count);\n float noise_normalized = (noise + max_amp) / (2. * max_amp) + (u_proportion - .5);\n float sharpness = clamp(1. - u_contour, 0., 1.);\n float smooth_w = 0.5 * fwidth(noise_normalized);\n float sharp_noise = smoothstep(\n .5 - .5 * sharpness - smooth_w, \n .5 + .5 * sharpness + smooth_w, \n noise_normalized\n );\n\n vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, sharp_noise);\n float opacity = mix(u_color1.a, u_color2.a, sharp_noise);\n\n fragColor = vec4(color, opacity);\n}\n`;\n", "export type VoronoiUniforms = {\n u_scale: number;\n u_colorCell1: [number, number, number, number];\n u_colorCell2: [number, number, number, number];\n u_colorCell3: [number, number, number, number];\n u_colorEdges: [number, number, number, number];\n u_colorMid: [number, number, number, number];\n u_colorGradient: number;\n u_distance: number;\n u_edgesSize: number;\n u_edgesSharpness: number;\n u_middleSize: number;\n u_middleSharpness: number;\n};\n\n/**\n * Voronoi pattern\n * The artwork by Ksenia Kondrashova\n * Renders a number of circular shapes with gooey effect applied\n *\n * Uniforms include:\n * u_scale - the scale applied to user space\n * u_colorCell1 - color #1 of mix used to fill the cell shape\n * u_colorCell2 - color #2 of mix used to fill the cell shape\n * u_colorCell3 - color #3 of mix used to fill the cell shape\n * u_colorEdges - color of borders between the cells\n * u_colorMid - color used to fill the radial shape in the center of each cell\n * u_colorGradient (0 .. 1) - if the cell color is a gradient of palette colors or one color selection\n * u_distance (0 ... 0.5) - how far the cell center can move from regular square grid\n * u_edgesSize (0 .. 1) - the size of borders\n * (can be set to zero but the edge may get glitchy due to nature of Voronoi diagram)\n * u_edgesSharpness (0 .. 1) - the blur/sharp for cell border\n * u_middleSize (0 .. 1) - the size of shape in the center of each cell\n * u_middleSharpness (0 .. 1) - the smoothness of shape in the center of each cell\n * (vary from cell color gradient to sharp dot in the middle)\n */\n\nexport const voronoiFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\n\nuniform vec4 u_colorCell1;\nuniform vec4 u_colorCell2;\nuniform vec4 u_colorCell3;\nuniform vec4 u_colorEdges;\nuniform vec4 u_colorMid;\n\nuniform float u_colorGradient;\nuniform float u_distance;\nuniform float u_edgesSize;\nuniform float u_edgesSharpness;\nuniform float u_middleSize;\nuniform float u_middleSharpness;\n\n#define TWO_PI 6.28318530718\n\nout vec4 fragColor;\n\nvec2 hash(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\nfloat smin(float angle, float b, float k) {\n float h = clamp(.5 + .5 * (b - angle) / k, 0., 1.);\n return mix(b, angle, h) - k * h * (1. - h);\n}\n\nvec4 blend_colors(vec4 c1, vec4 c2, vec4 c3, vec2 randomizer) {\n vec3 color1 = c1.rgb * c1.a;\n vec3 color2 = c2.rgb * c2.a;\n vec3 color3 = c3.rgb * c3.a;\n\n float mixer = clamp(u_colorGradient, 0., 1.);\n float r1 = smoothstep(.5 - .5 * mixer, .5 + .5 * mixer, randomizer[0]);\n float r2 = smoothstep(.6 - .6 * mixer, .6 + .4 * mixer, randomizer[1]);\n vec3 blended_color_2 = mix(color1, color2, r1);\n float blended_opacity_2 = mix(c1.a, c2.a, r1);\n vec3 c = mix(blended_color_2, color3, r2);\n float o = mix(blended_opacity_2, c3.a, r2);\n \n return vec4(c, o);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float t = u_time;\n uv -= .5;\n uv *= (.01 * u_scale * u_resolution);\n uv /= u_pixelRatio;\n uv += .5;\n\n vec2 i_uv = floor(uv);\n vec2 f_uv = fract(uv);\n\n vec2 randomizer = vec2(0.);\n vec3 distance = vec3(1.);\n\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 tile_offset = vec2(float(x), float(y));\n vec2 o = hash(i_uv + tile_offset);\n tile_offset += (.5 + clamp(u_distance, 0., .5) * sin(t + TWO_PI * o)) - f_uv;\n\n float dist = dot(tile_offset, tile_offset);\n float old_min_dist = distance.x;\n\n distance.z = max(distance.x, max(distance.y, min(distance.z, dist)));\n distance.y = max(distance.x, min(distance.y, dist));\n distance.x = min(distance.x, dist);\n\n if (old_min_dist > distance.x) {\n randomizer = o;\n }\n }\n }\n\n distance = sqrt(distance);\n\n distance = sqrt(distance);\n float cell_shape = min(smin(distance.z, distance.y, .1) - distance.x, 1.);\n\n float dot_shape = pow(distance.x, 2.) / (2. * clamp(u_middleSize, 0., 1.) + 1e-4);\n float dot_edge_width = fwidth(dot_shape);\n float dotSharp = clamp(u_middleSharpness, 0., 1.);\n dot_shape = 1. - smoothstep(.5 * dotSharp - dot_edge_width, 1. - .5 * dotSharp, dot_shape);\n\n float cell_edge_width = fwidth(distance.x);\n float w = .7 * (clamp(u_edgesSize, 0., 1.) - .1);\n float edgeSharp = clamp(u_edgesSharpness, 0., 1.);\n cell_shape = smoothstep(w - cell_edge_width, w + edgeSharp, cell_shape);\n\n dot_shape *= cell_shape;\n\n vec4 cell_mix = blend_colors(u_colorCell1, u_colorCell2, u_colorCell3, randomizer);\n \n vec4 edges = vec4(u_colorEdges.rgb * u_colorEdges.a, u_colorEdges.a);\n\n vec3 color = mix(edges.rgb, cell_mix.rgb, cell_shape);\n float opacity = mix(edges.a, cell_mix.a, cell_shape);\n\n color = mix(color, u_colorMid.rgb * u_colorMid.a, dot_shape);\n opacity = mix(opacity, u_colorMid.a, dot_shape);\n\n fragColor = vec4(color, opacity);\n}\n`;\n", "export type WavesUniforms = {\n u_scale: number;\n u_rotation: number;\n u_color1: [number, number, number, number];\n u_color2: [number, number, number, number];\n u_shape: number;\n u_frequency: number;\n u_amplitude: number;\n u_spacing: number;\n u_dutyCycle: number;\n u_edgeBlur: number;\n};\n\n/**\n * Stepped Simplex Noise by Ksenia Kondrashova\n * Calculates a combination of 2 simplex noises with result rendered as a stepped gradient\n *\n * Uniforms include:\n * u_scale - the scale applied to user space\n * u_rotation - the rotation applied to user space\n * u_color1 - the first color\n * u_color2 - the second color\n * u_shape (0 ... 3) - the line shaping coefficient, non-integer\n values allowed and produce mixed shapes\n - u_shape = 0 is zigzag\n - u_shape = 1 is perfect sine wave\n - u_shape = 2 is irregular wave #1\n - u_shape = 3 is irregular wave #2\n * u_frequency - the wave frequency\n * u_amplitude - the wave amplitude\n * u_spacing - the density of pattern lines\n * u_dutyCycle (0 ... 1) - the proportion of stroke width to the pattern step\n * u_edgeBlur (0 ... 1) - the blur applied to the lines edges\n */\n\nexport const wavesFragmentShader = `#version 300 es\nprecision highp float;\n\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform float u_rotation;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform float u_shape;\nuniform float u_frequency;\nuniform float u_amplitude;\nuniform float u_spacing;\nuniform float u_dutyCycle;\nuniform float u_edgeBlur;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nout vec4 fragColor;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.02 * max(0., u_scale) * u_resolution);\n uv = rotate(uv, u_rotation * .5 * PI);\n uv /= u_pixelRatio;\n uv += .5;\n\n float wave = .5 * cos(uv.x * u_frequency * TWO_PI);\n float zigzag = 2. * abs(fract(uv.x * u_frequency) - .5);\n float irregular = sin(uv.x * .25 * u_frequency * TWO_PI) * cos(uv.x * u_frequency * TWO_PI);\n float irregular2 = .75 * (sin(uv.x * u_frequency * TWO_PI) + .5 * cos(uv.x * .5 * u_frequency * TWO_PI));\n\n float offset = mix(zigzag, wave, smoothstep(0., 1., u_shape));\n offset = mix(offset, irregular, smoothstep(1., 2., u_shape));\n offset = mix(offset, irregular2, smoothstep(2., 3., u_shape));\n offset *= 2. * u_amplitude;\n \n float spacing = .02 + .98 * u_spacing;\n float shape = .5 + .5 * sin((uv.y + offset) * PI / spacing);\n \n float edge_width = .02 / (1. + abs(shape)) * (.001 + u_scale);\n edge_width += .5 * max(0., u_edgeBlur);\n float dc = clamp(u_dutyCycle, 0., 1.);\n float t = smoothstep(dc - edge_width, dc + edge_width, shape);\n\n vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, t);\n float opacity = mix(u_color1.a, u_color2.a, t);\n \n fragColor = vec4(color, opacity);\n}\n`;\n", "/** Convert color string from HSL, RGB, or hex to 0-to-1-range-RGBA array */\nexport function getShaderColorFromString(\n colorString: string | [number, number, number] | [number, number, number, number] | undefined,\n fallback: string | [number, number, number] | [number, number, number, number] = [0, 0, 0, 1]\n): [number, number, number, number] {\n // If the color string is already an array of 3 or 4 numbers, return it (with alpha=1 if needed)\n if (Array.isArray(colorString)) {\n if (colorString.length === 4) return colorString as [number, number, number, number];\n if (colorString.length === 3) return [...colorString, 1];\n return getShaderColorFromString(fallback);\n }\n\n // If the color string is not a string, return the fallback\n if (typeof colorString !== 'string') {\n return getShaderColorFromString(fallback);\n }\n\n let r: number,\n g: number,\n b: number,\n a = 1;\n if (colorString.startsWith('#')) {\n [r, g, b, a] = hexToRgba(colorString);\n } else if (colorString.startsWith('rgb')) {\n [r, g, b, a] = parseRgba(colorString);\n } else if (colorString.startsWith('hsl')) {\n [r, g, b, a] = hslaToRgba(parseHsla(colorString));\n } else {\n console.error('Unsupported color format', colorString);\n return getShaderColorFromString(fallback);\n }\n\n return [clamp(r, 0, 1), clamp(g, 0, 1), clamp(b, 0, 1), clamp(a, 0, 1)];\n}\n\n/** Convert hex to RGBA (0 to 1 range) */\nfunction hexToRgba(hex: string): [number, number, number, number] {\n // Remove # if present\n hex = hex.replace(/^#/, '');\n\n // Expand three-letter hex to six-letter\n if (hex.length === 3) {\n hex = hex\n .split('')\n .map((char) => char + char)\n .join('');\n }\n // Expand six-letter hex to eight-letter (add full opacity if no alpha)\n if (hex.length === 6) {\n hex = hex + 'ff';\n }\n\n // Parse the components\n const r = parseInt(hex.slice(0, 2), 16) / 255;\n const g = parseInt(hex.slice(2, 4), 16) / 255;\n const b = parseInt(hex.slice(4, 6), 16) / 255;\n const a = parseInt(hex.slice(6, 8), 16) / 255;\n\n return [r, g, b, a];\n}\n\n/** Parse RGBA string to RGBA (0 to 1 range) */\nfunction parseRgba(rgba: string): [number, number, number, number] {\n // Match both rgb and rgba patterns\n const match = rgba.match(/^rgba?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*([0-9.]+))?\\s*\\)$/i);\n if (!match) return [0, 0, 0, 1];\n\n return [\n parseInt(match[1] ?? '0') / 255,\n parseInt(match[2] ?? '0') / 255,\n parseInt(match[3] ?? '0') / 255,\n match[4] === undefined ? 1 : parseFloat(match[4]),\n ];\n}\n\n/** Parse HSLA string */\nfunction parseHsla(hsla: string): [number, number, number, number] {\n const match = hsla.match(/^hsla?\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)%\\s*,\\s*(\\d+)%\\s*(?:,\\s*([0-9.]+))?\\s*\\)$/i);\n if (!match) return [0, 0, 0, 1];\n\n return [\n parseInt(match[1] ?? '0'),\n parseInt(match[2] ?? '0'),\n parseInt(match[3] ?? '0'),\n match[4] === undefined ? 1 : parseFloat(match[4]),\n ];\n}\n\n/** Convert HSLA to RGBA (0 to 1 range) */\nfunction hslaToRgba(hsla: [number, number, number, number]): [number, number, number, number] {\n const [h, s, l, a] = hsla;\n const hDecimal = h / 360;\n const sDecimal = s / 100;\n const lDecimal = l / 100;\n let r, g, b;\n\n if (s === 0) {\n r = g = b = lDecimal; // achromatic\n } else {\n const hue2rgb = (p: number, q: number, t: number) => {\n if (t < 0) t += 1;\n if (t > 1) t -= 1;\n if (t < 1 / 6) return p + (q - p) * 6 * t;\n if (t < 1 / 2) return q;\n if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;\n return p;\n };\n\n const q = lDecimal < 0.5 ? lDecimal * (1 + sDecimal) : lDecimal + sDecimal - lDecimal * sDecimal;\n const p = 2 * lDecimal - q;\n r = hue2rgb(p, q, hDecimal + 1 / 3);\n g = hue2rgb(p, q, hDecimal);\n b = hue2rgb(p, q, hDecimal - 1 / 3);\n }\n\n return [r, g, b, a];\n}\n\nexport const clamp = (n: number, min: number, max: number): number => Math.min(Math.max(n, min), max);\n"],
5
+ "mappings": ";AAAO,IAAMA,EAAN,KAAkB,CACf,OACA,GACA,QAA+B,KAC/B,iBAAgE,CAAC,EAEjE,eAEA,MAAuB,KAEvB,cAAgB,EAEhB,mBAAqB,EAErB,MAAQ,EAER,iBAEA,gBAAkB,GAElB,kBAAoB,GAE5B,YACEC,EACAC,EACAC,EAA8C,CAAC,EAC/CC,EAEAC,EAAQ,EAERC,EAAO,EACP,CACA,KAAK,OAASL,EACd,KAAK,eAAiBC,EACtB,KAAK,iBAAmBC,EAExB,KAAK,mBAAqBG,EAE1B,IAAMC,EAAKN,EAAO,WAAW,SAAUG,CAAsB,EAC7D,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,qBAAqB,EAEvC,KAAK,GAAKA,EAEV,KAAK,UAAU,EACf,KAAK,oBAAoB,EAGzB,KAAK,SAASF,CAAK,EAGnB,KAAK,OAAO,aAAa,qBAAsB,MAAM,CACvD,CAEQ,UAAY,IAAM,CACxB,IAAMG,EAAUC,EAAc,KAAK,GAAIC,EAAoB,KAAK,cAAc,EACzEF,IACL,KAAK,QAAUA,EAEf,KAAK,uBAAuB,EAC5B,KAAK,cAAc,EACrB,EAEQ,uBAAyB,IAAM,CACrC,IAAMG,EAA4B,KAAK,GAAG,kBAAkB,KAAK,QAAU,YAAY,EACjFC,EAAiB,KAAK,GAAG,aAAa,EAC5C,KAAK,GAAG,WAAW,KAAK,GAAG,aAAcA,CAAc,EACvD,IAAMC,EAAY,CAAC,GAAI,GAAI,EAAG,GAAI,GAAI,EAAG,GAAI,EAAG,EAAG,GAAI,EAAG,CAAC,EAC3D,KAAK,GAAG,WAAW,KAAK,GAAG,aAAc,IAAI,aAAaA,CAAS,EAAG,KAAK,GAAG,WAAW,EACzF,KAAK,GAAG,wBAAwBF,CAAyB,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EAAI,kBAAcF,GAAKC,EAAID,IAAM,kBAAQE,GAAK,EAC3CF,GAGHC,EAAIH,EAAW,GAAMA,GAAY,EAAID,GAAYC,EAAWD,EAAWC,EAAWD,EAClFG,EAAI,EAAIF,EAAWG,EACzBZ,EAAIU,EAAQC,EAAGC,EAAGL,EAAW,EAAI,CAAC,EAClCjB,EAAIoB,EAAQC,EAAGC,EAAGL,CAAQ,EAC1BhB,EAAImB,EAAQC,EAAGC,EAAGL,EAAW,EAAI,CAAC,CACpC,CAEA,MAAO,CAACP,EAAGV,EAAGC,EAAG,CAAC,CACpB,CAEO,IAAMM,EAAQ,CAACiB,EAAWC,EAAaC,IAAwB,KAAK,IAAI,KAAK,IAAIF,EAAGC,CAAG,EAAGC,CAAG",
6
+ "names": ["ShaderMount", "canvas", "fragmentShader", "uniforms", "webGlContextAttributes", "speed", "seed", "gl", "program", "createProgram", "vertexShaderSource", "positionAttributeLocation", "positionBuffer", "positions", "key", "pixelRatio", "newWidth", "newHeight", "currentTime", "dt", "value", "location", "newSeed", "oneFrameAt120Fps", "newSpeed", "newUniforms", "createShader", "type", "source", "shader", "fragmentShaderSource", "vertexShader", "grainCloudsFragmentShader", "meshGradientFragmentShader", "smokeRingFragmentShader", "neuroNoiseFragmentShader", "dotsOrbitFragmentShader", "DotsGridShapes", "dotsGridFragmentShader", "steppedSimplexNoiseFragmentShader", "metaballsFragmentShader", "perlinNoiseFragmentShader", "voronoiFragmentShader", "wavesFragmentShader", "getShaderColorFromString", "colorString", "fallback", "g", "b", "a", "hexToRgba", "parseRgba", "hslaToRgba", "parseHsla", "clamp", "hex", "char", "r", "rgba", "match", "hsla", "h", "s", "l", "hDecimal", "sDecimal", "lDecimal", "hue2rgb", "p", "q", "t", "n", "min", "max"]
7
7
  }
@@ -19,7 +19,11 @@ export declare class ShaderMount {
19
19
  private hasBeenDisposed;
20
20
  /** If the resolution of the canvas has changed since the last render */
21
21
  private resolutionChanged;
22
- constructor(canvas: HTMLCanvasElement, fragmentShader: string, uniforms?: Record<string, number | number[]>, webGlContextAttributes?: WebGLContextAttributes, speed?: number);
22
+ constructor(canvas: HTMLCanvasElement, fragmentShader: string, uniforms?: Record<string, number | number[]>, webGlContextAttributes?: WebGLContextAttributes,
23
+ /** The speed of the animation, or 0 to stop it. Supports negative values to play in reverse. */
24
+ speed?: number,
25
+ /** Pass a seed to offset the starting u_time value and give deterministic results*/
26
+ seed?: number);
23
27
  private initWebGL;
24
28
  private setupPositionAttribute;
25
29
  private setupUniforms;
@@ -29,6 +33,8 @@ export declare class ShaderMount {
29
33
  private render;
30
34
  private requestRender;
31
35
  private updateProvidedUniforms;
36
+ /** Set a seed to get a deterministic result */
37
+ setSeed: (newSeed: number) => void;
32
38
  /** Set an animation speed (or 0 to stop animation) */
33
39
  setSpeed: (newSpeed?: number) => void;
34
40
  /** Update the uniforms that are provided by the outside shader */
@@ -0,0 +1,37 @@
1
+ /** Possible values for the shape uniform */
2
+ export declare const DotsGridShapes: {
3
+ readonly Circle: 0;
4
+ readonly Diamond: 1;
5
+ readonly Square: 2;
6
+ readonly Triangle: 3;
7
+ };
8
+ export type DotsGridShape = (typeof DotsGridShapes)[keyof typeof DotsGridShapes];
9
+ export type DotsGridUniforms = {
10
+ u_colorBack: [number, number, number, number];
11
+ u_colorFill: [number, number, number, number];
12
+ u_colorStroke: [number, number, number, number];
13
+ u_dotSize: number;
14
+ u_gridSpacingX: number;
15
+ u_gridSpacingY: number;
16
+ u_strokeWidth: number;
17
+ u_sizeRange: number;
18
+ u_opacityRange: number;
19
+ u_shape: DotsGridShape;
20
+ };
21
+ /**
22
+ * Dot Grid Pattern
23
+ * (the size parameters are set in pixels)
24
+ *
25
+ * Uniforms include:
26
+ * u_colorBack - the background color
27
+ * u_colorFill - the dots fill color
28
+ * u_colorStroke - the dots stroke color
29
+ * u_dotSize (px) - the base dot radius
30
+ * u_strokeWidth (px) - the stroke (to be subtracted from u_dotSize)
31
+ * u_gridSpacingX (px) - horizontal grid spacing
32
+ * u_gridSpacingY (px) - xertical grid spacing
33
+ * u_sizeRange (0 .. 1) - variety of dot size
34
+ * u_opacityRange(0 .. 1) - variety of dot opacity to be applied equally to fill and stroke
35
+ * u_shape - shape code (0 - circle, 1 - diamond, 2 - square, 3 - triangle)
36
+ */
37
+ export declare const dotsGridFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorFill;\nuniform vec4 u_colorStroke;\nuniform float u_dotSize;\nuniform float u_gridSpacingX;\nuniform float u_gridSpacingY;\nuniform float u_strokeWidth;\nuniform float u_sizeRange;\nuniform float u_opacityRange;\nuniform float u_shape;\n\nout vec4 fragColor;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nfloat hash(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n}\n\nvec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\nfloat polygon(vec2 p, float N, float rot) {\n float a = atan(p.x, p.y) + rot;\n float r = TWO_PI / float(N);\n\n return cos(floor(.5 + a/r) * r - a) * length(p);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy;\n uv.y = u_resolution.y - uv.y;\n\n uv /= u_pixelRatio;\n\n vec2 grid = fract(uv / vec2(u_gridSpacingX, u_gridSpacingY)) + 1e-4;\n vec2 grid_idx = floor(uv / vec2(u_gridSpacingX, u_gridSpacingY));\n float size_randomizer = .5 + .5 * snoise(2. * vec2(grid_idx.x * 100., grid_idx.y));\n float opacity_randomizer = .5 + .5 * snoise(2. * vec2(grid_idx.y, grid_idx.x));\n\n vec2 center = vec2(0.5) - 1e-3;\n vec2 p = (grid - center) * vec2(u_gridSpacingX, u_gridSpacingY);\n\n float base_size = u_dotSize * (1. - size_randomizer * clamp(u_sizeRange, 0., 1.));\n float stroke_width = u_strokeWidth;\n\n float dist;\n if (u_shape < 0.5) {\n // Circle\n dist = length(p);\n } else if (u_shape < 1.5) {\n // Diamond\n dist = polygon(1.5 * p, 4., .25 * PI);\n } else if (u_shape < 2.5) {\n // Square\n dist = polygon(1.5 * p, 4., 1e-3);\n } else {\n // Triangle\n p = p * 2. - 1.;\n p.y -= .75 * base_size;\n stroke_width *= 2.;\n dist = polygon(p, 3., 1e-3);\n }\n\n float edge_width = fwidth(dist);\n float shape_outer = smoothstep(base_size + edge_width, base_size - edge_width, dist);\n float shape_inner = smoothstep(base_size - u_strokeWidth + edge_width, base_size - u_strokeWidth - edge_width, dist);\n float stroke = clamp(shape_outer - shape_inner, 0., 1.);\n\n float dot_opacity = max(0., 1. - opacity_randomizer * clamp(u_opacityRange, 0., 1.));\n\n vec3 color = u_colorBack.rgb * u_colorBack.a;\n color = mix(color, u_colorFill.rgb, u_colorFill.a * dot_opacity * shape_inner);\n color = mix(color, u_colorStroke.rgb, u_colorStroke.a * dot_opacity * stroke);\n\n float opacity = u_colorBack.a;\n opacity += u_colorFill.a * shape_inner * dot_opacity;\n opacity += u_colorStroke.a * stroke * dot_opacity;\n\n fragColor = vec4(color, opacity);\n}\n";
@@ -1,9 +1,9 @@
1
1
  export type DotsOrbitUniforms = {
2
+ u_scale: number;
2
3
  u_color1: [number, number, number, number];
3
4
  u_color2: [number, number, number, number];
4
5
  u_color3: [number, number, number, number];
5
6
  u_color4: [number, number, number, number];
6
- u_scale: number;
7
7
  u_dotSize: number;
8
8
  u_dotSizeRange: number;
9
9
  u_spreading: number;
@@ -14,13 +14,13 @@ export type DotsOrbitUniforms = {
14
14
  * Renders a dot pattern with dots placed in the center of each cell of animated Voronoi diagram
15
15
  *
16
16
  * Uniforms include:
17
- * u_color1: The first dots color
18
- * u_color2: The second dots color
19
- * u_color3: The third dots color
20
- * u_color4: The fourth dots color
21
- * u_scale: The scale applied to pattern
22
- * u_dotSize: The base dot radius (relative to cell size)
23
- * u_dotSizeRange: Dot radius to vary between the cells
24
- * u_spreading: How far dots are moving around the straight grid
17
+ * u_scale - the scale applied to user space
18
+ * u_color1 - the first dots color
19
+ * u_color2 - the second dots color
20
+ * u_color3 - the third dots color
21
+ * u_color4 - the fourth dots color
22
+ * u_dotSize (0 .. 1) - the base dot radius (relative to cell size)
23
+ * u_dotSizeRange (0 .. 1) - the dot radius to vary between the cells
24
+ * u_spreading (0 .. 1) - the distance each dot can move around the regular grid
25
25
  */
26
- export declare const dotsOrbitFragmentShader = "\nprecision mediump float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform float u_dotSize;\nuniform float u_dotSizeRange;\nuniform float u_scale;\nuniform float u_spreading;\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n\nvec2 random2(vec2 p) {\n return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453);\n}\n\nvec3 get_voronoi_shape(vec2 _uv, float time) {\n vec2 i_uv = floor(_uv);\n vec2 f_uv = fract(_uv);\n\n float min_dist = 1.;\n vec2 cell_randomizer = vec2(0.);\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 tile_offset = vec2(float(x), float(y));\n vec2 rand = random2(i_uv + tile_offset);\n vec2 cell_center = .5 + u_spreading * sin(time + PI * 2. * rand);\n float dist = length(tile_offset + cell_center - f_uv);\n if (dist < min_dist) {\n min_dist = dist;\n cell_randomizer = rand;\n }\n min_dist = min(min_dist, dist);\n }\n }\n\n return vec3(min_dist, cell_randomizer);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n\n vec3 voronoi = get_voronoi_shape(uv, t);\n float radius = u_dotSize - u_dotSizeRange * voronoi[2];\n\n float radius_smoother = .001 + .001 * (u_scale - 1.);\n float shape = 1. - smoothstep(radius, radius + radius_smoother, voronoi[0]);\n\n float color_randomizer = voronoi[1];\n vec4 color =\n u_color1 * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +\n u_color2 * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +\n u_color3 * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +\n u_color4 * step(0.75, color_randomizer) * step(color_randomizer, 1.0);\n\n gl_FragColor = color * shape;\n}\n";
26
+ export declare const dotsOrbitFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform float u_dotSize;\nuniform float u_dotSizeRange;\nuniform float u_spreading;\n\nout vec4 fragColor;\n\n#define TWO_PI 6.28318530718\n\nfloat random(in vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n}\nvec2 random2(vec2 p) {\n return vec2(random(p), random(200. * p));\n}\n\nvec3 get_voronoi_shape(vec2 _uv, float time) {\n vec2 i_uv = floor(_uv);\n vec2 f_uv = fract(_uv);\n\n float min_dist = 1.;\n vec2 cell_randomizer = vec2(0.);\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 tile_offset = vec2(float(x), float(y));\n vec2 rand = random2(i_uv + tile_offset);\n vec2 cell_center = .5 + 1e-4 + .25 * clamp(u_spreading, 0., 1.) * sin(time + TWO_PI * rand);\n float dist = length(tile_offset + cell_center - f_uv);\n if (dist < min_dist) {\n min_dist = dist;\n cell_randomizer = rand;\n }\n min_dist = min(min_dist, dist);\n }\n }\n\n return vec3(min_dist, cell_randomizer);\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n float scale = .5 * u_scale + 1e-4;\n uv *= (.02 * (1. - step(1. - scale, 1.) / scale));\n uv *= u_resolution;\n uv /= u_pixelRatio;\n uv += .5;\n\n float t = u_time;\n\n vec3 voronoi = get_voronoi_shape(uv, t) + 1e-4;\n\n float radius = .25 * clamp(u_dotSize, 0., 1.) - .5 * clamp(u_dotSizeRange, 0., 1.) * voronoi[2];\n float dist = voronoi[0];\n float edge_width = fwidth(dist);\n float shape = smoothstep(radius + edge_width, radius - edge_width, dist);\n\n float color_randomizer = voronoi[1];\n\n float opacity =\n u_color1.a * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +\n u_color2.a * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +\n u_color3.a * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +\n u_color4.a * step(0.75, color_randomizer) * step(color_randomizer, 1.0);\n\n opacity *= shape;\n\n vec3 color =\n u_color1.rgb * step(0.0, color_randomizer) * step(color_randomizer, 0.25) +\n u_color2.rgb * step(0.25, color_randomizer) * step(color_randomizer, 0.5) +\n u_color3.rgb * step(0.5, color_randomizer) * step(color_randomizer, 0.75) +\n u_color4.rgb * step(0.75, color_randomizer) * step(color_randomizer, 1.0);\n\n fragColor = vec4(color * opacity, opacity);\n}\n";
@@ -1,7 +1,7 @@
1
1
  export type GrainCloudsUniforms = {
2
+ u_scale: number;
2
3
  u_color1: [number, number, number, number];
3
4
  u_color2: [number, number, number, number];
4
- u_scale: number;
5
5
  u_grainAmount: number;
6
6
  };
7
7
  /**
@@ -10,9 +10,9 @@ export type GrainCloudsUniforms = {
10
10
  * Generated by Claude 3.5 Sonnet
11
11
  *
12
12
  * Uniforms include:
13
- * u_color1: The first color of the clouds
14
- * u_color2: The second color of the clouds
15
- * u_scale: The scale of the noise
16
- * u_grainAmount: The amount of grain on the texture
13
+ * u_scale - the scale applied to user space
14
+ * u_color1 - the first mixed color
15
+ * u_color2 - the second mixed color
16
+ * u_grainAmount - the power of overlapping grain texture
17
17
  */
18
- export declare const grainCloudsFragmentShader = "\n precision highp float;\n uniform vec2 u_resolution;\n uniform float u_time;\n\n uniform vec4 u_color1;\n uniform vec4 u_color2;\n uniform float u_scale;\n uniform float u_grainAmount;\n\n // Simplex 2D noise\n vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }\n\n float snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy),\n dot(x12.zw,x12.zw)), 0.0);\n m = m*m ;\n m = m*m ;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n }\n\n void main() {\n vec2 st = gl_FragCoord.xy / u_resolution.xy;\n\n // Calculate the aspect ratio of the shader\n float shaderAspect = u_resolution.x / u_resolution.y;\n\n // Define the aspect ratio of your content (e.g., 1.0 for square)\n float contentAspect = 1.0;\n\n // Adjust st to maintain content aspect ratio\n if (shaderAspect > contentAspect) {\n float scale = shaderAspect / contentAspect;\n st.x = (st.x - 0.5) * scale + 0.5;\n } else {\n float scale = contentAspect / shaderAspect;\n st.y = (st.y - 0.5) * scale + 0.5;\n }\n\n // Create blobby texture\n float n = snoise(st * u_scale + u_time);\n n += 0.5 * snoise(st * u_scale * 2.0 - u_time * 0.5);\n n += 0.25 * snoise(st * u_scale * 4.0 + u_time * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec4 color = mix(u_color1, u_color2, n);\n\n // Add grain\n float grain = fract(sin(dot(st * 1000.0, vec2(12.9898, 78.233))) * 43758.5453);\n color += (grain - 0.5) * u_grainAmount;\n\n gl_FragColor = color;\n }\n";
18
+ export declare const grainCloudsFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_time;\n\nuniform float u_scale;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform float u_grainAmount;\n\nout vec4 fragColor;\n\n// Simplex 2D noise\nvec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }\n\nfloat snoise(vec2 v) {\n const vec4 C = vec4(0.211324865405187, 0.366025403784439,\n -0.577350269189626, 0.024390243902439);\n vec2 i = floor(v + dot(v, C.yy));\n vec2 x0 = v - i + dot(i, C.xx);\n vec2 i1;\n i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n vec4 x12 = x0.xyxy + C.xxzz;\n x12.xy -= i1;\n i = mod(i, 289.0);\n vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))\n + i.x + vec3(0.0, i1.x, 1.0));\n vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),\n dot(x12.zw, x12.zw)), 0.0);\n m = m * m;\n m = m * m;\n vec3 x = 2.0 * fract(p * C.www) - 1.0;\n vec3 h = abs(x) - 0.5;\n vec3 ox = floor(x + 0.5);\n vec3 a0 = x - ox;\n m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);\n vec3 g;\n g.x = a0.x * x0.x + h.x * x0.y;\n g.yz = a0.yz * x12.xz + h.yz * x12.yw;\n return 130.0 * dot(m, g);\n}\n\nfloat rand(vec2 n) {\n return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);\n}\nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\nfloat fbm(vec2 n) {\n float total = 0.0, amplitude = .2;\n for (int i = 0; i < 6; i++) {\n total += noise(n) * amplitude;\n n += n;\n amplitude *= 0.6;\n }\n return total;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n float scale = .5 * u_scale + 1e-4;\n uv *= (.0004 * (1. - step(1. - scale, 1.) / scale));\n uv *= u_resolution;\n uv /= u_pixelRatio;\n uv += .5;\n\n // Create blobby texture\n float n = snoise(uv + u_time);\n n += 0.5 * snoise(uv * 2.0 - u_time * 0.5);\n n += 0.25 * snoise(uv * 4.0 + u_time * 0.25);\n n = n * 0.5 + 0.5;\n\n // Color interpolation\n vec3 color = mix(u_color1.rgb, u_color2.rgb, n);\n float opacity = mix(u_color1.a, u_color2.a, n);\n\n // Add grain\n float grain = fbm(uv * 1000.);\n color.rgb += (grain - 0.5) * u_grainAmount;\n\n fragColor = vec4(color * opacity, opacity);\n}\n";
@@ -15,4 +15,4 @@ export type MeshGradientUniforms = {
15
15
  * u_color3: The third color of the mesh gradient
16
16
  * u_color4: The fourth color of the mesh gradient
17
17
  */
18
- export declare const meshGradientFragmentShader = "\n// Mesh Gradient: https://www.shadertoy.com/view/wdyczG\n#define S(a,b,t) smoothstep(a,b,t)\n\nprecision highp float;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\nuniform vec2 u_resolution;\nuniform float u_time;\n\nmat2 Rot(float a)\n{\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\n}\n\n\nvec2 hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nfloat noise( in vec2 p )\n{\n vec2 i = floor( p );\n vec2 f = fract( p );\n\n\tvec2 u = f*f*(3.0-2.0*f);\n\n float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),\n mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);\n\treturn 0.5 + 0.5*n;\n}\n\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n vec2 tuv = uv;\n tuv -= .5;\n\n // rotate with Noise\n float degree = noise(vec2(u_time, tuv.x * tuv.y));\n\n tuv.y *= 1./ratio;\n tuv *= Rot(radians((degree-.5)*720.+180.));\n\ttuv.y *= ratio;\n\n\n // Wave warp with sin\n float frequency = 5.;\n float amplitude = 30.;\n float speed = u_time * 2.;\n tuv.x += sin(tuv.y*frequency+speed)/amplitude;\n \ttuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n // draw the image\n vec4 layer1 = mix(u_color1, u_color2, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n vec4 layer2 = mix(u_color3, u_color4, S(-.3, .2, (tuv*Rot(radians(-5.))).x));\n\n vec4 finalComp = mix(layer1, layer2, S(.5, -.3, tuv.y));\n gl_FragColor = finalComp;\n}\n";
18
+ export declare const meshGradientFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\nuniform float u_time;\n\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform vec4 u_color4;\n\nout vec4 fragColor;\n\n#define S(a,b,t) smoothstep(a,b,t)\n\nmat2 Rot(float a) {\n float s = sin(a);\n float c = cos(a);\n return mat2(c, -s, s, c);\n}\n\nvec2 hash(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.xx+p3.yz)*p3.zy);\n}\n\nfloat noise( in vec2 p ) {\n vec2 i = floor( p );\n vec2 f = fract( p );\n vec2 u = f*f*(3.0-2.0*f);\n\n float n = mix( mix( dot( -1.0+2.0*hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),\n mix( dot( -1.0+2.0*hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),\n dot( -1.0+2.0*hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);\n return 0.5 + 0.5*n;\n}\n\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n \n uv /= u_pixelRatio;\n \n vec2 tuv = uv;\n tuv -= .5;\n\n // rotate with Noise\n float degree = noise(vec2(u_time, tuv.x * tuv.y));\n\n tuv.y *= 1./ratio;\n tuv *= Rot(radians((degree-.5)*720.+180.));\n tuv.y *= ratio;\n\n\n // Wave warp with sin\n float frequency = 5.;\n float amplitude = 30.;\n float speed = u_time * 2.;\n tuv.x += sin(tuv.y*frequency+speed)/amplitude;\n tuv.y += sin(tuv.x*frequency*1.5+speed)/(amplitude*.5);\n\n\n float proportion_1 = S(-.3, .2, (tuv*Rot(radians(-5.))).x);\n vec3 layer1_color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, proportion_1);\n float layer1_opacity = mix(u_color1.a, u_color2.a, proportion_1);\n vec3 layer2_color = mix(u_color3.rgb * u_color3.a, u_color4.rgb * u_color4.a, proportion_1);\n float layer2_opacity = mix(u_color3.a, u_color4.a, proportion_1);\n\n float proportion_2 = S(.5, -.3, tuv.y);\n vec3 color = mix(layer1_color, layer2_color, proportion_2);\n float opacity = mix(layer1_opacity, layer2_opacity, proportion_2);\n \n fragColor = vec4(color, opacity);\n}\n";
@@ -0,0 +1,22 @@
1
+ export type MetaballsUniforms = {
2
+ u_scale: number;
3
+ u_color1: [number, number, number, number];
4
+ u_color2: [number, number, number, number];
5
+ u_color3: [number, number, number, number];
6
+ u_ballSize: number;
7
+ u_visibilityRange: number;
8
+ };
9
+ /**
10
+ * Metaballs (circular shapes with gooey effect applied)
11
+ * The artwork by Ksenia Kondrashova
12
+ *
13
+ * Uniforms include:
14
+ * u_scale - the scale applied to user space
15
+ * (with scale = 1 metaballs fit the screen height)
16
+ * u_color1 - the mataballs gradient color #1
17
+ * u_color2 - the mataballs gradient color #2
18
+ * u_color3 - the mataballs gradient color #3
19
+ * u_ballSize (0 .. 1) - the size coefficient applied to each ball
20
+ * u_visibilityRange (0 .. 1) - to show 2 to 15 balls
21
+ */
22
+ export declare const metaballsFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform vec4 u_color3;\nuniform float u_ballSize;\nuniform float u_visibilityRange;\n\n#define TWO_PI 6.28318530718\n\nout vec4 fragColor;\n\nfloat hash(float x) {\n return fract(sin(x) * 43758.5453123);\n}\nfloat lerp(float a, float b, float t) {\n return a + t * (b - a);\n}\nfloat noise(float x) {\n float i = floor(x);\n float f = fract(x);\n float u = f * f * (3.0 - 2.0 * f); // Smoothstep function for interpolation\n return lerp(hash(i), hash(i + 1.0), u);\n}\n\nfloat get_ball_shape(vec2 uv, vec2 c, float p) {\n float s = .5 * length(uv - c);\n s = 1. - clamp(s, 0., 1.);\n s = pow(s, p);\n return s;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float ratio = u_resolution.x / u_resolution.y;\n\n uv -= .5;\n uv /= u_pixelRatio;\n float scale = .5 * u_scale + 1e-4;\n uv *= (18. * (1. - step(1. - scale, 1.) / scale));\n uv += .5;\n uv.x *= ratio;\n\n float t = u_time;\n\n vec3 total_color = vec3(0.);\n float total_shape = 0.;\n\n const int max_balls_number = 15;\n for (int i = 0; i < max_balls_number; i++) {\n vec2 pos = vec2(.5) + 1e-4;\n float idx_fract = float(i) / float(max_balls_number);\n float angle = TWO_PI * idx_fract;\n\n float speed = 1. - .2 * idx_fract;\n float noiseX = noise(angle * 10. + float(i) + t * speed);\n float noiseY = noise(angle * 20. + float(i) - t * speed);\n\n pos += 7. * (vec2(noiseX, noiseY) - .5);\n\n vec4 ball_color;\n if (i % 3 == 0) {\n ball_color = u_color1;\n } else if (i % 3 == 1) {\n ball_color = u_color2;\n } else {\n ball_color = u_color3;\n }\n\n float shape = get_ball_shape(uv, pos, 6. - 4. * u_ballSize) * ball_color.a;\n\n shape *= smoothstep((float(i) - 1.) / float(max_balls_number), idx_fract, u_visibilityRange);\n\n total_color += ball_color.rgb * shape;\n total_shape += shape;\n }\n\n total_color /= max(total_shape, 1e-4);\n\n float edge_width = fwidth(total_shape);\n float final_shape = smoothstep(.4, .4 + edge_width, total_shape);\n\n vec3 color = total_color * final_shape;\n float opacity = final_shape;\n\n if (opacity < .01) {\n discard;\n }\n\n fragColor = vec4(color, opacity);\n}\n";
@@ -1,18 +1,18 @@
1
1
  export type NeuroNoiseUniforms = {
2
+ u_scale: number;
2
3
  u_colorFront: [number, number, number, number];
3
4
  u_colorBack: [number, number, number, number];
4
- u_scale: number;
5
5
  u_brightness: number;
6
6
  };
7
7
  /**
8
- * Neuro Noise Pattern;
8
+ * Neuro Noise Pattern
9
9
  * The original artwork: https://codepen.io/ksenia-k/full/vYwgrWv by Ksenia Kondrashova
10
10
  * Renders a fractal-like structure made of several layers of since-arches
11
11
  *
12
12
  * Uniforms include:
13
- * u_colorFront: The front color of pattern
14
- * u_colorBack: The back color of pattern
15
- * u_brightness: The power/brightness of pattern lines
16
- * u_scale: The scale applied to coordinates
13
+ * u_scale - the scale applied to user space
14
+ * u_colorFront - the front color of pattern
15
+ * u_colorBack - the back color of pattern
16
+ * u_brightness - the power (brightness) of pattern lines
17
17
  */
18
- export declare const neuroNoiseFragmentShader = "\nprecision mediump float;\n\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_scale;\nuniform float u_brightness;\n\nuniform float u_time;\nuniform float u_ratio;\nuniform vec2 u_resolution;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat neuro_shape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n uv *= (.001 * u_scale * u_resolution);\n uv += .5;\n\n float t = u_time;\n vec3 color = vec3(0.);\n\n float noise = neuro_shape(uv, t);\n\n noise = u_brightness * pow(noise, 3.);\n noise += pow(noise, 12.);\n noise = max(.0, noise - .5);\n\n gl_FragColor = mix(u_colorBack, u_colorFront, noise);\n}\n";
18
+ export declare const neuroNoiseFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_brightness;\n\nout vec4 fragColor;\n\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n\nfloat neuro_shape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n\n uv -= .5;\n float scale = .5 * u_scale + 1e-4;\n uv *= (.001 * (1. - step(1. - scale, 1.) / scale));\n uv *= u_resolution;\n uv /= u_pixelRatio;\n uv += .5;\n\n float t = u_time;\n\n float noise = neuro_shape(uv, t);\n\n noise = u_brightness * pow(noise, 3.);\n noise += pow(noise, 12.);\n noise = max(.0, noise - .5);\n\n vec3 color = mix(u_colorBack.rgb * u_colorBack.a, u_colorFront.rgb * u_colorFront.a, noise);\n float opacity = mix(u_colorBack.a, u_colorFront.a, noise);\n\n fragColor = vec4(color, opacity);\n}\n";
@@ -0,0 +1,28 @@
1
+ export type PerlinNoiseUniforms = {
2
+ u_scale: number;
3
+ u_color1: [number, number, number, number];
4
+ u_color2: [number, number, number, number];
5
+ u_proportion: number;
6
+ u_contour: number;
7
+ u_octaveCount: number;
8
+ u_persistence: number;
9
+ u_lacunarity: number;
10
+ };
11
+ /**
12
+ * 3d Perlin noise with exposed parameters
13
+ * Based on https://www.shadertoy.com/view/NlSGDz
14
+ *
15
+ * Uniforms include:
16
+ * u_scale - the scale applied to user space
17
+ * u_color1 - the first mixed color
18
+ * u_color2 - the second mixed color
19
+ * u_proportion (0 .. 1) - the proportion between u_color1 and u_color2;
20
+ * u_contour - the sharpness of the transition between u_color1 and u_color2 in the noise output
21
+ * u_octaveCount - the number of octaves for Perlin noise;
22
+ * higher values increase the complexity of the noise
23
+ * u_persistence (0 .. 1) - the amplitude of each successive octave of the noise;
24
+ * lower values make higher octaves less pronounced
25
+ * u_lacunarity - the frequency of each successive octave of the noise;
26
+ * higher values increase the detail
27
+ */
28
+ export declare const perlinNoiseFragmentShader = "#version 300 es\nprecision highp float;\n\nuniform float u_time;\nuniform float u_pixelRatio;\nuniform vec2 u_resolution;\n\nuniform float u_scale;\nuniform vec4 u_color1;\nuniform vec4 u_color2;\nuniform float u_proportion;\nuniform float u_contour;\nuniform float u_octaveCount;\nuniform float u_persistence;\nuniform float u_lacunarity;\n\nout vec4 fragColor;\n\n#define TWO_PI 6.28318530718\n\nuint hash(uint x, uint seed) {\n const uint m = 0x5bd1e995U;\n uint hash = seed;\n // process input\n uint k = x;\n k *= m;\n k ^= k >> 24;\n k *= m;\n hash *= m;\n hash ^= k;\n // some final mixing\n hash ^= hash >> 13;\n hash *= m;\n hash ^= hash >> 15;\n return hash;\n}\n\nuint hash(uvec3 x, uint seed){\n const uint m = 0x5bd1e995U;\n uint hash = seed;\n // process first vector element\n uint k = x.x; \n k *= m;\n k ^= k >> 24;\n k *= m;\n hash *= m;\n hash ^= k;\n // process second vector element\n k = x.y; \n k *= m;\n k ^= k >> 24;\n k *= m;\n hash *= m;\n hash ^= k;\n // process third vector element\n k = x.z; \n k *= m;\n k ^= k >> 24;\n k *= m;\n hash *= m;\n hash ^= k;\n // some final mixing\n hash ^= hash >> 13;\n hash *= m;\n hash ^= hash >> 15;\n return hash;\n}\n\n\nvec3 gradientdy(uint hash) {\n switch (int(hash) & 15) { // look at the last four bits to pick a gradient dy\n case 0:\n return vec3(1, 1, 0);\n case 1:\n return vec3(-1, 1, 0);\n case 2:\n return vec3(1, -1, 0);\n case 3:\n return vec3(-1, -1, 0);\n case 4:\n return vec3(1, 0, 1);\n case 5:\n return vec3(-1, 0, 1);\n case 6:\n return vec3(1, 0, -1);\n case 7:\n return vec3(-1, 0, -1);\n case 8:\n return vec3(0, 1, 1);\n case 9:\n return vec3(0, -1, 1);\n case 10:\n return vec3(0, 1, -1);\n case 11:\n return vec3(0, -1, -1);\n case 12:\n return vec3(1, 1, 0);\n case 13:\n return vec3(-1, 1, 0);\n case 14:\n return vec3(0, -1, 1);\n case 15:\n return vec3(0, -1, -1);\n }\n}\n\nfloat interpolate(float value1, float value2, float value3, float value4, float value5, float value6, float value7, float value8, vec3 t) {\n return mix(\n mix(mix(value1, value2, t.x), mix(value3, value4, t.x), t.y),\n mix(mix(value5, value6, t.x), mix(value7, value8, t.x), t.y),\n t.z\n );\n}\n\nvec3 fade(vec3 t) {\n return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);\n}\n\nfloat perlinNoise(vec3 position, uint seed) {\n position += 1e+4;\n vec3 floorPosition = floor(position);\n vec3 fractPosition = fract(position);\n uvec3 cellCoordinates = uvec3(floorPosition);\n float value1 = dot(gradientdy(hash(cellCoordinates, seed)), fractPosition);\n float value2 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 0, 0)), seed)), fractPosition - vec3(1, 0, 0));\n float value3 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 1, 0)), seed)), fractPosition - vec3(0, 1, 0));\n float value4 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 1, 0)), seed)), fractPosition - vec3(1, 1, 0));\n float value5 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 0, 1)), seed)), fractPosition - vec3(0, 0, 1));\n float value6 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 0, 1)), seed)), fractPosition - vec3(1, 0, 1));\n float value7 = dot(gradientdy(hash((cellCoordinates + uvec3(0, 1, 1)), seed)), fractPosition - vec3(0, 1, 1));\n float value8 = dot(gradientdy(hash((cellCoordinates + uvec3(1, 1, 1)), seed)), fractPosition - vec3(1, 1, 1));\n return interpolate(value1, value2, value3, value4, value5, value6, value7, value8, fade(fractPosition));\n}\n\nfloat p_noise(vec3 position, int octaveCount, float persistence, float lacunarity) {\n float value = 0.0;\n float amplitude = 1.0;\n float currentFrequency = 10.;\n uint currentSeed = uint(0);\n for (int i = 0; i < octaveCount; i++) {\n currentSeed = hash(currentSeed, 0x0U);\n value += perlinNoise(position * currentFrequency, currentSeed) * amplitude;\n amplitude *= persistence;\n currentFrequency *= lacunarity;\n }\n return value;\n}\n\nfloat get_max_amp(float persistence, float octaveCount) {\n persistence *= .999;\n return (1. - pow(persistence, octaveCount)) / (1. - persistence);\n}\n\nvoid main() {\n\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n float t = .2 * u_time;\n\n uv -= .5;\n uv *= (.004 * u_scale * u_resolution);\n uv /= u_pixelRatio;\n uv += .5;\n \n vec3 p = vec3(uv, t);\n \n float oct_count = max(0., floor(u_octaveCount));\n float persistence = clamp(u_persistence, 0., 1.);\n float noise = p_noise(p, int(oct_count), persistence, u_lacunarity);\n \n float max_amp = get_max_amp(persistence, oct_count);\n float noise_normalized = (noise + max_amp) / (2. * max_amp) + (u_proportion - .5);\n float sharpness = clamp(1. - u_contour, 0., 1.);\n float smooth_w = 0.5 * fwidth(noise_normalized);\n float sharp_noise = smoothstep(\n .5 - .5 * sharpness - smooth_w, \n .5 + .5 * sharpness + smooth_w, \n noise_normalized\n );\n\n vec3 color = mix(u_color1.rgb * u_color1.a, u_color2.rgb * u_color2.a, sharp_noise);\n float opacity = mix(u_color1.a, u_color2.a, sharp_noise);\n\n fragColor = vec4(color, opacity);\n}\n";