Guest User

ToonLitSpecularVertexColor.shader

a guest
Aug 29th, 2018
445
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Lit Specular Vertex" {
  2. Properties{
  3.  
  4. [Header(Main)]
  5. _Color("Main Color", Color) = (1,1,1,1)
  6. _MainTex("Base (RGB)", 2D) = "white" {}
  7. _Ramp("Toon Ramp (RGB)", 2D) = "gray" {}
  8. [Space]
  9. [Header(Specular)]
  10. _SColor("Specular Color", Color) = (1,1,1,1)
  11. _RampS("Specular Ramp (RGB)", 2D) = "gray" {} // specular ramp, cutoff point
  12. _SpecSize("Specular Size", Range(0.65,0.999)) = 0.9 // specular size
  13. _SpecOffset("Specular Offset", Range(0,1)) = 0.5 // specular offset of the spec Ramp
  14. [Space]
  15. [Header(Rim Light)]
  16. _RimColor("Fresnel Rim Color", Color) = (0.49,0.94,0.64,1)
  17. _RimPower("Rim Power", Range(0,20)) = 3.2
  18. }
  19.  
  20. SubShader{
  21. Tags{ "RenderType" = "Opaque" }
  22. LOD 200
  23.  
  24. CGPROGRAM
  25. #pragma surface surf ToonRamp vertex:vert
  26. sampler2D _Ramp;
  27.  
  28. // custom lighting function that uses a texture ramp based
  29. // on angle between light direction and normal
  30. #pragma lighting ToonRamp exclude_path:prepass
  31. inline half4 LightingToonRamp(SurfaceOutput s, half3 lightDir, half atten)
  32. {
  33. #ifndef USING_DIRECTIONAL_LIGHT
  34. lightDir = normalize(lightDir);
  35. #endif
  36. half d = dot(s.Normal, lightDir)*0.5 + 0.5;
  37. half3 ramp = tex2D(_Ramp, float2(d,d)).rgb;
  38. half4 c;
  39. c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  40. c.a = 0;
  41. return c;
  42. }
  43.  
  44. sampler2D _MainTex;
  45. float4 _Color, _SColor, _RimColor;
  46. sampler2D _RampS; // specular ramp
  47. float _SpecSize; // specular size
  48. float _SpecOffset; // offset specular ramp
  49. float _RimPower; // gradient bottom offset
  50.  
  51. struct Input {
  52. float2 uv_MainTex : TEXCOORD0;
  53. float3 lightDir;
  54. float3 viewDir;
  55. float4 vertexColor: COLOR; // vertex color
  56. };
  57.  
  58. void vert(inout appdata_full v, out Input o)
  59. {
  60. UNITY_INITIALIZE_OUTPUT(Input, o);
  61. o.lightDir = WorldSpaceLightDir(v.vertex); // get the worldspace lighting direction
  62. }
  63.  
  64. void surf(Input IN, inout SurfaceOutput o) {
  65.  
  66. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; // main texture
  67. half d = dot(o.Normal, IN.lightDir + IN.viewDir) + _SpecOffset; // basing on normal and light direction
  68. half3 rampS = tex2D(_RampS, float2(d, d)).rgb; // specular ramp
  69. float rim = 1 - saturate(dot(IN.viewDir, o.Normal)); // calculate fresnel rim
  70. o.Emission = _RimColor.rgb * pow(rim, _RimPower) * IN.vertexColor.r; // fresnel rim
  71. float3 spec = ((step(_SpecSize, rampS.r)) * rampS * d* _SColor) * IN.vertexColor.r; // specular
  72. o.Albedo = c.rgb + spec; // multiply color by gradient lerp
  73. o.Alpha = c.a;
  74. }
  75. ENDCG
  76.  
  77. }
  78.  
  79. Fallback "Diffuse"
  80. }
RAW Paste Data