Optimization: Number of shaders

Hey,
As mentioned in PlayCanvas’ optimization guidelines, reducing the number of shaders in use is one of several considerations with respect to performance. It also mentions that too many shaders can lead to “glitches in framerate”. I am currently working on a project where I suspect we have some performance issues related to this.

Anyone have any experience with what number of shaders is usually okay, and what is too much?
There is prob a big difference between what phones and computers can handle?

This post has more information about this: How did he get into the car when the progress bar reached 100% - #11 by yaustar

1 Like

Thx! That was rly helpful :slight_smile:

One question: The post talkes a bit about runtime performance related to having to compile new shaders on-the-fly, but do you know how much it impacts runtime performance otherwise? Say if you have a very static scene where no new shaders are introduced, will still say as many as 50 unique shaders, have a significant impact on FPS?

That depends on the work needed to be done by the shader per pixel. The more complicated the shader on a material, the more work has to be done per pixel that the material takes up on the screen.

The number of unique shaders shouldn’t be an issue after compiling. @mvaligursky or @Gustav_Sterbrant could explain more here.

1 Like

Think that answered my question actually, Thx again!

To get an idea of how many shaders are compiled, and what the cost is, you can enabled this at start-up:
pc.Tracing.set(pc.TRACEID_SHADER_COMPILE, true);

1 Like

ooo! interesting!
Is that different from what U get from using the profiler?

ok: so to answer my own question:
yes, it is. It basically console logs a lot of useful stuff about the individual compiled shaders

you can also trace TRACEID_SHADER_ALLOC - which is allocation of the shaders, but that might be less useful, unless you want to inspect the shaders.

2 Likes

Sweet! might come in handy :slight_smile:

and some more related to texture allocations and similar if you’re optimizing vram use as well