Merged develop into NewAtmosphere.

This commit is contained in:
Jonathas Costa
2016-10-07 11:39:07 -04:00
541 changed files with 40285 additions and 9531 deletions
+14 -4
View File
@@ -38,11 +38,15 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphericalgrid.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrail.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrailnew.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceframebuffer.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimage.h
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/spiceephemeris.h
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/staticephemeris.h
${CMAKE_CURRENT_SOURCE_DIR}/translation/spicetranslation.h
${CMAKE_CURRENT_SOURCE_DIR}/translation/statictranslation.h
${CMAKE_CURRENT_SOURCE_DIR}/rotation/spicerotation.h
${CMAKE_CURRENT_SOURCE_DIR}/rotation/staticrotation.h
${CMAKE_CURRENT_SOURCE_DIR}/scale/staticscale.h
)
source_group("Header Files" FILES ${HEADER_FILES})
@@ -60,11 +64,15 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesphericalgrid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrail.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletrailnew.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceframebuffer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/screenspaceimage.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/spiceephemeris.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ephemeris/staticephemeris.cpp
${CMAKE_CURRENT_SOURCE_DIR}/translation/spicetranslation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/translation/statictranslation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rotation/spicerotation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rotation/staticrotation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/scale/staticscale.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})
@@ -73,6 +81,8 @@ set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/ephemeris_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/ephemeris_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderabletrailnew_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderabletrailnew_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/imageplane_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/imageplane_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/model_fs.glsl
+54 -9
View File
@@ -34,6 +34,7 @@
#include <modules/base/rendering/renderableconstellationbounds.h>
#include <modules/base/rendering/renderablestars.h>
#include <modules/base/rendering/renderabletrail.h>
#include <modules/base/rendering/renderabletrailnew.h>
#include <modules/base/rendering/renderablepath.h>
#include <modules/base/rendering/renderablerings.h>
#include <modules/base/rendering/renderablesphere.h>
@@ -47,8 +48,13 @@
#include <modules/base/rendering/screenspaceimage.h>
#include <modules/base/rendering/screenspaceframebuffer.h>
#include <modules/base/ephemeris/staticephemeris.h>
#include <modules/base/ephemeris/spiceephemeris.h>
#include <modules/base/translation/statictranslation.h>
#include <modules/base/translation/spicetranslation.h>
#include <modules/base/rotation/staticrotation.h>
#include <modules/base/rotation/spicerotation.h>
#include <modules/base/scale/staticscale.h>
#include <ghoul/filesystem/filesystem>
@@ -59,9 +65,27 @@ BaseModule::BaseModule()
{}
void BaseModule::internalInitialize() {
FactoryManager::ref().addFactory(std::make_unique<ghoul::TemplateFactory<planetgeometry::PlanetGeometry>>());
FactoryManager::ref().addFactory(std::make_unique<ghoul::TemplateFactory<modelgeometry::ModelGeometry>>());
FactoryManager::ref().addFactory(std::make_unique<ghoul::TemplateFactory<ScreenSpaceRenderable>>());
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<planetgeometry::PlanetGeometry>>(),
"PlanetGeometry"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<modelgeometry::ModelGeometry>>(),
"ModelGeometry"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<ScreenSpaceRenderable>>(),
"ScreenSpaceRenderable"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Rotation>>(),
"Rotation"
);
FactoryManager::ref().addFactory(
std::make_unique<ghoul::TemplateFactory<Scale>>(),
"Scale"
);
auto fScreenSpaceRenderable = FactoryManager::ref().factory<ScreenSpaceRenderable>();
ghoul_assert(fScreenSpaceRenderable, "ScreenSpaceRenderable factory was not created");
@@ -82,11 +106,24 @@ void BaseModule::internalInitialize() {
fRenderable->registerClass<RenderableSphericalGrid>("RenderableSphericalGrid");
fRenderable->registerClass<RenderableStars>("RenderableStars");
fRenderable->registerClass<RenderableTrail>("RenderableTrail");
fRenderable->registerClass<RenderableTrailNew>("RenderableTrailNew");
auto fEphemeris = FactoryManager::ref().factory<Ephemeris>();
ghoul_assert(fEphemeris, "Ephemeris factory was not created");
fEphemeris->registerClass<StaticEphemeris>("Static");
fEphemeris->registerClass<SpiceEphemeris>("Spice");
auto fTranslation = FactoryManager::ref().factory<Translation>();
ghoul_assert(fTranslation, "Ephemeris factory was not created");
fTranslation->registerClass<StaticTranslation>("StaticTranslation");
fTranslation->registerClass<SpiceTranslation>("SpiceTranslation");
auto fRotation = FactoryManager::ref().factory<Rotation>();
ghoul_assert(fRotation, "Rotation factory was not created");
fRotation->registerClass<StaticRotation>("StaticRotation");
fRotation->registerClass<SpiceRotation>("SpiceRotation");
auto fScale = FactoryManager::ref().factory<Scale>();
ghoul_assert(fScale, "Scale factory was not created");
fScale->registerClass <StaticScale> ("StaticScale");
auto fPlanetGeometry = FactoryManager::ref().factory<planetgeometry::PlanetGeometry>();
ghoul_assert(fPlanetGeometry, "Planet geometry factory was not created");
@@ -97,4 +134,12 @@ void BaseModule::internalInitialize() {
fModelGeometry->registerClass<modelgeometry::MultiModelGeometry>("MultiModelGeometry");
}
std::vector<Documentation> BaseModule::documentations() const {
return {
StaticScale::Documentation(),
StaticTranslation::Documentation(),
SpiceTranslation::Documentation()
};
}
} // namespace openspace
+2
View File
@@ -33,6 +33,8 @@ class BaseModule : public OpenSpaceModule {
public:
BaseModule();
std::vector<Documentation> documentations() const override;
protected:
void internalInitialize() override;
};
+25 -3
View File
@@ -64,7 +64,7 @@ ModelGeometry* ModelGeometry::createFromDictionary(const ghoul::Dictionary& dict
ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
: _parent(nullptr)
, _magnification("magnification", "Magnification", 0.f, 0.f, 10.f)
, _magnification("magnification", "Magnification", 1.f, 0.f, 10.f)
, _mode(GL_TRIANGLES)
{
setName("ModelGeometry");
@@ -90,6 +90,21 @@ ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
addProperty(_magnification);
}
double ModelGeometry::boundingRadius() const {
double maxDistSquared = 0;
double distSquared;
for (const Vertex& v : _vertices) {
distSquared = // x*x + y*y + z*z
v.location[0] * v.location[0] +
v.location[1] * v.location[1] +
v.location[2] * v.location[2];
maxDistSquared = glm::max(maxDistSquared, distSquared);
}
double maxDist = std::sqrt(maxDistSquared);
return maxDist;
}
ModelGeometry::~ModelGeometry() {
}
@@ -106,8 +121,15 @@ void ModelGeometry::changeRenderMode(const GLenum mode) {
bool ModelGeometry::initialize(Renderable* parent) {
_parent = parent;
PowerScaledScalar ps = PowerScaledScalar(1.0, 0.0); // will set proper bounding soon.
_parent->setBoundingSphere(ps);
float maximumDistanceSquared = 0;
for (auto v: _vertices)
{
maximumDistanceSquared = glm::max(
glm::pow(v.location[0], 2.f) +
glm::pow(v.location[1], 2.f) +
glm::pow(v.location[2], 2.f), maximumDistanceSquared);
}
_parent->setBoundingSphere(PowerScaledScalar(glm::sqrt(maximumDistanceSquared), 0.0));
if (_vertices.empty())
return false;
+2
View File
@@ -55,6 +55,8 @@ public:
bool getVertices(std::vector<Vertex>* vertexList);
bool getIndices(std::vector<int>* indexList);
double boundingRadius() const;
virtual void setUniforms(ghoul::opengl::ProgramObject& program);
protected:
@@ -74,9 +74,9 @@ namespace openspace {
);
Vertex vv;
//memcpy(vv.location, v.location, sizeof(GLfloat) * 3);
memcpy(vv.location, glm::value_ptr(p.vec4()), sizeof(GLfloat) * 4);
//vv.location[3] = 1.0;
memcpy(vv.location, v.location, sizeof(GLfloat) * 3);
vv.location[3] = 1.0;
//memcpy(vv.location, glm::value_ptr(p.vec4()), sizeof(GLfloat) * 4);
memcpy(vv.tex, v.tex, sizeof(GLfloat) * 2);
memcpy(vv.normal, v.normal, sizeof(GLfloat) * 3);
_vertices.push_back(vv);
+46 -48
View File
@@ -46,8 +46,6 @@
namespace {
const std::string _loggerCat = "RenderableModel";
const std::string keySource = "Rotation.Source";
const std::string keyDestination = "Rotation.Destination";
const std::string keyGeometry = "Geometry";
const std::string keyBody = "Body";
const std::string keyStart = "StartTime";
@@ -66,6 +64,7 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _performFade("performFading", "Perform Fading", false)
, _fading("fading", "Fade", 0)
, _debugModelRotation("modelrotation", "Model Rotation", glm::vec3(0.f), glm::vec3(0.f), glm::vec3(360.f))
, _programObject(nullptr)
, _texture(nullptr)
, _geometry(nullptr)
@@ -95,17 +94,19 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary)
addProperty(_colorTexturePath);
_colorTexturePath.onChange(std::bind(&RenderableModel::loadTexture, this));
dictionary.getValue(keySource, _source);
dictionary.getValue(keyDestination, _destination);
addProperty(_debugModelRotation);
//dictionary.getValue(keySource, _source);
//dictionary.getValue(keyDestination, _destination);
if (dictionary.hasKeyAndValue<glm::dmat3>(keyModelTransform))
dictionary.getValue(keyModelTransform, _modelTransform);
else
_modelTransform = glm::dmat3(1.f);
dictionary.getValue(keyBody, _target);
openspace::SpiceManager::ref().addFrame(_target, _source);
//openspace::SpiceManager::ref().addFrame(_target, _source);
setBoundingSphere(pss(1.f, 9.f));
//setBoundingSphere(pss(1.f, 9.f));
addProperty(_performShading);
if (dictionary.hasKeyAndValue<bool>(keyFading)) {
@@ -147,8 +148,8 @@ bool RenderableModel::initialize() {
completeSuccess &= (_texture != nullptr);
completeSuccess &= _geometry->initialize(this);
completeSuccess &= !_source.empty();
completeSuccess &= !_destination.empty();
//completeSuccess &= !_source.empty();
//completeSuccess &= !_destination.empty();
return completeSuccess;
}
@@ -173,55 +174,59 @@ bool RenderableModel::deinitialize() {
void RenderableModel::render(const RenderData& data) {
_programObject->activate();
_frameCount++;
double lt;
glm::mat4 transform = glm::mat4(1.f);
glm::mat4 tmp = glm::mat4(1);
for (int i = 0; i < 3; i++){
for (int j = 0; j < 3; j++){
tmp[i][j] = static_cast<float>(_stateMatrix[i][j]);
}
}
transform *= tmp;
double time = openspace::Time::ref().currentTime();
double lt;
// Fade away if it does not have spice coverage
double time = openspace::Time::ref().j2000Seconds();
bool targetPositionCoverage = openspace::SpiceManager::ref().hasSpkCoverage(_target, time);
if (!targetPositionCoverage){
if (!targetPositionCoverage) {
int frame = _frameCount % 180;
float fadingFactor = static_cast<float>(sin((frame * M_PI) / 180));
_alpha = 0.5f + fadingFactor * 0.5f;
}
else
_alpha = 1.0f;
glm::dvec3 p =
SpiceManager::ref().targetPosition(_target, "SUN", "GALACTIC", {}, time, lt);
psc tmppos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
glm::vec3 cam_dir = glm::normalize(data.camera.position().vec3() - tmppos.vec3());
_programObject->setUniform("cam_dir", cam_dir);
_programObject->setUniform("transparency", _alpha);
_programObject->setUniform("sun_pos", _sunPosition.vec3());
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(*_programObject.get(), data.camera, data.position);
_programObject->setUniform("_performShading", _performShading);
_geometry->setUniforms(*_programObject);
if (_performFade && _fading > 0.f){
// Fading
if (_performFade && _fading > 0.f) {
_fading = _fading - 0.01f;
}
else if (!_performFade && _fading < 1.f){
else if (!_performFade && _fading < 1.f) {
_fading = _fading + 0.01f;
}
// debug rotation controlled from GUI
glm::mat4 unitMat4(1);
glm::vec3 debugEulerRot = glm::radians(_debugModelRotation.value());
glm::mat4 rotX = glm::rotate(unitMat4, debugEulerRot.x, glm::vec3(1, 0, 0));
glm::mat4 rotY = glm::rotate(unitMat4, debugEulerRot.y, glm::vec3(0, 1, 0));
glm::mat4 rotZ = glm::rotate(unitMat4, debugEulerRot.z, glm::vec3(0, 0, 1));
glm::dmat4 debugModelRotation = rotX * rotY * rotZ;
// Model transform and view transform needs to be in double precision
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
glm::dmat4(glm::scale(glm::dmat4(_modelTransform), glm::dvec3(data.modelTransform.scale)));
debugModelRotation; // debug model rotation controlled from GUI
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
glm::vec3 directionToSun = glm::normalize(_sunPos - data.modelTransform.translation);
glm::vec3 directionToSunViewSpace = glm::mat3(data.camera.combinedViewMatrix()) * directionToSun;
_programObject->setUniform("transparency", _alpha);
_programObject->setUniform("directionToSunViewSpace", directionToSunViewSpace);
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
_programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
_programObject->setUniform("performShading", _performShading);
_programObject->setUniform("fading", _fading);
_geometry->setUniforms(*_programObject);
// Bind texture
ghoul::opengl::TextureUnit unit;
unit.activate();
@@ -255,15 +260,8 @@ void RenderableModel::update(const UpdateData& data) {
// _time = futureTime;
//}
// set spice-orientation in accordance to timestamp
if (!_source.empty()) {
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_source, _destination, _time) * _modelTransform;
}
double lt;
glm::dvec3 p =
openspace::SpiceManager::ref().targetPosition("SUN", _target, "GALACTIC", {}, _time, lt);
_sunPosition = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
_sunPos = openspace::SpiceManager::ref().targetPosition("SUN", "SUN", "GALACTIC", {}, _time, lt);
}
void RenderableModel::loadTexture() {
+5 -4
View File
@@ -67,18 +67,19 @@ private:
glm::dmat3 _modelTransform;
float _alpha;
glm::dmat3 _stateMatrix;
//glm::dmat3 _stateMatrix;
std::string _source;
std::string _destination;
//std::string _source;
//std::string _destination;
std::string _target;
//bool _isGhost;
int _frameCount;
psc _sunPosition;
glm::dvec3 _sunPos;
properties::BoolProperty _performShading;
properties::Vec3Property _debugModelRotation;
};
} // namespace openspace
+39 -44
View File
@@ -49,7 +49,9 @@ namespace {
const std::string keyPathModule = "ModulePath";
const std::string keyColor = "RGB";
const std::string keyTimeSteps = "TimeSteps";
const std::string keyPointSteps = "PointSteps";
const std::string keyDrawLine = "DrawLine";
const std::string keRenderDistanceInterval = "RenderDistanceInterval";
}
@@ -57,7 +59,6 @@ namespace openspace {
RenderablePath::RenderablePath(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _lineFade("lineFade", "Line Fade", 0.75f, 0.f, 5.f)
, _lineWidth("lineWidth", "Line Width", 2.f, 1.f, 20.f)
, _drawLine("drawline", "Draw Line", false)
, _programObject(nullptr)
@@ -73,6 +74,11 @@ RenderablePath::RenderablePath(const ghoul::Dictionary& dictionary)
_successfullDictionaryFetch &= dictionary.getValue(keyFrame, _frame);
_successfullDictionaryFetch &= dictionary.getValue(keyTimeSteps, _increment);
float fPointSteps; // Dictionary can not pick out ints...
if (!dictionary.getValue(keyPointSteps, fPointSteps))
fPointSteps = 4;
_pointSteps = fPointSteps;
glm::vec3 color(0.f);
if (dictionary.hasKeyAndValue<glm::vec3>(keyColor))
dictionary.getValue(keyColor, color);
@@ -83,7 +89,6 @@ RenderablePath::RenderablePath(const ghoul::Dictionary& dictionary)
dictionary.getValue(keyDrawLine, drawLine);
_drawLine = drawLine;
addProperty(_drawLine);
addProperty(_lineFade);
addProperty(_lineWidth);
_distanceFade = 1.0;
}
@@ -136,57 +141,42 @@ bool RenderablePath::isReady() const {
}
void RenderablePath::render(const RenderData& data) {
double time = openspace::Time::ref().currentTime();
double time = openspace::Time::ref().j2000Seconds();
if (_start > time || _stop < time)
return;
//const psc& position = data.camera.position();
//const psc& origin = openspace::OpenSpaceEngine::ref().interactionHandler()->focusNode()->worldPosition();
//const PowerScaledScalar& pssl = (position - origin).length();
//double properLength = static_cast<double>(pssl.lengthf());
//const PowerScaledScalar corrected = PowerScaledScalar::CreatePSS(properLength);
//float exp = corrected[1];
//
//if (exp > 11)
// return;
_programObject->activate();
psc currentPosition = data.position;
glm::mat4 camrot = glm::mat4(data.camera.viewRotationMatrix());
glm::mat4 transform = glm::mat4(1);
// setup the data to the shader
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
int nPointsToDraw = _vertexArray.size();// (time - _start) / (_stop - _start) * (_vertexArray.size()) + 1 + 0.5;
_programObject->activate();
// Calculate variables to be used as uniform variables in shader
glm::dvec3 bodyPosition = data.modelTransform.translation;
// Model transform and view transform needs to be in double precision
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), bodyPosition); // Translation
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
_programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
_programObject->setUniform("pointSteps", _pointSteps);
_programObject->setUniform("color", _lineColor);
_programObject->setUniform("lastPosition", _lastPosition);
setPscUniforms(*_programObject.get(), data.camera, data.position);
if (_drawLine) {
glLineWidth(_lineWidth);
glBindVertexArray(_vaoID);
glDrawArrays(GL_LINE_STRIP, 0, static_cast<GLsizei>(_vertexArray.size()));
glDrawArrays(GL_LINE_STRIP, 0, static_cast<GLsizei>(nPointsToDraw));
glBindVertexArray(0);
glLineWidth(1.f);
}
//float pointSize = std::min((11-exp),5.f);
//glPointSize(5);
glEnable(GL_PROGRAM_POINT_SIZE);
//GLfloat distanceParams[] = { 1.0f, 5.0f, 10.f }; //a, b, c
//GLfloat fadeThreshold[] = { 0.1f };
//
//glPointParameterf(GL_POINT_SIZE_MAX, 5.0f);
//glPointParameterf(GL_POINT_SIZE_MIN, 1.0f);
//glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, distanceParams);
////=> size = clamp(size*sqrt(1/(a+b*d+c*d^2)));
//glPointParameterfv(GL_POINT_FADE_THRESHOLD_SIZE, fadeThreshold);
glBindVertexArray(_vaoID);
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(_vertexArray.size()));
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(nPointsToDraw));
glBindVertexArray(0);
glDisable(GL_PROGRAM_POINT_SIZE);
_programObject->deactivate();
@@ -219,15 +209,20 @@ void RenderablePath::calculatePath(std::string observer) {
double currentTime = _start;
_vertexArray.resize(segments);
psc pscPos;
//psc pscPos;
//float r, g, b;
//float g = _lineColor[1];
//float b = _lineColor[2];
glm::vec3 position;
for (int i = 0; i < segments; i++) {
glm::dvec3 p =
SpiceManager::ref().targetPosition(_target, observer, _frame, {}, currentTime, lightTime);
pscPos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
pscPos[3] += 3;
position =
glm::vec3(SpiceManager::ref().targetPosition(_target, observer, _frame, {}, currentTime, lightTime));
// Convert from 100 m to m
position *= 10e2;
//pscPos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
//pscPos[3] += 3;
//if (!correctPosition) {
// r = 1.f;
@@ -242,12 +237,12 @@ void RenderablePath::calculatePath(std::string observer) {
// r = g = b = 0.6f;
//}
//add position
_vertexArray[i] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] };
_vertexArray[i] = { position[0], position[1], position[2], 1.0f };
//add color for position
//_vertexArray[i + 1] = { r, g, b, a };
currentTime += _increment;
}
_lastPosition = pscPos.dvec4();
_lastPosition = glm::vec4(position, 1.0f);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(VertexInfo), &_vertexArray[0]);
+2 -2
View File
@@ -59,12 +59,11 @@ private:
//float r, g, b, a;
};
void sendToGPU();
void addPosition(psc pos);
void addPosition(glm::vec3 pos);
void addColor(glm::vec4 col);
glm::vec3 _lineColor;
glm::vec4 _lastPosition;
properties::FloatProperty _lineFade;
properties::FloatProperty _lineWidth;
properties::BoolProperty _drawLine;
@@ -87,6 +86,7 @@ private:
double _start;
double _stop;
float _distanceFade;
int _pointSteps;
};
} // namespace openspace
+53 -9
View File
@@ -60,6 +60,7 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
, _shader(nullptr)
, _textureIsDirty(false)
, _texture(nullptr)
, _blendMode(BlendMode::Normal)
, _quad(0)
, _vertexPositionBuffer(0)
{
@@ -67,7 +68,7 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
dictionary.getValue("Size", size);
_size = size;
if (dictionary.hasKey("Name")){
if (dictionary.hasKey("Name")) {
dictionary.getValue("Name", _nodeName);
}
@@ -102,6 +103,13 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
}
}
std::string blendMode;
if (dictionary.getValue("BlendMode", blendMode)) {
if (blendMode == "Additive") {
_blendMode = BlendMode::Additive;
setRenderBin(Renderable::RenderBin::Transparent);
}
}
std::string texturePath = "";
bool success = dictionary.getValue("Texture", texturePath);
@@ -185,10 +193,8 @@ bool RenderablePlane::deinitialize() {
}
void RenderablePlane::render(const RenderData& data) {
glm::mat4 transform = glm::mat4(1.0);
if (_billboard)
transform = glm::inverse(glm::mat4(data.camera.viewRotationMatrix()));
glm::mat4 scaleTransform = glm::mat4(1.0);
// Activate shader
_shader->activate();
if (_projectionListener){
@@ -200,22 +206,60 @@ void RenderablePlane::render(const RenderData& data) {
float h = _texture->height();
float w = _texture->width();
float scale = h / w;
transform = glm::scale(transform, glm::vec3(1.f, scale, 1.f));
scaleTransform = glm::scale(glm::mat4(1.0), glm::vec3(1.f, scale, 1.f));
}
}
_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_shader->setUniform("ModelTransform", transform);
setPscUniforms(*_shader.get(), data.camera, data.position);
// Model transform and view transform needs to be in double precision
glm::dmat4 rotationTransform;
if (_billboard)
rotationTransform = glm::inverse(glm::dmat4(data.camera.viewRotationMatrix()));
else
rotationTransform = glm::dmat4(data.modelTransform.rotation);
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
rotationTransform *
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale))) *
glm::dmat4(scaleTransform);
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
_shader->setUniform("modelViewProjectionTransform",
data.camera.projectionMatrix() * glm::mat4(modelViewTransform));
//_shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
//_shader->setUniform("ModelTransform", transform);
//setPscUniforms(*_shader.get(), data.camera, data.position);
ghoul::opengl::TextureUnit unit;
unit.activate();
_texture->bind();
_shader->setUniform("texture1", unit);
bool usingFramebufferRenderer =
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer;
bool usingABufferRenderer =
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::ABuffer;
if (usingABufferRenderer) {
_shader->setUniform("additiveBlending", _blendMode == BlendMode::Additive);
}
bool additiveBlending = _blendMode == BlendMode::Additive && usingFramebufferRenderer;
if (additiveBlending) {
glDepthMask(false);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
glBindVertexArray(_quad);
glDrawArrays(GL_TRIANGLES, 0, 6);
if (additiveBlending) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(true);
}
_shader->deactivate();
}
+6
View File
@@ -51,6 +51,11 @@ class RenderablePlane : public Renderable {
};
public:
enum class BlendMode : int {
Normal = 0,
Additive
};
RenderablePlane(const ghoul::Dictionary& dictionary);
~RenderablePlane();
@@ -79,6 +84,7 @@ private:
std::unique_ptr<ghoul::opengl::ProgramObject> _shader;
bool _textureIsDirty;
std::unique_ptr<ghoul::opengl::Texture> _texture;
BlendMode _blendMode;
ghoul::filesystem::File* _textureFile;
GLuint _quad;
GLuint _vertexPositionBuffer;
+2 -6
View File
@@ -159,8 +159,7 @@ namespace openspace {
dictionary.getValue(keyFrame, _frame);
dictionary.getValue(keyBody, _target);
if (_target != "")
setBody(_target);
// TODO: textures need to be replaced by a good system similar to the geometry as soon
// as the requirements are fixed (ab)
@@ -615,8 +614,7 @@ bool RenderablePlanet::isReady() const {
return ready;
}
void RenderablePlanet::render(const RenderData& data)
{
void RenderablePlanet::render(const RenderData& data) {
// activate shader
_programObject->activate();
@@ -886,14 +884,12 @@ void RenderablePlanet::render(const RenderData& data)
_programObject->setUniform("exposure", 0.4f);
}
// render
_geometry->render();
// disable shader
_programObject->deactivate();
// DEBUG: Deferred Rendering of the atmosphere to a texture.
// Render Atmosphere to a texture:
@@ -218,6 +218,8 @@ private:
bool tempPic;
unsigned int count;
};
} // namespace openspace
+35 -7
View File
@@ -124,6 +124,7 @@ bool RenderableTrail::initialize() {
"${MODULE_BASE}/shaders/ephemeris_vs.glsl",
"${MODULE_BASE}/shaders/ephemeris_fs.glsl");
setRenderBin(Renderable::RenderBin::Overlay);
if (!_programObject)
return false;
@@ -150,16 +151,29 @@ bool RenderableTrail::isReady() const {
void RenderableTrail::render(const RenderData& data) {
_programObject->activate();
psc currentPosition = data.position;
psc campos = data.camera.position();
glm::mat4 camrot = glm::mat4(data.camera.viewRotationMatrix());
//psc currentPosition = data.position;
//psc campos = data.camera.position();
//glm::mat4 camrot = glm::mat4(data.camera.viewRotationMatrix());
glm::mat4 transform = glm::mat4(1);
//glm::mat4 transform = glm::mat4(1);
// setup the data to the shader
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
_programObject->setUniform("ModelTransform", transform);
setPscUniforms(*_programObject.get(), data.camera, data.position);
//_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
//_programObject->setUniform("ModelTransform", transform);
//setPscUniforms(*_programObject.get(), data.camera, data.position);
// Calculate variables to be used as uniform variables in shader
glm::dvec3 bodyPosition = data.modelTransform.translation;
// Model transform and view transform needs to be in double precision
glm::dmat4 modelTransform =
glm::translate(glm::dmat4(1.0), bodyPosition) *
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)));
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
_programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
_programObject->setUniform("color", _lineColor);
_programObject->setUniform("nVertices", static_cast<unsigned int>(_vertexArray.size()));
@@ -179,6 +193,14 @@ void RenderableTrail::render(const RenderData& data) {
// _programObject->setUniform("forceFade", _distanceFade);
//}
bool usingFramebufferRenderer =
OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer;
if (usingFramebufferRenderer) {
glDepthMask(false);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
glLineWidth(_lineWidth);
glBindVertexArray(_vaoID);
@@ -194,6 +216,12 @@ void RenderableTrail::render(const RenderData& data) {
glBindVertexArray(0);
}
if (usingFramebufferRenderer) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(true);
}
_programObject->deactivate();
}
@@ -0,0 +1,416 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/base/rendering/renderabletrailnew.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/updatestructures.h>
#include <openspace/util/timerange.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/interaction/interactionhandler.h>
#include <ghoul/opengl/programobject.h>
#include <limits>
#include <stdint.h>
namespace {
const std::string _loggerCat = "RenderableTrailNew";
// Spice
const std::string keyBody = "Body";
const std::string keyFrame = "Frame";
const std::string keyObserver = "Observer";
// Rendering properties
const std::string keyLineColor = "LineColor";
const std::string keyPointColor = "PointColor";
const std::string keyLineFade = "LineFade";
const std::string keyLineWidth = "LineWidth";
const std::string keyRenderPart = "RenderPart";
const std::string keyShowTimeStamps = "ShowTimeStamps";
const std::string keyRenderFullTrail = "RenderFullTrail";
// Time interval
const std::string keyTimeRange = "TimeRange";
const std::string keySampleDeltaTime = "SampleDeltaTime";
const std::string keySubSamples = "SubSamples";
// Static Constants
static const glm::vec3 DEFAULT_COLOR = glm::vec3(1.0f);
static const float DEFAULT_LINE_FADE = 0.5f;
static const float DEFAULT_LINE_WIDTH = 2.0f;
static const int DEFAULT_POINT_STEPS = 1;
static const int DEFAULT_RENDER_PART = 1;
static const bool DEFAULT_SHOW_TIME_STAMPS = false;
static const bool DEFAULT_RENDER_FULL_TRAIL = false;
}
namespace openspace {
RenderableTrailNew::RenderableTrailNew(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
// Properties
, _lineColor("lineColor", "Line Color", DEFAULT_COLOR, glm::vec3(0), glm::vec3(1))
, _pointColor("pointColor", "Point Color", DEFAULT_COLOR, glm::vec3(0), glm::vec3(1))
, _lineFade("lineFade", "Line Fade", DEFAULT_LINE_FADE, 0, 1)
, _lineWidth("lineWidth", "Line Width", DEFAULT_LINE_WIDTH, 1, 10)
, _renderPart("renderPart", "Render Part", DEFAULT_RENDER_PART, 0, DEFAULT_RENDER_PART)
, _showTimeStamps("showTimeStamps", "Show TimeStamps", DEFAULT_SHOW_TIME_STAMPS)
, _renderFullTrail("renderFullTrail", "Render Full Trail", DEFAULT_RENDER_FULL_TRAIL)
// OpenGL
, _vaoGlobalID(0)
, _vBufferGlobalID(0)
, _vaoLocalID(0)
, _vBufferLocalID(0)
// Other
, _programObject(nullptr)
, _successfullDictionaryFetch(true)
, _currentTimeClamped(0)
, _subSamples(0)
{
ghoul::Dictionary timeRangeDict;
// Values that needs to be set
_successfullDictionaryFetch &= dictionary.getValue(keyBody, _body);
_successfullDictionaryFetch &= dictionary.getValue(keyObserver, _observer);
_successfullDictionaryFetch &= dictionary.getValue(keyFrame, _frame);
_successfullDictionaryFetch &= dictionary.getValue(keySampleDeltaTime, _sampleDeltaTime);
_successfullDictionaryFetch &= dictionary.getValue(keyTimeRange, timeRangeDict);
_successfullDictionaryFetch &= TimeRange::initializeFromDictionary(
timeRangeDict, _timeRange);
// Validate
_successfullDictionaryFetch &= _sampleDeltaTime > 0;
// Initialize optional values
glm::vec3 lineColor = glm::vec3(DEFAULT_COLOR);
glm::vec3 pointColor = glm::vec3(DEFAULT_COLOR);
float lineFade = DEFAULT_LINE_FADE;
float lineWidth = DEFAULT_LINE_WIDTH;
float pointSteps = DEFAULT_POINT_STEPS;
double renderPart = DEFAULT_RENDER_PART;
bool showTimeStamps = DEFAULT_SHOW_TIME_STAMPS;
bool renderFullTrail = DEFAULT_RENDER_FULL_TRAIL;
// Fetch from dictionary
dictionary.getValue(keyLineColor, lineColor);
dictionary.getValue(keyPointColor, pointColor);
dictionary.getValue(keyLineFade, lineFade);
dictionary.getValue(keyLineWidth, lineWidth);
dictionary.getValue(keyRenderPart, renderPart);
dictionary.getValue(keyShowTimeStamps, showTimeStamps);
dictionary.getValue(keyRenderFullTrail, renderFullTrail);
float fSubSamples; // ghoul can not read ints from dictionaries...
if (dictionary.getValue(keySubSamples, fSubSamples))
_subSamples = fSubSamples;
// Set property values
_lineColor = lineColor;
_pointColor = pointColor;
_lineFade = lineFade;
_lineWidth = lineWidth;
_renderPart = renderPart;
_showTimeStamps = showTimeStamps;
_renderFullTrail = renderFullTrail;
// Add all properties and set view options
addProperty(_lineColor);
addProperty(_pointColor);
addProperty(_lineFade);
addProperty(_lineWidth);
addProperty(_renderPart);
addProperty(_showTimeStamps);
addProperty(_renderFullTrail);
_lineColor.setViewOption(properties::Property::ViewOptions::Color);
_pointColor.setViewOption(properties::Property::ViewOptions::Color);
}
bool RenderableTrailNew::initialize() {
if (!_successfullDictionaryFetch) {
LERROR("The following keys need to be set in the Dictionary. Cannot initialize!");
LERROR(keyBody << ": " << _body);
LERROR(keyObserver << ": " << _observer);
LERROR(keyFrame << ": " << _frame);
LERROR(keyTimeRange);
return false;
}
if (_subSamples < 0)
LERROR("SubSamples must not be less than 0: " << _subSamples);
RenderEngine& renderEngine = OsEng.renderEngine();
_programObject = renderEngine.buildRenderProgram("RenderableTrailNewProgram",
"${MODULE_BASE}/shaders/renderabletrailnew_vs.glsl",
"${MODULE_BASE}/shaders/renderabletrailnew_fs.glsl");
if (!_programObject)
return false;
sweepTimeRange();
initializeGlobalOpenGLPathData();
initializeLocalOpenGLPathData();
return true;
}
void RenderableTrailNew::initializeGlobalOpenGLPathData() {
glGenVertexArrays(1, &_vaoGlobalID);
glGenBuffers(1, &_vBufferGlobalID);
glBindVertexArray(_vaoGlobalID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferGlobalID);
// No need to update the trail several times, no need for stream draw.
glBufferData(
GL_ARRAY_BUFFER,
_vertexPositionArray.size() * sizeof(glm::vec3),
&_vertexPositionArray[0],
GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindVertexArray(0);
}
void RenderableTrailNew::initializeLocalOpenGLPathData() {
glGenVertexArrays(1, &_vaoLocalID);
glGenBuffers(1, &_vBufferLocalID);
glBindVertexArray(_vaoLocalID);
glBindBuffer(GL_ARRAY_BUFFER, _vBufferLocalID);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindVertexArray(0);
}
void RenderableTrailNew::deInitializeGlobalOpenGLPathData() {
glDeleteVertexArrays(1, &_vaoGlobalID);
glDeleteBuffers(1, &_vBufferGlobalID);
}
void RenderableTrailNew::deInitializeLocalOpenGLPathData() {
glDeleteVertexArrays(1, &_vaoLocalID);
glDeleteBuffers(1, &_vBufferLocalID);
}
bool RenderableTrailNew::deinitialize() {
deInitializeGlobalOpenGLPathData();
deInitializeLocalOpenGLPathData();
RenderEngine& renderEngine = OsEng.renderEngine();
if (_programObject) {
renderEngine.removeRenderProgram(_programObject);
_programObject = nullptr;
}
return true;
}
void RenderableTrailNew::sweepTimeRange() {
double lightTime = 0.0;
double subDeltaTime = _sampleDeltaTime / (1 + _subSamples);
glm::dvec3 bodyPosition;
// Loop through all points from time range start to end
for (double t = _timeRange.start; t < _timeRange.end; t += subDeltaTime) {
try {
bodyPosition = SpiceManager::ref().targetPosition(
_body, _observer, _frame, {}, t, lightTime);
}
catch (const SpiceManager::SpiceException& e) {
LERROR(e.what());
break;
}
// Convert from km used by SPICE to meters used by OpenSpace
bodyPosition *= 1000;
_vertexPositionArray.push_back(glm::vec3(bodyPosition));
}
// Last point
bodyPosition = SpiceManager::ref().targetPosition(
_body, _observer, _frame, {}, _timeRange.end, lightTime);
_vertexPositionArray.push_back(glm::vec3(bodyPosition));
}
bool RenderableTrailNew::isReady() const {
return (_programObject != nullptr) && _successfullDictionaryFetch;
}
void RenderableTrailNew::render(const RenderData& data) {
_programObject->activate();
if (_renderFullTrail.value() == true) {
preRender(_vertexPositionArray.size());
preRenderSubPathGlobally(data);
// Easy but not beautiful solution to render all vertices with max alpha
_programObject->setUniform(
"vertexIDPadding", static_cast<int>(_vertexPositionArray.size()));
renderLines(_vaoGlobalID, _vertexPositionArray.size() - 1);
if (_showTimeStamps) {
renderPoints(_vaoGlobalID, _vertexPositionArray.size() - 1);
}
}
else { // Only render the trail up to the point of the object body
int nVerticesToDraw = glm::ceil(_vertexPositionArray.size() *
(_currentTimeClamped - _timeRange.start) / (_timeRange.end - _timeRange.start));
nVerticesToDraw = glm::min(
nVerticesToDraw, static_cast<int>(_vertexPositionArray.size())) - 1;
if (nVerticesToDraw > 1) {
preRender(nVerticesToDraw);
// Perform rendering of the bulk of the trail in single floating point precision
preRenderSubPathGlobally(data);
// The last vertex is drawn with higher precision after this
// Hence we subtract one vertex from the ones to draw globally
int nVerticesToDrawGlobally = nVerticesToDraw - 1;
renderLines(_vaoGlobalID, nVerticesToDrawGlobally);
if (_showTimeStamps) {
renderPoints(_vaoGlobalID, nVerticesToDrawGlobally);
}
// The last line segment is rendered relative to body to achieve high precision
preRenderSubPathLocally(data, nVerticesToDraw);
renderLines(_vaoLocalID, 2);
if (_showTimeStamps) {
renderPoints(_vaoLocalID, 2);
}
}
else if (_currentTimeClamped > _timeRange.start) {
preRenderSubPathLocally(data, 2);
renderLines(_vaoLocalID, 2);
}
}
_programObject->deactivate();
}
void RenderableTrailNew::preRender(int totalNumVerticesToDraw) {
// Upload uniforms that are the same for global and local rendering to the program
_programObject->setUniform("lineFade", _lineFade.value());
_programObject->setUniform("subSamples", _subSamples);
_programObject->setUniform("maxNumVertices",
static_cast<int>(_renderPart.value() * _vertexPositionArray.size()));
_programObject->setUniform("numVertices", totalNumVerticesToDraw);
}
void RenderableTrailNew::preRenderSubPathGlobally(const RenderData& data) {
// Model transform and view transform needs to be in double precision
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * _modelTransform;
glm::mat4 modelViewProjectionTransform =
data.camera.projectionMatrix() * glm::mat4(modelViewTransform);
// Upload uniforms that are specific to global rendering to the shader program
_programObject->setUniform(
"modelViewProjectionTransform", modelViewProjectionTransform);
_programObject->setUniform("vertexIDPadding", 0);
}
void RenderableTrailNew::preRenderSubPathLocally(
const RenderData& data, int totalNumVerticesToDraw) {
glm::dvec3 v0; // Vertex that connects to the global part of the trail
glm::dvec3 v1; // last vertex of the trail is in the position of the body
v0 = _vertexPositionArray[totalNumVerticesToDraw - 2];
v1 = _clampedBodyPosition;
// Define positions relative to body (v1) which gives the high precision
glm::vec3 vertexData[2] = {glm::vec3(v0 - v1), glm::vec3(0)};
// Translation translates from the position of body so vertices should
// be defined relative to body (hence the added v1 in translation part of model matrix)
glm::dmat4 localTranslation = glm::translate(glm::dmat4(1.0), v1);
glm::dmat4 modelTransformLocal = _modelTransform * localTranslation;
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransformLocal;
glm::mat4 modelViewProjectionTransform =
data.camera.projectionMatrix() * glm::mat4(modelViewTransform);
// Upload the new MVP matrix to the shader program
_programObject->setUniform(
"modelViewProjectionTransform", modelViewProjectionTransform);
_programObject->setUniform("vertexIDPadding", totalNumVerticesToDraw - 2);
// Update the attribute data on the GPU
glBindBuffer(GL_ARRAY_BUFFER, _vBufferLocalID);
glBufferData(
GL_ARRAY_BUFFER,
2 * sizeof(glm::vec3), // Only two vertices for this part of the trail
vertexData, // Two vertices
GL_DYNAMIC_DRAW); // This part of the path is rendered dynamically
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
}
void RenderableTrailNew::renderLines(GLuint vao, int numberOfVertices) {
glLineWidth(_lineWidth);
_programObject->setUniform("color", _lineColor.value());
glBindVertexArray(vao);
glDrawArrays(GL_LINE_STRIP, 0, static_cast<GLsizei>(numberOfVertices));
glBindVertexArray(0);
glLineWidth(1.f);
}
void RenderableTrailNew::renderPoints(GLuint vao, int numberOfVertices) {
glEnable(GL_PROGRAM_POINT_SIZE);
_programObject->setUniform("color", _pointColor.value());
_programObject->setUniform("pointSize", static_cast<float>(_lineWidth * 3));
glBindVertexArray(vao);
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(numberOfVertices));
glBindVertexArray(0);
glDisable(GL_PROGRAM_POINT_SIZE);
}
void RenderableTrailNew::update(const UpdateData& data) {
_currentTimeClamped = glm::clamp(data.time, _timeRange.start, _timeRange.end);
_modelTransform =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)));
// Fetch the body position using SPICE
double lightTime = 0.0;
try {
_clampedBodyPosition = SpiceManager::ref().targetPosition(
_body, _observer, _frame, {}, _currentTimeClamped, lightTime);
}
catch (const SpiceManager::SpiceException& e) {
try {
_clampedBodyPosition = SpiceManager::ref().targetPosition(
_body, _observer, _frame, {}, _currentTimeClamped, _timeRange.end);
}
catch (const SpiceManager::SpiceException& e) {
return;
}
}
// Convert from km used by SPICE to meters used by OpenSpace
_clampedBodyPosition *= 1000;
}
} // namespace openspace
+116
View File
@@ -0,0 +1,116 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __RENDERABLETRAILNEW_H__
#define __RENDERABLETRAILNEW_H__
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/vectorproperty.h>
#include <openspace/util/timerange.h>
#include <ghoul/opengl/ghoul_gl.h>
namespace ghoul {
namespace opengl {
class ProgramObject;
class Texture;
}
}
namespace openspace {
/**
* This class currently has a temporary name until it is merged with or replaces
* RenderableTrail. It renders the trail with higher precision close to the
* position of the body of a renderable. The lua mod dictionary describing the
* renderable trail is changed.
*/
class RenderableTrailNew : public Renderable {
public:
explicit RenderableTrailNew(const ghoul::Dictionary& dictionary);
bool initialize() override;
bool deinitialize() override;
bool isReady() const override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
private:
void sweepTimeRange();
void initializeGlobalOpenGLPathData();
void initializeLocalOpenGLPathData();
void deInitializeGlobalOpenGLPathData();
void deInitializeLocalOpenGLPathData();
void preRender(int totalNumVerticesToDraw);
void preRenderSubPathGlobally(const RenderData& renderData);
void preRenderSubPathLocally(const RenderData& renderData, int totalNumVerticesToDraw);
void renderLines(GLuint vao, int numberOfVertices);
void renderPoints(GLuint vao, int numberOfVertices);
// Spice
std::string _body;
std::string _observer;
std::string _frame;
// Properties
properties::Vec3Property _lineColor;
properties::Vec3Property _pointColor;
properties::FloatProperty _lineFade;
properties::FloatProperty _lineWidth;
properties::FloatProperty _renderPart;
properties::BoolProperty _showTimeStamps;
properties::BoolProperty _renderFullTrail;
// OpenGL
GLuint _vaoGlobalID;
GLuint _vBufferGlobalID;
GLuint _vaoLocalID;
GLuint _vBufferLocalID;
// Other
bool _successfullDictionaryFetch;
TimeRange _timeRange;
double _sampleDeltaTime;
int _subSamples;
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
std::vector<glm::vec3> _vertexPositionArray;
// Data updated in update function
double _currentTimeClamped; // Time clamped to time range
glm::dmat4 _modelTransform;
glm::dvec3 _clampedBodyPosition; // Position of body clamped to time range
};
} // namespace openspace
#endif // __RENDERABLETRAILNEW_H__
@@ -22,37 +22,35 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/base/ephemeris/spiceephemeris.h>
#include <modules/base/rotation/spicerotation.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/time.h>
namespace {
const std::string _loggerCat = "SpiceEphemeris";
const std::string _loggerCat = "SpiceRotation";
//const std::string keyGhosting = "EphmerisGhosting";
const std::string KeyBody = "Body";
const std::string KeyOrigin = "Observer";
const std::string KeySourceFrame = "SourceFrame";
const std::string KeyDestinationFrame = "DestinationFrame";
const std::string KeyKernels = "Kernels";
}
namespace openspace {
SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary)
: _targetName("")
, _originName("")
, _position()
SpiceRotation::SpiceRotation(const ghoul::Dictionary& dictionary)
: _sourceFrame("")
, _destinationFrame("")
, _rotationMatrix(1.0)
, _kernelsLoadedSuccessfully(true)
{
const bool hasBody = dictionary.getValue(KeyBody, _targetName);
if (!hasBody)
LERROR("SpiceEphemeris does not contain the key '" << KeyBody << "'");
const bool hasSourceFrame = dictionary.getValue(KeySourceFrame, _sourceFrame);
if (!hasSourceFrame)
LERROR("SpiceRotation does not contain the key '" << KeySourceFrame << "'");
const bool hasObserver = dictionary.getValue(KeyOrigin, _originName);
if (!hasObserver)
LERROR("SpiceEphemeris does not contain the key '" << KeyOrigin << "'");
//dictionary.getValue(keyGhosting, _ghosting);
const bool hasDestinationFrame = dictionary.getValue(KeyDestinationFrame, _destinationFrame);
if (!hasDestinationFrame)
LERROR("SpiceRotation does not contain the key '" << KeyDestinationFrame << "'");
ghoul::Dictionary kernels;
dictionary.getValue(KeyKernels, kernels);
@@ -73,26 +71,23 @@ SpiceEphemeris::SpiceEphemeris(const ghoul::Dictionary& dictionary)
}
}
const psc& SpiceEphemeris::position() const {
return _position;
const glm::dmat3& SpiceRotation::matrix() const {
return _rotationMatrix;
}
void SpiceEphemeris::update(const UpdateData& data) {
void SpiceRotation::update(const UpdateData& data) {
if (!_kernelsLoadedSuccessfully)
return;
double lightTime = 0.0;
glm::dvec3 position = SpiceManager::ref().targetPosition(_targetName, _originName, "GALACTIC", {}, data.time, lightTime);
//double interval = openspace::ImageSequencer::ref().getIntervalLength();
//if (_ghosting == "TRUE" && interval > 60){
// double _time = openspace::ImageSequencer::ref().getNextCaptureTime();
// SpiceManager::ref().getTargetPosition(_targetName, _originName,
// "GALACTIC", "NONE", _time, position, lightTime);
//}
//
_position = psc::CreatePowerScaledCoordinate(position.x, position.y, position.z);
_position[3] += 3;
try {
_rotationMatrix = SpiceManager::ref().positionTransformMatrix(
_sourceFrame,
_destinationFrame,
data.time);
}
catch (const ghoul::RuntimeError&) {
// In case of missing coverage
_rotationMatrix = glm::dmat3(1);
}
}
} // namespace openspace
@@ -22,30 +22,26 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __SPICEEPHEMERIS_H__
#define __SPICEEPHEMERIS_H__
#ifndef __SPICEROTATION_H__
#define __SPICEROTATION_H__
#include <openspace/scene/ephemeris.h>
#include <openspace/util/powerscaledcoordinate.h>
#include <openspace/scene/rotation.h>
namespace openspace {
class SpiceEphemeris : public Ephemeris {
class SpiceRotation : public Rotation {
public:
SpiceEphemeris(const ghoul::Dictionary& dictionary);
const psc& position() const;
SpiceRotation(const ghoul::Dictionary& dictionary);
virtual const glm::dmat3& matrix() const;
void update(const UpdateData& data) override;
private:
std::string _targetName;
std::string _originName;
psc _position;
std::string _sourceFrame;
std::string _destinationFrame;
glm::dmat3 _rotationMatrix;
bool _kernelsLoadedSuccessfully;
//std::string _ghosting;
std::string _name;
};
} // namespace openspace
#endif // __SPICEEPHEMERIS_H__
#endif // __SPICEROTATION_H__
@@ -22,31 +22,31 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/base/ephemeris/staticephemeris.h>
#include <modules/base/rotation/staticrotation.h>
namespace {
const std::string KeyPosition = "Position";
const std::string KeyEulerAngles = "EulerAngles";
}
namespace openspace {
StaticEphemeris::StaticEphemeris(const ghoul::Dictionary& dictionary)
: _position(0.f, 0.f, 0.f, 0.f)
StaticRotation::StaticRotation(const ghoul::Dictionary& dictionary)
: _rotationMatrix(1.0)
{
const bool hasPosition = dictionary.hasKeyAndValue<glm::vec4>(KeyPosition);
if (hasPosition) {
glm::vec4 tmp;
dictionary.getValue(KeyPosition, tmp);
_position = tmp;
const bool hasEulerAngles = dictionary.hasKeyAndValue<glm::dvec3>(KeyEulerAngles);
if (hasEulerAngles) {
glm::dvec3 tmp;
dictionary.getValue(KeyEulerAngles, tmp);
_rotationMatrix = glm::mat3_cast(glm::dquat(tmp));
}
}
StaticEphemeris::~StaticEphemeris() {}
StaticRotation::~StaticRotation() {}
const psc& StaticEphemeris::position() const {
return _position;
const glm::dmat3& StaticRotation::matrix() const {
return _rotationMatrix;
}
void StaticEphemeris::update(const UpdateData&) {}
void StaticRotation::update(const UpdateData&) {}
} // namespace openspace
@@ -22,24 +22,24 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __STATICEPHEMERIS_H__
#define __STATICEPHEMERIS_H__
#ifndef __STATICROTATION_H__
#define __STATICROTATION_H__
#include <openspace/scene/ephemeris.h>
#include <openspace/scene/rotation.h>
namespace openspace {
class StaticEphemeris: public Ephemeris {
class StaticRotation: public Rotation {
public:
StaticEphemeris(const ghoul::Dictionary& dictionary
StaticRotation(const ghoul::Dictionary& dictionary
= ghoul::Dictionary());
virtual ~StaticEphemeris();
virtual const psc& position() const;
virtual ~StaticRotation();
virtual const glm::dmat3& matrix() const;
virtual void update(const UpdateData& data) override;
private:
psc _position;
glm::dmat3 _rotationMatrix;
};
} // namespace openspace
#endif // __STATICEPHEMERIS_H__
#endif // __STATICROTATION_H__
+68
View File
@@ -0,0 +1,68 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/base/scale/staticscale.h>
#include <openspace/documentation/verifier.h>
namespace {
const std::string _loggerCat = "StaticScale";
const std::string KeyValue = "Scale";
}
namespace openspace {
Documentation StaticScale::Documentation() {
using namespace openspace::documentation;
return {
"Static Scaling",
"base_scale_static",
{{
KeyValue,
new DoubleVerifier,
"The scaling factor by which the scenegraph node is scaled."
}}
};
}
StaticScale::StaticScale()
: _scaleValue("scale", "Scale", 1.0, 1.0, 1000.0)
{
addProperty(_scaleValue);
}
StaticScale::StaticScale(const ghoul::Dictionary& dictionary)
: StaticScale()
{
documentation::testSpecificationAndThrow(Documentation(), dictionary, "StaticScale");
_scaleValue = dictionary.value<double>(KeyValue);
}
double StaticScale::scaleValue() const {
return _scaleValue;
}
} // namespace openspace
+48
View File
@@ -0,0 +1,48 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __STATICSCALE_H__
#define __STATICSCALE_H__
#include <openspace/scene/scale.h>
#include <openspace/documentation/documentation.h>
namespace openspace {
class StaticScale : public Scale {
public:
StaticScale();
StaticScale(const ghoul::Dictionary& dictionary);
double scaleValue() const;
static openspace::Documentation Documentation();
private:
properties::FloatProperty _scaleValue;
};
} // namespace openspace
#endif // __STATICSCALE_H__
+6 -6
View File
@@ -205,7 +205,7 @@ float phaseFunctionR(float mu) {
// Mie phase function
float phaseFunctionM(float mu) {
return 1.5 * 1.0 / (4.0 * M_PI) * (1.0 - mieG*mieG) * pow(1.0 + (mieG*mieG) - 2.0*mieG*mu, -3.0/2.0) * (1.0 + mu * mu) / (2.0 + mieG*mieG);
return 1.5 * 1.0 / (4.0 * M_PI) * (1.0 - mieG*mieG) * pow(1.0 + (mieG*mieG) - 2.0*mieG*mu, -3.0/2.0) * (1.0 + mu * mu) / (2.0 + mieG*mieG);
}
float opticalDepth(float H, float r, float mu, float d) {
@@ -225,7 +225,7 @@ vec4 texture4D(sampler3D table, float r, float mu, float muS, float nu)
float rmu = r * mu;
float delta = rmu * rmu - r * r + Rg * Rg;
vec4 cst = rmu < 0.0 && delta > 0.0 ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / float(RES_MU)) : vec4(-1.0, H * H, H, 0.5 + 0.5 / float(RES_MU));
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
float uMu = cst.w + (rmu * cst.x + sqrt(delta + cst.y)) / (rho + cst.z) * (0.5 - 1.0 / float(RES_MU));
float uMuS = 0.5 / float(RES_MU_S) + (atan(max(muS, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / float(RES_MU_S));
float lerp = (nu + 1.0) / 2.0 * (float(RES_NU) - 1.0);
@@ -240,18 +240,18 @@ vec3 analyticTransmittance(float r, float mu, float d) {
}
vec3 getMie(vec4 rayMie) {
return rayMie.rgb * rayMie.a / max(rayMie.r, 1e-4) * (betaR.r / betaR);
return rayMie.rgb * rayMie.a / max(rayMie.r, 1e-4) * (betaR.r / betaR);
}
vec2 getTransmittanceUV(float r, float mu) {
float uR, uMu;
uR = sqrt((r - Rg) / (Rt - Rg));
uMu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
uR = sqrt((r - Rg) / (Rt - Rg));
uMu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
return vec2(uMu, uR);
}
vec3 transmittanceFromTexture(float r, float mu) {
vec2 uv = getTransmittanceUV(r, mu);
vec2 uv = getTransmittanceUV(r, mu);
return texture(transmittanceTexture, uv).rgb;
}
+3 -3
View File
@@ -59,9 +59,9 @@ void getMuMuSNu(const float r, vec4 dhdH, out float mu, out float mu_s, out floa
}
vec3 transmittanceFromTexture(const float r, const float mu) {
float u_r = sqrt((r - Rg) / (Rt - Rg));
float u_r = sqrt((r - Rg) / (Rt - Rg));
// See Colliene to understand the different mapping.
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
return texture(transmittanceTexture, vec2(u_mu, u_r)).rgb;
}
@@ -106,7 +106,7 @@ vec4 texture4D(sampler3D table, const float r, const float mu,
float rmu = r * mu;
float delta = rmu * rmu - r * r + Rg * Rg;
vec4 cst = rmu < 0.0 && delta > 0.0 ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / float(RES_MU)) : vec4(-1.0, H * H, H, 0.5 + 0.5 / float(RES_MU));
float u_r = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
float u_r = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
float u_mu = cst.w + (rmu * cst.x + sqrt(delta + cst.y)) / (rho + cst.z) * (0.5 - 1.0 / float(RES_MU));
float u_mu_s = 0.5 / float(RES_MU_S) + (atan(max(mu_s, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / float(RES_MU_S));
float lerp = (nu + 1.0) / 2.0 * (float(RES_NU) - 1.0);
+6 -9
View File
@@ -22,24 +22,21 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
in vec4 vs_point_position;
in vec4 vs_point_velocity;
in float fade;
uniform float forceFade;
uniform vec3 color;
in vec4 vs_positionScreenSpace;
in float fade;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment() {
vec4 position = vs_point_position;
float depth = pscDepth(position);
vec4 c = vec4(color, fade*forceFade);
vec4 c = vec4(color * fade * forceFade, 1.0);
Fragment frag;
frag.color = c;
frag.depth = depth;
frag.depth = vs_positionScreenSpace.w;
frag.blend = BLEND_MODE_ADDITIVE;
return frag;
}
+13 -13
View File
@@ -24,28 +24,28 @@
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform mat4 modelViewTransform;
uniform mat4 projectionTransform;
uniform vec4 objectVelocity;
layout(location = 0) in vec4 in_point_position;
out vec4 vs_point_position;
out float fade;
uniform uint nVertices;
uniform float lineFade;
layout(location = 0) in vec4 in_point_position;
out vec4 vs_positionScreenSpace;
out float fade;
#include "PowerScaling/powerScaling_vs.hglsl"
void main() {
float id = float(gl_VertexID) / float(nVertices * lineFade);
fade = 1.0 - id;
vec4 tmp = in_point_position;
vec4 position = pscTransform(tmp, ModelTransform);
vs_point_position = tmp;
position = ViewProjection * position;
gl_Position = z_normalization(position);
// Convert from psc to regular homogenous coordinates
vec4 position = vec4(in_point_position.xyz * pow(10, in_point_position.w), 1);
vec4 positionClipSpace = projectionTransform * modelViewTransform * position;
vs_positionScreenSpace = z_normalization(positionClipSpace);
gl_Position = vs_positionScreenSpace;
}
+3 -4
View File
@@ -26,15 +26,13 @@ uniform float time;
uniform sampler2D texture1;
in vec2 vs_st;
in vec4 vs_position;
in vec4 vs_positionScreenSpace;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment()
{
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse;
if (gl_FrontFacing)
diffuse = texture(texture1, vs_st);
@@ -44,6 +42,7 @@ Fragment getFragment()
Fragment frag;
frag.color = diffuse;
frag.depth = depth;
frag.depth = vs_positionScreenSpace.w;
return frag;
}
+9 -10
View File
@@ -24,26 +24,25 @@
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform mat4 modelViewProjectionTransform;
layout(location = 0) in vec4 in_position;
layout(location = 1) in vec2 in_st;
out vec2 vs_st;
out vec4 vs_position;
out vec4 vs_positionScreenSpace;
out float s;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
vec4 tmp = in_position;
vec4 position = pscTransform(tmp, ModelTransform);
vec4 position = vec4(in_position.xyz * pow(10, in_position.w), 1);
vec4 positionClipSpace = modelViewProjectionTransform * position;
vs_position = tmp;
vs_st = in_st;
position = ViewProjection * position;
gl_Position = z_normalization(position);
// Write output
vs_positionScreenSpace = z_normalization(positionClipSpace);
gl_Position = vs_positionScreenSpace;
vs_st = in_st;
}
@@ -58,9 +58,9 @@ void getMuMuSNu(const float r, vec4 dhdH, out float mu, out float mu_s, out floa
}
vec3 transmittanceFromTexture(const float r, const float mu) {
float u_r = sqrt((r - Rg) / (Rt - Rg));
float u_r = sqrt((r - Rg) / (Rt - Rg));
// See Colliene to understand the different mapping.
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
return texture(transmittanceTexture, vec2(u_mu, u_r)).rgb;
}
@@ -59,7 +59,7 @@ vec4 texture4D(sampler3D table, float r, float mu, float muS, float nu)
float rmu = r * mu;
float delta = rmu * rmu - r * r + Rg * Rg;
vec4 cst = rmu < 0.0 && delta > 0.0 ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / float(RES_MU)) : vec4(-1.0, H * H, H, 0.5 + 0.5 / float(RES_MU));
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
float uMu = cst.w + (rmu * cst.x + sqrt(delta + cst.y)) / (rho + cst.z) * (0.5 - 1.0 / float(RES_MU));
float uMuS = 0.5 / float(RES_MU_S) + (atan(max(muS, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / float(RES_MU_S));
float lerp = (nu + 1.0) / 2.0 * (float(RES_NU) - 1.0);
@@ -82,9 +82,9 @@ float limit(float r, float mu) {
}
vec3 transmittanceFromTexture(const float r, const float mu) {
float u_r = sqrt((r - Rg) / (Rt - Rg));
float u_r = sqrt((r - Rg) / (Rt - Rg));
// See Colliene to understand the different mapping.
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
return texture(transmittanceTexture, vec2(u_mu, u_r)).rgb;
}
+2 -2
View File
@@ -36,9 +36,9 @@ void getRAndMu(out float r, out float mu) {
}
vec3 transmittance(const float r, const float mu) {
float u_r = sqrt((r - Rg) / (Rt - Rg));
float u_r = sqrt((r - Rg) / (Rt - Rg));
// See Colliene to understand the different mapping.
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
float u_mu = atan((mu + 0.15) / (1.0 + 0.15) * tan(1.5)) / 1.5;
return texture(transmittanceTexture, vec2(u_mu, u_r)).rgb;
}
@@ -57,7 +57,7 @@ vec4 texture4D(sampler3D table, const float r, const float mu,
float rmu = r * mu;
float delta = rmu * rmu - r * r + Rg * Rg;
vec4 cst = rmu < 0.0 && delta > 0.0 ? vec4(1.0, 0.0, 0.0, 0.5 - 0.5 / float(RES_MU)) : vec4(-1.0, H * H, H, 0.5 + 0.5 / float(RES_MU));
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
float uR = 0.5 / float(RES_R) + rho / H * (1.0 - 1.0 / float(RES_R));
float uMu = cst.w + (rmu * cst.x + sqrt(delta + cst.y)) / (rho + cst.z) * (0.5 - 1.0 / float(RES_MU));
float uMuS = 0.5 / float(RES_MU_S) + (atan(max(muS, -0.1975) * tan(1.26 * 1.1)) / 1.1 + (1.0 - 0.26)) * 0.5 * (1.0 - 1.0 / float(RES_MU_S));
float lerp = (nu + 1.0) / 2.0 * (float(RES_NU) - 1.0);
+42 -40
View File
@@ -22,63 +22,65 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
uniform vec4 campos;
uniform vec4 objpos;
uniform vec3 cam_dir; // add this for specular
uniform vec3 sun_pos;
uniform bool _performShading = true;
// Uniforms
uniform float transparency;
uniform int shadows;
uniform float fading;
uniform bool performShading = true;
uniform vec3 directionToSunViewSpace;
uniform float time;
uniform sampler2D texture1;
// Input from the vertex shader
in vec2 vs_st;
in vec4 vs_normal;
in vec4 vs_position;
in vec3 vs_normalViewSpace;
in vec4 vs_positionCameraSpace;
in vec4 vs_positionScreenSpace;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment() {
vec4 position = vs_position;
float depth = pscDepth(position);
//depth = length(campos - position);
vec4 diffuse = texture(texture1, vs_st);
vec4 textureSample = texture(texture1, vs_st);
vec3 diffuseAlbedo = textureSample.rgb;
vec3 specularAlbedo = vec3(1);
diffuse[3] = fading;
vec3 color;
if (_performShading) {
vec4 spec = vec4(0.0);
if (performShading) {
// Some of these values could be passed in as uniforms
vec3 lightColorAmbient = vec3(1);
vec3 lightColor = vec3(1);
vec3 n = normalize(vs_normal.xyz);
vec3 l_pos = vec3(sun_pos); // sun.
vec3 l_dir = normalize(l_pos-objpos.xyz);
float intensity = min(max(1*dot(n,l_dir), 0.0), 1);
float shine = 100;
vec4 specular = vec4(1.0);
vec4 ambient =diffuse*0.4;
ambient[3] = transparency;
if(intensity > 0.0f){
// halfway vector
vec3 h = normalize(l_dir + normalize(cam_dir));
// specular factor
float intSpec = max(dot(n,h),0.0);
spec = specular * pow(intSpec, shine);
}
diffuse = vec4(max(intensity * diffuse , ambient).xyz,1) +spec*1.5*diffuse ;
vec3 n = normalize(vs_normalViewSpace);
vec3 l = directionToSunViewSpace;
vec3 c = normalize(vs_positionCameraSpace.xyz);
vec3 r = reflect(l, n);
float ambientIntensity = 0.2;
float diffuseIntensity = 1;
float specularIntensity = 1;
float diffuseCosineFactor = dot(n,l);
float specularCosineFactor = dot(c,r);
float specularPower = 100;
vec3 ambientColor = ambientIntensity * lightColorAmbient * diffuseAlbedo;
vec3 diffuseColor = diffuseIntensity * lightColor * diffuseAlbedo * max(diffuseCosineFactor, 0);
vec3 specularColor = specularIntensity * lightColor * specularAlbedo * pow(max(specularCosineFactor, 0), specularPower);
color = ambientColor + diffuseColor + specularColor;
}
else {
color = diffuseAlbedo;
}
diffuse[3] = fading*transparency;
float alpha = fading * transparency;
Fragment frag;
frag.color = diffuse;
frag.depth = depth;
frag.color = vec4(color, alpha);
frag.depth = vs_positionScreenSpace.w;
return frag;
}
+22 -22
View File
@@ -24,38 +24,38 @@
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform float _magnification;
// Vertex attributes
layout(location = 0) in vec4 in_position;
//in vec3 in_position;
layout(location = 1) in vec2 in_st;
layout(location = 2) in vec3 in_normal;
// Uniforms
uniform mat4 modelViewTransform;
uniform mat4 projectionTransform;
uniform vec3 cameraDirectionWorldSpace;
uniform float _magnification;
// Outputs
out vec2 vs_st;
out vec4 vs_normal;
out vec4 vs_position;
out float s;
out vec3 vs_normalViewSpace;
out vec4 vs_positionScreenSpace;
out vec4 vs_positionCameraSpace;
#include "PowerScaling/powerScaling_vs.hglsl"
void main() {
vec4 pos = in_position;
pos.w += _magnification;
vec4 position = in_position;
position.xyz *= pow(10, _magnification);
vs_positionCameraSpace = modelViewTransform * position;
vec4 positionClipSpace = projectionTransform * vs_positionCameraSpace;
// set variables
// Write output
vs_st = in_st;
//vs_stp = in_position.xyz;
vs_position = pos;
vec4 tmp = pos;
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
vs_positionScreenSpace = z_normalization(positionClipSpace);
gl_Position = vs_positionScreenSpace;
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
position = ViewProjection * position;
gl_Position = z_normalization(position);
// The normal transform should be the transposed inverse of the model transform?
vs_normalViewSpace = normalize(mat3(modelViewTransform) * in_normal);
}
+8 -13
View File
@@ -22,23 +22,18 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
in vec4 vs_point_position;
flat in int isHour;
in vec4 vs_point_color;
uniform vec3 color;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment() {
vec4 position = vs_point_position;
float depth = pscDepth(position);
vec4 diffuse = vs_point_color;
in vec4 vs_positionScreenSpace;
in vec4 vs_pointColor;
Fragment getFragment() {
if (vs_pointColor.a < 0.01)
discard;
Fragment frag;
frag.color = diffuse;
frag.depth = depth;
frag.color = vs_pointColor;
frag.depth = vs_positionScreenSpace.w;
return frag;
}
+26 -96
View File
@@ -25,108 +25,38 @@
#version __CONTEXT__
in vec4 in_point_position;
uniform vec3 color;
uniform mat4 modelViewTransform;
uniform mat4 projectionTransform;
uniform int pointSteps;
out vec4 vs_point_position;
flat out int isHour;
out vec4 vs_point_color;
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform vec4 objectVelocity;
uniform vec4 lastPosition;
//this function does not consider cases where w component is negative
float psc_distance(vec4 v1, vec4 v2) {
// reduce position numbers
/*while(v1.w > 1 && v2.w > 1) {
v1.w -= 1;
v2.w -= 1;
} */
// get position in vec3
if (v1.w > 1) {
float f = floor(v1.w);
v1.xyz *= pow(10, f);
v1.w -= f;
}
if (v2.w > 1) {
float f = floor(v2.w);
v2.xyz *= pow(10, f);
v2.w -= f;
}
// using native distance function
return distance(v1.xyz, v2.xyz);
}
out vec4 vs_positionScreenSpace;
out vec4 vs_pointColor;
#include "PowerScaling/powerScaling_vs.hglsl"
void main() {
vec4 gray = vec4(0.6f, 0.6f, 0.6f, 0.8f);
float cameraTooFar = 1 * pow(k, 10);
float bigPoint = 5.f;
float smallPoint = 2.f;
void main() {
vec4 positionCameraSpace = modelViewTransform * in_point_position;
vec4 positionClipSpace = projectionTransform * positionCameraSpace;
vs_positionScreenSpace = z_normalization(positionClipSpace);
vec4 tmp = in_point_position;
vec4 position = pscTransform(tmp, ModelTransform);
vs_point_position = tmp;
position = ViewProjection * position;
gl_Position = z_normalization(position);
int id = gl_VertexID;
float hour = mod(id, 4);
vs_point_color.xyz = color;
vs_point_color[3] = 1.f;
vec4 v1 = campos;
vec4 v2 = vs_point_position;
float cameraDistance = psc_distance(v1,v2);
vec4 temp = in_point_position;
vec4 templast = lastPosition;
if (temp.w > 1) {
float f = floor(temp.w);
temp.w -= f;
temp.xyz *= pow(10, f);
}
if (templast.w > 1) {
float f = floor(templast.w);
templast.w -= f;
templast.xyz *= pow(10, f);
}
// while(temp.w > 1) {
// temp.xyz *= 10;
// temp.w -= 1;
// }
// while(templast.w > 1) {
// templast.xyz *= 10;
// templast.w -= 1;
// }
float observerDistance = length(temp.xyz);
float lastDistance = length(templast.xyz);
if(hour > 0.1f) {
isHour = 0;
vs_point_color = gray;
gl_PointSize = bigPoint;
}
else {
isHour = 1;
gl_PointSize = bigPoint;
}
if (observerDistance > (lastDistance/20)) {
gl_PointSize = smallPoint;
//vs_point_color = gray;
}
/*if (cameraDistance > cameraTooFar ) {
vs_point_color[3] = 0.0f;
gl_Position = vs_positionScreenSpace;
}*/
if(mod(gl_VertexID, pointSteps) == 0) {
vs_pointColor.rgb = color;
gl_PointSize = 5.0f;
}
else {
vs_pointColor.rgb = (color + vec3(0.6f, 0.6f, 0.6f)) / 2;
gl_PointSize = 2.f;
}
// I don't like this random variable k defined in powerScalingMath.hglsl.
// Will ignore it and use 10 in protest of psc dependencies. /KB
// float maximumDistance = pow(k, 10);
float maximumDistance = pow(10, 10);
float distanceToCamera = length(positionCameraSpace.xyz);
vs_pointColor.a = maximumDistance / (distanceToCamera/100);
}
+7 -4
View File
@@ -24,16 +24,15 @@
uniform float time;
uniform sampler2D texture1;
uniform bool additiveBlending;
in vec2 vs_st;
in vec4 vs_position;
in vec4 vs_positionScreenSpace;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment() {
vec4 position = vs_position;
float depth = pscDepth(position);
vec4 diffuse;
if(gl_FrontFacing)
diffuse = texture(texture1, vs_st);
@@ -51,7 +50,11 @@ Fragment getFragment() {
Fragment frag;
frag.color = diffuse;
frag.depth = depth;
frag.depth = vs_positionScreenSpace.w;
if (additiveBlending) {
frag.blend = BLEND_MODE_ADDITIVE;
}
return frag;
}
+7 -9
View File
@@ -24,26 +24,24 @@
#version __CONTEXT__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
uniform mat4 modelViewProjectionTransform;
layout(location = 0) in vec4 in_position;
layout(location = 1) in vec2 in_st;
out vec2 vs_st;
out vec4 vs_position;
out vec4 vs_positionScreenSpace;
out float s;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
vec4 tmp = in_position;
vec4 position = pscTransform(tmp, ModelTransform);
// Transform the damn psc to homogenous coordinate
vec4 position = vec4(in_position.xyz * pow(10, in_position.w), 1);
vec4 positionClipSpace = modelViewProjectionTransform * position;
vs_positionScreenSpace = z_normalization(positionClipSpace);
gl_Position = vs_positionScreenSpace;
vs_position = tmp;
vs_st = in_st;
position = ViewProjection * position;
gl_Position = z_normalization(position);
}
@@ -0,0 +1,46 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// Inputs
in vec4 vs_positionScreenSpace;
in float vs_alpha;
// Uniforms
uniform float forceFade;
uniform vec3 color;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment() {
if (vs_alpha < 0.01)
discard;
vec4 c = vec4(color, vs_alpha);
Fragment frag;
frag.color = c;
frag.depth = vs_positionScreenSpace.w;
return frag;
}
@@ -0,0 +1,58 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
// Attributes
layout(location = 0) in vec3 in_position;
// Uniforms
uniform mat4 modelViewProjectionTransform;
uniform int numVertices;
uniform int maxNumVertices;
uniform int subSamples;
uniform float lineFade;
uniform int vertexIDPadding;
uniform float pointSize;
// Outputs
out vec4 vs_positionScreenSpace;
out float vs_alpha;
#include "PowerScaling/powerScaling_vs.hglsl"
void main() {
int vertexID = gl_VertexID + vertexIDPadding;
int threshHold = int(lineFade * numVertices);
int nVisibleVertices = min((int(numVertices) - threshHold), maxNumVertices);
vs_alpha = clamp((vertexID - (int(numVertices) - nVisibleVertices))
/ float(nVisibleVertices), 0, 1);
vec4 positionClipSpace = modelViewProjectionTransform * vec4(in_position, 1);
vs_positionScreenSpace = z_normalization(positionClipSpace);
gl_PointSize = (subSamples == 0 || vertexID % subSamples == 0) ? pointSize : pointSize / 2;
gl_Position = vs_positionScreenSpace;
}
@@ -0,0 +1,146 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/base/translation/spicetranslation.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/time.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/documentation/verifier.h>
namespace {
const std::string KeyBody = "Body";
const std::string KeyObserver = "Observer";
const std::string KeyKernels = "Kernels";
const std::string ReferenceFrame = "GALACTIC";
}
namespace openspace {
Documentation SpiceTranslation::Documentation() {
using namespace openspace::documentation;
return {
"Spice Translation",
"base_translation_spicetranslation",
{
{
"Type",
new StringEqualVerifier("SpiceTranslation"),
"",
Optional::No
},
{
KeyBody,
new StringAnnotationVerifier("A valid SPICE NAIF name or identifier"),
"This is the SPICE NAIF name for the body whose translation is to be "
"computed by the SpiceTranslation. It can either be a fully qualified "
"name (such as 'EARTH') or a NAIF integer id code (such as '399').",
Optional::No
},
{
KeyObserver,
new StringAnnotationVerifier("A valid SPICE NAIF name or identifier"),
"This is the SPICE NAIF name for the parent of the body whose "
"translation is to be computed by the SpiceTranslation. It can either be "
"a fully qualified name (such as 'SOLAR SYSTEM BARYCENTER') or a NAIF "
"integer id code (such as '0').",
Optional::No
},
{
KeyKernels,
new OrVerifier(
new TableVerifier({
{ "*", new StringVerifier }
}),
new StringVerifier
),
"A single kernel or list of kernels that this SpiceTranslation depends "
"on. All provided kernels will be loaded before any other operation is "
"performed.",
Optional::Yes
}
},
Exhaustive::Yes
};
}
SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
: _target("target", "Target", "")
, _origin("origin", "Origin", "")
, _kernelsLoadedSuccessfully(true)
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"SpiceTranslation"
);
_target = dictionary.value<std::string>(KeyBody);
_origin = dictionary.value<std::string>(KeyObserver);
auto loadKernel = [](const std::string& kernel) {
if (!FileSys.fileExists(kernel)) {
throw SpiceManager::SpiceException("Kernel '" + kernel + "' does not exist");
}
try {
SpiceManager::ref().loadKernel(kernel);
}
catch (const SpiceManager::SpiceException& exception) {
LERRORC("SpiceEphemeris", exception.message);
}
};
if (dictionary.hasKey(KeyKernels)) {
// Due to the specification, we can be sure it is either a Dictionary or a string
if (dictionary.hasValue<std::string>(KeyKernels)) {
std::string kernel = dictionary.value<std::string>(KeyKernels);
loadKernel(kernel);
}
else {
ghoul::Dictionary kernels = dictionary.value<ghoul::Dictionary>(KeyKernels);
for (size_t i = 1; i <= kernels.size(); ++i) {
std::string kernel = kernels.value<std::string>(std::to_string(i));
loadKernel(kernel);
}
}
}
}
glm::dvec3 SpiceTranslation::position() const {
return _position;
}
void SpiceTranslation::update(const UpdateData& data) {
double lightTime = 0.0;
_position = SpiceManager::ref().targetPosition(
_target, _origin, ReferenceFrame, {}, data.time, lightTime
) * glm::pow(10.0, 3.0);
}
} // namespace openspace
@@ -0,0 +1,53 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __SPICETRANSLATION_H__
#define __SPICETRANSLATION_H__
#include <openspace/scene/translation.h>
#include <openspace/documentation/documentation.h>
#include <openspace/properties/stringproperty.h>
namespace openspace {
class SpiceTranslation : public Translation {
public:
SpiceTranslation(const ghoul::Dictionary& dictionary);
glm::dvec3 position() const;
void update(const UpdateData& data) override;
static openspace::Documentation Documentation();
private:
properties::StringProperty _target;
properties::StringProperty _origin;
glm::dvec3 _position;
bool _kernelsLoadedSuccessfully;
};
} // namespace openspace
#endif // __SPICETRANSLATION_H__
@@ -0,0 +1,92 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <modules/base/translation/statictranslation.h>
#include <openspace/documentation/verifier.h>
namespace {
const std::string KeyPosition = "Position";
}
namespace openspace {
Documentation StaticTranslation::Documentation() {
using namespace openspace::documentation;
return {
"Static Translation",
"base_transform_translation_static",
{
{
"Type",
new StringEqualVerifier("StaticTranslation"),
"",
Optional::No
},
{
KeyPosition,
new DoubleVector3Verifier,
"Specifies the position (in meters) that this scenegraph node is located "
"at relative to its parent",
Optional::No
}
},
Exhaustive::Yes
};
}
StaticTranslation::StaticTranslation()
: _position(
"position",
"Position",
glm::dvec3(0.0),
glm::dvec3(-std::numeric_limits<double>::max()),
glm::dvec3(std::numeric_limits<double>::max())
)
{
addProperty(_position);
}
StaticTranslation::StaticTranslation(const ghoul::Dictionary& dictionary)
: StaticTranslation()
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"StaticEphemeris"
);
_position = dictionary.value<glm::dvec3>(KeyPosition);
}
StaticTranslation::~StaticTranslation() {}
glm::dvec3 StaticTranslation::position() const {
return _position;
}
void StaticTranslation::update(const UpdateData&) {}
} // namespace openspace
@@ -0,0 +1,51 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __STATICTRANSLATION_H__
#define __STATICTRANSLATION_H__
#include <openspace/scene/translation.h>
#include <openspace/documentation/documentation.h>
#include <openspace/properties/vectorproperty.h>
namespace openspace {
class StaticTranslation : public Translation {
public:
StaticTranslation();
StaticTranslation(const ghoul::Dictionary& dictionary);
virtual ~StaticTranslation();
virtual glm::dvec3 position() const;
virtual void update(const UpdateData& data) override;
static openspace::Documentation Documentation();
private:
properties::DVec3Property _position;
};
} // namespace openspace
#endif // __STATICTRANSLATION_H__