uniform sampler2D myNormal;
uniform sampler2D myDepth;

uniform vec2 cNormalBlurFalloffSharpness;


void main ()                                          
{ 
// TexCoord0 = UV + UVStep Normal
// TexCoord1 = UV + UVStep Depth

  vec4
    cNormal = vec4(0.0);
  float
    rZ = texture2D(myDepth, gl_TexCoord[1].xy).r,
    rContribute = 0.0;
    
  float
    rBlurFalloff = cNormalBlurFalloffSharpness.x,
    rBlurSharpness = cNormalBlurFalloffSharpness.y * 20.0;
      
  for (int iPass = -8; iPass <= 8; iPass++)
  {
    vec4
      cTempNormal = texture2D(myNormal, gl_TexCoord[0].xy + gl_TexCoord[0].zw * vec2(float(iPass)));
    
    float
      rD = texture2D(myDepth, gl_TexCoord[1].xy + gl_TexCoord[1].zw * vec2(float(iPass))).r;

	float
	  rDelta = rD - rZ;
      
	float w = exp(-float(iPass)*float(iPass)*rBlurFalloff - rDelta*rDelta*rBlurSharpness);
	rContribute += w;
	cNormal += vec4(w) * cTempNormal;
  }
  
  gl_FragColor = vec4(cNormal.xyz / vec3(rContribute), texture2D(myNormal, gl_TexCoord[0].xy).a); 
}                                                  
