Do Geometry Shader normal visualization in view-space to prevent perspective distortion.

This commit is contained in:
Joey de Vries
2020-06-04 17:41:32 +02:00
parent 3c5fd34424
commit 3615cfce79
2 changed files with 6 additions and 5 deletions

View File

@@ -8,11 +8,13 @@ in VS_OUT {
const float MAGNITUDE = 0.2;
uniform mat4 projection;
void GenerateLine(int index)
{
gl_Position = gl_in[index].gl_Position;
gl_Position = projection * gl_in[index].gl_Position;
EmitVertex();
gl_Position = gl_in[index].gl_Position + vec4(gs_in[index].normal, 0.0) * MAGNITUDE;
gl_Position = projection * (gl_in[index].gl_Position + vec4(gs_in[index].normal, 0.0) * MAGNITUDE);
EmitVertex();
EndPrimitive();
}

View File

@@ -6,13 +6,12 @@ out VS_OUT {
vec3 normal;
} vs_out;
uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
void main()
{
mat3 normalMatrix = mat3(transpose(inverse(view * model)));
vs_out.normal = vec3(projection * vec4(normalMatrix * aNormal, 0.0));
gl_Position = projection * view * model * vec4(aPos, 1.0);
vs_out.normal = vec3(vec4(normalMatrix * aNormal, 0.0));
gl_Position = view * model * vec4(aPos, 1.0);
}