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.
#22
08/21/2005 (9:23 am)
very welcome all, glad to hear it works well with the lighting pack too.
#23
Clint, when you have time, could you take a look at the TGE 1.4 renderlights function below -- does it look to you like GG integrated or superceded this?
Thanks!!!
04/13/2006 (11:27 pm)
Looking at the code above and comparing it to the TGE 1.4 renderlights function, I can't tell if this has been integrated into 1.4 or if it's still not in there....Clint, when you have time, could you take a look at the TGE 1.4 renderlights function below -- does it look to you like GG integrated or superceded this?
Thanks!!!
// From TGE 1.4
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);
if (dglDoesSupportARBMultitexture())
{
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mLightFalloff->getGLName());
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
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]];
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;
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);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glDisable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ZERO);
}
#24
the main change I made was to take into account the diffuse base texture colors, and mix it with the light texture. doesn't look like the code snippet you posted is doing it. I suspect this particular 1.4 code has changed little from 1.3.
04/14/2006 (12:54 am)
Hi Darrel, just glancing at the code you posted, it doesn't look like it's doing anything that this resource adds.the main change I made was to take into account the diffuse base texture colors, and mix it with the light texture. doesn't look like the code snippet you posted is doing it. I suspect this particular 1.4 code has changed little from 1.3.
#25
06/21/2006 (8:10 am)
Now we just need something like this for terrain because it gets to a point where the terrain seems textureless with light
#27
[edit]
nevermind, I lied....
02/03/2010 (11:17 pm)
hmmmm, this seems to have some really wacky shadowing effects in outdoor maps with .dif objects [edit]
nevermind, I lied....
Torque 3D Owner Randy Mlinarcik
I'm still pretty new to this whole thing...
EDIT: I combined the code snippets from this resource and the Lighting Pack and it works fine.