Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a GLSL command similar to the discard, but it discards the whole mesh and not just a fragment?

share|improve this question
up vote 2 down vote accepted

I also think there is no way how to "discard" whole mesh, but you can transform every vertex of the mesh to the same output vertex, so whole mesh will "implode" into one point in space. If you place it behind camera, it will be clipped and not processed.

share|improve this answer
Indeed I considered making an edit to suggest that. However, you'd still have to tell the vertex shader which mesh it was processing at the time. Then assuming your trigger to "discard" the mesh is found somewhere along the way during vertex processing, it wouldn't transform the vertices that have already been processed, that's a problem. The counter assumption being that you know ahead of time which mesh is going to be discarded, then why even tell the vertex shader to process it just to transform it to a point? Since you know beforehand, you can just skip the drawing altogether. – Byte56 May 22 '12 at 15:26

Well, I'm pretty sure, the fragment shader doesn't have a concept of a mesh. I'm mostly sure the vertex shader doesn't either. You could update the vertex shader to let it know which mesh it's processing via a uniform variable, but I assume you want something all GPU side.

So I believe the answer is, no, it does not. However, I'd love to be wrong, I think that would be pretty useful.

share|improve this answer

No. Object culling (discarding a whole mesh) must be done before submitting your drawing commands to the GPU.

Remember that the shaders are running at various stages of the pipeline. The vertex shader is run after submitting objects to the GPU. And operates on the vertex level only - it has no cinder of any other vertices, primitives, or the rendered object at all.

The fragment shader runs on fragments only, and has no concept of other fragments, the primitive that created the fragment, the vertices that made the primitive, or the original object.

If you want to selectively disable a mesh based on some kind of GPU processing, you will need to do multiple passes. Things like occlusion queries can be used, or transform feedback.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.