Unity VR Development Record
Published:
在2017年中至2019年中这段时间,笔者断断续续参与了两项VR项目的开发,也遇到了不少新人容易碰到的问题。由于即将开始PhD阶段的学习,短时间内没有再参与一线VR开发的计划,所以在这里做一下简单的总结,以免后人踩坑。
首先,这些开发都是基于Unity,SteamVR 和 VRTK 工具库的,如果读者遇到其余发生在其他引擎/框架/工具库的问题,这篇文章可能无法提供帮助。
During the period from mid-2017 to mid-2019, the author participated in the development of two VR projects intermittently, and encountered many problems that newcomers are likely to encounter. As the PhD phase of learning is about to begin, and there is no plan to participate in the development of first-line VR in a short time, so here is a brief summary to prevent future generations from stepping on the pit.
First of all, these developments are based on Unity, SteamVR and VRTK tool libraries. If readers encounter other problems that occur in other engines/frameworks/tool libraries, this article may not be helpful.
问题描述与解决 Issue Statement & Solution
限制移动区域 Restricted movement area
平整地面/模块化地面 Flat floor/modular floor
在平整地面上,限制用户移动区域的方案比较成熟且简单。在VRTK中Teleport组件被使用来移动到指向位置,只需要设定Nav Mesh并Bake,就可以设置PlayArea来限制可移动区域。当地面为模块化构建时,也可以通过设置Policy选择可以移动的对象,间接限制了移动范围。
以上方法均可以通过搜索VRTK+关键词获取完整流程,故本文中不再重复阐述细节。
On a flat ground, the solution to restrict the user’s moving area is relatively mature and simple. In VRTK, the Teleport component is used to move to the pointing position, only need to set Nav Mesh and Bake, you can set PlayArea to limit the movable area. When the ground is modularly constructed, you can also select objects that can be moved by setting the Policy, which indirectly limits the range of movement.
All of the above methods can obtain the complete process by searching VRTK+keywords, so the details will not be repeated in this article.
非平整&非模块化地面 Non-flat & non-modular floor
这是一个比较麻烦的情况,一大块有起伏的地面对象的一部分需要被设置为可移动区域,此时Bake Nav Mesh或者通过Policy设置均无法解决问题,此时可以通过物理引擎的碰撞判定设置移动范围,即利用空气墙和空气地面。
此方法较为低效且隅合度较高,一般情况下不建议使用,可以通过分割地面对象等方法解决,若读者有更为高效的方法也请不吝赐教。
This is a more troublesome situation. A part of a large undulating ground object needs to be set as a movable area. At this time, Bake Nav Mesh or the Policy setting cannot solve the problem. At this time, the collision determination setting of the physics engine can be used. The range of movement is the use of air walls and air floors.
This method is relatively inefficient and has a high degree of integration. Under normal circumstances, it is not recommended to use it. It can be solved by methods such as segmenting ground objects. If the reader has a more efficient method, please feel free to enlighten me.
物体交互 Object interaction
在Unity VR开发中,物体的抓握可以基于VRTK的Grab组件实现,抓握提示,可抓握区域均可在组件中自定义。
此处需要注意的点是,设置碰撞体时尽量避免选用自适应多边形,建议使用多个长方体或者柱体的组合设置碰撞及抓握,以避免奇妙判定甚至鬼畜事件的出现。
In Unity VR development, the grip of objects can be realized based on the Grab component of VRTK, and the gripping prompt and the gripping area can all be customized in the component.
The point to note here is that when setting the collision body, try to avoid using adaptive polygons. It is recommended to use a combination of multiple cuboids or cylinders to set collision and grasping to avoid strange judgments and even ghost events.
光线设置 Light setting
在Unity中,光影效果可以通过设置光源与环境对象进行增强,更高效的方法是在镜头上添加滤镜组件,由于该部分代码为老板提供,此处细节不做阐述。
当然,Unity3D在光影渲染领域表现并不突出,追求光影的话请移步Unreal或者其他商用引擎。
In Unity, the light and shadow effect can be enhanced by setting the light source and environment objects. A more efficient method is to add a filter component to the lens. Since this part of the code is provided by the boss, the details will not be explained here.
Of course, Unity3D is not outstanding in the field of lighting and shadow rendering. If you pursue lighting and shadow, please move to Unreal or other commercial engines.
硬件配置 Hardware Configuration
在开发过程中,一般会保持硬件设备一直开机,例如HTC Vive及其配件,但要注意隔一段时间重启一次并基于SteamVR重新校准。
因为在较长时间的使用后,由于小幅度位移,碰撞等,镜头校准会出现偏差,导致无法准确定位头戴式显示器或者手柄。笔者遇到过类似情况且Vive没有任何提示,摄像头均显示正常工作。
During the development process, hardware devices, such as HTC Vive and its accessories, are generally kept turned on, but be careful to restart once every other time and recalibrate based on SteamVR.
Because after a long time of use, due to small displacements, collisions, etc., the lens calibration will be deviated, resulting in the inability to accurately locate the head-mounted display or the handle. I have encountered a similar situation and Vive did not give any prompts, and the cameras showed that they were working normally.
硬件适配 Hardware adaptation
不同配置的电脑可承载的机能不同,在使用UnityVR开发时,需要注意模型精度与分辨率的问题。
笔者的团队在开发时由于追求模型在VR中的还原性,大量使用了超过4K的高清贴图,在模型数量增加到一个量级以上后,原本使用公版1080TI的开发机会出现加载缓慢,散热不足等问题,影响开发体验。后改用24G显存版本的M6000才部分解决了该问题。
由于笔者团队是研究项目,所以不考虑发行版的优化,在针对开发版的优化中,LOD是较为可行的方案,通过对不同级别的机能设置不同质量的模型和贴图可以减少渲染压力,增加普适性。
Computers with different configurations can carry different functions. When developing with Unity VR, you need to pay attention to the accuracy and resolution of the model.
The author’s team used a large number of high-definition textures exceeding 4K in the development of the pursuit of the model’s reducibility in VR. After the number of models increased to more than an order of magnitude, the development opportunities that originally used the public version of 1080TI showed slow loading and insufficient heat dissipation. Other issues affect the development experience. The problem was partially solved by using the 24G graphic memory version of M6000.
Since the author’s team is a research project, it does not consider the optimization of the release version. In the optimization of the development version, LOD is a more feasible solution. By setting different quality models and textures for different levels of functions, the rendering pressure can be reduced, and the generalization and adaptability can be increased.
总结 Conclusion
在UnityVR开发中,大部分工作与开发Unity3D项目相似,但是在交互设置和硬件设置上还有不少需要额外注意的点,VRTK在Youtube上的视频教程在我的开发过程中提供了较多的帮助,也祝大家能顺利解决在VR开发上遇到的问题。
最后,感谢 NVIDIA Joint-Lab 每一位同事的帮助,也感谢庄教授在研发过程中提供的指导与软硬件上的支持。
In UnityVR development, most of the work is similar to the development of Unity3D projects, but there are many points that require additional attention in interactive settings and hardware settings. The video tutorials of VRTK on Youtube have provided more in my development process. Help, and I wish everyone a smooth solution to the problems encountered in VR development.
Finally, I would like to thank every colleague of NVIDIA Joint-Lab for their help, and also thank Professor Eugene Ch’ng for his guidance and hardware and software support during the research and development process.