-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLCH_VJ-Creature.js
More file actions
202 lines (167 loc) · 3.42 KB
/
Copy pathLCH_VJ-Creature.js
File metadata and controls
202 lines (167 loc) · 3.42 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
setResolution(1280, 720);
setFunction({
name: "virus",
type: "src",
inputs: [
{
name: "density",
type: "float",
default: 30.0
}
],
glsl: `
vec2 uv = _st * 2.0 - 1.0;
vec3 col = vec3(0.0);
for(int i = 0; i < 30; i++) {
float fi = float(i);
float seed =
fi * 17.381 +
time * 0.2;
vec2 p = vec2(
sin(seed * 1.71),
cos(seed * 2.31)
);
p += 0.4 * vec2(
sin(time * (0.3 + fi * 0.01)),
cos(time * (0.5 + fi * 0.02))
);
float size =
0.03 +
0.08 *
abs(sin(seed + time));
vec2 d = uv - p;
float r = length(d);
float body =
smoothstep(size,size*0.4,r);
float spikes = 0.0;
for(int j = 0; j < 12; j++) {
float fj = float(j);
float a =
fj *
6.28318 /
12.0;
vec2 sp =
p +
vec2(cos(a),sin(a))
* size;
float sr =
length(uv - sp);
spikes +=
smoothstep(
size*0.3,
size*0.05,
sr
);
}
vec3 virusColor =
0.5 +
0.5 *
cos(
vec3(
0.0,
2.0,
4.0
)
+ seed
+ time
);
col +=
virusColor *
(
body +
spikes * 0.2
);
}
return vec4(col,1.0);
`
})
setFunction({
name: "insect",
type: "src",
inputs: [
{
name: "density",
type: "float",
default: 24.0
},
{
name: "speed",
type: "float",
default: 1.0
}
],
glsl: `
vec2 uv = _st * 2.0 - 1.0;
float t = time * speed;
uv.x += sin(t * 0.71 + uv.y * 4.0) * 0.2;
uv.y += cos(t * 0.53 + uv.x * 5.0) * 0.2;
float a = atan(uv.y, uv.x);
float r = length(uv);
float swarm = 0.0;
for(int i = 0; i < 8; i++) {
float fi = float(i);
vec2 p = vec2(
sin(t * (0.3 + fi * 0.07) + fi * 2.3),
cos(t * (0.5 + fi * 0.05) + fi * 1.7)
);
float rr =
0.12 +
0.05 * sin(t * 2.0 + fi * 4.0);
swarm += rr / (
length(uv - p) + 0.02
);
}
float spikes =
sin(a * density + t * 3.0) *
sin(a * density * 0.5 - t * 2.0);
float membrane =
smoothstep(
0.9 + spikes * 0.15,
0.2,
r + sin(t + r * 10.0) * 0.05
);
float body =
membrane +
swarm * 0.08;
float pulse =
0.5 +
0.5 *
sin(t * 5.0);
vec3 col = vec3(
body * (0.8 + pulse),
body * abs(sin(t)),
body * abs(cos(t * 0.7))
);
return vec4(col, 1.0);
`
})
function videocap(target = o0, durationMs = 5000, options = {}) {
const {
filename = `hydra-${Date.now()}.webm`,
renderTarget = true,
restore = null,
} = options;
if (renderTarget) {
render(target);
}
if (typeof vidRecorder === "undefined") {
throw new Error("vidRecorder is not available in this Hydra environment.");
}
vidRecorder.start();
setTimeout(() => {
try {
vidRecorder.stop();
} finally {
if (typeof restore === "function") {
restore();
}
}
}, durationMs);
return {
filename,
target,
durationMs,
};
}
virus().diff(insect()).blend(o0,[1/10,9/10].reverse().ease("easeInOutHalf").smooth(1/3).fit(1/5).offset(1/7).fast(1/11)).out();
videocap(o0, 6000);