[SOLVED]Unity Artifact on some android devices when create texture with a specific material effect rendered on it

129 views Asked by At

To create a texture with a certain material effect applied on it, I do something like this:

    public Texture2D source;    
    public Material material;    


     public static void Create(GameController gameController)
     {
          Texture2D t = source;
          gameController.ImprovedPhoto = t;
          gameController.ImprovedPhoto = 
          ImproveOriginalPhoto(gameController, material, 
          gameController.ImprovedPhoto, 1024);
     }


     //this is the method where I apply the material to the new texture, using a RenderTexture
     public static Texture2D ImproveOriginalPhoto(GameController gameController, Material material,        Texture2D source, int size)
     {

          //gameController.renderTexture.format is ARGB32 and I see in the logcat
          //that 
          CheckSupportRenderTextureInfo(RenderTextureFormat.ARGB32) == true
          RenderTexture buffer = new RenderTexture(size, size, 32, gameController.renderTexture.format);

          //render material to a RenderTexture using a Blit()
          Graphics.Blit(source, buffer, material, -1);

          //then create a Texture2D with the same dimensions and format as the render texture
          Texture2D new_Texture = new Texture2D(buffer.width, buffer.height, TextureFormat.ARGB32, true);
          new_Texture.filterMode = FilterMode.Bilinear;
          new_Texture.wrapMode = TextureWrapMode.Clamp;

          //and use ReadPixels() to copy the render texture to the CPU memory.
          new_Texture.ReadPixels(
          new Rect(0, 0, buffer.width, buffer.height), // Capture the whole texture
                    0, 0, // Write starting at the top-left texel
                    true);

          new_Texture.Apply();

          return new_Texture;

     }

source photo

I tested this method on an "old" Redmi Note 9 (M2003J15SS) and there it works great (in the editor too), but when I test my application on a newer Xiaomi Mi 10T Pro (M2007J3SG) the generated ImprovedPhoto looks like the ImprovedPhoto.png, with transparent lines cutting through it. The Redmi Note has an aspect of 1080x2340, the Mi 10T has 1080x2400. I'm using Unity 2021.3.24f1.

What could be causing this problem? ImprovedPhoto.png

0

There are 0 answers