SHARE
TWEET

ToonShaderReplace.shader

a guest Dec 17th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Toon/Character Replace" {
  2.     Properties{
  3.         _Color("Main Color", Color) = (0.5,0.5,0.5,1)
  4.         _MainTex("Base (RGB)", 2D) = "white" {}
  5.         _Offset("Toon Ramp Blur",  Range(0, 1)) = 0
  6.         _Mask("R = Emis, G = Spec", 2D) = "black" {}
  7.         _Matcap("Matcap", 2D) = "white" {}
  8.         _SpecTint("Spec Tint", Color) = (1,1,1,1)
  9.         _HitTint("Hit Tint", Color) = (1,1,1,1)
  10.         [PerRendererData] _Hit("Hit", Range(0, 1)) = 0 // hide in inspector
  11.         _Strength("Mask Strength", Range(0,2)) = 0.4
  12.     }
  13.  
  14.         SubShader{
  15.             Tags{ "RenderType" = "Opaque" "ThermalVision" = "ThermalColors"}
  16.             LOD 200
  17.             Cull Off
  18.  
  19.             CGPROGRAM
  20.  
  21.         #pragma surface surf ToonRamp fullforwardshadows addshadow
  22.  
  23.             float _Offset;
  24.  
  25.         // custom lighting function 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.             float d = dot(s.Normal, lightDir);
  34.             float3 lightIntensity = smoothstep(0 , fwidth(d) + _Offset , d);
  35.  
  36.             half4 c;
  37.             c.rgb = s.Albedo * _LightColor0.rgb * lightIntensity * (atten * 2);
  38.             c.a = s.Alpha;
  39.             return c;
  40.         }
  41.  
  42.  
  43.         sampler2D _MainTex;
  44.         float4 _Color, _HitTint;
  45.         sampler2D _Mask;
  46.         float4 _SpecTint;
  47.         float _Intensity;
  48.  
  49.         struct Input {
  50.             float2 uv_MainTex : TEXCOORD0;
  51.             float3 viewDir;
  52.         };
  53.  
  54.         // property blocks for hit effects
  55.         UNITY_INSTANCING_BUFFER_START(Props)
  56.             UNITY_DEFINE_INSTANCED_PROP(float, _Hit)
  57.         UNITY_INSTANCING_BUFFER_END(Props)
  58.  
  59.  
  60.         void surf(Input IN, inout SurfaceOutput o) {
  61.             // main texture
  62.             half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
  63.  
  64.             // effects mask
  65.             half4 e = tex2D(_Mask, IN.uv_MainTex);
  66.  
  67.             // spec
  68.             float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
  69.             float spec = dot(IN.viewDir, o.Normal);// specular based on view and light direction
  70.             float cutOff = step(saturate(spec), 0.8); // cutoff for where base color is
  71.             float3 specularMain = c.rgb * (1 - cutOff) * e.g * _SpecTint * 4;// inverted base cutoff times specular color
  72.  
  73.             // highlight
  74.             float highlight = saturate(dot(normalize(lightDir + (IN.viewDir * 0.5)), o.Normal)); // highlight based on light direction
  75.             float3 highlightMain = (step(0.9,highlight) * c.rgb *_SpecTint * 2) * e.g; //glowing highlight
  76.  
  77.             // rim
  78.             half rim = 1 - saturate(dot(normalize(IN.viewDir), o.Normal));// standard rim calculation  
  79.  
  80.            
  81.  
  82.             // emissive glow based on red channel
  83.             o.Emission = e.r * (c.rgb * 2);
  84.            
  85.  
  86.             // add a glow via the specular green channel as well
  87.             o.Emission += (pow(rim, 7) * e.g * c.rgb* _SpecTint );
  88.             // hit effect, power 2 is how much model is covered, higher number is less coverage
  89.             o.Emission += (pow(rim, 2) * (UNITY_ACCESS_INSTANCED_PROP(Props, _Hit) * 2 * _HitTint));
  90.  
  91.             // glow of dissolve
  92.             o.Emission += highlightMain;
  93.  
  94.            
  95.            
  96.             // final color
  97.             o.Albedo = c.rgb + specularMain;
  98.             // main rim
  99.             // rim on the lit side
  100.             float DotLight = dot(lightDir, o.Normal);
  101.             // blend with normal rim
  102.             float rimIntensity = rim * pow(DotLight, 0.1);
  103.             // cutoff
  104.             rimIntensity = smoothstep(0.7,fwidth(rimIntensity) + 0.7, rimIntensity);
  105.  
  106.             // add strong rim
  107.             o.Albedo += (rimIntensity * c.rgb);
  108.  
  109.  
  110.         }
  111.         ENDCG
  112.  
  113.         }
  114.  
  115.             Fallback "Diffuse"
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top