$translucent

From Valve Developer Community
Revision as of 12:34, 18 March 2013 by XFunc CaRteR (talk | contribs)
Jump to navigation Jump to search

The $translucent VMT command specifies that the material should be partially see-through. The alpha channel of $basetexture is used to decide translucency per-pixel.

Any object that has a $translucent material does not affect VIS, and can be seen through by NPCs from any angle.

VMT syntax example

$translucent <bool>
LightmappedGeneric
{
	$basetexture glass\window001a
	$translucent 1
}

Additional parameters

$additive <bool>
Add the material's colour values to the existing image, instead of performing a multiplication. This means, among other things, that the material will always brighten the world. This is useful for effects like volumetric dust, light sprites, etc...

Caveats

Flickering and reversed depth

Translucency can sometimes cause a material to flicker, or cause sorting issues with nearby surfaces. In both cases consider using $alphatest instead of $translucent when this happens. It drastically lowers quality, but will usually resolve the issue and is much faster to draw.


Translucent2p.png


Unlike $translucent which allows for varying degrees of opacity, alpha testing does not - portions of your texture are either 'on' or 'off'. $alphatestreference, a normal parameter, controls the 'fuzziness' of the transparency masking (Using lower values like .01 will result in a more blurred and fuzzy edge while a value of .99 will be extremely sharp.) Since alpha testing is cheaper than $translucent, this can be used to achieve a similar effect to materials using the $translucent parameter at reduced cost.

Compatibility with other effects

Certain shader parameters (such as $envmap) can disable translucency. If you are having trouble getting it to work, try commenting out other parts of the material.

Filtering borders

Texture filtering will blend nearby pixels together even if some of of them are entirely transparent. This can create unwanted outlining effects if sudden drop-offs in alpha coincide with drop-offs in colour, which may well happen when the alpha channel reaches zero and you stop being able to see the pixels.

An unwanted filtering border.

To resolve this issue, simply blend the colours of your image slightly beyond where the alpha channel drops off. This can be easily achieved by duplicating the translucent layer and smudging it into the relevant areas.

Fixing filtering borders.

(Unfortunately for users of The GIMP, the program will automatically remove colour information for pixels with an alpha of zero whenever layers are combined. The developers are aware of the the problems such behaviour creates but do not intend to change it.)

Trouble Achieving Transparency In Materials

Making a from-scratch material transparent seems to be tempermental. Some tips that may help:

- When making a Targa in Photoshop, compress as 32-bit, but without RLE selected. - Don't create layer style effects in Photoshop then save to Targa, even if you rastarize the layer (these may bring low-level pixel artefacts that interfere with transparency). Instead create your imagery by hand, or possibly exporting to/saving as a .png (from Illustrator or Photoshop) then reimporting to Photoshop and saving as a fresh Targa. - You may need to ensure that actual non-transparent pixels are touching one or more of the actual sides of your material. If no opaque or semi-transparent pixeles touches any sides VTF Edit (or something in the guts of the system) may decide to give your material an opaque border.

See also