From 4ef03bb02be1102e75bf4a3551110b0758f70a5a Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 3 Jun 2016 17:35:15 +0200 Subject: [PATCH] Further cleanup of projection code --- .../rendering/renderablemodelprojection.cpp | 78 +++---- .../rendering/renderablemodelprojection.h | 203 +++++++++--------- .../rendering/renderableplanetprojection.cpp | 38 +--- .../rendering/renderableplanetprojection.h | 27 +-- .../shaders/projectionPass_fs.glsl | 22 +- .../shaders/projectionPass_vs.glsl | 16 +- .../shaders/projectiveTexture_vs.glsl | 4 +- 7 files changed, 167 insertions(+), 221 deletions(-) diff --git a/modules/newhorizons/rendering/renderablemodelprojection.cpp b/modules/newhorizons/rendering/renderablemodelprojection.cpp index 606bd6d30a..e809244c49 100644 --- a/modules/newhorizons/rendering/renderablemodelprojection.cpp +++ b/modules/newhorizons/rendering/renderablemodelprojection.cpp @@ -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 +#include +#include + +#include +#include +#include +#include + +#include #include #include -#include - -#include -#include -#include - -#include -#include #include - -#define _USE_MATH_DEFINES -#include -#include - 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::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; diff --git a/modules/newhorizons/rendering/renderablemodelprojection.h b/modules/newhorizons/rendering/renderablemodelprojection.h index 564fe4303a..a526f25489 100644 --- a/modules/newhorizons/rendering/renderablemodelprojection.h +++ b/modules/newhorizons/rendering/renderablemodelprojection.h @@ -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 +#include #include -#include #include #include -#include -#include #include +#include #include #include 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 loadProjectionTexture(const std::string& texturePath); +protected: + void loadTextures(); + std::unique_ptr 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 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 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 _programObject; - std::unique_ptr _fboProgramObject; + std::unique_ptr _programObject; + std::unique_ptr _fboProgramObject; - std::unique_ptr _baseTexture; - std::unique_ptr _projectionTexture; + std::unique_ptr _baseTexture; + std::unique_ptr _projectionTexture; - properties::FloatProperty _projectionFading; + properties::FloatProperty _projectionFading; - modelgeometry::ModelGeometry* _geometry; + std::unique_ptr _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 _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 _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 _geometryVertecies; - std::vector _geometryIndeces; + GLuint _vbo; + GLuint _ibo; + GLuint _vaoID; + std::vector _geometryVertecies; + std::vector _geometryIndeces; - std::vector _imageTimes; - int _frameCount; - double _time; + std::vector _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 diff --git a/modules/newhorizons/rendering/renderableplanetprojection.cpp b/modules/newhorizons/rendering/renderableplanetprojection.cpp index 7b76281096..1b9c922fd1 100644 --- a/modules/newhorizons/rendering/renderableplanetprojection.cpp +++ b/modules/newhorizons/rendering/renderableplanetprojection.cpp @@ -22,38 +22,24 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -// open space includes #include #include +#include +#include +#include +#include +#include +#include +#include -#include - +#include #include #include -//#include -#include -#include - -#include -#include - -#include - +#include #include -#include -#include -#include -#include -#include -#include - -#define _USE_MATH_DEFINES -#include - - 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(); - } - _time = Time::ref().currentTime(); _capture = false; diff --git a/modules/newhorizons/rendering/renderableplanetprojection.h b/modules/newhorizons/rendering/renderableplanetprojection.h index 97bed69da9..2c11eadfb6 100644 --- a/modules/newhorizons/rendering/renderableplanetprojection.h +++ b/modules/newhorizons/rendering/renderableplanetprojection.h @@ -25,39 +25,24 @@ #ifndef __RENDERABLEPLANETPROJECTION_H__ #define __RENDERABLEPLANETPROJECTION_H__ -#include - -// open space includes #include + #include -#include -#include -#include -#include - - #include #include -#include #include +#include -#include - -// ghoul includes #include #include -#include - -#include 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 imageQueue; }; } // namespace openspace diff --git a/modules/newhorizons/shaders/projectionPass_fs.glsl b/modules/newhorizons/shaders/projectionPass_fs.glsl index a513097a51..9b3c4975b7 100644 --- a/modules/newhorizons/shaders/projectionPass_fs.glsl +++ b/modules/newhorizons/shaders/projectionPass_fs.glsl @@ -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; } -} \ No newline at end of file +} diff --git a/modules/newhorizons/shaders/projectionPass_vs.glsl b/modules/newhorizons/shaders/projectionPass_vs.glsl index 0fed1ba6ee..583c841193 100644 --- a/modules/newhorizons/shaders/projectionPass_vs.glsl +++ b/modules/newhorizons/shaders/projectionPass_vs.glsl @@ -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; diff --git a/modules/newhorizons/shaders/projectiveTexture_vs.glsl b/modules/newhorizons/shaders/projectiveTexture_vs.glsl index 2a1802b4b8..fb81090d2d 100644 --- a/modules/newhorizons/shaders/projectiveTexture_vs.glsl +++ b/modules/newhorizons/shaders/projectiveTexture_vs.glsl @@ -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;