Abhishek Bansal
Abhishek Bansal

Reputation: 5335

Prune Primitives using Geometry Shaders in OpenGL

I have a large 2D Triangle(not Triangle Strip) mesh with about 2+ million polygons. Many of these polygons are redundant which can be determined using one of the attribute variables in vertex shader. But since discarding a vertex in vertex shader is not possible. I am exploring the idea of discarding primitives in Geometry shader as an optimization. It is guaranteed that all three vertices of this primitive will have same attribute value.

I have a few doubts here

  1. Will this really optimize rendering in terms of speed and GPU memory?
  2. Is this even possible in geometry shader and are geometry shaders are suitable for this?

Upvotes: 3

Views: 706

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473232

But since discarding a vertex in vertex shader is not possible.

Nonsense. Oh sure, the VS cannot "discard" a triangle, but that doesn't mean it has no power.

Triangles which appear wholly off-screen will generally get minimal processing done on them. So at a minimum, you can have the VS adjust the final gl_Position value to be off screen based on whether the attribute in question has the property you are looking for.

If you have access to OpenGL 4.6, you can get even fancier by employing cull planes, which allow the VS to cull triangles more directly.

Will this really optimize rendering in terms of speed and GPU memory?

Broadly speaking, you should never assume Geometry Shaders will increase the performance of any algorithm you apply it to. There may be cases where a GS could be used in optimizing an algorithm, but absent actual performance data, you should start from the assumption that employing it will only make performance worse.

Upvotes: 3

Related Questions