Search Unity

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. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The spiritual successor to the Shadow Volumes Toolkit has now been released (2019-09-4): the Sharp Shadows Toolkit!

    NO LONGER RELEVANT REALLY OLD POST AND POLL:

    The Shadow Volumes Toolkit adds dynamic, pixel-perfect shadows to your projects. Drag and drop the bundled scripts onto the game objects of a scene, specify light/shadow properties and see the results in real-time. The toolkit supports all three Unity light types and any closed mesh can act as a shadow caster.

    Works with Unity Free, Pro and Mobile.

    Version 3.2 of the toolkit is now available on the asset store! :)

    Below is a video of the new workflow:



    Webplayer
    Asset Store
    Website


    Poll: How does the webplayer (old version) run on your machine?

    EDIT: The old post was removed because it was obsolete, see the website for up-to-date information
     
    Last edited: Sep 4, 2019
  2. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    It runs brilliantly on my gma950 netbook

    Would it work on terrain?

    If it works on terrain, and on android, you have my money, but do be sure to go over any drawbacks
     
  3. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Cool! I totally forgot about terrain objects, I will run some tests and get back to you tomorrow (first, some sleep) :)
     
  4. Chickenlord

    Chickenlord

    Joined:
    May 13, 2011
    Posts:
    381
    Looks good.Just a wish: Please turn vsync off for your next webplayer. I'd love to check how much fps i get :D
     
  5. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    They look pretty good - I'm wondering now what advantages Unity shadows have over these? I've always wanted to have sharper shadows over distances ie. from trees on a landscape, but the shadow cascades just fall apart - could this implementation manage that?

    Ps. What nitwit patented a shadow algorithm?
     
  6. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Can you turn of vsync in the webplayer? I thought it was limited to 60fps regardless.
     
  7. Chickenlord

    Chickenlord

    Joined:
    May 13, 2011
    Posts:
    381
    Not in fullscreen. In fullscreen its limited to 200fps.

    @duke You wouldn't believe how many stupid people patented a lot of extremely simple algorithms... It's soooo annoying.
     
  8. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Could there be an option to use depth fail as its quite cheap to patent, ie a toggle var so we can optionally apply for a patent for it - say on ios if need be?


    creative labs.
     
    Last edited: Aug 26, 2011
  9. Chickenlord

    Chickenlord

    Joined:
    May 13, 2011
    Posts:
    381
    Hey, another suggestion. I don't know if this would be working, because i didn't have a deeper look at this topic. Would it be possible to add a blur pass to the shadows, so your not limited to hard stencil shadows?
     
  10. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Yep count me in for android too, i can run it through a Desire and a Galaxy S2, and then if it works I shower you with money and oiled virgins
     
  11. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Sure, if it is possible on the webplayer. I get about 1000 fps on my MacBook Pro but the scene is quite simple.

    Unity Pro lighting/shadows are (for obvious reasons) better integrated into the Unity engine and editor.

    In my package you need to drag&drop a "Shadow Volume" prefab into the scene and onto the game objects you want to act as shadow casters, instead of just toggling a checkbox like in Unity Pro.

    EDIT: The following paragraph is no longer true with the latest version of the toolkit. The toolkit has transformed a lot since these posts were written so check out the website for up to date information. Thanks!
    Multiple simultaneous shadows per game object (from 2 different shadow-enabled lights) will work, but may not produce realistic results.

    The shadows are applied by multiplying the scene with a "shadow strength" value which may produce unrealistic (for the lack of a better word) but still good looking shadows when there is ambient light in the scene or other light sources acting on the objects. Basically, the surfaces facing away from the light will be darker than the ambient term because of the shadows, ideally they would only be lit by the ambient term.
     
    Last edited: Jul 13, 2013
  12. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I believe this would be possible in Unity Pro by rendering the shadows into a RenderTexture and then using a smart blur shader to smooth the shadows before applying it to the scene. It could definitely prove a challenge to get it working though, especially while still supporting sharp shadows on Unity Free. The inherent limitations of the package (only sharp shadows/not as well integrated as Unity Pro shadows) is why I've decided on the low price point :)
     
  13. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    They look absolutely perfect to my needs to be honest, especially for mobile dev you cant much ask for more, so fingers crossed
     
  14. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I don't know. I would like to avoid the algorithm altogether because there could be problems with me selling a product that "could potentially" be used to violate their patent. I believe that the toolkit is fast enough even when not using the depth-fail technique but it might become a bottle neck on mobile devices as you say. I will look into it when/if I get it running on mobile devices :)
     
  15. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    :)

    As I wrote in the original post I would be happy if Unity/someone who knows could share how the alpha channel is handled on mobile devices and if it is possible to specify the framebuffer format.
     
  16. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    So I guess they turned up to Siggraph, presented their paper and finished by saying "..but we just patented it so you can't use it! Later assholes!", at which point they jumped in a Ferrari and did donuts in their booth before speeding off.
     
  17. Chickenlord

    Chickenlord

    Joined:
    May 13, 2011
    Posts:
    381
    Ah okay. I still think it's worth more than 20$, even without soft shadows. Especially if could get squeeze some additional fps for mobiles out.
     
  18. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    now this is where i cant help you but i hope someone can help
     
  19. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
  20. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Actually john carmack discovered it at the same time, and his version is known as carmack's reverse. However carmack would be mortified if he was asked to patent something, so he never did (why would he? he gives his engines away free after a few years). The technique is very simple. It is not even mathy, and there is no doubt many people would have come to the same conclusion since at that point in history, everyone started working on faster stencil shadows.

    It's just very sad that they'd patent it then threaten to sue john even though he thought it up himself. They got an agreement where doom3 had to prioritise creative labs hardware. Sickens me.
     
  21. bgivenb

    bgivenb

    Joined:
    Sep 15, 2010
    Posts:
    449
    I'll buy it for sure.
     
  22. showoff

    showoff

    Joined:
    Apr 28, 2009
    Posts:
    273
    I want to see how it runs on android pro
     
  23. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    It will not run on Android commonly
    You can't enforce the ARGB32 backbuffer at all and thats a requirement from what I get.
    On iOS you can enforce it through the build settings
     
  24. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Haha that issue with my s2 again hey... Goddamn it, I presume some devices will do it and some won't then.

    Is it something to be addressed by UT or a matter of tough luck?
     
  25. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    nothing to do with your S2. You simply can't set it and I'm not even sure that it uses 32bit backbuffer on any device at all on android, haven't seen anything that would imply that
     
  26. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Ahh well ok, it was just something you mentioned when it came to me complaining about banding on the S2
     
  27. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    So, it is possible to change the backbuffer format (to include an alpha channel) on iOS devices, great news! I don't have an iOS device so I'll probably release the toolkit with only Unity Free/Pro support at first. I believe it should work without any changes on iOS but I can't be sure until I get a device.

    It seems like Unity does not offer the option to change the backbuffer format on Android devices yet. This might be a deliberate choice because I can't find any information on how widespread the ARGB_8888 surface format is. However, I can't imagine it not being supported by the higher-end devices.

    Here is a quote from the Android developer reference:
    Thanks for all the replies and votes!
     
  28. 95KillerZ95

    95KillerZ95

    Joined:
    May 27, 2011
    Posts:
    253
    Nice work!!!! I'll buy it! I was looking for a indie shadows solution!
     
  29. darkgaro

    darkgaro

    Joined:
    Aug 18, 2011
    Posts:
    7
    If it works on IOS I will definitively buy it.
     
  30. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    There's code snippets on the ARM forums for implementing it with the galaxy s2, for example, apparently that removes the colour banding problem with that device too, but i dont know a hell of a lot on the subject so i cant say too much
     
  31. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The terrain will receive shadows (anything that writes to the depth buffer will) from any game object acting as a shadow caster, but it won't be able to cast shadows itself. You'll need to use lightmaps if you want the terrain to cast shadows.
     
  32. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    What about terrain trees?
     
  33. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749

    That would actually be perfect as i'm using randomly generated terrains with a very stylised visual look anyways, now just to wait for the relevant feature support for my phone/android from UT i guess! hmmph

    I'm assuming it would have to be done by UT anyways
     
  34. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, the ARGB_8888 (32bit) format will use 8 bits per color channel as opposed to 5 or 6 bits as in the default RGB_565 (16bit) format. This will remove any banding because the GPU will be able to work with more colors. The 32 bit format also has the benefit of an alpha channel. Let's just hope Unity will open up this option in the future :)

    I've found a possible workaround for the problem here, I'll try it as soon as I can..
     
  35. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I think you may have just made my day, i'm going to have a look at doing this right now as it may be exactly what I was looking for, if it works you have made money, you can have all my money!
     
  36. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I did a quick test and there are holes in the tree mesh (it is not closed) so it does not work.
     
  37. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Is that back buffer access shadow solution only going to work on OpenGL ES 2.0? Any chance that's going to work on older 2nd Gen iPod Touch / iPhone 3G (OpenGL ES 1.1?)??
     
  38. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Well even if it did, the horrific fill rate of the 2nd gen would mean it would be sub 10 fps just for a cube.
     
  39. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,664
    I poorly have a bad Intel GMA 950 Card/Chip (because i'm on a laptop) and it works like a charm :3 Good work!
     
  40. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Well I havent had any luck with the Unity answers link above but i feel like i'm doing something wrong, should there just be a single .class file created by javac? and do i just put that and androidmanifest into the .jar?

    I'm still getting the banding which i'm sure I shouldn't be, maybe someone can throw some light

    Edit: Yep no luck with the banding, unless im doing something wrong, so I dont know if it's going to 32bit colour at all, although I think it may just be the model of my phone in this case, not sure, i'll ask in the android forum bit although who knows if an answer is forthcoming
     
    Last edited: Aug 26, 2011
  41. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I managed to enable the 32bit backbuffer on Android by following the Unity answers workaround and trying out different things :)

    Check it out here

    EDIT: The toolkit will not "officially" support mobile devices in the first release.

    The performance seems to be okay, but not excellent on my phone. I think the toolkit may be used on mobile devices but very carefully, for example on main characters or selected buildings only, to avoid a too big performance drop.

    I'm thinking of adding a "Simple" mode in the future, where the performance should be twice as good, but with the drawback that the camera can not be inside the shadows (the depth-pass algorithm). For now though, I think I'll release the toolkit and only "officially" support Unity Free/Pro. People with Unity iOS/Android could of course experiment with it but for now it's not easy enough to support :p
     
    Last edited: Aug 29, 2011
  42. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    In some cases we would probably be happy with using simpler primitives or a proxy mesh to generate shadows from. Would this be faster? Being able to control this step may lead to speed gains.

    Another thing: on mobile you shouldn't really use anything but directional lighting.

    Finally: would you be able to blend the shadows so they only affect the light part of beast lightmaps, and gracefully just dissapear for shaded parts of the lightmap? that would also improve the look.

    Finally, in doom3, you'll notice the stencil shadows there get lit by lights to make them seem much less dark and more varied. Can yours do similar? I am guessing it would be tricky with this approach.
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
  44. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    When attaching the Shadow Volume prefab you can specify which mesh it should use, so you could create a low polygon version of the object and use it as the shadow mesh to speed it up as you say. Less polygons is always better even if the bottleneck is the inherent overdraw.

    Thanks for the heads-up on directional lights, I'll keep the option in the app for demonstration purposes though.

    Blending the shadows with the lightmaps and/or ambient light is difficult when the actual rendering is controlled by the engine. Rewriting all the built-in Unity shaders is not an option imo :)

    Right now, I multiply the entire scene (ambient and light lit) with the shadow strength so the surfaces facing away from the light will be darker than the ambient term. Ideally they should be exactly the ambient term but when using the right ambient/shadow strength values it looks good. Currently, the lights will increase the brightness of the shadow but not in the same way as with doom 3.

    I'm currently trying to figure out a solution to this..

    Edit: Btw, I tried the app on Samsung Galaxy SII and the performance was great! I wonder if we should be getting used to this kind of performance on newer mobile devices :)
     
    Last edited: Aug 27, 2011
  45. darkgaro

    darkgaro

    Joined:
    Aug 18, 2011
    Posts:
    7
    Anyway to see the performance results on iphone and ipad ?
     
  46. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    No, sorry, I don't have a Unity iOS license or an iOS device and I've decided to release the package for Unity Free/Pro only. Hopefully someone will try it out on iOS and report the results, but I can't guarantee it of course.
     
  47. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749

    That app runs excellently on my phone, and it seems to have gotten rid of the banding! I'd offer you recompense just for close directions on how you did that (Because I just couldnt get it to play ball doing it myself from that article), regardless of the shadows because that's the holy grail for me around now, if thats possible! Cheers
     
  48. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Sure, I'll write a blogpost about it sometime this weekend when I'm finished with the toolkit :)

    (and no compensation needed, if you were serious heh,just happy to help)
     
    Last edited: Aug 27, 2011
  49. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    You are a champion, as I say if this can work properly theres going to be a lot of happy S2 Unityers
     
  50. Fishypants

    Fishypants

    Joined:
    Jan 25, 2009
    Posts:
    444
    Nice work! Impressive :D