Shard Engine PreProcess

After implementing Getic level importing into the Shard Engine, there was an obvious incompatibility between the normal game objects, rendered in HDR according to one lighting formula, and the exported lightmaps rendered in LDR with another lighting formula. Simultaneously, level loading times were increased because the physics engine had to preprocess the map into its own format. To solve both these problems I wrote the PreProcess utility.

PreProcess is designed to load Getic's .gbt level format, and to save and load a modified version of that format, .sgbt, in which the lightmaps are stored in a more D3D friendly format and there is a extra segment at the end of the file containing a serialized version of Newton's internal representation of the game environment.

Lightmaps are generated on the graphics card by transforming all world geometry into the tangent space of a particular face, and (for each light in turn) constructing a projection matrix that maps the edges of the lightmap texture to the edges of the view volume and the light to the apex of the view pyramid. The polygon is rendered once into the alpha channel, the rest of the world geometry as a depth-only pass, and finally the polygon is rendered additively in colour based on the standard lighting model. After this process any texel with an alpha between 0 and 1 can be divided by its own alpha in order to brighten texels partially covered by the polygon without interfering with the shadows, and any texel with an alpha of 0 can sum all texels around it and divide by their alpha to further protect against filtering errors. The finished lightmaps are encoded into RGBE format for storage.

Since not all graphics cards support multisampling on floating point render targets, the program can also be set to supersample by a variable amount, and can also be set to generate finished lightmaps at a fixed multiple of the resolution being used in the incoming file.