Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HD Lightmaps HOWTO
11-21-2012, 10:04 PM (This post was last modified: 01-11-2013 12:19 AM by Max.)
Post: #1
HD Lightmaps HOWTO
While there is a small chance of changes being made before the release, I'm pretty confident that the file format for HD lightmaps is finalized, meaning mappers can really start using this feature. I'll explain it in detail below.

What is a lightmap?

A lightmap is basically a big texture that covers the whole map, containing information about light and dark areas. It is generated during map compilation by qrad3. It contains all the light and shadow caused by static light entities and brushes. (Dynamic lights and shadows cast by meshes and mapmodels are handled by a separate system.) We inherited this technology pretty much unmodified from Quake II. Normally, the lightmap data is added directly to the BSP file by qrad3. The Quake II BSP format requires that these lightmaps be at a single very low resolution. This causes ugly, blocky shadows, among other problems.

What is a lightmap file? What is an HD lightmap?

Lightmap files are a new feature in Alien Arena 7.61. They allow lightmap data to be put in its own file, separate from the BSP file. Because it's a whole new file format for which we need not maintain any sort of compatibility, these lightmaps can be generated at a much higher resolution, resulting in more detailed and crisp shadows and lights. In fact, the new file format supports a wide range of different resolutions, from the same low resolution used in BSPs to a resolution with 256 times more pixel density than that. Once the lightmap data has been loaded by the game engine, it is rendered using pretty much the same code we were using before.

In summary, a lightmap file is a file with the extension .lightmap, containing lightmap data. An HD lightmap is a lightmap file generated at a high resolution. Most of the time, the distinction doesn't matter.

What is this good for?

Lightmap files make it possible to change the lighting in a map without modifying the BSP, thus preserving the BSP's compatibility while updating its visuals. The higher available resolutions not only look better on their own, they also allow for other graphical effects which previously would have been impractical: textured alphamasked surfaces can now cast shadows, and shadows can be blurred adaptively based on distance from the light source. Both of these would technically have been possible without HD lightmaps, but they'd have been quite ugly-looking.

Maps that don't have a lot of shadows will see relatively little benefit from HD lightmaps. Well-lit indoor maps usually won't need them. An example of a map that looks good without an HD lightmap is dm-zorn2k11. Outdoor or semi-outdoor maps with sunlight, or maps with "moody" lighting, tend to have lots of shadows. These maps will look a lot better with HD lightmaps.

How do I generate a lightmap file for my map?

First of all, it's important to continue running qrad3 on your BSP files as normal. HD lightmaps do use up quite a lot of video RAM, so players with older systems may wish to disable them. If you don't generate an old-fashioned lightmap built directly into the BSP, these players will not be able to see anything. You should test your map with r_lightmapfiles 0 to make sure it is still playable without lightmap files. Try to make the built-in lightmap look as good as possible.

To generate a lightmap file, you must call qrad3 again, this time adding the -refine parameter. -refine tells qrad3 put the lightmap in its own file, instead of compiling it into the BSP file. -refine also takes a single argument, specifying a factor by which to increase the resolution of the lightmap data on each axis. Valid values for that argument are 1, 2, 4, 8, and 16. To explain:
  • qrad3 -refine 1 generates a lightmap file but does not use a high resolution.
  • qrad3 -refine 2 generates a lightmap file at double the resolution on each axis. This means that there will be four times more pixel data compared to -refine 1, or compared to the BSP's built-in lightmap. It will also require correspondingly more time to create.
  • qrad3 -refine 4 generates a lightmap file at four times the resolution on each axis. This means that there will be sixteen times more pixel data compared to -refine 1.
  • qrad3 -refine 8 generates a lightmap file at eight times the resolution on each axis. This means that there will be 64 times more pixel data compared to -refine 1.
  • qrad3 -refine 16 generates a lightmap file at sixteen times the resolution on each axis. This means that there will be 256 times more pixel data compared to -refine 1.
In practice, the amount of increase is usually somewhat less than this, due to the way rounding errors are prevented in the code (by always rounding the number of pixels up, at lower resolutions, the number of pixels is higher than it "should" be.) Don't underestimate the increase in quality, though.

Lightmap files are compressed using zlib, which brings filesizes down to a fairly reasonable range, but make no mistake, they actually contain a staggering amount of data. In fact, the maximum amount of lightmap data has had to be limited to around 96 MiB, and some of our bigger maps are already coming close to that limit! If you create a really huge map, you may have to use a lower -refine setting in order to get it to fit. In the future, we may add a way to specify different lightmap resolutions for different surfaces, which may mitigate the problem.

For most maps, a -refine setting of 8 is recommended. Only relatively small maps are likely to work with a -refine setting of 16. Only very large maps are likely to require a -refine setting of 4. However, the lower -refine settings have their uses.

One important "gotcha" is that if you change any of the brushes in your map, the lightmap file will become incompatible and must be regenerated. Therefore, it may be convenient to use a -refine setting of 2 or 4 while making the map, just to get an idea of what it looks like, and then generate a lightmap file with -refine 8 when you're ready to call it "finished."

Remember to include your lightmap file with your map. If you submit your map to MartianBackup when it's done (which you should Smile ) you should also get the lightmap file included, otherwise people will have to download it via UDP. Lightmap files at -refine 8 are around 2/3 the size of the BSP, so UDP downloads would be very annoying.

How do I use shadow softening?

Add the -blur option to qrad3. The -blur option takes no arguments, so you can simply use it like this: qrad3 -blur -refine 8 mapfile.map. You can even use it without -refine, when generating the BSP's built-in lightmap, although I urge you not to.

You also have some degree of control over how much each shadow gets blurred. The amount of blurring on each lightmap pixel is calculated based on a weighted average of the distance of each light that illuminates it. So if you want more blurring, move lights further from the surface. The brighter a light is, the more influence it has over the amount of blurring.

How do I get alphamasked and translucent surfaces to cast shadows?

Add the -texcheck option to qrad3. Like the -blur option, it takes no arguments. If -texcheck is enabled, it's a good idea to enable -blur as well. NOTE: this option will make qrad3 a lot slower.

-texcheck also causes translucent surfaces to cast colored sunbeams (the "stained-glass projector" effect.)

Without the -texcheck option, qrad3 behaves like it used to, treating alphamasked and translucent surfaces as if they were completely transparent.

I'm creating an HD lightmap, but I still see blocky areas of lighting?

These areas are likely caused by radiosity bouncing (a feature where walls reflect light further than the original source can reach.) Radiosity bouncing is still done at a very low resolution. Until this issue is addressed, there are a couple of other things to try:
  • Rearrange your light entities and walls such that indirect light doesn't cast as many obvious shadows.
  • Reduce the number of radiosity bounces using the -bounce option to qrad3. The default value for -bounce is 4, try 1 or even 0. You may need to add more light entities or increase the ambient light amount to compensate.

What it all looks like when it's done:
[Image: alienarena274.jpg]

(TODO: add screenshots and examples of how maps look with different settings.)

Quote:* maxtothemax is back
<maxtothemax> with a vengeance
<maxtothemax> and chips
<maxtothemax> and bean dip
Visit this user's website Find all posts by this user
Quote this message in a reply
11-22-2012, 02:26 PM
Post: #2
RE: HD Lightmaps HOWTO
Great feature - cant be said often enough lol
and well written guide about it Smile

-will try it as soon as the win binary is finished
Visit this user's website Find all posts by this user
Quote this message in a reply
11-23-2012, 01:03 AM
Post: #3
RE: HD Lightmaps HOWTO
I'll get them uploaded soon, been busy with holidays and going crazy with AA Tactical work, and work day job work. And Alteria. Damn, I am busy Big Grin
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)