# Essential Mathematics for Graphics (Shader) Programming

Save 35% off the list price* of the related book or multi-format eBook (EPUB + MOBI + PDF) with discount code **ARTICLE**.

* See informit.com/terms

*The difference between the poet and the mathematician is that the poet tries to get his head into the heavens while the mathematician tries to get the heavens into his head.*

—G.K. Chesterton

In graphics programming, there are two components you need to understand: the programming framework and what problems it is capable of solving. The language of graphics is mathematics, which is the purest language we have to describe the world around us. Everything we see and everything that moves can be expressed mathematically, and the equations can be easily expressed in code. This chapter covers some important mathematical concepts that enable the framework to turn lifeless-looking code into lively, detailed graphics.

## Language of Mathematics

An algorithm is a process or set of rules to be followed in calculations or other problem-solving operations. The meat of an algorithm is the idea or process it describes. This description can be expressed in many “languages”—English, JavaScript, or linear algebra, for example. The ability to mentally articulate how to solve a problem and what a process does is an invaluable skill that will help you on your journey as a graphics programmer.

One advantage of expressing things mathematically is that mathematical algorithms are platform agnostic. There are not, as of this writing, a multitude of books on Metal programming, but the concepts around graphics math have been around for hundreds of years. Being able to “speak” this language allows you to use these resources to do incredible effects—you’re not constrained to materials that are written in the Metal language.

Graphics math is a vast topic. It includes aspects of linear algebra, vector calculus, and statistics. This information could—and does—fill several books. This chapter serves as a high-level overview of the concepts you should be familiar with and how they fit in this process. There are many wonderful resources out there for shader effects, but many of them are either platform specific or express their ideas mathematically. Having a basic understanding of these concepts allows you to decode those resources even though they may have been intended for a piece of software that no longer exists.