-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path092-2d-random.glsl
32 lines (23 loc) · 931 Bytes
/
092-2d-random.glsl
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
#ifdef GL_ES
precision mediump float;
#endif
#include "./libs/random.glsl"
uniform vec2 u_resolution;
uniform float u_time;
// trick to devide the screen in cell and give to each cell a random id
// P.S. do you remember this one? we did it with the truchet pattern!
void main(){
//vec2 mouse = u_mouse.xy / u_resolution.xy
vec2 st = gl_FragCoord.xy / u_resolution.xy;
st *= 5.0; // Scale the coordinate system by 10
vec2 ipos = floor(st); // get the integer coords
vec2 fpos = fract(st); // get the fractional coords
// Assign a random value based on the integer coord
vec3 color = vec3(rand( ipos ));
// Uncomment to see the subdivided grid
//color = vec3(fpos,0.0);
// exercise,
// 1 can you use the random id tick to introduce randomness in a pattern?
// 2 can you think about a sketch that uses random but more then 2 colors?
gl_FragColor=vec4(vec3(color), 1.0);
}