Rendering/DayNight: Difference between revisions
Jump to navigation
Jump to search
(Adding reversed logic for DayNight::SetDirection) |
|||
Line 5: | Line 5: | ||
== DayNight::SetDirection == | == DayNight::SetDirection == | ||
<tt>DayNight::SetDirection</tt> calculates a <tt>C3Vector</tt> containing the direction for the global light, aka <tt>sunDir</tt>. | <tt>DayNight::SetDirection</tt> calculates a <tt>C3Vector</tt> containing the direction vector for the global light, aka <tt>sunDir</tt>. | ||
This direction vector is transformed by the view matrix prior to being uploaded to the shader. | |||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> |
Revision as of 06:14, 24 April 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::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;
}