forked from patriciogonzalezvivo/lygia_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation_sprite.frag
46 lines (38 loc) · 1.41 KB
/
animation_sprite.frag
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
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_tex0; // /imgs/sprite.png
uniform vec2 u_tex0Resolution;
uniform vec2 u_resolution;
uniform float u_time;
#define SAMPLESPRITE_SAMPLER_FNC(TEX, UV) sampleNearest(TEX, UV, u_tex0Resolution)
#include "lygia/space/ratio.glsl"
#include "lygia/sample/nearest.glsl"
#include "lygia/animation/spriteLoop.glsl"
void main (void) {
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
vec2 pixel = 1.0/u_resolution.xy;
vec2 st = gl_FragCoord.xy * pixel;
st = ratio(st, u_resolution);
vec2 grid = vec2(10., 7.0);
float time = mod(u_time * 6.0, 48.0);
if (time < 6.0)
color = spriteLoop(u_tex0, st, grid, 0., 2., time);
else if (time < 12.0)
color = spriteLoop(u_tex0, st, grid, 3., 6., time);
else if (time < 18.0)
color = spriteLoop(u_tex0, st, grid, 13., 16., time);
else if (time < 24.0)
color = spriteLoop(u_tex0, st, grid, 23., 26., time);
else if (time < 30.0)
color = spriteLoop(u_tex0, st, grid, 33., 36., time);
else if (time < 36.0)
color = spriteLoop(u_tex0, st, grid, 43., 46., time);
else if (time < 42.0)
color = spriteLoop(u_tex0, st, grid, 50., 53., time);
else
color = spriteLoop(u_tex0, st, grid, 60., 65., time);
// color = sampleSprite(u_tex0, st, grid, 41.);
// color = texture2D(u_tex0, st);
gl_FragColor = color;
}