$color: Difference between revisions
(the argument in brackets [ ] takes all float values, not just normals (it is possible to raise a channel's value)) |
SirYodaJedi (talk | contribs) |
||
(40 intermediate revisions by 22 users not shown) | |||
Line 1: | Line 1: | ||
{{LanguageBar|title = $color}} | |||
{{this is a|shader parameter|name=$color}} | |||
{{infotable | |||
|$color | |||
|type=s1 | |||
|char=C | |||
|default="[1 1 1]"<br>"{255 255 255}" | |||
|engine=2 | |||
|in=0 | |||
|shader={{ent|LightmappedGeneric}}<br>{{ent|UnlitGeneric}}<br>{{ent|VertexLitGeneric}}{{l4d2}} | |||
}} | |||
{{toc-right}} | |||
{{Code|select=1|$color}} independently scales the [[RGB|red, green and blue]] channels of an [[albedo]] or [[diffuse]], and multiplies the result. There are two ways of expressing a value: | |||
== | ===Syntax=== | ||
'''$color "[ <[[float]]> <[[float]]> <[[float]]> ]"''' | |||
'''$color "{ <[[integer|int]]> <[[integer|int]]> <[[integer|int]]> }"''' | |||
{{note|You ''must'' use quotemarks, as there are space characters within the value.}} | |||
{{note|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 <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). | 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 <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). | ||
{{tip|Don't try to recreate a texture through a screenshot. [[GCFScape]] is free.}} | |||
== Solid color == | ==Solid color== | ||
This parameter can be used ''without'' an albedo to display a solid color without the need of a texture (except a <code>[[%tooltexture]]</code>). As well as a small saving in performance and memory footprint, {{ent|material_modify_control}} can be used to completely change the material's color at run-time if desired. | |||
In this scenario, <code>"[1 1 1]"</code> is pure white. | |||
{{tip|If the material is representing empty blackness, you will probably want to use the {{ent|UnlitGeneric}} shader to prevent it from ever becoming grey.}} | |||
{{tip| If game support [[HDR]] you can use negative values and [[float|floats]] above 1.0}} | |||
{{ | == <tt>$color2</tt> == | ||
{{infotable | |||
|$color2 | |||
|type=s1 | |||
|char=C | |||
|default="[1 1 1]"<br>"{255 255 255}" | |||
|engine=2 | |||
|in=0 | |||
|shader={{ent|VertexLitGeneric}}<br>{{ent|SurfaceGGX}}<br>{{ent|WorldGGX}} | |||
}} | |||
= | {{Code|select=1|$color2}} works the same way as {{ent|$color}} but for use on models. | ||
{{note|{{l4d2|4}} 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 "{ <[[integer|int]]> <[[integer|int]]> <[[integer|int]]> }"''' | |||
{{note|As with '''$color''', you can use a single float that'll apply to all three channels equally. {{css|not}} However, this may be unreliable.{{confirm}}}} | |||
===Additional Model Parameters=== | |||
{{def|code=1|[[$blendtintbybasealpha]]|type=[[boolean|bool]]|add={{l4d|since}} {{src13|also}} {{gmod|also}}}} Enables the use of an alpha mask to define areas on the model to tint. Uses the alpha channel of the <code>$basetexture.</code>{{bug|Incompatible with {{ent|$alphatest}} and {{ent|$translucent}}.}}{{bug|Incompatible with {{ent|Glowing Textures#$selfillum|alt=$selfillum}}. This parameter is ignored if both used.}} | |||
{{def|code=1|$blendtintcoloroverbase|type=[[float]]|add={{src13|only}} {{gmod|also}}}} Sets the amount to replace with solid color. A value of '0' will be regular multiplied tint while a value of '1.00' will replace the [[diffuse]] in the mask area with the color defined with <code>$color2.</code> Default value is '0'. | |||
{{def|code=1|$tintmasktexture|type=[[texture]]|add={{csgo|only|addtext={{strata}}}}}} Use a separate texture as a mask for color tinting instead of the {{ent|$basetexture}} alpha. Only the green channel is used for tinting. {{bug|Incompatible with {{ent|$phong}} and {{ent|$bumpmap}} used simultaneously.}} | |||
{{def|code=1|[[$allowdiffusemodulation]]|type=[[boolean|bool]]|add={{l4d|since}}|shaders={{ent|VertexLitGeneric}}}} Prevents the model's material from being tinted by <code>$color2</code> or <code>rendercolor</code>. | |||
:{{confusion|Unlike most boolean VMT parameters, the default value is 1; setting to 0 disables tinting.}} | |||
{{def|code=1|[[$notint]]|type=[[boolean|bool]]|add={{csgobranch|only|addtext={{strata}}}} {{gmod|also}}|shaders={{ent|VertexLitGeneric}}}} Prevents the model's material from being tinted by <code>$color2</code> or <code>rendercolor</code>. | |||
== | ==Caveats== | ||
* <code>$color2</code> is incompatible with the use of <code>[[$selfillum]]</code>, as it will override the glow properties used by both <code>$selfillum</code> & <code>$selfillummask</code>. Use the <code>$selfillumtint</code> command to adjust the glow so it properly appears. | |||
{{bug|tested={{dods}}|Due to being added during the lighting stage, it may not appear when shining a projected texture (such as the player flashlight) on the texture.}} | |||
==External links== | |||
== External | |||
* [http://hewmc.blogspot.com/2012/12/rgb-to-percentage-converter.html Convert RGB Values to Percent] | * [http://hewmc.blogspot.com/2012/12/rgb-to-percentage-converter.html Convert RGB Values to Percent] | ||
Latest revision as of 06:54, 19 April 2025
$color
is a material shader parameter available in all Source games.
$color | |
---|---|
Type | Material Shader parameter |
Default values | "[1 1 1]" "{255 255 255}" |
Engine | ![]() |
Availability | In all games |
Shaders | LightmappedGeneric UnlitGeneric VertexLitGeneric ![]() |
$color independently scales the red, green and blue channels of an albedo or diffuse, and multiplies the result. There are two ways of expressing a value:
Syntax
$color "[ <float> <float> <float> ]" $color "{ <int> <int> <int> }"


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).

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.

$color2
$color2 | |
---|---|
Type | Material Shader parameter |
Default values | "[1 1 1]" "{255 255 255}" |
Engine | ![]() |
Availability | In all games |
Shaders | VertexLitGeneric SurfaceGGX WorldGGX |
$color2 works the same way as $color but for use on models.


Syntax
$color2 "[ <float> <float> <float> ]" $color2 "{ <int> <int> <int> }"


Additional Model Parameters
- $blendtintbybasealpha <bool> (in all games since
) (also in
) (also in
)
- Enables the use of an alpha mask to define areas on the model to tint. Uses the alpha channel of the
$basetexture.
Bug:Incompatible with $alphatest and $translucent. [todo tested in ?]
Bug:Incompatible with $selfillum. This parameter is ignored if both used. [todo tested in ?]
- $blendtintcoloroverbase <float> (only in
) (also in
)
- Sets the amount to replace with solid color. A value of '0' will be regular multiplied tint while a value of '1.00' will replace the diffuse in the mask area with the color defined with
$color2.
Default value is '0'. - $tintmasktexture <texture> (only in
)
- Use a separate texture as a mask for color tinting instead of the $basetexture alpha. Only the green channel is used for tinting.
- $allowdiffusemodulation <bool> (in all games since
)
Shader: VertexLitGeneric - Prevents the model's material from being tinted by
$color2
orrendercolor
. Risk of Confusion:Unlike most boolean VMT parameters, the default value is 1; setting to 0 disables tinting.
- $notint <bool> (only in
) (also in
)
Shader: VertexLitGeneric - Prevents the model's material from being tinted by
$color2
orrendercolor
.
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.