wmo: apply MOHD ambient color to interior group lighting

Read the ambient color from the MOHD chunk (BGRA uint32) and store it
on WMOModel as a normalized RGB vec3.  Pass it through ModelData into
the per-batch WMOMaterialUBO (replacing the unused pad[3] bytes, keeping
the struct at 64 bytes).  The GLSL interior branch now floors vertex
colors against the WMO ambient instead of a hardcoded 0.5, so dungeon
interiors respect the artist-specified ambient tint from the WMO root
rather than always clamping to grey.
This commit is contained in:
Kelsi 2026-03-09 21:27:01 -07:00
parent 8561d5c58c
commit 4d1be18c18
6 changed files with 24 additions and 3 deletions

View file

@ -29,6 +29,9 @@ layout(set = 1, binding = 1) uniform WMOMaterial {
float heightMapVariance;
float normalMapStrength;
int isLava;
float wmoAmbientR;
float wmoAmbientG;
float wmoAmbientB;
};
layout(set = 1, binding = 2) uniform sampler2D uNormalHeightMap;
@ -185,7 +188,13 @@ void main() {
} else if (unlit != 0) {
result = texColor.rgb * shadow;
} else if (isInterior != 0) {
vec3 mocv = max(VertColor.rgb, vec3(0.5));
// WMO interior: vertex colors (MOCV) are pre-baked lighting from the artist.
// The MOHD ambient color tints/floors the vertex colors so dark spots don't
// go completely black, matching the WoW client's interior shading.
vec3 wmoAmbient = vec3(wmoAmbientR, wmoAmbientG, wmoAmbientB);
// Clamp ambient to at least 0.3 to avoid total darkness when MOHD color is zero
wmoAmbient = max(wmoAmbient, vec3(0.3));
vec3 mocv = max(VertColor.rgb, wmoAmbient);
result = texColor.rgb * mocv * shadow;
} else {
vec3 ldir = normalize(-lightDir.xyz);

Binary file not shown.

View file

@ -185,6 +185,7 @@ struct WMOModel {
uint32_t nDoodadDefs;
uint32_t nDoodadSets;
glm::vec3 ambientColor; // MOHD ambient color (used for interior group lighting)
glm::vec3 boundingBoxMin;
glm::vec3 boundingBoxMax;

View file

@ -353,7 +353,9 @@ private:
float heightMapVariance; // 40 (low variance = skip POM)
float normalMapStrength; // 44 (0=flat, 1=full, 2=exaggerated)
int32_t isLava; // 48 (1=lava/magma UV scroll)
float pad[3]; // 52-60 padding to 64 bytes
float wmoAmbientR; // 52 (interior ambient color R)
float wmoAmbientG; // 56 (interior ambient color G)
float wmoAmbientB; // 60 (interior ambient color B)
}; // 64 bytes total
/**
@ -472,6 +474,7 @@ private:
std::vector<GroupResources> groups;
glm::vec3 boundingBoxMin;
glm::vec3 boundingBoxMax;
glm::vec3 wmoAmbientColor{0.5f, 0.5f, 0.5f}; // From MOHD, used for interior lighting
bool isLowPlatform = false;
// Doodad templates (M2 models placed in WMO, stored for instancing)

View file

@ -109,7 +109,11 @@ WMOModel WMOLoader::load(const std::vector<uint8_t>& wmoData) {
model.nDoodadDefs = read<uint32_t>(wmoData, offset);
model.nDoodadSets = read<uint32_t>(wmoData, offset);
[[maybe_unused]] uint32_t ambColor = read<uint32_t>(wmoData, offset); // Ambient color (BGRA)
uint32_t ambColor = read<uint32_t>(wmoData, offset); // Ambient color (BGRA)
// Unpack BGRA bytes to normalized [0,1] RGB
model.ambientColor.r = ((ambColor >> 16) & 0xFF) / 255.0f;
model.ambientColor.g = ((ambColor >> 8) & 0xFF) / 255.0f;
model.ambientColor.b = ((ambColor >> 0) & 0xFF) / 255.0f;
[[maybe_unused]] uint32_t wmoID = read<uint32_t>(wmoData, offset);
model.boundingBoxMin.x = read<float>(wmoData, offset);

View file

@ -414,6 +414,7 @@ bool WMORenderer::loadModel(const pipeline::WMOModel& model, uint32_t id) {
modelData.id = id;
modelData.boundingBoxMin = model.boundingBoxMin;
modelData.boundingBoxMax = model.boundingBoxMax;
modelData.wmoAmbientColor = model.ambientColor;
{
glm::vec3 ext = model.boundingBoxMax - model.boundingBoxMin;
float horiz = std::max(ext.x, ext.y);
@ -681,6 +682,9 @@ bool WMORenderer::loadModel(const pipeline::WMOModel& model, uint32_t id) {
matData.heightMapVariance = mb.heightMapVariance;
matData.normalMapStrength = normalMapStrength_;
matData.isLava = mb.isLava ? 1 : 0;
matData.wmoAmbientR = modelData.wmoAmbientColor.r;
matData.wmoAmbientG = modelData.wmoAmbientColor.g;
matData.wmoAmbientB = modelData.wmoAmbientColor.b;
if (matBuf.info.pMappedData) {
memcpy(matBuf.info.pMappedData, &matData, sizeof(matData));
}