Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using geometry shader to create new primitives types

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();
}
like image 618
Raven Avatar asked Oct 09 '22 22:10

Raven


1 Answers

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.

like image 114
Christian Rau Avatar answered Oct 13 '22 12:10

Christian Rau