@paper-design/shaders 0.0.0-canary.156ab35
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,81 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import { sizingVariablesDeclaration } from "../shader-sizing.js";
|
|
7
|
+
import { simplexNoise, declarePI, colorBandingFix } from "../shader-utils.js";
|
|
8
|
+
const spiralFragmentShader = `#version 300 es
|
|
9
|
+
precision mediump float;
|
|
10
|
+
|
|
11
|
+
uniform float u_time;
|
|
12
|
+
|
|
13
|
+
uniform vec4 u_colorBack;
|
|
14
|
+
uniform vec4 u_colorFront;
|
|
15
|
+
uniform float u_density;
|
|
16
|
+
uniform float u_distortion;
|
|
17
|
+
uniform float u_strokeWidth;
|
|
18
|
+
uniform float u_strokeCap;
|
|
19
|
+
uniform float u_strokeTaper;
|
|
20
|
+
uniform float u_noise;
|
|
21
|
+
uniform float u_noiseFrequency;
|
|
22
|
+
uniform float u_softness;
|
|
23
|
+
|
|
24
|
+
${sizingVariablesDeclaration}
|
|
25
|
+
|
|
26
|
+
out vec4 fragColor;
|
|
27
|
+
|
|
28
|
+
${declarePI}
|
|
29
|
+
${simplexNoise}
|
|
30
|
+
|
|
31
|
+
void main() {
|
|
32
|
+
vec2 uv = 2. * v_patternUV;
|
|
33
|
+
|
|
34
|
+
float t = u_time;
|
|
35
|
+
float l = length(uv);
|
|
36
|
+
float density = clamp(u_density, 0., 1.);
|
|
37
|
+
l = pow(max(l, 1e-6), density);
|
|
38
|
+
float angle = atan(uv.y, uv.x) - t;
|
|
39
|
+
float angleNormalised = angle / TWO_PI;
|
|
40
|
+
|
|
41
|
+
angleNormalised += .125 * u_noise * snoise(16. * pow(u_noiseFrequency, 3.) * uv);
|
|
42
|
+
|
|
43
|
+
float offset = l + angleNormalised;
|
|
44
|
+
offset -= u_distortion * (sin(4. * l - .5 * t) * cos(PI + l + .5 * t));
|
|
45
|
+
float stripe = fract(offset);
|
|
46
|
+
|
|
47
|
+
float shape = 2. * abs(stripe - .5);
|
|
48
|
+
float width = 1. - clamp(u_strokeWidth, .005 * u_strokeTaper, 1.);
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
float wCap = mix(width, (1. - stripe) * (1. - step(.5, stripe)), (1. - clamp(l, 0., 1.)));
|
|
52
|
+
width = mix(width, wCap, u_strokeCap);
|
|
53
|
+
width *= (1. - clamp(u_strokeTaper, 0., 1.) * l);
|
|
54
|
+
|
|
55
|
+
float fw = fwidth(offset);
|
|
56
|
+
float fwMult = 4. - 3. * (smoothstep(.05, .4, 2. * u_strokeWidth) * smoothstep(.05, .4, 2. * (1. - u_strokeWidth)));
|
|
57
|
+
float pixelSize = mix(fwMult * fw, fwidth(shape), clamp(fw, 0., 1.));
|
|
58
|
+
pixelSize = mix(pixelSize, .002, u_strokeCap * (1. - clamp(l, 0., 1.)));
|
|
59
|
+
|
|
60
|
+
float res = smoothstep(width - pixelSize - u_softness, width + pixelSize + u_softness, shape);
|
|
61
|
+
|
|
62
|
+
vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
|
|
63
|
+
float fgOpacity = u_colorFront.a;
|
|
64
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
65
|
+
float bgOpacity = u_colorBack.a;
|
|
66
|
+
|
|
67
|
+
vec3 color = fgColor * res;
|
|
68
|
+
float opacity = fgOpacity * res;
|
|
69
|
+
|
|
70
|
+
color += bgColor * (1. - opacity);
|
|
71
|
+
opacity += bgOpacity * (1. - opacity);
|
|
72
|
+
|
|
73
|
+
${colorBandingFix}
|
|
74
|
+
|
|
75
|
+
fragColor = vec4(color, opacity);
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
export {
|
|
79
|
+
spiralFragmentShader
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=spiral.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 { simplexNoise, 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${simplexNoise}\n\nvoid main() {\n vec2 uv = 2. * v_patternUV;\n \n float t = u_time;\n float l = length(uv);\n float density = clamp(u_density, 0., 1.);\n l = pow(max(l, 1e-6), density);\n float angle = atan(uv.y, uv.x) - t;\n float angleNormalised = angle / TWO_PI;\n\n 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 = 1. - clamp(u_strokeWidth, .005 * u_strokeTaper, 1.);\n\n\n float wCap = mix(width, (1. - stripe) * (1. - step(.5, stripe)), (1. - clamp(l, 0., 1.)));\n width = mix(width, wCap, u_strokeCap);\n width *= (1. - clamp(u_strokeTaper, 0., 1.) * l);\n\n float fw = fwidth(offset);\n float fwMult = 4. - 3. * (smoothstep(.05, .4, 2. * u_strokeWidth) * smoothstep(.05, .4, 2. * (1. - u_strokeWidth)));\n float pixelSize = mix(fwMult * fw, fwidth(shape), clamp(fw, 0., 1.));\n pixelSize = mix(pixelSize, .002, u_strokeCap * (1. - clamp(l, 0., 1.)));\n\n float res = smoothstep(width - pixelSize - u_softness, width + pixelSize + u_softness, shape);\n\n vec3 fgColor = u_colorFront.rgb * u_colorFront.a;\n float fgOpacity = u_colorFront.a;\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n float bgOpacity = u_colorBack.a;\n\n vec3 color = fgColor * res;\n float opacity = fgOpacity * res;\n\n color += bgColor * (1. - opacity);\n opacity += bgOpacity * (1. - opacity);\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface SpiralUniforms extends ShaderSizingUniforms {\n u_colorBack: [number, number, number, number];\n u_colorFront: [number, number, number, number];\n u_density: number;\n u_distortion: number;\n u_strokeWidth: number;\n u_strokeTaper: number;\n u_strokeCap: number;\n u_noise: number;\n u_noiseFrequency: number;\n u_softness: number;\n}\n\nexport interface SpiralParams extends ShaderSizingParams, ShaderMotionParams {\n colorBack?: string;\n colorFront?: string;\n density?: number;\n distortion?: number;\n strokeWidth?: number;\n strokeTaper?: number;\n strokeCap?: number;\n noise?: number;\n noiseFrequency?: number;\n softness?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AACA,SAAS,kCAAsF;AAC/F,SAAS,cAAc,WAAW,uBAAuB;AAkBlD,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,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;AAAA;AAAA,IA4CV,eAAe;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
export declare const staticMeshGradientFragmentShader: string;
|
|
20
|
+
export interface StaticMeshGradientUniforms extends ShaderSizingUniforms {
|
|
21
|
+
u_colors: vec4[];
|
|
22
|
+
u_colorsCount: number;
|
|
23
|
+
u_positions: number;
|
|
24
|
+
u_waveX: number;
|
|
25
|
+
u_waveXShift: number;
|
|
26
|
+
u_waveY: number;
|
|
27
|
+
u_waveYShift: number;
|
|
28
|
+
u_mixing: number;
|
|
29
|
+
u_grainMixer: number;
|
|
30
|
+
u_grainOverlay: number;
|
|
31
|
+
}
|
|
32
|
+
export interface StaticMeshGradientParams extends ShaderSizingParams, ShaderMotionParams {
|
|
33
|
+
colors?: string[];
|
|
34
|
+
positions?: number;
|
|
35
|
+
waveX?: number;
|
|
36
|
+
waveXShift?: number;
|
|
37
|
+
waveY?: number;
|
|
38
|
+
waveYShift?: number;
|
|
39
|
+
mixing?: number;
|
|
40
|
+
grainMixer?: number;
|
|
41
|
+
grainOverlay?: number;
|
|
42
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
sizingDebugVariablesDeclaration,
|
|
8
|
+
sizingVariablesDeclaration,
|
|
9
|
+
sizingUniformsDeclaration
|
|
10
|
+
} from "../shader-sizing.js";
|
|
11
|
+
import { declarePI, rotation2, proceduralHash21 } from "../shader-utils.js";
|
|
12
|
+
const staticMeshGradientMeta = {
|
|
13
|
+
maxColorCount: 10
|
|
14
|
+
};
|
|
15
|
+
const staticMeshGradientFragmentShader = `#version 300 es
|
|
16
|
+
precision mediump float;
|
|
17
|
+
|
|
18
|
+
uniform vec4 u_colors[${staticMeshGradientMeta.maxColorCount}];
|
|
19
|
+
uniform float u_colorsCount;
|
|
20
|
+
|
|
21
|
+
uniform float u_positions;
|
|
22
|
+
uniform float u_waveX;
|
|
23
|
+
uniform float u_waveXShift;
|
|
24
|
+
uniform float u_waveY;
|
|
25
|
+
uniform float u_waveYShift;
|
|
26
|
+
uniform float u_mixing;
|
|
27
|
+
uniform float u_grainMixer;
|
|
28
|
+
uniform float u_grainOverlay;
|
|
29
|
+
|
|
30
|
+
${sizingVariablesDeclaration}
|
|
31
|
+
${sizingDebugVariablesDeclaration}
|
|
32
|
+
${sizingUniformsDeclaration}
|
|
33
|
+
|
|
34
|
+
out vec4 fragColor;
|
|
35
|
+
|
|
36
|
+
${declarePI}
|
|
37
|
+
${rotation2}
|
|
38
|
+
${proceduralHash21}
|
|
39
|
+
|
|
40
|
+
float valueNoise(vec2 st) {
|
|
41
|
+
vec2 i = floor(st);
|
|
42
|
+
vec2 f = fract(st);
|
|
43
|
+
float a = hash21(i);
|
|
44
|
+
float b = hash21(i + vec2(1.0, 0.0));
|
|
45
|
+
float c = hash21(i + vec2(0.0, 1.0));
|
|
46
|
+
float d = hash21(i + vec2(1.0, 1.0));
|
|
47
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
48
|
+
float x1 = mix(a, b, u.x);
|
|
49
|
+
float x2 = mix(c, d, u.x);
|
|
50
|
+
return mix(x1, x2, u.y);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
float noise(vec2 n, vec2 seedOffset) {
|
|
54
|
+
return valueNoise(n + seedOffset);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
vec2 getPosition(int i, float t) {
|
|
58
|
+
float a = float(i) * .37;
|
|
59
|
+
float b = .6 + mod(float(i), 3.) * .3;
|
|
60
|
+
float c = .8 + mod(float(i + 1), 4.) * 0.25;
|
|
61
|
+
|
|
62
|
+
float x = sin(t * b + a);
|
|
63
|
+
float y = cos(t * c + a * 1.5);
|
|
64
|
+
|
|
65
|
+
return .5 + .5 * vec2(x, y);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
void main() {
|
|
69
|
+
vec2 uv = v_objectUV;
|
|
70
|
+
uv += .5;
|
|
71
|
+
|
|
72
|
+
vec2 grainUV = v_objectUV;
|
|
73
|
+
// apply inverse transform to grain_uv so it respects the originXY
|
|
74
|
+
float grainUVRot = u_rotation * 3.14159265358979323846 / 180.;
|
|
75
|
+
mat2 graphicRotation = mat2(cos(grainUVRot), sin(grainUVRot), -sin(grainUVRot), cos(grainUVRot));
|
|
76
|
+
vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
|
|
77
|
+
grainUV = transpose(graphicRotation) * grainUV;
|
|
78
|
+
grainUV *= u_scale;
|
|
79
|
+
grainUV *= .7;
|
|
80
|
+
grainUV -= graphicOffset;
|
|
81
|
+
grainUV *= v_objectBoxSize;
|
|
82
|
+
|
|
83
|
+
float grain = noise(grainUV, vec2(0.));
|
|
84
|
+
float mixerGrain = .4 * u_grainMixer * (grain - .5);
|
|
85
|
+
|
|
86
|
+
float radius = smoothstep(0., 1., length(uv - .5));
|
|
87
|
+
float center = 1. - radius;
|
|
88
|
+
for (float i = 1.; i <= 2.; i++) {
|
|
89
|
+
uv.x += u_waveX * center / i * cos(TWO_PI * u_waveXShift + i * 2. * smoothstep(.0, 1., uv.y));
|
|
90
|
+
uv.y += u_waveY * center / i * cos(TWO_PI * u_waveYShift + i * 2. * smoothstep(.0, 1., uv.x));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
vec3 color = vec3(0.);
|
|
94
|
+
float opacity = 0.;
|
|
95
|
+
float totalWeight = 0.;
|
|
96
|
+
float positionSeed = 25. + .33 * u_positions;
|
|
97
|
+
|
|
98
|
+
for (int i = 0; i < ${staticMeshGradientMeta.maxColorCount}; i++) {
|
|
99
|
+
if (i >= int(u_colorsCount)) break;
|
|
100
|
+
|
|
101
|
+
vec2 pos = getPosition(i, positionSeed) + mixerGrain;
|
|
102
|
+
float dist = length(uv - pos);
|
|
103
|
+
dist = length(uv - pos);
|
|
104
|
+
|
|
105
|
+
vec3 colorFraction = u_colors[i].rgb * u_colors[i].a;
|
|
106
|
+
float opacityFraction = u_colors[i].a;
|
|
107
|
+
|
|
108
|
+
float power = 4.;
|
|
109
|
+
if (u_mixing > .5) {
|
|
110
|
+
power = mix(power, .75, 2. * (u_mixing - .5));
|
|
111
|
+
}
|
|
112
|
+
dist = pow(dist, power);
|
|
113
|
+
|
|
114
|
+
float w = 1. / (dist + 1e-3);
|
|
115
|
+
if (u_mixing < .5) {
|
|
116
|
+
w = pow(w, mix(mix(.01, 5., clamp(w, 0., 1.)), 1., 2. * u_mixing));
|
|
117
|
+
}
|
|
118
|
+
color += colorFraction * w;
|
|
119
|
+
opacity += opacityFraction * w;
|
|
120
|
+
totalWeight += w;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
color /= max(0.001, totalWeight);
|
|
124
|
+
opacity /= max(0.001, totalWeight);
|
|
125
|
+
|
|
126
|
+
float rr = noise(rotate(grainUV, 1.), vec2(3.));
|
|
127
|
+
float gg = noise(rotate(grainUV, 2.) + 10., vec2(-1.));
|
|
128
|
+
float bb = noise(grainUV - 2., vec2(5.));
|
|
129
|
+
vec3 grainColor = vec3(rr, gg, bb);
|
|
130
|
+
color = mix(color, grainColor, .01 + .3 * u_grainOverlay);
|
|
131
|
+
|
|
132
|
+
fragColor = vec4(color, opacity);
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
export {
|
|
136
|
+
staticMeshGradientFragmentShader,
|
|
137
|
+
staticMeshGradientMeta
|
|
138
|
+
};
|
|
139
|
+
//# 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 sizingDebugVariablesDeclaration,\n sizingVariablesDeclaration,\n sizingUniformsDeclaration,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from '../shader-sizing.js';\nimport { declarePI, rotation2, proceduralHash21 } from '../shader-utils.js';\n\nexport const staticMeshGradientMeta = {\n maxColorCount: 10,\n} as const;\n\n/**\n * 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// 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${sizingDebugVariablesDeclaration}\n${sizingUniformsDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${rotation2}\n${proceduralHash21}\n\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = hash21(i);\n float b = hash21(i + vec2(1.0, 0.0));\n float c = hash21(i + vec2(0.0, 1.0));\n float d = hash21(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\n\nfloat noise(vec2 n, vec2 seedOffset) {\n return valueNoise(n + seedOffset);\n}\n\nvec2 getPosition(int i, float t) {\n float a = float(i) * .37;\n float b = .6 + mod(float(i), 3.) * .3;\n float c = .8 + mod(float(i + 1), 4.) * 0.25;\n\n float x = sin(t * b + a);\n float y = cos(t * c + a * 1.5);\n\n return .5 + .5 * vec2(x, y);\n}\n\nvoid main() {\n vec2 uv = v_objectUV;\n uv += .5;\n\n vec2 grainUV = v_objectUV;\n // apply inverse transform to grain_uv so it respects the originXY\n float grainUVRot = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(grainUVRot), sin(grainUVRot), -sin(grainUVRot), cos(grainUVRot));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n grainUV = transpose(graphicRotation) * grainUV;\n grainUV *= u_scale;\n grainUV *= .7;\n grainUV -= graphicOffset;\n grainUV *= v_objectBoxSize;\n\n float grain = noise(grainUV, vec2(0.));\n float mixerGrain = .4 * u_grainMixer * (grain - .5);\n\n float radius = smoothstep(0., 1., length(uv - .5));\n float center = 1. - radius;\n for (float i = 1.; i <= 2.; i++) {\n uv.x += u_waveX * center / i * cos(TWO_PI * u_waveXShift + i * 2. * smoothstep(.0, 1., uv.y));\n uv.y += u_waveY * center / i * cos(TWO_PI * u_waveYShift + i * 2. * smoothstep(.0, 1., uv.x));\n }\n \n vec3 color = vec3(0.);\n float opacity = 0.;\n float totalWeight = 0.;\n float positionSeed = 25. + .33 * u_positions;\n\n for (int i = 0; i < ${staticMeshGradientMeta.maxColorCount}; i++) {\n if (i >= int(u_colorsCount)) break;\n\n vec2 pos = getPosition(i, positionSeed) + mixerGrain;\n float dist = length(uv - pos);\n 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 /= max(0.001, totalWeight);\n opacity /= max(0.001, totalWeight);\n\n float rr = noise(rotate(grainUV, 1.), vec2(3.));\n float gg = noise(rotate(grainUV, 2.) + 10., vec2(-1.));\n float bb = noise(grainUV - 2., vec2(5.));\n vec3 grainColor = vec3(rr, gg, bb);\n color = mix(color, grainColor, .01 + .3 * u_grainOverlay);\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,EACA;AAAA,OAGK;AACP,SAAS,WAAW,WAAW,wBAAwB;AAEhD,MAAM,yBAAyB;AAAA,EACpC,eAAe;AACjB;AAgBO,MAAM,mCAA2C;AAAA;AAAA;AAAA,wBAGhC,uBAAuB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY1D,0BAA0B;AAAA,EAC1B,+BAA+B;AAAA,EAC/B,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAIzB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,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,wBA4DM,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;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
export declare const staticRadialGradientFragmentShader: string;
|
|
22
|
+
export interface StaticRadialGradientUniforms extends ShaderSizingUniforms {
|
|
23
|
+
u_colorBack: [number, number, number, number];
|
|
24
|
+
u_colors: vec4[];
|
|
25
|
+
u_colorsCount: number;
|
|
26
|
+
u_radius: number;
|
|
27
|
+
u_focalDistance: number;
|
|
28
|
+
u_focalAngle: number;
|
|
29
|
+
u_falloff: number;
|
|
30
|
+
u_mixing: number;
|
|
31
|
+
u_distortion: number;
|
|
32
|
+
u_distortionShift: number;
|
|
33
|
+
u_distortionFreq: number;
|
|
34
|
+
u_grainMixer: number;
|
|
35
|
+
u_grainOverlay: number;
|
|
36
|
+
}
|
|
37
|
+
export interface StaticRadialGradientParams extends ShaderSizingParams, ShaderMotionParams {
|
|
38
|
+
colorBack?: string;
|
|
39
|
+
colors?: string[];
|
|
40
|
+
radius?: number;
|
|
41
|
+
focalDistance?: number;
|
|
42
|
+
focalAngle?: number;
|
|
43
|
+
falloff?: number;
|
|
44
|
+
mixing?: number;
|
|
45
|
+
distortion?: number;
|
|
46
|
+
distortionShift?: number;
|
|
47
|
+
distortionFreq?: number;
|
|
48
|
+
grainMixer?: number;
|
|
49
|
+
grainOverlay?: number;
|
|
50
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
sizingDebugVariablesDeclaration,
|
|
8
|
+
sizingVariablesDeclaration,
|
|
9
|
+
sizingUniformsDeclaration
|
|
10
|
+
} from "../shader-sizing.js";
|
|
11
|
+
import { declarePI, rotation2, proceduralHash21 } from "../shader-utils.js";
|
|
12
|
+
const staticRadialGradientMeta = {
|
|
13
|
+
maxColorCount: 10
|
|
14
|
+
};
|
|
15
|
+
const staticRadialGradientFragmentShader = `#version 300 es
|
|
16
|
+
precision mediump float;
|
|
17
|
+
|
|
18
|
+
uniform vec4 u_colorBack;
|
|
19
|
+
uniform vec4 u_colors[${staticRadialGradientMeta.maxColorCount}];
|
|
20
|
+
uniform float u_colorsCount;
|
|
21
|
+
|
|
22
|
+
uniform float u_radius;
|
|
23
|
+
uniform float u_focalDistance;
|
|
24
|
+
uniform float u_focalAngle;
|
|
25
|
+
uniform float u_falloff;
|
|
26
|
+
uniform float u_mixing;
|
|
27
|
+
uniform float u_distortion;
|
|
28
|
+
uniform float u_distortionShift;
|
|
29
|
+
uniform float u_distortionFreq;
|
|
30
|
+
uniform float u_grainMixer;
|
|
31
|
+
uniform float u_grainOverlay;
|
|
32
|
+
|
|
33
|
+
${sizingVariablesDeclaration}
|
|
34
|
+
${sizingDebugVariablesDeclaration}
|
|
35
|
+
${sizingUniformsDeclaration}
|
|
36
|
+
|
|
37
|
+
out vec4 fragColor;
|
|
38
|
+
|
|
39
|
+
${declarePI}
|
|
40
|
+
${rotation2}
|
|
41
|
+
${proceduralHash21}
|
|
42
|
+
|
|
43
|
+
float valueNoise(vec2 st) {
|
|
44
|
+
vec2 i = floor(st);
|
|
45
|
+
vec2 f = fract(st);
|
|
46
|
+
float a = hash21(i);
|
|
47
|
+
float b = hash21(i + vec2(1.0, 0.0));
|
|
48
|
+
float c = hash21(i + vec2(0.0, 1.0));
|
|
49
|
+
float d = hash21(i + vec2(1.0, 1.0));
|
|
50
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
51
|
+
float x1 = mix(a, b, u.x);
|
|
52
|
+
float x2 = mix(c, d, u.x);
|
|
53
|
+
return mix(x1, x2, u.y);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
float noise(vec2 n, vec2 seedOffset) {
|
|
57
|
+
return valueNoise(n + seedOffset);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
vec2 getPosition(int i, float t) {
|
|
61
|
+
float a = float(i) * .37;
|
|
62
|
+
float b = .6 + mod(float(i), 3.) * .3;
|
|
63
|
+
float c = .8 + mod(float(i + 1), 4.) * 0.25;
|
|
64
|
+
|
|
65
|
+
float x = sin(t * b + a);
|
|
66
|
+
float y = cos(t * c + a * 1.5);
|
|
67
|
+
|
|
68
|
+
return .5 + .5 * vec2(x, y);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
void main() {
|
|
72
|
+
vec2 uv = 2. * v_objectUV;
|
|
73
|
+
|
|
74
|
+
vec2 grainUV = v_objectUV;
|
|
75
|
+
// apply inverse transform to grain_uv so it respects the originXY
|
|
76
|
+
float grainUVRot = u_rotation * 3.14159265358979323846 / 180.;
|
|
77
|
+
mat2 graphicRotation = mat2(cos(grainUVRot), sin(grainUVRot), -sin(grainUVRot), cos(grainUVRot));
|
|
78
|
+
vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);
|
|
79
|
+
grainUV = transpose(graphicRotation) * grainUV;
|
|
80
|
+
grainUV *= u_scale;
|
|
81
|
+
grainUV *= .7;
|
|
82
|
+
grainUV -= graphicOffset;
|
|
83
|
+
grainUV *= v_objectBoxSize;
|
|
84
|
+
|
|
85
|
+
vec2 center = vec2(0.);
|
|
86
|
+
float angleRad = -radians(u_focalAngle + 90.);
|
|
87
|
+
vec2 focalPoint = vec2(cos(angleRad), sin(angleRad)) * u_focalDistance;
|
|
88
|
+
float radius = u_radius;
|
|
89
|
+
|
|
90
|
+
vec2 c_to_uv = uv - center;
|
|
91
|
+
vec2 f_to_uv = uv - focalPoint;
|
|
92
|
+
vec2 f_to_c = center - focalPoint;
|
|
93
|
+
float r = length(c_to_uv);
|
|
94
|
+
|
|
95
|
+
float fragAngle = atan(c_to_uv.y, c_to_uv.x);
|
|
96
|
+
float angleDiff = fract((fragAngle - angleRad + PI) / TWO_PI) * TWO_PI - PI;
|
|
97
|
+
|
|
98
|
+
float halfAngle = acos(clamp(radius / max(u_focalDistance, 1e-4), 0.0, 1.0));
|
|
99
|
+
float e0 = 0.6 * PI, e1 = halfAngle;
|
|
100
|
+
float lo = min(e0, e1), hi = max(e0, e1);
|
|
101
|
+
float s = smoothstep(lo, hi, abs(angleDiff));
|
|
102
|
+
float isInSector = (e1 >= e0) ? (1.0 - s) : s;
|
|
103
|
+
|
|
104
|
+
float a = dot(f_to_uv, f_to_uv);
|
|
105
|
+
float b = -2.0 * dot(f_to_uv, f_to_c);
|
|
106
|
+
float c = dot(f_to_c, f_to_c) - radius * radius;
|
|
107
|
+
|
|
108
|
+
float discriminant = b * b - 4.0 * a * c;
|
|
109
|
+
float t = 1.0;
|
|
110
|
+
|
|
111
|
+
if (discriminant >= 0.0) {
|
|
112
|
+
float sqrtD = sqrt(discriminant);
|
|
113
|
+
float div = max(1e-4, 2.0 * a);
|
|
114
|
+
float t0 = (-b - sqrtD) / div;
|
|
115
|
+
float t1 = (-b + sqrtD) / div;
|
|
116
|
+
t = max(t0, t1);
|
|
117
|
+
if (t < 0.0) t = 0.0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
float dist = length(f_to_uv);
|
|
121
|
+
float normalized = dist / max(1e-4, length(f_to_uv * t));
|
|
122
|
+
float shape = clamp(normalized, 0.0, 1.0);
|
|
123
|
+
|
|
124
|
+
float falloffMapped = mix(.2 + .8 * max(0., u_falloff + 1.), mix(1., 15., u_falloff * u_falloff), step(.0, u_falloff));
|
|
125
|
+
|
|
126
|
+
float falloffExp = mix(falloffMapped, 1., shape);
|
|
127
|
+
shape = pow(shape, falloffExp);
|
|
128
|
+
shape = 1. - clamp(shape, 0., 1.);
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
float outerMask = .002;
|
|
132
|
+
float outer = 1.0 - smoothstep(radius - outerMask, radius + outerMask, r);
|
|
133
|
+
outer = mix(outer, 1., isInSector);
|
|
134
|
+
|
|
135
|
+
shape = mix(0., shape, outer);
|
|
136
|
+
shape *= 1. - smoothstep(radius - .01, radius, r);
|
|
137
|
+
|
|
138
|
+
float angle = atan(f_to_uv.y, f_to_uv.x);
|
|
139
|
+
shape -= pow(u_distortion, 2.) * shape * pow(abs(sin(PI * clamp(length(f_to_uv) - 0.2 + u_distortionShift, 0.0, 1.0))), 4.0) * (sin(u_distortionFreq * angle) + cos(floor(0.65 * u_distortionFreq) * angle));
|
|
140
|
+
|
|
141
|
+
float grain = noise(grainUV, vec2(0.));
|
|
142
|
+
float mixerGrain = .4 * u_grainMixer * (grain - .5);
|
|
143
|
+
|
|
144
|
+
float mixer = shape * u_colorsCount + mixerGrain;
|
|
145
|
+
vec4 gradient = u_colors[0];
|
|
146
|
+
gradient.rgb *= gradient.a;
|
|
147
|
+
|
|
148
|
+
float outerShape = 0.;
|
|
149
|
+
for (int i = 1; i < ${staticRadialGradientMeta.maxColorCount + 1}; i++) {
|
|
150
|
+
if (i > int(u_colorsCount)) break;
|
|
151
|
+
float mLinear = clamp(mixer - float(i - 1), 0.0, 1.0);
|
|
152
|
+
|
|
153
|
+
float m = 0.;
|
|
154
|
+
float mixing = u_mixing * 3.;
|
|
155
|
+
if (mixing > 2.) {
|
|
156
|
+
float tt = mLinear * mLinear;
|
|
157
|
+
m = mix(mLinear, tt, .5 * clamp((mixing - 2.), 0., 1.));
|
|
158
|
+
} else if (mixing > 1.) {
|
|
159
|
+
m = mix(smoothstep(0., 1., mLinear), mLinear, clamp((mixing - 1.), 0., 1.));
|
|
160
|
+
} else {
|
|
161
|
+
float aa = fwidth(mLinear);
|
|
162
|
+
m = smoothstep(.5 - .5 * mixing - aa, .5 + .5 * mixing + aa, mLinear);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (i == 1) {
|
|
166
|
+
outerShape = m;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
vec4 c = u_colors[i - 1];
|
|
170
|
+
c.rgb *= c.a;
|
|
171
|
+
gradient = mix(gradient, c, m);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
vec3 color = gradient.rgb * outerShape;
|
|
175
|
+
float opacity = gradient.a * outerShape;
|
|
176
|
+
|
|
177
|
+
vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
|
|
178
|
+
color = color + bgColor * (1.0 - opacity);
|
|
179
|
+
opacity = opacity + u_colorBack.a * (1.0 - opacity);
|
|
180
|
+
|
|
181
|
+
float rr = noise(rotate(grainUV, 1.), vec2(3.));
|
|
182
|
+
float gg = noise(rotate(grainUV, 2.) + 10., vec2(-1.));
|
|
183
|
+
float bb = noise(grainUV - 2., vec2(5.));
|
|
184
|
+
vec3 grainColor = vec3(rr, gg, bb);
|
|
185
|
+
color = mix(color, grainColor, .01 + .3 * u_grainOverlay);
|
|
186
|
+
opacity += u_grainOverlay * grain;
|
|
187
|
+
|
|
188
|
+
fragColor = vec4(color, opacity);
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
191
|
+
export {
|
|
192
|
+
staticRadialGradientFragmentShader,
|
|
193
|
+
staticRadialGradientMeta
|
|
194
|
+
};
|
|
195
|
+
//# 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 sizingDebugVariablesDeclaration,\n sizingVariablesDeclaration,\n sizingUniformsDeclaration,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from '../shader-sizing.js';\nimport { declarePI, rotation2, proceduralHash21 } 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// 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${sizingDebugVariablesDeclaration}\n${sizingUniformsDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n${rotation2}\n${proceduralHash21}\n\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = hash21(i);\n float b = hash21(i + vec2(1.0, 0.0));\n float c = hash21(i + vec2(0.0, 1.0));\n float d = hash21(i + vec2(1.0, 1.0));\n vec2 u = f * f * (3.0 - 2.0 * f);\n float x1 = mix(a, b, u.x);\n float x2 = mix(c, d, u.x);\n return mix(x1, x2, u.y);\n}\n\nfloat noise(vec2 n, vec2 seedOffset) {\n return valueNoise(n + seedOffset);\n}\n\nvec2 getPosition(int i, float t) {\n float a = float(i) * .37;\n float b = .6 + mod(float(i), 3.) * .3;\n float c = .8 + mod(float(i + 1), 4.) * 0.25;\n\n float x = sin(t * b + a);\n float y = cos(t * c + a * 1.5);\n\n return .5 + .5 * vec2(x, y);\n}\n\nvoid main() {\n vec2 uv = 2. * v_objectUV;\n\n vec2 grainUV = v_objectUV;\n // apply inverse transform to grain_uv so it respects the originXY\n float grainUVRot = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(grainUVRot), sin(grainUVRot), -sin(grainUVRot), cos(grainUVRot));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n grainUV = transpose(graphicRotation) * grainUV;\n grainUV *= u_scale;\n grainUV *= .7;\n grainUV -= graphicOffset;\n grainUV *= v_objectBoxSize;\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 = fract((fragAngle - angleRad + PI) / TWO_PI) * TWO_PI - PI;\n\n float halfAngle = acos(clamp(radius / max(u_focalDistance, 1e-4), 0.0, 1.0));\n float e0 = 0.6 * PI, e1 = halfAngle;\n float lo = min(e0, e1), hi = max(e0, e1);\n float s = smoothstep(lo, hi, abs(angleDiff));\n float isInSector = (e1 >= e0) ? (1.0 - s) : s;\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 div = max(1e-4, 2.0 * a);\n float t0 = (-b - sqrtD) / div;\n float t1 = (-b + sqrtD) / div;\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 / max(1e-4, 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., u_falloff * u_falloff), 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 = 1.0 - smoothstep(radius - outerMask, radius + outerMask, r);\n outer = mix(outer, 1., isInSector);\n \n shape = mix(0., shape, outer);\n shape *= 1. - smoothstep(radius - .01, radius, r);\n\n float angle = atan(f_to_uv.y, f_to_uv.x);\n shape -= pow(u_distortion, 2.) * shape * pow(abs(sin(PI * clamp(length(f_to_uv) - 0.2 + u_distortionShift, 0.0, 1.0))), 4.0) * (sin(u_distortionFreq * angle) + cos(floor(0.65 * u_distortionFreq) * angle));\n\n float grain = noise(grainUV, vec2(0.));\n float mixerGrain = .4 * u_grainMixer * (grain - .5);\n\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 = mLinear * mLinear;\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 = noise(rotate(grainUV, 1.), vec2(3.));\n float gg = noise(rotate(grainUV, 2.) + 10., vec2(-1.));\n float bb = noise(grainUV - 2., vec2(5.));\n vec3 grainColor = vec3(rr, gg, bb);\n color = mix(color, grainColor, .01 + .3 * u_grainOverlay);\n opacity += u_grainOverlay * grain;\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,EACA;AAAA,OAGK;AACP,SAAS,WAAW,WAAW,wBAAwB;AAEhD,MAAM,2BAA2B;AAAA,EACtC,eAAe;AACjB;AAkBO,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,+BAA+B;AAAA,EAC/B,yBAAyB;AAAA;AAAA;AAAA;AAAA,EAIzB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,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,wBA4GM,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;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 swirlMeta: {
|
|
5
|
+
readonly maxColorCount: 10;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Twisting radial bands
|
|
9
|
+
*
|
|
10
|
+
* Uniforms:
|
|
11
|
+
* - u_colorBack (RGBA)
|
|
12
|
+
* - u_colors (vec4[]), u_colorsCount (float used as integer)
|
|
13
|
+
* - u_bandCount (float, used as int): number of sectors
|
|
14
|
+
* - u_twist: sectors twist intensity (0 = linear)
|
|
15
|
+
* - u_softness: color transition sharpness (0 = hard edge, 1 = smooth fade)
|
|
16
|
+
* - u_noise, u_noiseFrequency: simplex noise distortion over the shape
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export declare const swirlFragmentShader: string;
|
|
20
|
+
export interface SwirlUniforms extends ShaderSizingUniforms {
|
|
21
|
+
u_colorBack: [number, number, number, number];
|
|
22
|
+
u_colors: vec4[];
|
|
23
|
+
u_colorsCount: number;
|
|
24
|
+
u_bandCount: number;
|
|
25
|
+
u_twist: number;
|
|
26
|
+
u_center: number;
|
|
27
|
+
u_proportion: number;
|
|
28
|
+
u_softness: number;
|
|
29
|
+
u_noiseFrequency: number;
|
|
30
|
+
u_noise: number;
|
|
31
|
+
}
|
|
32
|
+
export interface SwirlParams extends ShaderSizingParams, ShaderMotionParams {
|
|
33
|
+
colorBack?: string;
|
|
34
|
+
colors?: string[];
|
|
35
|
+
bandCount?: number;
|
|
36
|
+
twist?: number;
|
|
37
|
+
center?: number;
|
|
38
|
+
proportion?: number;
|
|
39
|
+
softness?: number;
|
|
40
|
+
noiseFrequency?: number;
|
|
41
|
+
noise?: number;
|
|
42
|
+
}
|