DX11 - Weird shader behavior with and without branching

Posted by Martin Perry on Game Development See other posts from Game Development or by Martin Perry
Published on 2012-04-23T08:56:05Z Indexed on 2012/06/26 21:26 UTC
Read the original article Hit count: 275

Filed under:
|
|

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

© Game Development or respective owner

Related posts about hlsl

Related posts about directx11