PBR Diffuse Lighting for GGX+Smith Microsurfaces

193
PBR Diffuse Lighting for GGX+Smith Microsurfaces Earl Hammon, Jr. Lead Software Engineer Respawn Entertainment, LLC

Transcript of PBR Diffuse Lighting for GGX+Smith Microsurfaces

Page 1: PBR Diffuse Lighting for GGX+Smith Microsurfaces

PBR Diffuse Lighting for GGX+Smith Microsurfaces

Earl Hammon, Jr.Lead Software EngineerRespawn Entertainment, LLC

Page 2: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Who am I? Well, my name is Earl…

Page 3: PBR Diffuse Lighting for GGX+Smith Microsurfaces

GGX diffuse research done during Titanfall 2 development

Page 4: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 5: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 6: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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!

Page 7: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 8: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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”

Page 9: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Road map for today’s talk

● General microfacet-based BRDFs

● Simulating diffuse for GGX+Smith microfacet model

● Comparing to other diffuse BRDFs

Page 10: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Road map for today’s talk

● General microfacet-based BRDFs

● Simulating diffuse for GGX+Smith microfacet model

● Comparing to other diffuse BRDFs

Page 11: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Microfacet BRDF sub-topic map

● General form

● How we get PBR specular from that

● Extend to diffuse BRDF

Page 12: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Microfacet BRDF sub-topic map

● General form

● How we get PBR specular from that

● Extend to diffuse BRDF

Page 13: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Microfacet models

● Complex macrosurface BRDF averages many microfacets that use a simple BRDF

● Basically just subpixel shader antialiasing

Page 14: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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/

Page 15: PBR Diffuse Lighting for GGX+Smith Microsurfaces

β€œ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/

Page 16: PBR Diffuse Lighting for GGX+Smith Microsurfaces

General Microfacet-based BRDF

● Ξ©πœŒπ‘š 𝐿, 𝑉, π‘š 𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

𝑁⋅𝐿

π‘šβ‹…π‘‰

π‘β‹…π‘‰π‘‘π‘š

Page 17: PBR Diffuse Lighting for GGX+Smith Microsurfaces

General Microfacet-based BRDF

● Ξ©πœŒπ‘š 𝐿, 𝑉, π‘š 𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

𝑁⋅𝐿

π‘šβ‹…π‘‰

π‘β‹…π‘‰π‘‘π‘š

● Integral over all microfacet normals

Page 18: PBR Diffuse Lighting for GGX+Smith Microsurfaces

General Microfacet-based BRDF

● Ξ©πœŒπ‘š 𝐿, 𝑉, π‘š 𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

𝑁⋅𝐿

π‘šβ‹…π‘‰

π‘β‹…π‘‰π‘‘π‘š

● How an individual facetresponds to light

● I.e., microfacet BRDFcentered on π‘š

● Usually ideal mirror orideal diffuse

Page 19: PBR Diffuse Lighting for GGX+Smith Microsurfaces

General Microfacet-based BRDF

● Ξ©πœŒπ‘š 𝐿, 𝑉, π‘š 𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

𝑁⋅𝐿

π‘šβ‹…π‘‰

π‘β‹…π‘‰π‘‘π‘š

● Probability density of normal π‘š

● Which facet normals exist, butnot their arrangement (shape)

Page 20: PBR Diffuse Lighting for GGX+Smith Microsurfaces

General Microfacet-based BRDF

● Ξ©πœŒπ‘š 𝐿, 𝑉, π‘š 𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

𝑁⋅𝐿

π‘šβ‹…π‘‰

π‘β‹…π‘‰π‘‘π‘š

● Occlusion due to actual microfacetarrangement (actual shape)

● A.k.a. shadowing/masking function

● Probability microfacet π‘š sees bothlight 𝐿 and viewer 𝑉

Page 21: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 22: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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!

Page 23: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 πœƒπ‘š = π‘š β‹… 𝑁

Page 24: PBR Diffuse Lighting for GGX+Smith Microsurfaces

General Microfacet-based BRDF

● Ξ©πœŒπ‘š 𝐿, 𝑉, π‘š 𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

𝑁⋅𝐿

π‘šβ‹…π‘‰

π‘β‹…π‘‰π‘‘π‘š

● Probability density of having microfacet normal π‘š that is both lit and seen

● I.e., probability density of using BRDF πœŒπ‘š 𝐿, 𝑉, π‘š .

Page 25: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 26: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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!

Page 27: PBR Diffuse Lighting for GGX+Smith Microsurfaces

General Microfacet-based BRDF

● Related requirement:

Ξ©

𝐷 π‘š 𝐺1 𝑉, π‘š π‘š β‹… 𝑉 π‘‘π‘š = 𝑁 β‹… 𝑉

● In any direction 𝑉, total visible microfacet area equals macrosurface area

Page 28: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 29: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 π›Ώπ‘š 𝐻, π‘š

Page 30: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 31: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● General case: Ω𝜌 𝐿, 𝑉, 𝑁 cos πœƒπ‘‰ 𝑑𝑉 = 1

● Our case: Ξ©π‘˜π›Ώπ‘š 𝐻, π‘š cos πœƒπ‘‰

𝑑𝑉

π‘‘π‘šπ‘‘π‘š = 1

● Must integrate over π‘‘π‘š to evaluate π›Ώπ‘š, so find 𝑑𝑉

π‘‘π‘što change integration domain

Page 32: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

●𝑑𝑉

π‘‘π‘šis how fast 𝑉 changes relative to π‘š

● This will introduce PBR specular’s 4!

● Next few slides show how

Page 33: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● We’re going to find π‘‘π‘š from 𝑑𝑉 to get 𝑑𝑉

π‘‘π‘š

● First, π›Ώπ‘š picks π‘š = 𝐻, so π‘‘π‘š = 𝑑𝐻

● All vectors sketchedon unit hemisphere

𝐿

𝑉

𝐻𝑑𝑉

π‘‘π‘š = 𝑑𝐻

Page 34: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● Move solid angle 𝑑𝑉...

𝑉𝑑𝑉

Page 35: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● Move solid angle 𝑑𝑉 to 𝐿 + 𝑉...

𝐿

𝑉𝑑𝑉

𝑑𝑉

Page 36: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● Move solid angle 𝑑𝑉 to 𝐿 + 𝑉, scale by...

● 𝐿 + 𝑉 sphere: 𝐻 β‹… 𝑉

𝑉𝑑𝑉

𝑑𝑉

𝐻

Page 37: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● Move solid angle 𝑑𝑉 to 𝐿 + 𝑉, scale by...

● 𝐿 + 𝑉 sphere: 𝐻 β‹… 𝑉

● Unit sphere: 4πœ‹ 12

4πœ‹ 𝐿+𝑉 2 =1

𝐿+𝑉 2

𝑑𝑉

Page 38: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● Move solid angle 𝑑𝑉 to 𝐿 + 𝑉, scale by...

● 𝐿 + 𝑉 sphere: 𝐻 β‹… 𝑉

● Unit sphere: 4πœ‹ 12

4πœ‹ 𝐿+𝑉 2 =1

𝐿+𝑉 2

● π‘‘π‘š =𝐻⋅𝑉

𝐿+𝑉 2 𝑑𝑉 𝐻

𝑑𝑉

π‘‘π‘š

Page 39: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● Move solid angle 𝑑𝑉 to 𝐿 + 𝑉, scale by...

● 𝐿 + 𝑉 sphere: 𝐻 β‹… 𝑉

● Unit sphere: 4πœ‹ 12

4πœ‹ 𝐿+𝑉 2 =1

𝐿+𝑉 2

● π‘‘π‘š =𝐻⋅𝑉

𝐿+𝑉 2 𝑑𝑉𝐿

𝑉

𝐻𝑑𝑉

𝑑𝑉

π‘‘π‘š

Page 40: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● 𝐿 + 𝑉 = 𝐻 β‹… 𝐿 + 𝑉 = 𝐻 β‹… 𝐿 + 𝐻 β‹… 𝑉 = 2𝐻 β‹… 𝑉

● This 2 squared is specular BRDF’s 4!

● π‘‘π‘š =𝐻⋅𝑉

𝐿+𝑉 2 𝑑𝑉 =𝐻⋅𝑉

4 𝐻⋅𝑉 2 𝑑𝑉

●𝑑𝑉

π‘‘π‘š= 4𝐻 β‹… 𝑉

𝐿

𝑉

𝐻

Page 41: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular BRDF normalization

● Ξ©π‘˜π›Ώπ‘š 𝐻, π‘š cos πœƒπ‘‰

𝑑𝑉

π‘‘π‘šπ‘‘π‘š = 1

● Ξ©π‘˜π›Ώπ‘š 𝐻, π‘š π‘š β‹… 𝑉 4𝐻 β‹… 𝑉 π‘‘π‘š = 1

● π‘˜ =1

4 𝐻⋅𝐿 𝐻⋅𝑉since π‘š = 𝐻 and 𝐻 β‹… 𝑉 = 𝐻 β‹… 𝐿

● So, pure mirror BRDF: π›Ώπ‘š 𝐻,π‘š

4 𝐻⋅𝐿 𝐻⋅𝑉

Page 42: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular Microfacet BRDF

● Only the Fresnel reflection fraction 𝐹(𝐿, π‘š)of incoming light does specular reflection

● So, final specular microfacet BRDF:

πœŒπ‘š 𝐿, 𝑉, π‘š = 𝐹(𝐿, π‘š)𝛿𝐻(π‘š)

4 𝐻 β‹… 𝐿 𝐻 β‹… 𝑉

Page 43: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Specular Microfacet BRDF

● Ξ©πœŒπ‘š 𝐿, 𝑉, π‘š 𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

Nβˆ™L

π‘šβ‹…π‘‰

Nβˆ™Vπ‘‘π‘š

● Ξ©

𝐹(𝐿,π‘š)π›Ώπ‘š(𝐻,π‘š)

4 𝐻⋅𝐿 𝐻⋅𝑉𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

𝑁⋅𝐿

π‘šβ‹…π‘‰

π‘β‹…π‘‰π‘‘π‘š

● π›Ώπ‘š(𝐻, π‘š) eliminates integral and sets π‘š = 𝐻

● Specular BRDF: 𝐹(𝐿,𝐻)𝐷 𝐻 𝐺2 𝐿,𝑉,𝐻

4 𝑁⋅𝐿 𝑁⋅𝑉

Page 44: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Microfacet BRDF sub-topic map

● General form

● How we get PBR specular from that

● Extend to diffuse BRDF

Page 45: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Diffuse Microfacet BRDF

● Ξ©πœŒπ‘š 𝐿, 𝑉, π‘š 𝐷 π‘š 𝐺2 𝐿, 𝑉, π‘š

π‘šβ‹…πΏ

Nβˆ™L

π‘šβ‹…π‘‰

Nβˆ™Vπ‘‘π‘š

● Lambertian diffuse: πœŒπ‘š 𝐿, 𝑉, π‘š =1

πœ‹

● No dirac delta to eliminate integral

● No closed form solution for GGX+Smith

Page 46: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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)

Page 47: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Direct only

Albedo:0.75,0.5,0.25

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 48: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Direct plus indirect

Albedo:0.75,0.5,0.25

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 49: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Indirect only

Albedo:0.75,0.5,0.25

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 50: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Side-by-side

Albedo:0.75,0.5,0.25

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 51: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Importance of proper albedo

Top:Correct

Bottom:Albedo Γ— 0.5,Light Γ— 2

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 52: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Importance of proper albedo

Top:Correct

Bottom:Albedo Γ— 2,Light Γ— 0.5

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 53: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Road map for today’s talk

● General microfacet-based BRDFs

● Simulating diffuse for GGX+Smith microfacet model

● Comparing to other diffuse BRDFs

Page 54: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 55: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 56: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 57: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 58: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 59: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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%

Page 60: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 61: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 𝑉 = 𝑁

Page 62: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 63: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Uncorrelated vs. Correlated G

Page 64: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 65: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Exact vs. Approx Correlated G

Page 66: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Height Correlated G Uncorrelated G Difference

Page 67: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 𝐿 = 𝑉

Page 68: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 69: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith Shadowing/Masking

● Assumes all normals equally occluded

● I.e., 𝐺1 and 𝐺2 don’t depend on π‘š

● Most balanced assumption possible

Page 70: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith Shadowing/Masking

● Can derive from normalization constraint:

𝐺1 𝑉 Ξ©

𝐷 π‘š π‘š β‹… 𝑉 π‘‘π‘š = 𝑁 β‹… 𝑉

● Can also derive from ray-tracing a probabilistic heightfield

Page 71: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 72: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith Shadowing/Masking

Polar normal π‘š; PDF 𝐷 π‘š

π‘š

Page 73: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith Shadowing/Masking

2D slope 𝑝, π‘ž; PDF 𝑃22 𝑝, π‘ž

Polar normal π‘š; PDF 𝐷 π‘š

π‘š

𝑝, π‘ž, 1

Page 74: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith Shadowing/Masking

2D slope 𝑝, π‘ž; PDF 𝑃22 𝑝, π‘ž

Polar normal π‘š; PDF 𝐷 π‘š

π‘šAll 𝑝 for π‘ž

𝑝, π‘ž, 1

π‘ž

Page 75: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith Shadowing/Masking

1D slope π‘ž; PDF 𝑃2 π‘ž

2D slope 𝑝, π‘ž; PDF 𝑃22 𝑝, π‘ž

Polar normal π‘š; PDF 𝐷 π‘š

π‘š

π‘ž

𝑝, π‘ž, 1

All 𝑝 for π‘ž

Page 76: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith: Arbitrary 𝐷(π‘š)

● 𝑃22 𝑝, π‘ž = cos4 πœƒπ‘š 𝐷 π‘š

● 𝑃2 π‘ž = βˆ’βˆž

βˆžπ‘ƒ22 𝑝, π‘ž 𝑑𝑝

● Ξ› πœ‡ =1

πœ‡ πœ‡

∞(π‘ž βˆ’ πœ‡)𝑃2(π‘ž) π‘‘π‘ž

● 𝐺1 𝑉 =1

1+Ξ› 𝑉𝐺2 𝐿, 𝑉 =

1

1+Ξ› 𝐿 +Ξ› 𝑉

Page 77: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 𝑉

Page 78: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 79: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 80: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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!

Page 81: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 82: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 83: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 84: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 𝑁⋅𝐿 𝑁⋅𝑉 , 𝑁⋅𝐿 + 𝑁⋅𝑉 ,𝛼

Page 85: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 86: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 87: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 88: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Uncorrelated G Approximation

Difference Image:

Red = correlationGreen = approximation

Page 89: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Correlated G Approximation

Difference Image:

Relative to uncorrelated approximation

Page 90: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Correlated G Exact

Difference Image:

Relative tocorrelated approximation

Page 91: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 92: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith Microsurface Heightfields

● Example 1D heightfieldfrom Smith ray tracingderivation sketch inWalter 2007

Page 93: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Smith Microsurface Heightfields

● Derivation *also* uses 1D heightfield of mostly independent slabsnearing zero width

● Only forbids suddenlybeing under heightfield

π‘‘πœlimπ‘‘πœβ†’0

𝜏 β†’

Page 94: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 95: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 96: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 97: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 98: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 99: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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!

Page 100: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Cause of asymmetric BRDF

● Essentially had a merged BRDF:

● 𝜌 = 𝐹 𝐿, 𝑁 πœŒπ‘ π‘π‘’π‘ + 1 βˆ’ 𝐹 𝐿, 𝑁 πœŒπ‘‘π‘–π‘“π‘“

● Fresnel interpolation asymmetric!

● How to fix in a physically plausible way?

Page 101: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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!

Page 102: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 103: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 πœƒ

πœƒ

Page 104: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Lambertian diffuse explained

● Light enters, bounces around, exits

● Exit direction is random after many bounce events

● Albedo comes from frequency-dependent absorption events

Page 105: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Fixing diffuse for symmetric BRDF

● Entering uses Fresnel for reflection/transmission

● Exiting assumes always transmit

● Exiting needs Fresnel too!

Page 106: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 107: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 108: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 109: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Finally!

● Now have everything needed for path tracing simulation, resulting in...

Page 110: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Simulation with spec

Albedo:0.75,0.5,0.25

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 111: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Simulation diffuse only

Albedo:0.75,0.5,0.25

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 112: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Approximate diffuse only

Albedo:0.75,0.5,0.25

𝛼 = 02 0.252 0.52 0.752 12

0Β°

90Β°

135Β°

Page 113: PBR Diffuse Lighting for GGX+Smith Microsurfaces

GGX Diffuse Approximation

● π‘“π‘Žπ‘π‘–π‘›π‘” = 0.5 + 0.5 𝐿 β‹… 𝑉

● π‘Ÿπ‘œπ‘’π‘”β„Ž = π‘“π‘Žπ‘π‘–π‘›π‘” 0.9 βˆ’ 0.4π‘“π‘Žπ‘π‘–π‘›π‘”0.5+𝑁⋅𝐻

𝑁⋅𝐻

● π‘ π‘šπ‘œπ‘œπ‘‘β„Ž = 1.05 1 βˆ’ 1 βˆ’ 𝑁 β‹… 𝐿 5 1 βˆ’ 1 βˆ’ 𝑁 β‹… 𝑉 5

● 𝑠𝑖𝑛𝑔𝑙𝑒 =1

πœ‹π‘™π‘’π‘Ÿπ‘ π‘ π‘šπ‘œπ‘œπ‘‘β„Ž, π‘Ÿπ‘œπ‘’π‘”β„Ž, 𝛼

● π‘šπ‘’π‘™π‘‘π‘– = 0.1159𝛼

● 𝑑𝑖𝑓𝑓𝑒𝑠𝑒 = π‘Žπ‘™π‘π‘’π‘‘π‘œ βˆ— 𝑠𝑖𝑛𝑔𝑙𝑒 + π‘Žπ‘™π‘π‘’π‘‘π‘œ βˆ— π‘šπ‘’π‘™π‘‘π‘–

Page 114: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Aside: Useful shader identities

● 𝐿 + 𝑉 2 = 2 + 2𝐿 β‹… 𝑉

● 0.5 + 0.5𝐿 β‹… 𝑉 =1

4𝐿 + 𝑉 2

● 𝑁 β‹… 𝐻 =𝑁⋅𝐿+𝑁⋅𝑉

𝐿+𝑉

● 𝐿 β‹… 𝐻 = 𝑉 β‹… 𝐻 =1

2𝐿 + 𝑉

Page 115: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 116: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Aside: Useful shader identities

● π‘™π‘’π‘›π‘†π‘ž_𝐿𝑉 = 2 + 2 𝐿 β‹… 𝑉

● π‘Ÿπ‘π‘πΏπ‘’π‘›_𝐿𝑉 = π‘Ÿπ‘ π‘žπ‘Ÿπ‘‘ π‘™π‘’π‘›π‘†π‘ž_𝐿𝑉

● 𝑁 β‹… 𝐻 = 𝑁 β‹… 𝐿 + 𝑁 β‹… 𝑉 βˆ— π‘Ÿπ‘π‘πΏπ‘’π‘›_𝐿𝑉

● 𝐿 β‹… 𝐻 = 𝑉 β‹… 𝐻 = π‘Ÿπ‘π‘πΏπ‘’π‘›πΏπ‘‰ + π‘Ÿπ‘π‘πΏπ‘’π‘›πΏπ‘‰ βˆ— 𝐿 β‹… 𝑉● (Since 𝐿 β‹… 𝐻 =

1

2𝐿 + 𝑉 =

1

22 + 2𝐿 β‹… 𝑉 =

1

2

2+2𝐿⋅𝑉

2+2𝐿⋅𝑉= (1 + 𝐿 β‹… 𝑉)

1

2+2𝐿⋅𝑉)

Page 117: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 118: PBR Diffuse Lighting for GGX+Smith Microsurfaces

But First…

● It’s good to quickly understand Disney’s BRDF slices

Page 119: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 120: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 (πœƒβ„Ž)

Page 121: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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Β°

Page 122: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Retr

ore

flection

Disney’s BRDF slices

πœƒβ„Ž

πœƒπ‘‘

Fresnel

Specula

r

𝑁 β‹… 𝐻

𝐿 β‹… 𝐻; 𝐿 β‹… 𝑉

Equal

Opposite

Perpendicular

Specular Silhouette

Page 123: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Behavior of πœƒβ„Ž , πœƒπ‘‘ , πœ™π‘‘ on spheres

πœƒβ„Ž; 𝑁 β‹… 𝐻 πœ™π‘‘πœƒπ‘‘; 𝐿 β‹… 𝐻; 𝐿 β‹… 𝑉

Page 124: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Disney’s BRDF slices

● Various identities:

● cos πœƒβ„Ž = 𝑁 β‹… 𝐻

● cos πœƒπ‘‘ = 𝐿 β‹… 𝐻 = 𝑉 β‹… 𝐻 cos 2πœƒπ‘‘ = 𝐿 β‹… 𝑉

● cos πœ™π‘‘ =π‘β‹…π‘‰βˆ’π‘β‹…πΏ

2βˆ’2𝐿⋅𝑉 1βˆ’ 𝑁⋅𝐻 2

● BRDFs mostly functions of 𝑁 β‹… 𝐻 and 𝐿 β‹… 𝑉!

Page 125: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Almost ready to compare BRDFs!

● First, introduce the comparison format

Page 126: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New Model

Title says which diffuse model is shown. This intro uses the new model

Page 127: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New Model

This panel shows the same lit spheres as previous examples.

Page 128: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New Model

The matching BRDF slices are here (uncorrelated G)

Page 129: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 130: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Lambert

Page 131: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Disney

Page 132: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Oren Nayar, 𝜎 = 0.5𝛼

Page 133: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New model

Page 134: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New model (hybrid)

Smooth uses Disney’s 𝑓𝑑90 = 0.5, so same as Disney when 𝛼 = 0

Page 135: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New model (cheaper)

Smooth uses Lambert

Page 136: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Lambert

Page 137: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Disney

Page 138: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New model

Page 139: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Lambert

Page 140: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Disney

Page 141: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New model

Page 142: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Lambert

Page 143: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Disney

Page 144: PBR Diffuse Lighting for GGX+Smith Microsurfaces

New model

Page 145: PBR Diffuse Lighting for GGX+Smith Microsurfaces

Special Thanks

● Mark Cerny

● GDC mentor

● Chad Barb, Xin Liu, Steve Marton

● Fellow Respawn engineers with awesome ideas/feedback in this research (as always)

Page 146: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 148: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 149: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 150: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 πœ‰

Page 151: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 152: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 π‘ž π‘‘π‘ž

Page 153: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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+πœ‡ πœπ‘†

Page 154: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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+πœ‡ 𝜏

Page 155: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 + πœ‡πœ

Ξ› πœ‡

Page 156: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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+Ξ› πœ‡

Page 157: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 158: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 159: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 πœƒπ‘š

Page 160: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 πœƒ π‘‘π‘π‘‘π‘ž

Page 161: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 162: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 𝑝, π‘ž π‘‘π‘π‘‘π‘ž

Page 163: PBR Diffuse Lighting for GGX+Smith Microsurfaces

𝑃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

Page 164: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 165: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 166: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 167: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 168: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 169: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 170: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 171: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 172: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 173: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 174: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 175: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 176: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 177: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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).

Page 178: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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βˆ’π‘Œ

Page 179: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 180: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 181: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 182: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 183: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 184: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 185: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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πœƒ.

Page 186: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 187: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 188: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 πœƒ

Page 189: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.

Page 190: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 π‘š.

Page 191: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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 πœŒπ‘‘.

Page 192: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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

Page 193: PBR Diffuse Lighting for GGX+Smith Microsurfaces

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.