Search Unity

Android build differs from editor, rendertexture has blocky artifacts as in Point filter mode

Discussion in 'General Graphics' started by nasos_333, Jul 15, 2018.

  1. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,361
    Hi,

    I am trying to run a rendertexture swap based simulation in Android and while in Editor all seem fine, in the actual build the rendertextures behave like they are all in Point filter mode. I forced Point in the editor time too
    and get the exact same result with the Android, so i assume that is the issue.

    I use Unity 5.6 for the export of the project to Android.

    Thank you in advance for any insight on what might be the cause for this.
     
  2. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,361
    UPDATE:

    I also tested in Unity 2018 and seems to do the same.

    I get the below warning:
    "Tiled GPU perf. warning: RenderTexture color surface (440x540) was not cleared/discarded"

    Which points to one of the Blits in the script.
     
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    What's the RT format and on what device does this happen?
    And which graphics API are you using?
     
  4. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,361
    Hi,

    I test on a Samsung S8+ and build directly to Android. I tried export from both Unity 5.6 and Unity 2018.2 latest versions as well.

    The RT involved (the 3 ones i change to Point filtering and get the same effect with the artifacts in the editor as they appear with the phone) are the below. I can also send two pics from the desktop editor image and the phone image with the artifacts for reference if needed.

    Code (csharp):
    1.  
    2. CreateSurface(m_velocityTex, RenderTextureFormat.RGFloat, FilterMode.Bilinear);
    3. CreateSurface(m_densityTex, RenderTextureFormat.RFloat, FilterMode.Bilinear);
    4. CreateSurface(m_temperatureTex, RenderTextureFormat.RFloat, FilterMode.Bilinear);
    5.  
    where the function to create the RT is the below

    Code (csharp):
    1.  
    2. void CreateSurface(RenderTexture[] surface, RenderTextureFormat format, FilterMode filter)
    3.         {
    4.             surface[0] = new RenderTexture(m_width, m_height, 0, format, RenderTextureReadWrite.Linear);
    5.             surface[0].filterMode = filter;
    6.             surface[0].wrapMode = TextureWrapMode.Clamp;
    7.             surface[0].Create();
    8.             surface[1] = new RenderTexture(m_width, m_height, 0, format, RenderTextureReadWrite.Linear);
    9.             surface[1].filterMode = filter;
    10.             surface[1].wrapMode = TextureWrapMode.Clamp;
    11.             surface[1].Create();
    12.         }
    13.  
    I clear and swap the targets using the below functions

    Code (csharp):
    1.  
    2. void ClearSurface(RenderTexture surface)
    3.         {
    4.             Graphics.SetRenderTarget(surface);
    5.             GL.Clear(false, true, new Color(0, 0, 0, 0));
    6.             Graphics.SetRenderTarget(null);
    7.         }
    8.         void Swap(RenderTexture[] texs)
    9.         {
    10.             RenderTexture temp = texs[0];
    11.             texs[0] = texs[1];
    12.             texs[1] = temp;
    13.         }
    14.  
    All Blits take place in the "void Update()" function.

    Also i Blit the final result to an external RT using:
    Code (csharp):
    1.  
    2. Graphics.Blit(m_densityTex[READ], m_guiTex, m_guiMat);
    3.  
    I attach an image with the RT format.

    I have tried forcing the Bilinear filtering in the Update to make sure it stands at every update, it did not work. Also i cleared the targets whenever i did a Blit (using target.DiscardContents()) to a target and solved the above mentioned tiled rendering warning, but did not solve the issue either (but solved the warning).
     

    Attached Files:

    • rt1.jpg
      rt1.jpg
      File size:
      66 KB
      Views:
      795
    Last edited: Jul 16, 2018
  5. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,361
    I also attach an image of the editor running the project, using the Point filtering for the RT i mentioned like the below code
    1. CreateSurface(m_velocityTex, RenderTextureFormat.RGFloat, FilterMode.Point);
    2. CreateSurface(m_densityTex, RenderTextureFormat.RFloat, FilterMode.Point);
    3. CreateSurface(m_temperatureTex, RenderTextureFormat.RFloat, FilterMode.Point);
    This produces the exact same artifacts i see in the mobile build (in motion seem the same too)
     

    Attached Files:

  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    Code (CSharp):
    1. CreateSurface(m_velocityTex, RenderTextureFormat.RGFloat, FilterMode.Bilinear);
    2. CreateSurface(m_densityTex, RenderTextureFormat.RFloat, FilterMode.Bilinear);
    3. CreateSurface(m_temperatureTex, RenderTextureFormat.RFloat, FilterMode.Bilinear);
    This is your problem :)
    Most Android devices don't support anything but point filtering on 32-bit float textures.
    Change to RenderTextureFormat.RGHalf and RenderTextureFormat.RHalf, and it should work.
     
    nasos_333 likes this.
  7. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,361
    Many thanks :), this directly solved the issue !!!

    It was clear that reverted to Point filtering but i did not know why :)