【问题标题】:Set normal map at runtime in Unity在 Unity 运行时设置法线贴图
【发布时间】:2017-03-07 08:03:11
【问题描述】:

我在统一通过脚本设置法线贴图时遇到问题。我有一个法线贴图,我想将它分配给目标对象的材质。

renderer.material = new Material(oldMaterial);    
renderer.material.SetTexture("_BumpMap", normalTexture);

此行用于分配纹理。但是在我打开检查器并单击材质组件之前,目标对象的法线贴图不会更新。我可以使用这种技术更新反照率纹理,并且它有效。
是否有强制材料更新其属性的功能? 有什么想法吗?

【问题讨论】:

    标签: c# unity3d normals


    【解决方案1】:

    尝试添加一个:

    renderer.material.shaderKeywords = new string[1]{"_NORMALMAP"};
    

    【讨论】:

    • 谢谢你的工作!我在想法线贴图是每个着色器中的默认关键字。但事实证明我们必须为它添加一个关键字。谢谢。
    【解决方案2】:

    根据 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);
    

    【讨论】:

      猜你喜欢
      • 2015-10-18
      • 2018-01-05
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      • 2022-10-18
      相关资源
      最近更新 更多