Add ability to draw normals

This commit is contained in:
2024-12-30 17:31:54 +00:00
parent f65410b7ad
commit acefc1d254
4 changed files with 117 additions and 23 deletions

7
shaders/normal_frag.glsl Normal file
View File

@@ -0,0 +1,7 @@
#version 330 core
out vec4 color;
void main() {
color = vec4(1.0, 1.0, 0.0, 1.0);
}

34
shaders/normal_geo.glsl Normal file
View File

@@ -0,0 +1,34 @@
#version 330 core
#define MAGNITUDE 0.1
layout (triangles) in;
layout (line_strip, max_vertices = 6) out;
uniform float time;
in VS_OUT {
vec3 vert_normal;
} gs_in[];
layout (std140) uniform Common {
mat4 projection;
mat4 view;
vec3 camera_position;
};
void generate_line(int index) {
gl_Position = projection * gl_in[index].gl_Position;
EmitVertex();
gl_Position = projection * (gl_in[index].gl_Position + vec4(gs_in[index].vert_normal, 1.0) * MAGNITUDE);
EmitVertex();
EndPrimitive();
}
void main() {
for (int i = 0; i < 3; ++i) {
generate_line(i);
}
}

25
shaders/normal_vert.glsl Normal file
View File

@@ -0,0 +1,25 @@
#version 330 core
layout(location=0) in vec3 position;
layout(location=1) in vec3 normal;
layout(location=2) in vec2 uv;
uniform mat3 normal_mat;
uniform mat4 model;
layout (std140) uniform Common {
mat4 projection;
mat4 view;
vec3 camera_position;
};
// interface block
out VS_OUT {
vec3 vert_normal;
} vs_out;
void main() {
vs_out.vert_normal = normal_mat * normal;
gl_Position = view * model * vec4(position, 1.0);
};