Merge pull request #1195 from OpenSpace/issue/1102

Fixes for spherical grids were flickering.
Although they are not flickering anymore, a better correction is needed in the future
This commit is contained in:
Alexander Bock
2020-06-13 16:47:56 +02:00
committed by GitHub
6 changed files with 66 additions and 37 deletions
+10 -5
View File
@@ -24,7 +24,8 @@ local radio = {
Renderable = {
Type = "RenderableSphericalGrid",
Enabled = false,
GridColor = { 0.3, 0.84, 1.0, 0.3},
Opacity = 1.0,
GridColor = { 0.3, 0.84, 1.0 },
LineWidth = 2.0,
GridMatrix = { -0.05487554, 0.4941095, -0.8676661 , 0.0,
-0.9938214 , -0.1109906, -0.0003515167, 0.0,
@@ -49,7 +50,8 @@ local oort = {
Renderable = {
Type = "RenderableSphericalGrid",
Enabled = false,
GridColor = { 0.8, 0.4, 0.4, 0.25},
Opacity = 0.8,
GridColor = { 0.8, 0.4, 0.4 },
LineWidth = 2.0,
GridMatrix = { -0.05487554, 0.4941095, -0.8676661 , 0.0,
-0.9938214 , -0.1109906, -0.0003515167, 0.0,
@@ -74,7 +76,8 @@ local ecliptic = {
Renderable = {
Type = "RenderableSphericalGrid",
Enabled = false,
GridColor = { 0.74, 0.26, 0.26, 0.5},
Opacity = 1.0,
GridColor = { 0.74, 0.26, 0.26 },
LineWidth = 2.0,
GridMatrix = { -0.05487554, 0.4941095, -0.8676661 , 0.0,
-0.9938214 , -0.1109906, -0.0003515167, 0.0,
@@ -127,7 +130,8 @@ local equatorial = {
Renderable = {
Type = "RenderableSphericalGrid",
Enabled = false,
GridColor = { 0.69, 0.68, 0.29, 0.8},
Opacity = 0.8,
GridColor = { 0.69, 0.68, 0.29 },
LineWidth = 2.0,
GridMatrix = { -0.05487554, 0.4941095, -0.8676661, 0.0,
-0.8734371 , -0.4448296, -0.1980764, 0.0,
@@ -181,7 +185,8 @@ local galactic = {
Type = "RenderableSphericalGrid",
Enabled = false,
LineWidth = 2.0,
GridColor = { 0.0, 0.6, 0.6, 0.6}
Opacity = 1.0,
GridColor = { 0.0, 0.6, 0.6 }
},
GUI = {
Name = "Galactic Sphere",
@@ -80,7 +80,7 @@ documentation::Documentation RenderableSphericalGrid::Documentation() {
},
{
GridColorInfo.identifier,
new DoubleVector4Verifier,
new DoubleVector3Verifier,
Optional::Yes,
GridColorInfo.description
},
@@ -107,9 +107,9 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio
, _gridMatrix(GridMatrixInfo, glm::mat4(1.f))
, _gridColor(
GridColorInfo,
glm::vec4(0.5f, 0.5, 0.5f, 1.f),
glm::vec4(0.f),
glm::vec4(1.f)
glm::vec3(0.5f, 0.5, 0.5f),
glm::vec3(0.f),
glm::vec3(1.f)
)
, _segments(SegmentsInfo, 36, 4, 200)
, _lineWidth(LineWidthInfo, 0.5f, 0.f, 20.f)
@@ -129,7 +129,7 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio
addProperty(_gridMatrix);
if (dictionary.hasKey(GridColorInfo.identifier)) {
_gridColor = dictionary.value<glm::vec4>(GridColorInfo.identifier);
_gridColor = dictionary.value<glm::vec3>(GridColorInfo.identifier);
}
_gridColor.setViewOption(properties::Property::ViewOptions::Color);
addProperty(_gridColor);
@@ -214,16 +214,29 @@ void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){
const glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() *
modelTransform;
_gridProgram->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
_gridProgram->setUniform("projectionTransform", data.camera.projectionMatrix());
_gridProgram->setUniform("modelViewTransform", modelViewTransform);
_gridProgram->setUniform(
"MVPTransform",
glm::dmat4(data.camera.projectionMatrix()) * modelViewTransform
);
_gridProgram->setUniform("gridColor", _gridColor);
float adjustedLineWidth = 1.f;
#ifndef __APPLE__
adjustedLineWidth = _lineWidth;
#endif
// Saves current state:
GLboolean isBlendEnabled = glIsEnabledi(GL_BLEND, 0);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
GLfloat currentLineWidth;
glGetFloatv(GL_LINE_WIDTH, &currentLineWidth);
GLboolean isLineSmoothEnabled = glIsEnabled(GL_LINE_SMOOTH);
GLenum currentDepthFunction;
glGetIntegerv(GL_DEPTH_FUNC, &currentDepthFunction);
glDepthFunc(GL_LEQUAL);
GLenum blendEquationRGB, blendEquationAlpha, blendDestAlpha,
blendDestRGB, blendSrcAlpha, blendSrcRGB;
@@ -235,11 +248,11 @@ void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){
glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB);
// Changes GL state:
glLineWidth(_lineWidth);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(adjustedLineWidth);
glEnablei(GL_BLEND, 0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glBindVertexArray(_vaoID);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferID);
glDrawElements(_mode, _isize, GL_UNSIGNED_INT, nullptr);
@@ -251,12 +264,16 @@ void RenderableSphericalGrid::render(const RenderData& data, RendererTasks&){
glLineWidth(currentLineWidth);
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
if (!isBlendEnabled) {
glDisablei(GL_BLEND, 0);
}
if (!isLineSmoothEnabled) {
glDisable(GL_LINE_SMOOTH);
}
glDepthFunc(currentDepthFunction);
}
void RenderableSphericalGrid::update(const UpdateData&) {
@@ -31,7 +31,7 @@
#include <openspace/properties/matrix/dmat4property.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/scalar/intproperty.h>
#include <openspace/properties/vector/vec4property.h>
#include <openspace/properties/vector/vec3property.h>
#include <ghoul/opengl/ghoul_gl.h>
namespace ghoul::opengl { class ProgramObject; }
@@ -63,7 +63,7 @@ protected:
ghoul::opengl::ProgramObject* _gridProgram;
properties::DMat4Property _gridMatrix;
properties::Vec4Property _gridColor;
properties::Vec3Property _gridColor;
properties::IntProperty _segments;
properties::FloatProperty _lineWidth;
+11 -7
View File
@@ -25,18 +25,22 @@
#include "fragment.glsl"
#include "PowerScaling/powerScaling_fs.hglsl"
in float vs_screenSpaceDepth;
in float vs_depthClipSpace;
in vec4 vs_positionViewSpace;
uniform vec4 gridColor;
uniform vec3 gridColor;
uniform float opacity;
Fragment getFragment() {
Fragment frag;
frag.color = gridColor;
frag.color.a *= opacity;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vs_positionViewSpace;
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
frag.color.rgb = gridColor;
frag.color.a = opacity;
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;
}
+12 -9
View File
@@ -28,18 +28,21 @@
layout(location = 0) in vec3 in_position;
out float vs_screenSpaceDepth;
out float vs_depthClipSpace;
out vec4 vs_positionViewSpace;
uniform mat4 modelViewTransform;
uniform mat4 projectionTransform;
uniform dmat4 modelViewTransform;
uniform dmat4 MVPTransform;
void main() {
vec4 positionViewSpace = modelViewTransform * vec4(in_position, 1.0);
vec4 positionClipSpace = projectionTransform * positionViewSpace;
vec4 positionScreenSpace = z_normalization(positionClipSpace);
vs_screenSpaceDepth = positionScreenSpace.w;
vs_positionViewSpace = positionViewSpace;
dvec4 objPosDouble = dvec4(in_position, 1.0);
dvec4 positionViewSpace = modelViewTransform * objPosDouble;
dvec4 positionClipSpace = MVPTransform * objPosDouble;
gl_Position = positionScreenSpace;
positionClipSpace.z = 0.0;
vs_depthClipSpace = float(positionClipSpace.w);
vs_positionViewSpace = vec4(positionViewSpace);
gl_Position = vec4(positionClipSpace);
}
+2 -2
View File
@@ -735,13 +735,13 @@ void SceneGraphNode::computeScreenSpaceData(RenderData& newData) {
);
constexpr const double RadiusThreshold = 2.0;
const double r = abs(_screenSizeRadius - screenSpaceRadius);
const double r = std::fabs(_screenSizeRadius - screenSpaceRadius);
if (r > RadiusThreshold) {
_screenSizeRadius = screenSpaceRadius;
}
constexpr const double ZoomThreshold = 0.1;
const double d = abs(_distFromCamToNode - distFromCamToNode);
const double d = std::fabs(_distFromCamToNode - distFromCamToNode);
if (d > (ZoomThreshold * distFromCamToNode)) {
_distFromCamToNode = distFromCamToNode;
}