Lightmapped 4WayBlend: Difference between revisions
Deprecated (talk | contribs) (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) |
(Add Garry's Mod to the list of supported games) |
||
(29 intermediate revisions by 12 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{this is a|pixel shader|name=Lightmapped_4WayBlend|game2=Garry's Mod|game1=Counter-Strike: Global Offensive|game=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 {{ent|WorldVertexTransition}}. If you want to use an envmap and have masking then you should use the alpha channels of the base textures and {{ent|$basealphaenvmapmask}}. This shader does '''not''' support {{ent|$normalmapalphaenvmapmask}} in {{csgo}}. You can use an {{ent|$envmapmask}} texture, but you'll have to hand paint it to match what you want on the blended result. | The first 2 textures can have bumpmaps like {{ent|WorldVertexTransition}}. If you want to use an envmap and have masking then you should use the alpha channels of the base textures and {{ent|$basealphaenvmapmask}}. This shader does '''not''' support {{ent|$normalmapalphaenvmapmask}} in {{csgo}}. You can use an {{ent|$envmapmask}} texture, but you'll have to hand paint it to match what you want on the blended result. | ||
Line 6: | Line 6: | ||
{{note|This shader '''only''' works on displacements.}} | {{note|This shader '''only''' works on displacements.}} | ||
{{note|This shader | {{note|In {{bms|4}}, this shader support 4 bumpmaps.}} | ||
{{Warning|This shader does not support <code>$normalmapalphaenvmapmask</code> in {{csgo}} | {{note|This shader wasn't supposed to be used with moving brushes, since textures doesn't move with brush. [https://www.youtube.com/watch?v{{=}}Wqg7Ti59Fos Example] of how it looks with moving brushes.}} | ||
{{Warning|This shader does not support <code>$normalmapalphaenvmapmask</code> in {{csgo|4}} but it does in {{bms|4}}.}} | |||
{{bug|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.}} | {{bug|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.|tested={{p2ce}}}} | ||
{{bug|hidetested=1|In {{bms|4}} this shader do not show up correctly in Hammer's "3D Shaded Textured Polygons" view. Displacements have a rainbow effect overlaid onto them and the textures show up wrongly. The only way to solve this is to switch the view to "3D Textured", without shading. | |||
{{expand|title=Example of how it looks.| | |||
<br> | |||
<gallery mode=nolines heights=590px widths=520px> | |||
File:4wayView1.jpg|"3D Shaded Textured Polygons". | |||
File:4wayView2.jpg|"3D Textured". | |||
</gallery> | |||
}} | |||
}} | |||
{{bug|This shader flickers on surfaces which is not displacement (only [[3D Textured]] window). [https://www.youtube.com/watch?v{{=}}xw4XrganASo Example] of how it looks.|tested={{bms}},{{p2ce}}}} | |||
==Example== | ==Example== | ||
Line 22: | Line 31: | ||
"$ssbump" "1" | "$ssbump" "1" | ||
"$bumpmap2" "brick_a_normal" | "$bumpmap2" "brick_a_normal" | ||
"$basenormalmap2" "nature/bnc_dirt_rocky_large_001_norm" //Only Black Mesa | |||
"$surfaceprop" "concrete" | "$surfaceprop" "concrete" | ||
"$texture2_lumstart" "0.0" | "$texture2_lumstart" "0.0" | ||
Line 58: | Line 68: | ||
== Controlling Blending == | == Controlling Blending == | ||
[[ | [[File:SculptBlendDialog 4WayBlend.jpg|thumb|right|250px|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 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. | ||
Line 73: | Line 83: | ||
The lumstart and lumend parameters adjust the luminance value into a usable range with a [http://en.wikipedia.org/wiki/Smoothstep smoothstep]. | The lumstart and lumend parameters adjust the luminance value into a usable range with a [http://en.wikipedia.org/wiki/Smoothstep smoothstep]. | ||
{{codeblock|1=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. | You can think of this as adjusting the contrast of the luminance. In general, you need more contrast to get a more interesting blend. | ||
Line 95: | Line 106: | ||
The resulting luminance is used to modulate the vertex blend value with this formula: | The resulting luminance is used to modulate the vertex blend value with this formula: | ||
{{codeblock|1=blend = vertexblend * luminance + vertexblend}} | |||
The vertexblend is what you paint using the blend tool in hammer. | The vertexblend is what you paint using the blend tool in hammer. | ||
Line 105: | Line 117: | ||
Finally, the result of that formula is adjusted by another [http://en.wikipedia.org/wiki/Smoothstep smoothstep] with the blendstart and blendend parameters. | Finally, the result of that formula is adjusted by another [http://en.wikipedia.org/wiki/Smoothstep smoothstep] with the blendstart and blendend parameters. | ||
{{codeblock|1=blend = smoothstep( blendstart, blendend, blend )}} | |||
You can think of this as adjusting the sharpness of the blend. | You can think of this as adjusting the sharpness of the blend. | ||
Line 116: | Line 129: | ||
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 <code>1</code> to <code>4</code> 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. | 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 <code>1</code> to <code>4</code> 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. | ||
{{ | {{MatParamDef|$basetexture|to=$basetexture4|texture|See {{ent|$basetexture}}. Defines the [[albedo]] texture for a given layer.}} | ||
{{ | {{MatParamDef|$surfaceprop|to=$surfaceprop4|property|See {{ent|$surfaceprop}}. Defines the type of surface and its properties for a given layer.}} | ||
{{ | {{MatParamDef|$surfacepropalpha|property|{{Todo|What is this?}}}} | ||
{{ | {{MatParamDef|$surfacepropalphafilter|float|{{Todo|What is this?}}}} | ||
{{ | {{MatParamDef|$bumpmap|to=$bumpmap2|texture|See {{ent|$bumpmap}}. Defines the bump map for a given layer. Only 2 bump maps are supported.}} | ||
{{ | {{MatParamDef|$ssbump|bool|See {{ent|$ssbump}}. Defines whether or not the bumpmap(s) is/are self-shadowing.}} | ||
{{ | {{MatParamDef|$basenormalmap2|to=$basenormalmap4|texture|{{Todo|What is the difference between these and <code>$bumpmap2</code> to <code>$bumpmap4</code>?}}|only={{bms}}}} | ||
{{ | {{MatParamDef|$seamless_scale|float|See {{ent|$seamless_scale}}. Mitigates displacement texture stretching across the whole material.}} | ||
{{ | {{MatParamDef|$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.}} | ||
{{ | {{MatParamDef|$texture1_lumend|to=$texture4_lumend|normal| | ||
: {{note|A [http://en.wikipedia.org/wiki/Smoothstep smoothstep] operation is performed on the luminance of the texture, like so: <code>smoothstep(lumstart, lumend, [[luminanceof]](texture))</code>.}}}} | : {{note|A [http://en.wikipedia.org/wiki/Smoothstep smoothstep] operation is performed on the luminance of the texture, like so: <code>smoothstep(lumstart, lumend, [[luminanceof]](texture))</code>.}}}} | ||
{{ | {{MatParamDef|$texture1_uvscale|to=texture4_uvscale|vector2|Sets the scale of the UV. | ||
: {{note|Base texture is assumed to be 512x512px, larger textures will be scaled to fit 512x512.}} | : {{note|Base texture is assumed to be 512x512px, larger textures will be scaled to fit 512x512.}} | ||
: {{note|Changing UV scale of the base texture will scale all other textures as well, and can be compensated for by scaling other textures in the opposite direction.}}}} | : {{note|Changing UV scale of the base texture will scale all other textures as well, and can be compensated for by scaling other textures in the opposite direction.}}}} | ||
{{ | {{MatParamDef|$texture2_blendstart|to=$texture4_blendstart|normal|Used with <code>$texture2_blendend</code> to <code>$texture4_blendend</code> to define the blend range in a given layer.}} | ||
{{ | {{MatParamDef|$texture2_blendend|to=texture4_blendend|normal| | ||
: {{note|A [http://en.wikipedia.org/wiki/Smoothstep smoothstep] operation is performed on the blend, like so: <code>smoothstep(blendstart, blendend, blend)</code>.}}}} | : {{note|A [http://en.wikipedia.org/wiki/Smoothstep smoothstep] operation is performed on the blend, like so: <code>smoothstep(blendstart, blendend, blend)</code>.}}}} | ||
{{ | {{MatParamDef|$texture2_blendmode|to=$texture4_blendmode|int|Defines the blend mode for a given layer. You can choose between normal blending by setting it to 0, the default, or modulate 2x blending by setting it to 1.}} | ||
{{ | {{MatParamDef|$texture2_bumpblendfactor|to=$texture4_bumpblendfactor|normal|Defines how much the [[$bumpmap]] is shown for a given layer. | ||
: {{note|If the material has a <code>$bumpmap</code> to <code>$bumpmap4</code> defined, then this parameter is ignored. Instead the bumpmaps blend the same as they would in [[WorldVertexTransition]].}}}} | : {{note|If the material has a <code>$bumpmap</code> to <code>$bumpmap4</code> defined, then this parameter is ignored. Instead the bumpmaps blend the same as they would in [[WorldVertexTransition]].}}}} | ||
{{ | {{MatParamDef|$detail|texture|See {{ent|$detail}}. Defines a detail texture for the whole material.}} | ||
{{MatParamDef|$detailblendfactor|to=$detailblendfactor4|normal|See <code>[[$detail#$detailblendfactor <normal>|$detailblendfactor]]</code>. Specifies the blend amount of the <code>$detail</code> texture for a given layer.}} | |||
{{ | {{MatParamDef|$lumblendfactor2|to=$lumblendfactor4|normal|Defines luminance value to use for blending for a given layer. | ||
{{ | |||
: {{note|This is choosing between the luminance of the given layer and the inverse of the blended luminance of the layers below it using a lerp: <code>lerp( 1 - blended_lum_of_layers_below, lum_of_current_layer, lumblendfactor )</code>}}}} | : {{note|This is choosing between the luminance of the given layer and the inverse of the blended luminance of the layers below it using a lerp: <code>lerp( 1 - blended_lum_of_layers_below, lum_of_current_layer, lumblendfactor )</code>}}}} | ||
== See also == | == See also == | ||
* {{ent|LightmappedGeneric}} | |||
* | * {{ent|WorldVertexTransition}} | ||
* | * {{ent|Multiblend}} | ||
* | *[https://dev.wallworm.com/document/221/using_4way_blends.html Creating and Using 4way Blend in 3ds Max] | ||
*[ | * {{ent|$moss_enable}} | ||
* {{ent|$specmap_texture}} |
Latest revision as of 15:24, 5 September 2025
Lightmapped_4WayBlend
is a Pixel shader available in Black Mesa,
Counter-Strike: Global Offensive, and
Garry's Mod. 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 . 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 for the map cs_insertion.





$normalmapalphaenvmapmask
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" "$basenormalmap2" "nature/bnc_dirt_rocky_large_001_norm" //Only Black Mesa "$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 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.
Luminance Adjust
The lumstart and lumend parameters adjust the luminance value into a usable range with a smoothstep.
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 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.
Vertex Blend Modulate
The resulting luminance is used to modulate the vertex blend value with this formula:
The vertexblend is what you paint using the blend tool in hammer.
Blend Adjust
Finally, the result of that formula is adjusted by another smoothstep with the blendstart and blendend parameters.
You can think of this as adjusting the sharpness of the blend.
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.
$bumpmap2
to $bumpmap4
?$texture1_lumend
to $texture4_lumend
to adjust the luminance range used to modulate blending.Note:A smoothstep operation is performed on the luminance of the texture, like so:
smoothstep(lumstart, lumend, luminanceof(texture))
.
Note:Base texture is assumed to be 512x512px, larger textures will be scaled to fit 512x512.
Note:Changing UV scale of the base texture will scale all other textures as well, and can be compensated for by scaling other textures in the opposite direction.
$texture2_blendend
to $texture4_blendend
to define the blend range in a given layer.Note:A smoothstep operation is performed on the blend, like so:
smoothstep(blendstart, blendend, blend)
.
Note:If the material has a
$bumpmap
to$bumpmap4
defined, then this parameter is ignored. Instead the bumpmaps blend the same as they would in WorldVertexTransition.
$detailblendfactor
. Specifies the blend amount of the $detail
texture for a given layer.Note:This is choosing between the luminance of the given layer and the inverse of the blended luminance of the layers below it using a lerp:
lerp( 1 - blended_lum_of_layers_below, lum_of_current_layer, lumblendfactor )