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

来源:互联网 发布:邵阳学院网络教学平台 编辑:程序博客网 时间:2024/06/05 04:54


(接上文)

Anti-Aliasing(反走样(抗锯齿)

Anti-Aliasing is highly desirable in VR, as it helps to smooth the image and reduce jagged edges. If you are using Forward Rendering, you may be able to enable MSAA in Quality Settings, and you should always look to enable this for Gear VR where possible.

抗锯齿能够平滑图像并减少其上的锯齿边缘, VR非常依赖抗锯齿技术。如果你使用正向渲染,可以考虑在质量设置中启用MSAA,对于Gear VR你应该总是确保打开了该设置。

As MSAA is not possible when using Deferred Rendering, you may wish to enable AntiAliasing as a post-effect, or look into using SMAA. There’s an example of this from the community here.

由于延迟渲染时无法使用MSAA,你可能需要使用渲染后抗锯齿,或者看看能否应用SMAA,在社区中有一个相关的例子

Textures(纹理)

In general, you’ll want to use Texture Atlasing as much as possible in your project, and reduce the amount of separate textures and materials used.

通常,你会在项目中大量使用纹理图集并减少单个纹理和材质的使用

To simplify and speed up this process, MeshBaker can be used to bake textures, meshes, and materials to increase performance in your game.

为了简化和加速这个过程,可以用MeshBaker进行纹理、网格以及材质的烘焙以提高游戏的性能。

Holden from Turbo Button Inc talks about optimisation in general, and using MeshBaker at Oculus Connect 2.

Holden from Turbo Button公司在Oculus Connect 2上有关于 通用优化技术和MeshBaker使用 的讨论。

Please note that normal maps generally don’t look good in VR, so you may wish to avoid these. Please see the Oculus documentation on Rendering for more information on textures.

注意: VR中法线贴图的效果一般不佳,因此应尽量避免使用。如果想得到更多关于纹理的信息也请访问Oculus documentation on Rendering

Shaders(着色器)

Where appropriate, try to use the most basic shaders. On Gear VR, you might want to make use of the inexpensive Mobile > Unlit (Supports Lightmap) shader, and to lightmap your scenes.

尽可能多的使用基本着色器。在Gear VR上,尽可能多使用计算代价低廉的Mobile > Unlit (Supports Lightmap) 着色器,也可以用它进行场景的光照贴图。

Fullscreen Effects(全屏效果)

Fullscreen effects are expensive, and you will probably want to avoid these entirely on Gear VR.

全屏效果的运算代价高昂,在Gear VR上应尽量避免使用。

Quality Settings(质量设置)

The Quality Settings determine various aspects of the visual quality of your project. Altering these properties may help you increase performance at the expense of visual quality.

质量设置决定了游戏视觉质量的各个方面。修改这些参数以获得游戏性能与视觉效果间的平衡。

RenderScale(渲染规模)

Altering VRSettings.renderScale will trade sharpness for performance. See our Getting Started with VR Development article for more information and examples.

修改VRSettings.renderScale会在清晰度和性能之间进行平衡,欲获得更多这方面信息和例子可以参考我们的文章G Getting Started with VR Development

Asynchronous Loading(异步加载)

You may want to split your project into separate scenes to help performance. If you do this, be aware that when loading the next scene you will want to avoid freezing tracking of the head, as this will lead to nausea.

你可能会考虑将游戏分解到不同的场景中来提高游戏性能,如果你确定要这样做,要小心处置加载下一场景时对头部带来的追踪停滞,因为这会导致眩晕

To help avoid this, you might want and implement a loading screen with head tracking while asynchronously loading your next scene using SceneManager.LoadSceneAsync

为了避免上述情况,你可以通过SceneManager.LoadSceneAsync来在家在下一个场景时创建一个具有头部运动追踪的加载界面。

然后下面是例子场景中的优化技术:

Optimisation Techniques in Sample Scenes

We have implemented a number of optimisation techniques in the sample scenes to ensure good performance on Gear VR and DK2.

As we wanted to target both platforms with the same project, we catered for the lowest-end hardware; in this case Gear VR. We chose a low-poly art style, with a few basic colours to help items stand out in the environment.

As we are using Forward Rendering, we enabled 4x MSAA in Edit > Project Settings > Quality Settings for better visual quality:

MSAA Quality Settings

Let’s take a quick look at the techniques used in the scenes:

Menu scene optimisations

Like all of our scenes, this uses low-poly assets, and does not use realtime lighting.

We are using a custom shader called SeparableAlpha on the menu panels which allows a separate alpha channel to to be defined for the sequence of images. This means that not every frame needs it’s own alpha channel. This saves on filesize, and removes some aliasing.

Flyer scene optimisations

We enable fog at runtime in Flyer to ensure that the spawned objects don’t pop into view, and allows a shortened view distance, meaning fewer objects need to be rendered.

The asteroids have a low vertex count, meaning Dynamic Batching can be used, reducing draw calls.

To reuse objects we have created an object pool to handle lasers, asteroids, and gates. This stops expensive Instantiate calls being used regularly.

Of note here is the Flyer Vehicle albedo texture, which has been optimised to use a small colour swatch using a secondary UV channel in the Detail Map slot. This allows us to save on overall texture size.

Maze scene optimisations

The Maze environment is lightmapped, meaning that it has better performance at runtime, especially on the GearVR as it uses lower powered mobile devices to run the project. Otherwise it is a simple scene with no realtime lighting and minimal effects.

Shooter180 (Target Gallery) and Shooter360 (Target Arena) scene optimisations

As with the other games, we reuse the low poly art style in these scenes, along with object pooling for the targets, and a low vertex count to enable Dynamic Batching.

You should now have an understanding of some aspects of optimisation, how you can use built-in Unity tools to help analyse your performance, and some tips on how to get a better framerate.

The Oculus website has many useful resources that go into detail on this:

  • https://developer.oculus.com/documentation/

  • http://static.oculus.com/sdk-downloads/documents/Oculus_Best_Practices_Guide.pdf

  • https://developer.oculus.com/blog/squeezing-performance-out-of-your-unity-gear-vr-game/

  • https://developer.oculus.com/blog/squeezing-performance-out-of-your-unity-gear-vr-game-continued/

阅读全文
0 0