Unanswered
Lightbaking Tutorial

In Unity, you can have two light types; baked lights and dynamic lights. Dynamic lights are how we light our characters, and lightbaking is how we apply lighting to our environment.

Baked lighting has many advantages over dynamic lights- Unity has many rendering qualities which simulate light physics (like ambient occlusion and global illumination), which make the scene feel MUCH more real, but are only available in baked lights. They're also way less comutationally expensive. When a scene is playing a dynamic light needs to be calculated every frame. A baked light is simply overlayed at the beginning of the scene. Unity knows that it won't move so it doesn't need to update it.

Any light which is going to bake into the scene needs to be setup as a "baked" light. Area lights are baked by default. You can set a light to both Dynamically light a scene, and to also be baked if you set it to "mixed".

In order to bake light onto an object, the "static" box must be checked. This tells unity that this object is NOT going to move, and it is ok to embed lighting onto it.

The next thing we need to do is to select our item in the project, and in the import settings on the inspector make sure its set to "Generate Lightmap UVs", and hit "Apply".

So on the backend, a UV map is the coordinates for how a texture is applied to a mesh. The theory is very like a sewing pattern. The UV is the flat pattern, the texture is the fabric, and the model is how the fabric drapes around the object.

On the left is the UV map, and on the right the color information which is applied to it. Each piece of geometry on the left correlates to a different part of the mesh.

Sometimes you might have UVs which overlap each other, in situations where you have a repeating texture.

This is fine, and actually saves space. Most environments do this because they're so big, and often textures like concerete or wood repeat themselves a lot. The problem you run into, is that when you bake a lightmap, all of that light baking information is saved as a texture.

When "Generate Lightmap UVs" is unchecked, the diffuse map and the baked lighting share the same UV space. If there are any overlaps in UVs, this will cause wierd repeating artifacts in the baked lighting. If it is checked, unity will automatically generate a SECOND UV map (where there are no overlaps), and will use that to project the baked lighting onto. If you ever run into a problem where theres a lot of strange artifacts in the lighting, check this setting first.

Now we're going to go into baking. Open up your "lighting" tab. If it is not readily available, you can pull it up under "Window > Lighting"

For lighting tests, change your settings in the lighting tab to the following layout:

Skybox Material None Sun Source None

Environment Lighting Source Color Ambient Source Hex# 30425A Ambient Mode Baked (default, greyed out)

Environment Reflections Skybox Resolution 128 Compression Uncompressed Intensity Multiplier 1 Bounces 1

Realtime Global Illumination OFF

Baked Global Illumination ON Lighting Mode Baked Indirect

Lightmapper Enlighten Indirect Illumination 2 Lightmap Resolution 40 Lightmap Padding 5 Lightmap Size 128 Compress Lightmaps OFF Ambient Occlusion ON Max Distance 1 Indirect Contribution 1.71 Direct Contribution 1.14

Final Gather ON Ray Count 1024 Denoising ON Directional Mode Directional Indirect Intensity 1.1 Albedo Boost 1 Lightmap Parameters Default - High Resolution

Fog OFF Halo Texture None Halo Strength 0.5 Flare Fade Speed 3 Flare Strength 1 Spot Cookie Soft

Auto Generate OFF

This lightbaking method will still create some artifacts, but will give a good facimile for what the final lighting arrangement looks like. From here you can move lights around, increase their intensity or range, add shadows, ect, and bake again. Once you are happy with the way the final lighting looks, you change ONE parameter on the lighting tab to create a final build, and then hit bake.

Lightmap Size 2048

The bake will take a long time, so I usually do them overnight.

  
Posted 11 months ago
Votes Newest

Answers