feat: Update nixpkgs, build ghostty from latest master, add ghostty shaders (smear, crt, bloom, blaze)

This commit is contained in:
Martin Larsson 2025-07-07 02:04:22 +02:00
parent 72891e5ac7
commit 926960760c
8 changed files with 430 additions and 51 deletions

206
flake.lock generated
View file

@ -6,11 +6,11 @@
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
}, },
"locked": { "locked": {
"lastModified": 1748659443, "lastModified": 1751622568,
"narHash": "sha256-dav2hzyCmXZ3n6lEZrfZBG51+g6PUhkzRl3d6Ypd9x0=", "narHash": "sha256-EE3NBsej517VRa1x+ylAghrvngftxf1KgfHlE9OYyXE=",
"owner": "tpwrules", "owner": "tpwrules",
"repo": "nixos-apple-silicon", "repo": "nixos-apple-silicon",
"rev": "3ddc251d2acce5019b0fa770e224d068610a34e4", "rev": "eba4b40c816e5aff8951ae231ac237e8aab8ec1d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -22,16 +22,16 @@
"brew-src": { "brew-src": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1748148946, "lastModified": 1749511373,
"narHash": "sha256-srnyYAqGD27NeBDaEU3hchJdkeOQ2vRe3kWurihFYT8=", "narHash": "sha256-7u1TdHQaUCzzgf/n8T3bQosuYXyNBEPU/3WQQqozE5o=",
"owner": "Homebrew", "owner": "Homebrew",
"repo": "brew", "repo": "brew",
"rev": "dc0f9d50fd170492a33fd7234d06de1b94df363c", "rev": "7b4ef99fed96966269ee35994407fa4c06097a4d",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "Homebrew", "owner": "Homebrew",
"ref": "4.5.3", "ref": "4.5.6",
"repo": "brew", "repo": "brew",
"type": "github" "type": "github"
} }
@ -54,11 +54,27 @@
"flake-compat_2": { "flake-compat_2": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1733328505, "lastModified": 1747046372,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
"owner": "edolstra", "owner": "edolstra",
"repo": "flake-compat", "repo": "flake-compat",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_3": {
"flake": false,
"locked": {
"lastModified": 1747046372,
"narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -106,6 +122,48 @@
"type": "github" "type": "github"
} }
}, },
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"ghostty": {
"inputs": {
"flake-compat": "flake-compat_2",
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
],
"zig": "zig",
"zon2nix": "zon2nix"
},
"locked": {
"lastModified": 1751840395,
"narHash": "sha256-g93h5xxNUDZha8ppkNbYKYOem9aPJc0IqdwpHNyKMzo=",
"owner": "ghostty-org",
"repo": "ghostty",
"rev": "78e861b50ea88aa7e9cfb5362364f40f47943088",
"type": "github"
},
"original": {
"owner": "ghostty-org",
"repo": "ghostty",
"type": "github"
}
},
"home-manager": { "home-manager": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@ -113,11 +171,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1748610552, "lastModified": 1751824240,
"narHash": "sha256-bCBPjZ3ukUbAaCIDzGmvA+ZcMNk4+YIWLM8cks0jiic=", "narHash": "sha256-aDDC0CHTlL7QDKWWhdbEgVPK6KwWt+ca0QkmHYZxMzI=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "482c306ef70785f53d9d90839b6b5643521ac031", "rev": "fd9e55f5fac45a26f6169310afca64d56b681935",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -145,11 +203,11 @@
"homebrew-cask": { "homebrew-cask": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1748612238, "lastModified": 1751821182,
"narHash": "sha256-0fBTKGn5g8D4dVVNdKXpcwQ4Ky7gR9eFn7nYiP2Ymak=", "narHash": "sha256-E5YKU/HJLstUz1T2aQhjVpGnh5xr7KbQ/FyKq1HPoVM=",
"owner": "homebrew", "owner": "homebrew",
"repo": "homebrew-cask", "repo": "homebrew-cask",
"rev": "47eb2481bdb650215bc2f8fc4aeca8256e750c95", "rev": "b96f8b9b46ba3f49b82767dc469b459a92a080fc",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -161,11 +219,11 @@
"homebrew-core": { "homebrew-core": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1748616857, "lastModified": 1751824569,
"narHash": "sha256-tSBdWkTTZj4S0HALEygciPe3Ag/+2BvJE4OzDq37Mx4=", "narHash": "sha256-FnecbUxCRzxfq6BfHJbY72/TIsoiJLqySTBT80OvdWU=",
"owner": "homebrew", "owner": "homebrew",
"repo": "homebrew-core", "repo": "homebrew-core",
"rev": "4ddb15d1976ce3df71bf257ff96a2a0e79a01bec", "rev": "1d376783e883c6d15239fec91faba7ffcd289794",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -192,7 +250,7 @@
}, },
"neovim": { "neovim": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
@ -216,11 +274,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1748352827, "lastModified": 1751313918,
"narHash": "sha256-sNUUP6qxGkK9hXgJ+p362dtWLgnIWwOCmiq72LAWtYo=", "narHash": "sha256-HsJM3XLa43WpG+665aGEh8iS8AfEwOIQWk3Mke3e7nk=",
"owner": "LnL7", "owner": "LnL7",
"repo": "nix-darwin", "repo": "nix-darwin",
"rev": "44a7d0e687a87b73facfe94fba78d323a6686a90", "rev": "e04a388232d9a6ba56967ce5b53a8a6f713cdfcf",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -235,11 +293,11 @@
"brew-src": "brew-src" "brew-src": "brew-src"
}, },
"locked": { "locked": {
"lastModified": 1748379893, "lastModified": 1749952250,
"narHash": "sha256-7zvNSdEA4KhKA3vosAU3QdzGgSBKxTR2iUEredA8tLc=", "narHash": "sha256-V2ix0knpdJXirQ+4pjbnggjdSALTsFWGIP/NDpaQkdU=",
"owner": "zhaofengli-wip", "owner": "zhaofengli-wip",
"repo": "nix-homebrew", "repo": "nix-homebrew",
"rev": "77517445732b9ae0b413e4580b1c8e88f804da1c", "rev": "37126f06f4890f019af3d7606ce5d30a457afcd0",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -250,15 +308,15 @@
}, },
"nixos-wsl": { "nixos-wsl": {
"inputs": { "inputs": {
"flake-compat": "flake-compat_2", "flake-compat": "flake-compat_3",
"nixpkgs": "nixpkgs_3" "nixpkgs": "nixpkgs_3"
}, },
"locked": { "locked": {
"lastModified": 1746453552, "lastModified": 1749574455,
"narHash": "sha256-r66UGha+7KVHkI7ksrcMjnw/mm9Sg4l5bQlylxHwdGU=", "narHash": "sha256-fm2/8KPOYvvIAnNVtjDlTt/My00lIbZQ+LMrfQIWVzs=",
"owner": "nix-community", "owner": "nix-community",
"repo": "NixOS-WSL", "repo": "NixOS-WSL",
"rev": "be618645aa0adf461f778500172b6896d5ab2d01", "rev": "917af390377c573932d84b5e31dd9f2c1b5c0f09",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -302,11 +360,11 @@
}, },
"nixpkgs_3": { "nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1742937945, "lastModified": 1749173751,
"narHash": "sha256-lWc+79eZRyvHp/SqMhHTMzZVhpxkRvthsP1Qx6UCq0E=", "narHash": "sha256-ENY3y3v6S9ZmLDDLI3LUT8MXmfXg/fSt2eA4GCnMVCE=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d02d88f8de5b882ccdde0465d8fa2db3aa1169f7", "rev": "ed29f002b6d6e5e7e32590deb065c34a31dc3e91",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -318,11 +376,11 @@
}, },
"nixpkgs_4": { "nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1748460289, "lastModified": 1751637120,
"narHash": "sha256-7doLyJBzCllvqX4gszYtmZUToxKvMUrg45EUWaUYmBg=", "narHash": "sha256-xVNy/XopSfIG9c46nRmPaKfH1Gn/56vQ8++xWA8itO4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "96ec055edbe5ee227f28cdbc3f1ddf1df5965102", "rev": "5c724ed1388e53cc231ed98330a60eb2f7be4be3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -337,15 +395,14 @@
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
], ]
"treefmt-nix": "treefmt-nix"
}, },
"locked": { "locked": {
"lastModified": 1748613093, "lastModified": 1751824066,
"narHash": "sha256-ymuPofmMcKLEVyB/PVkh14tGQTXtvzu5WeptVIUWSUo=", "narHash": "sha256-bh/3BURJLJHUT0gpsR3NDkLVSme/dfoqv7EdXnxlAJo=",
"owner": "nix-community", "owner": "nix-community",
"repo": "NUR", "repo": "NUR",
"rev": "658eca19992a19259cee8861ae8886375b625490", "rev": "c6a24385d1e517bb1d901d63148828c8cfdff3dd",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -357,6 +414,7 @@
"root": { "root": {
"inputs": { "inputs": {
"apple-silicon-support": "apple-silicon-support", "apple-silicon-support": "apple-silicon-support",
"ghostty": "ghostty",
"home-manager": "home-manager", "home-manager": "home-manager",
"homebrew-bundle": "homebrew-bundle", "homebrew-bundle": "homebrew-bundle",
"homebrew-cask": "homebrew-cask", "homebrew-cask": "homebrew-cask",
@ -385,24 +443,72 @@
"type": "github" "type": "github"
} }
}, },
"treefmt-nix": { "systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"zig": {
"inputs": { "inputs": {
"flake-compat": [
"ghostty"
],
"flake-utils": [
"ghostty",
"flake-utils"
],
"nixpkgs": [ "nixpkgs": [
"nur", "ghostty",
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1733222881, "lastModified": 1748261582,
"narHash": "sha256-JIPcz1PrpXUCbaccEnrcUS8jjEb/1vJbZz5KkobyFdM=", "narHash": "sha256-3i0IL3s18hdDlbsf0/E+5kyPRkZwGPbSFngq5eToiAA=",
"owner": "numtide", "owner": "mitchellh",
"repo": "treefmt-nix", "repo": "zig-overlay",
"rev": "49717b5af6f80172275d47a418c9719a31a78b53", "rev": "aafb1b093fb838f7a02613b719e85ec912914221",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "mitchellh",
"repo": "treefmt-nix", "repo": "zig-overlay",
"type": "github"
}
},
"zon2nix": {
"inputs": {
"flake-utils": [
"ghostty",
"flake-utils"
],
"nixpkgs": [
"ghostty",
"nixpkgs"
]
},
"locked": {
"lastModified": 1742104771,
"narHash": "sha256-LhidlyEA9MP8jGe1rEnyjGFCzLLgCdDpYeWggibayr0=",
"owner": "jcollie",
"repo": "zon2nix",
"rev": "56c159be489cc6c0e73c3930bd908ddc6fe89613",
"type": "github"
},
"original": {
"owner": "jcollie",
"ref": "56c159be489cc6c0e73c3930bd908ddc6fe89613",
"repo": "zon2nix",
"type": "github" "type": "github"
} }
} }

View file

@ -3,6 +3,12 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
ghostty = {
url = "github:ghostty-org/ghostty";
inputs.nixpkgs.follows = "nixpkgs";
};
nur = { nur = {
url = "github:nix-community/NUR"; url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -46,6 +52,7 @@
{ {
self, self,
nixpkgs, nixpkgs,
ghostty,
nur, nur,
apple-silicon-support, apple-silicon-support,
home-manager, home-manager,
@ -125,6 +132,7 @@
extraSpecialArgs = { extraSpecialArgs = {
neovim-flake = neovim; neovim-flake = neovim;
nur = nur.legacyPackages.${system}; nur = nur.legacyPackages.${system};
ghosttyPkg = ghostty.packages.${system}.ghostty;
}; };
}; };
in in

View file

@ -1,5 +1,10 @@
gtk-tabs-location = hidden gtk-tabs-location = hidden
custom-shader = shaders/bettercrt.glsl
custom-shader = shaders/bloom.glsl
custom-shader = shaders/cursor_blaze_no_trail.glsl
custom-shader = shaders/cursor_smear.glsl
font-size = 16 font-size = 16
# Perfect cell height my external monitor when at the desk # Perfect cell height my external monitor when at the desk
adjust-cell-height = 42% adjust-cell-height = 42%

View file

@ -0,0 +1,33 @@
// Original shader collected from: https://www.shadertoy.com/view/WsVSzV
// Licensed under Shadertoy's default since the original creator didn't provide any license. (CC BY NC SA 3.0)
// Slight modifications were made to give a green-ish effect.
// This shader was modified by April Hall (arithefirst)
// Sourced from https://github.com/m-ahdal/ghostty-shaders/blob/main/retro-terminal.glsl
// Changes made:
// - Removed tint
// - Made the boundaries match ghostty's background color
float warp = 0.115; // simulate curvature of CRT monitor
float scan = 0.2; // simulate darkness between scanlines
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
// squared distance from center
vec2 uv = fragCoord / iResolution.xy;
vec2 dc = abs(0.5 - uv);
dc *= dc;
// warp the fragment coordinates
uv.x -= 0.5; uv.x *= 1.0 + (dc.y * (0.3 * warp)); uv.x += 0.5;
uv.y -= 0.5; uv.y *= 1.0 + (dc.x * (0.4 * warp)); uv.y += 0.5;
// determine if we are drawing in a scanline
float apply = abs(sin(fragCoord.y) * 0.25 * scan);
// sample the texture
vec3 color = texture(iChannel0, uv).rgb;
// mix the sampled color with the scanline intensity
fragColor = vec4(mix(color, vec3(0.0), apply), 1.0);
}

View file

@ -0,0 +1,52 @@
// source: https://gist.github.com/qwerasd205/c3da6c610c8ffe17d6d2d3cc7068f17f
// credits: https://github.com/qwerasd205
// Golden spiral samples, [x, y, weight] weight is inverse of distance.
const vec3[24] samples = {
vec3(0.1693761725038636, 0.9855514761735895, 1),
vec3(-1.333070830962943, 0.4721463328627773, 0.7071067811865475),
vec3(-0.8464394909806497, -1.51113870578065, 0.5773502691896258),
vec3(1.554155680728463, -1.2588090085709776, 0.5),
vec3(1.681364377589461, 1.4741145918052656, 0.4472135954999579),
vec3(-1.2795157692199817, 2.088741103228784, 0.4082482904638631),
vec3(-2.4575847530631187, -0.9799373355024756, 0.3779644730092272),
vec3(0.5874641440200847, -2.7667464429345077, 0.35355339059327373),
vec3(2.997715703369726, 0.11704939884745152, 0.3333333333333333),
vec3(0.41360842451688395, 3.1351121305574803, 0.31622776601683794),
vec3(-3.167149933769243, 0.9844599011770256, 0.30151134457776363),
vec3(-1.5736713846521535, -3.0860263079123245, 0.2886751345948129),
vec3(2.888202648340422, -2.1583061557896213, 0.2773500981126146),
vec3(2.7150778983300325, 2.5745586041105715, 0.2672612419124244),
vec3(-2.1504069972377464, 3.2211410627650165, 0.2581988897471611),
vec3(-3.6548858794907493, -1.6253643308191343, 0.25),
vec3(1.0130775986052671, -3.9967078676335834, 0.24253562503633297),
vec3(4.229723673607257, 0.33081361055181563, 0.23570226039551587),
vec3(0.40107790291173834, 4.340407413572593, 0.22941573387056174),
vec3(-4.319124570236028, 1.159811599693438, 0.22360679774997896),
vec3(-1.9209044802827355, -4.160543952132907, 0.2182178902359924),
vec3(3.8639122286635708, -2.6589814382925123, 0.21320071635561041),
vec3(3.3486228404946234, 3.4331800232609, 0.20851441405707477),
vec3(-2.8769733643574344, 3.9652268864187157, 0.20412414523193154)
};
float lum(vec4 c) {
return 0.299 * c.r + 0.587 * c.g + 0.114 * c.b;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 color = texture(iChannel0, uv);
vec2 step = vec2(1.414) / iResolution.xy;
for (int i = 0; i < 24; i++) {
vec3 s = samples[i];
vec4 c = texture(iChannel0, uv + s.xy * step);
float l = lum(c);
if (l > 0.2) {
color += l * s.z * c * 0.0075;
}
}
fragColor = color;
}

View file

@ -0,0 +1,54 @@
float getSdfRectangle(in vec2 p, in vec2 xy, in vec2 b)
{
vec2 d = abs(p - xy) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
}
vec2 normalize(vec2 value, float isPosition) {
return (value * 2.0 - (iResolution.xy * isPosition)) / iResolution.y;
}
float antialising(float distance) {
return 1. - smoothstep(0., normalize(vec2(2., 2.), 0.).x, distance);
}
vec2 getRectangleCenter(vec4 rectangle) {
return vec2(rectangle.x + (rectangle.z / 2.), rectangle.y - (rectangle.w / 2.));
}
float ease(float x) {
return pow(1.0 - x, 3.0);
}
const vec4 TRAIL_COLOR = vec4(0.7, 0.495, 0.111, 0.9);
const vec4 TRAIL_COLOR_ACCENT = vec4(0.8, 0., 0., 1.0);
const float DURATION = 0.1; //IN SECONDS
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
#if !defined(WEB)
fragColor = texture(iChannel0, fragCoord.xy / iResolution.xy);
#endif
// Normalization for fragCoord to a space of -1 to 1;
vec2 vu = normalize(fragCoord, 1.);
vec2 offsetFactor = vec2(-.5, 0.5);
// Normalization for cursor position and size;
// cursor xy has the postion in a space of -1 to 1;
// zw has the width and theight
vec4 currentCursor = vec4(normalize(iCurrentCursor.xy, 1.), normalize(iCurrentCursor.zw, 0.));
vec4 previousCursor = vec4(normalize(iPreviousCursor.xy, 1.), normalize(iPreviousCursor.zw, 0.));
vec2 centerCC = getRectangleCenter(currentCursor);
vec2 centerCP = getRectangleCenter(previousCursor);
float sdfCurrentCursor = getSdfRectangle(vu, currentCursor.xy - (currentCursor.zw * offsetFactor), currentCursor.zw * 0.5);
float progress = clamp((iTime - iTimeCursorChange) / DURATION, 0.0, 1.0);
float easedProgress = ease(progress);
float lineLength = distance(centerCC, centerCP);
//cursorblaze
vec4 trail = mix(TRAIL_COLOR_ACCENT, fragColor, 1. - smoothstep(0., sdfCurrentCursor + .002, 0.004));
trail = mix(TRAIL_COLOR, trail, 1. - smoothstep(0., sdfCurrentCursor + .002, 0.004));
fragColor = mix(trail, fragColor, 1. - smoothstep(0., sdfCurrentCursor, easedProgress * lineLength));
}

View file

@ -0,0 +1,120 @@
float getSdfRectangle(in vec2 p, in vec2 xy, in vec2 b)
{
vec2 d = abs(p - xy) - b;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
}
// Based on Inigo Quilez's 2D distance functions article: https://iquilezles.org/articles/distfunctions2d/
// Potencially optimized by eliminating conditionals and loops to enhance performance and reduce branching
float seg(in vec2 p, in vec2 a, in vec2 b, inout float s, float d) {
vec2 e = b - a;
vec2 w = p - a;
vec2 proj = a + e * clamp(dot(w, e) / dot(e, e), 0.0, 1.0);
float segd = dot(p - proj, p - proj);
d = min(d, segd);
float c0 = step(0.0, p.y - a.y);
float c1 = 1.0 - step(0.0, p.y - b.y);
float c2 = 1.0 - step(0.0, e.x * w.y - e.y * w.x);
float allCond = c0 * c1 * c2;
float noneCond = (1.0 - c0) * (1.0 - c1) * (1.0 - c2);
float flip = mix(1.0, -1.0, step(0.5, allCond + noneCond));
s *= flip;
return d;
}
float getSdfParallelogram(in vec2 p, in vec2 v0, in vec2 v1, in vec2 v2, in vec2 v3) {
float s = 1.0;
float d = dot(p - v0, p - v0);
d = seg(p, v0, v3, s, d);
d = seg(p, v1, v0, s, d);
d = seg(p, v2, v1, s, d);
d = seg(p, v3, v2, s, d);
return s * sqrt(d);
}
vec2 normalize(vec2 value, float isPosition) {
return (value * 2.0 - (iResolution.xy * isPosition)) / iResolution.y;
}
float antialising(float distance) {
return 1. - smoothstep(0., normalize(vec2(2., 2.), 0.).x, distance);
}
float determineStartVertexFactor(vec2 a, vec2 b) {
// Conditions using step
float condition1 = step(b.x, a.x) * step(a.y, b.y); // a.x < b.x && a.y > b.y
float condition2 = step(a.x, b.x) * step(b.y, a.y); // a.x > b.x && a.y < b.y
// If neither condition is met, return 1 (else case)
return 1.0 - max(condition1, condition2);
}
vec2 getRectangleCenter(vec4 rectangle) {
return vec2(rectangle.x + (rectangle.z / 2.), rectangle.y - (rectangle.w / 2.));
}
float ease(float x) {
return pow(1.0 - x, 3.0);
}
vec4 saturate(vec4 color, float factor) {
float gray = dot(color, vec4(0.299, 0.587, 0.114, 0.)); // luminance
return mix(vec4(gray), color, factor);
}
vec4 TRAIL_COLOR = vec4(0.361, 0.812, 0.902, 1.0);
const float OPACITY = 0.6;
const float DURATION = 0.1; //IN SECONDS
const float MAX_TRAIL_LENGTH = 0.4;
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
#if !defined(WEB)
fragColor = texture(iChannel0, fragCoord.xy / iResolution.xy);
#endif
// Normalization for fragCoord to a space of -1 to 1;
vec2 vu = normalize(fragCoord, 1.);
vec2 offsetFactor = vec2(-.5, 0.5);
// Normalization for cursor position and size;
// cursor xy has the postion in a space of -1 to 1;
// zw has the width and height
vec4 currentCursor = vec4(normalize(iCurrentCursor.xy, 1.), normalize(iCurrentCursor.zw, 0.));
vec4 previousCursor = vec4(normalize(iPreviousCursor.xy, 1.), normalize(iPreviousCursor.zw, 0.));
// When drawing a parellelogram between cursors for the trail i need to determine where to start at the top-left or top-right vertex of the cursor
float vertexFactor = determineStartVertexFactor(currentCursor.xy, previousCursor.xy);
float invertedVertexFactor = 1.0 - vertexFactor;
// Set every vertex of my parellogram
vec2 v0 = vec2(currentCursor.x + currentCursor.z * vertexFactor, currentCursor.y - currentCursor.w);
vec2 v1 = vec2(currentCursor.x + currentCursor.z * invertedVertexFactor, currentCursor.y);
vec2 v2 = vec2(previousCursor.x + currentCursor.z * invertedVertexFactor, previousCursor.y);
vec2 v3 = vec2(previousCursor.x + currentCursor.z * vertexFactor, previousCursor.y - previousCursor.w);
float sdfCurrentCursor = getSdfRectangle(vu, currentCursor.xy - (currentCursor.zw * offsetFactor), currentCursor.zw * 0.5);
float sdfTrail = getSdfParallelogram(vu, v0, v1, v2, v3);
float progress = clamp((iTime - iTimeCursorChange) / DURATION, 0.0, 1.0);
float easedProgress = ease(progress);
// Distance between cursors determine the total length of the parallelogram;
vec2 centerCC = getRectangleCenter(currentCursor);
vec2 centerCP = getRectangleCenter(previousCursor);
float lineLength = distance(centerCC, centerCP);
float cappedlinelength = min(lineLength, MAX_TRAIL_LENGTH);
vec4 newColor = vec4(fragColor);
vec4 trail = TRAIL_COLOR;
trail = saturate(trail, 2.5);
// Draw trail
newColor = mix(newColor, trail, antialising(sdfTrail));
// Draw current cursor
newColor = mix(newColor, trail, antialising(sdfCurrentCursor));
newColor = mix(newColor, fragColor, step(sdfCurrentCursor, 0.));
// newColor = mix(fragColor, newColor, OPACITY);
fragColor = mix(fragColor, newColor, step(sdfCurrentCursor, easedProgress * cappedlinelength));
}

View file

@ -1,5 +1,6 @@
{ {
pkgs, pkgs,
ghosttyPkg,
config, config,
... ...
}: }:
@ -40,7 +41,7 @@ in
llvmPackages_20.clang llvmPackages_20.clang
llvmPackages_20.clang-tools llvmPackages_20.clang-tools
gimp3 gimp3
ghostty ghosttyPkg
mullvad mullvad
thunderbird thunderbird
wofi wofi