Unity渲染绘制接口 Graphics.Blit

Graphics.Blit(source, dest,mat):使用着色器拷贝原纹理到RenderTexture

Graphics.Blit通常用于后处理,需要注意的是使用后会修改RenderTexture.active,在此接口后直接使用Graphics绘制接口,不会生效。

        public static Texture2D TextureToTexture2D(Texture texture)
        {
            Texture2D texture2d = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, true);
            RenderTexture rt = new RenderTexture(texture.width, texture.height, 0, RenderTextureFormat.ARGB32);
            Graphics.Blit(texture, rt); //使用着色器口拷贝原纹理到RenderTexture
            RenderTexture.active = rt;
            texture2d.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
            texture2d.Apply();
            return texture2d;
        }

猜你喜欢

转载自blog.csdn.net/m0_53377876/article/details/132280783