[Unity 5] Setting bump map programmatically.

Hello.
I have a question about setting bump map for an object programmatically.
This is what I do:

material.mainTexture = tex;
material.SetTexture("_BumpMap", tex);
material.SetFloat("_BumpScale", 1f);

This sets main texture just fine, but normal map it not set. Well, it is set, but it’s not visible unless I expand the standard shader editor GUI. After I do it, it appears just fine. Where’s the problem here? Do I need to set something else?

Thank you.

You need to also set the shader keywords:

material.shaderKeywords = new string[1]{"_NORMALMAP"};

Unfortunately, I can’t find a good resource for all of the keywords. I only have a few.

  • _NORMALMAP – _BumpMap
  • _EMISSION – _EmissionMap
  • _SPECGLOSSMAP – _SpecGlossMap
  • _DETAIL_MULX2 – _DetailAlbedoMap

I am hoping to find the one for the illumination map, as I am trying to have night side lights on a planet. Emission map shines even if light is on it already. Illumination map doesn’t.