Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using this soft mask with text mesh pro in unity 2023 makes the text blocky like the shader dosen't work #163

Open
TheEye2108 opened this issue Feb 1, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@TheEye2108
Copy link

As the title seas it seems to not work properly or did i miss a step i just imported the extra text mesh pro assets? Any help is appreciated.

@TheEye2108 TheEye2108 added the bug Something isn't working label Feb 1, 2024
@AgainJBC
Copy link

AgainJBC commented Mar 16, 2024

Seems to happen for >TextMeshPro/Distance Field< sharder .... the blocky appearance is fixed when I switch to >TextMeshPro/Mobile/Distance Field< but there still is some artifact looking like underline on each letter

Edit: Just found out that changing Vertical Mapping for the TextMeshPro component to "line" or "paragraph" seem to fix the problem.

Edit 2: No ... after further usage I found there are still some issues with the fonts looking differently or completely buggy in most scenarios :(

@karyol
Copy link

karyol commented Apr 8, 2024

I managed to fix it by copying the default Distance Field shader from TMP and making minor adjustments.
First changed the shader name to Hidden/TextMeshPro/Distance Field (SoftMaskable).
Second change is in Pass. Edit pragmas and includes like this:

#pragma target 3.0
#pragma vertex VertShader
#pragma fragment PixShader
#pragma shader_feature __ BEVEL_ON
#pragma shader_feature __ UNDERLAY_ON UNDERLAY_INNER
#pragma shader_feature __ GLOW_ON

#pragma multi_compile __ UNITY_UI_CLIP_RECT
#pragma multi_compile __ UNITY_UI_ALPHACLIP

#include "UnityCG.cginc"
#include "UnityUI.cginc"
#if UNITY_VERSION < 201910
  #include "Assets/TextMesh Pro/Resources/Shaders/TMPro_Properties.cginc"
  #include "Assets/TextMesh Pro/Resources/Shaders/TMPro.cginc"
#else
  #include "Assets/TextMesh Pro/Shaders/TMPro_Properties.cginc"
  #include "Assets/TextMesh Pro/Shaders/TMPro.cginc"
#endif

#include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc"
#pragma shader_feature __ SOFTMASK_EDITOR

With softmask editor included you can add softmask to your text but you need to know the world position and there comes the third change.
Add float4 worldPosition : TEXCOORD6; to struct pixel_t.
Then you need to add world position from input to output output.worldPosition = input.position; in VertShader just before returning the output.
And finally you can add the softmask into PixShader just before returning faceColor faceColor *= SoftMask(input.position, input.worldPosition);.
It works for soft masking the TMPro texts for me but i still do not managed to make it work for TMP inline sprites.

@TheEye2108
Copy link
Author

I managed to make it work with unities built in soft mask but then we had to downgrade to unity 2022 and there we had other problems so we just scraped the soft mask part and just went with the hard mask ore just mask :D.
But ty for posting this i will try and implement it for testing.

@SeanNi1221
Copy link

Make sure the TextMeshPro Support package is imported into your Asset folder as stated in
https://github.com/mob-sakai/SoftMaskForUGUI?tab=readme-ov-file#usage-with-textmeshpro
I think the author @mob-sakai maded it a bit misleading putting the resources under a folder called "Samples".

@akpil
Copy link

akpil commented May 22, 2024

Make sure the TextMeshPro Support package is imported into your Asset folder as stated in https://github.com/mob-sakai/SoftMaskForUGUI?tab=readme-ov-file#usage-with-textmeshpro I think the author @mob-sakai maded it a bit misleading putting the resources under a folder called "Samples".

I am experiencing the same issue as described in this thread, and I have definitely installed the package you mentioned. (If it isn't installed, it appears in magenta.) However, even after installation, the color that was magenta just shows up as a black (or the color of the font) rectangle. In the 2023 version, the same issue occurs no matter how I bake the font asset, whereas in version 2022.3.x, everything works perfectly with the same settings. Therefore, the method you suggested does not solve the problem.

@mob-sakai
Copy link
Owner

Sorry for my late reply.

The TextMeshPro shader does not work correctly in the following environments due to updates:

  • Unity 2023.2 and Unity 6 (TextMeshPro is built into uGUI)
  • TextMeshPro v3.2.0-pre and v4.0.0-pre

As a workaround, please try the following:

  • If you have already imported the TextMeshPro Support sample, delete the folder.
  • Extract the following zip file into the Assets folder:
  • Add the shaders to Project Settings > Shader Settings > Always Included Shaders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants