We will see Unity’s LOD (Level of Detail) system. This Unity Lod system improves the performance of the game by allowing a high-polygon model to be drawn on the screen with fewer polygons as it moves away from the camera.
LOD Group component
In unity, the LOD system runs over the LOD group component. So what is this component? what does it do?:
This component basically consists of several Lod compartments. By default, these panes are LOD 0, LOD 1, LOD 2, and culled. As the distance of the object to which the component is assigned to the camera changes, the transition from one pane to another is made. At the same time, but 1 partition can be a factor. For example, in the image above, the camera corresponds to the LOD 1 compartment, and therefore only the LOD 1 compartment is active. 4, written under the camera icon, describes how much the object covers about % of the screen. If you drag the camera icon Right-left, the camera in the Scene panel zooms in or out of the object. It’s the fastest way to check the Lod compartments.
If you click on one of the Lod panes, the Renderers rank will appear at the bottom. You can only add objects that have the Renderer component to this list, and the objects that you add must be child objects of the object to which the LOD Group component is assigned (or the object to which the component is assigned). So what’s the use of adding an object to the Renderers list? Allows the object to be drawn on the screen only when the LOD compartment is active:
- Let’s just say that if you add object A to the Lod zero compartment, object A will not be drawn on the screen when the camera is inside an external Lod zero compartment (LOD 1, LOD 2, or Culled
- if you only add object A to the Lod 1 compartment, object A will not be drawn on the screen when the camera is inside an external Lod 1 compartment (LOD zero, LOD 2, or Culled
- if you add object A to both the Lod zero and LOD 1 compartments, object A is not drawn on the screen when the camera is inside a compartment other than these two compartments (LOD 2 or Culled)
- if you do not add object A to any LOD pane, object A is not affected by the LOD group component and is always drawn on the screen
You cannot add any objects to the Culled page. When the camera is inside the Culled compartment, none of the objects in the other LOD compartments are drawn on the screen.
By right-clicking a LOD pane and saying Delete, you can delete that pane. Or, by right-clicking and saying Insert before, you can add a new pane to the left of that pane. By dragging the edge where the two panes meet, you can change the area covered by these panes. In the example above, the LOD 0 pane is active if the object occupies about or above the screen, the LOD 1 pane is active if it occupies 0 or above, or the LOD 2 pane is active if it occupies less space than the Culled pane is active.
I created an empty GameObject on my scene and threw a Sphere and a Cube object into it to indicate whether the component works well. Then I gave the LOD group component to my empty GameObject and filled in its pods as follows:
Here’s the Lod preview when I drag the camera icon:
As you can see, the Sphere object is drawn on the screen when the Lod 0 pane is active, The Cube object is not drawn on the screen; the cube object is drawn on the screen when the LOD 1 pane is active, the Sphere object is not drawn on the screen. Both objects are not scratched on the screen when the Culled pane is active.
You can see that the transition between compartments is blunt. To make this transition even smoother, there is a Fade Mode variable. We’ll look at this variable later in the lesson.
As a result, the LOD group component can draw a high-polygon object on the screen with fewer polygons. There’s nothing magical about unity here.:
- You create the lower polygon version(s)of the high polygon model in your hand and add it to Unity
- you make both the high-polygon model and the low-polygon model(s)the child of the same object
- you give that object the LOD group component
- You put a high-polygon object in the Lod 0 pane of the LOD Group, a lower-polygon model in the LOD 1 Pane, a lower-polygon model in the LOD 2 pane (or you delete the LOD 2 pane)
- now, depending on the distance of the camera to the object, the LOD group component is drawn on the high-polygon model or lower polygon model screen for the occasion
Fortunately, this process doesn’t necessarily have to be that long. As we will see in “creating LOD models”, installation of the LOD group component is often done automatically.
If I complete this part by talking about the buttons at the bottom of the LOD group component:
- Recalculate Bounds: the rectangular area used to calculate the %of how much space the object takes up on the screen again allows you to calculate, but I almost did not see that this button was active. If you see it active, press it.
- Recalculate Lightmap Scale: used to update the Scale in Lightmap values in the Inspector of Renderer components added to the LOD Group. This calculation is done in direct proportion to the % area that that LOD pane occupies on the screen so that the Scale in Lightmap value of objects in the LOD 0 pane is larger than those in the LOD 1 pane. The Scale in the lightmap variable appears only if the object is static and the lightmap is on in the scene (Baked Global Illumination or Real Global Illumination). The higher this value, the more space it takes up in the Renderer lightmap texture. Since the camera will be significantly away from the object when the Lod 1 and LOD 2 compartments are active, objects in these compartments do not need to occupy a large space in the texture for nothing
Building LOD models
You need to give unity the high-polygon and low-polygon models that the LOD system will use; unfortunately, Unity does not automatically create a low-polygon variation of the high-polygon model. For this job, you have 2 alternatives: manually creating LOD models in a 3D modeling program (Blender, 3DS Max, Maya, etc.) or use a ready-made plugin.
Smooth transition between LOD models
For the Lod transition to be smooth, the shader used by LOD models needs to support this. Unfortunately, no shader of Unity supports soft LOD switching by default. Let me tell you in advance; a smooth transition between LOD models is a feature that you should not use if possible (especially on mobile). There are 3 main reasons for this:
- let’s say that if switching from the Lod 0 pane to the LOD 1 pane, the models in both LOD bays must be drawn on the screen at the same time during the transition, which increases the number of polygons on the screen during the transition
- as I said at the top, none of the unity’s default shaders support a smooth transition. It may be difficult to find a shader that has the features you want and supports smooth switching, and you may have to write the shader yourself
- for the transition to be smooth, logically LOD models need to fade. That means the shader has to be transparent or cutout. These shaders, judging by opaque shaders, make the GPU more difficult
For more information: Unity 3D
Ready for the plugin: GitHub