Guest User

ToonLitMetal

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