Team Ai
Apppublic

OpenMotionLab/MotionGPT

sourceHugging Facemitupdated 1y agoView on Hugging Face
118likes
vertex_normals.geom75 linesDownload Raw Back to shaders
1#version 330 core2 3layout (triangles) in;4 5#ifdef FACE_NORMALS6 7#ifdef VERTEX_NORMALS8    layout (line_strip, max_vertices = 8) out;9#else10    layout (line_strip, max_vertices = 2) out;11#endif12 13#else14 15    layout (line_strip, max_vertices = 6) out;16 17#endif18 19in VS_OUT {20    vec3 position;21    vec3 normal;22    mat4 mvp;23} gs_in[];24 25uniform float normal_magnitude;26 27void GenerateVertNormal(int index)28{29 30    vec4 p0 = gs_in[index].mvp * vec4(gs_in[index].position, 1.0);31    vec4 p1 = gs_in[index].mvp * vec4(normal_magnitude * normalize(gs_in[index].normal) + gs_in[index].position, 1.0);32    gl_Position = p0;33    EmitVertex();34    gl_Position = p1;35    EmitVertex();36    EndPrimitive();37}38 39void GenerateFaceNormal()40{41    vec3 p0 = gs_in[0].position.xyz;42    vec3 p1 = gs_in[1].position.xyz;43    vec3 p2 = gs_in[2].position.xyz;44 45    vec3 v0 = p0 - p1;46    vec3 v1 = p2 - p1;47 48    vec3 N = normalize(cross(v1, v0));49    vec3 P = (p0 + p1 + p2) / 3.0;50 51    vec4 np0 = gs_in[0].mvp * vec4(P, 1.0);52    vec4 np1 = gs_in[0].mvp * vec4(normal_magnitude * N + P, 1.0);53 54    gl_Position = np0;55    EmitVertex();56    gl_Position = np1;57    EmitVertex();58    EndPrimitive();59}60 61void main()62{63 64#ifdef FACE_NORMALS65    GenerateFaceNormal();66#endif67 68#ifdef VERTEX_NORMALS69    GenerateVertNormal(0);70    GenerateVertNormal(1);71    GenerateVertNormal(2);72#endif73 74}75