Search Unity

Resolved Image are brighter in game compared to the source

Discussion in 'Scripting' started by EFLFE, Feb 2, 2023.

  1. EFLFE

    EFLFE

    Joined:
    Dec 27, 2018
    Posts:
    3
    I load a png from StreamingAssets, but the image are brighter in game compared to the source

    Code (CSharp):
    1. var tex2d = new Texture2D(2, 2, TextureFormat.RGBA32, false, true);
    2. var bytes = File.ReadAllBytes(path);
    3. if (!tex2d.LoadImage(bytes)) {
    4.     return null;
    5. }
    6. var sprite = Sprite.Create(tex2d, new Rect(0, 0, tex2d.width, tex2d.height), Vector2.zero, 100);
    7.  
    Unity 2021.3.15f1


     
    Last edited: Feb 7, 2023
  2. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    There are many things that could cause this..

    The first ones that come to mind are:
    - Are you using a lit shader?
    - Which Color Space are you using? (Linear/Gamma)
    - Compression settings?
     
  3. EFLFE

    EFLFE

    Joined:
    Dec 27, 2018
    Posts:
    3
    I used default ui material (Image canvas) and I can't configure the picture from unity. Where can this be?
     
  4. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    Ah, my bad. Compression Settings wouldn't be available if you're loading from disk.
    Color Space would be under Player Settings. Try both Linear & Gamma I guess..
    You could also try different TextureFormat's.
     
  5. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
  6. EFLFE

    EFLFE

    Joined:
    Dec 27, 2018
    Posts:
    3
    Different TextureFormat's and converting the color profile did not give any results. But changing the legacy PNG and the linear argument to false helped. Thanks!
     
    ThermalFusion and SF_FrankvHoof like this.