mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 03:00:58 -06:00
Merge pull request #1029 from OpenSpace/feature/FadeSatelliteTrails
Feature/fade satellite trails
This commit is contained in:
@@ -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<glm::vec3>(LineColorInfo.identifier)) {
|
||||
_appearance.lineColor = dictionary.value<glm::vec3>(LineColorInfo.identifier);
|
||||
}
|
||||
if (dictionary.hasKeyAndValue<double>("FadeInfo")) {
|
||||
_appearance.lineFade = static_cast<float>(
|
||||
dictionary.value<double>("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<float>(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);
|
||||
|
||||
@@ -94,10 +94,6 @@ private:
|
||||
/// trail.
|
||||
std::vector<TrailVBOLayout> _vertexBufferData;
|
||||
|
||||
/// The index array that is potentially used in the draw call. If this is empty, no
|
||||
/// element draw call is used.
|
||||
std::vector<unsigned int> _indexBufferData;
|
||||
|
||||
GLuint _vertexArray;
|
||||
GLuint _vertexBuffer;
|
||||
GLuint _indexBuffer;
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user