Skip to content

Engine → Renderer

mesh_asset.h

The CPU mesh asset. Geometry is stored in the two GPU streams: stream 0 holds positions (RGB32_FLOAT), stream 1 the packed attributes (32 bytes: normal and tangent as RGBA16_SNORM with the tangent sign in the normal's w, uv0 as RG32_FLOAT, uv1 as RG16_FLOAT, colour as RGBA8_UNORM). Indices are R32_UINT. Shadow and depth passes bind stream 0 only. Positions and indices stay resident for the editor's CPU picking (cpu_geometry).

Structs

File Description
cpu_geometry_view Positions and indices for CPU picking.
mesh_geometry Unpacked geometry as importers produce it. Optional attributes are either empty or one per position; missing normals are computed flat per face, missing tangents as the tangent_generation given to from_geometry says (from the UV derivatives by default), missing uv1 is zero and missing colours are white.
mesh_streams
packed_vertex_attributes Stream 1 of a vertex (32 bytes).
submesh

Classes

File Description
mesh_asset
mesh_loader The conjure.renderer.mesh loader: parses the blob on the load job, finalise is trivial, the fallback is the unit cube.

Enumerations

tangent_generation

enum class tangent_generation : u8 {
    FROM_UVS = 0,
    FROM_NORMAL
};

How mesh_asset::from_geometry builds the tangents of a geometry that carries none. FROM_UVS takes them from the uv0 derivatives of the triangles around each vertex, made perpendicular to the normal, with the handedness of the UV winding: the frame a tangent-space normal map needs. A geometry without uv0, and a vertex whose UVs give no direction (degenerate or cancelling triangles), gets the FROM_NORMAL tangent. FROM_NORMAL reads no UV: the tangent is a unit vector perpendicular to the normal, handedness +1. Lighting works with it; a tangent-space normal map does not shade correctly, because the tangent does not follow the texture.

Constants

Name Type Value Description
MESH_ASSET_TYPE_NAME inline constexpr std::string_view "conjure.renderer.mesh"
MESH_BLOB_VERSION inline constexpr u32 1

Macros

CONJURE_DECLARE_ASSET_TYPE

CONJURE_DECLARE_ASSET_TYPE(conjure::renderer::mesh_asset, "conjure.renderer.mesh")

Functions

Public

pack_half

[[nodiscard]] CONJURE_API u16 pack_half(
    f32 value) noexcept;

IEEE 754 half precision conversion (round to nearest even; out-of-range values saturate to infinity, NaN stays NaN).

pack_rgba8

[[nodiscard]] CONJURE_API u32 pack_rgba8(
    const math::vec4 &colour) noexcept;

Packs a colour with components in [0, 1] into RGBA8 (red in the low byte).

pack_snorm16

[[nodiscard]] CONJURE_API i16 pack_snorm16(
    f32 value) noexcept;

Packs a value in [-1, 1] into a 16-bit signed normalised integer (D3D/Vulkan SNORM rules).

pack_vertex_attributes

[[nodiscard]] CONJURE_API packed_vertex_attributes pack_vertex_attributes(
    const math::vec3 &normal,
    const math::vec3 &tangent,
    f32 tangentSign,
    const math::vec2 &uv0,
    const math::vec2 &uv1,
    const math::vec4 &colour) noexcept;

Packs one vertex's attributes. The normal and tangent are normalised first (a zero vector packs to +Z / +X); tangentSign is the handedness stored in the normal's w.

unpack_half

[[nodiscard]] CONJURE_API f32 unpack_half(
    u16 value) noexcept;

unpack_rgba8

[[nodiscard]] CONJURE_API math::vec4 unpack_rgba8(
    u32 packed) noexcept;

unpack_snorm16

[[nodiscard]] CONJURE_API f32 unpack_snorm16(
    i16 value) noexcept;