47 [[maybe_unused]]
int bandwidth) {
48 const int fine = repeats * 48, medium = repeats * 12;
49 const float a = noise(
u,
v, 4, 4,
seed),
b = noise(
u,
v, medium, medium,
seed + 13);
50 const float c = noise(
u,
v, fine, fine,
seed + 71);
51 const float d = noise(
u,
v, std::max(2, fine / 2), std::max(2, fine / 2),
seed + 133);
52 const float micro = .6f *
c + .4f *
d;
55 const float x = std::sin(3.14159265f * (
u - .25f));
56 const float y = std::sin(3.14159265f * (
v - .5f)) * .65f;
57 const float radius = std::sqrt(
x *
x +
y *
y + .03f);
58 const float warp = .9f * (noise(
u,
v, 4, 6,
seed + 3) - .5f) + .16f * (noise(
u,
v, 12, 8,
seed + 4) - .5f);
63 const int ringIndex = int(std::floor(
phase));
65 const float width = .04f + .10f * growth.
hash01(ringIndex, 0);
69 const float pore = std::pow(std::max(0.f, 1.f - vessel * 2.1f), 3.f);
71 return {.68f - .14f * latewood - .25f *
pore + .35f * (ringTone - .5f) + .10f * (
a - .5f),
72 .5f - .008f * latewood - .32f *
pore + .012f * (micro - .5f), .36f + .42f *
pore + .12f * latewood};
75 const int threads = std::max(2, (std::min(repeats * 10, std::max(2, fine / 2)) / 2) * 2);
76 const float x =
u * float(threads),
y =
v * float(threads);
77 const float sx = .5f + .5f * std::cos(tau *
x),
sy = .5f + .5f * std::cos(tau *
y);
79 const float over = .5f + .5f * std::cos(3.14159265f *
x) * std::cos(3.14159265f *
y);
80 const float warp = std::pow(
sx, .6f) * (.32f + .68f * over);
81 const float weft = std::pow(
sy, .6f) * (1.f - .68f * over);
82 const float crown = std::max(
warp, weft);
83 const float fiber = noise(
u,
v, fine, fine,
seed + 19);
84 return {.38f + .33f * crown + .12f * (fiber - .5f), .5f + .46f * (crown - .5f) + .035f * (fiber - .5f),
85 .65f + .30f * (1.f - crown)};
90 const int lines = repeats * (aluminum ? 90 : 70);
91 const uint32_t grainSeed =
seed + (aluminum ? 207u : 43u);
93 .6f * noise(
u,
v, 8,
lines, grainSeed) + .4f * noise(
u,
v, 24,
lines / 2, grainSeed + 7);
94 const float scratch = std::pow(std::max(0.f, 1.f - groove * 2.2f), 3.f);
95 return {.5f + (aluminum ? .025f : .045f) * (groove - .5f), .5f - (aluminum ? .045f : .075f) * scratch,
96 .28f + .40f * groove};
100 return {.5f + .018f * (
a - .5f), .5f + .0015f * (micro - .5f), .25f + .12f *
b};
103 const int count = std::min(std::max(3, repeats * 12), std::max(3, fine / 2));
108 const int cx = int(std::floor(
px)),
cy = int(std::floor(
py));
110 for (
int j = -1; j <= 1; ++j)
111 for (
int i = -1; i <= 1; ++i) {
112 const int ix =
cx + i, iy =
cy + j;
114 const float dx =
px - float(ix) -
h,
dy =
py - float(iy) - hashes.
hash01(ix + 19, iy + 31);
118 (1.f - smooth(.025f, .11f, std::abs(
across))) * (1.f - smooth(.20f, .48f, std::abs(along)));
119 fibers = std::max(fibers, fiber);
121 return {.64f + .10f * (
a - .5f) + .12f * (micro - .5f) - .18f * fibers,
122 .5f + .05f * (micro - .5f) + .035f * fibers, .65f + .22f * micro};
128 const float flow =
v + .08f * (noise(
u,
v, 8, 8,
seed + 19) - .5f);
129 const float across =
u +
v + .06f * (noise(
u,
v, 12, 12,
seed + 20) - .5f);
130 const int veins = std::clamp(repeats, 2, 12);
131 float core = 0.f, halo = 0.f, forks = 0.f;
132 for (
int i = 0; i < veins; ++i) {
133 const float phase = tau *
n.hash01(i, 1);
134 const float center = (float(i) + .2f + .6f *
n.hash01(i, 2)) /
float(veins) +
135 .15f * std::sin(tau * flow +
phase) +
136 .045f * std::sin(tau * 3.f * flow +
phase * 1.7f);
137 const float width = .004f + .008f * noise(
u,
v, 8, 8,
seed + uint32_t(i));
139 const float strength = .65f + .35f *
n.hash01(i, 3);
142 for (
int j = 0; j < 3; ++j) {
143 const float start =
n.hash01(i, j + 10);
144 const float t = (flow -
start) - std::floor(flow -
start);
145 const float length = .18f + .24f *
n.hash01(i, j + 20);
147 const float direction =
n.hash01(i, j + 30) > .5f ? 1.f : -1.f;
148 const float branch =
center +
direction *
t * (.35f + .45f *
n.hash01(i, j + 40)) +
149 .012f * std::sin(tau * 5.f *
t +
phase) * smooth(0.f, .06f,
t);
150 const float d = std::abs((
across - branch) - std::floor(
across - branch + .5f));
151 forks = std::max(forks, (1.f - smooth(.0015f, .005f,
d)) * support);
154 const float cloud = .6f * noise(
u,
v, repeats * 3, repeats * 3,
seed + 45) +
155 .4f * noise(
u,
v, repeats * 7, repeats * 7,
seed + 46);
156 return {.68f - .30f * core - .16f * forks - .08f * halo - .32f * cloud, .5f + .003f * (micro - .5f),
161 const float aggregate = .6f * noise(
u,
v, repeats * 10, repeats * 10,
seed + 51) +
162 .4f * noise(
u,
v, repeats * 22, repeats * 22,
seed + 52);
163 const Cell pores =
cell(
u,
v, std::max(3, repeats * 3),
seed + 7);
164 const float pore = (1.f - smooth(.025f, .12f, pores.distance)) * smooth(.50f, .78f,
a);
165 return {.52f + .28f * (
a - .5f) + .32f * (aggregate - .5f) - .20f *
pore,
166 .5f + .65f * (aggregate - .5f) + .12f * (micro - .5f) - .10f *
pore, .62f + .26f * aggregate};
169 const float grains = .6f * noise(
u,
v, repeats * 12, repeats * 12,
seed + 53) +
170 .4f * noise(
u,
v, repeats * 24, repeats * 24,
seed + 54);
171 const Cell crust =
cell(
u,
v, std::max(3, repeats * 8),
seed + 37);
172 const float raised = 1.f - smooth(.10f, .42f, crust.distance);
173 return {.5f + .24f * (
a - .5f) + .34f * (grains - .5f) + .10f * raised,
174 .5f + .65f * (grains - .5f) + .22f * (raised - .3f), .65f + .30f * grains};
177 const float grain = .6f * noise(
u,
v, repeats * 16, repeats * 16,
seed + 61) + .4f * micro;
178 return {.5f + .04f * (
a - .5f) + .04f * (
grain - .5f), .5f + .42f * (
grain - .5f), .65f + .3f *
grain};
181 return {.5f + .025f * (
a - .5f), .5f + .032f * (
b - .5f) + .012f * (micro - .5f), .35f + .25f *
b};
183 const float peel = .65f * noise(
u,
v, repeats * 14, repeats * 14,
seed + 81) +
184 .35f * noise(
u,
v, repeats * 28, repeats * 28,
seed + 82);
185 return {.5f + .025f * (
a - .5f), .5f + .42f * (peel - .5f) + .06f * (micro - .5f), .35f + .35f * peel};
188 return {.5f + .008f * (
a - .5f), .5f + .0005f * (micro - .5f), .5f + .03f * micro};