Adopting a physically based shading model
August 17, 2011 29 Comments
Version : 1.31 – Living blog – First version was 2 August 2011
With permission of my company : Dontnod entertainment http://www.dont-nod.com/
This last year sees a growing interest for physically based rendering. Physically based shading simplify parameters control for artists, allow more consistent look under different lighting condition and have better realistic look. As many game developers, I decided to introduce physical based shading model to my company. I started this blog to share what we learn. The blog post is divided in two-part.
I will first present the physical shading model we chose and what we add in our engine to support it : This is the subject of this post. Then I will describe the process of making good data to feed this lighting model: Feeding a physically based shading model . I hope you will enjoy it and will share your own way of working with physically based shading model. Feedback are welcomed!
Notation of this post can be found in siggraph 2010 Physically-Based Shading Models in Film and Game Production Naty Hoffman’s paper [2].
Working with a physically based shading model imply some changes in a game engine to fully support it. I will expose here the physically based rendering (PBR) way we chosed for our game engine.
When talking about PBR, we talk about BRDF, Fresnel, energy conserving, Microfacet theory, punctual light sources equation… All these concepts are very well described in [2] and will not be reexplained here.
Our main lighting model is composed of two-part: Ambient lighting and direct lighting. But before digging into these subjects, I will talk about some magic numbers.
Normalization factor
I would like to clarify the constant we find in various lighting model. The energy conservation constraint (the outgoing energy cannot be greater than the incoming energy) requires the BRDF to be normalized. There are two different approaches to normalize a BRDF.
Normalize the entire BRDF
Normalizing a BRDF means that the directional-hemispherical reflectance (the reflectance of a surface under direct illumination) must always be between 0 and 1 : . This is an integral over the hemisphere. In game
corresponds to the diffuse color
.
For lambertian BRDF, is constant. It mean that
and we can write
As a result, the normalization factor of a lambertian BRDF is
For original Phong (the Phong model most game programmer use) normalization factor is
For Phong BRDF (just mul Phong by See [1][8])
normalization factor becomes
For Binn-Phong normalization factor is
For Binn-Phong BRDF normalization factor is
Derivation of these constants can be found in [3] and [13]. Another good sum up is provide in [27].
Note that for Blinn-Phong BRDF, a cheap approximation is given in [1] as :
There is a discussion about this constant in [4] and here is the interesting comment from Naty Hoffmann
About the approximation we chose, we were not trying to be strictly conservative (that is important for multi-bounce GI solutions to converge, but not for rasterization).
We were trying to choose a cheap approximation which is close to 1, and we thought it more important to be close for low specular powers.
Low specular powers have highlights that cover a lot of pixels and are unlikely to be saturating past 1.
When working with microfacet BRDFs, normalize only microfacet normal distribution function (NDF)
A Microfacet distribution requires that the (signed) projected area of the microsurface is the same as the projected area of the macrosurface for any direction v [6]. In the special case v = n:
The integral is over the sphere and cosine factor is not clamped.
For Phong distribution (or Blinn distribution, two name, same distribution) the NDF normalization constant is
Derivation can be found in [7]
Direct Lighting
Our direct lighting model is composed of two-parts : direct diffuse + direct specular
Direct diffuse is the usual Lambertian BRDF :
Direct specular is the microfacet BRDF describe by Naty Hoffman in [2] :