mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-21 12:29:04 -06:00
solve merge conflict
This commit is contained in:
@@ -267,6 +267,7 @@ void RenderableModel::loadTexture() {
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_texture->uploadTexture();
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,10 +316,12 @@ void RenderableStars::update(const UpdateData& data) {
|
||||
_pointSpreadFunctionTexture = nullptr;
|
||||
if (_pointSpreadFunctionTexturePath.value() != "") {
|
||||
_pointSpreadFunctionTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_pointSpreadFunctionTexturePath)));
|
||||
|
||||
if (_pointSpreadFunctionTexture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_pointSpreadFunctionTexturePath) << "'");
|
||||
_pointSpreadFunctionTexture->uploadTexture();
|
||||
}
|
||||
_pointSpreadFunctionTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
|
||||
delete _psfTextureFile;
|
||||
_psfTextureFile = new ghoul::filesystem::File(_pointSpreadFunctionTexturePath);
|
||||
|
||||
@@ -49,7 +49,7 @@ void main()
|
||||
|
||||
vec4 position = pscTransform(tmp, mt);
|
||||
|
||||
vs_position = in_position;
|
||||
vs_position = tmp;
|
||||
vs_st = in_st;
|
||||
|
||||
position = ViewProjection * position;
|
||||
|
||||
@@ -58,7 +58,7 @@ vec4 bv2rgb(float bv) {
|
||||
Fragment getFragment() {
|
||||
// Something in the color calculations need to be changed because before it was dependent
|
||||
// on the gl blend functions since the abuffer was not involved
|
||||
|
||||
|
||||
vec4 color = vec4(0.0);
|
||||
switch (colorOption) {
|
||||
case COLOROPTION_COLOR:
|
||||
@@ -79,7 +79,7 @@ Fragment getFragment() {
|
||||
|
||||
vec4 position = vs_position;
|
||||
// This has to be fixed when the scale graph is in place ---emiax
|
||||
position.w = 19;
|
||||
position.w = 15;
|
||||
|
||||
Fragment frag;
|
||||
frag.color = fullColor;
|
||||
|
||||
@@ -40,9 +40,9 @@ Fragment getFragment()
|
||||
float alpha = 1-length(gs_normal)*length(gs_normal);
|
||||
vec4 fragColor;
|
||||
if (classification)
|
||||
fragColor = vec4(gs_color.rgb, alpha);
|
||||
fragColor = vec4(gs_color.rgb * alpha, 1.0);
|
||||
else
|
||||
fragColor = vec4(fieldLineColor.rgb, fieldLineColor.a * alpha);
|
||||
fragColor = vec4(fieldLineColor.rgb * fieldLineColor.a * alpha, 1.0);
|
||||
|
||||
float depth = pscDepth(gs_position);
|
||||
|
||||
|
||||
45
modules/galaxy/CMakeLists.txt
Normal file
45
modules/galaxy/CMakeLists.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
#########################################################################################
|
||||
# #
|
||||
# OpenSpace #
|
||||
# #
|
||||
# Copyright (c) 2014-2015 #
|
||||
# #
|
||||
# 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}/galaxymodule.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/galaxyraycaster.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablegalaxy.h
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/galaxymodule.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/galaxyraycaster.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablegalaxy.cpp
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
create_new_module(
|
||||
"Galaxy"
|
||||
galaxy
|
||||
${HEADER_FILES} ${SOURCE_FILES}
|
||||
)
|
||||
41
modules/galaxy/galaxymodule.cpp
Normal file
41
modules/galaxy/galaxymodule.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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/galaxy/galaxymodule.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <modules/galaxy/rendering/renderablegalaxy.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
GalaxyModule::GalaxyModule() : OpenSpaceModule("Galaxy") {}
|
||||
|
||||
void GalaxyModule::internalInitialize() {
|
||||
auto fRenderable = FactoryManager::ref().factory<Renderable>();
|
||||
ghoul_assert(fRenderable, "No renderable factory existed");
|
||||
fRenderable->registerClass<RenderableGalaxy>("RenderableGalaxy");
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
40
modules/galaxy/galaxymodule.h
Normal file
40
modules/galaxy/galaxymodule.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2015 *
|
||||
* *
|
||||
* 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 __GALAXYMODULE_H__
|
||||
#define __GALAXYMODULE_H__
|
||||
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class GalaxyModule : public OpenSpaceModule {
|
||||
public:
|
||||
GalaxyModule();
|
||||
void internalInitialize() override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __GALAXYMODULE_H__
|
||||
4
modules/galaxy/include.cmake
Normal file
4
modules/galaxy/include.cmake
Normal file
@@ -0,0 +1,4 @@
|
||||
set (DEFAULT_MODULE ON)
|
||||
set (OPENSPACE_DEPENDENCIES
|
||||
volume
|
||||
)
|
||||
177
modules/galaxy/rendering/galaxyraycaster.cpp
Normal file
177
modules/galaxy/rendering/galaxyraycaster.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/galaxy/rendering/galaxyraycaster.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
#include <sstream>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <openspace/util/powerscaledcoordinate.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
|
||||
|
||||
namespace {
|
||||
const std::string GlslRaycastPath = "${MODULES}/galaxy/shaders/galaxyraycast.glsl";
|
||||
const std::string GlslBoundsVsPath = "${MODULES}/galaxy/shaders/raycasterbounds.vs";
|
||||
const std::string GlslBoundsFsPath = "${MODULES}/galaxy/shaders/raycasterbounds.fs";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
GalaxyRaycaster::GalaxyRaycaster(ghoul::opengl::Texture& texture)
|
||||
: _boundingBox(glm::vec3(1.0))
|
||||
, _texture(texture)
|
||||
, _textureUnit(nullptr) {}
|
||||
|
||||
GalaxyRaycaster::~GalaxyRaycaster() {}
|
||||
|
||||
void GalaxyRaycaster::initialize() {
|
||||
_boundingBox.initialize();
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::deinitialize() {
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::renderEntryPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) {
|
||||
program.setUniform("modelTransform", _modelTransform);
|
||||
program.setUniform("viewProjection", data.camera.viewProjectionMatrix());
|
||||
program.setUniform("blendMode", static_cast<unsigned int>(1));
|
||||
|
||||
Renderable::setPscUniforms(program, data.camera, data.position);
|
||||
|
||||
// Cull back face
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
// Render bounding geometry
|
||||
_boundingBox.render();
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::renderExitPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) {
|
||||
// Uniforms
|
||||
program.setUniform("modelTransform", _modelTransform);
|
||||
program.setUniform("viewProjection", data.camera.viewProjectionMatrix());
|
||||
program.setUniform("blendMode", static_cast<unsigned int>(1));
|
||||
Renderable::setPscUniforms(program, data.camera, data.position);
|
||||
|
||||
// Cull front face
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
// Render bounding geometry
|
||||
_boundingBox.render();
|
||||
|
||||
// Restore defaults
|
||||
glCullFace(GL_BACK);
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::preRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) {
|
||||
std::string colorUniformName = "color" + std::to_string(data.id);
|
||||
std::string stepSizeUniformName = "maxStepSize" + std::to_string(data.id);
|
||||
std::string galaxyTextureUniformName = "galaxyTexture" + std::to_string(data.id);
|
||||
std::string volumeAspectUniformName = "aspect" + std::to_string(data.id);
|
||||
std::string opacityCoefficientUniformName = "opacityCoefficient" + std::to_string(data.id);
|
||||
|
||||
program.setUniform(volumeAspectUniformName, _aspect);
|
||||
program.setUniform(stepSizeUniformName, _stepSize);
|
||||
program.setUniform(opacityCoefficientUniformName, _opacityCoefficient);
|
||||
|
||||
_textureUnit = std::make_unique<ghoul::opengl::TextureUnit>();
|
||||
_textureUnit->activate();
|
||||
_texture.bind();
|
||||
program.setUniform(galaxyTextureUniformName, *_textureUnit);
|
||||
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::postRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) {
|
||||
_textureUnit = nullptr; // release texture unit.
|
||||
}
|
||||
|
||||
bool GalaxyRaycaster::cameraIsInside(const RenderData& data, glm::vec3& localPosition) {
|
||||
// Camera rig position in world coordinates.
|
||||
glm::vec4 rigWorldPos = glm::vec4(data.camera.position().vec3(), 1.0);
|
||||
//rigWorldPos /= data.camera.scaling().x * pow(10.0, data.camera.scaling().y);
|
||||
//glm::mat4 invSgctMatrix = glm::inverse(data.camera.viewMatrix());
|
||||
|
||||
// Camera position in world coordinates.
|
||||
glm::vec4 camWorldPos = rigWorldPos;
|
||||
glm::vec3 objPos = data.position.vec3();
|
||||
|
||||
glm::mat4 modelTransform = glm::translate(_modelTransform, objPos);
|
||||
|
||||
float divisor = 1.0;
|
||||
for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) {
|
||||
if (abs(modelTransform[i][j] > divisor)) divisor = modelTransform[i][j];
|
||||
}
|
||||
|
||||
glm::mat4 scaledModelTransform = modelTransform / divisor;
|
||||
|
||||
glm::vec4 modelPos = (glm::inverse(scaledModelTransform) / divisor) * camWorldPos;
|
||||
|
||||
localPosition = (modelPos.xyz() + glm::vec3(0.5));
|
||||
return (localPosition.x > 0 && localPosition.y > 0 && localPosition.z > 0 && localPosition.x < 1 && localPosition.y < 1 && localPosition.z < 1);
|
||||
}
|
||||
|
||||
std::string GalaxyRaycaster::getBoundsVsPath() const {
|
||||
return GlslBoundsVsPath;
|
||||
}
|
||||
|
||||
std::string GalaxyRaycaster::getBoundsFsPath() const {
|
||||
return GlslBoundsFsPath;
|
||||
}
|
||||
|
||||
std::string GalaxyRaycaster::getRaycastPath() const {
|
||||
return GlslRaycastPath;
|
||||
}
|
||||
|
||||
std::string GalaxyRaycaster::getHelperPath() const {
|
||||
return ""; // no helper file
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::setAspect(const glm::vec3& aspect) {
|
||||
_aspect = aspect / std::max(std::max(aspect.x, aspect.y), aspect.z);
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::setModelTransform(glm::mat4 transform) {
|
||||
_modelTransform = transform;
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::setOpacityCoefficient(float opacityCoefficient) {
|
||||
_opacityCoefficient = opacityCoefficient;
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::setTime(double time) {
|
||||
_time = time;
|
||||
}
|
||||
|
||||
void GalaxyRaycaster::setStepSize(float stepSize) {
|
||||
_stepSize = stepSize;
|
||||
}
|
||||
|
||||
}
|
||||
89
modules/galaxy/rendering/galaxyraycaster.h
Normal file
89
modules/galaxy/rendering/galaxyraycaster.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __GALAXYRAYCASTER_H__
|
||||
#define __GALAXYRAYCASTER_H__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <openspace/rendering/volumeraycaster.h>
|
||||
#include <openspace/util/boxgeometry.h>
|
||||
#include <openspace/util/blockplaneintersectiongeometry.h>
|
||||
|
||||
namespace ghoul {
|
||||
namespace opengl {
|
||||
class Texture;
|
||||
class TextureUnit;
|
||||
class ProgramObject;
|
||||
}
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderData;
|
||||
class RaycastData;
|
||||
|
||||
class GalaxyRaycaster : public VolumeRaycaster {
|
||||
public:
|
||||
|
||||
GalaxyRaycaster(ghoul::opengl::Texture& texture);
|
||||
|
||||
virtual ~GalaxyRaycaster();
|
||||
void initialize();
|
||||
void deinitialize();
|
||||
void renderEntryPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) override;
|
||||
void renderExitPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) override;
|
||||
void preRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) override;
|
||||
void postRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) override;
|
||||
bool cameraIsInside(const RenderData& data, glm::vec3& localPosition) override;
|
||||
|
||||
|
||||
std::string getBoundsVsPath() const override;
|
||||
std::string getBoundsFsPath() const override;
|
||||
std::string getRaycastPath() const override;
|
||||
std::string getHelperPath() const override;
|
||||
|
||||
void setAspect(const glm::vec3& aspect);
|
||||
void setModelTransform(glm::mat4 transform);
|
||||
void setTime(double time);
|
||||
void setStepSize(float stepSize);
|
||||
void setOpacityCoefficient(float opacityCoefficient);
|
||||
private:
|
||||
BoxGeometry _boundingBox;
|
||||
float _stepSize;
|
||||
glm::mat4 _modelTransform;
|
||||
glm::vec3 _aspect;
|
||||
double _time;
|
||||
float _opacityCoefficient;
|
||||
ghoul::opengl::Texture& _texture;
|
||||
std::unique_ptr<ghoul::opengl::TextureUnit> _textureUnit;
|
||||
|
||||
}; // GalaxyRaycaster
|
||||
|
||||
} // openspace
|
||||
|
||||
#endif // __GALAXYRRAYCASTER_H__
|
||||
367
modules/galaxy/rendering/renderablegalaxy.cpp
Normal file
367
modules/galaxy/rendering/renderablegalaxy.cpp
Normal file
@@ -0,0 +1,367 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/galaxy/rendering/renderablegalaxy.h>
|
||||
#include <modules/galaxy/rendering/galaxyraycaster.h>
|
||||
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/rendering/raycastermanager.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
#include <modules/volume/rawvolumereader.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
namespace {
|
||||
const std::string GlslRayCastPath = "${MODULES}/toyvolume/shaders/rayCast.glsl";
|
||||
const std::string GlslBoundsVsPath = "${MODULES}/toyvolume/shaders/boundsVs.glsl";
|
||||
const std::string GlslBoundsFsPath = "${MODULES}/toyvolume/shaders/boundsFs.glsl";
|
||||
const std::string _loggerCat = "Renderable Galaxy";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
RenderableGalaxy::RenderableGalaxy(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _stepSize("stepSize", "Step Size", 0.012, 0.0005, 0.05)
|
||||
, _pointStepSize("pointStepSize", "Point Step Size", 0.01, 0.01, 0.1)
|
||||
, _translation("translation", "Translation", glm::vec3(0.0, 0.0, 0.0), glm::vec3(0.0), glm::vec3(10.0))
|
||||
, _rotation("rotation", "Euler rotation", glm::vec3(0.0, 0.0, 0.0), glm::vec3(0), glm::vec3(6.28))
|
||||
, _enabledPointsRatio("nEnabledPointsRatio", "Enabled points", 0.2, 0, 1) {
|
||||
|
||||
float stepSize;
|
||||
glm::vec3 scaling, translation, rotation;
|
||||
glm::vec4 color;
|
||||
ghoul::Dictionary volumeDictionary, pointsDictionary;
|
||||
|
||||
if (dictionary.getValue("Translation", translation)) {
|
||||
_translation = translation;
|
||||
}
|
||||
if (dictionary.getValue("Rotation", rotation)) {
|
||||
_rotation = rotation;
|
||||
}
|
||||
if (dictionary.getValue("StepSize", stepSize)) {
|
||||
_stepSize = stepSize;
|
||||
}
|
||||
if (dictionary.getValue("Volume", volumeDictionary)) {
|
||||
std::string volumeFilename;
|
||||
if (volumeDictionary.getValue("Filename", volumeFilename)) {
|
||||
_volumeFilename = absPath(volumeFilename);
|
||||
} else {
|
||||
LERROR("No volume filename specified.");
|
||||
}
|
||||
glm::vec3 volumeDimensions;
|
||||
if (volumeDictionary.getValue("Dimensions", volumeDimensions)) {
|
||||
_volumeDimensions = static_cast<glm::ivec3>(volumeDimensions);
|
||||
} else {
|
||||
LERROR("No volume dimensions specified.");
|
||||
}
|
||||
glm::vec3 volumeSize;
|
||||
if (volumeDictionary.getValue("Size", volumeSize)) {
|
||||
_volumeSize = static_cast<glm::vec3>(volumeSize);
|
||||
}
|
||||
else {
|
||||
LERROR("No volume dimensions specified.");
|
||||
}
|
||||
|
||||
} else {
|
||||
LERROR("No volume dictionary specified.");
|
||||
}
|
||||
if (dictionary.getValue("Points", pointsDictionary)) {
|
||||
std::string pointsFilename;
|
||||
if (pointsDictionary.getValue("Filename", pointsFilename)) {
|
||||
_pointsFilename = absPath(pointsFilename);
|
||||
} else {
|
||||
LERROR("No points filename specified.");
|
||||
}
|
||||
glm::vec3 pointsScaling;
|
||||
if (pointsDictionary.getValue("Scaling", pointsScaling)) {
|
||||
_pointScaling = static_cast<glm::vec3>(pointsScaling);
|
||||
}
|
||||
else {
|
||||
LERROR("No volume dimensions specified.");
|
||||
}
|
||||
} else {
|
||||
LERROR("No points dictionary specified.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RenderableGalaxy::~RenderableGalaxy() {}
|
||||
|
||||
bool RenderableGalaxy::initialize() {
|
||||
// Aspect is currently hardcoded to cubic voxels.
|
||||
_aspect = static_cast<glm::vec3>(_volumeDimensions);
|
||||
_aspect = _aspect / std::max(std::max(_aspect.x, _aspect.y), _aspect.z);
|
||||
|
||||
RawVolumeReader<glm::tvec4<GLfloat>> reader(_volumeFilename, _volumeDimensions);
|
||||
_volume = reader.read();
|
||||
|
||||
_texture = std::make_unique<ghoul::opengl::Texture>(
|
||||
_volumeDimensions,
|
||||
ghoul::opengl::Texture::Format::RGBA,
|
||||
GL_RGBA32F,
|
||||
GL_FLOAT,
|
||||
ghoul::opengl::Texture::FilterMode::Linear,
|
||||
ghoul::opengl::Texture::WrappingMode::Clamp);
|
||||
|
||||
_texture->setPixelData(reinterpret_cast<char*>(_volume->data()), ghoul::opengl::Texture::TakeOwnership::No);
|
||||
_texture->setDimensions(_volume->dimensions());
|
||||
_texture->uploadTexture();
|
||||
|
||||
_raycaster = std::make_unique<GalaxyRaycaster>(*_texture);
|
||||
_raycaster->initialize();
|
||||
|
||||
OsEng.renderEngine().raycasterManager().attachRaycaster(*_raycaster.get());
|
||||
|
||||
std::function<void(bool)> onChange = [&](bool enabled) {
|
||||
if (enabled) {
|
||||
OsEng.renderEngine().raycasterManager().attachRaycaster(*_raycaster.get());
|
||||
}
|
||||
else {
|
||||
OsEng.renderEngine().raycasterManager().detachRaycaster(*_raycaster.get());
|
||||
}
|
||||
};
|
||||
|
||||
onEnabledChange(onChange);
|
||||
|
||||
addProperty(_stepSize);
|
||||
addProperty(_pointStepSize);
|
||||
addProperty(_translation);
|
||||
addProperty(_rotation);
|
||||
addProperty(_enabledPointsRatio);
|
||||
|
||||
// initialize points.
|
||||
std::ifstream pointFile(_pointsFilename, std::ios::in | std::ios::binary);
|
||||
|
||||
std::vector<glm::vec3> pointPositions;
|
||||
std::vector<glm::vec3> pointColors;
|
||||
|
||||
int64_t nPoints;
|
||||
pointFile.seekg(0, std::ios::beg); // read heder.
|
||||
pointFile.read(reinterpret_cast<char*>(&nPoints), sizeof(int64_t));
|
||||
|
||||
_nPoints = static_cast<size_t>(nPoints);
|
||||
|
||||
size_t nFloats = _nPoints * 7;
|
||||
|
||||
float* pointData = new float[nFloats];
|
||||
pointFile.seekg(sizeof(int64_t), std::ios::beg); // read past heder.
|
||||
pointFile.read(reinterpret_cast<char*>(pointData), nFloats * sizeof(float));
|
||||
pointFile.close();
|
||||
|
||||
float maxdist = 0;
|
||||
|
||||
|
||||
float x, y, z, r, g, b, a;
|
||||
for (size_t i = 0; i < _nPoints; ++i) {
|
||||
float x = pointData[i * 7 + 0];
|
||||
float y = pointData[i * 7 + 1];
|
||||
float z = pointData[i * 7 + 2];
|
||||
float r = pointData[i * 7 + 3];
|
||||
float g = pointData[i * 7 + 4];
|
||||
float b = pointData[i * 7 + 5];
|
||||
maxdist = std::max(maxdist, glm::length(glm::vec3(x, y, z)));
|
||||
//float a = pointData[i * 7 + 6]; alpha is not used.
|
||||
|
||||
pointPositions.push_back(glm::vec3(x, y, z));
|
||||
pointColors.push_back(glm::vec3(r, g, b));
|
||||
}
|
||||
|
||||
std::cout << maxdist << std::endl;
|
||||
|
||||
delete[] pointData;
|
||||
|
||||
glGenVertexArrays(1, &_pointsVao);
|
||||
glGenBuffers(1, &_positionVbo);
|
||||
glGenBuffers(1, &_colorVbo);
|
||||
|
||||
glBindVertexArray(_pointsVao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _positionVbo);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
pointPositions.size()*sizeof(glm::vec3),
|
||||
pointPositions.data(),
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _colorVbo);
|
||||
glBufferData(GL_ARRAY_BUFFER,
|
||||
pointColors.size()*sizeof(glm::vec3),
|
||||
pointColors.data(),
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_pointsProgram = renderEngine.buildRenderProgram("Galaxy points",
|
||||
"${MODULE_GALAXY}/shaders/points.vs",
|
||||
"${MODULE_GALAXY}/shaders/points.fs",
|
||||
ghoul::Dictionary(),
|
||||
RenderEngine::RenderProgramType::Post);
|
||||
|
||||
_pointsProgram->setIgnoreUniformLocationError(ghoul::opengl::ProgramObject::IgnoreError::Yes);
|
||||
|
||||
GLint positionAttrib = _pointsProgram->attributeLocation("inPosition");
|
||||
GLint colorAttrib = _pointsProgram->attributeLocation("inColor");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _positionVbo);
|
||||
glEnableVertexAttribArray(positionAttrib);
|
||||
glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _colorVbo);
|
||||
glEnableVertexAttribArray(colorAttrib);
|
||||
glVertexAttribPointer(colorAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderableGalaxy::deinitialize() {
|
||||
if (_raycaster) {
|
||||
OsEng.renderEngine().raycasterManager().detachRaycaster(*_raycaster.get());
|
||||
_raycaster = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderableGalaxy::isReady() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableGalaxy::update(const UpdateData& data) {
|
||||
if (_raycaster) {
|
||||
|
||||
//glm::mat4 transform = glm::translate(, static_cast<glm::vec3>(_translation));
|
||||
glm::vec3 eulerRotation = static_cast<glm::vec3>(_rotation);
|
||||
glm::mat4 transform = glm::rotate(glm::mat4(1.0), eulerRotation.x, glm::vec3(1, 0, 0));
|
||||
transform = glm::rotate(transform, eulerRotation.y, glm::vec3(0, 1, 0));
|
||||
transform = glm::rotate(transform, eulerRotation.z, glm::vec3(0, 0, 1));
|
||||
|
||||
|
||||
glm::mat4 volumeTransform = glm::scale(transform, static_cast<glm::vec3>(_volumeSize));
|
||||
_pointTransform = glm::scale(transform, static_cast<glm::vec3>(_pointScaling));
|
||||
|
||||
glm::vec4 translation = glm::vec4(static_cast<glm::vec3>(_translation), 0.0);
|
||||
|
||||
// Todo: handle floating point overflow, to actually support translation.
|
||||
|
||||
volumeTransform[3] += translation;
|
||||
_pointTransform[3] += translation;
|
||||
|
||||
|
||||
_raycaster->setStepSize(_stepSize);
|
||||
_raycaster->setAspect(_aspect);
|
||||
_raycaster->setModelTransform(volumeTransform);
|
||||
_raycaster->setTime(data.time);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) {
|
||||
RaycasterTask task{ _raycaster.get(), data };
|
||||
|
||||
glm::vec3 position = data.camera.position().vec3();
|
||||
float length = safeLength(position);
|
||||
glm::vec3 galaxySize = static_cast<glm::vec3>(_volumeSize);
|
||||
|
||||
float maxDim = std::max(std::max(galaxySize.x, galaxySize.y), galaxySize.z);
|
||||
|
||||
|
||||
float lowerRampStart = maxDim * 0.02;
|
||||
float lowerRampEnd = maxDim * 0.5;
|
||||
|
||||
float upperRampStart = maxDim * 2.0;
|
||||
float upperRampEnd = maxDim * 10;
|
||||
|
||||
float opacityCoefficient = 1.0;
|
||||
|
||||
if (length < lowerRampStart) {
|
||||
opacityCoefficient = 0; // camera really close
|
||||
} else if (length < lowerRampEnd) {
|
||||
opacityCoefficient = (length - lowerRampStart) / (lowerRampEnd - lowerRampStart);
|
||||
} else if (length < upperRampStart) {
|
||||
opacityCoefficient = 1.0; // sweet spot (max)
|
||||
} else if (length < upperRampEnd) {
|
||||
opacityCoefficient = 1.0 - (length - upperRampStart) / (upperRampEnd - upperRampStart); //fade out
|
||||
} else {
|
||||
opacityCoefficient = 0;
|
||||
}
|
||||
|
||||
_opacityCoefficient = opacityCoefficient;
|
||||
ghoul_assert(_opacityCoefficient >= 0.0 && _opacityCoefficient <= 1.0, "Opacity coefficient was not between 0 and 1");
|
||||
if (opacityCoefficient > 0) {
|
||||
_raycaster->setOpacityCoefficient(_opacityCoefficient);
|
||||
tasks.raycasterTasks.push_back(task);
|
||||
}
|
||||
}
|
||||
|
||||
float RenderableGalaxy::safeLength(const glm::vec3& vector) {
|
||||
float maxComponent = std::max(std::max(std::abs(vector.x), std::abs(vector.y)), std::abs(vector.z));
|
||||
return glm::length(vector / maxComponent) * maxComponent;
|
||||
}
|
||||
|
||||
void RenderableGalaxy::postRender(const RenderData& data) {
|
||||
|
||||
_raycaster->setStepSize(_pointStepSize);
|
||||
|
||||
_pointsProgram->activate();
|
||||
setPscUniforms(*_pointsProgram.get(), data.camera, data.position);
|
||||
|
||||
OsEng.ref().renderEngine().preRaycast(*_pointsProgram);
|
||||
|
||||
glm::mat4 modelMatrix = _pointTransform;
|
||||
glm::mat4 viewMatrix = data.camera.viewMatrix();
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
|
||||
_pointsProgram->setUniform("model", modelMatrix);
|
||||
_pointsProgram->setUniform("view", viewMatrix);
|
||||
_pointsProgram->setUniform("projection", projectionMatrix);
|
||||
|
||||
float emittanceFactor = _opacityCoefficient * static_cast<glm::vec3>(_volumeSize).x;
|
||||
_pointsProgram->setUniform("emittanceFactor", emittanceFactor);
|
||||
|
||||
glBindVertexArray(_pointsVao);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(false);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glDrawArrays(GL_POINTS, 0, _nPoints * _enabledPointsRatio);
|
||||
glBindVertexArray(0);
|
||||
glDepthMask(true);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
OsEng.ref().renderEngine().postRaycast(*_pointsProgram);
|
||||
}
|
||||
|
||||
}
|
||||
80
modules/galaxy/rendering/renderablegalaxy.h
Normal file
80
modules/galaxy/rendering/renderablegalaxy.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RENDERABLEGALAXY_H__
|
||||
#define __RENDERABLEGALAXY_H__
|
||||
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/util/boxgeometry.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <modules/galaxy/rendering/galaxyraycaster.h>
|
||||
#include <modules/volume/rawvolume.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
|
||||
class RenderableGalaxy : public Renderable {
|
||||
public:
|
||||
RenderableGalaxy(const ghoul::Dictionary& dictionary);
|
||||
~RenderableGalaxy();
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
bool isReady() const override;
|
||||
void render(const RenderData& data, RendererTasks& tasks) override;
|
||||
void postRender(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
float safeLength(const glm::vec3& vector);
|
||||
|
||||
glm::vec3 _volumeSize;
|
||||
glm::vec3 _pointScaling;
|
||||
properties::FloatProperty _stepSize;
|
||||
properties::FloatProperty _pointStepSize;
|
||||
properties::Vec3Property _translation;
|
||||
properties::Vec3Property _rotation;
|
||||
properties::FloatProperty _enabledPointsRatio;
|
||||
|
||||
std::string _volumeFilename;
|
||||
glm::ivec3 _volumeDimensions;
|
||||
std::string _pointsFilename;
|
||||
|
||||
std::unique_ptr<GalaxyRaycaster> _raycaster;
|
||||
std::unique_ptr<RawVolume<glm::tvec4<GLfloat>>> _volume;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
glm::mat4 _pointTransform;
|
||||
glm::vec3 _aspect;
|
||||
float _opacityCoefficient;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _pointsProgram;
|
||||
size_t _nPoints;
|
||||
GLuint _pointsVao;
|
||||
GLuint _positionVbo;
|
||||
GLuint _colorVbo;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __RENDERABLEGALAXY_H__
|
||||
97
modules/galaxy/shaders/galaxyraycast.glsl
Normal file
97
modules/galaxy/shaders/galaxyraycast.glsl
Normal file
@@ -0,0 +1,97 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
uniform float maxStepSize#{id} = 0.1;
|
||||
uniform vec3 aspect#{id} = vec3(1.0);
|
||||
uniform float opacityCoefficient#{id} = 1.0;
|
||||
|
||||
uniform sampler3D galaxyTexture#{id};
|
||||
|
||||
void sample#{id}(vec3 samplePos,
|
||||
vec3 dir,
|
||||
inout vec3 accumulatedColor,
|
||||
inout vec3 accumulatedAlpha,
|
||||
inout float maxStepSize) {
|
||||
|
||||
vec3 aspect = aspect#{id};
|
||||
maxStepSize = maxStepSize#{id} / length(dir/aspect);
|
||||
|
||||
vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz);
|
||||
|
||||
float STEP_SIZE = maxStepSize#{id};
|
||||
|
||||
vec3 alphaTint = vec3(0.3, 0.54, 0.85);
|
||||
//alphaTint = vec3(0.0, 0.5, 1.0);
|
||||
|
||||
sampledColor = sampledColor*sampledColor;
|
||||
sampledColor.a = pow(sampledColor.a, 0.7);
|
||||
//sampledColor.rgba = min(vec4(1.0), sampledColor.rgba);
|
||||
|
||||
//sampledColor.a = clamp(sampledColor.a * 10000000000.0, 0.0, 1.0);
|
||||
//sampledColor.a = exp(-sampledColor.a);
|
||||
//
|
||||
|
||||
//sampledColor.rgb = pow(sampledColor.rgb, vec3(10.0));
|
||||
//sampledColor.a = pow(sampledColor.a, 10.0);
|
||||
//sampledColor.a = pow(sampledColor.a, 100000000.0);
|
||||
sampledColor.rgb *= 500.0;
|
||||
sampledColor.a = sampledColor.a * 0.3; //1.0;
|
||||
|
||||
|
||||
//float emissionCoefficient = 80;
|
||||
//float absorptionCoefficient = 1;
|
||||
// sampledColor = clamp(sampledColor, 0.0, 1.0);
|
||||
|
||||
//backColor = vec3(1.0) - pow(vec3(1.0) - backColor, vec3(STEP_SIZE));
|
||||
/*if (sampledColor.a > 1.0) {
|
||||
sampledColor.a = 1.0;
|
||||
//accumulatedColor = vec3(1.0, 0.0, 0.0);
|
||||
//accumulatedAlpha = vec3(1.0, 1.0, 1.0);
|
||||
//return;
|
||||
}*/
|
||||
//sampledColor.a = 1.2;
|
||||
|
||||
//sampledColor.a *= 0.00001;
|
||||
|
||||
vec3 backColor = sampledColor.rgb;
|
||||
vec3 backAlpha = sampledColor.a * alphaTint;
|
||||
|
||||
backColor *= STEP_SIZE * opacityCoefficient#{id};
|
||||
backAlpha *= STEP_SIZE * opacityCoefficient#{id};
|
||||
|
||||
backColor = clamp(backColor, 0.0, 1.0);
|
||||
backAlpha = clamp(backAlpha, 0.0, 1.0);
|
||||
|
||||
vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha;
|
||||
accumulatedColor += oneMinusFrontAlpha * backColor;
|
||||
accumulatedAlpha += oneMinusFrontAlpha * backAlpha;
|
||||
|
||||
// acc+= 1.0;
|
||||
|
||||
//accumulatedColor = vec3(opacityCoefficient#{id});
|
||||
}
|
||||
|
||||
float stepSize#{id}(vec3 samplePos, vec3 dir) {
|
||||
return maxStepSize#{id} * length(dir * 1.0/aspect#{id});
|
||||
}
|
||||
47
modules/galaxy/shaders/points.fs
Normal file
47
modules/galaxy/shaders/points.fs
Normal file
@@ -0,0 +1,47 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
uniform float emittanceFactor;
|
||||
|
||||
in vec3 vsPosition;
|
||||
in vec3 vsColor;
|
||||
|
||||
#include "fragment.glsl"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 color = vec4(vsColor, 1.0);
|
||||
|
||||
Fragment frag;
|
||||
float depth = pscDepth(vec4(vsPosition, 0.0));
|
||||
|
||||
float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(depth));
|
||||
|
||||
frag.color = vec4(vsColor.rgb * coefficient, 1.0);
|
||||
|
||||
|
||||
frag.depth = depth;
|
||||
|
||||
return frag;
|
||||
}
|
||||
53
modules/galaxy/shaders/points.vs
Normal file
53
modules/galaxy/shaders/points.vs
Normal file
@@ -0,0 +1,53 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
in vec3 inPosition;
|
||||
in vec3 inColor;
|
||||
|
||||
out vec3 vsPosition;
|
||||
out vec3 vsColor;
|
||||
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main() {
|
||||
vec4 p = vec4(inPosition, 1.0);
|
||||
|
||||
vec4 worldPosition = model * p;
|
||||
worldPosition.w = 0.0;
|
||||
vec4 position = worldPosition; //pscTransform(worldPosition, model);
|
||||
|
||||
|
||||
position = pscTransform(position, mat4(1.0));
|
||||
vsPosition = position.xyz;
|
||||
position = projection * view * position;
|
||||
gl_Position = z_normalization(position);
|
||||
vsColor = inColor;
|
||||
}
|
||||
43
modules/galaxy/shaders/raycasterbounds.fs
Normal file
43
modules/galaxy/shaders/raycasterbounds.fs
Normal file
@@ -0,0 +1,43 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
in vec3 vPosition;
|
||||
in vec4 worldPosition;
|
||||
|
||||
uniform uint blendMode;
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 fragColor = vec4((vPosition+0.5), 1.0);
|
||||
vec4 position = worldPosition;
|
||||
float depth = pscDepth(position);
|
||||
|
||||
Fragment frag;
|
||||
frag.color = fragColor;
|
||||
frag.depth = depth;
|
||||
frag.blend = blendMode;
|
||||
return frag;
|
||||
}
|
||||
49
modules/galaxy/shaders/raycasterbounds.vs
Normal file
49
modules/galaxy/shaders/raycasterbounds.vs
Normal file
@@ -0,0 +1,49 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
layout(location = 0) in vec4 vertPosition;
|
||||
|
||||
uniform mat4 viewProjection;
|
||||
uniform mat4 modelTransform;
|
||||
|
||||
out vec3 vPosition;
|
||||
out vec4 worldPosition;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main() {
|
||||
vPosition = vertPosition.xyz;
|
||||
|
||||
worldPosition = modelTransform * vec4(vertPosition.xyz, 1.0);
|
||||
worldPosition.w = 0.0;
|
||||
vec4 position = pscTransform(worldPosition, mat4(1.0));
|
||||
|
||||
|
||||
|
||||
// project the position to view space
|
||||
gl_Position = z_normalization(viewProjection * position);
|
||||
//gl_Position.z = 1.0;
|
||||
}
|
||||
@@ -184,6 +184,7 @@ void DataProcessor::add(std::vector<std::vector<float>>& optionValues, std::vect
|
||||
_numValues[i] += numValues;
|
||||
|
||||
_histograms[i]->generateEqualizer();
|
||||
// _histograms[i]->print();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,13 @@
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <boost/iostreams/device/mapped_file.hpp>
|
||||
|
||||
#include <boost/config/warning_disable.hpp>
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/include/phoenix_stl.hpp>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "DataProcessorText";
|
||||
}
|
||||
@@ -115,12 +122,14 @@ void DataProcessorText::addDataValues(std::string data, properties::SelectionPro
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
add(optionValues, sum);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<float*> DataProcessorText::processData(std::string data, properties::SelectionProperty& dataOptions, glm::size3_t& dimensions){
|
||||
if(!data.empty()){
|
||||
|
||||
std::string line;
|
||||
std::stringstream memorystream(data);
|
||||
|
||||
@@ -141,21 +150,33 @@ std::vector<float*> DataProcessorText::processData(std::string data, properties:
|
||||
if(line.find("#") == 0) continue;
|
||||
|
||||
values = std::vector<float>();
|
||||
std::stringstream ss(line);
|
||||
copy(
|
||||
std::next( std::istream_iterator<float> (ss), 3 ), //+3 because options x, y and z in the file
|
||||
std::istream_iterator<float> (),
|
||||
back_inserter(values)
|
||||
);
|
||||
|
||||
int first = 0;
|
||||
int last = 0;
|
||||
int option = -3;
|
||||
int lineSize = line.size();
|
||||
|
||||
for(int option : selectedOptions){
|
||||
value = values[option];
|
||||
dataOptions[option][numValues] = processDataPoint(value, option);
|
||||
while(last < lineSize){
|
||||
|
||||
first = line.find_first_not_of(" \t", last);
|
||||
last = line.find_first_of(" \t", first);
|
||||
if(option >= 0){
|
||||
last = (last > 0)? last : lineSize;
|
||||
// boost::spirit::qi::parse(&line[first], &line[last], boost::spirit::qi::double_, value);
|
||||
value = std::stof(line.substr(first, last));
|
||||
|
||||
if(std::find(selectedOptions.begin(), selectedOptions.end(), option) != selectedOptions.end())
|
||||
dataOptions[option][numValues] = processDataPoint(value, option);
|
||||
}
|
||||
|
||||
option++;
|
||||
}
|
||||
|
||||
numValues++;
|
||||
}
|
||||
|
||||
calculateFilterValues(selectedOptions);
|
||||
|
||||
return dataOptions;
|
||||
}
|
||||
return std::vector<float*>();
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
#include <map>
|
||||
#include <future>
|
||||
#include <ghoul/glm.h>
|
||||
#ifdef OPENSPACE_MODULE_KAMELEON_ENABLED
|
||||
#include <ccmc/Kameleon.h>
|
||||
#endif
|
||||
#include <openspace/engine/downloadmanager.h>
|
||||
#include <modules/kameleon/include/kameleonwrapper.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
set (DEFAULT_MODULE ON)
|
||||
set (OPENSPACE_DEPENDENCIES
|
||||
volume
|
||||
)
|
||||
@@ -127,6 +127,33 @@ void MultiresVolumeRaycaster::preRaycast(const RaycastData& data, ghoul::opengl:
|
||||
program.setUniform("atlasSize_" + id, atlasSize);
|
||||
}
|
||||
|
||||
bool MultiresVolumeRaycaster::cameraIsInside(const RenderData& data, glm::vec3& localPosition) {
|
||||
// Camera rig position in world coordinates.
|
||||
glm::vec4 rigWorldPos = glm::vec4(data.camera.position().vec3(), 1.0);
|
||||
//rigWorldPos /= data.camera.scaling().x * pow(10.0, data.camera.scaling().y);
|
||||
glm::mat4 invSgctMatrix = glm::inverse(data.camera.viewMatrix());
|
||||
|
||||
// Camera position in world coordinates.
|
||||
glm::vec4 camWorldPos = rigWorldPos;
|
||||
glm::vec3 objPos = data.position.vec3();
|
||||
|
||||
glm::mat4 modelTransform = glm::translate(_modelTransform, objPos);
|
||||
|
||||
float divisor = 1.0;
|
||||
for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) {
|
||||
if (abs(modelTransform[i][j] > divisor)) divisor = modelTransform[i][j];
|
||||
}
|
||||
|
||||
glm::mat4 scaledModelTransform = modelTransform / divisor;
|
||||
|
||||
glm::vec4 modelPos = (glm::inverse(scaledModelTransform) / divisor) * camWorldPos;
|
||||
|
||||
|
||||
localPosition = (modelPos.xyz() + glm::vec3(0.5));
|
||||
return (localPosition.x > 0 && localPosition.y > 0 && localPosition.z > 0 && localPosition.x < 1 && localPosition.y < 1 && localPosition.z < 1);
|
||||
|
||||
}
|
||||
|
||||
void MultiresVolumeRaycaster::postRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) {
|
||||
// For example: release texture units
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public:
|
||||
void renderExitPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) override;
|
||||
void preRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) override;
|
||||
void postRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) override;
|
||||
bool cameraIsInside(const RenderData& data, glm::vec3& localPosition) override;
|
||||
|
||||
std::string getBoundsVsPath() const override;
|
||||
std::string getBoundsFsPath() const override;
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableMultiresVolume";
|
||||
const std::string KeyDataSource = "Source";
|
||||
const std::string KeyErrorHistogramsSource = "ErrorHistogramsSource";
|
||||
const std::string KeyHints = "Hints";
|
||||
const std::string KeyTransferFunction = "TransferFunction";
|
||||
|
||||
@@ -124,6 +125,13 @@ RenderableMultiresVolume::RenderableMultiresVolume (const ghoul::Dictionary& dic
|
||||
return;
|
||||
}
|
||||
|
||||
_errorHistogramsPath = "";
|
||||
if (dictionary.getValue(KeyErrorHistogramsSource, _errorHistogramsPath)) {
|
||||
_errorHistogramsPath = absPath(_errorHistogramsPath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float scalingExponent, stepSizeCoefficient;
|
||||
glm::vec3 scaling, translation, rotation;
|
||||
|
||||
@@ -143,6 +151,7 @@ RenderableMultiresVolume::RenderableMultiresVolume (const ghoul::Dictionary& dic
|
||||
_stepSizeCoefficient = stepSizeCoefficient;
|
||||
}
|
||||
|
||||
|
||||
std::string startTimeString, endTimeString;
|
||||
bool hasTimeData = true;
|
||||
hasTimeData &= dictionary.getValue(KeyStartTime, startTimeString);
|
||||
@@ -354,7 +363,7 @@ bool RenderableMultiresVolume::initialize() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
onEnabledChange(onChange);
|
||||
|
||||
return success;
|
||||
}
|
||||
@@ -384,11 +393,16 @@ bool RenderableMultiresVolume::initializeSelector() {
|
||||
cacheFilename = FileSys.cacheManager()->cachedFilename(
|
||||
cacheName.str(), "", ghoul::filesystem::CacheManager::Persistent::Yes);
|
||||
std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary);
|
||||
std::string errorHistogramsPath = _errorHistogramsPath;
|
||||
if (cacheFile.is_open()) {
|
||||
// Read histograms from cache.
|
||||
cacheFile.close();
|
||||
LINFO("Loading histograms from " << cacheFilename);
|
||||
LINFO("Loading histograms from cache: " << cacheFilename);
|
||||
success &= _errorHistogramManager->loadFromFile(cacheFilename);
|
||||
} else if (_errorHistogramsPath != "") {
|
||||
// Read histograms from scene data.
|
||||
LINFO("Loading histograms from scene data: " << _errorHistogramsPath);
|
||||
success &= _errorHistogramManager->loadFromFile(_errorHistogramsPath);
|
||||
} else {
|
||||
// Build histograms from tsp file.
|
||||
LWARNING("Failed to open " << cacheFilename);
|
||||
|
||||
@@ -81,6 +81,9 @@ public:
|
||||
|
||||
virtual void update(const UpdateData& data) override;
|
||||
virtual void render(const RenderData& data, RendererTasks& tasks);
|
||||
|
||||
|
||||
|
||||
//virtual void preResolve(ghoul::opengl::ProgramObject* program) override;
|
||||
//virtual std::string getHeaderPath() override;
|
||||
//virtual std::string getHelperPath() override;
|
||||
@@ -120,6 +123,7 @@ private:
|
||||
std::string _volumeName;
|
||||
|
||||
std::string _transferFunctionPath;
|
||||
std::string _errorHistogramsPath;
|
||||
|
||||
std::shared_ptr<TransferFunction> _transferFunction;
|
||||
|
||||
|
||||
@@ -35,13 +35,11 @@ out vec4 worldPosition;
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main() {
|
||||
vPosition = vertPosition.xyz;
|
||||
worldPosition = modelTransform*vertPosition;
|
||||
|
||||
vec4 position = pscTransform(worldPosition, mat4(1.0));
|
||||
|
||||
// project the position to view space
|
||||
gl_Position = viewProjection * position;
|
||||
vPosition = vertPosition.xyz;
|
||||
|
||||
gl_Position.z = 1.0;
|
||||
worldPosition = vec4(vertPosition.xyz, 0.0);
|
||||
vec4 position = pscTransform(worldPosition, modelTransform);
|
||||
|
||||
// project the position to view space
|
||||
gl_Position = z_normalization(viewProjection * position);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,13 @@ float stepSize#{id}(vec3 samplePos, vec3 dir){
|
||||
}
|
||||
}
|
||||
|
||||
vec4 sample#{id}(vec3 samplePos, vec3 dir, vec4 foregroundColor, inout float maxStepSize) {
|
||||
void sample#{id}(vec3 samplePos,
|
||||
vec3 dir,
|
||||
inout vec3 accumulatedColor,
|
||||
inout vec3 accumulatedAlpha,
|
||||
inout float maxStepSize) {
|
||||
|
||||
//vec4 sample#{id}(vec3 samplePos, vec3 dir, vec4 foregroundColor, inout float maxStepSize) {
|
||||
//return vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
if (true /*opacity_#{id} >= MULTIRES_OPACITY_THRESHOLD*/) {
|
||||
@@ -85,23 +91,30 @@ vec4 sample#{id}(vec3 samplePos, vec3 dir, vec4 foregroundColor, inout float max
|
||||
//sampleCoords = vec3(1.0,0.0, 0.0);
|
||||
float intensity = texture(textureAtlas_#{id}, sampleCoords).x;
|
||||
//intensity = sampleCoords;
|
||||
|
||||
maxStepSize = stepSizeCoefficient_#{id}/float(maxNumBricksPerAxis_#{id})/float(paddedBrickDim_#{id});
|
||||
//return vec4(vec3(intensity), 1.0);
|
||||
vec4 contribution = texture(transferFunction_#{id}, intensity);
|
||||
|
||||
contribution.a = 1.0 - pow(1.0 - contribution.a, maxStepSize);
|
||||
//contribution = vec4(sampleCoords, 1.0);
|
||||
//vec4 contribution = vec4(vec3(intensity), 1.0);
|
||||
//contribution.a *= 0.3;
|
||||
//contribution = vec4(1.0, 1.0, 1.0, intensity * 1000000.0);
|
||||
//contribution = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
maxStepSize = stepSizeCoefficient_#{id}/float(maxNumBricksPerAxis_#{id})/float(paddedBrickDim_#{id});
|
||||
|
||||
//contribution.a *= opacity_#{id};
|
||||
|
||||
//maxStepSize = 0.01;
|
||||
return contribution;
|
||||
|
||||
vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha;
|
||||
accumulatedColor += oneMinusFrontAlpha * contribution.rgb * contribution.a;
|
||||
accumulatedAlpha += oneMinusFrontAlpha * vec3(contribution.a);
|
||||
|
||||
|
||||
//accumulatedAlpha = vec3(1.0-);
|
||||
//return contribution;
|
||||
} else {
|
||||
maxStepSize = 2.0;
|
||||
return vec4(0.0);
|
||||
//return vec4(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/instrumentdecoder.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/labelparser.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/projectioncomponent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/scannerdecoder.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/sequenceparser.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/targetdecoder.h
|
||||
@@ -55,6 +56,7 @@ set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/imagesequencer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/instrumentdecoder.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/labelparser.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/projectioncomponent.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/scannerdecoder.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/sequenceparser.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/util/targetdecoder.cpp
|
||||
@@ -64,16 +66,16 @@ source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/crawlingline_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/crawlingline_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fboPass_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fboPass_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fov_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fov_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectiveTexture_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectiveTexture_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectionPass_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/projectionPass_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/modelShader_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/modelShader_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableModel_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableModel_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableModelProjection_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableModelProjection_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderablePlanet_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderablePlanet_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderablePlanetProjection_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderablePlanetProjection_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/terminatorshadow_fs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/terminatorshadow_vs.glsl
|
||||
)
|
||||
|
||||
@@ -1,45 +1,37 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <modules/newhorizons/rendering/renderablemodelprojection.h>
|
||||
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include "imgui.h"
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <thread>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderableModelProjection";
|
||||
@@ -51,22 +43,6 @@ namespace {
|
||||
const std::string keyTextureColor = "Textures.Color";
|
||||
const std::string keyTextureProject = "Textures.Project";
|
||||
const std::string keyTextureDefault = "Textures.Default";
|
||||
|
||||
const std::string keySequenceDir = "Projection.Sequence";
|
||||
const std::string keySequenceType = "Projection.SequenceType";
|
||||
const std::string keyProjObserver = "Projection.Observer";
|
||||
const std::string keyProjTarget = "Projection.Target";
|
||||
const std::string keyProjAberration = "Projection.Aberration";
|
||||
|
||||
const std::string keyInstrument = "Instrument.Name";
|
||||
const std::string keyInstrumentFovy = "Instrument.Fovy";
|
||||
const std::string keyInstrumentAspect = "Instrument.Aspect";
|
||||
const std::string keyInstrumentNear = "Instrument.Near";
|
||||
const std::string keyInstrumentFar = "Instrument.Far";
|
||||
|
||||
const std::string keyTranslation = "DataInputTranslation";
|
||||
const std::string sequenceTypeImage = "image-sequence";
|
||||
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
@@ -74,24 +50,12 @@ namespace openspace {
|
||||
RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("colorTexture", "Color Texture")
|
||||
, _projectionTexturePath("projectionTexture", "RGB Texture")
|
||||
, _rotationX("rotationX", "RotationX", 0, 0, 360)
|
||||
, _rotationY("rotationY", "RotationY", 0, 0, 360)
|
||||
, _rotationZ("rotationZ", "RotationZ", 0, 0, 360)
|
||||
, _rotation("rotation", "Rotation", glm::vec3(0.f), glm::vec3(0.f), glm::vec3(360.f))
|
||||
, _programObject(nullptr)
|
||||
, _fboProgramObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _baseTexture(nullptr)
|
||||
, _geometry(nullptr)
|
||||
//, _textureOriginal(nullptr)
|
||||
, _textureProj(nullptr)
|
||||
, _textureWhiteSquare(nullptr)
|
||||
, _alpha(1.f)
|
||||
, _performShading("performShading", "Perform Shading", true)
|
||||
, _performProjection("performProjection", "Perform Projections", true)
|
||||
, _clearAllProjections("clearAllProjections", "Clear Projections", false)
|
||||
, _frameCount(0)
|
||||
, _programIsDirty(false)
|
||||
, _clearingImage(absPath("${OPENSPACE_DATA}/scene/common/textures/clear.png"))
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
@@ -100,8 +64,11 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di
|
||||
ghoul::Dictionary geometryDictionary;
|
||||
success = dictionary.getValue(keyGeometry, geometryDictionary);
|
||||
if (success) {
|
||||
using modelgeometry::ModelGeometry;
|
||||
geometryDictionary.setValue(SceneGraphNode::KeyName, name);
|
||||
_geometry = modelgeometry::ModelGeometry::createFromDictionary(geometryDictionary);
|
||||
_geometry = std::unique_ptr<ModelGeometry>(
|
||||
ModelGeometry::createFromDictionary(geometryDictionary)
|
||||
);
|
||||
}
|
||||
|
||||
std::string texturePath = "";
|
||||
@@ -109,20 +76,16 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di
|
||||
if (success)
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
|
||||
success = dictionary.getValue(keyTextureProject, texturePath);
|
||||
if (success)
|
||||
_projectionTexturePath = absPath(texturePath);
|
||||
|
||||
success = dictionary.getValue(keyTextureDefault, texturePath);
|
||||
if (success)
|
||||
_defaultProjImage = absPath(texturePath);
|
||||
|
||||
addPropertySubOwner(_geometry);
|
||||
addPropertySubOwner(_geometry.get());
|
||||
|
||||
addProperty(_projectionFading);
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
addProperty(_projectionTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&RenderableModelProjection::loadTexture, this));
|
||||
_projectionTexturePath.onChange(std::bind(&RenderableModelProjection::loadProjectionTexture, this));
|
||||
_colorTexturePath.onChange(std::bind(&RenderableModelProjection::loadTextures, this));
|
||||
|
||||
dictionary.getValue(keySource, _source);
|
||||
dictionary.getValue(keyDestination, _destination);
|
||||
@@ -131,20 +94,7 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di
|
||||
setBody(_target);
|
||||
|
||||
bool completeSuccess = true;
|
||||
completeSuccess &= dictionary.getValue(keyInstrument, _instrumentID);
|
||||
completeSuccess &= dictionary.getValue(keyProjObserver, _projectorID);
|
||||
completeSuccess &= dictionary.getValue(keyProjTarget, _projecteeID);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentFovy, _fovy);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentAspect, _aspectRatio);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentNear, _nearPlane);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentFar, _farPlane);
|
||||
ghoul_assert(completeSuccess, "All neccessary attributes not found in modfile");
|
||||
|
||||
std::string a = "NONE";
|
||||
bool s = dictionary.getValue(keyProjAberration, a);
|
||||
_aberration = SpiceManager::AberrationCorrection(a);
|
||||
completeSuccess &= s;
|
||||
ghoul_assert(completeSuccess, "All neccessary attributes not found in modfile");
|
||||
completeSuccess &= initializeProjectionSettings(dictionary);
|
||||
|
||||
openspace::SpiceManager::ref().addFrame(_target, _source);
|
||||
setBoundingSphere(pss(1.f, 9.f));
|
||||
@@ -152,310 +102,154 @@ RenderableModelProjection::RenderableModelProjection(const ghoul::Dictionary& di
|
||||
addProperty(_performShading);
|
||||
addProperty(_performProjection);
|
||||
addProperty(_clearAllProjections);
|
||||
addProperty(_rotationX);
|
||||
addProperty(_rotationY);
|
||||
addProperty(_rotationZ);
|
||||
|
||||
SequenceParser* parser;
|
||||
|
||||
bool foundSequence = dictionary.getValue(keySequenceDir, _sequenceSource);
|
||||
if (foundSequence) {
|
||||
_sequenceSource = absPath(_sequenceSource);
|
||||
|
||||
foundSequence = dictionary.getValue(keySequenceType, _sequenceType);
|
||||
ghoul_assert(foundSequence, "Did not find sequence");
|
||||
//Important: client must define translation-list in mod file IFF playbook
|
||||
if (dictionary.hasKey(keyTranslation)) {
|
||||
ghoul::Dictionary translationDictionary;
|
||||
//get translation dictionary
|
||||
dictionary.getValue(keyTranslation, translationDictionary);
|
||||
if (_sequenceType == sequenceTypeImage) {
|
||||
parser = new LabelParser(name, _sequenceSource, translationDictionary);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
LWARNING("No translation provided, please make sure all spice calls match playbook!");
|
||||
}
|
||||
}
|
||||
addProperty(_rotation);
|
||||
|
||||
success = initializeParser(dictionary);
|
||||
ghoul_assert(success, "");
|
||||
}
|
||||
|
||||
bool RenderableModelProjection::isReady() const {
|
||||
bool ready = true;
|
||||
ready &= (_programObject != nullptr);
|
||||
ready &= (_texture != nullptr);
|
||||
ready &= (_baseTexture != nullptr);
|
||||
ready &= (_projectionTexture != nullptr);
|
||||
return ready;
|
||||
}
|
||||
|
||||
bool RenderableModelProjection::initialize() {
|
||||
bool completeSuccess = true;
|
||||
|
||||
if (_programObject == nullptr) {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram("ModelShader",
|
||||
"${MODULE_NEWHORIZONS}/shaders/modelShader_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/modelShader_fs.glsl");
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram("ModelShader",
|
||||
"${MODULE_NEWHORIZONS}/shaders/renderableModel_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/renderableModel_fs.glsl");
|
||||
|
||||
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
_programObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*) { this->_programIsDirty = true; } );
|
||||
_fboProgramObject = ghoul::opengl::ProgramObject::Build("ProjectionPass",
|
||||
"${MODULE_NEWHORIZONS}/shaders/renderableModelProjection_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/renderableModelProjection_fs.glsl");
|
||||
_fboProgramObject->setIgnoreUniformLocationError(
|
||||
ghoul::opengl::ProgramObject::IgnoreError::Yes
|
||||
);
|
||||
|
||||
if (_fboProgramObject == nullptr) {
|
||||
_fboProgramObject = ghoul::opengl::ProgramObject::Build("ProjectionPass",
|
||||
"${MODULE_NEWHORIZONS}/shaders/projectionPass_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/projectionPass_fs.glsl");
|
||||
_fboProgramObject->setIgnoreUniformLocationError(ghoul::opengl::ProgramObject::IgnoreError::Yes);
|
||||
if (!_fboProgramObject)
|
||||
return false;
|
||||
}
|
||||
_fboProgramObject->setProgramObjectCallback([&](ghoul::opengl::ProgramObject*) { this->_programIsDirty = true; } );
|
||||
completeSuccess &= loadTextures();
|
||||
|
||||
loadTexture();
|
||||
loadProjectionTexture();
|
||||
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
//completeSuccess &= (_textureOriginal != nullptr);
|
||||
completeSuccess &= (_textureProj != nullptr);
|
||||
completeSuccess &= (_textureWhiteSquare != nullptr);
|
||||
completeSuccess &= ProjectionComponent::initialize();
|
||||
|
||||
completeSuccess &= _geometry->initialize(this);
|
||||
completeSuccess &= !_source.empty();
|
||||
completeSuccess &= !_destination.empty();
|
||||
|
||||
|
||||
bool gotverts = _geometry->getVertices(&_geometryVertecies) && _geometry->getIndices(&_geometryIndeces);
|
||||
if (!gotverts)
|
||||
LWARNING("Lack of vertex data from geometry for image projection");
|
||||
|
||||
completeSuccess &= auxiliaryRendertarget();
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderableModelProjection::auxiliaryRendertarget() {
|
||||
bool completeSuccess = true;
|
||||
// set FBO to texture to project to
|
||||
|
||||
GLint defaultFBO;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
|
||||
|
||||
glGenFramebuffers(1, &_fboID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *_texture, 0);
|
||||
// check FBO status
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
completeSuccess &= false;
|
||||
// switch back to window-system-provided framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
|
||||
int vertexSize = sizeof(modelgeometry::ModelGeometry::Vertex);
|
||||
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
glGenBuffers(1, &_vbo);
|
||||
glGenBuffers(1, &_ibo);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, _geometryVertecies.size() * vertexSize, &_geometryVertecies[0], GL_STATIC_DRAW);
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, vertexSize,
|
||||
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, location)));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, vertexSize,
|
||||
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, tex)));
|
||||
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, vertexSize,
|
||||
reinterpret_cast<const GLvoid*>(offsetof(modelgeometry::ModelGeometry::Vertex, normal)));
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, _geometryIndeces.size() * sizeof(int), &_geometryIndeces[0], GL_STATIC_DRAW);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderableModelProjection::deinitialize() {
|
||||
if (_geometry) {
|
||||
if (_geometry)
|
||||
_geometry->deinitialize();
|
||||
delete _geometry;
|
||||
}
|
||||
|
||||
_geometry = nullptr;
|
||||
_texture = nullptr;
|
||||
_textureProj = nullptr;
|
||||
//_textureOriginal = nullptr;
|
||||
_textureWhiteSquare = nullptr;
|
||||
_baseTexture = nullptr;
|
||||
|
||||
glDeleteBuffers(1, &_vbo);
|
||||
ProjectionComponent::deinitialize();
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderableModelProjection::clearAllProjections() {
|
||||
_texture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
|
||||
if (_texture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_texture->uploadTexture();
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
|
||||
GLint defaultFBO;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *_texture, 0);
|
||||
// check FBO status
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
// switch back to window-system-provided framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
|
||||
|
||||
//float tmp = _fadeProjection;
|
||||
//_fadeProjection = 1.f;
|
||||
//_projectionTexturePath = _clearingImage;
|
||||
//imageProjectGPU();
|
||||
//_fadeProjection = tmp;
|
||||
_clearAllProjections = false;
|
||||
}
|
||||
|
||||
void RenderableModelProjection::render(const RenderData& data) {
|
||||
if (!_programObject)
|
||||
return;
|
||||
if (!_textureProj)
|
||||
return;
|
||||
|
||||
if (_clearAllProjections)
|
||||
clearAllProjections();
|
||||
|
||||
_programObject->activate();
|
||||
_frameCount++;
|
||||
|
||||
_camScaling = data.camera.scaling();
|
||||
_up = data.camera.lookUpVector();
|
||||
|
||||
if (_capture && _performProjection)
|
||||
project();
|
||||
|
||||
_programObject->activate();
|
||||
|
||||
attitudeParameters(_time);
|
||||
_imageTimes.clear();
|
||||
|
||||
double time = openspace::Time::ref().currentTime();
|
||||
bool targetPositionCoverage = openspace::SpiceManager::ref().hasSpkCoverage(_target, time);
|
||||
if (!targetPositionCoverage) {
|
||||
int frame = _frameCount % 180;
|
||||
|
||||
float fadingFactor = static_cast<float>(sin((frame * M_PI) / 180));
|
||||
_alpha = 0.5f + fadingFactor * 0.5f;
|
||||
}
|
||||
else
|
||||
_alpha = 1.0f;
|
||||
|
||||
_programObject->setUniform("ProjectorMatrix", _projectorMatrix);
|
||||
_programObject->setUniform("boresight", _boresight);
|
||||
_programObject->setUniform("_performShading", _performShading);
|
||||
_programObject->setUniform("sun_pos", _sunPosition.vec3());
|
||||
_viewProjection = data.camera.viewProjectionMatrix();
|
||||
_programObject->setUniform("ViewProjection", _viewProjection);
|
||||
_programObject->setUniform("ViewProjection", data.camera.viewProjectionMatrix());
|
||||
_programObject->setUniform("ModelTransform", _transform);
|
||||
_programObject->setUniform("_projectionFading", _projectionFading);
|
||||
setPscUniforms(*_programObject, data.camera, data.position);
|
||||
|
||||
_geometry->setUniforms(*_programObject);
|
||||
|
||||
textureBind();
|
||||
ghoul::opengl::TextureUnit unit[2];
|
||||
unit[0].activate();
|
||||
_baseTexture->bind();
|
||||
_programObject->setUniform("baseTexture", unit[0]);
|
||||
|
||||
unit[1].activate();
|
||||
_projectionTexture->bind();
|
||||
_programObject->setUniform("projectionTexture", unit[1]);
|
||||
|
||||
_geometry->render();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void RenderableModelProjection::update(const UpdateData& data) {
|
||||
if (_programIsDirty) {
|
||||
if (_programObject->isDirty())
|
||||
_programObject->rebuildFromFile();
|
||||
|
||||
if (_fboProgramObject->isDirty())
|
||||
_fboProgramObject->rebuildFromFile();
|
||||
_programIsDirty = false;
|
||||
}
|
||||
|
||||
_time = data.time;
|
||||
|
||||
if (openspace::ImageSequencer::ref().isReady() && _performProjection) {
|
||||
openspace::ImageSequencer::ref().updateSequencer(_time);
|
||||
_capture = openspace::ImageSequencer::ref().getImagePaths(_imageTimes, _projecteeID, _instrumentID);
|
||||
_capture = openspace::ImageSequencer::ref().getImagePaths(
|
||||
_imageTimes, _projecteeID, _instrumentID
|
||||
);
|
||||
}
|
||||
|
||||
// set spice-orientation in accordance to timestamp
|
||||
if (!_source.empty()) {
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_source, _destination, _time);
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(
|
||||
_source, _destination, _time
|
||||
);
|
||||
}
|
||||
|
||||
double lt;
|
||||
double lt;
|
||||
glm::dvec3 p =
|
||||
openspace::SpiceManager::ref().targetPosition("SUN", _target, "GALACTIC", {}, _time, lt);
|
||||
openspace::SpiceManager::ref().targetPosition(
|
||||
"SUN", _target, "GALACTIC", {}, _time, lt
|
||||
);
|
||||
_sunPosition = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
}
|
||||
|
||||
void RenderableModelProjection::imageProjectGPU() {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
void RenderableModelProjection::imageProjectGPU(
|
||||
std::shared_ptr<ghoul::opengl::Texture> projectionTexture)
|
||||
{
|
||||
ProjectionComponent::imageProjectBegin();
|
||||
|
||||
// keep handle to the current bound FBO
|
||||
GLint defaultFBO;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
|
||||
|
||||
GLint m_viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, m_viewport);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
// set blend eq
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ZERO);
|
||||
|
||||
glViewport(0, 0, static_cast<GLsizei>(_texture->width()), static_cast<GLsizei>(_texture->height()));
|
||||
_fboProgramObject->activate();
|
||||
|
||||
ghoul::opengl::TextureUnit unitFboProject;
|
||||
unitFboProject.activate();
|
||||
_textureProj->bind();
|
||||
_fboProgramObject->setUniform("projectTexture", unitFboProject);
|
||||
ghoul::opengl::TextureUnit unitFbo;
|
||||
unitFbo.activate();
|
||||
projectionTexture->bind();
|
||||
_fboProgramObject->setUniform("projectionTexture", unitFbo);
|
||||
|
||||
ghoul::opengl::TextureUnit unitFboCurrent;
|
||||
unitFboCurrent.activate();
|
||||
_texture->bind();
|
||||
_fboProgramObject->setUniform("currentTexture", unitFboCurrent);
|
||||
_fboProgramObject->setUniform("ProjectorMatrix", _projectorMatrix);
|
||||
_fboProgramObject->setUniform("ModelTransform", _transform);
|
||||
_fboProgramObject->setUniform("_scaling", _camScaling);
|
||||
_fboProgramObject->setUniform("boresight", _boresight);
|
||||
|
||||
_geometry->setUniforms(*_fboProgramObject);
|
||||
_geometry->render();
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ibo);
|
||||
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(_geometryIndeces.size()), GL_UNSIGNED_INT, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
_fboProgramObject->deactivate();
|
||||
//glDisable(GL_BLEND);
|
||||
//bind back to default
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
glViewport(m_viewport[0], m_viewport[1],
|
||||
m_viewport[2], m_viewport[3]);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
ProjectionComponent::imageProjectEnd();
|
||||
}
|
||||
|
||||
void RenderableModelProjection::attitudeParameters(double time) {
|
||||
@@ -468,10 +262,21 @@ void RenderableModelProjection::attitudeParameters(double time) {
|
||||
}
|
||||
|
||||
_transform = glm::mat4(1);
|
||||
|
||||
glm::mat4 rotPropX = glm::rotate(_transform, glm::radians(static_cast<float>(_rotationX)), glm::vec3(1, 0, 0));
|
||||
glm::mat4 rotPropY = glm::rotate(_transform, glm::radians(static_cast<float>(_rotationY)), glm::vec3(0, 1, 0));
|
||||
glm::mat4 rotPropZ = glm::rotate(_transform, glm::radians(static_cast<float>(_rotationZ)), glm::vec3(0, 0, 1));
|
||||
glm::mat4 rotPropX = glm::rotate(
|
||||
_transform,
|
||||
glm::radians(static_cast<float>(_rotation.value().x)),
|
||||
glm::vec3(1, 0, 0)
|
||||
);
|
||||
glm::mat4 rotPropY = glm::rotate(
|
||||
_transform,
|
||||
glm::radians(static_cast<float>(_rotation.value().y)),
|
||||
glm::vec3(0, 1, 0)
|
||||
);
|
||||
glm::mat4 rotPropZ = glm::rotate(
|
||||
_transform,
|
||||
glm::radians(static_cast<float>(_rotation.value().z)),
|
||||
glm::vec3(0, 0, 1)
|
||||
);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
@@ -496,95 +301,33 @@ void RenderableModelProjection::attitudeParameters(double time) {
|
||||
position[3] += (3 + _camScaling[1]);
|
||||
glm::vec3 cpos = position.vec3();
|
||||
|
||||
_projectorMatrix = computeProjectorMatrix(cpos, boresight, _up);
|
||||
}
|
||||
|
||||
glm::mat4 RenderableModelProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up) {
|
||||
//rotate boresight into correct alignment
|
||||
_boresight = _instrumentMatrix*aim;
|
||||
glm::vec3 uptmp(_instrumentMatrix*glm::dvec3(up));
|
||||
|
||||
// create view matrix
|
||||
glm::vec3 e3 = glm::normalize(_boresight);
|
||||
glm::vec3 e1 = glm::normalize(glm::cross(uptmp, e3));
|
||||
glm::vec3 e2 = glm::normalize(glm::cross(e3, e1));
|
||||
glm::mat4 projViewMatrix = glm::mat4(e1.x, e2.x, e3.x, 0.f,
|
||||
e1.y, e2.y, e3.y, 0.f,
|
||||
e1.z, e2.z, e3.z, 0.f,
|
||||
-glm::dot(e1, loc), -glm::dot(e2, loc), -glm::dot(e3, loc), 1.f);
|
||||
|
||||
// create perspective projection matrix
|
||||
glm::mat4 projProjectionMatrix = glm::perspective(glm::radians(_fovy), _aspectRatio, _nearPlane, _farPlane);
|
||||
// bias matrix
|
||||
glm::mat4 projNormalizationMatrix = glm::mat4(0.5f, 0, 0, 0,
|
||||
0, 0.5f, 0, 0,
|
||||
0, 0, 0.5f, 0,
|
||||
0.5f, 0.5f, 0.5f, 1);
|
||||
return projNormalizationMatrix*projProjectionMatrix*projViewMatrix;
|
||||
}
|
||||
|
||||
|
||||
void RenderableModelProjection::textureBind() {
|
||||
ghoul::opengl::TextureUnit unit[2];
|
||||
unit[0].activate();
|
||||
_texture->bind();
|
||||
_programObject->setUniform("currentTexture", unit[0]);
|
||||
unit[1].activate();
|
||||
_textureWhiteSquare->bind();
|
||||
_programObject->setUniform("projectedTexture", unit[1]);
|
||||
_projectorMatrix = computeProjectorMatrix(cpos, boresight, _up, _instrumentMatrix,
|
||||
_fovy, _aspectRatio, _nearPlane, _farPlane, _boresight
|
||||
);
|
||||
}
|
||||
|
||||
void RenderableModelProjection::project() {
|
||||
for (auto img : _imageTimes) {
|
||||
//std::thread t1(&RenderableModelProjection::attitudeParameters, this, img.startTime);
|
||||
//t1.join();
|
||||
attitudeParameters(img.startTime);
|
||||
_projectionTexturePath = img.path;
|
||||
imageProjectGPU(); //fbopass
|
||||
imageProjectGPU(loadProjectionTexture(img.path));
|
||||
}
|
||||
_capture = false;
|
||||
}
|
||||
|
||||
void RenderableModelProjection::loadTexture() {
|
||||
_texture = nullptr;
|
||||
bool RenderableModelProjection::loadTextures() {
|
||||
_baseTexture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
|
||||
if (_texture) {
|
||||
_baseTexture = std::move(
|
||||
ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath))
|
||||
);
|
||||
if (_baseTexture) {
|
||||
LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
_texture->uploadTexture();
|
||||
_texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
//_textureOriginal = nullptr;
|
||||
//if (_colorTexturePath.value() != "") {
|
||||
// _textureOriginal = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_colorTexturePath)));
|
||||
// if (_textureOriginal) {
|
||||
// LDEBUG("Loaded texture from '" << absPath(_colorTexturePath) << "'");
|
||||
// _textureOriginal->uploadTexture();
|
||||
// _textureOriginal->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
// }
|
||||
//}
|
||||
_textureWhiteSquare = nullptr;
|
||||
if (_defaultProjImage != "") {
|
||||
_textureWhiteSquare = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_defaultProjImage)));
|
||||
if (_textureWhiteSquare) {
|
||||
_textureWhiteSquare->uploadTexture();
|
||||
_textureWhiteSquare->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableModelProjection::loadProjectionTexture() {
|
||||
_textureProj = nullptr;
|
||||
if (_projectionTexturePath.value() != "") {
|
||||
_textureProj = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath)));
|
||||
if (_textureProj) {
|
||||
_textureProj->uploadTexture();
|
||||
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
_textureProj->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
|
||||
_baseTexture->uploadTexture();
|
||||
_baseTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
|
||||
return _baseTexture != nullptr;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1,152 +1,104 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __RENDERABLEMODELPROJECTION_H__
|
||||
#define __RENDERABLEMODELPROJECTION_H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <modules/newhorizons/util/projectioncomponent.h>
|
||||
|
||||
#include <modules/base/rendering/modelgeometry.h>
|
||||
#include <modules/newhorizons/util/imagesequencer.h>
|
||||
#include <modules/newhorizons/util/labelparser.h>
|
||||
|
||||
#include <openspace/properties/numericalproperty.h>
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/vectorproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <modules/base/rendering/modelgeometry.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace modelgeometry {
|
||||
class ModelGeometry;
|
||||
}
|
||||
namespace modelgeometry {
|
||||
class ModelGeometry;
|
||||
}
|
||||
|
||||
class RenderableModelProjection : public Renderable {
|
||||
public:
|
||||
RenderableModelProjection(const ghoul::Dictionary& dictionary);
|
||||
class RenderableModelProjection : public Renderable, private ProjectionComponent {
|
||||
public:
|
||||
RenderableModelProjection(const ghoul::Dictionary& dictionary);
|
||||
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
bool initialize() override;
|
||||
bool deinitialize() override;
|
||||
|
||||
bool isReady() const override;
|
||||
bool isReady() const override;
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
|
||||
private:
|
||||
bool loadTextures();
|
||||
void attitudeParameters(double time);
|
||||
void imageProjectGPU(std::shared_ptr<ghoul::opengl::Texture> projectionTexture);
|
||||
|
||||
protected:
|
||||
void loadTexture();
|
||||
void loadProjectionTexture();
|
||||
void project();
|
||||
|
||||
private:
|
||||
bool auxiliaryRendertarget();
|
||||
glm::mat4 computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up);
|
||||
void attitudeParameters(double time);
|
||||
void imageProjectGPU();
|
||||
properties::StringProperty _colorTexturePath;
|
||||
|
||||
void textureBind();
|
||||
void project();
|
||||
void clearAllProjections();
|
||||
properties::Vec3Property _rotation;
|
||||
|
||||
properties::StringProperty _colorTexturePath;
|
||||
properties::BoolProperty _performProjection;
|
||||
properties::BoolProperty _clearAllProjections;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _fboProgramObject;
|
||||
|
||||
properties::IntProperty _rotationX;
|
||||
properties::IntProperty _rotationY;
|
||||
properties::IntProperty _rotationZ;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _baseTexture;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _fboProgramObject;
|
||||
std::unique_ptr<modelgeometry::ModelGeometry> _geometry;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _textureOriginal;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _textureProj;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _textureWhiteSquare;
|
||||
glm::dmat3 _stateMatrix;
|
||||
glm::dmat3 _instrumentMatrix;
|
||||
|
||||
modelgeometry::ModelGeometry* _geometry;
|
||||
std::string _defaultProjImage;
|
||||
std::string _source;
|
||||
std::string _destination;
|
||||
std::string _target;
|
||||
|
||||
float _alpha;
|
||||
glm::dmat3 _stateMatrix;
|
||||
glm::dmat3 _instrumentMatrix;
|
||||
// uniforms
|
||||
glm::vec2 _camScaling;
|
||||
glm::vec3 _up;
|
||||
glm::mat4 _transform;
|
||||
glm::mat4 _projectorMatrix;
|
||||
glm::vec3 _boresight;
|
||||
|
||||
properties::StringProperty _projectionTexturePath;
|
||||
std::string _defaultProjImage;
|
||||
std::string _source;
|
||||
std::string _destination;
|
||||
std::string _target;
|
||||
std::vector<Image> _imageTimes;
|
||||
double _time;
|
||||
|
||||
// sequence loading
|
||||
std::string _sequenceSource;
|
||||
std::string _sequenceType;
|
||||
|
||||
// projection mod info
|
||||
std::string _instrumentID;
|
||||
std::string _projectorID;
|
||||
std::string _projecteeID;
|
||||
SpiceManager::AberrationCorrection _aberration;
|
||||
std::vector<std::string> _potentialTargets;
|
||||
float _fovy;
|
||||
float _aspectRatio;
|
||||
float _nearPlane;
|
||||
float _farPlane;
|
||||
|
||||
// uniforms
|
||||
glm::vec2 _camScaling;
|
||||
glm::vec3 _up;
|
||||
glm::mat4 _transform;
|
||||
glm::mat4 _viewProjection;
|
||||
glm::mat4 _projectorMatrix;
|
||||
glm::vec3 _boresight;
|
||||
|
||||
// FBO stuff
|
||||
GLuint _fboID;
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
|
||||
GLuint _vbo;
|
||||
GLuint _ibo;
|
||||
GLuint _vaoID;
|
||||
std::vector<modelgeometry::ModelGeometry::Vertex> _geometryVertecies;
|
||||
std::vector<int> _geometryIndeces;
|
||||
|
||||
std::vector<Image> _imageTimes;
|
||||
int _frameCount;
|
||||
double _time;
|
||||
|
||||
bool _capture;
|
||||
bool _capture;
|
||||
|
||||
std::string _clearingImage;
|
||||
psc _sunPosition;
|
||||
|
||||
psc _sunPosition;
|
||||
|
||||
properties::BoolProperty _performShading;
|
||||
bool _programIsDirty;
|
||||
};
|
||||
properties::BoolProperty _performShading;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
|
||||
@@ -22,106 +22,58 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <modules/newhorizons/rendering/renderableplanetprojection.h>
|
||||
|
||||
#include <modules/base/rendering/planetgeometry.h>
|
||||
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <openspace/util/time.h>
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/textureconversion.h>
|
||||
//#include <ghoul/opengl/textureunit.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <openspace/util/time.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <openspace/util/factorymanager.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "RenderablePlanetProjection";
|
||||
const std::string keyProjObserver = "Projection.Observer";
|
||||
const std::string keyProjTarget = "Projection.Target";
|
||||
const std::string keyProjAberration = "Projection.Aberration";
|
||||
const std::string keyInstrument = "Instrument.Name";
|
||||
const std::string keyInstrumentFovy = "Instrument.Fovy";
|
||||
const std::string keyInstrumentAspect = "Instrument.Aspect";
|
||||
const std::string keyInstrumentNear = "Instrument.Near";
|
||||
const std::string keyInstrumentFar = "Instrument.Far";
|
||||
const std::string keySequenceDir = "Projection.Sequence";
|
||||
const std::string keySequenceType = "Projection.SequenceType";
|
||||
const std::string keyPotentialTargets = "PotentialTargets";
|
||||
const std::string keyTranslation = "DataInputTranslation";
|
||||
|
||||
|
||||
|
||||
const std::string keyFrame = "Frame";
|
||||
const std::string keyGeometry = "Geometry";
|
||||
const std::string keyShading = "PerformShading";
|
||||
const std::string keyBody = "Body";
|
||||
const std::string _mainFrame = "GALACTIC";
|
||||
const std::string sequenceTypeImage = "image-sequence";
|
||||
const std::string sequenceTypePlaybook = "playbook";
|
||||
const std::string sequenceTypeHybrid = "hybrid";
|
||||
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
//#define ORIGINAL_SEQUENCER
|
||||
|
||||
RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _colorTexturePath("planetTexture", "RGB Texture")
|
||||
, _heightMapTexturePath("heightMap", "Heightmap Texture")
|
||||
, _normalMapTexturePath("normalMap", "Normalmap Texture")
|
||||
, _projectionTexturePath("projectionTexture", "RGB Texture")
|
||||
, _rotation("rotation", "Rotation", 0, 0, 360)
|
||||
//, _fadeProjection("fadeProjections", "Image Fading Factor", 0.f, 0.f, 1.f)
|
||||
, _performProjection("performProjection", "Perform Projections", true)
|
||||
, _clearAllProjections("clearAllProjections", "Clear Projections", false)
|
||||
, _heightExaggeration("heightExaggeration", "Height Exaggeration", 1.f, 0.f, 100.f)
|
||||
, _enableNormalMapping("enableNormalMapping", "Enable Normal Mapping", true)
|
||||
, _debugProjectionTextureRotation("debug.projectionTextureRotation", "Projection Texture Rotation", 0.f, 0.f, 360.f)
|
||||
, _programObject(nullptr)
|
||||
, _fboProgramObject(nullptr)
|
||||
, _texture(nullptr)
|
||||
, _textureOriginal(nullptr)
|
||||
, _textureProj(nullptr)
|
||||
, _textureWhiteSquare(nullptr)
|
||||
, _baseTexture(nullptr)
|
||||
, _heightMapTexture(nullptr)
|
||||
, _normalMapTexture(nullptr)
|
||||
, _geometry(nullptr)
|
||||
, _capture(false)
|
||||
, _hasHeightMap(false)
|
||||
, _hasNormalMap(false)
|
||||
, _clearingImage(absPath("${OPENSPACE_DATA}/scene/common/textures/clear.png"))
|
||||
{
|
||||
std::string name;
|
||||
bool success = dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
ghoul_assert(success, "");
|
||||
|
||||
_defaultProjImage = absPath("textures/defaultProj.png");
|
||||
|
||||
ghoul::Dictionary geometryDictionary;
|
||||
success = dictionary.getValue(
|
||||
keyGeometry, geometryDictionary);
|
||||
if (success) {
|
||||
geometryDictionary.setValue(SceneGraphNode::KeyName, name);
|
||||
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geometryDictionary);
|
||||
using planetgeometry::PlanetGeometry;
|
||||
_geometry = std::unique_ptr<PlanetGeometry>(
|
||||
PlanetGeometry::createFromDictionary(geometryDictionary)
|
||||
);
|
||||
}
|
||||
|
||||
dictionary.getValue(keyFrame, _frame);
|
||||
@@ -129,38 +81,9 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
|
||||
if (_target != "")
|
||||
setBody(_target);
|
||||
|
||||
bool b1 = dictionary.getValue(keyInstrument, _instrumentID);
|
||||
bool b2 = dictionary.getValue(keyProjObserver, _projectorID);
|
||||
bool b3 = dictionary.getValue(keyProjTarget, _projecteeID);
|
||||
std::string a = "NONE";
|
||||
bool b4 = dictionary.getValue(keyProjAberration, a);
|
||||
_aberration = SpiceManager::AberrationCorrection(a);
|
||||
bool b5 = dictionary.getValue(keyInstrumentFovy, _fovy);
|
||||
bool b6 = dictionary.getValue(keyInstrumentAspect, _aspectRatio);
|
||||
bool b7 = dictionary.getValue(keyInstrumentNear, _nearPlane);
|
||||
bool b8 = dictionary.getValue(keyInstrumentFar, _farPlane);
|
||||
|
||||
ghoul_assert(b1, "");
|
||||
ghoul_assert(b2, "");
|
||||
ghoul_assert(b3, "");
|
||||
ghoul_assert(b4, "");
|
||||
ghoul_assert(b5, "");
|
||||
ghoul_assert(b6, "");
|
||||
ghoul_assert(b7, "");
|
||||
ghoul_assert(b8, "");
|
||||
|
||||
// @TODO copy-n-paste from renderablefov ---abock
|
||||
ghoul::Dictionary potentialTargets;
|
||||
success = dictionary.getValue(keyPotentialTargets, potentialTargets);
|
||||
success = initializeProjectionSettings(dictionary);
|
||||
ghoul_assert(success, "");
|
||||
|
||||
_potentialTargets.resize(potentialTargets.size());
|
||||
for (int i = 0; i < potentialTargets.size(); ++i) {
|
||||
std::string target;
|
||||
potentialTargets.getValue(std::to_string(i + 1), target);
|
||||
_potentialTargets[i] = target;
|
||||
}
|
||||
|
||||
// TODO: textures need to be replaced by a good system similar to the geometry as soon
|
||||
// as the requirements are fixed (ab)
|
||||
std::string texturePath = "";
|
||||
@@ -168,239 +91,111 @@ RenderablePlanetProjection::RenderablePlanetProjection(const ghoul::Dictionary&
|
||||
if (success){
|
||||
_colorTexturePath = absPath(texturePath);
|
||||
}
|
||||
success = dictionary.getValue("Textures.Project", texturePath);
|
||||
if (success){
|
||||
_projectionTexturePath = absPath(texturePath);
|
||||
}
|
||||
|
||||
std::string heightMapPath = "";
|
||||
success = dictionary.getValue("Textures.Height", heightMapPath);
|
||||
if (success) {
|
||||
if (success)
|
||||
_heightMapTexturePath = absPath(heightMapPath);
|
||||
_hasHeightMap = true;
|
||||
}
|
||||
|
||||
std::string normalMapPath = "";
|
||||
success = dictionary.getValue("Textures.NormalMap", normalMapPath);
|
||||
if (success) {
|
||||
_normalMapTexturePath = absPath(normalMapPath);
|
||||
_hasNormalMap = true;
|
||||
}
|
||||
|
||||
addPropertySubOwner(_geometry);
|
||||
addProperty(_rotation);
|
||||
//addProperty(_fadeProjection);
|
||||
addPropertySubOwner(_geometry.get());
|
||||
addProperty(_performProjection);
|
||||
addProperty(_clearAllProjections);
|
||||
|
||||
|
||||
addProperty(_colorTexturePath);
|
||||
_colorTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadTexture, this));
|
||||
_colorTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadTextures, this));
|
||||
|
||||
addProperty(_heightMapTexturePath);
|
||||
_heightMapTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadTexture, this));
|
||||
|
||||
addProperty(_normalMapTexturePath);
|
||||
_normalMapTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadTexture, this));
|
||||
|
||||
addProperty(_projectionTexturePath);
|
||||
_projectionTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadProjectionTexture, this));
|
||||
_heightMapTexturePath.onChange(std::bind(&RenderablePlanetProjection::loadTextures, this));
|
||||
|
||||
addProperty(_projectionFading);
|
||||
addProperty(_heightExaggeration);
|
||||
addProperty(_enableNormalMapping);
|
||||
addProperty(_debugProjectionTextureRotation);
|
||||
|
||||
SequenceParser* parser;
|
||||
|
||||
// std::string sequenceSource;
|
||||
bool _foundSequence = dictionary.getValue(keySequenceDir, _sequenceSource);
|
||||
if (_foundSequence) {
|
||||
_sequenceSource = absPath(_sequenceSource);
|
||||
|
||||
_foundSequence = dictionary.getValue(keySequenceType, _sequenceType);
|
||||
//Important: client must define translation-list in mod file IFF playbook
|
||||
if (dictionary.hasKey(keyTranslation)){
|
||||
ghoul::Dictionary translationDictionary;
|
||||
//get translation dictionary
|
||||
dictionary.getValue(keyTranslation, translationDictionary);
|
||||
|
||||
if (_sequenceType == sequenceTypePlaybook) {
|
||||
parser = new HongKangParser(name,
|
||||
_sequenceSource,
|
||||
_projectorID,
|
||||
translationDictionary,
|
||||
_potentialTargets);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
}
|
||||
else if (_sequenceType == sequenceTypeImage) {
|
||||
parser = new LabelParser(name,
|
||||
_sequenceSource,
|
||||
translationDictionary);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
}
|
||||
else if (_sequenceType == sequenceTypeHybrid) {
|
||||
//first read labels
|
||||
parser = new LabelParser(name,
|
||||
_sequenceSource,
|
||||
translationDictionary);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
|
||||
std::string _eventFile;
|
||||
bool foundEventFile = dictionary.getValue("Projection.EventFile", _eventFile);
|
||||
if (foundEventFile){
|
||||
//then read playbook
|
||||
_eventFile = absPath(_eventFile);
|
||||
parser = new HongKangParser(name,
|
||||
_eventFile,
|
||||
_projectorID,
|
||||
translationDictionary,
|
||||
_potentialTargets);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
}
|
||||
else{
|
||||
LWARNING("No eventfile has been provided, please check modfiles");
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
LWARNING("No playbook translation provided, please make sure all spice calls match playbook!");
|
||||
}
|
||||
}
|
||||
success = initializeParser(dictionary);
|
||||
ghoul_assert(success, "");
|
||||
}
|
||||
|
||||
RenderablePlanetProjection::~RenderablePlanetProjection() {
|
||||
deinitialize();
|
||||
}
|
||||
RenderablePlanetProjection::~RenderablePlanetProjection() {}
|
||||
|
||||
bool RenderablePlanetProjection::initialize() {
|
||||
bool completeSuccess = true;
|
||||
if (_programObject == nullptr) {
|
||||
// projection program
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
_programObject = renderEngine.buildRenderProgram("projectiveProgram",
|
||||
"${MODULE_NEWHORIZONS}/shaders/projectiveTexture_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/projectiveTexture_fs.glsl"
|
||||
);
|
||||
|
||||
if (!_programObject)
|
||||
return false;
|
||||
}
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram("projectiveProgram",
|
||||
"${MODULE_NEWHORIZONS}/shaders/renderablePlanet_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/renderablePlanet_fs.glsl"
|
||||
);
|
||||
|
||||
_fboProgramObject = ghoul::opengl::ProgramObject::Build("fboPassProgram",
|
||||
"${MODULE_NEWHORIZONS}/shaders/fboPass_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/fboPass_fs.glsl"
|
||||
"${MODULE_NEWHORIZONS}/shaders/renderablePlanetProjection_vs.glsl",
|
||||
"${MODULE_NEWHORIZONS}/shaders/renderablePlanetProjection_fs.glsl"
|
||||
);
|
||||
|
||||
loadTexture();
|
||||
loadProjectionTexture();
|
||||
completeSuccess &= (_texture != nullptr);
|
||||
completeSuccess &= (_textureOriginal != nullptr);
|
||||
completeSuccess &= (_textureProj != nullptr);
|
||||
completeSuccess &= (_textureWhiteSquare != nullptr);
|
||||
|
||||
completeSuccess &= loadTextures();
|
||||
completeSuccess &= ProjectionComponent::initialize();
|
||||
|
||||
completeSuccess &= _geometry->initialize(this);
|
||||
|
||||
if (completeSuccess)
|
||||
completeSuccess &= auxiliaryRendertarget();
|
||||
if (completeSuccess) {
|
||||
//completeSuccess &= auxiliaryRendertarget();
|
||||
// SCREEN-QUAD
|
||||
const GLfloat size = 1.f;
|
||||
const GLfloat w = 1.f;
|
||||
const GLfloat vertex_data[] = {
|
||||
-size, -size, 0.f, w, 0.f, 0.f,
|
||||
size, size, 0.f, w, 1.f, 1.f,
|
||||
-size, size, 0.f, w, 0.f, 1.f,
|
||||
-size, -size, 0.f, w, 0.f, 0.f,
|
||||
size, -size, 0.f, w, 1.f, 0.f,
|
||||
size, size, 0.f, w, 1.f, 1.f,
|
||||
};
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
glGenVertexArrays(1, &_quad);
|
||||
glBindVertexArray(_quad);
|
||||
glGenBuffers(1, &_vertexPositionBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
|
||||
|
||||
bool RenderablePlanetProjection::auxiliaryRendertarget() {
|
||||
bool completeSuccess = true;
|
||||
if (!_texture) return false;
|
||||
|
||||
GLint defaultFBO;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
|
||||
|
||||
// setup FBO
|
||||
glGenFramebuffers(1, &_fboID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *_texture, 0);
|
||||
// check FBO status
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
completeSuccess &= false;
|
||||
// switch back to window-system-provided framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
|
||||
// SCREEN-QUAD
|
||||
const GLfloat size = 1.f;
|
||||
const GLfloat w = 1.f;
|
||||
const GLfloat vertex_data[] = {
|
||||
-size, -size, 0.f, w, 0.f, 0.f,
|
||||
size, size, 0.f, w, 1.f, 1.f,
|
||||
-size, size, 0.f, w, 0.f, 1.f,
|
||||
-size, -size, 0.f, w, 0.f, 0.f,
|
||||
size, -size, 0.f, w, 1.f, 0.f,
|
||||
size, size, 0.f, w, 1.f, 1.f,
|
||||
};
|
||||
|
||||
glGenVertexArrays(1, &_quad);
|
||||
glBindVertexArray(_quad);
|
||||
glGenBuffers(1, &_vertexPositionBuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(0));
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast<void*>(sizeof(GLfloat) * 4));
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool RenderablePlanetProjection::deinitialize() {
|
||||
_texture = nullptr;
|
||||
_textureProj = nullptr;
|
||||
_textureOriginal = nullptr;
|
||||
_textureWhiteSquare = nullptr;
|
||||
delete _geometry;
|
||||
ProjectionComponent::deinitialize();
|
||||
_baseTexture = nullptr;
|
||||
_geometry = nullptr;
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
}
|
||||
glDeleteVertexArrays(1, &_quad);
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
|
||||
OsEng.renderEngine().removeRenderProgram(_programObject);
|
||||
_programObject = nullptr;
|
||||
|
||||
_fboProgramObject = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
bool RenderablePlanetProjection::isReady() const {
|
||||
return _geometry && _programObject && _texture && _textureWhiteSquare;
|
||||
return _geometry && _programObject && _baseTexture && _projectionTexture;
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::imageProjectGPU() {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
void RenderablePlanetProjection::imageProjectGPU(
|
||||
std::shared_ptr<ghoul::opengl::Texture> projectionTexture)
|
||||
{
|
||||
imageProjectBegin();
|
||||
|
||||
// keep handle to the current bound FBO
|
||||
GLint defaultFBO;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
|
||||
|
||||
GLint m_viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, m_viewport);
|
||||
//counter = 0;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
// set blend eq
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ZERO);
|
||||
|
||||
glViewport(0, 0, static_cast<GLsizei>(_texture->width()), static_cast<GLsizei>(_texture->height()));
|
||||
_fboProgramObject->activate();
|
||||
|
||||
ghoul::opengl::TextureUnit unitFbo;
|
||||
unitFbo.activate();
|
||||
_textureProj->bind();
|
||||
_fboProgramObject->setUniform("texture1" , unitFbo);
|
||||
projectionTexture->bind();
|
||||
_fboProgramObject->setUniform("projectionTexture", unitFbo);
|
||||
|
||||
ghoul::opengl::TextureUnit unitFbo2;
|
||||
unitFbo2.activate();
|
||||
_textureOriginal->bind();
|
||||
_fboProgramObject->setUniform("texture2", unitFbo2);
|
||||
//_fboProgramObject->setUniform("projectionFading", _fadeProjection);
|
||||
|
||||
_fboProgramObject->setUniform("ProjectorMatrix", _projectorMatrix);
|
||||
_fboProgramObject->setUniform("ModelTransform" , _transform);
|
||||
_fboProgramObject->setUniform("_scaling" , _camScaling);
|
||||
@@ -426,49 +221,34 @@ void RenderablePlanetProjection::imageProjectGPU() {
|
||||
glBindVertexArray(_quad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
_fboProgramObject->deactivate();
|
||||
//glDisable(GL_BLEND);
|
||||
|
||||
//bind back to default
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
glViewport(m_viewport[0], m_viewport[1],
|
||||
m_viewport[2], m_viewport[3]);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
glm::mat4 RenderablePlanetProjection::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up) {
|
||||
//rotate boresight into correct alignment
|
||||
_boresight = _instrumentMatrix*aim;
|
||||
glm::vec3 uptmp(_instrumentMatrix*glm::dvec3(up));
|
||||
|
||||
// create view matrix
|
||||
glm::vec3 e3 = glm::normalize(_boresight);
|
||||
glm::vec3 e1 = glm::normalize(glm::cross(uptmp, e3));
|
||||
glm::vec3 e2 = glm::normalize(glm::cross(e3, e1));
|
||||
glm::mat4 projViewMatrix = glm::mat4(e1.x, e2.x, e3.x, 0.f,
|
||||
e1.y, e2.y, e3.y, 0.f,
|
||||
e1.z, e2.z, e3.z, 0.f,
|
||||
-glm::dot(e1, loc), -glm::dot(e2, loc), -glm::dot(e3, loc), 1.f);
|
||||
// create perspective projection matrix
|
||||
glm::mat4 projProjectionMatrix = glm::perspective(glm::radians(_fovy), _aspectRatio, _nearPlane, _farPlane);
|
||||
// bias matrix
|
||||
glm::mat4 projNormalizationMatrix = glm::mat4(0.5f, 0, 0, 0,
|
||||
0, 0.5f, 0, 0,
|
||||
0, 0, 0.5f, 0,
|
||||
0.5f, 0.5f, 0.5f, 1);
|
||||
return projNormalizationMatrix*projProjectionMatrix*projViewMatrix;
|
||||
imageProjectEnd();
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::attitudeParameters(double time) {
|
||||
// precomputations for shader
|
||||
_stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, _mainFrame, time);
|
||||
_instrumentMatrix = SpiceManager::ref().positionTransformMatrix(_instrumentID, _mainFrame, time);
|
||||
_instrumentMatrix = SpiceManager::ref().positionTransformMatrix(
|
||||
_instrumentID, _mainFrame, time
|
||||
);
|
||||
|
||||
_transform = glm::mat4(1);
|
||||
//90 deg rotation w.r.t spice req.
|
||||
glm::mat4 rot = glm::rotate(_transform, static_cast<float>(M_PI_2), glm::vec3(1, 0, 0));
|
||||
glm::mat4 roty = glm::rotate(_transform, static_cast<float>(M_PI_2), glm::vec3(0, -1, 0));
|
||||
glm::mat4 rotProp = glm::rotate(_transform, static_cast<float>(glm::radians(static_cast<float>(_rotation))), glm::vec3(0, 1, 0));
|
||||
glm::mat4 rot = glm::rotate(
|
||||
_transform,
|
||||
static_cast<float>(M_PI_2),
|
||||
glm::vec3(1, 0, 0)
|
||||
);
|
||||
glm::mat4 roty = glm::rotate(
|
||||
_transform,
|
||||
static_cast<float>(M_PI_2),
|
||||
glm::vec3(0, -1, 0)
|
||||
);
|
||||
glm::mat4 rotProp = glm::rotate(
|
||||
_transform,
|
||||
static_cast<float>(glm::radians(static_cast<float>(_rotation))),
|
||||
glm::vec3(0, 1, 0)
|
||||
);
|
||||
|
||||
for (int i = 0; i < 3; i++){
|
||||
for (int j = 0; j < 3; j++){
|
||||
@@ -487,7 +267,10 @@ void RenderablePlanetProjection::attitudeParameters(double time) {
|
||||
return;
|
||||
}
|
||||
|
||||
glm::dvec3 p = SpiceManager::ref().targetPosition(_projectorID, _projecteeID, _mainFrame, _aberration, time, lightTime);
|
||||
double lightTime;
|
||||
glm::dvec3 p = SpiceManager::ref().targetPosition(
|
||||
_projectorID, _projecteeID, _mainFrame, _aberration, time, lightTime
|
||||
);
|
||||
psc position = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
|
||||
//change to KM and add psc camera scaling.
|
||||
@@ -495,90 +278,25 @@ void RenderablePlanetProjection::attitudeParameters(double time) {
|
||||
//position[3] += 3;
|
||||
glm::vec3 cpos = position.vec3();
|
||||
|
||||
_projectorMatrix = computeProjectorMatrix(cpos, bs, _up);
|
||||
}
|
||||
|
||||
|
||||
void RenderablePlanetProjection::textureBind() {
|
||||
ghoul::opengl::TextureUnit unit[4];
|
||||
unit[0].activate();
|
||||
_texture->bind();
|
||||
_programObject->setUniform("texture1", unit[0]);
|
||||
unit[1].activate();
|
||||
_textureWhiteSquare->bind();
|
||||
_programObject->setUniform("texture2", unit[1]);
|
||||
|
||||
if (_hasHeightMap) {
|
||||
unit[2].activate();
|
||||
_heightMapTexture->bind();
|
||||
_programObject->setUniform("heightTex", unit[2]);
|
||||
}
|
||||
|
||||
if (_hasNormalMap) {
|
||||
unit[3].activate();
|
||||
_normalMapTexture->bind();
|
||||
_programObject->setUniform("normalTex", unit[3]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::project(){
|
||||
// If high dt -> results in GPU queue overflow
|
||||
// switching to using a simple queue to distribute
|
||||
// images 1 image / frame -> projections appear slower
|
||||
// but less viewable lagg for the sim overall.
|
||||
|
||||
// Comment out if not using queue and prefer old method -------------
|
||||
// + in update() function
|
||||
//if (!imageQueue.empty()){
|
||||
// Image& img = imageQueue.front();
|
||||
// RenderablePlanetProjection::attitudeParameters(img.startTime);
|
||||
// // if image has new path - ie actual image, NOT placeholder
|
||||
// if (_projectionTexturePath.value() != img.path){
|
||||
// // rebind and upload
|
||||
// _projectionTexturePath = img.path;
|
||||
// }
|
||||
// imageProjectGPU(); // fbopass
|
||||
// imageQueue.pop();
|
||||
//}
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
//---- Old method --- //
|
||||
// @mm
|
||||
for (const Image& img : _imageTimes) {
|
||||
RenderablePlanetProjection::attitudeParameters(img.startTime);
|
||||
if (_projectionTexturePath.value() != img.path){
|
||||
_projectionTexturePath = img.path; // path to current images
|
||||
}
|
||||
imageProjectGPU(); // fbopass
|
||||
}
|
||||
_capture = false;
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::clearAllProjections() {
|
||||
//float tmp = _fadeProjection;
|
||||
//_fadeProjection = 1.f;
|
||||
_projectionTexturePath = _clearingImage;
|
||||
imageProjectGPU();
|
||||
//_fadeProjection = tmp;
|
||||
_clearAllProjections = false;
|
||||
_projectorMatrix = computeProjectorMatrix(cpos, bs, _up, _instrumentMatrix,
|
||||
_fovy, _aspectRatio, _nearPlane, _farPlane, _boresight
|
||||
);
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::render(const RenderData& data) {
|
||||
if (!_programObject)
|
||||
return;
|
||||
if (!_textureProj)
|
||||
return;
|
||||
|
||||
if (_clearAllProjections)
|
||||
clearAllProjections();
|
||||
|
||||
_camScaling = data.camera.scaling();
|
||||
_up = data.camera.lookUpVector();
|
||||
|
||||
if (_capture && _performProjection)
|
||||
project();
|
||||
if (_capture && _performProjection) {
|
||||
for (const Image& img : _imageTimes) {
|
||||
RenderablePlanetProjection::attitudeParameters(img.startTime);
|
||||
imageProjectGPU(loadProjectionTexture(img.path));
|
||||
}
|
||||
_capture = false;
|
||||
}
|
||||
attitudeParameters(_time);
|
||||
_imageTimes.clear();
|
||||
|
||||
@@ -589,102 +307,66 @@ void RenderablePlanetProjection::render(const RenderData& data) {
|
||||
|
||||
// Main renderpass
|
||||
_programObject->activate();
|
||||
// setup the data to the shader
|
||||
_programObject->setUniform("sun_pos", sun_pos.vec3());
|
||||
_programObject->setUniform("ProjectorMatrix", _projectorMatrix);
|
||||
_programObject->setUniform("ViewProjection" , data.camera.viewProjectionMatrix());
|
||||
_programObject->setUniform("ModelTransform" , _transform);
|
||||
_programObject->setUniform("boresight" , _boresight);
|
||||
|
||||
_programObject->setUniform("_hasHeightMap", _hasHeightMap);
|
||||
_programObject->setUniform("_hasHeightMap", _heightMapTexture != nullptr);
|
||||
_programObject->setUniform("_heightExaggeration", _heightExaggeration);
|
||||
_programObject->setUniform("_enableNormalMapping", _enableNormalMapping && _hasNormalMap);
|
||||
_programObject->setUniform("_projectionFading", _projectionFading);
|
||||
|
||||
//_programObject->setUniform("debug_projectionTextureRotation", glm::radians(_debugProjectionTextureRotation.value()));
|
||||
|
||||
setPscUniforms(*_programObject.get(), data.camera, data.position);
|
||||
|
||||
textureBind();
|
||||
ghoul::opengl::TextureUnit unit[3];
|
||||
unit[0].activate();
|
||||
_baseTexture->bind();
|
||||
_programObject->setUniform("baseTexture", unit[0]);
|
||||
|
||||
unit[1].activate();
|
||||
_projectionTexture->bind();
|
||||
_programObject->setUniform("projectionTexture", unit[1]);
|
||||
|
||||
if (_heightMapTexture) {
|
||||
unit[2].activate();
|
||||
_heightMapTexture->bind();
|
||||
_programObject->setUniform("heightTexture", unit[2]);
|
||||
}
|
||||
|
||||
// render geometry
|
||||
_geometry->render();
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::update(const UpdateData& data) {
|
||||
//if (data.isTimeJump) {
|
||||
if (_time >= Time::ref().currentTime()) {
|
||||
// if jump back in time -> empty queue.
|
||||
imageQueue = std::queue<Image>();
|
||||
if (_fboProgramObject->isDirty()) {
|
||||
_fboProgramObject->rebuildFromFile();
|
||||
}
|
||||
|
||||
//_time = data.time;
|
||||
if (_programObject->isDirty())
|
||||
_programObject->rebuildFromFile();
|
||||
|
||||
_time = Time::ref().currentTime();
|
||||
_capture = false;
|
||||
|
||||
if (openspace::ImageSequencer::ref().isReady() && _performProjection){
|
||||
openspace::ImageSequencer::ref().updateSequencer(_time);
|
||||
_capture = openspace::ImageSequencer::ref().getImagePaths(_imageTimes, _projecteeID, _instrumentID);
|
||||
_capture = openspace::ImageSequencer::ref().getImagePaths(
|
||||
_imageTimes, _projecteeID, _instrumentID
|
||||
);
|
||||
}
|
||||
|
||||
if (_fboProgramObject && _fboProgramObject->isDirty()) {
|
||||
_fboProgramObject->rebuildFromFile();
|
||||
}
|
||||
|
||||
// remove these lines if not using queue ------------------------
|
||||
// @mm
|
||||
//_capture = true;
|
||||
//for (auto img : _imageTimes){
|
||||
// imageQueue.push(img);
|
||||
//}
|
||||
//_imageTimes.clear();
|
||||
// --------------------------------------------------------------
|
||||
|
||||
if (_programObject->isDirty())
|
||||
_programObject->rebuildFromFile();
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::loadProjectionTexture() {
|
||||
_textureProj = nullptr;
|
||||
if (_projectionTexturePath.value() != "") {
|
||||
_textureProj = ghoul::io::TextureReader::ref().loadTexture(absPath(_projectionTexturePath));
|
||||
if (_textureProj) {
|
||||
ghoul::opengl::convertTextureFormat(ghoul::opengl::Texture::Format::RGB, *_textureProj);
|
||||
_textureProj->uploadTexture();
|
||||
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
|
||||
//_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
|
||||
_textureProj->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderablePlanetProjection::loadTexture() {
|
||||
bool RenderablePlanetProjection::loadTextures() {
|
||||
using ghoul::opengl::Texture;
|
||||
_texture = nullptr;
|
||||
_baseTexture = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_texture = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
|
||||
if (_texture) {
|
||||
ghoul::opengl::convertTextureFormat(Texture::Format::RGB, *_texture);
|
||||
_texture->uploadTexture();
|
||||
_texture->setFilter(Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
_textureOriginal = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_textureOriginal = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
|
||||
if (_textureOriginal) {
|
||||
ghoul::opengl::convertTextureFormat(Texture::Format::RGB, *_textureOriginal);
|
||||
|
||||
_textureOriginal->uploadTexture();
|
||||
_textureOriginal->setFilter(Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
_textureWhiteSquare = nullptr;
|
||||
if (_colorTexturePath.value() != "") {
|
||||
_textureWhiteSquare = ghoul::io::TextureReader::ref().loadTexture(_defaultProjImage);
|
||||
if (_textureWhiteSquare) {
|
||||
_textureWhiteSquare->uploadTexture();
|
||||
_textureWhiteSquare->setFilter(Texture::FilterMode::Linear);
|
||||
_baseTexture = ghoul::io::TextureReader::ref().loadTexture(_colorTexturePath);
|
||||
if (_baseTexture) {
|
||||
ghoul::opengl::convertTextureFormat(Texture::Format::RGB, *_baseTexture);
|
||||
_baseTexture->uploadTexture();
|
||||
_baseTexture->setFilter(Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,14 +380,8 @@ void RenderablePlanetProjection::loadTexture() {
|
||||
}
|
||||
}
|
||||
|
||||
_normalMapTexture = nullptr;
|
||||
if (_normalMapTexturePath.value() != "") {
|
||||
_normalMapTexture = ghoul::io::TextureReader::ref().loadTexture(_normalMapTexturePath);
|
||||
if (_normalMapTexture) {
|
||||
_normalMapTexture->uploadTexture();
|
||||
_normalMapTexture->setFilter(Texture::FilterMode::Linear);
|
||||
}
|
||||
}
|
||||
return _baseTexture != nullptr;
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -25,40 +25,25 @@
|
||||
#ifndef __RENDERABLEPLANETPROJECTION_H__
|
||||
#define __RENDERABLEPLANETPROJECTION_H__
|
||||
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <modules/newhorizons/util/projectioncomponent.h>
|
||||
|
||||
#include <modules/newhorizons/util/imagesequencer.h>
|
||||
|
||||
#include <modules/newhorizons/util/sequenceparser.h>
|
||||
#include <modules/newhorizons/util/hongkangparser.h>
|
||||
#include <modules/newhorizons/util/labelparser.h>
|
||||
#include <modules/newhorizons/util/decoder.h>
|
||||
|
||||
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
#include <openspace/properties/triggerproperty.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <ghoul/opengl/framebufferobject.h>
|
||||
|
||||
// ghoul includes
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
#include <openspace/query/query.h>
|
||||
|
||||
#include <queue>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
namespace planetgeometry{
|
||||
class PlanetGeometry;
|
||||
namespace planetgeometry {
|
||||
class PlanetGeometry;
|
||||
}
|
||||
|
||||
|
||||
class RenderablePlanetProjection : public Renderable {
|
||||
class RenderablePlanetProjection : public Renderable, private ProjectionComponent {
|
||||
public:
|
||||
RenderablePlanetProjection(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanetProjection();
|
||||
@@ -67,105 +52,56 @@ public:
|
||||
bool deinitialize() override;
|
||||
bool isReady() const override;
|
||||
|
||||
|
||||
void render(const RenderData& data) override;
|
||||
void update(const UpdateData& data) override;
|
||||
ghoul::opengl::Texture* baseTexture() { return _texture.get(); };
|
||||
ghoul::opengl::Texture* baseTexture() { return _projectionTexture.get(); };
|
||||
|
||||
protected:
|
||||
|
||||
void loadTexture();
|
||||
void loadProjectionTexture();
|
||||
bool auxiliaryRendertarget();
|
||||
glm::mat4 computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up);
|
||||
bool loadTextures();
|
||||
void attitudeParameters(double time);
|
||||
|
||||
void textureBind();
|
||||
void project();
|
||||
void clearAllProjections();
|
||||
|
||||
private:
|
||||
void imageProjectGPU();
|
||||
void imageProjectGPU(std::shared_ptr<ghoul::opengl::Texture> projectionTexture);
|
||||
|
||||
std::map<std::string, Decoder*> _fileTranslation;
|
||||
|
||||
properties::StringProperty _colorTexturePath;
|
||||
properties::StringProperty _colorTexturePath;
|
||||
properties::StringProperty _heightMapTexturePath;
|
||||
properties::StringProperty _normalMapTexturePath;
|
||||
|
||||
properties::StringProperty _projectionTexturePath;
|
||||
properties::IntProperty _rotation;
|
||||
//properties::FloatProperty _fadeProjection;
|
||||
properties::BoolProperty _performProjection;
|
||||
properties::BoolProperty _clearAllProjections;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _fboProgramObject;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _textureOriginal;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _textureProj;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _textureWhiteSquare;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _baseTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _heightMapTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _normalMapTexture;
|
||||
|
||||
properties::FloatProperty _heightExaggeration;
|
||||
properties::BoolProperty _enableNormalMapping;
|
||||
properties::FloatProperty _debugProjectionTextureRotation;
|
||||
|
||||
planetgeometry::PlanetGeometry* _geometry;
|
||||
std::unique_ptr<planetgeometry::PlanetGeometry> _geometry;
|
||||
|
||||
glm::vec2 _camScaling;
|
||||
glm::vec3 _up;
|
||||
glm::mat4 _transform;
|
||||
glm::mat4 _projectorMatrix;
|
||||
|
||||
//sequenceloading
|
||||
std::string _sequenceSource;
|
||||
std::string _sequenceType;
|
||||
bool _foundSequence;
|
||||
|
||||
// spice
|
||||
std::string _instrumentID;
|
||||
std::string _projectorID;
|
||||
std::string _projecteeID;
|
||||
SpiceManager::AberrationCorrection _aberration;
|
||||
std::vector<std::string> _potentialTargets; // @TODO copy-n-paste from renderablefov
|
||||
|
||||
|
||||
float _fovy;
|
||||
float _aspectRatio;
|
||||
float _nearPlane;
|
||||
float _farPlane;
|
||||
glm::vec2 _camScaling;
|
||||
glm::vec3 _up;
|
||||
glm::mat4 _transform;
|
||||
glm::mat4 _projectorMatrix;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
glm::dmat3 _instrumentMatrix;
|
||||
glm::vec3 _boresight;
|
||||
glm::vec3 _boresight;
|
||||
|
||||
double _time;
|
||||
double _previousTime;
|
||||
double _previousCapture;
|
||||
double lightTime;
|
||||
|
||||
std::vector<Image> _imageTimes;
|
||||
int _sequenceID;
|
||||
|
||||
std::string _target;
|
||||
std::string _frame;
|
||||
std::string _defaultProjImage;
|
||||
std::string _clearingImage;
|
||||
std::string _next;
|
||||
|
||||
bool _capture;
|
||||
|
||||
// FBO stuff
|
||||
GLuint _fboID;
|
||||
GLuint _quad;
|
||||
GLuint _vertexPositionBuffer;
|
||||
|
||||
bool _hasHeightMap;
|
||||
bool _hasNormalMap;
|
||||
|
||||
std::queue<Image> imageQueue;
|
||||
};
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __RENDERABLEPLANETPROJECTION_H__
|
||||
#endif // __RENDERABLEPLANETPROJECTION_H__
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/engine/configurationmanager.h>
|
||||
#include <modules/newhorizons/rendering/renderableshadowcylinder.h>
|
||||
@@ -80,8 +80,7 @@ namespace openspace {
|
||||
ghoul_assert(success, "");
|
||||
}
|
||||
|
||||
RenderableShadowCylinder::~RenderableShadowCylinder() {
|
||||
}
|
||||
RenderableShadowCylinder::~RenderableShadowCylinder() {}
|
||||
|
||||
bool RenderableShadowCylinder::isReady() const {
|
||||
bool ready = true;
|
||||
@@ -103,6 +102,8 @@ bool RenderableShadowCylinder::initialize() {
|
||||
|
||||
if (!_shader)
|
||||
return false;
|
||||
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
//uniform vec3 camdir; // add this for specular
|
||||
|
||||
|
||||
uniform float time;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
uniform sampler2D heightTex;
|
||||
uniform sampler2D normalTex;
|
||||
|
||||
uniform bool _enableNormalMapping;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
|
||||
in vec4 ProjTexCoord;
|
||||
|
||||
uniform vec3 boresight;
|
||||
uniform vec3 sun_pos;
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 position = vs_position;
|
||||
float depth = pscDepth(position);
|
||||
vec4 diffuse = texture(texture1, vs_st);
|
||||
// vec4 diffuse = texture(heightTex, vs_st);
|
||||
|
||||
// directional lighting
|
||||
vec3 origin = vec3(0.0);
|
||||
vec4 spec = vec4(0.0);
|
||||
|
||||
// vec3 n = normalize(texture(normalTex, vs_st).xyz);
|
||||
|
||||
vec3 n = normalize(vs_normal.xyz);
|
||||
// n = vec3(0);
|
||||
// vec3 n = vec3(0);
|
||||
|
||||
if (_enableNormalMapping) {
|
||||
n = n + normalize(texture(normalTex, vs_st).xyz);
|
||||
}
|
||||
//vec3 e = normalize(camdir);
|
||||
vec3 l_pos = sun_pos; // sun.
|
||||
vec3 l_dir = normalize(l_pos-objpos.xyz);
|
||||
float terminatorBright = 0.4;
|
||||
float intensity = min(max(5*dot(n,l_dir), terminatorBright), 1);
|
||||
|
||||
float shine = 0.0001;
|
||||
|
||||
vec4 specular = vec4(0.1);
|
||||
vec4 ambient = vec4(0.f,0.f,0.f,1);
|
||||
/* Specular
|
||||
if(intensity > 0.f){
|
||||
// halfway vector
|
||||
vec3 h = normalize(l_dir + e);
|
||||
// specular factor
|
||||
float intSpec = max(dot(h,n),0.0);
|
||||
spec = specular * pow(intSpec, shine);
|
||||
}
|
||||
*/
|
||||
//diffuse = max(intensity * diffuse, ambient);
|
||||
|
||||
// PROJECTIVE TEXTURE
|
||||
vec4 projTexColor = textureProj(texture2, ProjTexCoord);
|
||||
vec4 shaded = max(intensity * diffuse, ambient);
|
||||
if (ProjTexCoord[0] > 0.0 ||
|
||||
ProjTexCoord[1] > 0.0 ||
|
||||
ProjTexCoord[0] < ProjTexCoord[2] ||
|
||||
ProjTexCoord[1] < ProjTexCoord[2]){
|
||||
diffuse = shaded;
|
||||
} else if (dot(n,boresight) < 0 &&
|
||||
(projTexColor.w != 0)) {// frontfacing
|
||||
diffuse = projTexColor;//*0.5f + 0.5f*shaded;
|
||||
} else {
|
||||
diffuse = shaded;
|
||||
}
|
||||
|
||||
Fragment frag;
|
||||
frag.color = diffuse;
|
||||
// frag.color = vec4(normalize(vs_position.xyz), 1.0);
|
||||
|
||||
// frag.color = vec4(vec3(texture(heightTex, vs_st).r), 1.0);
|
||||
// frag.color = texture(heightTex, vs_st);
|
||||
// frag.color = vec4(n, 1.0);
|
||||
// frag.color = test;
|
||||
frag.depth = depth;
|
||||
//frag.color = vec4(vs_st, 0.0, 1.0);
|
||||
return frag;
|
||||
}
|
||||
@@ -24,23 +24,20 @@
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform sampler2D projectTexture;
|
||||
uniform sampler2D currentTexture;
|
||||
|
||||
uniform mat4 ProjectorMatrix;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec2 _scaling;
|
||||
uniform vec3 boresight;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
in vec4 vs_position;
|
||||
in vec4 ProjTexCoord;
|
||||
in vec2 vs_uv;
|
||||
in vec4 vs_normal;
|
||||
in vec2 vs_uv;
|
||||
in vec4 ProjTexCoord;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
uniform sampler2D projectionTexture;
|
||||
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec2 _scaling;
|
||||
uniform vec3 boresight;
|
||||
|
||||
bool inRange(float x, float a, float b) {
|
||||
return (x >= a && x <= b);
|
||||
@@ -57,12 +54,9 @@ void main() {
|
||||
projected.y /= projected.w;
|
||||
//invert gl coordinates
|
||||
projected.x = 1 - projected.x;
|
||||
// projected.y = 1 - projected.y;
|
||||
|
||||
if((inRange(projected.x, 0, 1) && inRange(projected.y, 0, 1)) && (dot(n, boresight) < 0)) {
|
||||
color = texture(projectTexture, projected.xy);
|
||||
} else {
|
||||
color = texture(currentTexture, uv);
|
||||
color = texture(projectionTexture, projected.xy);
|
||||
color.a = 1.0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,22 +24,22 @@
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ProjectorMatrix;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec2 _scaling;
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
layout(location = 2) in vec3 in_normal;
|
||||
|
||||
uniform vec3 boresight;
|
||||
|
||||
out vec4 vs_position;
|
||||
out vec4 ProjTexCoord;
|
||||
out vec2 vs_uv;
|
||||
out vec4 vs_normal;
|
||||
out vec2 vs_uv;
|
||||
out vec4 ProjTexCoord;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
uniform mat4 ProjectorMatrix;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec2 _scaling;
|
||||
|
||||
uniform vec3 boresight;
|
||||
|
||||
void main() {
|
||||
vs_position = in_position;
|
||||
@@ -22,30 +22,26 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
in vec4 vs_position;
|
||||
in vec4 vs_normal;
|
||||
in vec2 vs_st;
|
||||
|
||||
uniform vec4 campos;
|
||||
uniform vec4 objpos;
|
||||
uniform vec3 camdir;
|
||||
|
||||
uniform float time;
|
||||
uniform sampler2D currentTexture;
|
||||
uniform sampler2D projectedTexture;
|
||||
uniform sampler2D baseTexture;
|
||||
uniform sampler2D projectionTexture;
|
||||
uniform bool _performShading;
|
||||
|
||||
in vec2 vs_st;
|
||||
in vec4 vs_normal;
|
||||
in vec4 vs_position;
|
||||
|
||||
in vec4 ProjTexCoord;
|
||||
uniform vec3 boresight;
|
||||
uniform float _projectionFading;
|
||||
uniform vec3 sun_pos;
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 position = vs_position;
|
||||
float depth = pscDepth(position);
|
||||
vec4 diffuse = texture(currentTexture, vs_st);
|
||||
|
||||
// directional lighting
|
||||
vec3 origin = vec3(0.0);
|
||||
@@ -58,34 +54,32 @@ Fragment getFragment() {
|
||||
float intensity = 1;
|
||||
|
||||
if (_performShading) {
|
||||
float terminatorBright = 0.4;
|
||||
intensity = min(max(5*dot(n,l_dir), terminatorBright), 1);
|
||||
const float terminatorBrightness = 0.4;
|
||||
intensity = min(max(5*dot(n,l_dir), terminatorBrightness), 1.0);
|
||||
}
|
||||
|
||||
float shine = 0.0001;
|
||||
vec4 specular = vec4(0.1);
|
||||
vec4 ambient = vec4(0.f,0.f,0.f,1);
|
||||
vec4 ambient = vec4(vec3(0.0), 1.0);
|
||||
//Specular
|
||||
if (intensity > 0.f) {
|
||||
if (intensity > 0.0) {
|
||||
vec3 h = normalize(l_dir + e);
|
||||
float intSpec = max(dot(h,n),0.0);
|
||||
spec = specular * pow(intSpec, shine);
|
||||
}
|
||||
|
||||
vec4 projTexColor = textureProj(projectedTexture, ProjTexCoord);
|
||||
vec4 shaded = max(intensity * diffuse, ambient);
|
||||
if (ProjTexCoord[0] > 0.0 || ProjTexCoord[1] > 0.0 ||
|
||||
ProjTexCoord[0] < ProjTexCoord[2] ||
|
||||
ProjTexCoord[1] < ProjTexCoord[2]) {
|
||||
diffuse = shaded;
|
||||
} else if (dot(n, boresight) < 0 && projTexColor.w != 0) {// frontfacing
|
||||
diffuse = projTexColor;
|
||||
} else {
|
||||
diffuse = shaded;
|
||||
vec4 textureColor = texture(baseTexture, vs_st);
|
||||
vec4 projectionColor = texture(projectionTexture, vs_st);
|
||||
if (projectionColor.a != 0.0) {
|
||||
textureColor.rgb = mix(
|
||||
textureColor.rgb,
|
||||
projectionColor.rgb,
|
||||
min(_projectionFading, projectionColor.a)
|
||||
);
|
||||
}
|
||||
|
||||
Fragment frag;
|
||||
frag.color = diffuse;
|
||||
frag.color = max(intensity * textureColor, ambient);
|
||||
frag.depth = depth;
|
||||
return frag;
|
||||
}
|
||||
@@ -24,26 +24,21 @@
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform mat4 ProjectorMatrix;
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
layout(location = 2) in vec3 in_normal;
|
||||
|
||||
uniform vec3 boresight;
|
||||
out vec4 vs_position;
|
||||
out vec4 vs_normal;
|
||||
out vec2 vs_st;
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
|
||||
uniform float _magnification;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_position;
|
||||
out float s;
|
||||
out vec4 ProjTexCoord;
|
||||
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
void main() {
|
||||
vec4 pos = in_position;
|
||||
pos.w += _magnification;
|
||||
@@ -56,8 +51,6 @@ void main() {
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_position = tmp;
|
||||
|
||||
vec4 raw_pos = psc_to_meter(pos, scaling);
|
||||
ProjTexCoord = ProjectorMatrix * ModelTransform * raw_pos;
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
}
|
||||
@@ -24,22 +24,22 @@
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
in vec4 vs_position;
|
||||
out vec4 color;
|
||||
|
||||
uniform sampler2D projectionTexture;
|
||||
|
||||
uniform mat4 ProjectorMatrix;
|
||||
uniform mat4 ModelTransform;
|
||||
|
||||
uniform vec2 _scaling;
|
||||
uniform vec4 _radius;
|
||||
uniform int _segments;
|
||||
|
||||
uniform float projectionFading;
|
||||
|
||||
in vec4 vs_position;
|
||||
|
||||
uniform vec3 boresight;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
vec4 uvToModel(vec2 uv, vec4 radius, float segments){
|
||||
@@ -58,38 +58,31 @@ vec4 uvToModel(vec2 uv, vec4 radius, float segments){
|
||||
return vec4(0.0);
|
||||
}
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
bool inRange(float x, float a, float b){
|
||||
return (x >= a && x <= b);
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 uv = (vs_position.xy + vec2(1.0)) / vec2(2.0);
|
||||
|
||||
vec4 vertex = uvToModel(uv, _radius, _segments);
|
||||
|
||||
vec4 raw_pos = psc_to_meter(vertex, _scaling);
|
||||
vec4 projected = ProjectorMatrix * ModelTransform * raw_pos;
|
||||
|
||||
projected.x /= projected.w;
|
||||
projected.y /= projected.w;
|
||||
|
||||
vec3 normal = normalize((ModelTransform*vec4(vertex.xyz,0)).xyz);
|
||||
|
||||
vec3 v_b = normalize(boresight);
|
||||
|
||||
if((inRange(projected.x, 0, 1) &&
|
||||
vec2 uv = (vs_position.xy + vec2(1.0)) / vec2(2.0);
|
||||
|
||||
vec4 vertex = uvToModel(uv, _radius, _segments);
|
||||
|
||||
vec4 raw_pos = psc_to_meter(vertex, _scaling);
|
||||
vec4 projected = ProjectorMatrix * ModelTransform * raw_pos;
|
||||
|
||||
projected.x /= projected.w;
|
||||
projected.y /= projected.w;
|
||||
|
||||
vec3 normal = normalize((ModelTransform*vec4(vertex.xyz,0)).xyz);
|
||||
|
||||
vec3 v_b = normalize(boresight);
|
||||
|
||||
if((inRange(projected.x, 0, 1) &&
|
||||
inRange(projected.y, 0, 1)) &&
|
||||
dot(v_b, normal) < 0 )
|
||||
{
|
||||
{
|
||||
// The 1-x is in this texture call because of flipped textures
|
||||
// to be fixed soon ---abock
|
||||
color = texture(texture1, vec2(projected.x, 1-projected.y));
|
||||
}else{
|
||||
color = texture(texture2, uv);
|
||||
color.a = projectionFading;
|
||||
}
|
||||
|
||||
// color.a = 0.1f;//1.f - abs(uv.x - 0.55) / (0.6 - 0.5); // blending
|
||||
color = texture(projectionTexture, vec2(projected.x, 1-projected.y));
|
||||
}
|
||||
}
|
||||
@@ -24,21 +24,13 @@
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
uniform mat4 ProjectorMatrix;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec2 _scaling;
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
|
||||
uniform vec3 boresight;
|
||||
uniform vec2 radius;
|
||||
|
||||
out vec4 vs_position;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main() {
|
||||
vs_position = in_position;
|
||||
gl_Position = vec4(in_position.xy, 0.0, 1.0);
|
||||
|
||||
}
|
||||
76
modules/newhorizons/shaders/renderablePlanet_fs.glsl
Normal file
76
modules/newhorizons/shaders/renderablePlanet_fs.glsl
Normal file
@@ -0,0 +1,76 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
in vec4 vs_position;
|
||||
in vec4 vs_normal;
|
||||
in vec2 vs_st;
|
||||
|
||||
uniform sampler2D baseTexture;
|
||||
uniform sampler2D projectionTexture;
|
||||
|
||||
uniform float _projectionFading;
|
||||
|
||||
uniform vec4 objpos;
|
||||
uniform vec3 sun_pos;
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 position = vs_position;
|
||||
float depth = pscDepth(position);
|
||||
|
||||
// directional lighting
|
||||
vec3 origin = vec3(0.0);
|
||||
vec4 spec = vec4(0.0);
|
||||
|
||||
vec3 n = normalize(vs_normal.xyz);
|
||||
|
||||
vec3 l_pos = sun_pos; // sun.
|
||||
vec3 l_dir = normalize(l_pos-objpos.xyz);
|
||||
float terminatorBrightness = 0.4;
|
||||
float intensity = min(max(5*dot(n,l_dir), terminatorBrightness), 1);
|
||||
|
||||
float shine = 0.0001;
|
||||
|
||||
vec4 specular = vec4(0.1);
|
||||
vec4 ambient = vec4(0.f,0.f,0.f,1);
|
||||
|
||||
vec4 textureColor = texture(baseTexture, vs_st);
|
||||
vec4 projectionColor = texture(projectionTexture, vs_st);
|
||||
if (projectionColor.a != 0.0) {
|
||||
textureColor.rgb = mix(
|
||||
textureColor.rgb,
|
||||
projectionColor.rgb,
|
||||
min(_projectionFading, projectionColor.a)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Fragment frag;
|
||||
frag.color = max(intensity * textureColor, ambient);
|
||||
frag.depth = depth;
|
||||
|
||||
return frag;
|
||||
}
|
||||
@@ -27,37 +27,24 @@
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
layout(location = 0) in vec4 in_position;
|
||||
//in vec3 in_position;
|
||||
layout(location = 1) in vec2 in_st;
|
||||
layout(location = 2) in vec3 in_normal;
|
||||
|
||||
uniform vec3 boresight;
|
||||
|
||||
out vec2 vs_st;
|
||||
out vec4 vs_normal;
|
||||
out vec4 vs_position;
|
||||
out float s;
|
||||
out vec4 ProjTexCoord;
|
||||
out vec4 vs_normal;
|
||||
out vec2 vs_st;
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
|
||||
//texture projection matrix
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ProjectorMatrix;
|
||||
|
||||
uniform bool _hasHeightMap;
|
||||
uniform float _heightExaggeration;
|
||||
uniform sampler2D heightTex;
|
||||
|
||||
uniform sampler2D heightTexture;
|
||||
|
||||
void main() {
|
||||
// Radius = 0.71492 *10^8;
|
||||
// set variables
|
||||
vs_st = in_st;
|
||||
//vs_stp = in_position.xyz;
|
||||
// vs_position = in_position;
|
||||
vec4 tmp = in_position;
|
||||
vec4 tmp = in_position;
|
||||
|
||||
// this is wrong for the normal.
|
||||
// The normal transform is the transposed inverse of the model transform
|
||||
@@ -65,19 +52,15 @@ void main() {
|
||||
|
||||
|
||||
if (_hasHeightMap) {
|
||||
float height = texture(heightTex, in_st).r;
|
||||
// float height = 0.00005;
|
||||
float height = texture(heightTexture, in_st).r;
|
||||
vec3 displacementDirection = (normalize(tmp.xyz));
|
||||
float displacementFactor = height * _heightExaggeration / 2500.0;
|
||||
float displacementFactor = height * _heightExaggeration / 750.0;
|
||||
tmp.xyz = tmp.xyz + displacementDirection * displacementFactor;
|
||||
}
|
||||
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_position = tmp;
|
||||
|
||||
vec4 raw_pos = psc_to_meter(tmp, scaling);
|
||||
ProjTexCoord = ProjectorMatrix * ModelTransform * raw_pos;
|
||||
|
||||
position = ViewProjection * position;
|
||||
|
||||
gl_Position = z_normalization(position);
|
||||
@@ -313,6 +313,7 @@ void HongKangParser::createImage(Image& image, double startTime, double stopTime
|
||||
}
|
||||
image.target = targ;
|
||||
image.projected = false;
|
||||
image.isPlaceholder = true;
|
||||
}
|
||||
|
||||
double HongKangParser::getETfromMet(std::string line){
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
// open space includes
|
||||
#include <modules/newhorizons/util/imagesequencer.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -164,8 +163,7 @@ const Image ImageSequencer::getLatestImageForInstrument(const std::string _instr
|
||||
if (it != _latestImages.end())
|
||||
return _latestImages[_instrumentID];
|
||||
else {
|
||||
Image dummyImage = { 0, 0, "", std::vector<std::string>(), "", false };
|
||||
return dummyImage;
|
||||
return Image();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,15 +191,16 @@ std::map<std::string, bool> ImageSequencer::getActiveInstruments(){
|
||||
// return entire map, seen in GUI.
|
||||
return _switchingMap;
|
||||
}
|
||||
bool ImageSequencer::instrumentActive(std::string instrumentID){
|
||||
for (auto i : _instrumentTimes){
|
||||
|
||||
bool ImageSequencer::instrumentActive(std::string instrumentID) {
|
||||
for (const auto& i : _instrumentTimes) {
|
||||
//check if this instrument is in range
|
||||
if (i.second.inRange(_currentTime)){
|
||||
if (i.second.inRange(_currentTime)) {
|
||||
//if so, then get the corresponding spiceID
|
||||
std::vector<std::string> spiceIDs = _fileTranslation[i.first]->getTranslation();
|
||||
//check which specific subinstrument is firing
|
||||
for (auto s : spiceIDs){
|
||||
if (s == instrumentID){
|
||||
for (auto s : spiceIDs) {
|
||||
if (s == instrumentID) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -211,7 +210,7 @@ bool ImageSequencer::instrumentActive(std::string instrumentID){
|
||||
}
|
||||
|
||||
float ImageSequencer::instrumentActiveTime(const std::string& instrumentID) const {
|
||||
for (auto i : _instrumentTimes){
|
||||
for (const auto& i : _instrumentTimes){
|
||||
//check if this instrument is in range
|
||||
if (i.second.inRange(_currentTime)){
|
||||
//if so, then get the corresponding spiceID
|
||||
@@ -262,7 +261,8 @@ bool ImageSequencer::getImagePaths(std::vector<Image>& captures,
|
||||
if (curr->startTime >= prev->startTime){
|
||||
std::copy_if(prev, curr, back_inserter(captureTimes),
|
||||
[instrumentRequest](const Image& i) {
|
||||
return i.activeInstruments[0] == instrumentRequest;
|
||||
bool correctInstrument = i.activeInstruments[0] == instrumentRequest;
|
||||
return correctInstrument;
|
||||
});
|
||||
|
||||
//std::reverse(captureTimes.begin(), captureTimes.end());
|
||||
@@ -270,13 +270,41 @@ bool ImageSequencer::getImagePaths(std::vector<Image>& captures,
|
||||
if (!captures.empty())
|
||||
_latestImages[captures.back().activeInstruments.front()] = captures.back();
|
||||
|
||||
std::vector<int> toDelete;
|
||||
for (auto it = captures.begin(); it != captures.end(); ++it) {
|
||||
if (it->isPlaceholder) {
|
||||
double beforeDist = std::numeric_limits<double>::max();
|
||||
if (it != captures.begin()) {
|
||||
auto before = std::prev(it);
|
||||
beforeDist = abs(before->startTime - it->startTime);
|
||||
}
|
||||
|
||||
double nextDist = std::numeric_limits<double>::max();
|
||||
if (it != captures.end() - 1) {
|
||||
auto next = std::next(it);
|
||||
nextDist = abs(next->startTime - it->startTime);
|
||||
}
|
||||
|
||||
if (beforeDist < 1.0 || nextDist < 1.0) {
|
||||
toDelete.push_back(std::distance(captures.begin(), it));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < toDelete.size(); ++i) {
|
||||
// We have to subtract i here as we already have deleted i value
|
||||
// before this and we need to adjust the location
|
||||
int v = toDelete[i] - i;
|
||||
captures.erase(captures.begin() + v);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void ImageSequencer::sortData(){
|
||||
void ImageSequencer::sortData() {
|
||||
auto targetComparer = [](const std::pair<double, std::string> &a,
|
||||
const std::pair<double, std::string> &b)->bool{
|
||||
return a.first < b.first;
|
||||
@@ -292,6 +320,14 @@ void ImageSequencer::sortData(){
|
||||
std::sort(_subsetMap[sub.first]._subset.begin(),
|
||||
_subsetMap[sub.first]._subset.end(), imageComparer);
|
||||
}
|
||||
|
||||
std::sort(
|
||||
_instrumentTimes.begin(),
|
||||
_instrumentTimes.end(),
|
||||
[](const std::pair<std::string, TimeRange>& a, const std::pair<std::string, TimeRange>& b) {
|
||||
return a.second._min < b.second._min;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void ImageSequencer::runSequenceParser(SequenceParser* parser){
|
||||
|
||||
346
modules/newhorizons/util/projectioncomponent.cpp
Normal file
346
modules/newhorizons/util/projectioncomponent.cpp
Normal file
@@ -0,0 +1,346 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <modules/newhorizons/util/projectioncomponent.h>
|
||||
|
||||
#include <modules/newhorizons/util/hongkangparser.h>
|
||||
#include <modules/newhorizons/util/imagesequencer.h>
|
||||
#include <modules/newhorizons/util/labelparser.h>
|
||||
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/io/texture/texturereader.h>
|
||||
#include <ghoul/opengl/textureconversion.h>
|
||||
#include <ghoul/systemcapabilities/openglcapabilitiescomponent.h>
|
||||
|
||||
namespace {
|
||||
const std::string keyPotentialTargets = "PotentialTargets";
|
||||
|
||||
const std::string keyInstrument = "Instrument.Name";
|
||||
const std::string keyInstrumentFovy = "Instrument.Fovy";
|
||||
const std::string keyInstrumentAspect = "Instrument.Aspect";
|
||||
const std::string keyInstrumentNear = "Instrument.Near";
|
||||
const std::string keyInstrumentFar = "Instrument.Far";
|
||||
|
||||
const std::string keyProjObserver = "Projection.Observer";
|
||||
const std::string keyProjTarget = "Projection.Target";
|
||||
const std::string keyProjAberration = "Projection.Aberration";
|
||||
|
||||
const std::string keySequenceDir = "Projection.Sequence";
|
||||
const std::string keySequenceType = "Projection.SequenceType";
|
||||
const std::string keyTranslation = "DataInputTranslation";
|
||||
|
||||
const std::string sequenceTypeImage = "image-sequence";
|
||||
const std::string sequenceTypePlaybook = "playbook";
|
||||
const std::string sequenceTypeHybrid = "hybrid";
|
||||
|
||||
const std::string placeholderFile =
|
||||
"${OPENSPACE_DATA}/scene/common/textures/placeholder.png";
|
||||
|
||||
const std::string _loggerCat = "ProjectionComponent";
|
||||
}
|
||||
|
||||
namespace openspace {
|
||||
|
||||
using ghoul::Dictionary;
|
||||
|
||||
ProjectionComponent::ProjectionComponent()
|
||||
: _performProjection("performProjection", "Perform Projections", true)
|
||||
, _clearAllProjections("clearAllProjections", "Clear Projections", false)
|
||||
, _projectionFading("projectionFading", "Projection Fading", 1.f, 0.f, 1.f)
|
||||
, _projectionTexture(nullptr)
|
||||
{}
|
||||
|
||||
bool ProjectionComponent::initialize() {
|
||||
bool a = generateProjectionLayerTexture();
|
||||
bool b = auxiliaryRendertarget();
|
||||
|
||||
using std::unique_ptr;
|
||||
using ghoul::opengl::Texture;
|
||||
using ghoul::io::TextureReader;
|
||||
|
||||
unique_ptr<Texture> texture = TextureReader::ref().loadTexture(absPath(placeholderFile));
|
||||
if (texture) {
|
||||
texture->uploadTexture();
|
||||
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
|
||||
//_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
texture->setFilter(Texture::FilterMode::Linear);
|
||||
texture->setWrapping(Texture::WrappingMode::ClampToBorder);
|
||||
}
|
||||
_placeholderTexture = std::move(texture);
|
||||
|
||||
return a && b;
|
||||
}
|
||||
|
||||
bool ProjectionComponent::deinitialize() {
|
||||
_projectionTexture = nullptr;
|
||||
|
||||
glDeleteFramebuffers(1, &_fboID);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectionComponent::initializeProjectionSettings(const Dictionary& dictionary) {
|
||||
bool completeSuccess = true;
|
||||
completeSuccess &= dictionary.getValue(keyInstrument, _instrumentID);
|
||||
completeSuccess &= dictionary.getValue(keyProjObserver, _projectorID);
|
||||
completeSuccess &= dictionary.getValue(keyProjTarget, _projecteeID);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentFovy, _fovy);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentAspect, _aspectRatio);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentNear, _nearPlane);
|
||||
completeSuccess &= dictionary.getValue(keyInstrumentFar, _farPlane);
|
||||
ghoul_assert(completeSuccess, "All neccessary attributes not found in modfile");
|
||||
|
||||
std::string a = "NONE";
|
||||
bool s = dictionary.getValue(keyProjAberration, a);
|
||||
_aberration = SpiceManager::AberrationCorrection(a);
|
||||
completeSuccess &= s;
|
||||
ghoul_assert(completeSuccess, "All neccessary attributes not found in modfile");
|
||||
|
||||
|
||||
if (dictionary.hasKeyAndValue<ghoul::Dictionary>(keyPotentialTargets)) {
|
||||
ghoul::Dictionary potentialTargets = dictionary.value<ghoul::Dictionary>(
|
||||
keyPotentialTargets
|
||||
);
|
||||
|
||||
_potentialTargets.resize(potentialTargets.size());
|
||||
for (int i = 0; i < potentialTargets.size(); ++i) {
|
||||
std::string target;
|
||||
potentialTargets.getValue(std::to_string(i + 1), target);
|
||||
_potentialTargets[i] = target;
|
||||
}
|
||||
}
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
bool ProjectionComponent::initializeParser(const ghoul::Dictionary& dictionary) {
|
||||
bool completeSuccess = true;
|
||||
|
||||
std::string name;
|
||||
dictionary.getValue(SceneGraphNode::KeyName, name);
|
||||
|
||||
SequenceParser* parser;
|
||||
|
||||
std::string sequenceSource;
|
||||
std::string sequenceType;
|
||||
bool foundSequence = dictionary.getValue(keySequenceDir, sequenceSource);
|
||||
if (foundSequence) {
|
||||
sequenceSource = absPath(sequenceSource);
|
||||
|
||||
foundSequence = dictionary.getValue(keySequenceType, sequenceType);
|
||||
//Important: client must define translation-list in mod file IFF playbook
|
||||
if (dictionary.hasKey(keyTranslation)) {
|
||||
ghoul::Dictionary translationDictionary;
|
||||
//get translation dictionary
|
||||
dictionary.getValue(keyTranslation, translationDictionary);
|
||||
|
||||
if (sequenceType == sequenceTypePlaybook) {
|
||||
parser = new HongKangParser(name,
|
||||
sequenceSource,
|
||||
_projectorID,
|
||||
translationDictionary,
|
||||
_potentialTargets);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
}
|
||||
else if (sequenceType == sequenceTypeImage) {
|
||||
parser = new LabelParser(name,
|
||||
sequenceSource,
|
||||
translationDictionary);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
}
|
||||
else if (sequenceType == sequenceTypeHybrid) {
|
||||
//first read labels
|
||||
parser = new LabelParser(name,
|
||||
sequenceSource,
|
||||
translationDictionary);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
|
||||
std::string _eventFile;
|
||||
bool foundEventFile = dictionary.getValue("Projection.EventFile", _eventFile);
|
||||
if (foundEventFile) {
|
||||
//then read playbook
|
||||
_eventFile = absPath(_eventFile);
|
||||
parser = new HongKangParser(name,
|
||||
_eventFile,
|
||||
_projectorID,
|
||||
translationDictionary,
|
||||
_potentialTargets);
|
||||
openspace::ImageSequencer::ref().runSequenceParser(parser);
|
||||
}
|
||||
else {
|
||||
LWARNING("No eventfile has been provided, please check modfiles");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
LWARNING("No playbook translation provided, please make sure all spice calls match playbook!");
|
||||
}
|
||||
}
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
void ProjectionComponent::imageProjectBegin() {
|
||||
// keep handle to the current bound FBO
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO);
|
||||
|
||||
glGetIntegerv(GL_VIEWPORT, _viewport);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
|
||||
glViewport(
|
||||
0, 0,
|
||||
static_cast<GLsizei>(_projectionTexture->width()),
|
||||
static_cast<GLsizei>(_projectionTexture->height())
|
||||
);
|
||||
}
|
||||
|
||||
void ProjectionComponent::imageProjectEnd() {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO);
|
||||
glViewport(_viewport[0], _viewport[1], _viewport[2], _viewport[3]);
|
||||
}
|
||||
|
||||
bool ProjectionComponent::auxiliaryRendertarget() {
|
||||
bool completeSuccess = true;
|
||||
|
||||
GLint defaultFBO;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
|
||||
|
||||
// setup FBO
|
||||
glGenFramebuffers(1, &_fboID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D,
|
||||
*_projectionTexture,
|
||||
0
|
||||
);
|
||||
// check FBO status
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
completeSuccess &= false;
|
||||
// switch back to window-system-provided framebuffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
|
||||
return completeSuccess;
|
||||
}
|
||||
|
||||
glm::mat4 ProjectionComponent::computeProjectorMatrix(const glm::vec3 loc, glm::dvec3 aim,
|
||||
const glm::vec3 up,
|
||||
const glm::dmat3& instrumentMatrix,
|
||||
float fieldOfViewY,
|
||||
float aspectRatio,
|
||||
float nearPlane, float farPlane,
|
||||
glm::vec3& boreSight)
|
||||
{
|
||||
//rotate boresight into correct alignment
|
||||
boreSight = instrumentMatrix*aim;
|
||||
glm::vec3 uptmp(instrumentMatrix*glm::dvec3(up));
|
||||
|
||||
// create view matrix
|
||||
glm::vec3 e3 = glm::normalize(boreSight);
|
||||
glm::vec3 e1 = glm::normalize(glm::cross(uptmp, e3));
|
||||
glm::vec3 e2 = glm::normalize(glm::cross(e3, e1));
|
||||
glm::mat4 projViewMatrix = glm::mat4(e1.x, e2.x, e3.x, 0.f,
|
||||
e1.y, e2.y, e3.y, 0.f,
|
||||
e1.z, e2.z, e3.z, 0.f,
|
||||
-glm::dot(e1, loc), -glm::dot(e2, loc), -glm::dot(e3, loc), 1.f);
|
||||
// create perspective projection matrix
|
||||
glm::mat4 projProjectionMatrix = glm::perspective(glm::radians(fieldOfViewY), aspectRatio, nearPlane, farPlane);
|
||||
// bias matrix
|
||||
glm::mat4 projNormalizationMatrix = glm::mat4(0.5f, 0, 0, 0,
|
||||
0, 0.5f, 0, 0,
|
||||
0, 0, 0.5f, 0,
|
||||
0.5f, 0.5f, 0.5f, 1);
|
||||
return projNormalizationMatrix*projProjectionMatrix*projViewMatrix;
|
||||
}
|
||||
|
||||
void ProjectionComponent::clearAllProjections() {
|
||||
// keep handle to the current bound FBO
|
||||
GLint defaultFBO;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
|
||||
|
||||
GLint m_viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, m_viewport);
|
||||
//counter = 0;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboID);
|
||||
|
||||
glViewport(0, 0, static_cast<GLsizei>(_projectionTexture->width()), static_cast<GLsizei>(_projectionTexture->height()));
|
||||
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
//bind back to default
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
|
||||
glViewport(m_viewport[0], m_viewport[1],
|
||||
m_viewport[2], m_viewport[3]);
|
||||
|
||||
_clearAllProjections = false;
|
||||
}
|
||||
|
||||
std::shared_ptr<ghoul::opengl::Texture> ProjectionComponent::loadProjectionTexture(
|
||||
const std::string& texturePath,
|
||||
bool isPlaceholder)
|
||||
{
|
||||
using std::unique_ptr;
|
||||
using ghoul::opengl::Texture;
|
||||
using ghoul::io::TextureReader;
|
||||
|
||||
|
||||
if (isPlaceholder)
|
||||
return _placeholderTexture;
|
||||
|
||||
|
||||
unique_ptr<Texture> texture = TextureReader::ref().loadTexture(absPath(texturePath));
|
||||
if (texture) {
|
||||
if (texture->format() == Texture::Format::Red)
|
||||
ghoul::opengl::convertTextureFormat(ghoul::opengl::Texture::Format::RGB, *texture);
|
||||
texture->uploadTexture();
|
||||
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
|
||||
//_textureProj->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
|
||||
texture->setFilter(Texture::FilterMode::Linear);
|
||||
texture->setWrapping(Texture::WrappingMode::ClampToBorder);
|
||||
}
|
||||
return std::move(texture);
|
||||
}
|
||||
|
||||
bool ProjectionComponent::generateProjectionLayerTexture() {
|
||||
int maxSize = OpenGLCap.max2DTextureSize() / 2;
|
||||
|
||||
LINFO(
|
||||
"Creating projection texture of size '" << maxSize << ", " << maxSize / 2 << "'"
|
||||
);
|
||||
_projectionTexture = std::make_unique<ghoul::opengl::Texture> (
|
||||
glm::uvec3(maxSize, maxSize / 2, 1),
|
||||
ghoul::opengl::Texture::Format::RGBA
|
||||
);
|
||||
if (_projectionTexture)
|
||||
_projectionTexture->uploadTexture();
|
||||
|
||||
return _projectionTexture != nullptr;
|
||||
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
98
modules/newhorizons/util/projectioncomponent.h
Normal file
98
modules/newhorizons/util/projectioncomponent.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __PROJECTIONCOMPONENT_H__
|
||||
#define __PROJECTIONCOMPONENT_H__
|
||||
|
||||
#include <openspace/properties/scalarproperty.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
|
||||
#include <ghoul/misc/dictionary.h>
|
||||
#include <ghoul/opengl/texture.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ProjectionComponent {
|
||||
public:
|
||||
ProjectionComponent();
|
||||
|
||||
protected:
|
||||
bool initialize();
|
||||
bool deinitialize();
|
||||
|
||||
bool initializeProjectionSettings(const ghoul::Dictionary& dictionary);
|
||||
bool initializeParser(const ghoul::Dictionary& dictionary);
|
||||
|
||||
void imageProjectBegin();
|
||||
void imageProjectEnd();
|
||||
|
||||
bool generateProjectionLayerTexture();
|
||||
bool auxiliaryRendertarget();
|
||||
|
||||
std::shared_ptr<ghoul::opengl::Texture> loadProjectionTexture(
|
||||
const std::string& texturePath,
|
||||
bool isPlaceholder = false
|
||||
);
|
||||
|
||||
glm::mat4 computeProjectorMatrix(
|
||||
const glm::vec3 loc, glm::dvec3 aim, const glm::vec3 up,
|
||||
const glm::dmat3& instrumentMatrix,
|
||||
float fieldOfViewY,
|
||||
float aspectRatio,
|
||||
float nearPlane,
|
||||
float farPlane,
|
||||
glm::vec3& boreSight
|
||||
);
|
||||
|
||||
void clearAllProjections();
|
||||
|
||||
|
||||
properties::BoolProperty _performProjection;
|
||||
properties::BoolProperty _clearAllProjections;
|
||||
properties::FloatProperty _projectionFading;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::Texture> _projectionTexture;
|
||||
|
||||
std::shared_ptr<ghoul::opengl::Texture> _placeholderTexture;
|
||||
|
||||
std::string _instrumentID;
|
||||
std::string _projectorID;
|
||||
std::string _projecteeID;
|
||||
SpiceManager::AberrationCorrection _aberration;
|
||||
std::vector<std::string> _potentialTargets;
|
||||
float _fovy;
|
||||
float _aspectRatio;
|
||||
float _nearPlane;
|
||||
float _farPlane;
|
||||
|
||||
|
||||
GLuint _fboID;
|
||||
|
||||
GLint _defaultFBO;
|
||||
GLint _viewport[4];
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __PROJECTIONCOMPONENT_H__
|
||||
@@ -36,12 +36,13 @@ namespace openspace {
|
||||
class Decoder;
|
||||
|
||||
struct Image {
|
||||
double startTime;
|
||||
double stopTime;
|
||||
double startTime = 0.0;
|
||||
double stopTime = 0.0;
|
||||
std::string path;
|
||||
std::vector<std::string> activeInstruments;
|
||||
std::string target;
|
||||
bool projected;
|
||||
bool isPlaceholder = false;
|
||||
bool projected = false;
|
||||
};
|
||||
|
||||
struct TimeRange {
|
||||
@@ -53,7 +54,7 @@ struct TimeRange {
|
||||
bool inRange(double min, double max){
|
||||
return (min >= _min && max <= _max);
|
||||
}
|
||||
bool inRange(double val){
|
||||
bool inRange(double val) const {
|
||||
return (val >= _min && val <= _max);
|
||||
}
|
||||
double _min;
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
// bool keyCallback(int key, int action);
|
||||
bool charCallback(unsigned int character, KeyModifier modifier);
|
||||
|
||||
void startFrame(float deltaTime, const glm::vec2& windowSize, const glm::vec2& mousePos, uint32_t mouseButtons);
|
||||
void startFrame(float deltaTime, const glm::vec2& windowSize, const glm::vec2& mousePosCorrectionFactor, const glm::vec2& mousePos, uint32_t mouseButtons);
|
||||
void endFrame();
|
||||
|
||||
void renderMainWindow();
|
||||
|
||||
@@ -43,7 +43,10 @@ public:
|
||||
|
||||
protected:
|
||||
ghoul::SharedMemory* _performanceMemory = nullptr;
|
||||
float _minMaxValues[2];
|
||||
int _sortingSelection;
|
||||
|
||||
bool _sceneGraphIsEnabled;
|
||||
bool _functionsIsEnabled;
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
|
||||
@@ -273,6 +273,7 @@ void GUI::deinitializeGL() {
|
||||
}
|
||||
|
||||
void GUI::startFrame(float deltaTime, const glm::vec2& windowSize,
|
||||
const glm::vec2& mousePosCorrectionFactor,
|
||||
const glm::vec2& mousePos,
|
||||
uint32_t mouseButtonsPressed)
|
||||
{
|
||||
@@ -280,11 +281,14 @@ void GUI::startFrame(float deltaTime, const glm::vec2& windowSize,
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.DisplaySize = ImVec2(windowSize.x, windowSize.y);
|
||||
io.DeltaTime = deltaTime;
|
||||
#ifdef __APPLE__
|
||||
io.MousePos = ImVec2(mousePos.x * 2, mousePos.y * 2);
|
||||
#else
|
||||
io.MousePos = ImVec2(mousePos.x, mousePos.y);
|
||||
#endif
|
||||
|
||||
io.MousePos = ImVec2(mousePos.x * mousePosCorrectionFactor.x, mousePos.y * mousePosCorrectionFactor.y);
|
||||
|
||||
//#ifdef __APPLE__
|
||||
// io.MousePos = ImVec2(mousePos.x * 2, mousePos.y * 2);
|
||||
//#else
|
||||
// io.MousePos = ImVec2(mousePos.x, mousePos.y);
|
||||
//#endif
|
||||
io.MouseDown[0] = mouseButtonsPressed & (1 << 0);
|
||||
io.MouseDown[1] = mouseButtonsPressed & (1 << 1);
|
||||
|
||||
|
||||
@@ -88,9 +88,9 @@ void GuiIswaComponent::render() {
|
||||
|
||||
if(_gmdata != gmdatavalue){
|
||||
if(_gmdata){
|
||||
std::string x = "openspace.iswa.addCygnet(-1,'Data','GMData');";
|
||||
std::string y = "openspace.iswa.addCygnet(-2,'Data','GMData');";
|
||||
std::string z = "openspace.iswa.addCygnet(-3,'Data','GMData');";
|
||||
std::string x = "openspace.iswa.addCygnet(-4,'Data','GMData');";
|
||||
std::string y = "openspace.iswa.addCygnet(-5,'Data','GMData');";
|
||||
std::string z = "openspace.iswa.addCygnet(-6,'Data','GMData');";
|
||||
OsEng.scriptEngine().queueScript(x+y+z);
|
||||
}else{
|
||||
OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('GMData');");
|
||||
@@ -99,9 +99,9 @@ void GuiIswaComponent::render() {
|
||||
|
||||
if(_gmimage != gmimagevalue){
|
||||
if(_gmimage){
|
||||
std::string x = "openspace.iswa.addCygnet(-1,'Texture','GMImage');";
|
||||
std::string y = "openspace.iswa.addCygnet(-2,'Texture','GMImage');";
|
||||
std::string z = "openspace.iswa.addCygnet(-3,'Texture','GMImage');";
|
||||
std::string x = "openspace.iswa.addCygnet(-4,'Texture','GMImage');";
|
||||
std::string y = "openspace.iswa.addCygnet(-5,'Texture','GMImage');";
|
||||
std::string z = "openspace.iswa.addCygnet(-6,'Texture','GMImage');";
|
||||
OsEng.scriptEngine().queueScript(x+y+z);
|
||||
}else{
|
||||
OsEng.scriptEngine().queueScript("openspace.iswa.removeGroup('GMImage');");
|
||||
@@ -116,6 +116,7 @@ void GuiIswaComponent::render() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
|
||||
if(ImGui::CollapsingHeader("Cdf files")){
|
||||
auto cdfInfo = IswaManager::ref().cdfInformation();
|
||||
|
||||
@@ -151,6 +152,7 @@ void GuiIswaComponent::render() {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for (const auto& p : _propertiesByOwner) {
|
||||
if (ImGui::CollapsingHeader(p.first.c_str())) {
|
||||
@@ -209,6 +211,7 @@ void GuiIswaComponent::render() {
|
||||
}
|
||||
|
||||
|
||||
#ifdef OPENSPACE_MODULE_ISWA_ENABLED
|
||||
if (ImGui::CollapsingHeader("iSWA screen space cygntes")) {
|
||||
|
||||
auto map = IswaManager::ref().cygnetInformation();
|
||||
@@ -237,7 +240,8 @@ void GuiIswaComponent::render() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,17 @@
|
||||
#include <modules/onscreengui/include/guiperformancecomponent.h>
|
||||
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/performance/performancelayout.h>
|
||||
#include <openspace/performance/performancemanager.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
|
||||
#include <ghoul/misc/sharedmemory.h>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <cppformat/format.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
namespace {
|
||||
const std::string _loggerCat = "GuiPerformanceComponent";
|
||||
@@ -38,8 +45,10 @@ namespace openspace {
|
||||
namespace gui {
|
||||
|
||||
void GuiPerformanceComponent::initialize() {
|
||||
_minMaxValues[0] = 100.f;
|
||||
_minMaxValues[1] = 250.f;
|
||||
_sortingSelection = -1;
|
||||
|
||||
_sceneGraphIsEnabled = false;
|
||||
_functionsIsEnabled = false;
|
||||
}
|
||||
|
||||
void GuiPerformanceComponent::deinitialize() {
|
||||
@@ -48,61 +57,208 @@ void GuiPerformanceComponent::deinitialize() {
|
||||
}
|
||||
|
||||
void GuiPerformanceComponent::render() {
|
||||
// Copy and paste from renderengine.cpp::storePerformanceMeasurements method
|
||||
// const int8_t Version = 0;
|
||||
const int nValues = 250;
|
||||
const int lengthName = 256;
|
||||
const int maxValues = 256;
|
||||
|
||||
struct PerformanceLayout {
|
||||
int8_t version;
|
||||
int32_t nValuesPerEntry;
|
||||
int32_t nEntries;
|
||||
int32_t maxNameLength;
|
||||
int32_t maxEntries;
|
||||
|
||||
struct PerformanceLayoutEntry {
|
||||
char name[lengthName];
|
||||
float renderTime[nValues];
|
||||
float updateRenderable[nValues];
|
||||
float updateEphemeris[nValues];
|
||||
|
||||
int32_t currentRenderTime;
|
||||
int32_t currentUpdateRenderable;
|
||||
int32_t currentUpdateEphemeris;
|
||||
};
|
||||
|
||||
PerformanceLayoutEntry entries[maxValues];
|
||||
};
|
||||
using namespace performance;
|
||||
|
||||
ImGui::Begin("Performance", &_isEnabled);
|
||||
if (OsEng.renderEngine().doesPerformanceMeasurements() &&
|
||||
ghoul::SharedMemory::exists(RenderEngine::PerformanceMeasurementSharedData))
|
||||
ghoul::SharedMemory::exists(PerformanceManager::PerformanceMeasurementSharedData))
|
||||
{
|
||||
ImGui::SliderFloat2("Min values, max Value", _minMaxValues, 0.f, 10000.f);
|
||||
_minMaxValues[1] = fmaxf(_minMaxValues[0], _minMaxValues[1]);
|
||||
ImGui::Checkbox("SceneGraph", &_sceneGraphIsEnabled);
|
||||
ImGui::Checkbox("Functions", &_functionsIsEnabled);
|
||||
|
||||
ImGui::Spacing();
|
||||
|
||||
if (ImGui::Button("Reset measurements")) {
|
||||
OsEng.renderEngine().performanceManager()->resetPerformanceMeasurements();
|
||||
}
|
||||
|
||||
if (_sceneGraphIsEnabled) {
|
||||
ImGui::Begin("SceneGraph", &_sceneGraphIsEnabled);
|
||||
|
||||
// The indices correspond to the index into the average array further below
|
||||
ImGui::Text("Sorting");
|
||||
ImGui::RadioButton("No Sorting", &_sortingSelection, -1);
|
||||
ImGui::RadioButton("UpdateEphemeris", &_sortingSelection, 0);
|
||||
ImGui::RadioButton("UpdateRender", &_sortingSelection, 1);
|
||||
ImGui::RadioButton("RenderTime", &_sortingSelection, 2);
|
||||
|
||||
if (!_performanceMemory)
|
||||
_performanceMemory = new ghoul::SharedMemory(RenderEngine::PerformanceMeasurementSharedData);
|
||||
if (!_performanceMemory)
|
||||
_performanceMemory = new ghoul::SharedMemory(PerformanceManager::PerformanceMeasurementSharedData);
|
||||
|
||||
void* ptr = _performanceMemory->memory();
|
||||
|
||||
void* ptr = _performanceMemory->memory();
|
||||
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(ptr);
|
||||
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(ptr);
|
||||
|
||||
for (int i = 0; i < layout->nEntries; ++i) {
|
||||
const PerformanceLayout::PerformanceLayoutEntry& entry = layout->entries[i];
|
||||
std::vector<size_t> indices(layout->nScaleGraphEntries);
|
||||
std::iota(indices.begin(), indices.end(), 0);
|
||||
|
||||
if (ImGui::CollapsingHeader(entry.name)) {
|
||||
std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[entry.currentUpdateEphemeris - 1]) + "us";
|
||||
ImGui::PlotLines("UpdateEphemeris", &entry.updateEphemeris[0], layout->nValuesPerEntry, 0, updateEphemerisTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
// Ordering:
|
||||
// updateEphemeris
|
||||
// UpdateRender
|
||||
// RenderTime
|
||||
std::vector<std::array<float, 3>> averages(layout->nScaleGraphEntries, { 0.f, 0.f, 0.f });
|
||||
|
||||
std::vector<std::array<std::pair<float, float>, 3>> minMax(
|
||||
layout->nScaleGraphEntries
|
||||
);
|
||||
|
||||
for (int i = 0; i < layout->nScaleGraphEntries; ++i) {
|
||||
const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[i];
|
||||
|
||||
std::string updateRenderableTime = std::to_string(entry.updateRenderable[entry.currentUpdateRenderable - 1]) + "us";
|
||||
ImGui::PlotLines("UpdateRender", &entry.updateRenderable[0], layout->nValuesPerEntry, 0, updateRenderableTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
int v[3] = { 0, 0, 0 };
|
||||
|
||||
for (int j = 0; j < PerformanceLayout::NumberValues; ++j) {
|
||||
averages[i][0] += entry.updateEphemeris[j];
|
||||
if (entry.updateEphemeris[j] != 0.f)
|
||||
++(v[0]);
|
||||
averages[i][1] += entry.updateRenderable[j];
|
||||
if (entry.updateRenderable[j] != 0.f)
|
||||
++(v[1]);
|
||||
averages[i][2] += entry.renderTime[j];
|
||||
if (entry.renderTime[j] != 0.f)
|
||||
++(v[2]);
|
||||
}
|
||||
|
||||
if (v[0] != 0)
|
||||
averages[i][0] /= static_cast<float>(v[0]);
|
||||
if (v[1] != 0)
|
||||
averages[i][1] /= static_cast<float>(v[1]);
|
||||
if (v[2] != 0)
|
||||
averages[i][2] /= static_cast<float>(v[2]);
|
||||
|
||||
auto minmaxEphemeris = std::minmax_element(
|
||||
std::begin(entry.updateEphemeris),
|
||||
std::end(entry.updateEphemeris)
|
||||
);
|
||||
minMax[i][0] = std::make_pair(
|
||||
*(minmaxEphemeris.first),
|
||||
*(minmaxEphemeris.second)
|
||||
);
|
||||
|
||||
|
||||
auto minmaxUpdateRenderable = std::minmax_element(
|
||||
std::begin(entry.updateRenderable),
|
||||
std::end(entry.updateRenderable)
|
||||
);
|
||||
minMax[i][1] = std::make_pair(
|
||||
*(minmaxUpdateRenderable.first),
|
||||
*(minmaxUpdateRenderable.second)
|
||||
);
|
||||
|
||||
|
||||
auto minmaxRendering = std::minmax_element(
|
||||
std::begin(entry.renderTime),
|
||||
std::end(entry.renderTime)
|
||||
);
|
||||
minMax[i][2] = std::make_pair(
|
||||
*(minmaxRendering.first),
|
||||
*(minmaxRendering.second)
|
||||
);
|
||||
|
||||
|
||||
std::string renderTime = std::to_string(entry.renderTime[entry.currentRenderTime - 1]) + "us";
|
||||
ImGui::PlotLines("RenderTime", &entry.renderTime[0], layout->nValuesPerEntry, 0, renderTime.c_str(), _minMaxValues[0], _minMaxValues[1], ImVec2(0, 40));
|
||||
}
|
||||
|
||||
if (_sortingSelection != -1) {
|
||||
int sortIndex = _sortingSelection;
|
||||
|
||||
std::sort(
|
||||
indices.begin(),
|
||||
indices.end(),
|
||||
[sortIndex, &averages](size_t a, size_t b) {
|
||||
return averages[a][sortIndex] > averages[b][sortIndex];
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < layout->nScaleGraphEntries; ++i) {
|
||||
const PerformanceLayout::SceneGraphPerformanceLayout& entry = layout->sceneGraphEntries[indices[i]];
|
||||
|
||||
if (ImGui::CollapsingHeader(entry.name)) {
|
||||
std::string updateEphemerisTime = std::to_string(entry.updateEphemeris[PerformanceLayout::NumberValues - 1]) + "us";
|
||||
;
|
||||
ImGui::PlotLines(
|
||||
fmt::format("UpdateEphemeris\nAverage: {}us", averages[indices[i]][0]).c_str(),
|
||||
&entry.updateEphemeris[0],
|
||||
PerformanceLayout::NumberValues,
|
||||
0,
|
||||
updateEphemerisTime.c_str(),
|
||||
minMax[indices[i]][0].first,
|
||||
minMax[indices[i]][0].second,
|
||||
ImVec2(0, 40)
|
||||
);
|
||||
|
||||
std::string updateRenderableTime = std::to_string(entry.updateRenderable[PerformanceLayout::NumberValues - 1]) + "us";
|
||||
ImGui::PlotLines(
|
||||
fmt::format("UpdateRender\nAverage: {}us", averages[indices[i]][1]).c_str(),
|
||||
&entry.updateRenderable[0],
|
||||
PerformanceLayout::NumberValues,
|
||||
0,
|
||||
updateRenderableTime.c_str(),
|
||||
minMax[indices[i]][1].first,
|
||||
minMax[indices[i]][1].second,
|
||||
ImVec2(0, 40)
|
||||
);
|
||||
|
||||
std::string renderTime = std::to_string(entry.renderTime[PerformanceLayout::NumberValues - 1]) + "us";
|
||||
ImGui::PlotLines(
|
||||
fmt::format("RenderTime\nAverage: {}us", averages[indices[i]][2]).c_str(),
|
||||
&entry.renderTime[0],
|
||||
PerformanceLayout::NumberValues,
|
||||
0,
|
||||
renderTime.c_str(),
|
||||
minMax[indices[i]][2].first,
|
||||
minMax[indices[i]][2].second,
|
||||
ImVec2(0, 40)
|
||||
);
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
if (_functionsIsEnabled) {
|
||||
ImGui::Begin("Functions", &_functionsIsEnabled);
|
||||
using namespace performance;
|
||||
|
||||
if (!_performanceMemory)
|
||||
_performanceMemory = new ghoul::SharedMemory(PerformanceManager::PerformanceMeasurementSharedData);
|
||||
|
||||
void* ptr = _performanceMemory->memory();
|
||||
|
||||
PerformanceLayout* layout = reinterpret_cast<PerformanceLayout*>(ptr);
|
||||
|
||||
for (int i = 0; i < layout->nFunctionEntries; ++i) {
|
||||
const PerformanceLayout::FunctionPerformanceLayout& entry = layout->functionEntries[i];
|
||||
|
||||
float avg = 0.f;
|
||||
int count = 0;
|
||||
for (int j = 0; j < PerformanceLayout::NumberValues; ++j) {
|
||||
avg += layout->functionEntries[i].time[j];
|
||||
if (layout->functionEntries[i].time[j] != 0.f)
|
||||
++count;
|
||||
}
|
||||
avg /= count;
|
||||
|
||||
auto minmax = std::minmax_element(
|
||||
std::begin(layout->functionEntries[i].time),
|
||||
std::end(layout->functionEntries[i].time)
|
||||
);
|
||||
|
||||
const PerformanceLayout::FunctionPerformanceLayout& f = layout->functionEntries[i];
|
||||
|
||||
std::string renderTime = std::to_string(entry.time[PerformanceLayout::NumberValues - 1]) + "us";
|
||||
ImGui::PlotLines(
|
||||
fmt::format("{}\nAverage: {}us", entry.name, avg).c_str(),
|
||||
&entry.time[0],
|
||||
PerformanceLayout::NumberValues,
|
||||
0,
|
||||
renderTime.c_str(),
|
||||
*(minmax.first),
|
||||
*(minmax.second),
|
||||
ImVec2(0, 40)
|
||||
);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -113,6 +269,5 @@ void GuiPerformanceComponent::render() {
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
} // namespace gui
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user