mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 20:21:24 -06:00
Created a basic point cloud renderable
This commit is contained in:
@@ -19,6 +19,9 @@ asset.request('scene/milkyway/milkyway/volume')
|
||||
asset.request('scene/milkyway/constellations/constellation_art')
|
||||
asset.request('scene/milkyway/constellations/constellation_keybinds')
|
||||
|
||||
-- TESTELITEST
|
||||
asset.require('examples/pointscloud')
|
||||
|
||||
assetHelper.requestAll(asset, 'scene/digitaluniverse')
|
||||
|
||||
-- Load default key bindings applicable to most scenes
|
||||
|
||||
18
data/assets/examples/pointscloud.asset
Normal file
18
data/assets/examples/pointscloud.asset
Normal file
@@ -0,0 +1,18 @@
|
||||
-- This asset requires OpenSpace to be built with the OPENSPACE_MODULE_SPOUT enabled
|
||||
|
||||
local assetHelper = asset.require("util/asset_helper")
|
||||
|
||||
local RenderablePointsCloud = {
|
||||
Identifier = "RenderablePointsCloud",
|
||||
Renderable = {
|
||||
Type = "RenderablePointsCloud",
|
||||
Color = {1.0, 1.0, 0.0},
|
||||
Size = 50,
|
||||
},
|
||||
GUI = {
|
||||
Path = "/Examples"
|
||||
}
|
||||
}
|
||||
|
||||
local objects = { RenderablePointsCloud }
|
||||
assetHelper.registerSceneGraphNodesAndExport(asset, objects)
|
||||
@@ -26,14 +26,22 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
|
||||
|
||||
set(HEADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/softwareintegrationmodule.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepointscloud.h
|
||||
)
|
||||
source_group("Header Files" FILES ${HEADER_FILES})
|
||||
|
||||
set(SOURCE_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/softwareintegrationmodule.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablepointscloud.cpp
|
||||
)
|
||||
source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
|
||||
set(SHADER_FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/point_vs.glsl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shaders/point_fs.glsl
|
||||
)
|
||||
source_group("Shader Files" FILES ${SHADER_FILES})
|
||||
|
||||
create_new_module(
|
||||
"SoftwareIntegration"
|
||||
softwareintegration
|
||||
|
||||
199
modules/softwareintegration/rendering/renderablepointscloud.cpp
Normal file
199
modules/softwareintegration/rendering/renderablepointscloud.cpp
Normal file
@@ -0,0 +1,199 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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 <modules/softwareintegration/rendering/renderablepointscloud.h>
|
||||
|
||||
#include <openspace/engine/globals.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/util/spicemanager.h>
|
||||
#include <openspace/util/updatestructures.h>
|
||||
#include <openspace/documentation/verifier.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
|
||||
namespace {
|
||||
constexpr const char* ProgramName = "shaderProgram";
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo ColorInfo = {
|
||||
"Color",
|
||||
"Color",
|
||||
"TODO"
|
||||
};
|
||||
|
||||
constexpr openspace::properties::Property::PropertyInfo SizeInfo = {
|
||||
"Size",
|
||||
"Size",
|
||||
"TODO"
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation RenderablePointsCloud::Documentation() {
|
||||
using namespace documentation;
|
||||
return {
|
||||
"RenderablePointsCloud",
|
||||
"softwareintegration_renderable_pointscloud",
|
||||
{
|
||||
{
|
||||
ColorInfo.identifier,
|
||||
new DoubleVector3Verifier,
|
||||
Optional::Yes,
|
||||
ColorInfo.description
|
||||
},
|
||||
{
|
||||
SizeInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
SizeInfo.description
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
RenderablePointsCloud::RenderablePointsCloud(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
, _color(
|
||||
ColorInfo,
|
||||
glm::vec3(0.5f, 0.5, 0.5f),
|
||||
glm::vec3(0.f),
|
||||
glm::vec3(1.f)
|
||||
)
|
||||
, _size(SizeInfo, 0.5f, 0.f, 20.f)
|
||||
{
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"RenderablePointsCloud"
|
||||
);
|
||||
|
||||
if (dictionary.hasKey(ColorInfo.identifier)) {
|
||||
_color = dictionary.value<glm::vec3>(ColorInfo.identifier);
|
||||
}
|
||||
_color.setViewOption(properties::Property::ViewOptions::Color);
|
||||
addProperty(_color);
|
||||
|
||||
if (dictionary.hasKey(SizeInfo.identifier)) {
|
||||
_size = dictionary.value<float>(SizeInfo.identifier);
|
||||
}
|
||||
addProperty(_size);
|
||||
}
|
||||
|
||||
bool RenderablePointsCloud::isReady() const {
|
||||
return _shaderProgram != nullptr;
|
||||
}
|
||||
|
||||
void RenderablePointsCloud::initializeGL() {
|
||||
_shaderProgram = global::renderEngine.buildRenderProgram(
|
||||
"PointsCloud",
|
||||
absPath("${MODULE_SOFTWAREINTEGRATION}/shaders/point_vs.glsl"),
|
||||
absPath("${MODULE_SOFTWAREINTEGRATION}/shaders/point_fs.glsl")
|
||||
);
|
||||
|
||||
glGenVertexArrays(1, &_vaoID);
|
||||
glGenBuffers(1, &_vBufferID);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void RenderablePointsCloud::deinitializeGL() {
|
||||
glDeleteVertexArrays(1, &_vaoID);
|
||||
_vaoID = 0;
|
||||
|
||||
glDeleteBuffers(1, &_vBufferID);
|
||||
_vBufferID = 0;
|
||||
|
||||
if (_shaderProgram) {
|
||||
global::renderEngine.removeRenderProgram(_shaderProgram.get());
|
||||
_shaderProgram = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderablePointsCloud::render(const RenderData& data, RendererTasks&) {
|
||||
_shaderProgram->activate();
|
||||
|
||||
glm::dmat4 modelTransform =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
|
||||
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
|
||||
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
|
||||
|
||||
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
|
||||
_shaderProgram->setUniform("modelViewTransform", modelViewTransform);
|
||||
_shaderProgram->setUniform(
|
||||
"MVPTransform",
|
||||
glm::dmat4(data.camera.projectionMatrix()) * modelViewTransform
|
||||
);
|
||||
|
||||
_shaderProgram->setUniform("color", _color);
|
||||
_shaderProgram->setUniform("size", _size);
|
||||
|
||||
// Changes GL state:
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_PROGRAM_POINT_SIZE); // Enable gl_PointSize in vertex
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(_varray.size()));
|
||||
glBindVertexArray(0);
|
||||
|
||||
_shaderProgram->deactivate();
|
||||
|
||||
}
|
||||
|
||||
void RenderablePointsCloud::update(const UpdateData&) {
|
||||
|
||||
// store data point in _varray
|
||||
_varray.push_back({ 0.f, 0.f, 0.f });
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_varray.size() * sizeof(Vertex),
|
||||
_varray.data(),
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
3,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(Vertex),
|
||||
nullptr
|
||||
);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
@@ -0,0 +1,73 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef __OPENSPACE_MODULE_SOFTWAREINTEGRATION___RENDERABLEPOINTSCLOUD___H__
|
||||
#define __OPENSPACE_MODULE_SOFTWAREINTEGRATION___RENDERABLEPOINTSCLOUD___H__
|
||||
|
||||
#include <openspace/rendering/renderable.h>
|
||||
|
||||
#include <openspace/properties/vector/vec3property.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
|
||||
namespace ghoul::opengl {
|
||||
class ProgramObject;
|
||||
} // namespace ghoul::opengl
|
||||
|
||||
namespace openspace::documentation { struct Documentation; }
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class RenderablePointsCloud : public Renderable {
|
||||
public:
|
||||
RenderablePointsCloud(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;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
protected:
|
||||
struct Vertex {
|
||||
float location[3];
|
||||
};
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _shaderProgram = nullptr;
|
||||
|
||||
properties::Vec3Property _color;
|
||||
properties::FloatProperty _size;
|
||||
|
||||
GLuint _vaoID = 0;
|
||||
GLuint _vBufferID = 0;
|
||||
|
||||
std::vector<Vertex> _varray;
|
||||
};
|
||||
|
||||
}// namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SOFTWAREINTEGRATION___RENDERABLEPOINTSCLOUD___H__
|
||||
45
modules/softwareintegration/shaders/point_fs.glsl
Normal file
45
modules/softwareintegration/shaders/point_fs.glsl
Normal file
@@ -0,0 +1,45 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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"
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
in float vs_depthClipSpace;
|
||||
in vec4 vs_positionViewSpace;
|
||||
|
||||
uniform vec3 color;
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
frag.color.rgb = color;
|
||||
frag.color.a = 1.0;
|
||||
frag.depth = vs_depthClipSpace;
|
||||
frag.gPosition = vs_positionViewSpace;
|
||||
|
||||
// There is no normal here
|
||||
frag.gNormal = vec4(0.0, 0.0, -1.0, 1.0);
|
||||
|
||||
return frag;
|
||||
|
||||
}
|
||||
50
modules/softwareintegration/shaders/point_vs.glsl
Normal file
50
modules/softwareintegration/shaders/point_vs.glsl
Normal file
@@ -0,0 +1,50 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* 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__
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
layout(location = 0) in vec3 in_position;
|
||||
|
||||
out float vs_depthClipSpace;
|
||||
out vec4 vs_positionViewSpace;
|
||||
|
||||
uniform dmat4 modelViewTransform;
|
||||
uniform dmat4 MVPTransform;
|
||||
uniform float size;
|
||||
|
||||
void main() {
|
||||
dvec4 objPosDouble = dvec4(in_position, 1.0);
|
||||
dvec4 positionViewSpace = modelViewTransform * objPosDouble;
|
||||
dvec4 positionClipSpace = MVPTransform * objPosDouble;
|
||||
|
||||
positionClipSpace.z = 0.0;
|
||||
|
||||
vs_depthClipSpace = float(positionClipSpace.w);
|
||||
vs_positionViewSpace = vec4(positionViewSpace);
|
||||
|
||||
gl_PointSize = size;
|
||||
gl_Position = vec4(positionClipSpace);
|
||||
}
|
||||
@@ -24,36 +24,38 @@
|
||||
|
||||
#include <modules/softwareintegration/softwareintegrationmodule.h>
|
||||
|
||||
#include <modules/softwareintegration/rendering/renderablepointscloud.h>
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <openspace/rendering/screenspacerenderable.h>
|
||||
#include <openspace/scripting/lualibrary.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
SoftwareIntegrationModule::SoftwareIntegrationModule() : OpenSpaceModule(Name) {}
|
||||
SoftwareIntegrationModule::SoftwareIntegrationModule() : OpenSpaceModule(Name) {}
|
||||
|
||||
void SoftwareIntegrationModule::internalInitialize(const ghoul::Dictionary&) {
|
||||
auto fRenderable = FactoryManager::ref().factory<Renderable>();
|
||||
ghoul_assert(fRenderable, "No renderable factory existed");
|
||||
//fRenderable->registerClass<RenderableGaiaStars>("RenderableGaiaStars");
|
||||
|
||||
//auto fTask = FactoryManager::ref().factory<Task>();
|
||||
//ghoul_assert(fRenderable, "No task factory existed");
|
||||
//fTask->registerClass<ReadFitsTask>("ReadFitsTask");
|
||||
//fTask->registerClass<ReadSpeckTask>("ReadSpeckTask");
|
||||
//fTask->registerClass<ConstructOctreeTask>("ConstructOctreeTask");
|
||||
fRenderable->registerClass<RenderablePointsCloud>("RenderablePointsCloud");
|
||||
}
|
||||
|
||||
/*std::vector<documentation::Documentation> SoftwareIntegrationModule::documentations() const {
|
||||
void SoftwareIntegrationModule::internalDeinitializeGL() {
|
||||
|
||||
}
|
||||
|
||||
std::vector<documentation::Documentation> SoftwareIntegrationModule::documentations() const {
|
||||
return {
|
||||
|
||||
RenderablePointsCloud::Documentation(),
|
||||
};
|
||||
}
|
||||
|
||||
scripting::LuaLibrary SoftwareIntegrationModule::luaLibrary() const {
|
||||
/*scripting::LuaLibrary SoftwareIntegrationModule::luaLibrary() const {
|
||||
scripting::LuaLibrary res;
|
||||
res.name = "softwareintegration";
|
||||
res.scripts = {
|
||||
|
||||
@@ -37,11 +37,12 @@ public:
|
||||
SoftwareIntegrationModule();
|
||||
virtual ~SoftwareIntegrationModule() = default;
|
||||
|
||||
//std::vector<documentation::Documentation> documentations() const override;
|
||||
std::vector<documentation::Documentation> documentations() const override;
|
||||
//scripting::LuaLibrary luaLibrary() const override;
|
||||
|
||||
private:
|
||||
void internalInitialize(const ghoul::Dictionary&) override;
|
||||
void internalDeinitializeGL() override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
4134
modules/softwareintegration/testdata/testPointsCloud.csv
vendored
Normal file
4134
modules/softwareintegration/testdata/testPointsCloud.csv
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user