paysages3d/src/render/opengl/OpenGLSkybox.cpp

95 lines
3.2 KiB
C++
Raw Normal View History

2013-12-21 22:48:54 +00:00
#include "OpenGLSkybox.h"
#include <cmath>
#include "OpenGLRenderer.h"
#include "OpenGLShaderProgram.h"
#include "OpenGLSharedState.h"
2015-12-07 22:32:55 +00:00
#include "OpenGLVertexArray.h"
2013-12-21 22:48:54 +00:00
#include "Scenery.h"
#include "AtmosphereDefinition.h"
#include "AtmosphereRenderer.h"
#include "AtmosphereModelBruneton.h"
#include "FloatNode.h"
2015-12-11 00:39:47 +00:00
#include "Logs.h"
2013-12-21 22:48:54 +00:00
static const string path_daytime = "/atmosphere/daytime";
static const string path_humidity = "/atmosphere/humidity";
static const string path_sun_radius = "/atmosphere/sun_radius";
2013-12-21 22:48:54 +00:00
2015-12-11 00:12:55 +00:00
OpenGLSkybox::OpenGLSkybox(OpenGLRenderer *renderer) : OpenGLPart(renderer, "skybox") {
2013-12-21 22:48:54 +00:00
program = createShader("skybox");
program->addVertexSource("skybox");
program->addFragmentSource("atmosphere");
program->addFragmentSource("tonemapping");
2013-12-21 22:48:54 +00:00
program->addFragmentSource("skybox");
2015-12-07 22:32:55 +00:00
vertices = createVertexArray(false, true);
2013-12-21 22:48:54 +00:00
2015-12-07 22:32:55 +00:00
vertices->setVertexCount(14);
2013-12-21 22:48:54 +00:00
2015-12-07 22:32:55 +00:00
vertices->set(0, Vector3(1.0f, 1.0f, 1.0f));
vertices->set(12, Vector3(1.0f, 1.0f, 1.0f));
2013-12-21 22:48:54 +00:00
2015-12-07 22:32:55 +00:00
vertices->set(1, Vector3(1.0f, -1.0f, 1.0f));
vertices->set(5, Vector3(1.0f, -1.0f, 1.0f));
vertices->set(13, Vector3(1.0f, -1.0f, 1.0f));
2013-12-21 22:48:54 +00:00
2015-12-07 22:32:55 +00:00
vertices->set(2, Vector3(-1.0f, 1.0f, 1.0f));
vertices->set(10, Vector3(-1.0f, 1.0f, 1.0f));
2013-12-21 22:48:54 +00:00
2015-12-07 22:32:55 +00:00
vertices->set(3, Vector3(-1.0f, -1.0f, 1.0f));
2013-12-21 22:48:54 +00:00
2015-12-07 22:32:55 +00:00
vertices->set(4, Vector3(-1.0f, -1.0f, -1.0f));
vertices->set(8, Vector3(-1.0f, -1.0f, -1.0f));
2013-12-21 22:48:54 +00:00
2015-12-07 22:32:55 +00:00
vertices->set(6, Vector3(1.0f, -1.0f, -1.0f));
2015-12-07 22:32:55 +00:00
vertices->set(7, Vector3(1.0f, 1.0f, -1.0f));
vertices->set(11, Vector3(1.0f, 1.0f, -1.0f));
vertices->set(9, Vector3(-1.0f, 1.0f, -1.0f));
}
OpenGLSkybox::~OpenGLSkybox() {
}
void OpenGLSkybox::initialize() {
// Watch for definition changes
2015-12-11 00:39:47 +00:00
Scenery *scenery = renderer->getScenery();
startWatching(scenery, path_daytime);
startWatching(scenery, path_humidity);
startWatching(scenery, path_sun_radius);
2013-12-21 22:48:54 +00:00
}
void OpenGLSkybox::update() {
2015-12-11 00:39:47 +00:00
Logs::debug() << "[OpenGL] Updating atmosphere textures" << endl;
SoftwareBrunetonAtmosphereRenderer *bruneton =
(SoftwareBrunetonAtmosphereRenderer *)renderer->getAtmosphereRenderer();
2013-12-22 17:05:11 +00:00
renderer->getSharedState()->set("transmittanceTexture", bruneton->getModel()->getTextureTransmittance());
renderer->getSharedState()->set("inscatterTexture", bruneton->getModel()->getTextureInscatter());
2013-12-21 22:48:54 +00:00
}
void OpenGLSkybox::render() {
2015-12-07 22:32:55 +00:00
program->draw(vertices);
2013-12-21 22:48:54 +00:00
}
2015-09-14 17:25:54 +00:00
void OpenGLSkybox::nodeChanged(const DefinitionNode *node, const DefinitionDiff *) {
2015-12-11 00:39:47 +00:00
OpenGLSharedState *state = renderer->getSharedState();
AtmosphereDefinition *newdef = renderer->getScenery()->getAtmosphere();
if (node->getPath() == path_daytime) {
Vector3 sun_direction = renderer->getAtmosphereRenderer()->getSunDirection(false);
2015-12-11 00:39:47 +00:00
state->set("sunDirection", sun_direction);
Color sun_color = newdef->sun_color;
state->set("sunColor", sun_color);
state->set("dayTime", newdef->propDayTime()->getValue());
} else if (node->getPath() == path_humidity) {
state->set("atmosphereHumidity", newdef->propHumidity()->getValue());
} else if (node->getPath() == path_sun_radius) {
state->set("sunRadius", newdef->propSunRadius()->getValue());
}
}