29 return (x << k) | (x >> (32 - k));
75 a =
b = c = 0xdeadbeef + (1 << 2) + 13;
86 a =
b = c = 0xdeadbeef + (2 << 2) + 13;
98 a =
b = c = 0xdeadbeef + (3 << 2) + 13;
111 a =
b = c = 0xdeadbeef + (4 << 2) + 13;
274template<
typename T> T
static mix(T v0, T v1,
float x)
276 return (1 - x) * v0 + x * v1;
292 return (1.0 - y) * (v0 * x1 + v1 *
x) + y * (
v2 * x1 + v3 * x);
328 return z1 * (y1 * (v0 * x1 + v1 *
x) + y * (
v2 * x1 + v3 * x)) +
329 z * (y1 * (v4 * x1 + v5 * x) + y * (v6 * x1 + v7 *
x));
354 return mix(
mix(v0, v1,
v2, v3, v4, v5, v6, v7, x, y,
z),
355 mix(v8, v9, v10, v11, v12, v13, v14, v15, x, y,
z),
361 return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
366 return (condition != 0u) ? -value : value;
372 float g = 1u + (h & 7u);
379 float u = h < 4u ?
x :
y;
380 float v = 2.0 * (h < 4u ?
y :
x);
387 float u = h < 8u ?
x :
y;
388 float vt =
ELEM(h, 12u, 14u) ?
x :
z;
389 float v = h < 4u ?
y : vt;
396 float u = h < 24u ?
x :
y;
397 float v = h < 16u ?
y :
z;
398 float s = h < 8u ?
z :
w;
499 noise_grad(
hash(
X + 1,
Y + 1, Z + 1,
W + 1), fx - 1.0, fy - 1.0, fz - 1.0, fw - 1.0),
513 float precision_correction = 0.5f *
float(
math::abs(position) >= 1000000.0f);
516 position =
math::mod(position, 100000.0f) + precision_correction;
524 float(
math::abs(position.y) >= 1000000.0f));
528 position =
math::mod(position, 100000.0f) + precision_correction;
536 float(
math::abs(position.y) >= 1000000.0f),
537 float(
math::abs(position.z) >= 1000000.0f));
541 position =
math::mod(position, 100000.0f) + precision_correction;
549 float(
math::abs(position.y) >= 1000000.0f),
550 float(
math::abs(position.z) >= 1000000.0f),
551 float(
math::abs(position.w) >= 1000000.0f));
555 position =
math::mod(position, 100000.0f) + precision_correction;
587 T p,
const float detail,
const float roughness,
const float lacunarity,
const bool normalize)
594 for (
int i = 0; i <=
int(detail); i++) {
599 fscale *= lacunarity;
601 float rmd = detail - std::floor(detail);
604 float sum2 =
sum + t * amp;
605 return normalize ?
mix(0.5f *
sum / maxamp + 0.5f, 0.5f * sum2 / (maxamp + amp) + 0.5f, rmd) :
614 const float roughness,
615 const float lacunarity,
624 for (
int i = 0; i <=
int(detail); i++) {
630 const float rmd = detail -
floorf(detail);
640 T p,
const float detail,
const float roughness,
const float lacunarity,
const float offset)
642 float pwr = roughness;
648 for (
int i = 1; i <=
int(detail); i++) {
655 const float rmd = detail -
floorf(detail);
658 value += rmd * increment;
667 const float roughness,
668 const float lacunarity,
676 for (
int i = 0; (weight > 0.001f) && (i <=
int(detail)); i++) {
683 value += weight * signal;
684 weight *= gain * signal;
688 const float rmd = detail -
floorf(detail);
689 if ((rmd != 0.0f) && (weight > 0.001f)) {
694 value += rmd * weight * signal;
703 const float roughness,
704 const float lacunarity,
708 float pwr = roughness;
712 float value = signal;
715 for (
int i = 1; i <=
int(detail); i++) {
717 weight = std::clamp(signal * gain, 0.0f, 1.0f);
721 value += signal * pwr;
929 position, detail, roughness, lacunarity, offset, gain, type,
normalize),
960 position, detail, roughness, lacunarity, offset, gain, type,
normalize),
991 position, detail, roughness, lacunarity, offset, gain, type,
normalize),
1053 return std::abs(
b - a);
1062 return std::abs(a.x -
b.x) + std::abs(a.y -
b.y);
1064 return std::max(std::abs(a.x -
b.x), std::abs(a.y -
b.y));
1066 return std::pow(std::pow(std::abs(a.x -
b.x),
params.exponent) +
1067 std::pow(std::abs(a.y -
b.y),
params.exponent),
1082 return std::abs(a.x -
b.x) + std::abs(a.y -
b.y) + std::abs(a.z -
b.z);
1084 return std::max(std::abs(a.x -
b.x), std::max(std::abs(a.y -
b.y), std::abs(a.z -
b.z)));
1086 return std::pow(std::pow(std::abs(a.x -
b.x),
params.exponent) +
1087 std::pow(std::abs(a.y -
b.y),
params.exponent) +
1088 std::pow(std::abs(a.z -
b.z),
params.exponent),
1103 return std::abs(a.x -
b.x) + std::abs(a.y -
b.y) + std::abs(a.z -
b.z) + std::abs(a.w -
b.w);
1106 std::abs(a.x -
b.x),
1107 std::max(std::abs(a.y -
b.y), std::max(std::abs(a.z -
b.z), std::abs(a.w -
b.w))));
1109 return std::pow(std::pow(std::abs(a.x -
b.x),
params.exponent) +
1110 std::pow(std::abs(a.y -
b.y),
params.exponent) +
1111 std::pow(std::abs(a.z -
b.z),
params.exponent) +
1112 std::pow(std::abs(a.w -
b.w),
params.exponent),
1125 return {0.0f, 0.0f, 0.0f, coord};
1130 float cellPosition =
floorf(coord);
1131 float localPosition = coord - cellPosition;
1134 float targetOffset = 0.0f;
1135 float targetPosition = 0.0f;
1136 for (
int i = -1; i <= 1; i++) {
1137 float cellOffset = i;
1138 float pointPosition = cellOffset +
1141 if (distanceToPoint < minDistance) {
1142 targetOffset = cellOffset;
1143 minDistance = distanceToPoint;
1144 targetPosition = pointPosition;
1157 const bool calc_color)
1159 float cellPosition =
floorf(coord);
1160 float localPosition = coord - cellPosition;
1162 float smoothDistance = 0.0f;
1163 float smoothPosition = 0.0f;
1164 float3 smoothColor = {0.0f, 0.0f, 0.0f};
1166 for (
int i = -2; i <= 2; i++) {
1167 float cellOffset = i;
1168 float pointPosition = cellOffset +
1174 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
1175 float correctionFactor =
params.smoothness * h * (1.0f - h);
1176 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
1177 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
1181 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
1183 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
1188 octave.
color = smoothColor;
1195 float cellPosition =
floorf(coord);
1196 float localPosition = coord - cellPosition;
1200 float offsetF1 = 0.0f;
1201 float positionF1 = 0.0f;
1202 float offsetF2 = 0.0f;
1203 float positionF2 = 0.0f;
1204 for (
int i = -1; i <= 1; i++) {
1205 float cellOffset = i;
1206 float pointPosition = cellOffset +
1209 if (distanceToPoint < distanceF1) {
1210 distanceF2 = distanceF1;
1211 distanceF1 = distanceToPoint;
1212 offsetF2 = offsetF1;
1213 offsetF1 = cellOffset;
1214 positionF2 = positionF1;
1215 positionF1 = pointPosition;
1217 else if (distanceToPoint < distanceF2) {
1218 distanceF2 = distanceToPoint;
1219 offsetF2 = cellOffset;
1220 positionF2 = pointPosition;
1233 float cellPosition =
floorf(coord);
1234 float localPosition = coord - cellPosition;
1239 float distanceToMidLeft =
fabsf((midPointPosition + leftPointPosition) / 2.0f - localPosition);
1240 float distanceToMidRight =
fabsf((midPointPosition + rightPointPosition) / 2.0f - localPosition);
1242 return math::min(distanceToMidLeft, distanceToMidRight);
1247 float cellPosition =
floorf(coord);
1248 float localPosition = coord - cellPosition;
1250 float closestPoint = 0.0f;
1251 float closestPointOffset = 0.0f;
1253 for (
int i = -1; i <= 1; i++) {
1254 float cellOffset = i;
1255 float pointPosition = cellOffset +
1257 float distanceToPoint =
fabsf(pointPosition - localPosition);
1258 if (distanceToPoint < minDistance) {
1259 minDistance = distanceToPoint;
1260 closestPoint = pointPosition;
1261 closestPointOffset = cellOffset;
1266 float closestPointToClosestPoint = 0.0f;
1267 for (
int i = -1; i <= 1; i++) {
1271 float cellOffset = i + closestPointOffset;
1272 float pointPosition = cellOffset +
1274 float distanceToPoint =
fabsf(closestPoint - pointPosition);
1275 if (distanceToPoint < minDistance) {
1276 minDistance = distanceToPoint;
1277 closestPointToClosestPoint = pointPosition;
1281 return fabsf(closestPointToClosestPoint - closestPoint) / 2.0f;
1288 return {coord.x, coord.y, 0.0f, 0.0f};
1294 float2 localPosition = coord - cellPosition;
1297 float2 targetOffset = {0.0f, 0.0f};
1298 float2 targetPosition = {0.0f, 0.0f};
1299 for (
int j = -1; j <= 1; j++) {
1300 for (
int i = -1; i <= 1; i++) {
1302 float2 pointPosition = cellOffset +
1305 if (distanceToPoint < minDistance) {
1306 targetOffset = cellOffset;
1307 minDistance = distanceToPoint;
1308 targetPosition = pointPosition;
1322 const bool calc_color)
1325 float2 localPosition = coord - cellPosition;
1327 float smoothDistance = 0.0f;
1328 float3 smoothColor = {0.0f, 0.0f, 0.0f};
1329 float2 smoothPosition = {0.0f, 0.0f};
1331 for (
int j = -2; j <= 2; j++) {
1332 for (
int i = -2; i <= 2; i++) {
1334 float2 pointPosition = cellOffset +
1341 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
1342 float correctionFactor =
params.smoothness * h * (1.0f - h);
1343 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
1344 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
1348 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
1350 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
1356 octave.
color = smoothColor;
1364 float2 localPosition = coord - cellPosition;
1368 float2 offsetF1 = {0.0f, 0.0f};
1369 float2 positionF1 = {0.0f, 0.0f};
1370 float2 offsetF2 = {0.0f, 0.0f};
1371 float2 positionF2 = {0.0f, 0.0f};
1372 for (
int j = -1; j <= 1; j++) {
1373 for (
int i = -1; i <= 1; i++) {
1375 float2 pointPosition = cellOffset +
1378 if (distanceToPoint < distanceF1) {
1379 distanceF2 = distanceF1;
1380 distanceF1 = distanceToPoint;
1381 offsetF2 = offsetF1;
1382 offsetF1 = cellOffset;
1383 positionF2 = positionF1;
1384 positionF1 = pointPosition;
1386 else if (distanceToPoint < distanceF2) {
1387 distanceF2 = distanceToPoint;
1388 offsetF2 = cellOffset;
1389 positionF2 = pointPosition;
1404 float2 localPosition = coord - cellPosition;
1406 float2 vectorToClosest = {0.0f, 0.0f};
1408 for (
int j = -1; j <= 1; j++) {
1409 for (
int i = -1; i <= 1; i++) {
1411 float2 vectorToPoint = cellOffset +
1414 float distanceToPoint =
math::dot(vectorToPoint, vectorToPoint);
1415 if (distanceToPoint < minDistance) {
1416 minDistance = distanceToPoint;
1417 vectorToClosest = vectorToPoint;
1423 for (
int j = -1; j <= 1; j++) {
1424 for (
int i = -1; i <= 1; i++) {
1426 float2 vectorToPoint = cellOffset +
1429 float2 perpendicularToEdge = vectorToPoint - vectorToClosest;
1430 if (
math::dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
1431 float distanceToEdge =
math::dot((vectorToClosest + vectorToPoint) / 2.0f,
1433 minDistance =
math::min(minDistance, distanceToEdge);
1444 float2 localPosition = coord - cellPosition;
1446 float2 closestPoint = {0.0f, 0.0f};
1447 float2 closestPointOffset = {0.0f, 0.0f};
1449 for (
int j = -1; j <= 1; j++) {
1450 for (
int i = -1; i <= 1; i++) {
1452 float2 pointPosition = cellOffset +
1454 float distanceToPoint =
math::distance(pointPosition, localPosition);
1455 if (distanceToPoint < minDistance) {
1456 minDistance = distanceToPoint;
1457 closestPoint = pointPosition;
1458 closestPointOffset = cellOffset;
1464 float2 closestPointToClosestPoint = {0.0f, 0.0f};
1465 for (
int j = -1; j <= 1; j++) {
1466 for (
int i = -1; i <= 1; i++) {
1467 if (i == 0 && j == 0) {
1471 float2 pointPosition = cellOffset +
1473 float distanceToPoint =
math::distance(closestPoint, pointPosition);
1474 if (distanceToPoint < minDistance) {
1475 minDistance = distanceToPoint;
1476 closestPointToClosestPoint = pointPosition;
1481 return math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
1488 return {coord.x, coord.y, coord.z, 0.0f};
1494 float3 localPosition = coord - cellPosition;
1497 float3 targetOffset = {0.0f, 0.0f, 0.0f};
1498 float3 targetPosition = {0.0f, 0.0f, 0.0f};
1499 for (
int k = -1; k <= 1; k++) {
1500 for (
int j = -1; j <= 1; j++) {
1501 for (
int i = -1; i <= 1; i++) {
1502 float3 cellOffset(i, j, k);
1503 float3 pointPosition = cellOffset +
1506 if (distanceToPoint < minDistance) {
1507 targetOffset = cellOffset;
1508 minDistance = distanceToPoint;
1509 targetPosition = pointPosition;
1524 const bool calc_color)
1527 float3 localPosition = coord - cellPosition;
1529 float smoothDistance = 0.0f;
1530 float3 smoothColor = {0.0f, 0.0f, 0.0f};
1531 float3 smoothPosition = {0.0f, 0.0f, 0.0f};
1533 for (
int k = -2; k <= 2; k++) {
1534 for (
int j = -2; j <= 2; j++) {
1535 for (
int i = -2; i <= 2; i++) {
1536 float3 cellOffset(i, j, k);
1537 float3 pointPosition = cellOffset +
1544 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
1545 float correctionFactor =
params.smoothness * h * (1.0f - h);
1546 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
1547 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
1551 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
1553 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
1560 octave.
color = smoothColor;
1568 float3 localPosition = coord - cellPosition;
1572 float3 offsetF1 = {0.0f, 0.0f, 0.0f};
1573 float3 positionF1 = {0.0f, 0.0f, 0.0f};
1574 float3 offsetF2 = {0.0f, 0.0f, 0.0f};
1575 float3 positionF2 = {0.0f, 0.0f, 0.0f};
1576 for (
int k = -1; k <= 1; k++) {
1577 for (
int j = -1; j <= 1; j++) {
1578 for (
int i = -1; i <= 1; i++) {
1579 float3 cellOffset(i, j, k);
1580 float3 pointPosition = cellOffset +
1583 if (distanceToPoint < distanceF1) {
1584 distanceF2 = distanceF1;
1585 distanceF1 = distanceToPoint;
1586 offsetF2 = offsetF1;
1587 offsetF1 = cellOffset;
1588 positionF2 = positionF1;
1589 positionF1 = pointPosition;
1591 else if (distanceToPoint < distanceF2) {
1592 distanceF2 = distanceToPoint;
1593 offsetF2 = cellOffset;
1594 positionF2 = pointPosition;
1610 float3 localPosition = coord - cellPosition;
1612 float3 vectorToClosest = {0.0f, 0.0f, 0.0f};
1614 for (
int k = -1; k <= 1; k++) {
1615 for (
int j = -1; j <= 1; j++) {
1616 for (
int i = -1; i <= 1; i++) {
1617 float3 cellOffset(i, j, k);
1618 float3 vectorToPoint = cellOffset +
1622 float distanceToPoint =
math::dot(vectorToPoint, vectorToPoint);
1623 if (distanceToPoint < minDistance) {
1624 minDistance = distanceToPoint;
1625 vectorToClosest = vectorToPoint;
1632 for (
int k = -1; k <= 1; k++) {
1633 for (
int j = -1; j <= 1; j++) {
1634 for (
int i = -1; i <= 1; i++) {
1635 float3 cellOffset(i, j, k);
1636 float3 vectorToPoint = cellOffset +
1640 float3 perpendicularToEdge = vectorToPoint - vectorToClosest;
1641 if (
math::dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
1642 float distanceToEdge =
math::dot((vectorToClosest + vectorToPoint) / 2.0f,
1644 minDistance =
math::min(minDistance, distanceToEdge);
1656 float3 localPosition = coord - cellPosition;
1658 float3 closestPoint = {0.0f, 0.0f, 0.0f};
1659 float3 closestPointOffset = {0.0f, 0.0f, 0.0f};
1661 for (
int k = -1; k <= 1; k++) {
1662 for (
int j = -1; j <= 1; j++) {
1663 for (
int i = -1; i <= 1; i++) {
1664 float3 cellOffset(i, j, k);
1665 float3 pointPosition = cellOffset +
1667 float distanceToPoint =
math::distance(pointPosition, localPosition);
1668 if (distanceToPoint < minDistance) {
1669 minDistance = distanceToPoint;
1670 closestPoint = pointPosition;
1671 closestPointOffset = cellOffset;
1678 float3 closestPointToClosestPoint = {0.0f, 0.0f, 0.0f};
1679 for (
int k = -1; k <= 1; k++) {
1680 for (
int j = -1; j <= 1; j++) {
1681 for (
int i = -1; i <= 1; i++) {
1682 if (i == 0 && j == 0 && k == 0) {
1685 float3 cellOffset =
float3(i, j, k) + closestPointOffset;
1686 float3 pointPosition = cellOffset +
1688 float distanceToPoint =
math::distance(closestPoint, pointPosition);
1689 if (distanceToPoint < minDistance) {
1690 minDistance = distanceToPoint;
1691 closestPointToClosestPoint = pointPosition;
1697 return math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
1710 float4 localPosition = coord - cellPosition;
1713 float4 targetOffset = {0.0f, 0.0f, 0.0f, 0.0f};
1714 float4 targetPosition = {0.0f, 0.0f, 0.0f, 0.0f};
1715 for (
int u = -1; u <= 1; u++) {
1716 for (
int k = -1; k <= 1; k++) {
1717 for (
int j = -1; j <= 1; j++) {
1718 for (
int i = -1; i <= 1; i++) {
1719 float4 cellOffset(i, j, k, u);
1723 if (distanceToPoint < minDistance) {
1724 targetOffset = cellOffset;
1725 minDistance = distanceToPoint;
1726 targetPosition = pointPosition;
1742 const bool calc_color)
1745 float4 localPosition = coord - cellPosition;
1747 float smoothDistance = 0.0f;
1748 float3 smoothColor = {0.0f, 0.0f, 0.0f};
1749 float4 smoothPosition = {0.0f, 0.0f, 0.0f, 0.0f};
1751 for (
int u = -2; u <= 2; u++) {
1752 for (
int k = -2; k <= 2; k++) {
1753 for (
int j = -2; j <= 2; j++) {
1754 for (
int i = -2; i <= 2; i++) {
1755 float4 cellOffset(i, j, k, u);
1763 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
1764 float correctionFactor =
params.smoothness * h * (1.0f - h);
1765 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
1766 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
1770 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
1772 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
1780 octave.
color = smoothColor;
1788 float4 localPosition = coord - cellPosition;
1792 float4 offsetF1 = {0.0f, 0.0f, 0.0f, 0.0f};
1793 float4 positionF1 = {0.0f, 0.0f, 0.0f, 0.0f};
1794 float4 offsetF2 = {0.0f, 0.0f, 0.0f, 0.0f};
1795 float4 positionF2 = {0.0f, 0.0f, 0.0f, 0.0f};
1796 for (
int u = -1; u <= 1; u++) {
1797 for (
int k = -1; k <= 1; k++) {
1798 for (
int j = -1; j <= 1; j++) {
1799 for (
int i = -1; i <= 1; i++) {
1800 float4 cellOffset(i, j, k, u);
1804 if (distanceToPoint < distanceF1) {
1805 distanceF2 = distanceF1;
1806 distanceF1 = distanceToPoint;
1807 offsetF2 = offsetF1;
1808 offsetF1 = cellOffset;
1809 positionF2 = positionF1;
1810 positionF1 = pointPosition;
1812 else if (distanceToPoint < distanceF2) {
1813 distanceF2 = distanceToPoint;
1814 offsetF2 = cellOffset;
1815 positionF2 = pointPosition;
1832 float4 localPosition = coord - cellPosition;
1834 float4 vectorToClosest = {0.0f, 0.0f, 0.0f, 0.0f};
1836 for (
int u = -1; u <= 1; u++) {
1837 for (
int k = -1; k <= 1; k++) {
1838 for (
int j = -1; j <= 1; j++) {
1839 for (
int i = -1; i <= 1; i++) {
1840 float4 cellOffset(i, j, k, u);
1841 float4 vectorToPoint = cellOffset +
1845 float distanceToPoint =
math::dot(vectorToPoint, vectorToPoint);
1846 if (distanceToPoint < minDistance) {
1847 minDistance = distanceToPoint;
1848 vectorToClosest = vectorToPoint;
1856 for (
int u = -1; u <= 1; u++) {
1857 for (
int k = -1; k <= 1; k++) {
1858 for (
int j = -1; j <= 1; j++) {
1859 for (
int i = -1; i <= 1; i++) {
1860 float4 cellOffset(i, j, k, u);
1861 float4 vectorToPoint = cellOffset +
1865 float4 perpendicularToEdge = vectorToPoint - vectorToClosest;
1866 if (
math::dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
1867 float distanceToEdge =
math::dot((vectorToClosest + vectorToPoint) / 2.0f,
1869 minDistance =
math::min(minDistance, distanceToEdge);
1882 float4 localPosition = coord - cellPosition;
1884 float4 closestPoint = {0.0f, 0.0f, 0.0f, 0.0f};
1885 float4 closestPointOffset = {0.0f, 0.0f, 0.0f, 0.0f};
1887 for (
int u = -1; u <= 1; u++) {
1888 for (
int k = -1; k <= 1; k++) {
1889 for (
int j = -1; j <= 1; j++) {
1890 for (
int i = -1; i <= 1; i++) {
1891 float4 cellOffset(i, j, k, u);
1894 float distanceToPoint =
math::distance(pointPosition, localPosition);
1895 if (distanceToPoint < minDistance) {
1896 minDistance = distanceToPoint;
1897 closestPoint = pointPosition;
1898 closestPointOffset = cellOffset;
1906 float4 closestPointToClosestPoint = {0.0f, 0.0f, 0.0f, 0.0f};
1907 for (
int u = -1; u <= 1; u++) {
1908 for (
int k = -1; k <= 1; k++) {
1909 for (
int j = -1; j <= 1; j++) {
1910 for (
int i = -1; i <= 1; i++) {
1911 if (i == 0 && j == 0 && k == 0 && u == 0) {
1914 float4 cellOffset =
float4(i, j, k, u) + closestPointOffset;
1917 float distanceToPoint =
math::distance(closestPoint, pointPosition);
1918 if (distanceToPoint < minDistance) {
1919 minDistance = distanceToPoint;
1920 closestPointToClosestPoint = pointPosition;
1927 return math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
1937 const bool calc_color )
1939 float amplitude = 1.0f;
1940 float max_amplitude = 0.0f;
1944 const bool zero_input =
params.detail == 0.0f ||
params.roughness == 0.0f;
1950 params.smoothness != 0.0f) ?
1955 max_amplitude = 1.0f;
1959 if (i <=
params.detail) {
1960 max_amplitude += amplitude;
1962 output.color += octave.
color * amplitude;
1963 output.position =
mix(output.position, octave.
position / scale, amplitude);
1964 scale *=
params.lacunarity;
1965 amplitude *=
params.roughness;
1969 if (remainder != 0.0f) {
1970 max_amplitude =
mix(max_amplitude, max_amplitude + amplitude, remainder);
1971 output.distance =
mix(
1972 output.distance, output.distance + octave.
distance * amplitude, remainder);
1973 output.color =
mix(output.color, output.color + octave.
color * amplitude, remainder);
1974 output.position =
mix(
1975 output.position,
mix(output.position, octave.
position / scale, amplitude), remainder);
1981 output.distance /= max_amplitude *
params.max_distance;
1982 output.color /= max_amplitude;
1985 output.position = (
params.scale != 0.0f) ? output.position /
params.scale :
1986 float4{0.0f, 0.0f, 0.0f, 0.0f};
1996 float amplitude = 1.0f;
1997 float max_amplitude =
params.max_distance;
1999 float distance = 8.0f;
2001 const bool zero_input =
params.detail == 0.0f ||
params.roughness == 0.0f;
2007 distance = octave_distance;
2010 if (i <=
params.detail) {
2011 max_amplitude =
mix(max_amplitude,
params.max_distance / scale, amplitude);
2012 distance =
mix(distance,
math::min(distance, octave_distance / scale), amplitude);
2013 scale *=
params.lacunarity;
2014 amplitude *=
params.roughness;
2018 if (remainder != 0.0f) {
2019 float lerp_amplitude =
mix(max_amplitude,
params.max_distance / scale, amplitude);
2020 max_amplitude =
mix(max_amplitude, lerp_amplitude, remainder);
2021 float lerp_distance =
mix(
2022 distance,
math::min(distance, octave_distance / scale), amplitude);
2023 distance =
mix(distance,
math::min(distance, lerp_distance), remainder);
2029 distance /= max_amplitude;
2039 const bool calc_color);
2042 const bool calc_color);
2045 const bool calc_color);
2048 const bool calc_color);
2114 const float frequency,
2115 const float orientation)
2120 const float windowed_gaussian_envelope = gaussian_envelop * hann_window;
2122 const float2 frequency_vector = frequency *
float2(
cos(orientation), sin(orientation));
2126 return windowed_gaussian_envelope * phasor;
2157 const float integral_of_gabor_squared = 0.25f;
2158 const float second_moment = 0.5f;
2170 const float frequency,
2171 const float isotropy,
2172 const float base_orientation)
2178 const float3 seed_for_orientation(cell.x, cell.y, i * 3);
2179 const float3 seed_for_kernel_center(cell.x, cell.y, i * 3 + 1);
2180 const float3 seed_for_weight(cell.x, cell.y, i * 3 + 2);
2188 const float orientation = base_orientation + random_orientation * isotropy;
2191 const float2 position_in_kernel_space = position - kernel_center;
2211 const float frequency,
2212 const float isotropy,
2213 const float base_orientation)
2216 const float2 local_position = coordinates - cell_position;
2219 for (
int j = -1; j <= 1; j++) {
2220 for (
int i = -1; i <= 1; i++) {
2222 const float2 current_cell_position = cell_position + cell_offset;
2223 const float2 position_in_cell_space = local_position - cell_offset;
2225 current_cell_position, position_in_cell_space, frequency, isotropy, base_orientation);
2237 const float frequency,
2238 const float3 orientation)
2243 const float windowed_gaussian_envelope = gaussian_envelop * hann_window;
2245 const float3 frequency_vector = frequency * orientation;
2249 return windowed_gaussian_envelope * phasor;
2258 const float second_moment = 0.5f;
2266 const float isotropy,
2270 if (isotropy == 0.0) {
2275 float inclination =
math::acos(orientation.z);
2284 inclination += random_angles.x * isotropy;
2285 azimuth += random_angles.y * isotropy;
2295 const float frequency,
2296 const float isotropy,
2297 const float3 base_orientation)
2303 const float4 seed_for_orientation(cell.x, cell.y, cell.z, i * 3);
2304 const float4 seed_for_kernel_center(cell.x, cell.y, cell.z, i * 3 + 1);
2305 const float4 seed_for_weight(cell.x, cell.y, cell.z, i * 3 + 2);
2308 base_orientation, isotropy, seed_for_orientation);
2311 const float3 position_in_kernel_space = position - kernel_center;
2330 const float frequency,
2331 const float isotropy,
2332 const float3 base_orientation)
2335 const float3 local_position = coordinates - cell_position;
2338 for (
int k = -1; k <= 1; k++) {
2339 for (
int j = -1; j <= 1; j++) {
2340 for (
int i = -1; i <= 1; i++) {
2342 const float3 current_cell_position = cell_position + cell_offset;
2343 const float3 position_in_cell_space = local_position - cell_offset;
2345 current_cell_position, position_in_cell_space, frequency, isotropy, base_orientation);
2355 const float frequency,
2356 const float anisotropy,
2357 const float orientation,
2362 const float2 scaled_coordinates = coordinates * scale;
2363 const float isotropy = 1.0f -
math::clamp(anisotropy, 0.0f, 1.0f);
2364 const float sanitized_frequency =
math::max(0.001f, frequency);
2367 scaled_coordinates, sanitized_frequency, isotropy, orientation);
2372 const float normalization_factor = 6.0f * standard_deviation;
2377 *r_value = (phasor.y / normalization_factor) * 0.5f + 0.5f;
2388 *r_intensity =
math::length(phasor) / normalization_factor;
2394 const float frequency,
2395 const float anisotropy,
2396 const float3 orientation,
2401 const float3 scaled_coordinates = coordinates * scale;
2402 const float isotropy = 1.0f -
math::clamp(anisotropy, 0.0f, 1.0f);
2403 const float sanitized_frequency =
math::max(0.001f, frequency);
2407 scaled_coordinates, sanitized_frequency, isotropy, normalized_orientation);
2412 const float normalization_factor = 6.0f * standard_deviation;
2417 *r_value = (phasor.y / normalization_factor) * 0.5f + 0.5f;
2428 *r_intensity =
math::length(phasor) / normalization_factor;
#define BLI_assert_unreachable()
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static T sum(const btAlignedObjectArray< T > &items)
static unsigned long seed
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
MINLINE float smoothstep(float edge0, float edge1, float x)
ccl_device_inline float3 cos(float3 v)
T length_squared(const VecBase< T, Size > &a)
T cos(const AngleRadianBase< T > &a)
T clamp(const T &a, const T &min, const T &max)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
T atan2(const T &y, const T &x)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
T sin(const AngleRadianBase< T > &a)
T max(const T &a, const T &b)
T mod(const T &a, const T &b)
template VoronoiOutput fractal_voronoi_x_fx< float4 >(const VoronoiParams ¶ms, const float4 coord, const bool calc_color)
template float fractal_voronoi_distance_to_edge< float >(const VoronoiParams ¶ms, const float coord)
float3 perlin_float3_fractal_distorted(float position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
BLI_INLINE float negate_if(float value, uint32_t condition)
BLI_INLINE float uint_to_float_01(uint32_t k)
float perlin_ridged_multi_fractal(T p, const float detail, const float roughness, const float lacunarity, const float offset, const float gain)
static float2 compute_3d_gabor_noise(const float3 coordinates, const float frequency, const float isotropy, const float3 base_orientation)
uint32_t hash_float(float kx)
static float compute_3d_gabor_standard_deviation()
template float perlin_fbm< float3 >(float3 p, const float detail, const float roughness, const float lacunarity, const bool normalize)
static float2 compute_2d_gabor_noise_cell(const float2 cell, const float2 position, const float frequency, const float isotropy, const float base_orientation)
BLI_INLINE float perlin_distortion(float position, float strength)
float hash_float_to_float(float k)
float perlin_signed(float position)
void gabor(const float2 coordinates, const float scale, const float frequency, const float anisotropy, const float orientation, float *r_value, float *r_phase, float *r_intensity)
@ NOISE_SHD_VORONOI_N_SPHERE_RADIUS
@ NOISE_SHD_VORONOI_SMOOTH_F1
@ NOISE_SHD_VORONOI_DISTANCE_TO_EDGE
template float perlin_fractal_distorted< float >(float position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
@ NOISE_SHD_VORONOI_MANHATTAN
@ NOISE_SHD_VORONOI_MINKOWSKI
@ NOISE_SHD_VORONOI_EUCLIDEAN
@ NOISE_SHD_VORONOI_CHEBYCHEV
BLI_INLINE void hash_bit_mix(uint32_t &a, uint32_t &b, uint32_t &c)
float4 voronoi_position(const float coord)
BLI_INLINE float fade(float t)
VoronoiOutput voronoi_smooth_f1(const VoronoiParams ¶ms, const float coord, const bool calc_color)
float voronoi_n_sphere_radius(const VoronoiParams ¶ms, const float coord)
static float2 compute_2d_gabor_noise(const float2 coordinates, const float frequency, const float isotropy, const float base_orientation)
float perlin(float position)
BLI_INLINE float random_float_offset(float seed)
BLI_INLINE float floor_fraction(float x, int &i)
float voronoi_distance_to_edge(const VoronoiParams ¶ms, const float coord)
BLI_INLINE uint32_t float_as_uint(float f)
template VoronoiOutput fractal_voronoi_x_fx< float3 >(const VoronoiParams ¶ms, const float3 coord, const bool calc_color)
template float perlin_fractal_distorted< float2 >(float2 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
BLI_INLINE float3 random_float3_offset(float seed)
static float2 compute_3d_gabor_noise_cell(const float3 cell, const float3 position, const float frequency, const float isotropy, const float3 base_orientation)
static float2 compute_2d_gabor_kernel(const float2 position, const float frequency, const float orientation)
VoronoiOutput fractal_voronoi_x_fx(const VoronoiParams ¶ms, const T coord, const bool calc_color)
float voronoi_distance(const float a, const float b)
static float2 compute_3d_gabor_kernel(const float3 position, const float frequency, const float3 orientation)
template float perlin_fractal_distorted< float4 >(float4 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
BLI_INLINE float2 random_float2_offset(float seed)
float perlin_fbm(T p, float detail, float roughness, float lacunarity, bool normalize)
VoronoiOutput voronoi_f2(const VoronoiParams ¶ms, const float coord)
float3 hash_float_to_float3(float k)
template VoronoiOutput fractal_voronoi_x_fx< float >(const VoronoiParams ¶ms, const float coord, const bool calc_color)
BLI_INLINE float4 random_float4_offset(float seed)
BLI_INLINE float perlin_noise(float position)
float fractal_voronoi_distance_to_edge(const VoronoiParams ¶ms, const T coord)
BLI_INLINE void hash_bit_final(uint32_t &a, uint32_t &b, uint32_t &c)
float4 hash_float_to_float4(float4 k)
float perlin_hybrid_multi_fractal(T p, const float detail, const float roughness, const float lacunarity, const float offset, const float gain)
static float compute_2d_gabor_standard_deviation()
@ NOISE_SHD_PERLIN_MULTIFRACTAL
@ NOISE_SHD_PERLIN_RIDGED_MULTIFRACTAL
@ NOISE_SHD_PERLIN_HYBRID_MULTIFRACTAL
@ NOISE_SHD_PERLIN_HETERO_TERRAIN
float perlin_select(T p, float detail, float roughness, float lacunarity, float offset, float gain, int type, bool normalize)
BLI_INLINE float noise_grad(uint32_t hash, float x)
VoronoiOutput voronoi_f1(const VoronoiParams ¶ms, const float coord)
float perlin_multi_fractal(T p, const float detail, const float roughness, const float lacunarity)
template float fractal_voronoi_distance_to_edge< float3 >(const VoronoiParams ¶ms, const float3 coord)
static constexpr int gabor_impulses_count
float perlin_fractal_distorted(T position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
template float perlin_fractal_distorted< float3 >(float3 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
template VoronoiOutput fractal_voronoi_x_fx< float2 >(const VoronoiParams ¶ms, const float2 coord, const bool calc_color)
template float fractal_voronoi_distance_to_edge< float4 >(const VoronoiParams ¶ms, const float4 coord)
BLI_INLINE uint32_t hash_bit_rotate(uint32_t x, uint32_t k)
float perlin_hetero_terrain(T p, const float detail, const float roughness, const float lacunarity, const float offset)
float2 hash_float_to_float2(float2 k)
static float3 compute_3d_orientation(const float3 orientation, const float isotropy, const float4 seed)
float hash_to_float(uint32_t kx)
template float fractal_voronoi_distance_to_edge< float2 >(const VoronoiParams ¶ms, const float2 coord)
VecBase< float, 4 > float4
VecBase< float, 2 > float2
VecBase< float, 3 > float3
float distance(float a, float b)