This article relates to the game "Half-Life: Alyx". Click here for more information.
This article relates to the workshop tools for "Half-Life: Alyx". Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Half-Life: Alyx Workshop Tools/Modeling/LODs

From Valve Developer Community
Jump to navigation Jump to search

This tutorial demonstrates building a model with multiple levels of detail (LODs). This tutorial uses primitive shapes as an example, but references to mesh files (.fbx, .dmx) can be directly substituted.

Create the highest detail level

In this example we will create a sphere with 3 levels of detail. To do this we will first add all 3 versions of the sphere to the render mesh list.

Click the Add node button and select the 'RenderPrimitiveSphere' node type.

LODs-131007636.png

When prompted for a name, give this sphere the name 'High'.

LODs-131007638.png

This sphere will represent the highest level of detail.

When prompted to select a bone, select 'none'.

Adjust the radius of the sphere to be 32 units by left clicking and dragging the manipulator ring that appears around the outside of the sphere.

LODs-131007639.gif

Use the Node Editor to make the sphere more smooth by setting the Segments U and Segments V properties to 32.

LODs-131007640.png

Create the lower detail levels

Duplicate the high detail level sphere by right clicking on the RenderMeshList in the Document Outliner and then selecting Duplicate from the context menu.

LODs-131007642.png

Use the name field at the top of the Node Editor to rename the new duplicate sphere to 'Medium', then set the Segments U and Segments V to 12.

LODs-131007644.png

Duplicate the high detail level sphere again, this time renaming the copy to 'Low' and set the Segments U and Segments V to 6.

LODs-131007647.png

You should now have all 3 spheres under the RenderMeshList in the Document Outliner.

LODs-131007646.png

Add an LOD group for the highest detail level

If you compile the model at this point all 3 spheres will be visible all the time, although it will be hard to tell since they are on top of each other.

We can change the model to only have a single version of the sphere visible at a any given time by adding LOD groups. LOD groups specify which mesh or meshes are visible at each level of detail.

Click the Add node button and select the 'LODGroup' node type.

LODs-131007652.png

With the new LOD Group node selected, click the Add Mesh button in the Node Editor.

LODs-131007654.png

This will add an empty mesh selection field in the ui.

Click the drop-down on the empty mesh selection field and select the 'High' mesh from from the list.

LODs-131007657.png

This will add the sphere named 'High' to the list of meshes included in LOD Group 0. LOD group 0 represents the highest level of detail and is visible by default.

Add lower level LOD groups

Right click on the LODGroupList in the Document Outliner and select Add LODGroup.

LODs-131007660.png

As before, click the Add Mesh button to add an empty mesh selection field, then click the drop-down and select the 'Medium' sphere.

LODs-131007661.png

Repeat the above two steps to add an additional LOD Group and add the 'Low' sphere to the group.

You should now have 3 LOD Groups in the LODGroupList in the Document Outliner.

If you select each one of the groups in the outlienr you should see that LOD 0 references the 'High' sphere, LOD1 references the 'Medium' sphere and LOD2 references the 'Low' sphere.

LODs-131007665.png LODs-131007668.png

Set the LOD switch distances

The model now has 3 LOD levels defined, but we still need to specified the distance at which each LOD should be active.

Click the Needs Compiling button to save and compile the model.

LODs-131007672.png

You can now preview each of the LOD levels explicitly by selecting one from the LOD drop-down in the top toolbar

LODs-131007674.png

Select LOD 2 from the toolbar drop-down, then also select LOD 2 in the Document Outliner, so that the Node Editor is displaying the properties for LOD Group 2.

LODs-131007675.png

Zoom out in the 3D viewport (Alt + Right Mouse) until the low detail sphere is small enough that it is of acceptable quality.

LODs-131007676.png

Click on the camera button in the Node Editor to set the Switch Threshold based on the current view in the 3D Viewport.

LODs-131007678.png

You should see the value of the Switch Threshold property change when you click the camera button.

Select LOD 1 from the toolbar drop-down and select LOD 1 in the Document Outliner so that the 3D viewport is previewing LOD 1 and the Node Editor is displaying the properties for LOD Group 1.

LODs-131007680.png

Adjust the zoom of the 3D viewport to the point where the quality of the visible 'Medium' sphere is just acceptable, then click on the camera button in the Node Editor..

LODs-131007685.png

Note that the Switch Threshold value is set. This value should be smaller than the value that was set for LOD 2 in the previous step.

Save and compile the model by clicking on the Needs Compiling button.

LODs-131007687.png

Preview the LODs

Re-enable automatic LOD selection in the 3D viewport by selecting Auto LOD from the toolbar's LOD selection drop-down.

LODs-131007691.png

This causes the editor's 3D viewport to pick the lod based on the size of the model in the viewport in the same way that the game will.

Enable wireframe preview from the 3D viewport toolbar by selecting Show Wireframe.

LODs-131007694.png

This will make it easier to see the changes in the LOD level to verify that the LODs are working as expected.

Zoom in and out in the 3D view. If you have enabled the Auto LOD mode, you should be able to see the visible meshes switching based on your zoom level..

LODs-131007696.gif

Add a mesh which does not have LODs

In some cases you may want a mesh be visible in all LOD levels. While it is possible to accomplish this by adding the mesh to each and every LOD Group, it can also by achieved by using the LOD Group All.

We will create a single box which will be visible in all LOD levels to demonstrate this.

Create a box primitive by right clicking on the RenderMeshList in the Document Outliner and selecting Add RenderPrimitiveBox.

LODs-131007698.png

Name the box 'BoxAll' and select 'none' for the parent bone .

LODs-131007701.png

In the 3D viewport change the model display mode to Always so that you can see the sphere while editing the box.

LODs-131007704.png

Use the manipulator handles to move and resize the box so that it is next to the sphere instead of inside it.

LODs-131007703.png

Add the all levels LOD group by right clicking on the LODGroupList in the Document Outliner and selecting Add LODGroupALL.

LODs-131007705.png

With the new All LOD Levels group selected in the Document Outliner, click the Add Mesh button in the Node Editor.

LODs-131007707.png

Select the 'BoxAll' mesh from the empty drop-down.

LODs-131007709.png

Click the Needs Compiling button to save and compile the model.

LODs-131007711.png

You should now be able to zoom in and out in the 3D viewport and see the sphere swapping between meshes while the box is always visible.

LODs-131007718.gif