Wednesday 12 September 2018

PBR theory and implementation 1


This article is mainly for my own studying, thus only very key fact will be explain here.

My implementation is in HLSL DirectX 11 in 3ds max environment.

You can see the result in the following image


reference

I read through a lot of article many times to fully understand the theory as well as the math behind this. The ones I reference a lot is :


Very good open gl PBR tutorial

https://learnopengl.com/PBR/Theory

many images in my notes is from here as well

Unity shader source code

Since I want to concentrate on shading I didn’t implement precalculate radiance map and lut this time, I reference Unity’s implementation on real time IBL.

what is PBR ?

Normally you see result images like this when talking about PBR



PBR stands for Physically Based Rendering : The way we calculate the lighting and shading (how different material react to the lighting) follow the physical rules. This will divided the topic into two parts : PBL (physically based lighting ) and PBS (physically based shading)

The target of rendering is : Calculate the light on a surface point by knowing the surface point(p), incoming light direction(i) and strength(Li), view direction(o).

Lo(p,o ) = f(p,i,Li,o)




Traditional lighting model and PBR is doing the same thing but PBR calculate more factors to simulate the real life result.

Energy conservation

One key rule : The radiance(light) comes out from one object can never exceed the light hit on the object.


outgoing light = incoming light

specular and Diffuse distribution

outgoing light from a lit surface falls into two parts : specularand diffuse.





yellow : specular, Light directly get reflected.

red : diffuse , Light get absorbed then comes out from the surface again.


different speculator/diffuse distributions defines the look of different material.


Metal only has speculator, because all the light energy that goes into the surface get absorbed.


To render physically correct means to find the correct distribution between diffuse and specular. In math term it will be something like this:


outgoing light =(diffuse scale+ specular scale) incoming light


because of Energy conservation.


diffuse scale+ speculator scale =1

Material and angle distribution

The next step will be calculate the outcoming light value (r,g,b) given a vertain viewing angle (w0) , incoming light direction (wi) , surface condition (roughness) and material (gold , mud ..)

In other words, how the roughness, metalness, viewing angle , normal ... affect the final result of the outcoming light. How is gold different from mud.

I call it disreibution for now,

view angle light =(diffuse fraction* diffuse distribution + specular fraction* specular distribution) * incoming light

let’s put :

Kd : diffuse fraction

Ks : specular fraction

Li: incoming lighti

Lo : out going light at o

f(d):diffuse distribution

f(s):specular distribution


the equation will be like:


Lo =(Kd*f(d) +Ks*f(s) ) * Li


The reason we seperate f(d) and f(s)is diffuse distribution is different from specular distribution.

In diffuse distribution we use Lambert law (viewing angle does not affect the light value )
In specular , cook-torrance (an advanced relflect / mirror effect)

Render equation

Lo =(Kd*f(d) +Ks*f(s) ) * Li is the Render equation

and Kd*f(d) +Ks*f(s) is the BRDF

BRDF

BRDF Bidirectional reflective distribution function approximates how much each individual light ray i contributes to the final reflected light of an opaque surface given its material properties.


the one used in real time rendering is Cook - Torrance BRDF.


The model used for f(d)is Lambert diffuse : The apparent brightness of a Lambertian surface to an observer is the same regardless of the observer’s angle of view.


f(d) = C/Pi


C is the albedo.