My Journey into the Fundamentals of Computer Graphics - Part 2

My Journey into the Fundamentals of Computer Graphics - Part 2

Linear Algebra Strikes Back

Overview

Hi everyone! This week I continued reading and doing the exercises of the books that I started last week. I finished part 2 of the book by Penny de Byl, where I saw practical applications of essential trigonometry. Meanwhile, in the 3D Math Primer book, I reviewed linear algebra concepts which I go into more detail in the corresponding section. So let's jump straight into what I learned!

Top 3 things I learned

Upright space

The authors of 3D Math Primer introduce a coordinate space that they call "upright space". It is halfway between world space and a particular object space. Besides, the axes are parallel with the axes of the world space and the origin coincides with the origin of the object space. It'll probably make a lot more sense if you look at this figure from the book:

I found it very useful because it makes it easier to transform a point between the world and object space by separating the operation into 2 steps, as shown in this figure:

Normals are very useful

I went from learning how to draw the normals of a cube to calculating the normals of the triangles of each polygon to draw it correctly.

Drawing normals of a cube:

Drawing normals on each triangle face of a cube

Displaying normals on a loaded mesh

Besides, I also learned these two uses of normals:

  • Dictating which side of a polygon is visible through culling, which is removing polygons by not rendering the backface (opposite side of the polygon from which the normal is projected). This means that you only see the polygons that have their normal projected into the camera.

  • Drawing billboards, which are flat planes that represent something solid from both sides. This is mostly used for faking distant geometry/buildings or individual leaves/branches on vegetation and grass.

Specify the order of your vertices!

Normals are also used to calculate how light falls across the surface of a polygon. However, you must specify the order of your vertices to avoid having problems with external files. This is because if OpenGL doesn't receive information about how to calculate the normals, it will automatically calculate them assuming that they are given in a counter-clockwise order. This can result in incorrect lighting of an object. Hopefully, these two GIFs will clarify this point:

Not calculating the normals will give the impression that the colors randomly change and not provide any indication of the direction of the light source.

When the normals are calculated correctly, it's easy to see that the cube is lit from a single direction.

This week's math concepts

Multiple Coordinate Spaces

This chapter was very important for understanding the different coordinate spaces (world, object, camera, and upright). Besides, it explains the usefulness of basis vectors when performing transformations between coordinate spaces.

Intro to Matrices

This chapter served as a review of the basics of matrices. Most notably, it allowed me to understand how a square matrix can describe any linear transformation (which I'll see in more detail in the next chapters). I also found very useful the explanation of how, by interpreting the row vectors of a matrix as basis vectors, you can construct or deconstruct the matrix and visualize the transformation.

For example, it explains how sketching a skew box (the complete parallelogram that is formed by 2 basis vectors) and drawing the object inside the box can help with the visualization, as shown in these figures:

Skew box.

Drawing the object inside the skew box.

Useful resources

This week, there are just a couple of useful resources provided by the 3D Math Primer book. The authors explain how the concepts of linear algebra in the book only focus on the geometric applications of vectors and matrices. They explain how solving larger systems of equations is something that is usually involved in the development of these technologies:

  • Physics engine

  • Fluid simulation

  • Cloth simulation

  • Hair simulation

  • Robust procedural animation

  • Real-time global illumination

  • Machine vision

  • Gesture recognition

Since the book doesn't cover how to solve these bigger parts of linear algebra and scientific computation, the authors recommend a pair of courses from MIT OpenCourseWare given by Professor Gilbert Strang:

What's next

Next week, I'll continue my deep dive into linear algebra by learning the theory and practical applications of the essential linear transformations. Meanwhile, I invite you to tell me your thoughts on the use of "upright space"!