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. vikram Jadhav

    vikram Jadhav

    Joined:
    Jun 21, 2012
    Posts:
    3
    Once imported, I never touched the scale of the model. In fact, as suggested in the readme I reset the transform for the model. Also, I was using MimicSkinnedMeshRenderer. If I don't, then the shadow doesn't animate with the character and above screenshots shows character in an animated frame.

    See if following info helps:
    I noticed that the shadow mesh created by the tool was really small and after setting it as "shadow", all three x, y and z scales were automatically set to 41.08. So to test I placed the shadow mesh as independent game object next to character and I had to scale every axis of it to 41 for it to be as big as the character model.

    I had increased extrusion amount to insanely high value but it didn't help. My guess is that if the bounds for shadow projection are scaled along with the shadow mesh, it may fix the problem.
     
  2. Acelondoner

    Acelondoner

    Joined:
    Jul 27, 2012
    Posts:
    101
    I get really odd results. (see image).


    image host

    Whats the reason for shadows looking like that?
     
    Last edited: Jul 27, 2012
  3. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The shadow artifacts appear when the shadow mesh is not properly closed. A mesh needs to be 2-manifold to function properly with the toolkit. That is, each edge in the mesh needs to be connected to exactly 2 triangles.

    Having a constraint on the geometry of the shadow caster is one of the drawbacks of using shadow volumes as opposed to shadow mapping and I will probably have to state this more clearly on the website. (I get a lot of questions about this)

    Hope this solves your problem :)
     
  4. Acelondoner

    Acelondoner

    Joined:
    Jul 27, 2012
    Posts:
    101
    I see. Thanks for the info.
     
  5. SashaRX

    SashaRX

    Joined:
    Jun 12, 2009
    Posts:
    8
    Is it possible to disable the self-shadowing, it helped me very much
     
  6. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    I'm very interested in this package. But it was mentioned it doesnt work with antialiasing, and I really need that. What happens if you do try to use it with antialiasing..?
     
  7. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    The shadows work in the editor, but not in game. Any ideas why? If I pause while in game, they show up. Just not while playing.
     
  8. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    Does any one have examples of this kit working with characters? I won't mind picking it up, just want to see a skinned character running around with it applied.

    thx!
     
  9. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    Works on unity4?
     
  10. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    The character here in my prototype uses the toolkit. The wooden chests too. The rest of the shadows are blob shadows though for performance reasons. Or even just a plane with a shadow graphics. Performance is a bit of a drawback with the toolkit. The nature of a volume shadow is to be a bit resource hungry.

    Webplayer. Takes a bit to load. Around 40 Mb: http://www.reinerstilesets.de/ext/dev2/alistertest.html

    I wasn`t able to convert my project to Unity 4 yet. I wait for a fix ...
     
  11. nestg

    nestg

    Joined:
    Oct 8, 2012
    Posts:
    155
    Gustav are you working in a version of this asset for unity 4?
     
  12. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, I'll investigate why it doesn't work as soon as I'm finished with an update to the Buoyancy Toolkit that I'm currently working on. Sorry for the delay..
     
  13. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    An update regarding Unity 4:

    The only problem I ran into when using the toolkit in Unity 4 was that, since Unity 4 has changed the way skinned meshes are imported, the shadow of the skinned mesh in my project did not render at all.

    To fix this, I removed the SkinnedShadowVolume and the MimicSkinnedMeshRenderer scripts from the bone game object they were originally attached to (where the SkinnedMeshRenderer was located in Unity 3.5) and then added the same scripts to the game object that now had the SkinnedMeshRenderer.

    I'll have to think about how I should solve this in an update, since I want the same package on the asset store to work with both Unity 3.5 and Unity 4, without modification. In the meantime, please use the fix above :)
     
  14. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Technically the toolkit should work with anti-aliasing enabled, and it does on my machines. However, I believe there might be graphics artifacts on some driver/machine configurations when enabled. If the driver does something strange with the output color, even though it would not be noticeable to a human, it'll mess up the shadow calculations (that are done in the alpha channel). I guess that if you allow the user to edit the anti-aliasing/shadow setting, or know exactly which devices you'll run the game on, you could still have shadows and anti-aliasing enabled by default..

    This sounds really strange. It might have to do with other graphics effects in conjunction with the toolkit. Please contact me through my website if you're still experiencing this problem.
     
  15. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Here is a demo of a new "Quick Shadow Setup" dialog that I've been working on for the next update (2.1) :)

    The dialog handles the game object setup with one button click. Jump to 0:50 to see it in action. Jump to 3:15 for an example of a skinned/animated mesh.



    The update will also provide 2 animation example scenes, one for Unity 3.5 and one for Unity 4. (The workflow will stay the same between the 2 versions though)
     
    Last edited: Jan 3, 2013
  16. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The update (2.1) is now live! I've also lowered the price to 20$ :)

    See the post above for a video showcasing the new workflow.

    Also, from now on, the toolkit will not let you create shadow meshes using non-closed source meshes. This will hopefully reduce the amount of confusion as to why the toolkit won't work with certain meshes. (It will no longer be possible to setup a game object so that "shadow streaks" appear. For an illustration of shadow streaks, check out the post at the top of this page)
     
    Last edited: Jan 7, 2013
  17. Acelondoner

    Acelondoner

    Joined:
    Jul 27, 2012
    Posts:
    101
    New update looks nice form what I see in the video. I used to find the workflow a bit to time consuming before.

    Time to import and start using your kit! :)
     
  18. Slay_

    Slay_

    Joined:
    Jan 10, 2013
    Posts:
    5
    Hi, Is it work on unity IOS standard(cheapest) licence? Or I need IOS PRO licence?
     
  19. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, the toolkit works with the standard Unity iOS license. Pro is not required :)

    Just enable the 32bit display buffer in the build settings and everything should work as on the desktop.
     
    Last edited: Jan 11, 2013
  20. Slay_

    Slay_

    Joined:
    Jan 10, 2013
    Posts:
    5
    Great!!! Thanks:)
     
  21. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    How does this work with Unity Free ? Judging from the comments, it apparently reads from the depth buffer, but how is that done in Unity Free ?
     
  22. suctioncup

    suctioncup

    Joined:
    May 19, 2012
    Posts:
    273
    I've wanted unity free shadows for a long time. If you need any beta testers, count me in. :)
     
  23. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Short answer: The toolkit does not read from a depth texture, so it works with Unity Free :)

    Long answer: The toolkit does not read from a depth texture, this would require Unity Pro. Instead, it relies on the depth buffer the way any opaque geometry does. That is, when the depth buffer is enabled during rendering, pixels that are occluded by pixels closer to the camera will be discarded. The shadow volumes algorithm uses this fact to occlude part of the extruded volumes to create a correct shadow mask. The contents of the depth buffer will thus determine where the shadows will be cast, which is why I mentioned it in my previous posts. Hope this helps!

    The shadows work with Unity Free and the toolkit is available on the Asset Store now :)

    Check out the website here
     
  24. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    Yes, but you'd still have to save the results of the first pass (rendered from the light source) so they can be used in the second pass (rendered from the camera). Or am I missing something?
    Also, I'm wondering whether this toolkit can be applied to runtime-generated geometry (your instructions only explained how to apply it to objects in the editor, if I'm not mistaken).
     
  25. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I believe you're referring to shadow mapping, which does require a rendering pass from the light's point of view. The toolkit is based on shadow volumes, which is an entirely different shadowing technique. The shadow volumes do not need to be rendered from any other point of view than the camera. Here is the wikipedia article

    Regarding runtime-generated geometry: Not supported out of the box. One of the drawbacks to using GPU-based shadow volumes is that it requires a special shadow mesh for each game object (mesh) that should cast a shadow. Shadow mesh assets are created and assigned automatically using the Quick Shadow Setup dialog but it can't be used during runtime, mainly because it's not a good idea to create assets then. The shadow mesh can be created manually using the ShadowMeshCreator script but it is probably too slow to be used during runtime, at least for more advanced source meshes. If you're interested in trying it out, watch the manual workflow example video on the website to see how the game object hierarchy should be set up and then replicate the behavior in the script that generates the source geometry.

    Hope this helps :)
     
    Last edited: Jan 17, 2013
  26. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    That article seems to only cover stencil buffer methods, but Unity doesn't allow access to a stencil buffer. So that still leaves me with a question mark. Your toolkit looks great, though, especially the precise shadowing at a reasonable speed.
     
  27. nestg

    nestg

    Joined:
    Oct 8, 2012
    Posts:
    155
    the same asset work in Unity 3 and Unity 4 or i need purchase diferent versions of the asset? the asset work with android and ios basic with unity free? how much cost the upgrade to a new version of the asset?, thanks.
     
    Last edited: Jan 18, 2013
  28. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yes, I figured out how one could use the alpha channel instead of the stencil buffer :) (It's not as straightforward as it sounds though, because it's not possible to do a test of what's already written to the screen the way you can do a stencil test) The alpha channel is the reason the toolkit requires a 32bit display buffer.

    Yes, the same asset works with both Unity 3 and Unity 4 and it does not require iOS/Android Pro. If you buy the toolkit, you'll get any future updates for free through the asset store :)
     
  29. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    So it only works if the alpha channel isn't being used for anything else (such as by other shaders), since you're apparently setting the alpha channel to a special "marker" value to mark the current fragment as part of a shadow-volume poly ? Some of my shaders change the alpha channel....
     
    Last edited: Jan 19, 2013
  30. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    That's correct. The toolkit uses the alpha channel for a limited time only (at render queue Overlay+~500) though, so anything using the channel before or after this will work fine.

    However, if something is written to the alpha channel before this time it'll be gone after the shadow pass. For example, if the scene geometry writes to the alpha channel to mark where a selective glow effect should blur the screen in a post process pass, the toolkit will overwrite the values and the selective glow will not function properly. (This is one of the limitations listed on the website) These examples are quite rare though and I haven't come across any alpha conflicts yet in my testing. Normal alpha blending, for example, does not even need the alpha channel so there will be no conflicts.
     
    Last edited: Jan 19, 2013
  31. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    951
     
    Last edited: Jan 25, 2013
  32. Wolfos

    Wolfos

    Joined:
    Mar 17, 2011
    Posts:
    951
    Yeah, this toolkit is horseshit. I got it to work properly on only 2 meshes, one's a cube, the other's an extruded cube. Generally it'll just bitch that the object isn't closed, but even if you close it using the shell modifier, it keeps bitching or you get glitchy shadows like portrayed above.

    I would like a refund and advise nobody to buy this unless your game exists of only primitives.
     
  33. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The shadow artifacts above seems to be the result of anti-aliasing used in conjunction with the toolkit, which is not supported (reliably across all hardware). Have you tried disabling it?

    Are you using the latest version of the toolkit? (2.1) The latest version will you not let you add shadows unless the source mesh is closed. This is a limitation of course, but in my opinion, it's not difficult to keep meshes closed during the modelling process.

    I'm sorry that you're so dissatisfied with the toolkit. I haven't had any refund requests yet, but I believe that you should contact the asset store support about this.
     
    Last edited: Jan 25, 2013
  34. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    I`ve finally updated my project to Unity 4, and have installed the latest version of the toolkit. And now when i select my character the shadow gets shown as a mesh in the editor it seems. The shadow in game still works fine. But i´m nevertheless curious about this behaviour. Unity 3.5 did not do that. Any way around this behaviour?
     

    Attached Files:

  35. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Yeah.. Unity has a debug renderer that renders a wireframe overlay of the selected mesh. The shadow volumes are extruded in the vertex shader and since the debug renderer now (in Unity 4) seems to take the vertex shader into account, the wireframe overlay of the shadow volume shows up in the editor.

    This is just a visual indication that shows up when working in the editor and it will not be visible when playing or deploying the game. I'm not sure if this feature is possible to turn off or not.
     
  36. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Thanks gustav. Then i have to live with it it seems. There`s worse. The shadow is still working as expected, that`s the main thing :)
     
  37. TheOtherGuy

    TheOtherGuy

    Joined:
    Feb 3, 2013
    Posts:
    6
    Hello, I bought the kit and got it working fine so far. I have a rock now that I generated the shadow on and made a prefab of so I can paint it on in the tree editor. When I paint it on the rocks show up but the shadows do not. What do I have to do to get the shadows to show up also since it seems that the child shadow mesh doesn't get included in the prefab?
     
  38. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I answered this in an email conversation but in case anyone else is wondering: I made a quick test scene and Unity seems to replace the shaders of painted game objects. The shadows are shader-based so I'm not sure if it's possible to paint shadowed game objects this way.

    Bottom line: Shadowed game objects need to be placed by hand. They can not be placed using the terrain painter.
     
  39. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I just wanted to let everyone know that version 2.2 has just been released. This fix should improve the performance on mobile devices considerably :)

    A special thanks to Brian that pointed out the bad performance linked to the ColorMask shader instruction. In his case, removing the ColorMask resulted in a 4ms (per frame) performance boost!
     
    Last edited: Mar 6, 2013
  40. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    So if i want to use this system for my player only for example, there is no way to not have shadows "shine through" other objects? It needs to be used on everything?
     
  41. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    You don`t need to use it on everything. That`s no good idea anyways because of the performance. But it shines through then under special circumstances here and there as you have pointed out.

    I personally just use this shadow at my character and a few boxes. I can live with this shine through effect.
     
  42. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    Yeah, the shine through effect wouldn't really be a problem if the game wasn't a 3D platformer, but now it's everywhere. I'll have to look for some other solution.
     
  43. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    You could try to reduce the "Extrude Amount" value of the Light/ShadowVolumeSource (under the Advanced tab) in order to limit how far shadows should be cast. If your objects tend to be close to the ground it could solve the problem.

    Also, since your game seems to be an isometric platformer (looking good btw :)), you could just keep the light pointed in the same direction as the camera. This should hide most of the shine through from the player.
     
    Last edited: Mar 11, 2013
  44. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    Thanks for your reply Gustav. The shadow will need to be visible for about three times the character size or so i would guess. I will try to tweak the Extrude Amount to see if that helps some.

    The game i'm using this in now isn't This Could Hurt from my signature. I'm guessing that is the one you are referring to, but this new game is an isometric platformer so maybe the second suggestion you mentioned could be something. But if i put the light between the camera and the player, the shadow will not be below the player. What i really need is like a blob shadow, but that actually looks like the player and reflects how the player looks from above. The shadow is used to help the one playing the game know where the character is positioned when in the air.
     
  45. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I can't quite picture your scene, could you provide a screenshot?

    If you want a blob-shadow like effect, you could try this:

    1. Use any number of lights without ShadowVolumeSource scripts to setup the lighting as you want it for the scene.
    2. Add another light with a ShadowVolumeSource component. Disable the light component, set it to be directional and then set it's rotation to point down. A rotation of (80, 10, 0) is good enough and avoids z-fighting on straight axis-aligned surfaces in the scene.

    Now, since the isometric camera is above the player, the user will never see the shine-through effect below the ground beneath the player, right?

    Also, if you only want a shadow for the player, you could avoid the shine-through effect by calculating the distance from the player to the ground in a script (using a raycast), and then set the Extrude Amount to be slightly further than this distance. This way, the shadow would never extrude through non-shadow casting terrain blocks in the world and thus never show up below these. (I imagine the game looking similar to This could hurt now)

    Hope this helps :)
     
    Last edited: Mar 13, 2013
  46. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    Ah, i could set the Extrude every frame. That should only give a few small artifacts. I'll give that a shot, thanks Gustav!
     
  47. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Would you mind to give a small example how this could work? I have quite a few situations where my shadow shines through too :)
     
  48. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Here is a rough draft. Keep in mind that this will only work with a single shadow caster (ie. the player character) and I don't think it will work as intended if the player game object is scaled.

    Set these inspector properties before running:
    Player Head - A transform (game object) that is located around the head of the player character
    Player Height - The height of the player (this is used when there is nothing beneath the player)
    Player Radius - The radius of the sphere cast that is used to find the ground
    Mask - Select the ground layer to avoid funky shadow flipping when over enemies etc.

    Hope this helps :)

    Code (csharp):
    1. using UnityEngine;
    2.  
    3. [RequireComponent(typeof(ShadowVolumeSource))]
    4. public class SetExtrudeAmountToPlayer : MonoBehaviour
    5. {
    6.     public Transform playerHead;
    7.     public float playerHeight = 2.0f;
    8.     public float playerRadius = 1.0f;
    9.     public LayerMask mask = -1;
    10.  
    11.     private ShadowVolumeSource source;
    12.  
    13.     public void Start()
    14.     {
    15.         source = GetComponent<ShadowVolumeSource>();
    16.     }
    17.  
    18.     public void Update()
    19.     {
    20.         if (playerHead != null)
    21.         {
    22.             float distance = 0.0f;
    23.  
    24.             RaycastHit hit;
    25.  
    26.             if (Physics.SphereCast(playerHead.position, playerRadius, transform.forward, out hit, Mathf.Infinity, mask))
    27.             {
    28.                 distance = playerRadius + hit.distance;
    29.             }
    30.             else
    31.             {
    32.                 distance = playerHeight;
    33.             }
    34.  
    35.             Debug.DrawRay(playerHead.position, transform.forward * distance, Color.red);
    36.  
    37.             source.ExtrudeAmount = Mathf.Max(distance - source.ExtrudeBias, 0.0f);
    38.         }
    39.     }
    40. }
    $test.png
     
  49. Tiles

    Tiles

    Joined:
    Feb 5, 2010
    Posts:
    2,481
    Thanks. Will give it a shot :)

    First i would have to translate it to Javascript though ...
     
  50. Enzign

    Enzign

    Joined:
    Aug 20, 2010
    Posts:
    169
    Here is a demo gameplay video. It's using another shadow system for the player, and it doesn't look very good as you can see.

    [video=youtube_share;Co-ixwKHgPA]http://youtu.be/Co-ixwKHgPA

    So that's the setting i'm trying to implement your shadow setting in. And you can turn the camera a little bit, so that makes it harder to get rid of the shine through as well.