Day2 Overview
1. Keynote: Infinity Unity
2. GPU Instancing – 羅志達
3. Unity 影視工具 Timeline – Marek Marchlewicz
4. Animation Instancing – 張陳淵
5. Unity 非同步編程技術詳解 – 楊懷忠
Day3 Overview
1. Unity 遊戲原型快速開發實踐 – 楊棟
2. UGUI 深度優化提升手遊效能 – 楊懷忠
3. Unity 靜態腳本分析 – 張黎明
4. Unity 圖形快速定位與 Debug 技巧 – 張陳淵
5. Scriptable Render Pipeline – 張黎明
6. Asset Bundle Graph Tool 流程工具深度介紹 – 羅志達
Keynote: Infinity Unity
劉景岩:大陸市場的問題
– Localization & Integration
– Platform support
– Publishing license
Reference: unity.mi.com
常守瑜:Unity Connect
– Showcase
– Find help
– Get paid
Kelvin Lo:新功能
CinemachineCamera (Virtual Camera)
– Procedure Camera Work:判斷目標位置或障礙物自動切換 Camera
NavMesh
– Progressive Lightmapping
– 不需要重新烘焙
– 針對 Camera 可視範圍,先用低階方式算
– 動態計算場景、無接縫地圖(可設定範圍大小)
Kelvin Lo:GPU Instancing,從入門到放棄
問題
– 大量的渲染、無雙系列
– 一次 Draw Call,來達到降低 CPU 負載
Instanced Shader: 5.6
– Advanced Options => Enable Instancing 打勾
原理
– 把相同 Geometry 物體的頂點數據以及世界座標交給 GPU 處理
限制
– 跟光有關的無法使用:Light probe
– 除了 PC 或家用主機外,其他平台還沒有好的解決方案:放棄!
API
– 5.5: DrawMeshInstanced
– 5.6
– DrawMeshInstancedIndirect
– Shader variant stripping
解決方案
– Array-of-Struct Layout:更緊湊的排列每個 Instance
– Out-of-Bounds Read
改進
– 支援半精度 half2, half4
– 大部分功能正在測試及程式審查 2017.2
Carl Callewaert:Unity 5.6 Video Player
Cinemachine FreeLook Camera
– LookAt
– Follow
– Rotate by mouse position
Cinemachine Virtual Camera
– Aim: 可以調整 Offset & Size
– Noise: 加入手震的感覺
Timeline + Playable Director
– 結合同一物件中的各個 Animation:Idle => Jump => Die
– 結合不同的物件 Animator
張陳淵:基於 Animation Instancing 的人群模擬
i7 + GTX 980Ti:30000個角色 x 500面 = 50~60 FPS
GPU Instancing 的缺陷:不支援骨骼動畫 => Animation Instancing
Animation Instancing
– GPU Instancing 的一種擴展
– 需要的數據
– Instancing Vertex:Animation T-Pose下的頂點數據、骨骼的索引及權重
– Instancing Data 角色的獨有數據:世界矩陣、骨骼動畫數據、動畫索引、動畫幀索引
LOD
– 距離 Camera 比較遠的物件,就使用低精度的 Mesh => 低頂點數
– 降低渲染的面數、降低 overdraw
Animation Texture
– TextureFormat.RGBAHalf
– Filter Mode: Point
– 不需要 mipmap
Animation Texture Bake Flow
– 搜索模型的動畫
– 計算蒙皮矩陣
提交渲染
– Material.SetBuffer
– DrawProcedural
– DrawMeshInstanced
優點
– 避免骨骼動畫的計算開銷 (Animator.Update())
– 在 GPU vertex shader 計算蒙皮 (MeshSkinning.Update())
– 降低了 CPU 到 GPU 的數據傳說 => 降低 Drawcall
缺點
– 無法使用 Blend Tree
– 不支持 IK
– 動畫精確性降低
楊懷忠:Unity 中的非同步程式技術(Job System)
多執行緒渲染
– 過多的遊戲性能負荷集中在 Main Thread
– 在 Unity 5.4 中把 Camera.Render 的工作移出,但大大還不足
– Unity 5.6 開始支持 Vulkan
Unity Job System (Worker threads)
– Main thread, Render thread, many worker threads
– Particle systems, Animation systems, 不料計算、遮擋剔除、視錐體剔除、蒙皮和靜態裁剪
– 基於任務式的高效安全多執行緒系統
– 多工之間可以存在依賴關係
– 可以根據主執行緒排優先順序
Unity 中的非同步作業
– Resources.LoadAsync, Lightmapping.BakeAsync…
– AssetBundle.LoadFromFileAsync:可能主執行緒只佔用 1% 時間
Coroutine
– Main thread
– one frame 中的執行順序:WaitForSeconds, WaitForFixedUpdates, WaitForEndOfFrame
– C# 編譯器會建立一個 Coroutine 類別,也是一種消耗(增加內存消耗)
– 生命週期與 MonoBehaviour 相同
– Coroutine 中的區域變數會變成 Class 的 Member
– 為了減少 Main Thread 的開銷,避免在 Coroutine 中進行一些大量的計算
– 盡可能少用 Coroutine
– 巢狀式的 Coroutine 對於 Code 的簡潔與維護都不錯,但會容易導致較高的記憶體開銷
C# Threads
– 真正的並行
– Race condition:Lock
– 鎖死:Deadlock
– 不能在 C# 的執行緒中 Call Unity API
楊棟:Unity 遊戲原型快速開發實踐
Why
– 驗證技術可行性
– 核心玩法試驗
– 從一堆原型中挑出最好的
實際案例分析:簡單的橫向捲軸格鬥遊戲(打殭屍)
– Parallax Scrolling:2D platformer
– Flash 2 Unity:GAF Pro: Flash to Unity ($95)
– SWF => .gaf (binary) + .png (atlas)
– Import 後會生成 Animation Controller + Animations => Create Prefab
– 自己連接 State:Sub State Machine
– 連擊操作 + 簡單 AI:PlayMaker
– 各種手勢:EasyTouch 5
– 解決碰撞體在正確時間出現在正確位置
– 粒子特效:Cartoon FX
– Custom Script:碰撞、控制 PlayMaker
楊懷忠:UGUI深度優化手遊效能
UI Basics
– Render Details
– Back-to-front with alpha blending
– High level of overdraw (每個像素期望只畫一次)
– Rebatch
– 保存結果,重用 Batching,直到 Dirty (任何 Mesh 發生變化)
– 如何計算 Batching (為何浪費):Mesh sorting (depth, overdraw, material)
– Rebuild
– Layout rebuilds:重新計算所有頂點
– UI 元素的位置或大小改變時
– 優先計算根節點
– Graphic rebuilds:Color & Alpha channel
– 頂點數據 Dirty
– 材質或貼圖 Dirty
– Perform::Update()
UI Optimize Tools
– Profilier
– Canvas.BuildBatch
– Canvas.SendWillRenderCanvases
– Unity Frame Debugger
– Xcode’s Instruments
– Xcode’s Frame Debugger
Canvas Rebuild
– 子物件的順序:把相同材質的物件排一起
– 多級 Canvas:僅影響自身 Canvas
– Rebuild 會是效能瓶頸嗎?
– 只存在單一或少數的 Canvas
– 太過平凡的 Dirty 導致 Rebuild
Canvas
– 一般準則:根據靜態與動態元件區分 Canvas
– Raycaster
– 必要組件才開啟 Raycast Target
– 放在越底層越好
Font
– 每個字都是四邊形
– Font Mesh Rebuild
– UI Text 組件發生變化
– 父物件發生變化
– SetActive or Enable/Disable
– 動態字體和字體集
– 當前 Font texture 未包含所需要的字時,Font texture 會 rebuild
– 字體集的大小只增不減
– Font.RequestCharactersInTexture 可以有效降低啟動時間
– Best Fit:自動調整到最大的整數大小,一般不建議開啟
ScrollView
– 列出所有的 Cell:只適用於少量的情況
– Buffer Pool
– 需要申請足夠大的記憶體
– RectMask2D
重要建議
– Layout 組建很昂貴:不要用
– Disabling Canvas Component
– SetActive 或是移到看不到的地方,同樣需要重建
– 使用 Disable 可以重新利用 Buffer Pool
– 避免 UI 重疊
– 優化 UI Shader
張黎明:Unity靜態腳本分析
Why
– 有限的開發時間
– 避免人工檢查的遺漏
– 可以整合 CI
已有的代碼分析器
– Visual Studio “Squiggles”
– Resharper
– Roslyn
– 可擴展的 Analyzer
– https://github.com/dotnet/roslyn
Unity Engine Analyzer
– https://github.com/meng-hui/UnityEngineAnalyzer
– Reflection
– Nuget => UnityEngineAnalyzer
– Customize
– Visual Studio SDK
– .Net Compiler Platform (“Roslyn”) SDK
Unsealed Derived Class Analyzer
– 利用 sealed class 來減少 virtual function 的消耗
– 繼承 DiagnosticAnalyzer:將所有 method 拿來判斷 IsOverride() && !IsSealed()
張陳淵:Unity圖形bug定位及調適技巧
Filter Mode
– Point = Bilinear
– Trilinear:使用不同的層級來進行 Mipmap
Why
– 找出壞圖原因
– 暸解原理,進一步優化
工具:確認數據(你的推測)
– 調查方法:分析 => 調試 => 驗證
– 範例(pic * 100 – 90)
優化
– 檢查渲染時間:Draw call time
– 渲染順序:Rendering Pipeline (常用:VS, PS)
– 同一 draw call 下,透過檢查頂點順序
– 裁剪
錯誤檢查
– 狀態檢查:History (檢查Overdraw)
– 輸入輸出檢查:確保每個階段的 I/O 都正確
– Shader調試
工具
– Unity Frame Debugger
– Nsight
– Visual Studio Graphics Analyzer (可看到 Geometry Stage 階段的狀態)
– Render Doc (推薦***)
– Android Studio
– Apple Instrument
Dynamically Batching
視角固定的遊戲:透過固定渲染順序來優化 (UGUI 就是透過此種方式來優化 Draw Call)
張黎明:Unity Scriptable Render Pipeline
Current pipeline status
– Configurability: Big black box
– Discoverability: Not documented
– Flexibility: Can’t be extended
– Maintainability
– Architecture is complex
– Camera does everything
– Outdated features: Grab pass
The new philosophy
– Small C++ core
– Expose API
– Implement specifics in C#
Features
– Lean
– User centric: Easy to debug, work & extend
– Optimal
– Explicit: No magic, clean API
How
– Rendering is generally (SUPER HIGH LEVEL)
– What to render
– What state of objects
– Submit to GPU
Scriptable Render Pipelines
幫助 User 進行底層光照陰影等細節
– Script a whole pipeline – High level abstractions
– Draw a list of things, rather than single thing
– Sorting
– Shadows
– State management
– More functionality
– User centric
Userland v.s Unityland
Performance: If it’s performance critical, it’s done in C++.
Future: More in C# if we can make it fast.
C# / Userland
– Instantiating culling
– Rendering passes
– No per renderer operations
C++ / Unityland
– Culling /soting modules
– Issuing watchable draw calls
Making a render pipeline
Render Pipeline Asset => (create) => Render Pipeline Instance
Render Pipeline Asset
– IRenderPipelineAsset: DestroyCreatedInstances, CreatePipeline
– IRenderPipeline: dispose, Render(ScritableRenderContext ,cameras);
Example
GraphicSettings => Scriptable Renderloop Setting => Drag render pipeline asset
– Clear depth buffer
– Draw opaque objects
– Draw skybox
– Draw transparent objects
Command scheduling
– Everything is queued up
– Submit gets called
– Every command is a job
Kelvin Lo:Asset Bundle Graph Tool
Hiroki Oame 大前廣樹:Unity Director, Unity-Chan’s father
AssetBundles
– Minimize first package
– Dynamically updating
– Better memory management
Current situation
– 文件不齊全
– 跨平台載入效率不一
– 某些系統相容性不足:Code stripping, shader variants
Asset Bundle Browser
– Configure: Drag prefab
– LoadAsset.cs
– LoadScene.cs:Disabled after load,可以設定 Loading
– Conflict detection: 把共用的 object 再拉出來,會自動建立關聯
– 可以關連 AssetBundle Graph Tool
Asset Bundle Manager
– Simulation mode:還沒 Build 之前可以先模擬
– Local Server
– Remote Server
Asset Bundle Graph Tool
– Load From Directory => Split By Filter => Group By File Path (Grouping keywords) =>
Configure Bundle from group => Build Asset Bundle => Export To Directory
– Extract shared assets: Check dependancy
– Group by runtime memory size
– Automation: 自動化美術資源匯入格式設定流程
– Load from directory => Split by filter => Overwrite import setting (Use As Postprocessor)
– Last imported items: 不管從哪來的資源都執行,建立好命名規則即可
– Label Assets: Preview 加標籤
Unity Technologies: Asset Bundle Manager + GraphTool + Browser
https://bitbucket.org/Unity-Technologies/assetbundledemo
https://bitbucket.org/Unity-Technologies/assetbundlegraphtool
https://bitbucket.org/Unity-Technologies/assetbundles-browser
大大你好
您的這篇文章 借我貼到我整理的連結內哦
https://github.com/L1247/2017-UDC_Taiwan-Link
感謝分享
OK~ 沒問題!