-
Notifications
You must be signed in to change notification settings - Fork 0
/
obj.vert
78 lines (69 loc) · 1.62 KB
/
obj.vert
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
/*{
frameskip: 1,
vertexMode: "TRIANGLES",
PASSES: [{
MODEL: { PATH: './deer.obj' },
BLEND: 'ADD',
}]
}*/
precision mediump float;
attribute vec3 position;
attribute vec3 normal;
attribute vec2 uv;
attribute float vertexId;
uniform float vertexCount;
uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
uniform sampler2D spectrum;
uniform mat3 uvTransform;
uniform float volume;
varying vec4 v_color;
varying vec2 vUv;
vec2 rot(in vec2 p, in float t) {
float s = sin(t);
float c = cos(t);
return mat2(s, c, -c, s) * p;
}
vec3 sphere(in vec3 p) {
float rz = 1. - (vertexId / 1000.) * .1;
float h = sqrt(1. - rz * rz);
return vec3(
cos(vertexId * .3 + time) * h,
sin(vertexId * .3 + time) * h,
rz
) * .3;
}
vec3 rects(in vec3 p) {
float xo = mod(floor(vertexId / 768.), 2.) - 1.;
float yo = mod(floor(vertexId / 768. / 2.), 2.) - 1.;
vec3 pRects = vec3(
mod(vertexId * 4.3, 2.0) / 2.0,
mod(vertexId * 8.3, 3.0) / 3.0,
mod(vertexId * 3.3, 4.0) / 4.0
) - .5;
pRects.xz = rot(pRects.xz, time);
pRects.x += xo * 1.3;
pRects.y += yo * 1.3;
pRects += .6;
pRects *= .4;
return pRects;
}
void main() {
vec3 pos = position;
pos *= .6;
pos.xz = rot(pos.xz, time);
// Morphing
float tt = time;
float d = mod(tt, 9.) * .5;
pos = mix(pos, sphere(pos), clamp(max(d - 3., 1.5 - d), 0., 1.));
pos = mix(pos, rects(pos), clamp(min(d - 2., 4.5 - d), 0., 1.));
pos.y *= resolution.x / resolution.y;
gl_Position = vec4(pos, 1);
v_color = vec4(
normalize(normal),
1.
);
v_color *= 1. + dot(normalize(normal), vec3(1));
v_color.a = 1.;
}