Text edges cut off using clamp and point filtering

I rasterize TTF file text into a texture, and this looks fine. Below is the generated font texture.
![Font_0|500x500]

Then I use a fairly simple shader for text rendering, with VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE and VK_FILTER_NEAREST. However, the text edges seem to have issues. For example, look at the letters 'j', left part of 'L', and the right part of 'U' — many of them appear slightly cut off at the edges.

(upload://7oAXFfsSkugSoh7e01jZlDcdDdZ.png)

font texture

font texture

Do the texture coordinates on the quads you draw for each letter (I assume that’s how you do it?) take into account that texel centers are at 0.5/textureSize?

Some of what you see might also just be a side effect of using nearest filtering (especially the verticals of L and U looking thinner than expected) - if the fragment centers happen to be just a hair over to the left/right of the midpoint between two texels you’ll get the value there, which could be the blank part of the font atlas. Additionally, if minification happens (i.e. you are drawing the letters smaller than they are in the font atlas) I would expect this to be more noticable.

@carsten_neumann

Yes, I draw the text using a quad made of four vertices and two triangles. The UVs correspond exactly to the four corners of each letter in the atlas. it seems that with the nearest filter, the sampling slightly shifts toward the center, causing some letter edges to appear thinner than expected. Do you know how to fix this issue?

The size in pixels of your rendered quads must match exactly the corresponding size in the font atlas texture and the quads must be positioned such that the fragments produced by rasterizing them have UV coordinates that map one-to-one to font atlas texels (and ideally to the texel centers).