V1 text, needs improvements
This commit is contained in:
@@ -205,6 +205,9 @@ std::vector<unsigned char> BuildLocalSdf(const std::vector<unsigned char>& alpha
|
||||
const float distance = std::sqrt(static_cast<float>(bestDistanceSq));
|
||||
const float signedDistance = (inside ? 1.0f : -1.0f) * distance;
|
||||
float normalized = 0.5f + signedDistance / static_cast<float>(kTextSdfSpread * 2);
|
||||
const unsigned char sourceAlpha = alpha[static_cast<std::size_t>(y) * width + x];
|
||||
if (sourceAlpha > 0 && sourceAlpha < 255)
|
||||
normalized = static_cast<float>(sourceAlpha) / 255.0f;
|
||||
if (normalized < 0.0f)
|
||||
normalized = 0.0f;
|
||||
if (normalized > 1.0f)
|
||||
@@ -220,6 +223,24 @@ std::vector<unsigned char> BuildLocalSdf(const std::vector<unsigned char>& alpha
|
||||
return sdf;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> BuildTextCoverageTexture(const std::vector<unsigned char>& alpha, unsigned width, unsigned height)
|
||||
{
|
||||
std::vector<unsigned char> coverage(static_cast<std::size_t>(width) * height * 4, 0);
|
||||
for (unsigned y = 0; y < height; ++y)
|
||||
{
|
||||
for (unsigned x = 0; x < width; ++x)
|
||||
{
|
||||
const unsigned char value = alpha[static_cast<std::size_t>(y) * width + x];
|
||||
const std::size_t out = (static_cast<std::size_t>(y) * width + x) * 4;
|
||||
coverage[out + 0] = value;
|
||||
coverage[out + 1] = value;
|
||||
coverage[out + 2] = value;
|
||||
coverage[out + 3] = value;
|
||||
}
|
||||
}
|
||||
return coverage;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> FlipTextTextureForShaderUv(const std::vector<unsigned char>& pixels, unsigned width, unsigned height)
|
||||
{
|
||||
std::vector<unsigned char> flipped(pixels.size(), 0);
|
||||
@@ -414,7 +435,7 @@ bool RasterizeTextSdf(const std::string& text, const std::filesystem::path& font
|
||||
alpha[static_cast<std::size_t>(y) * kTextTextureWidth + x] = static_cast<unsigned char>(luminance);
|
||||
}
|
||||
}
|
||||
sdf = BuildLocalSdf(alpha, kTextTextureWidth, kTextTextureHeight);
|
||||
sdf = BuildTextCoverageTexture(alpha, kTextTextureWidth, kTextTextureHeight);
|
||||
sdf = BlurTextSdf(sdf, kTextTextureWidth, kTextTextureHeight, kTextSdfBlurPasses);
|
||||
sdf = FlipTextTextureForShaderUv(sdf, kTextTextureWidth, kTextTextureHeight);
|
||||
WriteTextMaskDebugDump(text, alpha, sdf, kTextTextureWidth, kTextTextureHeight);
|
||||
|
||||
Reference in New Issue
Block a user