WMO/Rendering: Difference between revisions

From wowdev
Jump to navigation Jump to search
Line 12: Line 12:
# Derive ambient and diffuse color terms from the interpolated color.
# Derive ambient and diffuse color terms from the interpolated color.
# Use the static <tt>interiorSunDir</tt> vector as the interior light direction.
# Use the static <tt>interiorSunDir</tt> vector as the interior light direction.
'''Query with C3Vector and poly index'''
Query lighting when the relevant poly is already known.
<syntaxhighlight lang="cpp">
bool CMapObj::QueryLighting(CMapObj *this, uint32_t groupIndex, const C3Vector *point, uint16_t polyIdx, CImVector *color, bool *a5) {
  CMapObjGroup group = this->groupList[groupIndex];
  if (!this->unk6[16] || !(group->unk14 & 1) || group->flags & (SMOGroup::EXTERIOR | SMOGroup::EXTERIOR_LIT)) {
    return 0;
  }
  bool lightRes = CMapObjGroup::QueryLighting(group, point, polyIdx, color, a5);
  return lightRes;
}
</syntaxhighlight>


'''Query with C3Segment'''
'''Query with C3Segment'''
Line 79: Line 57:


   bool lightRes = CMapObjGroup::QueryLighting(group, &point, hitPoly, color, a5);
   bool lightRes = CMapObjGroup::QueryLighting(group, &point, hitPoly, color, a5);
  return lightRes;
}
</syntaxhighlight>
'''Query with C3Vector and poly index'''
Query lighting when the relevant poly is already known.
<syntaxhighlight lang="cpp">
bool CMapObj::QueryLighting(CMapObj *this, uint32_t groupIndex, const C3Vector *point, uint16_t polyIdx, CImVector *color, bool *a5) {
  CMapObjGroup group = this->groupList[groupIndex];
  if (!this->unk6[16] || !(group->unk14 & 1) || group->flags & (SMOGroup::EXTERIOR | SMOGroup::EXTERIOR_LIT)) {
    return 0;
  }
  // Since the point and poly are already known, there's no need to query the BSP tree
  bool lightRes = CMapObjGroup::QueryLighting(group, point, polyIdx, color, a5);


   return lightRes;
   return lightRes;

Revision as of 14:44, 4 October 2017

Lighting

CMapObj::QueryLighting

Lighting for interior WMO groups is prebaked into vertex colors.

In order to light entities (like units, game objects, etc) that exist within interior WMO groups, the game does the following:

  1. Query for the closest MOPY.
  2. Obtain the 3 relevant MOCV values for the MOPY.
  3. Interpolate the values based on the position of the entity relative to the MOPY (ie barycentric interpolation).
  4. Derive ambient and diffuse color terms from the interpolated color.
  5. Use the static interiorSunDir vector as the interior light direction.

Query with C3Segment

Query lighting when the exact poly is not yet known. Uses a C3Segment to perform a ranged query for possible tris.

bool CMapObj::QueryLighting(CMapObj *this, uint32_t groupIndex, const C3Segment *seg, CImVector *color, bool *a5) {

  CMapObjGroup group = this->groupList[groupIndex];

  if (!this->unk6[16] || !(group->unk14 & 1) || group->flags & (SMOGroup::EXTERIOR | SMOGroup::EXTERIOR_LIT)) {

    return 0;

  }

  World::TriData::resultFlags = 0;
  World::TriData::nBatches = 0;
  World::TriData::nTriIndices = 0;
  World::TriData::nVertexIndices = 0;
  World::TriData::nMatrices = 0;

  float hitT = 1.0;

  // Query the BSP tree for the group to find appropriate tris

  bool triRes = CMapObjGroup::GetTris(group, seg, &hitT, 0, 8, (int)&a2 + 3, 0);

  if (!triRes) {

    return 0;

  }

  // Obtain point matching intersection between segment and tri

  C3Vector point;

  point.x = seg->start.x + hitT * (seg->end.x - seg->start.x);
  point.y = seg->start.y + hitT * (seg->end.y - seg->start.y);
  point.z = seg->start.z + hitT * (seg->end.z - seg->start.z);

  unsigned __int16 hitPoly = word_CD8094;

  bool lightRes = CMapObjGroup::QueryLighting(group, &point, hitPoly, color, a5);

  return lightRes;

}

Query with C3Vector and poly index

Query lighting when the relevant poly is already known.

bool CMapObj::QueryLighting(CMapObj *this, uint32_t groupIndex, const C3Vector *point, uint16_t polyIdx, CImVector *color, bool *a5) {

  CMapObjGroup group = this->groupList[groupIndex];

  if (!this->unk6[16] || !(group->unk14 & 1) || group->flags & (SMOGroup::EXTERIOR | SMOGroup::EXTERIOR_LIT)) {

    return 0;

  }

  // Since the point and poly are already known, there's no need to query the BSP tree

  bool lightRes = CMapObjGroup::QueryLighting(group, point, polyIdx, color, a5);

  return lightRes;

}