Before we start diving into the meat of writing the shader, we need to get a few items set up in our scene. Let's do the following and then open the shader in your IDE of choice:
- Create a new scene and fill it with a simple sphere model.
- Create a new shader (Desaturate) and material (DesaturateMat).
- Attach the new shader to the new material and assign the material to the sphere.
- Create a directional light and position it above your sphere.
- Finally, open the UnityCG.cginc file from Unity's CgInclude folder located in Unity's install directory. This will let us analyze some of the helper functions' code so that we can understand what is happening when we use them.
- You should now have a simple scene set up to work on the shader. ...