Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Render scene with no antialiasing

Discussion in 'General Graphics' started by carcasanchez, Oct 18, 2021.

  1. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    Hi everyone,
    I'm trying to render my scene to a file, but I the result has some color-bleeding which I presume is from antialiasing.
    upload_2021-10-18_12-57-57.png
    I need the green and red objects to render as pure plain color, with no antialiasing.
    I have been searching for info on the web, and I have tried (unsuccessfully) the following:
    *Disabling antialiasing in project
    *Disabling HDR in the camera
    *Setting the Render texture and 2D texture format to Point
    *Disabling mipmaps
    *Setting render texture antialiasing to 1

    Changing the format to RGBA32 in both textures gives better results, but still some color bleeding
    upload_2021-10-18_13-7-54.png

    This is the code Im using for rendering:
    Code (CSharp):
    1.     void RenderCamera(string name)
    2.     {
    3.     RenderTexture thumbnail = new RenderTexture(_camera.pixelWidth, _camera.pixelHeight, 24);
    4.         thumbnail.autoGenerateMips = false;
    5.         thumbnail.filterMode = FilterMode.Point;
    6.         thumbnail.antiAliasing = 1;
    7.         thumbnail.Create();
    8.  
    9.  
    10.         _camera.targetTexture = thumbnail;
    11.         Texture2D thumb_tex = new Texture2D(_camera.pixelWidth, _camera.pixelHeight, TextureFormat.RGB24, false);
    12.         thumb_tex.filterMode = FilterMode.Point;
    13.  
    14.         _camera.Render();
    15.         RenderTexture.active = thumbnail;
    16.  
    17.         thumb_tex.ReadPixels(_camera.pixelRect, 0, 0);
    18.         thumb_tex.Apply();
    19.         byte[] png = thumb_tex.EncodeToPNG();
    20.         File.WriteAllBytes(Application.dataPath + "/../LabelRenders/" + name + ".png", png);
    21.         _camera.targetTexture = null;
    22.         RenderTexture.active = null;
    23.  
    24.     }
     
  2. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    I have encountered a curious issue when using ARGB32 format: all my scene is rendered as transparent, even the opaque objects, something I cannot comprehend
     

    Attached Files:

    • 0.png
      0.png
      File size:
      618.9 KB
      Views:
      224
  3. carcasanchez

    carcasanchez

    Joined:
    Jul 15, 2018
    Posts:
    177
    Solved! Turns out the Post Processing Layer in the camera has another instance of antialiasing, that had to be turned off. Dont know why the alpah channel got so messy, but that problem got solved too