Sunday, 2 January 2011

Why corners are dark

I am constantly plagued by “why”. One of the “why”s which has been eating away at me for a couple of days is that of ambient occlusion. Ambient occlusion is a technique in games that allows raised details to “pop” more by darkening surfaces close to corners. It works well and gives extra strength to the 3D illusion. It relies on the following truism: “corners are dark”

But does it really happen? My first response was: well sure, if you’ve got a shadow being cast, otherwise probably not - just a trick to make things look less flat. But as time passed, this problem ate away at me, and I have concluded that yes it really does happen. And here’s why…

A - Corners receive less direct light. 
Relevance: 6

In the diagram, a four-walled room is being lit by an ordinary bulb casting light in all directions evenly. If we divide this light into 15 degree sections, each emitting the exact same amount of light, we can examine where this light strikes. In sections near the middle of the wall, the light strikes only a small area of the wall. The same amount of light strikes a much larger surface area in the corner of the room, where the angle is more acute.

If the same amount of light strikes a larger surface area, it stands to reason that the strength of that light is diluted across the surface, and consequently the surface appears darker.

B - Corners are far away from lights.  
Relevance: 0.1

This might be some people’s immediate response to why the corners of a room are dark. While there is some truth to this, I believe this case to be very weak.

Let’s assume light sources are not found in corners (they generally aren’t). This means generally, corners are further from the source, and when this is the case, some light scatters on dust particles/similar before reaching the corner. This is called light falloff. Comparing corners to flat surfaces, however, we’re talking about very short distances, so the amount of falloff is negligible. Dusty rooms or foggy or smoky environments would cause more light falloff, but I’m still going with “barely relevant” on this one.

  C - Corners receive less scattered light.
Relevance: 4

Light bouncing around all over the place has a reduced chance of striking in a corner. In the diagram we follow 8 paths of light from the source - only a couple strike anywhere near a corner, whereas 4 could be said to hit very near to the middle portion of one of the walls. The innermost of the corner is affected most strongly by this phenomenon.

D - Corners are in “scatter-shadow”. 
Relevance: 0 to 10

This is not at all true of our four-wall room scenario, but it certainly is true of many other corner situations. While this shadow may not be from direct light sources and consequently no hard shadow edges are shown, here’s an example of where a corner is in scattered light shadow (another surface is catching its scattered light).

The diagram illustrates that those sections tucked away in the corner do not catch much, or any of the primary bounce light, and must receive it from a secondary bounce (which is less strong).

And here’s a real-life photo taken from the comfort of my desk to demonstrate the above. Apologies for the picture quality - fetching anything more than my phone camera would require me leaving my seat. Goodness, just the thought of it… 


D - corners are in scatter-shadow. 
We're already in shadow from the direct light, so the shadows you're seeing within the shadow are entirely scatter-shadows. 

C - corners receive less scattered light. 
Notice how the corner is darker, particularly very near to the corner. 

A - Corners receive less direct light.  
As the angle becomes less perpendicular to the source of the light, the light is spread over a larger area. This can be seen in two places of this picture.

C -  corners receive less scattered light. 
Again, the very innermost part of the corner has quite a dark line where very little scattered light reaches. 



    you're probably familiar with all this stuff, but its interesting anyway. certainly far removed from my physics at school when 'light travels in a straight line'

  2. damn impressive crytek have got all this in realtime - baked lightmaps are so limiting, particularly for anything dynamic. thanks for the share!