Fix text outline render order

This commit is contained in:
SirLynix 2023-02-26 13:46:19 +01:00
parent 6df919eb70
commit 5e6a20f479
3 changed files with 8 additions and 4 deletions

View File

@ -315,8 +315,10 @@ namespace Nz
m_defaultMaterials.basicTransparent = m_defaultMaterials.basicMaterial->Instantiate(); m_defaultMaterials.basicTransparent = m_defaultMaterials.basicMaterial->Instantiate();
m_defaultMaterials.basicTransparent->DisablePass(depthPassIndex); m_defaultMaterials.basicTransparent->DisablePass(depthPassIndex);
m_defaultMaterials.basicTransparent->DisablePass(shadowPassIndex); m_defaultMaterials.basicTransparent->DisablePass(shadowPassIndex);
m_defaultMaterials.basicTransparent->UpdatePassFlags(forwardPassIndex, MaterialPassFlag::SortByDistance);
m_defaultMaterials.basicTransparent->UpdatePassStates(forwardPassIndex, [](RenderStates& renderStates) m_defaultMaterials.basicTransparent->UpdatePassStates(forwardPassIndex, [](RenderStates& renderStates)
{ {
renderStates.depthBuffer = true;
renderStates.depthWrite = false; renderStates.depthWrite = false;
renderStates.blending = true; renderStates.blending = true;
renderStates.blend.modeColor = BlendEquation::Add; renderStates.blend.modeColor = BlendEquation::Add;

View File

@ -19,7 +19,7 @@ namespace Nz
m_material(std::move(material)) m_material(std::move(material))
{ {
if (!m_material) if (!m_material)
m_material = Graphics::Instance()->GetDefaultMaterials().basicTransparent->Clone(); m_material = Graphics::Instance()->GetDefaultMaterials().basicTransparent;
} }
void TextSprite::BuildElement(ElementRendererRegistry& registry, const ElementData& elementData, std::size_t passIndex, std::vector<RenderElementOwner>& elements) const void TextSprite::BuildElement(ElementRendererRegistry& registry, const ElementData& elementData, std::size_t passIndex, std::vector<RenderElementOwner>& elements) const
@ -44,7 +44,7 @@ namespace Nz
RenderIndices& indices = pair.second; RenderIndices& indices = pair.second;
if (indices.count > 0) if (indices.count > 0)
elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer(), m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, key.texture->shared_from_this(), indices.count, &m_vertices[indices.first * 4], *elementData.scissorBox)); elements.emplace_back(registry.AllocateElement<RenderSpriteChain>(GetRenderLayer() + key.renderOrder, m_material, passFlags, renderPipeline, *elementData.worldInstance, vertexDeclaration, key.texture->shared_from_this(), indices.count, &m_vertices[indices.first * 4], *elementData.scissorBox));
} }
} }

View File

@ -226,8 +226,10 @@ namespace Nz
Glyph glyph; Glyph glyph;
if (!whitespace) if (!whitespace)
{ {
int glyphRenderOrder = (m_outlineThickness > 0.f) ? 1 : 0;
int iAdvance; int iAdvance;
if (!GenerateGlyph(glyph, character, 0.f, true, m_color, 0, &iAdvance)) if (!GenerateGlyph(glyph, character, 0.f, true, m_color, glyphRenderOrder, &iAdvance))
continue; // Glyph failed to load, just skip it (can't do much) continue; // Glyph failed to load, just skip it (can't do much)
advance += float(iAdvance); advance += float(iAdvance);
@ -235,7 +237,7 @@ namespace Nz
if (m_outlineThickness > 0.f) if (m_outlineThickness > 0.f)
{ {
Glyph outlineGlyph; Glyph outlineGlyph;
if (GenerateGlyph(outlineGlyph, character, m_outlineThickness, false, m_outlineColor, -1, nullptr)) if (GenerateGlyph(outlineGlyph, character, m_outlineThickness, false, m_outlineColor, glyphRenderOrder - 1, nullptr))
m_glyphs.push_back(outlineGlyph); m_glyphs.push_back(outlineGlyph);
} }
} }