Skip to content

Instantly share code, notes, and snippets.

@mzgoddard
Created August 20, 2012 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzgoddard/3405102 to your computer and use it in GitHub Desktop.
Save mzgoddard/3405102 to your computer and use it in GitHub Desktop.
// packing a float in glsl with multiplication and fract
vec4 packFloat( float depth ) {
const vec4 bit_shift = vec4(
256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bit_mask = vec4(
0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
// fract is the problem
vec4 res = fract( depth * bit_shift );
res -= res.xxyz * bit_mask;
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment