在 Unity 运行时设置法线贴图
Set normal map at runtime in Unity
我在 unity 中通过脚本设置法线贴图时遇到问题。我有一张法线贴图,我想将它分配给目标对象的 material。
renderer.material = new Material(oldMaterial);
renderer.material.SetTexture("_BumpMap", normalTexture);
这一行用于指定纹理。但是直到我打开检查器并单击 material 组件,目标对象的法线贴图才会更新。我可以使用此技术更新反照率纹理并且它有效。
是否有强制 material 更新其属性的功能?
有什么想法吗?
尝试添加一个:
renderer.material.shaderKeywords = new string[1]{"_NORMALMAP"};
根据 Unity 的文档,您首先需要 EnableKeyword
: _NORMALMAP
。然后,可以显示您提供的法线贴图。更多解释可以看下面代码或者this website.
//Fetch the Renderer from the GameObject
renderer = GetComponent<Renderer> ();
//Make sure to enable the Keywords
renderer.material.EnableKeyword ("_NORMALMAP");
//Set the Normal map using the Texture
renderer.material.SetTexture("_BumpMap", normalTexture);
我在 unity 中通过脚本设置法线贴图时遇到问题。我有一张法线贴图,我想将它分配给目标对象的 material。
renderer.material = new Material(oldMaterial);
renderer.material.SetTexture("_BumpMap", normalTexture);
这一行用于指定纹理。但是直到我打开检查器并单击 material 组件,目标对象的法线贴图才会更新。我可以使用此技术更新反照率纹理并且它有效。
是否有强制 material 更新其属性的功能?
有什么想法吗?
尝试添加一个:
renderer.material.shaderKeywords = new string[1]{"_NORMALMAP"};
根据 Unity 的文档,您首先需要 EnableKeyword
: _NORMALMAP
。然后,可以显示您提供的法线贴图。更多解释可以看下面代码或者this website.
//Fetch the Renderer from the GameObject
renderer = GetComponent<Renderer> ();
//Make sure to enable the Keywords
renderer.material.EnableKeyword ("_NORMALMAP");
//Set the Normal map using the Texture
renderer.material.SetTexture("_BumpMap", normalTexture);