-
Notifications
You must be signed in to change notification settings - Fork 0
/
frag.js
89 lines (53 loc) · 1.66 KB
/
frag.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
80
81
82
83
84
85
86
87
88
89
const frag = function(items){
const textureLoop = items.map((item, index) =>{
return `
if(index == ${index}){
return texture2D(textures[${index}], uv);
}
`
}).join(" else ");
return `
#ifdef GL_ES
precision highp float;
#endif
#define MAX ${items.length}
uniform float u_time;
uniform vec2 U_resolution;
uniform float timeline;
uniform sampler2D textures[MAX];
uniform float startIndex;
uniform float endIndex;
varying vec3 v_normal;
varying vec2 v_texcoord;
${includes}
vec4 sampleColor(int index, vec2 uv){
${textureLoop}
return vec4(1.0, 1.0, 1.0, 1.0);
}
void main(void)
{
vec2 uv = v_texcoord;
uv -= 0.5;
float amplitude = 3.5;
float wave = fbm(amplitude * uv + 0.2 * u_time);
//creating fade in and fade out using timelines
float strength = smoothstep(0.0, 2.0, timeline) - smoothstep(2.0, 3.0, timeline);
float distortion = mix(1., 1.0 + strength, wave);
uv *= distortion;
uv += 0.5;
// //flip the texture
// uv.y = 1.0 - uv.y;
//get rid of extras
if(uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0 ){
discard;
}
//pick images
vec4 startTexture = sampleColor(int(startIndex), uv);
vec4 endTexture = sampleColor(int(endIndex), uv);
//tween
float changeTimeline = smoothstep(0.5, 2., timeline);
float mixer = 1.0 - step(changeTimeline, wave);
vec4 color = mix(startTexture, endTexture, mixer);
gl_FragColor = color;
}
`}