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
0
Question by Jon-Martin · Jan 18, 2011 at 05:37 PM · shadertextureruntimenormal

Runtime Loaded Bump/Normal Texture into "Bumped Diffuse" Shader

I've been working on a RUNTIME .OBJ importer, all is going well with building mesh, normals and uv's, even turning quads to tri's etc.

I've become stumped on getting a RUNTIME imported BumpMap texture to work correctly with the "Bumped Diffuse" Standard shader.

I've first tried altering the Texture2d from color, greyscale and included a found function to convert it to a NVidea type Normal Map at runtime with no results

I tried changing texture spec from DXT1,DXT5,ARG32,RGB24 to no gain, even swapping different channels about for fun, and compressing the textures at runtime. I know the inbuilt editor importer converts normal maps to DXTnm, but this is not supported under .TextureFormat. syntax.

I have included a function solvetangents that generates tangents for the mesh and puts them to mesh.tangents which belongs to the mesh attached to the meshfilter of GO.

My only conclusion is that I have to use some other shader which would be a shame, or am not passing something correctly, does anyone have an idea why this will theoretically not work or how I could get this to work?

edit: Here's a simplied and much stripped version of my problem:-

using UnityEngine; using System.Collections;

 public class tester : MonoBehaviour {
 public Texture2D BumpTexture;
 public Texture2D DiffTexture;
 public string objPath;
 public string PathDif;
 public string PathBump;
 private WWW loader;

 void Start() {
     StartCoroutine (Loader(objPath));
 }

 public IEnumerator Load(string objPath) {
     //....CODE...

     loader = new WWW(PathDif);
     yield return loader;
     loader.LoadImageIntoTexture(DiffTexture);
     loader = new WWW(PathBump);
     yield return loader;
     loader.LoadImageIntoTexture(BumpTexture);

     //....CODE...

     Material m;
     m=new Material(Shader.Find("Bumped Diffuse"));
     m.SetColor("_Color", new Color(0.5,0.5,0.5,1.0)); //example only
     if(DiffTexture!=null) m.SetTexture("_MainTex",DiffTexture);
     if(BumpTexture!=null) m.SetTexture("_BumpMap",BumpTexture);

     //....CODE...

     gameObject.AddComponent(typeof(MeshFilter));
     gameObject.AddComponent(typeof(MeshRenderer));
     //meshes generated, added, uv, normals recalculated, solved tangents
     gameObject.renderer.material = m;
     //result bump map doesn't look good
 }

}

See comment below for links to other parts of earlier code.

Many thanks in anticipation, Jon.

Comment
Add comment · Show 3
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 DaveA · Jan 18, 2011 at 08:42 PM 0
Share

Can you post some code for us to review here? I'm curious how you are doing the actual assignment of the bumpmap texture to the shader.

avatar image Jon-Martin · Jan 18, 2011 at 10:42 PM 0
Share

Thanks for the interest Dave, I won't post the full code i've been modding bartok's obj code from the Everyday3d site (I reposted some code back on his site last friday) you can see some of my earlier modifications here: http://pastebin.com/yqQjyHUg and here: http://pastebin.com/YPSYPi73 And i've posted a stripped simplified bit of the code i'm working in the original post above.

avatar image Jon-Martin · Jan 22, 2011 at 05:38 PM 0
Share

By transferring the material created onto a generated primitive sphere, I could see that the normal map generator, dxt5 compression and the Unity Bumped Diffuse shader were absolutely fine, what isn't working fine is the tangent space calculation on the object, code found on the forum, so i'm going to have to figure out why my mesh is getting its tangents in a twist, possibly something to do with either having sub-meshes, having to invert faces or inverting z-axis on vertex import??

2 Replies

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

Answer by Jon-Martin · Jan 24, 2011 at 12:22 PM

The solvetangents c# script on this page had an a tiny error:-

Calculating Tangents: Unity Answers

I posted the correction on that page in the comments underneath, thankyou to Dave A for the kind responses.

Comment
Add comment · Show 1 · 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 CodeAssembler · Aug 12, 2013 at 04:06 PM 0
Share

Thanks a lot Jon! I could fix my problem in the loader implementation I'm working too thanks to your pointer/hints about the tangents, since at first I tough the problem was at the Normal texture loader method.

avatar image
0

Answer by DaveA · Jan 18, 2011 at 08:42 PM

If time is money, someone is selling such a thing in the Asset store for $15. I don't know how good it is.

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 Jon-Martin · Jan 19, 2011 at 10:56 AM 0
Share

Thanks for the idea, but my importer works well bar this normal mapping, not sure if this importer will parse an obj material file as well as i'd like it too.

avatar image Jon-Martin · Jan 19, 2011 at 10:58 AM 0
Share

Almost forgot, I also have to release all the project source code for free under GPL as i am bound by an educational bid, so couldn't use a commercial script as we'd have to disclose the code. Thanks though all the same.

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

1 Person is following this question.

avatar image

Related Questions

Is it possible to adjust normal map strength at runtime? 1 Answer

How to fix a object intersection problem? 0 Answers

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

Moss/Snow texture on arbitrarily rotated doodads. 1 Answer

Applying decals / textures to uneven surfaces runtime 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