Crates.io | normal_pack |
lib.rs | normal_pack |
version | 0.1.4 |
source | src |
created_at | 2024-07-18 02:20:34.069076 |
updated_at | 2024-07-22 16:18:33.921933 |
description | Compresses normal vectors (or any 3D unit vector) using Octahedron encoding. |
homepage | |
repository | https://github.com/Davidster/normal_pack |
max_upload_size | |
id | 1306841 |
size | 71,915 |
This lossy compression scheme is able to achieve a compression ratio as high as 6:1 with an average error rate of less than 1 degree, depending on which representation is chosen.
let normal = [-0.5082557, 0.54751796, 0.6647558];
let encoded = normal_pack::EncodedUnitVector3U8::encode(normal);
let decoded = encoded.decode();
assert_eq!(decoded, [-0.52032965, 0.5473598, 0.6554802]);
It is common for 3D renderers to be bottlenecked by memory bandwidth, such as when loading normals from VRAM for high-poly meshes to supply to your vertex shader. A smaller memory footprint for your normals corresponds to memory bandwidth savings and higher FPS in such scenarios.
The teapot
example generates a reference visual and contains the wgsl code required to decode the vector in a shader.
The skybox used in the example is the work of Emil Persson, aka Humus. http://www.humus.name