Difference between revisions of "$blendmodulatetexture"

From Valve Developer Community
Jump to: navigation, search
m (Although TF2 is on Source 2013, it does not appear to be compatable with $detail there either.)
m (linked tf2, made that one line a tip)
 
(8 intermediate revisions by 7 users not shown)
Line 3: Line 3:
 
[[File:Blendmod_mockup.jpg|thumb|250px|A custom blend modulation mask (all channels) side-by-side its affected texture rendered in-game.]]
 
[[File:Blendmod_mockup.jpg|thumb|250px|A custom blend modulation mask (all channels) side-by-side its affected texture rendered in-game.]]
  
'''<code>$blendmodulatetexture</code>''' is a [[material]] parameter for the <code>[[WorldVertexTransition]]</code> shader. It changes the transition between the textures from a smooth, linear gradient to one "stamped" with a pattern.
+
{{Shaderparam|$blendmodulatetexture|since=Source 2006|shader1=WorldVertexTransition}} It changes the transition between the textures from a smooth, linear gradient to one "stamped" with a pattern.
  
You should use <code>$blendmodulatetexture</code> wherever possible, as the improvement in visual quality is immense!
+
{{tip|You should use <code>$blendmodulatetexture</code> wherever possible, as the improvement in visual quality is immense!}}
  
 
== Caveats ==
 
== Caveats ==
  
 
* Incompatible with [[$normalmapalphaenvmapmask]] (use [[$envmapmask]] instead).
 
* Incompatible with [[$normalmapalphaenvmapmask]] (use [[$envmapmask]] instead).
* In Source 2006/2007 and Team Fortress 2, incompatible with [[$basetexturetransform]] and [[$detail]].
+
* In Source 2006/2007 and {{Game link|Team Fortress 2}}, incompatible with [[$basetexturetransform]] and [[$detail]].
 
* In Source 2006, incompatible with [[$envmaptint]] and [[$envmapmask]].
 
* In Source 2006, incompatible with [[$envmaptint]] and [[$envmapmask]].
* Does not work underwater; when viewed through water, the textures will blend as if $blendmodulatetexture were not used.
+
* In {{Game link|Alien Swarm}}, modulation textures are not aligned correctly. Use <code>$blendmasktransform "center .5 .5 scale 1 -1 rotate 90 translate 0 0"</code> to fix them up.
* Does not display correctly when illuminated with player's flashlight in {{hl2}} [[Half-Life 2]].
+
 
* {{bug|{{as}} In [[Alien Swarm]], modulation textures are not aligned correctly. Use <code>$blendmasktransform "center .5 .5 scale 1 -1 rotate 90 translate 0 0"</code> to fix them up.}}
+
In some cases, textures will blend as if $blendmodulatetexture were not used:
 +
 
 +
* Does not display when viewed through water. {{todo|Only in earlier games?}}
 +
* Does not display when illuminated with player's flashlight in {{Game link|Half-Life 2}}. This is fixed in {{Game link|Mapbase}}.
 +
* Does not display in the Hammer Editor in most games. Known exceptions include {{Game link|Counter-Strike: Global Offensive}}, {{Game link|Portal 2}}, {{Game link|Garry's Mod}}, and {{Game link|Mapbase}}.
  
 
== Parameters ==
 
== Parameters ==
  
; <code>$blendmodulatetexture <path></code>
+
{{MatParam|$blendmodulatetexture|texture|The modulation texture for the blending. See below for more details.}}
: Path to a blend modulate texture. See below for more details.
+
{{MatParam|$blendmasktransform|matrix|Transforms the modulation texture before use in the material.
; <code>$blendmasktransform <matrix></code>
+
{{VMT UVtransform}}|dx9=1}}
: Transforms the modulation texture before use in the material. Requires DirectX 9.
+
 
{{VMT UVtransform}}
+
 
 +
{{MatParam|$maskedblending|bool|{{TODO}}: Appears to invert the blending effect}}
  
== Blend modulate textures ==
+
== Blend Modulation Textures ==
  
 
{{tip|The best way to create a modulation texture is to import the two [[albedo]]s to an image editor as layers, and create an alpha channel there by hand.}}
 
{{tip|The best way to create a modulation texture is to import the two [[albedo]]s to an image editor as layers, and create an alpha channel there by hand.}}

Latest revision as of 20:08, 2 July 2020

Without vs With. The technique was first used in Day of Defeat's snow maps, such as Kalt.
The green channel of DOD's ground\snowblendtexture.
A custom blend modulation mask (all channels) side-by-side its affected texture rendered in-game.

$blendmodulatetexture is a material shader parameter available in all Source games since <Source><Source> Source 2006 for WorldVertexTransition. It changes the transition between the textures from a smooth, linear gradient to one "stamped" with a pattern.

Tip:You should use $blendmodulatetexture wherever possible, as the improvement in visual quality is immense!

Caveats

In some cases, textures will blend as if $blendmodulatetexture were not used:

Parameters

$blendmodulatetexture <texture>
The modulation texture for the blending. See below for more details.
$blendmasktransform <matrix>  (DX9+)
Transforms the modulation texture before use in the material.
The default position is "center .5 .5 scale 1 1 rotate 0 translate 0 0".
  1. center defines the point of rotation. Only useful if rotate is being used.
  2. scale fits the texture into the material the given number of times. '2 1' is a 50% scale in the X axis.
  3. rotate rotates the texture counter-clockwise in degrees. Accepts any number, including negatives.
  4. translate shifts the texture by the given numbers. '.5' will shift it half-way.
Note:All values must be included!
Bug: Scaling the texture may cause odd issues where the Texture Lock tool in Hammer will not actually lock the texture in place.
Bug: Rotating textures applied on brushes will rotate around the map origin (confirm: Orangebox engine only?). A fix for this is to change the center position in the VMT to the brush's origin.


$maskedblending <boolean>
To do: Appears to invert the blending effect

Blend Modulation Textures

Tip:The best way to create a modulation texture is to import the two albedos to an image editor as layers, and create an alpha channel there by hand.

Only two colour channels are read from the texture:

Green
Biases in favor of $basetexture; high-value areas will be the most resistant to modulation. 128 is normal.
The idea is to paint noise and patterns into this channel, so that the edge between the two textures becomes irregular. Valve's snow texture (see right) has lots of ragged edges in the green channel, and even some bootprints. There are also lines painted along the edges of the albedo's bricks that give them a tendency to have snow along their edges.
Red
Sharpens. 0 makes the transition binary, 255 effectively disables modulation.
The red channel of Valve's snow modulation texture is a constant 99, which produces a fairly sharp falloff. Using different values in different places has the potential to produce a more complex effect.

There is not always a need for the texture to be high resolution - high frequency blends can be produced from low-res textures.