ISF - Generators - Truchet Tile
#define PI 3.14159265358979323846264
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;
} 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(RENDERSIZE.x,RENDERSIZE.y) : 1.0 / tSize;
vec2 uv = (gl_FragCoord.xy - 0.5 * RENDERSIZE.xy) / min(RENDERSIZE.y, RENDERSIZE.x);
uv *= fScale;
vec3 colour = pattern(uv);
gl_FragColor = vec4(colour,colour.r);
}