-
-
Save cloudqq/a63a4d7415345cbcdc88466b358cab57 to your computer and use it in GitHub Desktop.
glsl 32 bit unpack and pack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec4 pack (float depth) | |
{ | |
const vec4 bitSh = vec4(256 * 256 * 256, | |
256 * 256, | |
256, | |
1.0); | |
const vec4 bitMsk = vec4(0, | |
1.0 / 256.0, | |
1.0 / 256.0, | |
1.0 / 256.0); | |
vec4 comp = fract(depth * bitSh); | |
comp -= comp.xxyz * bitMsk; | |
return comp; | |
} | |
float unpack (vec4 colour) | |
{ | |
const vec4 bitShifts = vec4(1.0 / (256.0 * 256.0 * 256.0), | |
1.0 / (256.0 * 256.0), | |
1.0 / 256.0, | |
1); | |
return dot(colour , bitShifts); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment