varying highp vec3 xlv_TEXCOORD6;
varying highp vec4 xlv_TEXCOORD4;
varying highp vec4 xlv_TEXCOORD3;
varying highp vec4 xlv_TEXCOORD2;
varying highp vec4 xlv_COLOR0;
varying highp vec4 xlv_TEXCOORD1;
varying highp vec4 xlv_TEXCOORD0;
uniform sampler2D NormalDetailMap;
uniform samplerCube EnvironmentMap;
uniform sampler2D NormalMap;
uniform sampler2D DiffuseMap;
uniform sampler2D LightMapLookup;
uniform sampler2D LightMap;
uniform highp float Reflectance;
uniform highp vec2 OutlineBrightness;
uniform highp vec4 LightBorder;
uniform highp vec4 LightConfig3;
uniform highp vec4 LightConfig2;
uniform highp vec3 FogColor;
uniform highp vec3 AmbientColor;
uniform highp vec3 Lamp1Color;
uniform highp vec3 Lamp0Color;
uniform highp vec3 Lamp0Dir;
void main ()
{
  highp vec4 oColor0_1;
  highp vec3 reflection_2;
  highp vec4 albedo_3;
  highp vec3 normal_4;
  highp vec4 studs_5;
  lowp vec4 tmpvar_6;
  tmpvar_6 = texture2D (DiffuseMap, xlv_TEXCOORD1.xy);
  studs_5 = tmpvar_6;
  lowp vec4 tmpvar_7;
  tmpvar_7 = texture2D (NormalMap, xlv_TEXCOORD1.xy);
  highp vec3 tmpvar_8;
  highp vec4 value_9;
  value_9 = tmpvar_7;
  tmpvar_8 = ((value_9.xyz * 2.0) - 1.0);
  normal_4.z = tmpvar_8.z;
  lowp vec4 tmpvar_10;
  tmpvar_10 = texture2D (NormalDetailMap, xlv_TEXCOORD0.xy);
  highp vec4 value_11;
  value_11 = tmpvar_10;
  normal_4.xy = (tmpvar_8.xy + (((value_11.xyz * 2.0) - 1.0).xy * (max ((xlv_COLOR0.w - 0.5), 0.0) * clamp ((1.0 - (2.0 * Reflectance)), 0.0, 1.0))));
  normal_4.xy = (normal_4.xy * max ((1.0 - xlv_TEXCOORD3.w), 0.0));
  highp vec3 tmpvar_12;
  tmpvar_12 = ((xlv_COLOR0.xyz * studs_5.xyz) * 2.0);
  highp vec4 tmpvar_13;
  tmpvar_13.xyz = tmpvar_12;
  tmpvar_13.w = xlv_COLOR0.w;
  albedo_3.w = tmpvar_13.w;
  highp vec3 tmpvar_14;
  tmpvar_14 = normalize((((normal_4.x * xlv_TEXCOORD6) + (normal_4.y * ((xlv_TEXCOORD4.yzx * xlv_TEXCOORD6.zxy) - (xlv_TEXCOORD4.zxy * xlv_TEXCOORD6.yzx)))) + (tmpvar_8.z * xlv_TEXCOORD4.xyz)));
  highp float tmpvar_15;
  tmpvar_15 = dot (tmpvar_14, -(Lamp0Dir));
  highp vec3 tmpvar_16;
  tmpvar_16 = abs((xlv_TEXCOORD2.xyz - LightConfig2.xyz));
  highp vec3 t_17;
  t_17.x = float((tmpvar_16.x >= LightConfig3.x));
  t_17.y = float((tmpvar_16.y >= LightConfig3.y));
  t_17.z = float((tmpvar_16.z >= LightConfig3.z));
  highp float tmpvar_18;
  tmpvar_18 = min (dot (t_17, vec3(1.0, 1.0, 1.0)), 1.0);
  highp vec4 s1_19;
  highp vec4 s0_20;
  highp vec4 offsets_21;
  lowp vec4 tmpvar_22;
  tmpvar_22 = texture2D (LightMapLookup, xlv_TEXCOORD2.xy);
  offsets_21 = tmpvar_22;
  highp vec2 tmpvar_23;
  tmpvar_23 = (xlv_TEXCOORD2.yz * 0.125);
  highp vec2 tmpvar_24;
  tmpvar_24 = (tmpvar_23 - (tmpvar_23 * tmpvar_18));
  lowp vec4 tmpvar_25;
  highp vec2 P_26;
  P_26 = (tmpvar_24 + offsets_21.xy);
  tmpvar_25 = texture2D (LightMap, P_26);
  s0_20 = tmpvar_25;
  lowp vec4 tmpvar_27;
  highp vec2 P_28;
  P_28 = (tmpvar_24 + offsets_21.zw);
  tmpvar_27 = texture2D (LightMap, P_28);
  s1_19 = tmpvar_27;
  highp vec4 tmpvar_29;
  tmpvar_29 = mix (mix (s0_20, s1_19, vec4(fract((xlv_TEXCOORD2.x * 64.0)))), LightBorder, vec4(tmpvar_18));
  highp vec3 tmpvar_30;
  highp vec3 i_31;
  i_31 = -(xlv_TEXCOORD3.xyz);
  tmpvar_30 = (i_31 - (2.0 * (dot (tmpvar_14, i_31) * tmpvar_14)));
  lowp vec3 tmpvar_32;
  tmpvar_32 = textureCube (EnvironmentMap, tmpvar_30).xyz;
  reflection_2 = tmpvar_32;
  albedo_3.xyz = mix (tmpvar_12, reflection_2, vec3(Reflectance));
  oColor0_1.xyz = ((((AmbientColor + (((max (tmpvar_15, 0.0) * Lamp0Color) + (max (-(tmpvar_15), 0.0) * Lamp1Color)) * tmpvar_29.w)) + tmpvar_29.xyz) * albedo_3.xyz) + (Lamp0Color * (((float((tmpvar_15 >= 0.0)) * 0.4) * tmpvar_29.w) * pow (clamp (dot (tmpvar_14, normalize((-(Lamp0Dir) + normalize(xlv_TEXCOORD3.xyz)))), 0.0, 1.0), 9.0))));
  oColor0_1.w = albedo_3.w;
  highp vec2 tmpvar_33;
  tmpvar_33 = min (xlv_TEXCOORD0.wz, xlv_TEXCOORD1.wz);
  highp float tmpvar_34;
  tmpvar_34 = (min (tmpvar_33.x, tmpvar_33.y) / xlv_TEXCOORD3.w);
  oColor0_1.xyz = (oColor0_1.xyz * min (((min (((xlv_TEXCOORD3.w * OutlineBrightness.x) + OutlineBrightness.y), 1.0) * (1.5 - tmpvar_34)) + tmpvar_34), 1.0));
  oColor0_1.xyz = mix (FogColor, oColor0_1.xyz, vec3(clamp (xlv_TEXCOORD2.w, 0.0, 1.0)));
  gl_FragData[0] = oColor0_1;
}

