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

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    Gustav,
    Strange, shadows are now working, looks like your shadow volumes toolkit needs something else (not provided in your package) to work.
    I've first tried your packages in an empty project and they didn't show up (click on this image), then I've imported the package on my existing game project (which is fully loaded with all kind of assets (including Unity Defaults Assets)) and it worked (see here).
    I'm about to make an iOS build and post some results.
    Cheers,
     
  2. Demostenes

    Demostenes

    Joined:
    Sep 10, 2010
    Posts:
    1,106
    Does anybody know, if unity pro shadows are using this algorithm? Or it is completele different technology?

    What about speed? How fast is your sollution compared to Unity pro shadows?
     
  3. BIG-BUG

    BIG-BUG

    Joined:
    Mar 29, 2009
    Posts:
    457
    Unity Pro uses a complete different technology which I guess is faster in most applications (A speed test would be indeed interesting).
    However each shadow technology has other advantages and drawbacks dependent on your scenery so its not just about speed alone.

    @gustavolsson
    Does this system handle skinned meshes and animations?
    Are the volumes calculated via a shader? (Is this even possible as the vertex count could differ in my understanding? I'm curious as I'm working on a shadow system by myself.)
    Thanks!
     
    Last edited: Sep 7, 2011
  4. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458

    Oh, I already have this installed... and it is AWESOME!!! :) But with Lightmaps, I lose my normal maps (using Unity Indie here)
     
    Last edited: Sep 7, 2011
  5. Chickenlord

    Chickenlord

    Joined:
    May 13, 2011
    Posts:
    381
    Gotta wait for Radiosity Lightmaps (guess Unity 3.5 right?) and hope they'll be in the indie version as well, though i doubt it.
     
  6. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    And with my project, all i am missing is GI, real time reflections, and Shadows...
     
  7. Chickenlord

    Chickenlord

    Joined:
    May 13, 2011
    Posts:
    381
    Well. You got shadows now :D GI is probably never coming for Indie, at least i don't have any idea how to make it work without pro (thought about lot's of ways while working on realtime GI). Pretty much the same for realtime reflections. Only thing would be partial realtime reflections using lots of crazy things (working on it rigtht now).

    But back on topic. As said already, you got shadows now and i'd say they look extremely awesome. Pro users can even mix this system with unity's built-in one if they want, because this point and spot light shadows look way better than unity's in my opinion.
     
  8. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,458
    I am quite happy with it... :) and eventually I will have Pro :)
     
  9. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Cool, looking forward to it (make sure to use the Light Simple prefab if possible) :)

    Strange, it should work (and have worked for me) in an empty project. If it doesn't, try saving the project and restarting Unity..

    Yes, it handles skinned meshes (see the Animation example scene). And yes, the volumes are extruded in the vertex shader (the shadow mesh is pre-processed and the vertex count does differs from that of the original mesh) :)
     
  10. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Hi Gustavolsson,

    I`ve bought your plugin and like it. But skinned meshes is where i still have trouble to get it to work. Well, it casts shadow. But as you can see in my screenshot, the shadowcasting mesh doesn`t really follow the original mesh. It`s a bit hard to see in this shot, but watch the feet, it`s not only lagging behind, the mesh deforms wrong, and stretches his shin.

    I use animation blending here. Could that be the trouble maker? Or is my setup wrong?



    Uploaded with ImageShack.us

    I would`ve attached the original file. But that one contains the shadow volume toolkit too, hehe. A dangerous thing for the future. I hope i always think of removing it.
     
  11. darkgaro

    darkgaro

    Joined:
    Aug 18, 2011
    Posts:
    7
    Anyone tested this yet on iOS ?
     
  12. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Could you send me the project? Contact me using this form and I'll take a look at it.

    The scenes I've tested work perfectly, but it may have to do with animation blending as you say. Here are the results I get when using the toolkit with the viking demo:

    $skinnedmesh.png
     
  13. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Thanks gustavolsson. Link to a download of the file is sent :)
     
  14. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Just in case, and because it is not mentioned yet, this shadow solution doesn`t like antialias. You may get ray artifacts with enabled antialias.
     
  15. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Thanks to Tiles I've found a small bug in the toolkit when it is used with certain skinned meshes and I'm currently working on an update that should solve the problem. If you're having problems with the toolkit and skinned meshes, stay tuned for the update :)

    Yes, thanks again for reminding me about this, I've added the limitation to the top of the list on the website.
     
  16. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    @gustav,
    Waiting for the fix. :)

    @Tiles,
    Use the freely FXAA (look for it on the forums). It does a wonderful job. :)
     
  17. darkgaro

    darkgaro

    Joined:
    Aug 18, 2011
    Posts:
    7
    So nobody tested this yet on Iphone or Ipad ?

    I am wondering if it is working at all.
     
  18. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    I'm jumping in without reading the whole thread, so forgive me.
    Ive used another engine in the past that uses the same method for the shadows, but you don't need a closed mesh for your object, instead we have to create a second (lowpoly) mesh, name it in a specific way (ex: name_shadow.obj, etc.) and the system automatically recognizes it as the shadowcaster volume.
    is this possible with your algorithm?

    thanks in advance
    great work so far!
     
  19. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
    I am also very interested if this will work on a Iphone...
     
  20. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Me too :)

    Thanks! You can choose which mesh to use when rendering the shadows, so it is possible to use a low polygon version of the visible mesh to gain performance. The toolkit only supports closed meshes at the moment.
     
  21. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    @gustav,
    Do you have any plans for shadowmapping (or planar shadow) for iOS in the near future? Something less intensive than shadow volumes. ^^
     
  22. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    bought!
     
  23. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,624
    So I take it they don't perform all that well on ios? :)
     
  24. tatoforever

    tatoforever

    Joined:
    Apr 16, 2009
    Posts:
    4,364
    I din't had the chance to try it yet. But in theory yes, shadow volumes will perform slower than shadowmapping. Planar shadows is provably the fastest one but a Unity integration is quite tricky.
     
  25. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Bought it, works perfectly on the pc but just a black screen on android, any pointers? As your demo worked on my phone i'm sure it can work it just might need some particular tweaking
     
  26. darkgaro

    darkgaro

    Joined:
    Aug 18, 2011
    Posts:
    7
    My buddy installed it on IOS and I can confirm that default star animation sample works on iphone IOS 4.3 , frame rate seems Ok-ish ( little bit sluggish ) , need to do some better tests, but shadows are showing up fine.
     
  27. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I'm fairly certain my issues relate to the rgb8888 thing but for the life of me i don't know what i'm doing wrong, after following the guide on your blog

    I'll be able to test on a Desire soon which doesnt have the colour grading issue so i'm assuming not the backbuffer issue either so then i'll know if this definitely is the case, but i'm a bit unsure

    Is the resulting .class file from the compilation meant to be around 2kb in size? and i'm assuming the com.companyname etc stuff isnt case sensitive..
     
  28. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Did you enable the 32bit backbuffer using the guide? It is pretty difficult to determine if the backbuffer format has changed or not though. When I made the android demo (before writing the guide) I got a black screen a lot of times when my plugin didn't work. If you get a black screen, try following the guide more closely and just ask if you have any questions about it.

    Cool! :) The example scenes use the Light prefab which is slower than the Light Simple prefab. If I would target mobile devices I would try to use the Light Simple prefab wherever possible.
     
  29. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    It is case sensitive and you should replace the "com.companyname.productname" with what it says in your build settings. For my demo I used "com.GustavOlsson.SVTDemo" because that was the package I specified in the build settings. Also, make sure that you create the folder hierarchy that matches the build settings (My hierarchy: a folder called "com", a folder called "GustavOlsson" within "com" and a folder called "SVTDemo" within "GustavOlsson" and the "MyUnityPlayerActivity.java" file within "SVTDemo")

    If it still doesn't work just PM me so we don't tread too far off-topic :)
     
    Last edited: Sep 9, 2011
  30. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Oop PM'd!
     
  31. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    411
    same here... i thought the entire thing just crashed until i attached a lensflare to an animated light... and it floated over the black screen following the animation pattern :)
     
  32. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Android devices are not "officially" supported but if you want to get it working follow this guide to enable a 32bit backbuffer.
     
  33. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Thanks for the hint :)
     
  34. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Gustavolsson's guide is very good, goes over everything, i'm just ironing out a few things and I should be set. It does indeed work on android however, you just need to follow the guide and do a lil bit of fiddling
     
  35. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Got it working on a Samsung Galaxy S2! And it's not too shabby at all! You have to build a plugin for your specific package but after that its plain sailing on android

    I'll be giving this a proper workout tomorrow and see where its limits are but if it runs well on the S2, i'm happy, and Gustav was absolutely excellent at helping out so i'll do likewise

    If anyone has any problems building the necessary plugin to get it working even after gustavs excellent guide (I was a bit dumb for not really working it out based on that) then shoot me a pm. I'll just say remember absolutely everything should be in the correct case, including the jar and javac commands' directory names
     
  36. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Nope, FXAA is no go. I get an error when compiling the script. Seems that FXAA requires "Image Effects" package to compile. FXAA is a post process filter. And that`s Pro only.
     
    Last edited by a moderator: Sep 10, 2011
  37. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    Does it work with skinned meshes?
    I'm buying it anyway but I was just wondering.
     
  38. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Cool :)

    Yes, it does work, but there is currently a problem with some skinned meshes. I'm working on a fix that should be released sometime next week..
     
  39. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I just submitted the skinned mesh bug fix as version 1.1, it should be live soon!

    Also, if you guys have integrated the toolkit into your games, it would be awesome if you could share some screenshots :)
     
  40. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Hi Gustav,

    I have again a little bit of trouble. I tried to export the by you fixed scene as a unity package so that i could reimport it to my main project. That would make it easier to adjust my main character to your example setup. But the exported package gives me errors then, and refuses to work in my main project. The shadow is missing, and the character and anything else that uses your shader has turned into pink colour. Something turns wrong it seems when exporting. Is this a known issue?
     
  41. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    And another question. Is there a way to prevent that the shadow shines through objects? I cannot find a way to limit the depth. My spikeball shadow shines through the wall here.
     
  42. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Hm, I have no idea. I've exported a lot of packages and never experienced this problem. Try reassigning the Source property of the Shadow Volume script instances to an existing light source.

    Yes, the shadow of the spikeball is visible through the wall because the wall itself does not cast shadows, even though it technically should. If everything in the scene casts shadows, there will be no such problems.
     
  43. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    So if i understand correct, this works with Free version too?
     
  44. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, the webplayer demo was made with the free version of Unity :)
     
  45. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Huh thats a pretty huge slap into face of Pro. If that shadows are working with at least 50% of visual and performance aspects of normal shadows, then this could be real problem to justifing Pro shadows from now on. Unles if i missed something and you are charging for this shadows more than 200 dollars.
     
  46. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    There are some caveats to it but its pretty amazing for $20, i'll be hopefully having something to show for trying them in a sort-of practical setting on mobile eventually, hopefully
     
  47. Jamdalu

    Jamdalu

    Joined:
    Mar 20, 2011
    Posts:
    2
    Does not work in IOS for anything other than simple objects as pictured in the demo
     
  48. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    What device did you test it on? Do you use the Light Simple prefab? Have you tried using low polygon shadow meshes? There are a lot of different optimizations and tweaks that can be done to increase the performance.

    That said, I believe the toolkit is mostly useful for main character shadows etc on mobile devices..
     
    Last edited: Sep 13, 2011
  49. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I think it'd be very useful on mobile devices if you simply take the time to make simpler shadow casting meshes. This is how i'm planning to see how many things it seems are casting shadows in what im messing around on, and looking into ideas on how to mix it with pre-baked lighting for a nice visual effect
     
  50. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Thanks Gustav. But it already casts shadow through lightmapping. I cannot let everything cast a shadow by the volume shadow. That would be too much overhead.

    For now i simply have to take this issues into account i guess. Means i better use a shadow direction that comes nearly straight from the top, and build my level in a way that such things like shining through shadows are not visible.

    What would be good in this case is to limit the depth of the shadow volume. It is currently hardcoded, right? Hm i see the problems with a adjustable volume depth though. This would mean separate shaders for every mesh with another volume depth. It would nevertheless be a nice addition to have. And may it just be to decrease drawcalls :)