Professional Documents
Culture Documents
Lecture 4 - Ray Tracing
Lecture 4 - Ray Tracing
Introduction
o Rendering 3D objects to 2D screen
n Input: set of objects
n Output: array of pixels
o Object-order rendering
n For each object, all the pixels that it influences are
found and calculated/updated
o Image-order rendering
n For each pixel, all the objects that influence it are
found and the pixel value is computed
o Both approaches can compute same image
o Different flexibility and performance
n Image-order rendering more flexible but slower
o Many others
n Mostly an extension of the above
o “My purpose here is to, once and for all, rid the world of the
misconception that a pixel is a little geometric square. This is not a
religious issue. This is an issue that strikes right at the root of correct
image (sprite) computing and the ability to correctly integrate
(converge) the discrete and the continuous. The little square model is
simply incorrect. It harms. It gets in the way. If you find yourself
thinking that a pixel is a little square, please read this paper…”
o At the end we’ve done forward ray-tracing, but ONLY for the
rays that contribute to the image
}10/25/21 }15
Simple Ray Tracing
o A single ray is traced for each pixel in the image plane.
é x ù é x0 + t ( x1 - x0 ) ù
ê y ú = ê y + t ( y - y )ú
ê ú ê 0 1 0 ú
êë z úû êë z0 + t ( z1 - z0 ) úû
In vector form, where p = (x, y, z)
p(t) = p0 + t(p1 – p0)
p(t) = o + t(d)
p = o + t·d
p = o + t·d
}e
}s
}s -e
} p(0) = e
} p(1) = s
R3 T2
LB
S5 S6
O2
LA
R1
O4
S1
S2
O1
S3 S4
T1
R2
}10/25/21 }Sarajevo School of Science and Technology }22
O3
Ray-Object Intersection
o Finds the closest object that the ray
intersects
o Let:
vO = -(Pn · RO + D) = -(A * XO + B * YO + C * ZO + D)
o Then t = vO / vd
o If t < 0 then the line defined by the ray intersects the plane behind the ray’s
origin no actual intersection occurs
o Else the intersection point is:
n Compute vd :
vd = Pn · Rd = A * Xd + B * Yd + C * Zd =
1 * 0.577 + 0 * 0.577 + 0 * 0.577 = 0.577
o In our case vd > 0 => The normal of the plane points away from
the ray
n we have a two-sided plane
t = 5 / 0.577 = 8.66
o t>0 the point is not behind the ray
=-1-3*(5-(-1))/(-1-3))=3.5>0
o This means the line must cross +U axis and
NC=NC+1=1