Module math

Source
Expand description

Mathematical helper types and functions.

Primarily this module adds some traits to help using glam types on the GPU without panicking, as well as a few traits to aid in writing generic shader code that can be run on the CPU.

Lastly, it provides some common geometry and constants used in many shaders.

Structs§

ConstTexture
A CPU texture with no dimensions that always returns the same value when sampled.
CpuCubemap
A CPU-side cubemap texture.
CpuTexture2d
CpuTexture2dArray
GpuRng
An PCG PRNG that is optimized for GPUs, in that it is fast to evaluate and accepts sequential ids as it’s initial state without sacrificing on RNG quality.

Constants§

CLIP_QUAD_CCW
CLIP_SPACE_COORD_QUAD_CCW
CLIP_SPACE_COORD_QUAD_CCW_BL
CLIP_SPACE_COORD_QUAD_CCW_BR
CLIP_SPACE_COORD_QUAD_CCW_TL
CLIP_SPACE_COORD_QUAD_CCW_TR
CUBE
Points on the unit cube that create a triangle-list mesh.
POINTS_2D_TEX_QUAD
UNIT_INDICES
Triangle faces of the unit cube, winding CCW.
UNIT_POINTS
Points around the unit cube.
UNIT_QUAD_CCW
UV_COORD_QUAD_CCW

Traits§

Fetch
Float
Generic trait for floating point numbers
IsMatrix
Additional/replacement methods for glam matrix types.
IsSampler
IsVector
Additional/replacement methods for glam vector types.
Sample2d
Sample2dArray
SampleCube
Zero
Defines an additive identity element for Self.

Functions§

clamp
A value bounded by a minimum and a maximum
convert_pixel_to_ndc
Convert a pixel coordinate in screen space (origin is top left, Y increases downwards) to normalized device coordinates (origin is center, Y increses upwards).
convex_mesh
distance_to_line
Quantize an f32
hex_to_vec4
Convert a color from a hexadecimal number (eg. 0x52b14eff) into a Vec4.
is_inside_clip_space
luma_u8_to_vec4
reflect
scaled_f32_to_u8
Convert an f32 in range 0.0 - 1.0 into a u8 in range 0-255.
scaled_u8_to_f32
Convert a u8 in range 0-255 to an f32 in range 0.0 - 1.0.
scaled_u32_to_u8
Convert a u32 in rang 0-u32::MAX to a u8 in rang 0-255.
signum_or_zero
Returns 1.0 if n is greater than or equal to 0.0. Returns 1.0 if n is greater than or equal to -0.0. Returns -1.0 if n is less than 0.0. Returns 0.0 if n is NaN.
smoothstep
step_ge
Return 1.0 when value is greater than or equal to edge and 0.0 where value is less than edge.
step_le
Return 1.0 when value is less than or equal to edge and 0.0 when value is greater than edge.
triangle_face_normal
unit_cube