We spent some time deep in a fragment shader using trigonometry to "move" pixels around and we started looking at building a trail effect from triangles. Getting comfortable with both fragment shader math and geometry are critical components on the path to tech art proficiency!

Trigonometry is part of a larger family of mathematical functions we can use to sculpt digital art. Many of these functions operate on ranges of values from 0 to 1 or -1 to 1, so they can be mixed and matched liberally. We will not be able to spend time on all of them in class but the Book of Shaders Chapter 05 does a really good job of introducing them. It even has this great animated diagram of sin and cos!

The fragment shader we worked in in class is available on the class repo at tag class-02-03-fragment-tricks.

Goopy!

Key Takeaways

  1. Positioning things in a fragment shader consists of "convincing" pixels to render differently -- you can use math to "change" the position a fragment "thinks" its in before deciding on your color.
  2. sin and cos are built into glsl and give you an easy way to create smoothly changing values. You can manipulate their magnitude by multiplying their result and their frequency by multiplying their argument.
  3. We can build simple shapes in code out of triangles with some vector math