Texture mapping for performance


I'm trying my best to use best practise in my game and optimize where possible. A friend of mine was saying how I should use a 2048x2048 texture for my ENTIRE level, so that the engine only has to load one texture file.

I can understand that logic behind trying to cram as much as I can into a texture, but it's certainly a much harder way of working especially when I want to make as many reusable prefabs as possible.

I was wondering if this is actually good advice, is using more texture files (and subsequently more materials) in my scene going to hurt performance?

On a PC, you really do need to throw quite a lot of textures at it to hurt performance. However, you should always prototype fast, then optimise, optimise, optimise.

I have yet to build a PC App (I'm an iPhone guy, meh), but for iPhone I'll try squeeze as many things onto a single 1024x1024 texture as possible. Often, an entire level can be fit onto a single map, two at most.

Moral of the story is - Squeeze as much onto a single map as you can, but for the sake of ease, you can do it logically. Levels are a map, enemies are a single map, gui is all a single map, etc.

It's not worth making a texture atlas for the reason your friend is suggesting. If you're using the same shader, and shader settings, on multiple objects, it's often a good idea to make a texture atlas, because then all the objects can use the same material. With Unity iPhone, this will happen automatically with batching, and in other versions of Unity, you can use Mesh.CombineMeshes. (Batching may be a feature found in other versions of Unity in the future, but as of Unity 3 beta 5, it doesn't seem to be supported for the standalone or web platforms.)