Guest User

ToonStencilMasked

a guest
Oct 9th, 2017
3,909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. Shader "Toon/Lit StencilMask" {
  2. Properties {
  3. _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  4. _MainTex ("Base (RGB)", 2D) = "white" {}
  5. _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  6. _ID("Mask ID", Int) = 1
  7.  
  8. }
  9.  
  10. SubShader {
  11. Tags { "RenderType"="Opaque" "Queue" = "Geometry+2"}
  12. LOD 200
  13.  
  14. Stencil {
  15. Ref [_ID]
  16. Comp equal
  17. }
  18.  
  19.  
  20. CGPROGRAM
  21. #pragma surface surf ToonRamp
  22.  
  23. sampler2D _Ramp;
  24.  
  25. // custom lighting function that uses a texture ramp based
  26. // on angle between light direction and normal
  27. #pragma lighting ToonRamp exclude_path:prepass
  28. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
  29. {
  30. #ifndef USING_DIRECTIONAL_LIGHT
  31. lightDir = normalize(lightDir);
  32. #endif
  33.  
  34. half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  35. half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  36.  
  37. half4 c;
  38. c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  39. c.a = 0;
  40. return c;
  41. }
  42.  
  43.  
  44. sampler2D _MainTex;
  45. float4 _Color;
  46.  
  47. struct Input {
  48. float2 uv_MainTex : TEXCOORD0;
  49. };
  50.  
  51. void surf (Input IN, inout SurfaceOutput o) {
  52. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  53. o.Albedo = c.rgb;
  54. o.Alpha = c.a;
  55. }
  56. ENDCG
  57.  
  58. }
  59.  
  60. Fallback "Diffuse"
  61. }
Add Comment
Please, Sign In to add comment