glsl-read-float
Workaround for reading floating point values back from the GPU using GLSL.
Example
var triangle = var fit = var getContext = var glslify = var unpackFloat = var canvas = documentbodyvar gl = window var shader = gl { var num = Math //Draw shader shader shaderuniformsf = num //Read back the float var buffer = 4 gl var unpacked = //Log output to console console}
Install
npm install glsl-read-float
API
GLSL
# packFloat = require(glsl-read-float)
vec4 packed = packFloat(float f)
Packs a floating point number into an 8bit RGBA color vector, which can be written to the display using gl_FragColor
, for example.
f
is afloat
number
Returns A packed vec4
encoding the value of f
JavaScript
var unpackFloat =
var f = unpackFloat(x, y, z, w)
Unpacks a packed vec4
into a single floating point value.
x
is the first component of the packed floaty
is the second component of the packed floatz
is the third component of the packed floatw
is the fourth component of the packed float
Returns A number which is the unpacked value of the floating point input.
Note This module doesn't handle denormals or floats larger than Math.pow(2, 127)
Credits
Originally based on a routine by @ultraist. You can find his blog here: http://ultraist.hatenablog.com/
Newer version rewritten by Mikola Lysenko. MIT License (c) 2014