Search Unity

How to add Alpha to this Shader?

Discussion in 'Shaders' started by Cellenseres, Oct 17, 2017.

  1. Cellenseres

    Cellenseres

    Joined:
    Mar 30, 2015
    Posts:
    68
    Hey Guys,

    right now I'm working on a gameproject for a Hardware which has limited support for shaders.
    The following shaders are supported:
    Vertex Shaders, Fragment Shaders (Limited), This Unity version has vertex shader support based on OpenGL ES 2.0.

    Unsupported;
    Standard Shaders, Surface Shaders, Compute Shaders, Pixel Lighting, HDR Rendering, Linear Rendering, Image Effects

    Can someone help me with this shader?
    I want to add Alpha for the texture to this shader but I don't know how.
    I tried it with "Alpha Cutout" but it isn't supported on the hardware...

    Code (CSharp):
    1.  
    2. Shader "N3DS/DoubleSided/DoubleSided"
    3. {
    4. Properties
    5. {
    6.     _MainTex ("Base (RGB)", 2D) = "white" {}
    7. }
    8.  
    9. SubShader
    10. {
    11.     Tags { "Queue"="Transparent" "RenderType" = "Transparent" }
    12.     Cull Off
    13.     LOD 80
    14.  
    15.     // Non-lightmapped
    16.     Pass {
    17.         Tags { "LightMode" = "Vertex" }
    18.         Material
    19.         {
    20.             Diffuse (1,1,1,1)
    21.             Ambient (1,1,1,1)
    22.         }
    23.         Lighting On
    24.         SetTexture [_MainTex] {
    25.             constantColor (1,1,1,1)
    26.             Combine texture * primary DOUBLE, texture * primary
    27.         }
    28.     }
    29.  
    30.     // Lightmapped, encoded as dLDR
    31.     Pass
    32.      {
    33.         Tags { "LightMode" = "VertexLM" }
    34.         Cull Off
    35.  
    36.         BindChannels {
    37.             Bind "Vertex", vertex
    38.             Bind "normal", normal
    39.             Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
    40.             Bind "texcoord", texcoord1 // main uses 1st uv
    41.         }
    42.      
    43.         SetTexture [unity_Lightmap] {
    44.             matrix [unity_LightmapMatrix]
    45.             combine texture
    46.         }
    47.         SetTexture [_MainTex] {
    48.             constantColor (1,1,1,1)
    49.             combine texture * previous DOUBLE, texture * primary
    50.         }
    51.     }
    52.  
    53.     // Lightmapped, encoded as RGBM
    54.     Pass
    55.     {
    56.         Tags { "LightMode" = "VertexLMRGBM" }
    57.         Cull Off
    58.  
    59.         BindChannels {
    60.             Bind "Vertex", vertex
    61.             Bind "normal", normal
    62.             Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
    63.             Bind "texcoord", texcoord1 // main uses 1st uv
    64.         }
    65.      
    66.         SetTexture [unity_Lightmap] {
    67.             matrix [unity_LightmapMatrix]
    68.             combine texture * texture alpha DOUBLE
    69.         }
    70.         SetTexture [_MainTex] {
    71.             constantColor (1,1,1,1)
    72.             combine texture * previous QUAD, texture * primary
    73.         }
    74.     }
    75.  
    76.     // Pass to render object as a shadow caster
    77.     Pass
    78.     {
    79.         Name "ShadowCaster"
    80.         Tags { "LightMode" = "ShadowCaster" }
    81.         Cull Off
    82.         ZWrite On ZTest LEqual Cull Off
    83.  
    84.         CGPROGRAM
    85.         #pragma vertex vert
    86.         #pragma fragment frag
    87.         #pragma multi_compile_shadowcaster
    88.         #include "UnityCG.cginc"
    89.  
    90.         struct v2f {
    91.             V2F_SHADOW_CASTER;
    92.         };
    93.  
    94.         v2f vert( appdata_base v )
    95.         {
    96.             v2f o;
    97.             TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
    98.             return o;
    99.         }
    100.  
    101.         float4 frag( v2f i ) : SV_Target
    102.         {
    103.             SHADOW_CASTER_FRAGMENT(i)
    104.         }
    105.         ENDCG
    106.     }
    107. }
    108. }
    109.  
    On Hardware it looks like this:


    But it should look like this:
     
  2. Cellenseres

    Cellenseres

    Joined:
    Mar 30, 2015
    Posts:
    68