Skip to content

Instantly share code, notes, and snippets.

View gashtio's full-sized avatar

Nikola Vasilev gashtio

View GitHub Profile
@zeux
zeux / edge-encode.cpp
Last active December 8, 2018 06:25
8-bit (unsigned) floating point encoding that is designed to be very efficient to decode on DX9/GLES2 class GPUs
// Can be used to efficiently encode floating point values from a limited range ([0..65k]) into a byte
// edgeDecode is optimized for GPUs (native exp2)
// edgeEncode1 is optimized for GPUs (native log2)
// edgeEncode2 is optimized for CPUs but is an approximation
// edgeEncode3 is optimized for CPUs
float edgeDecode(int e)
{
return exp2f(float(e) * (1 / 16.f)) - 1;
}