gpt4 book ai didi

opengl - 在几何着色器中使用线条邻接

转载 作者:行者123 更新时间:2023-12-04 13:13:27 24 4
gpt4 key购买 nike

所以,我一直在尝试使用几何着色器从线带邻接基元中绘制一个圆柱体,它适用于 4 个顶点,但我想制作它以便我可以将它应用于更长的线带。问题是,它在第​​四个顶点之后完全搞砸了。我知道原语使着色器可以访问邻接信息,但我不确定如何访问它,所以我的问题是:

如何使用邻接信息?并且,是否可以使用相同的绘图调用对多条线执行此操作?

如果您能提供伪代码示例,我将不胜感激。

最佳答案

下图来自D3D10 documentation ,但我觉得它比 OpenGL 规范中的图表更好地传达了原始拓扑。

http://i.msdn.microsoft.com/dynimg/IC520307.png

您需要了解的是,当您使用带有邻接关系的原始类型(例如 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>

并且您已经确定了以下端邻接:

L-hand: 45
R-hand: 63

您的带邻接的线条将被编入索引:

[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)

如您所见,必须添加 2 个额外的索引(使用 [X] 表示),因为第一行和最后一行在它们之前或之后将没有顶点。那些指数 不要在 strip 中形成线条,它们只是在那里填写相邻信息,否则它会是未定义的。

在几何着色器中访问相邻顶点的伪代码:

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

几何着色器遵循 OpenGL 规范中给出的描述:

OpenGL 4.4 Core Profile Specification  -  10.1.12 Line Strips with Adjacency  -  p. 306

A line segment is drawn from the i + 2nd vertex to the i + 3rd vertex for each i = 0, 1, . . . , n − 1, where there are n + 3 vertices passed. If there are fewer than four vertices, all vertices are ignored. For line segment i, the i + 1st and i + 4th vertex are considered adjacent to the i + 2nd and i + 3rd vertices, respectively (see figure 10.3)

关于opengl - 在几何着色器中使用线条邻接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27467810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com