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"
|
#include "Weather.hpp"
|
||||||
|
|
||||||
RWTypes::RGB mix(RWTypes::RGB x, RWTypes::RGB y, float a) {
|
#define MIXPROP(prop) data.prop = glm::mix(x.prop, y.prop, 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)
|
|
||||||
|
|
||||||
Weather::Entry Weather::getWeatherData(WeatherCondition cond, float tod) {
|
Weather::Entry Weather::getWeatherData(WeatherCondition cond, float tod) {
|
||||||
const auto i = size_t(cond) * 24;
|
const auto i = size_t(cond) * 24;
|
||||||
@ -31,15 +17,15 @@ Weather::Entry Weather::getWeatherData(WeatherCondition cond, float tod) {
|
|||||||
MIXPROP(skyTopColor);
|
MIXPROP(skyTopColor);
|
||||||
MIXPROP(skyBottomColor);
|
MIXPROP(skyBottomColor);
|
||||||
MIXPROP(sunCoreColor);
|
MIXPROP(sunCoreColor);
|
||||||
MIXPROP2(sunCoreSize);
|
MIXPROP(sunCoreSize);
|
||||||
MIXPROP2(sunCoronaSize);
|
MIXPROP(sunCoronaSize);
|
||||||
MIXPROP2(sunBrightness);
|
MIXPROP(sunBrightness);
|
||||||
MIXPROP_INT(shadowIntensity);
|
MIXPROP(shadowIntensity);
|
||||||
MIXPROP_INT(lightShading);
|
MIXPROP(lightShading);
|
||||||
MIXPROP_INT(poleShading);
|
MIXPROP(poleShading);
|
||||||
MIXPROP2(farClipping);
|
MIXPROP(farClipping);
|
||||||
MIXPROP2(fogStart);
|
MIXPROP(fogStart);
|
||||||
MIXPROP2(amountGroundLight);
|
MIXPROP(amountGroundLight);
|
||||||
MIXPROP(lowCloudColor);
|
MIXPROP(lowCloudColor);
|
||||||
MIXPROP(topCloudColor);
|
MIXPROP(topCloudColor);
|
||||||
MIXPROP(bottomCloudColor);
|
MIXPROP(bottomCloudColor);
|
||||||
|
@ -6,17 +6,19 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
enum class WeatherCondition { Sunny = 0, Cloudy = 1, Rainy = 2, Foggy = 3 };
|
enum class WeatherCondition { Sunny = 0, Cloudy = 1, Rainy = 2, Foggy = 3 };
|
||||||
|
|
||||||
class Weather {
|
class Weather {
|
||||||
public:
|
public:
|
||||||
struct Entry {
|
struct Entry {
|
||||||
RWTypes::RGB ambientColor;
|
glm::vec3 ambientColor;
|
||||||
RWTypes::RGB directLightColor;
|
glm::vec3 directLightColor;
|
||||||
RWTypes::RGB skyTopColor;
|
glm::vec3 skyTopColor;
|
||||||
RWTypes::RGB skyBottomColor;
|
glm::vec3 skyBottomColor;
|
||||||
RWTypes::RGB sunCoreColor;
|
glm::vec3 sunCoreColor;
|
||||||
RWTypes::RGB sunCoronaColor;
|
glm::vec3 sunCoronaColor;
|
||||||
float sunCoreSize;
|
float sunCoreSize;
|
||||||
float sunCoronaSize;
|
float sunCoronaSize;
|
||||||
float sunBrightness;
|
float sunBrightness;
|
||||||
@ -26,9 +28,9 @@ public:
|
|||||||
float farClipping;
|
float farClipping;
|
||||||
float fogStart;
|
float fogStart;
|
||||||
float amountGroundLight;
|
float amountGroundLight;
|
||||||
RWTypes::RGB lowCloudColor;
|
glm::vec3 lowCloudColor;
|
||||||
RWTypes::RGB topCloudColor;
|
glm::vec3 topCloudColor;
|
||||||
RWTypes::RGB bottomCloudColor;
|
glm::vec3 bottomCloudColor;
|
||||||
uint8_t unknown[4];
|
uint8_t unknown[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,26 +1,14 @@
|
|||||||
#include <loaders/WeatherLoader.hpp>
|
#include <loaders/WeatherLoader.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
RWTypes::RGB readRGB(std::stringstream &ss) {
|
glm::vec3 readRGB(std::stringstream &ss) {
|
||||||
RWTypes::RGB color;
|
int r, g, b;
|
||||||
std::string r, g, b;
|
ss >> r >> g >> b;
|
||||||
|
return {r/255.f, g/255.f, b/255.f};
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,18 +23,7 @@ bool WeatherLoader::load(const std::string& filename, Weather& outWeather) {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Weather::Entry weather;
|
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::stringstream ss(line);
|
||||||
std::string tmpstr;
|
|
||||||
|
|
||||||
weather.ambientColor = readRGB(ss);
|
weather.ambientColor = readRGB(ss);
|
||||||
weather.directLightColor = readRGB(ss);
|
weather.directLightColor = readRGB(ss);
|
||||||
@ -55,32 +32,24 @@ bool WeatherLoader::load(const std::string& filename, Weather& outWeather) {
|
|||||||
weather.sunCoreColor = readRGB(ss);
|
weather.sunCoreColor = readRGB(ss);
|
||||||
weather.sunCoronaColor = readRGB(ss);
|
weather.sunCoronaColor = readRGB(ss);
|
||||||
|
|
||||||
std::getline(ss, tmpstr, ' ');
|
ss >> weather.sunCoreSize;
|
||||||
weather.sunCoreSize = atof(tmpstr.c_str());
|
ss >> weather.sunCoronaSize;
|
||||||
std::getline(ss, tmpstr, ' ');
|
ss >> weather.sunBrightness;
|
||||||
weather.sunCoronaSize = atof(tmpstr.c_str());
|
ss >> weather.shadowIntensity;
|
||||||
std::getline(ss, tmpstr, ' ');
|
ss >> weather.lightShading;
|
||||||
weather.sunBrightness = atof(tmpstr.c_str());
|
ss >> weather.poleShading;
|
||||||
std::getline(ss, tmpstr, ' ');
|
ss >> weather.farClipping;
|
||||||
weather.shadowIntensity = atoi(tmpstr.c_str());
|
ss >> weather.fogStart;
|
||||||
std::getline(ss, tmpstr, ' ');
|
ss >> weather.amountGroundLight;
|
||||||
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());
|
|
||||||
|
|
||||||
weather.lowCloudColor = readRGB(ss);
|
weather.lowCloudColor = readRGB(ss);
|
||||||
weather.topCloudColor = readRGB(ss);
|
weather.topCloudColor = readRGB(ss);
|
||||||
weather.bottomCloudColor = readRGB(ss);
|
weather.bottomCloudColor = readRGB(ss);
|
||||||
|
|
||||||
|
int d;
|
||||||
for (size_t i = 0; i < 4; i++) {
|
for (size_t i = 0; i < 4; i++) {
|
||||||
std::getline(ss, tmpstr, ' ');
|
ss >> d;
|
||||||
weather.unknown[i] = atoi(tmpstr.c_str());
|
weather.unknown[i] = d;
|
||||||
}
|
}
|
||||||
|
|
||||||
outWeather.entries.push_back(weather);
|
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);
|
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>();
|
float theta = (tod / (60.f * 24.f) - 0.5f) * 2.f * glm::pi<float>();
|
||||||
glm::vec3 sunDirection{
|
glm::vec3 sunDirection{
|
||||||
sin(theta), 0.0, cos(theta),
|
sin(theta), 0.0, cos(theta),
|
||||||
@ -265,18 +260,19 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
|
|||||||
auto view = _camera.getView();
|
auto view = _camera.getView();
|
||||||
auto proj = _camera.frustum.projection();
|
auto proj = _camera.frustum.projection();
|
||||||
|
|
||||||
Renderer::SceneUniformData sceneParams{proj,
|
Renderer::SceneUniformData sceneParams{
|
||||||
view,
|
proj,
|
||||||
glm::vec4{ambient, 0.0f},
|
view,
|
||||||
glm::vec4{dynamic, 0.0f},
|
glm::vec4{weather.ambientColor, 0.0f},
|
||||||
glm::vec4(skyBottom, 1.f),
|
glm::vec4{weather.directLightColor, 0.0f},
|
||||||
glm::vec4(camera.position, 0.f),
|
glm::vec4{weather.skyBottomColor, 1.f},
|
||||||
weather.fogStart,
|
glm::vec4{camera.position, 0.f},
|
||||||
_camera.frustum.far};
|
weather.fogStart,
|
||||||
|
_camera.frustum.far};
|
||||||
|
|
||||||
renderer->setSceneParameters(sceneParams);
|
renderer->setSceneParameters(sceneParams);
|
||||||
|
|
||||||
renderer->clear(glm::vec4(skyBottom, 1.f));
|
renderer->clear(glm::vec4(weather.skyBottomColor, 1.f));
|
||||||
|
|
||||||
_camera.frustum.update(proj * view);
|
_camera.frustum.update(proj * view);
|
||||||
if (cullOverride) {
|
if (cullOverride) {
|
||||||
@ -388,8 +384,10 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
|
|||||||
dp.count = skydomeSegments * skydomeRows * 6;
|
dp.count = skydomeSegments * skydomeRows * 6;
|
||||||
|
|
||||||
renderer->useProgram(skyProg.get());
|
renderer->useProgram(skyProg.get());
|
||||||
renderer->setUniform(skyProg.get(), "TopColor", glm::vec4(skyTop, 1.f));
|
renderer->setUniform(skyProg.get(), "TopColor",
|
||||||
renderer->setUniform(skyProg.get(), "BottomColor", glm::vec4(skyBottom, 1.f));
|
glm::vec4{weather.skyTopColor, 1.f});
|
||||||
|
renderer->setUniform(skyProg.get(), "BottomColor",
|
||||||
|
glm::vec4{weather.skyBottomColor, 1.f});
|
||||||
|
|
||||||
renderer->draw(glm::mat4(), &skyDbuff, dp);
|
renderer->draw(glm::mat4(), &skyDbuff, dp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user