$lightmap: Difference between revisions
(Garry's Mod VRAD can bake static prop lightmaps in HDR now) |
(Source 2013 MP -> Source 2013 Multiplayer) |
||
(14 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{this is a|shader parameter|shader=VertexLitGeneric|name=$lightmap|game=Source 2013 | {{this is a|shader parameter|shader=VertexLitGeneric|name=$lightmap|game=Source 2013 Multiplayer|game1=Team Fortress 2 branch|game2=Garry's Mod}} | ||
It defines a [[lightmap]] to be used to light the [[MDL]] model's material, instead of the per-vertex lighting used by {{ent|prop_static}} or point-based vertex lighting used by other models. | It defines a [[lightmap]] to be used to light the [[MDL]] model's material, instead of the per-vertex lighting used by {{ent|prop_static}} or point-based vertex lighting used by other models. | ||
Line 5: | Line 5: | ||
This parameter does not usually need to be added manually, as [[VRAD]] will generate model lightmaps automatically if {{mono|generatelightmaps}} is enabled for the [[prop_static]] and {{mono|-StaticPropLighting}} is enabled in [[VRAD]]. Nonetheless, it can still be added manually, such as for using a lightmap on a [[prop_dynamic]], or if a [[prop_static]] has multiple materials (as [[VRAD]] can only generate lightmaps for the first material and skin). | This parameter does not usually need to be added manually, as [[VRAD]] will generate model lightmaps automatically if {{mono|generatelightmaps}} is enabled for the [[prop_static]] and {{mono|-StaticPropLighting}} is enabled in [[VRAD]]. Nonetheless, it can still be added manually, such as for using a lightmap on a [[prop_dynamic]], or if a [[prop_static]] has multiple materials (as [[VRAD]] can only generate lightmaps for the first material and skin). | ||
{{tip|<ul><li>{{src13mp}} [[VRAD]] has a {{code|-dumppropmaps}} option, which will create external [[TGA]] versions of the generated static prop lightmaps which can be converted to [[VTF]] and manually defined as a {{mono|$lightmap}}. | {{tip|<ul><li>{{src13mp}} [[VRAD]] has a {{code|-dumppropmaps}} option, which will create external [[TGA]] versions of the generated static prop lightmaps which can be converted to [[VTF]] and manually defined as a {{mono|$lightmap}}. | ||
{{important|In {{src13mp}}, {{mono|$lightmap}} is automatically overridden by the engine, regardless of if a [[PPL]] lightmap is present.}} | |||
{{bug|hidetested=1|The resulting [[TGA]]s are written with the wrong color space; convert the resulting [[PPL]] files instead. This command can still be useful for indicating which model and at what location each prop is, which the PPL filenames lack. {{fixed|{{gmod}}}} }} | |||
{{tip|To pair static props in a map with their dumped lightmaps, use {{Cmd|r_staticpropinfo|2}} to show static prop IDs on screen.}} | |||
<li>For already-compiled maps, the lightmaps are stored as [[PPL]] files. These can be converted to [[VTF]] using [https://files.gamebanana.com/bitpit/proptexelvtf.exe Ficool2's proptexelvtf.exe (direct download)]. | <li>For already-compiled maps, the lightmaps are stored as [[PPL]] files. These can be converted to [[VTF]] using [https://files.gamebanana.com/bitpit/proptexelvtf.exe Ficool2's proptexelvtf.exe (direct download)]. | ||
<li>If {{code|$lightmap}} is used to manually define lightmaps for a {{ent|prop_static}}, disable vertex lighting for the prop ({{code|disablevertexlighting}}) to prevent [[VRAD]] from wasting time calculating lighting for the prop and generating a [[VHV]] file that will ultimately go unused and waste space. | <li>If {{code|$lightmap}} is used to manually define lightmaps for a {{ent|prop_static}}, disable vertex lighting for the prop ({{code|disablevertexlighting}}) to prevent [[VRAD]] from wasting time calculating lighting for the prop and generating a [[VHV]] file that will ultimately go unused and waste space. | ||
</ul>}} | </ul>}} | ||
{{codenote|The [[VertexLitGeneric]] shader code for lightmapped props from {{src13mp}} can be backported to {{src13sp}}, but the lightmaps will need to be explicitly defined in the VMT, rather than generated as [[PPL]] files by [[VRAD]].}} | {{codenote|The [[VertexLitGeneric]] shader code for lightmapped props from {{src13mp}} can be backported to {{src13sp}}, but the lightmaps will need to be explicitly defined in the VMT, rather than generated as [[PPL]] files by [[VRAD]].}} | ||
__TOC__ | __TOC__ | ||
==VMT syntax== | ==VMT syntax== | ||
Line 31: | Line 33: | ||
{{warning|Model lightmaps generated with [[VRAD]] are compiled as RGB888 (24-bit SDR) [[PPL]] files which can result in noticeable color banding when brightly lit in HDR mode.<!-- | {{warning|Model lightmaps generated with [[VRAD]] are compiled as RGB888 (24-bit SDR) [[PPL]] files which can result in noticeable color banding when brightly lit in HDR mode.<!-- | ||
-->{{workaround|<ul><li>Define a pre-baked RGBA16161616f {{ent|$lightmap}} in the [[VMT]] of the [[VertexLitGeneric]] material. A custom-coded compiler would be required to this accurately (and could also create RGBA16161616f PPL files instead, which will work with vanilla shaders).<!-- Technically a lightmap could be baked in Blender, but that would be a pain to set up. --><!-- | -->{{workaround|<ul><li>Define a pre-baked RGBA16161616f {{ent|$lightmap}} in the [[VMT]] of the [[VertexLitGeneric]] material. A custom-coded compiler would be required to this accurately (and could also create RGBA16161616f PPL files instead, which will work with vanilla shaders).<!-- Technically a lightmap could be baked in Blender, but that would be a pain to set up. --><!-- | ||
--><ul><li>{{gmod|4}}'s [[VRAD]] now bakes RGBA16161616f [[PPL]] files in addition to the traditional 24-bit SDR RGB888 PPL files.{{ref|1}} [[VRAD]] bakes and packs both PPLs in maps (during {{code|- | --><ul><li>{{gmod|4}}'s [[VRAD]] now bakes RGBA16161616f [[PPL]] files in addition to the traditional 24-bit SDR RGB888 PPL files.{{ref|1}} [[VRAD]] bakes and packs both PPLs in maps (during the {{code|-hdr}} and {{code|-ldr}} stages respectively) and will swap between them depending on the client's currently selected HDR mode. {{code|-dumppropmaps}} has also been updated to output [[PFM]] files in addition to the traditional [[TGA]]s, both being dumped to a new folder located at {{path|steamapps\common\[[gmod|GarrysMod]]\garrysmod\sp_lightmaps}}.</li></ul><!-- | ||
--><li>Increase lightmap resolution (results may vary).<li>Move light source further away from the lit surface.</ul>}}<!-- | --><li>Increase lightmap resolution (results may vary).<li>Move light source further away from the lit surface.</ul>}}<!-- | ||
-->}} | -->}} | ||
Line 38: | Line 40: | ||
-->{{codenote|There is an in-engine check that confirms whether or not the {{ent|$bumpmap}} parameter is defined for a material, a custom shader cannot simply use both as there are a dozen technicalities that have to be overcome. | -->{{codenote|There is an in-engine check that confirms whether or not the {{ent|$bumpmap}} parameter is defined for a material, a custom shader cannot simply use both as there are a dozen technicalities that have to be overcome. | ||
{{Expand|noborder=1|title=Technical| | {{Expand|noborder=1|title=Technical: Custom shaders| | ||
If {{ent|$bumpmap}}, {{ent|$normalmap}}, or {{ent|$phong}} is defined, the engine will not send the lightmap data to the shader.<br> | If {{ent|$bumpmap}}, {{ent|$normalmap}}, or {{ent|$phong}} is defined, the engine will not send the lightmap data to the shader.<br> | ||
For $bumpmap, a workaround for this is to use a differently named parameter. ($NormalTexture) to get the normal map and undefining $bumpmap.<br> | For $bumpmap, a workaround for this is to use a differently named parameter. ($NormalTexture) to get the normal map and undefining $bumpmap.<br> | ||
Line 47: | Line 49: | ||
This in-engine check also exists for $phong, however getting around the issue is more tricky. The default value of the integer parameter will be 0 even if not set in the [[vmt]]. Thus making $phong always be defined in a way.}} | This in-engine check also exists for $phong, however getting around the issue is more tricky. The default value of the integer parameter will be 0 even if not set in the [[vmt]]. Thus making $phong always be defined in a way.}} | ||
{{ | {{expand|noborder=1|title=Technical: Vanilla-compatible|This can be sidestepped for non-phong materials by modifying VRAD to bake the normal map data directly into the lightmap via a {{code|%NormalMap}} texture, akin to {{idtech3}} [https://github.com/Garux/netradiant-custom/tree/master/tools/quake3/q3map2 Q3Map2's] {{code|q3map_normalImage}}. The lightmap will need to be as high resolution as the normal map, but this is made up for by the normal map never entering VRAM (in fact, it won't even need to be shipped with the map!). Since the normal data will be prebaked into the lightmap, however, the illusion may be lost if using an {{cmd|$envmap}}.}} }}<!-- | ||
-->}} | -->}} | ||
== See also == | == See also == | ||
* {{ | * {{cmd|$detailblendmode|8}} - Can be used on the [[UnlitGeneric]] shader to simulate lightmaps in all Source engine branches. | ||
* {{ent|Modulate}} - A shader that can be used to fake lightmaps or vertex coloring in all Source engine branches. It can bypass some of the limitations of {{code|$lightmap}}, but requires additional setup to look convincing. | * {{ent|Modulate}} - A shader that can be used to fake lightmaps or vertex coloring in all Source engine branches. It can bypass some of the limitations of {{code|$lightmap}}, but requires additional setup to look convincing. | ||
{{references|1= | {{references|1= | ||
{{ref2|cite id=1|These | {{ref2|cite id=1|These features were implemented following {{code|garrysmod-requests}} issue [https://github.com/Facepunch/garrysmod-requests/issues/2464 #2464] | ||
}} | }} | ||
}} | }} | ||
[[Category:Shader parameters|l]] | [[Category:Shader parameters|l]] |
Latest revision as of 01:22, 20 April 2025
$lightmap
is a material shader parameter for the VertexLitGeneric shader available in Source 2013 Multiplayer,
Team Fortress 2 branch, and
Garry's Mod.
It defines a lightmap to be used to light the MDL model's material, instead of the per-vertex lighting used by prop_static or point-based vertex lighting used by other models.
This parameter does not usually need to be added manually, as VRAD will generate model lightmaps automatically if generatelightmaps is enabled for the prop_static and -StaticPropLighting is enabled in VRAD. Nonetheless, it can still be added manually, such as for using a lightmap on a prop_dynamic, or if a prop_static has multiple materials (as VRAD can only generate lightmaps for the first material and skin).

VRAD has a -dumppropmaps option, which will create external TGA versions of the generated static prop lightmaps which can be converted to VTF and manually defined as a $lightmap.
Important:In
, $lightmap is automatically overridden by the engine, regardless of if a PPL lightmap is present.
Tip:To pair static props in a map with their dumped lightmaps, use r_staticpropinfo 2 to show static prop IDs on screen.
- For already-compiled maps, the lightmaps are stored as PPL files. These can be converted to VTF using Ficool2's proptexelvtf.exe (direct download).
- If $lightmap is used to manually define lightmaps for a prop_static, disable vertex lighting for the prop (disablevertexlighting) to prevent VRAD from wasting time calculating lighting for the prop and generating a VHV file that will ultimately go unused and waste space.



VMT syntax
$lightmap <texture>
Limitations and caveats

VRAD cannot create lightmaps for UVs outside of the 0-1 UV space.
Additionally, shadows may appear on UV seams; this is more noticeable on lower-resolution lightmaps.




- Define a pre-baked RGBA16161616f $lightmap in the VMT of the VertexLitGeneric material. A custom-coded compiler would be required to this accurately (and could also create RGBA16161616f PPL files instead, which will work with vanilla shaders).
Garry's Mod's VRAD now bakes RGBA16161616f PPL files in addition to the traditional 24-bit SDR RGB888 PPL files.[1] VRAD bakes and packs both PPLs in maps (during the -hdr and -ldr stages respectively) and will swap between them depending on the client's currently selected HDR mode. -dumppropmaps has also been updated to output PFM files in addition to the traditional TGAs, both being dumped to a new folder located at
steamapps\common\GarrysMod\garrysmod\sp_lightmaps
.
- Increase lightmap resolution (results may vary).
- Move light source further away from the lit surface.


If $bumpmap, $normalmap, or $phong is defined, the engine will not send the lightmap data to the shader. This in-engine check also exists for $phong, however getting around the issue is more tricky. The default value of the integer parameter will be 0 even if not set in the vmt. Thus making $phong always be defined in a way. |
This can be sidestepped for non-phong materials by modifying VRAD to bake the normal map data directly into the lightmap via a %NormalMap texture, akin to ![]() |
See also
- $detailblendmode 8 - Can be used on the UnlitGeneric shader to simulate lightmaps in all Source engine branches.
- Modulate - A shader that can be used to fake lightmaps or vertex coloring in all Source engine branches. It can bypass some of the limitations of $lightmap, but requires additional setup to look convincing.
References
References |
---|