From add17da988f4518c451abc4d0bacf536071e1c0b Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sun, 2 Jun 2024 22:37:52 +1000 Subject: directive-based color variants for materials --- source/rendering/StarTilePainter.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'source/rendering/StarTilePainter.cpp') diff --git a/source/rendering/StarTilePainter.cpp b/source/rendering/StarTilePainter.cpp index f9cff34..eef54b6 100644 --- a/source/rendering/StarTilePainter.cpp +++ b/source/rendering/StarTilePainter.cpp @@ -230,7 +230,7 @@ bool TilePainter::produceTerrainPrimitives(HashMappieceId, hue, mod), [&](auto const&) { - String texture; - if (hue == 0) - texture = piece->texture; - else - texture = strf("{}?hueshift={}", piece->texture, materialHueToDegrees(hue)); + AssetPath texture = (hue == 0) ? piece->texture : strf("{}?hueshift={}", piece->texture, materialHueToDegrees(hue)); + + if (directives) + texture.directives += *directives; return m_textureGroup->create(*assets->image(texture)); }); @@ -281,16 +280,20 @@ bool TilePainter::produceTerrainPrimitives(HashMapoccludesBehind; - + auto materialColorVariant = materialRenderProfile->colorVariants > 0 ? colorVariant % materialRenderProfile->colorVariants : 0; uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]), pos[1], (int)terrainLayer, "main"); auto& quadList = primitives[materialZLevel(materialRenderProfile->zLevel, material, materialHue, materialColorVariant)]; MaterialPieceResultList pieces; determineMatchingPieces(pieces, &occlude, materialDatabase, materialRenderProfile->mainMatchList, renderData, pos, terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, false); + Directives const* directives = materialRenderProfile->colorDirectives.empty() + ? nullptr + : &materialRenderProfile->colorDirectives.wrap(materialColorVariant); for (auto const& piecePair : pieces) { - TexturePtr texture = getPieceTexture(material, piecePair.first, materialHue, false); + TexturePtr texture = getPieceTexture(material, piecePair.first, materialHue, directives, false); auto variant = piecePair.first->variants.ptr(materialColorVariant); + if (!variant) variant = piecePair.first->variants.ptr(0); if (!variant) continue; RectF textureCoords = variant->wrap(variance); RectF worldCoords = RectF::withSize(piecePair.second / TilePixels + Vec2F(pos), textureCoords.size() / TilePixels); @@ -308,16 +311,20 @@ bool TilePainter::produceTerrainPrimitives(HashMapmultiColor ? materialColorVariant : 0; + auto modColorVariant = modRenderProfile->colorVariants > 0 ? colorVariant % modRenderProfile->colorVariants : 0; uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]), pos[1], (int)terrainLayer, "mod"); auto& quadList = primitives[modZLevel(modRenderProfile->zLevel, mod, modHue, modColorVariant)]; MaterialPieceResultList pieces; determineMatchingPieces(pieces, &occlude, materialDatabase, modRenderProfile->mainMatchList, renderData, pos, terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, true); + Directives const* directives = modRenderProfile->colorDirectives.empty() + ? nullptr + : &modRenderProfile->colorDirectives.wrap(modColorVariant); for (auto const& piecePair : pieces) { - auto texture = getPieceTexture(mod, piecePair.first, modHue, true); + auto texture = getPieceTexture(mod, piecePair.first, modHue, directives, true); auto variant = piecePair.first->variants.ptr(modColorVariant); + if (!variant) variant = piecePair.first->variants.ptr(0); if (!variant) continue; auto& textureCoords = variant->wrap(variance); RectF worldCoords = RectF::withSize(piecePair.second / TilePixels + Vec2F(pos), textureCoords.size() / TilePixels); -- cgit v1.2.3