Commit e6abb48a authored by Dario Seyb's avatar Dario Seyb

added settings file for easier config

parent 7b2dead6
{
"shaders": "planets/earth",
"atmosphere": true,
"water": true,
"moons": 1
}
\ No newline at end of file
{
"shaders": "planets/jupiter",
"atmosphere": false,
"water": false,
"moons": 3
}
\ No newline at end of file
{
"shaders": "planets/mars",
"atmosphere": false,
"water": false,
"moons": 0
}
\ No newline at end of file
{
"resolution": [1280, 720],
"target_fps": 60,
"fullscreen": false,
"quality": "high",
"available_planet_prefabs": [
"earth",
"mars",
"jupiter"
],
"scene": "AtmosphereTest"
}
\ No newline at end of file
......@@ -33,13 +33,11 @@ void main()
depth = depthSample;
}
}
vec4 history = texture(uSamplerHistory, vTexCoord - motion.xy);
float factor = 0.85;
vec4 history = texture(uSamplerHistory, vTexCoord - motion);
vec4 current = texture(uSamplerColor, vTexCoord);
vec4 minNeighbour = current;
vec4 maxNeighbour = current;
......
......@@ -9,7 +9,7 @@
#pragma import "CommonDeferredFrag.glsl"
#pragma import "planets/earth_texture.glsl"
#pragma import "planets/earth/earth_texture.glsl"
#pragma import "terrain/generic_water_texture.glsl"
#pragma import "terrain/dispMappingWithWater_fsh.glsl"
#version 410 core
#pragma import "../setup/geometry.glsl"
#pragma import "../noise/noise3d.glsl"
#pragma import "../noise/noise4d.glsl"
#pragma import "../Utils.glsl"
#pragma import "../CommonDeferredFrag.glsl"
#pragma import "earth_texture.glsl"
#pragma import "../terrain/generic_water_texture.glsl"
#pragma import "../terrain/dispMappingWithWater_fsh.glsl"
#pragma import "../terrain/dispMapping_gsh.glsl"
#pragma import "../terrain/dispMapping_tcsh.glsl"
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "earth_texture.glsl"
#pragma import "../terrain/dispMapping_tesh.glsl"
#pragma import "../terrain/dispMapping_vsh.glsl"
#version 410 core
#pragma import "../../setup/geometry.glsl"
#pragma import "../../noise/noise3d.glsl"
#pragma import "../../noise/noise4d.glsl"
#pragma import "../../Utils.glsl"
#pragma import "../../CommonDeferredFrag.glsl"
#pragma import "earth_texture.glsl"
#pragma import "../../terrain/generic_water_texture.glsl"
#pragma import "../../terrain/dispMappingWithWater_fsh.glsl"
#pragma import "../../terrain/dispMapping_gsh.glsl"
#pragma import "../../terrain/dispMapping_tcsh.glsl"
#pragma import "../../noise/noise3d.glsl"
#pragma import "../../Utils.glsl"
#pragma import "earth_texture.glsl"
#pragma import "../../terrain/dispMapping_tesh.glsl"
#pragma import "../../terrain/dispMapping_vsh.glsl"
#version 410 core
#pragma import "../setup/geometry.glsl"
#pragma import "../CommonDeferredFrag.glsl"
#pragma import "gas_texture.glsl"
#pragma import "../terrain/plainSphere_fsh.glsl"
#pragma import "../terrain/plainSphere_gsh.glsl"
#pragma import "../terrain/plainSphere_tcsh.glsl"
#pragma import "../terrain/plainSphere_tesh.glsl"
#pragma import "../terrain/plainSphere_vsh.glsl"
#version 410 core
#pragma import "../../setup/geometry.glsl"
#pragma import "../../CommonDeferredFrag.glsl"
#pragma import "jupiter_texture.glsl"
#pragma import "../../terrain/plainSphere_fsh.glsl"
#pragma import "../../terrain/plainSphere_gsh.glsl"
#pragma import "../../terrain/plainSphere_tcsh.glsl"
#pragma import "../../terrain/plainSphere_tesh.glsl"
#pragma import "../../terrain/plainSphere_vsh.glsl"
#pragma import "../noise/noise3d.glsl"
#pragma import "../noise/noise2d.glsl"
#pragma import "../../noise/noise3d.glsl"
#pragma import "../../noise/noise2d.glsl"
//float getHeightNoise(vec3 normalizedPosInModelspace) {
......
#pragma import "../../terrain/dispMapping_gsh.glsl"
#pragma import "../../terrain/dispMapping_tcsh.glsl"
#pragma import "../../noise/noise3d.glsl"
#pragma import "../../Utils.glsl"
#pragma import "mars_texture.glsl"
#pragma import "../../terrain/dispMapping_tesh.glsl"
#pragma import "../../terrain/dispMapping_vsh.glsl"
float getContinentHeightNoise(vec3 normalizedPosInModelspace) {
return 2*(fbm_3d(normalizedPosInModelspace , 2, 1.25));
}
float getRidgedHeightNoise(vec3 normalizedPosInModelspace) {
return (.75 - abs(fbm_3d( normalizedPosInModelspace , 2, 40.)))/2.;
}
float getDetailHeightNoise(vec3 normalizedPosInModelspace) {
return fbm_3d( normalizedPosInModelspace , 2, 160.)/8.;
}
float getRidgedDetailsHeightNoise(vec3 normalizedPosInModelspace) {
return (.75 - abs(fbm_3d( normalizedPosInModelspace , 4, 8*640.)))/256.;
}
float getHeightNoise(vec3 normalizedPosInModelspace) {
return (getContinentHeightNoise(normalizedPosInModelspace)
+ getRidgedHeightNoise(normalizedPosInModelspace)
+ getDetailHeightNoise(normalizedPosInModelspace)
+ getRidgedDetailsHeightNoise(normalizedPosInModelspace))
* 2.;
}
#define SNOW_LEVEL .5
#define ROCK_LEVEL .3
#define PLANT_LEVEL .03
#define ROCK_SLOPE .6
vec4 texture_getColor(vec3 texCoord3d, vec3 upVectorNormalized, vec3 normalNormalized, float depth){
//float noiseVal1 = fbm_3d( texCoord3d,4, 128.*128.);// * 0.05;
float noiseOct1 = 0.;
float noiseOct2 = 0.;
float noiseOct3 = 0.;
float noiseOct4 = 0.;
float noiseOct5 = 0.;
noiseOct1 = snoise_3d(32.*128. * texCoord3d);
noiseOct2 = snoise_3d(64.*128. * texCoord3d);
noiseOct3 = snoise_3d(128.*128. * texCoord3d);
float heightPertubation = 1./2.*noiseOct1 + 1./4.*noiseOct2 + 1./8.*noiseOct3;
vec4 color = vec4(1., 1., 1., 1.);
float height =getHeightNoise(texCoord3d)/2.*.9 + heightPertubation * .1;
float dt = dot(normalNormalized, upVectorNormalized);
float cs = dt / (length(normalNormalized) * length(upVectorNormalized));
float phi = acos(dt);
float phiNormalized = 2*phi / M_PI; //scale results from [0, M_PI/2] to [0, 1]
float phiPertubation = 1./2.*noiseOct4 + 1./4.*noiseOct5;
float phiPert = .9*phiNormalized + .1 * phiPertubation;
if (height> SNOW_LEVEL && phiPert <= ROCK_SLOPE) {
color = vec4(1., 1., 1., 1.);
} else if (height> ROCK_LEVEL || phiPert > ROCK_SLOPE) {
color = vec4(.1, .1, .1, 1.);
} else if (height> PLANT_LEVEL) {
color = vec4(.2, .5,.15, 1.);
}else { //"sand""
color = vec4(1., .8, .55, 1.);
}
return color;
}
vec4 texture_getColor(vec3 texCoord3d, vec3 upVectorNormalized, vec3 normalNormalized){
return texture_getColor(texCoord3d, upVectorNormalized, normalNormalized, 1.);
}
float texture_getFinalHeight(vec3 normalizedPosInModelspace){
return 0.008 * getHeightNoise(normalizedPosInModelspace);
}
vec3 texture_getDisplacedPosition_modelspace(vec3 normalizedPosInModelspace, vec3 normalizedNormal) {
vec3 newPosition = normalizedPosInModelspace + normalizedNormal * texture_getFinalHeight(normalizedPosInModelspace);
return newPosition;
}
#version 410 core
#pragma import "../setup/geometry.glsl"
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "../CommonDeferredFrag.glsl"
#pragma import "moon_texture.glsl"
#pragma import "../terrain/dispMapping_fsh.glsl"
#pragma import "../terrain/dispMapping_gsh.glsl"
#pragma import "../terrain/dispMapping_tcsh.glsl"
#pragma import "../noise/noise3d.glsl"
#pragma import "../Utils.glsl"
#pragma import "earth_texture.glsl"
#pragma import "../terrain/dispMapping_tesh.glsl"
#pragma import "../terrain/dispMapping_vsh.glsl"
#version 410 core
#pragma import "../../setup/geometry.glsl"
#pragma import "../../noise/noise3d.glsl"
#pragma import "../../Utils.glsl"
#pragma import "../../CommonDeferredFrag.glsl"
#pragma import "moon_texture.glsl"
#pragma import "../../terrain/dispMapping_fsh.glsl"
#pragma import "../../terrain/dispMapping_gsh.glsl"
#pragma import "../../terrain/dispMapping_tcsh.glsl"
#pragma import "../../noise/noise3d.glsl"
#pragma import "../../Utils.glsl"
#pragma import "../earth/earth_texture.glsl"
#pragma import "../../terrain/dispMapping_tesh.glsl"
#pragma import "../../terrain/dispMapping_vsh.glsl"
"build\src\game\RelWithDebInfo\game.exe" AtmosphereTest ""
"build\src\game\RelWithDebInfo\game.exe" "config/settings.json"
./build/src/game/game AtmosphereTest ""
./build/src/game/game "config/settings.json"
......@@ -5,12 +5,14 @@
#include <engine/graphics/RendererSystem.hpp>
#include <engine/audio/AudioSystem.hpp>
#include <engine/events/EventSystem.hpp>
#include <engine/core/SettingsSystem.hpp>
#include <engine/core/SimulateEvent.hpp>
#include <array>
class GameLoopSystem : public System {
private:
SettingsSystem* m_settings;
EventSystem* m_events;
WindowSystem* m_window;
RendererSystem* m_renderer;
......
#pragma once
#include <engine/core/Context.hpp>
#include <engine/core/System.hpp>
#include <ACGL/Math/Math.hh>
enum class QualitySetting {
Low,
Medium,
High
};
struct PlanetMetaData {
std::string name;
std::string shaders;
bool hasAtmosphere;
bool hasWater;
uint64_t moonCount;
};
class SettingsSystem : public System {
private:
......@@ -10,19 +26,38 @@ private:
std::string m_shaderPath;
std::string m_soundPath;
std::string m_configFilePath;
std::vector<PlanetMetaData> m_availablePlanets;
glm::ivec2 m_resolution;
QualitySetting m_qualitySetting;
bool m_fullscreen;
uint64_t m_targetFps;
std::string m_defaultScene;
public:
CONSTRUCT_SYSTEM(SettingsSystem, std::string resourcePath,
std::string texturePath, std::string geometryPath,
std::string shaderPath, std::string soundPath)
std::string shaderPath, std::string soundPath, std::string configFilePath)
, m_resourcePath(resourcePath), m_texturePath(texturePath),
m_geometryPath(geometryPath), m_shaderPath(shaderPath),
m_soundPath(soundPath) {}
m_soundPath(soundPath) {
m_configFilePath = configFilePath;
}
inline std::string getResourcePath() const { return m_resourcePath; }
inline std::string getFullTexturePath() const { return m_resourcePath + m_texturePath; }
inline std::string getFullGeometryPath() const { return m_resourcePath + m_geometryPath; }
inline std::string getFullShaderPath() const { return m_resourcePath + m_shaderPath; }
inline std::string getFullSoundPath() const { return m_resourcePath + m_soundPath; }
inline glm::ivec2 getResolution() const { return m_resolution; }
inline bool getFullscreen() const { return m_fullscreen; }
inline uint64_t getTargetFps() const { return m_targetFps; }
inline QualitySetting getQualitySetting() const { return m_qualitySetting; }
inline std::string getDefaultScene() const { return m_defaultScene; }
inline std::vector<PlanetMetaData> getAvailablePlanets() const { return m_availablePlanets; }
bool startup() override;
void shutdown() override;
......
#pragma once
#include <engine/core/Context.hpp>
#include <engine/core/System.hpp>
#include <engine/core/SettingsSystem.hpp>
#include <SDL.h>
#include <glm/glm.hpp>
class WindowSystem : public System {
private:
SettingsSystem* m_settings;
void setSDLHintsForOpenGLVersion(unsigned int _version);
bool createWindow();
glm::uvec2 m_windowSize;
SDL_Window *m_sdlWindow;
SDL_GLContext m_glContext;
bool m_fullscreen;
public:
CONSTRUCT_SYSTEM(WindowSystem, int windowWidth, int windowHeight) {
CONSTRUCT_SYSTEM(WindowSystem, int windowWidth, int windowHeight, bool fullscreen) {
m_windowSize.x = windowWidth;
m_windowSize.y = windowHeight;
m_fullscreen = fullscreen;
}
void setWindowTitle(const char* title);
......
......@@ -9,10 +9,13 @@
#include <engine/scene/Planet.hpp>
#include <vector>
#include <engine/graphics/RendererSystem.hpp>
#include <engine/core/SettingsSystem.hpp>
class OrbitalSimulationSystem : public System {
private:
SettingsSystem* m_settings;
EventSystem* m_events;
SceneGraphSystem *m_scene;
RendererSystem *m_renderer;
......@@ -22,9 +25,6 @@ private:
Geometry orbitTorus;
Geometry minimapItem;
Material planetMat;
Material jupiterMat;
Material earthMat;
Material moonMat;
Material trajectoryMat;
Material atmosphereMat;
......@@ -32,6 +32,7 @@ private:
Material waterMat;
Material minimapItemMaterial;
std::unordered_map<std::string, Material> planetMaterials;
std::vector<Entity> trajectories;
......
This diff is collapsed.
......@@ -13,11 +13,14 @@
#include <engine/ui/UISystem.hpp>
bool GameLoopSystem::startup() {
RESOLVE_DEPENDENCY(m_settings);
RESOLVE_DEPENDENCY(m_events);
RESOLVE_DEPENDENCY(m_window);
RESOLVE_DEPENDENCY(m_renderer);
RESOLVE_DEPENDENCY(m_audio);
m_targetFrameRate = m_settings->getTargetFps();
m_events->subscribe<"DrawUI"_sh>([this] {
static bool opened = true;
ImGui::SetNextWindowPos(ImVec2(10, 10));
......
......@@ -2,14 +2,128 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Settings.hh>
#define PICOJSON_USE_INT64
#include <engine/utils/picojson.h>
#include <fstream>
using namespace ACGL::Base;
std::string getDirectory(std::string filename) {
size_t found;
found = filename.find_last_of("/\\");
return filename.substr(0, found);
}
bool SettingsSystem::startup() {
Settings::the()->setResourcePath(m_resourcePath);
Settings::the()->setTexturePath(m_texturePath);
Settings::the()->setGeometryPath(m_geometryPath);
Settings::the()->setShaderPath(m_shaderPath);
std::ifstream configFile(m_resourcePath + m_configFilePath);
if (!configFile.is_open()) {
std::cerr << "Could not open config file " << m_configFilePath << "!" << std::endl;
return false;
}
picojson::value config;
configFile >> config;
if (!config.is<picojson::object>()) {
std::cerr << "Could not read config file " << m_configFilePath << "!" << std::endl;
return false;
}
const picojson::object& o = config.get<picojson::object>();
m_availablePlanets = { };
m_resolution = { 1280, 720 };
m_qualitySetting = QualitySetting::High;
m_fullscreen = false;
m_targetFps = 60;
m_defaultScene = "AtmosphereTest";
#define VALIDATE_TYPE(p, type) if(!p.second.is<type>()) { std::cout << "Warning: Setting \"" << i.first << "\": " << i.second << " is not of expected type " #type "." << std::endl; continue; }
for (auto& i : o) {
if (i.first == "available_planet_prefabs") {
VALIDATE_TYPE(i, picojson::array);
const picojson::array& planets = i.second.get<picojson::array>();
m_availablePlanets.clear();
for (auto& planet : planets) {
auto planetName = planet.get<std::string>();
std::string fullPath = m_resourcePath + getDirectory(m_configFilePath) + "/planets/" + planetName + ".json";
std::ifstream planetFile(fullPath);
if (!planetFile.is_open()) {
std::cerr << "Could not open planet file " << fullPath << "!" << std::endl;
continue;
}
picojson::value planetVal;
planetFile >> planetVal;
if (!planetVal.is<picojson::object>()) {
std::cerr << "Could not read planet file " << fullPath << "!" << std::endl;
return false;
}
const picojson::object& planetObj = planetVal.get<picojson::object>();
PlanetMetaData planet;
planet.name = planetName;
for (auto& prop : planetObj) {
if (prop.first == "shaders") {
VALIDATE_TYPE(prop, std::string);
planet.shaders = prop.second.get<std::string>();
} else if (prop.first == "atmopshere") {
VALIDATE_TYPE(prop, bool);
planet.hasAtmosphere = prop.second.get<bool>();
} else if (prop.first == "water") {
VALIDATE_TYPE(prop, bool);
planet.hasWater = prop.second.get<bool>();
} else if (prop.first == "moons") {
VALIDATE_TYPE(prop, int64_t);
planet.moonCount = prop.second.get<int64_t>();
}
}
m_availablePlanets.push_back(planet);
}
} else if(i.first == "resolution") {
VALIDATE_TYPE(i, picojson::array);
const picojson::array& res = i.second.get<picojson::array>();
m_resolution.x = res[0].get<int64_t>();
m_resolution.y = res[1].get<int64_t>();
} else if (i.first == "fullscreen") {
VALIDATE_TYPE(i, bool);
m_fullscreen = i.second.get<bool>();
} else if (i.first == "target_fps") {
VALIDATE_TYPE(i, int64_t);
m_targetFps = i.second.get<int64_t>();
} else if (i.first == "quality") {
VALIDATE_TYPE(i, std::string);
auto setting = i.second.get<std::string>();
if (setting == "low") m_qualitySetting = QualitySetting::Low;
else if (setting == "medium") m_qualitySetting = QualitySetting::Medium;
else if (setting == "high") m_qualitySetting = QualitySetting::High;
} else if (i.first == "scene") {
VALIDATE_TYPE(i, std::string);
m_defaultScene = i.second.get<std::string>();
} else {
std::cout << "Warning: Unknown setting \"" << i.first << "\"." << std::endl;
}
}
#undef VALIDATE_TYPE
return true;
}
......
......@@ -85,7 +85,7 @@ bool WindowSystem::createWindow() {
// request an OpenGL debug context:
m_sdlWindow = SDL_CreateWindow(
"Edge of Space", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
m_windowSize.x, m_windowSize.y, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
m_windowSize.x, m_windowSize.y, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | (m_fullscreen & SDL_WINDOW_FULLSCREEN));
if (!m_sdlWindow) {
error() << "Failed to open a SDL window - requested OpenGL: "
......@@ -139,6 +139,10 @@ bool WindowSystem::createWindow() {
}
bool WindowSystem::startup() {
RESOLVE_DEPENDENCY(m_settings);
m_fullscreen = m_settings->getFullscreen();
m_windowSize = m_settings->getResolution();
/////////////////////////////////////////////////////////////////////////////////////
// Create OpenGL capable window:
if (!createWindow()) {
......
......@@ -23,7 +23,10 @@
#include <thread>
#include <filesystem>
bool OrbitalSimulationSystem::startup() {
RESOLVE_DEPENDENCY(m_settings);
RESOLVE_DEPENDENCY(m_events);
RESOLVE_DEPENDENCY(m_scene);
RESOLVE_DEPENDENCY(m_renderer);
......@@ -64,19 +67,27 @@ bool OrbitalSimulationSystem::startup() {
.attributeLocations(playerIconGeometry.vao->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations()));
// auto dispMappingShader = ShaderProgramFileManager::the()->get(ShaderProgramCreator("DispMapping")
// .attributeLocations(m_renderer->m_transformFeedbackVAO->getAttributeLocations())
// .fragmentDataLocations(m_renderer->getGBufferLocations()));
auto earthShader = ShaderProgramFileManager::the()->get(ShaderProgramCreator("planets/earth")
.attributeLocations(m_renderer->m_transformFeedbackVAO->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations()));
auto planets = m_settings->getAvailablePlanets();
auto jupiterShader = ShaderProgramFileManager::the()->get(ShaderProgramCreator("planets/jupiter")
.attributeLocations(m_renderer->m_transformFeedbackVAO->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations()));
for (auto planet : planets) {
auto planetShader = ShaderProgramFileManager::the()->get(
ShaderProgramCreator(planet.shaders + "/" + planet.name)
.attributeLocations(
m_renderer->m_transformFeedbackVAO->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations()));
auto moonShader = ShaderProgramFileManager::the()->get(ShaderProgramCreator("planets/moon")
planetMaterials[planet.name] = {glm::vec4(1, 1, 1, 1),