@paper-design/shaders 0.0.31-backbuffer-experiment.2 → 0.0.32

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.
Files changed (68) hide show
  1. package/README.md +7 -4
  2. package/dist/index.d.ts +1 -1
  3. package/dist/shader-mount.d.ts +0 -9
  4. package/dist/shaders/dithering.d.ts +6 -6
  5. package/dist/shaders/dot-orbit.d.ts +0 -3
  6. package/dist/shaders/god-rays.d.ts +3 -6
  7. package/dist/shaders/grain-gradient.d.ts +0 -2
  8. package/dist/shaders/liquid-metal.d.ts +10 -25
  9. package/dist/shaders/metaballs.d.ts +0 -3
  10. package/dist/shaders/neuro-noise.d.ts +4 -10
  11. package/dist/shaders/perlin-noise.d.ts +8 -8
  12. package/dist/shaders/spiral.d.ts +6 -6
  13. package/dist/shaders/swirl.d.ts +0 -2
  14. package/dist/shaders/voronoi.d.ts +5 -5
  15. package/dist/shaders/waves.d.ts +6 -6
  16. package/package.json +2 -2
  17. package/dist/get-shader-color-from-string.js +0 -93
  18. package/dist/get-shader-color-from-string.js.map +0 -7
  19. package/dist/get-shader-noise-texture.js +0 -23
  20. package/dist/get-shader-noise-texture.js.map +0 -7
  21. package/dist/index.js +0 -109
  22. package/dist/index.js.map +0 -7
  23. package/dist/shader-color-spaces.js +0 -96
  24. package/dist/shader-color-spaces.js.map +0 -7
  25. package/dist/shader-mount.js +0 -733
  26. package/dist/shader-mount.js.map +0 -7
  27. package/dist/shader-sizing.js +0 -193
  28. package/dist/shader-sizing.js.map +0 -7
  29. package/dist/shader-utils.js +0 -59
  30. package/dist/shader-utils.js.map +0 -7
  31. package/dist/shaders/dithering.js +0 -221
  32. package/dist/shaders/dithering.js.map +0 -7
  33. package/dist/shaders/dot-grid.js +0 -107
  34. package/dist/shaders/dot-grid.js.map +0 -7
  35. package/dist/shaders/dot-orbit.js +0 -124
  36. package/dist/shaders/dot-orbit.js.map +0 -7
  37. package/dist/shaders/god-rays.js +0 -133
  38. package/dist/shaders/god-rays.js.map +0 -7
  39. package/dist/shaders/grain-gradient.js +0 -243
  40. package/dist/shaders/grain-gradient.js.map +0 -7
  41. package/dist/shaders/liquid-metal.js +0 -221
  42. package/dist/shaders/liquid-metal.js.map +0 -7
  43. package/dist/shaders/mesh-gradient.js +0 -97
  44. package/dist/shaders/mesh-gradient.js.map +0 -7
  45. package/dist/shaders/metaballs.js +0 -110
  46. package/dist/shaders/metaballs.js.map +0 -7
  47. package/dist/shaders/neuro-noise.js +0 -81
  48. package/dist/shaders/neuro-noise.js.map +0 -7
  49. package/dist/shaders/perlin-noise.js +0 -201
  50. package/dist/shaders/perlin-noise.js.map +0 -7
  51. package/dist/shaders/pulsing-border.js +0 -218
  52. package/dist/shaders/pulsing-border.js.map +0 -7
  53. package/dist/shaders/simplex-noise.js +0 -103
  54. package/dist/shaders/simplex-noise.js.map +0 -7
  55. package/dist/shaders/smoke-ring.js +0 -141
  56. package/dist/shaders/smoke-ring.js.map +0 -7
  57. package/dist/shaders/spiral.js +0 -83
  58. package/dist/shaders/spiral.js.map +0 -7
  59. package/dist/shaders/swirl.js +0 -91
  60. package/dist/shaders/swirl.js.map +0 -7
  61. package/dist/shaders/voronoi.js +0 -143
  62. package/dist/shaders/voronoi.js.map +0 -7
  63. package/dist/shaders/warp.js +0 -128
  64. package/dist/shaders/warp.js.map +0 -7
  65. package/dist/shaders/waves.js +0 -68
  66. package/dist/shaders/waves.js.map +0 -7
  67. package/dist/types.js +0 -6
  68. package/dist/types.js.map +0 -7
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/shader-mount.ts"],
4
- "sourcesContent": ["const DEFAULT_MAX_PIXEL_COUNT: number = 1920 * 1080 * 4;\n\nexport class ShaderMount {\n public parentElement: PaperShaderElement;\n public canvasElement: 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 lastRenderTime = 0;\n /** Total time that we have played any animation, passed as a uniform to the shader for time-based VFX */\n private totalFrameTime = 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 = 0;\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: ShaderMountUniforms;\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 /** Store textures that are provided by the user */\n private textures: Map<string, WebGLTexture> = new Map();\n private minPixelRatio;\n private maxPixelCount;\n private isSafari = isSafari();\n\n // Framebuffer properties\n private framebuffer: WebGLFramebuffer | null = null;\n private framebufferTexture: WebGLTexture | null = null;\n private framebufferWidth = 0;\n private framebufferHeight = 0;\n private framebufferSamplingProgram: WebGLProgram | null = null;\n private framebufferSamplingUniformLocations: Record<string, WebGLUniformLocation | null> = {};\n\n constructor(\n /** The div you'd like to mount the shader to. The shader will match its size. */\n parentElement: HTMLElement,\n fragmentShader: string,\n uniforms: ShaderMountUniforms,\n webGlContextAttributes?: WebGLContextAttributes,\n /** The speed of the animation, or 0 to stop it. Supports negative values to play in reverse. */\n speed = 0,\n /** Pass a frame to offset the starting u_time value and give deterministic results*/\n frame = 0,\n /**\n * The minimum pixel ratio to render at, defaults to 2.\n * May be reduced to improve performance or increased together with `maxPixelCount` to improve antialiasing.\n */\n minPixelRatio = 2,\n /**\n * The maximum amount of physical device pixels to render for the shader,\n * by default it's 1920 * 1080 * 2x dpi (per each side) = 8,294,400 pixels of a 4K screen.\n * Actual DOM size of the canvas can be larger, it will just lose quality after this.\n *\n * May be reduced to improve performance or increased to improve quality on high-resolution screens.\n */\n maxPixelCount: number = DEFAULT_MAX_PIXEL_COUNT\n ) {\n if (parentElement instanceof HTMLElement) {\n this.parentElement = parentElement as PaperShaderElement;\n } else {\n throw new Error('Paper Shaders: parent element must be an HTMLElement');\n }\n\n if (!document.querySelector('style[data-paper-shaders]')) {\n const styleElement = document.createElement('style');\n styleElement.innerHTML = defaultStyle;\n styleElement.setAttribute('data-paper-shaders', '');\n document.head.prepend(styleElement);\n }\n\n // Create the canvas element and mount it into the provided element\n const canvasElement = document.createElement('canvas');\n this.canvasElement = canvasElement;\n this.parentElement.prepend(canvasElement);\n this.fragmentShader = fragmentShader;\n this.providedUniforms = uniforms;\n // Base our starting animation time on the provided frame value\n this.totalFrameTime = frame;\n this.minPixelRatio = minPixelRatio;\n this.maxPixelCount = maxPixelCount;\n\n const gl = canvasElement.getContext('webgl2', webGlContextAttributes);\n if (!gl) {\n throw new Error('Paper Shaders: WebGL is not supported in this browser');\n }\n this.gl = gl;\n\n // Initialize framebuffer and texture\n this.framebuffer = this.gl.createFramebuffer();\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffer);\n\n this.framebufferTexture = this.gl.createTexture();\n this.gl.bindTexture(this.gl.TEXTURE_2D, this.framebufferTexture);\n this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);\n this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);\n this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);\n this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);\n\n this.initProgram();\n this.setupPositionAttribute();\n // Grab the locations of the uniforms in the fragment shader\n this.setupUniforms();\n // Put the user provided values into the uniforms\n this.setUniformValues(this.providedUniforms);\n // Set up the resize observer to handle window resizing and set u_resolution\n this.setupResizeObserver();\n\n // Set the animation speed after everything is ready to go\n this.setSpeed(speed);\n\n // Mark parent element as paper shader mount\n this.parentElement.setAttribute('data-paper-shaders', '');\n\n // Add the shaderMount instance to the div mount element to make it easily accessible\n this.parentElement.paperShaderMount = this;\n }\n\n private initProgram = () => {\n const program = createProgram(this.gl, vertexShaderSource, this.fragmentShader);\n if (!program) return;\n this.program = program;\n\n // Initialize framebuffer program\n const framebufferVertexShader = `#version 300 es\n precision mediump float;\n\n layout(location = 0) in vec4 a_position;\n out vec2 v_texCoord;\n\n void main() {\n gl_Position = a_position;\n v_texCoord = a_position.xy * 0.5 + 0.5;\n }\n `;\n\n const framebufferFragmentShader = `#version 300 es\n precision mediump float;\n uniform sampler2D u_texture;\n uniform vec2 u_textureSize;\n uniform vec2 u_targetSize;\n\n in vec2 v_texCoord;\n out vec4 fragColor;\n\n void main() {\n // Calculate the scale factor between target size and texture size\n vec2 scale = u_targetSize / u_textureSize;\n \n // Scale UVs to only sample the portion of the texture that contains our render\n vec2 uv = v_texCoord * scale;\n \n fragColor = texture(u_texture, uv);\n }\n `;\n\n const framebufferProgram = createProgram(this.gl, framebufferVertexShader, framebufferFragmentShader);\n if (!framebufferProgram) return;\n\n this.framebufferSamplingProgram = framebufferProgram;\n this.framebufferSamplingUniformLocations = {\n u_texture: this.gl.getUniformLocation(framebufferProgram, 'u_texture'),\n u_textureSize: this.gl.getUniformLocation(framebufferProgram, 'u_textureSize'),\n u_targetSize: this.gl.getUniformLocation(framebufferProgram, 'u_targetSize'),\n };\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 // Create a map to store all uniform locations\n const uniformLocations: Record<string, WebGLUniformLocation | null> = {\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 };\n\n // Add locations for all provided uniforms\n Object.entries(this.providedUniforms).forEach(([key, value]) => {\n uniformLocations[key] = this.gl.getUniformLocation(this.program!, key);\n\n // For texture uniforms, also look for the aspect ratio uniform\n if (value instanceof HTMLImageElement) {\n const aspectRatioUniformName = `${key}_aspect_ratio`;\n uniformLocations[aspectRatioUniformName] = this.gl.getUniformLocation(this.program!, aspectRatioUniformName);\n }\n });\n\n this.uniformLocations = uniformLocations;\n };\n\n /**\n * The scale that we should render at.\n * - Used to target 2x rendering even on 1x screens for better antialiasing\n * - Prevents the virtual resolution from going beyond the maximum resolution\n * - Accounts for the page zoom level so we render in physical device pixels rather than CSS pixels\n */\n private renderScale = 1;\n private parentWidth = 0;\n private parentHeight = 0;\n\n private resizeObserver: ResizeObserver | null = null;\n private setupResizeObserver = () => {\n this.resizeObserver = new ResizeObserver(([entry]) => {\n if (entry?.borderBoxSize[0]) {\n this.parentWidth = entry.borderBoxSize[0].inlineSize;\n this.parentHeight = entry.borderBoxSize[0].blockSize;\n }\n\n this.handleResize();\n });\n\n this.resizeObserver.observe(this.parentElement);\n visualViewport?.addEventListener('resize', this.handleVisualViewportChange);\n\n const rect = this.parentElement.getBoundingClientRect();\n this.parentWidth = rect.width;\n this.parentHeight = rect.height;\n this.handleResize();\n };\n\n // Visual viewport resize handler, mainly used to react to browser zoom changes.\n // Wait 2 frames to align with when the resize observer callback is done (in case it might follow):\n // - Frame 1: a paint after the visual viewport resize\n // - Frame 2: a paint after the resize observer has been handled, if it was ever triggered\n //\n // Both resize observer and visual viewport will react to classic browser zoom changes,\n // so we dedupe the callbacks, but pinch zoom only triggers the visual viewport handler.\n private resizeRafId: number | null = null;\n private handleVisualViewportChange = () => {\n if (this.resizeRafId !== null) {\n cancelAnimationFrame(this.resizeRafId);\n }\n\n this.resizeRafId = requestAnimationFrame(() => {\n this.resizeRafId = requestAnimationFrame(() => {\n this.handleResize();\n });\n });\n };\n\n /** Resize handler for when the container div changes size or the max pixel count changes and we want to resize our canvas to match */\n private handleResize = () => {\n // Cancel any scheduled resize handlers\n if (this.resizeRafId !== null) {\n cancelAnimationFrame(this.resizeRafId);\n }\n\n const { width, height, renderScale } = this.getCanvasSize();\n\n if (\n this.canvasElement.width !== width ||\n this.canvasElement.height !== height ||\n this.renderScale !== renderScale // Usually, only render scale change when the user zooms in/out\n ) {\n this.renderScale = renderScale;\n this.canvasElement.width = width;\n this.canvasElement.height = height;\n this.resolutionChanged = true;\n this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);\n\n // this is necessary to avoid flashes while resizing (the next scheduled render will set uniforms)\n this.render(performance.now());\n }\n };\n\n private getCanvasSize = () => {\n const pinchZoom = visualViewport?.scale ?? 1;\n\n // Zoom level can be calculated comparing the browser's outerWidth and the viewport width.\n // Note: avoid innerWidth, use visualViewport.width instead.\n // - innerWidth is affected by pinch zoom in Safari, but not other browsers.\n // visualViewport.width works consistently in all browsers.\n // - innerWidth is rounded to integer, but not visualViewport.width.\n const innerWidth = visualViewport ? visualViewport.width * visualViewport.scale : window.innerWidth;\n\n // Slight rounding here helps the <canvas> maintain a consistent computed size as the zoom level changes\n const classicZoom = Math.round((10000 * window.outerWidth) / innerWidth) / 10000;\n\n // As of 2025, Safari reports physical devicePixelRatio, but other browsers add the current zoom level\n // https://bugs.webkit.org/show_bug.cgi?id=124862\n const realPixelRatio = this.isSafari ? devicePixelRatio : devicePixelRatio / classicZoom;\n const targetPixelRatio = Math.max(realPixelRatio, this.minPixelRatio);\n const targetRenderScale = targetPixelRatio * classicZoom * pinchZoom;\n const targetPixelWidth = this.parentWidth * targetRenderScale;\n const targetPixelHeight = this.parentHeight * targetRenderScale;\n\n // Prevent the total rendered pixel count from exceeding maxPixelCount\n const maxPixelCountHeadroom = Math.sqrt(this.maxPixelCount) / Math.sqrt(targetPixelWidth * targetPixelHeight);\n\n const newRenderScale = targetRenderScale * Math.min(1, maxPixelCountHeadroom);\n const newWidth = Math.round(this.parentWidth * newRenderScale);\n const newHeight = Math.round(this.parentHeight * newRenderScale);\n\n return {\n width: newWidth,\n height: newHeight,\n renderScale: newRenderScale,\n };\n };\n\n private handleResolutionChange = () => {\n const { renderScale, width, height } = this.getCanvasSize();\n\n if (\n this.renderScale !== renderScale ||\n this.canvasElement.width !== width ||\n this.canvasElement.height !== height\n ) {\n this.renderScale = renderScale;\n this.canvasElement.width = width;\n this.canvasElement.height = height;\n this.resolutionChanged = true;\n }\n };\n\n private ensureSceneTarget = (targetFramebufferWidth: number, targetFramebufferHeight: number) => {\n if (targetFramebufferWidth <= this.framebufferWidth && targetFramebufferHeight <= this.framebufferHeight) return; // already big enough\n\n this.framebufferWidth = Math.max(targetFramebufferWidth, this.framebufferWidth);\n this.framebufferHeight = Math.max(targetFramebufferHeight, this.framebufferHeight);\n\n // Update texture size\n this.gl.bindTexture(this.gl.TEXTURE_2D, this.framebufferTexture);\n this.gl.texImage2D(\n this.gl.TEXTURE_2D,\n 0,\n this.gl.RGBA,\n this.framebufferWidth,\n this.framebufferHeight,\n 0,\n this.gl.RGBA,\n this.gl.UNSIGNED_BYTE,\n null\n );\n\n // Bind framebuffer before attaching texture\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffer);\n\n // Attach texture to framebuffer\n this.gl.framebufferTexture2D(\n this.gl.FRAMEBUFFER,\n this.gl.COLOR_ATTACHMENT0,\n this.gl.TEXTURE_2D,\n this.framebufferTexture,\n 0\n );\n\n // Check framebuffer status\n const status = this.gl.checkFramebufferStatus(this.gl.FRAMEBUFFER);\n if (status !== this.gl.FRAMEBUFFER_COMPLETE) {\n console.error('Framebuffer is not complete:', status);\n }\n };\n\n private render = (currentTime: number) => {\n if (this.hasBeenDisposed) return;\n\n if (this.program === null || this.framebufferSamplingProgram === null) {\n console.warn('Tried to render before program or framebuffer or gl was initialized');\n return;\n }\n\n // Calculate the delta time\n const dt = currentTime - this.lastRenderTime;\n this.lastRenderTime = currentTime;\n // Increase the total animation time by dt * animationSpeed\n if (this.speed !== 0) {\n this.totalFrameTime += dt * this.speed;\n }\n\n // Calculate target framebuffer dimensions\n const targetFramebufferWidth = Math.round(this.parentWidth * this.renderScale);\n const targetFramebufferHeight = Math.round(this.parentHeight * this.renderScale);\n\n // Ensure framebuffer is large enough for current render\n this.ensureSceneTarget(targetFramebufferWidth, targetFramebufferHeight);\n\n // Unbind all textures before rendering to framebuffer to prevent feedback loops\n for (let i = 0; i < this.textures.size; i++) {\n this.gl.activeTexture(this.gl.TEXTURE0 + i);\n this.gl.bindTexture(this.gl.TEXTURE_2D, null);\n }\n\n // Render to framebuffer\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, this.framebuffer);\n this.gl.viewport(0, 0, targetFramebufferWidth, targetFramebufferHeight);\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.totalFrameTime * 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!, targetFramebufferWidth, targetFramebufferHeight);\n this.gl.uniform1f(this.uniformLocations.u_pixelRatio!, this.renderScale);\n this.resolutionChanged = false;\n }\n\n // Rebind textures for the shader and set their uniforms\n let textureUnit = 0;\n this.textures.forEach((texture, uniformName) => {\n const location = this.uniformLocations[uniformName];\n if (location) {\n this.gl.activeTexture(this.gl.TEXTURE0 + textureUnit);\n this.gl.bindTexture(this.gl.TEXTURE_2D, texture);\n this.gl.uniform1i(location, textureUnit);\n textureUnit++;\n }\n });\n\n this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);\n\n // Render framebuffer to canvas\n this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null);\n // console.log('render', this.gl.canvas.width, this.gl.canvas.height);\n this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);\n this.gl.clear(this.gl.COLOR_BUFFER_BIT);\n\n this.gl.useProgram(this.framebufferSamplingProgram);\n this.gl.activeTexture(this.gl.TEXTURE0);\n this.gl.bindTexture(this.gl.TEXTURE_2D, this.framebufferTexture);\n this.gl.uniform1i(this.framebufferSamplingUniformLocations.u_texture!, 0);\n this.gl.uniform2f(\n this.framebufferSamplingUniformLocations.u_textureSize!,\n this.framebufferWidth,\n this.framebufferHeight\n );\n this.gl.uniform2f(\n this.framebufferSamplingUniformLocations.u_targetSize!,\n targetFramebufferWidth,\n targetFramebufferHeight\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 /** Creates a texture from an image and sets it into a uniform value */\n private setTextureUniform = (uniformName: string, image: HTMLImageElement): void => {\n if (!image.complete || image.naturalWidth === 0) {\n throw new Error(`Paper Shaders: image for uniform ${uniformName} must be fully loaded`);\n }\n\n // Clean up existing texture if present\n const existingTexture = this.textures.get(uniformName);\n if (existingTexture) {\n this.gl.deleteTexture(existingTexture);\n }\n\n // Create and set up the new texture\n const texture = this.gl.createTexture();\n this.gl.bindTexture(this.gl.TEXTURE_2D, texture);\n\n // Set texture parameters\n this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.REPEAT);\n this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.REPEAT);\n this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);\n this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);\n\n // Upload image to texture\n this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, this.gl.RGBA, this.gl.UNSIGNED_BYTE, image);\n const error = this.gl.getError();\n if (error !== this.gl.NO_ERROR || texture === null) {\n console.error('Paper Shaders: WebGL error when uploading texture:', error);\n return;\n }\n\n // Store the texture\n this.textures.set(uniformName, texture);\n\n // Set up texture unit and uniform\n const location = this.uniformLocations[uniformName];\n if (location) {\n // Use texture unit based on the order textures were added\n const textureUnit = this.textures.size - 1;\n this.gl.useProgram(this.program);\n this.gl.activeTexture(this.gl.TEXTURE0 + textureUnit);\n this.gl.bindTexture(this.gl.TEXTURE_2D, texture);\n this.gl.uniform1i(location, textureUnit);\n\n // Calculate and set the aspect ratio uniform\n const aspectRatioUniformName = `${uniformName}_aspect_ratio`;\n const aspectRatioLocation = this.uniformLocations[aspectRatioUniformName];\n if (aspectRatioLocation) {\n const aspectRatio = image.naturalWidth / image.naturalHeight;\n this.gl.uniform1f(aspectRatioLocation, aspectRatio);\n }\n }\n };\n\n /** Sets the provided uniform values into the WebGL program, can be a partial list of uniforms that have changed */\n private setUniformValues = (updatedUniforms: ShaderMountUniforms) => {\n this.gl.useProgram(this.program);\n Object.entries(updatedUniforms).forEach(([key, value]) => {\n const location = this.uniformLocations[key];\n if (!location) {\n console.warn(`Uniform location for ${key} not found`);\n return;\n }\n\n if (value instanceof HTMLImageElement) {\n // Texture case, requires a good amount of code so it gets its own function:\n this.setTextureUniform(key, value);\n } else if (Array.isArray(value)) {\n // Array case\n let flatArray: number[] | null = null;\n let valueLength: number | null = null;\n\n // If it's an array of same-sized arrays, flatten it down so we can set the uniform\n if (value[0] !== undefined && Array.isArray(value[0])) {\n const firstChildLength = value[0].length;\n if (value.every((arr) => (arr as number[]).length === firstChildLength)) {\n // Array of same-sized arrays case, flattens the array sets it\n flatArray = value.flat();\n valueLength = firstChildLength;\n } else {\n console.warn(`All child arrays must be the same length for ${key}`);\n return;\n }\n } else {\n // Array of primitive values case, supports 2, 3, 4, 9, 16 length arrays\n flatArray = value as number[];\n valueLength = flatArray.length;\n }\n\n // Set the uniform based on array length... supports 2, 3, 4, 9, 16 length arrays of primitive values\n // or arbitrary length arrays of arrays\n switch (valueLength) {\n case 2:\n this.gl.uniform2fv(location, flatArray);\n break;\n case 3:\n this.gl.uniform3fv(location, flatArray);\n break;\n case 4:\n this.gl.uniform4fv(location, flatArray);\n break;\n case 9:\n this.gl.uniformMatrix3fv(location, false, flatArray);\n break;\n case 16:\n this.gl.uniformMatrix4fv(location, false, flatArray);\n break;\n default:\n console.warn(`Unsupported uniform array length: ${valueLength}`);\n }\n } else if (typeof value === 'number') {\n // Number case, supports floats and ints\n this.gl.uniform1f(location, value);\n } else if (typeof value === 'boolean') {\n // Boolean case, supports true and false\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 /** Gets the current total animation time from 0ms */\n public getCurrentFrameTime = (): number => {\n return this.totalFrameTime;\n };\n\n /** Set a frame to get a deterministic result, frames are literally just milliseconds from zero since the animation started */\n public setFrame = (newFrame: number): void => {\n this.totalFrameTime = newFrame;\n this.lastRenderTime = 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.lastRenderTime = 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 /** Set the maximum pixel count for the shader, this will limit the number of pixels that will be rendered */\n public setMaxPixelCount = (newMaxPixelCount: number = DEFAULT_MAX_PIXEL_COUNT): void => {\n this.maxPixelCount = newMaxPixelCount;\n\n this.handleResolutionChange();\n };\n\n /** Set the minimum pixel ratio for the shader */\n public setMinPixelRatio = (newMinPixelRatio: number = 2): void => {\n this.minPixelRatio = newMinPixelRatio;\n\n this.handleResolutionChange();\n };\n\n /** Update the uniforms that are provided by the outside shader, can be a partial set with only the uniforms that have changed */\n public setUniforms = (newUniforms: ShaderMountUniforms): 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.setUniformValues(newUniforms);\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) {\n // Clean up all textures\n this.textures.forEach((texture) => {\n this.gl.deleteTexture(texture);\n });\n this.textures.clear();\n\n // Clean up framebuffer resources\n if (this.framebuffer) {\n this.gl.deleteFramebuffer(this.framebuffer);\n this.framebuffer = null;\n }\n\n if (this.framebufferTexture) {\n this.gl.deleteTexture(this.framebufferTexture);\n this.framebufferTexture = null;\n }\n\n if (this.framebufferSamplingProgram) {\n this.gl.deleteProgram(this.framebufferSamplingProgram);\n this.framebufferSamplingProgram = null;\n }\n\n if (this.program) {\n this.gl.deleteProgram(this.program);\n this.program = null;\n }\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 visualViewport?.removeEventListener('resize', this.handleVisualViewportChange);\n\n this.uniformLocations = {};\n this.framebufferSamplingUniformLocations = {};\n\n // Remove the shader mount from the div wrapper element to avoid any GC issues\n this.parentElement.paperShaderMount = undefined;\n };\n}\n\n/** Vertex shader for the shader mount */\nconst vertexShaderSource = `#version 300 es\nprecision mediump float;\n\nlayout(location = 0) in vec4 a_position;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\n\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\n\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;\n\nuniform float u_pxSize;\n\nout vec2 v_objectUV;\nout vec2 v_objectBoxSize;\nout vec2 v_objectHelperBox;\n\nout vec2 v_responsiveUV;\nout vec2 v_responsiveBoxSize;\nout vec2 v_responsiveHelperBox;\nout vec2 v_responsiveBoxGivenSize;\n\nout vec2 v_patternUV;\nout vec2 v_patternBoxSize;\nout vec2 v_patternHelperBox;\n\n// #define ADD_HELPERS\n\nvec3 getBoxSize(float boxRatio, vec2 givenBoxSize, vec2 maxBoxSize) {\n vec2 box = vec2(0.);\n // fit = none\n box.x = boxRatio * min(givenBoxSize.x / boxRatio, givenBoxSize.y);\n float noFitBoxWidth = box.x;\n if (u_fit == 1.) { // fit = contain\n box.x = boxRatio * min(maxBoxSize[0] / boxRatio, maxBoxSize[1]);\n } else if (u_fit == 2.) { // fit = cover\n box.x = boxRatio * max(maxBoxSize[0] / boxRatio, maxBoxSize[1]);\n }\n box.y = box.x / boxRatio;\n return vec3(box, noFitBoxWidth);\n}\n\nvoid main() {\n gl_Position = a_position;\n\n vec2 uv = gl_Position.xy * .5;\n vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);\n vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);\n givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;\n vec2 maxBoxSize = vec2(max(u_resolution.x, givenBoxSize.x), max(u_resolution.y, givenBoxSize.y));\n float r = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n\n\n // ===================================================\n // Sizing api for graphic objects with fixed ratio\n // (currently supports only ratio = 1)\n\n float fixedRatio = 1.;\n vec2 fixedRatioBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n\n v_objectBoxSize = getBoxSize(fixedRatio, fixedRatioBoxGivenSize, maxBoxSize).xy;\n vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;\n\n #ifdef ADD_HELPERS\n v_objectHelperBox = uv;\n v_objectHelperBox *= objectWorldScale;\n v_objectHelperBox += boxOrigin * (objectWorldScale - 1.);\n #endif\n\n v_objectUV = uv;\n v_objectUV *= objectWorldScale;\n v_objectUV += boxOrigin * (objectWorldScale - 1.);\n v_objectUV += graphicOffset;\n v_objectUV /= u_scale;\n v_objectUV = graphicRotation * v_objectUV;\n\n\n // ===================================================\n\n\n // ===================================================\n // Sizing api for graphic objects with either givenBoxSize ratio or canvas ratio.\n // Full-screen mode available with u_worldWidth = u_worldHeight = 0\n\n v_responsiveBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n float responsiveRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;\n v_responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize, maxBoxSize).xy;\n vec2 responsiveBoxScale = u_resolution.xy / v_responsiveBoxSize;\n\n #ifdef ADD_HELPERS\n v_responsiveHelperBox = uv;\n v_responsiveHelperBox *= responsiveBoxScale;\n v_responsiveHelperBox += boxOrigin * (responsiveBoxScale - 1.);\n #endif\n\n v_responsiveUV = uv;\n v_responsiveUV *= responsiveBoxScale;\n v_responsiveUV += boxOrigin * (responsiveBoxScale - 1.);\n v_responsiveUV += graphicOffset;\n v_responsiveUV /= u_scale;\n v_responsiveUV.x *= responsiveRatio;\n v_responsiveUV = graphicRotation * v_responsiveUV;\n v_responsiveUV.x /= responsiveRatio;\n\n // ===================================================\n\n\n // ===================================================\n // Sizing api for patterns\n // (treating graphics as a image u_worldWidth x u_worldHeight size)\n\n float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;\n vec2 patternBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y;\n\n vec3 boxSizeData = getBoxSize(patternBoxRatio, patternBoxGivenSize, maxBoxSize);\n v_patternBoxSize = boxSizeData.xy;\n float patternBoxNoFitBoxWidth = boxSizeData.z;\n vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;\n\n #ifdef ADD_HELPERS\n v_patternHelperBox = uv;\n v_patternHelperBox *= patternBoxScale;\n v_patternHelperBox += boxOrigin * (patternBoxScale - 1.);\n #endif\n\n v_patternUV = uv;\n v_patternUV += graphicOffset / patternBoxScale;\n v_patternUV += boxOrigin;\n v_patternUV -= boxOrigin / patternBoxScale;\n v_patternUV *= u_resolution.xy;\n v_patternUV /= u_pixelRatio;\n if (u_fit > 0.) {\n v_patternUV *= (patternBoxNoFitBoxWidth / v_patternBoxSize.x);\n }\n v_patternUV /= u_scale;\n v_patternUV = graphicRotation * v_patternUV;\n v_patternUV += boxOrigin / patternBoxScale;\n v_patternUV -= boxOrigin;\n v_patternUV += .5;\n\n // ===================================================\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\nconst defaultStyle = `@layer paper-shaders {\n :where([data-paper-shaders]) {\n isolation: isolate;\n position: relative;\n\n & canvas {\n contain: strict;\n display: block;\n position: absolute;\n inset: 0;\n z-index: -1;\n width: 100%;\n height: 100%;\n border-radius: inherit;\n }\n }\n}`;\n\n/** A canvas element that has a ShaderMount available on it */\nexport interface PaperShaderElement extends HTMLElement {\n paperShaderMount: ShaderMount | undefined;\n}\n\n/** Check if a canvas element is a ShaderCanvas */\nexport function isPaperShaderElement(element: HTMLElement): element is PaperShaderElement {\n return 'paperShaderMount' in element;\n}\n\n/** Uniform types that we support to be auto-mapped into the fragment shader */\nexport interface ShaderMountUniforms {\n [key: string]: boolean | number | number[] | number[][] | HTMLImageElement;\n}\n\nexport interface ShaderMotionParams {\n speed?: number;\n frame?: number;\n}\n\nexport type ShaderPreset<T> = {\n name: string;\n params: Required<T>;\n};\n\nfunction isSafari() {\n const ua = navigator.userAgent.toLowerCase();\n return ua.includes('safari') && !ua.includes('chrome') && !ua.includes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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBd,SAAS,qBAAqB,SAAqD;AACxF,SAAO,sBAAsB;AAC/B;AAiBA,SAAS,WAAW;AAClB,QAAM,KAAK,UAAU,UAAU,YAAY;AAC3C,SAAO,GAAG,SAAS,QAAQ,KAAK,CAAC,GAAG,SAAS,QAAQ,KAAK,CAAC,GAAG,SAAS,SAAS;AAClF;",
6
- "names": ["vertexShaderSource"]
7
- }
@@ -1,193 +0,0 @@
1
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
- * Paper Shaders *
3
- * https://github.com/paper-design/shaders *
4
- * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
-
6
- const sizingVariablesDeclaration = `
7
- in vec2 v_objectUV;
8
- in vec2 v_responsiveUV;
9
- in vec2 v_responsiveBoxGivenSize;
10
- in vec2 v_patternUV;`;
11
- const sizingDebugVariablesDeclaration = `
12
- in vec2 v_objectBoxSize;
13
- in vec2 v_objectHelperBox;
14
- in vec2 v_responsiveBoxSize;
15
- in vec2 v_responsiveHelperBox;
16
- in vec2 v_patternBoxSize;
17
- in vec2 v_patternHelperBox;`;
18
- const sizingUniformsDeclaration = `
19
- uniform float u_originX;
20
- uniform float u_originY;
21
- uniform float u_worldWidth;
22
- uniform float u_worldHeight;
23
- uniform float u_fit;
24
-
25
- uniform float u_scale;
26
- uniform float u_rotation;
27
- uniform float u_offsetX;
28
- uniform float u_offsetY;`;
29
- const sizingUV = `
30
-
31
- vec2 uv = gl_FragCoord.xy / u_resolution.xy;
32
- #ifdef USE_PIXELIZATION
33
- float pxSize = u_pxSize * u_pixelRatio;
34
- vec2 pxSizeUv = gl_FragCoord.xy;
35
- pxSizeUv -= .5 * u_resolution;
36
- pxSizeUv /= pxSize;
37
- uv = floor(pxSizeUv) * pxSize / u_resolution.xy;
38
- uv += .5;
39
- #endif
40
- uv -= .5;
41
-
42
-
43
- // ===================================================
44
- // sizing params shared between objects and patterns
45
-
46
- vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);
47
- vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);
48
- givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;
49
- vec2 maxBoxSize = vec2(max(u_resolution.x, givenBoxSize.x), max(u_resolution.y, givenBoxSize.y));
50
- float r = u_rotation * 3.14159265358979323846 / 180.;
51
- mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));
52
- vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
53
-
54
-
55
- // ===================================================
56
- // Sizing api for objects (graphics with fixed ratio)
57
-
58
- #ifdef USE_OBJECT_SIZING
59
- float fixedRatio = 1.;
60
- vec2 fixedRatioBoxGivenSize = vec2(
61
- (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
62
- (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
63
- );
64
- vec2 objectBoxSize = vec2(0.);
65
- // fit = none
66
- objectBoxSize.x = fixedRatio * min(fixedRatioBoxGivenSize.x / fixedRatio, fixedRatioBoxGivenSize.y);
67
- if (u_fit == 1.) { // fit = contain
68
- objectBoxSize.x = fixedRatio * min(maxBoxSize.x / fixedRatio, maxBoxSize.y);
69
- } else if (u_fit == 2.) { // fit = cover
70
- objectBoxSize.x = fixedRatio * max(maxBoxSize.x / fixedRatio, maxBoxSize.y);
71
- }
72
- objectBoxSize.y = objectBoxSize.x / fixedRatio;
73
- vec2 objectWorldScale = u_resolution.xy / objectBoxSize;
74
-
75
- #ifdef ADD_HELPERS
76
- vec2 objectHelperBox = gl_FragCoord.xy / u_resolution.xy;
77
- objectHelperBox -= .5;
78
- objectHelperBox *= objectWorldScale;
79
- objectHelperBox += boxOrigin * (objectWorldScale - 1.);
80
- #endif
81
-
82
- vec2 objectUV = uv;
83
- objectUV *= objectWorldScale;
84
- objectUV += boxOrigin * (objectWorldScale - 1.);
85
- objectUV += vec2(-u_offsetX, u_offsetY);
86
- objectUV /= u_scale;
87
- objectUV = graphicRotation * objectUV;
88
- #endif
89
-
90
- // ===================================================
91
-
92
- // ===================================================
93
- // Sizing api for patterns (graphics respecting u_worldWidth / u_worldHeight ratio)
94
-
95
- #ifdef USE_PATTERN_SIZING
96
- float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;
97
- vec2 patternBoxGivenSize = vec2(
98
- (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
99
- (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
100
- );
101
- vec2 patternBoxSize = vec2(0.);
102
- // fit = none
103
- patternBoxSize.x = patternBoxRatio * min(patternBoxGivenSize.x / patternBoxRatio, patternBoxGivenSize.y);
104
- float patternWorldNoFitBoxWidth = patternBoxSize.x;
105
- if (u_fit == 1.) { // fit = contain
106
- patternBoxSize.x = patternBoxRatio * min(maxBoxSize.x / patternBoxRatio, maxBoxSize.y);
107
- } else if (u_fit == 2.) { // fit = cover
108
- patternBoxSize.x = patternBoxRatio * max(maxBoxSize.x / patternBoxRatio, maxBoxSize.y);
109
- }
110
- patternBoxSize.y = patternBoxSize.x / patternBoxRatio;
111
- vec2 patternWorldScale = u_resolution.xy / patternBoxSize;
112
-
113
- #ifdef ADD_HELPERS
114
- vec2 patternHelperBox = gl_FragCoord.xy / u_resolution.xy;
115
- patternHelperBox -= .5;
116
- patternHelperBox *= patternWorldScale;
117
- patternHelperBox += boxOrigin * (patternWorldScale - 1.);
118
- #endif
119
-
120
- vec2 patternUV = uv;
121
- patternUV += vec2(-u_offsetX, u_offsetY) / patternWorldScale;
122
- patternUV += boxOrigin;
123
- patternUV -= boxOrigin / patternWorldScale;
124
- patternUV *= u_resolution.xy;
125
- patternUV /= u_pixelRatio;
126
- if (u_fit > 0.) {
127
- patternUV *= (patternWorldNoFitBoxWidth / patternBoxSize.x);
128
- }
129
- patternUV /= u_scale;
130
- patternUV = graphicRotation * patternUV;
131
- patternUV += boxOrigin / patternWorldScale;
132
- patternUV -= boxOrigin;
133
- patternUV += .5;
134
- #endif
135
- `;
136
- const drawSizingHelpers = `
137
- vec2 worldBoxDist = abs(helperBox);
138
- float boxStroke = (step(max(worldBoxDist.x, worldBoxDist.y), .5) - step(max(worldBoxDist.x, worldBoxDist.y), .495));
139
- color.rgb = mix(color.rgb, vec3(1., 0., 0.), boxStroke);
140
- opacity += boxStroke;
141
-
142
- vec2 boxOriginCopy = vec2(.5 - u_originX, u_originY - .5);
143
- vec2 boxOriginDist = helperBox + boxOriginCopy;
144
- boxOriginDist.x *= (boxSize.x / boxSize.y);
145
- float boxOriginPoint = 1. - smoothstep(0., .05, length(boxOriginDist));
146
-
147
- vec2 graphicOriginPointDist = helperBox + vec2(-u_offsetX, u_offsetY);
148
- graphicOriginPointDist.x *= (boxSize.x / boxSize.y);
149
- float graphicOriginPoint = 1. - smoothstep(0., .05, length(graphicOriginPointDist));
150
-
151
- color.rgb = mix(color.rgb, vec3(0., 1., 0.), boxOriginPoint);
152
- opacity += boxOriginPoint;
153
- color.rgb = mix(color.rgb, vec3(0., 0., 1.), graphicOriginPoint);
154
- opacity += graphicOriginPoint;
155
- `;
156
- const defaultObjectSizing = {
157
- fit: "contain",
158
- scale: 1,
159
- rotation: 0,
160
- offsetX: 0,
161
- offsetY: 0,
162
- originX: 0.5,
163
- originY: 0.5,
164
- worldWidth: 0,
165
- worldHeight: 0
166
- };
167
- const defaultPatternSizing = {
168
- fit: "none",
169
- scale: 1,
170
- rotation: 0,
171
- offsetX: 0,
172
- offsetY: 0,
173
- originX: 0.5,
174
- originY: 0.5,
175
- worldWidth: 0,
176
- worldHeight: 0
177
- };
178
- const ShaderFitOptions = {
179
- none: 0,
180
- contain: 1,
181
- cover: 2
182
- };
183
- export {
184
- ShaderFitOptions,
185
- defaultObjectSizing,
186
- defaultPatternSizing,
187
- drawSizingHelpers,
188
- sizingDebugVariablesDeclaration,
189
- sizingUV,
190
- sizingUniformsDeclaration,
191
- sizingVariablesDeclaration
192
- };
193
- //# sourceMappingURL=shader-sizing.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/shader-sizing.ts"],
4
- "sourcesContent": ["/*\n ===================================================================\n The space coordinates passed from the vertex shader.\n\n `sizingVariablesDeclaration` must be included in every fragment\n shader\u2014unless we want to apply sizing to the coordinates directly\n in the fragment shader.\n\n So far, the only exception is when we need to apply pixelization\n before sizing (e.g., to make dithering pixels independent of sizing).\n*/\nexport const sizingVariablesDeclaration = `\nin vec2 v_objectUV;\nin vec2 v_responsiveUV;\nin vec2 v_responsiveBoxGivenSize;\nin vec2 v_patternUV;`;\n\n/*\n ===================================================================\n Additional variables used only for drawing a sizing overlay.\n*/\nexport const sizingDebugVariablesDeclaration = `\nin vec2 v_objectBoxSize;\nin vec2 v_objectHelperBox;\nin vec2 v_responsiveBoxSize;\nin vec2 v_responsiveHelperBox;\nin vec2 v_patternBoxSize;\nin vec2 v_patternHelperBox;`;\n\n/*\n ===================================================================\n In most cases, sizing UNIFORMS are used only in the vertex shader.\n But there are cases where we need to pass them to the fragment shader\n as well:\n - dithering pixelization where all the sizing happens in fragment\n - drawing the sizing helpers\n*/\nexport const sizingUniformsDeclaration = `\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\n\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;`;\n\n/*\n ===================================================================\n In most cases, sizing TRANSFORMS are applied in the vertex shader.\n For exceptions (e.g., dithering pixelization), the operations below\n need to be included in the fragment shader instead.\n\n Currently, only `objectUV` and `patternUV` are supported.\n The transforms are identical to those in the vertex shader,\n except for the `USE_PIXELIZATION` part.\n*/\nexport const sizingUV = `\n\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n #ifdef USE_PIXELIZATION\n float pxSize = u_pxSize * u_pixelRatio;\n vec2 pxSizeUv = gl_FragCoord.xy;\n pxSizeUv -= .5 * u_resolution;\n pxSizeUv /= pxSize;\n uv = floor(pxSizeUv) * pxSize / u_resolution.xy; \n uv += .5;\n #endif\n uv -= .5;\n\n \n // ===================================================\n // sizing params shared between objects and patterns\n \n vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);\n vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);\n givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;\n vec2 maxBoxSize = vec2(max(u_resolution.x, givenBoxSize.x), max(u_resolution.y, givenBoxSize.y));\n float r = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n\n \n // ===================================================\n // Sizing api for objects (graphics with fixed ratio)\n\n #ifdef USE_OBJECT_SIZING\n float fixedRatio = 1.;\n vec2 fixedRatioBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n vec2 objectBoxSize = vec2(0.);\n // fit = none\n objectBoxSize.x = fixedRatio * min(fixedRatioBoxGivenSize.x / fixedRatio, fixedRatioBoxGivenSize.y);\n if (u_fit == 1.) { // fit = contain\n objectBoxSize.x = fixedRatio * min(maxBoxSize.x / fixedRatio, maxBoxSize.y);\n } else if (u_fit == 2.) { // fit = cover\n objectBoxSize.x = fixedRatio * max(maxBoxSize.x / fixedRatio, maxBoxSize.y);\n }\n objectBoxSize.y = objectBoxSize.x / fixedRatio;\n vec2 objectWorldScale = u_resolution.xy / objectBoxSize;\n \n #ifdef ADD_HELPERS\n vec2 objectHelperBox = gl_FragCoord.xy / u_resolution.xy;\n objectHelperBox -= .5;\n objectHelperBox *= objectWorldScale;\n objectHelperBox += boxOrigin * (objectWorldScale - 1.); \n #endif\n \n vec2 objectUV = uv;\n objectUV *= objectWorldScale;\n objectUV += boxOrigin * (objectWorldScale - 1.);\n objectUV += vec2(-u_offsetX, u_offsetY);\n objectUV /= u_scale;\n objectUV = graphicRotation * objectUV;\n #endif\n \n // ===================================================\n \n // ===================================================\n // Sizing api for patterns (graphics respecting u_worldWidth / u_worldHeight ratio)\n \n #ifdef USE_PATTERN_SIZING\n float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;\n vec2 patternBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n vec2 patternBoxSize = vec2(0.);\n // fit = none\n patternBoxSize.x = patternBoxRatio * min(patternBoxGivenSize.x / patternBoxRatio, patternBoxGivenSize.y);\n float patternWorldNoFitBoxWidth = patternBoxSize.x;\n if (u_fit == 1.) { // fit = contain\n patternBoxSize.x = patternBoxRatio * min(maxBoxSize.x / patternBoxRatio, maxBoxSize.y);\n } else if (u_fit == 2.) { // fit = cover\n patternBoxSize.x = patternBoxRatio * max(maxBoxSize.x / patternBoxRatio, maxBoxSize.y);\n }\n patternBoxSize.y = patternBoxSize.x / patternBoxRatio;\n vec2 patternWorldScale = u_resolution.xy / patternBoxSize;\n \n #ifdef ADD_HELPERS \n vec2 patternHelperBox = gl_FragCoord.xy / u_resolution.xy;\n patternHelperBox -= .5;\n patternHelperBox *= patternWorldScale;\n patternHelperBox += boxOrigin * (patternWorldScale - 1.); \n #endif\n \n vec2 patternUV = uv;\n patternUV += vec2(-u_offsetX, u_offsetY) / patternWorldScale;\n patternUV += boxOrigin;\n patternUV -= boxOrigin / patternWorldScale;\n patternUV *= u_resolution.xy;\n patternUV /= u_pixelRatio;\n if (u_fit > 0.) {\n patternUV *= (patternWorldNoFitBoxWidth / patternBoxSize.x);\n }\n patternUV /= u_scale;\n patternUV = graphicRotation * patternUV;\n patternUV += boxOrigin / patternWorldScale;\n patternUV -= boxOrigin;\n patternUV += .5;\n #endif\n`;\n\n/*\n ===================================================================\n Helpers used to draw the sizing (box, box origin and graphic origin)\n over the shader. Can be used with both vertex sizing and vector sizing\n\n helperBox and boxSize should be defined before inserting the code\n*/\nexport const drawSizingHelpers = `\n vec2 worldBoxDist = abs(helperBox);\n float boxStroke = (step(max(worldBoxDist.x, worldBoxDist.y), .5) - step(max(worldBoxDist.x, worldBoxDist.y), .495));\n color.rgb = mix(color.rgb, vec3(1., 0., 0.), boxStroke);\n opacity += boxStroke;\n\n vec2 boxOriginCopy = vec2(.5 - u_originX, u_originY - .5);\n vec2 boxOriginDist = helperBox + boxOriginCopy;\n boxOriginDist.x *= (boxSize.x / boxSize.y);\n float boxOriginPoint = 1. - smoothstep(0., .05, length(boxOriginDist));\n \n vec2 graphicOriginPointDist = helperBox + vec2(-u_offsetX, u_offsetY);\n graphicOriginPointDist.x *= (boxSize.x / boxSize.y);\n float graphicOriginPoint = 1. - smoothstep(0., .05, length(graphicOriginPointDist));\n \n color.rgb = mix(color.rgb, vec3(0., 1., 0.), boxOriginPoint);\n opacity += boxOriginPoint;\n color.rgb = mix(color.rgb, vec3(0., 0., 1.), graphicOriginPoint);\n opacity += graphicOriginPoint;\n`;\n\nexport interface ShaderSizingUniforms {\n u_fit: (typeof ShaderFitOptions)[ShaderFit];\n u_scale: number;\n u_rotation: number;\n u_originX: number;\n u_originY: number;\n u_offsetX: number;\n u_offsetY: number;\n u_worldWidth: number;\n u_worldHeight: number;\n}\n\nexport interface ShaderSizingParams {\n fit?: 'none' | 'contain' | 'cover';\n scale?: number;\n rotation?: number;\n originX?: number;\n originY?: number;\n offsetX?: number;\n offsetY?: number;\n worldWidth?: number;\n worldHeight?: number;\n}\n\nexport const defaultObjectSizing: Required<ShaderSizingParams> = {\n fit: 'contain',\n scale: 1,\n rotation: 0,\n offsetX: 0,\n offsetY: 0,\n originX: 0.5,\n originY: 0.5,\n worldWidth: 0,\n worldHeight: 0,\n};\n\nexport const defaultPatternSizing: Required<ShaderSizingParams> = {\n fit: 'none',\n scale: 1,\n rotation: 0,\n offsetX: 0,\n offsetY: 0,\n originX: 0.5,\n originY: 0.5,\n worldWidth: 0,\n worldHeight: 0,\n};\n\nexport const ShaderFitOptions = {\n none: 0,\n contain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,aAAa;AACf;AAEO,MAAM,uBAAqD;AAAA,EAChE,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,aAAa;AACf;AAEO,MAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT;",
6
- "names": []
7
- }
@@ -1,59 +0,0 @@
1
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
- * Paper Shaders *
3
- * https://github.com/paper-design/shaders *
4
- * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
-
6
- const declarePI = `
7
- #define TWO_PI 6.28318530718
8
- #define PI 3.14159265358979323846
9
- `;
10
- const declareRotate = `
11
- vec2 rotate(vec2 uv, float th) {
12
- return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;
13
- }
14
- `;
15
- const declareRandom = `
16
- float random(vec2 st) {
17
- return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);
18
- }
19
- `;
20
- const colorBandingFix = `
21
- color += 1. / 256. * (fract(sin(dot(.014 * gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453123) - .5);
22
- `;
23
- const declareSimplexNoise = `
24
- vec3 permute(vec3 x) { return mod(((x * 34.0) + 1.0) * x, 289.0); }
25
- float snoise(vec2 v) {
26
- const vec4 C = vec4(0.211324865405187, 0.366025403784439,
27
- -0.577350269189626, 0.024390243902439);
28
- vec2 i = floor(v + dot(v, C.yy));
29
- vec2 x0 = v - i + dot(i, C.xx);
30
- vec2 i1;
31
- i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
32
- vec4 x12 = x0.xyxy + C.xxzz;
33
- x12.xy -= i1;
34
- i = mod(i, 289.0);
35
- vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))
36
- + i.x + vec3(0.0, i1.x, 1.0));
37
- vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),
38
- dot(x12.zw, x12.zw)), 0.0);
39
- m = m * m;
40
- m = m * m;
41
- vec3 x = 2.0 * fract(p * C.www) - 1.0;
42
- vec3 h = abs(x) - 0.5;
43
- vec3 ox = floor(x + 0.5);
44
- vec3 a0 = x - ox;
45
- m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
46
- vec3 g;
47
- g.x = a0.x * x0.x + h.x * x0.y;
48
- g.yz = a0.yz * x12.xz + h.yz * x12.yw;
49
- return 130.0 * dot(m, g);
50
- }
51
- `;
52
- export {
53
- colorBandingFix,
54
- declarePI,
55
- declareRandom,
56
- declareRotate,
57
- declareSimplexNoise
58
- };
59
- //# sourceMappingURL=shader-utils.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/shader-utils.ts"],
4
- "sourcesContent": ["export const declarePI = `\n#define TWO_PI 6.28318530718\n#define PI 3.14159265358979323846\n`;\n\nexport const declareRotate = `\nvec2 rotate(vec2 uv, float th) {\n return mat2(cos(th), sin(th), -sin(th), cos(th)) * uv;\n}\n`;\n\nexport const declareRandom = `\nfloat random(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n}\n`;\n\n// It does use the standard random function but we don't call it to keep\n// colorBandingFix insertion independent from declareRandom\nexport const colorBandingFix = `\n color += 1. / 256. * (fract(sin(dot(.014 * gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453123) - .5);\n`;\n\nexport const declareSimplexNoise = `\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`;\n"],
5
- "mappings": ";;;;;AAAO,MAAM,YAAY;AAAA;AAAA;AAAA;AAKlB,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAMtB,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAQtB,MAAM,kBAAkB;AAAA;AAAA;AAIxB,MAAM,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
6
- "names": []
7
- }
@@ -1,221 +0,0 @@
1
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
- * Paper Shaders *
3
- * https://github.com/paper-design/shaders *
4
- * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
-
6
- import {
7
- sizingUniformsDeclaration,
8
- sizingUV,
9
- drawSizingHelpers
10
- } from "../shader-sizing";
11
- import { declareSimplexNoise, declarePI, declareRandom } from "../shader-utils";
12
- const ditheringFragmentShader = `#version 300 es
13
- precision mediump float;
14
-
15
- uniform float u_time;
16
- uniform vec2 u_resolution;
17
- uniform float u_pixelRatio;
18
-
19
- ${sizingUniformsDeclaration}
20
-
21
- uniform vec4 u_colorBack;
22
- uniform vec4 u_colorFront;
23
- uniform float u_shape;
24
- uniform float u_type;
25
- uniform float u_pxSize;
26
-
27
- out vec4 fragColor;
28
-
29
- ${declareSimplexNoise}
30
- ${declarePI}
31
- ${declareRandom}
32
-
33
- float getSimplexNoise(vec2 uv, float t) {
34
- float noise = .5 * snoise(uv - vec2(0., .3 * t));
35
- noise += .5 * snoise(2. * uv + vec2(0., .32 * t));
36
-
37
- return noise;
38
- }
39
-
40
- const int bayer2x2[4] = int[4](0, 2, 3, 1);
41
- const int bayer4x4[16] = int[16](
42
- 0, 8, 2, 10,
43
- 12, 4, 14, 6,
44
- 3, 11, 1, 9,
45
- 15, 7, 13, 5
46
- );
47
-
48
- const int bayer8x8[64] = int[64](
49
- 0, 32, 8, 40, 2, 34, 10, 42,
50
- 48, 16, 56, 24, 50, 18, 58, 26,
51
- 12, 44, 4, 36, 14, 46, 6, 38,
52
- 60, 28, 52, 20, 62, 30, 54, 22,
53
- 3, 35, 11, 43, 1, 33, 9, 41,
54
- 51, 19, 59, 27, 49, 17, 57, 25,
55
- 15, 47, 7, 39, 13, 45, 5, 37,
56
- 63, 31, 55, 23, 61, 29, 53, 21
57
- );
58
-
59
- float getBayerValue(vec2 uv, int size) {
60
- ivec2 pos = ivec2(mod(uv, float(size)));
61
- int index = pos.y * size + pos.x;
62
-
63
- if (size == 2) {
64
- return float(bayer2x2[index]) / 4.0;
65
- } else if (size == 4) {
66
- return float(bayer4x4[index]) / 16.0;
67
- } else if (size == 8) {
68
- return float(bayer8x8[index]) / 64.0;
69
- }
70
- return 0.0;
71
- }
72
-
73
-
74
- void main() {
75
- float t = .5 * u_time;
76
-
77
- #define USE_PATTERN_SIZING
78
- #define USE_OBJECT_SIZING
79
- #define USE_PIXELIZATION
80
- // #define ADD_HELPERS
81
-
82
- ${sizingUV}
83
-
84
- vec2 dithering_uv = pxSizeUv;
85
- vec2 ditheringNoise_uv = uv;
86
- vec2 shape_uv = objectUV;
87
- if (u_shape < 3.5) {
88
- shape_uv = patternUV;
89
- }
90
-
91
- float shape = 0.;
92
- if (u_shape < 1.5) {
93
- // Simplex noise
94
- shape_uv *= .001;
95
-
96
- shape = 0.5 + 0.5 * getSimplexNoise(shape_uv, t);
97
- shape = smoothstep(0.3, 0.9, shape);
98
-
99
- } else if (u_shape < 2.5) {
100
- // Warp
101
- shape_uv *= .003;
102
-
103
- for (float i = 1.0; i < 6.0; i++) {
104
- shape_uv.x += 0.6 / i * cos(i * 2.5 * shape_uv.y + t);
105
- shape_uv.y += 0.6 / i * cos(i * 1.5 * shape_uv.x + t);
106
- }
107
-
108
- shape = .15 / abs(sin(t - shape_uv.y - shape_uv.x));
109
- shape = smoothstep(0.02, 1., shape);
110
-
111
- } else if (u_shape < 3.5) {
112
- // Dots
113
- shape_uv *= .05;
114
-
115
- float stripeIdx = floor(2. * shape_uv.x / TWO_PI);
116
- float rand = fract(sin(stripeIdx * 12.9898) * 43758.5453);
117
-
118
- float speed = sign(rand - .5) * ceil(2. + rand);
119
- shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);
120
- shape = pow(shape, 6.);
121
-
122
- } else if (u_shape < 4.5) {
123
- // Sine wave
124
- shape_uv *= 4.;
125
-
126
- float wave = cos(.5 * shape_uv.x - 2. * t) * sin(1.5 * shape_uv.x + t) * (.75 + .25 * cos(3. * t));
127
- shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);
128
-
129
- } else if (u_shape < 5.5) {
130
- // Ripple
131
-
132
- float dist = length(shape_uv);
133
- float waves = sin(pow(dist, 1.7) * 7. - 3. * t) * .5 + .5;
134
- shape = waves;
135
-
136
- } else if (u_shape < 6.5) {
137
- // Swirl
138
-
139
- float l = length(shape_uv);
140
- float angle = 6. * atan(shape_uv.y, shape_uv.x) + 4. * t;
141
- float twist = 1.2;
142
- float offset = pow(l, -twist) + angle / TWO_PI;
143
- float mid = smoothstep(0., 1., pow(l, twist));
144
- shape = mix(0., fract(offset), mid);
145
-
146
- } else {
147
- // Sphere
148
- shape_uv *= 2.;
149
-
150
- vec3 pos = vec3(shape_uv, sqrt(1. - pow(length(shape_uv), 2.)));
151
- vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));
152
- shape = .5 + .5 * dot(lightPos, pos);
153
- }
154
-
155
-
156
- int type = int(floor(u_type));
157
- float dithering = 0.0;
158
-
159
- switch (type) {
160
- case 1: {
161
- dithering = step(random(ditheringNoise_uv), shape);
162
- } break;
163
- case 2:
164
- dithering = getBayerValue(dithering_uv, 2);
165
- break;
166
- case 3:
167
- dithering = getBayerValue(dithering_uv, 4);
168
- break;
169
- default:
170
- dithering = getBayerValue(dithering_uv, 8);
171
- break;
172
- }
173
-
174
- dithering -= .5;
175
- float res = step(.5, shape + dithering);
176
-
177
- vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
178
- float fgOpacity = u_colorFront.a;
179
- vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
180
- float bgOpacity = u_colorBack.a;
181
-
182
- vec3 color = fgColor * res;
183
- float opacity = fgOpacity * res;
184
-
185
- color += bgColor * (1. - opacity);
186
- opacity += bgOpacity * (1. - opacity);
187
-
188
- #ifdef ADD_HELPERS
189
- vec2 helperBox = objectHelperBox;
190
- vec2 boxSize = objectBoxSize;
191
- if (u_shape < 3.5) {
192
- helperBox = patternHelperBox;
193
- boxSize = patternBoxSize;
194
- }
195
- ${drawSizingHelpers}
196
- #endif
197
-
198
- fragColor = vec4(color, opacity);
199
- }
200
- `;
201
- const DitheringShapes = {
202
- simplex: 1,
203
- warp: 2,
204
- dots: 3,
205
- wave: 4,
206
- ripple: 5,
207
- swirl: 6,
208
- sphere: 7
209
- };
210
- const DitheringTypes = {
211
- random: 1,
212
- "2x2": 2,
213
- "4x4": 3,
214
- "8x8": 4
215
- };
216
- export {
217
- DitheringShapes,
218
- DitheringTypes,
219
- ditheringFragmentShader
220
- };
221
- //# sourceMappingURL=dithering.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/shaders/dithering.ts"],
4
- "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount';\nimport {\n sizingUniformsDeclaration,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n sizingUV,\n drawSizingHelpers,\n} from '../shader-sizing';\nimport { declareSimplexNoise, declarePI, declareRandom } from '../shader-utils';\n\n/**\n * Dithering Fragment Shader by Ksenia Kondrashova\n * Applies dithering (4 dithering types available) over the\n * abstract shapes animation (7 animated shapes available)\n *\n * Uniforms include:\n * - u_colorBack: background color, RGBA\n * - u_colorFront: pixels color, RGBA\n *\n * - u_shape (float, used as int, 1 to 7):\n * --- shape = 1: Simplex noise pattern\n * --- shape = 2: Warp noise pattern\n * --- shape = 3: Columns if dots moving vertically\n * --- shape = 4: Sine wave\n * --- shape = 5: Ripple effect\n * --- shape = 6: Swirl animation\n * --- shape = 7: Rotating sphere\n *\n * - u_type (float, used as int, 1 to 4):\n * --- type = 1: Random dithering\n * --- type = 2: 2x2 Bayer matrix\n * --- type = 3: 4x4 Bayer matrix\n * --- type = 4: 8x8 Bayer matrix\n *\n * - pxSize (float), relative to canvas resolution\n *\n */\nexport const ditheringFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\n\n${sizingUniformsDeclaration}\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorFront;\nuniform float u_shape;\nuniform float u_type;\nuniform float u_pxSize;\n\nout vec4 fragColor;\n\n${declareSimplexNoise}\n${declarePI}\n${declareRandom}\n\nfloat getSimplexNoise(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\nconst int bayer2x2[4] = int[4](0, 2, 3, 1);\nconst int bayer4x4[16] = int[16](\n 0, 8, 2, 10,\n 12, 4, 14, 6,\n 3, 11, 1, 9,\n 15, 7, 13, 5\n);\n\nconst int bayer8x8[64] = int[64](\n 0, 32, 8, 40, 2, 34, 10, 42,\n 48, 16, 56, 24, 50, 18, 58, 26,\n 12, 44, 4, 36, 14, 46, 6, 38,\n 60, 28, 52, 20, 62, 30, 54, 22,\n 3, 35, 11, 43, 1, 33, 9, 41,\n 51, 19, 59, 27, 49, 17, 57, 25,\n 15, 47, 7, 39, 13, 45, 5, 37,\n 63, 31, 55, 23, 61, 29, 53, 21\n);\n\nfloat getBayerValue(vec2 uv, int size) {\n ivec2 pos = ivec2(mod(uv, float(size)));\n int index = pos.y * size + pos.x;\n\n if (size == 2) {\n return float(bayer2x2[index]) / 4.0;\n } else if (size == 4) {\n return float(bayer4x4[index]) / 16.0;\n } else if (size == 8) {\n return float(bayer8x8[index]) / 64.0;\n }\n return 0.0;\n}\n\n\nvoid main() {\n float t = .5 * u_time;\n\n #define USE_PATTERN_SIZING\n #define USE_OBJECT_SIZING\n #define USE_PIXELIZATION\n // #define ADD_HELPERS\n\n ${sizingUV}\n\n vec2 dithering_uv = pxSizeUv;\n vec2 ditheringNoise_uv = uv;\n vec2 shape_uv = objectUV;\n if (u_shape < 3.5) {\n shape_uv = patternUV;\n }\n\n float shape = 0.;\n if (u_shape < 1.5) {\n // Simplex noise\n shape_uv *= .001;\n\n shape = 0.5 + 0.5 * getSimplexNoise(shape_uv, t);\n shape = smoothstep(0.3, 0.9, shape);\n\n } else if (u_shape < 2.5) {\n // Warp\n shape_uv *= .003;\n\n for (float i = 1.0; i < 6.0; i++) {\n shape_uv.x += 0.6 / i * cos(i * 2.5 * shape_uv.y + t);\n shape_uv.y += 0.6 / i * cos(i * 1.5 * shape_uv.x + t);\n }\n\n shape = .15 / abs(sin(t - shape_uv.y - shape_uv.x));\n shape = smoothstep(0.02, 1., shape);\n\n } else if (u_shape < 3.5) {\n // Dots\n shape_uv *= .05;\n\n float stripeIdx = floor(2. * shape_uv.x / TWO_PI);\n float rand = fract(sin(stripeIdx * 12.9898) * 43758.5453);\n\n float speed = sign(rand - .5) * ceil(2. + rand);\n shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);\n shape = pow(shape, 6.);\n\n } else if (u_shape < 4.5) {\n // Sine wave\n shape_uv *= 4.;\n\n float wave = cos(.5 * shape_uv.x - 2. * t) * sin(1.5 * shape_uv.x + t) * (.75 + .25 * cos(3. * t));\n shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);\n\n } else if (u_shape < 5.5) {\n // Ripple\n\n float dist = length(shape_uv);\n float waves = sin(pow(dist, 1.7) * 7. - 3. * t) * .5 + .5;\n shape = waves;\n\n } else if (u_shape < 6.5) {\n // Swirl\n\n float l = length(shape_uv);\n float angle = 6. * atan(shape_uv.y, shape_uv.x) + 4. * t;\n float twist = 1.2;\n float offset = pow(l, -twist) + angle / TWO_PI;\n float mid = smoothstep(0., 1., pow(l, twist));\n shape = mix(0., fract(offset), mid);\n\n } else {\n // Sphere\n shape_uv *= 2.;\n\n vec3 pos = vec3(shape_uv, sqrt(1. - pow(length(shape_uv), 2.)));\n vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));\n shape = .5 + .5 * dot(lightPos, pos);\n }\n\n\n int type = int(floor(u_type));\n float dithering = 0.0;\n\n switch (type) {\n case 1: {\n dithering = step(random(ditheringNoise_uv), shape);\n } break;\n case 2:\n dithering = getBayerValue(dithering_uv, 2);\n break;\n case 3:\n dithering = getBayerValue(dithering_uv, 4);\n break;\n default:\n dithering = getBayerValue(dithering_uv, 8);\n break;\n }\n\n dithering -= .5;\n float res = step(.5, shape + dithering);\n\n vec3 fgColor = u_colorFront.rgb * u_colorFront.a;\n float fgOpacity = u_colorFront.a;\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n float bgOpacity = u_colorBack.a;\n\n vec3 color = fgColor * res;\n float opacity = fgOpacity * res;\n \n color += bgColor * (1. - opacity);\n opacity += bgOpacity * (1. - opacity);\n\n #ifdef ADD_HELPERS\n vec2 helperBox = objectHelperBox;\n vec2 boxSize = objectBoxSize;\n if (u_shape < 3.5) {\n helperBox = patternHelperBox;\n boxSize = patternBoxSize;\n }\n ${drawSizingHelpers}\n #endif\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface DitheringUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorFront: [number, number, number, number];\n u_shape: (typeof DitheringShapes)[DitheringShape];\n u_type: (typeof DitheringTypes)[DitheringType];\n u_pxSize: number;\n}\n\nexport interface DitheringParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colorFront?: string;\n shape?: DitheringShape;\n type?: DitheringType;\n pxSize?: number;\n}\n\nexport const DitheringShapes = {\n simplex: 1,\n warp: 2,\n dots: 3,\n wave: 4,\n ripple: 5,\n swirl: 6,\n sphere: 7,\n} as const;\n\nexport type DitheringShape = keyof typeof DitheringShapes;\n\nexport const DitheringTypes = {\n random: 1,\n '2x2': 2,\n '4x4': 3,\n '8x8': 4,\n} as const;\n\nexport type DitheringType = keyof typeof DitheringTypes;\n"],
5
- "mappings": ";;;;;AACA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB,WAAW,qBAAqB;AA6BvD,MAAM,0BAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7C,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUzB,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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