Shader Programming, Volume 8

Anisotropic Specular Lighting

Sebastian Monroy
2 min readJul 4, 2016

As we saw in the previous post, Phong and Blinn-Phong lighting models provide a simple, convincing simulation of realistic specular lighting. Let’s expand on their functionality to handle more complex surface types.

Chapter 3.5

Understanding Lighting Models, Creating an Anisotropic Specular type

The anisotropic type simulates directional grooves in a surface and stretches the Specular. The effect is fantastic for brushed metals, for example. Let’s see what tricks they pull this time.

Oh yeah, check this quote out:

“In future recipes, we will look at ways in which we can use the concepts of this recipe to achieve other effects such as stretched reflections and hair, but here, you are going to learn the fundamentals of the technique first.”

Note that I think “recipe” is a poor word choice and that the writer is a big fan of commas. That’s cool, though. Everyone loves commas. And recipes, I guess.

The first thing you’ll need is a texture for the Anisotropy normal map.

Go ahead, take one. I’ve got plenty.

Go ahead and set up a new shader, material, and scene like we always do, but let me explain something weird about this shader really quick before I give you the shader’s code.

This shader makes full use of both a custom lighting function and surface function. We kind of did in the last BlinnPhong shader, but the surf() function was really only used to set the base color of the surface. Another thing we haven’t seen in this book yet is the use of a second struct. In this case, the SurfaceAnisoOutput struct is used to get per-pixel information from the Anisotropic normal map. It’s also used as a means of interacting between the lighting function and the surface function. This is a powerful technique, I think.

Make sure to read the comments in the following code — some of the math is non-obvious.

You can read more about the UnpackNormal() function here. I was confused about it, too.

Left: Anisotropic Specular Lighting. Right: BlinnPhong Specular Lighting

And that wraps up Chapter 3! Crushed it. We’ve hinted at physically-based rendering (PBR) in the past, but if you want to understand how it works and how to use it, stick around for Chapter 4.

--

--