Search Unity

Normal Difference in Editor and Mobile Build

Discussion in 'General Graphics' started by Blastom, Dec 8, 2017.

  1. Blastom

    Blastom

    Joined:
    Aug 13, 2013
    Posts:
    24
    TL DR: Do anyone knows the formula Unity is using to convert the color of a texture, who's set as normal map.

    I've encounter a problem on Unity 5.4.1f1 that the same normal map acts differently on Editor and on mobile.
    And after a bit of experiements, I've spotted the cause of the problem and found a solution. The normal map can be fixed by import the texture, set it as normal type and then screenshot the texture preview in editor and replace the original one with it.

    -- On Editor, the left one was with my fixed normal map; the right one with the original normal;


    -- On Mobile, the left one with fixed normal; the right one with the original normal.


    But doing something like screenshoting, removing edge wasn't something for productation. So I want to implement an Editor script to fix all the normal maps.
    The problem is that I cannot figure out the formula of the convertion process.
    From my tests, the source is all about the red channel and green channel - I've messed up with the blue channel and got the same result.
    Also, I've tried the DTX5 unpack formula, which provided perfect results on most the pixels. But some of the pixels had the values of all rgb changed during the conversion, which is not simply normalized.

    So do anyone help me on the exactly formula of normal convertion in unity?
     
  2. Blastom

    Blastom

    Joined:
    Aug 13, 2013
    Posts:
    24
    Never mind. My old code accurately worked perfectly... Some glitch on operations happened yesterday, I think.

    The correct formula is to unpack the normal color as DTX5 with red and green channels, normalize the result and then repack it into rgb.
     
    theANMATOR2b likes this.