Computer Graphics Lecture 11.pptx Version 1
Computer Graphics Lecture 11.pptx Version 1
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)
can be calculated by
𝑓 𝑝(𝑡)
Ԧ =0
Or
𝑓 𝑒Ԧ + 𝑡𝑑Ԧ = 0
Spheres
(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
Ԧ 𝑑Ԧ 𝑡 2 + 2𝑑Ԧ 𝑒 − 𝑐Ԧ 𝑡 + 𝑒 − 𝑐Ԧ . 𝑒 − 𝑐Ԧ − 𝑅 2 = 0
𝑑.
At 2 + B t + C = 0
−𝐵 ± 𝐵2 − 4𝐴𝐶
𝑡1,2 =
2𝐴
x e + tx d = f (u, v)
y e + tyd = g (u, v)
ze + tzd = h(u, v)
Or
𝑒Ԧ + 𝑡𝑑Ԧ = 𝑓(𝑢,𝑣)
Ԧ
𝑒Ԧ + 𝑡𝑑Ԧ = 𝛼Ԧ + 𝛽 𝑏Ԧ − 𝑎Ԧ + 𝛾( 𝑐Ԧ − 𝑎)
Ԧ
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)
Or as
𝑥 𝑎 − 𝑥 𝑏 𝑥𝑎 − 𝑥 𝑐 𝑥 𝑑 𝛽 𝑥 𝑎 − 𝑥𝑒
𝑦𝑎 − 𝑦𝑏 𝑦𝑎 − 𝑦𝑐 𝑦𝑑 𝛾 = 𝑦𝑎 − 𝑦𝑒
𝑧𝑎 − 𝑧𝑏 𝑧𝑎 − 𝑧𝑐 𝑧𝑑 𝑡 𝑧𝑎 − 𝑧𝑒
𝑝Ԧ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.