Search Unity

Team Fortress 2 Shader FIX

Discussion in 'Shaders' started by CyberArtist, Oct 24, 2015.

  1. CyberArtist

    CyberArtist

    Joined:
    May 31, 2014
    Posts:
    25
    For those who are trying to use the Team Fortress 2 Shader for Unity, I was able to fix the "incorrect number of arguments" error.

    Here's the code below:
    Code (CSharp):
    1. Shader "Toon/Team Fortress 2" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _RimColor ("Rim Color", Color) = (0.97,0.88,1,0.75)
    5.         _RimPower ("Rim Power", Float) = 2.5
    6.         _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "white" {}
    7.         _BumpMap ("Normal (Normal)", 2D) = "bump" {}
    8.         _SpecularTex ("Specular Level (R) Gloss (G) Rim Mask (B)", 2D) = "gray" {}
    9.         _RampTex ("Toon Ramp (RGB)", 2D) = "white" {}
    10.         _Cutoff ("Alphatest Cutoff", Range(0, 1)) = 0.5
    11.     }
    12.  
    13.     SubShader{
    14.         Tags { "RenderType" = "Opaque" }
    15.      
    16.         CGPROGRAM
    17.             #pragma surface surf TF2 alphatest:_Cutoff
    18.             #pragma target 3.0
    19.  
    20.             struct Input
    21.             {
    22.                 float2 uv_MainTex;
    23.                 float3 worldNormal;
    24.                 INTERNAL_DATA
    25.             };
    26.          
    27.             sampler2D _MainTex, _SpecularTex, _BumpMap, _RampTex;
    28.             float4 _RimColor;
    29.             float _RimPower;
    30.  
    31.             inline fixed4 LightingTF2 (SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten)
    32.             {
    33.                 fixed3 h = normalize (lightDir + viewDir);
    34.  
    35.                 fixed NdotL = dot(s.Normal, lightDir) * 0.5 + 0.5;
    36.                 fixed d = NdotL * atten;
    37.                 fixed3 ramp = tex2D(_RampTex, float2(d,d)).rgb;
    38.              
    39.                 float nh = max (0, dot (s.Normal, h));
    40.                 float spec = pow (nh, s.Gloss * 128) * s.Specular;
    41.              
    42.                 fixed4 c;
    43.                 c.rgb = ((s.Albedo * ramp * _LightColor0.rgb + _LightColor0.rgb * spec) * (atten * 2));
    44.                 c.a = s.Alpha;
    45.                 return c;
    46.             }
    47.  
    48.             void surf (Input IN, inout SurfaceOutput o)
    49.             {
    50.                 o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
    51.                 o.Alpha = tex2D(_MainTex, IN.uv_MainTex).a;
    52.                 o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_MainTex));
    53.                 float3 specGloss = tex2D(_SpecularTex, IN.uv_MainTex).rgb;
    54.                 o.Specular = specGloss.r;
    55.                 o.Gloss = specGloss.g;
    56.              
    57.                 half3 rim = pow(max(0, dot(float3(0, 1, 0), WorldNormalVector (IN, o.Normal))), _RimPower) * _RimColor.rgb * _RimColor.a * specGloss.b;
    58.                 o.Emission = rim;
    59.             }
    60.         ENDCG
    61.     }
    62.     Fallback "Transparent/Cutout/Bumped Specular"
    63. }
    Let me know what you think. :)