• 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 craigp · Apr 19, 2013 at 06:22 PM · normal map

How to generate normal maps on the fly?

I have an application where I inherit normal maps from several layers, blurring the lower layers in a fairly complicated way. I've got all the image editing down - I can get a final result which is correctly stacked and blurred.

If I save the image to the hard drive and then manually import it as a normal map, I get the correct result. But I can't do that for this application - I need a way to do it just in code.

I can't figure out how to do it in code. When I assign this texture as the normal map on a material, it screws up. Even if the texture I use is entirely the standard blue (0.5, 0.5, 1, 1) it drops the normals from the mesh and just points everything off in another direction.

I've tried a few variations. For example, I tried importing a white image as a "convert from grayscale" normal map, then changing its pixels to my calculated height map at run time. That doesn't work. I tried importing a proper normal map and overwriting its pixels at run time with my calculated normal map, but evidently Unity's normal maps are in DXT5 format, and therefore you can't set their pixels using the normal set pixel functions...

So, what's the best way to do this? Do I need to convert the resulting image to DXT5? If so, how? Is there another way, a setting somewhere I can toggle? Some kind of function or setting I'm missing?

Comment
Add comment · Show 1
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 LightSource · Apr 19, 2013 at 06:54 PM 0
Share

Photoshop will do it. Just reverse coloring and turn it black and white, then change it to a normal map in Unity.

1 Reply

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

Answer by craigp · Apr 19, 2013 at 07:48 PM

Ahh, I feel like an idiot. I specified it as (xdelta, ydelta, normal, alpha), but if I specify it as (alpha, xdelta, ydelta, normal) any texture can be set as a normal map and functions fine.

However, it doesn't look anything like the normal maps generated by Unity. They're pink. I think this is because Unity doesn't properly carry the difference between formats RGBA32 and ARGB32, and is converting between them with a hard cast.

Either way, problem solved. Sorry to bother you.

Comment
Add comment · Show 3 · 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 LightSource · Apr 19, 2013 at 09:36 PM 0
Share

No problem, glad you found the answer. In the future though, make sure to post replies as comments not answers.

avatar image craigp · Apr 19, 2013 at 09:38 PM 0
Share

Huh? I posted it as an answer because it's an answer, not a reply.

The answer is: Normals work weird because RGBA32 and ARGB32 are randomly hard cast and normals need to be set to 0.5f rather than 1f. It has nothing to do with your comment about photoshop.

avatar image LightSource · Apr 19, 2013 at 10:05 PM 1
Share

$$anonymous$$y fault, I assumed you were responding to my comment. You see, allot of new users continually post replies and comments as answers. I was confused by the conversational format of your last sentence. Sorry again.

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

12 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

Related Questions

Problems With Alpha Channels When Loading DXT5 Texture2D From PNG 1 Answer

Why does my bumped diffuse material get lit in a weird way? 1 Answer

Incorrect lighting projecting normal map downwards in world space 1 Answer

How to add a normal map to custom shader which blends material on edges,Adding normal map to bump shader type 0 Answers

How to add UV images to an object 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