Game Development Community

Ok this isn

by John Kabus (BobTheCBuilder) · in Torque Game Engine · 11/28/2003 (3:36 pm) · 12 replies

Ok this isn't a bug but the code is too pathetic for a resource...

Luke Jones mentioned an issue with dynamic lights showing up on surfaces facing away from the light source. I said I would take a look at it and here's the fix:

Approximately line 1243 in interiorRender.cc you should have:

Point3F centerPoint;
      F32 d = plane.distToPlane(lightPoint);
      centerPoint = lightPoint - plane * d;
      d = mFabs(d);
      if (d >= pInfo->mRadius)
         continue;

change it to:

Point3F centerPoint;
      F32 d = plane.distToPlane(lightPoint);
      [b]F32 d2 = d;
      if(Interior::planeIsFlipped(rSurface.planeIndex))
         d2 = 0 - d2;
      if(d2 < 0)
         continue;[/b]
      centerPoint = lightPoint - plane * d;
      d = mFabs(d);
      if (d >= pInfo->mRadius)
         continue;

'distToPlane' calculates the distance using:

(plane.normal * point) + plane.d
dotproduct----^

which gives you a signed distance, positive if the point is on the positive side of the plane, negative for the negative side. Using the original value for d the code will skip any planes that have the light on or behind them.

John Kabus.

Edit: fixed reversed plane bug.

#1
11/28/2003 (6:11 pm)
LOL, legendary, 16 chars to fix what was a kinda big problem (depending on your persprctive).

Probably a good idea to slap in HEAD, since it could be called a bug fix!

Would never have guessed.
#2
11/28/2003 (10:21 pm)
@John: Make sure you fire an email to Tim or someone else on GG, I'm sure this would be considered a bug fix.
#3
11/29/2003 (11:25 am)
Yes, this needs to go into HEAD. I'd put it there now, but I'm at a public access computer lab... not the best place to do this. ;)
#4
11/29/2003 (6:08 pm)
Hold the phone!

Theres a few problems with this, it seems to not light every surfaces near as it should.
For example, putting a fxlight in the corner of a room, only one wall gets lit, and if you can move right into the corner, you can get 2 sides lit, but not the top or bottom (roof, floor).

I'll do some more testing and play with that section of code a bit more, might need to make a variable or something.
#5
11/29/2003 (6:26 pm)
Try changing the if statement to the following:

if(d < 0)
#6
11/29/2003 (6:30 pm)
The planes you're having problems with are flipped. Here's the fix:

Point3F centerPoint;
      F32 d = plane.distToPlane(lightPoint);
      [b]F32 d2 = d;
      if(Interior::planeIsFlipped(rSurface.planeIndex))
         d2 = 0 - d2;
      if(d2 < 0)
         continue;[/b]
      centerPoint = lightPoint - plane * d;
      d = mFabs(d);
      if (d >= pInfo->mRadius)
         continue;

Thanks for reporting the bug, if you see any more let me know.

Edit: clarity...
#7
11/29/2003 (8:51 pm)
Good job guys.

That did the trick, I'l try a few differant light styles and see what else come up.
The only other issue with fxLights, is if its in an interior, it will also show on the terrain even though its complety held in the interior.

*edit*
This seems to make the light blend on to the surface better too.
Before it looked like, say, get 3 tubes and put them on an x,y,z (like a cross) and the ends of each were the light on the interior walls, with slight blending, overall effect still looked like 'spots'.
This fix makes it blend together alot more realisticly, or so it seems.
I'll get some before/after screens together at some point.
#8
11/30/2003 (12:46 pm)
I'd love to see that.
#9
11/30/2003 (9:03 pm)
After.
homepages.ihug.co.nz/~lukenukem/images/fxlight-fix.JPG
Sorry i havnt got round to getting a before pic.
#10
11/30/2003 (9:22 pm)
That looks really good! Wow!

Are there other fixes in that? :)
#11
12/01/2003 (11:33 am)
Hi Luke,

Yes you will still see the light shining on the terrain and through walls. This fix only stops the light from interacting with surfaces facing away from it; the light still doesn't calculate shadows.

Can you post your picture with the three tubes? I'm curious to see the improvement.


Hey Ben,

Are you still adding bug fixes into Torque or should I be emailing Tim with my changes (I'm never sure)?

Thanks!

John.
#12
12/01/2003 (1:52 pm)
Not sure if you can see the differance, but
homepages.ihug.co.nz/~lukenukem/images/fxlight-before.JPGThe after shot looks more evenly lit than this.