fork/wezterm
git clone https://git.julia.blue/fork/wezterm
11c4b1166
termwiz-0.23.3
1// This is the Glyph fragment shader. 2// It is responsible for laying down the glyph graphics on top of the other layers. 3#extension GL_EXT_blend_func_extended : enable 4precision highp float ; 5 6in float o_has_color; 7in vec2 o_tex; 8in vec3 o_hsv; 9in vec4 o_fg_color; 10in vec4 o_fg_color_alt; 11in float o_fg_color_mix; 12 13// The color + alpha 14layout (location = 0 , index = 0 ) out vec4 color; 15// Individual alpha channels for RGBA in color, used for subpixel 16// antialiasing blending 17layout (location = 0 , index = 1 ) out vec4 colorMask; 18 19uniform vec3 foreground_text_hsb; 20uniform sampler2D atlas_nearest_sampler; 21uniform sampler2D atlas_linear_sampler; 22uniform bool subpixel_aa; 23uniform uint milliseconds; 24 25struct ColorEase { 26vec4 in_function ; 27vec4 out_function ; 28uint in_duration_ms ; 29uint out_duration_ms ; 30}; 31 32float evaluate_cubic_bezier( vec4 bezier, float x) { 33return pow( 1.0 - x, 3.0 ) * bezier[ 0 ] 34+ 3.0 * pow( 1.0 - x, 2. ) * x * bezier[ 1 ] 35+ 3.0 * ( 1.0 - x) * pow(x, 2. ) * bezier[ 2 ] 36+ pow(x, 3. ) * bezier[ 3 ]; 37} 38 39float colorease_intensity( ColorEase ease) { 40uint total_duration = ease. in_duration_ms + ease. out_duration_ms ; 41uint elapsed = milliseconds % total_duration; 42if (elapsed < ease. in_duration_ms ) { 43return evaluate_cubic_bezier( 44ease. in_function , 45float(elapsed) / float(ease. in_duration_ms ) 46); 47} 48return 1.0 - evaluate_cubic_bezier( 49ease. out_function , 50float(elapsed - ease. in_duration_ms ) / float(ease. out_duration_ms ) 51); 52} 53 54uniform ColorEase cursor_blink; 55uniform ColorEase blink; 56uniform ColorEase rapid_blink; 57 58vec3 rgb2hsv( vec3 c) 59{ 60vec4 K = vec4( 0.0 , -1.0 / 3.0 , 2.0 / 3.0 , -1.0 ); 61vec4 p = mix(vec4(c. bg , K. wz ), vec4(c. gb , K. xy ), step(c. b , c. g )); 62vec4 q = mix(vec4(p. xyw , c. r ), vec4(c. r , p. yzx ), step(p. x , c. r )); 63 64float d = q. x - min(q. w , q. y ); 65float e = 1.0e-10 ; 66return vec3(abs(q. z + (q. w - q. y ) / ( 6.0 * d + e)), d / (q. x + e), q. x ); 67} 68 69vec3 hsv2rgb( vec3 c) 70{ 71vec4 K = vec4( 1.0 , 2.0 / 3.0 , 1.0 / 3.0 , 3.0 ); 72vec3 p = abs(fract(c. xxx + K. xyz ) * 6.0 - K. www ); 73return c. z * mix(K. xxx , clamp(p - K. xxx , 0.0 , 1.0 ), c. y ); 74} 75 76const vec3 unit3 = vec3( 1.0 ); 77 78vec4 apply_hsv( vec4 c, vec3 transform) 79{ 80if (transform == unit3) { 81return c; 82} 83vec3 hsv = rgb2hsv(c. rgb ) * transform; 84return vec4(hsv2rgb(hsv). rgb , c. a ); 85} 86 87/* 88float to_srgb(float x) { 89if (x <= 0.0031308) { 90return 12.92 * x; 91} 92return 1.055 * pow(x, (1.0 / 2.4)) - 0.055; 93} 94 95vec3 to_srgb(vec3 c) { 96return vec3(to_srgb(c.r), to_srgb(c.g), to_srgb(c.b)); 97} 98 99vec4 to_srgb(vec4 v) { 100return vec4(to_srgb(v.rgb), v.a); 101} 102*/ 103 104vec4 to_srgb( vec4 linearRGB) 105{ 106bvec3 cutoff = lessThan(linearRGB. rgb , vec3( 0.0031308 )); 107vec3 higher = vec3( 1.055 ) * pow(linearRGB. rgb , vec3( 1.0 / 2.4 )) - vec3( 0.055 ); 108vec3 lower = linearRGB. rgb * vec3( 12.92 ); 109 110return vec4(mix(higher, lower, cutoff), linearRGB. a ); 111} 112 113void main() { 114vec4 fg_color = mix(o_fg_color, o_fg_color_alt, o_fg_color_mix); 115if (o_has_color == 3.0 ) { 116// Solid color block 117color = fg_color; 118colorMask = vec4( 1.0 ); 119} else if (o_has_color == 2.0 ) { 120// The window background attachment 121color = texture(atlas_linear_sampler, o_tex); 122// Apply window_background_image_opacity to the background image 123if (subpixel_aa) { 124colorMask = fg_color. aaaa ; 125} else { 126color. a *= fg_color. a ; 127} 128} else if (o_has_color == 1.0 ) { 129// the texture is full color info (eg: color emoji glyph) 130color = texture(atlas_nearest_sampler, o_tex); 131// this is the alpha 132colorMask = color. aaaa ; 133} else if (o_has_color == 4.0 ) { 134// Grayscale poly quad for non-aa text render layers 135colorMask = texture(atlas_nearest_sampler, o_tex); 136color = fg_color; 137// On Intel hardware/drivers, we need to recompute the alpha this way. 138// We don't know why; it doesn't make sense. 139// The inputs are already in range and work fine on other platforms. 140// See discussion starting at: 141// <https://github.com/wezterm/wezterm/issues/1180#issuecomment-1496102764> 142// for the background. 143color. a = mix(o_fg_color. a , o_fg_color_alt. a , clamp(o_fg_color_mix, 0.0 , 1.0 )); 144color. a *= colorMask. a ; 145} else if (o_has_color == 0.0 ) { 146// the texture is the alpha channel/color mask 147colorMask = texture(atlas_nearest_sampler, o_tex); 148// and we need to tint with the fg_color 149color = fg_color; 150if (!subpixel_aa) { 151color. a = colorMask. a ; 152} 153color = apply_hsv(color, foreground_text_hsb); 154} 155 156color = apply_hsv(color, o_hsv); 157 158// We MUST output SRGB and tell glium that we do that (outputs_srgb), 159// otherwise something in glium over-gamma-corrects depending on the gl setup. 160color = to_srgb(color ); 161}