Guest User

ToonColorMask.shader

a guest
Sep 18th, 2017
1,490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. Shader "Toon/Lit ColorMask" {
  2. Properties {
  3. _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  4. _MainTex ("Base (RGB)", 2D) = "white" {}
  5. _Mask("ColorMask (Red = Prim Green = Sec Blue = Ter)", 2D) = "white" {} // mask texture
  6. _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
  7. _ColorPrim("Primary Color", Color) = (0.5,0.5,0.5,1) // primary color, replaces the red masked area
  8. [Toggle] _Emis1("Primary: Emissive?", Float) = 0 // sets the color as emissive if toggled
  9. _Value1("Primary: Blend Main Texture", Range(0,1)) = 0.5 // blend value with the original texture
  10. _ColorSec("Secondary Color", Color) = (0.5,0.5,0.5,1) // secondary color, replaces green masked area
  11. [Toggle] _Emis2("Secondary: Emissive?", Float) = 0// sets the color as emissive if toggled
  12. _Value2("Secondary: Blend Main Texture", Range(0,1)) = 0.5// blend value with the original texture
  13. _ColorTert("Tertiary Color", Color) = (0.5,0.5,0.5,1)// tertiary color, replaces blue masked area
  14. [Toggle] _Emis3("Tertiary: Emissive?", Float) = 0// sets the color as emissive if toggled
  15. _Value3("Tertiary: Blend Main Texture", Range(0,1)) = 0.5// blend value with the original texture
  16.  
  17. }
  18.  
  19. SubShader {
  20. Tags { "RenderType"="Opaque" }
  21. LOD 200
  22.  
  23.  
  24. CGPROGRAM
  25. #pragma surface surf ToonRamp
  26.  
  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. sampler2D _Mask; // mask texture
  50. float4 _Color, _ColorPrim, _ColorSec, _ColorTert;// custom colors
  51. float _Emis1, _Emis2, _Emis3; // emission toggles
  52. float _Value1, _Value2, _Value3;// original texture blend values
  53.  
  54. struct Input {
  55. float2 uv_MainTex : TEXCOORD0;
  56. };
  57.  
  58. void surf (Input IN, inout SurfaceOutput o) {
  59. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  60. half4 m = tex2D(_Mask, IN.uv_MainTex); // mask based on the uvs
  61. float3 PrimaryColor = _ColorPrim * m.r + ((c.rgb * _Value1) * m.r); // the 3 custom colours multiplied by the mask , so it only affects the masked areas,
  62. float3 SecondaryColor = _ColorSec * m.g + ((c.rgb * _Value2) * m.g); // also multiplied by the original texture based on a blend value slider
  63. float3 TertiaryColor = _ColorTert * m.b + ((c.rgb * _Value3) * m.b);
  64. float3 NonMasked = c.rgb * (1 - m.r - m.g - m.b); // the part of the model thats not affected by the colour customisation
  65.  
  66. o.Albedo = NonMasked + PrimaryColor + SecondaryColor + TertiaryColor; // all parts added together form the new look for the model
  67. o.Emission = PrimaryColor * _Emis1 + SecondaryColor * _Emis2 + TertiaryColor * _Emis3; // emissive only shows up when the toggles for their colours are toggled
  68. o.Alpha = c.a;
  69. }
  70. ENDCG
  71.  
  72. }
  73.  
  74. Fallback "Diffuse"
  75. }
Add Comment
Please, Sign In to add comment