Rendering/DayNight: Difference between revisions

From wowdev
Jump to navigation Jump to search
(Adding DayNight::DarkenColor)
Line 2: Line 2:


Things like area lighting, zone lighting, clouds, the sky sphere (ie the color gradient of the sky), stars (ie sky boxes) are all managed by <tt>DayNight</tt>.
Things like area lighting, zone lighting, clouds, the sky sphere (ie the color gradient of the sky), stars (ie sky boxes) are all managed by <tt>DayNight</tt>.
== DayNight::DarkenColor ==
<syntaxhighlight lang="cpp">
CImVector DayNight::DarkenColor(CImVector const &clr, float amount) {
  C3Vector rgb;
  C3Vector hsv;
  rgb.x = clr->r / 255.0;
  rgb.y = clr->g / 255.0;
  rgb.z = clr->b / 255.0;
  hsv.x = 0.0;
  hsv.y = 0.0;
  hsv.z = 0.0;
  RGBtoHSV(&rgb, &hsv);
  hsv.z = hsv.z * amount;
  HSVtoRGB(&hsv, &rgb);
  CImVector result;
  CImVector::operator=(&result, &rgb);
  return result;
}
</syntaxhighlight>


== DayNight::SetDirection ==
== DayNight::SetDirection ==

Revision as of 02:49, 18 May 2017

In World of Warcraft, the DayNight system governs most of the general appearance of the world.

Things like area lighting, zone lighting, clouds, the sky sphere (ie the color gradient of the sky), stars (ie sky boxes) are all managed by DayNight.

DayNight::DarkenColor

CImVector DayNight::DarkenColor(CImVector const &clr, float amount) {

  C3Vector rgb;
  C3Vector hsv;

  rgb.x = clr->r / 255.0;
  rgb.y = clr->g / 255.0;
  rgb.z = clr->b / 255.0;

  hsv.x = 0.0;
  hsv.y = 0.0;
  hsv.z = 0.0;

  RGBtoHSV(&rgb, &hsv);

  hsv.z = hsv.z * amount;

  HSVtoRGB(&hsv, &rgb);

  CImVector result;

  CImVector::operator=(&result, &rgb);

  return result;

}

DayNight::SetDirection

DayNight::SetDirection calculates a C3Vector containing the direction vector for the global light, aka sunDir.

This direction vector is transformed by the view matrix prior to being uploaded to the shader.

void DayNight::SetDirection() {

  // Phi Table
  if ( !(dword_D39104 & 1) ) {

    dword_D39104 |= 1u;

    DayNight::phiTable[0].x = 0.0;   DayNight::phiTable[0].y = 2.2165682;
    DayNight::phiTable[1].x = 0.25;  DayNight::phiTable[1].y = 1.9198623;
    DayNight::phiTable[2].x = 0.5;   DayNight::phiTable[2].y = 2.2165682;
    DayNight::phiTable[3].x = 0.75;  DayNight::phiTable[3].y = 1.9198623;

  }

  // Theta Table
  if ( !(dword_D39104 & 2) ) {

    dword_D39104 |= 2;
    
    DayNight::thetaTable[0].x = 0.0;   DayNight::thetaTable[0].y = 3.926991;
    DayNight::thetaTable[1].x = 0.25;  DayNight::thetaTable[1].y = 3.926991;
    DayNight::thetaTable[2].x = 0.5;   DayNight::thetaTable[2].y = 3.926991;
    DayNight::thetaTable[3].x = 0.75;  DayNight::thetaTable[3].y = 3.926991;

  }

  // D38B04: float dnProgression (0.0 to 1.0)
  float phi = DayNight::InterpTable(&DayNight::phiTable, 4u, flt_D38B04);
  float theta = DayNight::InterpTable(&DayNight::thetaTable, 4u, flt_D38B04);

  // Convert from spherical coordinates to XYZ
  // x = rho * sin(phi) * cos(theta)
  // y = rho * sin(phi) * sin(theta)
  // z = rho * cos(phi)

  float sinPhi = CMath::sinoid(phi);
  float cosPhi = CMath::cosoid(phi);

  float sinTheta = CMath::sinoid(theta);
  float cosTheta = CMath::cosoid(theta);

  // D38C9C: C3Vector sunDir
  dword_D38C9C.x = sinPhi * cosTheta;
  dword_D38C9C.y = sinPhi * sinTheta;
  dword_D38C9C.z = cosPhi;

}