Rendering/Lighting: Difference between revisions

From wowdev
Jump to navigation Jump to search
Line 78: Line 78:


}
}
</syntaxhighlight>
== CMapDoodadDef::SelectLights ==
<syntaxhighlight lang="cpp">
</syntaxhighlight>
</syntaxhighlight>



Revision as of 00:35, 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

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;

    }

  }

}