Game Development Reference
In-Depth Information
Step 5. Save the code. Attach it to the Building object in the
Hierarchy. Select Building in the Hierarchy and locate the LOD
Manager script component in the Inspector.
Step 6. Click on the small circle to select a mesh for the value of Lod 1.
When the pop-up selector opens you will find two building meshes.
Select the one with more detail.
Step 7. Set the value for Lod 2 the same way, except this time pick
the less detailed building mesh.
Step 8. Set Lod Dist 1 to 80 and Lod Dist 2 to 120.
Step 9. Play. Turn around to face the building. Remain facing the
building as you move backward by holding the down arrow key.
When you get a distance of 80 away from the building the mesh will
switch to the less detailed mesh. Move forward again and as you pass
the 80 threshold it will become more detailed. Watch the Stats
screen polycount change as you move back and forth. Now move
even farther back. When you pass a distance of 120 the building
will disappear because in the script it is set to “null” or not value
after Lod Dist 2.
Step 10. Duplicate the Building object and move the copies
around on the terrain to create a bigger city. Walk around it
observing how the LOD snaps buildings in and out of different
levels of detail.
What you have just experienced is a very simple implementation of LOD. It
works well to reduce the polycount and yet keep many objects in the scene,
giving a great depth to the environment. You may have experienced this
snapping effect in games you have played.
2.7.2 Camera Viewing Volume
Previously in this chapter we examined the camera viewing volume and
how it reduces the objects being drawn. To emphasize its effectiveness
in association with LOD, we will run through a quick example.
Unity Hands On
Camera Viewing Volume and LOD
Step 1. Using the project from the previous hands-on session, create
a prefab from the Building object and remove any others from the
surface of the terrain.
Step 2. Create a new JavaScript file called instantCity and add the
code in Listing 2.21 .
Search Nedrilad ::

Custom Search