How Ray Tracing Works in Computer Graphics, Part 2
So, Part 1 introduced the most basic building blocks of a ray tracer, which were, more or less, a piece of code that draws a straight line between two objects and then does math on it until the object(s) more or less resemble a physical system. The question then is: how does the math know what math to math? Or, put differently, what are the properties of the object that determine how it appears in the final, rendered image?
These properties are captured using textures—the physical properties of the outside faces of the object. And the textures are found within the object's mesh, contained within the mesh's triangles. To create textures, we add faces to our edges and vertices, which are themselves made up of triangles. So the textured mesh is the wireframe edges and lines, now with triangles filling in the sides of the cube.
This is the next step up in mesh complexity. This mesh is made up of the same edges and vertices as before but now also contains triangles. Triangles are like the faces on the exterior of the object. So edge-vertices-cube.txt is a set of (x,y) points that creates a wireframe cube. Adding triangles creates the "faces" of the cube. These triangles define the object's surface.
In the most abstract sense, the color of the triangles is a part of the cube's texture. It's a property assigned to each triangle, and these properties determine how the cube is displayed. Like last time, the viewpoint is the user, e.g., the person executing the code. The mesh is now a 3D cube with a texture contained within its triangles. The "rendered image" is the plot displayed by matplotlib. This ray tracer contains a type of "surrogate" physics: the color value assigned to the cube's triangles. This is still the most basic ray tracing possible: a mesh to visualize that contains textures, with these textures telling the code what and how to display the final image.
A textured cube mesh has been added to the git repo, https://github.com/pjdurst/ray-tracing-basics/tree/main/bare-bones-raytracing. This cube's texture is simply the color assigned to the triangles inside the mesh reading functions. To add these surface properties to the cube, we will adjust the variables that go into the Poly3DCollection structure that represents the faces of the cube. Below is our first "textured" object - the same cube, but now containing triangles that are the color red.