Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
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

Show more comments

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.

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

Export Normal Map from Selected Mesh 0 Answers

Unity2D Tilemap Add Sprites with Normal Maps to tilePallet 2 Answers

Determine if a Texture2D has alpha 3 Answers

Changing Part Of Texture/Material 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