uniform sampler2D StudsMap;
uniform sampler2D NormalMap;
uniform sampler3D NoiseMap;
uniform sampler3D LightMap;
uniform vec4 LightConfig1;
uniform vec4 LightBorder;
uniform vec3 Lamp1Color;
uniform vec3 Lamp0Dir;
uniform vec3 Lamp0Color;
uniform vec3 FogColor;
uniform vec3 AmbientColor;
void main ()
{
  vec4 tmpvar_1;
  tmpvar_1 = gl_TexCoord[2];
  vec4 tmpvar_2;
  tmpvar_2 = gl_TexCoord[4];
  vec4 tmpvar_3;
  tmpvar_3 = gl_TexCoord[5];
  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);
  vec3 tNorm_9;
  vec3 tmpvar_10;
  tmpvar_10 = (texture2D (NormalMap, (tmpvar_3.xy * 0.6)).xyz - 0.5);
  tNorm_9.z = tmpvar_10.z;
  vec4 tmpvar_11;
  tmpvar_11.xy = dFdx(tmpvar_3.yz);
  tmpvar_11.zw = dFdy(tmpvar_3.yz);
  vec3 tmpvar_12;
  tmpvar_12 = (tmpvar_3.xyz + texture3D (NoiseMap, (tmpvar_3.xyz / 64.0)).xyz);
  float tmpvar_13;
  tmpvar_13 = (4.0 * sqrt(dot (tmpvar_12.yz, tmpvar_12.yz)));
  float tmpvar_14;
  tmpvar_14 = (tmpvar_13 + texture3D (NoiseMap, (vec3(tmpvar_13) / 32.0)).x);
  float tmpvar_15;
  tmpvar_15 = (tmpvar_14 - floor(tmpvar_14));
  float t_16;
  t_16 = max (min (((tmpvar_15 - 0.4) / 0.4), 1.0), 0.0);
  float t_17;
  t_17 = max (min (((tmpvar_15 - 0.83) / 0.17), 1.0), 0.0);
  float tmpvar_18;
  tmpvar_18 = mix (((t_16 * (t_16 * (3.0 - (2.0 * t_16)))) - (t_17 * (t_17 * (3.0 - (2.0 * t_17))))), 0.315, clamp (((sqrt(dot (tmpvar_11, tmpvar_11)) * 12.0) - 1.0), 0.0, 1.0));
  tNorm_9.xy = (tmpvar_10.xy * clamp ((1.05 - abs(tmpvar_3.w)), 0.0, 1.0));
  tmpvar_7.z = tNorm_9.z;
  float tmpvar_19;
  tmpvar_19 = clamp (tmpvar_4.w, 0.0, 1.0);
  tmpvar_7.xy = (tNorm_9.xy * (1.0 - tmpvar_19));
  vec3 tmpvar_20;
  tmpvar_20 = mix (mix ((gl_Color.xyz + (0.1 * (0.315 - tmpvar_18))), gl_Color.xyz, vec3(tmpvar_19)), tmpvar_8.xyz, tmpvar_8.www);
  vec4 tmpvar_21;
  tmpvar_21.xyz = tmpvar_20;
  tmpvar_21.w = gl_Color.w;
  albedo_6.w = tmpvar_21.w;
  vec3 tmpvar_22;
  tmpvar_22 = normalize((((tmpvar_7.x * tmpvar_4.xyz) + (tmpvar_7.y * ((tmpvar_2.yzx * tmpvar_4.zxy) - (tmpvar_2.zxy * tmpvar_4.yzx)))) + (tmpvar_10.z * tmpvar_2.xyz)));
  float tmpvar_23;
  tmpvar_23 = dot (tmpvar_22, -(Lamp0Dir));
  vec4 tmpvar_24;
  tmpvar_24.xyz = ((clamp (tmpvar_23, 0.0, 1.0) * Lamp0Color) + (max (-(tmpvar_23), 0.0) * Lamp1Color));
  tmpvar_24.w = (float((tmpvar_23 >= 0.0)) * mix (mix (0.32, 0.16, tmpvar_18), 0.2696, clamp (tmpvar_4.w, 0.0, 1.0)));
  vec3 tmpvar_25;
  tmpvar_25 = clamp (tmpvar_1.xyz, 0.0, 1.0);
  vec3 tmpvar_26;
  tmpvar_26 = abs((tmpvar_25 - 0.5));
  vec4 tmpvar_27;
  tmpvar_27 = mix (LightBorder, texture3D (LightMap, (tmpvar_25 - LightConfig1.xyz)), vec4(float((0.49 >= max (tmpvar_26.x, max (tmpvar_26.y, tmpvar_26.z))))));
  albedo_6.xyz = tmpvar_20;
  oColor0_5.xyz = ((((AmbientColor + (tmpvar_24.xyz * tmpvar_27.w)) + tmpvar_27.xyz) * tmpvar_20) + (Lamp0Color * ((tmpvar_27.w * tmpvar_24.w) * pow (clamp (dot (tmpvar_22, normalize((-(Lamp0Dir) + normalize(gl_TexCoord[3].xyz)))), 0.0, 1.0), tmpvar_2.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;
}

