48
How we optimized our Game – Jake & Tess’ Finding Monsters Adventure Phil Lira Sr. Staff Engineer (Graphics) @phi_lira

How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Embed Size (px)

Citation preview

Page 1: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

RELEASE TRAILER

https://www.youtube.com/watch?v=STzdj04n7dc

Page 3: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

TECHNICAL CHALLENGES

Page 4: How we optimized our Game - Jake & Tess' Finding Monsters Adventure
Page 5: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Technical challenges

Many custom shaders and effects

Page 6: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Technical challenges

Many custom shaders and effects

Page 7: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Technical challenges

Multiple characters with complex skinning

Page 8: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

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

OPTIMIZATION PROCESS

Page 11: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

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

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

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

Adreno GPU Profiler

Page 16: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

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

CASE STUDY – ROYAL MOON

Page 19: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

Overdraw Debug

Page 21: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

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

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

Character and Props

Page 25: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Camera Island Top

Page 26: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Outer Islands

Page 27: How we optimized our Game - Jake & Tess' Finding Monsters Adventure
Page 28: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Skydome

Page 29: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Before and After Improving Sort

Reduced from 2.51 to 1.91

Page 30: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Z-Reject

Page 31: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

FRAGMENT SHADER

Page 32: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Shader hotzone (% time shading)

Page 33: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

Shader hotzone (ALU per frag)

Page 34: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

• 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

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

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

1st Pass: ShaderForge

Page 38: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

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

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

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

ASTC

TEXTURE TEXTURE COMPRESSIONCOMPRESSION

Page 43: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

ASTC

ASTC 4x4 ASTC 6x6 ETC 2

Page 45: How we optimized our Game - Jake & Tess' Finding Monsters Adventure

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

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

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

Phil [email protected] @phi_lira

THANKS!

CONTACTS

www.blackriverstudios.net@BlackRvrStudios/blackrivergames