Advertisement
Guest User

Cel-Bumped.shader

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