Shader "PRD/FriendsShaderV2"
{
  Properties
  {
    [Enum(OFF,0,FRONT,1,BACK,2)] _CullMode ("Cull Mode", float) = 2
    _BaseMap ("BaseMap", 2D) = "white" {}
    _BaseColor ("BaseColor", Color) = (1,1,1,1)
    [MaterialToggle] _Is_LightColor_Base ("Is_LightColor_Base", float) = 1
    _1st_ShadeMap ("1st_ShadeMap", 2D) = "white" {}
    _1st_ShadeColor ("1st_ShadeColor", Color) = (0.9019,0.7843,0.7843,1)
    [MaterialToggle] _Is_LightColor_1st_Shade ("Is_LightColor_1st_Shade", float) = 1
    [MaterialToggle] _Set_SystemShadowsToBase ("Set_SystemShadowsToBase", float) = 1
    _Tweak_SystemShadowsLevel ("Tweak_SystemShadowsLevel", Range(-0.5, 0.5)) = 0.2
    _BaseColor_Step ("BaseColor_Step", Range(0, 1)) = 0.42
    _BaseShade_Feather ("Base/Shade_Feather", Range(0.0001, 1)) = 0.0001
    [MaterialToggle] _RimLight ("RimLight", float) = 0
    _RimLightColor ("RimLightColor", Color) = (1,1,1,1)
    [MaterialToggle] _Is_LightColor_RimLight ("Is_LightColor_RimLight", float) = 1
    _RimLight_Power ("RimLight_Power", Range(0, 1)) = 0.1
    _RimLight_InsideMask ("RimLight_InsideMask", Range(0.0001, 1)) = 0.0001
    [MaterialToggle] _RimLight_FeatherOff ("RimLight_FeatherOff", float) = 0
    _Outline_Width ("Outline_Width", float) = 2
    _Farthest_Distance ("Farthest_Distance", float) = 10
    _Nearest_Distance ("Nearest_Distance", float) = 0.5
    _Outline_Color ("Outline_Color", Color) = (0.196,0.1176,0.1176,1)
  }
  SubShader
  {
    Tags
    { 
      "RenderType" = "Opaque"
    }
    Pass // ind: 1, name: Outline
    {
      Name "Outline"
      Tags
      { 
        "RenderType" = "Opaque"
      }
      Cull Front
      // m_ProgramMask = 6
      CGPROGRAM
      //#pragma target 4.0
      
      #pragma vertex vert
      #pragma fragment frag
      
      #include "UnityCG.cginc"
      #define conv_mxt4x4_3(mat4x4) float4(mat4x4[0].w,mat4x4[1].w,mat4x4[2].w,mat4x4[3].w)
      
      
      #define CODE_BLOCK_VERTEX
      //uniform float3 _WorldSpaceCameraPos;
      //uniform float4x4 unity_ObjectToWorld;
      //uniform float4x4 unity_MatrixVP;
      uniform float _Outline_Width;
      uniform float _Farthest_Distance;
      uniform float _Nearest_Distance;
      uniform float4 _Outline_Color;
      uniform float _Alpha;
      uniform float _Camouflage;
      struct appdata_t
      {
          float4 color :COLOR0;
          float4 vertex :POSITION0;
          float3 normal :NORMAL0;
      };
      
      struct OUT_Data_Vert
      {
          float4 vertex :SV_POSITION;
      };
      
      struct v2f
      {
          float4 vertex :Position;
      };
      
      struct OUT_Data_Frag
      {
          float4 color :SV_Target0;
      };
      
      float4 u_xlat0;
      float4 u_xlat1;
      float u_xlat16_1;
      float u_xlat2;
      int u_xlatb2;
      float u_xlat4;
      OUT_Data_Vert vert(appdata_t in_v)
      {
          OUT_Data_Vert out_v;
          u_xlat0.xyz = ((-_WorldSpaceCameraPos.xyz) + conv_mxt4x4_3(unity_ObjectToWorld).xyz);
          u_xlat0.x = length(u_xlat0.xyz);
          u_xlat0.x = (u_xlat0.x + (-_Nearest_Distance));
          u_xlat2 = ((-_Nearest_Distance) + _Farthest_Distance);
          u_xlat2 = (float(1) / u_xlat2);
          u_xlat0.x = (u_xlat2 * u_xlat0.x);
          u_xlat0.x = clamp(u_xlat0.x, 0, 1);
          u_xlat2 = ((u_xlat0.x * (-2)) + 3);
          u_xlat0.x = (u_xlat0.x * u_xlat0.x);
          u_xlat0.x = ((u_xlat2 * u_xlat0.x) + 1);
          u_xlatb2 = (in_v.color.x>=1);
          u_xlat4 = ((-in_v.color.y) + 1);
          u_xlat16_1 = (u_xlatb2)?(1):(u_xlat4);
          u_xlat2 = (u_xlat16_1 * _Outline_Width);
          u_xlat2 = (u_xlat2 * 0.00100000005);
          u_xlat0.x = (u_xlat0.x * u_xlat2);
          u_xlat0.xyz = ((in_v.normal.xyz * u_xlat0.xxx) + in_v.vertex.xyz);
          u_xlat0 = UnityObjectToClipPos(u_xlat0);
          out_v.vertex = (u_xlat0 + float4(0, 0, 9.99999972E-10, 0));
          return out_v;
      }
      
      #define CODE_BLOCK_FRAGMENT
      float u_xlat0_d;
      int u_xlatb0;
      float u_xlat1_d;
      int u_xlatb1;
      OUT_Data_Frag frag(v2f in_f)
      {
          OUT_Data_Frag out_f;
          u_xlatb0 = (_Outline_Width<0);
          if(((int(u_xlatb0) * (-1))!=0))
          {
              discard;
          }
          u_xlat0_d = ((-_Camouflage) + 1);
          u_xlat0_d = (u_xlat0_d * _Alpha);
          u_xlatb1 = (0.649999976>=_Camouflage);
          u_xlat1_d = (u_xlatb1)?(1):(float(0));
          out_f.color.w = (u_xlat1_d * u_xlat0_d);
          out_f.color.xyz = _Outline_Color.xyz;
          return out_f;
      }
      
      
      ENDCG
      
    } // end phase
    Pass // ind: 2, name: FORWARD
    {
      Name "FORWARD"
      Tags
      { 
        "LIGHTMODE" = "FORWARDBASE"
        "RenderType" = "Opaque"
        "SHADOWSUPPORT" = "true"
      }
      Cull Off
      // m_ProgramMask = 6
      CGPROGRAM
      #pragma multi_compile DIRECTIONAL
      //#pragma target 4.0
      
      #pragma vertex vert
      #pragma fragment frag
      
      #include "UnityCG.cginc"
      #define conv_mxt4x4_0(mat4x4) float4(mat4x4[0].x,mat4x4[1].x,mat4x4[2].x,mat4x4[3].x)
      #define conv_mxt4x4_1(mat4x4) float4(mat4x4[0].y,mat4x4[1].y,mat4x4[2].y,mat4x4[3].y)
      #define conv_mxt4x4_2(mat4x4) float4(mat4x4[0].z,mat4x4[1].z,mat4x4[2].z,mat4x4[3].z)
      #define conv_mxt4x4_3(mat4x4) float4(mat4x4[0].w,mat4x4[1].w,mat4x4[2].w,mat4x4[3].w)
      
      
      #define CODE_BLOCK_VERTEX
      //uniform float4 _ProjectionParams;
      //uniform float4x4 unity_ObjectToWorld;
      //uniform float4x4 unity_WorldToObject;
      //uniform float4x4 unity_MatrixVP;
      //uniform float3 _WorldSpaceCameraPos;
      //uniform float4 _WorldSpaceLightPos0;
      uniform float4 _LightColor0;
      uniform float4 _1st_ShadeColor;
      uniform float _BaseColor_Step;
      uniform float4 _BaseColor;
      uniform float _Set_SystemShadowsToBase;
      uniform float _BaseShade_Feather;
      uniform float _RimLight;
      uniform float _RimLight_Power;
      uniform float4 _RimLightColor;
      uniform float4 _BaseMap_ST;
      uniform float4 _1st_ShadeMap_ST;
      uniform float _Is_LightColor_Base;
      uniform float _Is_LightColor_1st_Shade;
      uniform float _Is_LightColor_RimLight;
      uniform float _Tweak_SystemShadowsLevel;
      uniform float _RimLight_InsideMask;
      uniform float _RimLight_FeatherOff;
      uniform float _Alpha;
      uniform float _Camouflage;
      uniform sampler2D _BaseMap;
      uniform sampler2D _1st_ShadeMap;
      struct appdata_t
      {
          float4 color :COLOR0;
          float4 vertex :POSITION0;
          float3 normal :NORMAL0;
          float2 texcoord :TEXCOORD0;
      };
      
      struct OUT_Data_Vert
      {
          float2 texcoord :TEXCOORD0;
          float texcoord3 :TEXCOORD3;
          float4 texcoord1 :TEXCOORD1;
          float3 texcoord2 :TEXCOORD2;
          float4 vertex :SV_POSITION;
      };
      
      struct v2f
      {
          float2 texcoord :TEXCOORD0;
          float texcoord3 :TEXCOORD3;
          float4 texcoord1 :TEXCOORD1;
          float3 texcoord2 :TEXCOORD2;
      };
      
      struct OUT_Data_Frag
      {
          float4 color :SV_Target0;
      };
      
      float3 u_xlat0;
      float4 u_xlat1;
      float u_xlat16_1;
      float4 u_xlat2;
      int u_xlatb3;
      float u_xlat16_4;
      float u_xlat9;
      OUT_Data_Vert vert(appdata_t in_v)
      {
          OUT_Data_Vert out_v;
          u_xlat0.x = max(_ProjectionParams.y, 0.00999999978);
          u_xlat0.x = min(u_xlat0.x, 0.5);
          u_xlatb3 = (in_v.color.x>=1);
          u_xlat16_1 = (u_xlatb3)?(0):(1);
          u_xlat16_4 = (u_xlat16_1 * in_v.color.x);
          u_xlat16_1 = (((-in_v.color.z) * u_xlat16_1) + 1);
          out_v.texcoord3 = u_xlat16_1;
          u_xlat16_1 = (u_xlat16_4 * 0.166659996);
          u_xlat0.x = (u_xlat0.x * u_xlat16_1);
          u_xlat1 = (in_v.vertex.yyyy * conv_mxt4x4_1(unity_ObjectToWorld));
          u_xlat1 = ((conv_mxt4x4_0(unity_ObjectToWorld) * in_v.vertex.xxxx) + u_xlat1);
          u_xlat1 = ((conv_mxt4x4_2(unity_ObjectToWorld) * in_v.vertex.zzzz) + u_xlat1);
          u_xlat2 = (u_xlat1 + conv_mxt4x4_3(unity_ObjectToWorld));
          out_v.texcoord1 = ((conv_mxt4x4_3(unity_ObjectToWorld) * in_v.vertex.wwww) + u_xlat1);
          u_xlat1 = mul(unity_MatrixVP, u_xlat2);
          u_xlat0.x = (u_xlat0.x / u_xlat1.w);
          out_v.vertex.z = ((u_xlat0.x) + u_xlat1.z);
          out_v.vertex.xyw = u_xlat1.xyw;
          out_v.texcoord.xy = in_v.texcoord.xy;
          u_xlat0.x = dot(in_v.normal.xyz, conv_mxt4x4_0(unity_WorldToObject).xyz);
          u_xlat0.y = dot(in_v.normal.xyz, conv_mxt4x4_1(unity_WorldToObject).xyz);
          u_xlat0.z = dot(in_v.normal.xyz, conv_mxt4x4_2(unity_WorldToObject).xyz);
          out_v.texcoord2.xyz = normalize(u_xlat0.xyz);
          return out_v;
      }
      
      #define CODE_BLOCK_FRAGMENT
      float4 u_xlat0_d;
      float3 u_xlat10_0;
      float4 u_xlat1_d;
      float3 u_xlat10_1;
      int u_xlatb1;
      float3 u_xlat2_d;
      float3 u_xlat16_2;
      float3 u_xlat3;
      float3 u_xlat4;
      float u_xlat6;
      float u_xlat15;
      float u_xlat16_15;
      int u_xlatb15;
      float u_xlat16;
      OUT_Data_Frag frag(v2f in_f)
      {
          OUT_Data_Frag out_f;
          u_xlat0_d.xy = TRANSFORM_TEX(in_f.texcoord.xy, _1st_ShadeMap);
          u_xlat10_0.xyz = tex2D(_1st_ShadeMap, u_xlat0_d.xy).xyz;
          u_xlat0_d.xyz = (u_xlat10_0.xyz * _1st_ShadeColor.xyz);
          u_xlat1_d.xyz = ((u_xlat0_d.xyz * _LightColor0.xyz) + (-u_xlat0_d.xyz));
          u_xlat0_d.xyz = ((float3(float3(_Is_LightColor_1st_Shade, _Is_LightColor_1st_Shade, _Is_LightColor_1st_Shade)) * u_xlat1_d.xyz) + u_xlat0_d.xyz);
          u_xlat1_d.xy = TRANSFORM_TEX(in_f.texcoord.xy, _BaseMap);
          u_xlat10_1.xyz = tex2D(_BaseMap, u_xlat1_d.xy).xyz;
          u_xlat1_d.xyz = (u_xlat10_1.xyz * _BaseColor.xyz);
          u_xlat2_d.xyz = ((u_xlat1_d.xyz * _LightColor0.xyz) + (-u_xlat1_d.xyz));
          u_xlat1_d.xyz = ((float3(_Is_LightColor_Base, _Is_LightColor_Base, _Is_LightColor_Base) * u_xlat2_d.xyz) + u_xlat1_d.xyz);
          u_xlat16_2.xyz = normalize(_WorldSpaceLightPos0.xyz);
          u_xlat3.xyz = normalize(in_f.texcoord2.xyz);
          u_xlat15 = (((u_xlat16_15)?(1):(0)!=0))?(1):((1));
          u_xlat4.xyz = (float3(u_xlat15, u_xlat15, u_xlat15) * u_xlat3.xyz);
          u_xlat3.xyz = ((u_xlat3.xyz * float3(u_xlat15, u_xlat15, u_xlat15)) + float3(1, 1, 1));
          u_xlat15 = dot(u_xlat4.xyz, u_xlat16_2.xyz);
          u_xlat15 = ((u_xlat15 * 0.5) + 0.5);
          u_xlat16 = (_Tweak_SystemShadowsLevel + 1);
          u_xlat16 = clamp(u_xlat16, 0, 1);
          u_xlat16 = ((u_xlat15 * u_xlat16) + (-u_xlat15));
          u_xlat0_d.w = ((_Set_SystemShadowsToBase * u_xlat16) + u_xlat15);
          u_xlat1_d.w = (_BaseColor_Step + (-_BaseShade_Feather));
          u_xlat0_d = (u_xlat0_d + (-u_xlat1_d));
          u_xlat16 = ((-u_xlat1_d.w) + _BaseColor_Step);
          u_xlat15 = (u_xlat0_d.w / u_xlat16);
          u_xlat15 = ((-u_xlat15) + 1);
          u_xlat15 = clamp(u_xlat15, 0, 1);
          u_xlat15 = (u_xlat15 * in_f.texcoord3);
          u_xlat0_d.xyz = ((float3(u_xlat15, u_xlat15, u_xlat15) * u_xlat0_d.xyz) + u_xlat1_d.xyz);
          u_xlat1_d.xyz = ((-in_f.texcoord1.xyz) + _WorldSpaceCameraPos.xyz);
          u_xlat1_d.xyz = normalize(u_xlat1_d.xyz);
          u_xlat15 = dot(u_xlat4.xyz, u_xlat1_d.xyz);
          u_xlat15 = ((-u_xlat15) + 1);
          u_xlat15 = log2(u_xlat15);
          u_xlat1_d.x = ((_RimLight_Power * (-3)) + 3);
          u_xlat1_d.x = exp2(u_xlat1_d.x);
          u_xlat15 = (u_xlat15 * u_xlat1_d.x);
          u_xlat15 = exp2(u_xlat15);
          u_xlatb1 = (u_xlat15>=_RimLight_InsideMask);
          u_xlat15 = (u_xlat15 + (-_RimLight_InsideMask));
          u_xlat1_d.x = (u_xlatb1)?(1):(float(0));
          u_xlat6 = ((-_RimLight_InsideMask) + 1);
          u_xlat15 = (u_xlat15 / u_xlat6);
          u_xlat1_d.x = ((-u_xlat15) + u_xlat1_d.x);
          u_xlat15 = ((_RimLight_FeatherOff * u_xlat1_d.x) + u_xlat15);
          u_xlat15 = clamp(u_xlat15, 0, 1);
          u_xlat1_d.xyz = ((_RimLightColor.xyz * _LightColor0.xyz) + (-_RimLightColor.xyz));
          u_xlat1_d.xyz = ((float3(float3(_Is_LightColor_RimLight, _Is_LightColor_RimLight, _Is_LightColor_RimLight)) * u_xlat1_d.xyz) + _RimLightColor.xyz);
          u_xlat1_d.xyz = (float3(u_xlat15, u_xlat15, u_xlat15) * u_xlat1_d.xyz);
          u_xlat0_d.xyz = ((float3(_RimLight, _RimLight, _RimLight) * u_xlat1_d.xyz) + u_xlat0_d.xyz);
          u_xlat0_d.xyz = clamp(u_xlat0_d.xyz, 0, 1);
          u_xlatb15 = (_Camouflage>=0.800000012);
          u_xlat0_d.xyz = (int(u_xlatb15))?(float3(0, 0, 0)):(u_xlat0_d.xyz);
          u_xlat15 = (u_xlatb15)?(1):(float(0));
          u_xlat1_d.xyz = (float3(u_xlat15, u_xlat15, u_xlat15) * u_xlat3.xyz);
          out_f.color.xyz = ((u_xlat1_d.xyz * float3(0.5, 0.5, 0.5)) + u_xlat0_d.xyz);
          u_xlat0_d.x = ((-_Camouflage) + 1);
          out_f.color.w = (u_xlat0_d.x * _Alpha);
          return out_f;
      }
      
      
      ENDCG
      
    } // end phase
    Pass // ind: 3, name: ShadowCaster
    {
      Name "ShadowCaster"
      Tags
      { 
        "LIGHTMODE" = "SHADOWCASTER"
        "RenderType" = "Opaque"
        "SHADOWSUPPORT" = "true"
      }
      Cull Off
      Offset 1, 1
      // m_ProgramMask = 6
      CGPROGRAM
      #pragma multi_compile SHADOWS_DEPTH
      //#pragma target 4.0
      
      #pragma vertex vert
      #pragma fragment frag
      
      #include "UnityCG.cginc"
      
      
      #define CODE_BLOCK_VERTEX
      //uniform float4 unity_LightShadowBias;
      //uniform float4x4 unity_ObjectToWorld;
      //uniform float4x4 unity_MatrixVP;
      struct appdata_t
      {
          float4 vertex :POSITION0;
      };
      
      struct OUT_Data_Vert
      {
          float4 vertex :SV_POSITION;
      };
      
      struct v2f
      {
          float4 vertex :Position;
      };
      
      struct OUT_Data_Frag
      {
          float4 color :SV_Target0;
      };
      
      float4 u_xlat0;
      float4 u_xlat1;
      float u_xlat4;
      OUT_Data_Vert vert(appdata_t in_v)
      {
          OUT_Data_Vert out_v;
          u_xlat0 = UnityObjectToClipPos(in_v.vertex);
          u_xlat1.x = (unity_LightShadowBias.x / u_xlat0.w);
          u_xlat1.x = clamp(u_xlat1.x, 0, 1);
          u_xlat4 = (u_xlat0.z + u_xlat1.x);
          u_xlat1.x = max((-u_xlat0.w), u_xlat4);
          out_v.vertex.xyw = u_xlat0.xyw;
          u_xlat0.x = ((-u_xlat4) + u_xlat1.x);
          out_v.vertex.z = ((unity_LightShadowBias.y * u_xlat0.x) + u_xlat4);
          return out_v;
      }
      
      #define CODE_BLOCK_FRAGMENT
      OUT_Data_Frag frag(v2f in_f)
      {
          OUT_Data_Frag out_f;
          out_f.color = float4(0, 0, 0, 0);
          return out_f;
      }
      
      
      ENDCG
      
    } // end phase
  }
  FallBack Off
}
