TGE dynamic lights on interiors fix
by Clint S. Brewer · 06/26/2005 (10:35 am) · 27 comments
get your fixed-function pipeline goodness:
I'm using TGE1.3 codebase
This is very simple. I'm just using multitexturing if it's available to render the dynamic lights properly in UnEarthed Gods.
in interiorRender.cc, replace the existing renderLights function with this one.
so now we get destination color + (interior texture color * dynamic light)
in my own quick tests this does what I expected it to do.
Now you can use those dynamic lights in the interiors for torches or whatever other devious dynamic illumination you come up with.
I'm using TGE1.3 codebase
This is very simple. I'm just using multitexturing if it's available to render the dynamic lights properly in UnEarthed Gods.
in interiorRender.cc, replace the existing renderLights function with this one.
void Interior::renderLights(LightInfo* pInfo,
const MatrixF& transform,
const Point3F& scale,
U32* lightSurfaces,
U32 numLightSurfaces)
{
Point3F lightPoint = pInfo->mPos;
transform.mulP(lightPoint);
lightPoint.convolveInverse(scale);
bool useMultiTexture = dglDoesSupportARBMultitexture();
if (useMultiTexture) {
// Base textures
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//light map
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glActiveTextureARB(GL_TEXTURE0_ARB);
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mLightFalloff->getGLName());
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(-1,-1);
for (U32 i = 0; i < numLightSurfaces; i++) {
const Surface& rSurface = mSurfaces[lightSurfaces[i]];
if (useMultiTexture)
{
U32 baseName = mMaterialList->getMaterial(rSurface.textureIndex).getGLName();
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, baseName);
}
const PlaneF& plane = getPlane(rSurface.planeIndex);
Point3F centerPoint;
F32 d = plane.distToPlane(lightPoint);
centerPoint = lightPoint - plane * d;
d = mFabs(d);
if (d >= pInfo->mRadius)
continue;
F32 mr = mSqrt(pInfo->mRadius*pInfo->mRadius - d*d);
Point3F normalS;
Point3F normalT;
if (mFabs(plane.z) < 0.9)
mCross(plane, Point3F(0, 0, 1), &normalS);
else
mCross(plane, Point3F(0, 1, 0), &normalS);
mCross(plane, normalS, &normalT);
normalS.normalize();
normalT.normalize();
PlaneF splane(centerPoint, normalS);
PlaneF tplane(centerPoint, normalT);
F32 factor = (pInfo->mRadius - d) / pInfo->mRadius;
glColor4f(pInfo->mColor.red, pInfo->mColor.green, pInfo->mColor.blue, factor);
glBegin(GL_TRIANGLE_STRIP);
for (U32 j = rSurface.windingStart; j < rSurface.windingStart + rSurface.windingCount; j++) {
const Point3F& rPoint = mPoints[mWindings[j]].point;
if (useMultiTexture)
{
//grab the texture coordinates for the diffuse texture maps
F32 s = mTexGenEQs[rSurface.texGenIndex].planeX.distToPlane(mPoints[mWindings[j]].point);
F32 t = mTexGenEQs[rSurface.texGenIndex].planeY.distToPlane(mPoints[mWindings[j]].point);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,s,t);
}
//apply the texture coordinates for the light map
glTexCoord2f(((splane.distToPlane(rPoint) / mr) + 1.0) / 2.0,
((tplane.distToPlane(rPoint) / mr) + 1.0) / 2.0);
glVertex3fv(mPoints[mWindings[j]].point);
}
glEnd();
}
glDisable(GL_POLYGON_OFFSET_FILL);
if(useMultiTexture)
{
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
}
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glDisable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);
}so now we get destination color + (interior texture color * dynamic light)
in my own quick tests this does what I expected it to do.
Now you can use those dynamic lights in the interiors for torches or whatever other devious dynamic illumination you come up with.
#2
06/10/2005 (4:14 pm)
Robert, glad to hear it works(...strange my account still says that this is unaproved, yet you can see it?)
#3
06/12/2005 (7:28 pm)
I forgot to disable the second texture unit if we are doing multitexturing. cleaned up the function a little and reset that state on exit.
#4
Let me just say, my reasoning for seeing this resource is a weird one. When I get bored, I go through all resources one-by-one by altering the URL.
Example: The resource URL for this resource is www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8021 (as you know), but what I will do when I am bored is alter the URL in increments of one (ie, 8022, 8023) until I find something useful.
I have found quite a few useful resources this way, :P.
Robert
06/13/2005 (5:49 pm)
At the moment of this comment (June 13, 2005) the resource still does not appear to be approved.Let me just say, my reasoning for seeing this resource is a weird one. When I get bored, I go through all resources one-by-one by altering the URL.
Example: The resource URL for this resource is www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=8021 (as you know), but what I will do when I am bored is alter the URL in increments of one (ie, 8022, 8023) until I find something useful.
I have found quite a few useful resources this way, :P.
Robert
#6
This looks really interesting... Good job!
06/14/2005 (4:06 am)
Don't you have a bigger picture of that before and After pic.... ?This looks really interesting... Good job!
#7
06/14/2005 (11:43 am)
yeah it limits the size when you upload it. I didn't post one on my site, but in the pic from my last plan, my character is holding an fxlight, and the warm light arround him on the texture is comming from that, so you could consider that a bigger after pic :)
#8
06/14/2005 (11:46 am)
Now you're forcing me to do this to take my own before and after pic... marketing brilliance ;)
#9

but I still wanna see your own before and after shot too.
The angles aren't quite the same, but the key thing is how blue and washed out the textures are in the dark areas when using dynamic lights... it didn't use the texture map from the interior when rendering the lights.
06/14/2005 (12:00 pm)
ok here's a larger one
but I still wanna see your own before and after shot too.
The angles aren't quite the same, but the key thing is how blue and washed out the textures are in the dark areas when using dynamic lights... it didn't use the texture map from the interior when rendering the lights.
#10
EDIT: Thanx for the Pic!
06/14/2005 (12:03 pm)
Hehe... When I actually get to make something not orange (I'm following HL2 mapping way)EDIT: Thanx for the Pic!
#11
06/23/2005 (10:59 am)
hmmmm long time with no approval on this resource.
#12
06/26/2005 (10:38 am)
Sorry Clint, our bad. Slipped through somehow, but it's up now. :)
#13
Thanks alot !!
06/26/2005 (12:57 pm)
This is a lovely resource ,time for some dynamic shadows and dynamic lights on terrain Clint :)Thanks alot !!
#14

The more clear ness of the the after is awesome!
But you lose some of the light that bounces off the wall and floor.
Nice job even so!
(heh thats defualt torque stuff too)
06/27/2005 (7:21 pm)
Hmm, i have a couple comments of my be4 and after
The more clear ness of the the after is awesome!
But you lose some of the light that bounces off the wall and floor.
Nice job even so!
(heh thats defualt torque stuff too)
#15
(dont know what the "after" at the top of the befor is doing there ,must be a photoshop error)
06/27/2005 (7:26 pm)
crap the more i look at the pic the less i care about the light on the wall and floor , looks great :)(dont know what the "after" at the top of the befor is doing there ,must be a photoshop error)
#16
06/27/2005 (11:41 pm)
The 'after' pic just looks more real... The light as you put it bouncing off the wall looks more evened out in the after pic.
#17
06/28/2005 (2:26 pm)
Heh! thats one way to put it, ammazing what a few lines of code can do for you :).
#18
06/29/2005 (10:25 am)
Quote:Josh said: Sorry Clint, our bad. Slipped through somehow, but it's up now. :)no problem at all thanks for approving it.
Quote:Billy said: This is a lovely resource ,time for some dynamic shadows and dynamic lights on terrain Clint :)very welcome Billy! I doubt I'll get into dynamic shadows land, but I'll do dynamic lights on terrains. I looked into it a bit a week ago, and made some good headway. unfortunately the problem isn't as simple as this fix and takes some relatively large changes to the terrain code. if you're interested I could go into more details.
Thanks alot !!
Quote:Ace said: But you lose some of the light that bounces off the wall and floor.yeah with the new code you might need to up the intensity of your lights to get the same feel, or perhaps lower the overall ambient in your interior.
#19
Thanks
06/29/2005 (2:20 pm)
Love this resorce, thanks man, after sitting down with the lighting pack and installing your resorce i couldint beleve how much everything blended together and looked much clearer. Thanks
#20
07/15/2005 (3:38 am)
looks much, much better thank you
Torque Owner Robert Pierce
Robert