본문 바로가기
Works/Unity 3D

[Unity] 최적화에 관한 정보들

by Vader87 2020. 5. 6.
반응형

Unity Several optimization recommendations

불러오는 중입니다...

 


The simplest recommendations for optimization:

1.PC platform Words keep the number of vertices displayed in the scene less than 200k~3m, and mobile devices less than 10W, all depending on your target GPU and CPU.
2. If you are using U3d's own shader, select the mobile or unlit directory in the case of poor performance. They are more efficient.
3. Share the material as much as possible.
4. Set the object that does not need to be moved to static so that the engine can perform its batch processing.
5. Do not use light as much as possible.
6. The dynamic light is much less.
7. Try compressing the map format, or replace 32 bits with 16 bits.
8. If you do not need to use fog effect (fog)
9. It is very useful to try to use Occlusionculling to block multiple objects in the hallway of a room. If inappropriate, it will increase the burden.
10. Use the Sky box to "Fade Away" objects in the distance.
11.shader uses map blending to replace multi-channel computing.
Note the use of float/half/fixed in 12.shader.
Do not use complex computational pow,sin,cos,tan,log, etc. in 13.shader.
The less fragment 14.shader, the better.
15. Note that there is no extra animation script, the model automatically imported into the U3D will have animated script, a large number of words will seriously affect the consumption of CPU computing.
16. Notice the collision layer of the collision body, the unnecessary collision detection please.


1. Why you need to optimize for CPU (central processing unit) and GPU (graphics processor).

CPU and GPU have their own compute and transmission bottlenecks, different CPUs or GPUs they are not the same, so your game needs to be developed for the CPU and GPU capabilities of your target users.


2.CPU vs. GPU Limitations

The GPU typically has a fill rate (fillrate) and memory bandwidth (Bandwidth) limit, and if your game is much faster in low-quality performance, you probably need to limit your GPU fill rate.

The CPU is generally limited by the number of objects to be rendered, and the CPU sends the rendered object to the GPU command called Drawcalls. Generally speaking, the number of drawcalls need to be controlled, the less the better the performance of the premise. Generally speaking, the computer platform on the Drawcalls thousands of, mobile platform drawcalls within hundreds of. That's almost it. Of course, the above is not absolute, only for a reference.

Often rendering (Rendering) is not a problem, both on the GPU and on the CPU. It's probably the problem with your scripting code efficiency, look under profiler.

About Profiler Introduction: http://docs.unity3d.com/Documentation/Manual/Profiler.html

It is important to note that:
The rendertexture.setactive () occupancy rate shown in the GPU is high because you opened the edit window at the same time, not the u3d bug.

3. About vertex count and vertex calculation

CPU and GPU have a lot of computational processing for vertices. The number of vertices rendered in the GPU depends on the complexity of GPU performance and shader, and in general, within millions of vertices on the PC, no more than 100,000 vertices on the mobile platform per frame.

Calculations in the CPU are mainly in the skin skeleton calculation, cloth simulation, vertex animation, particle simulation and so on. GPU is a variety of vertex transformations, lighting, map blending and so on.

"Personally, I think you should look at your project needs, assuming you are 3d games. Your game needs to be compatible with low-configuration hardware, smooth operation, control hardware fever, but also to achieve a certain effect (lightmap+ fog effect), then the number of vertices must not be high. At this time the 2W vertex of the same screen I think is a more appropriate number, drawcall preferably less than 70. Another, control the heat please control the maximum frame rate, smooth words, the frame rate actually does not need too high. 



4. CPU-optimized-reduces the number of draw call

In order to render objects to the display, the CPU needs to do some work, such as distinguishing which objects need to be rendered, whether they are affected by the light, which shader to use and the shader, sending the drawing commands to the display driver, and then sending commands to tell the video card to delete.

Suppose you have a model on the Qian San corner that uses thousands of triangular models instead of the same GPU, but on the CPU it is very different and consumes much more. To make the CPU less work, you need to reduce the number of visible objects:

A. Merge similar models, manually merge in the Model Editor or use Unity's draw call batch to achieve the same effect (draw call batching). Specific methods and considerations see the following links:

Draw Call batching:http://docs.unity3d.com/documentation/manual/drawcallbatching.html


B. Use fewer materials (material) in the project, and combine several separate maps into a larger atlas.

If you need a script to control individual material properties, be aware that changing the renderer.material will result in a copy of the material. Therefore, you should use Renderer.sharedmaterial to guarantee the shared state of the material.

There is a merge model material good plug-in called Mesh Baker, you can consider the test.

C. Use as few rendering steps as possible, such as Reflections,shadows,per-pixel light.

D.draw call Batching's merged objects will make each object (the merged object) have at least hundreds of triangular faces.

Assuming that the merged two objects (manually merged) but do not share the material, there is no performance improvement. A multi-material object is equivalent to two objects without a decal. So, in order to improve the performance of the CPU, you should make sure that these objects use the same stickers.

In addition, the light will cancel the (break) engine's draw call BATCH, as for why, check the following:

Forward Rendering Path Details:
Http://docs.unity3d.com/Documentation/Components/RenderTech-ForwardRendering.html

E. The number of draw call is directly reduced using the associated culling quantity, as mentioned below.


5. Optimizing the Geometry model

The most basic two optimization criteria:
A. Do not have unnecessary triangular faces.
The fewer seams and hard edges in the B.uv map, the better.

It is important to note that the graphics hardware needs to handle the number of vertices and is not the same as the hardware reports. Not the hardware that can render several points is a few points. The model processing application pass shows the number of geometric vertices. For example, a model consisting of a number of different vertices. In the video card, some of the collection vertices will be separated (split) into two or more logical vertices for rendering. If there are normals, UV coordinates, vertex colors, this vertex must be detached. So the actual amount of processing in the game is obviously much more.


6. About Illumination

It must be the quickest if you don't run out of light. Mobile optimization can use a light map (lightmapping) to bake a static map, in lieu of each light calculation, in the u3d only a very short time can be generated. This method can greatly improve the efficiency, and has better performance (smooth transition processing, as well as additional shadows, etc.).

Try not to use true light in your scene on a mobile device or on a low-end computer, using a light map. This method greatly saves CPU and GPU compute, and the CPU gets less DRAWCALL,GPU and requires less vertex processing and pixel rasterization.

Lightmapping:http://docs.unity3d.com/documentation/manual/lightmapping.html


7. GPU Optimization--image compression and multiple texture formats

Compressed textures (image compression):

Http://docs.unity3d.com/Documentation/Components/class-Texture2D.html

Picture compression reduces the size of your pictures (faster loading of smaller memory spans (footprint)) and greatly improves rendering performance. Compressing a map consumes much less memory bandwidth than an uncompressed 32-bit RGBA map.

Before the U3d meeting also heard of an optimization, map as far as possible in a size format (512 * 512, 1024 * 1024), so that in memory can be better sorted, and there is no gap between the memory. Whether this is true or false has not been tested.

MIPMAps (multi-texture format):

Http://docs.unity3d.com/Documentation/Components/class-Texture2D.html

As with the thumbnails on the Web page, in 3D games we generate multiple texture maps for the game's textures, showing smaller objects in the distance with small stickers that show larger objects with fine textures. This makes it much more efficient to reduce the data that is transmitted to the GPU.


8.LOD, Per-layer cull distances, occlusion culling

LOD (level of Detail) is a very popular 3D game technology, and its function is equivalent to multi-texture mapping. The use of high or low-level models to reduce the transfer of data to the GPU and to reduce the vertex calculations required by the GPU is judged by the scale of the model size shown in the screen.

Camera layering distance culling (per-layer cull distances): Identifies the level of a small object and then determines whether it needs to be displayed based on its distance from the main camera.

Occlusion culling (occlusion culling) is the fact that when an object is completely blocked by another object in front of the camera, blocking is not sent to GPU rendering, which directly lowers draw call. However, sometimes it is computationally expensive to calculate whether or not it is blocked in the CPU, but it is not worth the candle.

The following are the relevant uses and descriptions of these optimization techniques:

Level of Detail:
Http://docs.unity3d.com/Documentation/Manual/LevelOfDetail.html

Per-layer Cull distances:
Http://docs.unity3d.com/Documentation/ScriptReference/Camera-layerCullDistances.html

Occlusion Culling:
Http://docs.unity3d.com/Documentation/Manual/OcclusionCulling.html


9. About Realtime Shadows (Live Shadow)

Real-time shadow technology is great, but consumes a lot of computation. For both the GPU and CPU are expensive burdens, the details are referenced below:

Http://docs.unity3d.com/Documentation/Manual/Shadows.html


10. GPU-Optimized: efficient shader

A. It is important to note that some (built-in) shader are mobile versions, which greatly improve the performance of vertex processing. There are, of course, some limitations.

B. Write your own shader note that complex operator calculations, such as Pow,exp,log,cos,sin,tan, are time-consuming calculations, at most once at each pixel point. It is not recommended to write your own normalize,dot,inversesqart operator, the built-in must be better than yours.

C. The need for vigilance is Alpha test, which is time consuming.

D. Floating-point type operation: The lower the precision, the faster the floating-point calculation.

In the CG/HLSL--

FLOAT:32-bit floating-point format, suitable for vertex transformation operations, but slower.
The half:16-bit floating-point format, suitable for mapping and UV coordinate calculations, is twice times the HIGHP type calculation.
Fixed:10 bit floating-point format, suitable for color, illumination, and others. Is four times times the HIGHP format calculation.

Tips for writing shader optimizations:
Http://docs.unity3d.com/Documentation/Components/SL-ShaderPerformance.html

11. Additional Related optimizations:

A. Optimization of the draw call batching
Http://docs.unity3d.com/Documentation/Manual/DrawCallBatching.html

B. Instructions and tips for rendering Statistics window:

 

유니티랑은 상관 없을 것 같지만 알고 있으면 유용할 것 같은 정보들

안드로이드에서의 비트맵과 메모리의 상관관계

 

안드로이드에서의 비트맵과 메모리의 상관관계

사실 이 글을 처음 접했을땐 서문에 “API 버전에 따른 비트맵 사용시 메모리 관리의 차이”라는 부분을 읽고 안드로이드 2.3.3(API level 10)기준 전후 버전의 메모리 모델 변경에 따른 recycle() 필요 유무에 대한 이야기이겠거니 생각했습니다. 이러한 내용은 구글 개발자 사이트의 Managing Bitmap Memory 에 설명되어 있는…

medium.com

Android 앱 메모리 최적화

불러오는 중입니다...

 

반응형

'Works > Unity 3D' 카테고리의 다른 글

[Unity] Playables API  (0) 2020.09.22
[Unity] OpenUPM 사용법  (0) 2020.05.30
[Unity3D] RenderTexture RawImage 출력 이슈  (1) 2020.02.13
[Unity3D] Image Prefab 과 Memory  (0) 2020.01.07
[Unity3D] Script Templates 사용하기  (0) 2019.09.19

댓글