Resource: Ambient Occlusion for TGEA Interiors
by Ryan Mounts · 07/16/2008 (10:18 am) · 59 comments
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)
About the author
#42
07/22/2008 (9:27 am)
So, was that only an AO fix? Or did that fix anything with Torque's lighting at all?
#43
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.
07/22/2008 (9:34 am)
Eric, based on Ryan's commentI 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.
#44
07/22/2008 (9:46 am)
kk, thanks. I kind of suspected that myself. I was still hopeful it'd fix some lighting bugs. ;-)
#45
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?
08/03/2008 (10:27 am)
first off this is a really awesome reasource and i hope im just doing something wrong. 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?
#46
08/03/2008 (1:22 pm)
I got this too. Try slicing-up the geometry into smaller portions.
#47
if you can point in the right direction atleast i may be able to get our engine coder to look at it as well?
08/03/2008 (7:11 pm)
anyone have any idea why larger geometry sets would be messing stuff up and if the problem could be rectified rather than having to slice up geometry? slicing up and placing certain level elements would prove to be quit difficult with some of the structures my level designers have made.if you can point in the right direction atleast i may be able to get our engine coder to look at it as well?
#48
08/03/2008 (8:14 pm)
You're probably not doing anything wrong. I've seen this too (not quite to that extent) but have been too busy to look into it. I'll see what I can do, but it may take a while.
#49
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.
08/04/2008 (5:43 pm)
Okay, got this one fixed. Thankfully it was very simple. In the case where areas are solid black, the ray casts were hitting their own surface and so all rays were being occluded. This is probably due to rounding errors associated with floating point precision. To fix this, simply offset the lexel center slightly in the direction of the lexel normal (new code in bold).// 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) [b]+ 0.005f*lexel.normal[/b];
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.
#50
heres a shot showing it off

thanks for for the help !! the ao looks better and better..
08/09/2008 (11:23 pm)
so what would be a good increment to increase by ? we tried the 0.005 and that did indeed improve , but the problem still arises somewhat. heres a shot showing it off

thanks for for the help !! the ao looks better and better..
#51
08/10/2008 (8:31 pm)
You can make the offset any size you want, but obviously you want to make it as small as possible without getting any black patches. I'd probably just increment it by 0.001 (equivalent to 1 mm in Torque units) until all the black goes away. Just be aware that as the offset increases, the physical accuracy of the AO decreases.
#52
09/07/2008 (6:53 pm)
anyone else still having problems with black areas ? tried messing with the lexel didnt improve much..
#53
09/07/2008 (7:17 pm)
If you want to email me the problem DIF file(s), I can take a look at it for you.
#54
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%A0
09/09/2008 (6:52 pm)
Hey guys,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%A0
#55
11/13/2008 (5:02 am)
Great resource, but now the TGEA 1.7.1 crashes A LOT, it also broke the bloom ?
#56
11/13/2008 (11:42 am)
Hey Petteri, if you're experiencing crashes during gameplay, I can pretty confidently say that it is not related to the proper addition of the AO resource. If it crashes upon relight, saving the mission, or mission loading, then there might be an issue with the lightmap persistence (the code in Appendix B). I haven't had any crashes due to the AO resource and haven't heard of anyone else having this problem (yet). As for the bloom, I'll have to check on that later. You might also try your game on a different machine to see if it behaves differently. Also, if you have other code changes or resources implemented, it might not be playing nicely with them. If so, you could add the AO resource to clean TGEA install to see if that fixes the problems.
#57
Error 1735 error C2666: 'operator *' : 2 overloads have similar conversions "\engine\source\lightingSystem\synapseGaming\interior\sgPlanarMap.cpp 1128
It has something to do with Point3F lexelMid = lexel.worldPos + 0.5f*(sVec + tVec) + 0.005*lexel.normal;
06/04/2009 (5:32 am)
I am getting this error when i compile:Error 1735 error C2666: 'operator *' : 2 overloads have similar conversions "\engine\source\lightingSystem\synapseGaming\interior\sgPlanarMap.cpp 1128
It has something to do with Point3F lexelMid = lexel.worldPos + 0.5f*(sVec + tVec) + 0.005*lexel.normal;
#58
06/08/2009 (11:41 am)
Looks like it's complaining about the 0.005 because there is no multiplication operator for type double. Try using 0.005f instead.
#59
In the scenelighting.cpp, when you add the following:
Just add a 'g' in front of the 'ResourceManager' so it looks like this:
10/11/2009 (5:17 pm)
If you would like to get this working in TGEA 1.8.1 there's only a small change needed beyond the initial installation instructions.In the scenelighting.cpp, when you add the following:
/// AO MOD UPDATE MISSION CRC START
U32 currMissionCRC;
ResourceManager->getCrc(Con::getVariable("$Client::MissionFile"), currMissionCRC);
if(currMissionCRC != gConnectionMissionCRC)
con->setMissionCRC(currMissionCRC);
/// AO MOD UPDATE MISSION CRC ENDJust add a 'g' in front of the 'ResourceManager' so it looks like this:
/// AO MOD UPDATE MISSION CRC START
U32 currMissionCRC;
gResourceManager->getCrc(Con::getVariable("$Client::MissionFile"), currMissionCRC);
if(currMissionCRC != gConnectionMissionCRC)
con->setMissionCRC(currMissionCRC);
/// AO MOD UPDATE MISSION CRC END
Torque 3D Owner Morrock