Expand description
Vertex compression and the per-mesh decode metadata.
The built-in pipeline consumes a compact vertex layout: positions and UVs
are 16-bit normalized integers relative to a per-mesh bounding box, so the
shader needs the parameters that reverse that encoding. MeshMetadata
carries those parameters; compress_positions and compress_uvs
produce them together with the packed attribute streams.
The Rust side and the WGSL side (mesh_metadata.wesl) are kept in sync by
the crate. SecondaryStreamWriter and PositionStreamWriter pack the
per-vertex streams a draw declares, whichever pipeline then draws them.
§One description per stream
A stream is described by StreamChannels: one attribute location and
ChannelEncoding per channel, in the order the channels are interleaved.
The pipeline’s vertex layout, the compression that packs a mesh and the
streams a pool allocates all derive their bytes per vertex from that same
description, so the three cannot drift apart.
Re-exports§
use wgpu::WriteOnly;🔒
Structs§
- Joint
Pair - The joint indices and weights of one vertex, as the position stream stores them.
- Mesh
Instance - One per-instance record: the affine model matrix, base color, pose bases, metadata index, alpha cutoff and inverted-hull width the built-in pipeline reads from its per-instance vertex buffer.
- Mesh
Metadata - Per-mesh vertex-decode parameters and draw addressing.
- Position
Stream Channels - The channels of the position vertex stream: a position and, for a skinned mesh, the joint indices and weights that deform it.
- Position
Stream Writer - Packs the position vertex stream: the compressed position and, when the stream declares them, the joint indices and weights that deform it.
- Secondary
Flags - The optional per-vertex channels of a secondary vertex stream: the UV, color and normal a mesh carries beside its position.
- Secondary
Stream Writer - The optional per-vertex channels of a secondary vertex stream: the UV, color and normal that a mesh carries beside its position.
- Stream
Channels - The channels one per-vertex stream carries, in the order they are interleaved.
Enums§
- Channel
Encoding - How one compressed channel is encoded as a vertex attribute.
- Compress
Error - Failure reasons reported by the compression helpers.
Constants§
- MAX_
POSITION_ 🔒STRIDE - Bytes per vertex of the widest position stream, used to size the per-vertex scratch the writer assembles on the stack.
- MAX_
SECONDARY_ 🔒STRIDE - Bytes per vertex of the widest secondary stream, used to size the per-vertex scratch the writer assembles on the stack.
Functions§
- compress_
indices - Narrow
u32indices tou16. - compress_
normals - Octahedral-encode
normalsintoSnorm16x2lanes. - compress_
positions - Compress positions into
Snorm16x4relative to their bounding box, writing the decode parameters intoout_meta. - compress_
uvs - Compress UVs into
Snorm16x2remapped by their bounding box, writing the decode parameters intoout_meta.uv_min_and_extents. - compress_
weights - Quantize joint weights to
Unorm16x4, clamping out-of-range components. - derive_
position_ 🔒bounds - Derive the position decode parameters from
positionsand write them intoout_meta. - derive_
uv_ 🔒bounds - Derive the UV decode parameters from
uvsand write them intoout_meta.uv_min_and_extents. - encode_
scale 🔒 - The reciprocal of
extents, with degenerate axes collapsed to zero. - encode_
scale2 🔒 - The 2D counterpart of
encode_scale, for the UV range. - encode_
uvs - The compressed UVs of
uvs, encoded againstout_meta’s existing parameters without re-deriving them. - f32_
to_ 🔒snorm16 - Quantize
[-1, 1]floats to signed 16-bit normalized integers. - f32_
to_ 🔒unorm8 - Quantize one normalized
f32toUnorm8. - f32_
to_ 🔒unorm16 - Quantize one normalized
f32toUnorm16. - index_
fits_ u16 - Whether a vertex index can be named by a
Uint16index buffer. - octahedral_
encode 🔒 - Octahedral-encode a unit normal into two
[-1, 1]lanes. - quantize_
colors - Quantize
[f32; 4]colors toUnorm8x4, clamping out-of-range components. - vertex_
count_ 🔒of - The vertex count a stream’s enabled channels agree on, or 0 for a stream with no channels.
Type Aliases§
- Compressed
Color - One vertex color:
Unorm8x4, straight (non-premultiplied) linear RGBA. - Compressed
Joints - One vertex’s joint indices:
Uint16x4. - Compressed
Normal - One compressed vertex normal:
Snorm16x2, octahedral-encoded. - Compressed
Position - One compressed vertex position:
Snorm16x4relative to the mesh AABB. - Compressed
Uv - One compressed vertex UV:
Snorm16x2remapped byMeshMetadata::uv_min_and_extents. - Compressed
Weights - One vertex’s joint weights:
Unorm16x4, summing to 1. - Joint
Matrix - One joint’s skinning matrix: the joint’s transform times the inverse of the bind-pose transform, applied to a vertex in the mesh’s local space.