diff --git a/ext/ghoul b/ext/ghoul index 68c53264aa..48bd2ef9a3 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 68c53264aaf05e1fc9526a857ac38db2d620557e +Subproject commit 48bd2ef9a32498be7dd5c7261561f6257342d6ec diff --git a/include/openspace/rendering/planets/renderableplanetprojection.h b/include/openspace/rendering/planets/renderableplanetprojection.h index ac0a11becb..e2c3b1a5ce 100644 --- a/include/openspace/rendering/planets/renderableplanetprojection.h +++ b/include/openspace/rendering/planets/renderableplanetprojection.h @@ -31,6 +31,8 @@ #include #include +#include + // ghoul includes #include #include @@ -60,7 +62,11 @@ private: properties::StringProperty _colorTexturePath; properties::StringProperty _projectionTexturePath; + ghoul::opengl::FramebufferObject fbo; + ghoul::opengl::ProgramObject* _programObject; + ghoul::opengl::ProgramObject* _writeToTextureProgramObject; + ghoul::opengl::Texture* _texture; ghoul::opengl::Texture* _textureProj; planetgeometryprojection::PlanetGeometryProjection* _geometry; diff --git a/include/openspace/rendering/planets/writeToTexture.h b/include/openspace/rendering/planets/writeToTexture.h new file mode 100644 index 0000000000..1ccae2a8c2 --- /dev/null +++ b/include/openspace/rendering/planets/writeToTexture.h @@ -0,0 +1,71 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014 * +* * +* 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 __RENDERABLEPLANET_H__ +#define __RENDERABLEPLANET_H__ + +// open space includes +#include + +#include +#include + +// ghoul includes +#include +#include + +namespace openspace { + +namespace planetgeometry { +class PlanetGeometry; +} + +class RenderablePlanet : public Renderable { +public: + RenderablePlanet(const ghoul::Dictionary& dictionary); + ~RenderablePlanet(); + + bool initialize() override; + bool deinitialize() override; + + void render(const RenderData& data) override; + void update(const UpdateData& data) override; + +protected: + void loadTexture(); + +private: + properties::StringProperty _colorTexturePath; + ghoul::opengl::ProgramObject* _programObject; + ghoul::opengl::Texture* _texture; + planetgeometry::PlanetGeometry* _geometry; + + glm::dmat3 _stateMatrix; + + std::string _target; +}; + +} // namespace openspace + +#endif // __RENDERABLEPLANET_H__ \ No newline at end of file diff --git a/openspace-data b/openspace-data index 7420c9d2b0..65ac894014 160000 --- a/openspace-data +++ b/openspace-data @@ -1 +1 @@ -Subproject commit 7420c9d2b031cd831057e639e92967ffc37e29d3 +Subproject commit 65ac8940144d28dc7d2669cad40ce0abe0ab62fb diff --git a/openspace3.zip b/openspace3.zip new file mode 100644 index 0000000000..39d7930afc Binary files /dev/null and b/openspace3.zip differ diff --git a/scripts/default_startup.lua b/scripts/default_startup.lua index e175e34478..3f7e4452c3 100644 --- a/scripts/default_startup.lua +++ b/scripts/default_startup.lua @@ -1,5 +1,5 @@ --openspace.setPropertyValue('Earth.renderable.colorTexture', '${OPENSPACE_DATA}/modules/mars/textures/mars.png') -openspace.time.setTime("2007-02-28T11:48:16.364") +openspace.time.setTime("2007-02-26T17:38:00.00") --openspace.time.setTime("2006-08-22T20:00:00") --openspace.time.setDeltaTime(200000.0) diff --git a/shaders/projectiveTexture_fs.glsl b/shaders/projectiveTexture_fs.glsl index 807221a2a9..b52fec6123 100644 --- a/shaders/projectiveTexture_fs.glsl +++ b/shaders/projectiveTexture_fs.glsl @@ -78,7 +78,7 @@ void main() // PROJECTIVE TEXTURE vec4 projTexColor = textureProj(texture2, ProjTexCoord); - vec4 shaded = max(intensity * diffuse, ambient); + vec4 shaded = diffuse;//max(intensity * diffuse, ambient); if (ProjTexCoord[0] > 0.0 || ProjTexCoord[1] > 0.0 || ProjTexCoord[0] < ProjTexCoord[2] || @@ -89,10 +89,7 @@ void main() }else{ diffuse = shaded; } - - - ABufferStruct_t frag = createGeometryFragment(diffuse, position, depth); addToBuffer(frag); diff --git a/shaders/projectiveTexture_vs.glsl b/shaders/projectiveTexture_vs.glsl index e5ea9e77a6..f7887e4ac5 100644 --- a/shaders/projectiveTexture_vs.glsl +++ b/shaders/projectiveTexture_vs.glsl @@ -51,6 +51,7 @@ out vec4 ProjTexCoord; void main() { + // Radius = 0.71492 *10^8; vs_boresight = boresight; // set variables vs_st = in_st; diff --git a/shaders/writeToTexture_fs.glsl b/shaders/writeToTexture_fs.glsl new file mode 100644 index 0000000000..4372bb0819 --- /dev/null +++ b/shaders/writeToTexture_fs.glsl @@ -0,0 +1,33 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * 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 430 + +in vec4 vs_position; + +out vec4 color; +void main() +{ + color = vec4(1); +} \ No newline at end of file diff --git a/shaders/writeToTexture_vs.glsl b/shaders/writeToTexture_vs.glsl new file mode 100644 index 0000000000..2ec1176451 --- /dev/null +++ b/shaders/writeToTexture_vs.glsl @@ -0,0 +1,34 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 * + * * + * 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 430 + + +layout(location = 0) in vec4 in_position; + +out vec4 vs_position; + +void main(){ + vs_position = in_position; +} \ No newline at end of file diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index dbdfe454de..572a2bbab3 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -291,27 +291,7 @@ bool OpenSpaceEngine::initialize() { LERROR("Error loading leap second kernel '" << leapSecondKernel << "'"); return false; } - - //// metakernel loading doesnt seem to work... it should. to tired to even - //// CK - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/ck/merged_nhpc_2006_v011.bc"); - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/ck/merged_nhpc_2007_v006.bc"); - //// FK - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/fk/nh_v200.tf"); - //// IK - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/ik/nh_lorri_v100.ti"); - //// LSK already loaded - ////PCK - ////SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/pck/pck00008.tpc"); - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/pck/new_horizons_413.tsc"); - ////SPK - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/de413.bsp"); - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/jup260.bsp"); - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/nh_nep_ura_000.bsp"); - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/nh_recon_e2j_v1.bsp"); - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/nh_recon_j2sep07_prelimv1.bsp"); - //SpiceManager::ref().loadKernel("${OPENSPACE_DATA}/spice/JupiterNhKernels/spk/sb_2002jf56_2.bsp"); - + FactoryManager::initialize(); scriptEngine().initialize(); diff --git a/src/rendering/planets/renderableplanetprojection.cpp b/src/rendering/planets/renderableplanetprojection.cpp index 1f68854daf..0d6953d808 100644 --- a/src/rendering/planets/renderableplanetprojection.cpp +++ b/src/rendering/planets/renderableplanetprojection.cpp @@ -51,6 +51,7 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& , _colorTexturePath("colorTexture", "Color Texture") , _projectionTexturePath("colorTexture", "Color Texture") , _programObject(nullptr) + , _writeToTextureProgramObject(nullptr) , _texture(nullptr) , _textureProj(nullptr) , _geometry(nullptr) @@ -102,6 +103,9 @@ bool RenderablePlanetProjection::initialize(){ if (_programObject == nullptr) completeSuccess &= OsEng.ref().configurationManager().getValue("projectiveProgram", _programObject); + if (_writeToTextureProgramObject == nullptr) + completeSuccess + &= OsEng.ref().configurationManager().getValue("writeToTextureProgram", _writeToTextureProgramObject); loadTexture(); completeSuccess &= (_texture != nullptr); @@ -195,18 +199,37 @@ void RenderablePlanetProjection::render(const RenderData& data) ghoul::opengl::TextureUnit unit; unit.activate(); _texture->bind(); - _programObject->setUniform("texture1", unit); + _programObject->setUniform("texture1", unit); // jupiter ghoul::opengl::TextureUnit unit2; unit2.activate(); _textureProj->bind(); - _programObject->setUniform("texture2", unit2); + _programObject->setUniform("texture2", unit2); // proj // render _geometry->render(); // disable shader _programObject->deactivate(); + + /* + fbo.activate(); + //glViewport(0, 0, 1024, 1024); + _writeToTextureProgramObject->activate(); + GLfloat vertices[] = { -1, -1, 0, // bottom left corner + -1, 1, 0, // top left corner + 1, 1, 0, // top right corner + 1, -1, 0 }; // bottom right corner + + GLubyte indices[] = { 0, 1, 2, // first triangle (bottom left - top left - top right) + 0, 2, 3 }; // second triangle (bottom left - top right - bottom right) + + glVertexPointer(3, GL_FLOAT, 0, vertices); + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices); + + _writeToTextureProgramObject->deactivate(); + fbo.deactivate(); + */ } void RenderablePlanetProjection::update(const UpdateData& data){ @@ -229,8 +252,13 @@ void RenderablePlanetProjection::loadTexture() // Textures of planets looks much smoother with AnisotropicMipMap rather than linear _texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); + fbo.activate(); + fbo.attachTexture(_texture, GL_COLOR_ATTACHMENT0, 0, 0); + fbo.deactivate(); } } + + delete _textureProj; _textureProj = nullptr; if (_colorTexturePath.value() != "") { diff --git a/src/rendering/planets/writeToTexture.cpp b/src/rendering/planets/writeToTexture.cpp new file mode 100644 index 0000000000..2cf4d1dc23 --- /dev/null +++ b/src/rendering/planets/writeToTexture.cpp @@ -0,0 +1,179 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014 * +* * +* 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 + +namespace { +const std::string _loggerCat = "RenderablePlanet"; +} + +namespace openspace { + +RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _colorTexturePath("colorTexture", "Color Texture") + , _programObject(nullptr) + , _texture(nullptr) + , _geometry(nullptr) +{ + std::string name; + bool success = dictionary.getValue(constants::scenegraphnode::keyName, name); + assert(success); + + std::string path; + success = dictionary.getValue(constants::scenegraph::keyPathModule, path); + assert(success); + + ghoul::Dictionary geometryDictionary; + success = dictionary.getValue( + constants::renderableplanet::keyGeometry, geometryDictionary); + if (success) { + geometryDictionary.setValue(constants::scenegraphnode::keyName, name); + geometryDictionary.setValue(constants::scenegraph::keyPathModule, path); + _geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary); + } + + dictionary.getValue(constants::renderableplanet::keyFrame, _target); + + // TODO: textures need to be replaced by a good system similar to the geometry as soon + // as the requirements are fixed (ab) + std::string texturePath = ""; + success = dictionary.getValue("Textures.Color", texturePath); + if (success) + _colorTexturePath = path + "/" + texturePath; + + addPropertySubOwner(_geometry); + + addProperty(_colorTexturePath); + _colorTexturePath.onChange(std::bind(&RenderablePlanet::loadTexture, this)); +} + +RenderablePlanet::~RenderablePlanet(){ + deinitialize(); +} + +bool RenderablePlanet::initialize(){ + bool completeSuccess = true; + if (_programObject == nullptr) + completeSuccess + &= OsEng.ref().configurationManager().getValue("pscShader", _programObject); + + loadTexture(); + completeSuccess &= (_texture != nullptr); + completeSuccess &= _geometry->initialize(this); + + return completeSuccess; +} + +bool RenderablePlanet::deinitialize(){ + _geometry->deinitialize(); + delete _geometry; + _geometry = nullptr; + delete _texture; + _texture = nullptr; + return true; +} + +void RenderablePlanet::render(const RenderData& data) +{ + if (!_programObject) return; + if (!_texture) return; + + // 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, 90.f, glm::vec3(1, 0, 0)); + + for (int i = 0; i < 3; i++){ + for (int j = 0; j < 3; j++){ + transform[i][j] = _stateMatrix[i][j]; + } + } + transform = transform* rot; + if (_target == "IAU_JUPITER"){ //x = 0.935126 + transform *= glm::scale(glm::mat4(1), glm::vec3(1, 0.93513, 1)); + } + + + glm::mat4 modelview = data.camera.viewMatrix()*data.camera.modelMatrix(); + glm::vec3 camSpaceEye = (-(modelview*data.position.vec4())).xyz; + + // setup the data to the shader +// _programObject->setUniform("camdir", camSpaceEye); + _programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); + _programObject->setUniform("ModelTransform", transform); + setPscUniforms(_programObject, &data.camera, data.position); + + // Bind texture + ghoul::opengl::TextureUnit unit; + unit.activate(); + _texture->bind(); + _programObject->setUniform("texture1", unit); + + // render + _geometry->render(); + + // disable shader + _programObject->deactivate(); +} + +void RenderablePlanet::update(const UpdateData& data){ + // set spice-orientation in accordance to timestamp + openspace::SpiceManager::ref().getPositionTransformMatrix(_target, "GALACTIC", data.time, _stateMatrix); +} + +void RenderablePlanet::loadTexture() +{ + delete _texture; + _texture = nullptr; + if (_colorTexturePath.value() != "") { + _texture = ghoul::opengl::loadTexture(absPath(_colorTexturePath)); + if (_texture) { + LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'"); + _texture->uploadTexture(); + + // Textures of planets looks much smoother with AnisotropicMipMap rather than linear + _texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); + } + } +} + +} // namespace openspace diff --git a/src/rendering/renderabletrail.cpp b/src/rendering/renderabletrail.cpp index 4365159cea..585b4eef86 100644 --- a/src/rendering/renderabletrail.cpp +++ b/src/rendering/renderabletrail.cpp @@ -164,7 +164,6 @@ void RenderableTrail::sendToGPU(){ glBindVertexArray(0); } - bool RenderableTrail::initialize(){ bool completeSuccess = true; if (_programObject == nullptr) @@ -176,7 +175,7 @@ bool RenderableTrail::initialize(){ completeSuccess &= (_texture != nullptr); _startTrail; - SpiceManager::ref().getETfromDate("2007 feb 28 11:48:00.000", _startTrail); + SpiceManager::ref().getETfromDate("2007 feb 26 17:38:00.000", _startTrail); _dtEt = _startTrail; fullYearSweep(); diff --git a/src/scenegraph/scenegraph.cpp b/src/scenegraph/scenegraph.cpp index b70e09bf60..c9d07a7a95 100644 --- a/src/scenegraph/scenegraph.cpp +++ b/src/scenegraph/scenegraph.cpp @@ -169,6 +169,15 @@ bool SceneGraph::initialize() typedef std::chrono::duration > second_; std::chrono::time_point beginning(clock_::now()); + // pscstandard + tmpProgram = ProgramObject::Build("writeToTextureProgram", + "${SHADERS}/writeToTexture_vs.glsl", + "${SHADERS}/writeToTexture_fs.glsl", + cb); + if (!tmpProgram) return false; + _programs.push_back(tmpProgram); + OsEng.ref().configurationManager().setValue("writeToTextureProgram", tmpProgram); + // pscstandard tmpProgram = ProgramObject::Build("projectiveProgram", "${SHADERS}/projectiveTexture_vs.glsl", diff --git a/src/util/powerscaledsphere.cpp b/src/util/powerscaledsphere.cpp index 338ba864ae..67947462bb 100644 --- a/src/util/powerscaledsphere.cpp +++ b/src/util/powerscaledsphere.cpp @@ -85,7 +85,6 @@ PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segmen _varray[nr].normal[1] = normal[1]; _varray[nr].normal[2] = normal[2]; - //std::cout << _varray[nr].location[0] << " " << _varray[nr].location[1] << " " << _varray[nr].location[2] << " " << _varray[nr].location[3] << std::endl; _varray[nr].tex[0] = t1; _varray[nr].tex[1] = t2; ++nr;