summaryrefslogtreecommitdiff
path: root/sway/desktop/fx_renderer/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'sway/desktop/fx_renderer/shaders')
-rw-r--r--sway/desktop/fx_renderer/shaders/blur1.frag18
-rw-r--r--sway/desktop/fx_renderer/shaders/blur2.frag22
-rw-r--r--sway/desktop/fx_renderer/shaders/blur_effects.frag54
-rw-r--r--sway/desktop/fx_renderer/shaders/box_shadow.frag74
-rw-r--r--sway/desktop/fx_renderer/shaders/common.vert12
-rw-r--r--sway/desktop/fx_renderer/shaders/corner.frag36
-rw-r--r--sway/desktop/fx_renderer/shaders/embed.sh11
-rw-r--r--sway/desktop/fx_renderer/shaders/meson.build27
-rw-r--r--sway/desktop/fx_renderer/shaders/quad.frag7
-rw-r--r--sway/desktop/fx_renderer/shaders/quad_round.frag39
-rw-r--r--sway/desktop/fx_renderer/shaders/stencil_mask.frag17
-rw-r--r--sway/desktop/fx_renderer/shaders/tex.frag67
12 files changed, 0 insertions, 384 deletions
diff --git a/sway/desktop/fx_renderer/shaders/blur1.frag b/sway/desktop/fx_renderer/shaders/blur1.frag
deleted file mode 100644
index e7cb1be8..00000000
--- a/sway/desktop/fx_renderer/shaders/blur1.frag
+++ /dev/null
@@ -1,18 +0,0 @@
-precision mediump float;
-varying mediump vec2 v_texcoord;
-uniform sampler2D tex;
-
-uniform float radius;
-uniform vec2 halfpixel;
-
-void main() {
- vec2 uv = v_texcoord * 2.0;
-
- vec4 sum = texture2D(tex, uv) * 4.0;
- sum += texture2D(tex, uv - halfpixel.xy * radius);
- sum += texture2D(tex, uv + halfpixel.xy * radius);
- sum += texture2D(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius);
- sum += texture2D(tex, uv - vec2(halfpixel.x, -halfpixel.y) * radius);
-
- gl_FragColor = sum / 8.0;
-}
diff --git a/sway/desktop/fx_renderer/shaders/blur2.frag b/sway/desktop/fx_renderer/shaders/blur2.frag
deleted file mode 100644
index 3755a294..00000000
--- a/sway/desktop/fx_renderer/shaders/blur2.frag
+++ /dev/null
@@ -1,22 +0,0 @@
-precision mediump float;
-varying mediump vec2 v_texcoord;
-uniform sampler2D tex;
-
-uniform float radius;
-uniform vec2 halfpixel;
-
-void main() {
- vec2 uv = v_texcoord / 2.0;
-
- vec4 sum = texture2D(tex, uv + vec2(-halfpixel.x * 2.0, 0.0) * radius);
-
- sum += texture2D(tex, uv + vec2(-halfpixel.x, halfpixel.y) * radius) * 2.0;
- sum += texture2D(tex, uv + vec2(0.0, halfpixel.y * 2.0) * radius);
- sum += texture2D(tex, uv + vec2(halfpixel.x, halfpixel.y) * radius) * 2.0;
- sum += texture2D(tex, uv + vec2(halfpixel.x * 2.0, 0.0) * radius);
- sum += texture2D(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius) * 2.0;
- sum += texture2D(tex, uv + vec2(0.0, -halfpixel.y * 2.0) * radius);
- sum += texture2D(tex, uv + vec2(-halfpixel.x, -halfpixel.y) * radius) * 2.0;
-
- gl_FragColor = sum / 12.0;
-}
diff --git a/sway/desktop/fx_renderer/shaders/blur_effects.frag b/sway/desktop/fx_renderer/shaders/blur_effects.frag
deleted file mode 100644
index 2fc16c15..00000000
--- a/sway/desktop/fx_renderer/shaders/blur_effects.frag
+++ /dev/null
@@ -1,54 +0,0 @@
-precision mediump float;
-varying vec2 v_texcoord;
-uniform sampler2D tex;
-
-uniform float noise;
-uniform float brightness;
-uniform float contrast;
-uniform float saturation;
-
-mat4 brightnessMatrix() {
- float b = brightness - 1.0;
- return mat4(1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- b, b, b, 1);
-}
-
-mat4 contrastMatrix() {
- float t = (1.0 - contrast) / 2.0;
- return mat4(contrast, 0, 0, 0,
- 0, contrast, 0, 0,
- 0, 0, contrast, 0,
- t, t, t, 1);
-}
-
-mat4 saturationMatrix() {
- vec3 luminance = vec3(0.3086, 0.6094, 0.0820);
- float oneMinusSat = 1.0 - saturation;
- vec3 red = vec3(luminance.x * oneMinusSat);
- red+= vec3(saturation, 0, 0);
- vec3 green = vec3(luminance.y * oneMinusSat);
- green += vec3(0, saturation, 0);
- vec3 blue = vec3(luminance.z * oneMinusSat);
- blue += vec3(0, 0, saturation);
- return mat4(red, 0,
- green, 0,
- blue, 0,
- 0, 0, 0, 1);
-}
-
-// Fast generative noise function
-float hash(vec2 p) {
- return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
-}
-
-void main() {
- vec4 color = texture2D(tex, v_texcoord);
- color *= brightnessMatrix() * contrastMatrix() * saturationMatrix();
- float noiseHash = hash(v_texcoord);
- float noiseAmount = (mod(noiseHash, 1.0) - 0.5);
- color.rgb += noiseAmount * noise;
-
- gl_FragColor = color;
-}
diff --git a/sway/desktop/fx_renderer/shaders/box_shadow.frag b/sway/desktop/fx_renderer/shaders/box_shadow.frag
deleted file mode 100644
index c9b2b91f..00000000
--- a/sway/desktop/fx_renderer/shaders/box_shadow.frag
+++ /dev/null
@@ -1,74 +0,0 @@
-// Writeup: https://madebyevan.com/shaders/fast-rounded-rectangle-shadows/
-
-precision mediump float;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-uniform vec2 position;
-uniform vec2 size;
-uniform float blur_sigma;
-uniform float corner_radius;
-
-float gaussian(float x, float sigma) {
- const float pi = 3.141592653589793;
- return exp(-(x * x) / (2.0 * sigma * sigma)) / (sqrt(2.0 * pi) * sigma);
-}
-
-// approximates the error function, needed for the gaussian integral
-vec2 erf(vec2 x) {
- vec2 s = sign(x), a = abs(x);
- x = 1.0 + (0.278393 + (0.230389 + 0.078108 * (a * a)) * a) * a;
- x *= x;
- return s - s / (x * x);
-}
-
-// return the blurred mask along the x dimension
-float roundedBoxShadowX(float x, float y, float sigma, float corner, vec2 halfSize) {
- float delta = min(halfSize.y - corner - abs(y), 0.0);
- float curved = halfSize.x - corner + sqrt(max(0.0, corner * corner - delta * delta));
- vec2 integral = 0.5 + 0.5 * erf((x + vec2(-curved, curved)) * (sqrt(0.5) / sigma));
- return integral.y - integral.x;
-}
-
-// return the mask for the shadow of a box from lower to upper
-float roundedBoxShadow(vec2 lower, vec2 upper, vec2 point, float sigma, float corner_radius) {
- // Center everything to make the math easier
- vec2 center = (lower + upper) * 0.5;
- vec2 halfSize = (upper - lower) * 0.5;
- point -= center;
-
- // The signal is only non-zero in a limited range, so don't waste samples
- float low = point.y - halfSize.y;
- float high = point.y + halfSize.y;
- float start = clamp(-3.0 * sigma, low, high);
- float end = clamp(3.0 * sigma, low, high);
-
- // Accumulate samples (we can get away with surprisingly few samples)
- float step = (end - start) / 4.0;
- float y = start + step * 0.5;
- float value = 0.0;
- for (int i = 0; i < 4; i++) {
- value += roundedBoxShadowX(point.x, point.y - y, sigma, corner_radius, halfSize) * gaussian(y, sigma) * step;
- y += step;
- }
-
- return value;
-}
-
-// per-pixel "random" number between 0 and 1
-float random() {
- return fract(sin(dot(vec2(12.9898, 78.233), gl_FragCoord.xy)) * 43758.5453);
-}
-
-void main() {
- float frag_alpha = v_color.a * roundedBoxShadow(
- position + blur_sigma,
- position + size - blur_sigma,
- gl_FragCoord.xy, blur_sigma * 0.5,
- corner_radius);
-
- // dither the alpha to break up color bands
- frag_alpha += (random() - 0.5) / 128.0;
-
- gl_FragColor = vec4(v_color.rgb, frag_alpha);
-}
diff --git a/sway/desktop/fx_renderer/shaders/common.vert b/sway/desktop/fx_renderer/shaders/common.vert
deleted file mode 100644
index 811e0f2d..00000000
--- a/sway/desktop/fx_renderer/shaders/common.vert
+++ /dev/null
@@ -1,12 +0,0 @@
-uniform mat3 proj;
-uniform vec4 color;
-attribute vec2 pos;
-attribute vec2 texcoord;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-void main() {
- gl_Position = vec4(proj * vec3(pos, 1.0), 1.0);
- v_color = color;
- v_texcoord = texcoord;
-}
diff --git a/sway/desktop/fx_renderer/shaders/corner.frag b/sway/desktop/fx_renderer/shaders/corner.frag
deleted file mode 100644
index 7699299a..00000000
--- a/sway/desktop/fx_renderer/shaders/corner.frag
+++ /dev/null
@@ -1,36 +0,0 @@
-precision mediump float;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-uniform bool is_top_left;
-uniform bool is_top_right;
-uniform bool is_bottom_left;
-uniform bool is_bottom_right;
-
-uniform vec2 position;
-uniform float radius;
-uniform vec2 half_size;
-uniform float half_thickness;
-
-float roundedBoxSDF(vec2 center, vec2 size, float radius) {
- return length(max(abs(center) - size + radius, 0.0)) - radius;
-}
-
-void main() {
- vec2 center = gl_FragCoord.xy - position - half_size;
- float distance = roundedBoxSDF(center, half_size - half_thickness, radius + half_thickness);
- float smoothedAlphaOuter = 1.0 - smoothstep(-1.0, 1.0, distance - half_thickness);
- // Create an inner circle that isn't as anti-aliased as the outer ring
- float smoothedAlphaInner = 1.0 - smoothstep(-1.0, 0.5, distance + half_thickness);
- gl_FragColor = mix(vec4(0), v_color, smoothedAlphaOuter - smoothedAlphaInner);
-
- if (is_top_left && (center.y > 0.0 || center.x > 0.0)) {
- discard;
- } else if (is_top_right && (center.y > 0.0 || center.x < 0.0)) {
- discard;
- } else if (is_bottom_left && (center.y < 0.0 || center.x > 0.0)) {
- discard;
- } else if (is_bottom_right && (center.y < 0.0 || center.x < 0.0)) {
- discard;
- }
-}
diff --git a/sway/desktop/fx_renderer/shaders/embed.sh b/sway/desktop/fx_renderer/shaders/embed.sh
deleted file mode 100644
index 47f07892..00000000
--- a/sway/desktop/fx_renderer/shaders/embed.sh
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/bin/sh -eu
-
-var=${1:-data}
-hex="$(od -A n -t x1 -v)"
-
-echo "static const char $var[] = {"
-for byte in $hex; do
- echo " 0x$byte,"
-done
-echo " 0x00,"
-echo "};"
diff --git a/sway/desktop/fx_renderer/shaders/meson.build b/sway/desktop/fx_renderer/shaders/meson.build
deleted file mode 100644
index 19f76dc2..00000000
--- a/sway/desktop/fx_renderer/shaders/meson.build
+++ /dev/null
@@ -1,27 +0,0 @@
-embed = find_program('./embed.sh', native: true)
-
-shaders = [
- 'blur1.frag',
- 'blur2.frag',
- 'blur_effects.frag',
- 'box_shadow.frag',
- 'common.vert',
- 'corner.frag',
- 'quad.frag',
- 'quad_round.frag',
- 'stencil_mask.frag',
- 'tex.frag',
-]
-
-foreach name : shaders
- output = name.underscorify() + '_src.h'
- var = name.underscorify() + '_src'
- sway_sources += custom_target(
- output,
- command: [embed, var],
- input: name,
- output: output,
- feed: true,
- capture: true,
- )
-endforeach
diff --git a/sway/desktop/fx_renderer/shaders/quad.frag b/sway/desktop/fx_renderer/shaders/quad.frag
deleted file mode 100644
index 7c763272..00000000
--- a/sway/desktop/fx_renderer/shaders/quad.frag
+++ /dev/null
@@ -1,7 +0,0 @@
-precision mediump float;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-void main() {
- gl_FragColor = v_color;
-}
diff --git a/sway/desktop/fx_renderer/shaders/quad_round.frag b/sway/desktop/fx_renderer/shaders/quad_round.frag
deleted file mode 100644
index 02e99028..00000000
--- a/sway/desktop/fx_renderer/shaders/quad_round.frag
+++ /dev/null
@@ -1,39 +0,0 @@
-#define SOURCE_QUAD_ROUND 1
-#define SOURCE_QUAD_ROUND_TOP_LEFT 2
-#define SOURCE_QUAD_ROUND_TOP_RIGHT 3
-#define SOURCE_QUAD_ROUND_BOTTOM_RIGHT 4
-#define SOURCE_QUAD_ROUND_BOTTOM_LEFT 5
-
-#if !defined(SOURCE)
-#error "Missing shader preamble"
-#endif
-
-precision mediump float;
-varying vec4 v_color;
-varying vec2 v_texcoord;
-
-uniform vec2 size;
-uniform vec2 position;
-uniform float radius;
-
-vec2 getCornerDist() {
-#if SOURCE == SOURCE_QUAD_ROUND
- vec2 half_size = size * 0.5;
- return abs(gl_FragCoord.xy - position - half_size) - half_size + radius;
-#elif SOURCE == SOURCE_QUAD_ROUND_TOP_LEFT
- return abs(gl_FragCoord.xy - position - size) - size + radius;
-#elif SOURCE == SOURCE_QUAD_ROUND_TOP_RIGHT
- return abs(gl_FragCoord.xy - position - vec2(0, size.y)) - size + radius;
-#elif SOURCE == SOURCE_QUAD_ROUND_BOTTOM_RIGHT
- return abs(gl_FragCoord.xy - position) - size + radius;
-#elif SOURCE == SOURCE_QUAD_ROUND_BOTTOM_LEFT
- return abs(gl_FragCoord.xy - position - vec2(size.x, 0)) - size + radius;
-#endif
-}
-
-void main() {
- vec2 q = getCornerDist();
- float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius;
- float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist);
- gl_FragColor = mix(vec4(0), v_color, smoothedAlpha);
-}
diff --git a/sway/desktop/fx_renderer/shaders/stencil_mask.frag b/sway/desktop/fx_renderer/shaders/stencil_mask.frag
deleted file mode 100644
index ee033070..00000000
--- a/sway/desktop/fx_renderer/shaders/stencil_mask.frag
+++ /dev/null
@@ -1,17 +0,0 @@
-precision mediump float;
-varying vec2 v_texcoord;
-
-uniform vec2 half_size;
-uniform vec2 position;
-uniform float radius;
-
-void main() {
- vec2 q = abs(gl_FragCoord.xy - position - half_size) - half_size + radius;
- float dist = min(max(q.x,q.y), 0.0) + length(max(q, 0.0)) - radius;
- float smoothedAlpha = 1.0 - smoothstep(-1.0, 0.5, dist);
- gl_FragColor = mix(vec4(0.0), vec4(1.0), smoothedAlpha);
-
- if (gl_FragColor.a < 1.0) {
- discard;
- }
-}
diff --git a/sway/desktop/fx_renderer/shaders/tex.frag b/sway/desktop/fx_renderer/shaders/tex.frag
deleted file mode 100644
index 77501887..00000000
--- a/sway/desktop/fx_renderer/shaders/tex.frag
+++ /dev/null
@@ -1,67 +0,0 @@
-#define SOURCE_TEXTURE_RGBA 1
-#define SOURCE_TEXTURE_RGBX 2
-#define SOURCE_TEXTURE_EXTERNAL 3
-
-#if !defined(SOURCE)
-#error "Missing shader preamble"
-#endif
-
-#if SOURCE == SOURCE_TEXTURE_EXTERNAL
-#extension GL_OES_EGL_image_external : require
-#endif
-
-precision mediump float;
-
-varying vec2 v_texcoord;
-
-#if SOURCE == SOURCE_TEXTURE_EXTERNAL
-uniform samplerExternalOES tex;
-#elif SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_RGBX
-uniform sampler2D tex;
-#endif
-
-uniform float alpha;
-uniform float dim;
-uniform vec4 dim_color;
-uniform vec2 size;
-uniform vec2 position;
-uniform float radius;
-uniform float saturation;
-uniform bool has_titlebar;
-uniform bool discard_transparent;
-
-const vec3 saturation_weight = vec3(0.2125, 0.7154, 0.0721);
-
-vec4 sample_texture() {
-#if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL
- return texture2D(tex, v_texcoord);
-#elif SOURCE == SOURCE_TEXTURE_RGBX
- return vec4(texture2D(tex, v_texcoord).rgb, 1.0);
-#endif
-}
-
-void main() {
- vec4 color = sample_texture();
- // Saturation
- if (saturation != 1.0) {
- vec4 pixColor = texture2D(tex, v_texcoord);
- vec3 irgb = pixColor.rgb;
- vec3 target = vec3(dot(irgb, saturation_weight));
- color = vec4(mix(target, irgb, saturation), pixColor.a);
- }
- // Dimming
- gl_FragColor = mix(color, dim_color, dim) * alpha;
-
- if (!has_titlebar || gl_FragCoord.y - position.y > radius) {
- vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy);
- if (max(corner_distance.x, corner_distance.y) < radius) {
- float d = radius - distance(corner_distance, vec2(radius));
- float smooth = smoothstep(-1.0, 0.5, d);
- gl_FragColor = mix(vec4(0), gl_FragColor, smooth);
- }
- }
-
- if (discard_transparent && gl_FragColor.a == 0.0) {
- discard;
- }
-}