intersecting_objects.md 2.89 KB
Newer Older
Hui Wang's avatar
Hui Wang committed
1
2
[[Home]](/docs/index.md)  [[User Guide]](/docs/guide/guide.md) [[Mesh Edit]](/docs/meshedit/overview.md) [[Path Tracer]](/docs/pathtracer/overview.md) [[Animation]](/docs/animation/overview.md)

yhesper's avatar
yhesper committed
3
4
5
6
---

# (Task 2) Intersecting Objects

allai5's avatar
allai5 committed
7
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
8

allai5's avatar
allai5 committed
9
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
10

Hesper Yin's avatar
Hesper Yin committed
11
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
12
13
14

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
15
16
17
* `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.
TheNumbat's avatar
TheNumbat committed
18
19
* `depth`: the recursive depth of the ray (Used in task 4).
* `throughput`: the fraction of incoming light along this ray that will contribute to the final image (Optionally used in task 4).
yhesper's avatar
yhesper committed
20

TheNumbat's avatar
TheNumbat committed
21
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
22
23
24

---

TheNumbat's avatar
TheNumbat committed
25
## Reference Results
yhesper's avatar
yhesper committed
26

TheNumbat's avatar
TheNumbat committed
27
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
28

Hui Wang's avatar
Hui Wang committed
29
30
31
![dodecahedron](./images/dodecahedron_normals.png)
![cbox](./images/cbox_normals.png)
![cow](./images/cow_normals.png)
yhesper's avatar
yhesper committed
32