High Quality Specular

August 10, 2011 by Terry

Here is a trick you can do with shaders to remove common ugly artifacts from your specular highlights. You might have seen it before–the Microcosm screensaver uses this technique to good effect. I’m sure other people have thought of this, but I haven’t seen it written up anywhere, and it’s a simple enhancement that can be a big help visually.

The specular highlight on the left sphere is what you get with the simple addition of your specular light value.  Notice the off-color rings around the highlight (click the image to enlarge it).  The silky smooth highlight on the right is achieved by multiplying the specular value by the difference between pure white and the underlying color value.  This causes each of the RGB color channels to saturate in the same pixels instead of in rings so that you only see the intended color of your highlight and no extra colors.  Here is the GLSL code for both methods:

// regular specular addition
diffuse.rgb += specular;
// smart specular addition
diffuse.rgb += specular * (vec3(1.0, 1.0, 1.0) - diffuse.rgb);

The OpenSceneGraph model file shown in the image, containing the complete GLSL shader code, can be downloaded here: quality_specular.osg.

2 Responses to “High Quality Specular”

  1. corysama

    Very cool.

    This is similar to how artists often blend in additive stuff using “screen” mode rather than additive because it is better at avoiding “blowing out” the color to white.

  2. Interesting article. Looks like it’s mathematically identical to what I’m doing in my shader. The sad thing is that I’ve used the screen filter in Gimp and Photoshop many times without really thinking about what it was doing.

Leave a Reply