viewDepth function

double viewDepth(
  1. Float32List v,
  2. ShaderBindings b
)

ViewDepth: how far this fragment is along the view axis, in world metres.

What the surface buffer's alpha holds. A depth rather than a distance, and the difference only shows on an orthographic camera, whose rays are parallel rather than meeting at the eye: a distance from the eye names a sphere, and a reader cannot tell which point of a parallel ray it means. A depth names a plane, which every ray crosses once.

Implementation

double viewDepth(Float32List v, ShaderBindings b) {
  final eye = b.vec4('FogInfo', 'eye', Vector4.zero());
  final forward = b.vec4('FogInfo', 'forward', Vector4.zero());
  return (v[kVWorld] - eye.x) * forward.x +
      (v[kVWorld + 1] - eye.y) * forward.y +
      (v[kVWorld + 2] - eye.z) * forward.z;
}