Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity terrain looks like a shiny rock in URP mobile

Discussion in '2022.1 Beta' started by creat327, Apr 12, 2022.

  1. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Hi

    I don't think people at Unity noticed this bug that is going on for months already. The Unity terrain on mobile (android and ios) has smoothness ignored and is completely off the charts. It's been reported in the forums multiple times and I even modified the default shader myself to fix it (just set the smoothness float to 0). But I download even the new alpha version and the bug is still there.

    Reading the URP shader it seems that it's getting the smoothness value from the Alpha of the texture. That's why if you use ASTC compression, the terrain looks horrible, but if you switch to RGB24 (no alpha) the bug seems to be gone. (Not really, and you lose all compression on mobile using that format). It doesn't matter that your texture has no alpha whatsoever, if you set it to ASTC, the shader will ignore your smoothness value and set it to 1 (highest value) because your alpha in the texture is 1 obviously. This bugs ONLY happens if you switch to iOS or Android. It seems that it works in a standalone.

    Please fix the shader.
    Here is one of the several threads I´ve found about this
    Glossy - Shiny terrain after updating V2020.3.26 to 2021.2.15 - Unity Forum

    Additionally, you should just replace or add a new shader and remove most of the Lit or Simple Lit stuff. Terrains usually don't need specular highlights, roughness, smoothness or whatever you want to call it. If you do, it's expensive. Which kills mobile performance. And most of us do not need it.

    Internally if you add the default URP Terrain shader it loads so much junk is crazy on mobile. Load the memory profiler and find that the terrain is loading about 4 shaders, including URP Lit (not even simple lit) and it takes over 140 mb of RAM just with the shaders and nothing else.

    You should have a simple lighting terrain shader in URP, but at the bare minimum, fix the current bug on the existing shader.
     
    Last edited: Apr 12, 2022
  2. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    55
    Thanks for the notes about this issue! Would you mind submitting a bug report about it? Looks like the similar issue in the thread you linked was resolved, but we still have something else to look into.
     
  3. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Ok, i've submitted it as case 1419939
     
    LeonhardP and mattb-unity like this.
  4. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    55
    Thank you very much!
     
  5. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    To summarize:
    1) For a quick fix on the Terrain shader, when the texture has no alpha even if compression is set to ASTC, smoothness should be zero on mobile, not 1.
    2) For a better fix, please take a look at the URP Terrain shader. It's loading URP Lit and a bunch other shaders behind the scene taking over 140mb in a mobile device just on shaders. URP Terrain should at maximum load URP Simple Lit, not Lit. And I honestly think it should be drastically trimmed for mobile because a terrain usually does not need most of the PBR lighting on a mobile device, and neither can afford 140mb on shaders for a single terrain inclusion. To give you an idea of the craziness, my 4kmx4km terrain with 4 textures takes about 1/5 of the RAM of that single URP Terrain shader.
     
    Last edited: Apr 14, 2022
    gotiobg, tmonestudio and Ruslank100 like this.
  6. gotiobg

    gotiobg

    Joined:
    May 10, 2017
    Posts:
    19
    I'm having this issue also. After switching from ETC to ASTC almost every texture in the scene became glossy. Will be reverting back to ETC for the time being.
     
  7. TG1980

    TG1980

    Joined:
    Oct 23, 2013
    Posts:
    40
    "Performance by default"
     
    nehvaleem and creat327 like this.
  8. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    James_Arndt and gotiobg like this.
  9. CrAzYpotpie

    CrAzYpotpie

    Joined:
    Sep 24, 2020
    Posts:
    11
    As someone that just recently switched to the latest stable (final) version of Unity (2022.1.1f1,) switched to ASTC compression for the textures, and also built my VR game into a standalone .apk for Quest 2, I also experienced this same exact issue a couple of days ago. The funny and strange thing is, I hadn't poked too much into it yet to discover that this was the case, and I only found this thread when searching google for "unity terrain unlit shader urp," as I just tried to make a custom terrain material in my URP project to be unlit, noticing that Unity only has a single terrain shader, which is lit.

    Hope a fix for this can be pushed out fairly quickly.

    I also apologize if this seems like a useless bump. I didn't intend that at all, but after posting I feel as if it is superflous, albeit relevant.
     
    Last edited: Jun 10, 2022
    yosefstudios and mattb-unity like this.
  10. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    55
    I have been looking into this bug and it turns out that what is happening is that the shininess is controlled by the alpha channel if the diffuse texture on the terrain layer has an alpha channel. So if you switch from ETC to ASTC, Unity is by default giving the ASTC version an alpha channel value of 1.0f. The way the code is now, when shininess is set by the alpha channel, then the value of the shininess slider is ignored.

    A possible fix could be just a toggle in the Inspector "override shininess with alpha" so you can enable/disable.
     
    yosefstudios and CrAzYpotpie like this.
  11. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    I suggested that myself on the bug report @mattb-unity to ignore the alpha channel. Also in settings if you disable alpha in the texture it shouldn't think opaque = shinny. Aside from that, why would you want shininess in a terrain for most cases? Lastly, why do you use URP Lit under the hood for terrains in mobile instead of URP Simple Lit? Heck, why do you even use another shader for terrain because it's loading a ton of crap shaders into ram for a cell phone just by including a simple terrain in your game. You should have a much simpler shader for mobile devices.
     
  12. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    55
    Are you talking about the texture import settings?

    I don't have an answer about the shader right now unfortunately.
     
  13. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,756
    Yes, the import texture settings. You have a Alpha Source, and Alpha Is Transparency there. Setting it to ignore transparency should not make it shiny in the terrain.
    But I guess the most user-friendly option would be to have the option in the terrain texture settings itself of "ignore alpha" or "ignore shininess" or whatever you want to call it. Otherwise, we are stuck with ETC compression and we can't use ASTC compression.
     
    Alvarden, CrAzYpotpie and mattb-unity like this.
  14. scosso

    scosso

    Joined:
    Dec 14, 2015
    Posts:
    1
  15. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    55
    In 2023.1 I've added an option in the layer "Smoothness Source" so if your texture has an alpha channel, you can choose to have smoothness sourced from a constant, or from the alpha channel of the texture.
     
    gotiobg likes this.
  16. gotiobg

    gotiobg

    Joined:
    May 10, 2017
    Posts:
    19
    Thanks a lot, Matt! I'll be waiting for the LTS in a couple of months.
     
    mattb-unity likes this.
  17. r2620

    r2620

    Joined:
    Jul 22, 2021
    Posts:
    2
    Thanks for fixing this issue in Unity 2023.

    I'm on 2021.3.21 and needed a fix. Simply setting Alpha Source to "None" in the texture import settings didn't fix the issue for me.

    The only solution I found out to work was the following:
    - Re-export your texture as a png image WITH an alpha channel that contains full transparency (if you do it with the gimp make sure to check the png export option "Save color values from transparent pixels")
    - In Unity set Alpha Source to "Input Texture Alpha" and leave "alpha is transparency" unchecked.

    And voilà, no more horrendous glossy terrains. What a relief.
     
    mattb-unity and gotiobg like this.
  18. yosefstudios

    yosefstudios

    Joined:
    May 8, 2015
    Posts:
    129
    So, no fix for pre-2023 versions?
     
    M_R_M likes this.
  19. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    55
    Yeah this approach works well. For textures without an alpha channel, Unity will give it an alpha channel (if you select an RGBA texture format) that is fully opaque -- which is an unfortunate thing for how this terrain layer stuff works.
     
    GCSVR likes this.
  20. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    55
    No, sorry. This fix added data to the serialized format of the terrain layer so it can "remember" your alpha channel settings. We generally don't want to backport changes to formats like that.
     
  21. Fargamer

    Fargamer

    Joined:
    Oct 14, 2013
    Posts:
    9
    This worked for me in Unity 2021.3.0f1. An even easier way... go to the texture and in the inspector, set Format to RGB 16 bit or 24 bit. Click Apply, no more shininess.
     
    Last edited: Jun 28, 2023
    mattb-unity and M_R_M like this.
  22. M_R_M

    M_R_M

    Joined:
    Jan 31, 2019
    Posts:
    26
    Thanks, Fargamer, this did it for me too.
     
  23. Nightmare34

    Nightmare34

    Joined:
    Oct 3, 2020
    Posts:
    7
    I used RGB Compressed ETC2 4bits (keep compression) and shininess is gone too. Thanks guys :)
     
  24. sevdigim1451

    sevdigim1451

    Joined:
    May 2, 2020
    Posts:
    42
    That solved my issue! Thanks! İn Build Settings>Player Settings>Other Settings>Texture Compression Format>ETC2 I added the path for who encounter the same problem!
     
    a872401892 and HayalOrtak like this.