[LWRP/URP] Can I make a fully transparent object cast shadows as if it's fully opaque?

I want to use dissolve shader for a see-through-walls effect. However, I don’t want the shadows to dissolve, I want them to remain the way they were as if the object was fully opaque. Is there a way to do it?

Create a local copy of “Lit.shader” and “ShadowCasterPass.hlsl”. Call them “LitSolidShadow.shader” and “SolidShadowCasterPass.hlsl” or whatever you’d like. Then in the base shader switch:

#include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"

to

#include "../SolidShadowCasterPass.hlsl"

In “SolidShadowCasterPass.hlsl” simply remove the line:

Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);

Then your shadows will always be solid regardless of your alpha settings for the lit pass.

Alternatively, you could write a custom Alpha() function to ignore your dissolve settings but include other sources of alpha.

Thanks for the quick reply. I want those changes to be used by shaders made with URP Graph. Is there an entry point where I can put this new Lit/ShadowPass shader so that URP uses it instead of the current one?

In that case, the simplest way is to use a local copy of the URP package and modify the shadowcasting shader file directly.

In theory, it may be be possible to create your own master node and get it to use your own custom shader code to avoid making changes to the URP code, but that isn’t something I’ve done before and I don’t use shadergraph much.

Not working for me. I followed all the steps. Any idea?
I’m using URP 7.2.1

you can create an exactly same object with an opaque material and make it child of original transparent one, and then choose “shadows only” in its mesh renderer component in lighting section for “cast shadows” property, and also disable shadows for transparent one.

2 Likes

There is no such option anymore in URP 12 to choose “cast shadows only”

I was going to say the same idea, duplicate the object and make one “shadows only”
The option is there. URP 12

1 Like