Search Unity

Darkhog's awesome toon shader

Discussion in 'Shaders' started by darkhog, May 2, 2016.

  1. darkhog

    darkhog

    Joined:
    Dec 4, 2012
    Posts:
    2,218
    Was playing around with shaders trying to make flatshading shader and by accident came upon that cool way of doing sharp cel-shading (think 2d cartoons instead of something like ToyStory) without ramp textures. Maybe will be useful for someone. Releasing under CC-by-sa (have to mention me in the credits, otherwise do whatever you want, but if modified, release under same license)

    Code (csharp):
    1.  
    2. Shader "Darkhog/Awesome Toon Shader" {
    3.   Properties {
    4.   _MainTex ("Texture", 2D) = "white" {}
    5.   _Color ("Main Color", Color) = (1,1,1,1)
    6.   }
    7.   SubShader {
    8.   Tags { "RenderType" = "Opaque" }
    9.   CGPROGRAM
    10.   #pragma surface surf WonderToon
    11.  
    12.   half4 LightingWonderToon (SurfaceOutput s, half3 lightDir, half atten) {
    13.   half NdotL = round(dot (s.Normal, lightDir));
    14.   half4 c;
    15.   c.rgb = s.Albedo * _LightColor0.rgb * (NdotL * atten);
    16.   c.a = s.Alpha;
    17.   return c;
    18.   }
    19.  
    20.   struct Input {
    21.   float2 uv_MainTex;
    22.   };
    23.    
    24.   sampler2D _MainTex;
    25.   fixed4 _Color;
    26.    
    27.   void surf (Input IN, inout SurfaceOutput o) {
    28.   o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb*_Color;
    29.   }
    30.   ENDCG
    31.   }
    32.   Fallback "Diffuse"
    33.   }
    34.  
    upload_2016-5-2_15-19-59.png
    Shader in action. Obviously it would look better when model, textures and lighting are prepared for the thing, however in this case I don't have time to do it. Feel free to post screenshots with models/scenes made for this shader.
     
    Kin0min likes this.
  2. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649