Difference between revisions of "$translucent"

From Valve Developer Community
Jump to: navigation, search
(Filtering borders)
m (Update info. As of writing this (and likely for a long time beforehand), gmod has supported $envmap with $translucent (at least on VertexLitGeneric))
 
(8 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
{{toc-right}}
 
{{toc-right}}
  
The <code>[[$translucent]]</code> [[VMT]] command specifies that the material should be partially see-through. The [[alpha channel]] of <code>[[$basetexture]]</code> is used to decide translucency per-pixel.
+
{{Shaderparam|$translucent}} It specifies that the material should be partially see-through. The [[alpha channel]] of the {{ent|$basetexture}} is used to decide translucency per-pixel.
  
 
Any object that has a <code>$translucent</code> material does not affect [[VIS]], and can be seen through by NPCs from any angle.
 
Any object that has a <code>$translucent</code> material does not affect [[VIS]], and can be seen through by NPCs from any angle.
 +
 +
{{note|Enabling translucency will completely disable shadows made by [[env_projectedtexture|Projected textures]] for the texture. Either separate the opaque and solid parts of the texture, or use {{ent|$alphatest}} instead.}}
 +
  
 
==VMT syntax example==
 
==VMT syntax example==
Line 17: Line 20:
 
==Additional parameters==
 
==Additional parameters==
  
; <code>$additive <bool></code>
+
{{MatParam|$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...}}
: 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 ==
 
== Caveats ==
Line 30: Line 32:
  
  
Unlike <code>$translucent</code> which allows for varying degrees of opacity, alpha testing does not - portions of your texture are either 'on' or 'off'. <code>'''$alphatestreference'''</code>, a normal parameter, controls the filtering of the transparency masking (Using lower values like .01 will result in a more blurred edge while a value of .99 will be extremely sharp.) Since alpha-testing is cheaper than <code>$translucent</code>, this can be used to achieve a similar effect to materials using the <code>$translucent</code> parameter at reduced cost. Using <code>'''$allowalphatocoverage'''</code> will enable antialiasing of alpha-tested textures, giving them much softer edges. Reference values won't affect the normal appearance of a texture with this enabled, however it will have an effect if the flashlight is shone on the surface.
+
Unlike <code>$translucent</code> which allows for varying degrees of opacity, alpha testing does not - portions of your texture are either 'on' or 'off'. <code>'''$alphatestreference'''</code>, a normal parameter, controls the filtering of the transparency masking (Using lower values like .01 will result in a more blurred edge while a value of .99 will be extremely sharp.) Since alpha-testing is cheaper than <code>$translucent</code>, this can be used to achieve a similar effect to materials using the <code>$translucent</code> parameter at reduced cost. Using <code>'''$allowAlphaToCoverage'''</code> will enable antialiasing of alpha-tested textures, giving them much softer edges. Reference values won't affect the normal appearance of a texture with this enabled, however it will have an effect if the flashlight is shone on the surface.
 +
 
 +
{{note|The effect of <code>'''$allowAlphaToCoverage'''</code> will only be visible if the user has MSAA enabled.}}
  
 
=== Compatibility with other effects ===
 
=== Compatibility with other effects ===
Certain shader parameters (such as <code>[[$envmap]]</code>) can disable translucency. If you are having trouble getting it to work, try commenting out other parts of the material.
+
Certain shader parameters (such as {{ent|$envmap}}) disable translucency. If you are having trouble getting it to work, try commenting out other parts of the material.
 +
 
 +
{{note|{{GameName|csgo}} and {{GameName|gmod}} support $envmap with translucency.}}
  
 
=== Filtering borders ===
 
=== Filtering borders ===
Line 45: Line 51:
 
[[Image:Filterborder fixed.jpg|center|Fixing filtering borders.]]
 
[[Image:Filterborder fixed.jpg|center|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 [http://bugzilla.gnome.org/show_bug.cgi?id=411599#c4 but do not intend to change it].) as a work-around for this, you could give those pixels an alpha value of one instead.
+
('''For users of older versions of [[The GIMP]],''' the program will '''automatically remove colour information for pixels with an alpha of zero''' whenever layers are combined. As a work-around for this, you could give those pixels an alpha value of one instead.
 +
 
 +
As of GIMP 2.8.14, pixels with an alpha value of 0 retain their color information when saved as a tga.
  
 
== See also ==
 
== See also ==
Line 52: Line 60:
 
*<code>[[$distancealpha]]</code>, for vector-like alpha edges
 
*<code>[[$distancealpha]]</code>, for vector-like alpha edges
 
*<code>[[$vertexalpha]]</code>
 
*<code>[[$vertexalpha]]</code>
 +
*<code>[[$alphatest]]</code>, for binary opacity.
  
 
[[Category:List of Shader Parameters|T]]
 
[[Category:List of Shader Parameters|T]]

Latest revision as of 15:40, 11 February 2021

$translucent is a material shader parameter available in all Source games. It specifies that the material should be partially see-through. The alpha channel of the $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.

Note.png Note: Enabling translucency will completely disable shadows made by Projected textures for the texture. Either separate the opaque and solid parts of the texture, or use $alphatest instead.


VMT syntax example

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

Additional parameters

$additive <boolean>
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. It will also cast flashlight shadows, unlike translucents.


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 filtering of the transparency masking (Using lower values like .01 will result in a more blurred 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. Using $allowAlphaToCoverage will enable antialiasing of alpha-tested textures, giving them much softer edges. Reference values won't affect the normal appearance of a texture with this enabled, however it will have an effect if the flashlight is shone on the surface.

Note.png Note: The effect of $allowAlphaToCoverage will only be visible if the user has MSAA enabled.

Compatibility with other effects

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

Note.png Note: <Counter-Strike: Global Offensive> Counter-Strike: Global Offensive and <Garry's Mod> Garry's Mod support $envmap with translucency.

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.

(For users of older versions of The GIMP, the program will automatically remove colour information for pixels with an alpha of zero whenever layers are combined. As a work-around for this, you could give those pixels an alpha value of one instead.

As of GIMP 2.8.14, pixels with an alpha value of 0 retain their color information when saved as a tga.

See also