Character Shadows

Blitz3D Forums/Blitz3D Programming/Character Shadows

CodeOrc(Posted 2004) [#1]
I've looked in the code archives and through the forums, but I need additional help understanding how to have a shadow cast for my character.

In other languages you can use a hardware call to cast a shadow, is there such a thing in B3D?

I am using B3D 1.85.

thanx in advance for your help.


jfk EO-11110(Posted 2004) [#2]
Unfortunately not. If you want shadows in Blitz, a lot of tricks and extra work is required. I am looking hopefully forward to the release of BlitzMAX, which will probably contain such things, along a range of other DX9 Hardware supporting stuff. Until then you need to use some tricks, or - not for free, but easier: buy sswifts shadow system, that's pretty good.


jhocking(Posted 2004) [#3]
I recommend sswift's shadow system.


Ruz(Posted 2004) [#4]
Is sswifts shadow system easy to understand/inorporate.
can you have mutipole shadows , ie a shadow for every entity.


jfk EO-11110(Posted 2004) [#5]
I think it's pretty simple to include. there's a demo: http://sky.prohosting.com/~scswift/Swift-Shadow-System-Demo-025.zip


jhocking(Posted 2004) [#6]
It's very simple. When you load the models/setup the scene you call commands something like CreatShadowCaster (I don't remember the exact commands off the top of my head) for every shadow casting entity, CastShadows for the lightsource, and ReceiveShadows for the model the shadows will be cast onto. Then just call UpdateShadows every frame, probably right after UpdateWorld.


Ruz(Posted 2004) [#7]
hmm sounds not too bad. i may buy this at some point depending on how far my prject gets. comin along ok right now


(tu) sinu(Posted 2004) [#8]
i reccommend it too, very simple to setup and use.


sswift(Posted 2004) [#9]
Hello.

As jhocking said, my shadow system is pretty simple to use. It's about as simple as it could get.

There's two things you should be aware of though.

1. You cannot cast shadows onto Blitz terrains.
2. You cannot cast shadows from MD2's.


Ruz(Posted 2004) [#10]
Thats cool, i don't use either right now. Is it fast ?
Will it cast shadows from alpha tranparencies


CopperCircle(Posted 2004) [#11]
I have also used Swift`s shadow system and its easy to use, but its a shame that Blitz has no features to support truly fast dynamic shadows, Blitz has physics, tools, etc... but things always look abit dated without true shadows.


Ruz(Posted 2004) [#12]
yeah its kind of essential really.


sswift(Posted 2004) [#13]
"Will it cast shadows from alpha tranparencies"

Hm...

I believe the answer is yes and no.

When casting a normal shadow, a copy of the mesh casting the shadow is made, and textured black and then a texture is made from the view of the light source. This would override any texture with alpha you have on the model.

However, there is a special shadow type for casitng shaodws from translucent objects, like colored glass. In this mode the model is NOT retextured. However, this means that the model will then cast a colored shadow as if it were fully transparent. But there will be uncolored holes where the alpha is.

There is a potential solution though. You could cast a shadow from a hidden entity. I forget if the system checks to see whether the entity is hidden or not before castign a shadow but it would be a trivial change to an if statement in the system that I could make for you if it did not. This hidden entity would be a copy of the entity you make, which is colored black but has alpha transparency. You then would use the colored shadow mode and the result would appear to be a shadow coming from the original object.


Copper:
There is no such thing s "true" shadows. Only various algorithms which approximate some things better than others. The shadows in Doom 3 have major limitations as well. All the characters have to be very low polygon for example. And a bunch of shadows which are cast across your viewpoint, such as the shadows from a jail cell door when viewed side on, kill the framerate.

Also more advanced techniques require more advanced hardware, and the nice thing about Blitz is that your game will look the same without any affort on your part on even the lowest end generic 3D hardware (in general). Though the framerate may not be spectacular.


Ruz(Posted 2004) [#14]
cheers sswift. I will probably invest in this at some point soon.
I am pretty happy with my lightmaps , but I need a good easy way fo giving all my level entities shadows or just the main characters at least


Gabriel(Posted 2004) [#15]
Thats cool, i don't use either right now. Is it fast ?


Well Anime Tennis Babes casts shadows from one light source to four players ( in doubles mode ) onto two court meshes. I can even turn on soft shadows and get no slowdown at 1024x768. Now ATB doesn't push the hardware too much in other areas. In fact it's optimized to the point where it runs on Intel onboard things with 8 meg of ram. And my machine has a Radeon 9700 Pro in it. But I think other people have tested it on much lower hardware with similar results, so I'd say that was pretty fast. And bear in mind that soft shadows are really intensive. Ordinary non-soft shadows are much faster still.

I doubt you could do faster in Blitz as it stands.


xmlspy(Posted 2004) [#16]
.


sswift(Posted 2004) [#17]
"Einstein said that light is a particle that behaves like a wave."

Uh huuuh. :-)

<Backs aaway slowly>


Mirror system huh? I'll think about it. But it probably wouldn't be very fast. For every mirror you would, effectively, need to render the entire scene again, just from a slightly different viewpoint.

Someone made a mirror system already. I don't know if it's in the code archives or not. It's not a perfect mirror though. Stuff looks funny if the mirror is at too great of an angle relative to the camera.


Ruz(Posted 2004) [#18]
'Einstein said that light is a particle that behaves like a wave'

you could make that in to a song lyric


slenkar(Posted 2004) [#19]
maybe light is a wave of particles or particles that give off waves


CopperCircle(Posted 2004) [#20]
Sswift, by true shadows i meant stenciled, I would just like to be able to cast basic stenciled shadows for more than 5 entites on a fairly complex level at a decent speed.
With Island Storm I have had to use basic fake shadows, just to keep the framerate, I have tried to switch from them to your system when the player gets closer, but the framerate dies, when casting onto a large .b3d with lots of textures.


John Blackledge(Posted 2004) [#21]
sswift, can you just clarify that point about your shadow system not being possible with Blitz terrains?


sswift(Posted 2004) [#22]
"Sswift, by true shadows i meant stenciled, I would just like to be able to cast basic stenciled shadows for more than 5 entites on a fairly complex level at a decent speed.
With Island Storm I have had to use basic fake shadows, just to keep the framerate, I have tried to switch from them to your system when the player gets closer, but the framerate dies, when casting onto a large .b3d with lots of textures."


Well you know if you have problems like this, you can always send me a copy of the game which I can compile that has the shadows integrated. Then I can see if I can offer suggestions to improve the speed, and I might find a way to optimize the system better for your specfic scenario. I don't really have any real levels to test with, nobody sends me anything but simple demos. :-)

Oh and were these entities animated by chance? One thing I've considered implementing would be an epsilon value for the animation much like I have for the movement and rotation of an entity realtive to the light source. In short, a value which determines how many frames the animation has to progress before the shadow is updated. In all likelyhood this would actually be fractional frames, but if you can avoid rendering the shadow map every frame, as you currently have to do with animated meshes, you get a large speed savings.

Another thing I could implement for distant entities is the abiltiy to force them to render their shadows less often.

I'd have to see how you're using the shadows though. I don't understand how you could see the shadows well enough to even need shadows if they're that far away.


sswift(Posted 2004) [#23]
"sswift, can you just clarify that point about your shadow system not being possible with Blitz terrains?"


You can use the Shadow system if you have a Blitz terrain in the scene, but you can't specify the terrain as a shadow receiver, because there is no way for the shadow system to get the vertices and polygons which make up its mesh. Any kind of mesh terrain would work just fine, but Blitz's Roam terrains are dynamic, and Blitz will not tell you how many vertcies it has or where they are at any particular time. So it is impossible to cast shadows onto them.

There is however a workaround if you're truly desperate to use my shadow system with a Blitz terrain. In the code archives there is code for "towel shadows". These towel shadows work with terrains because they simply drape over the terrain in an imprecise manner using the linepick commands. They however do not support true shadows. They're just black dots under your character as written. However, if you place one of these towel shadows on your terrain and specify it as a shadow recevier, then you could cast a character shadow onto it. But it would have to be large enough to catch all of the shadow.

I suggest you don't use Blitz terrains though. They're very simple to implement to be sure, but they're also very expensive to render. I can make a mesh terrain with the same level of detail that runs twice as fast as a Blitz terrain, and has more detailed texturing.