Search Unity

Bug Shadows alpha clipping doesn't work in build

Discussion in 'High Definition Render Pipeline' started by karol2555, Dec 14, 2022.

  1. karol2555

    karol2555

    Joined:
    Jun 19, 2015
    Posts:
    4
    Can someone confirm if it is a bug. ( Submitted report if so IN-25757)

    Alpha clipped meshes have bugged shadows in builds only on unity 2022.2. I tried changing all settings possible with no success. On other hand issue doesn't appear in unity 2021.3.

    You can also see flickering between correct clipped shadow and non clipped when moving camera around.

    It works perfectly in the editor but doesn't in the build. Replicated in empty project on different unity versions.

    Unity Editor 2021.3 and Build

    upload_2022-12-14_10-38-7.png

    Unity Editor 2022.2 and Build

    upload_2022-12-14_10-39-37.png
     
    waken and GM_O like this.
  2. GM_O

    GM_O

    Joined:
    Apr 30, 2021
    Posts:
    7
    Just now I encountered the same problem. I am using Unity 2022.2.19 with HDRP 14.0.7.

    In the editor the alpha clipped shadows (of an HDRP/Lit material) look correct, whereas in the built player they are unclipped:

    Editor.png Correct, alpha-clipped shadows in editor.

    Player.png Wrong, unclipped shadows in player.

    Has this bug been confirmed? How can I find it in the issue tracker? If needed, I could provide more details.
     
  3. karol2555

    karol2555

    Joined:
    Jun 19, 2015
    Posts:
    4
  4. GM_O

    GM_O

    Joined:
    Apr 30, 2021
    Posts:
    7
    Indeed, it does not occur in 2023.1.0b16 for me too.

    Though I hope that it will either get fixed in 2022.2 soon, or that there exists at least a workaround, because I cannot imagine that most HDRP projects can do without any alpha-clipped shadows.
     
    Last edited: May 16, 2023
  5. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    324
    Yip I get this too - 2022.2.12 + HDRP.
     
  6. Amplify_David

    Amplify_David

    Joined:
    Mar 29, 2023
    Posts:
    191
    i see something similar before in URP.
    in that case if the Light Atlas Resolution was too low it breaks clipping in the shadows

    give it a try
     
  7. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    324
    A bit more info - probably not useful, but who knows:

    We have 3 different tree types and some bushes in the scene that I'm testing.
    As stated before, the shadows render correctly in editor view and in play mode in the editor (game view).

    The interesting new piece of information that I have, is that in the build, it is only one of the tree types that cause the bad shadows. The other trees and the bushes are fine.

    Also - the bad shadows (ignored clipping) are not consistent. It flickers to and from correct rendering based on slightly different camera positions.

    Now regarding the "bad tree" - I have failed to find any differences between this tree and the others, regarding the shader, mesh renderer settings, texture import settings, etc. Although it is a different material with different textures, it is still the same shader used by all the other trees (a Lit shader graph).
     
    GM_O likes this.
  8. GM_O

    GM_O

    Joined:
    Apr 30, 2021
    Posts:
    7
    After a little experimentation, I found a workaround, though please check whether it also works for you:

    My tree model that suffers from the bug is made of a single mesh, but it uses two different materials: One for the trunk vertices and another for the leaf vertices.

    I have found that the bug seems to occur only if both materials are using the same shader, but exactly one of the two materials has alpha clipping enabled. So the workaround is to either assign different shaders to the two materials, or to enable alpha clipping on both materials.

    My guess is that this also applies to situations where your model uses even more than two materials, but I do not know for sure.

    By the way, this workaround also fixes the camera-position-dependent flickering you mentioned.
     
  9. ebaender

    ebaender

    Joined:
    Oct 29, 2020
    Posts:
    97
    This does not just affect meshes that use two different materials, the leaves on this fern are just a single mesh with just the leaf material and the shadows still ignore the alpha clipping.

    49ec00e1914c49b178e2b742722f7c3d5313d055.jpeg

    Is there seriously no fix planned for the 2022 LTS? That's what the issue tracker says, so I guess anybody using the extremely niche feature of vegetation can scrap their project now if it in any way depends on 2022 features or suck up these crap shadows. My bad for assuming basic features like shadows would be supported in an LTS release, silly me.

    Does anybody have more ideas for a workaround? I already tried increasing the shadow atlas size for punctual lights as far as it will go, to no effect.
     
    Last edited: Aug 6, 2023
  10. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    324
    I have no work-around currently - but it somehow only affects a particular tree out of the 10 or so tree/bush variations we have. Once I know what the difference is (if any), I might be able to post a work-around.
     
    ebaender likes this.
  11. Amplify_David

    Amplify_David

    Joined:
    Mar 29, 2023
    Posts:
    191
    Looks like transmission mask, could be something to look closer at.
    when Unity first added transmission mask, we found the internal Unity default in unity core without any data for transmission mask sort of looked like that
     
  12. Amplify_David

    Amplify_David

    Joined:
    Mar 29, 2023
    Posts:
    191

    suggest check the vertex tangents.
     
  13. ebaender

    ebaender

    Joined:
    Oct 29, 2020
    Posts:
    97
    @Amplify_David @mgeorgedeveloper

    Thanks for the help you two, I really appreciate it!

    Screenshot 2023-08-06 203649.png

    I tried using a transmission mask on the material, made no difference unfortunately. What did make a difference was separating the leaf mesh into its own fbx though, suddenly the alpha clipping works. I don't understand why though, I haven't changed the mesh in any way and used the exact same export settings in blender and the same import settings in unity as I did for the larger fbx which the leaves were a part of.
     
    mgeorgedeveloper likes this.
  14. ebaender

    ebaender

    Joined:
    Oct 29, 2020
    Posts:
    97
    Okay I did a stupid amount of testing and finally found the culprit. I missed one option on the model import settings, that being lightmap UV generation. Any model that has that turned on will not work with alpha clipping, even if no lightmaps are baked or the mesh renderer in question is set to receive GI from light probes.

    My take on this is that there is a design oversight in the HDRP lit shader that uses the second UV channel in some way for alpha clipping, even if that channel is occupied by lightmap UVs. This is not even the first time I encountered something like this, very similar problem with detail normal maps on the fabric shader, but there you can manually fix it since you have access to the UV mask.
     
    Last edited: Aug 6, 2023
    mgeorgedeveloper likes this.
  15. Amplify_David

    Amplify_David

    Joined:
    Mar 29, 2023
    Posts:
    191

    HDRP uses two UVs
    UV1 = static lightmaps unity_LightmapST
    UV2 = dynamic lightmaps unity_DynamicLightmapST
     
  16. ebaender

    ebaender

    Joined:
    Oct 29, 2020
    Posts:
    97
    Yes I'm aware of that, I wasn't quite clear with the naming. I meant UV1 when I said second UV channel, UV0 being the first one. I'm not using realtime GI so I'm not sure if UV2 also has an effect on it.
     
  17. impheris

    impheris

    Joined:
    Dec 30, 2009
    Posts:
    1,661
    is it looking good now? can we see it?
     
  18. ebaender

    ebaender

    Joined:
    Oct 29, 2020
    Posts:
    97
    The left shadow is what it looks like, this screenshot is taken from the build.
    I'm afraid it's not as simple as I thought yesterday, the behavior is abhorrently inconsistent. I did manage to get my fern casting alpha clipped shadows in the build, and that stopped being the case after I enabled lightmap UV generation on the isolated fern model. So I thought that was the cause, but disabling lightmap generation on the model after that did not get them working again, it looks like that model is permanently broken after that. Even undoing the change in version control and re-exporting it from blender made no difference, and creating a new file with just the leaves only works sometimes. It seems to be essentially random whether an exported model will work with alpha clipping, the only guarantee is that it definitely will not work if there is more than a single mesh at the root of the model.
     
    Last edited: Aug 7, 2023
  19. ebaender

    ebaender

    Joined:
    Oct 29, 2020
    Posts:
    97
    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.
     
  20. Wintermute-

    Wintermute-

    Joined:
    Sep 5, 2017
    Posts:
    56
    I was able to find what was causing this in my project using 2022.3.4f1. Problem appears to occur with objects that have materials with alpha clipping and static batching on. A work around is to disable static batching on these objects, provided it doesn't affect your project's performance. I will try a 2023 version to see if this still happens.
     
    ebaender likes this.
  21. ebaender

    ebaender

    Joined:
    Oct 29, 2020
    Posts:
    97
    Thanks for your input, I hadn't thought of disabling static batching yet. For most project's that's absolutely not an option though, that will cause a massive increase in draw calls that will send your CPU usage straight through the roof. There really is no hope for alpha clipping in 2022, there just is no good workaround and the devs have made it very clear that they are not going to fix this in their "LTS" release.

    I moved to 2023 and can report that this specific issue is fixed, but there is another one that affects alpha clipped mesh renderers in LOD groups in the same way, which sucks because you really need LODs for foliage.

    I reported it a few weeks ago and it actually got taken serious this time, I would encourage anyone who needs alpha clipping to vote on the issue: https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-48819
     
    ChainTechDev likes this.
  22. algaevkostr

    algaevkostr

    Joined:
    Jun 29, 2021
    Posts:
    1
    I'm not sure if I have exact this issue or something different, but at least looks similar.
    My alpha clipping is not just ignored, it somehow related to two-sided shadows of any other mesh.
    Like, I created two boxes using ProBuilder, deleted half of the faces of one of them and enabled double-sided shadow caster for it. And now, depending on camera angle, each of it's backfaces could cast normal shadow or shadow in form of my foliage material, which is not applied to that box. And exactly the same happens for objects with foliage material.
    Would really like to get fix of this on 22 LTS, newest version mentions too much issues so won't try :c
     
    ebaender likes this.
  23. dghsiba

    dghsiba

    Joined:
    Feb 8, 2019
    Posts:
    2