Search Unity

How to do pixel font dropshadows with TextMesh Pro?

Discussion in 'UGUI & TextMesh Pro' started by MattRix, Jan 23, 2020.

  1. MattRix

    MattRix

    Joined:
    Aug 23, 2011
    Posts:
    121
    I want a 1px dropshadow under my text with TMP. I'm wondering if there's some built-in "correct" way to approach this. I can't use SDF fonts because (at least in my experience) they don't work correctly with pixel fonts. I imagine the best approach is to create a custom atlas image, but extracting and modifying the generated atlas is a pain, and the quads it generates aren't big enough for the shadow to fit (at least not by default). Another approach would be a custom shader, but that won't work correctly either because of the aforementioned quads-too-small issue.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This is not currently possible but functionality that we are planning on adding to the TMP shaders where it will be possible to choose between relative mode and pixel mode for those values.
     
    Eater_Games likes this.
  3. MattRix

    MattRix

    Joined:
    Aug 23, 2011
    Posts:
    121
    Is there any easy/recommended way to replace a TMP atlas with a custom one? (ex. one where I've manually added the shadows in Photoshop). Ideally I'd like to generate the TMP atlas so that the quads have enough room for the shadows too.
     
  4. MattRix

    MattRix

    Joined:
    Aug 23, 2011
    Posts:
    121
    For the curious, I was able to come up with a solution. I created a font atlas with 2px padding, exported the atlas (click the settings gear in the top right corner of the font data) and put a shadow on it in photoshop. Then I assigned that texture to the debug part of of the material, and set the material's padding to 2.

    Later, I also came up with an alternative solution involving creating a custom font shader that I can use to put a dropshadow on any font, which has a small impact on performance, but requires less work per-font.
     
  5. dericatienza

    dericatienza

    Joined:
    Feb 18, 2019
    Posts:
    2
    How did you import the atlas back? I did the same but the shadows just simply take the color of the text and does not retain its original color when I edited it which is black. So it turns out looking like this:

    upload_2021-8-1_11-46-9.png