Torque's dynamic shadows
by Gerald Fishel · in Torque Game Engine · 04/16/2004 (2:33 pm) · 56 replies
Hi all,
I'm interested in learning about how Torque handles the dynamic shadows, and if it is a reasonable task to apply the shadows to new renderable types. Would I need to handle the shadow casting within the new types, or is there some type of container that holds polygons which the shadows can be cast on to?
Also, what about adding new polygons to the static lighting, as far as them casting static shadows on the terrain?
Any advice on where to begin in these ventures would be most appreciated.
Thanks
I'm interested in learning about how Torque handles the dynamic shadows, and if it is a reasonable task to apply the shadows to new renderable types. Would I need to handle the shadow casting within the new types, or is there some type of container that holds polygons which the shadows can be cast on to?
Also, what about adding new polygons to the static lighting, as far as them casting static shadows on the terrain?
Any advice on where to begin in these ventures would be most appreciated.
Thanks
#42
04/30/2004 (9:42 pm)
I think you guys should release it as a resource once its complete.
#43
04/30/2004 (10:58 pm)
Awesome work, guys. This is really coming together. The information from this thread should definitely be made into a resource!
#44
click here - 8 Meg Windows Media File
Sorry about the shaky cam look. It was done very quickly.
You can see that the shadow suddenly appears in the morning and quickly vanishes at night. You will also notice that the building's shadows are all the same direction.
What I will be working on is:
1 - Fix it so only 1 FXSunlight registers for shadows (no since in have 2 or more fxSunlights that are in the same spot all casting shadows)
2 - Add the ability for shadows to fade in and fade out at least for the day/night. I don't think a fade in/fade out will look good for the issue Gerald mentioned above.
3 - get the buildings to cast a proper shadow.
4 - get the trees to "not glow in the dark"
5 - Ensure Multiplayer still works. If it doesn't fix that.
If anyone has fixed one or more of the above, or has pointers I would greatly appreciate it.
I am also up for merging the day night with seasons with the code in this thread as one resource (with proper credit to everyone else - they did the hard work)
05/01/2004 (4:42 am)
Here is the video I failed to upload last night. click here - 8 Meg Windows Media File
Sorry about the shaky cam look. It was done very quickly.
You can see that the shadow suddenly appears in the morning and quickly vanishes at night. You will also notice that the building's shadows are all the same direction.
What I will be working on is:
1 - Fix it so only 1 FXSunlight registers for shadows (no since in have 2 or more fxSunlights that are in the same spot all casting shadows)
2 - Add the ability for shadows to fade in and fade out at least for the day/night. I don't think a fade in/fade out will look good for the issue Gerald mentioned above.
3 - get the buildings to cast a proper shadow.
4 - get the trees to "not glow in the dark"
5 - Ensure Multiplayer still works. If it doesn't fix that.
If anyone has fixed one or more of the above, or has pointers I would greatly appreciate it.
I am also up for merging the day night with seasons with the code in this thread as one resource (with proper credit to everyone else - they did the hard work)
#45
I'm just trying to think of low impact patches.
05/01/2004 (12:13 pm)
I like the idea of merging; it might be nice not to require the daynightseasons stuff, though? ie, make them integrate but don't make them dependencies?I'm just trying to think of low impact patches.
#46
You could always release a minor release and incorperate these changes as well as a few others that have been found around. Atleast with a minor release people would be expecting some differences.
Ben
05/02/2004 (1:03 pm)
Hello Ben, You could always release a minor release and incorperate these changes as well as a few others that have been found around. Atleast with a minor release people would be expecting some differences.
Ben
#47
05/02/2004 (2:10 pm)
I don't think this will go into HEAD any time soon. I'm just thinking of good ways to break this stuff up into resources.
#48
Either way I don't know what Gerald's plans are but I am moving forward with the integration of the Day/Night with the shadows. I am learning too much about the engine to stop now!
Taking Ben's advice I have been working on enables/disables for both the shadows and the day night. Not as "clean" as I would like but its getting there. I can upload another video if there is interest.
05/03/2004 (5:43 am)
Would anyone want this as a patch after Synapse Gaming: Lighting Pack has been released? "It allows allow static DTS objects to cast shadows." Seems that might be a more comprehensive way to go. Either way I don't know what Gerald's plans are but I am moving forward with the integration of the Day/Night with the shadows. I am learning too much about the engine to stop now!
Taking Ben's advice I have been working on enables/disables for both the shadows and the day night. Not as "clean" as I would like but its getting there. I can upload another video if there is interest.
#49
05/03/2004 (6:10 am)
I think this would be a great addition to Torque especially with the Lighting pack, since the shadows with this are only for static DTS objects. Oh, and videos are always cool and inspiring!
#50
Split into two posts because of limit...
05/03/2004 (6:42 am)
You know, in my Stencil Shadows resource, I had the exact same issues as some of your are discussing here. I wanted shadows to fade-in/fade-out based on proximity to the light. Plus, I also used points around the bounding box to determine occlusion for an object and averaged the number of visible points around the BBox to get an alpha value for my shadows. I had to turn it off, due to issues with generalizing the shadows, but here is some of the code (which may or may not be helpful):Split into two posts because of limit...
#51
okay.... THREE posts because of limit
05/03/2004 (6:43 am)
// Utility function that determines light type and returns a position
// for the list. Vector (directional) lights use an approximation.
Point3F calcLightPosition(LightInfo light, const Point3F objCenter, F32 visibleDist)
{
Point3F lPos(light.mPos);
if (light.mType == LightInfo::Vector)
{
F32 sceneRadius = visibleDist * 0.999f;
lPos = objCenter - (sceneRadius * light.mDirection);
}
return lPos;
}
// Check what parts of the world box can see the light
// If the center can see the light, early out
F32 checkOcclusion(Box3F worldBox, Point3F lightPos, U32 occludeMask)
{
RayInfo rInfo;
F32 alphaModulate = 0.5f;
F32 occFactor = (0.5f / 8.0f);
// Determine early out
if (!gClientContainer.castRay(worldBox.getCenter(),
lightPos,
occludeMask,
&rInfo))
return 0.0f;
// Check top corners of world box
Point3F topLeftFront(worldBox.min.x, worldBox.max.y, worldBox.max.z);
if (!gClientContainer.castRay(topLeftFront,
lightPos,
occludeMask,
&rInfo))
alphaModulate -= occFactor;
Point3F topLeftBack(worldBox.min.x, worldBox.min.y, worldBox.max.z);
if (!gClientContainer.castRay(topLeftBack,
lightPos,
occludeMask,
&rInfo))
alphaModulate -= occFactor;
Point3F topRightFront(worldBox.max.x, worldBox.max.y, worldBox.max.z);
if (!gClientContainer.castRay(topRightFront,
lightPos,
occludeMask,
&rInfo))
alphaModulate -= occFactor;
Point3F topRightBack(worldBox.max.x, worldBox.min.y, worldBox.max.z);
if (!gClientContainer.castRay(topRightFront,
lightPos,
occludeMask,
&rInfo))
alphaModulate -= occFactor;
// Check bottom corners of world box
Point3F bottomLeftFront(worldBox.min.x, worldBox.max.y, worldBox.min.z);
if (!gClientContainer.castRay(bottomLeftFront,
lightPos,
occludeMask,
&rInfo))
alphaModulate -= occFactor;
Point3F bottomLeftBack(worldBox.min.x, worldBox.min.y, worldBox.min.z);
if (!gClientContainer.castRay(bottomLeftBack,
lightPos,
occludeMask,
&rInfo))
alphaModulate -= occFactor;
Point3F bottomRightFront(worldBox.max.x, worldBox.max.y, worldBox.min.z);
if (!gClientContainer.castRay(bottomRightFront,
lightPos,
occludeMask,
&rInfo))
alphaModulate -= occFactor;
Point3F bottomRightBack(worldBox.max.x, worldBox.min.y, worldBox.min.z);
if (!gClientContainer.castRay(bottomRightBack,
lightPos,
occludeMask,
&rInfo))
alphaModulate -= occFactor;
// Clamp an return modulation
alphaModulate = mClampF(alphaModulate, 0.0f, 0.5f);
return alphaModulate;
}okay.... THREE posts because of limit
#52
Dunno if this will help...
- Brett
05/03/2004 (6:43 am)
void renderShadows() {
// Determine the sphere of the object that casts the shadow
// this is actually held in mWorldSphere for SceneObject
// For all lights in scene
for (U32 lightIdx=0; lightIdx < mLightManager->getNumLights(); lightIdx++)
{
LightInfo light = mLightManager->getLight(lightIdx);
// Is the object within the light's radius?
if (light.mType == LightInfo::Point)
{
SphereF lightSphere(light.mPos, light.mRadius);
if (mWorldSphere.isIntersecting(lightSphere))
inRadius = true;
} else {
// Other light types (vector only for now)
inRadius = true;
}
// Can the object see the light?
lPos = calcLightPosition(light, mWorldSphere.center, gClientSceneGraph->getVisibleDistance());
// Check if the light is occluded by either of:
// Terrain
// Interiors
U32 occludeMask = TerrainObjectType | InteriorObjectType;
visibleAlpha = checkOcclusion(mWorldBox, lPos, occludeMask);
// ...
}
}Dunno if this will help...
- Brett
#53
05/03/2004 (11:01 am)
Hey brett.. on your stencil shadows resource i noticed if you go into an interrior the stencil shad goes away BUT if you are in a interrior and the camera goes out of the interior (maybe because of thin walls or something) the stencil shadow comes back, inside the interrior..check it out..so i was wondering if there was a way to disable the flag for inside/outside, if so it may be exploitable to allow limited stencil shadows inside interriors.
#54
- Brett
05/03/2004 (11:06 am)
I never really tested with any interiors that defined lights. I don't know if the lights are kept in the LightManager, or if they are baked into the interior. If they are a part of the LightManager, it should work without any modifications. When the camera goes outside of an interior, I'm thinking that your bounding box must be protruding through the wall and can be "seen" by the light -- thus a shadow is produced.- Brett
#55
Anyone have any pointers on how the buildings (dif) shadows are created? The shadows are always pointing the same directions.
I have spent the last few days looking around, trying things out and reading post to no avail. Anyone have any ideas?
Thanks,
05/04/2004 (5:13 pm)
Ok I need some help with these shadows. Anyone have any pointers on how the buildings (dif) shadows are created? The shadows are always pointing the same directions.
I have spent the last few days looking around, trying things out and reading post to no avail. Anyone have any ideas?
Thanks,
Torque Owner Dan -
I got it running. I had to add a couple of things:
and
// Add the following code right after the calculations // for the update to mSunLightPosition. If we don't // the sun will be fixed at its starting pos. mLight.mPos = mSunlightPosition; mLight.mRadius = mSunlightPosition.len() * 2;Looks pretty sweet. I have a low resolution video, but my internet site isn't letting me upload it. There are also some enhancements I will probally be tweeking to this code. If there is interest I could post them here.
Over all I am VERY happy right now. Thanks! The shadows are nice and long in the morning, get really short towards noon and then grown long towards night.