Game Development Community

dev|Pro Game Development Curriculum

Native Ambient Occlusion for Interiors in TGE

by Ryan Mounts · 06/25/2008 (12:52 pm) · 24 comments

If you've followed any of my blogs at all, you've probably noticed my desire to get more advanced lighting into Torque. So far I've been using 3dsmax to do that with good success. The only problem is that the process can be somewhat time consuming and complicated at times. It'd be much nicer if I could do some simple advance lighting directly inside Torque. I've noticed that ambient occlusion really adds alot to a scene, so that seemed like a good place to start.

So here's some progress from my current endeavor: ambient occlusion for an interior calculated in Torque and added to its lightmap. It's a simple AO algorithm that shoots rays out from each lexel in the lightmap to determine that lexel's occlusion. This AO value is then used to modulate the ambient light.

i31.tinypic.com/10rr31x.jpg
There are three different quality settings: low, medium, and high. Low shoots 40 rays, Medium shoots 160, and High shoots 360. You can see that there are some artifacts in the corners using the Low setting. Medium got rid of the artifacts and smoothed the result considerably. High didn't change the visual quality much, but the shadowing is slightly smoother where the taller box touches the floor. I haven't profiled this, but approximate relight times for the above images on a Dell Inspiron 8600 laptop/1.5 GHz/512MB RAM were... Low: 5 seconds, Medium: 12 seconds, High: 30 seconds. Looks like Medium is sufficient to get good AO.

i28.tinypic.com/eg3gxz.jpg
Changing the ray length adjusts the "size" of the AO effect. Longer rays will generally result in darker shadowing (more accurate), but will take longer to calculate.

Next I need to expose these parameters to the World Editor and make an option to lock the AO in. That way it won't have to recalculate with every relight. Then I plan on releasing this as a resource. And porting this over to TGEA should only take a few minutes. :)
Page«First 1 2 Next»
#21
11/01/2008 (1:05 pm)
Hey Ryan,
Oh man this is frustrating, ok before I had all my mission files in the mission folder, there are 17 missions, so I have put them all in their seperate folders. I use SVN to keep all my computers up to date with the same versions, no art has been changed for a couple months now, just programming. I managed to light all missions using 3 different computers and committing the missions when done. So the folder will only have 3 files, the .mis, .ter and .ml file. After that was completed, I would start up the game and for some odd reason, it would just randomly choose folders and delete their .ml files.......? So I noticed on line 1077 in sgSceneLighting.cc is where it would actually do the deleting. I commented the deleting lines out so they wouldn't be called. That worked, the no longer get deleted. I can now load up some missions, quit the game (not right out, just to the menu) and start the next. If I play levels 1,2,3,4 then go back to 1 or 2 it would want to relight those missions sometimes. Then sometimes I would maybe jump to level 10 and it would want to relight, other times it wouldn't it seemed like a 50-50 chance. If it started to relight, I would stop it, delete the .ml file and then put the good working ml back. If I restarted the mission and started the level that just attempted to relight, it would start normally, using the AO lighted ml file. So it seems the first time round for any mission file it will work 100% of the time but the more times I close the mission (just to the menu) and start a new one the chances of any mission relighting increases. Is there something I can do to flush out a lighting cache or buffer or something? Is there a way to completely disable it from trying to relight. I have all my .ml files now, so I don't need to relight anymore. Any ideas?

Thanks a bunch.
#22
11/03/2008 (7:43 am)
Well, I'm guessing what is happening is that the ForceAlways or ForceWritable flags are getting set somewhere and not being cleared between mission loads. The easiest way to fix that would be to find this section of code in "sgSceneLighting.cc" in the light() method...

// check for some persisted data, check if being forced..
	if(!flags.test(ForceAlways|ForceWritable))
	{
		if(loadPersistInfo(mFileName))
		{
			Con::printf(" Successfully loaded mission lighting file: '%s'", mFileName);

			// touch this file...
			if(!dFileTouch(mFileName))
				Con::warnf("  Failed to touch file '%s'.  File may be read only.", mFileName);

and add this line right above it...

flags.clear(ForceAlways|ForceWritable);

I think that should fix your random relighting issue. Just for completeness, though, I'd probably comment out the Sim::postEvent() at the end of this method to disable relighting altogether. Now you need to handle the case where the lighting file doesn't exist for some reason. So if the load ever gets to the relighting phase of the mission download process (Phase 3), you need to throw up some kind of Error GUI and allow the player to go back to the main menu. So in "missionDownload.cs" you could change the onMissionDownloadPhase3() function to something like this...

function onMissionDownloadPhase3()
{
   Canvas.setContent( noLightingGUI );
}

If this doesn't fix it, that implies that the mission CRC is somehow changing between reloads (that's no good!), and I'd suggest just gutting the light() method code and rewriting it to just load any .ml file in the current mission folder, ignoring the CRC stuff.
#23
11/06/2008 (8:39 pm)
@Dalo

Question that might help.. Do you have decal projectors in the Mission files that relight? I just recently noticed a persistence of projectors between multiple missions. This would force a relight in missions where it shouldn't because the decal projector was being loaded at runtime, changing the mission content.

This might happen with other lighting objects as well.

C
#24
11/06/2008 (10:05 pm)
@Ryan, those changes you suggested seemed to crash the game here and there and the problem persisted, but read the next part for the partial solution.

@ William, Nadda, but I think I have somewhat figured out the problem......kinda......as stated earlier roughly line 1077 in sgSceneLighting.cc I commented out the lines that delete's .ml files. I don't know why but it would randomly delete .ml files. So that takes care of that issue. So after hours of trial and error I stumbled across 2 pref variables that may have been the problem.
$pref::sceneLighting::cacheLighting = 1;
$pref::sceneLighting::cacheSize = 20000;

I attempted to switch the cacheLighting to zero and after several tests, I was getting the same results. Any mission would attempt to relight after the 4th-7th game. It all depended on how big the lighting file was. For two of my levels they were 8000k big. So usually after the 3rd or 4th game it would relight. My other smaller arena levels wouldn't relight for quite a few games because the .ml size was relatively low.

So, I bumped the cacheSize up to 500000, 500 megs. After loading all the games all the arenas, NO LEVELS RELIT.......hooray. My only concern now is....what is happening here???. If I load mission 'A' that is 8mb big for the .ml file, quit to the menu and reload that same mission 'A' will the lighting cache jump to 16mb or stay at 8mb. If it jumps to 16mb then that could potentially be a problem.

Anyone have some suggestions?
Hopefully that'll help someone down the road ;-)
Page«First 1 2 Next»