cs354-4
cs354-4
Rendering: Reality
Eye acts as pinhole camera
• Algorithm:
1. For each pixel, trace primary ray in
direction V to the first visible surface.
2. For each intersection trace secondary
rays:
• Shadow in direction L to light sources
• Reflected in direction R
• Refracted (transmitted) in direction T
3. Calculate shading of pixel based on light
attenuation
Find First Object Hit By Ray
Collision detection: find all values of t
where ray hits object boundary
In-class Activity:
Use the plane equation to determine
where point Q is based on the ray origin P
and direction d ⃗ assuming we also know at
least one other point on this plane
N⋅Q+d=0
N ⋅ (P + d ⃗t) + d = 0
N ⋅ P + N ⋅ d ⃗t = − d
N ⋅ d ⃗t = − (d + N ⋅ P)
N⋅P+d
t=−
N ⋅ d⃗
Q = P + d ⃗t
Ray-Triangle Collision Detection
• Intersect ray with triangle’s supporting
plane:
N = (A - C)x(B - C)
• Check if inside triangle
How to Check if Inside?
• Using triangle edges
• Using barycentric coordinates
• Using projections
Ray-Triangle Collision Detection
Normal:
Ray-Triangle Collision Detection
Normal:
[(B-A)x(Q-A)]⋅n >= 0
[(C-B)x(Q-B)]⋅n >= 0
[(A-C)x(Q-C)]⋅n >= 0
• Used everywhere!
Barycentric Coordinates in 2D
Project down into 2D and compute
barycentric coordinates
Möller-Trumbore Triangle Intersect
• Introduced as an optimized triangle-ray intersection test
• Based on the barycentric parameterization
• Direction of ray intersection from ray origin becomes
3rd axis (uw are barycentric axes)
• Still commonly used
Not today.
Phong Shading Model
We’ll talk about the specific math behind
shading models later. For now, let’s
focus on the “ray-tracing” aspect of
shading…
Ray Tracing: Shading
(η is index of refraction)
What is this effect?
Total Internal Reflection
• Occurs if:
• ηi > ηt (index of refraction of current
medium > index of refraction of other
medium)
• ϴi > ϴc (angle of incidence > critical
angle)
• Critical angle is an angle of incidence that
provides an angle of refraction of 90°
• No transmission occurs — only reflection
Critical Angle in TIR
• If θt = 90°, light moves along boundary
surface
• If θt > 90°, light is reflected within current
medium
Light and Shadow Attenuation
Light attenuation:
• Light farther from the source contributes
less intensity
Shadow attenuation:
• If light source is blocked from point on an
object, object is in shadow
• Attenuation is 0 if completely blocked
• Some attenuation for translucent objects
Light Attenuation
Real light attenuation: inverse square law
So, we cheat:
d is light-to-point distance
Tweak constant & linear terms to taste:
1
fatten(d) =
a + bd + cd 2
Equation used in raytracing assignment
Shooting Shadow Rays
Local Illumination Redux
Simplifying assumptions:
• ignore everything except eye, light, and
object
• no shadows, reflections, etc
• only point lights
• only simple (diffuse & specular)
materials
Beyond Local Shading