Advertisement
Guest User

Untitled

a guest
Sep 14th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(Rim)]
  6.         _RimColor("Rim Color", Color) = (1,0.3,0.3,1)
  7.         _RimPower("Rim Power", Range(0, 20)) = 6
  8.             }
  9.  
  10.     SubShader {
  11.         Tags { "RenderType"="Opaque" }
  12.         LOD 200
  13.        
  14. CGPROGRAM
  15. #pragma surface surf ToonRamp vertex:vert
  16.  
  17. sampler2D _Ramp;
  18.  
  19. // custom lighting function that uses a texture ramp based
  20. // on angle between light direction and normal
  21. #pragma lighting ToonRamp exclude_path:prepass
  22. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
  23. {
  24.     #ifndef USING_DIRECTIONAL_LIGHT
  25.     lightDir = normalize(lightDir);
  26.     #endif
  27.    
  28.     half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  29.     half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  30.    
  31.     half4 c;
  32.     c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  33.     c.a = 0;
  34.     return c;
  35. }
  36.  
  37.  
  38. float4 _Color;
  39. float4 _RimColor;
  40. float _RimPower;
  41.  
  42. struct Input {
  43.     float2 uv_MainTex : TEXCOORD0;
  44.     float3 viewDir;
  45.     float3 lightDir;
  46. };
  47.  
  48.  void vert(inout appdata_full v, out Input o)
  49.     {
  50.         UNITY_INITIALIZE_OUTPUT(Input, o);
  51.         o.lightDir = WorldSpaceLightDir(v.vertex); // get the worldspace lighting direction
  52.     }
  53.  
  54.  
  55. void surf (Input IN, inout SurfaceOutput o) {
  56.     float3 baseAlbedo = _Color;// base color
  57.     o.Albedo = baseAlbedo;// result
  58.     half rim = 1- saturate(dot (normalize(IN.viewDir), o.Normal));// standard rim calculation  
  59.     o.Emission += _RimColor.rgb * pow(rim, _RimPower);// rim lighting added to glowing highlight
  60. }
  61. ENDCG
  62.  
  63.     }
  64.  
  65.     Fallback "Diffuse"
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement