Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to access all vertices in a polygon in a vertex shader?

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?

like image 601
aardvarkk Avatar asked Nov 04 '22 07:11

aardvarkk


1 Answers

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.

like image 106
Christian Rau Avatar answered Nov 15 '22 00:11

Christian Rau