ray tracing - Fabio...
Transcript of ray tracing - Fabio...
![Page 1: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/1.jpg)
ray tracing
1
![Page 2: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/2.jpg)
image formation
2
![Page 3: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/3.jpg)
image formation
3
![Page 4: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/4.jpg)
rendering
computational simulation of image formation
4
![Page 5: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/5.jpg)
rendering
given viewer, geometry, materials, lights
determine visibility and compute colors
5
![Page 6: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/6.jpg)
raytracing
a specific rendering algorithm
6
![Page 7: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/7.jpg)
raytracing algorithm
for each pixel {
determine viewing direction
intersect ray with scene
compute illumination
store result in pixel
}
7
![Page 8: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/8.jpg)
vector math review
point: location in 3D space
vector: direction and magnitude
P = ( , , )Px Py Pz
v = ( , , )vx vy vz
8
![Page 9: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/9.jpg)
vector math review
dot product
cross product
is orthogonal to and
a ⋅ b = |a||b| cos θ
|a × b| = |a||b| sin θ
a × b a b
9
![Page 10: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/10.jpg)
vector math review
segment: set of points (line) between two points
with P(t) = A + t(B − A) t ∈ [0, 1]
10
![Page 11: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/11.jpg)
vector math review
ray: infinite line from point in a given direction
with P(t) = E + td t ∈ [0, ∞]
11
![Page 12: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/12.jpg)
vector math review
coordinate system aka frame
frame : position and orthonormal
axes
default (or world) frame: origin and three major axes
f = { , , , }fO fx fy fz
12
![Page 13: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/13.jpg)
vector math review
point coords are defined wrt a frame
wrt (world if not
specified)
P = ( , , )Px Py Pz { , , , }fO fx fy fz
P = ((P − ) ⋅ , (P − ) ⋅ , (P − ) ⋅ )fO fx fO fy fO fz
13
![Page 14: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/14.jpg)
vector math review
change of coordinate system
is w.r.t
f → f ′
= ( , , )P′ P ′x P ′
y P ′z P { , , , }f ′
O f ′x f ′
y f ′z
= ((P − ) ⋅ , (P − ) ⋅ , (P − ) ⋅ )P′ f ′O f ′
x f ′O f ′
y f ′O f ′
z
14
![Page 15: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/15.jpg)
vector math review
change of coordinate system
is w.r.t
→ ff ′
= ( , , )P′ P ′x P ′
y P ′z P { , , , }f ′
O f ′x f ′
y f ′z
P = + + +f ′O P ′
xf ′x P ′
y f ′y P ′
z f ′z
15
![Page 16: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/16.jpg)
vector math review
vector coords are defined wrt a frame
to change coord system, ignore origin
v = + +v′xf ′
x v′y f ′
y v′zf ′
z
= (v ⋅ , v ⋅ , v ⋅ )v′ f ′x f ′
y f ′z
16
![Page 17: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/17.jpg)
vector math review
construct a frame from two non-orthonormal vectors ,
assume that is not parallel to
construct a frame from a vector
pick arbitrary and continue as above
z′ y′
z′ y′
z = /| |z′ z′
x = × z/| × z|y′ y′
y = z × xz′
y′
17
![Page 18: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/18.jpg)
vector math review
infinite plane
with
normal:
P ∈ plane ; (P − C) ⋅ n = 0 ; P ⋅ n = d
P(u, v) = C + u ⋅ u + v ⋅ v (u, v) ∈ (−∞, ∞)2
n = u × v
18
![Page 19: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/19.jpg)
vector math review
triangle baricentric coordinates
with
, ...
P(α, β, γ) = αA + βB + γC α + β + γ = 1P(α, β) = α(A − C) + β(B − C) + Cα = area(BCP)/area(ABC)
19
![Page 20: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/20.jpg)
vector math review
sphere
P ∈ sphere ; |P − C| = R
P(u, v) = C + R ⋅ (cos ϕ sin θ, sin ϕ sin θ, cos θ)
20
![Page 21: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/21.jpg)
viewing
for each pixel {
-> determine viewing direction
intersect ray with scene
compute illumination
store result in pixel
}
21
![Page 22: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/22.jpg)
viewer model
a painter tracing objects on a canvas in front
[Marschner 2004 – original unknown]22
![Page 23: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/23.jpg)
viewer model
equivalent to pinhole photography
[Marschner 2004 – original unknown] 23
![Page 24: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/24.jpg)
viewer model -- parameters
camera frame: position and orientation , ,
image plane: distance and size ,
O x y zd w h
24
![Page 25: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/25.jpg)
view frustum
all visible points within a truncated pyramid
25
![Page 26: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/26.jpg)
generating view rays
for each pixel, ray from camera center to the pixel center
26
![Page 27: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/27.jpg)
generating view rays
ray:
point on image plane
r = O + t(Q − O)/|Q − O|Q
27
![Page 28: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/28.jpg)
generating view rays
image plane params: , origin at bottom
Q(u, v) = (u − 0.5)wx + (v − 0.5)hy − dz(u, v) ∈ [0, 1]2
28
![Page 29: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/29.jpg)
geometry model
simple shapes
spheres, quads, traingles
complex shapes
handled as collections of simple shapes later in the course
29
![Page 30: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/30.jpg)
ray-shape intersection
determine visible surface by finding closest intersection
along a ray
ray with
keep explicit bounds on
e.g. used in shadows and to improve numerical precision
if not specified otherwise: ,
mitigate numerical precision issues ("shadow acne")
value is scene depedent: start with
r : E + td t ∈ ( , )tmin tmax
t
= ϵtmin = ∞tmax
ϵ
10−5
30
![Page 31: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/31.jpg)
ray-sphere intersection
point on a ray:
point on a sphere:
by substitution:
P(t) = E + td|P(t) − C| = R
|E + td − C| = R
31
![Page 32: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/32.jpg)
ray-sphere intersection
algebraic equation:
with: , ,
determinant:
no solution for
a + bt + c = 0t2
a = |d|2 b = 2d ⋅ (E − C) c = |E − C −|2 R2
d = − 4acb2
d < 0
32
![Page 33: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/33.jpg)
ray-sphere intersection
two solutions:
pick smallest such that
= (−b ± )/(2a)t± d√
t t ∈ ( , )tmin tmax
33
![Page 34: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/34.jpg)
ray-sphere intersection
shading frame at with normal with
and
and
, where ,
P = fO n = fz
P = E + td = (P − C)/RPl
θ = arccos P lz ϕ = arctan( , )P l
y P lx
f = {P, x, y, }Pl x = (sin ϕ, cos ϕ, 0)y = (cos θcos ϕ, cos θsin ϕ, sin θ)
34
![Page 35: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/35.jpg)
ray-plane intersection
point on a ray:
point on a plane:
by substitution:
P(t) = E + td(P(t) − C) ⋅ n = 0
(E + td − C) ⋅ n = 0
35
![Page 36: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/36.jpg)
ray-plane intersection
one solution for , no/infinite solutions otherwise
check that
d ⋅ n ≠ 0
t =(C − E) ⋅ n
d ⋅ n
t ∈ ( , )tmin tmax
36
![Page 37: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/37.jpg)
ray-plane intersection
shading frame: f = {e + td, u, v, n}
37
![Page 38: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/38.jpg)
ray-triangle intersection
point on ray:
point on triangle:
by substitution:
P(t) = E + tdP(α, β) = α(A − C) + β(B − C) + C
E + td = α(A − C) + β(B − C) + C
38
![Page 39: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/39.jpg)
ray-triangle intersection
E + td = α(A − C) + β(B − C) + C →
α(A − C) + β(B − C) − td = E − C →
αa + βb − td = e →
[ ] = e−d a b⎡⎣
t
α
β
⎤⎦
39
![Page 40: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/40.jpg)
ray-triangle intersection
use Cramer's rule
test for
t = =| |e a b
| |−d a b(e × a) ⋅ b(d × b) ⋅ a
α = =| |−d e b| |−d a b
(d × b) ⋅ e(d × b) ⋅ a
β = =| |−d a e| |−d a b
(e × a) ⋅ d(d × b) ⋅ a
t ∈ ( , ), α ≥ 0, β ≥ 0, α + β ≤ 1tmin tmax 40
![Page 41: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/41.jpg)
ray-triangle intersection
shading frame:
create frame by orthonomalization with
,
f = {e + td, u, v, n}
= (B − A) × (C − A)z′ = (B − A)x′
41
![Page 42: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/42.jpg)
intersection and coord systems
transform the object
simple for triangles, since they transforms to triangles
but objects may require more complex intersection tests
transform the ray
much more elegant
works on any surface
allow for much simpler intersection tests
42
![Page 43: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/43.jpg)
intersection and coord systems
ray wrt (e.g. world)
object defined wrt (in turn defined wrt )
transform rays
transform origin/direction as point/vector
intersect object with transformed ray
use standard intersection tests
transform intersection frame back to
transform origin/axes as point/vectors
r = {E, d} fo′ f ′ f
= { , }r′ E′ d′
o′ r′
f
43
![Page 44: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/44.jpg)
image so far
44
![Page 45: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/45.jpg)
intersecting many shapes
intersect each primitive
pick closest intersection
essentially a line search
45
![Page 46: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/46.jpg)
intersecting many shapes --pseudocode
minDistance = infinity
hit = false
foreach surface s {
if(s.intersect(ray,intersection)) {
if(intersection.distance < minDistance) {
hit = true;
minDistance = intersection.distance;
}
}
}
46
![Page 47: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/47.jpg)
image so far
47
![Page 48: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/48.jpg)
shading
for each pixel {
determine viewing direction
intersect ray with scene
-> compute illumination
store result in pixel
}
48
![Page 49: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/49.jpg)
shading
variation in observed color across a surface
49
![Page 50: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/50.jpg)
shading
compute reflected light
depends on:
view position
incoming light, i.e. lighting
surface geometry
surface material
50
![Page 51: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/51.jpg)
real-world materials
Metals Dielectric
[Marschner 2004] [Marschner 2004]
51
![Page 52: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/52.jpg)
real-world materials
Metals Dielectric
[Marschner 2004] [Marschner 2004] 52
![Page 53: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/53.jpg)
shading models
empirical models
produce believable images
simple and efficient
only for simple materials
physically-based shading models
can reproduce accurate effects
more complex and expensive
will concentrate on empirical models first
53
![Page 54: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/54.jpg)
shading model
shading model: diffuse + specular reflection
diffuse reflection
light is reflected in every direction equally
colored by surface color
specular reflection
light is reflected only around the mirror direction
white for plastic-like surfaces (glossy paints)
colored for metals (brass, copper, gold)
54
![Page 55: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/55.jpg)
incident light
beam of light is more spread on oblique surfaces
incident light depends on angle
light fraction: f = |n ⋅ l|
55
![Page 56: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/56.jpg)
surface reflectance
surface reflectance is described by the BRDF, bidirectional
surface distribution functions
BRDF is simple for simple shading models
in general, the BRDF is a function of incoming and outgoing
angles
is the direction from the point to the light
is the direction from the point to the viewer
is the local shading frame that describes surface
orientation (normal and tangent)
ρ(l, v; f)lvf
56
![Page 57: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/57.jpg)
lambert diffuse model
simple and efficient diffuse model
light is scattered uniformly in all directions
brdf:
surface color:
(l, v; f) =ρd kd
= (l, v; f) ⋅ |n ⋅ l| = |n ⋅ l|Cd ρd kd
57
![Page 58: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/58.jpg)
lambert diffuse model
produce matte appearance
left-to-right: increasing kd
58
![Page 59: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/59.jpg)
image so far
59
![Page 60: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/60.jpg)
phong specular model
empirical, used to look good enough
cosine of mirror and view direction
reflected direction:
brdf:
r vr = −l + 2(n ⋅ l)n
(l, v; f) = max(0, v ⋅ rρs ks )n
= (l, v; f) ⋅ |n ⋅ l| = max(0, v ⋅ r ⋅ |n ⋅ l|Cs ρs ks )n
60
![Page 61: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/61.jpg)
phong specular model
produces highlight, shiny appearance
left-to-right: increasing , top-to-bottom: increasing n ks
61
![Page 62: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/62.jpg)
blinn specular model
slightly better than Phong
cosine of bisector and normal
bisector:
brdf:
h nh = (l + v)/|l + v|
(l, v; f) = max(0, n ⋅ hρs ks )n
= (l, v; f) ⋅ |n ⋅ l| = max(0, n ⋅ h ⋅ |n ⋅ l|Cs ρs ks )n
62
![Page 63: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/63.jpg)
image so far
63
![Page 64: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/64.jpg)
lighting
patterns of illumination in the environment
64
![Page 65: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/65.jpg)
lighting
determines how much light reaches a point
depends on:
light geometry
light emission
scene geometry
65
![Page 66: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/66.jpg)
light source models
describe how light is emitted from light sources
empirical light source models
point, directional, spot
physically-based light source models
area light, sky model
66
![Page 67: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/67.jpg)
point lights
light is emitted equally from a point in all directions
simulate local lighting, different at each surface point
light direction:
light color:
SP
l = (S − P)/|S − P|L = /|S − Pkl |2
67
![Page 68: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/68.jpg)
directional lights
light is emitted from infinity in one direction
simulate distant lighting, e.g. sun, same at all surface points
light direction:
light color:
d
Pl = d
L = kl
68
![Page 69: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/69.jpg)
spot lights
same as points lights, but only emits in a cone around
simulate theatrical lights
cone falloff model arbitrary
light direction:
light color:
d
l = (S − P)/|S − P|L = ⋅ attenutation/|S − Pkl |2
69
![Page 70: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/70.jpg)
shading model with multiple lights
add contribution of all lights for diffuse and specular
for Lambert and Phong
for Lambert and Blinn
i
C = ⋅ ( ( , v; f) + ( , v; f)) ⋅ |n ⋅ |∑iLi ρd li ρs li li
C = ⋅ ( + max(0, v ⋅ ) ⋅ |n ⋅ |∑iLi kd ks ri)
n li
C = ⋅ ( + max(0, n ⋅ ) ⋅ |n ⋅ |∑iLi kd ks hi)
n li
70
![Page 71: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/71.jpg)
image so far
71
![Page 72: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/72.jpg)
illumination models
describe how light spreads in the environment
direct illumination
incoming light comes directly from light sources
shadows
indirect illumination
incoming light comes from other objects
specular reflections (mirrors)
diffuse inter-reflections
72
![Page 73: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/73.jpg)
illumination models
[PCG]
73
![Page 74: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/74.jpg)
ray tracing lighting model
point/directional/spot light sources
sharp shadows
sharp reflection/refractions
hacked diffuse inter-reflection: ambient term
74
![Page 75: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/75.jpg)
ray traced shadows
light contributes only if visible at surface point
no shadow shadow
75
![Page 76: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/76.jpg)
ray traced shadows
send a shadow ray to check if light is visible
visible if no hits or if more than light distancet
76
![Page 77: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/77.jpg)
ray traced shadows
shadow ray with
spot/point lights at :
directional lights:
scale lighting by visibility term which is 0 or 1
implementation detail: numerical precision
shadow acne: ray hits the visible point
solution: only intersect if , i.e.
r = P + tl t ∈ ( , )tmin tmax
S = length(S − P)tmax
= ∞tmax
(P)Vi
C = ⋅ (P)( + )|n ⋅ |∑iLi Vi ρd ρs li
t > ϵ = ϵtmin
77
![Page 78: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/78.jpg)
image so far
78
![Page 79: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/79.jpg)
ambient term hack
light bounces even in diffuse environment
ceiling are not black
shadows are not perfectly black
very expensive to compute
approximate (poorly) with a constant term
C = + ⋅ (P)( + )|n ⋅ |kd La ∑iLi Vi ρd ρs li
79
![Page 80: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/80.jpg)
ray traced reflections and refractions
perfectly shiny surfaces reflects objects
recursively trace a ray if material is reflective or refractive
80
![Page 81: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/81.jpg)
ray traced reflections and refractions
reflections: along mirror direction ,
scaled by
refractions: along refraction direction scaled by
implementation detail: recursion
avoid hitting visible point:
make sure you do not recurse indefinitely
r = −l + 2(l ⋅ n)nkr
kt
C = + ⋅ (P)( + )|n ⋅ | +kd La ∑iLi Vi ρd ρs li
+ raytrace(P, r) + raytrace(P, t)kr kt
> ϵtmin
81
![Page 82: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/82.jpg)
image so far
82
![Page 83: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/83.jpg)
antialiasing
83
![Page 84: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/84.jpg)
antialiasing: removing jaggies
1 sample/pixel
84
![Page 85: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/85.jpg)
antialiasing: removing jaggies
1 sample/pixel
85
![Page 86: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/86.jpg)
antialiasing: removing jaggies
1 sample/pixel
86
![Page 87: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/87.jpg)
antialiasing: removing jaggies
1 sample/pixel
87
![Page 88: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/88.jpg)
antialiasing: removing jaggies
1 sample/pixel 9 sample/pixel
88
![Page 89: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/89.jpg)
antialiasing: removing jaggies
1 sample/pixel 9 sample/pixel
89
![Page 90: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/90.jpg)
antialiasing: removing jaggies
1 sample/pixel 9 sample/pixel
90
![Page 91: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/91.jpg)
antialiasing: removing jaggies
1 sample/pixel 9 sample/pixel
91
![Page 92: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/92.jpg)
antialiasing: removing jaggies
poor-man antialiasing:
for each pixel
take multiple samples
compute average
92
![Page 93: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/93.jpg)
ray tracing pseudocode
for(i = 0; i < imageWidth; i ++) {
for(j = 0; j < imageHeight; j ++) {
u = (i + 0.5)/imageWidth;
v = (j + 0.5)/imageHeight;
ray = camera.generateRay(u,v);
c = computeColor(ray);
image[i][j] = c;
}
}
93
![Page 94: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/94.jpg)
anti-aliased ray tracing pseudocode
for(i = 0; i < imageWidth; i ++) {
for(j = 0; j < imageHeight; j ++) {
color c = 0;
for(ii = 0; ii < numberOfSamples; ii ++) {
for(jj = 0; jj < numberofSamples; jj ++) {
u = (i+(ii+0.5)/numberOfSamples)/imageWidth;
v = (j+(jj+0.5)/numberofSamples)/imageHeight;
ray = camera.generateRay(u,v);
c += computeColor(ray);
}
}
image[i][j] = c / (numberOfSamples^2);
}
}94
![Page 95: ray tracing - Fabio Pellacinipellacini.di.uniroma1.it/teaching/graphics13a/slides/03_raytracing.pdf · raytracing algorithm for each pixel {determine viewing direction intersect ray](https://reader031.fdocuments.in/reader031/viewer/2022022420/5a7dfc547f8b9a2e6e8e14c4/html5/thumbnails/95.jpg)
image so far
95