cameraInfo property

ByteData get cameraInfo

A packed PostCameraInfo std140 uniform block for reconstructing world positions from sceneDepthLinear. Layout: a vec4 (tan(fovX/2), tan(fovY/2), near, far), then the camera basis as three vec4s (right, up, forward, matching the depth prepass's view space: the eye at the origin looking down +forward), then a vec4 camera world position. Reconstruct with viewZ = depth; viewXY = (2*uv - 1 flipped) * viewZ * tangents; world = position + right*viewX + up*viewY + forward*viewZ. Bind it under a PostCameraInfo block via applyShader's uniforms. The projection terms are zero for a non-perspective camera (where depth is unavailable).

Implementation

ByteData get cameraInfo {
  final f = Float32List(20); // 5 vec4
  final projection = camera.projection;
  if (projection is PerspectiveProjection && dimensions.height > 0) {
    final tanY = math.tan(projection.fovRadiansY * 0.5);
    f[0] = tanY * (dimensions.width / dimensions.height);
    f[1] = tanY;
    f[2] = projection.near;
    f[3] = projection.far;
  }
  // The same view basis the depth prepass encodes against (eye at origin
  // looking down +forward), so a reconstructed view point maps to world.
  final forward = camera.forward.normalized();
  final right = camera.up.cross(forward)..normalize();
  final up = forward.cross(right)..normalize();
  f[4] = right.x;
  f[5] = right.y;
  f[6] = right.z;
  f[8] = up.x;
  f[9] = up.y;
  f[10] = up.z;
  f[12] = forward.x;
  f[13] = forward.y;
  f[14] = forward.z;
  f[16] = camera.position.x;
  f[17] = camera.position.y;
  f[18] = camera.position.z;
  return ByteData.sublistView(f);
}