This article's documentation is for anything that uses the Source engine. Click here for more information.

$lightwarptexture: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Clarification of the $bumpmap requirement & fix for $selfillumfresnel hyperlink)
(→‎Caveats: not a thing; works fine with just bumpmap)
 
(27 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{Language subpage}}
{{LanguageBar}}
{{Source topicon}}


[[File:Lightwarp snow.jpg|thumb|200px|The technique was first used in {{dods|2}}'s snow maps, such as Kalt.]]
[[File:Lightwarp snow.jpg|thumb|200px|The technique was first used in {{dods|2}}'s snow maps, such as Kalt.]]
[[File:Lightwarp heavy.png|thumb|150px|<code>$lightwarptexture</code> is a cornerstone of {{tf2|2}}'s illustrative character rendering.]]
[[File:Lightwarp heavy.png|thumb|150px|{{code|$lightwarptexture}} is a cornerstone of {{tf2|2}}'s illustrative character rendering.]]
[[File:Lightwarp BW.png|thumb|150px|Posterized color can be achieved, but lighting must be tightly controlled.]]
[[File:Lightwarp BW.png|thumb|150px|Posterized color can be achieved, but lighting must be tightly controlled.]]


{{Shaderparam|$lightwarptexture|dx9=1|since=Source 2006|shader1=VertexLitGeneric|shader2=LightmappedGeneric|shader3=WorldVertexTransition|shader4=EyeRefract}} It tints [[texel]]s depending on their brightness. It can be thought of as localized [[color correction]].
{{this is a|shader parameter|name=$lightwarptexture|shader=VertexLitGeneric|since=Source 2006|notitlechange=1|nocat=1|dx=dx95}} It tints [[texel]]s depending on their brightness. It can be thought of as localized [[color correction]].
 
{{Note|Also available for [[LightmappedGeneric]], [[WorldVertexTransition]], [[EyeRefract]].}}


== Caveats ==
== Caveats ==
{{Important|<code>$lightwarptexture</code> must be specified ''after'' all other textures, otherwise it will overwrite them.}}
{{Important|Make sure the texture is clamped in the VTF otherwise it will render incorrectly. Use '''Clamp S''' and '''Clamp T''' [[Texture flags|image flags]] for that.}}
{{Important|<code>$lightwarptexture</code> on {{ent|VertexLitGeneric}} requires a {{ent|$bumpmap}}. If not specified, a default one will used instead! '''It will be as if a {{ent|$bumpmap}} is in the VMT!'''}}
{{Important|{{code|$lightwarptexture}} on {{Ent|VertexLitGeneric}} requires a {{Ent|$bumpmap}}. If not specified, a default one will be used instead! '''It will be as if a {{Ent|$bumpmap}} is in the VMT!'''
{{Warning| This means that all parameters that don't work with {{ent|$bumpmap}} also won't work with <code>$lightwarptexture</code>.}}
{{Warning| This means that all parameters that don't work with {{Ent|$bumpmap}} also won't work with {{code|$lightwarptexture}}.
:* [[$detail#Parameters and Effects|$detailblendmode]] 5-9 won't work - 5 & 6 will work when {{ent|$phong}} is used.
* [[$detail#Parameters and Effects|$detailblendmode]] 5-9 won't work - 5 & 6 will work when {{Ent|$phong}} is used.
:* {{ent|$envmapmask}} won't work except in {{mapbase|4}}. {{ent|$selfillum_envmapmask_alpha}} Doesn't work in any branch.
* {{Ent|$envmapmask}} won't work, except in {{mapbase|2}}.
{{Note|Does not work without {{ent|$phong}} on {{ent|VertexLitGeneric}} in {{css|2}} '''and''' {{csgobranch|4}}.}}
* {{Ent|$selfillum_envmapmask_alpha}} doesn't work in any branch.
{{Note|<code>$lightwarptexture</code> does not seem to exist at all for {{ent|LightmappedGeneric}} in {{csgobranch|4}}.}}
* [[Per-vertex lighting]] won't work prior to {{csgobranch|2}}
}} }}
{{Note|{{code|$lightwarptexture}} does not seem to exist at all for {{Ent|LightmappedGeneric}} in {{csgobranch|2}}.}}


{{Bug|Does not work when using {{ent|$detail}} '''or''' {{ent|$bumpmap2}} on both {{ent|LightmappedGeneric}} and {{ent|WorldVertexTransition}}.}}
{{Bug|Does not work when using {{Ent|$detail}} '''or''' {{Ent|$bumpmap2}} on both {{Ent|LightmappedGeneric}} and {{Ent|WorldVertexTransition}}.}}
{{Bug|Does not work when using [[Glowing_Textures#.24selfillum|$selfillumfresnel]] without also using {{ent|$phong}}.}}
{{Bug|Does not work when using [[Glowing_Textures#.24selfillum|$selfillumfresnel]] without also using {{Ent|$phong}}.}}
{{Bug|Does not work when using {{ent|$seamless_scale}}.}}
{{Bug|Does not work when using {{Ent|$seamless_scale}}.}}
 


== Lightwarp textures ==
== Lightwarp textures ==
A lightwarp texture is a one-dimensional strip of pixels. Dark texels will be tinted with the colour on the left-hand side, and bright texels with the colour on the right. 50% gray means no tint.
A lightwarp texture is a one-dimensional strip of pixels. Dark texels will be tinted with the colour on the left-hand side, and bright texels with the colour on the right.
 
Lightwarp works slightly differently on lightmapped brushes and displacements compared to vertex-lit models. A completely 50% grey {{code|$lightwarptexture}} on a brush or displacement will appear as if lightwarp were not present, whereas the same {{code|$lightwarptexture}} on a model with no [[$phong|phong]] would result in the model being lit uniformly at 100% brightness (not overbright).
 
A lightwarp texture should usually have a horizontal resolution of at least 256px (any higher will have negligble benefits). The vertical resolution can be whatever; 1px is optimal, but higher resolutions may help with being able to see the texture thumbnail in a file browser.
 
=== VTF parameters ===
A lightwarp texture should use uncompressed BGR888 format to avoid undesired color banding on lighting gradients{{ref|1}}, and should be UV clamped.
 
If using {{vtex|4}}, use these compile parameters:
<pre>
nocompress 1 // disable texture compression, to prevent undesired color banding
nomip 1 // disable mipmaps, which are unnecessary in this instance
nolod 1 // always use the full resolution version of this texture (due to being low-resolution to begin with)
clamps 1 // prevent tints at lighting extremes from blending together
clampt 1 // optional?
stripalphachannel 1 // remove unnecessary alpha channel, if present
</pre>
 
If the transitions should be sharp, additionally enable point sampling ({{code|pointsample 1}}).


=== Examples ===
=== Examples ===
; <code>snow_warp</code>:[[File:Warptexture.jpg|border|dod\materials\ground\snow_warp]]
; {{file|ground/snow_warp|vtf}} ({{dods}}):[[File:Warptexture.jpg|border|dod\materials\ground\snow_warp]]
: This is the lightwarp texture used in the {{dods|2}} screen to the right. It is designed to add a subtle bluish tint to darker snow without affecting brighter regions.
: This is the lightwarp texture used in the {{dods|2}} screen above. It is designed to add a subtle bluish tint to darker snow without affecting brighter regions.
; <code>pyro_lightwarp</code>:[[File:Pyro lightwarp.png|border|tf\materials\models\player\pyro\pyro_lightwarp]]
; {{file|models/player/pyro/pyro_lightwarp|vtf}} ({{tf2}}):[[File:Pyro lightwarp.png|border|tf\materials\models\player\pyro\pyro_lightwarp]]
: This is applied to all {{tf2|2}} characters, not just the Pyro. It creates the high-contrast shadows with red-tinged terminators typical of the illustrative art the game apes.
: This is applied to all {{tf2|2}} characters, not just the Pyro. It creates the high-contrast shadows with red-tinged terminators typical of the illustrative art the game apes.
; Posterized: [[File:Warp bw.png|border|Custom texture]]
; Posterized (custom): [[File:Warp bw.png|border|Custom texture]]
: This custom warp texture creates a posterized "line art" style. Enabling lightwarp alone isn't enough however: ambient lighting must be at 0 to make unlit areas black, and world lighting must become viewer-dependent to ensure that shadows are always cast.
: This custom warp texture creates a posterized "line art" style. Enabling lightwarp alone isn't enough however: ambient lighting must be at 0 to make unlit areas black, and world lighting must become viewer-dependent to ensure that shadows are always cast.
; <code>Cel Shading</code>:[[File:Cel_lightwarp.png|border|Custom texture]]
; Cel Shading (custom):[[File:Cel_lightwarp.png|border|Custom texture]]
:Cel shading can make objects look more cartoony by replacing the smooth lighting gradient with sharp steps.
:Cel shading can make objects look more cartoony by replacing the smooth lighting gradient with sharp steps.
; Fake $phongdisablehalflambert (custom): [[file:Phongdisablehalflambert warp.png|border|custom texture]]
:Simulates {{cmd|$phongdisablehalflambert}} in games without that command.


Other possible uses of <code>$lightwarptexture</code> include contrast enhancement, tweaking vertex lighting shadow transitions, highlight softening, and more.
Other possible uses of {{code|$lightwarptexture}} include contrast enhancement, tweaking vertex lighting shadow transitions, highlight softening, and more.




::[[File:Celshadingpreview.png|thumb|320px|left|Cel shading in action.]]
::[[File:Celshadingpreview.png|thumb|320px|left|Cel shading in action.]]
{{clr}}
== References ==
<ol>
<li>[https://gamebanana.com/mods/466641 Lightwarp Fixes <nowiki>[Team Fortress 2] [Mods]</nowiki> on GameBanana]
</ol>
[[Category:Shader parameters|l]]

Latest revision as of 05:03, 1 May 2025

English (en)中文 (zh)Translate (Translate)

The technique was first used in Day of Defeat: Source Day of Defeat: Source's snow maps, such as Kalt.
$lightwarptexture is a cornerstone of Team Fortress 2 Team Fortress 2's illustrative character rendering.
Posterized color can be achieved, but lighting must be tightly controlled.

$lightwarptexture (DX9+ SM3) is a material shader parameter for the VertexLitGeneric shader available in all Source Source games since Source 2006 Source 2006. It tints texels depending on their brightness. It can be thought of as localized color correction.

Note.pngNote:Also available for LightmappedGeneric, WorldVertexTransition, EyeRefract.

Caveats

Icon-Important.pngImportant:Make sure the texture is clamped in the VTF otherwise it will render incorrectly. Use Clamp S and Clamp T image flags for that.
Icon-Important.pngImportant:$lightwarptexture on VertexLitGeneric requires a $bumpmap. If not specified, a default one will be used instead! It will be as if a $bumpmap is in the VMT!
Warning.pngWarning: This means that all parameters that don't work with $bumpmap also won't work with $lightwarptexture.
Note.pngNote:$lightwarptexture does not seem to exist at all for LightmappedGeneric in CS:GO engine branch CS:GO engine branch.
Icon-Bug.pngBug:Does not work when using $detail or $bumpmap2 on both LightmappedGeneric and WorldVertexTransition.  [todo tested in ?]
Icon-Bug.pngBug:Does not work when using $selfillumfresnel without also using $phong.  [todo tested in ?]
Icon-Bug.pngBug:Does not work when using $seamless_scale.  [todo tested in ?]

Lightwarp textures

A lightwarp texture is a one-dimensional strip of pixels. Dark texels will be tinted with the colour on the left-hand side, and bright texels with the colour on the right.

Lightwarp works slightly differently on lightmapped brushes and displacements compared to vertex-lit models. A completely 50% grey $lightwarptexture on a brush or displacement will appear as if lightwarp were not present, whereas the same $lightwarptexture on a model with no phong would result in the model being lit uniformly at 100% brightness (not overbright).

A lightwarp texture should usually have a horizontal resolution of at least 256px (any higher will have negligble benefits). The vertical resolution can be whatever; 1px is optimal, but higher resolutions may help with being able to see the texture thumbnail in a file browser.

VTF parameters

A lightwarp texture should use uncompressed BGR888 format to avoid undesired color banding on lighting gradients[1], and should be UV clamped.

If using VTEX VTEX, use these compile parameters:

nocompress 1 // disable texture compression, to prevent undesired color banding
nomip 1 // disable mipmaps, which are unnecessary in this instance
nolod 1 // always use the full resolution version of this texture (due to being low-resolution to begin with)
clamps 1 // prevent tints at lighting extremes from blending together
clampt 1 // optional?
stripalphachannel 1 // remove unnecessary alpha channel, if present

If the transitions should be sharp, additionally enable point sampling (pointsample 1).

Examples

🖿ground/snow_warp.vtf (Day of Defeat: Source)
dod\materials\ground\snow_warp
This is the lightwarp texture used in the Day of Defeat: Source Day of Defeat: Source screen above. It is designed to add a subtle bluish tint to darker snow without affecting brighter regions.
🖿models/player/pyro/pyro_lightwarp.vtf (Team Fortress 2)
tf\materials\models\player\pyro\pyro_lightwarp
This is applied to all Team Fortress 2 Team Fortress 2 characters, not just the Pyro. It creates the high-contrast shadows with red-tinged terminators typical of the illustrative art the game apes.
Posterized (custom)
Custom texture
This custom warp texture creates a posterized "line art" style. Enabling lightwarp alone isn't enough however: ambient lighting must be at 0 to make unlit areas black, and world lighting must become viewer-dependent to ensure that shadows are always cast.
Cel Shading (custom)
Custom texture
Cel shading can make objects look more cartoony by replacing the smooth lighting gradient with sharp steps.
Fake $phongdisablehalflambert (custom)
custom texture
Simulates $phongdisablehalflambert in games without that command.

Other possible uses of $lightwarptexture include contrast enhancement, tweaking vertex lighting shadow transitions, highlight softening, and more.


Cel shading in action.

References

  1. Lightwarp Fixes [Team Fortress 2] [Mods] on GameBanana