-
Notifications
You must be signed in to change notification settings - Fork 0
/
cathello2.js
60 lines (59 loc) · 1.2 KB
/
cathello2.js
1
2
3
4
5
6
7
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const regl = require('regl')()
const mat4 = require('gl-mat4')
var fs = require('fs');
var image = fs.readFileSync(__dirname + '/cathello.jpg', 'base64');
var imageurl = 'data:image/png;base64,' + image
const drawCube = regl({
frag: `
precision mediump float;
uniform sampler2D tex;
varying vec2 uv;
uniform float time;
void main () {
vec2 vuv = uv*(sin(time*0.5+uv)*(0.3-0.2*0.5)+0.5+0.4);
gl_FragColor = texture2D(tex,vec2(1.0-vuv.x-0.15,vuv.y));
}`,
vert: `
precision mediump float;
attribute vec2 position;
varying vec2 uv;
uniform float time;
void main() {
uv = position;
gl_Position = vec4(1.0 - 2.0 * position, 0, 1);
}`,
attributes: {
position: [
-2, 0,
0, -2,
2, 2
]
},
uniforms: {
tex: regl.prop('texture'),
time: regl.context('time')
},
count: 3
})
require('resl')({
manifest: {
texture: {
type: 'image',
src: imageurl,
parser: (data) => regl.texture({
data: data,
mag: 'linear',
min: 'linear'
})
}
},
onDone: ({texture}) => {
regl.frame(() => {
regl.clear({
color: [0, 0, 0, 255],
depth: 1
})
drawCube({texture})
})
}
})