Compare commits

..

No commits in common. "5f2990e6dc6e6b483975eaa4536ce222597b7692" and "135c7dd99969e6afcc6ee755e6aea6c80e3fb06d" have entirely different histories.

10 changed files with 54 additions and 104 deletions

View File

@ -121,7 +121,7 @@ private:
void buildString(String& string, const DirectivesGroup& directives) const; void buildString(String& string, const DirectivesGroup& directives) const;
List<Directives> m_directives; List<Directives> m_directives;
size_t m_count = 0; size_t m_count;
}; };
template <> template <>

View File

@ -714,7 +714,6 @@ void MainInterface::update(float dt) {
worldName = worldTemplate->worldName(); worldName = worldTemplate->worldName();
if (!worldName.empty()) { if (!worldName.empty()) {
m_planetText->parent()->setPosition(Vec2I(Vec2F(m_config->planetNameOffset) * (2.f / interfaceScale())));
m_planetText->setText(strf(m_config->planetNameFormatString.utf8Ptr(), worldName)); m_planetText->setText(strf(m_config->planetNameFormatString.utf8Ptr(), worldName));
m_paneManager.displayRegisteredPane(MainInterfacePanes::PlanetText); m_paneManager.displayRegisteredPane(MainInterfacePanes::PlanetText);
} }

View File

@ -89,12 +89,14 @@ inline LiquidSettingsConstPtr LiquidsDatabase::liquidSettings(LiquidId liquidId)
} }
inline Vec3F LiquidsDatabase::radiantLight(LiquidLevel level) const { inline Vec3F LiquidsDatabase::radiantLight(LiquidLevel level) const {
if (level.liquid < m_settings.size()) { if (level.liquid >= m_settings.size())
if (auto const& settings = m_settings[level.liquid]) return Vec3F();
return settings->radiantLightLevel * level.level;
}
return Vec3F(); auto const& settings = m_settings[level.liquid];
if (!settings)
return Vec3F();
return settings->radiantLightLevel * level.level;
} }
} }

View File

@ -402,31 +402,11 @@ ItemDescriptor MaterialDatabase::modItemDrop(ModId modId) const {
return {}; return {};
} }
MaterialColorVariant MaterialDatabase::materialColorVariants(MaterialId materialId) const {
if (isRealMaterial(materialId)) {
auto const& matInfo = getMaterialInfo(materialId);
if (matInfo->materialRenderProfile)
return matInfo->materialRenderProfile->colorVariants;
}
return 0;
}
MaterialColorVariant MaterialDatabase::modColorVariants(ModId modId) const {
if (isRealMod(modId)) {
auto const& modInfo = getModInfo(modId);
if (modInfo->modRenderProfile)
return modInfo->modRenderProfile->colorVariants;
}
return 0;
}
bool MaterialDatabase::isMultiColor(MaterialId materialId) const { bool MaterialDatabase::isMultiColor(MaterialId materialId) const {
if (isRealMaterial(materialId)) { if (isRealMaterial(materialId)) {
auto const& matInfo = getMaterialInfo(materialId); auto const& matInfo = getMaterialInfo(materialId);
if (matInfo->materialRenderProfile) if (matInfo->materialRenderProfile)
return matInfo->materialRenderProfile->colorVariants > 0; return matInfo->materialRenderProfile->multiColor;
} }
return false; return false;
@ -588,7 +568,7 @@ shared_ptr<MaterialDatabase::MaterialInfo const> const& MaterialDatabase::getMat
shared_ptr<MaterialDatabase::ModInfo const> const& MaterialDatabase::getModInfo(ModId modId) const { shared_ptr<MaterialDatabase::ModInfo const> const& MaterialDatabase::getModInfo(ModId modId) const {
if (modId >= m_mods.size() || !m_mods[modId]) if (modId >= m_mods.size() || !m_mods[modId])
throw MaterialException(strf("No such mod id: {}\n", modId)); throw MaterialException(strf("No such modId id: {}\n", modId));
else else
return m_mods[modId]; return m_mods[modId];
} }

View File

@ -69,8 +69,6 @@ public:
ItemDescriptor materialItemDrop(MaterialId materialId) const; ItemDescriptor materialItemDrop(MaterialId materialId) const;
ItemDescriptor modItemDrop(ModId modId) const; ItemDescriptor modItemDrop(ModId modId) const;
MaterialColorVariant materialColorVariants(MaterialId materialId) const;
MaterialColorVariant modColorVariants(ModId modId) const;
bool isMultiColor(MaterialId materialId) const; bool isMultiColor(MaterialId materialId) const;
bool foregroundLightTransparent(MaterialId materialId) const; bool foregroundLightTransparent(MaterialId materialId) const;
bool backgroundLightTransparent(MaterialId materialId) const; bool backgroundLightTransparent(MaterialId materialId) const;
@ -190,21 +188,15 @@ private:
}; };
inline MaterialRenderProfileConstPtr MaterialDatabase::materialRenderProfile(MaterialId materialId) const { inline MaterialRenderProfileConstPtr MaterialDatabase::materialRenderProfile(MaterialId materialId) const {
if (materialId < m_materials.size()) { if (materialId >= m_materials.size())
if (auto const& mat = m_materials[materialId]) return {};
return mat->materialRenderProfile; return m_materials[materialId]->materialRenderProfile;
}
return {};
} }
inline MaterialRenderProfileConstPtr MaterialDatabase::modRenderProfile(ModId modId) const { inline MaterialRenderProfileConstPtr MaterialDatabase::modRenderProfile(ModId modId) const {
if (modId < m_mods.size()) { if (modId >= m_mods.size())
if (auto const& mod = m_mods[modId]) return {};
return mod->modRenderProfile; return m_mods[modId]->modRenderProfile;
}
return {};
} }
inline bool MaterialDatabase::foregroundLightTransparent(MaterialId materialId) const { inline bool MaterialDatabase::foregroundLightTransparent(MaterialId materialId) const {
@ -247,13 +239,13 @@ inline Vec3F MaterialDatabase::radiantLight(MaterialId materialId, ModId modId)
Vec3F radiantLight; Vec3F radiantLight;
if (materialId < m_materials.size()) { if (materialId < m_materials.size()) {
auto const& mat = m_materials[materialId]; auto const& mat = m_materials[materialId];
if (mat && mat->materialRenderProfile) if (mat->materialRenderProfile)
radiantLight += mat->materialRenderProfile->radiantLight; radiantLight += mat->materialRenderProfile->radiantLight;
} }
if (modId < m_mods.size()) { if (modId < m_mods.size()) {
auto const& mod = m_mods[modId]; auto const& mat = m_mods[modId];
if (mod && mod->modRenderProfile) if (mat->modRenderProfile)
radiantLight += mod->modRenderProfile->radiantLight; radiantLight += mat->modRenderProfile->radiantLight;
} }
return radiantLight; return radiantLight;
} }

View File

@ -80,9 +80,7 @@ MaterialRenderProfile parseMaterialRenderProfile(Json const& spec, String const&
bool lightTransparent = spec.getBool("lightTransparent", false); bool lightTransparent = spec.getBool("lightTransparent", false);
profile.foregroundLightTransparent = spec.getBool("foregroundLightTransparent", lightTransparent); profile.foregroundLightTransparent = spec.getBool("foregroundLightTransparent", lightTransparent);
profile.backgroundLightTransparent = spec.getBool("backgroundLightTransparent", lightTransparent); profile.backgroundLightTransparent = spec.getBool("backgroundLightTransparent", lightTransparent);
profile.colorVariants = spec.getBool("multiColored", false) ? spec.getUInt("colorVariants", MaxMaterialColorVariant) : 0; profile.multiColor = spec.getBool("multiColored", false);
for (auto& entry : spec.getArray("colorDirectives", JsonArray()))
profile.colorDirectives.append(entry.toString());
profile.occludesBehind = spec.getBool("occludesBelow", true); profile.occludesBehind = spec.getBool("occludesBelow", true);
profile.zLevel = spec.getUInt("zLevel", 0); profile.zLevel = spec.getUInt("zLevel", 0);
profile.radiantLight = Color::rgb(jsonToVec3B(spec.get("radiantLight", JsonArray{0, 0, 0}))).toRgbF(); profile.radiantLight = Color::rgb(jsonToVec3B(spec.get("radiantLight", JsonArray{0, 0, 0}))).toRgbF();
@ -128,8 +126,8 @@ MaterialRenderProfile parseMaterialRenderProfile(Json const& spec, String const&
auto flipTextureCoordinates = [imageHeight]( auto flipTextureCoordinates = [imageHeight](
RectF const& rect) { return RectF::withSize(Vec2F(rect.xMin(), imageHeight - rect.yMax()), rect.size()); }; RectF const& rect) { return RectF::withSize(Vec2F(rect.xMin(), imageHeight - rect.yMax()), rect.size()); };
for (unsigned v = 0; v < variants; ++v) { for (unsigned v = 0; v < variants; ++v) {
if (profile.colorVariants > 0) { if (profile.multiColor) {
for (MaterialColorVariant c = 0; c <= profile.colorVariants; ++c) { for (MaterialColorVariant c = 0; c <= MaxMaterialColorVariant; ++c) {
RectF textureRect = RectF::withSize(texturePosition + variantStride * v + colorStride * c, textureSize); RectF textureRect = RectF::withSize(texturePosition + variantStride * v + colorStride * c, textureSize);
renderPiece->variants[c].append(flipTextureCoordinates(textureRect)); renderPiece->variants[c].append(flipTextureCoordinates(textureRect));
} }

View File

@ -6,7 +6,6 @@
#include "StarMultiArray.hpp" #include "StarMultiArray.hpp"
#include "StarGameTypes.hpp" #include "StarGameTypes.hpp"
#include "StarTileDamage.hpp" #include "StarTileDamage.hpp"
#include "StarDirectives.hpp"
namespace Star { namespace Star {
@ -97,12 +96,11 @@ struct MaterialRenderProfile {
MaterialRenderMatchList mainMatchList; MaterialRenderMatchList mainMatchList;
List<pair<String, Vec2F>> crackingFrames; List<pair<String, Vec2F>> crackingFrames;
List<pair<String, Vec2F>> protectedFrames; List<pair<String, Vec2F>> protectedFrames;
List<Directives> colorDirectives;
Json ruleProperties; Json ruleProperties;
bool foregroundLightTransparent; bool foregroundLightTransparent;
bool backgroundLightTransparent; bool backgroundLightTransparent;
uint8_t colorVariants; bool multiColor;
bool occludesBehind; bool occludesBehind;
uint32_t zLevel; uint32_t zLevel;
Vec3F radiantLight; Vec3F radiantLight;

View File

@ -65,7 +65,7 @@ bool TileDrawer::produceTerrainDrawables(Drawables& drawables,
MaterialId material = EmptyMaterialId; MaterialId material = EmptyMaterialId;
MaterialHue materialHue = 0; MaterialHue materialHue = 0;
MaterialColorVariant colorVariant = 0; MaterialColorVariant materialColorVariant = 0;
ModId mod = NoModId; ModId mod = NoModId;
MaterialHue modHue = 0; MaterialHue modHue = 0;
float damageLevel = 0.0f; float damageLevel = 0.0f;
@ -77,7 +77,7 @@ bool TileDrawer::produceTerrainDrawables(Drawables& drawables,
if (terrainLayer == TerrainLayer::Background) { if (terrainLayer == TerrainLayer::Background) {
material = tile.background; material = tile.background;
materialHue = tile.backgroundHueShift; materialHue = tile.backgroundHueShift;
colorVariant = tile.backgroundColorVariant; materialColorVariant = tile.backgroundColorVariant;
mod = tile.backgroundMod; mod = tile.backgroundMod;
modHue = tile.backgroundModHueShift; modHue = tile.backgroundModHueShift;
damageLevel = byteToFloat(tile.backgroundDamageLevel); damageLevel = byteToFloat(tile.backgroundDamageLevel);
@ -86,7 +86,7 @@ bool TileDrawer::produceTerrainDrawables(Drawables& drawables,
} else { } else {
material = tile.foreground; material = tile.foreground;
materialHue = tile.foregroundHueShift; materialHue = tile.foregroundHueShift;
colorVariant = tile.foregroundColorVariant; materialColorVariant = tile.foregroundColorVariant;
mod = tile.foregroundMod; mod = tile.foregroundMod;
modHue = tile.foregroundModHueShift; modHue = tile.foregroundModHueShift;
damageLevel = byteToFloat(tile.foregroundDamageLevel); damageLevel = byteToFloat(tile.foregroundDamageLevel);
@ -99,58 +99,43 @@ bool TileDrawer::produceTerrainDrawables(Drawables& drawables,
if ((isBlock && terrainLayer == TerrainLayer::Midground) || (!isBlock && terrainLayer == TerrainLayer::Foreground)) if ((isBlock && terrainLayer == TerrainLayer::Midground) || (!isBlock && terrainLayer == TerrainLayer::Foreground))
return false; return false;
auto getPieceImage = [](MaterialRenderPieceConstPtr const& piece, Box<float, 2> const& box, MaterialHue hue, Directives const* directives) -> AssetPath { auto getPieceImage = [](MaterialRenderPieceConstPtr const& piece, Box<float, 2> const& box, MaterialHue hue) -> String {
AssetPath image = hue == 0 return hue == 0
? strf("{}?crop={};{};{};{}", piece->texture, box.xMin(), box.yMin(), box.xMax(), box.yMax()) ? strf("{}?crop={};{};{};{}", piece->texture, box.xMin(), box.yMin(), box.xMax(), box.yMax())
: strf("{}?crop={};{};{};{}?hueshift={}", piece->texture, box.xMin(), box.yMin(), box.xMax(), box.yMax(), materialHueToDegrees(hue)); : strf("{}?crop={};{};{};{}?hueshift={}", piece->texture, box.xMin(), box.yMin(), box.xMax(), box.yMax(), materialHueToDegrees(hue));
if (directives)
image.directives += *directives;
return image;
}; };
auto materialRenderProfile = materialDatabase->materialRenderProfile(material); auto materialRenderProfile = materialDatabase->materialRenderProfile(material);
auto modRenderProfile = materialDatabase->modRenderProfile(mod); auto modRenderProfile = materialDatabase->modRenderProfile(mod);
if (materialRenderProfile) { if (materialRenderProfile) {
occlude = materialRenderProfile->occludesBehind; occlude = materialRenderProfile->occludesBehind;
auto materialColorVariant = materialRenderProfile->colorVariants > 0 ? colorVariant % materialRenderProfile->colorVariants : 0;
uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]) + offset[0], pos[1] + offset[1], (int)variantLayer.value(terrainLayer), "main"); uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]) + offset[0], pos[1] + offset[1], (int)variantLayer.value(terrainLayer), "main");
auto& drawList = drawables[materialZLevel(materialRenderProfile->zLevel, material, materialHue, materialColorVariant)]; auto& drawList = drawables[materialZLevel(materialRenderProfile->zLevel, material, materialHue, materialColorVariant)];
MaterialPieceResultList pieces; MaterialPieceResultList pieces;
determineMatchingPieces(pieces, &occlude, materialDatabase, materialRenderProfile->mainMatchList, renderData, pos, determineMatchingPieces(pieces, &occlude, materialDatabase, materialRenderProfile->mainMatchList, renderData, pos,
terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, false); terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, false);
Directives const* directives = materialRenderProfile->colorDirectives.empty()
? nullptr
: &materialRenderProfile->colorDirectives.wrap(materialColorVariant);
for (auto const& piecePair : pieces) { for (auto const& piecePair : pieces) {
auto variant = piecePair.first->variants.ptr(materialColorVariant); auto& variant = piecePair.first->variants.get(materialColorVariant).wrap(variance);
if (!variant) variant = piecePair.first->variants.ptr(0); auto image = getPieceImage(piecePair.first, variant, materialHue);
if (!variant) continue;
auto& textureCoords = variant->wrap(variance);
auto image = getPieceImage(piecePair.first, textureCoords, materialHue, directives);
drawList.emplace_back(Drawable::makeImage(image, scale, false, piecePair.second * scale + Vec2F(pos), color)); drawList.emplace_back(Drawable::makeImage(image, scale, false, piecePair.second * scale + Vec2F(pos), color));
} }
} }
if (modRenderProfile) { if (modRenderProfile) {
auto modColorVariant = modRenderProfile->colorVariants > 0 ? colorVariant % modRenderProfile->colorVariants : 0; auto modColorVariant = modRenderProfile->multiColor ? materialColorVariant : 0;
uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]), pos[1], (int)variantLayer.value(terrainLayer), "mod"); uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]), pos[1], (int)variantLayer.value(terrainLayer), "mod");
auto& drawList = drawables[modZLevel(modRenderProfile->zLevel, mod, modHue, modColorVariant)]; auto& drawList = drawables[modZLevel(modRenderProfile->zLevel, mod, modHue, modColorVariant)];
MaterialPieceResultList pieces; MaterialPieceResultList pieces;
determineMatchingPieces(pieces, &occlude, materialDatabase, modRenderProfile->mainMatchList, renderData, pos, determineMatchingPieces(pieces, &occlude, materialDatabase, modRenderProfile->mainMatchList, renderData, pos,
terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, true); terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, true);
Directives const* directives = modRenderProfile->colorDirectives.empty()
? nullptr
: &modRenderProfile->colorDirectives.wrap(modColorVariant);
for (auto const& piecePair : pieces) { for (auto const& piecePair : pieces) {
auto variant = piecePair.first->variants.ptr(modColorVariant); auto& variant = piecePair.first->variants.get(modColorVariant).wrap(variance);
if (!variant) variant = piecePair.first->variants.ptr(0); auto image = getPieceImage(piecePair.first, variant, modHue);
if (!variant) continue;
auto& textureCoords = variant->wrap(variance);
auto image = getPieceImage(piecePair.first, textureCoords, modHue, directives);
drawList.emplace_back(Drawable::makeImage(image, scale, false, piecePair.second * scale + Vec2F(pos), color)); drawList.emplace_back(Drawable::makeImage(image, scale, false, piecePair.second * scale + Vec2F(pos), color));
} }
} }

View File

@ -1631,7 +1631,6 @@ RpcPromise<InteractAction> WorldClient::interact(InteractRequest const& request)
} }
void WorldClient::lightingTileGather() { void WorldClient::lightingTileGather() {
int64_t start = Time::monotonicMicroseconds();
Vec3F environmentLight = m_sky->environmentLight().toRgbF(); Vec3F environmentLight = m_sky->environmentLight().toRgbF();
float undergroundLevel = m_worldTemplate->undergroundLevel(); float undergroundLevel = m_worldTemplate->undergroundLevel();
auto liquidsDatabase = Root::singleton().liquidsDatabase(); auto liquidsDatabase = Root::singleton().liquidsDatabase();
@ -1639,6 +1638,7 @@ void WorldClient::lightingTileGather() {
// Each column in tileEvalColumns is guaranteed to be no larger than the sector size. // Each column in tileEvalColumns is guaranteed to be no larger than the sector size.
size_t lights = 0;
m_tileArray->tileEvalColumns(m_lightingCalculator.calculationRegion(), [&](Vec2I const& pos, ClientTile const* column, size_t ySize) { m_tileArray->tileEvalColumns(m_lightingCalculator.calculationRegion(), [&](Vec2I const& pos, ClientTile const* column, size_t ySize) {
size_t baseIndex = m_lightingCalculator.baseIndexFor(pos); size_t baseIndex = m_lightingCalculator.baseIndexFor(pos);
for (size_t y = 0; y < ySize; ++y) { for (size_t y = 0; y < ySize; ++y) {
@ -1655,10 +1655,12 @@ void WorldClient::lightingTileGather() {
if (tile.backgroundLightTransparent && pos[1] + y > undergroundLevel) if (tile.backgroundLightTransparent && pos[1] + y > undergroundLevel)
light += environmentLight; light += environmentLight;
} }
if (light.max() > 0.0f)
++lights;
m_lightingCalculator.setCellIndex(baseIndex + y, light, !tile.foregroundLightTransparent); m_lightingCalculator.setCellIndex(baseIndex + y, light, !tile.foregroundLightTransparent);
} }
}); });
LogMap::set("client_render_world_async_light_gather", strf(u8"{:05d}\u00b5s", Time::monotonicMicroseconds() - start)); LogMap::set("client_render_world_async_light_tiles", toString(lights));
} }
void WorldClient::lightingCalc() { void WorldClient::lightingCalc() {

View File

@ -230,7 +230,7 @@ bool TilePainter::produceTerrainPrimitives(HashMap<QuadZLevel, List<RenderPrimit
MaterialId material = EmptyMaterialId; MaterialId material = EmptyMaterialId;
MaterialHue materialHue = 0; MaterialHue materialHue = 0;
MaterialColorVariant colorVariant = 0; MaterialColorVariant materialColorVariant = 0;
ModId mod = NoModId; ModId mod = NoModId;
MaterialHue modHue = 0; MaterialHue modHue = 0;
float damageLevel = 0.0f; float damageLevel = 0.0f;
@ -242,7 +242,7 @@ bool TilePainter::produceTerrainPrimitives(HashMap<QuadZLevel, List<RenderPrimit
if (terrainLayer == TerrainLayer::Background) { if (terrainLayer == TerrainLayer::Background) {
material = tile.background; material = tile.background;
materialHue = tile.backgroundHueShift; materialHue = tile.backgroundHueShift;
colorVariant = tile.backgroundColorVariant; materialColorVariant = tile.backgroundColorVariant;
mod = tile.backgroundMod; mod = tile.backgroundMod;
modHue = tile.backgroundModHueShift; modHue = tile.backgroundModHueShift;
damageLevel = byteToFloat(tile.backgroundDamageLevel); damageLevel = byteToFloat(tile.backgroundDamageLevel);
@ -251,7 +251,7 @@ bool TilePainter::produceTerrainPrimitives(HashMap<QuadZLevel, List<RenderPrimit
} else { } else {
material = tile.foreground; material = tile.foreground;
materialHue = tile.foregroundHueShift; materialHue = tile.foregroundHueShift;
colorVariant = tile.foregroundColorVariant; materialColorVariant = tile.foregroundColorVariant;
mod = tile.foregroundMod; mod = tile.foregroundMod;
modHue = tile.foregroundModHueShift; modHue = tile.foregroundModHueShift;
damageLevel = byteToFloat(tile.foregroundDamageLevel); damageLevel = byteToFloat(tile.foregroundDamageLevel);
@ -264,36 +264,34 @@ bool TilePainter::produceTerrainPrimitives(HashMap<QuadZLevel, List<RenderPrimit
if (terrainLayer == (isBlock ? TerrainLayer::Midground : TerrainLayer::Foreground)) if (terrainLayer == (isBlock ? TerrainLayer::Midground : TerrainLayer::Foreground))
return false; return false;
auto getPieceTexture = [this, assets](MaterialId material, MaterialRenderPieceConstPtr const& piece, MaterialHue hue, Directives const* directives, bool mod) { auto getPieceTexture = [this, assets](MaterialId material, MaterialRenderPieceConstPtr const& piece, MaterialHue hue, bool mod) {
return m_textureCache.get(MaterialPieceTextureKey(material, piece->pieceId, hue, mod), [&](auto const&) { return m_textureCache.get(MaterialPieceTextureKey(material, piece->pieceId, hue, mod), [&](auto const&) {
AssetPath texture = (hue == 0) ? piece->texture : strf("{}?hueshift={}", piece->texture, materialHueToDegrees(hue)); String texture;
if (hue == 0)
if (directives) texture = piece->texture;
texture.directives += *directives; else
texture = strf("{}?hueshift={}", piece->texture, materialHueToDegrees(hue));
return m_textureGroup->create(*assets->image(texture)); return m_textureGroup->create(*assets->image(texture));
}); });
}; };
auto materialRenderProfile = materialDatabase->materialRenderProfile(material); auto materialRenderProfile = materialDatabase->materialRenderProfile(material);
auto modRenderProfile = materialDatabase->modRenderProfile(mod); auto modRenderProfile = materialDatabase->modRenderProfile(mod);
if (materialRenderProfile) { if (materialRenderProfile) {
occlude = materialRenderProfile->occludesBehind; occlude = materialRenderProfile->occludesBehind;
auto materialColorVariant = materialRenderProfile->colorVariants > 0 ? colorVariant % materialRenderProfile->colorVariants : 0;
uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]), pos[1], (int)terrainLayer, "main"); uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]), pos[1], (int)terrainLayer, "main");
auto& quadList = primitives[materialZLevel(materialRenderProfile->zLevel, material, materialHue, materialColorVariant)]; auto& quadList = primitives[materialZLevel(materialRenderProfile->zLevel, material, materialHue, materialColorVariant)];
MaterialPieceResultList pieces; MaterialPieceResultList pieces;
determineMatchingPieces(pieces, &occlude, materialDatabase, materialRenderProfile->mainMatchList, renderData, pos, determineMatchingPieces(pieces, &occlude, materialDatabase, materialRenderProfile->mainMatchList, renderData, pos,
terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, false); terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, false);
Directives const* directives = materialRenderProfile->colorDirectives.empty()
? nullptr
: &materialRenderProfile->colorDirectives.wrap(materialColorVariant);
for (auto const& piecePair : pieces) { for (auto const& piecePair : pieces) {
TexturePtr texture = getPieceTexture(material, piecePair.first, materialHue, directives, false); TexturePtr texture = getPieceTexture(material, piecePair.first, materialHue, false);
auto variant = piecePair.first->variants.ptr(materialColorVariant); auto variant = piecePair.first->variants.ptr(materialColorVariant);
if (!variant) variant = piecePair.first->variants.ptr(0);
if (!variant) continue; if (!variant) continue;
RectF textureCoords = variant->wrap(variance); RectF textureCoords = variant->wrap(variance);
RectF worldCoords = RectF::withSize(piecePair.second / TilePixels + Vec2F(pos), textureCoords.size() / TilePixels); RectF worldCoords = RectF::withSize(piecePair.second / TilePixels + Vec2F(pos), textureCoords.size() / TilePixels);
@ -311,20 +309,16 @@ bool TilePainter::produceTerrainPrimitives(HashMap<QuadZLevel, List<RenderPrimit
} }
if (modRenderProfile) { if (modRenderProfile) {
auto modColorVariant = modRenderProfile->colorVariants > 0 ? colorVariant % modRenderProfile->colorVariants : 0; auto modColorVariant = modRenderProfile->multiColor ? materialColorVariant : 0;
uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]), pos[1], (int)terrainLayer, "mod"); uint32_t variance = staticRandomU32(renderData.geometry.xwrap(pos[0]), pos[1], (int)terrainLayer, "mod");
auto& quadList = primitives[modZLevel(modRenderProfile->zLevel, mod, modHue, modColorVariant)]; auto& quadList = primitives[modZLevel(modRenderProfile->zLevel, mod, modHue, modColorVariant)];
MaterialPieceResultList pieces; MaterialPieceResultList pieces;
determineMatchingPieces(pieces, &occlude, materialDatabase, modRenderProfile->mainMatchList, renderData, pos, determineMatchingPieces(pieces, &occlude, materialDatabase, modRenderProfile->mainMatchList, renderData, pos,
terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, true); terrainLayer == TerrainLayer::Background ? TileLayer::Background : TileLayer::Foreground, true);
Directives const* directives = modRenderProfile->colorDirectives.empty()
? nullptr
: &modRenderProfile->colorDirectives.wrap(modColorVariant);
for (auto const& piecePair : pieces) { for (auto const& piecePair : pieces) {
auto texture = getPieceTexture(mod, piecePair.first, modHue, directives, true); auto texture = getPieceTexture(mod, piecePair.first, modHue, true);
auto variant = piecePair.first->variants.ptr(modColorVariant); auto variant = piecePair.first->variants.ptr(modColorVariant);
if (!variant) variant = piecePair.first->variants.ptr(0);
if (!variant) continue; if (!variant) continue;
auto& textureCoords = variant->wrap(variance); auto& textureCoords = variant->wrap(variance);
RectF worldCoords = RectF::withSize(piecePair.second / TilePixels + Vec2F(pos), textureCoords.size() / TilePixels); RectF worldCoords = RectF::withSize(piecePair.second / TilePixels + Vec2F(pos), textureCoords.size() / TilePixels);