ray tracing ii. hw1 part a due october 10 camera module object module –read from a file –sphere...
TRANSCRIPT
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 and refraction.
• Display module (in text mode)
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.
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
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.
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.
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
Advanced Ray Tracing
• Make it fast.
• Make it better.– Anti-aliasing– Distributed Ray Tracing
Make It Fast
• From Pharr’s Chapter 4– Object subdivision (i.e., bounding volume)– Spatial subdivision (e.g., grid, octree, kd-
tree)– Ray coherence.
Anti-Aliasing
• Super(or Over)-sampling
• Adaptive vs. Non-adaptive
• Uniform vs. Jittered
• Detail coming in a future lecture
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.
Space Partitions
Common Operations in 3D
• Line/object intersection– Given a ray or line, which object will it
intersect?
• View frustum culling
• Collision detection
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”
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).
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.
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,
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
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.
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,
OBB Tree
• OBB stands for Oriented Bounding Box.
• OBB is a rectangular bounding box at an arbitrary orientation.
• Asymptotically faster for close proximity situations.