Advertisement
MinionsArt

Gradient Colormask Shader

Nov 17th, 2018
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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) = "black" {} // mask texture
  6.  
  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.         _Weight1("Primary: Gradient Placing", Range(-0.8,0.2)) = -0.2 // blend value with the original texture
  10.  
  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.         _Weight2("Secondary: Gradient Placing",  Range(-0.8,0.2)) = -0.2 // blend value with the original texture
  14.  
  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.         _Weight3("Tertiary: Gradient Placing",  Range(-0.8,0.2)) = -0.2 //// blend value with the original texture
  18.  
  19. }
  20.  
  21. SubShader{
  22.     Tags { "RenderType" = "Opaque" }
  23.     LOD 200
  24.     Cull Off
  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.  
  38.         #ifndef USING_DIRECTIONAL_LIGHT
  39.         lightDir = normalize(lightDir);
  40.         #endif
  41.  
  42.         float d = dot(s.Normal, lightDir);
  43.         float dChange = fwidth(d);
  44.         float3 lightIntensity = smoothstep(0, dChange + 0.03, d) + 0.4;//+ (_ToonRamp);
  45.  
  46.         half4 c;
  47.         c.rgb = s.Albedo * _LightColor0.rgb * (lightIntensity) * (atten * 2);
  48.        
  49.         c.a = 0;
  50.         return c;
  51.     }
  52.  
  53.  
  54.     sampler2D _MainTex;
  55.     sampler2D _Mask; // mask texture
  56.     float4 _Color, _ColorPrim1, _ColorPrim2, _ColorSec1, _ColorSec2, _ColorTert1, _ColorTert2;// custom colors
  57.     float _Weight1, _Weight2, _Weight3;// original texture blend values
  58.  
  59.     struct Input {
  60.         float2 uv_MainTex : TEXCOORD0;
  61.         float3 viewDir;
  62.     };
  63.  
  64.     void surf(Input IN, inout SurfaceOutput o) {
  65.         half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  66.         half3 m = tex2D(_Mask, IN.uv_MainTex); // mask based on the uvs
  67.         float3 PrimaryColor = lerp(_ColorPrim2, _ColorPrim1, saturate(IN.uv_MainTex.y + _Weight1)) * m.r;
  68.         float3 SecondaryColor = lerp(_ColorSec2, _ColorSec1, saturate(IN.uv_MainTex.y + _Weight2)) * m.g;
  69.         float3 TertiaryColor = lerp(_ColorTert2, _ColorTert1, saturate(IN.uv_MainTex.y + _Weight3)) * m.b;
  70.  
  71.         float3 NonMasked = c.rgb * saturate(1 - m.r - m.g - m.b); // the part of the model thats not affected by the colour customisation
  72.  
  73.         half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
  74.  
  75.         o.Albedo = NonMasked + PrimaryColor + SecondaryColor + TertiaryColor; // all parts added together form the new look for the model
  76.         o.Emission = pow(rim, 5)* 3 * o.Albedo;
  77.         o.Alpha = c.a;
  78.        
  79.     }
  80.     ENDCG
  81.  
  82.     }
  83.  
  84.         Fallback "Diffuse"
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement