4
Working with Shaders
Welcome to Chapter 4! In the previous two chapters, we created renderers for OpenGL and Vulkan, but we addressed only the application part of the drawing: how to store the data in a simplified model and how to copy the data over to the GPU via a vertex buffer.
The GPU needs to know what to do with the data too. We must tell the graphics card in which format, sizes, and order the data for the vertices arrives, whether and how we would like to transform it, and how to apply colors or textures to the objects we sent.These steps are done in so-called shaders, which are small programs running on the compute units of your graphics card.
In this chapter, we will take a deeper look into the basic functionality of shaders. You will learn more about the way data is sent to the GPU – the vertex data itself, and additional data, such as transformation matrices.
We will also discuss the OpenGL Mathematics (GLM) library, allowing you to use the same data...