Shadows not casting with LWRP Lit Shader (Transparent Surface)

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.

1 Like

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 :confused:

3 Likes

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?

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 :slight_smile:

I was asking for URP, so i don’t care about LWRP :wink:
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?

1 Like

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:

material.SetShaderPassEnabled("ShadowCaster", false);

to:

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.

5 Likes

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

Unity :wink: 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

1 Like

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.

thank you so much i cant belive that it the f*k problem still existed in unity URP2020

Any update on this?

also existed even in 2021 LTS!

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:

[ToggleUI] _CastShadows("Cast Shadows", Float) = 1.0
10 Likes

IT WORKED FOR ME THANK U THANK U!!!

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?

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.

LOLL why is this such an easy remedy? Huge thanks!

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!

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.

9490606--1335799--Snipaste_2023-11-24_14-19-38.png

What changes should ı do in here for make out, thanks