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 image:
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.
- Create a new material and assign the shader to it.
How to do it…
In all the previous chapters, we have always been able to refit Surface Shaders. This is not the case anymore as Surface and Fragment Shaders are structurally different. We will need the following changes:
- Delete all the properties of the shader, replacing them with the following:
_Color ("Color", Color) = (1,0,0,1) // Red _MainTex ("Base texture", 2D) = "white" {}
- Delete...