# Calculating ambient light.

• 06-06-2006
psychopath
Calculating ambient light.
I had an idea a little while ago for calculateing the ambient lighting term, but i'm not sure how well it would work in practice.

Suppose in my lighting system, i'm rendering the scene to a texture every frame to use HDR rendering, or some other technique that uses video post-processing.

Now, up untill now i've been just using a static value (usually zero) for the ambient term. But , if I were to get the average color from my scene texture, would this not be a more accurate ambient light value? To me (in theory of course), it sounds like using the average screen color as the ambient term would be able to emulate global indirect lighting.

This is probably not an original idea, but I haven't heard of it.
Is there any chance it could work, or does this idea break down when put into practice?
• 06-06-2006
VirtualAce
It breaks down because then ambient light is dependent on other light sources in the scene since they will add light to it. This means as your light's hit objects and thus lights surfaces up, this increases your average value, but it increases it for every object in the scene - no matter where it is.

Take two objects and stick a wall between them. Shine a light on the right hand object and you will unfortunately illuminate the left hand object as well since your ambient light for the entire scene has increased. It will increase because the surface of the right hand object has been lit. When you go to average the colors, these will increase the overall average even if the other object is totally obscured from the light hitting the right object. It wouldn't look right.

Ambient light is fine at being a static value. I normally choose something like 40 to 100 depending on the environment. I tried to use 0 in my space game and wow....everything looked pitch black when you moved away from the sun. Probably realistic, but not very fun.
• 06-07-2006
psychopath
>>This means as your light's hit objects and thus lights surfaces up, this increases your average value, but it increases it for every object in the scene - no matter where it is.

Wouldn't some type of shadowing method solve this?
• 06-07-2006
VirtualAce
But your ambient lighting calculations would nullify the shadowing. Essentially your ambient light calculation would be almost like doing a gamma ramp on the screen. It would brighten more and more with each light source which is how ambient light works, but it does not work like that in a world-based lighting model.