From 64adc2865805dc79de709e8a38a41bdb505fb662 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:29:43 +1000 Subject: [PATCH] fix the very last material color variant not displaying --- source/game/StarMaterialRenderProfile.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/source/game/StarMaterialRenderProfile.cpp b/source/game/StarMaterialRenderProfile.cpp index 1272e83..f25913d 100644 --- a/source/game/StarMaterialRenderProfile.cpp +++ b/source/game/StarMaterialRenderProfile.cpp @@ -80,7 +80,7 @@ MaterialRenderProfile parseMaterialRenderProfile(Json const& spec, String const& bool lightTransparent = spec.getBool("lightTransparent", false); profile.foregroundLightTransparent = spec.getBool("foregroundLightTransparent", lightTransparent); profile.backgroundLightTransparent = spec.getBool("backgroundLightTransparent", lightTransparent); - profile.colorVariants = spec.getBool("multiColored", false) ? spec.getUInt("colorVariants", MaxMaterialColorVariant) : 0; + profile.colorVariants = spec.getBool("multiColored", false) ? spec.getUInt("colorVariants", (uint64_t)MaxMaterialColorVariant + 1) : 0; for (auto& entry : spec.getArray("colorDirectives", JsonArray())) profile.colorDirectives.append(entry.toString()); profile.occludesBehind = spec.getBool("occludesBelow", true); @@ -128,14 +128,12 @@ MaterialRenderProfile parseMaterialRenderProfile(Json const& spec, String const& auto flipTextureCoordinates = [imageHeight]( RectF const& rect) { return RectF::withSize(Vec2F(rect.xMin(), imageHeight - rect.yMax()), rect.size()); }; for (unsigned v = 0; v < variants; ++v) { - if (profile.colorVariants > 0) { - for (MaterialColorVariant c = 0; c <= profile.colorVariants; ++c) { - RectF textureRect = RectF::withSize(texturePosition + variantStride * v + colorStride * c, textureSize); - renderPiece->variants[c].append(flipTextureCoordinates(textureRect)); - } - } else { - RectF textureRect = RectF::withSize(texturePosition + variantStride * v, textureSize); - renderPiece->variants[DefaultMaterialColorVariant].append(flipTextureCoordinates(textureRect)); + auto i = DefaultMaterialColorVariant; + RectF textureRect = RectF::withSize(texturePosition + variantStride * v, textureSize); + renderPiece->variants[i].append(flipTextureCoordinates(textureRect)); + for (MaterialColorVariant c = 0; c != profile.colorVariants; ++c) { + RectF textureRect = RectF::withSize(texturePosition + variantStride * v + colorStride * ++i, textureSize); + renderPiece->variants[i].append(flipTextureCoordinates(textureRect)); } }