@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.
- package/dist/shader-mount.d.ts +3 -0
- package/dist/shader-mount.js +38 -22
- package/dist/shader-mount.js.map +2 -2
- package/dist/shaders/color-panels.d.ts +15 -15
- package/dist/shaders/color-panels.js +29 -22
- package/dist/shaders/color-panels.js.map +2 -2
- package/dist/shaders/dithering.d.ts +7 -7
- package/dist/shaders/dithering.js.map +1 -1
- package/dist/shaders/dot-grid.d.ts +12 -12
- package/dist/shaders/dot-grid.js +1 -1
- package/dist/shaders/dot-grid.js.map +1 -1
- package/dist/shaders/dot-orbit.d.ts +9 -9
- package/dist/shaders/dot-orbit.js +3 -4
- package/dist/shaders/dot-orbit.js.map +2 -2
- package/dist/shaders/fluted-glass.d.ts +16 -16
- package/dist/shaders/fluted-glass.js +25 -36
- package/dist/shaders/fluted-glass.js.map +2 -2
- package/dist/shaders/gem-smoke.d.ts +13 -13
- package/dist/shaders/gem-smoke.js +1 -1
- package/dist/shaders/gem-smoke.js.map +1 -1
- package/dist/shaders/god-rays.d.ts +12 -12
- package/dist/shaders/god-rays.js +4 -6
- package/dist/shaders/god-rays.js.map +2 -2
- package/dist/shaders/grain-gradient.d.ts +14 -14
- package/dist/shaders/grain-gradient.js.map +1 -1
- package/dist/shaders/halftone-cmyk.d.ts +20 -20
- package/dist/shaders/halftone-cmyk.js +28 -15
- package/dist/shaders/halftone-cmyk.js.map +2 -2
- package/dist/shaders/halftone-dots.d.ts +11 -11
- package/dist/shaders/halftone-dots.js +18 -7
- package/dist/shaders/halftone-dots.js.map +2 -2
- package/dist/shaders/heatmap.d.ts +11 -11
- package/dist/shaders/heatmap.js.map +1 -1
- package/dist/shaders/image-dithering.d.ts +7 -7
- package/dist/shaders/image-dithering.js +7 -1
- package/dist/shaders/image-dithering.js.map +2 -2
- package/dist/shaders/lens-distortion.d.ts +26 -25
- package/dist/shaders/lens-distortion.js +10 -7
- package/dist/shaders/lens-distortion.js.map +2 -2
- package/dist/shaders/liquid-metal.d.ts +12 -12
- package/dist/shaders/liquid-metal.js +1 -2
- package/dist/shaders/liquid-metal.js.map +2 -2
- package/dist/shaders/mesh-gradient.d.ts +10 -10
- package/dist/shaders/mesh-gradient.js +2 -2
- package/dist/shaders/mesh-gradient.js.map +1 -1
- package/dist/shaders/metaballs.d.ts +7 -7
- package/dist/shaders/metaballs.js.map +1 -1
- package/dist/shaders/neuro-noise.d.ts +8 -8
- package/dist/shaders/neuro-noise.js.map +1 -1
- package/dist/shaders/paper-texture.d.ts +24 -24
- package/dist/shaders/paper-texture.js +9 -4
- package/dist/shaders/paper-texture.js.map +2 -2
- package/dist/shaders/perlin-noise.d.ts +10 -10
- package/dist/shaders/perlin-noise.js +1 -1
- package/dist/shaders/perlin-noise.js.map +1 -1
- package/dist/shaders/pulsing-border.d.ts +14 -14
- package/dist/shaders/pulsing-border.js +7 -2
- package/dist/shaders/pulsing-border.js.map +2 -2
- package/dist/shaders/simplex-noise.d.ts +8 -8
- package/dist/shaders/simplex-noise.js +5 -3
- package/dist/shaders/simplex-noise.js.map +2 -2
- package/dist/shaders/smoke-ring.d.ts +11 -11
- package/dist/shaders/smoke-ring.js.map +1 -1
- package/dist/shaders/spiral.d.ts +12 -12
- package/dist/shaders/spiral.js +62 -13
- package/dist/shaders/spiral.js.map +2 -2
- package/dist/shaders/static-mesh-gradient.d.ts +14 -14
- package/dist/shaders/static-mesh-gradient.js +28 -13
- package/dist/shaders/static-mesh-gradient.js.map +2 -2
- package/dist/shaders/static-radial-gradient.d.ts +15 -15
- package/dist/shaders/static-radial-gradient.js +17 -13
- package/dist/shaders/static-radial-gradient.js.map +2 -2
- package/dist/shaders/swirl.d.ts +12 -12
- package/dist/shaders/swirl.js +14 -7
- package/dist/shaders/swirl.js.map +2 -2
- package/dist/shaders/voronoi.d.ts +10 -10
- package/dist/shaders/voronoi.js +1 -2
- package/dist/shaders/voronoi.js.map +2 -2
- package/dist/shaders/warp.d.ts +12 -12
- package/dist/shaders/warp.js +1 -1
- package/dist/shaders/warp.js.map +1 -1
- package/dist/shaders/water.d.ts +12 -12
- package/dist/shaders/water.js +1 -3
- package/dist/shaders/water.js.map +2 -2
- package/dist/shaders/waves.d.ts +11 -11
- package/dist/shaders/waves.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/neuro-noise.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { rotation2, colorBandingFix } from '../shader-utils.js';\n\n/**\n * A glowing, web-like structure of fluid lines and soft intersections.\n * Great for creating atmospheric, organic-yet-futuristic visuals.\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colorFront (vec4): Graphics highlight color in RGBA\n * - u_colorMid (vec4): Graphics main color in RGBA\n * - u_colorBack (vec4): Background color in RGBA\n * - u_brightness (float): Luminosity of the crossing points (0 to 1)\n * - u_contrast (float): Sharpness of the transition between colorMid and colorBack (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
|
|
4
|
+
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { rotation2, colorBandingFix } from '../shader-utils.js';\n\n/**\n * A glowing, web-like structure of fluid lines and soft intersections.\n * Great for creating atmospheric, organic-yet-futuristic visuals.\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colorFront (vec4): Graphics highlight color in RGBA\n * - u_colorMid (vec4): Graphics main color in RGBA\n * - u_colorBack (vec4): Background color in RGBA\n * - u_brightness (float): Luminosity of the crossing points (min 0, recommended 0 to 1)\n * - u_contrast (float): Sharpness of the transition between colorMid and colorBack (no limits, recommended 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 * Original algorithm: https://x.com/zozuar/status/1625182758745128981/\n */\n\n// language=GLSL\nexport const neuroNoiseFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorFront;\nuniform vec4 u_colorMid;\nuniform vec4 u_colorBack;\nuniform float u_brightness;\nuniform float u_contrast;\n\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ rotation2 }\n\nfloat neuroShape(vec2 uv, float t) {\n vec2 sine_acc = vec2(0.);\n vec2 res = vec2(0.);\n float scale = 8.;\n\n for (int j = 0; j < 15; j++) {\n uv = rotate(uv, 1.);\n sine_acc = rotate(sine_acc, 1.);\n vec2 layer = uv * scale + float(j) + sine_acc - t;\n sine_acc += sin(layer);\n res += (.5 + .5 * cos(layer)) / scale;\n scale *= (1.2);\n }\n return res.x + res.y;\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= .13;\n\n float t = .5 * u_time;\n\n float noise = neuroShape(shape_uv, t);\n\n noise = (1. + u_brightness) * noise * noise;\n noise = pow(noise, .7 + 6. * u_contrast);\n noise = min(1.4, noise);\n\n float blend = smoothstep(0.7, 1.4, noise);\n\n vec4 frontC = u_colorFront;\n frontC.rgb *= frontC.a;\n vec4 midC = u_colorMid;\n midC.rgb *= midC.a;\n vec4 blendFront = mix(midC, frontC, blend);\n\n float safeNoise = max(noise, 0.0);\n vec3 color = blendFront.rgb * safeNoise;\n float opacity = clamp(blendFront.a * safeNoise, 0., 1.);\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 NeuroNoiseUniforms extends ShaderSizingUniforms {\n u_colorFront: [number, number, number, number];\n u_colorMid: [number, number, number, number];\n u_colorBack: [number, number, number, number];\n u_brightness: number;\n u_contrast: number;\n}\n\nexport interface NeuroNoiseParams extends ShaderSizingParams, ShaderMotionParams {\n colorFront?: string;\n colorMid?: string;\n colorBack?: string;\n brightness?: number;\n contrast?: number;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,uBAAuB;AAkCpC,MAAM,2BAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAe7C,SAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IA8CR,eAAgB;AAAA;AAAA;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -8,32 +8,32 @@ export declare const paperTextureMeta: {
|
|
|
8
8
|
* Works as an image filter or as a standalone texture.
|
|
9
9
|
*
|
|
10
10
|
* Fragment shader uniforms:
|
|
11
|
-
* - u_image (sampler2D): Optional source image texture
|
|
11
|
+
* - u_image (sampler2D): Optional source image texture, premultiplied alpha
|
|
12
12
|
* - u_isImage (bool): Whether a source image was provided
|
|
13
13
|
* - u_imageAspectRatio (float): Aspect ratio of the source image
|
|
14
14
|
* - u_colorBack (vec4): Color behind the paper sheet in RGBA
|
|
15
15
|
* - u_colorPaper (vec4): Color of the paper sheet in RGBA
|
|
16
16
|
* - u_colorShadow (vec4): Color of the patterns over the paper sheet in RGBA
|
|
17
|
-
* - u_blending (float): Amount of image-to-paper blending, needs image (0 to 1)
|
|
18
|
-
* - u_distortion (float): How much the image bends with the paper surface, needs image (-1 to 1)
|
|
17
|
+
* - u_blending (float): Amount of image-to-paper blending (0 = original image color, 1 = image multiplied with the paper pattern), needs image (min 0, recommended 0 to 1)
|
|
18
|
+
* - u_distortion (float): How much the image bends with the paper surface; negative values bend it the opposite way, needs image (no limits, recommended -1 to 1)
|
|
19
19
|
* - u_clip (bool): Cuts the paper sheet to the image frame, needs image
|
|
20
|
-
* - u_angle (float):
|
|
21
|
-
* - u_seed (float): Seed applied to every pattern (0 to 1000)
|
|
22
|
-
* - u_roughness (float): Fine grain covering the surface evenly (0 to 1)
|
|
23
|
-
* - u_roughnessSize (float): Scale of the roughness grain, needs roughness > 0 (0 to 1)
|
|
24
|
-
* - u_roughnessRows (float):
|
|
25
|
-
* - u_fiber (float): Curly thread-like noise covering the surface evenly (0 to 1)
|
|
26
|
-
* - u_fiberSize (float): Scale of the fiber noise, needs fiber > 0 (0 to 1)
|
|
27
|
-
* - u_folds (float): Straight vertical and horizontal fold lines producing ridges and valleys (0 to 1)
|
|
28
|
-
* - u_foldSizeX (float): Size of the vertical folds, needs folds > 0 (0 to 1)
|
|
29
|
-
* - u_foldSizeY (float): Size of the horizontal folds, needs folds > 0 (0 to 1)
|
|
30
|
-
* - u_foldOffsetX (float): Shifts the vertical folds across the surface, needs folds > 0 (0 to 1)
|
|
31
|
-
* - u_foldOffsetY (float): Shifts the horizontal folds across the surface, needs folds > 0 (0 to 1)
|
|
32
|
-
* - u_wrinkles (float):
|
|
33
|
-
* - u_wrinkleSize (float): Scale of the wrinkle facets, needs wrinkles > 0 (0 to 1)
|
|
34
|
-
* - u_crumples (float):
|
|
35
|
-
* - u_crumpleCount (float): Number of facets in the crumple field, needs crumples > 0 (2 to 15)
|
|
36
|
-
* - u_drops (float):
|
|
20
|
+
* - u_angle (float): Light direction in degrees, clockwise from the canvas top; also sets the direction of the roughness rows, needs crumples, wrinkles, folds, roughnessRows or drops > 0
|
|
21
|
+
* - u_seed (float): Seed applied to every pattern: crumples, wrinkles, folds, roughness, fiber and drops (no limits, recommended 0 to 1000)
|
|
22
|
+
* - u_roughness (float): Fine grain covering the surface evenly (min 0, recommended 0 to 1)
|
|
23
|
+
* - u_roughnessSize (float): Scale of the roughness grain, needs roughness > 0 (no limits, recommended 0 to 1)
|
|
24
|
+
* - u_roughnessRows (float): Aligns roughness into stripes: 0 = even scatter, 1 = laid-paper rows running across the angle direction, needs roughness > 0 (min 0, recommended 0 to 1)
|
|
25
|
+
* - u_fiber (float): Curly thread-like noise covering the surface evenly (min 0, recommended 0 to 1)
|
|
26
|
+
* - u_fiberSize (float): Scale of the fiber noise, needs fiber > 0 (no limits, recommended 0 to 1)
|
|
27
|
+
* - u_folds (float): Straight vertical and horizontal fold lines producing ridges and valleys, depending on the angle value (0 to 1)
|
|
28
|
+
* - u_foldSizeX (float): Size of the vertical folds; higher values give fewer and wider folds, needs folds > 0 (no limits, recommended 0 to 1)
|
|
29
|
+
* - u_foldSizeY (float): Size of the horizontal folds; higher values give fewer and wider folds, needs folds > 0 (no limits, recommended 0 to 1)
|
|
30
|
+
* - u_foldOffsetX (float): Shifts the vertical folds across the surface, needs folds > 0 (no limits, recommended 0 to 1)
|
|
31
|
+
* - u_foldOffsetY (float): Shifts the horizontal folds across the surface, needs folds > 0 (no limits, recommended 0 to 1)
|
|
32
|
+
* - u_wrinkles (float): Even facet pattern over the surface; looks like crumple lines but repeats instead of being counted; shaped by seed and angle (min 0, recommended 0 to 1)
|
|
33
|
+
* - u_wrinkleSize (float): Scale of the wrinkle facets, needs wrinkles > 0 (no limits, recommended 0 to 1)
|
|
34
|
+
* - u_crumples (float): Set of irregular folding lines, shaped by a combination of seed and angle values (min 0, recommended 0 to 1)
|
|
35
|
+
* - u_crumpleCount (float): Number of facets in the crumple field, needs crumples > 0 (2 to 15, integer)
|
|
36
|
+
* - u_drops (float): Speckle visibility; unlike other patterns it darkens the image instead of adding a colorShadow shape (min 0, recommended 0 to 1)
|
|
37
37
|
* - u_noiseTexture (sampler2D): Pre-computed randomizer source texture
|
|
38
38
|
*
|
|
39
39
|
* Vertex shader outputs (used in fragment shader):
|
|
@@ -45,10 +45,10 @@ export declare const paperTextureMeta: {
|
|
|
45
45
|
* - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
|
|
46
46
|
* - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
|
|
47
47
|
* - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
|
|
48
|
-
* - u_scale (float): Overall zoom level of the graphics
|
|
49
|
-
* - u_rotation (float): Overall rotation angle of the graphics in degrees
|
|
50
|
-
* - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
|
|
51
|
-
* - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
|
|
48
|
+
* - u_scale (float): Overall zoom level of the graphics
|
|
49
|
+
* - u_rotation (float): Overall rotation angle of the graphics in degrees
|
|
50
|
+
* - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)
|
|
51
|
+
* - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)
|
|
52
52
|
* - u_imageAspectRatio (float): Aspect ratio of the source image
|
|
53
53
|
*
|
|
54
54
|
*/
|
|
@@ -61,12 +61,16 @@ ${declarePI}
|
|
|
61
61
|
${proceduralHash21}
|
|
62
62
|
${proceduralHash22}
|
|
63
63
|
|
|
64
|
+
float sizeScale(float size, float smallScale, float bigScale) {
|
|
65
|
+
return size <= 1. ? mix(smallScale, bigScale, size) : bigScale / size;
|
|
66
|
+
}
|
|
67
|
+
|
|
64
68
|
float getRoughness(vec2 p, vec2 lightDir, vec2 seedShift, float basePixel) {
|
|
65
69
|
vec2 u = p / vec2(2, 4);
|
|
66
70
|
float w = 100. * basePixel;
|
|
67
71
|
float eps = 4. * w;
|
|
68
72
|
|
|
69
|
-
float size =
|
|
73
|
+
float size = sizeScale(u_roughnessSize, 3.2, .8);
|
|
70
74
|
float logLac = log2(2.1);
|
|
71
75
|
float level = -log2(w + 1e-8) / logLac;
|
|
72
76
|
float baseLevel = floor(level) - 2.;
|
|
@@ -114,7 +118,7 @@ float getRoughness(vec2 p, vec2 lightDir, vec2 seedShift, float basePixel) {
|
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
float getFiber(vec2 p, vec2 seedShift, float basePixel) {
|
|
117
|
-
float size =
|
|
121
|
+
float size = sizeScale(u_fiberSize, 4., 1.);
|
|
118
122
|
float w = 50. * basePixel;
|
|
119
123
|
float level = -log2(w + 1e-8);
|
|
120
124
|
float baseLevel = floor(level) - 3.;
|
|
@@ -391,7 +395,7 @@ void main() {
|
|
|
391
395
|
}
|
|
392
396
|
|
|
393
397
|
if (u_wrinkles > 0.) {
|
|
394
|
-
float detailFreq =
|
|
398
|
+
float detailFreq = sizeScale(u_wrinkleSize, 10., 1.);
|
|
395
399
|
float detailAmp = .2;
|
|
396
400
|
vec2 detailGrad = vec2(0.);
|
|
397
401
|
float detailDepth = 0., depthSum = 0.;
|
|
@@ -414,7 +418,7 @@ void main() {
|
|
|
414
418
|
|
|
415
419
|
if (u_folds > 0.) {
|
|
416
420
|
vec2 foldOffset = vec2(1. - 2. * u_foldOffsetX, 1. - 2. * u_foldOffsetY);
|
|
417
|
-
vec2 foldCount = vec2(
|
|
421
|
+
vec2 foldCount = vec2(sizeScale(u_foldSizeX, 3., .5), sizeScale(u_foldSizeY, 3., .5));
|
|
418
422
|
vec2 foldNoise = .005 * warpNoise * foldCount;
|
|
419
423
|
vec2 uv = patternUV + .03 * crumpleFlow;
|
|
420
424
|
|
|
@@ -488,6 +492,7 @@ void main() {
|
|
|
488
492
|
if (u_isImage) {
|
|
489
493
|
float frame = getUvFrame(imageUV);
|
|
490
494
|
vec4 image = texture(u_image, imageUV);
|
|
495
|
+
image.rgb /= max(image.a, .0001);
|
|
491
496
|
frame *= image.a;
|
|
492
497
|
|
|
493
498
|
float maxC = max(max(image.r, image.g), image.b);
|
|
@@ -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 = 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 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,
|
|
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_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 (0 = original image color, 1 = image multiplied with the paper pattern), needs image (min 0, recommended 0 to 1)\n * - u_distortion (float): How much the image bends with the paper surface; negative values bend it the opposite way, needs image (no limits, recommended -1 to 1)\n * - u_clip (bool): Cuts the paper sheet to the image frame, needs image\n * - u_angle (float): Light direction in degrees, clockwise from the canvas top; also sets the direction of the roughness rows, needs crumples, wrinkles, folds, roughnessRows or drops > 0\n * - u_seed (float): Seed applied to every pattern: crumples, wrinkles, folds, roughness, fiber and drops (no limits, recommended 0 to 1000)\n * - u_roughness (float): Fine grain covering the surface evenly (min 0, recommended 0 to 1)\n * - u_roughnessSize (float): Scale of the roughness grain, needs roughness > 0 (no limits, recommended 0 to 1)\n * - u_roughnessRows (float): Aligns roughness into stripes: 0 = even scatter, 1 = laid-paper rows running across the angle direction, needs roughness > 0 (min 0, recommended 0 to 1)\n * - u_fiber (float): Curly thread-like noise covering the surface evenly (min 0, recommended 0 to 1)\n * - u_fiberSize (float): Scale of the fiber noise, needs fiber > 0 (no limits, recommended 0 to 1)\n * - u_folds (float): Straight vertical and horizontal fold lines producing ridges and valleys, depending on the angle value (0 to 1)\n * - u_foldSizeX (float): Size of the vertical folds; higher values give fewer and wider folds, needs folds > 0 (no limits, recommended 0 to 1)\n * - u_foldSizeY (float): Size of the horizontal folds; higher values give fewer and wider folds, needs folds > 0 (no limits, recommended 0 to 1)\n * - u_foldOffsetX (float): Shifts the vertical folds across the surface, needs folds > 0 (no limits, recommended 0 to 1)\n * - u_foldOffsetY (float): Shifts the horizontal folds across the surface, needs folds > 0 (no limits, recommended 0 to 1)\n * - u_wrinkles (float): Even facet pattern over the surface; looks like crumple lines but repeats instead of being counted; shaped by seed and angle (min 0, recommended 0 to 1)\n * - u_wrinkleSize (float): Scale of the wrinkle facets, needs wrinkles > 0 (no limits, recommended 0 to 1)\n * - u_crumples (float): Set of irregular folding lines, shaped by a combination of seed and angle values (min 0, recommended 0 to 1)\n * - u_crumpleCount (float): Number of facets in the crumple field, needs crumples > 0 (2 to 15, integer)\n * - u_drops (float): Speckle visibility; unlike other patterns it darkens the image instead of adding a colorShadow shape (min 0, recommended 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\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 * - 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 sizeScale(float size, float smallScale, float bigScale) {\n return size <= 1. ? mix(smallScale, bigScale, size) : bigScale / size;\n}\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 = sizeScale(u_roughnessSize, 3.2, .8);\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 = sizeScale(u_fiberSize, 4., 1.);\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 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 = sizeScale(u_wrinkleSize, 10., 1.);\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(sizeScale(u_foldSizeX, 3., .5), sizeScale(u_foldSizeY, 3., .5));\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 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;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;AAAA;AAAA;AAAA,eAuMH,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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,10 +9,10 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
|
|
|
9
9
|
* - u_colorFront (vec4): Foreground color in RGBA
|
|
10
10
|
* - u_colorBack (vec4): Background color in RGBA
|
|
11
11
|
* - u_proportion (float): Blend point between two colors, 0.5 = equal distribution (0 to 1)
|
|
12
|
-
* - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient (0 to 1)
|
|
13
|
-
* - u_octaveCount (float): Perlin noise octaves number, more octaves for more detailed patterns (1 to 8)
|
|
14
|
-
* - u_persistence (float): Roughness, falloff between octaves, needs octaveCount > 1 (0
|
|
15
|
-
* - u_lacunarity (float): Frequency step,
|
|
12
|
+
* - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient (min 0, recommended 0 to 1)
|
|
13
|
+
* - u_octaveCount (float): Perlin noise octaves number, more octaves for more detailed patterns (1 to 8, integer)
|
|
14
|
+
* - u_persistence (float): Roughness, falloff between octaves, needs octaveCount > 1 (no limits, recommended 0 to 1)
|
|
15
|
+
* - u_lacunarity (float): Frequency step, typically around 2. Defines how compressed the pattern is, needs octaveCount > 1 (1.5 to 10)
|
|
16
16
|
*
|
|
17
17
|
* Vertex shader outputs (used in fragment shader):
|
|
18
18
|
* - v_patternUV (vec2): UV coordinates for pattern with global sizing (rotation, scale, offset, etc) applied
|
|
@@ -22,13 +22,13 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
|
|
|
22
22
|
* - u_pixelRatio (float): Device pixel ratio
|
|
23
23
|
* - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
|
|
24
24
|
* - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
|
|
25
|
-
* - u_worldWidth (float): Virtual width
|
|
26
|
-
* - u_worldHeight (float): Virtual height
|
|
25
|
+
* - u_worldWidth (float): Virtual graphic width before scaling to fit the canvas
|
|
26
|
+
* - u_worldHeight (float): Virtual graphic height before scaling to fit the canvas
|
|
27
27
|
* - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
|
|
28
|
-
* - u_scale (float): Overall zoom level of the graphics
|
|
29
|
-
* - u_rotation (float): Overall rotation angle of the graphics in degrees
|
|
30
|
-
* - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
|
|
31
|
-
* - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
|
|
28
|
+
* - u_scale (float): Overall zoom level of the graphics
|
|
29
|
+
* - u_rotation (float): Overall rotation angle of the graphics in degrees
|
|
30
|
+
* - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)
|
|
31
|
+
* - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)
|
|
32
32
|
*
|
|
33
33
|
*/
|
|
34
34
|
export declare const perlinNoiseFragmentShader: string;
|
|
@@ -137,7 +137,7 @@ void main() {
|
|
|
137
137
|
|
|
138
138
|
float max_amp = get_max_amp(u_persistence, octCount);
|
|
139
139
|
float noise_normalized = clamp((noise + max_amp) / max(1e-4, (2. * max_amp)) + (u_proportion - .5), 0.0, 1.0);
|
|
140
|
-
float sharpness =
|
|
140
|
+
float sharpness = max(u_softness, 0.);
|
|
141
141
|
float smooth_w = 0.5 * max(fwidth(noise_normalized), 0.001);
|
|
142
142
|
float res = smoothstep(
|
|
143
143
|
.5 - .5 * sharpness - smooth_w,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/perlin-noise.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, colorBandingFix, proceduralHash11, proceduralHash21 } from '../shader-utils.js';\n\n/**\n * Classic animated 3D Perlin noise with exposed controls.\n * Original algorithm: https://www.shadertoy.com/view/NlSGDz\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colorFront (vec4): Foreground color in RGBA\n * - u_colorBack (vec4): Background color in RGBA\n * - u_proportion (float): Blend point between two colors, 0.5 = equal distribution (0 to 1)\n * - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient (0 to 1)\n * - u_octaveCount (float): Perlin noise octaves number, more octaves for more detailed patterns (1 to 8)\n * - u_persistence (float): Roughness, falloff between octaves, needs octaveCount > 1 (0
|
|
4
|
+
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, colorBandingFix, proceduralHash11, proceduralHash21 } from '../shader-utils.js';\n\n/**\n * Classic animated 3D Perlin noise with exposed controls.\n * Original algorithm: https://www.shadertoy.com/view/NlSGDz\n *\n * Fragment shader uniforms:\n * - u_time (float): Animation time\n * - u_colorFront (vec4): Foreground color in RGBA\n * - u_colorBack (vec4): Background color in RGBA\n * - u_proportion (float): Blend point between two colors, 0.5 = equal distribution (0 to 1)\n * - u_softness (float): Color transition sharpness, 0 = hard edge, 1 = smooth gradient (min 0, recommended 0 to 1)\n * - u_octaveCount (float): Perlin noise octaves number, more octaves for more detailed patterns (1 to 8, integer)\n * - u_persistence (float): Roughness, falloff between octaves, needs octaveCount > 1 (no limits, recommended 0 to 1)\n * - u_lacunarity (float): Frequency step, typically around 2. Defines how compressed the pattern is, needs octaveCount > 1 (1.5 to 10)\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 perlinNoiseFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorFront;\nuniform vec4 u_colorBack;\nuniform float u_proportion;\nuniform float u_softness;\nuniform float u_octaveCount;\nuniform float u_persistence;\nuniform float u_lacunarity;\n\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n${ proceduralHash11 }\n${ proceduralHash21 }\n\nfloat hash31(vec3 p) {\n p = fract(p * 0.3183099) + 0.1;\n p += dot(p, p.yzx + 19.19);\n return fract(p.x * (p.y + p.z));\n}\n\nvec3 gradientPredefined(float hash) {\n int idx = int(hash * 12.0) % 12;\n\n if (idx == 0) return vec3(1, 1, 0);\n if (idx == 1) return vec3(-1, 1, 0);\n if (idx == 2) return vec3(1, -1, 0);\n if (idx == 3) return vec3(-1, -1, 0);\n if (idx == 4) return vec3(1, 0, 1);\n if (idx == 5) return vec3(-1, 0, 1);\n if (idx == 6) return vec3(1, 0, -1);\n if (idx == 7) return vec3(-1, 0, -1);\n if (idx == 8) return vec3(0, 1, 1);\n if (idx == 9) return vec3(0, -1, 1);\n if (idx == 10) return vec3(0, 1, -1);\n return vec3(0, -1, -1);// idx == 11\n}\n\nfloat interpolateSafe(float v000, float v001, float v010, float v011,\nfloat v100, float v101, float v110, float v111, vec3 t) {\n t = clamp(t, 0.0, 1.0);\n\n float v00 = mix(v000, v100, t.x);\n float v01 = mix(v001, v101, t.x);\n float v10 = mix(v010, v110, t.x);\n float v11 = mix(v011, v111, t.x);\n\n float v0 = mix(v00, v10, t.y);\n float v1 = mix(v01, v11, t.y);\n\n return mix(v0, v1, t.z);\n}\n\nvec3 fade(vec3 t) {\n return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);\n}\n\nfloat perlinNoise(vec3 position, float seed) {\n position += vec3(seed * 127.1, seed * 311.7, seed * 74.7);\n\n vec3 i = floor(position);\n vec3 f = fract(position);\n float h000 = hash31(i);\n float h001 = hash31(i + vec3(0, 0, 1));\n float h010 = hash31(i + vec3(0, 1, 0));\n float h011 = hash31(i + vec3(0, 1, 1));\n float h100 = hash31(i + vec3(1, 0, 0));\n float h101 = hash31(i + vec3(1, 0, 1));\n float h110 = hash31(i + vec3(1, 1, 0));\n float h111 = hash31(i + vec3(1, 1, 1));\n vec3 g000 = gradientPredefined(h000);\n vec3 g001 = gradientPredefined(h001);\n vec3 g010 = gradientPredefined(h010);\n vec3 g011 = gradientPredefined(h011);\n vec3 g100 = gradientPredefined(h100);\n vec3 g101 = gradientPredefined(h101);\n vec3 g110 = gradientPredefined(h110);\n vec3 g111 = gradientPredefined(h111);\n float v000 = dot(g000, f - vec3(0, 0, 0));\n float v001 = dot(g001, f - vec3(0, 0, 1));\n float v010 = dot(g010, f - vec3(0, 1, 0));\n float v011 = dot(g011, f - vec3(0, 1, 1));\n float v100 = dot(g100, f - vec3(1, 0, 0));\n float v101 = dot(g101, f - vec3(1, 0, 1));\n float v110 = dot(g110, f - vec3(1, 1, 0));\n float v111 = dot(g111, f - vec3(1, 1, 1));\n\n vec3 u = fade(f);\n return interpolateSafe(v000, v001, v010, v011, v100, v101, v110, v111, u);\n}\n\nfloat p_noise(vec3 position, int octaveCount, float persistence, float lacunarity) {\n float value = 0.0;\n float amplitude = 1.0;\n float frequency = 10.0;\n octaveCount = clamp(octaveCount, 1, 8);\n\n for (int i = 0; i < octaveCount; i++) {\n float seed = float(i) * 0.7319;\n value += perlinNoise(position * frequency, seed) * amplitude;\n amplitude *= persistence;\n frequency *= lacunarity;\n }\n return value;\n}\n\nfloat get_max_amp(float persistence, float octaveCount) {\n persistence = clamp(persistence * 0.999, 0.0, 0.999);\n octaveCount = clamp(octaveCount, 1.0, 8.0);\n\n return (1.0 - pow(persistence, octaveCount)) / max(1e-4, (1.0 - persistence));\n}\n\nvoid main() {\n vec2 uv = v_patternUV;\n uv *= .5;\n\n float t = .2 * u_time;\n\n vec3 p = vec3(uv, t);\n\n float octCount = floor(u_octaveCount);\n float noise = p_noise(p, int(octCount), u_persistence, u_lacunarity);\n\n float max_amp = get_max_amp(u_persistence, octCount);\n float noise_normalized = clamp((noise + max_amp) / max(1e-4, (2. * max_amp)) + (u_proportion - .5), 0.0, 1.0);\n float sharpness = max(u_softness, 0.);\n float smooth_w = 0.5 * max(fwidth(noise_normalized), 0.001);\n float res = smoothstep(\n .5 - .5 * sharpness - smooth_w,\n .5 + .5 * sharpness + smooth_w,\n noise_normalized\n );\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 PerlinNoiseUniforms extends ShaderSizingUniforms {\n u_colorFront: [number, number, number, number];\n u_colorBack: [number, number, number, number];\n u_proportion: number;\n u_softness: number;\n u_octaveCount: number;\n u_persistence: number;\n u_lacunarity: number;\n}\n\nexport interface PerlinNoiseParams extends ShaderSizingParams, ShaderMotionParams {\n colorFront?: string;\n colorBack?: string;\n proportion?: number;\n softness?: number;\n octaveCount?: number;\n persistence?: number;\n lacunarity?: number;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,iBAAiB,kBAAkB,wBAAwB;AAmCxE,MAAM,4BAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiB9C,SAAU;AAAA,EACV,gBAAiB;AAAA,EACjB,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAoIf,eAAgB;AAAA;AAAA;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,20 +14,20 @@ export declare const pulsingBorderMeta: {
|
|
|
14
14
|
* - u_colors (vec4[]): Up to 5 spot colors in RGBA
|
|
15
15
|
* - u_colorsCount (float): Number of active colors
|
|
16
16
|
* - u_roundness (float): Border radius (0 to 1)
|
|
17
|
-
* - u_thickness (float): Border base width (0 to 1)
|
|
17
|
+
* - u_thickness (float): Border base width (min 0, recommended 0 to 1)
|
|
18
18
|
* - u_softness (float): Border edge sharpness, 0 = hard edge, 1 = smooth gradient (0 to 1)
|
|
19
19
|
* - u_marginLeft (float): Distance from the left edge to the effect (0 to 1)
|
|
20
20
|
* - u_marginRight (float): Distance from the right edge to the effect (0 to 1)
|
|
21
21
|
* - u_marginTop (float): Distance from the top edge to the effect (0 to 1)
|
|
22
22
|
* - u_marginBottom (float): Distance from the bottom edge to the effect (0 to 1)
|
|
23
23
|
* - u_aspectRatio (float): Aspect ratio mode (0 = auto, 1 = square)
|
|
24
|
-
* - u_intensity (float): Thickness of individual color spots (0 to 1)
|
|
25
|
-
* - u_bloom (float): Power of glow, 0 = normal blending, 1 = additive blending (0 to 1)
|
|
26
|
-
* - u_spots (float): Number of spots added for each color (1 to 4)
|
|
27
|
-
* - u_spotSize (float): Angular size of spots (0 to 1)
|
|
28
|
-
* - u_pulse (float): Optional pulsing animation
|
|
29
|
-
* - u_smoke (float): Optional noisy shape extending the border (0 to 1)
|
|
30
|
-
* - u_smokeSize (float): Size of the smoke effect, needs smoke > 0 (0 to 1)
|
|
24
|
+
* - u_intensity (float): Thickness of individual color spots, amplified by softness (min 0, recommended 0 to 1)
|
|
25
|
+
* - u_bloom (float): Power of glow, 0 = normal color blending, 1 = fully additive blending (min 0, recommended 0 to 1)
|
|
26
|
+
* - u_spots (float): Number of spots added for each color (1 to 4, integer)
|
|
27
|
+
* - u_spotSize (float): Angular size of spots (no limits, recommended 0 to 1)
|
|
28
|
+
* - u_pulse (float): Optional pulsing animation (0 to 1)
|
|
29
|
+
* - u_smoke (float): Optional noisy shape extending the border shape (min 0, recommended 0 to 1)
|
|
30
|
+
* - u_smokeSize (float): Size of the smoke effect, needs smoke > 0 (min 0, recommended 0 to 1)
|
|
31
31
|
* - u_noiseTexture (sampler2D): Pre-computed randomizer source texture
|
|
32
32
|
*
|
|
33
33
|
* Vertex shader outputs (used in fragment shader):
|
|
@@ -40,13 +40,13 @@ export declare const pulsingBorderMeta: {
|
|
|
40
40
|
* - u_pixelRatio (float): Device pixel ratio
|
|
41
41
|
* - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
|
|
42
42
|
* - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
|
|
43
|
-
* - u_worldWidth (float): Virtual width
|
|
44
|
-
* - u_worldHeight (float): Virtual height
|
|
43
|
+
* - u_worldWidth (float): Virtual graphic width before scaling to fit the canvas
|
|
44
|
+
* - u_worldHeight (float): Virtual graphic height before scaling to fit the canvas
|
|
45
45
|
* - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
|
|
46
|
-
* - u_scale (float): Overall zoom level of the graphics
|
|
47
|
-
* - u_rotation (float): Overall rotation angle of the graphics in degrees
|
|
48
|
-
* - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
|
|
49
|
-
* - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
|
|
46
|
+
* - u_scale (float): Overall zoom level of the graphics
|
|
47
|
+
* - u_rotation (float): Overall rotation angle of the graphics in degrees
|
|
48
|
+
* - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)
|
|
49
|
+
* - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)
|
|
50
50
|
*
|
|
51
51
|
*/
|
|
52
52
|
export declare const pulsingBorderFragmentShader: string;
|
|
@@ -170,6 +170,10 @@ void main() {
|
|
|
170
170
|
|
|
171
171
|
float angle = atan(borderUV.y, borderUV.x) / TWO_PI;
|
|
172
172
|
|
|
173
|
+
float spotShrink = clamp(1. + u_spotSize, 0., 1.);
|
|
174
|
+
float spotGrow = max(u_spotSize, 0.);
|
|
175
|
+
spotGrow = .6 * spotGrow * spotGrow;
|
|
176
|
+
|
|
173
177
|
for (int colorIdx = 0; colorIdx < ${pulsingBorderMeta.maxColorCount}; colorIdx++) {
|
|
174
178
|
if (colorIdx >= int(u_colorsCount)) break;
|
|
175
179
|
float colorIdxF = float(colorIdx);
|
|
@@ -196,9 +200,10 @@ void main() {
|
|
|
196
200
|
mask = mix(mask, pulse, p);
|
|
197
201
|
|
|
198
202
|
float atg1 = fract(angle + time);
|
|
199
|
-
float spotSize = .05 + .
|
|
200
|
-
spotSize = mix(spotSize, .1, p);
|
|
203
|
+
float spotSize = (.05 + .05 * randVal.x) * spotShrink + spotGrow;
|
|
204
|
+
spotSize = max(mix(spotSize, .1, p), 1e-3);
|
|
201
205
|
float sector = sst(.5 - spotSize, .5, atg1) * (1. - sst(.5, .5 + spotSize, atg1));
|
|
206
|
+
sector *= spotShrink;
|
|
202
207
|
|
|
203
208
|
sector *= mask;
|
|
204
209
|
sector *= border;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/pulsing-border.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, colorBandingFix } from '../shader-utils.js';\n\nexport const pulsingBorderMeta = {\n maxColorCount: 5,\n maxSpots: 4,\n} as const;\n\n/**\n * Luminous trails of color merging into a glowing gradient contour.\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 5 spot colors in RGBA\n * - u_colorsCount (float): Number of active colors\n * - u_roundness (float): Border radius (0 to 1)\n * - u_thickness (float): Border base width (0 to 1)\n * - u_softness (float): Border edge sharpness, 0 = hard edge, 1 = smooth gradient (0 to 1)\n * - u_marginLeft (float): Distance from the left edge to the effect (0 to 1)\n * - u_marginRight (float): Distance from the right edge to the effect (0 to 1)\n * - u_marginTop (float): Distance from the top edge to the effect (0 to 1)\n * - u_marginBottom (float): Distance from the bottom edge to the effect (0 to 1)\n * - u_aspectRatio (float): Aspect ratio mode (0 = auto, 1 = square)\n * - u_intensity (float): Thickness of individual color spots (0 to 1)\n * - u_bloom (float): Power of glow, 0 = normal blending, 1 = additive blending (0 to 1)\n * - u_spots (float): Number of spots added for each color (1 to 4)\n * - u_spotSize (float): Angular size of spots (0 to 1)\n * - u_pulse (float): Optional pulsing animation intensity (0 to 1)\n * - u_smoke (float): Optional noisy shape extending the border (0 to 1)\n * - u_smokeSize (float): Size of the smoke effect, needs smoke > 0 (0 to 1)\n * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_responsiveUV (vec2): Responsive UV coordinates that adapt to canvas aspect ratio\n * - v_responsiveBoxGivenSize (vec2): Given size of the responsive bounding box\n * - v_patternUV (vec2): UV coordinates for pattern with global sizing (rotation, scale, offset, etc) applied (used for smoke calculation)\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 pulsingBorderFragmentShader: string = `#version 300 es\nprecision lowp float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${ pulsingBorderMeta.maxColorCount }];\nuniform float u_colorsCount;\nuniform float u_roundness;\nuniform float u_thickness;\nuniform float u_marginLeft;\nuniform float u_marginRight;\nuniform float u_marginTop;\nuniform float u_marginBottom;\nuniform float u_aspectRatio;\nuniform float u_softness;\nuniform float u_intensity;\nuniform float u_bloom;\nuniform float u_spotSize;\nuniform float u_spots;\nuniform float u_pulse;\nuniform float u_smoke;\nuniform float u_smokeSize;\n\nuniform sampler2D u_noiseTexture;\n\nin vec2 v_responsiveUV;\nin vec2 v_responsiveBoxGivenSize;\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n\nfloat beat(float time) {\n float first = pow(abs(sin(time * TWO_PI)), 10.);\n float second = pow(abs(sin((time - .15) * TWO_PI)), 10.);\n\n return clamp(first + 0.6 * second, 0.0, 1.0);\n}\n\nfloat sst(float edge0, float edge1, float x) {\n return smoothstep(edge0, edge1, x);\n}\n\nfloat roundedBox(vec2 uv, vec2 halfSize, float distance, float cornerDistance, float thickness, float softness) {\n float borderDistance = abs(distance);\n float aa = 2. * fwidth(distance);\n float border = 1. - sst(min(mix(thickness, -thickness, softness), thickness + aa), max(mix(thickness, -thickness, softness), thickness + aa), borderDistance);\n float cornerFadeCircles = 0.;\n cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv + halfSize) / thickness)));\n cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - vec2(-halfSize.x, halfSize.y)) / thickness)));\n cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - vec2(halfSize.x, -halfSize.y)) / thickness)));\n cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - halfSize) / thickness)));\n aa = fwidth(cornerDistance);\n float cornerFade = sst(0., mix(aa, thickness, softness), cornerDistance);\n cornerFade *= cornerFadeCircles;\n border += cornerFade;\n return border;\n}\n\n${ textureRandomizerGB }\n\nfloat randomG(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, fract(uv)).g;\n}\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = randomG(i);\n float b = randomG(i + vec2(1.0, 0.0));\n float c = randomG(i + vec2(0.0, 1.0));\n float d = randomG(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\nvoid main() {\n const float firstFrameOffset = 109.;\n float t = 1.2 * (u_time + firstFrameOffset);\n\n vec2 borderUV = v_responsiveUV;\n float pulse = u_pulse * beat(.18 * u_time);\n\n float canvasRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;\n vec2 halfSize = vec2(.5);\n borderUV.x *= max(canvasRatio, 1.);\n borderUV.y /= min(canvasRatio, 1.);\n halfSize.x *= max(canvasRatio, 1.);\n halfSize.y /= min(canvasRatio, 1.);\n\n float mL = u_marginLeft;\n float mR = u_marginRight;\n float mT = u_marginTop;\n float mB = u_marginBottom;\n float mX = mL + mR;\n float mY = mT + mB;\n\n if (u_aspectRatio > 0.) {\n float shapeRatio = canvasRatio * (1. - mX) / max(1. - mY, 1e-6);\n float freeX = shapeRatio > 1. ? (1. - mX) * (1. - 1. / max(abs(shapeRatio), 1e-6)) : 0.;\n float freeY = shapeRatio < 1. ? (1. - mY) * (1. - shapeRatio) : 0.;\n mL += freeX * 0.5;\n mR += freeX * 0.5;\n mT += freeY * 0.5;\n mB += freeY * 0.5;\n mX = mL + mR;\n mY = mT + mB;\n }\n\n float thickness = .5 * u_thickness * min(halfSize.x, halfSize.y);\n\n halfSize.x *= (1. - mX);\n halfSize.y *= (1. - mY);\n\n vec2 centerShift = vec2(\n (mL - mR) * max(canvasRatio, 1.) * 0.5,\n (mB - mT) / min(canvasRatio, 1.) * 0.5\n );\n\n borderUV -= centerShift;\n halfSize -= mix(thickness, 0., u_softness);\n\n float radius = mix(0., min(halfSize.x, halfSize.y), u_roundness);\n vec2 d = abs(borderUV) - halfSize + radius;\n float outsideDistance = length(max(d, .0001)) - radius;\n float insideDistance = min(max(d.x, d.y), .0001);\n float cornerDistance = abs(min(max(d.x, d.y) - .45 * radius, .0));\n float distance = outsideDistance + insideDistance;\n\n float borderThickness = mix(thickness, 3. * thickness, u_softness);\n float border = roundedBox(borderUV, halfSize, distance, cornerDistance, borderThickness, u_softness);\n border = pow(border, 1. + u_softness);\n\n vec2 smokeUV = .3 * u_smokeSize * v_patternUV;\n float smoke = clamp(3. * valueNoise(2.7 * smokeUV + .5 * t), 0., 1.);\n smoke -= valueNoise(3.4 * smokeUV - .5 * t);\n float smokeThickness = thickness + .2;\n smokeThickness = min(.4, max(smokeThickness, .1));\n smoke *= roundedBox(borderUV, halfSize, distance, cornerDistance, smokeThickness, 1.);\n smoke = 30. * smoke * smoke;\n smoke *= mix(0., .5, pow(u_smoke, 2.));\n smoke *= mix(1., pulse, u_pulse);\n smoke = clamp(smoke, 0., 1.);\n border += smoke;\n\n border = clamp(border, 0., 1.);\n\n vec3 blendColor = vec3(0.);\n float blendAlpha = 0.;\n vec3 addColor = vec3(0.);\n float addAlpha = 0.;\n\n float bloom = 4. * u_bloom;\n float intensity = 1. + (1. + 4. * u_softness) * u_intensity;\n\n float angle = atan(borderUV.y, borderUV.x) / TWO_PI;\n\n for (int colorIdx = 0; colorIdx < ${ pulsingBorderMeta.maxColorCount }; colorIdx++) {\n if (colorIdx >= int(u_colorsCount)) break;\n float colorIdxF = float(colorIdx);\n\n vec3 c = u_colors[colorIdx].rgb * u_colors[colorIdx].a;\n float a = u_colors[colorIdx].a;\n\n for (int spotIdx = 0; spotIdx < ${ pulsingBorderMeta.maxSpots }; spotIdx++) {\n if (spotIdx >= int(u_spots)) break;\n float spotIdxF = float(spotIdx);\n\n vec2 randVal = randomGB(vec2(spotIdxF * 10. + 2., 40. + colorIdxF));\n\n float time = (.1 + .15 * abs(sin(spotIdxF * (2. + colorIdxF)) * cos(spotIdxF * (2. + 2.5 * colorIdxF)))) * t + randVal.x * 3.;\n time *= mix(1., -1., step(.5, randVal.y));\n\n float mask = .5 + .5 * mix(\n sin(t + spotIdxF * (5. - 1.5 * colorIdxF)),\n cos(t + spotIdxF * (3. + 1.3 * colorIdxF)),\n step(mod(colorIdxF, 2.), .5)\n );\n\n float p = clamp(2. * u_pulse - randVal.x, 0., 1.);\n mask = mix(mask, pulse, p);\n\n float atg1 = fract(angle + time);\n float spotSize = .05 + .6 * pow(u_spotSize, 2.) + .05 * randVal.x;\n spotSize = mix(spotSize, .1, p);\n float sector = sst(.5 - spotSize, .5, atg1) * (1. - sst(.5, .5 + spotSize, atg1));\n\n sector *= mask;\n sector *= border;\n sector *= intensity;\n sector = clamp(sector, 0., 1.);\n\n vec3 srcColor = c * sector;\n float srcAlpha = a * sector;\n\n blendColor += ((1. - blendAlpha) * srcColor);\n blendAlpha = blendAlpha + (1. - blendAlpha) * srcAlpha;\n addColor += srcColor;\n addAlpha += srcAlpha;\n }\n }\n\n vec3 accumColor = mix(blendColor, addColor, bloom);\n float accumAlpha = mix(blendAlpha, addAlpha, bloom);\n accumAlpha = clamp(accumAlpha, 0., 1.);\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n vec3 color = accumColor + (1. - accumAlpha) * bgColor;\n float opacity = accumAlpha + (1. - accumAlpha) * u_colorBack.a;\n\n ${ colorBandingFix }\n\n fragColor = vec4(color, opacity);\n}`;\n\nexport interface PulsingBorderUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_roundness: number;\n u_thickness: number;\n u_marginLeft: number;\n u_marginRight: number;\n u_marginTop: number;\n u_marginBottom: number;\n u_aspectRatio: (typeof PulsingBorderAspectRatios)[PulsingBorderAspectRatio];\n u_softness: number;\n u_intensity: number;\n u_bloom: number;\n u_spots: number;\n u_spotSize: number;\n u_pulse: number;\n u_smoke: number;\n u_smokeSize: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface PulsingBorderParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n roundness?: number;\n thickness?: number;\n margin?: number;\n marginLeft?: number;\n marginRight?: number;\n marginTop?: number;\n marginBottom?: number;\n aspectRatio?: PulsingBorderAspectRatio;\n softness?: number;\n intensity?: number;\n bloom?: number;\n spots?: number;\n spotSize?: number;\n pulse?: number;\n smoke?: number;\n smokeSize?: number;\n}\n\nexport const PulsingBorderAspectRatios = {\n auto: 0,\n square: 1,\n} as const;\n\nexport type PulsingBorderAspectRatio = keyof typeof PulsingBorderAspectRatios;\n"],
|
|
5
|
-
"mappings": ";;;;;AAEA,eAAmE;AACnE,SAAS,WAAW,qBAAqB,uBAAuB;AAEzD,MAAM,oBAAoB;AAAA,EAC/B,eAAe;AAAA,EACf,UAAU;AACZ;AAgDO,MAAM,8BAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAM1B,kBAAkB,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,EA0BtD,SAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6BV,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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, colorBandingFix } from '../shader-utils.js';\n\nexport const pulsingBorderMeta = {\n maxColorCount: 5,\n maxSpots: 4,\n} as const;\n\n/**\n * Luminous trails of color merging into a glowing gradient contour.\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 5 spot colors in RGBA\n * - u_colorsCount (float): Number of active colors\n * - u_roundness (float): Border radius (0 to 1)\n * - u_thickness (float): Border base width (min 0, recommended 0 to 1)\n * - u_softness (float): Border edge sharpness, 0 = hard edge, 1 = smooth gradient (0 to 1)\n * - u_marginLeft (float): Distance from the left edge to the effect (0 to 1)\n * - u_marginRight (float): Distance from the right edge to the effect (0 to 1)\n * - u_marginTop (float): Distance from the top edge to the effect (0 to 1)\n * - u_marginBottom (float): Distance from the bottom edge to the effect (0 to 1)\n * - u_aspectRatio (float): Aspect ratio mode (0 = auto, 1 = square)\n * - u_intensity (float): Thickness of individual color spots, amplified by softness (min 0, recommended 0 to 1)\n * - u_bloom (float): Power of glow, 0 = normal color blending, 1 = fully additive blending (min 0, recommended 0 to 1)\n * - u_spots (float): Number of spots added for each color (1 to 4, integer)\n * - u_spotSize (float): Angular size of spots (no limits, recommended 0 to 1)\n * - u_pulse (float): Optional pulsing animation (0 to 1)\n * - u_smoke (float): Optional noisy shape extending the border shape (min 0, recommended 0 to 1)\n * - u_smokeSize (float): Size of the smoke effect, needs smoke > 0 (min 0, recommended 0 to 1)\n * - u_noiseTexture (sampler2D): Pre-computed randomizer source texture\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_responsiveUV (vec2): Responsive UV coordinates that adapt to canvas aspect ratio\n * - v_responsiveBoxGivenSize (vec2): Given size of the responsive bounding box\n * - v_patternUV (vec2): UV coordinates for pattern with global sizing (rotation, scale, offset, etc) applied (used for smoke calculation)\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 pulsingBorderFragmentShader: string = `#version 300 es\nprecision lowp float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${ pulsingBorderMeta.maxColorCount }];\nuniform float u_colorsCount;\nuniform float u_roundness;\nuniform float u_thickness;\nuniform float u_marginLeft;\nuniform float u_marginRight;\nuniform float u_marginTop;\nuniform float u_marginBottom;\nuniform float u_aspectRatio;\nuniform float u_softness;\nuniform float u_intensity;\nuniform float u_bloom;\nuniform float u_spotSize;\nuniform float u_spots;\nuniform float u_pulse;\nuniform float u_smoke;\nuniform float u_smokeSize;\n\nuniform sampler2D u_noiseTexture;\n\nin vec2 v_responsiveUV;\nin vec2 v_responsiveBoxGivenSize;\nin vec2 v_patternUV;\n\nout vec4 fragColor;\n\n${ declarePI }\n\nfloat beat(float time) {\n float first = pow(abs(sin(time * TWO_PI)), 10.);\n float second = pow(abs(sin((time - .15) * TWO_PI)), 10.);\n\n return clamp(first + 0.6 * second, 0.0, 1.0);\n}\n\nfloat sst(float edge0, float edge1, float x) {\n return smoothstep(edge0, edge1, x);\n}\n\nfloat roundedBox(vec2 uv, vec2 halfSize, float distance, float cornerDistance, float thickness, float softness) {\n float borderDistance = abs(distance);\n float aa = 2. * fwidth(distance);\n float border = 1. - sst(min(mix(thickness, -thickness, softness), thickness + aa), max(mix(thickness, -thickness, softness), thickness + aa), borderDistance);\n float cornerFadeCircles = 0.;\n cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv + halfSize) / thickness)));\n cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - vec2(-halfSize.x, halfSize.y)) / thickness)));\n cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - vec2(halfSize.x, -halfSize.y)) / thickness)));\n cornerFadeCircles = mix(1., cornerFadeCircles, sst(0., 1., length((uv - halfSize) / thickness)));\n aa = fwidth(cornerDistance);\n float cornerFade = sst(0., mix(aa, thickness, softness), cornerDistance);\n cornerFade *= cornerFadeCircles;\n border += cornerFade;\n return border;\n}\n\n${ textureRandomizerGB }\n\nfloat randomG(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, fract(uv)).g;\n}\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = randomG(i);\n float b = randomG(i + vec2(1.0, 0.0));\n float c = randomG(i + vec2(0.0, 1.0));\n float d = randomG(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\nvoid main() {\n const float firstFrameOffset = 109.;\n float t = 1.2 * (u_time + firstFrameOffset);\n\n vec2 borderUV = v_responsiveUV;\n float pulse = u_pulse * beat(.18 * u_time);\n\n float canvasRatio = v_responsiveBoxGivenSize.x / v_responsiveBoxGivenSize.y;\n vec2 halfSize = vec2(.5);\n borderUV.x *= max(canvasRatio, 1.);\n borderUV.y /= min(canvasRatio, 1.);\n halfSize.x *= max(canvasRatio, 1.);\n halfSize.y /= min(canvasRatio, 1.);\n\n float mL = u_marginLeft;\n float mR = u_marginRight;\n float mT = u_marginTop;\n float mB = u_marginBottom;\n float mX = mL + mR;\n float mY = mT + mB;\n\n if (u_aspectRatio > 0.) {\n float shapeRatio = canvasRatio * (1. - mX) / max(1. - mY, 1e-6);\n float freeX = shapeRatio > 1. ? (1. - mX) * (1. - 1. / max(abs(shapeRatio), 1e-6)) : 0.;\n float freeY = shapeRatio < 1. ? (1. - mY) * (1. - shapeRatio) : 0.;\n mL += freeX * 0.5;\n mR += freeX * 0.5;\n mT += freeY * 0.5;\n mB += freeY * 0.5;\n mX = mL + mR;\n mY = mT + mB;\n }\n\n float thickness = .5 * u_thickness * min(halfSize.x, halfSize.y);\n\n halfSize.x *= (1. - mX);\n halfSize.y *= (1. - mY);\n\n vec2 centerShift = vec2(\n (mL - mR) * max(canvasRatio, 1.) * 0.5,\n (mB - mT) / min(canvasRatio, 1.) * 0.5\n );\n\n borderUV -= centerShift;\n halfSize -= mix(thickness, 0., u_softness);\n\n float radius = mix(0., min(halfSize.x, halfSize.y), u_roundness);\n vec2 d = abs(borderUV) - halfSize + radius;\n float outsideDistance = length(max(d, .0001)) - radius;\n float insideDistance = min(max(d.x, d.y), .0001);\n float cornerDistance = abs(min(max(d.x, d.y) - .45 * radius, .0));\n float distance = outsideDistance + insideDistance;\n\n float borderThickness = mix(thickness, 3. * thickness, u_softness);\n float border = roundedBox(borderUV, halfSize, distance, cornerDistance, borderThickness, u_softness);\n border = pow(border, 1. + u_softness);\n\n vec2 smokeUV = .3 * u_smokeSize * v_patternUV;\n float smoke = clamp(3. * valueNoise(2.7 * smokeUV + .5 * t), 0., 1.);\n smoke -= valueNoise(3.4 * smokeUV - .5 * t);\n float smokeThickness = thickness + .2;\n smokeThickness = min(.4, max(smokeThickness, .1));\n smoke *= roundedBox(borderUV, halfSize, distance, cornerDistance, smokeThickness, 1.);\n smoke = 30. * smoke * smoke;\n smoke *= mix(0., .5, pow(u_smoke, 2.));\n smoke *= mix(1., pulse, u_pulse);\n smoke = clamp(smoke, 0., 1.);\n border += smoke;\n\n border = clamp(border, 0., 1.);\n\n vec3 blendColor = vec3(0.);\n float blendAlpha = 0.;\n vec3 addColor = vec3(0.);\n float addAlpha = 0.;\n\n float bloom = 4. * u_bloom;\n float intensity = 1. + (1. + 4. * u_softness) * u_intensity;\n\n float angle = atan(borderUV.y, borderUV.x) / TWO_PI;\n\n float spotShrink = clamp(1. + u_spotSize, 0., 1.);\n float spotGrow = max(u_spotSize, 0.);\n spotGrow = .6 * spotGrow * spotGrow;\n\n for (int colorIdx = 0; colorIdx < ${ pulsingBorderMeta.maxColorCount }; colorIdx++) {\n if (colorIdx >= int(u_colorsCount)) break;\n float colorIdxF = float(colorIdx);\n\n vec3 c = u_colors[colorIdx].rgb * u_colors[colorIdx].a;\n float a = u_colors[colorIdx].a;\n\n for (int spotIdx = 0; spotIdx < ${ pulsingBorderMeta.maxSpots }; spotIdx++) {\n if (spotIdx >= int(u_spots)) break;\n float spotIdxF = float(spotIdx);\n\n vec2 randVal = randomGB(vec2(spotIdxF * 10. + 2., 40. + colorIdxF));\n\n float time = (.1 + .15 * abs(sin(spotIdxF * (2. + colorIdxF)) * cos(spotIdxF * (2. + 2.5 * colorIdxF)))) * t + randVal.x * 3.;\n time *= mix(1., -1., step(.5, randVal.y));\n\n float mask = .5 + .5 * mix(\n sin(t + spotIdxF * (5. - 1.5 * colorIdxF)),\n cos(t + spotIdxF * (3. + 1.3 * colorIdxF)),\n step(mod(colorIdxF, 2.), .5)\n );\n\n float p = clamp(2. * u_pulse - randVal.x, 0., 1.);\n mask = mix(mask, pulse, p);\n\n float atg1 = fract(angle + time);\n float spotSize = (.05 + .05 * randVal.x) * spotShrink + spotGrow;\n spotSize = max(mix(spotSize, .1, p), 1e-3);\n float sector = sst(.5 - spotSize, .5, atg1) * (1. - sst(.5, .5 + spotSize, atg1));\n sector *= spotShrink;\n\n sector *= mask;\n sector *= border;\n sector *= intensity;\n sector = clamp(sector, 0., 1.);\n\n vec3 srcColor = c * sector;\n float srcAlpha = a * sector;\n\n blendColor += ((1. - blendAlpha) * srcColor);\n blendAlpha = blendAlpha + (1. - blendAlpha) * srcAlpha;\n addColor += srcColor;\n addAlpha += srcAlpha;\n }\n }\n\n vec3 accumColor = mix(blendColor, addColor, bloom);\n float accumAlpha = mix(blendAlpha, addAlpha, bloom);\n accumAlpha = clamp(accumAlpha, 0., 1.);\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n vec3 color = accumColor + (1. - accumAlpha) * bgColor;\n float opacity = accumAlpha + (1. - accumAlpha) * u_colorBack.a;\n\n ${ colorBandingFix }\n\n fragColor = vec4(color, opacity);\n}`;\n\nexport interface PulsingBorderUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_roundness: number;\n u_thickness: number;\n u_marginLeft: number;\n u_marginRight: number;\n u_marginTop: number;\n u_marginBottom: number;\n u_aspectRatio: (typeof PulsingBorderAspectRatios)[PulsingBorderAspectRatio];\n u_softness: number;\n u_intensity: number;\n u_bloom: number;\n u_spots: number;\n u_spotSize: number;\n u_pulse: number;\n u_smoke: number;\n u_smokeSize: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface PulsingBorderParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n roundness?: number;\n thickness?: number;\n margin?: number;\n marginLeft?: number;\n marginRight?: number;\n marginTop?: number;\n marginBottom?: number;\n aspectRatio?: PulsingBorderAspectRatio;\n softness?: number;\n intensity?: number;\n bloom?: number;\n spots?: number;\n spotSize?: number;\n pulse?: number;\n smoke?: number;\n smokeSize?: number;\n}\n\nexport const PulsingBorderAspectRatios = {\n auto: 0,\n square: 1,\n} as const;\n\nexport type PulsingBorderAspectRatio = keyof typeof PulsingBorderAspectRatios;\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA,eAAmE;AACnE,SAAS,WAAW,qBAAqB,uBAAuB;AAEzD,MAAM,oBAAoB;AAAA,EAC/B,eAAe;AAAA,EACf,UAAU;AACZ;AAgDO,MAAM,8BAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAM1B,kBAAkB,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,EA0BtD,SAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA6BV,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAwGgB,kBAAkB,aAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAOhC,kBAAkB,QAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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+C7D,eAAgB;AAAA;AAAA;AAAA;AAgDd,MAAM,4BAA4B;AAAA,EACvC,MAAM;AAAA,EACN,QAAQ;AACV;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -11,8 +11,8 @@ export declare const simplexNoiseMeta: {
|
|
|
11
11
|
* - u_time (float): Animation time
|
|
12
12
|
* - u_colors (vec4[]): Up to 10 base colors in RGBA
|
|
13
13
|
* - u_colorsCount (float): Number of active colors
|
|
14
|
-
* - u_stepsPerColor (float): Number of extra colors between base colors
|
|
15
|
-
* - u_softness (float): Color transition sharpness
|
|
14
|
+
* - u_stepsPerColor (float): Number of extra colors between base colors (1 = N colors, 2 = 2×N, 3 = 3×N, …), needs 2+ colors (min 1, integer, recommended 1 to 10)
|
|
15
|
+
* - u_softness (float): Color transition sharpness (0 = hard edge, 1 = smooth gradient), needs 2+ colors (0 to 1)
|
|
16
16
|
*
|
|
17
17
|
* Vertex shader outputs (used in fragment shader):
|
|
18
18
|
* - v_patternUV (vec2): UV coordinates for pattern with global sizing (rotation, scale, offset, etc) applied
|
|
@@ -22,13 +22,13 @@ export declare const simplexNoiseMeta: {
|
|
|
22
22
|
* - u_pixelRatio (float): Device pixel ratio
|
|
23
23
|
* - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
|
|
24
24
|
* - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
|
|
25
|
-
* - u_worldWidth (float): Virtual width
|
|
26
|
-
* - u_worldHeight (float): Virtual height
|
|
25
|
+
* - u_worldWidth (float): Virtual graphic width before scaling to fit the canvas
|
|
26
|
+
* - u_worldHeight (float): Virtual graphic height before scaling to fit the canvas
|
|
27
27
|
* - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
|
|
28
|
-
* - u_scale (float): Overall zoom level of the graphics
|
|
29
|
-
* - u_rotation (float): Overall rotation angle of the graphics in degrees
|
|
30
|
-
* - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
|
|
31
|
-
* - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
|
|
28
|
+
* - u_scale (float): Overall zoom level of the graphics
|
|
29
|
+
* - u_rotation (float): Overall rotation angle of the graphics in degrees
|
|
30
|
+
* - u_offsetX (float): Horizontal offset of the graphics center (no limits, recommended -1 to 1)
|
|
31
|
+
* - u_offsetY (float): Vertical offset of the graphics center (no limits, recommended -1 to 1)
|
|
32
32
|
*
|
|
33
33
|
*/
|
|
34
34
|
export declare const simplexNoiseFragmentShader: string;
|
|
@@ -35,7 +35,9 @@ float steppedSmooth(float m, float steps, float softness) {
|
|
|
35
35
|
float stepT = floor(m * steps) / steps;
|
|
36
36
|
float f = m * steps - floor(m * steps);
|
|
37
37
|
float fw = steps * fwidth(m);
|
|
38
|
-
float
|
|
38
|
+
float s = clamp(softness, 0., .5);
|
|
39
|
+
float smoothed = smoothstep(.5 - s, min(1., .5 + s + fw), f);
|
|
40
|
+
smoothed = mix(smoothed, f, clamp(2. * softness - 1., 0., 1.));
|
|
39
41
|
return stepT + smoothed / steps;
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -57,7 +59,7 @@ void main() {
|
|
|
57
59
|
if (i >= int(u_colorsCount)) break;
|
|
58
60
|
|
|
59
61
|
float localM = clamp(mixer - float(i - 1), 0., 1.);
|
|
60
|
-
localM = steppedSmooth(localM, steps,
|
|
62
|
+
localM = steppedSmooth(localM, steps, u_softness);
|
|
61
63
|
|
|
62
64
|
vec4 c = u_colors[i];
|
|
63
65
|
c.rgb *= c.a;
|
|
@@ -69,7 +71,7 @@ void main() {
|
|
|
69
71
|
if (mixer > (u_colorsCount - 1.)) {
|
|
70
72
|
localM = mixer - (u_colorsCount - 1.);
|
|
71
73
|
}
|
|
72
|
-
localM = steppedSmooth(localM, steps,
|
|
74
|
+
localM = steppedSmooth(localM, steps, u_softness);
|
|
73
75
|
vec4 cFst = u_colors[0];
|
|
74
76
|
cFst.rgb *= cFst.a;
|
|
75
77
|
vec4 cLast = u_colors[int(u_colorsCount - 1.)];
|