Spaces:
Sleeping
Sleeping
File size: 1,352 Bytes
b4c8bc3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#version 330 core
layout (triangles) in;
#ifdef FACE_NORMALS
#ifdef VERTEX_NORMALS
layout (line_strip, max_vertices = 8) out;
#else
layout (line_strip, max_vertices = 2) out;
#endif
#else
layout (line_strip, max_vertices = 6) out;
#endif
in VS_OUT {
vec3 position;
vec3 normal;
mat4 mvp;
} gs_in[];
uniform float normal_magnitude;
void GenerateVertNormal(int index)
{
vec4 p0 = gs_in[index].mvp * vec4(gs_in[index].position, 1.0);
vec4 p1 = gs_in[index].mvp * vec4(normal_magnitude * normalize(gs_in[index].normal) + gs_in[index].position, 1.0);
gl_Position = p0;
EmitVertex();
gl_Position = p1;
EmitVertex();
EndPrimitive();
}
void GenerateFaceNormal()
{
vec3 p0 = gs_in[0].position.xyz;
vec3 p1 = gs_in[1].position.xyz;
vec3 p2 = gs_in[2].position.xyz;
vec3 v0 = p0 - p1;
vec3 v1 = p2 - p1;
vec3 N = normalize(cross(v1, v0));
vec3 P = (p0 + p1 + p2) / 3.0;
vec4 np0 = gs_in[0].mvp * vec4(P, 1.0);
vec4 np1 = gs_in[0].mvp * vec4(normal_magnitude * N + P, 1.0);
gl_Position = np0;
EmitVertex();
gl_Position = np1;
EmitVertex();
EndPrimitive();
}
void main()
{
#ifdef FACE_NORMALS
GenerateFaceNormal();
#endif
#ifdef VERTEX_NORMALS
GenerateVertNormal(0);
GenerateVertNormal(1);
GenerateVertNormal(2);
#endif
}
|