Shader Programming, Volume 1

The Basics

Sebastian Monroy
2 min readMay 29, 2016

Like a lot of game developers, I need to learn shader programming but have gotten away with putting it off for years. I have some experience with shader programming from one of the courses I took in college but I didn’t get much out of it, aside from an appreciation for how important shaders are and how little I know about them.

Amazon: goo.gl/260UW8

I’ll be starting with this book, Unity 5.x Shaders and Effects Cookbook by Alan Zucconi and Kenneth Lammers, and taking notes as I go.

You can follow my progress on GitHub, if you so please.

goo.gl/SI9r6l

Chapter 1

Creating Your First Shader

Shader properties can be defined in the Properties block as follows:

Properties
{
_VariableName ("Inspector GUI Name"", Type) = Default Value
}

Here’s a list of Surface Shader Property Types:

  • Float: this creates a float value in the Inspector tab but without a slider
  • Range(min, max): this creates a float property as a slider from the min value to the max value
  • Vector: this creates a four-float property that allows you to create directions or colors, for example = (float, float, float, float)
  • Color: this creates a color swatch in the Inspector tab that opens up a color picker = (r, g, b, a)
  • Rect: this creates a non-power-of-2 texture swatch and functions the same as the 2D GUI element
  • Cube: this creates a cube map swatch in the Inspector tab and allows a user to drag and drop a cube map in the shader

The code for the first shader this book has you create is pretty straight-forward.

When attached to some spheres in a simple scene with values

  • Color = (255, 0, 0, 255)
  • AmbientColor = (218, 213, 248, 255)
  • This is a slider = 7.2

it looks like the left image.

Neat! But I still don’t know shit.

Let’s continue.

--

--