$color: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (→‎Additional Model Parameters: point a shader combo limitation declared under Source2013-SDK)
mNo edit summary
Line 1: Line 1:
{{Shaderparam|$color}} It independently scales the [[RGB|red, green and blue]] channels of an [[albedo]]. There are two ways of expressing a value:
{{lang|$color|$title=$color}}__NOTOC__
{{infotable|$color|type=s1|char=C|default="[1 1 1]"<br>"{255 255 255}"|engine=2|in=0|shader={{ent|LightmappedGeneric}}<br>{{ent|UnlitGeneric}}}} independently scales the [[RGB|red, green and blue]] channels of an [[albedo]]. There are two ways of expressing a value:


  $color "[ <[[float]]> <float> <float> ]"
===Syntax===
  $color "{ <[[int]]> <int> <int> }"
  '''$color "[ <[[float]]> <[[float]]> <[[float]]> ]"'''
 
  '''$color "{ <[[integer|int]]> <[[integer|int]]> <[[integer|int]]> }"'''
The default is <code>"[1 1 1]"</code> or <code>"{255 255 255}"</code>.
{{Note|You ''must'' use quotemarks, as there are space characters within the value.}}
{{Note|You ''must'' use quotemarks, as there are space characters within the value.}}


== Gamma ==
==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.}}
{{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, [[material_modify_control]] can be used to completely change the material's color at run-time if desired.
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, [[material_modify_control]] can be used to completely change the material's color at run-time if desired.


Line 19: Line 18:
{{tip|If the material is representing empty blackness, you will probably want to use the <code>[[UnlitGeneric]]</code> shader to prevent it from ever becoming grey.}}
{{tip|If the material is representing empty blackness, you will probably want to use the <code>[[UnlitGeneric]]</code> shader to prevent it from ever becoming grey.}}


== Models ==
=='''<code>$color2</code>'''==
 
{{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}}}} works the same way as {{ent|$color}} but for use on models.
A variant of '''<code>$color</code>''' named '''<code>$color2</code>''' is specific for use with {{ent|VertexLitGeneric}}. It works the same way as '''<code>$color</code>''' but for use on models.  


  $color2 "[ <[[float]]> <float> <float> ]"
===Syntax===
  $color2 "{ <[[int]]> <int> <int> }"
  '''$color2 "[ <[[float]]> <[[float]]> <[[float]]> ]"'''
  '''$color2 "{ <[[integer|int]]> <[[integer|int]]> <[[integer|int]]> }"'''


=== Additional Model Parameters ===
===Additional Model Parameters===
{{MatParam|$blendtintbybasealpha|bool|Enables the use of an alpha mask to define areas on the model to tint. Uses the alpha channel of the <code>$basetexture.</code>
{{def|code=1|$blendtintbybasealpha|type=boolean|add={{l4d|since}} {{src13|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.}}
: {{Bug|Incompatible with {{ent|$alphatest}} and {{ent|$translucent}}.}}|since={{l4d}}|also={{src13}}}}
{{def|code=1|$blendtintcoloroverbase|type=float|add={{src13|only}}}} 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 <code>$color2.</code> Default value is '0'.
: {{Bug|Incompatible with {{ent|$selfillum}}. This parameter is ignored if both used.}}
{{def|code=1|$tintmasktexture|type=texture|add={{csgo|only|addtext={{p2ce}}}}}} Use a seperate 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.}}
{{MatParam|$blendtintcoloroverbase|float|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 <code>$color2.</code> Default value is '0'.|only={{src13}}}}
{{def|code=1|[[$allowdiffusemodulation]]|type=boolean|add={{l4d|since}}|shaders={{ent|VertexLitGeneric}}}} Prevents the model's material from being tinted by <code>$color2</code> or <code>rendercolor</code>.
{{MatParam|$tintmasktexture|texture|Use a seperate texture as a mask for color tinting instead of the <code>$basetexture</code>'s alpha. Only the green channel is used for tinting.
{{def|code=1|[[$notint]]|type=boolean|add={{csgo|only|addtext={{p2ce}}}}|shaders={{ent|VertexLitGeneric}}}} Prevents the model's material from being tinted by <code>$color2</code> or <code>rendercolor</code>.
: {{bug|Incompatible with {{ent|$phong}} and {{ent|$bumpmap}} used simultaneously.}}|only={{csgo}}|also={{P2CE}}}}
{{MatParam|[[$allowdiffusemodulation]]|bool|Prevents the model's material from being tinted by <code>$color2</code> or <code>rendercolor.</code>|since={{l4d}}}}
{{MatParam|[[$notint]]|bool|Prevents the model's material from being tinted by <code>$color2</code> or <code>rendercolor.</code>|only={{csgo}}|also={{P2CE}}}}


== Caveats ==
==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.
* <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.


== External Links ==
==External Links==
* [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]
[[Category:List of Shader Parameters|C]]

Revision as of 02:33, 27 July 2022

English (en)中文 (zh)Translate (Translate)
$color
TypeMaterial Shader parameter
Default values"[1 1 1]"
"{255 255 255}"
EngineSource Source
AvailabilityIn all games
ShadersLightmappedGeneric
UnlitGeneric
 

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.

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.

$color2

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

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

Syntax

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

Additional Model Parameters

$blendtintbybasealpha<boolean> (in all games since Left 4 Dead) (also in Source 2013)
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)
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<boolean> (in all games since Left 4 Dead)
Shader: VertexLitGeneric
Prevents the model's material from being tinted by $color2 or rendercolor.
$notint<boolean> (only in Counter-Strike: Global OffensivePortal 2: Community Edition)
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