Day night cycle: Difference between revisions

From wowdev
Jump to navigation Jump to search
Line 78: Line 78:
   float fogRate;
   float fogRate;


   if (fogDelta <= fogFarClip) {
   if (fogRange <= fogFarClip) {
     fogRate = ((1.0f - (fogRange / fogFarClip)) * 5.5f) + 1.5f;
     fogRate = ((1.0f - (fogRange / fogFarClip)) * 5.5f) + 1.5f;
   } else {
   } else {

Revision as of 05:02, 20 September 2016

Summary

WIP

CGameTime

CGameTime contains the logic and values necessary to determine things like: time of day progression, adjustments necessary to transform local time in to server time, etc.

CGameTime::GameTimeGetDayProgression

The GameTimeGetDayProgression function in CGameTime is frequently used in the various DayNight calculations. This function calculates the minutes since midnight in server time, and divides by the total number of minutes in a day.

The return value is a floating point that ranges from 0.0 to 1.0, measuring the distance the current server time is from midnight. 0.0 represents the time just after midnight, 0.5 represents midday, and 1.0 represents the time just before midnight.

DayNight

DayNight::InterpTable

Given a table and an interpolation factor, this function returns a value linearly interpolated out of the table. The function is commonly called in various DayNight value / color update functions.

Return values are always floating points.

Tables

Tables that are fed into DayNight::InterpTable include:

  • DayNight::s_sidnTable
  • DayNight::DNSky::s_darkTable
  • DayNight::DNSky::s_fadeTable
  • DayNight::DNStars::s_fadeTable
  • DayNight::DNClouds::s_bumpFadeTable
  • DayNight::CDayNightObjectInt::SetDirection(void)::phiTable
  • DayNight::CDayNightObjectInt::SetDirection(void)::thetaTable

Tables are structured:

struct {
  float distance_along_interpolation;
  float value_at_distance;
};

For example,

DayNight::DNStars::s_fadeTable = { {0.1250, 1.0}
                                 , {0.1875, 0.0}
                                 , {0.9375, 0.0}
                                 , {1.0000, 1.0}
                                 }

Logic

Logic WIP

DayNight::DarkenColor

Adjusts a given RGB value's brightness by a given floating point multiplier. Converts RGB to HSV, applies the multiplier to the V component, converts the adjusted HSV value back to RGB, and returns it.

Called from the various SetColors functions within DayNight.

DayNight::CDayNightObjectInt::CalcFogRate

Description WIP

Logic

float DayNight::CDayNightObjectInt::CalcFogRate(DayNight::CDayNightObjectInt *this, float fogStart, float fogEnd) {
  float fogFarClip;

  if (this->info.cameraFarClip < 700.0f) {
    fogFarClip = cameraFarClip - 200.0f;
  } else {
    fogFarClip = 500.0f;
  }

  float fogRange = fogEnd - fogStart;

  float fogRate;

  if (fogRange <= fogFarClip) {
    fogRate = ((1.0f - (fogRange / fogFarClip)) * 5.5f) + 1.5f;
  } else {
    fogRate = 1.5f;
  }

  return fogRate;
}

CShaderEffect

CShaderEffect::SetFogParams

The given fog params and fog color set up to be passed to the GPU when this function is called. Values typically or always originate from DayNight.

Logic

void CShaderEffect::SetFogParams(float fogStart, float fogEnd, float fogRate, const CArgb *fogColor, float a5) {
  if (CShaderEffect::s_enableShaders) {
    CShaderEffect::s_fogColorAlphaRef = fogColor / 255.0f;

    float fogRange = fogEnd - fogStart;


    // s_fogMul is set to 1.0 in CShaderEffect::InitShaderSystem, and does not appear to be modified elsewhere
    float fogMul = CShaderEffect::s_fogMul;

    CShaderEffect::s_fogParams.x = -(1.0f / fogRange) * fogMul;
    CShaderEffect::s_fogParams.y = (1.0f / fogRange) * fogEnd;
    CShaderEffect::s_fogParams.z = fogRate;

    // w is unknown; often forcibly set to 0.0; possibly something to do with intersecting m_liquidPlane in CM2SceneRender::SetupLighting
    CShaderEffect::s_fogParams.w = a5;
  }
}