Best way to effectively disard fragments

I’m looking for the best possible way to test the alpha value of a fragment, see if it greater than a certain value (specifically 0.5) and discard or mask it if it is

Obviously calling discard in the fragment shader is a bit slow for my tastes

Suggestions?

I cannot allow the depth buffer to be written to, and I need speed.

Obviously calling discard in the fragment shader is a bit slow for my tastes

Well, that’s the only way so that’s the way it has to be done.

I mean the depth test discards fragments

so you’re wrong

is there any other way?

[QUOTE=Geklmin;1291175]I’m looking for the best possible way to test the alpha value of a fragment, see if it greater than a certain value (specifically 0.5) and discard or mask it if it is

Obviously calling discard in the fragment shader is a bit slow for my tastes[/quote]

You could bench both alpha test (compatibility profile) and discard, though I’d expect similar performance from both.

Depending on your use case, you can limit the fill area to the absolute minimum to minimize the number of discarded fragments.

Or you can repack the pixels to be rasterized (i.e. with alphas greater than the alpha test threshold) with a compute shader. In other words, rather than distribute pixels to GPU threads spatially as typically occurs with region rasterization, you distribute them as needed based on your sparse workload. This kind of approach has been used for many years (8+) in similar cases to improve GPU efficiency processing sparse pixel data (e.g. with MSAA in Deferred where you want to limit where you take the hit of performing per-sample shading).

[QUOTE=Geklmin;1291178]I mean the depth test discards fragments

so you’re wrong

is there any other way?[/QUOTE]

You asked for a way to discard fragments “if it greater than a certain value (specifically 0.5)”. The only way to do that is with fragment shader logic.