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

Shadows not casting with LWRP Lit Shader (Transparent Surface)

Discussion in 'Universal Render Pipeline' started by DirectK, Oct 13, 2019.

  1. DirectK

    DirectK

    Joined:
    Sep 7, 2019
    Posts:
    2
    Hi! I am trying to create a fade out effect on objects by periodically reducing the alpha channel of the material which works fine except casting shadows. My project is configured with LWRP (default settings) and I'm using the LWRP Lit Shader for the objects I am trying t fade out. When I use the surface type as Transparent, the shadows seem to stop casting on other objects. The Opaque surface type lets the shadows be cast from a directional light, although the fading effect wouldn't work anymore. On the forum, a solution implies using the Cutoff surface type instead of the Transparent one, though LWRP doesn't seem to offer this setting. Is this a limitation of the LWRP or am I missing a Light/Shader setting? Thanks.
     
    tillmonkthered likes this.
  2. doarp

    doarp

    Joined:
    Sep 24, 2019
    Posts:
    147
    Having the same issue.
    Would love to hear suggestions.

    Edit: I found a nasty work around.
    You can create two identical meshes, where the 2nd one has an Opaque material, and in the MeshRenderer settings, under "Cast Shadows" select "Shadows Only", so you have one object rendering the mesh, and the other rendering only the shadow.
    It works :/
     
    Last edited: Nov 8, 2019
  3. LeFx_Tom

    LeFx_Tom

    Joined:
    Jan 18, 2013
    Posts:
    88
    Having the same issue in 2019.3.2 with URP 7.2.1
    Is it really intended, that Lit-Transparent objects don't cast shadows at all, no matter their alpha-value?
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Transparency with shadows is only supported in Universal Pipeline. I believe that you'll be able to upgrade without too much pain (LWRP is in support and effectively dead anyway).

    Note: this is for receiving shadows. For casting, you can create a cast pass in a custom forward renderer via the UI.

    I honestly hope I'm not mistaken, so please check up :)
     
  5. LeFx_Tom

    LeFx_Tom

    Joined:
    Jan 18, 2013
    Posts:
    88
    I was asking for URP, so i don't care about LWRP ;)
    Thanks for the hint to look into cast passes...
    I checked that out, but some sort of documentation would be helpful. Anywhere where i could read more about that?
     
    soorya696 likes this.
  6. DirectK

    DirectK

    Joined:
    Sep 7, 2019
    Posts:
    2
    I have just updated to the last version of Unity (2019.3.7f1) and upgraded to URP (7.1.8). However, the shadow caster still does not work on transparent materials.

    Is there any chance you could expand on the cast pass in a custom forward renderer approach? I have tried creating a Custom Renderer Texture and applied to the transparent material and tested with all Shader Pass options, but with no result. If you could point me to the specific UI that allows the transparent material to cast shadows, that'd be great, however, I doubt is that simple. I kept messing up with the URP Shaders to combine ForwardLit behaviour with the ShadowCaster, but I couldn't get around that. My experience with shaders is based on an uni class I took 2 years ago, soo... If I manage to do that I probably need to figure out how to make the shadow strength change according to the alpha channel, but that's a totally different problem. :))

    Thank you in advance for your help. Really appreciate it.

    EDIT: Just found a workaround to the problem. Seems like by default, the ShadowCaster shader is disabled when you enable Transparent behaviour to a material. I managed to change that through the UIElement class in Packages/Universal RP/Editor/ShaderGUI/BaseShaderGUI.cs under
    SetupMaterialBlendMode method changed the line 479:
    Code (CSharp):
    1. material.SetShaderPassEnabled("ShadowCaster", false);
    to:
    Code (CSharp):
    1. material.SetShaderPassEnabled("ShadowCaster", true);
    I have no idea if this change brakes anything, but seems to work for now. However, the shadows do not change the strength according to the material alpha.
     
    Last edited: Apr 2, 2020
  7. warpfx

    warpfx

    Joined:
    Feb 10, 2020
    Posts:
    14
    Yes, this is currently the only way to enable shadow casting by (semi)transparent objects. I am working with the recent UWP and see the same code (URP 7.3.1) when ShadowCaster is simply disabled by BaseShaderGui.cs. I thought that was recently resolved in 7.3.0 or 7.2.0 but it wasn't
     
  8. jacoblaerdal

    jacoblaerdal

    Joined:
    Jun 12, 2017
    Posts:
    4
    Unity ;) Is this something you change or? I am using Unity 2019.4.1f1

    I mean for video production you could make a checkbox to set this to true.."if needed" so the code would change like below

    upload_2020-6-24_9-3-8.png
     
    eliteforcevn likes this.
  9. dukenukem4d

    dukenukem4d

    Joined:
    Jul 30, 2019
    Posts:
    14
    I am getting the same problem, I've just updated from LWRP to URP. It works to use the "SetShaderPassEnabled" "ShadowCaster", but the shadows does render the whole faces not considering the transparencies.
     
  10. eliteforcevn

    eliteforcevn

    Joined:
    Oct 25, 2018
    Posts:
    47
    thank you so much i cant belive that it the f*k problem still existed in unity URP2020
     
  11. FerGarD

    FerGarD

    Joined:
    Aug 15, 2018
    Posts:
    1
    Any update on this?
     
  12. pseudocolor

    pseudocolor

    Joined:
    Dec 15, 2019
    Posts:
    4
    also existed even in 2021 LTS!
     
  13. AlexGone

    AlexGone

    Joined:
    Feb 11, 2022
    Posts:
    5
    As long as Unity doesent want to add this checkbox.
    Just copy the shader from the URP package (Packages >> Universal RP >> Shaders), for example SimpleLit.
    Choose a different name maybe.
    Add this line of code:
    Code (CSharp):
    1. [ToggleUI] _CastShadows("Cast Shadows", Float) = 1.0
     
  14. pedreteGG

    pedreteGG

    Joined:
    Sep 26, 2021
    Posts:
    1
    IT WORKED FOR ME THANK U THANK U!!!!!
     
  15. Yonderboy

    Yonderboy

    Joined:
    Nov 19, 2014
    Posts:
    102
    do you know if its possible to make the shadows share the overall transparency? eg. If a texture is set to fade in, the shadow would also fade in?
     
  16. Erebar

    Erebar

    Joined:
    Oct 20, 2014
    Posts:
    11
    I'm using Unity 2021.2.19f1 with URP 12.1.6
    I've just noticed this issue. I'm using a lit shader and I don't get shadows when the material surface type is Transparent. Is this intended to be this way? Or is it some bug? If it's intended the fix posted here could add instability and I don't want that.
     
  17. Mister_Iwa

    Mister_Iwa

    Joined:
    Jul 27, 2021
    Posts:
    9
    LOLL why is this such an easy remedy? Huge thanks!
     
  18. DSFelton

    DSFelton

    Joined:
    May 19, 2013
    Posts:
    4
    Just found this tip a year-plus later, and it works like a charm in a Unity 2022.3.9f1 3D URP project. Many thanks!
     
  19. Cenly

    Cenly

    Joined:
    May 30, 2022
    Posts:
    16
    Hihihi!!!!! I find the principle!!!!! I study shaderGUI today, and all the keywords and pass enable control are in "BaseSahderGUI.cs", here's the associated segment!!

    If _CastShadows property can't be found, it enable/disable shadowCaster pass by surface type(opaque or transparent)!

    That's shocked me and I'm so excited to find out that.
     

    Attached Files: