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

Sharp Shadows Toolkit (LWRP/URP)

Discussion in 'Assets and Asset Store' started by gustavolsson, Sep 4, 2019.

  1. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Thanks for reaching out! It means a lot to hear positive feedback, not only the support requests when something doesn't work quite right. I've decided to keep going for now and I plan to investigate a solution to this issue asap.

    From now on though, I'll have to clearly state "supported versions" of Unity and dependencies on the website.
     
    chadfranklin47 likes this.
  2. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    See chadfranklin's answer below. If your project requires URP 7.2 and up, please contact me with your invoice number and I'll request a refund on your behalf. If you're using an older version, please read the README thoroughly and if you're still having problems just contact me using the same website form as above and I'll try to help you.

    Thanks @chadfranklin47 !
     
    chadfranklin47 likes this.
  3. Katzelschnurr

    Katzelschnurr

    Joined:
    Mar 25, 2011
    Posts:
    28
    Thanks, I was somehow not aware of this option! In my case it made sense to modify the postprocessor behaviour which worked fine as well.

    Another question: to change the strength of the shadow during runtime, we figured out we can do so but have to use reflection - which could break if Unity changes some things again.. is there another way by chance?

    Best regards

    PS: great to hear, that you want to keep going! Your asset has great value already and I would love to use it.
     
    gustavolsson likes this.
  4. chadfranklin47

    chadfranklin47

    Joined:
    Aug 11, 2015
    Posts:
    217
    @gustavolsson You're welcome. Glad to see you've decided to try to get things working with this asset. I would very much like to use it in my upcoming game.
     
    gustavolsson likes this.
  5. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Sure, you can access the shadow intensity by referencing the "ShowSharpShadows" render pass. Here is an example script that changes the intensity dynamically over time:
    Code (CSharp):
    1. using UnityEngine;
    2. using SharpShadowsToolkit;
    3.  
    4. public class DynamicallyChangeIntensity : MonoBehaviour
    5. {
    6.     public ShowSharpShadows showSharpShadows;
    7.  
    8.     protected float previousValue;
    9.  
    10.     public void OnEnable()
    11.     {
    12.         if (showSharpShadows != null)
    13.         {
    14.             previousValue = showSharpShadows.settings.shadowIntensity;
    15.         }
    16.     }
    17.  
    18.     public void OnDisable()
    19.     {
    20.         if (showSharpShadows != null)
    21.         {
    22.             showSharpShadows.settings.shadowIntensity = previousValue;
    23.         }
    24.     }
    25.  
    26.     public void Update()
    27.     {
    28.         if (showSharpShadows != null)
    29.         {
    30.             showSharpShadows.settings.shadowIntensity = Mathf.Cos(Time.time) * 0.5f + 0.5f;
    31.         }
    32.     }
    33. }
    34.  
     
    Katzelschnurr likes this.
  6. IronHelmet

    IronHelmet

    Joined:
    May 2, 2017
    Posts:
    83
    Hello Gustav,

    We have an open world game and I think we are going to have to make a few changes to sharp shadows to speed things up.

    For example, just calling Late Update so many times on the assets in our scene is very expensive. Our frame-rate doubles when I comment out the Late Update call on the sharp shadows script. (Thats after I actually disable the shadow rending which is not all the expensive! :))

    I also discovered when I set a far clipping plane on the camera the shadows go crazy.

    I was wondering if you had ever done any thinking about how you might set the shadows up for a very large open world scene.

    So for example I think we'll probably need to remove the sharp shadows script from each object, and have some special batched shadow objects that collect up all the shadow casters for objects in an area.

    Anyhow, would love to hear any thoughts you might have.
     
    Nyanpas likes this.
  7. maksimszigunovs007

    maksimszigunovs007

    Joined:
    Oct 9, 2019
    Posts:
    8
    Gustav, please, send me whole unity project zip that contains your sharp shadow asset and test scenes with everything working. I have no idea what I am doing incorrectly, I can not set up things, unfortunately.
     
  8. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Hi :)

    Yes, getting rid of LateUpdate() would speed things up in scenes with a lot of objects. I'll see if I can add this to the next update.

    This is what's known as z-fighting, try to keep the the near and far plane values in a reasonable range. For example, if you increase the far plane distance also increase the near plane distance slightly. (No need to keep the near plane below 0.1 for example, and if you're doing an FPS you should render the equipped items using another pass with another near/far plane distance)

    I think it's actually quite easy to remove the LateUpdate() overhead.. It involves the SharpShadow components to register/unregister themselves to a "SharpShadowManager" on enable/disable and then let the manager loop over a list of all active SharpShadow components. That'll reduce the number of method calls per frame considerably! (This is the approach I would go in the next update)
     
  9. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Please follow the exact steps from the README first. If it still doesn't work, please email me at: https://gustavolsson.com/contact
     
  10. maksimszigunovs007

    maksimszigunovs007

    Joined:
    Oct 9, 2019
    Posts:
    8
    I don't get how and where to download URP 7.1, because now unity has latest 7.4 or something like that.
     
  11. maksimszigunovs007

    maksimszigunovs007

    Joined:
    Oct 9, 2019
    Posts:
    8
    So my point is if there is URP 7.1 in your project then I can just take it and copy necessary files into my project.
     
    gustavolsson likes this.
  12. playBlaster

    playBlaster

    Joined:
    Jan 5, 2017
    Posts:
    7
    I found a solution that works for all versions of URP. i'm using 7.3.1. The downside is you need to use a custom shader with custom lighting. I'm doing this in shadergraph. but it I don't see why it could not be done in a traditional unity shader. I dug though the code and apparently, Unity only removed the the reference to "SampleScreenSpaceShadowmap(shadowCoord)" from their shader. The rest of the screen space shadowmap code is still there. So all you have to do is use the below methods to grab the results from the sharp shadows toolkit inject pass.

    I used a custom function node in shadergraph with the following file as the source:

    Code (CSharp):
    1.  
    2. #ifndef CUSTOM_LIGHTING_INCLUDED
    3. #define CUSTOM_LIGHTING_INCLUDED
    4.  
    5. void MainLightShadowsScreen_float(float3 WorldPos, out float3 Direction, out float3 Color, out float DistanceAtten, out float ShadowAtten)
    6. {
    7. #if SHADERGRAPH_PREVIEW
    8.     Direction = float3(0.5, 0.5, 0);
    9.     Color = 1;
    10.     DistanceAtten = 1;
    11.     ShadowAtten = 1;
    12. #else
    13.     float4 clipPos = TransformWorldToHClip(WorldPos);
    14.     float4 shadowCoord = ComputeScreenPos(clipPos);
    15.  
    16.     Light mainLight = GetMainLight(shadowCoord);
    17.    
    18.     Direction = mainLight.direction;
    19.     Color = mainLight.color;
    20.     DistanceAtten = mainLight.distanceAttenuation;
    21.     ShadowAtten = SampleScreenSpaceShadowmap(shadowCoord);
    22. #endif
    23. }
    24.  
    25. void MainLightShadowsScreen_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
    26. {
    27. #if SHADERGRAPH_PREVIEW
    28.     Direction = half3(0.5, 0.5, 0);
    29.     Color = 1;
    30.     DistanceAtten = 1;
    31.     ShadowAtten = 1;
    32. #else
    33.     half4 clipPos = TransformWorldToHClip(WorldPos);
    34.     half4 shadowCoord = ComputeScreenPos(clipPos);
    35.    
    36.     Light mainLight = GetMainLight(shadowCoord);
    37.    
    38.     Direction = mainLight.direction;
    39.     Color = mainLight.color;
    40.     DistanceAtten = mainLight.distanceAttenuation;
    41.     ShadowAtten = SampleScreenSpaceShadowmap(shadowCoord);
    42. #endif
    43. }
    44.  
    45. #endif
    46.  
    you will need to make use of the outputs of these methods on your own in your custom lighting setup. I.E. multiply "DistanceAtten" by "ShadowAtten" to get the shadows. Use direction... dot product etc...

    of course there is a chance Unity will remove the rest of the screen space shadowmap code at any time. However, it would still be possible to make use of any texture created in the inject pass. just change the name of the texture in the pass from "_ScreenSpaceShadowmapTexture" to something else and sample that texture in the code above.
     
    gustavolsson likes this.
  13. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I answered this in an email, please see that conversation for more info!
     
  14. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    That's great, thanks for sharing! I suspect that it works because of the fact that the render texture called _ScreenSpaceShadowmapTexture is simply created in my render passes if it doesn't exist previously (that's pretty neat!).

    A downside with this is that a user can only use custom shaders within their projects, and s/he must be confident with creating shaders... Still, I think this might be a middle ground for a future update. Thanks again for sharing!
     
  15. Black_Raptor

    Black_Raptor

    Joined:
    Nov 3, 2014
    Posts:
    175
    Hi,

    Still no news for URP 7.4+ ?
     
  16. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    257
    I just found this asset and I'm really happy you decided not to deprecate it, it is a very clean implementation with a lot of value! It's a shame it's such a tricky thing to add native support to.

    I noticed you aren't using Carmack's Reverse for when the camera is in shadow, and I'm presuming this is because of the licensing. You might be interested to know that the patent expired in 2019, and so presumably it's fine to use now.

    You've also almost got functioning VR support in there, you just need to add UNITY_VERTEX_OUTPUT_STEREO to your Varyings shader structures and UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output); in your vertex shaders.
    Unfortunately I think it might be too slow to use in VR because of the fillrate, especially with MSAA enabled, but nevertheless it looks very nice.
     
  17. IronHelmet

    IronHelmet

    Joined:
    May 2, 2017
    Posts:
    83
    For anybody interested, I've been following the development of a screen space shadow implementation that Unity is working on here. https://github.com/Unity-Technologies/Graphics/pull/1556

    I have no idea how easy this feature will be to take advantage of, but when it drops in a release I plan to try make use to it to get sharp shadows working again. I know almost nothing about graphics programming, so any help would be much appreciated.
     
    playBlaster and Nyanpas like this.
  18. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Nope, not enough free time sadly. I've decided to release this package for free for now, there is simply too many support requests and problems related to different versions of Unity. I'm sorry to you guys who bought it, but imagine that I spent 2 months full-time on this and that I'm nowhere near getting a return of investment.

    Thank you for the nice words. Yes, I didn't even want to be close to the patent for obvious reasons. Thanks for letting me know, if that's true then that's pretty low-hanging fruit for a performance update! Cool with the VR support. I've sold all of my VR gear so I'm unable to test this myself but I just added those lines to all shaders that didn't have them.

    There is some other PR that brings back the functionality that this toolkit relies on (the screen space shadow resolve texture) and I've been checking it causally from time to time, that's probably the best bet to focus on (once it's merged and released).

    I will of course update you guys in this thread if I make any progress!
     
    Last edited: Oct 10, 2020
    Nyanpas and Fewes like this.
  19. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    That's the biggest problem. Are you required to support a lot of versions or can you simply state which version(s) you are supporting? One of the reasons I never upload anything to the Unity store is exactly the problems with maintenance with regards to version inflation.
     
  20. KenjiJU

    KenjiJU

    Joined:
    Dec 31, 2012
    Posts:
    15
    Hello. How do I uninstall this safely?
     
  21. qpuilie

    qpuilie

    Joined:
    Jan 14, 2020
    Posts:
    69
    Hi,

    In the document, your highest test environment is 2019.3, but I work in Unity 2019.4.10f1, and the lowest URP version I can choose is 7.3.1. Although the ShadeMode I use is "Multiply Scene After Opaque", SharpShadows does not work properly. But when I switch to 2019.3.0f6 (URP 7.2.1), it works normally. Can you provide some ideas to help me find the problem, or how should I troubleshoot the problem?

    Thanks,
    Ripple
     
  22. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    Screen space shadows dropped in Unity 12. Has done zero to improve the quality of my shadows ;-P. But I wonder if it's possible to inject this in somehow?

    (I'm willing to buy the asset but only if I know it might work).
     
    Last edited: May 28, 2021
    gustavolsson and Nyanpas like this.
  23. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Great news everyone!

    Unity finally added the screen space shadow texture back in URP 11 so I managed to get the Sharp Shadows Toolkit working with Unity 2021.1 and URP 11!



    Stay tuned for an update...
     
    burningmime, Nyanpas and Ploops like this.
  24. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    1. Remove the SharpShadowsToolkit folder
    2. Remove all *_shadows.asset files that were created next to any shadow casting 3d model (for example: "SharpShadowsToolkit/Examples/Models/Workbench_shadows.asset")

    Unfortunately, I cannot support any permutation of Unity editor version and URP version, it would take too much time. Would Unity 2021.1 and URP 11 work for you? (see above)
     
  25. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    The update with Unity 2021 and URP 11 support (version 1.1) has been submitted to the store!

    Changes:
    UPDATE: Unfortunately I introduced a compile error in non-debug projects in v1.1 and I've submitted v1.1.1 to fix it, stay tuned! If you download the toolkit on v1.1, please move the offending code ("#if ... #else ... #end") into the SharpShadowsToolkit namespace just below it.
     
    Last edited: Jun 21, 2021
    burningmime and Nyanpas like this.
  26. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    Gonna try this again soon if I get the time...!
     
    gustavolsson likes this.
  27. Murdagamme

    Murdagamme

    Joined:
    Jul 22, 2019
    Posts:
    3
    It would appear that SharpShadowManager script is missing in v1.1, albeit package contents preview within the store implies otherwise. Can I get a confirmation or would this be an error from my part?
     
    gustavolsson likes this.
  28. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Hi! Please download the latest version v1.1.1 (released just now) which should fix the compile error that you're probably experiencing.

    Hi! Unfortunately, a last minute bug creeped into the v1.1 release and there is a compile error in SharpShadowManager if SHARP_SHADOWS_DEBUG is not defined (which is only the case on my computer -_-).
    I've submitted a fix as v1.1.1, just waiting for the asset store to accept it.
    To work around the issue, open up SharpShadowManager.cs and move "namespace SharpShadowsToolkit {" to above the #if line, like this:
    SharpShadowManager_fix.png
     
    Last edited: Jun 21, 2021
    Nyanpas likes this.
  29. FissicsPeep

    FissicsPeep

    Joined:
    Jan 14, 2014
    Posts:
    65
    Hi, I'm interested in this asset, and I'd like to clarify one aspect - "No support for custom vertex displacement". Just to sanity check, this means any shader I have where I modify the vertices, then this will not work correctly? It will just create a shadow from the unmodified mesh? This would be unfortunate for me as I have some meshes that I would like to cast shadows - waving flags, trees in the wind etc.
     
  30. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Hi and thanks for the interest! You are correct.

    Yes, exactly.

    Unfortunately there is no such support. You might be able to get it working by modifying the bundled shaders but I would not recommend it as a solution. Also, transparent textures on for example tree leaves will not show up in the shadows, only the polygons will.

    Hope this helps!
     
  31. FissicsPeep

    FissicsPeep

    Joined:
    Jan 14, 2014
    Posts:
    65
    Thanks for the reply. Yeah, I don't want to get into messing with the shaders. In my case my trees are low-poly, so no transparency anyway.

    I don't know too much about shaders, but is it not possible to create another pass for these shadows, that only invokes the vertex shader? I seem to recall the projectors (pre-URP) worked by rendering the objects (receiving the projector) with a different material.

    I don't know... just wishful thinking of ways this might work with my dynamic verts :)
     
  32. Peter-Dijkstra

    Peter-Dijkstra

    Joined:
    Feb 15, 2013
    Posts:
    8
    Hi!

    Sharp Shadows Toolkit looks perfect for the vertical slice me and my friend are making. It's a low poly game looking like it came out somewhere between the original PlayStation and the Gamecube. Some questions:

    - Does it work with URP 12?

    - I read that performance on mobile isn't great, necessarily. We would want to target Switch down the line. But it is fairly low poly so maybe it's not much of an issue? Like I said, we're making a vertical slice so we can show it to publishers and get funding, maybe, hopefully, so it's not hugely important at this stage but I'm interested to know nonetheless.

    - Is there a way to get the shadows in Shader Graph? I can also write shader code, but I'm more comfortable with node based shader editors. This would allow us to easily experiment with blending modes and the like.

    - The website states that it only supports one directional light, so I suppose I can't do shadows straight down for characters in addition to angled shadows for the environment?

    - Any plans for adding vertex displaced shadows and/or alpha clipped shadows?

    Thanks!
     
  33. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    I just checked and it seems like Unity has once again changed the URP internals, so unfortunately not.

    The performance impact is mostly related to how many overlapping shadow "volumes" there are in a scene. Imagine looking downn a pathway with pillars next to it, all the way to the horizon casting shadows on the path. This would be a performance intensive scene as the (invisible) shadow volumes of the pillars would all overlap and some pixels of the screen would have a huge amount of overdraw, causing bad performance. It is possible to get good performance from shadow volumes though, see Doom 3 as an example.

    Yes, shaders made in ShaderGraph will both cast and receive shadows automatically. This has been one of the priorities of my solution.

    Unfortunately not.

    Shadows for vertex displacement would be possible but would require custom nodes/lines of code in your shader to get it working with shadows. However, since the toolkit only generates what amounts to coffee money I have no plans to work on an update other than for fixing critical bugs at the moment.

    Hope this helps!
     
  34. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Scratch that, I got it working.. just submitted update v1.1.2 adding support for Unity 2021.2 and URP 12.
     
    Last edited: Dec 13, 2021
    FissicsPeep and chadfranklin47 like this.
  35. Peter-Dijkstra

    Peter-Dijkstra

    Joined:
    Feb 15, 2013
    Posts:
    8
  36. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    644
    Hey ... is this still active? Also, does it support 2022 LTS + otoon shader?
     
  37. gustavolsson

    gustavolsson

    Joined:
    Jan 14, 2011
    Posts:
    339
    Depends on what you mean by "still active" :p

    The toolkit works as intended on all officially supported versions listed in the readme under "3. Supported Unity builds". I have not looked into Unity 2022 support yet, it might work out of the box or it might not, so if you need to use that version I would hold off on buying.

    Best regards,
    Gustav
     
  38. TomLeeLive

    TomLeeLive

    Joined:
    May 2, 2018
    Posts:
    4
    Hello @gustavolsson thank you for developing Sharp Shadow Toolkit.

    I am using your asset in my project.

    in the past. I guess this asset is supporting for built-in render pipeline but URP only support for now.

    do you have plan for supporting built-in ? or can I get past version of Sharp Shadow Toolkit package?

    and also as far as I understand if I have many object in scene, then fps is low. do I need to additional camera frustum cull code for better performance?

    upload_2023-9-6_11-5-18.png
     
    Last edited: Sep 6, 2023
  39. RangerXT

    RangerXT

    Joined:
    May 25, 2023
    Posts:
    1
    Is there any specific reason why it's limited to directional light and no point/cone lights? Shadow volumes really work best for interior lighting imo.
     
    Last edited: Sep 20, 2023