-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsphere.js
48 lines (47 loc) · 1.04 KB
/
sphere.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
var regl = require('regl')()
var camera = require('regl-camera')(regl, {
distance: 4, far: 100
})
var mat4 = require('gl-mat4')
var vec3 = require('gl-vec3')
function makesphere (regl) {
var sphere = require('icosphere')(3)
var model = []
return regl({
frag: `
precision mediump float;
varying vec3 vpos;
void main () {
gl_FragColor = vec4(vpos, 1.0);
}
`,
vert: `
precision mediump float;
uniform mat4 projection, view, model;
attribute vec3 position, normal;
varying vec3 vpos;
void main () {
vpos = position;
gl_Position = projection * view * model * vec4(position,1);
}
`,
attributes: {
position: sphere.positions
},
uniforms: {
model: mat4.identity(model),
time: regl.context('time')
},
primitive: "lines",
elements: sphere.cells
})
}
var draw = {
sphere: makesphere(regl)
}
regl.frame(function (context) {
regl.clear({ color: [0,0,0,1], depth: true })
camera(function () {
draw.sphere()
})
})