开发者

using geometry shader to create new primitives types

开发者 https://www.devze.com 2023-04-06 14:41 出处:网络
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 no

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();
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号