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

$color

From Valve Developer Community
(Redirected from $color2)
Jump to navigation Jump to search
English (en)Translate (Translate)

$color is a material shader parameter available in all Source Source games.


$color
TypeMaterial Shader parameter
Default values"[1 1 1]"
"{255 255 255}"
EngineSource Source
AvailabilityIn all games
ShadersLightmappedGeneric
UnlitGeneric
VertexLitGenericLeft 4 Dead 2
 

$color independently scales the red, green and blue channels of an albedo. There are two ways of expressing a value:

Syntax

$color "[ <float> <float> <float> ]"
$color "{ <int> <int> <int> }"
Note.pngNote:You must use quotemarks, as there are space characters within the value.
Note.pngNote:You can also define the value as a single float, in which case it should equally apply to all three channels (e. g. $color 0.5 will equate to $color "[0.5 0.5 0.5]"). In this case you won't need the quotemarks. However, this method appears to not be 100% reliable.[confirm]

Gamma

Source uses a gamma correction of 2.2 by default. This must be taken into account when attempting to adjust the color of a texture to match some other color in a screenshot (for example, when trying to match the color of the bottom of a skybox material to the color of fog in the map). This is done by raising the initially calculated scale to the power of 2.2 before setting the $color value for your material. For example, if the sample (target) color in a screenshot is 120, the color of your texture at the point of interest is 240, and you want the two colors to match, you need to compute the albedo scale for your material as (120 / 240) ^ 2.2 = 0.218 (not 0.5, as one might expect).

Tip.pngTip:Don't try to recreate a texture through a screenshot. GCFScape is free.

Solid color

This parameter can be used without an albedo to display a solid color without the need of a texture (except a %tooltexture). As well as a small saving in performance and memory footprint, material_modify_control can be used to completely change the material's color at run-time if desired.

In this scenario, "[1 1 1]" is pure white.

Tip.pngTip:If the material is representing empty blackness, you will probably want to use the UnlitGeneric shader to prevent it from ever becoming grey.
Tip.pngTip: If game support HDR you can use negative values and floats above 1.0

$color2

$color2
TypeMaterial Shader parameter
Default values"[1 1 1]"
"{255 255 255}"
EngineSource Source
AvailabilityIn all games
ShadersVertexLitGeneric
SurfaceGGX
WorldGGX
 

$color2 works the same way as $color but for use on models.

Note.pngNote:Left 4 Dead 2 Left 4 Dead 2 has support for both $color and $color2 parameters with VertexLitGeneric and UnlitGeneric. It may be used as additional tint control.

Syntax

$color2 "[ <float> <float> <float> ]"
$color2 "{ <int> <int> <int> }"
Note.pngNote:As with $color, you can use a single float that'll apply to all three channels equally. (not in Counter-Strike: Source) However, this may be unreliable.[confirm]

Additional Model Parameters

$blendtintbybasealpha<bool> (in all games since Left 4 Dead) (also in Source 2013) (also in Garry's Mod)
Enables the use of an alpha mask to define areas on the model to tint. Uses the alpha channel of the $basetexture.
Icon-Bug.pngBug:Incompatible with $alphatest and $translucent.  [todo tested in?]
Icon-Bug.pngBug:Incompatible with $selfillum. This parameter is ignored if both used.  [todo tested in?]
$blendtintcoloroverbase<float> (only in Source 2013) (also in Garry's Mod)
Sets the amount to replace with solid color. A value of '0' will be full tint while a value of '1.00' will replace the albedo in the mask area with the color defined with $color2. Default value is '0'.
$tintmasktexture<texture> (only in Counter-Strike: Global OffensivePortal 2: Community Edition)
Use a seperate texture as a mask for color tinting instead of the $basetexture alpha. Only the green channel is used for tinting.
Icon-Bug.pngBug:Incompatible with $phong and $bumpmap used simultaneously.  [todo tested in?]
$allowdiffusemodulation<bool> (in all games since Left 4 Dead)
Shader: VertexLitGeneric
Prevents the model's material from being tinted by $color2 or rendercolor.
$notint<bool> (only in Counter-Strike: Global OffensivePortal 2: Community Edition) (also in Garry's Mod)
Shader: VertexLitGeneric
Prevents the model's material from being tinted by $color2 or rendercolor.

Caveats

  • $color2 is incompatible with the use of $selfillum, as it will override the glow properties used by both $selfillum & $selfillummask. Use the $selfillumtint command to adjust the glow so it properly appears.

External links