How do I discard a vertex in a vertex shader?

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.

Thanks

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)

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.

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?

Thanks

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.