Copy.js 711 Bytes
Newer Older
1 2
const GL = require("gl-react");
const React = GL.React;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
3 4 5 6 7 8 9 10

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

varying vec2 uv;
uniform sampler2D t;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
11
uniform bool preventAlphaMult;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
12 13

void main () {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
14 15 16 17 18
  vec4 c = texture2D(t, uv);
  if (preventAlphaMult) // (I know if() in glsl is not performant. don't do this. It's just for readability purpose here)
    gl_FragColor = c / sqrt(c.a);
  else
    gl_FragColor = c;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
19 20 21 22 23
}
`
  }
});

24 25
module.exports = GL.createComponent(
  ({ width, height, children: t, last, ...rest }) =>
26
  <GL.Node
27 28 29 30 31 32 33 34
    {...rest}
    shader={shaders.Copy}
    width={width}
    height={height}
    uniforms={{ t, preventAlphaMult: !last }}
  />,
  { displayName: "Copy" }
);