mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
1.91k stars 257 forks source link

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

Closed TheEye2108 closed 12 hours ago

TheEye2108 commented 5 months ago

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.

AgainJBC commented 4 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 1 month ago

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 commented 1 month ago

Sorry for my late reply.

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

As a workaround, please try the following:

mob-sakai commented 12 hours ago

Please try v2: https://github.com/mob-sakai/SoftMaskForUGUI/releases/tag/v2.0.0