-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Packing ints into a vec4 in a shader does not currently work #2
Comments
WebGL2 will come with bit-shift operators and higher-precision textures, both of which can fix this issue |
ThreeJS WebGL2Renderer Issue: mrdoob/three.js#9965 |
You can do it webgl you just need to do the shifting youtself via multiplies /**
* Properly encoding 32 bit float in rgba from here:
* http://www.gamedev.net/topic/486847-encoding-16-and-32-bit-floating-point-value-into-rgba-byte-texture/
*/
vec4 pack( const in float depth ) {
const float toFixed = 255.0/256.0;
vec4 result = vec4(0);
result.r = fract(depth*toFixed*1.0);
result.g = fract(depth*toFixed*255.0);
result.b = fract(depth*toFixed*255.0*255.0);
result.a = fract(depth*toFixed*255.0*255.0*255.0);
return result;
}
void main() {
gl_FragColor = pack(gl_FragCoord.z);
} |
Thanks @DanielJoyce! I'd considered packing the values manually -- I'll probably get around to it at some point! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently bitwise operations are not available in the current version of webgl (??!!!??), meaning
int
s anduint
s can't easily be packed into thevec4
color output and unpacked in javascript again.It may be possible to use these functions to emulate bitwise operations.
The text was updated successfully, but these errors were encountered: