uniform sampler2D depthTexture;
uniform vec2 pixelSize;
uniform float volumeProbeBit;
varying vec3 normal;

void depthPeel()
{
  if (texture2D(depthTexture, gl_FragCoord.xy * pixelSize).x >= gl_FragCoord.z) discard;
}

vec2 packNormal(vec3 n)
{
  if (n.z < 0.0) n = -n;
  return vec2(lessThan(n.xy, vec2(0.0))) * (32768.0 / 65535.0) + fract(n.xy) * (32767.0 / 65535.0);
}

void main()
{
  depthPeel();
  gl_FragData[0] = vec4(volumeProbeBit);
  gl_FragData[1] = vec4(packNormal(normalize(normal)), 0.0, 1.0);
}
