☑ Will two materials with same setup but different texture generate 2 shaders during runtime?

Hi,
Supposedly I have two materials with exactly same settings, but Material A has out_ao.jpg as AO map and Material B has inner_ao.jpg as AO map. Will the engine generate 2 different shaders during run time?

1 Like

Hi @cicerolee.

Good question, and no - it will reuse shader as semantically it will be the same. We have caching in place to avoid to many shaders being compiled as it is expensive thing to do in WebGL.
Textures - are only uniforms. But remember that missing texture - is treated as not defined texture, so that affects the setup and excludes code related to that missing texture.

The easiest way to test it: create new project, upload 2 textures, create material set it with one texture, duplicate it and set another texture. Then drop those materials each on own model.
Then run Launch with Profile from Editor, or add ?profile=true to launch url. You will see on bottom left panel number of shaders compiled and used. You can then modify material so that it will generate new shader, refresh and see number increment.
Remember there are number of engine shaders that are situational and will be there additionally.