I don’t know why material._count is added as a suffix to uniformId to form a new uniformId, this means that when my material.uniform has 5 uniforms, material._count will become 5 after createUniforms. Why is this?
From quickly skimming over the code, it is mainly used for disambiguation of uniform- and function names. So the answer to the question “Why is this?” is: Because when there are 3 materials, then thes corresponding unforms cannot all be called u_example, but have to be called u_example_0, u_example_1, and u_example_2.
But a broader and more important point is: The _count property is a private property. The value of this property should not be relevant for end-users.
Thanks for replying. I seem to understand a little bit. But I still have a question. When setting material.uniforms, the keys should be different, which means the variable names of uniforms in shader should also be different. According to fabric material specification, except for submaterial(combined material), I feel that a material can not be used twice when generating drawcommand, that is, the uniform variable name will not be repeated. I don’t know if my understanding is wrong.
If the combine material is used, and both sub materials have uniforms with the same name, then the count field of the parent material will be passed to the child material objects, so that the uniform variables with the same name will be distinguished based on the incremented count.
I have not studied that particular part of the code in all detail, but what you described is in line with my current understanding of the code. Specifically, the count variable is also used for disambiguation in the createSubMaterials function.