Performance of Static Switch vs. If

Node-based Shader Editor
Post Reply
JordyJS
Posts: 4
Joined: Wed Sep 05, 2018 3:42 pm

Performance of Static Switch vs. If

Post 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.
User avatar
Ricardo Teixeira
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Performance of Static Switch vs. If

Post 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!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
JordyJS
Posts: 4
Joined: Wed Sep 05, 2018 3:42 pm

Re: Performance of Static Switch vs. If

Post by JordyJS »

Ah, good to know! Thank you for the quick reply.
User avatar
Ricardo Teixeira
Posts: 954
Joined: Fri Aug 09, 2013 2:26 pm

Re: Performance of Static Switch vs. If

Post by Ricardo Teixeira »

JordyJS wrote:Ah, good to know! Thank you for the quick reply.
No problem!
Sales & Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Post Reply