#version 400 #define USE_INSTANCING 1 const bool BYPASS_COLOR = false; // Set to true to ignore vertex colour input. layout(points) in; #if USE_INSTANCING const bool INSTANCED = true; layout(invocations = 3) in; layout(triangle_strip, max_vertices = 4) out; #else const bool INSTANCED = false; layout(triangle_strip, max_vertices = 12) out; #endif uniform vec3 campos; uniform mat4 Mproj, Mcam; in vec3 v_col[1]; out vec3 g_col; out vec3 g_wnorm; out vec3 g_wdpos; void ptemit(vec3 ppos) { gl_Position = Mproj * Mcam * vec4(ppos, 1.0); g_wdpos = ppos - campos; EmitVertex(); } void quademit(vec3 bpos, vec3 norm) { g_wnorm = norm; vec3 hnorm = norm/2.0; ptemit(bpos + hnorm - hnorm.yzx - hnorm.zxy); ptemit(bpos + hnorm + hnorm.yzx - hnorm.zxy); ptemit(bpos + hnorm - hnorm.yzx + hnorm.zxy); ptemit(bpos + hnorm + hnorm.yzx + hnorm.zxy); EndPrimitive(); } void main() { vec3 bpos = gl_in[0].gl_Position.xyz; vec3 bcol; if(BYPASS_COLOR) { bcol = vec3(1.0, 0.0, 1.0); } else { bcol = v_col[0]; } vec3 ppos; const vec3 nvx = vec3(1.0, 0.0, 0.0); const vec3 nvy = vec3(0.0, 1.0, 0.0); const vec3 nvz = vec3(0.0, 0.0, 1.0); g_col = bcol; if((!INSTANCED) || gl_InvocationID == 0) { quademit(bpos, bpos.x < campos.x ? nvx : -nvx); } if((!INSTANCED) || gl_InvocationID == 1) { quademit(bpos, bpos.y < campos.y ? nvy : -nvy); } if((!INSTANCED) || gl_InvocationID == 2) { quademit(bpos, bpos.z < campos.z ? nvz : -nvz); } }