Browse Source

Shaders: fix MeshVisualizer vertex and object ID to work with TBN.

And also expand the docs to say the TBN visualization is not AAd when
used together with those, not just with wireframe.
pull/539/head
Vladimír Vondruš 4 years ago
parent
commit
2ac2155f2c
  1. 2
      doc/changelog.dox
  2. 12
      src/Magnum/Shaders/MeshVisualizer.geom
  3. 2
      src/Magnum/Shaders/MeshVisualizerGL.cpp
  4. 9
      src/Magnum/Shaders/MeshVisualizerGL.h

2
doc/changelog.dox

@ -608,6 +608,8 @@ See also:
compilation failed on OpenGL ES 3.2 with missing @glsl gl_PrimitiveID @ce
due to GLSL ES 3.20 not being properly used for the @glsl #version @ce
directive
- @ref Shaders::MeshVisualizerGL3D vertex ID visualization didn't work when
enabled together with TBN visualization
- @ref Shaders::PhongGL was normalizing light direction in vertex shader,
causing the fragment-interpolated direction being incorrect with visible
artifacts on long polygons under low light angle

12
src/Magnum/Shaders/MeshVisualizer.geom

@ -44,7 +44,7 @@ layout(location = 0)
uniform lowp vec2 viewportSize; /* defaults to zero */
#ifndef UNIFORM_BUFFERS
#if (defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)) && (defined(WIREFRAME_RENDERING) || defined(INSTANCED_OBJECT_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID))
#if (defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)) && (defined(WIREFRAME_RENDERING) || defined(OBJECT_ID) || defined(VERTEX_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID))
#ifdef EXPLICIT_UNIFORM_LOCATION
layout(location = 1)
#endif
@ -234,8 +234,8 @@ void emitQuad(
/* Calculate screen-space locations for the bar vertices and form two
triangles out of them. In case TBN is rendered alone, half bar width is
lineWidth + smoothness to allow for antialiasing, in case it's rendered
together with wireframe, it's just lineWidth, as antialiasing would
cause depth order issues.
together with wireframe, object ID, vertex ID or primitive ID, it's just
lineWidth, as antialiasing would cause depth order issues.
3 - e - 1 -S_-w_0__w_S -w_0__w
| /| | | | | | |
@ -251,7 +251,7 @@ void emitQuad(
and to 0 otherwise. See the fragment shader for details.
*/
vec2 direction = normalize(endpointScreen - positionScreen);
#if defined(WIREFRAME_RENDERING) || defined(INSTANCED_OBJECT_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID)
#if defined(WIREFRAME_RENDERING) || defined(OBJECT_ID) || defined(VERTEX_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID)
float edgeDistance = 0.0;
vec2 halfSide = lineWidth*vec2(-direction.y, direction.x);
#else
@ -292,7 +292,7 @@ void main() {
#endif
mediump const uint materialId = draws[drawId].draw_materialIdReserved & 0xffffu;
#if (defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)) && (defined(WIREFRAME_RENDERING) || defined(INSTANCED_OBJECT_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID))
#if (defined(TANGENT_DIRECTION) || defined(BITANGENT_DIRECTION) || defined(NORMAL_DIRECTION)) && (defined(WIREFRAME_RENDERING) || defined(OBJECT_ID) || defined(VERTEX_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID))
lowp const vec4 color = materials[materialId].color;
lowp const vec4 wireframeColor = materials[materialId].wireframeColor;
#endif
@ -340,7 +340,7 @@ void main() {
#endif
}
#if defined(WIREFRAME_RENDERING) || defined(INSTANCED_OBJECT_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID)
#if defined(WIREFRAME_RENDERING) || defined(OBJECT_ID) || defined(VERTEX_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID)
/* Vector of each triangle side */
const vec2 v[3] = vec2[3](
p[2]-p[1],

2
src/Magnum/Shaders/MeshVisualizerGL.cpp

@ -447,6 +447,7 @@ MeshVisualizerGL2D::MeshVisualizerGL2D(const Flags flags
.addSource("#define WIREFRAME_RENDERING\n#define MAX_VERTICES 3\n")
.addSource(_flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "")
.addSource(_flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "")
.addSource(_flags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "")
.addSource(_flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "")
.addSource(_flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "")
.addSource(_flags & FlagBase::PrimitiveId ?
@ -782,6 +783,7 @@ MeshVisualizerGL3D::MeshVisualizerGL3D(const Flags flags
.addSource(flags & Flag::Wireframe ? "#define WIREFRAME_RENDERING\n" : "")
.addSource(_flags >= FlagBase::ObjectIdTexture ? "#define TEXTURED\n" : "")
.addSource(_flags & FlagBase::TextureArrays ? "#define TEXTURE_ARRAYS\n" : "")
.addSource(_flags & FlagBase::ObjectId ? "#define OBJECT_ID\n" : "")
.addSource(_flags >= FlagBase::InstancedObjectId ? "#define INSTANCED_OBJECT_ID\n" : "")
.addSource(_flags & FlagBase::VertexId ? "#define VERTEX_ID\n" : "")
.addSource(_flags & FlagBase::PrimitiveId ?

9
src/Magnum/Shaders/MeshVisualizerGL.h

@ -959,10 +959,11 @@ Rendering setup the same as above.
@section Shaders-MeshVisualizerGL3D-tbn Tangent space visualization
On platforms with geometry shaders (desktop GL, OpenGL ES 3.2), the shader is
able to visualize tangents, bitangent and normal direction via colored lines
coming out of vertices (red, green and blue for tangent, bitangent and normal, respectively). This can be enabled together with wireframe visualization,
however note that when both are enabled, the lines are not antialiased to avoid
depth ordering artifacts.
able to visualize tangent, bitangent and normal direction via colored lines
coming out of vertices (red, green and blue for tangent, bitangent and normal, respectively). This can be enabled together with wireframe, object ID,
vertex ID or primitive ID visualization, however note that when both are
enabled, the lines are not antialiased to avoid depth ordering artifacts
between faces and lines.
For tangents and normals, you need to provide the @ref Tangent and @ref Normal
attributes and enable @ref Flag::TangentDirection and

Loading…
Cancel
Save