summaryrefslogtreecommitdiff
path: root/include/sway/desktop/shaders.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/sway/desktop/shaders.h')
-rw-r--r--include/sway/desktop/shaders.h173
1 files changed, 29 insertions, 144 deletions
diff --git a/include/sway/desktop/shaders.h b/include/sway/desktop/shaders.h
index 70e8e960..c1871aaf 100644
--- a/include/sway/desktop/shaders.h
+++ b/include/sway/desktop/shaders.h
@@ -43,57 +43,19 @@ const GLchar tex_fragment_src_rgba[] =
"uniform sampler2D tex;\n"
"uniform float alpha;\n"
"\n"
-"uniform vec2 topLeft;\n"
-"uniform vec2 bottomRight;\n"
-"uniform vec2 fullSize;\n"
+"uniform float width;\n"
+"uniform float height;\n"
+"uniform vec2 position;\n"
"uniform float radius;\n"
"\n"
-"uniform int discardOpaque;\n"
-"\n"
"void main() {\n"
-" vec4 pixColor = texture2D(tex, v_texcoord);\n"
-"\n"
-" if (discardOpaque == 1 && pixColor[3] * alpha == 1.0) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-"\n"
-" vec2 pixCoord = fullSize * v_texcoord;\n"
-"\n"
-" if (pixCoord[0] < topLeft[0]) {\n"
-" // we're close left\n"
-" if (pixCoord[1] < topLeft[1]) {\n"
- // top
-" if (distance(topLeft, pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" } else if (pixCoord[1] > bottomRight[1]) {\n"
- // bottom
-" if (distance(vec2(topLeft[0], bottomRight[1]), pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" }\n"
-" }\n"
-" else if (pixCoord[0] > bottomRight[0]) {\n"
- // we're close right
-" if (pixCoord[1] < topLeft[1]) {\n"
- // top
-" if (distance(vec2(bottomRight[0], topLeft[1]), pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" } else if (pixCoord[1] > bottomRight[1]) {\n"
- // bottom
-" if (distance(bottomRight, pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" gl_FragColor = pixColor * alpha;\n"
+" gl_FragColor = texture2D(tex, v_texcoord) * alpha;\n"
+" vec2 corner_distance = min(gl_FragCoord.xy - position, position + vec2(width, height) - gl_FragCoord.xy);\n"
+" if (max(corner_distance.x, corner_distance.y) < radius) {\n"
+" float d = radius - distance(corner_distance, vec2(radius, radius));\n"
+" float smooth = smoothstep(-1.0f, 1.0f, d);\n"
+" gl_FragColor = mix(vec4(0), gl_FragColor, smooth);\n"
+" }\n"
"}\n";
const GLchar tex_fragment_src_rgbx[] =
@@ -102,56 +64,19 @@ const GLchar tex_fragment_src_rgbx[] =
"uniform sampler2D tex;\n"
"uniform float alpha;\n"
"\n"
-"uniform vec2 topLeft;\n"
-"uniform vec2 bottomRight;\n"
-"uniform vec2 fullSize;\n"
+"uniform float width;\n"
+"uniform float height;\n"
+"uniform vec2 position;\n"
"uniform float radius;\n"
"\n"
-"uniform int discardOpaque;\n"
-"\n"
"void main() {\n"
-"\n"
-" if (discardOpaque == 1 && alpha == 1.0) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-"\n"
-" vec2 pixCoord = fullSize * v_texcoord;\n"
-"\n"
-" if (pixCoord[0] < topLeft[0]) {\n"
- // we're close left
-" if (pixCoord[1] < topLeft[1]) {\n"
- // top
-" if (distance(topLeft, pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" } else if (pixCoord[1] > bottomRight[1]) {\n"
- // bottom
-" if (distance(vec2(topLeft[0], bottomRight[1]), pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" }\n"
-" }\n"
-" else if (pixCoord[0] > bottomRight[0]) {\n"
- // we're close right
-" if (pixCoord[1] < topLeft[1]) {\n"
- // top
-" if (distance(vec2(bottomRight[0], topLeft[1]), pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" } else if (pixCoord[1] > bottomRight[1]) {\n"
- // bottom
-" if (distance(bottomRight, pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
" gl_FragColor = vec4(texture2D(tex, v_texcoord).rgb, 1.0) * alpha;\n"
+" vec2 corner_distance = min(gl_FragCoord.xy - position, position + vec2(width, height) - gl_FragCoord.xy);\n"
+" if (max(corner_distance.x, corner_distance.y) < radius) {\n"
+" float d = radius - distance(corner_distance, vec2(radius, radius));\n"
+" float smooth = smoothstep(-1.0f, 1.0f, d);\n"
+" gl_FragColor = mix(vec4(0), gl_FragColor, smooth);\n"
+" }\n"
"}\n";
const GLchar tex_fragment_src_external[] =
@@ -161,58 +86,19 @@ const GLchar tex_fragment_src_external[] =
"uniform samplerExternalOES texture0;\n"
"uniform float alpha;\n"
"\n"
-"uniform vec2 topLeft;\n"
-"uniform vec2 bottomRight;\n"
-"uniform vec2 fullSize;\n"
+"uniform float width;\n"
+"uniform float height;\n"
+"uniform vec2 position;\n"
"uniform float radius;\n"
"\n"
-"uniform int discardOpaque;\n"
-"\n"
"void main() {\n"
-"\n"
-" vec4 pixColor = texture2D(texture0, v_texcoord);\n"
-"\n"
-" if (discardOpaque == 1 && pixColor[3] * alpha == 1.0) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-"\n"
-" vec2 pixCoord = fullSize * v_texcoord;\n"
-"\n"
-" if (pixCoord[0] < topLeft[0]) {\n"
- // we're close left
-" if (pixCoord[1] < topLeft[1]) {\n"
- // top
-" if (distance(topLeft, pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" } else if (pixCoord[1] > bottomRight[1]) {\n"
- // bottom
-" if (distance(vec2(topLeft[0], bottomRight[1]), pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" }\n"
-" }\n"
-" else if (pixCoord[0] > bottomRight[0]) {\n"
- // we're close right
-" if (pixCoord[1] < topLeft[1]) {\n"
- // top
-" if (distance(vec2(bottomRight[0], topLeft[1]), pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" } else if (pixCoord[1] > bottomRight[1]) {\n"
- // bottom
-" if (distance(bottomRight, pixCoord) > radius) {\n"
-" discard;\n"
-" return;\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" gl_FragColor = pixColor * alpha;\n"
+" gl_FragColor = texture2D(texture0, v_texcoord) * alpha;\n"
+" vec2 corner_distance = min(gl_FragCoord.xy - position, position + vec2(width, height) - gl_FragCoord.xy);\n"
+" if (max(corner_distance.x, corner_distance.y) < radius) {\n"
+" float d = radius - distance(corner_distance, vec2(radius, radius));\n"
+" float smooth = smoothstep(-1.0f, 1.0f, d);\n"
+" gl_FragColor = mix(vec4(0), gl_FragColor, smooth);\n"
+" }\n"
"}\n";
const GLchar frag_blur_1[] =
@@ -259,4 +145,3 @@ const GLchar frag_blur_2[] =
"}\n";
#endif
-