how we optimized our game - jake & tess' finding monsters adventure
TRANSCRIPT
![Page 1: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/1.jpg)
How we optimized our Game – Jake & Tess’ Finding Monsters Adventure
Phil Lira Sr. Staff Engineer (Graphics) @phi_lira
![Page 2: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/2.jpg)
RELEASE TRAILER
https://www.youtube.com/watch?v=STzdj04n7dc
![Page 3: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/3.jpg)
TECHNICAL CHALLENGES
![Page 4: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/4.jpg)
![Page 5: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/5.jpg)
Technical challenges
Many custom shaders and effects
![Page 6: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/6.jpg)
Technical challenges
Many custom shaders and effects
![Page 7: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/7.jpg)
Technical challenges
Multiple characters with complex skinning
![Page 8: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/8.jpg)
Our budget is the limit
• Push as much content as possible with smooth gameplay and no overheat– Can we get the same quality
with a similar approach?– Are we doing something we
don’t need to?
![Page 9: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/9.jpg)
What if we hit our budge
• What happens when we fail?– Either gameplay or visual quality
will be impacted
• When it comes to remove effects, trust is important
![Page 10: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/10.jpg)
OPTIMIZATION PROCESS
![Page 11: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/11.jpg)
Optimization Process
• Do not make any assumptions. • A profiler will tell you where the bottleneck is.
Profile Optimize Test
![Page 12: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/12.jpg)
Optimization Process
• Rewrite code to use resources more efficiently• Often we can fake or simplify effects • Experience comes into play here.
OptimizeProfile Test
![Page 13: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/13.jpg)
Optimization Process
• Guarantee your tests have same conditions• Did you work reduced overall gpu ms?
TestProfile Optimize
![Page 14: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/14.jpg)
How to find our bottleneck?
• Unity comes with a built-in profiler that does most of the work
• We wanted to have more detailed GPU info
– Adreno Profiler – Snapdragon GPUs– Mali Graphics Debugger (MGD) and
DS-5 Streamline – Mali GPUs
![Page 15: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/15.jpg)
Adreno GPU Profiler
![Page 16: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/16.jpg)
How to find our bottleneck?
Disable GL
Frame rate increased?
No Yes
CPU Bound GPU Bound
Vertex Frag Memory
![Page 17: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/17.jpg)
How to find our bottleneck?
• Vertex– #triangles– Vertex shader– Per-vertex lighting
• Fragment– Fragment Shader (instruc. / sample)– Blend Ops– Per-Pixel light (forward rendering)
• Bandwidth– Large textures– Dependent Texture Reads– Block Resolve (ReadPixels)
![Page 18: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/18.jpg)
CASE STUDY – ROYAL MOON
![Page 19: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/19.jpg)
Case Study – Royale Moon
• Triangles 106k• Drawcalls 87• Overdraw 2.51x• Shader Stats:
– Up to 160 ALU/Frag– Up to 7 texture samples
• Adreno %Time Shading Fragment - max– Fragment bound
![Page 20: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/20.jpg)
Overdraw Debug
![Page 21: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/21.jpg)
Case Study – Royale Moon
• Early Z-Test Discards occluded fragments
• Render Order Matters
• Optimized Render Order– Opaques – Front to Back– Skybox– Transparent – Back to Front– Overlay (UI / HUD)
We need to improve this
![Page 22: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/22.jpg)
How to assign object to sorting layers?• Per Shader
– Have to duplicate shader files. Hard to maintain because we have to make changes individually to each duplicate.
• Per Mesh– Not scalable, requires lot of work. – Risky! May break batches by mistake.
• Per Material– YES!– In that case do not use same material for different scene
• While you fix sort for one might break for the other.
![Page 23: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/23.jpg)
Custom Material Inspector
• Created an editor script BRSMaterialEditor to set Material.renderQueue
• Add CustomEditor “BRSMaterialEditor”
to the end of shader file.
![Page 24: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/24.jpg)
Character and Props
![Page 25: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/25.jpg)
Camera Island Top
![Page 26: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/26.jpg)
Outer Islands
![Page 27: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/27.jpg)
![Page 28: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/28.jpg)
Skydome
![Page 29: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/29.jpg)
Before and After Improving Sort
Reduced from 2.51 to 1.91
![Page 30: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/30.jpg)
Z-Reject
![Page 31: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/31.jpg)
FRAGMENT SHADER
![Page 32: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/32.jpg)
Shader hotzone (% time shading)
![Page 33: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/33.jpg)
Shader hotzone (ALU per frag)
![Page 34: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/34.jpg)
• Improving Shader Instructions– Model: ops that can be done once per drawcall
• Use scripts to compute and pass values to shader• Input Vector Normalization (ex. Rim Light)• Scroll Offset
– Vertex: Ops that can be done per vertex• Uniform texture tile & offset
– Fragment: Ops that needs to be done per pixel• Equation simplification• Half & Fixed precision for better thermal• Saturate vs max(0.0, dot)
Fragment
Vertex
Model
COM
PLEX
ITY
How to optimize fragment shader
![Page 35: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/35.jpg)
Optimizing Shaders
• Many custom shaders done in ShaderForge– ShaderForge does heavy work on fragment
• Many variants and not exactly the same code structure
• How to optimize them all?– 1st pass optimizing in ShaderForge– 2nd pass optimizing in Code
![Page 36: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/36.jpg)
1st Pass: ShaderForge
• Identify core changes to lighting model– BlinnPhongWrapped– BlinnPhongRamp
• Created custom code node– Artist helped with the process to replace for this code– This made shader code common and more organized
![Page 37: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/37.jpg)
1st Pass: ShaderForge
![Page 38: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/38.jpg)
Custom Lightmap in ShaderForge
• One major art complain was the lack of support for lightmap in custom lighting
• Created a Lightmap node for them• Problem1: Need to enable lightmap in config shader header.• Problem2: ShaderForge does not exposes interpolated data.
![Page 39: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/39.jpg)
2nd Pass: Shader Code
Created a cginc file with macros for optimized code• ShaderForge follows name convention for
input data
![Page 40: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/40.jpg)
The results - Ground Shader
After optimization:
Before optimization:
• Avg ALU/Frag – ~21% reduction• Fragments Shaded – ~45% reduction Overall Improvement: ~7ms• Fragment Instructions – ~64% reduction
![Page 41: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/41.jpg)
Further Improvements
• Fallback Shader– We came across some problems
with shaders not being supported for some configurations
– Vertex Animation with a noise texture (tex2dlod) is not supported on OpenGL ES 2.0 profiles
– Fallback shader to standout in those cases
– Makes it easy to differentiate from other errors
![Page 42: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/42.jpg)
ASTC
TEXTURE TEXTURE COMPRESSIONCOMPRESSION
![Page 43: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/43.jpg)
ASTC
• Optimal performance with high quality
• Improves bandwitdh and power consuption
• Galaxy Note 4, Galaxy S6 and above support it
• Supported with OpenGL 3 Unity profile
![Page 44: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/44.jpg)
ASTC
ASTC 4x4 ASTC 6x6 ETC 2
![Page 45: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/45.jpg)
ASTC
Format RGB RGBA Normal MapCodec ASTC 6x6 ASTC 4x4 ASTC 4x4BPP 3.56 8 8
Size vs Uncompressed
14.8% 50% 50%
Size vs ETC2 89% 100% 100%
Recommended Settings:
![Page 46: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/46.jpg)
Review
• Do not make assumptions, use a profiler.• GPU profilers will give you in-depth data per drawcall• One can assign objects to sorting layers at material
level for best workflow• Reduce amount of work to optimize shader by
creating means to reuse optimized code. • ASTC texture compression is best option available
for quality but only supported in a few devices.
![Page 47: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/47.jpg)
Phil [email protected] @phi_lira
Q&A
CONTACTS
www.blackriverstudios.net@BlackRvrStudios/blackrivergames
![Page 48: How we optimized our Game - Jake & Tess' Finding Monsters Adventure](https://reader036.vdocument.in/reader036/viewer/2022081605/587310071a28ab99088b79b7/html5/thumbnails/48.jpg)
Phil [email protected] @phi_lira
THANKS!
CONTACTS
www.blackriverstudios.net@BlackRvrStudios/blackrivergames