This article's documentation is for anything that uses the Source engine. Click here for more information.

$lod: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (→‎Options: hope its a little clearer)
No edit summary
 
(72 intermediate revisions by 23 users not shown)
Line 1: Line 1:
Each [[$lod]] [[QC command]] begins a block of commands describing how to perform [[LOD system|LOD ('''L'''evel '''o'''f '''D'''etail)]] on the model. Each block specifies a single ''threshold'' parameter which represents a distance between the Model and the Viewer. When the Model is rendered beyond this distance that block of LOD commands are executed. The commands allow the [[LOD system]] to remove or replace various "expensive" parts of the Model so it can be rendered more efficiently.
{{LanguageBar|title = $lod}}
{{this is a|QC command|name=$lod}}


* See [[LOD Models]] for in-depth information on generating LOD models
{{toc-right}}{{src topicon}}  It is also available in {{hlps2|4}}. It is a [[QC command]] describing how to reduce the [[LOD system|level of detail]] when rendering the model at a given size. It handles the removal or replacement of [[expensive]] parts of the model so it can be rendered more efficiently. There can be up to 8 levels.
* See [[LOD system]] for a better overview.
* See also [[$shadowlod]] for cheaper [[Dynamic Shadows]].


== Syntax ==
{{tip|[[Studiomdl]] will transfer weightmapping and flexes from the reference mesh.}}


$lod <[[int]]|threshhold> { <options> }
== Limitations ==
where
{{warning|New [[material]]s cannot be introduced in an LOD SMD. All mesh using newly introduced materials will not be compiled into the model and simply disappear.
* <code><[[int]]|threshhold></code> : The LOD threshhold number is based on an inverse of the screen space. The smaller the model is on-screen, the larger the LOD threshhold will become.
{{fix|Use <code>replacematerial</code> instead.}} }}
{{tip|The practical way to achieve a good set of LOD threshholds for your [[LOD Models]] is to use the [[HLMV]] Model tab to find numbers where the LOD transitions with a low amount of visual popping.}}
{{warning|{{csgo|4}} does not support level of detail. $lod will be ignored, but the model will still work. Try to avoid using this command in {{csgo}}.
<!-- //note : Jeff is currently digging out some info on how this "threshold" figure relates to Model-Viewer distance ... apparently it's nothing to do with meters, so I've changed the "metric" to "threshhold" for now ... please leave alone until we have more definitive info ... //
{{modernConfirm|Was this broken in an update, or did LODs not work in the 2012 build (available as public beta)?}} }}
{{warning|Edges that end up split or merged in a LOD, while it has not been like that in the original mesh, will cause the edge to disappear in the LOD.<br>In other words, Adding sharp edges to fix a smoothing issue on a LOD will cause that edge to not show up. {{confirm|This does not always appear to be the case.}} }}
{{warning|Each LOD will have its own model, even if it does not use <code>$replacemodel</code>. Those models add to the total polycount. If your model has very high polycount and you add a LOD just to collapse bones, it will double the overall polycount.<br>
Therefore it might be best to either not have any LOD at all, or using a '''highly''' decimated version of the model.}}


{{tip| When distance from the model doubles, the apparent vertical and horizontal 'resolution' (screen pixels) of the model is halved. Therefore the standard 'double' distances provide a useful benchmark both for modelling and compiling [[LOD Models]]:}}
== Syntax ==
:{|
<source lang=php>
|-
$lod <threshold>
|'''Game units:''' ||32||64||128||256||512||1024||2048||4096||8192
{
|-
<options>
|'''Meters:''' ||0.6 ||1.2 ||2.4 ||4.9 ||9.75 ||19.5 ||39.0 ||78.0 ||156.0
}
|}
-->
* <code><options></code> : See below.
== Options ==


{{note|Each LOD block does not inherit commands from the previous block; they always modify the ''original'' (effectively "$lod 0") mesh, skin or bone, never the previous ''lod_model'' or anything like that.}}
$shadowlod // Used to generate cheap render-to-texture shadows (not shadow maps)
{
<options>
}
</source>


*;<code>replacemodel <original_mesh>.smd <lod_mesh>.smd [reverse]</code>
; <code>threshold</code>
: Causes the ''lod_mesh'' to be rendered instead of the ''original_mesh''.
: Defines when the LOD takes effect. Its value is (100 / screen pixels per unit) [http://www.interlopers.net/forum/viewtopic.php?f=25&t=29954], which means that distance at which the transition happens depends on the size of the user's monitor and their [[FOV]], not simply the model's distance from the camera. Someone with a truly massive screen may never see an LOD!
: The '''original_mesh''' can be any named SMD used by $body, $bodygroup or $model.  
: The threshold formula makes it difficult to determine what values to use, however. The best way of working things out is to load your model into [[HLMV]], switch to the Model tab, enable Auto LOD, and use {{key|RMB}} to zoom in and out.
: The '''lod_mesh''' should be a lower polygon-count version of the ''reference_model''. If no ''lod_model'' is specified the ''reference_model'' is not rendered at all.
{{note|Floating point values can be used if wrapped in quotes. i.e. $lod "10.5"}}
: The '''reverse''' command is used only to correct reversed normals on the ''lod_model'', caused by SMD export problems. <!-- see also [[Talk:$body]]-->


*;<code>removemodel <original_mesh>.smd</code>
=== Options ===
: The specified Mesh or Sub-mesh ''will not be rendered'' at this LOD.
{{note|LOD blocks do not inherit from previous blocks. They always modify the reference mesh.}}
<!-- :Stops the specified $body from being rendered at all. // no that's not the same thing -->


*;<code>replacematerial <original_material>.vmt <lod_material>.vmt</code>
; <code>replacemodel <Reference smd> <LOD smd> [reverse]</code>
: Replaces ''all'' instances of the ''original_material'' with the ''lod_material''.
: Replaces the given reference SMD (can by anything from <code>[[$body]]</code>, <code>[[$bodygroup]]</code> or <code>[[$model]]</code>) with an LOD version.<br>
: Useful for removing expensive shaders like [[Normal Maps]] or the Eye Shader from LOD Skins.
: <code>Reverse</code> is used to correct reversed normals on the LOD, which can be caused by SMD export problems. <!-- See also [[Talk:$body]]-->{{bug|LOD meshes for [[$bodygroup|Bodygroups]] defined outside the <code>.qc</code> file (i.e. via <code>$include file.qci</code>) or inside of [[$pushd]]/[[$popd]] blocks will not be correctly assigned.<br> Contents of <code>.qci</code> files must be merged into the main <code>.qc</code> file to work. Any usage of <code>$pushd</code> or <code>$popd</code> must be replaced with full relative paths, using <code>..\</code> and forward-slashes to work.|only=}}
: {{confirm|The Skin's $basetexture, etc will be [[mipmap]]ped automatically - you don't need to do it manually.}}
; <code>removemodel <Reference smd></code>
: {{confirm|If lod1_mesh.smd was [[UV map]]ped to an lod1_skin.bmp, the lod1_skin.vmt will automatically be rendered on the lod1_mesh and doesn't need to be specified with "replacematerial" ?}}
: The specified SMD will not be rendered at all at this level of detail.<br>{{bug|Causes compiles to fail with an EXCEPTION_ACCESS_VIOLATION error in [[studiomdl]] builds later than 2006.<br>Instead, use "replacemodel" to swap the specified model for one that is a single tiny triangle hidden inside the mesh. Invisible textures can be used hide it better, should the little triangle ever be seen.{{workaround|See [[$no_draw]].}} |only=}}
; <code>replacematerial <Reference material> <LOD material></code>
: Replaces all instances of the reference [[material]] with another. Useful for removing expensive effects like the [[Eye]] shader. Paths are relative to <code>[[$cdmaterials]]</code>.{{bug|If you use <code>replacemodel</code> to replace the mesh, and then set <code>replacematerial</code>'s 2nd argument to one of the materials found in the LOD mesh, it will cause the entire mesh to be removed.|only=}}
; <code>removemesh <Reference material></code>
: Removes all triangles attached to the named material. Unlike in <code>replacematerial</code>, paths are relative to the root materials folder. {{bug|If a material's VMT is not present in the game's folder, studiomdl sees a material named "__error" instead; the compiler does not detect VMTs from mounted GCFs/games.|only=}}
; <code>nofacial</code>
: Disables [[facial animation]].
; <code>bonetreecollapse <Reference bone></code>
: Causes children of the specified bone to be removed. Their attached vertices return to the reference position. This is commonly used on fingers. Remember that it only applies to clients!{{note|This don't affect the bones with their parents that have an [[$attachment|attachment]].<br>This means that if you collapse bonetree from ValveBiped.Bip01_R_UpperArm but ValveBiped.Bip01_R_Hand has an attachment, such bones as ValveBiped.Bip01_R_Hand and ValveBiped.Bip01_R_Forearm will not be deleted.}}
;<code>replacebone <Reference bone> <LOD bone></code>
:The precursor of <code>bonetreecollapse</code>. Replacing bones is much more complex, but allows all kinds of unusual bone optimisations that a simple collapse wouldn't achieve.<!-- go on ... give us another clue!-->
; <code>use_shadowlod_materials</code>
: {{todo|Describe (Perhaps $shadowlod models without this use a simple opaque textureless material?); sets {{code|STUDIOHDR_FLAGS_USE_SHADOWLOD_MATERIALS}} flag, which is explained like so in {{file|public/studio.h}}: {{quote|This flag is set when we should use the actual materials on the shadow LOD instead of overriding them with the default one (necessary for translucent shadows)}} }}


*;<code>removemesh <original_material>.vmt</code>
== Example ==
: Removes all the triangles attached to the named material at this LOD.
<!-- :Removes all meshes using the given material. // no that's not the same thing -->
 
*;<code>nofacial</code>
:Disables [[facial animation]] at this LOD.


*;<code>bonetreecollapse <original_bonename></code>
<source lang=php>
: Causes all child bones of the specified bone to use the specified bone instead of whatever they currently are attached to.
$lod 12
:Deletes all children of the given bone, disabling movement on the client. The [[envelope]]s return to their reference position. Commonly used on fingers.
{
replacemodel "Police_reference" "lod1_Police_reference"
replacemodel "Manhack_reference" "lod1_Manhack_reference"
}


*;<code>replacebone <original_bonename> <lod_bonename></code>
$lod 18
:The precursor of <code>bonetreecollapse</code>. Accepting a replacement bone makes it slightly less user-friendly, but allows [[all kinds of unusual bone optimisations]] that a simple collapse wouldn't achieve.<!-- go on ... give us another clue!-->
{
 
replacemodel "Police_reference" "lod2_Police_reference"
== Example ==
replacemodel "Manhack_reference" "lod2_Manhack_reference"
bonetreecollapse "ValveBiped.Bip01_R_Hand"
bonetreecollapse "ValveBiped.Bip01_L_Hand"
}


$lod 12
$lod 42
{
{
replacemodel Police_reference "lod1_Police_reference.smd"
replacemodel "Police_reference" "lod3_Police_reference"
replacemodel Manhack_reference "lod1_Manhack_reference.smd"
replacemodel "Manhack_reference" "lod3_Manhack_reference"
}
bonetreecollapse "ValveBiped.Bip01_R_Hand"
bonetreecollapse "ValveBiped.Bip01_L_Hand"
$lod 18
}
{
</source>
replacemodel Police_reference "lod2_Police_reference.smd"
replacemodel Manhack_reference "lod2_Manhack_reference.smd"
bonetreecollapse ValveBiped.Bip01_R_Hand
bonetreecollapse ValveBiped.Bip01_L_Hand
}
$lod 42
{
replacemodel Police_reference "lod3_Police_reference.smd"
replacemodel Manhack_reference "lod3_Manhack_reference.smd"
bonetreecollapse ValveBiped.Bip01_R_Hand
bonetreecollapse ValveBiped.Bip01_L_Hand
}


[[Category:QC Commands|lod]]
== See also ==
* [[LOD Models]]
* [[LOD system|LOD system]]

Latest revision as of 21:26, 18 July 2025

English (en)Translate (Translate)

$lod is a QC command available in all Source Source games.

It is also available in Half-Life (PS2) Half-Life (PS2). It is a QC command describing how to reduce the level of detail when rendering the model at a given size. It handles the removal or replacement of expensive parts of the model so it can be rendered more efficiently. There can be up to 8 levels.

Tip.pngTip:Studiomdl will transfer weightmapping and flexes from the reference mesh.

Limitations

Warning.pngWarning:New materials cannot be introduced in an LOD SMD. All mesh using newly introduced materials will not be compiled into the model and simply disappear.
Note.pngFix:Use replacematerial instead.
Warning.pngWarning:Counter-Strike: Global Offensive Counter-Strike: Global Offensive does not support level of detail. $lod will be ignored, but the model will still work. Try to avoid using this command in Counter-Strike: Global Offensive.
Confirm:Was this broken in an update, or did LODs not work in the 2012 build (available as public beta)?
Warning.pngWarning:Edges that end up split or merged in a LOD, while it has not been like that in the original mesh, will cause the edge to disappear in the LOD.
In other words, Adding sharp edges to fix a smoothing issue on a LOD will cause that edge to not show up.
Confirm:This does not always appear to be the case.
Warning.pngWarning:Each LOD will have its own model, even if it does not use $replacemodel. Those models add to the total polycount. If your model has very high polycount and you add a LOD just to collapse bones, it will double the overall polycount.
Therefore it might be best to either not have any LOD at all, or using a highly decimated version of the model.

Syntax

$lod <threshold>
{
	<options>
}

$shadowlod // Used to generate cheap render-to-texture shadows (not shadow maps)
{
	<options>
}
threshold
Defines when the LOD takes effect. Its value is (100 / screen pixels per unit) [1], which means that distance at which the transition happens depends on the size of the user's monitor and their FOV, not simply the model's distance from the camera. Someone with a truly massive screen may never see an LOD!
The threshold formula makes it difficult to determine what values to use, however. The best way of working things out is to load your model into HLMV, switch to the Model tab, enable Auto LOD, and use RMB to zoom in and out.
Note.pngNote:Floating point values can be used if wrapped in quotes. i.e. $lod "10.5"

Options

Note.pngNote:LOD blocks do not inherit from previous blocks. They always modify the reference mesh.
replacemodel <Reference smd> <LOD smd> [reverse]
Replaces the given reference SMD (can by anything from $body, $bodygroup or $model) with an LOD version.
Reverse is used to correct reversed normals on the LOD, which can be caused by SMD export problems.
Icon-Bug.pngBug:LOD meshes for Bodygroups defined outside the .qc file (i.e. via $include file.qci) or inside of $pushd/$popd blocks will not be correctly assigned.
Contents of .qci files must be merged into the main .qc file to work. Any usage of $pushd or $popd must be replaced with full relative paths, using ..\ and forward-slashes to work.  [todo tested in ?]
removemodel <Reference smd>
The specified SMD will not be rendered at all at this level of detail.
Icon-Bug.pngBug:Causes compiles to fail with an EXCEPTION_ACCESS_VIOLATION error in studiomdl builds later than 2006.
Instead, use "replacemodel" to swap the specified model for one that is a single tiny triangle hidden inside the mesh. Invisible textures can be used hide it better, should the little triangle ever be seen.
PlacementTip.pngWorkaround:See $no_draw.
  [todo tested in ?]
replacematerial <Reference material> <LOD material>
Replaces all instances of the reference material with another. Useful for removing expensive effects like the Eye shader. Paths are relative to $cdmaterials.
Icon-Bug.pngBug:If you use replacemodel to replace the mesh, and then set replacematerial's 2nd argument to one of the materials found in the LOD mesh, it will cause the entire mesh to be removed.  [todo tested in ?]
removemesh <Reference material>
Removes all triangles attached to the named material. Unlike in replacematerial, paths are relative to the root materials folder.
Icon-Bug.pngBug:If a material's VMT is not present in the game's folder, studiomdl sees a material named "__error" instead; the compiler does not detect VMTs from mounted GCFs/games.  [todo tested in ?]
nofacial
Disables facial animation.
bonetreecollapse <Reference bone>
Causes children of the specified bone to be removed. Their attached vertices return to the reference position. This is commonly used on fingers. Remember that it only applies to clients!
Note.pngNote:This don't affect the bones with their parents that have an attachment.
This means that if you collapse bonetree from ValveBiped.Bip01_R_UpperArm but ValveBiped.Bip01_R_Hand has an attachment, such bones as ValveBiped.Bip01_R_Hand and ValveBiped.Bip01_R_Forearm will not be deleted.
replacebone <Reference bone> <LOD bone>
The precursor of bonetreecollapse. Replacing bones is much more complex, but allows all kinds of unusual bone optimisations that a simple collapse wouldn't achieve.
use_shadowlod_materials
Todo: Describe (Perhaps $shadowlod models without this use a simple opaque textureless material?); sets STUDIOHDR_FLAGS_USE_SHADOWLOD_MATERIALS flag, which is explained like so in 🖿public/studio.h:
This flag is set when we should use the actual materials on the shadow LOD instead of overriding them with the default one (necessary for translucent shadows)

Example

$lod 12
{
	replacemodel "Police_reference" "lod1_Police_reference"
	replacemodel "Manhack_reference" "lod1_Manhack_reference"
}

$lod 18
{
	replacemodel "Police_reference" "lod2_Police_reference"
	replacemodel "Manhack_reference" "lod2_Manhack_reference"
	bonetreecollapse "ValveBiped.Bip01_R_Hand"
	bonetreecollapse "ValveBiped.Bip01_L_Hand"
}

$lod 42
{
	replacemodel "Police_reference" "lod3_Police_reference"
	replacemodel "Manhack_reference" "lod3_Manhack_reference"
	bonetreecollapse "ValveBiped.Bip01_R_Hand"
	bonetreecollapse "ValveBiped.Bip01_L_Hand"
}

See also