Oct encoding

21, Jan, 2015

Oct encoding compresses a 3D unit vector into 2 values. This is particularly handy for deferred rendering, where you want to pack a normal into a slim G buffer, or for storing a normal map in a BC5 texture. The technique involves projecting the vector onto a octahedron, then unfolding it into a square.


Oct unwrapping

I’ve made a visual testbed to compare the technique and a couple of alternatives (such as Spheremapping) at different precisions.



Shader Shed

There’s a detailed explanation in A Survey of Efficient Representations for Independent Unit Vectors. Crytek best fit normals offer better precision but require a texture lookup. c0de517e has some interesting ideas about blendable, wrappable encodings.