diff --git a/src/database/CSqliteDB.cpp b/src/database/CSqliteDB.cpp index a23d2e55..b47eec07 100644 --- a/src/database/CSqliteDB.cpp +++ b/src/database/CSqliteDB.cpp @@ -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(); @@ -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; diff --git a/wowViewerLib/src/engine/algorithms/mathHelper.cpp b/wowViewerLib/src/engine/algorithms/mathHelper.cpp index b962a176..c684ae9d 100644 --- a/wowViewerLib/src/engine/algorithms/mathHelper.cpp +++ b/wowViewerLib/src/engine/algorithms/mathHelper.cpp @@ -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, 5> sunPhiTable = { +namespace SkyConstantsAndFunctions { + static constexpr std::array, 5> sunPhiTable = { { { 0.25f, 1.7453293f }, { 0.49652779f, 0.08726646f}, @@ -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 + 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(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(time), 0.0f); + return sunPlanetPos.xyz(); +} mathfu::vec3 MathHelper::hsv2rgb(const MathHelper::hsv &in) { double hh, p, q, t, ff; diff --git a/wowViewerLib/src/engine/algorithms/mathHelper.h b/wowViewerLib/src/engine/algorithms/mathHelper.h index 82e7b6b5..4246837d 100644 --- a/wowViewerLib/src/engine/algorithms/mathHelper.h +++ b/wowViewerLib/src/engine/algorithms/mathHelper.h @@ -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; diff --git a/wowViewerLib/src/engine/objects/scenes/dayNightDataHolder/DayNightLightHolder.cpp b/wowViewerLib/src/engine/objects/scenes/dayNightDataHolder/DayNightLightHolder.cpp index 8794b2ee..37d82332 100644 --- a/wowViewerLib/src/engine/objects/scenes/dayNightDataHolder/DayNightLightHolder.cpp +++ b/wowViewerLib/src/engine/objects/scenes/dayNightDataHolder/DayNightLightHolder.cpp @@ -126,6 +126,8 @@ void DayNightLightHolder::updateLightAndSkyboxData(const HMapRenderPlan &mapRend FogResult exteriorFogResult; + auto fdd = mapRenderPlan->frameDependentData; + std::vector lightResults; if ((m_api->databaseHandler != nullptr)) { //Check zoneLight @@ -133,8 +135,9 @@ void DayNightLightHolder::updateLightAndSkyboxData(const HMapRenderPlan &mapRend 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 /* @@ -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) { @@ -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, @@ -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(std::max(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]; @@ -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 || @@ -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; diff --git a/wowViewerLib/src/engine/objects/scenes/dayNightDataHolder/DayNightLightHolder.h b/wowViewerLib/src/engine/objects/scenes/dayNightDataHolder/DayNightLightHolder.h index 771d5375..88359144 100644 --- a/wowViewerLib/src/engine/objects/scenes/dayNightDataHolder/DayNightLightHolder.h +++ b/wowViewerLib/src/engine/objects/scenes/dayNightDataHolder/DayNightLightHolder.h @@ -35,6 +35,7 @@ class DayNightLightHolder { void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, SkyColors &skyColors, + SkyBodyData &skyBodyData, ExteriorColors &exteriorColors, FogResult &fogResult, LiquidColors &liquidColors, diff --git a/wowViewerLib/src/include/database/dbStructs.h b/wowViewerLib/src/include/database/dbStructs.h index 2e2d9dfc..0adddf8a 100644 --- a/wowViewerLib/src/include/database/dbStructs.h +++ b/wowViewerLib/src/include/database/dbStructs.h @@ -84,6 +84,9 @@ struct LightParamData { float oceanDeepAlpha; int lightParamFlags = 0; + std::array celestialBodyOverride; + std::array celestialBodyOverride2; + std::string skyBoxName; int skyBoxFdid; int skyBoxFlags; diff --git a/wowViewerLib/src/renderer/mapScene/FrameDependentData.h b/wowViewerLib/src/renderer/mapScene/FrameDependentData.h index 81c0af69..d64e9d4d 100644 --- a/wowViewerLib/src/renderer/mapScene/FrameDependentData.h +++ b/wowViewerLib/src/renderer/mapScene/FrameDependentData.h @@ -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); @@ -86,6 +91,9 @@ struct FrameDependantData { bool overrideValuesWithFinalFog = false; SkyColors skyColors; +//Planet data + mathfu::vec3 sunDirection; + //Fog params bool FogDataFound = false; diff --git a/wowViewerLib/src/renderer/mapScene/MapSceneRenderer.cpp b/wowViewerLib/src/renderer/mapScene/MapSceneRenderer.cpp index 0568ce3e..11e6ebc2 100644 --- a/wowViewerLib/src/renderer/mapScene/MapSceneRenderer.cpp +++ b/wowViewerLib/src/renderer/mapScene/MapSceneRenderer.cpp @@ -232,7 +232,7 @@ void MapSceneRenderer::updateSceneWideChunk(const std::shared_ptrexteriorDirectColorDir, //TODO: for fog this is calculated from SUN position + fdd->sunDirection, fogResult.FogZScalar ); fogData.heightFogCoeff = fogResult.FogHeightCoefficients;