Specularity

Originally posted to Shawn Hargreaves Blog on MSDN, Thursday, April 12, 2007

BasicEffect uses the standard Blinn-Phong shading model, which combines both diffuse and specular light.

Tweaking the diffuse part is pretty easy. Just set the BasicEffect.DiffuseColor property to the color of your object, or to white if your model is textured, and you're done.

Here is a model illuminated only by only diffuse light:

Specular light can be harder to understand. When viewed in isolation, its contribution seems incredibly minimal:

But in combination with the diffuse light, specular is a critical part of making a model look good. Set it too low, and your objects will appear flat and uninteresting. Too high, and everything will look like plastic: waxy and unnatural.

So how do you tweak specular?

BasicEffect.SpecularColor should almost always be monochrome. Brighter whites increase the overall amount of specularity, while darker grays make it more subtle.

BasicEffect.SpecularPower is the more important property. This controls the focus of the specular highlight. Smaller values produce a softer, more blurred highlight, while higher settings give a smaller and tighter glint.

Here is the character model rendered using SpecularPower = 4:

 

This is using SpecularPower = 16:

 

And finally with SpecularPower = 64:

Makes quite a difference, huh? The higher specular power looks silly on the skin, but I like how the more focused glints accentuate the shape of the leggings and that wrist armor thingie.

A single specular power will rarely look good for all the surfaces which make up a model. You will usually need several different materials, each with different specular settings, to get good results.

Fortunately, both the .FBX and .X model formats support specular power as part of their standard material data, so you can set up as many materials as you like in your modeling program, and the content pipeline will bring these settings through into the game for you.

If you are writing your own shaders rather than using BasicEffect, you might want to consider using a separate texture, or perhaps the alpha channel of your main texture, to control the specular amount and power. That way you can tweak these settings differently for every single pixel, rather than just changing them from one material to another.

Blog index   -   Back to my homepage