Jump to content
  • Advertisement
Sign in to follow this  
Martin Perry

DX11 [DX11] Weird shader behavior with branching

This topic is 2280 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
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 huh.png . I tried compilation with NO and FULL optimalization, result is same

Share this post


Link to post
Share on other sites
Advertisement
val = tmp * X1
val = !tmp * X2[/quote]The top line isn't used; it's overwritten by the bottom line.

Also, instead of "[font=courier new,courier,monospace]!x[/font]", use "[font=courier new,courier,monospace]1-x[/font]", if [font=courier new,courier,monospace]x[/font] is float.

Simplest version is probably:
[font=courier new,courier,monospace]val = lerp( X2, X1, tmp );[/font]
[edit] or
[font=courier new,courier,monospace]val = !temp*X2 + temp*X1;[/font]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!