Search Unity

Assign normal maps at runtime

Discussion in 'Shaders' started by GodOfMagic, Sep 19, 2017.

  1. GodOfMagic

    GodOfMagic

    Joined:
    Mar 25, 2014
    Posts:
    34
    Hello everyone,

    In my program I need to be able to import textures at runtime and set them as normal maps. When downloading image at runtime it is not possible to mark it as normal map so Unity doesn't understand what to do with it.

    In Unity 5.6 with lots of time spent in google I managed to change a few lines in Standart shader to make it work, but now after upgrading to Unity 2017 something changed and it throws error in that line. And original Unity Shader seems to have been changed a bit in that line too:

    In Unity 5.6 it was something like this:
    _BumpMap("Normal Map", 2D) = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap)) - 1; {}
    and I changed it to:
    _BumpMap("Normal Map", 2D) = normalize(tex2D(_BumpMap, IN.uv_BumpMap)*2-1);
    And in Unity 2017 that line looks like:
    _BumpMap("Normal Map", 2D) = "bump" {}

    Also I'm totaly new to shaders and it was almost half a year back when I did this so I'm not sure if that's all what I did :(

    So is there a way to change a Standart shader somehow so that I could put normal maps to materials without marking them as normal maps. Or maybe somehow modify that texture in C# after downloading it so that final result will be correct?

    Thanks in advance.