questions for sswift about shadow systemCommunity Forums/Developer Stations/questions for sswift about shadow system
| Sswift, I have a couple questions about your shadow system. These are both things I need to know before I spend time optimizing my use of your shadow system in my game. I think I know the answer to both, but I want to be sure.|
Does your system draw shadows outside the camera view?
Does your system fade shadows in/out as the shadow caster moves closer to/away from the camera?
"Does your system draw shadows outside the camera view?"
Why? If I did, then if you had a camera in another location in the level the shadows there would be missing.
It is also unlikely that doing so would improve the speed. I cannot clip shadow casters quickly using the camera fustrum or object behind the camera casting shadows in front of it would not display shadows. So I'd have to check all the polygons against even more planes.
It is your job to decide based on your style of game which objects should cast shadows at any paticular time. If you want to turn off shadows for objects far in the distance, you can. But if you need them, the system won't interfere with that. Likewise you can handle multiple camera views elegantly this way. And any occlusion system you write that is custom to your level is going to be faster than any generalized one I could implement.
"Does your system fade shadows in/out as the shadow caster moves closer to/away from the camera?"
No. Nor do shadows dissapear a specific distance from the camera. Shadows only fade as they recede from a light source. It is trivial for you to keep a list of entities yourself in a type and calculate the distance of each from the camera(s) each frame and decide which to diable shadows for.
But bear this in mind if you do that: Make sure you do not turn off all the shadows and then selectively turn on those you want to cast shadows. Only change the state of each object if it needs to be changed. Turning off the shadow for an object would clear any data that is used to optimize shadow texture rendering. Of course, this has no effect on animated meshes, but if you have a car or a segmented mesh that animates then that benefits from that optimization.
| I just got your email.|
"If the answers to these questions are yes and no, respectively, how would you recommend I implement these optimizations in my game?"
What would I recoomend... hm... lemme see...
For the first one... disabling shadows outside the camera's view, you can't just disable the shadow if the object's bounding sphere is outside the camera view, because the shadow might be in the camera's view anyway.
But, based on how you know you will have lights set up in your game, you could fudge the radius of the object a bit. Pretend that a solider with a bounding sphere with a radius of 1 meter really has a bounding radius of say, 3 meters. Then dtermine if this 3 meter wide sphere centered on the solider is visible to the camera. I beleive that to do this you could use a pivot, set it's entityradius, and then use entityvisible. But if not, my clipping system in the code archives... which is also included with the shadow system will help you set up clipping planes for the camera view and has a function to determine if a sphere is in that. Of course if you do this, then a shadow cast onto a distant wall from an object behind the camera may not show up. But that probably wouldn't look good anyway.
As for the second, I already suggested a method to deal with that. If you want to fade the shadows out... well, that'd be kinda difficult, but if you want to do it, the secret would be to add to the vertex color when the shadow mesh is built at the end of the shadow update function. If you take that color, and add increasing shades of grey to it, the shadow will fade out. It's basically how ambient works but that affects all shadows.
And you didn't ask, but the best way to improve the speed of the system is to split your level up into rooms and turn off those rooms the player is not near and/or can't see as receivers. And make parts of rooms that don't need shadows seperate objects so you can keep those polygons fom being receivers. Like if you have a detailed thing hanging from the ceiling, make that a seprate object. Don't need shadows there probably. And railings. But if you do want things to receive shadows, at the very least try to find areas of high detail that fit in a cube and make that a seperate object. Like if you did have a detailed railing running all around a room, try to split it into smaller sections... each section can be culled with a simple sphere test and get rid of all those polygons in one fell swoop.
| Thanks for the reply. That's all pretty much what I had been thinking. Oh, and thanks for the reminder that objects outside the camera view can still cast shadows into view; I forgot about that. I'd already been planning to turn shadow casting on/off based on EntityDistance checks, I just wanted to make sure I'm not doing something redundant. |