diff --git a/data/scene/earth/earth.mod b/data/scene/earth/earth.mod index 5743118b1c..ff198f5642 100644 --- a/data/scene/earth/earth.mod +++ b/data/scene/earth/earth.mod @@ -25,14 +25,9 @@ return { Name = "Earth", Parent = "EarthBarycenter", Renderable = { - Type = "RenderableTestPlanet", + Type = "Planet", Frame = "IAU_EARTH", Body = "EARTH", - Geometry = { - Type = "SimpleSphereTest", - Radius = { 6.371, 6 }, - Segments = 100 - }, Textures = { Type = "simple", Color = "textures/earth_bluemarble.jpg", diff --git a/modules/planetbrowsing/CMakeLists.txt b/modules/planetbrowsing/CMakeLists.txt index 28650a180c..8613163980 100644 --- a/modules/planetbrowsing/CMakeLists.txt +++ b/modules/planetbrowsing/CMakeLists.txt @@ -27,18 +27,12 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planet.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletestplanet.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planettestgeometry.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheretestgeometry.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planet.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/geometry.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabletestplanet.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planettestgeometry.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheretestgeometry.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/planetbrowsing/planetbrowsingmodule.cpp b/modules/planetbrowsing/planetbrowsingmodule.cpp index 78717d84ca..7735701fc5 100644 --- a/modules/planetbrowsing/planetbrowsingmodule.cpp +++ b/modules/planetbrowsing/planetbrowsingmodule.cpp @@ -25,9 +25,6 @@ #include #include -#include -#include -#include #include #include @@ -60,17 +57,10 @@ void PlanetBrowsingModule::internalInitialize() { - FactoryManager::ref().addFactory(std::make_unique>()); - auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fRenderable, "Renderable factory was not created"); - fRenderable->registerClass("RenderableTestPlanet"); - - - auto fPlanetGeometry = FactoryManager::ref().factory(); - ghoul_assert(fPlanetGeometry, "Planet test geometry factory was not created"); - fPlanetGeometry->registerClass("SimpleSphereTest"); + fRenderable->registerClass("Planet"); } diff --git a/modules/planetbrowsing/rendering/geometry.cpp b/modules/planetbrowsing/rendering/geometry.cpp index 2ef7215e1a..dd5dcd65ea 100644 --- a/modules/planetbrowsing/rendering/geometry.cpp +++ b/modules/planetbrowsing/rendering/geometry.cpp @@ -95,8 +95,8 @@ bool Geometry::initialize() { glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferID); glBufferData( GL_ARRAY_BUFFER, - _elementData.size() * sizeof(Vertex), - &_elementData[0], + _vertexData.size() * sizeof(Vertex), + &_vertexData[0], GL_STATIC_DRAW); // Positions at location 0 diff --git a/modules/planetbrowsing/rendering/planet.cpp b/modules/planetbrowsing/rendering/planet.cpp index cb85ea615b..f5c6578a84 100644 --- a/modules/planetbrowsing/rendering/planet.cpp +++ b/modules/planetbrowsing/rendering/planet.cpp @@ -23,131 +23,258 @@ ****************************************************************************************/ // open space includes -#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 = "Planet"; - const std::string keyGeometry = "Geometry"; + const std::string keyFrame = "Frame"; + const std::string keyGeometry = "Geometry"; + const std::string keyShading = "PerformShading"; + + const std::string keyBody = "Body"; } namespace openspace { -Planet::Planet(const ghoul::Dictionary& dictionary) : - Renderable(dictionary), - _geometry(nullptr), - _testProgramObject(nullptr) -{ - std::string name; - bool success = dictionary.getValue(SceneGraphNode::KeyName, name); - LDEBUG(name); + Planet::Planet(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _colorTexturePath("colorTexture", "Color Texture") + , _programObject(nullptr) + , _texture(nullptr) + , _nightTexture(nullptr) + , _performShading("performShading", "Perform Shading", true) + , _rotation("rotation", "Rotation", 0, 0, 360) + , _alpha(1.f) + , _nightTexturePath("") + , _hasNightTexture(false) + { + std::string name; + bool success = dictionary.getValue(SceneGraphNode::KeyName, name); + ghoul_assert(success, + "RenderablePlanet need the '" << SceneGraphNode::KeyName << "' be specified"); - ghoul_assert(success, - "Planet need the '" << SceneGraphNode::KeyName << "' be specified"); + //std::string path; + //success = dictionary.getValue(constants::scenegraph::keyPathModule, path); + //ghoul_assert(success, + // "RenderablePlanet need the '"<(keyShading)) { + bool shading; + dictionary.getValue(keyShading, shading); + _performShading = shading; + } + + addProperty(_performShading); + // Mainly for debugging purposes @AA + addProperty(_rotation); - ghoul::Dictionary geometryDictionary; - success = dictionary.getValue(keyGeometry, geometryDictionary); - if (success) { - geometryDictionary.setValue(SceneGraphNode::KeyName, name); - //geometryDictionary.setValue(constants::scenegraph::keyPathModule, path); - _geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary); + // Create a simple triangle for testing the geometry + std::vector triangleElements; + std::vector trianglePositions; + + trianglePositions.push_back(glm::vec4(0, 0, 0, 1)); + trianglePositions.push_back(glm::vec4(10000000, 0, 0, 1)); + trianglePositions.push_back(glm::vec4(10000000, 10000000, 0, 1)); + + triangleElements.push_back(0); + triangleElements.push_back(1); + triangleElements.push_back(2); + + _testGeometry = std::unique_ptr(new Geometry( + triangleElements, + Geometry::Positions::Yes, + Geometry::Textures::No, + Geometry::Normals::No)); + + _testGeometry->setPositionData(trianglePositions); + _testGeometry->initialize(); + } - addPropertySubOwner(_geometry); - - /* - // Create a simple triangle for testing the geometry - std::vector triangleElements; - std::vector trianglePositions; - - trianglePositions.push_back(glm::vec4(0, 0, -0.5, 1)); - trianglePositions.push_back(glm::vec4(1, 0, -0.5, 1)); - trianglePositions.push_back(glm::vec4(1, 1, -0.5, 1)); - - triangleElements.push_back(0); - triangleElements.push_back(1); - triangleElements.push_back(2); - - _testGeometry = std::unique_ptr(new Geometry( - triangleElements, - Geometry::Positions::Yes, - Geometry::Textures::No, - Geometry::Normals::No)); - - _testGeometry->setPositionData(trianglePositions); - _testGeometry->initialize(); - */ - // Create a test shader program object - -} - -Planet::~Planet() { - -} - -bool Planet::initialize() { - RenderEngine& renderEngine = OsEng.renderEngine(); - if (_testProgramObject == nullptr) { - _testProgramObject = renderEngine.buildRenderProgram( - "simpleTestProgram", - "${MODULE_PLANETBROWSING}/shaders/simple_vs.glsl", - "${MODULE_PLANETBROWSING}/shaders/simple_fs.glsl"); - if (!_testProgramObject) return false; + Planet::~Planet() { } - return true; -} + bool Planet::initialize() { + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_programObject == nullptr && _hasNightTexture) { + // Night texture program + _programObject = renderEngine.buildRenderProgram( + "simpleTextureProgram", + "${MODULE_PLANETBROWSING}/shaders/simple_vs.glsl", + "${MODULE_PLANETBROWSING}/shaders/simple_fs.glsl"); + if (!_programObject) return false; + } + else if (_programObject == nullptr) { + // pscstandard + _programObject = renderEngine.buildRenderProgram( + "pscstandard", + "${SHADERS}/pscstandard_vs.glsl", + "${SHADERS}/pscstandard_fs.glsl"); + if (!_programObject) return false; -bool Planet::deinitialize() { - RenderEngine& renderEngine = OsEng.renderEngine(); - if (_testProgramObject) { - renderEngine.removeRenderProgram(_testProgramObject); - _testProgramObject = nullptr; + } + using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; + _programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes); + + loadTexture(); + + return isReady(); } - - if (_geometry) { - _geometry->deinitialize(); - delete _geometry; + + bool Planet::deinitialize() { + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_programObject) { + renderEngine.removeRenderProgram(_programObject); + _programObject = nullptr; + } + + _texture = nullptr; + _nightTexture = nullptr; + return true; } - _geometry = nullptr; - return true; -} + bool Planet::isReady() const { + bool ready = true; + ready &= (_programObject != nullptr); + ready &= (_texture != nullptr); + return ready; + } -bool Planet::isReady() const { - bool ready = true; - ready &= (_testProgramObject != nullptr); - ready &= (_geometry != nullptr); + void Planet::render(const RenderData& data) + { + // activate shader + _programObject->activate(); - return ready; -} + // scale the planet to appropriate size since the planet is a unit sphere + glm::mat4 transform = glm::mat4(1); -void Planet::render(const RenderData& data) { - // activate shader - _testProgramObject->activate(); + //earth needs to be rotated for that to work. + glm::mat4 rot = glm::rotate(transform, static_cast(M_PI_2), glm::vec3(1, 0, 0)); + glm::mat4 roty = glm::rotate(transform, static_cast(M_PI_2), glm::vec3(0, -1, 0)); + glm::mat4 rotProp = glm::rotate(transform, glm::radians(static_cast(_rotation)), glm::vec3(0, 1, 0)); + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + transform[i][j] = static_cast(_stateMatrix[i][j]); + } + } + transform = transform * rot * roty * rotProp; + + //glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix(); + //glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz; - //_testGeometry->render(); - _geometry->render(); + double lt; + glm::dvec3 p = + SpiceManager::ref().targetPosition("SUN", _target, "GALACTIC", {}, _time, lt); + psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z); + // setup the data to the shader + // _programObject->setUniform("camdir", camSpaceEye); + _programObject->setUniform("transparency", _alpha); + _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); + _programObject->setUniform("ModelTransform", transform); + setPscUniforms(_programObject.get(), &data.camera, data.position); - // disable shader - _testProgramObject->deactivate(); -} + _programObject->setUniform("_performShading", _performShading); -void Planet::update(const UpdateData& data) { - -} + // Bind texture + ghoul::opengl::TextureUnit dayUnit; + dayUnit.activate(); + _texture->bind(); + _programObject->setUniform("texture1", dayUnit); + + // Bind possible night texture + if (_hasNightTexture) { + ghoul::opengl::TextureUnit nightUnit; + nightUnit.activate(); + _nightTexture->bind(); + _programObject->setUniform("nightTex", nightUnit); + } + + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + // render + _testGeometry->render(); + + // disable shader + _programObject->deactivate(); + } + + void Planet::update(const UpdateData& data) { + // set spice-orientation in accordance to timestamp + _stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time); + _time = data.time; + } + + void Planet::loadTexture() { + _texture = nullptr; + if (_colorTexturePath.value() != "") { + _texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath))); + if (_texture) { + LDEBUG("Loaded texture from '" << _colorTexturePath << "'"); + _texture->uploadTexture(); + + // Textures of planets looks much smoother with AnisotropicMipMap rather than linear + // TODO: AnisotropicMipMap crashes on ATI cards ---abock + //_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); + _texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + } + } + if (_hasNightTexture) { + _nightTexture = nullptr; + if (_nightTexturePath != "") { + _nightTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath))); + if (_nightTexture) { + LDEBUG("Loaded texture from '" << _nightTexturePath << "'"); + _nightTexture->uploadTexture(); + _nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + //_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); + } + } + } + } } // namespace openspace diff --git a/modules/planetbrowsing/rendering/planet.h b/modules/planetbrowsing/rendering/planet.h index d4db0b95d5..b02fe5e344 100644 --- a/modules/planetbrowsing/rendering/planet.h +++ b/modules/planetbrowsing/rendering/planet.h @@ -28,34 +28,55 @@ // open space includes #include +#include +#include + #include -#include +// ghoul includes +namespace ghoul { + namespace opengl { + class ProgramObject; + class Texture; + } +} namespace openspace { -namespace planetgeometry { - class PlanetGeometry; -} + class Planet : public Renderable { + public: + Planet(const ghoul::Dictionary& dictionary); + ~Planet(); -class Planet : public Renderable { -public: - Planet(const ghoul::Dictionary& dictionary); - ~Planet(); + bool initialize() override; + bool deinitialize() override; + bool isReady() const override; - bool initialize() override; - bool deinitialize() 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 loadTexture(); -private: -// std::unique_ptr _testGeometry; - planetgeometry::PlanetGeometry* _geometry; + private: + properties::StringProperty _colorTexturePath; + std::unique_ptr _programObject; + std::unique_ptr _texture; + std::unique_ptr _nightTexture; - std::unique_ptr _testProgramObject; -}; + std::unique_ptr _testGeometry; + + properties::BoolProperty _performShading; + properties::IntProperty _rotation; + float _alpha; + + glm::dmat3 _stateMatrix; + std::string _nightTexturePath; + std::string _frame; + std::string _target; + bool _hasNightTexture; + double _time; + }; } // namespace openspace diff --git a/modules/planetbrowsing/rendering/planettestgeometry.cpp b/modules/planetbrowsing/rendering/planettestgeometry.cpp deleted file mode 100644 index 2c06f5e90c..0000000000 --- a/modules/planetbrowsing/rendering/planettestgeometry.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/***************************************************************************************** -* * -* 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 -#include -#include - -namespace { - const std::string _loggerCat = "PlanetTestGeometry"; - const std::string KeyType = "Type"; -} - -namespace openspace { - namespace planettestgeometry { - - PlanetTestGeometry* PlanetTestGeometry::createFromDictionary(const ghoul::Dictionary& dictionary) { - std::string geometryType; - const bool success = dictionary.getValue(KeyType, geometryType); - if (!success) { - LERROR("PlanetTestGeometry did not contain a correct value of the key '" - << KeyType << "'"); - return nullptr; - } - ghoul::TemplateFactory* factory - = FactoryManager::ref().factory(); - - PlanetTestGeometry* result = factory->create(geometryType, dictionary); - if (result == nullptr) { - LERROR("Failed to create a PlanetTestGeometry object of type '" << geometryType - << "'"); - return nullptr; - } - return result; - } - - PlanetTestGeometry::PlanetTestGeometry() - : _parent(nullptr) - { - setName("PlanetTestGeometry"); - } - - PlanetTestGeometry::~PlanetTestGeometry() - { - } - - bool PlanetTestGeometry::initialize(RenderableTestPlanet* parent) - { - _parent = parent; - return true; - } - - void PlanetTestGeometry::deinitialize() - { - } - - } // namespace planettestgeometry -} // namespace openspace diff --git a/modules/planetbrowsing/rendering/planettestgeometry.h b/modules/planetbrowsing/rendering/planettestgeometry.h deleted file mode 100644 index 4a4a510290..0000000000 --- a/modules/planetbrowsing/rendering/planettestgeometry.h +++ /dev/null @@ -1,53 +0,0 @@ -/***************************************************************************************** -* * -* 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 __PLANETTESTGEOMETRY_H__ -#define __PLANETTESTGEOMETRY_H__ - -#include -#include -#include - -namespace openspace { - - namespace planettestgeometry { - - class PlanetTestGeometry : public properties::PropertyOwner { - public: - static PlanetTestGeometry* createFromDictionary(const ghoul::Dictionary& dictionary); - - PlanetTestGeometry(); - virtual ~PlanetTestGeometry(); - virtual bool initialize(RenderableTestPlanet* parent); - virtual void deinitialize(); - virtual void render() = 0; - - protected: - RenderableTestPlanet* _parent; - }; - - } // namespace planettestgeometry -} // namespace openspace - -#endif // __PLANETTESTGEOMETRY_H__ diff --git a/modules/planetbrowsing/rendering/renderabletestplanet.cpp b/modules/planetbrowsing/rendering/renderabletestplanet.cpp deleted file mode 100644 index 811c4fb5a2..0000000000 --- a/modules/planetbrowsing/rendering/renderabletestplanet.cpp +++ /dev/null @@ -1,279 +0,0 @@ -/***************************************************************************************** - * * - * 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 - -#define _USE_MATH_DEFINES -#include - -namespace { - const std::string _loggerCat = "RenderableTestPlanet"; - - const std::string keyFrame = "Frame"; - const std::string keyGeometry = "Geometry"; - const std::string keyShading = "PerformShading"; - -const std::string keyBody = "Body"; -} - -namespace openspace { - -RenderableTestPlanet::RenderableTestPlanet(const ghoul::Dictionary& dictionary) - : Renderable(dictionary) - , _colorTexturePath("colorTexture", "Color Texture") - , _programObject(nullptr) - , _texture(nullptr) - , _nightTexture(nullptr) - , _geometry(nullptr) - , _performShading("performShading", "Perform Shading", true) - , _rotation("rotation", "Rotation", 0, 0, 360) - , _alpha(1.f) - , _nightTexturePath("") - , _hasNightTexture(false) -{ - std::string name; - bool success = dictionary.getValue(SceneGraphNode::KeyName, name); - ghoul_assert(success, - "RenderablePlanet need the '" << SceneGraphNode::KeyName<<"' be specified"); - - //std::string path; - //success = dictionary.getValue(constants::scenegraph::keyPathModule, path); - //ghoul_assert(success, - // "RenderablePlanet need the '"<(keyShading)) { - bool shading; - dictionary.getValue(keyShading, shading); - _performShading = shading; - } - - addProperty(_performShading); - // Mainly for debugging purposes @AA - addProperty(_rotation); -} - -RenderableTestPlanet::~RenderableTestPlanet() { -} - -bool RenderableTestPlanet::initialize() { - RenderEngine& renderEngine = OsEng.renderEngine(); - if (_programObject == nullptr && _hasNightTexture) { - // Night texture program - _programObject = renderEngine.buildRenderProgram( - "nightTextureProgram", - "${SHADERS}/nighttexture_vs.glsl", - "${SHADERS}/nighttexture_fs.glsl"); - if (!_programObject) return false; - } - else if (_programObject == nullptr) { - // pscstandard - _programObject = renderEngine.buildRenderProgram( - "pscstandard", - "${SHADERS}/pscstandard_vs.glsl", - "${SHADERS}/pscstandard_fs.glsl"); - if (!_programObject) return false; - - } - using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; - _programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes); - - loadTexture(); - _geometry->initialize(this); - - return isReady(); -} - -bool RenderableTestPlanet::deinitialize() { - if(_geometry) { - _geometry->deinitialize(); - delete _geometry; - } - - RenderEngine& renderEngine = OsEng.renderEngine(); - if (_programObject) { - renderEngine.removeRenderProgram(_programObject); - _programObject = nullptr; - } - - _geometry = nullptr; - _texture = nullptr; - _nightTexture = nullptr; - return true; -} - -bool RenderableTestPlanet::isReady() const { - bool ready = true; - ready &= (_programObject != nullptr); - ready &= (_texture != nullptr); - ready &= (_geometry != nullptr); - return ready; -} - -void RenderableTestPlanet::render(const RenderData& data) -{ - // activate shader - _programObject->activate(); - - // scale the planet to appropriate size since the planet is a unit sphere - glm::mat4 transform = glm::mat4(1); - - //earth needs to be rotated for that to work. - glm::mat4 rot = glm::rotate(transform, static_cast(M_PI_2), glm::vec3(1, 0, 0)); - glm::mat4 roty = glm::rotate(transform, static_cast(M_PI_2), glm::vec3(0, -1, 0)); - glm::mat4 rotProp = glm::rotate(transform, glm::radians(static_cast(_rotation)), glm::vec3(0, 1, 0)); - - for (int i = 0; i < 3; i++){ - for (int j = 0; j < 3; j++){ - transform[i][j] = static_cast(_stateMatrix[i][j]); - } - } - transform = transform * rot * roty * rotProp; - - //glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix(); - //glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz; - - - double lt; - glm::dvec3 p = - SpiceManager::ref().targetPosition("SUN", _target, "GALACTIC", {}, _time, lt); - psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z); - - // setup the data to the shader -// _programObject->setUniform("camdir", camSpaceEye); - _programObject->setUniform("transparency", _alpha); - _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); - _programObject->setUniform("ModelTransform", transform); - setPscUniforms(_programObject.get(), &data.camera, data.position); - - _programObject->setUniform("_performShading", _performShading); - - // Bind texture - ghoul::opengl::TextureUnit dayUnit; - dayUnit.activate(); - _texture->bind(); - _programObject->setUniform("texture1", dayUnit); - - // Bind possible night texture - if (_hasNightTexture) { - ghoul::opengl::TextureUnit nightUnit; - nightUnit.activate(); - _nightTexture->bind(); - _programObject->setUniform("nightTex", nightUnit); - } - - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - - // render - _geometry->render(); - - // disable shader - _programObject->deactivate(); -} - -void RenderableTestPlanet::update(const UpdateData& data){ - // set spice-orientation in accordance to timestamp - _stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time); - _time = data.time; -} - -void RenderableTestPlanet::loadTexture() { - _texture = nullptr; - if (_colorTexturePath.value() != "") { - _texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath))); - if (_texture) { - LDEBUG("Loaded texture from '" << _colorTexturePath << "'"); - _texture->uploadTexture(); - - // Textures of planets looks much smoother with AnisotropicMipMap rather than linear - // TODO: AnisotropicMipMap crashes on ATI cards ---abock - //_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); - _texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); - } - } - if (_hasNightTexture) { - _nightTexture = nullptr; - if (_nightTexturePath != "") { - _nightTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_nightTexturePath))); - if (_nightTexture) { - LDEBUG("Loaded texture from '" << _nightTexturePath << "'"); - _nightTexture->uploadTexture(); - _nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); - //_nightTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); - } - } - } -} - -} // namespace openspace diff --git a/modules/planetbrowsing/rendering/renderabletestplanet.h b/modules/planetbrowsing/rendering/renderabletestplanet.h deleted file mode 100644 index 2903f24b28..0000000000 --- a/modules/planetbrowsing/rendering/renderabletestplanet.h +++ /dev/null @@ -1,83 +0,0 @@ -/***************************************************************************************** - * * - * 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 __RENDERABLETESTPLANET_H__ -#define __RENDERABLETESTPLANET_H__ - -// open space includes -#include - -#include -#include - -// ghoul includes -namespace ghoul { - namespace opengl { - class ProgramObject; - class Texture; - } -} - -namespace openspace { - -namespace planettestgeometry { -class PlanetTestGeometry; -} - -class RenderableTestPlanet : public Renderable { -public: - RenderableTestPlanet(const ghoul::Dictionary& dictionary); - ~RenderableTestPlanet(); - - 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(); - -private: - properties::StringProperty _colorTexturePath; - std::unique_ptr _programObject; - std::unique_ptr _texture; - std::unique_ptr _nightTexture; - planettestgeometry::PlanetTestGeometry* _geometry; - properties::BoolProperty _performShading; - properties::IntProperty _rotation; - float _alpha; - - glm::dmat3 _stateMatrix; - std::string _nightTexturePath; - std::string _frame; - std::string _target; - bool _hasNightTexture; - double _time; -}; - -} // namespace openspace - -#endif // __RENDERABLETESTPLANET_H__ \ No newline at end of file diff --git a/modules/planetbrowsing/rendering/simplespheretestgeometry.cpp b/modules/planetbrowsing/rendering/simplespheretestgeometry.cpp deleted file mode 100644 index 549eab6302..0000000000 --- a/modules/planetbrowsing/rendering/simplespheretestgeometry.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/***************************************************************************************** -* * -* 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 -#include -#include - -namespace { - const std::string _loggerCat = "SimpleSphereTestGeometry"; -} - -namespace openspace { - - namespace constants { - namespace simplespheretestgeometry { - const std::string keyRadius = "Radius"; - const std::string keySegments = "Segments"; - } // namespace simplespheretestgeometry - } - - namespace planettestgeometry { - - SimpleSphereTestGeometry::SimpleSphereTestGeometry(const ghoul::Dictionary& dictionary) - : PlanetTestGeometry() - , _realRadius("radius", "Radius", glm::vec4(1.f, 1.f, 1.f, 0.f), glm::vec4(-10.f, -10.f, -10.f, -20.f), - glm::vec4(10.f, 10.f, 10.f, 20.f)) - , _segments("segments", "Segments", 20, 1, 50) - , _sphere(nullptr) - { - using constants::simplespheretestgeometry::keyRadius; - using constants::simplespheretestgeometry::keySegments; - - // The name is passed down from the SceneGraphNode - bool success = dictionary.getValue(SceneGraphNode::KeyName, _name); - assert(success); - - glm::vec4 radius; - success = dictionary.getValue(keyRadius, _modRadius); - if (!success) { - LERROR("SimpleSphereTestGeometry of '" << _name << "' did not provide a key '" - << keyRadius << "'"); - } - else { - radius[0] = _modRadius[0]; - radius[1] = _modRadius[0]; - radius[2] = _modRadius[0]; - radius[3] = _modRadius[1]; - _realRadius = radius; // In case the kernels does not supply a real - } - - double segments; - success = dictionary.getValue(keySegments, segments); - if (!success) { - LERROR("SimpleSphereTestGeometry of '" << _name << "' did not provide a key '" - << keySegments << "'"); - } - else - _segments = static_cast(segments); - - // The shader need the radii values but they are not changeable runtime - // TODO: Possibly add a scaling property @AA - addProperty(_realRadius); - // Changing the radius/scaling should affect the shader but not the geometry? @AA - //_radius.onChange(std::bind(&SimpleSphereTestGeometry::createSphere, this)); - addProperty(_segments); - _segments.onChange(std::bind(&SimpleSphereTestGeometry::createSphere, this)); - } - - SimpleSphereTestGeometry::~SimpleSphereTestGeometry() - { - } - - bool SimpleSphereTestGeometry::initialize(RenderableTestPlanet* parent) - { - bool success = PlanetTestGeometry::initialize(parent); - createSphere(); - return success; - } - - void SimpleSphereTestGeometry::deinitialize() - { - if (_sphere) - delete _sphere; - _sphere = nullptr; - } - - void SimpleSphereTestGeometry::render() - { - _sphere->render(); - } - - void SimpleSphereTestGeometry::createSphere() { - //create the power scaled scalar - - PowerScaledScalar planetSize(_modRadius); - _parent->setBoundingSphere(planetSize); - - if (_sphere) - delete _sphere; - //_sphere = new PowerScaledSphere(planetSize, _segments); - _sphere = new PowerScaledSphere(_realRadius, _segments, _name); - _sphere->initialize(); - } - - } // namespace planetgeometry -} // namespace openspace diff --git a/modules/planetbrowsing/rendering/simplespheretestgeometry.h b/modules/planetbrowsing/rendering/simplespheretestgeometry.h deleted file mode 100644 index d84efb0ccd..0000000000 --- a/modules/planetbrowsing/rendering/simplespheretestgeometry.h +++ /dev/null @@ -1,64 +0,0 @@ -/***************************************************************************************** -* * -* 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 __SIMPLESPHERETESTGEOMETRY_H__ -#define __SIMPLESPHERETESTGEOMETRY_H__ - -#include -#include -#include - -namespace openspace { - - class RenderablePlanet; - class PowerScaledSphere; - - namespace planettestgeometry { - - class SimpleSphereTestGeometry : public PlanetTestGeometry { - public: - SimpleSphereTestGeometry(const ghoul::Dictionary& dictionary); - ~SimpleSphereTestGeometry(); - - - bool initialize(RenderableTestPlanet* parent) override; - void deinitialize() override; - void render() override; - PowerScaledSphere* _planet; - - private: - void createSphere(); - - glm::vec2 _modRadius; - properties::Vec4Property _realRadius; - properties::IntProperty _segments; - std::string _name; - - PowerScaledSphere* _sphere; - }; - - } // namespace planetgeometry -} // namespace openspace - -#endif // __SIMPLESPHERETESTGEOMETRY_H__ diff --git a/modules/planetbrowsing/shaders/simple_fs.glsl b/modules/planetbrowsing/shaders/simple_fs.glsl index b46d9f5e65..9610505039 100644 --- a/modules/planetbrowsing/shaders/simple_fs.glsl +++ b/modules/planetbrowsing/shaders/simple_fs.glsl @@ -22,6 +22,18 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +uniform vec4 campos; +uniform vec4 objpos; + +uniform vec3 sun_pos; + +uniform bool _performShading = true; +uniform float transparency; +uniform int shadows; + +uniform float time; +uniform sampler2D texture1; +uniform sampler2D nightTex; in vec4 vs_position; @@ -29,12 +41,10 @@ in vec4 vs_position; #include "fragment.glsl" Fragment getFragment() { - vec4 position = vs_position; - Fragment frag; - + frag.color = vec4(1,1,1,1); - frag.depth = 0; + frag.depth = pscDepth(vs_position); return frag; } diff --git a/modules/planetbrowsing/shaders/simple_vs.glsl b/modules/planetbrowsing/shaders/simple_vs.glsl index 863ab80cb7..ae2870f620 100644 --- a/modules/planetbrowsing/shaders/simple_vs.glsl +++ b/modules/planetbrowsing/shaders/simple_vs.glsl @@ -24,6 +24,9 @@ #version __CONTEXT__ +uniform mat4 ViewProjection; +uniform mat4 ModelTransform; + layout(location = 0) in vec4 in_position; out vec4 vs_position; @@ -34,6 +37,10 @@ void main() { // set variables vs_position = in_position; + vec4 tmp = in_position; - gl_Position = in_position; + vec4 position = pscTransform(tmp, ModelTransform); + vs_position = tmp; + position = ViewProjection * position; + gl_Position = z_normalization(position); } \ No newline at end of file