Search Unity

Shader Transparent

Discussion in 'Shaders' started by jpiera, Jul 29, 2019.

  1. jpiera

    jpiera

    Joined:
    Jun 10, 2019
    Posts:
    111
    Hello I want to do a shader to see the player when he is behind a object.For this objective I use a extra shader pass:
    Code (CSharp):
    1.     Pass {
    2.  
    3.             Tags
    4.             {
    5.                 "RenderType" = "Transparent"  "Queue" = "Transparent"
    6.             }
    7.              Blend One OneMinusSrcAlpha
    8.             ZWrite On
    9.             ZTest GEqual
    10.             CGPROGRAM
    11.             #pragma vertex vert
    12.             #pragma fragment frag
    13.  
    14.             #include "UnityCG.cginc"
    15.  
    16.             struct appdata
    17.             {
    18.                 float4 vertex : POSITION;
    19.                 float2 uv : TEXCOORD0;
    20.             };
    21.  
    22.             struct v2f
    23.             {
    24.                 float2 uv : TEXCOORD0;
    25.  
    26.                 float4 vertex : SV_POSITION;
    27.             };
    28.  
    29.             sampler2D _MainTex;
    30.             float4 _MainTex_ST;
    31.             float4 _PlayerColor;
    32.             v2f vert(appdata v)
    33.             {
    34.                 v2f o;
    35.                 o.vertex = UnityObjectToClipPos(v.vertex);
    36.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    37.  
    38.                 return o;
    39.             }
    40.  
    41.             fixed4 frag(v2f i) : SV_Target
    42.             {
    43.                 return _PlayerColor;
    44.             }
    45.             ENDCG
    46.             }
    Thats works great but I have a problem when I use alpha, I can see faces of another objects in my own player overlapping themselves(typical alfa ordering problem).How I can draw this pass like opaque figur and after apply alfa to this figur? or how I solve this problem?

    Thanks!