Within a fragment shader, I need some simple conditional evaluation - basically I'm checking the luminance of a pixel and want to perform an extra calculation if it is above some threshold value.
A simple example of the naive implementation would be:
if (lum >= threshold) {
col *= some_value;
}
However, this will (as far as I'm aware) cause a branch and destroy the built-in parallelism.
I have instead come up with the following:
col *= lerp(1.0, some_value, step(threshold, lum));
My question is: will the trade-off between arithmetic complexity (more instructions used) and removal of branching be worthwhile? Is this a viable (common?) strategy?