Tracing / Ray Casting
- Provides a related , powerful
approach to render scenes
Overview
of Ray Tracing Process
Pseudo code of a ray tracer:
for(int r =
0; r <nRows ; r++)
for(int c =
0; c <nCols ; c++)
{
1.
build the rc-th ray
2.
find all intersections of the rc-th ray with
objects in the scene
3.
Identify
the intersection that lies closest to and in front of the eye
4.
Compute
the hit point where the ray hits
this object and the normal vector at that point
5.
Find
the color of the light returning to the eye along the ray from the point of
intersection
6.
place the color in the rc-th pixel
}
Intersection
of a Ray with an Object
Common shapes used in ray tracing
§ Sphere
§ Cylinder
§ Cone cube
§ hex cone
If ‘S’ is the starting point of a ray and ‘c’ is its
direction then the ray that intersects with a shape is given by
r(t) = S + ct // implicit form of shape is F(P)
Condition for r(t) to coincide with a point of the
surface is
F(r(t)) = 0
The hit time thit can be found by solving
F(S+ c thit ) = 0
Intersection of a Ray with the
Generic Plane
§ generic plane – xy plane or z = 0
§ Implicit form is F(x ,y , z) = z
§ The ray S+ct intersects the
generic plane when
Sz
+czth = 0 , where th = - ( Sz / cz
)
If cz = 0 , the ray is moving parallel to
the plane & there is no intersection
Otherwise , the ray hits the plane at the point Phit
= S – c(Sz / cz )
Intersection of a Ray with the
Generic Shape
§ Consider a generic shape whose
implicit form is F(P) = |P|2 – 1
§ The point of intersection of the
ray is given by |S + ct |2 - 1 = 0
|c|2T2
+ 2.(S.C)t + (|S|2 - 1) = 0
which is of the form At2 +2Bt + c = 0
by solving th
= -(B/A) ±(√B2 – AC)/ A
ü If B2 - Ac is ‘-’ ve , the ray misses the sphere
ü If B2 - Ac is
zero , the ray grazes the sphere at one point
ü If B2 - Ac is ‘+’ ve , there are 2 hit times t1&
t2
No comments:
Post a Comment