Unity and the Beast

I must say I experiment a lot with Lightmapping in Unity using Beast and I have never wrote anything about it, so I wanted to share what it is and how it might be useful to some of you.

Since the time of Quake which was the first video game to utilize lightmapping, Unity has integrated the Beast lightmapping technology for both the pro and free version, yes! you can use expensive rendering power for free on your games, I know what your thinking…this is awesome, and it is,  lightmaps can really bring your environments to life.

What are lightmaps?

If you have read this far without knowing what lightmaps are, I’ll give a quick overview, a typical lightmap is light data stored into a texture and applied to static objects in your scene, lightmaps in Unity take into account meshes, textures, materials and lights.

Unity contains 3 lightmapping modes to choose from, Single Lightmaps. Dual Lightmaps and Directional Lightmaps, each mode has slightly different functionality.

Single lightmap mode uses the far lightmap only, this is a baked texture, so pre-computed and contains full illumination.

Single lightmaps

Dual Lightmaps use a near and far lightmap texture, the near lightmap texture contains indirect illumination from lights set to auto, full illumination if your lights are set to BakeOnly, emissive materials and sky lights.

This near lightmap is only used when within the distance of the camera, when within the camera distance auto lights are rendered as realtime allowing for specular, bump and realtime shadows, this is not a feature for single lightmaps.

Single and  Dual Lightmap

On the right hand side on the image showing dual lightmapping, the near lightmap texture is used, this is because we are within the camera’s distance, near lightmap texture is showing both specular and bump, as if it was realtime lighting. If we were to pan the camera away from the leaf we would eventually not see the bump and spec because it will fallback to the far lightmap, which is shown on the left.

Using Directional lightmapping in Unity has the ability to bake specular and normal maps into the texture without using any realtime lighting, the lightmaps encode the direction of the light so that it can be used in the pixel shader to vary the lighting depending on the per pixel normal and calculates specular for the average light direction.

The image below shows baked specular using directional lightmaps, I have a simple mouse orbit script attached to the camera which allows me to see the specular highlights on all the cubes in the scene.

directional lightmap

Other area’s of lightmapping which I haven’t mentioned in any real detail or at all are using emissive materials, they can give some really interesting effects, as well as area lights, light probes and lightmapping dynamic objects, that’s a whole new dimension of fun.

Maybe I’ll write about those some other time, for now I encourage you all to have a play around with lightmapping. Catch you soon!