Shadows ignore material alpha clipping in build only

As you can see in the left image taken from play mode, the shadow looks accurate given the transparent portions of the fern leaf material. The image on the right was taken from a build of the exact same scene with no changes made to the scene, and now the shadow acts as if the whole material was opaque.

Why is this happening and how can I fix it? I’m using 2022.3.5f1 and the HDRP if that helps.


we are aware of this issue for 22.3 version. And as you mention is it indeed fix on 2023 version. However we aren’t refusing to backport the fix, we have currently no idea what fixed it :(, or rather we don’t understand what it isn’t working in 22.3

This is under investigation and we will update the tracker when we found.
When something differ between runtime version and editor version it is always related to a shader variant issues. i.e a shader variant isn’t emmbed in the runtime.
This explain why your workaround with LitTesselation is worksing, because it is a different variant.

As of today we don’t have workaround to provide but we will actively work on the issue after Unite.

I found this thread on the forum where some other developers were sharing their experience with this, looks like this is a tracked issue that is fixed in recent 2023 versions, but the Unity devs refuse to backport the fix to the 2022 LTS.

Judging by the forum post this issue can be caused by a multitude of obscure things like the shadow atlas size being too low, having two materials on the same mesh where one has alpha clipping on and the other doesn’t, having no transmission mask on a material with subsurface scattering enabled, or problems with the vertex tangents of the mesh.

In my case it was none of those things though, and instead a simple case of having lightmap UVs on my mesh. Whether you authored them yourself or use the autogenerated ones from the model importer, this will cause alpha clipping to break without fail. This is kind of a massive design oversight considering lightmaps are essential for most projects.

But if you backed yourself into a corner by relying on features of the 2022 LTS like I have and can’t go back to the last real LTS, you’re going to have to compromise by not only switching all mesh renderers that need alpha clipping to receive GI from light probes, but you also need to separate all of those meshes into their own files if you’re using the autogenerated lightmap UVs.

The other alternative would be to use the lit tessellation shader since that does not suffer from this problem, but that is probably not a scalable solution since the manual page for that says even with a tessellation factor of 0 that will still come with a significant GPU performance cost. It does not make it very clear if that also applies when tessellation mode is set to none, so it might be worth experimenting with if you don’t feel like ripping apart all your models into tiny chunks or going through the pain of manually authoring lightmaps UVs.

I did some more testing on this, looks like the advice in my last reply is not generally applicable. The issue is definitely related to lightmaps UVs in some way, but it’s not as simple as I thought. Sometimes exporting a mesh that needs alpha clipping separately and not generating lightmap UVs in the importer will fix the problem, sometimes it won’t, and sometimes it will appear to fix it but only when the camera is positioned and rotated in a specific way.

The only reliable workaround is the aforementioned use of the Lit Tessellation shader. I still have some reservations about scalability, but after some experimentation I can report no significant increase in GPU frametime by using it with a tessellation of factor of 1. Your mileage may vary depending on the target hardware though, I tested this only on a high end desktop GPU. If someone has a mobile project that’s affected by the issue I would be interested in hearing how well that works there.

If you’re going to try this make sure that tessellation mode is not set to none which it is by default for me, otherwise the lit tessellation shader will behave exactly like the standard lit shader.

Does anyone have more ideas for a workaround? This is killing my project.

Lit Tessellation has tons of problems and is not scalable if you have lots of foliage, also does not support LOD animated crossfading at all which looks horrible.