Detail props

From Valve Developer Community
Revision as of 05:12, 8 June 2009 by Remmiz (talk | contribs)

Jump to: navigation, search

Introduction

Models of type prop_detail can be set to be randomly emitted from surfaces based upon the material assigned to the surface. The detail.vbsp file defines detail prop groups. Each detail prop group specifies which prop_detail 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 detail_group_name is the one of the detail prop group entries in game_directory/detail.vbsp.

Usage

Here's an simple example of a detail prop group, as defined in detail.vbsp:

   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"
        } 
      } 
   } 

"density" 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 model fields above describe which studio model to use, and the "amount" 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 "density".

The "alpha" 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 (alpha = 1 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 "alpha" "1.0" contains rock models and the group with "alpha" "0.0" contains grass models. Note that you can make as many groups as you want; for example, if you were to add a group with "alpha" "0.5", 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 "materials\detail\detailsprites.vtf".

The first two numbers in the "sprite" field shown above specify the (X, Y) coordinate of the upper left corner of the sprite as it lies within the detailsprite.vtf texture. The next two numbers specify the width and height of the sprite. The final number is the size of the detailsprite.vtf texture in pixels.

The first two numbers in the "spritesize" 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 "spritesize" line indicate the width and height of the sprite in world units when it gets drawn.

"spriterandomscale" 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 "spritesize" line).

Finally, "detailOrientation" 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.

General Properties

Property Comment
"density" Specifies how many points to randomly generate. Larger numbers will generate more detail props.
"amount" The ratio of a detail relative to the others in the group.

Value: 0.0 => 1.0

"alpha" Determines which alpha to use for blended displacement surfaces. 0.5 would be between the two textures.

Value:0.0 => 1.0

Properties Specific to Sprites

Property Comment
"sprite" Specifies the sprite to use by selecting a region of detailsprites.vtf. The first two numbers specify the (X, Y) coordinate of the upper left corner of the sprite as it lies within the detailsprite.vtf texture. The next two numbers specify the width and height of the sprite. The final number is the size of the detailsprite.vtf texture in pixels.
"spritesize" The first two numbers specify the rotational center of the detail sprite in normalized coordinates: (0,0) specifies the lower left, and (1,1) specifies the upper right (0.5, 0.0 usually suffice). The final two numbers in the "spritesize" line indicate the width and height of the sprite in world units when it gets drawn.
"spriterandomscale" Specifies a random amount by which the sprite's size is scaled.
"detailOrientation" 0: Do not orient towards the player.

1: Always face the player.

2: Always face the player but rotate on the x and y axis only.

Properties Specific to Models

Property Comment
"model" Specifies which studio model to use.

Detail Shapes

Detail shapes are a new way for the engine to place auto-emitted detail props on a surface, as specified by the detail.vbsp file. Introduced in the Day of Defeat: Source release, detail shapes allow normal sprites to be placed in a variety of shapes.

In addition, sprites can now have a "swaying" motion, where the sprite leans forward and back.

Finally, these sprites are capable of being "displaced". That is, they will move away from players upon contact and then bounce back to their original orientation. Note that the sprites will continue to "sway" even when pushed out of their original position.

Usage

Detail shape functionality was added (silently) to Counter-Strike: Source with the HDR update on December 1, 2005, which indicates that this addition is linked to the HDR technology and thus will likely be added to the other Source games when they are updated with HDR.

Does this work for mods yet? Cant seem to enable it yet

Types of Detail Shapes

Detail shape of "tri"
Another "tri" with a small distance value
sprite_shape Comment
"cross" This makes a criss-cross shape.


Places two sprites which cross over one-another in the middle.

"tri" This makes a detail in the exploded prism shape (triangle).


Places three sprites sitting equidistant from each other in a triangle formation.


Refining Detail Shapes

There are several properties for the detail.vbsp file which refine the shape of the detail sprites, as well as enhacing their aesthetic quality (such as the sway).


Property Comment
"sway" Percentage of cl_detail_max_sway ( default 5 ).


Value: 0.0 => 1.0

"shape_angle" Specific to "tri" shape. Degrees to angle out each of the leaves.


Value: 0 => 90 (Untested)

"shape_size" Specific to "tri" shape. Percentage of sprite width to separate each leaf. near 0 for a triangle shape, near 1 for a closer, criss-cross shape.


Value: 0, 1 (Untested)

Related Console Commands

There are several clientside console commands you may use to alter the behavior of detail sprites.


Command Comment
"cl_detail_avoid_force" Force with which to avoid players.
"cl_detail_avoid_radius" Radius around sprite to avoid players.
"cl_detail_avoid_recover_speed" How fast to recover position after avoiding players.
"cl_detail_max_sway" Amplitude of the detail prop sway.