Search Unity

Alpha Texture Cutoff shader has aliasing

Discussion in 'Shaders' started by yuriythebest, Aug 27, 2013.

  1. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    Right, here is the shader. it uses a transparency map to hide stuff. However, the problem is because it is a cutoff shader it causes aliasing at the edges

    Code (csharp):
    1. Shader "Transparent/Mask" {
    2.  
    3.     // by moffatjason.
    4.      
    5.     Properties
    6.      
    7.     {
    8.     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
    9.     _Cutoff ("Base Alpha cutoff", Range (0,.9)) = .5
    10.     }
    11.      
    12.     SubShader {
    13.      
    14.     // Render the mask after regular geometry, but before masked geometry and
    15.     // transparent things.
    16.      
    17.     Tags {"Queue" = "Geometry+10"}
    18.      
    19.     // Don't draw in the RGBA channels; just the depth buffer
    20.      
    21.     ColorMask 0
    22.     ZWrite On
    23.      
    24.     Pass
    25.      
    26.     {
    27.     AlphaTest LEqual [_Cutoff]
    28.     SetTexture [_MainTex] {
    29.     combine texture * primary, texture
    30.     }
    31.      
    32.     }
    33.      
    34.     }
    35.  
    36. }
    1.changing the anti-aliasing in the project quality settings didn't help
    2. Adding anti-aliasing as a post processing effect did help, however it blurred everything else as well (since this app is 2d that won't work)

    Any ideas on how to remove this anti-alasing
     
  2. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    If you can, use alpha blending instead and change the alpha texture to have a sharp transition. You don't need to blur it or anything, texture filtering alone will reduce the aliasing.