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 Softener - Official Thread

Discussion in 'Assets and Asset Store' started by PolyVector, Sep 11, 2013.

  1. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,459
    How to add shadow softener support to Quantum Theory PolyWorld shaders ?
    I need to run it on IOS devices and webplayer.
     
  2. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The answer in both of these cases is to use the "Advanced Setup" instructions in Shadow Softener's documentation. Mobile devices don't appear to work with the UsePass-style integration, so you must add the following lines to your shader:

    Code (csharp):
    1. // Define the Shadow Filter you wish to use:
    2. #define SOFTENER_FILTER PCF4x4
    3.  
    4. // Include Shadow Softener:
    5. #include "Assets/Shadow Softener/Shaders/ShadowSoftener.cginc"
    In the case of PolyWorld, you would add these lines in, say, VertexColorsIBLDiffuse.shader

    I hope this helps.
     
  3. dxmachina

    dxmachina

    Joined:
    Jul 4, 2012
    Posts:
    66
    I saw that someone inquired about this working together with Alloy. Are these packages compatible?
     
  4. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Edit: I misread this as a Sunshine question, just woke up!

    Deferred Directional Shadows should work pretty seamlessly (You will have to delete Shadow Softener's Internal-PrePassLighting shaders and restart the Editor).

    Deferred Point/Spot lights aren't supported with Alloy out of the box, it would require merging the two PrePassLighting shaders, which I'm not sure if that's possible.

    In the Forward Renderer you can edit the Alloy shaders to use Shadow Softener by following the included instructions, and it should work with all light types.

    If you run into any trouble though, I'm here to help.
     
    Last edited: Jul 26, 2014
  5. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Sunshine is a finalist in the 2014 Unity Awards for Technical Achievement!

    We are honored to be considered a finalist! And we're also up in the Community Choice Awards. We're up against a lot of really awesome assets by some talented devs. But if you like what we do, don't hesitate to give us a vote.
     
  6. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Sunshine is on sale for the first time ever!

    Get Sunshine for 50% OFF in the Unity Asset Store until Aug 14th to celebrate with us making it as a 2014 Unity Awards Finalist!

     
  7. Discmage

    Discmage

    Joined:
    Aug 11, 2014
    Posts:
    58
    Hiya! We just bought softener and for our test run we had it looking great wiith a standard camera...but as soon as I took the main camera out and threw in the Oculus Rift player Controller...it seems the Rift cameras do not support Shadow Softener as they go back to jagged shadows?? Have I done something wrong, or does softener not support the rift yet...or do I perhaps need to set something in script for it to work again?

    From a base camera perspective, this is an AWESOME product! I just hope we can carry it across to the rift!

    EDIT : OK...so I did forget a couple of things. I've clicked on the individual cameras and set them to deferred lighting...and now the shadows are all over the place. I can't make sense of twhat they are actually doing exactly. Any thoughts on getting this to work would be greatly appreciated...even if it's a case of Rift does not support softener yet as we need it for a project proposal and may look to other shadow alternatives.
     
    Last edited: Aug 11, 2014
  8. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    That is strange, I would have expected it to work since Shadow Softener only attempts to edit the shadow filtering, not the shadows themselves. This very well may have to do with Unity's new stereoscopic support which I have not had time to test.

    I'll do my best to reproduce this behavior and see if it can be fixed as soon as possible.
     
  9. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Okay, I was able to reproduce it using the Oculus SDK 0.4 when setting the two cameras to Deferred. After some testing, it appears to be a Unity issue that occurs even with Shadow Softener completely removed from the project.

    I'm using Unity 4.5.2f1, what version are you on?

    I would try removing Shadow Softener, restarting the Editor, and just verifying that the problem is indeed related to Shadow Softener.
     
  10. Discmage

    Discmage

    Joined:
    Aug 11, 2014
    Posts:
    58
    You're right...the shadows aren't working even without Shadow Softener. I'll see if I can get those working first and then reapply shadow softener.
     
  11. Discmage

    Discmage

    Joined:
    Aug 11, 2014
    Posts:
    58
    So looking into it I found this thread. Seems deferred lighting DOES have some issues...but people have a workaround/fix for it. I don't exactly know how robust it is...but on initial impressions it seems to be working so far! Image effects may still have issues if you are using those, but I think they are working on those too.

    https://developer.oculusvr.com/forums/viewtopic.php?f=34&t=11014&start=20

    I must admit shadow softener looks pretty slick in the rift DK2! :)
     
  12. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    That's great to hear! The prototype devkit I have is pretty sweet, but I bet the final DK2's feel even better since they have translation. :)
     
  13. Discmage

    Discmage

    Joined:
    Aug 11, 2014
    Posts:
    58
    Sorry to bring up another issue so soon, but I've been poring over the threads and couldn't find anyone having similar issues.

    I have my scene setup as I'd like and the point and spot lights work great with the softener working fine...but the directional light does not have soft shadows.

    I have double checked the config file to make sure the defines for directional is at 6 (tested 8 too but it didn't change). I have made sure all the cameras are in deferred...but that shouldn't be an issue as point and spot work.

    So I'm at a bit of a loss as to what to focus on next. Any ideas ? Knowing my luck it's going to be a simple click somewhere! But I can't for the life of me figure out what that might be!
     
  14. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    It's no bother! :)

    The most common cause of Directional shadows looking harsh having your light set to "Soft Shadows", which makes Unity perform it's notoriously noisy filtering. Counterintuitively if you set the Light to use "Hard" shadows it should soften up.

    Another possibility is that sometimes the Resolution is set too high. Since Shadow Softener filters in texel-space a lower resolution can result in softer shadows.

    If these suggestions don't help, feel free to PM me a scene and I'll see if I can spot any problems.
     
  15. Discmage

    Discmage

    Joined:
    Aug 11, 2014
    Posts:
    58
    With help from PolyVector I managed to find the solution so I thought I'd post for others to see if they have the same issue.

    It may be possible that you have more than one "Internal-PrePassCollectShadows.shader" in your project. If that's the case, then Shadow Softener's Directional shadow code wouldn't be executing.

    This was indeed the case with my project as I was bringing softener into a preexisting project which had the aforementioned shader. Cleaned it out and it worked a treat.
     
    JohnyZuper likes this.
  16. JohnyZuper

    JohnyZuper

    Joined:
    Jan 7, 2008
    Posts:
    174
    Do these shadows take a modified projection matrix into account?
    I'm using Camera Perspective Editor but Unity culls shadows based on the original frustum not the one modified by the script.
     
  17. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    It does appear to have a compatibility issue when used with Deferred Rendering. I'll see if there's any way to address this in an update.

    Edit: Unfortunately, this appears to be related to the Deferred Renderer not handling custom projection matrices, and not Shadow Softener. When I removed Shadow Softener entirely from my test project, it exhibited the same behavior.
     
  18. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    648
    Hey,

    I noticed you mentioned we can edit the Alloy shaders to work with Shadow Softener. About how much work does that entail? I don't have very much experience with shader code, so I wouldn't want to have to do anything too strange ...

    Thanks,
    Dale
     
  19. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    It depends on the requirements.

    Forward Renderer:
    You can get Directional shadows working with Alloy by simply using the included converter (which adds a single "UsePass" line to the shader). Other light types would require a few more changes explained in the documentation, but it should be possible.

    Deferred Renderer:
    Alloy has an Internal-PrePassLighting.shader included with some commented changes. You can copy these changes into Shadow Softener's Internal-PrePassLighting-40.shader and then delete Alloy's copy. Restart the Editor, and you should be good to go.

    If you have any trouble, feel free to PM me a small project and I'll do my best help with integration.
     
  20. 8Infinite8

    8Infinite8

    Joined:
    Jul 27, 2013
    Posts:
    112
    Hi, I recently bought this to try and overcome Unity's horrid shadow system. I can get some very cool results, thank you! But still face some issues. Mainly on objects self shadow that shows nasty stepping and artefacts.

    Hard Shadows



    Soft Shadows



    Soft Shadows overcomes this but we get noise and distance and the shadows don't clip to edges properly.

    Nasty stepping and artefacts on self shadows








    Any ideas how to overcome this? Using Soft Shadows hides this issue but then we have the nasty side effect of horrible noise at distance. If only we could control and blur the noise!!

    In some scenes Very High Resolution Shadows is unresponsive and they look just like High Resolution Shadows? Do you know what causes this phenomena?

    Thanks
    Lee
     
  21. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hi Lee,

    This clipping is called "shadow acne" and is the primary downside of the "Bilinear PCF" technique I chose to go with. As you've observed, Unity's "Soft" filtering will break it up, but you get noise and edge artifacts. The best way to control acne is to fine-tune the light's "Bias" setting, the shadow resolution, and the shadow distance.

    You might also consider adjusting the kernel Shadow Softener uses to be as small as possible while still looking good (You might choose PCF4x4 instead of PCF8x8 for example). Smaller kernels not only run faster, but have less of a problem with acne in complex scenes.

    Regarding shadow resolution, Unity bases this on a number of factors including the game's current resolution, and available VRAM. "Very High" can sometimes be the same resolution as "High" if Unity doesn't think it needs the added resolution, or there isn't enough VRAM on the system to support it.

    Hope this helps.
     
  22. 8Infinite8

    8Infinite8

    Joined:
    Jul 27, 2013
    Posts:
    112
    Many thanks for the reply.

    "You might also consider adjusting the kernel Shadow Softener uses to be as small as possible while still looking good (You might choose PCF4x4 instead of PCF8x8 for example). Smaller kernels not only run faster, but have less of a problem with acne in complex scenes."

    How might I go about this? I had someone configure the custom shaders to work with your Shadow Softener. So I guess this is done per shader?
     
  23. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    If you're using the Forward renderer, this is done per shader, and you would simply change the line that looks like:
    Code (csharp):
    1. UsePass "ShadowSoftener/PCF4X4"
    or possibly this:
    Code (csharp):
    1. #define SOFTENER_FILTER PCF4x4
    If you're using the Deferred renderer, you'll want to edit these defines in ShadowSoftenerConfig.cginc.

    The documentation goes over these settings in much more detail.
     
  24. 8Infinite8

    8Infinite8

    Joined:
    Jul 27, 2013
    Posts:
    112
    Many thanks!
     
  25. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    672
    Hi,

    Can someone explain me the diference between Shadow softener and Sunshine ?
    Thanks :)
     
  26. OnePxl

    OnePxl

    Joined:
    Aug 6, 2012
    Posts:
    307
    IIRC Shadow Softener softens the Unity shadows. Sunshine replaces Unity's shadow system.
     
  27. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    Also, Shadow Softener can be used in free while Sunshine requires Pro.
     
  28. Radiangames2

    Radiangames2

    Joined:
    Aug 22, 2012
    Posts:
    45

    I'm using Shadow Softener on point lights. On the static geometry, it tends to look nice, but on dynamic (moving) objects, it looks like the image above. The top image is at Very High resolution for shadows, the bottom is at Low. Is this just how realtime shadows will always look up close with Unity's built-in shadow system?

    Can these not be filtered as they're rendered? I can subdue the shadows to the point that the pixelation isn't so terrible, but I'm trying to have tight (and dark) interiors with harsh lighting, and these shadows are making that less of an option.

    Hopefully I'm missing something.
     
  29. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The problem is that Point lights are very hard to filter since samples are dealt with using 3D coordinates like a cubemap. With Directional or Spot lights we can use a bilinear PCF filter, but with Point lights we have to take jittered samples and average them. Shadow Softener allows up to 64 taps with Point lights, the built-in only goes up to 4(?), but they both use the same basic approach and have the same overall limitation.

    Something you might want to do is try defining SOFTENER_POINT_KERNEL to be something less than 1.0 (default). If you set it to 0.5 for example, you would get a penumbra that's half as large, but may appear smoother from being compressed more. I believe this is currently an undocumented feature, but it's not going anywhere so it's safe to use.

    Code (csharp):
    1. #define SOFTENER_POINT_KERNEL 0.5
    In the Deferred renderer, you would define this in ShadowSoftenerConfig.cginc...
    In the Forward renderer, you would define this in your shaders before including ShadowSoftener.cginc.

    I hope this helps.
     
  30. Radiangames2

    Radiangames2

    Joined:
    Aug 22, 2012
    Posts:
    45
    Thanks, that clears things up. Looks like using point lights should be limited to lights with dim shadows or no shadows (aka effects or subtle fill lights), or only at a distance.

    The spot light shadows do look very nice, especially with a Spot Angle of 90 or less.
     
  31. 99Castles

    99Castles

    Joined:
    Dec 13, 2013
    Posts:
    4
    Hi, I realise the shadow softening is applied per texel and so is scaled with the resolution of the screen, but this is changing my shadows quite a lot when the screen resolution is changed. Is there any way I can scale the shadow softening with the amount of pixels so that the shadows look the same no matter what the screen resolution is? Example of the problem below:

    Shadow is perfect here
    Screenshot 2014-10-26 00.08.49.png

    Here the window is smaller and the shadow is a bit too blurry
    Screenshot 2014-10-26 00.09.01.png
     
  32. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Yeah, that is a slight problem due to the way Unity automatically adjusts shadowmap resolution.

    Something you could try is using a #pragma multi_compile in your shader(s) to create more than one variant for different scenarios... like this:
    Code (csharp):
    1. #pragma multi_compile PCF_4x4 PCF_8x8
    Then create a script that uses Shader.SetKeyword() to select which quality to use depending on the screen resolution (I don't think there's a way to directly read the shadowmap resolution from a script).
     
  33. 99Castles

    99Castles

    Joined:
    Dec 13, 2013
    Posts:
    4
    That seems like it would work, I'm using deferred rendering though so I wasn't sure where to put the #pragma multi_compile line. I put it in ShadowSoftenerConfig.cginc:
    Code (csharp):
    1.  
    2. //Create shader variants for different screen resolutions
    3. #pragma multi_compile PCF_4x4 PCF_2x2 PCF_8x8
    4.  
    5. //Set the Default Shadow Filter
    6. #ifdef PCF_2x2
    7. #define SOFTENER_FILTER PCF2x2
    8. #endif
    9. #ifdef PCF_4x4
    10. #define SOFTENER_FILTER PCF4x4
    11. #endif
    12. #ifdef PCF_8x8
    13. #define SOFTENER_FILTER PCF8x8
    14. #endif
    15.  
    Is this the correct place to put it?

    And then I attached this script to my main camera:
    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. function Update () {
    5.  
    6. var screenWidth = Screen.width;
    7.  
    8. if (screenWidth < 540) {
    9. Shader.EnableKeyword("PCF_2x2");
    10. Shader.DisableKeyword("PCF_4x4");
    11. Shader.DisableKeyword("PCF_8x8");
    12. } elseif (screenWidth < 1079) {
    13. Shader.DisableKeyword("PCF_2x2");
    14. Shader.EnableKeyword("PCF_4x4");
    15. Shader.DisableKeyword("PCF_8x8");
    16. } else {
    17. Shader.DisableKeyword("PCF_2x2");
    18. Shader.DisableKeyword("PCF_4x4");
    19. Shader.EnableKeyword("PCF_8x8");
    20. }
    21. }
    22.  
    but it doesn't seem to be having any effect yet. It just defaults to PCF4x4
     
  34. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    That all seems mostly correct, although I don't think Unity supports #pragma lines within .cginc files, so you may have to put the multi_compile part in a few places: Inside Internal-PrePassCollectShadows.shader and Internal-PrePassLighting.shader next to the existing multi_compile statements.

    Also, you might run into an issue with PCF8x8 in Deferred, I'm pretty sure you hit the instruction limit with point lights, possibly others, so you might have to specify a lower SOFTENER_FILTER_POINT filter size than PCF8x8.

    Regarding Point Lights, there is also an undocumented the SOFTENER_POINT_KERNEL define you may specify which allows you to change the kernel size of the Point Filtering without changing the number of samples.
     
    Last edited: Oct 29, 2014
  35. 99Castles

    99Castles

    Joined:
    Dec 13, 2013
    Posts:
    4
    Works perfectly, thanks!
     
  36. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Oh, excellent! Let me know if you run into any other issues. :)
     
  37. 99Castles

    99Castles

    Joined:
    Dec 13, 2013
    Posts:
    4
    Hi again, I'm having another small problem, I've adjusted the bias on my only light (directional) so that there is no noticeable shadow acne, but there is a strange effect happening where at a certain distance from the camera the shade of my terrain texture becomes slightly darker (further away), and the boundary is quite noticeable. It looks like it could be shadow acne but only occurring outside a certain distance from the player. I've attached a short screen recording showing what is happening (but vimeo has compressed it so the quality is quite low), you can just see the effect on the cliff face:


    download for better quality: https://www.dropbox.com/s/dz2ydz1luncksus/ShadowProblem.mov?dl=0

    Do you know if there is any way around this? even if the boundary could just be blurred that would solve the problem.
    (Using deferred rendering, PCF7x7 and medium-quality hard shadows with a directional light)
     
  38. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    It's hard to tell, but it looks like that's where the cascades split. What's probably happening is that the next cascade down has larger physical texels, so you're seeing some subtle self-shadowing.

    All I can suggest is that you might try lowering the PCF kernel size a notch or two to, say, 5x5, or increasing the shadow resolution. Unity 5 adds the ability to control where each cascade splits, so that may also help when it's released.
     
  39. ErikRobson

    ErikRobson

    Joined:
    Mar 4, 2014
    Posts:
    11
    Greets Poly!

    We're trying to use Shadow Softener with the Unity 5 Beta in Forward rendering. Because U5's Standard/Universal shaders seem to get constructed dynamically at project build time, we can't get the Softener properly inserted into the relevant shader code.

    Using the Shadow Softener application tool on the Standard shader just returns an error: "DirectoryNotFoundException: Could not find a part of the path 'D:\dev\vr\unity\main\UnityTest\Resources\unity_builtin_extra'."

    ...which makes sense, because the shader doesn't really exist yet.

    Any ideas?
     
  40. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Shadow Softener is not supported in the Unity 5 beta yet, but now that Sunshine is mostly functioning I will be spending some time investigating what changes will be needed to get things working with Shadow Softener.

    One thing I'm excited about is the possibility that Shadow Softener will no longer require per-shader integration. I can't say for certain if it will work, but my initial experiments have shown that it might be possible to filter shadows in Forward/Deferred/Prepass using a single replacement shader. This would eliminate the need for the shader converter and manual editing entirely...

    Rest assured, as soon as I get Shadow Softener running properly in Unity 5 (without breaking Unity 4 compatibility), I'll post an update.
     
    hopeful likes this.
  41. ErikRobson

    ErikRobson

    Joined:
    Mar 4, 2014
    Posts:
    11
    Exciting news, then. Thanks!
     
  42. ErikRobson

    ErikRobson

    Joined:
    Mar 4, 2014
    Posts:
    11
    So wait, Poly - is that to say Sunshine is now fully compatible with Unity 5?
     
  43. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Well from what I can tell it appears to be working... I'm only going to call it "preliminary support" because Unity 5 is still in beta (complete with ongoing breaking changes) and there will likely be issues that I have missed.
     
  44. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Shadow Softener 1.3.2 is Now Available in the Unity Asset Store

    • Preliminary Unity 5 Beta support
    • Added support for the new "Pure Deferred" renderer.
    • Removed unused multi_compiles
    • Under Unity 5, shader modification is no longer needed for Directional shadows!
     
  45. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    This looks great! The default shadows definitely need improvements, so I'll probably be buying this soon.

    I noticed with the built-in Unity hard shadows that when the light source or object is moving, high-distance shadows get a lot of flickering at the shadow edges. Does this plugin help hide that artifact, or is this flickering not possible to get rid of unless I lower shadow distance?
     
  46. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Shadow Softener doesn't replace the built-in shadows, it's just a replacement filtering for them. If the flickering you're describing is the built-in "Soft Shadow" noisy effect that follows the camera, then Shadow Softener should help.

    Feel free to give it a try, and if it doesn't work out for any reason I'll issue a refund no questions asked. I prefer to keep things risk-free. ;)
     
  47. Sir-Spunky

    Sir-Spunky

    Joined:
    Apr 7, 2013
    Posts:
    132
    Thanks! :) Will probably have good use for it anyway even if it doesn't fix the flickering. But that's good to know.
     
  48. ErikRobson

    ErikRobson

    Joined:
    Mar 4, 2014
    Posts:
    11
    So Poly, what's the workflow now in Unity 5? (Specifically, I need to get soft point shadows to work with Unity 5's Standard shader in Forward rendering.)
     
  49. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The workflow isn't finalized for Unity 5, but as it stands...
    • Forward
      • Directional - Just Works
      • Point / Spot - Requires the "Forward Setup (Mobile/Advanced)" process in the manual. I have not tested this with the new standard shader yet.
    • Deferred
      • Directional - Just Works
      • Point / Spot - Requires selecting the custom Deferred shader in Project Settings->Graphics
    • Prepass (deprecated)
      • Directional - Just Works
      • Point / Spot - Should work by selecting the custom Prepass shader, but appears broken.
     
  50. rOBY GAMES

    rOBY GAMES

    Joined:
    Oct 16, 2012
    Posts:
    40
    Hello.

    I purchased today Shadow Softener version 1.3.4. Uttilizzo unity 3d free version 3.5.7 I tried sample scenes created by you, but I see no shadow on the packages.
    I attach a picture. Where am I wrong? I await your response.
    You can also contact me here: email cabras.games@gmail.com