Multiply.js 705 Bytes
Newer Older
1
const GL = require("gl-react");
2
const React = require("react");
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

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

varying vec2 uv;
uniform sampler2D t1;
uniform sampler2D t2;

void main () {
  vec4 c1 = texture2D(t1, uv);
  vec4 c2 = texture2D(t2, uv);
  gl_FragColor = c1 * c2;
}
`
  }
});

22 23
module.exports = GL.createComponent(
  ({ width, height, children }) => {
24 25
    if (!children || children.length !== 2) throw new Error("You must provide 2 children to Multiply");
    const [t1, t2] = children;
26
    return <GL.Node
27 28 29 30 31
      shader={shaders.multiply}
      width={width}
      height={height}
      uniforms={{ t1, t2 }}
    />;
32 33
  },
  { displayName: "Multiply" });