Premultiply.js 564 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
const React = require("react-native");
const GL = require("gl-react-native");

const shaders = GL.Shaders.create({
  Premultiply: {
    frag: `
precision highp float;

varying vec2 uv;
uniform sampler2D t;

void main () {
  vec4 c = texture2D(t, uv);
  c.rgb *= c.a;
  gl_FragColor = c;
}
`
  }
});

class Premultiply extends GL.Component {
  render () {
    const { children: t, ...rest } = this.props;
    return <GL.View
      {...rest}
      opaque={false}
      shader={shaders.Premultiply}
      uniforms={{ t }}
    />;
  }
}

module.exports = Premultiply;