forked from olange/learning-webgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbose-truchet-tile.glsl
68 lines (60 loc) · 1.7 KB
/
bose-truchet-tile.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
61
62
63
64
65
66
67
68
// Title: A Truchet Tile pattern
// Author: pjkarlik
// Adapted from https://github.com/pjkarlik/TruchetTiles/blob/master/src/shader/truchet/fragmentShader.js
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265358979323846264
uniform vec2 u_resolution; // Canvas size (width,height)
uniform vec2 u_mouse; // mouse position in screen pixels
uniform float u_time; // Time in seconds since load
float nSeed = 0.34999999999999998;
bool lineMode = false;
float tSize = 0.10000000000000001;
vec2 hash2( vec2 p) {
vec2 o = (p+0.5)/256.0;
return o;
}
float goldNoise( vec2 coord, float seed){
float phi = 1.61803398874989484820459 * 00000.1;
float pi2 = PI * 00000.1;
float sq2 = 1.41421356237309504880169 * 10000.0;
float temp = fract(
sin(
dot(
coord*(seed+phi), vec2(phi, pi2)
)
) * sq2
);
return temp;
}
vec3 pattern( vec2 uv) {
vec2 grid = floor(uv);
vec2 subuv = fract(uv);
float mult = 0.5;
float dnoise = goldNoise(grid, nSeed);
vec2 rand = hash2(grid);
float shade = 0.;
float df;
float check = dnoise;
if( check <= .25 ) {
df = subuv.x - subuv.y; // tl
} else if( check <= .5 ) {
df = 1. - subuv.y - subuv.x;
} else if( check <= .75 ) {
df = subuv.y - subuv.x;
} else if( check <= 1. ) {
df = subuv.y - 1. + subuv.x;
}
shade = smoothstep(.0, -.02, df);
if (lineMode)
shade += smoothstep(.02, .04, df);
return vec3( shade );
}
void main() {
float fScale = (tSize == 0.0) ? max( u_resolution.x, u_resolution.y) : 1.0 / tSize;
vec2 uv = (gl_FragCoord.xy - 0.5 * u_resolution.xy) / min( u_resolution.y, u_resolution.x);
uv *= fScale;
vec3 colour = pattern(uv);
gl_FragColor = vec4( colour,colour.r);
}