From 309bce2e30c11715c2eef8e5d0c07ef18211c2bb Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 28 Jul 2021 14:49:29 +0200 Subject: [PATCH] Fix DebugAxis helper; Increase the sensitivity to prevent loss of color in debug axis (closes #1560) --- data/assets/util/debug_helper.asset | 2 +- .../rendering/renderablecartesianaxes.cpp | 14 ++++------- modules/base/shaders/axes_fs.glsl | 23 +++++++++++-------- modules/base/shaders/axes_vs.glsl | 16 ++++++------- modules/globebrowsing/src/tileprovider.cpp | 3 --- 5 files changed, 27 insertions(+), 31 deletions(-) diff --git a/data/assets/util/debug_helper.asset b/data/assets/util/debug_helper.asset index 6c75714d06..9b10fb04c6 100644 --- a/data/assets/util/debug_helper.asset +++ b/data/assets/util/debug_helper.asset @@ -67,7 +67,7 @@ local addCartesianAxes = function (specification) Parent = parent, Transform = { Scale = { - Type = "StaticScale", + Type = "NonUniformStaticScale", Scale = scale }, Translation = { diff --git a/modules/base/rendering/renderablecartesianaxes.cpp b/modules/base/rendering/renderablecartesianaxes.cpp index 9b658ac953..2228fa11e1 100644 --- a/modules/base/rendering/renderablecartesianaxes.cpp +++ b/modules/base/rendering/renderablecartesianaxes.cpp @@ -118,14 +118,7 @@ void RenderableCartesianAxes::initializeGL() { ); glGenVertexArrays(1, &_vaoId); - glGenBuffers(1, &_vBufferId); - glGenBuffers(1, &_iBufferId); - glBindVertexArray(_vaoId); - glBindBuffer(GL_ARRAY_BUFFER, _vBufferId); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); - glEnableVertexAttribArray(0); - glBindVertexArray(0); std::vector vertices({ Vertex{0.f, 0.f, 0.f}, @@ -140,7 +133,7 @@ void RenderableCartesianAxes::initializeGL() { 0, 3 }; - glBindVertexArray(_vaoId); + glGenBuffers(1, &_vBufferId); glBindBuffer(GL_ARRAY_BUFFER, _vBufferId); glBufferData( GL_ARRAY_BUFFER, @@ -149,8 +142,10 @@ void RenderableCartesianAxes::initializeGL() { GL_STATIC_DRAW ); + glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr); + glGenBuffers(1, &_iBufferId); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); glBufferData( GL_ELEMENT_ARRAY_BUFFER, @@ -158,6 +153,7 @@ void RenderableCartesianAxes::initializeGL() { indices.data(), GL_STATIC_DRAW ); + glBindVertexArray(0); } void RenderableCartesianAxes::deinitializeGL() { @@ -201,9 +197,9 @@ void RenderableCartesianAxes::render(const RenderData& data, RendererTasks&){ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnablei(GL_BLEND, 0); glEnable(GL_LINE_SMOOTH); + glLineWidth(3.0); glBindVertexArray(_vaoId); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iBufferId); glDrawElements(GL_LINES, NVertexIndices, GL_UNSIGNED_INT, nullptr); glBindVertexArray(0); diff --git a/modules/base/shaders/axes_fs.glsl b/modules/base/shaders/axes_fs.glsl index 912657481c..182e24e973 100644 --- a/modules/base/shaders/axes_fs.glsl +++ b/modules/base/shaders/axes_fs.glsl @@ -33,17 +33,20 @@ uniform vec3 yColor; uniform vec3 zColor; Fragment getFragment() { - Fragment frag; + Fragment frag; - vec3 colorComponents = step(0.01, vs_positionModelSpace); + // We compare against a small value as the first vertex doesn't have a positional + // information (or rather it is 0) and we don't want to miss out on the color close to + // the origin + vec3 colorComponents = step(2e-32, vs_positionModelSpace); - frag.color.rgb = colorComponents.x * xColor + - colorComponents.y * yColor + - colorComponents.z * zColor; - frag.color.a = 1.0; + frag.color.rgb = colorComponents.x * xColor + + colorComponents.y * yColor + + colorComponents.z * zColor; + frag.color.a = 1.0; - frag.depth = vs_screenSpaceDepth; - frag.gPosition = vs_positionViewSpace; - frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); - return frag; + frag.depth = vs_screenSpaceDepth; + frag.gPosition = vs_positionViewSpace; + frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + return frag; } diff --git a/modules/base/shaders/axes_vs.glsl b/modules/base/shaders/axes_vs.glsl index 539b4ddd18..feb654a310 100644 --- a/modules/base/shaders/axes_vs.glsl +++ b/modules/base/shaders/axes_vs.glsl @@ -34,13 +34,13 @@ uniform mat4 modelViewTransform; uniform mat4 projectionTransform; void main() { - vec4 positionViewSpace = modelViewTransform * vec4(in_position, 1.0); - vec4 positionClipSpace = projectionTransform * positionViewSpace; - vec4 positionScreenSpace = positionClipSpace; - positionScreenSpace.z = 0.0; - vs_positionModelSpace = in_position; - vs_screenSpaceDepth = positionScreenSpace.w; - vs_positionViewSpace = positionViewSpace; + vec4 positionViewSpace = modelViewTransform * vec4(in_position, 1.0); + vec4 positionClipSpace = projectionTransform * positionViewSpace; + vec4 positionScreenSpace = positionClipSpace; + positionScreenSpace.z = 0.0; + vs_positionModelSpace = in_position; + vs_screenSpaceDepth = positionScreenSpace.w; + vs_positionViewSpace = positionViewSpace; - gl_Position = positionScreenSpace; + gl_Position = positionScreenSpace; } diff --git a/modules/globebrowsing/src/tileprovider.cpp b/modules/globebrowsing/src/tileprovider.cpp index 53d75717f3..0f743ec592 100644 --- a/modules/globebrowsing/src/tileprovider.cpp +++ b/modules/globebrowsing/src/tileprovider.cpp @@ -228,9 +228,7 @@ Tile tile(TextTileProvider& t, const TileIndex& tileIndex) { // Keep track of defaultFBO and viewport to be able to reset state when done GLint defaultFBO; - //GLint viewport[4]; defaultFBO = global::renderEngine->openglStateCache().defaultFramebuffer(); - //glGetIntegerv(GL_VIEWPORT, viewport); // Render to texture glBindFramebuffer(GL_FRAMEBUFFER, t.fbo); @@ -252,7 +250,6 @@ Tile tile(TextTileProvider& t, const TileIndex& tileIndex) { glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO); global::renderEngine->openglStateCache().resetViewportState(); - //glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); tile = Tile{ texture, std::nullopt, Tile::Status::OK }; t.tileCache->put(key, t.initData.hashKey, tile);