如何在运行时访问Normap Map(纹理)属性和Border Mip Maps?

时间:2019-02-06 11:12:26

标签: unity3d runtime textures

我正在运行时导入法线贴图,一切正常,但模型上没有边框。

例如,如果我在材质上分配了相同的法线贴图(在Unity编辑器中),则一切正常。因为我的Border Mip Maps属性已打开。

因此可以在运行时打开border mip maps属性。

在编辑器中,可以使用UnityEngine.Editor.TextureImporter访问法线贴图的Border Mip Maps属性。但是我不知道如何在运行时访问Border Mip Map。

public void bumpConvert(Texture2D bumpTexture)
{
        Texture2D normalTexture  = new Texture2D (bumpTexture.width,    bumpTexture.height, TextureFormat.RGBA32, true,true);
        normalTexture.filterMode = FilterMode.Bilinear;
        normalTexture.wrapMode = TextureWrapMode.Repeat;
        Color[] pixels  = bumpTexture.GetPixels(0, 0, bumpTexture.width, bumpTexture.height);

        float r;
        float g;
        float b;
        float a;

        for (int i = pixels.Length - 1; i >= 0; i--){
        Color colour  = pixels[i];
            r = g = b = colour.g;
            a = colour.r;
            pixels[i] = new Color(r, g, b, a);
        }
        normalTexture.SetPixels(pixels);

        normalTexture.Apply();
        bumpTexture = normalTexture;


        GameObject go  = GameObject.Find("Cube");
        go.GetComponent< Renderer > ().material.SetTexture("_BumpMap", bumpTexture);

       // this.enabled = false;
}

我希望法线贴图具有与在运行时加载时相同的效果。 有什么建议吗?

0 个答案:

没有答案