Day night cycle: Difference between revisions

From wowdev
Jump to navigation Jump to search
(Added first stab at CShaderEffect::s_fogParams description)
(→‎CShaderEffect::SetFogParams: Fixed values (thanks schlumpf))
Line 96: Line 96:


  <nowiki>
  <nowiki>
float recipFogDelta = 1.0 / (fogEnd - fogStart);
float fogRange = fogEnd - fogStart;


CShaderEffect::s_fogParams.x = recipFogDelta * fogMul;
CShaderEffect::s_fogParams.x = -(1.0f / fogRange) * CShaderEffect::s_fogMul;
CShaderEffect::s_fogParams.y = recipFogDelta * fogEnd;
CShaderEffect::s_fogParams.y = (1.0f / fogRange) * fogEnd;
CShaderEffect::s_fogParams.z = fogRate;
CShaderEffect::s_fogParams.z = fogRate;
CShaderEffect::s_fogParams.w = unknown; // (often forcibly set to 0.0)
CShaderEffect::s_fogParams.w = unknown; // (final argument fed to CShaderEffect::SetFogParams; often forcibly set to 0.0)
</nowiki>
</nowiki>

Revision as of 00:42, 19 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 fogDelta = fogEnd - fogStart;

  float fogRate;

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

  return fogRate;
}

CShaderEffect

CShaderEffect::SetFogParams

The shader uniform for fogParams should look like the following, populated by values determined in the DayNight objects:

float fogRange = fogEnd - fogStart;

CShaderEffect::s_fogParams.x = -(1.0f / fogRange) * CShaderEffect::s_fogMul;
CShaderEffect::s_fogParams.y = (1.0f / fogRange) * fogEnd;
CShaderEffect::s_fogParams.z = fogRate;
CShaderEffect::s_fogParams.w = unknown; // (final argument fed to CShaderEffect::SetFogParams; often forcibly set to 0.0)