[SOLVED] How do ambient light and material interact (bug?)

Note: I found this problem while coding but it seems to be an issue in the renderer as I get the same issue in the editor, too.

Basically, the ambient material is ignored, and ambient light only interacts with diffuse material property.


Scene ambient colour set to red
Three boxes, one with no material, two with.
Box 1 / Material 1 - Ambient colour = black, diffuse colour = white, has pinky cast - OK
Box 2 / Material 2 - Ambient colour = white, diffuse colour = black, looks black - I’d expect it to be pinkish.

Is this intended behaviour, or should ambient light red + ambient material white = red?


Hi. So we don’t really use constant ambient color for specular, which is probably wrong, the more I think about it. Right now ambient lighting is a simply added to other diffuse lighting and multiplied by albedo. Generally it’s preferred that you use cubemaps as a source of ambient lighting, and then you get both diffuse and specular lighting right, and the constant ambient color was just left there as a legacy solution which probably doesn’t make much sense. You can however switch from Physical to Phong material type, and then you’ll probably get what expected with the constant factor. In code it would be:

mat.fresnelModel = pc.FRESNEL_NONE;
mat.shadingModel = pc.SPECULAR_PHONG;
1 Like

Cool! (Note: should be fresnelModel not fresnelMode).

Having the ambient may be legacy, but it can be useful for simple lighting models for speed, etc.


1 Like

Well spotted @CarlBateman. I’ve edited the original response from @Mr_F.

No, Will, it had to be the other way :smiley:
Fixed myself.

Haha, oh yeah, you’re right. I must be going crazy!