Add dithering for gradients

This commit is contained in:
2026-03-04 00:48:02 -05:00
parent b01fa2261a
commit 5aa0d7466e
3 changed files with 10 additions and 2 deletions

View File

@@ -148,6 +148,10 @@ float4 PSMain(PSInput input) : SV_TARGET {
} }
} }
// Dither to reduce gradient banding (interleaved gradient noise)
float dither = frac(52.9829189 * frac(dot(input.pos.xy, float2(0.06711056, 0.00583715)))) - 0.5;
col.rgb += dither / 255.0;
if (col.a < 0.002) discard; if (col.a < 0.002) discard;
return col; return col;
} }

View File

@@ -133,6 +133,10 @@ fragment float4 fragment_main(Fragment in [[stage_in]],
} }
} }
// Dither to reduce gradient banding (interleaved gradient noise)
float dither = fract(52.9829189 * fract(dot(in.pos.xy, float2(0.06711056, 0.00583715)))) - 0.5;
col.rgb += dither / 255.0;
if (col.a < 0.002) discard_fragment(); if (col.a < 0.002) discard_fragment();
return col; return col;
} }

View File

@@ -268,7 +268,7 @@ B32 ui_button(const char *id, const char *text) {
CLAY(eid, CLAY(eid,
.layout = { .layout = {
.sizing = { .width = CLAY_SIZING_FIT(), .height = CLAY_SIZING_FIXED(WIDGET_BUTTON_HEIGHT) }, .sizing = { .width = CLAY_SIZING_FIT(), .height = CLAY_SIZING_FIXED(WIDGET_BUTTON_HEIGHT) },
.padding = { uip(12), uip(12), 0, 0 }, .padding = { uip(12), uip(12), uip(1), 0 },
.childAlignment = { .y = CLAY_ALIGN_Y_CENTER }, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER },
}, },
.backgroundColor = base, .backgroundColor = base,
@@ -1099,7 +1099,7 @@ S32 ui_modal(const char *id, const char *title, const char *message,
CLAY(btn_id, CLAY(btn_id,
.layout = { .layout = {
.sizing = { .width = CLAY_SIZING_FIT(), .height = CLAY_SIZING_FIXED(WIDGET_BUTTON_HEIGHT) }, .sizing = { .width = CLAY_SIZING_FIT(), .height = CLAY_SIZING_FIXED(WIDGET_BUTTON_HEIGHT) },
.padding = { uip(16), uip(16), 0, 0 }, .padding = { uip(16), uip(16), uip(1), 0 },
.childAlignment = { .y = CLAY_ALIGN_Y_CENTER }, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER },
}, },
.backgroundColor = mbtn_base, .backgroundColor = mbtn_base,