Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by Rednalreden · Oct 02, 2014 at 12:35 PM · textureruntime

Runtime loading normal texture

Hello,

I'm currently trying to load textures at runtime through the WWW class and it is working perfectly for every texture except for normal textures. Unity does not convert these like they do when you put them in the editor. I've looked through Unity Anwsers but only found this solution: http://answers.unity3d.com/questions/47121/runtime-normal-map-import.html Which creates a grayscale version of my normal map. If I recall correctly this is how Unity used to work with normals.

When I use this runtime loaded and converted normal map with Unity 4.5 the lighting is all over the place. I did not find any other method to load a normal map at runtime.

Does somebody know a way to load the normals correctly? Like when I load normals in the editor and convert them to a normal map.

Runtime modified through previous anwser (grayscale): alt text

Runtime unmodified: alt text

normal_runtime_unmodified.jpg (98.1 kB)
grayscale_normal_runtime.jpg (120.2 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Aras · Oct 09, 2014 at 06:59 AM

On PC & console platforms, Unity does "DXT5nm" encoding for normal maps. The X component (red channel of original normal map texture) should be put into alpha; and Y component (green channel of original normal map texture) should stay in the green channel. Red and blue channels are not used.

This is done so that DXT5 compression can be done for normal maps at acceptable quality, since if done on "regular normal map" the DXT5 quality is really, really bad.

On "mobile" platforms a regular normal map encoding is uses, where XYZ components are just put into RGB channels of the texture.

Comment
Add comment · Show 2 · 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
avatar image Rednalreden · Oct 09, 2014 at 09:42 AM 1
Share

Thanks! This works. It makes the texture green ins$$anonymous$$d of greyscale but it does the trickt. Below I've added a method to convert a normal texture imported at runtime (modified from http://answers.unity3d.com/questions/47121/runtime-normal-map-import.html).

 private Texture2D Normal$$anonymous$$ap(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;
     }
avatar image anthonyscott · Jun 24, 2015 at 08:19 PM 0
Share

This explanation helped me save generated normal maps correctly. Thanks a bunch!

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to update texture during runtime to display damage? 0 Answers

Load texture and shaders at runtime on iPhone 2 Answers

export normal texture at runtime 2 Answers

Importing and configuring Normal Maps at runtime ? 2 Answers

Changing texture import settings during runtime 3 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