mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-15 09:46:00 +01:00
shaders: fixup jagged edges in texture rounded corners
This commit is contained in:
parent
d1638a09ba
commit
55ccb1a8cf
1 changed files with 7 additions and 4 deletions
|
@ -5,24 +5,27 @@
|
||||||
inline static constexpr auto ROUNDED_SHADER_FUNC = [](const std::string colorVarName) -> std::string {
|
inline static constexpr auto ROUNDED_SHADER_FUNC = [](const std::string colorVarName) -> std::string {
|
||||||
return R"#(
|
return R"#(
|
||||||
|
|
||||||
// branchless baby!
|
// shoutout me: I fixed this shader being a bit pixelated while watching hentai
|
||||||
|
|
||||||
highp vec2 pixCoord = vec2(gl_FragCoord);
|
highp vec2 pixCoord = vec2(gl_FragCoord);
|
||||||
pixCoord -= topLeft + fullSize * 0.5;
|
pixCoord -= topLeft + fullSize * 0.5;
|
||||||
pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0;
|
pixCoord *= vec2(lessThan(pixCoord, vec2(0.0))) * -2.0 + 1.0;
|
||||||
pixCoord -= fullSize * 0.5 - radius;
|
pixCoord -= fullSize * 0.5 - radius;
|
||||||
pixCoord += vec2(1.0, 1.0) / fullSize; // center the pix dont make it top-left
|
pixCoord += vec2(1.0, 1.0) / fullSize; // center the pix dont make it top-left
|
||||||
|
|
||||||
|
const float SMOOTHING_CONSTANT = 0.651724; // smoothing constant for the edge: more = blurrier, but smoother
|
||||||
|
|
||||||
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 + SMOOTHING_CONSTANT * 2.0)
|
||||||
discard;
|
discard;
|
||||||
|
|
||||||
if (dist > radius - 1.0) {
|
if (dist > radius - SMOOTHING_CONSTANT * 2.0) {
|
||||||
float dist = length(pixCoord);
|
float dist = length(pixCoord);
|
||||||
|
|
||||||
float normalized = 1.0 - smoothstep(0.0, 1.0, dist - radius + 0.5);
|
float normalized = 1.0 - smoothstep(0.0, 1.0, (dist - radius + SMOOTHING_CONSTANT) / (SMOOTHING_CONSTANT * 2.0));
|
||||||
|
|
||||||
)#" +
|
)#" +
|
||||||
colorVarName + R"#( = )#" + colorVarName + R"#( * normalized;
|
colorVarName + R"#( = )#" + colorVarName + R"#( * normalized;
|
||||||
|
|
Loading…
Reference in a new issue