Last active
August 29, 2015 14:20
-
-
Save caiwan/f378e5c7fb0f35413ee6 to your computer and use it in GitHub Desktop.
This file contains 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 packDepth(const in 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); | |
vec4 res = fract(depth * bit_shift); | |
res -= res.xxyz * bit_mask; | |
return res; | |
} | |
float unpackDepth(const in vec4 rgba_depth) { | |
const vec4 bit_shift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0); | |
float depth = dot(rgba_depth, bit_shift); | |
return depth; | |
} |
This file contains 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 packDepth(float v ) { | |
vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * v; | |
enc = fract(enc); | |
enc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0); | |
return enc; | |
} | |
float unpackDepth(vec4 rgba ) { | |
return dot( rgba, vec4(1.0, 1/255.0, 1/65025.0, 1/160581375.0) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment