Indirect Illumination
Michael Kazhdan
(601.457/657)
HB Ch. 14.1, 14.2
FvDFH 16.1, 16.2
Surface Illumination Calculation• Multiple light source:
𝑁𝑁
𝐿𝐿1
𝐿𝐿2
𝑉𝑉
Viewer
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿
Overview• Direct Illumination
Emission at light sources Direct light at surface points
• Global illumination Shadows Transmissions Inter-object reflections
Shadows• Shadow term tells if light sources are blocked
Cast ray towards each light source 𝐿𝐿𝑖𝑖 If the ray is blocked, do not consider the contribution of
the light.
Shadows• Shadow term tells if light sources are blocked
Cast ray towards each light source 𝐿𝐿𝑖𝑖 𝑆𝑆𝑖𝑖 = 0 if ray is blocked, 𝑆𝑆𝑖𝑖 = 1 otherwise
𝐿𝐿1
𝐿𝐿0
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿
ShadowTerm
• Shadow term tells if light sources are blocked Cast ray towards each light source 𝐿𝐿𝑖𝑖 𝑆𝑆𝑖𝑖 = 0 if ray is blocked, 𝑆𝑆𝑖𝑖 = 1 otherwise
Shadows
𝑆𝑆0 = 1:𝐿𝐿0 contributes
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿
ShadowTerm
𝐿𝐿1
𝐿𝐿0
• Shadow term tells if light sources are blocked Cast ray towards each light source 𝐿𝐿𝑖𝑖 𝑆𝑆𝑖𝑖 = 0 if ray is blocked, 𝑆𝑆𝑖𝑖 = 1 otherwise
Shadows
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿
ShadowTerm
𝐿𝐿1
𝐿𝐿0
𝑆𝑆0 = 1:𝐿𝐿0 contributes
𝑆𝑆1 = 0:𝐿𝐿1 doesn’t contribute
Ray Casting• Trace primary rays from camera
Direct illumination from unblocked lights only
Recursive Ray Tracing• Also trace secondary rays from hit surfaces
Consider contributions from:1. Reflected Rays2. Refracted Rays
• Also trace secondary rays from hit surfaces Consider contributions from:
1. Reflected Rays2. Refracted Rays
Mirror Reflections
𝐿𝐿1
Recall:The specularity of a surface, 𝐾𝐾𝑆𝑆, measures how mirror-like it is.
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿
𝐿𝐿0
• Also trace secondary rays from hit surfaces Consider contributions from:
1. Reflected Rays2. Refracted Rays
Mirror Reflections
𝐿𝐿1
𝐿𝐿0
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅
Radiance for mirror
reflection ray
• Also trace secondary rays from hit surfaces Consider contributions from:
1. Reflected Rays2. Refracted Rays
Mirror Reflections
𝐿𝐿1
𝐿𝐿0
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅
Radiance for mirror
reflection ray
• Also trace secondary rays from hit surfaces Consider contributions from:
1. Reflected Rays2. Refracted Rays
Mirror Reflections
𝐿𝐿1
𝐿𝐿0
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅
Radiance for mirror
reflection ray
Mirror Reflections• Also trace secondary rays from hit surfaces
Consider contributions from:1. Reflected Rays2. Refracted Rays
Transparent Refraction• Also trace secondary rays from hit surfaces
Consider contributions from:1. Reflected Rays2. Refracted Rays
Radiance for refraction ray
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
𝐿𝐿1
𝐿𝐿0
Transparent Refraction• Also trace secondary rays from hit surfaces
Consider contributions from:1. Reflected Rays2. Refracted Rays
𝐿𝐿1
𝐿𝐿0
Radiance for refraction ray
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparent Refraction• Also trace secondary rays from hit surfaces
Consider contributions from:1. Reflected Rays2. Refracted Rays
𝐿𝐿1
𝐿𝐿0
Radiance for refraction ray
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparent Refraction• Also trace secondary rays from hit surfaces
Consider contributions from:1. Reflected Rays2. Refracted Rays
𝐿𝐿1
𝐿𝐿0
Radiance for refraction ray
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparent Refraction• Also trace secondary rays from hit surfaces
Consider contributions from:1. Reflected Rays2. Refracted Rays
𝐿𝐿1
𝐿𝐿0
Radiance for refraction ray
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparent Refraction• Also trace secondary rays from hit surfaces
Consider contributions from:1. Reflected Rays2. Refracted Rays
Transparency and Shadow• Problem:
If a surface is transparent, then rays to the light source may pass through the object
Over-shadowing
Transparency and Shadow• Problem:
If a surface is transparent, then rays to the light source may pass through the object
Need to modify the shadow term so that instead of representing a binary (0/1) value, it gives the fraction of light passing through.
⇒ Accumulate transparency values as the ray travels to the light source.
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparency and Shadow• Accumulate transparency values as the ray
travels to the light source.
𝑆𝑆0 = 1:𝐿𝐿0 contributes fully
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
𝐿𝐿1
𝐿𝐿0
Transparency and Shadow• Accumulate transparency values as the ray
travels to the light source.
𝐿𝐿1
𝐿𝐿0
𝑆𝑆0 = 1:𝐿𝐿0 contributes fully
𝑆𝑆1 =?:
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparency and Shadow• Accumulate transparency values as the ray
travels to the light source.
𝐾𝐾𝑇𝑇
𝐿𝐿1
𝐿𝐿0
𝑆𝑆0 = 1:𝐿𝐿0 contributes fully
𝑆𝑆1 = 1 ⋅ 𝐾𝐾𝑇𝑇 ⋅?:
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparency and Shadow• Accumulate transparency values as the ray
travels to the light source.
𝐾𝐾𝑇𝑇
𝐿𝐿1
𝐿𝐿0
𝑆𝑆0 = 1:𝐿𝐿0 contributes fully
𝑆𝑆1 = 1 ⋅ 𝐾𝐾𝑇𝑇 ⋅ 𝐾𝐾𝑇𝑇 ⋅?:
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparency and Shadow• Accumulate transparency values as the ray
travels to the light source.
𝐾𝐾𝑇𝑇
𝐿𝐿1
𝐿𝐿0
𝑆𝑆0 = 1:𝐿𝐿0 contributes fully
𝑆𝑆1 = 1 ⋅ 𝐾𝐾𝑇𝑇 ⋅ 𝐾𝐾𝑇𝑇:𝐿𝐿1 contributes partially
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparency and Shadow• Accumulate transparency values as the ray
travels to the light source.
KT
𝐿𝐿1
𝐿𝐿0
For solid models we can use the distance, 𝑑𝑑, travelled through the
surface instead: 𝑆𝑆 = 𝑒𝑒−𝑑𝑑⋅𝐾𝐾𝑇𝑇
𝑆𝑆0 = 1:𝐿𝐿0 contributes fully
𝑆𝑆1 = 1 ⋅ 𝐾𝐾𝑇𝑇 ⋅ 𝐾𝐾𝑇𝑇:𝐿𝐿1 contributes partially
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Transparency and Shadow• Accumulate transparency values as the ray
travels to the light source.
Transparent Refraction• When a light of light passes through a transparent
object, the ray of light can bend, (𝜃𝜃𝑖𝑖 ≠ 𝜃𝜃𝑟𝑟).
𝑁𝑁
𝐿𝐿
𝑇𝑇
𝜃𝜃𝑖𝑖
𝜃𝜃𝑟𝑟
Snell’s Law• The way that light bends is determined by the
indices of refraction of the internal and external materials 𝜂𝜂𝑖𝑖 and 𝜂𝜂𝑟𝑟:
The index of refraction of air is 𝜂𝜂 = 1.
𝑁𝑁
𝐿𝐿
𝑇𝑇
𝜃𝜃𝑖𝑖
𝜃𝜃𝑟𝑟
𝜂𝜂𝑟𝑟 ⋅ sin𝜃𝜃𝑟𝑟 = 𝜂𝜂𝑖𝑖 ⋅ sin𝜃𝜃𝑖𝑖
Snell’s Law• The way that light bends is determined by the
indices of refraction of the internal and external materials 𝜂𝜂𝑖𝑖 and 𝜂𝜂𝑟𝑟: 𝑁𝑁
𝐿𝐿
𝑇𝑇
𝜃𝜃𝑖𝑖
𝜃𝜃𝑟𝑟
𝜂𝜂𝑟𝑟 ⋅ sin𝜃𝜃𝑟𝑟 = 𝜂𝜂𝑖𝑖 ⋅ sin𝜃𝜃𝑖𝑖
Note (Critical Angle):
If 𝜂𝜂𝑖𝑖 > 𝜂𝜂𝑟𝑟 it is possible that 𝜂𝜂𝑖𝑖𝜂𝜂𝑟𝑟⋅ sin𝜃𝜃𝑖𝑖 > 1.
In this case:• There is no value of 𝜃𝜃𝑟𝑟 such that 𝜂𝜂𝑟𝑟 ⋅ sin𝜃𝜃𝑟𝑟 = 𝜂𝜂𝑖𝑖 ⋅ sin𝜃𝜃𝑖𝑖.• The light reflects off the surface and does not pass through.
Snell’s Law• The way that light bends is determined by the
indices of refraction of the internal and external materials 𝜂𝜂𝑖𝑖 and 𝜂𝜂𝑟𝑟: 𝑁𝑁
𝐿𝐿
𝑇𝑇
𝜃𝜃𝑖𝑖
𝜃𝜃𝑟𝑟
𝑇𝑇 =𝜂𝜂𝑖𝑖𝜂𝜂𝑟𝑟⋅ cos𝜃𝜃𝑖𝑖 − cos𝜃𝜃𝑟𝑟 ⋅ 𝑁𝑁 −
𝜂𝜂𝑖𝑖𝜂𝜂𝑟𝑟⋅ 𝐿𝐿
𝜂𝜂𝑟𝑟 ⋅ sin𝜃𝜃𝑟𝑟 = 𝜂𝜂𝑖𝑖 ⋅ sin𝜃𝜃𝑖𝑖
Snell’s Law• The way that light bends is determined by the
indices of refraction of the internal and external materials 𝜂𝜂𝑖𝑖 and 𝜂𝜂𝑟𝑟:
𝐿𝐿1
𝐿𝐿0
𝜂𝜂𝑟𝑟 ⋅ sin𝜃𝜃𝑟𝑟 = 𝜂𝜂𝑖𝑖 ⋅ sin𝜃𝜃𝑖𝑖
Snell’s Law• The way that light bends is determined by the
indices of refraction of the internal and external materials 𝜂𝜂𝑖𝑖 and 𝜂𝜂𝑟𝑟:
Snell’s Law and Caustics• Challenge:
If a surface is transparent, then rays to the light source may not travel along straight paths
⇒ For a given point of intersection, there may be multiple directions/paths a ray can travel to get to the light
⇒ Summing the intensity contribution from all of theses directions/paths we get bright caustics
This is difficult to address with ray-tracing
https://en.wikipedia.org/wiki/Caustic_(optics)
(Rough) Complexity Analysis• Simulating reflection and refraction in the ray
tracer, a ray splits into two at each bounce
𝐿𝐿1
𝐿𝐿0
CastReflectedRefracted
(Rough) Complexity Analysis• Simulating reflection and refraction in the ray
tracer, a ray splits into two at each bounce
𝐿𝐿1
𝐿𝐿0
CastReflectedRefracted
(Rough) Complexity Analysis• Simulating reflection and refraction in the ray
tracer, a ray splits into two at each bounce
𝐿𝐿1
𝐿𝐿0
CastReflectedRefracted
(Rough) Complexity Analysis• Simulating reflection and refraction in the ray
tracer, a ray splits into two at each bounce
𝐿𝐿1
𝐿𝐿0
CastReflectedRefracted
(Rough) Complexity Analysis• Simulating reflection and refraction in the ray
tracer, a ray splits into two at each bounce
𝐿𝐿1
𝐿𝐿0
CastReflectedRefracted
(Rough) Complexity Analysis• Simulating reflection and refraction in the ray
tracer, a ray splits into two at each bounce
𝐿𝐿1
𝐿𝐿0
CastReflectedRefracted
(Rough) Complexity Analysis• Simulating reflection and refraction in the ray
tracer, a ray splits into two at each bounce
⇒ Exponential growth in the number of rays as a function of the number of bounces
𝐿𝐿1
𝐿𝐿0
Note that we do not cast reflected rays from the interior of a shape.That is, if the dot-product of the surface normal
with the ray direction is positive
CastReflectedRefracted
Termination Criteria• How do we determine when to stop recursing?
If the ray bounces around too much If the contribution will be too small
Termination CriteriaPixel GetColor( scene , ray , ir , depth , cutOff ){
Pixel p(0,0,0)Ray reflect, refractIntersection hit = FindIntersection( ray , scene )if ( hit ){
p += GetSurfaceColor( hit.position )
reflect.direction = Reflect( ray.direction , hit.normal )reflect.position = hit.position + reflect.direction*εif( depth >0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec
refract.direction = Refract( ray.direction , hit.normal , ir , hit.ir )refract.position = hit.position + refract.direction*εif( depth >0 && hit.kTran>cutOff )
p += GetColor( scene , refract , hit.ir , depth-1 , cutOff/hit.kTran )*hit.kTran}return p
}
Pixel GetColor( scene , ray , ir , depth , cutOff ){
Pixel p(0,0,0)Ray reflect, refractIntersection hit = FindIntersection( ray , scene )if ( hit ){
p += GetSurfaceColor( hit.position )
reflect.direction = Reflect( ray.direction , hit.normal )reflect.position = hit.position + reflect.direction*εif( depth >0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec
refract.direction = Refract( ray.direction , hit.normal , ir , hit.ir )refract.position = hit.position + refract.direction*εif( depth >0 && hit.kTran>cutOff )
p += GetColor( scene , refract , hit.ir , depth-1 , cutOff/hit.kTran ) *hit.kTran}return p
}
Termination Criteria
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Pixel GetColor( scene , ray , ir , depth , cutOff ){
Pixel p(0,0,0)Ray reflect, refractIntersection hit = FindIntersection( ray , scene )if ( hit ){
p += GetSurfaceColor( hit.position )
reflect.direction = Reflect( ray.direction , hit.normal )reflect.position = hit.position + reflect.direction*εif( depth>0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec
refract.direction = Refract( ray.direction , hit.normal , ir , hit.ir )refract.position = hit.position + refract.direction*εif( depth >0 && hit.kTran>cutOff )
p += GetColor( scene , refract , hit.ir , depth-1 , cutOff/hit.kTran ) *hit.kTran}return p
}
Termination Criteria
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
if( depth>0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec;
The first reflected ray should be cast if it cancontribute an intensity greater than the cut-off.
⇒ 𝐾𝐾𝑆𝑆1 > cut-off
Termination Criteria
𝐿𝐿1
𝐿𝐿0
𝐾𝐾𝑆𝑆1
if( depth>0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec;
The second reflected ray should be cast if it cancontribute an intensity greater than the cut-off.
⇒ 𝐾𝐾𝑆𝑆2 ⋅ 𝐾𝐾𝑆𝑆1 > cut-off
⇔ 𝐾𝐾𝑆𝑆2 > cut-off𝐾𝐾𝑆𝑆1
Termination Criteria
𝐿𝐿1
𝐿𝐿0
𝐾𝐾𝑆𝑆1
𝐾𝐾𝑆𝑆2
if( depth>0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec;
The second reflected ray should be cast if it cancontribute an intensity greater than the cut-off.
⇒ 𝐾𝐾𝑆𝑆2 ⋅ 𝐾𝐾𝑆𝑆1 > cut-off
⇔ 𝐾𝐾𝑆𝑆2 > cut-off𝐾𝐾𝑆𝑆1
⇒ The second reflected rayshould be cast if it can reflectat least cut-off
𝐾𝐾𝑆𝑆1 of the local intensity
Termination Criteria
𝐿𝐿1
𝐿𝐿0
𝐾𝐾𝑆𝑆1
𝐾𝐾𝑆𝑆2
Pixel GetColor( scene , ray , ir , depth , cutOff ){
Pixel p(0,0,0)Ray reflect, refractIntersection hit = FindIntersection( ray , scene )if ( hit ){
p += GetSurfaceColor( hit.position )
reflect.direction = Reflect( ray.direction , hit.normal )reflect.position = hit.position + reflect.direction*εif( depth>0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec
refract.direction = Refract( ray.direction , hit.normal , ir , hit.ir )refract.position = hit.position + refract.direction*εif( depth>0 && hit.kTran>cutOff )
p += GetColor( scene , refract , hit.ir , depth-1 , cutOff/hit.kTran )*hit.kTran}return p
}
Termination Criteria
𝐼𝐼 = 𝐼𝐼𝐸𝐸 + �𝐿𝐿
𝐾𝐾𝐴𝐴 ⋅ 𝐼𝐼𝐿𝐿𝐴𝐴 + 𝐾𝐾𝐷𝐷 ⋅ 𝑁𝑁, 𝐿𝐿 + 𝐾𝐾𝑆𝑆 ⋅ 𝑉𝑉,𝑅𝑅 𝑛𝑛 ⋅ 𝐼𝐼𝐿𝐿 ⋅ 𝑆𝑆𝐿𝐿 + 𝐾𝐾𝑠𝑠 ⋅ 𝐼𝐼𝑅𝑅 + 𝐾𝐾𝑇𝑇 ⋅ 𝐼𝐼𝑇𝑇
Pixel GetColor( scene , ray , ir , depth , cutOff ){
Pixel p(0,0,0)Ray reflect, refractIntersection hit = FindIntersection( ray , scene )if ( hit ){
p += GetSurfaceColor( hit.position )
reflect.direction = Reflect( ray.direction , hit.normal )reflect.position = hit.position + reflect.direction*εif( depth>0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec
refract.direction = Refract( ray.direction , hit.normal , ir , hit.ir )refract.position = hit.position + refract.direction*εif( depth>0 && hit.kTran>cutOff )
p += GetColor( scene , refract , hit.ir , depth-1 , cutOff/hit.kTran )*hit.kTran}return p
}
Termination Criteria
Why do we add a small amount of the direction to the position?
To ensure that the new ray does not hit its starting location!
Pixel GetColor( scene , ray , ir , depth , cutOff ){
Pixel p(0,0,0)Ray reflect, refractIntersection hit = FindIntersection( ray , scene )if ( hit ){
p += GetSurfaceColor( hit.position )
reflect.direction = Reflect( ray.direction , hit.normal )reflect.position = hit.position + reflect.direction*εif( depth>0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec
refract.direction = Refract( ray.direction , hit.normal , ir , hit.ir )refract.position = hit.position + refract.direction*εif( depth>0 && hit.kTran>cutOff )
p += GetColor( scene , refract , hit.ir , depth-1 , cutOff/hit.kTran )*hit.kTran}return p
}
Termination Criteria
Warning:In practice, cutOff is a scalar while hit.kTran/kSpec are RGB values.
Pixel GetColor( scene , ray , ir , depth , cutOff ){
Pixel p(0,0,0)Ray reflect, refractIntersection hit = FindIntersection( ray , scene )if ( hit ){
p += GetSurfaceColor( hit.position )
reflect.direction = Reflect( ray.direction , hit.normal )reflect.position = hit.position + reflect.direction*εif( depth>0 && hit.kSpec>cutOff )
p += GetColor( scene , reflect , ir , depth-1 , cutOff/hit.kSpec )*hit.kSpec
refract.direction = Refract( ray.direction , hit.normal , ir , hit.ir )refract.position = hit.position + refract.direction*εif( depth>0 && hit.kTran>cutOff )
p += GetColor( scene , refract , hit.ir , depth-1 , cutOff/hit.kTran )*hit.kTran}return p
}
Termination Criteria
Note:When we refract, we enter a new material and the associated index of refraction changes.
Illumination Examples• Ray tracing (rays to point light source)
Courtesy Henrik Wann Jensen
• Soft shadows (rays to area light source)
Illumination Examples
Courtesy Henrik Wann Jensen
Illumination Examples• Caustics (rays from light source)
Courtesy Henrik Wann Jensen
• Full Global Illumination
Illumination Examples
Courtesy Henrik Wann Jensen
• GetColor calls itself recursively
Recursive Ray Tracing
Image RayTrace( Camera camera , Scene scene ,int width , int height ,int depth , float cutOff )
{Image image = new Image( width , height );for( int i=0 ; i<width ; i++ ) for( int j=0 ; j<height ; j++ ){
Ray ray = ConstructRayThroughPixel( camera , i , j );image[i][j] = GetColor( scene , ray , 1 , depth , cutOff );
}return image;
}
Summary• Ray casting (direct Illumination)
Use simple analytic approximations for light source emission and surface reflectance
• Recursive ray tracing (global illumination) Incorporate shadows, mirror reflections,
and pure refractions
More on global illumination later!
All of this is an approximationso that it is practical to compute