Guest User

Cel-Diffuse.shader

a guest
Apr 1st, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. // By Tim Volp
  2. // Updated 02/04/15
  3.  
  4. Shader "Cel/Diffuse" {
  5. Properties {
  6. _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  7. _MainTex ("Base (RGB)", 2D) = "white" {}
  8. _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  9. _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
  10. _RimPower ("Rim Power", Float) = 1.4
  11. }
  12.  
  13. SubShader {
  14. Tags { "RenderType"="Opaque" }
  15. LOD 200
  16.  
  17. CGPROGRAM
  18. #pragma surface surf Cel
  19.  
  20. sampler2D _Ramp;
  21.  
  22. // Custom lighting model
  23. inline half4 LightingCel(SurfaceOutput s, half3 lightDir, half atten) {
  24. #ifndef USING_DIRECTIONAL_LIGHT
  25. lightDir = normalize(lightDir);
  26. #endif
  27.  
  28. // Calculate lighting from angle between normal and light direction
  29. half NdotL = saturate(dot(s.Normal, lightDir));
  30. // New lighting based on texture ramp
  31. half3 ramp = tex2D(_Ramp, half2(NdotL, 0.5));
  32.  
  33. half4 c;
  34. c.rgb = s.Albedo * _LightColor0.rgb * (atten * 2) * ramp;
  35. c.a = s.Alpha;
  36. return c;
  37. }
  38.  
  39. sampler2D _MainTex;
  40. half4 _Color;
  41. half4 _RimColor;
  42. half _RimPower;
  43.  
  44. struct Input {
  45. half2 uv_MainTex;
  46. half3 viewDir;
  47. };
  48.  
  49. void surf (Input IN, inout SurfaceOutput o) {
  50. // Calculate rim lighting from angle between normal and view direction
  51. half NdotV = saturate(dot(o.Normal, normalize(IN.viewDir)));
  52. // New lighting based on texture ramp
  53. half ramp = tex2D(_Ramp, half2(1.0 - NdotV, 0.5));
  54.  
  55. half4 c = tex2D(_MainTex, IN.uv_MainTex);
  56. o.Albedo = c.rgb * _Color;
  57. o.Alpha = c.a;
  58. o.Emission = _RimColor.rgb * pow(ramp, _RimPower);
  59. }
  60. ENDCG
  61. }
  62. FallBack "Diffuse"
  63. }
Advertisement
Add Comment
Please, Sign In to add comment