Alphatexture: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{this is a|shader parameter|internal=1<!--is there a better way to do this?-->|name=%alphatexture|game=Garry's Mod}}
{{toc-right}}{{this is a|shader parameter|internal=1<!--is there a better way to do this?-->|name=%alphatexture|game=Garry's Mod|game1=Mapbase}}
Used on [[static prop]]s when the prop is flagged for [[texture shadows]] and compiling [[VRAD]] with {{code|-textureshadows}}. The alpha channel of the specified VTF will be used instead of {{ent|$basetexture}}, even if {{ent|$alphatest}} and {{ent|$translucent}} are absent.
Used on [[static prop]]s when the prop is flagged for [[texture shadows]] and compiling [[VRAD]] with {{code|-textureshadows}}. The alpha channel of the specified VTF will be used instead of {{ent|$basetexture}}, even if {{ent|$alphatest}} and {{ent|$translucent}} are absent.


{{note|As this parameter is only used by VRAD, the VTF mentioned does not need to be shipped with the map if it is unused elsewhere.}}
{{tip|As this parameter is only used by VRAD, the VTF mentioned does not need to be shipped with the map if it is unused elsewhere.}}
{{todo|Implementing in custom VRAD; see [https://github.com/Yuis-Archives/source-sdk-2013_vs2022/commit/ea77f7d0172f70f06110b54bc83caf2c5919804d GitHub commit which was used in gmod feature request].}}
{{codenote|See [https://github.com/ValveSoftware/source-sdk-2013/pull/1150 this GitHub PR] for how to add this to a custom VRAD.<br>The source code for {{Mapbase|2}} 8.0 includes this implementation.}}


== Syntax ==
== Syntax ==
Line 13: Line 13:
}
}
</syntaxhighlight>
</syntaxhighlight>
== Potential usecases ==
{{code|%alphatexture}} is most useful for materials that are translucent enough for light to pass through, but are opaque to the human eye. Common materials that would exhibit this behavior are:
* Foliage such as leaves and grass
* Curtains, awnings, and umbrellas
* Paper
This parameter can be useful in certain other niche instances:
* Making the shadows for a given prop less dark, which can be useful if it uses {{cmd|$halflambert}} (or {{cmd|$phong}} without {{cmd|$phongdisablehalflambert}}).
* When {{cmd|$detailblendmode|4}} is used, as the shadows would then make more sense to be cast from $detail
* When {{cmd|$additive}} is used, as no alpha channel will be present and neither {{ent|$translucent}} nor {{ent|$alphatest}} are used
* When a shader such as {{cmd|Refract}} is used, as no alpha channel will be present and neither {{ent|$translucent}} nor {{ent|$alphatest}} are used, and {{ent|$basetexture}} won't be used as the [[diffuse]]
* If a shader such as {{cmd|Wireframe}} is used, as {{ent|$basetexture}} will not be present
* When {{cmd|$alpha}} is used, as [[VRAD]] doesn't account for it
* For creating a sharp high-resolution texture shadow without bloating the map's filesize, as the shadow-casting texture does not need to be shipped with the map.
== Workaround for other versions of VRAD ==
If mapping for a game that does not have an SDK that includes the source code to compile your own version of [[VRAD]] (ex: {{l4d2}} {{portal2}}), it is still possible to simulate the effect of {{code|%alphatexture}} by creating a separate {{cmd|$translucent}} material to use in VRAD only, and setting the alpha texture to that material's {{cmd|$basetexture}}. To avoid needing to swap VMTs every time the map is being compiled, the {{code|-insert_search_path}} parameter can be used with VRAD, which should take priority over the search paths declared in [[gameinfo.txt]].

Latest revision as of 09:54, 29 July 2025

%alphatexture is an internal material shader parameter available in Garry's Mod Garry's Mod and Mapbase Mapbase.

Used on static props when the prop is flagged for texture shadows and compiling VRAD with -textureshadows. The alpha channel of the specified VTF will be used instead of $basetexture, even if $alphatest and $translucent are absent.

Tip.pngTip:As this parameter is only used by VRAD, the VTF mentioned does not need to be shipped with the map if it is unused elsewhere.
Cpp.pngCode:See this GitHub PR for how to add this to a custom VRAD.
The source code for Mapbase Mapbase 8.0 includes this implementation.

Syntax

"VertexLitGeneric"
{
    $basetexture "models/props_custom/myprop_base"
    %alphatexture "models/props_custom/myprop_alpha"
}

Potential usecases

%alphatexture is most useful for materials that are translucent enough for light to pass through, but are opaque to the human eye. Common materials that would exhibit this behavior are:

  • Foliage such as leaves and grass
  • Curtains, awnings, and umbrellas
  • Paper

This parameter can be useful in certain other niche instances:

Workaround for other versions of VRAD

If mapping for a game that does not have an SDK that includes the source code to compile your own version of VRAD (ex: Left 4 Dead 2 Portal 2), it is still possible to simulate the effect of %alphatexture by creating a separate $translucent material to use in VRAD only, and setting the alpha texture to that material's $basetexture. To avoid needing to swap VMTs every time the map is being compiled, the -insert_search_path parameter can be used with VRAD, which should take priority over the search paths declared in gameinfo.txt.