Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax.
  2.  
  3. // Toony Colors Pro+Mobile 2
  4. // (c) 2014-2018 Jean Moreno
  5.  
  6. Shader "Toony Colors Pro 2/User/2DToon"
  7. {
  8.     Properties
  9.     {
  10.     [TCP2HeaderHelp(BASE, Base Properties)]
  11.         //TOONY COLORS
  12.         _Color ("Color", Color) = (1,1,1,1)
  13.         _HColor ("Highlight Color", Color) = (0.785,0.785,0.785,1.0)
  14.         _SColor ("Shadow Color", Color) = (0.195,0.195,0.195,1.0)
  15.  
  16.         //DIFFUSE
  17.         _MainTex ("Main Texture", 2D) = "white" {}
  18.     [TCP2Separator]
  19.  
  20.         //TOONY COLORS RAMP
  21.         [TCP2Header(RAMP SETTINGS)]
  22.  
  23.         _RampThreshold ("Ramp Threshold", Range(0,1)) = 0.5
  24.         _RampSmooth ("Ramp Smoothing", Range(0.001,1)) = 0.1
  25.     [TCP2Separator]
  26.  
  27.     [TCP2HeaderHelp(NORMAL MAPPING, Normal Bump Map)]
  28.         //BUMP
  29.         _BumpMap ("Normal map (RGB)", 2D) = "bump" {}
  30.     [TCP2Separator]
  31.  
  32.     [TCP2HeaderHelp(TRANSPARENCY)]
  33.         //Alpha Testing
  34.         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  35.     [TCP2Separator]
  36.  
  37.  
  38.         //Avoid compile error if the properties are ending with a drawer
  39.         [HideInInspector] __dummy__ ("unused", Float) = 0
  40.     }
  41.  
  42.     SubShader
  43.     {
  44.  
  45.         Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  46.         Cull Off
  47.  
  48.         CGPROGRAM
  49.  
  50.         #pragma surface surf ToonyColorsCustom  exclude_path:deferred exclude_path:prepass
  51.         #pragma target 3.0
  52.  
  53.         //================================================================
  54.         // VARIABLES
  55.  
  56.         fixed4 _Color;
  57.         sampler2D _MainTex;
  58.         sampler2D _BumpMap;
  59.         fixed _Cutoff;
  60.  
  61.         struct Input
  62.         {
  63.             half2 uv_MainTex;
  64.             half2 uv_BumpMap;
  65.         };
  66.  
  67.         //================================================================
  68.         // CUSTOM LIGHTING
  69.  
  70.         //Lighting-related variables
  71.         fixed4 _HColor;
  72.         fixed4 _SColor;
  73.         half _RampThreshold;
  74.         half _RampSmooth;
  75.  
  76.         // Instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
  77.         // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
  78.         // #pragma instancing_options assumeuniformscaling
  79.         UNITY_INSTANCING_BUFFER_START(Props)
  80.             // put more per-instance properties here
  81.         UNITY_INSTANCING_BUFFER_END(Props)
  82.  
  83.         //Custom SurfaceOutput
  84.         struct SurfaceOutputCustom
  85.         {
  86.             half atten;
  87.             fixed3 Albedo;
  88.             fixed3 Normal;
  89.             fixed3 Emission;
  90.             half Specular;
  91.             fixed Gloss;
  92.             fixed Alpha;
  93.         };
  94.  
  95.         inline half4 LightingToonyColorsCustom (inout SurfaceOutputCustom s, half3 viewDir, UnityGI gi)
  96.         {
  97.         #define IN_NORMAL s.Normal
  98.    
  99.             half3 lightDir = gi.light.dir;
  100.         #if defined(UNITY_PASS_FORWARDBASE)
  101.             half3 lightColor = _LightColor0.rgb;
  102.             half atten = s.atten;
  103.         #else
  104.             half3 lightColor = gi.light.color.rgb;
  105.             half atten = 1;
  106.         #endif
  107.  
  108.             IN_NORMAL = normalize(IN_NORMAL);
  109.             fixed ndl = max(0, dot(IN_NORMAL, lightDir));
  110.             #define NDL ndl
  111.  
  112.             #define     RAMP_THRESHOLD  _RampThreshold
  113.             #define     RAMP_SMOOTH     _RampSmooth
  114.  
  115.             fixed3 ramp = smoothstep(RAMP_THRESHOLD - RAMP_SMOOTH*0.5, RAMP_THRESHOLD + RAMP_SMOOTH*0.5, NDL);
  116.         #if !(POINT) && !(SPOT)
  117.             ramp *= atten;
  118.         #endif
  119.         #if !defined(UNITY_PASS_FORWARDBASE)
  120.             _SColor = fixed4(0,0,0,1);
  121.         #endif
  122.             _SColor = lerp(_HColor, _SColor, _SColor.a);    //Shadows intensity through alpha
  123.             ramp = lerp(_SColor.rgb, _HColor.rgb, ramp);
  124.             fixed4 c;
  125.             c.rgb = s.Albedo * lightColor.rgb * ramp;
  126.             c.a = s.Alpha;
  127.  
  128.         #ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT
  129.             c.rgb += s.Albedo * gi.indirect.diffuse;
  130.         #endif
  131.  
  132.             return c;
  133.         }
  134.  
  135.         void LightingToonyColorsCustom_GI(inout SurfaceOutputCustom s, UnityGIInput data, inout UnityGI gi)
  136.         {
  137.             gi = UnityGlobalIllumination(data, 1.0, IN_NORMAL);
  138.  
  139.             s.atten = data.atten;   //transfer attenuation to lighting function
  140.             gi.light.color = _LightColor0.rgb;  //remove attenuation
  141.         }
  142.  
  143.         //================================================================
  144.         // SURFACE FUNCTION
  145.  
  146.         void surf(Input IN, inout SurfaceOutputCustom o)
  147.         {
  148.             fixed4 mainTex = tex2D(_MainTex, IN.uv_MainTex);
  149.             o.Albedo = mainTex.rgb * _Color.rgb;
  150.             o.Alpha = mainTex.a * _Color.a;
  151.    
  152.             //Cutout (Alpha Testing)
  153.             clip (o.Alpha - _Cutoff);
  154.  
  155.             //Normal map
  156.             half4 normalMap = tex2D(_BumpMap, IN.uv_BumpMap.xy);
  157.             o.Normal = UnpackNormal(normalMap);
  158.         }
  159.  
  160.         ENDCG
  161.     }
  162.  
  163.     Fallback "Diffuse"
  164.     CustomEditor "TCP2_MaterialInspector_SG"
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement