Fix DebugAxis helper; Increase the sensitivity to prevent loss of color in debug axis (closes #1560)

This commit is contained in:
Alexander Bock
2021-07-28 14:49:29 +02:00
parent 6628b9f0b4
commit 309bce2e30
5 changed files with 27 additions and 31 deletions

View File

@@ -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<Vertex> 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);

View File

@@ -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;
}

View File

@@ -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;
}