• 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 minimal. 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Changing Part Of Texture/Material 1 Answer

How to load an image at runtime via WWW correctly 1 Answer

How are normal maps imported? 1 Answer

Changing normal map intensity 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges