Last active
December 20, 2015 18:49
-
-
Save hamsham/6178927 to your computer and use it in GitHub Desktop.
A GLSL 330 shader program to visualize polygon edges, vertex normals, tangents, and bitangents.Vertices are passed in as normal to the vertex shader, colors are set in the geometry shader.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
* Edge/Normal/Tangent/Bitangent Visualizer | |
******************************************************************************/ | |
/** | |
* Vertex Shader | |
*/ | |
const char enbtVS[] = R"( | |
#version 330 | |
uniform mat4 mvpMatrix; | |
layout ( location = 0 ) in vec3 posVerts; | |
layout ( location = 1 ) in vec2 texVerts; | |
layout ( location = 2 ) in vec3 normVerts; | |
layout ( location = 3 ) in vec3 tangVerts; | |
layout ( location = 4 ) in vec3 btngVerts; | |
out vec4 normPos; | |
out vec4 tangPos; | |
out vec4 btngPos; | |
void main() { | |
gl_Position = mvpMatrix * vec4( posVerts, 1.0 ); | |
normPos = mvpMatrix * vec4( normVerts, 0.0 ); | |
tangPos = mvpMatrix * vec4( tangVerts, 0.0 ); | |
btngPos = mvpMatrix * vec4( btngVerts, 0.0 ); | |
} | |
)"; | |
/** | |
* Geometry Shader | |
*/ | |
const char enbtGS[] = R"( | |
#version 330 | |
layout( triangles ) in; | |
layout( line_strip, max_vertices = 21 ) out; | |
uniform bool showEdges = true; | |
uniform bool showNormals = false; | |
uniform bool showTangents = false; | |
uniform bool showBitangents = false; | |
in vec4 normPos[]; | |
in vec4 tangPos[]; | |
in vec4 btngPos[]; | |
out vec4 lineCol; | |
void main() { | |
vec4 edgeColor = vec4( 1.0, 0.0, 1.0, 1.0 ); | |
vec4 normColor = vec4( 0.0, 1.0, 0.0, 1.0 ); | |
vec4 tangColor = vec4( 1.0, 0.0, 0.0, 1.0 ); | |
vec4 btngColor = vec4( 0.0, 0.0, 1.0, 1.0 ); | |
for ( int i = 0; i < 3; ++i ) { | |
vec4 origin = gl_in[i].gl_Position; | |
if ( showBitangents ) { | |
lineCol = btngColor; | |
gl_Position = origin; | |
EmitVertex(); | |
gl_Position = origin + btngPos[i]; | |
EmitVertex(); | |
EndPrimitive(); | |
} | |
if ( showTangents ) { | |
lineCol = tangColor; | |
gl_Position = origin; | |
EmitVertex(); | |
gl_Position = origin + tangPos[i]; | |
EmitVertex(); | |
EndPrimitive(); | |
} | |
if ( showNormals ) { | |
lineCol = normColor; | |
gl_Position = origin; | |
EmitVertex(); | |
gl_Position = origin + normPos[i]; | |
EmitVertex(); | |
EndPrimitive(); | |
} | |
} | |
if ( showEdges ) { | |
lineCol = edgeColor; | |
vec4 a = gl_in[0].gl_Position; | |
vec4 b = gl_in[1].gl_Position; | |
vec4 c = gl_in[2].gl_Position; | |
gl_Position = a; | |
EmitVertex(); | |
gl_Position = b; | |
EmitVertex(); | |
EndPrimitive(); | |
gl_Position = b; | |
EmitVertex(); | |
gl_Position = c; | |
EmitVertex(); | |
EndPrimitive(); | |
gl_Position = c; | |
EmitVertex(); | |
gl_Position = a; | |
EmitVertex(); | |
EndPrimitive(); | |
} | |
} | |
)"; | |
/** | |
* Fragment Shader | |
*/ | |
const char enbtFS[] = R"( | |
#version 330 | |
in vec4 lineCol; | |
out vec4 fragCol; | |
void main() { | |
fragCol = lineCol; | |
} | |
)"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment