5

Is it possible to output new primitive type from geometry shader other than was input? I'd like to input a point and render a triangle. The point would be used just as center for this triangle. If not, is there other option to input just point and render some other piece of geometry defined by that point?

With the help from answer here is geometry shader doing just what I asked for (if anyone ever needed):

#version 120
#extension GL_EXT_geometry_shader4 : enable

layout(points) in;
layout(triangle_strip) out;

void main()
{   
    gl_Position = gl_in[0].gl_Position;
    EmitVertex();
    gl_Position = gl_in[0].gl_Position+vec4(1,0,0,0);
    EmitVertex();
    gl_Position = gl_in[0].gl_Position+vec4(0, 1, 0, 0);
    EmitVertex();
    EndPrimitive();
}

1 Answer 1

4

Yes, this is perfectly possible, that's what the geometry shader is there for. Just specify the input primitive type as point and the output primitive type as triangle (or rather triangle strip, no matter if it's only a single triangle) using either glProgramParameteri in the application or using the more modern layout syntax directly in the shader.

Sign up to request clarification or add additional context in comments.

2 Comments

Note that you don't really get a choice of syntax. Or rather, your choice of syntax is based on whether you are using the extension version of geometry shaders or the core functionality. Don't try to mix the two.
@Nicol I actually haven't worked with geometry shaders, yet. Thanks for the clarification.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.