How to do it...

The following are the steps to create a normal map shader:

  1. Let's get the Properties block set up in order to have a color Tint and texture:
Properties 
{ 
  _MainTint ("Diffuse Tint", Color) = (0,1,0,1) 
  _NormalTex ("Normal Map", 2D) = "bump" {} 
} 
In this case, I have 1 in the green and alpha channels and 0 for red and blue, so the default color will be green. For the _NormalTex property, we are using a 2D type, which means we can use a 2D image to dictate what each pixel will use. By initializing the texture as bump, we are telling Unity that _NormalTex will contain a normal map (sometimes referred to as bump maps as well, hence the bump name). If the texture is not set, it will be replaced by a grey texture. The color used ...

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.