intersecting_objects.md 2.83 KB
Newer Older
yhesper's avatar
yhesper committed
1
2
---
layout: default
allai5's avatar
allai5 committed
3
title: (Task 2) Intersections
yhesper's avatar
yhesper committed
4
permalink: /pathtracer/intersecting_objects
allai5's avatar
allai5 committed
5
6
7
parent: "A3: Pathtracer"
has_children: true
has_toc: false
yhesper's avatar
yhesper committed
8
9
10
11
---

# (Task 2) Intersecting Objects

allai5's avatar
allai5 committed
12
Now that your ray tracer generates camera rays, we need to be able to answer the core query in ray tracing: "does this ray hit this object?" Here, you will start by implementing ray-object intersection routines against the two types of objects in the starter code: **triangles** and **spheres**.
yhesper's avatar
yhesper committed
13

allai5's avatar
allai5 committed
14
First, take a look at `rays/object.h` for the interface of the `Object` class. An `Object` can be **either** a `Tri_Mesh`, a `Shape`, a BVH(which you will implement in Task 3), or a list of `Objects`. Right now, we are only dealing with `Tri_Mesh`'s case and `Shape`'s case, and their interfaces are in `rays/tri_mesh.h`  and `rays/shapes.h`, respectively. `Tri_Mesh` contains a BVH of `Triangle`, and in this task you will be working with the `Triangle` class. For `Shape`, you are going to work with `Sphere`s, which is the major type of `Shape` in Scotty 3D.
yhesper's avatar
yhesper committed
15

Hesper Yin's avatar
Hesper Yin committed
16
Now, you need to implement the `hit` routine for both `Triangle` and `Sphere`. `hit` takes in a ray, and returns a `Trace` structure, which contains information on whether the ray hits the object and if hits, the information describing the surface at the point of the hit. See `rays/trace.h` for the definition of `Trace`.
yhesper's avatar
yhesper committed
17
18
19

In order to correctly implement `hit` you need to understand some of the fields in the Ray structure defined in `lib/ray.h`.

TheNumbat's avatar
TheNumbat committed
20
21
22
23
* `point`: the 3D point of origin of the ray
* `dir`: the 3D direction of the ray (always normalized)
* `dist_bounds`: the minimum and maximum distance along the ray. Primitive intersections that lie outside the [`ray.dist_bounds.x`, `ray.dist_bounds.y`] range should be disregarded.
* `depth`: the recursive depth of the ray (Used in task 5).
TheNumbat's avatar
TheNumbat committed
24
* `throughput`: the fraction of incoming light along this ray that will contribute to the final image (Task 5).
yhesper's avatar
yhesper committed
25

TheNumbat's avatar
TheNumbat committed
26
One important detail of the ray structure is that `dist_bounds` is a mutable field. This means that it can be modified even in `const` rays, for example within `Triangle::hit`. When finding the first intersection of a ray and the scene, you will want to update the ray's `dist_bounds` value after finding each hit with scene geometry. By bounding the ray as tightly as possible, your ray tracer will be able to avoid unnecessary tests with scene geometry that is known to not be able to result in a closest hit, resulting in higher performance.
yhesper's avatar
yhesper committed
27
28
29

---

TheNumbat's avatar
TheNumbat committed
30
## Reference Results
yhesper's avatar
yhesper committed
31

TheNumbat's avatar
TheNumbat committed
32
You should now be able to render all of the example scenes colored based on surface normals. Note that scenes with high geometric complexity will be extremely slow until you implement task 3. Here is `dodecahedron.dae`, `cbox.dae`, and `cow.dae`:
yhesper's avatar
yhesper committed
33

TheNumbat's avatar
TheNumbat committed
34
35
36
![dodecahedron](images/dodecahedron_normals.png)
![cbox](images/cbox_normals.png)
![cow](images/cow_normals.png)
yhesper's avatar
yhesper committed
37