Creating non-overlapping tiles without jumping through too many loops can be quite a challenge. In such cases, code examples from the Shadertoy community can be really inspiring to us Houdini artists. This original code written by a user called fizzer cleverly offsets a checkerboard and supports scaling as well as shifting the entire pattern.
A primitive wrangle creates tiles based on randomized world positions:
vector2 s = chu('scale');
vector2 t = chu('translate');
vector2 uv = (set(v@P.x, v@P.z) + t) / s;
vector2 f = frac(uv);
vector2 c = floor(uv);
vector2 offset;
vector2 tile = c;
float val_0 = rand(c);
int check = (int(c[0]) + int(c[1])) & 1;
tile[check] += f[check] > val_0;
offset[check] = f[check] > val_0 ? 1.0 : -1.0;
float val_1 = rand(c + offset);
tile[check ^ 1] += f[check ^ 1] > val_1;
i@tile = random_fhash(tile[0], tile[1]);
In uv we offset and scale the position attribute. The result gets split up in fractional f and integer c. After declaring offset and tile we generate random values for val_0 and val_1 which will be compared with f. For orient we check if the sum of the integer components of c is even or odd using a bitwise & operation with 1. Next, orient ^ 1 flips the value stored in orient based on whether the sum of the x and y coordinates in c was even or odd.
The primitives get split up based on the tile attribute and a divide node removes inner edges, which leaves us with clean tiles that can be projected onto surfaces or used as a base for texturing.