для этой страницы,
отображается код на другом
Setting Up LODs
Using Levels of Details (LODs) is the main way to optimize your project. The point is to switch the high detailed mesh to a mesh with lower number of details when the mesh is far from camera. For that, you need to take your detailed model and create several versions of it, each with lower polygon count.
In UNIGINE, the mesh with LODs is a single object with a number of surfaces representing LODs. LODs settings allow you to specify the distance when a surface should be switched to another.
The mesh LODs can be created and set up in one of the following ways:
- Automatically when importing the model into UNIGINE.
- Manually by means of a 3D editor and UnigineEditor.
Automatic LODs Setting#
Automatic LODs setting implies that LODs for the model are generated and set up on its importing into UNIGINE.
Step 1. Export a Model From a Third-Party Software#
As an example, we will use the tubes_constructor_chrome_1120.fbx model from the Oil Refinery demo (available in UNIGINE SDK Browser). This FBX consists of several meshes, each of which represents an element of the tubes constructor.
To create and set up LODs on importing the model into UNIGINE, first, you should perform the following in a 3D editor:
- Create several meshes for different LODs of your model: a detailed mesh for the closest LOD and a number of less detailed meshes for farther LODs.
For example, for each mesh representing an element of the tubes constructor (10 meshes), there are 3 meshes representing LODs:
- Export the meshes as an .fbx file.
Step 2. Import Model to UNIGINE#
To import the model into UNIGINE, click Import in the Asset Browser and choose the exported FBX file. In the Import FBX window, perform the following to automatically create LODs based on the name postfixes:
- Enable the Combine By Postfixes option.
- Specify the number of LODs stored in the FBX container (in our case, 3).
- For each LOD define a postfix that will be used to group objects in an FBX file into a corresponding LOD.
For the tubes constructor model, the following postfixes should be specified:The postfix must be the same as the one used when creating objects in a 3D editor.
The names of generated surfaces will be as follows: material_name + LOD_postfix.
- Specify minimum visibility distance for each LOD. Maximum visibility distance of each LOD is equal to the minimum visibility distance of the next LOD. Maximum visibility distance of the last LOD is equal to inf.
- For _lod_0, leave the -inf value. It means that no matter how close the camera comes to the mesh, the surfaces will still be visible.
- For _lod_1, set the distance at 5 units. It means that when the camera is 5 units away from mesh, the first LOD surfaces won't be visible and the second LOD surfaces will be shown.
- For _lod_2, set the distance at 30 units. After 30 units, the second LOD surfaces won't be visible and the third LOD surfaces will be shown.
In the result, the FBX container with 10 meshes will be imported. Each mesh will have 3 surfaces representing LODs.
Step 3. Add Model to the World#
Add an exported model into the world as described here. All LODs will be already created and set up according to the specified import values:
If required, adjust the LODs surfaces in the Node tab of the Parameters window:
- Set the Minimum and Maximum Fade distances for each LOD:
- For the first LOD surfaces, leave the Minimum Fade distance 0 and set the Maximum Fade distance to 10 units. t will prolong the distance over which the LOD surfaces are still visible and provide smooth fading.
- For the second LOD surfaces, set the Minimum Fade distance to 10 units. After 5 up to 15 units, the second LOD surfaces will smoothly fade in. The Maximum Fade distance set to 20 units. After 30 up to 50 units, the second LOD surfaces will smoothly fade out.
- For the third LOD surfaces, set he Minimum Fade distance to 20 units. The third LOD surfaces will start to smoothly fade in from 30 to 50 units.
- Set the Min and Max Parents. Within this tutorial, we use the default values of 1.
Try to move the camera forward/backward to check how LODs are switched:
Manual LODs Setting#
Manual LODs setting implies that LODs for the model are created in a 3D editor and LODs parameters are adjusted when the model is already imported and added to the scene.
Step 1. Export LODs#
To export the mesh with LODs, do the following:
- In a 3D editor, create a detailed model and a number of models with a low number of polygons. For example, you can just copy the existing detailed model and reduce the number of polygons.
You should create a separate LOD for each part of the model to which a unique material is assigned.
As an example, we will use the model of an oscilloscope from Superposition benchmark (available via UNIGINE SDK Browser). This model already contains 3 LODs.
10109 polygons 5004 polygons 2583 polygonsLOD 0LOD 1LOD 2
- Generate LODs according to a pipeline used by your 3D editor. For example, in 3ds Max, you should group meshes representing LODs and then create LODs via the Level of Detail utility.
- Export the model with LODs as an *.fbx file.
Step 2. Import Model to UNIGINE#
To import the model into UNIGINE:
Step 3. Add a Model to the World#
Add an exported model into the world as described here. By default, all surfaces (LODs) are visible at the same time:
The surfaces of the exported model that represent LODs can be found in the Node tab of the Parameters window:
Step 4. Set Up LODs#
This section explains how to set up LODs of the mesh to smoothly switch a high detailed LOD to a low detailed when the camera begins to move away from the mesh. LOD surfaces have 3 parameters:
Visibility and Fade Distances#
For each LOD surface, you should specify a visibility distance and a fade distance. For setting up the LOD surfaces, do the following:
- Open the World Hierarchy window, and choose the added node.
- In the Surfaces group of the Node tab (the Parameters window), choose the first LOD surface:
You can disable other LOD surfaces to see the result of the current LOD surface settings.
- Set its Maximum Visibility distance to 5. It means that when the camera is 5 units away from mesh, the first LOD surfaces won't be visible.
- Leave the Minimum Visibility distance at -inf. It means that no matter how close the camera comes to the mesh, the surfaces will still be visible.
- Set the Maximum Fade distance to 10 units. It will prolong the distance over which the LOD surfaces are still visible and provide smooth fading.
- Choose the second LOD surfaces and:
- Set the Minimum Visibility distance of the second LOD surfaces to start exactly where the Maximum Visible distance of the first LOD surfaces ends: at 5 units. It means that when the first LOD surfaces begin to fade out, the second LOD surfaces will be shown.
- Set the Maximum Visibility distance at 30 units. After 30 units, the second LOD surfaces begin to fade out and the third LOD surfaces will be shown.
- Set the Minimum Fade distance to 10 units. After 5 up to 15 units, the second LOD surfaces will smoothly fade in.
- Set the Maximum Fade distance to 20 units. After 30 up to 50 units, the second LOD surfaces will smoothly fade out.
- Choose the third LOD surfaces and:
- Set the Minimum Visibility distance to 30 units. It means that when the second LOD surfaces begin to disappear, the third LOD surfaces will be shown.
- Set the Maximum Visibility distance at 300 units. After 300 units the third LOD surfaces totally disappear.
- Set the Minimum Fade distance to 20 units. The third LOD surfaces will start to smoothly fade in from 30 to 50 units.
- Set the Maximum Fade distance to 50 units. After 300 units, the mesh will begin to smoothly fade out.
If you want to leave the last LOD surface always visible, set the Maximum Visibility distance to inf.
You should specify the same settings for each surface of the same LOD (if any). Different surfaces from one level of details should have the same settings to appear and disappear simultaneously.
Minimum and Maximum Parents#
Another important parameters of the LODs are Min and Max Parents.
These parameters allow you to specify to which surface or node up in the hierarchy the minimum and maximum visibility distances will be measured. Use the default values of 1. In this case, all surfaces of the mesh will be switched simultaneously, because their distances will be measured not to surfaces themselves, but to the bounding box of the whole mesh.
Read here about these parameters.