$lightmap: Difference between revisions
SirYodaJedi (talk | contribs) (→Limitations and caveats: template unnecessary now) |
SirYodaJedi (talk | contribs) (→Limitations and caveats: note about HDR PPL files, and how an equivalent to q3map_normalimage could sidestep bumpmap limitations) |
||
Line 26: | Line 26: | ||
-->{{bug|Lightmaps for models with multiple materials do not compile properly in [[VRAD]]! A lightmap will only be compiled for the first material on the model, that is a combined version of all the UV's used by all materials.<!-- | -->{{bug|Lightmaps for models with multiple materials do not compile properly in [[VRAD]]! A lightmap will only be compiled for the first material on the model, that is a combined version of all the UV's used by all materials.<!-- | ||
-->{{workaround|Define a pre-baked {{ent|$lightmap}} in the [[VMT]] of the [[VertexLitGeneric]] material (can be obtained using {{code|-dumppropmaps}} in [[VRAD]]).}}<!-- | -->{{workaround|Define a pre-baked {{ent|$lightmap}} in the [[VMT]] of the [[VertexLitGeneric]] material (can be obtained using {{code|-dumppropmaps}} in [[VRAD]]).}}<!-- | ||
-->}} | -->}} | ||
-->{{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.<!-- Technically a lightmap could be baked in Blender, but that would be a pain to set up. --><li>Increase lightmap resolution (results may vary).<li>Move light source further away from the lit surface.</ul>}}<!-- | {{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. --><li>Increase lightmap resolution (results may vary).<li>Move light source further away from the lit surface.</ul>}}<!-- | ||
-->}} | |||
{{warning|Models using [[$bumpmap]] cannot receive lightmaps, they will fall back to vertex-lighting based upon the models' origin or [[$illumposition]].<!-- | |||
-->{{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. | ||
Line 41: | Line 43: | ||
A fix for this would be modifying [[VRAD]] to spit out a lightmap that is *2 the size on the U axis and then storing an average light direction there or doing some other smart technique to 'memorize' light directions. | A fix for this would be modifying [[VRAD]] to spit out a lightmap that is *2 the size on the U axis and then storing an average light direction there or doing some other smart technique to 'memorize' light directions. | ||
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.}} | ||
{{workaround|This can be sidestepped by baking 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!).}} }}<!-- | |||
-->}} | -->}} | ||
Revision as of 07:06, 5 September 2024
$lightmap
is a material shader parameter for the VertexLitGeneric shader available in Source 2013 Multiplayer and
Garry's Mod.

- The {{{game}}} parameter is inconsistent with the name defined by the {{Source 2013 MP}} template. This can most likely be fixed by setting the value of the {{{game}}} parameter to Source 2013 Multiplayer.
If a parameter is consistent but you're still seeing this warning, it may be an issue with the template itself. Please discuss it on the template's talk page.
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.
- For already-compiled maps, the lightmaps are stored as PPL files. These can be converted to VTF using Ficool2's proptexelvtf.exe (direct download).




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).
- 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. |


See also
- 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.