$distancealpha
$distancealpha  is a   material shader parameter  available in all  Source games since
 Source games since  Source 2007. It is a cheap edge filtering technique for raster images. It takes advantage of 3D hardware's well-established texture filtering methods by defining a series of alpha channel thresholds above, below, or between which effects can be applied. This feature was added to the
 Source 2007. It is a cheap edge filtering technique for raster images. It takes advantage of 3D hardware's well-established texture filtering methods by defining a series of alpha channel thresholds above, below, or between which effects can be applied. This feature was added to the  Source engine with the release of
 Source engine with the release of  Source 2007. It's great for UI elements, foliage, chain link fences, grates, and more.
 Source 2007. It's great for UI elements, foliage, chain link fences, grates, and more.
 Bug:This shader reads the image in sRGB space rather than linear space by default, which throws off the calculations and leads to wavy-like edges and wrong opacity. To fix this, always use
Bug:This shader reads the image in sRGB space rather than linear space by default, which throws off the calculations and leads to wavy-like edges and wrong opacity. To fix this, always use $gammacolorread 1 with this technique (only available on UnlitGeneric). Bug:In
Bug:In 
 On VertexLitGeneric
 On VertexLitGeneric $distancealpha does not work with any of : $envmap, $bumpmap, $selfillum, $selfillum_envmapmask_alpha, $seamless_detail, $blendtintbybasealpha Warning:(only in
Warning:(only in  )
) $distancealpha and parameters that come with it, don't appear to exist for VertexLitGeneric and LightmappedGeneric Shaders.- Advantages
- Vector-like edges on raster images even during extreme zoom.
- Far faster than adaptive AA.
- Disadvantages
- Effects look extremely pixelated from grazing angles in some situations (might be related to brush application?).
For (lots) more detail, see this SIGGRAPH paper.
 Bug:Distance alpha materials are not rendered correctly in Hammer's 3D view.
Bug:Distance alpha materials are not rendered correctly in Hammer's 3D view.Texture Creation
Distance alpha source textures are created at a very high resolution. Valve use 4096x4096 images, but the SDK's build of VTEX will crash if you pass it anything over 2048x2048.
 Tip:
Tip: Team Fortress 2: Patched VTEX can be downloaded here that supports 4096x4096 TGA textures.
 Team Fortress 2: Patched VTEX can be downloaded here that supports 4096x4096 TGA textures.
The image should otherwise be completely normal, except that the alpha channel should avoid gradients (you'll be able to re-construct them with the shader).
To compile the texture, you must use VTEX; third-party tools (including VTFEdit and VTFEdit Reloaded) don't support distance alpha yet.
Your .txt file should look something like this:
// Enable distance alpha compiling alphatodistance 1 // Scale the image down to 1/nth its original size. '8' takes 2048 down to 256 reduce 8 // Size of 'spread' zone between alpha values of 0 and 1. This is the area the shader works with. // Bear in mind that higher numbers exponentially increase texture compile time! distancespread 4 // To prevent artefacting: nomip 1 nolod 1 nocompress 1
Material Creation (class_spy_outline)
 
  This material is displayed in  Team Fortress 2 when a Spy player gains or loses a disguise. Despite the fact that it fills the entire screen at any resolution, its texture (seen right) is only 256 pixels square.
 Team Fortress 2 when a Spy player gains or loses a disguise. Despite the fact that it fills the entire screen at any resolution, its texture (seen right) is only 256 pixels square.
UnlitGeneric { $basetexture hud\class_spy_outline $translucent 1 $distancealpha 1 $softedges 1 $edgesoftnessstart .5 $edgesoftnessend .46 $scaleedgesoftnessbasedonscreenres 1 $glow 1 $glowcolor "[0 0 0]" $glowalpha .4 $glowstart .1 $glowend .5 //$glowx .98 //$glowy .98 $vertexcolor 1 $vertexalpha 1 $no_fullbright 1 $ignorez 1 }
The most interesting commands here are the starts and ends—their values determine the range of alpha values across which each effect is applied.
- $softedgesis applied from 50% to 46% opacity
- $glowis applied from 10% to 50% opacity
By setting $glowcolor to black and $glowalpha to 40%, the glow effect is made to look like a shadow.
Effects
$softedges
Fades out all color channels from $edgesoftnessstart (opaque edge) to $edgesoftnessend (transparent edge).
 Bug:In
Bug:In 
 On LightmappedGeneric and WorldVertexTransition
 On LightmappedGeneric and WorldVertexTransition $softedges does not work with any of : $seamless_scale, $selfillum, $lightwarptexture, $bumpmap, $bumpmap2, $basetexture2, $blendmodulatetexture- $scaleedgesoftnessbasedonscreenres <bool>
- Todo: Describe
$glow
Creates a monotone gradient from $glowstart (opaque edge) to $glowend (transparent edge).
- $glowcolor <RGB>
- Color of glow.
- $glowalpha <normal>
- Opacity of glow.
- $glowx <normal>
- $glowy <normal>
- Offsets glow; good for shadow effects.
- $glowstart <normal>
- $glowend <normal>
- Alpha channel thresholds. $glowstartis full intensity,$glowendis where it becomes invisible.
$outline
The same as glow, but with the added option of defining how sharp each edge appears.
 Bug:In
Bug:In 
 On LightmappedGeneric and WorldVertexTransition
 On LightmappedGeneric and WorldVertexTransition $outline does not work with any of : $seamless_scale, $selfillum, $lightwarptexture, $bumpmap, $bumpmap2, $basetexture2, $blendmodulatetexture- $outlinecolor <RGB>
- Color of outline.
- $outlinealpha <normal>
- Opacity of outline.
- $outlinestart0 <normal>
- $outlinestart1 <normal>
- Defines the outer (i.e., low alpha) edge of the outline. Any gap between the two values will become a gradient.
- 0 is "outer outer," while 1 is "inner outer."
- $outlineend0 <normal>
- $outlineend1 <normal>
- Defines the inner (i.e., high alpha) edge of the outline.
- 0 is the "outer inner," while 1 is the "inner inner."  Note:The two values must differ by at least 0.02 or the entire outline will disappear! Note:The two values must differ by at least 0.02 or the entire outline will disappear!
- $scaleoutlinesoftnessbasedonscreenres 1
- Scales the outline's softness based on the user's screen resolution.



























