Physically-Based Rendering UMBC Graphics for Games A Little Multivariable Calculus Because I didnt make it a prereq Partial Derivatives Derivatives with respect to one variable, treat the rest as constant

Surface Integrals Integrate one variable at a time

Concrete example Change of Variables Disk in polar coordinates: Area scales with radius: Integral with area scaling: Illumination

Illumination Effect of light on objects Mostly just look at intensity Apply to each color channel independently Good for most objects Not fluorescent Light enters at one wavelength, leaves as another Brighter green, yellow than we expect

Not phosphorescent Light enters at one point in time, leaves later Local vs. Global Local Photons leave light, bounce off of one surface, make it to eye Global Photons bouncing multiple times

Ambient Illumination Approximate global illumination as a constant Typically ~1% of direct illumination Ambient Occlusion Approximate as a constant scaled by local visibility Harder for light to bounce into corners BRDF Bidirectional Reflectance Distribution Function

How much of Li makes it to Lo? Lo Outgoing radiance L i Incoming radiance P

Physically Plausible BRDF Positive Reciprocity Same light from Li to Lo as from Lo to Li Can trace view to light or light to view Conservation of Energy Dont put out more than comes in

Lo Outgoing radiance L i Incoming radiance P

Important directions L V P = position of light = position of viewer = position on surface

= unit-length surface normal = unit vector toward light = unit vector toward view

= half-way between and L V P

Rendering Equation Integral of all incoming light Playing a little loose with the notation Really differential solid angles, not unit vectors: not Rendering Equation

outgoing light in direction hemisphere above P incoming light from direction BRDF from to

projection of differential solid angle onto surface Like the for integrating in polar coordinates Dot product part Less light per unit area of surface at steeper angles Point Lights Light emitted an infinitesimally small point

Intensity falls off with square of distance to the source For light at position , shining on a surface at point Light intensity Spot Lights Lights with a direction and cone Just point lights with extra code to mask intensity For direction , mask based on AKA the cosine of the angle to the light axis

Directional Lights Really bright point light, really far away Basically, an optimization for the sun Far enough away is basically constant Far enough away that the squared distance is basically constant No falloff with distance Punctual lights Point, Spot, and Directional

From the point of view of any single point on the surface, these all come from a single direction. Integral turns into a sum More on BRDFs Decompose BRDF BRDF = sum of convenient parts Typical breakdown Diffuse (view independent)

Specular (view dependent glossy reflection) Others less common, often ignored (e.g. retro reflection) + = Decompose BRDF BRDF = sum of convenient parts

Diffuse Also called Lambertian or Matte About Pi [Legarde 2012] Common to have a ~3x too bright or ~3x too dark bug Often easier specify point lights with a scaled intensity Specify intensity I at one unit distance with normal incidence and unit albedo So

Simplifies lighting equation: If you use kd with a light that doesnt have the , its 3.14x too bright If you use I as the intensity where you need Li, its 3.14x too dark Microfacet Specular Model to construct physically plausible BRDFs Imagine random mirrored microfacets, too small to see Perfect reflectors, so only facets aligned with contribute Normal Distribution Function (D)

Probability density (on hemisphere of directions) that aligns with Geometry Term (G) Proportion of facets blocked from the light (shadowing) or view (masking) Fresnel Term (F) Reflection is stronger at glancing angles

Microfacet BRDF Original form by Cook & Torrance [1981] Often swap out D & G GGX (aka Trowbridge-Reitz) NDF [Walter et al. 2007] Smith geometry term for GGX [Walter et al. 2007, Karis 2013] Fresnel n = index of refraction

Air: 1; Water: 1.33; Ice; 1.31; Glass: 1.5; Diamond: 2.4 What matters is ratio between materials F0 = reflectance at normal incidence Air to Water: 0.02; Ice: 0.018; Glass: 0.04; Diamond: 0.17 Some games just use one value (0.02-0.04) for everything Schlick approximation for dielectrics (aka non-metal) [Schlick 1994] Wrong for metals, need a different formula for them

Advanced Microfacets Distribution of visible facets [Heitz & DEon 2014] Combine D and G terms into a single joint probability density Multi-bounce [Heitz et al. 2016, Kulla & Conty 2017]

Especially for rough surfaces, lose a ton of energy due to single bounce Model multiple bounces between microfacets (still part of BRDF) Ground truth: simulate multiple bounces Approximation: add a term to compensate for missing energy Normal Map to BRDF When far away, variation in normal map blends to average normal Should push that variation into NDF Otherwise, muddy road (shiny with bumps) turns to mirror in the distance

Plus, shiny normal maps alias like crazy LEAN mapping Model NDF as Gaussian, bumps as off-center Gaussians Best fit Gaussian to a mixture of Gaussians = blend moments Ignores shadowing, masking, Fresnel LEADR mapping (more accurate, more expensive) Model PDF of visible normals as off-center

Gaussians (ignores Fresnel) Toksvig (less accurate, less expensive) Weighted average of unit-length normals will be less than unit length How much less depends on spread, can use to estimate NDF variance Diffuse as Subsurface Fresnel F = proportion that reflects

1 F is proportion that enters surface Diffuse is just subsurface scattered < 1 pixel [Jensen et al. 2001] Instead of BRDF = diffuse + specular Have Environment Light Beyond Points Especially reflection is affected by full environment

Pre-convolved Reflection (aka Environment) map [Greene 1986] Approximate as Blur to approximate integral Precomputed Radiance Transfer (PRT) [Sloan et al. 2005] Glossy reflection as sum of Spherical Harmonics

9-17 coefficients for fixed basis functions Area Lights Beyond Points All real light comes from an area Even the sun is about Affects shadows Softens diffuse

Spreads specular Area diffuse Multiple samples Approximate area light as multiple point lights Overall approximation Above horizon, use center of light Below horizon, shift light direction & scale intensity

Exact Polygonal shapes Closed form for integral of cosine (& powers of cosine) [Arvo 1995] Area Specular Multiple samples Approximate area light as multiple point lights Representative Point [Karis 2013] If mirror reflection direction lands in light source, use that point

If it lands outside the light source, use the closest point in the light Arvo integral approximations Zonal Harmonics [Belcour et al. 2018] Single-axis subset of Spherical Harmonics Linearly Transformed Cosines [Heitz et al. 2016] Squish and stretch cosine (and projection of light shape) to match roughness