Search Unity

Alpha blending a complex model

Discussion in 'Shaders' started by pixpusher2, Dec 12, 2014.

  1. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Hi,
    I've modified the Toon Shader to add an X-Ray effect whenever my characters goes behind the walls. It works fine when _XColor's alpha is 1 (255), but overlapping polygon starts to show through when alpha is lowered.

    How can I get a clean alpha blended solid color without the overlaps? Thanks

    Edit: I've tried adding ColorMask 0 as shown here http://wiki.unity3d.com/index.php?title=AlphaVertexLitZ but the outcome is still the same

    Edit2: Further testing shows that ZTest Greater in X-Ray pass may be interfering with the ColorMask. But I'm not sure how to resolve it.

    Code (CSharp):
    1. // Toony Colors Pro+Mobile Shaders
    2. // (c) 2013,2014 Jean Moreno
    3.  
    4. Shader "Toony Colors Pro/OutlineConst/OneDirLight/Basic X-Ray"
    5. {
    6.     Properties
    7.     {
    8.         _MainTex ("Base (RGB)", 2D) = "white" {}
    9.         _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
    10.    
    11.         //COLORS
    12.         _Color ("Highlight Color", Color) = (0.8,0.8,0.8,1)
    13.         _SColor ("Shadow Color", Color) = (0.0,0.0,0.0,1)
    14.         _XColor ("X-Ray Color", Color) = (1.0,0.0,1.0)
    15.    
    16.         //OUTLINE
    17.         _Outline ("Outline Width", Range(0,0.05)) = 0.005
    18.         _OutlineColor ("Outline Color", Color) = (0.2, 0.2, 0.2, 1)
    19.     }
    20.  
    21.     SubShader
    22.     {
    23.         Tags { "Queue"="Transparent" }
    24.         LOD 200
    25.  
    26.        Pass
    27.        {
    28.            ColorMask 0
    29.        }
    30.  
    31.         // X-Ray pass
    32.         Pass
    33.         {
    34.             Zwrite Off
    35.             ZTest Greater
    36.             Blend SrcAlpha OneMinusSrcAlpha
    37.             Cull Back
    38.             ColorMask RGB
    39.  
    40.             Color [_XColor]
    41.         }
    42.    
    43.         // Toon pass
    44.         CGPROGRAM
    45.  
    46.        // NOTE: Toon shader pass redacted because it's bought from the asset store
    47.  
    48.         ENDCG
    49.    
    50.         UsePass "Hidden/ToonyColors-Outline/OUTLINE_CONST"
    51.     }
    52.  
    53.     Fallback "VertexLit"
    54. }
     
    Last edited: Dec 18, 2014