Saturation.js 759 Bytes
Newer Older
1 2 3 4
const React = require("react-native");
const GL = require("gl-react-native");

const shaders = GL.Shaders.create({
5
  saturation: {
6 7 8 9 10 11 12 13
    frag: `
precision highp float;
varying vec2 uv;
uniform sampler2D image;
uniform float factor;

void main () {
  vec4 c = texture2D(image, uv);
14 15 16
  // Algorithm from Chapter 16 of OpenGL Shading Language
  const vec3 W = vec3(0.2125, 0.7154, 0.0721);
  gl_FragColor = vec4(mix(vec3(dot(c.rgb, W)), c.rgb, factor), c.a);
17 18 19 20 21
}
    `
  }
});

22
class Saturation extends React.Component {
23 24 25
  render () {
    const { width, height, factor, image } = this.props;
    return <GL.View
26
      shader={shaders.saturation}
27 28 29 30 31 32 33
      width={width}
      height={height}
      uniforms={{ factor, image }}
    />;
  }
}

34
module.exports = Saturation;