2IV60 Computer graphics
set 11: Ray-tracing
Jack van Wijk
TU/e
John Tsiombikas
Caustic Graphics
Overview
Ray-tracing:
• Based on geometric optics;
• Mirroring, transparency, cast shadows;
• Many other effects…
• And very time consuming…
H&B 21-1:639-647
Ray casting (reprise)
Normalized view volume
z
Algorithm:
Per pixel:
- Calculate intersections
- Determine first
yv
xv
front =
visible
zv
pixel
View plane
H&B 21-1:639-647
Ray-tracing principle 1
light source
Ray-tracing:
opaque
projection point
mirroring
view plane
Mirroring and
transparent
H&B 21-1:639-647
Ray-tracing principle 2
light source
Ray-tracing:
projection point
pixel
view plane
H&B 21-1:639-647
Ray-tracing algorithm 1
var fbuf: array[N,N] of color;
{ frame-buffer }
For all 1<= i, j <=N do { for all pixels }
fbuf [i,j] := RayTrace((0,0,0),(i,j,d), 1)
projection point
pixel
d
H&B 21-1:639-647
Ray-tracing algorithm 2
function RayTrace(P: point; u:vector; level: integer): color;
if level > MaxLevel or GetIntersections (P, u, t, N) = 0
then return BkColor;
level := level+1;
P
col := famb*Iamb;
u
Q := P + ut;
if (L Q).N > 0 and GetIntersections (Q, L Q) = 0
then col := col + fdif*I
+ fspec*I*power(N.H(u,N), nspec);
col := col + fspec*Raytrace(Q, R(u,N), level);
col:= (1–ftra)*col + ftra*Raytrace(Q, T(u,N), level);
return col;
N
H
R
L
Q
T
H&B 21-1:639-647
Calculation intersections
function GetIntersections (P: point; u: vector; t: array of real;
N: array of vector): integer;
{ Get the intersections of a line with the scene }
For all objects do:
Calculate intersection points with surface;
Store the results in the arrays t and N,
sorted for t.
Return the number of intersection points.
Equation line:
P
u
t
X P ut
H&B 21-1:639-647
Line/Sphere intersections
Equation line:
X P ut (1)
Equation sphere:
(X C) (X C) r
2
(2)
Substitute (1) in (2):
P
u
t
Q
(P ut C) ( P ut C) r 2 , with P P C :
(P ut ) (P ut ) r 2 0, or
C
(u u)t 2 ( 2P u)t ( P P r 2 ) 0, or
t1,2
P u ( P u) 2 (u u)(P P r 2 )
u u
r
H&B 21-1:639-647
Line/polygon intersection
Equation line:
X P ut (1)
Equation plane polygon:
N X D (2)
Substitute (1) in (2):
N
P
u
t
Q
N (P ut ) D, or
N P N ut D, hence
t
D NP
Nu
Check if Q is inside polygon
H&B 21-1:639-647
Ray-tracing acceleration 1
Limit intersection calculations:
Hierarchy of Bounding Volumes
Bounding Boxes
Bounding Spheres
H&B 21-1:639-647
Ray-tracing acceleration 2
Limit intersection calculations:
Space-subdivision
Regular
Adaptive (Octtree, quadtree)
H&B 21-1:639-647
Aliasing 1
• Generic problem of raster graphics
• Shapes are continuous, pixels are discrete
• Jagged edges, Moiré patterns, flickering textures, …
• Especially annoying during animation
• More pixels?
• More samples!
Aliased
Anti-aliased
H&B 21-1:639-647
Aliasing 2
ray
pixel
1 ray/pixel: blocky patterns
H&B 21-1:639-647
Anti-aliasing 1
ray
pixel
average 5 rays/pixel:
smoother transitions
H&B 21-1:639-647
Anti-aliasing 2
ray
pixel
adaptive sampling:
more efficient, not fail save
H&B 21-1:639-647
Anti-aliasing 3
ray
pixel
dense patterns
give problems
H&B 21-1:639-647
Anti-aliasing 3
ray
pixel
dense patterns
give problems
H&B 21-1:639-647
Anti-aliasing 3
ray
pixel
dense patterns
give problems
H&B 21-1:639-647
Anti-aliasing 4
ray
pixel
random sampling gives
a better result
H&B 21-1:639-647
Anti-aliasing 4
ray
pixel
random sampling gives
a better result
H&B 21-1:639-647
Anti-aliasing 4
ray
pixel
random sampling gives
a better result
H&B 21-1:639-647
More optical effects…
Imperfect reflection
Non-point light source
Cook, Porter, Carpenter, 1984
Distributed ray tracing 1
Motion blur
Cook, Porter, Carpenter, 1984
Distributed ray tracing 1
• Monte Carlo sampling
• Typically 16 rays/pixel;
• Each ray is shifted along a small
random vector (jitter)
• rough reflecting surfaces, nonpoint light sources, depth of field,
motion blur
ray
pixel
H&B 21-1:651-653
Distributed ray tracing 2
R
L
P
• rough reflecting surfaces, nonpoint light sources, depth of
field, motion blur
u
T
H&B 21-1:651-653
Radiosity
• Surface-surface
interreflection
• Physically based simulation
• Calculate for each polygon
the balance between incoming
and outgoing light
• Important for architecture
and indoor scenes
Cornell box
Cohen et al., 1988
Finally
• That concludes our tour through the world
of 2D and 3D graphics
© Copyright 2026 Paperzz