Post on 22-Jul-2020
1
Raytracing
COSC 4328/5327
Scott A. King
Render With Triangles COSC4328/5327 Computer Graphics 2
"Villarceau Circles" by Tor Olav Kristensen (2004)
• Flat shading
• Phong Shading
• Now what?
• What lighting effects would we have
trouble
– Shadows (can fake)
– Reflection (can fake)
– Refraction (can fake, but not easily)
– Reflected refraction?
– Harder to fake if moving camera
• So how will we do this?
COSC4328/5327 Computer Graphics 3
Marc Jacquier (2004)
COSC4328/5327 Computer Graphics 4
"Glasses" by Gilles Tran (2006)
COSC4328/5327 Computer Graphics 5
"Christmas Baubles" by Jaime Vives Piqueres (2005)
COSC4328/5327 Computer Graphics 6
"Office" by Jaime Vives Piqueres (2004)
2
COSC4328/5327 Computer Graphics 7
"Villarceau Circles" by Tor Olav
Kristensen (2004)
COSC4328/5327 Computer Graphics 8
"Autobahn WIP" by Jaime Vives Piqueres (2005)
COSC4328/5327 Computer Graphics 9
"Car Study" by René Bui (2006)
COSC4328/5327 Computer Graphics 10
Jaime Vives Piqueres (2003)
COSC4328/5327 Computer Graphics 11 COSC4328/5327 Computer Graphics 12
"Small World" by Stephen M. Farrell (2002)
3
COSC4328/5327 Computer Graphics 13
"Urban Tree" by Jaime Vives Piqueres (1999)
COSC4328/5327 Computer Graphics 14
"Rocket" by Jochen Diehl (2004)
COSC4328/5327 Computer Graphics 15
"The Dark Side of the Trees" by
Gilles Tran (2002)
Gilles Tran (2000)
COSC4328/5327 Computer Graphics 16
"Techno Garb"
by Samuel Benge
(2003)
COSC4328/5327 Computer Graphics 17
"Dancing Cube" by Friedrich A. Lohmueller (2003)
COSC4328/5327 Computer Graphics 18
"Balanza" by Jaime Vives Piqueres (2002)
4
COSC4328/5327 Computer Graphics 19
"BL Object 5" by Douglas Eichenberg (2003)
COSC4328/5327 Computer Graphics 20
"Travieso" by Jaime Vives Piqueres (1997)
COSC4328/5327 Computer Graphics 21
"Harvest Time" by Gilles
Tran (1999)
This image won the
IRTC competition of
November - December
1999, "Gardens" topic
COSC4328/5327 Computer Graphics 22
"Still with Bolts" by Jaime Vives Piqueres (2002)
COSC4328/5327 Computer Graphics 23
© 1994 by Martin Moeck, Siemens Lighting
Radiance Movies COSC4328/5327 Computer Graphics 24
5
Consider This Room.
• When I’m looking towards the wall,
what can I see behind me?
• Do I get any clues about what is
behind me?
• How do we see?
– Our eyes are sensors. What do they
sense?
– We are detecting light at different
wavelengths (roughly)
– Where does this light come from?
– From the desk, the wall, the table?
– From some light source.
COSC4328/5327 Computer Graphics 25
Pinhole Camera
• Why a camera?
• Lets use a pinhole camera model.
• Why?
• Should we flip image?
COSC4328/5327 Computer Graphics 26
Light Comes Forward
From its Source(s) Forward Tracing
• Can this be done?
• How would we do it?
– Well, we would have to trace all
rays from all lights.
– If they end up hitting our eye
(camera) then we add in it’s
contribution.
• Is this efficient?
• Is it accurate?
• What could we do instead?
Tracing from light source
Traditional ray-tracing
Yes
No
Yes
Backward Tracing
Basic Ray Casting
Method
• pixels in screen
– Shoot ray 𝑝 from the eye through
the pixel.
– Find closest ray-object intersection.
– Get color at intersection
6
Basic Ray Casting
Method
• pixels in screen
– Shoot ray 𝑝 from the eye through
the pixel.
– Find closest ray-object intersection.
– Get color at intersection
Basic Ray Casting
Method
• pixels in screen
– Shoot ray 𝑝 from the eye through
the pixel.
– Find closest ray-object intersection.
– Get color at intersection
Basic Ray Casting
Method
• pixels in screen
– Shoot ray 𝑝 from the eye through
the pixel.
– Find closest ray-object intersection.
– Get color at intersection
Basic Ray Model
• Let’s treat a ray as a vector. Namely
we can represent a ray by the vector
form:
𝑝 = 𝑢 + 𝑣 𝑡
Basic Ray Model
• Let’s treat a ray as a vector. Namely
we can represent a ray by the vector
form:
𝑝 = 𝑢 + 𝑣 𝑡
• where:
𝑝 is any point along the ray
Basic Ray Model
• Let’s treat a ray as a vector. Namely
we can represent a ray by the vector
form:
𝑝 = 𝑢 + 𝑣 𝑡
• where:
𝑝 is any point along the ray
𝑢 is the starting point
7
Basic Ray Model
• Let’s treat a ray as a vector. Namely
we can represent a ray by the vector
form:
𝑝 = 𝑢 + 𝑣 𝑡
• where:
𝑝 is any point along the ray
𝑢 is the starting point
𝑣 is the direction
Basic Ray Model
• Let’s treat a ray as a vector. Namely
we can represent a ray by the vector
form:
𝑝 = 𝑢 + 𝑣 𝑡
• where:
𝑝 is any point along the ray
𝑢 is the starting point
𝑣 is the direction
𝑡 is how far we’ve travelled along ray.
Ray/Sphere Intersection
• Let’s use a sphere of radius 1 centered
at the origin
• In vector form
• The ray 𝑝 intersects the sphere when
𝑝 = 𝑢 + 𝑣 𝑡 satisfies the equation for
the sphere.
• Plug in the ray into sphere equation
• Let’s expand
• We have a lot of vector times vector
operations? What is that? What is the
result?
𝑥2 + 𝑦2 + 𝑧2 = 1
𝑝 2 = 1
𝑝 2 = 1 𝑝 = 𝑢 + 𝑣 𝑡
𝑢 + 𝑣 𝑡 2 = 1
𝑢2 + 2𝑢𝑣 𝑡 + 𝑣 2𝑡2 = 1
Ray/Sphere Intersection
• Solve using quadratic formula
• Let’s solve this in three steps.
1. if 𝑏2 ≤ 4𝑎𝑐, we don’t get a solution.
if 𝑏2 = 4𝑎𝑐, 𝑝 is a tangent ray, which
we can consider a miss.
2. if 𝑏 > 0 then 𝑡1 = −𝑏− 𝑏2−4𝑎𝑐
2𝑎 else
𝑡1 = −𝑏+ 𝑏2−4𝑎𝑐
2𝑎
3. 𝑡2 =𝑐
𝑎𝑡1
𝑢2 + 2𝑢𝑣 𝑡 + 𝑣 2𝑡2 = 1
𝑐 𝑏 𝑎
𝑢2 − 1 + 2𝑢𝑣 𝑡 + 𝑣 2𝑡2 = 0
rad=b*b-4*a*c
if (rad <= 0) return no int
if (b > 0)
t1 = (-b-sqrt(rad))/(2*a)
else
t1 = (-b+sqrt(rad))/(2*a)
T2 = c/(a*t1);
Ray/Sphere Intersection
D = B*B - 4*AC;
if (D < 0.0) return NULL;
rootD = sqrt(D);
t0 = 0.5*(-B - rootD)/A;
t1 = 0.5*(-B + rootD)/A;
if (t0 >= 0)
hit->t = t0, return hit;
if (t1 >= 0)
hit->t = t1, return hit;
return NULL;
* / + -
A 3+1+1 1+1 1 1+2+1 1
B 3+1+1 1+1 1+2 1
rad=b*b-4*a*c
if (rad <= 0) return no int
if (b > 0)
t1 = (-b-sqrt(rad))/(2*a)
else
t1 = (-b+sqrt(rad))/(2*a)
T2 = c/(a*t1);