Previous Blog Next Blog
Prev/Next Blog
by date

Native Ambient Occlusion for Interiors in TGE

Native Ambient Occlusion for Interiors in TGE
Name:Ryan Mounts 
Date Posted:Jun 25, 2008
Rating:5.0 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Ryan Mounts

Blog post
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.



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.



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. :)

Recent Blog Posts
List:07/16/08 - Resource: Ambient Occlusion for TGEA Interiors
07/11/08 - Resource: Ambient Occlusion for TGE Interiors
06/25/08 - Native Ambient Occlusion for Interiors in TGE
06/17/08 - Custom Lightmaps for TGEA Interiors
04/03/08 - Add Custom Lightmaps to Interiors
01/24/08 - Update: Max2Ctor 1.0.1
01/10/08 - Tutorial: Export 3dsmax directly to Constructor
01/09/08 - Free Resource for 3dsmax Users

Submit ResourceSubmit your own resources!

Stephan (viKKing) Bondier   (Jun 25, 2008 at 20:27 GMT)
8-P

Really nice. Awesome work.

James Brad Barnette   (Jun 25, 2008 at 21:03 GMT)
nay vhance this code will be release so that it can be added to TGEA?

Ryan Mounts   (Jun 25, 2008 at 21:25 GMT)
Yeah, after I get it tweaked in TGE, I'll try to get a TGEA version out (hopefully next week).

Apparatus   (Jun 26, 2008 at 04:37 GMT)
I've been following this for a time, I really like the outcome. Congrats.

ando   (Jun 26, 2008 at 14:44 GMT)
Great stuff Ryan, cant wait

Mark Dynna   (Jun 26, 2008 at 15:09 GMT)
Looks really good. This has the potential to be a permanent engine addition, I think.

Xavier "eXoDuS" Amado   (Jun 28, 2008 at 00:50 GMT)
I can't recall, but doesn't map2dif calculate lightmaps when it exports? The engine at load time only adds the sun shadows IIRC. Maybe this could be integrated with map2dif, so it generates ambient occlusion on any dif lights exported. The sun light is only useful in dif's that have an opening towards the exterior.

Just a thought, it looks very nice. Great work!

Ryan Mounts   (Jun 28, 2008 at 05:15 GMT)
Yes, this could very easily be integrated into map2dif. The only problem is if you want to tweak the effect, you would have to re-export with the new parameters and open up Torque again every time. This would quickly get annoying after a few iterations. It could also be integrated directly into Constructor, but I don't have the code for that. ;) Calculating the AO inside Torque gives an additional benefit over both those options... it allows the shadowing to interact with other things in the world, like the terrain, static objects, and other nearby interiors.
Edited on Jun 28, 2008 05:16 GMT

James Brad Barnette   (Jun 28, 2008 at 15:32 GMT)
yeah keep it in torque. no exporter non-sense.
@ryan:

in the picture of the with it at high above. On the floor on the right hand side the shadow of the small box still seems to be pixelated while all of the other angled stuff appears to be" at least from the picture angle" smooth. Is there any explanation of this or are other edges this way as well and we just cant see them?

one more question is this process fully threaded so that it would take advantage of SMP systems? and is it Video hardware Dependant for its generation or would it work on pretty much anything that is capable of the running the engine
Edited on Jun 28, 2008 15:34 GMT

Ryan Mounts   (Jun 28, 2008 at 16:49 GMT)
@James

The pixelated shadow you're referring to is a diffuse light shadow cast from the sun, so it doesn't have anything to do with the ambient occlusion code. If you notice, that shadow is exactly the same in every image, since I didn't change the sun. Not really sure why that little section is rougher than the rest.

The algorithm itself is single threaded. This doesn't mean that it wouldn't benefit from SMP systems. I don't know for a fact, but the way the light manager handles queued lighting events is most likely multi-threaded. If so, this would distribute the AO calculations for different interiors to different cores. And no, it's not tied to any video hardware. It should work on anything. :)
Edited on Jun 28, 2008 16:53 GMT

Stefan Lundmark   (Jun 30, 2008 at 11:09 GMT)
Ryan,

Are you doing these calculations in scene-relighting or somewhere else? Really interesting work!

Ryan Mounts   (Jun 30, 2008 at 13:25 GMT)
@ Stefan

Yup, it's done in the scene relight code.

Kory James   (Jul 09, 2008 at 20:38 GMT)   Resource Rating: 5
I had a problem adding the code to tgea 1.7.1 I got a fatal error after compiling it. I was wondering did anyone else have it too. I think the error was coming from the interior I/O. If someone could help me out it would be great!

thx

James Brad Barnette   (Jul 09, 2008 at 22:07 GMT)
any update on getting this in to TGEA?

Ryan Mounts   (Jul 10, 2008 at 05:39 GMT)
@Kory

I think you meant to post in the thread for custom lightmaps in TGEA. The code in this thread hasn't been released yet. The only thing that was changed in the Interior I/O was the four places where "smFileVersion == 0" was changed to "smFileVersion == 1". You might try changing them back to "smFileVersion == 0" and just adding " || smFileVersion == 1" to each of the if-statements. I think that should allow you to load old map2dif files and still leave the backwards compatibility that might have been causing the error.

@James

I just got the persistence part of the code working the way I wanted today in TGE. So I'll try to package it up and post a resource within the next day or two. If you're familiar enough with TGEA, you might be able to port it over yourself. The persistence code was actually very difficult for me to iron out, and I have a feeling TGEA might pose some more problems... so I'm not sure when a TGEA version will be posted.

Associa   (Jul 29, 2008 at 23:02 GMT)   Resource Rating: 5
That is really useful Ryan. Congratulations!

You must be a member and be logged in to either append comments or rate this resource.