# How do I discard a vertex in a vertex shader?

**URL:** <https://community.khronos.org/t/how-do-i-discard-a-vertex-in-a-vertex-shader/52040>\
**Category:** OpenGL\
**Tags:** glsl\
**Created:** [April 10, 2007, 4:46pm UTC](https://community.khronos.org/t/how-do-i-discard-a-vertex-in-a-vertex-shader/52040 "2007-04-10T16:46:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ewmailing](https://community.khronos.org/letter_avatar_proxy/v4/letter/e/f6c823/32.png) [@ewmailing](https://community.khronos.org/u/ewmailing)\
**Post date:** [April 10, 2007, 4:46pm UTC](https://community.khronos.org/t/how-do-i-discard-a-vertex-in-a-vertex-shader/52040/1 "2007-04-10T16:46:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oc2k1](https://community.khronos.org/user_avatar/community.khronos.org/oc2k1/32/97_2.png) [@oc2k1](https://community.khronos.org/u/oc2k1)\
**Post date:** [April 10, 2007, 5:01pm UTC](https://community.khronos.org/t/how-do-i-discard-a-vertex-in-a-vertex-shader/52040/2 "2007-04-10T17:01:00Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![dorbie](https://community.khronos.org/user_avatar/community.khronos.org/dorbie/32/53_2.png) [@dorbie](https://community.khronos.org/u/dorbie)\
**Post date:** [April 10, 2007, 11:42pm UTC](https://community.khronos.org/t/how-do-i-discard-a-vertex-in-a-vertex-shader/52040/3 "2007-04-10T23:42:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ewmailing](https://community.khronos.org/letter_avatar_proxy/v4/letter/e/f6c823/32.png) [@ewmailing](https://community.khronos.org/u/ewmailing)\
**Post date:** [April 11, 2007, 10:15am UTC](https://community.khronos.org/t/how-do-i-discard-a-vertex-in-a-vertex-shader/52040/4 "2007-04-11T10:15:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knackered](https://community.khronos.org/user_avatar/community.khronos.org/knackered/32/58_2.png) [@knackered](https://community.khronos.org/u/knackered)\
**Post date:** [April 12, 2007, 4:14am UTC](https://community.khronos.org/t/how-do-i-discard-a-vertex-in-a-vertex-shader/52040/5 "2007-04-12T04:14:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://community.khronos.org/uploads/default/original/2X/b/ba89cb49313a0e869198c8be354afde8bcae027e.png) [@system](https://community.khronos.org/u/system)\
**Post date:** [October 19, 2021, 7:38pm UTC](https://community.khronos.org/t/how-do-i-discard-a-vertex-in-a-vertex-shader/52040/6 "2021-10-19T19:38:57Z")

</div>

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