uniform sampler2D StudsMap;
uniform sampler2D NormalMap;
uniform sampler3D LightMap;
uniform vec4 LightConfig1;
uniform vec4 LightBorder;
uniform vec3 Lamp1Color;
uniform vec3 Lamp0Dir;
uniform vec3 Lamp0Color;
uniform vec3 FogColor;
uniform samplerCube EnvironmentMap;
uniform vec3 AmbientColor;
void main ()
{
  vec4 tmpvar_1;
  tmpvar_1 = gl_TexCoord[2];
  vec4 tmpvar_2;
  tmpvar_2 = gl_TexCoord[3];
  vec4 tmpvar_3;
  tmpvar_3 = gl_TexCoord[4];
  vec4 tmpvar_4;
  tmpvar_4 = gl_TexCoord[6];
  vec4 oColor0_5;
  vec4 albedo_6;
  vec3 tmpvar_7;
  vec4 tmpvar_8;
  tmpvar_8 = texture2D (StudsMap, gl_TexCoord[1].xy);
  vec2 tmpvar_9;
  tmpvar_9 = (gl_TexCoord[0].xy * 0.2);
  vec2 tmpvar_10;
  tmpvar_10 = (tmpvar_9 * 0.4);
  vec3 tmpvar_11;
  tmpvar_11 = (mix (mix (texture2D (NormalMap, tmpvar_9).xyz, texture2D (NormalMap, tmpvar_10).xyz, vec3(0.5, 0.5, 0.5)), texture2D (NormalMap, (tmpvar_10 * 0.1)).xyz, vec3(0.3, 0.3, 0.3)) - 0.5);
  tmpvar_7.z = tmpvar_11.z;
  float tmpvar_12;
  tmpvar_12 = clamp (tmpvar_4.w, 0.0, 1.0);
  tmpvar_7.xy = (tmpvar_11.xy * (1.0 - tmpvar_12));
  vec3 tmpvar_13;
  tmpvar_13 = mix (mix ((gl_Color.xyz * (0.4 + dot (tmpvar_11, vec3(0.6, 0.6, 0.6)))), gl_Color.xyz, vec3(tmpvar_12)), tmpvar_8.xyz, tmpvar_8.www);
  vec4 tmpvar_14;
  tmpvar_14.xyz = tmpvar_13;
  tmpvar_14.w = gl_Color.w;
  albedo_6.w = tmpvar_14.w;
  vec3 tmpvar_15;
  tmpvar_15 = normalize((((tmpvar_7.x * tmpvar_4.xyz) + (tmpvar_7.y * ((tmpvar_3.yzx * tmpvar_4.zxy) - (tmpvar_3.zxy * tmpvar_4.yzx)))) + (tmpvar_11.z * tmpvar_3.xyz)));
  float tmpvar_16;
  tmpvar_16 = dot (tmpvar_15, -(Lamp0Dir));
  vec4 tmpvar_17;
  tmpvar_17.xyz = ((clamp (tmpvar_16, 0.0, 1.0) * Lamp0Color) + (max (-(tmpvar_16), 0.0) * Lamp1Color));
  tmpvar_17.w = (float((tmpvar_16 >= 0.0)) * 0.9);
  vec3 tmpvar_18;
  tmpvar_18 = clamp (tmpvar_1.xyz, 0.0, 1.0);
  vec3 tmpvar_19;
  tmpvar_19 = abs((tmpvar_18 - 0.5));
  vec4 tmpvar_20;
  tmpvar_20 = mix (LightBorder, texture3D (LightMap, (tmpvar_18 - LightConfig1.xyz)), vec4(float((0.49 >= max (tmpvar_19.x, max (tmpvar_19.y, tmpvar_19.z))))));
  vec3 i_21;
  i_21 = -(tmpvar_2.xyz);
  albedo_6.xyz = (tmpvar_13 + ((0.35 * (1.0 - tmpvar_12)) * textureCube (EnvironmentMap, (i_21 - (2.0 * (dot (tmpvar_15, i_21) * tmpvar_15)))).xyz));
  oColor0_5.xyz = ((((AmbientColor + (tmpvar_17.xyz * tmpvar_20.w)) + tmpvar_20.xyz) * albedo_6.xyz) + (Lamp0Color * ((tmpvar_20.w * tmpvar_17.w) * pow (clamp (dot (tmpvar_15, normalize((-(Lamp0Dir) + normalize(tmpvar_2.xyz)))), 0.0, 1.0), tmpvar_3.w))));
  oColor0_5.w = albedo_6.w;
  oColor0_5.xyz = mix (FogColor, oColor0_5.xyz, vec3(clamp (tmpvar_1.w, 0.0, 1.0)));
  gl_FragData[0] = oColor0_5;
}

