2013-12-21 22:48:54 +00:00
|
|
|
#include "OpenGLSkybox.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include "OpenGLRenderer.h"
|
|
|
|
#include "OpenGLShaderProgram.h"
|
2013-12-22 14:04:33 +00:00
|
|
|
#include "OpenGLSharedState.h"
|
2013-12-21 22:48:54 +00:00
|
|
|
#include "Scenery.h"
|
|
|
|
#include "AtmosphereDefinition.h"
|
|
|
|
#include "AtmosphereRenderer.h"
|
|
|
|
#include "AtmosphereModelBruneton.h"
|
2015-08-18 18:31:11 +00:00
|
|
|
#include "FloatNode.h"
|
2013-12-21 22:48:54 +00:00
|
|
|
|
|
|
|
OpenGLSkybox::OpenGLSkybox(OpenGLRenderer* renderer):
|
|
|
|
OpenGLPart(renderer)
|
|
|
|
{
|
|
|
|
vertices = new float[14 * 3];
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenGLSkybox::~OpenGLSkybox()
|
|
|
|
{
|
|
|
|
delete[] vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLSkybox::initialize()
|
|
|
|
{
|
|
|
|
program = createShader("skybox");
|
|
|
|
program->addVertexSource("skybox");
|
2014-11-21 10:40:47 +00:00
|
|
|
program->addFragmentSource("atmosphere");
|
2013-12-22 17:47:24 +00:00
|
|
|
program->addFragmentSource("tonemapping");
|
2013-12-21 22:48:54 +00:00
|
|
|
program->addFragmentSource("skybox");
|
|
|
|
|
|
|
|
setVertex(0, 1.0f, 1.0f, 1.0f);
|
|
|
|
setVertex(12, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
setVertex(1, 1.0f, -1.0f, 1.0f);
|
|
|
|
setVertex(5, 1.0f, -1.0f, 1.0f);
|
|
|
|
setVertex(13, 1.0f, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
setVertex(2, -1.0f, 1.0f, 1.0f);
|
|
|
|
setVertex(10, -1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
setVertex(3, -1.0f, -1.0f, 1.0f);
|
|
|
|
|
|
|
|
setVertex(4, -1.0f, -1.0f, -1.0f);
|
|
|
|
setVertex(8, -1.0f, -1.0f, -1.0f);
|
|
|
|
|
|
|
|
setVertex(6, 1.0f, -1.0f, -1.0f);
|
|
|
|
|
|
|
|
setVertex(7, 1.0f, 1.0f, -1.0f);
|
|
|
|
setVertex(11, 1.0f, 1.0f, -1.0f);
|
|
|
|
|
|
|
|
setVertex(9, -1.0f, 1.0f, -1.0f);
|
2015-08-18 18:31:11 +00:00
|
|
|
|
|
|
|
// Watch for definition changes
|
|
|
|
renderer->getScenery()->getAtmosphere()->propDayTime()->addWatcher(this, true);
|
2015-08-25 21:33:47 +00:00
|
|
|
renderer->getScenery()->getAtmosphere()->propHumidity()->addWatcher(this, true);
|
2015-09-21 21:12:43 +00:00
|
|
|
renderer->getScenery()->getAtmosphere()->propSunRadius()->addWatcher(this, true);
|
2013-12-21 22:48:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGLSkybox::update()
|
|
|
|
{
|
2013-12-22 14:04:33 +00:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
program->drawTriangleStrip(vertices, 14);
|
|
|
|
}
|
2015-09-14 17:25:54 +00:00
|
|
|
|
2015-08-18 18:31:11 +00:00
|
|
|
void OpenGLSkybox::nodeChanged(const DefinitionNode *node, const DefinitionDiff *)
|
|
|
|
{
|
|
|
|
if (node->getPath() == "/atmosphere/daytime")
|
|
|
|
{
|
|
|
|
Vector3 sun_direction = renderer->getAtmosphereRenderer()->getSunDirection(false);
|
|
|
|
renderer->getSharedState()->set("sunDirection", sun_direction);
|
|
|
|
|
|
|
|
Color sun_color = renderer->getScenery()->getAtmosphere()->sun_color;
|
|
|
|
renderer->getSharedState()->set("sunColor", sun_color);
|
2015-08-25 21:33:47 +00:00
|
|
|
|
|
|
|
renderer->getSharedState()->set("dayTime", renderer->getScenery()->getAtmosphere()->propDayTime()->getValue());
|
|
|
|
}
|
|
|
|
else if (node->getPath() == "/atmosphere/humidity")
|
|
|
|
{
|
|
|
|
renderer->getSharedState()->set("atmosphereHumidity", renderer->getScenery()->getAtmosphere()->propHumidity()->getValue());
|
2015-08-18 18:31:11 +00:00
|
|
|
}
|
2015-09-21 21:12:43 +00:00
|
|
|
else if (node->getPath() == "/atmosphere/sun_radius")
|
|
|
|
{
|
|
|
|
renderer->getSharedState()->set("sunRadius", renderer->getScenery()->getAtmosphere()->propSunRadius()->getValue());
|
|
|
|
}
|
2015-08-18 18:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 22:48:54 +00:00
|
|
|
void OpenGLSkybox::setVertex(int i, float x, float y, float z)
|
|
|
|
{
|
|
|
|
vertices[i * 3] = x;
|
|
|
|
vertices[i * 3 + 1] = y;
|
|
|
|
vertices[i * 3 + 2] = z;
|
|
|
|
}
|