Further cleanup of projection code

This commit is contained in:
Alexander Bock
2016-06-03 17:35:15 +02:00
parent 89d5e69da4
commit 4ef03bb02b
7 changed files with 167 additions and 221 deletions

View File

@@ -1,47 +1,42 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
* *
* 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. *
****************************************************************************************/
// open space includes
#include <modules/newhorizons/rendering/renderablemodelprojection.h>
#include <modules/newhorizons/util/imagesequencer.h>
#include <modules/newhorizons/util/labelparser.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/time.h>
#include <ghoul/filesystem/filesystem.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/scene/scenegraphnode.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <ghoul/systemcapabilities/openglcapabilitiescomponent.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <thread>
namespace {
const std::string _loggerCat = "RenderableModelProjection";
const std::string keySource = "Rotation.Source";
@@ -67,7 +62,6 @@ namespace {
const std::string keyTranslation = "DataInputTranslation";
const std::string sequenceTypeImage = "image-sequence";
}
namespace openspace {
@@ -90,7 +84,6 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di
, _clearAllProjections("clearAllProjections", "Clear Projections", false)
, _frameCount(0)
, _programIsDirty(false)
, _clearingImage(absPath("${OPENSPACE_DATA}/scene/common/textures/clear.png"))
{
std::string name;
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
@@ -100,7 +93,7 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di
success = dictionary.getValue(keyGeometry, geometryDictionary);
if (success) {
geometryDictionary.setValue(SceneGraphNode::KeyName, name);
_geometry = modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary);
_geometry = std::unique_ptr<modelgeometry::ModelGeometry>(modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary));
}
std::string texturePath = "";
@@ -112,7 +105,7 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di
if (success)
_defaultProjImage = absPath(texturePath);
addPropertySubOwner(_geometry);
addPropertySubOwner(_geometry.get());
addProperty(_projectionFading);
@@ -271,15 +264,12 @@ bool RenderableModelProjection::auxiliaryRendertarget() {
glBindVertexArray(0);
return completeSuccess;
}
bool RenderableModelProjection::deinitialize() {
if (_geometry) {
if (_geometry)
_geometry->deinitialize();
delete _geometry;
}
_geometry = nullptr;
_baseTexture = nullptr;

View File

@@ -1,149 +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. *
****************************************************************************************/
* *
* 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 __RENDERABLEMODELPROJECTION_H__
#define __RENDERABLEMODELPROJECTION_H__
#include <openspace/rendering/renderable.h>
#include <modules/base/rendering/modelgeometry.h>
#include <modules/newhorizons/util/imagesequencer.h>
#include <modules/newhorizons/util/labelparser.h>
#include <openspace/properties/numericalproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/util/updatestructures.h>
#include <modules/base/rendering/modelgeometry.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
namespace openspace {
namespace modelgeometry {
class ModelGeometry;
}
namespace modelgeometry {
class ModelGeometry;
}
class RenderableModelProjection : public Renderable {
public:
RenderableModelProjection(const ghoul::Dictionary& dictionary);
class RenderableModelProjection : public Renderable {
public:
RenderableModelProjection(const ghoul::Dictionary& dictionary);
bool initialize() override;
bool deinitialize() override;
bool initialize() override;
bool deinitialize() override;
bool isReady() const override;
bool isReady() const override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
protected:
void loadTextures();
std::unique_ptr<ghoul::opengl::Texture> loadProjectionTexture(const std::string& texturePath);
protected:
void loadTextures();
std::unique_ptr<ghoul::opengl::Texture> loadProjectionTexture(const std::string& texturePath);
private:
bool auxiliaryRendertarget();
glm::mat4 computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up);
void attitudeParameters(double time);
void imageProjectGPU(std::unique_ptr<ghoul::opengl::Texture> projectionTexture);
private:
bool auxiliaryRendertarget();
glm::mat4 computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up);
void attitudeParameters(double time);
void imageProjectGPU(std::unique_ptr<ghoul::opengl::Texture> projectionTexture);
void project();
void clearAllProjections();
void project();
void clearAllProjections();
properties::StringProperty _colorTexturePath;
properties::BoolProperty _performProjection;
properties::BoolProperty _clearAllProjections;
properties::StringProperty _colorTexturePath;
properties::BoolProperty _performProjection;
properties::BoolProperty _clearAllProjections;
properties::IntProperty _rotationX;
properties::IntProperty _rotationY;
properties::IntProperty _rotationZ;
properties::IntProperty _rotationX;
properties::IntProperty _rotationY;
properties::IntProperty _rotationZ;
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
std::unique_ptr<ghoul::opengl::ProgramObject> _fboProgramObject;
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
std::unique_ptr<ghoul::opengl::ProgramObject> _fboProgramObject;
std::unique_ptr<ghoul::opengl::Texture> _baseTexture;
std::unique_ptr<ghoul::opengl::Texture> _projectionTexture;
std::unique_ptr<ghoul::opengl::Texture> _baseTexture;
std::unique_ptr<ghoul::opengl::Texture> _projectionTexture;
properties::FloatProperty _projectionFading;
properties::FloatProperty _projectionFading;
modelgeometry::ModelGeometry* _geometry;
std::unique_ptr<modelgeometry::ModelGeometry> _geometry;
float _alpha;
glm::dmat3 _stateMatrix;
glm::dmat3 _instrumentMatrix;
float _alpha;
glm::dmat3 _stateMatrix;
glm::dmat3 _instrumentMatrix;
std::string _defaultProjImage;
std::string _source;
std::string _destination;
std::string _target;
std::string _defaultProjImage;
std::string _source;
std::string _destination;
std::string _target;
// sequence loading
std::string _sequenceSource;
std::string _sequenceType;
// sequence loading
std::string _sequenceSource;
std::string _sequenceType;
// projection mod info
std::string _instrumentID;
std::string _projectorID;
std::string _projecteeID;
SpiceManager::AberrationCorrection _aberration;
std::vector<std::string> _potentialTargets;
float _fovy;
float _aspectRatio;
float _nearPlane;
float _farPlane;
// projection mod info
std::string _instrumentID;
std::string _projectorID;
std::string _projecteeID;
SpiceManager::AberrationCorrection _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 _projectorMatrix;
glm::vec3 _boresight;
// uniforms
glm::vec2 _camScaling;
glm::vec3 _up;
glm::mat4 _transform;
glm::mat4 _projectorMatrix;
glm::vec3 _boresight;
// FBO stuff
GLuint _fboID;
GLuint _quad;
GLuint _vertexPositionBuffer;
// FBO stuff
GLuint _fboID;
GLuint _quad;
GLuint _vertexPositionBuffer;
GLuint _vbo;
GLuint _ibo;
GLuint _vaoID;
std::vector<modelgeometry::ModelGeometry::Vertex> _geometryVertecies;
std::vector<int> _geometryIndeces;
GLuint _vbo;
GLuint _ibo;
GLuint _vaoID;
std::vector<modelgeometry::ModelGeometry::Vertex> _geometryVertecies;
std::vector<int> _geometryIndeces;
std::vector<Image> _imageTimes;
int _frameCount;
double _time;
std::vector<Image> _imageTimes;
int _frameCount;
double _time;
bool _capture;
bool _capture;
std::string _clearingImage;
psc _sunPosition;
psc _sunPosition;
properties::BoolProperty _performShading;
bool _programIsDirty;
};
properties::BoolProperty _performShading;
bool _programIsDirty;
};
} // namespace openspace

View File

@@ -22,38 +22,24 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// open space includes
#include <modules/newhorizons/rendering/renderableplanetprojection.h>
#include <modules/base/rendering/planetgeometry.h>
#include <modules/newhorizons/util/hongkangparser.h>
#include <modules/newhorizons/util/labelparser.h>
#include <modules/newhorizons/util/sequenceparser.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/factorymanager.h>
#include <openspace/util/time.h>
#include <openspace/engine/configurationmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/opengl/textureconversion.h>
//#include <ghoul/opengl/textureunit.h>
#include <ghoul/filesystem/filesystem.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/opengl/textureunit.h>
#include <ghoul/systemcapabilities/openglcapabilitiescomponent.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/configurationmanager.h>
#include <openspace/rendering/renderengine.h>
#include <iomanip>
#include <string>
#include <thread>
#define _USE_MATH_DEFINES
#include <math.h>
namespace {
const std::string _loggerCat = "RenderablePlanetProjection";
const std::string keyProjObserver = "Projection.Observer";
@@ -98,7 +84,6 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
, _projectionTexture(nullptr)
, _heightMapTexture(nullptr)
, _capture(false)
, _clearingImage(absPath("${OPENSPACE_DATA}/scene/common/textures/clear.png"))
{
std::string name;
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
@@ -519,11 +504,6 @@ void RenderablePlanetProjection::render(const RenderData& data) {
}
void RenderablePlanetProjection::update(const UpdateData& data) {
if (_time >= Time::ref().currentTime()) {
// if jump back in time -> empty queue.
imageQueue = std::queue<Image>();
}
_time = Time::ref().currentTime();
_capture = false;

View File

@@ -25,39 +25,24 @@
#ifndef __RENDERABLEPLANETPROJECTION_H__
#define __RENDERABLEPLANETPROJECTION_H__
#include <ghoul/opengl/textureunit.h>
// open space includes
#include <openspace/rendering/renderable.h>
#include <modules/newhorizons/util/imagesequencer.h>
#include <modules/newhorizons/util/sequenceparser.h>
#include <modules/newhorizons/util/hongkangparser.h>
#include <modules/newhorizons/util/labelparser.h>
#include <modules/newhorizons/util/decoder.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <openspace/util/updatestructures.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/framebufferobject.h>
// ghoul includes
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <openspace/query/query.h>
#include <queue>
namespace openspace {
namespace planetgeometry{
class PlanetGeometry;
namespace planetgeometry {
class PlanetGeometry;
}
class RenderablePlanetProjection : public Renderable {
public:
RenderablePlanetProjection(const ghoul::Dictionary& dictionary);
@@ -138,7 +123,6 @@ private:
std::string _target;
std::string _frame;
std::string _clearingImage;
std::string _next;
bool _capture;
@@ -147,9 +131,6 @@ private:
GLuint _fboID;
GLuint _quad;
GLuint _vertexPositionBuffer;
std::queue<Image> imageQueue;
};
} // namespace openspace

View File

@@ -24,22 +24,21 @@
#version __CONTEXT__
#include "PowerScaling/powerScaling_vs.hglsl"
in vec4 vs_position;
in vec4 vs_normal;
in vec2 vs_uv;
in vec4 ProjTexCoord;
out vec4 color;
uniform sampler2D projectionTexture;
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);
}
@@ -55,10 +54,9 @@ void main() {
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(projectionTexture, projected.xy);
color.a = 1.0;
}
}
}

View File

@@ -24,22 +24,22 @@
#version __CONTEXT__
uniform mat4 ProjectorMatrix;
uniform mat4 ModelTransform;
uniform vec2 _scaling;
#include "PowerScaling/powerScaling_vs.hglsl"
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;
out vec2 vs_uv;
out vec4 ProjTexCoord;
#include "PowerScaling/powerScaling_vs.hglsl"
uniform mat4 ProjectorMatrix;
uniform mat4 ModelTransform;
uniform vec2 _scaling;
uniform vec3 boresight;
void main() {
vs_position = in_position;

View File

@@ -61,8 +61,8 @@ void main() {
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
vec4 raw_pos = psc_to_meter(tmp, scaling);
ProjTexCoord = ProjectorMatrix * ModelTransform * raw_pos;
// vec4 raw_pos = psc_to_meter(tmp, scaling);
// ProjTexCoord = ProjectorMatrix * ModelTransform * raw_pos;
position = ViewProjection * position;