BTW, under what circumstance would a light’s specular color be different than it’s diffuse color? Just out of curiousity…
The specular reflection from most real surfaces is the color of the light source, hence the specular color should be white (or grey if its a very dull surface)
Only a few metals such as gold have a specular highlight the same color as the material, and hence these are the only materials that should use single-color mode if you want a realistic look.
For a textured surface, both the primary & secondary colors will usually be white, but you still need the separate secondary color to prevent the specular highlight being colored by the texture.
The full lighting equations are:
L = Direction of light
v = inverse of L
d = Spotlight pointing direction
s = half-angle vector
n = Vertex Normal
Light[0].Attenuation = 1/(ConstantAttenuation + (LinearAttenuation * Light[0].DistanceFromVertex) + (QuadraticAttenuation * Pow(Light[0].DistanceFromVertex,2)))
if spotlight then
if vertex outside light-cone then
Light[0].SpotlightEffect = 0
else
Light[0].SpotlightEffect = pow( max( dot(v,d),0 ), Light[0].SpotlightExponent )
else
Light[0].SpotlightEffect = 1;
NOTE: In the following equations all terms including “Light[0]” are repeated and summed for each light, while all other terms (emmisive & ambient) are only included once in the sum.
PrimaryColor = Material.Emission + (Light[0].Ambient * Material.Ambient) + ( Light[0].Attenuation * Light[0].SpotlightEffect * ((Light[0].Ambient * Material.Ambient) + (max(dot(L,n),0) * Light[0].Diffuse 8 Material.Diffuse))
SecondaryColor = Light[0].Attenuation * Light[0].SpotLightEffect * ( pow(max(dot(s,n), 0), Material.Shininess) * Light[0].Specular * Material.Specular );
(IF texturing is enabled THEN combine the texture color at the current texture coords with the PrimaryColor using the currently enabled replace, modulate, decal or blend texture function)
FragmentColor = PrimaryColor + SecondaryColor;