-
Notifications
You must be signed in to change notification settings - Fork 275
LOD Generator Helper component
The LOD Generator Helper component is there to make it possible for you to easily generate LODs for game objects in Unity without writing any code.
It works by collecting all the meshes in mesh renderers and mesh filters on the same game object or any child object where the component is attached, then potentially combines them into a single mesh and reduces the triangle count in different levels and automatically creating a LOD Group component already setup based on your settings on the LOD Generator Helper component. This will work with both regular and skinned meshes, meaning that even animated meshes is easily handled.
The examples shown below make use of a free asset on the Unity Asset store: https://assetstore.unity.com/packages/3d/characters/humanoids/sci-fi/free-biomechanical-mutant-166330
Please always keep your project backed up or in a version control system in case you experience problems using this library. This component will make changes to your game objects as well as creating and deleting assets automatically based on your actions such as generating LODs or destroying them. It will make it's best to avoid making these mistakes, but we cannot guarantee that it will not happen. Therefor please always use this with cation. Having your projects in a version control system will truly save you from a lot of pain.
First select the game object that you wish to generate LODs for (please note that this can both be an object in the scene as well as a prefab) and then add the LOD Generator Helper
component in the inspector:
You should now see something like this in your inspector:
Setting | Description |
---|---|
Fade Mode | This will be applied to the resulting LOD Group component. Read more here. |
Auto Collect Renderers | If renderers should be automatically collected, otherwise you will have to manually specify them for each LOD level. |
Simplification Options | The options used for the actual mesh simplification. |
Override Save Assets Path | Enabling this override will let you control where the automatically generated assets are saved within your project. The default path will be Assets/UMS_LODs/{gameObjectName}/{rendererName} . |
Levels | These are the LOD levels that you wish to create. Typically the first level is original quality (100%) and each level below reduces the quality for a more optimal rendering on distances. |
Setting | Description |
---|---|
Preserve Border Edges | If border edges should be preserved, essentially the edges that do not share two triangles. Enabling this prevents simplification, and might result in poor mesh simplification, but it could also prevent holes that might otherwise appear or weird border artifacts. Prefer to enable smart linking instead. |
Preserve UV Seam Edges | If UV seam edges should be preserved, these are essentially smart linked edges that contain differences in their UV coordinates. Enabling this prevents simplification, and might result in poor mesh simplification, but it could also prevent simplification issues around UV-seams making an improved visual result. Only works with smart linking enabled. |
Preserve UV Foldover Edges | If UV foldover edges should be preserved, these are essentially smart linked edges that contain identical UV coordinates. Enabling this prevents simplification, and might result in poor mesh simplification, but it could also prevent simplification issues around UV-seams making an improved visual result. Only works with smart linking enabled. |
Preserve Surface Curvature | If surface curvature should be preserved. Will make the simplification slightly more expensive but will try to preserve the surface curvature much better. |
Enable Smart Link | If smart linking should enabled. Smart linking is when two triangle edges aren't linked through the mesh indices, but are located at the same 3D location. Smart linking can find these edges and link them together to prevent holes that would otherwise appear. Enabling this makes the simplification more expensive, but is still recommended for most meshes. |
Vertex Link Distance | The vertex link distance when smart linking is enabled. This value should be kept very small, but could be increased for large scale meshes that require it. This distance is used when searching for vertices to link together, where this is the maximum distance to consider them at the same 3D location. |
Max Iteration Count | The maximum iteration count for the mesh simplification. Reducing this could (not guaranteed) make the simplification faster, but it could also reduce the resulting quality. See this value more as a prevention of never ending simplification where it simply is unable to find more edges to collapse. |
Agressiveness | The agressiveness of the mesh simplification. You could experiment with this value if you find your simplification being very ineffective. |
Manual UV Component Count | If you prefer to manually set the UV component count, rather than it being detected automatically. |
UV Component Count | The UV component count to use, if manual count is enabled. |
Setting | Description |
---|---|
Screen Relative Transition Height | The screen relative height to use for the transition (0-1). |
Quality | The quality relative to the original mesh in percentage (0-1). Imagine the number of triangles multiplied with this percentage. |
Combine Meshes | If all meshes should be combined as much as possible to reduce the number of draw calls. |
Combine Sub Meshes | If all sub-meshes should be combined into one, further reducing the number of draw calls. Important: This is actually not yet supported. |
Skin Quality | The quality of the skinning, with the possibility of reducing the number of bones used for animating the mesh. Optimizing rendering slightly. |
Shadow Casting Mode | The shadow casting mode of the created LOD renderer. Disabling shadows on the lowest LOD levels are recommended to increase performance. |
Receive Shadows | If the renderer can receive shadows. Disabling shadow receiving is recommended on the lowest LOD levels to increase performance. |
Motion Vector Generation Mode | The motion vector generation mode of the created renderer. You can read more about this here. |
Skinned Motion Vectors | If skinned motion vectors should be enabled for the created renderer. |
Light Probe Usage | Specifies the light probe usage for the created renderer. You can read more about this here. |
Reflection Probe Usage | Specifies the reflection probe usage for the created renderer. You can read more about this here. |
Once you have configured the component, you will want to generate the LODs to preview the result.
You should now see something like this, where your LOD Generator Helper has fewer options and a newly created LOD Group component.
The Copy Visibility Changes
button is there to copy changes made to the LOD Group component back to the LOD Generator Helper component, if you have moved the sliders around and want them to be remembered if you wish to reconfigure.
Have in mind that generating LODs will create a LOD Group component on the same game object that you have the LOD Generator Helper component, and will create additional game objects with renderers for the LOD levels. In addition to this, the simplified meshes will be saved as assets in your Unity project. When you click on Destroy LODs
then we will attempt to clean up any automatically created game objects and assets in your project related to the same game object. So therefore it is always important to make backups or keep your files versioned in a VCS, so that you can easily revert if things break.
After having generated LODs you can choose to Destroy LODs
if you want to go back to the settings to reconfigure and try again. This is in most case necessary in order to experiment with the parameters for achieving the best result possible.
You can easily select the LOD level game objects in the Hierarchy
window and see the result in the Scene
window. Look for the _UMS_LODs_
game object.
The first level with 100% quality:
The last level with 20% quality: