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

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Yes, I believe Unity will be pushing rendering much further in the future. Render Loops may even make custom shadow implementations easier to integrate, who knows. Interesting about UnityGrass, I had dismissed it myself after bad experiences with performance/quality. Glad to hear it's improving. :)

    Cheers,
    Oren
     
  2. OlliIllustrator

    OlliIllustrator

    Joined:
    Nov 1, 2013
    Posts:
    71
    I am having a problem with Unity 5.5 and VR (Vive, openVR).
    Bought Shadowsofter because I am not satisfied with Uintys shadow quality/performance in VR and hoped to solve it.

    Shadow softener is set up and I have one directional light . In Editor (when I turn the shadow to hard) and when in NonVR Gameview I get beautiful soft shadows, but when I run in VR mode the shadows are not soft at all, neither the view on PC nor in the Vive.
    Do you have any idea what I can do?

    I tried it with your demoscene, same result: when I turn both lights in demo to directional in VR they are hard, no softening.
    Pointlight and spotlights in the demo work in VR.
     
  3. OlliIllustrator

    OlliIllustrator

    Joined:
    Nov 1, 2013
    Posts:
    71
    New try: tried it with soft shadows, seems to work (at least in the demo scene). Could it be that hard shadows are treated differently in VR somehow?
     
  4. OlliIllustrator

    OlliIllustrator

    Joined:
    Nov 1, 2013
    Posts:
    71
    Another try with a pointlight in my scene (and the manipulated standard shader on the floor) works nicely and makes hard shadow soft in VR. actually looks pretty nice--- but if possible I would like to avoid to tweak every shader I have used (Skin, GPU-hair and a couple more that are non-trivial and crucial for the project.)
    With directional light and softshadows in VR I do not have the same softness that I see with the pointlight and hard shadows or that I see in Editor weirdly..
    Actually the directional VR softshadow only looks a bit better then Unity without shadow softener and I guess does not really make sense. same with the hard shadow: it looks basically as in Unity bit a bit aliased. As if the filter uses a scale for blurring that is too small.

    With the pointlight:
    I also get those blocky transitions when crossing the border of a hard softened shadow.
    Tried to change the Bias of the light but did not seem to change a lot-- how is this connected to the bias? Or what do I have to tweak?
    Screenshot: Only the spacesuit and the floor material have SoftshadowStandardshader, rest is hard and can be ignored.
     
    Last edited: Dec 20, 2016
  5. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    First, double check that all of the replacement shaders are set up in Project Settings->Graphics. You want Screen Space Shadow, and probably the Deferred set to "Custom" with the corresponding Shadow Softener shader selected.

    For Deferred rendering, this should be all the setup required, with the exception of any transparent, or (for some reason) Standard shaders. In these cases replacements are needed for non-directional shadows.

    For Forward rendering, you will always need a replacement shader to support non-directional shadows.

    I'm not sure why this would be any different for 1 or 2 directional lights. Shadow Softener doesn't deal with any of the logical setup, only replaces the filtering used. Perhaps your Quality Settings has a limit on "Per-Pixel Lights" that could be raised?

    They should appear the same since Shadow Softener replaces the filtering completely, unless Shadow Softener isn't being applied for some reason. In this case you're probably seeing the built-in shadow filtering which has been improved to support 3x3 and 5x5 PCF in Unity 5 so it can look pretty soft.

    I know it's a pain to tweak shaders, but you can make it somewhat easier by including ShadowSoftenerConfig.cginc so all these shaders share a common configuration (instead of defining filter settings in each shader). Just remember to reimport shaders if you modify the config.

    There are a couple of Point light tweaks you can try...

    First, you can define SOFTENER_POINT_BIAS_SCALE before including ShadowSoftener.cginc:
    Code (csharp):
    1. // Example Usage (Default: 0.01)
    2. #define SOFTENER_POINT_BIAS_SCALE 0.015
    Second, you can define SOFTENER_POINT_KERNEL. (Try lowering this one)
    Code (csharp):
    1. // Example Usage (Default: 1.0)
    2. #define SOFTENER_POINT_KERNEL 0.5
    I hope this helps.

    Regards,
    Oren
     
  6. OlliIllustrator

    OlliIllustrator

    Joined:
    Nov 1, 2013
    Posts:
    71
    Thank you for the detailed reply. I fear I am a bit short on time for further digging into it, right now but I will dig deeper into the matter after Xmas I guess.
    One correction, seems that I wrote that so it is not clear:
    There is no difference with 2 lights.
    In my project I will use forward rendering, deferred is unfortunately not suitable for VR yet (technicall it is, but performance of screenFX and Aliasing is the problem).

    I sum it up to make it clear, wrote that a bit confusing:

    -Without VR in "normal" Shadow softener works nicley in viewport and gameview, directional light is globally softened, not necessary to use custom shaders even if the shadows are hard it looks wonderful.

    - in VR (openVR): directional lights:
    shadows are not (or only very little) softened in VR.
    The difference is very obvious and I do not see improvement over Unity native. If there is there is too little to make a difference. Viewport looks nice as I would like it to be, so the question is: why only in Viewport and not in Gameview?.

    in VR (openVR) other lights:
    Shadowsoftener works, but Shader customization has to be done. I will check out what can be done to deal with the blocky banding artifacts, thanks for the hints. I am sure this can be dealt with.

    Bottomline: you should look into the directional light VR matter. It would be really nice to be able to use the directional light shadows softened in VR. I have no idea what the cause of this is, since I am not very good with shaderstuff but it looks like as if Shadowsoftener is completely left out in VR rendering.

    Maybe somebody can confirm this or he has got in running in VR (Unity 5.5) -OpenVR-forward rendering, directional light-hard shadows and might wirte a line?
    Here ist the test: fresh project, only shadow softener imported

    Use the shadowsoftener demoscene for test, deactivate one light, set the other to directional hard shadows.
    Turn off VR in player settings, run scene, check gameview --> works
    Turn on VR (camera is automtically VR then) turn headset to look at products: shadows are not or nearly not aliased or softened. In headset view and also in Gameview on screen.

    I have replicated this with a fresh project with only shadow softener asset in it here in the screenshots to make clear what is going on, I am on a windows 8.1 PC btw. :
    Non VR Testscene:




    Now VR Testscene, forward rendering, one directional light GAME

    SCENE view during running VR scene

    when the scne is not playing the gameview also looks as it should---
     
    Last edited: Dec 21, 2016
  7. OlliIllustrator

    OlliIllustrator

    Joined:
    Nov 1, 2013
    Posts:
    71
    When browsing around I found this in UNity 5.4 feature list-- could this have anything to do with the directive light VR Problem? ( as said, I do not know a lot about shaders, but this sounded so--suspicious:)
     
    Last edited: Dec 21, 2016
  8. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Thank you for the detailed information, I feel much clearer on the issue now.
    The only VR headset I have at the moment is an older Oculus prototype, but I will pull this out of storage and and see if maybe it exhibits the same issue. If it doesn't occur with the Oculus headset I will come up with an experiment or two for you to run so we can narrow the cause down.

    My gut reaction based on your observations right now is that Unity may not actually be using Screen Space shadows in VR, and so it might be instead using the shadow collectors in the individual shaders. I'll look into this issue first.

    Regards,
    Oren
     
  9. OlliIllustrator

    OlliIllustrator

    Joined:
    Nov 1, 2013
    Posts:
    71
    the Oculus should work (at least my old DK2 does), should work with OpenVr also, not only with the Oculus custom setting.
    I really appreciate your support, thanks.
    Oh, and no hurry, christmas is coming:) I will be more then happy to shed light on the subject next year ---unless you immediately nail the bugger, of course.
    Merry xMas.
     
  10. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hope you had a nice xmas. :)

    Alright, I believe I've resolved the issue! All that's left is to run some tests and push a new update out. What happened was the built-in ScreenSpaceShadows shader recently got some new capabilities relating to projection matrices for VR. Shadow Softener didn't support this, so it was falling back to built-in shadows.

    A quick workaround is to delete the "Fallback" line in Shadow Softener's ScreenSpaceShadows replacement shader, but I suspect this will result in incorrectly projected shadows in some cases. (It worked fine on my DK2 prototype though).

    I'll get to work on finalizing the Unity 5.5 update. :)
     
  11. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Shadow Softener 1.4.8 is Now Available in the Unity Asset Store
    • Unity 5.5 support.
    • Fixed issue with VR
    • Updated Documentation
     
    ccsander and hopeful like this.
  12. ccsander

    ccsander

    Joined:
    May 17, 2013
    Posts:
    44
    Thanks for 5.5 support and VR fix (whatever that might been since I haven't noticed an issue on my VR projects).

    But...the updates are endless. :) It appears 5.6 beta changes some things with shadows and shadow softener no longer works (forward rendering is all I tested). I've been digging through Unity CGIncludes trying to figure out what is breaking shadow softener, but I haven't determined it yet. Hope there is a simple fix for it.

    Thanks
    ccs
     
  13. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Unity betas change so rapidly that we don't support them until we start seeing things getting finalized for that version. Double check that all of the replacement shaders are set up in Project Settings->Graphics.
     
  14. ccsander

    ccsander

    Joined:
    May 17, 2013
    Posts:
    44
    I have the replacement shaders set up, but I only use forward point lights so that doesn't apply for me. I understand about the betas. It is hard for me to keep up as well. If I find the fix, I'll post back to save you some trouble when you get to it.

    Thanks!
    ccs
     
  15. ccsander

    ccsander

    Joined:
    May 17, 2013
    Posts:
    44
    It looks like the issue is 5.5 and earlier UnityShadowLibrary.cginc from CGIncludes used inline function:

    inline fixed UnitySampleShadowmap (float4 shadowCoord)

    And AutoLight.cginc has (for forward point/spot shadows)
    #define SHADOW_ATTENUATION(a) UnitySampleShadowmap(a._ShadowCoord)

    Hack in shadow softener was to redfine UnitySampleShadowmap, and this works great since everything was either a define or inline function.

    Now in 5.6beta there is another non-inline function in between SHADOW_ATTENUATION macro and UnitySampleShadowmap call that breaks this redefine:

    AutoLight.cginc (for forward point/spot shadows)
    # define UNITY_SHADOW_ATTENUATION(a, worldPos) UnityComputeForwardShadows(0, worldPos, 0)

    half UnityComputeForwardShadows(float2 lightmapUV, float3 worldPos, float4 screenPos)
    ...
    //point realtime shadow
    #if defined (SHADOWS_CUBE)
    realtimeShadowAttenuation = UnitySampleShadowmap(worldPos - _LightPositionRange.xyz);
    #endif

    So UnitySampleShadowmap is still used, but it is used within non-inline UnityComputeForwardShadows so that redefine hack appears to no longer work.

    I was able to cobble a solution together that fixes this, but it is not very elegant and requires making copy of function from AutoLight.cginc that is likely to change a lot moving forward. The fix involves 2 steps:
    1. copy UnityComputeForwardShadows function from AutoLight.cginc to near bottom of ShadowSoftener.cginc, just before the last #else. Rename the function UnityComputeForwardShadowsSoft.
    2. in 'Surface Shader Haxies' section of ShadowSoftener.cginc add the following lines at bottom of #if defined(SOFTENER_SPOT) and #if defined(SOFTENER_POINT) sections:
    #undef UNITY_SHADOW_ATTENUATION
    #define UNITY_SHADOW_ATTENUATION(a, worldPos) UnityComputeForwardShadowsSoft(0, worldPos, 0)

    I didn't attempt to fix directional shadows yet, so this is just for spot and point.

    Maybe you can come up with something better, but this gets me by for now! Hopefully the above points you in the right direction.

    ccs
     
    Last edited: Dec 27, 2016
  16. PolyVector

    PolyVector

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

    Thank you very much for taking the time to work this out and post it, my job will certainly be easier when Unity 5.6 moves closer to a final release!

    Unity is a pretty fast moving target to keep up with when trying to replace core functionality in this way, as you can see. :)

    Cheers,
    Oren
     
  17. OlliIllustrator

    OlliIllustrator

    Joined:
    Nov 1, 2013
    Posts:
    71
    Thank you so much, stellar support.
    I will try it out tonight:)
     
    Skunkie likes this.
  18. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    In 1.4.8, on an iOS game in forward I get this error during build
    Screen Shot 2017-01-12 at 3.56.42 PM.png
     
  19. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    It sounds like some of the files might have been moved or not imported. You could try right-clicking on the PrePassLighting shader and reimporting.

    If that doesn't work I would remove Shadow Softener and import the asset from scratch.

    Cheers,
    Oren
     
  20. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    Thanks, the simple solutions work
     
  21. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Glad it's working now, Those are my favorite kind of solutions! :)
     
  22. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,225
    The best - now I'm testing this ol' game that has the softener on all hard shadows, testing it on ipad air 2 and perfs are abysmal, have you seen any way to optimize that and get close to zero perf cost from PCF?
     
  23. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    We don't recommend Shadow Softener for mobile devices, but it should perform better if you reduce the PCF kernel. The cost of PCF is mostly related to the number of samples taken, so reducing the kernel will improve performance.
     
  24. candycat

    candycat

    Joined:
    Jun 5, 2014
    Posts:
    29
    @PolyVector Hi, I just purchased your asset and I found it didn't work in Unity 5.6.0:



    You can see the shadow isn't blurred correctly.

    Can you fix that? Thanks.
     

    Attached Files:

  25. candycat

    candycat

    Joined:
    Jun 5, 2014
    Posts:
    29
    And I also found the shadows for directional light didn't work at least in Unity 5.4.2. In Unity 5.4.2, the sample scene includes two spot lights, which can deliver nice soft shadow. But for directional light, it doesn't work.

    QQ图片20170519193001.png
     
  26. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    It should have worked back in 5.4.2. Make sure you've selected the ShadowSoftener shaders in Unity's Graphics Settings.

    I can confirm there is a problem in 5.6.0, I'm working on tracking down the cause.
     
  27. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Shadow Softener 1.4.9 is now available in the Unity Asset Store.
    • Unity 5.6 support.
     
  28. candycat

    candycat

    Joined:
    Jun 5, 2014
    Posts:
    29
    @PolyVector Have checked it and works, great! Thanks for the quick support :)
     
    hopeful likes this.
  29. MorganSandb

    MorganSandb

    Joined:
    Jun 4, 2015
    Posts:
    19
    @PolyVector Hi! We are having issues getting shadow softener on Directional Light to work with Playstation 4 and Graphics Jobs enabled - Tested on : Unity 5.4.4 - Unity 5.5 - Unity 5.6.1. The issue we are experiencing is that either everything is in shadows from the directional light(No light gets applied to the meshes) or that everything gets lit by the light(No shadows). Using shadow cascades.
     
  30. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I haven't seen this issue on my Mac, although I don't have any experience with the PS4. I tried Unity 5.6.1 using Graphics Jobs and 4 Cascades with no issue. Does this still happen with Graphics Jobs disabled?
     
  31. MorganSandb

    MorganSandb

    Joined:
    Jun 4, 2015
    Posts:
    19
    Without graphics jobs it works fine 5.4 - we never tested 5.6 with graphics jobs and shadow softener.
     
  32. MorganSandb

    MorganSandb

    Joined:
    Jun 4, 2015
    Posts:
    19
    Just tested again on 5.4 to be sure, we don't get shadows from directional lights with graphics jobs and shadow softener!
     
  33. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Well Graphics Jobs is still an experimental feature, so it could very well be a Unity bug. Have you reproduced it without Graphics Jobs in any version?

    Cheers,
    Oren
     
  34. MorganSandb

    MorganSandb

    Joined:
    Jun 4, 2015
    Posts:
    19
    1)The shadows work like they should without shadow softener and graphics jobs turned on. 2)The shadows work With shadow softener and without graphics jobs. We did test on Unity 5.4 and unity 5.6.
     
  35. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Digging through the shadow collection code there's nothing I can find to indicate it does anything special to handle graphics jobs. This seems like an "experimental" problem on Unity's end, since I don't think graphics jobs are supposed to affect the shaders in that way.
     
  36. MorganSandb

    MorganSandb

    Joined:
    Jun 4, 2015
    Posts:
    19
    Ok. Thanks for looking into it!
     
  37. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,765
    Hello, I have a couple of questions on the asset:

    1. Right now I'm still using Unity 5.3.6. Does this asset work with that version of Unity?

    2. Does this asset help resolve the issues of shadow dithering due to semi-transparent shadows?
    The issue I'm running into with Unity appears like this:

    shadow1.jpg


    Can this assets be used to help to improve the appearance of these types of semi-transparent shadows from point lights?
    (This is just the Unity standard shader in "Fade" mode)

    Thank you.
     
  38. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hello,

    1. I try to release an update whenever Unity changes become great enough to break compatibility. Currently the relevant version that would be served to a Unity 5.3.6 editor was created for Unity 5.1.2. The next jumps are at 5.4.0, 5.5.0, and 5.6.0. Short answer: it should work.

    2. Yes, and No. Shadow Softener will be able to filter the shadows to look softer, but this filtering would be applied to the dithered source material. The soft appearance could potentially be "lumpy" due to the uneven nature of the source shadows. I've taken the example scene and made both boxes 50% transparent with both Point and Spot lights to show you what I mean.

    As a side note, your tarantula looks basically opaque except for the fur, yet the center of the shadow is still dithered/transparent. Using a separate material for the opaque body might improve your shadows without having to purchase anything. Of course I realize this might just be a random sample to show me. ;)

    Cheers!
    Oren
     

    Attached Files:

    ArachnidAnimal likes this.