Rendering/Lighting: Difference between revisions
Jump to navigation
Jump to search
Line 157: | Line 157: | ||
} | } | ||
if (this-> | if (this->flagInside) { // Flag 0x02 | ||
lighting->flags |= 0x08; | lighting->flags |= 0x08; |
Revision as of 01:14, 8 October 2017
Overview
Note: this page largely deals with how lighting worked in the WotLK era. That said, large chunks of this are relevant from the vanilla era through WoD. Potentially, much of this is also relevant for Legion.
Doodad Lighting
CMapDoodadDef::QueryInteriorLighting
void CMapDoodadDef::QueryInteriorLighting(CMapDoodadDef *this, CMapObjDef *mapObjDef, uint32_t groupIdx, uint16_t *polyIdx, const C3Vector *pos) {
CImVector color = 0;
bool blendExtLight;
bool lightRes;
if (polyIdx) {
C3Vector lPos;
operator*(&lPos, pos, &mapObjDef->invMat);
lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, groupIdx, &lPos, *polyIdx, &color, &blendExtLight);
} else {
C3Vector wStart;
C3Vector lStart;
wStart.x = this->m_mat.columns[3].x;
wStart.y = this->m_mat.columns[3].y;
wStart.z = this->m_mat.columns[3].z + 1.5;
operator*(&lStart, &wStart, &mapObjDef->invMat);
C3Vector wEnd;
C3Vector lEnd;
wEnd.x = this->m_mat.columns[3].x;
wEnd.y = this->m_mat.columns[3].y;
wEnd.z = this->m_mat.columns[3].z - 1760.0;
operator*(&lEnd, &wEnd, &mapObjDef->invMat);
C3Segment seg;
seg.start = lStart;
seg.end = lEnd;
lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, groupIdx, &seg, &color, &blendExtLight);
}
if (lightRes) {
CMapStaticEntity::AdjustLighting(&color, &this->dirColor, 0xA8u, &this->ambColor, 0x60u);
// Set to true if MOPY.flags & 0x01
if (blendExtLight) {
DNInfo dnInfo = DayNightGetInfo();
if (color.a) {
CImVector::BlendRGB255(&this->dirColor, color.a, (const CImVector *)dnInfo + 106);
CImVector::BlendRGB255(&this->ambColor, color.a, (const CImVector *)dnInfo + 107);
}
this->dirColor.a = color.a;
this->unk3 |= 0x1000u;
} else {
this->unk3 &= 0xFFFFEFFF;
}
}
}
CMapDoodadDef::SelectLights
void CMapDoodadDef::SelectLights(CMapDoodadDef *this, CM2Lighting *lighting) {
if (this->flagInside) { // Flag 0x02
// Doodad is in interior
C3Vector ambColor;
ambColor.x = this->ambColor.r / 255.0f;
ambColor.y = this->ambColor.g / 255.0f;
ambColor.z = this->ambColor.b / 255.0f;
CM2Lighting::AddAmbient(lighting, &ambColor);
C3Vector dirColor;
dirColor.x = this->dirColor.r / 255.0f;
dirColor.y = this->dirColor.g / 255.0f;
dirColor.z = this->dirColor.b / 255.0f;
CM2Lighting::AddDiffuse(lighting, &dirColor, &CMapStaticEntity::s_interiorSunDir);
} else {
// Doodad is in exterior
C3Vector ambColor;
ambColor.x = CMap::sunLight->ambColor.x;
ambColor.y = CMap::sunLight->ambColor.y;
ambColor.z = CMap::sunLight->ambColor.z;
CM2Lighting::AddAmbient(lighting, &ambColor);
C3Vector dir;
dir.x = CMap::sunLight->dir.x;
dir.y = CMap::sunLight->dir.y;
dir.z = CMap::sunLight->dir.z;
C3Vector dirColor;
dirColor.x = CMap::sunLight->dirColor.x * this->dirLightScale;
dirColor.y = CMap::sunLight->dirColor.y * this->dirLightScale;
dirColor.z = CMap::sunLight->dirColor.z * this->dirLightScale;
CM2Lighting::AddDiffuse(lighting, &dirColor, &dir);
}
DNInfo dnInfo = DayNightGetInfo();
if (this->flags & 0x8000) {
C3Vector fogColor;
fogColor.x = ((uchar *)dnInfo + 162) / 255.0f;
fogColor.y = ((uchar *)dnInfo + 161) / 255.0f;
fogColor.z = ((uchar *)dnInfo + 160) / 255.0f;
CM2Lighting::SetFog(lighting, &fogColor, *((float *)dnInfo + 41), *((float *)dnInfo + 42), *((float *)dnInfo + 43));
} else {
C3Vector fogColor;
fogColor.x = ((uchar *)dnInfo + 142) / 255.0f;
fogColor.y = ((uchar *)dnInfo + 141) / 255.0f;
fogColor.z = ((uchar *)dnInfo + 140) / 255.0f;
CM2Lighting::SetFog(lighting, &fogColor, *((float *)dnInfo + 36), *((float *)dnInfo + 37), *((float *)dnInfo + 38));
}
if (this->flagInside) { // Flag 0x02
lighting->flags |= 0x08;
} else {
lighting->flags &= 0xFFFFFFF7;
}
}
Entity Lighting
CMapEntity::QueryInteriorLighting
void CMapEntity::QueryInteriorLighting(CMapEntity *this, CMapObjDef *mapObjDef, uint32_t groupIdx, uint16_t *polyIdx, const C3Vector *pos) {
CImVector color;
bool blendExtLight;
bool lightRes;
if (polyIdx) {
C3Vector lPos;
operator*(&lPos, pos, &mapObjDef->invMat);
lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, groupIdx, &lPos, *polyIdx, &color, &blendExtLight);
} else {
C3Vector lPos;
operator*(&lPos, (const C3Vector *)&this->m_mat.columns[3], &mapObjDef->invMat);
C3Segment seg;
seg.start.x = lPos.x;
seg.start.y = lPos.y;
seg.start.z = lPos.z + 1.0f;
seg.end.x = lPos.x;
seg.end.y = lPos.y;
seg.end.z = lPos.z - 12.0f;
lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, groupIdx, &seg, &color, &blendExtLight);
}
if (lightRes) {
CMapStaticEntity::AdjustLighting(&color, &this->dirColor, 168u, &this->ambientTarget, 96u);
// Set to true if MOPY.flags & 0x01
if (blendExtLight) {
DNInfo dnInfo = DayNightGetInfo();
if (color.a) {
CImVector::BlendRGB255(&this->dirColor, color.a, (const CImVector *)dnInfo + 106);
CImVector::BlendRGB255(&this->ambientTarget, color.a, (const CImVector *)dnInfo + 107);
}
this->dirColor.a = color.a;
this->unk3 |= 0x1000u;
} else {
this->unk3 &= 0xFFFFEFFF;
}
}
}