是否可以在顶点着色器中访问多边形中的所有顶点?

发布于 2024-12-27 19:55:55 字数 358 浏览 4 评论 0原文

我正在尝试在 Unity 中创建线框顶点/片段着色器。根据本文,这似乎是可能的。一般的想法似乎是,将顶点着色器中计算的距离向量传递给片段着色器中的每个片段,它可以使用它来根据线框线在多边形内的位置确定绘制线框线的亮度。

不过,从我读过的其他内容来看,您似乎只能访问顶点着色器中的单个顶点。我需要访问 ecah 顶点的多边形中的所有相邻顶点。该论文似乎暗示几何着色器不是必需的,这很好,因为 Unity 还不支持它们。

我缺少什么?是否永远不可能在顶点着色器中访问相邻顶点?如果没有几何着色器,我想要做的事情是不可能的吗?

I'm trying to create a wireframe vertex/fragment shader in Unity. It seems possible according to this paper. The general ideas seems to be that you pass a distance vector calculated in the vertex shader to each fragment in the fragment shader, which it can use to determine what brightness to draw the wireframe line at based on its position within a polygon.

From everything else I've read, though, it appears that you only get access to a single vertex in a vertex shader. I would need access to all of the neighbouring vertices in a polygon for ecah vertex. The paper seems to imply that a geometry shader is not necessary, which is good because Unity doesn't support them yet.

What am I missing? Is it never possible to access neighbouring vertices in a vertex shader? Is what I'm trying to do impossible without geometry shaders?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2025-01-03 19:55:55

你似乎确实已经读完了 2.1 中的段落:

步骤G1通常总是在顶点着色器中执行。步骤G2
应该在几何着色器中执行,因为几何着色器
可以访问多边形的所有顶点(前提是它是三角形)。
因此,如果不使用几何着色器,则使用顶点着色器
需要接收其他顶点作为属性才能计算
距离。这意味着应用程序代码不是不变的
是否使用线框方法,需要额外的数据
被传输,最后,索引原语的使用是
排除,因为顶点的属性取决于哪个三角形
绘制。

因此,当不使用几何着色器时,您确实不知道三角形的其他顶点,因此必须将它们作为附加顶点属性进行传输。因此,对于三角形的每个顶点,您都会获得两个额外的 vec3 属性,其中包含该三角形的其他两个顶点的位置。当然,就像文本所说,您不能使用索引绘图,因为这两个属性不仅取决于顶点位置,还取决于该顶点所属的三角形。

You seem to indeed have over-read the paragraph in 2.1 that says

Step G1 is generally always performed in the vertex shader. Step G2
should be performed in the geometry shader since the geometry shader
has access to all vertices of the polygon (provided it is a triangle).
Consequently, if the geometry shader is not used, the vertex shader
needs to receive the other vertices as attributes in order to compute
the distances. This entails that the application code is not invariant
to whether the wireframe method is used, that additional data needs to
be transmitted, and, finally, that the use of indexed primitives is
precluded since the attributes of a vertex depend on which triangle is
drawn.

So when not using the geometry shader you indeed don't know the other vertices of a triangle and therefore have to transmit them as additional vertex attributes. So for each vertex of a triangle you got two additional vec3 attributes containing the positions of the other two vertices of this triangle. And of course, like the text says, you cannot use indexed drawing, since those two attributes don't only depend on the vertex position, but also on the triangle this vertex belongs to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文