diff options
| author | Will McKinnon <[email protected]> | 2023-03-20 12:30:40 -0400 |
|---|---|---|
| committer | Will McKinnon <[email protected]> | 2023-03-20 13:00:31 -0400 |
| commit | 7d5d7a3022eb17835cea7af7290b1a5d2fe4b03a (patch) | |
| tree | 2bf9be23f960f5ff7674e0a5dbe5cce71dfcbe59 /sway/desktop/shaders | |
| parent | 474bfb460adab10ba0ca208891653d278ce1fbb9 (diff) | |
style: cleaned up fx_renderer.c
Diffstat (limited to 'sway/desktop/shaders')
| -rw-r--r-- | sway/desktop/shaders/meson.build | 6 | ||||
| -rw-r--r-- | sway/desktop/shaders/tex.frag | 29 | ||||
| -rw-r--r-- | sway/desktop/shaders/tex_decorated.frag | 63 |
3 files changed, 31 insertions, 67 deletions
diff --git a/sway/desktop/shaders/meson.build b/sway/desktop/shaders/meson.build index ff5e04b2..14014c7d 100644 --- a/sway/desktop/shaders/meson.build +++ b/sway/desktop/shaders/meson.build @@ -1,14 +1,14 @@ embed = find_program('./embed.sh', native: true) shaders = [ + 'box_shadow.frag', 'common.vert', + 'corner.frag', 'quad.frag', 'quad_round.frag', 'quad_round_tl.frag', 'quad_round_tr.frag', - 'corner.frag', - 'box_shadow.frag', - 'tex_decorated.frag', + 'tex.frag', ] foreach name : shaders diff --git a/sway/desktop/shaders/tex.frag b/sway/desktop/shaders/tex.frag index 3f529137..40320f9b 100644 --- a/sway/desktop/shaders/tex.frag +++ b/sway/desktop/shaders/tex.frag @@ -22,6 +22,15 @@ uniform sampler2D tex; #endif uniform float alpha; +uniform float dim; +uniform vec4 dim_color; +uniform vec2 size; +uniform vec2 position; +uniform float radius; +uniform bool has_titlebar; +uniform float saturation; + +const vec3 saturation_weight = vec3(0.2125, 0.7154, 0.0721); vec4 sample_texture() { #if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL @@ -32,5 +41,23 @@ vec4 sample_texture() { } void main() { - gl_FragColor = sample_texture() * alpha; + 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.0f, 0.5f, d); + gl_FragColor = mix(vec4(0), gl_FragColor, smooth); + } + } } diff --git a/sway/desktop/shaders/tex_decorated.frag b/sway/desktop/shaders/tex_decorated.frag deleted file mode 100644 index 40320f9b..00000000 --- a/sway/desktop/shaders/tex_decorated.frag +++ /dev/null @@ -1,63 +0,0 @@ -/* enum wlr_gles2_shader_source */ -#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 bool has_titlebar; -uniform float saturation; - -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.0f, 0.5f, d); - gl_FragColor = mix(vec4(0), gl_FragColor, smooth); - } - } -} |
