varying vec3 ldir;
varying vec2 tex_coord;
+const float fog_density = 0.005;
+const vec4 sky_color = vec4(0.35, 0.5, 0.65, 1.0);
+
out vec4 color;
void main()
{
- vec3 p = normalize(pos);
+ vec3 p = normalize(pos); // view space dir
vec3 n = normalize(normal);
vec3 l = normalize(ldir);
float cdiff = max(dot(l, n), 0.0);
float cspec = pow(max(dot(r, vdir), 0.0), shininess);
+ float dist = -pos.z;
+ float fog = clamp(exp(-fog_density * dist), 0.0, 1.0);
+
vec4 texel = texture2D(tex, tex_coord);
- color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
- color.w = 1.0;
+
+ vec4 object_color;
+ object_color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+ object_color.w = 1.0;
+
+ color = mix(sky_color, object_color, fog);
}
glGenerateMipmap(target);
}
-void TextureGL::bind()
+void TextureGL::bind(int texture_unit)
{
+ glActiveTexture(GL_TEXTURE0 + texture_unit);
+
unsigned int target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
glBindTexture(target, tex);
+
+ //TODO: (not needed for now) if I ever use textures outside the Texture class
+ //glActiveTexture(GL_TEXTURE0);
}
void TextureGL::unbind()
virtual bool is_cubemap() const;
- virtual void bind() = 0;
+ virtual void bind(int texture_unit = 0) = 0;
virtual void unbind() = 0;
};