Banner.js 1.15 KB
Newer Older
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
1
import React from "react";
2 3
import GL from "gl-react";
import {Surface} from "gl-react-native";
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
const shaders = GL.Shaders.create({
  banner: {
    frag: `
precision highp float;
varying vec2 uv;
uniform float time;
void main( void ) {
	float color = 0.0;
	color += sin( uv.x * cos( time / 15.0 ) * 80.0 ) + cos( uv.y * cos( time / 15.0 ) * 10.0 );
	color += sin( uv.y * sin( time / 10.0 ) * 40.0 ) + cos( uv.x * sin( time / 25.0 ) * 40.0 );
	color += sin( uv.x * sin( time / 5.0 ) * 10.0 ) + sin( uv.y * sin( time / 35.0 ) * 80.0 );
	color *= sin( time / 10.0 ) * 0.5;
	gl_FragColor = vec4(
    smoothstep(0.0, 1.5, color),
    smoothstep(0.0, 0.5, color),
    smoothstep(1.0, 0.6, color) - smoothstep(0.1, 0.0, color),
    color
  ) * (pow(uv.y, 2.0));
}
`
  }
});

27
class Banner extends React.Component {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
28 29
  render () {
    const { width, height, time } = this.props;
30
    return <Surface width={width} height={height} backgroundColor="transparent"
31 32
      onLoad={() => console.log("Banner onLoad")}
      onProgress={e => console.log("Banner onProgress", e.nativeEvent)}>
33
      <GL.Node shader={shaders.banner} uniforms={{ time }} />
34
    </Surface>;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
35 36 37 38
  }
}

module.exports = Banner;