diff --git a/data/scene/default.scene b/data/scene/default.scene index dfd83d1e6c..ff8ede83e2 100644 --- a/data/scene/default.scene +++ b/data/scene/default.scene @@ -77,7 +77,11 @@ function postInitialization() openspace.setPropertyValue("SunGlare.renderable.Enabled", false) openspace.setPropertyValue("SunMarker.renderable.Enabled", false) - + + -- DU Objects + openspace.setPropertyValue("Quasars.renderable.Enabled", false) + openspace.setPropertyValue("WMAP.renderable.Enabled", false) + openspace.setPropertyValue("Constellation Bounds.renderable.Enabled", false) openspace.setPropertyValue("Earth.RenderableGlobe.Atmosphere", true) @@ -111,7 +115,7 @@ return { "mercury", "venus", "earth", - "moon", + --"moon", "mars", "jupiter", "saturn", @@ -123,7 +127,9 @@ return { --"milkyway/eso", -- "satellites" "constellationbounds", - "grids" + "grids", + "quasars/digitaluniverse", + "backgroundradiation/digitaluniverse" } } diff --git a/ext/sgct b/ext/sgct index 34d3ebb4dd..d6e251c4b2 160000 --- a/ext/sgct +++ b/ext/sgct @@ -1 +1 @@ -Subproject commit 34d3ebb4ddae8524f512af12df943bd2aa058f46 +Subproject commit d6e251c4b25f286b6da315d1a461f313a5491c44 diff --git a/modules/digitaluniverse/CMakeLists.txt b/modules/digitaluniverse/CMakeLists.txt new file mode 100644 index 0000000000..4b22e65e5a --- /dev/null +++ b/modules/digitaluniverse/CMakeLists.txt @@ -0,0 +1,56 @@ +########################################################################################## +# # +# OpenSpace # +# # +# Copyright (c) 2014-2017 # +# # +# 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(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) + +set(HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepointssprite.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepoints.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabledumeshes.h +) +source_group("Header Files" FILES ${HEADER_FILES}) + +set(SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepointssprite.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepoints.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderabledumeshes.cpp +) +source_group("Source Files" FILES ${SOURCE_FILES}) + +set(SHADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/pointssprite_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/pointssprite_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/points_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/points_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/dumesh_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/dumesh_fs.glsl +) +source_group("Shader Files" FILES ${SHADER_FILES}) + +create_new_module( + "DigitalUniverse" + digitaluniverse_module + STATIC + ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} +) diff --git a/modules/digitaluniverse/digitaluniversemodule.cpp b/modules/digitaluniverse/digitaluniversemodule.cpp new file mode 100644 index 0000000000..234afa704a --- /dev/null +++ b/modules/digitaluniverse/digitaluniversemodule.cpp @@ -0,0 +1,60 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * 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 +#include +#include + +#include + +#include +//#include +#include + +#include + +namespace openspace { + +DigitalUniverseModule::DigitalUniverseModule() : OpenSpaceModule(DigitalUniverseModule::Name) {} + +void DigitalUniverseModule::internalInitialize() { + auto fRenderable = FactoryManager::ref().factory(); + ghoul_assert(fRenderable, "Renderable factory was not created"); + + fRenderable->registerClass("RenderablePoints"); + //fRenderable->registerClass("RenderablePointsSprite"); + fRenderable->registerClass("RenderableDUMeshes"); +} + +std::vector DigitalUniverseModule::documentations() const { + return { + RenderablePoints::Documentation() + //RenderablePointsSprinte::Documentation() + }; +} + +} // namespace openspace diff --git a/modules/digitaluniverse/digitaluniversemodule.h b/modules/digitaluniverse/digitaluniversemodule.h new file mode 100644 index 0000000000..681374ba86 --- /dev/null +++ b/modules/digitaluniverse/digitaluniversemodule.h @@ -0,0 +1,46 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * 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 __OPENSPACE_MODULE_DIGITALUNIVERSE___DIGITALUNIVERSEMODULE___H__ +#define __OPENSPACE_MODULE_DIGITALUNIVERSE___DIGITALUNIVERSEMODULE___H__ + +#include + +namespace openspace { + +class DigitalUniverseModule : public OpenSpaceModule { +public: + constexpr static const char* Name = "DigitalUniverse"; + + DigitalUniverseModule(); + virtual ~DigitalUniverseModule() = default; + std::vector documentations() const override; + +protected: + void internalInitialize() override; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___DIGITALUNIVERSEMODULE___H__ diff --git a/modules/digitaluniverse/include.cmake b/modules/digitaluniverse/include.cmake new file mode 100644 index 0000000000..3d5ca687a5 --- /dev/null +++ b/modules/digitaluniverse/include.cmake @@ -0,0 +1 @@ +set(DEFAULT_MODULE OFF) diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp new file mode 100644 index 0000000000..989419d76b --- /dev/null +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -0,0 +1,503 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace { + const char* _loggerCat = "RenderablePoints"; + const char* KeyFile = "File"; + const char* keyColor = "Color"; + const char* keyUnit = "Unit"; + const char* MeterUnit = "m"; + const char* KilometerUnit = "Km"; + const char* ParsecUnit = "pc"; + const char* KiloparsecUnit = "Kpc"; + const char* MegaparsecUnit = "Mpc"; + const char* GigaparsecUnit = "Gpc"; + const char* GigalightyearUnit = "Gly"; + + const int8_t CurrentCacheVersion = 1; + const double PARSEC = 0.308567756E17; + + static const openspace::properties::Property::PropertyInfo TransparencyInfo = { + "Transparency", + "Transparency", + "This value is a multiplicative factor that is applied to the transparency of " + "all point." + }; + + static const openspace::properties::Property::PropertyInfo ScaleFactorInfo = { + "ScaleFactor", + "Scale Factor", + "This value is used as a multiplicative factor that is applied to the apparent " + "size of each point." + }; + + static const openspace::properties::Property::PropertyInfo ColorInfo = { + "Color", + "Color", + "This value is used to define the color of the astronomical object." + }; +} // namespace + +namespace openspace { + + documentation::Documentation RenderableDUMeshes::Documentation() { + using namespace documentation; + return { + "RenderablePoints", + "digitaluniverse_renderablepoints", + { + { + "Type", + new StringEqualVerifier("RenderablePoints"), + Optional::No + }, + { + KeyFile, + new StringVerifier, + Optional::No, + "The path to the SPECK file that contains information about the astronomical " + "object being rendered." + }, + { + keyColor, + new Vector3Verifier, + Optional::No, + "Astronomical Object Color (r,g,b)." + }, + { + TransparencyInfo.identifier, + new DoubleVerifier, + Optional::Yes, + TransparencyInfo.description + }, + { + ScaleFactorInfo.identifier, + new DoubleVerifier, + Optional::Yes, + ScaleFactorInfo.description + } + } + }; + } + + + RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _dataIsDirty(true) + , _alphaValue(TransparencyInfo, 1.f, 0.f, 1.f) + , _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 64.f) + , _pointColor(ColorInfo, glm::vec3(1.f, 0.4f, 0.2f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.0f, 1.0f, 1.0f)) + , _program(nullptr) + , _speckFile("") + , _unit(Parsec) + , _nValuesPerAstronomicalObject(0) + , _vao(0) + , _vbo(0) + { + using File = ghoul::filesystem::File; + + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "RenderableDUMeshes" + ); + + _speckFile = absPath(dictionary.value(KeyFile)); + + + if (dictionary.hasKey(keyUnit)) { + std::string unit = dictionary.value(keyUnit); + if (unit == MeterUnit) { + _unit = Meter; + } + else if (unit == KilometerUnit) { + _unit = Kilometer; + } + else if (unit == ParsecUnit) { + _unit = Parsec; + } + else if (unit == KiloparsecUnit) { + _unit = Kiloparsec; + } + else if (unit == MegaparsecUnit) { + _unit = Megaparsec; + } + else if (unit == GigaparsecUnit) { + _unit = Gigaparsec; + } + else if (unit == GigalightyearUnit) { + _unit = GigalightYears; + } + else { + LWARNING("No unit given for RenderableDUMeshes. Using meters as units."); + _unit = Meter; + } + } + + if (dictionary.hasKey(keyColor)) { + _pointColor = dictionary.value(keyColor); + } + addProperty(_pointColor); + + if (dictionary.hasKey(TransparencyInfo.identifier)) { + _alphaValue = static_cast( + dictionary.value(TransparencyInfo.identifier) + ); + } + addProperty(_alphaValue); + + if (dictionary.hasKey(ScaleFactorInfo.identifier)) { + _scaleFactor = static_cast( + dictionary.value(ScaleFactorInfo.identifier) + ); + } + addProperty(_scaleFactor); + + } + + bool RenderableDUMeshes::isReady() const { + return (_program != nullptr) && (!_fullData.empty()); + } + + void RenderableDUMeshes::initialize() { + RenderEngine& renderEngine = OsEng.renderEngine(); + _program = renderEngine.buildRenderProgram("RenderableDUMeshes", + "${MODULE_DIGITALUNIVERSE}/shaders/points_vs.glsl", + "${MODULE_DIGITALUNIVERSE}/shaders/points_fs.glsl");// , + //"${MODULE_DIGITALUNIVERSE}/shaders/points_ge.glsl"); + + bool success = loadData(); + if (!success) { + throw ghoul::RuntimeError("Error loading data"); + } + } + + void RenderableDUMeshes::deinitialize() { + glDeleteBuffers(1, &_vbo); + _vbo = 0; + glDeleteVertexArrays(1, &_vao); + _vao = 0; + + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_program) { + renderEngine.removeRenderProgram(_program); + _program = nullptr; + } + } + + void RenderableDUMeshes::render(const RenderData& data, RendererTasks&) { + glDepthMask(false); + _program->activate(); + + glm::dmat4 modelMatrix = glm::dmat4(1.0); + + using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; + _program->setIgnoreUniformLocationError(IgnoreError::Yes); + _program->setUniform("modelViewProjectionTransform", glm::dmat4(data.camera.projectionMatrix()) * + data.camera.combinedViewMatrix() * modelMatrix); + + _program->setUniform("color", _pointColor); + _program->setUniform("alphaValue", _alphaValue); + _program->setUniform("scaleFactor", _scaleFactor); + + //setPscUniforms(*_program.get(), data.camera, data.position); + //_program->setUniform("scaling", scaling); + + + glEnable(GL_PROGRAM_POINT_SIZE); + glBindVertexArray(_vao); + const GLsizei nAstronomicalObjects = static_cast(_fullData.size() / _nValuesPerAstronomicalObject); + glDrawArrays(GL_POINTS, 0, nAstronomicalObjects); + + glDisable(GL_PROGRAM_POINT_SIZE); + glBindVertexArray(0); + using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; + _program->setIgnoreUniformLocationError(IgnoreError::No); + _program->deactivate(); + + glDepthMask(true); + } + + void RenderableDUMeshes::update(const UpdateData&) { + if (_dataIsDirty) { + LDEBUG("Regenerating data"); + + createDataSlice(); + + int size = static_cast(_slicedData.size()); + + if (_vao == 0) { + glGenVertexArrays(1, &_vao); + LDEBUG("Generating Vertex Array id '" << _vao << "'"); + } + if (_vbo == 0) { + glGenBuffers(1, &_vbo); + LDEBUG("Generating Vertex Buffer Object id '" << _vbo << "'"); + } + glBindVertexArray(_vao); + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glBufferData( + GL_ARRAY_BUFFER, + size * sizeof(double), + &_slicedData[0], + GL_STATIC_DRAW + ); + + GLint positionAttrib = _program->attributeLocation("in_position"); + + const size_t nAstronomicalObjects = _fullData.size() / _nValuesPerAstronomicalObject; + const size_t nValues = _slicedData.size() / nAstronomicalObjects; + + GLsizei stride = static_cast(sizeof(double) * nValues); + + glEnableVertexAttribArray(positionAttrib); + glVertexAttribLPointer( + positionAttrib, + 4, + GL_DOUBLE, + 0, + nullptr + ); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + + _dataIsDirty = false; + } + } + + bool RenderableDUMeshes::loadData() { + std::string _file = _speckFile; + std::string cachedFile = FileSys.cacheManager()->cachedFilename( + _file, + ghoul::filesystem::CacheManager::Persistent::Yes + ); + + bool hasCachedFile = FileSys.fileExists(cachedFile); + if (hasCachedFile) { + LINFO("Cached file '" << cachedFile << "' used for Speck file '" << _file << "'"); + + bool success = loadCachedFile(cachedFile); + if (success) { + return true; + } + else { + FileSys.cacheManager()->removeCacheFile(_file); + // Intentional fall-through to the 'else' computation to generate the cache + // file for the next run + } + } + else { + LINFO("Cache for Speck file '" << _file << "' not found"); + } + LINFO("Loading Speck file '" << _file << "'"); + + bool success = readSpeckFile(); + if (!success) { + return false; + } + + LINFO("Saving cache"); + success = saveCachedFile(cachedFile); + + return success; + } + + bool RenderableDUMeshes::readSpeckFile() { + std::string _file = _speckFile; + std::ifstream file(_file); + if (!file.good()) { + LERROR("Failed to open Speck file '" << _file << "'"); + return false; + } + + _nValuesPerAstronomicalObject = 0; + + // The beginning of the speck file has a header that either contains comments + // (signaled by a preceding '#') or information about the structure of the file + // (signaled by the keywords 'datavar', 'texturevar', and 'texture') + std::string line = ""; + while (true) { + std::streampos position = file.tellg(); + std::getline(file, line); + + if (line[0] == '#' || line.empty()) { + continue; + } + + if (line.substr(0, 7) != "datavar" && + line.substr(0, 10) != "texturevar" && + line.substr(0, 7) != "texture") + { + // we read a line that doesn't belong to the header, so we have to jump back + // before the beginning of the current line + file.seekg(position); + break; + } + + if (line.substr(0, 7) == "datavar") { + // datavar lines are structured as follows: + // datavar # description + // where # is the index of the data variable; so if we repeatedly overwrite + // the 'nValues' variable with the latest index, we will end up with the total + // number of values (+3 since X Y Z are not counted in the Speck file index) + std::stringstream str(line); + + std::string dummy; + str >> dummy; + str >> _nValuesPerAstronomicalObject; + _nValuesPerAstronomicalObject += 1; // We want the number, but the index is 0 based + } + } + + _nValuesPerAstronomicalObject += 3; // X Y Z are not counted in the Speck file indices + + do { + std::vector values(_nValuesPerAstronomicalObject); + + std::getline(file, line); + std::stringstream str(line); + + for (int i = 0; i < _nValuesPerAstronomicalObject; ++i) { + str >> values[i]; + } + + _fullData.insert(_fullData.end(), values.begin(), values.end()); + } while (!file.eof()); + + return true; + } + + bool RenderableDUMeshes::loadCachedFile(const std::string& file) { + std::ifstream fileStream(file, std::ifstream::binary); + if (fileStream.good()) { + int8_t version = 0; + fileStream.read(reinterpret_cast(&version), sizeof(int8_t)); + if (version != CurrentCacheVersion) { + LINFO("The format of the cached file has changed: deleting old cache"); + fileStream.close(); + FileSys.deleteFile(file); + return false; + } + + int32_t nValues = 0; + fileStream.read(reinterpret_cast(&nValues), sizeof(int32_t)); + fileStream.read(reinterpret_cast(&_nValuesPerAstronomicalObject), sizeof(int32_t)); + + _fullData.resize(nValues); + fileStream.read(reinterpret_cast(&_fullData[0]), + nValues * sizeof(_fullData[0])); + + bool success = fileStream.good(); + return success; + } + else { + LERROR("Error opening file '" << file << "' for loading cache file"); + return false; + } + } + + bool RenderableDUMeshes::saveCachedFile(const std::string& file) const { + std::ofstream fileStream(file, std::ofstream::binary); + if (fileStream.good()) { + fileStream.write(reinterpret_cast(&CurrentCacheVersion), + sizeof(int8_t)); + + int32_t nValues = static_cast(_fullData.size()); + if (nValues == 0) { + LERROR("Error writing cache: No values were loaded"); + return false; + } + fileStream.write(reinterpret_cast(&nValues), sizeof(int32_t)); + + int32_t nValuesPerAstronomicalObject = static_cast(_nValuesPerAstronomicalObject); + fileStream.write(reinterpret_cast(&nValuesPerAstronomicalObject), sizeof(int32_t)); + + size_t nBytes = nValues * sizeof(_fullData[0]); + fileStream.write(reinterpret_cast(&_fullData[0]), nBytes); + + bool success = fileStream.good(); + return success; + } + else { + LERROR("Error opening file '" << file << "' for save cache file"); + return false; + } + } + + void RenderableDUMeshes::createDataSlice() { + _slicedData.clear(); + + for (size_t i = 0; i < _fullData.size(); i += _nValuesPerAstronomicalObject) { + glm::dvec3 p = glm::dvec3(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2]); + + // Converting untis + if (_unit == Kilometer) { + p *= 1E3; + } + else if (_unit == Parsec) { + p *= PARSEC; + } + else if (_unit == Kiloparsec) { + p *= 1E3 * PARSEC; + } + else if (_unit == Megaparsec) { + p *= 1E6 * PARSEC; + } + else if (_unit == Gigaparsec) { + p *= 1E9 * PARSEC; + } + else if (_unit == GigalightYears) { + p *= 306391534.73091 * PARSEC; + } + + glm::dvec4 position(p, 1.0); + + for (auto j = 0; j < 4; ++j) { + _slicedData.push_back(position[j]); + } + } + } + + +} // namespace openspace diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.h b/modules/digitaluniverse/rendering/renderabledumeshes.h new file mode 100644 index 0000000000..f941de6c7f --- /dev/null +++ b/modules/digitaluniverse/rendering/renderabledumeshes.h @@ -0,0 +1,110 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * 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 __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEDUMESHES___H__ +#define __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEDUMESHES___H__ + +#include + +#include +#include +#include +#include +#include + +#include + +namespace ghoul::filesystem { + class File; +} + +namespace ghoul::opengl { + class ProgramObject; + class Texture; +} // namespace ghoul::opengl + +namespace openspace { + + namespace documentation { struct Documentation; } + + class RenderableDUMeshes : public Renderable { + public: + explicit RenderableDUMeshes(const ghoul::Dictionary& dictionary); + ~RenderableDUMeshes() = default; + + void initialize() override; + void deinitialize() override; + + bool isReady() const override; + + void render(const RenderData& data, RendererTasks& rendererTask) override; + void update(const UpdateData& data) override; + + static documentation::Documentation Documentation(); + + private: + + enum Unit { + Meter = 0, + Kilometer = 1, + Parsec = 2, + Kiloparsec = 3, + Megaparsec = 4, + Gigaparsec = 5, + + GigalightYears = 6 + }; + + void createDataSlice(); + + bool loadData(); + bool readSpeckFile(); + bool loadCachedFile(const std::string& file); + bool saveCachedFile(const std::string& file) const; + + bool _dataIsDirty; + + properties::FloatProperty _alphaValue; + properties::FloatProperty _scaleFactor; + properties::Vec3Property _pointColor; + + + std::unique_ptr _program; + + std::string _speckFile; + + Unit _unit; + + std::vector _slicedData; + std::vector _fullData; + int _nValuesPerAstronomicalObject; + + GLuint _vao; + GLuint _vbo; + }; + + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEDUMESHES___H__ diff --git a/modules/digitaluniverse/rendering/renderablepoints.cpp b/modules/digitaluniverse/rendering/renderablepoints.cpp new file mode 100644 index 0000000000..3896c54c54 --- /dev/null +++ b/modules/digitaluniverse/rendering/renderablepoints.cpp @@ -0,0 +1,503 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace { + const char* _loggerCat = "RenderablePoints"; + const char* KeyFile = "File"; + const char* keyColor = "Color"; + const char* keyUnit = "Unit"; + const char* MeterUnit = "m"; + const char* KilometerUnit = "Km"; + const char* ParsecUnit = "pc"; + const char* KiloparsecUnit = "Kpc"; + const char* MegaparsecUnit = "Mpc"; + const char* GigaparsecUnit = "Gpc"; + const char* GigalightyearUnit = "Gly"; + + const int8_t CurrentCacheVersion = 1; + const double PARSEC = 0.308567756E17; + + static const openspace::properties::Property::PropertyInfo TransparencyInfo = { + "Transparency", + "Transparency", + "This value is a multiplicative factor that is applied to the transparency of " + "all point." + }; + + static const openspace::properties::Property::PropertyInfo ScaleFactorInfo = { + "ScaleFactor", + "Scale Factor", + "This value is used as a multiplicative factor that is applied to the apparent " + "size of each point." + }; + + static const openspace::properties::Property::PropertyInfo ColorInfo = { + "Color", + "Color", + "This value is used to define the color of the astronomical object." + }; +} // namespace + +namespace openspace { + + documentation::Documentation RenderablePoints::Documentation() { + using namespace documentation; + return { + "RenderablePoints", + "digitaluniverse_renderablepoints", + { + { + "Type", + new StringEqualVerifier("RenderablePoints"), + Optional::No + }, + { + KeyFile, + new StringVerifier, + Optional::No, + "The path to the SPECK file that contains information about the astronomical " + "object being rendered." + }, + { + keyColor, + new Vector3Verifier, + Optional::No, + "Astronomical Object Color (r,g,b)." + }, + { + TransparencyInfo.identifier, + new DoubleVerifier, + Optional::Yes, + TransparencyInfo.description + }, + { + ScaleFactorInfo.identifier, + new DoubleVerifier, + Optional::Yes, + ScaleFactorInfo.description + } + } + }; + } + + + RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _dataIsDirty(true) + , _alphaValue(TransparencyInfo, 1.f, 0.f, 1.f) + , _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 64.f) + , _pointColor(ColorInfo, glm::vec3(1.f, 0.4f, 0.2f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.0f, 1.0f, 1.0f)) + , _program(nullptr) + , _speckFile("") + , _unit(Parsec) + , _nValuesPerAstronomicalObject(0) + , _vao(0) + , _vbo(0) + { + using File = ghoul::filesystem::File; + + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "RenderablePoints" + ); + + _speckFile = absPath(dictionary.value(KeyFile)); + + + if (dictionary.hasKey(keyUnit)) { + std::string unit = dictionary.value(keyUnit); + if (unit == MeterUnit) { + _unit = Meter; + } + else if (unit == KilometerUnit) { + _unit = Kilometer; + } + else if (unit == ParsecUnit) { + _unit = Parsec; + } + else if (unit == KiloparsecUnit) { + _unit = Kiloparsec; + } + else if (unit == MegaparsecUnit) { + _unit = Megaparsec; + } + else if (unit == GigaparsecUnit) { + _unit = Gigaparsec; + } + else if (unit == GigalightyearUnit) { + _unit = GigalightYears; + } + else { + LWARNING("No unit given for RenderablePoints. Using meters as units."); + _unit = Meter; + } + } + + if (dictionary.hasKey(keyColor)) { + _pointColor = dictionary.value(keyColor); + } + addProperty(_pointColor); + + if (dictionary.hasKey(TransparencyInfo.identifier)) { + _alphaValue = static_cast( + dictionary.value(TransparencyInfo.identifier) + ); + } + addProperty(_alphaValue); + + if (dictionary.hasKey(ScaleFactorInfo.identifier)) { + _scaleFactor = static_cast( + dictionary.value(ScaleFactorInfo.identifier) + ); + } + addProperty(_scaleFactor); + + } + + bool RenderablePoints::isReady() const { + return (_program != nullptr) && (!_fullData.empty()); + } + + void RenderablePoints::initialize() { + RenderEngine& renderEngine = OsEng.renderEngine(); + _program = renderEngine.buildRenderProgram("RenderablePoints", + "${MODULE_DIGITALUNIVERSE}/shaders/points_vs.glsl", + "${MODULE_DIGITALUNIVERSE}/shaders/points_fs.glsl");// , + //"${MODULE_DIGITALUNIVERSE}/shaders/points_ge.glsl"); + + bool success = loadData(); + if (!success) { + throw ghoul::RuntimeError("Error loading data"); + } + } + + void RenderablePoints::deinitialize() { + glDeleteBuffers(1, &_vbo); + _vbo = 0; + glDeleteVertexArrays(1, &_vao); + _vao = 0; + + RenderEngine& renderEngine = OsEng.renderEngine(); + if (_program) { + renderEngine.removeRenderProgram(_program); + _program = nullptr; + } + } + + void RenderablePoints::render(const RenderData& data, RendererTasks&) { + glDepthMask(false); + _program->activate(); + + glm::dmat4 modelMatrix = glm::dmat4(1.0); + + using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; + _program->setIgnoreUniformLocationError(IgnoreError::Yes); + _program->setUniform("modelViewProjectionTransform", glm::dmat4(data.camera.projectionMatrix()) * + data.camera.combinedViewMatrix() * modelMatrix); + + _program->setUniform("color", _pointColor); + _program->setUniform("alphaValue", _alphaValue); + _program->setUniform("scaleFactor", _scaleFactor); + + //setPscUniforms(*_program.get(), data.camera, data.position); + //_program->setUniform("scaling", scaling); + + + glEnable(GL_PROGRAM_POINT_SIZE); + glBindVertexArray(_vao); + const GLsizei nAstronomicalObjects = static_cast(_fullData.size() / _nValuesPerAstronomicalObject); + glDrawArrays(GL_POINTS, 0, nAstronomicalObjects); + + glDisable(GL_PROGRAM_POINT_SIZE); + glBindVertexArray(0); + using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; + _program->setIgnoreUniformLocationError(IgnoreError::No); + _program->deactivate(); + + glDepthMask(true); + } + + void RenderablePoints::update(const UpdateData&) { + if (_dataIsDirty) { + LDEBUG("Regenerating data"); + + createDataSlice(); + + int size = static_cast(_slicedData.size()); + + if (_vao == 0) { + glGenVertexArrays(1, &_vao); + LDEBUG("Generating Vertex Array id '" << _vao << "'"); + } + if (_vbo == 0) { + glGenBuffers(1, &_vbo); + LDEBUG("Generating Vertex Buffer Object id '" << _vbo << "'"); + } + glBindVertexArray(_vao); + glBindBuffer(GL_ARRAY_BUFFER, _vbo); + glBufferData( + GL_ARRAY_BUFFER, + size * sizeof(double), + &_slicedData[0], + GL_STATIC_DRAW + ); + + GLint positionAttrib = _program->attributeLocation("in_position"); + + const size_t nAstronomicalObjects = _fullData.size() / _nValuesPerAstronomicalObject; + const size_t nValues = _slicedData.size() / nAstronomicalObjects; + + GLsizei stride = static_cast(sizeof(double) * nValues); + + glEnableVertexAttribArray(positionAttrib); + glVertexAttribLPointer( + positionAttrib, + 4, + GL_DOUBLE, + 0, + nullptr + ); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + + _dataIsDirty = false; + } + } + + bool RenderablePoints::loadData() { + std::string _file = _speckFile; + std::string cachedFile = FileSys.cacheManager()->cachedFilename( + _file, + ghoul::filesystem::CacheManager::Persistent::Yes + ); + + bool hasCachedFile = FileSys.fileExists(cachedFile); + if (hasCachedFile) { + LINFO("Cached file '" << cachedFile << "' used for Speck file '" << _file << "'"); + + bool success = loadCachedFile(cachedFile); + if (success) { + return true; + } + else { + FileSys.cacheManager()->removeCacheFile(_file); + // Intentional fall-through to the 'else' computation to generate the cache + // file for the next run + } + } + else { + LINFO("Cache for Speck file '" << _file << "' not found"); + } + LINFO("Loading Speck file '" << _file << "'"); + + bool success = readSpeckFile(); + if (!success) { + return false; + } + + LINFO("Saving cache"); + success = saveCachedFile(cachedFile); + + return success; + } + + bool RenderablePoints::readSpeckFile() { + std::string _file = _speckFile; + std::ifstream file(_file); + if (!file.good()) { + LERROR("Failed to open Speck file '" << _file << "'"); + return false; + } + + _nValuesPerAstronomicalObject = 0; + + // The beginning of the speck file has a header that either contains comments + // (signaled by a preceding '#') or information about the structure of the file + // (signaled by the keywords 'datavar', 'texturevar', and 'texture') + std::string line = ""; + while (true) { + std::streampos position = file.tellg(); + std::getline(file, line); + + if (line[0] == '#' || line.empty()) { + continue; + } + + if (line.substr(0, 7) != "datavar" && + line.substr(0, 10) != "texturevar" && + line.substr(0, 7) != "texture") + { + // we read a line that doesn't belong to the header, so we have to jump back + // before the beginning of the current line + file.seekg(position); + break; + } + + if (line.substr(0, 7) == "datavar") { + // datavar lines are structured as follows: + // datavar # description + // where # is the index of the data variable; so if we repeatedly overwrite + // the 'nValues' variable with the latest index, we will end up with the total + // number of values (+3 since X Y Z are not counted in the Speck file index) + std::stringstream str(line); + + std::string dummy; + str >> dummy; + str >> _nValuesPerAstronomicalObject; + _nValuesPerAstronomicalObject += 1; // We want the number, but the index is 0 based + } + } + + _nValuesPerAstronomicalObject += 3; // X Y Z are not counted in the Speck file indices + + do { + std::vector values(_nValuesPerAstronomicalObject); + + std::getline(file, line); + std::stringstream str(line); + + for (int i = 0; i < _nValuesPerAstronomicalObject; ++i) { + str >> values[i]; + } + + _fullData.insert(_fullData.end(), values.begin(), values.end()); + } while (!file.eof()); + + return true; + } + + bool RenderablePoints::loadCachedFile(const std::string& file) { + std::ifstream fileStream(file, std::ifstream::binary); + if (fileStream.good()) { + int8_t version = 0; + fileStream.read(reinterpret_cast(&version), sizeof(int8_t)); + if (version != CurrentCacheVersion) { + LINFO("The format of the cached file has changed: deleting old cache"); + fileStream.close(); + FileSys.deleteFile(file); + return false; + } + + int32_t nValues = 0; + fileStream.read(reinterpret_cast(&nValues), sizeof(int32_t)); + fileStream.read(reinterpret_cast(&_nValuesPerAstronomicalObject), sizeof(int32_t)); + + _fullData.resize(nValues); + fileStream.read(reinterpret_cast(&_fullData[0]), + nValues * sizeof(_fullData[0])); + + bool success = fileStream.good(); + return success; + } + else { + LERROR("Error opening file '" << file << "' for loading cache file"); + return false; + } + } + + bool RenderablePoints::saveCachedFile(const std::string& file) const { + std::ofstream fileStream(file, std::ofstream::binary); + if (fileStream.good()) { + fileStream.write(reinterpret_cast(&CurrentCacheVersion), + sizeof(int8_t)); + + int32_t nValues = static_cast(_fullData.size()); + if (nValues == 0) { + LERROR("Error writing cache: No values were loaded"); + return false; + } + fileStream.write(reinterpret_cast(&nValues), sizeof(int32_t)); + + int32_t nValuesPerAstronomicalObject = static_cast(_nValuesPerAstronomicalObject); + fileStream.write(reinterpret_cast(&nValuesPerAstronomicalObject), sizeof(int32_t)); + + size_t nBytes = nValues * sizeof(_fullData[0]); + fileStream.write(reinterpret_cast(&_fullData[0]), nBytes); + + bool success = fileStream.good(); + return success; + } + else { + LERROR("Error opening file '" << file << "' for save cache file"); + return false; + } + } + + void RenderablePoints::createDataSlice() { + _slicedData.clear(); + + for (size_t i = 0; i < _fullData.size(); i += _nValuesPerAstronomicalObject) { + glm::dvec3 p = glm::dvec3(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2]); + + // Converting untis + if (_unit == Kilometer) { + p *= 1E3; + } + else if (_unit == Parsec) { + p *= PARSEC; + } + else if (_unit == Kiloparsec) { + p *= 1E3 * PARSEC; + } + else if (_unit == Megaparsec) { + p *= 1E6 * PARSEC; + } + else if (_unit == Gigaparsec) { + p *= 1E9 * PARSEC; + } + else if (_unit == GigalightYears) { + p *= 306391534.73091 * PARSEC; + } + + glm::dvec4 position(p, 1.0); + + for (auto j = 0; j < 4; ++j) { + _slicedData.push_back(position[j]); + } + } + } + + +} // namespace openspace diff --git a/modules/digitaluniverse/rendering/renderablepoints.h b/modules/digitaluniverse/rendering/renderablepoints.h new file mode 100644 index 0000000000..07f83b8ae3 --- /dev/null +++ b/modules/digitaluniverse/rendering/renderablepoints.h @@ -0,0 +1,110 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * 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 __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEPOINTS___H__ +#define __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEPOINTS___H__ + +#include + +#include +#include +#include +#include +#include + +#include + +namespace ghoul::filesystem { + class File; +} + +namespace ghoul::opengl { + class ProgramObject; + class Texture; +} // namespace ghoul::opengl + +namespace openspace { + + namespace documentation { struct Documentation; } + + class RenderablePoints : public Renderable { + public: + explicit RenderablePoints(const ghoul::Dictionary& dictionary); + ~RenderablePoints() = default; + + void initialize() override; + void deinitialize() override; + + bool isReady() const override; + + void render(const RenderData& data, RendererTasks& rendererTask) override; + void update(const UpdateData& data) override; + + static documentation::Documentation Documentation(); + + private: + + enum Unit { + Meter = 0, + Kilometer = 1, + Parsec = 2, + Kiloparsec = 3, + Megaparsec = 4, + Gigaparsec = 5, + + GigalightYears = 6 + }; + + void createDataSlice(); + + bool loadData(); + bool readSpeckFile(); + bool loadCachedFile(const std::string& file); + bool saveCachedFile(const std::string& file) const; + + bool _dataIsDirty; + + properties::FloatProperty _alphaValue; + properties::FloatProperty _scaleFactor; + properties::Vec3Property _pointColor; + + + std::unique_ptr _program; + + std::string _speckFile; + + Unit _unit; + + std::vector _slicedData; + std::vector _fullData; + int _nValuesPerAstronomicalObject; + + GLuint _vao; + GLuint _vbo; + }; + + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEPOINTS___H__ diff --git a/modules/digitaluniverse/rendering/renderablepointssprite.cpp b/modules/digitaluniverse/rendering/renderablepointssprite.cpp new file mode 100644 index 0000000000..176e0a9ac0 --- /dev/null +++ b/modules/digitaluniverse/rendering/renderablepointssprite.cpp @@ -0,0 +1,76 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2017 * + * * + * 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 +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace { + enum BlendMode { + BlendModeNormal = 0, + BlendModeAdditive + }; + + static const openspace::properties::Property::PropertyInfo TextureInfo = { + "Texture", + "Texture", + "This value specifies an image that is loaded from disk and is used as a texture " + "that is applied to this plane. This image has to be square." + }; + + static const openspace::properties::Property::PropertyInfo BillboardInfo = { + "Billboard", + "Billboard mode", + "This value specifies whether the plane is a billboard, which means that it is " + "always facing the camera. If this is false, it can be oriented using other " + "transformations." + }; + + static const openspace::properties::Property::PropertyInfo SizeInfo = { + "Size", + "Size (in meters)", + "This value specifies the size of the plane in meters." + }; + + static const openspace::properties::Property::PropertyInfo BlendModeInfo = { + "BlendMode", + "Blending Mode", + "This determines the blending mode that is applied to this plane." + }; +} // namespace + +namespace openspace { + +} // namespace openspace diff --git a/modules/digitaluniverse/rendering/renderablepointssprite.h b/modules/digitaluniverse/rendering/renderablepointssprite.h new file mode 100644 index 0000000000..18b810d43d --- /dev/null +++ b/modules/digitaluniverse/rendering/renderablepointssprite.h @@ -0,0 +1,45 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2017 * +* * +* 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 __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEPOINTSSPRITE___H__ +#define __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEPOINTSSPRITE___H__ + +#include + +#include +#include +#include +#include + +#include + +namespace ghoul::filesystem { class File; } + +namespace ghoul::opengl { + class ProgramObject; + class Texture; +} // namespace ghoul::opengl + + +#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEPOINTSSPRITE___H__ diff --git a/modules/digitaluniverse/shaders/dumesh_fs.glsl b/modules/digitaluniverse/shaders/dumesh_fs.glsl new file mode 100644 index 0000000000..f8c0922ced --- /dev/null +++ b/modules/digitaluniverse/shaders/dumesh_fs.glsl @@ -0,0 +1,44 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 - 2017 * + * * + * 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 "fragment.glsl" + +in float vs_screenSpaceDepth; +flat in dvec4 test; + +uniform vec3 color; +uniform float alphaValue; + +Fragment getFragment() { + Fragment frag; + + if (alphaValue == 0.0) { + discard; + } + + frag.color = vec4(color, alphaValue); + frag.depth = vs_screenSpaceDepth; + + return frag; +} diff --git a/modules/digitaluniverse/shaders/dumesh_vs.glsl b/modules/digitaluniverse/shaders/dumesh_vs.glsl new file mode 100644 index 0000000000..a3b2f0e64b --- /dev/null +++ b/modules/digitaluniverse/shaders/dumesh_vs.glsl @@ -0,0 +1,48 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 - 2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version __CONTEXT__ + +#include "PowerScaling/powerScaling_vs.hglsl" + +in dvec4 in_position; + +uniform dmat4 modelViewProjectionTransform; +uniform float scaleFactor; + +out float vs_screenSpaceDepth; +out dvec4 test; + +void main() { + test = in_position; + vec4 positionClipSpace = vec4(modelViewProjectionTransform * in_position); + //positionClipSpace = vec4( modelViewProjectionTransform * + //vec4(0,0,0,1)); + vec4 positionScreenSpace = vec4(z_normalization(positionClipSpace)); + + vs_screenSpaceDepth = positionScreenSpace.w; + + gl_PointSize = scaleFactor; + gl_Position = positionScreenSpace; +} diff --git a/modules/digitaluniverse/shaders/points_fs.glsl b/modules/digitaluniverse/shaders/points_fs.glsl new file mode 100644 index 0000000000..f8c0922ced --- /dev/null +++ b/modules/digitaluniverse/shaders/points_fs.glsl @@ -0,0 +1,44 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 - 2017 * + * * + * 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 "fragment.glsl" + +in float vs_screenSpaceDepth; +flat in dvec4 test; + +uniform vec3 color; +uniform float alphaValue; + +Fragment getFragment() { + Fragment frag; + + if (alphaValue == 0.0) { + discard; + } + + frag.color = vec4(color, alphaValue); + frag.depth = vs_screenSpaceDepth; + + return frag; +} diff --git a/modules/digitaluniverse/shaders/points_vs.glsl b/modules/digitaluniverse/shaders/points_vs.glsl new file mode 100644 index 0000000000..a3b2f0e64b --- /dev/null +++ b/modules/digitaluniverse/shaders/points_vs.glsl @@ -0,0 +1,48 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 - 2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version __CONTEXT__ + +#include "PowerScaling/powerScaling_vs.hglsl" + +in dvec4 in_position; + +uniform dmat4 modelViewProjectionTransform; +uniform float scaleFactor; + +out float vs_screenSpaceDepth; +out dvec4 test; + +void main() { + test = in_position; + vec4 positionClipSpace = vec4(modelViewProjectionTransform * in_position); + //positionClipSpace = vec4( modelViewProjectionTransform * + //vec4(0,0,0,1)); + vec4 positionScreenSpace = vec4(z_normalization(positionClipSpace)); + + vs_screenSpaceDepth = positionScreenSpace.w; + + gl_PointSize = scaleFactor; + gl_Position = positionScreenSpace; +} diff --git a/modules/digitaluniverse/shaders/pointssprite_fs.glsl b/modules/digitaluniverse/shaders/pointssprite_fs.glsl new file mode 100644 index 0000000000..f0711af866 --- /dev/null +++ b/modules/digitaluniverse/shaders/pointssprite_fs.glsl @@ -0,0 +1,53 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 - 2017 * + * * + * 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 "fragment.glsl" + +in float vs_screenSpaceDepth; +in vec2 vs_st; + +uniform sampler2D texture1; +uniform bool additiveBlending; + + +Fragment getFragment() { + Fragment frag; + if (gl_FrontFacing) { + frag.color = texture(texture1, vs_st); + } + else { + frag.color = texture(texture1, vec2(1 - vs_st.s, vs_st.t)); + } + + if (frag.color.a == 0.0) { + discard; + } + + frag.depth = vs_screenSpaceDepth; + + if (additiveBlending) { + frag.blend = BLEND_MODE_ADDITIVE; + } + return frag; +} diff --git a/modules/digitaluniverse/shaders/pointssprite_vs.glsl b/modules/digitaluniverse/shaders/pointssprite_vs.glsl new file mode 100644 index 0000000000..10a044d23d --- /dev/null +++ b/modules/digitaluniverse/shaders/pointssprite_vs.glsl @@ -0,0 +1,48 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014 - 2017 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version __CONTEXT__ + +#include "PowerScaling/powerScaling_vs.hglsl" + +layout(location = 0) in vec4 in_position; +layout(location = 1) in vec2 in_st; + +out vec2 vs_st; +out float vs_screenSpaceDepth; +out vec4 vs_positionScreenSpace; + +uniform mat4 modelViewProjectionTransform; + + +void main() { + vec4 position = vec4(in_position.xyz * pow(10, in_position.w), 1); + vec4 positionClipSpace = modelViewProjectionTransform * position; + vec4 positionScreenSpace = z_normalization(positionClipSpace); + + gl_Position = positionScreenSpace; + + vs_st = in_st; + vs_screenSpaceDepth = positionScreenSpace.w; +}