Download presentation
Presentation is loading. Please wait.
Published byVictoria McDaniel Modified over 8 years ago
1
Ray Tracing I
2
Reading Hill, Chapter 14, Sections 14.1 to 14.5 Hill, Chapter 14, Sections 14.7.1 and 14.7.2
3
References Hill Chapter 14 Specialized books: Online resources http://www.irtc.org/ http://www.acm.org/tog/resources/RTNews/html/ http://www.povray.org/ http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtrace0.htm http://www.siggraph.org/education/materials/HyperGraph/raytrace/rt_java/raytrace.html
4
Outline Introduction Camera and Ray Generation Ray-Sphere Intersection Ray-Plane Intersection Writing a Ray Tracer Shadows Recursive Ray Tracing
5
BRDF Dan Lemmon - Global Illumination: A Brief Overview http://www.debevec.org/IBL2001
6
Phong Illumination
7
Phong vs. Reality
13
Arnold Ray Tracer
14
Global Illumination in Games
15
Ray Casting For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest
16
Durer’s Ray casting machine Albrecht Durer, 16 th century
17
Durer’s Ray casting machine Albrecht Durer, 16 th century
18
Arthur Appel, 1968 “On calculating the illusion of reality”, 1968 Cast one ray per pixel (ray casting). For each intersection, trace one ray to the light to check for shadows Only a local illumination model Developed for pen-plotters V V L L
19
Ray Casting Image by Henrik Wann Jensen
20
Turner Whitted, 1980 “An Improved Illumination Model for Shaded Display”, 1980 First global illumination model. An object’s color is influenced by lights and other objects in the scene First to simulate specular reflection and refractive transmission V T L R L R T R R
21
Ray Tracing Original Ray-traced image by Whitted Image computed using the Dali ray tracer by Henrik Wann Jensen
22
Ray Tracing Image computed using the Dali ray tracer from Henrik Wann Jensen Model Stephen Duck
23
Outline Introduction Camera and Ray Generation Ray-Sphere Intersection Ray-Plane Intersection Writing a Ray Tracer Shadows Recursive Ray Tracing
24
Cameras For every pixel Construct a ray from the eye For every object in the scene Find intersection with the ray Keep if closest
25
Ray Representation A parametric line: Origin Direction (normalized is better) p(t) = origin + t * direction origin direction p(t)
26
Pinhole Camera Box with a tiny hole Inverted image Pure geometric optics
27
Simplified Pinhole Camera Eye-image pyramid (frustum)
28
Durer’s Ray Casting Machine Albrecht Durer, 16 th century
29
Perspective Camera Eye point Look-At Point Up Vector Horizontal FOV (degrees) Look-At Up Eye
30
Perspective Ray Generation
31
Outline Introduction Camera and Ray Generation Ray-Sphere Intersection Ray-Plane Intersection Writing a Ray Tracer Shadows Recursive Ray Tracing
32
Implicit Sphere Equation Implicit sphere equation: ||P|| 2 = r 2 Assume sphere is centered at the origin - easy to translate origin direction
33
Ray-Sphere Intersection Implicit sphere equation: ||P|| 2 = r 2 Parametric ray equation: p(t) = O + t d with || d || = 1 Intersection means both are satisfied origin direction
34
Ray-Sphere Intersection
35
This is just a quadratic at 2 + bt + c = 0, where a = 1 b = 2 d O c = O O – r 2 With discriminant and solutions
36
Ray-Sphere Intersection Three cases, depending on sign of b 2 – 4ac Which root (t+ or t-) should you choose? Closest positive! (usually t-)
37
Ray-Sphere Intersection So easy that all ray-tracing images have spheres!
38
Geometric Ray-Sphere Intersection Try to shortcut (easy reject) E.g., if the ray is facing away from the sphere Geometric considerations can help In general, early reject is important r S
39
Geometric Ray-Sphere Intersection What geometric information is important? Inside / outside Closest point Direction O r S d
40
Geometric Ray-Sphere Intersection Check if the ray’s origin is outside the sphere ||O|| 2 > r 2 If inside, it intersects If on the sphere, it does not intersect Avoid degeneracy with epsilon test (later) O r S d
41
Geometric Ray-Sphere Intersection If the ray’s origin is outside the sphere Find the closest point P to the sphere center t P = OS d If t P < 0: Ray points away from the sphere, no hit O r S d tPtP P
42
Geometric Ray-Sphere Intersection Else find squared distance e 2 Pythagoras: e 2 = OS 2 - t P 2 if e 2 > r 2 : Ray misses sphere, no hit O r S d P tPtP e
43
Geometric Ray-Sphere Intersection t’ 2 + e 2 = r 2 If ray starts outside sphere: t = t P - t’ If ray starts inside sphere: t = t P + t’ O r S d P tPtP e t t’
44
Geometric vs. Algebraic Algebraic was simpler (and more generic) Geometric is more efficient Timely tests In particular for outside and pointing away
45
Normal Simply (I(t)-S) / r O r S d t n I(t)
46
Precision Problems In ray tracing, the origin of (secondary) rays is often on the surface of objects Theoretically, t = 0 for these rays In practice, calculation imprecision creeps in, and the origin of the new ray is slightly beneath the surface This could lead to a situation where a surface area is shadowing itself…
47
to the rescue… Check if t is within some epsilon tolerance: if abs(t) < eps // eps = 0.01 point is on the sphere else point is inside/outside Choose the epsilon tolerance empirically Move the intersection point by epsilon along the surface normal so it is outside of the object Check if point is inside/outside surface by checking the sign of the implicit (sphere etc.) equation
48
Outline Introduction Camera and Ray Generation Ray-Sphere Intersection Ray-Plane Intersection Writing a Ray Tracer Shadows Recursive Ray Tracing
49
Implicit Plane Equation Given a point A on the plane and the normal n, any point P on the plane must satisfy: n A P v
50
Implicit Plane Equation Suppose n = [a, b, c] T and P=[x, y, z] T : Every plane perpendicular to n = [a, b, c] T has an implicit equation: The value d = 0 gives a plane through the origin Different values of d give parallel planes
51
Implicit Plane Equation Implicit plane equation ax + by + cz + d = 0 Plane defined by P 0 = [x, y, z, 1] T n = [a, b, c, 0] T
52
Line-Plane Intersection Insert parametric equation of the line into the implicit equation of the plane Origin Direction P(t)
53
Additional House Keeping Verify that intersection is closer than previous Verify that it is in the allowed range t<0: intersection is behind the camera O d p(t)
54
Headed towards plane? Dot product with normal if t n = 0: Ray parallel to plane; no intersection if t n < 0: Normal is pointing away from ray (may be culled)* if t n > 0: Ray hits plane *Reverse plane normal so that ray intersects:
55
Intersection Calculation Ray expression: Substitute into plane equation: Solve for t: If t < 0: ray intersects plane behind O
56
The Algorithm
57
Normal Use the normal to the plane from the implicit equation Normal Origin Direction P(t)
58
Outline Introduction Camera and Ray Generation Ray-Sphere Intersection Ray-Plane Intersection Writing a Ray Tracer Shadows Recursive Ray Tracing
59
Object-Oriented Design We want to be able to add primitives easily Inheritance and virtual methods Even the scene is derived from Object3D Object3D bool intersect(Ray, Hit, tmin) Plane bool intersect(Ray, Hit, tmin ) Sphere bool intersect(Ray, Hit, tmin) Triangle bool intersect(Ray, Hit, tmin) Group bool intersect(Ray, Hit, tmin)
60
Ray ////////// class Ray { ////////// Ray () {} Ray (const Vec3f &dir, const Vec3f &orig) {_dir =dir; _orig=orig;} Ray (const Ray& r) {*this=r;} const Vec3f &origin() {return _orig;} const Vec3f &direction() {return &dir;} Vec3f pointAtParameter (float t) {return _orig+t*_dir;} private: Vec3f _dir; Vec3f _orig; };
61
Hit Stores intersection point and various information ///////// class Hit { ///////// float _t; Vec3f _color; Material *_material; Vec3f _normal; };
62
Shaders ( Material Class) Functions executed when light interacts with a surface Constructor: Set shader parameters Inputs: Incident radiance (lights) Incident & reflected viewing directions Output: Reflected radiance
63
Outline Introduction Camera and Ray Generation Ray-Sphere Intersection Ray-Plane Intersection Writing a Ray Tracer Shadows Recursive Ray Tracing
64
Ray Tracing with Shadows Image Henrik Wann Jensen
65
Outline Introduction Camera and Ray Generation Ray-Sphere Intersection Ray-Plane Intersection Writing a Ray Tracer Shadows Recursive Ray Tracing
66
Turner Whitted, 1980 “An Improved Illumination Model for Shaded Display”, 1980 First global illumination model. An object’s color is influenced by lights and other objects in the scene First to simulate specular reflection and refractive transmission V T L R L R T R R
67
Does it ever end? Stopping criteria: Recursion depth: Stop after a number of bounces Ray contribution: Stop if reflected / transmitted contribution becomes too small 1 recursion0 recursion2 recursions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.