View Full Version : How do I discard a vertex in a vertex shader?

04-10-2007, 04:46 PM
How do I discard a vertex in a vertex shader? I read there is a 'discard' command in the fragment shader, but not the vertex shader.

I am drawing lines and am running a log() function on the points via a vertex shader. I need to throw away the point if the value is <= 0 since the log is not a number.


04-10-2007, 05:01 PM
It's not possible to discard a vertex in a vertexshader. That would be possible:

1. Calculate a valid position or default position

2. Set a varying float to 0 if the vertex is valid, and to 1.0 if it isn't valid. Drop all fragments with that varying float != 0.0

3. Use a geometryshader and drop the complete primitive (not recommend jet)

04-10-2007, 11:42 PM
You can also make the primitive degenerate, i.e. make two vertices the same coordinate post transformation, but that would require at least two vertices to be rejected or additional attributes per vertex an significant work to reject.

04-11-2007, 10:15 AM
Thanks for the replies. I suspected skipping a vertex wouldn't be easy. So I can't use a fragment shader because for lines, I seem to lose all the regular antialiasing, and thus it looks really bad.

Setting a default position sounds like my best option. I'm wondering though, how many decimal places out should I be able to go out in GLSL? (I'm not sure how to calculate what my minimum should be.)

Also, I am unclear on how to make the primitive degenerate. Is this something that can be done in a shader?


04-12-2007, 04:14 AM
you don't need to use a fragment shader, you can simply set the gl_FrontColor.a to 0.0 in the vertex shader and enable alpha testing.