Rendering/Lighting

From wowdev
Jump to navigation Jump to search

Doodad Lighting

CMapDoodadDef::QueryInteriorLighting

void CMapDoodadDef::QueryInteriorLighting(CMapDoodadDef *this, CMapObjDef *mapObjDef, uint32_t groupIndex, uint16_t *a4, const C3Vector *pos) {

  CImVector color = 0;
  bool lightRes;

  if (a4) {

    // Convert pos to local pos
    C3Vector lPos;
    sub_4C21B0(&lPos, pos, &mapObjDef->invMat);

    lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, groupIndex, &lPos, *a4, &color, (bool *)&mapObjDef + 3);

  } 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;

    sub_4C21B0(&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;

    sub_4C21B0(&lEnd, &wEnd, &mapObjDef->invMat);

    C3Segment seg;
    seg.start = lStart;
    seg.end = lEnd;

    lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, groupIndex, &seg, &color, (bool *)&mapObjDef + 3);

  }

  if (lightRes) {

    CMapStaticEntity::AdjustLighting(&color, &this->dirColor, 0xA8u, &this->ambColor, 0x60u);

    if (BYTE3(mapObjDef)) {

      dnInfo = DayNightGetInfo();

      if (color.a) {
        CImVector::BlendRGB255(&v7->dirColor, color.a, (const CImVector *)dnInfo + 106);
        CImVector::BlendRGB255(&v7->ambColor, color.a, (const CImVector *)dnInfo + 107);
      }

      this->dirColor.a = color.a;
      this->unk3 |= 0x1000u;

    } else {

      this->unk3 &= 0xFFFFEFFF;

    }

  }

}