diff --git a/data/assets/examples/pointscloud.asset b/data/assets/examples/pointscloud.asset index 70dbfae51d..d458799f8d 100644 --- a/data/assets/examples/pointscloud.asset +++ b/data/assets/examples/pointscloud.asset @@ -13,8 +13,9 @@ local RenderablePointsCloud = { Identifier = "RenderablePointsCloud", Renderable = { Type = "RenderablePointsCloud", - File = "", --speck .. "/2MASS.speck" Color = {1.0, 1.0, 0.5}, + File = "", --speck .. "/2MASS.speck" + Opacity = 1.0, Size = 50, }, GUI = { diff --git a/modules/softwareintegration/rendering/renderablepointscloud.cpp b/modules/softwareintegration/rendering/renderablepointscloud.cpp index a3a5eb8b30..99ba9a9144 100644 --- a/modules/softwareintegration/rendering/renderablepointscloud.cpp +++ b/modules/softwareintegration/rendering/renderablepointscloud.cpp @@ -52,11 +52,23 @@ namespace { "TODO" }; + constexpr openspace::properties::Property::PropertyInfo OpacityInfo = { + "Opacity", + "Opacity", + "TODO" + }; + constexpr openspace::properties::Property::PropertyInfo SizeInfo = { "Size", "Size", "TODO" }; + + constexpr openspace::properties::Property::PropertyInfo ToggleVisibilityInfo = { + "ToggleVisibility", + "Toggle Visibility", + "Enables/Disables the drawing of points." + }; } // namespace namespace openspace { @@ -67,6 +79,12 @@ namespace openspace { "RenderablePointsCloud", "softwareintegration_renderable_pointscloud", { + { + ColorInfo.identifier, + new DoubleVector3Verifier, + Optional::Yes, + ColorInfo.description + }, { KeyFile, new StringVerifier, @@ -74,10 +92,10 @@ namespace openspace { "TODO" }, { - ColorInfo.identifier, - new DoubleVector3Verifier, + OpacityInfo.identifier, + new DoubleVerifier, Optional::Yes, - ColorInfo.description + OpacityInfo.description }, { SizeInfo.identifier, @@ -97,7 +115,9 @@ namespace openspace { glm::vec3(0.f), glm::vec3(1.f) ) + , _opacity(OpacityInfo, 1.f, 0.f, 1.f) , _size(SizeInfo, 1.f, 0.f, 600.f) + , _toggleVisibility(ToggleVisibilityInfo, true) { documentation::testSpecificationAndThrow( Documentation(), @@ -105,23 +125,35 @@ namespace openspace { "RenderablePointsCloud" ); - if (dictionary.hasKey(KeyFile)) { - _speckFile = absPath(dictionary.value(KeyFile)); - _hasSpeckFile = true; - } - if (dictionary.hasKey(ColorInfo.identifier)) { _color = dictionary.value(ColorInfo.identifier); } _color.setViewOption(properties::Property::ViewOptions::Color); addProperty(_color); + if (dictionary.hasKey(KeyFile)) { + _speckFile = absPath(dictionary.value(KeyFile)); + _hasSpeckFile = true; + } + + if (dictionary.hasKey(OpacityInfo.identifier)) { + _opacity = static_cast( + dictionary.value(OpacityInfo.identifier)); + } + addProperty(_opacity); + if (dictionary.hasKey(SizeInfo.identifier)) { _size = static_cast( dictionary.value(SizeInfo.identifier)); - //dictionary.value(SizeInfo.identifier); } addProperty(_size); + + if (dictionary.hasKey(ToggleVisibilityInfo.identifier)) { + _toggleVisibility = dictionary.value(ToggleVisibilityInfo.identifier); + } + + _toggleVisibility.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; }); + addProperty(_toggleVisibility); } bool RenderablePointsCloud::isReady() const { @@ -160,36 +192,39 @@ namespace openspace { if (_fullData.empty()) { return; } - _shaderProgram->activate(); + if (_hasSpeckFile && _toggleVisibility) { + _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 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; + glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; - _shaderProgram->setUniform("modelViewTransform", modelViewTransform); - _shaderProgram->setUniform( - "MVPTransform", - glm::dmat4(data.camera.projectionMatrix()) * modelViewTransform - ); + _shaderProgram->setUniform("modelViewTransform", modelViewTransform); + _shaderProgram->setUniform( + "MVPTransform", + glm::dmat4(data.camera.projectionMatrix()) * modelViewTransform + ); - _shaderProgram->setUniform("color", _color); - _shaderProgram->setUniform("size", _size); + _shaderProgram->setUniform("color", _color); + _shaderProgram->setUniform("opacity", _opacity); + _shaderProgram->setUniform("size", _size); - // Changes GL state: - glEnablei(GL_BLEND, 0); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_PROGRAM_POINT_SIZE); // Enable gl_PointSize in vertex + // Changes GL state: + glEnablei(GL_BLEND, 0); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_PROGRAM_POINT_SIZE); // Enable gl_PointSize in vertex - glBindVertexArray(_vaoID); - const GLsizei nPoints = static_cast(_fullData.size() / _nValuesPerPoints); - glDrawArrays(GL_POINTS, 0, nPoints); + glBindVertexArray(_vaoID); + const GLsizei nPoints = static_cast(_fullData.size() / _nValuesPerPoints); + glDrawArrays(GL_POINTS, 0, nPoints); - glBindVertexArray(0); - _shaderProgram->deactivate(); + glBindVertexArray(0); + _shaderProgram->deactivate(); + } } void RenderablePointsCloud::update(const UpdateData&) { diff --git a/modules/softwareintegration/rendering/renderablepointscloud.h b/modules/softwareintegration/rendering/renderablepointscloud.h index 0320e3eb85..3b22b3a054 100644 --- a/modules/softwareintegration/rendering/renderablepointscloud.h +++ b/modules/softwareintegration/rendering/renderablepointscloud.h @@ -69,8 +69,10 @@ namespace openspace { std::unique_ptr _shaderProgram = nullptr; - properties::Vec3Property _color; + properties::BoolProperty _toggleVisibility; + properties::FloatProperty _opacity; properties::FloatProperty _size; + properties::Vec3Property _color; std::string _speckFile; std::vector _fullData; diff --git a/modules/softwareintegration/shaders/point_fs.glsl b/modules/softwareintegration/shaders/point_fs.glsl index 3dc4029f75..9ec824cd34 100644 --- a/modules/softwareintegration/shaders/point_fs.glsl +++ b/modules/softwareintegration/shaders/point_fs.glsl @@ -29,11 +29,12 @@ in float vs_depthClipSpace; in vec4 vs_positionViewSpace; uniform vec3 color; +uniform float opacity; Fragment getFragment() { Fragment frag; frag.color.rgb = color; - frag.color.a = 1.0; + frag.color.a = opacity; frag.depth = vs_depthClipSpace; frag.gPosition = vs_positionViewSpace;