@paper-design/shaders 0.0.0-canary.390a3d9
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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/get-empty-pixel.d.ts +1 -0
- package/dist/get-empty-pixel.js +19 -0
- package/dist/get-empty-pixel.js.map +7 -0
- package/dist/get-shader-color-from-string.d.ts +3 -0
- package/dist/get-shader-color-from-string.js +93 -0
- package/dist/get-shader-color-from-string.js.map +7 -0
- package/dist/get-shader-noise-texture.d.ts +1 -0
- package/dist/get-shader-noise-texture.js +19 -0
- package/dist/get-shader-noise-texture.js.map +7 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +168 -0
- package/dist/index.js.map +7 -0
- package/dist/shader-color-spaces.d.ts +6 -0
- package/dist/shader-color-spaces.js +96 -0
- package/dist/shader-color-spaces.js.map +7 -0
- package/dist/shader-mount.d.ts +130 -0
- package/dist/shader-mount.js +483 -0
- package/dist/shader-mount.js.map +7 -0
- package/dist/shader-sizing.d.ts +35 -0
- package/dist/shader-sizing.js +230 -0
- package/dist/shader-sizing.js.map +7 -0
- package/dist/shader-utils.d.ts +10 -0
- package/dist/shader-utils.js +131 -0
- package/dist/shader-utils.js.map +7 -0
- package/dist/shaders/color-panels.d.ts +50 -0
- package/dist/shaders/color-panels.js +224 -0
- package/dist/shaders/color-panels.js.map +7 -0
- package/dist/shaders/dithering.d.ts +56 -0
- package/dist/shaders/dithering.js +223 -0
- package/dist/shaders/dithering.js.map +7 -0
- package/dist/shaders/dot-grid.d.ts +51 -0
- package/dist/shaders/dot-grid.js +110 -0
- package/dist/shaders/dot-grid.js.map +7 -0
- package/dist/shaders/dot-orbit.d.ts +39 -0
- package/dist/shaders/dot-orbit.js +124 -0
- package/dist/shaders/dot-orbit.js.map +7 -0
- package/dist/shaders/fluted-glass.d.ts +73 -0
- package/dist/shaders/fluted-glass.js +187 -0
- package/dist/shaders/fluted-glass.js.map +7 -0
- package/dist/shaders/god-rays.d.ts +45 -0
- package/dist/shaders/god-rays.js +133 -0
- package/dist/shaders/god-rays.js.map +7 -0
- package/dist/shaders/grain-gradient.d.ts +58 -0
- package/dist/shaders/grain-gradient.js +289 -0
- package/dist/shaders/grain-gradient.js.map +7 -0
- package/dist/shaders/heatmap.d.ts +31 -0
- package/dist/shaders/heatmap.js +303 -0
- package/dist/shaders/heatmap.js.map +7 -0
- package/dist/shaders/image-dithering.d.ts +49 -0
- package/dist/shaders/image-dithering.js +163 -0
- package/dist/shaders/image-dithering.js.map +7 -0
- package/dist/shaders/image-halftone-dots.d.ts +46 -0
- package/dist/shaders/image-halftone-dots.js +337 -0
- package/dist/shaders/image-halftone-dots.js.map +7 -0
- package/dist/shaders/liquid-metal.d.ts +66 -0
- package/dist/shaders/liquid-metal.js +627 -0
- package/dist/shaders/liquid-metal.js.map +7 -0
- package/dist/shaders/mesh-gradient.d.ts +33 -0
- package/dist/shaders/mesh-gradient.js +136 -0
- package/dist/shaders/mesh-gradient.js.map +7 -0
- package/dist/shaders/metaballs.d.ts +35 -0
- package/dist/shaders/metaballs.js +112 -0
- package/dist/shaders/metaballs.js.map +7 -0
- package/dist/shaders/neuro-noise.d.ts +27 -0
- package/dist/shaders/neuro-noise.js +80 -0
- package/dist/shaders/neuro-noise.js.map +7 -0
- package/dist/shaders/paper-texture.d.ts +53 -0
- package/dist/shaders/paper-texture.js +248 -0
- package/dist/shaders/paper-texture.js.map +7 -0
- package/dist/shaders/perlin-noise.d.ts +33 -0
- package/dist/shaders/perlin-noise.js +195 -0
- package/dist/shaders/perlin-noise.js.map +7 -0
- package/dist/shaders/pulsing-border.d.ts +72 -0
- package/dist/shaders/pulsing-border.js +237 -0
- package/dist/shaders/pulsing-border.js.map +7 -0
- package/dist/shaders/simplex-noise.d.ts +27 -0
- package/dist/shaders/simplex-noise.js +100 -0
- package/dist/shaders/simplex-noise.js.map +7 -0
- package/dist/shaders/smoke-ring.d.ts +39 -0
- package/dist/shaders/smoke-ring.js +130 -0
- package/dist/shaders/smoke-ring.js.map +7 -0
- package/dist/shaders/spiral.d.ts +41 -0
- package/dist/shaders/spiral.js +81 -0
- package/dist/shaders/spiral.js.map +7 -0
- package/dist/shaders/static-mesh-gradient.d.ts +42 -0
- package/dist/shaders/static-mesh-gradient.js +139 -0
- package/dist/shaders/static-mesh-gradient.js.map +7 -0
- package/dist/shaders/static-radial-gradient.d.ts +50 -0
- package/dist/shaders/static-radial-gradient.js +195 -0
- package/dist/shaders/static-radial-gradient.js.map +7 -0
- package/dist/shaders/swirl.d.ts +42 -0
- package/dist/shaders/swirl.js +102 -0
- package/dist/shaders/swirl.js.map +7 -0
- package/dist/shaders/voronoi.d.ts +44 -0
- package/dist/shaders/voronoi.js +139 -0
- package/dist/shaders/voronoi.js.map +7 -0
- package/dist/shaders/warp.d.ts +54 -0
- package/dist/shaders/warp.js +132 -0
- package/dist/shaders/warp.js.map +7 -0
- package/dist/shaders/water.d.ts +39 -0
- package/dist/shaders/water.js +120 -0
- package/dist/shaders/water.js.map +7 -0
- package/dist/shaders/waves.d.ts +38 -0
- package/dist/shaders/waves.js +66 -0
- package/dist/shaders/waves.js.map +7 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +7 -0
- package/dist/vertex-shader.d.ts +2 -0
- package/dist/vertex-shader.js +211 -0
- package/dist/vertex-shader.js.map +7 -0
- package/package.json +27 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
+
import { declarePI, rotation2, textureRandomizerR, colorBandingFix, proceduralHash11 } from "../shader-utils.js";
|
|
8
|
+
const godRaysMeta = {
|
|
9
|
+
maxColorCount: 5
|
|
10
|
+
};
|
|
11
|
+
const godRaysFragmentShader = `#version 300 es
|
|
12
|
+
precision mediump float;
|
|
13
|
+
|
|
14
|
+
uniform float u_time;
|
|
15
|
+
|
|
16
|
+
uniform sampler2D u_noiseTexture;
|
|
17
|
+
|
|
18
|
+
uniform vec4 u_colorBack;
|
|
19
|
+
uniform vec4 u_colorBloom;
|
|
20
|
+
uniform vec4 u_colors[${godRaysMeta.maxColorCount}];
|
|
21
|
+
uniform float u_colorsCount;
|
|
22
|
+
|
|
23
|
+
uniform float u_density;
|
|
24
|
+
uniform float u_spotty;
|
|
25
|
+
uniform float u_midSize;
|
|
26
|
+
uniform float u_midIntensity;
|
|
27
|
+
uniform float u_intensity;
|
|
28
|
+
uniform float u_bloom;
|
|
29
|
+
|
|
30
|
+
${sizingVariablesDeclaration}
|
|
31
|
+
|
|
32
|
+
out vec4 fragColor;
|
|
33
|
+
|
|
34
|
+
${declarePI}
|
|
35
|
+
${rotation2}
|
|
36
|
+
${textureRandomizerR}
|
|
37
|
+
float valueNoise(vec2 st) {
|
|
38
|
+
vec2 i = floor(st);
|
|
39
|
+
vec2 f = fract(st);
|
|
40
|
+
float a = randomR(i);
|
|
41
|
+
float b = randomR(i + vec2(1.0, 0.0));
|
|
42
|
+
float c = randomR(i + vec2(0.0, 1.0));
|
|
43
|
+
float d = randomR(i + vec2(1.0, 1.0));
|
|
44
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
45
|
+
float x1 = mix(a, b, u.x);
|
|
46
|
+
float x2 = mix(c, d, u.x);
|
|
47
|
+
return mix(x1, x2, u.y);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
${proceduralHash11}
|
|
51
|
+
|
|
52
|
+
float raysShape(vec2 uv, float r, float freq, float intensity, float radius) {
|
|
53
|
+
float a = atan(uv.y, uv.x);
|
|
54
|
+
vec2 left = vec2(a * freq, r);
|
|
55
|
+
vec2 right = vec2(fract(a / TWO_PI) * TWO_PI * freq, r);
|
|
56
|
+
float n_left = pow(valueNoise(left), intensity);
|
|
57
|
+
float n_right = pow(valueNoise(right), intensity);
|
|
58
|
+
float shape = mix(n_right, n_left, smoothstep(-.15, .15, uv.x));
|
|
59
|
+
return shape;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void main() {
|
|
63
|
+
vec2 shape_uv = v_objectUV;
|
|
64
|
+
|
|
65
|
+
float t = .2 * u_time;
|
|
66
|
+
|
|
67
|
+
float radius = length(shape_uv);
|
|
68
|
+
float spots = 6.5 * abs(u_spotty);
|
|
69
|
+
|
|
70
|
+
float intensity = 4. - 3. * clamp(u_intensity, 0., 1.);
|
|
71
|
+
|
|
72
|
+
float delta = 1. - smoothstep(0., 1., radius);
|
|
73
|
+
|
|
74
|
+
float midSize = 10. * abs(u_midSize);
|
|
75
|
+
float ms_lo = 0.02 * midSize;
|
|
76
|
+
float ms_hi = max(midSize, 1e-6);
|
|
77
|
+
float middleShape = pow(u_midIntensity, 0.3) * (1. - smoothstep(ms_lo, ms_hi, 3.0 * radius));
|
|
78
|
+
middleShape = pow(middleShape, 5.0);
|
|
79
|
+
|
|
80
|
+
vec3 accumColor = vec3(0.0);
|
|
81
|
+
float accumAlpha = 0.0;
|
|
82
|
+
|
|
83
|
+
for (int i = 0; i < ${godRaysMeta.maxColorCount}; i++) {
|
|
84
|
+
if (i >= int(u_colorsCount)) break;
|
|
85
|
+
|
|
86
|
+
vec2 rotatedUV = rotate(shape_uv, float(i) + 1.0);
|
|
87
|
+
|
|
88
|
+
float r1 = radius * (1.0 + 0.4 * float(i)) - 3.0 * t;
|
|
89
|
+
float r2 = 0.5 * radius * (1.0 + spots) - 2.0 * t;
|
|
90
|
+
float density = 6. * u_density + step(.5, u_density) * pow(4.5 * (u_density - .5), 4.);
|
|
91
|
+
float f = mix(1.0, 3.0 + 0.5 * float(i), hash11(float(i) * 15.)) * density;
|
|
92
|
+
|
|
93
|
+
float ray = raysShape(rotatedUV, r1, 5.0 * f, intensity, radius);
|
|
94
|
+
ray *= raysShape(rotatedUV, r2, 4.0 * f, intensity, radius);
|
|
95
|
+
ray += (1. + 4. * ray) * middleShape;
|
|
96
|
+
ray = clamp(ray, 0.0, 1.0);
|
|
97
|
+
|
|
98
|
+
float srcAlpha = u_colors[i].a * ray;
|
|
99
|
+
vec3 srcColor = u_colors[i].rgb * srcAlpha;
|
|
100
|
+
|
|
101
|
+
vec3 alphaBlendColor = accumColor + (1.0 - accumAlpha) * srcColor;
|
|
102
|
+
float alphaBlendAlpha = accumAlpha + (1.0 - accumAlpha) * srcAlpha;
|
|
103
|
+
|
|
104
|
+
vec3 addBlendColor = accumColor + srcColor;
|
|
105
|
+
float addBlendAlpha = accumAlpha + srcAlpha;
|
|
106
|
+
|
|
107
|
+
accumColor = mix(alphaBlendColor, addBlendColor, u_bloom);
|
|
108
|
+
accumAlpha = mix(alphaBlendAlpha, addBlendAlpha, u_bloom);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
float overlayAlpha = u_colorBloom.a;
|
|
112
|
+
vec3 overlayColor = u_colorBloom.rgb * overlayAlpha;
|
|
113
|
+
|
|
114
|
+
vec3 colorWithOverlay = accumColor + accumAlpha * overlayColor;
|
|
115
|
+
accumColor = mix(accumColor, colorWithOverlay, u_bloom);
|
|
116
|
+
|
|
117
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
118
|
+
|
|
119
|
+
vec3 color = accumColor + (1. - accumAlpha) * bgColor;
|
|
120
|
+
float opacity = accumAlpha + (1. - accumAlpha) * u_colorBack.a;
|
|
121
|
+
color = clamp(color, 0., 1.);
|
|
122
|
+
opacity = clamp(opacity, 0., 1.);
|
|
123
|
+
|
|
124
|
+
${colorBandingFix}
|
|
125
|
+
|
|
126
|
+
fragColor = vec4(color, opacity);
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
export {
|
|
130
|
+
godRaysFragmentShader,
|
|
131
|
+
godRaysMeta
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=god-rays.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shaders/god-rays.ts"],
|
|
4
|
+
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, rotation2, textureRandomizerR, colorBandingFix, proceduralHash11 } from '../shader-utils.js';\n\nexport const godRaysMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Radial rays animated from center\n *\n * Uniforms:\n * - u_colorBack, u_colorBloom (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_density: frequency of sector shapes\n * - u_intensity: rays visibility within sectors\n * - u_spotty: density of spots on the ray (higher = more spots)\n * - u_midSize, u_midIntensity: central shape over the rays\n * - u_bloom (0..1): normal to additive blending mix\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n */\n\n// language=GLSL\nexport const godRaysFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorBloom;\nuniform vec4 u_colors[${godRaysMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_density;\nuniform float u_spotty;\nuniform float u_midSize;\nuniform float u_midIntensity;\nuniform float u_intensity;\nuniform float u_bloom;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${rotation2}\n${textureRandomizerR}\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = randomR(i);\n float b = randomR(i + vec2(1.0, 0.0));\n float c = randomR(i + vec2(0.0, 1.0));\n float d = randomR(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\n\n${proceduralHash11}\n\nfloat raysShape(vec2 uv, float r, float freq, float intensity, float radius) {\n float a = atan(uv.y, uv.x);\n vec2 left = vec2(a * freq, r);\n vec2 right = vec2(fract(a / TWO_PI) * TWO_PI * freq, r);\n float n_left = pow(valueNoise(left), intensity);\n float n_right = pow(valueNoise(right), intensity);\n float shape = mix(n_right, n_left, smoothstep(-.15, .15, uv.x));\n return shape;\n}\n\nvoid main() {\n vec2 shape_uv = v_objectUV;\n\n float t = .2 * u_time;\n\n float radius = length(shape_uv);\n float spots = 6.5 * abs(u_spotty);\n\n float intensity = 4. - 3. * clamp(u_intensity, 0., 1.);\n\n float delta = 1. - smoothstep(0., 1., radius);\n\n float midSize = 10. * abs(u_midSize);\n float ms_lo = 0.02 * midSize;\n float ms_hi = max(midSize, 1e-6);\n float middleShape = pow(u_midIntensity, 0.3) * (1. - smoothstep(ms_lo, ms_hi, 3.0 * radius));\n middleShape = pow(middleShape, 5.0);\n\n vec3 accumColor = vec3(0.0);\n float accumAlpha = 0.0;\n\n for (int i = 0; i < ${godRaysMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n\n vec2 rotatedUV = rotate(shape_uv, float(i) + 1.0);\n\n float r1 = radius * (1.0 + 0.4 * float(i)) - 3.0 * t;\n float r2 = 0.5 * radius * (1.0 + spots) - 2.0 * t;\n float density = 6. * u_density + step(.5, u_density) * pow(4.5 * (u_density - .5), 4.);\n float f = mix(1.0, 3.0 + 0.5 * float(i), hash11(float(i) * 15.)) * density;\n\n float ray = raysShape(rotatedUV, r1, 5.0 * f, intensity, radius);\n ray *= raysShape(rotatedUV, r2, 4.0 * f, intensity, radius);\n ray += (1. + 4. * ray) * middleShape;\n ray = clamp(ray, 0.0, 1.0);\n\n float srcAlpha = u_colors[i].a * ray;\n vec3 srcColor = u_colors[i].rgb * srcAlpha;\n\n vec3 alphaBlendColor = accumColor + (1.0 - accumAlpha) * srcColor;\n float alphaBlendAlpha = accumAlpha + (1.0 - accumAlpha) * srcAlpha;\n\n vec3 addBlendColor = accumColor + srcColor;\n float addBlendAlpha = accumAlpha + srcAlpha;\n\n accumColor = mix(alphaBlendColor, addBlendColor, u_bloom);\n accumAlpha = mix(alphaBlendAlpha, addBlendAlpha, u_bloom);\n }\n\n float overlayAlpha = u_colorBloom.a;\n vec3 overlayColor = u_colorBloom.rgb * overlayAlpha;\n\n vec3 colorWithOverlay = accumColor + accumAlpha * overlayColor;\n accumColor = mix(accumColor, colorWithOverlay, u_bloom);\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n\n vec3 color = accumColor + (1. - accumAlpha) * bgColor;\n float opacity = accumAlpha + (1. - accumAlpha) * u_colorBack.a;\n color = clamp(color, 0., 1.);\n opacity = clamp(opacity, 0., 1.);\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface GodRaysUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorBloom: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_spotty: number;\n u_midSize: number;\n u_midIntensity: number;\n u_density: number;\n u_intensity: number;\n u_bloom: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface GodRaysParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colorBloom?: string;\n colors?: string[];\n spotty?: number;\n midSize?: number;\n midIntensity?: number;\n density?: number;\n intensity?: number;\n bloom?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,WAAW,oBAAoB,iBAAiB,wBAAwB;AAErF,MAAM,cAAc;AAAA,EACzB,eAAe;AACjB;AAkBO,MAAM,wBAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBASrB,YAAY,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU/C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,SAAS;AAAA,EACT,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAclB,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,wBAiCM,YAAY,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAyC7C,eAAe;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { vec4 } from '../types.js';
|
|
2
|
+
import type { ShaderMotionParams } from '../shader-mount.js';
|
|
3
|
+
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
|
|
4
|
+
export declare const grainGradientMeta: {
|
|
5
|
+
readonly maxColorCount: 7;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Multi-color gradient with noise & grain over animated abstract shapes
|
|
9
|
+
*
|
|
10
|
+
* Uniforms:
|
|
11
|
+
* - u_colorBack (RGBA)
|
|
12
|
+
* - u_colors (vec4[]), u_colorsCount (float used as integer)
|
|
13
|
+
* - u_softness (0..1): blur between color bands
|
|
14
|
+
* - u_intensity (0..1): distortion between color bands
|
|
15
|
+
* - u_noise (0..1): grainy noise independent of softness
|
|
16
|
+
* - u_shape (float used as integer):
|
|
17
|
+
* ---- 1: single sine wave
|
|
18
|
+
* ---- 2: dots pattern
|
|
19
|
+
* ---- 3: truchet pattern
|
|
20
|
+
* ---- 4: corners (2 rounded rectangles)
|
|
21
|
+
* ---- 5: ripple
|
|
22
|
+
* ---- 6: blob (metaballs)
|
|
23
|
+
* ---- 7: circle imitating 3d look
|
|
24
|
+
*
|
|
25
|
+
* - u_noiseTexture (sampler2D): pre-computed randomizer source
|
|
26
|
+
*
|
|
27
|
+
* Note: grains are calculated using gl_FragCoord & u_resolution, meaning grains don't react to scaling and fit
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
export declare const grainGradientFragmentShader: string;
|
|
31
|
+
export interface GrainGradientUniforms extends ShaderSizingUniforms {
|
|
32
|
+
u_colorBack: [number, number, number, number];
|
|
33
|
+
u_colors: vec4[];
|
|
34
|
+
u_colorsCount: number;
|
|
35
|
+
u_softness: number;
|
|
36
|
+
u_intensity: number;
|
|
37
|
+
u_noise: number;
|
|
38
|
+
u_shape: (typeof GrainGradientShapes)[GrainGradientShape];
|
|
39
|
+
u_noiseTexture?: HTMLImageElement;
|
|
40
|
+
}
|
|
41
|
+
export interface GrainGradientParams extends ShaderSizingParams, ShaderMotionParams {
|
|
42
|
+
colorBack?: string;
|
|
43
|
+
colors?: string[];
|
|
44
|
+
softness?: number;
|
|
45
|
+
intensity?: number;
|
|
46
|
+
noise?: number;
|
|
47
|
+
shape?: GrainGradientShape;
|
|
48
|
+
}
|
|
49
|
+
export declare const GrainGradientShapes: {
|
|
50
|
+
wave: number;
|
|
51
|
+
dots: number;
|
|
52
|
+
truchet: number;
|
|
53
|
+
corners: number;
|
|
54
|
+
ripple: number;
|
|
55
|
+
blob: number;
|
|
56
|
+
sphere: number;
|
|
57
|
+
};
|
|
58
|
+
export type GrainGradientShape = keyof typeof GrainGradientShapes;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
sizingVariablesDeclaration,
|
|
8
|
+
sizingDebugVariablesDeclaration
|
|
9
|
+
} from "../shader-sizing.js";
|
|
10
|
+
import {
|
|
11
|
+
simplexNoise,
|
|
12
|
+
declarePI,
|
|
13
|
+
rotation2,
|
|
14
|
+
textureRandomizerR,
|
|
15
|
+
proceduralHash21,
|
|
16
|
+
proceduralHash11
|
|
17
|
+
} from "../shader-utils.js";
|
|
18
|
+
const grainGradientMeta = {
|
|
19
|
+
maxColorCount: 7
|
|
20
|
+
};
|
|
21
|
+
const grainGradientFragmentShader = `#version 300 es
|
|
22
|
+
precision lowp float;
|
|
23
|
+
|
|
24
|
+
uniform mediump float u_time;
|
|
25
|
+
uniform mediump vec2 u_resolution;
|
|
26
|
+
uniform mediump float u_pixelRatio;
|
|
27
|
+
|
|
28
|
+
uniform sampler2D u_noiseTexture;
|
|
29
|
+
|
|
30
|
+
uniform vec4 u_colorBack;
|
|
31
|
+
uniform vec4 u_colors[${grainGradientMeta.maxColorCount}];
|
|
32
|
+
uniform float u_colorsCount;
|
|
33
|
+
uniform float u_softness;
|
|
34
|
+
uniform float u_intensity;
|
|
35
|
+
uniform float u_noise;
|
|
36
|
+
uniform float u_shape;
|
|
37
|
+
|
|
38
|
+
uniform mediump float u_originX;
|
|
39
|
+
uniform mediump float u_originY;
|
|
40
|
+
uniform mediump float u_worldWidth;
|
|
41
|
+
uniform mediump float u_worldHeight;
|
|
42
|
+
uniform mediump float u_fit;
|
|
43
|
+
|
|
44
|
+
uniform mediump float u_scale;
|
|
45
|
+
uniform mediump float u_rotation;
|
|
46
|
+
uniform mediump float u_offsetX;
|
|
47
|
+
uniform mediump float u_offsetY;
|
|
48
|
+
|
|
49
|
+
${sizingVariablesDeclaration}
|
|
50
|
+
${sizingDebugVariablesDeclaration}
|
|
51
|
+
|
|
52
|
+
out vec4 fragColor;
|
|
53
|
+
|
|
54
|
+
${declarePI}
|
|
55
|
+
${simplexNoise}
|
|
56
|
+
${rotation2}
|
|
57
|
+
${proceduralHash21}
|
|
58
|
+
${textureRandomizerR}
|
|
59
|
+
|
|
60
|
+
float valueNoiseR(vec2 st) {
|
|
61
|
+
vec2 i = floor(st);
|
|
62
|
+
vec2 f = fract(st);
|
|
63
|
+
float a = randomR(i);
|
|
64
|
+
float b = randomR(i + vec2(1.0, 0.0));
|
|
65
|
+
float c = randomR(i + vec2(0.0, 1.0));
|
|
66
|
+
float d = randomR(i + vec2(1.0, 1.0));
|
|
67
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
68
|
+
float x1 = mix(a, b, u.x);
|
|
69
|
+
float x2 = mix(c, d, u.x);
|
|
70
|
+
return mix(x1, x2, u.y);
|
|
71
|
+
}
|
|
72
|
+
float fbmR(vec2 n) {
|
|
73
|
+
float total = 0.;
|
|
74
|
+
float amplitude = .2;
|
|
75
|
+
for (int i = 0; i < 3; i++) {
|
|
76
|
+
n = rotate(n, .3);
|
|
77
|
+
total += valueNoiseR(n) * amplitude;
|
|
78
|
+
n *= 1.99;
|
|
79
|
+
amplitude *= 0.6;
|
|
80
|
+
}
|
|
81
|
+
return total;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
${proceduralHash11}
|
|
85
|
+
|
|
86
|
+
vec2 truchet(vec2 uv, float idx){
|
|
87
|
+
idx = fract(((idx - .5) * 2.));
|
|
88
|
+
if (idx > 0.75) {
|
|
89
|
+
uv = vec2(1.0) - uv;
|
|
90
|
+
} else if (idx > 0.5) {
|
|
91
|
+
uv = vec2(1.0 - uv.x, uv.y);
|
|
92
|
+
} else if (idx > 0.25) {
|
|
93
|
+
uv = 1.0 - vec2(1.0 - uv.x, uv.y);
|
|
94
|
+
}
|
|
95
|
+
return uv;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void main() {
|
|
99
|
+
|
|
100
|
+
const float firstFrameOffset = 7.;
|
|
101
|
+
float t = .1 * (u_time + firstFrameOffset);
|
|
102
|
+
|
|
103
|
+
vec2 shape_uv = vec2(0.);
|
|
104
|
+
vec2 grain_uv = vec2(0.);
|
|
105
|
+
|
|
106
|
+
if (u_shape > 3.5) {
|
|
107
|
+
shape_uv = v_objectUV;
|
|
108
|
+
grain_uv = shape_uv;
|
|
109
|
+
|
|
110
|
+
// apply inverse transform to grain_uv so it respects the originXY
|
|
111
|
+
float r = u_rotation * 3.14159265358979323846 / 180.;
|
|
112
|
+
mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));
|
|
113
|
+
vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
|
|
114
|
+
grain_uv = transpose(graphicRotation) * grain_uv;
|
|
115
|
+
grain_uv *= u_scale;
|
|
116
|
+
grain_uv -= graphicOffset;
|
|
117
|
+
grain_uv *= v_objectBoxSize;
|
|
118
|
+
grain_uv *= .7;
|
|
119
|
+
} else {
|
|
120
|
+
shape_uv = .5 * v_patternUV;
|
|
121
|
+
grain_uv = 100. * v_patternUV;
|
|
122
|
+
|
|
123
|
+
// apply inverse transform to grain_uv so it respects the originXY
|
|
124
|
+
float r = u_rotation * 3.14159265358979323846 / 180.;
|
|
125
|
+
mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));
|
|
126
|
+
vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
|
|
127
|
+
grain_uv = transpose(graphicRotation) * grain_uv;
|
|
128
|
+
grain_uv *= u_scale;
|
|
129
|
+
if (u_fit > 0.) {
|
|
130
|
+
vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);
|
|
131
|
+
givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;
|
|
132
|
+
float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;
|
|
133
|
+
vec2 patternBoxGivenSize = vec2(
|
|
134
|
+
(u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,
|
|
135
|
+
(u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y
|
|
136
|
+
);
|
|
137
|
+
patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y;
|
|
138
|
+
float patternBoxNoFitBoxWidth = patternBoxRatio * min(patternBoxGivenSize.x / patternBoxRatio, patternBoxGivenSize.y);
|
|
139
|
+
grain_uv /= (patternBoxNoFitBoxWidth / v_patternBoxSize.x);
|
|
140
|
+
}
|
|
141
|
+
vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;
|
|
142
|
+
grain_uv -= graphicOffset / patternBoxScale;
|
|
143
|
+
grain_uv *= 1.6;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
float shape = 0.;
|
|
148
|
+
|
|
149
|
+
if (u_shape < 1.5) {
|
|
150
|
+
// Sine wave
|
|
151
|
+
|
|
152
|
+
float wave = cos(.5 * shape_uv.x - 4. * t) * sin(1.5 * shape_uv.x + 2. * t) * (.75 + .25 * cos(6. * t));
|
|
153
|
+
shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);
|
|
154
|
+
|
|
155
|
+
} else if (u_shape < 2.5) {
|
|
156
|
+
// Grid (dots)
|
|
157
|
+
|
|
158
|
+
float stripeIdx = floor(2. * shape_uv.x / TWO_PI);
|
|
159
|
+
float rand = hash11(stripeIdx * 100.);
|
|
160
|
+
rand = sign(rand - .5) * pow(4. * abs(rand), .3);
|
|
161
|
+
shape = sin(shape_uv.x) * cos(shape_uv.y - 5. * rand * t);
|
|
162
|
+
shape = pow(abs(shape), 4.);
|
|
163
|
+
|
|
164
|
+
} else if (u_shape < 3.5) {
|
|
165
|
+
// Truchet pattern
|
|
166
|
+
|
|
167
|
+
float n2 = valueNoiseR(shape_uv * .4 - 3.75 * t);
|
|
168
|
+
shape_uv.x += 10.;
|
|
169
|
+
shape_uv *= .6;
|
|
170
|
+
|
|
171
|
+
vec2 tile = truchet(fract(shape_uv), randomR(floor(shape_uv)));
|
|
172
|
+
|
|
173
|
+
float distance1 = length(tile);
|
|
174
|
+
float distance2 = length(tile - vec2(1.));
|
|
175
|
+
|
|
176
|
+
n2 -= .5;
|
|
177
|
+
n2 *= .1;
|
|
178
|
+
shape = smoothstep(.2, .55, distance1 + n2) * (1. - smoothstep(.45, .8, distance1 - n2));
|
|
179
|
+
shape += smoothstep(.2, .55, distance2 + n2) * (1. - smoothstep(.45, .8, distance2 - n2));
|
|
180
|
+
|
|
181
|
+
shape = pow(shape, 1.5);
|
|
182
|
+
|
|
183
|
+
} else if (u_shape < 4.5) {
|
|
184
|
+
// Corners
|
|
185
|
+
|
|
186
|
+
shape_uv *= .6;
|
|
187
|
+
vec2 outer = vec2(.5);
|
|
188
|
+
|
|
189
|
+
vec2 bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(3. * t), .2 - .1 * sin(5.25 * t)));
|
|
190
|
+
vec2 tr = smoothstep(vec2(0.), outer, 1. - shape_uv);
|
|
191
|
+
shape = 1. - bl.x * bl.y * tr.x * tr.y;
|
|
192
|
+
|
|
193
|
+
shape_uv = -shape_uv;
|
|
194
|
+
bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(3. * t), .2 - .1 * cos(5.25 * t)));
|
|
195
|
+
tr = smoothstep(vec2(0.), outer, 1. - shape_uv);
|
|
196
|
+
shape -= bl.x * bl.y * tr.x * tr.y;
|
|
197
|
+
|
|
198
|
+
shape = 1. - smoothstep(0., 1., shape);
|
|
199
|
+
|
|
200
|
+
} else if (u_shape < 5.5) {
|
|
201
|
+
// Ripple
|
|
202
|
+
|
|
203
|
+
shape_uv *= 2.;
|
|
204
|
+
float dist = length(.4 * shape_uv);
|
|
205
|
+
float waves = sin(pow(dist, 1.2) * 5. - 3. * t) * .5 + .5;
|
|
206
|
+
shape = waves;
|
|
207
|
+
|
|
208
|
+
} else if (u_shape < 6.5) {
|
|
209
|
+
// Blob
|
|
210
|
+
|
|
211
|
+
t *= 2.;
|
|
212
|
+
|
|
213
|
+
vec2 f1_traj = .25 * vec2(1.3 * sin(t), .2 + 1.3 * cos(.6 * t + 4.));
|
|
214
|
+
vec2 f2_traj = .2 * vec2(1.2 * sin(-t), 1.3 * sin(1.6 * t));
|
|
215
|
+
vec2 f3_traj = .25 * vec2(1.7 * cos(-.6 * t), cos(-1.6 * t));
|
|
216
|
+
vec2 f4_traj = .3 * vec2(1.4 * cos(.8 * t), 1.2 * sin(-.6 * t - 3.));
|
|
217
|
+
|
|
218
|
+
shape = .5 * pow(1. - clamp(0., 1., length(shape_uv + f1_traj)), 5.);
|
|
219
|
+
shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f2_traj)), 5.);
|
|
220
|
+
shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f3_traj)), 5.);
|
|
221
|
+
shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f4_traj)), 5.);
|
|
222
|
+
|
|
223
|
+
shape = smoothstep(.0, .9, shape);
|
|
224
|
+
float edge = smoothstep(.25, .3, shape);
|
|
225
|
+
shape = mix(.0, shape, edge);
|
|
226
|
+
|
|
227
|
+
} else {
|
|
228
|
+
// Sphere
|
|
229
|
+
|
|
230
|
+
shape_uv *= 2.;
|
|
231
|
+
float d = 1. - pow(length(shape_uv), 2.);
|
|
232
|
+
vec3 pos = vec3(shape_uv, sqrt(max(d, 0.)));
|
|
233
|
+
vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));
|
|
234
|
+
shape = .5 + .5 * dot(lightPos, pos);
|
|
235
|
+
shape *= step(0., d);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
float simplex = snoise(grain_uv * .5);
|
|
239
|
+
float grainDist = simplex * snoise(grain_uv * .2) - fbmR(.002 * grain_uv + 10.) - fbmR(.003 * grain_uv);
|
|
240
|
+
float rawNoise = .75 * simplex - fbmR(rotate(.4 * grain_uv, 2.)) - fbmR(.001 * grain_uv);
|
|
241
|
+
float noise = clamp(rawNoise, 0., 1.);
|
|
242
|
+
|
|
243
|
+
shape += u_intensity * 2. / u_colorsCount * (grainDist + .5);
|
|
244
|
+
shape += u_noise * 10. / u_colorsCount * noise;
|
|
245
|
+
|
|
246
|
+
float aa = fwidth(shape);
|
|
247
|
+
|
|
248
|
+
shape = clamp(shape - .5 / u_colorsCount, 0., 1.);
|
|
249
|
+
float totalShape = smoothstep(0., u_softness + 2. * aa, clamp(shape * u_colorsCount, 0., 1.));
|
|
250
|
+
float mixer = shape * (u_colorsCount - 1.);
|
|
251
|
+
|
|
252
|
+
vec4 gradient = u_colors[0];
|
|
253
|
+
gradient.rgb *= gradient.a;
|
|
254
|
+
for (int i = 1; i < ${grainGradientMeta.maxColorCount}; i++) {
|
|
255
|
+
if (i > int(u_colorsCount) - 1) break;
|
|
256
|
+
|
|
257
|
+
float localT = clamp(mixer - float(i - 1), 0., 1.);
|
|
258
|
+
localT = smoothstep(.5 - .5 * u_softness - aa, .5 + .5 * u_softness + aa, localT);
|
|
259
|
+
|
|
260
|
+
vec4 c = u_colors[i];
|
|
261
|
+
c.rgb *= c.a;
|
|
262
|
+
gradient = mix(gradient, c, localT);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
vec3 color = gradient.rgb * totalShape;
|
|
266
|
+
float opacity = gradient.a * totalShape;
|
|
267
|
+
|
|
268
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
269
|
+
color = color + bgColor * (1.0 - opacity);
|
|
270
|
+
opacity = opacity + u_colorBack.a * (1.0 - opacity);
|
|
271
|
+
|
|
272
|
+
fragColor = vec4(color, opacity);
|
|
273
|
+
}
|
|
274
|
+
`;
|
|
275
|
+
const GrainGradientShapes = {
|
|
276
|
+
wave: 1,
|
|
277
|
+
dots: 2,
|
|
278
|
+
truchet: 3,
|
|
279
|
+
corners: 4,
|
|
280
|
+
ripple: 5,
|
|
281
|
+
blob: 6,
|
|
282
|
+
sphere: 7
|
|
283
|
+
};
|
|
284
|
+
export {
|
|
285
|
+
GrainGradientShapes,
|
|
286
|
+
grainGradientFragmentShader,
|
|
287
|
+
grainGradientMeta
|
|
288
|
+
};
|
|
289
|
+
//# sourceMappingURL=grain-gradient.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shaders/grain-gradient.ts"],
|
|
4
|
+
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport {\n sizingVariablesDeclaration,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n sizingDebugVariablesDeclaration,\n} from '../shader-sizing.js';\nimport {\n simplexNoise,\n declarePI,\n rotation2,\n textureRandomizerR,\n proceduralHash21,\n proceduralHash11,\n} from '../shader-utils.js';\n\nexport const grainGradientMeta = {\n maxColorCount: 7,\n} as const;\n\n/**\n * Multi-color gradient with noise & grain over animated abstract shapes\n *\n * Uniforms:\n * - u_colorBack (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_softness (0..1): blur between color bands\n * - u_intensity (0..1): distortion between color bands\n * - u_noise (0..1): grainy noise independent of softness\n * - u_shape (float used as integer):\n * ---- 1: single sine wave\n * ---- 2: dots pattern\n * ---- 3: truchet pattern\n * ---- 4: corners (2 rounded rectangles)\n * ---- 5: ripple\n * ---- 6: blob (metaballs)\n * ---- 7: circle imitating 3d look\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n *\n * Note: grains are calculated using gl_FragCoord & u_resolution, meaning grains don't react to scaling and fit\n *\n */\n\n// language=GLSL\nexport const grainGradientFragmentShader: string = `#version 300 es\nprecision lowp float;\n\nuniform mediump float u_time;\nuniform mediump vec2 u_resolution;\nuniform mediump float u_pixelRatio;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${grainGradientMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform float u_softness;\nuniform float u_intensity;\nuniform float u_noise;\nuniform float u_shape;\n\nuniform mediump float u_originX;\nuniform mediump float u_originY;\nuniform mediump float u_worldWidth;\nuniform mediump float u_worldHeight;\nuniform mediump float u_fit;\n\nuniform mediump float u_scale;\nuniform mediump float u_rotation;\nuniform mediump float u_offsetX;\nuniform mediump float u_offsetY;\n\n${sizingVariablesDeclaration}\n${ sizingDebugVariablesDeclaration }\n\nout vec4 fragColor;\n\n${declarePI}\n${simplexNoise}\n${rotation2}\n${proceduralHash21}\n${textureRandomizerR}\n\nfloat valueNoiseR(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = randomR(i);\n float b = randomR(i + vec2(1.0, 0.0));\n float c = randomR(i + vec2(0.0, 1.0));\n float d = randomR(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\nfloat fbmR(vec2 n) {\n float total = 0.;\n float amplitude = .2;\n for (int i = 0; i < 3; i++) {\n n = rotate(n, .3);\n total += valueNoiseR(n) * amplitude;\n n *= 1.99;\n amplitude *= 0.6;\n }\n return total;\n}\n\n${proceduralHash11}\n\nvec2 truchet(vec2 uv, float idx){\n idx = fract(((idx - .5) * 2.));\n if (idx > 0.75) {\n uv = vec2(1.0) - uv;\n } else if (idx > 0.5) {\n uv = vec2(1.0 - uv.x, uv.y);\n } else if (idx > 0.25) {\n uv = 1.0 - vec2(1.0 - uv.x, uv.y);\n }\n return uv;\n}\n\nvoid main() {\n\n const float firstFrameOffset = 7.;\n float t = .1 * (u_time + firstFrameOffset);\n\n vec2 shape_uv = vec2(0.);\n vec2 grain_uv = vec2(0.);\n\n if (u_shape > 3.5) {\n shape_uv = v_objectUV;\n grain_uv = shape_uv;\n\n // apply inverse transform to grain_uv so it respects the originXY\n float r = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n grain_uv = transpose(graphicRotation) * grain_uv;\n grain_uv *= u_scale;\n grain_uv -= graphicOffset;\n grain_uv *= v_objectBoxSize;\n grain_uv *= .7;\n } else {\n shape_uv = .5 * v_patternUV;\n grain_uv = 100. * v_patternUV;\n\n // apply inverse transform to grain_uv so it respects the originXY\n float r = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n grain_uv = transpose(graphicRotation) * grain_uv;\n grain_uv *= u_scale;\n if (u_fit > 0.) {\n vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);\n givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;\n float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;\n vec2 patternBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n patternBoxRatio = patternBoxGivenSize.x / patternBoxGivenSize.y;\n float patternBoxNoFitBoxWidth = patternBoxRatio * min(patternBoxGivenSize.x / patternBoxRatio, patternBoxGivenSize.y);\n grain_uv /= (patternBoxNoFitBoxWidth / v_patternBoxSize.x);\n }\n vec2 patternBoxScale = u_resolution.xy / v_patternBoxSize;\n grain_uv -= graphicOffset / patternBoxScale;\n grain_uv *= 1.6;\n }\n\n\n float shape = 0.;\n\n if (u_shape < 1.5) {\n // Sine wave\n\n float wave = cos(.5 * shape_uv.x - 4. * t) * sin(1.5 * shape_uv.x + 2. * t) * (.75 + .25 * cos(6. * t));\n shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);\n\n } else if (u_shape < 2.5) {\n // Grid (dots)\n\n float stripeIdx = floor(2. * shape_uv.x / TWO_PI);\n float rand = hash11(stripeIdx * 100.);\n rand = sign(rand - .5) * pow(4. * abs(rand), .3);\n shape = sin(shape_uv.x) * cos(shape_uv.y - 5. * rand * t);\n shape = pow(abs(shape), 4.);\n\n } else if (u_shape < 3.5) {\n // Truchet pattern\n\n float n2 = valueNoiseR(shape_uv * .4 - 3.75 * t);\n shape_uv.x += 10.;\n shape_uv *= .6;\n\n vec2 tile = truchet(fract(shape_uv), randomR(floor(shape_uv)));\n\n float distance1 = length(tile);\n float distance2 = length(tile - vec2(1.));\n\n n2 -= .5;\n n2 *= .1;\n shape = smoothstep(.2, .55, distance1 + n2) * (1. - smoothstep(.45, .8, distance1 - n2));\n shape += smoothstep(.2, .55, distance2 + n2) * (1. - smoothstep(.45, .8, distance2 - n2));\n\n shape = pow(shape, 1.5);\n\n } else if (u_shape < 4.5) {\n // Corners\n\n shape_uv *= .6;\n vec2 outer = vec2(.5);\n\n vec2 bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(3. * t), .2 - .1 * sin(5.25 * t)));\n vec2 tr = smoothstep(vec2(0.), outer, 1. - shape_uv);\n shape = 1. - bl.x * bl.y * tr.x * tr.y;\n\n shape_uv = -shape_uv;\n bl = smoothstep(vec2(0.), outer, shape_uv + vec2(.1 + .1 * sin(3. * t), .2 - .1 * cos(5.25 * t)));\n tr = smoothstep(vec2(0.), outer, 1. - shape_uv);\n shape -= bl.x * bl.y * tr.x * tr.y;\n\n shape = 1. - smoothstep(0., 1., shape);\n\n } else if (u_shape < 5.5) {\n // Ripple\n\n shape_uv *= 2.;\n float dist = length(.4 * shape_uv);\n float waves = sin(pow(dist, 1.2) * 5. - 3. * t) * .5 + .5;\n shape = waves;\n\n } else if (u_shape < 6.5) {\n // Blob\n\n t *= 2.;\n\n vec2 f1_traj = .25 * vec2(1.3 * sin(t), .2 + 1.3 * cos(.6 * t + 4.));\n vec2 f2_traj = .2 * vec2(1.2 * sin(-t), 1.3 * sin(1.6 * t));\n vec2 f3_traj = .25 * vec2(1.7 * cos(-.6 * t), cos(-1.6 * t));\n vec2 f4_traj = .3 * vec2(1.4 * cos(.8 * t), 1.2 * sin(-.6 * t - 3.));\n\n shape = .5 * pow(1. - clamp(0., 1., length(shape_uv + f1_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f2_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f3_traj)), 5.);\n shape += .5 * pow(1. - clamp(0., 1., length(shape_uv + f4_traj)), 5.);\n\n shape = smoothstep(.0, .9, shape);\n float edge = smoothstep(.25, .3, shape);\n shape = mix(.0, shape, edge);\n\n } else {\n // Sphere\n\n shape_uv *= 2.;\n float d = 1. - pow(length(shape_uv), 2.);\n vec3 pos = vec3(shape_uv, sqrt(max(d, 0.)));\n vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));\n shape = .5 + .5 * dot(lightPos, pos);\n shape *= step(0., d);\n }\n\n float simplex = snoise(grain_uv * .5);\n float grainDist = simplex * snoise(grain_uv * .2) - fbmR(.002 * grain_uv + 10.) - fbmR(.003 * grain_uv);\n float rawNoise = .75 * simplex - fbmR(rotate(.4 * grain_uv, 2.)) - fbmR(.001 * grain_uv);\n float noise = clamp(rawNoise, 0., 1.);\n\n shape += u_intensity * 2. / u_colorsCount * (grainDist + .5);\n shape += u_noise * 10. / u_colorsCount * noise;\n\n float aa = fwidth(shape);\n\n shape = clamp(shape - .5 / u_colorsCount, 0., 1.);\n float totalShape = smoothstep(0., u_softness + 2. * aa, clamp(shape * u_colorsCount, 0., 1.));\n float mixer = shape * (u_colorsCount - 1.);\n\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${grainGradientMeta.maxColorCount}; i++) {\n if (i > int(u_colorsCount) - 1) break;\n\n float localT = clamp(mixer - float(i - 1), 0., 1.);\n localT = smoothstep(.5 - .5 * u_softness - aa, .5 + .5 * u_softness + aa, localT);\n\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n vec3 color = gradient.rgb * totalShape;\n float opacity = gradient.a * totalShape;\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n color = color + bgColor * (1.0 - opacity);\n opacity = opacity + u_colorBack.a * (1.0 - opacity);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface GrainGradientUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_softness: number;\n u_intensity: number;\n u_noise: number;\n u_shape: (typeof GrainGradientShapes)[GrainGradientShape];\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface GrainGradientParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n softness?: number;\n intensity?: number;\n noise?: number;\n shape?: GrainGradientShape;\n}\n\nexport const GrainGradientShapes = {\n wave: 1,\n dots: 2,\n truchet: 3,\n corners: 4,\n ripple: 5,\n blob: 6,\n sphere: 7,\n};\n\nexport type GrainGradientShape = keyof typeof GrainGradientShapes;\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA;AAAA,EACE;AAAA,EAGA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM,oBAAoB;AAAA,EAC/B,eAAe;AACjB;AA2BO,MAAM,8BAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAU3B,kBAAkB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBrD,0BAA0B;AAAA,EACzB,+BAAgC;AAAA;AAAA;AAAA;AAAA,EAIjC,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BlB,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,wBA0KM,kBAAkB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0ChD,MAAM,sBAAsB;AAAA,EACjC,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AACV;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { vec4 } from '../types.js';
|
|
2
|
+
import type { ShaderMotionParams } from '../shader-mount.js';
|
|
3
|
+
import type { ShaderSizingParams, ShaderSizingUniforms } from '../shader-sizing.js';
|
|
4
|
+
export declare const heatmapMeta: {
|
|
5
|
+
readonly maxColorCount: 10;
|
|
6
|
+
};
|
|
7
|
+
export declare const heatmapFragmentShader: string;
|
|
8
|
+
export declare function toProcessedHeatmap(file: File | string): Promise<{
|
|
9
|
+
blob: Blob;
|
|
10
|
+
}>;
|
|
11
|
+
export interface HeatmapUniforms extends ShaderSizingUniforms {
|
|
12
|
+
u_image: HTMLImageElement | string;
|
|
13
|
+
u_contour: number;
|
|
14
|
+
u_angle: number;
|
|
15
|
+
u_noise: number;
|
|
16
|
+
u_innerGlow: number;
|
|
17
|
+
u_outerGlow: number;
|
|
18
|
+
u_colorBack: [number, number, number, number];
|
|
19
|
+
u_colors: vec4[];
|
|
20
|
+
u_colorsCount: number;
|
|
21
|
+
}
|
|
22
|
+
export interface HeatmapParams extends ShaderSizingParams, ShaderMotionParams {
|
|
23
|
+
image: HTMLImageElement | string;
|
|
24
|
+
contour?: number;
|
|
25
|
+
angle?: number;
|
|
26
|
+
noise?: number;
|
|
27
|
+
innerGlow?: number;
|
|
28
|
+
outerGlow?: number;
|
|
29
|
+
colorBack?: string;
|
|
30
|
+
colors?: string[];
|
|
31
|
+
}
|