Today I'd like to explain a technique we're using in our new game considering lighting. It involves using the lightmap to shade models like bullet impacts and characters. A lightmap is actually just another texture applied to a model in combination with the second texture coordinates. The lightmap is blended with the primary texture to obtain a model that is shaded without there being any (hardware) light in the scene. The reason this is done is because it is much faster to render than real-time lighting/shadows. The downside is that it is computed beforehand and so is static (i.e. not real-time). Below you see an example of a scene that uses a lightmap for shading and below that an example of what a lightmap texture looks like.
|An example of a lightmapped scene, notice the shadows of the trees and hills.|
|An example of a lightmap texture. You can see the shadows of trees and buildings in this texture.|
Now what we'd like is that when a character walks through the scene and walk into a shaded area, the character also becomes darker (because it's walking in the shade). To do this we cast a ray from the character onto the ground and get the second texture coordinate of the point on the ground. We then use this color on the character material and in this way it'll shade appropriately.
|A character in light on the left and in shadow on the right.|
|Bullet holes in light on the left and in shadow on the right.|