chr*_*ome 6 opengl geometry-shader
所以,我一直在尝试使用几何着色器从线条邻接原语中绘制一个圆柱体,它适用于4个顶点,但我想这样做,我可以将它应用于更长的线条.问题是,它在第四个顶点之后完全混乱.我知道原语让着色器访问邻接信息,但我不知道如何访问它,所以我的问题是:
我如何使用邻接信息?并且,是否可以使用相同的绘图调用为多个行执行此操作?
如果您能提供伪代码示例,我将非常感谢.
And*_*man 17
下图来自D3D10文档,但我觉得它比OpenGL规范中的图表更好地传达了原始拓扑.
您需要了解的是,当您使用原始类型w/Adjacency(例如 GL_LINE_STRIP_ADJACENCY
)时,您实际上必须在索引缓冲区中提供其他数据.
你看到图中的虚线了吗?这些都是多余的,你必须插入到索引缓冲区(或简称为额外的顶点,如果你不使用索引绘制命令)指数.
您将在线条的开头和结尾添加一个额外的索引,以提供相邻的顶点信息(在上图中表示为0和5).
0,9,36,4,52,1,8 (7 indices, 6 lines)
Lines produced:
<0,9>
<9,36>
<36,4>
<4,52>
<52,1>
<1,8>
Run Code Online (Sandbox Code Playgroud)
L-hand: 45
R-hand: 63
Run Code Online (Sandbox Code Playgroud)
[45],0,9,36,4,52,1,8,[63] (9 indices, **still** 6 lines)
+ Vertices [45] and 36 are adjacent to line <0,9> (first line)
+ Vertices 52 and [63] are adjacent to line <1,8> (last line)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,[X]
必须添加2个额外索引(使用表示),因为第一行和最后一行在它们之前或之后没有顶点.这些索引不会在条带中形成线条,它们只是用于填充邻接信息,否则它将不确定.
#version 330
// 4 vertices per-primitive -- 2 for the line (1,2) and 2 for adjacency (0,3)
layout (lines_adjacency) in;
// Standard fare for drawing lines
layout (line_strip, max_vertices = 2) out;
void main (void) {
// The two vertices adjacent to the line that you are currently processing
vec4 prev_vtx = gl_in [0].gl_Position;
vec4 next_vtx = gl_in [3].gl_Position;
gl_Position = gl_in [1].gl_Position; // First vertex in the line
EmitVertex ();
gl_Position = gl_in [2].gl_Position; // Second vertex in the line
EmitVertex ();
}
Run Code Online (Sandbox Code Playgroud)
几何着色器遵循OpenGL规范中给出的描述:
OpenGL 4.4核心配置文件规范 - 10.1.12带邻接的线路 - p.306
对于每个= 0,1,,从
i
+ 2 nd顶点到i
+ 3 rd顶点绘制线段...,- 1,其中传递了+ 3个顶点.如果顶点少于四个,则忽略所有顶点.对于线段,+ 1 st和+ 4 th顶点分别被认为与+ 2 nd和+ 3 rd顶点相邻(见图10.3)i
n
n
i
i
i
i
i