Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Deamon87 committed Jul 10, 2024
1 parent 0c134ec commit 3141d45
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 38 deletions.
8 changes: 8 additions & 0 deletions src/database/CSqliteDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ bool CSqliteDB::getLightParamData(int lightParamId, int time, LightParamData &li
getLightParamDataStatement.setInputs(lightParamId);
bool hasSecondOverrideSphere = getLightParamDataStatement.getFieldIndex("Field_11_0_0_54210_001_0");
if (getLightParamDataStatement.execute()) {
lightParamData.glow = getLightParamDataStatement.getField("Glow").getDouble();
lightParamData.lightSkyBoxId = getLightParamDataStatement.getField("LightSkyboxID").getInt();
Expand All @@ -394,6 +396,12 @@ bool CSqliteDB::getLightParamData(int lightParamId, int time, LightParamData &li
lightParamData.oceanShallowAlpha = getLightParamDataStatement.getField("OceanShallowAlpha").getDouble();
lightParamData.oceanDeepAlpha = getLightParamDataStatement.getField("OceanDeepAlpha").getDouble();
lightParamData.lightParamFlags = getLightParamDataStatement.getField("Flags").getInt();
if (hasSecondOverrideSphere) {
lightParamData.celestialBodyOverride2[0] = getLightParamDataStatement.getField("Field_11_0_0_54210_001_0").getDouble();
lightParamData.celestialBodyOverride2[1] = getLightParamDataStatement.getField("Field_11_0_0_54210_001_1").getDouble();
lightParamData.celestialBodyOverride2[2] = getLightParamDataStatement.getField("Field_11_0_0_54210_001_2").getDouble();
}
} else {
//Record not found
return false;
Expand Down
68 changes: 39 additions & 29 deletions wowViewerLib/src/engine/algorithms/mathHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,8 @@ float doSomeConvert(float a) {
return res;
}

mathfu::vec3 MathHelper::calcExteriorColorDir(const mathfu::mat4 &lookAtMat, int time) {
// Phi Table
static constexpr std::array<std::array<float, 2>, 5> sunPhiTable = {
namespace SkyConstantsAndFunctions {
static constexpr std::array<std::array<float, 2>, 5> sunPhiTable = {
{
{ 0.25f, 1.7453293f },
{ 0.49652779f, 0.08726646f},
Expand Down Expand Up @@ -862,44 +861,55 @@ mathfu::vec3 MathHelper::calcExteriorColorDir(const mathfu::mat4 &lookAtMat, int
}
};

enum class SkyDataType : int { SK_SUN, SK_MOON, SK_DIR_LIGHT };

template <SkyDataType T>
mathfu::vec3 getVector(int time) {
float timeF = time / 2880.0f;

float phi = sunPhiTable[0][1];
float theta = sunThetaTable[0][1];

//Find Index
float timeF = time / 2880.0f;
float phi = 0.0f;
float theta = 0.0f;

if constexpr (T == SkyDataType::SK_DIR_LIGHT) {
phi = InterpTable<4>(directionalLightPhiTable, timeF);
theta = InterpTable<4>(directionalLightThetaTable, timeF);
}
if constexpr (T == SkyDataType::SK_SUN) {
phi = InterpTable<5>(sunPhiTable, timeF);
theta = InterpTable<3>(sunThetaTable, timeF);
}
if constexpr (T == SkyDataType::SK_MOON) {
phi = InterpTable<5>(moonPhiTable, timeF);
theta = InterpTable<3>(moonThetaTable, timeF);
}

phi = InterpTable<4>(directionalLightPhiTable, timeF);
theta = InterpTable<4>(directionalLightThetaTable, timeF);
constexpr float INV_PI = 1.0f / M_PI;

// if ( timeF >= 0.22222222f && timeF <= 0.81944448f )
// {
// phi = InterpTable<5>(sunPhiTable, timeF);
// theta = InterpTable<3>(sunThetaTable, timeF);
// }
// else
// {
// phi = InterpTable<5>(moonPhiTable, timeF);
// theta = InterpTable<3>(moonThetaTable, timeF);
// }
constexpr float INV_PI = 1.0f / M_PI;
float sinPhi = doSomeConvert(phi * INV_PI - 0.5f);
float cosPhi = doSomeConvert(phi * INV_PI);

float sinPhi = doSomeConvert(phi * INV_PI - 0.5f);
float cosPhi = doSomeConvert(phi * INV_PI);
float sinTheta = doSomeConvert(theta * INV_PI + -0.5f);
float cosTheta = doSomeConvert(theta * INV_PI);

float sinTheta = doSomeConvert(theta * INV_PI + -0.5f);
float cosTheta = doSomeConvert(theta * INV_PI);
mathfu::vec3 vec = mathfu::vec3(sinPhi * cosTheta, sinPhi * sinTheta, cosPhi);
return vec;
}
}

mathfu::vec3 MathHelper::calcExteriorColorDir(const mathfu::mat4 &lookAtMat, int time) {
using namespace SkyConstantsAndFunctions;

mathfu::vec4 sunDirWorld = mathfu::vec4(sinPhi * cosTheta, sinPhi * sinTheta, cosPhi, 0);
// sunDirWorld = mathfu::vec4(sunDirWorld.x, sunDirWorld.x, sunDirWorld.x, 0);
mathfu::vec4 sunDirWorld = mathfu::vec4(getVector<SkyDataType::SK_DIR_LIGHT>(time), 0.0f);
sunDirWorld = mathfu::vec4(sunDirWorld.xyz().Normalized(), 0.0f);
// mathfu::vec4 sunDirWorld = mathfu::vec4(sinPhi * cosTheta, sinPhi * sinTheta, cosPhi, 0);
// mathfu::vec4 sunDirWorld = mathfu::vec4(-0.30822, -0.30822, -0.89999998, 0);

return (lookAtMat.Inverse().Transpose() * sunDirWorld).xyz().Normalized();
}
mathfu::vec3 MathHelper::calcSunPlanetPos(const mathfu::mat4 &lookAtMat, int time) {
using namespace SkyConstantsAndFunctions;

mathfu::vec4 sunPlanetPos = mathfu::vec4(getVector<SkyDataType::SK_SUN>(time), 0.0f);
return sunPlanetPos.xyz();
}

mathfu::vec3 MathHelper::hsv2rgb(const MathHelper::hsv &in) {
double hh, p, q, t, ff;
Expand Down
1 change: 1 addition & 0 deletions wowViewerLib/src/engine/algorithms/mathHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class MathHelper {

static float distanceFromAABBToPoint2DSquared(const mathfu::vec2 aabb[2], mathfu::vec2 &p);
static mathfu::vec3 calcExteriorColorDir(const mathfu::mat4 &lookAtMat, int time);
static mathfu::vec3 calcSunPlanetPos(const mathfu::mat4 &lookAtMat, int time);
};

const float ROUNDING_ERROR_f32 = 0.001f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,18 @@ void DayNightLightHolder::updateLightAndSkyboxData(const HMapRenderPlan &mapRend

FogResult exteriorFogResult;

auto fdd = mapRenderPlan->frameDependentData;

std::vector<LightResult> lightResults;
if ((m_api->databaseHandler != nullptr)) {
//Check zoneLight
SkyColors skyColors;
ExteriorColors exteriorColors;

LiquidColors liquidColors;
SkyBodyData skyBodyData;

getLightResultsFromDB(frustumData.cameraPos, config, skyColors, exteriorColors, exteriorFogResult, liquidColors, &stateForConditions);
getLightResultsFromDB(frustumData.cameraPos, config, skyColors, skyBodyData, exteriorColors, exteriorFogResult, liquidColors, &stateForConditions);

//TODO: restore skyboxes
/*
Expand Down Expand Up @@ -200,6 +203,22 @@ void DayNightLightHolder::updateLightAndSkyboxData(const HMapRenderPlan &mapRend
}
*/

{
mathfu::vec3 sunPlanetPosVec3 = MathHelper::calcSunPlanetPos(
mapRenderPlan->renderingMatrices->lookAtMat,
m_api->getConfig()->currentTime
) + frustumData.cameraPos;

if (skyBodyData.celestialBodyOverride2.LengthSquared() > 0.0f) {
sunPlanetPosVec3 = mathfu::vec3(
skyBodyData.celestialBodyOverride2[0],
skyBodyData.celestialBodyOverride2[1],
skyBodyData.celestialBodyOverride2[2]);
}
mathfu::vec4 sunPlanetPos = mathfu::vec4((sunPlanetPosVec3 - frustumData.cameraPos).Normalized(), 0.0f);
fdd->sunDirection = (frustumData.viewMat.Inverse().Transpose() * sunPlanetPos).xyz().Normalized();
}

float ambientMult = areaRecord.ambientMultiplier * 2.0f + 1;

if (config->glowSource == EParameterSource::eDatabase) {
Expand Down Expand Up @@ -442,12 +461,13 @@ void DayNightLightHolder::fixLightTimedData(LightTimedData &data, float farClip,
fogScalarOverride = std::min(fogScalarOverride, -0.2f);
}

// if ( data.FogHeightScaler == 0.0f )
// data.FogHeightDensity = data.FogDensity;
if ( data.FogHeightScaler == 0.0f )
data.FogHeightDensity = data.FogDensity;
}

void DayNightLightHolder::getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config,
SkyColors &skyColors,
SkyBodyData &skyBodyData,
ExteriorColors &exteriorColors,
FogResult &fogResult,
LiquidColors &liquidColors,
Expand Down Expand Up @@ -527,6 +547,11 @@ void DayNightLightHolder::getLightResultsFromDB(mathfu::vec3 &cameraVec3, const
float blendTimeCoeff = (config->currentTime - lightParamData.lightTimedData[0].time) / (float)(lightParamData.lightTimedData[1].time - lightParamData.lightTimedData[0].time);
blendTimeCoeff = std::min<float>(std::max<float>(blendTimeCoeff, 0.0f), 1.0f);

skyBodyData.celestialBodyOverride2 = mathfu::vec3(
lightParamData.celestialBodyOverride2[0],
lightParamData.celestialBodyOverride2[1],
lightParamData.celestialBodyOverride2[2]
);

auto &dataA = lightParamData.lightTimedData[0];
auto &dataB = lightParamData.lightTimedData[1];
Expand Down Expand Up @@ -622,9 +647,9 @@ void DayNightLightHolder::getLightResultsFromDB(mathfu::vec3 &cameraVec3, const
fogResult.HeightEndFogColor = mixMembers<3>(lightParamData, &LightTimedData::EndFogHeightColor, blendTimeCoeff);
fogResult.FogStartOffset = mixMembers<1>(lightParamData, &LightTimedData::FogStartOffset, blendTimeCoeff);

// if (fogResult.FogHeightCoefficients.LengthSquared() <= 0.00000011920929f ){
// fogResult.FogHeightCoefficients = mathfu::vec4(0,0,1,0);
// }
if (fogResult.FogHeightCoefficients.LengthSquared() <= 0.00000011920929f ){
fogResult.FogHeightCoefficients = mathfu::vec4(0,0,1,0);
}

if (
(fogResult.MainFogCoefficients.LengthSquared()) > 0.00000011920929f ||
Expand Down Expand Up @@ -653,6 +678,9 @@ void DayNightLightHolder::createMinFogDistances() {

switch ( m_mapId )
{
case 2695:
m_minFogDist1 = maxFarClip(7000.0);
break;
case 1492:
m_minFogDist1 = maxFarClip(7000.0);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DayNightLightHolder {

void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config,
SkyColors &skyColors,
SkyBodyData &skyBodyData,
ExteriorColors &exteriorColors,
FogResult &fogResult,
LiquidColors &liquidColors,
Expand Down
3 changes: 3 additions & 0 deletions wowViewerLib/src/include/database/dbStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ struct LightParamData {
float oceanDeepAlpha;
int lightParamFlags = 0;

std::array<float, 3> celestialBodyOverride;
std::array<float, 3> celestialBodyOverride2;

std::string skyBoxName;
int skyBoxFdid;
int skyBoxFlags;
Expand Down
8 changes: 8 additions & 0 deletions wowViewerLib/src/renderer/mapScene/FrameDependentData.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ struct SkyColors {
mathfu::vec4 SkyFogColor;
};

struct SkyBodyData {
mathfu::vec3 celestialBodyOverride;
mathfu::vec3 celestialBodyOverride2;
};

struct LiquidColors {
mathfu::vec4 closeRiverColor_shallowAlpha = mathfu::vec4(0,0,0,0);
mathfu::vec4 farRiverColor_deepAlpha = mathfu::vec4(0,0,0,0);
Expand Down Expand Up @@ -86,6 +91,9 @@ struct FrameDependantData {
bool overrideValuesWithFinalFog = false;
SkyColors skyColors;

//Planet data
mathfu::vec3 sunDirection;


//Fog params
bool FogDataFound = false;
Expand Down
6 changes: 3 additions & 3 deletions wowViewerLib/src/renderer/mapScene/MapSceneRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void MapSceneRenderer::updateSceneWideChunk(const std::shared_ptr<IBufferChunkVe
);

fogData.sunAngle_and_sunColor = mathfu::vec4(
1.0f,//fogResult.SunFogAngle,
fogResult.SunFogAngle,
fogResult.SunFogColor.x,
fogResult.SunFogColor.y,
fogResult.SunFogColor.z
Expand All @@ -244,10 +244,10 @@ void MapSceneRenderer::updateSceneWideChunk(const std::shared_ptr<IBufferChunkVe
1000.0f
);
fogData.sunPercentage = mathfu::vec4(
0.0f, //fogResult.SunAngleBlend * fogResult.SunFogStrength,
fogResult.SunAngleBlend * fogResult.SunFogStrength,
0, 1.0, 1.0);
fogData.sunDirection_and_fogZScalar = mathfu::vec4(
fdd->exteriorDirectColorDir, //TODO: for fog this is calculated from SUN position
fdd->sunDirection,
fogResult.FogZScalar
);
fogData.heightFogCoeff = fogResult.FogHeightCoefficients;
Expand Down

0 comments on commit 3141d45

Please sign in to comment.