{
  "id": "depth-map-shader",
  "kind": "element",
  "title": "Depth map shader",
  "summary": "A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.",
  "url": "https://enrichr.dev/elements/depth-map-shader.html",
  "section": "hero",
  "techniques": [
    "webgl",
    "pointer-interaction",
    "parallax"
  ],
  "stack": [
    "Vanilla JS",
    "WebGL"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "cinematic",
    "soft"
  ],
  "intents": [
    "depth map parallax",
    "3d photo effect",
    "image depth hover",
    "2.5d image",
    "pointer parallax image shader"
  ],
  "status": "tested",
  "params": [
    {
      "key": "strength",
      "label": "Strength",
      "type": "range",
      "min": 0,
      "max": 0.15,
      "step": 0.005,
      "value": 0.05
    },
    {
      "key": "smoothing",
      "label": "Smoothing",
      "type": "range",
      "min": 0.02,
      "max": 0.4,
      "step": 0.01,
      "value": 0.1
    },
    {
      "key": "image",
      "label": "Image URL (empty uses a generated picture)",
      "type": "text",
      "value": ""
    },
    {
      "key": "colorA",
      "label": "Generated picture colour A",
      "type": "color",
      "value": "#2f7d5b"
    },
    {
      "key": "colorB",
      "label": "Generated picture colour B",
      "type": "color",
      "value": "#c6f26b"
    }
  ],
  "license": "Free to use in personal and client projects during the preview. Final licence terms will be published here before any paid tier starts; ask before reselling the code as a collection.",
  "contract": "function mount(root, opts) -> { update(partialOpts), destroy() }; root must contain the element markup",
  "exports": {
    "claude": "Add the \"Depth map shader\" element to this project.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSteps:\n1. Look at the project first to see its framework and where components, styles and static files live. Follow its conventions.\n2. Fetch https://enrichr.dev/elements/depth-map-shader.json if you can read URLs (fields: source.markup, source.css, source.js, params); otherwise use the source at the end of this message.\n3. Add the files, mount it where I tell you (default: the top of the home page), and pass the settings below as the opts.\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n5. Run the dev server and check it. with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "chatgpt": "I want the \"Depth map shader\" element on my website. Below is its complete source. Please:\n1. Build one self-contained index.html that I can open locally to see it working (put the CSS in a <style> tag and the JavaScript in a <script> tag, with the markup in the body).\n2. Then explain, step by step, which parts go where in my own site, and how to mount it. My stack is: [tell me yours, or say \"plain HTML\"].\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "cursor": "Add the \"Depth map shader\" element to this codebase.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nUse Composer / agent mode. First search the repo for how components, styles and scripts are organised, then add the files in the matching places, mount it on the page I name, and run the app to confirm it works. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nOptional: save this as .cursor/rules/enrichr-depth-map-shader.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Depth map shader element\nalwaysApply: false\n---\nmount(root, opts) expects the element markup inside root and returns { update, destroy }. Always call destroy() on unmount and never edit the ef- class names.",
    "v0": "Create a Next.js (App Router) client component for the \"Depth map shader\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- depth-map-shader.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nUse this component as the wrapper (adjust the import paths):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./depth-map-shader\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DepthMapShader(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRender it on the home page so I can see it. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "lovable": "Add the \"Depth map shader\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- depth-map-shader.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nWrapper component (src/components/DepthMapShader.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./depth-map-shader\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DepthMapShader(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRemove the \"use client\" line if it is not needed. Show it on the home page. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "bolt": "Create a small Vite project (vanilla JavaScript, no framework unless I already have one) that shows the \"Depth map shader\" element.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, then a script tag), style.css (the CSS below), depth-map-shader.js (the JavaScript below) and main.js that sets the container's innerHTML to the markup and calls mount(container, opts) with the settings below. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "replit": "Create a new HTML, CSS and JavaScript Repl that shows the \"Depth map shader\" element. No packages, no server code.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, link style.css, load depth-map-shader.js and then main.js), style.css (the CSS below), depth-map-shader.js (the JavaScript below), main.js (sets the container's innerHTML to the markup, then calls mount(container, opts) with the settings below). Press Run to preview. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "figma": "Designer handoff notes for the \"Depth map shader\" element (Enrichr Library). Figma cannot run this JavaScript inside a design file, so use it as a motion reference and hand the code to a developer.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nWhat it does: The picture is uploaded as a texture and drawn by a fragment shader. For each pixel the shader reads the picture's brightness, treats it as depth (bright is near), and shifts the lookup position by the pointer direction times that depth. Near pixels move further than far ones, which fakes parallax from a flat image. With no pointer, a slow drift runs so touch screens still show the effect. For best results supply a picture whose brightness roughly follows depth.\nAccessibility: The canvas is a labelled image; supply a more specific label for a real picture. With reduced motion the shader draws one still frame and does not drift or follow the pointer. If WebGL is missing, the container keeps a CSS gradient.\n\nTunable settings:\n- Strength: range 0 to 0.15, step 0.005, default 0.05\n- Smoothing: range 0.02 to 0.4, step 0.01, default 0.1\n- Image URL (empty uses a generated picture): text, default \n- Generated picture colour A: color, default #2f7d5b\n- Generated picture colour B: color, default #c6f26b\n\nCurrent settings:\n{{SETTINGS}}\n\nFor the developer: Element contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nIn Figma:\n- Draw the resting state as a frame and the end state as a second frame; link them with Smart Animate to show the motion in a prototype.\n- Put the settings above in the frame's notes or Dev Mode annotations so the developer matches them.\n- Link https://enrichr.dev/elements/depth-map-shader.html in the handoff: the live demo and the copy-ready code are there. Developers can paste the prompts for Claude, Cursor or v0 from the Export menu.\nNothing is copied from another designer's file; this is original code from Enrichr.",
    "framer": "Add the \"Depth map shader\" element to Framer as a code component. Framer code components are React, so wrap the vanilla code like this. Check it in the Framer editor, as Framer's component API can change.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. In Framer: Assets > Code > New component. Name it DepthMapShader.\n2. Paste the JavaScript below into a separate code file named depth-map-shader.js in the same project, with  export { mount };  and  export const markup = \"<the markup string>\";  added. Put the CSS into the component as a <style> tag.\n3. Component:\n```tsx\nimport { addPropertyControls, ControlType } from \"framer\"\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./depth-map-shader\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DepthMapShader(props: any) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n\naddPropertyControls(DepthMapShader, {\n  strength: { type: ControlType.Number, title: \"Strength\", min: 0, max: 0.15, step: 0.005, defaultValue: 0.05 },\n  smoothing: { type: ControlType.Number, title: \"Smoothing\", min: 0.02, max: 0.4, step: 0.01, defaultValue: 0.1 },\n  image: { type: ControlType.String, title: \"Image URL (empty uses a generated picture)\", defaultValue: \"\" },\n  colorA: { type: ControlType.Color, title: \"Generated picture colour A\", defaultValue: \"#2f7d5b\" },\n  colorB: { type: ControlType.Color, title: \"Generated picture colour B\", defaultValue: \"#c6f26b\" },\n})\n```\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "webflow": "Add the \"Depth map shader\" element to a Webflow site with an Embed element. Test it on the published or preview site: scripts in embeds may not run inside the Designer canvas.\n\nThis is the \"Depth map shader\" element from the Enrichr Library: A WebGL shader that shifts an image by its own depth and the pointer, so near parts move more than far ones.\nPage: https://enrichr.dev/elements/depth-map-shader.html\nMachine-readable spec: https://enrichr.dev/elements/depth-map-shader.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. Add an Embed element where it should appear. Paste a <style> block with the CSS, one container <div id=\"enrichr-depth-map-shader\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-depth-map-shader\"), { ...your settings... });\n   (set the container's innerHTML to the markup first, as in the contract).\n2. Embed elements have a size limit (check Webflow's current number). If the code is longer, host the JS and CSS as files and link them from Custom code in the page settings, then keep only the container and the mount call in the Embed.\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}"
  },
  "exportTools": [
    "claude",
    "chatgpt",
    "cursor",
    "v0",
    "lovable",
    "bolt",
    "replit",
    "figma",
    "framer",
    "webflow"
  ],
  "accessibility": "The canvas is a labelled image; supply a more specific label for a real picture. With reduced motion the shader draws one still frame and does not drift or follow the pointer. If WebGL is missing, the container keeps a CSS gradient.",
  "performance": "One full-screen triangle and two texture reads per pixel, at a capped resolution, paused when off screen or the tab is hidden. Large textures cost memory, so keep images under about 2000 pixels.",
  "dependencies": [],
  "source": {
    "markup": "<div class=\"ef-dgl\"><canvas class=\"ef-dgl__c\" role=\"img\" aria-label=\"An image whose layers shift with the pointer\"></canvas></div>",
    "css": ".ef-dgl { position: relative; overflow: hidden; min-height: 18rem; border-radius: 1rem; background: linear-gradient(135deg, var(--ef-a, #2f7d5b), var(--ef-b, #c6f26b)); touch-action: pan-y; }\r\n.ef-dgl__c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }",
    "js": "// Depth map shader: a small WebGL fragment shader shifts each pixel of an image by its own depth and by the pointer,\r\n// so near parts move more than far ones. With no depth image it derives depth from brightness (bright = near), so it works on any picture.\r\n// A generated picture is used until you give an image URL (it must allow cross-origin use). Without WebGL the container keeps a CSS gradient.\r\n// mount(root, { image (URL or empty), strength (0-0.15), smoothing (0.02-0.4), colorA, colorB })\r\nfunction mount(root, o) {\r\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\r\n  var wrap = root.querySelector(\".ef-dgl\");\r\n  var canvas = root.querySelector(\".ef-dgl__c\");\r\n  var gl = canvas.getContext(\"webgl\", { antialias: false, alpha: false, powerPreference: \"low-power\" });\r\n  var opts = {}, raf = 0, visible = true, io = null, prog, u = {}, tex, imgAspect = 1, hovering = false;\r\n  var tx = 0, ty = 0, cx = 0, cy = 0, t0 = performance.now(), customImg = null;\r\n  var VS = \"attribute vec2 p;varying vec2 vUv;void main(){vUv=p*.5+.5;gl_Position=vec4(p,0.,1.);}\";\r\n  var FS = \"precision mediump float;varying vec2 vUv;uniform sampler2D uT;uniform vec2 uP;uniform float uS,uA,uIA;\" +\r\n    \"void main(){vec2 uv=vUv;vec2 s=vec2(1.);if(uA>uIA){s.y=uIA/uA;}else{s.x=uA/uIA;}uv=(uv-.5)*s+.5;\" +\r\n    \"float d=dot(texture2D(uT,uv).rgb,vec3(.299,.587,.114));vec2 off=uP*uS*(d-.5);\" +\r\n    \"gl_FragColor=texture2D(uT,clamp(uv+off,0.,1.));}\";\r\n\r\n  function sh(type, src) { var s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return gl.getShaderParameter(s, gl.COMPILE_STATUS) ? s : null; }\r\n  function setup() {\r\n    var v = sh(gl.VERTEX_SHADER, VS), f = sh(gl.FRAGMENT_SHADER, FS);\r\n    if (!v || !f) return false;\r\n    prog = gl.createProgram(); gl.attachShader(prog, v); gl.attachShader(prog, f); gl.linkProgram(prog);\r\n    if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) return false;\r\n    gl.useProgram(prog);\r\n    var b = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, b);\r\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\r\n    var loc = gl.getAttribLocation(prog, \"p\"); gl.enableVertexAttribArray(loc); gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);\r\n    [\"uT\", \"uP\", \"uS\", \"uA\", \"uIA\"].forEach(function (k) { u[k] = gl.getUniformLocation(prog, k); });\r\n    tex = gl.createTexture();\r\n    return true;\r\n  }\r\n  function upload(source, aspect) {\r\n    gl.bindTexture(gl.TEXTURE_2D, tex);\r\n    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);\r\n    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);\r\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\r\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\r\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\r\n    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\r\n    imgAspect = aspect;\r\n  }\r\n  // a generated picture: a gradient with a few bright and dark shapes, so brightness works as depth\r\n  function generated() {\r\n    var c = document.createElement(\"canvas\"); c.width = c.height = 512;\r\n    var g = c.getContext(\"2d\");\r\n    var gr = g.createLinearGradient(0, 0, 512, 512); gr.addColorStop(0, opts.colorA); gr.addColorStop(1, opts.colorB);\r\n    g.fillStyle = gr; g.fillRect(0, 0, 512, 512);\r\n    [[150, 170, 120, \"rgba(255,255,255,.85)\"], [360, 130, 70, \"rgba(255,255,255,.6)\"], [300, 340, 140, \"rgba(0,0,0,.45)\"], [110, 380, 60, \"rgba(255,255,255,.7)\"], [420, 420, 45, \"rgba(255,255,255,.9)\"]].forEach(function (s) {\r\n      var rg = g.createRadialGradient(s[0], s[1], 0, s[0], s[1], s[2]);\r\n      rg.addColorStop(0, s[3]); rg.addColorStop(1, \"rgba(0,0,0,0)\");\r\n      g.fillStyle = rg; g.beginPath(); g.arc(s[0], s[1], s[2], 0, 6.2832); g.fill();\r\n    });\r\n    return c;\r\n  }\r\n  function safeUrl(x) { try { var a = new URL(x, window.location.href); return /^https?:$/.test(a.protocol) ? a.href : \"\"; } catch (e) { return \"\"; } }\r\n  function loadPicture() {\r\n    customImg = null;\r\n    var url = opts.image ? safeUrl(opts.image) : \"\";\r\n    if (url) {\r\n      var im = new Image(); im.crossOrigin = \"anonymous\";\r\n      im.onload = function () { try { customImg = im; upload(im, im.naturalWidth / im.naturalHeight); } catch (e) { customImg = null; upload(generated(), 1); } draw(); };\r\n      im.onerror = function () { upload(generated(), 1); draw(); };\r\n      im.src = url;\r\n    }\r\n    upload(generated(), 1);\r\n  }\r\n  function size() {\r\n    var dpr = Math.min(window.devicePixelRatio || 1, 1.5);\r\n    var w = Math.max(1, Math.round(wrap.clientWidth * dpr)), h = Math.max(1, Math.round(wrap.clientHeight * dpr));\r\n    if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; gl.viewport(0, 0, w, h); }\r\n  }\r\n  function draw() {\r\n    size();\r\n    gl.uniform1i(u.uT, 0);\r\n    gl.uniform2f(u.uP, cx, cy);\r\n    gl.uniform1f(u.uS, opts.strength);\r\n    gl.uniform1f(u.uA, canvas.width / canvas.height);\r\n    gl.uniform1f(u.uIA, imgAspect);\r\n    gl.drawArrays(gl.TRIANGLES, 0, 3);\r\n  }\r\n  function frame(now) {\r\n    raf = requestAnimationFrame(frame);\r\n    if (!visible || document.hidden) return;\r\n    if (!hovering) { var s = (now - t0) / 1000; tx = Math.sin(s * 0.7) * 0.5; ty = Math.cos(s * 0.5) * 0.4; }\r\n    cx += (tx - cx) * opts.smoothing; cy += (ty - cy) * opts.smoothing;\r\n    draw();\r\n  }\r\n  function move(e) {\r\n    var r = wrap.getBoundingClientRect();\r\n    tx = ((e.clientX - r.left) / r.width - 0.5) * 2;\r\n    ty = -((e.clientY - r.top) / r.height - 0.5) * 2;\r\n    hovering = true;\r\n  }\r\n  function leave() { hovering = false; }\r\n  function update(next) {\r\n    var prevImage = opts.image, prevA = opts.colorA, prevB = opts.colorB;\r\n    opts = Object.assign({ image: \"\", strength: 0.05, smoothing: 0.1, colorA: \"#2f7d5b\", colorB: \"#c6f26b\" }, opts, next || {});\r\n    wrap.style.setProperty(\"--ef-a\", opts.colorA);\r\n    wrap.style.setProperty(\"--ef-b\", opts.colorB);\r\n    if (!ok) return;\r\n    if (opts.image !== prevImage || opts.colorA !== prevA || opts.colorB !== prevB) loadPicture();\r\n    if (reduce) draw();\r\n  }\r\n  var ok = gl && setup();\r\n  if (!ok) { canvas.style.display = \"none\"; update(o); return { update: update, destroy: function () {} }; }\r\n  update(o);\r\n  if (!reduce) {\r\n    wrap.addEventListener(\"pointermove\", move);\r\n    wrap.addEventListener(\"pointerleave\", leave);\r\n    if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(wrap); }\r\n    raf = requestAnimationFrame(frame);\r\n  }\r\n  return { update: update, destroy: function () { cancelAnimationFrame(raf); if (io) io.disconnect(); wrap.removeEventListener(\"pointermove\", move); wrap.removeEventListener(\"pointerleave\", leave); } };\r\n}"
  }
}