• Unity
  • Any way to individually tint without breaking batching?

  • Düzenlendi
Related Discussions
...

I'm working on optimization, and just realized that I had wrongly assumed that rendering skeletons with the same material but with Material Property Blocks (for tinting) would batch together. From using the Frame Debugger and googling, it seems that the purpose of MPBs is to prevent each individual renderer from having to create its own separate material, but they still can't be batched together.

Are there any tricks or special ways to tint skeleton renderers without breaking batching? We have a lot of spine animations for plants in our game, and our artist has been tinting them various levels of darkness to make them match the environment - I had set up a component for him to use that just applies an MPB.

Does tinting at the slot level break batching? If it doesn't, would it make any sense for us to instead apply the tinting to every slot in the skeleton instead of using the MPB? Or is that just a silly/inefficient thing to do?

Thanks for any help!!

Unfortunately your observations are correct, MaterialPropertyBlocks don't serve to reduce batching.

Jamez0r yazdı

Are there any tricks or special ways to tint skeleton renderers without breaking batching?
..
Does tinting at the slot level break batching? If it doesn't, would it make any sense for us to instead apply the tinting to every slot in the skeleton instead of using the MPB?

Tinting Attachments will not break batching, because it simply sets a different vertex color at the respective attachment, it does not change Material properties. Please note that you can also tint the complete skeleton like this:

Color color;
skeleton = this.GetComponent<SkeletonRenderer>().Skeleton;
skeleton.R = color.r;
skeleton.G = color.g;
skeleton.B = color.b;
skeleton.A = color.a;

So the above solution might be the best one for your scenario when tinting entire plant skeletons.


I have updated the spine-unity documentation pages and added a section about using Skeleton.RGBA for tinting to retain batching, hopefully this will help others in the future.
spine-unity Runtime Documentation: Changing Materials Per Instance

12 gün sonra

Thanks for the info Harald!

So on my quest for optimization, we're currently CPU bound. Would enabling the "Advanced - PMA Vertex Colors" affect CPU much? I guess that's similar to my question the other week about enabling the Add Normals / Solve Tangents options, lol. I'm just not sure exactly what's going on behind the scenes with these.

I suppose I could take the prefab of one of my plants and just put a couple hundred of them into an empty scene and see if there is a noticeable difference between having the PMA Vertex Colors option enabled or disabled :detective:

Profiling has been tricky because the normal profiler doesn't give you detailed information, but from what I'm reading the deep profiler can inflate the CPU time of functions that are called lots of times. I took a peek at the Solve Tangents function call in the deep profiler, and it was taking a "not insignificant" amount of CPU (can't remember the exact number, but I'll be looking at it again in the near future). But again, from what I'm reading, functions that are called thousands of times get inflated in the deep profiler - so figuring out what is actually going on, or what is worth trying to improve has been funky :zipper:

Jamez0r yazdı

Would enabling the "Advanced - PMA Vertex Colors" affect CPU much?

No, this basically adds just the rgb *= a multiplication operations per vertex, vertex colors have to be transmitted either way.

Jamez0r yazdı

Profiling has been tricky because the normal profiler doesn't give you detailed information, but from what I'm reading the deep profiler can inflate the CPU time of functions that are called lots of times.

Yes, deep profiling is not recommended here, as you said the instrumentations sometimes lead to distorted timing values. Normal profiling with- and without the respective codepaths enabled should provide more reliable data though.

If you are willing to take an extra step you could have a try using a thirdparty sampling profiler like Intel VTune:
https://www.youtube.com/watch?v=OvJqC9bRnPo
Sampling profilers should work very well in a situation where there are the same recurring functions being called every frame. Admittedly I haven't used VTune with Unity yet, just for other 3D application profiling. One downside is that it takes some time to process the collected samples, so be prepared to make yourself a tea after you hit the "stop" button 😉.

Awesome, will eek out a little extra batching with this setup! :detective:

Thanks Harald!

You're welcome! :nerd: