Here is the struct:
Code: Select all
typedef struct
{
char magic[4]; //"QLIT"
unsigned int version; //2
unsigned int numsurfs; //should be checked against the bsps' surface count
unsigned int numpoints; //total number of sample-points in the lit2
//uint lmoffsets[numsurfs]; //completely overrides the bsp lightmap info
//ushort lmextents[numsurfs*2]; //only to avoid precision issues. width+height pairs, actual lightmap sizes on disk (so +1).
//byte lmstyles[numsurfs*4]; //completely overrides the bsp lightmap info
//byte lmshifts[numsurfs]; //default is 4 (1<<4=16), for 1/16th lightmap-to-texel ratio. minimum value is 0
//byte litdata[numpoints*3]; //rgb data
//byte luxdata[numpoints*3]; //stn light dirs (unsigned bytes
} qlit2_t;
- It's designed not to affect the original lightmap data in the bsp or .lit v1 files, so engines that don't load the .lit2 will be totally unaffected. By putting it in a separate .lit2 file, we don't break colored lighting in non-lit2-supporting engines.
- lmextents contains the full width/height of each lightmap, measured in samples. Quake and the light tool use the word "extents" differently, to mean 1 sample less on each axis than what's stored on disk
- having the lmstyles array allows relighting a map, possibly adding dynamic lights, and being able to distribute just the .lit2 file.
- The lightmap scale for each face is stored in lmshifts as an exponent of 2. The maximum resolution is an lmshift value of 0, which is 1<<0 == 1, i.e. a 1:1 texel:lightmap ratio. lmshift of 1 means 1<<1==2, or a 2:1 texel:lightmap ratio.
I guess we just want feedback on whether everything makes sense.
One question is whether it's worth including the lmextents or not. This is to avoid floating point precision issues in CalcSurfaceExtents, e.g. on a few of mfx's maps, the CalcSurfaceExtents calculation needs to be done at 64-bit precision or better, or else it computes the wrong lightmap width/height.
Code:
There is (work in progress) progress compiler code at https://github.com/ericwa/tyrutils , in the "lit2" branch.
A preliminary patch to support this in Quakespasm is at: https://github.com/ericwa/quakespasm , also in the "lit2" branch.
Binaries:
These are special builds of quakespasm and my tyrutils fork with lit2 support:
tyrutils
quakespasm
Here is the documentation for the modded tyrutils:
Code: Select all
Command-line options:
-lit2 Force generation of a .lit2 file, which allow variable lightmap
resolution as well as storing light direction data. By default,
light will automatically generate the .lit2 file when needed.
-lightmapscale n | -lmscale n
Force the given lightmap scale for the entire map, overriding
any values set in the map via the "_lightmapscale" entity key.
See "_lightmapscale". Default 1.0.
Func_Group/Func_Detail Keys
The following keys can be used on any entity with a brush model,
worldspawn, as well as special entities func_group and func_detail,
which are processed by qbsp. Note: these keys are read by qbsp and
passed to light through a temporary file.
"_lightmapscale" "n"
Customize the lightmap scale for brush faces of this entity:
0.0625 => 16 times default resolution (finest)
0.125 => eight times default resoluton
0.25 => four times default resolution
0.5 => two times default resolution
1 => default
2 => half default resolution
4 => quarter default resolution
8 => eigth default resolution
16 => 1/16 default resolution (coarsest)
Using this key imples -lit2.
http://i.imgur.com/zwuQv4j.jpg
http://i.imgur.com/iMkCSh6.jpg