layout(triangles, invocations=1) in; layout(triangle_strip, max_vertices=6) out; out vec4 fcolor; in vec4 fca[]; uniform mat4 mvp; uniform int sw; uniform float bulge; vec4 n4_test(vec4 x){ return vec4(normalize(x.xyz), 1); } void dt(vec4 a, vec4 b, vec4 c, vec4 ac, vec4 bc, vec4 cc){ gl_Position = mvp * n4_test(a); fcolor = ac; EmitVertex(); gl_Position = mvp * n4_test(b); fcolor = bc; EmitVertex(); gl_Position = mvp * n4_test(c); fcolor = cc; EmitVertex(); EndPrimitive(); } void main(){ vec3 av = gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz; vec3 bv = gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz; vec4 normal = vec4(normalize(cross(av,bv)), 0); vec4 a = gl_in[0].gl_Position; vec4 b = gl_in[1].gl_Position; vec4 c = gl_in[2].gl_Position; vec4 ac = fca[0]; vec4 bc = fca[1]; vec4 cc = fca[2]; // if(sw < 1){ // dt(a, b, c, ac, bc, cc); // return; // } float d_ab = distance(a, b); float d_bc = distance(b, c); float d_ca = distance(c, a); if(d_ab > d_bc && d_ab > d_ca){ vec4 hc = (a + b) / 2 - normal * bulge; vec4 hcol = (ac + bc) / 2; dt(a, hc, c, ac, hcol, cc); dt(hc, b, c, hcol, bc, cc); } else if(d_bc > d_ca){ vec4 hc = (b + c) / 2 - normal * bulge; vec4 hcol = (bc + cc) / 2; dt(a, b, hc, ac, bc, hcol); dt(a, hc, c, ac, hcol, cc); } else { vec4 hc = (c + a) / 2 - normal * bulge; vec4 hcol = (cc + ac) / 2; dt(a, b, hc, ac, bc, hcol); dt(hc, b, c, hcol, bc, cc); } }