Added new renderable for visualizing the speed of light

This commit is contained in:
Christian Adamsson
2020-07-13 17:10:31 +02:00
parent 5cc7eedee7
commit c82b8aa420
10 changed files with 413 additions and 4 deletions
@@ -0,0 +1,32 @@
asset.info = {
Name = "Lighttravel sun to earth",
Version = "1.0",
Description = "Speed of light from sun to earth",
Author = "Christian Adamsson, Emilie Ho",
URL = "https://dx.doi.org/10.3847/1538-4357/aab36d",
License = ""
}
local assetHelper = asset.require('util/asset_helper')
local transforms = asset.require('./transforms')
local sunTransforms = asset.require('scene/solarsystem/sun/transforms')
openspace.setPropertyValueSingle("Modules.Space.ShowExceptions", false)
--openspace.setPropertyValueSingle("Scene.NeptuneTrail.Renderable.Enabled", false)
--openspace.setPropertyValueSingle("Scene.UranusTrail.Renderable.Enabled", false)
--openspace.setPropertyValueSingle("Scene.SaturnTrail.Renderable.Enabled", false)
local speedofLight = {
Identifier = "SpeedofLight",
Parent = sunTransforms.SunIAU.Identifier,
Renderable = {
Type = "RenderableLightTravel"
},
GUI = {
Path = "/Solar System/Heliosphere",
Name = "Lighttravel"
}
}
assetHelper.registerSceneGraphNodesAndExport(asset, { speedofLight})
@@ -25,7 +25,7 @@ local streamnodesDirectory = asset.syncedResource({
Name = "Bastille Day Stream nodes",
Type = "HttpSynchronization",
Identifier = "bastille_day_streamnodes",
Version = 2
Version = 4
})
local streamnodesBinaries = asset.syncedResource({
Name = "Bastille day Stream nodes binaries",
+5 -1
View File
@@ -30,6 +30,7 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/util/commons.h
${CMAKE_CURRENT_SOURCE_DIR}/util/kameleonfieldlinehelper.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestreamnodes.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablelighttravel.h
)
source_group("Header Files" FILES ${HEADER_FILES})
@@ -39,6 +40,7 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/util/fieldlinesstate.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/commons.cpp
${CMAKE_CURRENT_SOURCE_DIR}/util/kameleonfieldlinehelper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablelighttravel.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})
@@ -46,7 +48,9 @@ set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fieldlinessequence_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/fieldlinessequence_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/streamnodes_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/streamnodes_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/streamnodes_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/lighttravel_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/lighttravel_vs.glsl
)
source_group("Shader Files" FILES ${SHADER_FILES})
@@ -26,6 +26,7 @@
#include <modules/fieldlinessequence/rendering/renderablefieldlinessequence.h>
#include <modules/fieldlinessequence/rendering/renderablestreamnodes.h>
#include <modules/fieldlinessequence/rendering/renderablelighttravel.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/misc/assert.h>
@@ -63,6 +64,7 @@ void FieldlinesSequenceModule::internalInitialize(const ghoul::Dictionary&) {
factory->registerClass<RenderableFieldlinesSequence>("RenderableFieldlinesSequence");
factory->registerClass<RenderableStreamNodes>("RenderableStreamNodes");
factory->registerClass<RenderableLightTravel>("RenderableLightTravel");
}
} // namespace openspace
@@ -0,0 +1,192 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* 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. *
****************************************************************************************/
//including our own h file
#include <modules/fieldlinessequence/rendering/renderablelighttravel.h>
// Includes from fieldlinessequence, might not need all of them
#include <modules/fieldlinessequence/fieldlinessequencemodule.h>
#include <modules/fieldlinessequence/util/kameleonfieldlinehelper.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/interaction/orbitalnavigator.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
#include <openspace/util/timemanager.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
// Test debugging tools more then logmanager
#include <ghoul/logging/consolelog.h>
#include <ghoul/logging/visualstudiooutputlog.h>
#include <ghoul/filesystem/cachemanager.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/textureunit.h>
#include <fstream>
#include <thread>
#include <openspace/json.h>
#include <openspace/query/query.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scene.h>
namespace {
constexpr const char* _loggerCat = "renderableLightTravel";
constexpr openspace::properties::Property::PropertyInfo LightSpeedInfo = {
"lightspeed",
"speed of light",
"The speed of light"
};
}
namespace openspace {
using namespace properties;
RenderableLightTravel::RenderableLightTravel(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
, _lightspeed(LightSpeedInfo, 3000000000)
{
_dictionary = std::make_unique<ghoul::Dictionary>(dictionary);
}
void RenderableLightTravel::initializeGL() {
_dictionary.reset();
_shaderProgram = global::renderEngine.buildRenderProgram(
"Lighttravel",
absPath("${MODULE_FIELDLINESSEQUENCE}/shaders/lighttravel_vs.glsl"),
absPath("${MODULE_FIELDLINESSEQUENCE}/shaders/lighttravel_fs.glsl")
);
glGenVertexArrays(1, &_vertexArrayObject);
glGenBuffers(1, &_vertexPositionBuffer);
setRenderBin(Renderable::RenderBin::Transparent);
positions.push_back(glm::vec3(0.0, 0.0, 0.0));
glm::vec3 earthPos = glm::vec3(94499869340, -115427843118, 11212075887.3);
//positions.push_back(glm::vec3(94499869340 / 2, -115427843118 / 2, 11212075887.3 / 2));
positions.push_back(earthPos);
//Earthnode worldposition, is not aligned with the actual position shown as it seems right now.
//SceneGraphNode* earthNode = sceneGraphNode("Earth");
//glm::vec3 earthPos = earthNode->worldPosition();
//glm::vec3 earthPos = earthNode->position();
// positions.push_back(earthPos);
// positions.push_back(earthPos);
LDEBUG("vi kom in i init");
}
void RenderableLightTravel::deinitializeGL()
{
glDeleteVertexArrays(1, &_vertexArrayObject);
_vertexArrayObject = 0;
glDeleteBuffers(1, &_vertexPositionBuffer);
_vertexPositionBuffer = 0;
if (_shaderProgram) {
global::renderEngine.removeRenderProgram(_shaderProgram.get());
_shaderProgram = nullptr;
}
}
bool RenderableLightTravel::isReady() const
{
return _shaderProgram != nullptr;
}
void RenderableLightTravel::render(const RenderData& data, RendererTasks& rendererTask)
{
/*
if(positions.size() < 3){
SceneGraphNode* earthNode = sceneGraphNode("Earth");
glm::vec3 earthPos = earthNode->worldPosition();
// glm::vec3 earthPos =
// global::renderEngine.scene()->sceneGraphNode("Earth")->worldPosition();
positions.push_back(earthPos);
}
*/
_shaderProgram->activate();
//LDEBUG("vi kom in i render");
// Calculate Model View MatrixProjection
const glm::dmat4 rotMat = glm::dmat4(data.modelTransform.rotation);
const glm::dmat4 modelMat =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
rotMat *
glm::dmat4(glm::scale(glm::dmat4(1), glm::dvec3(data.modelTransform.scale)));
const glm::dmat4 modelViewMat = data.camera.combinedViewMatrix() * modelMat;
_shaderProgram->setUniform("modelViewProjection",
data.camera.sgctInternal.projectionMatrix() * glm::mat4(modelViewMat));
glBindVertexArray(_vertexArrayObject);
glLineWidth(5.0f);
GLint temp = 0;
glDrawArrays(
GL_LINE_STRIP,
temp,
static_cast<GLsizei>(positions.size())
);
glBindVertexArray(0);
_shaderProgram->deactivate();
}
inline void unbindGL() {
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
void RenderableLightTravel::update(const UpdateData& data)
{
if (_shaderProgram->isDirty()) {
_shaderProgram->rebuildFromFile();
}
glBindVertexArray(_vertexArrayObject);
glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer);
const std::vector<glm::vec3>& vertPos = positions;
glBufferData(
GL_ARRAY_BUFFER,
vertPos.size() * sizeof(glm::vec3),
vertPos.data(),
GL_STATIC_DRAW
);
constexpr const GLuint VaPosition = 0;
glEnableVertexAttribArray(VaPosition);
glEnable(GL_PROGRAM_POINT_SIZE);
glVertexAttribPointer(VaPosition, 3, GL_FLOAT, GL_FALSE, 0, 0);
unbindGL();
}
}
@@ -0,0 +1,72 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* 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/rendering/renderable.h>
#include <modules/fieldlinessequence/util/fieldlinesstate.h>
#include <openspace/properties/optionproperty.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/triggerproperty.h>
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/vector/vec2property.h>
#include <openspace/properties/vector/vec4property.h>
#include <openspace/rendering/transferfunction.h>
#include <atomic>
#include <modules/base/rendering/renderabletrail.h>
namespace openspace {
class RenderableLightTravel : public Renderable {
public:
RenderableLightTravel(const ghoul::Dictionary& dictionary);
void initializeGL() override;
void deinitializeGL() override;
bool isReady() const override;
void render(const RenderData& data, RendererTasks& rendererTask) override;
void update(const UpdateData& data) override;
private:
std::string _identifier;
// OpenGL Vertex Array Object
GLuint _vertexArrayObject = 0;
// OpenGL Vertex Buffer Object containing the vertex positions
GLuint _vertexPositionBuffer = 0;
// OpenGL Vertex Buffer Object containing the Flux values used for coloring
// the nodes
GLuint _vertexColorBuffer = 0;
// OpenGL Vertex Buffer Object containing the positions to filter the nodes
GLuint _vertexFilteringBuffer = 0;
// OpenGL Vertex Buffer Object containing the index of nodes
GLuint _vertexindexBuffer = 0;
std::vector<glm::vec3> positions;
properties::FloatProperty _lightspeed;
std::unique_ptr<ghoul::Dictionary> _dictionary;
std::unique_ptr<ghoul::opengl::ProgramObject> _shaderProgram;
};
}
@@ -562,6 +562,7 @@ void RenderableStreamNodes::loadNodeData() {
writeCachedFile("StreamnodesCachePosition");
}
}
void RenderableStreamNodes::createStreamnumberVector() {
int nPoints = 1999;
@@ -0,0 +1,54 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "fragment.glsl"
in vec4 vs_color;
in float vs_depth;
Fragment getFragment() {
if (vs_color.a == 0) {
discard;
}
vec4 fragColor = vs_color;
Fragment frag;
frag.depth = vs_depth;
frag.color = fragColor;
//if(vs_st.x != -1){
//if (gl_FrontFacing) {
// frag.color = texture(texture1, vs_st);
// }
// else {
// frag.color = texture(texture1, vec2(1 - vs_st.s, vs_st.t));
// }
// }
// G-Buffer
frag.gPosition = vec4(0.0); //vs_gPosition;
// There is no normal here
// TODO: Add the correct normal if necessary (JCC)
frag.gNormal = vec4(0.0, 0.0, -1.0, 1.0);
return frag;
}
@@ -0,0 +1,41 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* 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 modelViewProjection;
layout(location = 0) in vec3 in_position;
out vec4 vs_color;
out float vs_depth;
void main() {
vs_color = vec4(1.0, 1.0, 1.0, 1.0);
vec4 position_in_meters = vec4(in_position, 1);
vec4 positionClipSpace = modelViewProjection * position_in_meters;
gl_Position = vec4(positionClipSpace.xy, 0, positionClipSpace.w);
vs_depth = gl_Position.w;
}
@@ -74,6 +74,7 @@ uniform int activestreamnumber;
uniform bool firstrender;
uniform int EnhanceMethod;
uniform double time;
//uniform vec3 camerapos;
//uniform float interestingStreams[4];
// Inputs
@@ -359,9 +360,19 @@ void main() {
vec4 position_in_meters = vec4(in_position, 1);
vec4 positionClipSpace = modelViewProjection * position_in_meters;
//vs_gPosition = vec4(modelViewTransform * dvec4(in_point_position, 1));
/* if(distance(position_in_meters.xyz, camerapos) < 3000000000.f){
vs_color = streamColor;
}
else{
vs_color = vs_color;
}
*/
//gl_PointSize = nodeSize;
gl_Position = vec4(positionClipSpace.xy, 0, positionClipSpace.w);
vs_depth = gl_Position.w;
// if(distance(positionClipSpace.xyz, camerapos) < 0.f){
}