$color: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(Added a note about gamma correction)
Line 5: Line 5:


Quote marks are required. A float value of 1.0 (or an integer value of 255) represents a unit scale; thus, the default value is <code>[1 1 1]</code> (or <code>{255 255 255}</code>).
Quote marks are required. A float value of 1.0 (or an integer value of 255) represents a unit scale; thus, the default value is <code>[1 1 1]</code> (or <code>{255 255 255}</code>).
Note that the Source engine 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 <code>$color</code> 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 <code>(120 / 240) ^ 2.2 = 0.218</code> (not 0.5, as one might expect).


== Solid color ==
== Solid color ==

Revision as of 21:24, 20 August 2009

$color independently scales the red, green and blue channels of an albedo.

$color "[<red float> <green float> <blue float>]"
$color "{<red integer> <green integer> <blue integer>}"

Quote marks are required. A float value of 1.0 (or an integer value of 255) represents a unit scale; thus, the default value is [1 1 1] (or {255 255 255}).

Note that the Source engine 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).

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.