Hyprland/src/render/shaders/glsl/border.frag

93 lines
2.8 KiB
GLSL
Raw Normal View History

#version 300 es
#extension GL_ARB_shading_language_include : enable
2022-06-26 19:39:56 +02:00
2024-02-15 17:32:27 +00:00
precision highp float;
in vec2 v_texcoord;
2022-11-26 20:36:05 +00:00
uniform vec2 fullSizeUntransformed;
uniform float radiusOuter;
2022-06-26 19:39:56 +02:00
uniform float thick;
// Gradients are in OkLabA!!!! {l, a, b, alpha}
2022-11-26 17:56:43 +00:00
uniform vec4 gradient[10];
uniform vec4 gradient2[10];
2022-11-26 17:56:43 +00:00
uniform int gradientLength;
uniform int gradient2Length;
2022-11-26 17:56:43 +00:00
uniform float angle;
uniform float angle2;
uniform float gradientLerp;
uniform float alpha;
2022-11-26 17:56:43 +00:00
#include "rounding.glsl"
#include "CM.glsl"
renderer: shader code refactor (#12926) * shader: begin the shader refactor make SShader a class and rename it to CShader, move createprogram, compileshader, logshadererror to CShader. * shader: move uniform creation to CShader move uniform creation to CShader, reduces tons of duplicated effort, however forcing uniform names to be same in all shaders. * shader: move to array based frag handling use an array with an enum so it gets easier dealing with multiple shaders, move creating program to a for loop and array, reduces line of code a lot. * shader: use shared ptr for frags with smart pointers we can now rename useProgram to useShader and return the shader directly, means only place we have to decide the shader frag is when calling useShader. easier for future shader splitting to reduce branching. * shader: move unneded public members to private move structs and uniforms to private add a get/set for initialtime and add a getUniformLocation to make the code tell what its doing, instead of direct array getting when all we wanted to get was its value, also limits the setting of uniformLocations to the createProgram as it should be. * shader: fix style nits set first enum member to 0 , remove extra {} * shader: dont show a failed notif on success the logic got inverted in the refactor here. * shader: split CM shader to rgba/rgbx variants split shader to rgba/rgbx variants, use bool, and reduce branching. * shader: split up blurprepare CM and non CM split up blurprepare, remove skipcm, move gain to gain.glsl. remove ternary operator and reduce branching by using step() and mix() use vec3 for gain, make brightness a cheap mulitplication with max. * shader: split up border to CM/noncm variants splitup border shader to CM/noncm variant, move common used things to border.glsl , there is room for optimisations here but its a complex shader im putting it for future PR. * shader: touchup blurfinish make brightness a cheap multiplication instead of branching. mod is redundant, fract in hash already returns a value in [0.0, 1.0]
2026-01-12 18:27:16 +01:00
#include "border.glsl"
layout(location = 0) out vec4 fragColor;
2022-11-21 18:09:47 +00:00
void main() {
highp vec2 pixCoord = vec2(gl_FragCoord);
highp vec2 pixCoordOuter = pixCoord;
highp vec2 originalPixCoord = v_texcoord;
originalPixCoord *= fullSizeUntransformed;
float additionalAlpha = 1.0;
2022-06-26 19:39:56 +02:00
vec4 pixColor = vec4(1.0, 1.0, 1.0, 1.0);
2022-06-26 19:39:56 +02:00
2022-11-21 18:09:47 +00:00
bool done = false;
2022-06-26 19:39:56 +02:00
2022-11-21 18:09:47 +00:00
pixCoord -= topLeft + fullSize * 0.5;
pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0;
pixCoordOuter = pixCoord;
2022-11-21 18:09:47 +00:00
pixCoord -= fullSize * 0.5 - radius;
pixCoordOuter -= fullSize * 0.5 - radiusOuter;
2022-06-26 19:39:56 +02:00
// center the pixes don't make it top-left
pixCoord += vec2(1.0, 1.0) / fullSize;
pixCoordOuter += vec2(1.0, 1.0) / fullSize;
2022-06-26 19:39:56 +02:00
if (min(pixCoord.x, pixCoord.y) > 0.0 && radius > 0.0) {
float dist = pow(pow(pixCoord.x,roundingPower)+pow(pixCoord.y,roundingPower),1.0/roundingPower);
float distOuter = pow(pow(pixCoordOuter.x,roundingPower)+pow(pixCoordOuter.y,roundingPower),1.0/roundingPower);
float h = (thick / 2.0);
2023-09-30 01:35:05 +01:00
if (dist < radius - h) {
// lower
float normalized = smoothstep(0.0, 1.0, (dist - radius + thick + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT * 2.0));
2023-09-30 01:35:05 +01:00
additionalAlpha *= normalized;
done = true;
} else if (min(pixCoordOuter.x, pixCoordOuter.y) > 0.0) {
2023-09-30 01:35:05 +01:00
// higher
float normalized = 1.0 - smoothstep(0.0, 1.0, (distOuter - radiusOuter + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT * 2.0));
2023-09-30 01:35:05 +01:00
additionalAlpha *= normalized;
done = true;
} else if (distOuter < radiusOuter - h) {
additionalAlpha = 1.0;
done = true;
2023-09-30 01:35:05 +01:00
}
2022-06-26 19:39:56 +02:00
}
// now check for other shit
if (!done) {
// distance to all straight bb borders
2022-11-21 18:09:47 +00:00
float distanceT = originalPixCoord[1];
2022-11-26 20:36:05 +00:00
float distanceB = fullSizeUntransformed[1] - originalPixCoord[1];
2022-11-21 18:09:47 +00:00
float distanceL = originalPixCoord[0];
2022-11-26 20:36:05 +00:00
float distanceR = fullSizeUntransformed[0] - originalPixCoord[0];
2022-06-26 19:39:56 +02:00
// get the smallest
float smallest = min(min(distanceT, distanceB), min(distanceL, distanceR));
2022-11-21 18:09:47 +00:00
if (smallest > thick)
discard;
2022-06-26 19:39:56 +02:00
}
2023-08-18 22:07:28 +02:00
if (additionalAlpha == 0.0)
2022-11-21 18:09:47 +00:00
discard;
2022-06-26 19:39:56 +02:00
2022-11-29 11:12:29 +00:00
pixColor = getColorForCoord(v_texcoord);
2023-08-18 22:07:28 +02:00
pixColor.rgb *= pixColor[3];
2023-08-18 22:07:28 +02:00
pixColor *= alpha * additionalAlpha;
fragColor = pixColor;
2022-06-26 19:39:56 +02:00
}