Page 1 of 1

Performance of Static Switch vs. If

PostPosted: Wed Sep 05, 2018 3:45 pm
by JordyJS
I'm trying to optimize my shaders by making certain features toggleable, but I wanted to know which method was the most efficient? I've heard using conditional statements in shaders is generally frowned upon, so I thought I'd ask just to be sure.

Re: Performance of Static Switch vs. If

PostPosted: Wed Sep 05, 2018 4:09 pm
by Ricardo Teixeira
Greetings,

You should definitely go for Static Switches whenever possible as they are more performant than conditional statements that execute all functions before comparing their results.

For additional information on how Unity handles this type of behavior, be sure to check the link below.

https://docs.unity3d.com/Manual/SL-Mult ... iants.html

Thanks!

Re: Performance of Static Switch vs. If

PostPosted: Wed Sep 05, 2018 4:17 pm
by JordyJS
Ah, good to know! Thank you for the quick reply.

Re: Performance of Static Switch vs. If

PostPosted: Wed Sep 05, 2018 4:29 pm
by Ricardo Teixeira
JordyJS wrote:Ah, good to know! Thank you for the quick reply.


No problem!