Lightmapped 4WayBlend: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Changed to use Shader multi, MatParam, and ent templates were applicable, rewrote some parts, added that Black Mesa also has this shader, added new parameters)
(Revamped for MatParam changes, corrected bumpmap information)
Line 6: Line 6:


{{note|This shader '''only''' works on displacements.}}
{{note|This shader '''only''' works on displacements.}}
{{note|This shader is '''only''' available in {{csgo}} and {{bms}} as of June 2019.}}
{{Warning|This shader does not support <code>$normalmapalphaenvmapmask</code> in {{csgo}}. It does in {{bms}}.}}
{{Warning|This shader does not support <code>$normalmapalphaenvmapmask</code> in {{csgo}}. It does in {{bms}}.}}
: {{Todo|Document if {{bms}}'s version of the shader has any more differences from {{csgo}}'s.}}
: {{Todo|Document if {{bms}}'s version of the shader has any more differences from {{csgo}}'s.}}
Line 120: Line 119:
{{MatParam|$surfacepropalpha|property|{{Todo|What is this?}}}}
{{MatParam|$surfacepropalpha|property|{{Todo|What is this?}}}}
{{MatParam|$surfacepropalphafilter|float|{{Todo|What is this?}}}}
{{MatParam|$surfacepropalphafilter|float|{{Todo|What is this?}}}}
{{MatParam|$bumpmap|to=$bumpmap4|texture|See {{ent|$bumpmap}}. Defines the bumpmap for a given layer.}}
{{MatParam|$bumpmap|to=$bumpmap2|texture|See {{ent|$bumpmap}}. Defines the bump map for a given layer. Only 2 bump maps are supported.}}
{{MatParam|$ssbump|bool|See {{ent|$ssbump}}. Defines whether or not the bumpmap is self-shadowing.}}
{{MatParam|$ssbump|bool|See {{ent|$ssbump}}. Defines whether or not the bump map is self-shadowing.}}
{{MatParam|$basenormalmap2|to=$basenormalmap4|texture|{{Todo|What is the difference between these and <code>$bumpmap2</code> to <code>$bumpmap4</code>?}}|only=BMS}}
{{MatParam|$basenormalmap2|to=$basenormalmap4|texture|{{Todo|What is the difference between these and <code>$bumpmap2</code> to <code>$bumpmap4</code>?}}|only={{bms}}}}
{{MatParam|$seamless_scale|float|See {{ent|$seamless_scale}}. Mitigates displacement texture stretching across the whole material.}}
{{MatParam|$seamless_scale|float|See {{ent|$seamless_scale}}. Mitigates displacement texture stretching across the whole material.}}
{{MatParam|$texture1_lumstart|to=$texture4_lumstart|normal|Used with <code>$texture1_lumend</code> to <code>$texture4_lumend</code> to adjust the luminance range used to modulate blending.}}
{{MatParam|$texture1_lumstart|to=$texture4_lumstart|normal|Used with <code>$texture1_lumend</code> to <code>$texture4_lumend</code> to adjust the luminance range used to modulate blending.}}

Revision as of 20:20, 22 April 2020

Lightmapped_4WayBlend is a material shader available in the following Source engine games: Counter-Strike: Global Offensive Counter-Strike: Global Offensive , Black Mesa Black Mesa . It is a shader that blends the vertices of a displacement surface between four different materials. It handles four at once by using mirrored sets of parameters with "2", "3", or "4" in their name.

The first 2 textures can have bumpmaps like WorldVertexTransition. If you want to use an envmap and have masking then you should use the alpha channels of the base textures and $basealphaenvmapmask. This shader does not support $normalmapalphaenvmapmask in Counter-Strike: Global Offensive. You can use an $envmapmask texture, but you'll have to hand paint it to match what you want on the blended result.

Being a replacement of the older Multiblend shader, it was introduced to Counter-Strike: Global Offensive for the map cs_insertion.

Note.pngNote:This shader only works on displacements.
Warning.pngWarning:This shader does not support $normalmapalphaenvmapmask in Counter-Strike: Global Offensive. It does in Black Mesa.
Todo: Document if Black Mesa's version of the shader has any more differences from Counter-Strike: Global Offensive's.
Icon-Bug.pngBug:This shader won't draw the painted blends you put in if Hammer's 3D View is set to "3D Shaded Textured Polygons", remember to set the 3D View back to "3D Textured" when painting your blends.  [todo tested in ?]

Example

Lightmapped_4WayBlend
{
    "$basetexture"              "brick_a"
    "$bumpmap"                  "brick_a_normal"
    "$texture1_lumstart"        "0.0"
    "$texture1_lumend"          "0.5"
"$basetexture2" "brick_a" "$ssbump" "1" "$bumpmap2" "brick_a_normal" "$surfaceprop" "concrete" "$texture2_lumstart" "0.0" "$texture2_lumend" "0.5" "$texture2_blendmode" "0" "$texture2_blendstart" "0.8" "$texture2_blendend" "0.9" "$texture2_uvscale" "[1.0 1.0]" "$texture2_bumpblendfactor" "0.7"
"$basetexture3" "brick_a_bottom_grime" "$texture3_blendmode" "0" "$texture3_uvscale" "[2.0 2.0]" "$texture3_lumstart" "0.0" "$texture3_lumend" "0.05" "$texture3_blendstart" "0.8" "$texture3_blendend" "1.0" "$texture3_bumpblendfactor" "0.7"
"$basetexture4" "brick_a_top_grime" "$texture4_blendmode" "0" "$texture4_uvscale" "[2.0 2.0]" "$texture4_lumstart" "0.0" "$texture4_lumend" "0.2" "$texture4_blendstart" "0.90" "$texture4_blendend" "0.99" "$texture4_bumpblendfactor" "0.3"
"$detail" "detail\noise_detail_01" "$detailscale" "[ 32 32 ]" "$detailblendfactor" "0.7" "$detailblendfactor2" "0.4" "$detailblendfactor3" "0.2" "$detailblendfactor4" "0.2"
"$lumblendfactor2" "0.5" "$lumblendfactor3" "0.7" "$lumblendfactor4" "0.4" }

Controlling Blending

The blend tools inside the displacement sculpt window.

The pattern of the blend is defined by Hammer's sculpt window blend tool (shown in the picture on the right). The texture preview in Hammer requires you to set up additional VMT files for each texture to show up in the dialog. Those are not used by the shader itself. The Alpha Blend and Color Blend features of this dialog are disabled when using 4WayBlend, they are only used by the Multiblend material.

The blend can be tuned between being a linear gradient and a more realistic look using the luminance of each basetexture adjusted by parameters. This is done using some simple math in the shader, and avoids requiring extra textures.

Source texture 1
Source texture 2
Source texture 3
Source texture 4
In game example of 4WayBlend.

Luminance Adjust

The lumstart and lumend parameters adjust the luminance value into a usable range with a smoothstep.

luminance = smoothstep( lumstart, lumend, luminanceof(basetexture) )

You can think of this as adjusting the contrast of the luminance. In general, you need more contrast to get a more interesting blend.

Luminance without any adjusting
lumstart = 0.0, lumend = 0.5
lumstart = 0.0, lumend = 0.2
Note.pngNote:You can invert the result by swapping the lumstart and lumend values. For example, if your texture is of dark tiles with a bright grout, then you probably want to use the inverse luminance so that the tiles drop out after the grout.

Luminance Blending

When blending a given layer, you can choose between using the luminance of that layer or the inverse of blended luminance of the layers below it. This is done with the lumblendfactor parameters.

lumblendfactor = 1.0
lumblendfactor = 0.5
lumblendfactor = 0.0

Vertex Blend Modulate

The resulting luminance is used to modulate the vertex blend value with this formula:

blend = vertexblend * luminance + vertexblend. 

The vertexblend is what you paint using the blend tool in hammer.

Blend without Luminance
Blend with Luminance

Blend Adjust

Finally, the result of that formula is adjusted by another smoothstep with the blendstart and blendend parameters.

blend = smoothstep( blendstart, blendend, blend )

You can think of this as adjusting the sharpness of the blend.

blendstart = 0.75, blendend = 1.0
blendstart = 0.90, blendend = 1.0

Parameters

Most of these parameters have counterparts that can be applied to the first, second, third or fourth layers of a material. For brevity's sake, this will be indicated by 1 to 4 where applicable. Note that a lack of 1 means that, if intended for use with the first layer, there should simply be no number in that place.

$basetexture $surfaceprop $surfacepropalpha $surfacepropalphafilter $bumpmap $ssbump $basenormalmap2 $seamless_scale $texture1_lumstart $texture1_lumend $texture1_uvscale $texture2_blendstart $texture2_blendend $texture2_blendmode $texture2_bumpblendfactor $detail $detailblendfactor2 $lumblendfactor2

See also