Fix lamp posts rendering as glass by using texture name for window detection

Instead of relying on material flag 0x40 (F_CLAMP_S, not F_WINDOW) to
identify glass materials, detect windows by checking for "window" in the
texture path. This correctly applies glass to window textures while
leaving lamp posts and other geometry opaque.
This commit is contained in:
Kelsi 2026-02-23 03:29:07 -08:00
parent a7cf0d0c4e
commit 4511de8d38
2 changed files with 17 additions and 2 deletions

View file

@ -445,6 +445,7 @@ private:
// Texture handles for this model (indexed by texture path order)
std::vector<VkTexture*> textures; // non-owning, from cache
std::vector<std::string> textureNames; // lowercase texture paths (parallel to textures)
// Material texture indices (materialId -> texture index)
std::vector<uint32_t> materialTextureIndices;

View file

@ -427,6 +427,11 @@ bool WMORenderer::loadModel(const pipeline::WMOModel& model, uint32_t id) {
core::Logger::getInstance().debug(" Loading texture ", i, ": ", texPath);
VkTexture* tex = loadTexture(texPath);
modelData.textures.push_back(tex);
// Store lowercase texture name for material detection
std::string lowerPath = texPath;
std::transform(lowerPath.begin(), lowerPath.end(), lowerPath.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
modelData.textureNames.push_back(lowerPath);
}
core::Logger::getInstance().debug(" Loaded ", modelData.textures.size(), " textures for WMO");
}
@ -588,8 +593,17 @@ bool WMORenderer::loadModel(const pipeline::WMOModel& model, uint32_t id) {
unlit = (matFlags & 0x01) != 0;
}
// F_WINDOW = 0x40, renders as transparent glass.
bool isWindow = (matFlags & 0x40) != 0;
// Detect window/glass materials by texture name.
// Flag 0x10 (F_SIDN) marks night-glow materials (windows AND lamps),
// so we additionally check for "window" in the texture path to
// distinguish actual glass from lamp post geometry.
bool isWindow = false;
if (batch.materialId < modelData.materialTextureIndices.size()) {
uint32_t ti = modelData.materialTextureIndices[batch.materialId];
if (ti < modelData.textureNames.size()) {
isWindow = (modelData.textureNames[ti].find("window") != std::string::npos);
}
}
BatchKey key{ reinterpret_cast<uintptr_t>(tex), alphaTest, unlit, isWindow };
auto& mb = batchMap[key];