Geometry in Ray Tracing
CS6965 Fall 2011
Geometry in Ray Tracing CS6965 Fall 2011 Programming Trax Need to - - PowerPoint PPT Presentation
Geometry in Ray Tracing CS6965 Fall 2011 Programming Trax Need to be aware of: Thread assignment (atomicinc) Global memory Special function units Calling convention (use const &) NO DOUBLES! Inline
CS6965 Fall 2011
Fall 2011 CS 6965
2
Fall 2011 CS 6965
3
Fall 2011 CS 6965
4
Fall 2011 CS 6965
5
Fall 2011 CS 6965
6
Fall 2011 CS 6965
memory
from global memory
7
Fall 2011 CS 6965
8
Fall 2011 CS 6965
9
Fall 2011 CS 6965
10
Fall 2011 CS 6965
11
Fall 2011 CS 6965
12
Fall 2011 CS 6965
13
Fall 2011 CS 6965
14
Fall 2011 CS 6965
15
y=0 y=0 Real world Our ray tracer OpenGL Taught since 2nd grade Televisions Raster Images Other 1950’s technology
Fall 2011 CS 6965
imaginary camera
16
Fall 2011 CS 6965
worth doing
doing
17
Fall 2011 CS 6965
useful to perform?
point lie on?
18
Fall 2011 CS 6965
19
Fall 2011 CS 6965
V is a vector space, then the following are true ( are vectors, r, s are scalars):
X, Y, Z X + Y = Y + X ( X + Y ) + Z = X + ( Y + Z) X + 0 = 0 + X = X
20
Fall 2011 CS 6965
X + (− X) = 0 (rs) X = r(s X) (r + s) X = r X + s X r + ( X + Y ) = r X + r Y 1 X = X
21
Fall 2011 CS 6965
vector is three real numbers: ℜ3
22
Fall 2011 CS 6965
23
Fall 2011 CS 6965
line.
segment as radius and one endpoint as center.
sum of the inner angles on one side is less than two right angles, then the two lines inevitably must intersect each other on that side if extended far enough.
24
Fall 2011 CS 6965
Image from www.confluence.org
25
Fall 2011 CS 6965
properties (P ,Q are points, A,B are vectors):
P + 0 = P P + ( A + B) = ( P + A) + B For any Q, there exists A such that: Q = P + A ( A = P − Q)
26
Fall 2011 CS 6965
vectors?
27
Fall 2011 CS 6965
and ratios of distances
all affine
28
Fall 2011 CS 6965
translation vector)
M 00 M 01 M 02 TX M10 M11 M12 TY M 20 M 21 M 22 TZ ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥
M p + T = ʹ″ p
29
Fall 2011 CS 6965
M 00 M 01 M 02 Tx M10 M11 M12 Ty M 20 M 21 M 22 Tz ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ Vx Vy Vz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = ʹ″ Vx ʹ″ Vy ʹ″ Vz ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ M 00 M 01 M 02 Tx M10 M11 M12 Ty M 20 M 21 M 22 Tz ⎡ ⎣ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ P
x
P
y
P
z
1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ = ʹ″ P
x
ʹ″ P
y
ʹ″ P
z
1 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥
30
Fall 2011 CS 6965
points and vectors:
Vector classes
Vector class and store four values with 0 or 1 in the fourth component
31
Fall 2011 CS 6965
is the geometric meaning of P1 + P2?
32
Fall 2011 CS 6965
between two points?
for an arbitrary number of points only if the weights sum to 1
33
Fall 2011 CS 6965
points/vectors
34
Fall 2011 CS 6965
all affine
35
Fall 2011 CS 6965
Point)
36
Fall 2011 CS 6965
V + V
V - V
V
V
37
Fall 2011 CS 6965
inefficient
Vector&)
Vector(const Point&)
Vector::asPoint()
V*V and a way to access each component
38
Fall 2011 CS 6965
39
Fall 2011 CS 6965
need: first, an inner product
resulting in a scalar with these properties:
40
Fall 2011 CS 6965
41
Fall 2011 CS 6965
the Dot product:
42
Fall 2011 CS 6965
the vector P2-P1
find a unit vector having the same direction
43
Fall 2011 CS 6965
A B AxB
44
Fall 2011 CS 6965
A × B = A sinθ A × B = −B × A A × (B + C ) = (A × B ) + (A × C ) (sA ) × B = s(A × B ) A × B = Area of swept rectangle If C = A × B , then C is perpendicular to A and B (C ⋅ A = C ⋅ B = 0) If A = B
= −B then A × B = 0
45
Fall 2011 CS 6965
Ax Ay Az Bx By Bz Cx Cy Cz
46
Fall 2011 CS 6965
will bite you and nobody will be able to read your code
47
Fall 2011 CS 6965
Origin Direction
48
Fall 2011 CS 6965
t=0 t=1.0 t=2.0
49
Fall 2011 CS 6965
Where?
O + t V
50
Fall 2011 CS 6965
centered at the origin?
51
Fall 2011 CS 6965
centered at the origin?
52
Fall 2011 CS 6965
Sphere: x2 + y2 + z2 − r2 = 0 Ray: Ox + tVx,Oy + tVy,Oz + tVz ⎡ ⎣ ⎤ ⎦
53
Fall 2011 CS 6965
Sphere: x2 + y2 + z2 − r2 = 0 Ray: Ox + tVx,Oy + tVy,Oz + tVz ⎡ ⎣ ⎤ ⎦ Ox + tVx
2 + Oy + tVy
2 + Oz + tVz
2 − r2 = 0
54
Fall 2011 CS 6965
Sphere: x2 + y2 + z2 − r2 = 0 Ray: Ox + tVx,Oy + tVy,Oz + tVz ⎡ ⎣ ⎤ ⎦ Ox + tVx
2 + Oy + tVy
2 + Oz + tVz
2 − r2 = 0
Ox
2 + 2tVx + t 2Vx 2 + Oy 2 + 2tVy + t 2Vy 2 + Oz 2 + 2tVz + t 2Vz 2 − r2 = 0
55
Fall 2011 CS 6965
Sphere: x2 + y2 + z2 − r2 = 0 Ray: Ox + tVx,Oy + tVy,Oz + tVz ⎡ ⎣ ⎤ ⎦ Ox + tVx
2 + Oy + tVy
2 + Oz + tVz
2 − r2 = 0
Ox
2 + 2tVx + t 2Vx 2 + Oy 2 + 2tVy + t 2Vy 2 + Oz 2 + 2tVz + t 2Vz 2 − r2 = 0
Ox
2 + Oy 2 + Oz 2 + 2tVx + 2tVy + 2tVz + t 2Vx 2 + t 2Vy 2 + t 2Vz 2 − r2 = 0
56
Fall 2011 CS 6965
Sphere: x2 + y2 + z2 − r2 = 0 Ray: Ox + tVx,Oy + tVy,Oz + tVz ⎡ ⎣ ⎤ ⎦ Ox + tVx
2 + Oy + tVy
2 + Oz + tVz
2 − r2 = 0
Ox
2 + 2tVx + t 2Vx 2 + Oy 2 + 2tVy + t 2Vy 2 + Oz 2 + 2tVz + t 2Vz 2 − r2 = 0
Ox
2 + Oy 2 + Oz 2 + 2tVx + 2tVy + 2tVz + t 2Vx 2 + t 2Vy 2 + t 2Vz 2 − r2 = 0
t 2 Vx
2 + Vy 2 + Vz 2
2 + Oy 2 + Oz 2 − r2 = 0
57
Fall 2011 CS 6965
t 2 Vx
2 + Vy 2 + Vz 2
2 + Oy 2 + Oz 2 − r2 = 0
A quadratic equation, with a = Vx
2 + Vy 2 + Vz 2
b = 2 Vx + Vy + Vz
c = Ox
2 + Oy 2 + Oz 2 − r2
roots: −b + b2 − 4ac 2a , −b − b2 − 4ac 2a
58
Fall 2011 CS 6965
ray misses the sphere
two roots)
b2 − 4ac
59
Fall 2011 CS 6965
easier way…
x − Cx
2 + y − Cy
2 + z − Cz
2 − r2 = 0
60
Fall 2011 CS 6965
center of the sphere
61
Fall 2011 CS 6965
center of the sphere
62
Fall 2011 CS 6965
t 2 Vi V + 2t O − C
V + O − C
O − C
Vector ʹ″ O = O − C a = Vi V b = 2 ʹ″ O i V c = ʹ″ O i ʹ″ O − r2
63
Fall 2011 CS 6965
Vector, Color, Image, and Sphere classes
throwaway prototype, but the others you will use forever
Rearrange the same spheres (or make new
64