![Page 1: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/1.jpg)
Real Shading in Unreal Engine 4 Brian Karis ([email protected])
![Page 2: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/2.jpg)
Goals • More realistic image • Material layering
– Better workflow – Blended in shader
• Timely inspiration from Disney – Presented in this course last year
![Page 3: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/3.jpg)
Overview • Shading model • Material model • Lighting model
![Page 4: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/4.jpg)
Shading Model
![Page 5: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/5.jpg)
• Lambert – Saw little effect of more sophisticated models
Diffuse BRDF
Lambert Burley
![Page 6: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/6.jpg)
Specular BRDF • Generalized microfacet model
– Compared many options for each term – Use same input parameters
𝑓 l, v =𝐷 h 𝐹(l, h)𝐺 l, v, h
4(n ⋅ l)(n ⋅ v)
![Page 7: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/7.jpg)
Specular distribution • Trowbridge-Reitz (GGX)
– Fairly cheap – Longer tail looks much more natural
GGX Blinn-Phong
𝑓 l, v =𝐷 h 𝐹(l, h)𝐺 l, v, h
4(n ⋅ l)(n ⋅ v)
![Page 8: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/8.jpg)
Geometric shadowing • Schlick
– Matched to Smith – Cheaper, difference is minor – Uses Disney’s roughness remapping*
n ⋅ v
𝐺𝑆𝑐ℎ𝑙𝑖𝑐𝑘(v)
𝛼 = 0.1 𝛼 = 0.5 𝛼 = 0.9
𝑓 l, v =𝐷 h 𝐹(l, h)𝐺 l, v, h
4(n ⋅ l)(n ⋅ v)
n ⋅ v
𝐺𝑆𝑚𝑖𝑡ℎ(v)
![Page 9: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/9.jpg)
Fresnel • Schlick
– Approximate the power
Identical for all practical purposes
𝑓 l, v =𝐷 h 𝐹(l, h)𝐺 l, v, h
4(n ⋅ l)(n ⋅ v)
![Page 10: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/10.jpg)
Image-based lighting : Problem • Only use single sample per environment map • Match importance-sampled reference
𝐿𝑖 l 𝑓 l, v 𝑐𝑜𝑠 𝜃l 𝑑l
𝐻
≈1
𝑁 𝐿𝑖 l𝑘 𝑓 l𝑘 , v 𝑐𝑜𝑠 𝜃l𝑘
𝑝 l𝑘 , v
𝑁
𝑘=1
![Page 11: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/11.jpg)
Image-based lighting : Solution • Same as Dimitar’s: split the sum • Pre-calculate both parts
1
𝑁 𝐿𝑖 l𝑘 𝑓 l𝑘 , v cos 𝜃l𝑘
𝑝 l𝑘 , 𝑣
𝑁
𝑘=1
≈1
𝑁 𝐿𝑖 l𝑘
𝑁
𝑘=1
1
𝑁 𝑓(l𝑘 , v) cos 𝜃l𝑘𝑝(l𝑘 , v)
𝑁
𝑘=1
![Page 12: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/12.jpg)
Pre-filtered environment map • 1st sum stored in cubemap mips
– Pre-filter for specific roughness’s – Fixed distribution, assume n = v – Loses stretched highlights
1
𝑁 𝐿𝑖 l𝑘
𝑁
𝑘=1
≈ Cubemap. Sample(r,mip)
![Page 13: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/13.jpg)
Environment BRDF • 2nd sum stored in 2D lookup texture (LUT)
1
𝑁 𝑓(l𝑘 , v) cos 𝜃l𝑘𝑝(l𝑘 , v)
𝑁
𝑘=1
= LUT. r ∗ 𝐹0 + LUT. g
cos 𝜃v
Roughness
![Page 14: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/14.jpg)
Importance-sampled reference
![Page 15: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/15.jpg)
Split sum approximation
![Page 16: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/16.jpg)
Complete approximation (n=v)
![Page 17: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/17.jpg)
Complete approximation (n=v)
Importance-sampled reference
Split sum approximation
![Page 18: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/18.jpg)
Material Model
![Page 19: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/19.jpg)
Material model • BaseColor
– Single color • Metallic
– Less chance of error • Roughness
– Very clear in its meaning • Cavity
– Used for small scale shadowing
Metallic 0 to 1
Non-metal with roughness 0 to 1
Metal with roughness 0 to 1
![Page 20: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/20.jpg)
Material model lessons • Specular parameter is confusing
– Not really needed – Replaced with Cavity
DiffuseColor SpecularColor SpecularPower
BaseColor Metallic Specular Roughness
BaseColor Metallic Roughness Cavity
Samaritan Infiltrator Now
![Page 21: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/21.jpg)
Material layering • TODO:anotherimage
![Page 22: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/22.jpg)
Material layering tools • Added layers to our node graph based material editor
– Layers use existing material function feature – Added material attributes struct
• Layer workflow similar to previous texture workflow
![Page 23: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/23.jpg)
Material layering
![Page 24: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/24.jpg)
Material layering
![Page 25: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/25.jpg)
Lighting Model
![Page 26: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/26.jpg)
Inverse square falloff
Old falloff Inverse square
![Page 27: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/27.jpg)
Area Lights
![Page 28: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/28.jpg)
Area light requirements • Consistent material appearance
– Energy evaluated with diffuse BRDF and specular BRDF should match
• Approaches point light model as solid angle approaches zero – Don’t want to lose any aspect of our shading model
• Fast enough to use everywhere – Otherwise artists will bias roughness
![Page 29: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/29.jpg)
Specular D modification • Widen specular distribution by light’s solid angle
– We presented this last year
• Problems – Glossy surfaces don’t look glossy anymore
![Page 30: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/30.jpg)
Reference Specular D modification
![Page 31: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/31.jpg)
Representative point • Pick one representative point on light source shape • Shading model can be used directly • Point with largest contribution is a good choice • Approximate using smallest angle to reflection ray
![Page 32: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/32.jpg)
Sphere lights • Irradiance identical to point light
– If sphere above horizon
• Closest point between ray and sphere – Approximates smallest angle
![Page 33: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/33.jpg)
Sphere light energy conservation • Specular distribution has been widened by light’s solid angle
– We already have an approximation for this using “Specular D modification” – Only use normalization term – Divide out original normalization, multiply in new
![Page 34: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/34.jpg)
Reference Representative point
![Page 35: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/35.jpg)
Representative point applied to Tube Lights
![Page 36: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/36.jpg)
In the course notes • Tons of extra stuff
– Importance sampling code – Area light formulas – Lots of math
![Page 37: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/37.jpg)
Thanks • Epic
– Rendering team – All the artists making me look good
• Special thanks to Sébastien Lagarde • Stephen Hill and Stephen McAuley for valuable input
![Page 38: Real Shading in Unreal Engine 4 - Self Shadowblog.selfshadow.com/publications/s2013-shading-course/karis/s2013... · Real Shading in Unreal Engine 4 Brian Karis (brian.karis@epicgames.com)](https://reader035.vdocuments.net/reader035/viewer/2022082207/5aebc92e7f8b9ac3618fa31c/html5/thumbnails/38.jpg)