美文网首页
Unity性能优化技术(一)--LOD技术

Unity性能优化技术(一)--LOD技术

作者: Jens丶 | 来源:发表于2017-05-24 11:48 被阅读0次

    LOD: (Level of detail)多层次细节,是最常用的游戏优化技术。它按照模型的位置和重要程度决定物体渲染的资源分配,降低非重要物体的面数和细节度,从而获得高效率的渲染运算。缺点是增加了内存,并且需要模型师为我们多提供一套模型。

    以下是官方文档:

    Level of Detail

    多层次细节

    When an object in the scene is a long way from the camera, the amount of detail that can be seen on it is greatly reduced. However, the same number of triangles will be used to render the object, even though the detail will not be noticed. An optimisation technique called 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.

    In Unity, you use the LOD Group component to set up LOD rendering for an object. Full details are given on the component reference page but the images below show how the LOD level used to render an object changes with its distance from camera. The first shows LOD level 0 (the most detailed). Note the large number of small triangles in the mesh:

    LOD0

    The second shows a lower level being used when the object is farther away. Note that the mesh has been reduced in detail (smaller number of larger triangles):

    LOD1

    Since the arrangement of LOD levels depends somewhat on the target platform and available rendering performance, Unity lets you set maximum LOD levels and a LOD bias preference (ie, whether to favour higher or lower LOD levels at threshold distances) in the Quality Settings.

    接下来我们来做一个简单的LOD例子.
    由于没有粗模, 中模, 和 精模的模型, 我们暂时用简单的模型进行代替. 
    
    1. 创建工程, 保存场景,拖入David(精模)的模型(你可以随便找个模型)
    2. 创建两个3D物体Capsule(中模)和Sphere(粗模)作为David的子物体
    3. 给David添加LOD Group组件.
    4. Inspector面板配置LOD Group的属性. 点击LOD0, 添加精模; 点击LOD1, 添加中模; 点击LOD2, 添加粗模.
    5. 运行游戏, 拖动摄像机,观察Game和Scene视图的变化如图所示. 建议你们结合Unity Profiler分析器窗口去分析内存和渲染值变化.
    Game视图
    如果觉得本文对你有所帮助, 欢迎添加喜欢.
    如需转载,请标明出处.
    

    相关文章

      网友评论

          本文标题:Unity性能优化技术(一)--LOD技术

          本文链接:https://www.haomeiwen.com/subject/gprfzttx.html