Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Deamon87 committed Jul 3, 2024
1 parent cb34cfb commit 15c05ea
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/ui/FrontendUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 4 additions & 1 deletion wowViewerLib/src/engine/objects/iMapApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class IMapApi {
virtual std::shared_ptr<WmoObject> getWmoObject(int fileDataId, SMMapObjDef &mapObjDef) = 0;
virtual std::shared_ptr<WmoObject> getWmoObject(std::string fileName, SMMapObjDefObj1 &mapObjDef) = 0;
virtual std::shared_ptr<WmoObject> getWmoObject(int fileDataId, SMMapObjDefObj1 &mapObjDef) = 0;
virtual void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, std::vector<LightResult> &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;
Expand Down
102 changes: 101 additions & 1 deletion wowViewerLib/src/engine/objects/scenes/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,68 @@ void Map::updateLightAndSkyboxData(const HMapRenderPlan &mapRenderPlan, MathHelp
}
}

void Map::getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, std::vector<LightResult> &lightResults, StateForConditions *stateForConditions) {
template <int T>
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<float, 4> a) {
//BGRA
return mathfu::vec4(
a[3],
a[2],
a[1],
a[0]
);
}

template <int C, typename T>
decltype(auto) mixMembers(LightParamData& data, T LightTimedData::*member, float blendTimeCoeff) {
if constexpr (C == 3) {
static_assert(std::is_same<T, int>::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<T, std::array<float, 4>>::value) {
return mix(floatArr(data.lightTimedData[0].*member), floatArr(data.lightTimedData[1].*member), blendTimeCoeff);
} else if constexpr (C == 4) {
static_assert(std::is_same<T, int>::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<T, float>::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 ;

Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion wowViewerLib/src/engine/objects/scenes/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ class Map : public IScene, public IMapApi {
// HDrawStage doGaussBlur(const HDrawStage &parentDrawStage, std::vector<HGUniformBufferChunk> &uniformBufferChunks) const;


void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config, std::vector<LightResult> &lightResults, StateForConditions *stateForConditions) override;
void getLightResultsFromDB(mathfu::vec3 &cameraVec3, const Config *config,
SkyColors &skyColors,
ExteriorColors &exteriorColors,
FogResult &fogResult, StateForConditions *stateForConditions) override;

void createAdtFreeLamdas();
};
Expand Down
6 changes: 3 additions & 3 deletions wowViewerLib/src/include/database/dbStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ struct LightTimedData {
float SunFogStrength;
int FogHeightColor;
int EndFogHeightColor;
float FogHeightCoefficients[4];
float MainFogCoefficients[4];
float HeightDensityFogCoeff[4];
std::array<float, 4> FogHeightCoefficients;
std::array<float, 4> MainFogCoefficients;
std::array<float, 4> HeightDensityFogCoeff;
};

struct LightParamData {
Expand Down

0 comments on commit 15c05ea

Please sign in to comment.