0% found this document useful (0 votes)
16 views36 pages

Class 06 Recursive Ray Tracing

Uploaded by

suuukiyaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views36 pages

Class 06 Recursive Ray Tracing

Uploaded by

suuukiyaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Recursive Ray Tracing

Reflection and Transmission


• A shadow ray is cast to each light source, and the total contribution from all unobscured light
sources is accumulated:
𝑘𝑅 , 𝑘𝐺 , 𝑘𝐵 𝐿𝑑𝑖𝑓𝑓𝑢𝑠𝑒 + 𝐿𝑎𝑚𝑏𝑖𝑒𝑛𝑡 + 𝐿𝑟𝑒𝑓𝑙𝑒𝑐𝑡 + 𝐿𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡
𝐿𝑑𝑖𝑓𝑓𝑢𝑠𝑒 = ෍ 𝑉𝑙𝑖𝑔ℎ𝑡 𝐼𝑙𝑖𝑔ℎ𝑡 max 0, cos 𝜃𝑙𝑖𝑔ℎ𝑡
𝑙𝑖𝑔ℎ𝑡𝑠

𝐿𝑎𝑚𝑏𝑖𝑒𝑛𝑡 = 𝐼𝑎𝑚𝑏𝑖𝑒𝑛𝑡 ෑ 1 − 𝑉𝑙𝑖𝑔ℎ𝑡


𝑙𝑖𝑔ℎ𝑡𝑠
• 𝑉𝑙𝑖𝑔ℎ𝑡 = 1 for visible light sources, and 𝑉𝑙𝑖𝑔ℎ𝑡 = 0 for occluded light sources
• 𝐼𝑎𝑚𝑏𝑖𝑒𝑛𝑡 is added to fully shadowed regions where ς𝑙𝑖𝑔ℎ𝑡𝑠 1 − 𝑉𝑙𝑖𝑔ℎ𝑡 ≠ 0

• Mirror-like reflection can also contribute to the color at an intersection point


• Transparency allows other objects to be seen through a surface, allowing those objects to
contribute to the color as well
Scaling Coefficients
• Scaling coefficients are added in front of every lighting contribution
𝑘𝑅 , 𝑘𝐺 , 𝑘𝐵 𝑘𝑑 𝐿𝑑𝑖𝑓𝑓𝑢𝑠𝑒 + 𝑘𝑎 𝐿𝑎𝑚𝑏𝑖𝑒𝑛𝑡 + 𝑘𝑟 𝐿𝑟𝑒𝑓𝑙𝑒𝑐𝑡 + 𝑘𝑡 𝐿𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡
• These coefficients are first adjusted relative to each other to get the desired “look”
• Then, all the coefficients are scaled together for overall brightness/darkness
• Note: each term adds light to the image, making it brighter (so it might over-saturate)

less reflection (darker) more reflection (brighter)


Recursion
• 𝐿𝑟𝑒𝑓𝑙𝑒𝑐𝑡 and 𝐿𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 are treated in the same way that pixel color is treated

• A ray is constructed for the reflection direction and intersected with scene geometry (just like
what is done for camera rays through pixels)
• The result is stored in 𝐿𝑟𝑒𝑓𝑙𝑒𝑐𝑡
• A ray is constructed for the transmission direction and intersected with scene geometry (just
like what is done for camera rays through pixels)
• The result is stored in 𝐿𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡

• 𝐿𝑟𝑒𝑓𝑙𝑒𝑐𝑡 and 𝐿𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 depend on the color computed from the geometry that their rays
intersected
• Those intersection points have colors of their own, also computed via: shadow rays, ambient
and diffuse shading, and additional reflection and transmission
• Thus, even more rays need to be spawned
Ray Tree Example
Code Simplicity
• Recursion allows for stunning imagery with minimal code, as demonstrated by these 1337
characters printed on the back of a business card

http://fabiensanglard.net/rayTracing_back_of_business_card/
Termination
• If every intersected point continued to depend on reflected/transmitted rays, rays would be
spawned indefinitely
• Eventually, one hits the recursion limit (depending on hardware) that prevents stack overflow

• If 𝑘𝑑 and 𝑘𝑎 are frequently nonzero, their contributions diminish as the depth of the
reflected/transmitted ray hierarchy increases; so, can eventually terminate the recursion (with
imperceptible error)
• Terminate by using an arbitrary value for 𝐿𝑟𝑒𝑓𝑙𝑒𝑐𝑡 and/or 𝐿𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 (without tracing the
associated ray)

• When there is not enough ambient/diffuse lighting (e.g. mirrors, bubbles, etc.), nearly 100%
of the lighting is sought recursively via reflected/transmitted rays
• Then, the arbitrary values can show up in the pixel color (which is undesirable)
• So, choose realistic termination colors when possible (common choices: sky color, background
color, etc.)
Reflected Ray
• Given an incoming ray 𝑅 𝑡 = 𝐴 + 𝐷𝑡, and (outward) unit normal 𝑁, ෡ the angle of incidence is
෡ = − 𝐷 2 cos 𝜃𝑖
defined via 𝐷 ⋅ 𝑁
෡ i.e. 𝜃𝑜 = 𝜃𝑖
• Mirror reflection: incoming/outgoing rays make the same angle with 𝑁,
• Note: all the rays and the normal are all coplanar
෡ 𝑁
• Reflected ray direction: 𝐷𝑟𝑒𝑓𝑙𝑒𝑐𝑡 = 𝐷 − 2 𝐷 ⋅ 𝑁 ෡
• Reflected ray: 𝑅𝑟𝑒𝑓𝑙𝑒𝑐𝑡 𝑡 = 𝑅 𝑡𝑖𝑛𝑡 + 𝐷𝑟𝑒𝑓𝑙𝑒𝑐𝑡 𝑡
Recall: Fixing Spurious Self-Occlusion
• A simple solution is to use 𝑡 ∈ (𝜖, 𝑡𝑙𝑖𝑔ℎ𝑡 ) for some 𝜖 > 0 large enough to avoid numerical
precision issues
• This works well for many cases
• However, grazing shadow rays may still incorrectly re-intersect the object
Spurious Self-Occlusion
• Perturb the starting point of the reflected ray to 𝑅 𝑡𝑖𝑛𝑡 + 𝜖 𝑁෡
• The ray direction does not need to be modified (dissimilar to shadow rays)
• The new reflected ray is 𝑅𝑟𝑒𝑓𝑙𝑒𝑐𝑡 (𝑡) = 𝑅 𝑡𝑖𝑛𝑡 + 𝜖𝑁 ෡ + 𝐷𝑟𝑒𝑓𝑙𝑒𝑐𝑡 𝑡 with 𝑡 ∈ [0, ∞)
• Need to be careful that the new starting point isn’t inside (or too close to) any other geometry
Reflections
Transmission
• The angle of incidence and angle of transmission (or refraction) are related via Snell’s Law:
sin 𝜃1 𝜈1 𝑛2
sin 𝜃2
= 𝜈2
= 𝑛1
• Incoming/outgoing angles: 𝜃1 , 𝜃2 ; phase velocities: 𝜈1 , 𝜈2 ; indices of refraction: 𝑛1 , 𝑛2
Transmitted Ray
• 𝐷෡ is the (unit) incoming ray direction, 𝑁
෡ is the (outward) unit normal, and 𝑇෠ is the unit
tangent in the plane of 𝐷෡ and 𝑁,
෡ so that 𝐷෡ + 𝑁𝑐𝑜𝑠𝜃
෡ ෠
1 + 𝑇𝑠𝑖𝑛𝜃1 = 0
• 𝐷෡𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 is the (unit) transmitted ray direction, so 𝐷
෡𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 + 𝑇𝑠𝑖𝑛𝜃
෠ ෡
2 + 𝑁𝑐𝑜𝑠𝜃2 = 0
Transmitted Ray
𝑠𝑖𝑛𝜃2
෡𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 = −𝑇𝑠𝑖𝑛𝜃
• 𝐷 ෠ ෡ ෡ ෡
2 − 𝑁𝑐𝑜𝑠𝜃2 = 𝐷 + 𝑁𝑐𝑜𝑠𝜃1
෡ 1 − sin2 𝜃2
−𝑁
𝑠𝑖𝑛𝜃1
𝑛1 𝑛1 2
෡𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 = 𝐷
• Using Snell’s Law: 𝐷 ෡ + 𝑁𝑐𝑜𝑠𝜃
෡ 1
෡ 1−
−𝑁 𝑠𝑖𝑛𝜃1
𝑛2 𝑛2
2
𝐷 ෡ 𝑛1 + 𝑁
෡𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 = 𝐷 ෡ 𝑛1
𝑐𝑜𝑠𝜃1 − 1 −
𝑛1
1 − cos 2 𝜃1
𝑛2 𝑛2 𝑛2

𝑛1 𝑛1 𝑛1 2 2
෡ ⋅𝑁
𝑐𝑜𝑠𝜃1 = −𝐷 ෡ leads to 𝐷
෡𝑡𝑟𝑎𝑛𝑠𝑚𝑖𝑡 = 𝐷
෡ ෡
−𝑁 ෡ ⋅𝑁
𝐷 ෡+ 1− ෡⋅𝑁
1− 𝐷 ෡
𝑛2 𝑛2 𝑛2
• When the term under the square root is negative, there is no transmitted ray (all the light
comes from the reflected ray, i.e. total internal reflection)

Notes:
• This equation works regardless of whether 𝑛1 or 𝑛2 is bigger
• Add 𝜖 > 0 to avoid self intersection, or offset in the negative normal direction (while avoiding
other nearby geometry, etc.)
Total Internal Reflection
• When looking from a higher index of refraction material towards a lower index of refraction
material, there is no light transmission when the incident angle exceeds a critical angle
• In such a case, all the light comes from the reflected ray

when θ2 < θ2,max , both reflection and when θ2 > θ2,max , only reflection occurs
transmission occur
Critical Angle
𝜋
• 𝜃1 = is the maximum angle for transmission
2
𝜋 1 𝑛2 𝑛1
• sin = 1 and Snell’s Law becomes = or 𝜃2 = arcsin
2 sin 𝜃2 𝑛1 𝑛2
• Note: this can only occur when 𝑛1 < 𝑛2
Total Internal Reflection
• Responsible for many interesting and impressive visuals in both glass and water
Snell’s Window
• Yes, fish can see you standing on the shore!
Snell’s Window
Reflection vs. Transmission
• The amount of transmission vs. reflection decreases as the viewing angle goes from
perpendicular (overhead) to parallel (grazing)

Perpendicular (overhead) view: Parallel (grazing) view:


more transmission, less reflection more reflection, less transmission
Reflection vs. Transmission
• Even for opaque objects (that lack transmission), reflection behaves similarly

As the viewing angle changes from overhead to a grazing angle (from left to right), the amount of reflection
off of the table increases (and one can better see the book’s reflection)
Fresnel Equations
• The proportion of reflection gradually increases as the viewing angle goes from perpendicular
(coincident with the normal) to parallel (orthogonal to the normal)

Looking from air towards water Looking from water towards air
Fresnel Equations
• Light is polarized into 2 parts, based on whether the plane containing the incident, reflected,
refracted rays is parallel (p-polarized) or perpendicular (s-polarized) to the electric field
• The Fresnel equations approximate the fraction of light reflected as:

• Transmission (if it occurs) is calculated as the remaining light:


𝑇𝑝 = 1 − 𝑅𝑝 𝑇𝑠 = 1 − 𝑅𝑠

• For unpolarized light (a typical assumption in ray tracing), assume:

𝑅𝑝 +𝑅𝑠
𝑅= 𝑇 =1−𝑅
2
Schlick’s Approximation
• Approximate reflection via:

Fresnel (solid lines)


Schlick (dotted lines)
Conductors vs. Dielectrics
• Conductors (of electricity, e.g. metals) mostly reflect light (low absorption, no transmission)
• The amount reflected doesn’t change much with viewing angle
• see copper, aluminum, iron on the last slide
• Thus, 𝑘𝑟 can be approximated as a constant (independent of viewing direction) for conductors
• In contrast, 𝑘𝑟 varies significantly with viewing angle for dielectrics (e.g. glass, water)

Conductor Dielectric
Curved Surfaces
• The viewing angle can vary (from perpendicular to parallel) across the surface of an object
• The amount of reflection vs. transmission similarly varies
• Capturing this is especially important for dielectrics

Correct reflection vs. transmission Incorrect reflection vs. transmission


(based on viewing angle) (no dependence on viewing angle)
Attenuation
• Light is absorbed and scattered as it travels through material
• This attenuates the amount of light traveling along a straight line
• The amount of attenuation depends on the distance traveled (through the material)
• Different colors (actually, different wavelengths) are attenuated at different rates

Example:
• Shallow water is clear (almost no attenuation)
• Deeper water attenuates all the red light and looks bluish-green
• Even deeper water attenuates all the green light too, and looks dark blue
• Eventually all the light attenuates, and the color ranges from blackish-blue to black
Beer’s Law
• For homogeneous media, attenuation can be approximated by Beer’s Law
• Light with intensity 𝐼 is attenuated over a distance 𝑥 via the Ordinary Differential Equation
𝑑𝐼
(ODE): = −𝑐𝐼 where 𝑐 is the attenuation coefficient
𝑑𝑥
• This ODE has an exact solution: 𝐼 𝑥 = 𝐼𝑜 𝑒 −𝑐𝑥 where 𝐼𝑜 is the original amount of light
Beer’s Law
• The color of a transparent object can be described by three attenuation coefficients: 𝑐𝑅 , 𝑐𝐺 , 𝑐𝐵
• Shadow rays are also attenuated
Atmospheric Refraction
• As light passes though varying temperature (and thus varying density, and varying index of
refraction) gases, it bends continuously
• This causes light to follow a curved path
Inferior Mirage
Superior Mirage (March 2021, England)
Atmospheric Refraction
• Bend ray traced rays as they go through varying air densities
• Can change the ray direction between every interval in the vertical direction (left) or along the
ray direction (right)
Gravity bends light too!

http://www.wired.com/2014/10/astrophysics-interstellar-black-hole/
https://www.businessinsider.com/interstellar-anniversary-learned-about-black-holes-2019-11
Iridescence
• A surface can gradually change color as the viewing angle or the lighting changes
Iridescence
• Various light waves are emitted in the same direction giving constructive/destructive
interference

http://www.glassner.com/wp-content/uploads/2014/04/CG-CGA-PDF-00-11-Soap-Bubbles-2-Nov00.pdf

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy