Uniy3D优化之Optimizing Graphics Performance (一)

Optimizing Graphics Performance 优化图形性能

Desktop 桌面游戏

 

Good performance is critical to the success of many games. Below are some simple guidelines for maximizing the speed of your game's graphical rendering.

良好的性能是许多游戏的成功的关键。下面是一些简单的指导,可以用来帮助您最大化你的游戏图形渲染速度。

 

Optimizing Meshes 优化网格

You only pay a rendering cost for objects that have aMesh Renderer attached and are within the view frustum. There is no rendering cost from emptyGameObjects in the scene or from objects that are out of the view of any camera.

您仅仅只需要渲染视域体内含有Mesh Renderer的物体,而对于空的或者视域体外的游戏物体则不需要进行渲染。

 

Modern graphics cards are really good at handling a lot of polygons but there is a significant overhead for each batch (ie, mesh) that you submit to the graphics card. So if you have a 100-triangle object it is going to be just as expensive to render as a 1500-triangle object. The "sweet spot" for optimal rendering performance is somewhere around 1500-4000 triangles per mesh.

现代的图形卡已经非常擅长处理大量的多边形渲染,但在每次将每批几何数据(网格)提交给图形卡时却要花费很大的开销。即便你只渲染一个只有100个三角形的物体,它的开销也和渲染一个1500个三角形面片的物体的开销是一样的。因此,最优的渲染性能的"平衡点"是每次渲染1500-4000三角形网格。

 

Usually, the best way to improve rendering performance is to combine objects together so that each mesh has around 1500 or more triangles and uses only oneMaterial for the entire mesh. It is important to understand that combining two objects which don't share a material does not give you any performance increase at all. The most common reason for having multiple materials is that two meshes don't share the same textures, so to optimize rendering performance, you should ensure that any objects you combine share the same textures.

通常情况下,提高渲染性能的最佳途径是将物体组合一起,使每个网格大概拥有大约 1500个三角形面片,并且整个网格只使用一种材质。值得注意的一点是,您需要了解将拥有不同材质的两个物体拼合在一起并不会给您带来任何的性能提升。最常见的原因两个网格所用的材质并不共享相同的纹理,所以要优化渲染性能,您至少应该确保您所组合的任何物体共享相同的纹理。

 

However, when using many pixel lights in theForward rendering path, there are situations where combining objects may not make sense, as explained below.

但是,在Forward rendering path的渲染方式下,如果每个像素使用多个光源,那么可能会出现拼合物体不起作用的情况,我们将在下面对其进行解释。

 

Pixel Lights in the Forward Rendering Path 前向渲染路径的像素光源

Note: this applies only to theForward rendering path.

If you use pixel lighting then each mesh has to be rendered as many times as there are pixel lights illuminating it. If you combine two meshes that are very far apart, it will increase the effective size of the combined object. All pixel lights that illuminate any part of this combined object will be taken into account during rendering, so the number of rendering passes that need to be made could be increased. Generally, the number of passes that must be made to render the combined object is the sum of the number of passes for each of the separate objects, and so nothing is gained by combining. For this reason, you should not combine meshes that are far enough apart to be affected by different sets of pixel lights.

如果您使用像素光照,那么每个网格将会渲染多遍,渲染次数是根据每个像素的光源个数来决定的。如果两个相距很远的网格进行合并,它将会增加合并物体的有效大小。因此,任何可以找到该物体的像素光源都将在渲染过程中进行计算,这势必会增加整个渲染的pass。一般情况下,拼合物体的渲染pass总数将是各个物体所需要的渲染pass的综合,这样一来,拼合这些物体显然没有任何的好处。出于以上原因,您不应该组合距离较远的、受到不同的像素光照影响的物体。

 

During rendering, Unity finds all lights surrounding a mesh and calculates which of those lights affect it most. TheQuality Settings are used to modify how many of the lights end up as pixel lights and how many as vertex lights. Each light calculates its importance based on how far away it is from the mesh and how intense its illumination is. Furthermore, some lights are more important than others purely from the game context. For this reason, every light has aRender Mode setting which can be set toImportant orNot Important; lights marked as Not Important will typically have a lower rendering overhead.

在渲染过程中,Unity会查找一个网格周边的所有光源,并计算最影响这些光线的。质量设置(Quality Settings)是用来修改多少光源将最终会作为像素光源和多少光源将作为顶点光源。每个光源的重要性计算是基于它距离物体的远近以及它自身的亮度强弱。此外,一些光源的重要性与否需要根据游戏内容而定,因此,每个光源都有一个渲染模式(Render Mode)设置,来制定其是重要还是不重要的;被标记为不重要的光源通常会被设定为较低的渲染开销。

 

As an example, consider a driving game where the player's car is driving in the dark with headlights switched on. The headlights are likely to be the most visually significant light sources in the game, so their Render Mode would probably be set to Important. On the other hand, there may be other lights in the game that are less important (other cars' rear lights, say) and which don't improve the visual effect much by being pixel lights. The Render Mode for such lights can safely be set to Not Important so as to avoid wasting rendering capacity in places where it will give little benefit.

比如,我们以一个赛车游戏为例,选手的车打开车前疼在黑暗中行驶。车前灯应该算是游戏中最为显著的

光源,所以它们的渲染模式应该被设定为重要(Important)。同时,游戏中很可能存在一些不重要的光源(比如其他车的车尾灯)。对于这些光源,其绘制模式可以被设定为不重要(Not Important),以此来避免渲染方面的开销,从而达到更良好的运行性能。

 

Per-Layer Cull Distances 每层裁剪距离

In some games, it may be appropriate to cull small objects more aggressively than large ones in order to reduce number of draw calls. For example, small rocks and debris could be made invisible at long distances while large buildings would still be visible. To accomplish this culling, you can put small objects into aseparate layer and setup per-layer cull distances using theCamera.layerCullDistances script function.

在某些游戏中,通过裁剪小物体来减少绘制调用的数量可能比裁剪大物体达到更好的效果。例如,小块岩石和碎片在距离较远时可以设为不可见,而大型建筑物仍然可见。为了完成这样的裁剪,可以将小物体放入单独的图层和并使用Camera.layerCullDistances脚本来对每层物体进行不同的视域裁剪距离。

 

 

Shadows 阴影

If you are deploying for Desktop platforms then you should be careful when using shadows because they can add a lot of rendering overhead to your game if not used correctly. For further details, see theShadows page.

如果您要在桌面平台上进行发布,那么您应谨慎地使用阴影,因为如果没有正确地使用它们,可能会将很多不必要的渲染开销添加到您的游戏中。有关进一步的详细信息,情况阴影部分(以后翻译)

 

Note: Shadows are not currently supported on iOS or Android devices.

注意:目前阴影功能暂不支持iOS和Android设备。

 

备注:最近一直在研究Unity3D的性能优化问题,这段时间可能会多翻译这方面的文章,如有翻译不当之处还请多多指出。

原文地址:http://unity3d.com/support/documentation/Manual/Optimizing%20Graphics%20Performance.html#iPhoneOptimizingGraphicsPerformance

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值