daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Jul 17th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Lit Specular" {
  2.     Properties {
  3.         _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  4.         _SColor("Specular Color", Color) = (0.5,0.5,0.5,1)
  5.         _MainTex ("Base (RGB)", 2D) = "white" {}
  6.         _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  7.         _RampS("Specular Ramp (RGB)", 2D) = "gray" {} // specular ramp, cutoff point
  8.         _SpecSize("Specular Size", Range(0.65,0.999)) = 0.9 // specular size
  9.             _SpecOffset("Specular Offset", Range(0.5,1)) = 0.5 // specular offset of the spec Ramp
  10.      _TColor("Gradient Overlay Top Color", Color) = (0.49,0.94,0.64,1)
  11.       _BottomColor("Gradient Overlay Bottom Color", Color) = (0.23,0,0.95,1)
  12.       _Offset("Gradient Offset", Range(-4,4)) = 3.2
  13.             [Toggle(RIM)] _RIM("Fresnel Rim?", Float) = 0
  14.             _RimColor("Fresnel Rim Color", Color) = (0.49,0.94,0.64,1)
  15.       [Toggle(FADE)] _FADE("Fade specular to bottom?", Float) = 0
  16.       _TopBottomOffset("Specular Fade Offset", Range(-4,4)) = 3.2
  17.     }
  18.  
  19.     SubShader {
  20.         Tags { "RenderType"="Opaque" }
  21.         LOD 200
  22.        
  23. CGPROGRAM
  24. #pragma surface surf ToonRamp vertex:vert
  25. #pragma shader_feature FADE
  26. #pragma shader_feature RIM
  27. sampler2D _Ramp;
  28.  
  29. // custom lighting function that uses a texture ramp based
  30. // on angle between light direction and normal
  31. #pragma lighting ToonRamp exclude_path:prepass
  32. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
  33. {
  34.     #ifndef USING_DIRECTIONAL_LIGHT
  35.     lightDir = normalize(lightDir);
  36.     #endif
  37.    
  38.     half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  39.     half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  40.    
  41.     half4 c;
  42.     c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  43.     c.a = 0;
  44.     return c;
  45. }
  46.  
  47.  
  48. sampler2D _MainTex;
  49. float4 _Color;
  50. float4 _SColor;
  51. sampler2D _RampS;
  52. float _SpecSize;
  53. float _SpecOffset;
  54. float4 _TColor;
  55. float4 _BottomColor;// bottom gradient color
  56. float _TopBottomOffset;
  57. float _Offset;
  58. float4 _RimColor;
  59.  
  60. struct Input {
  61.     float2 uv_MainTex : TEXCOORD0;
  62.     float3 lightDir;
  63.         float3 worldPos; // world position
  64.         float3 viewDir;
  65. };
  66.  
  67. void vert(inout appdata_full v, out Input o)
  68. {
  69.     UNITY_INITIALIZE_OUTPUT(Input, o);
  70.     o.lightDir = WorldSpaceLightDir(v.vertex);
  71. }
  72.  
  73. void surf (Input IN, inout SurfaceOutput o) {
  74.     float3 localPos = (IN.worldPos - mul(unity_ObjectToWorld, float4(0, 0, 0, 1)).xyz);// local position of the object, with an offset
  75.     half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  76.     half d = dot(o.Normal, IN.lightDir)*0.5 + _SpecOffset;
  77.     half3 rampS = tex2D(_RampS, float2(d, d)).rgb;
  78.    
  79.     float rim = 1 - saturate(dot(IN.viewDir, o.Normal));
  80. #if RIM
  81.     o.Emission = _RimColor.rgb * pow(rim, 1.5);
  82. #endif
  83.     o.Albedo = (step(_SpecSize, rampS.r)) * rampS * d* _SColor;
  84.     #if FADE
  85.    
  86.             o.Albedo = (step(_SpecSize, rampS.r)) * rampS * d* saturate(localPos.y + _TopBottomOffset) * _SColor ;
  87.            
  88.     #endif
  89.     o.Albedo += c.rgb*lerp(_BottomColor, _TColor, saturate(localPos.y + _Offset)) * 1.1;
  90.     o.Alpha = c.a;
  91. }
  92. ENDCG
  93.  
  94.     }
  95.  
  96.     Fallback "Diffuse"
  97. }
RAW Paste Data
Top