Avoid if statements in DirectX 10 shaders?
- by PolGraphic
I have heard that if statements should be avoid in shaders, because both parts of the statements will be execute, and than the wrong will be dropped (which harms the performance).
It's still a problem in DirectX 10? Somebody told me, that in it only the right branch will be execute.
For the illustration I have the code:
float y1 = 5; float y2 = 6; float b1 = 2; float b2 = 3;
if(x>0.5){
x = 10 * y1 + b1;
}else{
x = 10 * y2 + b2;
}
Is there an other way to make it faster?
If so, how do it?
Both branches looks similar, the only difference is the values of "constants" (y1, y2, b1, b2 are the same for all pixels in Pixel Shader).