Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Using Unity's Normal from Grayscale at runtime

Discussion in 'Editor & General Support' started by Blenderik, Mar 13, 2015.

  1. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    133
    I hope this isn't a double post, but everything I found was only kinda close to my question.

    I am creating a bw image from a font and want to use it as a normal map. If I go into the inspector I can choose "normal map" for any texture, if it is not one already it will be created from grayscale. I want to do exactly that but at runtime.
    I can do something close to it, using methods I found. Assigning textures to the standard shader works without problems for _mainTex and _occlusionMap, but if I assign it to the normals (even pre-converted normalmaps) it does not update until I click on the object and twirl down the material settings in the inspector while the game is running.
    So I'm kind of puzzled.
    Thanks.
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    If you do not have a normal-map setup-ed for the slot unity will disable the normal map calculations for saving time
    you can it re-enable it like this for example.

    Code (CSharp):
    1.         GetComponent<Renderer> ().sharedMaterial.SetTexture ("_BumpMap", normalMap);
    2.         GetComponent<Renderer> ().sharedMaterial.EnableKeyword ("_NORMALMAP");
    If you like to find out what shader keywords are available in you shader , download the build in shader and look in the shader code for this:
    Code (CSharp):
    1. #pragma shader_feature
     
  3. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    133
    That explains it, thanks a lot
     
  4. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    133
    But what about the conversion of bump to normal map (the one you can do in the inspector) does that work at runtime?
     
  5. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Last edited: Mar 17, 2015
  6. Blenderik

    Blenderik

    Joined:
    May 14, 2013
    Posts:
    133
    VIelen Dank