1. 程式人生 > >unite2016上海Unity大會--Unity3D效能優化篇

unite2016上海Unity大會--Unity3D效能優化篇

目錄結構
  • 專案簡述
  • 策劃文案
  • 美術資源
  • 程式邏輯
  • 效能優化

專案簡述
  1. 專案方向
  2. 時間計劃
  3. 人員配置
  4. 具體內容執行 GO!


策劃文案(略過) “兵馬未動,糧草先行~”,優秀的策劃文件是專案良好的開端

美術資源
  • Standard
  • Model
  • Shader
  • Texture
  • Lighting
  • Animator/Controller
  • Audioclip
          
                   Standard
Material使用
Model三角面
Texture尺寸
Particle限制
Animation幀頻

               Model

  • Enabled執行時更改(makes a copy in memory),Disable 節省記憶體

  • Optimize Mesh 必須選擇

  • Normals & Tangents 設定為非Import選項可以降低memory以及減少ipa/apk包體大小

                      Shader
  • Check對應的Vertex/fragment
  • Compile 彙編程式碼/GLSL程式碼
  • Shader效能分析工具 - AMD GPU ShaderAnalyzer/PVRShaderEditor
  • Shader compile when need
  • Comiled Shader快取

                             Texture
  • PSD,TIFF,JPG,TGA,PNG,GIF,BMP,IFF,PICT
  • Scence/Mipmaps check紋理精度
  • Enabled Runtime 可更改(Make a copy in memory),Disable save memory
  • PVRTC格式Texture需要為正方形
  • Mipmap空間換時間

                                   Light
  • Mobile device推薦使用Baked or Mixed
  • Rendeer Mode 儘量少用Important
  • Window->Lighting
  • Scale in light map
  • Preserve UVs
                   Animator/Controller
  • Apply Root Motion 動畫驅動位置
  • State 切換 & Bleed Tree
  • Window -> Animator

AudioClip
  • 常用格式aif,wav,mp3,ogg
  • Verbis-encoded(ogg)解壓變大10倍
  • PCM高質量單低壓縮率
  • ADPCM效能結餘PCM與Mp3之間
  • Mp3格式在IOS裝置你有硬體解碼器



程式邏輯
  • Logic架構
  • Script應用
  • Assert管理
  • Dynamic update

Logic架構
  • Modular Design
  • "Plug and Play"
  • independence and encapsulation(封裝)
Script應用
  • Edit->Project Setting ->Script Execution
  • MonoBehavior 執行機制
  • C++到託管C#存在呼叫開銷
  • Script Call Optimization 可忽略 Exception
  • Script serialization (ScriptableObject)
Asset管理
  • Asset Serialization (Text,Binary,Mixed)
  • .meta file
  • UI atlas arrange
  • Prefab(模型檔案都變成prefab)
  • Asset bundle
Dynamic Update
  • Script updata(使用C#前提下Android使用dll反射,其他平臺暫不支援)
  • 美術Assets(使用Asset bundle)
  • 配置資料



效能優化
  • Graphics
  • Physics
  • Scripts
  • File size
  • Tools

Graphics
  • Bottlenecks on CPU or GPU
  • GPU limitaiton  (verticle not more than 10w on mobile,several millions on PC)
  • Vertex processiong on GPU.(skinned meshes,cloth simulation,particles etc.)
CPU optimization
  • Combine objects(manually or batching)
  • Use less materials
  • Putting separate textures into a larger
  • Use less muliple render(reflections,shadows,perpixel lights etc)
GPU optimaization
  • Model Geometry
    • Don't use any more triangles than necessary
    • Static batching non-moving objects
    • Try to keep the numbers of UV mapping seams and hard edges(doubled-up vertices) as low as possible
  • Lighting Performance
    • LightMap replace real time lighting
    • Shader instad of lighting
    • Use the least pixel lighting saves both CPU and the GPU
  • High-performance shaders
    • Alpha Blend replace Alpha Test
    • Complex mathematical operations pow,exp,log,cos,sin,tan
    • Floating point operations Cg/HLSL(float ,half,fixed) GLSL ES(highp,mediump,lowp)
  • Texture Compression and Mipmaps
    • Compression save memory and bandwidth
    • Always Mipmaps for textures used in a 3D scene
  • LOD and Pre-Layer Cull
    • LOD forlarge object
    • Camera,layCullDistances for small object
 Physics
  • Fixed Timestep
  • Mesh colliders and wheel colliders
  • Rigidbody
  • Physics.RaycastAll in scripts  存在記憶體中
Scripts
  • Optimized by Design
  • Use IL2CPP
  • Script Call Optimization
  • Aviod allcating memory frequently
  • Profiler is King
File Size
  • Identify the assets size by Consonle->Open Editor Log
  • Replach assets in Resources with AssetBundles
  • Use .NET Subset if you can
  • IOS  Stripping
  • Specific operaiton
Tools

Search 打法:在Manual 輸入 Optimiziing  優化的所有項都出現了