Search Unity

How do I add transparency in this shader??

Discussion in 'Shaders' started by hizral, Jun 4, 2018.

  1. hizral

    hizral

    Joined:
    Apr 27, 2010
    Posts:
    568
    hello

    can anyone help me out on this shader, I would like to add transparency for this curve shader

    Code (CSharp):
    1. Shader "Custom/WorldCurve" {
    2.     Properties {
    3.       _MainTex("Base (RGB) Alpha (A)", 2D) = "white"
    4.   }
    5.     SubShader {
    6.         Tags { "RenderType"="Opaque" }
    7.         Pass
    8.         {
    9.             Lighting Off
    10.  
    11.             CGPROGRAM
    12.             #pragma vertex vert
    13.             #pragma fragment frag
    14.             #include "UnityCG.cginc"
    15.  
    16.             sampler2D _MainTex;      
    17.             float _CurvatureY;
    18.             float _CurvatureX;
    19.             float _Dist;
    20.             uniform float4 _MainTex_ST;
    21.            
    22.             struct v2f {
    23.                 float4 pos : SV_POSITION;
    24.                 float2 uv : TEXCOORD0;
    25.             };
    26.  
    27.             v2f vert (appdata_base v)
    28.             {
    29.                 v2f o;
    30.                 float4 vPos = mul (UNITY_MATRIX_MV, v.vertex);
    31.                 float zOff = vPos.z/_Dist;
    32.                 vPos += float4( (zOff * zOff) * - _CurvatureX, (zOff * zOff) * - _CurvatureY, 0.0f, 0.0f );
    33.                 o.pos = mul (UNITY_MATRIX_P, vPos);
    34.                 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    35.                 return o;
    36.             }
    37.  
    38.             half4 frag (v2f i) : COLOR
    39.             {
    40.               return tex2D(_MainTex, i.uv);
    41.             }
    42.             ENDCG
    43.         }
    44.     }
    45.     //FallBack "Mobil/Unlit"
    46. }
    Thank you.
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    https://docs.unity3d.com/Manual/SL-Blend.html

    Add the type of transparent blending you want above your CGPROGRAM, and make sure you're setting your return color's alpha in the fragment program. And change your RenderType and Queue to Transparent (you'll see examples on that page)