Search Unity

2D dynamic soft shadows (will release source later)

Discussion in 'Made With Unity' started by brianasu, May 3, 2013.

  1. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    ***Source code can be found here***

    ***http://forum.unity3d.com/threads/181520-2D-dynamic-shadows-with-source***


    I found a great blog post about implementing 2D shadows.
    http://www.catalinzima.com/samples/shader-based-dynamic-2d-smooth-shadows/

    Requires a number of passes to generate the shadow occluder data but by keeping the shadow map size down it is still relatively fast. It's very useful since it doesn't depend on extruding any geometry.

    Doesn't really work on iOS now because it requires NPOT render textures. Looks like it's been ported to win 7 phones so an iOS one is probably possible with a few shader tweaks.

    Here is a demo video
    [video=youtube_share;PBBCJHrNH-o]http://youtu.be/PBBCJHrNH-o

    Source coming soon (hopefully:))
     
    Last edited: May 18, 2013
    XCO likes this.
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    absolutely cool :)

    long time since I last saw an implementation of the penumbra shadow casting shown yeeears ago on gamasutra :)
     
  3. dwayne792

    dwayne792

    Joined:
    Apr 6, 2013
    Posts:
    5
    very impressive :p
     
  4. GeneBox

    GeneBox

    Joined:
    Nov 15, 2012
    Posts:
    480
    Wow. Just wow, brilliant job!
     
  5. Chazede

    Chazede

    Joined:
    Dec 12, 2012
    Posts:
    42
    so are you porting this to Unity?
     
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    See the title of the video.

    It's a pretty nice technique although it does require several passes for each light rendering into a texture, and then each light has to have its own set of passes so you can imagine it getting slow fairly quickly for a more complex scene. But on the plus side, it doesn't need to detect where geometry is so you could have an extremely complex and dynamic level.
     
    Last edited: May 7, 2013
  7. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Thanks for the comments. Yup Imaginaryhuman you hit the nail in the head. It still works quite fast on desktop computers if you keep the resolution of the "shadowmap" low. The more expensive version simulates a penumbra using a 3.0 ps. It's a very clever way of generating shadowmaps by projecting everything to the x axis and then "raycasting" by downscaling by the x-axis. That's what made me want to try it. The advantage with this technique is that it decouples the shadow mapping algorithm from the geometry. You can think of it as a defered renderer.

    Later I'll try the geometry extrusion version which would most likely work on iOS much better.

    Chazde it has been already done in Unity. I'll release the source for free later this week I promise:)
     
  8. luispedrofonseca

    luispedrofonseca

    Joined:
    Aug 29, 2012
    Posts:
    943
    The final result is very similar to the 2DVLS plugin already on the Asset Store. The technical approach though is very different and I'm very interested to know which one is better.

    I'll definitely keep an eye on your work and can't wait to see a first implementation! Keep up the great work!
     
  9. mattdesl

    mattdesl

    Joined:
    May 12, 2013
    Posts:
    1
  10. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Nice. I was trying to find a more efficient way. Might give that a go. Thanks