only run aa on corners

This commit is contained in:
jacob 2025-11-04 07:12:27 -06:00
parent 6a5cf09961
commit f825cc918c
2 changed files with 16 additions and 14 deletions

View File

@ -1963,8 +1963,6 @@ void PP_UpdateUser(void)
UI_Push(BorderColor, 0xff343a3b); UI_Push(BorderColor, 0xff343a3b);
UI_Push(Border, 1); UI_Push(Border, 1);
// UI_Size padding = UI_FILL(1, 0);
// UI_Size padding = UI_PIX(10, 0);
UI_Push(Width, UI_PIX(size.x, 0)); UI_Push(Width, UI_PIX(size.x, 0));
UI_Push(Height, UI_PIX(size.y, 0)); UI_Push(Height, UI_PIX(size.y, 0));

View File

@ -57,6 +57,8 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input)
Vec2 p0 = rect.p0; Vec2 p0 = rect.p0;
Vec2 p1 = rect.p1; Vec2 p1 = rect.p1;
b32 aa_enabled = 0;
/* Calculate rect sdf (negative means pixel is inside of rect) */ /* Calculate rect sdf (negative means pixel is inside of rect) */
f32 rect_dist = min(min(p.x - p0.x, p1.x - p.x), min(p.y - p0.y, p1.y - p.y)); f32 rect_dist = min(min(p.x - p0.x, p1.x - p.x), min(p.y - p0.y, p1.y - p.y));
{ {
@ -68,10 +70,10 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input)
Vec2 tr = Vec2(p1.x - tr_radius, p0.y + tr_radius); Vec2 tr = Vec2(p1.x - tr_radius, p0.y + tr_radius);
Vec2 br = Vec2(p1.x - br_radius, p1.y - br_radius); Vec2 br = Vec2(p1.x - br_radius, p1.y - br_radius);
Vec2 bl = Vec2(p0.x + bl_radius, p1.y - bl_radius); Vec2 bl = Vec2(p0.x + bl_radius, p1.y - bl_radius);
if (p.x < tl.x && p.y < tl.y) rect_dist = min(rect_dist, tl_radius - length(tl - p)); if (p.x < tl.x && p.y < tl.y) { rect_dist = min(rect_dist, tl_radius - length(tl - p)); aa_enabled = 1; }
if (p.x > tr.x && p.y < tr.y) rect_dist = min(rect_dist, tr_radius - length(tr - p)); if (p.x > tr.x && p.y < tr.y) { rect_dist = min(rect_dist, tr_radius - length(tr - p)); aa_enabled = 1; }
if (p.x > br.x && p.y > br.y) rect_dist = min(rect_dist, br_radius - length(br - p)); if (p.x > br.x && p.y > br.y) { rect_dist = min(rect_dist, br_radius - length(br - p)); aa_enabled = 1; }
if (p.x < bl.x && p.y > bl.y) rect_dist = min(rect_dist, bl_radius - length(bl - p)); if (p.x < bl.x && p.y > bl.y) { rect_dist = min(rect_dist, bl_radius - length(bl - p)); aa_enabled = 1; }
} }
rect_dist = -rect_dist; rect_dist = -rect_dist;
@ -97,7 +99,15 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input)
} }
} }
/* Background */ /* Calculate border blend from derivitive */
f32 border_dist_fwidth = fwidth(border_dist);
f32 border_blend = saturate(0.5 - border_dist / border_dist_fwidth);
if (!aa_enabled)
{
border_blend = border_dist <= 0;
}
/* Background color */
Vec4 background_color = 0; Vec4 background_color = 0;
{ {
if (rect_dist <= 0) if (rect_dist <= 0)
@ -116,13 +126,7 @@ UI_RectPS_Output PSDef(UI_RectPS, UI_RectPS_Input input)
} }
/* Final color */ /* Final color */
Vec4 final_color = 0; Vec4 final_color = lerp(background_color, border_color, border_blend);
{
f32 w = fwidth(border_dist);
f32 border_blend = saturate(0.5 - border_dist / w);
// f32 border_blend = 0;
final_color = lerp(background_color, border_color, border_blend);
}
final_color *= input.tint_lin; final_color *= input.tint_lin;
UI_RectPS_Output output; UI_RectPS_Output output;