Real-time projected shadows!

Hi Blenders!

I have been working on a script to create shadows for one of my game.
It’s a projected shadows script. This means that the shadow is a copy of an object that is projected on a plane to render shadow. And it works very well so far! No need of GLSL, so it should works on all graphic cards.

There is two version of the script.

Both of them handles:

  • Multi light-sources
  • Any kind of object, no matters its shape (concave, convex…)
  • Textures or vertex-color for shadowsOne script use ray-casters to find the plane where the shadow should be projected.
    The other one, simpler, handle one specific plane for one shadow. But you can create as many shadows as you want… so one for each plane…
    Just look at the file I have uploaded just below.

http://www.mediafire.com/?0mgxnljgkvt

Happy blending! :slight_smile:

Remi

Hi, Remi. I tried it and it is working perfectly. I had been searching for this a long time. Thanks for showing me the way. ;). I will use part of your script in my game project if you dont mind.
Good work!

I’m downloading it now, I’m looking forward to trying this out. It sounds wicked!

No problem! you can use use it!I posted it here to share it!
I’ve been looking myself for hours to find a script handling shadows, but I have always been disappointed. So finally i decided to do my own :wink:

If you have question, or any idea to improve this script…
I have been working on a optional GLSL part two render only the right vertex of the shadow. the script is finished, but I don’t know how to specify to blender how to use alpha channel (alpha blending)… :frowning:

OK. I have questions :). I have tried it in empty scene with one game character. I add a sun lamp (static). Character has one mesh on one armature which is rotating. The result

  1. shadow is rotatng too,
  2. shadow is in head level.
    Could it be a problem of object center?
    Here is a pic.
    http://www.pharcom.ic.cz/BlendArt/shadow1.jpg

The projection is computed whith these informations :

  • position of light (no matter the direction)
  • position and orientation of the “real” object
  • a point of the plane and the normal of the planeIt seems that your problem comes from the center of the object.
    It’s important to have the center of the “real” object and the shadow in the same “position”, like on the center of the body, on feet, etc…
    It seems that the “shadow” object is low poly. if so maybe try to use a copy of the real mesh before using a low poly.

Anyway, try to learn how to use this script step by step :wink:
If you still face the problem send me your file, so I can explain you the problem

Cheers

Hi

I think, I know your problem come from…
It’s about local and global position… A well known problem for blender users.
Try first to put the centre on the feet of your player, then follow the instructions I have written in this file, where there is an example of animation (very basic :wink: ) :

http://www.mediafire.com/?dbnpwe0se2i

If you still don’t know how to do, find out on google to understand the local/global issue…

Thanks for halp, Remi. I found that my problem was in the position of the projection plane, which position wasnt 0.000 in z-axis. Thanks for your demo file it shows, how should the scene look.
I am now dealing with my last (really last :)) problem. You can see it in your demo file too, if you add motion actuator (which is rotating along z-axis) to armature on one of the mills. The mill is rotating, but his shadow is rotating too. The shadow should be always in the direction of light, but if you rotate armature, parented shadow will rotate with it. I think, that it can by solved by adding some scripting, which will tell shadow to turn in opossite direction of the rotating armature. But if rotation of armature is changing it can be a problem.
I added an example - it is your file with added rotation to armature “wheel” (137 KB, RAR).
I am sorry if I am bothering you with my problems, but I can do only game logic python scripts (mesh deformation is a mystery for me :)).

No problem.
Where is your link ? :wink:
The thing is that because your shadow is a child of the armature, every modification on the armature affects the shadow. You shouldn’t use an actuator on the armature to rotate your character. Use the same actuator on the character itself instead. It works fine on my windmill! Rotation, movement…
Enjoy!

I added movement logic bricks from armature to character object and it is working :). I allways thought, that I should move the armature.
Again. Thanks for help, Remi :). I see you did a lot of work. I am looking forward to your next shadow projection projects :).

You are welcome!
If you could share a video of your draft animation by posting a link here and on the other thread I have created in the “Game Engine” Forum, it would give a good idea for other users what is possible to do!
Thanks!