Friday 14 December 2018

PBR theory and implementation 2

The model used for f(s)is Cook-Torrance

Cook-Torrance approximates the amount of reflected light considering two factor : microfacet and fresnel effect. The equation is :



In this equation Wo is the viewing direction, Wi is the incoming light direction D F G are the three factors affect how much light will be reflected.

D : normal distribution function

F : Fresnel equation

G : Geometry function


microfacet theory


D and G is related to the microfacet theory. The amount of light is reflected relates to smoothness of a surface.

More micro surfaces with reflect vector aligns to the viewing direction more light is reflected to that direction.

More rough the surface , more shadow the surface is casting on itself.





D : Towbridge-Reitx approuch


approximate how much microfacets with reflect vectors align to view direction with a given roughness.

𝛂 : roughness * roughness

h : normalize (L+V)

n : normal of the surface



h= L+V / length (L,H) = normalize (L+V)

This comes from Blinn_Phong lighting model, instead of evaluating the alignment between view vector and reflect vector, evaluating the Normal vector and Halfway vector of incoming light and view direction.

The correct implimentation of D will be look like :



G : Schlick - GGX approximation




It approximate how much self shadowing will generate given a certain roughness lighting direction and view angle.


The reason it is calculated twice on light vector and view vector is that both of these are affecting how much shadow can be seen.

k is a remapping for . Different lighting situation will need different remapping.

The correct implimentation of G will be look like :



Fresnel schlick approximation

Fresnel equation describe how much light is reflected given a viewing angle and the base reflectivity.

Fresnel effect : the amount of reflected light changes with viewing angle. At grazing angle all material can fully reflect light.


Base reflectivity F0 : describe how much light is reflected when viewing angle is aligned to a surface normal. Different material will have different base reflectivity.

Metal has a higher F0(0.5~1.0) , usually tinted(it is a sRGB). Dielectricity has lower F0(<0.17)

a useful reference chart can be found here





we lerp the value between reflectivity of metall F0-SRGB and a reflectivity of dielecctric 0.04 with the value of the metalic.
The second equation

Distribute outgoing light energy according to the material and form. For example, metal reflect environment much more than dielectric material. It also has a fancy name : BRDF.



correct implimented Fresnel schlick approximation will look like this



When implimenting the equation, we found the precious equation is not matermaticcaly correct , if we use cook-torrance BRDF , because cook-torrance already include the Ks part (how much light is reflected) by having fresnel equation.
Thus , the equation change from :
Lo =(Kd*f(d) +Ks*f(s) ) * Li
to :
Lo =(Kd*f(d) +cook-torrance ) * Li