uniform sampler2D surroundingDepthTexture;
uniform sampler2D depthTexture;
varying vec2 pos;

uniform float start;
uniform float end;
uniform float density;
uniform int volumetric;

uniform vec3 color;

void main(void)
{
	vec4 _depth = texture2D(depthTexture, gl_TexCoord[0].st);
	vec4 _surroundingDepth = texture2D(surroundingDepthTexture, gl_TexCoord[0].st);
  
  float f= 16.0;
  float n = 0.1;
  float z = (2.0 * n) / (f + n - _depth.r * (f - n));
  float sz = (2.0 * n) / (f + n - _surroundingDepth.r * (f - n));
  
  float q = (z - sz) * 10;
  
  float depth = z;
  
  if (volumetric == 1)
  {
    depth = q;
  }

  float fog = 0.0;
  fog = clamp((depth - start) / (end - start), 0.0, 1.0) * density;  

  color = vec3(1,1,1);

	//gl_FragColor = vec4(2.0, 2.0, 2.0, fog);
  gl_FragColor = vec4(color,fog);
  //gl_FragColor = vec4(vec3(depth), 1.0);
  
  //gl_FragColor = vec4(vec3(q),1.0);  
}
