Ray Tracing - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Ray Tracing

Description:

Why Write a Ray Tracer? More elegant than polygon scan conversion ... Snell's Law: i sin i = t sin. t Let = i / t =sin t / sin. i t = sin t m - cos t n ... – PowerPoint PPT presentation

Number of Views:137
Avg rating:3.0/5.0
Slides: 18
Provided by: csAri
Category:
Tags: ray | snell | tracing

less

Transcript and Presenter's Notes

Title: Ray Tracing


1
Ray Tracing
  • Alon Efrat
  • CS 534
  • Advanced Computer Graphics
  • (based on a course by John C. Hart)

2
Why Write a Ray Tracer?
  • More elegant than polygon scan conversion
  • Testbed for numerous techniques and effects
  • modeling
  • rendering
  • texturing
  • Easiest photorealistic renderer to implement

3
Overview
  • Vector arithmetic
  • Lookat viewing coordinates
  • Ray casting
  • Shadows
  • Reflection
  • Refraction

4
Homogeneous Coordinates
  • Point
  • o (xo, yo, zo, 1)
  • Direction
  • d (xd, yd, zd, 0)
  • Points translate, directions do not
  • Homogeneous coordinate always zero or one (no
    perspective distortion)
  • Ray
  • r (o,d) ((xo, yo, zo,1),(xd, yd, zd,0))
  • Ray direction d always unit length
  • Not absolutely necessary
  • Makes life easier

5
Dot Product
b
  • a b dot(a,b) lta,bgt
  • xa xb ya yb za zb
  • a b cos q
  • Cosine of angle between a and bif both unit
    length
  • Used to cast a shadow of one unit vector onto
    another

q
a
(ab) a
6
Cross Product
q
  • a ? b cross(a,b)
  • (ya zb - za yb, za xb - xa zb, xa yb - ya xb,
    0)
  • a ? b a b sin q
  • Returns direction perpendicular to the plane
    spanned by a, b
  • Used to set up coordinate systems

7
Eye LUV Coordinates
l (lookat - eye)/(lookat - eye)
v (l ? up)/(l ? up)
u v ? l
up
u
eye
l
v
lookat
  • Really called Gram-Schmidt Orthonormalization

8
Pixels in World Coordinates
ll eye dl - av - u
aspect ratio a w/h
focal length d 1/tan(fovy/2)
ll
eye
9
Casting Rays through Pixels
for (j 0 j lt VRES j) for (i 0 i lt
HRES i) p ll 2av (double)i/HRES 2u
(double)j/VRES d (p - eye)/p - eye r
(eye,d) color TraceRay(r) plot(i,j,color
)
10
TraceRay Attributes
  • Invoked with ray parameter
  • Better if object database is global
  • Best if TraceRay is a member function of object
    database object (yikes)
  • Returns a color vector (R,G,B,?)
  • ? indicates transparency
  • color ? foreground (1- ?) background

11
Object Hierarchy
12
TraceRay Definition
Color TraceRay(Ray r, int depth) HitObject
ho color c background if (intersects(r,ho))
c ho.shade(lights) / casts a shadow ray
/ c ho.ksTraceRay(ho.reflect(r),
depth-1) c ho.krTraceRay(ho.refract(r),
depth-1) return c
13
List Definition
class List public Composite Object
item100 int n boolean intersects(Ray r,
HitObject ho) min_t 1.e20 for (i 0 i
lt n i) if (itemi.intersects(r,o) o.t lt
min_t) min_t o.t ho
o combine_shade(ho) return (min_t lt
1.e20)
14
shade Definition
Color shade(Lights lights) Color c ka for
(l 0 l lt lights.n l) ldir
normalized(lightsl.pos - hit) if
(!intersects(ray(hit,ldir))) c
kdcddot(n, ldir) return(c)
15
reflect Definition
Ray reflect(Ray r) Ray bounce bounce.o
hit bounce.d 2.0dot(n,-r.d)n
r.d return(bounce)
16
Calculating Refraction
Snells Law ?i sin ?i ?t sin ?t
cos ?i n - i
Let ? ?i /?t sin ?t / sin ?i
t sin ?t m - cos ?t n
(sin ?t / sin ?i) (cos ?i n - i) - cos ?t n
(? cos ?i - cos ?t )n - ? i
m (cos ?i n - i) / sin ?i
17
refract Definition
Ray refract(Ray r) Ray t double ni
dot(n,-r.d) eta current_index/new_index t.o
hit t.d (etani - sqrt(1.0 -
etaeta(1-nini)))n etar.d return(t)
Write a Comment
User Comments (0)
About PowerShow.com