TSStatics with not casting shadows on terrain
by Manoel Neto · in Torque Game Engine · 09/14/2005 (1:18 pm) · 6 replies
Or should I say... tsstatics with small collision meshes are not casting shadows on the terrain. Streetlights, thin trees and small bushes are among the objects that aren't casting any shadows whatsoever. I suspected the size issue, scaled one of the trees up and did a relight. Only then some shadow got cast on the terrain.
How are the rays being cast for lighting the terrain? From each lightmap texel to each light (that could explain the issue I'm experimenting), or from each light to each object (sounds slow... but would make all objects cast something on the terrain)?
How are the rays being cast for lighting the terrain? From each lightmap texel to each light (that could explain the issue I'm experimenting), or from each light to each object (sounds slow... but would make all objects cast something on the terrain)?
About the author
Recent Threads
#2
The performance hit was small, and acceptable (of course, the shadows are set to non-moving and non-animated), I only had to add some extra code to turn shadows on/off per TSStatic, since there are some very dense replicators in our current project, and getting close to them makes the game crawl. Since those replications already cast proper lightmap shadows on the terrain, it was OK to turn the projected shadows off.
I only got one problem, and was not sure about where to post it... since I am not sure if the problem lies in the LP code or the TGE shadow code/TSStatic rendering. I'll post it here, for now. Someone tell me if I should post it elsewhere:
The TSStatic shadows cast on interiors are flickering at certain camera angles, but remain fine on the terrain:
- By flickering, I mean that the shadows' blend level changes slightly at certain camera angles (it becomes suddenly lighter at some angles).
- Only the part projected on the interiors is flickering.
- Shadows cast from shapebase-derived objects won't flicker.
I failed so far in finding what the TSStatics are doing different that causes the flickering.
To make it worse, the flickering is *only* happening in our main mission. I created a new mission, to try to step into the code and see what's going on and: no flickering at any camera angle! I tried adding tons of objects, to no avail. I tried using replicators, adding waterblocks, adding more interiors, chaning the sun angle. Nothing! It works perfectly.
I went back to the main mission and started a deleting spree to see where the problem was, but couldn't nail it down to any specific class. At some point the flickering stopped, but I had deleted tons of objects and couldn't quite identify the culprit. Then I started deleting things by class (removing grass and foliage replicators), to no avail.
I know it is hard to know what might be going wrong without seeing the code or the mission file... but maybe the symptoms I gave can help someone more experienced help me locate possible areas where this bug might be happening. It's the shadow blending values that changes, and at given camera angles (but not at regular intervals). If someone wants to help, I can post the modified code here.
09/15/2005 (2:54 pm)
Alright, I did some hackin' on my own and some forum searching, and modified the code so TSStatics cast projected shadows. It improved our visuals a LOT, since small things cast nice shadows, and the effect is particualrly good on fences.The performance hit was small, and acceptable (of course, the shadows are set to non-moving and non-animated), I only had to add some extra code to turn shadows on/off per TSStatic, since there are some very dense replicators in our current project, and getting close to them makes the game crawl. Since those replications already cast proper lightmap shadows on the terrain, it was OK to turn the projected shadows off.
I only got one problem, and was not sure about where to post it... since I am not sure if the problem lies in the LP code or the TGE shadow code/TSStatic rendering. I'll post it here, for now. Someone tell me if I should post it elsewhere:
The TSStatic shadows cast on interiors are flickering at certain camera angles, but remain fine on the terrain:
- By flickering, I mean that the shadows' blend level changes slightly at certain camera angles (it becomes suddenly lighter at some angles).
- Only the part projected on the interiors is flickering.
- Shadows cast from shapebase-derived objects won't flicker.
I failed so far in finding what the TSStatics are doing different that causes the flickering.
To make it worse, the flickering is *only* happening in our main mission. I created a new mission, to try to step into the code and see what's going on and: no flickering at any camera angle! I tried adding tons of objects, to no avail. I tried using replicators, adding waterblocks, adding more interiors, chaning the sun angle. Nothing! It works perfectly.
I went back to the main mission and started a deleting spree to see where the problem was, but couldn't nail it down to any specific class. At some point the flickering stopped, but I had deleted tons of objects and couldn't quite identify the culprit. Then I started deleting things by class (removing grass and foliage replicators), to no avail.
I know it is hard to know what might be going wrong without seeing the code or the mission file... but maybe the symptoms I gave can help someone more experienced help me locate possible areas where this bug might be happening. It's the shadow blending values that changes, and at given camera angles (but not at regular intervals). If someone wants to help, I can post the modified code here.
#3
I'm not sure what's happening there. I only enabled projected shadows on StaticShape and ScopeAlwaysShape objects in order to avoid the performance problems you mentioned above (this way shape replicators never cast projected shadows).
As an example using the new TLK code I would use StaticShape objects for the fences.
I'm not sure if this helps, but it's a simple and effective solution,
-John
09/15/2005 (3:34 pm)
Hi Manoel,I'm not sure what's happening there. I only enabled projected shadows on StaticShape and ScopeAlwaysShape objects in order to avoid the performance problems you mentioned above (this way shape replicators never cast projected shadows).
As an example using the new TLK code I would use StaticShape objects for the fences.
I'm not sure if this helps, but it's a simple and effective solution,
-John
#4
Our fxShapeReplciator has been tweaked with extra replication modes. We added a linear mode, that replicates models along the replicator Y axis, at regular intervals and using the replicator rotation, among other modes. We got around performance issues adding a RenderShadow flag to both replicators and TSStatics. If a replicator's mRenderShadow is false, it'll toggle the shadows for all replicatins off (they'll not even render a shadow bitmap during load, nor create a shadow instance).
Here's how the fences look now:
09/16/2005 (12:28 pm)
Since we got a lot of fences, using StaticShapes would overwhelm our level mapper, since each fence piece would need to be placed by hand. Our fxShapeReplciator has been tweaked with extra replication modes. We added a linear mode, that replicates models along the replicator Y axis, at regular intervals and using the replicator rotation, among other modes. We got around performance issues adding a RenderShadow flag to both replicators and TSStatics. If a replicator's mRenderShadow is false, it'll toggle the shadows for all replicatins off (they'll not even render a shadow bitmap during load, nor create a shadow instance).
Here's how the fences look now:
#5


09/16/2005 (2:26 pm)
And here are some screenshots of the problem I'm experiencing. Notice how the shadow intensity suddenly changes when the camera gnle changes (at some point, one of the shadows disappear completly).

#6
I have TSStatics with collision meshes receiving shadows fixed, but, I need them to cast shadows on the terrain.
Alternatively, I have not found how to make them ScopeAlwaysShapes yet. If you do not want to share the code changes but, can offer info on how to make them ScopeAlwaysShapes as opposed to TSStatics that would be helpful as well.
09/06/2007 (2:00 pm)
What code modifications did you make to cause TSStatics to cast projected shadows? This is what I am looking into now. If you can share that information it would save me a great deal of time.I have TSStatics with collision meshes receiving shadows fixed, but, I need them to cast shadows on the terrain.
Alternatively, I have not found how to make them ScopeAlwaysShapes yet. If you do not want to share the code changes but, can offer info on how to make them ScopeAlwaysShapes as opposed to TSStatics that would be helpful as well.
Torque Owner John Kabus (BobTheCBuilder)
The lighting works differently depending on the light type. Shadows cast from the sun use a shadow volume that calculates the approximate shadow coverage per-lexel, the TLK shadows are calculated by finding obstructions between the light source and the lexel's center. Though these methods are different both are inaccurate when small objects (relative to the lexel area) are casting shadows, but this is more a function of light mapping in general.
That said, in the next TLK release (still a while off) StaticShape objects cast projected shadows, which are accurate regardless of the terrain light map density, because they don't use the light map.
The new static object / light / shadow relationship looks something like this:
[b] Object Type Light type Shadow Type[/b] TSStatic Static Static Dynamic None ScopeAlwaysShape Static Static Dynamic Projected (Dynamic) StaticShape Static Projected (Dynamic) Dynamic Projected (Dynamic)As a point of reference the current relationship looks like this:
[b] Object Type Light type Shadow Type[/b] TSStatic Static Static Dynamic None ScopeAlwaysShape Static Static Dynamic None StaticShape Static None Dynamic NoneAlso you can disable shadow casting from dynamic lights (just like the current static lights).
Keep in mind that all Torque point lights are considered dynamic lights by TLK, even weapon fire and explosions (assuming lighting is enabled on these effects, see the corresponding datablocks for details), so they also affect the static object shadows.
These new options create far more realism and higher flexibility. As an example in the next release you can replace your TSStatic objects with StaticShape objects and have much higher detail shadows.
There are a few more surprises in the shadow department, but I'll get into more detail later. If you're going to IGC definitely checkout the TLK demos running there. :)
-John