Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

2D Text not reacting to URP light sources?

Discussion in 'UGUI & TextMesh Pro' started by IsDarKsly, Jun 6, 2022.

  1. IsDarKsly

    IsDarKsly

    Joined:
    Mar 15, 2020
    Posts:
    6
    I've been trying to manage a little UI System. I have the URP installed so I can add some fancy lighting to my 2D UI system (The entire game is essentially a UI system). The lighting with URP doesn't seem to affect TMP text objects.

    Even after following this thread - https://forum.unity.com/threads/plans-for-hdrp-compatibility-for-tmp.660598/page-3#post-7463915

    I was able to obtain specific URP shaders for TMP objects, but the objects still wont be affected by any 2D URP lights. I have tried:

    -Tweaking the Shader settings in the editor
    -Changing the Canvas to occupy World Space
    -Making my own custom Material (Bad Idea)

    I've been caught on this for quite a few days, am I missing something? I've attached example of what I am dealing with.
     

    Attached Files:

    • tmp.png
      tmp.png
      File size:
      236.7 KB
      Views:
      322
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    To use TMP with SRP, you will need to make sure you are using the latest release of the TMP package which is version 3.2.0-pre.3 for Unity 2020.3 or newer.

    You will also need re-import the TMP Essential Resources which contain the updated SRP shaders. To re-import the TMP Essential Resources, go to "Window - TextMeshPro - Import ..." menu.

    Once the TMP Essential Resources have been updated, you will see new shaders available which includes both URP and HDRP sets of shaders including Unlit and Lit shaders.
     
    IsDarKsly likes this.
  3. IsDarKsly

    IsDarKsly

    Joined:
    Mar 15, 2020
    Posts:
    6
    Thanks for the quick reply! Unfortunately my 2020.3.32f1 version of Unity only allows me to have TMP Version 3.0.6. It will not allow me to update it. I'm going to upgrade the project to 2021.3.4f1 to see if that allows me to update it from the package manager.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Version 3.2.0-pre.3 is a preview release. You will need to enable show preview packages in Package Manager in order to see it but you will most certainly be able to use it in 2020.3 or newer versions of Unity.
     
    IsDarKsly likes this.
  5. IsDarKsly

    IsDarKsly

    Joined:
    Mar 15, 2020
    Posts:
    6
    I have [Enable Pre-release Packages] Turned on, and I can see other items in the Unity Registry marked with the yellow Pre label. However there is still only TMP 3.0.6 marked with the Release sticker. There aren't any indicators pointing me to the preview release. I am rather confused, I'm even using the guide at:
    https://docs.unity3d.com/Packages/com.unity.textmeshpro@3.2/manual/index.html
    Apologies for the inconvenience, normally I'd find a Youtube tutorial, but most people seem to be using 3.0.6

    [UPDATE] : It appears that Unity Version 2021 never actually shows the pre release package for TMP 3.2.0. I downgraded back to 2020.3.32 and found that after uninstalling TMP the reinstall allows you to "See other versions". Currently fixing all the bugs from the downgrade

    [UPDATE 2] : Unfortunately It did not work, I installed the pre release and re-Imported but the Text is still unresponsive to URP 2D Lights.
     

    Attached Files:

    • tmp2.png
      tmp2.png
      File size:
      224.4 KB
      Views:
      220
    Last edited: Jun 7, 2022
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Make sure that you are using one of the newer shaders which in this case would be the SDF URP Lit shader as seen below.

    upload_2022-6-7_1-21-54.png
     
  7. IsDarKsly

    IsDarKsly

    Joined:
    Mar 15, 2020
    Posts:
    6
    Again, thanks for helping me out with this. Here is an attachment with what I'm seeing right now. I have TMP 3.2.0-pre.3 And the Shader SDF URP LIT is applied. The only distinction I can make is the base material for your text is SDF - URP LIT. Could this be the cause? If so, I can't seem to find that specific material in the TMP Folders.
     

    Attached Files:

    • tmp3.png
      tmp3.png
      File size:
      261.2 KB
      Views:
      261
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    You should definitely be using the SDF URP LIT shader on your text object.

    Any reason you are using a <TextMeshProUGUI> component that works with the Canvas as opposed to the normal <TextMeshPro> component that works with the MeshRenderer?

    Getting lighting to work correctly with the Canvas can be challenging even when using WorldSpace render mode.

    I just tested with version 3.2.0-pre.3 with the above shader with normal <TextMeshPro> component and this works as expect as seen below.

    upload_2022-6-7_15-52-53.png
     
    IsDarKsly likes this.
  9. IsDarKsly

    IsDarKsly

    Joined:
    Mar 15, 2020
    Posts:
    6
    I tried your suggestion and used the non UI Text mesh pro alongside the normal TextMeshPro (MeshRenderer).
    Both with the correct shader on. Neither reacting to the 2D lighting system. Here's another file of what I see.
    (I'd still want to use the UI Components in any case as the project is mostly 2D UI)
     

    Attached Files:

    • tmp4.png
      tmp4.png
      File size:
      353.2 KB
      Views:
      231
  10. IsDarKsly

    IsDarKsly

    Joined:
    Mar 15, 2020
    Posts:
    6
    To those of you wondering, I found an answer (Although it wasn't the one I was hoping for). TMP does not seem to work with the 2D URP lighting system. By switching back to the base URP lighting system (Which doesn't work as efficiently for 2D projects) I found that the TMP objects, specifically the ones with mesh rendering components, work just fine.

    Unfortunately I don't have a workaround right now, I'll keep messing around with things until I find a solution. Here's an attachment of what it looks like without the 2D Renderer on, The TMP is now responsive to the light, at the cost of not having the canvas light itself correctly. Rip
     

    Attached Files:

    • tmp5.png
      tmp5.png
      File size:
      239.5 KB
      Views:
      259
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Good find. I'll take a look as soon as possible to try to figure out why the 2D Light don't work as expected.
     
    IsDarKsly likes this.
  12. Endlesser

    Endlesser

    Joined:
    Nov 11, 2015
    Posts:
    90
    Last edited: Jun 27, 2022
  13. Metamor

    Metamor

    Joined:
    Mar 7, 2018
    Posts:
    1
    I encountered this problem in my 2D project a while back. I eventually decided to use the Universal Renderer over the 2D Renderer.

    Before the switch, however, I was able to come up with a workaround for this problem. What I did was open up the "TMP_SDF-URP Lit" shader graph and change the material in the graph inspector from Lit to Sprite Lit.

    If you want to keep the original Lit shader graph intact, you can duplicate the file, make the new changes in it, and rename it to something like "TMP_SDF-URP Sprite Lit".

    I didn't do much experimenting so I can't guarantee if you'll encounter any new errors down the road. Hopefully this fixes your problem in the short term until an official bug fix is released.
     
    xaldin-76, nikomine and ThomasMcGrath like this.
  14. cunibon

    cunibon

    Joined:
    May 6, 2020
    Posts:
    7
    Anything new on the 2D lightning problem?
     
  15. kbm

    kbm

    Joined:
    Aug 7, 2014
    Posts:
    84
    Oh my god, dude. You saved me! Thanks so so much for this.. it's so dumb, really.
    Please, Unity developer Stephan_B, if you're still working at Unity: Fix this! It's 2 minutes work, just copy-paste the URP Lit shader and set the Material to "Sprite Lit" instead of "Lit". This just cost me 2 hours of research. Jesus.
     
    ThomasMcGrath likes this.
  16. JulianNeil

    JulianNeil

    Joined:
    Jun 27, 2022
    Posts:
    115
    Hi there. Thanks for the info @Metamor. Can someone from Unity please indicate whether using the "Sprite Lit" material is the preferred way to workaround (or fix) this problem? I'm not finding any bug report that matches this problem in the unity issue tracker.
     
    ThomasMcGrath likes this.
  17. ThisllDo

    ThisllDo

    Joined:
    Jun 8, 2015
    Posts:
    1
    Ty, saved me a lot of headache.
     
  18. xaldin-76

    xaldin-76

    Joined:
    Oct 1, 2016
    Posts:
    25
    This seems to work nicely, although the text vertex colors needs some rework, as some colors got darker and almost black..
     
  19. onlyJucyBlue

    onlyJucyBlue

    Joined:
    Feb 7, 2023
    Posts:
    2
    THANK YOU!