mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-07 20:25:58 +01:00
Unify rounding shaders
This commit is contained in:
parent
be03a6186c
commit
c78db1212b
3 changed files with 67 additions and 76 deletions
|
@ -809,7 +809,7 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int round) {
|
||||||
RASSERT(m_RenderData.pMonitor, "Tried to render rect without begin()!");
|
RASSERT(m_RenderData.pMonitor, "Tried to render rect without begin()!");
|
||||||
|
|
||||||
if (!pixman_region32_not_empty(m_RenderData.pDamage) || (m_pCurrentWindow && m_pCurrentWindow->m_sAdditionalConfigData.forceNoBorder))
|
if (!pixman_region32_not_empty(m_RenderData.pDamage) || (m_pCurrentWindow && m_pCurrentWindow->m_sAdditionalConfigData.forceNoBorder))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
static auto *const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue;
|
static auto *const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue;
|
||||||
static auto *const PMULTISAMPLE = &g_pConfigManager->getConfigValuePtr("decoration:multisample_edges")->intValue;
|
static auto *const PMULTISAMPLE = &g_pConfigManager->getConfigValuePtr("decoration:multisample_edges")->intValue;
|
||||||
|
@ -860,12 +860,15 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int round) {
|
||||||
#endif
|
#endif
|
||||||
glUniform4f(m_RenderData.pCurrentMonData->m_shBORDER1.color, col.r / 255.f, col.g / 255.f, col.b / 255.f, col.a / 255.f);
|
glUniform4f(m_RenderData.pCurrentMonData->m_shBORDER1.color, col.r / 255.f, col.g / 255.f, col.b / 255.f, col.a / 255.f);
|
||||||
|
|
||||||
const auto TOPLEFT = Vector2D(round, round);
|
wlr_box transformedBox;
|
||||||
const auto BOTTOMRIGHT = Vector2D(box->width - round, box->height - round);
|
wlr_box_transform(&transformedBox, box, wlr_output_transform_invert(m_RenderData.pMonitor->transform),
|
||||||
const auto FULLSIZE = Vector2D(box->width, box->height);
|
m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y);
|
||||||
|
|
||||||
|
const auto TOPLEFT = Vector2D(transformedBox.x, transformedBox.y);
|
||||||
|
const auto FULLSIZE = Vector2D(transformedBox.width, transformedBox.height);
|
||||||
|
|
||||||
glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.topLeft, (float)TOPLEFT.x, (float)TOPLEFT.y);
|
glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.topLeft, (float)TOPLEFT.x, (float)TOPLEFT.y);
|
||||||
glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.bottomRight, (float)BOTTOMRIGHT.x, (float)BOTTOMRIGHT.y);
|
//glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.bottomRight, (float)BOTTOMRIGHT.x, (float)BOTTOMRIGHT.y);
|
||||||
glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.fullSize, (float)FULLSIZE.x, (float)FULLSIZE.y);
|
glUniform2f(m_RenderData.pCurrentMonData->m_shBORDER1.fullSize, (float)FULLSIZE.x, (float)FULLSIZE.y);
|
||||||
glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.radius, round);
|
glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.radius, round);
|
||||||
glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.thick, scaledBorderSize);
|
glUniform1f(m_RenderData.pCurrentMonData->m_shBORDER1.thick, scaledBorderSize);
|
||||||
|
@ -890,13 +893,13 @@ void CHyprOpenGLImpl::renderBorder(wlr_box* box, const CColor& col, int round) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pixman_region32_fini(&damageClip);
|
pixman_region32_fini(&damageClip);
|
||||||
} else {
|
} else {
|
||||||
PIXMAN_DAMAGE_FOREACH(m_RenderData.pDamage) {
|
PIXMAN_DAMAGE_FOREACH(m_RenderData.pDamage) {
|
||||||
const auto RECT = RECTSARR[i];
|
const auto RECT = RECTSARR[i];
|
||||||
scissor(&RECT);
|
scissor(&RECT);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib);
|
glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBORDER1.posAttrib);
|
||||||
|
|
|
@ -9,82 +9,70 @@ varying vec4 v_color;
|
||||||
varying vec2 v_texcoord;
|
varying vec2 v_texcoord;
|
||||||
|
|
||||||
uniform vec2 topLeft;
|
uniform vec2 topLeft;
|
||||||
uniform vec2 bottomRight;
|
|
||||||
uniform vec2 fullSize;
|
uniform vec2 fullSize;
|
||||||
uniform float radius;
|
uniform float radius;
|
||||||
uniform float thick;
|
uniform float thick;
|
||||||
uniform int primitiveMultisample;
|
uniform int primitiveMultisample;
|
||||||
|
|
||||||
float getOpacityForPixAndCorner(vec2 pix, vec2 corner) {
|
|
||||||
|
|
||||||
if (primitiveMultisample == 0) {
|
|
||||||
float dis = distance(pix + vec2(0.5, 0.5), corner);
|
|
||||||
return dis < radius && dis > radius - thick ? 1.0 : 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float distance1 = distance(pix + vec2(0.25, 0.25), corner);
|
|
||||||
float distance2 = distance(pix + vec2(0.75, 0.25), corner);
|
|
||||||
float distance3 = distance(pix + vec2(0.25, 0.75), corner);
|
|
||||||
float distance4 = distance(pix + vec2(0.75, 0.75), corner);
|
|
||||||
|
|
||||||
float v1 = distance1 < radius && distance1 > radius - thick ? 1.0 : 0.0;
|
|
||||||
float v2 = distance2 < radius && distance2 > radius - thick ? 1.0 : 0.0;
|
|
||||||
float v3 = distance3 < radius && distance3 > radius - thick ? 1.0 : 0.0;
|
|
||||||
float v4 = distance4 < radius && distance4 > radius - thick ? 1.0 : 0.0;
|
|
||||||
|
|
||||||
return (v1 + v2 + v3 + v4) / 4.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
vec2 pixCoord = fullSize * v_texcoord;
|
highp vec2 pixCoord = vec2(gl_FragCoord);
|
||||||
|
vec2 originalPixCoord = fullSize * v_texcoord;
|
||||||
|
|
||||||
vec4 pixColor = v_color;
|
vec4 pixColor = v_color;
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
// check for edges
|
pixCoord -= topLeft + fullSize * 0.5;
|
||||||
if (pixCoord[0] < topLeft[0]) {
|
pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0;
|
||||||
if (pixCoord[1] < topLeft[1]) {
|
pixCoord -= fullSize * 0.5 - radius;
|
||||||
// top left
|
|
||||||
pixColor[3] = pixColor[3] * getOpacityForPixAndCorner(pixCoord, topLeft + vec2(1,1));
|
if (min(pixCoord.x, pixCoord.y) > 0.0) {
|
||||||
done = true;
|
|
||||||
} else if (pixCoord[1] > bottomRight[1]) {
|
float dist = length(pixCoord);
|
||||||
// bottom left
|
|
||||||
pixColor[3] = pixColor[3] * getOpacityForPixAndCorner(pixCoord, vec2(topLeft[0] + 1.0, bottomRight[1]));
|
if (dist > radius || dist < radius - thick - 1.0)
|
||||||
done = true;
|
discard;
|
||||||
}
|
|
||||||
} else if (pixCoord[0] > bottomRight[0]) {
|
if (primitiveMultisample == 1 && (dist > radius - 1.0 || dist < radius - thick + 1.0)) {
|
||||||
if (pixCoord[1] < topLeft[1]) {
|
float distances = 0.0;
|
||||||
// top right
|
float len = length(pixCoord + vec2(0.25, 0.25));
|
||||||
pixColor[3] = pixColor[3] * getOpacityForPixAndCorner(pixCoord, vec2(bottomRight[0], topLeft[1] + 1.0));
|
distances += float(len < radius && len > radius - thick);
|
||||||
done = true;
|
len = length(pixCoord + vec2(0.75, 0.25));
|
||||||
} else if (pixCoord[1] > bottomRight[1]) {
|
distances += float(len < radius && len > radius - thick);
|
||||||
// bottom right
|
len = length(pixCoord + vec2(0.25, 0.75));
|
||||||
pixColor[3] = pixColor[3] * getOpacityForPixAndCorner(pixCoord, bottomRight);
|
distances += float(len < radius && len > radius - thick);
|
||||||
done = true;
|
len = length(pixCoord + vec2(0.75, 0.75));
|
||||||
|
distances += float(len < radius && len > radius - thick);
|
||||||
|
|
||||||
|
if (distances == 0.0)
|
||||||
|
discard;
|
||||||
|
|
||||||
|
distances /= 4.0;
|
||||||
|
|
||||||
|
pixColor = pixColor * distances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// now check for other shit
|
// now check for other shit
|
||||||
if (!done) {
|
if (!done) {
|
||||||
// distance to all straight bb borders
|
// distance to all straight bb borders
|
||||||
float distanceT = pixCoord[1];
|
float distanceT = originalPixCoord[1];
|
||||||
float distanceB = fullSize[1] - pixCoord[1];
|
float distanceB = fullSize[1] - originalPixCoord[1];
|
||||||
float distanceL = pixCoord[0];
|
float distanceL = originalPixCoord[0];
|
||||||
float distanceR = fullSize[0] - pixCoord[0];
|
float distanceR = fullSize[0] - originalPixCoord[0];
|
||||||
|
|
||||||
// get the smallest
|
// get the smallest
|
||||||
float smallest = min(min(distanceT, distanceB), min(distanceL, distanceR));
|
float smallest = min(min(distanceT, distanceB), min(distanceL, distanceR));
|
||||||
|
|
||||||
if (smallest > thick) {
|
if (smallest > thick)
|
||||||
discard; return;
|
discard;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pixColor[3] == 0.0) {
|
if (pixColor[3] == 0.0)
|
||||||
discard; return;
|
discard;
|
||||||
}
|
|
||||||
|
|
||||||
gl_FragColor = pixColor;
|
gl_FragColor = pixColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,24 +13,24 @@ inline static constexpr auto ROUNDED_SHADER_FUNC = [](const std::string colorVar
|
||||||
|
|
||||||
if (pixCoord.x + pixCoord.y > radius) {
|
if (pixCoord.x + pixCoord.y > radius) {
|
||||||
|
|
||||||
float dist = length(pixCoord);
|
float dist = length(pixCoord);
|
||||||
|
|
||||||
if (dist > radius)
|
if (dist > radius)
|
||||||
discard;
|
discard;
|
||||||
|
|
||||||
if (primitiveMultisample == 1 && dist > radius - 1.0) {
|
if (primitiveMultisample == 1 && dist > radius - 1.0) {
|
||||||
float distances = 0.0;
|
float distances = 0.0;
|
||||||
distances += float(length(pixCoord + vec2(0.25, 0.25)) < radius);
|
distances += float(length(pixCoord + vec2(0.25, 0.25)) < radius);
|
||||||
distances += float(length(pixCoord + vec2(0.75, 0.25)) < radius);
|
distances += float(length(pixCoord + vec2(0.75, 0.25)) < radius);
|
||||||
distances += float(length(pixCoord + vec2(0.25, 0.75)) < radius);
|
distances += float(length(pixCoord + vec2(0.25, 0.75)) < radius);
|
||||||
distances += float(length(pixCoord + vec2(0.75, 0.75)) < radius);
|
distances += float(length(pixCoord + vec2(0.75, 0.75)) < radius);
|
||||||
|
|
||||||
if (distances == 0.0)
|
if (distances == 0.0)
|
||||||
discard;
|
discard;
|
||||||
|
|
||||||
distances /= 4.0;
|
distances /= 4.0;
|
||||||
|
|
||||||
)#" + colorVarName + R"#( = )#" + colorVarName + R"#( * distances;
|
)#" + colorVarName + R"#( = )#" + colorVarName + R"#( * distances;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue