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

    Anicus

    Joined:
    Jul 15, 2012
    Posts:
    14
    Hi
    I'm try to use this plugin in iOS5 and 6 (IPod Touch Gen4-5) the result is not the same between editor and in device. (see my picture)
    The volume shadow is missing in device but available in editor (cast shadow is available in both ). What wrong? and how can I do for this situation?
    Thank you.
    $2013-03-22 17.58.12.jpg
    ps. I do every thing follow the read me file.
     
  2. Anicus

    Anicus

    Joined:
    Jul 15, 2012
    Posts:
    14
    OK, Sorry that is my mistake.
    This problem can be solved by only set light render mode to "Important".
    Your plugin is cool!! Keep it up!!
    Thank you for great plugin. :)
     
  3. sonder

    sonder

    Joined:
    Apr 11, 2013
    Posts:
    3
    Hi - great looking plugin. How do you ensure that a mesh is 2-manifold in Blender?
     
  4. gustavolsson

    gustavolsson

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

    See the last paragraph in the following quote, taken from the FAQ on the website:
     
  5. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Is there any possibility to set the quality level of this tool?
    Would be great, when it depends on the quality setting from Unity.

    For example, that it generates different quality shadow meshes.
    Or a maximum distance to the camera where the shadows are visible.

    Greetings
    Chillersanim
     
  6. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    There are no quality settings available at the moment. It is possible to use a low-poly version of the visible mesh as shadow mesh, but the toolkit can not lower the poly-count automatically.

    It should be easy to write a custom script that disables shadow renderers that are too far away from the camera to be noticed. I can add this to my todo list for the next version :)
     
  7. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    So, when I use the InstantOC kit, could I add the shadow meshes to the different LOD stages and it will automatically update?

    And I have already a second question...
    Are there already some plans, to allow multiple lights?

    Greetings
    Chillersanim
     
  8. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I have not tried the InstantOC kit so I can not say anything definite about compatibility. However, if the InstantOC kit only disables/enables the MeshFilter/SkinnedMeshRenderer components it should theoretically work out of the box. The shadow game object acts just like any other game object in the scene.

    There are no plans to support multiple simultaneous shadow casting lights. I won't say never, but it would require quite a bit of work and rethinking (if it's even possible).
     
  9. Apshai-Arts

    Apshai-Arts

    Joined:
    Feb 3, 2013
    Posts:
    67
    Ehm, I might be missing something, but don't you say in one of your posts on the first page that:
    "Multiple simultaneous shadows per game object (from 2 different shadow-enabled lights) will work, but may not produce realistic results."
    ?
     
  10. Mogthew

    Mogthew

    Joined:
    Jan 30, 2013
    Posts:
    18
    Any ideas about what would cause the edges of the shadow volume to show as black lines that render through stuff? They seem to be incredibly thin and aren't always obvious on stationary models, but when they're moving you can see ugly black lines tracing around the screen.

    This happens on my desktop pc (GTX 460) and my mac book pro (nvidia 650m ? Can't remember)

    Edit: Added an example - $example.png
     
    Last edited: May 31, 2013
  11. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Could be Antialias fragments. The Volume shadow doesn`t play together with Antialias.
     
  12. Mogthew

    Mogthew

    Joined:
    Jan 30, 2013
    Posts:
    18
    Just ensured this was turned off in my GFX card settings. This is exactly what it is. Thanks for that.Sucks that you can't have antialiasing with it though:(
     
  13. Pflugshaupt

    Pflugshaupt

    Joined:
    Sep 7, 2012
    Posts:
    35
    Hi all, I'm a happy buyer of the Shadow Volumes toolkit. I am currently experiencing problems with the ToolKit 2.2, Unity 4.1.5 and my new Samsung Galaxy S4 running the latest stock firmware. I am getting the android issues as described in the manual and on the webpage (black screen). However setting all settings as recommended to "No Blend" does not solve the issue. Has anyone gotten the toolkit to work on the S4?
     
  14. Serreas

    Serreas

    Joined:
    Jun 1, 2013
    Posts:
    28
    Hi, I just bought this shadow pack as well and find it really awesome. I do have a question though is it possible to apply the shadows to meshes that are created or instantiated at runtime?
     
  15. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Thanks for the feedback! If someone else that owns a Galaxy S4 can confirm this I can add it to the website. This is a really strange problem and I can't figure out what the cause is. On some devices it does not work at all on the stock firmware but fine when running Cyanogenmod, and on some devices it even works without the NoBlendOp setting no matter the firmware. It seems to be a problem related to the gpu/driver combination used.

    Note to other users: This is only a problem with Android devices, Apple devices work fine :)

    Thanks for the feedback :) Unfortunately, real-time meshes are trickier. Here is the answer from the FAQ on the website:

     
    Last edited: Jul 13, 2013
  16. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    That was a long time ago, when I just started the project :)

    I later made the choice to only support 1 light in order to make the toolkit simpler and more robust. (The results with multiple shadow casting lights were not realistic so the pros outweighed the cons)

    I will go back and edit my original post, thanks!
     
    Last edited: Jul 13, 2013
  17. hholland

    hholland

    Joined:
    Jun 27, 2013
    Posts:
    3
    Hello There,

    I can confirm that i'm having the a similar problem ;-) On my Nexus 7 everything works fine, when i try with my Nexus 4 i get a blank (grey actually) screen. My hunch was that the Nexus 7 has an nvidia Tegra 3 GPU, whilst the Nexus 4 uses a Snapdragon S4 Pro... Otherwise the machines are fairly well matched...

    Any ideas?

    Cheers!

    -henry
     
  18. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    I have updated to Unity 4.2, and now my formerly semi transparent Volume Shadow is totally opaque. Seems that the Shadow Volume Toolkit is not compatible with Unity 4.2 :(
     
  19. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Ouch. Do the shadows show up ok otherwise?

    Unfortunately, I will not have access to my development pc until next week but I will look into this as soon as I can.
     
  20. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    They show up, yes. But they are totally opaque. I can change the colour, but not the transparency level anymore.
     
  21. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I was able to install Unity 4.2 Pro alongside my installation of Unity 3.5.7 Pro on this computer, so I will try to solve the issue this week.

    @Tiles: Thanks, that will help debugging.

    Some information regarding the future of the toolkit:

    1. Future versions will drop support for Unity 3. There are more elegant ways to solve things in Unity 4 and now that mobile deployment is free, there are very few reasons to stay with Unity 3. I will provide a zipped copy of the current version of the toolkit for people that still want to use the current version though.

    2. I will add stencil buffer support so people with Unity/iOS/Android Pro can take advantage of the way shadow volumes is meant to be implemented. Basically, if you have Unity Pro, the performance and mobile compatibility of the toolkit will be better.
     
  22. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Does the new access to the stencil buffer in 4.2 mean much for the toolkit? As I understand it currently you're emulating what the stencil buffer does on the CPU, so with 4.2 and proper stencil buffer access, you can offload it to the gpu.
     
  23. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, I plan to support it in the next update :) See my post above.

    The current version uses the alpha channel, so it has always been GPU accelerated. The stencil buffer will increase performance and make it more robust though.
     
  24. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    There seems to be a bug in Unity 4.2 related to multipass shaders with blending. See the following thread: http://forum.unity3d.com/threads/192049-Multipass-shader-not-working-after-4-2-Update

    If I put each pass of the ScreenFinal shader in it's own shader the problem goes away. I'm going to submit this work-around as version 2.3 of the toolkit today and then add stencil buffer support etc next week for a second update.

    EDIT: I've now submitted the workaround as version 2.3 to the asset store :)
     
    Last edited: Jul 25, 2013
  25. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Version 2.3 is now available on the Asset Store! Download the update if you're using or planning to use Unity 4.2.


    I'm working on the next version at the moment. It will break backwards compatibility so I'm going to call it version 3.0. Here are the planned changes:

    • Stencil buffer support for Unity Pro users - better performance/device compatibility
    • Shadows are now configurable from a single component
    • No more shadow game objects that clutter the Hierarchy and Scene views
    • All global settings are now located in one place
    • The Quick Shadow Setup dialog will stay the same and the manual workflow will be improved
    • Unity 4.2 and up only - the previous version of the toolkit will be included though
    The update should be ready towards the end of the week. Opinions and feedback welcome. What would you like to see in future versions? :)
     
    Last edited: Jul 29, 2013
  26. MABManZ

    MABManZ

    Joined:
    Sep 29, 2011
    Posts:
    144
    I'm getting some weird looking shadows for a fairly simple object, or any object I use this with. The shadow is not 1 solid color and seems to have "overlap" elements. If it means anything, the ground has a baked lightmap on it.

    $weirdshadow.jpg

    Looking forward to update 3.0, it sounds great!
     
  27. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    @MABManZ: What version of Unity are you running?

    This is a bug that should be fixed in the latest version of the toolkit (2.3). Please redownload the toolkit from the asset store to make sure that you have the latest version.

    Let me know if this solves the problem or not!
     
  28. MABManZ

    MABManZ

    Joined:
    Sep 29, 2011
    Posts:
    144
    Looks like the newest version fixed the problem. Now I'm seeing another issue:

    $weirdshadow2.jpg

    The shadow volume is rendering in front of 3D text objects or planes I that are placed directly in front of the camera and should be on top of everything. (See where is says 4P Health) Is there any way to prevent this?
     
  29. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The shadow volumes are currently being rendered on render queue "Overlay+~500", so if the text/plane is rendered before this value and it does not write to the depth buffer (this is the case with transparent shaders), the pixels will be overwritten. To work around the problem, use Cut-out shaders. For the text and other non-overlapping geometry, it should also be possible to use a transparent shader with ZWrites enabled.

    In version 3 of the toolkit, shadows will be rendered after opaque objects but before transparent ones, which should solve the problem.

    The new version is ready, and I will submit it to the asset store as soon as I've rewritten the documenation :)
     
  30. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Version 3 of the toolkit is now available on the asset store!

    This is update breaks backwards compatibility. You'll have to delete the existing "Shadow Volumes Toolkit" folder and remove all references to the assets in your scenes, then redownload the toolkit and setup the scene using the new Readme.

    Let me know if you run into any problems!

    Here is the changelist:

    The updated Readme contains information on platform compatibility, unity license requirements and a backend (stencil buffer/alpha channel) performance comparison.

    Also, it looks like antialiasing works well with the stencil buffer backend, but I need more time to confirm this :)
     
    Last edited: Aug 7, 2013
  31. GD-Darren

    GD-Darren

    Joined:
    Jan 12, 2013
    Posts:
    53
    I have a large open world, how would it be performance wise in a large open world with day night cycles etc, and would it be harder to setup for large areas?
     
  32. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The performance depends on a lot things: What platform you're targeting. The triangle count of your models and the placement and direction of the sun. Whether you use "simple" shadow volumes (faster but the camera can not be located inside a volume) or not. Whether you're using the Alpha Channel backend or the Stencil Buffer backend.

    In the game I'm currently making, I use the Stencil Buffer backend and non-"simple" shadow volumes for dynamic objects. I will write a post here when I have made some stress tests.

    In a large world, it would probably be best to disable shadows for far-away objects. (Just disable the attached ShadowVolume component using a custom script) Unity's built-in dynamic culling make sure that shadows are not rendered if they're outside the view frustum.

    For a single game object, just add a Shadow Volume component. For more advanced game object hierarchies, use the Quick Shadow Setup dialog. It would not be more work to set up shadows for a large area as long as you're using prefabs.
     
    Last edited: Aug 7, 2013
  33. Evasion4D

    Evasion4D

    Joined:
    Aug 8, 2013
    Posts:
    16
    Hi,

    I have the last FREE version of Unity (4.2) and this last version of Shadow volumes toolkit (3.0)

    1/ I test your tool with the quick solution and with a spot, the shadows don't move if I turn the spot (Moving the spot is OK)
    Why ?

    2/ Where can I specify if my object cast and/or receive shadows ?

    Thanks
     
  34. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Hi, thanks for using the toolkit!

    The spot light in Unity is actually a point light with a "light mask". Rotating the cone does not change where the light originates from so the result you're seeing is correct. The shadows should only change when the position of the light is changed.

    Enable/disable the Shadow Volume component of the game object in question to control shadow casting. Everything that writes to the depth buffer (before render queue "AlphaTest+~500") will receive shadows.

    Even though there is no checkbox that controls whether a game object receives shadows or not, you can use multiple cameras to selectively shadow the scene. In my game, I render all the static geometry and shadows using the first camera, then the dynamic game objects using the second camera (which doesn't clear the display buffer). This way, only the static geometry will receive shadows and there will be no self-shadowing on dynamic objects.

    Hope this helps :)
     
  35. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    .
     
    Last edited: Aug 18, 2013
  36. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Nice! What platform are you targeting, and do you use the Stencil Buffer backend or the Alpha Channel backend, if I may ask?

    It is possible to blur the shadows in screenspace before applying them, but this would require Unity Pro. Previously, I have rejected this idea because I was mainly targeting Unity Free, but now that there are Pro only features in the toolkit (stencil buffer support) I might as well experiment a little with this. I will see what I can do for the next version :)
     
  37. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    I haven't followed this thread since I purchased the Toolkit months ago so I apologize if this was answered here ( I couldn't find any info in the docs or website) but...

    ...I see the Stencil Shadows in the Editor, but not on the iOS device when I build. Is there a checklist to ensure I have it setup correctly?

    Thanks gustav

    -Steven
     
  38. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    ...in fact this last build I got a fullscreen 'tinting' that was the color of the shadow volume. Thing is the camera isn't 'inside' the shadow volume, as it really couldn't be since the shadow is on a tiny character. Hmmmm...
     
  39. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Do you have a Unity iOS Pro license? The stencil buffer is not available on Unity iOS Free, unfortunately.
     
  40. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Most definitely everything Pro :)
     
  41. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Huh, strange. I don't have iOS Pro so I can't verify the problem but according to the documentation it should "just work". Have you tried using the "Stencil Buffer No Two Sided" backend as well? This backend should not use anything other than features that existed back in 1998 :p

    If it still doesn't work I don't think there is a lot that I can do. I could buy iOS Pro myself but I still don't think I would be able to pinpoint the error without more information from Unity.
     
  42. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Check 32 bit depth for iOS
     
  43. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Yep set to 32...dang, hehe.

    Mind you I'm certain its my scene and not the scripts, but c'est la vie.
     
  44. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Hmmm, I see I have a few notices as such:

    Shader wants texture coordinates, but the mesh Alien_GruntShadow doesn't have them
    UnityEditor.DockArea:OnGUI()

    Shader wants texture coordinates, but the mesh Alien_GruntShadow doesn't have them
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()


    Do we in fact need texture coordinates for Stencil Shadows? If so why would it work in the editor (the shadows) and not on iOS?

    Any thoughts as to why my iOS screen gets tinted the color of the shadow, yet no shadow on the object? Clearly it thinks 'something' is going on in relation to Shadow Volumes.

    Thanks for brain'in this through with me

    -Steven
     
  45. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    There is no need for a 32bit display buffer when using the "Stencil Buffer" backend. This setting only needs to be enabled when using one of the "Alpha Channel" backends.

    Have you tried the example scenes that came with the toolkit on iOS? If it still doesn't work we can rule out the possibility that it's your scene that causes the problem.

    No, and the shadow mesh does not contain any. It's actually the editor preview shader that wants the texture coordinates and spits out a warning. Nothing to worry about :)

    Yes. If for some reason the stencil operations did not run at all (say if Unity just removed them for the iOS build), the whole screen would get shaded by the shadow color.

    First of all, could you try using the "Alpha Channel" backend and see if this works as expected? (Remember to enable the 32bit display buffer in the build settings). Second, could you try using the "Stencil Buffer No Two Sided" backend? (Now there is no need for a 32bit display buffer)

    Two additional questions: What iOS device do you deploy to? What version of Unity do you use?
     
    Last edited: Aug 11, 2013
  46. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Just to get the important details out of the way:

    Unity Pro/iOS Pro 4.2.0f4
    iPhone 5 / iPad Mini - iOS 6.1.4
    XCode 4.6.3

    So I believe I'm all up to 'code' :D

    ...and actually the Basic scene from your /Examples did not work. I tried everything I could think of, from changing the shaders to checking and unchecking 'Is Simple' to trying 32 bit on/off to making sure the light had its shadows on to making sure the player had shadows turned on...nothing worked. :(
     
  47. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I tried the example scenes with the "Alpha Channel" backend on my iPhone 4S just now and everything works as expected. (Toolkit version 3.0, 32bit display buffer enabled)

    Have you tried all 4 different backend settings? You can select which backend to use in the inspector of the ShadowVolumeRenderer component. Use a 32bit display buffer at all times just in case. (I can't tell from your post if you have tried different backends using this method or if you have somehow modified the shaders manually. Redownload/reimport the toolkit just in case!)
     
  48. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Just to be clear, I 'have' to use Stencil Shadows or no shadows at all. My shaders are strictly vertex colored, so as you know shadowmaps won't work; my models are full-bright with no textures, and again only vertex colors.

    I've tried every stencil shadow option, which is pretty much backend or no-backend and Is Simple. You have additional stencil materials in the /ShadowVolumes material category.

    I didn't adjust anything and yea this is after a fresh import of your asset.

    Unity Shadows DO work for me on iOS but they won't work with my art style, so Stencils were my last hope.
     
  49. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Actually, the Alpha Channel backends will produce the exact same shadows as the Stencil Buffer backends. The implementation is different but the end result will be the same, pixel perfect sharp shadows. (The exception is that the Stencil Buffer backend will work with anti-aliasing)

    So, just use the Alpha Channel backend in the meantime until I've pinpointed the error :)

    The term "stencil shadows" is somewhat misleading because the technique does not actually require a stencil buffer. (The better, technology agnostic term is "shadow volumes")

    That said, the Stencil Buffer backends should work on iOS Pro. Can anyone else verify that this is not just a problem with SteveB's deployment configuration?
     
    Last edited: Aug 12, 2013
  50. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Victory! I clearly misunderstood the difference between Alpha Channel Backend and Stencil, but sure enough Alpha Channel works!

    For academic purposes, can you explain the difference between the two and why you might think one works on iOS while the other does not?

    Great job on support Gustav thank you :D

    -Steven