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 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[5];
  vec4 tmpvar_5;
  tmpvar_5 = gl_TexCoord[6];
  vec4 oColor0_6;
  vec4 albedo_7;
  vec3 tmpvar_8;
  vec4 tmpvar_9;
  tmpvar_9 = texture2D (StudsMap, gl_TexCoord[1].xy);
  vec3 tNorm_10;
  vec3 tmpvar_11;
  tmpvar_11 = (texture2D (NormalMap, (gl_TexCoord[0].xy * 0.01)).xyz - vec3(0.5, 0.5, 0.5));
  tNorm_10.z = tmpvar_11.z;
  tNorm_10.xy = (tmpvar_11.xy * 0.15);
  tmpvar_8.z = tNorm_10.z;
  float tmpvar_12;
  tmpvar_12 = clamp (tmpvar_5.w, 0.0, 1.0);
  tmpvar_8.xy = (tNorm_10.xy * (1.0 - tmpvar_12));
  vec3 tmpvar_13;
  tmpvar_13 = mix (mix (((gl_Color.xyz + (((texture3D (NoiseMap, ((tmpvar_4.xyz / 2.33333) * 0.1)).xyz * ((texture3D (NoiseMap, ((tmpvar_4.xyz / 2.33333) * 0.5)).xyz * 0.7) + 0.5)) * 0.35) - 0.15)) * (0.85 + (0.15 * dot (tmpvar_11, vec3(1.0, 1.0, 1.0))))), gl_Color.xyz, vec3(tmpvar_12)), tmpvar_9.xyz, tmpvar_9.www);
  vec4 tmpvar_14;
  tmpvar_14.xyz = tmpvar_13;
  tmpvar_14.w = gl_Color.w;
  albedo_7.w = tmpvar_14.w;
  vec3 tmpvar_15;
  tmpvar_15 = normalize((((tmpvar_8.x * tmpvar_5.xyz) + (tmpvar_8.y * ((tmpvar_3.yzx * tmpvar_5.zxy) - (tmpvar_3.zxy * tmpvar_5.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.4);
  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_7.xyz = (tmpvar_13 + ((0.275 * (1.0 - tmpvar_12)) * textureCube (EnvironmentMap, (i_21 - (2.0 * (dot (tmpvar_15, i_21) * tmpvar_15)))).xyz));
  oColor0_6.xyz = ((((AmbientColor + (tmpvar_17.xyz * tmpvar_20.w)) + tmpvar_20.xyz) * albedo_7.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_6.w = albedo_7.w;
  oColor0_6.xyz = mix (FogColor, oColor0_6.xyz, vec3(clamp (tmpvar_1.w, 0.0, 1.0)));
  gl_FragData[0] = oColor0_6;
}

