Search Unity

How to rotate normal map?

Discussion in 'Scripting' started by alussam, Jul 24, 2018.

  1. alussam

    alussam

    Joined:
    May 13, 2018
    Posts:
    15
    Hello! I try to rotate normal map for terrain by using getPixe and setPixel functions. With texture this works ok, but with normal map some trouble. Resulting texture not looking as normal map and Ive got no idea why. Texture for splatmap looks allright, but normal map dont work properly. Instead of blue color it looks red. Thanks for any help.

    public Texture2D RotateTexture2d(Texture2D tex)
    {
    Texture2D tex1 = new Texture2D(tex.width, tex.height);
    int wid = tex.width; int height = tex.height;

    tex1.Resize(height, wid);
    for (int a = 0; a < wid; a++)
    {
    for (int b = 0; b < height; b++)
    {
    Color color = tex1.GetPixel(a, b);
    tex1.SetPixel(b, a, color);
    }
    }
    }
     
  2. alussam

    alussam

    Joined:
    May 13, 2018
    Posts:
    15
    Thats a self answer, beacuse no others. Ok, we can rotate picture and than use use texture importer class.