三分钟了解LOD在游戏里面的运用 性能优化

http://www.narkii.com/club/thread-321290-1.html

LOD为Levels of Detail的简称,简单来说即为多细节层次,不少朋友经常听到这个名称,但是并不知道如何把这个技术运用在游戏里面,如果用百度查到的说法是:LOD技术指根据物体模型的节点在显示环境中所处的位置和重要度,决定物体渲染的资源分配,降低非重要物体的面数和细节度,从而获得高效率的渲染运算。

以上的解释可能很多人看了是一头雾水,还是不了解LOD的实际运用,以下让我们通过一个简单的案例来说明LOD的巧妙之处。

我们使用了3dsmax来说明LOD模型的制作,下载附件后打开场景文件,里面是三个面数不同的油桶造型,由左到右分别代表了高模,一般与低模的模型结构。

1.png 


选择左边的油桶模型,如图所示,这个模型的数据为三角面712,顶点数358。

2.png 


选择右边的模型,这个低模的数据很符合我们的要求,一般来说,用三个模型来制作LOD的效果就很足够了,例如建筑场景里面,最远端的房子只能看到类似盒子的效果,而镜头前面的楼房则是可以清楚的看到里面的许多细节,但是镜头推进到远处的楼房时,原来的盒子立即换成另一个可以战胜细节的模型,这个就是LOD的运作原理。

3.png 


将模型保存为FBX后,导入Unity进行测试,命名的方式建议是在物件的后面加上LOD的层级代号,这样比较方便我们直接用名称来选择高模与低模。

4.png 


在制作LOD之前,我们需要注意一个事情,那就是将不同面数的模型放在同一个位置,否则会发生模型位置错乱的情况,如图所示,使用Reset方式将中间的模型与低模移到与高模相同的位置。

5.png 
6.png 


接着建立一个空的Game Object,将其命名为prop_Barrell,我们准备用在这个空组件上面添加LOD的属性。

7.png 


选择Component > Rendering > LODGroup,然后就可以对LOD开始进行设置的工作。

8.png 


在LODGroup的设置里面列出了LOD的层级,底下的Add用来添加LOD所对应的模型,操作方法是先选择LOD : 0,按下Add,选择场景里面的prop_barell_LOD0模型。

9.png 


系统弹出一个提示,询问是否将这个选择的模型设置子物体,选择Yes,Reparent即可。

10.png 


如图所示,在选择Reparent后,LOD0的模型自动的设置为prop_Barell的子物件。

11.png 


设置完成LOD:0的层级后,选择LOD:1,按下Add,选择场景内的prop_barell_LOD1,接着选择LOD:2,按下Add,选择prop_barell_LOD2后即可完成整个LOD的设置。

12.png 


现在滑动LODGroup上方的相机图标来测试LOD的效果,模型在近处时使用的是LOD0所设置的高模,移到LOD1时则是显示为一般进度的模型,而在LOD3的层级时,模型就换为低模,移到最后的Culled插件,模型已经完全的消失了。

13.png 
14.png 
15.png 


此外,我们还可以任意的修改每一个层级的作用范围,只要拖动LOD分隔的线段即可,然后再根据相机的预览来调整出最合适的LOD效果。

16.png 

Unity的资源商店也提供了功能更为强大的LOD设置插件,以下为试用版的位置,如果是用于商业项目,请支持正版。

Smart LOD 1.0 - 大场景的优化神器
http://www.narkii.com/club/thread-320869-1.html



http://www.cnblogs.com/snake-hand/p/3149488.html

今天下了一个4.0破解版,然后看到一个Demo Level of Detail    就研究了一下  以前用的是Unity3.5 free版本,没有这个功能,真实泪奔。。。。。。。

 

As your scenes get larger, performance becomes a bigger consideration. One of the ways to manage this is to have meshes with different levels of detail depending on how far the camera is from the object. This is called Level of Detail (abbreviated asLOD)

由于场景变大,就要更加考虑性能的问题。有一种管理方法,取决于摄像机离对象的远近,网格有不同的细节级别,这就是所谓的细节级别( Level of Detail)(LOD的缩写)

Here's one of the ways to set up an object with different LODs.

下面是建立具有不同LODs对象的方法。

  1. Create an empty Game Object in the scene 
    在场景创建一个空的游戏物体。
  2. Create 2 versions of the mesh, a high-res mesh (for LOD:0, when camera is the closest), and a low-res mesh (forLOD:1, when camera is further away) 
    创建2个版本的网格,高清晰度网格(L0D:0,当摄像机最接近时),和一个低分辨率网格(L0D:1,当摄像机较远)
  3. Add a LODGroup component to this object (Component->Rendering->LOD Group)
    给这个对象添加LODGroup 组件(Component->Rendering->LOD Group
  4. Drag in the object with the high-res mesh onto the first Renderers box forLOD:0. Say yes to the "Reparent game objects?" dialog 
    把高分辨率网格的对象拖到的第一个渲染器框 L0D:0。对话框"Reparent game objects?" 按下yes按钮
  5. Drag in the object with the low-res mesh onto the first Renderers box forLOD:1. Say yes to the "Reparent game objects?" dialog 
    把低分辨率网格的对象拖到的第二个渲染器框 L0D:1。对话框"Reparent game objects?" 按下yes按钮
  6. Right Click on LOD:2 and remove it. 
    在LOD:2上右键单击并删除它。

At this point the empty object should contain both versions of the mesh, and "know" which mesh to show depending on how far away the camera is.

此时,空对象应包含两个版本的网格,"知道"网格取决于相机远离程度显示不同的版本。

You can preview the effect of this, by dragging the camera icon left and right in the window for theLODGroup component.

您可以预览这个效果,通过拖拽摄像机图标到LODGroup组件窗口(的LOD:0,LOD:1的矩形框)。

LOD 0

camera at LOD 0(在LOD 0时的摄像机)

LOD 1

camera at LOD 1(在LOD 1时的摄像机)

In the Scene View, you should be able to see

在场景视图,你应该能够看到:

  • Percentage of the view this object occupies 
    这个对象占用视图的百分比
  • What LOD is currently being displayed 
    当前显示的是哪个LOD
  • The number of triangles 
    三角形的数量

LOD-based naming conventions in the asset import pipeline
在资产的导入管线基于LOD的命名约定

In order to simplify setup of LODs, Unity has a naming convention for models that are being imported.

为了简化LOD设置,Unity在模型导入时有一个命名约定。

Simply create your meshes in your modelling tool with names ending with _LOD0, _LOD1, _LOD2, etc., and the LOD group with appropriate settings will be created for you.

简单地创建你网格,名称后缀为_LOD0,_LOD1,_LOD2等,会为你创建LOD组,并作出相应的设置。

Note that the convention assumes that the LOD 0 is the highest resolution model.

请注意,该约定假定最高分辨率的网格的LOD后面的数字是最小的。

Setting up LODs for different platforms
对于不同的平台设置LOD

You can tweak your LOD settings for each platform in Quality Settings, in particular the properties of LOD bias and Maximum LOD Level.

质量设置你可以为每个平台条件LOD设置,特别是LOD偏移和最大LOD层次。

Utilities 实用工具

Here are some options that help you work with LODs

下面是一些选项,可有助于你更好的使用LOD工作。

 


Recalculate Bounds
重新计算边界
If there is new geometry added to the LODGroup, that is not reflected in the bounding volume, press this to update the bounds. One example where this is needed is when one of the geometries is part of aprefab, and new geometry is added to that prefab. Geometry added directly to the LODGroup will automatically updates the bounds
如果有新的几何体添加到LODGroup,未被映射到边界体内,按这个按钮来更新边界。一个例子,当几何体之一是prefab的一部分,以及新的几何体被添加到这个prefab。几何体直接添加到LODGroup将自动更新边界。

Update Lightmaps
更新光照贴图
Updates the Scale in Lightmap property in the lightmaps based on the LOD level boundaries.
更新光照贴图基于LOD层次边界光照贴图属性比例。
Upload to Importer
上传给导入器
Uploads the LOD level boundaries to the importer
上传LOD层次边界给导入器





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值