#include <metal_stdlib>
#pragma clang diagnostic ignored "-Wparentheses-equality"
using namespace metal;
constexpr sampler _mtl_xl_shadow_sampler(address::clamp_to_edge, filter::linear, compare_func::less_equal);
struct FragmentCommonData {
  half3 diffColor;
  half3 specColor;
  half oneMinusReflectivity;
  half oneMinusRoughness;
  half3 normalWorld;
  half3 eyeVec;
  half3 posWorld;
  half alpha;
};
constant FragmentCommonData _xlat_mtl_const1 = {float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), 0.0, 0.0, float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), float3(0.0, 0.0, 0.0), 0.0};
struct xlatMtlShaderInput {
  float4 xlv_TEXCOORD0;
  half3 xlv_TEXCOORD1;
  half4 xlv_TEXCOORD2_2;
  half4 xlv_TEXCOORD5;
  half4 xlv_TEXCOORD6;
  half4 xlv_COLOR;
};
struct xlatMtlShaderOutput {
  half4 FragData_0 [[color(0)]];
};
struct xlatMtlShaderUniform {
  half4 _WorldSpaceLightPos0;
  half4 unity_SHAr;
  half4 unity_SHAg;
  half4 unity_SHAb;
  half4 _LightShadowData;
  half4 unity_SpecCube0_HDR;
  half4 unity_ColorSpaceDielectricSpec;
  half4 _LightColor0;
  half4 _Color;
  half _Metallic;
  half _Glossiness;
  half _OcclusionStrength;
};
fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]]
  ,   texturecube<half> unity_SpecCube0 [[texture(0)]], sampler _mtlsmp_unity_SpecCube0 [[sampler(0)]]
  ,   texture2d<half> _MainTex [[texture(1)]], sampler _mtlsmp__MainTex [[sampler(1)]]
  ,   texture2d<half> _OcclusionMap [[texture(2)]], sampler _mtlsmp__OcclusionMap [[sampler(2)]]
  ,   depth2d<float> _ShadowMapTexture [[texture(3)]], sampler _mtlsmp__ShadowMapTexture [[sampler(3)]])
{
  xlatMtlShaderOutput _mtl_o;
  half4 c_1 = 0;
  half atten_2 = 0;
  half4 tmpvar_3 = 0;
  tmpvar_3 = _MainTex.sample(_mtlsmp__MainTex, (float2)(_mtl_i.xlv_TEXCOORD0.xy));
  half2 tmpvar_4 = 0;
  tmpvar_4.x = _mtl_u._Metallic;
  tmpvar_4.y = _mtl_u._Glossiness;
  half3 tmpvar_5 = 0;
  tmpvar_5 = (_mtl_u._Color.xyz * tmpvar_3.xyz);
  half3 tmpvar_6 = 0;
  half3 tmpvar_7 = 0;
  tmpvar_7 = mix (_mtl_u.unity_ColorSpaceDielectricSpec.xyz, tmpvar_5, half3(_mtl_u._Metallic));
  half tmpvar_8 = 0;
  tmpvar_8 = (_mtl_u.unity_ColorSpaceDielectricSpec.w - (_mtl_u._Metallic * _mtl_u.unity_ColorSpaceDielectricSpec.w));
  tmpvar_6 = (tmpvar_5 * tmpvar_8);
  half3 tmpvar_9 = 0;
  tmpvar_9 = normalize(_mtl_i.xlv_TEXCOORD2_2.xyz);
  half3 tmpvar_10 = 0;
  tmpvar_10 = normalize(_mtl_i.xlv_TEXCOORD1);
  half3 tmpvar_11 = 0;
  tmpvar_11 = _mtl_u._LightColor0.xyz;
  half shadow_12 = 0;
  half tmpvar_13 = 0;
  tmpvar_13 = _ShadowMapTexture.sample_compare(_mtl_xl_shadow_sampler, (float2)(_mtl_i.xlv_TEXCOORD6.xyz).xy, saturate((float)(_mtl_i.xlv_TEXCOORD6.xyz).z));
  half tmpvar_14 = 0;
  tmpvar_14 = tmpvar_13;
  shadow_12 = (_mtl_u._LightShadowData.x + (tmpvar_14 * ((half)(1.0) - _mtl_u._LightShadowData.x)));
  atten_2 = shadow_12;
  half occ_15 = 0;
  half tmpvar_16 = 0;
  tmpvar_16 = _OcclusionMap.sample(_mtlsmp__OcclusionMap, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).y;
  occ_15 = tmpvar_16;
  half tmpvar_17 = 0;
  tmpvar_17 = (((half)(1.0) - _mtl_u._OcclusionStrength) + (occ_15 * _mtl_u._OcclusionStrength));
  FragmentCommonData s_18;
  s_18 = _xlat_mtl_const1;
  s_18.oneMinusRoughness = tmpvar_4.y;
  s_18.normalWorld = tmpvar_9;
  s_18.eyeVec = tmpvar_10;
  s_18.posWorld = half3(float3(0.0, 0.0, 0.0));
  half3 tmpvar_19 = 0;
  half3 tmpvar_20 = 0;
  tmpvar_19 = s_18.normalWorld;
  tmpvar_20 = s_18.eyeVec;
  float4 tmpvar_21 = 0;
  tmpvar_21 = float4(_mtl_u.unity_SpecCube0_HDR);
  half tmpvar_22 = 0;
  tmpvar_22 = ((half)(1.0) - s_18.oneMinusRoughness);
  half3 tmpvar_23 = 0;
  tmpvar_23 = (tmpvar_20 - ((half)(2.0) * (
    dot (tmpvar_19, tmpvar_20)
   * tmpvar_19)));
  half4 tmpvar_24 = 0;
  tmpvar_24.w = half(1.0);
  tmpvar_24.xyz = tmpvar_19;
  half3 x_25 = 0;
  x_25.x = dot (_mtl_u.unity_SHAr, tmpvar_24);
  x_25.y = dot (_mtl_u.unity_SHAg, tmpvar_24);
  x_25.z = dot (_mtl_u.unity_SHAb, tmpvar_24);
  half4 hdr_26 = 0;
  hdr_26 = half4(tmpvar_21);
  half4 tmpvar_27 = 0;
  tmpvar_27.xyz = tmpvar_23;
  tmpvar_27.w = ((tmpvar_22 * ((half)(1.7) - 
    ((half)(0.7) * tmpvar_22)
  )) * (half)(6.0));
  half4 tmpvar_28 = 0;
  tmpvar_28 = unity_SpecCube0.sample(_mtlsmp_unity_SpecCube0, (float3)(tmpvar_23), level(tmpvar_27.w));
  half4 tmpvar_29 = 0;
  tmpvar_29 = tmpvar_28;
  half3 viewDir_30 = 0;
  viewDir_30 = -(tmpvar_10);
  half3 tmpvar_31 = 0;
  half3 inVec_32 = 0;
  inVec_32 = (_mtl_u._WorldSpaceLightPos0.xyz + viewDir_30);
  tmpvar_31 = (inVec_32 * rsqrt(max ((half)0.001, 
    dot (inVec_32, inVec_32)
  )));
  half tmpvar_33 = 0;
  tmpvar_33 = max ((half)0.0, dot (_mtl_u._WorldSpaceLightPos0.xyz, tmpvar_31));
  half tmpvar_34 = 0;
  tmpvar_34 = ((half)(1.0) - _mtl_u._Glossiness);
  half tmpvar_35 = 0;
  tmpvar_35 = max ((half)0.0001, (tmpvar_34 * tmpvar_34));
  half tmpvar_36 = 0;
  tmpvar_36 = max ((((half)(2.0) / 
    (tmpvar_35 * tmpvar_35)
  ) - (half)(2.0)), (half)0.0001);
  half x_37 = 0;
  x_37 = ((half)(1.0) - max ((half)0.0, dot (tmpvar_9, viewDir_30)));
  half4 tmpvar_38 = 0;
  tmpvar_38.w = half(1.0);
  tmpvar_38.xyz = (((
    ((tmpvar_6 + (sqrt(
      max ((half)0.0001, (((tmpvar_36 + (half)(1.0)) * pow (
        max ((half)0.0, dot (tmpvar_9, tmpvar_31))
      , tmpvar_36)) / ((
        ((half)(8.0) * (((tmpvar_33 * tmpvar_33) * _mtl_u._Glossiness) + (tmpvar_34 * tmpvar_34)))
       * tmpvar_33) + (half)(0.0001))))
    ) * tmpvar_7)) * (tmpvar_11 * atten_2))
   * 
    max ((half)0.0, dot (tmpvar_9, _mtl_u._WorldSpaceLightPos0.xyz))
  ) + (
    (max ((((half)(1.055) * 
      pow (max ((half3)float3(0.0, 0.0, 0.0), (_mtl_i.xlv_TEXCOORD5.xyz + x_25)), (half3)float3(0.4166667, 0.4166667, 0.4166667))
    ) - (half)(0.055)), (half3)float3(0.0, 0.0, 0.0)) * tmpvar_17)
   * tmpvar_6)) + ((
    ((half)(1.0) - ((tmpvar_34 * tmpvar_34) * (tmpvar_34 * (half)(0.28))))
   * 
    (((hdr_26.x * tmpvar_29.w) * tmpvar_29.xyz) * tmpvar_17)
  ) * mix (tmpvar_7, half3(
    clamp ((_mtl_u._Glossiness + ((half)(1.0) - tmpvar_8)), (half)0.0, (half)1.0)
  ), half3(
    ((x_37 * x_37) * (x_37 * x_37))
  ))));
  c_1 = (tmpvar_38 * _mtl_i.xlv_COLOR);
  c_1.xyz = c_1.xyz;
  c_1.xyz = c_1.xyz;
  half4 xlat_varoutput_39 = 0;
  xlat_varoutput_39.xyz = c_1.xyz;
  xlat_varoutput_39.w = half(1.0);
  _mtl_o.FragData_0 = xlat_varoutput_39;
  return _mtl_o;
}


// stats: 97 alu 4 tex 0 flow
// inputs: 6
//  #0: xlv_TEXCOORD0 (high float) 4x1 [-1]
//  #1: xlv_TEXCOORD1 (medium float) 3x1 [-1]
//  #2: xlv_TEXCOORD2_2 (medium float) 4x1 [-1]
//  #3: xlv_TEXCOORD5 (medium float) 4x1 [-1]
//  #4: xlv_TEXCOORD6 (medium float) 4x1 [-1]
//  #5: xlv_COLOR (low float) 4x1 [-1]
// uniforms: 12 (total size: 78)
//  #0: _WorldSpaceLightPos0 (medium float) 4x1 [-1] loc 0
//  #1: unity_SHAr (medium float) 4x1 [-1] loc 8
//  #2: unity_SHAg (medium float) 4x1 [-1] loc 16
//  #3: unity_SHAb (medium float) 4x1 [-1] loc 24
//  #4: _LightShadowData (medium float) 4x1 [-1] loc 32
//  #5: unity_SpecCube0_HDR (medium float) 4x1 [-1] loc 40
//  #6: unity_ColorSpaceDielectricSpec (medium float) 4x1 [-1] loc 48
//  #7: _LightColor0 (low float) 4x1 [-1] loc 56
//  #8: _Color (medium float) 4x1 [-1] loc 64
//  #9: _Metallic (medium float) 1x1 [-1] loc 72
//  #10: _Glossiness (medium float) 1x1 [-1] loc 74
//  #11: _OcclusionStrength (medium float) 1x1 [-1] loc 76
// textures: 4
//  #0: unity_SpecCube0 (low cube) 0x0 [-1] loc 0
//  #1: _MainTex (low 2d) 0x0 [-1] loc 1
//  #2: _OcclusionMap (low 2d) 0x0 [-1] loc 2
//  #3: _ShadowMapTexture (low 2dshadow) 0x0 [-1] loc 3
