[簡介]
關於VFX的效能優化,在網路上有找到這篇(Unity 2018 – Game VFX – 10 Performance Improvements Tips)介紹優化的10種提醒就依照這十個點和大家討論分享。
1.Destroy your VFX as soon as possible
在Particle System或VFX中,若有設定噴發持續時間,可以透過以下的程式碼進行調整,在最大的噴發週期結束後,再加上持續時間。若沒有用到持續時間概念的VFX,這條就沒有用。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyVFXScript : MonoBehaviour
{
void Start()
{
Destroy (gameObject, GetComponent(ParticleSystem).main.duration + GetComponent(ParticleSystem).main.startLifetime.constantMax);
}
}
2.How many times your VFX appears simultaneously matters
不要太多VFX同時間出現,看下圖效能比較得知,FPS會直接掉。

3.Amount of Triangles per VFX
減少 Triangles 的數量,這案例用了不同的Texture sheet,來減少 Triangle 的數量。

4.Reduce the amount of materials, reduce the draw calls
減少設計素材的數量,就能減少draw calls,就能增加效能。
5.Use Sprite Sheets / Texture Atlas
在做連續動畫,若循環圖形時可用 Sprite Sheets

在2D介面時,可用 Texture Atlas 將素材都整併進一個Atlas檔案,也能減少 draw calls
6.Make sure your Sprite Sheets are not above 4096 x 4096
因為手機解析度的關係,會將 Sprite Sheets 的檔案大小做在 4096 x 4096 以下。
7.The Renderer Settings of the Particle Systems should be equal
在同一組Particle Systems的Render mode的模式,都要選一樣的才會效能提升,若選不同的效能就直落。如下圖,選擇不同模式,FPS和Tris都會提升,效能變差。

8.Your VFX is ready for batching
9.Some modules will cancel Automatic Culling

10.Avoid using “Application Framerate = -1”
[小結]
此案例以Particle System為主,但當中蠻多實際運用的方式,也相當適用於VFX。