Advertisement
Guest User

ToonlitStencil.shader

a guest
Apr 19th, 2019
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Lit Stencil" {
  2.     Properties{
  3.         _Color("Main Color", Color) = (0.5,0.5,0.5,1)
  4.         _RampStrength("Ramp Strength", Range(0,1)) = 0.4
  5.         _MainTex("Base (RGB)", 2D) = "white" {}
  6.           _BumpMap("Bumpmap", 2D) = "bump" {}
  7.     }
  8.  
  9.         SubShader{
  10.             Tags { "RenderType" = "Opaque" }
  11.             LOD 200
  12.         Stencil
  13.             {
  14.                 Ref 1
  15.                 Comp Always
  16.                 Pass Replace
  17.             }
  18.             CGPROGRAM
  19.             #pragma surface surf ToonRamp fullforwardshadows
  20.  
  21.             sampler2D _Ramp;
  22.     float _RampStrength;
  23.     // custom lighting function that uses a texture ramp based
  24.     // on angle between light direction and normal
  25.     #pragma lighting ToonRamp exclude_path:prepass
  26.     inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten) {
  27.         #ifndef USING_DIRECTIONAL_LIGHT
  28.         lightDir = normalize(lightDir);
  29.         #endif
  30.  
  31.         half d = dot(s.Normal, lightDir);
  32.         half ramp = smoothstep(0,0.05, d) ;
  33.  
  34.         half4 c;
  35.         c.rgb = (s.Albedo ) * _LightColor0.rgb * (ramp * _RampStrength) * (atten * 2);
  36.        
  37.         c.a = 0;
  38.         return c;
  39.     }
  40.  
  41.     sampler2D _MainTex;
  42.     float4 _Color;
  43.     sampler2D _BumpMap;
  44.     struct Input {
  45.         float2 uv_MainTex : TEXCOORD0;
  46.         float2 uv_BumpMap;
  47.     };
  48.  
  49.     void surf(Input IN, inout SurfaceOutput o) {
  50.         half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  51.         o.Albedo = c.rgb;
  52.         o.Alpha = c.a;
  53.         o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
  54.     }
  55.  
  56.     ENDCG
  57.     }
  58.  
  59.         Fallback "Diffuse"
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement