簡介
在一連串效能優化介紹後,可以在 Unity 找到很多方法,而今天要來講一個透過我們常用的製作材質工具來建立體積非常小的材質包,就是 Substance 的 .Sbsar 格式的材質球。
前提
在過往我們的製作程序是進入 Substance Painter 繪製好材質後,匯出數張材質的貼圖,通常幾張貼圖所佔的空間就是好幾十MB,更大的物件可能大到幾百MB,一併整合在場景中,累積起來的記憶體Loading可說是非常吃重,我們來看看一般的貼圖與材質球的大小。

製作.SBSAR檔案
我們在 Unity 中要使用 .Sbsar 檔案的話要先至 Asset Store 下載 Substance in Unity Plugin,下載好請 Import。

我們先轉台至 Substance Designer 軟體將先前透過 Painter 匯出的 Texture 進入 Designer 匯出 .Sbsar 檔案。
先前已經學會在 Painter 設定匯出 Unity HDRP 的設定,但我們現在是要丟到 Designer 產出 .Sbsar 檔案,所以透過 Painter 匯出6個格式的檔案如下圖。

接著開啟 Designer 新增一個 Graph 檔案,並選擇 PBR Template。

把剛剛從 Painter 匯出的圖檔拉到畫布中 ,並將相對應的圖檔連結至正確的Channel中。並可以看3D View中的效果再來做一些微調。

最後匯出 .Sbsar 格式,依照下圖的順序點選並匯出即可,製作 .Sbsar 步驟大概就到這邊,其實也可以使用 Substance Alchemist (煉金術師)軟體匯出也可以。

將.SBSAR匯入Unity

將剛剛製作好的 .Sbsar 檔案匯入 Unity 時 (要先安裝好Substance in Unity Plugin)就可以看到如上圖的樣式。

而在將材質球丟到模型前我們可以看看 .Sbsar 檔案大小,34.2 < 65 MB,與舊有的基本製作流程小了快兩倍的資源,而且圖片大小都是2048*2048。

跟以往的 Texture Setting 有點類似,但 .Sbsar 檔案是整合了所有 Texture 可以一併作調整。接著我們把包在 .Sbsar 中的 Material 拖曳至模型中,就完成了。
當然 .Sbsar 的材質球依樣可以在 Unity 中做調整,此外掛是使用了HDRP/LitTessllation Unity Shader,所以不需要將 .Sbsar 轉換成 HDRP。

下圖為兩個模型運用 Basic Texture + Material 花費 65MB (右邊物件) VS .Sbsar Substance Material 花費 34.2MB(左邊物件)。

小結

當然使用 Unity 內建的 Compression 或是調整 Max Size 會降低大小,但是畫質也會跟著打折,雖然使用本篇介紹的流程會多一個步驟,但能讓整個場景跑得動、跑的順、跑得漂亮才是最終目標,在未來遇到多物件與大場景的專案時,可以嘗試使用這方法,順便做一個效能實測。