@paper-design/shaders 0.0.38 → 0.0.40
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/README.md +3 -24
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +2 -2
- package/dist/shader-mount.d.ts +2 -2
- package/dist/shader-mount.js +26 -11
- package/dist/shader-mount.js.map +2 -2
- package/dist/shader-utils.d.ts +1 -0
- package/dist/shader-utils.js +38 -0
- package/dist/shader-utils.js.map +2 -2
- package/dist/shaders/color-panels.d.ts +3 -0
- package/dist/shaders/color-panels.js +29 -16
- package/dist/shaders/color-panels.js.map +2 -2
- package/dist/shaders/dot-grid.js +3 -2
- package/dist/shaders/dot-grid.js.map +2 -2
- package/dist/shaders/dot-orbit.js +1 -2
- package/dist/shaders/dot-orbit.js.map +2 -2
- package/dist/shaders/grain-gradient.js +5 -5
- package/dist/shaders/grain-gradient.js.map +1 -1
- package/dist/shaders/liquid-metal.js +11 -11
- package/dist/shaders/liquid-metal.js.map +1 -1
- package/dist/shaders/mesh-gradient.js +1 -6
- package/dist/shaders/mesh-gradient.js.map +2 -2
- package/dist/shaders/neuro-noise.js +1 -2
- package/dist/shaders/neuro-noise.js.map +2 -2
- package/dist/shaders/perlin-noise.js +2 -2
- package/dist/shaders/perlin-noise.js.map +1 -1
- package/dist/shaders/pulsing-border.d.ts +8 -7
- package/dist/shaders/pulsing-border.js +119 -103
- package/dist/shaders/pulsing-border.js.map +2 -2
- package/dist/shaders/simplex-noise.js +13 -17
- package/dist/shaders/simplex-noise.js.map +2 -2
- package/dist/shaders/spiral.d.ts +3 -3
- package/dist/shaders/spiral.js +27 -30
- package/dist/shaders/spiral.js.map +2 -2
- package/dist/shaders/static-mesh-gradient.d.ts +43 -0
- package/dist/shaders/static-mesh-gradient.js +114 -0
- package/dist/shaders/static-mesh-gradient.js.map +7 -0
- package/dist/shaders/static-radial-gradient.d.ts +51 -0
- package/dist/shaders/static-radial-gradient.js +155 -0
- package/dist/shaders/static-radial-gradient.js.map +7 -0
- package/dist/shaders/swirl.d.ts +3 -3
- package/dist/shaders/swirl.js +18 -17
- package/dist/shaders/swirl.js.map +2 -2
- package/dist/shaders/voronoi.js +2 -2
- package/dist/shaders/voronoi.js.map +1 -1
- package/dist/shaders/warp.js +16 -11
- package/dist/shaders/warp.js.map +2 -2
- package/dist/shaders/waves.js +6 -10
- package/dist/shaders/waves.js.map +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/spiral.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declareSimplexNoise, declarePI, colorBandingFix } from '../shader-utils.js';\n\n/**\n * 2-color spiral shape\n *\n * Uniforms:\n * - u_colorBack, u_colorFront (RGBA)\n * - u_density: spacing falloff to simulate radial perspective (0 = no perspective)\n * - u_strokeWidth: thickness of stroke\n * - u_strokeTaper: stroke loosing width further from center (0 for full visibility)\n * - u_distortion: per-arch shift\n * - u_strokeCap: extra width at the center (no effect on u_strokeWidth = 0.5)\n * - u_noiseFrequency,
|
|
5
|
-
"mappings": ";;;;;AACA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,uBAAuB;AAkBzD,MAAM,uBAA+B;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 { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declareSimplexNoise, declarePI, colorBandingFix } from '../shader-utils.js';\n\n/**\n * 2-color spiral shape\n *\n * Uniforms:\n * - u_colorBack, u_colorFront (RGBA)\n * - u_density: spacing falloff to simulate radial perspective (0 = no perspective)\n * - u_strokeWidth: thickness of stroke\n * - u_strokeTaper: stroke loosing width further from center (0 for full visibility)\n * - u_distortion: per-arch shift\n * - u_strokeCap: extra width at the center (no effect on u_strokeWidth = 0.5)\n * - u_noiseFrequency, u_noise: simplex noise distortion over the shape\n * - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)\n *\n */\n\n// language=GLSL\nexport const spiralFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colorFront;\nuniform float u_density;\nuniform float u_distortion;\nuniform float u_strokeWidth;\nuniform float u_strokeCap;\nuniform float u_strokeTaper;\nuniform float u_noise;\nuniform float u_noiseFrequency;\nuniform float u_softness;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareSimplexNoise}\n\nvoid main() {\n vec2 uv = 2. * v_patternUV;\n \n float t = u_time;\n float l = length(uv);\n float density = clamp(u_density, 0., 1.);\n l = pow(l, density);\n float angle = atan(uv.y, uv.x) - t;\n float angleNormalised = angle / TWO_PI;\n\n angleNormalised += .125 * u_noise * snoise(16. * pow(u_noiseFrequency, 3.) * uv);\n\n float offset = l + angleNormalised;\n offset -= u_distortion * (sin(4. * l - .5 * t) * cos(PI + l + .5 * t));\n float stripe = fract(offset);\n \n float shape = 2. * abs(stripe - .5);\n float width = clamp(u_strokeWidth, .005 * u_strokeTaper, 1.);\n\n\n float wCap = mix(width, (1. - stripe) * (1. - step(.5, stripe)), (1. - clamp(l, 0., 1.)));\n width = mix(width, wCap, u_strokeCap);\n width *= (1. - clamp(u_strokeTaper, 0., 1.) * l);\n\n float fw = fwidth(offset);\n float fwMult = 4. - 3. * (smoothstep(.05, .4, 2. * u_strokeWidth) * smoothstep(.05, .4, 2. * (1. - u_strokeWidth)));\n float pixelSize = mix(fwMult * fw, fwidth(shape), clamp(fw, 0., 1.));\n pixelSize = mix(pixelSize, .002, u_strokeCap * (1. - clamp(l, 0., 1.)));\n\n float res = smoothstep(width - pixelSize - u_softness, width + pixelSize + u_softness, shape);\n\n vec3 fgColor = u_colorFront.rgb * u_colorFront.a;\n float fgOpacity = u_colorFront.a;\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n float bgOpacity = u_colorBack.a;\n\n vec3 color = fgColor * res;\n float opacity = fgOpacity * res;\n\n color += bgColor * (1. - opacity);\n opacity += bgOpacity * (1. - opacity);\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SpiralUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorFront: [number, number, number, number];\n u_density: number;\n u_distortion: number;\n u_strokeWidth: number;\n u_strokeTaper: number;\n u_strokeCap: number;\n u_noise: number;\n u_noiseFrequency: number;\n u_softness: number;\n}\n\nexport interface SpiralParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colorFront?: string;\n density?: number;\n distortion?: number;\n strokeWidth?: number;\n strokeTaper?: number;\n strokeCap?: number;\n noise?: number;\n noiseFrequency?: number;\n softness?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AACA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,uBAAuB;AAkBzD,MAAM,uBAA+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgB1C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,mBAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IA4CjB,eAAe;AAAA;AAAA;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 staticMeshGradientMeta: {
|
|
5
|
+
readonly maxColorCount: 10;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A composition of N color spots (one per color)
|
|
9
|
+
*
|
|
10
|
+
* Uniforms:
|
|
11
|
+
* - u_colorBack (RGBA)
|
|
12
|
+
* - u_colors (vec4[]), u_colorsCount (float used as integer)
|
|
13
|
+
* - u_waveX, u_waveY - power of sine wave distortion along X and Y axes
|
|
14
|
+
* - u_waveXShift, u_waveYShift - each wave phase offset
|
|
15
|
+
* - u_mixing (0 .. 1, float) - 0 for stepped gradient, 0.5 for smooth transitions, 1 for pronounced color points
|
|
16
|
+
* - u_grainMixer - shape distortion
|
|
17
|
+
* - u_grainOverlay - post-processing blending
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export declare const staticMeshGradientFragmentShader: string;
|
|
21
|
+
export interface StaticMeshGradientUniforms extends ShaderSizingUniforms {
|
|
22
|
+
u_colors: vec4[];
|
|
23
|
+
u_colorsCount: number;
|
|
24
|
+
u_positions: number;
|
|
25
|
+
u_waveX: number;
|
|
26
|
+
u_waveXShift: number;
|
|
27
|
+
u_waveY: number;
|
|
28
|
+
u_waveYShift: number;
|
|
29
|
+
u_mixing: number;
|
|
30
|
+
u_grainMixer: number;
|
|
31
|
+
u_grainOverlay: number;
|
|
32
|
+
}
|
|
33
|
+
export interface StaticMeshGradientParams extends ShaderSizingParams, ShaderMotionParams {
|
|
34
|
+
colors?: string[];
|
|
35
|
+
positions?: number;
|
|
36
|
+
waveX?: number;
|
|
37
|
+
waveXShift?: number;
|
|
38
|
+
waveY?: number;
|
|
39
|
+
waveYShift?: number;
|
|
40
|
+
mixing?: number;
|
|
41
|
+
grainMixer?: number;
|
|
42
|
+
grainOverlay?: number;
|
|
43
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
sizingVariablesDeclaration,
|
|
8
|
+
sizingUniformsDeclaration
|
|
9
|
+
} from "../shader-sizing.js";
|
|
10
|
+
import { declarePI, declareRotate, declareGrainShape, colorBandingFix } from "../shader-utils.js";
|
|
11
|
+
const staticMeshGradientMeta = {
|
|
12
|
+
maxColorCount: 10
|
|
13
|
+
};
|
|
14
|
+
const staticMeshGradientFragmentShader = `#version 300 es
|
|
15
|
+
precision mediump float;
|
|
16
|
+
|
|
17
|
+
uniform vec4 u_colors[${staticMeshGradientMeta.maxColorCount}];
|
|
18
|
+
uniform float u_colorsCount;
|
|
19
|
+
|
|
20
|
+
uniform float u_positions;
|
|
21
|
+
uniform float u_waveX;
|
|
22
|
+
uniform float u_waveXShift;
|
|
23
|
+
uniform float u_waveY;
|
|
24
|
+
uniform float u_waveYShift;
|
|
25
|
+
uniform float u_mixing;
|
|
26
|
+
uniform float u_grainMixer;
|
|
27
|
+
uniform float u_grainOverlay;
|
|
28
|
+
|
|
29
|
+
${sizingVariablesDeclaration}
|
|
30
|
+
${sizingUniformsDeclaration}
|
|
31
|
+
|
|
32
|
+
out vec4 fragColor;
|
|
33
|
+
|
|
34
|
+
${declarePI}
|
|
35
|
+
${declareRotate}
|
|
36
|
+
${declareGrainShape}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
vec2 getPosition(int i, float t) {
|
|
40
|
+
float a = float(i) * .37;
|
|
41
|
+
float b = .6 + mod(float(i), 3.) * .3;
|
|
42
|
+
float c = .8 + mod(float(i + 1), 4.) * 0.25;
|
|
43
|
+
|
|
44
|
+
float x = sin(t * b + a);
|
|
45
|
+
float y = cos(t * c + a * 1.5);
|
|
46
|
+
|
|
47
|
+
return .5 + .5 * vec2(x, y);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void main() {
|
|
51
|
+
vec2 uv = v_objectUV;
|
|
52
|
+
uv += .5;
|
|
53
|
+
|
|
54
|
+
vec2 grainUV = rotate(v_objectUV, 2.) * 180.;
|
|
55
|
+
float grain = grainShape(grainUV, vec2(100.));
|
|
56
|
+
|
|
57
|
+
float radius = smoothstep(0., 1., length(uv - .5));
|
|
58
|
+
float center = 1. - radius;
|
|
59
|
+
for (float i = 1.; i <= 2.; i++) {
|
|
60
|
+
uv.x += u_waveX * center / i * cos(TWO_PI * u_waveXShift + i * 2. * smoothstep(.0, 1., uv.y));
|
|
61
|
+
uv.y += u_waveY * center / i * cos(TWO_PI * u_waveYShift + i * 2. * smoothstep(.0, 1., uv.x));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
float mixerGrain = .4 * u_grainMixer * (grain - .3);
|
|
65
|
+
|
|
66
|
+
vec3 color = vec3(0.);
|
|
67
|
+
float opacity = 0.;
|
|
68
|
+
float totalWeight = 0.;
|
|
69
|
+
float positionSeed = 25. + .33 * u_positions;
|
|
70
|
+
|
|
71
|
+
for (int i = 0; i < ${staticMeshGradientMeta.maxColorCount}; i++) {
|
|
72
|
+
if (i >= int(u_colorsCount)) break;
|
|
73
|
+
|
|
74
|
+
vec2 pos = getPosition(i, positionSeed) + mixerGrain;
|
|
75
|
+
float dist = length(uv - pos);
|
|
76
|
+
dist = length(uv - pos);
|
|
77
|
+
|
|
78
|
+
vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;
|
|
79
|
+
float opacityFraction = u_colors[i].a;
|
|
80
|
+
|
|
81
|
+
float power = 4.;
|
|
82
|
+
if (u_mixing > .5) {
|
|
83
|
+
power = mix(power, .75, 2. * (u_mixing - .5));
|
|
84
|
+
}
|
|
85
|
+
dist = pow(dist, power);
|
|
86
|
+
|
|
87
|
+
float w = 1. / (dist + 1e-3);
|
|
88
|
+
if (u_mixing < .5) {
|
|
89
|
+
w = pow(w, mix(mix(.01, 5., clamp(w, 0., 1.)), 1., 2. * u_mixing));
|
|
90
|
+
}
|
|
91
|
+
color += colorFraction * w;
|
|
92
|
+
opacity += opacityFraction * w;
|
|
93
|
+
totalWeight += w;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
color /= totalWeight;
|
|
97
|
+
opacity /= totalWeight;
|
|
98
|
+
|
|
99
|
+
float rr = grainShape(grainUV, vec2(0.));
|
|
100
|
+
float gg = grainShape(grainUV, vec2(-1.));
|
|
101
|
+
float bb = grainShape(grainUV, vec2(2.));
|
|
102
|
+
vec3 grainColor = 2. * vec3(rr, gg, bb);
|
|
103
|
+
color = mix(color, grainColor, u_grainOverlay * grain);
|
|
104
|
+
|
|
105
|
+
${colorBandingFix}
|
|
106
|
+
|
|
107
|
+
fragColor = vec4(color, opacity);
|
|
108
|
+
}
|
|
109
|
+
`;
|
|
110
|
+
export {
|
|
111
|
+
staticMeshGradientFragmentShader,
|
|
112
|
+
staticMeshGradientMeta
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=static-mesh-gradient.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shaders/static-mesh-gradient.ts"],
|
|
4
|
+
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport {\n sizingVariablesDeclaration,\n sizingUniformsDeclaration,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from '../shader-sizing.js';\nimport { declarePI, declareRotate, declareGrainShape, colorBandingFix } from '../shader-utils.js';\n\nexport const staticMeshGradientMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * A composition of N color spots (one per color)\n *\n * Uniforms:\n * - u_colorBack (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_waveX, u_waveY - power of sine wave distortion along X and Y axes\n * - u_waveXShift, u_waveYShift - each wave phase offset\n * - u_mixing (0 .. 1, float) - 0 for stepped gradient, 0.5 for smooth transitions, 1 for pronounced color points\n * - u_grainMixer - shape distortion\n * - u_grainOverlay - post-processing blending\n *\n */\n\n// language=GLSL\nexport const staticMeshGradientFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform vec4 u_colors[${staticMeshGradientMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_positions;\nuniform float u_waveX;\nuniform float u_waveXShift;\nuniform float u_waveY;\nuniform float u_waveYShift;\nuniform float u_mixing;\nuniform float u_grainMixer;\nuniform float u_grainOverlay;\n\n${sizingVariablesDeclaration}\n${sizingUniformsDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareRotate}\n${declareGrainShape}\n\n\nvec2 getPosition(int i, float t) {\n float a = float(i) * .37;\n float b = .6 + mod(float(i), 3.) * .3;\n float c = .8 + mod(float(i + 1), 4.) * 0.25;\n\n float x = sin(t * b + a);\n float y = cos(t * c + a * 1.5);\n\n return .5 + .5 * vec2(x, y);\n}\n\nvoid main() {\n vec2 uv = v_objectUV;\n uv += .5;\n\n vec2 grainUV = rotate(v_objectUV, 2.) * 180.;\n float grain = grainShape(grainUV, vec2(100.));\n\n float radius = smoothstep(0., 1., length(uv - .5));\n float center = 1. - radius;\n for (float i = 1.; i <= 2.; i++) {\n uv.x += u_waveX * center / i * cos(TWO_PI * u_waveXShift + i * 2. * smoothstep(.0, 1., uv.y));\n uv.y += u_waveY * center / i * cos(TWO_PI * u_waveYShift + i * 2. * smoothstep(.0, 1., uv.x));\n }\n\n float mixerGrain = .4 * u_grainMixer * (grain - .3);\n\n vec3 color = vec3(0.);\n float opacity = 0.;\n float totalWeight = 0.;\n float positionSeed = 25. + .33 * u_positions;\n\n for (int i = 0; i < ${staticMeshGradientMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n\n vec2 pos = getPosition(i, positionSeed) + mixerGrain;\n float dist = length(uv - pos);\n dist = length(uv - pos);\n\n vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;\n float opacityFraction = u_colors[i].a;\n\n float power = 4.;\n if (u_mixing > .5) {\n power = mix(power, .75, 2. * (u_mixing - .5));\n }\n dist = pow(dist, power);\n\n float w = 1. / (dist + 1e-3);\n if (u_mixing < .5) {\n w = pow(w, mix(mix(.01, 5., clamp(w, 0., 1.)), 1., 2. * u_mixing));\n }\n color += colorFraction * w;\n opacity += opacityFraction * w;\n totalWeight += w;\n }\n\n color /= totalWeight;\n opacity /= totalWeight;\n\n float rr = grainShape(grainUV, vec2(0.));\n float gg = grainShape(grainUV, vec2(-1.));\n float bb = grainShape(grainUV, vec2(2.));\n vec3 grainColor = 2. * vec3(rr, gg, bb);\n color = mix(color, grainColor, u_grainOverlay * grain);\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface StaticMeshGradientUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_positions: number;\n u_waveX: number;\n u_waveXShift: number;\n u_waveY: number;\n u_waveYShift: number;\n u_mixing: number;\n u_grainMixer: number;\n u_grainOverlay: number;\n}\n\nexport interface StaticMeshGradientParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n positions?: number;\n waveX?: number;\n waveXShift?: number;\n waveY?: number;\n waveYShift?: number;\n mixing?: number;\n grainMixer?: number;\n grainOverlay?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,WAAW,eAAe,mBAAmB,uBAAuB;AAEtE,MAAM,yBAAyB;AAAA,EACpC,eAAe;AACjB;AAiBO,MAAM,mCAA2C;AAAA;AAAA;AAAA,wBAGhC,uBAAuB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY1D,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAIzB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAmCK,uBAAuB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAkCxD,eAAe;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 staticRadialGradientMeta: {
|
|
5
|
+
readonly maxColorCount: 10;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* N-colors radial gradient
|
|
9
|
+
*
|
|
10
|
+
* Uniforms:
|
|
11
|
+
* - u_colorBack (RGBA)
|
|
12
|
+
* - u_colors (vec4[]), u_colorsCount (float used as integer)
|
|
13
|
+
* - u_radius - circle radius
|
|
14
|
+
* - u_focalDistance, u_focalAngle (float) - gradient center offset to the circle center
|
|
15
|
+
* - u_falloff (-1 .. 1, float) - color points distribution (0 for linear gradient)
|
|
16
|
+
* - u_mixing (0 .. 1, float) - 0 for stepped gradient, 0.5 for smooth transitions, 1 for pronounced color points
|
|
17
|
+
* - u_distortion, u_distortionShift, u_distortionFreq - radial distortion (effective with u_distortion > 0)
|
|
18
|
+
* - u_grainMixer - shape distortion
|
|
19
|
+
* - u_grainOverlay - post-processing blending
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare const staticRadialGradientFragmentShader: string;
|
|
23
|
+
export interface StaticRadialGradientUniforms extends ShaderSizingUniforms {
|
|
24
|
+
u_colorBack: [number, number, number, number];
|
|
25
|
+
u_colors: vec4[];
|
|
26
|
+
u_colorsCount: number;
|
|
27
|
+
u_radius: number;
|
|
28
|
+
u_focalDistance: number;
|
|
29
|
+
u_focalAngle: number;
|
|
30
|
+
u_falloff: number;
|
|
31
|
+
u_mixing: number;
|
|
32
|
+
u_distortion: number;
|
|
33
|
+
u_distortionShift: number;
|
|
34
|
+
u_distortionFreq: number;
|
|
35
|
+
u_grainMixer: number;
|
|
36
|
+
u_grainOverlay: number;
|
|
37
|
+
}
|
|
38
|
+
export interface StaticRadialGradientParams extends ShaderSizingParams, ShaderMotionParams {
|
|
39
|
+
colorBack?: string;
|
|
40
|
+
colors?: string[];
|
|
41
|
+
radius?: number;
|
|
42
|
+
focalDistance?: number;
|
|
43
|
+
focalAngle?: number;
|
|
44
|
+
falloff?: number;
|
|
45
|
+
mixing?: number;
|
|
46
|
+
distortion?: number;
|
|
47
|
+
distortionShift?: number;
|
|
48
|
+
distortionFreq?: number;
|
|
49
|
+
grainMixer?: number;
|
|
50
|
+
grainOverlay?: number;
|
|
51
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
sizingVariablesDeclaration,
|
|
8
|
+
sizingUniformsDeclaration
|
|
9
|
+
} from "../shader-sizing.js";
|
|
10
|
+
import { declarePI, declareRotate, declareGrainShape, colorBandingFix } from "../shader-utils.js";
|
|
11
|
+
const staticRadialGradientMeta = {
|
|
12
|
+
maxColorCount: 10
|
|
13
|
+
};
|
|
14
|
+
const staticRadialGradientFragmentShader = `#version 300 es
|
|
15
|
+
precision mediump float;
|
|
16
|
+
|
|
17
|
+
uniform vec4 u_colorBack;
|
|
18
|
+
uniform vec4 u_colors[${staticRadialGradientMeta.maxColorCount}];
|
|
19
|
+
uniform float u_colorsCount;
|
|
20
|
+
|
|
21
|
+
uniform float u_radius;
|
|
22
|
+
uniform float u_focalDistance;
|
|
23
|
+
uniform float u_focalAngle;
|
|
24
|
+
uniform float u_falloff;
|
|
25
|
+
uniform float u_mixing;
|
|
26
|
+
uniform float u_distortion;
|
|
27
|
+
uniform float u_distortionShift;
|
|
28
|
+
uniform float u_distortionFreq;
|
|
29
|
+
uniform float u_grainMixer;
|
|
30
|
+
uniform float u_grainOverlay;
|
|
31
|
+
|
|
32
|
+
${sizingVariablesDeclaration}
|
|
33
|
+
${sizingUniformsDeclaration}
|
|
34
|
+
|
|
35
|
+
out vec4 fragColor;
|
|
36
|
+
|
|
37
|
+
${declarePI}
|
|
38
|
+
${declareRotate}
|
|
39
|
+
${declareGrainShape}
|
|
40
|
+
|
|
41
|
+
void main() {
|
|
42
|
+
vec2 uv = 2. * v_objectUV;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
vec2 center = vec2(0.);
|
|
46
|
+
float angleRad = radians(u_focalAngle - 90.);
|
|
47
|
+
vec2 focalPoint = vec2(cos(angleRad), sin(angleRad)) * u_focalDistance;
|
|
48
|
+
float radius = u_radius;
|
|
49
|
+
|
|
50
|
+
vec2 c_to_uv = uv - center;
|
|
51
|
+
vec2 f_to_uv = uv - focalPoint;
|
|
52
|
+
vec2 f_to_c = center - focalPoint;
|
|
53
|
+
float r = length(c_to_uv);
|
|
54
|
+
|
|
55
|
+
float fragAngle = atan(c_to_uv.y, c_to_uv.x);
|
|
56
|
+
float angleDiff = fragAngle - angleRad;
|
|
57
|
+
angleDiff = mod(angleDiff + PI, TWO_PI) - PI;
|
|
58
|
+
|
|
59
|
+
float halfAngle = acos(clamp(radius / u_focalDistance, 0.0, 1.0));
|
|
60
|
+
float isInSector = 1.0 - smoothstep(.6 * PI, halfAngle, abs(angleDiff));
|
|
61
|
+
|
|
62
|
+
float a = dot(f_to_uv, f_to_uv);
|
|
63
|
+
float b = -2.0 * dot(f_to_uv, f_to_c);
|
|
64
|
+
float c = dot(f_to_c, f_to_c) - radius * radius;
|
|
65
|
+
|
|
66
|
+
float discriminant = b * b - 4.0 * a * c;
|
|
67
|
+
float t = 1.0;
|
|
68
|
+
|
|
69
|
+
if (discriminant >= 0.0) {
|
|
70
|
+
float sqrtD = sqrt(discriminant);
|
|
71
|
+
float t0 = (-b - sqrtD) / (2.0 * a);
|
|
72
|
+
float t1 = (-b + sqrtD) / (2.0 * a);
|
|
73
|
+
t = max(t0, t1);
|
|
74
|
+
if (t < 0.0) t = 0.0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
float dist = length(f_to_uv);
|
|
78
|
+
float normalized = dist / (length(f_to_uv * t));
|
|
79
|
+
float shape = clamp(normalized, 0.0, 1.0);
|
|
80
|
+
|
|
81
|
+
float falloffMapped = mix(.2 + .8 * max(0., u_falloff + 1.), mix(1., 15., pow(u_falloff, 2.)), step(.0, u_falloff));
|
|
82
|
+
|
|
83
|
+
float falloffExp = mix(falloffMapped, 1., shape);
|
|
84
|
+
shape = pow(shape, falloffExp);
|
|
85
|
+
shape = 1. - clamp(shape, 0., 1.);
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
float outerMask = .002;
|
|
89
|
+
float outer = smoothstep(radius + outerMask, radius - outerMask, r);
|
|
90
|
+
outer = mix(outer, 1., isInSector);
|
|
91
|
+
|
|
92
|
+
shape = mix(0., shape, outer);
|
|
93
|
+
shape *= smoothstep(radius, radius - .01, r);
|
|
94
|
+
|
|
95
|
+
float angle = atan(f_to_uv.y, f_to_uv.x);
|
|
96
|
+
shape -= pow(u_distortion, 2.) * shape * pow(sin(PI * clamp(length(f_to_uv) - .2 + u_distortionShift, 0., 1.)), 4.) * (sin(u_distortionFreq * angle) + cos(floor(.65 * u_distortionFreq) * angle));
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
vec2 grainUV = rotate(v_objectUV, 2.) * 180.;
|
|
100
|
+
float grain = grainShape(grainUV, vec2(100.));
|
|
101
|
+
|
|
102
|
+
float mixerGrain = u_grainMixer * (grain - .3);
|
|
103
|
+
float mixer = shape * u_colorsCount + mixerGrain;
|
|
104
|
+
vec4 gradient = u_colors[0];
|
|
105
|
+
gradient.rgb *= gradient.a;
|
|
106
|
+
|
|
107
|
+
float outerShape = 0.;
|
|
108
|
+
for (int i = 1; i < ${staticRadialGradientMeta.maxColorCount + 1}; i++) {
|
|
109
|
+
if (i > int(u_colorsCount)) break;
|
|
110
|
+
float mLinear = clamp(mixer - float(i - 1), 0.0, 1.0);
|
|
111
|
+
|
|
112
|
+
float m = 0.;
|
|
113
|
+
float mixing = u_mixing * 3.;
|
|
114
|
+
if (mixing > 2.) {
|
|
115
|
+
float tt = pow(mLinear, 2.);
|
|
116
|
+
m = mix(mLinear, tt, .5 * clamp((mixing - 2.), 0., 1.));
|
|
117
|
+
} else if (mixing > 1.) {
|
|
118
|
+
m = mix(smoothstep(0., 1., mLinear), mLinear, clamp((mixing - 1.), 0., 1.));
|
|
119
|
+
} else {
|
|
120
|
+
float aa = fwidth(mLinear);
|
|
121
|
+
m = smoothstep(.5 - .5 * mixing - aa, .5 + .5 * mixing + aa, mLinear);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (i == 1) {
|
|
125
|
+
outerShape = m;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
vec4 c = u_colors[i - 1];
|
|
129
|
+
c.rgb *= c.a;
|
|
130
|
+
gradient = mix(gradient, c, m);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
vec3 color = gradient.rgb * outerShape;
|
|
134
|
+
float opacity = gradient.a * outerShape;
|
|
135
|
+
|
|
136
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
137
|
+
color = color + bgColor * (1.0 - opacity);
|
|
138
|
+
opacity = opacity + u_colorBack.a * (1.0 - opacity);
|
|
139
|
+
|
|
140
|
+
float rr = grainShape(grainUV, vec2(0.));
|
|
141
|
+
float gg = grainShape(grainUV, vec2(-1.));
|
|
142
|
+
float bb = grainShape(grainUV, vec2(2.));
|
|
143
|
+
vec3 grainColor = 2. * vec3(rr, gg, bb);
|
|
144
|
+
color = mix(color, grainColor, u_grainOverlay * grain);
|
|
145
|
+
|
|
146
|
+
${colorBandingFix}
|
|
147
|
+
|
|
148
|
+
fragColor = vec4(color, opacity);
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
export {
|
|
152
|
+
staticRadialGradientFragmentShader,
|
|
153
|
+
staticRadialGradientMeta
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=static-radial-gradient.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shaders/static-radial-gradient.ts"],
|
|
4
|
+
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport {\n sizingVariablesDeclaration,\n sizingUniformsDeclaration,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from '../shader-sizing.js';\nimport { declarePI, declareRotate, declareGrainShape, colorBandingFix } from '../shader-utils.js';\n\nexport const staticRadialGradientMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * N-colors radial gradient\n *\n * Uniforms:\n * - u_colorBack (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_radius - circle radius\n * - u_focalDistance, u_focalAngle (float) - gradient center offset to the circle center\n * - u_falloff (-1 .. 1, float) - color points distribution (0 for linear gradient)\n * - u_mixing (0 .. 1, float) - 0 for stepped gradient, 0.5 for smooth transitions, 1 for pronounced color points\n * - u_distortion, u_distortionShift, u_distortionFreq - radial distortion (effective with u_distortion > 0)\n * - u_grainMixer - shape distortion\n * - u_grainOverlay - post-processing blending\n *\n */\n\n// language=GLSL\nexport const staticRadialGradientFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${staticRadialGradientMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_radius;\nuniform float u_focalDistance;\nuniform float u_focalAngle;\nuniform float u_falloff;\nuniform float u_mixing;\nuniform float u_distortion;\nuniform float u_distortionShift;\nuniform float u_distortionFreq;\nuniform float u_grainMixer;\nuniform float u_grainOverlay;\n\n${sizingVariablesDeclaration}\n${sizingUniformsDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareRotate}\n${declareGrainShape}\n\nvoid main() {\n vec2 uv = 2. * v_objectUV;\n\n\n vec2 center = vec2(0.);\n float angleRad = radians(u_focalAngle - 90.);\n vec2 focalPoint = vec2(cos(angleRad), sin(angleRad)) * u_focalDistance;\n float radius = u_radius;\n \n vec2 c_to_uv = uv - center;\n vec2 f_to_uv = uv - focalPoint;\n vec2 f_to_c = center - focalPoint;\n float r = length(c_to_uv);\n \n float fragAngle = atan(c_to_uv.y, c_to_uv.x);\n float angleDiff = fragAngle - angleRad;\n angleDiff = mod(angleDiff + PI, TWO_PI) - PI;\n \n float halfAngle = acos(clamp(radius / u_focalDistance, 0.0, 1.0));\n float isInSector = 1.0 - smoothstep(.6 * PI, halfAngle, abs(angleDiff));\n \n float a = dot(f_to_uv, f_to_uv);\n float b = -2.0 * dot(f_to_uv, f_to_c);\n float c = dot(f_to_c, f_to_c) - radius * radius;\n\n float discriminant = b * b - 4.0 * a * c;\n float t = 1.0;\n\n if (discriminant >= 0.0) {\n float sqrtD = sqrt(discriminant);\n float t0 = (-b - sqrtD) / (2.0 * a);\n float t1 = (-b + sqrtD) / (2.0 * a);\n t = max(t0, t1);\n if (t < 0.0) t = 0.0;\n }\n\n float dist = length(f_to_uv);\n float normalized = dist / (length(f_to_uv * t));\n float shape = clamp(normalized, 0.0, 1.0);\n\n float falloffMapped = mix(.2 + .8 * max(0., u_falloff + 1.), mix(1., 15., pow(u_falloff, 2.)), step(.0, u_falloff));\n \n float falloffExp = mix(falloffMapped, 1., shape);\n shape = pow(shape, falloffExp);\n shape = 1. - clamp(shape, 0., 1.);\n\n\n float outerMask = .002;\n float outer = smoothstep(radius + outerMask, radius - outerMask, r);\n outer = mix(outer, 1., isInSector);\n \n shape = mix(0., shape, outer);\n shape *= smoothstep(radius, radius - .01, r);\n\n float angle = atan(f_to_uv.y, f_to_uv.x);\n shape -= pow(u_distortion, 2.) * shape * pow(sin(PI * clamp(length(f_to_uv) - .2 + u_distortionShift, 0., 1.)), 4.) * (sin(u_distortionFreq * angle) + cos(floor(.65 * u_distortionFreq) * angle));\n\n\n vec2 grainUV = rotate(v_objectUV, 2.) * 180.;\n float grain = grainShape(grainUV, vec2(100.));\n\n float mixerGrain = u_grainMixer * (grain - .3);\n float mixer = shape * u_colorsCount + mixerGrain;\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n \n float outerShape = 0.;\n for (int i = 1; i < ${staticRadialGradientMeta.maxColorCount + 1}; i++) {\n if (i > int(u_colorsCount)) break;\n float mLinear = clamp(mixer - float(i - 1), 0.0, 1.0);\n \n float m = 0.;\n float mixing = u_mixing * 3.;\n if (mixing > 2.) {\n float tt = pow(mLinear, 2.);\n m = mix(mLinear, tt, .5 * clamp((mixing - 2.), 0., 1.));\n } else if (mixing > 1.) {\n m = mix(smoothstep(0., 1., mLinear), mLinear, clamp((mixing - 1.), 0., 1.));\n } else {\n float aa = fwidth(mLinear);\n m = smoothstep(.5 - .5 * mixing - aa, .5 + .5 * mixing + aa, mLinear);\n }\n \n if (i == 1) {\n outerShape = m;\n }\n\n vec4 c = u_colors[i - 1];\n c.rgb *= c.a;\n gradient = mix(gradient, c, m);\n }\n\n vec3 color = gradient.rgb * outerShape;\n float opacity = gradient.a * outerShape;\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 float rr = grainShape(grainUV, vec2(0.));\n float gg = grainShape(grainUV, vec2(-1.));\n float bb = grainShape(grainUV, vec2(2.));\n vec3 grainColor = 2. * vec3(rr, gg, bb);\n color = mix(color, grainColor, u_grainOverlay * grain);\n \n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface StaticRadialGradientUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_radius: number;\n u_focalDistance: number;\n u_focalAngle: number;\n u_falloff: number;\n u_mixing: number;\n u_distortion: number;\n u_distortionShift: number;\n u_distortionFreq: number;\n u_grainMixer: number;\n u_grainOverlay: number;\n}\n\nexport interface StaticRadialGradientParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n radius?: number;\n focalDistance?: number;\n focalAngle?: number;\n falloff?: number;\n mixing?: number;\n distortion?: number;\n distortionShift?: number;\n distortionFreq?: number;\n grainMixer?: number;\n grainOverlay?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,WAAW,eAAe,mBAAmB,uBAAuB;AAEtE,MAAM,2BAA2B;AAAA,EACtC,eAAe;AACjB;AAmBO,MAAM,qCAA6C;AAAA;AAAA;AAAA;AAAA,wBAIlC,yBAAyB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAc5D,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAIzB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAqEK,yBAAyB,gBAAgB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAsC9D,eAAe;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/shaders/swirl.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare const swirlMeta: {
|
|
|
13
13
|
* - u_bandCount (float, used as int): number of sectors
|
|
14
14
|
* - u_twist: sectors twist intensity (0 = linear)
|
|
15
15
|
* - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)
|
|
16
|
-
* -
|
|
16
|
+
* - u_noise, u_noiseFrequency: simplex noise distortion over the shape
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
19
|
export declare const swirlFragmentShader: string;
|
|
@@ -25,7 +25,7 @@ export interface SwirlUniforms extends ShaderSizingUniforms {
|
|
|
25
25
|
u_twist: number;
|
|
26
26
|
u_softness: number;
|
|
27
27
|
u_noiseFrequency: number;
|
|
28
|
-
|
|
28
|
+
u_noise: number;
|
|
29
29
|
}
|
|
30
30
|
export interface SwirlParams extends ShaderSizingParams, ShaderMotionParams {
|
|
31
31
|
colorBack?: string;
|
|
@@ -34,5 +34,5 @@ export interface SwirlParams extends ShaderSizingParams, ShaderMotionParams {
|
|
|
34
34
|
twist?: number;
|
|
35
35
|
softness?: number;
|
|
36
36
|
noiseFrequency?: number;
|
|
37
|
-
|
|
37
|
+
noise?: number;
|
|
38
38
|
}
|
package/dist/shaders/swirl.js
CHANGED
|
@@ -19,7 +19,7 @@ uniform float u_colorsCount;
|
|
|
19
19
|
uniform float u_bandCount;
|
|
20
20
|
uniform float u_twist;
|
|
21
21
|
uniform float u_softness;
|
|
22
|
-
uniform float
|
|
22
|
+
uniform float u_noise;
|
|
23
23
|
uniform float u_noiseFrequency;
|
|
24
24
|
|
|
25
25
|
${sizingVariablesDeclaration}
|
|
@@ -45,33 +45,34 @@ void main() {
|
|
|
45
45
|
|
|
46
46
|
float shape = fract(offset);
|
|
47
47
|
shape = 1. - abs(2. * shape - 1.);
|
|
48
|
-
shape +=
|
|
48
|
+
shape += u_noise * snoise(15. * pow(u_noiseFrequency, 2.) * shape_uv);
|
|
49
49
|
|
|
50
50
|
float mid = smoothstep(.2, .4, pow(l, twist));
|
|
51
51
|
shape = mix(0., shape, mid);
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
float edge_w = fwidth(shape);
|
|
56
|
-
|
|
57
|
-
float totalShape = smoothstep(0., u_softness + 2. * edge_w, clamp(shape * u_colorsCount, 0., 1.));
|
|
58
|
-
float mixer = shape * (u_colorsCount - 1.);
|
|
59
|
-
|
|
53
|
+
float mixer = shape * u_colorsCount;
|
|
60
54
|
vec4 gradient = u_colors[0];
|
|
61
55
|
gradient.rgb *= gradient.a;
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
|
|
57
|
+
float outerShape = 0.;
|
|
58
|
+
for (int i = 1; i < ${swirlMeta.maxColorCount + 1}; i++) {
|
|
59
|
+
if (i > int(u_colorsCount)) break;
|
|
60
|
+
|
|
61
|
+
float m = clamp(mixer - float(i - 1), 0., 1.);
|
|
62
|
+
float aa = fwidth(m);
|
|
63
|
+
m = smoothstep(.5 - .5 * u_softness - aa, .5 + .5 * u_softness + aa, m);
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if (i == 1) {
|
|
66
|
+
outerShape = m;
|
|
67
|
+
}
|
|
67
68
|
|
|
68
|
-
vec4 c = u_colors[i];
|
|
69
|
+
vec4 c = u_colors[i - 1];
|
|
69
70
|
c.rgb *= c.a;
|
|
70
|
-
gradient = mix(gradient, c,
|
|
71
|
+
gradient = mix(gradient, c, m);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
vec3 color = gradient.rgb *
|
|
74
|
-
float opacity = gradient.a *
|
|
74
|
+
vec3 color = gradient.rgb * outerShape;
|
|
75
|
+
float opacity = gradient.a * outerShape;
|
|
75
76
|
|
|
76
77
|
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
77
78
|
color = color + bgColor * (1.0 - opacity);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/swirl.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 { declareSimplexNoise, declarePI, declareRotate, colorBandingFix } from '../shader-utils.js';\n\nexport const swirlMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * Twisting radial bands\n *\n * Uniforms:\n * - u_colorBack (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_bandCount (float, used as int): number of sectors\n * - u_twist: sectors twist intensity (0 = linear)\n * - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)\n * -
|
|
5
|
-
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,eAAe,uBAAuB;AAExE,MAAM,YAAY;AAAA,EACvB,eAAe;AACjB;AAgBO,MAAM,sBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAMnB,UAAU,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,mBAAmB;AAAA,EACnB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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 { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declareSimplexNoise, declarePI, declareRotate, colorBandingFix } from '../shader-utils.js';\n\nexport const swirlMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * Twisting radial bands\n *\n * Uniforms:\n * - u_colorBack (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_bandCount (float, used as int): number of sectors\n * - u_twist: sectors twist intensity (0 = linear)\n * - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)\n * - u_noise, u_noiseFrequency: simplex noise distortion over the shape\n *\n */\n\n// language=GLSL\nexport const swirlFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform vec4 u_colorBack;\nuniform vec4 u_colors[${swirlMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform float u_bandCount;\nuniform float u_twist;\nuniform float u_softness;\nuniform float u_noise;\nuniform float u_noiseFrequency;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${declareSimplexNoise}\n${declareRotate}\n\nvoid main() {\n vec2 shape_uv = v_objectUV;\n\n float l = length(shape_uv);\n\n float t = u_time;\n\n float angle = ceil(u_bandCount) * atan(shape_uv.y, shape_uv.x) + t;\n float angle_norm = angle / TWO_PI;\n\n float twist = 3. * clamp(u_twist, 0., 1.);\n float offset = pow(l, -twist) + angle_norm;\n\n float shape = fract(offset);\n shape = 1. - abs(2. * shape - 1.);\n shape += u_noise * snoise(15. * pow(u_noiseFrequency, 2.) * shape_uv);\n\n float mid = smoothstep(.2, .4, pow(l, twist));\n shape = mix(0., shape, mid);\n\n float mixer = shape * u_colorsCount;\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n \n float outerShape = 0.;\n for (int i = 1; i < ${swirlMeta.maxColorCount + 1}; i++) {\n if (i > int(u_colorsCount)) break;\n\n float m = clamp(mixer - float(i - 1), 0., 1.);\n float aa = fwidth(m);\n m = smoothstep(.5 - .5 * u_softness - aa, .5 + .5 * u_softness + aa, m);\n\n if (i == 1) {\n outerShape = m;\n }\n\n vec4 c = u_colors[i - 1];\n c.rgb *= c.a;\n gradient = mix(gradient, c, m);\n }\n\n vec3 color = gradient.rgb * outerShape;\n float opacity = gradient.a * outerShape;\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 ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SwirlUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colors: vec4[];\n u_colorsCount: number;\n u_bandCount: number;\n u_twist: number;\n u_softness: number;\n u_noiseFrequency: number;\n u_noise: number;\n}\n\nexport interface SwirlParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colors?: string[];\n bandCount?: number;\n twist?: number;\n softness?: number;\n noiseFrequency?: number;\n noise?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,qBAAqB,WAAW,eAAe,uBAAuB;AAExE,MAAM,YAAY;AAAA,EACvB,eAAe;AACjB;AAgBO,MAAM,sBAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAMnB,UAAU,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ7C,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA,EACT,mBAAmB;AAAA,EACnB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBA2BS,UAAU,gBAAgB,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAuB/C,eAAe;AAAA;AAAA;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/shaders/voronoi.js
CHANGED
|
@@ -82,7 +82,7 @@ vec4 voronoi(vec2 x, float t) {
|
|
|
82
82
|
|
|
83
83
|
void main() {
|
|
84
84
|
vec2 shape_uv = v_patternUV;
|
|
85
|
-
shape_uv *= .
|
|
85
|
+
shape_uv *= 1.25;
|
|
86
86
|
|
|
87
87
|
float t = u_time;
|
|
88
88
|
|
|
@@ -120,7 +120,7 @@ void main() {
|
|
|
120
120
|
vec3 cellColor = gradient.rgb;
|
|
121
121
|
float cellOpacity = gradient.a;
|
|
122
122
|
|
|
123
|
-
float glows = length(voronoiRes.yz * u_glow
|
|
123
|
+
float glows = length(voronoiRes.yz * u_glow);
|
|
124
124
|
glows = pow(glows, 1.5);
|
|
125
125
|
|
|
126
126
|
vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * glows);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/shaders/voronoi.ts"],
|
|
4
|
-
"sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI } from '../shader-utils.js';\n\nexport const voronoiMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Double-pass Voronoi pattern cell edges\n * Original algorithm: https://www.shadertoy.com/view/ldl3W8\n *\n * Uniforms:\n * - u_colorBack, u_colorGlow (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_stepsPerColor: discrete color steps between u_colors\n * - u_distortion (0..0.5): max distance the cell center moves away from regular grid\n * - u_gap: width of the stroke between the cells\n * - u_glow: radial glow around each cell center\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n *\n * Note: gaps can't be removed completely due to artifacts of Voronoi cells\n *\n */\n\n// language=GLSL\nexport const voronoiFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${voronoiMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_stepsPerColor;\nuniform vec4 u_colorGlow;\nuniform vec4 u_colorGap;\nuniform float u_distortion;\nuniform float u_gap;\nuniform float u_glow;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n\nvec2 hash(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, uv).gb;\n}\n\nvec4 voronoi(vec2 x, float t) {\n vec2 ip = floor(x);\n vec2 fp = fract(x);\n\n vec2 mg, mr;\n float md = 8.;\n float rand = 0.;\n\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n vec2 g = vec2(float(i), float(j));\n vec2 raw_hash = hash(ip + g);\n vec2 o = hash(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n float d = dot(r, r);\n\n if (d < md) {\n md = d;\n mr = r;\n mg = g;\n rand = raw_hash.x;\n }\n }\n }\n\n md = 8.;\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n vec2 g = mg + vec2(float(i), float(j));\n vec2 o = hash(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n if (dot(mr - r, mr - r) > .00001) {\n md = min(md, dot(.5 * (mr + r), normalize(r - mr)));\n }\n }\n }\n\n return vec4(md, mr, rand);\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= .
|
|
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 } from '../shader-utils.js';\n\nexport const voronoiMeta = {\n maxColorCount: 5,\n} as const;\n\n/**\n * Double-pass Voronoi pattern cell edges\n * Original algorithm: https://www.shadertoy.com/view/ldl3W8\n *\n * Uniforms:\n * - u_colorBack, u_colorGlow (RGBA)\n * - u_colors (vec4[]), u_colorsCount (float used as integer)\n * - u_stepsPerColor: discrete color steps between u_colors\n * - u_distortion (0..0.5): max distance the cell center moves away from regular grid\n * - u_gap: width of the stroke between the cells\n * - u_glow: radial glow around each cell center\n *\n * - u_noiseTexture (sampler2D): pre-computed randomizer source\n *\n * Note: gaps can't be removed completely due to artifacts of Voronoi cells\n *\n */\n\n// language=GLSL\nexport const voronoiFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform float u_time;\n\nuniform float u_scale;\n\nuniform sampler2D u_noiseTexture;\n\nuniform vec4 u_colors[${voronoiMeta.maxColorCount}];\nuniform float u_colorsCount;\n\nuniform float u_stepsPerColor;\nuniform vec4 u_colorGlow;\nuniform vec4 u_colorGap;\nuniform float u_distortion;\nuniform float u_gap;\nuniform float u_glow;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n\nvec2 hash(vec2 p) {\n vec2 uv = floor(p) / 100. + .5;\n return texture(u_noiseTexture, uv).gb;\n}\n\nvec4 voronoi(vec2 x, float t) {\n vec2 ip = floor(x);\n vec2 fp = fract(x);\n\n vec2 mg, mr;\n float md = 8.;\n float rand = 0.;\n\n for (int j = -1; j <= 1; j++) {\n for (int i = -1; i <= 1; i++) {\n vec2 g = vec2(float(i), float(j));\n vec2 raw_hash = hash(ip + g);\n vec2 o = hash(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n float d = dot(r, r);\n\n if (d < md) {\n md = d;\n mr = r;\n mg = g;\n rand = raw_hash.x;\n }\n }\n }\n\n md = 8.;\n for (int j = -2; j <= 2; j++) {\n for (int i = -2; i <= 2; i++) {\n vec2 g = mg + vec2(float(i), float(j));\n vec2 o = hash(ip + g);\n o = .5 + u_distortion * sin(t + TWO_PI * o);\n vec2 r = g + o - fp;\n if (dot(mr - r, mr - r) > .00001) {\n md = min(md, dot(.5 * (mr + r), normalize(r - mr)));\n }\n }\n }\n\n return vec4(md, mr, rand);\n}\n\nvoid main() {\n vec2 shape_uv = v_patternUV;\n shape_uv *= 1.25;\n\n float t = u_time;\n\n vec4 voronoiRes = voronoi(shape_uv, t);\n\n float shape = clamp(voronoiRes.w, 0., 1.);\n float mixer = shape * (u_colorsCount - 1.);\n mixer = (shape - .5 / u_colorsCount) * u_colorsCount;\n float steps = max(1., u_stepsPerColor);\n\n vec4 gradient = u_colors[0];\n gradient.rgb *= gradient.a;\n for (int i = 1; i < ${voronoiMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n float localT = clamp(mixer - float(i - 1), 0.0, 1.0);\n localT = round(localT * steps) / steps;\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n gradient = mix(gradient, c, localT);\n }\n\n if ((mixer < 0.) || (mixer > (u_colorsCount - 1.))) {\n float localT = mixer + 1.;\n if (mixer > (u_colorsCount - 1.)) {\n localT = mixer - (u_colorsCount - 1.);\n }\n localT = round(localT * steps) / steps;\n vec4 cFst = u_colors[0];\n cFst.rgb *= cFst.a;\n vec4 cLast = u_colors[int(u_colorsCount - 1.)];\n cLast.rgb *= cLast.a;\n gradient = mix(cLast, cFst, localT);\n }\n\n vec3 cellColor = gradient.rgb;\n float cellOpacity = gradient.a;\n\n float glows = length(voronoiRes.yz * u_glow);\n glows = pow(glows, 1.5);\n\n vec3 color = mix(cellColor, u_colorGlow.rgb * u_colorGlow.a, u_colorGlow.a * glows);\n float opacity = cellOpacity + u_colorGlow.a * glows;\n\n float edge = voronoiRes.x;\n float smoothEdge = .02 / (2. * u_scale) * (1. + .5 * u_gap);\n edge = smoothstep(u_gap - smoothEdge, u_gap + smoothEdge, edge);\n\n color = mix(u_colorGap.rgb * u_colorGap.a, color, edge);\n opacity = mix(u_colorGap.a, opacity, edge);\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface VoronoiUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_stepsPerColor: number;\n u_colorGap: [number, number, number, number];\n u_colorGlow: [number, number, number, number];\n u_distortion: number;\n u_gap: number;\n u_glow: number;\n u_noiseTexture?: HTMLImageElement;\n}\n\nexport interface VoronoiParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n stepsPerColor?: number;\n colorGap?: string;\n colorGlow?: string;\n distortion?: number;\n gap?: number;\n glow?: number;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,iBAAiB;AAEnB,MAAM,cAAc;AAAA,EACzB,eAAe;AACjB;AAqBO,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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAgEa,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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/shaders/warp.js
CHANGED
|
@@ -36,7 +36,7 @@ ${declareValueNoise}
|
|
|
36
36
|
|
|
37
37
|
void main() {
|
|
38
38
|
vec2 uv = v_patternUV;
|
|
39
|
-
uv *= .
|
|
39
|
+
uv *= .5;
|
|
40
40
|
|
|
41
41
|
float t = 0.0625 * u_time;
|
|
42
42
|
|
|
@@ -46,10 +46,13 @@ void main() {
|
|
|
46
46
|
uv.x += 4. * u_distortion * n2 * cos(angle);
|
|
47
47
|
uv.y += 4. * u_distortion * n2 * sin(angle);
|
|
48
48
|
|
|
49
|
-
float
|
|
50
|
-
for (
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
float swirl = u_swirl;
|
|
50
|
+
for (int i = 1; i <= 20; i++) {
|
|
51
|
+
if (i >= int(u_swirlIterations)) break;
|
|
52
|
+
float iFloat = float(i);
|
|
53
|
+
// swirl *= (1. - smoothstep(.0, .25, length(fwidth(uv))));
|
|
54
|
+
uv.x += swirl / iFloat * cos(t + iFloat * 1.5 * uv.y);
|
|
55
|
+
uv.y += swirl / iFloat * cos(t + iFloat * 1. * uv.x);
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
float proportion = clamp(u_proportion, 0., 1.);
|
|
@@ -72,19 +75,21 @@ void main() {
|
|
|
72
75
|
float mixer = shape * (u_colorsCount - 1.);
|
|
73
76
|
vec4 gradient = u_colors[0];
|
|
74
77
|
gradient.rgb *= gradient.a;
|
|
78
|
+
float aa = fwidth(shape);
|
|
75
79
|
for (int i = 1; i < ${warpMeta.maxColorCount}; i++) {
|
|
76
80
|
if (i >= int(u_colorsCount)) break;
|
|
77
|
-
float
|
|
81
|
+
float m = clamp(mixer - float(i - 1), 0.0, 1.0);
|
|
78
82
|
|
|
79
|
-
float localMixerStart = floor(
|
|
80
|
-
float
|
|
81
|
-
float
|
|
83
|
+
float localMixerStart = floor(m);
|
|
84
|
+
float softness = .5 * u_softness + fwidth(m);
|
|
85
|
+
float smoothed = smoothstep(max(0., .5 - softness - aa), min(1., .5 + softness + aa), m - localMixerStart);
|
|
86
|
+
float stepped = localMixerStart + smoothed;
|
|
82
87
|
|
|
83
|
-
|
|
88
|
+
m = mix(stepped, m, u_softness);
|
|
84
89
|
|
|
85
90
|
vec4 c = u_colors[i];
|
|
86
91
|
c.rgb *= c.a;
|
|
87
|
-
gradient = mix(gradient, c,
|
|
92
|
+
gradient = mix(gradient, c, m);
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
vec3 color = gradient.rgb;
|