Unity Optimization - zzragida/UnityDocs GitHub Wiki
Reference
์ต์ ํ ํ๋ก์ธ์ค(The optimization process)
- ์์ธกํ์ง ๋ง๊ณ ๊ณ์ธกํ๋ผ!
- ํ๋กํ์ผ๋ฌ๋ก ์ดํ๋ฆฌ์ผ์ด์
์ ์ธก์ ํ๋ผ(Take measurements of your application with a profiler.)
- ๋ณ๋ชฉ์ง์ ์ ๋ถ์ํ๋ผ(Analyze the data to locate the bottleneck.)
- ์ด๋ค๋ถ๋ถ์ ์ต์ ํ๋ฅผ ์ ์ฉํ ์ง ๊ฒฐ์ ํ๋ผ(Determine the relevant optimization to apply.)
- ์ต์ ํ๋ ์์
์ ๊ฒ์ฆํ๋ผ(Verify that the optimization works.)
- ์ต์ ํ ์์
๋ ๊ฒฐ๊ณผ๊ฐ ๋ง์กฑ์ค๋ฝ์ง ๋ชปํ๋ค๋ฉด Step1๋ก ๋์๊ฐ๋ผ(If the performance is not acceptable return to step 1 and repeat the process.)
์ต์ ํ ํฌ์ธํธ(The optimization point)
- ์คํฌ๋ฆฝํธ(Script)
- ์๋๋ฉ์ด์
(Animation)
- ๊ทธ๋ํฝ์ค(Graphics) / ์์ด๋(Shader)
- ๋ฌผ๋ฆฌ(Physics)
- ํ๋ซํผ ์ข
์ ๋ถ๋ถ(Platform Specific)
์ฐ๋ฆฌํ์์ ์๋ํด๋ณผ๋งํ ์ต์ ํ ํฌ์ธํธ
์ฑ๋ฅ ํ๋กํ์ผ๋ง
- ๋๊ตฌ
- ์ ๋ํฐ ํ๋กํ์ผ๋ฌ
- AP๋ฒค๋๋ณ ํ๋กํ์ผ๋ฌ(Adreno, Nvidia, ARM, PowerVR)
- Android Studio Monitor
- Xcode Instruments
- ํ์ธ๋ด์ฉ
- ๋ชจ๋ธ ๋ ๋๋ง ์๊ฐ ํ์ธ
- ํฌ์คํธ ์ดํํธ ์๊ฐ ํ์ธ
- ์ดํํธ ์๊ฐ ํ์ธ
์ต์ ํ ๋ฐฉ๋ฒ
- LOD(Level of Detail)
- Occlusion Culling
- LightMap
- Static/Dynamic Batching
- Combined Mesh
- SharedMaterial
- SharedMesh
- Procedural Mesh
- Procedural Material
- Mesh Baker
- Texture Compression
Mobile GPU vendors
- Imagination Technologies
- PowerVR
- Series 5, 5XT, 6, 6XT, Wizard
- ARM
- Mali
- Utgard (Mali400), Midgard (Mali T624)
- Qualicomm
- Adreno
- Adreno 2xx, 3xx, 4xx
- nVidia
๋ชจ๋ฐ์ผ ์ต์ ํ(Mobile Optimization)
- ๋์ ์๋ณด์ด๋? ์ต์ ํ ์ค์ ์ ์ฌ์ฉํ๋ผ(Use more eye-candy on higher performance configurations)
- ๋ชจ๋ฐ์ผ ๊ฐ๋ฐ์ ์ฒดํฌ๋ฆฌ์คํธ(Mobile Developer Checklist)
GPU ์ธก๋ฉด(Focus on GPUs)
Good practice
- Keep the number of materials as low as possible.
- This makes it easier for Unity to batch stuff. Use texture atlases (large images containing a collection of sub-images) instead of a number of individual textures.
- These are faster to load, have fewer state switches, and are batching friendly.
- Use Renderer.shaderedMaterial instead of Renderer.material if using texture atlases and shared materials.
Forward rendered pixel lights of realtime lights where ever possible.
- Use light mapping instead of realtime lights where ever possible.
- Adjust pixel light count in quality settings. Essentially only the directional light should be per pixel, everything else - per vertext. Certainly this depends on the game.
- Experiment with Render Mode of Lights in the Quality Settings to get the correct priority.
- Avoid Cutout (alpha test) shaders unless really necessary.
- Keep Transparent (alpha blend) screen coverage to a minimum.
- Try to avoid situations where multiple lights illuminate any given object.
- Try to reduce the overall number of shader passes (Shadows, pixel lights, reflections).
Rendering order is critical. In general case:
- fully opaque objects roughly front-to-back.
- alpha tested objects roughly front-to-back.
- skybox.
- alpha blended objects (back to front if needed.)
- Post Processing is expensive on mobiles, use with care.
- Particles: reduce overdraw, use the simplest possible shaders.
- Double buffer for Meshes modified every frame:
void Update()
{
// flip between meshes
bufferMesh = on ? meshA : meshB;
on = !on;
bufferMesh.verticles = vertices; // modification to mesh
meshFilter.sharedMesh = bufferMesh;
}
Shader optimizations
- Avoid alpha-testing shaders; instead use alpha-blended versions.
- Use simple, optimized shader code (such as the "Mobile" shaders that ship with Unity).
- Avoid expensive math functions in shader code (pow, exp, log, cos, sin, tan, etc). Consider using pre-calculated lookup textures instead.
- Pick lowest possible number precision format (float, half, fixedin Cg) for best performance.
CPU ์ธก๋ฉด(Focus on CPUs)
Good practice
- Don't use more than a few hundred draw calls per frame on mobiles.
- FindObjectsOfType (and Unity getter properties in general) are very slow, so use them sensibly.
- Set the static property on non-moving objects to allow internal optimizations like static batching.
- Spend lots of CPU cycles to do occlusion culling and better sorting (to take advantage of Early Z-cull).
Physics
- Physics can be CPU heavy. It can be profiled via the Editor profiler. If Physics appears to take too much time on CPU:
- Tweak Time.fixedDeltaTime (in Project settings -> Time) to be as high as you can get away with. If your game is slow moving, you probably need less fixed updated than games with fast action. Fast paced games will need more frequent calculations, and thus fixedDeltaTime will need to be lower or a collision may fail.
- Physics.solverIterationCount (Physics Manager).
- Use as little Cloth objects as possible.
- Use Rigidbodies only where necessary.
- Use primitive colliders in preference mesh colliders.
- Never ever move a static collider (ie a collider without a Rigidbody) as it causes a big performance hit. It shows up in Profiler as "Static Collider.Move" but actual processing is in Physics.Simulate. If necessary, add a Rigidbody and set isKinematic to true.
- On Windows you can use NVidia's AgPerfMon profilling tool set to get more details if needed.