Search Unity

VertexLit Lightmapped ramped shader?

Discussion in 'Shaders' started by Graph, Aug 16, 2014.

  1. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    154
    Hey there,
    I'm currently working on a little project that requires some stylized rendering. For that purpose i mcGyvered myself a little shader out of what info i could find and my minimal shader knowledge :p

    Unfortunately tho on older devices the performance of that is not really good so i thought about going vertLit with lightmapping. The mobile VertexLit shader is a very good base of what what i'm after, unfortunately tho it's missing 2 aspects I'd require and those would be ramped/toon lighting of the lightmap data and rimLighting.

    Code (CSharp):
    1. Shader "Graph/ToonLit"
    2. {
    3.  
    4.     Properties
    5.     {
    6.         _Color ("FilterColor", Color) = (0.5, 0.5, 0.5, 0.5)
    7.    
    8.         _MainTex ("Albedo", 2D) = "white" {}
    9.  
    10.         _Ramp ("Toon Ramp", 2D) = "gray" {}
    11.  
    12.         _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
    13.         _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
    14.   }
    15.    
    16.     SubShader
    17.     {
    18.         Tags
    19.         {
    20.             "RenderType" = "Opaque"
    21.             "LightMode" = "VertexLM"
    22.         }
    23.  
    24.         LOD 200
    25.         CGPROGRAM
    26.             #pragma surface surf ToonRamp
    27.            
    28.                
    29.             sampler2D _MainTex;
    30.             fixed4 _Color;
    31.             sampler2D _Ramp;
    32.             float4 _RimColor;
    33.             float _RimPower;
    34.  
    35.  
    36.             struct Input
    37.             {
    38.                 float2 uv_MainTex : TEXCOORD0;
    39.                 float4 color: Color; // vert color
    40.                 float3 viewDir;
    41.             };
    42.  
    43.  
    44.             #pragma lighting ToonRamp exclude_path:prepass
    45.             inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
    46.             {
    47.                 #ifndef USING_DIRECTIONAL_LIGHT
    48.                 lightDir = normalize(lightDir);
    49.                 #endif
    50.    
    51.                 half NdotL = dot (s.Normal, lightDir);
    52.                 half diff = (NdotL * 0.5 + 0.5) *atten;
    53.  
    54.                 half3 ramp = tex2D (_Ramp, float2(diff, diff)).rgb;
    55.  
    56.                 half4 c;
    57.                 c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten *2);
    58.                 c.a = s.Alpha;
    59.  
    60.                 return c;
    61.             }
    62.  
    63.             void surf (Input IN, inout SurfaceOutput o)
    64.             {
    65.                 half4 c = tex2D(_MainTex, IN.uv_MainTex);
    66.  
    67.                 o.Albedo =  c.rgb * IN.color.rgb;
    68.                 o.Albedo *= (_Color.rgb + _Color.rgb);
    69.  
    70.                 o.Alpha = c.a * _Color.a;
    71.  
    72.                 half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
    73.                 o.Emission = _RimColor.rgb * pow (rim, _RimPower);
    74.             }
    75.             ENDCG
    76.         }
    77.     FallBack "Mobile/VertexLit"
    78. }
    This is my current shader.. now applying that to a lightmapped object with a vertLit rendering path the object disappears :confused: And i have no clue why.
    In case you're interested what project it's for: http://facebook.com/pages/Nark/686022421476229

    Any help would be greatly appreciated.