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

Modulate: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Changed parameters of {{this is a}} to comply with the updated version. This action was performed by a bot.)
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 3: Line 3:
{{this is a|pixel shader|name=Modulate}} It modulates the colors of any pixels behind it.
{{this is a|pixel shader|name=Modulate}} It modulates the colors of any pixels behind it.


{{tip|This shader can be effectively used to fake various features that [[Source]] may not support, such as vertex coloring or [[lightmap]]ping on models, by creating a surface above the first one to modulate it.}}
By default, it acts like the "multiply" layer mode in image editors, where full white (#FFFFFF) means no modulation, and darker values will darken what's underneath. If {{code|$mod2x}} is used, it acts like the "overlay" layer mode instead, where 50% grey (#7F7F7F or #808080) means no modulation, and lighter or darker values will lighten or darken what's underneath respectively.
 
A practical application of this shader is to create [[env_tonemap_controller|bloom-boosting]] textures, to create fake eye adaptation inside interiors.
Other uses include faking various features that [[Source]] may not support, such as vertex coloring or [[lightmap]]ping on models, by creating a surface above the first one to modulate it.
   
   
==Description==
==Description==
[[File:Mod2x bloom.jpg|thumb|300px|Comparison of bloom boosting with $mod2x 1 + white basetexture and without]]
[[File:Mod2x_comparison.png|thumb|300px|Picture showing the difference between $mod2x 0 and 1.]]
[[File:Mod2x_comparison.png|thumb|300px|Picture showing the difference between $mod2x 0 and 1.]]
Accepts only the following parameters:
Accepts only the following parameters:
{{pre|<nowiki>
 
$basetexture             "texture" //Multiplies the color behind it with this surface's texture.
{{MatParamDef|$basetexture|texture|Modulates the color behind it with this surface's texture.}}
$mod2x                   "boolean"  //Doubles the modulation, making it appear brighter. 1 enables this, 0 disables. Disabled by default.
{{MatParamDef|$mod2x|boolean|Use [[DecalModulate]] blending instead of multiplication.
$nocull                   "boolean"  //Draws triangles from both sides, not just one. 1 enables this, 0 disables. Disabled by default.
:{{codenote|Standard multiplication is equivalent to a BlendFunc of [DestinationColor,Zero], and Mod2x is equivalent to a BlendFunc of [DestinationColor, SourceColor]}} }}
</nowiki>}}
{{MatParamDef|$nocull|boolean|Apply effect from through both sides of the polygon, instead of only through the front.}}


{{note|Does not accept any translucency parameters, including [[$alpha]], [[$alphatest]], [[$additive]] and [[$translucent]].}}
{{note|Does not accept any translucency parameters, including [[$alpha]], [[$alphatest]], [[$additive]] and [[$translucent]].}}

Latest revision as of 11:47, 23 August 2025

English (en)Translate (Translate)
GIF Animation showing "Modulate" shader in action.

Modulate is a Pixel shader available in all Source Source games. It modulates the colors of any pixels behind it.

By default, it acts like the "multiply" layer mode in image editors, where full white (#FFFFFF) means no modulation, and darker values will darken what's underneath. If $mod2x is used, it acts like the "overlay" layer mode instead, where 50% grey (#7F7F7F or #808080) means no modulation, and lighter or darker values will lighten or darken what's underneath respectively.

A practical application of this shader is to create bloom-boosting textures, to create fake eye adaptation inside interiors. Other uses include faking various features that Source may not support, such as vertex coloring or lightmapping on models, by creating a surface above the first one to modulate it.

Description

Comparison of bloom boosting with $mod2x 1 + white basetexture and without
Picture showing the difference between $mod2x 0 and 1.

Accepts only the following parameters:

Modulates the color behind it with this surface's texture.
Use DecalModulate blending instead of multiplication.
Cpp.pngCode:Standard multiplication is equivalent to a BlendFunc of [DestinationColor,Zero], and Mod2x is equivalent to a BlendFunc of [DestinationColor, SourceColor]
Apply effect from through both sides of the polygon, instead of only through the front.
Note.pngNote:Does not accept any translucency parameters, including $alpha, $alphatest, $additive and $translucent.

See also