Incorrect light source when shapeBase is on an interior
by Ben Carnes · in Torque Game Engine · 03/25/2004 (7:41 am) · 4 replies
The light direction vector in shapeBase.cc is hardcoded in, causing the shadow to not correlate with the light source. I fixed this problem by changing
around line 2513 to the following
This works perfectly. The shodow correctly hits both the terrain and interiors and the shapeBase object is correctly lit.
Then I discovered another problem. When a shapeBase object has the same x,y coordinates as an interior object, the light source changes to some apparently hard-coded value. This looks bad when a shapeBase object is on top of an interior, where the sunlight should be the light source.
Does anybody know how to fix this? Does the sun use a different index in the light manager when a shapebase is on an interior?
Point3F lightDir(0.57f,0.57f,-0.57f);
around line 2513 to the following
Point3F lightDir;
// Do we have any lights?
if ( gClientSceneGraph->getLightManager()->getNumLights() > 0 )
{
// Yes, so fetch sunlight ( always first light ).
// calculate real sun elevation/azimuth.
LightInfo sunLight = gClientSceneGraph->getLightManager()->getLight(0);
lightDir = sunLight.mDirection; //first light is always sun
}
else
{
// No, so set default light.
lightDir.set( 0.5, 0.5, -0.5 );
}
// Normalise light direction.
lightDir.normalize();This works perfectly. The shodow correctly hits both the terrain and interiors and the shapeBase object is correctly lit.
Then I discovered another problem. When a shapeBase object has the same x,y coordinates as an interior object, the light source changes to some apparently hard-coded value. This looks bad when a shapeBase object is on top of an interior, where the sunlight should be the light source.
Does anybody know how to fix this? Does the sun use a different index in the light manager when a shapebase is on an interior?
About the author
#2
Don't remember the exact spot this is in, but check sceneligthing
03/25/2004 (8:10 am)
It's because once you're in or on an interior, the code switches to another instance of the same hardcoded value, so you see the jump because the light vector changes from your sun value to the hardcoded valueDon't remember the exact spot this is in, but check sceneligthing
#3
One way you could fix this, which was suggested to me by Tim Gift is to do a series of raycasts around the player, say 6 to 8, and average the light values as they are collected from each end point in the raycast.
Look in sceneObject.cc, SceneObject::installLights.
03/25/2004 (8:12 am)
We fixed this in Legends by doing a second raycast towards the direction of the sun however there are still a few problems with this method as well.One way you could fix this, which was suggested to me by Tim Gift is to do a series of raycasts around the player, say 6 to 8, and average the light values as they are collected from each end point in the raycast.
Look in sceneObject.cc, SceneObject::installLights.
#4
03/25/2004 (8:28 am)
Thanx, I'll try raycasting from shapeBase to sun. It doesn't have to be perfect if it isn't noticably bad.
Torque Owner Ben Carnes