Advertisement
Guest User

ToonLitMetalNormal.shader

a guest
Sep 29th, 2018
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Lit Metal Normal" {
  2.     Properties {
  3.         _Color ("Base Color", Color) = (0.8,0.4,0.15,1)
  4.         _Ramp ("Toon Ramp (RGB)", 2D) = "white" {}
  5.         _Normal("Normal Map", 2D) = "bump" {}
  6.         [Header(Metal)]
  7.         _Brightness("Specular Brightness", Range(0, 2)) = 1.3  
  8.         _Offset("Specular Size", Range(0, 5)) = 0.8 //  
  9.         _SpecuColor("Specular Color", Color) = (0.8,0.45,0.2,1)
  10.         [Header(Highlight)]
  11.         _HighlightOffset("Highlight Size", Range(0, 5)) = 0.9  
  12.         _HiColor("Highlight Color", Color) = (1,1,1,1)
  13.         [Header(Rim)]
  14.         _RimColor("Rim Color", Color) = (1,0.3,0.3,1)
  15.         _RimPower("Rim Power", Range(0, 20)) = 6
  16.             }
  17.  
  18.     SubShader {
  19.         Tags { "RenderType"="Opaque" }
  20.         LOD 200
  21.        
  22. CGPROGRAM
  23. #pragma surface surf ToonRamp vertex:vert
  24. #pragma target 3.5
  25. sampler2D _Ramp;
  26.  
  27.     struct SurfaceOutputCustom {
  28.     fixed3 Albedo;
  29.     fixed3 Normal;
  30.     fixed3 Emission;
  31.     half Specular;
  32.     fixed Gloss;
  33.     fixed Alpha;
  34.     fixed3 Custom;
  35.     };
  36.  
  37. // custom lighting function that uses a texture ramp based
  38. // on angle between light direction and normal
  39. #pragma lighting ToonRamp exclude_path:prepass
  40. inline half4 LightingToonRamp (SurfaceOutputCustom s, half3 lightDir, half atten)
  41. {
  42.     #ifndef USING_DIRECTIONAL_LIGHT
  43.     lightDir = normalize(lightDir);
  44.     #endif
  45.        
  46.     half d = dot (s.Normal + s.Custom, lightDir)*0.5 + 0.5;
  47.     half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  48.    
  49.     half4 c;
  50.     c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  51.     c.a = 0;
  52.     return c;
  53. }
  54.  
  55.  
  56. float4 _Color;
  57. float _Offset;
  58. float4 _HiColor;
  59. float _HighlightOffset;
  60. float _Brightness;
  61. float4 _SpecuColor;
  62. float4 _RimColor;
  63. float _RimPower;
  64. sampler2D _Normal;
  65.  
  66.  
  67.  
  68. struct Input {
  69.     float2 uv_MainTex : TEXCOORD0;
  70.     float2 uv_Normal;
  71.     float3 viewDir;
  72.     float3 lightDir;
  73. };
  74.  
  75.  void vert(inout appdata_full v, out Input o)
  76.     {
  77.         UNITY_INITIALIZE_OUTPUT(Input, o);
  78.         o.lightDir = WorldSpaceLightDir(v.vertex); // get the worldspace lighting direction    
  79.     }
  80.  
  81.  
  82. void surf (Input IN, inout SurfaceOutputCustom o) {
  83.  
  84.     float3 nor = UnpackNormal(tex2D(_Normal, IN.uv_Normal));
  85.     float spec = dot(normalize(IN.viewDir) + IN.lightDir, o.Normal);// specular based on view and light direction
  86.     float cutOff = step(spec + nor, _Offset); // cutoff for where base color is
  87.     float3 baseAlbedo = _Color * cutOff;// base color
  88.     float3 specularAlbedo = _SpecuColor * (1-cutOff) * _Brightness;// inverted base cutoff times specular color
  89.     float highlight = dot(IN.lightDir, o.Normal); // highlight based on light direction
  90.     highlight =  step(_HighlightOffset,highlight + nor); //glowing highlight
  91.     float3 highlightAlbedo = highlight * _HiColor; //glowing highlight
  92.     o.Albedo = baseAlbedo + specularAlbedo  + highlightAlbedo;// result
  93.     half rim = 1- saturate(dot (normalize(IN.viewDir), o.Normal * nor));// standard rim calculation  
  94.     o.Emission += _RimColor.rgb * pow(rim, _RimPower);// rim lighting added to glowing highlight
  95.     o.Custom = nor;
  96.    
  97. }
  98. ENDCG
  99.  
  100.     }
  101.  
  102.     Fallback "Diffuse"
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement