warunapww
warunapww

Reputation: 1006

Access primitive id/index a vertex belongs inside glsl:vertex-shader

I'm drawing set of polygons using glMultiDrawArray command. I want to color each polygon with a different color. If I can access the primitive index (or the polygon) a vertex belongs to inside vertex shader, I can look color up from an array and set the color.

So my question is: Is it possible to access primitive index within a (vertex) shader?

What are the other alternatives to color each polygon using a different color?

Upvotes: 1

Views: 1660

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473407

Vertex shaders operate on vertices, not primitives (hence the name ;) ). As such, they have no access to any per-primitive data. Now, if each vertex is associated with exactly one primitive, then vertex operations are effectively per-primitive. But this will generally require replicating lots of per-vertex information, since most meshes will share vertices across multiple primitives.

Geometry shaders operate per-primitive, so it is entirely possible for them to be used for this. However, the best way to perform per-primitive operations will depend on exactly when and how you intend to do this.

Upvotes: 2

Related Questions