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

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

    • 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.
    • 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 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值