diff --git a/src/ui/FrontendUI.cpp b/src/ui/FrontendUI.cpp index 0ecf1326..ff755cb0 100644 --- a/src/ui/FrontendUI.cpp +++ b/src/ui/FrontendUI.cpp @@ -321,14 +321,14 @@ void FrontendUI::showCurrentStatsDialog() { if (cullStageData != nullptr && cullStageData->frameDependentData != nullptr ) { ImGui::Text("List of current Light.db2 ids:"); - for (auto lightId : cullStageData->frameDependentData->currentLightIds) { + for (auto lightId : cullStageData->frameDependentData->stateForConditions.currentLightIds) { ImGui::Text("%d", lightId); } ImGui::Separator(); ImGui::Text("List of current LightParams.db2 ids:"); - for (auto lightParamId : cullStageData->frameDependentData->currentLightParamIds) { + for (auto lightParamId : cullStageData->frameDependentData->stateForConditions.currentLightParams) { ImGui::Text("%d", lightParamId); } } diff --git a/wowViewerLib/src/engine/objects/iMapApi.h b/wowViewerLib/src/engine/objects/iMapApi.h index b84ad4f4..a2367173 100644 --- a/wowViewerLib/src/engine/objects/iMapApi.h +++ b/wowViewerLib/src/engine/objects/iMapApi.h @@ -19,7 +19,10 @@ class IMapApi { virtual std::shared_ptr getWmoObject(int fileDataId, SMMapObjDef &mapObjDef) = 0; virtual std::shared_ptr getWmoObject(std::string fileName, SMMapObjDefObj1 &mapObjDef) = 0; virtual std::shared_ptr getWmoObject(int fileDataId, SMMapObjDefObj1 &mapObjDef) = 0; - virtual void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, std::vector &lightResults,StateForConditions *stateForConditions) = 0; + virtual void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, + SkyColors &skyColors, + ExteriorColors &exteriorColors, + FogResult &fogResult, StateForConditions *stateForConditions) = 0; virtual animTime_t getCurrentSceneTime() = 0; diff --git a/wowViewerLib/src/engine/objects/scenes/map.cpp b/wowViewerLib/src/engine/objects/scenes/map.cpp index 5ad5d0e0..a86c761e 100644 --- a/wowViewerLib/src/engine/objects/scenes/map.cpp +++ b/wowViewerLib/src/engine/objects/scenes/map.cpp @@ -973,7 +973,68 @@ void Map::updateLightAndSkyboxData(const HMapRenderPlan &mapRenderPlan, MathHelp } } -void Map::getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, std::vector &lightResults, StateForConditions *stateForConditions) { +template +inline float getFloatFromInt(int value) { + if constexpr (T == 0) { + return (value & 0xFF) / 255.0f; + } + if constexpr (T == 1) { + return ((value >> 8) & 0xFF) / 255.0f; + } + if constexpr (T == 2) { + return ((value >> 16) & 0xFF) / 255.0f; + } +} + +inline mathfu::vec3 intToColor3(int a) { + //BGR + return mathfu::vec3( + getFloatFromInt<2>(a), + getFloatFromInt<1>(a), + getFloatFromInt<0>(a) + ); +} +inline mathfu::vec4 intToColor4(int a) { + //BGRA + return mathfu::vec4( + getFloatFromInt<2>(a), + getFloatFromInt<1>(a), + getFloatFromInt<0>(a), + getFloatFromInt<3>(a) + ); +} +inline mathfu::vec4 floatArr(std::array a) { + //BGRA + return mathfu::vec4( + a[3], + a[2], + a[1], + a[0] + ); +} + +template +decltype(auto) mixMembers(LightParamData& data, T LightTimedData::*member, float blendTimeCoeff) { + if constexpr (C == 3) { + static_assert(std::is_same::value, "the type must be int for vector component"); + return mix(intToColor3(data.lightTimedData[0].*member), intToColor3(data.lightTimedData[0].*member), blendTimeCoeff); + } + if constexpr (C == 4 && std::is_same>::value) { + return mix(floatArr(data.lightTimedData[0].*member), floatArr(data.lightTimedData[1].*member), blendTimeCoeff); + } else if constexpr (C == 4) { + static_assert(std::is_same::value, "the type must be int for vector component"); + return mix(intToColor4(data.lightTimedData[0].*member), intToColor4(data.lightTimedData[0].*member), blendTimeCoeff); + } + if constexpr (C == 1) { + static_assert(std::is_same::value, "the type must be float for one component"); + return mix(data.lightTimedData[0].*member, data.lightTimedData[0].*member, blendTimeCoeff); + } +} + +void Map::getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, + SkyColors &skyColors, + ExteriorColors &exteriorColors, + FogResult &fogResult, StateForConditions *stateForConditions) { if (m_api->databaseHandler == nullptr) return ; @@ -1044,8 +1105,47 @@ void Map::getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, LightParamData lightParamData; if (m_api->databaseHandler->getLightParamData(selectedLightParam, config->currentTime, lightParamData)) { + + float blendTimeCoeff = (config->currentTime - lightParamData.lightTimedData[0].time) / (float)(lightParamData.lightTimedData[1].time - lightParamData.lightTimedData[0].time); + + auto &dataA = lightParamData.lightTimedData[0]; + auto &dataB = lightParamData.lightTimedData[1]; //Blend two times using certain rules + //Ambient lights + + //Fog! + fogResult.FogEnd = mixMembers<1>(lightParamData, &LightTimedData::FogEnd, blendTimeCoeff); + fogResult.FogScaler = mixMembers<1>(lightParamData, &LightTimedData::FogScaler, blendTimeCoeff); + fogResult.FogDensity = mixMembers<1>(lightParamData, &LightTimedData::FogDensity, blendTimeCoeff); + fogResult.FogHeight = mixMembers<1>(lightParamData, &LightTimedData::FogHeight, blendTimeCoeff); + fogResult.FogHeightScaler = mixMembers<1>(lightParamData, &LightTimedData::FogHeightScaler, blendTimeCoeff); + fogResult.FogHeightDensity = mixMembers<1>(lightParamData, &LightTimedData::FogHeightDensity, blendTimeCoeff); + fogResult.SunFogAngle = mixMembers<1>(lightParamData, &LightTimedData::SunFogAngle, blendTimeCoeff); + + if (false) {//fdd->overrideValuesWithFinalFog) { + fogResult.FogColor = mixMembers<3>(lightParamData, &LightTimedData::EndFogColor, blendTimeCoeff); + } else { + fogResult.FogColor = mixMembers<3>(lightParamData, &LightTimedData::SkyFogColor, blendTimeCoeff); + } + + fogResult.EndFogColor = mixMembers<3>(lightParamData, &LightTimedData::EndFogColor, blendTimeCoeff); + fogResult.EndFogColorDistance = mixMembers<1>(lightParamData, &LightTimedData::EndFogColorDistance, blendTimeCoeff); + fogResult.SunFogColor = mixMembers<3>(lightParamData, &LightTimedData::SunFogColor, blendTimeCoeff); + fogResult.SunFogStrength = mixMembers<1>(lightParamData, &LightTimedData::SunFogStrength, blendTimeCoeff); + fogResult.FogHeightColor = mixMembers<3>(lightParamData, &LightTimedData::FogHeightColor, blendTimeCoeff); + fogResult.FogHeightCoefficients = mixMembers<4>(lightParamData, &LightTimedData::FogHeightCoefficients, blendTimeCoeff); + fogResult.MainFogCoefficients = mixMembers<4>(lightParamData, &LightTimedData::MainFogCoefficients, blendTimeCoeff); + fogResult.HeightDensityFogCoefficients = mixMembers<4>(lightParamData, &LightTimedData::MainFogCoefficients, blendTimeCoeff); + + fogResult.FogZScalar = mixMembers<1>(lightParamData, &LightTimedData::FogZScalar, blendTimeCoeff); +// fogResult.LegacyFogScalar = mixMembers<1>(lightParamData, &LightTimedData::LegacyFogScalar, blendTimeCoeff); + fogResult.MainFogStartDist = mixMembers<1>(lightParamData, &LightTimedData::MainFogStartDist, blendTimeCoeff); + fogResult.MainFogEndDist = mixMembers<1>(lightParamData, &LightTimedData::MainFogEndDist, blendTimeCoeff); +// fogResult.FogBlendAlpha = mixMembers<1>(lightParamData, &LightTimedData::FogBlendAlpha, blendTimeCoeff); + fogResult.HeightEndFogColor = mixMembers<3>(lightParamData, &LightTimedData::EndFogHeightColor, blendTimeCoeff); + fogResult.FogStartOffset = mixMembers<1>(lightParamData, &LightTimedData::FogStartOffset, blendTimeCoeff); + } } void Map::getPotentialEntities(const MathHelper::FrustumCullingData &frustumData, diff --git a/wowViewerLib/src/engine/objects/scenes/map.h b/wowViewerLib/src/engine/objects/scenes/map.h index 0a2cecd3..17210d93 100644 --- a/wowViewerLib/src/engine/objects/scenes/map.h +++ b/wowViewerLib/src/engine/objects/scenes/map.h @@ -207,7 +207,10 @@ class Map : public IScene, public IMapApi { // HDrawStage doGaussBlur(const HDrawStage &parentDrawStage, std::vector &uniformBufferChunks) const; - void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, std::vector &lightResults, StateForConditions *stateForConditions) override; + void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, + SkyColors &skyColors, + ExteriorColors &exteriorColors, + FogResult &fogResult, StateForConditions *stateForConditions) override; void createAdtFreeLamdas(); }; diff --git a/wowViewerLib/src/include/database/dbStructs.h b/wowViewerLib/src/include/database/dbStructs.h index 555d4531..7b33567c 100644 --- a/wowViewerLib/src/include/database/dbStructs.h +++ b/wowViewerLib/src/include/database/dbStructs.h @@ -68,9 +68,9 @@ struct LightTimedData { float SunFogStrength; int FogHeightColor; int EndFogHeightColor; - float FogHeightCoefficients[4]; - float MainFogCoefficients[4]; - float HeightDensityFogCoeff[4]; + std::array FogHeightCoefficients; + std::array MainFogCoefficients; + std::array HeightDensityFogCoeff; }; struct LightParamData {