Detailtype: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
m (Redirected page to Detail props)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Automatically emitting prop_details on a material ==
#REDIRECT [[Detail props]]
 
See Also [[Detail Props]]
 
Models of type prop_detail can be set to be randomly emitted from surfaces based upon the material assigned to the surface. The file <code>detail.vbsp</code> describes detail prop groups. Each detail prop group specifies which <code>prop_detail</code> models are emitted from that group. A material can indicate which detail prop group is assigned to it by adding this line to the .vmt file:
 
%detailtype = "detail_group_name"
 
Where <code>detail_group_name</code> is the one of the detail prop group entries in <code>detail.vbsp</code>.
 
Here's an simple example of a detail prop group, as defined in <code>detail.vbsp</code>:
swamp_grass_and_rocks
{
"density" "800.0"
Group1
{
"alpha" "1.0"
Model1
{
"model" "models/junk/rock1.mdl"
"amount" "0.3"
}
Model2
{
"model" "models/junk/rock2.mdl"
  "amount" "0.3"
}
}
Group2
{
"alpha" "0.0"
Model1
{
"model" "models/foliage/Grass_tuft_003a.mdl"
"amount" "0.1"
}
Model2
{
"model" "models/foliage/Grass_tuft_004b.mdl"
"amount" "0.3"
}
}
}
 
<code>"Density"</code> describes how many points to randomly generate on all surfaces that have materials that use this detail prop group. Larger numbers will generate more detail props.
 
Then, you can specify as many groups of detail props as you like. Materials on non-displacement surfaces will only use one group, but displacement surfaces may use multiple groups. Each group specifies a list of the models that will be randomly emitted. The <code>model</code> fields above describe which studio model to use, and the <code>"amount"</code> field describes how many to emit relative to the other models in the list. For advanced users: If the amounts of all the models within a single group add up to less than 1, then the system will actually emit less than the maximum number of models described by <code>"density"</code>.
 
The <code>"alpha"</code> field is only used for displacement surfaces. When a displacement surface is using a material that blends between two textures, the alpha describes how much of each texture to use. The detail system looks at that alpha to choose which group to select models from. For example, lets say you've got a displacement with two textures on it, one is road (<code>alpha = 1</code> for the road) and the other is grass (alpha = 0 for the grass). In the example above, it would emit rocks on the road and grass tufts on the grass, since the group with <code>"alpha" "1.0"</code> contains rock models and the group with <code>"alpha" "0.0"</code> contains grass models. Note that you can make as many groups as you want; for example, if you were to add a group with <code>"alpha" "0.5"</code>, this would create detail props using that group's models wherever the displacement is blending halfway between the rocks and grass.
 
Using the detail prop system with .MDLs can actually be fairly expensive owing to a high per-model overhead that currently exists in DirectX. To avoid this, you may also use sprites with the detail prop system, which doesn't have this overhead and is consequently at least 10x faster than using .MDLs. Here's how to specify a detail model group that uses detail sprites:
Group1
{
"alpha" "1"
Model1
{
"sprite" "288 0 128 128 512"
"spritesize" "0.5 0.0 19 25"
"spriterandomscale" "0.2"
"amount" "0.2"
"detailOrientation" "2"
}
Model2
{
"sprite" "0 0 128 128 512"
"spritesize" "0.5 0.0 23 30"
"spriterandomscale" "0.2"
"amount" "0.1"
"detailOrientation" "2"
}
}
 
The textures for detail sprites must all be placed in sub-regions of the texture <code>"detailsprite.vtf"</code>.
 
The first two numbers in the <code>"sprite"</code> field shown above specify the (X, Y) coordinate of the upper left corner of the sprite as it lies within the <code>detailsprite.vtf</code> texture. The next two numbers specify the width and height of the sprite. The final number is the size of the <code>detailsprite.vtf</code> texture in pixels.
 
The first two numbers in the <code>"spritesize"</code> line specifies the rotational center of the detail sprite in normalized coordinates: (0,0) specifies the lower left, and (1,1) specifies the upper right. In the example above, the rotational center of the sprite is halfway along the lower edge of the sprite. The final two numbers in the <code>"spritesize"</code> line indicate the width and height of the sprite in world units when it gets drawn.
 
<code>"spriterandomscale"</code> specifies a random amount to scale the width and height of the detail sprite (in the example, the sprite will be between 80% and 120% of the size indicated in the <code>"spritesize"</code> line).
 
Finally, <code>"detailOrientation"</code> specifies how the detail sprite will move. A value of 0 indicates that it will not rotate; 1 means that it will always face the camera, and 2 means it will rotate around its Z-axis to try to face the camera as best it can.
 
[[Category:Level Design]]

Latest revision as of 15:10, 12 November 2009

Redirect to: