Rendering 3D scenes on a 2D screen
We’ve seen that a 3D shape cannot be blitted on a screen as-is. This is because the computer just doesn’t have the required information to fill the entire set of pixels from the virtual positions of the shape’s vertices. So, in practice, how do shaders achieve this? In the following sections, we will discuss the working of shaders, both in general and in Unity.
A typical 3D rendering pipeline
Shaders are able to bridge the gap between the scarce 3D data and the denser 2D pixel information, thanks to the following three-step process:
- Vertex shader: First of all, the shader has to gather all the data about the shape that is necessary for its render. This is done in the vertex shader: this piece of code is run in parallel on all vertices of the 3D mesh and transforms the initial raw per-vertex data into processed per-vertex data. Usually, this process implies converting the vertex’s position from object space...