Hello folks.
I’m experiencing some problems with dynamic batching. I’ve looked through the questions aswell as the forum pages but I can’t seem to find an answer to my specific problem so I’m turning to you guys.
I have three materials, a red and a green tinted texture and a solid black. The red and green ones are each copied into four shades of green and red respectively into a collection of materials at the start of the game, giving a total of nine materials.
Then I have a prefab (shadows disabled) which I instantiate and dynamically assign a cube-ish mesh. The mesh’s scale is basically randomized in x-, y- and z-axis and should a duplicate be found the previously created mesh of that scale is used. The object is then assigned a random material of the eight colored ones (the black isn’t used here).
This setup creates a number of unique combinations (of meshes and materials) in which copies are neatly batched giving sweet performance. Now to the actual problem, I wan’t to make these cubes black, and furthermore fade them to black. Simply assigning the black material (or any of the existing nine) to the cubes works well, the cube turns black and the batching works fine. But since I want to fade them to black I wrote a shader that does just that over a randomized period of time. This new “fading” material will obviously break the batching but as soon as the fading is over I set the material to the predefined black one but, as you might’ve guessed, the batching is permanently broken.
Does anyone of you have any experience in this area? Or a good explanation to why it won’t work? Any help, pointer or suggestion would be greatly appreciated.
Thanks for your time!