Understanding Vertex and Fragment Shaders
The best way to understand how Vertex and Fragment Shaders work is by creating one yourself. This recipe will show you how to write one of these shaders, which will simply apply a texture to a model and multiply it by a given color, as shown in the following screenshot:
Notice how it works similarly to how the Multiply filter in Photoshop works. That's because we will be doing the same calculation that's done there!
The shader presented here is very simple, and it will be used as a starting base for all the other Vertex and Fragment Shaders.
Getting ready
For this recipe, we will need a new shader. Follow these steps:
- Create a new shader (
Multiply
). - Create a new material (
MultiplyMat
) and assign the shader to it. - Bring the soldier prefab from the
Chapter 07 | Prefabs
folder into the scene and attach the new material to the prefab&apos...