Try   HackMD

PBR: Real-time Implementation

Site du cours

Before we start

Comment on genere une image ?

  • On a vu le raytracing
  • On a vu la rasterization

On va se focus sur le temps reel avec de la rasterization

Old Times

Lambert

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

On a tous fait un Lambert model

  • Plus l'angle est eleve entre la normal et la lumiere, moins il n'y a d'energie

Il n'y a pas de modele

100% diffus

En une seule operation on a notre BRDF

Il existe d'autres modeles mais la difference visuelle n'est pas assez bonne pour etre utilises

Phong

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Approximation pas tres bonne
  • MAIS precurseur a son epoque (
    70s
    )

Pas de conservation d'energie:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Pseudocode

Lambert

void main()
{
 vec3 diffuse = kD * dot(normal, lightDirection) * color;
 gl_FragColor.rgba = vec4(diffuse, 1.0);
}

Phong

void main()
{
 vec3 r = reflect(- viewDirection, normal);
 vec3 diffuse = kD * dot(normal, lightDirection) * color;
 vec3 specular = kS * pow(max(dot(lightDirection, r)), exponent);
 gl_FragColor.rgba = vec4(diffuse + specular, 1.0);
}

What and why

Introduction

Non-physical model requires a lot of tweaking

Si on a un artiste qui fait une scene en exterieur puis on lui dit qu'on doit aller dans un tunnel en voiture, l'artiste pleure
Il doit tweaker les materiaux pour que ca ait l'air joli en fonction de la lumiere

C'est pour ca qu'il y a eu l'avenement du Real Time Rendering vers 2013

C'est dur de definir le PBR

Definition: PBR
Modele mathematiques et approximations que nous allons tous suivre pour decrire les interactions entre la lumiere et la matiere

What is PBR ?

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Pourquoi c'est populaire ?

Decrit le monde plus precisement, donne des rendus realistes
Tout le monde utilise plus ou moins les memes inputs
Moins de tweaking

Win-win pour les ingenieurs et artistes

Microfacets Theory

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Ce modele approxime ce qu'il se passe dans la vraie vie

On dit que tous les materiaux sont composes de miroirs plus ou moins alignes

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

C'est quoi la difference entre un miroir et un plastique ?

Notre premier cas sera un miroir
Le second est un materiaux super diffus

Dielectrics vs Conductors

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Conductors

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

La couleur diffuse serait une approximation du sub-surface scattering

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Les conducteurs reflete
    020%
    de la lumiere

Les metaux n'ont pas de sub-surface scattering

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Les conducteurs refletent
    6090%
    de la lumiere
  • Certains conducteurs ont leur couleur propre due aux longueurs d'ondes absorbees

BRDF

BRDF Simplification

fr(p,ω0,ωi)=fd(p,ω0,ωi)+fs(p,ω0,ωi)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Notre BRDF devient pulg & play

On peut remplacer par ce qu'on veut du moment que

1

Implementation notes

fr(p,ω0,ωi)=kdfd(p,ω0,ωi)+ksfs(p,ω0,ωi)kd+kd1

Diffuse Lobe

fd(p,ω0,ωi)=ρπ

  • ρ
    : reflectance spectrum

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Specular Lobe

fs(p,ω0,ωi)=D(ω0,ωi)F(ω0,ωi)G(ω0,ωi)4(ω0,ωi)(ωi×n)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Specular BRDF

DGGX(n,h,a)=α2π((n×h)2(α21)+1)2h=v+Lv+L

  • Normal distribution function
    D(ω0,ωi)
  • Estimates the area of microfacets aligned to give perfect specular
  • As usual, lots of different NDF equations
  • To be consistent, let's implement the Trowbridge-Reitz equation
  • Low roughness means few samples contributing a lot to specular

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Shadowing term
G(ω0,ωi)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

G(n,v,l,k)=GSchlickGGX(n,v,k)ObstructionGSchlik(n,l,k)ShadowingGSchlickGGX(n,v,k)=n×v(n×v)(1k)+k

  • On va approximer
    k=α
  • Approximation de l'occlusion

L'orientation des facettes peut pieger la lumiere

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Effet Fresnel

On a un joli coucher de soleil sur la mer (ou ocean)
L'eau est un miroir modulo les vagues

Pour tout materiaux, la reflectance va etre maximale aux angles rasants

L'effet Fresnel c'est le poids du specular lobe

ks

FSchlik(v,h,f0,f90)=f0+(f90f0)(1v×h)5FSchlik(v,h,f0)=f0+(1f0)(1v×h)5F0(ior)=(1ior)2(ior+1)2

  • f0
    : base reflectivity at normal incidence
  • f90
    : base reflectivity at grazing angle
    • Almost always 1 for conductors

Fresnel reflectance for common materials

  • For dialectics,
    f0
    is often approximated with
    0.04
  • Some materials
    f0
    are tainted (gold, copper)
  • Implementation note:
    • For dielectics, pick
      0.04
      f0
    • For conductors, store
      f0
      in albedo texture
    • Use metallic input to lerp between the 2

Demo !

Direct-Lightning pseudocode

vec3 radiance = vec3(0.0);
for(int i = 0; i < NB_LIGHTS; ++i)
{
 vec3 w_i = lights[i].direction;
 vec3 kS = FresnelShlick(f0, wi, w_o);
 vec3 specularBRDFEval = kS * f_s(p, w_i, w_o);
 vec3 diffuseBRDFEval = (1.0 - kS) * f_d(p, w_i, w_o);

 radiance += (diffuseBRDFEval + specularBRDFEval) * sampleLight(lights[i], p, w_i) * dot(normal, w_i);
}

Textures

Les artistes font plusieurs textures

To remember !

  • Diffuse is an approximation of sub-surface scattering
  • La plupart des moteurs connus vont avoir des metallics workflow
  • Ca simplifie beaucoup la vie

Ponctual light

Point light

  • Infinitely small
  • Isotropic
  • Describe only by a position
  • Simple to code and fast to sample
  • Power unit should be set using Lumens
  • How to select a proper value ?
  • Not as accurate as Area Light

Li(p,ωi)=ϕ4πr2n×ωi

Cette lumiere n'existe pas dans la vraie vie

Note

  • On ne va pas parler de directionnal light (deja fait)
  • Si on utilise une directionnal light, il faudra tweaker les parametres
  • Ce n'est pas aussi fidele que les Area lights

Image Based Lightning

  • 4 points lights

  • Avec environnement

L0(p,ω0)=Ω(fd(p,ω0,ωi)+fs(p,ω0,ωi))Li(p,ωi)n×wiL0(p,ω0)=Ωfd(p,ω0,ωi)Li(p,ωi)m×ωi+Ωfs(p,ω0,ωi)Li(p,ωi)m×ωi

IBL Diffuse

Ωfd(p,ω0,ωi)Li(p,ωi)m×ωi

Mais c'est juste un flou gaussien ?

C'est pas si faux que ca, c'est assez proche

L0(p,n)=ΩρπLi(p,ωi)n×ωidωiL0(p,n)=ρπΩLi(p,ωi)n×ωidωi

Il faut faire une integration par angle solide, et c'est complique.

  • Utilisation des coordonnees spheriques pour l'integration
  • Discretiser l'integrale avec la somme de Riemann
  • Calculer pour chaque texel, avec la direction
    N
    du centre

IBL Specular

Ωfs(p,ω0,ωi)Li(p,ωi)m×ωi

L0(p,ω0)=ΩLi(p,ωi)dωi×Ωfr(p,ω0,ωi)n×ωidωi

Ca a ete teste et ca marche: c'est ca la 3D

Changer le niveau de roughness c'est faire du downsampling, pourquoi par appliquer la roughness en faisant des images de plus en plus petites

Pre-computed BRDF

Ωfr(p,ω0,ωi)n×ωidωi=F0Ωfr(p,ω0,ωi)(1(1ω0×h)5)n×ωidωi+Ωfr(p,ω0,ωi)(1ω0×h)5n×ωidωi

Obtained bu substituting Fresnel Shlick
Only 2 inputs left: roughness, viewing angle

At runtime:

  1. Fetch pre-integrated BRDF texture
  2. Fetch convoluted environment
  3. Apply the above equation to get the full specular component

Specular: compisistion

c2 brdf = GetIntegratedBRDF(NdotV, roughness);
vec3 prefilteredSpecular = GetPrefilteredSpecular((NdotV, roughness);
vec3 specular = prefilteredSpecular * (F * brdf.x + brdf.y);
  • F: Fresnel term

To remember

  • C'est juste du pre-filtering

Colorspace and color precision

  • sRGB vs Linear
  • Monitors apply pow function to luminance
  • Toute l'industrie a du se base sur les ecran qui font ca donc ils ont cree le
    sRGB
  • Sur photoshop, une image sera encodee en sRGB pour retrouver les couleurs imaginees

On va eviter de faire nos calculs en sRGB

  • Soit on fait tout en sRGB
  • Soit on fait tout en lineaire
    OUI
    • On applique a la fin la fonction sRGB pour convertir en lineaire

HDR vs LDR

HDR: High Dynamic Range

Reinhard Tonemapping:

colorfinal=cc+1

  • HDR has larger range of values
  • Units will create radiance color outside the
    01
    range
  • Perform computation in HDR, tonemap to LDR is required
  • HDR is required to get correct PBR result
  • Especially important for IBL

Going further

Advanced materials

Examples: hair, skin, cloud, etc.