What is the "material switches" stat?


#1

What are the material switches in the stats? I noticed I have a lot of them. How can I reduce this? ty


#2

Hi Djehan

THis counter is not very much representative of what it says, it s pretty old
it is counting the number of time we change the material during the rendering of a frame

IN practice for every shape of a FBX model (meaning every sub mesh) we are assigning a different geometry/material/transform to draw that geometry part at the correct place in the 3d scene, with the correct material

So as of now, this counter is pretty much equivalent to ~numbers of parts in view)
I wouldn;t worry too much about that coutner.

Under the hood a Material describes 2 things:

  • its behavior and a pipeline of shaders associated to render that material
  • its unique set of values and textures which feeds into the shader pipeline

WE want to minimize as much as possible the different pipeline changes needed to render a frame and so minimize the “pipeline switches” because changing that object is costly
the next priority is to minimize changing the values & textures feeding this pipelie

In a scene with several shapes using different materials A, B & C, the shapes don;t have a particular order for rednering at the start. You end up with a random sequence of material used (for example BBBAACACBCBCBAACB…)
Materials A & B can be sharing the SAME pipeline but have different values
And Material C can be different both in pipeline and values than A and B.
To render efficiently these shapes we would try to sort them in the following order:
All shapes using A
Then all shapes using B
Then all shapes using C
Because that sorting minimize the changes of pipelines and of values we need to apply while rendering these shapes.

THere is a metric visible in the script “renderStats.js” that represent that “State CHanges/ Pipeline” which is something i look at to chek that our materiall sorting is helping.

Let me know if you have more question,
Cheers
S


#3

Hello Sam,

I had over 5K switches while testing a large test build which consisted into c/v the same low poly mesh (approx. x8 y5 x10 & a dozen textures) about 500 time resulting in a bigger hollow object with dimensions of approx. x100 y1000 z100.
I will keep the stats opened while testing large environments to try to optimize my work accordingly and esp. try to see which stats are vital VS less important ones.
Thank you for your reply!
d