I have a shader which has a mix of transparent, partially transparent and opaque pixels. I was wondering if there was any point in explicitly calling discard, or if just setting ALPHA = 0 would be just as efficient?
if (blend <= 0.0)
discard;
ALPHA = blend;
I’m assuming whatever is executing the shader will be able to determine there is no need to write a fragment when ALPHA == 0 and discard the fragment automatically, but then maybe I’m assuming too much.
Best to profile your typical use case on the target hardware. discard can improve performance by skipping the pixel write but it can also worsen it because its presence in the code disables the early depth test on most hardware, even if it’s never executed. It can be a double edged sword. Performance may suffer more on mobile. You also introduce per pixel branching which is not ideal.