DX11 - Weird shader behavior with and without branching
- by Martin Perry
I have found problem in my shader code, which I dont´t know how to solve.
I want to rewrite this code without "ifs"
tmp = evaluate and result is 0 or 1 (nothing else)
if (tmp == 1) val = X1;
if (tmp == 0) val = X2;
I rewite it this way, but this piece of code doesn ´t word correctly
tmp = evaluate and result is 0 or 1 (nothing else)
val = tmp * X1
val = !tmp * X2
However if I change it to:
tmp = evaluate and result is 0 or 1 (nothing else)
val = tmp * X1
if (!tmp) val = !tmp * X2
It works fine... but it is useless because of "if", which need to be eliminated
I honestly don´t understand it Posted Image . I tried compilation with NO and FULL optimalization, result is same