Page 1 of 1

Shader variants

PostPosted: Wed Oct 10, 2018 3:26 pm
by wintomee
Hi.
I made a nice little custom lit sprite shader with quite a few options.
The default one is standard transparent and I created a duplicate for blending variants where I can customize types of Alpha Blend.

Now, I'd like to somehow merge these two, so that when I update the default shader, it reflects into the other shader.
The only way I can think of now is making the shader a function included in the other shader, but it feels more like a hack than a real solution.

I tried to find more about usage of subshaders in Amplify, but failed to find anything.
Is there a nice and clean solution?

Thanks

Re: Shader variants

PostPosted: Wed Oct 10, 2018 4:08 pm
by Amplify_Borba
Hello, thank you for getting in touch and for your support!

In this situation, you'll have to merge both variants into a single shader, and make use of Keywords through our Static Switch node in order to the generate of a number of Shader Variants, which are generated internally by Unity depending on the type of Keyword that you're using.

If you don't need to change the variant in runtime, set the Keyword Type to Shader Feature, as this way Unity will only generate the used variants and will only include in the build the active one, while in Multi Compile it generates all the variants and includes them all in the build,

Also, be mindful that the use of Keywords is limited to 256 in Unity, and about 60 are already being used internally.

Regarding having shared code between variants, using Shader Functions is the way to go.

Please let me know if this helps, thanks!