add basic first time installation
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
theme = "LiquidCarbonTransparent"
|
||||
|
||||
background-blur = 255
|
||||
background-opacity = 0.98
|
||||
|
||||
title = " "
|
||||
window-height = 40
|
||||
window-width = 140
|
||||
window-decoration = none
|
||||
|
||||
quit-after-last-window-closed = true
|
||||
quit-after-last-window-closed-delay = 1s
|
||||
|
||||
custom-shader-animation = always
|
||||
custom-shader = ~/.config/ghostty/shaders/cursor_tail.glsl
|
||||
custom-shader = ~/.config/ghostty/shaders/in_game_crt_cursor.glsl
|
||||
|
||||
# keybind = cmd+shift+right=new_split:right
|
||||
# keybind = cmd+shift+left=new_split:left
|
||||
# keybind = cmd+shift+up=new_split:up
|
||||
# keybind = cmd+shift+down=new_split:down
|
||||
@@ -0,0 +1,236 @@
|
||||
// Taken from https://github.com/sahaj-b/ghostty-cursor-shaders
|
||||
|
||||
// -- CONFIGURATION --
|
||||
vec4 TRAIL_COLOR = iCurrentCursorColor; // can change to eg: vec4(0.2, 0.6, 1.0, 0.5);
|
||||
const float DURATION = 0.09; // in seconds
|
||||
const float MAX_TRAIL_LENGTH = 0.2;
|
||||
const float THRESHOLD_MIN_DISTANCE = 1.5; // min distance to show trail (units of cursor width)
|
||||
const float BLUR = 2.0; // blur size in pixels (for antialiasing)
|
||||
|
||||
// --- CONSTANTS for easing functions ---
|
||||
const float PI = 3.14159265359;
|
||||
const float C1_BACK = 1.70158;
|
||||
const float C2_BACK = C1_BACK * 1.525;
|
||||
const float C3_BACK = C1_BACK + 1.0;
|
||||
const float C4_ELASTIC = (2.0 * PI) / 3.0;
|
||||
const float C5_ELASTIC = (2.0 * PI) / 4.5;
|
||||
const float SPRING_STIFFNESS = 9.0;
|
||||
const float SPRING_DAMPING = 0.9;
|
||||
|
||||
// --- EASING FUNCTIONS ---
|
||||
|
||||
// // Linear
|
||||
// float ease(float x) {
|
||||
// return x;
|
||||
// }
|
||||
|
||||
// // EaseOutQuad
|
||||
// float ease(float x) {
|
||||
// return 1.0 - (1.0 - x) * (1.0 - x);
|
||||
// }
|
||||
|
||||
// // EaseOutCubic
|
||||
// float ease(float x) {
|
||||
// return 1.0 - pow(1.0 - x, 3.0);
|
||||
// }
|
||||
|
||||
|
||||
// // EaseOutQuart
|
||||
// float ease(float x) {
|
||||
// return 1.0 - pow(1.0 - x, 4.0);
|
||||
// }
|
||||
|
||||
// // EaseOutQuint
|
||||
// float ease(float x) {
|
||||
// return 1.0 - pow(1.0 - x, 5.0);
|
||||
// }
|
||||
|
||||
// // EaseOutSine
|
||||
// float ease(float x) {
|
||||
// return sin((x * PI) / 2.0);
|
||||
// }
|
||||
|
||||
// // EaseOutExpo
|
||||
// float ease(float x) {
|
||||
// return x == 1.0 ? 1.0 : 1.0 - pow(2.0, -10.0 * x);
|
||||
// }
|
||||
|
||||
// EaseOutCirc
|
||||
float ease(float x) {
|
||||
return sqrt(1.0 - pow(x - 1.0, 2.0));
|
||||
}
|
||||
|
||||
// // EaseOutBack
|
||||
// float ease(float x) {
|
||||
// return 1.0 + C3_BACK * pow(x - 1.0, 3.0) + C1_BACK * pow(x - 1.0, 2.0);
|
||||
// }
|
||||
|
||||
// // EaseOutElastic
|
||||
// float ease(float x) {
|
||||
// return x == 0.0 ? 0.0
|
||||
// : x == 1.0 ? 1.0
|
||||
// : pow(2.0, -10.0 * x) * sin((x * 10.0 - 0.75) * C4_ELASTIC) + 1.0;
|
||||
// }
|
||||
|
||||
// Parametric Spring
|
||||
// float ease(float x) {
|
||||
// x = clamp(x, 0.0, 1.0);
|
||||
// float decay = exp(-SPRING_DAMPING * SPRING_STIFFNESS * x);
|
||||
// float freq = sqrt(SPRING_STIFFNESS * (1.0 - SPRING_DAMPING * SPRING_DAMPING));
|
||||
// float osc = cos(freq * 6.283185 * x) + (SPRING_DAMPING * sqrt(SPRING_STIFFNESS) / freq) * sin(freq * 6.283185 * x);
|
||||
// return 1.0 - decay * osc;
|
||||
// }
|
||||
|
||||
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(BLUR, BLUR), 0.).x, distance);
|
||||
}
|
||||
|
||||
float determineIfTopRightIsLeading(vec2 a, vec2 b) {
|
||||
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.));
|
||||
}
|
||||
|
||||
|
||||
void mainImage(out vec4 fragColor, in vec2 fragCoord){
|
||||
#if !defined(WEB)
|
||||
fragColor = texture(iChannel0, fragCoord.xy / iResolution.xy);
|
||||
#endif
|
||||
|
||||
// normalization & setup(-1, 1 coords)
|
||||
vec2 vu = normalize(fragCoord, 1.);
|
||||
vec2 offsetFactor = vec2(-.5, 0.5);
|
||||
|
||||
vec4 currentCursor = vec4(normalize(iCurrentCursor.xy, 1.), normalize(iCurrentCursor.zw, 0.));
|
||||
vec4 previousCursor = vec4(normalize(iPreviousCursor.xy, 1.), normalize(iPreviousCursor.zw, 0.));
|
||||
|
||||
vec2 centerCC = currentCursor.xy - (currentCursor.zw * offsetFactor);
|
||||
vec2 centerCP = previousCursor.xy - (previousCursor.zw * offsetFactor);
|
||||
|
||||
vec2 delta = centerCP - centerCC;
|
||||
float lineLength = length(delta);
|
||||
|
||||
float sdfCurrentCursor = getSdfRectangle(vu, centerCC, currentCursor.zw * 0.5);
|
||||
|
||||
vec4 newColor = vec4(fragColor);
|
||||
|
||||
float minDist = currentCursor.w * THRESHOLD_MIN_DISTANCE;
|
||||
float progress = clamp((iTime - iTimeCursorChange) / DURATION, 0.0, 1.0);
|
||||
if (lineLength > minDist) {
|
||||
// ANIMATION logic
|
||||
|
||||
float head_eased = 0.0;
|
||||
float tail_eased = 0.0;
|
||||
|
||||
float tail_delay_factor = MAX_TRAIL_LENGTH / lineLength;
|
||||
|
||||
float isLongMove = step(MAX_TRAIL_LENGTH, lineLength);
|
||||
|
||||
float head_eased_short = ease(progress);
|
||||
float tail_eased_short = ease(smoothstep(tail_delay_factor, 1.0, progress));
|
||||
float head_eased_long = 1.0;
|
||||
float tail_eased_long = ease(progress);
|
||||
|
||||
head_eased = mix(head_eased_long, head_eased_short, isLongMove);
|
||||
tail_eased = mix(tail_eased_long, tail_eased_short, isLongMove);
|
||||
|
||||
// detect straight moves
|
||||
vec2 delta_abs = abs(centerCC - centerCP);
|
||||
float threshold = 0.001;
|
||||
float isHorizontal = step(delta_abs.y, threshold);
|
||||
float isVertical = step(delta_abs.x, threshold);
|
||||
float isStraightMove = max(isHorizontal, isVertical);
|
||||
|
||||
// -- Making the parallelogram sdf (diagonal move) --
|
||||
|
||||
// animate the TOP-LEFT corners
|
||||
vec2 head_pos_tl = mix(previousCursor.xy, currentCursor.xy, head_eased);
|
||||
vec2 tail_pos_tl = mix(previousCursor.xy, currentCursor.xy, tail_eased);
|
||||
|
||||
float isTopRightLeading = determineIfTopRightIsLeading(currentCursor.xy, previousCursor.xy);
|
||||
float isBottomLeftLeading = 1.0 - isTopRightLeading;
|
||||
|
||||
// v0, v1 : "front" of the trail (head)
|
||||
vec2 v0 = vec2(head_pos_tl.x + currentCursor.z * isTopRightLeading, head_pos_tl.y - currentCursor.w);
|
||||
vec2 v1 = vec2(head_pos_tl.x + currentCursor.z * isBottomLeftLeading, head_pos_tl.y);
|
||||
|
||||
// v2, v3: "back" of the trail (tail)
|
||||
vec2 v2 = vec2(tail_pos_tl.x + currentCursor.z * isBottomLeftLeading, tail_pos_tl.y);
|
||||
vec2 v3 = vec2(tail_pos_tl.x + currentCursor.z * isTopRightLeading, tail_pos_tl.y - previousCursor.w);
|
||||
|
||||
float sdfTrail_diag = getSdfParallelogram(vu, v0, v1, v2, v3);
|
||||
|
||||
// -- Making the rectangle sdf (straight move) --
|
||||
|
||||
vec2 head_center = mix(centerCP, centerCC, head_eased);
|
||||
vec2 tail_center = mix(centerCP, centerCC, tail_eased);
|
||||
|
||||
vec2 min_center = min(head_center, tail_center);
|
||||
vec2 max_center = max(head_center, tail_center);
|
||||
|
||||
vec2 box_size = (max_center - min_center) + currentCursor.zw;
|
||||
vec2 box_center = (min_center + max_center) * 0.5;
|
||||
|
||||
float sdfTrail_rect = getSdfRectangle(vu, box_center, box_size * 0.5);
|
||||
|
||||
// -- FINAL SELECTING AND DRAWING --
|
||||
float sdfTrail = mix(sdfTrail_diag, sdfTrail_rect, isStraightMove);
|
||||
|
||||
vec4 trail = TRAIL_COLOR;
|
||||
float trailAlpha = antialising(sdfTrail);
|
||||
newColor = mix(newColor, trail, trailAlpha);
|
||||
|
||||
// punch hole
|
||||
newColor = mix(newColor, fragColor, step(sdfCurrentCursor, 0.));
|
||||
}
|
||||
|
||||
fragColor = newColor;
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
// In-game CRT shader
|
||||
// Author: sarphiv
|
||||
// License: CC BY-NC-SA 4.0
|
||||
// Description:
|
||||
// Cursor shader for Ghostty designed to be applied before the accompanying in-game CRT shader.
|
||||
// Highlights the cursor whenever it changes (line/block) or moves, and draws a glowing trail for large movements.
|
||||
// The glow is colored based on cursor colors with an override for white-grey colors.
|
||||
|
||||
// Taken from https://github.com/0xhckr/ghostty-shaders
|
||||
|
||||
// Settings:
|
||||
// Minimum distance in UV coordinates before drawing trail
|
||||
// [0, sqrt(2)]
|
||||
#define TRAIL_MIN_DISTANCE 0.0095
|
||||
// Use override colors when color channel brightness standard deviation is below threshold
|
||||
// [0, sqrt(2)/3]
|
||||
#define GLOW_COLOR_OVERRIDE_THRESHOLD 0.1
|
||||
// Override color for current cursor
|
||||
// [0, 1]^3
|
||||
#define GLOW_COLOR_OVERRIDE_CURRENT 0.2, 0.4, 1.0
|
||||
// Override color for previous cursor
|
||||
// [0, 1]^3
|
||||
#define GLOW_COLOR_OVERRIDE_PREVIOUS 0.4, 0.1, 1.0
|
||||
// Brightness offset for glow effect
|
||||
// [0, 1]
|
||||
#define GLOW_COLOR_OFFSET_BRIGHTNESS 0.5
|
||||
// Time slowdown factor for animations
|
||||
// x \in R : x > 0
|
||||
#define TIME_DURATION_FACTOR 1.0
|
||||
|
||||
|
||||
|
||||
// Constants:
|
||||
#define EPS 1e-9
|
||||
|
||||
|
||||
|
||||
// Functions:
|
||||
float min_(float a, float b, float c) { return min(a, min(b, c)); }
|
||||
float max_(float a, float b, float c) { return max(a, max(b, c)); }
|
||||
|
||||
float sdRectangle(vec2 p, vec2 topLeft, vec2 size) {
|
||||
vec2 center = topLeft + vec2(size.x, -size.y) * 0.5;
|
||||
vec2 d = abs(p - center) - size * 0.5;
|
||||
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
|
||||
}
|
||||
|
||||
float sdSeg(vec2 p, vec2 a)
|
||||
{
|
||||
vec2 c = a * clamp(dot(p, a) / (dot(a, a) + EPS), 0., 1.) - p;
|
||||
return sqrt(dot(c, c));
|
||||
}
|
||||
|
||||
float sdTriangle(vec2 p, vec2 a, vec2 b, vec2 c)
|
||||
{
|
||||
a -= p; b -= p; c -= p;
|
||||
|
||||
vec3 t = cross(vec3(a.x, b.x, c.x), vec3(a.y, b.y, c.y));
|
||||
vec2 m = vec2(min_(t.x, t.y, t.z), max_(t.x, t.y, t.z));
|
||||
float s = -1. + 2. * step(m.x, 0.) * step(0., m.y);
|
||||
|
||||
return s * min_(
|
||||
sdSeg(a, a - b),
|
||||
sdSeg(b, b - c),
|
||||
sdSeg(c, c - a)
|
||||
);
|
||||
}
|
||||
|
||||
float sdTrail(vec2 p, vec2 currPos, vec2 currSize, vec2 prevPos, vec2 prevSize, float t) {
|
||||
// Initialize points
|
||||
vec2 currWidth = vec2(currSize.x, 0.0), currHeight = vec2(0.0, -currSize.y);
|
||||
vec2 currTopLeft = currPos;
|
||||
vec2 currTopRight = currTopLeft + currWidth;
|
||||
vec2 currBottomLeft = currTopLeft + currHeight;
|
||||
vec2 currBottomRight = currBottomLeft + currWidth;
|
||||
vec2 currCenter = (currTopLeft + currBottomRight) * 0.5;
|
||||
|
||||
vec2 prevWidth = vec2(prevSize.x, 0.0), prevHeight = vec2(0.0, -prevSize.y);
|
||||
vec2 prevTopLeft = prevPos;
|
||||
vec2 prevTopRight = prevTopLeft + prevWidth;
|
||||
vec2 prevBottomLeft = prevTopLeft + prevHeight;
|
||||
vec2 prevBottomRight = prevBottomLeft + prevWidth;
|
||||
vec2 prevCenter = (prevTopLeft + prevBottomRight) * 0.5;
|
||||
|
||||
// Check whether to only draw cursor
|
||||
bool nearbyPrev = distance(currCenter, prevCenter) < TRAIL_MIN_DISTANCE;
|
||||
bool insidePrev = (
|
||||
currCenter.x >= prevTopLeft.x && currCenter.x <= prevTopRight.x &&
|
||||
currCenter.y <= prevTopLeft.y && currCenter.y >= prevBottomLeft.y
|
||||
);
|
||||
|
||||
float rectDist = max(sdRectangle(p, currTopLeft, currSize), 0.0);
|
||||
|
||||
if (nearbyPrev || insidePrev)
|
||||
return rectDist;
|
||||
|
||||
// Draw trail and cursor
|
||||
vec2[4] corners = { currTopLeft, currTopRight, currBottomRight, currBottomLeft };
|
||||
vec2 triB = corners[0], triC = corners[0], dir = normalize(currCenter - prevCenter);
|
||||
float minRel = 1/EPS, maxRel = -minRel;
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
vec2 delta = corners[i] - prevCenter;
|
||||
float rel = atan(dir.x * delta.y - dir.y * delta.x, dot(dir, delta));
|
||||
|
||||
if (rel < minRel)
|
||||
minRel = rel, triB = corners[i];
|
||||
if (rel > maxRel)
|
||||
maxRel = rel, triC = corners[i];
|
||||
}
|
||||
|
||||
float triDist = max(sdTriangle(p, prevCenter, triB, triC), 0.0);
|
||||
|
||||
|
||||
return min(rectDist, mix(triDist, rectDist, t));
|
||||
}
|
||||
|
||||
vec4 colorOverride(vec4 baseColor, vec4 overrideColor) {
|
||||
if (sqrt(pow(distance(baseColor.rgb, vec3(dot(baseColor.rgb, vec3(1.0)) / 3.0)), 2) / 3.0) < GLOW_COLOR_OVERRIDE_THRESHOLD)
|
||||
return overrideColor;
|
||||
else
|
||||
return baseColor;
|
||||
}
|
||||
|
||||
|
||||
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
|
||||
vec2 uv = fragCoord.xy / iResolution.xy;
|
||||
fragColor = texture(iChannel0, uv);
|
||||
|
||||
vec2 currPos = iCurrentCursor.xy / iResolution.xy, currSize = iCurrentCursor.zw / iResolution.xy;
|
||||
vec2 prevPos = iPreviousCursor.xy / iResolution.xy, prevSize = iPreviousCursor.zw / iResolution.xy;
|
||||
vec2 currCenter = currPos + currSize * vec2(0.5, -0.5);
|
||||
vec2 prevCenter = prevPos + prevSize * vec2(0.5, -0.5);
|
||||
|
||||
float dCenter = distance(currCenter, prevCenter);
|
||||
float dSeg = dot(uv - prevCenter, currCenter - prevCenter) * pow(dCenter + EPS, -2);
|
||||
bool nearbyPrev = dCenter < TRAIL_MIN_DISTANCE;
|
||||
|
||||
float tShape = 1.0 - pow(1.0 - clamp((iTime - iTimeCursorChange) / TIME_DURATION_FACTOR, 0.0, 1.0), 3);
|
||||
float tVisible = exp(-(iTime - iTimeCursorChange) / TIME_DURATION_FACTOR * 50.0);
|
||||
|
||||
float dTrail = sdTrail(uv, currPos, currSize, prevPos, prevSize, tShape);
|
||||
float dTip = nearbyPrev ? 0.0 : clamp(1.0 - abs(dSeg - 1.0), 0.0, 1.0);
|
||||
|
||||
vec4 currColor = colorOverride(iCurrentCursorColor, vec4(GLOW_COLOR_OVERRIDE_CURRENT, 1.0));
|
||||
vec4 prevColor = colorOverride(iPreviousCursorColor, vec4(GLOW_COLOR_OVERRIDE_PREVIOUS, 1.0));
|
||||
vec4 glowColor = mix(fragColor, mix(prevColor, currColor, dTip) + GLOW_COLOR_OFFSET_BRIGHTNESS, pow(dTip, 3));
|
||||
glowColor = mix(glowColor, fragColor, pow(smoothstep(0.0, 0.3, dTrail), 0.1));
|
||||
|
||||
vec4 trailColor = mix(vec4(1.0), glowColor, pow(smoothstep(0.0, 0.01, dTrail), 0.2));
|
||||
vec4 trail = mix(trailColor, fragColor, pow(smoothstep(0.0, nearbyPrev ? 0.01 : 0.1, dTrail), 0.2));
|
||||
if (!nearbyPrev) {
|
||||
trail = mix(trailColor, trail, pow(smoothstep(0.0, 6.0, dTip), 0.05));
|
||||
trail = mix(trailColor, trail, pow(smoothstep(0.0, 8.0, dTip), 0.005));
|
||||
}
|
||||
|
||||
fragColor = mix(fragColor, trail, tVisible);
|
||||
}
|
||||
Reference in New Issue
Block a user