GithubHelp home page GithubHelp logo

rgba-to-float's Introduction

rgba-to-float

stable

Packs a RGBA color into an ABGR-encoded float. This is useful in WebGL to interleave color data into a Float32Array, but only using a single float for RGBA.

var pack = require('rgba-to-float')

//packs RGBA into a float,
var color = pack(0, 255, 128, 127)

This will only work in browsers that implement typed arrays correctly.

precision

This masks high bits to avoid NaN values, and has a slight amount of precision loss. In the vertex shader you may want to bias it so that 0.0 and 1.0 alpha produces expected results.

attribute vec4 color;
varying vec4 v_color;

void main() {
    v_color = color;
    v_color.a = color.a * (255.0/254.0);
    //...
}

Usage

NPM

color = pack(r, g, b, a)

Packs the red, green, blue and alpha channels (0 - 255) into a single float, encoded as ABGR.

License

MIT, see LICENSE.md for details.

rgba-to-float's People

Contributors

mattdesl avatar

Stargazers

Alexander Schumacher avatar Terkel avatar Fritz Lekschas avatar  avatar

Watchers

Andor Salga avatar Miguel Moraleda avatar Max Rusan avatar Tomasz Dysinski avatar Mikko Haapoja avatar James Cloos avatar  avatar Nick Poisson avatar  avatar Brendan Neufeld avatar Jeremias Menichelli avatar Mauricio Salazar avatar Marcelo Rodriguez avatar max avatar Felipe Vega avatar Chris avatar Guillermo Figueroa Mesa avatar  avatar Santiago D'Antuoni avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.