From 564a3abbf4247bd0658b8d4eb8a4881fa274e309 Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 7 Nov 2022 18:15:29 -0800 Subject: Fix font clipping bug When fonts completely fill a slot, any pixel touching a perimeter border gets stretched due to clamping. To avoid this, add a 2% margin around each slot. --- TaSTT.shader | 18 ++++++++++++++---- generate.py | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/TaSTT.shader b/TaSTT.shader index 4ea7e99..d4f4faf 100644 --- a/TaSTT.shader +++ b/TaSTT.shader @@ -786,10 +786,20 @@ int CHAR_COLS = 44; // OK, I know what cell I'm in. Now I need to know how far across it I - // am. Produce a float in the range [0, CHAR_COLS). + // am. Produce a float in the range [0, 1). float CHAR_FRAC_COL = uv.x * CHAR_COLS - floor(uv.x * CHAR_COLS); float CHAR_FRAC_ROW = uv.y * CHAR_ROWS - floor(uv.y * CHAR_ROWS); + // Avoid rendering pixels right on the edge of the slot. If we were to + // do this, then that value would get stretched due to clamping + // (AddMarginToUV), resulting in long lines on the edge of the display. + if (CHAR_FRAC_ROW < 0.01 || + CHAR_FRAC_COL < 0.01 || + CHAR_FRAC_ROW > 0.99 || + CHAR_FRAC_COL > 0.99) { + return float2(0, 0); + } + // This is the number of rows and columns in the actual texture. float LETTER_COLS = 128.0; float LETTER_ROWS = 64.0; @@ -797,8 +807,8 @@ float LETTER_COL = fmod(nth_letter, floor(LETTER_COLS)); float LETTER_ROW = floor(LETTER_ROWS) - floor(nth_letter / floor(LETTER_COLS)); - float LETTER_UV_ROW = (LETTER_ROW + CHAR_FRAC_ROW - 0.99) / LETTER_ROWS; - float LETTER_UV_COL = (LETTER_COL + CHAR_FRAC_COL - 0.01) / LETTER_COLS; + float LETTER_UV_ROW = (LETTER_ROW + CHAR_FRAC_ROW - 1.0) / LETTER_ROWS; + float LETTER_UV_COL = (LETTER_COL + CHAR_FRAC_COL) / LETTER_COLS; float2 result; result.x = LETTER_UV_COL; @@ -1229,7 +1239,7 @@ } float uv_x_margin = 0.03; - float uv_y_margin = 0.06; + float uv_y_margin = 0.03; uv = AddMarginToUV(uv, uv_x_margin, uv_y_margin); int2 letter_bytes = (int2) floor(GetLetterParameter(uv)); diff --git a/generate.py b/generate.py index 2c073bd..2442dc7 100644 --- a/generate.py +++ b/generate.py @@ -16,7 +16,7 @@ state.encoding = osc_ctrl.generateEncoding() osc_ctrl.clear(client) -i = 0xC000 +i = 0x3400 line = "" while True: for j in range(0, 256): -- cgit v1.2.3