mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 20:02:40 +01:00
Interpolate between weather types too
This commit is contained in:
parent
23fc9bbbe8
commit
9f68e4c95d
@ -1,34 +1,59 @@
|
|||||||
#include "Weather.hpp"
|
#include "Weather.hpp"
|
||||||
|
|
||||||
#define MIXPROP(prop) data.prop = glm::mix(x.prop, y.prop, a)
|
|
||||||
|
|
||||||
Weather::Entry Weather::getWeatherData(WeatherCondition cond, float tod) {
|
namespace {
|
||||||
const auto i = size_t(cond) * 24;
|
Weather::Entry interpolateWeather(const Weather::Entry& a,
|
||||||
RW_ASSERT(i < entries.size());
|
const Weather::Entry& b,
|
||||||
|
float t) {
|
||||||
size_t hour = std::floor(tod);
|
#define MIXPROP(prop) glm::mix(a.prop, b.prop, t)
|
||||||
const auto& x = entries[i + hour];
|
return {
|
||||||
const auto& y = entries[i + (hour + 1) % 24];
|
MIXPROP(ambientColor),
|
||||||
const float a = tod - std::floor(tod);
|
MIXPROP(directLightColor),
|
||||||
|
MIXPROP(skyTopColor),
|
||||||
Entry data;
|
MIXPROP(skyBottomColor),
|
||||||
MIXPROP(ambientColor);
|
MIXPROP(sunCoreColor),
|
||||||
MIXPROP(directLightColor);
|
MIXPROP(sunCoronaColor),
|
||||||
MIXPROP(skyTopColor);
|
MIXPROP(sunCoreSize),
|
||||||
MIXPROP(skyBottomColor);
|
MIXPROP(sunCoronaSize),
|
||||||
MIXPROP(sunCoreColor);
|
MIXPROP(sunBrightness),
|
||||||
MIXPROP(sunCoreSize);
|
MIXPROP(shadowIntensity),
|
||||||
MIXPROP(sunCoronaSize);
|
MIXPROP(lightShading),
|
||||||
MIXPROP(sunBrightness);
|
MIXPROP(poleShading),
|
||||||
MIXPROP(shadowIntensity);
|
MIXPROP(farClipping),
|
||||||
MIXPROP(lightShading);
|
MIXPROP(fogStart),
|
||||||
MIXPROP(poleShading);
|
MIXPROP(amountGroundLight),
|
||||||
MIXPROP(farClipping);
|
MIXPROP(lowCloudColor),
|
||||||
MIXPROP(fogStart);
|
MIXPROP(topCloudColor),
|
||||||
MIXPROP(amountGroundLight);
|
MIXPROP(bottomCloudColor),
|
||||||
MIXPROP(lowCloudColor);
|
{}
|
||||||
MIXPROP(topCloudColor);
|
};
|
||||||
MIXPROP(bottomCloudColor);
|
#undef MIXPROP
|
||||||
|
}
|
||||||
return data;
|
}
|
||||||
|
|
||||||
|
Weather::Entry Weather::interpolate(WeatherCondition prev,
|
||||||
|
WeatherCondition next,
|
||||||
|
float a, float tod) {
|
||||||
|
const float t = tod - std::floor(tod);
|
||||||
|
const auto nI = size_t(next) * 24;
|
||||||
|
const auto pI = size_t(prev) * 24;
|
||||||
|
const auto hour = size_t(tod);
|
||||||
|
|
||||||
|
RW_ASSERT(nI < entries.size());
|
||||||
|
const auto& x = entries[nI + hour];
|
||||||
|
const auto& y = entries[nI + (hour + 1) % 24];
|
||||||
|
|
||||||
|
const auto& nextWeather = interpolateWeather(x, y, t);
|
||||||
|
|
||||||
|
if (a >= 1.0f) {
|
||||||
|
return nextWeather;
|
||||||
|
}
|
||||||
|
|
||||||
|
RW_ASSERT(pI < entries.size());
|
||||||
|
const auto& z = entries[pI + hour];
|
||||||
|
const auto& w = entries[pI + (hour + 1) % 24];
|
||||||
|
|
||||||
|
const auto& prevWeather = interpolateWeather(z, w, t);
|
||||||
|
|
||||||
|
return interpolateWeather(prevWeather, nextWeather, a);
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,9 @@ public:
|
|||||||
uint8_t unknown[4];
|
uint8_t unknown[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
Entry interpolate(WeatherCondition lastWeather,
|
||||||
* @brief getWeatherData returns interpolated Weather data for the time of
|
WeatherCondition nextWeather,
|
||||||
* day.
|
float a, float tod);
|
||||||
* @param cond weather condition
|
|
||||||
* @param tod float time of day
|
|
||||||
* @return Correctly interpolated values.
|
|
||||||
*/
|
|
||||||
Entry getWeatherData(WeatherCondition condition, float tod);
|
|
||||||
|
|
||||||
std::vector<Entry> entries;
|
std::vector<Entry> entries;
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ BasicState::BasicState()
|
|||||||
, lastWeather{0}
|
, lastWeather{0}
|
||||||
, nextWeather{0}
|
, nextWeather{0}
|
||||||
, forcedWeather{0}
|
, forcedWeather{0}
|
||||||
, weatherInterpolation{0}
|
, weatherInterpolation{1.0}
|
||||||
, weatherType{0}
|
, weatherType{0}
|
||||||
, cameraData{0}
|
, cameraData{0}
|
||||||
, cameraData2{0} {
|
, cameraData2{0} {
|
||||||
|
@ -243,10 +243,11 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
|
|||||||
|
|
||||||
const auto currentWeather = WeatherCondition(state->basic.nextWeather);
|
const auto currentWeather = WeatherCondition(state->basic.nextWeather);
|
||||||
const auto lastWeather = WeatherCondition(state->basic.lastWeather);
|
const auto lastWeather = WeatherCondition(state->basic.lastWeather);
|
||||||
/// @todo Interpolate when weatherInterpolation is < 1
|
const auto weatherTransition = state->basic.weatherInterpolation;
|
||||||
RW_UNUSED(lastWeather);
|
auto weather = world->data->weather.interpolate(lastWeather,
|
||||||
|
currentWeather,
|
||||||
auto weather = world->data->weather.getWeatherData(currentWeather, tod);
|
weatherTransition,
|
||||||
|
tod);
|
||||||
|
|
||||||
float theta = (tod / (60.f * 24.f) - 0.5f) * 2.f * glm::pi<float>();
|
float theta = (tod / (60.f * 24.f) - 0.5f) * 2.f * glm::pi<float>();
|
||||||
glm::vec3 sunDirection{
|
glm::vec3 sunDirection{
|
||||||
|
Loading…
Reference in New Issue
Block a user