Guest User

ColormaskGradient

a guest
Sep 21st, 2017
1,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. Shader "Toon/Lit ColorMask Gradient
  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. _ColorPrim1("Primary Color Top", Color) = (0.5,0.5,0.5,1) // primary color, replaces the red masked area
  8. _ColorPrim2("Primary Color Bottom", Color) = (0.5,0.5,0.5,1) // primary color, replaces the red masked area
  9. [Toggle] _Emis1("Primary: Emissive?", Float) = 0 // sets the color as emissive if toggled
  10. _Value1("Primary: Gradient Placing", Range(-1,2)) = 0.5 // blend value with the original texture
  11. _ColorSec1("Secondary Color Top", Color) = (0.5,0.5,0.5,1) // secondary color, replaces green masked area
  12. _ColorSec2("Secondary Color Bottom", Color) = (0.5,0.5,0.5,1) // secondary color, replaces green masked area
  13. [Toggle] _Emis2("Secondary: Emissive?", Float) = 0// sets the color as emissive if toggled
  14. _Value2("Secondary: Gradient Placing", Range(-1,2)) = 0.5// blend value with the original texture
  15. _ColorTert1("Tertiary Color Top", Color) = (0.5,0.5,0.5,1)// tertiary color, replaces blue masked area
  16. _ColorTert2("Tertiary Color Bottom", Color) = (0.5,0.5,0.5,1)// tertiary color, replaces blue masked area
  17. [Toggle] _Emis3("Tertiary: Emissive?", Float) = 0// sets the color as emissive if toggled
  18. _Value3("Tertiary: Gradient Placing", Range(-1,2)) = 0.5// blend value with the original texture
  19.  
  20. }
  21.  
  22. SubShader {
  23. Tags { "RenderType"="Opaque" }
  24. LOD 200
  25.  
  26.  
  27. CGPROGRAM
  28. #pragma surface surf ToonRamp
  29.  
  30. sampler2D _Ramp;
  31.  
  32. // custom lighting function that uses a texture ramp based
  33. // on angle between light direction and normal
  34. #pragma lighting ToonRamp exclude_path:prepass
  35. inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
  36. {
  37. #ifndef USING_DIRECTIONAL_LIGHT
  38. lightDir = normalize(lightDir);
  39. #endif
  40.  
  41. half d = dot (s.Normal, lightDir)*0.5 + 0.5;
  42. half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
  43.  
  44. half4 c;
  45. c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
  46. c.a = 0;
  47. return c;
  48. }
  49.  
  50.  
  51. sampler2D _MainTex;
  52. sampler2D _Mask; // mask texture
  53. float4 _Color, _ColorPrim1, _ColorPrim2, _ColorSec1, _ColorSec2, _ColorTert1, _ColorTert2;// custom colors
  54. float _Emis1, _Emis2, _Emis3; // emission toggles
  55. float _Value1, _Value2, _Value3;// original texture blend values
  56.  
  57. struct Input {
  58. float2 uv_MainTex : TEXCOORD0;
  59. };
  60.  
  61. void surf (Input IN, inout SurfaceOutput o) {
  62. half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  63. half4 m = tex2D(_Mask, IN.uv_MainTex); // mask based on the uvs
  64. float3 PrimaryColor = lerp(_ColorPrim2, _ColorPrim1, saturate(IN.uv_MainTex.y)) * m.r;
  65. float3 SecondaryColor = lerp(_ColorSec2, _ColorSec1, saturate(IN.uv_MainTex.y)) * m.g;
  66. float3 TertiaryColor = lerp(_ColorTert2, _ColorTert1, saturate(IN.uv_MainTex.y )) * m.b;
  67.  
  68. float3 NonMasked = c.rgb * (1 - m.r - m.g - m.b); // the part of the model thats not affected by the colour customisation
  69.  
  70. o.Albedo = NonMasked + PrimaryColor + SecondaryColor + TertiaryColor; // all parts added together form the new look for the model
  71. o.Emission = PrimaryColor * _Emis1 + SecondaryColor * _Emis2 + TertiaryColor * _Emis3; // emissive only shows up when the toggles for their colours are toggled
  72. o.Alpha = c.a;
  73. }
  74. ENDCG
  75.  
  76. }
  77.  
  78. Fallback "Diffuse"
  79. }
Advertisement
Add Comment
Please, Sign In to add comment