[Unity3D] Optimization – Make Atlas textures for ParticleSystem, reduce drawcall, why not ?

来源:互联网 发布:php虚拟物品商城 编辑:程序博客网 时间:2024/06/08 04:21

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, smokefalling 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

原创粉丝点击