Advertisement
dnnkeeper

TGP_Include.cginc +deferred

Oct 20th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. // Toony Colors Pro+Mobile Shaders
  2. // (c) 2013,2014 Jean Moreno
  3.  
  4. #ifndef TOONYCOLORS_INCLUDED
  5.     #define TOONYCOLORS_INCLUDED
  6.    
  7.     //Lighting Ramp
  8.     sampler2D _Ramp;
  9.    
  10.     //Highlight/Shadow Colors
  11.     fixed4 _Color;
  12.     fixed4 _SColor;
  13.    
  14. #endif
  15.  
  16. // TOONY COLORS
  17. #pragma lighting ToonRamp exclude_path:prepass
  18. inline half4 LightingToonyColors (SurfaceOutput s, half3 lightDir, half atten)
  19. {
  20.     #ifndef USING_DIRECTIONAL_LIGHT
  21.         lightDir = normalize(lightDir);
  22.     #endif
  23.    
  24.     //Ramp shading
  25.     fixed ndl = dot(s.Normal, lightDir)*0.5 + 0.5;
  26.     fixed3 ramp = tex2D(_Ramp, fixed2(ndl,ndl));
  27.    
  28.     //Gooch shading
  29.     ramp = lerp(_SColor,_Color,ramp);
  30.    
  31.     fixed4 c;
  32.     c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  33.     c.a = s.Alpha;
  34.    
  35.     return c;
  36. }
  37.  
  38. // TOONY COLORS + SPECULAR
  39. #pragma lighting ToonRamp exclude_path:prepass
  40. inline half4 LightingToonyColorsSpec (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
  41. {
  42.     fixed diff = max (0, dot (s.Normal, lightDir)*0.5 + 0.5);
  43.    
  44.     //Ramp shading
  45.     fixed3 ramp = tex2D(_Ramp, fixed2(diff,diff));
  46.    
  47.     //Gooch shading
  48.     ramp = lerp(_SColor,_Color,ramp);
  49.    
  50.     //Specular
  51.     half3 h = normalize (lightDir + viewDir);
  52.     float ndh = max (0, dot (s.Normal, h));
  53.     float spec = pow (ndh, s.Specular*128.0) * s.Gloss;
  54.    
  55.     fixed4 c;
  56.     c.rgb = (s.Albedo * _LightColor0.rgb * ramp + _LightColor0.rgb * _SpecColor.rgb * spec) * ( atten * 2);
  57.     c.a = s.Alpha + _LightColor0.a * _SpecColor.a * spec * atten;
  58.    
  59.     return c;
  60. }
  61.  
  62. inline fixed4 LightingToonyColorsDeferred_PrePass (SurfaceOutput s, half4 light)
  63. {
  64.     half spec = light.a * s.Gloss;
  65.     half d = Luminance(light.rgb)*0.5+0.5;
  66.     half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  67.     ramp = lerp(_SColor,_Color,ramp);
  68.    
  69.     half4 c;
  70.     c.rgb = (s.Albedo * light.rgb * ramp + light.rgb * _SpecColor.rgb * spec);
  71.     c.a = s.Alpha + spec * _SpecColor.a;
  72.     return c;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement