I am trying to figure out how to switch outputs in the geometry shader, specifically these two outputs:
layout(points, max_vertices = 1) out; // OUTPUT 1
layout(triangle_strip, max_vertices = 4) out; // OUTPUT 2
I am doing a rendering of starclusters and have a dataset of 100 000+ stars using sprites generated in the geometry shader. But, the sprite "halos" are to only appear if we move closer to the target star.
Geometry Shader
#version 440
const vec2 corners[4] = {
vec2(0.0, 1.0),
vec2(0.0, 0.0),
vec2(1.0, 1.0),
vec2(1.0, 0.0)
};
layout(points) in;
layout(points, max_vertices = 1) out;
//layout(triangle_strip, max_vertices = 4) out;
uniform vec4 campos;
float spriteSize = 0.000005; // set here for now.
out vec2 texCoord;
void main(){
float distToPoint = 1; //(1.f/((length(gl_in[0].gl_Position - campos)) ));
if(distToPoint == 1){ // dumb condition just to illustrate my point
// EMIT QUAD
for(int i=0; i<4; ++i){
vec4 pos = gl_in[0].gl_Position;
pos.xy += spriteSize *(corners[i] - vec2(0.5));
gl_Position = pos;
texCoord = corners[i];
EmitVertex();
}
EndPrimitive();
}else{
// EMIT POINT
gl_Position = gl_in[0].gl_Position;
EmitVertex();
EndPrimitive();
}
}
Fragment Shader
void main(void){
... // First I do a bunch of depth computation, irrelevant to this question
gl_FragDepth = depth;
// Here I want to switch between these two outputs!
//diffuse = texture2D(texture1, texCoord); // OUTPUT 1
diffuse = vec4(Color, 1.0); // OUTPUT 2
}
I have recently encountered streams for geometry shader but cant find a decent example of how this can be done in my instance.
Please let me know if more code needs to be posted.