Rendering Optimization Technology in Unity3D

Factors Affecting Performance

CPU

Too many draw calls

Complex scripts or physics simulations

GPU

1. Vertex Processing

too many vertices

Excessive per-vertex calculations

2. Fragment processing

Too many fragments (either due to resolution or overdraw).

Excessive fragment-by-fragment calculations

bandwidth

Large uncompressed textures are used

High resolution framebuffer

Optimization technology

CPU optimization

Use batching techniques to reduce the number of draw calls

Whether it is dynamic batching or static batching, the same material needs to be shared between models.

1. Dynamic batch processing

Conditions for dynamic batch processing: the vertex attribute scale of meshes capable of dynamic batch processing should be less than 900;

In general, all objects need to use the same scale; an exception is that if all objects use different non-uniform scales, they can also be dynamically batched. But in Unity5, this limitation of model scaling no longer exists;

Objects that use lightmaps need to be handled with care. Make sure they point to the same location in the light texture;

Shaders with multiple passes will interrupt batch processing.

2. Static batch processing

For static batch processing, its advantage is that it has a high degree of freedom and few restrictions; but the disadvantage is that it may take up more memory, and all objects after static batch processing cannot be moved.


GPU optimized

Reduce the number of vertices that need to be processed

1. Optimize the geometry

2. Use the LOD (Level of Detail) technology of the model

3. Use Occlusion Culling

Reduce the number of fragments that need to be processed

1. Control the drawing order

2. Be wary of transparent objects

3. Reduce real-time lighting and shadows

Reduce computational complexity

1. Use Shader's LOD (Level of Detail) technology

2. Code optimization

a. Generally speaking, the number of objects, vertices and pixels that the game needs to calculate is the number of objects < number of vertices < number of pixels. Therefore, we should try to put computation on a per-object or per-vertex basis as much as possible.

b. Use low-precision floating-point values ​​for operations as much as possible. float/highp is suitable for storing variables such as vertex coordinates, while half/mediump is suitable for some scalars, texture coordinates and other variables, and fixed/lowp is suitable for most color variables and normalized direction vectors. For low-level calculations, we should try to use variables of this precision.

c. For the vast majority of GPUs, we should use as few interpolation variables as possible when using interpolation registers to pass data from the vertex shader to the next stage.

d. Try not to use full-screen post-processing effects.

e. Avoid using branch and loop statements as much as possible.

f. Avoid using complex mathematical operations like sin, tan, pow, log, etc. as much as possible. We can use a lookup table instead.

g. Do not use the discard operation as much as possible, because this will affect some optimizations of the hardware.

h. Try to avoid conversion between different precisions, which may cause some performance degradation.

Save memory bandwidth

1. Reduce texture size

a. The aspect ratio of all textures is preferably square, and the aspect ratio is preferably an integer power of 2

b. Use multi-level fading texture technology (mipmapping)

c. Texture compression

2. Take advantage of resolution scaling

Guess you like

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