-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexamples.js
63 lines (52 loc) · 1.49 KB
/
examples.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
/* global THREE */
window.GRAPH_EXAMPLES = {
step: {
shaderFunc: "float y(float x) {\n return step(0.5, x);\n}",
},
smoothstep: {
shaderFunc: "float y(float x) {\n return smoothstep(0.0, 1.0, x);\n}",
},
multiSmoothstep: {
shaderFunc: [
"float y(float x) {",
" return smoothstep(0.0, 0.5, x) - smoothstep(0.5, 1.0, x);",
"}",
].join("\n"),
},
gradientNoise: {
shaderFunc: `vec2 vec2Random(vec2 st) {
st = vec2(dot(st, vec2(0.040,-0.250)),
dot(st, vec2(269.5,183.3)));
return -1.0 + 2.0 * fract(sin(st) * 43758.633);
}
float gradientNoise(vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = smoothstep(0.0, 1.0, f);
return mix(mix(dot(vec2Random(i + vec2(0.0,0.0)), f - vec2(0.0,0.0)),
dot(vec2Random(i + vec2(1.0,0.0)), f - vec2(1.0,0.0)), u.x),
mix(dot(vec2Random(i + vec2(0.0,1.0)), f - vec2(0.0,1.0)),
dot(vec2Random(i + vec2(1.0,1.0)), f - vec2(1.0,1.0)), u.x), u.y);
}
float y(float x) {
return gradientNoise(vec2(x, 1.0));
}`,
limits: new THREE.Box2(new THREE.Vector2(0, -1), new THREE.Vector2(20, 1)),
},
breathe: {
shaderFunc: `float breathe(float k, float t) {
t = fract(t); // period of 1 for the animation
t *= 2.0;
if (t < 1.0) {
return 1.0 - exp(-t/k);
} else {
t -= 1.0;
return exp(-t/k);
}
}
float y(float x) {
return breathe(0.1, x);
}`,
limits: new THREE.Box2(new THREE.Vector2(-0.1, -0.6), new THREE.Vector2(5.1, 1.6)),
},
};