- Home /
Texture Atlasing Performance
I've been wondering for some time now how to do this properly. For example; lets say i have a city with lots of cars, people, animals, etc. By the way i'm talking about a 3D game here.
I understand the fact that one object should not have multiple textures if you want it to be only one drawcall. And therefor you make a texture atlas with the different parts of; for example a car.
To my question: Would it be better to combine multiple different cars on one atlas? Even if there is a big chance not all of those will be seen at the same time.
If the answer is YES, where should you stop? Should i combine as much as possible on as few atlases as possible? Like: "Cats, Dogs, Jeeps, Blond Girls" on one atlas?
If this is the way to go, how big should the atlases ideally be?
I would be happy with any answers. Thx!
Answer by Hanoble · Sep 13, 2016 at 04:13 AM
Using texture atlases is done to reduce draw calls, which is a GPU and typically FPS optimization. However, when you atlas textures it requires a larger texture to be used, which eats up more memory.
The question you ask of how far you take the atlasing, really comes down to your game and your performance. If you are on mobile and GPU bound because you have 1k draw calls, atlasing those objects in the scene can be the difference between 5 and 60 FPS.
When you atlas textures, you typically atlas the ones that will be on the screen together, as this is where you get your GPU optimization. Putting multiple smaller textures into a single large texture, when they will never be on the screen to batch at the same time, means all you have done is create a larger texture memory footprint. Which is why it is also important to remember the difference in size between textures, such as a 1024 and 2048, where the size difference is actually 4x (2x in each dimension) and not the common misconception of 2x larger.
The texture atlas size can vary depending on scene construction and what you can even atlas together, but it is important to remember that most platforms have some texture limitations. For example, the iPhone 4 allows a max texture of 2048, so you may need to adjust for this on specific platforms.
It would also probably be a good idea to take a look at both dynamic and static batching, if that is something you have not done. It may be enough for you without having to worry about extra atlasing. There are also assets available on the asset store than can help you with this, with Mesh Baker being a personal favorite of mine.
All of this can sound like a real PITA, but trust me it works. I worked on a game that had a top down view of a city, in which the player could manipulate the camera and see the majority of the city at any one point and time. It was set up of individual assets by a designer and was nearly 10k draw calls. With proper atlasing and batching, we were able to drop that below 50 and enjoyed a smooth mobile launch.
Thanks for a great answer! Out of interest, the city game you worked on: Could the player place and destroy buildings? Or was it all static?
I'm thinking mesh baking might not work "outside the individual building" When doing a city building type game. But your talking about "proper atlasing and batching" and i might be missing the point.
If you would want to elaborate a little bit on how you achieved this amazing draw call reduction i would be happy : )
I know i should not worry about optimization yet. But its just so hard, i don't want to waste time doing things the wrong way.
Thanks again!
In the city game the entire scene was static outside of the player and a handful of enemies on the screen at any point. We baked the entire city as a single mesh using $$anonymous$$esh Baker, which also handled the atlasing for us (we ended up using multiple atlases due to texture size limitations). For the enemies, we ensured they were under the vert limit for dynamic batching and atlased enemies that were known to be together as best as we could. With just those optimizations we were fine on the GPU side.
There really is no "one size fits all" solution to optimization. Each game has it's own requirements that make some optimization techniques much more effective than others. In a game with a lot of dynamic objects that you want to batch, keep the vert limit under the batching limits and use batching friendly shaders. Lighting is also a major game changer on lower platforms, and breaks batching entirely in most cases (light probes are a much cheaper alternative).
As far as spending too much time optimizing or worrying about it, that really comes down to what you are getting out of your project. If this is a hobby project or learning experience, go ahead and optimize to your heart's content. Time spent on knowledge today is time saved tomorrow. I spent countless hours optimizing my own hobby projects to levels I probably never should have, but when I had to apply those same techniques in the workplace, having the ability to do so was well worth it.
Answer by daleran · Sep 13, 2016 at 04:28 AM
Another tip, don't try to reduce draw calls or worry about optimizations until you have to. There is a principle in programming where you don't try to optimize prematurely. First, implement your solution as simply as you can, and if the performance is unacceptable, then work on optimizing by reducing draw calls, memory footprint, etc. Otherwise, you may spend many hours optimizing something that actually doesn't have any negligible impact on performance either way.
I would agree with this on almost any platform, with the big exception being VR (especially considering mobile VR). If you wait too long on VR to at least become aware of your performance issues, you may very well find out you are wasting your time doing something that is simply not feasible with current device limitations.
Outside of VR though, there is certainly a lot of premature and unneeded optimizations wreaking havoc on developer's work schedules. :)
@Hanoble That is good to know. I've never worked with VR. I'll keep that in $$anonymous$$d if I ever do.
Answer by SorenaCoder · Sep 13, 2016 at 02:51 PM
In most android devices(if your target platform is android) you can't use more than 2048 texture size. so if you combine textures too much, that will reduce the quality. (you can combine 4 1024x1024 textures in one 2048x2048 textures, but if you combine more, you have to use 4096x4096 texture to maintain quality)