diff --git a/shaders/text-overlay/shader.slang b/shaders/text-overlay/shader.slang index 3434c7b..61f268d 100644 --- a/shaders/text-overlay/shader.slang +++ b/shaders/text-overlay/shader.slang @@ -38,12 +38,14 @@ float4 shadeVideo(ShaderContext context) float2 pixelTextUv = (1.0 / resolution) / safeTextSize; float2 sampleOffset = pixelTextUv * 0.38; float msdfDistance = sampleTitleTextMsdf(textUv); - float fill = ( + float msdfFill = ( coverage(msdfDistance, edge, aa) * 2.0 + coverage(sampleTitleTextMsdf(textUv + float2(sampleOffset.x, sampleOffset.y)), edge, aa) + coverage(sampleTitleTextMsdf(textUv + float2(-sampleOffset.x, sampleOffset.y)), edge, aa) + coverage(sampleTitleTextMsdf(textUv + float2(sampleOffset.x, -sampleOffset.y)), edge, aa) + coverage(sampleTitleTextMsdf(textUv + float2(-sampleOffset.x, -sampleOffset.y)), edge, aa)) / 6.0; + float sdfFill = coverage(distance, edge, aa); + float fill = min(msdfFill, sdfFill); float outlineEdge = edge - min(outlineWidth * 0.7, 0.48); float outline = coverage(distance, outlineEdge, aa); float outlineAlpha = saturate(outline - fill) * outlineColor.a; diff --git a/src/runtime/text/RuntimeTextTextureComposer.cpp b/src/runtime/text/RuntimeTextTextureComposer.cpp index 5ed814d..6f8e6c6 100644 --- a/src/runtime/text/RuntimeTextTextureComposer.cpp +++ b/src/runtime/text/RuntimeTextTextureComposer.cpp @@ -83,6 +83,13 @@ void SampleAtlasPixel(const FontAtlasBuildOutput& atlas, double x, double y, uns } } +double GlyphAtlasCoordinate(double minBound, double maxBound, double uv) +{ + if (maxBound - minBound <= 1.0) + return (minBound + maxBound) * 0.5; + return minBound + 0.5 + uv * ((maxBound - 0.5) - (minBound + 0.5)); +} + std::vector ComposeTextTexture( const FontAtlasBuildOutput& atlas, const ShaderParameterDefinition& definition, @@ -135,8 +142,8 @@ std::vector ComposeTextTexture( if (x < 0 || x >= static_cast(width)) continue; const double u = (static_cast(x) + 0.5 - destLeft) / destWidth; - const double atlasX = glyph.atlasLeft + u * (glyph.atlasRight - glyph.atlasLeft); - const double atlasY = glyph.atlasTop + v * (glyph.atlasBottom - glyph.atlasTop); + const double atlasX = GlyphAtlasCoordinate(glyph.atlasLeft, glyph.atlasRight, u); + const double atlasY = GlyphAtlasCoordinate(glyph.atlasTop, glyph.atlasBottom, v); unsigned char sample[4] = {}; SampleAtlasPixel(atlas, atlasX, atlasY, sample); unsigned char* destination = texturePixels.data() + (static_cast(y) * width + static_cast(x)) * 4u;