/////////////////////////////////////////////////// Fragment

#ifdef infsh
varying vec2 texcoord;

uniform sampler2D colortex1;
uniform sampler2D depthtex0; 
uniform int isEyeInWater;

vec3 wScatter(vec3 color) {
	float wcS = 0.038; // white surface to position -y
	
	vec3 aCoefficient = vec3(1.304, 0.3 - wcS, 0.32 - wcS);
	float sCoefficient = aCoefficient.x * 7.6687117e-2; // 0.100000000568
	
	float d = texture2D(depthtex0, texcoord).x;
	bool isSky = d == 1.0;
	
	vec3 ws =color * sCoefficient;
	ws *= aCoefficient * 11.234;	
	ws = isSky ? color : ws;
	
	return (isEyeInWater == 0) ? ws : color * 0.5;
}

vec4 refWSup(vec3 color) {
	float d = texture2D(depthtex0, texcoord).x;
	bool isSky = d == 1.0;
	
	vec3 rw = color;
	rw = isSky ? rw * 0.95 : pow(rw * 2.0, vec3(1.5)) * 0.7;
	rw = (isEyeInWater == 0) ? rw : color;
	
	return vec4(rw, 1.0);
}

void main() {
    vec4 block_color = texture2D(colortex1, texcoord);
    vec4 block_color2 = block_color;
    block_color2.rgb = wScatter(block_color.rgb);
    block_color = refWSup(block_color.rgb); 
    
/*DRAWBUFFERS:46*/
	gl_FragData[0] = block_color;
    gl_FragData[1] = block_color2;
}

#endif

/////////////////////////////////////////////////// Vertex

#ifdef outvsh
varying vec2 texcoord;

void main(){
	gl_Position = ftransform();
	
	texcoord = gl_MultiTexCoord0.xy;	
}

#endif