@paper-design/shaders 0.0.81 → 0.0.83

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 (87) hide show
  1. package/dist/shader-mount.d.ts +3 -0
  2. package/dist/shader-mount.js +38 -22
  3. package/dist/shader-mount.js.map +2 -2
  4. package/dist/shaders/color-panels.d.ts +15 -15
  5. package/dist/shaders/color-panels.js +29 -22
  6. package/dist/shaders/color-panels.js.map +2 -2
  7. package/dist/shaders/dithering.d.ts +7 -7
  8. package/dist/shaders/dithering.js.map +1 -1
  9. package/dist/shaders/dot-grid.d.ts +12 -12
  10. package/dist/shaders/dot-grid.js +1 -1
  11. package/dist/shaders/dot-grid.js.map +1 -1
  12. package/dist/shaders/dot-orbit.d.ts +9 -9
  13. package/dist/shaders/dot-orbit.js +3 -4
  14. package/dist/shaders/dot-orbit.js.map +2 -2
  15. package/dist/shaders/fluted-glass.d.ts +16 -16
  16. package/dist/shaders/fluted-glass.js +25 -36
  17. package/dist/shaders/fluted-glass.js.map +2 -2
  18. package/dist/shaders/gem-smoke.d.ts +13 -13
  19. package/dist/shaders/gem-smoke.js +1 -1
  20. package/dist/shaders/gem-smoke.js.map +1 -1
  21. package/dist/shaders/god-rays.d.ts +12 -12
  22. package/dist/shaders/god-rays.js +4 -6
  23. package/dist/shaders/god-rays.js.map +2 -2
  24. package/dist/shaders/grain-gradient.d.ts +14 -14
  25. package/dist/shaders/grain-gradient.js.map +1 -1
  26. package/dist/shaders/halftone-cmyk.d.ts +20 -20
  27. package/dist/shaders/halftone-cmyk.js +28 -15
  28. package/dist/shaders/halftone-cmyk.js.map +2 -2
  29. package/dist/shaders/halftone-dots.d.ts +11 -11
  30. package/dist/shaders/halftone-dots.js +18 -7
  31. package/dist/shaders/halftone-dots.js.map +2 -2
  32. package/dist/shaders/heatmap.d.ts +11 -11
  33. package/dist/shaders/heatmap.js.map +1 -1
  34. package/dist/shaders/image-dithering.d.ts +7 -7
  35. package/dist/shaders/image-dithering.js +7 -1
  36. package/dist/shaders/image-dithering.js.map +2 -2
  37. package/dist/shaders/lens-distortion.d.ts +26 -25
  38. package/dist/shaders/lens-distortion.js +10 -7
  39. package/dist/shaders/lens-distortion.js.map +2 -2
  40. package/dist/shaders/liquid-metal.d.ts +12 -12
  41. package/dist/shaders/liquid-metal.js +1 -2
  42. package/dist/shaders/liquid-metal.js.map +2 -2
  43. package/dist/shaders/mesh-gradient.d.ts +10 -10
  44. package/dist/shaders/mesh-gradient.js +2 -2
  45. package/dist/shaders/mesh-gradient.js.map +1 -1
  46. package/dist/shaders/metaballs.d.ts +7 -7
  47. package/dist/shaders/metaballs.js.map +1 -1
  48. package/dist/shaders/neuro-noise.d.ts +8 -8
  49. package/dist/shaders/neuro-noise.js.map +1 -1
  50. package/dist/shaders/paper-texture.d.ts +24 -24
  51. package/dist/shaders/paper-texture.js +9 -4
  52. package/dist/shaders/paper-texture.js.map +2 -2
  53. package/dist/shaders/perlin-noise.d.ts +10 -10
  54. package/dist/shaders/perlin-noise.js +1 -1
  55. package/dist/shaders/perlin-noise.js.map +1 -1
  56. package/dist/shaders/pulsing-border.d.ts +14 -14
  57. package/dist/shaders/pulsing-border.js +7 -2
  58. package/dist/shaders/pulsing-border.js.map +2 -2
  59. package/dist/shaders/simplex-noise.d.ts +8 -8
  60. package/dist/shaders/simplex-noise.js +5 -3
  61. package/dist/shaders/simplex-noise.js.map +2 -2
  62. package/dist/shaders/smoke-ring.d.ts +11 -11
  63. package/dist/shaders/smoke-ring.js.map +1 -1
  64. package/dist/shaders/spiral.d.ts +12 -12
  65. package/dist/shaders/spiral.js +62 -13
  66. package/dist/shaders/spiral.js.map +2 -2
  67. package/dist/shaders/static-mesh-gradient.d.ts +14 -14
  68. package/dist/shaders/static-mesh-gradient.js +28 -13
  69. package/dist/shaders/static-mesh-gradient.js.map +2 -2
  70. package/dist/shaders/static-radial-gradient.d.ts +15 -15
  71. package/dist/shaders/static-radial-gradient.js +17 -13
  72. package/dist/shaders/static-radial-gradient.js.map +2 -2
  73. package/dist/shaders/swirl.d.ts +12 -12
  74. package/dist/shaders/swirl.js +14 -7
  75. package/dist/shaders/swirl.js.map +2 -2
  76. package/dist/shaders/voronoi.d.ts +10 -10
  77. package/dist/shaders/voronoi.js +1 -2
  78. package/dist/shaders/voronoi.js.map +2 -2
  79. package/dist/shaders/warp.d.ts +12 -12
  80. package/dist/shaders/warp.js +1 -1
  81. package/dist/shaders/warp.js.map +1 -1
  82. package/dist/shaders/water.d.ts +12 -12
  83. package/dist/shaders/water.js +1 -3
  84. package/dist/shaders/water.js.map +2 -2
  85. package/dist/shaders/waves.d.ts +11 -11
  86. package/dist/shaders/waves.js.map +1 -1
  87. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/shaders/simplex-noise.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 { simplexNoise, colorBandingFix } from '../shader-utils.js';\n\nexport const simplexNoiseMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * A multi-color gradient mapped into smooth, animated curves built as a combination of 2 Simplex noises.\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colors (vec4[]): Up to 10 base 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 10)\n * - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient, needs 2+ colors (0 to 1)\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 simplexNoiseFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colors[${ simplexNoiseMeta.maxColorCount }];\nuniform float u_colorsCount;\nuniform float u_stepsPerColor;\nuniform float u_softness;\n\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ simplexNoise }\n\nfloat getNoise(vec2 uv, float t) {\n float noise = .5 * snoise(uv - vec2(0., .3 * t));\n noise += .5 * snoise(2. * uv + vec2(0., .32 * t));\n\n return noise;\n}\n\nfloat steppedSmooth(float m, float steps, float softness) {\n float stepT = floor(m * steps) / steps;\n float f = m * steps - floor(m * steps);\n float fw = steps * fwidth(m);\n float smoothed = smoothstep(.5 - softness, min(1., .5 + softness + fw), f);\n return stepT + smoothed / steps;\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= .1;\n\n float t = .2 * u_time;\n\n float shape = .5 + .5 * getNoise(shape_uv, t);\n\n float mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\n\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 < ${ simplexNoiseMeta.maxColorCount }; i++) {\n if (i >= int(u_colorsCount)) break;\n\n float localM = clamp(mixer - float(i - 1), 0., 1.);\n localM = steppedSmooth(localM, steps, .5 * u_softness);\n\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localM);\n }\n\n if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {\n float localM = mixer + 1.;\n if (mixer > (u_colorsCount - 1.)) {\n localM = mixer - (u_colorsCount - 1.);\n }\n localM = steppedSmooth(localM, steps, .5 * u_softness);\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, localM);\n }\n\n vec3 color = gradient.rgb;\n float opacity = gradient.a;\n\n ${ colorBandingFix }\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SimplexNoiseUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_stepsPerColor: number;\n u_softness: number;\n}\n\nexport interface SimplexNoiseParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n stepsPerColor?: number;\n softness?: number;\n}\n"],
5
- "mappings": ";;;;;AAEA,eAAmE;AACnE,SAAS,cAAc,uBAAuB;AAEvC,MAAM,mBAAmB;AAAA,EAC9B,eAAe;AACjB;AA+BO,MAAM,6BAAqC;AAAA;AAAA;AAAA;AAAA;AAAA,wBAKzB,iBAAiB,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASrD,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,wBA+BS,iBAAiB,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,IA2BnD,eAAgB;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 { simplexNoise, colorBandingFix } from '../shader-utils.js';\n\nexport const simplexNoiseMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * A multi-color gradient mapped into smooth, animated curves built as a combination of 2 Simplex noises.\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colors (vec4[]): Up to 10 base 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, 3 = 3\u00D7N, \u2026), needs 2+ colors (min 1, integer, recommended 1 to 10)\n * - u_softness (float): Color transition sharpness (0 = hard edge, 1 = smooth gradient), needs 2+ colors (0 to 1)\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 graphic width before scaling to fit the canvas\n * - u_worldHeight (float): Virtual graphic height before scaling 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\n * - u_rotation (float): Overall rotation angle of the graphics in degrees\n * - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)\n *\n */\n\n// language=GLSL\nexport const simplexNoiseFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colors[${ simplexNoiseMeta.maxColorCount }];\nuniform float u_colorsCount;\nuniform float u_stepsPerColor;\nuniform float u_softness;\n\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ simplexNoise }\n\nfloat getNoise(vec2 uv, float t) {\n float noise = .5 * snoise(uv - vec2(0., .3 * t));\n noise += .5 * snoise(2. * uv + vec2(0., .32 * t));\n\n return noise;\n}\n\nfloat steppedSmooth(float m, float steps, float softness) {\n float stepT = floor(m * steps) / steps;\n float f = m * steps - floor(m * steps);\n float fw = steps * fwidth(m);\n float s = clamp(softness, 0., .5);\n float smoothed = smoothstep(.5 - s, min(1., .5 + s + fw), f);\n smoothed = mix(smoothed, f, clamp(2. * softness - 1., 0., 1.));\n return stepT + smoothed / steps;\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= .1;\n\n float t = .2 * u_time;\n\n float shape = .5 + .5 * getNoise(shape_uv, t);\n\n float mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\n\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 < ${ simplexNoiseMeta.maxColorCount }; i++) {\n if (i >= int(u_colorsCount)) break;\n\n float localM = clamp(mixer - float(i - 1), 0., 1.);\n localM = steppedSmooth(localM, steps, u_softness);\n\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localM);\n }\n\n if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {\n float localM = mixer + 1.;\n if (mixer > (u_colorsCount - 1.)) {\n localM = mixer - (u_colorsCount - 1.);\n }\n localM = steppedSmooth(localM, steps, u_softness);\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, localM);\n }\n\n vec3 color = gradient.rgb;\n float opacity = gradient.a;\n\n ${ colorBandingFix }\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SimplexNoiseUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_stepsPerColor: number;\n u_softness: number;\n}\n\nexport interface SimplexNoiseParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n stepsPerColor?: number;\n softness?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,eAAmE;AACnE,SAAS,cAAc,uBAAuB;AAEvC,MAAM,mBAAmB;AAAA,EAC9B,eAAe;AACjB;AA+BO,MAAM,6BAAqC;AAAA;AAAA;AAAA;AAAA;AAAA,wBAKzB,iBAAiB,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASrD,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,wBAiCS,iBAAiB,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,IA2BnD,eAAgB;AAAA;AAAA;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -14,11 +14,11 @@ export declare const smokeRingMeta: {
14
14
  * - u_colorBack (vec4): Background color in RGBA
15
15
  * - u_colors (vec4[]): Up to 10 gradient colors in RGBA
16
16
  * - u_colorsCount (float): Number of active colors
17
- * - u_thickness (float): Thickness of the ring shape (0.01 to 1)
18
- * - u_radius (float): Radius of the ring shape (0 to 1)
19
- * - u_innerShape (float): Ring inner fill amount, needs radius > 0 (0 to 4)
20
- * - u_noiseIterations (float): Number of noise layers, more layers gives more details (1 to 8)
21
- * - u_noiseScale (float): Noise frequency (0.01 to 5)
17
+ * - u_thickness (float): Thickness of the ring shape (min 0, recommended 0 to 1)
18
+ * - u_radius (float): Radius of the ring shape (min 0, recommended 0 to 1)
19
+ * - u_innerShape (float): Ring inner fill, needs radius > 0 (0 to 2)
20
+ * - u_noiseIterations (float): Number of noise layers, more layers gives more details (1 to 8, integer)
21
+ * - u_noiseScale (float): Noise frequency (min 0, recommended 0 to 5)
22
22
  * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture
23
23
  *
24
24
  * Vertex shader outputs (used in fragment shader):
@@ -29,13 +29,13 @@ export declare const smokeRingMeta: {
29
29
  * - u_pixelRatio (float): Device pixel ratio
30
30
  * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
31
31
  * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
32
- * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas
33
- * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas
32
+ * - u_worldWidth (float): Virtual graphic width before scaling to fit the canvas
33
+ * - u_worldHeight (float): Virtual graphic height before scaling to fit the canvas
34
34
  * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
35
- * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)
36
- * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)
37
- * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
38
- * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
35
+ * - u_scale (float): Overall zoom level of the graphics
36
+ * - u_rotation (float): Overall rotation angle of the graphics in degrees
37
+ * - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)
38
+ * - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)
39
39
  *
40
40
  */
41
41
  export declare const smokeRingFragmentShader: string;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/shaders/smoke-ring.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, textureRandomizerR, colorBandingFix } from '../shader-utils.js';\n\nexport const smokeRingMeta = {\n maxColorCount: 10,\n maxNoiseIterations: 8,\n} as const;\n\n/**\n * Radial multi-colored gradient shaped with layered noise for a natural, smoky aesthetic.\n *\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colorBack (vec4): Background color in RGBA\n * - u_colors (vec4[]): Up to 10 gradient colors in RGBA\n * - u_colorsCount (float): Number of active colors\n * - u_thickness (float): Thickness of the ring shape (0.01 to 1)\n * - u_radius (float): Radius of the ring shape (0 to 1)\n * - u_innerShape (float): Ring inner fill amount, needs radius > 0 (0 to 4)\n * - u_noiseIterations (float): Number of noise layers, more layers gives more details (1 to 8)\n * - u_noiseScale (float): Noise frequency (0.01 to 5)\n * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_objectUV (vec2): Object box UV coordinates with global sizing (scale, rotation, offsets, 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 smokeRingFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${ smokeRingMeta.maxColorCount }];\nuniform float u_colorsCount;\n\nuniform float u_thickness;\nuniform float u_radius;\nuniform float u_innerShape;\nuniform float u_noiseScale;\nuniform float u_noiseIterations;\n\nin vec2 v_objectUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n${ textureRandomizerR }\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = randomR(i);\n float b = randomR(i + vec2(1.0, 0.0));\n float c = randomR(i + vec2(0.0, 1.0));\n float d = randomR(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\nvec2 fbm(vec2 n0, vec2 n1) {\n vec2 total = vec2(0.0);\n float amplitude = .4;\n for (int i = 0; i < ${ smokeRingMeta.maxNoiseIterations }; i++) {\n if (i >= int(u_noiseIterations)) break;\n total.x += valueNoise(n0) * amplitude;\n total.y += valueNoise(n1) * amplitude;\n n0 *= 1.99;\n n1 *= 1.99;\n amplitude *= 0.65;\n }\n return total;\n}\n\nfloat getNoise(vec2 uv, vec2 pUv, float t) {\n vec2 pUvLeft = pUv + .03 * t;\n float period = max(abs(u_noiseScale * TWO_PI), 1e-6);\n vec2 pUvRight = vec2(fract(pUv.x / period) * period, pUv.y) + .03 * t;\n vec2 noise = fbm(pUvLeft, pUvRight);\n return mix(noise.y, noise.x, smoothstep(-.25, .25, uv.x));\n}\n\nfloat getRingShape(vec2 uv) {\n float radius = u_radius;\n float thickness = u_thickness;\n\n float distance = length(uv);\n float ringValue = 1. - smoothstep(radius, radius + thickness, distance);\n ringValue *= smoothstep(radius - pow(u_innerShape, 3.) * thickness, radius, distance);\n\n return ringValue;\n}\n\nvoid main() {\n vec2 shape_uv = v_objectUV;\n\n float t = u_time;\n\n float cycleDuration = 3.;\n float period2 = 2.0 * cycleDuration;\n float localTime1 = fract((0.1 * t + cycleDuration) / period2) * period2;\n float localTime2 = fract((0.1 * t) / period2) * period2;\n float timeBlend = .5 + .5 * sin(.1 * t * PI / cycleDuration - .5 * PI);\n\n float atg = atan(shape_uv.y, shape_uv.x) + .001;\n float l = length(shape_uv);\n float radialOffset = .5 * l - inversesqrt(max(1e-4, l));\n vec2 polar_uv1 = vec2(atg, localTime1 - radialOffset) * u_noiseScale;\n vec2 polar_uv2 = vec2(atg, localTime2 - radialOffset) * u_noiseScale;\n \n float noise1 = getNoise(shape_uv, polar_uv1, t);\n float noise2 = getNoise(shape_uv, polar_uv2, t);\n\n float noise = mix(noise1, noise2, timeBlend);\n\n shape_uv *= (.8 + 1.2 * noise);\n\n float ringShape = getRingShape(shape_uv);\n\n float mixer = ringShape * ringShape * (u_colorsCount - 1.);\n int idxLast = int(u_colorsCount) - 1;\n vec4 gradient = u_colors[idxLast];\n gradient.rgb *= gradient.a;\n for (int i = ${ smokeRingMeta.maxColorCount } - 2; i >= 0; i--) {\n float localT = clamp(mixer - float(idxLast - i - 1), 0., 1.);\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n vec3 color = gradient.rgb * ringShape;\n float opacity = gradient.a * ringShape;\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n color = color + bgColor * (1. - opacity);\n opacity = opacity + u_colorBack.a * (1. - opacity);\n\n ${ colorBandingFix }\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SmokeRingUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_noiseScale: number;\n u_thickness: number;\n u_radius: number;\n u_innerShape: number;\n u_noiseIterations: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface SmokeRingParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n noiseScale?: number;\n thickness?: number;\n radius?: number;\n innerShape?: number;\n noiseIterations?: number;\n}\n"],
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, textureRandomizerR, colorBandingFix } from '../shader-utils.js';\n\nexport const smokeRingMeta = {\n maxColorCount: 10,\n maxNoiseIterations: 8,\n} as const;\n\n/**\n * Radial multi-colored gradient shaped with layered noise for a natural, smoky aesthetic.\n *\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colorBack (vec4): Background color in RGBA\n * - u_colors (vec4[]): Up to 10 gradient colors in RGBA\n * - u_colorsCount (float): Number of active colors\n * - u_thickness (float): Thickness of the ring shape (min 0, recommended 0 to 1)\n * - u_radius (float): Radius of the ring shape (min 0, recommended 0 to 1)\n * - u_innerShape (float): Ring inner fill, needs radius > 0 (0 to 2)\n * - u_noiseIterations (float): Number of noise layers, more layers gives more details (1 to 8, integer)\n * - u_noiseScale (float): Noise frequency (min 0, recommended 0 to 5)\n * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_objectUV (vec2): Object box UV coordinates with global sizing (scale, rotation, offsets, 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 graphic width before scaling to fit the canvas\n * - u_worldHeight (float): Virtual graphic height before scaling 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\n * - u_rotation (float): Overall rotation angle of the graphics in degrees\n * - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)\n *\n */\n\n// language=GLSL\nexport const smokeRingFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${ smokeRingMeta.maxColorCount }];\nuniform float u_colorsCount;\n\nuniform float u_thickness;\nuniform float u_radius;\nuniform float u_innerShape;\nuniform float u_noiseScale;\nuniform float u_noiseIterations;\n\nin vec2 v_objectUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n${ textureRandomizerR }\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = randomR(i);\n float b = randomR(i + vec2(1.0, 0.0));\n float c = randomR(i + vec2(0.0, 1.0));\n float d = randomR(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\nvec2 fbm(vec2 n0, vec2 n1) {\n vec2 total = vec2(0.0);\n float amplitude = .4;\n for (int i = 0; i < ${ smokeRingMeta.maxNoiseIterations }; i++) {\n if (i >= int(u_noiseIterations)) break;\n total.x += valueNoise(n0) * amplitude;\n total.y += valueNoise(n1) * amplitude;\n n0 *= 1.99;\n n1 *= 1.99;\n amplitude *= 0.65;\n }\n return total;\n}\n\nfloat getNoise(vec2 uv, vec2 pUv, float t) {\n vec2 pUvLeft = pUv + .03 * t;\n float period = max(abs(u_noiseScale * TWO_PI), 1e-6);\n vec2 pUvRight = vec2(fract(pUv.x / period) * period, pUv.y) + .03 * t;\n vec2 noise = fbm(pUvLeft, pUvRight);\n return mix(noise.y, noise.x, smoothstep(-.25, .25, uv.x));\n}\n\nfloat getRingShape(vec2 uv) {\n float radius = u_radius;\n float thickness = u_thickness;\n\n float distance = length(uv);\n float ringValue = 1. - smoothstep(radius, radius + thickness, distance);\n ringValue *= smoothstep(radius - pow(u_innerShape, 3.) * thickness, radius, distance);\n\n return ringValue;\n}\n\nvoid main() {\n vec2 shape_uv = v_objectUV;\n\n float t = u_time;\n\n float cycleDuration = 3.;\n float period2 = 2.0 * cycleDuration;\n float localTime1 = fract((0.1 * t + cycleDuration) / period2) * period2;\n float localTime2 = fract((0.1 * t) / period2) * period2;\n float timeBlend = .5 + .5 * sin(.1 * t * PI / cycleDuration - .5 * PI);\n\n float atg = atan(shape_uv.y, shape_uv.x) + .001;\n float l = length(shape_uv);\n float radialOffset = .5 * l - inversesqrt(max(1e-4, l));\n vec2 polar_uv1 = vec2(atg, localTime1 - radialOffset) * u_noiseScale;\n vec2 polar_uv2 = vec2(atg, localTime2 - radialOffset) * u_noiseScale;\n \n float noise1 = getNoise(shape_uv, polar_uv1, t);\n float noise2 = getNoise(shape_uv, polar_uv2, t);\n\n float noise = mix(noise1, noise2, timeBlend);\n\n shape_uv *= (.8 + 1.2 * noise);\n\n float ringShape = getRingShape(shape_uv);\n\n float mixer = ringShape * ringShape * (u_colorsCount - 1.);\n int idxLast = int(u_colorsCount) - 1;\n vec4 gradient = u_colors[idxLast];\n gradient.rgb *= gradient.a;\n for (int i = ${ smokeRingMeta.maxColorCount } - 2; i >= 0; i--) {\n float localT = clamp(mixer - float(idxLast - i - 1), 0., 1.);\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n vec3 color = gradient.rgb * ringShape;\n float opacity = gradient.a * ringShape;\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n color = color + bgColor * (1. - opacity);\n opacity = opacity + u_colorBack.a * (1. - opacity);\n\n ${ colorBandingFix }\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SmokeRingUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_noiseScale: number;\n u_thickness: number;\n u_radius: number;\n u_innerShape: number;\n u_noiseIterations: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface SmokeRingParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n noiseScale?: number;\n thickness?: number;\n radius?: number;\n innerShape?: number;\n noiseIterations?: number;\n}\n"],
5
5
  "mappings": ";;;;;AAEA,eAAmE;AACnE,SAAS,WAAW,oBAAoB,uBAAuB;AAExD,MAAM,gBAAgB;AAAA,EAC3B,eAAe;AAAA,EACf,oBAAoB;AACtB;AAqCO,MAAM,0BAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAQtB,cAAc,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAalD,SAAU;AAAA,EACV,kBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAgBG,cAAc,kBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBA4DxC,cAAc,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAczC,eAAgB;AAAA;AAAA;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -9,13 +9,13 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
9
9
  * - u_pixelRatio (float): Device pixel ratio
10
10
  * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
11
11
  * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
12
- * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas
13
- * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas
12
+ * - u_worldWidth (float): Virtual graphic width before scaling to fit the canvas
13
+ * - u_worldHeight (float): Virtual graphic height before scaling to fit the canvas
14
14
  * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
15
- * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)
16
- * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)
17
- * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
18
- * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
15
+ * - u_scale (float): Overall zoom level of the graphics
16
+ * - u_rotation (float): Overall rotation angle of the graphics in degrees
17
+ * - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)
18
+ * - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)
19
19
  *
20
20
  * Vertex shader outputs (used in fragment shader):
21
21
  * - v_patternUV (vec2): UV coordinates in pixels (scaled by 0.01 for precision), with rotation and offset applied
@@ -25,13 +25,13 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
25
25
  * - u_colorBack (vec4): Background color in RGBA
26
26
  * - u_colorFront (vec4): Foreground (ink) color in RGBA
27
27
  * - u_density (float): Spacing falloff simulating perspective, 0 = flat spiral (0 to 1)
28
- * - u_distortion (float): Power of shape distortion applied along the spiral (0 to 1)
28
+ * - u_distortion (float): Power of shape distortion applied along the spiral (no limits, recommended 0 to 1)
29
29
  * - u_strokeWidth (float): Thickness of spiral curve (0 to 1)
30
- * - u_strokeTaper (float): How much stroke loses width away from center, 0 = full visibility (0 to 1)
31
- * - u_strokeCap (float): Extra stroke width at the center, needs strokeWidth ≠ 0.5 (0 to 1)
32
- * - u_noise (float): Noise distortion applied over the canvas, needs noiseFrequency > 0 (0 to 1)
33
- * - u_noiseFrequency (float): Noise frequency, needs noise > 0 (0 to 1)
34
- * - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient (0 to 1)
30
+ * - u_strokeTaper (float): How much the stroke thins away from center, 0 = constant width (-1 to 1, recommended 0 to 1)
31
+ * - u_strokeCap (float): Round cap at the start of the stroke, 0 = pointed, 1 = round (0 to 1)
32
+ * - u_noise (float): Noise distortion applied over the canvas, needs noiseFrequency > 0 (min 0, recommended 0 to 1)
33
+ * - u_noiseFrequency (float): Noise frequency, needs noise > 0 (0 to 2)
34
+ * - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient (min 0, recommended 0 to 1)
35
35
  *
36
36
  */
37
37
  export declare const spiralFragmentShader: string;
@@ -32,9 +32,9 @@ void main() {
32
32
  vec2 uv = 2. * v_patternUV;
33
33
 
34
34
  float t = u_time;
35
- float l = length(uv);
35
+ float r = max(length(uv), 1e-6);
36
36
  float density = clamp(u_density, 0., 1.);
37
- l = pow(max(l, 1e-6), density);
37
+ float l = pow(r, density);
38
38
  float angle = atan(uv.y, uv.x) - t;
39
39
  float angleNormalised = angle / TWO_PI;
40
40
 
@@ -47,19 +47,63 @@ void main() {
47
47
  float stripe = fract(offset);
48
48
 
49
49
  float shape = 2. * abs(stripe - .5);
50
- float width = 1. - clamp(u_strokeWidth, .005 * u_strokeTaper, 1.);
51
50
 
51
+ vec2 uvDx = dFdx(uv);
52
+ vec2 uvDy = dFdy(uv);
53
+ float rGrad = max(r, 1e-3);
54
+ vec2 angleGrad = vec2(uv.x * uvDx.y - uv.y * uvDx.x, uv.x * uvDy.y - uv.y * uvDy.x) / rGrad / rGrad / TWO_PI;
55
+ float smoothOffset = offset - angle / TWO_PI;
56
+ vec2 offsetGrad = vec2(dFdx(smoothOffset), dFdy(smoothOffset)) + angleGrad;
57
+ float fw = length(offsetGrad);
58
+ float pixelSize = fw;
59
+ float softness = u_softness;
60
+
61
+ float cap = sqrt(sqrt(density)) * clamp(u_strokeCap, 0., 1.);
62
+ if (cap > 0.) {
63
+ float capDensity = max(density, 1e-3);
64
+ float radialGrad = capDensity * l / r;
65
+ float widthFix = radialGrad / length(vec2(radialGrad, 1. / (TWO_PI * r)));
66
+ widthFix = mix(1., widthFix, sqrt(cap));
67
+ float strokeDist = .5 * (1. - shape) * widthFix;
68
+ float halfWidth = .5 * clamp(u_strokeWidth, 0., 1.);
69
+ float capU = (1. - cap) * halfWidth;
70
+ float capAngle = t - TWO_PI * (capU - u_distortion * sin(4. * capU - .5 * t) * cos(PI + capU + .5 * t));
71
+ vec2 capCenter = pow(capU, 1. / capDensity) * vec2(cos(capAngle), sin(capAngle));
72
+ float capDist = length(uv - capCenter) * max(capDensity * pow(.5, capDensity - 1.), 1.);
73
+ float blend = max(cap * halfWidth, 1e-4);
74
+ capDist += (1. - cap) * halfWidth;
75
+ float h = clamp(.5 + .5 * (capDist - strokeDist) / blend, 0., 1.);
76
+ float dist = mix(capDist, strokeDist, h) - blend * h * (1. - h);
77
+ float capShape = 1. - 2. * dist;
78
+ float distPixel = length(vec2(dFdx(dist), dFdy(dist)));
79
+ float grow = step(shape, capShape);
80
+ pixelSize = mix(pixelSize, mix(distPixel, fw * widthFix, step(1., h)), grow);
81
+ vec2 capGrad = vec2(dFdx(capDist), dFdy(capDist));
82
+ vec2 strokeGrad = widthFix * offsetGrad;
83
+ float side = clamp(4. * sin(TWO_PI * stripe), -1., 1.);
84
+ float blended = length(mix(capGrad, sign(side) * strokeGrad, h));
85
+ float crossing = length(vec2((1. - h) * length(capGrad), h * length(strokeGrad)));
86
+ softness *= mix(crossing, blended, abs(side) * (1. - smoothstep(.1, .5, u_softness))) / max(fw, 1e-5);
87
+ shape = max(shape, capShape);
88
+ }
52
89
 
53
- float wCap = mix(width, (1. - stripe) * (1. - step(.5, stripe)), (1. - clamp(l, 0., 1.)));
54
- width = mix(width, wCap, u_strokeCap);
55
- width *= (1. - clamp(u_strokeTaper, 0., 1.) * l);
56
-
57
- float fw = fwidth(offset);
58
- float fwMult = 4. - 3. * (smoothstep(.05, .4, 2. * u_strokeWidth) * smoothstep(.05, .4, 2. * (1. - u_strokeWidth)));
59
- float pixelSize = mix(fwMult * fw, fwidth(shape), clamp(fw, 0., 1.));
60
- pixelSize = mix(pixelSize, .002, u_strokeCap * (1. - clamp(l, 0., 1.)));
61
-
62
- float res = smoothstep(width - pixelSize - u_softness, width + pixelSize + u_softness, shape);
90
+ float minWidth = min(pixelSize, .5);
91
+ float baseWidth = clamp(u_strokeWidth, minWidth, 1. - minWidth);
92
+ float taper = clamp(u_strokeTaper, -1., 1.);
93
+ float taperFactor = 1. - max(taper, 0.) * l - max(-taper, 0.) * (1. - l);
94
+ float taperCut = .5 * minWidth / max(baseWidth, 1e-5);
95
+ float taperPixel = max(fwidth(taperFactor), 1e-5);
96
+ float taperSoftness = abs(taper) * u_softness;
97
+ float taperEnd = clamp((taperFactor - taperCut + .5 * taperPixel) / (taperPixel + taperSoftness), 0., 1.);
98
+ taperEnd = mix(taperEnd, taperEnd * taperEnd * (3. - 2. * taperEnd), taperSoftness / (taperSoftness + taperPixel));
99
+ float strokeWidth = min(max(baseWidth * taperFactor, minWidth), 1.);
100
+ float width = 1. - strokeWidth;
101
+
102
+ float edge = clamp((shape - width + pixelSize + softness) / (2. * (pixelSize + softness)), 0., 1.);
103
+ float res = mix(edge, edge * edge * (3. - 2. * edge), softness / (softness + pixelSize));
104
+ res *= taperEnd;
105
+ res = mix(res, 1., clamp(1. - width / max(pixelSize, 1e-4), 0., 1.));
106
+ res = mix(res, clamp(u_strokeWidth, 0., 1.) * clamp(taperFactor, 0., 1.), smoothstep(.3, .7, fw));
63
107
 
64
108
  vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
65
109
  float fgOpacity = u_colorFront.a;
@@ -69,9 +113,14 @@ void main() {
69
113
  vec3 color = fgColor * res;
70
114
  float opacity = fgOpacity * res;
71
115
 
116
+ vec3 colorLinear = pow(u_colorFront.rgb, vec3(2.2)) * opacity + pow(u_colorBack.rgb, vec3(2.2)) * bgOpacity * (1. - opacity);
117
+
72
118
  color += bgColor * (1. - opacity);
73
119
  opacity += bgOpacity * (1. - opacity);
74
120
 
121
+ colorLinear = pow(colorLinear / max(opacity, 1e-4), vec3(1. / 2.2)) * opacity;
122
+ color = mix(color, colorLinear, pixelSize / (pixelSize + softness));
123
+
75
124
  ${colorBandingFix}
76
125
 
77
126
  fragColor = vec4(color, opacity);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/shaders/spiral.ts"],
4
- "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { simplexNoise, declarePI, colorBandingFix } from '../shader-utils.js';\n\n/**\n * A single-colored animated spiral that morphs across a wide range of shapes -\n * from crisp, thin-lined geometry to flowing whirlpool forms and wavy, abstract rings.\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 * Vertex shader outputs (used in fragment shader):\n * - v_patternUV (vec2): UV coordinates in pixels (scaled by 0.01 for precision), with rotation and offset applied\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colorBack (vec4): Background color in RGBA\n * - u_colorFront (vec4): Foreground (ink) color in RGBA\n * - u_density (float): Spacing falloff simulating perspective, 0 = flat spiral (0 to 1)\n * - u_distortion (float): Power of shape distortion applied along the spiral (0 to 1)\n * - u_strokeWidth (float): Thickness of spiral curve (0 to 1)\n * - u_strokeTaper (float): How much stroke loses width away from center, 0 = full visibility (0 to 1)\n * - u_strokeCap (float): Extra stroke width at the center, needs strokeWidth \u2260 0.5 (0 to 1)\n * - u_noise (float): Noise distortion applied over the canvas, needs noiseFrequency > 0 (0 to 1)\n * - u_noiseFrequency (float): Noise frequency, needs noise > 0 (0 to 1)\n * - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient (0 to 1)\n *\n */\n\n// language=GLSL\nexport const spiralFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorFront;\nuniform float u_density;\nuniform float u_distortion;\nuniform float u_strokeWidth;\nuniform float u_strokeCap;\nuniform float u_strokeTaper;\nuniform float u_noise;\nuniform float u_noiseFrequency;\nuniform float u_softness;\n\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n${ simplexNoise }\n\nvoid main() {\n vec2 uv = 2. * v_patternUV;\n\n float t = u_time;\n float l = length(uv);\n float density = clamp(u_density, 0., 1.);\n l = pow(max(l, 1e-6), density);\n float angle = atan(uv.y, uv.x) - t;\n float angleNormalised = angle / TWO_PI;\n\n if (u_noise > 0.) {\n angleNormalised += .125 * u_noise * snoise(16. * pow(u_noiseFrequency, 3.) * uv);\n }\n\n float offset = l + angleNormalised;\n offset -= u_distortion * (sin(4. * l - .5 * t) * cos(PI + l + .5 * t));\n float stripe = fract(offset);\n\n float shape = 2. * abs(stripe - .5);\n float width = 1. - clamp(u_strokeWidth, .005 * u_strokeTaper, 1.);\n\n\n float wCap = mix(width, (1. - stripe) * (1. - step(.5, stripe)), (1. - clamp(l, 0., 1.)));\n width = mix(width, wCap, u_strokeCap);\n width *= (1. - clamp(u_strokeTaper, 0., 1.) * l);\n\n float fw = fwidth(offset);\n float fwMult = 4. - 3. * (smoothstep(.05, .4, 2. * u_strokeWidth) * smoothstep(.05, .4, 2. * (1. - u_strokeWidth)));\n float pixelSize = mix(fwMult * fw, fwidth(shape), clamp(fw, 0., 1.));\n pixelSize = mix(pixelSize, .002, u_strokeCap * (1. - clamp(l, 0., 1.)));\n\n float res = smoothstep(width - pixelSize - u_softness, width + pixelSize + u_softness, shape);\n\n vec3 fgColor = u_colorFront.rgb * u_colorFront.a;\n float fgOpacity = u_colorFront.a;\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n float bgOpacity = u_colorBack.a;\n\n vec3 color = fgColor * res;\n float opacity = fgOpacity * res;\n\n color += bgColor * (1. - opacity);\n opacity += bgOpacity * (1. - opacity);\n\n ${ colorBandingFix }\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SpiralUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorFront: [number, number, number, number];\n u_density: number;\n u_distortion: number;\n u_strokeWidth: number;\n u_strokeTaper: number;\n u_strokeCap: number;\n u_noise: number;\n u_noiseFrequency: number;\n u_softness: number;\n}\n\nexport interface SpiralParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colorFront?: string;\n density?: number;\n distortion?: number;\n strokeWidth?: number;\n strokeTaper?: number;\n strokeCap?: number;\n noise?: number;\n noiseFrequency?: number;\n softness?: number;\n}\n"],
5
- "mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,cAAc,WAAW,uBAAuB;AAsClD,MAAM,uBAA+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBzC,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,IA8CX,eAAgB;AAAA;AAAA;AAAA;AAAA;",
4
+ "sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { simplexNoise, declarePI, colorBandingFix } from '../shader-utils.js';\n\n/**\n * A single-colored animated spiral that morphs across a wide range of shapes -\n * from crisp, thin-lined geometry to flowing whirlpool forms and wavy, abstract rings.\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 graphic width before scaling to fit the canvas\n * - u_worldHeight (float): Virtual graphic height before scaling 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\n * - u_rotation (float): Overall rotation angle of the graphics in degrees\n * - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_patternUV (vec2): UV coordinates in pixels (scaled by 0.01 for precision), with rotation and offset applied\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colorBack (vec4): Background color in RGBA\n * - u_colorFront (vec4): Foreground (ink) color in RGBA\n * - u_density (float): Spacing falloff simulating perspective, 0 = flat spiral (0 to 1)\n * - u_distortion (float): Power of shape distortion applied along the spiral (no limits, recommended 0 to 1)\n * - u_strokeWidth (float): Thickness of spiral curve (0 to 1)\n * - u_strokeTaper (float): How much the stroke thins away from center, 0 = constant width (-1 to 1, recommended 0 to 1)\n * - u_strokeCap (float): Round cap at the start of the stroke, 0 = pointed, 1 = round (0 to 1)\n * - u_noise (float): Noise distortion applied over the canvas, needs noiseFrequency > 0 (min 0, recommended 0 to 1)\n * - u_noiseFrequency (float): Noise frequency, needs noise > 0 (0 to 2)\n * - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient (min 0, recommended 0 to 1)\n *\n */\n\n// language=GLSL\nexport const spiralFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorFront;\nuniform float u_density;\nuniform float u_distortion;\nuniform float u_strokeWidth;\nuniform float u_strokeCap;\nuniform float u_strokeTaper;\nuniform float u_noise;\nuniform float u_noiseFrequency;\nuniform float u_softness;\n\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n${ simplexNoise }\n\nvoid main() {\n vec2 uv = 2. * v_patternUV;\n\n float t = u_time;\n float r = max(length(uv), 1e-6);\n float density = clamp(u_density, 0., 1.);\n float l = pow(r, density);\n float angle = atan(uv.y, uv.x) - t;\n float angleNormalised = angle / TWO_PI;\n\n if (u_noise > 0.) {\n angleNormalised += .125 * u_noise * snoise(16. * pow(u_noiseFrequency, 3.) * uv);\n }\n\n float offset = l + angleNormalised;\n offset -= u_distortion * (sin(4. * l - .5 * t) * cos(PI + l + .5 * t));\n float stripe = fract(offset);\n\n float shape = 2. * abs(stripe - .5);\n\n vec2 uvDx = dFdx(uv);\n vec2 uvDy = dFdy(uv);\n float rGrad = max(r, 1e-3);\n vec2 angleGrad = vec2(uv.x * uvDx.y - uv.y * uvDx.x, uv.x * uvDy.y - uv.y * uvDy.x) / rGrad / rGrad / TWO_PI;\n float smoothOffset = offset - angle / TWO_PI;\n vec2 offsetGrad = vec2(dFdx(smoothOffset), dFdy(smoothOffset)) + angleGrad;\n float fw = length(offsetGrad);\n float pixelSize = fw;\n float softness = u_softness;\n\n float cap = sqrt(sqrt(density)) * clamp(u_strokeCap, 0., 1.);\n if (cap > 0.) {\n float capDensity = max(density, 1e-3);\n float radialGrad = capDensity * l / r;\n float widthFix = radialGrad / length(vec2(radialGrad, 1. / (TWO_PI * r)));\n widthFix = mix(1., widthFix, sqrt(cap));\n float strokeDist = .5 * (1. - shape) * widthFix;\n float halfWidth = .5 * clamp(u_strokeWidth, 0., 1.);\n float capU = (1. - cap) * halfWidth;\n float capAngle = t - TWO_PI * (capU - u_distortion * sin(4. * capU - .5 * t) * cos(PI + capU + .5 * t));\n vec2 capCenter = pow(capU, 1. / capDensity) * vec2(cos(capAngle), sin(capAngle));\n float capDist = length(uv - capCenter) * max(capDensity * pow(.5, capDensity - 1.), 1.);\n float blend = max(cap * halfWidth, 1e-4);\n capDist += (1. - cap) * halfWidth;\n float h = clamp(.5 + .5 * (capDist - strokeDist) / blend, 0., 1.);\n float dist = mix(capDist, strokeDist, h) - blend * h * (1. - h);\n float capShape = 1. - 2. * dist;\n float distPixel = length(vec2(dFdx(dist), dFdy(dist)));\n float grow = step(shape, capShape);\n pixelSize = mix(pixelSize, mix(distPixel, fw * widthFix, step(1., h)), grow);\n vec2 capGrad = vec2(dFdx(capDist), dFdy(capDist));\n vec2 strokeGrad = widthFix * offsetGrad;\n float side = clamp(4. * sin(TWO_PI * stripe), -1., 1.);\n float blended = length(mix(capGrad, sign(side) * strokeGrad, h));\n float crossing = length(vec2((1. - h) * length(capGrad), h * length(strokeGrad)));\n softness *= mix(crossing, blended, abs(side) * (1. - smoothstep(.1, .5, u_softness))) / max(fw, 1e-5);\n shape = max(shape, capShape);\n }\n\n float minWidth = min(pixelSize, .5);\n float baseWidth = clamp(u_strokeWidth, minWidth, 1. - minWidth);\n float taper = clamp(u_strokeTaper, -1., 1.);\n float taperFactor = 1. - max(taper, 0.) * l - max(-taper, 0.) * (1. - l);\n float taperCut = .5 * minWidth / max(baseWidth, 1e-5);\n float taperPixel = max(fwidth(taperFactor), 1e-5);\n float taperSoftness = abs(taper) * u_softness;\n float taperEnd = clamp((taperFactor - taperCut + .5 * taperPixel) / (taperPixel + taperSoftness), 0., 1.);\n taperEnd = mix(taperEnd, taperEnd * taperEnd * (3. - 2. * taperEnd), taperSoftness / (taperSoftness + taperPixel));\n float strokeWidth = min(max(baseWidth * taperFactor, minWidth), 1.);\n float width = 1. - strokeWidth;\n\n float edge = clamp((shape - width + pixelSize + softness) / (2. * (pixelSize + softness)), 0., 1.);\n float res = mix(edge, edge * edge * (3. - 2. * edge), softness / (softness + pixelSize));\n res *= taperEnd;\n res = mix(res, 1., clamp(1. - width / max(pixelSize, 1e-4), 0., 1.));\n res = mix(res, clamp(u_strokeWidth, 0., 1.) * clamp(taperFactor, 0., 1.), smoothstep(.3, .7, fw));\n\n vec3 fgColor = u_colorFront.rgb * u_colorFront.a;\n float fgOpacity = u_colorFront.a;\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n float bgOpacity = u_colorBack.a;\n\n vec3 color = fgColor * res;\n float opacity = fgOpacity * res;\n\n vec3 colorLinear = pow(u_colorFront.rgb, vec3(2.2)) * opacity + pow(u_colorBack.rgb, vec3(2.2)) * bgOpacity * (1. - opacity);\n\n color += bgColor * (1. - opacity);\n opacity += bgOpacity * (1. - opacity);\n\n colorLinear = pow(colorLinear / max(opacity, 1e-4), vec3(1. / 2.2)) * opacity;\n color = mix(color, colorLinear, pixelSize / (pixelSize + softness));\n\n ${ colorBandingFix }\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SpiralUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorFront: [number, number, number, number];\n u_density: number;\n u_distortion: number;\n u_strokeWidth: number;\n u_strokeTaper: number;\n u_strokeCap: number;\n u_noise: number;\n u_noiseFrequency: number;\n u_softness: number;\n}\n\nexport interface SpiralParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colorFront?: string;\n density?: number;\n distortion?: number;\n strokeWidth?: number;\n strokeTaper?: number;\n strokeCap?: number;\n noise?: number;\n noiseFrequency?: number;\n softness?: number;\n}\n"],
5
+ "mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,cAAc,WAAW,uBAAuB;AAsClD,MAAM,uBAA+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoBzC,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;AAAA;AAAA,IA+FX,eAAgB;AAAA;AAAA;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -11,14 +11,14 @@ export declare const staticMeshGradientMeta: {
11
11
  * Fragment shader uniforms:
12
12
  * - u_colors (vec4[]): Up to 10 gradient colors in RGBA
13
13
  * - u_colorsCount (float): Number of active colors
14
- * - u_positions (float): Color spots placement seed (0 to 100)
15
- * - u_waveX (float): Strength of sine wave distortion along X axis (0 to 1)
16
- * - u_waveXShift (float): Phase offset applied to the X-axis wave, needs waveX > 0 (0 to 1)
17
- * - u_waveY (float): Strength of sine wave distortion along Y axis (0 to 1)
18
- * - u_waveYShift (float): Phase offset applied to the Y-axis wave, needs waveY > 0 (0 to 1)
19
- * - u_mixing (float): Blending behavior, 0 = hard stripes, 0.5 = smooth, 1 = gradual blend (0 to 1)
20
- * - u_grainMixer (float): Strength of grain distortion applied to shape edges (0 to 1)
21
- * - u_grainOverlay (float): Post-processing black/white grain overlay (0 to 1)
14
+ * - u_positions (float): Color spots placement seed (no limits, recommended 0 to 100)
15
+ * - u_waveX (float): Strength of sine wave distortion along X axis (no limits, recommended 0 to 1)
16
+ * - u_waveXShift (float): Phase offset applied to the X-axis wave, needs waveX > 0 (no limits, recommended 0 to 1)
17
+ * - u_waveY (float): Strength of sine wave distortion along Y axis (no limits, recommended 0 to 1)
18
+ * - u_waveYShift (float): Phase offset applied to the Y-axis wave, needs waveY > 0 (no limits, recommended 0 to 1)
19
+ * - u_mixing (float): Blending behavior, sharper vs. smoother color transitions (0 to 1)
20
+ * - u_grainMixer (float): Strength of grain distortion applied to the shapes’ edges (min 0, recommended 0 to 1)
21
+ * - u_grainOverlay (float): Post-processing b/w grain overlay (min 0, recommended 0 to 1)
22
22
  *
23
23
  * Vertex shader outputs (used in fragment shader):
24
24
  * - v_objectUV (vec2): Object box UV coordinates with global sizing (scale, rotation, offsets, etc) applied
@@ -28,13 +28,13 @@ export declare const staticMeshGradientMeta: {
28
28
  * - u_pixelRatio (float): Device pixel ratio
29
29
  * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
30
30
  * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
31
- * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas
32
- * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas
31
+ * - u_worldWidth (float): Virtual graphic width before scaling to fit the canvas
32
+ * - u_worldHeight (float): Virtual graphic height before scaling to fit the canvas
33
33
  * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
34
- * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)
35
- * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)
36
- * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
37
- * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
34
+ * - u_scale (float): Overall zoom level of the graphics
35
+ * - u_rotation (float): Overall rotation angle of the graphics in degrees
36
+ * - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)
37
+ * - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)
38
38
  *
39
39
  */
40
40
  export declare const staticMeshGradientFragmentShader: string;
@@ -81,25 +81,40 @@ void main() {
81
81
  float totalWeight = 0.;
82
82
  float positionSeed = 25. + .33 * u_positions;
83
83
 
84
+ float m = clamp(u_mixing, 0., 1.);
85
+ float mixingValue = m < .2 ? -2. * pow(1. - m / .2, 2.)
86
+ : m < .75 ? pow((m - .2) / .55, .6)
87
+ : 1. + 2. * pow((m - .75) / .25, 1.5);
88
+ float mixing = pow(clamp(mixingValue, 0., 1.), .7);
89
+ float power = mix(2., 1., mixing);
90
+ float flatten = 1. / pow(max(mixingValue, 1.), 2.);
91
+ float sharpen = exp2(3. * max(-mixingValue, 0.));
92
+
93
+ float weights[${staticMeshGradientMeta.maxColorCount}];
94
+ float maxWeight = 1e-20;
84
95
  for (int i = 0; i < ${staticMeshGradientMeta.maxColorCount}; i++) {
85
96
  if (i >= int(u_colorsCount)) break;
86
97
 
87
98
  vec2 pos = getPosition(i, positionSeed) + mixerGrain;
88
- float dist = length(uv - pos);
89
-
90
- vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;
91
- float opacityFraction = u_colors[i].a;
92
-
93
- float mixing = pow(u_mixing, .7);
94
- float power = mix(2., 1., mixing);
95
- dist = pow(dist, power);
99
+ float dist = pow(length(uv - pos), power);
96
100
 
97
101
  float w = 1. / (dist + 1e-3);
98
102
  float baseSharpness = mix(.0, 8., clamp(w, 0., 1.));
99
103
  float sharpness = mix(baseSharpness, 1., mixing);
100
- w = pow(w, sharpness);
101
- color += colorFraction * w;
102
- opacity += opacityFraction * w;
104
+ w = pow(w, sharpness * flatten);
105
+ weights[i] = w;
106
+ maxWeight = max(maxWeight, w);
107
+ }
108
+
109
+ for (int i = 0; i < ${staticMeshGradientMeta.maxColorCount}; i++) {
110
+ if (i >= int(u_colorsCount)) break;
111
+
112
+ float w = weights[i];
113
+ if (sharpen > 1.) {
114
+ w = pow(w / maxWeight, sharpen);
115
+ }
116
+ color += u_colors[i].rgb * u_colors[i].a * w;
117
+ opacity += u_colors[i].a * w;
103
118
  totalWeight += w;
104
119
  }
105
120
 
@@ -113,9 +128,9 @@ void main() {
113
128
 
114
129
  float grainOverlayV = grainOverlay * 2. - 1.;
115
130
  vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
116
- float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
131
+ float grainOverlayStrength = (u_grainOverlay <= 1. ? u_grainOverlay : sqrt(u_grainOverlay)) * abs(grainOverlayV);
117
132
  grainOverlayStrength = pow(grainOverlayStrength, .8);
118
- color = mix(color, grainOverlayColor, .35 * grainOverlayStrength);
133
+ color = mix(color, grainOverlayColor, min(1., .35 * grainOverlayStrength));
119
134
 
120
135
  opacity += .5 * grainOverlayStrength;
121
136
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/shaders/static-mesh-gradient.ts"],
4
- "sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport {\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from '../shader-sizing.js';\nimport { declarePI, rotation2, proceduralHash21 } from '../shader-utils.js';\n\nexport const staticMeshGradientMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * Multi-point mesh gradient with up to 10 color spots, enhanced by two-direction warping,\n * adjustable blend sharpness, and grain controls.\n *\n * Fragment shader uniforms:\n * - u_colors (vec4[]): Up to 10 gradient colors in RGBA\n * - u_colorsCount (float): Number of active colors\n * - u_positions (float): Color spots placement seed (0 to 100)\n * - u_waveX (float): Strength of sine wave distortion along X axis (0 to 1)\n * - u_waveXShift (float): Phase offset applied to the X-axis wave, needs waveX > 0 (0 to 1)\n * - u_waveY (float): Strength of sine wave distortion along Y axis (0 to 1)\n * - u_waveYShift (float): Phase offset applied to the Y-axis wave, needs waveY > 0 (0 to 1)\n * - u_mixing (float): Blending behavior, 0 = hard stripes, 0.5 = smooth, 1 = gradual blend (0 to 1)\n * - u_grainMixer (float): Strength of grain distortion applied to shape edges (0 to 1)\n * - u_grainOverlay (float): Post-processing black/white grain overlay (0 to 1)\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_objectUV (vec2): Object box UV coordinates with global sizing (scale, rotation, offsets, 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 staticMeshGradientFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform vec4 u_colors[${ staticMeshGradientMeta.maxColorCount }];\nuniform float u_colorsCount;\n\nuniform float u_positions;\nuniform float u_waveX;\nuniform float u_waveXShift;\nuniform float u_waveY;\nuniform float u_waveYShift;\nuniform float u_mixing;\nuniform float u_grainMixer;\nuniform float u_grainOverlay;\n\nin vec2 v_objectUV;\nout vec4 fragColor;\n\n${ declarePI }\n${ rotation2 }\n${ proceduralHash21 }\n\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = hash21(i);\n float b = hash21(i + vec2(1.0, 0.0));\n float c = hash21(i + vec2(0.0, 1.0));\n float d = hash21(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\n\nfloat noise(vec2 n, vec2 seedOffset) {\n return valueNoise(n + seedOffset);\n}\n\nvec2 getPosition(int i, float t) {\n float a = float(i) * .37;\n float b = .6 + mod(float(i), 3.) * .3;\n float c = .8 + mod(float(i + 1), 4.) * 0.25;\n\n float x = sin(t * b + a);\n float y = cos(t * c + a * 1.5);\n\n return .5 + .5 * vec2(x, y);\n}\n\nvoid main() {\n vec2 uv = v_objectUV;\n uv += .5;\n vec2 grainUV = uv * 1000.;\n\n float mixerGrain = 0.;\n if (u_grainMixer > 0.) {\n mixerGrain = .4 * u_grainMixer * (noise(grainUV, vec2(0.)) - .5);\n }\n\n float radius = smoothstep(0., 1., length(uv - .5));\n float center = 1. - radius;\n for (float i = 1.; i <= 2.; i++) {\n uv.x += u_waveX * center / i * cos(TWO_PI * u_waveXShift + i * 2. * smoothstep(.0, 1., uv.y));\n uv.y += u_waveY * center / i * cos(TWO_PI * u_waveYShift + i * 2. * smoothstep(.0, 1., uv.x));\n }\n\n vec3 color = vec3(0.);\n float opacity = 0.;\n float totalWeight = 0.;\n float positionSeed = 25. + .33 * u_positions;\n\n for (int i = 0; i < ${ staticMeshGradientMeta.maxColorCount }; i++) {\n if (i >= int(u_colorsCount)) break;\n\n vec2 pos = getPosition(i, positionSeed) + mixerGrain;\n float dist = length(uv - pos);\n\n vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;\n float opacityFraction = u_colors[i].a;\n\n float mixing = pow(u_mixing, .7);\n float power = mix(2., 1., mixing);\n dist = pow(dist, power);\n\n float w = 1. / (dist + 1e-3);\n float baseSharpness = mix(.0, 8., clamp(w, 0., 1.));\n float sharpness = mix(baseSharpness, 1., mixing);\n w = pow(w, sharpness);\n color += colorFraction * w;\n opacity += opacityFraction * w;\n totalWeight += w;\n }\n\n color /= max(1e-4, totalWeight);\n opacity /= max(1e-4, totalWeight);\n\n if (u_grainOverlay > 0.) {\n float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));\n grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);\n grainOverlay = pow(grainOverlay, 1.3);\n\n float grainOverlayV = grainOverlay * 2. - 1.;\n vec3 grainOverlayColor = vec3(step(0., grainOverlayV));\n float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);\n grainOverlayStrength = pow(grainOverlayStrength, .8);\n color = mix(color, grainOverlayColor, .35 * grainOverlayStrength);\n\n opacity += .5 * grainOverlayStrength;\n }\n opacity = clamp(opacity, 0., 1.);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface StaticMeshGradientUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_positions: number;\n u_waveX: number;\n u_waveXShift: number;\n u_waveY: number;\n u_waveYShift: number;\n u_mixing: number;\n u_grainMixer: number;\n u_grainOverlay: number;\n}\n\nexport interface StaticMeshGradientParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n positions?: number;\n waveX?: number;\n waveXShift?: number;\n waveY?: number;\n waveYShift?: number;\n mixing?: number;\n grainMixer?: number;\n grainOverlay?: number;\n}\n"],
5
- "mappings": ";;;;;AAEA;AAAA,OAGO;AACP,SAAS,WAAW,WAAW,wBAAwB;AAEhD,MAAM,yBAAyB;AAAA,EACpC,eAAe;AACjB;AAqCO,MAAM,mCAA2C;AAAA;AAAA;AAAA,wBAG/B,uBAAuB,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAe3D,SAAU;AAAA,EACV,SAAU;AAAA,EACV,gBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAoDK,uBAAuB,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;AAAA;AAAA;",
4
+ "sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport {\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from '../shader-sizing.js';\nimport { declarePI, rotation2, proceduralHash21 } from '../shader-utils.js';\n\nexport const staticMeshGradientMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * Multi-point mesh gradient with up to 10 color spots, enhanced by two-direction warping,\n * adjustable blend sharpness, and grain controls.\n *\n * Fragment shader uniforms:\n * - u_colors (vec4[]): Up to 10 gradient colors in RGBA\n * - u_colorsCount (float): Number of active colors\n * - u_positions (float): Color spots placement seed (no limits, recommended 0 to 100)\n * - u_waveX (float): Strength of sine wave distortion along X axis (no limits, recommended 0 to 1)\n * - u_waveXShift (float): Phase offset applied to the X-axis wave, needs waveX > 0 (no limits, recommended 0 to 1)\n * - u_waveY (float): Strength of sine wave distortion along Y axis (no limits, recommended 0 to 1)\n * - u_waveYShift (float): Phase offset applied to the Y-axis wave, needs waveY > 0 (no limits, recommended 0 to 1)\n * - u_mixing (float): Blending behavior, sharper vs. smoother color transitions (0 to 1)\n * - u_grainMixer (float): Strength of grain distortion applied to the shapes\u2019 edges (min 0, recommended 0 to 1)\n * - u_grainOverlay (float): Post-processing b/w grain overlay (min 0, recommended 0 to 1)\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_objectUV (vec2): Object box UV coordinates with global sizing (scale, rotation, offsets, 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 graphic width before scaling to fit the canvas\n * - u_worldHeight (float): Virtual graphic height before scaling 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\n * - u_rotation (float): Overall rotation angle of the graphics in degrees\n * - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)\n *\n */\n\n// language=GLSL\nexport const staticMeshGradientFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform vec4 u_colors[${ staticMeshGradientMeta.maxColorCount }];\nuniform float u_colorsCount;\n\nuniform float u_positions;\nuniform float u_waveX;\nuniform float u_waveXShift;\nuniform float u_waveY;\nuniform float u_waveYShift;\nuniform float u_mixing;\nuniform float u_grainMixer;\nuniform float u_grainOverlay;\n\nin vec2 v_objectUV;\nout vec4 fragColor;\n\n${ declarePI }\n${ rotation2 }\n${ proceduralHash21 }\n\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = hash21(i);\n float b = hash21(i + vec2(1.0, 0.0));\n float c = hash21(i + vec2(0.0, 1.0));\n float d = hash21(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\n\nfloat noise(vec2 n, vec2 seedOffset) {\n return valueNoise(n + seedOffset);\n}\n\nvec2 getPosition(int i, float t) {\n float a = float(i) * .37;\n float b = .6 + mod(float(i), 3.) * .3;\n float c = .8 + mod(float(i + 1), 4.) * 0.25;\n\n float x = sin(t * b + a);\n float y = cos(t * c + a * 1.5);\n\n return .5 + .5 * vec2(x, y);\n}\n\nvoid main() {\n vec2 uv = v_objectUV;\n uv += .5;\n vec2 grainUV = uv * 1000.;\n\n float mixerGrain = 0.;\n if (u_grainMixer > 0.) {\n mixerGrain = .4 * u_grainMixer * (noise(grainUV, vec2(0.)) - .5);\n }\n\n float radius = smoothstep(0., 1., length(uv - .5));\n float center = 1. - radius;\n for (float i = 1.; i <= 2.; i++) {\n uv.x += u_waveX * center / i * cos(TWO_PI * u_waveXShift + i * 2. * smoothstep(.0, 1., uv.y));\n uv.y += u_waveY * center / i * cos(TWO_PI * u_waveYShift + i * 2. * smoothstep(.0, 1., uv.x));\n }\n\n vec3 color = vec3(0.);\n float opacity = 0.;\n float totalWeight = 0.;\n float positionSeed = 25. + .33 * u_positions;\n\n float m = clamp(u_mixing, 0., 1.);\n float mixingValue = m < .2 ? -2. * pow(1. - m / .2, 2.)\n : m < .75 ? pow((m - .2) / .55, .6)\n : 1. + 2. * pow((m - .75) / .25, 1.5);\n float mixing = pow(clamp(mixingValue, 0., 1.), .7);\n float power = mix(2., 1., mixing);\n float flatten = 1. / pow(max(mixingValue, 1.), 2.);\n float sharpen = exp2(3. * max(-mixingValue, 0.));\n\n float weights[${ staticMeshGradientMeta.maxColorCount }];\n float maxWeight = 1e-20;\n for (int i = 0; i < ${ staticMeshGradientMeta.maxColorCount }; i++) {\n if (i >= int(u_colorsCount)) break;\n\n vec2 pos = getPosition(i, positionSeed) + mixerGrain;\n float dist = pow(length(uv - pos), power);\n\n float w = 1. / (dist + 1e-3);\n float baseSharpness = mix(.0, 8., clamp(w, 0., 1.));\n float sharpness = mix(baseSharpness, 1., mixing);\n w = pow(w, sharpness * flatten);\n weights[i] = w;\n maxWeight = max(maxWeight, w);\n }\n\n for (int i = 0; i < ${ staticMeshGradientMeta.maxColorCount }; i++) {\n if (i >= int(u_colorsCount)) break;\n\n float w = weights[i];\n if (sharpen > 1.) {\n w = pow(w / maxWeight, sharpen);\n }\n color += u_colors[i].rgb * u_colors[i].a * w;\n opacity += u_colors[i].a * w;\n totalWeight += w;\n }\n\n color /= max(1e-4, totalWeight);\n opacity /= max(1e-4, totalWeight);\n\n if (u_grainOverlay > 0.) {\n float grainOverlay = valueNoise(rotate(grainUV, 1.) + vec2(3.));\n grainOverlay = mix(grainOverlay, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);\n grainOverlay = pow(grainOverlay, 1.3);\n\n float grainOverlayV = grainOverlay * 2. - 1.;\n vec3 grainOverlayColor = vec3(step(0., grainOverlayV));\n float grainOverlayStrength = (u_grainOverlay <= 1. ? u_grainOverlay : sqrt(u_grainOverlay)) * abs(grainOverlayV);\n grainOverlayStrength = pow(grainOverlayStrength, .8);\n color = mix(color, grainOverlayColor, min(1., .35 * grainOverlayStrength));\n\n opacity += .5 * grainOverlayStrength;\n }\n opacity = clamp(opacity, 0., 1.);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface StaticMeshGradientUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_positions: number;\n u_waveX: number;\n u_waveXShift: number;\n u_waveY: number;\n u_waveYShift: number;\n u_mixing: number;\n u_grainMixer: number;\n u_grainOverlay: number;\n}\n\nexport interface StaticMeshGradientParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n positions?: number;\n waveX?: number;\n waveXShift?: number;\n waveY?: number;\n waveYShift?: number;\n mixing?: number;\n grainMixer?: number;\n grainOverlay?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA;AAAA,OAGO;AACP,SAAS,WAAW,WAAW,wBAAwB;AAEhD,MAAM,yBAAyB;AAAA,EACpC,eAAe;AACjB;AAqCO,MAAM,mCAA2C;AAAA;AAAA;AAAA,wBAG/B,uBAAuB,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAe3D,SAAU;AAAA,EACV,SAAU;AAAA,EACV,gBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBA6DD,uBAAuB,aAAc;AAAA;AAAA,wBAE/B,uBAAuB,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAcrC,uBAAuB,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;",
6
6
  "names": []
7
7
  }
@@ -12,16 +12,16 @@ export declare const staticRadialGradientMeta: {
12
12
  * - u_colorBack (vec4): Background color in RGBA
13
13
  * - u_colors (vec4[]): Up to 10 gradient colors in RGBA
14
14
  * - u_colorsCount (float): Number of active colors
15
- * - u_radius (float): Size of the shape (0 to 3)
16
- * - u_focalDistance (float): Distance of the focal point from center (0 to 3)
17
- * - u_focalAngle (float): Angle of the focal point in degrees, needs focalDistance > 0 (0 to 360)
18
- * - u_falloff (float): Gradient decay, 0 = equal color distribution (-1 to 1)
19
- * - u_mixing (float): Blending behavior, 0 = hard stripes, 1 = smooth gradient (0 to 1)
20
- * - u_distortion (float): Strength of radial distortion (0 to 1)
15
+ * - u_radius (float): Size of the shape (min 0, recommended 0 to 3)
16
+ * - u_focalDistance (float): Distance of the focal point from center (no limits, recommended 0 to 3)
17
+ * - u_focalAngle (float): Angle of the focal point in degrees, needs focalDistance > 0
18
+ * - u_falloff (float): Gradient decay, 0 = equal color distribution (min -1, recommended -1 to 1)
19
+ * - u_mixing (float): Blending behavior, sharper vs. smoother color transitions (min 0, recommended 0 to 1)
20
+ * - u_distortion (float): Strength of radial distortion (min 0, recommended 0 to 1)
21
21
  * - u_distortionShift (float): Radial distortion offset, needs distortion > 0 (-1 to 1)
22
- * - u_distortionFreq (float): Radial distortion frequency, needs distortion > 0 (0 to 20)
23
- * - u_grainMixer (float): Strength of grain distortion applied to shape edges (0 to 1)
24
- * - u_grainOverlay (float): Post-processing black/white grain overlay (0 to 1)
22
+ * - u_distortionFreq (float): Radial distortion frequency, needs distortion > 0 (min 0, recommended 0 to 40)
23
+ * - u_grainMixer (float): Strength of grain distortion applied to the shapes’ edges (min 0, recommended 0 to 1)
24
+ * - u_grainOverlay (float): Post-processing b/w grain overlay (min 0, recommended 0 to 1)
25
25
  *
26
26
  * Vertex shader outputs (used in fragment shader):
27
27
  * - v_objectUV (vec2): Object box UV coordinates with global sizing (scale, rotation, offsets, etc) applied
@@ -31,13 +31,13 @@ export declare const staticRadialGradientMeta: {
31
31
  * - u_pixelRatio (float): Device pixel ratio
32
32
  * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
33
33
  * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
34
- * - u_worldWidth (float): Virtual width of the graphic before it's scaled to fit the canvas
35
- * - u_worldHeight (float): Virtual height of the graphic before it's scaled to fit the canvas
34
+ * - u_worldWidth (float): Virtual graphic width before scaling to fit the canvas
35
+ * - u_worldHeight (float): Virtual graphic height before scaling to fit the canvas
36
36
  * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
37
- * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)
38
- * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)
39
- * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
40
- * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
37
+ * - u_scale (float): Overall zoom level of the graphics
38
+ * - u_rotation (float): Overall rotation angle of the graphics in degrees
39
+ * - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)
40
+ * - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)
41
41
  *
42
42
  */
43
43
  export declare const staticRadialGradientFragmentShader: string;
@@ -62,6 +62,15 @@ vec2 getPosition(int i, float t) {
62
62
  return .5 + .5 * vec2(x, y);
63
63
  }
64
64
 
65
+ float blendCurve(float mLinear, float width, float aa, float quadBlend) {
66
+ float t = clamp((mLinear - (0.5 - width - aa)) / (2. * width + 2. * aa), 0., 1.);
67
+ float p = 2. - quadBlend;
68
+ float m = t < 0.5
69
+ ? 0.5 * pow(2. * t, p)
70
+ : 1. - 0.5 * pow(2. * (1. - t), p);
71
+ return mix(m, m * m, 0.5 * quadBlend);
72
+ }
73
+
65
74
  void main() {
66
75
  vec2 uv = 2. * v_objectUV;
67
76
  vec2 grainUV = uv * 1000.;
@@ -132,23 +141,18 @@ void main() {
132
141
  gradient.rgb *= gradient.a;
133
142
 
134
143
  float outerShape = 0.;
144
+ float quadBlend = clamp((u_mixing - 0.5) * 2., 0., 1.);
145
+ float edgeWidth = clamp(u_mixing, 0., .5);
146
+ float colorWidth = edgeWidth + max(u_mixing - 1., 0.);
135
147
  for (int i = 1; i < ${staticRadialGradientMeta.maxColorCount + 1}; i++) {
136
148
  if (i > int(u_colorsCount)) break;
137
149
  float mLinear = clamp(mixer - float(i - 1), 0.0, 1.0);
138
150
 
139
151
  float aa = fwidth(mLinear);
140
- float width = min(u_mixing, 0.5);
141
- float t = clamp((mLinear - (0.5 - width - aa)) / (2. * width + 2. * aa), 0., 1.);
142
- float p = mix(2., 1., clamp((u_mixing - 0.5) * 2., 0., 1.));
143
- float m = t < 0.5
144
- ? 0.5 * pow(2. * t, p)
145
- : 1. - 0.5 * pow(2. * (1. - t), p);
146
-
147
- float quadBlend = clamp((u_mixing - 0.5) * 2., 0., 1.);
148
- m = mix(m, m * m, 0.5 * quadBlend);
149
-
152
+ float m = blendCurve(mLinear, colorWidth, aa, quadBlend);
153
+
150
154
  if (i == 1) {
151
- outerShape = m;
155
+ outerShape = blendCurve(mLinear, edgeWidth, aa, quadBlend);
152
156
  }
153
157
 
154
158
  vec4 c = u_colors[i - 1];
@@ -170,9 +174,9 @@ void main() {
170
174
 
171
175
  float grainOverlayV = grainOverlay * 2. - 1.;
172
176
  vec3 grainOverlayColor = vec3(step(0., grainOverlayV));
173
- float grainOverlayStrength = u_grainOverlay * abs(grainOverlayV);
177
+ float grainOverlayStrength = (u_grainOverlay <= 1. ? u_grainOverlay : sqrt(u_grainOverlay)) * abs(grainOverlayV);
174
178
  grainOverlayStrength = pow(grainOverlayStrength, .8);
175
- color = mix(color, grainOverlayColor, .35 * grainOverlayStrength);
179
+ color = mix(color, grainOverlayColor, min(1., .35 * grainOverlayStrength));
176
180
 
177
181
  opacity += .5 * grainOverlayStrength;
178
182
  }