Rendering/Lighting: Difference between revisions

From wowdev
Jump to navigation Jump to search
mNo edit summary
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Doodad Lighting ==
= Overview =


=== CMapDoodadDef::QueryInteriorLighting ===
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 ==


<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
void CMapDoodadDef::QueryInteriorLighting(CMapDoodadDef *this, CMapObjDef *mapObjDef, uint32_t a3, uint16_t *a4, const C3Vector *pos) {
void CMapDoodadDef::QueryInteriorLighting(CMapDoodadDef *this, CMapObjDef *mapObjDef, uint32_t groupIdx, uint16_t *polyIdx, const C3Vector *pos) {


   CImVector color = 0;
   CImVector color = 0;
  bool blendExtLight;
   bool lightRes;
   bool lightRes;


   if (a4) {
   if (polyIdx) {


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


     lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, a3, &v13, *a4, &color, (bool *)&mapObjDef + 3);
     lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, groupIdx, &lPos, *polyIdx, &color, &blendExtLight);


   } else {
   } else {
Line 25: Line 30:
     wStart.z = this->m_mat.columns[3].z + 1.5;
     wStart.z = this->m_mat.columns[3].z + 1.5;


     sub_4C21B0(&lStart, &wStart, &mapObjDef->invMat);
     operator*(&lStart, &wStart, &mapObjDef->invMat);


     C3Vector wEnd;
     C3Vector wEnd;
Line 34: Line 39:
     wEnd.z = this->m_mat.columns[3].z - 1760.0;
     wEnd.z = this->m_mat.columns[3].z - 1760.0;


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


     C3Segment seg;
     C3Segment seg;
Line 40: Line 45:
     seg.end = lEnd;
     seg.end = lEnd;


     lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, a3, &seg, &color, (bool *)&mapObjDef + 3);
     lightRes = CMapObj::QueryLighting(mapObjDef->mapObj, groupIdx, &seg, &color, &blendExtLight);
 
  }
 
  if (lightRes) {
 
    CMapStaticEntity::AdjustLighting(&color, &this->dirColor, 168u, &this->ambColor, 96u);
 
    // Set to true if MOPY.flags & 0x01
 
    if (blendExtLight) {
 
      DNInfo dnInfo = DayNightGetInfo();
 
      if (color.a) {
 
        CImVector::BlendRGB255(&this->dirColor, color.a, &dnInfo->lightInfo.dirColor);
        CImVector::BlendRGB255(&this->ambColor, color.a, &dnInfo->lightInfo.ambColor);
 
      }
 
      this->dirColor.a = color.a;
      this->unk3 |= 0x1000u;
 
    } else {
 
      this->unk3 &= 0xFFFFEFFF;
 
    }
 
  }
 
}
</syntaxhighlight>
 
== CMapDoodadDef::SelectLights ==
 
<syntaxhighlight lang="cpp">
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::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;
 
  }
 
}
</syntaxhighlight>
 
= Entity Lighting =
 
== CMapEntity::QueryInteriorLighting ==
 
<syntaxhighlight lang="cpp">
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);


   }
   }
Line 46: Line 210:
   if (lightRes) {
   if (lightRes) {


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


     if (BYTE3(mapObjDef)) {
     // Set to true if MOPY.flags & 0x01


       dnInfo = DayNightGetInfo();
    if (blendExtLight) {
 
       DNInfo dnInfo = DayNightGetInfo();


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



Latest revision as of 02:51, 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, 168u, &this->ambColor, 96u);

    // Set to true if MOPY.flags & 0x01

    if (blendExtLight) {

      DNInfo dnInfo = DayNightGetInfo();

      if (color.a) {

        CImVector::BlendRGB255(&this->dirColor, color.a, &dnInfo->lightInfo.dirColor);
        CImVector::BlendRGB255(&this->ambColor, color.a, &dnInfo->lightInfo.ambColor);

      }

      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::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, &dnInfo->lightInfo.dirColor);
        CImVector::BlendRGB255(&this->ambientTarget, color.a, &dnInfo->lightInfo.ambColor);

      }

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

    } else {

      this->unk3 &= 0xFFFFEFFF;

    }

  }

}