ParticleSystem and Atlas texture
These are familiar concepts to Game developers.
ParticleSystem
A familiar feature, available in most of GameEngine nowaday, which is used to create a variety of effects in the games (fire, explodsion, smoke, falling leaves, snow ….).
Atlas textures
We often pack all small textures into one big texture (call Atlas), to reduce drawcall, save a lot of game performance.
We are also familiar with SpritePacker in Unity – a tool for packing sprites in to one atlas. Currently, this tool support only Sprite2D.
Why ParticleSystem cost a lot of drawcalls ?
With each ParticleSystem we need one material. Using difference materials will make particleSystem not batch together, read more here
Depending on the game, the number of ParticleSystem will be difference, but in most cases, we used them quite a lot. Drawcall amount costly for ParticleSystem therefore also very high.
The benefit of making atlas for ParticleSystem ?
I made a simple demo on Github, a comparison between using and not using atlas for ParticleSystem
Not using
I create some effects using ParticleSystem, you can see here we spend 7 drawcall, corresponding to 7 materials was used for ParticleSystem :
Using Atlas:
Use the same amount of ParticleSystem, but now there’re only 1 drawcall :
How to ?
Texture Sheet Animation Module
Throught a very useful feature of ParticleSystem in Unity : Texture Sheet Animation Module . This feature is used to make animationSheet for ParticleSystem (some effects need a few frames, not just one). Like this:
Take advantage of this feature, we’ll make atlas for ParticleSystem. As the demo on Github, I used only 1 atlas for all ParticleSystem, then just one material is used.
Configuration steps
For example, I make a ParticleSystem, use the second tile in above atlas
Frame over lifetime
Here, we only need 1 frame, so select Constant
Split the atlas
For the second tile, I have to set :
* Tile : 4 x 2
* Frame over Time : 1
If you want to choose the smaller tiles, you have to change the divide ratio
Here, with the particle need the Smoke tile, I have to set:
* Tile is 8 x 4
* Frame over Time : 17
That it, very simple huh? Check out my sample on Github.
Some notes
-
- Atlas texure size must be POT (Power of two)
The size of texture must be 64, 128, 256, 512 …. This is relate to device’s GPU, you can read more here.
- For mobile devices, keep the atlas size lower than 2048×2048
I’ve read many “best practice” articles, they all say that the good texture size for mobile devices is not bigger than 2048. Texture size too large will cause the application consumes a lot of RAM, GPU overheating, reduce game performance.
- Atlas texure size must be POT (Power of two)
-
- Using Mobile Shader for Materials
Unity have some basic built-in shaders for Mobile, thoes shader written for more optimal for mobile devices. Of couse, the effects that use them will not “beautiful” as the default shaders, but don’t worry, the result won’t difference much. Unless you plan to make a big game like BattleField or Assassin’s creed on mobile
- Using Mobile Shader for Materials