Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Text Mesh pro with default fog

Discussion in 'Scripting' started by Muhammad_Taha, Dec 1, 2021.

  1. Muhammad_Taha

    Muhammad_Taha

    Joined:
    Jun 21, 2015
    Posts:
    22
    I don't know what to do, I tried many solution to hide text mesh pro in the fog in URP. Anyone has any idea?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I don't have a solution for using default fog, but I would suggest trying out a volumetric fog instead.
     
  3. onurkiris05

    onurkiris05

    Joined:
    Feb 11, 2022
    Posts:
    1
    Same issue here. Is there any solution about it ?
     
    Unifikation likes this.
  4. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    Bump:

    Builtin, TextMeshPro, Unity Fog. TMP ignored by fog.
     
  5. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,070
    Sounds like a feature-omission to me. If you need it really badly, you can file a feature request, write a variant of the shader that does play with the built-in fog (this could be hard or impossible), or move on to volumetric fog.

    I personally wouldn't try making a new shader, but I would do some research first. Maybe it's just missing #pragma multi_compile_fog (I doubt it, but it's worth checking out).

    Here's someone who tried this, but used the Fog keyword instead, and that didn't work. I'm not even sure what's legacy and what's not legacy at this point.
     
  6. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    Personally, by the time I'm writing about something here, I've exhausted what google, bing, chatGPT, stack overflow and GitHub have provided.

    As to volumetric fog, why do you think that would be any different?

    Socially, how do you think a fail like this has existed for the life of TMP? I ask, because if it's been a problem for the life of TMP, and there's every indication that it has, and TMP has been abandoned, now do you think a feature request is going to go?
     
  7. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    In the shader, it's Queued to pass as Transparent. This is a problem, because it's AFTER everything else, including Fog.

    Setting it to Geometry is part one of solving the problem. I'm testing other settins to see if I can get it to work with Fog, which the shader has turned off.

    There's probably some issues with the ways Z is not handled, too:

    upload_2023-6-25_20-37-9.jpeg
     
  8. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,070
    The way it works is completely different. It's worth trying if this is early in the project. It's also a better and more customizable solution than the default fog which uses camera depth. I'm not completely versed in this, so it could be that it's HDRP-only or maybe you need an asset, who knows. In URP you can fake a volumetric fog with particles. (Edit: and because you said TMP was rendered as Transparent, a particle fog or a post-processing fog should work perfectly with it.)

    TMP is not abandoned. They're reconsolidating it into UIElements (and will be called TextCore if I get this right), the legacy text will be abandoned. As it should be.

    TMP really has no substitutes. You shocked me with the statement, and I had to double check.

    There are two reasons why I think a feature request would work: 1) People don't readily scream about this and it's relatively rare that someone needs this. Now it could be because it's easily fixed, or nobody really uses the default fog, I don't know. 2) If it's something that is easily fixed / introduced as a feature, that will likely happen, and if not, perhaps you'll get a workaround recommendation.

    Another potential solution would be to ask on UGUI & TextMesh Pro forum. Stephan_B still works for Unity and was active there in March of this year. Though I'm not saying that you should address him specifically, as far as I can tell, he was relocated to another project.
     
    Last edited: Jun 25, 2023
    tsukimi likes this.
  9. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,070
    Ok that's why then. Have you tried changing to opaque?
    Edit: Though I'm not sure about this, fog should work with transparent objects as well.
    Try with a cube with transparent shader, see what happens.
     
    Last edited: Jun 25, 2023
  10. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    The queues are "orders" of what happens. Things that are transparent go last.

    So there's no certainty that anything like volumetric fog will render over the top of it, nor particles, as there's also an index (or queue) within each queue.

    Somewhere in the Geometry queue is where TMP needs to be, based on a user's ordering of things, such that it's still visible in ways that they want. Otherwise it can disappear behind things that are behind it, as illogical as that sounds, because of z issues AND the nature of render queuing.

    I'm using Builtin, by the way, so have more options with regards this kind of thing than either HDRP or URP, which are both problematic with transparencies. Half baked, at best.

    TMP, as a technology and approach to UI rendering, is over, at Unity. They're all in on their nonsensical adoption of web technologies. The rolling of some TMP functionality into what is currently a tangential part of UI Toolkit/Builder via TextCore is one of their few concessions to the fact that their new approach isn't nearly as good as it needs to be.

    Stephan, from TMP, has moved onto a management role in Unity. It's in maintenance mode, or the equivalent of that.

    Like you, I'm saddened by this, as TMP was part way to being an amazing approach to rendering UI elements and text, and I quite like the constraints and mechanisms of the Canvas approach.
     
  11. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    Also, anyone that's happy with the default Unity fog, and organised their effects and cameras in accordance with it, is not going to be wanting to change their fog rendering technique (and therefore much else) just to get TMP to respond accordingly to fog.
     
  12. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,061
    Traditional fog in Unity is not an effect or an object that gets rendered separately, it's calculated in each shader and added to the object's fragment color. So all shaders need to explicitly include the necessary calculations or they won't be affected by fog. Transparency or rendering queues don't affect this (generally, a fog that doesn't support transparent objects would be pretty useless).

    Looks like the TMP shaders all don't support fog. You have to modify them to include the fog calculations in the fragment and pixel shaders, Unity provides macros to help with this. The modification isn't too difficult but requires some knowledge of shaders, I'd take the most basic standard shader with fog support and copy over the fog-related parts to the TMP shader you're using.

    The Fog keyword is for very old fixed-function shaders only, nobody uses them anymore.

    Modern fog can works differently and more like its own object or as a dedicated effect. I don't know how the different types of fog work in HDRP but it could be that they don't require all shaders to be modified anymore.
     
    Ryiah, Unifikation and orionsyndrome like this.
  13. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,070
    Yes there is, because the shaders for it are also transparent, so they belong to the same queue and you can always offset the fog to come later. It's not a special rendering feature, like default fog kind of is.

    I have mixed feelings about this. It's not nearly as half-baked as you might think. This is poorly communicated, however, but once you get your hands on it, it's drastically different and some things do not have to be supported like they were in the built-in. Some things actually work from the ground up, and are enabled by design. And many others are actually programmable, which wasn't the case with the built-in. I was actually pleasantly surprised with URP when I finally tried to probe it a little.

    But it's not. The technology is the same, it's still the best approach when it comes to rendering fonts (and by extension text) via GPU.

    And yes they are bundling it with something that resembles web tech, BUT! Hear me out, I have a deep Flash background, and ok many people didn't like that tech in general, but Macromedia's and Adobe's approach to how UI was formulated technically was the most beautiful system ever.

    It was a very rich retained-GUI event propagation system, and the whole stack naturally moved from web integration (Flash player) to desktop/mobile standalones (AIR). Obviously it aimed to solve a similar problem space as Microsoft Silverlight, choosing to split complex designs into design/behavior dualities with XML-like CSS-like underframes (Flex). In fact, Silverlight stole a lot of neat ideas, Microsoft being Microsoft.

    And so they decided to use XAML instead of MXML, and this is why Unity borrows from XAML to do the same thing. It's literally because C++ guys are probably MS fanboys. In other words, I know exactly why they chose to do this, and what they're hoping to achieve, and they're literally 15 years late to the party. In my view, my workflow has severely devolved once I moved to Unity. Immediate mode GUI is and was so incredibly passé for anything past 2010.

    And once you start using UGUI, yes it solves so many problems, and is retained and better performing, but soon enough you discover that modifications are expensive, that you need a junior to make shallow controllers, tackle the parameters and that designers do not want to touch it.

    Actually I entered Unity prior to UGUI asset being released as a 3rd party (I believe it was called nGui), and had to roll a full-on GUI solution for the studio where I was working at the time. What I rolled was a responsive tech (with anchors and that stuff) but also nearly fully programmatic. I have literally 20+ years of experience with UI systems, but nobody cares about me, my knowledge, or my experience, and that's why we can't have nice things. If it wasn't for Apple (which ironically killed Flash who pioneered the slick buttery experience; not to mention realtime-rendered vector graphics and animation) we'd still be clicking on dithered 32x32 icons made from a predefined 16-color palette. But now I'm entering the rant mode.

    Edit: I concur with Adrian above, I tried to convey the same message, don't know if it came across. Default fog != volumetric fog.
     
    Last edited: Jun 25, 2023
    spiney199 likes this.
  14. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    Could be. That's the take away from volumetrics in HDRP. It could work, it might sometimes work, and other updates it might not. And there's nobody making a great set of volumetrics based light effects as a 3rd party for HDRP or URP because of the nonsense that's going on with these constant changes.

    They started life as templates to demonstrate the benefits of a Scriptable Render Pipeline approach, and have become ends unto themselves. And problems of all manner and kind, as one claim after another leads to ever more adoption of these premature approaches to the usages of an unfinished integration of SRP with DOTS.

    etc.

    TMP has stalled. It's not getting any further features. It's over for it. Yes, it's unchanging, now. But that's not a good thing. It wasn't yet finished. The documentation still isn't, either.

    Again, I'll ask... why should someone happy with what they're getting from default fog go to all the troubles required to try volumetric fog approaches just to get diegetic usages of TMP to correctly render within fog?

    This is, to my mind, just another example of things in Unity that just don't work. Out of the box.

    I'm so used to this, and then foraging around to find out how it should have been done, that I know it will be easier to get the TMP object to play nice with default fog than to try move everything to accepting a new type of fog, and there's no way I'm trying to move this project to URP.

    I try URP with each major update. And find ever more interesting things that don't work, aren't done or hobble performance. It might work for some projects. Not for me.

    And if I had to use HDRP I'd just go to Unreal.
     
  15. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    THANK YOU!!!

    Will give this a go and post any successes here for others to crimp from.
     
  16. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    This turns out to be truly ridiculous:

    1. That it wasn't done already
    2. Now that TMP's abandoned, won't ever be done
    3. Means learning to try follow/find Macros, of Shaders of CG... etc.

    No fun at all.

    Half baked, like most of Unity's features.
     
  17. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,070
    @Unifikation
    Check out the shaders I've shared here (for an unrelated problem), because they look like they implement the fog you're after. Maybe you can copy paste this to TMP shader.

    Specifically
    #pragma multi_compile_fog
    and then all functions mentioning FOG written in caps.
    I'm not claiming it works, these are older shaders from the Standard Assets that were pulled off for some reason, but might be worth trying.
     
  18. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,079
    Will do, thank you!

    Have been dissecting the Standard Particle Unlit and how it handles fog, because it does it quite well, and is claimed to be a very light shader.

    It's going to take a while for me to get any results, as I have actual development and design to do that I can do, and know how to do, and this... which is in the "uncertain if I can, or if it will work" pile of ideas for later consideration and experimentation.

    A pile that keeps getting ever bigger.
     
  19. GiantLightStudios

    GiantLightStudios

    Joined:
    Jul 24, 2019
    Posts:
    9
    Just switching the shader on the text material to TextMeshPro/Distance Field (Surface) seems to do the trick for me:
    upload_2023-7-19_10-40-28.png
     
    LeviTaylor and bananadev_ like this.
  20. LeviTaylor

    LeviTaylor

    Joined:
    Mar 18, 2024
    Posts:
    1
    I just figured it out:
    - Select the 3D Object called "Text - TextMeshPro"
    - Select it, then scroll down in the Inspector just under "Extra Settings"
    - Where it says "Shader," select the drop down.
    - Then select "TextMeshPro"
    - Then select "Distance Field (Surface)"

    Hope this works for you too!

    **EDIT**
    I just now saw that the person above me said the same thing