Fix regular image display.

This commit is contained in:
Skyth 2024-12-11 17:22:28 +03:00
parent bdebd6408f
commit 1282c1384e
3 changed files with 24 additions and 8 deletions

View file

@ -195,14 +195,15 @@ static bool FontBuilder_Build(ImFontAtlas* atlas)
}
for (auto& glyph : glyphs)
glyph.edgeColoring(&msdfgen::edgeColoringInkTrap, 3.0, 0);
glyph.edgeColoring(&msdfgen::edgeColoringByDistance, 3.0, 0);
for (auto& customRect : atlas->CustomRects)
customRects.emplace_back(0, 0, int(customRect.Width), int(customRect.Height));
TightAtlasPacker packer;
packer.spacing = 1;
packer.minScale = 16.0;
packer.dimensionsConstraint = msdf_atlas::DimensionsConstraint::POWER_OF_TWO_RECTANGLE;
packer.minScale = 24.0;
packer.miterLimit = 1.0;
packer.pxRange = 4.0;
packer.pack(glyphs.data(), glyphs.size(), customRects.data(), customRects.size());

View file

@ -73,10 +73,15 @@ float4 PixelAntialiasing(float2 uvTexspace)
return SampleLinear(uvTexspace);
}
uint GetTexture2DDescriptorIndex()
{
return g_PushConstants.Texture2DDescriptorIndex & 0x7FFFFFFF;
}
float ComputeScreenPixelRange(float2 texCoord)
{
uint width, height;
g_Texture2DDescriptorHeap[g_PushConstants.Texture2DDescriptorIndex].GetDimensions(width, height);
g_Texture2DDescriptorHeap[GetTexture2DDescriptorIndex()].GetDimensions(width, height);
float2 unitRange = 4.0 / float2(width, height);
float2 screenTextureSize = 1.0 / fwidth(texCoord);
@ -95,11 +100,18 @@ float4 main(in Interpolators interpolators) : SV_Target
if (g_PushConstants.Texture2DDescriptorIndex != 0)
{
float4 msd = g_Texture2DDescriptorHeap[g_PushConstants.Texture2DDescriptorIndex].Sample(g_SamplerDescriptorHeap[0], interpolators.UV);
float sd = median(msd.r, msd.g, msd.b) - 0.5;
float screenPixelDistance = ComputeScreenPixelRange(interpolators.UV) * sd;
color.a *= saturate(screenPixelDistance + 0.5);
color.a *= msd.a;
float4 texture = g_Texture2DDescriptorHeap[GetTexture2DDescriptorIndex()].Sample(g_SamplerDescriptorHeap[0], interpolators.UV);
if ((g_PushConstants.Texture2DDescriptorIndex & 0x80000000) != 0)
{
float sd = median(texture.r, texture.g, texture.b) - 0.5;
float screenPixelDistance = ComputeScreenPixelRange(interpolators.UV) * sd;
color.a *= saturate(screenPixelDistance + 0.5);
color.a *= texture.a;
}
else
{
color *= texture;
}
}
if (g_PushConstants.ShaderModifier == IMGUI_SHADER_MODIFIER_MARQUEE_FADE)

View file

@ -1953,6 +1953,9 @@ static void ProcDrawImGui(const RenderCommand& cmd)
}
descriptorIndex = texture->descriptorIndex;
if (texture == g_imFontTexture.get())
descriptorIndex |= 0x80000000;
}
commandList->setGraphicsPushConstants(0, &descriptorIndex, offsetof(ImGuiPushConstants, texture2DDescriptorIndex), sizeof(descriptorIndex));