Page 1 of 1

Multi Shader

PostPosted: Fri Jun 22, 2018 7:13 pm
by Juarez
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

Re: Multi Shader

PostPosted: Mon Jun 25, 2018 6:06 pm
by Ricardo Teixeira
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


Hello there!

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.

Be sure to let us know if you have any follow-up questions, we would be happy to elaborate!

Thanks!