-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path062-pattern-truchet-random.glsl
60 lines (47 loc) · 1.36 KB
/
062-pattern-truchet-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
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
#ifdef GL_ES
precision mediump float;
#endif
//glslViewer col-invert-sqaures.frag ../textures/pink-necked-green-pigeon-big.jpg
#define PI 3.14159265359
#define SPEED.2
uniform float u_time;
uniform vec2 u_resolution;
uniform sampler2D u_tex0;
// returns a random float value given a vec2
float hash(vec2 p){
p=fract(p*vec2(234.34,435.345));
p+=dot(p,p+34.23);
return fract(p.x*p.y);
}
float myShape(vec2 gv){
// Try to play with the functions that
// you know. Try to came up with your own
// shape.
//return abs(gv.y + gv.x);
return abs(abs(gv.x+gv.y)-.5);
}
void main(void){
vec2 uv=(2.*gl_FragCoord.xy-u_resolution.xy)/u_resolution.y;
vec3 col=vec3(0.);
// 6) Animate
// uv += u_time * 0.3;
uv*=8.;
// 2) each cell has now an id
vec2 id=floor(uv);
uv=fract(uv)-.5;
// 3) we can use the id to give a random value to each cell.
float n=hash(id);// random between 0 and 1
// 5) random flip the x direction only if a condition is match
if(n<.5){
uv.x*=-1.;
};
// 4) Try to see what happens if you flip the x direction
//uv.x *= -1.;
float width=.25;
// 1) draw something. Possible something that is not simmetric
float d=myShape(uv);
float mask=d-width;
mask=smoothstep(.01,-.01,mask);
col = mix(col, vec3(1.), mask);
gl_FragColor=vec4(sqrt(col),1.);
}