![Page 1: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/1.jpg)
Ray Tracing II
![Page 2: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/2.jpg)
HW1 Part A due October 10
• Camera module
• Object module– Read from a file– Sphere and Light only
• Ray tracer module: – No shading. No reflection and refraction.
• Display module (in text mode)
![Page 3: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/3.jpg)
Ray-Object Intersection
• For example: sphere(x-x0)2+(y-y0)2+(z-z0)2=r2
• Ray: (x,y,z)=(x1,y1,z1)+t(xd,yd,zd)
• Find t that satisfy (x-x0)2+(y-y0)2+(z-z0)2=r2
• Normal vector?
• Also easy for planes, cones, …etc.
![Page 4: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/4.jpg)
Ray-Triangle Intersection
• Ray: (x,y,z)=(x1,y1,z1)+t(xd,yd,zd)
• Triangle:
(x,y,z)=(x1,y1,z1)+u(x01,y01,z01)+v(x02,y02,z02)
• Find t, u, v that produce the same (x,y,z)• Intersection found if:
t > 0
0 ≦ u, v 1, and≦u + v 1≦
V0V1
V2
![Page 5: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/5.jpg)
Part B due October 24
• Object module– Add at least a plane type.
• Ray tracer module: – Add shading, reflection, and refraction.
• Display module:– PPM library will be provided.
• Add a demo scene of your own.
![Page 6: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/6.jpg)
Lighting (Shading) & Shadow
• Point light is easy to implement.
• How to determine a surface point is in the shadow? Use a shadow ray (from intersection point to light).
• Shading will be introduced in the next lecture.
![Page 7: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/7.jpg)
Reflection and Refraction
• Reflected ray is determined by:– incoming ray and normal vector.
• Refracted ray is determined by:– Incoming ray– Normal vector– And density
• Snell’s law: I sin i = t sin t
i t
![Page 8: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/8.jpg)
Advanced Ray Tracing
• Make it fast.
• Make it better.– Anti-aliasing– Distributed Ray Tracing
![Page 9: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/9.jpg)
Make It Fast
• From Pharr’s Chapter 4– Object subdivision (i.e., bounding volume)– Spatial subdivision (e.g., grid, octree, kd-
tree)– Ray coherence.
![Page 10: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/10.jpg)
Anti-Aliasing
• Super(or Over)-sampling
• Adaptive vs. Non-adaptive
• Uniform vs. Jittered
• Detail coming in a future lecture
![Page 11: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/11.jpg)
Distributed Ray Tracing
• Published by R. L. Cook in 1984.
• Antialiasing
• Motion blur
• Depth of field (camera)
• Ideas behind other so-called Monte Carlo methods.
![Page 12: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/12.jpg)
Space Partitions
![Page 13: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/13.jpg)
Common Operations in 3D
• Line/object intersection– Given a ray or line, which object will it
intersect?
• View frustum culling
• Collision detection
![Page 14: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/14.jpg)
Sorting/Indexing in 3D
• Sequential search is too slow for large models.
• How about storing them in a 3D array?– Size will be overwhelming
• Think “hierarchy”
![Page 15: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/15.jpg)
Octree
• Divide the space in halves in X/Y/Z.– Always split in the middle.– You may also consider them as splitting in
X, then in Y, then in Z.
• If too many objects are in a partition, divide them again (recursively).
![Page 16: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/16.jpg)
K-D Tree
• More flexible than octree:– Not always splitted in the middle.– Split in X, then in Y, then in Z, or any order.
![Page 17: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/17.jpg)
Kd-tree Example
1
1
2 3
2
3
4 5 6 7
4
5
6
7
8 9 10 11 12 13
8
9
10
11
12
13
Figure Source: CS638 slides by Stephen Chenney, University of Wisconsin – Madison,
![Page 18: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/18.jpg)
BSP Trees
• From the paper by Fuchs et al, “On visible surface generation by a priori tree structures” SIGGRAPH 80.
• Binary Space Partition trees– A sequence of cuts that divide a region of
space into two
• Cutting planes can be of any orientation
![Page 19: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/19.jpg)
Drawing Order from BSP Trees
• BSP tress can be used to order polygons from back to front, or visa-versa– Descend tree with viewpoint– Things on the same side of a splitting plane as the
viewpoint are always in front of things on the far side
• Can draw from back to front– Gives the correct order for rendering transparent
objects with a z-buffer, and by far the best way to do it
• Can draw front to back too.
![Page 20: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/20.jpg)
BSP Example1
42
3 75
BA out8
D out
6
C out
12
3
4
56
78
outA
outBC
D Figure Source: CS638 slides by Stephen Chenney, University of Wisconsin – Madison,
![Page 21: Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection](https://reader035.vdocuments.us/reader035/viewer/2022062423/5697c0101a28abf838ccb4df/html5/thumbnails/21.jpg)
OBB Tree
• OBB stands for Oriented Bounding Box.
• OBB is a rectangular bounding box at an arbitrary orientation.
• Asymptotically faster for close proximity situations.