@skathi-native/cli 0.1.0-beta.4 → 0.2.0
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/aot-inputs.ts +21 -2
- package/build.ts +241 -60
- package/check/bundle.ts +265 -0
- package/check/graph.ts +3 -1
- package/check/index.ts +10 -1
- package/check/program.ts +26 -6
- package/cli/create.ts +29 -7
- package/devtools/commands.ts +25 -0
- package/effects/compile.ts +160 -31
- package/effects/sk.slang +353 -29
- package/package.json +7 -4
- package/prod.ts +40 -7
- package/svelte.ts +76 -0
- package/templates/icon.png +0 -0
- package/templates/showcase/assets/textures/golden.png +0 -0
- package/templates/showcase/assets/textures/hammered.png +0 -0
- package/templates/showcase/assets/textures/noir.png +0 -0
- package/templates/showcase/assets/textures/reeded.png +0 -0
- package/templates/showcase/assets/textures/teal-orange.png +0 -0
- package/templates/showcase/shaders/dissolve.slang +40 -0
- package/templates/showcase/shaders/fireflies.slang +58 -0
- package/templates/showcase/shaders/glass.slang +31 -0
- package/templates/showcase/shaders/grade.slang +34 -0
- package/templates/showcase/shaders/halftone.slang +42 -0
- package/templates/showcase/shaders/lens.slang +51 -0
- package/templates/showcase/shaders/nebula.slang +57 -0
- package/templates/showcase/shaders/orbit.slang +52 -0
- package/templates/showcase/shaders/pond.slang +76 -0
- package/templates/showcase/shaders/ripples.slang +71 -0
- package/templates/showcase/shaders/shatter.slang +116 -0
- package/templates/showcase/shaders/snow.slang +57 -0
- package/templates/showcase/shaders/spotlight.slang +52 -0
- package/templates/showcase/src/App.vue +11 -16
- package/templates/showcase/src/components/FullWindow.vue +77 -0
- package/templates/showcase/src/components/Page.vue +2 -0
- package/templates/showcase/src/fullwindow.ts +36 -0
- package/templates/showcase/src/icons.ts +2 -0
- package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
- package/templates/showcase/src/pages/MotionPage.vue +71 -1
- package/templates/showcase/src/pages/ShadersPage.vue +443 -0
- package/templates/showcase/src/router.ts +32 -1
- package/templates/svelte/.vscode/settings.json +3 -0
- package/templates/svelte/assets/hello.txt +1 -0
- package/templates/svelte/src/App.svelte +142 -0
- package/templates/svelte/src/main.ts +4 -0
- package/vitecompat.ts +2 -0
package/svelte.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Svelte 5 components (`.svelte`) and rune modules (`.svelte.ts`, `.svelte.js`), compiled with the app's own
|
|
2
|
+
// `svelte/compiler`: the compiled code calls `svelte/internal/client`, which must be the same version.
|
|
3
|
+
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import type * as SvelteCompiler from "svelte/compiler";
|
|
6
|
+
|
|
7
|
+
type Compiler = typeof SvelteCompiler;
|
|
8
|
+
|
|
9
|
+
/** Files the Svelte compiler owns, components and rune modules both. */
|
|
10
|
+
export const SVELTE_SOURCE = /\.svelte(?:\.[jt]s)?$/;
|
|
11
|
+
const RUNE_MODULE = /\.svelte\.[jt]s$/;
|
|
12
|
+
|
|
13
|
+
const compilers = new Map<string, Promise<Compiler>>();
|
|
14
|
+
|
|
15
|
+
/** `svelte/compiler` as the app at `appRoot` resolves it. */
|
|
16
|
+
export function svelteCompiler(appRoot: string): Promise<Compiler> {
|
|
17
|
+
let compiler = compilers.get(appRoot);
|
|
18
|
+
if (!compiler) {
|
|
19
|
+
compiler = (async () => {
|
|
20
|
+
let path: string;
|
|
21
|
+
try {
|
|
22
|
+
path = Bun.resolveSync("svelte/compiler", appRoot);
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`${appRoot}: a .svelte file needs Svelte 5 installed in the app: add "svelte" to its dependencies`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
const mod = (await import(pathToFileURL(path).href)) as Compiler;
|
|
29
|
+
if (!/^5\./.test(mod.VERSION)) {
|
|
30
|
+
throw new Error(`${appRoot}: svelte ${mod.VERSION} is installed; Skathi compiles Svelte 5 components`);
|
|
31
|
+
}
|
|
32
|
+
return mod;
|
|
33
|
+
})();
|
|
34
|
+
compilers.set(appRoot, compiler);
|
|
35
|
+
}
|
|
36
|
+
return compiler;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface SvelteOutput {
|
|
40
|
+
js: string;
|
|
41
|
+
css: string | null;
|
|
42
|
+
warnings: string[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const stripTypes = new Bun.Transpiler({ loader: "ts", trimUnusedImports: false });
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Compiles one Svelte source. `filename` names it in dev diagnostics and seeds the scoped-CSS hash, so it is the
|
|
49
|
+
* module id, stable across machines. `dev` adds Svelte's runtime checks and the `import.meta.hot` epilogue.
|
|
50
|
+
*/
|
|
51
|
+
export async function compileSvelte(
|
|
52
|
+
appRoot: string,
|
|
53
|
+
absPath: string,
|
|
54
|
+
source: string,
|
|
55
|
+
o: { dev: boolean; filename: string },
|
|
56
|
+
): Promise<SvelteOutput> {
|
|
57
|
+
const svelte = await svelteCompiler(appRoot);
|
|
58
|
+
const describe = (w: SvelteCompiler.Warning) =>
|
|
59
|
+
`${o.filename}${w.start ? `:${w.start.line}:${w.start.column + 1}` : ""}: ${w.message.split("\n")[0]} (${w.code})`;
|
|
60
|
+
if (RUNE_MODULE.test(absPath)) {
|
|
61
|
+
const js = absPath.endsWith(".ts") ? stripTypes.transformSync(source) : source;
|
|
62
|
+
const out = svelte.compileModule(js, { filename: o.filename, generate: "client", dev: o.dev });
|
|
63
|
+
return { js: out.js.code, css: null, warnings: out.warnings.map(describe) };
|
|
64
|
+
}
|
|
65
|
+
const out = svelte.compile(source, {
|
|
66
|
+
filename: o.filename,
|
|
67
|
+
generate: "client",
|
|
68
|
+
dev: o.dev,
|
|
69
|
+
hmr: o.dev,
|
|
70
|
+
// The builders route component CSS into the app stylesheet, as they do an SFC's <style>.
|
|
71
|
+
css: "external",
|
|
72
|
+
// svelte-dom-shim: fragments: "tree" builds templates with createElement, since Skathi's DOM has no HTML parser for the default <template> innerHTML; goes with the custom renderer (sveltejs/svelte#18042)
|
|
73
|
+
fragments: "tree",
|
|
74
|
+
});
|
|
75
|
+
return { js: out.js.code, css: out.css?.code ?? null, warnings: out.warnings.map(describe) };
|
|
76
|
+
}
|
package/templates/icon.png
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Burns the element away: its own painting is eaten by noise from the ragged edge inwards, with a
|
|
4
|
+
// glowing ember rim. `progress` is a plain number, so a CSS transition on `--shading` plays the burn.
|
|
5
|
+
[SkEffect("dissolve")]
|
|
6
|
+
[SkDoc("burns the element's own painting away behind an ember edge")]
|
|
7
|
+
[SkContent]
|
|
8
|
+
struct Dissolve : IEffect
|
|
9
|
+
{
|
|
10
|
+
// 0 is the element untouched, 1 is all of it gone.
|
|
11
|
+
[SkDefault("0")] [SkRange(0.0, 1.0)]
|
|
12
|
+
float progress;
|
|
13
|
+
|
|
14
|
+
// The size of the burnt patches.
|
|
15
|
+
[SkLength] [SkDefault("46")] [SkRange(4.0, 1024.0)]
|
|
16
|
+
float grain;
|
|
17
|
+
|
|
18
|
+
[SkColor] [SkOptional] [SkDefault("#ff7a1a")]
|
|
19
|
+
float4 ember;
|
|
20
|
+
|
|
21
|
+
float4 shade(EffectInput input)
|
|
22
|
+
{
|
|
23
|
+
// Mostly noise, a little of the distance from the top left, so the burn sweeps across.
|
|
24
|
+
float n = sk_fbm(input.px / max(grain, 1.0)) * 0.75 + dot(input.local, float2(0.15, 0.1));
|
|
25
|
+
float edge = progress * 1.12 - 0.06;
|
|
26
|
+
float burnt = n - edge;
|
|
27
|
+
float width = 0.05;
|
|
28
|
+
|
|
29
|
+
float4 content = input.contentAtPx(input.px + float2(0.0, -6.0 * input.scale * saturate(1.0 - burnt / width)));
|
|
30
|
+
float alive = smoothstep(0.0, 0.012, burnt);
|
|
31
|
+
float rim = alive * (1.0 - smoothstep(0.0, width, burnt));
|
|
32
|
+
|
|
33
|
+
// The rim chars the content to black, then glows through it.
|
|
34
|
+
float3 rgb = lerp(content.rgb, float3(0.0, 0.0, 0.0), rim * 0.8 * content.a);
|
|
35
|
+
float flicker = 0.6 + 0.4 * sk_value_noise(input.px / (6.0 * input.scale) + input.time * 3.0);
|
|
36
|
+
float glow = rim * rim * flicker * content.a;
|
|
37
|
+
float4 shaded = float4(rgb, content.a) * alive;
|
|
38
|
+
return sk_over(shaded, float4(ember.rgb, 1.0) * glow * ember.a);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Fireflies wandering over the element on paths made of incommensurate sines, so no two repeat,
|
|
4
|
+
// each blinking on its own rhythm. With `lure` above 0 the ones near the pointer gather round it while
|
|
5
|
+
// it is in the window.
|
|
6
|
+
[SkEffect("fireflies")]
|
|
7
|
+
[SkDoc("glowing fireflies drifting about, drawn to the pointer")]
|
|
8
|
+
struct Fireflies : IEffect
|
|
9
|
+
{
|
|
10
|
+
[SkAnimated] [SkDefault("1")] [SkRange(0.0, 4.0)]
|
|
11
|
+
float speed;
|
|
12
|
+
|
|
13
|
+
// The glow's radius.
|
|
14
|
+
[SkLength] [SkDefault("16")] [SkRange(2.0, 128.0)]
|
|
15
|
+
float glow;
|
|
16
|
+
|
|
17
|
+
// 0 ignores the pointer; 1 gathers the nearby fireflies round it.
|
|
18
|
+
[SkDefault("0")] [SkRange(0.0, 1.0)]
|
|
19
|
+
float lure;
|
|
20
|
+
|
|
21
|
+
[SkPointer]
|
|
22
|
+
float2 at;
|
|
23
|
+
|
|
24
|
+
[SkPointerTimes]
|
|
25
|
+
float3 seen;
|
|
26
|
+
|
|
27
|
+
float4 shade(EffectInput input)
|
|
28
|
+
{
|
|
29
|
+
float t = input.time * speed;
|
|
30
|
+
float reach = max(glow, 1.0);
|
|
31
|
+
float aspect = input.size.x / max(input.size.y, 1.0);
|
|
32
|
+
float near = sk_pointer_presence(seen, input.time, 0.5);
|
|
33
|
+
float3 light = float3(0.0, 0.0, 0.0);
|
|
34
|
+
for (int i = 0; i < 28; i++)
|
|
35
|
+
{
|
|
36
|
+
float2 h = sk_hash22(float2(i, 3.7));
|
|
37
|
+
float2 k = sk_hash22(float2(i, 9.1));
|
|
38
|
+
float2 wander = 0.5 + float2(
|
|
39
|
+
0.30 * sin(t * (0.07 + 0.09 * h.x) + 6.28 * h.y) + 0.17 * sin(t * (0.19 + 0.13 * k.x) + 6.28 * k.y),
|
|
40
|
+
0.28 * sin(t * (0.05 + 0.08 * k.y) + 6.28 * k.x) + 0.18 * sin(t * (0.23 + 0.11 * h.y) + 6.28 * h.x));
|
|
41
|
+
|
|
42
|
+
// Drawn in by distance in the element's own proportions, then kept circling the pointer.
|
|
43
|
+
float2 toward = (at - wander) * float2(aspect, 1.0);
|
|
44
|
+
float pull = lure * near * exp(-dot(toward, toward) / 0.35);
|
|
45
|
+
float2 circle = float2(cos(t * (0.6 + h.x) + 6.28 * k.x) / aspect, sin(t * (0.6 + h.x) + 6.28 * k.x));
|
|
46
|
+
float2 spot = lerp(wander, at + circle * (0.04 + 0.06 * k.y), pull) * input.size;
|
|
47
|
+
|
|
48
|
+
float2 d = input.px - spot;
|
|
49
|
+
float r2 = dot(d, d) / (reach * reach);
|
|
50
|
+
float blink = 0.15 + 0.85 * pow(saturate(sin(t * (0.7 + 1.1 * h.y) + 6.28 * k.x)), 3.0);
|
|
51
|
+
float shine = (exp(-r2 * 24.0) + 0.35 * exp(-r2 * 2.0)) * blink;
|
|
52
|
+
float3 tint = lerp(float3(0.75, 1.0, 0.35), float3(1.0, 0.78, 0.3), k.x);
|
|
53
|
+
light += tint * shine;
|
|
54
|
+
}
|
|
55
|
+
float strength = max(light.r, max(light.g, light.b));
|
|
56
|
+
return float4(light, saturate(strength));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Patterned glass. A tiling normal map bends the backdrop pixel by pixel and catches a little light,
|
|
4
|
+
// one texel of the map per `scale` pixels.
|
|
5
|
+
[SkEffect("glass")]
|
|
6
|
+
[SkDoc("textured glass: a repeating normal map refracts what is behind")]
|
|
7
|
+
[SkBackdrop]
|
|
8
|
+
struct Glass : IEffect
|
|
9
|
+
{
|
|
10
|
+
[SkLinear] [SkDefault("#8080ffff")]
|
|
11
|
+
SkTexture normals;
|
|
12
|
+
|
|
13
|
+
[SkLength] [SkDefault("10")] [SkRange(0.0, 64.0)]
|
|
14
|
+
float depth;
|
|
15
|
+
|
|
16
|
+
[SkDefault("1")] [SkRange(0.25, 8.0)]
|
|
17
|
+
float scale;
|
|
18
|
+
|
|
19
|
+
[SkColor] [SkOptional] [SkDefault("#ffffff10")]
|
|
20
|
+
float4 tint;
|
|
21
|
+
|
|
22
|
+
float4 shade(EffectInput input)
|
|
23
|
+
{
|
|
24
|
+
float2 tile = max(normals.size, float2(1.0, 1.0)) * scale;
|
|
25
|
+
float3 n = normals.sampleRepeat(input.px / tile).xyz * 2.0 - 1.0;
|
|
26
|
+
float4 seen = input.backdropAtPx(input.px + n.xy * depth);
|
|
27
|
+
float light = 0.2 * pow(saturate(dot(normalize(n), normalize(float3(-0.4, -0.6, 0.7)))), 12.0);
|
|
28
|
+
float4 glass = sk_over(seen, sk_premultiply(tint));
|
|
29
|
+
return float4(glass.rgb + light, saturate(glass.a + light * (1.0 - glass.a)));
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// A colour grade through a 3D lookup table: 16 slices of 16x16 side by side, red across a slice,
|
|
4
|
+
// green down it, blue from slice to slice. Until the image arrives it shows the backdrop as it is.
|
|
5
|
+
[SkEffect("grade")]
|
|
6
|
+
[SkDoc("re-colours the backdrop through a 16x16x16 LUT image")]
|
|
7
|
+
[SkBackdrop]
|
|
8
|
+
struct Grade : IEffect
|
|
9
|
+
{
|
|
10
|
+
[SkLinear]
|
|
11
|
+
SkTexture lut;
|
|
12
|
+
|
|
13
|
+
[SkDefault("1")] [SkRange(0.0, 1.0)]
|
|
14
|
+
float amount;
|
|
15
|
+
|
|
16
|
+
float3 lookup(float3 c)
|
|
17
|
+
{
|
|
18
|
+
float blue = c.b * 15.0;
|
|
19
|
+
float slice = floor(blue);
|
|
20
|
+
float2 cell = float2(c.r * 15.0 + 0.5, c.g * 15.0 + 0.5);
|
|
21
|
+
float3 lo = lut.sample((cell + float2(slice * 16.0, 0.0)) / lut.size).rgb;
|
|
22
|
+
float3 hi = lut.sample((cell + float2(min(slice + 1.0, 15.0) * 16.0, 0.0)) / lut.size).rgb;
|
|
23
|
+
return lerp(lo, hi, blue - slice);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
float4 shade(EffectInput input)
|
|
27
|
+
{
|
|
28
|
+
float4 seen = input.backdrop;
|
|
29
|
+
if (!lut.loaded())
|
|
30
|
+
return seen;
|
|
31
|
+
float3 rgb = saturate(seen.rgb / max(seen.a, 1e-4));
|
|
32
|
+
return float4(lerp(rgb, lookup(rgb), amount) * seen.a, seen.a);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// A print-style halftone of whatever is behind the element: an image, a video, the page. Every pixel
|
|
4
|
+
// of a cell reads the backdrop at the cell's centre, so a cell is one dot of one colour, sized by how
|
|
5
|
+
// bright that spot is.
|
|
6
|
+
[SkEffect("halftone")]
|
|
7
|
+
[SkDoc("re-screens the backdrop as rotated halftone dots")]
|
|
8
|
+
[SkBackdrop]
|
|
9
|
+
struct Halftone : IEffect
|
|
10
|
+
{
|
|
11
|
+
[SkLength] [SkDefault("9")] [SkRange(3.0, 64.0)]
|
|
12
|
+
float cell;
|
|
13
|
+
|
|
14
|
+
// Screen angle in turns: 0.125 is the classic 45 degrees.
|
|
15
|
+
[SkDefault("0.125")] [SkRange(-1.0, 1.0)]
|
|
16
|
+
float angle;
|
|
17
|
+
|
|
18
|
+
// How much colour the dots keep: 0 prints them in `paper`'s complement, 1 in the backdrop's own.
|
|
19
|
+
[SkDefault("1")] [SkRange(0.0, 1.0)]
|
|
20
|
+
float colour;
|
|
21
|
+
|
|
22
|
+
[SkColor] [SkOptional] [SkDefault("#0b0b12")]
|
|
23
|
+
float4 paper;
|
|
24
|
+
|
|
25
|
+
float4 shade(EffectInput input)
|
|
26
|
+
{
|
|
27
|
+
float turn = angle * 6.28318530718;
|
|
28
|
+
float2 q = sk_rotate(input.px, -turn) / cell;
|
|
29
|
+
float2 centre = floor(q) + 0.5;
|
|
30
|
+
|
|
31
|
+
// Back to element pixels, kept inside the element so the edge cells read its own backdrop.
|
|
32
|
+
float2 at = clamp(sk_rotate(centre * cell, turn), float2(0.0, 0.0), input.size);
|
|
33
|
+
float4 seen = input.backdropAtPx(at);
|
|
34
|
+
|
|
35
|
+
float3 rgb = seen.rgb / max(seen.a, 1e-4);
|
|
36
|
+
float ink = sqrt(saturate(sk_luma(rgb) * 1.15)) * 0.5 * cell;
|
|
37
|
+
float disc = input.aa(length(q - centre) * cell - ink);
|
|
38
|
+
|
|
39
|
+
float3 tone = lerp(1.0 - paper.rgb, saturate(rgb * 1.2), colour);
|
|
40
|
+
return float4(lerp(paper.rgb, tone, disc), 1.0);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Liquid glass. It reads the backdrop at displaced coordinates rather than under the pixel: the
|
|
4
|
+
// middle magnifies a little, and the curved rim gathers in what lies just outside the element, each
|
|
5
|
+
// colour channel from a slightly different place.
|
|
6
|
+
[SkEffect("lens")]
|
|
7
|
+
[SkDoc("liquid glass: refraction, dispersion and a specular rim over whatever is behind")]
|
|
8
|
+
[SkBackdrop]
|
|
9
|
+
struct Lens : IEffect
|
|
10
|
+
{
|
|
11
|
+
// How far past the edge the rim reaches for what it shows.
|
|
12
|
+
[SkLength] [SkDefault("18")] [SkRange(0.0, 96.0)]
|
|
13
|
+
float depth;
|
|
14
|
+
|
|
15
|
+
// The width of the curved rim; inside it the glass is flat.
|
|
16
|
+
[SkLength] [SkDefault("24")] [SkRange(1.0, 256.0)]
|
|
17
|
+
float bevel;
|
|
18
|
+
|
|
19
|
+
// How far apart red and blue refract, as a fraction of the bend.
|
|
20
|
+
[SkDefault("0.12")] [SkRange(0.0, 1.0)]
|
|
21
|
+
float dispersion;
|
|
22
|
+
|
|
23
|
+
[SkColor] [SkOptional] [SkDefault("#ffffff0f")]
|
|
24
|
+
float4 tint;
|
|
25
|
+
|
|
26
|
+
float4 shade(EffectInput input)
|
|
27
|
+
{
|
|
28
|
+
// `sd` is a distance field, so its screen-space gradient is the outward normal of the rim.
|
|
29
|
+
float2 gradient = float2(ddx(input.sd), ddy(input.sd));
|
|
30
|
+
float2 normal = gradient / max(length(gradient), 1e-4);
|
|
31
|
+
|
|
32
|
+
float edge = 1.0 - saturate(-input.sd / max(bevel, 1.0));
|
|
33
|
+
float curve = edge * edge;
|
|
34
|
+
|
|
35
|
+
float2 magnify = (input.size * 0.5 - input.px) * 0.07;
|
|
36
|
+
float2 shift = normal * depth * curve + magnify;
|
|
37
|
+
float r = input.backdropAtPx(input.px + shift * (1.0 + dispersion)).r;
|
|
38
|
+
float4 g = input.backdropAtPx(input.px + shift);
|
|
39
|
+
float b = input.backdropAtPx(input.px + shift * (1.0 - dispersion)).b;
|
|
40
|
+
float4 glass = sk_over(float4(r, g.g, b, g.a), sk_premultiply(tint));
|
|
41
|
+
|
|
42
|
+
// A key light from the top left catches that rim, a weaker internal reflection the opposite one.
|
|
43
|
+
float facing = dot(normal, float2(-0.6, -0.8));
|
|
44
|
+
float rim = pow(edge, 5.0);
|
|
45
|
+
float specular = rim * (0.5 * saturate(facing) + 0.16 * saturate(-facing));
|
|
46
|
+
float sheen = 0.05 * saturate(1.0 - input.local.y * 1.6) * (1.0 - edge);
|
|
47
|
+
|
|
48
|
+
float light = specular + sheen;
|
|
49
|
+
return float4(glass.rgb + light, saturate(glass.a + light * (1.0 - glass.a)));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Domain warping: noise sampled at coordinates bent by more noise, twice over, so the field folds into
|
|
4
|
+
// gas-like filaments. It paints the whole element; `hue` is a plain number, so a CSS transition on
|
|
5
|
+
// `--shading` cross-fades the palette while the gas keeps moving.
|
|
6
|
+
[SkEffect("nebula")]
|
|
7
|
+
[SkDoc("drifting domain-warped gas with twinkling stars")]
|
|
8
|
+
struct Nebula : IEffect
|
|
9
|
+
{
|
|
10
|
+
[SkAnimated] [SkDefault("0.12")] [SkRange(0.0, 2.0)]
|
|
11
|
+
float speed;
|
|
12
|
+
|
|
13
|
+
// Features per shorter side of the element.
|
|
14
|
+
[SkDefault("2.2")] [SkRange(0.2, 12.0)]
|
|
15
|
+
float scale;
|
|
16
|
+
|
|
17
|
+
// Shifts the palette around the colour wheel, 0..1.
|
|
18
|
+
[SkDefault("0")] [SkRange(-4.0, 4.0)]
|
|
19
|
+
float hue;
|
|
20
|
+
|
|
21
|
+
// The brightest filaments and the stars.
|
|
22
|
+
[SkColor] [SkOptional] [SkDefault("#ffe6c7")]
|
|
23
|
+
float4 glow;
|
|
24
|
+
|
|
25
|
+
float4 shade(EffectInput input)
|
|
26
|
+
{
|
|
27
|
+
float t = input.time * speed;
|
|
28
|
+
float2 p = input.centered() * scale;
|
|
29
|
+
|
|
30
|
+
float2 q = float2(sk_fbm(p + float2(0.0, t)), sk_fbm(p + float2(5.2, 1.3) - t * 0.7));
|
|
31
|
+
float2 r = float2(
|
|
32
|
+
sk_fbm(p + 2.8 * q + float2(1.7, 9.2) + t * 1.3),
|
|
33
|
+
sk_fbm(p + 2.8 * q + float2(8.3, 2.8) - t * 0.9));
|
|
34
|
+
float f = sk_fbm(p + 2.8 * r);
|
|
35
|
+
|
|
36
|
+
float3 rgb = sk_palette(
|
|
37
|
+
f + length(q) * 0.35 + hue,
|
|
38
|
+
float3(0.42, 0.30, 0.52),
|
|
39
|
+
float3(0.42, 0.30, 0.40),
|
|
40
|
+
float3(1.0, 1.0, 1.0),
|
|
41
|
+
float3(0.62, 0.78, 0.95));
|
|
42
|
+
float density = smoothstep(0.25, 0.95, f * f * 1.6 + r.x * 0.45);
|
|
43
|
+
rgb *= 0.18 + 0.95 * density;
|
|
44
|
+
rgb = lerp(rgb, glow.rgb, pow(saturate(f * 1.25 - 0.35), 3.0) * glow.a);
|
|
45
|
+
|
|
46
|
+
// A sparse star field on a lattice in logical pixels, so the stars keep their size on any display.
|
|
47
|
+
float lattice = 7.0 * input.scale;
|
|
48
|
+
float2 cell = floor(input.px / lattice);
|
|
49
|
+
float2 spot = (cell + 0.2 + 0.6 * sk_hash22(cell + 11.0)) * lattice;
|
|
50
|
+
float size = (0.5 + 0.9 * sk_hash12(cell + 5.0)) * input.scale;
|
|
51
|
+
float star = step(0.975, sk_hash12(cell)) * input.aa(length(input.px - spot) - size);
|
|
52
|
+
float twinkle = 0.5 + 0.5 * sin(input.time * (1.5 + 3.0 * sk_hash12(cell + 7.0)) + 40.0 * sk_hash12(cell + 3.0));
|
|
53
|
+
rgb += glow.rgb * star * twinkle * (1.0 - density * 0.5);
|
|
54
|
+
|
|
55
|
+
return float4(rgb, 1.0);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Two comets chasing each other around the element's rounded border. `halo` is the `[SkBleed]`
|
|
4
|
+
// parameter: the drawn quad grows by it, so the light spills past the border box instead of being cut
|
|
5
|
+
// off at it.
|
|
6
|
+
[SkEffect("orbit")]
|
|
7
|
+
[SkDoc("light running around the border, glowing past it")]
|
|
8
|
+
struct Orbit : IEffect
|
|
9
|
+
{
|
|
10
|
+
// Laps per second.
|
|
11
|
+
[SkAnimated] [SkDefault("0.35")] [SkRange(0.0, 4.0)]
|
|
12
|
+
float speed;
|
|
13
|
+
|
|
14
|
+
[SkLength] [SkDefault("2")] [SkRange(0.5, 16.0)]
|
|
15
|
+
float width;
|
|
16
|
+
|
|
17
|
+
[SkLength] [SkBleed] [SkDefault("18")] [SkRange(0.0, 96.0)]
|
|
18
|
+
float halo;
|
|
19
|
+
|
|
20
|
+
// How much of the lap the tail covers, 0..1.
|
|
21
|
+
[SkDefault("0.35")] [SkRange(0.02, 1.0)]
|
|
22
|
+
float tail;
|
|
23
|
+
|
|
24
|
+
[SkColor] [SkDefault("#7fd4ff")]
|
|
25
|
+
float4 color;
|
|
26
|
+
|
|
27
|
+
static override bool straightAlpha() { return true; }
|
|
28
|
+
|
|
29
|
+
// A long tail behind the head and a short soft front, so no edge of the light is a hard cut.
|
|
30
|
+
float comet(float around, float head)
|
|
31
|
+
{
|
|
32
|
+
float ahead = frac(around - head + 0.5) - 0.5;
|
|
33
|
+
float front = ahead / 0.02;
|
|
34
|
+
return ahead > 0.0 ? exp(-front * front) : pow(saturate(1.0 + ahead / tail), 3.0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
float4 shade(EffectInput input)
|
|
38
|
+
{
|
|
39
|
+
float2 c = input.local * 2.0 - 1.0;
|
|
40
|
+
float around = atan2(c.y, c.x) / 6.28318530718 + 0.5;
|
|
41
|
+
float head = frac(input.time * speed);
|
|
42
|
+
float light = comet(around, head) + 0.65 * comet(around, head + 0.5);
|
|
43
|
+
|
|
44
|
+
float stroke = input.aa(abs(input.sd + width * 0.5) - width * 0.5);
|
|
45
|
+
float outside = max(input.sd, 0.0) / max(halo, 1.0);
|
|
46
|
+
float glow = exp(-outside * 4.0) * (input.sd > 0.0 ? 1.0 : saturate(1.0 + input.sd / (width * 4.0)));
|
|
47
|
+
|
|
48
|
+
float alpha = stroke * (0.14 + 0.86 * light) + glow * light * 0.55;
|
|
49
|
+
float3 rgb = lerp(color.rgb, float3(1.0, 1.0, 1.0), stroke * light * light * 0.6);
|
|
50
|
+
return float4(rgb, saturate(alpha * color.a));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// A water surface over the element's own painting. The pointer drags through it; the waves it makes
|
|
4
|
+
// run outwards, bounce off the edges and die down, and they bend and light what is under them.
|
|
5
|
+
//
|
|
6
|
+
// The surface is a wave equation stepped in the history: red is the height now, green the height one
|
|
7
|
+
// step ago. The window keeps repainting for four seconds after the pointer last moved, which is long
|
|
8
|
+
// enough for the water to settle.
|
|
9
|
+
[SkEffect("pond")]
|
|
10
|
+
[SkDoc("a rippling water surface the pointer stirs, over the element's own painting")]
|
|
11
|
+
[SkContent]
|
|
12
|
+
[SkHistory]
|
|
13
|
+
struct Pond : IEffect
|
|
14
|
+
{
|
|
15
|
+
// How long a wave lasts: the share of its height it keeps each step.
|
|
16
|
+
[SkDefault("0.985")] [SkRange(0.8, 0.999)]
|
|
17
|
+
float damping;
|
|
18
|
+
|
|
19
|
+
// How far the slope of the water shifts what is under it.
|
|
20
|
+
[SkLength] [SkDefault("40")] [SkRange(0.0, 400.0)]
|
|
21
|
+
float depth;
|
|
22
|
+
|
|
23
|
+
[SkColor] [SkOptional] [SkDefault("#bfe3ff")]
|
|
24
|
+
float4 light;
|
|
25
|
+
|
|
26
|
+
[SkPointer]
|
|
27
|
+
float2 at;
|
|
28
|
+
|
|
29
|
+
[SkPointerTimes] [SkAnimatedFor(4.0)]
|
|
30
|
+
float3 seen;
|
|
31
|
+
|
|
32
|
+
// The grid the waves travel on, in device pixels: coarser than a pixel so they move at a
|
|
33
|
+
// readable speed with the history stepping at most 75 times a second.
|
|
34
|
+
float spacing(EffectInput input)
|
|
35
|
+
{
|
|
36
|
+
return 2.0 * input.scale;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
float height(EffectInput input, float2 px)
|
|
40
|
+
{
|
|
41
|
+
return input.historyAtPx(px).r;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override float4 update(EffectInput input)
|
|
45
|
+
{
|
|
46
|
+
float s = spacing(input);
|
|
47
|
+
float around = height(input, input.px + float2(s, 0.0)) + height(input, input.px - float2(s, 0.0))
|
|
48
|
+
+ height(input, input.px + float2(0.0, s)) + height(input, input.px - float2(0.0, s));
|
|
49
|
+
float next = (around * 0.5 - input.history.g) * damping;
|
|
50
|
+
|
|
51
|
+
// The pointer pushes the water down while it moves inside the element.
|
|
52
|
+
float2 pointer = at * input.size;
|
|
53
|
+
float moving = 1.0 - saturate((input.time - seen.x) / 0.05);
|
|
54
|
+
bool inside = all(at >= 0.0) && all(at <= 1.0) && seen.y > seen.z;
|
|
55
|
+
float radius = 9.0 * input.scale;
|
|
56
|
+
float2 d = input.px - pointer;
|
|
57
|
+
next -= inside ? moving * 0.9 * exp(-dot(d, d) / (radius * radius)) : 0.0;
|
|
58
|
+
|
|
59
|
+
return float4(clamp(next, -4.0, 4.0), input.history.r, 0.0, 0.0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
float4 shade(EffectInput input)
|
|
63
|
+
{
|
|
64
|
+
float s = spacing(input);
|
|
65
|
+
float2 slope = float2(
|
|
66
|
+
height(input, input.px + float2(s, 0.0)) - height(input, input.px - float2(s, 0.0)),
|
|
67
|
+
height(input, input.px + float2(0.0, s)) - height(input, input.px - float2(0.0, s)));
|
|
68
|
+
|
|
69
|
+
// Kept inside the box: past its edge the element painted nothing to show.
|
|
70
|
+
float4 under = input.contentAtPx(clamp(input.px + slope * depth, 0.5, input.size - 0.5));
|
|
71
|
+
// Light from the top left catches the faces of the waves that tilt towards it.
|
|
72
|
+
float glint = pow(saturate(dot(slope, float2(-0.6, -0.8)) * 1.6), 2.0);
|
|
73
|
+
float3 rgb = under.rgb * (1.0 + input.history.r * 0.08) + light.rgb * glint * light.a * under.a;
|
|
74
|
+
return float4(rgb, under.a);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import sk;
|
|
2
|
+
|
|
3
|
+
// Rings of water spreading from up to eight points, refracting whatever is behind the element. The
|
|
4
|
+
// rings add up as heights, so where two meet they interfere: crests stack, crest and trough cancel.
|
|
5
|
+
//
|
|
6
|
+
// A ring is where it started and when, on the effect clock (`performance.now() / 1000` in JS), so
|
|
7
|
+
// the page sets it once per click and the effect works out the age itself. The window repaints for
|
|
8
|
+
// three seconds after the newest ring and then the effect is still.
|
|
9
|
+
[SkEffect("ripples")]
|
|
10
|
+
[SkDoc("interfering water rings that refract the backdrop")]
|
|
11
|
+
[SkBackdrop]
|
|
12
|
+
struct Ripples : IEffect
|
|
13
|
+
{
|
|
14
|
+
// Where each ring starts, 0..1 across the element.
|
|
15
|
+
float2 at0;
|
|
16
|
+
float2 at1;
|
|
17
|
+
float2 at2;
|
|
18
|
+
float2 at3;
|
|
19
|
+
float2 at4;
|
|
20
|
+
float2 at5;
|
|
21
|
+
float2 at6;
|
|
22
|
+
float2 at7;
|
|
23
|
+
|
|
24
|
+
// When each ring started; long ago is no ring.
|
|
25
|
+
[SkAnimatedFor(3.0)] [SkDefault("-1000")]
|
|
26
|
+
float4 born0;
|
|
27
|
+
[SkAnimatedFor(3.0)] [SkDefault("-1000")]
|
|
28
|
+
float4 born1;
|
|
29
|
+
|
|
30
|
+
// Height of one ring at `px` and its slope along the ring's radius.
|
|
31
|
+
float2 ring(float2 at, float born, EffectInput input, out float2 outward)
|
|
32
|
+
{
|
|
33
|
+
outward = float2(0.0, 0.0);
|
|
34
|
+
float age = input.time - born;
|
|
35
|
+
if (age < 0.0 || age > 3.0)
|
|
36
|
+
return float2(0.0, 0.0);
|
|
37
|
+
float2 d = input.px - at * input.size;
|
|
38
|
+
float r = length(d);
|
|
39
|
+
outward = d / max(r, 1.0);
|
|
40
|
+
|
|
41
|
+
float s = input.scale;
|
|
42
|
+
float wavelength = 34.0 * s;
|
|
43
|
+
float front = age * 300.0 * s;
|
|
44
|
+
float width = (40.0 + 90.0 * age) * s;
|
|
45
|
+
float x = (r - front) / width;
|
|
46
|
+
float packet = exp(-x * x) * pow(1.0 - age / 3.0, 2.0) / sqrt(1.0 + r / (160.0 * s));
|
|
47
|
+
float phase = (r - front) / wavelength * 6.28318530718;
|
|
48
|
+
return float2(sin(phase), cos(phase) * 6.28318530718 / wavelength) * packet;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
float4 shade(EffectInput input)
|
|
52
|
+
{
|
|
53
|
+
float2 ats[8] = { at0, at1, at2, at3, at4, at5, at6, at7 };
|
|
54
|
+
float borns[8] = { born0.x, born0.y, born0.z, born0.w, born1.x, born1.y, born1.z, born1.w };
|
|
55
|
+
float2 slope = float2(0.0, 0.0);
|
|
56
|
+
float height = 0.0;
|
|
57
|
+
for (int i = 0; i < 8; i++)
|
|
58
|
+
{
|
|
59
|
+
float2 outward;
|
|
60
|
+
float2 h = ring(ats[i], borns[i], input, outward);
|
|
61
|
+
height += h.x;
|
|
62
|
+
slope += outward * h.y;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The surface's slope bends the view; its tilt toward a light at the top left makes highlights.
|
|
66
|
+
float4 seen = input.backdropAtPx(input.px + slope * 70.0 * input.scale);
|
|
67
|
+
float glint = saturate(dot(slope, float2(-0.6, -0.8)) * 5.0 * input.scale);
|
|
68
|
+
float shade = 1.0 + height * 0.06;
|
|
69
|
+
return float4(seen.rgb * shade + glint * glint * 0.35 * seen.a, seen.a);
|
|
70
|
+
}
|
|
71
|
+
};
|