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
    Even though it only minimizes the actual "problem", it is possible to change the shadow volume extrusion distance on a per-light basis :)

    Select the light, open up the Advanced tab of the ShadowVolumeSource instance and then tweak the Extrude Amount property.
     
  2. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Ah, there it is. Many thanks :)
     
  3. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    i am wondering if this could be something like the Per-object dynamic shadows in udk:
    http://udn.epicgames.com/Three/ShadowingReference.html#Per-object dynamic shadows

    but as the screenshoot from tiles shows it produces shadows that shine through static geometry which is only lightmapped – like the built in shadows from unity do when using forward rendering and mixing single light map mode with real time shadows.

    have a look at the shadow from the blue capsule on the backside or the upright cube [light is directional]:
    $shadowbug.png

    so there is still no effective way to use baked lighting with any kind of real time shadows i guess.
    or am i wrong?

    lars
     
  4. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I'm looking at the idea of baking lighting but only baking certain shadows, and baking GI and direct light and seeing if these shadows can do the shadow part of the lighting process
     
  5. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    No, not at the moment. Combining the shadows with ambient light and/or light mapping is a difficult problem.

    As LazyGunn suggested it might be possible to only bake the light map for certain objects and use the shadow volumes for the rest, which would minimize the problem.
     
  6. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Version 1.1 is now live on the Asset Store and should solve all issues related to the MimicSkinnedMeshRenderer script :)

    See the Animation example scene for how to use the toolkit with skinned meshes.
     
    Last edited: Sep 15, 2011
  7. Captain-Mike

    Captain-Mike

    Joined:
    Jul 25, 2011
    Posts:
    43
    Hi there Gustav

    does your shadow kit work with vertex coloured models not vertex lit easily confused...?
     
  8. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, as long as the shader writes to the depth buffer.
     
  9. Captain-Mike

    Captain-Mike

    Joined:
    Jul 25, 2011
    Posts:
    43
    Thanks for the reply Gustav I am not sure if the shaders i use do that or not I am not that technical and to be quite honest not sure how to find out...I am using the mobile vertex coloured shaders that ship with unity...so will they work...?
     
  10. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes :)
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    1. unity shadows look nicer when set up right, soft etc
    2. unity shadows fade and blend with lightmaps
    3. unity shadows are faster

    Of course it's not a slap in the face. It isn't even a threat.

    Good work to the author and its a great filler for people with limited or no budgets, but no replacement by any means. It's strength imo is that it works on mobile. For character shadows its a fantastic and great thing.
     
    Last edited: Sep 16, 2011
  12. Captain-Mike

    Captain-Mike

    Joined:
    Jul 25, 2011
    Posts:
    43
    Thanks for the reply Gustav... will be buying the poor-mans Dynamic shader for sure!
     
  13. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I'm fairly new to unity still so i hope this is not too foolish a question but is there an easy way to apply this to large groups of objects?
     
  14. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    As you asked, here's a screenshot of what ive been doing the last couple of days



    All the shadows are gustavs, the other lighting is baked diffuse in max

    I got a strange error in the webplayer where i got those streaming lines like you get in an unclosed mesh, this didnt happen on mobile or in-editor s i dont know whats going on thee, didnt want to do the toolkit a disservice so no webplayer but, just to prove it works fine on phones..

    If you have a strong android phone, and i'm talking kind of.. galaxy s2 (I tested it on a s2 and a desire, was great on s2, terrible on desire) then this is quite persuasive

    Bearing in mind around 5000 triangles are being shadow-ifed and i'm also using a bit of piecemaker and its not very optimised at all, its not bad at all! Shows skinned meshes etc all being nicely shadowed. Cheers gustav! This could go far

    Is it possible for a object to NOT self shadow? As you can see in the screenshot, the nice bright colours are being dimmed inside the volume, its hardly a dealbreaker but it means a tradeoff between the darkness of the shadows against the brightness of the textures
     
  15. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Actually i'll show what i'm getting in the webplayer, doesnt happen on android or in the editor



    Any ideas why this might be happening?
     
  16. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Hmm, Looks like the Antialias fragments that i have mentioned a bit earlier.
     
  17. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    It turns out it was exactly that! Cheers for that, i should read more carefully, ill try get a webplayer up soon
     
  18. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Wow, that looks amazing! Great art! :)

    I would use prefabs when game objects are used in multiple scenes or especially important. The Source property of a shadow volume will not be saved in a prefab though, because it is dependent on scene lights. If I would need a number of identical game objects/prefabs in a single scene I would start with one, set the Source property of it's shadow volume and then duplicate it or have a script that automatically sets the Source property of a shadow volume to the nearest light in Start().

    No, it is not possible to disable self-shadowing (unless the material is transparent, transparent materials will not pick up shadows because they do not write to the depth buffer). You can lower the shadow strength property of the Shadow Volume Renderer to get lighter shadows and thus brighter colors.
     
  19. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Well, i'm not too worried about the self hadowing thing it seems im going to have to scale the shadows vback a little anyways

    However i'm trying to use piecemaker with the shadows (i cant really afford your shattering thing) and i dont know how i might apply the shadow volume to the piece prefabs as they are generated by piecemaker, although i guess itd be hard for anyone to know unless they have good experience of both things

    Anyways as Tiles pointed out, the problems i was having were related to antialiasing, so i turned that off and here's a webplayer showing shadows on skinned and non-skinned models, and some piecemaker-delivered shattery stuff too for good measure (Trying to work out the lagginess when stuff shatters)

    http://pourfoi.com/test/index.html
     
  20. hellraizerhhh

    hellraizerhhh

    Joined:
    May 26, 2010
    Posts:
    619
    awesome work
     
  21. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    Gustav,
    I was thinking, why don't you add one-two passes to blur the shadows? It would give really awesome high quality soft-shadows.
    Btw, are you using the stencil buffer?
     
  22. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    A couple of reasons: screen space blur requires Unity Pro and deferred rendering (for depth), a (selective) blur pass is quite costly performance-wise, I think the pixel-perfect shadows look good and they are an alternative to the soft Unity Pro shadows :)

    The toolkit uses the alpha channel of the backbuffer because Unity does not provide a way to access the stencil buffer..
     
  23. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    There's a technique to blur the shadows (but i think you need the stencil buffer for that, not sure how it should work using the alpha channel) by jittering the light casting shadows in different passes and accumulate them in a buffer.
     
  24. Deleted User

    Deleted User

    Guest

    @gustavolsson really a great product! Do you plan to support officially iOS devices?
     
  25. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Several people have confirmed that the toolkit works on iOS devices if a 32bit backbuffer is enabled in the Unity build settings.

    However, I will not "officially" support iOS until I buy an iOS device and the Unity iOS license for myself. I currently don't have a plan to do so, but I might in the future. :)

    Thanks for the interest!
     
  26. swojtowicz

    swojtowicz

    Joined:
    Jan 2, 2011
    Posts:
    2
    Having a bit of an issue with the objects self shadow.



    Notice the hard edges on the sphere. Doesnt appear smooth like in the basic demo.

    Thanks.
    Scott
     
  27. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,368
    That's a normal behavior from shadow volumes. What you really need to do is match the shadows color with the scene ambient color so they will blend together and remove the hard edge effect on models casting shadows.
     
  28. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Or turn off self shadowing if possible...
     
  29. swojtowicz

    swojtowicz

    Joined:
    Jan 2, 2011
    Posts:
    2
    Thanks. Got it working. Didnt even cross my mind.
     
  30. GrimWare

    GrimWare

    Joined:
    Jul 23, 2009
    Posts:
    211
    Just purchased this. Great stuff! Shadows in indie FTW!
     
  31. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Nice :) I've been trying to come up with a better solution to this, but at the moment the best way to solve it is by adjusting the shadow strength.

    Cool, thanks!
     
  32. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    I stumbled across a problem with prefabs. The moment when i click at apply is the moment when the shadows quits working. They are gone after reloading the project. And i get a Shader wants texture coordinates but the mesh doesn`t have them error then. I have to recreate the shadow all the time for all instances after such a changing. Not nice. Is there a possible workaround? :)
     
    Last edited by a moderator: Oct 25, 2011
  33. Terryalex157

    Terryalex157

    Joined:
    Oct 25, 2011
    Posts:
    2
    I Am very new a unity and I can not figgure out how to use this.
    A guide would help I have looked at the readme but some of it I do not understand.
    I am just making a simple game in unity.
     
    Last edited: Oct 25, 2011
  34. johno

    johno

    Joined:
    Feb 20, 2011
    Posts:
    12
    Just a quick heads up for anyone thinking about picking this up. I got the shadows running on my iPad 2 with no problems. I still need to do some real performance tests, and when I'm feeling braver I'll try it on my 3GS too...

    Nice simple readme, tells you everything you need to know!

    John
     
  35. GrimWare

    GrimWare

    Joined:
    Jul 23, 2009
    Posts:
    211
    I think a video tutorial would be a helpful addition to the readme, but not necessary. I guess I could put one up if gustavolsson doesn't mind..
     
  36. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yeah, this is a drawback when the shadow volumes are treated as prefabs. I've been thinking of ways to better integrate the toolkit with Unity but for now there is no workaround.

    Try looking at the first steps of the readme (don't bother with the steps related to skinned meshes) and examine the basic example scene. Basically, you have to drag the Shadow Volume Renderer prefab and the Light prefab into your scene and for each game object you want to add a shadow to, drag the Shadow Volume prefab onto the game object in the scene list. Select the newly added Shadow Volume object in the scene and specify which mesh you want to use to cast shadows and then click Add. To make the shadows appear, set the Source property of the Shadow Volume game object in the scene to the Light you added earlier.

    That would be super helpful!

    Cool, thanks for the feedback!
     
  37. Terryalex157

    Terryalex157

    Joined:
    Oct 25, 2011
    Posts:
    2
    That will be very nice of you
     
  38. Alec

    Alec

    Joined:
    Mar 11, 2008
    Posts:
    1,330
    Buying this as soon as I get home, awesome!
     
  39. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    951
    If I'd known about this, I probably wouldn't have paid for the Unity Pro student version.
     
    Last edited: Dec 6, 2011
  40. carking1996

    carking1996

    Joined:
    Jun 15, 2010
    Posts:
    2,609
    I'm getting very low fps with one shadow casting object. I remove the shadow renderer object, and it's automatically up to 100fps no problem from 30-40 fps. Any ideas?
     
  41. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Performance is one of the reasons why i think to go back to projector shadows. Volume shadow is simply a bit more resource hungry.

    While at it, i made a little video that shows the setup process for a simple object. Maybe it`s of use for some here.

     
    Last edited by a moderator: Dec 8, 2011
  42. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    This Shadow Volumes Toolkit looks like exactly what I've been hoping for. I'm wondering how large an area it can cover while still maintaining a high resolution (does it use cascading, or at least can you restrict the area so that it only casts shadows on geometry near the viewer so that the shadow resolution doesn't degrade ?)
     
  43. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Just wanted to let you know that the Unity 3.5 beta allows android users to force a 32bit backbuffer in the build settings now, which means that it is possible to use the shadow volumes toolkit on android devices. Thanks Unity!

    By the way, I plan to update the toolkit in a few weeks in order to make it simpler, more elegant (no prefabs) and easier to setup :)


    What platform are you targeting? The performance depends on how complicated the shadow casting mesh is, how much of the screen space the shadow occupies and which quality setting is used (Standard or Simple).

    Awesome, thanks a lot for taking the time!!

    The toolkit uses the shadow volumes algorithm so there is no problem with shadow resolution, the shadows are always pixel-perfect, no matter how much space they occupy.
     
  44. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There's new depth buffer support and other goodies inside so you may be able to optimise a bit?
     
  45. Lizzard4000

    Lizzard4000

    Joined:
    Mar 3, 2010
    Posts:
    101
    nice shadows! some questions:

    do work multiple shadows on the same object? multiple light sources?
    (didnt work for me somehow)

    this FXAA makes the shadows disappear. a user said it sould work? does it?

    ty

    EDIT: AH! you need to change "clear flags" to "depth only", FXAA works
     
    Last edited: Dec 30, 2011
  46. johno

    johno

    Joined:
    Feb 20, 2011
    Posts:
    12
    So I did some more performance tests on iOS (specifically an iPad 2), and unfortunately I don't think its fast enough for use in a finished product. The main problem seems to be the multiple full screen passes that the Shadow Volume Renderer uses. This takes about 40ms to render, largely independent of the number of characters it has to render. I see the shader uses a lot of passes, maybe it would be possible to implement this with a slightly different technique that doesn't need as many passes?

    I think in general iOS devices don't seem to like full screen effects. The Image Effects package runs really slowly too.

    To get prefabs to work, I had to save the generated shadow mesh as an asset. I just save the result of CalculateShadowMesh to the asset database:


    SkinnedMeshRenderer skinned = obj.GetComponent<SkinnedMeshRenderer>();
    Mesh shadowMesh = ShadowVolume.CalculateShadowMesh(skinned.sharedMesh);
    AssetDatabase.CreateAsset(shadowMesh, "Assets/My/Path/To/Saved/Shadow.asset");


    There is a little more supporting code, but basically you can put this in a menu command and you are good to go!
     
  47. parnell

    parnell

    Joined:
    Jan 14, 2009
    Posts:
    206
    Ah bummer I was waiting to hear about these shadows on is before buying in. If he can get this working decently on ios I'd buy in a heartbeat.
    Googol!
    B
     
  48. manno

    manno

    Joined:
    Jun 29, 2011
    Posts:
    5
    Hello we're looking for a faster alternative to using a projector for shadows. We've found that after adding about a dozen or so projector shadows to a scene the game slows to a crawl. could this work for something like that? the following is a link to what we're trying to do.

    http://www.22randomletters.com/shadow-questions/stuff.html

    Thanks!
    -manno
     
  49. Dany0

    Dany0

    Joined:
    Aug 22, 2011
    Posts:
    18
    I love how manno never got his response. Way to go, "friendly" community!
     
  50. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Well, `tis a big community here, with hundrets of postings every day. So sometimes a posting falls off the table. Or sometimes there is really nobody there who has the answer. That`s the way it is.

    For an answer: define a directional light that points downwards to be the shadow source, and you will have your shadow that points downwards everytime.

    Now the hook: this Volume shadow solution here is ways more resource hungry than a Projector shadow. So when you look for a faster substitute for Projector shadows, then you are at the wrong place. My guess is that you haven`t optimized your Projector shadows, and their corresponding drawcalls. You can for example exclude layers so that they don`t get affected by Projector shadows. You can also disable Projectors when they are above a given distance or out of reach.