I'm working on a vertex shader in which I want to conditionally drop some vertices:
float visible = texture(VisibleTexture, index).x;
if (visible > threshold)
gl_Vertex.z = 9999; // send out of frustum
I know that branches kill performance when there's little commonality between neighboring data. In this case, every other vertex may get a different 'visible' value, which would be bad for the performance of the local shader core cluster (from my understanding).
To my question: Is a ternary operator better (irrespective of readability issues)?
float visible = texture(VisibleTexture, index).x;
gl_Vertex.z = (visible > threshold) ? 9999 : gl_Vertex.z;
If not, is converting it into a calculation worthwhile?
float visible = texture(VisibleTexture, index).x;
visible = sign(visible - threshold) * .5 + .5; // 1=visible, 0=invisible
gl_Vertex.z += 9999 * visible; // original value only for visible
Is there an even better way to drop vertices without relying on a Geometry shader?
Thanks in advance for any help!