[Unity3D basics] - Stats window

Stats window##

The Stats window, the whole process is called Rendering Statistics Window, is the rendering data statistics window, which will statistics data in real time.

Stats

FPS(Time per frame andFPS)
Frames per seconds represents the time it takes the engine to process and render a game frame. This number is mainly affected by the number of rendered objects in the scene and GPU performance. The higher the FPS value, the smoother and smoother the animation of the game scene will be.
Generally speaking, the human eye will not feel the card when the screen exceeds 30FPS , and it has the characteristics of visual residual. After the light stops on the retina, the human eye will remain for about 1/24 second, so the number of frames per second of the game screen is at least 1/24 seconds. Make sure it's above 30 . In addition, the FPS
value in Unity only includes the frames updated and rendered in this game 's Scene , not the progress of the edited Scene and other monitoring windows in the editor.

CPU
Get the absolute value of the time currently occupied by the CPU for calculation, or the time point. If the Unity main process is in the hang-up or sleep state, the CPU time will remain unchanged.

Render thread
The time spent by the GPU rendering process to process the image, the specific value is determined by the GPU performance.

Batches, Batched Draw Calls, is the Draw Call Batching technology built into Unity.
Generally speaking, each time the engine performs a DrawCall on an object , it will generate a Batch , which contains all the mesh and vertex data of the object. When rendering another identical object, the engine will directly call the batch in the batch . information, and send the relevant vertex data directly to the GPU , so that the rendering process is more efficient, that is, the Batching technology is to combine and render all objects with similar materials.

For objects with multiple different Shaders and Materials , the rendering process is time-consuming because multiple Batches are generated. Every time you modify the material or texture of an object, it will affect the composition of the dataset in Batches . Therefore, if there are a large number of objects with different materials in the scene, it will obviously affect the rendering efficiency of the GPU . Solutions related to Batches optimization:

1. Although the Unity engine comes with the Draw Call Batching technology, we can also manually merge objects with close materials;
2. Try not to modify the Scale of objects in Batches , because this will generate a new Batch.
3. In order to improve the rendering efficiency of the GPU , as few materials as possible should be used on an object to reduce the excessive overhead of Batches .
4. For objects that do not move in the scene, consider setting the Static property. The objects declared by Static will automatically perform internal batch optimization.

SetPass calls
In Unity4.x and 3.x, the first item of the original Stats panel is "Draw calls", but in Unity5.X version, there is no "Draw calls" on Stats, but there is one more item "SetPass calls".

For example, if there are 100 gameObjects in the scene , they have exactly the same Material , then these 100 objects are likely to be combined into a Batch by the Batching mechanism in Unity . So using "Batchs" to describe Unity 's rendering performance is not appropriate, it can only reflect the number of objects that need to be batched in the scene. So can we use "Draw calls" to describe it? The answer is also not suitable. Each "Draw calls" is a rendering request sent by the CPU to the GPU . The request includes all the vertex parameters, triangular faces, index values, number of primitives, etc. of the rendering object. This request does not occupy too many trumpets. What really consumes the rendering resources is that after the GPU gets the request instruction, it sends the instruction to the Shader of the corresponding object, so that the Shader reads the instruction and notifies the corresponding rendering pass (Pass) to perform the rendering operation. Suppose there is a gameObject in the scene , hoping to display cool effects, its Material

There are many specific Shaders on it . In order to achieve the corresponding effect, the Shader may contain a lot of Passes . Whenever the GPU is about to run a Pass , a "SetPass call" will be generated . Therefore, "SetPass calls" are more convincing in describing the rendering performance overhead. .


Batches and DrawCall are important indicators for drawing images and can be used as the primary reference to measure the efficiency of scene drawing.
A Draw Call , and so on with a call to DrawlndexedPrimitive(DX) or glDrawElements(OGL) , is equal to a Batch. NVIDIA once proposed
at GDC that the rendering amount of 25k batch/sec will make the 1GHz CPU reach 100 % utilization , so use the formula:
25K∗n(GHZ)∗Percentage/Framerate=Batch/Frame

可以推算出某些 CPU 可以抗多少 Batch。例如红米手机 CPU 为 1.5Hz, 假设分出 20% 资源供渲染,希望游戏跑到 30 帧 。那么能抗多少 DrawCall ? 25k * 1.5 * 0.2 / 30 = 250。 因此从这方面也能看出,如果 CPU 不能分出更多的资源供渲染计算,能抗的 D人awCall 就会变少。
在 Stats 面板中看到的 Batches 是渲染的总 Batch 这个值等于同于 DrawCall。 但 Unity 中可以获取到末批次处理之前的 DrawCall。 因此需要注意不要混淆感念。


Saved By Batching :
这个值是由于 Batch 减少的 DrawCall, 可以间接的看到场景优化的效果。这个值有两部分组成: Static BatchingDynamic Batching
这个由 Unity 内建自动合并虽然优点多多,但也不是没有缺陷。静态合并会引发内存和存储的额外开销,动态合并会增加 CPU 的负担。 这部分内容参考 Unity 官方文档
总体上讲所以希望批次渲染的元素要有相同的材质。通常两个材质如果只有贴图不同,可以将贴图合并到一张大图中,这就是所谓的和图。另外在使用 ShadowCaster 时,只要材质相同,即使贴图不同也可以合并渲染。
Dynamic Batches

动态合并在满足以下条件时时自动完成的额:

  • 模型总顶点数小于 900。
  • 不包含镜像 transform 改变。 不改变 Scale。
  • 如果使用动态 lightmap 需要指定正确。
  • 不使用多 Pass 的 Shader。

由于需要在合并时通过 CPU 计算转为世界坐标,这项技术只在 CPU 消耗比 DrawCall 消耗“便宜”时才值得。这个衡量标准会根据平台产生差异,例如苹果平台上 DrawCAll的消耗便宜,就不应该使用这项技术。这个功能可以在 Editor–> Project Setting –>Player 中进行设置打开与关闭。



Static Batches
场景中不能移动的物件可以使用静态合并,它不受顶点数的限制,可以大幅较少 DrawCall。 但为了将元素合并到一个大模型中,这项技术需要额外的内存。主要的内存消耗在于共享多边形会在内存中重复创建。因此有时候需要牺牲渲染效率来避免静态合并,来保证内存够小。例如在茂密的树林中使用这项技术会导致大量的内存消耗。

Verts
摄像机视野(field of view)内渲染的顶点数。
Tis
摄像机视野(field of view)内渲染的三角面总数量。

关于 Tris 和 Verts

1、 Camera 的渲染性能受到 Draw calls 的影响。之前说过,对一个物体进行渲染,会生成相应的 Draw call,处理一个 Draw Call 的时间是由它上边的 TrisCerts 数目决定。尽可能得合并物体,会很大程度的提高性能。举个很简单例子,比如场景一种有 1000 个不同的物体,每个物体都有 10 个 Tris; 场景二中有 10 个不同的物体,每个物体有 1000Tris 。 在渲染处理中,场景一中会产生 1000Draw Calls,它的渲染时间明显比场景二慢。

2、Unity stats 视图中的 TrisVerts 并不仅仅是视锥中的梯形内的 TrisVerts,而是 Camerafield of view 所有取值下的 trisverts,换句话说,哪怕你在当前 game 视图中看不到这个 cube, 如果当你把 field of view 调大到179 过程中都看不到这个 cubestats 面板才不会统计, GPU 才不会渲染,否则都会渲染,而且 unity 不会把模型拆分,这个模型哪怕只有 1 个顶点需要渲染, Unity 也会把整个模型都渲染出来。(参考自Mess的《Unity Camera组件部分参数详解》)

3、新建一个空的场景,里面没有添加任何物体,为什么 status 面板上显示有 1.7k Tris 以及 5.0k Verts 。这是因为空的场景自带默认的天空盒、Windows—>Lighting打开 Ligh下的 Scene 面板,把 Skybox 里的材质设为空。删掉它,就会发现 Tris 和 Verts 都会变为0了。

write picture description here

Scree
Get the resolution size of the current Game screen, the following value represents the total memory usage.


Shadow casters
Indicates how many objects in the scene that can cast shadows, generally these objects are used as light sources in the scene.

Visible skinned meshed
The number of skin meshes to render.

Animations
The number of animations being played.

The script gets the value.
In the edit mode, the data can be obtained through the script, but it is not very successful to type out the package. The code is as follows:

 GUILayout.TextField("Total DrawCall: " + UnityStats.drawCalls);
        GUILayout.TextField("Batch: " + UnityStats.batches);
        GUILayout.TextField("Static Batch DC: " + UnityStats.staticBatchedDrawCalls);
        GUILayout.TextField("Static Batch: " + UnityStats.staticBatches);
        GUILayout.TextField("DynamicBatch DC: " + UnityStats.dynamicBatchedDrawCalls);
        GUILayout.TextField("DynamicBatch: " + UnityStats.dynamicBatches);

        GUILayout.TextField("Tri: " + UnityStats.triangles);
        GUILayout.TextField("Ver: " + UnityStats.vertices);

Reference: http://blog.csdn.net/wdmzjzlym/article/details/51335915

http://blog.csdn.net/fansongy/article/details/51025325

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324965496&siteId=291194637