From a38635b2f033c4132997a71866bb9b0eda86bec2 Mon Sep 17 00:00:00 2001 From: Elon Date: Mon, 25 Mar 2019 14:34:56 -0600 Subject: [PATCH] appearance --- modules/base/rendering/renderabletrail.cpp | 83 +++++++++++++------ modules/base/rendering/renderabletrail.h | 22 +++++ modules/space/CMakeLists.txt | 78 ++++++++--------- .../space/rendering/renderablesatellites.cpp | 6 +- .../space/rendering/renderablesatellites.h | 2 +- .../shaders/renderablekeplerorbits_fs.glsl | 46 ++++++++++ .../shaders/renderablekeplerorbits_vs.glsl | 44 ++++++++++ modules/space/translation/keplertranslation.h | 21 +++++ 8 files changed, 237 insertions(+), 65 deletions(-) create mode 100644 modules/space/shaders/renderablekeplerorbits_fs.glsl create mode 100644 modules/space/shaders/renderablekeplerorbits_vs.glsl diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index 03c36fc0e4..c437c847f8 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -59,6 +59,13 @@ namespace { { "Points+Lines", RenderingModeLinesPoints } }; + static const openspace::properties::PropertyOwner::PropertyOwnerInfo + AppearanceInfo = { + "Appearance", + "Appearance", + "The appearance of the trail." + }; + constexpr openspace::properties::Property::PropertyInfo LineColorInfo = { "Color", "Color", @@ -166,8 +173,35 @@ documentation::Documentation RenderableTrail::Documentation() { }; } +RenderableTrail::Appearance::Appearance() + : properties::PropertyOwner(AppearanceInfo) + , lineColor(LineColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) + , useLineFade(EnableFadeInfo, true) + , lineFade(FadeInfo, 1.f, 0.f, 30.f) + , lineWidth(LineWidthInfo, 2.f, 1.f, 20.f) + , pointSize(PointSizeInfo, 1, 1, 64) + , renderingModes( + RenderingModeInfo, + properties::OptionProperty::DisplayType::Dropdown + ) +{ + renderingModes.addOptions({ + { RenderingModeLines, "Lines" }, + { RenderingModePoints, "Points" }, + { RenderingModeLinesPoints, "Lines+Points" } + }); + + addProperty(lineColor); + addProperty(useLineFade); + addProperty(lineFade); + addProperty(lineWidth); + addProperty(pointSize); + addProperty(renderingModes); +} + RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) : Renderable(dictionary) + /* , _lineColor(LineColorInfo, glm::vec3(1.f), glm::vec3(0.f), glm::vec3(1.f)) , _useLineFade(EnableFadeInfo, true) , _lineFade(FadeInfo, 1.f, 0.f, 30.f) @@ -177,6 +211,7 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) RenderingModeInfo, properties::OptionProperty::DisplayType::Dropdown ) + */ { addProperty(_opacity); registerUpdateRenderBinFromOpacity(); @@ -186,32 +221,32 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) ); addPropertySubOwner(_translation.get()); - _lineColor = dictionary.value(LineColorInfo.identifier); - addProperty(_lineColor); + _appearance.lineColor = dictionary.value(LineColorInfo.identifier); + addProperty(_appearance.lineColor); if (dictionary.hasKeyAndValue(EnableFadeInfo.identifier)) { - _useLineFade = dictionary.value(EnableFadeInfo.identifier); + _appearance.useLineFade = dictionary.value(EnableFadeInfo.identifier); } - addProperty(_useLineFade); + addProperty(_appearance.useLineFade); if (dictionary.hasKeyAndValue(FadeInfo.identifier)) { - _lineFade = static_cast(dictionary.value(FadeInfo.identifier)); + _appearance.lineFade = static_cast(dictionary.value(FadeInfo.identifier)); } - addProperty(_lineFade); + addProperty(_appearance.lineFade); if (dictionary.hasKeyAndValue(LineWidthInfo.identifier)) { - _lineWidth = static_cast(dictionary.value( + _appearance.lineWidth = static_cast(dictionary.value( LineWidthInfo.identifier )); } - addProperty(_lineWidth); + addProperty(_appearance.lineWidth); if (dictionary.hasKeyAndValue(PointSizeInfo.identifier)) { - _pointSize = static_cast(dictionary.value(PointSizeInfo.identifier)); + _appearance.pointSize = static_cast(dictionary.value(PointSizeInfo.identifier)); } - addProperty(_pointSize); + addProperty(_appearance.pointSize); - _renderingModes.addOptions({ + _appearance.renderingModes.addOptions({ { RenderingModeLines, "Lines" }, { RenderingModePoints, "Points" }, { RenderingModeLinesPoints, "Lines+Points" } @@ -220,14 +255,14 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) // This map is not accessed out of order as long as the Documentation is adapted // whenever the map changes. The documentation will check for valid values if (dictionary.hasKeyAndValue(RenderingModeInfo.identifier)) { - _renderingModes = RenderingModeConversion.at( + _appearance.renderingModes = RenderingModeConversion.at( dictionary.value(RenderingModeInfo.identifier) ); } else { - _renderingModes = RenderingModeLines; + _appearance.renderingModes = RenderingModeLines; } - addProperty(_renderingModes); + addProperty(_appearance.renderingModes); } void RenderableTrail::initializeGL() { @@ -272,10 +307,10 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { _programObject->setUniform(_uniformCache.projection, data.camera.projectionMatrix()); - _programObject->setUniform(_uniformCache.color, _lineColor); - _programObject->setUniform(_uniformCache.useLineFade, _useLineFade); - if (_useLineFade) { - _programObject->setUniform(_uniformCache.lineFade, _lineFade); + _programObject->setUniform(_uniformCache.color, _appearance.lineColor); + _programObject->setUniform(_uniformCache.useLineFade, _appearance.useLineFade); + if (_appearance.useLineFade) { + _programObject->setUniform(_uniformCache.lineFade, _appearance.lineFade); } static std::map SortingMapping = { @@ -294,21 +329,21 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { //glBlendFunc(GL_SRC_ALPHA, GL_ONE); } - const bool renderLines = (_renderingModes == RenderingModeLines) | - (_renderingModes == RenderingModeLinesPoints); + const bool renderLines = (_appearance.renderingModes == RenderingModeLines) | + (_appearance.renderingModes == RenderingModeLinesPoints); - const bool renderPoints = (_renderingModes == RenderingModePoints) | - (_renderingModes == RenderingModeLinesPoints); + const bool renderPoints = (_appearance.renderingModes == RenderingModePoints) | + (_appearance.renderingModes == RenderingModeLinesPoints); if (renderLines) { - glLineWidth(_lineWidth); + glLineWidth(_appearance.lineWidth); } if (renderPoints) { glEnable(GL_PROGRAM_POINT_SIZE); } auto render = [renderLines, renderPoints, p = _programObject, &data, - &modelTransform, pointSize = _pointSize.value(), c = _uniformCache] + &modelTransform, pointSize = _appearance.pointSize.value(), c = _uniformCache] (RenderInformation& info, int nVertices, int offset) { // We pass in the model view transformation matrix as double in order to maintain diff --git a/modules/base/rendering/renderabletrail.h b/modules/base/rendering/renderabletrail.h index 1bd1e802c8..68adcf8e8b 100644 --- a/modules/base/rendering/renderabletrail.h +++ b/modules/base/rendering/renderabletrail.h @@ -71,6 +71,23 @@ class Translation; */ class RenderableTrail : public Renderable { public: + +struct Appearance : properties::PropertyOwner { + Appearance(); + /// Specifies the base color of the line before fading + properties::Vec3Property lineColor; + /// Settings that enables or disables the line fading + properties::BoolProperty useLineFade; + /// Specifies a multiplicative factor that fades out the line + properties::FloatProperty lineFade; + /// Line width for the line rendering part + properties::FloatProperty lineWidth; + /// Point size for the point rendering part + properties::IntProperty pointSize; + /// The option determining which rendering method to use + properties::OptionProperty renderingModes; + }; + ~RenderableTrail() = default; void initializeGL() override; @@ -143,6 +160,8 @@ protected: RenderInformation _floatingRenderInformation; private: + +/* /// Specifies the base color of the line before fading properties::Vec3Property _lineColor; /// Settings that enables or disables the line fading @@ -156,6 +175,9 @@ private: /// The option determining which rendering method to use properties::OptionProperty _renderingModes; + */ + Appearance _appearance; + /// Program object used to render the data stored in RenderInformation ghoul::opengl::ProgramObject* _programObject = nullptr; diff --git a/modules/space/CMakeLists.txt b/modules/space/CMakeLists.txt index 107c86614b..5a0843fc61 100644 --- a/modules/space/CMakeLists.txt +++ b/modules/space/CMakeLists.txt @@ -25,51 +25,55 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometry.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableconstellationbounds.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanet.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablerings.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.h - ${CMAKE_CURRENT_SOURCE_DIR}/translation/keplertranslation.h - ${CMAKE_CURRENT_SOURCE_DIR}/translation/spicetranslation.h - ${CMAKE_CURRENT_SOURCE_DIR}/translation/tletranslation.h - ${CMAKE_CURRENT_SOURCE_DIR}/translation/horizonstranslation.h - ${CMAKE_CURRENT_SOURCE_DIR}/rotation/spicerotation.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometry.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableconstellationbounds.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanet.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesatellites.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablerings.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.h + ${CMAKE_CURRENT_SOURCE_DIR}/translation/keplertranslation.h + ${CMAKE_CURRENT_SOURCE_DIR}/translation/spicetranslation.h + ${CMAKE_CURRENT_SOURCE_DIR}/translation/tletranslation.h + ${CMAKE_CURRENT_SOURCE_DIR}/translation/horizonstranslation.h + ${CMAKE_CURRENT_SOURCE_DIR}/rotation/spicerotation.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometry.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableconstellationbounds.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanet.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablerings.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/translation/keplertranslation.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/translation/spicetranslation.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/translation/tletranslation.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/translation/horizonstranslation.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rotation/spicerotation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometry.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableconstellationbounds.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanet.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablesatellites.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablerings.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/translation/keplertranslation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/translation/spicetranslation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/translation/tletranslation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/translation/horizonstranslation.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rotation/spicerotation.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/nighttexture_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/nighttexture_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableplanet_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableplanet_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/rings_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/rings_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_nighttexture_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_nighttexture_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_ge.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/nighttexture_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/nighttexture_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderablekeplerorbits_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderablekeplerorbits_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableplanet_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableplanet_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/rings_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/rings_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_nighttexture_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_nighttexture_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_ge.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_vs.glsl ) source_group("Shader Files" FILES ${SHADER_FILES}) diff --git a/modules/space/rendering/renderablesatellites.cpp b/modules/space/rendering/renderablesatellites.cpp index 626faeca35..9a341e9062 100644 --- a/modules/space/rendering/renderablesatellites.cpp +++ b/modules/space/rendering/renderablesatellites.cpp @@ -228,16 +228,16 @@ RenderableSatellites::RenderableSatellites(const ghoul::Dictionary& dictionary) * test */ - const std::string& file = dictionary.value(KeyFile); int lineNumber = 1; - if (dictionary.hasKeyAndValue)(KeyLineNumber) { + if (dictionary.hasKeyAndValue(KeyLineNumber)) { lineNumber = static_cast(dictionary.value(KeyLineNumber)); } readTLEFile(file, lineNumber); } -void RenderableSatellites::readTLEFile(const std::string& filename, int lineNumber){ +void RenderableSatellites::readTLEFile(const std::string& filename, int lineNum){ ghoul_assert(FileSys.fileExists(filename), "The filename must exist"); std::ifstream file; diff --git a/modules/space/rendering/renderablesatellites.h b/modules/space/rendering/renderablesatellites.h index e9e3dae852..562648d2cd 100644 --- a/modules/space/rendering/renderablesatellites.h +++ b/modules/space/rendering/renderablesatellites.h @@ -27,7 +27,7 @@ #include #include -#include +// #include #include #include diff --git a/modules/space/shaders/renderablekeplerorbits_fs.glsl b/modules/space/shaders/renderablekeplerorbits_fs.glsl new file mode 100644 index 0000000000..cf095fb168 --- /dev/null +++ b/modules/space/shaders/renderablekeplerorbits_fs.glsl @@ -0,0 +1,46 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * 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 "floatoperations.glsl" + +uniform vec3 color; +uniform float opacity = 1.0; +uniform bool useLineFade; +uniform float lineFade; + +in vec4 viewSpacePosition; + +Fragment getFragment() { + Fragment frag; + frag.color = vec4(color, opacity); + frag.depth = safeLength(viewSpacePosition); + frag.blend = BLEND_MODE_ADDITIVE; + frag.gPosition = viewSpacePosition; + + // There is no normal here + frag.gNormal = vec4(0.0, 0.0, -1.0, 1.0); + + return frag; +} \ No newline at end of file diff --git a/modules/space/shaders/renderablekeplerorbits_vs.glsl b/modules/space/shaders/renderablekeplerorbits_vs.glsl new file mode 100644 index 0000000000..9640dea8aa --- /dev/null +++ b/modules/space/shaders/renderablekeplerorbits_vs.glsl @@ -0,0 +1,44 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * 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 vertexData; + +uniform dmat4 modelViewTransform; +uniform mat4 projectionTransform; +uniform bool useLineFade; +uniform float lineFade; +uniform int vertexSortingMethod; +uniform int pointSize; + +out vec4 viewSpacePosition; + +void main() { + dvec4 position = dvec4(vertexData.xyz, 1.0); + float timeOffset = vertexData.w; + + viewSpacePosition = vec4(modelViewTransform * position); + gl_Position = projectionTransform * viewSpacePosition; +} \ No newline at end of file diff --git a/modules/space/translation/keplertranslation.h b/modules/space/translation/keplertranslation.h index 762c95c29e..f357e297bc 100644 --- a/modules/space/translation/keplertranslation.h +++ b/modules/space/translation/keplertranslation.h @@ -47,6 +47,27 @@ public: std::string offender; }; + struct KeplerOrbit { + /// The period of the orbit in seconds + double period() const; + /// The eccentricity of the orbit in [0, 1) + double eccentricity; + /// The semi-major axis in km + double semiMajorAxis; + /// The inclination of the orbit in [0, 360] + double inclination; + /// The right ascension of the ascending node in [0, 360] + double ascendingNode; + /// The argument of periapsis in [0, 360] + double argumentOfPeriapsis; + /// The mean anomaly at the epoch in [0, 360] + double meanAnomalyAtEpoch; + /// The epoch in seconds relative to the J2000 epoch + double epoch; + /// The mass of the more massive body + double massiveBodyMass = 1.989E30; // Sun's mass in kg + }; + /** * The constructor that retrieves the required Keplerian elements from the passed * \p dictionary. These values are then apssed to the setKeplerElements method for