Why we need to set diffuse color when using specular map?

When I am using specular map, I also have to set some color properties on the material,

        tankMaterial.setBoolean("UseMaterialColors", true);
        tankMaterial.setColor("Diffuse", ColorRGBA.White);
        tankMaterial.setColor("Ambient", ColorRGBA.Blue);
        tankMaterial.setColor("Specular", ColorRGBA.White);
        tankMaterial.setFloat("Shininess", 50); 

I understand that I have to set the Shininess and Specular value for the the specular map. But I am already using diffuse map, so why I have to set the diffuse color? My understanding is that I need to use Diffuse color when I am not using diffuse map.

Also if I don’t set any diffuse color, the model appears black, and if I set it other color(i.e. red) it affects the whole model. So is White is a placeholder color to prevent it from interfering with the Diffuse map?

When you use “UseMaterialColors” the diffuse, ambient and specular colors are multiplied with their respective map values.
That’s not completely great IMO, but that’s how it works.

1 Like

Ah, that explain the black model when I don’t set any diffuse color.

So, when the diffuse color is set to white it doesn’t affect the diffuse map?

Usually when you don’t set a uniform you’ll have zero values. But that’s completely up to the drivers so you may have whatever is in memory on some cards…

Well it does… but you multiply the map value by 1, so the result is the map color :stuck_out_tongue:

1 Like

uh, thanks :stuck_out_tongue: