Getting ready

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:

  1. Create a new scene and fill it with a simple sphere model.
  2. Create a new shader (Desaturate) and material (DesaturateMat).
  3. Attach the new shader to the new material and assign the material to the sphere.
  4. Create a directional light and position it above your sphere.
  5. 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.
  6. You should now have a simple scene set up to work on the shader. ...

Get Unity 2018 Shaders and Effects Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.