Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Shadow Softener - Official Thread

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

  1. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Hello, we just ordered it and I got this after opening the sample scene in 3.5.6 Pro (Win7 64). Do you have any ideas, what causes the problem? Thx.

    $error.jpg
     
    Last edited: Oct 18, 2013
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,767
    hi there,

    i have tried shadow softener along with unity 3.5. and the original terrain shader but since i have installed the package the terrain shows a lot of "shadow interferences" artifacts.
    i am running unity 3.5.6 using deferred lighting, stable shadows, 1 directional light, hard shadows, 2 cascades on a mac book pro (nvidia 9600m).

    any idea how to fix this?


    lars

    $shadowsoftener.jpg
     
  3. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I haven't seen this problem before, I'll look into it right away!

    This is called Shadow Acne. You should be able to increase the Bias on your directional light. :)
     
  4. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Just an update on the bug you found, I was able to confirm it using Unity 3.5 on Windows. I'm heading out the door right now, but I will attempt to fix this tonight or tomorrow. :)
     
  5. XilenceX

    XilenceX

    Joined:
    Jun 16, 2013
    Posts:
    119
    Btw does Shadow Softener affect the appearance/visiblity of shadow acne in any way? Like positively or negatively or just the same as before?
    Given that the bias is on the same setting with and without it ofc.
     
  6. Lad-Ty

    Lad-Ty

    Joined:
    May 7, 2013
    Posts:
    36
    Just out of curiosity (very new to shaders), why is SM3 required? Wouldn't it be possible even without it? I bought this asset hoping it could run on mobile devices (stupid me, did not notice the SM3 in description :)) and was a little sad when i found out it does not work on Android.
    I'm still glad I bought it, it's an awesome piece of work and looks amazing on PC. Also it's somewhat an investment to the future (GLES 3.0 support I hope). I'm just curious if it would be possible to extend the functionality to GLES 2... mb with some limitations :-[
     
  7. rcalt2vt

    rcalt2vt

    Joined:
    Jun 6, 2009
    Posts:
    36
    Absolutely awesome, glad I picked it up. I do have one question though, would it be possible to adjust the level of softening based on the distance from the casting object using a directional light? Say for example you have a Pole sticking out of the ground, it would smooth less near the base and more as it gets towards the top of the shadow.

    Either way giving you 5 stars on the store as soon as my Unity copy loads the store again.
     
    Last edited: Oct 19, 2013
  8. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I would have to say that it increases it, by the very nature of PCF sampling. The further you sample away from the origin, higher the risk of acne. However, Shadow Softener employs a per-sample bias system that does a very good job of keeping it in check, although you may need to adjust the Bias setting depending on the scene.

    Unity's built-in "Soft" filter blurs a single sample in screenspace, so it's exceptional at avoiding acne, but doesn't look so great IMHO. ;)

    GLES 3.0 is currently supported for Spot and Point lights, and I'm going to be investigating Directional support as well in the next update. :)

    Edit: SM3 is required simply because there aren't enough spare instructions using SM2 in my tests. It just won't compile. Unfortunately I don't think there's much that can be done to support SM2 since the built-in shadows eat up quite a few instructions on their own.

    The technique you are describing is known as PCSS. I've actually implemented it if you read back through this thread, but unfortunately it's not feasible at this time due to some required data that is not exposed by Unity. To be honest, it's not as nice an effect as I would have assumed, so it's really not a huge loss.
     
    Last edited: Oct 19, 2013
  9. rcalt2vt

    rcalt2vt

    Joined:
    Jun 6, 2009
    Posts:
    36
    Ya after I typed the question I realized that while it would be a cool thing to have, most players would never notice that to justify the additional shader complexity I would wager. Thanks for the fast response!
     
  10. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Just a reminder to everyone that the 70% OFF SALE is ending in only 2 hours! Now's the time to grab a copy!

    A quick note for Unity 3.5 Pro users running Windows. There appears to be a compatibility issue with this version/platform combination that was just brought to my attention. I'm currently investigating this, and am hoping to have it sorted out in the next release. Thank you for your patience.
     
  11. Arian

    Arian

    Joined:
    Aug 19, 2013
    Posts:
    2
    How do you use the shadow softener? Im new and all.
     
    Last edited: Oct 19, 2013
  12. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I highly recommend working your way through the documentation, it's pretty easy to get up and running.

    If you're using the Deferred Renderer, you can simply restart the Unity Editor, and you'll see an improvement immediately. There's a config file in the Shadow Softener/Shaders/Deferred folder that lets you customize the filtering.

    If you're using the Forward Renderer, you'll need to edit any shader that you want to use to receive softer shadows. Again, it's very helpful to read through the documentation since it details this process, but often times you can simply right-click on an existing shader and select Create->Shader (Shadow Softener) to generate a modified version automatically.

    Hope this helps. :)
     
    Last edited: Oct 19, 2013
  13. Arian

    Arian

    Joined:
    Aug 19, 2013
    Posts:
    2
    Thank you soooooooooooooooooooooooooooooooooooooooooooooo much. cheers. :D
     
  14. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    406
    Hey PolyVector, just came here to thank you for this awesome asset. I got it on the sale and i completely love the shader generator, man it works 100% with SkyShop! Also... the lower the quality of the shadow (unity free), the better the blurred version :D


    (right-click and open for full size)


    keep up the great work!
     
    Last edited: Oct 19, 2013
  15. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Thanks.
     
  16. Becoming

    Becoming

    Joined:
    May 19, 2013
    Posts:
    781
    Thanks to you, i am a victim of cheesy advertising now, bought this at the 24h deal!
    Too bad that PCSS isn't possible with unity! If you are going to post about what you need to achieve Fast PCSS(link) in unity feedback i would gladly move some votes towards it, im probably not the only one! Some dreams in life are always good :p
     
  17. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    HAHAHA! I love it! I might have to steal the "softness twins" for an advert. :D

    After I push out a compatibility update and pay some attention to Sunshine, I will revisit PCSS once again since the people demand it. I don't see what all the fuss is about though, PCSS has some pretty nasty artifacts (imagine a character with a small penumbra walking under a building with a large one... one cuts into the other and it's pretty nasty). I think that's why it's not used in more games.

    I managed to track down the problem this morning! To fix it, open up ShadowSoftener.cginc and replace these lines:

    Code (csharp):
    1.  
    2.         #if defined(SHADOWS_NATIVE)  defined(UNITY4_PLUS)
    3.             #define SOFTENER_SAMPLE_SHADOW(coordDepth) UNITY_SAMPLE_SHADOW(_ShadowMapTexture, (coordDepth))
    4.         #else
    5.             #define SOFTENER_SAMPLE_SHADOW(coordDepth) UNITY_SAMPLE_DEPTH(tex2D( _ShadowMapTexture, (coordDepth).xy))
    6.         #endif
    7.  
    with these lines:

    Code (csharp):
    1.  
    2.         #if !defined(UNITY4_PLUS)  defined (SHADOWS_NATIVE)  !defined (SHADER_API_OPENGL)
    3.             #define SOFTENER_SAMPLE_SHADOW(coordDepth) (tex2D(_ShadowMapTexture, (coordDepth)).r)
    4.         #elif defined(UNITY4_PLUS)  defined (SHADOWS_NATIVE)
    5.             #define SOFTENER_SAMPLE_SHADOW(coordDepth) UNITY_SAMPLE_SHADOW(_ShadowMapTexture, (coordDepth))
    6.         #else
    7.             #define SOFTENER_SAMPLE_SHADOW(coordDepth) UNITY_SAMPLE_DEPTH(tex2D( _ShadowMapTexture, (coordDepth).xy))
    8.         #endif
    9.  
    Note: You will need to Reimport any shaders using Shadow Softener. You can do this by right-clicking on them (or their folder) and selecting Reimport.

    I'll include this fix in the next update. :)
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,767
    i had to raise the bias to "0.5" to make the acne not to show up any more.
    unfortunately shadows now loose the connection to their shadow casters so trees on the terrain seem to float around.

    not really what i wanted to archive i have to admit.

    may be you can have a look into this.

    thanks, lars
     
  19. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    It looks like you've discovered a bug! Apparently I'm only performing the per-texel bias when shadows are running in NATIVE mode, but not when the depth value is packed, and compared with my LIT macros... Hrmm

    I'll try to fix this in the next release, sorry for the inconvenience. :oops:

    In the mean time, your best bet would be to try using a single cascade, increasing your shadow resolution, or using a smaller kernel filter ( like PCF4x4 instead of PCF8x8 )
     
  20. olivier-etienne

    olivier-etienne

    Joined:
    Feb 15, 2013
    Posts:
    13
    Hello, I have recently purchase this asset.
    I have posted a comment on the Asset store recently and you have asked me to raise the issue on the Forum.
    This issue is as follow, I import the asset add a default cube, and see the result below:
    I have tried to adjust the light bias but made no difference. The filter selected is the PFC3x3.
    $shadow.jpg
     
  21. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    That is strange. A couple quick questions:
    • What version of Unity are you running?
    • What OS are you on?
    There is a compatibility issue that was just discovered with Unity 3.5 that will be fixed in the next release. This might be related. I posted the fix a few posts back if you'd like to try it. Just remember to Reimport your shaders after editing the file.
     
  22. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    5,767

    hi there,

    absolutely no problem!
    i just wanted to make sure if this was a bug or a "feature"...

    looking forward to the next release,

    lars
     
  23. cristims

    cristims

    Joined:
    Dec 21, 2012
    Posts:
    24
    Got the pack, great job!

    But I really have to ask you to add these 2 shaders in your package:
    - Nature Terrain Diffuse SoftShadow
    - Nature Terrain Bumped SoftShadow

    I've tried to use the code you posted on the first page of this thread.... no use. All I've got is a bunch of errors...and a purple terrain without textures)
    (I am not a shader coder, and I got no clue on what to do next)

    So, can you please help us the non-shader guys with some custom made terrain shaders that use your superb soft shadows?

    Thank you.
     
  24. PolyVector

    PolyVector

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

    The newer versions of Shadow Softener come with a nifty Shader Generator/Converter that automagically augments shaders for you (just tested it with the terrain shaders, works great!)... See the documentation for more details.

    Basically, you can do this:
    1. Download the built-in shaders for your version of Unity
    2. Copy the FirstPass and AddPass shaders to your project (works with the Bumped versions as well)
    3. Right Click on both shaders, and select Create->Shader (Shadow Softener)
    4. Generate some softer versions. ;)

    Because the generator isn't perfect, you'll want to make a small change to the FirstPass shader on the Dependancy line to have it reference the new softer AddPass, instead of the old one... I'm hoping to make the generator smarter in the future to handle this for you. :)

    Hope that helps!
     
  25. cristims

    cristims

    Joined:
    Dec 21, 2012
    Posts:
    24
    Thank you!
    I didn't know where the default shaders were. Now all works perfectly!

    On a side note, can you add a slider for "shadow spread"?
    Something that will make the shadow spread over a larger area
    The terrain seen from above, even with soft 8x8 shadows still looks too "hard". Also, this will help for darker days on fps games. The shadows on a darker, cloudy day are wider somehow.

    It adds a nice feel.

    Thank you again, great great job!
     
  26. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    975
    Will this benefit the lightmapping at all?
     
  27. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Glad it worked. Variable penumbra techniques are inherently noisier than edge-tap PCF, but maybe I'll add a Poisson Filter in a future version to allow that. :)

    Nope, Shadow Softener is for realtime shadows only. :)
     
  28. cristims

    cristims

    Joined:
    Dec 21, 2012
    Posts:
    24
    Sounds great!
     
  29. olivier-etienne

    olivier-etienne

    Joined:
    Feb 15, 2013
    Posts:
    13

    Hello and thank you for replying,
    I am using the latest version of Unity4.2 running on WindowsXP SP3.
    Can you confirm which post you are referring to and I will give it a try
    and confirm whether it works or not.
    Thank you very.
     
    Last edited: Oct 21, 2013
  30. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The fix probably won't help if you're already running Unity 4.2. I've never tested with Windows XP, so this could very well be a compatibility issue that I haven't run into.

    I'll try and find an old copy of WinXP to test with. :)

    Here's the post I was referring to, just in case it helps:
     
    Last edited: Oct 22, 2013
  31. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    @Olivier

    I believe I've been able to reproduce your problem by virtualizing a copy of WinXP running Unity 4.2 Free... I have a couple more questions about the issue:

    1) Are you seeing shadows from objects even if you drag them below the floor?
    2) Are the shadows abruptly cutting off? (100% shadows in the distance, 0% shadows up close)
    3) Have you ever noticed similar problems with the built-in Directional shadows? The bug I found actually happens with or without Shadow Softener, oddly enough!
     
    Last edited: Oct 22, 2013
  32. olivier-etienne

    olivier-etienne

    Joined:
    Feb 15, 2013
    Posts:
    13
    Well Thank you very much for that, much appreciated!

    Yes, but as you have mentioned this bug also happened with UnityFree built in shadow

    Actually it is the opposite, 100% close up and fading in the distance, but I don't mind that as it is fading gracefully!
    Just like the unity3D built in shadow does.

    I have noticed two more problem which do not happend with Unity built in shadow:

    1. When moving the cube up and down it reduce the size of the shadow of the object around:
    down
    $down.jpg
    up
    $up.jpg

    2. When moving the cube away from the light the shadow of the cube is clipped:
    $side.jpg


    Thank you very much for your excellent support.
     
  33. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Excellent! Your screenshots confirm that we are both looking at the same bug! I've noticed the exact same behavior down to the checkerboard patterns on the ground. The shadows do appear to be cutting off at inappropriate times, but this very well could be the shadowmap's format being incorrectly reported to the shaders.

    Unfortunately this does appear to be either a Unity bug or a video driver issue. We're both seeing the built-in shadows casting backwards, so there's obviously a problem. :eek:.

    Shadow Softener does alter the appearance of the bug as you've pointed out, but that's probably because it's using a different sampling/bias technique than Unity does... Sadly there isn't anything I can do on my end, since the source data appears to be corrupted or in the wrong format. :/

    I've found some other people with similar problems, but no work-around.

    I would suggest looking for updated video drivers to see if that affects the issue. Also, if upgrading Windows is an option, I would recommend that as well.

    Are you Virtualizing Windows, by any chance? I've noticed that this bug only happens for me using VMWare, but not when I boot into Windows. I assume this is because the video drivers are different when virtualizing.

    Anyway, if you can't get shadows working, just PM me your invoice number and I'll try to get you a refund.
     
    Last edited: Oct 23, 2013
  34. SeanM3D

    SeanM3D

    Joined:
    Jul 24, 2013
    Posts:
    192
    Unfortunately your plugin doesn't work for me properly.

    I use Skyshop shader everywhere except for the terrain where I use the Relief Terrain Pack 2.1. I have one directional light set to "Hard Shadows".

    Here is what I get with 4x4 filtering:

    $Shadows.jpg

    Is this the kind of soft shadow everybody is raving about? :/


    When I set the Default Shadow Filter to PCF 8x8 the mess begins:

    $4x4.jpg

    I get this:

    $Scene_Blue.jpg

    and these error messages:

    $Console_Errors.jpg

    In my Game view everything turns flat blue. In my Scene view I see NOTHING. My whole scene literally disappears.

    Also, when I set SOFTENER_FILTER_DIRECTIONAL to anything other than PCF 5x5 all shadows of my directional lights simply disappear.

    What's causing all this?

    On a sidenote: Having people edit CGinc files is terrible usability no matter how minute the required change in the file is.
     
  35. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    This is easily fixed. :)

    The problem is that you've set the Point Filter too PCF8x8 implicitly which is too high for the deferred renderer (check out the comments). If you uncomment the Point Filter line, leaving it at PCF7x7, you should squeeze by within the limits of SM3.0.

    There is no perfect solution to configuring shaders with the amount of flexibility Shadow Softener provides without exploding the permutation count and losing the ability to nicely specify custom filters. It's not ideal, but I think that anybody working on a game has the ability to edit a config file. :)
     
  36. SeanM3D

    SeanM3D

    Joined:
    Jul 24, 2013
    Posts:
    192
    Do I have to remove the comment from #define SOFTENER_FILTER PCF5x5 and everything else in the CGINC file when I remove the comments from this line:
    #define SOFTENER_FILTER_POINT PCF7x7 ? Or can multiple lines be without comment signs at the same time?

    Are my 4x4 shadows which you can see in the screenshot of my previous post correct? The amount of softness is really subtle. I was expecting a more pronounced effect.

    Concerning usability: I knew you would say that ;) But even gamers love usability. It's also annoying that one has to open a second application (in this case a text editor or an IDE) in order to adjust settings. No matter how you turn it, usability wise this is unacceptable nowadays.
    Anyhow, let's not get off topic.
     
  37. SeanM3D

    SeanM3D

    Joined:
    Jul 24, 2013
    Posts:
    192
    Also, why is it the Point Filter PCF 7x7 that I have to uncomment? I have no point lights in the scene. Only one directional light.
     
  38. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Yes, you can have multiple defines. The documentation goes over it, but here's a summary:

    SOFTENER_FILTER - Sets the default filter for all 3 light types (Directional, Spot, Point). If you do nothing else, all 3 will use this filter. This causes a problem if one goes over the instruction limit, but so far I've only seen the Point+PCF8x8 combination go over in the deferred renderer.

    SOFTENER_FILTER_DIRECTIONAL - Overrides the Directional filter, leaving Spot/Point alone
    SOFTENER_FILTER_SPOT - Overrides the Spot filter, leaving Directional/Point alone
    SOFTENER_FILTER_POINT - Overrides the Point filter, leaving Directional/Spot alone

    If you want the penumbra/softness to be larger, you would want to use lower resolution shadows. Both Directional and Spot filters operate in Light Space, so the physical size of the shadow texels matter. For example, the PCF4x4 filter blends 4x4 shadow texels, however large they might physically be.

    Because the shader gets compiled regardless of whether you use it or not.
     
    Last edited: Oct 23, 2013
  39. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    975
    I grabbed it when It was on sale. Quickly dropped it in a copy of my project, brought my PC to it's knees!!! Real time sun with thousands of shadow casters. I would have liked to see more balanced default settings. But i'm looking forward to seeing what it can do. My 2 cents. thanks.
     
  40. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I'm sorry to hear that, mind if I ask some questions?

    • What was the FPS before and after?
    • What version of Unity are you running? (3.5 / 4.2? Free / Pro?)
    • Are you using Forward or Deferred rendering?
    • How many shadow casting lights are there in your scene? What types?
    • What platform are you running on?
    All I can suggest off the top of my head:
    • Make sure Unity's "Soft" shadow setting is disabled on your lights. (to avoid double-filtering and ugly noise)
    • Try lowering the shadow resolution, or reduce the number of cascades... This can counterintuitively look better with PCF filtering.
     
  41. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Shadow Softener 1.2.1 is now available in the Asset Store!

    Changes:
    • Fixed compatibility issue with Unity 3.5 on some platforms.
    • Per-Texel biasing is now applied on all platforms.
     
  42. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    406
    OK, ive quickly put together a video of my pet project, with a bunch of the best assets we've got for Unity FREE working together and looking amazing...
    Shadow Softener is there for the win!



     
    Last edited: Oct 26, 2013
  43. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Whoahhhhhh!

    This looks amazing, excellent work! :D

    Edit: Would you mind if I stick this video in the first post as an example?
     
  44. nukeD

    nukeD

    Joined:
    Feb 12, 2009
    Posts:
    406
    It would be an honor. Thank you!
     
  45. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Done, and done! Thanks! :)
     
  46. givemeluckstar2018

    givemeluckstar2018

    Joined:
    Jan 15, 2013
    Posts:
    33
    please make a video tutorials for not good at english people
     
  47. givemeluckstar2018

    givemeluckstar2018

    Joined:
    Jan 15, 2013
    Posts:
    33
    Please recorded a simple video tutorial, Demonstrates simple process,thank you
     
  48. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Thank you for the suggestion, I will add this to my TODO list. :)
     
  49. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    I bought shadow softener as soon as you added the point light support :)
    i like it a lot but my problem is i can't make it work if i change the camera rendering path to Deferred lightning.
    with forward its working fine.
     
  50. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    That's odd. A couple quick questions for ya. :)

    1. Have you restarted the Unity Editor? This is required initially to swap out the prepass shaders.
    2. Are the other light types working in deferred?

    There is a limitation of PCF7x7 with Point Lights in the deferred renderer, above that it tends to run out of constant registers/instructions. You could try using PCF6x6 or below for point lights just to play it safe and see if that works.
     
unityunity