Remove extern from custom shader vars declarations

Since we specialize and compiler shader separately for every occurrence
in the pipeline, it is no longer needed.
This commit is contained in:
Kovid Goyal 2026-08-10 12:03:56 +05:30
parent 6a32ee62c4
commit 4a7b87a4f5
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
16 changed files with 91 additions and 92 deletions

View file

@ -124,7 +124,7 @@ with ``#`` are comments; blank lines are ignored.
below for their semantics.
``var <type> <name> <value>``
Sets a pipeline-level shader variable. Any ``extern static const``
Sets a pipeline-level shader variable. Any ``static const``
declaration in a shader whose name matches ``<name>`` is replaced with
``static const <type> <name> = <value>;`` before compilation, baking the
value in. This is the mechanism for tuning shader parameters without

View file

@ -37,9 +37,9 @@ static const float3 samples[24] = {
};
// minimum luminance for a pixel to contribute bloom
extern static const float BLOOM_THRESHOLD = 0.2f;
static const float BLOOM_THRESHOLD = 0.2f;
// strength of the bloom contribution
extern static const float BLOOM_STRENGTH = 0.2f;
static const float BLOOM_STRENGTH = 0.2f;
float lum(float4 c) {
return 0.299f * c.r + 0.587f * c.g + 0.114f * c.b;

View file

@ -9,9 +9,9 @@
import kitty_custom_shader_types;
extern static const float WARP = 0.25f; // simulates curvature of CRT monitor
extern static const float SCAN = 0.50f; // simulates darkness between scanlines
extern static const float4 TINT = float4(0, 0.8, 0.6, 0); // tint color set the fourth component to 1 to apply it fully
static const float WARP = 0.25f; // simulates curvature of CRT monitor
static const float SCAN = 0.50f; // simulates darkness between scanlines
static const float4 TINT = float4(0, 0.8, 0.6, 0); // tint color set the fourth component to 1 to apply it fully
public float4 fragment_main(
float4 color,

View file

@ -9,10 +9,10 @@
import kitty_custom_shader_types;
extern static const float4 TRAIL_COLOR = float4(1.0, 0.725, 0.161, 1.0);
extern static const float4 TRAIL_COLOR_ACCENT = float4(1.0, 0.0, 0.0, 1.0);
static const float4 TRAIL_COLOR = float4(1.0, 0.725, 0.161, 1.0);
static const float4 TRAIL_COLOR_ACCENT = float4(1.0, 0.0, 0.0, 1.0);
// Trail lifetime in seconds.
extern static const float DURATION = 0.5;
static const float DURATION = 0.5;
// pow(1 - x, 10) via repeated squaring — branchless ease-out.
static float ease_out10(float x) {

View file

@ -7,18 +7,18 @@
import kitty_custom_shader_types;
extern static const float3 BOLT_COLOR = float3(1.00, 0.82, 0.72);
extern static const float3 GLOW_COLOR = float3(0.74, 0.00, 0.00);
static const float3 BOLT_COLOR = float3(1.00, 0.82, 0.72);
static const float3 GLOW_COLOR = float3(0.74, 0.00, 0.00);
// Bolt lifetime in seconds.
extern static const float DURATION = 0.14;
static const float DURATION = 0.14;
// Sideways displacement relative to bolt length.
extern static const float JAGGEDNESS = 0.085;
static const float JAGGEDNESS = 0.085;
// Core stroke width in pixels.
extern static const float CORE_WIDTH = 1.15;
static const float CORE_WIDTH = 1.15;
// Glow radius in pixels.
extern static const float GLOW_WIDTH = 5.5;
static const float GLOW_WIDTH = 5.5;
// Number of linear segments that make up the main bolt.
extern static const int BOLT_SEGMENTS = 12;
static const int BOLT_SEGMENTS = 12;
static float hash11(float p) {
p = frac(p * 0.1031);

View file

@ -7,10 +7,10 @@
import kitty_custom_shader_types;
extern static const int NUM_PARTICLES = 128;
extern static const float BLACK_BLEND_THRESHOLD = 0.4f;
extern static const float CYCLE_TIME = 6.0f;
extern static const float PARTICLE_PHASE = 2.0f;
static const int NUM_PARTICLES = 128;
static const float BLACK_BLEND_THRESHOLD = 0.4f;
static const float CYCLE_TIME = 6.0f;
static const float PARTICLE_PHASE = 2.0f;
// Pseudo-random in [-1, 1]
float rand_val(float val, float seed) {

View file

@ -8,11 +8,11 @@
import kitty_custom_shader_types;
extern static const int NUM_EXPLOSIONS = 3;
extern static const int NUM_PARTICLES = 42;
extern static const float BLACK_BLEND_THRESHOLD = 0.4f;
extern static const float TIME_SCALE = 0.5f;
extern static const float PI = 3.14159265359f;
static const int NUM_EXPLOSIONS = 3;
static const int NUM_PARTICLES = 42;
static const float BLACK_BLEND_THRESHOLD = 0.4f;
static const float TIME_SCALE = 0.5f;
static const float PI = 3.14159265359f;
// Noise constant from Dave Hoskins — not user-tunable so kept as plain static const
static const float3 MOD3 = float3(0.1031f, 0.11369f, 0.13787f);

View file

@ -11,13 +11,13 @@ import kitty_custom_shader_types;
// Brightness multiplier boost applied to content inside the active window.
// 0.0 = no boost, 0.15 = 15% brighter.
extern static const float HIGHLIGHT_INTENSITY = 0.30;
static const float HIGHLIGHT_INTENSITY = 0.30;
// Width of the inner border glow in UV units.
extern static const float BORDER_WIDTH = 0.04;
static const float BORDER_WIDTH = 0.04;
// Peak additive brightness multiplier at the window border edge.
extern static const float BORDER_GLOW = 0.55;
static const float BORDER_GLOW = 0.55;
// Dim factor applied to pixels outside the active window (1.0 = unchanged, 0.0 = black).
extern static const float INACTIVE_DIM = 0.3;
static const float INACTIVE_DIM = 0.3;
public float4 fragment_main(
float4 color,

View file

@ -8,19 +8,19 @@
import kitty_custom_shader_types;
extern static const int ITERATIONS = 40;
extern static const float SPEED = 0.5f;
extern static const float STRIP_CHARS_MIN = 7.0f;
extern static const float STRIP_CHARS_MAX = 40.0f;
extern static const float STRIP_CHAR_HEIGHT = 0.15f;
extern static const float STRIP_CHAR_WIDTH = 0.10f;
extern static const float ZCELL_SIZE = STRIP_CHAR_HEIGHT * STRIP_CHARS_MAX;
extern static const float XYCELL_SIZE = 12.0f * STRIP_CHAR_WIDTH;
extern static const int BLOCK_SIZE = 10;
extern static const int BLOCK_GAP = 2;
extern static const float WALK_SPEED = 0.5f * XYCELL_SIZE;
extern static const float BLOCKS_BEFORE_TURN = 3.0f;
extern static const float PI = 3.14159265359f;
static const int ITERATIONS = 40;
static const float SPEED = 0.5f;
static const float STRIP_CHARS_MIN = 7.0f;
static const float STRIP_CHARS_MAX = 40.0f;
static const float STRIP_CHAR_HEIGHT = 0.15f;
static const float STRIP_CHAR_WIDTH = 0.10f;
static const float ZCELL_SIZE = STRIP_CHAR_HEIGHT * STRIP_CHARS_MAX;
static const float XYCELL_SIZE = 12.0f * STRIP_CHAR_WIDTH;
static const int BLOCK_SIZE = 10;
static const int BLOCK_GAP = 2;
static const float WALK_SPEED = 0.5f * XYCELL_SIZE;
static const float BLOCKS_BEFORE_TURN = 3.0f;
static const float PI = 3.14159265359f;
// ---- random ----

View file

@ -9,21 +9,21 @@
import kitty_custom_shader_types;
// Maximum wavefront radius at animation_progress=1 (aspect-corrected UV units).
extern static const float WAVE_SPEED = 0.45;
static const float WAVE_SPEED = 0.45;
// Spatial frequency of the rings (cycles per aspect-corrected UV unit).
extern static const float WAVE_FREQUENCY = 14.0;
static const float WAVE_FREQUENCY = 14.0;
// Starting half-width of the Gaussian envelope (expands as animation_progress increases).
extern static const float WAVE_WIDTH = 0.055;
static const float WAVE_WIDTH = 0.055;
// Peak radial UV displacement at the wavecrest.
extern static const float AMPLITUDE = 0.010;
static const float AMPLITUDE = 0.010;
// Scale applied to the wave gradient when constructing the surface normal.
extern static const float NORMAL_SCALE = 8.0;
static const float NORMAL_SCALE = 8.0;
// Blinn-Phong shininess exponent — higher values give a sharper, more mirror-like glint.
extern static const float SHININESS = 64.0;
static const float SHININESS = 64.0;
// Peak specular contribution at the wave crest facing the light.
extern static const float SPECULAR_STRENGTH = 0.40;
static const float SPECULAR_STRENGTH = 0.40;
// Subtle diffuse shading that rounds each ring into a 3D ridge.
extern static const float DIFFUSE_STRENGTH = 0.10;
static const float DIFFUSE_STRENGTH = 0.10;
public float4 fragment_main(
float4 color,

View file

@ -7,19 +7,19 @@
import kitty_custom_shader_types;
extern static const float SPOTLIGHT_RADIUS = 0.25; // spotlight radius in UV units
extern static const float SPOTLIGHT_SOFTNESS = 20.0; // edge sharpness; higher = sharper
extern static const float AMBIENT_LIGHT = 0.5; // minimum brightness outside the spotlight
extern static const float SPOTLIGHT_SPEED = 1.0; // oscillation speed in random-motion mode
static const float SPOTLIGHT_RADIUS = 0.25; // spotlight radius in UV units
static const float SPOTLIGHT_SOFTNESS = 20.0; // edge sharpness; higher = sharper
static const float AMBIENT_LIGHT = 0.5; // minimum brightness outside the spotlight
static const float SPOTLIGHT_SPEED = 1.0; // oscillation speed in random-motion mode
// Set to 1 to follow the mouse, 0 to use random oscillation
extern static const int USE_MOUSE = 1;
static const int USE_MOUSE = 1;
// When USE_MOUSE=1 and the mouse leaves the window:
// 0 = fall back to random oscillation
// 1 = clamp spotlight to the nearest window edge
// 2 = disable spotlight (pass through unchanged pixels)
extern static const int MOUSE_LEAVE_BEHAVIOR = 2;
static const int MOUSE_LEAVE_BEHAVIOR = 2;
// Set to 1 to pass through unchanged pixels when the mouse pointer is hidden
extern static const int HIDE_WHEN_POINTER_HIDDEN = 1;
static const int HIDE_WHEN_POINTER_HIDDEN = 1;
public float4 fragment_main(
float4 color,

View file

@ -17,13 +17,13 @@
import kitty_custom_shader_types;
// 0=FADE, 1=WIPE, 2=BLINDS, 3=IRIS
extern static const int ANIMATION_TYPE = 1;
static const int ANIMATION_TYPE = 1;
// Number of strips for ANIMATION_TYPE == 2 (BLINDS).
extern static const int NUM_BLINDS = 8;
static const int NUM_BLINDS = 8;
// Soft-edge width in UV units used by WIPE and IRIS.
extern static const float EDGE_SOFTNESS = 0.04;
static const float EDGE_SOFTNESS = 0.04;
// Returns a value in [0, 1] for this pixel: 0 at the tab-bar edge of the
// content area, 1 at the opposite edge. The wipe sweeps from 0 toward 1.

View file

@ -7,10 +7,10 @@
import kitty_custom_shader_types;
// size of the simulated pixels
extern static const float RESOLUTION = 4.0;
static const float RESOLUTION = 4.0;
// strength of the effect
extern static const float STRENGTH = 0.5;
static const float STRENGTH = 0.5;
void scanline(inout float3 color, float2 pixel_pos) {
float scanline = step(1.2, fmod(pixel_pos.y, RESOLUTION));

View file

@ -8,37 +8,37 @@
import kitty_custom_shader_types;
// Luminance threshold: pixels darker than this receive the ray overlay
extern static const float BLACK_BLEND_THRESHOLD = 0.4;
static const float BLACK_BLEND_THRESHOLD = 0.4;
// Ray 1 source position (as fractions of viewport dimensions)
extern static const float RAY1_SRC_X = 0.7;
extern static const float RAY1_SRC_Y = 1.1;
static const float RAY1_SRC_X = 0.7;
static const float RAY1_SRC_Y = 1.1;
// Y component of ray 1 reference direction (X component is always 1.0)
extern static const float RAY1_DIR_Y = 0.116;
extern static const float RAY1_SEED_A = 36.2214;
extern static const float RAY1_SEED_B = 21.11349;
extern static const float RAY1_SPEED = 1.1;
extern static const float RAY1_WEIGHT = 0.5; // contribution weight in final blend
static const float RAY1_DIR_Y = 0.116;
static const float RAY1_SEED_A = 36.2214;
static const float RAY1_SEED_B = 21.11349;
static const float RAY1_SPEED = 1.1;
static const float RAY1_WEIGHT = 0.5; // contribution weight in final blend
// Ray 2 source position (as fractions of viewport dimensions)
extern static const float RAY2_SRC_X = 0.8;
extern static const float RAY2_SRC_Y = 1.2;
extern static const float RAY2_DIR_Y = -0.241;
extern static const float RAY2_SEED_A = 22.39910;
extern static const float RAY2_SEED_B = 18.0234;
extern static const float RAY2_SPEED = 0.9;
extern static const float RAY2_WEIGHT = 0.4;
static const float RAY2_SRC_X = 0.8;
static const float RAY2_SRC_Y = 1.2;
static const float RAY2_DIR_Y = -0.241;
static const float RAY2_SEED_A = 22.39910;
static const float RAY2_SEED_B = 18.0234;
static const float RAY2_SPEED = 0.9;
static const float RAY2_WEIGHT = 0.4;
// Per-channel depth-attenuation: channel *= BASE + brightness * SCALE
extern static const float DEPTH_R_BASE = 0.05;
extern static const float DEPTH_R_SCALE = 0.8;
extern static const float DEPTH_G_BASE = 0.15;
extern static const float DEPTH_G_SCALE = 0.6;
extern static const float DEPTH_B_BASE = 0.3;
extern static const float DEPTH_B_SCALE = 0.5;
static const float DEPTH_R_BASE = 0.05;
static const float DEPTH_R_SCALE = 0.8;
static const float DEPTH_G_BASE = 0.15;
static const float DEPTH_G_SCALE = 0.6;
static const float DEPTH_B_BASE = 0.3;
static const float DEPTH_B_SCALE = 0.5;
// Overall strength of the ray overlay on dark terminal content
extern static const float OVERLAY_STRENGTH = 0.3;
static const float OVERLAY_STRENGTH = 0.3;
float hash21(float2 p) {
p = frac(p * float2(233.34, 851.73));

View file

@ -6,11 +6,11 @@
import kitty_custom_shader_types;
extern static const float TAU = 6.28318530718;
extern static const int MAX_ITER = 6;
extern static const float3 WATER_COLOR = float3(0.5, 0.5, 0.5); // water overlay tint
extern static const float CAUSTIC_INTEN = 0.005; // caustic ripple intensity
extern static const float UV_DISPLACEMENT = 0.04; // UV warp magnitude from caustics
static const float TAU = 6.28318530718;
static const int MAX_ITER = 6;
static const float3 WATER_COLOR = float3(0.5, 0.5, 0.5); // water overlay tint
static const float CAUSTIC_INTEN = 0.005; // caustic ripple intensity
static const float UV_DISPLACEMENT = 0.04; // UV warp magnitude from caustics
public float4 fragment_main(
float4 color,

View file

@ -1193,9 +1193,8 @@ def apply_pipeline_specializations(src: bytes, merged_vars: dict[str, tuple[str,
return src
text = src.decode()
for var_name, (var_type, value) in merged_vars.items():
# Replace: extern static const <any_type> <name> = <default>; → static const <type> <name> = <value>;
# The extern keyword is removed so the value is baked into the compiled shader module.
pattern = rf'(?m)^(\s*)extern\s+static\s+const\s+\S+\s+{re.escape(var_name)}\s*=[^;\n]+;'
# Replace: static const <any_type> <name> = <default>; → static const <type> <name> = <value>;
pattern = rf'(?m)^(\s*)static\s+const\s+{re.escape(var_type)}\s+{re.escape(var_name)}\s*=.+'
text = re.sub(pattern, rf'\g<1>static const {var_type} {var_name} = {value};', text)
return text.encode()