vector p = @P;
// Center control, optional
p -= chv("pivot");
// Scale the cellular pattern
p *= chf("scale");
// Rotation controls in degrees
float rx = radians(chf("rotate_x"));
float ry = radians(chf("rotate_y"));
float rz = radians(chf("rotate_z"));
matrix3 m = ident();
rotate(m, rx, {1, 0, 0});
rotate(m, ry, {0, 1, 0});
rotate(m, rz, {0, 0, 1});
// Rotate the cellular noise space
p *= m;
// Directional stretch makes the rotation visible
p.x *= chf("stretch_x");
p.y *= chf("stretch_y");
p.z *= chf("stretch_z");
float f1, f2;
vector pos1, pos2;
vnoise(
p,
chf("jitter"),
chi("seed"),
f1,
f2,
pos1,
pos2
);
// Border calculation
float edge = f2 - f1;
float border = 1.0 - smooth(
chf("border_width"),
chf("border_width") + chf("softness"),
edge
);
// Cell color value
float cell = rand(pos1 + chi("seed"));
// Final result
float result = lerp(cell * chf("cell_brightness"), 1.0, border);
@Cd = set(result, result, result);
f@cell_border = border;
f@cell_value = cell;
f@cell_result = result;