UnigineScript
The Language
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library

Setting Up Object LODs

Level of detail optimization will help you greatly enhance the framerate of your project. For that, you need to take your detailed model and create several versions of it, each with lower polygon count. Do not worry, after being exported, they still remain one object, but with a number surfaces. Then the engine will simply switch them one by one as the camera moves away from your object. You just have to control when and how they will be switched.
Here, we would demonstrate how to switch LODs smoothly using alpha fading.

Step 1. Export LODs

LODs are exported from a 3D editor into Unigine as separate surfaces of the same mesh. That is, each surface in our exported mesh represents a separate LOD of the model and can be enabled or disabled. In our case, they will be exported from 3ds Max. Maya is done exactly in the same way.

  1. Create a high-poly mesh of the object, which will be seen from close-by:

    Create a low-poly mesh to be seen from the distance:

  2. Group all the objects that will be exported as separate surfaces.
    In our case, it will be two LODs of the airplane body, two LODs of the gun and lights (because they need to be assigned a separate emissive material).
    Notice
    Keep the number of surfaces in the exported art assets as low as reasonably possible. A separate surface is exported if it either needs a different material or represents a LOD.

  3. On the Exporter panel at the side check the Groups as surfaces box.

  4. Set up other options and click Export.

Step 2. Add a Mesh and Assign Materials

  1. Add an exported mesh into the world as described here. By default, all surfaces (with a low-poly and a high-poly airplane) are visible at the same time:

  2. Create a material for airplane body as described here. (If you do not yet have a material library associated with the world, you'll need to create one).

  3. Press N hot key to go to the Nodes settings -> Surfaces tab. Hold SHIFT or CTRL to select surfaces with both low-poly and high-poly airplane body:

  4. Assign the same material for two LOD surfaces:

    Choose the material from the list:

    Create materials for the rest of surfaces (guns and lights, in our case) and assign them as well:

Step 3. Set Up LODs

In this tutorial we would want a high-poly LOD of the airplane to smoothly change into a low-poly one at about 5 units away from the camera. Normally, of course, it should have been much further: let's say, at 100 units.

  1. To start with, hold CTRL, select surfaces with low-poly LODs and disable them, so we can see what's happening.

    Only the first LODs are now displayed. That is the airplane we'll see from close-by:

  2. Choose the 1st LOD surface:
    • Set its Maximum Visible distance to 5.
    • Leave the Minimum Visible distance at -inf. It means that no matter how close the camera comes to the airplane, the surface will still be visible.

    As soon as we leave the 5-units range, the surface is no longer rendered:

  3. For the 1st surface LOD to smoothly fade out rather then disappear abruptly, set the Maximum Fade distance to 3 units.

    It will prolong the distance over which the surface is still visible.

  4. Enable the 2nd LOD surface.

  5. For the 2nd LOD to fade in smoothly (just like the 1st LOD fades out), set the Minimum Fade distance to the same 3 units.

    Now the 2nd LOD fades in, while the first one fades out, making the switching less noticeable.

    By the time the 2nd LOD is fully visible, the 1st LOD disappears completely:

  6. Now we can enable and set up guns LODs with the same values:
    • We have left Min and Max Parents of all surfaces at default of 1. This means, both airplane body and guns will be switched simultaneously, because their distances will be measured not to surfaces themselves, but to the bounding box of the whole airplane.

     

    Here is the same airplane, but one closer and one further away. As you can see, guns LODs and airplane body LODs are switched on at the same time:

Last update: 2017-07-03