int-pack-vec
v1.0.1
Published
For those times where you want to pack an integer into a vec on the gpu, and then unpack it back in javascript. Useful when constrained to a uint8 framebuffer because your device does not properly handle writing to a float framebuffer even though it suppo
Downloads
164
Readme
int-pack-vec
For those times where you want to pack an integer into a vec on the gpu, and then unpack it back in javascript. Useful when constrained to a uint8 framebuffer because your device does not properly handle writing to a float framebuffer even though it supports the texture float extension. As happened to me with iOS debugging a mixmap
picking feature.
example
The intended use of the package is displayed within the example file.
api
In glsl you can pack int values into the frag color using glslify
and the following line to import the module:
#pragma glslify: pack = require('int-pack-vec/pack.glsl');
Once you read your value from the frame buffer, you can use the decode function to get your original value back:
const { decodeVec3 } = require('int-pack-vec')
const vec4 = regl.read({
framebuffer,
x: 0,
y: 0,
width: 1,
height: 1,
})
const decoded = decodeVec3(vec4.slice(0, 3))