Tutorials

Compiling LOD models



LOD stands for Level Of Detail, and LOD models are a very important step in optimizing your props.

This tutorial is going to go through the process of compiling a prop with the $lod command. There are a few small bits of information that aren't explained very thoroughly on the VDC so I'll go into some more detail here. That said, you should read the pages on LOD models on the VDC to get a better feel for the system. I will assume that you are familiar with the concepts and modelling of LOD models.

The export

Export your reference and physics as well as your LOD models into your export folder (mine will be mdlsrc)

news post image

IMPORTANT: Your reference SMD and lod SMD MUST share the same material. Otherwise the model will disappear when it hits the threshold. To check if the materials are the same, you can open up the SMD file in a text editor. You will see something like this:

version 1
nodes
0 "root" -1
end
skeleton
time 0
0 0 0 0 0 0 0
end
triangles
Material
0 0.299381 0.355865 -87.137268 0.795801 0.461592 -0.391919 0.770237 0.046839 0
0 -1.081276 -0.220317 -89.397217 0.068239 0.077700 -0.994629 0.795186 0.000000 0
0 -0.412915 1.128637 -87.423782 0.625538 0.660573 -0.415082 0.791387 0.048980 0
Material
0 0.605703 -0.161556 -86.976273 0.913785 0.134159 -0.383374 0.758137 0.044712 0
0 -1.081276 -0.220317 -89.397217 0.068239 0.077700 -0.994629 0.795186 0.000000 0
0 0.299381 0.355865 -87.137268 0.795801 0.461592 -0.391919 0.770237 0.046839 0
Material
0 0.286532 -1.670301 -87.220871 0.733482 -0.520768 -0.436781 0.284422 0.041808 0
0 -1.081276 -0.220317 -89.397217 0.068239 0.077700 -0.994629 0.274941 0.000000 0
0 0.605703 -0.161556 -86.976273 0.913785 0.134159 -0.383374 0.305466 0.033078 0
Material
0 -0.675708 -1.852435 -87.912666 0.180151 -0.807459 -0.561693 0.269793 0.033505 0
0 -1.081276 -0.220317 -89.397217 0.068239 0.077700 -0.994629 0.274941 0.000000 0
0 0.286532 -1.670301 -87.220871 0.733482 -0.520768 -0.436781 0.284422 0.041808 0



"Material" will be the name of the material you have assigned your model. If that differs between your LOD and REF models, change it. This can be done from the text editor (with ctrl+h for notepad) or set from within your modelling program.

The .QC

The .qc file can be as generic as you like, no special stuff here.

$modelname aura/rocks/stalactite_01/stalactite_01
$cdmaterials models/aura/rocks/stalactite_01
$staticprop
$body stal1 ref
$sequence idle ref
$collisionmodel phy



Now we add the $lod command to our .qc

$modelname aura/rocks/stalactite_01/stalactite_01
$cdmaterials models/aura/rocks/stalactite_01
$staticprop
$body stal1 ref
$sequence idle ref
$collisionmodel phy

$lod 40
{
	replacemodel ref lod1
}



The $lod command requires an integer to describe how far away from the player the model must be before it changes out. To get a better feel for this 'threshold' number, there is a thingy we'll look at in HLMV soon. After the $lod [int] command, we put in some curly brackets to signify an options block. "replacemodel" tells studiomdl what to replace with what.

IMPORTANT: the models you are swapping out with the replacemodel command are the .SMD files you exported from your modelling program. you do NOT need to compile them separately.

Compile away, cross your fingers studiomdl is in a good mood.

The T&E

Your initial $lod integer will probably be way off, but luckily HLMV has a widget to show you what your current LOD integer is. Open up your model in HLMV, go to the "model" tab and select the "Auto LOD" box.

"LOD Metric" tells us the current LOD number, use that to decide when your model should change over.

The Extras

If you want to add more than one LOD model to your file you do much the same thing, but remember when you add your next $lod command that you have to replace the reference model with the next LOD model. ie:

$lod 25
{
	replacemodel ref lod1
}

$lod 40
{
	replacemodel ref lod2
}



Notice we are still swapping the reference SMD on both LOD levels. You will still need to export all your LOD models separately.

There are more options for LOD models, for instance $shadowlod and $removemodel but they are beyond this tutorial.

The tricks

Although the VDC states that you can't have multiple materials across LOD models, there is a way to dirtymod it in.

Multiple materials on each model is handled in the usual way, by assigning each material to a vertice group and having a separate .VMT for each material. Well, if you make a random floating triangle in each model assigned to a second or third material, then you can swap to that material in a later LOD.

For instance, a tree model with 2 LOD levels and a ref. The ref and first LOD model can share the same materials for leaves and trunk. The second LOD model is a billboard, and uses a billboard texture. The first two models contain a floating triangle inside the trunk that has the billboard material assigned to it. This allows the material to be carried over. It might be a bit of a waste, but the billboard model is only usually 256*256 if not smaller.

I'm not sure if the billboard model keeps the other materials in the buffer, since it has the materials included in the modelling program, but no vertices assigned to those materials in the exported SMD. It doesn't render them in any case. If someone wants to run some sort of benchmark thing I'd be much obliged.

Further reading



The Video Tutorial

I also made a video tutorial using Blender, the same rules apply to any modelling program.



Hopefully that gets you on the path to making nicely optimized models, let's see those frame rates fly!

- Black_Stormy

View comments ( 0 )

Back to top