Text rendering
Some checks failed
CI / React UI Build (push) Successful in 40s
CI / Native Windows Build And Tests (push) Failing after 2m28s
CI / Windows Release Package (push) Has been skipped

This commit is contained in:
2026-05-21 15:39:37 +10:00
parent 09efe2d6a0
commit df0a77ef01
8 changed files with 107 additions and 52 deletions

View File

@@ -53,7 +53,8 @@ std::string BuildParameterUniforms(const std::vector<ShaderParameterDefinition>&
{
if (definition.type == ShaderParameterType::Text)
{
source << "\tfloat " << definition.id << "TextureWidthScale;\n";
source << "\tfloat " << definition.id << "TextureActiveWidthScale;\n";
source << "\tfloat " << definition.id << "TextureAspect;\n";
continue;
}
if (definition.type == ShaderParameterType::Trigger)
@@ -102,17 +103,36 @@ std::string BuildTextSamplerDeclarations(const std::vector<ShaderParameterDefini
std::string BuildTextHelpers(const std::vector<ShaderParameterDefinition>& parameters)
{
std::ostringstream source;
bool emittedMedian = false;
for (const ShaderParameterDefinition& definition : parameters)
{
if (definition.type != ShaderParameterType::Text)
continue;
if (!emittedMedian)
{
source
<< "float median(float r, float g, float b)\n"
<< "{\n"
<< "\treturn max(min(r, g), min(max(r, g), b));\n"
<< "}\n\n";
emittedMedian = true;
}
const std::string suffix = CapitalizeIdentifier(definition.id);
source
<< "float sample" << suffix << "(float2 uv)\n"
<< "float4 sample" << suffix << "Mtsdf(float2 uv)\n"
<< "{\n"
<< "\tif (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0)\n"
<< "\t\treturn 0.0;\n"
<< "\treturn " << definition.id << "Texture.Sample(float2(uv.x * " << definition.id << "TextureWidthScale, uv.y)).r;\n"
<< "\t\treturn float4(0.0, 0.0, 0.0, 0.0);\n"
<< "\treturn " << definition.id << "Texture.Sample(float2(uv.x * " << definition.id << "TextureActiveWidthScale, uv.y));\n"
<< "}\n\n"
<< "float sample" << suffix << "Msdf(float2 uv)\n"
<< "{\n"
<< "\tfloat4 mtsdf = sample" << suffix << "Mtsdf(uv);\n"
<< "\treturn median(mtsdf.r, mtsdf.g, mtsdf.b);\n"
<< "}\n\n"
<< "float sample" << suffix << "(float2 uv)\n"
<< "{\n"
<< "\treturn sample" << suffix << "Mtsdf(uv).a;\n"
<< "}\n\n"
<< "float4 draw" << suffix << "(float2 uv, float4 fillColor)\n"
<< "{\n"