-
Notifications
You must be signed in to change notification settings - Fork 322
/
camera.js
46 lines (40 loc) · 924 Bytes
/
camera.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
/*
tags: basic
<p>This example shows how to implement a movable camera with regl.</p>
*/
const regl = require('../regl')()
const bunny = require('bunny')
const normals = require('angle-normals')
const camera = require('./util/camera')(regl, {
center: [0, 2.5, 0]
})
const drawBunny = regl({
frag: `
precision mediump float;
varying vec3 vnormal;
void main () {
gl_FragColor = vec4(abs(vnormal), 1.0);
}`,
vert: `
precision mediump float;
uniform mat4 projection, view;
attribute vec3 position, normal;
varying vec3 vnormal;
void main () {
vnormal = normal;
gl_Position = projection * view * vec4(position, 1.0);
}`,
attributes: {
position: bunny.positions,
normal: normals(bunny.cells, bunny.positions)
},
elements: bunny.cells
})
regl.frame(() => {
regl.clear({
color: [0, 0, 0, 1]
})
camera(() => {
drawBunny()
})
})