Hello. I have a question about the switch between shaders at runtime.
In my game, I have some enemies with only one material. Sometimes I need to change the shader of the material to highlight or to disintegrate the enemy for example. The idea is to make one shader that contains all the possible effects in the game and defines the output with a switch. In terms of optimization, do you think that is a good idea?
Is it better to have that huge shader with all possibilities, is it better to keep all the effects separated like one per material and change the whole material when needed, or it does not make so much difference? One of the main concerns I have about putting everything in the same shader and just switching between them, is that I don't know if the inactive shaders will be still doing calculus, thus being very expensive to put all of them together
Multi Shader
- Ricardo Teixeira
- Posts: 954
- Joined: Fri Aug 09, 2013 2:26 pm
Re: Multi Shader
Hello there!Juarez wrote:Hello. I have a question about the switch between shaders at runtime.
In my game, I have some enemies with only one material. Sometimes I need to change the shader of the material to highlight or to disintegrate the enemy for example. The idea is to make one shader that contains all the possible effects in the game and defines the output with a switch. In terms of optimization, do you think that is a good idea?
Is it better to have that huge shader with all possibilities, is it better to keep all the effects separated like one per material and change the whole material when needed, or it does not make so much difference? One of the main concerns I have about putting everything in the same shader and just switching between them, is that I don't know if the inactive shaders will be still doing calculus, thus being very expensive to put all of them together
I got back to you via email but I'll post my reply here for other users, it might be useful.
I'm afraid that it always depends on the actual complexity of the shaders used, and how it's implemented.
You have a couple of nodes at your disposal that might be useful:
- The Toggle Switch Node allows you to toggle specific node networks but both inputs are simultaneously processed, you can think of it as a standard Lerp Node.
- Unlike the previous, the Static Switch Node offers you an alternative way to control what is calculated/used.
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!
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!