Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
21 views19 pages

Computer Graphics Lecture 11.pptx Version 1

Computer graphics ray tracing

Uploaded by

shan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views19 pages

Computer Graphics Lecture 11.pptx Version 1

Computer graphics ray tracing

Uploaded by

shan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Computer Graphics

Lecture 11
Basics of Ray tracing – part 2

Presented by
Dr. Muhammad Ahsan Ansari
A basic ray tracing algorithm

F o r e a c h obje c t D O
❖ f ind 1st object h it by ray and
surface normal 𝑛
❖ set pixe l color t o value computed
from hit point , light , a nd 𝑛
Ray-object intersection (implicit surface)

In general, the intersection points of


❖ a ray 𝑝 𝑡 = 𝑒 + 𝑡𝑑
❖ an implicit surface 𝑓 𝑝Ԧ = 0

can be calculated by

𝑓 𝑝(𝑡)
Ԧ =0
Or
𝑓 𝑒Ԧ + 𝑡𝑑Ԧ = 0
Spheres

The implicit equation for a sphere with


center 𝑟Ԧ = 𝑥𝑐,𝑦𝑐 , 𝑧𝑐 and radius R is

(x − x c ) 2 + (y − yc ) 2 + (z − zc ) 2 −R 2 = 0

or in vector form
𝑝Ԧ − 𝑐Ԧ . 𝑝Ԧ − 𝑐Ԧ − 𝑅 2 = 0
Intersections between rays and spheres
Intersection points have to fullfil
❖ the ray equation
𝑝 𝑡 = 𝑒 + 𝑡𝑑
❖ the sphere equation
(x − x c ) 2 + (y − yc ) 2 +(z − zc ) 2 - R2 =0

Hence, we get

𝑒Ԧ + 𝑡 𝑑Ԧ − 𝑐Ԧ . 𝑒Ԧ + 𝑡 𝑑Ԧ − 𝑐Ԧ − 𝑅 2 = 0

which is the same as


Ԧ 𝑑Ԧ 𝑡 2 + 2𝑑Ԧ 𝑒 − 𝑐Ԧ 𝑡 + 𝑒 − 𝑐Ԧ . 𝑒 − 𝑐Ԧ − 𝑅 2 = 0
𝑑.
Intersections between rays and spheres

Ԧ 𝑑Ԧ 𝑡 2 + 2𝑑Ԧ 𝑒 − 𝑐Ԧ 𝑡 + 𝑒 − 𝑐Ԧ . 𝑒 − 𝑐Ԧ − 𝑅 2 = 0
𝑑.

is a quadratic equation in t, i.e.

At 2 + B t + C = 0

that can be solved by

−𝐵 ± 𝐵2 − 4𝐴𝐶
𝑡1,2 =
2𝐴

and can have 0, 1, or 2 solutions.


Ray-object intersection (parametric surface)

The intersection points of a ray


𝑝 𝑡 = 𝑒 + 𝑡𝑑 and a parametric
surface f (u, v) can be calculated by

x e + tx d = f (u, v)
y e + tyd = g (u, v)
ze + tzd = h(u, v)

Or

𝑒Ԧ + 𝑡𝑑Ԧ = 𝑓(𝑢,𝑣)
Ԧ

Notice that these are 3 equations


with 3 unknowns (t, u, v).
Ray-triangle intersection

For ray-triangle intersections:


❖ We first calculate the
intersection point of the
ray with the plane defined
by the triangle.

❖ Then we check if this


point is within the triangle
or not.
Plane specification

Recall that the plane V through the


Ԧ 𝑏Ԧ and 𝑐Ԧ can be written as
points 𝑎,
Ԧ 𝛾 = 𝛼Ԧ + 𝛽 𝑏 − 𝑎 + 𝛾(𝑐Ԧ − 𝑎)
𝑝 𝛽,
Plane specification

Recall that the plane V through the


Ԧ 𝑏Ԧ and 𝑐Ԧ can be written as
points 𝑎,
Ԧ 𝛾 = 𝛼Ԧ + 𝛽 𝑏 − 𝑎 + 𝛾(𝑐Ԧ − 𝑎)
𝑝 𝛽,
Plane specification

Recall that the plane V through the


Ԧ 𝑏Ԧ and 𝑐Ԧ can be written as
points 𝑎,
Ԧ 𝛾 = 𝛼Ԧ + 𝛽 𝑏 − 𝑎 + 𝛾(𝑐Ԧ − 𝑎)
𝑝 𝛽,
Ray-plane intersection

Again, intersection points must fullfil


the plane and the ray equation.
Hence, we get

𝑒Ԧ + 𝑡𝑑Ԧ = 𝛼Ԧ + 𝛽 𝑏Ԧ − 𝑎Ԧ + 𝛾( 𝑐Ԧ − 𝑎)
Ԧ

That give us . . .
Ray-plane intersection
. . . the following three equations
x e + tx d = x a + β(x b − x a ) + γ(x c − x a )
ye + tyd = ya + β(y b − ya ) + γ(y c − ya )
ze + tzd = za + β(zb − za ) + γ(zc − za)

which can be rewritten as


(x a − x b )β + (x a − x c)γ + x dt = xa − xe
(y a − yb )β + (y a − yc )γ + ydt = ya − ye
(za − zb )β + (za − zc )γ + zdt = za − ze
Ray-plane intersection

Or as
𝑥 𝑎 − 𝑥 𝑏 𝑥𝑎 − 𝑥 𝑐 𝑥 𝑑 𝛽 𝑥 𝑎 − 𝑥𝑒
𝑦𝑎 − 𝑦𝑏 𝑦𝑎 − 𝑦𝑐 𝑦𝑑 𝛾 = 𝑦𝑎 − 𝑦𝑒
𝑧𝑎 − 𝑧𝑏 𝑧𝑎 − 𝑧𝑐 𝑧𝑑 𝑡 𝑧𝑎 − 𝑧𝑒

Also like this


𝛽 𝑥𝑎 − 𝑥 𝑒
𝐴 𝛾 = 𝑦𝑎 − 𝑦𝑒
𝑡 𝑧𝑎 − 𝑧𝑒

Then we can see that


𝛽 𝑥𝑎 − 𝑥 𝑒
𝛾 = 𝐴 −1 𝑦𝑎 − 𝑦𝑒
𝑡 𝑧𝑎 − 𝑧𝑒
Rays: parametric representation

We can use t to calculate the


intersection point 𝑝 𝑡 (or 𝛼, 𝛽 to
calculate 𝑝 𝛽 , 𝛾

And we can use β and γ to verify if it


is inside of the triangle or not:
❖β>0
❖γ> 0
❖ β+ γ< 1
(Notice that these are barycentric
coordinates)
Ray-object intersection (implicit plane)

Of course, we can also get the


ray-plane intersection if the latter is
given as implicit equation:
𝑝Ԧ − 𝑝Ԧ 1 .𝑛 = 0

Putting our ray equation


𝑝 𝑡 = 𝑒 + 𝑡𝑑 and solving for t
gives us:

𝑝Ԧ1 − 𝑒 . 𝑛
𝑡=
Ԧ𝑛
𝑑.
A basic ray tracing algorithm

F o r e a c h obje c t D O
❖ f ind 1st object h it by ray and
surface normal 𝑛
❖ set pixe l color t o value computed
from hit point , light , a nd 𝑛
A basic ray tracing algorithm
FOR each p i xe l DO
❖ Compute viewing ray
❖ IF (ray h i t s an objec t wit h t ∈ [0, ∞)) THEN
❖ Compute n
❖ Evaluate shading model and s e t p i xe l to th a t
co l o r
❖ ELSE
❖ s e t p i xe l co l o r to background co l o r
Shading model

𝑐
= 𝑐 𝑟 𝑐 𝑎 + 𝑐 𝑙 max 0, 𝑛. 𝑙
+ 𝑐 𝑙(ℎ. 𝑛) 𝑝
with
❖Ambient shading
❖Lambertian shading
❖Phong shading
and Gouraud interpolation.

You might also like