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”

Leave a Reply to corysama

   Click here to cancel reply.