1. 程式人生 > >unity VR遊戲幀數優化(二)

unity VR遊戲幀數優化(二)

這篇主要摘錄了unity官網上對於VR專案優化相關的帖子,讀罷受益良多,也應用到了自己的專案裡。這裡記錄留作日後學習參考。

由於在目標平臺上達到幀率要求是保證玩家獲得良好VR體驗,同時避免眩暈的重要措施,優化在VR遊戲開發中佔據著極其重要的地位。和其他平臺不同,最好在VR遊戲開發早期就著手進行優化,同時優化也應當經常進行,而不是將其放在開發的最後階段,當然,在目標平臺上經常性開展測試也是有益的優化手段

相較於非VR工程,VR是計算消耗很大,這主要是由於每次都要分別為每隻眼睛單獨進行整個場景的渲染。因此,在建立VR體驗時應確保自己熟知該領域中的一些常見問題。如果你能預先對這些問題有所認識,就可以圍繞這些問題進行專案的設計,從而避免在專案生命週期後期的繁重工作。


移動VR對於優化的要求更加強烈,不僅在於執行VR應用的大量開銷,同時,移動裝置的效能只是桌面PC的零頭,此時優化就會成為影響專案成敗的至關重要的因素。

由於達到目標幀率十分重要,所有的優化方法都需要進行考慮。別忘了儘可能多的優化程式程式碼,細節可以檢視Unity的程式碼優化指南

Unity Editor optimisation tools(Unity自帶的優化工具)

The Profiler(效能分析器)

The profiler will help you understand how much time is spent rendering each frame of your game, and splits this into CPU, Rendering, Memory, Audio, Physics and Network. Understanding how to use the Profiler is critical to examining performance, and identifying areas that need optimisation.

可以讓你瞭解遊戲中每幀渲染的時間開銷,並通過處理器、渲染、記憶體、音訊、物理和網路進行分項顯示。執行效能測試時,瞭解效能分析器,找到需要優化的方面非常重要

To find out more about using the Profiler, please see these links(擴充套件連結):

Geometry(幾何體)

Remove any faces from your geometry that will never be seen in VR. We don’t want to render something that will never be seen. For example, if the user will never see the back of a cupboard as it’s against the wall, we don’t want any of those faces on the model.

移除VR場景中永不可見的幾何體表面。例如,使用者永遠看不到靠牆櫃子的背面,那麼我們就不需要在那個模型中建立背面中任何一個表面。

Simplify your meshes as much as possible. Depending on your target platform, you may want to look into adding detail via textures, and potentially parallax mapping and tessellation, though this can impact performance, and may not be suitable or available for your target platform.

儘可能簡化mesh。根據你的目標平臺,你可能會想通過紋理增添細節,使用視差貼圖、曲面細分技術,但這可能會對效能造成影響,也可能無法適用於你的目標平臺。

Overdraw(遮擋繪製)

Overdraw view allows you to see what objects are drawn on top of another, which is a waste of GPU time. Look atreducing overdraw as much as possible. You can view overdraw in the Scene View by using the Scene View Control Bar.

遮擋繪製會讓你看到繪製在別的物體上方的物體,這樣就造成了GPU時間的浪費。 儘可能減少遮擋繪製的數量。你可以通過Scene View 控制欄中檢查遮擋繪製。

Overdraw Menu

Normal shaded view:

Maze Normal Shaded

Overdraw enabled:

Maze Overdraw

Level of Detail(細節級別)

Level Of Detail (LOD) rendering allows you to reduce the number of triangles rendered for an object as its distance from camera increases. As long as your objects aren’t all close to the camera at the same time, LOD will reduce the load on the hardware and improve rendering performance by adding an LOD component and providing lower detail meshes for distance groups further from the camera.

細節級別渲染可以讓你減少距離相機較遠物體的三角面的數量。只要遊戲物體不是同時出現在攝像機附近,通過新增LOD元件就可以通過為較遠物體指定面數較低的網格模型,減少硬體負荷,並提高渲染質量。

LODLOD

Using Simplygon can automate much of the asset preparation process for LOD.

使用Simpolygon 可以自動為大部分遊戲資源進行LOD預處理。

Draw Call batching(Draw Call批處理)

Batch Draw Calls wherever possible, using Static Batching and Dynamic Batching. This can greatly increase performance. See the Unity guide to Draw Call Batching.

儘可能使用靜態批處理和動態批處理來進行Draw Call 批處理的呼叫。這個可以極大提高執行效能。(檢視Unity指南來進行Draw Call批處理的學習)

Lightmapping(光照貼圖)

Eliminate dynamic lighting wherever possible, and bake lighting where you can, and avoid realtime shadows.

儘可能削減動態光照而使用烘焙得到光照效果,避免使用實時陰影

See the Unity guide to Lighting and Rendering for more information.

Light Probes(光線檢測)

Light probes allow you to sample the lighting at points in the scene and apply this to dynamic objects. This is relatively fast, and frequently has great visual results.

光線檢測對場景中某點的光照進行取樣並將其應用於動態物體上,執行速度較快,通常能獲得較好的視覺效果。

Reflection Probes(反射檢測)

Reflection probes store cubemaps of their surroundings to allow for realistic reflections, and can impact performance. Please be aware that real-time mode reflection probes are too slow to use in VR at this time.

反射檢測儲存周圍環境的立方體貼圖來獲得真是的反射,並且會顯著影響效能。請注意實時的反射檢測因過於緩慢而無法應用於VR專案的開發中。

Occlusion Culling(遮擋剔除)

Occlusion Culling stops objects from being rendered if they cannot be seen. For example, we don’t want to render another room if a door is closed and it cannot be seen.

遮擋剔除可以停止不可見的物體渲染。例如,我們沒有必要去渲染一個門被關上。並且內部情形不可見的房間。

Depending on your project and target platform, you may be able to implement Occlusion Culling, which can significantly increase performance.

能否使用遮擋剔除視你的工程和目標平臺而定,但一旦使用,遮擋剔除將極大提升遊戲效能。

An example of frustum culling:

Frustum Culling

An example of Occlusion Culling:

Occulusion Culling