forked from patriciogonzalezvivo/thebookofshaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ikeda-simple-grid.frag
74 lines (61 loc) · 2.28 KB
/
ikeda-simple-grid.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
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
// Author @patriciogv - 2015
// Title: Ikeda Grid
#ifdef GL_ES
precision mediump float;
#endif
// Copyright (c) Patricio Gonzalez Vivo, 2015 - http://patriciogonzalezvivo.com/
// I am the sole copyright owner of this Work.
//
// You cannot host, display, distribute or share this Work in any form,
// including physical and digital. You cannot use this Work in any
// commercial or non-commercial product, website or project. You cannot
// sell this Work and you cannot mint an NFTs of it.
// I share this Work for educational purposes, and you can link to it,
// through an URL, proper attribution and unmodified screenshot, as part
// of your educational material. If these conditions are too restrictive
// please contact me and we'll definitely work it out.
uniform vec2 u_resolution;
uniform float u_time;
float random(in float x){ return fract(sin(x)*43758.5453); }
float random(in vec2 st){ return fract(sin(dot(st.xy ,vec2(12.9898,78.233))) * 43758.5453); }
float grid(vec2 st, float res){
vec2 grid = fract(st*res);
return 1.-(step(res,grid.x) * step(res,grid.y));
}
float box(in vec2 st, in vec2 size){
size = vec2(0.5) - size*0.5;
vec2 uv = smoothstep(size,
size+vec2(0.001),
st);
uv *= smoothstep(size,
size+vec2(0.001),
vec2(1.0)-st);
return uv.x*uv.y;
}
float cross(in vec2 st, vec2 size){
return clamp(box(st, vec2(size.x*0.5,size.y*0.125)) +
box(st, vec2(size.y*0.125,size.x*0.5)),0.,1.);
}
void main(){
vec2 st = gl_FragCoord.st/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
vec3 color = vec3(0.0);
// Grid
vec2 grid_st = st*300.;
color += vec3(0.5,0.,0.)*grid(grid_st,0.01);
color += vec3(0.2,0.,0.)*grid(grid_st,0.02);
color += vec3(0.2)*grid(grid_st,0.1);
// Crosses
vec2 crosses_st = st + .5;
crosses_st *= 3.;
vec2 crosses_st_f = fract(crosses_st);
color *= 1.-cross(crosses_st_f,vec2(.3,.3));
color += vec3(.9)*cross(crosses_st_f,vec2(.2,.2));
// Digits
vec2 blocks_st = floor(st*6.);
float t = u_time*.8+random(blocks_st);
float time_i = floor(t);
float time_f = fract(t);
color.rgb += step(0.9,random(blocks_st+time_i))*(1.0-time_f);
gl_FragColor = vec4( color , 1.0);
}