PBR Diffuse Lighting for GGX+Smith Microsurfaces
Transcript of PBR Diffuse Lighting for GGX+Smith Microsurfaces
PBR Diffuse Lighting for GGX+Smith Microsurfaces
Earl Hammon, Jr.Lead Software EngineerRespawn Entertainment, LLC
Who am I? Well, my name is Earlβ¦
GGX diffuse research done during Titanfall 2 development
Key Takeaways
β New diffuse equations derived from same assumptions as GGX+Smith specular
β New cheap and good shadowing/masking function πΊ for GGX+Smith specular
β New trig identities for shader optimization
Some fun discoveries on the way
β Whyβs that β4β in PBR specular?
β What is βsβ in Oren Nayar diffuse?
β Smith shadowing/masking assumptions
β A physical interpretation of Lambert
β Help interpreting Disneyβs BRDF slices
Quick aside: Original motivation
β Titanfall 2 used Oren-Nayar diffuse
β Question: How to get Oren-Nayarβs roughness π from GGXβs roughness πΌ?
β Discovery: Oren-Nayar came from very different assumptions!
Quick aside: Original motivation
Oren-Nayar GGX+Smith
Shadowing/Masking V-cavities Smith
Normal Distribution Spherical Gaussian GGX
Roughness parameter π β 0, β πΌ β 0,1
Perfectly flat π = 0 πΌ = 0
Standard deviation of slopes of normals
π 0 πΌ = 0πΌ2β πΌ β 0
Quick aside: Original motivation
β Oren-Nayar and Smith+GGX donβt match!
β Canβt even match standard deviations
β Hmmβ¦ GGX standard deviation is πΌ2ββ Maybe βbestβ to mipmap/filter πΌ2?
β Sum of two GGX distributions is not GGX, so canβt mipmap/filter βproperlyβ
Road map for todayβs talk
β General microfacet-based BRDFs
β Simulating diffuse for GGX+Smith microfacet model
β Comparing to other diffuse BRDFs
Road map for todayβs talk
β General microfacet-based BRDFs
β Simulating diffuse for GGX+Smith microfacet model
β Comparing to other diffuse BRDFs
Microfacet BRDF sub-topic map
β General form
β How we get PBR specular from that
β Extend to diffuse BRDF
Microfacet BRDF sub-topic map
β General form
β How we get PBR specular from that
β Extend to diffuse BRDF
Microfacet models
β Complex macrosurface BRDF averages many microfacets that use a simple BRDF
β Basically just subpixel shader antialiasing
Real world examples
Images: http://funjungle.net/the-world-is-different-under-the-microscope/http://www.geek.com/news/chocolate-under-an-electron-microscope-looks-like-an-alien-planet-1648301/
βGeneralβ Microfacet-based BRDF
β Not fully general; assumes heightfield
β No weaves, arches, or caves
Images: http://funjungle.net/the-world-is-different-under-the-microscope/
General Microfacet-based BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
General Microfacet-based BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
β Integral over all microfacet normals
General Microfacet-based BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
β How an individual facetresponds to light
β I.e., microfacet BRDFcentered on π
β Usually ideal mirror orideal diffuse
General Microfacet-based BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
β Probability density of normal π
β Which facet normals exist, butnot their arrangement (shape)
General Microfacet-based BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
β Occlusion due to actual microfacetarrangement (actual shape)
β A.k.a. shadowing/masking function
β Probability microfacet π sees bothlight πΏ and viewer π
Microfacet BRDF: πΊ2 vs πΊ1
β πΊ2 πΏ, π, π is % visible in 2 directions
πΊ2 πΏ, π, π
πΊ1 πΏ, π πΊ1 π, π
β πΊ1 π, π is % visible in just 1 direction
β In practice, πΊ2 is derived from πΊ1
Microfacet BRDF: π·(π) properties
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
β Probability density of normal πβ How quickly cumulative probability changes near π
β Will change more quickly in more probable regions
β In range 0, β , not 0,1 !
β π· π = β for any π whose probability β 0!
Microfacet BRDF: π·(π) properties
β Ξ©π· π ππ =?
β Total surface area of all microfacets
β Always > 1 if any roughness at all!
β Ξ©π· π cos ππ ππ = 1
β To normalize total area, project microfacets onto macrosurface using cos ππ = π β π
General Microfacet-based BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
β Probability density of having microfacet normal π that is both lit and seen
β I.e., probability density of using BRDF ππ πΏ, π, π .
General Microfacet-based BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
βπβ πΏ
πβ πΏ- How big facet π appears to the light
βπβ π
πβ π- How big facet π appears to the viewer
β I.e., normalize contribution from light and to viewer
General Microfacet-based BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
β Probability density of light from πΏ reaching πin a single bounce off microfacet normal π
β Requirement: Ξ©π· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ β€ 1
β Only = 1 for flat π· π - too dark if any roughness!
General Microfacet-based BRDF
β Related requirement:
Ξ©
π· π πΊ1 π, π π β π ππ = π β π
β In any direction π, total visible microfacet area equals macrosurface area
Microfacet BRDF sub-topic map
β General form
β How we get PBR specular from thatπΉ(πΏ, π»)π· π» πΊ2 πΏ, π, π»
4 π β πΏ π β πβ Also: Where does that 4 come from, and why isnβt it π?
β Extend to diffuse BRDF
PBR Specular Microfacet BRDF
β Microfacet BRDF is a perfect mirror
β I.e., light reflects if and only if π = π»β Mathematically, BRDF is a scaled dirac delta πΏπ π», π
PBR Specular Microfacet BRDF
β Pure mirror BRDF: ππΏπ π», π
β πΏπ π», π is the dirac delta using measure π
β π is some normalization factor we must find
β Normalized BRDF: Ξ©π πΏ, π, π cos ππ ππ = 1
β For any light and normal, all energy reflects to exactly one viewer
Specular BRDF normalization
β General case: Ξ©π πΏ, π, π cos ππ ππ = 1
β Our case: Ξ©ππΏπ π», π cos ππ
ππ
ππππ = 1
β Must integrate over ππ to evaluate πΏπ, so find ππ
ππto change integration domain
Specular BRDF normalization
βππ
ππis how fast π changes relative to π
β This will introduce PBR specularβs 4!
β Next few slides show how
Specular BRDF normalization
β Weβre going to find ππ from ππ to get ππ
ππ
β First, πΏπ picks π = π», so ππ = ππ»
β All vectors sketchedon unit hemisphere
πΏ
π
π»ππ
ππ = ππ»
Specular BRDF normalization
β Move solid angle ππ...
πππ
Specular BRDF normalization
β Move solid angle ππ to πΏ + π...
πΏ
πππ
ππ
Specular BRDF normalization
β Move solid angle ππ to πΏ + π, scale by...
β πΏ + π sphere: π» β π
πππ
ππ
π»
Specular BRDF normalization
β Move solid angle ππ to πΏ + π, scale by...
β πΏ + π sphere: π» β π
β Unit sphere: 4π 12
4π πΏ+π 2 =1
πΏ+π 2
ππ
Specular BRDF normalization
β Move solid angle ππ to πΏ + π, scale by...
β πΏ + π sphere: π» β π
β Unit sphere: 4π 12
4π πΏ+π 2 =1
πΏ+π 2
β ππ =π»β π
πΏ+π 2 ππ π»
ππ
ππ
Specular BRDF normalization
β Move solid angle ππ to πΏ + π, scale by...
β πΏ + π sphere: π» β π
β Unit sphere: 4π 12
4π πΏ+π 2 =1
πΏ+π 2
β ππ =π»β π
πΏ+π 2 πππΏ
π
π»ππ
ππ
ππ
Specular BRDF normalization
β πΏ + π = π» β πΏ + π = π» β πΏ + π» β π = 2π» β π
β This 2 squared is specular BRDFβs 4!
β ππ =π»β π
πΏ+π 2 ππ =π»β π
4 π»β π 2 ππ
βππ
ππ= 4π» β π
πΏ
π
π»
Specular BRDF normalization
β Ξ©ππΏπ π», π cos ππ
ππ
ππππ = 1
β Ξ©ππΏπ π», π π β π 4π» β π ππ = 1
β π =1
4 π»β πΏ π»β πsince π = π» and π» β π = π» β πΏ
β So, pure mirror BRDF: πΏπ π»,π
4 π»β πΏ π»β π
Specular Microfacet BRDF
β Only the Fresnel reflection fraction πΉ(πΏ, π)of incoming light does specular reflection
β So, final specular microfacet BRDF:
ππ πΏ, π, π = πΉ(πΏ, π)πΏπ»(π)
4 π» β πΏ π» β π
Specular Microfacet BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
NβL
πβ π
NβVππ
β Ξ©
πΉ(πΏ,π)πΏπ(π»,π)
4 π»β πΏ π»β ππ· π πΊ2 πΏ, π, π
πβ πΏ
πβ πΏ
πβ π
πβ πππ
β πΏπ(π», π) eliminates integral and sets π = π»
β Specular BRDF: πΉ(πΏ,π»)π· π» πΊ2 πΏ,π,π»
4 πβ πΏ πβ π
Microfacet BRDF sub-topic map
β General form
β How we get PBR specular from that
β Extend to diffuse BRDF
Diffuse Microfacet BRDF
β Ξ©ππ πΏ, π, π π· π πΊ2 πΏ, π, π
πβ πΏ
NβL
πβ π
NβVππ
β Lambertian diffuse: ππ πΏ, π, π =1
π
β No dirac delta to eliminate integral
β No closed form solution for GGX+Smith
Diffuse Microfacet BRDF
β Solved integral numerically, hoping to find good approximation
β Same approach as the Oren-Nayar paper
β Up to half the light was missing!
β Canβt ignore multiple bounces...
β (Full Oren-Nayar includes a second bounce too)
Direct only
Albedo:0.75,0.5,0.25
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
Direct plus indirect
Albedo:0.75,0.5,0.25
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
Indirect only
Albedo:0.75,0.5,0.25
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
Side-by-side
Albedo:0.75,0.5,0.25
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
Importance of proper albedo
Top:Correct
Bottom:Albedo Γ 0.5,Light Γ 2
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
Importance of proper albedo
Top:Correct
Bottom:Albedo Γ 2,Light Γ 0.5
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
Road map for todayβs talk
β General microfacet-based BRDFs
β Simulating diffuse for GGX+Smith microfacet model
β Comparing to other diffuse BRDFs
Road map for todayβs talk
β General microfacet-based BRDFs
β Simulating diffuse for GGX+Smith microfacet model
β Shadowing/masking functions
β Path tracing
β Comparing to other diffuse BRDFs
Diffuse Simulation sub-topic map
β Shadowing/masking functions (πΊ1, πΊ2)
β Uncorrelated vs height correlated G
β Smith shadowing/masking
β New Smith+GGX πΊ2 approximation
β Greatness and weirdness of Smith
β Path tracing
Diffuse Simulation sub-topic map
β Shadowing/masking functions (πΊ1, πΊ2)
β Uncorrelated vs height correlated G
β Smith shadowing/masking
β New Smith+GGX πΊ2 approximation
β Greatness and weirdness of Smith
β Path tracing
Height-Correlated G
β πΊπ is geometric visibility to π directions
β If uncorrelated:πΊ2 πΏ, π, π = πΊ1 πΏ, π πΊ1 π, π
β Not realistic! Higher points more likely visible to both πΏ and π (and lower points less likely)
β Still, surprisingly good in practice
Height-Correlated G
β Uncorrelated G takes light hitting a normal in the heightfield...
m %
β2 93%
β1 87%
0 57%
+1 0%
+2 0%
L
Height-Correlated G
β ...and redistributes it evenly across each microfacet with that normal
L
m %
β2 93%
β1 87%
0 57%
+1 0%
+2 0%
Height-Correlated G
β This tends to move light lower, reducing its visibility and darkening specular.
m %
β2 93%
β1 87%
0 57%
+1 0%
+2 0%
L
Height-Correlated G
β Uncorrelated πΊβs error is related to occlusion
β Error bigger for rougher surfaces
β Error bigger when πΏ and π more glancing
β No error if πΏ = π and/or π = π
Uncorrelated vs. Correlated G
Height-correlation (bottom) boosts glancing reflection on rough surfaces
Black albedo;light intensity = π
135Β°
157.5Β°
165Β°
πΌ = 02 0.252 0.52 0.752 12
Uncorrelated vs. Correlated G
Exact vs. Approx Correlated G
Approximation (bottom) is quite good, but still a little too dark for medium angles and roughness
135Β°
157.5Β°
165Β°
πΌ = 02 0.252 0.52 0.752 12
Exact vs. Approx Correlated G
Height Correlated G Uncorrelated G Difference
Correlated G
β There is angular correlation too
β πΏ = π should have: πΊ2 π, π, π = πΊ1 V, π
β Uncorrelated form: πΊ2 π, π, π = πΊ1 V, π 2
β Height correlated πΊ2 somewhere in between when πΏ = π
Diffuse Simulation sub-topic map
β Shadowing/masking functions (πΊ1, πΊ2)
β Uncorrelated vs height correlated G
β Smith shadowing/masking
β New Smith+GGX πΊ2 approximation
β Greatness and weirdness of Smith
β Path tracing
Smith Shadowing/Masking
β Assumes all normals equally occluded
β I.e., πΊ1 and πΊ2 donβt depend on π
β Most balanced assumption possible
Smith Shadowing/Masking
β Can derive from normalization constraint:
πΊ1 π Ξ©
π· π π β π ππ = π β π
β Can also derive from ray-tracing a probabilistic heightfield
Smith Shadowing/Masking
β Super basic ray trace derivation:
β Project π onto 2D plane with PDF π22 π, π
β π· π isotropic, so use 1D slice with PDF π2 π
β Use π2 π to get PDF of ray-surface collisions while ray with slope π walks the heightfield
β Use PDF of collisions to get πΊ1
Smith Shadowing/Masking
Polar normal π; PDF π· π
π
Smith Shadowing/Masking
2D slope π, π; PDF π22 π, π
Polar normal π; PDF π· π
π
π, π, 1
Smith Shadowing/Masking
2D slope π, π; PDF π22 π, π
Polar normal π; PDF π· π
πAll π for π
π, π, 1
π
Smith Shadowing/Masking
1D slope π; PDF π2 π
2D slope π, π; PDF π22 π, π
Polar normal π; PDF π· π
π
π
π, π, 1
All π for π
Smith: Arbitrary π·(π)
β π22 π, π = cos4 ππ π· π
β π2 π = ββ
βπ22 π, π ππ
β Ξ π =1
π π
β(π β π)π2(π) ππ
β πΊ1 π =1
1+Ξ ππΊ2 πΏ, π =
1
1+Ξ πΏ +Ξ π
Smith: Correlated vs Uncorrelated
β πΊ1 π =1
1+Ξ π
β Correlated: πΊ2 πΏ, π =1
1+Ξ πΏ +Ξ π
β Uncorrelated: πΊ2 πΏ, π =1
1+Ξ πΏ +Ξ π +Ξ πΏ Ξ π
β Too small, unless Ξ = 0 (i.e. πΊ1 = 1) for πΏ or π
Smith for GGX: Ξ π
β For GGX: π· π =πΌ2
π cos4 ππ πΌ2+tan2 ππ2
β π22 π, π =πΌ2
π πΌ2+tan2 ππ2 =
πΌ2
π πΌ2+π2+π2 2
β π2 π = ββ
β πΌ2
π πΌ2+π2+π2 2 ππ =πΌ2
2 πΌ2+π2 3 2
Smith for GGX: Ξ π
β Ξ π =1
π π
β(q β π)π2(π)ππ =
1
2
πΌ2+π2
πβ 1
β π = cot ππ
β cos ππ = N β V
β Ξ V =1
2
πΌ2+ 1βπΌ2 NβV 2
NβVβ 1
Smith for GGX: πΊ1 π , πΊ2 πΏ, π
β πΊ1 π =2NβV
πΌ2+ 1βπΌ2 NβV 2+NβV
β πΊ2 πΏ, π =2 NβL NβV
NβV πΌ2+ 1βπΌ2 NβL 2+NβL πΌ2+ 1βπΌ2 NβV 2
β Would like cheaper approximation!
Diffuse Simulation sub-topic map
β Shadowing/masking functions (πΊ1, πΊ2)
β Uncorrelated vs height correlated G
β Smith shadowing/masking
β New Smith+GGX πΊ2 approximation
β Greatness and weirdness of Smith
β Path tracing
Smith: Approximate GGX πΊ1 π
β Denominator of πΊ1:
β πΌ2 + 1 β πΌ2 N β V 2 + N β V
β ππππ N β V 2, 1, πΌ2 + N β V
β Approximation: ππππ N β V, 1, πΌ + N β V
Smith: Approximate GGX πΊ1 π
β πΊ1 π β2NβV
lerp NβV,1,πΌ +NβV=
2NβV
NβV 2βπΌ +πΌ
β Turns out, identical to Unrealβs Smith:
β πΊ1 π βNβV
NβV 1βπ +π, π =
πΌ
2
Smith: Approximate GGX πΊ2 πΏ, π
β Solve this πΊ1 for Ξ π , plug in for πΊ2 πΏ, π :
β πΊ2 πΏ, π =2 πβ πΏ πβ π
lerp 2 πβ πΏ πβ π , πβ πΏ + πβ π ,πΌ
β πΊ2βs numerator cancels in full specular BRDF:
βπΉ(πΏ,π»)π· π» πΊ2 πΏ,π
4 πβ πΏ πβ π=
πΉ(πΏ,π»)π· π»
2 lerp 2 πβ πΏ πβ π , πβ πΏ + πβ π ,πΌ
Smith Approximation Cost
β Compare cost of denominator:
β πΊ1 πΏ πΊ1 π :πΉ(πΏ,π»)π· π»
πβ πΏ 2βπΌ +πΌ πβ π 2βπΌ +πΌ~4 cycles
β πΊ2 πΏ, π :πΉ(πΏ,π»)π· π»
2 lerp 2 πβ πΏ πβ π , πβ πΏ + πβ π ,πΌ~6 cycles
β Costs exclude calculating π β πΏ and π β π
β Height-correlated form has negligible extra cost
Smith Approximation Quality
β Helps rough dielectrics at glancing anglesExact πΊ2 πΏ, π Approx πΊ1 πΏ πΊ1 πApprox πΊ2 πΏ, π
πΉ0 = 0, πΌ = 20
πΉ0 = 1, πΌ = 2
GGX Specular BRDF for πΌ = 0.8; π β πΏ,π β π increase down,right
Top left of image:glancing reflection
Bottom right:normal incidenceand viewer
Smith Approximation Quality
β Helps rough dielectrics at glancing anglesExact πΊ2 πΏ, π Approx πΊ1 πΏ πΊ1 πApprox πΊ2 πΏ, π
πΉ0 = 0, πΌ = 20
πΉ0 = 1, πΌ = 2
GGX Specular BRDF for πΌ = 0.8; π β πΏ,π β π increase down,right
Top left of image:glancing reflection
Bottom right:normal incidenceand viewer
Uncorrelated G Approximation
Difference Image:
Red = correlationGreen = approximation
Correlated G Approximation
Difference Image:
Relative to uncorrelated approximation
Correlated G Exact
Difference Image:
Relative tocorrelated approximation
Diffuse Simulation sub-topic map
β Shadowing/masking functions (πΊ1, πΊ2)
β Uncorrelated vs height correlated G
β Smith shadowing/masking
β New Smith+GGX πΊ2 approximation
β Greatness and weirdness of Smith
β Path tracing
Smith Microsurface Heightfields
β Example 1D heightfieldfrom Smith ray tracingderivation sketch inWalter 2007
Smith Microsurface Heightfields
β Derivation *also* uses 1D heightfield of mostly independent slabsnearing zero width
β Only forbids suddenlybeing under heightfield
ππlimππβ0
π β
Why Smith masking is weird
β Ray tracing derivation has contradictory assumptions at different steps:
β Height in next ππ independent of this height
β Assumes not continuous
β Heightfield is any differentiable function
β Assumes continuous
Why Smith masking is weird
β Math says visibility is asymmetric: downward rays less likely than upward rays to survive the same heightfield path!
β Ξ π =1
π π
β(π β π)π2(π) ππ
β Ξ π integrates all π > π, so π < 0 can hit more values of π than when π > 0
Why Smith masking is great
β Only energy conserving πΊ where all facet normals have the same fraction visible
β Any other πΊ not using π gets total visible area wrong for some directions
β Too high reflects too much, creating energy
β Too low reflects too little, absorbing energy
Diffuse Simulation sub-topic map
β Shadowing/masking functions (πΊ1, πΊ2)
β Uncorrelated vs height correlated G
β Smith shadowing/masking
β New Smith+GGX πΊ2 approximation
β Greatness and weirdness of Smith
β Path tracing
Path traced diffuse solution
β Smith oddities prevent real heightfields from matching its assumptions
β Canβt be both continuous and discontuous
β Must ray trace the mathematical model
β See bonus slides for numerous details
First ray traced result
β Simple ray tracer with Fresnel to choose GGX specular or Lambertian diffuse
β Resulting BRDF was not symmetric!
β π πΏ, π, π β π π, πΏ, π
β What went wrong? Both parts are symmetric BRDFs!
Cause of asymmetric BRDF
β Essentially had a merged BRDF:
β π = πΉ πΏ, π ππ πππ + 1 β πΉ πΏ, π πππππ
β Fresnel interpolation asymmetric!
β How to fix in a physically plausible way?
Why Lambertian diffuse?
β What does Lambertian diffuse simulate?
β BRDF π =1
π: same for all viewers
β Radiance = π cos ππ: more photons at normal
β Balanced by 1
cos ππfor total surface area seen by π
β Why the cosine energy falloff? Answer is surprisingly hard to discover, yet quite simple!
Lambertian diffuse explained
β BRDFs given at the surface, but diffuse light just passes through the surface
β Lambert assumes interior light has same density in all directions
β Cosine falloff is from surface angle relative to light direction
Lambertian diffuse explained
β Same energy per area each direction
β Directions angled to surface project over larger areaβ Area per unit light scaled by 1 cos π
β Light per unit area scaled by cos π
π
Lambertian diffuse explained
β Light enters, bounces around, exits
β Exit direction is random after many bounce events
β Albedo comes from frequency-dependent absorption events
Fixing diffuse for symmetric BRDF
β Entering uses Fresnel for reflection/transmission
β Exiting assumes always transmit
β Exiting needs Fresnel too!
Fixing diffuse for symmetric BRDF
β Reflect: πΉ = πΉ0 + 1 β πΉ0 1 β π β π 5
β Transmit: 1 β πΉ = 1 β πΉ0 1 β 1 β π β π 5
β Fresnelβs laws are symmetric, so fraction entering surface from viewer equals fraction exiting surface toward viewer
Fixing diffuse for symmetric BRDF
β Internally reflected light keeps getting chances to transmit; need to normalize!
β 2π 0
π 2π 1 β 1 β cos π 5 cos π sin π ππ = 1
β Factor 1 β πΉ0 absorbed into norm factor π
β cos π needed to normalize a BRDF
β 2π and sin π ππ from integrating on a hemisphere
Fixing diffuse for symmetric BRDF
β Easily solved exactly: π =21
20π=
1.05
π
β Merged diffuse+spec microfacet BRDF:
β πΉ = πΉ0 + 1 β πΉ0 1 β π β π 5
β Ο = πΉ ππ πππ + 1 β πΉ1.05
π1 β 1 β π β π 5
Finally!
β Now have everything needed for path tracing simulation, resulting in...
Simulation with spec
Albedo:0.75,0.5,0.25
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
Simulation diffuse only
Albedo:0.75,0.5,0.25
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
Approximate diffuse only
Albedo:0.75,0.5,0.25
πΌ = 02 0.252 0.52 0.752 12
0Β°
90Β°
135Β°
GGX Diffuse Approximation
β ππππππ = 0.5 + 0.5 πΏ β π
β πππ’πβ = ππππππ 0.9 β 0.4ππππππ0.5+πβ π»
πβ π»
β π ππππ‘β = 1.05 1 β 1 β π β πΏ 5 1 β 1 β π β π 5
β π πππππ =1
πππππ π ππππ‘β, πππ’πβ, πΌ
β ππ’ππ‘π = 0.1159πΌ
β πππππ’π π = ππππππ β π πππππ + ππππππ β ππ’ππ‘π
Aside: Useful shader identities
β πΏ + π 2 = 2 + 2πΏ β π
β 0.5 + 0.5πΏ β π =1
4πΏ + π 2
β π β π» =πβ πΏ+πβ π
πΏ+π
β πΏ β π» = π β π» =1
2πΏ + π
Aside: Useful shader identities
β Can find π β π» and πΏ β π» without finding π»!
* Add 3 cycles if you donβt already have πΏ β π
Calculation Cycles Registers
Get π» = normalize πΏ + π 13 4
Get π» then π β π» 16 4
Get π» then π β π» and πΏ β π» 19 4
π΅ β π― from identities 7* 2
π³ β π― and π½ β π― from identities 8* 2
Aside: Useful shader identities
β πππππ_πΏπ = 2 + 2 πΏ β π
β ππππΏππ_πΏπ = ππ πππ‘ πππππ_πΏπ
β π β π» = π β πΏ + π β π β ππππΏππ_πΏπ
β πΏ β π» = π β π» = ππππΏπππΏπ + ππππΏπππΏπ β πΏ β πβ (Since πΏ β π» =
1
2πΏ + π =
1
22 + 2πΏ β π =
1
2
2+2πΏβ π
2+2πΏβ π= (1 + πΏ β π)
1
2+2πΏβ π)
Road map for todayβs talk
β General microfacet-based BRDFs
β Simulating diffuse for GGX+Smith microfacet model
β Shadowing/masking functions
β Path tracing
β Comparing to other diffuse BRDFs
But Firstβ¦
β Itβs good to quickly understand Disneyβs BRDF slices
Disneyβs BRDF slices
β BRDF is a 4D function of 2 polar vectors
β Before, light+viewer vectors: ππ , ππ , ππ£, ππ£
β After, half angle+difference: πβ , πβ , ππ , ππ
β Isotropic BRDFs never depend on πβ
β Dependence on ππ is often negligible
Disneyβs BRDF slices intuition
β Each row is a light+viewer pair (ππ)
β Opposite at top, perpendicular in middle, coincident at bottom
β Left-to-right shows falloff going away from center of specular highlight (πβ)
False color example on lit sphere
0Β° 45Β° 90Β° 135Β°
135Β°
BRDF Slice Corresponding Lit Spheres
Lighter bands highlightrows used by spheres
Lighter bands highlight ππ = 90Β°;ππ increases counterclockwise
90Β°
45Β°
0Β°
Retr
ore
flection
Disneyβs BRDF slices
πβ
ππ
Fresnel
Specula
r
π β π»
πΏ β π»; πΏ β π
Equal
Opposite
Perpendicular
Specular Silhouette
Behavior of πβ , ππ , ππ on spheres
πβ; π β π» ππππ; πΏ β π»; πΏ β π
Disneyβs BRDF slices
β Various identities:
β cos πβ = π β π»
β cos ππ = πΏ β π» = π β π» cos 2ππ = πΏ β π
β cos ππ =πβ πβπβ πΏ
2β2πΏβ π 1β πβ π» 2
β BRDFs mostly functions of π β π» and πΏ β π!
Almost ready to compare BRDFs!
β First, introduce the comparison format
New Model
Title says which diffuse model is shown. This intro uses the new model
New Model
This panel shows the same lit spheres as previous examples.
New Model
The matching BRDF slices are here (uncorrelated G)
New Model
Same full BRDF with πΌfrom 0 to 1, but lit by Paul Debevecβs HDR environment probes.
uff
izi
gra
ce
cam
pus
Lambert
Disney
Oren Nayar, π = 0.5πΌ
New model
New model (hybrid)
Smooth uses Disneyβs ππ90 = 0.5, so same as Disney when πΌ = 0
New model (cheaper)
Smooth uses Lambert
Lambert
Disney
New model
Lambert
Disney
New model
Lambert
Disney
New model
Special Thanks
β Mark Cerny
β GDC mentor
β Chad Barb, Xin Liu, Steve Marton
β Fellow Respawn engineers with awesome ideas/feedback in this research (as always)
Selected Referencesβ Eric Heitz 2014 β Understanding the Masking-Shadowing Function in Microfacet-based BRDFs
http://jcgt.org/published/0003/02/03/paper.pdf
β Bruce Walter et al 2007 β Microfacet Models for Refraction through Rough Surfaces http://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf
β Brent Burley 2012 β Physically Based Shading at Disney http://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf
β Brian Karis 2013 - Real Shading in Unreal Engine 4 http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf
β Peter Shirley et al 1997 - A practitionersβ Assessment of Light Reflection Models http://www.cs.utah.edu/~shirley/papers/pg97.pdf
β Michael Ashikhman et al 2000 β A Microfacet-based BRDF Generator http://www.cs.utah.edu/~shirley/papers/facets.pdf
β Oren Nayar 1994 β Generalization of Lambertβs Reflectance Model http://www1.cs.columbia.edu/CAVE/publications/pdfs/Oren_SIGGRAPH94.pdf
Respawn is [email protected]
Appendixβ The following is a bunch of derivations for Smith shadowing/masking
from the ray tracing formulation, and how you use that to actually do the path tracing. This is how I got the results included in the preceding presentation.
β This is quite math heavy. As such, it fits much better in an appendix than in the talk. It is hard to read derivations to an audience, and it is even harder to listen to them! Itβs better to be able to go at your own pace, and to be able to flip back and forth as needed.
β Final caveat: I didnβt polish these appendix slides much (e.g., there is a complete lack of figures). Still, the information and derivation should be helpful to those who like to understand where things come from, and/or who want to understand the Smith shadowing/masking derivation.
Solution β Path Tracingβ Shoot photons into the microsurface for a light direction
β See which view direction those photons come out
β This lets us model diffuse and specular interactions
β But first, we have to be able to ray trace the microsurface
β The microsurface is implicitly defined by the normal distrubution function π·(π) and the shadowing/masking function πΊ(πΏ, π, π)
β πΊ(πΏ, π, π) derived from π·(π) is basically ray tracing
β So, we need to understand how Smith πΊ(πΏ, π, π) works
Starting to derive Smithβ This basically follows Appendix A in Walterβs 2007 GGX paper
β With many missing details filled in, and slightly reordered. Any differences with Walterβs appendix are my own attempt to complete the derivation.
β It may be handy to pull up Walterβs appendix as you follow these slides
β Consider ray tracing a 2D slice of the heightfield in the plane of the ray and macrosurface normal
β Y axis is height (π), X axis is projected distance along ray (π)
β We need probability of hitting height field, given that we havenβt yet
β Let π1(π) be the probability density of height π
β Probability height π is above the heightfield π π = ββ
ππ1 π₯ ππ₯
β This is total probability of heightfield being lower than π
PDF of hitting heightfield (1/2)
β For ray π0 + ππ to hit in the next Ξπ from height π with slope π:
β π0 + π π > π
β π0 + π π + π Ξπ > π + π Ξπ
β Rearranging, we have:
β π0 + π π > π > π0 + π π β π β π Ξπ
β Clearly requires π > π
β Probability of hitting is π
β π0+π πβ πβπ Ξπ
π0+π ππ1 π₯ π2 π ππ₯ ππ
β π1 π₯ is probability density of height π₯
β π2 π is probability density of slope q
β Product assumes probability π1 π₯ and π2 π are independent
β All normals equally likely at each height; heightfield is fractal, not like canyons or spikes
PDF of hitting heightfield (2/2)
β π
βπ2 π π0+π πβ πβπ Ξπ
π0+π ππ1 π₯ ππ₯ ππ
β Can pull π2 π out of the inner integral because it doesnβt use π₯
β Take limβπβ0
βπ = ππ
β Assume π1 π₯ is constant over ππ at π1 π0 + π π
β π
βπ2 π π1 π0 + π π π β π ππ ππ
β Probability of ray π0 + ππ hitting in next ππ:
ππ π1 π0 + π π π
β
π β π π2 π ππ
Meet S, the surviving fractionβ Need conditional probability given we start outside the heightfield:
βππ π1 π0+π π π
βπβπ π2 π ππ
ββπ0+π π
π1 π₯ ππ₯=
ππ π1 π0+π π πβ
πβπ π2 π ππ
π π0+π π
β Let π(π, π, π) be the surviving fraction and consider how it changes:
β ππ = β πππ1 π0+π π π
βπ2 π πβπ ππ
π π0+π ππ
β I.e., the fraction of surviving rays hitting in the next ππ are subtracted from S
βππ
ππ= β
π1 π0+π π πβ
π2 π πβπ ππ
π π0+π ππ
Start solving diff. eq. for Sβ We have
ππ
ππ= β
π1 π0+π π πβ
π2 π πβπ ππ
π π0+π ππ
β In general, π
πππβπ(π) = βπβπ(π)πβ² π , so S = πβπ(π)
β πβ² π =π1 π0+π π π
βπ2 π πβπ ππ
π π0+π π
βRecall definition π π0 + π π = ββ
π0+π ππ1 π₯ ππ₯
βππ
ππ= π1 π0 + π π
π
πππ0 + π π = π π1 π0 + π π
βDefine Ξ π =1
π π
βπ β π π2 π ππ
βAssumes π β 0
β πβ² π =ππ1 π0+π π
1
π π
βπ2 π πβπ ππ
π π0+π π= Ξ π
πβ² π0+π π
π π0+π π
Final solution for π π0, π, πβ π π = 0
ππβ² π‘ ππ‘ = 0
πΞ π
πβ² π0+π π‘
π π0+π π‘ππ‘ = Ξ π ln π π0 + π π‘ 0
π
β Uses the fact that π
ππ‘ln π(π‘) =
1
π(π‘)πβ²(π‘)
β Assumes π π and π1 π₯ are continuous
β π π = Ξ π ln π π0 + ππ β ln π π0 = Ξ π lnπ π0+ππ
π π0
β π π0, π, π = πβπ π = πβΞ π ln
π π0+ππ
π π0 =π π0+ππ
π π0
βΞ π
β Weβve derived the heart of Smith shadowing/masking:
π π0, π, π =π π0
π π0 + ππ
Ξ π
Solving for πΊ1 π given π π0, π, πβ We can use this to find the probability of a ray escaping
β π π0, π = limπββ
π π0, π, π =π π0
π β
Ξ π
=π π0
1
Ξ π
= π π0Ξ π
β Assumes π > 0 in π π0 + ππ β π β
β Can find probability of seeing the heightfield in slope π =ππ
ππ:
β πΊ1 π = ββ
βπ1(π) π π, π ππ
β Integral over all heights of the probability of having height π and escaping in direction π
β πΊ1 π = ββ
βπβ²(π) π π Ξ π ππ =
1
1+Ξ ππ π Ξ π +1
ββ
β
β π β = 1 and π ββ = 0 regardless of choice of π1(π), which defines π π
β πΊ1 π =1
1+Ξ π
Solving for πΊ2 ππΏ, ππβ Can also find visibility in two directions from one height
β πΊ2 ππΏ , ππ = ββ
βπ1(π) π π, ππΏ π π, ππ ππ
β πΊ2 ππΏ , ππ = ββ
βπ1(π) π π Ξ ππΏ π π Ξ ππ ππ
β πΊ2 ππΏ , ππ = ββ
βπ1(π) π π Ξ ππΏ +Ξ ππ ππ
β This gives the height correlated Smith shadowing/masking function:
β πΊ2 ππΏ , ππ =1
1+Ξ ππΏ +Ξ ππ
β Note that π = cot π, where π is the angle from the macrosurface normal
Starting to derive Ξ πβ We still need to finish derivation of Ξ π =
1
π π
βπ β π π2 π ππ
β This uses the probability of a tangent slope π2 π , where q =ππ
ππ.
β We have the surface area of a microsurface normal, π· π .β Project the microsurface normal area onto the macrosurface to
get the probability density of a normal per unit area of the macrosurface
β π· π cos ππ, where cos ππ = π β π is the angle from vertical
β Project from spherical coordinates (ππ, ππ) to plane (π, π, 1)
βcos ππ sin ππ,sin ππ sin ππ,cos ππ
cos ππ= cos ππ tan ππ , sin ππ tan ππ , 1
Change variables (ππ, ππ) to (π, π)β π = cos ππ tan ππ, π = sin ππ tan ππ
β Implies π2 + π2 = tan2 ππ
β Probability density of normal π is π· π cos ππ ππ
β ππ = sin ππ ππππππ
β We need it as probability density of slopes π22 π, π ππππβ This is the same as π· π cosππ ππ, just with change of
variables.β Need the Jacobian, based on partial derivatives
βππ
πππ= β sin ππ tan ππ,
ππ
πππ=
cos ππ
cos2 ππ
βππ
πππ= cos ππ tan ππ,
ππ
πππ=
sin ππ
cos2 ππ
Final Jacobian for (ππ, ππ) to (π, π)
β det
ππ
πππ
ππ
πππ
ππ
πππ
ππ
πππ
= β sin ππ tan ππsin ππ
cos2 ππβ cosππ tan ππ
cos ππ
cos2 ππ
β This is the Jacobian for the change in area of the measure for a change of variables from ππ, ππ to (π, π)
β Jacobian = β sin2 ππtan ππ
cos2 ππβ cos2 ππ
tan ππ
cos2 ππ=
tan ππ
cos2 ππ=
sin ππ
cos3 ππ
β This means
βsin π
cos3 ππππππ = ππππ
β sin π πππππ = cos3 π ππππ
Completing (ππ, ππ) to (π, π)β Change of variables for π from (ππ, ππ) to (π, π) has
β ππ = sin ππ ππππππ = cos3 ππ ππππ
β We want π22 π, π ππππ = π· π cos ππ ππ
β π22 π, π ππππ = π· π cos ππ cos3 ππ ππππ = π· π cos4 ππ ππππ
β Recall that π2 + π2 = tan2 ππ... so ππ is a function of (π, π)
β If π· π doesnβt depend on ππ, π· π cos4 ππ ππππ is a function on (π, π)!
β For GGX, π· π =πΌ2
π cos4 ππ πΌ2+tan2 ππ2
β π· π cos4 ππ =πΌ2
π πΌ2+tan2 ππ2 =
πΌ2
π πΌ2+π2+π2 2
Slope PDF from 2D to 1Dβ Weβre getting close! We have probability density of 2D slope
π, π :
β π22 π, π ππππ
β We need the 1D probability of slope:
β π2 π ππ
β Since weβve assumed π· π doesnβt depend on ππ, we can arbitrarily rotate π, π such that π aligns with the ray direction and π is perpendicular to it
β This lets us integrate π22 π, π ππππ over all π to get π2 π ππ:
β π2 π ππ = ββ
βπ22 π, π ππππ
π2 π : normals or tangents?β π2 π was derived as the probability density that a microfacet
normal goes π units along the x-axis π for every 1 unit along the y-axis π .
β Tangents are always perpendicular to normals.β In 2D, vector (π₯, π¦) is perpendicular to (βπ¦, π₯) and (π¦, βπ₯).
β So, this is equivalent to the microfacet tangent slope going βπunits along the y-axis π for every 1 unit along the x-axis π .
β This means π2 π is the probability density of tangent slope βπ.β But π· π doesnβt depend on ππ, so π2 π = π2 βπ .
β This means π2 π is the probability of a microfacet tangent slope π.
β This is how we used it earlier
Use GGXβs π22 π, π to get its Ξ πβ For GGX, we saw that π22 π, π =
πΌ2
π πΌ2+π2+π2 2
β π2 π = ββ
βπ22 π, π ππ = ββ
β πΌ2
π πΌ2+π2+π2 2 ππ =πΌ2
π πΌ2+π2 1.5
β All this is to find Ξ π =1
π π
βπ β π π2 π ππ
β Ξ π =1
π π
β πΌ2 πβπ
π πΌ2+π2 1.5 ππ = βπΌ2+ππ
2π πΌ2+π2π=π
β
= β1
2+
πΌ2+π2
2π
β We have π =ππ
ππfor a view vector, so π = cot ππ =
cos ππ
sin ππfor ππ from
vertical.
β Ξ π = β1
2+
πΌ2 sin2 ππ+cos2 ππ
2 cos ππ=
πΌ2+ 1βπΌ2 cos2 ππ
2 cos ππβ
1
2
Smith masking is weird (1/2)β Ray-tracing derivation of the Smith masking function assumed
any height/slope can be immediately adjacent to any other height/slope.
β I.e., the heightfield is continuous nowhere, yet differentiable everywhere.
βTo be differentiable, you have to be continuous, so this is contradictory.
β This also means you canβt integrate slopes to get heights, yet slopes are the derivatives of the heights.
βThis is the same contradiction.
β Smithβs result can be derived just from slope-independent visibility, so there may be a better way to do the ray-tracing derivation.
β We canβt construct a heightfield and just path trace it.β Any heightfield with a finite number of heights must violate the
assumption of all heights being fully independent.
Smith masking is weird (2/2)β Ray-tracing derivation has odd result for downward rays (π < 0).
β Derivations donβt require π > 0, but do require π β 0.β Can show that Ξ βπ = βΞ π β 1.
β With π0 < π1 and π > 0, we have π π0, π1, π =π(π0)
π(π1)
Ξ π
β π π1, π0, βπ =π(π1)
π(π0)
βΞ π β1=
π(π0)
π(π1)π π0, π1, π < π π0, π1, π
β Visibility is asymmetric; rays traveling the same path between two heights are more likely to hit something going down than going up!
β Derivation assumes rays can hit any opposing microfacet normal (π β π < 0).
β More normals oppose downward rays than upward rays.β Since the probability distribution of normals is everywhere the same, the
cumulative area of candidate normals must be greater for downward rays than for upward rays.
β In other words, surface area is bigger going down than going up.
Path tracing with Smith maskingβ BRDFs must be symmetric
β To be symmetric, we need π π1, π0, βπ = π π0, π1, π
β Derivation instead has π π1, π0, βπ =π(π0)
π(π1)π π0, π1, π
β Caused by Ξ βπ = βΞ π β 1
β To βfixβ, redefine Ξ π so Ξ βπ = βΞ π , without changing positive slopes:
Ξ π =1
π
π
β
(π β π )π2(π) ππ
β Conceptually, renormalize downward surface area to match upward surface area.
β For GGX, Ξ π =1
2
πΌ2+π2β π
π, βπ β 0
Derivation that Ξ βπ = βΞ π β 1β This derivation uses the fact that π2 βπ = π2(π)
β Ξ βπ =1
βπ βπ
β(q + π)π2(π) ππ
β β1
π βπ
πq + π π2 π ππ β
1
π π
βq β π + 2π π2 π ππ
β β1
π βπ
πππ2 π ππ β
1
π βπ
πππ2 π ππ β Ξ π β 2 π
βπ2 π ππ
β 0 β βπ
ππ2 π ππ β Ξ π β π
βπ2 π ππ β ββ
βππ2 π ππ
β βΞ π β ββ
βπ2 π ππ
β βΞ π β 1
Handling π = 0β Preceding derivation assumed π β 0. If you instead assume π =
0, you get
β π π0, π, π = πβπ
π1(π0)
π(π0) π
β(πβπ)π2 π ππ
β For GGX, 0
βππ2 π ππ = 0
β πΌ2π
π πΌ2+π2 1.5 ππ =πΌ
2, so π π0, 0, π = π
βππΌ
2
π1(π0)
π(π0)
β This barely resembles the equation for π β 0
β π π0, π, π =π(π0)
π(π1)
Ξ π=
π(π0+ππ)
π(π0)
β1
π π
β(πβπ)π2(π)ππ
β Limit as ΞΌ β 0 of the equation for ΞΌ β 0 is the equation for ΞΌ = 0!
β Furthermore, limΞΌβ0+
π(π0+ππ)
π(π0)
βΞ π= lim
ΞΌβ0β
π(π0+ππ)
π(π0)
βΞ π
β True even though Ξ π is discontinuous at 0, since π(π0+ππ)
π(π0)β 1.
Heightfield heights
β Given π·(π), itβs possible to figure out the heightfield height limit.
β We have π2 π , the 1D probability of slope π.
β GGXβs cumulative probability π = ββ
π πΌ2
2 πΌ2+π2 1.5 ππ =π
2 πΌ2+π2+
1
2.
β Solve for π to turn a random variable into a slope: π =πΌ 2πβ1
1β 2πβ1 2
β Height is π ππππ = ππΌ 2ππβ1
1β 2ππβ1 2ππ = πΌ π
2ππβ1
1β 2ππβ1 2ππ.
β All roughnesses can use same heightfield, just scaled by πΌ.
β Correctly says πΌ = 0 is perfectly flat.
GGX heightfield probability funcβ I summed random slopes with πΌ = 1 to generate heightfields.
β The random number generator is proven good with a period around 296.
β Height histograms were spiky with no correllation between runs.β Each run basically picked a random number of random heights to center on.
β Uniform height distribution over Β±0.0002πΌ seems reasonable.
Number of Slopes
Height Range
216 Β±0.0100
220 Β±0.0030
224 Β±0.0007
227 Β±0.0004
230 Β±0.0002
231 Β±0.0002
Starting to path trace GGXβ We now have what we need to path trace GGX:
β π1 π = 1
0.0004β0.0002 β€ π β€ 0.0002
0 ππ‘βπππ€ππ π
β π π = ββ
ππ1 π₯ ππ₯
β Ξ π =1
2
πΌ2+π2β π
π, π β 0
β π π0, π, π =
π(π0)
π(π0+ππ)
Ξ ππ β 0
πβπ
πΌ
2
π1(π0)
π(π0) π = 0
Intersection distance (1/2)β Going from height π0 in direction π, at what π do we hit the surface?β Cumulative probability of hitting the surface is 1 β π, since π is the cumulative
probability of not hitting the surface.β We can pick a uniform random variable for 1 β π and solve for π
β This is equivalent to picking a uniform random variable for π
β π π0, π, π =
π(π0)
π(π0+ππ)
Ξ ππ β 0
πβπ
πΌ
2
π1(π0)
π(π0) π = 0
β π =
πβ1 π π0 π β1 Ξ π βπ0
ππ β 0
β ln π2π(π0)
πΌπ1(π0)π = 0
β π =π
1+π2
Intersection distance (2/2)β More convenient to use π and π.
β π = cot π π = π sin π ππ = π cos π
β Ξ π =πΌ2+(1βπΌ2) cos2 πβ cos π
2 cos π, cos π β 0
β π π0, π, π =
π(π0)
π(π0+π cos π)
Ξ πcos π β 0
πβπ
πΌ
2
π1(π0)
π(π0) cos π = 0
β π = πβ1 π π0 π β1 Ξ π β π0 tan π cos π β 0
β ln π2π(π0)
πΌπ1(π0)cos π = 0
β For a 3D vector π, we have cos ππ = ππ§, making this trivial to calculate
Escaping raysβ If cos π β 0, then π = πβ1 π π0 π β1 Ξ π β π0 tan π
β πβ1 is undefined if π π0 π β1 Ξ π > 1.
β Can only happen if Ξ π > 0, which is when cos π > 0 (upward rays).
β Fortunately, algebra shows this is when π < π π0Ξ π .
β Recall that π π0Ξ π is the probability of a ray escaping when it
starts at π0 and goes in direction π
β If π β€ π π0Ξ π , the ray hit the viewer, not the microsurface.
β This is our one and only path termination condition.
Intersection normalβ Smith derivation assumes π·(π) is independent of height.
β So, for a vector traveling in direction π, pick any π according to π·(π) such that π β π < 0 (ray points at surface, normal points away).
β Need to pick ππ, ππ .
β π· π =πΌ2
π 1β(1βπΌ2) cos2 ππ2
β Since π·(π) doesnβt depend on azimuth ππ, just uniformly pick in [0,2π).
β Need to importance sample π·(π) over hemisphere
β π2π 0
π/2π·(π) cosππ sin ππ πππ = 1
Intersection normalβ π = 2π
0
ππ·(π) cos ππ sin ππ πππ
β π = 0
π 2πΌ2 cos ππ sin ππ
1β(1βπΌ2) cos2 ππ2 πππ
β Note that π
πππ1 β 1 β πΌ2 cos2 ππ = 2(1 β πΌ2) cos ππ sin ππ
β We have the form
πΌ2
1βπΌ2 πβ²(π₯)
π(π₯)2 ππ₯, which has the solution βπΌ2
1βπΌ2
1
π(π₯).
β π = βπΌ2
1βπΌ2 1
1β 1βπΌ2 cos2 ππ 0
π= β
πΌ2
1βπΌ2
1
1β(1βπΌ2) cos2 πβ
1
πΌ2
β π = βπΌ2
1βπΌ2
πΌ2β 1β 1βπΌ2 cos2 π
πΌ2 1β 1βπΌ2 cos2 π= β
β1+cos2 π
1β 1βπΌ2 cos2 π=
1βcos2 π
1β 1βπΌ2 cos2 π
β When π =π
2(whole hemisphere), cos π = 0, so π = 1 (i.e., already properly
normalized).
Intersection normal
β π =1βcos2 π
1β 1βπΌ2 cos2 π
β Need to solve this for π given π.
β π β π 1 β πΌ2 cos2 π = 1 β cos2 π
β 1 β π 1 β πΌ2 cos2 π = 1 β π
β cos2 π =1βπ
1β 1βπΌ2 π
β π = cosβ1 1βπ
1β 1βπΌ2 π
β Algebraically equivalent to Walterβs result X = tanβ1 πΌ π
1βπ
Intersection normalβ We can now pick a random microfacet normal:
β π0, π1 = π’ππππππ ππππππ π£πππ’ππ ππ [0,1]
β ππ = 2π π0
β ππ = cosβ1 1βπ1
1β 1βπΌ2 π1
β π = cosππ sin ππ , sin ππ sin ππ , cos ππ
β Start over if π β π β₯ 0.
β Have to retry because there is no closed form solution to importance sample GGXβs π·(π) directly given the constraint π β π < 0.
Intersection normalβ Can be slow to pick a normal as ππ§ β 1. Almost none of
our guesses satisfy the constraint π β π < 0.
β Dot product is cos ππ sin ππ ππ₯ + sinππ sin ππ ππ¦ + cos ππ ππ§ <0.
β ππ₯ cos ππ + ππ¦ sin ππ < βππ§ cot ππ
β Set ππ₯ = π cos π½ and ππ¦ = π sinπ½
β π = ππ₯2 + ππ¦
2 = 1 β ππ§2; π½ = π πππ π’πππππ€π πππππ
β π cosπ½ cosππ + π sin π½ sin ππ < βππ§ cot ππ
β cos π½ β ππ < βππ§
π tan ππ; the minimum value for the left is β1
Intersection normalβ β1 < β
ππ§
π tan ππ, so tan ππ >
ππ§
1βππ§2
β cos2 ππ < 1 β ππ§2 (trivial since ππ§ acts like a sine of some angle)
β1βπ1
1β 1βπΌ2 π1< 1 β ππ§
2 (the left is our derivation for sampling cos2 ππ)
β 1 β π1 < 1 β ππ§2 β 1 β ππ§
2 1 β πΌ2 π1
β ππ§2 < 1 β 1 β ππ§
2 1 β πΌ2 π1
β π1 >ππ§
2
1β 1βππ§2 1βπΌ2 =
ππ§2
πΌ2+ππ§2 1βπΌ2
Intersection normalβ We can now pick a random normal more efficiently:
β π0, π1 = π’ππππππ ππππππ π£πππ’ππ ππ [0,1]
β ππ = 2π π0
β If ππ§ > 0, shrink π1 to the range [ππ§
2
πΌ2+ππ§2 1βπΌ2 , 1]
β ππ = cosβ1 1βπ1
1β 1βπΌ2 π1
β π = cos ππ sin ππ , sin ππ sin ππ , cos ππ
β If π β π < 0, return πβ If ππ§ > 0, negate ππ. If π β π < 0 now, return this π.
β Start over
β This is more efficient, because at least half the values for π0, π1 generate valid normals given the constraint π β π < 0
Reflection/Transmissionβ Given the microfacet normal π and incoming direction π, we can
calculate Fresnel πΉ to decide to reflect or transmit at the facet.
β πΉ = πΉ0 + (1 β πΉ0)(1 β π β π)5, Schlickβs famous approximation
β We use πΉ0 = 0.02, for index of refraction = 1.33, common for dialectrics.
β Each ray starts with 1 unit of energy. If the rayβs energy is above a threshold, we split it into reflected and transmitted parts with energies scaled by πΉ and (1 β πΉ), respectively. Otherwise, we use Russian Roulette to decide which path gets all the energy.
β Reflected rays continue recursively in the reflection direction.
β Transmitted rays continue in a carefully chosen random direction.
β If the transmitted rayβs energy is above a threshold, we split it into N rays first.
Transmission Directionβ Lambertian scattering would use a cosine weighted hemisphere.
β We tried that. The BRDF was not symmetric.
β The problem is our effective microfacet BRDF was:
β πΉ β π ππππ’πππ + 1 β πΉ β πππππ’π π
β Both π ππππ’πππ and πππππ’π π are valid BRDFs, but πΉ lerps between them based only on the incoming direction π = βπΏ.
β This means that swapping πΏ and π is asymmetric in πΉ; it replaces one vector with an unrelated one.
β In short, Lambertian diffuse doesnβt play nicely with a specular BRDF.
β Fortunately, Shirley et al. solved this in 1997.
Transmission Directionβ Why is Lambertian cosine weighted?
β Lambertian scattering assumes that light enters the microsurface, bounces around on the inside, and then comes back out.
β When there is a scattering event inside the surface, it assumes each outgoing direction is equally likely for a ray.
β You can thus model the interior volume as having uniform beams of energy in every direction. The ones pointing to the surface escape.
β But the BRDF is defined for a unit area of the surface, not the interior volume. A unit area on the surface cuts diagonally across the uniform beam exiting at an angle, so that the fraction hitting the surface is only cosπ.
Transmission Directionβ We had a Fresnel reflection on entering the microsurface
volume. For symmetry, we need the same Fresnel reflection on exiting too.
β Fortunately, reflection/transmission is symmetric.
β This means we can calculate Fresnel transmission from the view direction into the surface, and it is equivalent to calculating the Fresnel inside the surface for another vector that gets refracted into the view direction.
Transmission Directionβ So, the probability of keeping an exiting
direction is 1 β πΉ(cos ππ£):β 1 β πΉ0 + (1 β πΉ0)(1 β π β π)5
β 1 β πΉ0 1 β (1 β π β π)5
β We need a normalization constant such that this integrates to 1 over all view directions. Thatβs because rays reflected back into the surface will bounce around and get another chance to escape.
β Since 1 β πΉ0 is a constant, we can just absorb it as part of the normalization constant
Transmission Direction
β 2ππ 0
π
2 1 β (1 β cos π)5 cos π sin π ππ = 1β The cos π outside the exponent is the normalization constraint for a
BRDFβ sin π ππ is the measure for integrating over the hemisphere.β 2π is from integrating over the hemisphere but not depending on
azimuth.β π is the normalization constant we want to find.
β This is actually easy to solve. Just multiply out (1 β cos π)5 to get a polynomial in cos π. The 1βs cancel. Weβre left with terms like:
β π cosπ π sin π
β Trivial integral of each term is βπ
π+1cosπ+1 π
Transmission Directionβ The final result of the integral is:
β 2ππ β5
3cos3 π +
5
2cos4 π β 2 cos5 π +
5
6cos6 π β
1
7cos7 π
0
ππ£
β For ππ£ =π
2, cosππ£ = 0, and weβre left with
β2ππ5
3β
5
2+ 2 β
5
6+
1
7= 2ππ
10
21=
20π
21π = 1
βπ =21
20π=
1.05
π
βInterestingly, this is just 5% larger than the pure Lambertian BRDF.
β 1 +21
10β
5
3cos3 ππ£ +
5
2cos4 ππ£ β 2 cos5 ππ£ +
5
6cos6 ππ£ β
1
7cos7 ππ£
β 1 β7
2cos3 ππ£ +
21
4cos4 ππ£ β
21
5cos5 ππ£ +
7
4cos6 ππ£ β
3
10cos7 ππ£
β We want to importance sample this with a [0,1] variable, so can use 1 β this.
Transmission Directionβ Y =
7
2cos3 ππ£ β
21
4cos4 ππ£ +
21
5cos5 ππ£ β
7
4cos6 ππ£ +
3
10cos7 ππ£
β We can solve this polynomial for cos ππ£ to use in importance sampling of view directions.
β No easy closed form solution; follow Shirleyβs recommendation to pick a good guess then improve with Newton Raphson.
β The first guess is y = cos ππ£ =0.0114813+154.4π+13002.4π2+38295.9π3
1+1483.57π+33596.4π2+16520.2π3
β We then use this and ππ£ in [0,2π] to get the outgoing transmission direction relative to the microfacetβs normal π.
Transmission Directionβ The result is a combined BRDF:
β πΉ β π ππππ’πππ + 1 β πΉ β1.05ππ
π1 β 1 β π β π 5
β The specular part is symmetric because it is nonzero only where π = π», which is where πΉ π β πΏ = πΉ π β π
β π» = ππππππππ§π(πΏ + π), the half-angle vector.
β The diffuse part is symmetric because 1 β πΉ = 1 β πΉ0 1 β 1 β π β πΏ 5
β Swapping πΏ and π just swaps which Fresnel is entering and which is exiting, as expected.
β πΉ is what fraction of rays reflect; 1 β πΉ is what fraction transmits.β If the ray reflects, only facets aligned to π» reflect light, without loss of energy.
β If the ray transmits, it has to survive another transmission event to escape the surface. Once it escapes, partial absorption has tinted it by ππ.
Transmission Observationβ This still doesnβt perfectly model subsurface effectsβ Most obviously, we ignore how Snellβs law changes ray
directionsβ Assumptions have ray directions uniformly distributed inside the surfaceβ Equation assumes rays are uniformly distributed outside the surface
β Snellβs law says π1 sin π1 = π2 sin π2, so π2 = sinβ1 π1
π2sin π1
β π2 approximately linear for π1 near 0, then π2 changes faster as it approaches
π
2and π1 approaches angle of total internal reflection
β This means outgoing angles are less represented near π
2than near 0
β Conveniently, thatβs where transmission is weakest, so theyβre already less represented
Appendix Conclusionβ This now gives all the pieces needed to get the path tracing
solution
β I picked about 64 representative zenith angles and 16 πΌ values, and then shot tons of rays for each pair of settings.
β For each ray, I recursively saw what it hit and did Fresnel transmission/reflection based on the chosen normal. Finally, I bucket escaping rays into view directions.
β From this raw data, I tried tons of random equations with terms symmetric in L and V until I saw ones that I liked based on their tradeoff between computation cost and fidelity.