对于我的项目,我需要在运行时创建材料.当我创建材质时,法线贴图无效.我尝试了两个解决方案,但它们对我不起作用.在Unity 5中有什么变化吗?
我检查的链接:
http://answers.unity3d.com/questions/801670/runtime-loading-normal-texture.html
http://answers.unity3d.com/questions/47121/runtime-normal-map-import.html
P.S:奇怪的是当我切换到Unity内部的“场景视图”时,如果我从“检查器”展开材质选项卡,则将法线贴图应用于对象.
我的代码:
.... Material mat = new Material(Shader.Find("Standard (specular setup)")); mat.SetTexture("_MainTex",colortex); normaltex = getnormalTexture(Texture2D source); mat.SetTexture("_BumpMap",normaltex); mat.SetFloat("_Glossiness",0.1f); mat.SetFloat("_BumpScale",1.0f); .... public static Texture2D getnormalTexture(Texture2D source) { Texture2D normalTexture = new Texture2D(source.width,source.height,TextureFormat.ARGB32,true); Color theColour = new Color(); for (int x = 0; x < source.width; x++) { for (int y = 0; y < source.height; y++) { theColour.r = 0; theColour.g = source.GetPixel(x,y).g; theColour.b = 0; theColour.a = source.GetPixel(x,y).r; normalTexture.SetPixel(x,y,theColour); } } normalTexture.Apply(); return normalTexture; }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。