Game Development Community

Atlas Lightmap Question

by J.C. Smith · in Torque Game Engine Advanced · 01/07/2009 (10:10 am) · 3 replies

Recently I've been trying to figure something out with Atlas, and am having a bit of problems. So I figured I'd ask here on the chance that someone else has done this before.

What I'm trying to do is take the generated Atlas lightmap and export it into a bitmap, but I'm having a bit of a problem understanding the format that its in. The advantage of splitting this into a lightmap is that I could then bake all of my shadows into atlas, and then read the lightmap into the groundcover lightmap and have the groundcover shaded properly. I'm at a bit of a loss though in figuring out how the data is stored here though.

Anyone have any suggestions or information that might be useful, it would be much appreciated.

#1
01/08/2009 (4:45 pm)
The lightmap generated by the SG lighting kit for blended Atlas terrain is stored in an Atlas file called "_.atlas" (with "atlasfilename" being the name of the Atlas terrain file). IIRC, there's no console command to dump an Atlas texture TOC back to bitmaps, but writing this is almost trivial (just walk the deepest level in the texture quadtree and save out all the tiles using GBitmap).

You could then do your custom lighting stuff, generate a new Atlas file from the resulting texture and do a "loadAlternateLightmap()" on the AtlasInstance. The question is why?

GroundCover does not have a lightmap of its own but rather accesses TerrainBlock lightmaps for some stuff. In order to get this to work with Atlas, that code would have to be changed.
#2
01/09/2009 (12:12 am)
We made a lot of changes to Groundcover, and one of those was making it load an external colormap file. This is basically a lightmap, but since its an RGB texture we also use it to place color variations on the groundcover. So we can paint certain patches with a yellowish tint, etc. But we start with a lightmap generated from Grome and have been using that as the basis and then place some tinted colors based on which layers are being used texture wise for the color differences.

There are two problems though with using a Grome exported lightmap. The first, is that the lightmaps aren't really consistant with those that Atlas generates. Which results in the grass being improperly shaded from the get go. But the main problem is with the shadows generated from cliffs, trees, buildings, etc. We have them all casting shadows on Atlas through the lightmap, but since we're using an externally loaded colormap, it doesn't have any of those shadows on it. Since the trees and cliffs are using modified replicators, its pretty hard to get the shadows from them to line up properly without dumping a bitmap from atlas.

The other atlernative would be to get the shadow color from atlas in the groundcover class, and just use the colormap for tinting grass color. When I was looking over that though I couldn't figure out an efficient way to do that. Will have to tinker around more later.

Thanks for the information Rene, much appreciated.
#3
01/09/2009 (10:53 am)
In this case, you may consider to just simply go with the Grome-generated lightmap and do away with the SG lightmap altogether. Simply pack the lightmap into an Atlas file and do the loadAlternateLightmap() call (you may want to override the SG lightmap generation altogether in this case).

If you want to go the other way and read out the Atlas lightmap, there's code doing just that in sgAtlasSystem::getColorFromRayInfo(). Should be easy to adapt this to your needs.