From b2d2039dc27e9e489ea74ced58e0aff4430cacf2 Mon Sep 17 00:00:00 2001 From: Lovisa Hassler Date: Fri, 13 Dec 2019 19:04:06 +0100 Subject: [PATCH] Trail fading for satellites and debris --- .../space/rendering/renderablesatellites.cpp | 22 ++++++++++++++----- .../space/rendering/renderablesatellites.h | 4 ---- modules/space/shaders/debrisViz_fs.glsl | 16 +++++++++++--- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/modules/space/rendering/renderablesatellites.cpp b/modules/space/rendering/renderablesatellites.cpp index 5476bf828f..9998db6b2c 100644 --- a/modules/space/rendering/renderablesatellites.cpp +++ b/modules/space/rendering/renderablesatellites.cpp @@ -308,7 +308,6 @@ RenderableSatellites::RenderableSatellites(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _path(PathInfo) , _nSegments(SegmentsInfo, 120, 4, 1024) - { documentation::testSpecificationAndThrow( Documentation(), @@ -322,6 +321,14 @@ RenderableSatellites::RenderableSatellites(const ghoul::Dictionary& dictionary) if (dictionary.hasKeyAndValue(LineColorInfo.identifier)) { _appearance.lineColor = dictionary.value(LineColorInfo.identifier); } + if (dictionary.hasKeyAndValue("FadeInfo")) { + _appearance.lineFade = static_cast( + dictionary.value("FadeInfo") + ); + } + else { + _appearance.lineFade = 20; + } auto reinitializeTrailBuffers = [this]() { initializeGL(); @@ -333,6 +340,9 @@ RenderableSatellites::RenderableSatellites(const ghoul::Dictionary& dictionary) addPropertySubOwner(_appearance); addProperty(_path); addProperty(_nSegments); + addProperty(_opacity); + + setRenderBin(Renderable::RenderBin::Overlay); } @@ -475,7 +485,6 @@ void RenderableSatellites::initializeGL() { _uniformCache.opacity = _programObject->uniformLocation("opacity"); updateBuffers(); - setRenderBin(Renderable::RenderBin::Overlay); } void RenderableSatellites::deinitializeGL() { @@ -514,9 +523,12 @@ void RenderableSatellites::render(const RenderData& data, RendererTasks&) { data.camera.combinedViewMatrix() * modelTransform ); + // Because we want the property to work similar to the planet trails + float fade = static_cast(pow(_appearance.lineFade.maxValue() - _appearance.lineFade, 2.0)); + _programObject->setUniform(_uniformCache.projection, data.camera.projectionMatrix()); _programObject->setUniform(_uniformCache.color, _appearance.lineColor); - _programObject->setUniform(_uniformCache.lineFade, _appearance.lineFade); + _programObject->setUniform(_uniformCache.lineFade, fade); glLineWidth(_appearance.lineWidth); @@ -595,10 +607,10 @@ void RenderableSatellites::updateBuffers() { ); glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), (GLvoid*)0); // stride : 4*sizeof(GL_FLOAT) + 2*sizeof(GL_DOUBLE) + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), nullptr); glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_DOUBLE, GL_FALSE, sizeof(TrailVBOLayout), (GLvoid*)(4*sizeof(GL_FLOAT)) ); + glVertexAttribPointer(1, 2, GL_DOUBLE, GL_FALSE, sizeof(TrailVBOLayout), (GLvoid*)(4 * sizeof(GL_FLOAT))); glBindVertexArray(0); diff --git a/modules/space/rendering/renderablesatellites.h b/modules/space/rendering/renderablesatellites.h index b2bf0864a0..8f58d936d8 100644 --- a/modules/space/rendering/renderablesatellites.h +++ b/modules/space/rendering/renderablesatellites.h @@ -94,10 +94,6 @@ private: /// trail. std::vector _vertexBufferData; - /// The index array that is potentially used in the draw call. If this is empty, no - /// element draw call is used. - std::vector _indexBufferData; - GLuint _vertexArray; GLuint _vertexBuffer; GLuint _indexBuffer; diff --git a/modules/space/shaders/debrisViz_fs.glsl b/modules/space/shaders/debrisViz_fs.glsl index ada17beb95..e54886d99a 100644 --- a/modules/space/shaders/debrisViz_fs.glsl +++ b/modules/space/shaders/debrisViz_fs.glsl @@ -63,15 +63,25 @@ Fragment getFragment() { vertexDistance_f += 1.0; } - float invert = 1.0 - vertexDistance_f; - float fade = clamp(invert * lineFade, 0.0, 1.0); + float invert = pow((1.0 - vertexDistance_f), lineFade); + float fade = clamp(invert, 0.0, 1.0); + // Currently even fully transparent lines can occlude other lines, thus we discard + // these fragments since debris and satellites are rendered so close to each other + if (fade < 0.05) { + discard; + } Fragment frag; + + // Use additive blending for some values to make the discarding less abrupt + if (fade < 0.15) { + frag.blend = BLEND_MODE_ADDITIVE; + } + frag.color = vec4(color, fade * opacity); frag.depth = vs_position_w; frag.gPosition = viewSpacePosition; frag.gNormal = vec4(1, 1, 1, 0); - // frag.blend = BLEND_MODE_ADDITIVE; // to debug using colors use this if-statment.