by date
Resource: Ambient Occlusion for TGEA Interiors
Resource: Ambient Occlusion for TGEA Interiors
| Name: | Ryan Mounts | |
|---|---|---|
| Date Posted: | Jul 16, 2008 | |
| Rating: | 5.0 out of 5 | |
| Public: | YES | |
| Comments: | YES | |
| RSS Feed: | or Subscribe with . | |
| Profile Page: | View profile page for Ryan Mounts |
Blog post
NOTICE: Resource updated 8/4/08.
Link to TGEA AO Resource
Well, as I figured, the ambient occlusion code was very simple to port over from TGE, but the lightmap persistence and caching took a little more work. Hopefully everyone will find this useful. This is a feature that I've been wanting to see in Torque for a long time, so I'm pretty excited to see it coming together.
For those of you who have already looked at the TGE version of this resource, I suggest at least reading over the Persistence and Caching section again, because the TGEA version behaves slightly differently.
As before, if anyone finds/fixes any bugs, enhances performance, or makes interesting modifications to this resource, please share!
Pics: Side-by-side comparisons of two identical interiors, one with AO and one without. In the first pic, there are two small boxes in the Cornell box on the right, I promise! :) You just can't see them because the ambient light is constant and the textures are a single color. This just illustrates how much visual "pop" AO can add to an interior.


(Church dif created by Benjamin Naulls, of course)
Link to TGEA AO Resource
Well, as I figured, the ambient occlusion code was very simple to port over from TGE, but the lightmap persistence and caching took a little more work. Hopefully everyone will find this useful. This is a feature that I've been wanting to see in Torque for a long time, so I'm pretty excited to see it coming together.
For those of you who have already looked at the TGE version of this resource, I suggest at least reading over the Persistence and Caching section again, because the TGEA version behaves slightly differently.
As before, if anyone finds/fixes any bugs, enhances performance, or makes interesting modifications to this resource, please share!
Pics: Side-by-side comparisons of two identical interiors, one with AO and one without. In the first pic, there are two small boxes in the Cornell box on the right, I promise! :) You just can't see them because the ambient light is constant and the textures are a single color. This just illustrates how much visual "pop" AO can add to an interior.


(Church dif created by Benjamin Naulls, of course)
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 your own resources!| Ryan Mounts (Jul 16, 2008 at 17:27 GMT) |
| James Ford (Jul 16, 2008 at 17:27 GMT) Resource Rating: 5 |
Now all we need is AO for dts and players '-)
| Taylor Petrick (Jul 16, 2008 at 17:35 GMT) Resource Rating: 5 |
Edit: I believe congratz is spelt with a t, not a d...
Edited on Jul 16, 2008 17:42 GMT
| Ryan Mounts (Jul 16, 2008 at 17:35 GMT) |
There is no performance hit in-game because the AO is baked into the interior's lightmap. All calculations are done "offline," so to speak, during the scene relight.
| Eric Forhan (Jul 16, 2008 at 17:54 GMT) Resource Rating: 5 |
Is there any way to include pre-compiled AO cache files? Or move a lot of the calculations over into map2DIF?
Thanks for your hard work... I've been wanting AO for quite some time!
| Taylor Petrick (Jul 16, 2008 at 18:47 GMT) Resource Rating: 5 |
Yeah, I too noticed that the re-light time drastically increases. I'm gonna try it on my 3GB RAM / quad core tomorrow, just to see how long it would take to relight on a map with every difs on high. What I plan to do is, before release, render the final lightmap and then remove the scene lighter from the mission download. That way no players will accidenally end up waiting an eternity for their game to load.
| Morrock (Jul 16, 2008 at 18:48 GMT) Resource Rating: 5 |
| Ryan Mounts (Jul 16, 2008 at 18:54 GMT) |
Yeah, it would be nice to be able to bake the AO at dif creation time if you were going to drop dozens of the same interior into a scene and didn't really care if the AO interacted with objects in the world. Then you'd only have to do the calculation once.
I don't remember what the lightmap code looks like in map2dif, but it's probably similar enough to the engine that the AO code could be dropped in there. I'll look into it when I get a chance. It'd be nice if it could be added to Constructor where you could tweak the AO and see it before export... plus you could use the internal exporter. Maybe Jaimi would be up for that! ;)
Also, relight times will be affected by the "light_geometry_scale" (it basically controls the resolution of your lightmap) and the number of LODs, since AO will get calculated for each LOD. Unless you have REALLY high resolution lightmaps or an annoyingly splotchy area, you shouldn't really need to go above Low quality. A good method for adding AO to a scene with many interiors is to use the filtered relight instead of the full. Don't worry, once an AO enabled interior is out of range of the filtered relight, it will still keep its lightmap. This way you can update only one or two interiors at a time, allowing for quicker feedback.
Edited on Jul 16, 2008 19:22 GMT
| Eric Forhan (Jul 16, 2008 at 19:58 GMT) Resource Rating: 5 |
I'm sure using only DIF-baked lights instead of sgLights would probably speed it up some too. They don't seem to be taken account of anyway, so it may as well be done in the DIF.
Do you think could take a snapshot of either of those same scenes from the same angle with the AO settings reversed? Just for a better comparison?
| Apparatus (Jul 16, 2008 at 20:15 GMT) Resource Rating: 5 |
| Ryan Mounts (Jul 16, 2008 at 20:38 GMT) |

| ando (Jul 16, 2008 at 21:09 GMT) |
| James Brad Barnette (Jul 16, 2008 at 21:37 GMT) |
is it me or is the quality of the effect better in TGEA? At least that is the way it looks from the screen shots
Edited on Jul 16, 2008 21:38 GMT
| Brian \\\"Cybore\\\" Smith (Jul 16, 2008 at 22:59 GMT) |
| Ryan Mounts (Jul 17, 2008 at 04:09 GMT) |
@Ando - Here is a clean build + AO mod.
And thanks for the encouraging comments everyone... :)
Edited on Jul 21, 2008 22:03 GMT
| J.C. Smith (Jul 17, 2008 at 13:34 GMT) Resource Rating: 5 |
| ando (Jul 17, 2008 at 18:00 GMT) |
The only snag is it seems to favor having ambient shadows going up instead of going down, it just looks a bit odd.
| Orion Elenzil (Jul 17, 2008 at 18:16 GMT) |
Ando,
could you elaborate on that a bit ? Maybe a screenshot ?
| ando (Jul 17, 2008 at 19:02 GMT) |

Edited on Jul 17, 2008 19:24 GMT
| Morrock (Jul 17, 2008 at 19:45 GMT) Resource Rating: 5 |
edit: Never mind, just tried this out for myself with several relights and different settings, it is definately darker on top.
Edited on Jul 17, 2008 19:58 GMT
| Ryan Mounts (Jul 17, 2008 at 20:59 GMT) |
| Orion Elenzil (Jul 17, 2008 at 21:21 GMT) |
if there is a bug in the underlying LM technique, the AO code might present an opportunity for accounting for it. eg, you could orient the hemisphere slightly towards "down", which would shoot more rays "down" and tend to make that side a bit darker, i think.
| Morrock (Jul 17, 2008 at 21:43 GMT) Resource Rating: 5 |
// Generate a random vector between (-1,-1,-1) and (1,1,1)
randPt.set(gRandGen.randF(-1.0f,1.0f),
gRandGen.randF(-1.0f,1.0f),
gRandGen.randF(-1.0f,1.0f));
to
// Generate a random vector between (0,0,0) and (1,1,1)
randPt.set(gRandGen.randF(0.0f,1.0f),
gRandGen.randF(0.0f,1.0f),
gRandGen.randF(0.0f,1.0f));
You obviously don't have to change the values in the comments, that mainly for keeping track of it. What this does is instead of generating a random normal from negatives to positive, it just generates it from 0 to postive. Actually, you could probably just change the z random for this to work, lemme check...
Well, that screenshot doesn't show it off too well, but it definately feels more balanced. I'd be up for helping to track down the lightmapping problem however, real solution > angling hack.

Edited on Jul 17, 2008 22:00 GMT
| ando (Jul 17, 2008 at 22:06 GMT) |
Also could it be related to the normal map bug? http://www.garagegames.com/mg/forums/result.thread.php?qt=76412
| Morrock (Jul 17, 2008 at 22:15 GMT) Resource Rating: 5 |

Edited on Jul 17, 2008 22:21 GMT
| Kory James (Jul 18, 2008 at 04:05 GMT) |
| Edward Smith (Jul 18, 2008 at 11:47 GMT) |
| ando (Jul 18, 2008 at 11:48 GMT) |
Be great to get rid of the nasty border lines in map2dif
| Ryan Mounts (Jul 18, 2008 at 14:25 GMT) |
I'm not quite sure how you generated that bottom pic... changing the random vector bounds doesn't really affect anything. You could change the random vector to a constant vector if you wanted (it just can't be the same direction as your surface normal), and the only visual difference will be some shadow banding that is related to the gaps between the ray dome vectors. Randomizing the lexel basis helps to smooth this banding effect.
@Ando
My hunch is that it has something to do with the lexel creation code... I remember looking at that code once and noticing something interesting. The lexels overhang the surface borders by about half a lexel all the way around (I believe this is what leads to light leaks, when the overlap is big enough to reach underneath a wall to the other side). But if the lexels overhang more on one side than another, that would definitely either cause the AO to be darker on that side, or cause a "light leak" if the lexel was inside a wall 'cause the ray casts wouldn't hit anything and it'd appear unoccluded. Anyway, this is kinda tough to track down...
| Morrock (Jul 18, 2008 at 15:27 GMT) Resource Rating: 5 |
You were right, I left in a few lines of code from when I tried messing with the algorithm (I do this way too much). Now I'm not sure how I got that first screenshot of the extrusion being darker on the bottom...
@Kory
The problem with ambient occlusion for those non-static objects (animated objects, physics objects, players) is that in this AO algorithm, it determines occlusion by doing raycasts in all directions to check how occluded the space around it is. It bakes it into the lightmap, so no calculation is done in-game. But with non-static objects, the space around them may become more/less occluded as they move around, or as other objects interact with them; so it would need to be calculated and shaded in real-time. This method takes far to long to do real-time calculation. I would love to try to tackle something like real-time "ambient occlusion", but right now I don't know enough shader language to write most methods (like SSAO) or know how Torque does shadows well enough if I were to try to do it in the engine.
| Ryan Mounts (Jul 18, 2008 at 16:55 GMT) |

Edited on Jul 18, 2008 16:56 GMT
| Morrock (Jul 18, 2008 at 21:22 GMT) Resource Rating: 5 |
| Ryan Mounts (Jul 18, 2008 at 22:46 GMT) |
for(U32 i=0; i<sgPlanarLightMap::sglpCount; i++)
{
// set which list...
U32 templexelscount;
sgLexel *templexels;
if(i == sgPlanarLightMap::sglpInner)
{
templexelscount = sgInnerLexels.size();
templexels = sgInnerLexels.address();
}
else
{
templexelscount = sgOuterLexels.size();
templexels = sgOuterLexels.address();
}
So down where the texels get set, you can test if(i != sgPlanarLightMap::sglpInner) then make the texel red. Then I commented out the sgBlur line in sgMergeLighting so I could see the lexels clearly. Now why there is an outer lexel in the center of the ledge, the only thing I can think of that could cause that is if the lexel lied exactly on the center of that face. For a rectangular surface like that, the center happens to lie on the shared edge between the two tris that form the surface. All lexels on a tri edge are classified as outer. The AO doesn't depend on the inner/outer concept, so that shouldn't really matter.
As a side note, my hunch has shifted slightly, but I'll elaborate when I have more info.
Edited on Jul 18, 2008 23:01 GMT
| Ryan Mounts (Jul 19, 2008 at 17:31 GMT) |
| James Brad Barnette (Jul 19, 2008 at 17:42 GMT) |
| ando (Jul 19, 2008 at 20:08 GMT) |
| Ryan Mounts (Jul 21, 2008 at 14:58 GMT) |
If you don't want to download the resource again, here are the code changes in bold. This is in the AO code in sgCalculateLighting...
/// AO MOD LEXEL OCCLUSION START
if(sgInteriorInstance->mAO)
{
F32 sum = 0.0f;
F32 *rayDome;
F32 rayArea;
F32 AO;
F32 alpha;
U32 rayCount;
Point3F tangent, binormal, randPt, ray;
RayInfo info;
// Calculate the world position of the lexel center
Point3F sVec(sgLightMapSVector.x, sgLightMapSVector.y, sgLightMapSVector.z);
Point3F tVec(sgLightMapTVector.x, sgLightMapTVector.y, sgLightMapTVector.z);
Point3F lexelMid = lexel.worldPos + 0.5f*(sVec + tVec);
// Cast a ray along the tranformed direction
if(gClientContainer.castRay(lexelMid, lexelMid + ray, mask, &info))
{
// Return ray to unit length before dot product
ray /= sgInteriorInstance->mAORadius;
// Sum up cos(angle between normal and ray) for all occluded rays
sum += mDot(lexel.normal, ray);
}

Edited on Jul 21, 2008 15:04 GMT
| Ryan Mounts (Jul 21, 2008 at 22:00 GMT) |
| ando (Jul 22, 2008 at 00:32 GMT) |
Edited on Jul 22, 2008 00:33 GMT
| Stefan *Shaderman* Greven (Jul 22, 2008 at 13:29 GMT) Resource Rating: 5 |
| Morrock (Jul 22, 2008 at 16:24 GMT) Resource Rating: 5 |
| Eric Forhan (Jul 22, 2008 at 16:27 GMT) Resource Rating: 5 |
| Orion Elenzil (Jul 22, 2008 at 16:34 GMT) |
I had made a wrong assumption that lexel.worldpos was the center of the lexel when it is actually the lower left corner. So the rays were being projected from the corner of the lexel instead of the center, which biased the shadow to the bottom and left. To fix it, I simply calculate the center of the lexel and shoot rays from there. :),
i would expect that stock lighting was already correct, and this fix only affects AO.
| Eric Forhan (Jul 22, 2008 at 16:46 GMT) Resource Rating: 5 |
| Fleeky (Aug 03, 2008 at 17:27 GMT) |
our coder friend got this integrated into our tgea build and i used the ray length 3 quality poor multiplier 1 settings and this is what i got..



have any idea whats going on and how we could get this looking a bit better?
Edited on Aug 03, 2008 18:06 GMT
| Eric Forhan (Aug 03, 2008 at 20:22 GMT) Resource Rating: 5 |
| Fleeky (Aug 04, 2008 at 02:11 GMT) |
if you can point in the right direction atleast i may be able to get our engine coder to look at it as well?
| Ryan Mounts (Aug 04, 2008 at 03:14 GMT) |
| Ryan Mounts (Aug 05, 2008 at 00:43 GMT) |
// Calculate the world position of the lexel center
Point3F sVec(sgLightMapSVector.x, sgLightMapSVector.y, sgLightMapSVector.z);
Point3F tVec(sgLightMapTVector.x, sgLightMapTVector.y, sgLightMapTVector.z);
Point3F lexelMid = lexel.worldPos + 0.5f*(sVec + tVec) + 0.005f*lexel.normal;
I used an offset of 0.005, but this number is not set in stone. If you still run into patches of black, just increase this value in small increments until they're gone. I'll try to update the resource link in a minute. Please let me know if this fixes your problems. Since I only had one interior that exhibited this behavior in a small area, I can't be sure it addresses all cases.
| Fleeky (Aug 10, 2008 at 06:23 GMT) |
heres a shot showing it off

thanks for for the help !! the ao looks better and better..
Edited on Aug 10, 2008 07:05 GMT
| Ryan Mounts (Aug 11, 2008 at 03:31 GMT) |
| Fleeky (Sep 08, 2008 at 01:53 GMT) |
| Ryan Mounts (Sep 08, 2008 at 02:17 GMT) |
| Lorne McIntosh (Sep 10, 2008 at 01:52 GMT) |
I've just created a great Screen Space Ambient Occlusion Shader that would make a great addition to this light baking exporter. It creates real time ambient occlusion on anything in the scene: DIF, DTS, animated DTS, and players. I'm selling the shaders for a very reasonable price if you want to add it into your game and get some nice AO happening. www.ubiqvisuals.com
I've put a video on my website so you can see it with dif and animating dts models. www.ubiqvisuals.com/index.php?option=com_content&view=article&id=46%C2%A...

Edited on Sep 10, 2008 02:04 GMT
| Petteri Huttunen (Nov 13, 2008 at 13:02 GMT) |
| Ryan Mounts (Nov 13, 2008 at 19:42 GMT) |
You must be a member and be logged in to either append comments or rate this resource.


5.0 out of 5


