Infected

From Valve Developer Community
Jump to: navigation, search

The Infected shader is used in <Left 4 Dead 2> Left 4 Dead 2 to dynamically render wounded zombies and body parts.

Instead of relying on gibbed variations of all models, this shader is used on the models to remove whichever body part was shot at to look more realistic, and allows for adding different types of slashes and dynamic gore and flesh effects.

The model will simply render hollow, however. So the programmer or artist would need to place skeleton and flesh models inside of the holes that were created, in order to create a convincing effect. To do: Add some images from the game or the presentation here.

To do: How does this shader relate to $shinyblood of VertexLitGeneric?

Note:This shader only works on models.

Usage

Note:The shader was only tested in Source Filmmaker. As of such, and due to the fact that the source code is inaccessible, many shader parameters and features are not further explained and require further testing (especially inside of the game itself).

Check out left4dead2/materials/models/infected/common/l4d2/bp_head_include.vmt for a sample material that uses the shader.

General

$basetexture <texture>
Unlike other shaders, this parameter serves a completely different role. It acts as a mask texture, where each channel serves a different purpose:
Red*: Detail blend mask
Green*: Blood blend mask
Blue: Skin mask
Alpha*: Eyeglow mask
Additionally, the vtf is split up similarly to a sprite sheet. All channels marked with a * are affected by this.
To compensate, scale down these channels to half their size and place them in one of the four quarters of the texture. This allows for more "variations" without using animation frames.
$nocull <bool>
Determines whether the backsides of faces can be seen. If a model is sliced open, you will see the insides of the model as well.
$translucent <bool>
Disables dynamic shadows on the model.
$cheapdiffuse <bool>
According to a vmt comment: "test stuff, doesn’t do anything right now".
$rttshadowbuild <bool>
Unknown. May be related to RTT shadow rendering. Default value is 0, setting to 1 changes shader combination and renders the model as white.
$translucent_material <string>
Unknown. Possibly allows for a translucent render pass.
$gradienttexture <texture>
Unknown. Possibly related to wounds.
$sheetindex <int>
$colortintgradient <int>
Unknown. Possibly controlled using code?
$ambientocclusion <bool>
Enables ambient occlusion on the model (for example in Source Filmmaker).
Note:While this shader supports many of VertexLitGeneric's shader parameters, it does not support $bumpmap due to the complexity of the shader. From Shading a Bigger, Better Sequel - Techniques in Left 4 Dead 2

Wounds

The most interesting part of this shader is the wound calculation. Set $wounded 1 to enable it.

To debug the wounds, you can use following shader parameters:

$debugellipsoids <bool>
Enables debugging ellipsoids. These can be positioned using other shader parameters to mess with the effect.
There are two debugging ellipsoids with different functionality. Only the second one is currently known to work: it bursts a hole into the model where it intersects.
Leaving out the 2 from the next four shader parameters controls the ellipsoid 1, but no effects could be seen.
$ellipsoidcenter2 <vector>
Center of the ellipsoid 2, in local space (0 0 0 should be the entity's origin).
$ellipsoidup2 <vector>
The up axis of ellipsoid 2. Z-up (0 0 1) by default.
$ellipsoidlookat2 <vector>
The direction that the ellipsoid 2 faces.
$ellipsoidscale2 <vector>
The size of the ellipsoid 2, in local coordinates.
$ellipsoid2culltype <int>
Unknown. 0 seems to be regular culling of ellipsoid 2, other values disable the ellipsoid. (This parameter does not exist for ellipsoid 1.)


The following shader parameters are unknown in function, but seem to be related to the wound rendering. They do not seem to influence the debugging ellipsoid culling at all.

$woundcutouttexture <texture>
Texture containing masks for blood and shapes of the wounds.
$cutouttexturebias <float>
When the cutout texture should mask the wound. Values below 0.5 hide the entire model when using debugging ellipsoids.
$cutoutdecalfalloff <float>
Unknown.
$cutoutdecalmappingscale <float>
Unknown.

Phong

$phong <bool>
$phongboost <float>
$phongtint <vector>
$phongfresnelranges <vector>
$halflambert <bool>
See the relevant articles for these commands. They function identically to VertexLitGeneric's counterparts. However, $phongexponent related options do not work. See below for replacement options.
$defaultphongexponent <float>
Equivalent to $phongexponent, except for any unmasked parts of the texture.

Detail

The detail pass is controlled by the red channel of the $basetexture. Unlike other textures in Source, this texture is actually transformed differently.

In order to convert a regular $basetexture to the equivalent $detail texture (with same UV mapping), you will need to:

  1. Take the original vtf file
  2. Mirror it horizontally
  3. Rotate it by 90° counter-clockwise
  4. Use a $detailscale of 1

Besides these parameters, $detailframe and $detailblendfactor are also supported.

To do: How is the alpha channel handled?

To do: Is the $basetexture transformed like this as well?

Skin

The skin pass is controlled by the blue channel of the $basetexture. It also is the only channel that does not allow for variation using texture indexes (see below).

$skintintgradient <int>
Unknown. Possibly controlled using code?
$skinphongexponent <float>
Equivalent to $phongexponent, except for skin parts of the texture (blue channel).

Blood

The blood pass is controlled by the green channel of the $basetexture.

$bloodcolor <color>
Color of the blood pass. To do: Is this multiplied with anything, or just overlaid as it is?
$bloodphongexponent <float>
Equivalent to $phongexponent, except for blood parts of the texture (green channel).
$bloodspecboost <float>
Equivalent to $phongboost, except for blood parts of the texture (green channel).
$bloodmaskrange <vector2>
Unknown. Seems to modify the phong shape on blood.

To do: Something seems wrong! A fully red basetexture is affected by the values of $bloodspecboost and $bloodphongexponent, and $phongboost and $phongexponent do nothing!

Burning

$burning <bool>
Controls whether the material should appear burning. Does not seem to do anything.
$burnstrength <float>
Opacity of the burning effect. Defaults to 0.
$burndetailtexture <texture>
Unknown. Most likely the texture to use for the burning effect, implemented similarly to how Team Fortress 2 handles burning models (overlaying a $detail texture).

Eyeglow

The eyeglow pass is controlled by the alpha channel of the $basetexture.

$eyeglow <bool>
Set to 1 to enable the effect. Causes an additive color overlay, as well as different phong settings.
$eyeglowcolor <color>
Color of the effect.
$eyeglowflashlightboost <float>
Phong boost for the effect, in case the model is hit by projected texture lighting such as the flashlight.

SFM integration

Since Source Filmmaker version 0.9.8.9 (released 27 Aug, 2014), the Infected shader is supported and integrated into the program.

Creating an animation set with the shader will automatically generate the following attributes as part of the DmeGameModel:

infectedSkinTint <int>
infectedClothesTint <int>
Unknown. May be related to the gradient texture controls.
infectedTextureIndex <int>
Controls which of the four quarters of the $basetexture get selected for display (see above for detailed information).
0 is top left, 1 is top right, 2 is bottom left, 3 is bottom right.

See also

Rendering Wounds in Left 4 Dead 2