mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
DU branch Quasar and WMAP.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
ext/sgct
2
ext/sgct
Submodule ext/sgct updated: 34d3ebb4dd...d6e251c4b2
56
modules/digitaluniverse/CMakeLists.txt
Normal file
56
modules/digitaluniverse/CMakeLists.txt
Normal file
@@ -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}
|
||||
)
|
||||
60
modules/digitaluniverse/digitaluniversemodule.cpp
Normal file
60
modules/digitaluniverse/digitaluniversemodule.cpp
Normal file
@@ -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 <modules/digitaluniverse/digitaluniversemodule.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
#include <ghoul/misc/assert.h>
|
||||
|
||||
#include <modules/digitaluniverse/rendering/renderablepoints.h>
|
||||
//#include <modules/digitaluniverse/rendering/renderablepointssprite.h>
|
||||
#include <modules/digitaluniverse/rendering/renderabledumeshes.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
DigitalUniverseModule::DigitalUniverseModule() : OpenSpaceModule(DigitalUniverseModule::Name) {}
|
||||
|
||||
void DigitalUniverseModule::internalInitialize() {
|
||||
auto fRenderable = FactoryManager::ref().factory<Renderable>();
|
||||
ghoul_assert(fRenderable, "Renderable factory was not created");
|
||||
|
||||
fRenderable->registerClass<RenderablePoints>("RenderablePoints");
|
||||
//fRenderable->registerClass<RenderablePointsSprite>("RenderablePointsSprite");
|
||||
fRenderable->registerClass<RenderableDUMeshes>("RenderableDUMeshes");
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation> DigitalUniverseModule::documentations() const {
|
||||
return {
|
||||
RenderablePoints::Documentation()
|
||||
//RenderablePointsSprinte::Documentation()
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
46
modules/digitaluniverse/digitaluniversemodule.h
Normal file
46
modules/digitaluniverse/digitaluniversemodule.h
Normal file
@@ -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 <openspace/util/openspacemodule.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class DigitalUniverseModule : public OpenSpaceModule {
|
||||
public:
|
||||
constexpr static const char* Name = "DigitalUniverse";
|
||||
|
||||
DigitalUniverseModule();
|
||||
virtual ~DigitalUniverseModule() = default;
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
|
||||
protected:
|
||||
void internalInitialize() override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___DIGITALUNIVERSEMODULE___H__
|
||||
1
modules/digitaluniverse/include.cmake
Normal file
1
modules/digitaluniverse/include.cmake
Normal file
@@ -0,0 +1 @@
|
||||
set(DEFAULT_MODULE OFF)
|
||||
503
modules/digitaluniverse/rendering/renderabledumeshes.cpp
Normal file
503
modules/digitaluniverse/rendering/renderabledumeshes.cpp
Normal file
@@ -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 <modules/digitaluniverse/rendering/renderabledumeshes.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
|
||||
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<float>,
|
||||
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<std::string>(KeyFile));
|
||||
|
||||
|
||||
if (dictionary.hasKey(keyUnit)) {
|
||||
std::string unit = dictionary.value<std::string>(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<glm::vec3>(keyColor);
|
||||
}
|
||||
addProperty(_pointColor);
|
||||
|
||||
if (dictionary.hasKey(TransparencyInfo.identifier)) {
|
||||
_alphaValue = static_cast<float>(
|
||||
dictionary.value<double>(TransparencyInfo.identifier)
|
||||
);
|
||||
}
|
||||
addProperty(_alphaValue);
|
||||
|
||||
if (dictionary.hasKey(ScaleFactorInfo.identifier)) {
|
||||
_scaleFactor = static_cast<float>(
|
||||
dictionary.value<double>(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<GLsizei>(_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<int>(_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<GLsizei>(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<float> 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<char*>(&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<char*>(&nValues), sizeof(int32_t));
|
||||
fileStream.read(reinterpret_cast<char*>(&_nValuesPerAstronomicalObject), sizeof(int32_t));
|
||||
|
||||
_fullData.resize(nValues);
|
||||
fileStream.read(reinterpret_cast<char*>(&_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<const char*>(&CurrentCacheVersion),
|
||||
sizeof(int8_t));
|
||||
|
||||
int32_t nValues = static_cast<int32_t>(_fullData.size());
|
||||
if (nValues == 0) {
|
||||
LERROR("Error writing cache: No values were loaded");
|
||||
return false;
|
||||
}
|
||||
fileStream.write(reinterpret_cast<const char*>(&nValues), sizeof(int32_t));
|
||||
|
||||
int32_t nValuesPerAstronomicalObject = static_cast<int32_t>(_nValuesPerAstronomicalObject);
|
||||
fileStream.write(reinterpret_cast<const char*>(&nValuesPerAstronomicalObject), sizeof(int32_t));
|
||||
|
||||
size_t nBytes = nValues * sizeof(_fullData[0]);
|
||||
fileStream.write(reinterpret_cast<const char*>(&_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
|
||||
110
modules/digitaluniverse/rendering/renderabledumeshes.h
Normal file
110
modules/digitaluniverse/rendering/renderabledumeshes.h
Normal file
@@ -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 <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
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<ghoul::opengl::ProgramObject> _program;
|
||||
|
||||
std::string _speckFile;
|
||||
|
||||
Unit _unit;
|
||||
|
||||
std::vector<double> _slicedData;
|
||||
std::vector<float> _fullData;
|
||||
int _nValuesPerAstronomicalObject;
|
||||
|
||||
GLuint _vao;
|
||||
GLuint _vbo;
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEDUMESHES___H__
|
||||
503
modules/digitaluniverse/rendering/renderablepoints.cpp
Normal file
503
modules/digitaluniverse/rendering/renderablepoints.cpp
Normal file
@@ -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 <modules/digitaluniverse/rendering/renderablepoints.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
|
||||
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<float>,
|
||||
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<std::string>(KeyFile));
|
||||
|
||||
|
||||
if (dictionary.hasKey(keyUnit)) {
|
||||
std::string unit = dictionary.value<std::string>(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<glm::vec3>(keyColor);
|
||||
}
|
||||
addProperty(_pointColor);
|
||||
|
||||
if (dictionary.hasKey(TransparencyInfo.identifier)) {
|
||||
_alphaValue = static_cast<float>(
|
||||
dictionary.value<double>(TransparencyInfo.identifier)
|
||||
);
|
||||
}
|
||||
addProperty(_alphaValue);
|
||||
|
||||
if (dictionary.hasKey(ScaleFactorInfo.identifier)) {
|
||||
_scaleFactor = static_cast<float>(
|
||||
dictionary.value<double>(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<GLsizei>(_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<int>(_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<GLsizei>(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<float> 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<char*>(&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<char*>(&nValues), sizeof(int32_t));
|
||||
fileStream.read(reinterpret_cast<char*>(&_nValuesPerAstronomicalObject), sizeof(int32_t));
|
||||
|
||||
_fullData.resize(nValues);
|
||||
fileStream.read(reinterpret_cast<char*>(&_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<const char*>(&CurrentCacheVersion),
|
||||
sizeof(int8_t));
|
||||
|
||||
int32_t nValues = static_cast<int32_t>(_fullData.size());
|
||||
if (nValues == 0) {
|
||||
LERROR("Error writing cache: No values were loaded");
|
||||
return false;
|
||||
}
|
||||
fileStream.write(reinterpret_cast<const char*>(&nValues), sizeof(int32_t));
|
||||
|
||||
int32_t nValuesPerAstronomicalObject = static_cast<int32_t>(_nValuesPerAstronomicalObject);
|
||||
fileStream.write(reinterpret_cast<const char*>(&nValuesPerAstronomicalObject), sizeof(int32_t));
|
||||
|
||||
size_t nBytes = nValues * sizeof(_fullData[0]);
|
||||
fileStream.write(reinterpret_cast<const char*>(&_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
|
||||
110
modules/digitaluniverse/rendering/renderablepoints.h
Normal file
110
modules/digitaluniverse/rendering/renderablepoints.h
Normal file
@@ -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 <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
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<ghoul::opengl::ProgramObject> _program;
|
||||
|
||||
std::string _speckFile;
|
||||
|
||||
Unit _unit;
|
||||
|
||||
std::vector<double> _slicedData;
|
||||
std::vector<float> _fullData;
|
||||
int _nValuesPerAstronomicalObject;
|
||||
|
||||
GLuint _vao;
|
||||
GLuint _vbo;
|
||||
};
|
||||
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEPOINTS___H__
|
||||
76
modules/digitaluniverse/rendering/renderablepointssprite.cpp
Normal file
76
modules/digitaluniverse/rendering/renderablepointssprite.cpp
Normal file
@@ -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 <modules/base/rendering/renderableplane.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
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
|
||||
45
modules/digitaluniverse/rendering/renderablepointssprite.h
Normal file
45
modules/digitaluniverse/rendering/renderablepointssprite.h
Normal file
@@ -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 <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/optionproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/scalar/boolproperty.h>
|
||||
#include <openspace/properties/scalar/floatproperty.h>
|
||||
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul::filesystem { class File; }
|
||||
|
||||
namespace ghoul::opengl {
|
||||
class ProgramObject;
|
||||
class Texture;
|
||||
} // namespace ghoul::opengl
|
||||
|
||||
|
||||
#endif // __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEPOINTSSPRITE___H__
|
||||
44
modules/digitaluniverse/shaders/dumesh_fs.glsl
Normal file
44
modules/digitaluniverse/shaders/dumesh_fs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
48
modules/digitaluniverse/shaders/dumesh_vs.glsl
Normal file
48
modules/digitaluniverse/shaders/dumesh_vs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
44
modules/digitaluniverse/shaders/points_fs.glsl
Normal file
44
modules/digitaluniverse/shaders/points_fs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
48
modules/digitaluniverse/shaders/points_vs.glsl
Normal file
48
modules/digitaluniverse/shaders/points_vs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
53
modules/digitaluniverse/shaders/pointssprite_fs.glsl
Normal file
53
modules/digitaluniverse/shaders/pointssprite_fs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
48
modules/digitaluniverse/shaders/pointssprite_vs.glsl
Normal file
48
modules/digitaluniverse/shaders/pointssprite_vs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user