Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shadow Volumes Toolkit (now with stencil buffer support)

Discussion in 'Assets and Asset Store' started by gustavolsson, Aug 26, 2011.

?

Webplayer feedback

Poll closed Sep 4, 2019.
  1. The shadows look good (Mac OSX)

    79 vote(s)
    27.2%
  2. The shadows look good (Windows)

    178 vote(s)
    61.4%
  3. There seems to be a problem with the shadows (Mac OSX)

    6 vote(s)
    2.1%
  4. There seems to be a problem with the shadows (Windows)

    13 vote(s)
    4.5%
  5. Other problem

    14 vote(s)
    4.8%
  1. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    So did you fix the issues the previous approach by Aras had? This version had huge problems with artifacts and a lot of meshes didn't work at all or worked only partially. Have you been able to fix those completely? If you did, how did you do that? Aras wrote there are two ways of fixing those issues:

    That's definitely an interesting topic and I'd love to see something like that available in Unity.
     
    Last edited: Aug 28, 2011
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Well I'd like to see this native done by unity. Of course I mentioned it could be done fast for mobile on another topic but there were cries of "ooh it's too slow" from people who just don't think.

    Definately want to see pro shadows for ios pro... aras or someone, do you have itchy feet this anything goes friday? :D
     
  3. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    I'm using a similar planar shadow system (as the one in the wiki) on my iOS project and performance is great (if you pay attention to the amount of projectors and existing drawcall of course).
    I'm may provably give it a go on the iOS and post some results with our current game (Forgotten Memories).
     
    Last edited: Aug 28, 2011
  4. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Fishypants: Thanks!

    Yes, my implementation does not suffer from those problems. As long as the mesh is closed it will work. I pre-process the mesh and extrude the volume in the vertex shader. Doing the extrusion on the cpu is really slow and there is no reason to do it when shader support is available.

    The papers Aras referenced only supported up to 8 overlapping shadow volumes which is why there were artifacts on more complex models (self-overlapping occurred), my implementation is similar to "normal" shadow volumes and supports 255 overlapping volumes (more than enough for all scenes). Also, the papers suggested that each game object should have it's own state changes (as opposed to only one state change for all shadows) to minimize the max 8 overlapping volumes problem. State changes are expensive and my implementation only changes state once for all shadows.

    These are not planar shadows, these are as dynamic as shadow maps. (ie. supports self shadowing etc)
     
    Last edited: Aug 28, 2011
  5. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Looks fantastic! So when is this going to be available ?
     
  6. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Just one more hassle haha, as it works on my phone, banding or not, i'll be getting this, but to add you said there would maybe be a 'simple' function when the camera wont be inside the shadow that should be a little less costly performnce wise, as how i'd implement my shadows wouldnt be in the shadow (In fact in my implementation there should just be certain objects casting shadows on the landscape and nothing else, no self shadowing or shadows on each other, although maybe i could play with it a bit

    Either way, these sort of options would be great
     
    Last edited: Aug 28, 2011
  7. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Yeh i'm aware this is a technique knonw as shadow volumes. ^^
     
  8. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I've added a couple of things over the weekend but it should be good to go now, only documentation and another example scene left to do. I'll probably submit it in a day or two :)

    Yeah, I just added that option now. The "Light" prefab will work in all cases whereas the "Light Simple" prefab will only work when the camera is outside the shadows (it could be used for top-down/sidescroller type games). The performance will be roughly twice as good when using the "Light Simple" prefab.

    I might have misunderstood you, sorry :)
     
  9. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    @gustav,
    Any release date for your shadow system? I really wanna try the performance on our current game. It will also be a good benchmark for heavy graphical-oriented projects on iOS. ^^
     
  10. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I'll submit it tomorrow or tuesday :)
     
  11. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Awesome,
    I spec it on the Asset Store in one-two weeks. :)
    Cheers,
     
  12. andererandre

    andererandre

    Joined:
    Dec 17, 2010
    Posts:
    683
    Ok sounds like you did indeed finally implement this technique properly, congratz on that. Your shadows will be a huge leap forward, especially for all Unity Indie users. There are however two drawbacks:

    - the meshes have to be closed, I removed a lot of faces from my meshes that the player cannot see to save some polygons.
    - you still have to add the meshes separately, a single prefab might have about 10-20 MeshFilter components in all of it's children. That will lead to a lot of iteration through MeshFilter arrays to add and remove GameObjects when they are being instantiated or destroyed and will add some serious overhead to all spawn and despawn actions.

    But for games that don't extensively spawn GameObjects at runtime it will be a nice realtime shadow implementation, I'm really looking forward to it. And now that Unity Indie got it's first realtime shadows implementation maybe we will even see some sort of realtime shadows in a future Unity Indie release.
     
  13. stefann

    stefann

    Joined:
    Jan 4, 2011
    Posts:
    17
    hey,
    first of all thank you for all the effort. on my laptop it looks perfect. however i just downloaded the android preview from the market and it's by far not giving the result as expected. in the different light modes i get the light displayed correctly but the shadows just appear as artifacts in some rare cases. any ideas on that?

    i'm on a xperia x10 running android 2.3.3
     
  14. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I believe this problem occurs when there is no 32bit backbuffer support on the device and it reverts to a 16bit buffer. On desktops all graphics cards support 32bit backbuffers nowadays but on mobile devices it can vary, which is why the toolkit won't support mobile devices. I should probably pull the Android app to avoid any confusion.

    Basically, if you can force a standard 32bit backbuffer format with an alpha channel on a platform, it should work well, if not, there will be artifacts..
     
  15. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    As from v3.4 you can force 32 bit backbuffer on Unity iOS (theres an option in the player setting menu).
    So it should be fine on Unity iOS though performance is an other story. ^^
     
  16. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Tato, if you get this and try it on ios, please give us some impressions afterwards (workflow/performance etc). It would be much appreciated.
     
  17. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Cool, yeah, if it actually enforces the format (the app won't run on the oldest apple devices) it should technically work :)
     
  18. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    @AcidArrow,
    I'll post some results with our current project iOS game as soon as the package is available. :)
    I'm willing to do some compares with our current planarshadow system (performance and workflow-wise).
     
  19. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    So, I'm about to submit the package to the asset store :)

    Here is the final webplayer demo

    and for LazyGunn, a screenshot showing the shadows interacting with the built-in terrain:

    $terraintest.png
     
    Last edited: Sep 1, 2011
  20. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Awesome,
    I'll be waiting to give it a try on Unity iOS first. ;)
    Cheers,
     
  21. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
    WOW, how do you do that! :D Runs great in Firefox on Windows!
     
  22. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Looks great! I'll look forwards to messing with it, and rremember to tell us how you got rgb888 working!
     
  23. wingedfox123

    wingedfox123

    Joined:
    Apr 11, 2011
    Posts:
    229
    oops, i clicked the webplayer on the first page and their were no objects so i pushed other problem, buti tried the other webplayer and it worked fine
     
  24. Chickenlord

    Chickenlord

    Joined:
    May 13, 2011
    Posts:
    381
    Still awesome :D
    Quick thought i had: Is it possible to write into the "shadow buffer" yourself via script or shader? Because that would be even more awesome :D
     
  25. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Everything that writes to the depth buffer will receive shadows. An invisible/non-existent object can cast shadows by just using the "Shadow Volume" prefab by itself (and specifying a suitable shadow caster mesh).


    I submitted the package yesterday so it'll hopefully be released soon :)
     
  26. ivanzu

    ivanzu

    Joined:
    Nov 25, 2010
    Posts:
    2,065
    Whats the price?
     
  27. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
  28. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    At that price gustav, you'll sell a lots of copies, knowing how many free users are waiting for shadows.
    That's a good price strategy indeed. ^^
     
  29. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    In the near future, you may provably wanna try other ways to get shadows on Unity mobile but this time very optimized for. :)
     
  30. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    Very interesting! I'll be looking into it and possibly purchasing, I love seeing these types of creative alternatives. =)
     
  31. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
  32. namoricoo

    namoricoo

    Joined:
    Apr 14, 2011
    Posts:
    534
    When is the release date.
     
  33. CoatlGames

    CoatlGames

    Joined:
    Apr 25, 2008
    Posts:
    773
    im on Mac OSX lion with a intel graphics hd 3000 and the shadows look wonderful
     
  34. Squideey

    Squideey

    Joined:
    Aug 26, 2010
    Posts:
    24
    Wow. I will definitely buy this. I've got one project going, and the only Pro aspect I need are the shadows, especially when these happen to be pixel-perfect hard shadows.
     
    Last edited: Sep 4, 2011
  35. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Thanks for all the replies!

    When/if Unity approves it for the Asset Store.
     
  36. reissgrant

    reissgrant

    Joined:
    Aug 20, 2009
    Posts:
    726
    Nice! Great job getting this to work with the free version!
     
  37. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Here is the blogpost :)
     
  38. Squideey

    Squideey

    Joined:
    Aug 26, 2010
    Posts:
    24
    One question: does this system support self-shadows?
     
  39. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes :)
     
  40. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    excellent cheers! much appreciated, bookmarked and will test out soon
     
  41. Squideey

    Squideey

    Joined:
    Aug 26, 2010
    Posts:
    24
    Oh, I should have noticed that anyway. If it didn't, it defeats the purpose of using dynamic shadows in the first place. One more question I forgot: does this also support cut-out materials, like the Pro shadows?
     
  42. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    No, it doesn't. This is one of the downsides with shadow volumes, they rely on the geometric representation of the object, not what's rendered.
     
  43. RandAlThor

    RandAlThor

    Joined:
    Dec 2, 2007
    Posts:
    1,293
    It is in the unity asset store :)

    No i hope the closing time will come soon so that i can test it on the iphone.
     
  44. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    This is a nice addon too... but as someone mentioned, the meshes have to be closed, which is very painful if your character is optimised for gameplay... i think i should work still if u have a prefab...and this may force me to model the cliffs as meshes since terrains cannot cast shadows onto themselves
     
  45. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Thanks for your comments, the toolkit was just released a moment ago :)

    Check it out here

    (Btw, I'm going to start a new thread for the finished product in the Asset Store forums soon, stay tuned..)

    Yeah, only working with closed meshes is certainly a drawback, but used properly, shadow volumes can definitely be a great tool.
     
    Last edited: Sep 6, 2011
  46. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    I will have to test this when I get a moment... And that means I would have to model my characters with closed pieces each time i want to use this asset, especially if i am working with gore models.

    EDIT: And also if u want to use lightmaps on the terrain, you lose your normal maps (using Unity Indie here), which stinks if u want all of those detailed rocks and stuff...
     
    Last edited: Sep 6, 2011
  47. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    [Edit] Is now working, check out my post below.
     
    Last edited: Sep 6, 2011
  48. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    You can download a custom Terrain shaders (for free) on the Asset Store which enables normal and parallax mapping on unity terrains. ;)
     
  49. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    You don't mean the ATS Shaders do you?
     
  50. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Yeah, those are the one i was talking about. :D