【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

查看: 4054|回复: 0

[Oculus&VR] Unity如何在Oculus SDK中发挥最大优势

[复制链接]
发表于 2015-3-22 16:22:39 | 显示全部楼层 |阅读模式
Unity Performance Best Practices
Good performance is critical for VR applications. This section provides simple guidelines to help your Android Unity app perform well. Please review the section titled “Performance Advice for Early Titles” in Design Guidelines before reading this guide.
良好的性能是虚拟现实应用的关键!本节提供了简单的指导,帮助你的Android应用程序执行Unity程序。没看过“早期游戏性能的建议“设计指南的先去看指南。
Oculus/GearVR开发者群 302294234
1. General CPU Optimizations 常用CPU设定
To create a VR application or game that performs well, careful consideration must be given to how features are implemented. Scene should always run at 60 FPS, and you should avoid any hitching or laggy performance during any point that the player is in your game.创建一个虚拟现实的应用或游戏的执行,功能如何实现必须认真考虑。游戏应该始终不能低于60帧,你应该避免任何影响到玩家在游戏中的延时。
Note: The Unity Profiler is not available for Unity Free.
Unity的性能分析在免费版中没有。
●Be mindful of the total number of GameObjects and components your scenes use.   注意在游戏中使用GameObjects和组件的总数
●Model your game data and objects efficiently. You will generally have plenty of memory. 游戏数据和模型会占用很多的内存
●Minimize the number of objects that actually perform calculations in Update() or FixedUpdate(). 对没有必要的Update() or FixedUpdate()尽量少用
●Reduce or eliminate physics simulations when they are not actually needed. 减少或者不用物理模拟,我们并不是经常使用到他们
●Use object pools to respawn frequently used effects or objects versus allocating new ones at runtime. 在运行特效或者创建物体的时候多使用对象池
●Use pooled AudioSources versus PlayOneShot sounds which allocate a GameObject and destroy it when the sound is done playing . 对于频繁调用的声音片段也是用池
●Avoid expensive mathematical operations whenever possible.尽量避免出现高昂代价的数学运算
●Cache frequently used components and transforms to avoid lookups each frame.缓存经常调用的数据和组件,避免每一帧都去检查这些数据
●Use the Unity Profiler to identify expensive code and optimize as needed. 通过Unity Profiler去分析和优化
●Use the Unity Profiler to identify and eliminate Garbage Collection (GC) allocations that occur each frame.通过Unity Profiler去分析每一帧的碰撞检测
●Use the Unity Profiler to identify and eliminate any spikes in performance during normal play. 通过Unity Profiler去分析影响正常性能发挥的拐点
●Do not use Unity’s OnGUI() calls. 不要使用OnGUI()
●Do not enable gyro or the accelerometer. In current versions of Unity, these features trigger calls to expensive display calls.不要使用陀螺仪和速度计算器,在Unity的新版本中这些调用都会严重影响渲染
●All best practices for mobile app and game development generally apply.所有的app和game都适用。

Oculus/GearVR开发者群 302294234
2. Rendering Optimization 渲染设定
While building your app, the most important thing to keep in mind is to be conservative on performance from the start.
一切最重要的就是性能的稳定
● Keep draw calls down.  保持稳定的DrawCalls
●Be mindful of texture usage and bandwidth. 注意控制纹理尺寸和带宽
●Keep geometric complexity to a minimum.将几何图形复杂度降到最低
●Be mindful of fillrate.  注意填充率
Reducing Draw Calls
Keep the total number of draw calls to a minimum. A conservative target would be less than 100 draw calls per frame.
保持最小的DrawCalls,保守的来讲每一帧不要超过100个DrawCalls。
Unity provides several built-in features to help reduce draw calls such as batching and culling. Draw Call Batching Unity attempts to combine objects at runtime and draw them in a single draw call. This helps reduce overhead on the CPU. There are two types of draw call batching: Static and Dynamic.
Static batching is used for objects that will not move, rotate or scale, and must be set explicitly per object. To mark an object static, select the Static checkbox in the object Inspector.为了降低CPU的消耗,Unity采用了尽量一次性渲染降低渲染。每一次渲染的都尽量减少资源之间的切换。这里有两种类型的绘制:静态和动态。
静态项将不能移动、旋转和缩放。
Note: Static batching is not available for Unity Free.
注意:静态项在Unity免费版本中不存在
Dynamic batching is used for moving objects and is applied automatically when objects meet certain criteria, such as sharing the same material, not using real-time shadows, or not using multipass shaders. More information on dynamic batching criteria may be found here:https://docs.unity3d.com/Documen ... awCallBatching.html
动态渲染也要有一定的标准:共享材质、不使用实时阴影,不使用多通道渲染等.......关于详细信息猛戳后面的链接。

Culling 裁剪
Unity offers the ability to set manual per-layer culling distances on the camera via Per-Layer Cull Distance. This may be useful for culling small objects that do not contribute to the scene when viewed from a given distance. More information about how to set up culling distances may be found here:
http://docs.unity3d.com/ScriptRe ... rCullDistances.html
Unity also has an integrated Occlusion Culling system. The advice to early VR titles is to favor modest “scenes” instead of “open worlds,” and Occlusion Culling may be overkill for modest scenes. More information about the Occlusion Culling system can be found here: http://blogs.unity3d.com/2013/12/02/occlusion-culling-in-unity-4-3-the-basics/

Reducing Memory Bandwidth
Texture Compression(纹理压缩)
Texture compression offers a significant performance benefit. Favor ETC2 compressed texture formats.
纹理压缩大大提高了性能,ETC2是有利于工作的压缩纹理格式。
Texture Mipmaps (渐进式纹理)
Always use mipmaps for in-game textures. Fortunately, Unity automatically generates mipmaps for textures on import. To see the available mipmapping options, switch Texture Type to Advanced in the texture inspector.游戏中总是使用Mipmaps。很幸运的是Unity在导入纹理的时候自动开启mipmaps,在 Texture 类型的 Advanced 去查看mipmaps项。
Texture Filtering(纹理过滤)
Trilinear filtering is often a good idea for VR. It does have a performance cost, but it is worth it. Anisotropic filtering may be used as well, but keep it to a single anisotropic texture lookup per fragment.
三线式过滤是非常适合VR的,它会增加一些消耗,但这是值得的。各向异性过滤也可以使用,但是要尽量保持单一的各向异性纹理查找每个片段。
Texture Sizes (纹理大小)
Favor texture detail over geometric detail, e.g., use high-resolution textures over more triangles. We have a lot of texture memory, and it is pretty much free from a performance standpoint. That said, textures from the Asset Store often come at resolutions which are wasteful for mobile. You can often reduce the size of these textures with no appreciable difference.
推荐使用细节纹理来覆盖模型细节,用一个高分辨率的纹理取代三角形,我们损失了一些纹理内存<---从性能上而言这简直是免费的。对于移动端,你可以随意的设定他们的大小,而视觉效果上差距不大。
Framebuffer Format (帧缓冲格式)
Most scenes should be built to work with a 16 bit depth buffer resolution. Additionally, if your world is mostly pre-lit to compressed textures, a 16 bit color buffer may be used.
大部分的帧缓冲都是16位的,另外如果你用了压缩纹理也是够用的。
Screen Resolution
Setting Screen.Resolution to a lower resolution may provide a sizeable speedup for most Unity apps.
设置屏幕分辨率的时候设置个较低的可以提高运行速度。

Oculus/GearVR开发者群 302294234
Reduce Geometric Complexity 降低几何复杂度
Keep geometric complexity to a minimum. 50,000 static triangles per-eye per-view is a conservative target.  Verify model vert counts are mobile-friendly. Typically, assets from the Asset Store are high-fidelity and will need tuning for mobile.
保持较低的图形复杂度,我们尽量保持一个屏幕在50,000个三角形。(后面的看不懂啦)
Unity Pro provides a built-in Level of Detail System (not available in Unity Free), allowing lower-resolution meshes to be displayed when an object is viewed from a certain distance. For more information on how to set up a LODGroup for a model, see the following: https://docs.unity3d.com/Documentation/Manual/LevelOfDetail.html
Unity的专业版支持LOD技术(免费版没有)在较远的距离显示面数较低模型,想知道关于更多的LOD设置信息猛戳这个链接。
Verify your vertex shaders are mobile friendly. And, when using built-in shaders, favor the Mobile or Unlit version of the shader. Bake as much detail into the textures as possible to reduce the computation per vertex, for example, baked bumpmapping as demonstrated in the Shadowgun project:https://docs.unity3d.com/430/Documentation/Manual/iphone-PracticalRenderingOptimizations.html要你的shaders支持移动端,选择支持移动端的shander。(后面的看不懂啦)例如:烘焙一个凹凸贴图在《暗影之枪》项目上。
Be mindful of GameObject counts when constructing your scenes. The more GameObjects and Renderers in the scene, the more memory consumed and the longer it will take Unity to cull and render your scene.

在场景里放的东西越多,渲染的东西就越多,更多的内存被使用并且渲染的时间也会变长。
Reduce Pixel Complexity and Overdraw 像素计算和
Pixel Complexity
Reduce per-pixel calculations by baking as much detail into the textures as possible. For example, bake specular highlights into the texture to avoid having to compute the highlight in the fragment shader. Verify your fragment shaders are mobile friendly. And, when using built-in shaders, favor the Mobile or Unlit version of the shader.
烘焙尽量多的细节在纹理上,例如烘焙高光贴图到纹理上,然后通过山的热计算高光,测试shander片段是否适合在移动端并且开始使用这些shander。
Overdraw
Objects in the Unity opaque queue are rendered in front to back order using depth-testing to minimize overdraw. However, objects in the transparent queue are rendered in a back to front,order without depth testing and are subject to overdraw.Avoid overlapping alpha-blended geometry (e.g., dense particle effects) and full-screen post processing effects.

在unity中调整不透明物体的渲染顺序并使用深度测试减少运算。另一方面带透明通道的队列渲染是有顺序的,没有深度测试并管理覆盖。要避免重叠。
3. Best Practices  最佳效果
Be Batch-Friendly.Share materials and use a texture atlas when possible.  尽量使用一张纹理资源
Prefer lightmapped, static geometry.烘焙到纹理,静态几何元素
Prefer lightprobes instead of dynamic lighting for characters and moving objects. 角色行为的时候用预光组
Bake as much detail into the textures as possible. E.g., specular reflections, ambient occlusion. 烘焙更多的细节到纹理上,比如镜面反射,环境光照
●Only render one view per eye. No shadow buffers, reflections, multi-camera setups, et cetera. 每个视口仅渲染一次,没有阴影缓冲、反射、多相机设置。
Keep the number of rendering passes to a minimum. No dynamic lighting, no post effects, don't resolve buffers, don’t use grabpass in a shader, et cetera.保持每次渲染pass最低值,没有动态光照,没有特效,不清理缓冲区,不执行grabpass这样的shander
Avoid alpha tested / pixel discard transparency.Alpha-testing incurs a high performance overhead. Replace with alpha-blended ifpossible.避免半透明测试或者像素透明。半透明混合将带来更大的开销。
Keep alpha blended transparency to a minimum. 保持半透明混合透明度降到最低。
Use Texture Compression. Favor ETC2. 纹理压缩采用ETC2
Do not enable MSAA on the main framebuffer. MSAA may be enabled on the Eye Render Textures. 不要打开各向异性,各向异性可以用在眼镜渲染纹理上。


4. Design Considerations 设计上的考虑
Please review Design Guidelines if you have not already done so.
你还没看《Design Guidelines(设计指南)》那就赶紧去看看吧
Startup Sequence
For good VR experiences, all graphics should be rendered such that the user is always viewing a proper three-dimensional stereoscopic image. Additionally, head-tracking must be maintained at all times. An example of how to do this during application startup is demonstrated in the SDKExamples Startup_Sample scene:
好的VR体验是在用户可以看到所有常见的内容。这些都需要实时渲染出来,并且要跟随着头部的动作保持连贯,在例子SDKExamples Startup_Sample里可以看到。(下面应该是个流程)
●Solid black splash image is shown for the minimum time possible.
●A small test scene with 3D logo and 3D rotating widget or progress meter is immediately loaded.
●While the small startup scene is active, the main scene is loaded in the background.
●Once the main scene is fully loaded, the start scene transitions to the main scene using a fade.
Universal Menu Handling
Applications will need to handle the Back Key long-press action which launches the Universal Menu as well as the Back Key short-press action which launches the “Confirm-Quit to Home” Menu which exits the current application and returns to the Oculus Home application. An example of demonstrating this functionality is in the SDKExamples GlobalMenu_Sample scene. More information about application menu options and access can be found in the Universal Menu document.

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2024-11-23 12:25

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表