Gaming
 

Lightmaps with higher level of detail

From OpenArena

The BSP format used by Q3 is internally constrained to lightmaps that are no larger than 128 x 128 per surface, unless ioquake3 upgrade its engine to remove that constrain there is no hack to go over 128 x 128. What this trick do is take advantage of two handy features: 1st q3map2 capability of generating lightmaps which are larger than 128 x 128 and saving them as TGAs. 2nd Q3 capability of blending textures which are over 128 x 128. In other words, you'll be overriding the default low res lightmap with external textures. Lightmaps are, in fact, texture layers.

Q3map2 can both add normal map depth information to lightmaps as well as compile lightmaps with resolution higher than 128 x 128.

You'll need to write shader scripts per surface, per texure or per map to do this:

textures/my_dir/my_texture_hi_res_lightmap {

 qer_editorimage textures/my_dir/my_texture.jpg
 q3map_lightmapfilterradius 2 0
 q3map_lightmapSize 1024 1024 
 q3map_lightmapsamplesize 16
 q3map_lightmapBrightness 2.0
 //q3map_normalimage textures/my_dir/normal_map.tga
 {
   tcgen lightmap
   map $lightmap
   rgbGen identity
 }
 {
   map textures/my_dir/my_texture.tga
   blendFunc GL_DST_COLOR GL_ZERO
 }

}

r_ext_texture_compression does affect external lightmaps as well.


Higher lightmapsizes increase both level of detail and memory usage, as well as compiling times.


It's possible to change lightmapsize of default textures without needing to duplicate them, just pay attention to not name your my_texture_hi_res_lightmap line with the same name as the default texture. And have map point at the correct default texture path (note the file extension here, TGA, that seems to be mandatory, regardless of texture filetype), else you'll see shader not found errors and/or end up loading a different texture.


qer_editorimage if you are changing a default texture, put the same path used in map (note that in here, TGA or JPG does matter). This texture is only used in the editor, missing it doesn't do anything in game.


blendFunc see shader manual for further reference, this seems to change the overall contrast / brightness / gamma of the lightmap.


q3map_normalimage q3map2 generates lightmaps that lack the necessary sharpness and minimum definition to make pre-rendered normal maps worth it, with its current lighting algorithm is just a waste of time trying to take advantage of normal maps on all map's surfaces.


q3map_lightmapfilterradius This is used for anti-aliasing both the surfacelight's own surface and surfaces with lightmaps. Both values define the blur radius applied to the lightmap's shadow edges, first is self for surfaces with lightmaps and second is other, for surfaces hitted by surfacelight. To put it in another order, first value is for this surface's lightmap, while second value is for the shadows casted by this surface's surfacelight's shader.


Pay attention to the blog's tutorial part that explains the mapname's shader generated by q3map2. The high resolution lightmaps won't be embedded in your map's BSP, but left outside it as ordinary textures with a shader that has all the necessary lines to load them in game. The Q3BSP format doesn't support internal and external lightmaps, so if the external lightmaps fail to load, the whole map will lose all textures in game.


[edit] Thanks to

http://sgq3-mapping.blogspot.com/2009/01/using-hi-resolution-external-lightmap.html

http://www.cgtextures.com/content.php?action=tutorial&name=normalmap