Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Rendering

Issues
• Visibility
What objects or parts in the scene are visible?
Clipping (with respect to the view frustum)
Done
Occlusion (with respect to the objects in the scene)
Hidden surface elimination
• Illumination
Reflection, Refraction, Transparency, Shadows, etc.
Rendering Pipeline (Revisit)
Modeling Viewing
Transformation Transformation
Model 1
M1

Model 2 3DWorld V 3D View


M2
Scene Scene

Mn
Model n Forward Mapping Approach

2D
Image
Rasterization 2D Scene Projection
Forward Ray Tracing
Modeling interaction of light with the objects/surfaces

Problem:
Many rays will not contribute
to the image!
Backward Ray Tracing

Rays from camera (viewer)


through each pixel to the scene

Backward Ray Tracing = Ray Tracing


Backward Ray Tracing
Primary and Secondary Rays
D

Viewer B

E
C
A
View Plane F
Backward Ray Tracing
Shadow Rays

Visibility check with respect


to the light source
Ray Casting
D

Viewer B

E
C
A
View Plane F
Two Issues

Ray-object intersection
Visibility test: Closest to the viewer

Pixel color determination (shading)


Illumination model
Ray Object Intersection
Sphere

Ro = [ X o Yo Zo ] (Ray Origin)
Rd = [ X d Yd Zd ] (Ray Direction)
X d2 + Yd2 + Zd2 = 1

Rd Parametric Form
Ro R(t) = Ro + Rd t t >0
Ray Object Intersection
Sphere
Implicit Form

Center Sc = [ Xc Yc Zc ]
Radius Sr
Surface Point [ Xs Ys Zs ]

( X s - X c )2 + (Ys - Yc )2 + (Zs - Zc )2 = Sr2


Ray Object Intersection
Sphere
To solve the intersection problem the ray equation is
substituted into the sphere equation and the result is
solved for t

That is
( X o + X d t - X c )2 + (Yo + Yd t - Yc )2 + (Zo + Zd t - Zc )2 = Sr2
Ray Object Intersection
Sphere

At 2 + Bt + C = 0
where
A = X d2 + Yd2 + Zd2 = 1
B = 2( X d ( X o - X c ) + Yd (Yo - Yc ) + Zd (Zo - Zc ))
C = ( X o - X c )2 + (Yo - Yc )2 + (Zo - Zc )2 - Sr2
Ray Object Intersection
Sphere
- B - B 2 - 4 AC
t0 =
At 2 + Bt + C = 0 2A
- B + B 2 - 4 AC
t1 =
2A
Smaller positive among t0 and t1 gives the closest
intersection point
[ Xi Yi Zi ] = [ Xo + Xdt , Yo + Ydt , Zo + Zdt ]
Ray Object Intersection
Sphere
Normal

é( X i - X c ) (Yi - Yc ) (Zi - Zc ) ù
n=ê , , ú
ë S r S r S r û
Ray Object Intersection
Sum up
Calculate A B C
Compute the discriminant
Calculate min (t0 , t1)
Compute the intersection point
Compute the normal
Ray Object Intersection
Sphere
Geometric Approach

tca thc
Rd d
r
R0 L O
Ray Object Intersection
Sphere
Geometric Approach
L = O - R0
t ca = LT Rd
tca thc t ca < 0 no intersection
Rd d
r
R0 L O
Ray Object Intersection
Sphere
Geometric Approach
L = O - R0
t ca = LT Rd
tca thc t ca < 0 no intersection
Rd d
r
R0 L O d = LT L - t ca
2

if d > r no intersection
Ray Object Intersection
Sphere
Geometric Approach

tca t hc = r 2 - d 2
thc
Rd d t = t ca - t hc and t ca + t hc
r
R0 O
smaller t
L
Ray Plane Intersection
Ray
Ro = [ Xo Yo Zo ] (ray origin)
Rd = [ Xd Yd Zd ] (ray direction)
Xd2 + Yd2 + Zd2 =1 (normalized)
R(t) = Ro + Rdt t>0
Plane
P : Ax + By + Cz + D = 0
A2 + B2 +C2 = 1
Pnormal = Pn = [ A B C ]
D : Distance from origin
Ray Plane Intersection
Substituting ray equation in plane’s equation

A ( Xo + Xdt ) + B (Yo + Ydt ) + C ( Zo + Zdt ) + D = 0

Solving for t
AX 0 + BY0 + CZ0 + D
t =-
AX d + BYd + CZd
Pn × R0 + D
t =-
Pn × Rd
Ray Plane Intersection
Let
Vd = Pn × Rd = AX d + BYd + CZd
If Vd = 0 then the ray is parallel to the plane
(no intersection)
Normal
Vd > 0 normal is pointing away from the ray
(may be used for back-face culling)
Ray
Ray Plane Intersection
Let V0 = -(Pn × R0 + D ) = ( AX 0 + BY0 + CZ0 + D )
V0
t=
Vd
If t < 0 then plane is behind ray’s origin
else compute intersection

ri = [ Xi Yi Zi ] = [Xo + Xdt , Yo + Ydt , Zo + Zdt ]


rnormal = Pn
Ray Plane Intersection
Containment Test

Parity Test: If the number of intersection is odd then point


is inside (special case for vertices)
Triangle Intersection
Containment Test
Triangle: Barycentric Coordinates
V3

V1 V2

P = uV1 + vV2 + wV3


Triangle Intersection
Containment Test
Triangle: Barycentric Coordinates
V3

P A2 A1
Total A
V1 V2
A3 Area Coordinates
P = uV1 + vV2 + wV3
Triangle Intersection
Containment Test
Triangle: Barycentric Coordinates
A1 A A V3
u= ,v = 2 ,w = 3
A A A A2 A1
u +v +w =1 P
u ³ 0, v ³ 0, w ³ 0 V1 V2
P = uV1 + vV2 + wV3 A3
Ray Quadric Intersection
Quadrics:
Cylinders, Cone, Sphere, Ellipsoids,
Paraboloids, Hyperboloids, etc.
Implict form f(X,Y,Z) = 0
Ax2 + 2Bxy + 2Cxz + 2Dx + Ey2 +2Fyz +26y + Hz2 + 2Iz +J = 0

Ray: Parametric form


Ro = [ Xo Yo Zo ] (ray origin)
Rd = [ Xd Yd Zd ] (ray direction)
Xd2 + Yd2 + Zd2 =1 (normalized)
R(t) = Ro + Rdt t > 0
Ray Quadric Intersection
Matrix Form

f(X,Y,Z) = 0
éA B C Dù éX ù
êB E F Gú êY ú
[X Y Z 1] ê ú ê ú=0
êC F H Iú êZ ú
êD G I J úû ê 1ú
ë ë û
Ray Quadric Intersection
Substituting
Aq t 2 + Bq t + Cq = 0
If Aq ¹ 0
If Aq = 0
2
- Bq - Bq - 4 AqCq Cq
t0 = t =-
2 Aq Bq
2
- Bq + Bq - 4 AqCq
t1 =
2 Aq
Ray Quadric Intersection

Normal

é ¶F ¶F ¶F ù
n=ê , , ú

ë iX ¶Y i ¶Z iû
n x = 2( AX i + BYi + CZi + D )
ny = 2(BX i + EYi + FZi + G )
nz = 2(CX i + FYi + HZi + I )
Ray Box Intersection
3D Clipping: Cyrus Beck/Liang Barsky

You might also like