>>1009792>what is the deal with 'alphatest' being so seemingly cheap in shadersIt's not! It's a perf hit although for different reasons than the ones involved in ray tracing. This is because rasterizers can use a series of optimizations grouped under the appellation of early-Z. basically checks you can do before running the pixel shader.
For example, if you render a triangle with no alpha test, you can write depth as soon as you've run the vertex shader, so the next triangle can be depth tested against depth in parallel with the pixel shader for the current triangle being run. But if you need alpha test, then the pixle shader must be run before the next triangle can be tested.
That's not the only one, another common one is dividing the screen into tiles, and as long as a tile is entirely covered by a triangle instead of writing each pixel you just write the plane parameters (4 numbers) for the whole tile and do further depth tests against that, saving tons of bandwidth (for an 8x8 tile it'd be 16 times less bandwidth for example).
As a consequence games usually render all the alpha tested stuff after all the opaque stuff to speed things up. Another optimization is to render only depth at first, so you can run a pxiel shader that only does the strict minimum for an alpha test, then a second pass of the whole scene where you don't write depth but instead test for equality, so you only have to run the part of the shader that writes color and part of the early Z stuff can run in parallel because the depth buffer's static. Like, yeah, if you pixel shader's complex enough, rendering the whole scene twice to take better advantage of early Z is faster (don't mistake it for deferred rendering, this is a different trick that can be used with or without it).
So basically it isn't cheap at all and a bunch of tricks are used to reduce its impact.