Search Unity

Surface Shader Issue

Discussion in 'Editor & General Support' started by MSong, Apr 1, 2015.

  1. MSong

    MSong

    Joined:
    Mar 30, 2015
    Posts:
    12
    Edit2: New Issue...

    Code (CSharp):
    1. Shader "Custom/WrapLambert" {
    2.     Properties {
    3.             _Alpha("Transparency", Range(0, 1.0)) = 1.0
    4.             _MainTex ("Color (RGB) Alpha (A)", 2D) = "white" {}
    5.             _RimColor("Rim Color", Color) = (0.26,0.19,0.16,0.0)
    6.             _RimPower("Rim Power", Range(0.5,8.0)) = 3.0
    7.             }
    8.         SubShader {
    9.         Tags { "RenderType"="Opaque"}
    10.     CGPROGRAM
    11.     #pragma surface surf WrapLambert alpha
    12.     #pragma target 3.0
    13.  
    14.     half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
    15.         half NdotL = dot (s.Normal, lightDir);
    16.         half diff = NdotL * 0.5 + 0.5;
    17.         half4 c;
    18.         c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
    19.         c.a = s.Alpha;
    20.         return c;
    21.     }
    22.  
    23.     struct Input {
    24.         float2 uv_MainTex;
    25.         float3 viewDir;
    26.     };
    27.  
    28.         sampler2D _MainTex;
    29.         float4 _RimColor;
    30.         float _RimPower;
    31.         half _Alpha;
    32.  
    33.         void surf (Input IN, inout SurfaceOutput o) {
    34.             o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    35.             o.Alpha = _Alpha;
    36.             half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
    37.             o.Emission = _RimColor.rgb * pow(rim, _RimPower);
    38.         }
    39.     ENDCG
    40.     }
    41.     Fallback "Diffuse"
    42. }
    43.  
    Why does this cause some of my models to disappear?? info2.png

    But if i add.. Queue" = "Transparent" to the Tags.. it works a little more, the gameObjects still disappear in certain spots while playing. Sigh I don't want to compromise - I wish it would just work :<.

    info3.png
     
    Last edited: Apr 1, 2015