@paper-design/shaders 0.0.0-canary.b7acb21 → 0.0.0-canary.df082ba

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 (47) hide show
  1. package/dist/html-in-canvas.d.ts +23 -0
  2. package/dist/html-in-canvas.js +64 -0
  3. package/dist/html-in-canvas.js.map +7 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +4 -0
  6. package/dist/index.js.map +2 -2
  7. package/dist/shader-mount.d.ts +16 -1
  8. package/dist/shader-mount.js +143 -26
  9. package/dist/shader-mount.js.map +2 -2
  10. package/dist/shaders/color-panels.js +0 -3
  11. package/dist/shaders/color-panels.js.map +2 -2
  12. package/dist/shaders/dot-orbit.js +1 -2
  13. package/dist/shaders/dot-orbit.js.map +2 -2
  14. package/dist/shaders/fluted-glass.d.ts +4 -1
  15. package/dist/shaders/fluted-glass.js +18 -18
  16. package/dist/shaders/fluted-glass.js.map +2 -2
  17. package/dist/shaders/god-rays.js +3 -5
  18. package/dist/shaders/god-rays.js.map +2 -2
  19. package/dist/shaders/halftone-cmyk.d.ts +4 -2
  20. package/dist/shaders/halftone-cmyk.js +34 -8
  21. package/dist/shaders/halftone-cmyk.js.map +2 -2
  22. package/dist/shaders/halftone-dots.d.ts +4 -2
  23. package/dist/shaders/halftone-dots.js +30 -5
  24. package/dist/shaders/halftone-dots.js.map +2 -2
  25. package/dist/shaders/image-dithering.d.ts +5 -3
  26. package/dist/shaders/image-dithering.js +20 -4
  27. package/dist/shaders/image-dithering.js.map +2 -2
  28. package/dist/shaders/lens-distortion.d.ts +3 -1
  29. package/dist/shaders/lens-distortion.js +14 -7
  30. package/dist/shaders/lens-distortion.js.map +2 -2
  31. package/dist/shaders/liquid-metal.js +1 -2
  32. package/dist/shaders/liquid-metal.js.map +2 -2
  33. package/dist/shaders/paper-texture.d.ts +5 -1
  34. package/dist/shaders/paper-texture.js +34 -21
  35. package/dist/shaders/paper-texture.js.map +2 -2
  36. package/dist/shaders/voronoi.js +1 -2
  37. package/dist/shaders/voronoi.js.map +2 -2
  38. package/dist/shaders/water.d.ts +4 -2
  39. package/dist/shaders/water.js +23 -8
  40. package/dist/shaders/water.js.map +2 -2
  41. package/dist/size-to-content.d.ts +8 -0
  42. package/dist/size-to-content.js +41 -0
  43. package/dist/size-to-content.js.map +7 -0
  44. package/dist/vertex-shader.d.ts +1 -1
  45. package/dist/vertex-shader.js +3 -0
  46. package/dist/vertex-shader.js.map +2 -2
  47. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/shaders/paper-texture.ts"],
4
- "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, proceduralHash21, proceduralHash22 } from '../shader-utils.js';\n\nexport const paperTextureMeta = {\n maxCrumpleCount: 15,\n} as const;\n\n/**\n * Static paper-like texture built from a combination of grain, noise and multiple fold patterns.\n * Works as an image filter or as a standalone texture.\n *\n * Fragment shader uniforms:\n * - u_image (sampler2D): Optional source image texture\n * - u_isImage (bool): Whether a source image was provided\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n * - u_colorBack (vec4): Color behind the paper sheet in RGBA\n * - u_colorPaper (vec4): Color of the paper sheet in RGBA\n * - u_colorShadow (vec4): Color of the patterns over the paper sheet in RGBA\n * - u_blending (float): Amount of image-to-paper blending, needs image (0 to 1)\n * - u_distortion (float): How much the image bends with the paper surface, needs image (-1 to 1)\n * - u_clip (bool): Cuts the paper sheet to the image frame, needs image\n * - u_angle (float): Direction the surface is lit from in degrees, also the roughness rows direction, needs crumples, wrinkles, folds, roughnessRows or drops > 0 (0 to 360)\n * - u_seed (float): Seed applied to every pattern (0 to 1000)\n * - u_roughness (float): Fine grain covering the surface evenly (0 to 1)\n * - u_roughnessSize (float): Scale of the roughness grain, needs roughness > 0 (0 to 1)\n * - u_roughnessRows (float): Lines the roughness up into stripes, 0 = even scatter, 1 = laid-paper rows, needs roughness > 0 (0 to 1)\n * - u_fiber (float): Curly thread-like noise covering the surface evenly (0 to 1)\n * - u_fiberSize (float): Scale of the fiber noise, needs fiber > 0 (0 to 1)\n * - u_folds (float): Straight vertical and horizontal fold lines producing ridges and valleys (0 to 1)\n * - u_foldSizeX (float): Size of the vertical folds, needs folds > 0 (0 to 1)\n * - u_foldSizeY (float): Size of the horizontal folds, needs folds > 0 (0 to 1)\n * - u_foldOffsetX (float): Shifts the vertical folds across the surface, needs folds > 0 (0 to 1)\n * - u_foldOffsetY (float): Shifts the horizontal folds across the surface, needs folds > 0 (0 to 1)\n * - u_wrinkles (float): Crumple-like facets repeating across the surface (0 to 1)\n * - u_wrinkleSize (float): Scale of the wrinkle facets, needs wrinkles > 0 (0 to 1)\n * - u_crumples (float): A set of irregular folding lines (0 to 1)\n * - u_crumpleCount (float): Number of facets in the crumple field, needs crumples > 0 (2 to 15)\n * - u_drops (float): Visibility of the speckle pattern, darkens the image instead of coloring it (0 to 1)\n * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_imageUV (vec2): UV coordinates for sampling the source image, with fit, scale, rotation, and offset applied\n *\n * Vertex shader uniforms:\n * - u_resolution (vec2): Canvas resolution in pixels\n * - u_pixelRatio (float): Device pixel ratio\n * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)\n * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)\n * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)\n * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)\n * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)\n * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n *\n */\n\n// language=GLSL\nexport const paperTextureFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform sampler2D u_image;\nuniform bool u_isImage;\nuniform float u_imageAspectRatio;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorPaper;\nuniform vec4 u_colorShadow;\n\nuniform float u_blending;\nuniform float u_distortion;\nuniform bool u_clip;\nuniform float u_angle;\nuniform float u_seed;\n\nuniform float u_roughness;\nuniform float u_roughnessSize;\nuniform float u_roughnessRows;\nuniform float u_fiber;\nuniform float u_fiberSize;\nuniform float u_folds;\nuniform float u_foldSizeX;\nuniform float u_foldSizeY;\nuniform float u_foldOffsetX;\nuniform float u_foldOffsetY;\nuniform float u_wrinkles;\nuniform float u_wrinkleSize;\nuniform float u_crumples;\nuniform float u_crumpleCount;\nuniform float u_drops;\n\nuniform sampler2D u_noiseTexture;\n\nin vec2 v_imageUV;\nout vec4 fragColor;\n\nfloat getUvFrame(vec2 uv) {\n vec2 invAA = .5 / clamp(fwidth(uv), 1e-5, .02);\n vec2 lo = clamp(uv * invAA + .5, 0., 1.);\n vec2 hi = clamp((1. - uv) * invAA + .5, 0., 1.);\n return lo.x * hi.x * lo.y * hi.y;\n}\n\nfloat lst(float edge0, float edge1, float x) {\n return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);\n}\n\n${declarePI}\n${proceduralHash21}\n${proceduralHash22}\n\nfloat getRoughness(vec2 p, vec2 lightDir, vec2 seedShift, float basePixel) {\n vec2 u = p / vec2(2, 4);\n float w = 100. * basePixel;\n float eps = 4. * w;\n\n float size = mix(3.2, .8, u_roughnessSize);\n float logLac = log2(2.1);\n float level = -log2(w + 1e-8) / logLac;\n float baseLevel = floor(level) - 2.;\n float fade = fract(level);\n\n vec2 px = (u.x + vec2(eps, -eps)) * .1;\n float py = u.y * .1;\n\n vec2 sum = vec2(0.);\n float norm = 0., amp = .5;\n float freq = exp2(baseLevel * logLac);\n for (int i = 0; i < 4; i++) {\n float absIdx = baseLevel + float(i);\n vec2 qx = size * px * freq;\n float qy = size * py * freq;\n\n float wi = 1.;\n if (i == 0) wi = 1. - fade;\n if (i == 3) wi = fade;\n\n vec2 fx = fract(qx);\n float fy = fract(qy);\n vec2 shift = .5 + absIdx * .3 + seedShift;\n float uvY = floor(qy) / 50. + shift.y;\n vec2 s0a = texture(u_noiseTexture, fract(vec2(floor(qx.x) / 50. + shift.x, uvY))).rg;\n vec2 s1a = texture(u_noiseTexture, fract(vec2( ceil(qx.x) / 50. + shift.x, uvY))).rg;\n vec2 s0b = texture(u_noiseTexture, fract(vec2(floor(qx.y) / 50. + shift.x, uvY))).rg;\n vec2 s1b = texture(u_noiseTexture, fract(vec2( ceil(qx.y) / 50. + shift.x, uvY))).rg;\n vec2 ny0 = mix(vec2(s0a.r, s0b.r), vec2(s0a.g, s0b.g), fy);\n vec2 ny1 = mix(vec2(s1a.r, s1b.r), vec2(s1a.g, s1b.g), fy);\n vec2 n = mix(ny0, ny1, fx);\n\n sum += amp * wi * n;\n norm += amp * wi;\n amp *= .8;\n freq *= 2.1;\n }\n\n vec2 r = sum / norm;\n float dx = .5 + r.x - r.y;\n float grain = 3. * dx * dx - .7;\n\n float rowBand = fract(dot(p, lightDir) * .05 * size);\n return grain + .6 * u_roughnessRows * (rowBand - .5);\n}\n\nfloat getFiber(vec2 p, vec2 seedShift, float basePixel) {\n float size = mix(4., 1., u_fiberSize);\n float w = 50. * basePixel;\n float level = -log2(w + 1e-8);\n float baseLevel = floor(level) - 3.;\n float fade = fract(level);\n\n vec2 grad = vec2(0.);\n float scale = 1.;\n float amp = 1.;\n float freq = pow(1.7, baseLevel);\n for (int i = 0; i < 5; i++) {\n float absIdx = baseLevel + float(i);\n vec2 q = size * p * freq;\n\n float an = absIdx * .8;\n float rc = cos(an), rs = sin(an);\n q = vec2(rc * q.x - rs * q.y, rs * q.x + rc * q.y);\n\n float wi = 1.;\n if (i == 0) wi = 1. - fade;\n if (i == 4) wi = fade;\n\n vec2 iq = floor(q);\n vec2 fq = fract(q);\n float shift = absIdx * .3;\n vec4 uv = fract(vec4(iq, iq + 1.) / 50. + .5 + shift + seedShift.xyxy);\n float aF = texture(u_noiseTexture, uv.xy).b;\n float bF = texture(u_noiseTexture, uv.zy).b;\n float cF = texture(u_noiseTexture, uv.xw).b;\n float dF = texture(u_noiseTexture, uv.zw).b;\n vec2 u = fq * fq * (3. - 2. * fq);\n vec2 du = 8. * fq * (1. - fq);\n float dx = du.x * mix(bF - aF, dF - cF, u.y);\n float dy = du.y * mix(cF - aF, dF - bF, u.x);\n grad += wi * amp * scale * vec2(rc * dx + rs * dy, -rs * dx + rc * dy);\n scale *= 1.7;\n amp *= .5;\n freq *= 1.7;\n }\n\n return clamp(.333 * length(grad), 0., 1.);\n}\n\nvec2 smoothNoise(vec2 p) {\n vec2 t = p * 50. - .5;\n vec2 i = floor(t);\n vec2 f = fract(t);\n f = f * f * (3. - 2. * f);\n return texture(u_noiseTexture, fract((i + f + .5) / vec2(50.))).rg;\n}\n\nfloat getDrops(vec2 uv, vec2 seedShift) {\n vec2 iDropsUV = floor(uv);\n vec2 fDropsUV = fract(uv);\n float dropsMinDist = 1.;\n for (int y = -1; y < 2; y += 1) {\n for (int x = -1; x < 2; x += 1) {\n vec2 neighbor = vec2(float(y), float(x));\n vec2 offset = hash22(iDropsUV + neighbor);\n offset = .5 + .5 * sin(10. * u_seed + TWO_PI * offset);\n vec2 pos = neighbor + offset - fDropsUV;\n dropsMinDist *= min(1., dot(pos, pos));\n }\n }\n return .5 * lst(.09, .08, sqrt(sqrt(dropsMinDist)));\n}\n\nvec2 getCellTilt(float idx, float radius) {\n vec2 rand = hash22(vec2(idx + 31., idx * u_seed + 17.));\n float an = rand.x * TWO_PI;\n return vec2(cos(an), sin(an)) * mix(.3, 1.7, rand.y * rand.y) * mix(.7, 1., radius);\n}\n\nvec2 getCrumpleDetail(vec2 uv, float freq, float shift, float basePixel, out float depth) {\n depth = 0.;\n vec2 v = uv * freq;\n float pixel = .9 * freq * basePixel;\n vec2 base = floor(v);\n float n1 = 9., n2 = 9.;\n vec2 s1 = vec2(0.), s2 = vec2(0.), q1 = vec2(0.), q2 = vec2(0.);\n\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 cell = base + vec2(float(x), float(y));\n vec2 q = hash22(vec2(cell.y * 1.9 + 3.1 + shift, cell.x * 1.3 + .11 * u_seed));\n float keep = .8;\n if (q.y > keep) continue;\n\n vec2 r = hash22(vec2(cell.x + .37 * u_seed + shift + 11.1, cell.y - .21 * u_seed + 5.7));\n vec2 s = cell + .06 + .88 * r;\n\n vec2 d = v - s;\n float dsq = dot(d, d);\n if (dsq < n1) {\n n2 = n1;\n s2 = s1;\n q2 = q1;\n n1 = dsq;\n s1 = s;\n q1 = q;\n } else if (dsq < n2) {\n n2 = dsq;\n s2 = s;\n q2 = q;\n }\n }\n }\n\n if (n1 > 8.) return vec2(0.);\n\n float an1 = q1.x * TWO_PI, mag1 = q1.y / .8;\n vec2 t1 = vec2(cos(an1), sin(an1)) * mix(.3, 1.7, mag1 * mag1);\n float an2 = q2.x * TWO_PI, mag2 = q2.y / .8;\n vec2 t2 = vec2(cos(an2), sin(an2)) * mix(.3, 1.7, mag2 * mag2);\n\n vec2 span = s1 - s2;\n float spanLen = max(length(span), 1e-4);\n float toEdge = (n2 - n1) / (2. * spanLen);\n\n float pair = hash21(s1 + s2 + 1.7 * abs(s1 - s2));\n float pairSoft = .05 + .1 * step(pair, .4);\n float b = clamp(toEdge / max(1.5 * pixel, .5 * pairSoft), 0., 1.);\n b = b * b * (3. - 2. * b);\n float d1 = max(sqrt(n1), 1e-4);\n depth = .2 * d1;\n float shoulderAmt = max(0., 1. - toEdge / .42) * b;\n vec2 shoulder = vec2(0.);\n if (shoulderAmt > 0.) {\n float d2 = max(sqrt(n2), 1e-4);\n shoulder = shoulderAmt * ((v - s2) / d2 - (v - s1) / d1);\n }\n\n vec2 mid = .5 * (t1 + t2);\n return mid + (t1 - mid) * b + .9 * shoulder;\n}\n\nvec4 getCrumples(vec2 uv) {\n float crumpleN = max(2., floor(u_crumpleCount + .5));\n float near = 9., nearB = 9.;\n float idx = 0., rad = 0.;\n vec2 nearP = vec2(0.), nearPb = vec2(0.);\n vec4 seeds[${paperTextureMeta.maxCrumpleCount}];\n for (int i = 0; i < ${paperTextureMeta.maxCrumpleCount}; i++) {\n if (float(i) >= crumpleN) break;\n vec2 rand = hash22(vec2(float(i), float(i) * u_seed));\n float an = rand.x * TWO_PI;\n vec2 p = vec2(cos(an), sin(an)) * rand.y;\n seeds[i] = vec4(p, rand);\n\n vec2 d = uv - p;\n float dsq = dot(d, d);\n if (dsq < near) {\n nearB = near;\n nearPb = nearP;\n near = dsq;\n idx = float(i);\n rad = rand.y;\n nearP = p;\n } else if (dsq < nearB) {\n nearB = dsq;\n nearPb = p;\n }\n }\n float l = sqrt(near), lb = sqrt(nearB);\n vec2 dir = (uv - nearP) / max(l, 1e-4);\n float edge = lst(0., .5, lb - l);\n\n float shoulderLimit = l + .5;\n\n vec2 tilt = getCellTilt(idx, rad);\n float tiltSum = 1.;\n vec2 wide = vec2(0.);\n float wideSum = 0.;\n float toEdge = 9., edgeSoft = 0.;\n\n for (int i = 0; i < ${paperTextureMeta.maxCrumpleCount}; i++) {\n if (float(i) >= crumpleN) break;\n if (float(i) == idx) continue;\n vec4 seed = seeds[i];\n vec2 p = seed.xy;\n vec2 rand = seed.zw;\n\n vec2 d = uv - p;\n float dsq = dot(d, d);\n\n if (dsq < shoulderLimit * shoulderLimit) {\n float di = sqrt(dsq);\n float shoulder = lst(.5, 0., di - l);\n wide += shoulder * (d / max(di, 1e-4) - dir);\n wideSum += shoulder;\n }\n\n float pairSoft = .01 + .05 * step(.2, rand.x) + .3 * rand.y;\n float toBisector = (dsq - near) / (.2 * max(length(p - nearP), 1e-4));\n if (toBisector < toEdge) {\n toEdge = toBisector;\n edgeSoft = pairSoft;\n }\n\n float w = 1. - toBisector / pairSoft;\n if (w > 0.) {\n w *= w;\n tilt += w * getCellTilt(float(i), rand.y);\n tiltSum += w;\n }\n }\n\n float blend = clamp(toEdge / edgeSoft, 0., 1.);\n vec2 sharp = (1. - edge) * ((uv - nearPb) / max(lb, 1e-4) - dir);\n vec2 rounding = mix(sharp, wide / max(wideSum, 1.), min(2. * edgeSoft, 1.));\n float radial = l / max(l + toEdge, 1e-4);\n\n return vec4(tilt / tiltSum + rounding * blend * radial, .2 * l, edge);\n}\n\nvoid getFolds(vec2 coord, vec2 offset, vec2 count, vec2 noise, vec2 baseFwidth, out vec2 slope, out vec2 dark, out vec2 lift) {\n vec2 g = coord * count + .5 * offset + noise;\n vec2 dx = fract(g) - .5;\n vec2 adx = abs(dx);\n float foldRadius = .3;\n vec2 t = clamp(adx / foldRadius, 0., 1.);\n dark = t * t * (3. - 2. * t);\n lift = 1. - t;\n lift *= lift;\n\n vec2 crease = clamp(dx / max(count * baseFwidth, 1e-5), -1., 1.);\n slope = crease * (1. - dark);\n\n vec2 lineWidth = .02 * count * mix(vec2(2.5), vec2(.8), dark.yx) + .1 * noise;\n slope -= 1. - smoothstep(vec2(0.), lineWidth, adx);\n}\n\nvoid main() {\n\n vec2 patternUV = (v_imageUV - .5) * vec2(u_imageAspectRatio, 1.);\n float basePixel = max(length(dFdx(patternUV)), length(dFdy(patternUV)));\n vec2 baseFwidth = fwidth(patternUV);\n\n float pattern = 0.;\n\n float crumpleDepth = 0.;\n float wrinkleDepth = 0.;\n float foldDepth = 0.;\n float roughness = 0.;\n float fiber = 0.;\n float drops = 0.;\n\n float grazing = 0.7;\n float lightRad = radians(u_angle);\n vec2 lightDir = vec2(sin(lightRad), -cos(lightRad));\n float foldAngleInSector = mod(u_angle, 90.);\n float foldLightRad = radians(u_angle - foldAngleInSector + mix(12., 78., foldAngleInSector / 90.));\n vec2 foldLightDir = vec2(sin(foldLightRad), -cos(foldLightRad));\n vec2 relief = vec2(0.);\n vec2 foldSlope = vec2(0.);\n float reliefAmount = 0.;\n float foldInk = 1.;\n vec2 crumpleFlow = vec2(0.);\n\n vec2 warpNoise = vec2(0.);\n if (u_crumples > 0. || u_folds > 0. || u_wrinkles > 0.) {\n warpNoise = smoothNoise(patternUV * .1 + .2 + .6 * fract(.017 * u_seed)) - .5;\n }\n vec2 crumplesUV = (patternUV * .9) + .012 * warpNoise;\n\n if (u_crumples > 0.) {\n vec4 crumples = getCrumples(crumplesUV);\n\n vec2 crumpleTilt = .5 * u_crumples * crumples.xy;\n crumpleTilt -= .1 * max(dot(crumpleTilt, lightDir), 0.) * lightDir;\n relief += crumpleTilt;\n reliefAmount += .6 * u_crumples;\n crumpleFlow = crumples.w * crumpleTilt;\n\n crumpleDepth = clamp(5. * crumples.z, 0., 1.);\n }\n\n if (u_wrinkles > 0.) {\n float detailFreq = mix(10., 1., u_wrinkleSize);\n float detailAmp = .2;\n vec2 detailGrad = vec2(0.);\n float detailDepth = 0., depthSum = 0.;\n for (int i = 0; i < 3; i++) {\n float layerDepth;\n detailGrad += detailAmp * getCrumpleDetail(crumplesUV, detailFreq, 31. * float(i), basePixel, layerDepth);\n detailDepth += detailAmp * layerDepth;\n depthSum += detailAmp;\n detailAmp *= (.5 + .2 * detailGrad.x);\n detailFreq *= 2.1;\n }\n\n vec2 detailTilt = 1.5 * u_wrinkles * detailGrad;\n detailTilt -= .65 * max(dot(detailTilt, lightDir), 0.) * lightDir;\n relief += detailTilt;\n reliefAmount += .6 * u_wrinkles;\n\n wrinkleDepth = clamp(5. * detailDepth / max(depthSum, 1e-4), 0., 1.);\n }\n\n if (u_folds > 0.) {\n vec2 foldOffset = vec2(1. - 2. * u_foldOffsetX, 1. - 2. * u_foldOffsetY);\n vec2 foldCount = vec2(mix(3., .5, u_foldSizeX), mix(3., .5, u_foldSizeY));\n vec2 foldNoise = .005 * warpNoise * foldCount;\n vec2 uv = patternUV + .03 * crumpleFlow;\n\n vec2 slope, dark, lift;\n getFolds(uv, foldOffset, foldCount, foldNoise, baseFwidth, slope, dark, lift);\n\n foldSlope = u_folds * slope;\n reliefAmount += 1. * u_folds;\n vec2 ink = mix(vec2(.96), vec2(1.), dark);\n float flatness = dark.x * dark.y;\n foldInk *= mix(1., ink.x * ink.y * mix(.5, .3, flatness), u_folds);\n\n foldDepth = u_folds * (lift.y * foldLightDir.y - lift.x * foldLightDir.x);\n }\n\n float unlit = cos(grazing);\n float lit = unlit;\n\n if (reliefAmount > 0.) {\n float lightFalloff = clamp(.5 + dot(v_imageUV - .5, lightDir), 0., 1.);\n float lightPower = mix(.5, 1., lightFalloff);\n float slope = clamp(dot(relief, lightDir) + dot(foldSlope, foldLightDir), -1.2, 1.2);\n lit = max(cos(slope + grazing), 0.);\n\n pattern += (clamp(reliefAmount, 0., 1.) * unlit + (lit - unlit)) * foldInk * lightPower;\n }\n\n patternUV += .04 * crumpleFlow;\n\n vec2 seedShift = floor(fract(u_seed * vec2(.7548776662, .5698402909)) * 50.) / 50.;\n\n if (u_roughness > 0.) {\n roughness = u_roughness * getRoughness(1000. * patternUV, lightDir, seedShift, basePixel);\n pattern += roughness;\n }\n\n if (u_fiber > 0.) {\n fiber = u_fiber * getFiber(50. * patternUV, seedShift, basePixel);\n pattern += fiber;\n }\n\n if (u_drops > 0.) {\n drops = u_drops * getDrops(patternUV * 10., seedShift);\n }\n\n pattern = clamp(pattern, 0., 1.);\n\n vec3 backColor = u_colorBack.rgb * u_colorBack.a;\n float backOpacity = u_colorBack.a;\n vec3 baseColor = u_colorPaper.rgb * u_colorPaper.a;\n float baseOpacity = u_colorPaper.a;\n vec3 shadowColor = u_colorShadow.rgb * u_colorShadow.a;\n float shadowOpacity = u_colorShadow.a;\n\n float notClipped = u_clip ? .1 : 1.;\n vec2 imageCenteredUV = v_imageUV - .5;\n float edgeDist = 2. * max(abs(imageCenteredUV.x), abs(imageCenteredUV.y));\n float wrinkleDistortion = mix(.38, .0175, smoothstep(0., 1., edgeDist));\n float scaleDistortion = .15 * u_crumples * (crumpleDepth - .5) + wrinkleDistortion * u_wrinkles * (wrinkleDepth - .5) + .05 * foldDepth;\n vec2 linearDistortion = notClipped * .002 * lightDir * drops;\n float radialDistortion = notClipped * .02 * (roughness + fiber);\n vec2 centeredUV = imageCenteredUV * (1. - u_distortion * scaleDistortion);\n centeredUV -= u_distortion * linearDistortion;\n vec2 imageUV = .5 + centeredUV * (1. - abs(u_distortion) * radialDistortion * dot(centeredUV, centeredUV));\n\n vec3 color = shadowColor * pattern;\n float opacity = shadowOpacity * pattern;\n color += baseColor * (1. - opacity);\n opacity += baseOpacity * (1. - opacity);\n\n if (u_isImage) {\n float frame = getUvFrame(imageUV);\n vec4 image = texture(u_image, imageUV);\n frame *= image.a;\n\n float maxC = max(max(image.r, image.g), image.b);\n float minC = min(min(image.r, image.g), image.b);\n float sat = maxC > 0. ? (maxC - minC) / maxC : 0.;\n float midC = image.r + image.g + image.b - maxC - minC;\n float secondaryness = maxC > minC ? (midC - minC) / (maxC - minC) : 0.;\n float satDampen = sat * (1. - .5 * secondaryness);\n float darkDampen = 1. - dot(vec3(.2126, .7152, .0722), image.rgb);\n float dampen = mix(0., .7, u_blending) * max(satDampen, darkDampen);\n\n vec3 paper = vec3(1.) - opacity + color;\n vec3 pic = image.rgb * paper * u_blending + image.rgb * (1. - u_blending);\n pic = mix(pic, vec3(1.), .6 * pow(dampen, 2. + 3. * pattern));\n\n color = mix(color, pic, frame);\n opacity = frame + opacity * (1. - frame);\n\n if (u_clip) {\n color *= frame;\n opacity *= frame;\n }\n }\n\n color *= mix(vec3(1.), .5 * u_colorShadow.rgb, drops * shadowOpacity);\n\n color += backColor * (1. - opacity);\n opacity += backOpacity * (1. - opacity);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface PaperTextureUniforms extends ShaderSizingUniforms {\n u_image: HTMLImageElement | string | undefined;\n u_isImage: boolean;\n u_colorBack: [number, number, number, number];\n u_colorPaper: [number, number, number, number];\n u_colorShadow: [number, number, number, number];\n u_blending: number;\n u_distortion: number;\n u_clip: boolean;\n u_angle: number;\n u_seed: number;\n u_roughness: number;\n u_roughnessSize: number;\n u_roughnessRows: number;\n u_fiber: number;\n u_fiberSize: number;\n u_folds: number;\n u_foldSizeX: number;\n u_foldSizeY: number;\n u_foldOffsetX: number;\n u_foldOffsetY: number;\n u_wrinkles: number;\n u_wrinkleSize: number;\n u_crumples: number;\n u_crumpleCount: number;\n u_drops: number;\n u_noiseTexture?: HTMLImageElement;\n}\nexport interface PaperTextureParams extends ShaderSizingParams, ShaderMotionParams {\n image?: HTMLImageElement | string;\n colorBack?: string;\n colorPaper?: string;\n colorShadow?: string;\n blending?: number;\n distortion?: number;\n clip?: boolean;\n angle?: number;\n seed?: number;\n roughness?: number;\n roughnessSize?: number;\n roughnessRows?: number;\n fiber?: number;\n fiberSize?: number;\n folds?: number;\n foldSizeX?: number;\n foldSizeY?: number;\n foldOffsetX?: number;\n foldOffsetY?: number;\n wrinkles?: number;\n wrinkleSize?: number;\n crumples?: number;\n crumpleCount?: number;\n drops?: number;\n}\n"],
5
- "mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,kBAAkB,wBAAwB;AAEvD,MAAM,mBAAmB;AAAA,EAC9B,iBAAiB;AACnB;AAqDO,MAAM,6BAAqC;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,EAiDhD,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,gBAAgB;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;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;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;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,eAoMH,iBAAiB,eAAe;AAAA,wBACvB,iBAAiB,eAAe;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,wBAiChC,iBAAiB,eAAe;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;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;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;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;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;",
4
+ "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, proceduralHash21, proceduralHash22 } from '../shader-utils.js';\n\nexport const paperTextureMeta = {\n maxCrumpleCount: 15,\n} as const;\n\n/**\n * Static paper-like texture built from a combination of grain, noise and multiple fold patterns.\n * Works as an image filter or as a standalone texture.\n *\n * Fragment shader uniforms:\n * - u_image (sampler2D): Optional source image texture, premultiplied alpha\n * - u_isImage (bool): Whether a source image was provided\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n * - u_imageIsHtml (float): 1 when u_image is HTML. HTML is drawn 1:1, so the surface detail (crumples, wrinkles, roughness,\n * fiber, drops) doesn't scale with the canvas. It's anchored at originX / originY instead of the center,\n * 0 0 being the top left like CSS. The folds are anchored there too,\n * but keep their size relative to the frame, and so does the warp of the image. Wrinkles get much finer toward wrinkleSize 0\n * - u_colorBack (vec4): Color behind the paper sheet in RGBA\n * - u_colorPaper (vec4): Color of the paper sheet in RGBA\n * - u_colorShadow (vec4): Color of the patterns over the paper sheet in RGBA\n * - u_blending (float): Amount of image-to-paper blending, needs image (0 to 1)\n * - u_distortion (float): How much the image bends with the paper surface, needs image (-1 to 1)\n * - u_clip (bool): Cuts the paper sheet to the image frame, needs image\n * - u_angle (float): Direction the surface is lit from in degrees, also the roughness rows direction, needs crumples, wrinkles, folds, roughnessRows or drops > 0 (0 to 360)\n * - u_seed (float): Seed applied to every pattern (0 to 1000)\n * - u_roughness (float): Fine grain covering the surface evenly (0 to 1)\n * - u_roughnessSize (float): Scale of the roughness grain, needs roughness > 0 (0 to 1)\n * - u_roughnessRows (float): Lines the roughness up into stripes, 0 = even scatter, 1 = laid-paper rows, needs roughness > 0 (0 to 1)\n * - u_fiber (float): Curly thread-like noise covering the surface evenly (0 to 1)\n * - u_fiberSize (float): Scale of the fiber noise, needs fiber > 0 (0 to 1)\n * - u_folds (float): Straight vertical and horizontal fold lines producing ridges and valleys (0 to 1)\n * - u_foldSizeX (float): Size of the vertical folds, needs folds > 0 (0 to 1)\n * - u_foldSizeY (float): Size of the horizontal folds, needs folds > 0 (0 to 1)\n * - u_foldOffsetX (float): Shifts the vertical folds across the surface, needs folds > 0 (0 to 1)\n * - u_foldOffsetY (float): Shifts the horizontal folds across the surface, needs folds > 0 (0 to 1)\n * - u_wrinkles (float): Crumple-like facets repeating across the surface (0 to 1)\n * - u_wrinkleSize (float): Scale of the wrinkle facets, needs wrinkles > 0 (0 to 1)\n * - u_crumples (float): A set of irregular folding lines (0 to 1)\n * - u_crumpleCount (float): Number of facets in the crumple field, needs crumples > 0 (2 to 15)\n * - u_drops (float): Visibility of the speckle pattern, darkens the image instead of coloring it (0 to 1)\n * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_imageUV (vec2): UV coordinates for sampling the source image, with fit, scale, rotation, and offset applied\n *\n * Vertex shader uniforms:\n * - u_resolution (vec2): Canvas resolution in pixels\n * - u_pixelRatio (float): Device pixel ratio\n * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)\n * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)\n * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)\n * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)\n * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)\n * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n *\n */\n\n// language=GLSL\nexport const paperTextureFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform sampler2D u_image;\nuniform bool u_isImage;\nuniform float u_imageAspectRatio;\nuniform float u_imageIsHtml;\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_originX;\nuniform float u_originY;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorPaper;\nuniform vec4 u_colorShadow;\n\nuniform float u_blending;\nuniform float u_distortion;\nuniform bool u_clip;\nuniform float u_angle;\nuniform float u_seed;\n\nuniform float u_roughness;\nuniform float u_roughnessSize;\nuniform float u_roughnessRows;\nuniform float u_fiber;\nuniform float u_fiberSize;\nuniform float u_folds;\nuniform float u_foldSizeX;\nuniform float u_foldSizeY;\nuniform float u_foldOffsetX;\nuniform float u_foldOffsetY;\nuniform float u_wrinkles;\nuniform float u_wrinkleSize;\nuniform float u_crumples;\nuniform float u_crumpleCount;\nuniform float u_drops;\n\nuniform sampler2D u_noiseTexture;\n\nin vec2 v_imageUV;\nout vec4 fragColor;\n\nfloat getUvFrame(vec2 uv) {\n vec2 invAA = .5 / clamp(fwidth(uv), 1e-5, .02);\n vec2 lo = clamp(uv * invAA + .5, 0., 1.);\n vec2 hi = clamp((1. - uv) * invAA + .5, 0., 1.);\n return lo.x * hi.x * lo.y * hi.y;\n}\n\nfloat lst(float edge0, float edge1, float x) {\n return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);\n}\n\n${declarePI}\n${proceduralHash21}\n${proceduralHash22}\n\nfloat getRoughness(vec2 p, vec2 lightDir, vec2 seedShift, float basePixel) {\n vec2 u = p / vec2(2, 4);\n float w = 100. * basePixel;\n float eps = 4. * w;\n\n float size = mix(3.2, .8, u_roughnessSize);\n float logLac = log2(2.1);\n float level = -log2(w + 1e-8) / logLac;\n float baseLevel = floor(level) - 2.;\n float fade = fract(level);\n\n vec2 px = (u.x + vec2(eps, -eps)) * .1;\n float py = u.y * .1;\n\n vec2 sum = vec2(0.);\n float norm = 0., amp = .5;\n float freq = exp2(baseLevel * logLac);\n for (int i = 0; i < 4; i++) {\n float absIdx = baseLevel + float(i);\n vec2 qx = size * px * freq;\n float qy = size * py * freq;\n\n float wi = 1.;\n if (i == 0) wi = 1. - fade;\n if (i == 3) wi = fade;\n\n vec2 fx = fract(qx);\n float fy = fract(qy);\n vec2 shift = .5 + absIdx * .3 + seedShift;\n float uvY = floor(qy) / 50. + shift.y;\n vec2 s0a = textureLod(u_noiseTexture, fract(vec2(floor(qx.x) / 50. + shift.x, uvY)), 0.).rg;\n vec2 s1a = textureLod(u_noiseTexture, fract(vec2( ceil(qx.x) / 50. + shift.x, uvY)), 0.).rg;\n vec2 s0b = textureLod(u_noiseTexture, fract(vec2(floor(qx.y) / 50. + shift.x, uvY)), 0.).rg;\n vec2 s1b = textureLod(u_noiseTexture, fract(vec2( ceil(qx.y) / 50. + shift.x, uvY)), 0.).rg;\n vec2 ny0 = mix(vec2(s0a.r, s0b.r), vec2(s0a.g, s0b.g), fy);\n vec2 ny1 = mix(vec2(s1a.r, s1b.r), vec2(s1a.g, s1b.g), fy);\n vec2 n = mix(ny0, ny1, fx);\n\n sum += amp * wi * n;\n norm += amp * wi;\n amp *= .8;\n freq *= 2.1;\n }\n\n vec2 r = sum / norm;\n float dx = .5 + r.x - r.y;\n float grain = 3. * dx * dx - .7;\n\n float rowBand = fract(dot(p, lightDir) * .05 * size);\n return grain + .6 * u_roughnessRows * (rowBand - .5);\n}\n\nfloat getFiber(vec2 p, vec2 seedShift, float basePixel) {\n float size = mix(4., 1., u_fiberSize);\n float w = 50. * basePixel;\n float level = -log2(w + 1e-8);\n float baseLevel = floor(level) - 3.;\n float fade = fract(level);\n\n vec2 grad = vec2(0.);\n float scale = 1.;\n float amp = 1.;\n float freq = pow(1.7, baseLevel);\n for (int i = 0; i < 5; i++) {\n float absIdx = baseLevel + float(i);\n vec2 q = size * p * freq;\n\n float an = absIdx * .8;\n float rc = cos(an), rs = sin(an);\n q = vec2(rc * q.x - rs * q.y, rs * q.x + rc * q.y);\n\n float wi = 1.;\n if (i == 0) wi = 1. - fade;\n if (i == 4) wi = fade;\n\n vec2 iq = floor(q);\n vec2 fq = fract(q);\n float shift = absIdx * .3;\n vec4 uv = fract(vec4(iq, iq + 1.) / 50. + .5 + shift + seedShift.xyxy);\n float aF = textureLod(u_noiseTexture, uv.xy, 0.).b;\n float bF = textureLod(u_noiseTexture, uv.zy, 0.).b;\n float cF = textureLod(u_noiseTexture, uv.xw, 0.).b;\n float dF = textureLod(u_noiseTexture, uv.zw, 0.).b;\n vec2 u = fq * fq * (3. - 2. * fq);\n vec2 du = 8. * fq * (1. - fq);\n float dx = du.x * mix(bF - aF, dF - cF, u.y);\n float dy = du.y * mix(cF - aF, dF - bF, u.x);\n grad += wi * amp * scale * vec2(rc * dx + rs * dy, -rs * dx + rc * dy);\n scale *= 1.7;\n amp *= .5;\n freq *= 1.7;\n }\n\n return clamp(.333 * length(grad), 0., 1.);\n}\n\nvec2 smoothNoise(vec2 p) {\n vec2 t = p * 50. - .5;\n vec2 i = floor(t);\n vec2 f = fract(t);\n f = f * f * (3. - 2. * f);\n return textureLod(u_noiseTexture, fract((i + f + .5) / vec2(50.)), 0.).rg;\n}\n\nfloat getDrops(vec2 uv, vec2 seedShift) {\n vec2 iDropsUV = floor(uv);\n vec2 fDropsUV = fract(uv);\n float dropsMinDist = 1.;\n for (int y = -1; y < 2; y += 1) {\n for (int x = -1; x < 2; x += 1) {\n vec2 neighbor = vec2(float(y), float(x));\n vec2 offset = hash22(iDropsUV + neighbor + 50. * seedShift);\n vec2 pos = neighbor + offset - fDropsUV;\n dropsMinDist *= min(1., dot(pos, pos));\n }\n }\n return .5 * lst(.09, .08, sqrt(sqrt(dropsMinDist)));\n}\n\nvec2 getCellTilt(float idx, float radius) {\n vec2 rand = hash22(vec2(idx + 31., idx * u_seed + 17.));\n float an = rand.x * TWO_PI;\n return vec2(cos(an), sin(an)) * mix(.3, 1.7, rand.y * rand.y) * mix(.7, 1., radius);\n}\n\nvec2 getCrumpleDetail(vec2 uv, float freq, float shift, float basePixel, out float depth) {\n depth = 0.;\n vec2 v = uv * freq;\n float pixel = .9 * freq * basePixel;\n vec2 base = floor(v);\n float n1 = 9., n2 = 9.;\n vec2 s1 = vec2(0.), s2 = vec2(0.), q1 = vec2(0.), q2 = vec2(0.);\n\n for (int y = -1; y <= 1; y++) {\n for (int x = -1; x <= 1; x++) {\n vec2 cell = base + vec2(float(x), float(y));\n vec2 q = hash22(vec2(cell.y * 1.9 + 3.1 + shift, cell.x * 1.3 + .11 * u_seed));\n float keep = .8;\n if (q.y > keep) continue;\n\n vec2 r = hash22(vec2(cell.x + .37 * u_seed + shift + 11.1, cell.y - .21 * u_seed + 5.7));\n vec2 s = cell + .06 + .88 * r;\n\n vec2 d = v - s;\n float dsq = dot(d, d);\n if (dsq < n1) {\n n2 = n1;\n s2 = s1;\n q2 = q1;\n n1 = dsq;\n s1 = s;\n q1 = q;\n } else if (dsq < n2) {\n n2 = dsq;\n s2 = s;\n q2 = q;\n }\n }\n }\n\n if (n1 > 8.) return vec2(0.);\n\n float an1 = q1.x * TWO_PI, mag1 = q1.y / .8;\n vec2 t1 = vec2(cos(an1), sin(an1)) * mix(.3, 1.7, mag1 * mag1);\n float an2 = q2.x * TWO_PI, mag2 = q2.y / .8;\n vec2 t2 = vec2(cos(an2), sin(an2)) * mix(.3, 1.7, mag2 * mag2);\n\n vec2 span = s1 - s2;\n float spanLen = max(length(span), 1e-4);\n float toEdge = (n2 - n1) / (2. * spanLen);\n\n float pair = hash21(s1 + s2 + 1.7 * abs(s1 - s2));\n float pairSoft = .05 + .1 * step(pair, .4);\n float b = clamp(toEdge / max(1.5 * pixel, .5 * pairSoft), 0., 1.);\n b = b * b * (3. - 2. * b);\n float d1 = max(sqrt(n1), 1e-4);\n depth = .2 * d1;\n float shoulderAmt = max(0., 1. - toEdge / .42) * b;\n vec2 shoulder = vec2(0.);\n if (shoulderAmt > 0.) {\n float d2 = max(sqrt(n2), 1e-4);\n shoulder = shoulderAmt * ((v - s2) / d2 - (v - s1) / d1);\n }\n\n vec2 mid = .5 * (t1 + t2);\n return mid + (t1 - mid) * b + .9 * shoulder;\n}\n\nvec4 getCrumples(vec2 uv) {\n float crumpleN = max(2., floor(u_crumpleCount + .5));\n float near = 60000., nearB = 60000.;\n float idx = 0., rad = 0.;\n vec2 nearP = vec2(0.), nearPb = vec2(0.);\n vec4 seeds[${paperTextureMeta.maxCrumpleCount}];\n for (int i = 0; i < ${paperTextureMeta.maxCrumpleCount}; i++) {\n if (float(i) >= crumpleN) break;\n vec2 rand = hash22(vec2(float(i), float(i) * u_seed));\n float an = rand.x * TWO_PI;\n vec2 p = vec2(cos(an), sin(an)) * rand.y;\n seeds[i] = vec4(p, rand);\n\n vec2 d = uv - p;\n float dsq = dot(d, d);\n if (dsq < near) {\n nearB = near;\n nearPb = nearP;\n near = dsq;\n idx = float(i);\n rad = rand.y;\n nearP = p;\n } else if (dsq < nearB) {\n nearB = dsq;\n nearPb = p;\n }\n }\n float l = sqrt(near), lb = sqrt(nearB);\n vec2 dir = (uv - nearP) / max(l, 1e-4);\n float edge = lst(0., .5, lb - l);\n\n float shoulderLimit = l + .5;\n\n vec2 tilt = getCellTilt(idx, rad);\n float tiltSum = 1.;\n vec2 wide = vec2(0.);\n float wideSum = 0.;\n float toEdge = 9., edgeSoft = 0.;\n\n for (int i = 0; i < ${paperTextureMeta.maxCrumpleCount}; i++) {\n if (float(i) >= crumpleN) break;\n if (float(i) == idx) continue;\n vec4 seed = seeds[i];\n vec2 p = seed.xy;\n vec2 rand = seed.zw;\n\n vec2 d = uv - p;\n float dsq = dot(d, d);\n\n if (dsq < shoulderLimit * shoulderLimit) {\n float di = sqrt(dsq);\n float shoulder = lst(.5, 0., di - l);\n wide += shoulder * (d / max(di, 1e-4) - dir);\n wideSum += shoulder;\n }\n\n float pairSoft = .01 + .05 * step(.2, rand.x) + .3 * rand.y;\n float toBisector = (dsq - near) / (.2 * max(length(p - nearP), 1e-4));\n if (toBisector < toEdge) {\n toEdge = toBisector;\n edgeSoft = pairSoft;\n }\n\n float w = 1. - toBisector / pairSoft;\n if (w > 0.) {\n w *= w;\n tilt += w * getCellTilt(float(i), rand.y);\n tiltSum += w;\n }\n }\n\n float blend = clamp(toEdge / edgeSoft, 0., 1.);\n vec2 sharp = (1. - edge) * ((uv - nearPb) / max(lb, 1e-4) - dir);\n vec2 rounding = mix(sharp, wide / max(wideSum, 1.), min(2. * edgeSoft, 1.));\n float radial = l / max(l + toEdge, 1e-4);\n\n return vec4(tilt / tiltSum + rounding * blend * radial, .2 * l, edge);\n}\n\nvoid getFolds(vec2 coord, vec2 offset, vec2 count, vec2 noise, vec2 baseFwidth, out vec2 slope, out vec2 dark, out vec2 lift) {\n vec2 g = coord * count + .5 * offset + noise;\n vec2 dx = fract(g) - .5;\n vec2 adx = abs(dx);\n float foldRadius = .3;\n vec2 t = clamp(adx / foldRadius, 0., 1.);\n dark = t * t * (3. - 2. * t);\n lift = 1. - t;\n lift *= lift;\n\n vec2 crease = clamp(dx / max(count * baseFwidth, 1e-5), -1., 1.);\n slope = crease * (1. - dark);\n\n vec2 lineWidth = .02 * count * mix(vec2(2.5), vec2(.8), dark.yx) + .1 * noise;\n slope -= 1. - smoothstep(vec2(0.), lineWidth, adx);\n}\n\nvoid main() {\n\n vec2 surfaceOrigin = u_imageIsHtml == 1. ? vec2(u_originX, u_originY) : vec2(.5);\n vec2 patternUV = (v_imageUV - surfaceOrigin) * vec2(u_imageAspectRatio, 1.);\n vec2 surfaceUV = patternUV;\n if (u_imageIsHtml == 1.) {\n surfaceUV *= u_resolution.y / u_pixelRatio / 1000.;\n }\n float basePixel = max(length(dFdx(surfaceUV)), length(dFdy(surfaceUV)));\n vec2 baseFwidth = fwidth(patternUV);\n\n float pattern = 0.;\n\n float crumpleDepth = 0.;\n float wrinkleDepth = 0.;\n float foldDepth = 0.;\n float roughness = 0.;\n float fiber = 0.;\n float drops = 0.;\n\n float grazing = 0.7;\n float lightRad = radians(u_angle);\n vec2 lightDir = vec2(sin(lightRad), -cos(lightRad));\n float foldAngleInSector = mod(u_angle, 90.);\n float foldLightRad = radians(u_angle - foldAngleInSector + mix(12., 78., foldAngleInSector / 90.));\n vec2 foldLightDir = vec2(sin(foldLightRad), -cos(foldLightRad));\n vec2 relief = vec2(0.);\n vec2 foldSlope = vec2(0.);\n float reliefAmount = 0.;\n float foldInk = 1.;\n vec2 crumpleFlow = vec2(0.);\n\n vec2 warpNoise = vec2(0.);\n if (u_crumples > 0. || u_folds > 0. || u_wrinkles > 0.) {\n warpNoise = smoothNoise(surfaceUV * .1 + .2 + .6 * fract(.017 * u_seed)) - .5;\n }\n vec2 crumplesUV = (surfaceUV * .9) + .012 * warpNoise;\n\n if (u_crumples > 0.) {\n vec4 crumples = getCrumples(crumplesUV);\n\n vec2 crumpleTilt = .5 * u_crumples * crumples.xy;\n crumpleTilt -= .1 * max(dot(crumpleTilt, lightDir), 0.) * lightDir;\n relief += crumpleTilt;\n reliefAmount += .6 * u_crumples;\n crumpleFlow = crumples.w * crumpleTilt;\n\n crumpleDepth = clamp(5. * crumples.z, 0., 1.);\n }\n\n if (u_wrinkles > 0.) {\n float detailFreq = mix(10., 1., u_wrinkleSize);\n if (u_imageIsHtml == 1.) {\n detailFreq *= mix(4., 1., smoothstep(0., .5, u_wrinkleSize));\n }\n float detailAmp = .2;\n vec2 detailGrad = vec2(0.);\n float detailDepth = 0., depthSum = 0.;\n for (int i = 0; i < 3; i++) {\n float layerDepth;\n detailGrad += detailAmp * getCrumpleDetail(crumplesUV, detailFreq, 31. * float(i), basePixel, layerDepth);\n detailDepth += detailAmp * layerDepth;\n depthSum += detailAmp;\n detailAmp *= (.5 + .2 * detailGrad.x);\n detailFreq *= 2.1;\n }\n\n vec2 detailTilt = 1.5 * u_wrinkles * detailGrad;\n detailTilt -= .65 * max(dot(detailTilt, lightDir), 0.) * lightDir;\n relief += detailTilt;\n reliefAmount += .6 * u_wrinkles;\n\n wrinkleDepth = clamp(5. * detailDepth / max(depthSum, 1e-4), 0., 1.);\n }\n\n if (u_folds > 0.) {\n vec2 foldOffset = vec2(1. - 2. * u_foldOffsetX, 1. - 2. * u_foldOffsetY);\n vec2 foldCount = vec2(mix(3., .5, u_foldSizeX), mix(3., .5, u_foldSizeY));\n vec2 foldNoise = .005 * warpNoise * foldCount;\n vec2 uv = patternUV + .03 * crumpleFlow;\n\n vec2 slope, dark, lift;\n getFolds(uv, foldOffset, foldCount, foldNoise, baseFwidth, slope, dark, lift);\n\n foldSlope = u_folds * slope;\n reliefAmount += 1. * u_folds;\n vec2 ink = mix(vec2(.96), vec2(1.), dark);\n float flatness = dark.x * dark.y;\n foldInk *= mix(1., ink.x * ink.y * mix(.5, .3, flatness), u_folds);\n\n foldDepth = u_folds * (lift.y * foldLightDir.y - lift.x * foldLightDir.x);\n }\n\n float unlit = cos(grazing);\n float lit = unlit;\n\n if (reliefAmount > 0.) {\n float lightFalloff = clamp(.5 + dot(v_imageUV - .5, lightDir), 0., 1.);\n float lightPower = mix(.5, 1., lightFalloff);\n float slope = clamp(dot(relief, lightDir) + dot(foldSlope, foldLightDir), -1.2, 1.2);\n lit = max(cos(slope + grazing), 0.);\n\n pattern += (clamp(reliefAmount, 0., 1.) * unlit + (lit - unlit)) * foldInk * lightPower;\n }\n\n surfaceUV += .04 * crumpleFlow;\n\n vec2 seedShift = floor(fract(u_seed * vec2(.7548776662, .5698402909)) * 50.) / 50.;\n\n if (u_roughness > 0.) {\n roughness = u_roughness * getRoughness(1000. * surfaceUV, lightDir, seedShift, basePixel);\n pattern += roughness;\n }\n\n if (u_fiber > 0.) {\n fiber = u_fiber * getFiber(50. * surfaceUV, seedShift, basePixel);\n pattern += fiber;\n }\n\n if (u_drops > 0.) {\n drops = u_drops * getDrops(surfaceUV * 10., seedShift);\n }\n\n pattern = clamp(pattern, 0., 1.);\n\n vec3 backColor = u_colorBack.rgb * u_colorBack.a;\n float backOpacity = u_colorBack.a;\n vec3 baseColor = u_colorPaper.rgb * u_colorPaper.a;\n float baseOpacity = u_colorPaper.a;\n vec3 shadowColor = u_colorShadow.rgb * u_colorShadow.a;\n float shadowOpacity = u_colorShadow.a;\n\n float notClipped = u_clip ? .1 : 1.;\n vec2 imageCenteredUV = v_imageUV - .5;\n float edgeDist = 2. * max(abs(imageCenteredUV.x), abs(imageCenteredUV.y));\n float wrinkleDistortion = mix(.38, .0175, smoothstep(0., 1., edgeDist));\n float scaleDistortion = .15 * u_crumples * (crumpleDepth - .5) + wrinkleDistortion * u_wrinkles * (wrinkleDepth - .5) + .05 * foldDepth;\n vec2 linearDistortion = notClipped * .002 * lightDir * drops;\n float radialDistortion = notClipped * .02 * (roughness + fiber);\n vec2 centeredUV = imageCenteredUV * (1. - u_distortion * scaleDistortion);\n centeredUV -= u_distortion * linearDistortion;\n vec2 imageUV = .5 + centeredUV * (1. - abs(u_distortion) * radialDistortion * dot(centeredUV, centeredUV));\n\n vec3 color = shadowColor * pattern;\n float opacity = shadowOpacity * pattern;\n color += baseColor * (1. - opacity);\n opacity += baseOpacity * (1. - opacity);\n\n if (u_isImage || u_imageIsHtml == 1.) {\n float frame = getUvFrame(imageUV);\n vec4 image = texture(u_image, imageUV);\n image.rgb /= max(image.a, .0001);\n frame *= image.a;\n\n float maxC = max(max(image.r, image.g), image.b);\n float minC = min(min(image.r, image.g), image.b);\n float sat = maxC > 0. ? (maxC - minC) / maxC : 0.;\n float midC = image.r + image.g + image.b - maxC - minC;\n float secondaryness = maxC > minC ? (midC - minC) / (maxC - minC) : 0.;\n float satDampen = sat * (1. - .5 * secondaryness);\n float darkDampen = 1. - dot(vec3(.2126, .7152, .0722), image.rgb);\n float dampen = mix(0., .7, u_blending) * max(satDampen, darkDampen);\n\n vec3 paper = vec3(1.) - opacity + color;\n vec3 pic = image.rgb * paper * u_blending + image.rgb * (1. - u_blending);\n pic = mix(pic, vec3(1.), .6 * pow(dampen, 2. + 3. * pattern));\n\n color = mix(color, pic, frame);\n opacity = frame + opacity * (1. - frame);\n\n if (u_clip) {\n color *= frame;\n opacity *= frame;\n }\n }\n\n color *= mix(vec3(1.), .5 * u_colorShadow.rgb, drops * shadowOpacity);\n\n color += backColor * (1. - opacity);\n opacity += backOpacity * (1. - opacity);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface PaperTextureUniforms extends ShaderSizingUniforms {\n u_image: HTMLImageElement | string | undefined;\n u_isImage: boolean;\n u_colorBack: [number, number, number, number];\n u_colorPaper: [number, number, number, number];\n u_colorShadow: [number, number, number, number];\n u_blending: number;\n u_distortion: number;\n u_clip: boolean;\n u_angle: number;\n u_seed: number;\n u_roughness: number;\n u_roughnessSize: number;\n u_roughnessRows: number;\n u_fiber: number;\n u_fiberSize: number;\n u_folds: number;\n u_foldSizeX: number;\n u_foldSizeY: number;\n u_foldOffsetX: number;\n u_foldOffsetY: number;\n u_wrinkles: number;\n u_wrinkleSize: number;\n u_crumples: number;\n u_crumpleCount: number;\n u_drops: number;\n u_noiseTexture?: HTMLImageElement;\n}\nexport interface PaperTextureParams extends ShaderSizingParams, ShaderMotionParams {\n image?: HTMLImageElement | string;\n colorBack?: string;\n colorPaper?: string;\n colorShadow?: string;\n blending?: number;\n distortion?: number;\n clip?: boolean;\n angle?: number;\n seed?: number;\n roughness?: number;\n roughnessSize?: number;\n roughnessRows?: number;\n fiber?: number;\n fiberSize?: number;\n folds?: number;\n foldSizeX?: number;\n foldSizeY?: number;\n foldOffsetX?: number;\n foldOffsetY?: number;\n wrinkles?: number;\n wrinkleSize?: number;\n crumples?: number;\n crumpleCount?: number;\n drops?: number;\n}\n"],
5
+ "mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,kBAAkB,wBAAwB;AAEvD,MAAM,mBAAmB;AAAA,EAC9B,iBAAiB;AACnB;AAyDO,MAAM,6BAAqC;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;AAAA;AAAA;AAAA;AAAA,EAsDhD,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,gBAAgB;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;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;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;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,eAmMH,iBAAiB,eAAe;AAAA,wBACvB,iBAAiB,eAAe;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,wBAiChC,iBAAiB,eAAe;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;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;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;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;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;",
6
6
  "names": []
7
7
  }
@@ -85,8 +85,7 @@ void main() {
85
85
  vec4 voronoiRes = voronoi(shape_uv, t);
86
86
 
87
87
  float shape = clamp(voronoiRes.w, 0., 1.);
88
- float mixer = shape * (u_colorsCount - 1.);
89
- mixer = (shape - .5 / u_colorsCount) * u_colorsCount;
88
+ float mixer = (shape - .5 / u_colorsCount) * u_colorsCount;
90
89
  float steps = max(1., u_stepsPerColor);
91
90
 
92
91
  vec4 gradient = u_colors[0];
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/shaders/voronoi.ts"],
4
- "sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, textureRandomizerGB } from '../shader-utils.js';\n\nexport const voronoiMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Anti-aliased animated Voronoi pattern with smooth and customizable edges.\n *\n * Double-pass Voronoi pattern cell edges.\n * Original algorithm: https://www.shadertoy.com/view/ldl3W8\n *\n * Note: gaps can't be removed completely due to natural artifacts of Voronoi cells borders\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_scale (float): Overall zoom level, used for anti-aliasing calculations\n * - u_colors (vec4[]): Up to 5 base cell colors in RGBA\n * - u_colorsCount (float): Number of active colors\n * - u_stepsPerColor (float): Number of extra colors between base colors, 1 = N colors, 2 = 2\u00D7N, etc., needs 2+ colors (1 to 3)\n * - u_colorGlow (vec4): Color tint for radial inner shadow inside cells in RGBA, needs glow > 0\n * - u_colorGap (vec4): Color used for cell borders/gaps in RGBA\n * - u_distortion (float): Strength of noise-driven displacement of cell centers (0 to 0.5)\n * - u_gap (float): Width of the border/gap between cells (0 to 0.1)\n * - u_glow (float): Strength of the radial inner shadow inside cells, needs colorGlow alpha > 0 (0 to 1)\n * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_patternUV (vec2): UV coordinates for pattern with global sizing (rotation, scale, offset, etc) applied\n *\n * Vertex shader uniforms:\n * - u_resolution (vec2): Canvas resolution in pixels\n * - u_pixelRatio (float): Device pixel ratio\n * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)\n * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)\n * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas\n * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas\n * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)\n * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)\n * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)\n * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)\n *\n */\n\n// language=GLSL\nexport const voronoiFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${ voronoiMeta.maxColorCount }];\nuniform float u_colorsCount;\n\nuniform float u_stepsPerColor;\nuniform vec4 u_colorGlow;\nuniform vec4 u_colorGap;\nuniform float u_distortion;\nuniform float u_gap;\nuniform float u_glow;\n\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n${ textureRandomizerGB }\n\nvec4 voronoi(vec2 x, float t) {\n vec2 ip = floor(x);\n vec2 fp = fract(x);\n\n vec2 mg, mr;\n float md = 8.;\n float rand = 0.;\n\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n vec2 g = vec2(float(i), float(j));\n vec2 o = randomGB(ip + g);\n float raw_hash = o.x;\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n float d = dot(r, r);\n\n if (d < md) {\n md = d;\n mr = r;\n mg = g;\n rand = raw_hash;\n }\n }\n }\n\n md = 8.;\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n vec2 g = mg + vec2(float(i), float(j));\n vec2 o = randomGB(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n if (dot(mr - r, mr - r) > .00001) {\n md = min(md, dot(.5 * (mr + r), normalize(r - mr)));\n }\n }\n }\n\n return vec4(md, mr, rand);\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= 1.25;\n\n float t = u_time;\n\n vec4 voronoiRes = voronoi(shape_uv, t);\n\n float shape = clamp(voronoiRes.w, 0., 1.);\n float mixer = shape * (u_colorsCount - 1.);\n mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\n float steps = max(1., u_stepsPerColor);\n\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${ voronoiMeta.maxColorCount }; i++) {\n if (i >= int(u_colorsCount)) break;\n float localT = clamp(mixer - float(i - 1), 0.0, 1.0);\n localT = round(localT * steps) / steps;\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {\n float localT = mixer + 1.;\n if (mixer > (u_colorsCount - 1.)) {\n localT = mixer - (u_colorsCount - 1.);\n }\n localT = round(localT * steps) / steps;\n vec4 cFst = u_colors[0];\n cFst.rgb *= cFst.a;\n vec4 cLast = u_colors[int(u_colorsCount - 1.)];\n cLast.rgb *= cLast.a;\n gradient = mix(cLast, cFst, localT);\n }\n\n vec3 cellColor = gradient.rgb;\n float cellOpacity = gradient.a;\n\n float glows = length(voronoiRes.yz * u_glow);\n glows = pow(glows, 1.5);\n\n vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * glows);\n float opacity = cellOpacity + u_colorGlow.a * glows;\n\n float edge = voronoiRes.x;\n float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);\n edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);\n\n color = mix(u_colorGap.rgb * u_colorGap.a, color, edge);\n opacity = mix(u_colorGap.a, opacity, edge);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface VoronoiUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_stepsPerColor: number;\n u_colorGap: [number, number, number, number];\n u_colorGlow: [number, number, number, number];\n u_distortion: number;\n u_gap: number;\n u_glow: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n stepsPerColor?: number;\n colorGap?: string;\n colorGlow?: string;\n distortion?: number;\n gap?: number;\n glow?: number;\n}\n"],
5
- "mappings": ";;;;;AAEA,eAAmE;AACnE,SAAS,WAAW,2BAA2B;AAExC,MAAM,cAAc;AAAA,EACzB,eAAe;AACjB;AA0CO,MAAM,wBAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBASpB,YAAY,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAchD,SAAU;AAAA,EACV,mBAAoB;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBA2DE,YAAY,aAAc;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;",
4
+ "sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, textureRandomizerGB } from '../shader-utils.js';\n\nexport const voronoiMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Anti-aliased animated Voronoi pattern with smooth and customizable edges.\n *\n * Double-pass Voronoi pattern cell edges.\n * Original algorithm: https://www.shadertoy.com/view/ldl3W8\n *\n * Note: gaps can't be removed completely due to natural artifacts of Voronoi cells borders\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_scale (float): Overall zoom level, used for anti-aliasing calculations\n * - u_colors (vec4[]): Up to 5 base cell colors in RGBA\n * - u_colorsCount (float): Number of active colors\n * - u_stepsPerColor (float): Number of extra colors between base colors, 1 = N colors, 2 = 2\u00D7N, etc., needs 2+ colors (1 to 3)\n * - u_colorGlow (vec4): Color tint for radial inner shadow inside cells in RGBA, needs glow > 0\n * - u_colorGap (vec4): Color used for cell borders/gaps in RGBA\n * - u_distortion (float): Strength of noise-driven displacement of cell centers (0 to 0.5)\n * - u_gap (float): Width of the border/gap between cells (0 to 0.1)\n * - u_glow (float): Strength of the radial inner shadow inside cells, needs colorGlow alpha > 0 (0 to 1)\n * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_patternUV (vec2): UV coordinates for pattern with global sizing (rotation, scale, offset, etc) applied\n *\n * Vertex shader uniforms:\n * - u_resolution (vec2): Canvas resolution in pixels\n * - u_pixelRatio (float): Device pixel ratio\n * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)\n * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)\n * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas\n * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas\n * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)\n * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)\n * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)\n * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)\n *\n */\n\n// language=GLSL\nexport const voronoiFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${ voronoiMeta.maxColorCount }];\nuniform float u_colorsCount;\n\nuniform float u_stepsPerColor;\nuniform vec4 u_colorGlow;\nuniform vec4 u_colorGap;\nuniform float u_distortion;\nuniform float u_gap;\nuniform float u_glow;\n\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n${ textureRandomizerGB }\n\nvec4 voronoi(vec2 x, float t) {\n vec2 ip = floor(x);\n vec2 fp = fract(x);\n\n vec2 mg, mr;\n float md = 8.;\n float rand = 0.;\n\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n vec2 g = vec2(float(i), float(j));\n vec2 o = randomGB(ip + g);\n float raw_hash = o.x;\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n float d = dot(r, r);\n\n if (d < md) {\n md = d;\n mr = r;\n mg = g;\n rand = raw_hash;\n }\n }\n }\n\n md = 8.;\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n vec2 g = mg + vec2(float(i), float(j));\n vec2 o = randomGB(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n if (dot(mr - r, mr - r) > .00001) {\n md = min(md, dot(.5 * (mr + r), normalize(r - mr)));\n }\n }\n }\n\n return vec4(md, mr, rand);\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= 1.25;\n\n float t = u_time;\n\n vec4 voronoiRes = voronoi(shape_uv, t);\n\n float shape = clamp(voronoiRes.w, 0., 1.);\n float mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\n float steps = max(1., u_stepsPerColor);\n\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${ voronoiMeta.maxColorCount }; i++) {\n if (i >= int(u_colorsCount)) break;\n float localT = clamp(mixer - float(i - 1), 0.0, 1.0);\n localT = round(localT * steps) / steps;\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {\n float localT = mixer + 1.;\n if (mixer > (u_colorsCount - 1.)) {\n localT = mixer - (u_colorsCount - 1.);\n }\n localT = round(localT * steps) / steps;\n vec4 cFst = u_colors[0];\n cFst.rgb *= cFst.a;\n vec4 cLast = u_colors[int(u_colorsCount - 1.)];\n cLast.rgb *= cLast.a;\n gradient = mix(cLast, cFst, localT);\n }\n\n vec3 cellColor = gradient.rgb;\n float cellOpacity = gradient.a;\n\n float glows = length(voronoiRes.yz * u_glow);\n glows = pow(glows, 1.5);\n\n vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * glows);\n float opacity = cellOpacity + u_colorGlow.a * glows;\n\n float edge = voronoiRes.x;\n float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);\n edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);\n\n color = mix(u_colorGap.rgb * u_colorGap.a, color, edge);\n opacity = mix(u_colorGap.a, opacity, edge);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface VoronoiUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_stepsPerColor: number;\n u_colorGap: [number, number, number, number];\n u_colorGlow: [number, number, number, number];\n u_distortion: number;\n u_gap: number;\n u_glow: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n stepsPerColor?: number;\n colorGap?: string;\n colorGlow?: string;\n distortion?: number;\n gap?: number;\n glow?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,eAAmE;AACnE,SAAS,WAAW,2BAA2B;AAExC,MAAM,cAAc;AAAA,EACzB,eAAe;AACjB;AA0CO,MAAM,wBAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBASpB,YAAY,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAchD,SAAU;AAAA,EACV,mBAAoB;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBA0DE,YAAY,aAAc;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;",
6
6
  "names": []
7
7
  }
@@ -5,8 +5,10 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
5
5
  *
6
6
  * Fragment shader uniforms:
7
7
  * - u_time (float): Animation time
8
- * - u_image (sampler2D): Optional source image texture
8
+ * - u_image (sampler2D): Optional source image texture, premultiplied alpha
9
9
  * - u_imageAspectRatio (float): Aspect ratio of the source image
10
+ * - u_imageIsHtml (float): 1 when u_image is HTML. HTML is drawn 1:1, so the ripples and their distortion don't scale with the
11
+ * canvas. They're anchored at originX / originY instead of the center, 0 0 being the top left like CSS
10
12
  * - u_colorBack (vec4): Background color in RGBA
11
13
  * - u_colorHighlight (vec4): Highlight color in RGBA, needs highlights > 0
12
14
  * - u_highlights (float): Coloring added over image/background following caustic shape, needs colorHighlight alpha > 0 (0 to 1)
@@ -14,7 +16,7 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
14
16
  * - u_edges (float): Caustic distortion power on the image edges, needs image and caustic > 0 (0 to 1)
15
17
  * - u_waves (float): Additional distortion based on simplex noise, independent from caustic (0 to 1)
16
18
  * - u_caustic (float): Power of caustic distortion, needs image (0 to 1)
17
- * - u_size (float): Pattern scale relative to the image (0.01 to 7)
19
+ * - u_size (float): Pattern scale (0.01 to 7)
18
20
  *
19
21
  * Vertex shader outputs (used in fragment shader):
20
22
  * - v_imageUV (vec2): UV coordinates for sampling the source image, with fit, scale, rotation, and offset applied
@@ -15,6 +15,11 @@ uniform vec4 u_colorHighlight;
15
15
 
16
16
  uniform sampler2D u_image;
17
17
  uniform float u_imageAspectRatio;
18
+ uniform float u_imageIsHtml;
19
+ uniform vec2 u_resolution;
20
+ uniform float u_pixelRatio;
21
+ uniform float u_originX;
22
+ uniform float u_originY;
18
23
 
19
24
  uniform float u_size;
20
25
  uniform float u_highlights;
@@ -28,6 +33,9 @@ in vec2 v_imageUV;
28
33
  out vec4 fragColor;
29
34
 
30
35
  ${declarePI}
36
+ float sizeToPx(float size) {
37
+ return 1000. * (.002 + .07 * size);
38
+ }
31
39
  ${rotation2}
32
40
  ${simplexNoise}
33
41
 
@@ -64,9 +72,18 @@ float getCausticNoise(vec2 uv, float t, float scale) {
64
72
 
65
73
  void main() {
66
74
  vec2 imageUV = v_imageUV;
67
- vec2 patternUV = v_imageUV - .5;
68
- patternUV = (patternUV * vec2(u_imageAspectRatio, 1.));
69
- patternUV /= (.01 + .09 * u_size);
75
+ vec2 htmlScale = vec2(1.);
76
+ vec2 patternUV = v_imageUV;
77
+ if (u_imageIsHtml == 1.) {
78
+ htmlScale = u_resolution / u_pixelRatio / 1000.;
79
+ patternUV -= vec2(u_originX, u_originY);
80
+ patternUV *= vec2(u_imageAspectRatio, 1.);
81
+ patternUV /= sizeToPx(u_size) / (u_resolution.y / u_pixelRatio);
82
+ } else {
83
+ patternUV -= .5;
84
+ patternUV = (patternUV * vec2(u_imageAspectRatio, 1.));
85
+ patternUV /= (.01 + .09 * u_size);
86
+ }
70
87
 
71
88
  float t = u_time;
72
89
 
@@ -89,8 +106,8 @@ void main() {
89
106
 
90
107
  float wavesDistortion = .1 * u_waves * wavesNoise;
91
108
 
92
- imageUV += vec2(wavesDistortion, -wavesDistortion);
93
- imageUV += (u_caustic * causticNoiseDistortion);
109
+ imageUV += vec2(wavesDistortion, -wavesDistortion) / htmlScale;
110
+ imageUV += (u_caustic * causticNoiseDistortion) / htmlScale;
94
111
 
95
112
  float frame = getUvFrame(imageUV);
96
113
 
@@ -98,11 +115,9 @@ void main() {
98
115
  vec4 backColor = u_colorBack;
99
116
  backColor.rgb *= backColor.a;
100
117
 
101
- vec3 color = mix(backColor.rgb, image.rgb, image.a * frame);
118
+ vec3 color = backColor.rgb * (1. - image.a * frame) + image.rgb * frame;
102
119
  float opacity = backColor.a + image.a * frame;
103
120
 
104
- causticNoise = max(-.2, causticNoise);
105
-
106
121
  float hightlight = .025 * u_highlights * causticNoise;
107
122
  hightlight *= u_colorHighlight.a;
108
123
  color = mix(color, u_colorHighlight.rgb, .05 * u_highlights * causticNoise * u_colorHighlight.a);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/shaders/water.ts"],
4
- "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, rotation2, simplexNoise } from '../shader-utils.js';\n\n/**\n * Water-like surface distortion with natural caustic realism. Works as an image filter or standalone animated texture.\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_image (sampler2D): Optional source image texture\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n * - u_colorBack (vec4): Background color in RGBA\n * - u_colorHighlight (vec4): Highlight color in RGBA, needs highlights > 0\n * - u_highlights (float): Coloring added over image/background following caustic shape, needs colorHighlight alpha > 0 (0 to 1)\n * - u_layering (float): Power of 2nd layer of caustic distortion, needs caustic or highlights > 0 (0 to 1)\n * - u_edges (float): Caustic distortion power on the image edges, needs image and caustic > 0 (0 to 1)\n * - u_waves (float): Additional distortion based on simplex noise, independent from caustic (0 to 1)\n * - u_caustic (float): Power of caustic distortion, needs image (0 to 1)\n * - u_size (float): Pattern scale relative to the image (0.01 to 7)\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_imageUV (vec2): UV coordinates for sampling the source image, with fit, scale, rotation, and offset applied\n *\n * Vertex shader uniforms:\n * - u_resolution (vec2): Canvas resolution in pixels\n * - u_pixelRatio (float): Device pixel ratio\n * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)\n * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)\n * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas\n * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas\n * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)\n * - u_scale (float): Overall zoom level of the graphics (0.1 to 4)\n * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)\n * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n *\n */\n\n// language=GLSL\nexport const waterFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorHighlight;\n\nuniform sampler2D u_image;\nuniform float u_imageAspectRatio;\n\nuniform float u_size;\nuniform float u_highlights;\nuniform float u_layering;\nuniform float u_edges;\nuniform float u_caustic;\nuniform float u_waves;\n\nin vec2 v_imageUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n${ rotation2 }\n${ simplexNoise }\n\nfloat getUvFrame(vec2 uv) {\n float aax = 2. * fwidth(uv.x);\n float aay = 2. * fwidth(uv.y);\n\n float left = smoothstep(0., aax, uv.x);\n float right = 1.0 - smoothstep(1. - aax, 1., uv.x);\n float bottom = smoothstep(0., aay, uv.y);\n float top = 1.0 - smoothstep(1. - aay, 1., uv.y);\n\n return left * right * bottom * top;\n}\n\nmat2 rotate2D(float r) {\n return mat2(cos(r), sin(r), -sin(r), cos(r));\n}\n\nfloat getCausticNoise(vec2 uv, float t, float scale) {\n vec2 n = vec2(.1);\n vec2 N = vec2(.1);\n mat2 m = rotate2D(.5);\n for (int j = 0; j < 6; j++) {\n uv *= m;\n n *= m;\n vec2 q = uv * scale + float(j) + n + (.5 + .5 * float(j)) * (mod(float(j), 2.) - 1.) * t;\n n += sin(q);\n N += cos(q) / scale;\n scale *= 1.1;\n }\n return (N.x + N.y + 1.);\n}\n\nvoid main() {\n vec2 imageUV = v_imageUV;\n vec2 patternUV = v_imageUV - .5;\n patternUV = (patternUV * vec2(u_imageAspectRatio, 1.));\n patternUV /= (.01 + .09 * u_size);\n\n float t = u_time;\n\n float wavesNoise = snoise((.3 + .1 * sin(t)) * .1 * patternUV + vec2(0., .4 * t));\n\n float causticNoise = getCausticNoise(patternUV + u_waves * vec2(1., -1.) * wavesNoise, 2. * t, 1.5);\n\n if (u_layering > 0.) {\n causticNoise += u_layering * getCausticNoise(patternUV + 2. * u_waves * vec2(1., -1.) * wavesNoise, 1.5 * t, 2.);\n }\n causticNoise = causticNoise * causticNoise;\n\n float edgesDistortion = smoothstep(0., .1, imageUV.x);\n edgesDistortion *= smoothstep(0., .1, imageUV.y);\n edgesDistortion *= (smoothstep(1., 1.1, imageUV.x) + (1.0 - smoothstep(.8, .95, imageUV.x)));\n edgesDistortion *= (1.0 - smoothstep(.9, 1., imageUV.y));\n edgesDistortion = mix(edgesDistortion, 1., u_edges);\n\n float causticNoiseDistortion = .02 * causticNoise * edgesDistortion;\n\n float wavesDistortion = .1 * u_waves * wavesNoise;\n\n imageUV += vec2(wavesDistortion, -wavesDistortion);\n imageUV += (u_caustic * causticNoiseDistortion);\n\n float frame = getUvFrame(imageUV);\n\n vec4 image = texture(u_image, imageUV);\n vec4 backColor = u_colorBack;\n backColor.rgb *= backColor.a;\n\n vec3 color = mix(backColor.rgb, image.rgb, image.a * frame);\n float opacity = backColor.a + image.a * frame;\n\n causticNoise = max(-.2, causticNoise);\n\n float hightlight = .025 * u_highlights * causticNoise;\n hightlight *= u_colorHighlight.a;\n color = mix(color, u_colorHighlight.rgb, .05 * u_highlights * causticNoise * u_colorHighlight.a);\n opacity += hightlight;\n\n color += hightlight * (.5 + .5 * wavesNoise);\n opacity += hightlight * (.5 + .5 * wavesNoise);\n\n opacity = clamp(opacity, 0., 1.);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface WaterUniforms extends ShaderSizingUniforms {\n u_image: HTMLImageElement | string | undefined;\n u_colorBack: [number, number, number, number];\n u_colorHighlight: [number, number, number, number];\n u_highlights: number;\n u_layering: number;\n u_edges: number;\n u_caustic: number;\n u_waves: number;\n u_size: number;\n}\n\nexport interface WaterParams extends ShaderSizingParams, ShaderMotionParams {\n image?: HTMLImageElement | string;\n colorBack?: string;\n colorHighlight?: string;\n highlights?: number;\n layering?: number;\n edges?: number;\n caustic?: number;\n waves?: number;\n size?: number;\n}\n"],
5
- "mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,WAAW,oBAAoB;AAsC5C,MAAM,sBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBxC,SAAU;AAAA,EACV,SAAU;AAAA,EACV,YAAa;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;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;",
4
+ "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, rotation2, simplexNoise } from '../shader-utils.js';\n\n/**\n * Water-like surface distortion with natural caustic realism. Works as an image filter or standalone animated texture.\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_image (sampler2D): Optional source image texture, premultiplied alpha\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n * - u_imageIsHtml (float): 1 when u_image is HTML. HTML is drawn 1:1, so the ripples and their distortion don't scale with the\n * canvas. They're anchored at originX / originY instead of the center, 0 0 being the top left like CSS\n * - u_colorBack (vec4): Background color in RGBA\n * - u_colorHighlight (vec4): Highlight color in RGBA, needs highlights > 0\n * - u_highlights (float): Coloring added over image/background following caustic shape, needs colorHighlight alpha > 0 (0 to 1)\n * - u_layering (float): Power of 2nd layer of caustic distortion, needs caustic or highlights > 0 (0 to 1)\n * - u_edges (float): Caustic distortion power on the image edges, needs image and caustic > 0 (0 to 1)\n * - u_waves (float): Additional distortion based on simplex noise, independent from caustic (0 to 1)\n * - u_caustic (float): Power of caustic distortion, needs image (0 to 1)\n * - u_size (float): Pattern scale (0.01 to 7)\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_imageUV (vec2): UV coordinates for sampling the source image, with fit, scale, rotation, and offset applied\n *\n * Vertex shader uniforms:\n * - u_resolution (vec2): Canvas resolution in pixels\n * - u_pixelRatio (float): Device pixel ratio\n * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)\n * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)\n * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas\n * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas\n * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)\n * - u_scale (float): Overall zoom level of the graphics (0.1 to 4)\n * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)\n * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n *\n */\n\n// language=GLSL\nexport const waterFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorHighlight;\n\nuniform sampler2D u_image;\nuniform float u_imageAspectRatio;\nuniform float u_imageIsHtml;\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_originX;\nuniform float u_originY;\n\nuniform float u_size;\nuniform float u_highlights;\nuniform float u_layering;\nuniform float u_edges;\nuniform float u_caustic;\nuniform float u_waves;\n\nin vec2 v_imageUV;\n\nout vec4 fragColor;\n\n${ declarePI }\nfloat sizeToPx(float size) {\n return 1000. * (.002 + .07 * size);\n}\n${ rotation2 }\n${ simplexNoise }\n\nfloat getUvFrame(vec2 uv) {\n float aax = 2. * fwidth(uv.x);\n float aay = 2. * fwidth(uv.y);\n\n float left = smoothstep(0., aax, uv.x);\n float right = 1.0 - smoothstep(1. - aax, 1., uv.x);\n float bottom = smoothstep(0., aay, uv.y);\n float top = 1.0 - smoothstep(1. - aay, 1., uv.y);\n\n return left * right * bottom * top;\n}\n\nmat2 rotate2D(float r) {\n return mat2(cos(r), sin(r), -sin(r), cos(r));\n}\n\nfloat getCausticNoise(vec2 uv, float t, float scale) {\n vec2 n = vec2(.1);\n vec2 N = vec2(.1);\n mat2 m = rotate2D(.5);\n for (int j = 0; j < 6; j++) {\n uv *= m;\n n *= m;\n vec2 q = uv * scale + float(j) + n + (.5 + .5 * float(j)) * (mod(float(j), 2.) - 1.) * t;\n n += sin(q);\n N += cos(q) / scale;\n scale *= 1.1;\n }\n return (N.x + N.y + 1.);\n}\n\nvoid main() {\n vec2 imageUV = v_imageUV;\n vec2 htmlScale = vec2(1.);\n vec2 patternUV = v_imageUV;\n if (u_imageIsHtml == 1.) {\n htmlScale = u_resolution / u_pixelRatio / 1000.;\n patternUV -= vec2(u_originX, u_originY);\n patternUV *= vec2(u_imageAspectRatio, 1.);\n patternUV /= sizeToPx(u_size) / (u_resolution.y / u_pixelRatio);\n } else {\n patternUV -= .5;\n patternUV = (patternUV * vec2(u_imageAspectRatio, 1.));\n patternUV /= (.01 + .09 * u_size);\n }\n\n float t = u_time;\n\n float wavesNoise = snoise((.3 + .1 * sin(t)) * .1 * patternUV + vec2(0., .4 * t));\n\n float causticNoise = getCausticNoise(patternUV + u_waves * vec2(1., -1.) * wavesNoise, 2. * t, 1.5);\n\n if (u_layering > 0.) {\n causticNoise += u_layering * getCausticNoise(patternUV + 2. * u_waves * vec2(1., -1.) * wavesNoise, 1.5 * t, 2.);\n }\n causticNoise = causticNoise * causticNoise;\n\n float edgesDistortion = smoothstep(0., .1, imageUV.x);\n edgesDistortion *= smoothstep(0., .1, imageUV.y);\n edgesDistortion *= (smoothstep(1., 1.1, imageUV.x) + (1.0 - smoothstep(.8, .95, imageUV.x)));\n edgesDistortion *= (1.0 - smoothstep(.9, 1., imageUV.y));\n edgesDistortion = mix(edgesDistortion, 1., u_edges);\n\n float causticNoiseDistortion = .02 * causticNoise * edgesDistortion;\n\n float wavesDistortion = .1 * u_waves * wavesNoise;\n\n imageUV += vec2(wavesDistortion, -wavesDistortion) / htmlScale;\n imageUV += (u_caustic * causticNoiseDistortion) / htmlScale;\n\n float frame = getUvFrame(imageUV);\n\n vec4 image = texture(u_image, imageUV);\n vec4 backColor = u_colorBack;\n backColor.rgb *= backColor.a;\n\n vec3 color = backColor.rgb * (1. - image.a * frame) + image.rgb * frame;\n float opacity = backColor.a + image.a * frame;\n\n float hightlight = .025 * u_highlights * causticNoise;\n hightlight *= u_colorHighlight.a;\n color = mix(color, u_colorHighlight.rgb, .05 * u_highlights * causticNoise * u_colorHighlight.a);\n opacity += hightlight;\n\n color += hightlight * (.5 + .5 * wavesNoise);\n opacity += hightlight * (.5 + .5 * wavesNoise);\n\n opacity = clamp(opacity, 0., 1.);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface WaterUniforms extends ShaderSizingUniforms {\n u_image: HTMLImageElement | string | undefined;\n u_colorBack: [number, number, number, number];\n u_colorHighlight: [number, number, number, number];\n u_highlights: number;\n u_layering: number;\n u_edges: number;\n u_caustic: number;\n u_waves: number;\n u_size: number;\n}\n\nexport interface WaterParams extends ShaderSizingParams, ShaderMotionParams {\n image?: HTMLImageElement | string;\n colorBack?: string;\n colorHighlight?: string;\n highlights?: number;\n layering?: number;\n edges?: number;\n caustic?: number;\n waves?: number;\n size?: number;\n}\n"],
5
+ "mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,WAAW,oBAAoB;AAwC5C,MAAM,sBAA8B;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,EA2BxC,SAAU;AAAA;AAAA;AAAA;AAAA,EAIV,SAAU;AAAA,EACV,YAAa;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;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;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,8 @@
1
+ /** Axes on which the shader takes the size of its content instead of its own size styles */
2
+ export type ShaderSizeToContent = 'width' | 'height' | 'both';
3
+ /**
4
+ * Measures the content element for a shader sized to it, since the canvas can't be sized by what's inside it.
5
+ * The caller applies the measured size: `--paper-shader-content-width` and `--paper-shader-content-height` on the
6
+ * shader, with the content element at `max-content` width or `auto` height on those axes
7
+ */
8
+ export declare function observeContentSize(shader: HTMLElement, content: HTMLElement): () => void;
@@ -0,0 +1,41 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ const WIDTH_VARIABLE = "--paper-shader-content-width";
7
+ const HEIGHT_VARIABLE = "--paper-shader-content-height";
8
+ function observeContentSize(shader, content) {
9
+ let contentWidth = 0;
10
+ let contentHeight = 0;
11
+ const observer = new ResizeObserver((entries) => {
12
+ for (const entry of entries) {
13
+ const size = entry.borderBoxSize[0];
14
+ if (entry.target === content && size) {
15
+ contentWidth = size.inlineSize;
16
+ contentHeight = size.blockSize;
17
+ }
18
+ }
19
+ const style = getComputedStyle(shader);
20
+ let borderX = 0;
21
+ let borderY = 0;
22
+ if (style.boxSizing === "border-box") {
23
+ borderX = parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);
24
+ borderY = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
25
+ }
26
+ shader.style.setProperty(WIDTH_VARIABLE, `${contentWidth + borderX}px`);
27
+ shader.style.setProperty(HEIGHT_VARIABLE, `${contentHeight + borderY}px`);
28
+ shader.paperShaderMount?.syncSize();
29
+ });
30
+ observer.observe(content, { box: "border-box" });
31
+ observer.observe(shader);
32
+ return () => {
33
+ observer.disconnect();
34
+ shader.style.removeProperty(WIDTH_VARIABLE);
35
+ shader.style.removeProperty(HEIGHT_VARIABLE);
36
+ };
37
+ }
38
+ export {
39
+ observeContentSize
40
+ };
41
+ //# sourceMappingURL=size-to-content.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/size-to-content.ts"],
4
+ "sourcesContent": ["import type { PaperShaderElement } from './shader-mount.js';\n\nconst WIDTH_VARIABLE = '--paper-shader-content-width';\nconst HEIGHT_VARIABLE = '--paper-shader-content-height';\n\n/** Axes on which the shader takes the size of its content instead of its own size styles */\nexport type ShaderSizeToContent = 'width' | 'height' | 'both';\n\n/**\n * Measures the content element for a shader sized to it, since the canvas can't be sized by what's inside it.\n * The caller applies the measured size: `--paper-shader-content-width` and `--paper-shader-content-height` on the\n * shader, with the content element at `max-content` width or `auto` height on those axes\n */\nexport function observeContentSize(shader: HTMLElement, content: HTMLElement): () => void {\n let contentWidth = 0;\n let contentHeight = 0;\n\n // The shader is observed too, so that its border changes are picked up\n const observer = new ResizeObserver((entries) => {\n for (const entry of entries) {\n const size = entry.borderBoxSize[0];\n if (entry.target === content && size) {\n contentWidth = size.inlineSize;\n contentHeight = size.blockSize;\n }\n }\n\n // The canvas sits inside the shader's border\n const style = getComputedStyle(shader);\n let borderX = 0;\n let borderY = 0;\n if (style.boxSizing === 'border-box') {\n borderX = parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);\n borderY = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);\n }\n\n shader.style.setProperty(WIDTH_VARIABLE, `${contentWidth + borderX}px`);\n shader.style.setProperty(HEIGHT_VARIABLE, `${contentHeight + borderY}px`);\n\n // Otherwise the canvas only sees its new size next frame\n (shader as PaperShaderElement).paperShaderMount?.syncSize();\n });\n // Border box, so that the content's padding changes are picked up\n observer.observe(content, { box: 'border-box' });\n observer.observe(shader);\n\n return () => {\n observer.disconnect();\n shader.style.removeProperty(WIDTH_VARIABLE);\n shader.style.removeProperty(HEIGHT_VARIABLE);\n };\n}\n"],
5
+ "mappings": ";;;;;AAEA,MAAM,iBAAiB;AACvB,MAAM,kBAAkB;AAUjB,SAAS,mBAAmB,QAAqB,SAAkC;AACxF,MAAI,eAAe;AACnB,MAAI,gBAAgB;AAGpB,QAAM,WAAW,IAAI,eAAe,CAAC,YAAY;AAC/C,eAAW,SAAS,SAAS;AAC3B,YAAM,OAAO,MAAM,cAAc,CAAC;AAClC,UAAI,MAAM,WAAW,WAAW,MAAM;AACpC,uBAAe,KAAK;AACpB,wBAAgB,KAAK;AAAA,MACvB;AAAA,IACF;AAGA,UAAM,QAAQ,iBAAiB,MAAM;AACrC,QAAI,UAAU;AACd,QAAI,UAAU;AACd,QAAI,MAAM,cAAc,cAAc;AACpC,gBAAU,WAAW,MAAM,eAAe,IAAI,WAAW,MAAM,gBAAgB;AAC/E,gBAAU,WAAW,MAAM,cAAc,IAAI,WAAW,MAAM,iBAAiB;AAAA,IACjF;AAEA,WAAO,MAAM,YAAY,gBAAgB,GAAG,eAAe,OAAO,IAAI;AACtE,WAAO,MAAM,YAAY,iBAAiB,GAAG,gBAAgB,OAAO,IAAI;AAGxE,IAAC,OAA8B,kBAAkB,SAAS;AAAA,EAC5D,CAAC;AAED,WAAS,QAAQ,SAAS,EAAE,KAAK,aAAa,CAAC;AAC/C,WAAS,QAAQ,MAAM;AAEvB,SAAO,MAAM;AACX,aAAS,WAAW;AACpB,WAAO,MAAM,eAAe,cAAc;AAC1C,WAAO,MAAM,eAAe,eAAe;AAAA,EAC7C;AACF;",
6
+ "names": []
7
+ }
@@ -1,2 +1,2 @@
1
1
  /** Vertex shader for the shader mount */
2
- export declare const vertexShaderSource = "#version 300 es\nprecision mediump float;\n\nlayout(location = 0) in vec4 a_position;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_imageAspectRatio;\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;\n\nout vec2 v_objectUV;\nout vec2 v_objectBoxSize;\nout vec2 v_responsiveUV;\nout vec2 v_responsiveBoxGivenSize;\nout vec2 v_patternUV;\nout vec2 v_patternBoxSize;\nout vec2 v_imageUV;\n\nvec3 getBoxSize(float boxRatio, vec2 givenBoxSize) {\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(u_resolution.x / boxRatio, u_resolution.y);\n } else if (u_fit == 2.) { // fit = cover\n box.x = boxRatio * max(u_resolution.x / boxRatio, u_resolution.y);\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 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\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).xy;\n vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;\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 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 vec2 responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize).xy;\n vec2 responsiveBoxScale = u_resolution.xy / 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 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);\n v_patternBoxSize = boxSizeData.xy;\n float patternBoxNoFitBoxWidth = boxSizeData.z;\n vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;\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 // x100 is a default multiplier between vertex and fragmant shaders\n // we use it to avoid UV presision issues\n v_patternUV *= .01;\n\n // ===================================================\n\n vec2 imageBoxSize;\n if (u_fit == 1.) { // contain\n imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else if (u_fit == 2.) { // cover\n imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else {\n imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);\n }\n imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;\n vec2 imageBoxScale = u_resolution.xy / imageBoxSize;\n\n v_imageUV = uv;\n v_imageUV *= imageBoxScale;\n v_imageUV += boxOrigin * (imageBoxScale - 1.);\n v_imageUV += graphicOffset;\n v_imageUV /= u_scale;\n v_imageUV.x *= u_imageAspectRatio;\n v_imageUV = graphicRotation * v_imageUV;\n v_imageUV.x /= u_imageAspectRatio;\n\n v_imageUV += .5;\n v_imageUV.y = 1. - v_imageUV.y;\n}";
2
+ export declare const vertexShaderSource = "#version 300 es\nprecision mediump float;\n\nlayout(location = 0) in vec4 a_position;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_imageAspectRatio;\nuniform float u_imageIsHtml;\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;\n\nout vec2 v_objectUV;\nout vec2 v_objectBoxSize;\nout vec2 v_responsiveUV;\nout vec2 v_responsiveBoxGivenSize;\nout vec2 v_patternUV;\nout vec2 v_patternBoxSize;\nout vec2 v_imageUV;\n\nvec3 getBoxSize(float boxRatio, vec2 givenBoxSize) {\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(u_resolution.x / boxRatio, u_resolution.y);\n } else if (u_fit == 2.) { // fit = cover\n box.x = boxRatio * max(u_resolution.x / boxRatio, u_resolution.y);\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 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\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).xy;\n vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;\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 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 vec2 responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize).xy;\n vec2 responsiveBoxScale = u_resolution.xy / 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 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);\n v_patternBoxSize = boxSizeData.xy;\n float patternBoxNoFitBoxWidth = boxSizeData.z;\n vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;\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 // x100 is a default multiplier between vertex and fragmant shaders\n // we use it to avoid UV presision issues\n v_patternUV *= .01;\n\n // ===================================================\n\n vec2 imageBoxSize;\n if (u_fit == 1.) { // contain\n imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else if (u_fit == 2.) { // cover\n imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else {\n imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);\n }\n imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;\n vec2 imageBoxScale = u_resolution.xy / imageBoxSize;\n\n v_imageUV = uv;\n v_imageUV *= imageBoxScale;\n v_imageUV += boxOrigin * (imageBoxScale - 1.);\n v_imageUV += graphicOffset;\n v_imageUV /= u_scale;\n v_imageUV.x *= u_imageAspectRatio;\n v_imageUV = graphicRotation * v_imageUV;\n v_imageUV.x /= u_imageAspectRatio;\n\n if (u_imageIsHtml == 1.) v_imageUV = uv;\n\n v_imageUV += .5;\n v_imageUV.y = 1. - v_imageUV.y;\n}";
@@ -11,6 +11,7 @@ layout(location = 0) in vec4 a_position;
11
11
  uniform vec2 u_resolution;
12
12
  uniform float u_pixelRatio;
13
13
  uniform float u_imageAspectRatio;
14
+ uniform float u_imageIsHtml;
14
15
  uniform float u_originX;
15
16
  uniform float u_originY;
16
17
  uniform float u_worldWidth;
@@ -151,6 +152,8 @@ void main() {
151
152
  v_imageUV = graphicRotation * v_imageUV;
152
153
  v_imageUV.x /= u_imageAspectRatio;
153
154
 
155
+ if (u_imageIsHtml == 1.) v_imageUV = uv;
156
+
154
157
  v_imageUV += .5;
155
158
  v_imageUV.y = 1. - v_imageUV.y;
156
159
  }`;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/vertex-shader.ts"],
4
- "sourcesContent": ["/** Vertex shader for the shader mount */\n// language=GLSL\nexport const vertexShaderSource = `#version 300 es\nprecision mediump float;\n\nlayout(location = 0) in vec4 a_position;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_imageAspectRatio;\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;\n\nout vec2 v_objectUV;\nout vec2 v_objectBoxSize;\nout vec2 v_responsiveUV;\nout vec2 v_responsiveBoxGivenSize;\nout vec2 v_patternUV;\nout vec2 v_patternBoxSize;\nout vec2 v_imageUV;\n\nvec3 getBoxSize(float boxRatio, vec2 givenBoxSize) {\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(u_resolution.x / boxRatio, u_resolution.y);\n } else if (u_fit == 2.) { // fit = cover\n box.x = boxRatio * max(u_resolution.x / boxRatio, u_resolution.y);\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 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\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).xy;\n vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;\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 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 vec2 responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize).xy;\n vec2 responsiveBoxScale = u_resolution.xy / 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 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);\n v_patternBoxSize = boxSizeData.xy;\n float patternBoxNoFitBoxWidth = boxSizeData.z;\n vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;\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 // x100 is a default multiplier between vertex and fragmant shaders\n // we use it to avoid UV presision issues\n v_patternUV *= .01;\n\n // ===================================================\n\n vec2 imageBoxSize;\n if (u_fit == 1.) { // contain\n imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else if (u_fit == 2.) { // cover\n imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else {\n imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);\n }\n imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;\n vec2 imageBoxScale = u_resolution.xy / imageBoxSize;\n\n v_imageUV = uv;\n v_imageUV *= imageBoxScale;\n v_imageUV += boxOrigin * (imageBoxScale - 1.);\n v_imageUV += graphicOffset;\n v_imageUV /= u_scale;\n v_imageUV.x *= u_imageAspectRatio;\n v_imageUV = graphicRotation * v_imageUV;\n v_imageUV.x /= u_imageAspectRatio;\n\n v_imageUV += .5;\n v_imageUV.y = 1. - v_imageUV.y;\n}`;\n"],
5
- "mappings": ";;;;;AAEO,MAAM,qBAAqB;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;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;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;",
4
+ "sourcesContent": ["/** Vertex shader for the shader mount */\n// language=GLSL\nexport const vertexShaderSource = `#version 300 es\nprecision mediump float;\n\nlayout(location = 0) in vec4 a_position;\n\nuniform vec2 u_resolution;\nuniform float u_pixelRatio;\nuniform float u_imageAspectRatio;\nuniform float u_imageIsHtml;\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;\n\nout vec2 v_objectUV;\nout vec2 v_objectBoxSize;\nout vec2 v_responsiveUV;\nout vec2 v_responsiveBoxGivenSize;\nout vec2 v_patternUV;\nout vec2 v_patternBoxSize;\nout vec2 v_imageUV;\n\nvec3 getBoxSize(float boxRatio, vec2 givenBoxSize) {\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(u_resolution.x / boxRatio, u_resolution.y);\n } else if (u_fit == 2.) { // fit = cover\n box.x = boxRatio * max(u_resolution.x / boxRatio, u_resolution.y);\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 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\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).xy;\n vec2 objectWorldScale = u_resolution.xy / v_objectBoxSize;\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 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 vec2 responsiveBoxSize = getBoxSize(responsiveRatio, v_responsiveBoxGivenSize).xy;\n vec2 responsiveBoxScale = u_resolution.xy / 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 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);\n v_patternBoxSize = boxSizeData.xy;\n float patternBoxNoFitBoxWidth = boxSizeData.z;\n vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;\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 // x100 is a default multiplier between vertex and fragmant shaders\n // we use it to avoid UV presision issues\n v_patternUV *= .01;\n\n // ===================================================\n\n vec2 imageBoxSize;\n if (u_fit == 1.) { // contain\n imageBoxSize.x = min(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else if (u_fit == 2.) { // cover\n imageBoxSize.x = max(u_resolution.x / u_imageAspectRatio, u_resolution.y) * u_imageAspectRatio;\n } else {\n imageBoxSize.x = min(10.0, 10.0 / u_imageAspectRatio * u_imageAspectRatio);\n }\n imageBoxSize.y = imageBoxSize.x / u_imageAspectRatio;\n vec2 imageBoxScale = u_resolution.xy / imageBoxSize;\n\n v_imageUV = uv;\n v_imageUV *= imageBoxScale;\n v_imageUV += boxOrigin * (imageBoxScale - 1.);\n v_imageUV += graphicOffset;\n v_imageUV /= u_scale;\n v_imageUV.x *= u_imageAspectRatio;\n v_imageUV = graphicRotation * v_imageUV;\n v_imageUV.x /= u_imageAspectRatio;\n\n if (u_imageIsHtml == 1.) v_imageUV = uv;\n\n v_imageUV += .5;\n v_imageUV.y = 1. - v_imageUV.y;\n}`;\n"],
5
+ "mappings": ";;;;;AAEO,MAAM,qBAAqB;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;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;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;AAAA;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paper-design/shaders",
3
- "version": "0.0.0-canary.b7acb21",
3
+ "version": "0.0.0-canary.df082ba",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,