uniform sampler2D colortex;
uniform sampler2D dephtex;
uniform sampler2D envitex;
uniform float radiusx, radiusy;
uniform float envipow;

void main() {
	vec3 color = texture2D(colortex, gl_TexCoord[0].xy).rgb;
	vec2 texcoord = gl_TexCoord[0].xy;
	float rr, gg, bb;
	float v=1.0;


  float d0, dy, dx;
	d0 = texture2D(dephtex, texcoord).r;
	dx = texture2D(dephtex, vec2(texcoord.x+radiusx, texcoord.y)).r;
	dy = texture2D(dephtex, vec2(texcoord.x, texcoord.y+radiusy)).r;
  vec2 pier = clamp(vec2(0.5+(d0-dx)*envipow, 0.5+(d0-dy)*envipow), 0.0, 1.0);
  vec3 envicol = texture2D(envitex, pier).rgb;

	gl_FragColor = vec4(envicol*color, 1.0);
}
