npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

glsl-read-float

v1.1.0

Published

Read floating point values back from WebGL

Downloads

31,957

Readme

glsl-read-float

Workaround for reading floating point values back from the GPU using GLSL.

Example

var triangle     = require('a-big-triangle')
var fit          = require('canvas-fit')
var getContext   = require('gl-context')
var glslify      = require('glslify')
var unpackFloat  = require("glsl-read-float")

var canvas     = document.body.appendChild(document.createElement('canvas'))
var gl         = getContext(canvas, render)

window.addEventListener('resize', fit(canvas), false)

var shader = glslify({
  vert: "\
attribute vec2 position;\
void main() {\
  gl_Position = vec4(position, 0, 1);\
}",
  frag: "\
#pragma glslify: packFloat = require(glsl-read-float)\n\
uniform highp float f;\
void main() {\
  gl_FragColor = packFloat(f);\
}",
  inline: true
})(gl)

function render() {
  var num = Math.random()

  //Draw shader
  shader.bind()
  shader.uniforms.f = num
  triangle(gl)

  //Read back the float
  var buffer = new Uint8Array(4)
  gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buffer)
  var unpacked = unpackFloat(buffer[0], buffer[1], buffer[2], buffer[3])

  //Log output to console
  console.log("expected:", num, "got:", unpacked)
}

Install

npm install glsl-read-float

API

GLSL

#pragma glslify: 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 a float number

Returns A packed vec4 encoding the value of f

JavaScript

var unpackFloat = require("glsl-read-float")

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 float
  • y is the second component of the packed float
  • z is the third component of the packed float
  • w 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