Specular Color In OpenGL
Question submitted by (07 October 1999)




Return to The Archives
 
  When drawing primitive with DirectX, you can specify both a specular and diffuse color component whereas OpenGL only takes one color component. At first I thought adding the specular to the diffuse and clamping to [0..255] would give correct results and it did if there is no texture... But when I apply a texture (Modulate) on a face , I have different results : In DirectX I have the expected specular highlight effect (white spot on the texture). In OpenGL the texture is at max color but there is no additional highlight. It looks like DirectX multiply the texture by the diffuse color and then adds the specular color. Is there any way to have the same effect in OpenGL ? Thanks for your help  
 

 
  What you describe is exactly right. The specular color is added at the end of the texturing stage. OpenGL exposes this functionality with the GL_EXT_secondary_color extension. Unfortunately this isn't a very well supported extension right now, but I've asked NVIDIA about it and the drivers that are coming with the GeForce256 should support it, as well as the GL_EXT_fog_coord extension so that's at least something. In the mean time the replacement for the effect is to use an additional texture that contains the specular highlight. This second method is actually becoming pretty common and I believe it is referred to as a gloss map. The problem with using the vertices for the specular highlight becomes obvious when you think about what a small highlight in the center of a triangle would look like. If the highlight doesn't touch any of the vertices it disappears, and then reappears as it moves across the surface of the object and touches other vertices. The texturing solution doesn't have this problem, but does use more fill rate. Fortunately with fill rates going through the roof this isn't an incredible problem.



Response provided by Tom Hubina
 
 

This article was originally an entry in flipCode's Fountain of Knowledge, an open Question and Answer column that no longer exists.


 

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.