LOD system

From Valve Developer Community
Jump to navigation Jump to search

When rendering any First-Person Perspective view, objects appear to get smaller as they get futher away from the viewer.

In source, the Viewer is usually the Player's Viewport, but LOD also applies to a point_camera entity's in-world display.

Because the Viewer's screen resolution limits the number of pixels available to render a scene, an object's finely detailed "close-up" geometry and textures are simply wasted at greater distances. Source therefore uses an LOD optimisation system which renders "cheaper" models and textures at greater distances, where the difference in detail (number of polygons and pixels) is invisible to the Viewer. This allows us to have very large, open areas in maps without sacrificing "close-up" detail or bringing the Rendering Engine to its knees.

  • Models use the $lod configuration in their QC file to specify which Mesh and Skin should be rendered beyond a specified Distance.
  • Brushes may use func_lod to specify a Distance at which the Brush is not rendered at all.
  • Textures use mipmaps which are automatically generated by the VTF compiler, stored in the texture's VTF file, and used automatically by the Rendering Engine.

Design Guidelines

The simple rule of thumb is:

  • When the distance between Viewer and Object is doubled, the apparent height and width of the Object are halved..

Mipmaps are created and applied on this principle. Each successive mipmap is half the height and width of the previous one, and its distance threshhold is double. In practice the texture_scale is also a factor in determining the actual distance (eg in game units) at which the mipmap will switch.

Todo: where does $detail come into it ?

A Model's $lod configuration specifies the Distance for each LOD threshhold, so you are not limited to "double-distances", but these do provide a good benchmark for creating LOD meshes and skins. Unfortunately the $lod Distance is specified in meters rather than game units.

Distance (game units) 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 etc
Distance (meters) 0.02 0.04 0.08 0.15 0.3 0.6 1.2 2.4 4.9 9.75 19.5 39.0 78.0 156.0

Once you've built your LOD Models you'll want to check that they look right in game. The easiest way to workaround LOD problems is to tweak the distance threshholds, which is made easier by using the HLMV model tab functions.