Supposing I need this function in a shader:
if (y < 1) return x/y;
else
{
if (x < 0.5) return x;
else if (x < y -0.5) return 0.5;
else return x - y + 1;
}
This can be achieved without if
branches, like:
return
(x/y) +
max(0,y-1)/(y-1) *
(
2 * (max(y - 0.5, x)-(y - 1)) * min(0.5, x)
-(x/y)
);
Is this the second function really worth the trade?
Regarding performance. That seems a lot computation.
But they say if
branching is no-go for fixed pipeline GPUs.
I would not ask if the second function would not involve computations that many.