• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Cagkan Toptas · Aug 07, 2015 at 04:12 PM · normalmap

How to import Normal map at Runtime in Unity 5?

For my project, I need to create materials at run time. When I create material, Normal map has no effect. I tried the two solutions about this but they did not work for me. Is something has changed about this in Unity 5 ?

The Links I checked :

http://answers.unity3d.com/questions/801670/runtime-loading-normal-texture.html http://answers.unity3d.com/questions/47121/runtime-normal-map-import.html

P.S: The weird thing is when I switch to "Scene View" inside Unity, If I expand material tab from "Inspector" Normal Map is being applied to the object.

My Code:

             ....
 Material mat = new Material(Shader.Find("Standard (Specular setup)"));
 mat.SetTexture("_MainTex", colortex);

 //For source texture I both tried to use a file from external path and from 
 //Resources path which the image file marked as "Normal map".Result did not changed.

 normaltex = getNormalTexture(source);
 mat.SetTexture("_BumpMap", normaltex);
 mat.SetFloat("_Glossiness", 0.1f);
 mat.SetFloat("_BumpScale", 1.0f);
 
             ....             
 
 public static Texture2D getNormalTexture(Texture2D source)
 {
     Texture2D normalTexture = new Texture2D(source.width, source.height, TextureFormat.ARGB32, true);
     Color theColour = new Color();
     for (int x = 0; x < source.width; x++)
     {
         for (int y = 0; y < source.height; y++)
         {
             theColour.r = 0;
             theColour.g = source.GetPixel(x, y).g;
             theColour.b = 0;
             theColour.a = source.GetPixel(x, y).r;
             normalTexture.SetPixel(x, y, theColour);
         }
     }
     normalTexture.Apply();
     return normalTexture;
  }



Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image carmine · Mar 28, 2016 at 03:11 PM 1
Share

I am having this EXACT issue. For some reason the normal map doesn't seem to take effect until I flip the triangle down in the inspector (next to the material).

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by Gagan25 · Jun 21, 2017 at 08:14 AM

hello thankyou for your code. This code works perfectly on mac and windows. But on iOS normal map is not created properly. As you can see in screenshot. As i switch platform from iOS to pc it comes properly. Please see the screenshot for reference. Please help me in this case.alt textalt text


withpropernormal.png (101.7 kB)
iosnormalproblem.png (130.0 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Change normal map bumpiness runtime? 1 Answer

A few modeling questions 1 Answer

Cant see normal maps in a specific project. 0 Answers

Unity 5 bake normal map into lightmap 1 Answer

How do I compress a normal map to DTX5_NM without getting inconsistent results? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges