pub enum Geometry<'a> {
Flat {
vertices: Cow<'a, [u8]>,
uv_range: UvRange,
indices: Cow<'a, [u32]>,
clusters: MeshClusters,
flags: u32,
},
Dag {
uv_range: UvRange,
levels: Vec<Cow<'a, [u8]>>,
dag: ClusterDag,
flags: u32,
},
}Expand description
One resident mesh’s geometry, as the renderer needs it: triangles for a vertex stage, clusters for a mesh stage, and nothing else.
The clusters are supplied rather than built, because building them is
crcbl-scene’s build_meshlets and the renderer must not depend on that
crate — §3.5 makes the meshlet build a bake step for exactly that reason.
Variants§
Flat
A mesh with no level hierarchy: one vertex range, one index range, one run of clusters, drawn from every camera.
Fields
vertices: Cow<'a, [u8]>Vertices as mesh::MeshVertex bytes — mesh::VERTEX_STRIDE per
vertex, little-endian, exactly what
cube_vertex_bytes produces.
Interleaved, which is not how the pool stores them. A record is
a position and then its attributes; crate::MeshPool::upload
separates the two streams, so a caller describes geometry once and
the position region reaches the device contiguous.
uv_range: UvRangeThe scale and offset every UV lane in vertices was quantised
against — UvRange::from_uvs over the mesh’s float coordinates,
before any vertex was built.
It has to travel with the bytes: a unorm16 lane means nothing
without it, and the pool cannot recover it from lanes that are
already quantised. It reaches the shaders through
mesh::GpuMesh::uv_range.
indices: Cow<'a, [u32]>Triangle indices into vertices, mesh-relative: the pool’s base
vertex is added by the shader through the mesh table.
clusters: MeshClustersThe same triangles partitioned for a mesh stage. Read on
GeometryPath::MeshShader and
on no other path.
flags: u32Per-mesh bits for mesh::GpuMesh::flags — today only
MESH_AUTHORED_TANGENTS.
Zero is the honest value for a caller that builds its vertices
with mesh::MeshVertex::from_normal, which is every mesh this
engine authors for itself: that constructor fills the frame with
orthonormal_basis’
stand-in, which is orthonormal and agrees with no UV
parameterisation, so a normal map read through it would be rotated by
an angle nobody chose. Setting the bit is a claim that these
vertices came from a real TANGENT, and the fragment stage takes the
caller at its word — the screen-space derivative frame is what it
falls back to otherwise.
Dag
Topic 25’s cluster DAG: several levels of one surface, each its own vertex range, with the grouping that relates them.
§A coarse level has no attributes, and the caller has to supply them
crcbl_scene::simplify is position-only and says so in its own
module docs: a coarser level’s vertices are wherever the collapses put
them and belong to no vertex of the level below, so the decimator carries
no normals and no UVs. ClusterDag therefore holds positions, and
this variant’s levels is where the attributes come back — one
vertex-byte array per level, which the caller produces however it can.
demo’s dunes patch can do it because the surface is analytic:
crcbl_shaders::dunes::vertex_at evaluates the height field at a
position rather than interpolating an attribute nothing recorded. An
application-supplied DAG needs attribute-aware simplification or
nearest-source attribute transfer, which is unbuilt topic 25 work — so
this variant is usable today only by a caller that can answer that
question for its own surface.
Fields
uv_range: UvRangeThe range every level’s UV lanes were quantised against — one for all of them.
The mesh path resolves a row through the instance’s mesh, which for a DAG is level 0, so a coarser level’s vertices are decoded through level 0’s range. A caller that quantised each level against its own bounds would see the coarse levels’ texture slide.
levels: Vec<Cow<'a, [u8]>>Vertex bytes per level, finest first and parallel to
dag.levels — same length, and one vertex
per position of the level beside it.
dag: ClusterDagThe levels, their clusters, and the groups that relate them.
flags: u32Per-mesh bits for mesh::GpuMesh::flags — today only
MESH_AUTHORED_TANGENTS.
Zero is the honest value for a caller that builds its vertices
with mesh::MeshVertex::from_normal, which is every mesh this
engine authors for itself: that constructor fills the frame with
orthonormal_basis’
stand-in, which is orthonormal and agrees with no UV
parameterisation, so a normal map read through it would be rotated by
an angle nobody chose. Setting the bit is a claim that these
vertices came from a real TANGENT, and the fragment stage takes the
caller at its word — the screen-space derivative frame is what it
falls back to otherwise.