How Ray Tracing Works in Computer Graphics, Part 3

Ok, Part 1 introduced the most basic building blocks of a ray tracer - drawing a line between two points and some clever math. Part 2 touched on that math - the properties of the object that determine how it appears. So for Part 3, we're going to look a little more about these properties. In Part 2, we looked at color; for Part 3, we're going to look at the rest of the basics.

Last time, we looked at the color properties of an object. For our extra dumb ray tracer, this was assigned via matplotlib parameters. Remember that the shape we're plotting is our object, and the parameters of our plotting function serve as the shape's properties and the final image is the raytracer. We saw this by plotting a red cube:

We created this image using: visualize_mesh.display_texture_mesh(vertices,edges,triangles,'red',1.0)

This function tells the raytracer what shape to plot (vertices,edges,triangles) and the color (red). Now it's time to think a little bit about lighting. When we view something with our eyes, the lighting determines how that object ultimately looks. Whether an object is bright, dull, in sunlight, in shade, etc. are all determined by the amount of light and the direction from which the light originates. When we get to making a real, grown up ray tracer, this will matter a lot. For now, let's just look at the core concept.

In our image visualization code, there's one remaining parameter: alpha. The object's alpha parameter, in our case, is the total amount of light falling upon the object. Well, not really, the alpha parameter tells the plotting function how transparent to draw the object. Or, for our raytracer, the alpha parameter sets how bright/saturated to render the object. Changing the alpha parameter results in objects like these:

Note that in our example, the edges and vertices are not lighter, only the cube's surface triangles. In the next part, we'll look in more depth at meshing and lighting. And eventually we'll stop using matplotlib as a ray tracer, I promise. In the meantime, feel free to download the code from the repo, https://github.com/pjdurst/ray-tracing-basics, and play around with the plotting functions.

Previous
Previous

How Ray Tracing Works in Computer Graphics, Part 2