Hi All,
I have geometry shader which receives data from vertex shader and to draw mesh in triangle.
It would be good if I can draw points at the same.
Can you please let me know how I can achieve my goal?
Do I need to use two different programs?
#shader geometry
#version 430 core
/* Information passed from the vertex shader */
in DATA {
vec4 glPosition;
} gs_in[];
/* Information passed to the fragment shader */
out DATA {
vec4 glPosition;
} gs_out;
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
void main() {
vec2 p0 = gs_in[0].glPosition.xy / gs_in[0].glPosition.w;
vec2 p1 = gs_in[1].glPosition.xy / gs_in[1].glPosition.w;
vec2 p2 = gs_in[2].glPosition.xy / gs_in[2].glPosition.w;
vec2 v0 = p2 - p1;
vec2 v1 = p2 - p0;
vec2 v2 = p1 - p0;
float area = abs(v1.x * v2.y - v1.y * v2.x);
for (int i = 0; i < 3; i++) {
if (i == 0)
gs_out.distance = vec3(area / length(v0), 0, 0);
else if (i == 1)
gs_out.distance = vec3(0, area / length(v1), 0);
else if (i == 2)
gs_out.distance = vec3(0, 0, area / length(v2));
EmitVertex();
}
EndPrimitive();
}