-
Notifications
You must be signed in to change notification settings - Fork 0
/
iphone.js
79 lines (78 loc) · 1.93 KB
/
iphone.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var regl = require('regl')()
var mat4 = require('gl-mat4')
var glsl = require('glslify')
var normals = require('angle-normals')
var mesh = require('./phone.json')
var camera = require('regl-camera')(regl, {
center: [0, 6, 0],
distance: 20,
theta: 0.3,
phi: 0.4
})
var rmat = []
function phone (regl){
return regl({
frag: glsl`
precision mediump float;
#pragma glslify: snoise = require('glsl-noise/simplex/4d')
varying vec3 vnormal, vpos;
uniform float t;
void main () {
vec3 p = vnormal+0.2/(snoise(vec4(vpos*0.01,sin(t)+20.5))*0.5+0.3);
float cross = abs(max(
max(sin(p.z*10.0+p.y), sin(p.y*01.0)),
sin(p.x*10.0)
));
gl_FragColor = vec4(p*cross, 1);
}`,
vert: glsl`
precision mediump float;
uniform mat4 model, projection, view;
attribute vec3 position, normal;
varying vec3 vnormal, vpos;
uniform float t;
void main () {
vnormal = normal;
vpos = position;
gl_Position = projection * view * model *
vec4(position, 1.0);
gl_PointSize = 10.0*sin(t);
}`,
attributes: {
position: mesh.positions,
normal: normals(mesh.cells, mesh.positions)
},
elements: mesh.cells,
uniforms: {
t: function(context, props){
return context.time
},
model: function(context, props){
var t = context.time
mat4.identity(rmat)
mat4.scale(rmat, rmat,[0.1,0.1,0.1])
mat4.rotateY(rmat, rmat, -t)
mat4.rotateX(rmat, rmat, -t/2.0)
mat4.rotateZ(rmat, rmat, t)
return rmat
}
},
primitive: "triangles",
blend: {
enable: true,
func: { src: 'src alpha', dst: 'one minus src alpha' }
},
cull: { enable: true }
})
}
var draw = {
phone: phone(regl)
}
regl.frame(function() {
regl.clear({
color: [0, 0, 0, 1]
})
camera(function() {
draw.phone()
})
})