Decals: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Apostrophe Alignment Militia strikes again!)
(ported current decal info from html site)
Line 1: Line 1:
[[Category:Material System]]
[[Category:Material System]]
When the player shoots his or her weapon into a wall, the marks left by the bullet impacts are called "decals". These are most easily thought of as materials that are applied to a surface and remain there as an indelible mark on the world. Posters, scorch marks, and stenciled letters can all be created using this type of graphic. Decals will clip their extents to whatever surface they are placed on to. For example, a decal applied to a staircase would cascade down on to each stair surface instead of hanging out into space. You can also think of this as how a stencil would apply a mark to the world.
When the player shoots his or her weapon into a wall, the marks left by the bullet impacts are called "decals". These are most easily thought of as materials that are applied to a surface and remain there as an indelible mark on the world. Posters, scorch marks, and stenciled letters can all be created using this type of graphic. Decals will ''clip'' their extents to whatever surface they are placed on to. For example, a decal applied to a staircase would cascade down on to each stair surface instead of hanging out into space. You can also think of this as how a stencil would apply a mark to the world.


Creating decals is fairly straightforward: they are simply materials generally having an alpha mask of some sort, and also often using the mod2x shader. Before reading this document, please refer to the [[Creating Materials]] document for the basics of material creation.
Creating decals is fairly straightforward: they are simply materials generally having an ''alpha channel mask'' of some sort, and also often using the ''mod2x'' shader. Before reading this document, please refer to the [[Creating Materials]] document for the basics of material creation.


=Simple Decals=
== Simple Decals ==


The most simple type of decal is one that simply acts like a true decal or stencil: source art (<i>See Fig 1a</i>) is clipped and projected on to the world within some mask, specified via the material's alpha channel (<i>See Fig 1b</i>). The result is similar to <i>Fig 1c</i>.
The most simple type of decal is one that simply acts like a true decal or stencil: source art (''See Fig 1a'') is clipped and projected on to the world within some mask, specified via the material's alpha channel (''See Fig 1b''). The result is similar to ''Fig 1c''.


{|
[[Image:decal04.jpg |frame|left|Fig 1a - Source color channels]] [[Image:decal05.jpg |frame|left|Fig 1b - Source alpha channel]] [[Image:Decal06.jpg |frame|left|Fig 1c - Decal in the world]] <br style="clear:both">
[[Image:decal04.jpg | Fig 1a - Source color channels]] ||
[[Image:decal05.jpg | Fig 1b - Source alpha channel]] ||
[[Image:Decal06.jpg | Fig 1c - Decal in the world]]
|}


You must also define a VMT file for the decal material, so that it can properly be interpreted by the renderer. This VMT would look like:
You must also define a .VMT file for the decal material, so that it can properly be interpreted by the renderer. This .VMT would look like:


<pre>
"LightmappedGeneric"
"Decal"
{
{
    "$basetexture" "decals/mydecal"
    "$basetexture"   "decals/mydecal"
    "$decal" 1
    "$decalscale"     0.10
    "$decalscale" 0.10
}
    "$translucent" 1
</pre>
}


It's important that the shader used to render this image is the "Decal" shader. Without this shader, the material will not clipped or projected onto the world properly.
It's important the "<code>$decal</code>" parameter is included. Without this parameter, the material will not clipped or projected onto the world properly.


In this example the key <code>"$decalscale"</code> is set to a value of "0.1", meaning that the decal is rendered at 1/10th scale inside of the engine. If the source texture for this decal is 128 pixels, it will be 12.8 inches in size in the engine (or about a foot in length).
The "<code>$basetexture</code>" parameter should specify the source .VTF texture file to be used for the decal.


Once the VMT has been specified, the decal may be placed in Hammer via an overlay, or in code via the decal code.
In this example the key "<code>$decalscale</code>" is set to a value of "0.1", meaning that the decal is rendered at 1/10th scale inside of the engine. If the source texture for this decal is 128 pixels, it will be 12.8 inches in size in the engine (or about a foot in length).


=Using Modulation=
The "$<code>translucent</code>" parameter specifies that the material should use the alpha channel of the source .VTF to mask transparent sections of the material.


For decals intended to mimic the look of pock marks or dents in a surface, the <code>mod2x</code> material shader is especially suitable. This shader lightens any destination pixels for every source pixel that is over mid-range gray (128). Likewise, it will darken any destination pixels for every source pixel that is below mid-range gray. This effect can be used to give the impression of depth when applied to a surface (<i>See Fig 2c</i>).
Once the VMT has been specified, the decal may be placed in Hammer via the '''Overlay''' or '''Decal''' tool, or in code via the decal code. For decals placed in code that are meant to be applied to models (such as blood), the <code>VertexLitGeneric</code> shader should be used instead of <code>LightmappedGeneric</code>. <code>LightmappedGeneric</code> is used for decals applied to world geometry.


To begin, create a source image whose color channel will be used for the modulation's source values (<i>See Fig 2a</i>). Again, light values will lighten pixels they're drawn over, while dark values will darken the destination pixels. Mid-gray values will be treated as translucent.
== Using Modulation ==


Next, create an alpha channel that defines a mask for the decal. Because modulation cannot have an exact middle value currently, the mask is necessary to prevent "bordering" from occurring around the decal (See <i>Fig 2b</i>).
For decals intended to mimic the look of pock marks or dents in a surface, the ''mod2x'' material shader is especially suitable. This shader lightens any destination pixels for every source pixel that is over mid-range gray (128). Likewise, it will darken any destination pixels for every source pixel that is below mid-range gray. This effect can be used to give the impression of depth when applied to a surface (''See Fig 2c'').


{|
To begin, create a source image whose color channel will be used for the modulation's source values (''See Fig 2a''). Again, light values will lighten pixels they're drawn over, while dark values will darken the destination pixels. Mid-gray values will be treated as translucent.
[[Image:decal01.jpg | Fig 2a - Source color channels]] ||
[[Image:decal02.jpg | Fig 2b - Source alpha channel]] ||
[[Image:decal03.jpg | Fig 2c - Decal in the world]]
|}


Finally, you must create a VMT file to properly define this material as a modulated decal:


<pre>
Next, create an alpha channel that defines a mask for the decal. Because modulation cannot have an exact middle value currently, the mask is necessary to prevent "bordering" from occurring around the decal (''See Fig 2b'').
"DecalModulate"
 
{
[[Image:decal01.jpg|frame|left|Fig 2a - Source color channels]][[Image:decal02.jpg|frame|left|Fig 2b - Source alpha channel]] [[Image:decal03.jpg|frame|left|Fig 2c - Decal in the world]]<br style="clear:both">
    "$basetexture"   "decals/mydecal"
 
    "$decalscale"     0.10
Finally, you must create a VMT file to properly define this material as a modulated decal with the <code>DecalModulate</code> shader:
}
 
</pre>
"DecalModulate"
Again, the decal is now ready for use within the engine.
{
    "$basetexture" "decals/mydecal"
    "$decalscale" 0.10
}
 
Note that neither the <code>"$translucent"</code> or <code>"$decal"</code> parameters are needed. Again, the decal is now ready for use within the engine.

Revision as of 18:37, 25 July 2005

When the player shoots his or her weapon into a wall, the marks left by the bullet impacts are called "decals". These are most easily thought of as materials that are applied to a surface and remain there as an indelible mark on the world. Posters, scorch marks, and stenciled letters can all be created using this type of graphic. Decals will clip their extents to whatever surface they are placed on to. For example, a decal applied to a staircase would cascade down on to each stair surface instead of hanging out into space. You can also think of this as how a stencil would apply a mark to the world.

Creating decals is fairly straightforward: they are simply materials generally having an alpha channel mask of some sort, and also often using the mod2x shader. Before reading this document, please refer to the Creating Materials document for the basics of material creation.

Simple Decals

The most simple type of decal is one that simply acts like a true decal or stencil: source art (See Fig 1a) is clipped and projected on to the world within some mask, specified via the material's alpha channel (See Fig 1b). The result is similar to Fig 1c.

Fig 1a - Source color channels
Fig 1b - Source alpha channel
Fig 1c - Decal in the world


You must also define a .VMT file for the decal material, so that it can properly be interpreted by the renderer. This .VMT would look like:

"LightmappedGeneric"
{
    "$basetexture" "decals/mydecal"
    "$decal" 1
    "$decalscale" 0.10
    "$translucent" 1
}

It's important the "$decal" parameter is included. Without this parameter, the material will not clipped or projected onto the world properly.

The "$basetexture" parameter should specify the source .VTF texture file to be used for the decal.

In this example the key "$decalscale" is set to a value of "0.1", meaning that the decal is rendered at 1/10th scale inside of the engine. If the source texture for this decal is 128 pixels, it will be 12.8 inches in size in the engine (or about a foot in length).

The "$translucent" parameter specifies that the material should use the alpha channel of the source .VTF to mask transparent sections of the material.

Once the VMT has been specified, the decal may be placed in Hammer via the Overlay or Decal tool, or in code via the decal code. For decals placed in code that are meant to be applied to models (such as blood), the VertexLitGeneric shader should be used instead of LightmappedGeneric. LightmappedGeneric is used for decals applied to world geometry.

Using Modulation

For decals intended to mimic the look of pock marks or dents in a surface, the mod2x material shader is especially suitable. This shader lightens any destination pixels for every source pixel that is over mid-range gray (128). Likewise, it will darken any destination pixels for every source pixel that is below mid-range gray. This effect can be used to give the impression of depth when applied to a surface (See Fig 2c).

To begin, create a source image whose color channel will be used for the modulation's source values (See Fig 2a). Again, light values will lighten pixels they're drawn over, while dark values will darken the destination pixels. Mid-gray values will be treated as translucent.


Next, create an alpha channel that defines a mask for the decal. Because modulation cannot have an exact middle value currently, the mask is necessary to prevent "bordering" from occurring around the decal (See Fig 2b).

Fig 2a - Source color channels
Fig 2b - Source alpha channel
Fig 2c - Decal in the world


Finally, you must create a VMT file to properly define this material as a modulated decal with the DecalModulate shader:

"DecalModulate"
{
    "$basetexture" "decals/mydecal"
    "$decalscale" 0.10
}

Note that neither the "$translucent" or "$decal" parameters are needed. Again, the decal is now ready for use within the engine.