Unity movement end performance optimization

1. Rendering

  • Using reflect probe instead of the reflection, refraction, try not RTT, GrabPass, RenderWithShader, CommandBuffer.Blit (BuiltinRenderTextureType.CurrentActive ...)
  • After establishing unitary frame (bloom, hdr, DOF, etc.) instead of the multi-post-treatment, the blur function can be shared, reducing the blit times; Also note that the size of the RTT.
  • Deflecting air, using heat distortions GrabPass not supported on all hardware, or to post treatment to optimize the RTT.
  • A unified shader shader instead of a single material, full use shader_feature, multi_compile, macro switch and display the interface.
  • Instead of mixing multi-channel texture image, shadow projections, shadow reception, MetaPass, forwardadd the like do not need to be removed when the pass.
  • Less alpha test, discard, clip, Alpha Converage the like, as it will affect the Early-Z Culling, HSR optimization.
  • Alpha Blend avoid penetration problems (weight mixing, peeling depth sorted by price is too transparent).
  • Instead of shading Lightmap dynamic, real-time as possible without light; shadow mapping, environment mapping using 16 instead of 32; use in place of the aperture projector + rtt or real-time shadows.
  • The environmental parameters (wind, rain, sun) and other global parameters unified shader management.
  • Non-lead may be used instead of PBR matcap, not have to use metal-free pbr, careful selection of the physical rendering FDG used (F: schlick, cook-torrance, lerp, less demanding with the fourth power, D: blinn-phong, beckmann, GGX, GGX Anisotropic, G: neumann, cook-torrance, Kelemen, SmithGGX; standard shader should be selected BRDF1-BRDF3), without rendering less demanding GGX; LH can be used to optimize the GGX.
  • Fixed with, half float in place, the establishment of a unified shader type (fixed float is four times the efficiency, half the float 2 times), careful selection of the modified shader variables (uniform, static, global), or Mobile Unlit selected directory shader
  • You may consider the use of open mipmap level with rendering, memory enough
  • Note the use of surface shader to turn off unused functions, such as: noshadow, noambient, novertexlights, nolightmap, nodynlightmap, nodirlightmap, nofog, nometa, noforwardadd etc.
  • Variants of standard shader too much (more than 30,000), resulting in longer compile time, memory footprint is impressive (close 1G), if used to turn off the useless shader_feature, such as: _PARALLAXMAP, SHADOWS_SOFT, DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE, _DETAIL_MULX2, _ALPHAPREMULTIPLY_ON; Further pass to remove the excess
  • shaderforge, Amplify Shader Editor generation shader programs have extra code to be optimized, Amplify Shader Editor features more powerful, and open source, it is recommended to learn.
  • Do not terrian comes with unity, because even with only three splat map, shader also correspond to four recommended T4M or converted to mesh.
  • Models and materials to optimize use the same Instance and the huge amount of time, such as grass.
  • Using a lookup texture (LUT) to optimize complex lighting rendering, such as: skin, hair, painting and so on.
  • Try not to use Procedural Sky, Ruili computing scattering and Mie scattering efficiency is relatively low.
  • Try not to use speedtree, plus simple model instead leaves animation, but SpeedTreeWind.cginc inside the animation function is very rich, TerrianEngine in SmoothTriangleWave good use.
  • Multi the debug tool shader performance with a commonly used tools: FrameDebug, Nsight, RenderDoc, AMD GPU ShaderAnalyzer / PVRShaderEditor, Adreno Profiler, Tencent Cube, UWA the like; may additionally built GM interface, such as switches shadow, batch replace shader other convenient device debugging .

2. Script

  • Reduce call GetComponent, find lookup functions such as circulatory function in the Update, go.CompareTag instead of go.tag,
  • SendMessage reduce other synchronous function calls; reduce string concatenation; for foreach place, later optimized version 5.5 has a foreach; LINQ less;
  • Large resources instead loaded asynchronously
  • Reasonable processing coroutine call
  • The AI, networks, etc. in a separate thread
  • Published Optimization: Close log, codes for culling
  • Pseudorandom
  • Script Manager and other global change mount type class implementation
  • lua implemented as much as possible not to update, fixedupdate circulatory functions, and lua csharp mutual calls is relatively inefficient.

3. Memory Management

  • Small pond resource management particles, float UI, etc., frequently cause GC Caton
  • If necessary, take the initiative to call GC.Collect ()
  • According to different sources, different equipment life cycle management of resources, Resources.Load and Assetbundle unified interface, use reference counting to manage the life cycle, and print and observe the life cycle. Ensure resources with the scene and unloading, no permanent memory, to determine which is pre-loaded, which leak.
  • Memory Leak (reducing memory-resident): Container internal resources are not used Resources.UnloadUnusedAssets is to uninstall remove off can not afford; in this case, is recommended to be directly detected by Profiler Memory of Take Sample, or by direct viewing WebStream SerializedFile in AssetBundle name to determine whether there is a "leak" case; / iOS Instrument feedback thread of memory to view the App by Android PSS;
  • Heap too large: Avoid disposable too big heap memory allocation, Mono heap memory allocation once, they will not be returned to the system, which means that Mono is heap memory instead of falling in. Common: high-frequency call new; log output;
  • High CPU Usage: NGui reconstructed grid leads UIPanel.LateUpdate (A still moving, to move the high-frequency slicing); Ngui update logic anchor itself will consume a lot of CPU overhead. Even in the case where the control stationary, the anchor will be updated every frame control (see UIWidget.OnUpdate function), and it updates are recursive, so that the CPU usage higher. Therefore, we modify the internal code NGUI of the anchor only updated when necessary. Updates can generally only in the event of a change control initialization and screen size. But the cost of this optimization is the time (for example, controls movement, or control the size of the change, etc.) vertex position of the control changes, needs its own top logic responsible for updating the anchor. Loaded with the coroutine; UIPanel same number of control dynamic UI element, the more the number, the greater the Mesh created, so that a significant increase in the cost of reconstruction. For example, the blood of the HUD during the battle may appear large, this time, the research and development team sports recommended the blood is separated into different UIpanel, each UIPanel 5 ~ 10 under dynamic UI appropriate. This approach, its essence is to reduce the cost of reconstruction in UIPanel a single frame from a probability as possible.
  • Slack: AssetBundle packaged in multiple hit; dynamically modifying resource caused Instance multiple copies (such as dynamic modify materials, Renderer.meterial, Animation.AddClip).
  • Disk space for memory: for occupancy WebStream large AssetBundle file (such as AssetBundle file UI Atlas-related, etc.), it is recommended to replace LoadFromCacheOrDownLoad or CreateFromFile, AssetBundle data is stored is about to be decompressed for use in local Cache. This approach is particularly well-suited for tight memory project, in exchange for the memory space by the local disk space

4. Art

  • Establish a resource specification review and auditing tools: PBR production of standardized textures, scenes production resources control norms, the role of production specifications, special effects production specifications; use AssetPostprocessor establish auditing tools.
  • Compressed textures, fill rate Optimization Wizard, animation compression, sound compression, compression UI (squares better than stretching); strictly control the number of surface models, textures count, character count bones.
  • Particle: To record movies instead of particles, reducing the number of particles, the particles do not collide
  • Role: Enable Optimize Game Objects node to reduce the use of (SimpleLOD, Cruncher) to optimize the number of faces.
  • Model: Import check Read / Write only, Optimize Mesh, normal to the tangent, color, disabled Mipmap
  • Compressed textures question: compression may result in insufficient gradation; no alpha channel with ETC1, Android does not support ETC2 now has less than 5%, it is recommended to give up the separation channel approach.
  • UI: UI elements as static and dynamic UI elements are separated into different UIPanel (UIPanel reconstructed in units UI), such as the reconstruction because the UI element changes due to the control in a smaller scale; do UI elements may allow dynamic synchronization in accordance with the divided, i.e., frequency of movement of different UI elements placed in different isolated UIPanel as possible; dynamic UI elements so as to be divided in accordance with the synchronization, i.e. different frequencies motion UI elements separated as much as possible placed in different UIPanel;
  • ugui: canvas can take advantage of the different elements to segmentation.
  • Large map will lead Caton, it can be cut into multiple loads.
  • mp3 compression using iOS, Android use Vorbis compression

5. Batch

  • Open static batch
  • Open dynamic batch: model requires less than 900 vertices, wire usage is less than 300, less than 180 with the tangent, scaling inconsistent use LightMap, multi-channel material and the like cause an invalid dynamic batch.
  • Reduce GameObject, a huge impact on the number of scenes model fps.
  • Not a lot better, too large rendering data bus transfer will bring pressure.

6. Physical

  • Static objects need not be moved to
  • Do not use Mesh collision, the role of the body do not collide
  • Trigger logic optimization
  • Pathfinding frequency, AI frequency logic, Fixed Timestep, down to the frame 30
  • Caton complex calculations, for example find the road, a large number of resource loading may be divided into an asynchronous frame or RA treated
Published 42 original articles · won praise 23 · Views 200,000 +

Guess you like

Origin blog.csdn.net/gaojinjingg/article/details/104015632