A perspective projection from the frustum with its near plane at distance n spanning l..r by b..t, and its far plane at f. The camera looks along -z, clip depth is -1..1 (0..1 with depth_range_01 = true), and after multiplying a Vector4 you divide by w to get normalized coordinates. n and f must be positive and n != f.
m := make_frustum_matrix(-1, 1, -1, 1, 1, 10);
p := m * xyzw(0, 0, -1, 1); // on the near plane
assert(abs(p.z / p.w + 1) < 0.0001);
p = m * xyzw(0, 0, -10, 1); // on the far plane
assert(abs(p.z / p.w - 1) < 0.0001);make_frustum_matrix :: (
l: float,
r: float,
b: float,
t: float,
n: float,
f: float,
depth_range_01 := false
) -> Matrix4
A perspective projection from the rectangle on the near plane.
Parameters
- l: float
- left edge of the near rectangle.
- r: float
- right edge of the near rectangle.
- b: float
- bottom edge of the near rectangle.
- t: float
- top edge of the near rectangle.
- n: float
- distance to the near plane.
- f: float
- distance to the far plane.
- depth_range_01 := false
- true maps depth to
0..1, false to-1..1.