pointShadowFaceViewProjection method

Matrix4 pointShadowFaceViewProjection(
  1. Vector3 worldPosition,
  2. int face
)

The world -> clip matrix that renders face face (0..5, the +X, -X, +Y, -Y, +Z, -Z axes) of this light's shadow cube for a light at worldPosition. A 90 degree square frustum from shadowNear to shadowFar. The per-face basis must stay in lockstep with the dominant-axis face selection in material_shadow_sampling.glsl (SamplePointShadow), which reconstructs the same mapping analytically.

Implementation

Matrix4 pointShadowFaceViewProjection(Vector3 worldPosition, int face) {
  final right = _pointFaceRight[face];
  final up = _pointFaceUp[face];
  final forward = _pointFaceForward[face];
  final view = Matrix4(
    right.x,
    up.x,
    forward.x,
    0.0, //
    right.y,
    up.y,
    forward.y,
    0.0, //
    right.z,
    up.z,
    forward.z,
    0.0, //
    -right.dot(worldPosition),
    -up.dot(worldPosition),
    -forward.dot(worldPosition),
    1.0, //
  );
  final projection = PerspectiveProjection(
    fovRadiansY: math.pi / 2.0,
    near: shadowNear,
    far: shadowFar,
  ).getProjectionMatrix(1.0);
  return projection * view;
}