Search Unity

Graphics.CopyTexture and Graphics.Blit problem

Discussion in 'General Graphics' started by MaxNekra, Jan 11, 2020.

  1. MaxNekra

    MaxNekra

    Joined:
    Jan 11, 2020
    Posts:
    1
    Sorry for my English.

    Hi.
    I have problems on my android device. (Galaxy A30). (I didn't check on the others).

    Texture blurs when using Blit several times.

    1. Copy a texture using CopyTexture.
    2. I copy the resulting texture using the Blit method.

    Each time I use the Blit method, the texture will blur.
    More details can be found in the code.

    Code (CSharp):
    1.     public SpriteRenderer SpriteRenderer;
    2.    
    3.     // Sprite-Default material
    4.     public Material BlitMaterial;
    5.    
    6.     // Two identical textures
    7.     public Texture2D Texture1;
    8.     public Texture2D Texture2;
    9.  
    10.     private Texture2D _tempTexture;
    11.    
    12.     public void Start()
    13.     {
    14.         // Create temp texture
    15.         _tempTexture = new Texture2D(Texture1.width, Texture1.height, TextureFormat.RGBA32, false);
    16.         Graphics.CopyTexture(Texture1, _tempTexture);
    17.        
    18.         // Copy Texture 2 to Temp texture
    19.         Graphics.CopyTexture(Texture2, _tempTexture);
    20.  
    21.         // Create new sprite
    22.         SpriteRenderer.sprite = _tempTexture.ToSprite();
    23.     }
    24.  
    25.     private void Update()
    26.     {
    27.         // Get texture from SpriteRenderer
    28.         var texture = SpriteRenderer.sprite.texture;
    29.        
    30.         var renderTexture = RenderTexture.GetTemporary(texture.width, texture.height, 0);
    31.  
    32.         renderTexture.filterMode = FilterMode.Point;
    33.  
    34.         Graphics.Blit(texture, renderTexture, BlitMaterial);
    35.  
    36.         Graphics.CopyTexture(renderTexture, texture);
    37.  
    38.         RenderTexture.ReleaseTemporary(renderTexture);
    39.        
    40.         // Each frame picture will deteriorate
    41.         // If you remove "Graphics.CopyTexture(Texture2, _tempTexture);" everything will be fine.
    42.     }