Game Development Community

Forcing Atlas to Load a Compiled Lightmap

by J.C. Smith · in Torque Game Engine Advanced · 09/02/2007 (4:54 am) · 1 replies

First off, I love the new lightmaps for atlas. Kudos to GG on getting those in. The lighting time required on large terrains is pretty long though and in my current project we're using pretty large continents with a dynamic day/night cycle so I decided to disable creating lightmaps on the client and to instead create them from another program and then just save one lightmap (in this case taken with the sun directly overhead) and then just adjust the sun values over the day to simulate the day/night. For this to work I wanted to force atlas to not generate lightmaps and not to check the crc for the lighting file. This isn't going to be useful for most people but if you have the need to do something similar this is how to force atlas to use a lightmap.atlas file for lighting and to not create atlas lightmaps.

All of this code is in lightingsystem/scenelighting.cc.

In the SceneLighting::Light function we need to change this block at line 579:

if(!proxy->calcValidation() && !isAtlas(*itr))// jc
		{
			Con::errorf(ConsoleLogEntry::General, "Failed to calculate validation info for object.  Skipped.");
			delete proxy;
			continue;
		}

		if(!proxy->loadResources() && !isAtlas(*itr)) //jc
		{
			Con::errorf(ConsoleLogEntry::General, "Failed to load resources for object.  Skipped.");
			delete proxy;
			continue;
		}

Down around line 1206:

//dSprintf(cachedLighting, sizeof(cachedLighting), "%s_%x.atlas", baseAtlas, gLighting->calcMissionCRC());
   // jc rig it up to load only our pregenerated lightmap
   dSprintf(cachedLighting, sizeof(cachedLighting), "%slightmap.atlas", baseAtlas); // jc

And then at line 1288:

//   dSprintf(cachedLighting, sizeof(cachedLighting), "%s_%x.atlas", baseAtlas, gLighting->calcMissionCRC()); //jc
	dSprintf(cachedLighting, sizeof(cachedLighting), "%slightmap.atlas", baseAtlas); //jc

You should then comment out all of the code inside of the SceneLighting::AtlasLightMapProxy::postLight function (starting at line 1226) so the function doesn't do anything.

Now whenever Atlas loads it will load up a lightmap.atlas file. There isn't any error checking here, if the file doesn't exist it will probably crash you. If you relight the scene it will skip atlas lighting. Hopefully this is useful to someone.

#1
09/06/2007 (2:36 pm)
Awesome!!

This will be very useful.
Lots of possibilities.
Linking the lightmap name to a field in the mission file for instance.
new AtlasInstance2(IO) {
      detailTex = "~/data/terrains/io/detail1";
      atlasFile = "~/data/terrains/io/io.atlas";
     [b] LightmapFileName = "IO_noon";[/b]
      lightmapDimension = "256";
   };