pub enum Projection {
Perspective {
fov_y: f32,
near: f32,
},
Orthographic {
half_height: f32,
near: f32,
far: f32,
},
}Expand description
How a camera flattens the world into clip space.
Two variants and one code path: stage 2’s milestone
5 is “orthographic camera mode proving the 2D story (z = z-index) is just a
projection matrix swap”, and this enum is that proof’s shape. Nothing
downstream of Camera::view_projection — not the shader, not the pipeline,
not the render graph — can tell which variant produced the matrix it was
handed.
Variants§
Perspective
Infinite-far reversed-Z perspective.
There is no far field, and its absence is the design: an infinite far
plane is free under reversed-Z (it costs one matrix element, not
precision) and it removes the “what should the far plane be?” question
from every caller in a world measured in sectors.
Fields
Orthographic
Reversed-Z orthographic.
The 2D mode. half_height is half the visible world height; the width
follows from the aspect ratio, so a resize changes what is visible
horizontally and never squashes the picture.
Fields
Implementations§
Source§impl Projection
impl Projection
Sourcepub fn matrix(self, aspect: f32) -> Mat4
pub fn matrix(self, aspect: f32) -> Mat4
The projection matrix for an aspect (width ÷ height) viewport.
The result maps to Y-up NDC with depth in 0..1. Y-up rather than
Vulkan’s native Y-down because crcbl-vk submits a negative-height
viewport, so the seam’s convention is +Y up and a backend that did not
flip would be the one out of step. Depth 0..1 because that is what
every backend this engine targets uses; only the direction is unusual.
§Panics
If aspect is not finite and positive, or if a distance is not positive
— all of which are caller bugs that otherwise produce a NaN matrix and a
blank screen with no error anywhere.
Sourcepub const fn is_orthographic(self) -> bool
pub const fn is_orthographic(self) -> bool
Whether this is the 2D mode.
Sourcepub fn pixels_per_unit(self, height: f32) -> f32
pub fn pixels_per_unit(self, height: f32) -> f32
How many pixels one unit of length subtends one unit from the eye, in a
viewport height pixels tall.
Topic 25’s scale factor: the number that carries a frame’s
size and field of view into a screen-space error, so a level’s stored
error in world units becomes the pixels its simplification would cost.
ClusterSelect::is_drawn divides it by the distance to the group’s
sphere, which is where the perspective falloff comes from.
An orthographic projection has no falloff at all, so for that variant
this is the whole scale factor and dividing it by a distance is wrong.
The value returned is still the right one — half the viewport over half
the visible height — and ForwardRenderer is what deals with the rest:
it pairs an orthographic camera with a budget nothing satisfies, so the
descent expands every group and draws the base level. That is the honest
answer for a 2D mode rather than a distance term invented for it.
§Panics
On the same arguments matrix refuses: a field of view
outside (0, π) or a non-positive half-height. height is not checked —
a zero-height viewport gives zero pixels per unit, which is a budget
nothing exceeds and a frame with no pixels in it.