Search Unity

Pixelization effect, turn off AA?

Discussion in 'Image Effects' started by FurssAxel, Jul 18, 2017.

  1. FurssAxel

    FurssAxel

    Joined:
    Jun 21, 2017
    Posts:
    7
    Hello,

    Is there any way I could remove this pixel smoothing (semitransparent pixels on edges)?
    upload_2017-7-18_13-53-25.png

    Code I am using:
    Code (CSharp):
    1. public class ScreenPixelization : MonoBehaviour
    2. {
    3.     [Range(1, 25)] public int resolution = 8;
    4.  
    5.  
    6.     void OnRenderImage(RenderTexture source, RenderTexture destination)
    7.     {
    8.         RenderTexture lowRez;
    9.  
    10.         int w = source.width / resolution;
    11.         int h = source.height / resolution;
    12.  
    13.         lowRez = RenderTexture.GetTemporary(w, h);
    14.         lowRez.filterMode = FilterMode.Point;
    15.  
    16.         Graphics.Blit(source, lowRez);
    17.         Graphics.Blit(lowRez, destination);
    18.     }
    19. }
    Thanks!
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You have MSAA or FXAA or Post Effect AA enabled.

    A render texture (not a temporary one) is able to exclude MSAA if that's the problem. Otherwise don't render it with AA to begin with.
     
  3. FurssAxel

    FurssAxel

    Joined:
    Jun 21, 2017
    Posts:
    7
    My quality and camera settings:
    upload_2017-7-18_15-5-32.png upload_2017-7-18_15-5-59.png

    As you can see I have AA and MSAA disabled. Is there something Ive missed?
     
    Last edited: Jul 18, 2017
  4. FurssAxel

    FurssAxel

    Joined:
    Jun 21, 2017
    Posts:
    7
    Anyone? I found some questions about same problem and they also not answered. This should not be very hard to solve
     
  5. FurssAxel

    FurssAxel

    Joined:
    Jun 21, 2017
    Posts:
    7
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The issue you're seeing is due to bilinear sampling of the original render texture, in part likely caused by the initial screen resolution not being a multiple of 8, though correcting for just that will just mean all of the samples will be "blurry" add they'll be bilinearly sampled from the exact center of 4 pixels.

    Try setting the source texture to point filtered.
     
  7. FurssAxel

    FurssAxel

    Joined:
    Jun 21, 2017
    Posts:
    7
    I tried setting my screen to 512x256
    upload_2017-7-31_12-42-45.png

    Also I update the code and set source texture to point filtering
    Code (CSharp):
    1.     void OnRenderImage(RenderTexture source, RenderTexture destination)
    2.     {
    3.         RenderTexture lowRez;
    4.         Debug.Log("SOURCE: " + source.width + " " + source.height);
    5.         var w = source.width / resolution;
    6.         var h = source.height / resolution;
    7.         Debug.Log("TARGET: " + w + " " + h);
    8.    
    9.         source.filterMode = FilterMode.Point;    
    10.         lowRez = RenderTexture.GetTemporary(w, h);
    11.         lowRez.filterMode = FilterMode.Point;
    12.        
    13.         Graphics.Blit(source, lowRez);
    14.         Graphics.Blit(lowRez, destination);
    15.         RenderTexture.ReleaseTemporary(lowRez);
    16.     }
    Still I have this AA :(
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Using that code exactly as is with either deferred or forward with MSAA disabled works perfectly for me. I'm using Unity 5.6.1 to test, and I disabled MSAA directly on the camera (Allow MSAA).
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Could it possibly be driver AA from driver control panel or such?
     
    bgolus likes this.
  10. FurssAxel

    FurssAxel

    Joined:
    Jun 21, 2017
    Posts:
    7
    All driver settings were application controlled. I tried to set them off but AA still appears.
    The only way I was able to get sharp pixels on edges was rendering to already created low res texture using camera. And then drawing it using OnGUI method. I dont like this solution because of some problems with different resolutions and unity shows annoying popup if there is no camera that rendering to display.
    I tried shader solutions but they also produce AA.