Time for action – Generating Beast lightmaps

To illustrate how lightmapping can improve our application we're going to take our City level scene and add Beast lightmapping to it.

  1. The first step in preparing our scene for lightmapping is to ensure that any object that we want to have lightmaps generated for is declared static. Unity uses this declaration to make assumptions that the object won't move, scale, or change in any way during the scene. Remember, we only want to bake lightmaps on static geometry, as we're generating lighting based on the location of lights in the scene at a given time. If we tried to use this approach on objects that moved, for example, you'd find that even though an object changes its orientation with respect to a light, the lighting and shadow calculations would look as if the object were in a different place:
    Time for action – Generating Beast lightmaps

    Here we have specified that one of our birch tree prefabs is Static. Similarly we can add the same settings to the terrain.

  2. Add a light to the scene using Game Object | Create Other | Point Light. Position this light in our scene. This is the light whose lighting effects we want to bake into our scene. Now that our objects are defined as being static, let's add a light to the scene that we want to bake to our objects:
    Time for action – Generating Beast lightmaps
  3. Observe the scene to see what everything looks like when the lighting is rendering normally. This will give us an idea of what the lightmapped scene should look like if we perform the operation properly:
    Time for action – Generating Beast lightmaps

    Now that we've provided some lighting data for the lightmapper to work with, we can start the baking process.

  4. In the Window menu select the Lightmapping option to bring up the Beast lightmapping interface:
    Time for action – Generating Beast lightmaps

    This will open the Unity Lightmapping interface which allows us to configure the Beast lightmapping session:

    Time for action – Generating Beast lightmaps
  5. With the interface is open, select the Point light we added to the scene and click on the Bake tab:
    Time for action – Generating Beast lightmaps
  6. We can take our simple light and have it baked into the lightmaps of the scene. Press the Bake button and observe the debug output window:
    Time for action – Generating Beast lightmaps

    The output window is telling us that it is unable to bake the lights because there is no UV data for the geometry in our scene. Remember that our lightmaps are texture maps that are being added as a texture map and, as such, if the geometry does not have UVs generated properly it cannot generate the lightmaps.

  7. Select the geometry that Unity is reporting does not have UV data and select its FBXImporter. Click on the Generate Lightmap UVs button to ensure that Unity generates the UV information for this piece of geometry:
    Time for action – Generating Beast lightmaps

    Now when you bake the scene, Unity will be able to generate a properly lightmapped scene.

  8. Select the Point light in the Hierarchy view and delete it from the scene. When you run the game you will note that the game looks exactly the same as it did before but it is now running without the performance overhead of the lights in the scene.

What just happened?

What Unity is doing behind the scenes is taking all of the assets and scripts from the Unity IDE and putting together a player that will be able to playback the content and all of its scenarios based on input from the user. This is a very important concept to understand as the content within the Unity IDE is largely platform agnostic and can be readily redeployed after a simple recompile within the Unity environment. This player is the the actual application that is deployed to the iOS device.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.222.149