mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 20:13:22 +08:00
Do Geometry Shader normal visualization in view-space to prevent perspective distortion.
This commit is contained in:
@@ -8,11 +8,13 @@ in VS_OUT {
|
|||||||
|
|
||||||
const float MAGNITUDE = 0.2;
|
const float MAGNITUDE = 0.2;
|
||||||
|
|
||||||
|
uniform mat4 projection;
|
||||||
|
|
||||||
void GenerateLine(int index)
|
void GenerateLine(int index)
|
||||||
{
|
{
|
||||||
gl_Position = gl_in[index].gl_Position;
|
gl_Position = projection * gl_in[index].gl_Position;
|
||||||
EmitVertex();
|
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();
|
EmitVertex();
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,12 @@ out VS_OUT {
|
|||||||
vec3 normal;
|
vec3 normal;
|
||||||
} vs_out;
|
} vs_out;
|
||||||
|
|
||||||
uniform mat4 projection;
|
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
uniform mat4 model;
|
uniform mat4 model;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
mat3 normalMatrix = mat3(transpose(inverse(view * model)));
|
mat3 normalMatrix = mat3(transpose(inverse(view * model)));
|
||||||
vs_out.normal = vec3(projection * vec4(normalMatrix * aNormal, 0.0));
|
vs_out.normal = vec3(vec4(normalMatrix * aNormal, 0.0));
|
||||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
gl_Position = view * model * vec4(aPos, 1.0);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user