mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Load weather data into GLM types instead
This commit is contained in:
parent
5d4231f922
commit
4490d91ee1
@ -1,20 +1,6 @@
|
||||
#include "Weather.hpp"
|
||||
|
||||
RWTypes::RGB mix(RWTypes::RGB x, RWTypes::RGB y, float a) {
|
||||
RWTypes::RGB n;
|
||||
n.r = x.r * (1.f - a) + y.r * a;
|
||||
n.g = x.g * (1.f - a) + y.g * a;
|
||||
n.b = x.b * (1.f - a) + y.b * a;
|
||||
return n;
|
||||
}
|
||||
|
||||
int32_t mixint(int32_t x, int32_t y, float a) {
|
||||
return x * (1.f - a) + y * a;
|
||||
}
|
||||
|
||||
#define MIXPROP(prop) data.prop = mix(x.prop, y.prop, a)
|
||||
#define MIXPROP2(prop) data.prop = glm::mix(x.prop, y.prop, a)
|
||||
#define MIXPROP_INT(prop) data.prop = mixint(x.prop, y.prop, a)
|
||||
#define MIXPROP(prop) data.prop = glm::mix(x.prop, y.prop, a)
|
||||
|
||||
Weather::Entry Weather::getWeatherData(WeatherCondition cond, float tod) {
|
||||
const auto i = size_t(cond) * 24;
|
||||
@ -31,15 +17,15 @@ Weather::Entry Weather::getWeatherData(WeatherCondition cond, float tod) {
|
||||
MIXPROP(skyTopColor);
|
||||
MIXPROP(skyBottomColor);
|
||||
MIXPROP(sunCoreColor);
|
||||
MIXPROP2(sunCoreSize);
|
||||
MIXPROP2(sunCoronaSize);
|
||||
MIXPROP2(sunBrightness);
|
||||
MIXPROP_INT(shadowIntensity);
|
||||
MIXPROP_INT(lightShading);
|
||||
MIXPROP_INT(poleShading);
|
||||
MIXPROP2(farClipping);
|
||||
MIXPROP2(fogStart);
|
||||
MIXPROP2(amountGroundLight);
|
||||
MIXPROP(sunCoreSize);
|
||||
MIXPROP(sunCoronaSize);
|
||||
MIXPROP(sunBrightness);
|
||||
MIXPROP(shadowIntensity);
|
||||
MIXPROP(lightShading);
|
||||
MIXPROP(poleShading);
|
||||
MIXPROP(farClipping);
|
||||
MIXPROP(fogStart);
|
||||
MIXPROP(amountGroundLight);
|
||||
MIXPROP(lowCloudColor);
|
||||
MIXPROP(topCloudColor);
|
||||
MIXPROP(bottomCloudColor);
|
||||
|
@ -6,17 +6,19 @@
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
enum class WeatherCondition { Sunny = 0, Cloudy = 1, Rainy = 2, Foggy = 3 };
|
||||
|
||||
class Weather {
|
||||
public:
|
||||
struct Entry {
|
||||
RWTypes::RGB ambientColor;
|
||||
RWTypes::RGB directLightColor;
|
||||
RWTypes::RGB skyTopColor;
|
||||
RWTypes::RGB skyBottomColor;
|
||||
RWTypes::RGB sunCoreColor;
|
||||
RWTypes::RGB sunCoronaColor;
|
||||
glm::vec3 ambientColor;
|
||||
glm::vec3 directLightColor;
|
||||
glm::vec3 skyTopColor;
|
||||
glm::vec3 skyBottomColor;
|
||||
glm::vec3 sunCoreColor;
|
||||
glm::vec3 sunCoronaColor;
|
||||
float sunCoreSize;
|
||||
float sunCoronaSize;
|
||||
float sunBrightness;
|
||||
@ -26,9 +28,9 @@ public:
|
||||
float farClipping;
|
||||
float fogStart;
|
||||
float amountGroundLight;
|
||||
RWTypes::RGB lowCloudColor;
|
||||
RWTypes::RGB topCloudColor;
|
||||
RWTypes::RGB bottomCloudColor;
|
||||
glm::vec3 lowCloudColor;
|
||||
glm::vec3 topCloudColor;
|
||||
glm::vec3 bottomCloudColor;
|
||||
uint8_t unknown[4];
|
||||
};
|
||||
|
||||
|
@ -1,26 +1,14 @@
|
||||
#include <loaders/WeatherLoader.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
RWTypes::RGB readRGB(std::stringstream &ss) {
|
||||
RWTypes::RGB color;
|
||||
std::string r, g, b;
|
||||
|
||||
std::getline(ss, r, ' ');
|
||||
std::getline(ss, g, ' ');
|
||||
std::getline(ss, b, ' ');
|
||||
|
||||
color.r = atoi(r.c_str());
|
||||
color.b = atoi(b.c_str());
|
||||
color.g = atoi(g.c_str());
|
||||
|
||||
return color;
|
||||
glm::vec3 readRGB(std::stringstream &ss) {
|
||||
int r, g, b;
|
||||
ss >> r >> g >> b;
|
||||
return {r/255.f, g/255.f, b/255.f};
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,18 +23,7 @@ bool WeatherLoader::load(const std::string& filename, Weather& outWeather) {
|
||||
continue;
|
||||
|
||||
Weather::Entry weather;
|
||||
|
||||
// Convert tabs into spaces
|
||||
std::replace(line.begin(), line.end(), '\t', ' ');
|
||||
// Remove all duplicate whitespace
|
||||
line.erase(std::unique(line.begin(), line.end(),
|
||||
[](char l, char r) {
|
||||
return l == r && std::isspace(l);
|
||||
}),
|
||||
line.end());
|
||||
|
||||
std::stringstream ss(line);
|
||||
std::string tmpstr;
|
||||
|
||||
weather.ambientColor = readRGB(ss);
|
||||
weather.directLightColor = readRGB(ss);
|
||||
@ -55,32 +32,24 @@ bool WeatherLoader::load(const std::string& filename, Weather& outWeather) {
|
||||
weather.sunCoreColor = readRGB(ss);
|
||||
weather.sunCoronaColor = readRGB(ss);
|
||||
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.sunCoreSize = atof(tmpstr.c_str());
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.sunCoronaSize = atof(tmpstr.c_str());
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.sunBrightness = atof(tmpstr.c_str());
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.shadowIntensity = atoi(tmpstr.c_str());
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.lightShading = atoi(tmpstr.c_str());
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.poleShading = atoi(tmpstr.c_str());
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.farClipping = atof(tmpstr.c_str());
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.fogStart = atof(tmpstr.c_str());
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.amountGroundLight = atof(tmpstr.c_str());
|
||||
ss >> weather.sunCoreSize;
|
||||
ss >> weather.sunCoronaSize;
|
||||
ss >> weather.sunBrightness;
|
||||
ss >> weather.shadowIntensity;
|
||||
ss >> weather.lightShading;
|
||||
ss >> weather.poleShading;
|
||||
ss >> weather.farClipping;
|
||||
ss >> weather.fogStart;
|
||||
ss >> weather.amountGroundLight;
|
||||
|
||||
weather.lowCloudColor = readRGB(ss);
|
||||
weather.topCloudColor = readRGB(ss);
|
||||
weather.bottomCloudColor = readRGB(ss);
|
||||
|
||||
int d;
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
std::getline(ss, tmpstr, ' ');
|
||||
weather.unknown[i] = atoi(tmpstr.c_str());
|
||||
ss >> d;
|
||||
weather.unknown[i] = d;
|
||||
}
|
||||
|
||||
outWeather.entries.push_back(weather);
|
||||
|
@ -248,11 +248,6 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
|
||||
|
||||
auto weather = world->data->weather.getWeatherData(currentWeather, tod);
|
||||
|
||||
glm::vec3 skyTop = weather.skyTopColor;
|
||||
glm::vec3 skyBottom = weather.skyBottomColor;
|
||||
glm::vec3 ambient = weather.ambientColor;
|
||||
glm::vec3 dynamic = weather.directLightColor;
|
||||
|
||||
float theta = (tod / (60.f * 24.f) - 0.5f) * 2.f * glm::pi<float>();
|
||||
glm::vec3 sunDirection{
|
||||
sin(theta), 0.0, cos(theta),
|
||||
@ -265,18 +260,19 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
|
||||
auto view = _camera.getView();
|
||||
auto proj = _camera.frustum.projection();
|
||||
|
||||
Renderer::SceneUniformData sceneParams{proj,
|
||||
view,
|
||||
glm::vec4{ambient, 0.0f},
|
||||
glm::vec4{dynamic, 0.0f},
|
||||
glm::vec4(skyBottom, 1.f),
|
||||
glm::vec4(camera.position, 0.f),
|
||||
weather.fogStart,
|
||||
_camera.frustum.far};
|
||||
Renderer::SceneUniformData sceneParams{
|
||||
proj,
|
||||
view,
|
||||
glm::vec4{weather.ambientColor, 0.0f},
|
||||
glm::vec4{weather.directLightColor, 0.0f},
|
||||
glm::vec4{weather.skyBottomColor, 1.f},
|
||||
glm::vec4{camera.position, 0.f},
|
||||
weather.fogStart,
|
||||
_camera.frustum.far};
|
||||
|
||||
renderer->setSceneParameters(sceneParams);
|
||||
|
||||
renderer->clear(glm::vec4(skyBottom, 1.f));
|
||||
renderer->clear(glm::vec4(weather.skyBottomColor, 1.f));
|
||||
|
||||
_camera.frustum.update(proj * view);
|
||||
if (cullOverride) {
|
||||
@ -388,8 +384,10 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
|
||||
dp.count = skydomeSegments * skydomeRows * 6;
|
||||
|
||||
renderer->useProgram(skyProg.get());
|
||||
renderer->setUniform(skyProg.get(), "TopColor", glm::vec4(skyTop, 1.f));
|
||||
renderer->setUniform(skyProg.get(), "BottomColor", glm::vec4(skyBottom, 1.f));
|
||||
renderer->setUniform(skyProg.get(), "TopColor",
|
||||
glm::vec4{weather.skyTopColor, 1.f});
|
||||
renderer->setUniform(skyProg.get(), "BottomColor",
|
||||
glm::vec4{weather.skyBottomColor, 1.f});
|
||||
|
||||
renderer->draw(glm::mat4(), &skyDbuff, dp);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user