This should really be in a more general category, but there isn’t a more appropriate one in existence, and since I’m mainly making iOS games I put it here.
I did quite a bit of reading on these forums to uncover the mysteries behind dynamic batching. I finally decided to give it a try to see if I could get just a little more perf out of Belt Runner. I opened an old, finished game, Bubble Time, and saw that my bubbles were all getting batched. I thought, “This is supposed to be impossible,” seeing as how every one was a different scale. I puttered around with my asteroids, and cubes, and even the same bubble prefabs for hours until it hit me: The bubbles were not 100% uniform!
The bubble prefabs were being scaled in the x and y, but not the z. Each time I changed the z to match the x and y, however, that instance was removed from the batch and placed into a new draw call. I played with the numbers a little more until I finally found the tolerance level. I then applied the same theory to Belt Runner and I am now averaging 15 draw calls with batching instead of 24 draw calls without, which gained me an average of about 5fps on the iPhone 1G.
So the part that you all care about: You can scale instances of prefabs to any size and still have them batch as long as one axis is 0.0001 less than the other two. Yes, you read that right, 0.0001. In my size randomizing method I just did:
t.gameObject.transform.localScale = new Vector3(n, n, n - 0.01f);
Voila, mission accomplished! Hope this helps someone looking to get that last bit of performance out of their game.
What you say makes sense, because when you scale non-uniformly, vertex attributes and matrices are recalculated with scale in mind; in the case of uniform scaling, they’re not, and unity_Scale.w is used to account for it. As long as unity_Scale isn’t coming into play, then dynamic batching can work. But all that stuff is done on the CPU too, just like draw calls and batching, so whether it’s worth doing probably has to do with how many vertices and attributes you’re dealing with.
How many bubbles? What kind of results are you getting on a device that anyone actually uses these days?
You say 0.0001 then post code for -0.01. Which is true?
Also this is incredibly daft. Dynamic batching should just work, not be stupidly undocumented with weird-ass quirks like this. It is utterely foolish engine design.
@Jessy, in Bubble Time I’m pushing 20 bubbles in 1 draw call (with DB). They’re just alpha textures on a square plane, just two polys each. The performance increase in that app was huge. In Belt Runner I’m moving 18 asteroids with 180 polys each. The increase was 7-11fps on the iPod Touch 2G and 5-6 on the iPhone 1G. I didn’t even bother testing on the iPod Touch 4G because it was already smooth as silk before the tweak. The numbers aren’t that much, but the difference means that my game is now super smooth on the 2G Touch, and fully playable (as opposed to a little choppy) on the 1G iPhone.
@Hippo, it’s 0.0001. I just didn’t like the look of my code with such a ridiculous number, and the visual difference is imperceptible at that scale beyond two decimal places. Plus I’m pretty anal about performance and I didn’t want to have to account for the extra decimal places of float precision. Yeah, I know. Like I said, I’m anal.
I have to agree with your comments on DB in general. That’s some retarded ass shite, dude. It’s a great feature when it works, but to have to jump through so many hoops to get it working is just plain wrong. I don’t know what genius coded that 0.0001 requirement in there, but I hope someone TP’s his house…
P.S: @Jessy, you’d probably be surprised how many people I know (in the tech industry no less) who are still using an iPhone 1G or iPod Touch 2G. I take the train to work (in Silicon Valley) and the most common iOS device I see is still the iPhone 3G.
Well, I suppose they could be crazy and just talking to themselves on their iPod, but what do I know.
Also, I’m including people I know and/or work with in that observation. I only know/work with a handful of people who have an iPhone 4G. Everyone else either still uses their 3G or switched to an Android. Tech nerds are a fickle bunch…
Unity tech of course they do read these forums. Part of being a verbose forum goer I like to have my facts right so I can help others. Thats why I would like clarification from someone who works at unity…
Sure you don’t have them as child to another transform rotate stuff which forces the child scale to be recalculated leading to an error in that range potentially as thats in the range of the maximum precision of the first 2 generations of iOS devices as ARMV6 devices calculate “floats” in 16bit precision, not 32bit?
Uh, Dreamora, what are you talking about? Did you reply to the wrong thread?
There’s not a problem per se. I was just letting the community know that I figured out that, contrary to popular belief, dynamic batching does work on objects of different scale. That is, as long as one axis is 0.0001 less than the other two.
I think iPhone 3G users are not active iPhone app users. People who care about using iPhone as a real smart phone will switch to newer devices. That’s only my opinion though. I will never include armv6 support for my unity ios games again. (that saves me tons of build size as well.)
And it’s a wrong one. If you want to fly out to the bay area, take a ride on BART or CalTrain and observe. I only saw two 4G’s today, but I saw a ton of 3G’s. Most of them were playing games. Long train ride == boring…
Yeah, they could be 3GS’s. I just lump them in the same bin as they’re not the 1G or the 4G. My point was just that not everyone and their kid brother is upgrading to the 4G.
It’s funny how a rather pertinent discussion about dynamic batching manages to devolve into an argument on user preference to phone popularity. Why don’t we just stay on topic and take everything else to the gossip forum.
The iPhone 4 isn’t an upgrade, as far a gaming is concerned. The GPU can’t handle the retina display.
I think my first response was clear enough on this. It’s possible that the speed increase of uniform scaling is outweighed by the ability to batch, in all cases, and Unity simply hasn’t accounted for that, since batching came around. But I bet not, and I’m interested to hear what happens with better hardware.
@Jessy, I doubled the number of polys (and therefor bubbles) in Bubble Time after I got dynamic batching working and it still runs faster than 50% bubbles without batching on my iPhone 1G, iPod Touch 2G, and iPod Touch 4G.
@Hippo, was that a reference to Aliens? Mostly? So hey, how long do you think it’ll take a rep fro Unity Technology to give us some feedback on my findings?