Search Unity

Simplest transparent surface shader

Discussion in 'Shaders' started by SunnySunshine, Jul 4, 2015.

  1. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    I'm trying to learn more about surface shaders. Right now I'm trying to mimic the behavior of the standard transparent shader, but I can't get the transparency to work as desired. Even when the alpha is set to zero, there's still a strange gray being rendered.

    Code (CSharp):
    1. Shader "Custom/NewShader2" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    6.         _Metallic ("Metallic", Range(0,1)) = 0.0
    7.     }
    8.     SubShader {
    9.         Tags {"Queue"="Transparent" "RenderType"="Transparent"}
    10.         LOD 200
    11.        
    12.         CGPROGRAM
    13.         // Physically based Standard lighting model, and enable shadows on all light types
    14.         #pragma surface surf Standard alpha
    15.  
    16.         // Use shader model 3.0 target, to get nicer looking lighting
    17.         #pragma target 3.0
    18.  
    19.         sampler2D _MainTex;
    20.  
    21.         struct Input {
    22.             float2 uv_MainTex;
    23.         };
    24.  
    25.         half _Glossiness;
    26.         half _Metallic;
    27.         fixed4 _Color;
    28.  
    29.         void surf (Input IN, inout SurfaceOutputStandard o) {
    30.             // Albedo comes from a texture tinted by color
    31.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    32.             o.Albedo = c.rgb;
    33.             // Metallic and smoothness come from slider variables
    34.             o.Metallic = _Metallic;
    35.             o.Smoothness = _Glossiness;
    36.             o.Alpha = c.a;
    37.         }
    38.         ENDCG
    39.     }
    40.     FallBack "Diffuse"
    41. }
    What exactly is required to get it to behave as the default standard transparent shader?
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520