(部分原创)unity项目开发中VR工程的优化(上)

来源:互联网 发布:淘宝旗袍模特周婷资料 编辑:程序博客网 时间:2024/06/05 19:21

前些日子,总结了之前VR工程的一些教训,又回到了unity的官网进行学习,看到了这篇文章。

读罢,感觉之前我们做的项目还有很大的优化空间,并且感觉学到了不少,然后就把这篇文章摘录了部分自认为有用的内容,并加以部分翻译,留作以后参考。

Introduction(前言)

As achieving the target frame rate for your chosen platform is an essential part of ensuring users have a great, nausea-free VR experience, optimisation is a critical part of VR development. Unlike some other platforms, with VR it’s best to optimise early and often, rather than leaving it to a later stage in development. Testing regularly on the target devices is also very helpful.

由于在目标平台上达到帧率要求是保证玩家获得良好VR体验,同时避免眩晕的重要措施,优化在VR游戏开发中占据着极其重要的地位。和其他平台不同,最好在VR游戏开发早期就着手进行优化,同时优化也应当经常进行,而不是将其放在开发的最后阶段,当然,在目标平台上经常性开展测试也是有益的优化手段

VR is computationally expensive compared to non-VR projects, mainly due to having to render everything once per-eye, so make sure you’re familiar with some of the common issues when creating your VR experience. If you’re aware of these issues beforehand, you can design your project around them, saving a lot of hard work later on in your project lifecycle.

相较于非VR工程,VR是计算消耗很大,这主要是由于每次都要分别为每只眼睛单独进行整个场景的渲染。因此,在创建VR体验时应确保自己熟知该领域中的一些常见问题。如果你能预先对这些问题有所认识,就可以围绕这些问题进行项目的设计,从而避免在项目生命周期后期的繁重工作。

Mobile VR can be particularly demanding. Not only do you have the overhead of running a VR application, but mobile devices are a fraction as powerful as a desktop PC, so optimisation will be of critical importance in your project.

移动VR对于优化的要求更加强烈,不仅在于运行VR应用的大量开销,同时,移动设备的性能只是桌面PC的零头,此时优化就会成为影响项目成败的至关重要的因素。

As hitting the target framerate is crucial, all optimisation counts. Don’t forget to optimise your code as much as possible. See the Unity guide on optimising code for more detail.

由于达到目标帧率十分重要,所有的优化方法都需要进行考虑。别忘了尽可能多的优化程序代码,细节可以查看Unity的代码优化指南

Unity Editor optimisation tools(Unity自带的优化工具)

There are are number of useful tools and techniques in Unity that will help you optimise your content for VR.

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(扩展链接):

http://docs.unity3d.com/Manual/Profiler.html

https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/profiler-overview

https://unity3d.com/learn/tutorials/modules/intermediate/editor/intro-to-profiler

Frame Debugger(帧调试器)

The Frame Debugger allows you to freeze playback on a frame and step through the individual draw calls to see how your scene is constructed, and identify where these could be optimised. You may find you’re rendering objects you don’t need to, which will greatly help in reducing the draw calls per frame.

使用帧调试器可以让你冻结任意帧的反馈,进入每个单独的Draw Call以检查场景构建的过程,并找到那些需要优化的位置。从中你可以找到那些对无需渲染对象进行的渲染操作,从而极大的帮助降低每帧的Draw Call数。

More information on using the Frame Debugger can be found here(扩展链接):

http://docs.unity3d.com/Manual/FrameDebugger.html

https://unity3d.com/learn/tutorials/modules/intermediate/graphics/frame-debugger

VR Optimisation Fundamentals(VR优化基础)

As optimisation is a huge field, and requirements change per-platform and on your project’s requirements, we have provided areas of interest for further reading.

In general, existing optimisation techniques carry over well into VR development, so existing knowledge can often be applied.

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


阅读全文
1 0