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

[Released] Analytic Soft Shadows for Unity

Discussion in 'Assets and Asset Store' started by JollyTheory, Mar 2, 2021.

  1. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Try reducing Shadow Strength on the component.
     
  2. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    I mean sure that helps, but this should work without that? as it dilutes the shadows too much? Anyhow, I figured out a hack/workaround for now, in the LightingPhysicallyBased_ overrde

    Code (CSharp):
    1.  
    2.  if (uass.a == 1.0) {
    3.         // this means it's the directional world light, so we dont modify it
    4.         if (light.color.r == 1 && light.color.g == 1 && light.color.b == 1) {
    5.             light.shadowAttenuation = uass.x;
    6.         }
    7.  
    8.         // if this is for a point light, we remove shadow based on the luminance of the light
    9.         else {
    10.             light.shadowAttenuation = min(1, uass.x + Luminance(light.color.rgb));
    11.         }
    12.     }
    13.  
    For the point lights we remove shadow based on the luminance of the color, it works neatly and still allows me to have dark/deep shadows - it might not be 100% correct, but dont need it to be

    I just set the main directional light to (1, 1, 1) to identify it in the shader, it's a hack i know, work for now
     
  3. Anisoft

    Anisoft

    Joined:
    Jul 5, 2013
    Posts:
    137
    Any plans to allow this to work with URP Deferred? Any chance it can work with both?
     
  4. MrPifo

    MrPifo

    Joined:
    Sep 11, 2017
    Posts:
    2
    Hey, I bought the asset and even though I think its really really cool, I'm quite dissappointed that it doesnt work with Orthographic Cameras. Or is there a way to make it work with Orthographic Cameras too? This would be really awesome.
     
  5. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, there's some complicated math involved with the way the asset does culling and Orthographic cameras that I was unfortunately not able to solve, so for now the asset does not work with Orthographic cameras, sorry.
     
    MrPifo likes this.
  6. Onat-H

    Onat-H

    Joined:
    Mar 11, 2015
    Posts:
    195
    Hi, your asset looks amazing! Are there any plans for HDRP support?
     
  7. bearcoree

    bearcoree

    Joined:
    Mar 8, 2016
    Posts:
    72
    Heya, I'm getting visual glitches using your asset in 2022.1.19f1:



    I also get these errors in the console: upload_2022-10-15_9-24-45.png
     
  8. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, there's currently a bug in Unity 2022 that makes _CameraDepthTexture_TexelSize report incorrect values. I've reported it to Unity and they've confirmed the bug, but haven't fixed it yet.
    Could you try it on your own machine:
    Debug.Log(Shader.GetGlobalVector("_CameraDepthTexture_TexelSize"));

    ^ Does that also report incorrect values for you? It should be (1/resolution.x, 1/resolution.y, resolution.x, resolution.y)
     
  9. bearcoree

    bearcoree

    Joined:
    Mar 8, 2016
    Posts:
    72
    upload_2022-10-16_9-51-25.png

    Looks like it's printing 1/x, 1/y, x, y to me

    I am having an issue where screenspace UV's are offset by around 5% though in other shaders.
     

    Attached Files:

  10. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Is 341, 192 the actual resolution of your game view though?
     
  11. bearcoree

    bearcoree

    Joined:
    Mar 8, 2016
    Posts:
    72
    I made it very small to get readable values, I am pretty sure that it's correct.
     
  12. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    On both of my separate MacBook m1 and my windows machines it reports wrong resolution values with URP template and Unity 2022.1.19f1. Do you print the value from the Update() function? The problem is, i'm not really sure if it's something on my end or not.
     
  13. bearcoree

    bearcoree

    Joined:
    Mar 8, 2016
    Posts:
    72
    Interesting. Now I get weird behavior as well. Before, it was updating to me resizing the window, not it's stuck at 103,103 resolution... I print in Update, yes.
     
  14. Nirvan

    Nirvan

    Joined:
    Nov 16, 2013
    Posts:
    134
    So the box shadow is just not working with point lights or it's a bug?
    Also is it ok idea to use multiple UAAS for multiple light sources?
    If I make some system to switch max 3 UAAS depending on what is happening on the scene it wouldn't be overkill/is it possible?
     
  15. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, yes the box shape does not generate shadows with point lights, it's a limitation.
    3 separate UASS would probably not be too bad in terms of performance.
     
    Nirvan likes this.
  16. neoludicgames

    neoludicgames

    Joined:
    Aug 30, 2022
    Posts:
    2
    Hi there, I just bought the asset and played around in URP with it. The shadows look amazing, and the performance is outstanding.

    Sadly I have noticed a small issue that makes this asset a little harder to use for me: I see massive frame drops in the demo scene (from ~400 to ~15 fps) every 2 seconds. This behavior is present in builds as well.

    upload_2022-11-23_23-40-0.png

    I am not sure if it is connected, but from time to time black horizontal lines will be visible on screen, and the shading will flicker slightly.


    Using Unity LTS 2021.3.8f1 LTS
    URP version 12.1.7
    Running on Windows DX11
    Using the default configuration and demo scene from the package.
     
  17. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, nice catch!
    From https://somasim.com/blog/2015/04/30/csharp-memory-and-performance-tips-for-unity/
    Calling Max with three arguments means invoking a variadic
    “ Mathf.Max(params int[] args) “, which then allocates 36 bytes on the heap

    Fixed it by replacing
    float MaxVector(Vector3 vec) { return Mathf.Max(vec.x, vec.y, vec.z); } 
    with
    float MaxVector(Vector3 vec) { return Mathf.Max(Mathf.Max(vec.x, vec.y), vec.z); }


    Also snagged some other low hanging fruit in terms of allocations. Now should be much less of them.
    I've submitted an update with these fixes, it should go live as soon as the asset store team approves it. Thank you.
     
    DragonCoder likes this.
  18. neoludicgames

    neoludicgames

    Joined:
    Aug 30, 2022
    Posts:
    2
    Thank you! Looking forward to the update :)
     
  19. Anisoft

    Anisoft

    Joined:
    Jul 5, 2013
    Posts:
    137
    Does this support forward + (aka the new tiled forward)

    Also does this have any plans to support urps deferred mode?
     
    Last edited: Dec 13, 2022
  20. Agoxandr

    Agoxandr

    Joined:
    Aug 16, 2014
    Posts:
    44
    It only supports 2020 and 2021 and I haven't been able to a make in 2022.
     
  21. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, some earlier versions of 2022 had a Unity bug that prevented the asset from working, but it should be fixed now in the latest 2022 versions. Just checked and the asset works properly on 2022.1.19f1, what version were you experiencing problems with?


    About Deferred URP - It unfortunately looks like it's not going to be possible to integrate this asset into it, there's just not a nice injection point provided by Unity. I tried injecting the shadows into albedo/occlusion/emission of the URP GBuffer, and none of it looks visually satisfactory due to the way those channels get processed by URP. The only way I can think of making it work would be to require URP Deferred users to copy their entire URP package and modify the GBuffer shading code deep inside URP itself, but that of-course would be too cumbersome for an out-of-the-box experience asset.
    And so unfortunately for now I must declare the asset only working on URP Forward, not URP Deferred.
     
    DragonCoder likes this.
  22. Setmaster

    Setmaster

    Joined:
    Sep 2, 2013
    Posts:
    239
    Does this have a manual? I would like to see the process of making a shader compatible with it.
     
  23. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    There's a well documented example shader, you basically just declare _UASSTexture and sample it with screen uv in your shader.
     
  24. FlightFight

    FlightFight

    Joined:
    May 29, 2017
    Posts:
    26
    Hello, I'm already using your SSCC solution and it looks great!
    How would I go about displaying these shadows on a Microsplat terrain?
     
  25. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, you will have to modify the Microsplat shaders in question to read from _UASSTexture with screenUV and apply the shadow signal, look inside the provided Lit shader for an example, it's basically just shadow = tex2D(_UASSTexture, screenUV).r;
     
    Last edited: Jan 6, 2023
    FlightFight likes this.
  26. FlightFight

    FlightFight

    Joined:
    May 29, 2017
    Posts:
    26
    Okay. Does it require adding a component to the shadow-casting GameObjects? Can it work without GameObjects entirely? I'm using GPUI and Entities Graphics in my project.
     
  27. Agoxandr

    Agoxandr

    Joined:
    Aug 16, 2014
    Posts:
    44
    I finally managed to write a version with 0 per frame GC allocations.
     
    hopeful and DragonCoder like this.
  28. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    If you want you can DM me your improvements, I'll see if I can add them to the asset for everyone.
     
    hopeful likes this.
  29. Agoxandr

    Agoxandr

    Joined:
    Aug 16, 2014
    Posts:
    44
    I just wrote you the updated scripts for URP, I think. Kinda confusing.
     
  30. FlynnyMac

    FlynnyMac

    Joined:
    Aug 24, 2020
    Posts:
    10
    Thanks for the asset. Seems to be impacted by the Vulkan issue:
    Crashed: Thread: SIGSEGV
    #00 pc 0x84e514 libGLES_mali.so

    Any update on that?
     
  31. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Replied to your email.
     
  32. Immu

    Immu

    Joined:
    Jun 18, 2013
    Posts:
    239
    Hello. I'm studying to eventually to buy the asset, I'm just wondering, does the 'shader changes required' for a shader to receive the shadows can be easily applied through via shader graph ? (via the code node function maybe ?) If so, is the package featuring an example of that ?
    Thanks for your time :)
     
  33. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, the shadergraph is unfortunately not powerful enough to /properly/ inject custom shadows for a shader (without reimplementing the entire shading code). In shadergraph the signal that you get from _UASSTexture is just between 0.0 for "this pixel is in some analytic shadow" and 1.0 for "this pixel is not in any analytic shadows". Injecting that 0-1 signal into blending properly into your shadergaph as shadows is the problem. If you have a stylized shader you can get away with just something like multiplying the final color by shadow+some ambient color to brighten them up a bit. The Lit+AnalyticShadows.shader included in the package has a modification to the actual BRDF code of Lit.shader, which is not something that's possible in shadergraph unfortunately.
     
    Immu likes this.
  34. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Submitted an update (1.1.3) that fixes a bug with UASS + Bloom sometimes producing bright pixels (fireflies). (Some pixels were NaN's). Should be live as soon as the asset store team approves it.
     
  35. ljc123456gogo

    ljc123456gogo

    Joined:
    Nov 26, 2014
    Posts:
    1
    I like this plugin, but I encountered a problem. If I change the render scale in the quality settings of Universal Render Pipeline Asset to anything other than 1, the shadows produce incorrect results. Could you please check into this issue? Thank you.
     
  36. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, this is due URP bugs such as this one. Please send me an email and i'll send you a modified version of the package that works with non 1.0 renderScale, but with the trade-off that it can sometimes glitch out in scene view.
     
  37. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Just submitted an update that should make the asset support URP 14+ (Unity 2022).
    Should be live as soon as the asset store team approves it. Thank you.
     
  38. Setmaster

    Setmaster

    Joined:
    Sep 2, 2013
    Posts:
    239
    Getting a shadow glitch similar to the other user. Latest version of the asset on unity urp.
     
  39. cfantauzzo

    cfantauzzo

    Joined:
    Apr 8, 2012
    Posts:
    75
    Hi! I purchased this and am overall impressed. Like other users here, I'm also experiencing some bad self shadowing artifacts (unity 2022 LTS, URP). I have to set the bias to extreme levels to reduce the artifacts. Is this normal behavior?

    Regardless. I was looking into using this for a VR project. I saw elsewhere here that VR is not officially supported, but I was curious to see how well the effect worked in VR, if at all, so I took a look at it in multi-pass mode in URP. For sure it's pretty broken. Are there any plans for VR support in the future? This would be an amazing thing to have in VR.
     
  40. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, please email me, i'll have a version of the asset for you to try that hopefully should fix this issue.

    Could you email me with some screenshots of the self shadowing artifacts you're experiencing?
     
  41. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Just submitted update 1.1.5:
    - Improved support for 2022 (that should hopefully fix all these issues people are having above).
    - URP non 1.0 render scale support.

    Should be live as soon as the asset store team approves it. Thank you.
     
    Lars-Steenhoff likes this.
  42. RastaGrzywa

    RastaGrzywa

    Joined:
    Jun 16, 2018
    Posts:
    12
    Hey,
    I've got the asset and must say it worked really great. I know it does not have an official support for mobile but I wanted to try it on oculus.
    Yesterday everything was perfectly fine. I've imported an asset, assigned proper scripts, made required setups. Looked good in Quest 2. Unfortunately today on opening Unity and trying to build new version I was greeted with an error:

    upload_2023-7-7_6-43-3.png

    I've tried like everything I can imagine:
    - Re-import assets
    - Update Unity version (2021 -> 2022)
    - Setting up project like yesterday (Removing assets, build, importing assets again)

    I'm using Built-in renderer.

    I wonder if you could possibly have any idea why it worked previously and now it won't let me use itself?

    What I found is that maybe it's because of some issue on Unity side and possible solution could be by replacing some lines in shader:
    upload_2023-7-7_6-47-10.png

    https://discussions.unity.com/t/ope...-post-fx-for-android-in-unity-2018-2/211488/2

    Code (Boo):
    1. Shader error in 'Hidden/UASS': undeclared identifier 'sampler_CameraDepthTexture' at line 327 (on vulkan)
    2.  
    3. Compiling Subshader: 0, Pass: , Vertex program with INDIRECT_ALGO STEREO_MULTIVIEW_ON
    4. Platform defines: SHADER_API_MOBILE UNITY_ASTC_NORMALMAP_ENCODING UNITY_ENABLE_REFLECTION_BUFFERS UNITY_HARDWARE_TIER1 UNITY_LIGHTMAP_FULL_HDR UNITY_NO_CUBEMAP_ARRAY UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_RGBM UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION
    5. Disabled keywords: SHADER_API_GLES30 UNITY_COLORSPACE_GAMMA UNITY_ENABLE_DETAIL_NORMALMAP UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF2 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_VIRTUAL_TEXTURING
    6.  
    7.  

    Code (Boo):
    1. Shader error in 'Hidden/UASS': undeclared identifier 'sampler_CameraDepthTexture' at line 466 (on vulkan)
    2.  
    3. Compiling Subshader: 0, Pass: , Vertex program with STEREO_MULTIVIEW_ON
    4. Platform defines: SHADER_API_MOBILE UNITY_ASTC_NORMALMAP_ENCODING UNITY_ENABLE_REFLECTION_BUFFERS UNITY_HARDWARE_TIER2 UNITY_LIGHTMAP_FULL_HDR UNITY_NO_CUBEMAP_ARRAY UNITY_NO_RGBM UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION
    5. Disabled keywords: SHADER_API_GLES30 UNITY_COLORSPACE_GAMMA UNITY_ENABLE_DETAIL_NORMALMAP UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_PBS_USE_BRDF1 UNITY_PBS_USE_BRDF3 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_VIRTUAL_TEXTURING
    6.  
     
    Last edited: Jul 7, 2023
  43. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, this is an issue most probably localized to Vulkan, so it's hard for me to test it, some people had issues on Vulkan before as well so i decided to remove official support for Vulkan.
    Nevertheless, I've submitted an update to the package that replaces the depth texture declarations with the macro (v1.1.6), it should be live as soon as the asset store team approves it. If you don't want to wait, replace the UASS.shader file with this one I included, let's see if this fixes the issue for you. I imagine it will only reveal some deeper issues with Vulkan. Please email me with your results (jollytheorygames at gmail.com) as i respond there faster. Thank you.
     

    Attached Files:

  44. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,450
    How to make it work with unity terrain?

    Thanks
     
  45. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Hi, a shader is going to have to be made, a copy of URP-Terrain-Lit with support for the effect. I'll write it some time later.

    Been battling this crazy food poisoning for the last 4 days so for now I'm kind of out of commission everyone.
     
    Lars-Steenhoff likes this.
  46. ununion

    ununion

    Joined:
    Dec 2, 2018
    Posts:
    268
    orth need.
     
  47. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    Here's the shader, put it in the "URP Lit Shader" folder.
    Will update the asset soon to include it out of the box.
     

    Attached Files:

    Lars-Steenhoff likes this.
  48. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,450
    Thats great, thanks, will try it out
     
  49. SHTien

    SHTien

    Joined:
    Jul 2, 2023
    Posts:
    1
    It was in the previous question, but I can't check the answer, so I'm asking you a separate question

    1. Are only shadows in the form of spheres, capsules, and boxes supported?
    2. How do I make the shadow of a human figure appear like the demo?
     
  50. JollyTheory

    JollyTheory

    Joined:
    Dec 30, 2018
    Posts:
    134
    1. Yes
    2. The human figures in all the demos were made by fitting capsules to the bones of the character, much like when you're setting up a ragdoll. The same effect is used in Counter Strike 2, Unreal Engine, etc.