适用于Unity3D 5.x一下版本
Gpu和cpu直接权衡一下,找出瓶颈,如果缩小屏幕分辩率能提高速度,一般是瓶颈在gpu fillrate。Cpu的瓶颈一般在draw calls,蒙皮动画,布料,粒子等会比较费cpu时间。Gpu的优化,尽量减少顶点,并且减少贴图数量和大小并且让宽高为2的整数次幂。导入纹理时生成Mip Maps,会增加33%的内存使用,但是降低gpu压力。实时阴影对cpu和gpu都会造成较大压力。
综上所述,GPU和CPU的优化如下:
GPU相关: 缩小屏幕分辨率(减少GPU填充率),减少顶点,减少贴图数量和大小并且让宽高为2的整数次幂,导入纹理时生成Mip Maps,减少实时阴影。
CPU相关: 减少draw Calls,减少蒙皮动画,减少布料,粒子特效等,导入纹理时不生成Mip Mapsd但会增加GPU压力。
下面是渲染数据统计窗口的说明:
Fps的时间,仅仅是渲染这个游戏场景的世界,不包含在编辑器里的一些运算。
Draw calls渲染次数,像素光照,阴影,反射等会导致同一个物体调用多次draw calls。
Batching 渲染批次,合并渲染批次会提升性能。(公用材质的才可以合并)。Unity也会自动合并渲染批次。
Tris and Verts 三角形数,顶点数。顶点数量移动平台最好小于100k,PC不大于几兆。
Used Textures 绘制当前帧用到的纹理内存。
Render Textures 绘制纹理,纹理交换次数。
Screen屏幕大小和内存使用(与抗锯齿等级有关)。
VRAM usage 显存使用量(video memory)。
VBO total 显卡中不同网格顶点数Vertex Buffers Objects。
Visible Skinned Meshes 蒙皮网格数。
Animations 动画数。
Tips:
Unity自动合并的是900个顶点以下的网格。缩放不同的物体不会自动合并。材质不同的不合并。等比缩放的和不等比缩放的不合并,但是scale(1,2,1) 和 (1,3,1)的可以合并。使用光照贴图的不合并。Shader多个渲染通道的不合并。用预制件创建的比较容易合并。
静态合并批次性能更好,把游戏中不会移动缩放和旋转的物体标记为静态。但是静态合并会增加内存使用,需要权衡一下,比较密集的森林就不要把树标记为静态了。
下面是官方的文档说明,也可以一起用于参考。
The Game View has a Stats button in the top right corner. When the button is pressed, an overlay window is displayed which shows realtime rendering statistics, which are useful for optimizing performance. The exact statistics displayed vary according to the build target.
游戏视图(Game View)右上方状态(Stats )按钮。这个状态按钮按下时,显示一个重叠视窗与实时渲染统计数据。帮助优化你的游戏,这是非常有用的。统计数据取决于你的构建目标显示不同的内容。
Rendering Statistics Window. 渲染统计数据窗口
The Statistics window contains the following information:-
统计数据窗口包含以下信息:
-
Time per frame and FPS
每帧的时间和FPSThe amount of time taken to process and render one game frame (and its reciprocal, frames per second). Note that this number only includes the time taken to do the frame update and render the game view; it does not include the time taken in the editor to draw the scene view, inspector and other editor-only processing.
处理和渲染一个游戏框架(以及由此产生的FPS)的需要多少时间。请注意,这个数量只包括游戏视图更新和渲染的帧,不包括在编辑器中绘制场景视图,检视窗口和其他仅编辑器进程的时间。 -
Draw Calls
描绘调用The total number of meshes drawn after batching was applied. Note that where objects are rendered multiple times (for example, objects illuminated by pixel lights), each rendering results in a separate draw call.
批处理后网格绘制的总数。请注意其中有对象被多次渲染(例如,被像素灯光照亮的物体),每次渲染结果都会导致一个单独的描绘调用。 -
Batched (Draw Calls)
批处理(描绘调用)The number of initially separate draw calls that were added to batches. "Batching" is where the engine attempts to combine the rendering of multiple objects into one draw call in order to reduce CPU overhead. To ensure good batching, you should share materials between different objects as often as possible.
最初单独描绘调用被添加到批处理的数量。批处理是引擎试图结合多个物体渲染进行一次描绘调用,以降低CPU开销。为了确保良好的批处理,你应该尽可能多的在不同物体之间共享材质。 -
Tris and Verts 三角面与顶点数The number of triangles and vertices drawn. This is mostly important when optimizing for low-end hardware
绘制三角形和顶点的数目。为低端硬件的优化时(optimizing for low-end hardware),这多是重要的。 -
Used Textures 使用的纹理The number of textures used to draw this frame and their memory usage.
绘制该帧使用的纹理数和它们使用的内存。 -
Render Textures
渲染纹理The number of Render Textures and their memory usage. The number of times the active Render Texture was switched each frame is also displayed.
渲染纹理的数量和它们使用的内存。 Switches--每帧切换激活纹理的次数也显示。 -
Screen 屏幕The size of the screen, along with its anti-aliasing level and memory usage.
屏幕的大小,连同其抗锯齿级别和内存的使用率。 -
VRAM usage 显存使用Approximate bounds of current video memory (VRAM) usage. This also shows how much video memory your graphics card has.
当前显存(VRAM)的使用情况的大约范围,同时显示你的显卡有多少显存。 -
VBO total
顶点缓冲区对象总数The number of unique meshes (Vertex Buffers Objects or VBOs) that are uploaded to the graphics card. Each different model will cause a new VBO to be created. In some cases scaled objects will cause additional VBOs to be created. In the case of a static batching, several different objects can potentially share the same VBO.
上传到图形卡的唯一网格(顶点缓冲区)的数量。各种不同的模式,将导致要创建新的VBO。在某些情况下缩放对象会导致要创建额外的VBO。在静态批处理的情况下,然而对象数量可以共享相同的VBO。 -
Visible Skinned Meshes
可见蒙皮网格The number of skinned meshes rendered.
渲染蒙皮网格的数量。 -
Animations 动画The number of animations playing. 正在播放动画的数量。