Intro.js 2.31 KB
Newer Older
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
1 2
import React from "react";
import {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
3 4
  View,
  Text,
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
5
} from "react-native";
6 7
import GL from "gl-react";
import {Surface} from "gl-react-native";
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
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 34 35 36 37 38 39

const shaders = GL.Shaders.create({
  drunkEffect: {
    frag: `
precision highp float;
varying vec2 uv;

uniform float time;
uniform float amp;
uniform float freq;
uniform float colorSeparation;
uniform sampler2D texture;
uniform float moving;

vec2 lookup (vec2 offset) {
  return mod(
    uv + amp * vec2(cos(freq*(uv.x+offset.x)+time),sin(freq*(uv.y+offset.x)+time)) + vec2(moving * time/10.0, 0.0),
    vec2(1.0));
}

void main() {
  gl_FragColor = vec4(
    vec3(
    texture2D(texture, lookup(vec2(colorSeparation))).r,
    texture2D(texture, lookup(vec2(-colorSeparation))).g,
    texture2D(texture, lookup(vec2(0.0))).b),
    1.0);
}
`
  }
});

40
class Intro extends React.Component {
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
41 42
  render () {
    const { time, fps, width, height } = this.props;
43 44 45
    return <Surface
      width={width}
      height={height}
46 47
      onLoad={() => console.log("Intro onLoad")}
      onProgress={e => console.log("Intro onProgress", e.nativeEvent)}>
48 49 50 51 52 53 54 55 56 57
      <GL.Node
        shader={shaders.drunkEffect}
        uniforms={{
          time: time,
          freq: 20 - 14 * Math.sin(time / 7),
          amp: 0.05 - 0.03 * Math.cos(time / 4),
          colorSeparation: 0.02,
          moving: 1
        }}>
        <GL.Uniform name="texture">
58
          <View style={{ flex: 1, justifyContent: "center", backgroundColor: "#111" }}>
59 60
            <Text style={{ color: "#00BDF3", fontSize: 32, letterSpacing: -1.0 }}>
              GL REACT NATIVE
61
            </Text>
62 63 64 65 66 67 68 69 70 71 72 73
            <View style={{ flex: 1, flexDirection: "row", alignItems: "center", justifyContent: "center" }}>
              <View style={{ backgroundColor: "#00FF66", marginRight: 8, width: 14, height: 14, borderRadius: 7, opacity: time%1 < 0.6 ? 1 : 0 }} />
              <Text style={{ flex: 1, color: "#00FF66", fontSize: 14 }}>
                {time.toFixed(2)}s
              </Text>
              <Text style={{ flex: 1, color: "#fff", fontSize: 14 }}>
                {(fps).toFixed(0)} fps
              </Text>
              <Text style={{ flex: 1, color: "#999", fontSize: 14 }}>
                {"<Text />"}
              </Text>
            </View>
74
          </View>
75 76 77
        </GL.Uniform>
      </GL.Node>
    </Surface>;
Gaëtan Renaudeau's avatar
Gaëtan Renaudeau committed
78 79 80 81
  }
}

module.exports = Intro;