mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 12:29:04 -06:00
Merge branch 'develop' of openspace.itn.liu.se:/openspace into develop
Conflicts: scripts/default_startup.lua
This commit is contained in:
@@ -718,8 +718,6 @@ protected:
|
||||
|
||||
/// The last assigned kernel-id, used to determine the next free kernel id
|
||||
KernelIdentifier _lastAssignedKernel;
|
||||
|
||||
static SpiceManager* _manager;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -76,7 +76,7 @@ ModelGeometry::ModelGeometry(const ghoul::Dictionary& dictionary)
|
||||
|
||||
success = dictionary.getValue(keySize, _magnification);
|
||||
if (!success)
|
||||
_magnification = 4; // if not set, models will be 1:1000, feel free to change @AA
|
||||
_magnification = 0; // if not set, models will be 1:1 (earlier 1:1000) @AA
|
||||
|
||||
success = dictionary.getValue(keyObjFile, _file);
|
||||
if (!success) {
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace openspace {
|
||||
bool loadObj(const std::string& filename);
|
||||
bool loadCachedFile(const std::string& filename);
|
||||
bool saveCachedFile(const std::string& filename);
|
||||
int _magnification;
|
||||
float _magnification;
|
||||
|
||||
GLuint _vaoID;
|
||||
GLuint _vbo;
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "WavefrontGeometry";
|
||||
const std::string keyObjFile = "ObjFile";
|
||||
// const int8_t CurrentCacheVersion = 3;
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -32,6 +32,7 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanetprojection.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableshadowcylinder.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometryprojection.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodelprojection.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/writeToTexture.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/decoder.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/hongkangparser.h
|
||||
@@ -53,6 +54,7 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanetprojection.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableshadowcylinder.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometryprojection.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablemodelprojection.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/decoder.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/hongkangparser.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer.cpp
|
||||
@@ -72,6 +74,10 @@ set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fov_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectiveTexture_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectiveTexture_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectionPass_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectionPass_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/modelShader_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/modelShader_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/terminatorshadow_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/terminatorshadow_vs.glsl
|
||||
)
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <modules/newhorizons/rendering/renderableplaneprojection.h>
|
||||
#include <modules/newhorizons/rendering/renderableplanetprojection.h>
|
||||
#include <modules/newhorizons/rendering/simplespheregeometryprojection.h>
|
||||
#include <modules/newhorizons/rendering/renderablemodelprojection.h>
|
||||
|
||||
#include <modules/newhorizons/util/decoder.h>
|
||||
#include <modules/newhorizons/util/instrumentdecoder.h>
|
||||
@@ -69,6 +70,7 @@ bool NewHorizonsModule::create() {
|
||||
fRenderable->registerClass<RenderableFov>("RenderableFov");
|
||||
fRenderable->registerClass<RenderablePlaneProjection>("RenderablePlaneProjection");
|
||||
fRenderable->registerClass<RenderablePlanetProjection>("RenderablePlanetProjection");
|
||||
fRenderable->registerClass<RenderableModelProjection>("RenderableModelProjection");
|
||||
|
||||
auto fPlanetGeometryProjection = FactoryManager::ref().factory<planetgeometryprojection::PlanetGeometryProjection>();
|
||||
fPlanetGeometryProjection->registerClass<planetgeometryprojection::SimpleSphereGeometryProjection>("SimpleSphereProjection");
|
||||
|
||||
531
modules/newhorizons/rendering/renderablemodelprojection.cpp
Normal file
531
modules/newhorizons/rendering/renderablemodelprojection.cpp
Normal file
@@ -0,0 +1,531 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <modules/newhorizons/rendering/renderablemodelprojection.h>
|
||||
#include <openspace/util/constants.h>
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <sgct.h>
|
||||
#include "imgui.h"
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <thread>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableModelProjection";
|
||||
const std::string keySource = "Rotation.Source";
|
||||
const std::string keyDestination = "Rotation.Destination";
|
||||
const std::string keyBody = "Body";
|
||||
const std::string keyGeometry = "Geometry";
|
||||
|
||||
const std::string keyTextureColor = "Textures.Color";
|
||||
const std::string keyTextureProject = "Textures.Project";
|
||||
const std::string keyTextureDefault = "Textures.Default";
|
||||
|
||||
const std::string keySequenceDir = "Projection.Sequence";
|
||||
const std::string keySequenceType = "Projection.SequenceType";
|
||||
const std::string keyProjObserver = "Projection.Observer";
|
||||
const std::string keyProjTarget = "Projection.Target";
|
||||
const std::string keyProjAberration = "Projection.Aberration";
|
||||
|
||||
const std::string keyInstrument = "Instrument.Name";
|
||||
const std::string keyInstrumentFovy = "Instrument.Fovy";
|
||||
const std::string keyInstrumentAspect = "Instrument.Aspect";
|
||||
const std::string keyInstrumentNear = "Instrument.Near";
|
||||
const std::string keyInstrumentFar = "Instrument.Far";
|
||||
|
||||
const std::string keyTranslation = "DataInputTranslation";
|
||||
const std::string sequenceTypeImage = "image-sequence";
|
||||
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _projectionTexturePath("projectionTexture", "RGB Texture")
|
||||
, _rotationX("rotationX", "RotationX", 0, 0, 360)
|
||||
, _rotationY("rotationY", "RotationY", 0, 0, 360)
|
||||
, _rotationZ("rotationZ", "RotationZ", 0, 0, 360)
|
||||
, _programObject(nullptr)
|
||||
, _fboProgramObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _geometry(nullptr)
|
||||
, _textureOriginal(nullptr)
|
||||
, _textureProj(nullptr)
|
||||
, _textureWhiteSquare(nullptr)
|
||||
, _alpha(1.f)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _performProjection("performProjection", "Perform Projections", true)
|
||||
, _frameCount(0)
|
||||
, _programIsDirty(false)
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(constants::scenegraphnode::keyName, name);
|
||||
ghoul_assert(success, "Name was not passed to RenderableModelProjection");
|
||||
|
||||
ghoul::Dictionary geometryDictionary;
|
||||
success = dictionary.getValue(keyGeometry, geometryDictionary);
|
||||
if (success) {
|
||||
geometryDictionary.setValue(constants::scenegraphnode::keyName, name);
|
||||
_geometry = modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary);
|
||||
}
|
||||
|
||||
std::string texturePath = "";
|
||||
success = dictionary.getValue(keyTextureColor, texturePath);
|
||||
if (success)
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
|
||||
success = dictionary.getValue(keyTextureProject, texturePath);
|
||||
if (success)
|
||||
_projectionTexturePath = absPath(texturePath);
|
||||
|
||||
success = dictionary.getValue(keyTextureDefault, texturePath);
|
||||
if (success)
|
||||
_defaultProjImage = absPath(texturePath);
|
||||
|
||||
addPropertySubOwner(_geometry);
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
addProperty(_projectionTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&RenderableModelProjection::loadTexture, this));
|
||||
_projectionTexturePath.onChange(std::bind(&RenderableModelProjection::loadProjectionTexture, this));
|
||||
|
||||
dictionary.getValue(keySource, _source);
|
||||
dictionary.getValue(keyDestination, _destination);
|
||||
dictionary.getValue(keyBody, _target);
|
||||
if (_target != "")
|
||||
setBody(_target);
|
||||
|
||||
bool completeSuccess = true;
|
||||
completeSuccess &= dictionary.getValue(keyInstrument, _instrumentID);
|
||||
completeSuccess &= dictionary.getValue(keyProjObserver, _projectorID);
|
||||
completeSuccess &= dictionary.getValue(keyProjTarget, _projecteeID);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentFovy, _fovy);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentAspect, _aspectRatio);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentNear, _nearPlane);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentFar, _farPlane);
|
||||
ghoul_assert(completeSuccess, "All neccessary attributes not found in modfile");
|
||||
|
||||
completeSuccess = dictionary.getValue(keyProjAberration, _aberration);
|
||||
if (!completeSuccess)
|
||||
_aberration = "NONE";
|
||||
|
||||
openspace::SpiceManager::ref().addFrame(_target, _source);
|
||||
setBoundingSphere(pss(1.f, 9.f));
|
||||
|
||||
addProperty(_performShading);
|
||||
addProperty(_performProjection);
|
||||
addProperty(_rotationX);
|
||||
addProperty(_rotationY);
|
||||
addProperty(_rotationZ);
|
||||
|
||||
SequenceParser* parser;
|
||||
|
||||
bool foundSequence = dictionary.getValue(keySequenceDir, _sequenceSource);
|
||||
if (foundSequence) {
|
||||
_sequenceSource = absPath(_sequenceSource);
|
||||
|
||||
foundSequence = dictionary.getValue(keySequenceType, _sequenceType);
|
||||
//Important: client must define translation-list in mod file IFF playbook
|
||||
if (dictionary.hasKey(keyTranslation)) {
|
||||
ghoul::Dictionary translationDictionary;
|
||||
//get translation dictionary
|
||||
dictionary.getValue(keyTranslation, translationDictionary);
|
||||
if (_sequenceType == sequenceTypeImage) {
|
||||
parser = new LabelParser(_sequenceSource, translationDictionary);
|
||||
openspace::ImageSequencer2::ref().runSequenceParser(parser);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
LWARNING("No translation provided, please make sure all spice calls match playbook!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool RenderableModelProjection::isReady() const {
|
||||
bool ready = true;
|
||||
ready &= (_programObject != nullptr);
|
||||
ready &= (_texture != nullptr);
|
||||
return ready;
|
||||
}
|
||||
|
||||
bool RenderableModelProjection::initialize() {
|
||||
bool completeSuccess = true;
|
||||
|
||||
if (_programObject == nullptr) {
|
||||
_programObject = ghoul::opengl::ProgramObject::Build("ModelShader",
|
||||
"${MODULES}/newhorizons/shaders/modelShader_vs.glsl",
|
||||
"${MODULES}/newhorizons/shaders/modelShader_fs.glsl");
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
_programObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*) { this->_programIsDirty = true; } );
|
||||
|
||||
if (_fboProgramObject == nullptr) {
|
||||
_fboProgramObject = ghoul::opengl::ProgramObject::Build("ProjectionPass",
|
||||
"${MODULES}/newhorizons/shaders/projectionPass_vs.glsl",
|
||||
"${MODULES}/newhorizons/shaders/projectionPass_fs.glsl");
|
||||
if (!_fboProgramObject)
|
||||
return false;
|
||||
}
|
||||
_fboProgramObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*) { this->_programIsDirty = true; } );
|
||||
|
||||
loadTexture();
|
||||
loadProjectionTexture();
|
||||
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
completeSuccess &= (_textureOriginal != nullptr);
|
||||
completeSuccess &= (_textureProj != nullptr);
|
||||
completeSuccess &= (_textureWhiteSquare != nullptr);
|
||||
|
||||
completeSuccess &= _geometry->initialize(this);
|
||||
completeSuccess &= !_source.empty();
|
||||
completeSuccess &= !_destination.empty();
|
||||
|
||||
|
||||
bool gotverts = _geometry->getVertices(&_geometryVertecies) && _geometry->getIndices(&_geometryIndeces);
|
||||
if (!gotverts)
|
||||
LWARNING("Lack of vertex data from geometry for image projection");
|
||||
|
||||
completeSuccess &= auxiliaryRendertarget();
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderableModelProjection::auxiliaryRendertarget() {
|
||||
bool completeSuccess = true;
|
||||
// set FBO to texture to project to
|
||||
glGenFramebuffers(1, &_fboID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *_texture, 0);
|
||||
// check FBO status
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
completeSuccess &= false;
|
||||
// switch back to window-system-provided framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
int vertexSize = sizeof(modelgeometry::ModelGeometry::Vertex);
|
||||
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
glGenBuffers(1, &_vbo);
|
||||
glGenBuffers(1, &_ibo);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, _geometryVertecies.size() * vertexSize, &_geometryVertecies[0], GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, vertexSize,
|
||||
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, location)));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, vertexSize,
|
||||
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, tex)));
|
||||
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, vertexSize,
|
||||
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, normal)));
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _geometryIndeces.size() * sizeof(int), &_geometryIndeces[0], GL_STATIC_DRAW);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderableModelProjection::deinitialize() {
|
||||
if (_geometry) {
|
||||
_geometry->deinitialize();
|
||||
delete _geometry;
|
||||
}
|
||||
|
||||
if (_texture)
|
||||
delete _texture;
|
||||
if (_textureProj)
|
||||
delete _textureProj;
|
||||
if (_textureOriginal)
|
||||
delete _textureOriginal;
|
||||
if (_textureWhiteSquare)
|
||||
delete _textureWhiteSquare;
|
||||
|
||||
_geometry = nullptr;
|
||||
_texture = nullptr;
|
||||
_textureProj = nullptr;
|
||||
_textureOriginal = nullptr;
|
||||
_textureWhiteSquare = nullptr;
|
||||
|
||||
glDeleteBuffers(1, &_vbo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableModelProjection::render(const RenderData& data) {
|
||||
if (!_programObject) return;
|
||||
if (!_textureProj) return;
|
||||
_programObject->activate();
|
||||
_frameCount++;
|
||||
|
||||
_camScaling = data.camera.scaling();
|
||||
_up = data.camera.lookUpVector();
|
||||
|
||||
if (_capture && _performProjection)
|
||||
project();
|
||||
|
||||
attitudeParameters(_time);
|
||||
_imageTimes.clear();
|
||||
|
||||
double time = openspace::Time::ref().currentTime();
|
||||
bool targetPositionCoverage = openspace::SpiceManager::ref().hasSpkCoverage(_target, time);
|
||||
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;
|
||||
|
||||
_programObject->setUniform("ProjectorMatrix", _projectorMatrix);
|
||||
_programObject->setUniform("boresight", _boresight);
|
||||
_programObject->setUniform("_performShading", _performShading);
|
||||
_programObject->setUniform("sun_pos", _sunPosition.vec3());
|
||||
_viewProjection = data.camera.viewProjectionMatrix();
|
||||
_programObject->setUniform("ViewProjection", _viewProjection);
|
||||
_programObject->setUniform("ModelTransform", _transform);
|
||||
setPscUniforms(_programObject, &data.camera, data.position);
|
||||
|
||||
textureBind();
|
||||
_geometry->render();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void RenderableModelProjection::update(const UpdateData& data) {
|
||||
if (_programIsDirty) {
|
||||
_programObject->rebuildFromFile();
|
||||
_fboProgramObject->rebuildFromFile();
|
||||
_programIsDirty = false;
|
||||
}
|
||||
|
||||
_time = data.time;
|
||||
|
||||
if (openspace::ImageSequencer2::ref().isReady() && _performProjection) {
|
||||
openspace::ImageSequencer2::ref().updateSequencer(_time);
|
||||
_capture = openspace::ImageSequencer2::ref().getImagePaths(_imageTimes, _projecteeID, _instrumentID);
|
||||
}
|
||||
|
||||
// set spice-orientation in accordance to timestamp
|
||||
if (!_source.empty())
|
||||
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, _time, _stateMatrix);
|
||||
|
||||
double lt;
|
||||
openspace::SpiceManager::ref().getTargetPosition("SUN", _target, "GALACTIC", "NONE", _time, _sunPosition, lt);
|
||||
}
|
||||
|
||||
void RenderableModelProjection::imageProjectGPU() {
|
||||
|
||||
// keep handle to the current bound FBO
|
||||
GLint defaultFBO;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
|
||||
|
||||
GLint m_viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, m_viewport);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
// set blend eq
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ZERO);
|
||||
|
||||
glViewport(0, 0, static_cast<GLsizei>(_texture->width()), static_cast<GLsizei>(_texture->height()));
|
||||
_fboProgramObject->activate();
|
||||
|
||||
ghoul::opengl::TextureUnit unitFboProject;
|
||||
unitFboProject.activate();
|
||||
_textureProj->bind();
|
||||
_fboProgramObject->setUniform("projectTexture", unitFboProject);
|
||||
|
||||
ghoul::opengl::TextureUnit unitFboCurrent;
|
||||
unitFboCurrent.activate();
|
||||
_texture->bind();
|
||||
_fboProgramObject->setUniform("currentTexture", unitFboCurrent);
|
||||
_fboProgramObject->setUniform("ProjectorMatrix", _projectorMatrix);
|
||||
_fboProgramObject->setUniform("ModelTransform", _transform);
|
||||
_fboProgramObject->setUniform("_scaling", _camScaling);
|
||||
_fboProgramObject->setUniform("boresight", _boresight);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
|
||||
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(_geometryIndeces.size()), GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
_fboProgramObject->deactivate();
|
||||
glDisable(GL_BLEND);
|
||||
//bind back to default
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
glViewport(m_viewport[0], m_viewport[1],
|
||||
m_viewport[2], m_viewport[3]);
|
||||
|
||||
}
|
||||
|
||||
void RenderableModelProjection::attitudeParameters(double time) {
|
||||
openspace::SpiceManager::ref().getPositionTransformMatrix(_source, _destination, time, _stateMatrix);
|
||||
openspace::SpiceManager::ref().getPositionTransformMatrix(_instrumentID, _destination, time, _instrumentMatrix);
|
||||
|
||||
_transform = glm::mat4(1);
|
||||
|
||||
glm::mat4 rotPropX = glm::rotate(_transform, static_cast<float>(_rotationX), glm::vec3(1, 0, 0));
|
||||
glm::mat4 rotPropY = glm::rotate(_transform, static_cast<float>(_rotationY), glm::vec3(0, 1, 0));
|
||||
glm::mat4 rotPropZ = glm::rotate(_transform, static_cast<float>(_rotationZ), glm::vec3(0, 0, 1));
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
_transform[i][j] = static_cast<float>(_stateMatrix[i][j]);
|
||||
}
|
||||
}
|
||||
_transform = _transform * rotPropX * rotPropY * rotPropZ;
|
||||
|
||||
std::string shape, instrument;
|
||||
std::vector<glm::dvec3> bounds;
|
||||
glm::dvec3 boresight;
|
||||
bool found = openspace::SpiceManager::ref().getFieldOfView(_instrumentID, shape, instrument, boresight, bounds);
|
||||
if (!found)
|
||||
return;
|
||||
|
||||
double lightTime;
|
||||
psc position; //observer target
|
||||
found = SpiceManager::ref().getTargetPosition(_projectorID, _projecteeID, _destination, _aberration, time, position, lightTime);
|
||||
|
||||
position[3] += (3 + _camScaling[1]);
|
||||
glm::vec3 cpos = position.vec3();
|
||||
|
||||
_projectorMatrix = computeProjectorMatrix(cpos, boresight, _up);
|
||||
}
|
||||
|
||||
glm::mat4 RenderableModelProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up) {
|
||||
//rotate boresight into correct alignment
|
||||
_boresight = _instrumentMatrix*aim;
|
||||
glm::vec3 uptmp(_instrumentMatrix*glm::dvec3(up));
|
||||
|
||||
// create view matrix
|
||||
glm::vec3 e3 = glm::normalize(_boresight);
|
||||
glm::vec3 e1 = glm::normalize(glm::cross(uptmp, e3));
|
||||
glm::vec3 e2 = glm::normalize(glm::cross(e3, e1));
|
||||
glm::mat4 projViewMatrix = glm::mat4(e1.x, e2.x, e3.x, 0.f,
|
||||
e1.y, e2.y, e3.y, 0.f,
|
||||
e1.z, e2.z, e3.z, 0.f,
|
||||
-glm::dot(e1, loc), -glm::dot(e2, loc), -glm::dot(e3, loc), 1.f);
|
||||
|
||||
// create perspective projection matrix
|
||||
glm::mat4 projProjectionMatrix = glm::perspective(_fovy, _aspectRatio, _nearPlane, _farPlane);
|
||||
// bias matrix
|
||||
glm::mat4 projNormalizationMatrix = glm::mat4(0.5f, 0, 0, 0,
|
||||
0, 0.5f, 0, 0,
|
||||
0, 0, 0.5f, 0,
|
||||
0.5f, 0.5f, 0.5f, 1);
|
||||
return projNormalizationMatrix*projProjectionMatrix*projViewMatrix;
|
||||
}
|
||||
|
||||
|
||||
void RenderableModelProjection::textureBind() {
|
||||
ghoul::opengl::TextureUnit unit[2];
|
||||
unit[0].activate();
|
||||
_texture->bind();
|
||||
_programObject->setUniform("currentTexture", unit[0]);
|
||||
unit[1].activate();
|
||||
_textureWhiteSquare->bind();
|
||||
_programObject->setUniform("projectedTexture", unit[1]);
|
||||
}
|
||||
|
||||
void RenderableModelProjection::project() {
|
||||
for (auto img : _imageTimes) {
|
||||
std::thread t1(&RenderableModelProjection::attitudeParameters, this, img.startTime);
|
||||
t1.join();
|
||||
_projectionTexturePath = img.path;
|
||||
imageProjectGPU(); //fbopass
|
||||
}
|
||||
_capture = false;
|
||||
}
|
||||
|
||||
void RenderableModelProjection::loadTexture() {
|
||||
delete _texture;
|
||||
_texture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_texture->uploadTexture();
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
delete _textureOriginal;
|
||||
_textureOriginal = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath));
|
||||
if (_textureOriginal) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_textureOriginal->uploadTexture();
|
||||
_textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
delete _textureWhiteSquare;
|
||||
_textureWhiteSquare = nullptr;
|
||||
if (_defaultProjImage != "") {
|
||||
_textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(absPath(_defaultProjImage));
|
||||
if (_textureWhiteSquare) {
|
||||
_textureWhiteSquare->uploadTexture();
|
||||
_textureWhiteSquare->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableModelProjection::loadProjectionTexture() {
|
||||
delete _textureProj;
|
||||
_textureProj = nullptr;
|
||||
if (_projectionTexturePath.value() != "") {
|
||||
_textureProj = ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath));
|
||||
if (_textureProj) {
|
||||
_textureProj->uploadTexture();
|
||||
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
_textureProj->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
147
modules/newhorizons/rendering/renderablemodelprojection.h
Normal file
147
modules/newhorizons/rendering/renderablemodelprojection.h
Normal file
@@ -0,0 +1,147 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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 __RENDERABLEMODELPROJECTION_H__
|
||||
#define __RENDERABLEMODELPROJECTION_H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <modules/newhorizons/util/imagesequencer2.h>
|
||||
#include <modules/newhorizons/util/labelparser.h>
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <modules/base/rendering/modelgeometry.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace modelgeometry {
|
||||
class ModelGeometry;
|
||||
}
|
||||
|
||||
class RenderableModelProjection : public Renderable {
|
||||
public:
|
||||
RenderableModelProjection(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;
|
||||
|
||||
|
||||
protected:
|
||||
void loadTexture();
|
||||
void loadProjectionTexture();
|
||||
|
||||
private:
|
||||
bool auxiliaryRendertarget();
|
||||
glm::mat4 computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up);
|
||||
void attitudeParameters(double time);
|
||||
void imageProjectGPU();
|
||||
|
||||
void textureBind();
|
||||
void project();
|
||||
|
||||
properties::StringProperty _colorTexturePath;
|
||||
properties::BoolProperty _performProjection;
|
||||
|
||||
properties::IntProperty _rotationX;
|
||||
properties::IntProperty _rotationY;
|
||||
properties::IntProperty _rotationZ;
|
||||
|
||||
ghoul::opengl::ProgramObject* _programObject;
|
||||
ghoul::opengl::ProgramObject* _fboProgramObject;
|
||||
|
||||
ghoul::opengl::Texture* _texture;
|
||||
ghoul::opengl::Texture* _textureOriginal;
|
||||
ghoul::opengl::Texture* _textureProj;
|
||||
ghoul::opengl::Texture* _textureWhiteSquare;
|
||||
|
||||
modelgeometry::ModelGeometry* _geometry;
|
||||
|
||||
float _alpha;
|
||||
glm::dmat3 _stateMatrix;
|
||||
glm::dmat3 _instrumentMatrix;
|
||||
|
||||
properties::StringProperty _projectionTexturePath;
|
||||
std::string _defaultProjImage;
|
||||
std::string _source;
|
||||
std::string _destination;
|
||||
std::string _target;
|
||||
|
||||
// sequence loading
|
||||
std::string _sequenceSource;
|
||||
std::string _sequenceType;
|
||||
|
||||
// projection mod info
|
||||
std::string _instrumentID;
|
||||
std::string _projectorID;
|
||||
std::string _projecteeID;
|
||||
std::string _aberration;
|
||||
std::vector<std::string> _potentialTargets;
|
||||
float _fovy;
|
||||
float _aspectRatio;
|
||||
float _nearPlane;
|
||||
float _farPlane;
|
||||
|
||||
// uniforms
|
||||
glm::vec2 _camScaling;
|
||||
glm::vec3 _up;
|
||||
glm::mat4 _transform;
|
||||
glm::mat4 _viewProjection;
|
||||
glm::mat4 _projectorMatrix;
|
||||
glm::vec3 _boresight;
|
||||
|
||||
// FBO stuff
|
||||
GLuint _fboID;
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
|
||||
GLuint _vbo;
|
||||
GLuint _ibo;
|
||||
GLuint _vaoID;
|
||||
std::vector<modelgeometry::ModelGeometry::Vertex> _geometryVertecies;
|
||||
std::vector<int> _geometryIndeces;
|
||||
|
||||
std::vector<Image> _imageTimes;
|
||||
int _frameCount;
|
||||
double _time;
|
||||
|
||||
bool _capture;
|
||||
|
||||
psc _sunPosition;
|
||||
|
||||
properties::BoolProperty _performShading;
|
||||
bool _programIsDirty;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __RENDERABLEMODELPROJECTION_H__
|
||||
96
modules/newhorizons/shaders/modelShader_fs.glsl
Normal file
96
modules/newhorizons/shaders/modelShader_fs.glsl
Normal file
@@ -0,0 +1,96 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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__
|
||||
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
uniform vec3 camdir;
|
||||
|
||||
uniform float time;
|
||||
uniform sampler2D currentTexture;
|
||||
uniform sampler2D projectedTexture;
|
||||
uniform bool _performShading;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
|
||||
in vec4 ProjTexCoord;
|
||||
uniform vec3 boresight;
|
||||
uniform vec3 sun_pos;
|
||||
|
||||
#include "ABuffer/abufferStruct.hglsl"
|
||||
#include "ABuffer/abufferAddToBuffer.hglsl"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
//#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
void main()
|
||||
{
|
||||
vec4 position = vs_position;
|
||||
float depth = pscDepth(position);
|
||||
vec4 diffuse = texture(currentTexture, vs_st);
|
||||
|
||||
// directional lighting
|
||||
vec3 origin = vec3(0.0);
|
||||
vec4 spec = vec4(0.0);
|
||||
|
||||
vec3 n = normalize(vs_normal.xyz);
|
||||
vec3 e = normalize(camdir);
|
||||
vec3 l_pos = sun_pos;
|
||||
vec3 l_dir = normalize(l_pos-objpos.xyz);
|
||||
float intensity = 1;
|
||||
|
||||
if (_performShading) {
|
||||
float terminatorBright = 0.4;
|
||||
intensity = min(max(5*dot(n,l_dir), terminatorBright), 1);
|
||||
}
|
||||
|
||||
float shine = 0.0001;
|
||||
vec4 specular = vec4(0.1);
|
||||
vec4 ambient = vec4(0.f,0.f,0.f,1);
|
||||
//Specular
|
||||
if (intensity > 0.f) {
|
||||
vec3 h = normalize(l_dir + e);
|
||||
float intSpec = max(dot(h,n),0.0);
|
||||
spec = specular * pow(intSpec, shine);
|
||||
}
|
||||
|
||||
vec4 projTexColor = textureProj(projectedTexture, ProjTexCoord);
|
||||
vec4 shaded = max(intensity * diffuse, ambient);
|
||||
if (ProjTexCoord[0] > 0.0 || ProjTexCoord[1] > 0.0 ||
|
||||
ProjTexCoord[0] < ProjTexCoord[2] ||
|
||||
ProjTexCoord[1] < ProjTexCoord[2]) {
|
||||
diffuse = shaded;
|
||||
} else if (dot(n, boresight) < 0 && projTexColor.w != 0) {// frontfacing
|
||||
diffuse = projTexColor;
|
||||
} else {
|
||||
diffuse = shaded;
|
||||
}
|
||||
|
||||
ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth);
|
||||
addToBuffer(frag);
|
||||
|
||||
}
|
||||
|
||||
60
modules/newhorizons/shaders/modelShader_vs.glsl
Normal file
60
modules/newhorizons/shaders/modelShader_vs.glsl
Normal file
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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__
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform mat4 ProjectorMatrix;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
layout(location = 2) in vec3 in_normal;
|
||||
|
||||
uniform vec3 boresight;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_position;
|
||||
out float s;
|
||||
|
||||
|
||||
out vec4 ProjTexCoord;
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
void main(){
|
||||
|
||||
vs_st = in_st;
|
||||
vs_position = in_position;
|
||||
vec4 tmp = in_position;
|
||||
//tmp[3] += _magnification for runtime alteration of model size @AA
|
||||
|
||||
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_position = tmp;
|
||||
|
||||
vec4 raw_pos = psc_to_meter(in_position, scaling);
|
||||
ProjTexCoord = ProjectorMatrix * ModelTransform * raw_pos;
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
}
|
||||
67
modules/newhorizons/shaders/projectionPass_fs.glsl
Normal file
67
modules/newhorizons/shaders/projectionPass_fs.glsl
Normal file
@@ -0,0 +1,67 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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__
|
||||
uniform sampler2D projectTexture;
|
||||
uniform sampler2D currentTexture;
|
||||
|
||||
uniform mat4 ProjectorMatrix;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec2 _scaling;
|
||||
uniform vec3 boresight;
|
||||
|
||||
|
||||
in vec4 vs_position;
|
||||
in vec4 ProjTexCoord;
|
||||
in vec2 vs_uv;
|
||||
in vec4 vs_normal;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
bool inRange(float x, float a, float b) {
|
||||
return (x >= a && x <= b);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 uv = vec2(0.5,0.5)*vs_uv+vec2(0.5,0.5);
|
||||
|
||||
vec3 n = normalize(vs_normal.xyz);
|
||||
vec4 projected = ProjTexCoord;
|
||||
|
||||
//normalize
|
||||
projected.x /= projected.w;
|
||||
projected.y /= projected.w;
|
||||
//invert gl coordinates
|
||||
projected.x = 1 - projected.x;
|
||||
projected.y = 1 - projected.y;
|
||||
|
||||
if((inRange(projected.x, 0, 1) && inRange(projected.y, 0, 1)) && (dot(n, boresight) < 0)) {
|
||||
color = texture(projectTexture, projected.xy);
|
||||
} else {
|
||||
color = texture(currentTexture, uv);
|
||||
}
|
||||
|
||||
}
|
||||
60
modules/newhorizons/shaders/projectionPass_vs.glsl
Normal file
60
modules/newhorizons/shaders/projectionPass_vs.glsl
Normal file
@@ -0,0 +1,60 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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__
|
||||
uniform mat4 ProjectorMatrix;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec2 _scaling;
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
layout(location = 2) in vec3 in_normal;
|
||||
|
||||
uniform vec3 boresight;
|
||||
|
||||
out vec4 vs_position;
|
||||
out vec4 ProjTexCoord;
|
||||
out vec2 vs_uv;
|
||||
out vec4 vs_normal;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main() {
|
||||
vs_position = in_position;
|
||||
|
||||
vec4 tmp = in_position;
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_position = tmp;
|
||||
|
||||
vec4 raw_pos = psc_to_meter(in_position, _scaling);
|
||||
ProjTexCoord = ProjectorMatrix * ModelTransform * raw_pos;
|
||||
|
||||
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
|
||||
|
||||
//match clipping plane
|
||||
vec2 texco = (in_st * 2) - 1;
|
||||
vs_uv = texco;
|
||||
gl_Position = vec4(texco, 0.0, 1.0);
|
||||
|
||||
}
|
||||
@@ -47,8 +47,7 @@ namespace openspace {
|
||||
ImageSequencer2* ImageSequencer2::_instance = nullptr;
|
||||
|
||||
ImageSequencer2::ImageSequencer2()
|
||||
: _latestImage()
|
||||
, _hasData(false)
|
||||
: _hasData(false)
|
||||
{}
|
||||
|
||||
ImageSequencer2& ImageSequencer2::ref() {
|
||||
@@ -162,8 +161,13 @@ double ImageSequencer2::getNextCaptureTime(){
|
||||
return nextCaptureTime;
|
||||
}
|
||||
const Image ImageSequencer2::getLatestImageForInstrument(const std::string _instrumentID){
|
||||
|
||||
return _latestImage;
|
||||
auto it = _latestImages.find(_instrumentID);
|
||||
if (it != _latestImages.end())
|
||||
return _latestImages[_instrumentID];
|
||||
else {
|
||||
Image dummyImage = { 0, 0, "", std::vector<std::string>(), "", false };
|
||||
return dummyImage;
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, bool> ImageSequencer2::getActiveInstruments(){
|
||||
@@ -265,7 +269,7 @@ bool ImageSequencer2::getImagePaths(std::vector<Image>& captures,
|
||||
std::reverse(captureTimes.begin(), captureTimes.end());
|
||||
captures = captureTimes;
|
||||
if (!captures.empty())
|
||||
_latestImage = captures.back();
|
||||
_latestImages[captures.back().activeInstruments.front()] = captures.back();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ private:
|
||||
// default capture image
|
||||
std::string _defaultCaptureImage;
|
||||
|
||||
Image _latestImage;
|
||||
std::map<std::string, Image> _latestImages;
|
||||
// if no data, no run
|
||||
bool _hasData;
|
||||
};
|
||||
|
||||
@@ -55,5 +55,5 @@ return {
|
||||
File = "${BASE_PATH}/Properties.txt"
|
||||
},
|
||||
DownloadRequestURL = "http://openspace.itn.liu.se/request.cgi",
|
||||
RenderingMethod = "ABufferFrameBuffer"
|
||||
-- RenderingMethod = "ABufferFrameBuffer"
|
||||
}
|
||||
@@ -22,7 +22,23 @@ openspace.bindKey("5", "openspace.time.setDeltaTime(60)")
|
||||
openspace.bindKey("6", "openspace.time.setDeltaTime(120)")
|
||||
openspace.bindKey("7", "openspace.time.setDeltaTime(360)")
|
||||
openspace.bindKey("8", "openspace.time.setDeltaTime(540)")
|
||||
openspace.bindKey("9", "openspace.time.setDeltaTime(720)")
|
||||
openspace.bindKey("9", "openspace.time.setDeltaTime(720)")
|
||||
|
||||
--[[openspace.bindKey("2", "openspace.time.setDeltaTime(30)")
|
||||
openspace.bindKey("3", "openspace.time.setDeltaTime(180)") -- 3m
|
||||
openspace.bindKey("4", "openspace.time.setDeltaTime(900)") -- 15m
|
||||
openspace.bindKey("5", "openspace.time.setDeltaTime(3600)") -- 1h
|
||||
openspace.bindKey("6", "openspace.time.setDeltaTime(14400)") -- 3h
|
||||
openspace.bindKey("7", "openspace.time.setDeltaTime(43200)") -- 12h
|
||||
openspace.bindKey("8", "openspace.time.setDeltaTime(86400)") -- 1d
|
||||
openspace.bindKey("9", "openspace.time.setDeltaTime(172800)") -- 2d
|
||||
|
||||
openspace.bindKey("v", "openspace.time.setTime('2014 AUG 22 03:45:00'); openspace.time.setDeltaTime(1);")
|
||||
openspace.bindKey("b", "openspace.time.setTime('2014 SEP 02 11:30:30'); openspace.time.setDeltaTime(1);")
|
||||
openspace.bindKey("n", "openspace.time.setTime('2014 SEP 14 17:55:00'); openspace.time.setDeltaTime(1);")
|
||||
|
||||
openspace.bindKey("i", "local b = openspace.getPropertyValue('ImagePlaneRosetta.renderable.enabled'); openspace.setPropertyValue('ImagePlaneRosetta.renderable.enabled', not b)")
|
||||
--]]
|
||||
|
||||
openspace.bindKey("F8", "openspace.time.setTime('2015-07-14T09:00:00.00'); openspace.setPropertyValue('PlutoProjection.renderable.clearAllProjections', true); openspace.setPropertyValue('Charon.renderable.clearAllProjections', true);")
|
||||
|
||||
|
||||
@@ -14,5 +14,6 @@ openspace.setPropertyValue("MilkyWay.renderable.transparency", 0.75)
|
||||
openspace.setPropertyValue("MilkyWay.renderable.segments", 50)
|
||||
|
||||
openspace.changeCoordinateSystem("Jupiter")
|
||||
--openspace.changeCoordinateSystem("67P")
|
||||
|
||||
openspace.printInfo("Done setting default values")
|
||||
|
||||
@@ -5,22 +5,23 @@
|
||||
openspace.setInvertRoll(true);
|
||||
--openspace.setInteractionSensitivity(10) -- This is the default value for the sensitivity (the higher, the more sensitive)
|
||||
|
||||
--openspace.time.setTime("2007 FEB 27 16:30:00") -- This is the start time for a Jupiter run of New Horizons
|
||||
openspace.time.setTime("2007 FEB 27 16:30:00") -- This is the start time for a Jupiter run of New Horizons
|
||||
|
||||
--openspace.time.setTime("2011 AUG 06 00:00:00") -- Dawn takes pictures of Vesta
|
||||
--openspace.time.setTime("2011 JUL 28 12:00:00") -- Rosetta starts dancing around 67p
|
||||
--openspace.time.setTime("2007 FEB 28 11:45:00") -- europa rise
|
||||
--TESTING ALICE
|
||||
--openspace.time.setTime("2015-07-13T00:00:00.00")
|
||||
|
||||
openspace.time.setTime("2015-07-14T10:00:00.00")
|
||||
--openspace.time.setTime("2015-07-14T08:00:00.00")
|
||||
|
||||
openspace.time.setDeltaTime(0) -- How many seconds pass per second of realtime, changeable in the GUI
|
||||
|
||||
dofile(openspace.absPath('${SCRIPTS}/bind_keys.lua')) -- Load the default keybindings
|
||||
|
||||
openspace.fadeIn(1)
|
||||
|
||||
-- openspace.time.setDeltaTime(50);
|
||||
|
||||
--openspace.time.setTime("2015-07-14T12:30:00.00") -- PLUTO
|
||||
--openspace.time.setTime("2015-07-14T12:00:00.00") -- PLUTO
|
||||
-- NH takes series of images from visible to dark side (across terminator)
|
||||
-- Sequence lasts ~10 mins, (recommended dt = 10)
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ RenderEngine::RenderEngine()
|
||||
, _takeScreenshot(false)
|
||||
, _doPerformanceMeasurements(false)
|
||||
, _performanceMemory(nullptr)
|
||||
, _globalBlackOutFactor(0.f)
|
||||
, _globalBlackOutFactor(1.f)
|
||||
, _fadeDuration(2.f)
|
||||
, _currentFadeTime(0.f)
|
||||
, _fadeDirection(0)
|
||||
@@ -927,9 +927,9 @@ void RenderEngine::changeViewPoint(std::string origin) {
|
||||
if (origin == "Pluto") {
|
||||
if (newHorizonsPathNodeP) {
|
||||
Renderable* R = newHorizonsPathNodeP->renderable();
|
||||
newHorizonsPathNodeP->setParent(plutoBarycenterNode);
|
||||
nhPath = static_cast<RenderablePath*>(R);
|
||||
nhPath->calculatePath("PLUTO BARYCENTER");
|
||||
newHorizonsPathNodeP->setParent(plutoBarycenterNode);
|
||||
}
|
||||
|
||||
plutoBarycenterNode->setParent(scene()->sceneGraphNode("SolarSystem"));
|
||||
@@ -1092,9 +1092,9 @@ void RenderEngine::changeViewPoint(std::string origin) {
|
||||
if (origin == "Jupiter") {
|
||||
if (newHorizonsPathNodeJ) {
|
||||
Renderable* R = newHorizonsPathNodeJ->renderable();
|
||||
newHorizonsPathNodeJ->setParent(jupiterBarycenterNode);
|
||||
nhPath = static_cast<RenderablePath*>(R);
|
||||
nhPath->calculatePath("JUPITER BARYCENTER");
|
||||
newHorizonsPathNodeJ->setParent(jupiterBarycenterNode);
|
||||
}
|
||||
|
||||
jupiterBarycenterNode->setParent(scene()->sceneGraphNode("SolarSystem"));
|
||||
@@ -1244,6 +1244,41 @@ void RenderEngine::changeViewPoint(std::string origin) {
|
||||
// return;
|
||||
//}
|
||||
|
||||
//if (origin == "67P") {
|
||||
// SceneGraphNode* rosettaNode = scene()->sceneGraphNode("Rosetta");
|
||||
// SceneGraphNode* cgNode = scene()->sceneGraphNode("67P");
|
||||
// //jupiterBarycenterNode->setParent(solarSystemBarycenterNode);
|
||||
// //plutoBarycenterNode->setParent(solarSystemBarycenterNode);
|
||||
// solarSystemBarycenterNode->setParent(cgNode);
|
||||
// rosettaNode->setParent(cgNode);
|
||||
//
|
||||
// ghoul::Dictionary solarDictionary =
|
||||
// {
|
||||
// { std::string("Type"), std::string("Spice") },
|
||||
// { std::string("Body"), std::string("SUN") },
|
||||
// { std::string("Reference"), std::string("GALACTIC") },
|
||||
// { std::string("Observer"), std::string("CHURYUMOV-GERASIMENKO") },
|
||||
// { std::string("Kernels"), ghoul::Dictionary() }
|
||||
// };
|
||||
// solarSystemBarycenterNode->setEphemeris(new SpiceEphemeris(solarDictionary));
|
||||
//
|
||||
// ghoul::Dictionary rosettaDictionary =
|
||||
// {
|
||||
// { std::string("Type"), std::string("Spice") },
|
||||
// { std::string("Body"), std::string("ROSETTA") },
|
||||
// { std::string("Reference"), std::string("GALACTIC") },
|
||||
// { std::string("Observer"), std::string("CHURYUMOV-GERASIMENKO") },
|
||||
// { std::string("Kernels"), ghoul::Dictionary() }
|
||||
// };
|
||||
//
|
||||
// cgNode->setParent(scene()->sceneGraphNode("SolarSystem"));
|
||||
// rosettaNode->setEphemeris(new SpiceEphemeris(rosettaDictionary));
|
||||
// cgNode->setEphemeris(new StaticEphemeris);
|
||||
//
|
||||
// return;
|
||||
//
|
||||
//}
|
||||
|
||||
ghoul_assert(false, "This function is being misused");
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ namespace {
|
||||
|
||||
namespace openspace {
|
||||
|
||||
SpiceManager* SpiceManager::_manager = nullptr;
|
||||
|
||||
SpiceManager::SpiceManager()
|
||||
: _lastAssignedKernel(0)
|
||||
{
|
||||
@@ -52,7 +50,7 @@ SpiceManager::SpiceManager()
|
||||
}
|
||||
|
||||
SpiceManager::~SpiceManager() {
|
||||
for (const KernelInformation& i : _manager->_loadedKernels)
|
||||
for (const KernelInformation& i : _loadedKernels)
|
||||
unload_c(i.path.c_str());
|
||||
|
||||
// Set values back to default
|
||||
|
||||
Reference in New Issue
Block a user