Introduction to shaders

Everything rendered on the screen needs shaders. Shaders are small programmes that run on the GPU (graphics processing unit) very efficiently. These programmes calculate both the position of geometry vertices on the screen and the color of each fragment.

When do you need custom shaders?

For some visual styles, you may not need to to create your own shaders. Built in shaders support basic functionality like projecting vertices to screen space, configuring a specific color, texture, while also calculating how lights affect the color.

However, when this is not enough, you may have to create your own shaders. Some examples

  • Vertex animation: You can transform the position of the geometry's vertices. This can be done to make an object spin around an axis or make foliage look like it is swaying in wind. As this happens on the GPU, it is very efficient as opposed to doing this on the CPU.

  • Mixing materials: A mesh can only have one material rendered at a time. If you want to display different materials on different parts of a mesh, you can use a custom shader. You can for example use the angle of the surface to decide which color to render.

Last updated