Post
by fr0stbyte124 » Tue Jan 08, 2013 6:57 pm
Typically, it's deferred lighting. That's where lighting is calculated independently for for each light source, and then all of them are summed up in a single pass in screen-space.
-For Spotlights, you have to make a shadow map with a conical projection matrix. However, once that is done, you have an idea of which pixels on the screen need to read in that particular map.
-Point-lights are the same, only they are typically mapped to a 6-sided texture called a cubemap, with which they can project onto all surfaces. This one dies off with distance.
-Sunlight is the same as spotlights, except that its projection matrix is orthogonal (rectangular rather than conical, since the sun's distance is essentially infinity). More work is usually put into this one, because the shadow map has to cover a much larger area.
Shadow maps themselves are simply depth maps stored to a texture. Once reprojected, you calculate whether the screen-space pixel is in front of or behind the light source's depth map to decide whether that surface is lit or not. Things can get a lot more sophisticated when you start taking into account texture resolutions, soft shadows, atmospheric scattering, and so on, but all of them are depth comparisons at their core.
Every time you add another light source, you have to redraw the scene another time and use more resources to store the results. However, you can often reuse the results from frame to frame, so long as the lightsource hasn't moved. Still a game developer will try to limit the number of dynamic lights present in any scene to avoid swamping the GPU. We won't have any control over the number of lights here, so it could easily get out of hand fast.
Minecraft simplifies the approach by storing the light level for each voxel with a simple rule of "light level = brightest neighbor's light level - 1". Technically, this is also deferred lighting, only this particular method would be prohibitively expensive to do in realtime on a GPU. The Minecraft approach can't do hard shadows, but when smoothed, does make for some rather nice soft lighting, which can even spill around corners. The only other way to make that effect in realtime is a technique called global illumination, which happens to be fantastically expensive and only the highest level GPUs can do it at all.
Most of the time you see global illumination, the devs are cheating and placing ambient lights, which ignore walls and surface angles completely, or it's baked into the texture.
----
*edit*
There was once a mod around the time Zeppelin came out which did give you a carryable dynamic light. I'm pretty all it did was recalculate the voxel lighting (probably in some optimized way) and then redrew all chunks in which the light level was changed. It overloaded the axis aligned bounding box class, though, so there might have been more to it. For us, it would only be a texture update, which is rather-bandwidth friendly compared to the old way, so that is definitely an option we can consider. However, I wouldn't try it on anything which would require large updates, like changing the position of the sun, or casting ship shadows. That would need to be done with shaders.