201403-GDC UnityPhysicallyBasedShading Notes
201403-GDC UnityPhysicallyBasedShading Notes
Shading in Unity
Aras Pranckeviius
Rendering Dude
This is about physically based shading in upcoming Unity 5, and all things that fall out of that.
I am Aras and have been working on Unity graphics since 2006. @aras_p on the twitterverse.
Outline
Note: everything in this talk describes what is planned for Unity 5, which is in very early alpha stage right now. We really want to ship all this, but if things go wrong, some features might get pulled from 5.0 release.
Shaders in Unity 4.x
A lot of good things are available
Marmoset Skyshop
Shader Forge
Alloy physical shaders
A lot of good things are possible
If you know how to write shaders, that is
Unity 4.x has a bunch of built-in shaders (Diffuse, Bumped Specular, ). Many of them are just variations of essentially the same blinn-phong shader.
We want to both improve the shading model (oldskool Blinn-Phong made sense in 2005 not so much in 2014), and improve workflow.
We want the scene like this to be made with built-in shaders & features.
This scene has all textures from Quixels Megascans HDR scanning (http://dev.quixel.se/megascans) by the way.
Shaders in Unity 5
New built-in shaders
Physically based shading
Improved UI & workflow
Related things
Deferred shading, Reflection probes, HDR,
Built-in could cover 80% of use cases
Still possible to write your own, like always
Physically Based Shading
Physically Based Shading
(PBS)
Try to model how light actually behaves
Instead of ad-hoc models that may or might not
work
Movies have moved to it
Games are moving to it
Does not have to meanphoto-realism!
See Pixar
Tons of background information on PBS in recent siggraph courses, for example http://blog.selfshadow.com/publications/s2013-shading-course/ and http://blog.selfshadow.com/publications/s2012-shading-course/
At Unity, our first big experience with PBS was in Butterfly Effect R&D demo (http://unity3d.com/pages/butterfly) in 2012.
PBS motivation
Consistent, plausible look under different
lighting conditions
Less material parameters
All parameter values behave sensibly
More interchangeable data
From 3D / material scanning etc.
Lighting Conditions
Want same content to look good
Energy conservation
Dont reflect more light than you receive
Sharper reflections = stronger; more
blurry reflections = dimmer
Specular takes away from diffuse
Specular everywhere
Blur mip levels: every mip step increases the angle of specular. We use a non-linear angle curve to have more detail in low-angle region.
New Standard Shader
New Standard Shader
Diffuse color
Specular color
Surface smoothness
Normal map
Input: Diffuse
a.k.a. Albedo
Should not have
lighting!
Metals have no (black)
diffuse
Rust etc. can make it not
pure black
Input: Normals
a.k.a. glossiness
or opposite of
roughness
0=rough, 1=smooth
Interesting detail in this
map
Optional inputs
Emission
Ambient Occlusion
Detail albedo/normal maps
Heightmap (for parallax)
Automatic inputs
If you dont know any of these words, do not worry. They describe math done by the shader to make pretty pixels.
Disneys stuff: see Physically-Based Shading at Disney (Brent Burley 2012) here http://blog.selfshadow.com/publications/s2012-shading-course/
Light attenuation
Here were going over shading step by step
Ambient Occlusion
AO from baked texture
Cubemap in the reflection probe has mip levels blurred in special way (specular convolution) so that surfaces of different smoothness can pick up appropriately blurred reflection.
Environment
And with ambient occlusion
Diffuse factor
Specular factor
Diffuse part
Specular from light
Reflection for metals
Coming from the environment
Fresnel reflection for non-metals
Coming from the environment
Diffuse+Specular
Everything
Diffuse + Specular + that Fresnel I could not explain in
simple words
Workflow
One shader
Unity 3/4 deferred lighting (a.k.a. light pre-pass) has really tiny g-buffer (just normals & glossiness). The advantage of it is that it does not require multiple render targets. Disadvantage is two geometry passes, and hard to express
any more sophisticated shading model.
So were making full deferred shading option, with one geometry pass and multiple render targets to store the g-buffer information.
Deferred Shading
G-buffer layout
RT0: diffuse color (rgb)
RT1: specular color (rgb), smoothness (a)
RT2: world normal (rgb; 10.2)
RT3: emission/light buffer; FP16 when HDR
Z-buffer: depth
160bpp (ldr), 192bpp (hdr)
Quite fat
Likely not final yet
This is the current WIP g-buffer layout. Uses 4 MRTs (all 32 bit, except emission/light buffer which can be 64 bit when using HDR).
Since it needs MRTs, that makes it require OpenGL ES 3.0 on mobile, and not-too-old GPU (i.e. not a 10 year old one) on PC.
Deferred Shading
Diffuse Normals Specular
While were on topic of graphics & rendering, heres a random other Unity 5.0 feature: Frame Debugger.
Frame Debugger
You can already do something like this in external tools like GPA, VS2012, NSight, PIX, RenderDoc etc., but having a slimmed down version integrated into Unity for much less hassle would be useful, we thought.
This is particularly useful to see what is rendered into render textures (reflections, depth textures, shadow maps etc.) or which things get batched together.