Game Development Community

Torque Shadow Bug

by Mark Owen · in Torque Game Engine · 12/31/2003 (3:10 pm) · 12 replies

UPDATED 1/2/2004 - A cleaner and somewhat more efficient method (simpler change, less dereferncing, bigger compile/link).

Here's a complete alternative correction for this bug derived in part from Mark Harmon's posted code which eliminates all the hard coded light references and substitutes the sun's direction vector for them instead. It correctly renders the player shadow on DIF's and terrain, corresponding to the sun's position.

In scenegraph.h immediately following the statements:
extern SceneGraph* gClientSceneGraph;
extern SceneGraph* gServerSceneGraph;

paste the following code
inline Point3F gGetSunDirection()
{
 LightManager *pLightMgr=gClientSceneGraph->getLightManager();
 if ( pLightMgr->getNumLights() > 0 ) // we have lights
   return  pLightMgr->getLight(0).mDirection; //first is sun  
 return Point3F(0.57735f, 0.57735f, -0.57735f); // default
}

In renderShadow(F32 dist, F32 fogAmount) of both shapebase.cc and tsstatic.cc replace

Point3F lightDir = (0.57f,0.57f,-0.57f);

with

Point3F lightDir = gGetSunDirection();

In SceneObject::installLights of sceneobject.cc replace

light.mDirection = VectorF(0.57735f, 0.57735f, -0.57735f);
with
light.mDirection = gGetSunDirection();

#1
01/01/2004 (11:22 am)
Not exactly sure why but I had to 'extern' gGetSunDirection(); not only in sceneObject.cc but also in tsStatic.cc and shapeBase.cc in order to compile. Without the additional extern's I got an 'error C2065: 'gGetSunDirection' undeclared identifier'.
#2
01/02/2004 (5:08 pm)
Chris... I missed a line of code in the shadow.h above when I posted it here... its been revised above to remedy the omission. Thanks!
#3
01/02/2004 (6:14 pm)
No problem, I figured it was something wrong on my end. :) Great fix, by the way!
#4
01/02/2004 (6:30 pm)
That's cleaner. I really think there should be a variable that is updated by the light manager. That way no need to do all that pointer math to get the sun vector for every shape.
#5
01/02/2004 (7:04 pm)
Does this work with the day/night code?
#6
01/02/2004 (9:48 pm)
Mark.. you're right. It would save a bit of time if a pointer to the sun was stashed off somewhere... but where in the hierarchy? I'll look into it further when I get a chance since SceneObject::installLights is called frequently enough to warrant it.

Kuhles.. I have not tried it with night. If you try it out let us know the result.
#7
01/02/2004 (10:25 pm)
Hopefully the update I just posted is a bit faster. Its definitely easier to implement, although the compile and link takes a while longer because of the change to scenegraph.h
#8
01/03/2004 (12:07 pm)
If you're using my day/night code, there is a DaylightCycle:: function for getting the sun vector, so just use that function.
#9
09/15/2004 (9:21 am)
Is the a fix for the bug where the player's shadow reverses direction when
the player steps onto an interior instance ?

eg in the torque SDK starter FPS, version 1.2.2,
walk onto any of the docks and notice
1. the player's shadow flips direction when standing on the dock
2. when on the dock, the player's shadow is in the opposite direction of the pilings.
#10
09/15/2004 (11:23 am)
It doesn't seem to happen in the cvs version.

Ben
#11
09/15/2004 (11:43 am)
You mean the cvs version of release 1.2.2 ?
hm.
maybe i'll try a clean compile.

i notice it doesn't happen in the precompiled Demo App,
altho in there it does appear that the local lighting
on the player mesh flips when you step onto the dock.

and the dock piling shadows are in a different direction than the player's.
#12
09/15/2004 (2:02 pm)
Doesn't
LightManager::getShadowLightDirection()
perform the same function as:
Point3F gGetSunDirection()?

As well as it uses the "mSunLight" which is what the code seems to be migrating towards for sunlight instead of the "pLightMgr->getLight(0).mDirection;"

Just a thought. Correct me if I am wrong.