Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Shadow Softener - Official Thread

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

  1. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,773
    @dahuilang

    I don't know much about Shadow Softener, but this is the relevant part of the error message, I think:

    It looks like this is unrelated to Shadow Softener. Maybe there is some permissions issue on your machine, or this file was locked by another process.
     
  2. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Thanks Josh, you beat me to it. :)
    Yes, this is unrelated to Shadow Softener, since there are no included scripts that would be processed by IL2CPP. Shadow Softener does actually appear to work properly in WebGL in my tests today (Unity 5.1.2f1 and Shadow Softener 1.4.5).

    Cheers,
    Oren
     
  3. dahuilang

    dahuilang

    Joined:
    Jun 5, 2014
    Posts:
    32
    yes ,you are right ,i restarted my computer, it worked , thank you
     
  4. dahuilang

    dahuilang

    Joined:
    Jun 5, 2014
    Posts:
    32
    it worked after i restarted my computer, but there is another queustion, the shadow is too week if the distance is small between two models , but the big distance is not what i want , how to strong the shadow except set shadow length=1

    not use Shadow Softener, shadow length=1
    shadow1.png

    use Shadow Softener, shadow length=1
    shadow2.png
     
  5. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The first thing I would try is adjusting the Bias and Normal Bias of the Light to compensate.

    If that doesn't work, and this is a Point light, you may need to adjust the kernel radius:
    Code (csharp):
    1. // Any value between 0 and 1 is valid:
    2. #define SOFTENER_POINT_KERNEL 0.5
    This code can be added to ShadowSoftenerConfig.cginc if you are using Deferred rendering, or to any Forward rendered shader. I thought I had a note about this in the documentation, but I can't find it now... I may have to revise it.

    There are 2 other settings to play with that could have an effect, I would try lowering these values:
    SOFTENER_POINT_BIAS_BASE, and SOFTENER_POINT_BIAS_SCALE

    I hope this helps,
    Oren
     
  6. ryschawy

    ryschawy

    Joined:
    Jul 28, 2012
    Posts:
    65
    Hi, I do have an issue using Shadow Softener in Unity 5.2.2 in deferred / linear mode in the Editor Scene View when using no Scene Lightning. No textures are displayed. Anybody?
     
  7. dahuilang

    dahuilang

    Joined:
    Jun 5, 2014
    Posts:
    32
    nothing happens , hope you can fix it, thank you by the way
     
  8. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Thanks for alerting me to this, it might have been a recent change to the deferred renderer that I'll need to integrate into an update.

    That's strange, I'll run some tests and see what's going on.
     
  9. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I've done some research and experiments. It seems that Unity still doesn't pass along the Light Bias to the shader when doing Point Lights, here's an open issue about it: http://issuetracker.unity3d.com/issues/shadow-bias-broken-for-point-lights
    I think this is why I originally added the point light constants you could adjust in Shadow Softener, although it was some time ago (Unity 3.x) so I'm a bit fuzzy on that. It would be better if I could get it to hook into the Light Bias setting somehow, I'll make a note of it for possible inclusion in an update. For now, the best solution is to modify any shader you're using with the following defines before including ShadowSoftener.cgic (or adding these to ShadowSoftenerConfig.cginc if you use Deferred)

    Code (csharp):
    1. //Low values seem to help:
    2. #define SOFTENER_POINT_BIAS_BASE 0.01
    3. #define SOFTENER_POINT_BIAS_SCALE 0.01
     
  10. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I haven't been able to reproduce this, but I'm on a Mac. What platform are you using?
     
  11. dahuilang

    dahuilang

    Joined:
    Jun 5, 2014
    Posts:
    32
    still not working.
    i found another issue, the shandow is appearing in WebGL editor but not working in browser after i made customer shader by including ShadowSoftener.cgic , why?

    win7, unity 5.1.1, firfox 41.0.2
     
  12. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Well without seeing an repro project I'm really working in the dark. Those are the constants for modifying bias behavior in Shadow Softener, and they should be at least affecting the shadows.

    I haven't used WebGL with Shadow Softener very much, I'll run some tests with Firefox.

    Edit: I did a quick WebGL export from Unity 5.1.2f1 on my Mac (closest version I had to yours), and it seems to work fine in Firefox although it takes longer than I'd like to load. Link: [WebGL Test]

    You are running an older version of Unity, so you are missing the latest Shadow Softener update. It's a minor update for PS4 compatibility, but it's possible it affects WebGL as well.
     
    Last edited: Oct 30, 2015
  13. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303
    Hi... I haven't buy this yet, But I'm interested.

    I have a question on how this works.

    I see on the documentation That I need to replace the Deferred shader on Graphics Settings.

    Does this means this is not compatible with Alloy or UBER?
     
  14. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I've made sure that the modifications required to the built-in Deferred shader are minimal. It's actually just a single line of code that you should be able to copy over to the same place in Alloy or UBER's replacement shader.

    Code (csharp):
    1. // =================================== BEGIN SHADOW SOFTENER SUPPORT ===================================
    2. #include "ShadowSoftenerInjection.cginc"
    3. // =================================== END SHADOW SOFTENER SUPPORT ===================================
    If you go this route, make sure to adjust the include path since their shader will be in a different directory.

    I hope this helps,
    Oren
     
    daville likes this.
  15. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    303

    Thanks
     
  16. ryschawy

    ryschawy

    Joined:
    Jul 28, 2012
    Posts:
    65
    I'm on windows.
     
  17. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I was able to reproduce your issue using a virtualized Windows installation running Unity 5.2.2f1 with the graphics set to Deferred + Linear Space. The problem now is that I'm also able to reproduce it in a blank project without Shadow Softener installed, which makes me think this could simply be a Unity bug.

    If you get a chance, try creating a blank project with the same Deferred/Linear/etc lighting setup and let me know what happens.

    Cheers,
    Oren
     
  18. ludo_ics

    ludo_ics

    Joined:
    Nov 25, 2014
    Posts:
    3
    Hi,

    Sorry to bother but I have a question concerning shadow softener on mobile (IOS)

    I've created a project which use Vuforia 5.0.6 for displaying some contents when tracking a specific image. I've added a simple plane just below my model for showing only its shadow, when I pre-visualized using the webcam, everything works fine but when I export my project to ios and run it, the plane where the shadow should appear become fully black.

    Is there some kind of shader we can't use with shadow softener?

    I join the quality setting I'm using.

    My light is a directional light with hard shadow. (other settings are the default one).

    below is the shader I'm using (found in the unity3d forum):

    Code (CSharp):
    1. Shader "TransparentShadowSupport" {
    2. Properties
    3. {
    4.     _ShadowColor ("Shadow Color", Color) = (0,0,0,1)
    5. }
    6. Category {
    7.     Blend  SrcAlpha OneMinusSrcAlpha
    8.  
    9.     Lighting Off
    10.     Zwrite Off
    11.     LOD 200
    12.  
    13.  
    14.     SubShader
    15.     {
    16.    
    17.         Tags { "RenderType"="Transparent" }
    18.      
    19.      
    20.         CGPROGRAM
    21.         #pragma surface surf Custom addshadow
    22.        
    23.         // Shadow Softener requires Shader Model 3.0
    24.         #pragma target 3.0
    25.         // Define the Shadow Filter
    26.         #define SOFTENER_FILTER PCF8x8
    27.         // Include Shadow Softener
    28.         #include "Assets/Shadow Softener/Shaders/ShadowSoftener.cginc"
    29.         struct Input {
    30.             float2 pos : POSITION;
    31.         };
    32.         uniform float4 _ShadowColor;
    33.              
    34.         void surf(Input IN, inout SurfaceOutput o)
    35.         {
    36.             //Pass through shadow colour to lighting model
    37.             o.Albedo = _ShadowColor.rgb;
    38.             o.Alpha  = _ShadowColor.a;
    39.         }
    40.              
    41.         half4 LightingCustom(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
    42.         {
    43.             half4 c;
    44.             //Inverse illumination - atten accounts for shadowing
    45.             c.rgb = s.Albedo.rgb * 1.0f-atten;
    46.             c.a   = s.Alpha * 1.0f-atten;
    47.                      
    48.             return c;
    49.         }
    50.         ENDCG
    51.     }
    52. }
    53. Fallback "VertexLit", 2
    54. }
    Could you please tell me why my texture appear black on IOS?

    PS: I'm using Unity 4.6.3 pro with the free version of IOS (tested on iphone 5c IOS 8.0 and iPad air IOS 8.3).

    I really thank you in advance for your help
     

    Attached Files:

  19. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hello,
    I'm not entirely sure how the shader should look, but I'll assume it works properly without Shadow Softener. To be honest though, it might just be a problematic shader on its own:
    Code (csharp):
    1. s.Albedo.rgb * (1.0f-atten); //Without parenthesis, this formula doesn't make sense to me.
    As for the inconsistency between desktop/mobile, I would try adding the "fullforwardshadows" option to your "surf" line:
    Code (csharp):
    1. #pragma surface surf Custom addshadow fullforwardshadows
    Without fullforwardshadows, Shadow Softener can't hook into the shadows on mobile devices, so this might be the source of the issue.

    I hope this helps,
    Oren
     
  20. ludo_ics

    ludo_ics

    Joined:
    Nov 25, 2014
    Posts:
    3
    Thank you very much for your reply.

    You were right I had to add the parenthesis for albedo and add the fullforwardsshadows (I tought this paremeter was only for point light and spot light).

    I just to reduce the blurry effect from PCF8x8 to PCF4x4. I don't know the reason (model have too many polygon?) but in PCF8X8, the framerate is really slow

    Thanks for your help :)
     
  21. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Oh, I'm glad those changes worked out. You're right that fullforwardshadows is mostly for point/spot lights, but it also creates forward passes for directional lights which Shadow Softener can then modify.

    Yeah, PCF4x4 is probably the best compromise between quality/speed. :)

    Cheers,
    Oren
     
  22. ryschawy

    ryschawy

    Joined:
    Jul 28, 2012
    Posts:
    65
    Thanks for trying this out. For me turning on shadow softener (setting it as deferred shader in the GraphicsSettings) is exactly the thing that's causing the problem. I haven't send you this error I get when turning shadow softener on:
    Failed to create DX11 vertex declaration; something wrong with vertex shader input data? (hr=80070057)
    Does that give you any clue?

    Cheers,
    ThomasR
     
  23. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hey Thomas,
    I'm out of the office most of this week so I apologize in advance for the delay, but I'll look into this as soon as I get a chance.
     
  24. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    If you get a chance could you try replacing the 2 "SV_POSITION" semantics in the deferred shader with "POSITION". I'm seeing a warning that DX11 doesn't like this semantic but since I'm virtualizing Windows I can't actually run DX11.
     
  25. ryschawy

    ryschawy

    Joined:
    Jul 28, 2012
    Posts:
    65
    :)

    That was it.
    It works.
    Thank you.

    Cheers,
    ThomasR
     
  26. Darkstep79

    Darkstep79

    Joined:
    Jul 18, 2012
    Posts:
    6
    I've been looking at Sunshine or Shadow Softener for solving my Point Light woes. I'm working on a very large scale space game and I'm happy with how I'm simulating the sun light, but when I'm creating Point Lights for space stations I'm not happy with the shadow casting as it is far too blurry. Even in a simple test scene with basic objects you can replicate the problem by moving the point light 100+ units away from the objects and see the shadow map size get reduced dramatically and produced blocky shadows. My space station are thousands of units wide so the shadow casting is far too low resolution from Point Lights and Spot Lights.

    Can Shadow Softener control the shadow map size for Point Lights? Can it use shadow cascades for Point Lights? Can Sunshine help with this problem? The very least I think Shadow Softener will help these low resolution shadows appear more pleasing, but I think a resolution increase is almost required.

    Thanks in advance.
     
  27. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hello,

    I wish I knew of a simple fix for this problem, but point light shadows are tricky. Point lights have this drawback since effective resolution decreases with distance from the light source and to my knowledge there is no way to increase resolution beyond what Unity offers. Sunshine also can't help since it doesn't work with point lights. You could try Shadow Softener, but I think you're going to have problems with blurry shadow acne from the insufficient resolution.

    Some things you might try
    • See if you can get away with baking your lights into the space station models.
    • See if you can get away with wide-angle spotlights instead.
    • Look into shadow volumes. They're pixel-perfect, but I don't believe they support self-shadowing. Maybe breaking up the space station models into chunks could work.
    • Write a custom shadowing solution just for this purpose.
    I hope this helps.

    Cheers,
    Oren
     
  28. Darkstep79

    Darkstep79

    Joined:
    Jul 18, 2012
    Posts:
    6
    Thanks for the feedback and ideas, Oren. Very much appreciated. Baking sounds like a good solution so I will try that method.

    A custom shadow solution sounds fun to make. Something I might dabble at and see how it turns out. For now the best success I've had is to fake the look I'm trying to achieve by placing multiple point lights and spot lights around the space station and use realtime lighting.Unfortunately very wide angle spot lights are even worse resolution than point lights. The space station in question is a torus with a main cylinder running down the middle and I wanted at least one point light on the top of the cylinder.

    I think I will give Shadow Softener a try as it will increase the visuals of all shadows. Thanks again for your help!
     
  29. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    No problem, best of luck finding a solution that works for your game. :)

    Cheers,
    Oren
     
  30. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Hello there!

    Just wanted to ask if this asset is working with 5.3 in Deferred?
    I just bought it and replaced the shader in the Graphics preferences, but now I'm missing all shadows.
    Sample Scene in Forward is working for me.
    Did I do something wrong?

    Best Regards,
    Kristina Waldt
     
  31. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    There was a small bug fix that didn't make it in the last release affecting DX11. In ShadowSoftener-DeferredShading.shader try changing both POSITION semantics to SV_POSITION.

    Code (csharp):
    1.  
    2. struct v2f {
    3.    float4 vertex : SV_POSITION;
    4.    float2 texcoord : TEXCOORD0;
    5. };
    6.  
    7. v2f vert (float4 vertex : SV_POSITION, float2 texcoord : TEXCOORD0)
    8. {
    If that solves the issue for you, I'll try and push an update out as soon as possible.

    Cheers,
    Oren
     
  32. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Hello there!

    Thanks for the fast response!
    I misunderstood at first, but changing "SV_POSITION" to "POSITION" helped!

    It's working fine now~

    Cheers,
    Kristina
     
  33. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hi Kristina,
    I'm glad it fixed the issue you were having. I haven't had a chance to test on DirectX yet, so it's nice to have additional confirmation that it works. I'll try to get the fix out to everyone else as soon as possible.

    Edit: Oops! You're totally correct that I had it backwards. It was indeed a switch from SV_POSITION to POSITION, and not the other way around *facepalm*. Apparently I haven't had enough coffee today. ;)

    Cheers,
    Oren
     
    KWaldt likes this.
  34. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Shadow Softener 1.4.6 is Now Available in the Unity Asset Store
    • Improved DirectX Support
     
  35. shreniksadalgi

    shreniksadalgi

    Joined:
    Sep 19, 2015
    Posts:
    1
    Hey!

    Shadow Softener is a great product and I've had good results with it (on mobile too!).

    I'm a noob to shaders and I'm trying to modify / create a new shader to render shadows onto a transparent plane with multiple spot lights. I haven't had much luck creating a custom shader (using the customizing filter or creating an additional pass or just messing around with your standard shader). Would be really nice if you could point me in the right direction!

    Much appreciated!
    -Shrenik
     
  36. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
    In Unity5 forward rendering, all the materials receive shadows that are blurred.

    Changing the shader to Standard or Diffuse 8x8 or Diffuse 2x2 gives the same result: barely blurred shadows.

    How do I change the PCF, can the PCF be changed per material?

    from left to right: custom-pcf2x2-pcf8x8
     
  37. Migueljb

    Migueljb

    Joined:
    Feb 27, 2008
    Posts:
    562
    Hello,

    Im on 5.3.2f1 using forward renderer. When I build to standalone for Oculus DK2 and the Vive the shadows wont come over in a build. If I get rid of shadow softner in the project the standard unity shadows build just fine. So is shadow shadow softner not VR ready? Any help would be great. Thanks.

    -Miguel
     
  38. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Which version of Unity 5 are you using, and what platform are you targeting? Unity 5 has made so many changes, it's been hard to keep up with compatibility on each platform.
    Make sure Shadow Softener is up-to-date, the current version doesn't come with a sample Diffuse 2x2 shader, so it might have issues with your version of Unity.

    I haven't worked with the Oculus/Vive yet, so I can't say one way or the other. Make sure you're using a Shadow Softener shader (like "Diffuse 8x8") since there is no "Shadow Collection" pass on mobile devices.

    It's worth mentioning that Shadow Softener is not recommended for Mobile since this form of PCF requires SM3 and is expensive (doubly so with VR).
     
  39. CFprime

    CFprime

    Joined:
    Feb 6, 2015
    Posts:
    27
    We are currently switching over to Unity 5. It appears that the new LM baking uses the internal shadow maps. Does it take Shadow Softener into account or override it during the baking process?

    Thanks,
    Tharyn
     
  40. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I believe the LM baking uses raytracing internally, so it would completely bypass Shadow Softener. If you are using baking and don't wind up needing Shadow Softener for your project, just PM me the order # and I'll issue a refund. :)

    Cheers,
    Oren
     
  41. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
    Targeting PC/MC in 5.3.3p1 funny enough, when I switch to ios shadows are smooth as silk.
     
  42. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    If you could PM me a small project that reproduces the issue I'll try and narrow down what's happening. In the mean time I'll check out that patch release and see if there's been any breaking changes to the graphics.

    Cheers,
    Oren
     
  43. DrDecipher

    DrDecipher

    Joined:
    Dec 5, 2012
    Posts:
    54
    Thank you for the information and the offer, but we use both and a refund is not necessary.
     
  44. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    hi @PolyVector !
    I've a question: in my project I use forward light, with basically only a sun -> directional light, with some custom shader built myself and some standard...
    how works your shadow softener? I tried to read the docs but I don't understand...
    my basical question is: I need to modify all my shaders to inject shadow softener or not?
    thanks in advance!
     
  45. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hello,
    On Desktop platforms (recommended) Unity 5 uses a Shadow Collector shader in both Forward and Deferred renderers which Shadow Softener replaces. This will soften Directional light shadows automatically, but be sure to restart Unity after importing Shadow Softener to force it to load this shader.

    For Point and Spot light shadows things are different. In Deferred, a similar replacement shader takes care of these shadows, but in Forward you're right that you would have to modify shaders you wish to receive soft shadows.

    Transparent Objects are the exception since they are purely forward rendered in Unity. If you wish transparent objects to receive soft shadows, their shader must be modified. I think most people leave built-in filtering on transparencies for simplicity though.

    I hope this answers your question!

    Cheers,
    Oren
     
  46. ghiboz

    ghiboz

    Joined:
    Sep 7, 2012
    Posts:
    465
    hi @PolyVector !
    thanks for your reply: I've not yet purchased your asset, i'm investigating... so the only thing needed is put the asset in my project (unity 5, desktop platform, forward with one directional light) and automatically I obtain the benefits of shadow softener?

    reading the documentation there's a thing that I don't understand: for example, I wish use PCF4x4 setting, where I set
    Code (CSharp):
    1. #define SOFTENER_FILTER PCF4x4
    if I doesn't need to change my shaders?
     
    Last edited: Mar 2, 2016
  47. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    5,994
    I wanted to thank @PolyVector who solved this problem.

    Unity has a bug: when there are two Shadowcaster shaders it doesn't know which one to use so it choses randomly, also doesn't log an error because that would cut the fun of bug chasing in half.

    There were two Shadowcaster shaders, one from shadow softener and the other from some old built in directory that we used during dev. Nuke the old shadowcaster and now we have smooth shadows.


     
  48. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Correct, you won't have to change anything to get the benefits from Directional Lights in the Forward (or any) renderer on Desktop platforms.
    The code you see in the documentation is specifically for other cases such as:
    • Point or Spotlight shadows
    • Non-Desktop platforms
    • Transparent shadow receivers
    These are the cases where you would need to modify a shader to get softer shadows.

    No problemo, but ultimately you were the one who tracked down the cause! I think Unity just likes to keep us on our toes, warnings would make things much to easy. :)
     
  49. gian-reto-alig

    gian-reto-alig

    Joined:
    Apr 30, 2013
    Posts:
    756
    Quick question: I use shadow softener in my Unity projects for quite some time now... it is great, but something it does not fix is the jarring border between two shadow cascades. Which, given a viewpoint high enough looking down, can be quite ugly.

    Is there a way that shadow softener could, in a future version, also smooth the border between shadow cascades? I have nothing fancy in mind, just some nice filtering the way it currently does for shadows within the cascade.

    Or is this outside of what shadow softener can achieve or access and would need an update to the shadowing system of Unity?


    Regards

    Gian-Reto
     
  50. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hi Gian-Reto
    I put some thought into this when designing Shadow Softener, and never came up with a satisfactory solution. Smoothly blending would require performing the expensive PCF filtering twice, one for each neighboring cascade. Jittering might improve the look somewhat, but doesn't really eliminate the problem.

    I'll experiment more with this when I get some free time.

    Cheers,
    Oren
     
    gian-reto-alig likes this.