I'm using a simple Geometry Shader in Processing:
shader(shader);
beginShape();
vertex(0.1, 0.1);
vertex(0.0, 0.0);
vertex(0.001, 0.02);
endShape();
So I'm applying a shader on a triangle.
We first have a simple Vertex shader that does nothing.
in vec4 position;
void main() {
gl_Position = position;
}
Then we have the Geometry Shader that should return a vertex for each input vertex, so 3 vertex in total.
#version 150
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
out FragData {
vec4 color;
} FragOut;
void main(){
for(int i=0; i<gl_in.length(); i++){
if(i%3==0){
FragOut.color = vec4(1., 0., 0., 1.);
}else if(i%3==1){
FragOut.color = vec4(0., 1., 0., 1.);
}else if(i%3==2){
FragOut.color = vec4(0., 0., 1., 1.);
}
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}
Finally we have a simple Fragment Shader that does nothing:
#version 150
in FragData {
vec4 color;
} FragIn;
out vec4 fragColor;
void main() {
fragColor = FragIn.color;
}
The result should be a triangle, with a different color for each vertex. But the result are four triangles and I don't know why.
noStroke();
before drawing the geoemetry. – Rabbid76