Search Unity

uGui fonts in linear color space

Discussion in 'UGUI & TextMesh Pro' started by IcyHammer, May 30, 2015.

  1. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    Has anyone else tried to render fonts when linear color space is enabled? I noticed that rendering is totally wrong. White text on black background looks like it is bold, and black text on white background is barely visible. I was using dynamic font, tried different sizes etc, and just can't get the same look as in Gamma color space. Does anyone have any idea what to do?
     
    zitemzs likes this.
  2. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    After days of debugging, I still haven't found a fix for the issue :S
     
  3. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Maybe posting comparison pictures might help to get someone to post a guess on the problem.
     
  4. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    Ok, so here is the comparison, made in fresh unity 5 project. Left side is rendered with Linear and right with Gamma pipeline. You can clearly notice that Linear color space is not working properly. On black background font is too thick and on white it's too thin, so black actually becomes gray.

    Comparison.png
     
    Last edited: Jun 7, 2015
  5. TechCor

    TechCor

    Joined:
    Apr 3, 2015
    Posts:
    56
    I'm also having this issue. It's a very subtle difference, and so might be easily overlooked by someone not doing a direct comparison.

    The text looks less crisp in linear space and makes the shadows on the text in my UI less pronounced as well. I assume it has something to do with the anti aliasing.

    EDIT:
    Searching google, all I can find are your posts on the subject with no responses. No one else seems to notice or care about this issue. I think we're screwed, buddy.
     
    Last edited: Jul 31, 2015
  6. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    Well I hope someone will see this issue sooner or later.
    I also created an Issue: http://issuetracker.unity3d.com/iss...changes-the-text-and-it-is-not-shown-properly

    But it seems that almost no one cares / notices this issue. I saw it the very moment when I enabled linear color space and It's really bothering me. Black text on bright background is barely visible and the hue is not correct. I've been trying to fix it with the shader, but I just couldn't make it work for all colors.
     
  7. TechCor

    TechCor

    Joined:
    Apr 3, 2015
    Posts:
    56
    I can confirm that the problem is due to the alpha blending of the font's anti-aliasing. I don't think Unity considers the change in how blending works to be a bug.

    I've managed to settle for good enough with changing the fragment shader, but this seems like a silly hack to revert the UI back to gamma space. It would be nice if they would enable an option to pick the color space per camera/canvas.

    I've been using the below in the UI-DefaultFont shader, and for other blended UI elements.
    Code (csharp):
    1. col.a = pow(col.a + 0.055, 2.2) / 1.13711896582;
     
  8. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    I already tried something similar, and also tried your solution but this doesn't fix the whole problem. This only fixes the case when you are drawing bright font on a dark background. If you try your solution with rendering black font on a white background it gets even worse. So this is definitely not a solution.
     
  9. RV1

    RV1

    Joined:
    Nov 18, 2012
    Posts:
    68
    I'm not sure there is a fix for this. The issue is that alpha blending intentionally behaves differently in linear color space.

    My ideal solution is for Unity to introduce some flexibilty with their color space. For example, force the UI to render in gamma color space. The immediate mode GUI always renders in gamma color space, so surely it must be possible?

    I really need someone from Unity to comment on this. I'm stuck in a position where I really want to switch to linear color space for my game, but my UI uses a lot of alpha blending and I don't know how to get it looking the way I want.
     
  10. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    If you find the solution, please let me know.
     
  11. Loadus

    Loadus

    Joined:
    Nov 5, 2012
    Posts:
    15
    Actually, the linear space font rendering is correct and the gamma space rendering is wrong (the font's alpha texture has gamma correction applied to it so the antialiasing suffers). This of course is a matter of taste on which one you prefer.
     
  12. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi I just responded to this bug, this is what I said:

     
  13. RV1

    RV1

    Joined:
    Nov 18, 2012
    Posts:
    68
    Hi,

    Thank you for replying to this thread. I have some follow up questions:

    1. Despite the complexity involved, are there any future plans to add support for switching color spaces at runtime? Specifically will it ever be likely that there will be a feature implemented lets us render the just the UI in gamma when using linear.

    2. Given that fonts look different and there are no options to tweak or control them to account for linear, can you suggest any other viable solutions aside from tweaking the font shader?

    Thanks!
     
    TechCor likes this.
  14. TechCor

    TechCor

    Joined:
    Apr 3, 2015
    Posts:
    56
    I am also curious about RV1's questions.

    I'm well aware that blending is different in linear space. However, fonts are handled by Unity. The font's antialiasing is of worse quality in Linear. It seems like Unity should have "Gamma" and "Linear" font import settings. Perhaps autodetected.

    In any case, Unity's built-in font system should look better when using Unity's "advanced" features, not worse.

    At the very least, it should not degrade in quality.
     
    firstuser likes this.
  15. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    So, this issue still persist and it is year 2018. @Tim-C has there been any progress on this issue? From the way I see it all we would need is to render UI in gamma space or at least option to do that. It seems really strange there is actually still no solution to this problem in Unity.
     
    firstuser likes this.
  16. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    2019 and we still can't properly render fonts when using linear color space, is really no one from unity interested in fixing this?
     
    firstuser likes this.
  17. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Just letting everyone know that I am reading these posts and aware of this behavior. I will take a look at this once the next release of TMP is available.
     
    firstuser and IcyHammer like this.
  18. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    Thanks for finally looking at this, also know that this isn't just a TMP issue but also with Unity UI. If I can help you with anything, please let me know :)
     
  19. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    Here is also the comparison, when I tried to solve the issue with shaders and nothing worked. Comparison.png
     
  20. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    @Stephan_B anything new regarding this issue?
     
  21. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
  22. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I am aware of the difference between the two color spaces.

    I need to figure out the best way to handle this.
     
    firstuser and karl_jones like this.
  23. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    Cool, please let me know if you manage to find any workaround.
     
  24. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    I haven't specifically tested this with font rendering, but I've got a solution which is "working" for gamma-space UI assets on a linear-space scene render with all colours blending correctly.

    @rainini posted a package in this thread which implements a discussed solution of:
    1. Convert the linear-rendered scene to gamma space.
    2. Render your GUI with a separate camera, and all of the assets' sRGB settings disabled.
    3. Convert the results back to linear space.

    I did tweak the package, but just to use Unity's provided conversion functions rather than approximated powers.

    I have "working" in quote marks because this requires two post processes which I feel really should be redundant. I believe I read somewhere that the old IMGUI was rendered after the backbuffer was already converted to gamma space. If that's true then the ideal solution would surely be to have that as an option for UI cameras? This would perhaps fix the font rendering issues mentioned here, while also allowing GUI assets to be shared between linear and gamma space projects.
     
  25. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    Unforetunately this won't work with fonts due to font antialiasing which is the main problem here.
     
  26. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    Sorry for the necro, but the problem is still present and I don't think there's a great solution out there. There's no doubt that lighting is a ton better in linear colorspace. However, trying to get the UI artists to work in linear color is a pretty tough ask. However, the biggest place where we feel the pain is on our fonts.

    @Stephan_B I recognize that this is a difficult problem since the entire UI is rendering/blending assuming linear color, but the biggest problem in us trying to use a linear color space (which our lighting artists really want) is TextMesh Pro rendering so much thinner than gamma. Are there any improvements in the pipe to the TMP shaders to support linear color better or have there been any talks about rendering the UI in gamma colorspace?
     
    Garrettec and angrypenguin like this.
  27. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    I suspect it really has to be done on the UI side rather than with individual components within it. But in any case, I agree that this is something that should be handled by our tools, once for everyone, rather than by making every dev team individually work around it (in inefficient ways).
     
    Noxury and firstuser like this.
  28. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    Just converted my project to linear and stumbled into the issue of all my semi-transparent sprites becoming even more transparent. Holy S***, how is there still no solution to this issue?
     
    firstuser and Garrettec like this.
  29. IcyHammer

    IcyHammer

    Joined:
    Dec 2, 2013
    Posts:
    71
    Garrettec and firstuser like this.
  30. firstuser

    firstuser

    Joined:
    May 5, 2016
    Posts:
    147
    Shameless necro bump cause this REALLY sucks. What can we do to get Unity's attention?

    Sprite/font handling in linear space shouldn't require workaround shaders etc
     
  31. carbon_studios

    carbon_studios

    Joined:
    Jun 14, 2020
    Posts:
    8
    Garrettec, firstuser and angrypenguin like this.
  32. LavieA

    LavieA

    Joined:
    Apr 25, 2017
    Posts:
    4
    A year later, have you figured out the best way to handle this?
     
  33. Personuo

    Personuo

    Joined:
    Mar 19, 2014
    Posts:
    129
    no one to slove this.
     
    timbo_unity and Garrettec like this.
  34. SevenPointRed

    SevenPointRed

    Joined:
    Feb 3, 2016
    Posts:
    218
    This is still an issue :(
     
  35. Garrettec

    Garrettec

    Joined:
    Nov 26, 2012
    Posts:
    98
    Because no-one cares, BIG announcements - that is what important for Unity management, after announcement happened, no-one cares. Time to move on. Save your nerves, just switch the engine.