forked from patriciogonzalezvivo/thebookofshaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2d-random-dots.frag
41 lines (30 loc) · 959 Bytes
/
2d-random-dots.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
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
float rows = 10.0;
float circle(vec2 st, float radius){
vec2 pos = vec2(0.5)-st;
radius *= 0.75;
return 1.-smoothstep(radius-(radius*0.01),radius+(radius*0.01),dot(pos,pos)*3.14);
}
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
void main(){
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
st *= 10.0;
// Offset every other row
st.x -= step(1., mod(st.y,2.0)) * 0.5;
vec2 ipos = floor(st); // integer position
vec2 fpos = fract(st); // float position
// Move Right
ipos += vec2(floor(u_time*-8.),0.);
float pct = random(ipos);
pct *= circle(fpos, 0.5);
// pct = step(0.1+u_mouse.x/u_resolution.x,pct);
// pct = 1.-pct;
gl_FragColor = vec4(vec3(pct),1.0);
}