From 1a10c61165a790b95c6fdd7c640ce7d4e9d7d978 Mon Sep 17 00:00:00 2001 From: Will McKinnon Date: Sat, 18 Mar 2023 01:03:02 -0400 Subject: refactor: merged tex shaders --- sway/desktop/shaders/meson.build | 4 +-- sway/desktop/shaders/tex.frag | 36 +++++++++++++++++++ sway/desktop/shaders/tex_decorated.frag | 63 +++++++++++++++++++++++++++++++++ sway/desktop/shaders/tex_external.frag | 37 ------------------- sway/desktop/shaders/tex_rgba.frag | 35 ------------------ sway/desktop/shaders/tex_rgbx.frag | 34 ------------------ 6 files changed, 100 insertions(+), 109 deletions(-) create mode 100644 sway/desktop/shaders/tex.frag create mode 100644 sway/desktop/shaders/tex_decorated.frag delete mode 100644 sway/desktop/shaders/tex_external.frag delete mode 100644 sway/desktop/shaders/tex_rgba.frag delete mode 100644 sway/desktop/shaders/tex_rgbx.frag (limited to 'sway/desktop/shaders') diff --git a/sway/desktop/shaders/meson.build b/sway/desktop/shaders/meson.build index ce2439de..ff5e04b2 100644 --- a/sway/desktop/shaders/meson.build +++ b/sway/desktop/shaders/meson.build @@ -8,9 +8,7 @@ shaders = [ 'quad_round_tr.frag', 'corner.frag', 'box_shadow.frag', - 'tex_rgba.frag', - 'tex_rgbx.frag', - 'tex_external.frag', + 'tex_decorated.frag', ] foreach name : shaders diff --git a/sway/desktop/shaders/tex.frag b/sway/desktop/shaders/tex.frag new file mode 100644 index 00000000..3f529137 --- /dev/null +++ b/sway/desktop/shaders/tex.frag @@ -0,0 +1,36 @@ +/* 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; + +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() { + gl_FragColor = sample_texture() * alpha; +} diff --git a/sway/desktop/shaders/tex_decorated.frag b/sway/desktop/shaders/tex_decorated.frag new file mode 100644 index 00000000..40320f9b --- /dev/null +++ b/sway/desktop/shaders/tex_decorated.frag @@ -0,0 +1,63 @@ +/* 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); + } + } +} diff --git a/sway/desktop/shaders/tex_external.frag b/sway/desktop/shaders/tex_external.frag deleted file mode 100644 index 9976eb51..00000000 --- a/sway/desktop/shaders/tex_external.frag +++ /dev/null @@ -1,37 +0,0 @@ -#extension GL_OES_EGL_image_external : require - -precision mediump float; -varying vec2 v_texcoord; -uniform samplerExternalOES texture0; -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); - -void main() { - vec4 color = texture2D(texture0, v_texcoord); - // Saturation - if (saturation != 1.0) { - vec4 pixColor = texture2D(texture0, 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_rgba.frag b/sway/desktop/shaders/tex_rgba.frag deleted file mode 100644 index b46885b2..00000000 --- a/sway/desktop/shaders/tex_rgba.frag +++ /dev/null @@ -1,35 +0,0 @@ -precision mediump float; -varying vec2 v_texcoord; -uniform sampler2D tex; -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); - -void main() { - vec4 color = texture2D(tex, v_texcoord); - // 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_rgbx.frag b/sway/desktop/shaders/tex_rgbx.frag deleted file mode 100644 index 283963f2..00000000 --- a/sway/desktop/shaders/tex_rgbx.frag +++ /dev/null @@ -1,34 +0,0 @@ -precision mediump float; -varying vec2 v_texcoord; -uniform sampler2D tex; -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); - -void main() { - vec4 color = vec4(texture2D(tex, v_texcoord).rgb, 1.0); - // Saturation - if (saturation != 1.0) { - vec3 irgb = texture2D(tex, v_texcoord).rgb; - vec3 target = vec3(dot(irgb, saturation_weight)); - color = vec4(mix(target, irgb, saturation), 1.0); - } - // 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); - } - } -} -- cgit v1.2.3