in vec4 varColor;
in vec2 varTexCoord;
#ifdef USE_FOG
in float varFog;
#endif  // USE_FOG
#ifdef USE_ENV
in vec2 varEnvCoord;
#endif  // USE_ENV

// textures
uniform sampler2D diffuseTexture;

#ifdef ALPHA_TEST
// alpha test
uniform float alphaRef;
#endif  // ALPHA_TEST

#ifdef USE_FOG
// fog vars
uniform bool inFog;
uniform vec3 fogColor;
#endif  // USE_FOG

#ifdef USE_ENV
// env vars
uniform sampler2D envTexture;
uniform bool setEnv;
uniform vec3 envColor;
#endif  // USE_ENV

void main(void)
{
  vec4 diffuse = texture(diffuseTexture, varTexCoord);
  #ifdef ALPHA_TEST
  if (diffuse.a < alphaRef) {
    discard;
  }
  #endif  // ALPHA_TEST
  outColor = varColor * diffuse;

  #ifdef USE_ENV
  if (setEnv) {
    vec3 specular = texture(envTexture, varEnvCoord).rgb;
    outColor.rgb += envColor * specular;
  }
  #endif  // USE_ENV

  #ifdef USE_FOG
  if (inFog) {
    outColor.rgb = mix(fogColor, outColor.rgb, varFog);
  }
  #endif  // USE_FOG
}
