• 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
0
Question by FairGamesProductions · Jun 05, 2019 at 01:15 PM · texture2druntimenormalmapnormal mapimporting textures

Problem importing normal map texture at runtime

I am having an issue importing a png image and using it as a normal map at runtime. This is my code:

     t = new Texture2D(16, 16, TextureFormat.DXT5Crunched, false, true);
     ImageConversion.LoadImage(t, _downloader.data, false);
     Color[] colors = t.GetPixels();
     Color c;
     for (int q = 0; q < colors.Length; q++)
            {
             c = colors[q];
             c.a = c.r;
             c.r = 1; //have tried this with 0, same result
             c.b = 0; // have tried this with 1, same result
             colors[q] = c;
             }
     t.SetPixels(colors);
     yield return null;
     t.Compress(true);
     t.Apply(false, true);
 

I have tried every single answer I could find online. This one comes from: https://forum.unity.com/threads/get-external-normal-map-at-runtime.532892/ and it's the answer given by the guy with the Unity Technologies tag. This solution gets me close but not close enough. Here is what the material is supposed to look like (with the texture imported into Unity and applied manually): alt text And here is what it looks like with the normal map imported at runtime with this code: alt text The difference is very noticeable if the camera moves around or gets far away. The main difference is that in the runtime material there is an overall tilt to the reflection.

The Texture2D is set to linear. I have tried it with mip maps (the result is worse) and without, compressed and un-compressed, and multiple formats. It's all the same result. Any ideas as to what I am missing here?

[EDIT]: Changed the example images to a different angle to better illustrate the problem.

1.jpg (76.8 kB)
2.jpg (71.7 kB)
Comment
Add comment · Show 6
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 Bunny83 · Jun 05, 2019 at 04:31 PM 0
Share

Are you sure that your texture is actually a normal map and not just a bump map? Can you show your texture that you import at runtime?

avatar image FairGamesProductions Bunny83 · Jun 05, 2019 at 04:55 PM 0
Share

I am 100% sure. Here is a scaled down version of the texture: alt text

beige-tiles-5-normal-small.png (220.7 kB)
avatar image Bunny83 FairGamesProductions · Jun 05, 2019 at 08:59 PM 0
Share

Sorry but your two provided screenshots in the question we can see barely a difference. Your normal map details are really $$anonymous$$imal. You may want to look at the result without the albedo texture (so render the cube with a solid color but with normal map). This might help to see if there's a difference.


As far as i know Unity uses the "DXT5nm" normal map format. So you probably should do:

 c = colors[q];
 c.a = c.r;
 c.r = 0;
 c.b = 0;
 colors[q] = c;

Also note that the normalmap format might change depending on the platform / renderer used. This can be seen in the way the unpack normal shader helper is designed. Note the current implementation of UnpackNormal has already changed. Just look it up in your own Unity version in [...]\Editor\Data\CGIncludes\UnityCG.cginc

avatar image FairGamesProductions Bunny83 · Jun 06, 2019 at 04:38 AM 0
Share

I only care about running this on Windows, in deffered linear mode.

The problem is that if you look too closely you'll notice a tilt in the entire reflection of the runtime material, compared to the manually made one.

Here is the result of your suggestion, but I already tried it before and it's really not good. alt text And this is what it's SUPPOSED to look like: alt text

1.jpg (74.1 kB)
2.jpg (69.0 kB)
avatar image FairGamesProductions Bunny83 · Jun 06, 2019 at 04:40 AM 0
Share

So as you can see from the original example and this one, issue is not with the detailing that the normal provides but with the "flat" areas as well.

avatar image FairGamesProductions Bunny83 · Jun 06, 2019 at 04:44 AM 0
Share

Also, this is what the imported normal map texture looks like with this change (c.r = c.b = 0) alt text

3.jpg (37.8 kB)

0 Replies

· Add your reply
  • Sort: 

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

180 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Run-time loaded Normal Map Lighting problem 1 Answer

Convert Texture2d to sprite 2 Answers

How are normal maps imported? 1 Answer

Changing normal map intensity 1 Answer

How to set a texture resource to texture type "GUI" by script? 1 Answer


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