Results 1 to 7 of 7

Thread: Dynamic 2D Shadows

  1. #1

    Dynamic 2D Shadows

    Hi all,
    Just wondering if anyone has any experience, tips or links to creating dynamic shadows in 2D. ie Given a sprite, I want to create either a soft shadow or shadow that I can adaptively blend, to give the illusion of a soft shadow.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  2. #2

    Dynamic 2D Shadows

    What about using filters? Edge detection to make it black, rotation and shrink and, then blending... everything is here:

    http://www.gamedev.net/reference/pro...oc/default.asp

  3. #3

    Dynamic 2D Shadows

    To enhance the 3d element in Village Defense I used a lot of shadows. To create this effect I created 2 renders of each frame of an animationcycle. The first render is the characters, but without it's shadows. In the render only the shadows are visible. Then, in photoshop using the alpha channels I joing them together again.

    Below you can see a screenshot of all frames (best viewed in FireFox as Internet Explorer kills the png transparency effect)



    There is another technique available where you use real 3d objects to calculate shadows and then render only the shadows, but it is quite difficult, and only performs well in certain cases. Iirc there's an article about it on gamedev.

  4. #4

    Dynamic 2D Shadows

    Hi crono,
    Thanks for the link looks like it might be quite usefull. I'm not sure if just doing the black, shrink and blend will be too expensive.

    Hi Traveller,
    I unfortunately don't have the luxury of of rendering the shadows as I did not create the initial isometric models/renderings. FYI I'm using the Siege of Avalon sprites. At the time the engine used a 3rd Party DLL to create the shadows dynamically, and I am trying to do away with the use of said DLL.

    Either way it is something that would be implemented further down the line. But I wanted to gather the information before hand. I also thought others on here might find it interesting as well.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  5. #5

    Dynamic 2D Shadows

    It doesn't matter if you created the sprites or not . If you have them available in a renderable format, then you can edit them (granted may take a nasty hack of the engine to render to a clipping plane to create a sprite sheet).

    As for run time generated shadows; its very expensive to do it all of the time. Best best is to creat them on the fly when the sprite is loaded. Store them off for re-use later on, and then re-use when needed.

    I've been playing with stretch - skew - blur combinations and the results are quite nice. Graphics32 lets you do all of the operations quite quicly. Once I have rendered them I store them off to a png with alpha and everything is ready for the next engine run. Of course you don't have to store them local, you could generate them every time the game runs.

    Now, if you want them to bend up buildings, fall down holes, and do other 3Dish effects, then look out brother the road ahead just got rocky. I hate to point off site, but take a look at Malahedra on GameDev.net in the Isometric Land group. EDI has done quite a bit of work with shaders and 2D graphics to get nice looking shadows that "react" with the environment.

  6. #6
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Dynamic 2D Shadows

    There is the possibility to pre-rendering them during the 'level/ map load' cycle. Basically calculate the width & height required to make a copy of the character sprites.

    Then do a bit of processing and copy the alpha chanel and convert each non-transparent pixel as a white pixel onto the new texture. Continue through all the sprite frames until you have made a complete shilohette copy of the sprite's frames. You can then take these and use Traveler's trick to get them to show as a shadow (considering that you are using your GPU this costs you peanuts to scale & add to screen) you may then draw your sprites with the added benifit of shadows.

    Or... to reduce the need to have to scale each time you want to draw a 'shadowed' sprite.. you can scale them all to size when drawing them to the new texture during the processing. This will also have the added benift of reducing the amount of extra texture space need from double down to about one and a half.

    Then it'll cost you nothing more than a measily Add function each character on screen.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7

    Dynamic 2D Shadows

    Thats what I ment (WILL's comment that is). BTW: You can't use rotate to generate a shadow. You have to use stretch. For example a typical shadow transform looks something like:

    Invert Mask - IE: Make a copy then fill all but mask with a color (not black)
    Scale: 2/3
    Transform Top, Left: 2/3 * Width
    Apply Aplha: 30-50%
    Render Shadow
    Render Sprite

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •