From 4511de8d38a2be83366f659e9c66887cf227c2f7 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Mon, 23 Feb 2026 03:29:07 -0800 Subject: [PATCH] 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. --- include/rendering/wmo_renderer.hpp | 1 + src/rendering/wmo_renderer.cpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/rendering/wmo_renderer.hpp b/include/rendering/wmo_renderer.hpp index a2a2d435..86b43352 100644 --- a/include/rendering/wmo_renderer.hpp +++ b/include/rendering/wmo_renderer.hpp @@ -445,6 +445,7 @@ private: // Texture handles for this model (indexed by texture path order) std::vector textures; // non-owning, from cache + std::vector textureNames; // lowercase texture paths (parallel to textures) // Material texture indices (materialId -> texture index) std::vector materialTextureIndices; diff --git a/src/rendering/wmo_renderer.cpp b/src/rendering/wmo_renderer.cpp index 5ae2035d..1ca93250 100644 --- a/src/rendering/wmo_renderer.cpp +++ b/src/rendering/wmo_renderer.cpp @@ -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(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(tex), alphaTest, unlit, isWindow }; auto& mb = batchMap[key];